|
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
|
|
|
use Images; |
|
16
|
|
|
use Notifications; |
|
17
|
|
|
use Xmf\Highlighter; |
|
18
|
|
|
use Xmf\Request; |
|
19
|
|
|
use Xoops; |
|
20
|
|
|
use Xoops\Core\Kernel\Criteria; |
|
21
|
|
|
use Xoops\Core\Kernel\CriteriaCompo; |
|
22
|
|
|
use Xoops\Core\Kernel\XoopsObject; |
|
23
|
|
|
use Xoops\Core\Text\Sanitizer; |
|
24
|
|
|
use XoopsBaseConfig; |
|
25
|
|
|
use XoopsLoad; |
|
26
|
|
|
use XoopsLocale; |
|
27
|
|
|
use XoopsModules\Publisher; |
|
28
|
|
|
use XoopsUserUtility; |
|
29
|
|
|
use Doctrine\DBAL\FetchMode; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @copyright The XUUPS Project http://sourceforge.net/projects/xuups/ |
|
33
|
|
|
* @license GNU GPL V2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
|
34
|
|
|
* @package Publisher |
|
35
|
|
|
* @since 1.0 |
|
36
|
|
|
* @author trabis <[email protected]> |
|
37
|
|
|
* @author The SmartFactory <www.smartfactory.ca> |
|
38
|
|
|
* @version $Id$ |
|
39
|
|
|
*/ |
|
40
|
|
|
require_once \dirname(__DIR__) . '/include/common.php'; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Class Item |
|
44
|
|
|
* @package XoopsModules\Publisher |
|
45
|
|
|
*/ |
|
46
|
|
|
class Item extends XoopsObject |
|
47
|
|
|
{ |
|
48
|
|
|
/** |
|
49
|
|
|
* @var Helper |
|
50
|
|
|
* @access public |
|
51
|
|
|
*/ |
|
52
|
|
|
public $helper = null; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var Publisher\Category |
|
56
|
|
|
* @access public |
|
57
|
|
|
*/ |
|
58
|
|
|
public $_category = null; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param int|null $id |
|
62
|
|
|
*/ |
|
63
|
|
|
public function __construct($id = null) |
|
64
|
|
|
{ |
|
65
|
|
|
$this->helper = Helper::getInstance(); |
|
66
|
|
|
$this->initVar('itemid', \XOBJ_DTYPE_INT, 0); |
|
67
|
|
|
$this->initVar('categoryid', \XOBJ_DTYPE_INT, 0, false); |
|
68
|
|
|
$this->initVar('title', \XOBJ_DTYPE_TXTBOX, '', true, 255); |
|
69
|
|
|
$this->initVar('subtitle', \XOBJ_DTYPE_TXTBOX, '', false, 255); |
|
70
|
|
|
$this->initVar('summary', \XOBJ_DTYPE_TXTAREA, '', false); |
|
71
|
|
|
$this->initVar('body', \XOBJ_DTYPE_TXTAREA, '', false); |
|
72
|
|
|
$this->initVar('uid', \XOBJ_DTYPE_INT, 0, false); |
|
73
|
|
|
$this->initVar('author_alias', \XOBJ_DTYPE_TXTBOX, '', false, 255); |
|
74
|
|
|
$this->initVar('datesub', \XOBJ_DTYPE_INT, '', false); |
|
75
|
|
|
$this->initVar('status', \XOBJ_DTYPE_INT, -1, false); |
|
76
|
|
|
$this->initVar('image', \XOBJ_DTYPE_INT, 0, false); |
|
77
|
|
|
$this->initVar('images', \XOBJ_DTYPE_TXTBOX, '', false, 255); |
|
78
|
|
|
$this->initVar('counter', \XOBJ_DTYPE_INT, 0, false); |
|
79
|
|
|
$this->initVar('rating', \XOBJ_DTYPE_OTHER, 0, false); |
|
80
|
|
|
$this->initVar('votes', \XOBJ_DTYPE_INT, 0, false); |
|
81
|
|
|
$this->initVar('weight', \XOBJ_DTYPE_INT, 0, false); |
|
82
|
|
|
$this->initVar('dohtml', \XOBJ_DTYPE_INT, 1, true); |
|
83
|
|
|
$this->initVar('dosmiley', \XOBJ_DTYPE_INT, 1, true); |
|
84
|
|
|
$this->initVar('doimage', \XOBJ_DTYPE_INT, 1, true); |
|
85
|
|
|
$this->initVar('dobr', \XOBJ_DTYPE_INT, 1, false); |
|
86
|
|
|
$this->initVar('doxcode', \XOBJ_DTYPE_INT, 1, true); |
|
87
|
|
|
$this->initVar('cancomment', \XOBJ_DTYPE_INT, 1, true); |
|
88
|
|
|
$this->initVar('comments', \XOBJ_DTYPE_INT, 0, false); |
|
89
|
|
|
$this->initVar('notifypub', \XOBJ_DTYPE_INT, 1, false); |
|
90
|
|
|
$this->initVar('meta_keywords', \XOBJ_DTYPE_TXTAREA, '', false); |
|
91
|
|
|
$this->initVar('meta_description', \XOBJ_DTYPE_TXTAREA, '', false); |
|
92
|
|
|
$this->initVar('short_url', \XOBJ_DTYPE_TXTBOX, '', false, 255); |
|
93
|
|
|
$this->initVar('item_tag', \XOBJ_DTYPE_TXTAREA, '', false); |
|
94
|
|
|
// Non consistent values |
|
95
|
|
|
$this->initVar('pagescount', \XOBJ_DTYPE_INT, 0, false); |
|
96
|
|
|
if (isset($id)) { |
|
97
|
|
|
$item = $this->helper->getItemHandler()->get($id); |
|
98
|
|
|
foreach ($item->vars as $k => $v) { |
|
99
|
|
|
$this->assignVar($k, $v['value']); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @return null|Publisher\Category |
|
106
|
|
|
*/ |
|
107
|
|
|
public function category(): ?Category |
|
108
|
|
|
{ |
|
109
|
|
|
if (!isset($this->_category)) { |
|
110
|
|
|
$this->_category = $this->helper->getCategoryHandler()->get($this->getVar('categoryid')); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
return $this->_category; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @param int $maxLength |
|
118
|
|
|
* @param string $format |
|
119
|
|
|
*/ |
|
120
|
|
|
public function title($maxLength = 0, $format = 'S'): string |
|
121
|
|
|
{ |
|
122
|
|
|
$ret = $this->getVar('title', $format); |
|
123
|
|
|
if (0 != $maxLength) { |
|
124
|
|
|
if (!XoopsLocale::isMultiByte()) { |
|
|
|
|
|
|
125
|
|
|
if (\mb_strlen($ret) >= $maxLength) { |
|
|
|
|
|
|
126
|
|
|
$ret = Publisher\Utils::substr($ret, 0, $maxLength); |
|
|
|
|
|
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
return $ret; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @param int $maxLength |
|
136
|
|
|
* @param string $format |
|
137
|
|
|
* |
|
138
|
|
|
* @return mixed|string |
|
139
|
|
|
*/ |
|
140
|
|
|
public function subtitle($maxLength = 0, $format = 'S') |
|
141
|
|
|
{ |
|
142
|
|
|
$ret = $this->getVar('subtitle', $format); |
|
143
|
|
|
if (0 != $maxLength) { |
|
144
|
|
|
if (!XoopsLocale::isMultiByte()) { |
|
|
|
|
|
|
145
|
|
|
if (\mb_strlen($ret) >= $maxLength) { |
|
|
|
|
|
|
146
|
|
|
$ret = Publisher\Utils::substr($ret, 0, $maxLength); |
|
|
|
|
|
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
return $ret; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @param int $maxLength |
|
156
|
|
|
* @param string $format |
|
157
|
|
|
* @param string $stripTags |
|
158
|
|
|
* |
|
159
|
|
|
* @return mixed|string |
|
160
|
|
|
*/ |
|
161
|
|
|
public function summary($maxLength = 0, $format = 'S', $stripTags = '') |
|
162
|
|
|
{ |
|
163
|
|
|
$ret = $this->getVar('summary', $format); |
|
164
|
|
|
if (!empty($stripTags)) { |
|
165
|
|
|
$ret = \strip_tags($ret, $stripTags); |
|
|
|
|
|
|
166
|
|
|
} |
|
167
|
|
|
if (0 != $maxLength) { |
|
168
|
|
|
if (!XoopsLocale::isMultiByte()) { |
|
|
|
|
|
|
169
|
|
|
if (\mb_strlen($ret) >= $maxLength) { |
|
170
|
|
|
//$ret = Publisher\Utils::substr($ret , 0, $maxLength); |
|
171
|
|
|
$ret = Publisher\Utils::truncateTagSafe($ret, $maxLength, $etc = '...', $break_words = false); |
|
172
|
|
|
} |
|
173
|
|
|
} |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
return $ret; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* @param int $maxLength |
|
181
|
|
|
* @param bool $fullSummary |
|
182
|
|
|
* |
|
183
|
|
|
* @return mixed|string |
|
184
|
|
|
*/ |
|
185
|
|
|
public function getBlockSummary($maxLength = 0, $fullSummary = false) |
|
186
|
|
|
{ |
|
187
|
|
|
if ($fullSummary) { |
|
188
|
|
|
$ret = $this->summary(0, 's', '<br><br>'); |
|
189
|
|
|
} else { |
|
190
|
|
|
$ret = $this->summary($maxLength, 's', '<br><br>'); |
|
191
|
|
|
} |
|
192
|
|
|
//no summary? get body! |
|
193
|
|
|
if ('' == $ret) { |
|
194
|
|
|
$ret = $this->body($maxLength, 's', '<br><br>'); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
return $ret; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* @param string $file_name |
|
202
|
|
|
*/ |
|
203
|
|
|
public function wrappage($file_name): string |
|
204
|
|
|
{ |
|
205
|
|
|
$content = ''; |
|
206
|
|
|
$page = Publisher\Utils::getUploadDir(true, 'content') . $file_name; |
|
207
|
|
|
if (XoopsLoad::fileExists($page)) { |
|
208
|
|
|
// this page uses smarty template |
|
209
|
|
|
\ob_start(); |
|
210
|
|
|
include $page; |
|
211
|
|
|
$content = \ob_get_clean(); |
|
212
|
|
|
// Cleaning the content |
|
213
|
|
|
$body_start_pos = \mb_strpos($content, '<body>'); |
|
214
|
|
|
if ($body_start_pos) { |
|
215
|
|
|
$body_end_pos = \mb_strpos($content, '</body>', $body_start_pos); |
|
216
|
|
|
$content = \mb_substr($content, $body_start_pos + \mb_strlen('<body>'), $body_end_pos - \mb_strlen('<body>') - $body_start_pos); |
|
217
|
|
|
} |
|
218
|
|
|
// Check if ML Hack is installed, and if yes, parse the $content in formatForML |
|
219
|
|
|
$myts = Sanitizer::getInstance(); |
|
220
|
|
|
if (\method_exists($myts, 'formatForML')) { |
|
221
|
|
|
$content = $myts->formatForML($content); |
|
222
|
|
|
} |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
return $content; |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* This method returns the body to be displayed. Not to be used for editing |
|
230
|
|
|
* |
|
231
|
|
|
* @param int $maxLength |
|
232
|
|
|
* @param string $format |
|
233
|
|
|
* @param string $stripTags |
|
234
|
|
|
* |
|
235
|
|
|
* @return mixed|string |
|
236
|
|
|
*/ |
|
237
|
|
|
public function body($maxLength = 0, $format = 'S', $stripTags = '') |
|
238
|
|
|
{ |
|
239
|
|
|
$ret = $this->getVar('body', $format); |
|
240
|
|
|
$wrap_pos = \mb_strpos($ret, '[pagewrap='); |
|
|
|
|
|
|
241
|
|
|
if (!(false === $wrap_pos)) { |
|
242
|
|
|
$wrap_pages = []; |
|
243
|
|
|
$wrap_code_length = \mb_strlen('[pagewrap='); |
|
244
|
|
|
while (!(false === $wrap_pos)) { |
|
245
|
|
|
$end_wrap_pos = \mb_strpos($ret, ']', $wrap_pos); |
|
246
|
|
|
if ($end_wrap_pos) { |
|
247
|
|
|
$wrap_page_name = \mb_substr($ret, $wrap_pos + $wrap_code_length, $end_wrap_pos - $wrap_code_length - $wrap_pos); |
|
|
|
|
|
|
248
|
|
|
$wrap_pages[] = $wrap_page_name; |
|
249
|
|
|
} |
|
250
|
|
|
$wrap_pos = \mb_strpos($ret, '[pagewrap=', $end_wrap_pos - 1); |
|
251
|
|
|
} |
|
252
|
|
|
foreach ($wrap_pages as $page) { |
|
253
|
|
|
$wrap_page_content = $this->wrappage($page); |
|
254
|
|
|
$ret = \str_replace("[pagewrap={$page}]", $wrap_page_content, $ret); |
|
255
|
|
|
} |
|
256
|
|
|
} |
|
257
|
|
|
if ($this->helper->getConfig('item_disp_blocks_summary')) { |
|
258
|
|
|
$summary = $this->summary($maxLength, $format, $stripTags); |
|
259
|
|
|
if ($summary) { |
|
260
|
|
|
$ret = $this->summary() . '<br><br>' . $ret; |
|
261
|
|
|
} |
|
262
|
|
|
} |
|
263
|
|
|
if (!empty($stripTags)) { |
|
264
|
|
|
$ret = \strip_tags($ret, $stripTags); |
|
265
|
|
|
} |
|
266
|
|
|
if (0 != $maxLength) { |
|
267
|
|
|
if (!XoopsLocale::isMultiByte()) { |
|
|
|
|
|
|
268
|
|
|
if (\mb_strlen($ret) >= $maxLength) { |
|
269
|
|
|
//$ret = Publisher\Utils::substr($ret , 0, $maxLength); |
|
270
|
|
|
$ret = Publisher\Utils::truncateTagSafe($ret, $maxLength, $etc = '...', $break_words = false); |
|
271
|
|
|
} |
|
272
|
|
|
} |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
return $ret; |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
/** |
|
279
|
|
|
* @param string $dateFormat |
|
280
|
|
|
* @param string $format |
|
281
|
|
|
*/ |
|
282
|
|
|
public function datesub($dateFormat = '', $format = 'S'): string |
|
283
|
|
|
{ |
|
284
|
|
|
if (empty($dateformat)) { |
|
|
|
|
|
|
285
|
|
|
$dateFormat = $this->helper->getConfig('format_date'); |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
return XoopsLocale::formatTimestamp($this->getVar('datesub', $format), $dateFormat); |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
|
|
/** |
|
292
|
|
|
* @param int $realName |
|
293
|
|
|
*/ |
|
294
|
|
|
public function posterName($realName = -1): string |
|
295
|
|
|
{ |
|
296
|
|
|
if (-1 == $realName) { |
|
297
|
|
|
$realName = $this->helper->getConfig('format_realname'); |
|
298
|
|
|
} |
|
299
|
|
|
$ret = $this->getVar('author_alias'); |
|
300
|
|
|
if ('' == $ret) { |
|
301
|
|
|
$ret = XoopsUserUtility::getUnameFromId($this->getVar('uid'), $realName); |
|
302
|
|
|
} |
|
303
|
|
|
|
|
304
|
|
|
return $ret; |
|
305
|
|
|
} |
|
306
|
|
|
|
|
307
|
|
|
public function posterAvatar(): string |
|
308
|
|
|
{ |
|
309
|
|
|
$xoops = Xoops::getInstance(); |
|
310
|
|
|
$ret = 'blank.gif'; |
|
311
|
|
|
$memberHandler = $xoops->getHandlerMember(); |
|
312
|
|
|
$thisUser = $memberHandler->getUser($this->getVar('uid')); |
|
313
|
|
|
if (\is_object($thisUser)) { |
|
314
|
|
|
$ret = $xoops->service('avatar')->getAvatarUrl($thisUser)->getValue(); |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
return $ret; |
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
|
|
public function linkedPosterName(): string |
|
321
|
|
|
{ |
|
322
|
|
|
$ret = $this->getVar('author_alias'); |
|
323
|
|
|
if ('' == $ret) { |
|
324
|
|
|
$ret = XoopsUserUtility::getUnameFromId($this->getVar('uid'), $this->helper->getConfig('format_realname'), true); |
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
return $ret; |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
/** |
|
331
|
|
|
* @return mixed |
|
332
|
|
|
*/ |
|
333
|
|
|
public function updateCounter() |
|
334
|
|
|
{ |
|
335
|
|
|
return $this->helper->getItemHandler()->updateCounter($this->getVar('itemid')); |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
/** |
|
339
|
|
|
* @param bool $force |
|
340
|
|
|
*/ |
|
341
|
|
|
public function store($force = true): bool |
|
342
|
|
|
{ |
|
343
|
|
|
$xoops = Xoops::getInstance(); |
|
344
|
|
|
$isNew = $this->isNew(); |
|
345
|
|
|
if (!$this->helper->getItemHandler()->insert($this, $force)) { |
|
346
|
|
|
return false; |
|
347
|
|
|
} |
|
348
|
|
|
if ($isNew && \_PUBLISHER_STATUS_PUBLISHED == $this->getVar('status')) { |
|
349
|
|
|
// Increment user posts |
|
350
|
|
|
$userHandler = $xoops->getHandlerUser(); |
|
351
|
|
|
$memberHandler = $xoops->getHandlerMember(); |
|
352
|
|
|
$poster = $userHandler->get($this->getVar('uid')); |
|
353
|
|
|
if (\is_object($poster) && !$poster->isNew()) { |
|
354
|
|
|
$poster->setVar('posts', $poster->getVar('posts') + 1); |
|
355
|
|
|
if (!$memberHandler->insertUser($poster, true)) { |
|
356
|
|
|
$this->setErrors('Article created but could not increment user posts.'); |
|
357
|
|
|
|
|
358
|
|
|
return false; |
|
359
|
|
|
} |
|
360
|
|
|
} |
|
361
|
|
|
} |
|
362
|
|
|
|
|
363
|
|
|
return true; |
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
|
|
public function getCategoryName(): string |
|
367
|
|
|
{ |
|
368
|
|
|
return $this->category()->getVar('name'); |
|
|
|
|
|
|
369
|
|
|
} |
|
370
|
|
|
|
|
371
|
|
|
public function getCategoryUrl(): string |
|
372
|
|
|
{ |
|
373
|
|
|
return $this->category()->getCategoryUrl(); |
|
374
|
|
|
} |
|
375
|
|
|
|
|
376
|
|
|
public function getCategoryLink(): string |
|
377
|
|
|
{ |
|
378
|
|
|
return $this->category()->getCategoryLink(); |
|
379
|
|
|
} |
|
380
|
|
|
|
|
381
|
|
|
/** |
|
382
|
|
|
* @param bool $withAllLink |
|
383
|
|
|
*/ |
|
384
|
|
|
public function getCategoryPath($withAllLink = true): string |
|
385
|
|
|
{ |
|
386
|
|
|
return $this->category()->getCategoryPath($withAllLink); |
|
|
|
|
|
|
387
|
|
|
} |
|
388
|
|
|
|
|
389
|
|
|
public function getCategoryImagePath(): string |
|
390
|
|
|
{ |
|
391
|
|
|
return Publisher\Utils::getImageDir('category', false) . $this->category()->image(); |
|
392
|
|
|
} |
|
393
|
|
|
|
|
394
|
|
|
/** |
|
395
|
|
|
* @return mixed |
|
396
|
|
|
*/ |
|
397
|
|
|
public function getFiles() |
|
398
|
|
|
{ |
|
399
|
|
|
return $this->helper->getFileHandler()->getAllFiles($this->getVar('itemid'), _PUBLISHER_STATUS_FILE_ACTIVE); |
|
400
|
|
|
} |
|
401
|
|
|
|
|
402
|
|
|
public function getAdminLinks(): string |
|
403
|
|
|
{ |
|
404
|
|
|
$xoops = Xoops::getInstance(); |
|
405
|
|
|
$adminLinks = ''; |
|
406
|
|
|
if ($xoops->isUser() && (Publisher\Utils::IsUserAdmin() || Publisher\Utils::IsUserAuthor($this) || $this->helper->getPermissionHandler()->isGranted('item_submit', $this->getVar('categoryid')))) { |
|
407
|
|
|
if (Publisher\Utils::IsUserAdmin() || Publisher\Utils::IsUserAuthor($this) || Publisher\Utils::IsUserModerator($this)) { |
|
408
|
|
|
if ($this->helper->getConfig('perm_edit') || Publisher\Utils::IsUserModerator($this) || Publisher\Utils::IsUserAdmin()) { |
|
409
|
|
|
// Edit button |
|
410
|
|
|
$adminLinks .= "<a href='" . \PUBLISHER_URL . '/submit.php?itemid=' . $this->getVar('itemid') . "'><img src='" . \PUBLISHER_URL . "/images/links/edit.gif'" . " title='" . _CO_PUBLISHER_EDIT . "' alt='" . _CO_PUBLISHER_EDIT . "'></a>"; |
|
411
|
|
|
$adminLinks .= ' '; |
|
412
|
|
|
} |
|
413
|
|
|
if ($this->helper->getConfig('perm_delete') || Publisher\Utils::IsUserModerator($this) || Publisher\Utils::IsUserAdmin()) { |
|
414
|
|
|
// Delete button |
|
415
|
|
|
$adminLinks .= "<a href='" . \PUBLISHER_URL . '/submit.php?op=del&itemid=' . $this->getVar('itemid') . "'><img src='" . \PUBLISHER_URL . "/images/links/delete.png'" . " title='" . _CO_PUBLISHER_DELETE . "' alt='" . _CO_PUBLISHER_DELETE . "'></a>"; |
|
416
|
|
|
$adminLinks .= ' '; |
|
417
|
|
|
} |
|
418
|
|
|
} |
|
419
|
|
|
if ($this->helper->getConfig('perm_clone') || Publisher\Utils::IsUserModerator($this) || Publisher\Utils::IsUserAdmin()) { |
|
420
|
|
|
// Duplicate button |
|
421
|
|
|
$adminLinks .= "<a href='" . \PUBLISHER_URL . '/submit.php?op=clone&itemid=' . $this->getVar('itemid') . "'><img src='" . \PUBLISHER_URL . "/images/links/clone.gif'" . " title='" . _CO_PUBLISHER_CLONE . "' alt='" . _CO_PUBLISHER_CLONE . "'></a>"; |
|
422
|
|
|
$adminLinks .= ' '; |
|
423
|
|
|
} |
|
424
|
|
|
} |
|
425
|
|
|
// PDF button |
|
426
|
|
|
if ($xoops->service('htmltopdf')->isAvailable()) { |
|
427
|
|
|
$adminLinks .= "<a href='" . \PUBLISHER_URL . '/makepdf.php?itemid=' . $this->getVar('itemid') . "' rel='nofollow' target='_blank'><img src='" . \PUBLISHER_URL . "/images/links/pdf.gif' title='" . _CO_PUBLISHER_PDF . "' alt='" . _CO_PUBLISHER_PDF . "'></a>"; |
|
428
|
|
|
$adminLinks .= ' '; |
|
429
|
|
|
} |
|
430
|
|
|
// Print button |
|
431
|
|
|
$adminLinks .= "<a href='" . Publisher\Utils::seoGenUrl('print', $this->getVar('itemid'), $this->getVar('short_url')) . "' rel='nofollow' target='_blank'><img src='" . \PUBLISHER_URL . "/images/links/print.gif' title='" . _CO_PUBLISHER_PRINT . "' alt='" . _CO_PUBLISHER_PRINT . "'></a>"; |
|
432
|
|
|
$adminLinks .= ' '; |
|
433
|
|
|
// Email button |
|
434
|
|
|
if ($xoops->isActiveModule('tellafriend')) { |
|
435
|
|
|
$subject = \sprintf(_CO_PUBLISHER_INTITEMFOUND, $xoops->getConfig('sitename')); |
|
436
|
|
|
$subject = $this->_convert_for_japanese($subject); |
|
437
|
|
|
$maillink = Publisher\Utils::tellafriend($subject); |
|
438
|
|
|
$adminLinks .= '<a href="' . $maillink . '"><img src="' . \PUBLISHER_URL . '/images/links/friend.gif" title="' . _CO_PUBLISHER_MAIL . '" alt="' . _CO_PUBLISHER_MAIL . '"></a>'; |
|
439
|
|
|
$adminLinks .= ' '; |
|
440
|
|
|
} |
|
441
|
|
|
|
|
442
|
|
|
return $adminLinks; |
|
443
|
|
|
} |
|
444
|
|
|
|
|
445
|
|
|
/** |
|
446
|
|
|
* @param array $notifications |
|
447
|
|
|
*/ |
|
448
|
|
|
public function sendNotifications($notifications = []): void |
|
449
|
|
|
{ |
|
450
|
|
|
$xoops = Xoops::getInstance(); |
|
451
|
|
|
if ($xoops->isActiveModule('notifications')) { |
|
452
|
|
|
$notificationHandler = Notifications::getInstance()->getHandlerNotification(); |
|
453
|
|
|
$tags = []; |
|
454
|
|
|
$tags['MODULE_NAME'] = $this->helper->getModule()->getVar('name'); |
|
455
|
|
|
$tags['ITEM_NAME'] = $this->title(); |
|
456
|
|
|
$tags['CATEGORY_NAME'] = $this->getCategoryName(); |
|
457
|
|
|
$tags['CATEGORY_URL'] = \PUBLISHER_URL . '/category.php?categoryid=' . $this->getVar('categoryid'); |
|
458
|
|
|
$tags['ITEM_BODY'] = $this->body(); |
|
459
|
|
|
$tags['DATESUB'] = $this->datesub(); |
|
460
|
|
|
foreach ($notifications as $notification) { |
|
461
|
|
|
switch ($notification) { |
|
462
|
|
|
case \_PUBLISHER_NOT_ITEM_PUBLISHED: |
|
463
|
|
|
$tags['ITEM_URL'] = \PUBLISHER_URL . '/item.php?itemid=' . $this->getVar('itemid'); |
|
464
|
|
|
$notificationHandler->triggerEvent('global', 0, 'published', $tags, [], $this->helper->getModule()->getVar('mid')); |
|
465
|
|
|
$notificationHandler->triggerEvent('category', $this->getVar('categoryid'), 'published', $tags, [], $this->helper->getModule()->getVar('mid')); |
|
466
|
|
|
$notificationHandler->triggerEvent('item', $this->getVar('itemid'), 'approved', $tags, [], $this->helper->getModule()->getVar('mid')); |
|
467
|
|
|
break; |
|
468
|
|
|
case \_PUBLISHER_NOT_ITEM_SUBMITTED: |
|
469
|
|
|
$tags['WAITINGFILES_URL'] = \PUBLISHER_URL . '/admin/item.php?itemid=' . $this->getVar('itemid'); |
|
470
|
|
|
$notificationHandler->triggerEvent('global', 0, 'submitted', $tags, [], $this->helper->getModule()->getVar('mid')); |
|
471
|
|
|
$notificationHandler->triggerEvent('category', $this->getVar('categoryid'), 'submitted', $tags, [], $this->helper->getModule()->getVar('mid')); |
|
472
|
|
|
break; |
|
473
|
|
|
case \_PUBLISHER_NOT_ITEM_REJECTED: |
|
474
|
|
|
$notificationHandler->triggerEvent('item', $this->getVar('itemid'), 'rejected', $tags, [], $this->helper->getModule()->getVar('mid')); |
|
475
|
|
|
break; |
|
476
|
|
|
case -1: |
|
477
|
|
|
default: |
|
478
|
|
|
break; |
|
479
|
|
|
} |
|
480
|
|
|
} |
|
481
|
|
|
} |
|
482
|
|
|
} |
|
483
|
|
|
|
|
484
|
|
|
public function notLoaded(): bool |
|
485
|
|
|
{ |
|
486
|
|
|
return -1 == $this->getVar('itemid'); |
|
487
|
|
|
} |
|
488
|
|
|
|
|
489
|
|
|
public function getItemUrl(): string |
|
490
|
|
|
{ |
|
491
|
|
|
return Publisher\Utils::seoGenUrl('item', $this->getVar('itemid'), $this->getVar('short_url')); |
|
|
|
|
|
|
492
|
|
|
} |
|
493
|
|
|
|
|
494
|
|
|
/** |
|
495
|
|
|
* @param bool $class |
|
496
|
|
|
* @param int $maxsize |
|
497
|
|
|
* |
|
498
|
|
|
* @return string |
|
499
|
|
|
*/ |
|
500
|
|
|
public function getItemLink($class = false, $maxsize = 0): ?string |
|
501
|
|
|
{ |
|
502
|
|
|
if ($class) { |
|
503
|
|
|
return '<a class=' . $class . ' href="' . $this->getItemUrl() . '">' . $this->title($maxsize) . '</a>'; |
|
|
|
|
|
|
504
|
|
|
} |
|
505
|
|
|
|
|
506
|
|
|
return '<a href="' . $this->getItemUrl() . '">' . $this->title($maxsize) . '</a>'; |
|
507
|
|
|
} |
|
508
|
|
|
|
|
509
|
|
|
public function getWhoAndWhen(): string |
|
510
|
|
|
{ |
|
511
|
|
|
$posterName = $this->linkedPosterName(); |
|
512
|
|
|
$postdate = $this->datesub(); |
|
513
|
|
|
|
|
514
|
|
|
return \sprintf(_CO_PUBLISHER_POSTEDBY, $posterName, $postdate); |
|
515
|
|
|
} |
|
516
|
|
|
|
|
517
|
|
|
/** |
|
518
|
|
|
* @param null|string $body |
|
519
|
|
|
*/ |
|
520
|
|
|
public function plain_maintext($body = null): string |
|
521
|
|
|
{ |
|
522
|
|
|
$ret = ''; |
|
523
|
|
|
if (!$body) { |
|
524
|
|
|
$body = $this->body(); |
|
525
|
|
|
} |
|
526
|
|
|
$ret .= \str_replace('[pagebreak]', '<br><br>', $body); |
|
527
|
|
|
|
|
528
|
|
|
return $ret; |
|
529
|
|
|
} |
|
530
|
|
|
|
|
531
|
|
|
/** |
|
532
|
|
|
* @param int $item_page_id |
|
533
|
|
|
* @param null|string $body |
|
534
|
|
|
*/ |
|
535
|
|
|
public function buildmaintext($item_page_id = -1, $body = null): string |
|
536
|
|
|
{ |
|
537
|
|
|
if (!$body) { |
|
538
|
|
|
$body = $this->body(); |
|
539
|
|
|
} |
|
540
|
|
|
$body_parts = \explode('[pagebreak]', $body); |
|
541
|
|
|
$this->setVar('pagescount', \count($body_parts)); |
|
542
|
|
|
if (\count($body_parts) <= 1) { |
|
543
|
|
|
return $this->plain_maintext($body); |
|
544
|
|
|
} |
|
545
|
|
|
$ret = ''; |
|
546
|
|
|
if (-1 == $item_page_id) { |
|
547
|
|
|
$ret .= \trim($body_parts[0]); |
|
548
|
|
|
|
|
549
|
|
|
return $ret; |
|
550
|
|
|
} |
|
551
|
|
|
if ($item_page_id >= \count($body_parts)) { |
|
552
|
|
|
$item_page_id = \count($body_parts) - 1; |
|
553
|
|
|
} |
|
554
|
|
|
$ret .= \trim($body_parts[$item_page_id]); |
|
555
|
|
|
|
|
556
|
|
|
return $ret; |
|
557
|
|
|
} |
|
558
|
|
|
|
|
559
|
|
|
/** |
|
560
|
|
|
* @return mixed |
|
561
|
|
|
*/ |
|
562
|
|
|
public function getImages() |
|
563
|
|
|
{ |
|
564
|
|
|
static $ret; |
|
565
|
|
|
|
|
566
|
|
|
$xoops = Xoops::getInstance(); |
|
567
|
|
|
if (!$xoops->isActiveModule('images')) { |
|
568
|
|
|
return []; |
|
569
|
|
|
} |
|
570
|
|
|
$itemid = $this->getVar('itemid'); |
|
571
|
|
|
if (!isset($ret[$itemid])) { |
|
572
|
|
|
$ret[$itemid]['main'] = ''; |
|
573
|
|
|
$ret[$itemid]['others'] = []; |
|
574
|
|
|
$images_ids = []; |
|
575
|
|
|
$image = $this->getVar('image'); |
|
576
|
|
|
$images = $this->getVar('images'); |
|
577
|
|
|
if ('' != $images) { |
|
578
|
|
|
$images_ids = \explode('|', $images); |
|
|
|
|
|
|
579
|
|
|
} |
|
580
|
|
|
if ($image > 0) { |
|
581
|
|
|
$images_ids[] = $image; |
|
582
|
|
|
} |
|
583
|
|
|
$imageObjs = []; |
|
584
|
|
|
if (\count($images_ids) > 0) { |
|
585
|
|
|
$imageHandler = Images::getInstance()->getHandlerImages(); |
|
586
|
|
|
$criteria = new CriteriaCompo(new Criteria('image_id', '(' . \implode(',', $images_ids) . ')', 'IN')); |
|
587
|
|
|
$imageObjs = $imageHandler->getObjects($criteria, true); |
|
588
|
|
|
unset($criteria); |
|
589
|
|
|
} |
|
590
|
|
|
foreach ($imageObjs as $id => $imageObj) { |
|
591
|
|
|
if ($id == $image) { |
|
592
|
|
|
$ret[$itemid]['main'] = $imageObj; |
|
593
|
|
|
} else { |
|
594
|
|
|
$ret[$itemid]['others'][] = $imageObj; |
|
595
|
|
|
} |
|
596
|
|
|
unset($imageObj); |
|
597
|
|
|
} |
|
598
|
|
|
unset($imageObjs); |
|
599
|
|
|
} |
|
600
|
|
|
|
|
601
|
|
|
return $ret[$itemid]; |
|
602
|
|
|
} |
|
603
|
|
|
|
|
604
|
|
|
/** |
|
605
|
|
|
* @param string $display |
|
606
|
|
|
* @param int $max_char_title |
|
607
|
|
|
* @param int $max_char_summary |
|
608
|
|
|
* @param bool $full_summary |
|
609
|
|
|
* |
|
610
|
|
|
* @return array |
|
611
|
|
|
*/ |
|
612
|
|
|
public function toArray($display = 'default', $max_char_title = 0, $max_char_summary = 0, $full_summary = false) |
|
|
|
|
|
|
613
|
|
|
{ |
|
614
|
|
|
$item_page_id = -1; |
|
615
|
|
|
if (\is_numeric($display)) { |
|
616
|
|
|
$item_page_id = $display; |
|
617
|
|
|
$display = 'all'; |
|
618
|
|
|
} |
|
619
|
|
|
$item['itemid'] = $this->getVar('itemid'); |
|
|
|
|
|
|
620
|
|
|
$item['uid'] = $this->getVar('uid'); |
|
621
|
|
|
$item['titlelink'] = $this->getItemLink(false, $max_char_title); |
|
622
|
|
|
$item['subtitle'] = $this->subtitle(); |
|
623
|
|
|
$item['datesub'] = $this->datesub(); |
|
624
|
|
|
$item['counter'] = $this->getVar('counter'); |
|
625
|
|
|
switch ($display) { |
|
626
|
|
|
case 'summary': |
|
627
|
|
|
case 'list': |
|
628
|
|
|
break; |
|
629
|
|
|
case 'full': |
|
630
|
|
|
case 'wfsection': |
|
631
|
|
|
case 'default': |
|
632
|
|
|
$summary = $this->summary($max_char_summary); |
|
633
|
|
|
if (!$summary) { |
|
634
|
|
|
$summary = $this->body($max_char_summary); |
|
635
|
|
|
} |
|
636
|
|
|
$item['summary'] = $summary; |
|
637
|
|
|
$item = $this->toArrayFull($item); |
|
638
|
|
|
break; |
|
639
|
|
|
case 'all': |
|
640
|
|
|
$item = $this->toArrayFull($item); |
|
641
|
|
|
$item = $this->toArrayAll($item, $item_page_id); |
|
642
|
|
|
break; |
|
643
|
|
|
} |
|
644
|
|
|
// Highlighting searched words |
|
645
|
|
|
$highlight = true; |
|
646
|
|
|
if ($highlight && isset($_GET['keywords'])) { |
|
647
|
|
|
$myts = Sanitizer::getInstance(); |
|
648
|
|
|
$keywords = $myts->htmlSpecialChars(\trim(\urldecode($_GET['keywords']))); |
|
649
|
|
|
$fields = ['title', 'maintext', 'summary']; |
|
650
|
|
|
foreach ($fields as $field) { |
|
651
|
|
|
if (isset($item[$field])) { |
|
652
|
|
|
$item[$field] = $this->highlight($item[$field], $keywords); |
|
653
|
|
|
} |
|
654
|
|
|
} |
|
655
|
|
|
} |
|
656
|
|
|
|
|
657
|
|
|
return $item; |
|
658
|
|
|
} |
|
659
|
|
|
|
|
660
|
|
|
/** |
|
661
|
|
|
* @param array $item |
|
662
|
|
|
*/ |
|
663
|
|
|
public function toArrayFull($item): array |
|
664
|
|
|
{ |
|
665
|
|
|
$item['title'] = $this->title(); |
|
666
|
|
|
$item['clean_title'] = $this->title(); |
|
667
|
|
|
$item['itemurl'] = $this->getItemUrl(); |
|
668
|
|
|
$item['cancomment'] = $this->getVar('cancomment'); |
|
669
|
|
|
$item['comments'] = $this->getVar('comments'); |
|
670
|
|
|
$item['adminlink'] = $this->getAdminLinks(); |
|
671
|
|
|
$item['categoryPath'] = $this->getCategoryPath($this->helper->getConfig('format_linked_path')); |
|
672
|
|
|
$item['who_when'] = $this->getWhoAndWhen(); |
|
673
|
|
|
$item = $this->getMainImage($item); |
|
674
|
|
|
|
|
675
|
|
|
return $item; |
|
676
|
|
|
} |
|
677
|
|
|
|
|
678
|
|
|
/** |
|
679
|
|
|
* @param array $item |
|
680
|
|
|
* @param int $item_page_id |
|
681
|
|
|
*/ |
|
682
|
|
|
public function toArrayAll($item, $item_page_id): array |
|
683
|
|
|
{ |
|
684
|
|
|
$item['maintext'] = $this->buildmaintext($item_page_id, $this->body()); |
|
685
|
|
|
$item = $this->getOtherImages($item); |
|
686
|
|
|
|
|
687
|
|
|
return $item; |
|
688
|
|
|
} |
|
689
|
|
|
|
|
690
|
|
|
/** |
|
691
|
|
|
* @param array $item |
|
692
|
|
|
*/ |
|
693
|
|
|
public function getMainImage($item = []): array |
|
694
|
|
|
{ |
|
695
|
|
|
$images = $this->getImages(); |
|
696
|
|
|
$item['image_path'] = ''; |
|
697
|
|
|
$item['image_name'] = ''; |
|
698
|
|
|
if (\is_object($images['main'])) { |
|
699
|
|
|
/* @var \ImagesImage $image */ |
|
700
|
|
|
$image = $images['main']; |
|
701
|
|
|
$dimensions = \getimagesize(XoopsBaseConfig::get('root-path') . '/uploads/' . $image->getVar('image_name')); |
|
702
|
|
|
$item['image_width'] = $dimensions[0]; |
|
703
|
|
|
$item['image_height'] = $dimensions[1]; |
|
704
|
|
|
$item['image_path'] = XoopsBaseConfig::get('url') . '/uploads/' . $image->getVar('image_name'); |
|
705
|
|
|
// pass this on since some consumers build custom thumbnails |
|
706
|
|
|
$item['image_vpath'] = 'uploads/' . $image->getVar('image_name'); |
|
707
|
|
|
$item['image_thumb'] = Xoops::getInstance()->service('thumbnail')->getImgUrl($item['image_vpath'], 0, 180)->getValue(); |
|
708
|
|
|
$item['image_name'] = $image->getVar('image_nicename'); |
|
709
|
|
|
} |
|
710
|
|
|
|
|
711
|
|
|
return $item; |
|
712
|
|
|
} |
|
713
|
|
|
|
|
714
|
|
|
/** |
|
715
|
|
|
* @param array $item |
|
716
|
|
|
*/ |
|
717
|
|
|
public function getOtherImages($item = []): array |
|
718
|
|
|
{ |
|
719
|
|
|
$thumbService = Xoops::getInstance()->service('thumbnail'); |
|
720
|
|
|
$images = $this->getImages(); |
|
721
|
|
|
$item['images'] = []; |
|
722
|
|
|
$i = 0; |
|
723
|
|
|
/* @var \ImagesImage $image */ |
|
724
|
|
|
foreach ($images['others'] as $image) { |
|
725
|
|
|
$dimensions = \getimagesize(XoopsBaseConfig::get('root-path') . '/uploads/' . $image->getVar('image_name')); |
|
726
|
|
|
$item['images'][$i]['width'] = $dimensions[0]; |
|
727
|
|
|
$item['images'][$i]['height'] = $dimensions[1]; |
|
728
|
|
|
$item['images'][$i]['path'] = XoopsBaseConfig::get('url') . '/uploads/' . $image->getVar('image_name'); |
|
729
|
|
|
$item['images'][$i]['thumb'] = $thumbService->getImgUrl('uploads/' . $image->getVar('image_name'), 240, 0)->getValue(); |
|
730
|
|
|
$item['images'][$i]['name'] = $image->getVar('image_nicename'); |
|
731
|
|
|
++$i; |
|
732
|
|
|
} |
|
733
|
|
|
|
|
734
|
|
|
return $item; |
|
735
|
|
|
} |
|
736
|
|
|
|
|
737
|
|
|
/** |
|
738
|
|
|
* @param string $content |
|
739
|
|
|
* @param string|array $keywords |
|
740
|
|
|
* |
|
741
|
|
|
* @return string Text |
|
742
|
|
|
*/ |
|
743
|
|
|
public function highlight($content, $keywords): string |
|
744
|
|
|
{ |
|
745
|
|
|
$color = $this->helper->getConfig('format_highlight_color'); |
|
746
|
|
|
if (0 !== \mb_strpos($color, '#')) { |
|
|
|
|
|
|
747
|
|
|
$color = '#' . $color; |
|
748
|
|
|
} |
|
749
|
|
|
$pre = '<span style="font-weight: bolder; background-color: ' . $color . ';">'; |
|
750
|
|
|
$post = '</span>'; |
|
751
|
|
|
|
|
752
|
|
|
return Highlighter::apply($keywords, $content, $pre, $post); |
|
753
|
|
|
} |
|
754
|
|
|
|
|
755
|
|
|
/** |
|
756
|
|
|
* Create metada and assign it to template |
|
757
|
|
|
*/ |
|
758
|
|
|
public function createMetaTags(): void |
|
759
|
|
|
{ |
|
760
|
|
|
$publisher_metagen = new Publisher\Metagen($this->title(), $this->getVar('meta_keywords'), $this->getVar('meta_description'), $this->_category->_categoryPath); |
|
|
|
|
|
|
761
|
|
|
$publisher_metagen->createMetaTags(); |
|
762
|
|
|
} |
|
763
|
|
|
|
|
764
|
|
|
/** |
|
765
|
|
|
* @param string $str |
|
766
|
|
|
*/ |
|
767
|
|
|
public function _convert_for_japanese($str): string |
|
768
|
|
|
{ |
|
769
|
|
|
global $xoopsConfig; |
|
770
|
|
|
// no action, if not flag |
|
771
|
|
|
if (!\defined('_PUBLISHER_FLAG_JP_CONVERT')) { |
|
772
|
|
|
return $str; |
|
773
|
|
|
} |
|
774
|
|
|
// no action, if not Japanese |
|
775
|
|
|
if ('japanese' !== $xoopsConfig['language']) { |
|
776
|
|
|
return $str; |
|
777
|
|
|
} |
|
778
|
|
|
// presume OS Browser |
|
779
|
|
|
$agent = $_SERVER['HTTP_USER_AGENT']; |
|
780
|
|
|
$os = ''; |
|
781
|
|
|
$browser = ''; |
|
782
|
|
|
if (false !== \mb_stripos($agent, 'Win')) { |
|
783
|
|
|
$os = 'win'; |
|
784
|
|
|
} |
|
785
|
|
|
if (false !== \mb_stripos($agent, 'MSIE')) { |
|
786
|
|
|
$browser = 'msie'; |
|
787
|
|
|
} |
|
788
|
|
|
// if msie |
|
789
|
|
|
if (('win' === $os) && ('msie' === $browser)) { |
|
790
|
|
|
// if multibyte |
|
791
|
|
|
if (\function_exists('mb_convert_encoding')) { |
|
792
|
|
|
$str = mb_convert_encoding($str, 'SJIS', 'EUC-JP'); |
|
793
|
|
|
$str = \rawurlencode($str); |
|
|
|
|
|
|
794
|
|
|
} |
|
795
|
|
|
} |
|
796
|
|
|
|
|
797
|
|
|
return $str; |
|
798
|
|
|
} |
|
799
|
|
|
|
|
800
|
|
|
/** |
|
801
|
|
|
* Checks if a user has access to a selected item. if no item permissions are |
|
802
|
|
|
* set, access permission is denied. The user needs to have necessary category |
|
803
|
|
|
* permission as well. |
|
804
|
|
|
* Also, the item needs to be Published |
|
805
|
|
|
* |
|
806
|
|
|
* @return bool : TRUE if the no errors occured |
|
807
|
|
|
*/ |
|
808
|
|
|
public function accessGranted(): bool |
|
809
|
|
|
{ |
|
810
|
|
|
if (Publisher\Utils::IsUserAdmin()) { |
|
811
|
|
|
return true; |
|
812
|
|
|
} |
|
813
|
|
|
if (\_PUBLISHER_STATUS_PUBLISHED != $this->getVar('status')) { |
|
814
|
|
|
return false; |
|
815
|
|
|
} |
|
816
|
|
|
// Do we have access to the parent category |
|
817
|
|
|
if ($this->helper->getPermissionHandler()->isGranted('category_read', $this->getVar('categoryid'))) { |
|
818
|
|
|
return true; |
|
819
|
|
|
} |
|
820
|
|
|
|
|
821
|
|
|
return false; |
|
822
|
|
|
} |
|
823
|
|
|
|
|
824
|
|
|
/** |
|
825
|
|
|
* The name says it all |
|
826
|
|
|
*/ |
|
827
|
|
|
public function setVarsFromRequest(): void |
|
828
|
|
|
{ |
|
829
|
|
|
$xoops = Xoops::getInstance(); |
|
830
|
|
|
//Required fields |
|
831
|
|
|
if (isset($_REQUEST['categoryid'])) { |
|
832
|
|
|
$this->setVar('categoryid', Request::getInt('categoryid')); |
|
833
|
|
|
} |
|
834
|
|
|
if (isset($_REQUEST['title'])) { |
|
835
|
|
|
$this->setVar('title', Request::getString('title')); |
|
836
|
|
|
} |
|
837
|
|
|
if (isset($_REQUEST['body'])) { |
|
838
|
|
|
$this->setVar('body', Request::getText('body')); |
|
839
|
|
|
} |
|
840
|
|
|
//Not required fields |
|
841
|
|
|
if (isset($_REQUEST['summary'])) { |
|
842
|
|
|
$this->setVar('summary', Request::getText('summary')); |
|
843
|
|
|
} |
|
844
|
|
|
if (isset($_REQUEST['subtitle'])) { |
|
845
|
|
|
$this->setVar('subtitle', Request::getString('subtitle')); |
|
846
|
|
|
} |
|
847
|
|
|
if (isset($_REQUEST['item_tag'])) { |
|
848
|
|
|
$this->setVar('item_tag', Request::getString('item_tag')); |
|
849
|
|
|
} |
|
850
|
|
|
if (isset($_REQUEST['image_featured'])) { |
|
851
|
|
|
$image_item = Request::getArray('image_item'); |
|
852
|
|
|
$image_featured = Request::getString('image_featured'); |
|
853
|
|
|
//Todo: get a better image class for xoops! |
|
854
|
|
|
//Image hack |
|
855
|
|
|
$image_item_ids = []; |
|
856
|
|
|
|
|
857
|
|
|
$qb = Xoops::getInstance()->db()->createXoopsQueryBuilder(); |
|
858
|
|
|
$qb->select('i.image_id', 'i.image_name')->fromPrefix('image', 'i')->orderBy('i.image_id'); |
|
859
|
|
|
$result = $qb->execute(); |
|
860
|
|
|
|
|
861
|
|
|
while (false !== ($myrow = $result->fetch(FetchMode::ASSOCIATIVE))) { |
|
862
|
|
|
$image_name = $myrow['image_name']; |
|
863
|
|
|
$id = $myrow['image_id']; |
|
864
|
|
|
if ($image_name == $image_featured) { |
|
865
|
|
|
$this->setVar('image', $id); |
|
866
|
|
|
} |
|
867
|
|
|
if (\in_array($image_name, $image_item)) { |
|
868
|
|
|
$image_item_ids[] = $id; |
|
869
|
|
|
} |
|
870
|
|
|
} |
|
871
|
|
|
$this->setVar('images', \implode('|', $image_item_ids)); |
|
872
|
|
|
} |
|
873
|
|
|
if (isset($_REQUEST['uid'])) { |
|
874
|
|
|
$this->setVar('uid', Request::getInt('uid')); |
|
875
|
|
|
} elseif ($this->isNew()) { |
|
876
|
|
|
$this->setVar('uid', $xoops->isUser() ? $xoops->user->getVar('uid') : 0); |
|
877
|
|
|
} |
|
878
|
|
|
if (isset($_REQUEST['author_alias'])) { |
|
879
|
|
|
$this->setVar('author_alias', Request::getString('author_alias')); |
|
880
|
|
|
if ('' != $this->getVar('author_alias')) { |
|
881
|
|
|
$this->setVar('uid', 0); |
|
882
|
|
|
} |
|
883
|
|
|
} |
|
884
|
|
|
if (isset($_REQUEST['datesub'])) { |
|
885
|
|
|
$this->setVar('datesub', \strtotime($_REQUEST['datesub']['date']) + $_REQUEST['datesub']['time']); |
|
886
|
|
|
} elseif ($this->isNew()) { |
|
887
|
|
|
$this->setVar('datesub', \time()); |
|
888
|
|
|
} |
|
889
|
|
|
if (isset($_REQUEST['item_short_url'])) { |
|
890
|
|
|
$this->setVar('short_url', Request::getString('item_short_url')); |
|
891
|
|
|
} |
|
892
|
|
|
if (isset($_REQUEST['item_meta_keywords'])) { |
|
893
|
|
|
$this->setVar('meta_keywords', Request::getString('item_meta_keywords')); |
|
894
|
|
|
} |
|
895
|
|
|
if (isset($_REQUEST['item_meta_description'])) { |
|
896
|
|
|
$this->setVar('meta_description', Request::getString('item_meta_description')); |
|
897
|
|
|
} |
|
898
|
|
|
if (isset($_REQUEST['weight'])) { |
|
899
|
|
|
$this->setVar('weight', Request::getInt('weight')); |
|
900
|
|
|
} |
|
901
|
|
|
if (isset($_REQUEST['allowcomments'])) { |
|
902
|
|
|
$this->setVar('cancomment', Request::getInt('allowcomments')); |
|
903
|
|
|
} elseif ($this->isNew()) { |
|
904
|
|
|
$this->setVar('cancoment', $this->helper->getConfig('submit_allowcomments')); |
|
905
|
|
|
} |
|
906
|
|
|
if (isset($_REQUEST['status'])) { |
|
907
|
|
|
$this->setVar('status', Request::getInt('status')); |
|
908
|
|
|
} elseif ($this->isNew()) { |
|
909
|
|
|
$this->setVar('status', $this->helper->getConfig('submit_status')); |
|
910
|
|
|
} |
|
911
|
|
|
if (isset($_REQUEST['dohtml'])) { |
|
912
|
|
|
$this->setVar('dohtml', Request::getInt('dohtml')); |
|
913
|
|
|
} elseif ($this->isNew()) { |
|
914
|
|
|
$this->setVar('dohtml', $this->helper->getConfig('submit_dohtml')); |
|
915
|
|
|
} |
|
916
|
|
|
if (isset($_REQUEST['dosmiley'])) { |
|
917
|
|
|
$this->setVar('dosmiley', Request::getInt('dosmiley')); |
|
918
|
|
|
} elseif ($this->isNew()) { |
|
919
|
|
|
$this->setVar('dosmiley', $this->helper->getConfig('submit_dosmiley')); |
|
920
|
|
|
} |
|
921
|
|
|
if (isset($_REQUEST['doxcode'])) { |
|
922
|
|
|
$this->setVar('doxcode', Request::getInt('doxcode')); |
|
923
|
|
|
} elseif ($this->isNew()) { |
|
924
|
|
|
$this->setVar('doxcode', $this->helper->getConfig('submit_doxcode')); |
|
925
|
|
|
} |
|
926
|
|
|
if (isset($_REQUEST['doimage'])) { |
|
927
|
|
|
$this->setVar('doimage', Request::getInt('doimage')); |
|
928
|
|
|
} elseif ($this->isNew()) { |
|
929
|
|
|
$this->setVar('doimage', $this->helper->getConfig('submit_doimage')); |
|
930
|
|
|
} |
|
931
|
|
|
if (isset($_REQUEST['dolinebreak'])) { |
|
932
|
|
|
$this->setVar('dobr', Request::getInt('dolinebreak')); |
|
933
|
|
|
} elseif ($this->isNew()) { |
|
934
|
|
|
$this->setVar('dobr', $this->helper->getConfig('submit_dobr')); |
|
935
|
|
|
} |
|
936
|
|
|
if (isset($_REQUEST['notify'])) { |
|
937
|
|
|
$this->setVar('notifypub', Request::getInt('notify')); |
|
938
|
|
|
} |
|
939
|
|
|
} |
|
940
|
|
|
} |
|
941
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.