[Topic solved] Some stuff I always meant to get committed for this but never got round to it: ! Use hooks where possible without going totally nuts about it, plus the banner above a topic being a template layer rather than a template edit, plus some streamlining of the code and the uninstaller actually being able to clean up properly after itself. ! Members not being able to mark things solved properly due to wrong permission check, followed by missing error message. [Bug 717] ! Adding solved.gif to the SSI functions [Bug 382]
gruffen

gruffen commited on 2011-07-01 02:47:17
Showing 9 changed files, with 235 additions and 125 deletions.

... ...
@@ -0,0 +1,76 @@
1
+<?php
2
+
3
+if (!defined('SMF'))
4
+	die('Hacking attempt...');
5
+
6
+function add_ts_settings_menu(&$subActions)
7
+{
8
+	$subActions['topicsolved'] = 'ModifyTopicSolvedSettings';
9
+}
10
+
11
+function add_ts_permissions(&$permissionGroups, &$permissionList, &$leftPermissionGroups, &$hiddenPermissions, &$relabelPermissions)
12
+{
13
+	$permissionList['board']['solve_topic'] = array(true, 'topic', 'moderate', 'moderate');
14
+}
15
+
16
+function add_ts_adminmenu(&$admin_areas)
17
+{
18
+	global $txt, $context, $modSettings, $scripturl;
19
+	$admin_areas['maintenance']['areas']['logs']['subsections']['solvelog'] = array($txt['modlog_solve_log'], 'moderate_forum', 'enabled' => !empty($modSettings['enable_solved_log']) && in_array('ml', $context['admin_features']), 'url' => $scripturl . '?action=moderate;area=modlog;sa=solvelog');
20
+	$admin_areas['config']['areas']['modsettings']['subsections']['topicsolved'] = array($txt['topic_solved_title']);
21
+}
22
+
23
+function ModifyTopicSolvedSettings($return_config = false)
24
+{
25
+	global $txt, $scripturl, $context, $settings, $sc, $modSettings, $smcFunc;
26
+	
27
+	$query = $smcFunc['db_query']('', '
28
+		SELECT id_board, id_cat, child_level, name FROM {db_prefix}boards ORDER BY board_order ASC
29
+	');
30
+	
31
+	$config_vars = array();
32
+	$last = -1;
33
+	
34
+	$config_vars = array(
35
+		array('check', 'enable_solved_log', 'disabled' => !in_array('ml', $context['admin_features'])),
36
+		array('check', 'topicsolved_highlight'),
37
+		array('text', 'topicsolved_highlight_col1', 'size' => 10, 'disabled' => empty($modSettings['topicsolved_highlight'])),
38
+		array('text', 'topicsolved_highlight_col2', 'size' => 10, 'disabled' => empty($modSettings['topicsolved_highlight'])),
39
+		array('check', 'topicsolved_display_notice'),
40
+		'',
41
+		array('message', 'topicsolved_board_desc'),
42
+	);
43
+
44
+	while ($row = $smcFunc['db_fetch_assoc']($query)) {
45
+		if ($row['id_cat'] != $last && $last != -1)
46
+			$config_vars[] = '';
47
+
48
+		$board_id = 'topicsolved_board_' . $row['id_board'];
49
+		$txt[$board_id] = (($row['child_level'] > 0) ? str_repeat('&nbsp; &nbsp; ', $row['child_level']) : '') . $row['name'];
50
+		$config_vars[] = array('check', $board_id);
51
+		$last = $row['id_cat'];
52
+	}
53
+	
54
+	$smcFunc['db_free_result']($query);	
55
+
56
+	if ($return_config)
57
+		return $config_vars;
58
+
59
+	$context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=topicsolved';
60
+	$context['settings_title'] = $txt['topic_solved_title'];
61
+
62
+	// Saving?
63
+	if (isset($_GET['save']))
64
+	{
65
+		checkSession();
66
+
67
+		$save_vars = $config_vars;
68
+		saveDBSettings($save_vars);
69
+		
70
+		redirectexit('action=admin;area=modsettings;sa=topicsolved');
71
+	}
72
+
73
+	prepareDBSettingContext($config_vars);
74
+}
75
+
76
+?>
0 77
\ No newline at end of file
... ...
@@ -0,0 +1,27 @@
1
+<?php
2
+
3
+if (!defined('SMF'))
4
+	die('Hacking attempt...');
5
+
6
+function template_topicsolved_header_above()
7
+{
8
+	global $txt;
9
+
10
+	echo '<br /><div class="information">', $txt['topicsolved_is_solved'], '</div>';
11
+}
12
+
13
+function template_topicsolved_header_below()
14
+{
15
+
16
+}
17
+
18
+// This is called from the hook in the display template. Since that's the case I didn't think it was inappropriate to put it here...
19
+function add_topicsolved_button(&$mod_buttons)
20
+{
21
+	global $context, $scripturl;
22
+	$mod_buttons = array_merge(array(
23
+		'solve' => array('test' => 'can_solve', 'text' => empty($context['is_solved']) ? 'solve_topic' : 'unsolve_topic', 'image' => empty($context['is_solved']) ? 'solve.gif' : 'unsolve.gif', 'lang' => true, 'url' => $scripturl . '?action=solve;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']),
24
+	), $mod_buttons);
25
+}
26
+
27
+?>
0 28
\ No newline at end of file
... ...
@@ -50,9 +50,9 @@ function SolveTopic()
50 50
 	// Youcansolvez?
