1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* NewBB 5.0x, the forum module for XOOPS project |
4
|
|
|
* |
5
|
|
|
* @copyright XOOPS Project (http://xoops.org) |
6
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
7
|
|
|
* @author Taiwen Jiang (phppp or D.J.) <[email protected]> |
8
|
|
|
* @since 4.00 |
9
|
|
|
* @package module::newbb |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
use Xmf\Request; |
13
|
|
|
|
14
|
|
|
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
|
|
|
|
15
|
|
|
|
16
|
|
|
defined('NEWBB_FUNCTIONS_INI') || include_once __DIR__ . '/functions.ini.php'; |
17
|
|
|
define('NEWBB_FUNCTIONS_SESSION_LOADED', true); |
18
|
|
|
xoops_load('XoopsRequest'); |
19
|
|
|
|
20
|
|
|
if (!defined('NEWBB_FUNCTIONS_SESSION')) { |
21
|
|
|
define('NEWBB_FUNCTIONS_SESSION', 1); |
22
|
|
|
|
23
|
|
|
/* |
24
|
|
|
* Currently the newbb session/cookie handlers are limited to: |
25
|
|
|
* -- one dimension |
26
|
|
|
* -- "," and "|" are preserved |
27
|
|
|
* |
28
|
|
|
*/ |
29
|
|
|
/** |
30
|
|
|
* @param $name |
31
|
|
|
* @param string $string |
32
|
|
|
*/ |
33
|
|
|
function newbbSetSession($name, $string = '') |
|
|
|
|
34
|
|
|
{ |
35
|
|
View Code Duplication |
if (is_array($string)) { |
|
|
|
|
36
|
|
|
$value = []; |
37
|
|
|
foreach ($string as $key => $val) { |
38
|
|
|
$value[] = $key . '|' . $val; |
39
|
|
|
} |
40
|
|
|
$string = implode(',', $value); |
41
|
|
|
} |
42
|
|
|
$_SESSION['newbb_' . $name] = $string; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param $name |
47
|
|
|
* @param bool $isArray |
48
|
|
|
* @return array|bool |
49
|
|
|
*/ |
50
|
|
|
function newbbGetSession($name, $isArray = false) |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
$value = !empty($_SESSION['newbb_' . $name]) ? $_SESSION['newbb_' . $name] : false; |
53
|
|
|
if ($isArray) { |
54
|
|
|
$_value = $value ? explode(',', $value) : []; |
55
|
|
|
$value = []; |
56
|
|
|
if (count($_value) > 0) { |
57
|
|
|
foreach ($_value as $string) { |
58
|
|
|
$key = substr($string, 0, strpos($string, '|')); |
59
|
|
|
$val = substr($string, strpos($string, '|') + 1); |
60
|
|
|
$value[$key] = $val; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
unset($_value); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $value; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param $name |
71
|
|
|
* @param string $string |
72
|
|
|
* @param int $expire |
73
|
|
|
*/ |
74
|
|
|
function newbbSetCookie($name, $string = '', $expire = 0) |
75
|
|
|
{ |
76
|
|
|
global $forumCookie; |
|
|
|
|
77
|
|
View Code Duplication |
if (is_array($string)) { |
|
|
|
|
78
|
|
|
$value = []; |
79
|
|
|
foreach ($string as $key => $val) { |
80
|
|
|
$value[] = $key . '|' . $val; |
81
|
|
|
} |
82
|
|
|
$string = implode(',', $value); |
83
|
|
|
} |
84
|
|
|
setcookie($forumCookie['prefix'] . $name, $string, (int)$expire, $forumCookie['path'], $forumCookie['domain'], $forumCookie['secure']); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param $name |
89
|
|
|
* @param bool $isArray |
90
|
|
|
* @return array|null |
91
|
|
|
*/ |
92
|
|
|
function newbbGetCookie($name, $isArray = false) |
93
|
|
|
{ |
94
|
|
|
global $forumCookie; |
|
|
|
|
95
|
|
|
// $value = !empty($_COOKIE[$forumCookie['prefix'] . $name]) ? $_COOKIE[$forumCookie['prefix'] . $name] : null; |
|
|
|
|
96
|
|
|
$value = Request::getString($forumCookie['prefix'] . $name, null, 'COOKIE'); |
97
|
|
|
|
98
|
|
|
if ($isArray) { |
99
|
|
|
$_value = $value ? explode(',', $value) : []; |
100
|
|
|
$value = []; |
101
|
|
|
if (count($_value) > 0) { |
102
|
|
|
foreach ($_value as $string) { |
103
|
|
|
$sep = strpos($string, '|'); |
104
|
|
|
if ($sep === false) { |
105
|
|
|
$value[] = $string; |
106
|
|
|
} else { |
107
|
|
|
$key = substr($string, 0, $sep); |
108
|
|
|
$val = substr($string, $sep + 1); |
109
|
|
|
$value[$key] = $val; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
unset($_value); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return $value; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
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.