Browse Source

Merge pull request #1269 from Arantor/release-2.1

Alerts goodies
Arantor 10 years ago
parent
commit
88f08feeb5

+ 13 - 1
Sources/Load.php

@@ -1885,10 +1885,22 @@ function loadTheme($id_theme = 0, $initialize = true)
 			tempImage.src = smf_scripturl + "?scheduled=' . $type . ';ts=' . $ts . '";
 		}
 		window.setTimeout("smfAutoTask();", 1);');
-
 		}
 	}
 
+	// And we should probably trigger the cron too.
+	if (empty($modSettings['cron_is_real_cron']))
+	{
+		$ts = time();
+		$ts -= $ts % 15;
+		addInlineJavaScript('
+	function triggerCron() {
+		var tempImage = new Image();
+		tempImage.src = ' . JavaScriptEscape($boardurl) . ' + "/cron.php?ts=' . $ts . '";
+	}
+	window.setTimeout(triggerCron, 1);', true);
+	}
+
 	// Any files to include at this point?
 	if (!empty($modSettings['integrate_theme_include']))
 	{

+ 37 - 0
Sources/Profile-Modify.php

@@ -1865,6 +1865,7 @@ function notification($memID)
 	// This is just a bootstrap for everything else.
 	$sa = array(
 		'alerts' => 'alert_configuration',
+		'markread' => 'alert_markread',
 		'topics' => 'alert_notifications_topics',
 		'boards' => 'alert_notifications_boards',
 	);
@@ -2080,6 +2081,42 @@ function alert_configuration($memID)
 	createToken($context['token_check'], 'post');
 }
 
+function alert_markread($memID)
+{
+	global $context, $db_show_debug, $smcFunc;
+
+	// We do not want to output debug information here.
+	$db_show_debug = false;
+
+	// We only want to output our little layer here.
+	$context['template_layers'] = array();
+	$context['sub_template'] = 'alerts_all_read';
+
+	loadLanguage('Alerts');
+
+	// Now we're all set up.
+	is_not_guest();
+	if (!$context['user']['is_owner'])
+		fatal_error('no_access');
+
+	checkSession('get');
+
+	// Assuming we're here, mark everything as read and head back.
+	// We only spit back the little layer because this should be called AJAXively.
+	$smcFunc['db_query']('', '
+		UPDATE {db_prefix}user_alerts
+		SET is_read = {int:now}
+		WHERE id_member = {int:current_member}
+			AND is_read = 0',
+		array(
+			'now' => time(),
+			'current_member' => $memID,
+		)
+	);
+
+	updateMemberData($memID, array('alerts' => 0));
+}
+
 function alert_notifications_topics($memID)
 {
 	global $txt, $scripturl, $user_profile, $context, $modSettings, $smcFunc, $sourcedir;

+ 1 - 1
Sources/tasks/GroupReq-Notify.php

@@ -18,7 +18,7 @@ class GroupReq_Notify_Background extends SMF_BackgroundTask
 {
 	public function execute()
  	{
- 		global $sourcedir, $smcFunc, $language, $modSettings;		
+ 		global $sourcedir, $smcFunc, $language, $modSettings, $scripturl;		
 
 		// Do we have any group moderators?
 		$request = $smcFunc['db_query']('', '

+ 24 - 4
Themes/default/Profile.template.php

@@ -95,7 +95,7 @@ function template_alerts_popup()
 	echo '
 		<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=profile;area=notification;sa=markread;', $context['session_var'], '=', $context['session_id'], '" onclick="return markAlertsRead(this)">', $txt['mark_alerts_read'], '</a>
 				| <a href="', $scripturl, '?action=profile;area=notification;sa=alerts">', $txt['alert_settings'], '</a>
 			</div>
 			<div class="alerts_box floatleft">
@@ -106,8 +106,7 @@ function template_alerts_popup()
 
 	if (empty($context['unread_alerts']))
 	{
-		echo '
-			<div class="no_unread">', $txt['alerts_no_unread'], '</div>';
+		template_alerts_all_read();
 	}
 	else
 	{
@@ -125,7 +124,28 @@ function template_alerts_popup()
 	}
 
 	echo '
-		</div>';
+		</div>
+		<script><!-- // --><![CDATA[
+		function markAlertsRead(obj) {
+			ajax_indicator(true);
+			$.get(
+				obj.href,
+				function(data) {
+					ajax_indicator(false);
+					$("#alerts_menu_top span.amt").remove();
+					$("#alerts_menu div.alerts_unread").html(data);
+				}
+			);
+			return false;
+		}
+		// ]]></script>';
+}
+
+function template_alerts_all_read()
+{
+	global $txt;
+
+	echo '<div class="no_unread">', $txt['alerts_no_unread'], '</div>';
 }
 
 // This template displays users details without any option to edit them.

+ 1 - 1
Themes/default/languages/Alerts.english.php

@@ -15,7 +15,7 @@ $txt['alert_msg_report_reply'] = '{member_link} replied to <a href="{scripturl}{
 $txt['alert_member_register_standard'] = '{member_link} just signed up';
 $txt['alert_member_register_approval'] = '{member_link} just signed up (account requires approval)';
 $txt['alert_member_register_activation'] = '{member_link} just signed up (account requires activation)';
-$txt['alert_member_group_request'] = '{member_link} has requested to join {group_name}';
+$txt['alert_member_group_request'] = '{member_link} has <a href="{scripturl}?action=moderate;area=groups;sa=requests">requested</a> to join {group_name}';
 
 $txt['alert_event_new_guest'] = 'A new event, <a href="{scripturl}?action=calendar;event={event_id}">{event_title}</a>, was added to the calendar.';
 $txt['alert_event_new'] = '{member_link} added a new event, <a href="{scripturl}?action=calendar;event={event_id}">{event_title}</a> to the calendar.';

+ 11 - 1
cron.php

@@ -21,7 +21,7 @@
  */
 
 define('SMF', 'BACKGROUND');
-define('FROM_CLI', !isset($_SERVER['REQUEST_METHOD']));
+define('FROM_CLI', empty($_SERVER['REQUEST_METHOD']));
 define('WIRELESS', false);
 
 // This one setting is worth bearing in mind. If you are running this from proper cron, make sure you
@@ -65,6 +65,15 @@ if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.')
 if (file_exists($cachedir . '/cron.lock'))
 	obExit_cron();
 
+// Before we go any further, if this is not a CLI request, we need to do some checking.
+if (!FROM_CLI)
+{
+	// We will clean up $_GET shortly. But we want to this ASAP.
+	$ts = isset($_GET['ts']) ? (int) $_GET['ts'] : 0;
+	if ($ts <= 0 || $ts % 15 != 0 || time() - $ts < 0 || time() - $ts > 20)
+		obExit_cron();
+}
+
 // Load the most important includes. In general, a background should be loading its own dependencies.
 require_once($sourcedir . '/Errors.php');
 require_once($sourcedir . '/Load.php');
@@ -107,6 +116,7 @@ while ($task_details = fetch_task())
 		);
 	}
 }
+obExit_cron();
 exit;
 
 // The heart of this cron handler...