Переглянути джерело

+ Error handling for AJAX PMs preview

emanuele 13 роки тому
батько
коміт
67b0155815

+ 16 - 6
Sources/PersonalMessage.php

@@ -1873,7 +1873,12 @@ function messagePostError($error_types, $named_recipients, $recipient_ids = arra
 			)
 		);
 		if ($smcFunc['db_num_rows']($request) == 0)
-			fatal_lang_error('pm_not_yours', false);
+		{
+			if (!isset($_REQUEST['xml']))
+				fatal_lang_error('pm_not_yours', false);
+			else
+				$error_types[] = 'pm_not_yours';
+		}
 		$row_quoted = $smcFunc['db_fetch_assoc']($request);
 		$smcFunc['db_free_result']($request);
 
@@ -1977,6 +1982,9 @@ function MessagePost2()
 	// Extract out the spam settings - it saves database space!
 	list ($modSettings['max_pm_recipients'], $modSettings['pm_posts_verification'], $modSettings['pm_posts_per_hour']) = explode(',', $modSettings['pm_spam_settings']);
 
+	// Initialize the errors we're about to make.
+	$post_errors = array();
+
 	// Check whether we've gone over the limit of messages we can send per hour - fatal error if fails!
 	if (!empty($modSettings['pm_posts_per_hour']) && !allowedTo(array('admin_forum', 'moderate_forum', 'send_mail')) && $user_info['mod_cache']['bq'] == '0=1' && $user_info['mod_cache']['gq'] == '0=1')
 	{
@@ -1996,7 +2004,12 @@ function MessagePost2()
 		$smcFunc['db_free_result']($request);
 
 		if (!empty($postCount) && $postCount >= $modSettings['pm_posts_per_hour'])
-			fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
+		{
+			if (!isset($_REQUEST['xml']))
+				fatal_lang_error('pm_too_many_per_hour', true, array($modSettings['pm_posts_per_hour']));
+			else
+				$post_errors[] = 'pm_too_many_per_hour';
+		}
 	}
 
 	// If we came from WYSIWYG then turn it back into BBC regardless.
@@ -2012,11 +2025,8 @@ function MessagePost2()
 		$_REQUEST['message'] = $_POST['message'];
 	}
 
-	// Initialize the errors we're about to make.
-	$post_errors = array();
-
 	// If your session timed out, show an error, but do allow to re-submit.
-	if (checkSession('post', '', false) != '')
+	if (!isset($_REQUEST['xml']) && checkSession('post', '', false) != '')
 		$post_errors[] = 'session_timeout';
 
 	$_REQUEST['subject'] = isset($_REQUEST['subject']) ? trim($_REQUEST['subject']) : '';

+ 17 - 26
Themes/default/PersonalMessage.template.php

@@ -940,21 +940,17 @@ function template_send()
 			<div class="roundframe"><br class="clear" />';
 
 	// If there were errors for sending the PM, show them.
-	if (!empty($context['post_error']['messages']))
-	{
-		echo '
-				<div class="errorbox">
-					<strong>', $txt['error_while_submitting'], '</strong>
-					<ul class="reset">';
-
-		foreach ($context['post_error']['messages'] as $error)
-			echo '
-						<li class="error">', $error, '</li>';
-
-		echo '
-					</ul>
+	echo '
+				<div class="errorbox"', empty($context['post_error']['messages']) ? ' style="display: none"' : '', ' id="errors">
+					<dl>
+						<dt>
+							<strong>', $txt['error_while_submitting'], '</strong>
+						</dt>
+						<dd class="error" id="error_list">
+							', empty($context['post_error']['messages']) ? '' : implode('<br />', $context['post_error']['messages']), '
+						</dd>
+					</dl>
 				</div>';
-	}
 
 	echo '
 				<dl id="post_header">';
@@ -962,7 +958,7 @@ function template_send()
 	// To and bcc. Include a button to search for members.
 	echo '
 					<dt>
-						<span', (isset($context['post_error']['no_to']) || isset($context['post_error']['bad_to']) ? ' class="error"' : ''), '>', $txt['pm_to'], ':</span>
+						<span', (isset($context['post_error']['no_to']) || isset($context['post_error']['bad_to']) ? ' class="error"' : ''), ' id="caption_to">', $txt['pm_to'], ':</span>
 					</dt>';
 
 	// Autosuggest will be added by the JavaScript later on.
@@ -984,7 +980,7 @@ function template_send()
 	// This BCC row will be hidden by default if JavaScript is enabled.
 	echo '
 					<dt  class="clear_left" id="bcc_div">
-						<span', (isset($context['post_error']['no_to']) || isset($context['post_error']['bad_bcc']) ? ' class="error"' : ''), '>', $txt['pm_bcc'], ':</span>
+						<span', (isset($context['post_error']['no_to']) || isset($context['post_error']['bad_bcc']) ? ' class="error"' : ''), ' id="caption_bbc">', $txt['pm_bcc'], ':</span>
 					</dt>
 					<dd id="bcc_div2">
 						<input type="text" name="bcc" id="bcc_control" value="', $context['bcc_value'], '" tabindex="', $context['tabindex']++, '" size="40" style="width: 130px;" class="input_text" />