51 51
 	$user_solve = !allowedTo('solve_topic_any', $board);
52 52
 	if ($user_solve && $starter == $user_info['id'])
53
-		isAllowedTo('solve_own', $board);
53
+		isAllowedTo('solve_topic_own', $board);
54 54
 	else
55
-		isAllowedTo('solve_any', $board);
55
+		isAllowedTo('solve_topic_any', $board);
56 56
 
57 57
 	// Mark the topic solved in the database. Simple enough.
58 58
 	$smcFunc['db_query']('', '
... ...
@@ -21,6 +21,8 @@ $txt['solve_log_help'] = '<strong>Topic solved log</strong><br />This section al
21 21
 $txt['permissionname_solve_topic'] = 'Mark topics solved/not solved';
22 22
 $txt['permissionname_solve_topic_any'] = 'Any topic';
23 23
 $txt['permissionname_solve_topic_own'] = 'Own topic';
24
+$txt['cannot_solve_topic_any'] = 'You do not have permission to mark topics solved.';
25
+$txt['cannot_solve_topic_own'] = 'You do not have permission to mark topics solved.';
24 26
 $txt['permissionhelp_solve_topic'] = 'This permission will allow the user to mark topics as solved and not solved.';
25 27
 $txt['enable_solved_log'] = 'Enable logging of topic solving (Requires moderation logging to be enabled)';
26 28
 $txt['topicsolved_board_desc'] = '<span class="smalltext">Please select the boards you wish to enable the topic solved feature in.</span>';
... ...
@@ -46,8 +48,10 @@ $txt['modlog_solve_log_desc'] = 'Below is a list of all topics that have been so
46 48
 $txt['modlog_solve_log_no_entries_found'] = 'There are currently no entries in the topic solved log.';
47 49
 $txt['solve_log_help'] = '<strong>Topic solved log</strong><br />This section allows members of the moderation team to track all usage of the topic solved/not solved feature. To ensure that moderators cannot remove references to the actions they have performed, entries may not be deleted until 24 hours after the action was taken.';
48 50
 $txt['permissionname_solve_topic'] = 'Mark topics solved/not solved';
49
-$txt['permissionname_solve_topic_any'] = 'Any topic';
50
-$txt['permissionname_solve_topic_own'] = 'Own topic';
51
+$txt['permissionname_solve_topic_any'] = 'Any topics';
52
+$txt['permissionname_solve_topic_own'] = 'Own topics';
53
+$txt['cannot_solve_topic_any'] = 'You do not have permission to mark topics solved.';
54
+$txt['cannot_solve_topic_own'] = 'You do not have permission to mark topics solved.';
51 55
 $txt['permissionhelp_solve_topic'] = 'This permission will allow the user to mark topics as solved and not solved.';
52 56
 $txt['enable_solved_log'] = 'Enable logging of topic solving';
53 57
 $txt['topicsolved_board_desc'] = '<span class="smalltext">Please select the boards you wish to enable the topic solved feature in.</span>';
... ...
@@ -21,16 +21,21 @@ if (empty($modSettings['topicsolved_highlight_col1']))
21 21
 		updateSettings(array($key => $value));
22 22
 }
