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
|
|
|
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
|
|
|
|
13
|
|
|
|
14
|
|
|
defined('NEWBB_FUNCTIONS_INI') || include __DIR__ . '/functions.ini.php'; |
15
|
|
|
define('NEWBB_FUNCTIONS_RENDER_LOADED', true); |
16
|
|
|
|
17
|
|
|
if (!defined('NEWBB_FUNCTIONS_RENDER')) { |
18
|
|
|
define('NEWBB_FUNCTIONS_RENDER', 1); |
19
|
|
|
|
20
|
|
|
/* |
21
|
|
|
* Sorry, we have to use the stupid solution unless there is an option in MyTextSanitizer:: htmlspecialchars(); |
22
|
|
|
*/ |
23
|
|
|
/** |
24
|
|
|
* @param $text |
25
|
|
|
* @return mixed |
26
|
|
|
*/ |
27
|
|
|
function newbbHtmlspecialchars(&$text) |
28
|
|
|
{ |
29
|
|
|
return preg_replace(['/&/i', '/ /i'], ['&', '&nbsp;'], htmlspecialchars($text)); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param $text |
34
|
|
|
* @param int $html |
35
|
|
|
* @param int $smiley |
36
|
|
|
* @param int $xcode |
37
|
|
|
* @param int $image |
38
|
|
|
* @param int $br |
39
|
|
|
* @return mixed |
40
|
|
|
*/ |
41
|
|
|
function &newbbDisplayTarea(&$text, $html = 0, $smiley = 1, $xcode = 1, $image = 1, $br = 1) |
42
|
|
|
{ |
43
|
|
|
global $myts; |
|
|
|
|
44
|
|
|
|
45
|
|
|
if ($html !== 1) { |
46
|
|
|
// html not allowed |
47
|
|
|
$text = newbbHtmlspecialchars($text); |
48
|
|
|
} |
49
|
|
|
$text = $myts->codePreConv($text, $xcode); // Ryuji_edit(2003-11-18) |
|
|
|
|
50
|
|
|
$text = $myts->makeClickable($text); |
51
|
|
|
if ($smiley !== 0) { |
52
|
|
|
// process smiley |
53
|
|
|
$text = $myts->smiley($text); |
54
|
|
|
} |
55
|
|
|
if ($xcode !== 0) { |
56
|
|
|
// decode xcode |
57
|
|
|
if ($image !== 0) { |
58
|
|
|
// image allowed |
59
|
|
|
$text = $myts->xoopsCodeDecode($text); |
60
|
|
|
} else { |
61
|
|
|
// image not allowed |
62
|
|
|
$text = $myts->xoopsCodeDecode($text, 0); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
if ($br !== 0) { |
66
|
|
|
$text = $myts->nl2Br($text); |
67
|
|
|
} |
68
|
|
|
$text = $myts->codeConv($text, $xcode, $image); // Ryuji_edit(2003-11-18) |
|
|
|
|
69
|
|
|
|
70
|
|
|
return $text; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param $document |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
|
|
function newbbHtml2text($document) |
78
|
|
|
{ |
79
|
|
|
$text = strip_tags($document); |
80
|
|
|
|
81
|
|
|
return $text; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Display forrum button |
86
|
|
|
* |
87
|
|
|
* @param $link |
88
|
|
|
* @param $button |
89
|
|
|
* @param string $alt alt message |
90
|
|
|
* @param boolean $asImage true for image mode; false for text mode |
91
|
|
|
* @param string $extra extra attribute for the button |
92
|
|
|
* @return mixed |
93
|
|
|
* @internal param string $image image/button name, without extension |
94
|
|
|
*/ |
95
|
|
|
function newbbGetButton($link, $button, $alt = '', $asImage = true, $extra = "class='forum_button'") |
96
|
|
|
{ |
97
|
|
|
$button = "<input type='button' name='{$button}' {$extra} value='{$alt}' onclick='window.location.href={$link}' />"; |
98
|
|
|
if (empty($asImage)) { |
99
|
|
|
$button = "<a href='{$link}' title='{$alt}' {$extra}>" . newbbDisplayImage($button, $alt, true) . '</a>'; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return $button; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Display forrum images |
107
|
|
|
* |
108
|
|
|
* @param string $image image name, without extension |
109
|
|
|
* @param string $alt alt message |
110
|
|
|
* @param boolean $display true for return image anchor; faulse for assign to $xoopsTpl |
111
|
|
|
* @param string $extra extra attribute for the image |
112
|
|
|
* @return mixed |
113
|
|
|
*/ |
114
|
|
|
function newbbDisplayImage($image, $alt = '', $display = true, $extra = "class='forum_icon'") |
|
|
|
|
115
|
|
|
{ |
116
|
|
|
$iconHandler = newbbGetIconHandler(); |
117
|
|
|
// START hacked by irmtfan |
118
|
|
|
// to show text links instead of buttons - func_num_args()==2 => only when $image, $alt is set and optional $display not set |
119
|
|
|
|
120
|
|
|
if (func_num_args() == 2) { |
121
|
|
|
// overall setting |
122
|
|
|
if (!empty($GLOBALS['xoopsModuleConfig']['display_text_links'])) { |
123
|
|
|
$display = false; |
124
|
|
|
} |
125
|
|
|
// if set for each link => overwrite $display |
126
|
|
|
if (isset($GLOBALS['xoopsModuleConfig']['display_text_each_link'][$image])) { |
127
|
|
|
$display = empty($GLOBALS['xoopsModuleConfig']['display_text_each_link'][$image]); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
// END hacked by irmtfan |
131
|
|
|
if (empty($display)) { |
132
|
|
|
return $iconHandler->assignImage($image, $alt, $extra); |
133
|
|
|
} else { |
134
|
|
|
return $iconHandler->getImage($image, $alt, $extra); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @return NewbbIconHandler |
140
|
|
|
*/ |
141
|
|
|
function newbbGetIconHandler() |
|
|
|
|
142
|
|
|
{ |
143
|
|
|
global $xoTheme; |
|
|
|
|
144
|
|
|
static $iconHandler; |
145
|
|
|
|
146
|
|
|
if (isset($iconHandler)) { |
147
|
|
|
return $iconHandler; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
if (!class_exists('NewbbIconHandler')) { |
151
|
|
|
require_once dirname(__DIR__) . '/class/icon.php'; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
$iconHandler = NewbbIconHandler::getInstance(); |
155
|
|
|
$iconHandler->template = $xoTheme->template; |
156
|
|
|
$iconHandler->init($GLOBALS['xoopsConfig']['language']); |
157
|
|
|
|
158
|
|
|
return $iconHandler; |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|
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.