Updated topic solved for SMF 2.1 support
jdarwood007

jdarwood007 commited on 2017-09-16 21:17:30
Showing 9 changed files, with 306 additions and 13 deletions.


Signed-off-by: jdarwood007 <unmonitored+github@sleepycode.com>
... ...
@@ -16,6 +16,11 @@ function add_ts_permissions(&$permissionGroups, &$permissionList, &$leftPermissi
16 16
 function add_ts_adminmenu(&$admin_areas)
17 17
 {
18 18
 	global $txt, $context, $modSettings, $scripturl;
19
+
20
+	// If this is 2.1, we don't check admin_features
21
+	if (function_exists('loadCacheAccelerator'))
22
+		$admin_areas['maintenance']['areas']['logs']['subsections']['solvelog'] = array($txt['modlog_solve_log'], 'moderate_forum', 'enabled' => !empty($modSettings['enable_solved_log']), 'url' => $scripturl . '?action=moderate;area=modlog;sa=solvelog');
23
+	else
19 24
 		$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 25
 	$admin_areas['config']['areas']['modsettings']['subsections']['topicsolved'] = array($txt['topic_solved_title']);
21 26
 }
... ...
@@ -32,7 +37,7 @@ function ModifyTopicSolvedSettings($return_config = false)
32 37
 	$last = -1;
33 38
 	
34 39
 	$config_vars = array(
35
-		array('check', 'enable_solved_log', 'disabled' => !in_array('ml', $context['admin_features'])),
40
+		array('check', 'enable_solved_log', 'disabled' => function_exists('loadCacheAccelerator') ? false : !in_array('ml', $context['admin_features'])),
36 41
 		array('check', 'topicsolved_highlight'),
37 42
 		array('text', 'topicsolved_highlight_col1', 'size' => 10, 'disabled' => empty($modSettings['topicsolved_highlight'])),
38 43
 		array('text', 'topicsolved_highlight_col2', 'size' => 10, 'disabled' => empty($modSettings['topicsolved_highlight'])),
... ...
@@ -73,4 +78,34 @@ function ModifyTopicSolvedSettings($return_config = false)
73 78
 	prepareDBSettingContext($config_vars);
74 79
 }
75 80
 
81
+/**
82
+ *	Adds Topic Solved to our Moderation Log.
83
+ *
84
+ *	@param string &$listOptions The list options for our moderation log.
85
+ *	@param string &$moderation_menu_name Normally empty, but we fill it here with our new menu link.
86
+ *
87
+ *	@since 2.0
88
+*/
89
+function integrate_viewModLog_solveTopic(&$listOptions, $moderation_menu_name)
90
+{
91
+	global $context, $modSettings, $scripturl, $txt, $settings;
92
+
93
+	// Topic solved log
94
+	$context['log_type'] = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'solvelog' ? 4 : $context['log_type'];
95
+	
96
+	// Make sure the solve log is enabled.
97
+	if ($context['log_type'] == 4 && empty($modSettings['enable_solved_log']))
98
+		redirectexit('action=moderate');
99
+	elseif ($context['log_type'] != 4)
100
+		return false;
101
+
102
+	// At this point, we are certain to be on the solved topic section.
103
+	$context['page_title'] = $txt['modlog_solve_log'];	
104
+	$context['url_start'] = '?action=moderate;area=modlog;sa=solvelog;type=4';		
105
+
106
+	$listOptions['title'] = '<a href="' . $scripturl . '?action=helpadmin;help=solve_log_help" onclick="return reqWin(this.href);" class="help"><img src="' . $settings['images_url'] . '/helptopics.gif" alt="' . $txt['help'] . '" align="top" /></a> ' . $txt['modlog_solve_log'];
107
+	$listOptions['additional_rows'][0]['value'] = $txt['modlog_solve_log_desc'];
108
+	$listOptions['no_items_label'] = $txt['modlog_solve_log_no_entries_found'];
109
+}
110
+
76 111
 ?>
77 112
\ No newline at end of file
... ...
@@ -19,13 +19,25 @@ if (!defined('SMF'))
19 19
 
20 20
 */
21 21
 
22
-// Mark a topic solved.
22
+/**
23
+ *	The heavy lifting for solving a topic, all requests go through here and are validated and logged (if enabled).
24
+ *
25
+ *	@param string &$actionArray The master list of actions from index.php
26
+ *
27
+ *	@since 1.0
28
+*/
23 29
 function SolveTopic()
24 30
 {
25 31
 	global $topic, $user_info, $sourcedir, $board, $smcFunc, $modSettings;
26 32
 
27 33
 	// See if its enabled in this board.
28
-	if (empty($modSettings['topicsolved_board_' . $board]))
34
+	$solve_boards = array();
35
+	$boardsettings = array_keys($modSettings);
36
+	foreach($boardsettings as $setting) {
37
+		if(substr($setting, 0, 18) == 'topicsolved_board_' && $modSettings[$setting] == 1)
38
+			$solve_boards[] = str_replace('topicsolved_board_','',$setting);
39
+	}	
40
+	if(!in_array($board,$solve_boards))
29 41
 		fatal_lang_error('topicsolved_not_enabled', false);		
30 42
 	
31 43
 	// You need a topic to solve.
... ...
@@ -48,11 +60,11 @@ function SolveTopic()
48 60
 	$smcFunc['db_free_result']($request);
49 61
 
50 62
 	// Youcansolvez?
51
-	$user_solve = !allowedTo('solve_topic_any', $board);
63
+	$user_solve = !allowedTo('solve_topic_any');
52 64
 	if ($user_solve && $starter == $user_info['id'])
53
-		isAllowedTo('solve_topic_own', $board);
65
+		isAllowedTo('solve_topic_own');
54 66
 	else
55
-		isAllowedTo('solve_topic_any', $board);
67
+		isAllowedTo('solve_topic_any');
56 68
 
57 69
 	// Mark the topic solved in the database. Simple enough.
58 70
 	$smcFunc['db_query']('', '
... ...
@@ -84,4 +96,153 @@ function SolveTopic()
84 96
 	redirectexit('topic=' . $topic . '.' . $_REQUEST['start'] . (WIRELESS ? ';moderate' : ''));
85 97
 }
86 98
 
99
+/**
100
+ *	Adds solveTopic to the Action Array.
101
+ *
102
+ *	@param string &$actionArray The master list of actions from index.php
103
+ *
104
+ *	@since 1.1
105
+*/
106
+function integrate_actions_solveTopic(&$actionArray)
107
+{
108
+	$actionArray['solve'] = array('SolveTopic.php', 'SolveTopic');
109
+}
110
+
111
+/**
112
+ *	Adds Topic Solved to the Display Buttons.
113
+ *
114
+ *	@param string &$buttons The "normal" buttons, doesn't work.
115
+ *
116
+ *	@since 1.1
117
+*/
118
+function integrate_display_buttons_solveTopic(&$buttons)
119
+{
120
+	global $modSettings, $context, $board, $scripturl;
121
+
122
+	// Can you solve this?
123
+	$context['can_solve'] = allowedTo('solve_topic_any') || ($context['user']['started'] && allowedTo('solve_topic_own'));
124
+		
125
+	// Topic solved stuff. Is this one of THE boards?
126
+	loadTemplate('SolveTopic-Display');
127
+	$context['board_solve'] = !empty($modSettings['topicsolved_board_' . $board]);
128
+	$context['can_solve'] &= $context['board_solve'];
129
+
130
+	// Support SMF 2.0.
131
+	if (!isset($context['topicinfo']['solved']) && isset($context['is_solved']))
132
+		$context['topicinfo']['solved'] = $context['is_solved'];
133
+
134
+	if (!empty($modSettings['topicsolved_display_notice']) && $context['topicinfo']['solved'] && $context['board_solve'])
135
+		$context['template_layers'][] = 'topicsolved_header';
136
+
137
+	$context['mod_buttons']['solve'] = array(
138
+		'test' => 'can_solve',
139
+		'text' => empty($context['topicinfo']['solved']) ? 'solve_topic' : 'unsolve_topic',
140
+		'image' => empty($context['topicinfo']['solved']) ? 'solve.gif' : 'unsolve.gif',
141
+		'lang' => true,
142
+		'url' => $scripturl . '?action=solve;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']
143
+	);
144
+}
145
+
146
+/**
147
+ *	Adds Topic Solved column to the Display Query.
148
+ *
149
+ *	@param string &$topic_selects The selects to append to the query.
150
+ *	@param string &$topic_tables The tables to append to the query.
151
+ *	@param string &$topic_parameters The parameters to append to the query.
152
+ *
153
+ *	@since 1.1
154
+*/
155
+function integrate_display_topic_solveTopic(&$topic_selects, &$topic_tables, &$topic_parameters)
156
+{
157
+	$topic_selects[] = 't.solved';
158
+}
159
+
160
+/**
161
+ *	Adds Topic Solved to our Actionn Log as its own section.
162
+ *
163
+ *	@param string &$log_types The log types.
164
+ *
165
+ *	@since 1.1
166
+*/
167
+function integrate_log_types_solveTopic(&$log_types)
168
+{
169
+	$log_types['solve'] = 4;
170
+}
171
+
172
+/**
173
+ *	Adds Topic Solved to our Moderation Menu.
174
+ *
175
+ *	@param string &$menuData The menu data.
176
+ *
177
+ *	@since 1.1
178
+*/
179
+function integrate_moderate_areas_solveTopic(&$menuData)
180
+{
181
+	global $modSettings, $txt, $scripturl;
182
+
183
+	$menuData['main']['areas']['solvelog'] = array(
184
+		'enabled' => !empty($modSettings['enable_solved_log']),
185
+		'label' => $txt['modlog_solve_log'],
186
+		'file' => 'Modlog.php',
187
+		'function' => 'ViewModlog',
188
+		'custom_url' => $scripturl . '?action=moderate;area=modlog;sa=solvelog',
189
+	);
190
+}
191
+
192
+/**
193
+ *	Adds Topic Solved column to the Message Index Query.
194
+ *
195
+ *	@param string &$message_index_selects The selects to append to the query.
196
+ *	@param string &$message_index_tables The tables to append to the query.
197
+ *	@param string &$message_index_parameters The parameters to append to the query.
198
+ *
199
+ *	@since 1.1
200
+*/
201
+function integrate_message_index_solveTopic(&$message_index_selects, &$message_index_tables, &$message_index_parameters)
202
+{
203
+	$message_index_selects[] = 't.solved';
204
+}
205
+
206
+/**
207
+ *	We don't actually add any buttons to the message index, instead we use this to loop through the topics context and set it up.
208
+ *
209
+ *	@param string &$buttons The "normal" buttons.
210
+ *
211
+ *	@since 1.1
212
+*/
213
+function integrate_messageindex_buttons_solveTopic(&$buttons)
214
+{
215
+	global $context, $modSettings, $board;
216
+
217
+	// Is this board solvable?
218
+	$context['board_solve'] = !empty($modSettings['topicsolved_board_' . $board]);
219
+
220
+	// Loop through all topics and set is solved.
221
+	foreach ($context['topics'] as $id_topic => $topic_data)
222
+	{
223
+		$context['topics'][$topic_data['id']]['is_solved'] = $context['board_solve'] && !empty($topic_data['solved']);
224
+
225
+		// Is it solved?
226
+		if ($context['topics'][$topic_data['id']]['is_solved'])
227
+			$context['topics'][$topic_data['id']]['css_class'] = 'solvedbg';
228
+	}
229
+
230
+	// Do we have a custom CSS?
231
+	if (!empty($modSettings['topicsolved_highlight']) && !empty($modSettings['topicsolved_highlight_col1']) && !empty($modSettings['topicsolved_highlight_col2']))
232
+		addInlineCss('/* Topic solved */ .solvedbg:nth-of-type(even) { background:' . $modSettings['topicsolved_highlight_col1'] . '; } .solvedbg:nth-of-type(odd) { background:' . $modSettings['topicsolved_highlight_col2'] . '; }');
233
+}
234
+
235
+/**
236
+ *	Add Topic solved to the stable icons list.
237
+ *
238
+ *	@since 1.1
239
+*/
240
+function integrate_pre_load_solveTopic()
241
+{
242
+	global $context;
243
+
244
+	if (SMF == 'SSI')
245
+		$context['stable_icons'][] = 'solved';
246
+}
247
+
87 248
 ?>
88 249
\ No newline at end of file
... ...
@@ -35,7 +35,9 @@ $txt['topicsolved_highlight_col1'] = 'Color for highlighted solved topics (light
35 35
 $txt['topicsolved_highlight_col2'] = 'Color for highlighted solved topics (darker columns, such as subject/started by)';
36 36
 $txt['topicsolved_display_notice'] = 'Display a notice inside of solved topics';
37 37
 $txt['topicsolved_is_solved'] = '<strong style="color: green;">Topic solved</strong><br />This topic is marked as solved and as such require no attention unless you want to bump this issue.';
38
-$txt['topicsolved_not_enabled'] = 'Topic solved is not enabled on this board.';]]></add>
38
+$txt['topicsolved_not_enabled'] = 'Topic solved is not enabled on this board.';
39
+$txt['cannot_solve_own'] = 'You can not mark your own topics as solved';
40
+$txt['cannot_solve_any'] = 'You can not mark just any topic as solved';]]></add>
39 41
 		</operation>
