-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathIconHandler.php
More file actions
213 lines (191 loc) · 6.72 KB
/
IconHandler.php
File metadata and controls
213 lines (191 loc) · 6.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php declare(strict_types=1);
namespace XoopsModules\Newbb;
/**
* NewBB 5.0x, the forum module for XOOPS project
*
* @copyright XOOPS Project (https://xoops.org)
* @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
* @author Taiwen Jiang (phppp or D.J.) <phppp@users.sourceforge.net>
* @since 4.00
*/
/**
* Set forum image
*
* Priority for path per types:
* NEWBB_ROOT - IF EXISTS XOOPS_THEME/modules/newbb/images/, TAKE IT;
* ELSEIF EXISTS XOOPS_THEME_DEFAULT/modules/newbb/assets/images/, TAKE IT;
* ELSE TAKE XOOPS_ROOT/modules/newbb/templates/images/.
* types:
* button/misc - language specified;
* //indicator - language specified;
* icon - universal;
* mime - universal;
*/
/**
* Icon Renderer
*
* @author D.J. (phppp)
* @copyright copyright © Xoops Project
*/
class IconHandler
{
/**
* reference to XOOPS template
*/
public $template;
/**
* image set
*/
private $forumImage = [];
/**
* prefix
*/
private $prefix = '';
/**
* postfix, including extension
*/
private $postfix = '.png';
/**
* images to be assigned to template
*/
private $images = [];
/**
* Constructor
*/
public function __construct()
{
}
/**
* Access the only instance of this class
* @return IconHandler
*/
public static function getInstance()
{
static $instance;
if (null === $instance) {
$instance = new self();
}
return $instance;
}
/**
* TODO: get compatible with new theme engine
* @param $type
* @param string $dirname
* @param string $default
* @param string $endDir
* @return mixed
*/
// START irmtfan - improve to get other "end dirnames" like "css" and "js" - change images with $endDir
public function getPath($type, $dirname = 'newbb', $default = '', $endDir = 'images')
{
static $paths;
if (isset($paths[$endDir . '/' . $type])) {
return $paths[$endDir . '/' . $type];
}
$theme_path = $this->template->currentTheme->path;
$rel_dir = "modules/{$dirname}/{$endDir}";
// START irmtfan add default for all pathes
if (empty($default)) {
$path = \is_dir($theme_path . "/{$rel_dir}/{$type}/") ? $theme_path . "/{$rel_dir}/{$type}" : (\is_dir(\XOOPS_THEME_PATH . "/default/{$rel_dir}/{$type}/") ? \XOOPS_THEME_PATH . "/default/{$rel_dir}/{$type}" : $GLOBALS['xoops']->path("modules/{$dirname}/templates/{$endDir}/{$type}"));
} else {
$path = \is_dir($theme_path . "/{$rel_dir}/{$type}/") ? $theme_path . "/{$rel_dir}/{$type}" : (
\is_dir($theme_path . "/{$rel_dir}/{$default}/") ? $theme_path . "/{$rel_dir}/{$default}" : (
\is_dir(\XOOPS_THEME_PATH . "/default/{$rel_dir}/{$type}/") ? \XOOPS_THEME_PATH
. "/default/{$rel_dir}/{$type}" : (
\is_dir(
\XOOPS_THEME_PATH . "/default/{$rel_dir}/{$default}/"
) ? \XOOPS_THEME_PATH . "/default/{$rel_dir}/{$default}" : (\is_dir($GLOBALS['xoops']->path("modules/{$dirname}/templates/{$endDir}/{$type}/")) ? $GLOBALS['xoops']->path("modules/{$dirname}/templates/{$endDir}/{$type}") : $GLOBALS['xoops']->path(
"modules/{$dirname}/templates/{$endDir}/{$default}"
)) // XOOPS_ROOT_PATH
) // XOOPS_THEME_PATH {$default}
) // XOOPS_THEME_PATH
); // $theme_path {$default}
}
// END irmtfan add default for all pathes
$paths[$endDir . '/' . $type] = \str_replace(XOOPS_ROOT_PATH, '', \str_replace('\\', '/', $path));
return $paths[$endDir . '/' . $type];
}
// END irmtfan - improve to get other "end dirnames" like "css" and "js" - change images with $endDir
/**
* @param string $language
* @param string $dirname
*/
public function init(
/*$set = "default", */
$language = 'english',
$dirname = 'newbb'
): void {
$this->forumImage = require_once $GLOBALS['xoops']->path("modules/{$dirname}/include/images.php");
$this->forumImage['icon'] = XOOPS_URL . $this->getPath('icon', $dirname) . '/';
$this->forumImage['language'] = XOOPS_URL . $this->getPath("language/{$language}", $dirname, 'language/english') . '/';
}
/**
* @param $image
* @param string $alt
* @param string $extra
*/
public function setImage($image, $alt = '', $extra = ''): void
{
if (!isset($this->images[$image])) {
$imageSource = $this->getImageSource($image);
// irmtfan add id={$image}
$this->images[$image] = "<img src=\"{$imageSource}\" alt=\"{$alt}\" title=\"{$alt}\" align=\"middle\" {$extra} id={$image} >";
}
}
/**
* TODO: How about image not exist?
* @param $image
* @return string
*/
public function getImageSource($image)
{
return $this->forumImage[$this->forumImage[$image]] . $this->prefix . $image . $this->postfix;
}
/**
* @param $image
* @param string $alt
* @param string $extra
* @return mixed
*/
public function getImage($image, $alt = '', $extra = '')
{
$this->setImage($image, $alt, $extra);
return $this->images[$image];
}
/**
* @param $image
* @param string $alt
* @param string $extra
* @return string
*/
public function assignImage($image, $alt = '', $extra = '')
{
$this->setImage($image, $alt, $extra);
// START hacked by irmtfan - improve function to CSS3 buttons - add alt and title attributes - use span instead of button to support IE7&8
$tag = 'span';
if ("class='forum_icon'" === $extra && \in_array(mb_substr($image, 0, 2), ['t_', 'p_', 'up'], true)) {
$extra = "class='forum_icon forum_button'";
}
return "<{$tag} alt=\"{$alt}\" title=\"{$alt}\" align=\"middle\" {$extra} id={$image}>$alt</{$tag}>";
// END hacked by irmtfan - improve function to CSS3 buttons
}
/**
* @param $images
*/
public function assignImages($images): void
{
foreach ($images as $myImage) {
[$image, $alt, $extra] = $myImage;
$this->assignImage($image, $alt, $extra);
}
}
/**
* @return int
*/
public function render()
{
//$this->template->assignByRef("image", $this->images);
$this->template->assign($this->images);
return \count($this->images);
}
}