Skip to content
Browse files

+ Preview of warning templates

  • Loading branch information...
1 parent ed3edf4 commit f4ef5d6a2ade6f5631b041952a8a8164452bcff1 @emanuele45 committed Apr 4, 2012
View
63 Sources/Xml.php
@@ -79,17 +79,18 @@ function RetrievePreview()
global $context;
$subActions = array(
- 'newspreview' => 'newspreview',
- 'newsletterpreview' => 'newsletterpreview',
- 'sig_preview' => 'sig_preview',
+ 'newspreview',
+ 'newsletterpreview',
+ 'sig_preview',
+ 'warning_preview',
);
$context['sub_template'] = 'generic_xml';
if (!isset($_POST['item']) || !in_array($_POST['item'], $subActions))
return false;
- $subActions[$_POST['item']]();
+ $_POST['item']();
}
function newspreview()
@@ -222,4 +223,58 @@ function sig_preview()
);
}
+function warning_preview()
+{
+ global $context, $sourcedir, $smcFunc, $txt, $user_info, $scripturl, $mbname;
+
+ require_once($sourcedir . '/Subs-Post.php');
+ loadLanguage('Errors');
+ loadLanguage('ModerationCenter');
+
+ $user = isset($_POST['user']) ? (int) $_POST['user'] : 0;
+
+ $context['post_error']['messages'] = array();
+ if (allowedTo('issue_warning'))
+ {
+ $warning_body = !empty($_POST['template_body']) ? trim(censorText($_POST['template_body'])) : '';
+ $context['preview_subject'] = !empty($_POST['template_title']) ? trim($smcFunc['htmlspecialchars']($_POST['template_title'])) : '';
+ if (empty($_POST['template_title']))
+ $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_title'];
+ if (empty($_POST['template_body']))
+ $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_body'];
+ else
+ {
+ // Add in few replacements.
+ /**
+ * These are the defaults:
+ * - {MEMBER} - Member Name. => current user for review
+ * - {MESSAGE} - Link to Offending Post. (If Applicable) => not applicable here, so not replaced
+ * - {FORUMNAME} - Forum Name.
+ * - {SCRIPTURL} - Web address of forum.
+ * - {REGARDS} - Standard email sign-off.
+ */
+ $find = array(
+ '{MEMBER}',
+ '{FORUMNAME}',
+ '{SCRIPTURL}',
+ '{REGARDS}',
+ );
+ $replace = array(
+ $user_info['name'],
+ $mbname,
+ $scripturl,
+ $txt['regards_team'],
+ );
+ $warning_body = str_replace($find, $replace, $warning_body);
+ preparsecode($warning_body);
+ $warning_body = parse_bbc($warning_body, true);
+ }
+ $context['preview_message'] = $warning_body;
+ }
+ else
+ $context['post_error']['messages'][] = array('value' => $txt['cannot_issue_warning'], 'attributes' => array('type' => 'error'));
+
+ $context['sub_template'] = 'pm';
+}
+
?>
View
51 Themes/default/ModerationCenter.template.php
@@ -831,6 +831,16 @@ function template_warn_template()
</dd>
</dl>
</div>
+ <div id="box_preview"', !empty($context['template_preview']) ? '' : ' style="display:none"', '>
+ <dl class="settings">
+ <dt>
+ <strong>', $txt['preview'] , '</strong>
+ </dt>
+ <dd id="template_preview">
+ ', !empty($context['template_preview']) ? $context['template_preview'] : '', '
+ </dd>
+ </dl>
+ </div>
<dl class="settings">
<dt>
<strong><label for="template_title">', $txt['mc_warning_template_title'], '</label>:</strong>
@@ -858,6 +868,7 @@ function template_warn_template()
<br />';
echo '
+ <input type="submit" name="preview" id="preview_button" value="', $txt['preview'], '" class="button_submit" />
<input type="submit" name="save" value="', $context['page_title'], '" class="button_submit" />
</div>
<span class="botslice"><span></span></span>
@@ -866,7 +877,45 @@ function template_warn_template()
<input type="hidden" name="', $context['mod-wt_token_var'], '" value="', $context['mod-wt_token'], '" />
</form>
</div>
- <br class="clear" />';
+ <br class="clear" />
+ <script type="text/javascript"><!-- // --><![CDATA[
+ $(document).ready(function() {
+ $("#preview_button").click(function() {
+ return ajax_getTemplatePreview();
+ });
+ });
+
+ function ajax_getTemplatePreview ()
+ {
+ $.ajax({
+ type: "POST",
+ url: "' . $scripturl . '?action=xmlhttp;sa=previews;xml",
+ data: {item: "warning_preview", template_title: $("#template_title").val(), template_body: $("#template_body").val(), user: $(\'input[name="u"]\').attr("value")},
+ context: document.body,
+ success: function(request){
+ $("#box_preview").css({display:""});
+ $("#template_preview").html($(request).find(\'body\').text());
+ if ($(request).find("error").text() != \'\')
+ {
+ $("#errors").css({display:""});
+ var errors_html = \'\';
+ var errors = $(request).find(\'error\').each(function() {
+ errors_html += $(this).text() + \'<br />\';
+ });
+
+ $(document).find("#error_list").html(errors_html);
+ }
+ else
+ {
+ $("#errors").css({display:"none"});
+ $("#error_list").html(\'\');
+ }
+ return false;
+ },
+ });
+ return false;
+ }
+ // ]]></script>';
}
?>
View
2 Themes/default/PersonalMessage.template.php
@@ -1046,7 +1046,7 @@ function template_send()
echo '
<script type="text/javascript"><!-- // --><![CDATA[';
- // The functions used to preview a posts without loading a new page.
+ // The functions used to preview a personal message without loading a new page.
echo '
var txt_preview_title = "', $txt['preview_title'], '";
var txt_preview_fetch = "', $txt['preview_fetch'], '";
View
1 Themes/default/Profile.template.php
@@ -2626,7 +2626,6 @@ function calcCharLeft()
if (is_opera)
currentChars = currentSignature.replace(/\r/g,\'\').length;
- //ajax_getSignaturePreview(false);
if (currentChars > maxLength)
{
document.getElementById("signatureLeft").className = "error";
View
1 Themes/default/languages/Post.english.php
@@ -9,7 +9,6 @@
$txt['subject_not_filled'] = 'The Subject field was not filled out. It is required.';
$txt['message_body_not_filled'] = 'The Message Body was not filled out. It is required.';
// Use numeric entities in the below string.
-$txt['regards_team'] = "Regards,\nThe " . $context['forum_name'] . ' Team.';
$txt['add_bbc'] = 'Add BBC tags';
$txt['bold'] = 'Bold';
$txt['italic'] = 'Italicized';
View
2 Themes/default/languages/index.english.php
@@ -110,7 +110,7 @@
$txt['unnotify'] = 'Unnotify';
$txt['notify_request'] = 'Do you want a notification email if someone replies to this topic?';
// Use numeric entities in the below string.
-$txt['regards_team'] = 'Regards,' . "\n" . 'The ' . $context['forum_name'] . ' Team.';
+$txt['regards_team'] = "Regards,\nThe " . $context['forum_name'] . ' Team.';
$txt['notify_replies'] = 'Notify of replies';
$txt['move_topic'] = 'Move Topic';
$txt['move_to'] = 'Move to';

0 comments on commit f4ef5d6

Please sign in to comment.
Something went wrong with that request. Please try again.