Skip to content

Commit bf16922

Browse files
authored
Smarty stripslashes and htmlspecialchars (#883)
* smarty_stripslashes Resolved warning for php8.1: - Deprecated: Using php-function "stripslashes" as a modifier is deprecated and will be removed in a future release. Use Smarty::registerPlugin to explicitly register a custom modifier. in .../includes/vendor/smarty/smarty/libs/sysplugins/smarty_internal_compile_private_modifier.php on line 114 * smarty_htmlspecialchars Resolved warning for php8.1: - Deprecated: Using php-function "htmlspecialchars" as a modifier is deprecated and will be removed in a future release. Use Smarty::registerPlugin to explicitly register a custom modifier. in .../includes/vendor/smarty/smarty/libs/sysplugins/smarty_internal_compile_private_modifier.php on line 114
1 parent a47d90a commit bf16922

9 files changed

+49
-16
lines changed

web/includes/SmartyCustomFunctions.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,35 @@ function smarty_function_sb_button($params) //$text, $click, $class, $id="", $su
5454
function smarty_function_load_template(array $params): void
5555
{
5656
require TEMPLATES_PATH . "/{$params['file']}.php";
57+
}
58+
59+
/**
60+
* Smarty {smarty_stripslashes} function plugin
61+
*
62+
* Type: function<br>
63+
* Name: smarty_stripslashes<br>
64+
* Purpose: custom stripslashes function
65+
* @link https://github.com/lechuga16/sourcebans-pp/tree/smarty_stripslashes
66+
* @author Lechuga
67+
* @param array $params
68+
* @return string
69+
* @version 1.0
70+
*/
71+
function smarty_stripslashes($string)
72+
{
73+
return stripslashes($string);
74+
}
75+
76+
/**
77+
* Smarty {smarty_htmlspecialchars} function plugin
78+
*
79+
* Type: function<br>
80+
* Name: smarty_htmlspecialchars<br>
81+
* Purpose: custom htmlspecialchars function
82+
* @link https://github.com/lechuga16/sourcebans-pp/tree/smarty_stripslashes
83+
* @author Lechuga
84+
* @param array $params
85+
*/
86+
function smarty_htmlspecialchars($string, $flags = ENT_COMPAT | ENT_HTML401, $encoding = 'UTF-8', $double_encode = true) {
87+
return htmlspecialchars($string, $flags, $encoding, $double_encode);
5788
}

web/init.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ function sbError($errno, $errstr, $errfile, $errline)
203203
$theme->registerPlugin(Smarty::PLUGIN_FUNCTION, 'help_icon', 'smarty_function_help_icon');
204204
$theme->registerPlugin(Smarty::PLUGIN_FUNCTION, 'sb_button', 'smarty_function_sb_button');
205205
$theme->registerPlugin(Smarty::PLUGIN_FUNCTION, 'load_template', 'smarty_function_load_template');
206+
$theme->registerPlugin('modifier', 'smarty_stripslashes', 'smarty_stripslashes');
207+
$theme->registerPlugin('modifier', 'smarty_htmlspecialchars', 'smarty_htmlspecialchars');
206208

207209
if ((isset($_GET['debug']) && $_GET['debug'] == 1) || DEBUG_MODE) {
208210
$theme->force_compile = true;

web/themes/default/page_admin_bans_submissions.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<td class="listtable_1" height='16'>
2020
<a href="#" onclick="xajax_SetupBan({$sub.subid});return false;">Ban</a> -
2121
{if $permissions_editsub}
22-
<a href="#" onclick="RemoveSubmission({$sub.subid}, '{$sub.name|stripslashes}', '1');return false;">Remove</a> -
22+
<a href="#" onclick="RemoveSubmission({$sub.subid}, '{$sub.name|smarty_stripslashes}', '1');return false;">Remove</a> -
2323
{/if}
2424
<a href="index.php?p=admin&c=bans&o=email&type=s&id={$sub.subid}">Contact</a>
2525
</td>

web/themes/default/page_admin_bans_submissions_archiv.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
{if $sub.archiv != "2" and $sub.archiv != "3"}
2121
<a href="#" onclick="xajax_SetupBan({$sub.subid});">Ban</a> -
2222
{if $permissions_editsub}
23-
<a href="#" onclick="RemoveSubmission({$sub.subid}, '{$sub.name|stripslashes}', '2');">Restore</a> -
23+
<a href="#" onclick="RemoveSubmission({$sub.subid}, '{$sub.name|smarty_stripslashes}', '2');">Restore</a> -
2424
{/if}
2525
{/if}
2626
{if $permissions_editsub}
27-
<a href="#" onclick="RemoveSubmission({$sub.subid}, '{$sub.name|stripslashes}', '0');">Delete</a> -
27+
<a href="#" onclick="RemoveSubmission({$sub.subid}, '{$sub.name|smarty_stripslashes}', '0');">Delete</a> -
2828
{/if}
2929
<a href="index.php?p=admin&c=bans&o=email&type=s&id={$sub.subid}">Contact</a>
3030
</td>

web/themes/default/page_admin_groups_list.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
{foreach from=$server_overrides_list[$smarty.foreach.server_admin_group.index] item="override"}
163163
<tr>
164164
<td width="60%" height="16" class="listtable_1">{$override.type}</td>
165-
<td width="60%" height="16" class="listtable_1">{$override.name|htmlspecialchars}</td>
165+
<td width="60%" height="16" class="listtable_1">{$override.name|smarty_htmlspecialchars}</td>
166166
<td width="60%" height="16" class="listtable_1">{$override.access}</td>
167167
</tr>
168168
{/foreach}

web/themes/default/page_admin_mods_list.tpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414
</tr>
1515
{foreach from=$mod_list item="mod" name="gaben"}
1616
<tr id="mid_{$mod.mid}">
17-
<td class="listtable_1" height='16'>{$mod.name|htmlspecialchars}</td>
18-
<td class="listtable_1" height='16'>{$mod.modfolder|htmlspecialchars}</td>
17+
<td class="listtable_1" height='16'>{$mod.name|smarty_htmlspecialchars}</td>
18+
<td class="listtable_1" height='16'>{$mod.modfolder|smarty_htmlspecialchars}</td>
1919
<td class="listtable_1" height='16'><img src="images/games/{$mod.icon}" width="16"></td>
20-
<td class="listtable_1" height='16'>{$mod.steam_universe|htmlspecialchars}</td>
20+
<td class="listtable_1" height='16'>{$mod.steam_universe|smarty_htmlspecialchars}</td>
2121
{if $permission_editmods || $permission_deletemods}
2222
<td class="listtable_1" height='16'>
2323
{if $permission_editmods}
2424
<a href="index.php?p=admin&c=mods&o=edit&id={$mod.mid}">Edit</a> -
2525
{/if}
2626
{if $permission_deletemods}
27-
<a href="#" onclick="RemoveMod('{$mod.name|escape:'quotes'|htmlspecialchars}', '{$mod.mid}');">Delete</a>
27+
<a href="#" onclick="RemoveMod('{$mod.name|escape:'quotes'|smarty_htmlspecialchars}', '{$mod.mid}');">Delete</a>
2828
{/if}
2929
</td>
3030
{/if}

web/themes/default/page_admin_overrides.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
</select>
3030
<input type="hidden" name="override_id[]" value="{$override.id}" />
3131
</td>
32-
<td class="tablerow1"><input name="override_name[]" value="{$override.name|htmlspecialchars}" /></td>
33-
<td class="tablerow1"><input name="override_flags[]" value="{$override.flags|htmlspecialchars}" /></td>
32+
<td class="tablerow1"><input name="override_name[]" value="{$override.name|smarty_htmlspecialchars}" /></td>
33+
<td class="tablerow1"><input name="override_flags[]" value="{$override.flags|smarty_htmlspecialchars}" /></td>
3434
</tr>
3535
{/foreach}
3636
<tr>

web/themes/default/page_bans.tpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<br />
5757
{load_template file='admin.bans.search'}
5858
<br />
59-
<div id="banlist-nav"><a href="index.php?p=banlist&hideinactive={if $hidetext == 'Hide'}true{else}false{/if}{$searchlink|htmlspecialchars}" title="{$hidetext} inactive">{$hidetext} inactive</a> | <i>Total Bans: {$total_bans}</i></div>
59+
<div id="banlist-nav"><a href="index.php?p=banlist&hideinactive={if $hidetext == 'Hide'}true{else}false{/if}{$searchlink|smarty_htmlspecialchars}" title="{$hidetext} inactive">{$hidetext} inactive</a> | <i>Total Bans: {$total_bans}</i></div>
6060
<div id="banlist">
6161
<table width="100%" cellspacing="0" cellpadding="0" align="center" class="listtable">
6262
<tr>
@@ -87,7 +87,7 @@
8787
{if empty($ban.player)}
8888
<i><font color="#677882">no nickname present</font></i>
8989
{else}
90-
{$ban.player|escape:'html'|stripslashes}
90+
{$ban.player|escape:'html'|smarty_stripslashes}
9191
{/if}
9292
</div>
9393
{if $ban.demo_available}
@@ -128,7 +128,7 @@
128128
{if empty($ban.player)}
129129
<i><font color="#677882">no nickname present</font></i>
130130
{else}
131-
{$ban.player|escape:'html'|stripslashes}
131+
{$ban.player|escape:'html'|smarty_stripslashes}
132132
{/if}
133133
</td>
134134
<!-- ###############[ Start Admin Controls ]################## -->

web/themes/default/page_comms.tpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<div id="banlist-nav">
6060
{$ban_nav}
6161
</div>
62-
<a href="index.php?p=commslist&hideinactive={if $hidetext == 'Hide'}true{else}false{/if}{$searchlink|htmlspecialchars}" title="{$hidetext} inactive">{$hidetext} inactive</a>
62+
<a href="index.php?p=commslist&hideinactive={if $hidetext == 'Hide'}true{else}false{/if}{$searchlink|smarty_htmlspecialchars}" title="{$hidetext} inactive">{$hidetext} inactive</a>
6363
<div id="banlist">
6464
<table width="100%" cellspacing="0" cellpadding="0" align="center" class="listtable">
6565
<tr>
@@ -84,7 +84,7 @@
8484
{if empty($ban.player)}
8585
<i><font color="#677882">no nickname present</font></i>
8686
{else}
87-
{$ban.player|escape:'html'|stripslashes}
87+
{$ban.player|escape:'html'|smarty_stripslashes}
8888
{/if}
8989
</div>
9090
<div style="float:right;">
@@ -127,7 +127,7 @@
127127
{if empty($ban.player)}
128128
<i><font color="#677882">no nickname present</font></i>
129129
{else}
130-
{$ban.player|escape:'html'|stripslashes}
130+
{$ban.player|escape:'html'|smarty_stripslashes}
131131
{/if}
132132
</td>
133133
<!-- ###############[ Start Admin Controls ]################## -->

0 commit comments

Comments
 (0)