40 42
 	</file>
41 43
 	<file name="$languagedir/Modifications.english-utf8.php" error="skip">	
... ...
@@ -0,0 +1,36 @@
1
+<?php
2
+
3
+if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF'))
4
+	require_once(dirname(__FILE__) . '/SSI.php');
5
+elseif (!defined('SMF')) // If we are outside SMF and can't find SSI.php, then throw an error
6
+	die('<b>Error:</b> Cannot install - please verify you put this file in the same place as SMF\'s SSI.php.');
7
+	
8
+global $smcFunc;	
9
+	
10
+if (!array_key_exists('db_add_column', $smcFunc))
11
+	db_extend('packages');
12
+
13
+if (empty($modSettings['topicsolved_highlight_col1']))
14
+{
15
+	$new_settings = array(
16
+		'topicsolved_highlight_col1' => '#eefee5',
17
+		'topicsolved_highlight_col2' => '#eafedd',
18
+	);
19
+
20
+	foreach ($new_settings as $key => $value)
21
+		updateSettings(array($key => $value));
22
+}
23
+
24
+$smcFunc['db_add_column']('{db_prefix}topics', array('name' => 'solved', 'type' => 'tinyint', 'size' => 3, 'default' => 0, 'unsigned' => true));	
25
+	
26
+$installed = $smcFunc['db_list_columns']('{db_prefix}topics');
27
+
28
+if (SMF == 'SSI')
29
+{
30
+	if (in_array('solved', $installed))
31
+		echo 'Database edits completed!';
32
+	else
33
+		echo 'Database edits failed!';
34
+}
35
+	
36
+?>
0 37
\ No newline at end of file
... ...
@@ -3,9 +3,9 @@
3 3
 <package-info xmlns="http://www.simplemachines.org/xml/package-info" xmlns:smf="http://www.simplemachines.org/">
