瀏覽代碼

! Use createList to list the news

emanuele 13 年之前
父節點
當前提交
89dcea60d7
共有 3 個文件被更改,包括 106 次插入73 次删除
  1. 105 4
      Sources/ManageNews.php
  2. 0 68
      Themes/default/ManageNews.template.php
  3. 1 1
      Themes/default/languages/Admin.english.php

+ 105 - 4
Sources/ManageNews.php

@@ -85,7 +85,7 @@ function ManageNews()
  */
 function EditNews()
 {
-	global $txt, $modSettings, $context, $sourcedir, $user_info;
+	global $txt, $modSettings, $context, $sourcedir, $user_info, $scripturl;
 	global $smcFunc;
 
 	require_once($sourcedir . '/Subs-Post.php');
@@ -131,16 +131,117 @@ function EditNews()
 		logAction('news');
 	}
 
+	// We're going to want this for making our list.
+	require_once($sourcedir . '/Subs-List.php');
+
+	$context['page_title'] = $txt['admin_edit_news'];
+
+	// Use the standard templates for showing this.
+	$listOptions = array(
+		'id' => 'news_lists',
+//		'title' => $txt['admin_edit_news'],
+		'get_items' => array(
+			'function' => 'list_getNews',
+		),
+		'columns' => array(
+			'news' => array(
+				'header' => array(
+					'value' => $txt['admin_edit_news'],
+				),
+				'data' => array(
+					'function' => create_function('$news', '
+
+						if (is_numeric($news[\'id\']))
+							return \'<textarea rows="3" cols="65" name="news[]" style="\' . (isBrowser(\'is_ie8\') ? \'width: 635px; max-width: 85%; min-width: 85%\' : \'width: 85%\') . \';">\' . $news[\'unparsed\'] . \'</textarea>\';
+						else
+							return $news[\'unparsed\'];
+					'),
+					'style' => 'width: 50%;',
+				),
+			),
+			'preview' => array(
+				'header' => array(
+					'value' => $txt['preview'],
+				),
+				'data' => array(
+					'function' => create_function('$news', '
+
+						return \'<div style="overflow: auto; width: 100%; height: 10ex;">\' . $news[\'parsed\'] . \'</div>\';
+					'),
+					'style' => 'width: 45%;',
+				),
+			),
+			'check' => array(
+				'header' => array(
+					'value' => '<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />',
+				),
+				'data' => array(
+					'function' => create_function('$news', '
+
+						if (is_numeric($news[\'id\']))
+							return \'<input type="checkbox" name="remove[]" value="\' . $news[\'id\'] . \'" class="input_check" />\';
+						else
+							return \'\';
+					'),
+					'style' => 'text-align: center',
+				),
+			),
+		),
+		'form' => array(
+			'href' => $scripturl . '?action=admin;area=news;sa=editnews',
+			'hidden_fields' => array(
+				$context['session_var'] => $context['session_id'],
+			),
+		),
+		'additional_rows' => array(
+			array(
+				'position' => 'bottom_of_list',
+				'value' => '
+				<span id="moreNewsItems_link" style="display: none;">[<a href="javascript:void(0);" onclick="addNewsItem(); return false;">' . $txt['editnews_clickadd'] . '</a>]</span>
+				<script type="text/javascript"><!-- // --><![CDATA[
+					document.getElementById(\'list_news_lists_last\').style.display = "none";
+					document.getElementById("moreNewsItems_link").style.display = "";
+					function addNewsItem()
+					{
+						document.getElementById("list_news_lists_last").style.display = "";
+						setOuterHTML(document.getElementById("moreNewsItems"), \'<div style="margin-bottom: 2ex;"><textarea rows="3" cols="65" name="news[]" style="' . (isBrowser('is_ie8') ? 'width: 635px; max-width: 85%; min-width: 85%' : 'width: 85%') . ';"><\' + \'/textarea><\' + \'/div><div id="moreNewsItems"><\' + \'/div>\');
+					}
+				// ]]></script>
+				<input type="submit" name="save_items" value="' . $txt['save'] . '" class="button_submit" /> <input type="submit" name="delete_selection" value="' . $txt['editnews_remove_selected'] . '" onclick="return confirm(\'' . $txt['editnews_remove_confirm'] . '\');" class="button_submit" />',
+				'align' => 'right',
+			),
+		),
+	);
+
+	// Create the request list.
+	createList($listOptions);
+
+	$context['sub_template'] = 'show_list';
+	$context['default_list'] = 'news_lists';
+}
+
+function list_getNews()
+{
+	global $modSettings;
+
+	$admin_current_news = array();
 	// Ready the current news.
 	foreach (explode("\n", $modSettings['news']) as $id => $line)
-		$context['admin_current_news'][$id] = array(
+		$admin_current_news[$id] = array(
 			'id' => $id,
 			'unparsed' => un_preparsecode($line),
 			'parsed' => preg_replace('~<([/]?)form[^>]*?[>]*>~i', '<em class="smalltext">&lt;$1form&gt;</em>', parse_bbc($line)),
 		);
 
-	$context['sub_template'] = 'edit_news';
-	$context['page_title'] = $txt['admin_edit_news'];
+	$admin_current_news['last'] = array(
+		'id' => 'last',
+		'unparsed' => '<div id="moreNewsItems"></div>
+		<noscript><textarea rows="3" cols="65" name="news[]" style="' . (isBrowser('is_ie8') ? 'width: 635px; max-width: 85%; min-width: 85%' : 'width: 85%') . ';"></textarea></noscript>',
+		'parsed' => '<div id="moreNewsItems_preview"></div>',
+	);
+
+	return $admin_current_news;
+//	$context['sub_template'] = 'edit_news';
 }
 
 /**

+ 0 - 68
Themes/default/ManageNews.template.php

@@ -10,74 +10,6 @@
  * @version 2.1 Alpha 1
  */
 
-// Form for editing current news on the site.
-function template_edit_news()
-{
-	global $context, $settings, $options, $scripturl, $txt;
-
-	echo '
-	<div id="admincenter">
-		<form action="', $scripturl, '?action=admin;area=news;sa=editnews" method="post" accept-charset="', $context['character_set'], '" name="postmodify" id="postmodify">
-			<table class="table_grid" width="100%">
-				<thead>
-					<tr class="catbg">
-						<th class="first_th" width="50%">', $txt['admin_edit_news'], '</th>
-						<th align="left" width="45%">', $txt['preview'], '</th>
-						<th class="last_th" align="center" width="5%"><input type="checkbox" class="input_check" onclick="invertAll(this, this.form);" /></th>
-					</tr>
-				</thead>
-				<tbody>';
-
-	// Loop through all the current news items so you can edit/remove them.
-	foreach ($context['admin_current_news'] as $admin_news)
-		echo '
-					<tr class="windowbg2">
-						<td align="center">
-
-							<div style="margin-bottom: 2ex;"><textarea rows="3" cols="65" name="news[]" style="' . (isBrowser('is_ie8') ? 'width: 635px; max-width: 85%; min-width: 85%' : 'width: 85%') . ';">', $admin_news['unparsed'], '</textarea></div>
-						</td><td align="left" valign="top">
-							<div style="overflow: auto; width: 100%; height: 10ex;">', $admin_news['parsed'], '</div>
-						</td><td align="center">
-							<input type="checkbox" name="remove[]" value="', $admin_news['id'], '" class="input_check" />
-						</td>
-					</tr>';
-
-	// This provides an empty text box to add a news item to the site.
-	echo '
-					<tr id="moreNews" class="windowbg2" style="display: none;">
-						<td align="center">
-							<div id="moreNewsItems"></div>
-						</td>
-						<td align="center">
-						</td>
-						<td align="center">
-						</td>
-					</tr>
-				</tbody>
-			</table>
-			<div class="floatleft padding">
-				<div id="moreNewsItems_link" style="display: none;"><a href="javascript:void(0);" onclick="addNewsItem(); return false;">', $txt['editnews_clickadd'], '</a></div>
-				<script type="text/javascript"><!-- // --><![CDATA[
-					document.getElementById("moreNewsItems_link").style.display = "";
-					function addNewsItem()
-					{
-						document.getElementById("moreNews").style.display = "";
-						setOuterHTML(document.getElementById("moreNewsItems"), \'<div style="margin-bottom: 2ex;"><textarea rows="3" cols="65" name="news[]" style="' . (isBrowser('is_ie8') ? 'width: 635px; max-width: 85%; min-width: 85%' : 'width: 85%') . ';"><\' + \'/textarea><\' + \'/div><div id="moreNewsItems"><\' + \'/div>\');
-					}
-				// ]]></script>
-				<noscript>
-					<div style="margin-bottom: 2ex;"><textarea rows="3" cols="65" style="' . (isBrowser('is_ie8') ? 'width: 635px; max-width: 85%; min-width: 85%' : 'width: 85%') . ';" name="news[]"></textarea></div>
-				</noscript>
-			</div>
-			<div class="floatright padding">
-				<input type="submit" name="save_items" value="', $txt['save'], '" class="button_submit" /> <input type="submit" name="delete_selection" value="', $txt['editnews_remove_selected'], '" onclick="return confirm(\'', $txt['editnews_remove_confirm'], '\');" class="button_submit" />
-			</div>
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-		</form>
-	</div>
-	<br class="clear" />';
-}
-
 function template_email_members()
 {
 	global $context, $settings, $options, $txt, $scripturl;

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

@@ -441,7 +441,7 @@ $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';
 $txt['xmlnews_maxlen'] = 'Maximum message length:<div class="smalltext">(0 to disable, bad idea.)</div>';
-$txt['editnews_clickadd'] = 'Click here to add another item.';
+$txt['editnews_clickadd'] = 'Click here to add another item';
 $txt['editnews_remove_selected'] = 'Remove selected';
 $txt['editnews_remove_confirm'] = 'Are you sure you want to delete the selected news items?';
 $txt['censor_clickadd'] = 'Click here to add another word.';