23 23
 
24
-$check = $smcFunc['db_list_columns']('{db_prefix}topics');
25
-
26
-if (!in_array('solved', $check))
27
-	$smcFunc['db_add_column']('{db_prefix}topics', array('name' => 'solved', 'type' => 'tinyint', 'size' => 4));	
24
+$smcFunc['db_add_column']('{db_prefix}topics', array('name' => 'solved', 'type' => 'tinyint', 'size' => 3, 'unsigned' => true));	
28 25
 	
29 26
 $installed = $smcFunc['db_list_columns']('{db_prefix}topics');
30 27
 
28
+add_integration_function('integrate_mod_buttons', 'add_topicsolved_button', true);
29
+add_integration_function('integrate_admin_include', '$sourcedir/SolveTopic-Admin.php', true);
30
+add_integration_function('integrate_modify_modifications', 'add_ts_settings_menu', true);
31
+add_integration_function('integrate_admin_areas', 'add_ts_adminmenu', true);
32
+
33
+if (SMF == 'SSI')
34
+{
31 35
 	if (in_array('solved', $installed))
32 36
 		echo 'Database edits completed!';
33 37
 	else
34 38
 		echo 'Database edits failed!';
39
+}
35 40
 	
36 41
 ?>
37 42
\ No newline at end of file
... ...
@@ -7,40 +7,21 @@
7 7
 	<!-- Template files -->		
8 8
 	<file name="$themedir/MessageIndex.template.php">	
9 9
 		<operation>
