Skip to content

Commit 16bed0e

Browse files
PHP 8.1 compatibility fixes, fix for #1
1 parent 2df992e commit 16bed0e

7 files changed

Lines changed: 95 additions & 48 deletions

File tree

functions.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,41 @@
2020
exit('Cannot access this file directly');
2121
}
2222

23+
/* stupid PHP 8.1 fixes by florian -- BEGIN -- */
24+
25+
function lazystrip($val) {
26+
if ($val!==null) {
27+
$val = stripslashes($val);
28+
}
29+
return $val;
30+
}
31+
32+
function lazystriptags($val) {
33+
if ($val!==null) {
34+
$val = strip_tags($val);
35+
}
36+
return $val;
37+
}
38+
39+
function lazyspecial($val) {
40+
if ($val!==null) {
41+
$val = htmlspecialchars($val);
42+
}
43+
return $val;
44+
}
45+
46+
function lazyexplode($x,$y) {
47+
if ($y!==null) {
48+
$val = explode($x,$y);
49+
} else {
50+
$val = array();
51+
}
52+
return $val;
53+
}
54+
55+
/* stupid PHP 8.1 fixes by florian -- END -- */
56+
57+
2358
/* ---------- adapted from OfA for WebsiteBaker --------------- */
2459

2560
function is_serialized($data){

info.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
3737
DEVELOPMENT HISTORY:
3838
39+
v1.1.8 (Florian; 06/07/2022)
40+
! PHP 8.1 compatibility fixes
41+
! fix for backend display error when no items exist (thx to atlasfreak, see https://forum.wbce.org/viewtopic.php?id=4771)
42+
3943
v1.1.7 (Bernd; 27/12/2021)
4044
! Fix for search issue, see https://forum.wbce.org/viewtopic.php?pid=38845#p38845
4145
@@ -308,7 +312,7 @@
308312
$renamed_to = $mod_name == 'oneforall' ? '' : '(renamed to <strong>'.$module_name.'</strong>) ';
309313

310314
$module_function = 'page';
311-
$module_version = '1.1.7';
315+
$module_version = '1.1.8';
312316
$module_platform = '2.8.x';
313317
$module_author = 'Christoph Marti';
314318
$module_license = 'GNU General Public License';

modify.php

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
$inc_path = dirname(__FILE__);
2525
// Get module name
2626
require_once($inc_path.'/info.php');
27+
require_once($inc_path.'/functions.php');
2728

2829
// Make use of the skinable backend themes of WB > 2.7
2930
// Check if THEME_URL is supported otherwise use ADMIN_URL
@@ -169,24 +170,7 @@
169170
} else {
170171
$field_id = false;
171172
}
172-
?>
173173

174-
<table id="mod_<?php echo $mod_name; ?>_items_b" class="sortierbar">
175-
<thead>
176-
<tr>
177-
<th class="sortierbar">ID</th>
178-
<th></th>
179-
<th class="sortierbar"><?php echo $MOD_ONEFORALL[$mod_name]['TXT_TITLE']; ?></th>
180-
<th><?php if ($field_id) echo $MOD_ONEFORALL[$mod_name]['TXT_GROUP']; ?></th>
181-
<th class="sortierbar"><?php echo $MOD_ONEFORALL[$mod_name]['TXT_ENABLED']; ?></th>
182-
<th></th>
183-
<th></th>
184-
<th></th>
185-
</tr>
186-
</thead>
187-
<tbody>
188-
189-
<?php
190174
// Define the up and down arrows depending on ordering
191175
$position_order = $order_by_position_asc ? 'ASC' : 'DESC';
192176
$arrow1 = 'up';
@@ -205,6 +189,26 @@
205189
$query_items = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_".$mod_name."_items` WHERE section_id = '$section_id' AND title != '' ORDER BY position ".$position_order);
206190

207191
if ($query_items->numRows() > 0) {
192+
193+
?>
194+
195+
<table id="mod_<?php echo $mod_name; ?>_items_b" class="sortierbar">
196+
<thead>
197+
<tr>
198+
<th class="sortierbar">ID</th>
199+
<th></th>
200+
<th class="sortierbar"><?php echo $MOD_ONEFORALL[$mod_name]['TXT_TITLE']; ?></th>
201+
<th><?php if ($field_id) echo $MOD_ONEFORALL[$mod_name]['TXT_GROUP']; ?></th>
202+
<th class="sortierbar"><?php echo $MOD_ONEFORALL[$mod_name]['TXT_ENABLED']; ?></th>
203+
<th></th>
204+
<th></th>
205+
<th></th>
206+
</tr>
207+
</thead>
208+
<tbody>
209+
210+
<?php
211+
208212
$num_items = $query_items->numRows();
209213

210214
// Loop through existing items
@@ -217,7 +221,7 @@
217221

218222
// Sanitize
219223
$item = array_map('stripslashes', $item);
220-
$item = array_map('htmlspecialchars', $item);
224+
$item = array_map('lazyspecial', $item);
221225

222226
// Get item group id
223227
if ($field_id) {

save_fields.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
$inc_path = dirname(__FILE__);
2626
// Get module name
2727
require_once($inc_path.'/info.php');
28+
require_once($inc_path.'/functions.php');
2829

2930
// Look for language file
3031
if (LANGUAGE_LOADED) {
@@ -50,11 +51,11 @@
5051
foreach ($_POST['fields'] as $field_id => $fields) {
5152

5253
// Add slashes and remove any tags
53-
$field_id = $admin->add_slashes(strip_tags($field_id));
54-
$type = $admin->add_slashes(strip_tags($fields['type']));
55-
$extra = $admin->add_slashes(strip_tags($fields['extra']));
56-
$name = $admin->add_slashes(strip_tags($fields['name']));
57-
$label = $admin->add_slashes(strip_tags($fields['label']));
54+
$field_id = $admin->add_slashes(lazystriptags($field_id));
55+
$type = $admin->add_slashes(lazystriptags($fields['type']));
56+
$extra = $admin->add_slashes(lazystriptags($fields['extra']));
57+
$name = $admin->add_slashes(lazystriptags($fields['name']));
58+
$label = $admin->add_slashes(lazystriptags($fields['label']));
5859
$template = $admin->add_slashes($fields['template']);
5960

6061
// First delete field if requested
@@ -70,7 +71,7 @@
7071
$first_group_field_id = $database->get_one("SELECT field_id FROM `".TABLE_PREFIX."mod_".$mod_name."_fields` WHERE type = 'group'");
7172
// Error message and continue
7273
if ($type == 'group' && $first_group_field_id != null && $field_id != $first_group_field_id) {
73-
$errors[] = sprintf($MOD_ONEFORALL[$mod_name]['ERR_ONLY_ONE_GROUP_FIELD'], htmlspecialchars($name));
74+
$errors[] = sprintf($MOD_ONEFORALL[$mod_name]['ERR_ONLY_ONE_GROUP_FIELD'], lazyspecial($name));
7475
continue;
7576
}
7677

@@ -85,13 +86,13 @@
8586
// Prevent conflicts between customized field names and general placeholders
8687
$reserved_names = array('BACK', 'DATE', 'DISPLAY_NAME', 'DISPLAY_PREVIOUS_NEXT_LINKS', 'USER_EMAIL', 'FIELD_NAME', 'IMAGE', 'IMAGES', 'ITEM_ID', 'LINK', 'NEXT', 'NEXT_LINK', 'NEXT_PAGE_LINK', 'OF', 'OUT_OF', 'PAGE_TITLE', 'PREVIOUS', 'PREVIOUS_LINK', 'PREVIOUS_PAGE_LINK', 'TEXT_OF', 'TEXT_OUT_OF', 'TEXT_READ_MORE', 'TXT_BACK', 'TXT_DESCRIPTION', 'TXT_ITEM', 'THUMB', 'THUMBS', 'TIME', 'TITLE', 'USERNAME', 'USER_ID');
8788
if (in_array(strtoupper($name), $reserved_names)) {
88-
$errors[] = sprintf($MOD_ONEFORALL[$mod_name]['ERR_CONFLICT_WITH_RESERVED_NAME'], htmlspecialchars($name));
89+
$errors[] = sprintf($MOD_ONEFORALL[$mod_name]['ERR_CONFLICT_WITH_RESERVED_NAME'], lazyspecial($name));
8990
continue;
9091
}
9192

9293
// Check field name for invalid chars
9394
if (!preg_match('#^[a-zA-Z0-9._-]*$#', $name)) {
94-
$errors[] = sprintf($MOD_ONEFORALL[$mod_name]['ERR_INVALID_FIELD_NAME'], htmlspecialchars($name));
95+
$errors[] = sprintf($MOD_ONEFORALL[$mod_name]['ERR_INVALID_FIELD_NAME'], lazyspecial($name));
9596
continue;
9697
}
9798

@@ -125,7 +126,7 @@
125126
if ($database->is_error()) {
126127
if (false !== strpos($database->get_error(), 'Duplicate entry')) {
127128
if (!empty($name)) {
128-
$errors[] = sprintf($MOD_ONEFORALL[$mod_name]['ERR_FIELD_NAME_EXISTS'], htmlspecialchars($name));
129+
$errors[] = sprintf($MOD_ONEFORALL[$mod_name]['ERR_FIELD_NAME_EXISTS'], lazyspecial($name));
129130
}
130131
}
131132
// ...or get any other db error

save_general_settings.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
$inc_path = dirname(__FILE__);
2525
// Get module name
2626
require_once($inc_path.'/info.php');
27+
require_once($inc_path.'/functions.php');
2728

2829
// Check page and section id
2930
if (empty($_REQUEST['page_id']) OR !is_numeric($_REQUEST['page_id']) OR empty($_POST['section_id']) OR !is_numeric($_POST['section_id'])) {
@@ -43,7 +44,7 @@
4344
}
4445

4546
// Escape and strip tags
46-
$settings[$key] = strip_tags($admin->get_post_escaped($value));
47+
$settings[$key] = lazystriptags($admin->get_post_escaped($value));
4748

4849
// Validate (pseudo) boolean
4950
if (in_array($key, array('settings_admin_only', 'order_by_position_asc', 'show_item_mover', 'show_item_duplicator', 'wysiwyg_full_width', 'show_group_headers', 'order_by_group_asc', 'field_meta_desc', 'view_detail_pages', 'field_type_code', 'imgresize', 'set_scheduling', 'scheduling_debug'))) {

save_item.php

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
require('../../config.php');
3131
require($inc_path.'/resize_img.php');
3232
require($inc_path.'/pngthumb.php');
33+
require($inc_path.'/functions.php');
3334
require_once(WB_PATH.'/framework/functions.php');
3435

3536
// Get module name
@@ -72,21 +73,21 @@
7273
$item_dir = $page['link'];
7374

7475
// Remove any tags and add slashes
75-
$old_link = strip_tags($admin->get_post('link'));
76-
$old_section_id = strip_tags($admin->get_post('section_id'));
77-
$new_section_id = strip_tags($admin->get_post('new_section_id'));
78-
$action = strip_tags($admin->get_post('action'));
79-
$title = $admin->add_slashes(strip_tags($admin->get_post('title')));
80-
$scheduling_start = strip_tags($admin->get_post('scheduling_start'));
81-
$scheduling_end = strip_tags($admin->get_post('scheduling_end'));
82-
$description = $admin->add_slashes(strip_tags($admin->get_post('description')));
76+
$old_link = lazystriptags($admin->get_post('link'));
77+
$old_section_id = lazystriptags($admin->get_post('section_id'));
78+
$new_section_id = lazystriptags($admin->get_post('new_section_id'));
79+
$action = lazystriptags($admin->get_post('action'));
80+
$title = $admin->add_slashes(lazystriptags($admin->get_post('title')));
81+
$scheduling_start = lazystriptags($admin->get_post('scheduling_start'));
82+
$scheduling_end = lazystriptags($admin->get_post('scheduling_end'));
83+
$description = $admin->add_slashes(lazystriptags($admin->get_post('description')));
8384

8485
// Images
8586
$images = array();
8687
if (!empty($_POST['images'])) {
8788
foreach ($_POST['images'] as $img_id => $image) {
8889
// Strip tags and add slashes
89-
$image = array_map('strip_tags', $image);
90+
$image = array_map('lazystriptags', $image);
9091
$image = array_map('addslashes', $image);
9192
// Sanitize vars
9293
$image['active'] = empty($image['active']) ? 0 : 1;
@@ -96,11 +97,11 @@
9697
}
9798
}
9899

99-
$imgresize = strip_tags($admin->get_post('imgresize'));
100-
$quality = strip_tags($admin->get_post('quality'));
101-
$maxheight = strip_tags($admin->get_post('maxheight'));
102-
$maxwidth = strip_tags($admin->get_post('maxwidth'));
103-
$active = strip_tags($admin->get_post('active'));
100+
$imgresize = lazystriptags($admin->get_post('imgresize'));
101+
$quality = lazystriptags($admin->get_post('quality'));
102+
$maxheight = lazystriptags($admin->get_post('maxheight'));
103+
$maxwidth = lazystriptags($admin->get_post('maxwidth'));
104+
$active = lazystriptags($admin->get_post('active'));
104105

105106

106107

@@ -176,7 +177,7 @@
176177
if ($scheduling['ts_start'] && $scheduling['ts_end'] && $scheduling['ts_start'] >= $scheduling['ts_end']) {
177178
$scheduling['end'] = $scheduling['start'];
178179
$scheduling['ts_end'] = $scheduling['ts_start'];
179-
$errors[] = sprintf($MOD_ONEFORALL[$mod_name]['ERR_INVALID_SCHEDULING'], htmlspecialchars($scheduling_start), htmlspecialchars($scheduling_end));
180+
$errors[] = sprintf($MOD_ONEFORALL[$mod_name]['ERR_INVALID_SCHEDULING'], lazyspecial($scheduling_start), lazyspecial($scheduling_end));
180181
}
181182
// Serialize start and end time
182183
$scheduling = serialize($scheduling);
@@ -188,7 +189,7 @@
188189
$field_id = $field['field_id'];
189190
$email = $_POST['fields'][$field_id];
190191
if (!empty($email) && !filter_var($email, FILTER_VALIDATE_EMAIL)) {
191-
$errors[] = sprintf($MOD_ONEFORALL[$mod_name]['ERR_INVALID_EMAIL'], htmlspecialchars($email));
192+
$errors[] = sprintf($MOD_ONEFORALL[$mod_name]['ERR_INVALID_EMAIL'], lazyspecial($email));
192193
}
193194
}
194195
}
@@ -200,7 +201,7 @@
200201
$field_id = $field['field_id'];
201202
$url = $_POST['fields'][$field_id];
202203
if (!empty($url) && !filter_var($url, FILTER_VALIDATE_URL)) {
203-
$errors[] = sprintf($MOD_ONEFORALL[$mod_name]['ERR_INVALID_URL'], htmlspecialchars($url));
204+
$errors[] = sprintf($MOD_ONEFORALL[$mod_name]['ERR_INVALID_URL'], lazyspecial($url));
204205
}
205206
}
206207
}
@@ -280,12 +281,12 @@
280281
}
281282
// Check for invalid chars in filename
282283
if (!preg_match('#^[a-zA-Z0-9._-]*$#', $filename)) {
283-
$errors[] = $MOD_ONEFORALL[$mod_name]['ERR_INVALID_FILE_NAME'].": ".htmlspecialchars($filename.'.'.$fileext);
284+
$errors[] = $MOD_ONEFORALL[$mod_name]['ERR_INVALID_FILE_NAME'].": ".lazyspecial($filename.'.'.$fileext);
284285
continue;
285286
}
286287
// Check if filename already exists
287288
if (file_exists($file_path)) {
288-
$errors[] = $MESSAGE['MEDIA']['FILE_EXISTS'].": ".htmlspecialchars($filename.'.'.$fileext);
289+
$errors[] = $MESSAGE['MEDIA']['FILE_EXISTS'].": ".lazyspecial($filename.'.'.$fileext);
289290
continue;
290291
}
291292

save_page_settings.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
$inc_path = dirname(__FILE__);
2626
// Get module name
2727
require_once($inc_path.'/info.php');
28+
require_once($inc_path.'/functions.php');
2829

2930
// This code removes any php tags and adds slashes
3031
$friendly = array('&lt;', '&gt;', '?php');

0 commit comments

Comments
 (0)