1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
You may not change or alter any portion of this comment or credits |
4
|
|
|
of supporting developers from this source code or any supporting source code |
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
6
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
use Xmf\Module\Helper\Session; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @copyright XOOPS Project (http://xoops.org) |
16
|
|
|
* @license GNU GPL V2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
17
|
|
|
* @package Publisher |
18
|
|
|
* @since 1.0 |
19
|
|
|
* @author trabis <[email protected]> |
20
|
|
|
* @author The SmartFactory <www.smartfactory.ca> |
21
|
|
|
* @author trabis <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class PublisherUtils |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Includes scripts in HTML header |
27
|
|
|
* |
28
|
|
|
* @return void |
29
|
|
|
*/ |
30
|
|
|
public static function cpHeader() |
31
|
|
|
{ |
32
|
|
|
$xoops = Xoops::getInstance(); |
33
|
|
|
$publisher = Publisher::getInstance(); |
34
|
|
|
$xoops->header(); |
35
|
|
|
|
36
|
|
|
$css = array(); |
37
|
|
|
$css[] = $publisher->path('css/publisher.css'); |
38
|
|
|
$xoops->theme()->addBaseStylesheetAssets($css); |
39
|
|
|
|
40
|
|
|
$js = array(); |
41
|
|
|
$js[] = $publisher->path('js/funcs.js'); |
42
|
|
|
$js[] = $publisher->path('js/cookies.js'); |
43
|
|
|
$js[] = $publisher->path('js/ajaxupload.3.9.js'); |
44
|
|
|
$js[] = $publisher->path('js/publisher.js'); |
45
|
|
|
$xoops->theme()->addBaseScriptAssets($js); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Default sorting for a given order |
50
|
|
|
* |
51
|
|
|
* @param string $sort |
52
|
|
|
* |
53
|
|
|
* @return string |
54
|
|
|
*/ |
55
|
|
|
public static function getOrderBy($sort) |
56
|
|
|
{ |
57
|
|
|
if (in_array($sort, array("datesub", "counter"))) { |
58
|
|
|
return 'DESC'; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return 'ASC'; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @credits Thanks to Mithandir |
66
|
|
|
* |
67
|
|
|
* @param string $str |
68
|
|
|
* @param int $start |
69
|
|
|
* @param int $length |
70
|
|
|
* @param string $trimmarker |
71
|
|
|
* |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
|
|
public static function substr($str, $start, $length, $trimmarker = '...') |
75
|
|
|
{ |
76
|
|
|
// if the string is empty, let's get out ;-) |
77
|
|
|
if ($str == '') { |
78
|
|
|
return $str; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
// reverse a string that is shortened with '' as trimmarker |
82
|
|
|
$reversed_string = strrev(XoopsLocale::substr($str, $start, $length, '')); |
83
|
|
|
|
84
|
|
|
// find first space in reversed string |
85
|
|
|
$position_of_space = strpos($reversed_string, " ", 0); |
86
|
|
|
|
87
|
|
|
// truncate the original string to a length of $length |
88
|
|
|
// minus the position of the last space |
89
|
|
|
// plus the length of the $trimmarker |
90
|
|
|
$truncated_string = XoopsLocale::substr($str, $start, $length - $position_of_space + strlen($trimmarker), $trimmarker); |
91
|
|
|
|
92
|
|
|
return $truncated_string; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param string $document |
97
|
|
|
* |
98
|
|
|
* @return string |
99
|
|
|
*/ |
100
|
|
|
public static function html2text($document) |
101
|
|
|
{ |
102
|
|
|
// PHP Manual:: function preg_replace |
103
|
|
|
// $document should contain an HTML document. |
104
|
|
|
// This will remove HTML tags, javascript sections |
105
|
|
|
// and white space. It will also convert some |
106
|
|
|
// common HTML entities to their text equivalent. |
107
|
|
|
// Credits : newbb2 |
108
|
|
|
$search = array( |
109
|
|
|
"'<script[^>]*?>.*?</script>'si", // Strip out javascript |
110
|
|
|
"'<img.*?/>'si", // Strip out img tags |
111
|
|
|
"'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags |
112
|
|
|
"'([\r\n])[\s]+'", // Strip out white space |
113
|
|
|
"'&(quot|#34);'i", // Replace HTML entities |
114
|
|
|
"'&(amp|#38);'i", "'&(lt|#60);'i", "'&(gt|#62);'i", "'&(nbsp|#160);'i", "'&(iexcl|#161);'i", |
115
|
|
|
"'&(cent|#162);'i", "'&(pound|#163);'i", "'&(copy|#169);'i", "'&#(\d+);'e" |
116
|
|
|
); // evaluate as php |
117
|
|
|
|
118
|
|
|
$replace = array( |
119
|
|
|
"", "", "", "\\1", "\"", "&", "<", ">", " ", chr(161), chr(162), chr(163), chr(169), "chr(\\1)" |
120
|
|
|
); |
121
|
|
|
|
122
|
|
|
$text = preg_replace($search, $replace, $document); |
123
|
|
|
|
124
|
|
|
return $text; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @return string[] |
129
|
|
|
*/ |
130
|
|
|
public static function getAllowedImagesTypes() |
131
|
|
|
{ |
132
|
|
|
return array( |
133
|
|
|
'jpg/jpeg', 'image/bmp', 'image/gif', 'image/jpeg', 'image/jpg', 'image/x-png', 'image/png', 'image/pjpeg' |
134
|
|
|
); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @param bool $withLink |
139
|
|
|
* |
140
|
|
|
* @return string |
141
|
|
|
*/ |
142
|
|
|
public static function moduleHome($withLink = true) |
143
|
|
|
{ |
144
|
|
|
$xoops = Xoops::getInstance(); |
145
|
|
|
$publisher = Publisher::getInstance(); |
146
|
|
|
|
147
|
|
|
if (!$publisher->getConfig('format_breadcrumb_modname')) { |
148
|
|
|
return ''; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
if (!$withLink) { |
152
|
|
|
return $publisher->getModule()->getVar('name'); |
153
|
|
|
} else { |
154
|
|
|
return '<a href="' . $xoops->url(PUBLISHER_URL) . '/">' . $publisher->getModule()->getVar('name') . '</a>'; |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Copy a file, or a folder and its contents |
160
|
|
|
* |
161
|
|
|
* @author Aidan Lister <[email protected]> |
162
|
|
|
* @version 1.0.0 |
163
|
|
|
* |
164
|
|
|
* @param string $source The source |
165
|
|
|
* @param string $dest The destination |
166
|
|
|
* |
167
|
|
|
* @return bool Returns true on success, false on failure |
168
|
|
|
*/ |
169
|
|
|
public static function copyr($source, $dest) |
170
|
|
|
{ |
171
|
|
|
// Simple copy for a file |
172
|
|
|
if (is_file($source)) { |
173
|
|
|
return copy($source, $dest); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
// Make destination directory |
177
|
|
|
if (!is_dir($dest)) { |
178
|
|
|
mkdir($dest); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
// Loop through the folder |
182
|
|
|
$dir = dir($source); |
183
|
|
|
while (false !== $entry = $dir->read()) { |
184
|
|
|
// Skip pointers |
185
|
|
|
if ($entry === '.' || $entry === '..') { |
186
|
|
|
continue; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
// Deep copy directories |
190
|
|
|
if (is_dir("$source/$entry") && ($dest !== "$source/$entry")) { |
191
|
|
|
self::copyr("$source/$entry", "$dest/$entry"); |
192
|
|
|
} else { |
193
|
|
|
copy("$source/$entry", "$dest/$entry"); |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
// Clean up |
198
|
|
|
$dir->close(); |
199
|
|
|
|
200
|
|
|
return true; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* @credits Thanks to the NewBB2 Development Team |
205
|
|
|
* @param string $item |
206
|
|
|
* @param bool $getStatus |
207
|
|
|
* |
208
|
|
|
* @todo check undefined string |
209
|
|
|
* @return bool|int|string |
210
|
|
|
*/ |
211
|
|
|
public static function getPathStatus($item, $getStatus = false) |
212
|
|
|
{ |
213
|
|
|
$publisher = Publisher::getInstance(); |
214
|
|
|
if ($item === 'root') { |
215
|
|
|
$path = ''; |
216
|
|
|
} else { |
217
|
|
|
$path = $item; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
$thePath = self::getUploadDir(true, $path); |
|
|
|
|
221
|
|
|
|
222
|
|
|
if (empty($thePath)) { |
223
|
|
|
return false; |
224
|
|
|
} |
225
|
|
|
if (@is_writable($thePath)) { |
226
|
|
|
$pathCheckResult = 1; |
227
|
|
|
$path_status = _AM_PUBLISHER_AVAILABLE; |
228
|
|
|
} elseif (!@is_dir($thePath)) { |
229
|
|
|
$pathCheckResult = -1; |
230
|
|
|
$path_status = _AM_PUBLISHER_NOTAVAILABLE . " <a href='" . $publisher->url("admin/index.php?op=createdir&path={$item}") . "'>" . _AM_PUBLISHER_CREATETHEDIR . "</a>"; |
231
|
|
|
} else { |
232
|
|
|
$pathCheckResult = -2; |
233
|
|
|
$path_status = _AM_PUBLISHER_NOTWRITABLE . " <a href='" . $publisher->url("admin/index.php?op=setperm&path={$item}") . "'>" . _AM_SCS_SETMPERM . "</a>"; |
|
|
|
|
234
|
|
|
} |
235
|
|
|
if (!$getStatus) { |
236
|
|
|
return $path_status; |
237
|
|
|
} else { |
238
|
|
|
return $pathCheckResult; |
239
|
|
|
} |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @credits Thanks to the NewBB2 Development Team |
244
|
|
|
* |
245
|
|
|
* @param string $target |
246
|
|
|
* |
247
|
|
|
* @return bool |
248
|
|
|
*/ |
249
|
|
|
public static function mkdir($target) |
250
|
|
|
{ |
251
|
|
|
// http://www.php.net/manual/en/function.mkdir.php |
252
|
|
|
// saint at corenova.com |
253
|
|
|
// bart at cdasites dot com |
254
|
|
|
if (is_dir($target) || empty($target)) { |
255
|
|
|
return true; // best case check first |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
if (XoopsLoad::fileExists($target) && !is_dir($target)) { |
259
|
|
|
return false; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
if (self::mkdir(substr($target, 0, strrpos($target, '/')))) { |
263
|
|
|
if (!XoopsLoad::fileExists($target)) { |
264
|
|
|
$res = mkdir($target, 0777); // crawl back up & create dir tree |
265
|
|
|
self::chmod($target); |
266
|
|
|
|
267
|
|
|
return $res; |
268
|
|
|
} |
269
|
|
|
} |
270
|
|
|
$res = is_dir($target); |
271
|
|
|
|
272
|
|
|
return $res; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* @credits Thanks to the NewBB2 Development Team |
277
|
|
|
* |
278
|
|
|
* @param string $target |
279
|
|
|
* @param int $mode |
280
|
|
|
* |
281
|
|
|
* @return bool |
282
|
|
|
*/ |
283
|
|
|
public static function chmod($target, $mode = 0777) |
284
|
|
|
{ |
285
|
|
|
return @chmod($target, $mode); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* @param bool $hasPath |
290
|
|
|
* @param bool $item |
291
|
|
|
* |
292
|
|
|
* @return string |
293
|
|
|
*/ |
294
|
|
|
public static function getUploadDir($hasPath = true, $item = false) |
295
|
|
|
{ |
296
|
|
|
$xoops = Xoops::getInstance(); |
297
|
|
|
if ($item) { |
298
|
|
|
if ($item === 'root') { |
|
|
|
|
299
|
|
|
$item = ''; |
300
|
|
|
} else { |
301
|
|
|
$item = $item . '/'; |
|
|
|
|
302
|
|
|
} |
303
|
|
|
} else { |
304
|
|
|
$item = ''; |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
if ($hasPath) { |
308
|
|
|
return $xoops->path(PUBLISHER_UPLOADS_PATH . '/' . $item); |
309
|
|
|
} else { |
310
|
|
|
return $xoops->url(PUBLISHER_UPLOADS_URL . '/' . $item); |
311
|
|
|
} |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* @param string $item |
316
|
|
|
* @param bool $hasPath |
317
|
|
|
* |
318
|
|
|
* @return string |
319
|
|
|
*/ |
320
|
|
|
public static function getImageDir($item = '', $hasPath = true) |
321
|
|
|
{ |
322
|
|
|
if ($item) { |
323
|
|
|
$item = "images/{$item}"; |
324
|
|
|
} else { |
325
|
|
|
$item = "images"; |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
return self::getUploadDir($hasPath, $item); |
|
|
|
|
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* @param array $errors |
333
|
|
|
* |
334
|
|
|
* @return string |
335
|
|
|
*/ |
336
|
|
|
public static function formatErrors($errors = array()) |
337
|
|
|
{ |
338
|
|
|
$ret = ''; |
339
|
|
|
foreach ($errors as $value) { |
340
|
|
|
$ret .= '<br /> - ' . $value; |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
return $ret; |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* Check is current user is author of a given article |
348
|
|
|
* |
349
|
|
|
* @param object $itemObj |
350
|
|
|
* |
351
|
|
|
* @return bool |
352
|
|
|
*/ |
353
|
|
|
public static function IsUserAuthor($itemObj) |
354
|
|
|
{ |
355
|
|
|
$xoops = Xoops::getInstance(); |
356
|
|
|
|
357
|
|
|
return ($xoops->isUser() && is_object($itemObj) && ($xoops->user->getVar('uid') == $itemObj->getVar('uid'))); |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* Check is current user is moderator of a given article |
362
|
|
|
* |
363
|
|
|
* @param PublisherItem $itemObj |
364
|
|
|
* |
365
|
|
|
* @return bool |
366
|
|
|
*/ |
367
|
|
|
public static function IsUserModerator($itemObj) |
368
|
|
|
{ |
369
|
|
|
$publisher = Publisher::getInstance(); |
370
|
|
|
$categoriesGranted = $publisher->getPermissionHandler()->getGrantedItems('category_moderation'); |
371
|
|
|
|
372
|
|
|
return (is_object($itemObj) && in_array($itemObj->getVar('categoryid'), $categoriesGranted)); |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
public static function IsUserAdmin() |
376
|
|
|
{ |
377
|
|
|
return Publisher::getInstance()->isUserAdmin(); |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* Saves permissions for the selected category |
382
|
|
|
* |
383
|
|
|
* @param array $groups : group with granted permission |
384
|
|
|
* @param integer $categoryid : categoryid on which we are setting permissions |
385
|
|
|
* @param string $perm_name : name of the permission |
386
|
|
|
* |
387
|
|
|
* @todo Move to category class |
388
|
|
|
* @return boolean : TRUE if the no errors occured |
389
|
|
|
*/ |
390
|
|
|
public static function saveCategoryPermissions($groups, $categoryid, $perm_name) |
391
|
|
|
{ |
392
|
|
|
$xoops = Xoops::getInstance(); |
393
|
|
|
$publisher = Publisher::getInstance(); |
394
|
|
|
|
395
|
|
|
$result = true; |
396
|
|
|
|
397
|
|
|
$module_id = $publisher->getModule()->getVar('mid'); |
398
|
|
|
$gperm_handler = $xoops->getHandlerGroupPermission(); |
399
|
|
|
// First, if the permissions are already there, delete them |
400
|
|
|
$gperm_handler->deleteByModule($module_id, $perm_name, $categoryid); |
401
|
|
|
|
402
|
|
|
// Save the new permissions |
403
|
|
|
if (count($groups) > 0) { |
404
|
|
|
foreach ($groups as $group_id) { |
405
|
|
|
$gperm_handler->addRight($perm_name, $categoryid, $group_id, $module_id); |
406
|
|
|
} |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
return $result; |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
/** |
413
|
|
|
* @param string $tablename |
414
|
|
|
* @param string $iconname |
415
|
|
|
* @param string $tabletitle |
416
|
|
|
* @param string $tabledsc |
417
|
|
|
* @param bool $open |
418
|
|
|
* |
419
|
|
|
* @return void |
420
|
|
|
*/ |
421
|
|
|
public static function openCollapsableBar($tablename = '', $iconname = '', $tabletitle = '', $tabledsc = '', $open = true) |
422
|
|
|
{ |
423
|
|
|
$publisher = Publisher::getInstance(); |
424
|
|
|
$image = 'open12.gif'; |
425
|
|
|
$display = 'none'; |
426
|
|
|
if ($open) { |
427
|
|
|
$image = 'close12.gif'; |
428
|
|
|
$display = 'block'; |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
echo "<h3 style=\"color: #2F5376; font-weight: bold; font-size: 14px; margin: 6px 0 0 0; \"><a href='javascript:;' onclick=\"toggle('" . $tablename . "'); toggleIcon('" . $iconname . "')\";>"; |
432
|
|
|
echo "<img id='" . $iconname . "' src='" . $publisher->url("images/links/" . $image) . "' alt='' /></a> " . $tabletitle . "</h3>"; |
433
|
|
|
echo "<div id='" . $tablename . "' style='display: " . $display . ";'>"; |
434
|
|
|
if ($tabledsc != '') { |
435
|
|
|
echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . $tabledsc . "</span>"; |
436
|
|
|
} |
437
|
|
|
} |
438
|
|
|
|
439
|
|
|
/** |
440
|
|
|
* @param string $name |
441
|
|
|
* @param string $icon |
442
|
|
|
* |
443
|
|
|
* @return void |
444
|
|
|
*/ |
445
|
|
|
public static function closeCollapsableBar($name, $icon) |
446
|
|
|
{ |
447
|
|
|
echo "</div>"; |
448
|
|
|
|
449
|
|
|
$urls = self::getCurrentUrls(); |
450
|
|
|
$path = $urls['phpself']; |
451
|
|
|
|
452
|
|
|
$cookie_name = $path . '_publisher_collaps_' . $name; |
453
|
|
|
$cookie_name = str_replace('.', '_', $cookie_name); |
454
|
|
|
$cookie = self::getCookieVar($cookie_name, ''); |
455
|
|
|
|
456
|
|
|
if ($cookie === 'none') { |
457
|
|
|
echo ' |
458
|
|
|
<script type="text/javascript"><!-- |
459
|
|
|
toggle("' . $name . '"); toggleIcon("' . $icon . '"); |
460
|
|
|
//--> |
461
|
|
|
</script> |
462
|
|
|
'; |
463
|
|
|
} |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
/** |
467
|
|
|
* @param string $name |
468
|
|
|
* @param string $value |
469
|
|
|
* @param int $time |
470
|
|
|
* |
471
|
|
|
* @return void |
472
|
|
|
*/ |
473
|
|
|
public static function setCookieVar($name, $value, $time = 0) |
474
|
|
|
{ |
475
|
|
|
if ($time == 0) { |
476
|
|
|
$time = time() + 3600 * 24 * 365; |
477
|
|
|
} |
478
|
|
|
setcookie($name, $value, $time, '/'); |
479
|
|
|
} |
480
|
|
|
|
481
|
|
|
/** |
482
|
|
|
* @param string $name |
483
|
|
|
* @param string $default |
484
|
|
|
* |
485
|
|
|
* @return string |
486
|
|
|
*/ |
487
|
|
|
public static function getCookieVar($name, $default = '') |
488
|
|
|
{ |
489
|
|
|
if (isset($_COOKIE[$name]) && ($_COOKIE[$name] > '')) { |
490
|
|
|
return $_COOKIE[$name]; |
491
|
|
|
} else { |
492
|
|
|
return $default; |
493
|
|
|
} |
494
|
|
|
} |
495
|
|
|
|
496
|
|
|
/** |
497
|
|
|
* @return array |
498
|
|
|
*/ |
499
|
|
|
public static function getCurrentUrls() |
500
|
|
|
{ |
501
|
|
|
$http = strpos(\XoopsBaseConfig::get('url'), "https://") === false ? "http://" : "https://"; |
502
|
|
|
$phpself = $_SERVER['PHP_SELF']; |
503
|
|
|
$httphost = $_SERVER['HTTP_HOST']; |
504
|
|
|
$querystring = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : ''; |
505
|
|
|
|
506
|
|
|
if ($querystring != '') { |
507
|
|
|
$querystring = '?' . $querystring; |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
$currenturl = $http . $httphost . $phpself . $querystring; |
511
|
|
|
|
512
|
|
|
$urls = array(); |
513
|
|
|
$urls['http'] = $http; |
514
|
|
|
$urls['httphost'] = $httphost; |
515
|
|
|
$urls['phpself'] = $phpself; |
516
|
|
|
$urls['querystring'] = $querystring; |
517
|
|
|
$urls['full'] = $currenturl; |
518
|
|
|
|
519
|
|
|
return $urls; |
520
|
|
|
} |
521
|
|
|
|
522
|
|
|
/** |
523
|
|
|
* @return string |
524
|
|
|
*/ |
525
|
|
|
public static function getCurrentPage() |
526
|
|
|
{ |
527
|
|
|
$urls = self::getCurrentUrls(); |
528
|
|
|
|
529
|
|
|
return $urls['full']; |
530
|
|
|
} |
531
|
|
|
|
532
|
|
|
/** |
533
|
|
|
* @param object $categoryObj |
534
|
|
|
* @param int $selectedid |
535
|
|
|
* @param int $level |
536
|
|
|
* @param string $ret |
537
|
|
|
* |
538
|
|
|
* @todo move to ccategory class |
539
|
|
|
* @return string |
540
|
|
|
*/ |
541
|
|
|
public static function addCategoryOption($categoryObj, $selectedid = 0, $level = 0, $ret = '') |
542
|
|
|
{ |
543
|
|
|
$publisher = Publisher::getInstance(); |
544
|
|
|
|
545
|
|
|
$spaces = ''; |
546
|
|
|
for ($j = 0; $j < $level; ++$j) { |
547
|
|
|
$spaces .= '--'; |
548
|
|
|
} |
549
|
|
|
|
550
|
|
|
$ret .= "<option value='" . $categoryObj->getVar('categoryid') . "'"; |
551
|
|
|
if (is_array($selectedid) && in_array($categoryObj->getVar('categoryid'), $selectedid)) { |
|
|
|
|
552
|
|
|
$ret .= " selected='selected'"; |
553
|
|
|
} elseif ($categoryObj->getVar('categoryid') == $selectedid) { |
554
|
|
|
$ret .= " selected='selected'"; |
555
|
|
|
} |
556
|
|
|
$ret .= ">" . $spaces . $categoryObj->getVar('name') . "</option>\n"; |
557
|
|
|
|
558
|
|
|
$subCategoriesObj = $publisher->getCategoryHandler()->getCategories(0, 0, $categoryObj->getVar('categoryid')); |
559
|
|
|
if (count($subCategoriesObj) > 0) { |
560
|
|
|
++$level; |
561
|
|
|
foreach ($subCategoriesObj as $subCategoryObj) { |
562
|
|
|
$ret .= self::addCategoryOption($subCategoryObj, $selectedid, $level); |
563
|
|
|
} |
564
|
|
|
} |
565
|
|
|
|
566
|
|
|
return $ret; |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
/** |
570
|
|
|
* @param int $selectedid |
571
|
|
|
* @param int $parentcategory |
572
|
|
|
* @param bool $allCatOption |
573
|
|
|
* @param string $selectname |
574
|
|
|
* |
575
|
|
|
* @todo move to category class |
576
|
|
|
* @return string |
577
|
|
|
*/ |
578
|
|
|
public static function createCategorySelect($selectedid = 0, $parentcategory = 0, $allCatOption = true, $selectname = 'options[0]') |
579
|
|
|
{ |
580
|
|
|
$publisher = Publisher::getInstance(); |
581
|
|
|
|
582
|
|
|
$selectedid = explode(',', $selectedid); |
583
|
|
|
|
584
|
|
|
$ret = "<select name='" . $selectname . "[]' multiple='multiple' size='10'>"; |
585
|
|
|
if ($allCatOption) { |
586
|
|
|
$ret .= "<option value='0'"; |
587
|
|
|
if (in_array(0, $selectedid)) { |
588
|
|
|
$ret .= " selected='selected'"; |
589
|
|
|
} |
590
|
|
|
$ret .= ">" . _MB_PUBLISHER_ALLCAT . "</option>"; |
591
|
|
|
} |
592
|
|
|
|
593
|
|
|
// Creating category objects |
594
|
|
|
$categoriesObj = $publisher->getCategoryHandler()->getCategories(0, 0, $parentcategory); |
595
|
|
|
|
596
|
|
|
if (count($categoriesObj) > 0) { |
597
|
|
|
foreach ($categoriesObj as $catID => $categoryObj) { |
598
|
|
|
$ret .= self::addCategoryOption($categoryObj, $selectedid); |
|
|
|
|
599
|
|
|
} |
600
|
|
|
} |
601
|
|
|
$ret .= "</select>"; |
602
|
|
|
|
603
|
|
|
return $ret; |
604
|
|
|
} |
605
|
|
|
|
606
|
|
|
/** |
607
|
|
|
* @param int $selectedid |
608
|
|
|
* @param int $parentcategory |
609
|
|
|
* @param bool $allCatOption |
610
|
|
|
* |
611
|
|
|
* @todo move to category class |
612
|
|
|
* @return string |
613
|
|
|
*/ |
614
|
|
|
public static function createCategoryOptions($selectedid = 0, $parentcategory = 0, $allCatOption = true) |
615
|
|
|
{ |
616
|
|
|
$publisher = Publisher::getInstance(); |
617
|
|
|
|
618
|
|
|
$ret = ""; |
619
|
|
|
if ($allCatOption) { |
620
|
|
|
$ret .= "<option value='0'"; |
621
|
|
|
$ret .= ">" . _MB_PUBLISHER_ALLCAT . "</option>\n"; |
622
|
|
|
} |
623
|
|
|
|
624
|
|
|
// Creating category objects |
625
|
|
|
$categoriesObj = $publisher->getCategoryHandler()->getCategories(0, 0, $parentcategory); |
626
|
|
|
if (count($categoriesObj) > 0) { |
627
|
|
|
foreach ($categoriesObj as $categoryObj) { |
628
|
|
|
$ret .= self::addCategoryOption($categoryObj, $selectedid); |
629
|
|
|
} |
630
|
|
|
} |
631
|
|
|
|
632
|
|
|
return $ret; |
633
|
|
|
} |
634
|
|
|
|
635
|
|
|
/** |
636
|
|
|
* @param array $err_arr |
637
|
|
|
* @param string $reseturl |
638
|
|
|
* |
639
|
|
|
* @todo check this undefined strings |
640
|
|
|
* @return void |
641
|
|
|
*/ |
642
|
|
|
public static function renderErrors(&$err_arr, $reseturl = '') |
643
|
|
|
{ |
644
|
|
|
if (is_array($err_arr) && count($err_arr) > 0) { |
645
|
|
|
echo '<div id="readOnly" class="errorMsg" style="border:1px solid #D24D00; background:#FEFECC url(' . PUBLISHER_URL . '/images/important-32.png) no-repeat 7px 50%;color:#333;padding-left:45px;">'; |
646
|
|
|
|
647
|
|
|
echo '<h4 style="text-align:left;margin:0; padding-top:0">' . _AM_PUBLISHER_MSG_SUBMISSION_ERR; |
|
|
|
|
648
|
|
|
|
649
|
|
|
if ($reseturl) { |
650
|
|
|
echo ' <a href="' . $reseturl . '">[' . _AM_PUBLISHER_TEXT_SESSION_RESET . ']</a>'; |
|
|
|
|
651
|
|
|
} |
652
|
|
|
|
653
|
|
|
echo '</h4><ul>'; |
654
|
|
|
|
655
|
|
|
foreach ($err_arr as $key => $error) { |
656
|
|
|
if (is_array($error)) { |
657
|
|
|
foreach ($error as $err) { |
658
|
|
|
echo '<li><a href="#' . $key . '" onclick="var e = xoopsGetElementById(\'' . $key . '\'); e.focus();">' . htmlspecialchars($err) . '</a></li>'; |
659
|
|
|
} |
660
|
|
|
} else { |
661
|
|
|
echo '<li><a href="#' . $key . '" onclick="var e = xoopsGetElementById(\'' . $key . '\'); e.focus();">' . htmlspecialchars($error) . '</a></li>'; |
662
|
|
|
} |
663
|
|
|
} |
664
|
|
|
echo "</ul></div><br />"; |
665
|
|
|
} |
666
|
|
|
} |
667
|
|
|
|
668
|
|
|
/** |
669
|
|
|
* Generate publisher URL |
670
|
|
|
* |
671
|
|
|
* @param string $page |
672
|
|
|
* @param array $vars |
673
|
|
|
* @param bool $encodeAmp |
674
|
|
|
* |
675
|
|
|
* @return string |
676
|
|
|
* @credit : xHelp module, developped by 3Dev |
677
|
|
|
*/ |
678
|
|
|
public static function makeURI($page, $vars = array(), $encodeAmp = true) |
679
|
|
|
{ |
680
|
|
|
$joinStr = ''; |
681
|
|
|
|
682
|
|
|
$amp = ($encodeAmp ? '&' : '&'); |
683
|
|
|
|
684
|
|
|
if (!count($vars)) { |
685
|
|
|
return $page; |
686
|
|
|
} |
687
|
|
|
|
688
|
|
|
$qs = ''; |
689
|
|
|
foreach ($vars as $key => $value) { |
690
|
|
|
$qs .= $joinStr . $key . '=' . $value; |
691
|
|
|
$joinStr = $amp; |
692
|
|
|
} |
693
|
|
|
|
694
|
|
|
return $page . '?' . $qs; |
695
|
|
|
} |
696
|
|
|
|
697
|
|
|
/** |
698
|
|
|
* @param string $subject |
699
|
|
|
* |
700
|
|
|
* @return string |
701
|
|
|
*/ |
702
|
|
|
public static function tellafriend($subject = '') |
703
|
|
|
{ |
704
|
|
|
$xoops = Xoops::getInstance(); |
705
|
|
|
if (stristr($subject, '%')) { |
706
|
|
|
$subject = rawurldecode($subject); |
707
|
|
|
} |
708
|
|
|
$target_uri = $xoops->url($_SERVER['REQUEST_URI']); |
709
|
|
|
|
710
|
|
|
return $xoops->url('modules/tellafriend/index.php?target_uri=' . rawurlencode($target_uri) . '&subject=' . rawurlencode($subject)); |
711
|
|
|
} |
712
|
|
|
|
713
|
|
|
/** |
714
|
|
|
* @param bool $another |
715
|
|
|
* @param bool $withRedirect |
716
|
|
|
* @param $itemObj |
717
|
|
|
* |
718
|
|
|
* @return bool|string |
719
|
|
|
*/ |
720
|
|
|
public static function uploadFile($another = false, $withRedirect = true, &$itemObj) |
721
|
|
|
{ |
722
|
|
|
$xoops = Xoops::getInstance(); |
723
|
|
|
|
724
|
|
|
$publisher = Publisher::getInstance(); |
725
|
|
|
|
726
|
|
|
$itemid = isset($_POST['itemid']) ? (int)($_POST['itemid']) : 0; |
727
|
|
|
$uid = $xoops->isUser() ? $xoops->user->getVar('uid') : 0; |
728
|
|
|
$session = new Session(); |
729
|
|
|
$session->set('publisher_file_filename', isset($_POST['item_file_name']) ? $_POST['item_file_name'] : ''); |
730
|
|
|
$session->set('publisher_file_description', isset($_POST['item_file_description']) ? $_POST['item_file_description'] : ''); |
731
|
|
|
$session->set('publisher_file_status', isset($_POST['item_file_status']) ? (int)($_POST['item_file_status']) : 1); |
732
|
|
|
$session->set('publisher_file_uid', $uid); |
733
|
|
|
$session->set('publisher_file_itemid', $itemid); |
734
|
|
|
|
735
|
|
|
if (!is_object($itemObj)) { |
736
|
|
|
$itemObj = $publisher->getItemHandler()->get($itemid); |
737
|
|
|
} |
738
|
|
|
|
739
|
|
|
$fileObj = $publisher->getFileHandler()->create(); |
740
|
|
|
$fileObj->setVar('name', isset($_POST['item_file_name']) ? $_POST['item_file_name'] : ''); |
741
|
|
|
$fileObj->setVar('description', isset($_POST['item_file_description']) ? $_POST['item_file_description'] : ''); |
742
|
|
|
$fileObj->setVar('status', isset($_POST['item_file_status']) ? (int)($_POST['item_file_status']) : 1); |
743
|
|
|
$fileObj->setVar('uid', $uid); |
744
|
|
|
$fileObj->setVar('itemid', $itemObj->getVar('itemid')); |
745
|
|
|
$fileObj->setVar('datesub', time()); |
746
|
|
|
|
747
|
|
|
// Get available mimetypes for file uploading |
748
|
|
|
$allowed_mimetypes = $publisher->getMimetypeHandler()->getArrayByType(); |
|
|
|
|
749
|
|
|
// TODO : display the available mimetypes to the user |
750
|
|
|
$errors = array(); |
751
|
|
|
/* @var $fileObj PublisherFile */ |
752
|
|
|
if ($publisher->getConfig('perm_upload') && is_uploaded_file($_FILES['item_upload_file']['tmp_name'])) { |
753
|
|
|
if (!$ret = $fileObj->checkUpload('item_upload_file', $allowed_mimetypes, $errors)) { |
|
|
|
|
754
|
|
|
$errorstxt = implode('<br />', $errors); |
755
|
|
|
|
756
|
|
|
$message = sprintf(_CO_PUBLISHER_MESSAGE_FILE_ERROR, $errorstxt); |
757
|
|
|
if ($withRedirect) { |
758
|
|
|
$xoops->redirect("file.php?op=mod&itemid=" . $itemid, 5, $message); |
759
|
|
|
} else { |
760
|
|
|
return $message; |
761
|
|
|
} |
762
|
|
|
} |
763
|
|
|
} |
764
|
|
|
|
765
|
|
|
// Storing the file |
766
|
|
|
if (!$fileObj->store($allowed_mimetypes)) { |
767
|
|
|
if ($withRedirect) { |
768
|
|
|
$xoops->redirect("file.php?op=mod&itemid=" . $fileObj->getVar('itemid'), 3, _CO_PUBLISHER_FILEUPLOAD_ERROR . self::formatErrors($fileObj->getErrors())); |
769
|
|
|
} else { |
770
|
|
|
return _CO_PUBLISHER_FILEUPLOAD_ERROR . self::formatErrors($fileObj->getErrors()); |
771
|
|
|
} |
772
|
|
|
} |
773
|
|
|
|
774
|
|
|
if ($withRedirect) { |
775
|
|
|
$redirect_page = $another ? 'file.php' : 'item.php'; |
776
|
|
|
$xoops->redirect($redirect_page . "?op=mod&itemid=" . $fileObj->getVar('itemid'), 2, _CO_PUBLISHER_FILEUPLOAD_SUCCESS); |
777
|
|
|
} |
778
|
|
|
|
779
|
|
|
return true; |
780
|
|
|
} |
781
|
|
|
|
782
|
|
|
/** |
783
|
|
|
* @return string |
784
|
|
|
*/ |
785
|
|
|
public static function newFeatureTag() |
786
|
|
|
{ |
787
|
|
|
$ret = '<span style="padding-right: 4px; font-weight: bold; color: red;">' . _CO_PUBLISHER_NEW_FEATURE . '</span>'; |
788
|
|
|
|
789
|
|
|
return $ret; |
790
|
|
|
} |
791
|
|
|
|
792
|
|
|
/** |
793
|
|
|
* Smarty truncate_tagsafe modifier plugin |
794
|
|
|
* Type: modifier<br> |
795
|
|
|
* Name: truncate_tagsafe<br> |
796
|
|
|
* Purpose: Truncate a string to a certain length if necessary, |
797
|
|
|
* optionally splitting in the middle of a word, and |
798
|
|
|
* appending the $etc string or inserting $etc into the middle. |
799
|
|
|
* Makes sure no tags are left half-open or half-closed |
800
|
|
|
* (e.g. "Banana in a <a...") |
801
|
|
|
* |
802
|
|
|
* @author Monte Ohrt <monte at ohrt dot com>, modified by Amos Robinson |
803
|
|
|
* <amos dot robinson at gmail dot com> |
804
|
|
|
* |
805
|
|
|
* @param string |
806
|
|
|
* @param integer |
807
|
|
|
* @param string |
808
|
|
|
* @param boolean |
809
|
|
|
* @param boolean |
810
|
|
|
* |
811
|
|
|
* @return string |
812
|
|
|
*/ |
813
|
|
|
public static function truncateTagSafe($string, $length = 80, $etc = '...', $break_words = false) |
814
|
|
|
{ |
815
|
|
|
if ($length == 0) { |
816
|
|
|
return ''; |
817
|
|
|
} |
818
|
|
|
|
819
|
|
|
if (strlen($string) > $length) { |
820
|
|
|
$length -= strlen($etc); |
821
|
|
|
if (!$break_words) { |
822
|
|
|
$string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length + 1)); |
823
|
|
|
$string = preg_replace('/<[^>]*$/', '', $string); |
824
|
|
|
$string = self::closeTags($string); |
825
|
|
|
} |
826
|
|
|
|
827
|
|
|
return $string . $etc; |
828
|
|
|
} else { |
829
|
|
|
return $string; |
830
|
|
|
} |
831
|
|
|
} |
832
|
|
|
|
833
|
|
|
/** |
834
|
|
|
* @author Monte Ohrt <monte at ohrt dot com>, modified by Amos Robinson |
835
|
|
|
* <amos dot robinson at gmail dot com> |
836
|
|
|
* |
837
|
|
|
* @param string $string |
838
|
|
|
* |
839
|
|
|
* @return string |
840
|
|
|
*/ |
841
|
|
|
public static function closeTags($string) |
842
|
|
|
{ |
843
|
|
|
// match opened tags |
844
|
|
|
if (preg_match_all('/<([a-z\:\-]+)[^\/]>/', $string, $start_tags)) { |
845
|
|
|
$start_tags = $start_tags[1]; |
846
|
|
|
// match closed tags |
847
|
|
|
if (preg_match_all('/<\/([a-z]+)>/', $string, $end_tags)) { |
848
|
|
|
$complete_tags = array(); |
849
|
|
|
$end_tags = $end_tags[1]; |
850
|
|
|
|
851
|
|
|
foreach ($start_tags as $val) { |
852
|
|
|
$posb = array_search($val, $end_tags); |
853
|
|
|
if (is_integer($posb)) { |
854
|
|
|
unset($end_tags[$posb]); |
855
|
|
|
} else { |
856
|
|
|
$complete_tags[] = $val; |
857
|
|
|
} |
858
|
|
|
} |
859
|
|
|
} else { |
860
|
|
|
$complete_tags = $start_tags; |
861
|
|
|
} |
862
|
|
|
|
863
|
|
|
$complete_tags = array_reverse($complete_tags); |
864
|
|
|
for ($i = 0; $i < count($complete_tags); ++$i) { |
|
|
|
|
865
|
|
|
$string .= '</' . $complete_tags[$i] . '>'; |
866
|
|
|
} |
867
|
|
|
} |
868
|
|
|
|
869
|
|
|
return $string; |
870
|
|
|
} |
871
|
|
|
|
872
|
|
|
/** |
873
|
|
|
* @param int $itemid |
874
|
|
|
* |
875
|
|
|
* @return string |
876
|
|
|
*/ |
877
|
|
|
public static function ratingBar($itemid) |
878
|
|
|
{ |
879
|
|
|
$xoops = Xoops::getInstance(); |
880
|
|
|
$publisher = Publisher::getInstance(); |
881
|
|
|
$rating_unitwidth = 30; |
882
|
|
|
$units = 5; |
883
|
|
|
|
884
|
|
|
$criteria = new Criteria('itemid', $itemid); |
885
|
|
|
$ratingObjs = $publisher->getRatingHandler()->getObjects($criteria); |
886
|
|
|
unset($criteria); |
887
|
|
|
|
888
|
|
|
$uid = $xoops->isUser() ? $xoops->user->getVar('uid') : 0; |
889
|
|
|
$count = count($ratingObjs); |
890
|
|
|
$current_rating = 0; |
891
|
|
|
$voted = false; |
892
|
|
|
$ip = getenv('REMOTE_ADDR'); |
893
|
|
|
|
894
|
|
|
/* @var $ratingObj PublisherRating */ |
895
|
|
|
foreach ($ratingObjs as $ratingObj) { |
896
|
|
|
$current_rating += $ratingObj->getVar('rate'); |
897
|
|
|
if ($ratingObj->getVar('ip') == $ip || ($uid > 0 && $uid == $ratingObj->getVar('uid'))) { |
898
|
|
|
$voted = true; |
899
|
|
|
} |
900
|
|
|
} |
901
|
|
|
|
902
|
|
|
$tense = $count == 1 ? _MD_PUBLISHER_VOTE_lVOTE : _MD_PUBLISHER_VOTE_lVOTES; //plural form votes/vote |
903
|
|
|
|
904
|
|
|
// now draw the rating bar |
905
|
|
|
$rating_width = @number_format($current_rating / $count, 2) * $rating_unitwidth; |
906
|
|
|
$rating1 = @number_format($current_rating / $count, 1); |
907
|
|
|
$rating2 = @number_format($current_rating / $count, 2); |
908
|
|
|
|
909
|
|
|
$groups = $xoops->getUserGroups(); |
910
|
|
|
$gperm_handler = $publisher->getGrouppermHandler(); |
911
|
|
|
|
912
|
|
|
if (!$gperm_handler->checkRight('global', _PUBLISHER_RATE, $groups, $publisher->getModule()->getVar('mid'))) { |
913
|
|
|
$static_rater = array(); |
914
|
|
|
$static_rater[] .= "\n" . '<div class="publisher_ratingblock">'; |
915
|
|
|
$static_rater[] .= '<div id="unit_long' . $itemid . '">'; |
916
|
|
|
$static_rater[] .= '<div id="unit_ul' . $itemid . '" class="publisher_unit-rating" style="width:' . $rating_unitwidth * $units . 'px;">'; |
917
|
|
|
$static_rater[] .= '<div class="publisher_current-rating" style="width:' . $rating_width . 'px;">' . _MD_PUBLISHER_VOTE_RATING . ' ' . $rating2 . '/' . $units . '</div>'; |
918
|
|
|
$static_rater[] .= '</div>'; |
919
|
|
|
$static_rater[] .= '<div class="publisher_static">' . _MD_PUBLISHER_VOTE_RATING . ': <strong> ' . $rating1 . '</strong>/' . $units . ' (' . $count . ' ' . $tense . ') <br /><em>' . _MD_PUBLISHER_VOTE_DISABLE . '</em></div>'; |
920
|
|
|
$static_rater[] .= '</div>'; |
921
|
|
|
$static_rater[] .= '</div>' . "\n\n"; |
922
|
|
|
|
923
|
|
|
return join("\n", $static_rater); |
924
|
|
|
} else { |
925
|
|
|
$rater = ''; |
926
|
|
|
$rater .= '<div class="publisher_ratingblock">'; |
927
|
|
|
$rater .= '<div id="unit_long' . $itemid . '">'; |
928
|
|
|
$rater .= '<div id="unit_ul' . $itemid . '" class="publisher_unit-rating" style="width:' . $rating_unitwidth * $units . 'px;">'; |
929
|
|
|
$rater .= '<div class="publisher_current-rating" style="width:' . $rating_width . 'px;">' . _MD_PUBLISHER_VOTE_RATING . ' ' . $rating2 . '/' . $units . '</div>'; |
930
|
|
|
|
931
|
|
|
for ($ncount = 1; $ncount <= $units; ++$ncount) { // loop from 1 to the number of units |
932
|
|
|
if (!$voted) { // if the user hasn't yet voted, draw the voting stars |
933
|
|
|
$rater .= '<div><a href="' . PUBLISHER_URL . '/rate.php?itemid=' . $itemid . '&rating=' . $ncount . '" title="' . $ncount . ' ' . _MD_PUBLISHER_VOTE_OUTOF . ' ' . $units . '" class="publisher_r' . $ncount . '-unit rater" rel="nofollow">' . $ncount . '</a></div>'; |
934
|
|
|
} |
935
|
|
|
} |
936
|
|
|
|
937
|
|
|
$rater .= ' </div>'; |
938
|
|
|
$rater .= ' <div'; |
939
|
|
|
|
940
|
|
|
if ($voted) { |
941
|
|
|
$rater .= ' class="publisher_voted"'; |
942
|
|
|
} |
943
|
|
|
|
944
|
|
|
$rater .= '>' . _MD_PUBLISHER_VOTE_RATING . ': <strong> ' . $rating1 . '</strong>/' . $units . ' (' . $count . ' ' . $tense . ')'; |
945
|
|
|
$rater .= ' </div>'; |
946
|
|
|
$rater .= '</div>'; |
947
|
|
|
$rater .= '</div>'; |
948
|
|
|
|
949
|
|
|
return $rater; |
950
|
|
|
} |
951
|
|
|
} |
952
|
|
|
|
953
|
|
|
/** |
954
|
|
|
* @param array $allowed_editors |
955
|
|
|
* |
956
|
|
|
* @return array |
957
|
|
|
*/ |
958
|
|
|
public static function getEditors($allowed_editors = null) |
959
|
|
|
{ |
960
|
|
|
$ret = array(); |
961
|
|
|
$nohtml = false; |
962
|
|
|
$editor_handler = XoopsEditorHandler::getInstance(); |
963
|
|
|
$editors = $editor_handler->getList($nohtml); |
964
|
|
|
foreach ($editors as $name => $title) { |
965
|
|
|
$key = self::stringToInt($name); |
966
|
|
|
if (is_array($allowed_editors)) { |
967
|
|
|
//for submit page |
968
|
|
|
if (in_array($key, $allowed_editors)) { |
969
|
|
|
$ret[] = $name; |
970
|
|
|
} |
971
|
|
|
} else { |
972
|
|
|
//for admin permissions page |
973
|
|
|
$ret[$key]['name'] = $name; |
974
|
|
|
$ret[$key]['title'] = $title; |
975
|
|
|
} |
976
|
|
|
} |
977
|
|
|
|
978
|
|
|
return $ret; |
979
|
|
|
} |
980
|
|
|
|
981
|
|
|
/** |
982
|
|
|
* @param string $string |
983
|
|
|
* @param int $length |
984
|
|
|
* |
985
|
|
|
* @return int |
986
|
|
|
*/ |
987
|
|
|
public static function stringToInt($string = '', $length = 5) |
988
|
|
|
{ |
989
|
|
|
for ($i = 0, $final = "", $string = substr(md5($string), $length); $i < $length; $final .= (int)($string[$i]), ++$i) { |
|
|
|
|
990
|
|
|
} |
991
|
|
|
|
992
|
|
|
return (int)($final); |
993
|
|
|
} |
994
|
|
|
|
995
|
|
|
/** |
996
|
|
|
* @param string $item |
997
|
|
|
* |
998
|
|
|
* @return string |
999
|
|
|
*/ |
1000
|
|
|
public static function convertCharset($item) |
1001
|
|
|
{ |
1002
|
|
|
if (XoopsLocale::getCharset() === 'UTF-8') { |
1003
|
|
|
return $item; |
1004
|
|
|
} |
1005
|
|
|
|
1006
|
|
|
if (XoopsLocale::getCharset() !== 'windows-1256') { |
1007
|
|
|
return utf8_encode($item); |
1008
|
|
|
} |
1009
|
|
|
|
1010
|
|
|
if ($unserialize = unserialize($item)) { |
1011
|
|
|
foreach ($unserialize as $key => $value) { |
1012
|
|
|
$unserialize[$key] = @iconv('windows-1256', 'UTF-8', $value); |
1013
|
|
|
} |
1014
|
|
|
$serialize = serialize($unserialize); |
1015
|
|
|
|
1016
|
|
|
return $serialize; |
1017
|
|
|
} else { |
1018
|
|
|
return @iconv('windows-1256', 'UTF-8', $item); |
1019
|
|
|
} |
1020
|
|
|
} |
1021
|
|
|
|
1022
|
|
|
public static function seoTitle($title = '', $withExt = true) |
1023
|
|
|
{ |
1024
|
|
|
|
1025
|
|
|
/** |
1026
|
|
|
* if XOOPS ML is present, let's sanitize the title with the current language |
1027
|
|
|
*/ |
1028
|
|
|
$myts = \Xoops\Core\Text\Sanitizer::getInstance(); |
1029
|
|
|
if (method_exists($myts, 'formatForML')) { |
1030
|
|
|
$title = $myts->formatForML($title); |
1031
|
|
|
} |
1032
|
|
|
|
1033
|
|
|
// Transformation de la chaine en minuscule |
1034
|
|
|
// Codage de la chaine afin d'éviter les erreurs 500 en cas de caractères imprévus |
1035
|
|
|
$title = rawurlencode(strtolower($title)); |
1036
|
|
|
|
1037
|
|
|
// Transformation des ponctuations |
1038
|
|
|
// Tab Space ! " # % & ' ( ) , / : ; < = > ? @ [ \ ] ^ { | } ~ . |
1039
|
|
|
$pattern = array( |
1040
|
|
|
"/%09/", "/%20/", "/%21/", "/%22/", "/%23/", "/%25/", "/%26/", "/%27/", "/%28/", "/%29/", "/%2C/", "/%2F/", |
1041
|
|
|
"/%3A/", "/%3B/", "/%3C/", "/%3D/", "/%3E/", "/%3F/", "/%40/", "/%5B/", "/%5C/", "/%5D/", "/%5E/", "/%7B/", |
1042
|
|
|
"/%7C/", "/%7D/", "/%7E/", "/\./" |
1043
|
|
|
); |
1044
|
|
|
$rep_pat = array( |
1045
|
|
|
"-", "-", "", "", "", "-100", "", "-", "", "", "", "-", "", "", "", "-", "", "", "-at-", "", "-", "", "-", |
1046
|
|
|
"", "-", "", "-", "" |
1047
|
|
|
); |
1048
|
|
|
$title = preg_replace($pattern, $rep_pat, $title); |
1049
|
|
|
|
1050
|
|
|
// Transformation des caractères accentués |
1051
|
|
|
// è é ê ë ç à â ä î ï ù ü û ô ö |
1052
|
|
|
$pattern = array( |
1053
|
|
|
"/%B0/", "/%E8/", "/%E9/", "/%EA/", "/%EB/", "/%E7/", "/%E0/", "/%E2/", "/%E4/", "/%EE/", "/%EF/", "/%F9/", |
1054
|
|
|
"/%FC/", "/%FB/", "/%F4/", "/%F6/" |
1055
|
|
|
); |
1056
|
|
|
$rep_pat = array("-", "e", "e", "e", "e", "c", "a", "a", "a", "i", "i", "u", "u", "u", "o", "o"); |
1057
|
|
|
$title = preg_replace($pattern, $rep_pat, $title); |
1058
|
|
|
|
1059
|
|
|
if (sizeof($title) > 0) { |
1060
|
|
|
if ($withExt) { |
1061
|
|
|
$title .= '.html'; |
1062
|
|
|
} |
1063
|
|
|
|
1064
|
|
|
return $title; |
1065
|
|
|
} |
1066
|
|
|
|
1067
|
|
|
return ''; |
1068
|
|
|
} |
1069
|
|
|
|
1070
|
|
|
/** |
1071
|
|
|
* seoGenUrl |
1072
|
|
|
* |
1073
|
|
|
* @param string $op |
1074
|
|
|
* @param integer $id |
1075
|
|
|
* @param string $short_url |
1076
|
|
|
* |
1077
|
|
|
* @return string |
1078
|
|
|
*/ |
1079
|
|
|
public static function seoGenUrl($op, $id, $short_url = "") |
1080
|
|
|
{ |
1081
|
|
|
$publisher = Publisher::getInstance(); |
1082
|
|
|
if ($publisher->getConfig('seo_url_rewrite') !== 'none') { |
1083
|
|
|
if (!empty($short_url)) { |
1084
|
|
|
$short_url = $short_url . '.html'; |
1085
|
|
|
} |
1086
|
|
|
|
1087
|
|
|
if ($publisher->getConfig('seo_url_rewrite') === 'htaccess') { |
1088
|
|
|
// generate SEO url using htaccess |
1089
|
|
|
return \XoopsBaseConfig::get('url') . '/' . $publisher->getConfig('seo_module_name') . ".${op}.${id}/${short_url}"; |
1090
|
|
|
} else { |
1091
|
|
|
if ($publisher->getConfig('seo_url_rewrite') === 'path-info') { |
1092
|
|
|
// generate SEO url using path-info |
1093
|
|
|
return $publisher->url("index.php/${op}.${id}/${short_url}"); |
1094
|
|
|
} else { |
1095
|
|
|
die('Unknown SEO method.'); |
|
|
|
|
1096
|
|
|
} |
1097
|
|
|
} |
1098
|
|
|
} else { |
1099
|
|
|
// generate classic url |
1100
|
|
|
switch ($op) { |
1101
|
|
|
case 'category': |
1102
|
|
|
return $publisher->url("${op}.php?categoryid=${id}"); |
1103
|
|
|
case 'item': |
1104
|
|
|
case 'print': |
1105
|
|
|
return $publisher->url("${op}.php?itemid=${id}"); |
1106
|
|
|
default: |
1107
|
|
|
die('Unknown SEO operation.'); |
|
|
|
|
1108
|
|
|
} |
1109
|
|
|
} |
1110
|
|
|
} |
1111
|
|
|
|
1112
|
|
|
/** |
1113
|
|
|
* @param string $url |
1114
|
|
|
* @param int $width |
1115
|
|
|
* @param int $height |
1116
|
|
|
* |
1117
|
|
|
* @return string |
1118
|
|
|
*/ |
1119
|
|
|
public static function displayFlash($url, $width = 0, $height = 0) |
1120
|
|
|
{ |
1121
|
|
|
if (!$width || !$height) { |
1122
|
|
|
if (!$dimension = @getimagesize($url)) { |
1123
|
|
|
return "<a href='{$url}' target='_blank'>{$url}</a>"; |
1124
|
|
|
} |
1125
|
|
|
if (!$width) { |
1126
|
|
|
$height = $dimension[1] * $width / $dimension[0]; |
1127
|
|
|
} elseif (!empty($height)) { |
1128
|
|
|
$width = $dimension[0] * $height / $dimension[1]; |
1129
|
|
|
} else { |
1130
|
|
|
list($width, $height) = array($dimension[0], $dimension[1]); |
1131
|
|
|
} |
1132
|
|
|
} |
1133
|
|
|
|
1134
|
|
|
$rp = "<object width='{$width}' height='{$height}' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0'>"; |
1135
|
|
|
$rp .= "<param name='movie' value='{$url}'>"; |
1136
|
|
|
$rp .= "<param name='QUALITY' value='high'>"; |
1137
|
|
|
$rp .= "<PARAM NAME='bgcolor' VALUE='#FFFFFF'>"; |
1138
|
|
|
$rp .= "<param name='wmode' value='transparent'>"; |
1139
|
|
|
$rp .= "<embed src='{$url}' width='{$width}' height='{$height}' quality='high' bgcolor='#FFFFFF' wmode='transparent' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash'></embed>"; |
1140
|
|
|
$rp .= "</object>"; |
1141
|
|
|
|
1142
|
|
|
return $rp; |
1143
|
|
|
} |
1144
|
|
|
} |
1145
|
|
|
|