Browse Source

We all like lists! :D Attachments approval now uses createList

Signed-off-by: emanuele <[email protected]>
emanuele 12 years ago
parent
commit
603d98bb55
2 changed files with 205 additions and 113 deletions
  1. 198 26
      Sources/PostModeration.php
  2. 7 87
      Themes/default/ModerationCenter.template.php

+ 198 - 26
Sources/PostModeration.php

@@ -307,7 +307,7 @@ function UnapprovedPosts()
  */
 function UnapprovedAttachments()
 {
-	global $txt, $scripturl, $context, $user_info, $sourcedir, $smcFunc;
+	global $txt, $scripturl, $context, $user_info, $sourcedir, $smcFunc, $modSettings;
 
 	$context['page_title'] = $txt['mc_unapproved_attachments'];
 
@@ -377,26 +377,158 @@ function UnapprovedAttachments()
 		}
 	}
 
-	// How many unapproved attachments in total?
-	$request = $smcFunc['db_query']('', '
-		SELECT COUNT(*)
-		FROM {db_prefix}attachments AS a
-			INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg)
-			INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
-		WHERE a.approved = {int:not_approved}
-			AND a.attachment_type = {int:attachment_type}
-			AND {query_see_board}
-			' . $approve_query,
-		array(
-			'not_approved' => 0,
-			'attachment_type' => 0,
-		)
+	require_once($sourcedir . '/Subs-List.php');
+
+	$listOptions = array(
+		'id' => 'mc_unapproved_attach',
+		'width' => '100%',
+		'items_per_page' => $modSettings['defaultMaxMessages'],
+		'no_items_label' => $txt['mc_unapproved_attachments_none_found'],
+		'base_href' => $scripturl . '?action=moderate;area=attachmod;sa=attachments',
+		'default_sort_col' => 'attach_name',
+		'get_items' => array(
+			'function' => 'list_getUnapprovedAttachments',
+			'params' => array(
+				$approve_query,
+			),
+		),
+		'get_count' => array(
+			'function' => 'list_getNumUnapprovedAttachments',
+			'params' => array(
+				$approve_query,
+			),
+		),
+		'columns' => array(
+			'attach_name' => array(
+				'header' => array(
+					'value' => $txt['mc_unapproved_attach_name'],
+				),
+				'data' => array(
+					'db' => 'filename',
+				),
+				'sort' => array(
+					'default' => 'a.filename',
+					'reverse' => 'a.filename DESC',
+				),
+			),
+			'attach_size' => array(
+				'header' => array(
+					'value' => $txt['mc_unapproved_attach_size'],
+				),
+				'data' => array(
+					'db' => 'size',
+				),
+				'sort' => array(
+					'default' => 'a.size',
+					'reverse' => 'a.size DESC',
+				),
+			),
+			'attach_poster' => array(
+				'header' => array(
+					'value' => $txt['mc_unapproved_attach_poster'],
+				),
+				'data' => array(
+					'function' => create_function('$data', '
+						return $data[\'poster\'][\'link\'];'
+					)
+				),
+				'sort' => array(
+					'default' => 'm.id_member',
+					'reverse' => 'm.id_member DESC',
+				),
+			),
+			'date' => array(
+				'header' => array(
+					'value' => $txt['date'],
+					'style' => 'width: 18%;',
+				),
+				'data' => array(
+					'db' => 'time',
+					'class' => 'smalltext',
+					'style' => 'white-space:nowrap;',
+				),
+				'sort' => array(
+					'default' => 'm.poster_time',
+					'reverse' => 'm.poster_time DESC',
+				),
+			),
+			'message' => array(
+				'header' => array(
+					'value' => $txt['post'],
+				),
+				'data' => array(
+					'function' => create_function('$data', '
+						return \'<a href="\' . $data[\'message\'][\'href\'] . \'">\' . shorten_subject($data[\'message\'][\'subject\'], 20) . \'</a>\';'
+					),
+					'class' => 'smalltext',
+					'style' => 'width:15em;',
+				),
+				'sort' => array(
+					'default' => 'm.subject',
+					'reverse' => 'm.subject DESC',
+				),
+			),
+			'action' => array(
+				'header' => array(
+					'value' => '<input type="checkbox" class="input_check" onclick="invertAll(this, this.form);" checked="checked" />',
+					'style' => 'width: 4%;',
+				),
+				'data' => array(
+					'sprintf' => array(
+						'format' => '<input type="checkbox" name="item[]" value="%1$d" checked="checked" class="input_check" />',
+						'params' => array(
+							'id' => false,
+						),
+					),
+					'style' => 'text-align: center;',
+				),
+			),
+		),
+		'form' => array(
+			'href' => $scripturl . '?action=moderate;area=attachmod;sa=attachments',
+			'include_sort' => true,
+			'include_start' => true,
+			'hidden_fields' => array(
+				$context['session_var'] => $context['session_id'],
+			),
+			'token' => 'mod-ap',
+		),
+		'additional_rows' => array(
+			array(
+				'position' => 'bottom_of_list',
+				'value' => '
+					<select name="do" onchange="if (this.value != 0 &amp;&amp; confirm(\'' . $txt['mc_unapproved_sure'] . '\')) submit();">
+						<option value="0">' . $txt['with_selected'] . ':</option>
+						<option value="0">-------------------</option>
+						<option value="approve">&nbsp;--&nbsp;' . $txt['approve'] . '</option>
+						<option value="delete">&nbsp;--&nbsp;' . $txt['delete'] . '</option>
+					</select>
+					<noscript><input type="submit" name="ml_go" value="' . $txt['go'] . '" class="button_submit" /></noscript>',
+				'align' => 'right',
+			),
+		),
 	);
-	list ($context['total_unapproved_attachments']) = $smcFunc['db_fetch_row']($request);
-	$smcFunc['db_free_result']($request);
 
-	$context['page_index'] = constructPageIndex($scripturl . '?action=moderate;area=attachmod;sa=attachments', $_GET['start'], $context['total_unapproved_attachments'], 10);
-	$context['start'] = $_GET['start'];
+	// Create the request list.
+	createToken('mod-ap');
+	createList($listOptions);
+
+	$context['sub_template'] = 'unapproved_attachments';
+}
+
+/**
+ * Callback function for UnapprovedAttachments
+ * retrieve all the attachments waiting for approval the approver can approve
+ * 
+ * @param int $start
+ * @param int $items_per_page
+ * @param string $sort
+ * @param string $approve_query additional restrictions based on the boards the approver can see
+ * @return array, an array of unapproved attachments
+ */
+function list_getUnapprovedAttachments($start, $items_per_page, $sort, $approve_query)
+{
+	global $smcFunc, $scripturl;
 
 	// Get all unapproved attachments.
 	$request = $smcFunc['db_query']('', '
@@ -412,19 +544,24 @@ function UnapprovedAttachments()
 		WHERE a.approved = {int:not_approved}
 			AND a.attachment_type = {int:attachment_type}
 			AND {query_see_board}
-			' . $approve_query . '
-		LIMIT ' . $context['start'] . ', 10',
+			{raw:approve_query}
+		ORDER BY {raw:sort}
+		LIMIT {int:start}, {int:items_per_page}',
 		array(
 			'not_approved' => 0,
 			'attachment_type' => 0,
+			'start' => $start,
+			'sort' => $sort,
+			'items_per_page' => $items_per_page,
+			'approve_query' => $approve_query,
 		)
 	);
-	$context['unapproved_items'] = array();
-	for ($i = 1; $row = $smcFunc['db_fetch_assoc']($request); $i++)
+
+	$unapproved_items = array();
+	while ($row = $smcFunc['db_fetch_assoc']($request))
 	{
-		$context['unapproved_items'][] = array(
+		$unapproved_items[] = array(
 			'id' => $row['id_attach'],
-			'alternate' => $i % 2,
 			'filename' => $row['filename'],
 			'size' => round($row['size'] / 1024, 2),
 			'time' => timeformat($row['poster_time']),
@@ -456,7 +593,42 @@ function UnapprovedAttachments()
 	}
 	$smcFunc['db_free_result']($request);
 
-	$context['sub_template'] = 'unapproved_attachments';
+	return $unapproved_items;
+}
+
+/**
+ * Callback function for UnapprovedAttachments
+ * count all the attachments waiting for approval the approver can approve
+ * 
+ * @param int $start
+ * @param int $items_per_page
+ * @param string $sort
+ * @param string $approve_query additional restrictions based on the boards the approver can see
+ * @return int, the number of unapproved attachments
+ */
+function list_getNumUnapprovedAttachments($approve_query)
+{
+	global $smcFunc;
+
+	// How many unapproved attachments in total?
+	$request = $smcFunc['db_query']('', '
+		SELECT COUNT(*)
+		FROM {db_prefix}attachments AS a
+			INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg)
+			INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
+		WHERE a.approved = {int:not_approved}
+			AND a.attachment_type = {int:attachment_type}
+			AND {query_see_board}
+			' . $approve_query,
+		array(
+			'not_approved' => 0,
+			'attachment_type' => 0,
+		)
+	);
+	list ($total_unapproved_attachments) = $smcFunc['db_fetch_row']($request);
+	$smcFunc['db_free_result']($request);
+
+	return $total_unapproved_attachments;
 }
 
 /**

+ 7 - 87
Themes/default/ModerationCenter.template.php

@@ -438,96 +438,16 @@ function template_unapproved_attachments()
 	// Show all the attachments still oustanding.
 	echo '
 	<div id="modcenter">
-		<form action="', $scripturl, '?action=moderate;area=attachmod;sa=attachments;start=', $context['start'], '" method="post" accept-charset="', $context['character_set'], '">
-			<div class="cat_bar">
-				<h3 class="catbg">', $txt['mc_unapproved_attachments'], '</h3>
-			</div>
-			<div class="information">
-				', $txt['mc_unapproved_attachments_desc'], '
-			</div>';
-
-	// The ever popular approve button, with the massively unpopular delete.
-	$approve_button = create_button('approve.png', 'approve', 'approve', 'class="centericon"');
-	$remove_button = create_button('delete.png', 'remove_message', 'remove', 'class="centericon"');
-
-	// None awaiting?
-	if (empty($context['unapproved_items']))
-		echo '
-			<div class="windowbg">
-				<span class="topslice"><span></span></span>
-				<div class="content">
-					<p class="centertext">', $txt['mc_unapproved_attachments_none_found'], '</p>
-				</div>
-				<span class="botslice"><span></span></span>
-			</div>';
-	else
-		echo '
-			<div class="pagesection">
-				<div class="floatleft">
-					', $txt['pages'], ': ', $context['page_index'], '
-				</div>
-			</div>
-			<table class="table_grid" width="100%">
-			<thead>
-				<tr class="catbg">
-					<th class="first_th">', $txt['mc_unapproved_attach_name'], '</th>
-					<th>', $txt['mc_unapproved_attach_size'], '</th>
-					<th>', $txt['mc_unapproved_attach_poster'], '</th>
-					<th>', $txt['date'], '</th>
-					<th class="last_th" nowrap="nowrap" align="center"><input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" checked="checked" /></th>
-				</tr>
-			</thead>
-			<tbody>';
-
-	foreach ($context['unapproved_items'] as $item)
-	{
-		echo '
-				<tr class="', $item['alternate'] ? 'windowbg' : 'windowbg2', '">
-					<td>
-						', $item['filename'], '
-					</td>
-					<td align="right">
-						', $item['size'], $txt['kilobyte'], '
-					</td>
-					<td>
-						', $item['poster']['link'], '
-					</td>
-					<td class="smalltext">
-						', $item['time'], '<br />', $txt['in'], ' <a href="', $item['message']['href'], '">', $item['message']['subject'], '</a>
-					</td>
-					<td width="4%" align="center">
-						<input type="checkbox" name="item[]" value="', $item['id'], '" checked="checked" class="input_check" />
-					</td>
-				</tr>';
-	}
-
-	if (!empty($context['unapproved_items']))
-		echo '
-			</tbody>
-			</table>';
-
-		echo '
-			<div class="pagesection">
-				<div class="floatright">
-					<select name="do" onchange="if (this.value != 0 &amp;&amp; confirm(\'', $txt['mc_unapproved_sure'], '\')) submit();">
-						<option value="0">', $txt['with_selected'], ':</option>
-						<option value="0">-------------------</option>
-						<option value="approve">&nbsp;--&nbsp;', $txt['approve'], '</option>
-						<option value="delete">&nbsp;--&nbsp;', $txt['delete'], '</option>
-					</select>
-					<noscript><input type="submit" name="ml_go" value="', $txt['go'], '" class="button_submit" /></noscript>
-				</div>';
+		<div class="cat_bar">
+			<h3 class="catbg">', $txt['mc_unapproved_attachments'], '</h3>
+		</div>
+		<div class="information">
+			', $txt['mc_unapproved_attachments_desc'], '
+		</div>';
 
-	if (!empty($context['unapproved_items']))
-		echo '
-				<div class="floatleft">
-					<div class="pagelinks">', $txt['pages'], ': ', $context['page_index'], '</div>
-				</div>';
+	template_show_list('mc_unapproved_attach');
 
 	echo '
-			</div>
-			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
-		</form>
 	</div>
 	<br class="clear" />';
 }