1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* mylinks Utility Class Elements |
5
|
|
|
* |
6
|
|
|
* @copyright :: ZySpec Incorporated |
7
|
|
|
* @license :: {@link http://www.gnu.org/licenses/gpl-2.0.html GNU Public License} |
8
|
|
|
* @package :: mylinks |
9
|
|
|
* @subpackage:: class |
10
|
|
|
* @author :: zyspec ([email protected]) |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
defined('XOOPS_ROOT_PATH') or die('Restricted access'); |
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* MylinksUtility |
17
|
|
|
* |
18
|
|
|
* @package :: mylinks |
19
|
|
|
* @author :: zyspec ([email protected]), Herve Thouzard |
20
|
|
|
* @copyright :: {@link http://xoops.org/ XOOPS Project} |
21
|
|
|
* @copyright :: Copyright (c) 2010 ZySpec Incorporated, Herve Thouzard |
22
|
|
|
* @access:: public |
23
|
|
|
*/ |
24
|
|
|
class MylinksUtility |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Sanitize input variables |
28
|
|
|
* @param string $global the input array ($_REQUEST, $_GET, $_POST) |
29
|
|
|
* @param unknown_type $key the array key for variable to clean |
30
|
|
|
* @param string|unknown_type $default the default value to use if filter fails |
31
|
|
|
* @param string $type the variable type (string, email, url, int) |
32
|
|
|
* @param array $limit 'min' 'max' keys - the lower/upper limit for integer values |
|
|
|
|
33
|
|
|
* @return Ambigous|number <boolean, unknown> |
34
|
|
|
*/ |
35
|
|
|
public static function mylinks_cleanVars(&$global, $key, $default = '', $type = 'int', $limit = null) |
36
|
|
|
{ |
37
|
|
|
switch ($type) { |
38
|
|
|
case 'string': |
39
|
|
|
$ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_MAGIC_QUOTES) : $default; |
40
|
|
|
break; |
41
|
|
|
case 'email': |
42
|
|
|
$ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_EMAIL) : $default; |
43
|
|
|
break; |
44
|
|
|
case 'url': |
45
|
|
|
$ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_URL) : $default; |
46
|
|
|
break; |
47
|
|
|
case 'int': |
48
|
|
|
default: |
49
|
|
|
$default = (int)$default; |
50
|
|
|
$ret = isset($global[$key]) ? filter_var($global[$key], FILTER_SANITIZE_NUMBER_INT) : false; |
51
|
|
|
if (isset($limit) && is_array($limit) && (false !== $ret)) { |
52
|
|
View Code Duplication |
if (array_key_exists('min', $limit)) { |
|
|
|
|
53
|
|
|
$ret = ($ret >= $limit['min']) ? $ret : false; |
54
|
|
|
} |
55
|
|
View Code Duplication |
if (array_key_exists('max', $limit)) { |
|
|
|
|
56
|
|
|
$ret = ($ret <= $limit['max']) ? $ret : false; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
break; |
60
|
|
|
} |
61
|
|
|
$ret = ($ret === false) ? $default : $ret; |
62
|
|
|
|
63
|
|
|
return $ret; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* |
68
|
|
|
* Temporary patch for errorHandler processing |
69
|
|
|
* @deprecated |
70
|
|
|
* @param string $msg message to display |
71
|
|
|
* @param int $pages number of pages to jump back for link |
72
|
|
|
* @param string $type error||info to add errorMsg CSS to display |
73
|
|
|
* @return null |
74
|
|
|
*/ |
75
|
|
|
public static function show_message($msg, $pages = 1, $type = 'error') |
76
|
|
|
{ |
77
|
|
|
switch (mb_strtolower($type)) { |
78
|
|
|
case 'error': |
79
|
|
|
$div_class = "class='errorMsg'"; |
80
|
|
|
break; |
81
|
|
|
case 'info': |
82
|
|
|
$div_class = ''; |
83
|
|
|
break; |
84
|
|
|
} |
85
|
|
|
include_once XOOPS_ROOT_PATH . '/header.php'; |
86
|
|
|
echo "<div{$div_class}><strong>{$xoopsConfig['sitename']} Error</strong><br><br>\n" . "Error Code: {$e_code}<br><br><br>\n" . "<strong>ERROR:</strong> {$msg}<br>\n"; |
|
|
|
|
87
|
|
|
$pages = (int)$pages; |
88
|
|
|
if (0 != $pages) { |
89
|
|
|
$pages = '-' . abs($pages); |
90
|
|
|
echo "<br><br>\n" . "[ <a href=\'javascript:history.go(-{$pages})\'>" . _BACK . '</a> ]</div>'; |
91
|
|
|
} |
92
|
|
|
include_once XOOPS_ROOT_PATH . '/footer.php'; |
93
|
|
|
|
94
|
|
|
return; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.