Browse Source

! When deleting or restoring a topic, don't actually touch the messages' icons, instead alter the icon softly if it's in the recycle bin board.

Signed-off-by: Peter Spicer <[email protected]>
Peter Spicer 10 years ago
parent
commit
1b0d164057
8 changed files with 58 additions and 54 deletions
  1. 11 1
      SSI.php
  2. 8 4
      Sources/Display.php
  3. 1 0
      Sources/Load.php
  4. 4 1
      Sources/MessageIndex.php
  5. 8 0
      Sources/Recent.php
  6. 10 44
      Sources/RemoveTopic.php
  7. 11 0
      Sources/Search.php
  8. 5 4
      Sources/Subs-Members.php

+ 11 - 1
SSI.php

@@ -478,6 +478,8 @@ function ssi_recentTopics($num_recent = 8, $exclude_boards = null, $include_boar
 	if (empty($topics))
 		return array();
 
+	$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
+
 	// Find all the posts in distinct topics.  Newer ones will have higher IDs.
 	$request = $smcFunc['db_query']('substring', '
 		SELECT
@@ -509,6 +511,10 @@ function ssi_recentTopics($num_recent = 8, $exclude_boards = null, $include_boar
 		censorText($row['subject']);
 		censorText($row['body']);
 
+		// Recycled icon
+		if (!empty($recycle_board) && $topics[$row['id_topic']]['id_board'])
+			$row['icon'] = 'recycled';
+
 		if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']]))
 			$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';
 
@@ -1716,7 +1722,7 @@ function ssi_boardNews($board = null, $limit = null, $start = null, $length = nu
 	$request = $smcFunc['db_query']('', '
 		SELECT
 			m.icon, m.subject, m.body, IFNULL(mem.real_name, m.poster_name) AS poster_name, m.poster_time,
-			t.num_replies, t.id_topic, m.id_member, m.smileys_enabled, m.id_msg, t.locked, t.id_last_msg
+			t.num_replies, t.id_topic, m.id_member, m.smileys_enabled, m.id_msg, t.locked, t.id_last_msg, m.id_board
 		FROM {db_prefix}topics AS t
 			INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
 			LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
@@ -1728,6 +1734,7 @@ function ssi_boardNews($board = null, $limit = null, $start = null, $length = nu
 		)
 	);
 	$return = array();
+	$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
 	while ($row = $smcFunc['db_fetch_assoc']($request))
 	{
 		// If we want to limit the length of the post.
@@ -1751,6 +1758,9 @@ function ssi_boardNews($board = null, $limit = null, $start = null, $length = nu
 
 		$row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
 
+		if (!empty($recycle_board) && $row['id_board'] == $recycle_board)
+			$row['icon'] = 'recycled';
+
 		// Check that this message icon is there...
 		if (!empty($modSettings['messageIconChecks_enable']) && !isset($icon_sources[$row['icon']]))
 			$icon_sources[$row['icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['icon'] . '.png') ? 'images_url' : 'default_images_url';

+ 8 - 4
Sources/Display.php

@@ -159,7 +159,7 @@ function Display()
 			t.num_replies, t.num_views, t.locked, ms.subject, t.is_sticky, t.id_poll,
 			t.id_member_started, t.id_first_msg, t.id_last_msg, t.approved, t.unapproved_posts, t.id_redirect_topic,
 			' . ($user_info['is_guest'] ? 't.id_last_msg + 1' : 'IFNULL(lt.id_msg, IFNULL(lmr.id_msg, -1)) + 1') . ' AS new_from
-			' . (!empty($modSettings['recycle_board']) && $modSettings['recycle_board'] == $board ? ', id_previous_board, id_previous_topic' : '') . '
+			' . (!empty($board_info['recycle']) ? ', id_previous_board, id_previous_topic' : '') . '
 			' . (!empty($topic_selects) ? implode(',', $topic_selects) : '') . '
 			' . (!$user_info['is_guest'] ? ', IFNULL(lt.unwatched, 0) as unwatched' : '') . '
 		FROM {db_prefix}topics AS t
@@ -1120,8 +1120,8 @@ function Display()
 	$context['can_remove_post'] = allowedTo('delete_any') || (allowedTo('delete_replies') && $context['user']['started']);
 
 	// Can restore topic?  That's if the topic is in the recycle board and has a previous restore state.
-	$context['can_restore_topic'] &= !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $board && !empty($topicinfo['id_previous_board']);
-	$context['can_restore_msg'] &= !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $board && !empty($topicinfo['id_previous_topic']);
+	$context['can_restore_topic'] &= !empty($board_info['recycle']) && !empty($topicinfo['id_previous_board']);
+	$context['can_restore_msg'] &= !empty($board_info['recycle']) && !empty($topicinfo['id_previous_topic']);
 
 	// Check if the draft functions are enabled and that they have permission to use them (for quick reply.)
 	$context['drafts_save'] = !empty($modSettings['drafts_post_enabled']) && allowedTo('post_draft') && $context['can_reply'];
@@ -1217,7 +1217,7 @@ function Display()
 function prepareDisplayContext($reset = false)
 {
 	global $settings, $txt, $modSettings, $scripturl, $options, $user_info, $smcFunc;
-	global $memberContext, $context, $messages_request, $topic;
+	global $memberContext, $context, $messages_request, $topic, $board_info;
 
 	static $counter = null;
 
@@ -1295,6 +1295,10 @@ function prepareDisplayContext($reset = false)
 	// Run BBC interpreter on the message.
 	$message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']);
 
+	// If it's in the recycle bin we need to override whatever icon we did have.
+	if (!empty($board_info['recycle']))
+		$message['icon'] = 'recycled';
+
 	// Compose the memory eat- I mean message array.
 	$output = array(
 		'attachment' => loadAttachmentContext($message['id_msg']),

+ 1 - 0
Sources/Load.php

@@ -630,6 +630,7 @@ function loadBoard()
 				'override_theme' => !empty($row['override_theme']),
 				'profile' => $row['id_profile'],
 				'redirect' => $row['redirect'],
+				'recycle' => !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) && $modSettings['recycle_board'] == $board,
 				'posts_count' => empty($row['count_posts']),
 				'cur_topic_approved' => empty($topic) || $row['approved'],
 				'cur_topic_starter' => empty($topic) ? 0 : $row['id_member_started'],

+ 4 - 1
Sources/MessageIndex.php

@@ -502,6 +502,9 @@ function MessageIndex()
 					$context['icon_sources'][$row['last_icon']] = 'images_url';
 			}
 
+			if (!empty($board_info['recycle']))
+				$row['first_icon'] = 'recycled';
+
 			// 'Print' the topic info.
 			$context['topics'][$row['id_topic']] = array(
 				'id' => $row['id_topic'],
@@ -611,7 +614,7 @@ function MessageIndex()
 		// Ignore approving own topics as it's unlikely to come up...
 		$context['can_approve'] = $modSettings['postmod_active'] && allowedTo('approve_posts') && !empty($board_info['unapproved_topics']);
 		// Can we restore topics?
-		$context['can_restore'] = allowedTo('move_any') && !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $board;
+		$context['can_restore'] = allowedTo('move_any') && !empty($board_info['recycle']);
 
 		if ($user_info['is_admin'] || $modSettings['topic_move_any'])
 			$context['can_move_any'] = true;

+ 8 - 0
Sources/Recent.php

@@ -1154,6 +1154,7 @@ function UnreadTopics()
 
 	$context['topics'] = array();
 	$topic_ids = array();
+	$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? $modSettings['recycle_board'] : 0;
 
 	while ($row = $smcFunc['db_fetch_assoc']($request))
 	{
@@ -1237,6 +1238,13 @@ function UnreadTopics()
 				$context['icon_sources'][$row['last_icon']] = file_exists($settings['theme_dir'] . '/images/post/' . $row['last_icon'] . '.png') ? 'images_url' : 'default_images_url';
 		}
 
+		// Force the recycling icon if appropriate
+		if ($recycle_board == $row['id_board'])
+		{
+			$row['first_icon'] = 'recycled';
+			$row['last_icon'] = 'recycled';
+		}
+
 		// And build the array.
 		$context['topics'][$row['id_topic']] = array(
 			'id' => $row['id_topic'],

+ 10 - 44
Sources/RemoveTopic.php

@@ -239,6 +239,8 @@ function removeTopics($topics, $decreasePostCount = true, $ignoreRecycling = fal
 	if (is_numeric($topics))
 		$topics = array($topics);
 
+	$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
+
 	// Decrease the post counts.
 	if ($decreasePostCount)
 	{
@@ -246,14 +248,14 @@ function removeTopics($topics, $decreasePostCount = true, $ignoreRecycling = fal
 			SELECT m.id_member, COUNT(*) AS posts
 			FROM {db_prefix}messages AS m
 				INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
-			WHERE m.id_topic IN ({array_int:topics})
-				AND m.icon != {string:recycled}
+			WHERE m.id_topic IN ({array_int:topics})' . (!empty($recycle_board) ? '
+				AND m.id_board != {int:recycled_board}' : '') . '
 				AND b.count_posts = {int:do_count_posts}
 				AND m.approved = {int:is_approved}
 			GROUP BY m.id_member',
 			array(
 				'do_count_posts' => 0,
-				'recycled' => 'recycled',
+				'recycled_board' => $recycle_board,
 				'topics' => $topics,
 				'is_approved' => 1,
 			)
@@ -267,7 +269,7 @@ function removeTopics($topics, $decreasePostCount = true, $ignoreRecycling = fal
 	}
 
 	// Recycle topics that aren't in the recycle board...
-	if (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 && !$ignoreRecycling)
+	if (!empty($recycle_board) && !$ignoreRecycling)
 	{
 		$request = $smcFunc['db_query']('', '
 			SELECT id_topic, id_board, unapproved_posts, approved
@@ -276,7 +278,7 @@ function removeTopics($topics, $decreasePostCount = true, $ignoreRecycling = fal
 				AND id_board != {int:recycle_board}
 			LIMIT ' . count($topics),
 			array(
-				'recycle_board' => $modSettings['recycle_board'],
+				'recycle_board' => $recycle_board,
 				'topics' => $topics,
 			)
 		);
@@ -305,17 +307,6 @@ function removeTopics($topics, $decreasePostCount = true, $ignoreRecycling = fal
 			}
 			$smcFunc['db_free_result']($request);
 
-			// Mark recycled topics as recycled.
-			$smcFunc['db_query']('', '
-				UPDATE {db_prefix}messages
-				SET icon = {string:recycled}
-				WHERE id_topic IN ({array_int:recycle_topics})',
-				array(
-					'recycle_topics' => $recycleTopics,
-					'recycled' => 'recycled',
-				)
-			);
-
 			// Move the topics to the recycle board.
 			require_once($sourcedir . '/MoveTopic.php');
 			moveTopics($recycleTopics, $modSettings['recycle_board']);
@@ -573,6 +564,8 @@ function removeMessage($message, $decreasePostCount = true)
 	if (empty($message) || !is_numeric($message))
 		return false;
 
+	$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
+
 	$request = $smcFunc['db_query']('', '
 		SELECT
 			m.id_member, m.icon, m.poster_time, m.subject,' . (empty($modSettings['search_custom_index_config']) ? '' : ' m.body,') . '
@@ -696,7 +689,7 @@ function removeMessage($message, $decreasePostCount = true)
 	}
 
 	// Deleting a recycled message can not lower anyone's post count.
-	if ($row['icon'] == 'recycled')
+	if (!empty($recycle_board) && $row['id_board'] == $recycle_board)
 		$decreasePostCount = false;
 
 	// This is the last post, update the last post on the board.
@@ -813,14 +806,12 @@ function removeMessage($message, $decreasePostCount = true)
 				SET
 					id_topic = {int:id_topic},
 					id_board = {int:recycle_board},
-					icon = {string:recycled},
 					approved = {int:is_approved}
 				WHERE id_msg = {int:id_msg}',
 				array(
 					'id_topic' => $topicID,
 					'recycle_board' => $modSettings['recycle_board'],
 					'id_msg' => $message,
-					'recycled' => 'recycled',
 					'is_approved' => 1,
 				)
 			);
@@ -1129,18 +1120,6 @@ function RestoreTopic()
 					$unfound_messages[$msg['id']] = $msg['subject'];
 			}
 		}
-
-		// Put the icons back.
-		if (!empty($messages))
-			$smcFunc['db_query']('', '
-				UPDATE {db_prefix}messages
-				SET icon = {string:icon}
-				WHERE id_msg IN ({array_int:messages})',
-				array(
-					'icon' => 'xx',
-					'messages' => $messages,
-				)
-			);
 	}
 
 	// Now any topics?
@@ -1175,17 +1154,6 @@ function RestoreTopic()
 			// Ok we got here so me move them from here to there.
 			moveTopics($row['id_topic'], $row['id_previous_board']);
 
-			// Lets remove the recycled icon.
-			$smcFunc['db_query']('', '
-				UPDATE {db_prefix}messages
-				SET icon = {string:icon}
-				WHERE id_topic = {int:id_topic}',
-				array(
-					'icon' => 'xx',
-					'id_topic' => $row['id_topic'],
-				)
-			);
-
 			// Lets see if the board that we are returning to has post count enabled.
 			$request2 = $smcFunc['db_query']('', '
 				SELECT count_posts
@@ -1304,12 +1272,10 @@ function mergePosts($msgs = array(), $from_topic, $target_topic)
 		SET
 			id_topic = {int:target_topic},
 			id_board = {int:target_board},
-			icon = {string:icon}
 		WHERE id_msg IN({array_int:msgs})',
 		array(
 			'target_topic' => $target_topic,
 			'target_board' => $target_board,
-			'icon' => $target_board == $modSettings['recycle_board'] ? 'recycled' : 'xx',
 			'msgs' => $msgs,
 		)
 	);

+ 11 - 0
Sources/Search.php

@@ -1868,6 +1868,10 @@ function prepareSearchContext($reset = false)
 	global $txt, $modSettings, $scripturl, $user_info;
 	global $memberContext, $context, $settings, $options, $messages_request;
 	global $boards_can, $participants, $smcFunc;
+	static $recycle_board = null;
+
+	if ($recycle_board === null)
+		$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
 
 	// Remember which message this is.  (ie. reply #83)
 	static $counter = null;
@@ -1969,6 +1973,13 @@ function prepareSearchContext($reset = false)
 	// Make sure we don't end up with a practically empty message body.
 	$message['body'] = preg_replace('~^(?:&nbsp;)+$~', '', $message['body']);
 
+	if (!empty($recycle_board) && $message['id_board'] == $recycle_board)
+	{
+		$message['first_icon'] = 'recycled';
+		$message['last_icon'] = 'recycled';
+		$message['icon'] = 'recycled';
+	}
+
 	// Sadly, we need to check the icon ain't broke.
 	if (!empty($modSettings['messageIconChecks_enable']))
 	{

+ 5 - 4
Sources/Subs-Members.php

@@ -1165,7 +1165,7 @@ function membersAllowedTo($permission, $board_id = null)
  */
 function reattributePosts($memID, $email = false, $membername = false, $post_count = false)
 {
-	global $smcFunc;
+	global $smcFunc, $modSettings;
 
 	$updated = array(
 		'messages' => 0,
@@ -1192,13 +1192,14 @@ function reattributePosts($memID, $email = false, $membername = false, $post_cou
 	// If they want the post count restored then we need to do some research.
 	if ($post_count)
 	{
+		$recycle_board = !empty($modSettings['recycle_enable']) && !empty($modSettings['recycle_board']) ? (int) $modSettings['recycle_board'] : 0;
 		$request = $smcFunc['db_query']('', '
 			SELECT COUNT(*)
 			FROM {db_prefix}messages AS m
 				INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND b.count_posts = {int:count_posts})
 			WHERE m.id_member = {int:guest_id}
-				AND m.approved = {int:is_approved}
-				AND m.icon != {string:recycled_icon}' . (empty($email) ? '' : '
+				AND m.approved = {int:is_approved}' . (!empty($recycle_board) ? '
+				AND m.id_board != {int:recycled_board}' : '') . (empty($email) ? '' : '
 				AND m.poster_email = {string:email_address}') . (empty($membername) ? '' : '
 				AND m.poster_name = {string:member_name}'),
 			array(
@@ -1207,7 +1208,7 @@ function reattributePosts($memID, $email = false, $membername = false, $post_cou
 				'email_address' => $email,
 				'member_name' => $membername,
 				'is_approved' => 1,
-				'recycled_icon' => 'recycled',
+				'recycled_board' => $recycle_board,
 			)
 		);
 		list ($messageCount) = $smcFunc['db_fetch_row']($request);