Jeremy D commited on 2022-03-27 10:05:34
Showing 3 changed files, with 53 additions and 8 deletions.
... | ... |
@@ -221,12 +221,23 @@ class SFS |
221 | 221 |
$profile_areas['info']['areas']['sfs'] = [ |
222 | 222 |
'label' => $this->txt('sfs_profile'), |
223 | 223 |
'file' => 'SFS.php', |
224 |
+ 'icon' => 'sfs.webp', |
|
224 | 225 |
'function' => 'SFS::ProfileTrackSFS', |
225 | 226 |
'permission' => [ |
226 | 227 |
'own' => ['moderate_forum'], |
227 | 228 |
'any' => ['moderate_forum'], |
228 | 229 |
], |
229 | 230 |
]; |
231 |
+ |
|
232 |
+ // SMF 2.0 can't call objects or classes. |
|
233 |
+ if ($this->versionCheck('2.0', 'smf')) |
|
234 |
+ { |
|
235 |
+ function ProfileTrackSFS20(int $memID) |
|
236 |
+ { |
|
237 |
+ return SFS::ProfileTrackSFS($memID); |
|
238 |
+ } |
|
239 |
+ $profile_areas['info']['areas']['sfs']['function'] = 'ProfileTrackSFS20'; |
|
240 |
+ } |
|
230 | 241 |
} |
231 | 242 |
|
232 | 243 |
/** |
... | ... |
@@ -259,7 +270,7 @@ class SFS |
259 | 270 |
*/ |
260 | 271 |
public function TrackSFS(int $memID): void |
261 | 272 |
{ |
262 |
- global $user_profile, $context, $smcFunc, $scripturl, $modSettings; |
|
273 |
+ global $user_profile, $context, $smcFunc, $scripturl, $modSettings, $sourcedir; |
|
263 | 274 |
|
264 | 275 |
isAllowedTo('moderate_forum'); |
265 | 276 |
|
... | ... |
@@ -299,7 +310,7 @@ class SFS |
299 | 310 |
} |
300 | 311 |
|
301 | 312 |
// CHeck if we have this info. |
302 |
- if (($cache = cache_get_data($cache_key)) === null || ($response = $smcFunc['json_decode']($cache, true)) === null) |
|
313 |
+ if (($cache = cache_get_data($cache_key)) === null || ($response = $this->decodeJSON($cache, true)) === null) |
|
303 | 314 |
{ |
304 | 315 |
$checks = [ |
305 | 316 |
['username' => $user_profile[$memID]['real_name']], |
... | ... |
@@ -312,7 +323,7 @@ class SFS |
312 | 323 |
$this->buildCheckPath($requestURL, $checks, 'profile'); |
313 | 324 |
$response = (array) $this->sendSFSCheck($requestURL, $checks, 'profile'); |
314 | 325 |
|
315 |
- cache_put_data($cache_key, $smcFunc['json_encode']($response), 600); |
|
326 |
+ cache_put_data($cache_key, $this->encodeJSON($response), 600); |
|
316 | 327 |
} |
317 | 328 |
|
318 | 329 |
// Prepare for the template. |
... | ... |
@@ -325,6 +336,8 @@ class SFS |
325 | 336 |
$context['sfs_submit_url'] = $scripturl . '?action=profile;area=sfs;u=' . $memID; |
326 | 337 |
if (!$this->versionCheck('2.0', 'smf')) |
327 | 338 |
createToken($context['token_check'], 'post'); |
339 |
+ else |
|
340 |
+ unset($context['token_check']); |
|
328 | 341 |
} |
329 | 342 |
|
330 | 343 |
loadTemplate('StopForumSpam'); |
... | ... |
@@ -750,7 +763,7 @@ class SFS |
750 | 763 |
$type == 'email' ? $check['value'] : '', |
751 | 764 |
$type == 'ip' ? $check['value'] : $user_info['ip'], |
752 | 765 |
$user_info['ip2'], |
753 |
- json_encode($check), |
|
766 |
+ $this->encodeJSON($check), |
|
754 | 767 |
'Blocked' |
755 | 768 |
), |
756 | 769 |
array('id_sfs', 'id_type') |
... | ... |
@@ -839,6 +852,38 @@ class SFS |
839 | 852 |
} |
840 | 853 |
} |
841 | 854 |
|
855 |
+ /** |
|
856 |
+ * json JSON data and return it. |
|
857 |
+ * If we have $smcFunc['json_encode'], we use this as it handles errors natively. |
|
858 |
+ * For all others, we simply ensure a proper array is returned in the event of a error. |
|
859 |
+ * |
|
860 |
+ * @param array $requestData A properly formatted json string. |
|
861 |
+ * |
|
862 |
+ * @internal |
|
863 |
+ * @CalledIn SMF 2.0, SMF 2.1 |
|
864 |
+ * @version 1.1 |
|
865 |
+ * @since 1.1 |
|
866 |
+ * @return string The stringified array. |
|
867 |
+ */ |
|
868 |
+ public function encodeJSON(array $requestData): string |
|
869 |
+ { |
|
870 |
+ global $smcFunc; |
|
871 |
+ |
|
872 |
+ // Do we have $smcFunc? It handles errors and logs them as needed. |
|
873 |
+ if (isset($smcFunc['json_encode']) && is_callable($smcFunc['json_encode'])) |
|
874 |
+ return $smcFunc['json_encode']($requestData); |
|
875 |
+ // Back to the basics. |
|
876 |
+ else |
|
877 |
+ { |
|
878 |
+ $data = @json_encode($requestData); |
|
879 |
+ |
|
880 |
+ // We got a error, return nothing. Don't log this, not worth it. |
|
881 |
+ if (json_last_error() !== JSON_ERROR_NONE) |
|
882 |
+ return null; |
|
883 |
+ return $data; |
|
884 |
+ } |
|
885 |
+ } |
|
886 |
+ |
|
842 | 887 |
/** |
843 | 888 |
* Build the SFS Server URL based on our configuration setup. |
844 | 889 |
* |
... | ... |
@@ -97,7 +97,7 @@ function template_profile_tracksfs() |
97 | 97 |
|
98 | 98 |
if (!empty($context['token_check'])) |
99 | 99 |
echo ' |
100 |
- <input type="hidden" name="' . $context[$context['token_check'] . '_token_var'] . '" value="' . $context[$context['token_check'] . '_token'] . '"> |
|
100 |
+ <input type="hidden" name="' . $context[$context['token_check'] . '_token_var'] . '" value="' . $context[$context['token_check'] . '_token'] . '">'; |
|
101 | 101 |
|
102 | 102 |
echo ' |
103 | 103 |
</form>'; |
... | ... |
@@ -78,7 +78,7 @@ |
78 | 78 |
<hook hook="integrate_manage_logs" function="SFSA::hook_manage_logs" /> |
79 | 79 |
|
80 | 80 |
<!-- Profile Section --> |
81 |
- <hook hook="integrate_pre_profile_areas" function="SFSA::hook_pre_profile_areas" /> |
|
81 |
+ <hook hook="integrate_pre_profile_areas" function="SFS::hook_pre_profile_areas" /> |
|
82 | 82 |
|
83 | 83 |
<redirect url="?action=admin;area=modsettings;sa=sfs" /> |
84 | 84 |
</install> |
... | ... |
@@ -101,7 +101,7 @@ |
101 | 101 |
<hook hook="integrate_manage_logs" function="SFSA::hook_manage_logs" reverse="true" /> |
102 | 102 |
|
103 | 103 |
<!-- Profile Section --> |
104 |
- <hook hook="integrate_pre_profile_areas" function="SFSA::hook_pre_profile_areas" reverse="true" /> |
|
104 |
+ <hook hook="integrate_pre_profile_areas" function="SFS::hook_pre_profile_areas" reverse="true" /> |
|
105 | 105 |
|
106 | 106 |
<!-- language files, removed --> |
107 | 107 |
<remove-file name="$themes_dir/default/languages/StopForumSpam.english.php" /> |
... | ... |
@@ -119,7 +119,7 @@ |
119 | 119 |
<require-file name="StopForumSpam.template.php" destination="$themedir" /> |
120 | 120 |
<require-file name="SFS.php" destination="$sourcedir" /> |
121 | 121 |
<require-file name="SFS-Subs-Admin.php" destination="$sourcedir" /> |
122 |
- <hook hook="integrate_pre_profile_areas" function="SFSA::hook_pre_profile_areas" /> |
|
122 |
+ <hook hook="integrate_pre_profile_areas" function="SFS::hook_pre_profile_areas" /> |
|
123 | 123 |
|
124 | 124 |
<!-- this dir may not exist in SMF --> |
125 | 125 |
<create-dir name="admin" destination="$themedir/images" /> |
126 | 126 |