Quellcode durchsuchen

+ Preview of existing news elements. Still to do new ones, the important ones! :P

emanuele vor 12 Jahren
Ursprung
Commit
ddd1345cf1
3 geänderte Dateien mit 63 neuen und 1 gelöschten Zeilen
  1. 13 1
      Sources/ManageNews.php
  2. 49 0
      Sources/Xml.php
  3. 1 0
      Themes/default/languages/Admin.english.php

+ 13 - 1
Sources/ManageNews.php

@@ -205,8 +205,20 @@ function EditNews()
 					$(document).ready(function() {
 						$("div[id ^= \'preview_\']").each(function () {
 							$(this).css({cursor: \'hand\', cursor: \'pointer\', });
+							var preview_id = $(this).attr(\'id\').split(\'_\')[1];
 							$(this).text(\'' . $txt['preview'] . '\').click(function () {
-								// @todo ajax...
+								$.ajax({
+									type: "POST",
+									url: "' . $scripturl . '?action=xmlhttp;sa=previews;xml",
+									data: {item: "newspreview", news: $(this).prev().val()},
+									context: document.body,
+									success: function(request){
+										if ($(request).find("error").text() == \'\')
+											$(document).find("#box_preview_" + preview_id).html($(request).text());
+										else
+											$(document).find("#box_preview_" + preview_id).text(\'' . $txt['news_error_no_news'] . '\');
+									},
+								});
 							});
 						});
 					});

+ 49 - 0
Sources/Xml.php

@@ -28,6 +28,9 @@ function XMLhttpMain()
 		'messageicons' => array(
 			'function' => 'ListMessageIcons',
 		),
+		'previews' => array(
+			'function' => 'RetrievePreview',
+		),
 	);
 	if (!isset($_REQUEST['sa'], $sub_actions[$_REQUEST['sa']]))
 		fatal_lang_error('no_access', false);
@@ -71,4 +74,50 @@ function ListMessageIcons()
 	$context['sub_template'] = 'message_icons';
 }
 
+function RetrievePreview()
+{
+	global $context;
+
+	$subActions = array(
+		'newspreview' => 'newspreview',
+	);
+
+	$context['sub_template'] = 'generic_xml';
+
+	if (!isset($_POST['item']) || !in_array($_POST['item'], $subActions))
+		return false;
+
+// echo $subActions[$_REQUEST['item']];die();
+	$subActions[$_POST['item']]();
+}
+
+function newspreview()
+{
+	global $context, $sourcedir, $smcFunc;
+
+	require_once($sourcedir . '/Subs-Post.php');
+
+	$errors = array();
+	$news = !isset($_POST['news'])? '' : $smcFunc['htmlspecialchars']($_POST['news'], ENT_QUOTES);;
+	if (empty($news))
+		$errors[] = array('value' => 'no_news');
+	else
+		preparsecode($news);
+
+	$context['xml_data'] = array(
+		'news' => array(
+			'identifier' => 'parsedNews',
+			'children' => array(
+				array(
+					'value' => parse_bbc($news),
+				),
+			),
+		),
+		'errors' => array(
+			'identifier' => 'error',
+			'children' => $errors
+		),
+	);
+
+}
 ?>

+ 1 - 0
Themes/default/languages/Admin.english.php

@@ -437,6 +437,7 @@ $txt['news_title'] = 'News and Newsletters';
 $txt['news_settings_desc'] = 'Here you can change the settings and permissions related to news and newsletters.';
 $txt['news_settings_submit'] = 'Save';
 $txt['news_mailing_desc'] = 'From this menu you can send messages to all members who\'ve registered and entered their email addresses. You may edit the distribution list, or send messages to all. Useful for important update/news information.';
+$txt['news_error_no_news'] = 'Nothing written';
 $txt['groups_edit_news'] = 'Groups allowed to edit news items';
 $txt['groups_send_mail'] = 'Groups allowed to send out forum newsletters';
 $txt['xmlnews_enable'] = 'Enable XML/RSS news';