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