1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Publisher; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
You may not change or alter any portion of this comment or credits |
7
|
|
|
of supporting developers from this source code or any supporting source code |
8
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
9
|
|
|
|
10
|
|
|
This program is distributed in the hope that it will be useful, |
11
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
17
|
|
|
* @license https://www.fsf.org/copyleft/gpl.html GNU public license |
18
|
|
|
* @since 1.0 |
19
|
|
|
* @author trabis <[email protected]> |
20
|
|
|
* @author The SmartFactory <www.smartfactory.ca> |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
use Xmf\Request; |
24
|
|
|
|
25
|
|
|
/** @var \XoopsMemberHandler $memberHandler */ |
26
|
|
|
/** @var \XoopsImageHandler $imageHandler */ |
27
|
|
|
require_once \dirname(__DIR__) . '/include/common.php'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Class Item |
31
|
|
|
*/ |
32
|
|
|
class Item extends \XoopsObject |
33
|
|
|
{ |
34
|
|
|
public const PAGEWRAP = '[pagewrap='; |
35
|
|
|
public const BODYTAG = '<body>'; |
36
|
|
|
/** |
37
|
|
|
* @var Helper |
38
|
|
|
*/ |
39
|
|
|
public $helper; |
40
|
|
|
/** @var \XoopsMySQLDatabase */ |
41
|
|
|
public $db; |
42
|
|
|
public $groupsRead = []; |
43
|
|
|
/** |
44
|
|
|
* @var Category |
45
|
|
|
*/ |
46
|
|
|
public $category; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param int|null $id |
50
|
|
|
*/ |
51
|
|
|
public function __construct($id = null) |
52
|
|
|
{ |
53
|
|
|
// $this->helper = Helper::getInstance(); |
54
|
|
|
$this->db = \XoopsDatabaseFactory::getDatabaseConnection(); |
55
|
|
|
$this->initVar('itemid', \XOBJ_DTYPE_INT, 0); |
56
|
|
|
$this->initVar('categoryid', \XOBJ_DTYPE_INT, 0, false); |
57
|
|
|
$this->initVar('title', \XOBJ_DTYPE_TXTBOX, '', true, 255); |
58
|
|
|
$this->initVar('subtitle', \XOBJ_DTYPE_TXTBOX, '', false, 255); |
59
|
|
|
$this->initVar('summary', \XOBJ_DTYPE_TXTAREA, '', false); |
60
|
|
|
$this->initVar('body', \XOBJ_DTYPE_TXTAREA, '', false); |
61
|
|
|
$this->initVar('uid', \XOBJ_DTYPE_INT, 0, false); |
62
|
|
|
$this->initVar('author_alias', \XOBJ_DTYPE_TXTBOX, '', false, 255); |
63
|
|
|
$this->initVar('datesub', \XOBJ_DTYPE_INT, '', false); |
64
|
|
|
$this->initVar('dateexpire', \XOBJ_DTYPE_INT, '', false); |
65
|
|
|
$this->initVar('status', \XOBJ_DTYPE_INT, -1, false); |
66
|
|
|
$this->initVar('image', \XOBJ_DTYPE_INT, 0, false); |
67
|
|
|
$this->initVar('images', \XOBJ_DTYPE_TXTBOX, '', false, 255); |
68
|
|
|
$this->initVar('counter', \XOBJ_DTYPE_INT, 0, false); |
69
|
|
|
$this->initVar('rating', \XOBJ_DTYPE_OTHER, 0, false); |
70
|
|
|
$this->initVar('votes', \XOBJ_DTYPE_INT, 0, false); |
71
|
|
|
$this->initVar('weight', \XOBJ_DTYPE_INT, 0, false); |
72
|
|
|
$this->initVar('dohtml', \XOBJ_DTYPE_INT, 1, true); |
73
|
|
|
$this->initVar('dosmiley', \XOBJ_DTYPE_INT, 1, true); |
74
|
|
|
$this->initVar('doimage', \XOBJ_DTYPE_INT, 1, true); |
75
|
|
|
$this->initVar('dobr', \XOBJ_DTYPE_INT, 1, false); |
76
|
|
|
$this->initVar('doxcode', \XOBJ_DTYPE_INT, 1, true); |
77
|
|
|
$this->initVar('cancomment', \XOBJ_DTYPE_INT, 1, true); |
78
|
|
|
$this->initVar('comments', \XOBJ_DTYPE_INT, 0, false); |
79
|
|
|
$this->initVar('notifypub', \XOBJ_DTYPE_INT, 1, false); |
80
|
|
|
$this->initVar('meta_keywords', \XOBJ_DTYPE_TXTAREA, '', false); |
81
|
|
|
$this->initVar('meta_description', \XOBJ_DTYPE_TXTAREA, '', false); |
82
|
|
|
$this->initVar('short_url', \XOBJ_DTYPE_TXTBOX, '', false, 255); |
83
|
|
|
$this->initVar('item_tag', \XOBJ_DTYPE_TXTAREA, '', false); |
84
|
|
|
$this->initVar('votetype', \XOBJ_DTYPE_INT, 0, false); |
85
|
|
|
// Non consistent values |
86
|
|
|
$this->initVar('pagescount', \XOBJ_DTYPE_INT, 0, false); |
87
|
|
|
if (null !== $id) { |
88
|
|
|
$item = $this->helper->getHandler('Item') |
89
|
|
|
->get($id); |
90
|
|
|
foreach ($item->vars as $k => $v) { |
91
|
|
|
$this->assignVar($k, $v['value']); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param string $method |
98
|
|
|
* @param array $args |
99
|
|
|
* |
100
|
|
|
* @return mixed |
101
|
|
|
*/ |
102
|
|
|
public function __call(string $method, array $args) |
103
|
|
|
{ |
104
|
|
|
$arg = $args[0] ?? ''; //mb changed to empty string as in PHP 8.1 Passing null to parameter of type string is deprecated (in object.php on line 441) |
105
|
|
|
|
106
|
|
|
return $this->getVar($method, $arg); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return null|Category |
111
|
|
|
*/ |
112
|
|
|
public function getCategory() |
113
|
|
|
{ |
114
|
|
|
if (null === $this->category) { |
115
|
|
|
$this->category = $this->helper->getHandler('Category') |
116
|
|
|
->get($this->getVar('categoryid')); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
return $this->category; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param int $maxLength |
124
|
|
|
* @param string $format |
125
|
|
|
* |
126
|
|
|
* @return mixed|string |
127
|
|
|
*/ |
128
|
|
|
public function getTitle($maxLength = 0, $format = 'S') |
129
|
|
|
{ |
130
|
|
|
$ret = $this->getVar('title', $format); |
131
|
|
|
if (0 != $maxLength) { |
132
|
|
|
if (!XOOPS_USE_MULTIBYTES) { |
133
|
|
|
if (\mb_strlen($ret) >= $maxLength) { |
134
|
|
|
$ret = Utility::substr($ret, 0, $maxLength); |
|
|
|
|
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
return $ret; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @param int $maxLength |
144
|
|
|
* @param string $format |
145
|
|
|
* |
146
|
|
|
* @return mixed|string |
147
|
|
|
*/ |
148
|
|
|
public function getSubtitle($maxLength = 0, $format = 'S') |
149
|
|
|
{ |
150
|
|
|
$ret = $this->getVar('subtitle', $format); |
151
|
|
|
if (0 != $maxLength) { |
152
|
|
|
if (!XOOPS_USE_MULTIBYTES) { |
153
|
|
|
if (\mb_strlen($ret) >= $maxLength) { |
154
|
|
|
$ret = Utility::substr($ret, 0, $maxLength); |
|
|
|
|
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
return $ret; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @param int $maxLength |
164
|
|
|
* @param string $format |
165
|
|
|
* @param string $stripTags |
166
|
|
|
* |
167
|
|
|
* @return mixed|string |
168
|
|
|
*/ |
169
|
|
|
public function getSummary($maxLength = 0, $format = 'S', $stripTags = '') |
170
|
|
|
{ |
171
|
|
|
$ret = $this->getVar('summary', $format); |
172
|
|
|
if (!empty($stripTags)) { |
173
|
|
|
$ret = \strip_tags($ret, $stripTags); |
174
|
|
|
} |
175
|
|
|
if (0 != $maxLength) { |
176
|
|
|
if (!XOOPS_USE_MULTIBYTES) { |
177
|
|
|
if (\mb_strlen($ret) >= $maxLength) { |
178
|
|
|
//$ret = Utility::substr($ret , 0, $maxLength); |
179
|
|
|
// $ret = Utility::truncateTagSafe($ret, $maxLength, $etc = '...', $breakWords = false); |
180
|
|
|
$ret = Utility::truncateHtml($ret, $maxLength, $etc = '...', $breakWords = false); |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
return $ret; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @param int $maxLength |
190
|
|
|
* @param bool $fullSummary |
191
|
|
|
* |
192
|
|
|
* @return mixed|string |
193
|
|
|
*/ |
194
|
|
|
public function getBlockSummary($maxLength = 0, $fullSummary = false) |
195
|
|
|
{ |
196
|
|
|
if ($fullSummary) { |
197
|
|
|
$ret = $this->getSummary(0, 's', '<br><br>'); |
198
|
|
|
} else { |
199
|
|
|
$ret = $this->getSummary($maxLength, 's', '<br><br>'); |
200
|
|
|
} |
201
|
|
|
//no summary? get body! |
202
|
|
|
if ('' === $ret) { |
203
|
|
|
$ret = $this->getBody($maxLength, 's', '<br><br>'); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
return $ret; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @param string $fileName |
211
|
|
|
* |
212
|
|
|
* @return string |
213
|
|
|
*/ |
214
|
|
|
public function wrapPage($fileName) |
215
|
|
|
{ |
216
|
|
|
$content = ''; |
217
|
|
|
$page = Utility::getUploadDir(true, 'content') . $fileName; |
218
|
|
|
if (\is_file($page)) { |
219
|
|
|
// this page uses smarty template |
220
|
|
|
\ob_start(); |
221
|
|
|
require $page; |
222
|
|
|
$content = \ob_get_clean(); |
223
|
|
|
// Cleaning the content |
224
|
|
|
$bodyStartPos = \mb_strpos($content, self::BODYTAG); |
225
|
|
|
if ($bodyStartPos) { |
226
|
|
|
$bodyEndPos = \mb_strpos($content, '</body>', $bodyStartPos); |
227
|
|
|
$content = \mb_substr($content, $bodyStartPos + \mb_strlen(self::BODYTAG), $bodyEndPos - \mb_strlen(self::BODYTAG) - $bodyStartPos); |
228
|
|
|
} |
229
|
|
|
// Check if ML Hack is installed, and if yes, parse the $content in formatForML |
230
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
231
|
|
|
if (\method_exists($myts, 'formatForML')) { |
232
|
|
|
$content = $myts->formatForML($content); |
233
|
|
|
} |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
return $content; |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* This method returns the body to be displayed. Not to be used for editing |
241
|
|
|
* |
242
|
|
|
* @param int $maxLength |
243
|
|
|
* @param string $format |
244
|
|
|
* @param string $stripTags |
245
|
|
|
* |
246
|
|
|
* @return mixed|string |
247
|
|
|
*/ |
248
|
|
|
public function getBody($maxLength = 0, $format = 'S', $stripTags = '') |
249
|
|
|
{ |
250
|
|
|
$ret = $this->getVar('body', $format); |
251
|
|
|
$wrapPos = \mb_strpos($ret, self::PAGEWRAP); |
252
|
|
|
if (!(false === $wrapPos)) { |
253
|
|
|
$wrapPages = []; |
254
|
|
|
$wrapCodeLength = \mb_strlen(self::PAGEWRAP); |
255
|
|
|
while (!(false === $wrapPos)) { |
256
|
|
|
$endWrapPos = \mb_strpos($ret, ']', $wrapPos); |
257
|
|
|
if ($endWrapPos) { |
258
|
|
|
$wrapPagename = \mb_substr($ret, $wrapPos + $wrapCodeLength, $endWrapPos - $wrapCodeLength - $wrapPos); |
259
|
|
|
$wrapPages[] = $wrapPagename; |
260
|
|
|
} |
261
|
|
|
$wrapPos = \mb_strpos($ret, self::PAGEWRAP, $endWrapPos - 1); |
262
|
|
|
} |
263
|
|
|
foreach ($wrapPages as $page) { |
264
|
|
|
$wrapPageContent = $this->wrapPage($page); |
265
|
|
|
$ret = \str_replace("[pagewrap={$page}]", $wrapPageContent, $ret); |
266
|
|
|
} |
267
|
|
|
} |
268
|
|
|
if ($this->helper->getConfig('item_disp_blocks_summary')) { |
269
|
|
|
$summary = $this->getSummary($maxLength, $format, $stripTags); |
270
|
|
|
if ($summary) { |
271
|
|
|
$ret = $this->getSummary() . '<br><br>' . $ret; |
272
|
|
|
} |
273
|
|
|
} |
274
|
|
|
if (!empty($stripTags)) { |
275
|
|
|
$ret = \strip_tags($ret, $stripTags); |
276
|
|
|
} |
277
|
|
|
if (0 != $maxLength) { |
278
|
|
|
if (!XOOPS_USE_MULTIBYTES) { |
279
|
|
|
if (\mb_strlen($ret) >= $maxLength) { |
280
|
|
|
//$ret = Utility::substr($ret , 0, $maxLength); |
281
|
|
|
$ret = Utility::truncateHtml($ret, $maxLength, $etc = '...', $breakWords = false); |
282
|
|
|
} |
283
|
|
|
} |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
return $ret; |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* @param string $dateFormat |
291
|
|
|
* @param string $format |
292
|
|
|
* |
293
|
|
|
* @return string |
294
|
|
|
*/ |
295
|
|
|
public function getDatesub($dateFormat = '', $format = 'S') |
296
|
|
|
{ |
297
|
|
|
if (empty($dateFormat)) { |
298
|
|
|
$dateFormat = $this->helper->getConfig('format_date'); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
return \formatTimestamp($this->getVar('datesub', $format), $dateFormat); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* @param string $dateFormat |
306
|
|
|
* @param string $format |
307
|
|
|
* |
308
|
|
|
* @return string|false |
309
|
|
|
*/ |
310
|
|
|
public function getDateExpire($dateFormat = '', $format = 'S') |
311
|
|
|
{ |
312
|
|
|
if (empty($dateFormat)) { |
313
|
|
|
$dateFormat = $this->helper->getConfig('format_date'); |
314
|
|
|
} |
315
|
|
|
if (0 == $this->getVar('dateexpire')) { |
316
|
|
|
return false; |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
return \formatTimestamp($this->getVar('dateexpire', $format), $dateFormat); |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* @param int $realName |
324
|
|
|
* |
325
|
|
|
* @return string |
326
|
|
|
*/ |
327
|
|
|
public function posterName($realName = -1) |
328
|
|
|
{ |
329
|
|
|
\xoops_load('XoopsUserUtility'); |
330
|
|
|
if (-1 == $realName) { |
331
|
|
|
$realName = $this->helper->getConfig('format_realname'); |
332
|
|
|
} |
333
|
|
|
$ret = $this->author_alias(); |
|
|
|
|
334
|
|
|
if ('' == $ret) { |
335
|
|
|
$ret = \XoopsUserUtility::getUnameFromId($this->uid(), $realName); |
|
|
|
|
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
return $ret; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* @return string |
343
|
|
|
*/ |
344
|
|
|
public function posterAvatar() |
345
|
|
|
{ |
346
|
|
|
$ret = 'blank.gif'; |
347
|
|
|
/** @var \XoopsMemberHandler $memberHandler */ |
348
|
|
|
$memberHandler = \xoops_getHandler('member'); |
349
|
|
|
$thisUser = $memberHandler->getUser($this->uid()); |
350
|
|
|
if (\is_object($thisUser)) { |
351
|
|
|
$ret = $thisUser->getVar('user_avatar'); |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
return $ret; |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
/** |
358
|
|
|
* @return string |
359
|
|
|
*/ |
360
|
|
|
public function getLinkedPosterName() |
361
|
|
|
{ |
362
|
|
|
\xoops_load('XoopsUserUtility'); |
363
|
|
|
$ret = $this->author_alias(); |
364
|
|
|
if ('' === $ret) { |
365
|
|
|
$ret = \XoopsUserUtility::getUnameFromId($this->uid(), $this->helper->getConfig('format_realname'), true); |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
return $ret; |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
/** |
372
|
|
|
* @return mixed |
373
|
|
|
*/ |
374
|
|
|
public function updateCounter() |
375
|
|
|
{ |
376
|
|
|
return $this->helper->getHandler('Item') |
377
|
|
|
->updateCounter($this->itemid()); |
|
|
|
|
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* @param bool $force |
382
|
|
|
* |
383
|
|
|
* @return bool |
384
|
|
|
*/ |
385
|
|
|
public function store($force = true) |
386
|
|
|
{ |
387
|
|
|
$isNew = $this->isNew(); |
388
|
|
|
if (!$this->helper->getHandler('Item') |
389
|
|
|
->insert($this, $force)) { |
390
|
|
|
return false; |
391
|
|
|
} |
392
|
|
|
if ($isNew && Constants::PUBLISHER_STATUS_PUBLISHED == $this->getVar('status')) { |
393
|
|
|
// Increment user posts |
394
|
|
|
$userHandler = \xoops_getHandler('user'); |
395
|
|
|
/** @var \XoopsMemberHandler $memberHandler */ |
396
|
|
|
$memberHandler = \xoops_getHandler('member'); |
397
|
|
|
/** @var \XoopsUser $poster */ |
398
|
|
|
$poster = $userHandler->get($this->uid()); |
399
|
|
|
if (\is_object($poster) && !$poster->isNew()) { |
400
|
|
|
$poster->setVar('posts', $poster->getVar('posts') + 1); |
401
|
|
|
if (!$memberHandler->insertUser($poster, true)) { |
402
|
|
|
$this->setErrors('Article created but could not increment user posts.'); |
403
|
|
|
|
404
|
|
|
return false; |
405
|
|
|
} |
406
|
|
|
} |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
return true; |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
/** |
413
|
|
|
* @return string |
414
|
|
|
*/ |
415
|
|
|
public function getCategoryName() |
416
|
|
|
{ |
417
|
|
|
return $this->getCategory() |
|
|
|
|
418
|
|
|
->name(); |
|
|
|
|
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* @return string |
423
|
|
|
*/ |
424
|
|
|
public function getCategoryUrl() |
425
|
|
|
{ |
426
|
|
|
return $this->getCategory() |
427
|
|
|
->getCategoryUrl(); |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
/** |
431
|
|
|
* @return string |
432
|
|
|
*/ |
433
|
|
|
public function getCategoryLink() |
434
|
|
|
{ |
435
|
|
|
return $this->getCategory() |
436
|
|
|
->getCategoryLink(); |
437
|
|
|
} |
438
|
|
|
|
439
|
|
|
/** |
440
|
|
|
* @param bool $withAllLink |
441
|
|
|
* |
442
|
|
|
* @return array|bool|string |
443
|
|
|
*/ |
444
|
|
|
public function getCategoryPath($withAllLink = true) |
445
|
|
|
{ |
446
|
|
|
return $this->getCategory() |
447
|
|
|
->getCategoryPath($withAllLink); |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* @return string |
452
|
|
|
*/ |
453
|
|
|
public function getCategoryImagePath() |
454
|
|
|
{ |
455
|
|
|
return Utility::getImageDir('category', false) . $this->getCategory() |
456
|
|
|
->getImage(); |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
/** |
460
|
|
|
* @return mixed |
461
|
|
|
*/ |
462
|
|
|
public function getFiles() |
463
|
|
|
{ |
464
|
|
|
return $this->helper->getHandler('File') |
465
|
|
|
->getAllFiles($this->itemid(), Constants::PUBLISHER_STATUS_FILE_ACTIVE); |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
/** |
469
|
|
|
* @param $icons |
470
|
|
|
* @return string |
471
|
|
|
*/ |
472
|
|
|
public function getAdminLinks($icons) |
473
|
|
|
{ |
474
|
|
|
$adminLinks = ''; |
475
|
|
|
if (\is_object($GLOBALS['xoopsUser']) |
476
|
|
|
&& (Utility::userIsAdmin() || Utility::userIsAuthor($this) |
477
|
|
|
|| $this->helper->getHandler('Permission') |
478
|
|
|
->isGranted('item_submit', $this->categoryid()))) { |
|
|
|
|
479
|
|
|
if (Utility::userIsAdmin() || Utility::userIsAuthor($this) || Utility::userIsModerator($this)) { |
480
|
|
|
if ($this->helper->getConfig('perm_edit') || Utility::userIsModerator($this) || Utility::userIsAdmin()) { |
481
|
|
|
// Edit button |
482
|
|
|
$adminLinks .= "<a href='" . PUBLISHER_URL . '/submit.php?itemid=' . $this->itemid() . "'>" . $icons['edit'] . '</a>'; |
483
|
|
|
$adminLinks .= ' '; |
484
|
|
|
} |
485
|
|
|
if ($this->helper->getConfig('perm_delete') || Utility::userIsModerator($this) || Utility::userIsAdmin()) { |
486
|
|
|
// Delete button |
487
|
|
|
$adminLinks .= "<a href='" . PUBLISHER_URL . '/submit.php?op=del&itemid=' . $this->itemid() . "'>" . $icons['delete'] . '</a>'; |
488
|
|
|
$adminLinks .= ' '; |
489
|
|
|
} |
490
|
|
|
} |
491
|
|
|
if ($this->helper->getConfig('perm_clone') || Utility::userIsModerator($this) || Utility::userIsAdmin()) { |
492
|
|
|
// Duplicate button |
493
|
|
|
$adminLinks .= "<a href='" . PUBLISHER_URL . '/submit.php?op=clone&itemid=' . $this->itemid() . "'>" . $icons['clone'] . '</a>'; |
494
|
|
|
$adminLinks .= ' '; |
495
|
|
|
} |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
return $adminLinks; |
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
/** |
502
|
|
|
* @param $icons |
503
|
|
|
* @return string |
504
|
|
|
*/ |
505
|
|
|
public function getPdfButton($icons) |
506
|
|
|
{ |
507
|
|
|
$pdfButton = ''; |
508
|
|
|
// PDF button |
509
|
|
|
if (\is_file(XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php')) { |
510
|
|
|
$pdfButton .= "<a href='" . PUBLISHER_URL . '/makepdf.php?itemid=' . $this->itemid() . "' rel='nofollow' target='_blank'>" . $icons['pdf'] . '</a> '; |
511
|
|
|
$pdfButton .= ' '; |
512
|
|
|
} |
513
|
|
|
// if (is_object($GLOBALS['xoopsUser']) && Utility::userIsAdmin()) { |
514
|
|
|
// $GLOBALS['xoTheme']->addStylesheet('/modules/system/css/jquery.jgrowl.min.css'); |
515
|
|
|
// $GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/plugins/jquery.jgrowl.js'); |
516
|
|
|
// $adminLinks .= '<script type="text/javascript"> |
517
|
|
|
// (function($){ |
518
|
|
|
// $(document).ready(function(){ |
519
|
|
|
// $.jGrowl("' . _MD_PUBLISHER_ERROR_NO_PDF . '");}); |
520
|
|
|
// })(jQuery); |
521
|
|
|
// </script>'; |
522
|
|
|
// } |
523
|
|
|
|
524
|
|
|
return $pdfButton; |
525
|
|
|
} |
526
|
|
|
|
527
|
|
|
/** |
528
|
|
|
* @param $icons |
529
|
|
|
* @return string |
530
|
|
|
*/ |
531
|
|
|
public function getPrintLinks($icons) |
532
|
|
|
{ |
533
|
|
|
$printLinks = ''; |
534
|
|
|
// Print button |
535
|
|
|
$printLinks .= "<a href='" . Seo::generateUrl('print', $this->itemid(), $this->short_url()) . "' rel='nofollow' target='_blank'>" . $icons['print'] . '</a> '; |
|
|
|
|
536
|
|
|
$printLinks .= ' '; |
537
|
|
|
|
538
|
|
|
return $printLinks; |
539
|
|
|
} |
540
|
|
|
|
541
|
|
|
/** |
542
|
|
|
* @param array $notifications |
543
|
|
|
*/ |
544
|
|
|
public function sendNotifications($notifications = []): void |
545
|
|
|
{ |
546
|
|
|
/** @var \XoopsNotificationHandler $notificationHandler */ |
547
|
|
|
$notificationHandler = \xoops_getHandler('notification'); |
548
|
|
|
$tags = []; |
549
|
|
|
|
550
|
|
|
$tags['MODULE_NAME'] = $this->helper->getModule() |
551
|
|
|
->getVar('name'); |
552
|
|
|
$tags['ITEM_NAME'] = $this->getTitle(); |
553
|
|
|
$tags['ITEM_SUBNAME'] = $this->getSubtitle(); |
554
|
|
|
$tags['CATEGORY_NAME'] = $this->getCategoryName(); |
555
|
|
|
$tags['CATEGORY_URL'] = PUBLISHER_URL . '/category.php?categoryid=' . $this->categoryid(); |
556
|
|
|
$tags['ITEM_BODY'] = $this->body(); |
|
|
|
|
557
|
|
|
$tags['DATESUB'] = $this->getDatesub(); |
558
|
|
|
foreach ($notifications as $notification) { |
559
|
|
|
switch ($notification) { |
560
|
|
|
case Constants::PUBLISHER_NOTIFY_ITEM_PUBLISHED: |
561
|
|
|
$tags['ITEM_URL'] = PUBLISHER_URL . '/item.php?itemid=' . $this->itemid(); |
562
|
|
|
$notificationHandler->triggerEvent('global_item', 0, 'published', $tags, [], $this->helper->getModule() |
563
|
|
|
->getVar('mid')); |
564
|
|
|
$notificationHandler->triggerEvent('category_item', $this->categoryid(), 'published', $tags, [], $this->helper->getModule() |
565
|
|
|
->getVar('mid')); |
566
|
|
|
$notificationHandler->triggerEvent('item', $this->itemid(), 'approved', $tags, [], $this->helper->getModule() |
567
|
|
|
->getVar('mid')); |
568
|
|
|
break; |
569
|
|
|
case Constants::PUBLISHER_NOTIFY_ITEM_SUBMITTED: |
570
|
|
|
$tags['WAITINGFILES_URL'] = PUBLISHER_URL . '/admin/item.php?itemid=' . $this->itemid(); |
571
|
|
|
$notificationHandler->triggerEvent('global_item', 0, 'submitted', $tags, [], $this->helper->getModule() |
572
|
|
|
->getVar('mid')); |
573
|
|
|
$notificationHandler->triggerEvent('category_item', $this->categoryid(), 'submitted', $tags, [], $this->helper->getModule() |
574
|
|
|
->getVar('mid')); |
575
|
|
|
break; |
576
|
|
|
case Constants::PUBLISHER_NOTIFY_ITEM_REJECTED: |
577
|
|
|
$notificationHandler->triggerEvent('item', $this->itemid(), 'rejected', $tags, [], $this->helper->getModule() |
578
|
|
|
->getVar('mid')); |
579
|
|
|
break; |
580
|
|
|
case -1: |
581
|
|
|
default: |
582
|
|
|
break; |
583
|
|
|
} |
584
|
|
|
} |
585
|
|
|
} |
586
|
|
|
|
587
|
|
|
/** |
588
|
|
|
* Sets default permissions for this item |
589
|
|
|
*/ |
590
|
|
|
public function setDefaultPermissions(): void |
591
|
|
|
{ |
592
|
|
|
$memberHandler = \xoops_getHandler('member'); |
593
|
|
|
$groups = $memberHandler->getGroupList(); |
|
|
|
|
594
|
|
|
$groupIds = \count($groups) > 0 ? \array_keys($groups) : []; |
595
|
|
|
/* |
596
|
|
|
$j = 0; |
597
|
|
|
$groupIds = []; |
598
|
|
|
foreach (array_keys($groups) as $i) { |
599
|
|
|
$groupIds[$j] = $i; |
600
|
|
|
++$j; |
601
|
|
|
} |
602
|
|
|
*/ |
603
|
|
|
$this->groupsRead = $groupIds; |
604
|
|
|
} |
605
|
|
|
|
606
|
|
|
/** |
607
|
|
|
* @param $groupIds |
608
|
|
|
* @deprecated - NOT USED |
609
|
|
|
* |
610
|
|
|
* @todo look at this |
611
|
|
|
*/ |
612
|
|
|
public function setPermissions($groupIds): void |
613
|
|
|
{ |
614
|
|
|
if (!isset($groupIds)) { |
615
|
|
|
$this->setDefaultPermissions(); |
616
|
|
|
/* |
617
|
|
|
$memberHandler = xoops_getHandler('member'); |
618
|
|
|
$groups = $memberHandler->getGroupList(); |
619
|
|
|
$j = 0; |
620
|
|
|
$groupIds = []; |
621
|
|
|
foreach (array_keys($groups) as $i) { |
622
|
|
|
$groupIds[$j] = $i; |
623
|
|
|
++$j; |
624
|
|
|
} |
625
|
|
|
*/ |
626
|
|
|
} |
627
|
|
|
} |
628
|
|
|
|
629
|
|
|
/** |
630
|
|
|
* @return bool |
631
|
|
|
*/ |
632
|
|
|
public function notLoaded() |
633
|
|
|
{ |
634
|
|
|
return -1 == $this->getVar('itemid'); |
635
|
|
|
} |
636
|
|
|
|
637
|
|
|
/** |
638
|
|
|
* @return string |
639
|
|
|
*/ |
640
|
|
|
public function getItemUrl() |
641
|
|
|
{ |
642
|
|
|
return Seo::generateUrl('item', $this->itemid(), $this->short_url()); |
643
|
|
|
} |
644
|
|
|
|
645
|
|
|
/** |
646
|
|
|
* @param bool $class |
647
|
|
|
* @param int $maxsize |
648
|
|
|
* |
649
|
|
|
* @return string |
650
|
|
|
*/ |
651
|
|
|
public function getItemLink($class = false, $maxsize = 0) |
652
|
|
|
{ |
653
|
|
|
if ($class) { |
654
|
|
|
return '<a class="' . $class . '" href="' . $this->getItemUrl() . '">' . $this->getTitle($maxsize) . '</a>'; |
|
|
|
|
655
|
|
|
} |
656
|
|
|
|
657
|
|
|
return '<a href="' . $this->getItemUrl() . '">' . $this->getTitle($maxsize) . '</a>'; |
658
|
|
|
} |
659
|
|
|
|
660
|
|
|
/** |
661
|
|
|
* @return string |
662
|
|
|
*/ |
663
|
|
|
public function getWhoAndWhen() |
664
|
|
|
{ |
665
|
|
|
$posterName = $this->getLinkedPosterName(); |
666
|
|
|
$postdate = $this->getDatesub(); |
667
|
|
|
|
668
|
|
|
return \sprintf(\_CO_PUBLISHER_POSTEDBY, $posterName, $postdate); |
669
|
|
|
} |
670
|
|
|
|
671
|
|
|
/** |
672
|
|
|
* @return string |
673
|
|
|
*/ |
674
|
|
|
public function getWho() |
675
|
|
|
{ |
676
|
|
|
$posterName = $this->getLinkedPosterName(); |
677
|
|
|
|
678
|
|
|
return $posterName; |
679
|
|
|
} |
680
|
|
|
|
681
|
|
|
/** |
682
|
|
|
* @return string |
683
|
|
|
*/ |
684
|
|
|
public function getWhen() |
685
|
|
|
{ |
686
|
|
|
$postdate = $this->getDatesub(); |
687
|
|
|
|
688
|
|
|
return $postdate; |
689
|
|
|
} |
690
|
|
|
|
691
|
|
|
/** |
692
|
|
|
* @param null|string $body |
693
|
|
|
* |
694
|
|
|
* @return string |
695
|
|
|
*/ |
696
|
|
|
public function plainMaintext($body = null) |
697
|
|
|
{ |
698
|
|
|
$ret = ''; |
699
|
|
|
if (!$body) { |
700
|
|
|
$body = $this->body(); |
701
|
|
|
} |
702
|
|
|
$ret .= \str_replace('[pagebreak]', '<br><br>', $body); |
703
|
|
|
|
704
|
|
|
return $ret; |
705
|
|
|
} |
706
|
|
|
|
707
|
|
|
/** |
708
|
|
|
* @param int $itemPageId |
709
|
|
|
* @param null|string $body |
710
|
|
|
* |
711
|
|
|
* @return string |
712
|
|
|
*/ |
713
|
|
|
public function buildMainText($itemPageId = -1, $body = null) |
714
|
|
|
{ |
715
|
|
|
if (null === $body) { |
716
|
|
|
$body = $this->body(); |
717
|
|
|
} |
718
|
|
|
/** @var array $bodyParts */ |
719
|
|
|
$bodyParts = \explode('[pagebreak]', $body); |
720
|
|
|
$this->setVar('pagescount', \count($bodyParts)); |
721
|
|
|
if (\count($bodyParts) <= 1) { |
722
|
|
|
return $this->plainMaintext($body); |
723
|
|
|
} |
724
|
|
|
$ret = ''; |
725
|
|
|
if (-1 == $itemPageId) { |
726
|
|
|
$ret .= \trim($bodyParts[0]); |
727
|
|
|
|
728
|
|
|
return $ret; |
729
|
|
|
} |
730
|
|
|
if ($itemPageId >= \count($bodyParts)) { |
731
|
|
|
$itemPageId = \count($bodyParts) - 1; |
732
|
|
|
} |
733
|
|
|
$ret .= \trim($bodyParts[$itemPageId]); |
734
|
|
|
|
735
|
|
|
return $ret; |
736
|
|
|
} |
737
|
|
|
|
738
|
|
|
/** |
739
|
|
|
* @return mixed |
740
|
|
|
*/ |
741
|
|
|
public function getImages() |
742
|
|
|
{ |
743
|
|
|
static $ret; |
744
|
|
|
$itemId = (int)$this->getVar('itemid'); |
745
|
|
|
if (!isset($ret[$itemId])) { |
746
|
|
|
$ret[$itemId]['main'] = ''; |
747
|
|
|
$ret[$itemId]['others'] = []; |
748
|
|
|
/** @var array $imagesIds */ |
749
|
|
|
$imagesIds = []; |
750
|
|
|
$image = $this->getVar('image'); |
751
|
|
|
$images = $this->getVar('images'); |
752
|
|
|
if ('' != $images) { |
753
|
|
|
$imagesIds = \explode('|', $images); |
754
|
|
|
} |
755
|
|
|
if ($image > 0 && $imagesIds) { |
756
|
|
|
$imagesIds[] = $image; |
757
|
|
|
} |
758
|
|
|
$imageObjs = []; |
759
|
|
|
if (\count($imagesIds) > 0) { |
760
|
|
|
$imageHandler = \xoops_getHandler('image'); |
761
|
|
|
$criteria = new \CriteriaCompo(new \Criteria('image_id', '(' . \implode(',', $imagesIds) . ')', 'IN')); |
762
|
|
|
$imageObjs = $imageHandler->getObjects($criteria, true); |
|
|
|
|
763
|
|
|
unset($criteria); |
764
|
|
|
} |
765
|
|
|
foreach ($imageObjs as $id => $imageObj) { |
766
|
|
|
if ($id == $image) { |
767
|
|
|
$ret[$itemId]['main'] = $imageObj; |
768
|
|
|
} else { |
769
|
|
|
$ret[$itemId]['others'][] = $imageObj; |
770
|
|
|
} |
771
|
|
|
unset($imageObj); |
772
|
|
|
} |
773
|
|
|
unset($imageObjs); |
774
|
|
|
} |
775
|
|
|
|
776
|
|
|
return $ret[$itemId]; |
777
|
|
|
} |
778
|
|
|
|
779
|
|
|
/** |
780
|
|
|
* @param string $display |
781
|
|
|
* @param int $maxCharTitle |
782
|
|
|
* @param int $maxCharSummary |
783
|
|
|
* @param bool $fullSummary |
784
|
|
|
* |
785
|
|
|
* @return array |
786
|
|
|
*/ |
787
|
|
|
public function toArraySimple($display = 'default', $maxCharTitle = 0, $maxCharSummary = 300, $fullSummary = false) |
|
|
|
|
788
|
|
|
{ |
789
|
|
|
$itemPageId = -1; |
790
|
|
|
if (\is_numeric($display)) { |
791
|
|
|
$itemPageId = $display; |
792
|
|
|
$display = 'all'; |
793
|
|
|
} |
794
|
|
|
$item['itemid'] = $this->itemid(); |
|
|
|
|
795
|
|
|
$item['uid'] = $this->uid(); |
796
|
|
|
$item['itemurl'] = $this->getItemUrl(); |
797
|
|
|
$item['titlelink'] = $this->getItemLink('titlelink', $maxCharTitle); |
798
|
|
|
$item['subtitle'] = $this->subtitle(); |
799
|
|
|
$item['datesub'] = $this->getDatesub(); |
800
|
|
|
$item['dateexpire'] = $this->getDateExpire(); |
801
|
|
|
$item['counter'] = $this->counter(); |
802
|
|
|
$item['hits'] = ' ' . $this->counter() . ' ' . _READS . ''; |
803
|
|
|
$item['who'] = $this->getWho(); |
804
|
|
|
$item['when'] = $this->getWhen(); |
805
|
|
|
$item['category'] = $this->getCategoryName(); |
806
|
|
|
$item['categorylink'] = $this->getCategoryLink(); |
807
|
|
|
$item['cancomment'] = $this->cancomment(); |
808
|
|
|
$item['votetype'] = $this->votetype(); |
809
|
|
|
$comments = $this->comments(); |
810
|
|
|
if ($comments > 0) { |
811
|
|
|
//shows 1 comment instead of 1 comm. if comments ==1 |
812
|
|
|
//langugage file modified accordingly |
813
|
|
|
if (1 == $comments) { |
814
|
|
|
$item['comments'] = ' ' . \_MD_PUBLISHER_ONECOMMENT . ' '; |
815
|
|
|
} else { |
816
|
|
|
$item['comments'] = ' ' . $comments . ' ' . \_MD_PUBLISHER_COMMENTS . ' '; |
817
|
|
|
} |
818
|
|
|
} else { |
819
|
|
|
$item['comments'] = ' ' . \_MD_PUBLISHER_NO_COMMENTS . ' '; |
820
|
|
|
} |
821
|
|
|
$item = $this->getMainImage($item); |
822
|
|
|
switch ($display) { |
823
|
|
|
case 'summary': |
824
|
|
|
$item = $this->toArrayFull($item); |
825
|
|
|
$item = $this->toArrayAll($item, $itemPageId); |
826
|
|
|
// no break |
827
|
|
|
case 'list': |
828
|
|
|
$item = $this->toArrayFull($item); |
829
|
|
|
$item = $this->toArrayAll($item, $itemPageId); |
830
|
|
|
//break; |
831
|
|
|
// no break |
832
|
|
|
case 'full': |
833
|
|
|
$item = $this->toArrayFull($item); |
834
|
|
|
$item = $this->toArrayAll($item, $itemPageId); |
835
|
|
|
// no break |
836
|
|
|
case 'wfsection': |
837
|
|
|
$item = $this->toArrayFull($item); |
838
|
|
|
$item = $this->toArrayAll($item, $itemPageId); |
839
|
|
|
// no break |
840
|
|
|
case 'default': |
841
|
|
|
$item = $this->toArrayFull($item); |
842
|
|
|
$item = $this->toArrayAll($item, $itemPageId); |
843
|
|
|
$summary = $this->getSummary($maxCharSummary); |
844
|
|
|
if (!$summary) { |
845
|
|
|
$summary = $this->getBody($maxCharSummary); |
846
|
|
|
} |
847
|
|
|
$item['summary'] = $summary; |
848
|
|
|
$item['truncated'] = $maxCharSummary > 0 && \mb_strlen($summary) > $maxCharSummary; |
849
|
|
|
$item = $this->toArrayFull($item); |
850
|
|
|
break; |
851
|
|
|
case 'all': |
852
|
|
|
$item = $this->toArrayFull($item); |
853
|
|
|
$item = $this->toArrayAll($item, $itemPageId); |
854
|
|
|
break; |
855
|
|
|
} |
856
|
|
|
// Highlighting searched words |
857
|
|
|
$highlight = true; |
858
|
|
|
if ($highlight && Request::getString('keywords', '', 'GET')) { |
859
|
|
|
$keywords = \htmlspecialchars(\trim(\urldecode(Request::getString('keywords', '', 'GET'))), \ENT_QUOTES | \ENT_HTML5); |
860
|
|
|
$fields = ['title', 'maintext', 'summary']; |
861
|
|
|
foreach ($fields as $field) { |
862
|
|
|
if (isset($item[$field])) { |
863
|
|
|
$item[$field] = $this->highlight($item[$field], $keywords); |
864
|
|
|
} |
865
|
|
|
} |
866
|
|
|
} |
867
|
|
|
|
868
|
|
|
return $item; |
869
|
|
|
} |
870
|
|
|
|
871
|
|
|
/** |
872
|
|
|
* @param array $item |
873
|
|
|
* |
874
|
|
|
* @return array |
875
|
|
|
*/ |
876
|
|
|
public function toArrayFull($item) |
877
|
|
|
{ |
878
|
|
|
$configurator = new Common\Configurator(); |
879
|
|
|
$icons = $configurator->icons; |
880
|
|
|
|
881
|
|
|
$item['title'] = $this->getTitle(); |
882
|
|
|
$item['clean_title'] = $this->getTitle(); |
883
|
|
|
$item['itemurl'] = $this->getItemUrl(); |
884
|
|
|
|
885
|
|
|
$item['adminlink'] = $this->getAdminLinks($icons); |
886
|
|
|
$item['pdfbutton'] = $this->getPdfButton($icons); |
887
|
|
|
$item['printlink'] = $this->getPrintLinks($icons); |
888
|
|
|
$item['categoryPath'] = $this->getCategoryPath($this->helper->getConfig('format_linked_path')); |
889
|
|
|
$item['who_when'] = $this->getWhoAndWhen(); |
890
|
|
|
$item['who'] = $this->getWho(); |
891
|
|
|
$item['when'] = $this->getWhen(); |
892
|
|
|
$item['category'] = $this->getCategoryName(); |
893
|
|
|
$item['body'] = $this->getBody(); |
894
|
|
|
$item['more'] = $this->getItemUrl(); |
895
|
|
|
$item = $this->getMainImage($item); |
896
|
|
|
|
897
|
|
|
return $item; |
898
|
|
|
} |
899
|
|
|
|
900
|
|
|
/** |
901
|
|
|
* @param array $item |
902
|
|
|
* @param int $itemPageId |
903
|
|
|
* |
904
|
|
|
* @return array |
905
|
|
|
*/ |
906
|
|
|
public function toArrayAll($item, $itemPageId) |
907
|
|
|
{ |
908
|
|
|
$item['maintext'] = $this->buildMainText($itemPageId, $this->getBody()); |
909
|
|
|
$item = $this->getOtherImages($item); |
910
|
|
|
|
911
|
|
|
return $item; |
912
|
|
|
} |
913
|
|
|
|
914
|
|
|
/** |
915
|
|
|
* @param array $item |
916
|
|
|
* |
917
|
|
|
* @return array |
918
|
|
|
*/ |
919
|
|
|
public function getMainImage($item = []) |
920
|
|
|
{ |
921
|
|
|
$images = $this->getImages(); |
922
|
|
|
$item['image_path'] = ''; |
923
|
|
|
$item['image_name'] = ''; |
924
|
|
|
if (\is_object($images['main'])) { |
925
|
|
|
/** @var array $dimensions */ |
926
|
|
|
$dimensions = \getimagesize($GLOBALS['xoops']->path('uploads/' . $images['main']->getVar('image_name'))); |
927
|
|
|
$item['image_width'] = $dimensions[0]; |
928
|
|
|
$item['image_height'] = $dimensions[1]; |
929
|
|
|
$item['image_path'] = XOOPS_URL . '/uploads/' . $images['main']->getVar('image_name'); |
930
|
|
|
// check to see if GD function exist |
931
|
|
|
if (\function_exists('imagecreatetruecolor')) { |
932
|
|
|
$item['image_thumb'] = PUBLISHER_URL . '/thumb.php?src=' . XOOPS_URL . '/uploads/' . $images['main']->getVar('image_name') . '&h=180'; |
933
|
|
|
} else { |
934
|
|
|
$item['image_thumb'] = XOOPS_URL . '/uploads/' . $images['main']->getVar('image_name'); |
935
|
|
|
} |
936
|
|
|
$item['image_name'] = $images['main']->getVar('image_nicename'); |
937
|
|
|
} |
938
|
|
|
|
939
|
|
|
return $item; |
940
|
|
|
} |
941
|
|
|
|
942
|
|
|
/** |
943
|
|
|
* @param array $item |
944
|
|
|
* |
945
|
|
|
* @return array |
946
|
|
|
*/ |
947
|
|
|
public function getOtherImages($item = []) |
948
|
|
|
{ |
949
|
|
|
$images = $this->getImages(); |
950
|
|
|
$item['images'] = []; |
951
|
|
|
$i = 0; |
952
|
|
|
foreach ($images['others'] as $image) { |
953
|
|
|
/** @var array $dimensions */ |
954
|
|
|
$dimensions = \getimagesize($GLOBALS['xoops']->path('uploads/' . $image->getVar('image_name'))); |
955
|
|
|
$item['images'][$i]['width'] = $dimensions[0]; |
956
|
|
|
$item['images'][$i]['height'] = $dimensions[1]; |
957
|
|
|
$item['images'][$i]['path'] = XOOPS_URL . '/uploads/' . $image->getVar('image_name'); |
958
|
|
|
// check to see if GD function exist |
959
|
|
|
if (\function_exists('imagecreatetruecolor')) { |
960
|
|
|
$item['images'][$i]['thumb'] = PUBLISHER_URL . '/thumb.php?src=' . XOOPS_URL . '/uploads/' . $image->getVar('image_name') . '&w=240'; |
961
|
|
|
} else { |
962
|
|
|
$item['images'][$i]['thumb'] = XOOPS_URL . '/uploads/' . $image->getVar('image_name'); |
963
|
|
|
} |
964
|
|
|
$item['images'][$i]['name'] = $image->getVar('image_nicename'); |
965
|
|
|
++$i; |
966
|
|
|
} |
967
|
|
|
|
968
|
|
|
return $item; |
969
|
|
|
} |
970
|
|
|
|
971
|
|
|
/** |
972
|
|
|
* @param string $content |
973
|
|
|
* @param string|array $keywords |
974
|
|
|
* |
975
|
|
|
* @return string Text |
976
|
|
|
*/ |
977
|
|
|
public function highlight($content, $keywords) |
978
|
|
|
{ |
979
|
|
|
$color = $this->helper->getConfig('format_highlight_color'); |
980
|
|
|
if (0 !== \mb_strpos($color, '#')) { |
|
|
|
|
981
|
|
|
$color = '#' . $color; |
982
|
|
|
} |
983
|
|
|
require_once __DIR__ . '/Highlighter.php'; |
984
|
|
|
$highlighter = new Highlighter(); |
985
|
|
|
$highlighter->setReplacementString('<span style="font-weight: bolder; background-color: ' . $color . ';">\1</span>'); |
986
|
|
|
|
987
|
|
|
return $highlighter->highlight($content, $keywords); |
988
|
|
|
} |
989
|
|
|
|
990
|
|
|
/** |
991
|
|
|
* Create metada and assign it to template |
992
|
|
|
*/ |
993
|
|
|
public function createMetaTags(): void |
994
|
|
|
{ |
995
|
|
|
$publisherMetagen = new Metagen($this->getTitle(), $this->meta_keywords(), $this->meta_description(), $this->category->categoryPath); |
|
|
|
|
996
|
|
|
$publisherMetagen->createMetaTags(); |
997
|
|
|
} |
998
|
|
|
|
999
|
|
|
/** |
1000
|
|
|
* @param string $str |
1001
|
|
|
* |
1002
|
|
|
* @return string |
1003
|
|
|
*/ |
1004
|
|
|
protected function convertForJapanese($str) |
1005
|
|
|
{ |
1006
|
|
|
// no action, if not flag |
1007
|
|
|
if (!\defined('_PUBLISHER_FLAG_JP_CONVERT')) { |
1008
|
|
|
return $str; |
1009
|
|
|
} |
1010
|
|
|
// no action, if not Japanese |
1011
|
|
|
if ('japanese' !== $GLOBALS['xoopsConfig']['language']) { |
1012
|
|
|
return $str; |
1013
|
|
|
} |
1014
|
|
|
// presume OS Browser |
1015
|
|
|
$agent = Request::getString('HTTP_USER_AGENT', '', 'SERVER'); |
1016
|
|
|
$os = ''; |
1017
|
|
|
$browser = ''; |
1018
|
|
|
// if (preg_match("/Win/i", $agent)) { |
1019
|
|
|
if (false !== \mb_stripos($agent, 'Win')) { |
1020
|
|
|
$os = 'win'; |
1021
|
|
|
} |
1022
|
|
|
// if (preg_match("/MSIE/i", $agent)) { |
1023
|
|
|
if (false !== \mb_stripos($agent, 'MSIE')) { |
1024
|
|
|
$browser = 'msie'; |
1025
|
|
|
} |
1026
|
|
|
// if msie |
1027
|
|
|
if (('win' === $os) && ('msie' === $browser)) { |
1028
|
|
|
// if multibyte |
1029
|
|
|
if (\function_exists('mb_convert_encoding')) { |
1030
|
|
|
$str = \mb_convert_encoding($str, 'SJIS', 'EUC-JP'); |
1031
|
|
|
$str = \rawurlencode($str); |
|
|
|
|
1032
|
|
|
} |
1033
|
|
|
} |
1034
|
|
|
|
1035
|
|
|
return $str; |
1036
|
|
|
} |
1037
|
|
|
|
1038
|
|
|
/** |
1039
|
|
|
* @param string $title |
1040
|
|
|
* @param bool $checkperm |
1041
|
|
|
* |
1042
|
|
|
* @return Form\ItemForm |
1043
|
|
|
*/ |
1044
|
|
|
public function getForm($title = 'default', $checkperm = true) |
1045
|
|
|
{ |
1046
|
|
|
// require_once $GLOBALS['xoops']->path('modules/' . PUBLISHER_DIRNAME . '/class/form/item.php'); |
1047
|
|
|
$form = new Form\ItemForm($title, 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true); |
1048
|
|
|
$form->setCheckPermissions($checkperm); |
1049
|
|
|
$form->createElements($this); |
1050
|
|
|
|
1051
|
|
|
return $form; |
1052
|
|
|
} |
1053
|
|
|
|
1054
|
|
|
/** |
1055
|
|
|
* Checks if a user has access to a selected item. if no item permissions are |
1056
|
|
|
* set, access permission is denied. The user needs to have necessary category |
1057
|
|
|
* permission as well. |
1058
|
|
|
* Also, the item needs to be Published |
1059
|
|
|
* |
1060
|
|
|
* @return bool : TRUE if the no errors occured |
1061
|
|
|
*/ |
1062
|
|
|
public function accessGranted() |
1063
|
|
|
{ |
1064
|
|
|
if (Utility::userIsAdmin()) { |
1065
|
|
|
return true; |
1066
|
|
|
} |
1067
|
|
|
if (Constants::PUBLISHER_STATUS_PUBLISHED != $this->getVar('status')) { |
1068
|
|
|
return false; |
1069
|
|
|
} |
1070
|
|
|
// Do we have access to the parent category |
1071
|
|
|
if ($this->helper->getHandler('Permission') |
1072
|
|
|
->isGranted('category_read', $this->categoryid())) { |
1073
|
|
|
return true; |
1074
|
|
|
} |
1075
|
|
|
|
1076
|
|
|
return false; |
1077
|
|
|
} |
1078
|
|
|
|
1079
|
|
|
/** |
1080
|
|
|
* The name says it all |
1081
|
|
|
*/ |
1082
|
|
|
public function setVarsFromRequest(): void |
1083
|
|
|
{ |
1084
|
|
|
//Required fields |
1085
|
|
|
// if (!empty($categoryid = Request::getInt('categoryid', 0, 'POST'))) { |
1086
|
|
|
// $this->setVar('categoryid', $categoryid);} |
1087
|
|
|
if (\is_object($GLOBALS['xoopsUser'])) { |
1088
|
|
|
$userTimeoffset = $GLOBALS['xoopsUser']->getVar('timezone_offset'); |
1089
|
|
|
} else { |
1090
|
|
|
$userTimeoffset = null; |
1091
|
|
|
} |
1092
|
|
|
$this->setVar('categoryid', Request::getInt('categoryid', 0, 'POST')); |
1093
|
|
|
$this->setVar('title', Request::getString('title', '', 'POST')); |
1094
|
|
|
$this->setVar('body', Request::getText('body', '', 'POST')); |
1095
|
|
|
|
1096
|
|
|
if ('' !== ($imageFeatured = Request::getString('image_featured', '', 'POST'))) { |
1097
|
|
|
$imageItem = Request::getArray('image_item', [], 'POST'); |
1098
|
|
|
// $imageFeatured = Request::getString('image_featured', '', 'POST'); |
1099
|
|
|
//Todo: get a better image class for xoops! |
1100
|
|
|
//Image hack |
1101
|
|
|
$imageItemIds = []; |
1102
|
|
|
|
1103
|
|
|
$sql = 'SELECT image_id, image_name FROM ' . $GLOBALS['xoopsDB']->prefix('image'); |
1104
|
|
|
$result = $GLOBALS['xoopsDB']->query($sql, 0, 0); |
1105
|
|
|
while (false !== ($myrow = $GLOBALS['xoopsDB']->fetchArray($result))) { |
1106
|
|
|
$imageName = $myrow['image_name']; |
1107
|
|
|
$id = $myrow['image_id']; |
1108
|
|
|
if ($imageName == $imageFeatured) { |
1109
|
|
|
$this->setVar('image', $id); |
1110
|
|
|
} |
1111
|
|
|
if (\in_array($imageName, $imageItem, true)) { |
1112
|
|
|
$imageItemIds[] = $id; |
1113
|
|
|
} |
1114
|
|
|
} |
1115
|
|
|
$this->setVar('images', \implode('|', $imageItemIds)); |
1116
|
|
|
} else { |
1117
|
|
|
$this->setVar('image', 0); |
1118
|
|
|
$this->setVar('images', ''); |
1119
|
|
|
} |
1120
|
|
|
|
1121
|
|
|
if (false !== ($authorAlias = Request::getString('author_alias', '', 'POST'))) { |
|
|
|
|
1122
|
|
|
$this->setVar('author_alias', $authorAlias); |
1123
|
|
|
if ('' !== $this->getVar('author_alias')) { |
1124
|
|
|
$this->setVar('uid', 0); |
1125
|
|
|
} |
1126
|
|
|
} |
1127
|
|
|
|
1128
|
|
|
//mb TODO check on version |
1129
|
|
|
//check if date is set and convert it to GMT date |
1130
|
|
|
// if (($datesub = Request::getString('datesub', '', 'POST'))) { |
1131
|
|
|
if ('' !== Request::getString('datesub', '', 'POST')) { |
1132
|
|
|
// if (version_compare(PHP_VERSION, '5.4.0') >= 0) { |
1133
|
|
|
// $this->setVar('datesub', strtotime(Request::getArray('datesub', array(), 'POST')['date']) + Request::getArray('datesub', array(), 'POST')['time']); |
1134
|
|
|
// } else { |
1135
|
|
|
$resDate = Request::getArray('datesub', [], 'POST'); |
1136
|
|
|
$resTime = Request::getArray('datesub', [], 'POST'); |
1137
|
|
|
$dateTimeObj = \DateTime::createFromFormat(_SHORTDATESTRING, $resDate['date']); |
1138
|
|
|
$dateTimeObj->setTime(0, 0, (int)$resTime['time']); |
1139
|
|
|
$serverTimestamp = \userTimeToServerTime($dateTimeObj->getTimestamp(), $userTimeoffset); |
1140
|
|
|
$this->setVar('datesub', $serverTimestamp); |
1141
|
|
|
// } |
1142
|
|
|
} elseif ($this->isNew()) { |
1143
|
|
|
$this->setVar('datesub', \time()); |
1144
|
|
|
} |
1145
|
|
|
|
1146
|
|
|
// date expire |
1147
|
|
|
if (0 !== Request::getInt('use_expire_yn', 0, 'POST')) { |
1148
|
|
|
if ('' !== Request::getString('dateexpire', '', 'POST')) { |
1149
|
|
|
$resExDate = Request::getArray('dateexpire', [], 'POST'); |
1150
|
|
|
$resExTime = Request::getArray('dateexpire', [], 'POST'); |
1151
|
|
|
$dateTimeObj = \DateTime::createFromFormat(_SHORTDATESTRING, $resExDate['date']); |
1152
|
|
|
$dateTimeObj->setTime(0, 0, (int)$resExTime['time']); |
1153
|
|
|
$serverTimestamp = \userTimeToServerTime($dateTimeObj->getTimestamp(), $userTimeoffset); |
1154
|
|
|
$this->setVar('dateexpire', $serverTimestamp); |
1155
|
|
|
} |
1156
|
|
|
} else { |
1157
|
|
|
$this->setVar('dateexpire', 0); |
1158
|
|
|
} |
1159
|
|
|
|
1160
|
|
|
if ($this->isNew()) { |
1161
|
|
|
$this->setVar('uid', Request::getInt('uid', (\is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->uid() : 0), 'POST')); |
1162
|
|
|
$this->setVar('cancoment', Request::getInt('allowcomments', $this->helper->getConfig('submit_allowcomments'), 'POST')); |
1163
|
|
|
$this->setVar('status', Request::getInt('status', $this->helper->getConfig('submit_status'), 'POST')); |
1164
|
|
|
$this->setVar('dohtml', Request::getInt('dohtml', $this->helper->getConfig('submit_dohtml'), 'POST')); |
1165
|
|
|
$this->setVar('dosmiley', Request::getInt('dosmiley', $this->helper->getConfig('submit_dosmiley'), 'POST')); |
1166
|
|
|
$this->setVar('doxcode', Request::getInt('doxcode', $this->helper->getConfig('submit_doxcode'), 'POST')); |
1167
|
|
|
$this->setVar('doimage', Request::getInt('doimage', $this->helper->getConfig('submit_doimage'), 'POST')); |
1168
|
|
|
$this->setVar('dobr', Request::getInt('dolinebreak', $this->helper->getConfig('submit_dobr'), 'POST')); |
1169
|
|
|
$this->setVar('votetype', Request::getInt('votetype', $this->helper->getConfig('ratingbars'), 'POST')); |
1170
|
|
|
$this->setVar('short_url', Request::getString('item_short_url', '', 'POST')); |
1171
|
|
|
$this->setVar('meta_keywords', Request::getString('item_meta_keywords', '', 'POST')); |
1172
|
|
|
$this->setVar('meta_description', Request::getString('item_meta_description', '', 'POST')); |
1173
|
|
|
$this->setVar('weight', Request::getInt('weight', 0, 'POST')); |
1174
|
|
|
//Not required fields |
1175
|
|
|
$this->setVar('summary', Request::getText('summary', '', 'POST')); |
1176
|
|
|
$this->setVar('subtitle', Request::getString('subtitle', '', 'POST')); |
1177
|
|
|
$this->setVar('item_tag', Request::getString('item_tag', '', 'POST')); |
1178
|
|
|
|
1179
|
|
|
$this->setVar('notifypub', Request::getString('notify', 1, 'POST')); |
1180
|
|
|
} else { |
1181
|
|
|
$this->setVar('uid', Request::getInt('uid', null, 'POST')); |
1182
|
|
|
$this->setVar('cancomment', Request::getInt('allowcomments', null, 'POST')); |
1183
|
|
|
$this->setVar('status', Request::getInt('status', $this->helper->getConfig('submit_edit_status'), 'POST')); |
1184
|
|
|
$this->setVar('dohtml', Request::getInt('dohtml', null, 'POST')); |
1185
|
|
|
$this->setVar('dosmiley', Request::getInt('dosmiley', null, 'POST')); |
1186
|
|
|
$this->setVar('doxcode', Request::getInt('doxcode', null, 'POST')); |
1187
|
|
|
$this->setVar('doimage', Request::getInt('doimage', null, 'POST')); |
1188
|
|
|
$this->setVar('dobr', Request::getInt('dolinebreak', null, 'POST')); |
1189
|
|
|
$this->setVar('votetype', Request::getInt('votetype', null, 'POST')); |
1190
|
|
|
$this->setVar('short_url', Request::getString('item_short_url', $this->getVar('short_url'), 'POST')); |
|
|
|
|
1191
|
|
|
$this->setVar('meta_keywords', Request::getString('item_meta_keywords', $this->getVar('meta_keywords'), 'POST')); |
1192
|
|
|
$this->setVar('meta_description', Request::getString('item_meta_description', $this->getVar('meta_description'), 'POST')); |
1193
|
|
|
$this->setVar('weight', Request::getInt('weight', null, 'POST')); |
1194
|
|
|
//Not required fields |
1195
|
|
|
if (null !== Request::getVar('summary', null, 'POST')) { |
1196
|
|
|
$this->setVar('summary', Request::getText('summary', '', 'POST')); |
1197
|
|
|
} |
1198
|
|
|
$this->setVar('subtitle', Request::getString('subtitle', $this->getVar('subtitle'), 'POST')); |
1199
|
|
|
$this->setVar('item_tag', Request::getString('item_tag', $this->getVar('item_tag'), 'POST')); |
1200
|
|
|
$this->setVar('notifypub', Request::getString('notify', $this->getVar('notifypub'), 'POST')); |
1201
|
|
|
} |
1202
|
|
|
} |
1203
|
|
|
|
1204
|
|
|
public function assignOtherProperties(): void |
1205
|
|
|
{ |
1206
|
|
|
$module = $this->helper->getModule(); |
1207
|
|
|
$module_id = $module->getVar('mid'); |
1208
|
|
|
/** @var \XoopsGroupPermHandler $grouppermHandler */ |
1209
|
|
|
$grouppermHandler = \xoops_getHandler('groupperm'); |
1210
|
|
|
|
1211
|
|
|
$this->category = $this->helper->getHandler('Category') |
1212
|
|
|
->get($this->getVar('categoryid')); |
1213
|
|
|
$this->groups_read = $grouppermHandler->getGroupIds('item_read', $this->itemid(), $module_id); |
|
|
|
|
1214
|
|
|
} |
1215
|
|
|
} |
1216
|
|
|
|