10
-			<search position="replace"><![CDATA[$color_class = 'windowbg';]]></search>
11
-			<add><![CDATA[$color_class = 'windowbg';
12
-				
13
-			// Solved topics
14
-			if ($topic['is_solved'] && $topic['is_locked'])
15
-				$color_class = 'lockedbg solvedbg';
16
-			elseif ($topic['is_solved'])
17
-				$color_class = 'solvedbg';]]></add>
18
-		</operation>
19
-	</file>
20
-	<file name="$themedir/Display.template.php">	
21
-		<operation>
22
-			<search position="before"><![CDATA[// Show the anchor for the top and for the first message. If the first message is new, say so.]]></search>
23
-			<add><![CDATA[// Let them know that this is solved
24
-	if(!empty($modSettings['topicsolved_display_notice']) && $context['is_solved'] && $context['board_solve'])
25
-		echo'<br /><div class="information">', $txt['topicsolved_is_solved'], '</div>';]]></add>
26
-		</operation>
27
-		<operation>
28
-			<search position="after"><![CDATA[// Restore topic. eh?  No monkey business.]]></search>
29
-			<add><![CDATA[// Topic solved.
30
-	$mod_buttons = array_merge(array(
31
-		'solve' => array('test' => 'can_solve', 'text' => empty($context['is_solved']) ? 'solve_topic' : 'unsolve_topic', 'image' => empty($context['is_solved']) ? 'solve.gif' : 'unsolve.gif', 'lang' => true, 'url' => $scripturl . '?action=solve;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']),
32
-	),$mod_buttons);]]></add>
10
+			<search position="before"><![CDATA[// Some columns require a different shade of the color class.]]></search>
11
+			<add><![CDATA[
12
+			if (!empty($topic['is_solved']))
13
+				$color_class .= ' solvedbg';]]></add>
33 14
 		</operation>
34 15
 	</file>
35 16
 
36 17
 	<!-- Source files -->		
37
-	<file name="$boarddir/index.php">	
18
+	<file name="$boarddir/index.php"><!-- Adding the action. While it would be nice to use a hook, I don't want to include a file every page load for the sake of this one change. -->	
38 19
 		<operation>
39 20
 			<search position="after"><![CDATA[// Get the function and file to include - if it's not there, do the board index.]]></search>
40 21
 			<add><![CDATA[$actionArray['solve'] = array('SolveTopic.php', 'SolveTopic');]]></add>
41 22
 		</operation>
42 23
 	</file>
43
-	<file name="$sourcedir/Display.php">	
24
+	<file name="$sourcedir/Display.php"><!-- Lots to change, notably figuring out the permission for adding the button, plus loading all sorts of other stuff. -->
44 25
 		<operation>
45 26
 			<search position="replace"><![CDATA[foreach ($anyown_permissions as $contextual => $perm)
46 27
 		$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));]]></search>
... ...
@@ -50,9 +31,12 @@
50 31
 	foreach ($anyown_permissions as $contextual => $perm)
51 32
 		$context[$contextual] = allowedTo($perm . '_any') || ($context['user']['started'] && allowedTo($perm . '_own'));
52 33
 		
53
-	// Topic solved. Is this one of THE boards?
34
+	// Topic solved stuff. Is this one of THE boards?
35
+	loadTemplate('SolveTopic-Display');
54 36
 	$context['board_solve'] = !empty($modSettings['topicsolved_board_' . $board]);
55 37
 	$context['can_solve'] &= $context['board_solve'];
38
+	if (!empty($modSettings['topicsolved_display_notice']) && $context['is_solved'] && $context['board_solve'])
39
+		$context['template_layers'][] = 'topicsolved_header';
56 40
 ]]></add>
57 41
 		</operation>
58 42
 		<operation>
... ...
@@ -65,14 +49,14 @@
65 49
 	$context['is_solved'] = $topicinfo['solved'];]]></add>
66 50
 		</operation>		
67 51
 	</file>	
68
-	<file name="$sourcedir/Subs.php">	
52
+	<file name="$sourcedir/Subs.php"><!-- Add the topic solved log to the list of possible log types we can handle. -->
69 53
 		<operation>
70 54
 			<search position="after"><![CDATA[if (!is_array($extra))]]></search>
71 55
 			<add><![CDATA[// Solved log
72
-	$log_types = array_merge($log_types,array('solve' => 4));]]></add>
56
+	$log_types['solve'] = 4;]]></add>
73 57
 		</operation>	
74 58
 	</file>		
75
-	<file name="$sourcedir/ModLog.php">	
59
+	<file name="$sourcedir/Modlog.php"><!-- Extend the moderation log to support the topic solving too. -->
76 60
 		<operation>
77 61
 			<search position="before"><![CDATA[isAllowedTo('admin_forum');]]></search>
78 62
 			<add><![CDATA[// Topic solved log
... ...
@@ -87,7 +71,7 @@
87 71
 			<add><![CDATA[// Topic solved log: Override page_title and url_starts if required.
88 72
 	if ($context['log_type'] == 4)
89 73
 	{
90
-		$context['page_title'] = 'Solve log';	
74
+		$context['page_title'] = $txt['modlog_solve_log'];	
91 75
 		$context['url_start'] = '?action=moderate;area=modlog;sa=solvelog;type=4';		
92 76
 	}]]></add>
93 77
 		</operation>	
... ...
@@ -102,22 +86,11 @@
102 86
 	}]]></add>
103 87
 		</operation>		
104 88
 	</file>	
