1
|
|
|
<?php |
2
|
|
|
// |
3
|
|
|
// ------------------------------------------------------------------------ // |
4
|
|
|
// XOOPS - PHP Content Management System // |
5
|
|
|
// Copyright (c) 2000-2016 XOOPS.org // |
6
|
|
|
// <http://xoops.org/> // |
7
|
|
|
// ------------------------------------------------------------------------ // |
8
|
|
|
// This program is free software; you can redistribute it and/or modify // |
9
|
|
|
// it under the terms of the GNU General Public License as published by // |
10
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
11
|
|
|
// (at your option) any later version. // |
12
|
|
|
|
13
|
|
|
// You may not change or alter any portion of this comment or credits // |
14
|
|
|
// of supporting developers from this source code or any supporting // |
15
|
|
|
// source code which is considered copyrighted (c) material of the // |
16
|
|
|
// original comment or credit authors. // |
17
|
|
|
// This program is distributed in the hope that it will be useful, // |
18
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
19
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
20
|
|
|
// GNU General Public License for more details. // |
21
|
|
|
|
22
|
|
|
// You should have received a copy of the GNU General Public License // |
23
|
|
|
// along with this program; if not, write to the Free Software // |
24
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
25
|
|
|
// ------------------------------------------------------------------------ // |
26
|
|
|
// URL: http://xoops.org/ // |
27
|
|
|
// Project: XOOPS Project // |
28
|
|
|
// -------------------------------------------------------------------------// |
29
|
|
|
|
30
|
|
|
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
|
|
|
|
31
|
|
|
|
32
|
|
|
include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Class SmartobjectCustomtag |
36
|
|
|
*/ |
37
|
|
|
class SmartobjectCustomtag extends SmartObject |
38
|
|
|
{ |
39
|
|
|
public $content = false; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* SmartobjectCustomtag constructor. |
43
|
|
|
*/ |
44
|
|
|
public function __construct() |
45
|
|
|
{ |
46
|
|
|
$this->quickInitVar('customtagid', XOBJ_DTYPE_INT, true); |
47
|
|
|
$this->quickInitVar('name', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CUSTOMTAG_NAME, _CO_SOBJECT_CUSTOMTAG_NAME_DSC); |
48
|
|
|
$this->quickInitVar('description', XOBJ_DTYPE_TXTAREA, false, _CO_SOBJECT_CUSTOMTAG_DESCRIPTION, _CO_SOBJECT_CUSTOMTAG_DESCRIPTION_DSC); |
49
|
|
|
$this->quickInitVar('content', XOBJ_DTYPE_TXTAREA, true, _CO_SOBJECT_CUSTOMTAG_CONTENT, _CO_SOBJECT_CUSTOMTAG_CONTENT_DSC); |
50
|
|
|
$this->quickInitVar('language', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CUSTOMTAG_LANGUAGE, _CO_SOBJECT_CUSTOMTAG_LANGUAGE_DSC); |
51
|
|
|
|
52
|
|
|
$this->initNonPersistableVar('dohtml', XOBJ_DTYPE_INT, 'class', 'dohtml', '', true); |
53
|
|
|
$this->initNonPersistableVar('doimage', XOBJ_DTYPE_INT, 'class', 'doimage', '', true); |
54
|
|
|
$this->initNonPersistableVar('doxcode', XOBJ_DTYPE_INT, 'class', 'doxcode', '', true); |
55
|
|
|
$this->initNonPersistableVar('dosmiley', XOBJ_DTYPE_INT, 'class', 'dosmiley', '', true); |
56
|
|
|
|
57
|
|
|
$this->setControl('content', array( |
58
|
|
|
'name' => 'textarea', |
59
|
|
|
'form_editor' => 'textarea', |
60
|
|
|
'form_rows' => 25 |
61
|
|
|
)); |
62
|
|
|
$this->setControl('language', array( |
63
|
|
|
'name' => 'language', |
64
|
|
|
'all' => true |
65
|
|
|
)); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string $key |
70
|
|
|
* @param string $format |
71
|
|
|
* @return mixed |
72
|
|
|
*/ |
73
|
|
|
public function getVar($key, $format = 's') |
74
|
|
|
{ |
75
|
|
|
if ($format === 's' && in_array($key, array())) { |
76
|
|
|
// return call_user_func(array($this, $key)); |
|
|
|
|
77
|
|
|
return $this->{$key}(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return parent::getVar($key, $format); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return bool|mixed |
85
|
|
|
*/ |
86
|
|
|
public function render() |
87
|
|
|
{ |
88
|
|
|
if (!$this->content) { |
89
|
|
|
$ret = $this->getVar('content'); |
90
|
|
|
$this->content = $ret; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return $this->content; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return bool|mixed|string |
98
|
|
|
*/ |
99
|
|
|
public function renderWithPhp() |
100
|
|
|
{ |
101
|
|
|
if (!$this->content) { |
102
|
|
|
$ret = $this->getVar('content'); |
103
|
|
|
$this->content = $ret; |
104
|
|
|
} else { |
105
|
|
|
$ret = $this->content; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
// check for PHP if we are not on admin side |
109
|
|
|
if (!defined('XOOPS_CPFUNC_LOADED') && !(strpos($ret, '[php]') === false)) { |
110
|
|
|
$ret = str_replace('[php]', '', $ret); |
111
|
|
|
// we have PHP code, let's evaluate |
112
|
|
|
eval($ret); |
|
|
|
|
113
|
|
|
|
114
|
|
|
return ''; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
return $this->content; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @return string |
122
|
|
|
*/ |
123
|
|
|
public function getXoopsCode() |
124
|
|
|
{ |
125
|
|
|
$ret = '[customtag]' . $this->getVar('tag', 'n') . '[/customtag]'; |
126
|
|
|
|
127
|
|
|
return $ret; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return string |
132
|
|
|
*/ |
133
|
|
|
public function getCloneLink() |
134
|
|
|
{ |
135
|
|
|
$ret = '<a href="' . |
136
|
|
|
SMARTOBJECT_URL . |
137
|
|
|
'admin/customtag.php?op=clone&customtagid=' . |
138
|
|
|
$this->id() . |
139
|
|
|
'"><img src="' . |
140
|
|
|
SMARTOBJECT_IMAGES_ACTIONS_URL . |
141
|
|
|
'editcopy.png" style="vertical-align: middle;" alt="' . |
142
|
|
|
_CO_SOBJECT_CUSTOMTAG_CLONE . |
143
|
|
|
'" title="' . |
144
|
|
|
_CO_SOBJECT_CUSTOMTAG_CLONE . |
145
|
|
|
'" /></a>'; |
146
|
|
|
|
147
|
|
|
return $ret; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param $var |
152
|
|
|
* @return bool |
153
|
|
|
*/ |
154
|
|
|
public function emptyString($var) |
155
|
|
|
{ |
156
|
|
|
return (strlen($var) > 0); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @return mixed|string |
161
|
|
|
*/ |
162
|
|
View Code Duplication |
public function generateTag() |
|
|
|
|
163
|
|
|
{ |
164
|
|
|
$title = rawurlencode(strtolower($this->getVar('description', 'e'))); |
165
|
|
|
$title = xoops_substr($title, 0, 10, ''); |
166
|
|
|
// Transformation des ponctuations |
167
|
|
|
$pattern = array( |
168
|
|
|
'/%09/', // Tab |
169
|
|
|
'/%20/', // Space |
170
|
|
|
'/%21/', // ! |
171
|
|
|
'/%22/', // " |
172
|
|
|
'/%23/', // # |
173
|
|
|
'/%25/', // % |
174
|
|
|
'/%26/', // & |
175
|
|
|
'/%27/', // ' |
176
|
|
|
'/%28/', // ( |
177
|
|
|
'/%29/', // ) |
178
|
|
|
'/%2C/', // , |
179
|
|
|
'/%2F/', // / |
180
|
|
|
'/%3A/', // : |
181
|
|
|
'/%3B/', // ; |
182
|
|
|
'/%3C/', // < |
183
|
|
|
'/%3D/', // = |
184
|
|
|
'/%3E/', // > |
185
|
|
|
'/%3F/', // ? |
186
|
|
|
'/%40/', // @ |
187
|
|
|
'/%5B/', // [ |
188
|
|
|
'/%5C/', // \ |
189
|
|
|
'/%5D/', // ] |
190
|
|
|
'/%5E/', // ^ |
191
|
|
|
'/%7B/', // { |
192
|
|
|
'/%7C/', // | |
193
|
|
|
'/%7D/', // } |
194
|
|
|
'/%7E/', // ~ |
195
|
|
|
"/\./" // . |
196
|
|
|
); |
197
|
|
|
$rep_pat = array('-', '-', '-', '-', '-', '-100', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-at-', '-', '-', '-', '-', '-', '-', '-', '-', '-'); |
198
|
|
|
$title = preg_replace($pattern, $rep_pat, $title); |
199
|
|
|
|
200
|
|
|
// Transformation des caract�res accentu�s |
201
|
|
|
$pattern = array( |
202
|
|
|
'/%B0/', // ° |
203
|
|
|
'/%E8/', // è |
204
|
|
|
'/%E9/', // é |
205
|
|
|
'/%EA/', // ê |
206
|
|
|
'/%EB/', // ë |
207
|
|
|
'/%E7/', // ç |
208
|
|
|
'/%E0/', // à |
209
|
|
|
'/%E2/', // â |
210
|
|
|
'/%E4/', // ä |
211
|
|
|
'/%EE/', // î |
212
|
|
|
'/%EF/', // ï |
213
|
|
|
'/%F9/', // ù |
214
|
|
|
'/%FC/', // ü |
215
|
|
|
'/%FB/', // û |
216
|
|
|
'/%F4/', // ô |
217
|
|
|
'/%F6/', // ö |
218
|
|
|
); |
219
|
|
|
$rep_pat = array('-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o'); |
220
|
|
|
$title = preg_replace($pattern, $rep_pat, $title); |
221
|
|
|
|
222
|
|
|
$tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
223
|
|
|
$tableau = array_filter($tableau, array($this, 'emptyString')); // Supprime les chaines vides du tableau |
224
|
|
|
$title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
225
|
|
|
|
226
|
|
|
$title .= time(); |
227
|
|
|
$title = md5($title); |
228
|
|
|
|
229
|
|
|
return $title; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @return mixed |
234
|
|
|
*/ |
235
|
|
|
public function getCustomtagName() |
236
|
|
|
{ |
237
|
|
|
$ret = $this->getVar('name'); |
238
|
|
|
|
239
|
|
|
return $ret; |
240
|
|
|
} |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* Class SmartobjectCustomtagHandler |
245
|
|
|
*/ |
246
|
|
|
class SmartobjectCustomtagHandler extends SmartPersistableObjectHandler |
247
|
|
|
{ |
248
|
|
|
public $objects = false; |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* SmartobjectCustomtagHandler constructor. |
252
|
|
|
* @param XoopsDatabase $db |
253
|
|
|
*/ |
254
|
|
|
public function __construct(XoopsDatabase $db) |
255
|
|
|
{ |
256
|
|
|
parent::__construct($db, 'customtag', 'customtagid', 'name', 'description', 'smartobject'); |
257
|
|
|
$this->addPermission('view', _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW, _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW_DSC); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* @return array|bool |
262
|
|
|
*/ |
263
|
|
|
public function getCustomtagsByName() |
264
|
|
|
{ |
265
|
|
|
if (!$this->objects) { |
266
|
|
|
global $xoopsConfig; |
267
|
|
|
|
268
|
|
|
$ret = array(); |
269
|
|
|
|
270
|
|
|
$criteria = new CriteriaCompo(); |
271
|
|
|
|
272
|
|
|
$criteria_language = new CriteriaCompo(); |
273
|
|
|
$criteria_language->add(new Criteria('language', $xoopsConfig['language'])); |
274
|
|
|
$criteria_language->add(new Criteria('language', 'all'), 'OR'); |
275
|
|
|
$criteria->add($criteria_language); |
276
|
|
|
|
277
|
|
|
$smartobjectPermissionsHandler = new SmartObjectPermissionHandler($this); |
278
|
|
|
$granted_ids = $smartobjectPermissionsHandler->getGrantedItems('view'); |
279
|
|
|
|
280
|
|
|
if ($granted_ids && count($granted_ids) > 0) { |
|
|
|
|
281
|
|
|
$criteria->add(new Criteria('customtagid', '(' . implode(', ', $granted_ids) . ')', 'IN')); |
282
|
|
|
$customtagsObj = $this->getObjects($criteria, true); |
283
|
|
|
foreach ($customtagsObj as $customtagObj) { |
284
|
|
|
$ret[$customtagObj->getVar('name')] = $customtagObj; |
285
|
|
|
} |
286
|
|
|
} |
287
|
|
|
$this->objects = $ret; |
|
|
|
|
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
return $this->objects; |
291
|
|
|
} |
292
|
|
|
} |
293
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.