4 4
 	<id>SimpleDesk:Topic_Solved_Mod</id>
5 5
 	<name>Topic Solved Mod</name>
6
-	<version>1.0</version>
6
+	<version>1.1</version>
7 7
 	<type>modification</type>
8
-	<install for="2.0-2.99.99">
8
+	<install for="2.0-2.0.99">
9 9
 		<readme type="file" parsebbc="true">readme.txt</readme>	
10 10
 		<modification>install2.0.xml</modification>
11 11
 		<modification>english.xml</modification>
... ...
@@ -13,12 +13,12 @@
13 13
 		<require-file name="SolveTopic-Admin.php" destination="$sourcedir" />
14 14
 		<require-file name="solved.gif" destination="$imagesdir/post" />
15 15
 		<require-file name="SolveTopic-Display.template.php" destination="$themes_dir/default" />
16
-		<database>install.php</database>
16
+		<database>install-2.0.php</database>
17 17
 		<redirect url="?action=admin;area=modsettings;sa=topicsolved" />
18 18
 	</install>
19
-	<uninstall for="2.0-2.99.99">
19
+	<uninstall for="2.0-2.0.99">
20 20
 		<database>uninstall-optional.php</database>
21
-		<code>uninstall-required.php</code>
21
+		<code>uninstall-required-2.0.php</code>
22 22
 		<readme type="inline">This will uninstall the Topic Solved Mod. Thanks for using this customization.</readme>			
