Conditions | 141 |
Total Lines | 581 |
Code Lines | 292 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
756 | function QuickModeration() |
||
757 | { |
||
758 | global $sourcedir, $board, $user_info, $modSettings, $smcFunc, $context; |
||
759 | |||
760 | // Check the session = get or post. |
||
761 | checkSession('request'); |
||
762 | |||
763 | // Lets go straight to the restore area. |
||
764 | if (isset($_REQUEST['qaction']) && $_REQUEST['qaction'] == 'restore' && !empty($_REQUEST['topics'])) |
||
765 | redirectexit('action=restoretopic;topics=' . implode(',', $_REQUEST['topics']) . ';' . $context['session_var'] . '=' . $context['session_id']); |
||
766 | |||
767 | if (isset($_SESSION['topicseen_cache'])) |
||
768 | $_SESSION['topicseen_cache'] = array(); |
||
769 | |||
770 | // This is going to be needed to send off the notifications and for updateLastMessages(). |
||
771 | require_once($sourcedir . '/Subs-Post.php'); |
||
772 | |||
773 | // Remember the last board they moved things to. |
||
774 | if (isset($_REQUEST['move_to'])) |
||
775 | $_SESSION['move_to_topic'] = $_REQUEST['move_to']; |
||
776 | |||
777 | // Only a few possible actions. |
||
778 | $possibleActions = array(); |
||
779 | |||
780 | if (!empty($board)) |
||
781 | { |
||
782 | $boards_can = array( |
||
783 | 'make_sticky' => allowedTo('make_sticky') ? array($board) : array(), |
||
784 | 'move_any' => allowedTo('move_any') ? array($board) : array(), |
||
785 | 'move_own' => allowedTo('move_own') ? array($board) : array(), |
||
786 | 'remove_any' => allowedTo('remove_any') ? array($board) : array(), |
||
787 | 'remove_own' => allowedTo('remove_own') ? array($board) : array(), |
||
788 | 'lock_any' => allowedTo('lock_any') ? array($board) : array(), |
||
789 | 'lock_own' => allowedTo('lock_own') ? array($board) : array(), |
||
790 | 'merge_any' => allowedTo('merge_any') ? array($board) : array(), |
||
791 | 'approve_posts' => allowedTo('approve_posts') ? array($board) : array(), |
||
792 | ); |
||
793 | |||
794 | $redirect_url = 'board=' . $board . '.' . $_REQUEST['start']; |
||
795 | } |
||
796 | else |
||
797 | { |
||
798 | $boards_can = boardsAllowedTo(array('make_sticky', 'move_any', 'move_own', 'remove_any', 'remove_own', 'lock_any', 'lock_own', 'merge_any', 'approve_posts'), true, false); |
||
799 | |||
800 | $redirect_url = isset($_POST['redirect_url']) ? $_POST['redirect_url'] : (isset($_SESSION['old_url']) ? $_SESSION['old_url'] : ''); |
||
801 | } |
||
802 | |||
803 | // Are we enforcing the "no moving topics to boards where you can't post new ones" rule? |
||
804 | if (!$user_info['is_admin'] && !$modSettings['topic_move_any']) |
||
805 | { |
||
806 | // Don't count this board, if it's specified |
||
807 | if (!empty($board)) |
||
808 | { |
||
809 | $boards_can['post_new'] = array_diff(boardsAllowedTo('post_new'), array($board)); |
||
810 | } |
||
811 | else |
||
812 | { |
||
813 | $boards_can['post_new'] = boardsAllowedTo('post_new'); |
||
814 | } |
||
815 | |||
816 | if (empty($boards_can['post_new'])) |
||
817 | { |
||
818 | $boards_can['move_any'] = $boards_can['move_own'] = array(); |
||
819 | } |
||
820 | } |
||
821 | |||
822 | if (!$user_info['is_guest']) |
||
823 | $possibleActions[] = 'markread'; |
||
824 | |||
825 | if (!empty($boards_can['make_sticky'])) |
||
826 | $possibleActions[] = 'sticky'; |
||
827 | |||
828 | if (!empty($boards_can['move_any']) || !empty($boards_can['move_own'])) |
||
829 | $possibleActions[] = 'move'; |
||
830 | |||
831 | if (!empty($boards_can['remove_any']) || !empty($boards_can['remove_own'])) |
||
832 | $possibleActions[] = 'remove'; |
||
833 | |||
834 | if (!empty($boards_can['lock_any']) || !empty($boards_can['lock_own'])) |
||
835 | $possibleActions[] = 'lock'; |
||
836 | |||
837 | if (!empty($boards_can['merge_any'])) |
||
838 | $possibleActions[] = 'merge'; |
||
839 | |||
840 | if (!empty($boards_can['approve_posts'])) |
||
841 | $possibleActions[] = 'approve'; |
||
842 | |||
843 | // Two methods: $_REQUEST['actions'] (id_topic => action), and $_REQUEST['topics'] and $_REQUEST['qaction']. |
||
844 | // (if action is 'move', $_REQUEST['move_to'] or $_REQUEST['move_tos'][$topic] is used.) |
||
845 | if (!empty($_REQUEST['topics'])) |
||
846 | { |
||
847 | // If the action isn't valid, just quit now. |
||
848 | if (empty($_REQUEST['qaction']) || !in_array($_REQUEST['qaction'], $possibleActions)) |
||
849 | redirectexit($redirect_url); |
||
850 | |||
851 | // Merge requires all topics as one parameter and can be done at once. |
||
852 | if ($_REQUEST['qaction'] == 'merge') |
||
853 | { |
||
854 | // Merge requires at least two topics. |
||
855 | if (empty($_REQUEST['topics']) || count($_REQUEST['topics']) < 2) |
||
856 | redirectexit($redirect_url); |
||
857 | |||
858 | require_once($sourcedir . '/SplitTopics.php'); |
||
859 | return MergeExecute($_REQUEST['topics']); |
||
860 | } |
||
861 | |||
862 | // Just convert to the other method, to make it easier. |
||
863 | foreach ($_REQUEST['topics'] as $topic) |
||
864 | $_REQUEST['actions'][(int) $topic] = $_REQUEST['qaction']; |
||
865 | } |
||
866 | |||
867 | // Weird... how'd you get here? |
||
868 | if (empty($_REQUEST['actions'])) |
||
869 | redirectexit($redirect_url); |
||
870 | |||
871 | // Validate each action. |
||
872 | $temp = array(); |
||
873 | foreach ($_REQUEST['actions'] as $topic => $action) |
||
874 | { |
||
875 | if (in_array($action, $possibleActions)) |
||
876 | $temp[(int) $topic] = $action; |
||
877 | } |
||
878 | $_REQUEST['actions'] = $temp; |
||
879 | |||
880 | if (!empty($_REQUEST['actions'])) |
||
881 | { |
||
882 | // Find all topics... |
||
883 | $request = $smcFunc['db_query']('', ' |
||
884 | SELECT id_topic, id_member_started, id_board, locked, approved, unapproved_posts |
||
885 | FROM {db_prefix}topics |
||
886 | WHERE id_topic IN ({array_int:action_topic_ids}) |
||
887 | LIMIT {int:limit}', |
||
888 | array( |
||
889 | 'action_topic_ids' => array_keys($_REQUEST['actions']), |
||
890 | 'limit' => count($_REQUEST['actions']), |
||
891 | ) |
||
892 | ); |
||
893 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
894 | { |
||
895 | if (!empty($board)) |
||
896 | { |
||
897 | if ($row['id_board'] != $board || ($modSettings['postmod_active'] && !$row['approved'] && !allowedTo('approve_posts'))) |
||
898 | unset($_REQUEST['actions'][$row['id_topic']]); |
||
899 | } |
||
900 | else |
||
901 | { |
||
902 | // Don't allow them to act on unapproved posts they can't see... |
||
903 | if ($modSettings['postmod_active'] && !$row['approved'] && !in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])) |
||
904 | unset($_REQUEST['actions'][$row['id_topic']]); |
||
905 | // Goodness, this is fun. We need to validate the action. |
||
906 | elseif ($_REQUEST['actions'][$row['id_topic']] == 'sticky' && !in_array(0, $boards_can['make_sticky']) && !in_array($row['id_board'], $boards_can['make_sticky'])) |
||
907 | unset($_REQUEST['actions'][$row['id_topic']]); |
||
908 | elseif ($_REQUEST['actions'][$row['id_topic']] == 'move' && !in_array(0, $boards_can['move_any']) && !in_array($row['id_board'], $boards_can['move_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['move_own']) && !in_array($row['id_board'], $boards_can['move_own'])))) |
||
909 | unset($_REQUEST['actions'][$row['id_topic']]); |
||
910 | elseif ($_REQUEST['actions'][$row['id_topic']] == 'remove' && !in_array(0, $boards_can['remove_any']) && !in_array($row['id_board'], $boards_can['remove_any']) && ($row['id_member_started'] != $user_info['id'] || (!in_array(0, $boards_can['remove_own']) && !in_array($row['id_board'], $boards_can['remove_own'])))) |
||
911 | unset($_REQUEST['actions'][$row['id_topic']]); |
||
912 | // @todo $locked is not set, what are you trying to do? (taking the change it is supposed to be $row['locked']) |
||
913 | elseif ($_REQUEST['actions'][$row['id_topic']] == 'lock' && !in_array(0, $boards_can['lock_any']) && !in_array($row['id_board'], $boards_can['lock_any']) && ($row['id_member_started'] != $user_info['id'] || $row['locked'] == 1 || (!in_array(0, $boards_can['lock_own']) && !in_array($row['id_board'], $boards_can['lock_own'])))) |
||
914 | unset($_REQUEST['actions'][$row['id_topic']]); |
||
915 | // If the topic is approved then you need permission to approve the posts within. |
||
916 | elseif ($_REQUEST['actions'][$row['id_topic']] == 'approve' && (!$row['unapproved_posts'] || (!in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])))) |
||
917 | unset($_REQUEST['actions'][$row['id_topic']]); |
||
918 | } |
||
919 | } |
||
920 | $smcFunc['db_free_result']($request); |
||
921 | } |
||
922 | |||
923 | $stickyCache = array(); |
||
924 | $moveCache = array(0 => array(), 1 => array()); |
||
925 | $removeCache = array(); |
||
926 | $lockCache = array(); |
||
927 | $markCache = array(); |
||
928 | $approveCache = array(); |
||
929 | |||
930 | // Separate the actions. |
||
931 | foreach ($_REQUEST['actions'] as $topic => $action) |
||
932 | { |
||
933 | $topic = (int) $topic; |
||
934 | |||
935 | if ($action == 'markread') |
||
936 | $markCache[] = $topic; |
||
937 | elseif ($action == 'sticky') |
||
938 | $stickyCache[] = $topic; |
||
939 | elseif ($action == 'move') |
||
940 | { |
||
941 | require_once($sourcedir . '/MoveTopic.php'); |
||
942 | moveTopicConcurrence(); |
||
943 | |||
944 | // $moveCache[0] is the topic, $moveCache[1] is the board to move to. |
||
945 | $moveCache[1][$topic] = (int) (isset($_REQUEST['move_tos'][$topic]) ? $_REQUEST['move_tos'][$topic] : $_REQUEST['move_to']); |
||
946 | |||
947 | if (empty($moveCache[1][$topic])) |
||
948 | continue; |
||
949 | |||
950 | // Never move topics to redirect boards |
||
951 | $redirect_boards = array(); |
||
952 | $request = $smcFunc['db_query']('', ' |
||
953 | SELECT id_board |
||
954 | FROM {db_prefix}boards |
||
955 | WHERE redirect != {string:blank_redirect}', |
||
956 | array( |
||
957 | 'blank_redirect' => '', |
||
958 | ) |
||
959 | ); |
||
960 | while ($row = $smcFunc['db_fetch_row']($request)) |
||
961 | $redirect_boards[] = $row[0]; |
||
962 | $smcFunc['db_free_result']($request); |
||
963 | |||
964 | if (in_array($moveCache[1][$topic], $redirect_boards)) |
||
965 | continue; |
||
966 | |||
967 | $moveCache[0][] = $topic; |
||
968 | } |
||
969 | elseif ($action == 'remove') |
||
970 | $removeCache[] = $topic; |
||
971 | elseif ($action == 'lock') |
||
972 | $lockCache[] = $topic; |
||
973 | elseif ($action == 'approve') |
||
974 | $approveCache[] = $topic; |
||
975 | } |
||
976 | |||
977 | if (empty($board)) |
||
978 | $affectedBoards = array(); |
||
979 | else |
||
980 | $affectedBoards = array($board => array(0, 0)); |
||
981 | |||
982 | // Do all the stickies... |
||
983 | if (!empty($stickyCache)) |
||
984 | { |
||
985 | $smcFunc['db_query']('', ' |
||
986 | UPDATE {db_prefix}topics |
||
987 | SET is_sticky = CASE WHEN is_sticky = {int:is_sticky} THEN 0 ELSE 1 END |
||
988 | WHERE id_topic IN ({array_int:sticky_topic_ids})', |
||
989 | array( |
||
990 | 'sticky_topic_ids' => $stickyCache, |
||
991 | 'is_sticky' => 1, |
||
992 | ) |
||
993 | ); |
||
994 | |||
995 | // Get the board IDs and Sticky status |
||
996 | $request = $smcFunc['db_query']('', ' |
||
997 | SELECT id_topic, id_board, is_sticky |
||
998 | FROM {db_prefix}topics |
||
999 | WHERE id_topic IN ({array_int:sticky_topic_ids}) |
||
1000 | LIMIT {int:limit}', |
||
1001 | array( |
||
1002 | 'sticky_topic_ids' => $stickyCache, |
||
1003 | 'limit' => count($stickyCache), |
||
1004 | ) |
||
1005 | ); |
||
1006 | $stickyCacheBoards = array(); |
||
1007 | $stickyCacheStatus = array(); |
||
1008 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
1009 | { |
||
1010 | $stickyCacheBoards[$row['id_topic']] = $row['id_board']; |
||
1011 | $stickyCacheStatus[$row['id_topic']] = empty($row['is_sticky']); |
||
1012 | } |
||
1013 | $smcFunc['db_free_result']($request); |
||
1014 | } |
||
1015 | |||
1016 | // Move sucka! (this is, by the by, probably the most complicated part....) |
||
1017 | if (!empty($moveCache[0])) |
||
1018 | { |
||
1019 | // I know - I just KNOW you're trying to beat the system. Too bad for you... we CHECK :P. |
||
1020 | $request = $smcFunc['db_query']('', ' |
||
1021 | SELECT t.id_topic, t.id_board, b.count_posts |
||
1022 | FROM {db_prefix}topics AS t |
||
1023 | LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board) |
||
1024 | WHERE t.id_topic IN ({array_int:move_topic_ids})' . (!empty($board) && !allowedTo('move_any') ? ' |
||
1025 | AND t.id_member_started = {int:current_member}' : '') . ' |
||
1026 | LIMIT {int:limit}', |
||
1027 | array( |
||
1028 | 'current_member' => $user_info['id'], |
||
1029 | 'move_topic_ids' => $moveCache[0], |
||
1030 | 'limit' => count($moveCache[0]) |
||
1031 | ) |
||
1032 | ); |
||
1033 | $moveTos = array(); |
||
1034 | $moveCache2 = array(); |
||
1035 | $countPosts = array(); |
||
1036 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
1037 | { |
||
1038 | $to = $moveCache[1][$row['id_topic']]; |
||
1039 | |||
1040 | if (empty($to)) |
||
1041 | continue; |
||
1042 | |||
1043 | // Does this topic's board count the posts or not? |
||
1044 | $countPosts[$row['id_topic']] = empty($row['count_posts']); |
||
1045 | |||
1046 | if (!isset($moveTos[$to])) |
||
1047 | $moveTos[$to] = array(); |
||
1048 | |||
1049 | $moveTos[$to][] = $row['id_topic']; |
||
1050 | |||
1051 | // For reporting... |
||
1052 | $moveCache2[] = array($row['id_topic'], $row['id_board'], $to); |
||
1053 | } |
||
1054 | $smcFunc['db_free_result']($request); |
||
1055 | |||
1056 | $moveCache = $moveCache2; |
||
1057 | |||
1058 | require_once($sourcedir . '/MoveTopic.php'); |
||
1059 | |||
1060 | // Do the actual moves... |
||
1061 | foreach ($moveTos as $to => $topics) |
||
1062 | moveTopics($topics, $to); |
||
1063 | |||
1064 | // Does the post counts need to be updated? |
||
1065 | if (!empty($moveTos)) |
||
1066 | { |
||
1067 | $topicRecounts = array(); |
||
1068 | $request = $smcFunc['db_query']('', ' |
||
1069 | SELECT id_board, count_posts |
||
1070 | FROM {db_prefix}boards |
||
1071 | WHERE id_board IN ({array_int:move_boards})', |
||
1072 | array( |
||
1073 | 'move_boards' => array_keys($moveTos), |
||
1074 | ) |
||
1075 | ); |
||
1076 | |||
1077 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
1078 | { |
||
1079 | $cp = empty($row['count_posts']); |
||
1080 | |||
1081 | // Go through all the topics that are being moved to this board. |
||
1082 | foreach ($moveTos[$row['id_board']] as $topic) |
||
1083 | { |
||
1084 | // If both boards have the same value for post counting then no adjustment needs to be made. |
||
1085 | if ($countPosts[$topic] != $cp) |
||
1086 | { |
||
1087 | // If the board being moved to does count the posts then the other one doesn't so add to their post count. |
||
1088 | $topicRecounts[$topic] = $cp ? '+' : '-'; |
||
1089 | } |
||
1090 | } |
||
1091 | } |
||
1092 | |||
1093 | $smcFunc['db_free_result']($request); |
||
1094 | |||
1095 | if (!empty($topicRecounts)) |
||
1096 | { |
||
1097 | $members = array(); |
||
1098 | |||
1099 | // Get all the members who have posted in the moved topics. |
||
1100 | $request = $smcFunc['db_query']('', ' |
||
1101 | SELECT id_member, id_topic |
||
1102 | FROM {db_prefix}messages |
||
1103 | WHERE id_topic IN ({array_int:moved_topic_ids})', |
||
1104 | array( |
||
1105 | 'moved_topic_ids' => array_keys($topicRecounts), |
||
1106 | ) |
||
1107 | ); |
||
1108 | |||
1109 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
1110 | { |
||
1111 | if (!isset($members[$row['id_member']])) |
||
1112 | $members[$row['id_member']] = 0; |
||
1113 | |||
1114 | if ($topicRecounts[$row['id_topic']] === '+') |
||
1115 | $members[$row['id_member']] += 1; |
||
1116 | else |
||
1117 | $members[$row['id_member']] -= 1; |
||
1118 | } |
||
1119 | |||
1120 | $smcFunc['db_free_result']($request); |
||
1121 | |||
1122 | // And now update them member's post counts |
||
1123 | foreach ($members as $id_member => $post_adj) |
||
1124 | updateMemberData($id_member, array('posts' => 'posts + ' . $post_adj)); |
||
1125 | } |
||
1126 | } |
||
1127 | } |
||
1128 | |||
1129 | // Now delete the topics... |
||
1130 | if (!empty($removeCache)) |
||
1131 | { |
||
1132 | // They can only delete their own topics. (we wouldn't be here if they couldn't do that..) |
||
1133 | $result = $smcFunc['db_query']('', ' |
||
1134 | SELECT id_topic, id_board |
||
1135 | FROM {db_prefix}topics |
||
1136 | WHERE id_topic IN ({array_int:removed_topic_ids})' . (!empty($board) && !allowedTo('remove_any') ? ' |
||
1137 | AND id_member_started = {int:current_member}' : '') . ' |
||
1138 | LIMIT {int:limit}', |
||
1139 | array( |
||
1140 | 'current_member' => $user_info['id'], |
||
1141 | 'removed_topic_ids' => $removeCache, |
||
1142 | 'limit' => count($removeCache), |
||
1143 | ) |
||
1144 | ); |
||
1145 | |||
1146 | $removeCache = array(); |
||
1147 | $removeCacheBoards = array(); |
||
1148 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
||
1149 | { |
||
1150 | $removeCache[] = $row['id_topic']; |
||
1151 | $removeCacheBoards[$row['id_topic']] = $row['id_board']; |
||
1152 | } |
||
1153 | $smcFunc['db_free_result']($result); |
||
1154 | |||
1155 | // Maybe *none* were their own topics. |
||
1156 | if (!empty($removeCache)) |
||
1157 | { |
||
1158 | // Gotta send the notifications *first*! |
||
1159 | foreach ($removeCache as $topic) |
||
1160 | { |
||
1161 | // Only log the topic ID if it's not in the recycle board. |
||
1162 | logAction('remove', array((empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $removeCacheBoards[$topic] ? 'topic' : 'old_topic_id') => $topic, 'board' => $removeCacheBoards[$topic])); |
||
1163 | sendNotifications($topic, 'remove'); |
||
1164 | } |
||
1165 | |||
1166 | require_once($sourcedir . '/RemoveTopic.php'); |
||
1167 | removeTopics($removeCache); |
||
1168 | } |
||
1169 | } |
||
1170 | |||
1171 | // Approve the topics... |
||
1172 | if (!empty($approveCache)) |
||
1173 | { |
||
1174 | // We need unapproved topic ids and their authors! |
||
1175 | $request = $smcFunc['db_query']('', ' |
||
1176 | SELECT id_topic, id_member_started |
||
1177 | FROM {db_prefix}topics |
||
1178 | WHERE id_topic IN ({array_int:approve_topic_ids}) |
||
1179 | AND approved = {int:not_approved} |
||
1180 | LIMIT {int:limit}', |
||
1181 | array( |
||
1182 | 'approve_topic_ids' => $approveCache, |
||
1183 | 'not_approved' => 0, |
||
1184 | 'limit' => count($approveCache), |
||
1185 | ) |
||
1186 | ); |
||
1187 | $approveCache = array(); |
||
1188 | $approveCacheMembers = array(); |
||
1189 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
1190 | { |
||
1191 | $approveCache[] = $row['id_topic']; |
||
1192 | $approveCacheMembers[$row['id_topic']] = $row['id_member_started']; |
||
1193 | } |
||
1194 | $smcFunc['db_free_result']($request); |
||
1195 | |||
1196 | // Any topics to approve? |
||
1197 | if (!empty($approveCache)) |
||
1198 | { |
||
1199 | // Handle the approval part... |
||
1200 | approveTopics($approveCache); |
||
1201 | |||
1202 | // Time for some logging! |
||
1203 | foreach ($approveCache as $topic) |
||
1204 | logAction('approve_topic', array('topic' => $topic, 'member' => $approveCacheMembers[$topic])); |
||
1205 | } |
||
1206 | } |
||
1207 | |||
1208 | // And (almost) lastly, lock the topics... |
||
1209 | if (!empty($lockCache)) |
||
1210 | { |
||
1211 | $lockStatus = array(); |
||
1212 | |||
1213 | // Gotta make sure they CAN lock/unlock these topics... |
||
1214 | if (!empty($board) && !allowedTo('lock_any')) |
||
1215 | { |
||
1216 | // Make sure they started the topic AND it isn't already locked by someone with higher priv's. |
||
1217 | $result = $smcFunc['db_query']('', ' |
||
1218 | SELECT id_topic, locked, id_board |
||
1219 | FROM {db_prefix}topics |
||
1220 | WHERE id_topic IN ({array_int:locked_topic_ids}) |
||
1221 | AND id_member_started = {int:current_member} |
||
1222 | AND locked IN (2, 0) |
||
1223 | LIMIT {int:limit}', |
||
1224 | array( |
||
1225 | 'current_member' => $user_info['id'], |
||
1226 | 'locked_topic_ids' => $lockCache, |
||
1227 | 'limit' => count($lockCache), |
||
1228 | ) |
||
1229 | ); |
||
1230 | $lockCache = array(); |
||
1231 | $lockCacheBoards = array(); |
||
1232 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
||
1233 | { |
||
1234 | $lockCache[] = $row['id_topic']; |
||
1235 | $lockCacheBoards[$row['id_topic']] = $row['id_board']; |
||
1236 | $lockStatus[$row['id_topic']] = empty($row['locked']); |
||
1237 | } |
||
1238 | $smcFunc['db_free_result']($result); |
||
1239 | } |
||
1240 | else |
||
1241 | { |
||
1242 | $result = $smcFunc['db_query']('', ' |
||
1243 | SELECT id_topic, locked, id_board |
||
1244 | FROM {db_prefix}topics |
||
1245 | WHERE id_topic IN ({array_int:locked_topic_ids}) |
||
1246 | LIMIT {int:limit}', |
||
1247 | array( |
||
1248 | 'locked_topic_ids' => $lockCache, |
||
1249 | 'limit' => count($lockCache) |
||
1250 | ) |
||
1251 | ); |
||
1252 | $lockCacheBoards = array(); |
||
1253 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
||
1254 | { |
||
1255 | $lockStatus[$row['id_topic']] = empty($row['locked']); |
||
1256 | $lockCacheBoards[$row['id_topic']] = $row['id_board']; |
||
1257 | } |
||
1258 | $smcFunc['db_free_result']($result); |
||
1259 | } |
||
1260 | |||
1261 | // It could just be that *none* were their own topics... |
||
1262 | if (!empty($lockCache)) |
||
1263 | { |
||
1264 | // Alternate the locked value. |
||
1265 | $smcFunc['db_query']('', ' |
||
1266 | UPDATE {db_prefix}topics |
||
1267 | SET locked = CASE WHEN locked = {int:is_locked} THEN ' . (allowedTo('lock_any') ? '1' : '2') . ' ELSE 0 END |
||
1268 | WHERE id_topic IN ({array_int:locked_topic_ids})', |
||
1269 | array( |
||
1270 | 'locked_topic_ids' => $lockCache, |
||
1271 | 'is_locked' => 0, |
||
1272 | ) |
||
1273 | ); |
||
1274 | } |
||
1275 | } |
||
1276 | |||
1277 | if (!empty($markCache)) |
||
1278 | { |
||
1279 | $request = $smcFunc['db_query']('', ' |
||
1280 | SELECT id_topic, unwatched |
||
1281 | FROM {db_prefix}log_topics |
||
1282 | WHERE id_topic IN ({array_int:selected_topics}) |
||
1283 | AND id_member = {int:current_user}', |
||
1284 | array( |
||
1285 | 'selected_topics' => $markCache, |
||
1286 | 'current_user' => $user_info['id'], |
||
1287 | ) |
||
1288 | ); |
||
1289 | $logged_topics = array(); |
||
1290 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
||
1291 | $logged_topics[$row['id_topic']] = $row['unwatched']; |
||
1292 | |||
1293 | $smcFunc['db_free_result']($request); |
||
1294 | |||
1295 | $markArray = array(); |
||
1296 | foreach ($markCache as $topic) |
||
1297 | $markArray[] = array($modSettings['maxMsgID'], $user_info['id'], $topic, (isset($logged_topics[$topic]) ? $logged_topics[$topic] : 0)); |
||
1298 | |||
1299 | $smcFunc['db_insert']('replace', |
||
1300 | '{db_prefix}log_topics', |
||
1301 | array('id_msg' => 'int', 'id_member' => 'int', 'id_topic' => 'int', 'unwatched' => 'int'), |
||
1302 | $markArray, |
||
1303 | array('id_member', 'id_topic') |
||
1304 | ); |
||
1305 | } |
||
1306 | |||
1307 | foreach ($moveCache as $topic) |
||
1308 | { |
||
1309 | // Didn't actually move anything! |
||
1310 | if (!isset($topic[0])) |
||
1311 | break; |
||
1312 | |||
1313 | logAction('move', array('topic' => $topic[0], 'board_from' => $topic[1], 'board_to' => $topic[2])); |
||
1314 | sendNotifications($topic[0], 'move'); |
||
1315 | } |
||
1316 | foreach ($lockCache as $topic) |
||
1317 | { |
||
1318 | logAction($lockStatus[$topic] ? 'lock' : 'unlock', array('topic' => $topic, 'board' => $lockCacheBoards[$topic])); |
||
1319 | sendNotifications($topic, $lockStatus[$topic] ? 'lock' : 'unlock'); |
||
1320 | } |
||
1321 | foreach ($stickyCache as $topic) |
||
1322 | { |
||
1323 | logAction($stickyCacheStatus[$topic] ? 'unsticky' : 'sticky', array('topic' => $topic, 'board' => $stickyCacheBoards[$topic])); |
||
1324 | sendNotifications($topic, 'sticky'); |
||
1325 | } |
||
1326 | |||
1327 | updateStats('topic'); |
||
1328 | updateStats('message'); |
||
1329 | updateSettings(array( |
||
1330 | 'calendar_updated' => time(), |
||
1331 | )); |
||
1332 | |||
1333 | if (!empty($affectedBoards)) |
||
1334 | updateLastMessages(array_keys($affectedBoards)); |
||
1335 | |||
1336 | redirectexit($redirect_url); |
||
1337 | } |
||
1339 | ?> |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.