소스 검색

! Very WIP of the alert preferences area. It doesn't work properly, I'm well aware of that, I just wanted to get it in as it is, just so it's there and I might be able to get some feedback on it (even though it doesn't work properly)

Signed-off-by: Peter Spicer <[email protected]>
Peter Spicer 10 년 전
부모
커밋
a6fb5fb1a7
3개의 변경된 파일349개의 추가작업 그리고 94개의 파일을 삭제
  1. 206 81
      Sources/Profile-Modify.php
  2. 10 5
      Sources/Profile.php
  3. 133 8
      Themes/default/Profile.template.php

+ 206 - 81
Sources/Profile-Modify.php

@@ -992,7 +992,7 @@ function saveProfileChanges(&$profile_vars, &$post_errors, $memID)
 	{
 		makeThemeChanges($memID, isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']);
 		//makeAvatarChanges($memID, $post_errors);
-		makeNotificationChanges($memID);
+
 		if (!empty($_REQUEST['sa']))
 			makeCustomFieldChanges($memID, $_REQUEST['sa'], false);
 
@@ -1820,94 +1820,130 @@ function notification($memID)
 {
 	global $txt, $scripturl, $user_profile, $user_info, $context, $modSettings, $smcFunc, $sourcedir, $settings;
 
-	// Gonna want this for the list.
-	require_once($sourcedir . '/Subs-List.php');
+	// Going to want this for consistency.
+	loadCSSFile('admin.css', array(), 'admin');
 
-	// Fine, start with the board list.
-	$listOptions = array(
-		'id' => 'board_notification_list',
-		'width' => '100%',
-		'no_items_label' => $txt['notifications_boards_none'] . '<br /><br />' . $txt['notifications_boards_howto'],
-		'no_items_align' => 'left',
-		'base_href' => $scripturl . '?action=profile;u=' . $memID . ';area=notification',
-		'default_sort_col' => 'board_name',
-		'get_items' => array(
-			'function' => 'list_getBoardNotifications',
-			'params' => array(
-				$memID,
-			),
-		),
-		'columns' => array(
-			'board_name' => array(
-				'header' => array(
-					'value' => $txt['notifications_boards'],
-					'class' => 'lefttext first_th',
-				),
-				'data' => array(
-					'function' => create_function('$board', '
-						global $settings, $txt;
+	// This is just a bootstrap for everything else.
+	$sa = array(
+		'alerts' => 'alert_configuration',
+		'topics' => 'alert_notifications_topics',
+		'boards' => 'alert_notifications_boards',
+	);
 
-						$link = $board[\'link\'];
+	$subAction = !empty($_GET['sa']) && isset($sa[$_GET['sa']]) ? $_GET['sa'] : 'alerts';
 
-						if ($board[\'new\'])
-							$link .= \' <a href="\' . $board[\'href\'] . \'"><span class="new_posts">' . $txt['new'] . '</span></a>\';
+	$context['sub_template'] = $sa[$subAction];
+	$context[$context['profile_menu_name']]['tab_data'] = array(
+		'title' => $txt['notification'],
+		'help' => '',
+		'description' => $txt['notification_info'],
+	);
+	$sa[$subAction]($memID);
+}
 
-						return $link;
-					'),
-				),
-				'sort' => array(
-					'default' => 'name',
-					'reverse' => 'name DESC',
-				),
-			),
-			'delete' => array(
-				'header' => array(
-					'value' => '<input type="checkbox" class="input_check" onclick="invertAll(this, this.form);" />',
-					'style' => 'width: 4%;',
-					'class' => 'centercol',
-				),
-				'data' => array(
-					'sprintf' => array(
-						'format' => '<input type="checkbox" name="notify_boards[]" value="%1$d" class="input_check" />',
-						'params' => array(
-							'id' => false,
-						),
-					),
-					'class' => 'centercol',
-				),
-			),
+function alert_configuration($memID)
+{
+	global $txt, $scripturl, $user_profile, $user_info, $context, $modSettings, $smcFunc, $sourcedir, $settings;
+
+	// What options are set?
+	$context['member'] += array(
+		'notify_announcements' => $user_profile[$memID]['notify_announcements'],
+		'notify_send_body' => $user_profile[$memID]['notify_send_body'],
+		'notify_types' => $user_profile[$memID]['notify_types'],
+		'notify_regularity' => $user_profile[$memID]['notify_regularity'],
+	);
+
+	loadThemeOptions($memID);
+
+	// Now for the exciting stuff.
+	// We have groups of items, each item has both an alert and an email key as well as an optional help string.
+	// Valid values for these keys are 'always', 'yes', 'never'; if using always or never you should add a help string.
+	$alert_types = array(
+		'msg' => array(
+			'msg_mention' => array('alert' => 'yes', 'email' => 'yes'),
+			'msg_quote' => array('alert' => 'yes', 'email' => 'yes'),
+			'msg_like' => array('alert' => 'yes', 'email' => 'yes'),
 		),
-		'form' => array(
-			'href' => $scripturl . '?action=profile;area=notification;save',
-			'include_sort' => true,
-			'include_start' => true,
-			'hidden_fields' => array(
-				'u' => $memID,
-				'sa' => $context['menu_item_selected'],
-				$context['session_var'] => $context['session_id'],
-			),
-			'token' => $context['token_check'],
+		'pm' => array(
+			'pm_new' => array('alert' => 'always', 'email' => 'yes', 'help' => 'alert_pm_new'),
+			'pm_reply' => array('alert' => 'always', 'email' => 'yes', 'help' => 'alert_pm_new'),
 		),
-		'additional_rows' => array(
-			array(
-				'position' => 'bottom_of_list',
-				'value' => '<input type="submit" name="edit_notify_boards" value="' . $txt['notifications_update'] . '" class="button_submit" />',
-				'align' => 'right',
-			),
+		'moderation' => array(
+			'msg_report' => array('alert' => 'yes', 'email' => 'yes'),
+			'msg_report_reply' => array('alert' => 'yes', 'email' => 'yes'),
+		),
+		'members' => array(
+			'register_new' => array('alert' => 'yes', 'email' => 'yes'),
+			'warn_own' => array('alert' => 'yes', 'email' => 'yes'),
+			'warn_any' => array('alert' => 'yes', 'email' => 'yes'),
+		),
+		'calendar' => array(
+			'event_new' => array('alert' => 'yes', 'email' => 'yes', 'help' => 'alert_event_new'),
+		),
+	);
+	$group_options = array(
+		'msg' => array(
+			array('check', 'msg_auto_notify', 'label' => 'after'),
+			array('select', 'msg_notify_pref', 'label' => 'before', 'opts' => array(
+				'nothing' => $txt['alert_opt_msg_notify_pref_nothing'],
+				'instant' => $txt['alert_opt_msg_notify_pref_instant'],
+				'first' => $txt['alert_opt_msg_notify_pref_first'],
+				'daily' => $txt['alert_opt_msg_notify_pref_daily'],
+				'weekly' => $txt['alert_opt_msg_notify_pref_weekly'],
+			)),
 		),
 	);
+	// Now, now, we could pass this through global but we should really get into the habit of
+	// passing content to hooks, not expecting hooks to splatter everything everywhere.
+	call_integration_hook('integrate_alert_types', array(&$alert_types, &$group_options));
+	$context['alert_types'] = $alert_types;
+	$context['alert_group_options'] = $group_options;
 
-	// Create the board notification list.
-	createList($listOptions);
+	if (isset($_POST['saving or something']))
+	{
+		is_not_guest();
+		if (!$context['member']['is_owner'])
+			isAllowedTo('profile_extra_any');
+		checkSession('post');
+		validateToken(str_replace('%u', $memID, 'profile-nt%u'), 'post');
+
+		makeNotificationChanges($memID);
+		$context['profile_updated'] = $txt['profile_updated_own'];
+	}
 
-	// Now do the topic notifications.
+	$context['token_check'] = str_replace('%u', $memID, 'profile-nt%u');
+	createToken($context['token_check'], 'post');
+}
+
+function alert_notifications_topics($memID)
+{
+	global $txt, $scripturl, $user_profile, $user_info, $context, $modSettings, $smcFunc, $sourcedir, $settings;
+
+	// Because of the way this stuff works, we want to do this ourselves.
+	if (isset($_POST['edit_notify_topics']))
+	{
+		checkSession('post');
+		validateToken(str_replace('%u', $memID, 'profile-nt%u'), 'post');
+
+		makeNotificationChanges($memID);
+		$context['profile_updated'] = $txt['profile_updated_own'];
+	}
+
+	// Now set up for the token check.
+	$context['token_check'] = str_replace('%u', $memID, 'profile-nt%u');
+	createToken($context['token_check'], 'post');
+
+	// Gonna want this for the list.
+	require_once($sourcedir . '/Subs-List.php');
+
+	// Do the topic notifications.
 	$listOptions = array(
 		'id' => 'topic_notification_list',
 		'width' => '100%',
 		'items_per_page' => $modSettings['defaultMaxMessages'],
 		'no_items_label' => $txt['notifications_topics_none'] . '<br /><br />' . $txt['notifications_topics_howto'],
 		'no_items_align' => 'left',
-		'base_href' => $scripturl . '?action=profile;u=' . $memID . ';area=notification',
+		'base_href' => $scripturl . '?action=profile;u=' . $memID . ';area=notification;sa=topics',
 		'default_sort_col' => 'last_post',
 		'get_items' => array(
 			'function' => 'list_getTopicNotifications',
@@ -1996,7 +2032,7 @@ function notification($memID)
 			),
 		),
 		'form' => array(
-			'href' => $scripturl . '?action=profile;area=notification;save',
+			'href' => $scripturl . '?action=profile;area=notification;sa=topics',
 			'include_sort' => true,
 			'include_start' => true,
 			'hidden_fields' => array(
@@ -2017,16 +2053,105 @@ function notification($memID)
 
 	// Create the notification list.
 	createList($listOptions);
+}
 
-	// What options are set?
-	$context['member'] += array(
-		'notify_announcements' => $user_profile[$memID]['notify_announcements'],
-		'notify_send_body' => $user_profile[$memID]['notify_send_body'],
-		'notify_types' => $user_profile[$memID]['notify_types'],
-		'notify_regularity' => $user_profile[$memID]['notify_regularity'],
+function alert_notifications_boards($memID)
+{
+	global $txt, $scripturl, $user_profile, $user_info, $context, $modSettings, $smcFunc, $sourcedir, $settings;
+
+	// Because of the way this stuff works, we want to do this ourselves.
+	if (isset($_POST['edit_notify_boards']))
+	{
+		checkSession('post');
+		validateToken(str_replace('%u', $memID, 'profile-nt%u'), 'post');
+
+		makeNotificationChanges($memID);
+		$context['profile_updated'] = $txt['profile_updated_own'];
+	}
+
+	// Now set up for the token check.
+	$context['token_check'] = str_replace('%u', $memID, 'profile-nt%u');
+	createToken($context['token_check'], 'post');
+
+	// Gonna want this for the list.
+	require_once($sourcedir . '/Subs-List.php');
+
+	// Fine, start with the board list.
+	$listOptions = array(
+		'id' => 'board_notification_list',
+		'width' => '100%',
+		'no_items_label' => $txt['notifications_boards_none'] . '<br /><br />' . $txt['notifications_boards_howto'],
+		'no_items_align' => 'left',
+		'base_href' => $scripturl . '?action=profile;u=' . $memID . ';area=notification;sa=boards',
+		'default_sort_col' => 'board_name',
+		'get_items' => array(
+			'function' => 'list_getBoardNotifications',
+			'params' => array(
+				$memID,
+			),
+		),
+		'columns' => array(
+			'board_name' => array(
+				'header' => array(
+					'value' => $txt['notifications_boards'],
+					'class' => 'lefttext first_th',
+				),
+				'data' => array(
+					'function' => create_function('$board', '
+						global $settings, $txt;
+
+						$link = $board[\'link\'];
+
+						if ($board[\'new\'])
+							$link .= \' <a href="\' . $board[\'href\'] . \'"><span class="new_posts">' . $txt['new'] . '</span></a>\';
+
+						return $link;
+					'),
+				),
+				'sort' => array(
+					'default' => 'name',
+					'reverse' => 'name DESC',
+				),
+			),
+			'delete' => array(
+				'header' => array(
+					'value' => '<input type="checkbox" class="input_check" onclick="invertAll(this, this.form);" />',
+					'style' => 'width: 4%;',
+					'class' => 'centercol',
+				),
+				'data' => array(
+					'sprintf' => array(
+						'format' => '<input type="checkbox" name="notify_boards[]" value="%1$d" class="input_check" />',
+						'params' => array(
+							'id' => false,
+						),
+					),
+					'class' => 'centercol',
+				),
+			),
+		),
+		'form' => array(
+			'href' => $scripturl . '?action=profile;area=notification;sa=boards',
+			'include_sort' => true,
+			'include_start' => true,
+			'hidden_fields' => array(
+				'u' => $memID,
+				'sa' => $context['menu_item_selected'],
+				$context['session_var'] => $context['session_id'],
+			),
+			'token' => $context['token_check'],
+		),
+		'additional_rows' => array(
+			array(
+				'position' => 'bottom_of_list',
+				'value' => '<input type="submit" name="edit_notify_boards" value="' . $txt['notifications_update'] . '" class="button_submit" />',
+				'align' => 'right',
+			),
+		),
 	);
 
-	loadThemeOptions($memID);
+	// Create the board notification list.
+	createList($listOptions);
 }
 
 /**

+ 10 - 5
Sources/Profile.php

@@ -252,10 +252,15 @@ function ModifyProfile($post_errors = array())
 					'function' => 'notification',
 					'icon' => 'mail.png',
 					'sc' => 'post',
-					'token' => 'profile-nt%u',
+					//'token' => 'profile-nt%u', This is not checked here. We do it in the function itself - but if it was checked, this is what it'd be.
+					'subsections' => array(
+						'alerts' => array($txt['alert_prefs'], array('is_not_guest', 'profile_extra_any')),
+						'topics' => array($txt['watched_topics'], array('is_not_guest', 'profile_extra_any')),
+						'boards' => array($txt['watched_boards'], array('is_not_guest', 'profile_extra_any')),
+					),
 					'permission' => array(
-						'own' => array('profile_extra_any', 'profile_extra_own'),
-						'any' => array('profile_extra_any'),
+						'own' => array('is_not_guest'),
+						'any' => array('profile_extra_any'), // If you change this, update it in the functions themselves; we delegate all saving checks there.
 					),
 				),
 				'ignoreboards' => array(
@@ -278,7 +283,6 @@ function ModifyProfile($post_errors = array())
 					'icon' => 'frenemy.png',
 					'enabled' => !empty($modSettings['enable_buddylist']) && $context['user']['is_owner'],
 					'sc' => 'post',
-					'token' => 'profile-bl%u',
 					'subsections' => array(
 						'buddies' => array($txt['editBuddies']),
 						'ignore' => array($txt['editIgnoreList']),
@@ -428,6 +432,7 @@ function ModifyProfile($post_errors = array())
 
 	// Set the selected item - now it's been validated.
 	$current_area = $profile_include_data['current_area'];
+	$current_sa = $profile_include_data['current_subsection'];
 	$context['menu_item_selected'] = $current_area;
 
 	// Before we go any further, let's work on the area we've said is valid. Note this is done here just in case we ever compromise the menu function in error!
@@ -693,7 +698,7 @@ function ModifyProfile($post_errors = array())
 	}
 	// If it's you then we should redirect upon save.
 	elseif (!empty($profile_vars) && $context['user']['is_owner'] && !$context['do_preview'])
-		redirectexit('action=profile;area=' . $current_area . ';updated');
+		redirectexit('action=profile;area=' . $current_area . (!empty($current_sa) ? ';sa=' . $current_sa : '') . ';updated');
 	elseif (!empty($force_redirect))
 		redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=' . $current_area);
 

+ 133 - 8
Themes/default/Profile.template.php

@@ -96,7 +96,7 @@ function template_alerts_popup()
 		<div class="alert_bar">
 			<div class="alerts_opts floatright">
 				<a href="' . $scripturl . '?action=pm;sa=send">', $txt['mark_alerts_read'], '</a>
-				| <a href="', $scripturl, '?action=pm;sa=settings">', $txt['alert_settings'], '</a>
+				| <a href="', $scripturl, '?action=profile;area=notification;sa=alerts">', $txt['alert_settings'], '</a>
 			</div>
 			<div class="alerts_box floatleft">
 				', $txt['unread_alerts'], '
@@ -1767,19 +1767,23 @@ function template_profile_theme_settings()
 							</dd>';
 }
 
-function template_notification()
+function template_alert_configuration()
 {
 	global $context, $settings, $options, $txt, $scripturl, $modSettings;
 
-	// The main containing header.
 	echo '
-		<form action="', $scripturl, '?action=profile;area=notification;save" method="post" accept-charset="', $context['character_set'], '" id="notify_options" class="flow_hidden">
-			<div class="cat_bar">
-				<h3 class="catbg">
-					<img src="', $settings['images_url'], '/icons/profile_hd.png" alt="" class="icon" />', $txt['profile'], '
+		<div class="cat_bar">
+			<h3 class="catbg">
+				', $txt['alert_prefs'], '
+			</h3>
+		</div>
+		<p class="description">', $txt['alert_prefs_desc'], '</p>
+		<form action="', $scripturl, '?action=profile;area=notification;sa=alerts" id="admin_form_wrapper" method="post" accept-charset="', $context['character_set'], '" id="notify_options" class="flow_hidden">
+			<div class="title_bar">
+				<h3 class="titlebg">
+					', $txt['notification_general'], '
 				</h3>
 			</div>
-			<p class="description">', $txt['notification_info'], '</p>
 			<div class="windowbg2">
 				<div class="content">
 					<dl class="settings">';
@@ -1839,6 +1843,101 @@ function template_notification()
 							</select>
 						</dd>
 					</dl>
+				</div>
+			</div>
+			<div class="title_bar">
+				<h3 class="titlebg">
+					', $txt['notify_what_how'], '
+				</h3>
+			</div>
+			<div class="windowbg2">
+				<div class="content">
+					<table class="table_grid" style="width: 100%">
+						<tr class="titlebg">
+							<td></td>
+							<td>', $txt['receive_alert'], '</td>
+							<td>', $txt['receive_mail'], '</td>
+						</tr>';
+	foreach ($context['alert_types'] as $alert_group => $alerts)
+	{
+		echo '
+						<tr class="catbg">
+							<th colspan="3">
+								', $txt['alert_group_' . $alert_group];
+		if (isset($context['alert_group_options'][$alert_group]))
+		{
+			foreach ($context['alert_group_options'][$alert_group] as $opts)
+			{
+				echo '
+						<div class="smalltext">';
+				$label = $txt['alert_opt_' . $opts[1]];
+				$label_pos = isset($opts['label']) ? $opts['label'] : '';
+				if ($label_pos == 'before')
+					echo '
+							<label for="opt_', $opts[1], '">', $label, '</label>';
+
+				switch ($opts[0])
+				{
+					case 'check':
+						echo '
+								<input type="checkbox" name="opt_', $opts[1], '" id="opt_', $opts[1], '" />';
+						break;
+					case 'select':
+						echo '
+								<select name="opt_', $opts[1], '" id="opt_', $opts[1], '">';
+						foreach ($opts['opts'] as $k => $v)
+							echo '
+									<option value="', $k, '">', $v, '</option>';
+						echo '
+								</select>';
+						break;
+				}
+
+				if ($label_pos == 'after')
+					echo '
+							<label for="opt_', $opts[1], '">', $label, '</label>';
+
+				echo '
+						</div>';
+			}
+		}
+
+		echo '
+							</th>
+						</tr>';
+		foreach ($alerts as $alert_id => $alert_details)
+		{
+			echo '
+						<tr>
+							<td>', $txt['alert_' . $alert_id], '</td>';
+
+			foreach (array('alert', 'email') as $type)
+			{
+				echo '
+							<td>';
+				switch ($alert_details[$type])
+				{
+					case 'always':
+						echo '
+								<input type="checkbox" checked="checked" disabled="disabled" />';
+						break;
+					case 'yes':
+						echo '
+								<input type="checkbox" />';
+						break;
+					case 'never':
+						echo '
+								<input type="checkbox" disabled="disabled" />';
+						break;
+				}
+				echo '
+							</td>';
+			}
+		}
+	}
+
+	echo '
+					</table>
 					<hr class="hrcolor" />
 					<div>
 						<input id="notify_submit" type="submit" value="', $txt['notify_save'], '" class="button_submit" />
@@ -1851,10 +1950,36 @@ function template_notification()
 			</div>
 		</form>
 		<br />';
+}
+
+function template_alert_notifications_topics()
+{
+	global $context, $settings, $options, $txt, $scripturl, $modSettings;
+
+	// The main containing header.
+	echo '
+		<div class="cat_bar">
+			<h3 class="catbg">
+				', $txt['watched_topics'], '
+			</h3>
+		</div>
+		<p class="description">', $txt['watched_topics_desc'], '</p>
+		<br />';
 
 	template_show_list('topic_notification_list');
+}
+
+function template_alert_notifications_boards()
+{
+	global $context, $settings, $options, $txt, $scripturl, $modSettings;
 
 	echo '
+		<div class="cat_bar">
+			<h3 class="catbg">
+				', $txt['watched_boards'], '
+			</h3>
+		</div>
+		<p class="description">', $txt['watched_boards_desc'], '</p>
 		<br />';
 
 	template_show_list('board_notification_list');