23 23
 		<modification reverse="true">install2.0.xml</modification>	
24 24
 		<modification reverse="true">english.xml</modification>
... ...
@@ -27,4 +27,63 @@
27 27
 		<remove-file name="$imagesdir/post/solved.gif" />
28 28
 		<remove-file name="$themes_dir/default/SolveTopic-Display.template.php" />
29 29
 	</uninstall>	
30
+
31
+	<install for="2.1 Beta 3, 2.1 Beta 4, 2.1 RC1">
32
+		<readme type="file" parsebbc="true">readme.txt</readme>	
33
+		<modification>english.xml</modification>
34
+		<require-file name="SolveTopic.php" destination="$sourcedir" />
35
+		<require-file name="SolveTopic-Admin.php" destination="$sourcedir" />
36
+		<require-file name="solved.png" destination="$imagesdir/post" />
37
+		<require-file name="SolveTopic-Display.template.php" destination="$themes_dir/default" />
38
+		<database>install-2.1.php</database>
39
+		<redirect url="?action=admin;area=modsettings;sa=topicsolved" />
40
+
41
+		<hook function="integrate_pre_load_solveTopic" hook="integrate_pre_load" file="$sourcedir/SolveTopic.php" />
42
+		<hook hook="integrate_admin_include" file="$sourcedir/SolveTopic-Admin.php" />
43
+		<hook function="add_ts_settings_menu" hook="integrate_modify_modifications" file="$sourcedir/SolveTopic-Admin.php" />
44
+		<hook function="add_ts_adminmenu" hook="integrate_admin_areas" file="$sourcedir/SolveTopic-Admin.php" />
45
+		<hook function="add_ts_permissions" hook="integrate_load_permissions" file="$sourcedir/SolveTopic.php" />
46
+
47
+		<hook function="integrate_actions_solveTopic" hook="integrate_actions" file="$sourcedir/SolveTopic.php" />
48
+		<hook function="integrate_moderate_areas_solveTopic" hook="integrate_moderate_areas" file="$sourcedir/SolveTopic.php" />
49
+
50
+		<hook function="integrate_display_buttons_solveTopic" hook="integrate_display_buttons" file="$sourcedir/SolveTopic.php" />
51
+		<hook function="integrate_display_topic_solveTopic" hook="integrate_display_topic" file="$sourcedir/SolveTopic.php" />
52
+
53
+
54
+		<hook function="integrate_message_index_solveTopic" hook="integrate_message_index" file="$sourcedir/SolveTopic.php" />
55
+		<hook function="integrate_messageindex_buttons_solveTopic" hook="integrate_messageindex_buttons" file="$sourcedir/SolveTopic.php" />
56
+
57
+		<hook function="integrate_log_types_solveTopic" hook="integrate_log_types" file="$sourcedir/SolveTopic.php" />
58
+		<hook function="integrate_viewModLog_solveTopic" hook="integrate_viewModLog" file="$sourcedir/SolveTopic-Admin.php" />
59
+
60
+	</install>
61
+	<uninstall for="2.1 Beta 3, 2.1 Beta 4, 2.1 RC1">
62
+		<database>uninstall-optional.php</database>
63
+		<readme type="inline">This will uninstall the Topic Solved Mod. Thanks for using this customization.</readme>			
64
+		<modification reverse="true">english.xml</modification>
65
+		<remove-file name="$sourcedir/SolveTopic.php" />
66
+		<remove-file name="$sourcedir/SolveTopic-Admin.php" />
67
+		<remove-file name="$imagesdir/post/solved.png" />
68
+		<remove-file name="$themes_dir/default/SolveTopic-Display.template.php" />
69
+
70
+		<hook function="integrate_pre_load_solveTopic" hook="integrate_pre_load" file="$sourcedir/SolveTopic.php" reverse="true" />
71
+		<hook hook="integrate_admin_include" file="$sourcedir/SolveTopic-Admin.php" reverse="true" />
72
+		<hook function="add_ts_settings_menu" hook="integrate_modify_modifications" file="$sourcedir/SolveTopic-Admin.php" reverse="true" />
73
+		<hook function="add_ts_adminmenu" hook="integrate_admin_areas" file="$sourcedir/SolveTopic-Admin.php" reverse="true" />
74
+		<hook function="add_ts_permissions" hook="integrate_load_permissions" file="$sourcedir/SolveTopic.php" reverse="true" />
75
+
76
+		<hook function="integrate_actions_solveTopic" hook="integrate_actions" file="$sourcedir/SolveTopic.php" reverse="true" />
77
+		<hook function="integrate_moderate_areas_solveTopic" hook="integrate_moderate_areas" file="$sourcedir/SolveTopic.php" reverse="true" />
78
+
79
+		<hook function="integrate_display_buttons_solveTopic" hook="integrate_display_buttons" file="$sourcedir/SolveTopic.php" reverse="true" />
80
+		<hook function="integrate_display_topic_solveTopic" hook="integrate_display_topic" file="$sourcedir/SolveTopic.php" reverse="true" />
81
+
82
+		<hook function="integrate_message_index_solveTopic" hook="integrate_message_index" file="$sourcedir/SolveTopic.php" reverse="true" />
83
+		<hook function="integrate_messageindex_buttons_solveTopic" hook="integrate_messageindex_buttons" file="$sourcedir/SolveTopic.php" reverse="true" />
84
+
85
+		<hook function="integrate_log_types_solveTopic" hook="integrate_log_types" file="$sourcedir/SolveTopic.php" reverse="true" />
86
+		<hook function="integrate_viewModLog_solveTopic" hook="integrate_viewModLog" file="$sourcedir/SolveTopic-Admin.php" reverse="true" />
87
+	</uninstall>	
88
+
30 89
 </package-info>
31 90
\ No newline at end of file
... ...
@@ -1 +1 @@
1
-Insert nice description here.
2 1
\ No newline at end of file
2
+Topic Solved for SMF 2.0/2.1
3 3
\ No newline at end of file