105
-	<file name="$sourcedir/Admin.php">	
106
-		<operation>
107
-			<search position="before"><![CDATA['pruning' => array($txt['pruning_title'], 'admin_forum'),]]></search>
108
-			<add><![CDATA['solvelog' => array($txt['modlog_solve_log'], 'moderate_forum', 'enabled' => !empty($modSettings['enable_solved_log']), 'url' => $scripturl . '?action=moderate;area=modlog;sa=solvelog'),]]></add>
109
-		</operation>
110
-		<operation>
111
-			<search position="before"><![CDATA[// Mod Authors for a "ADD AFTER" on this line. Ensure you end your change with a comma. For example:]]></search>
112
-			<add><![CDATA[
113
-			'topicsolved' => array($txt['topic_solved_title']),]]></add>
114
-		</operation>		
115
-	</file>	
116
-	<file name="$sourcedir/ModerationCenter.php">	
89
+	<file name="$sourcedir/ModerationCenter.php"><!-- Provide access from the moderation center to the moderation log for topic solving. -->
117 90
 		<operation>
118 91
 			<search position="after"><![CDATA['notice' => array(]]></search>
119 92
 			<add><![CDATA['solvelog' => array(
120
-					'enabled' => !empty($modSettings['enable_solved_log']),
93
+					'enabled' => !empty($modSettings['enable_solved_log']) && in_array('ml', $context['admin_features']),
121 94
 					'label' => $txt['modlog_solve_log'],
122 95
 					'file' => 'Modlog.php',
123 96
 					'function' => 'ViewModlog',
... ...
@@ -125,74 +98,7 @@
125 98
 				),]]></add>
126 99
 		</operation>	
127 100
 	</file>	
128
-	<file name="$sourcedir/ManagePermissions.php">	
129
-		<operation>
130
-			<search position="before"><![CDATA[// All permission groups that will be shown in the left column on classic view.
131
-]]></search>
132
-			<add><![CDATA[$permissionList['board']['solve_topic'] = array(true, 'topic', 'moderate', 'moderate');]]></add>
133
-		</operation>	
134
-	</file>
135
-	<file name="$sourcedir/ManageSettings.php">	
136
-		<operation>
137
-			<search position="after"><![CDATA[// Mod authors, once again, if you have a whole section to add do it AFTER this line, and keep a comma at the end.]]></search>
138
-			<add><![CDATA['topicsolved' => 'ModifyTopicSolvedSettings',]]></add>
139
-		</operation>	
140
-		<operation>
141
-			<search position="end" />
142
-			<add><![CDATA[// Topic solved mod
143
-function ModifyTopicSolvedSettings($return_config = false)
144
-{
145
-	global $txt, $scripturl, $context, $settings, $sc, $modSettings, $smcFunc;
146
-	
147
-	$query = $smcFunc['db_query']('', '
148
-		SELECT id_board, id_cat, child_level, name FROM {db_prefix}boards ORDER BY board_order ASC
149
-	');
150
-	
151
-	$config_vars = array();
152
-	$last = -1;
153
-	
154
-	$config_vars[] = array('check', 'enable_solved_log');
155
-	$config_vars[] = array('check', 'topicsolved_highlight');
156
-	$config_vars[] = array('text', 'topicsolved_highlight_col1', 'size' => 10, 'disabled' => empty($modSettings['topicsolved_highlight']));
157
-	$config_vars[] = array('text', 'topicsolved_highlight_col2', 'size' => 10, 'disabled' => empty($modSettings['topicsolved_highlight']));
158
-	$config_vars[] = array('check', 'topicsolved_display_notice');
159
-	$config_vars[] = '';	
160
-	$config_vars[] = array('message', 'topicsolved_board_desc');
161
-
162
-	while($row = $smcFunc['db_fetch_assoc']($query)) {
163
-		if($row['id_cat'] != $last && $last != -1) {
164
-			$config_vars[] = '';
165
-		}
166
-		$board_id = 'topicsolved_board_' . $row['id_board'];
167
-		$txt[$board_id] = (($row['child_level'] > 0) ? str_repeat('&nbsp; &nbsp; ', $row['child_level']) : '') . $row['name'];
168
-		$config_vars[] = array('check', $board_id);
169
-		$last = $row['id_cat'];
170
-	}
171
-	
172
-	$smcFunc['db_free_result']($query);	
173
-
174
-	if ($return_config)
175
-		return $config_vars;
176
-
177
-	$context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=topicsolved';
178
-	$context['settings_title'] = $txt['topic_solved_title'];
179
-
180
-	// Saving?
181
-	if (isset($_GET['save']))
182
-	{
183
-		checkSession();
184
-
185
-		$save_vars = $config_vars;
186
-		saveDBSettings($save_vars);
187
-		
188
-		redirectexit('action=admin;area=modsettings;sa=topicsolved');
189
-	}
190
-
191
-	prepareDBSettingContext($config_vars);
192
-}]]></add>
193
-		</operation>		
194
-	</file>	
195
-	<file name="$sourcedir/MessageIndex.php">	
101
+	<file name="$sourcedir/MessageIndex.php"><!-- Be sure to get the topic data, to be able to display whether something is solved or not. -->
196 102
 		<operation>
197 103
 			<search position="after"><![CDATA[determineTopicClass($context['topics'][$row['id_topic']]);]]></search>
198 104
 			<add><![CDATA[// Topic solved highlighting, if enabled.
... ...
@@ -200,25 +106,31 @@ function ModifyTopicSolvedSettings($return_config = false)
200 106
 			]]></add>
201 107
 		</operation>
202 108
 		<operation>
203
-			<search position="before"><![CDATA[SUBSTRING(mf.body, 1, 385) AS first_body, ml.smileys_enabled AS last_smileys, mf.smileys_enabled AS first_smileys]]></search>
109
+			<search position="before"><![CDATA[mf.smileys_enabled AS first_smileys]]></search>
204 110
 			<add><![CDATA[, t.solved]]></add>
205 111
 		</operation>
206 112
 		<operation>
207 113
 			<search position="after"><![CDATA[// Begin 'printing' the message index for current board.]]></search>
208 114
 			<add><![CDATA[// Is this board solvable?
209 115
 		$context['board_solve'] = !empty($modSettings['topicsolved_board_' . $board]);
210
-		if (!empty($modSettings['topicsolved_highlight']))
211
-		{
212
-			if (!empty($modSettings['topicsolved_highlight_col1']) && !empty($modSettings['topicsolved_highlight_col2']))
116
+		if (!empty($modSettings['topicsolved_highlight']) && !empty($modSettings['topicsolved_highlight_col1']) && !empty($modSettings['topicsolved_highlight_col2']))
213 117
 		{
214 118
 			if (empty($context['html_headers']))
215 119
 				$context['html_headers'] = '';
216 120
 			$context['html_headers'] .= '<style type="text/css">/* Topic solved */ .solvedbg { background:' . $modSettings['topicsolved_highlight_col1'] . '; } .solvedbg2 { background:' . $modSettings['topicsolved_highlight_col2'] . '; }</style>';
217 121
 		}
218
-		}
219 122
 
220 123
 		]]></add>
221 124
 		</operation>
222 125
 	</file>
223
-
126
+	<file name="$boarddir/SSI.php"><!-- Make sure the topic solved icon is actually added to the SSI functions too. Same code, used twice. -->
127
+		<operation>
128
+			<search position="replace"><![CDATA[$stable_icons = array('xx']]></search>
129
+			<add><![CDATA[$stable_icons = array('solved', 'xx']]></add>
130
+		</operation>
131
+		<operation>
132
+			<search position="replace"><![CDATA[$stable_icons = array('xx']]></search>
133
+			<add><![CDATA[$stable_icons = array('solved', 'xx']]></add>
134
+		</operation>
135
+	</file>
224 136
 </modification>
225 137
\ No newline at end of file
... ...
@@ -10,14 +10,21 @@
10 10
 		<modification>install2.0.xml</modification>
11 11
 		<modification>english.xml</modification>
12 12
 		<require-file name="SolveTopic.php" destination="$sourcedir" />
13
+		<require-file name="SolveTopic-Admin.php" destination="$sourcedir" />
13 14
 		<require-file name="solved.gif" destination="$imagesdir/post" />
15
+		<require-file name="SolveTopic-Display.template.php" destination="$themes_dir/default" />
14 16
 		<database>install.php</database>
17
+		<redirect url="?action=admin;area=modsettings;sa=topicsolved" />
15 18
 	</install>
16 19
 	<uninstall for="2.0-2.99.99">
20
+		<database>uninstall-optional.php</database>
21
+		<code>uninstall-required.php</code>
17 22
 		<readme type="inline">This will uninstall the Topic Solved Mod. Thanks for using this customization.</readme>			
18 23
 		<modification reverse="true">install2.0.xml</modification>	
19 24
 		<modification reverse="true">english.xml</modification>
20 25
 		<remove-file name="$sourcedir/SolveTopic.php" />
26
+		<remove-file name="$sourcedir/SolveTopic-Admin.php" />
21 27
 		<remove-file name="$imagesdir/post/solved.gif" />
28
+		<remove-file name="$themes_dir/default/SolveTopic-Display.template.php" />
22 29
 	</uninstall>	
23 30
 </package-info>
24 31
\ No newline at end of file
... ...
@@ -0,0 +1,58 @@
1
+<?php
2
+if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF'))
3
+	require_once(dirname(__FILE__) . '/SSI.php');
4
+elseif (!defined('SMF')) // If we are outside SMF and can't find SSI.php, then throw an error
5
+	die('<b>Error:</b> Cannot uninstall - please verify you put this file in the same place as SMF\'s SSI.php.');
6
+
7
+// OK, so we're cleaning up everything in the DB. The new columnw will have been taken care of already.
8
+
9
+// 1. Clean up the settings table.
10
+$remove = array('enable_solved');
11
+foreach ($modSettings as $variable => $value)
12
+	if (strpos($variable, 'topicsolved') === 0)
13
+		$remove[] = $variable;
14
+
15
+$smcFunc['db_query']('', '
16
+	DELETE FROM {db_prefix}settings WHERE variable IN ({array_string:vars})',
17
+	array(
18
+		'vars' => $remove
19
+	)
20
+);
21
+
22
+// 2. Clean up permissions.
23
+$smcFunc['db_query']('', '
24
+	DELETE FROM {db_prefix}board_permissions
25
+	WHERE permission LIKE {string:perm}',
26
+	array(
27
+		'perm' => 'solve_topic%',
28
+	)
29
+);
30
+
31
+// 3. Clean up the moderation log.
32
+$smcFunc['db_query']('', '
33
+	DELETE FROM {db_prefix}log_actions
34
+	WHERE id_log = {int:topic_solved_log}',
35
+	array(
36
+		'topic_solved_log' => 4,
37
+	)
38
+);
39
+
40
+// 4. Reset topic solved icons to their normal state.
41
+$smcFunc['db_query']('', '
42
+	UPDATE {db_prefix}messages
43
+	SET icon = {string:xx}
44
+	WHERE icon = {string:solved}',
45
+	array(
46
+		'xx' => 'xx', // for the bog standard icon
47
+		'solved' => 'solved', // for our icon
48
+	)
49
+);
50
+
51
+if (SMF == 'SSI')
52
+{
53
+	if (in_array('solved', $installed))
54
+		echo 'All topic-solved activity has been removed!';
55
+	else
56
+		echo 'Database edits failed!';
57
+}
58
+?>
0 59
\ No newline at end of file
... ...
@@ -0,0 +1,21 @@
1
+<?php
2
+if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF'))
3
+	require_once(dirname(__FILE__) . '/SSI.php');
4
+elseif (!defined('SMF')) // If we are outside SMF and can't find SSI.php, then throw an error
5
+	die('<b>Error:</b> Cannot uninstall - please verify you put this file in the same place as SMF\'s SSI.php.');
6
+
7
+// We need to clean out things like hooks, and we must do this on an uninstall regardless of anything else.
8
+
9
+remove_integration_function('integrate_mod_buttons', 'add_topicsolved_button');
10
+remove_integration_function('integrate_admin_include', '$sourcedir/SolveTopic-Admin.php');
11
+remove_integration_function('integrate_modify_modifications', 'add_ts_settings_menu');
12
+remove_integration_function('integrate_admin_areas', 'add_ts_adminmenu');
13
+
14
+if (SMF == 'SSI')
15
+{
16
+	if (in_array('solved', $installed))
17
+		echo 'Basic database changes edits removed!';
18
+	else
19
+		echo 'Database edits failed!';
20
+}
21
+?>
0 22
\ No newline at end of file
1 23