Add SMF 2.1 Support
jdarwood007

jdarwood007 commited on 2017-09-16 18:11:04
Showing 4 changed files, with 314 additions and 2 deletions.


Signed-off-by: jdarwood007 <unmonitored+github@sleepycode.com>
... ...
@@ -1,4 +1,4 @@
1
-Copyright (c) 2011, SleePy (smf [dash] mods [dash] license [dash] a2ebg [at] sleepycode [dot]com)
1
+Copyright (c) 2017, SleePy (smf [dash] mods [dash] license [dash] a2ebg [at] sleepycode [dot]com)
2 2
 All rights reserved.
3 3
 
4 4
 Redistribution and use in source and binary forms, with or without
... ...
@@ -0,0 +1,300 @@
1
+<?xml version="1.0"?>
2
+<!DOCTYPE modification SYSTEM "http://www.simplemachines.org/xml/modification">
3
+<!-- This package was generated by SleePys Modification Maker at https://sleepycode.com -->
4
+<modification xmlns="http://www.simplemachines.org/xml/modification" xmlns:smf="http://www.simplemachines.org/">
5
+	<id>SleePy:Add_to_existing_ban_group</id>
6
+	<version>1.1</version>
7
+	<file name="$languagedir/Modifications.english.php" error="skip">
8
+		<operation>
9
+			<search position="end" />
10
+			<add><![CDATA[
11
+$txt['aebg_add_existing'] = 'Add to existing ban group';
12
+$txt['aebg_new_ban_group'] = 'Create New Ban Group';
13
+$txt['aebg_ban_group'] = 'Allow quick ban?';
14
+$txt['aebg_ban_group_desc'] = 'Quick bans are done via ban link from profiles';
15
+$txt['aebg_auto_select'] = 'Easy Ban Auto select ban options';
16
+]]></add>
17
+		</operation>
18
+	</file>
19
+	<file name="$sourcedir/ManageSettings.php">
20
+		<operation>
21
+			<search position="before"><![CDATA[
22
+	$config_vars = array(
23
+		// Mod authors, add any settings UNDER this line. Include a comma at the end of the line and don't remove this statement!!
24
+]]></search>
25
+			<add><![CDATA[
26
+		array(
27
+			'select', 'aebg_auto_select',
28
+			array('main_ip_check' => $txt['ban_on_ip'], 'hostname_check' => $txt['ban_on_hostname'], 'email_check' => $txt['ban_on_email'], 'user_check' => $txt['ban_on_username']),
29
+			'multiple' => true,
30
+		),
31
+]]></add>
32
+		</operation>
33
+	</file>
34
+	<file name="$sourcedir/ManageBans.php">
35
+		<operation>
36
+			<search position="before"><![CDATA[
37
+		$ban_info['cannot']['login'] = !empty($ban_info['full_ban']) || empty($_POST['cannot_login']) ? 0 : 1;
38
+]]></search>
39
+			<add><![CDATA[		$ban_info['easy_ban_group'] = empty($_POST['easy_ban_group']) ? '0' : '1';
40
+]]></add>
41
+		</operation>
42
+		<operation>
43
+			<search position="after"><![CDATA[
44
+				$context['ban']['from_user'] = true;
45
+			}
46
+		}
47
+	}
48
+
49
+	loadJavaScriptFile('suggest.js', array(), 'smf_suggest');
50
+]]></search>
51
+			<add><![CDATA[				$context['ban']['from_user'] = true;
52
+			}
53
+
54
+			// Find our ban groups we can append.
55
+			$request = $smcFunc['db_query']('', '
56
+				SELECT id_ban_group, name
57
+				FROM {db_prefix}ban_groups
58
+				WHERE easy_bg = {int:one}
59
+				ORDER BY name',
60
+				array(
61
+					'one' => '1',
62
+				)
63
+			);
64
+			while ($row = $smcFunc['db_fetch_assoc']($request))
65
+				$context['ban_group_suggestions'][$row['id_ban_group']] = $row['name'];
66
+			$smcFunc['db_free_result']($request);
67
+
68
+			$context['ban_group_auto_selects'] = is_array($modSettings['aebg_auto_select']) ? $modSettings['aebg_auto_select'] : $smcFunc['json_decode']($modSettings['aebg_auto_select']);
69
+		}
70
+	}
71
+
72
+	loadJavaScriptFile('suggest.js', array(), 'smf_suggest');
73
+]]></add>
74
+		</operation>
75
+		<operation>
76
+			<search position="replace"><![CDATA[	// Yes yes, we're ready to add now.
77
+	$ban_info['id'] = $smcFunc['db_insert']('',
78
+		'{db_prefix}ban_groups',
79
+		array(
80
+			'name' => 'string-20', 'ban_time' => 'int', 'expire_time' => 'raw', 'cannot_access' => 'int', 'cannot_register' => 'int',
81
+			'cannot_post' => 'int', 'cannot_login' => 'int', 'reason' => 'string-255', 'notes' => 'string-65534',
82
+		),
83
+		array(
84
+			$ban_info['name'], time(), $ban_info['db_expiration'], $ban_info['cannot']['access'], $ban_info['cannot']['register'],
85
+			$ban_info['cannot']['post'], $ban_info['cannot']['login'], $ban_info['reason'], $ban_info['notes'],
86
+		),
87
+		array('id_ban_group'),
88
+		1
89
+	);
90
+]]></search>
91
+			<add><![CDATA[	// No No, we're not adding yet another group.
92
+	if (!empty($_REQUEST['ban_group']))
93
+	{
94
+		// Make sure the ban group exists.
95
+		$request = $smcFunc['db_query']('', '
96
+			SELECT id_ban_group
97
+			FROM {db_prefix}ban_groups
98
+			WHERE id_ban_group = {int:ban_group}',
99
+			array(
100
+				'ban_group' => $_REQUEST['ban_group'],
101
+			)
102
+		);
103
+		if ($smcFunc['db_num_rows']($request) != 1)
104
+			unset($_REQUEST['ban_group']);
105
+		else
106
+			$ban_info['id'] = (int) $_REQUEST['ban_group'];
107
+		$smcFunc['db_free_result']($request);
108
+	}
109
+
110
+	// Yes yes, we're ready to add now.
111
+	if (empty($ban_info['id']))
112
+	{
113
+		$ban_info['id'] = $smcFunc['db_insert']('',
114
+			'{db_prefix}ban_groups',
115
+			array(
116
+				'name' => 'string-20', 'ban_time' => 'int', 'expire_time' => 'raw', 'cannot_access' => 'int', 'cannot_register' => 'int',
117
+				'cannot_post' => 'int', 'cannot_login' => 'int', 'reason' => 'string-255', 'notes' => 'string-65534',
118
+				'easy_bg' => 'int',
119
+			),
120
+			array(
121
+				$ban_info['name'], time(), $ban_info['db_expiration'], $ban_info['cannot']['access'], $ban_info['cannot']['register'],
122
+				$ban_info['cannot']['post'], $ban_info['cannot']['login'], $ban_info['reason'], $ban_info['notes'],
123
+				$ban_info['easy_ban_group'],
124
+			),
125
+			array('id_ban_group'),
126
+			1
127
+		);
128
+	}]]></add>
129
+		</operation>
130
+		<operation>
131
+			<search position="replace"><![CDATA[
132
+			cannot_login = {int:cannot_login}
133
+		WHERE id_ban_group = {int:id_ban_group}',
134
+		array(
135
+			'expiration' => $ban_info['db_expiration'],
136
+]]></search>
137
+			<add><![CDATA[
138
+			cannot_login = {int:cannot_login},
139
+			easy_bg = {int:easy_bg}
140
+		WHERE id_ban_group = {int:id_ban_group}',
141
+		array(
142
+			'easy_bg' => $ban_info['easy_ban_group'],
143
+			'expiration' => $ban_info['db_expiration'],
144
+]]></add>
145
+		</operation>
146
+		<operation>
147
+			<search position="replace"><![CDATA[
148
+			COALESCE(mem.id_member, 0) AS id_member, mem.member_name, mem.real_name
149
+		FROM {db_prefix}ban_groups AS bg
150
+			LEFT JOIN {db_prefix}ban_items AS bi ON (bi.id_ban_group = bg.id_ban_group)
151
+]]></search>
152
+			<add><![CDATA[
153
+			COALESCE(mem.id_member, 0) AS id_member, mem.member_name, mem.real_name, bg.easy_bg
154
+		FROM {db_prefix}ban_groups AS bg
155
+			LEFT JOIN {db_prefix}ban_items AS bi ON (bi.id_ban_group = bg.id_ban_group)
156
+]]></add>
157
+		</operation>
158
+		<operation>
159
+			<search position="replace"><![CDATA[
160
+				'reason' => $row['reason'],
161
+				'notes' => $row['notes'],
162
+				'cannot' => array(
163
+]]></search>
164
+			<add><![CDATA[
165
+				'reason' => $row['reason'],
166
+				'notes' => $row['notes'],
167
+				'easy_bg' => $row['easy_bg'],
168
+				'cannot' => array(
169
+]]></add>
170
+		</operation>
171
+	</file>
172
+	<file name="$themedir/ManageBans.template.php">
173
+		<operation>
174
+			<search position="replace"><![CDATA[
175
+	echo '
176
+		<div class="windowbg2 noup">
177
+			<dl class="settings">
178
+				<dt id="ban_name_label">
179
+					<strong>', $txt['ban_name'], ':</strong>
180
+]]></search>
181
+			<add><![CDATA[
182
+	// Only allow selecting a ban group if it is new.
183
+	if ($context['ban']['is_new'] && !empty($context['ban_group_suggestions']))
184
+	{		
185
+		echo '
186
+					<fieldset>
187
+						<legend>', $txt['aebg_add_existing'], '</legend>
188
+						<select name="ban_group" onchange="disableOtherFields();" id="ban_group">
189
+							<option value="-1" selected="selected">', $txt['aebg_new_ban_group'], '</option>';
190
+
191
+		foreach ($context['ban_group_suggestions'] as $id_ban_group => $ban_name)
192
+			echo '
193
+							<option value="', $id_ban_group, '" onselect="disableOtherFields();">', $ban_name, '</option>';
194
+		echo '
195
+						</select>
196
+					</fieldset>';
197
+	}
198
+
199
+	echo '
200
+		<div class="windowbg2 noup">
201
+			<dl id="ban_info" class="settings">
202
+				<dt id="ban_name_label">
203
+					<strong>', $txt['ban_name'], ':</strong>
204
+]]></add>
205
+		</operation>
206
+		<operation>
207
+			<search position="before"><![CDATA[
208
+	if (isset($context['ban']['reason']))
209
+		echo '
210
+				<dt>
211
+					<strong><label for="reason">', $txt['ban_reason'], ':</label></strong><br>
212
+					<span class="smalltext">', $txt['ban_reason_desc'], '</span>
213
+				</dt>
214
+				<dd>
215
+					<textarea name="reason" id="reason" cols="40" rows="3" style="min-height: 64px; max-height: 64px; min-width: 50%; max-width: 99%;">', $context['ban']['reason'], '</textarea>
216
+				</dd>';
217
+]]></search>
218
+			<add><![CDATA[
219
+	echo '
220
+				<dt id="aebg_select">
221
+					<strong>', $txt['aebg_ban_group'], ':</strong><br />
222
+					<span class="smalltext">', $txt['aebg_ban_group_desc'], '</span>
223
+				</dt>
224
+				<dd>
225
+					<input type="checkbox" name="easy_ban_group" value="1" class="input_check"', !empty($context['ban']['easy_bg']) ? ' checked="checked"' : '', ' />
226
+				</dd>';
227
+]]></add>
228
+		</operation>
229
+		<operation>
230
+			<search position="replace"><![CDATA[
231
+				<fieldset class="ban_settings floatleft">
232
+					<legend>
233
+						', $txt['ban_expiration'], '
234
+]]></search>
235
+			<add><![CDATA[
236
+				<fieldset id="ban_expire" class="ban_settings floatleft">
237
+					<legend>
238
+						', $txt['ban_expiration'], '
239
+]]></add>
240
+		</operation>
241
+		<operation>
242
+			<search position="replace"><![CDATA[
243
+				<fieldset class="ban_settings floatright">
244
+					<legend>
245
+						', $txt['ban_restriction'], '
246
+]]></search>
247
+			<add><![CDATA[
248
+				<fieldset id="ban_restrict" class="ban_settings floatright">
249
+					<legend>
250
+						', $txt['ban_restriction'], '
251
+]]></add>
252
+		</operation>
253
+		<operation>
254
+			<search position="after"><![CDATA[
255
+		var fUpdateStatus = function ()
256
+		{
257
+			document.getElementById("expire_date").disabled = !document.getElementById("expires_one_day").checked;
258
+]]></search>
259
+			<add><![CDATA[';
260
+
261
+	// Only allow selecting a ban group if it is new.
262
+	if ($context['ban']['is_new'] && !empty($context['ban_group_suggestions']))
263
+	{
264
+		echo '
265
+		function disableOtherFields()
266
+		{
267
+			var display_value = document.getElementById("ban_group").value == "-1" ? "" : "none";
268
+
269
+			document.getElementById("ban_info").style.display = display_value;
270
+			document.getElementById("ban_expire").style.display = display_value;
271
+			document.getElementById("ban_restrict").style.display = display_value;';
272
+
273
+		// Do we want to auto select some options?
274
+		if (!empty($modSettings['aebg_auto_select']))
275
+		{
276
+			// Incase it isn't an array.
277
+			$allOptions = array_flip(array('main_ip_check', 'hostname_check', 'email_check', 'user_check'));
278
+			if (!empty($modSettings['disableHostnameLookup']))
279
+				unset($allOptions['hostname_check']);
280
+
281
+			$autoSelects = is_array($modSettings['aebg_auto_select']) ? $modSettings['aebg_auto_select'] : safe_unserialize($modSettings['aebg_auto_select']);
282
+			foreach ($autoSelects as $elID)
283
+			{
284
+				unset($allOptions[$elID]);
285
+				echo '
286
+			document.getElementById("', $elID, '").checked = "checked";';
287
+			}
288
+			foreach ($allOptions as $elID => $dummy)
289
+				echo '
290
+			document.getElementById("', $elID, '").checked = "";';
291
+		}
292
+		
293
+		echo '
294
+		}';
295
+	}
296
+
297
+	echo ']]></add>
298
+		</operation>
299
+	</file>
300
+</modification>
0 301
\ No newline at end of file
... ...
@@ -14,6 +14,8 @@ global $db_prefix, $modSettings, $func, $smcFunc;
14 14
 
15 15
 if (version_compare('2.0 RC2', $modSettings['smfVersion']) > 0)
16 16
 	exit('<b>Error:</b> Cannot install - Your SMF version is not sufficient enough.  Please upgrade to SMF 2.0 RC2 or higher');
17
+elseif (version_compare('2.1 Beta 2', $modSettings['smfVersion']) > 0 && version_compare('2.1 Beta 1', $modSettings['smfVersion']) < 0)
18
+	exit('<b>Error:</b> Cannot install - Your SMF version is not sufficient enough.  Please upgrade to SMF 2.1 Beta 3 or higher');
17 19
 
18 20
 // Our column.
19 21
 $smcFunc['db_add_column']($db_prefix . "ban_groups", array('name'=> 'easy_bg', 'type'=>'smallint', 'size' => '3'));
... ...
@@ -4,7 +4,7 @@
4 4
 <package-info xmlns="http://www.simplemachines.org/xml/package-info" xmlns:smf="http://www.simplemachines.org/">
5 5
 	<id>SleePy:Add_to_Existing_Ban_Group</id>
6 6
 	<name>Add to Existing Ban Group</name>
7
-	<version>1.0.3</version>
7
+	<version>1.1</version>
8 8
 	<type>modification</type>
9 9
 	<install for="2.0-2.0.99">
10 10
 		<readme>README.txt</readme>
... ...
@@ -14,4 +14,14 @@
14 14
 	<uninstall for="2.0-2.0.99">
15 15
 		<modification reverse="true">add_to_existing_ban_group-20x.xml</modification>
16 16
 	</uninstall>
17
+
18
+	<install for="2.1 Beta 3, 2.1 Beta 4, 2.1 RC1">
19
+		<readme>README.txt</readme>
20
+		<modification>add_to_existing_ban_group-21x.xml</modification>
21
+		<database>database_install.php</database>
22
+	</install>
23
+	<uninstall for="2.1 Beta 3, 2.1 Beta 4, 2.1 RC1">
24
+		<modification reverse="true">add_to_existing_ban_group-21x.xml</modification>
25
+	</uninstall>
26
+
17 27
 </package-info>
18 28
\ No newline at end of file
19 29