@@ -994,7 +990,7 @@ function template_send()
 	// The subject of the PM.
 	echo '
 					<dt class="clear_left">
-						<span', (isset($context['post_error']['no_subject']) ? ' class="error"' : ''), '>', $txt['subject'], ':</span>
+						<span', (isset($context['post_error']['no_subject']) ? ' class="error"' : ''), ' id="caption_subject">', $txt['subject'], ':</span>
 					</dt>
 					<dd id="pm_subject">
 						<input type="text" name="subject" value="', $context['subject'], '" tabindex="', $context['tabindex']++, '" size="60" maxlength="60" />
@@ -1077,11 +1073,8 @@ function template_send()
 					// @todo Currently not sending poll options and option checkboxes.
 					var x = new Array();
 					var textFields = [\'subject\', ', JavaScriptEscape($context['post_box_name']), ', \'to\', \'bcc\'];
-					var numericFields = [
-					];
-					var checkboxFields = [
-						\'outbox\'
-					];
+					var numericFields = [\'recipient_to[]\', \'recipient_bcc[]\'];
+					var checkboxFields = [\'outbox\'];
 
 					for (var i = 0, n = textFields.length; i < n; i++)
 						if (textFields[i] in document.forms.postmodify)
@@ -1138,12 +1131,10 @@ function template_send()
 				for (var i = 0, numErrors = errors.getElementsByTagName(\'error\').length; i < numErrors; i++)
 					errorList[errorList.length] = errors.getElementsByTagName(\'error\')[i].firstChild.nodeValue;
 				document.getElementById(\'errors\').style.display = numErrors == 0 ? \'none\' : \'\';
-				document.getElementById(\'error_serious\').style.display = errors.getAttribute(\'serious\') == 1 ? \'\' : \'none\';
+				// @todo temporarly removed
+				//document.getElementById(\'error_serious\').style.display = errors.getAttribute(\'serious\') == 1 ? \'\' : \'none\';
 				setInnerHTML(document.getElementById(\'error_list\'), numErrors == 0 ? \'\' : errorList.join(\'<br />\'));
 
-				// Show a warning if the topic has been locked.
-				document.getElementById(\'lock_warning\').style.display = errors.getAttribute(\'topic_locked\') == 1 ? \'\' : \'none\';
-
 				// Adjust the color of captions if the given data is erroneous.
 				var captions = errors.getElementsByTagName(\'caption\');
 				for (var i = 0, numCaptions = errors.getElementsByTagName(\'caption\').length; i < numCaptions; i++)

+ 5 - 22
Themes/default/Xml.template.php

@@ -143,36 +143,19 @@ function template_pm()
 		<subject><![CDATA[', $context['preview_subject'], ']]></subject>
 		<body><![CDATA[', $context['preview_message'], ']]></body>
 	</preview>
-	<errors serious="', empty($context['error_type']) || $context['error_type'] != 'serious' ? '0' : '1', '" topic_locked="', $context['locked'] ? '1' : '0', '">';
+	<errors serious="', empty($context['error_type']) || $context['error_type'] != 'serious' ? '0' : '1', '">';
 	if (!empty($context['post_error']['messages']))
 		foreach ($context['post_error']['messages'] as $message)
 			echo '
 		<error><![CDATA[', cleanXml($message), ']]></error>';
+
 	echo '
-		<caption name="guestname" class="', isset($context['post_error']['long_name']) || isset($context['post_error']['no_name']) || isset($context['post_error']['bad_name']) ? 'error' : '', '" />
-		<caption name="email" class="', isset($context['post_error']['no_email']) || isset($context['post_error']['bad_email']) ? 'error' : '', '" />
-		<caption name="evtitle" class="', isset($context['post_error']['no_event']) ? 'error' : '', '" />
+		<caption name="to" class="', isset($context['post_error']['no_to']) ? 'error' : '', '" />
+		<caption name="bbc" class="', isset($context['post_error']['no_bbc']) ? 'error' : '', '" />
 		<caption name="subject" class="', isset($context['post_error']['no_subject']) ? 'error' : '', '" />
 		<caption name="question" class="', isset($context['post_error']['no_question']) ? 'error' : '', '" />', isset($context['post_error']['no_message']) || isset($context['post_error']['long_message']) ? '
 		<post_error />' : '', '
-	</errors>
-	<last_msg>', isset($context['topic_last_message']) ? $context['topic_last_message'] : '0', '</last_msg>';
-
-	if (!empty($context['previous_posts']))
-	{
-		echo '
-	<new_posts>';
-		foreach ($context['previous_posts'] as $post)
-			echo '
-		<post id="', $post['id'], '">
-			<time><![CDATA[', $post['time'], ']]></time>
-			<poster><![CDATA[', cleanXml($post['poster']), ']]></poster>
-			<message><![CDATA[', cleanXml($post['message']), ']]></message>
-			<is_ignored>', $post['is_ignored'] ? '1' : '0', '</is_ignored>
-		</post>';
-		echo '
-	</new_posts>';
-	}
+	</errors>';
 
 	echo '
 </smf>';