Passed
Branch master (99165a)
by Michael
04:26
created

Item::getPdfButton()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 20
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace XoopsModules\Publisher;
6
7
/*
8
 You may not change or alter any portion of this comment or credits
9
 of supporting developers from this source code or any supporting source code
10
 which is considered copyrighted (c) material of the original comment or credit authors.
11
12
 This program is distributed in the hope that it will be useful,
13
 but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
 */
16
17
/**
18
 * @copyright       The XUUPS Project http://sourceforge.net/projects/xuups/
19
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
20
 * @package         Publisher
21
 * @since           1.0
22
 * @author          trabis <[email protected]>
23
 * @author          The SmartFactory <www.smartfactory.ca>
24
 */
25
26
use Xmf\Request;
27
use XoopsModules\Publisher;
28
29
//namespace Publisher;
30
31
32
require_once \dirname(__DIR__) . '/include/common.php';
33
34
/**
35
 * Class Item
36
 */
37
class Item extends \XoopsObject
38
{
39
    /**
40
     * @var Publisher\Helper
41
     */
42
    public $helper;
43
    public $groupsRead = [];
44
45
    /**
46
     * @var Publisher\Category
47
     */
48
    public $category;
49
50
    /**
51
     * @param int|null $id
52
     */
53
    public function __construct($id = null)
54
    {
55
        /** @var \XoopsModules\Publisher\Helper $this->helper */
56
        $this->helper = \XoopsModules\Publisher\Helper::getInstance();
57
        /** @var \XoopsDatabase $this->db */
58
        $this->db     = \XoopsDatabaseFactory::getDatabaseConnection();
0 ignored issues
show
Bug Best Practice introduced by
The property db does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
59
        $this->initVar('itemid', \XOBJ_DTYPE_INT, 0);
60
        $this->initVar('categoryid', \XOBJ_DTYPE_INT, 0, false);
61
        $this->initVar('title', \XOBJ_DTYPE_TXTBOX, '', true, 255);
62
        $this->initVar('subtitle', \XOBJ_DTYPE_TXTBOX, '', false, 255);
63
        $this->initVar('summary', \XOBJ_DTYPE_TXTAREA, '', false);
64
        $this->initVar('body', \XOBJ_DTYPE_TXTAREA, '', false);
65
        $this->initVar('uid', \XOBJ_DTYPE_INT, 0, false);
66
        $this->initVar('author_alias', \XOBJ_DTYPE_TXTBOX, '', false, 255);
67
        $this->initVar('datesub', \XOBJ_DTYPE_INT, '', false);
68
        $this->initVar('dateexpire', \XOBJ_DTYPE_INT, '', false);
69
        $this->initVar('status', \XOBJ_DTYPE_INT, -1, false);
70
        $this->initVar('image', \XOBJ_DTYPE_INT, 0, false);
71
        $this->initVar('images', \XOBJ_DTYPE_TXTBOX, '', false, 255);
72
        $this->initVar('counter', \XOBJ_DTYPE_INT, 0, false);
73
        $this->initVar('rating', \XOBJ_DTYPE_OTHER, 0, false);
74
        $this->initVar('votes', \XOBJ_DTYPE_INT, 0, false);
75
        $this->initVar('weight', \XOBJ_DTYPE_INT, 0, false);
76
        $this->initVar('dohtml', \XOBJ_DTYPE_INT, 1, true);
77
        $this->initVar('dosmiley', \XOBJ_DTYPE_INT, 1, true);
78
        $this->initVar('doimage', \XOBJ_DTYPE_INT, 1, true);
79
        $this->initVar('dobr', \XOBJ_DTYPE_INT, 1, false);
80
        $this->initVar('doxcode', \XOBJ_DTYPE_INT, 1, true);
81
        $this->initVar('cancomment', \XOBJ_DTYPE_INT, 1, true);
82
        $this->initVar('comments', \XOBJ_DTYPE_INT, 0, false);
83
        $this->initVar('notifypub', \XOBJ_DTYPE_INT, 1, false);
84
        $this->initVar('meta_keywords', \XOBJ_DTYPE_TXTAREA, '', false);
85
        $this->initVar('meta_description', \XOBJ_DTYPE_TXTAREA, '', false);
86
        $this->initVar('short_url', \XOBJ_DTYPE_TXTBOX, '', false, 255);
87
        $this->initVar('item_tag', \XOBJ_DTYPE_TXTAREA, '', false);
88
        // Non consistent values
89
        $this->initVar('pagescount', \XOBJ_DTYPE_INT, 0, false);
90
        if (null !== $id) {
91
            $item = $this->helper->getHandler('Item')->get($id);
92
            foreach ($item->vars as $k => $v) {
93
                $this->assignVar($k, $v['value']);
94
            }
95
        }
96
    }
97
98
    /**
99
     * @param string $method
100
     * @param array  $args
101
     *
102
     * @return mixed
103
     */
104
    public function __call($method, $args)
105
    {
106
        $arg = $args[0] ?? null;
107
108
        return $this->getVar($method, $arg);
109
    }
110
111
    /**
112
     * @return null|Publisher\Category
113
     */
114
    public function getCategory()
115
    {
116
        if (null === $this->category) {
117
            $this->category = $this->helper->getHandler('Category')->get($this->getVar('categoryid'));
118
        }
119
120
        return $this->category;
121
    }
122
123
    /**
124
     * @param int    $maxLength
125
     * @param string $format
126
     *
127
     * @return mixed|string
128
     */
129
    public function getTitle($maxLength = 0, $format = 'S')
130
    {
131
        $ret = $this->getVar('title', $format);
132
        if (0 != $maxLength) {
133
            if (!XOOPS_USE_MULTIBYTES) {
134
                if (mb_strlen($ret) >= $maxLength) {
0 ignored issues
show
Bug introduced by
It seems like $ret can also be of type array and array; however, parameter $str of mb_strlen() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

134
                if (mb_strlen(/** @scrutinizer ignore-type */ $ret) >= $maxLength) {
Loading history...
135
                    $ret = Publisher\Utility::substr($ret, 0, $maxLength);
0 ignored issues
show
Bug introduced by
It seems like $ret can also be of type array and array; however, parameter $str of XoopsModules\Publisher\Utility::substr() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

135
                    $ret = Publisher\Utility::substr(/** @scrutinizer ignore-type */ $ret, 0, $maxLength);
Loading history...
136
                }
137
            }
138
        }
139
140
        return $ret;
141
    }
142
143
    /**
144
     * @param int    $maxLength
145
     * @param string $format
146
     *
147
     * @return mixed|string
148
     */
149
    public function getSubtitle($maxLength = 0, $format = 'S')
150
    {
151
        $ret = $this->getVar('subtitle', $format);
152
        if (0 != $maxLength) {
153
            if (!XOOPS_USE_MULTIBYTES) {
154
                if (mb_strlen($ret) >= $maxLength) {
0 ignored issues
show
Bug introduced by
It seems like $ret can also be of type array and array; however, parameter $str of mb_strlen() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

154
                if (mb_strlen(/** @scrutinizer ignore-type */ $ret) >= $maxLength) {
Loading history...
155
                    $ret = Publisher\Utility::substr($ret, 0, $maxLength);
0 ignored issues
show
Bug introduced by
It seems like $ret can also be of type array and array; however, parameter $str of XoopsModules\Publisher\Utility::substr() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

155
                    $ret = Publisher\Utility::substr(/** @scrutinizer ignore-type */ $ret, 0, $maxLength);
Loading history...
156
                }
157
            }
158
        }
159
160
        return $ret;
161
    }
162
163
    /**
164
     * @param int    $maxLength
165
     * @param string $format
166
     * @param string $stripTags
167
     *
168
     * @return mixed|string
169
     */
170
    public function getSummary($maxLength = 0, $format = 'S', $stripTags = '')
171
    {
172
        $ret = $this->getVar('summary', $format);
173
        if (!empty($stripTags)) {
174
            $ret = \strip_tags($ret, $stripTags);
0 ignored issues
show
Bug introduced by
It seems like $ret can also be of type array and array; however, parameter $str of strip_tags() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

174
            $ret = \strip_tags(/** @scrutinizer ignore-type */ $ret, $stripTags);
Loading history...
175
        }
176
        if (0 != $maxLength) {
177
            if (!XOOPS_USE_MULTIBYTES) {
178
                if (mb_strlen($ret) >= $maxLength) {
179
                    //$ret = Publisher\Utility::substr($ret , 0, $maxLength);
180
                    //                    $ret = Publisher\Utility::truncateTagSafe($ret, $maxLength, $etc = '...', $breakWords = false);
181
                    $ret = Publisher\Utility::truncateHtml($ret, $maxLength, $etc = '...', $breakWords = false);
182
                }
183
            }
184
        }
185
186
        return $ret;
187
    }
188
189
    /**
190
     * @param int  $maxLength
191
     * @param bool $fullSummary
192
     *
193
     * @return mixed|string
194
     */
195
    public function getBlockSummary($maxLength = 0, $fullSummary = false)
196
    {
197
        if ($fullSummary) {
198
            $ret = $this->getSummary(0, 's', '<br><br>');
199
        } else {
200
            $ret = $this->getSummary($maxLength, 's', '<br><br>');
201
        }
202
        //no summary? get body!
203
        if ('' === $ret) {
204
            $ret = $this->getBody($maxLength, 's', '<br><br>');
205
        }
206
207
        return $ret;
208
    }
209
210
    /**
211
     * @param string $fileName
212
     *
213
     * @return string
214
     */
215
    public function wrapPage($fileName)
216
    {
217
        $content = '';
218
        $page    = Publisher\Utility::getUploadDir(true, 'content') . $fileName;
219
        if (\file_exists($page)) {
220
            // this page uses smarty template
221
            \ob_start();
222
            require $page;
223
            $content = \ob_get_clean();
224
            // Cleaning the content
225
            $bodyStartPos = mb_strpos($content, '<body>');
226
            if ($bodyStartPos) {
227
                $bodyEndPos = mb_strpos($content, '</body>', $bodyStartPos);
228
                $content    = mb_substr($content, $bodyStartPos + mb_strlen('<body>'), $bodyEndPos - mb_strlen('<body>') - $bodyStartPos);
229
            }
230
            // Check if ML Hack is installed, and if yes, parse the $content in formatForML
231
            $myts = \MyTextSanitizer::getInstance();
232
            if (\method_exists($myts, 'formatForML')) {
233
                $content = $myts->formatForML($content);
234
            }
235
        }
236
237
        return $content;
238
    }
239
240
    /**
241
     * This method returns the body to be displayed. Not to be used for editing
242
     *
243
     * @param int    $maxLength
244
     * @param string $format
245
     * @param string $stripTags
246
     *
247
     * @return mixed|string
248
     */
249
    public function getBody($maxLength = 0, $format = 'S', $stripTags = '')
250
    {
251
        $ret     = $this->getVar('body', $format);
252
        $wrapPos = mb_strpos($ret, '[pagewrap=');
0 ignored issues
show
Bug introduced by
It seems like $ret can also be of type array and array; however, parameter $haystack of mb_strpos() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

252
        $wrapPos = mb_strpos(/** @scrutinizer ignore-type */ $ret, '[pagewrap=');
Loading history...
253
        if (!(false === $wrapPos)) {
254
            $wrapPages      = [];
255
            $wrapCodeLength = mb_strlen('[pagewrap=');
256
            while (!(false === $wrapPos)) {
257
                $endWrapPos = mb_strpos($ret, ']', $wrapPos);
258
                if ($endWrapPos) {
259
                    $wrap_page_name = mb_substr($ret, $wrapPos + $wrapCodeLength, $endWrapPos - $wrapCodeLength - $wrapPos);
0 ignored issues
show
Bug introduced by
It seems like $ret can also be of type array and array; however, parameter $str of mb_substr() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

259
                    $wrap_page_name = mb_substr(/** @scrutinizer ignore-type */ $ret, $wrapPos + $wrapCodeLength, $endWrapPos - $wrapCodeLength - $wrapPos);
Loading history...
260
                    $wrapPages[]    = $wrap_page_name;
261
                }
262
                $wrapPos = mb_strpos($ret, '[pagewrap=', $endWrapPos - 1);
263
            }
264
            foreach ($wrapPages as $page) {
265
                $wrapPageContent = $this->wrapPage($page);
266
                $ret             = \str_replace("[pagewrap={$page}]", $wrapPageContent, $ret);
267
            }
268
        }
269
        if ($this->helper->getConfig('item_disp_blocks_summary')) {
270
            $summary = $this->getSummary($maxLength, $format, $stripTags);
271
            if ($summary) {
272
                $ret = $this->getSummary() . '<br><br>' . $ret;
273
            }
274
        }
275
        if (!empty($stripTags)) {
276
            $ret = \strip_tags($ret, $stripTags);
277
        }
278
        if (0 != $maxLength) {
279
            if (!XOOPS_USE_MULTIBYTES) {
280
                if (mb_strlen($ret) >= $maxLength) {
281
                    //$ret = Publisher\Utility::substr($ret , 0, $maxLength);
282
                    $ret = Publisher\Utility::truncateHtml($ret, $maxLength, $etc = '...', $breakWords = false);
283
                }
284
            }
285
        }
286
287
        return $ret;
288
    }
289
290
    /**
291
     * @param string $dateFormat
292
     * @param string $format
293
     *
294
     * @return string
295
     */
296
    public function getDatesub($dateFormat = '', $format = 'S')
297
    {
298
        if (empty($dateFormat)) {
299
            $dateFormat = $this->helper->getConfig('format_date');
300
        }
301
302
        return \formatTimestamp($this->getVar('datesub', $format), $dateFormat);
303
    }
304
305
    /**
306
     * @param string $dateFormat
307
     * @param string $format
308
     *
309
     * @return string
310
     */
311
    public function getDateExpire($dateFormat = '', $format = 'S')
312
    {
313
        if (empty($dateFormat)) {
314
            $dateFormat = $this->helper->getConfig('format_date');
315
        }
316
        if (0 == $this->getVar('dateexpire')) {
317
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type string.
Loading history...
318
        }
319
320
        return \formatTimestamp($this->getVar('dateexpire', $format), $dateFormat);
321
    }
322
    
323
    /**
324
     * @param int $realName
325
     *
326
     * @return string
327
     */
328
    public function posterName($realName = -1)
329
    {
330
        \xoops_load('XoopsUserUtility');
331
        if (-1 == $realName) {
332
            $realName = $this->helper->getConfig('format_realname');
333
        }
334
        $ret = $this->author_alias();
0 ignored issues
show
Bug introduced by
The method author_alias() does not exist on XoopsModules\Publisher\Item. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

334
        /** @scrutinizer ignore-call */ 
335
        $ret = $this->author_alias();
Loading history...
335
        if ('' == $ret) {
336
            $ret = \XoopsUserUtility::getUnameFromId($this->uid(), $realName);
0 ignored issues
show
Bug introduced by
The method uid() does not exist on XoopsModules\Publisher\Item. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

336
            $ret = \XoopsUserUtility::getUnameFromId($this->/** @scrutinizer ignore-call */ uid(), $realName);
Loading history...
337
        }
338
339
        return $ret;
340
    }
341
342
    /**
343
     * @return string
344
     */
345
    public function posterAvatar()
346
    {
347
        $ret           = 'blank.gif';
348
        $memberHandler = \xoops_getHandler('member');
349
        $thisUser      = $memberHandler->getUser($this->uid());
0 ignored issues
show
Bug introduced by
The method getUser() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsAvatarHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

349
        /** @scrutinizer ignore-call */ 
350
        $thisUser      = $memberHandler->getUser($this->uid());
Loading history...
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')->updateCounter($this->itemid());
0 ignored issues
show
Bug introduced by
The method itemid() does not exist on XoopsModules\Publisher\Item. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

376
        return $this->helper->getHandler('Item')->updateCounter($this->/** @scrutinizer ignore-call */ itemid());
Loading history...
377
    }
378
379
    /**
380
     * @param bool $force
381
     *
382
     * @return bool
383
     */
384
    public function store($force = true)
385
    {
386
        $isNew = $this->isNew();
387
        if (!$this->helper->getHandler('Item')->insert($this, $force)) {
388
            return false;
389
        }
390
        if ($isNew && Constants::PUBLISHER_STATUS_PUBLISHED == $this->getVar('status')) {
391
            // Increment user posts
392
            $userHandler   = \xoops_getHandler('user');
393
            $memberHandler = \xoops_getHandler('member');
394
            $poster        = $userHandler->get($this->uid());
395
            if (\is_object($poster) && !$poster->isNew()) {
396
                $poster->setVar('posts', $poster->getVar('posts') + 1);
397
                if (!$memberHandler->insertUser($poster, true)) {
0 ignored issues
show
Bug introduced by
The method insertUser() does not exist on XoopsObjectHandler. Did you maybe mean insert()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

397
                if (!$memberHandler->/** @scrutinizer ignore-call */ insertUser($poster, true)) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
398
                    $this->setErrors('Article created but could not increment user posts.');
399
400
                    return false;
401
                }
402
            }
403
        }
404
405
        return true;
406
    }
407
408
    /**
409
     * @return string
410
     */
411
    public function getCategoryName()
412
    {
413
        return $this->getCategory()->name();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getCategory()->name() also could return the type array|boolean which is incompatible with the documented return type string.
Loading history...
Bug introduced by
The method name() does not exist on XoopsModules\Publisher\Category. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

413
        return $this->getCategory()->/** @scrutinizer ignore-call */ name();
Loading history...
414
    }
415
416
    /**
417
     * @return string
418
     */
419
    public function getCategoryUrl()
420
    {
421
        return $this->getCategory()->getCategoryUrl();
422
    }
423
424
    /**
425
     * @return string
426
     */
427
    public function getCategoryLink()
428
    {
429
        return $this->getCategory()->getCategoryLink();
430
    }
431
432
    /**
433
     * @param bool $withAllLink
434
     *
435
     * @return string
436
     */
437
    public function getCategoryPath($withAllLink = true)
438
    {
439
        return $this->getCategory()->getCategoryPath($withAllLink);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getCategor...egoryPath($withAllLink) also could return the type array|boolean which is incompatible with the documented return type string.
Loading history...
440
    }
441
442
    /**
443
     * @return string
444
     */
445
    public function getCategoryImagePath()
446
    {
447
        return Publisher\Utility::getImageDir('category', false) . $this->getCategory()->getImage();
448
    }
449
450
    /**
451
     * @return mixed
452
     */
453
    public function getFiles()
454
    {
455
        return $this->helper->getHandler('File')->getAllFiles($this->itemid(), Constants::PUBLISHER_STATUS_FILE_ACTIVE);
456
    }
457
458
    /**
459
     * @return string
460
     */
461
    public function getAdminLinks()
462
    {
463
        $adminLinks = '';
464
        if (\is_object($GLOBALS['xoopsUser'])
465
            && (Publisher\Utility::userIsAdmin() || Publisher\Utility::userIsAuthor($this)
466
                || $this->helper->getHandler('Permission')->isGranted('item_submit', $this->categoryid()))) {
0 ignored issues
show
Bug introduced by
The method categoryid() does not exist on XoopsModules\Publisher\Item. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

466
                || $this->helper->getHandler('Permission')->isGranted('item_submit', $this->/** @scrutinizer ignore-call */ categoryid()))) {
Loading history...
467
            if (Publisher\Utility::userIsAdmin() || Publisher\Utility::userIsAuthor($this) || Publisher\Utility::userIsModerator($this)) {
468
                if ($this->helper->getConfig('perm_edit') || Publisher\Utility::userIsModerator($this) || Publisher\Utility::userIsAdmin()) {
469
                    // Edit button
470
                    $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>";
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Publisher\PUBLISHER_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
471
                    $adminLinks .= ' ';
472
                }
473
                if ($this->helper->getConfig('perm_delete') || Publisher\Utility::userIsModerator($this) || Publisher\Utility::userIsAdmin()) {
474
                    // Delete button
475
                    $adminLinks .= "<a href='" . PUBLISHER_URL . '/submit.php?op=del&amp;itemid=' . $this->itemid() . "'><img src='" . PUBLISHER_URL . "/assets/images/links/delete.png'" . " title='" . \_CO_PUBLISHER_DELETE . "' alt='" . \_CO_PUBLISHER_DELETE . "'></a>";
476
                    $adminLinks .= ' ';
477
                }
478
            }
479
            if ($this->helper->getConfig('perm_clone') || Publisher\Utility::userIsModerator($this) || Publisher\Utility::userIsAdmin()) {
480
                // Duplicate button
481
                $adminLinks .= "<a href='" . PUBLISHER_URL . '/submit.php?op=clone&amp;itemid=' . $this->itemid() . "'><img src='" . PUBLISHER_URL . "/assets/images/links/clone.gif'" . " title='" . \_CO_PUBLISHER_CLONE . "' alt='" . \_CO_PUBLISHER_CLONE . "'></a>";
482
                $adminLinks .= ' ';
483
            }
484
        }
485
486
        return $adminLinks;
487
    }
488
	
489
	    /**
490
     * @return string
491
     */
492
    public function getPdfButton()
493
    {
494
       $pdfButton = '';
495
        // PDF button
496
            if (!\is_file(XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php')) {
497
                //                if (is_object($GLOBALS['xoopsUser']) && Publisher\Utility::userIsAdmin()) {
498
                //                    $GLOBALS['xoTheme']->addStylesheet('/modules/system/css/jquery.jgrowl.min.css');
499
                //                    $GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/plugins/jquery.jgrowl.js');
500
                //                    $adminLinks .= '<script type="text/javascript">
501
                //                    (function($){
502
                //                        $(document).ready(function(){
503
                //                            $.jGrowl("' . _MD_PUBLISHER_ERROR_NO_PDF . '");});
504
                //                        })(jQuery);
505
                //                        </script>';
506
                //                }
507
            } else {
508
                $pdfButton .= "<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>&nbsp;";
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Publisher\PUBLISHER_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
509
                $pdfButton .= ' ';
510
            }
511
        return $pdfButton;
512
        }
513
514
	   /**
515
     * @return string
516
     */
517
    public function getPrintLinks()
518
    {
519
		$printLinks = '';
520
        // Print button
521
        $printLinks .= "<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>&nbsp;";
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Publisher\PUBLISHER_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The method short_url() does not exist on XoopsModules\Publisher\Item. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

521
        $printLinks .= "<a href='" . Publisher\Seo::generateUrl('print', $this->itemid(), $this->/** @scrutinizer ignore-call */ short_url()) . "' rel='nofollow' target='_blank'><img src='" . PUBLISHER_URL . "/assets/images/links/print.gif' title='" . \_CO_PUBLISHER_PRINT . "' alt='" . \_CO_PUBLISHER_PRINT . "'></a>&nbsp;";
Loading history...
Bug introduced by
It seems like $this->short_url() can also be of type array and array; however, parameter $shortUrl of XoopsModules\Publisher\Seo::generateUrl() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

521
        $printLinks .= "<a href='" . Publisher\Seo::generateUrl('print', $this->itemid(), /** @scrutinizer ignore-type */ $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>&nbsp;";
Loading history...
522
        $printLinks .= ' ';
523
        return $printLinks;
524
    }
525
526
    /**
527
     * @param array $notifications
528
     */
529
    public function sendNotifications($notifications = [])
530
    {
531
        /** @var \XoopsNotificationHandler $notificationHandler */
532
        $notificationHandler = \xoops_getHandler('notification');
533
        $tags                = [];
534
535
        $tags['MODULE_NAME']   = $this->helper->getModule()->getVar('name');
536
        $tags['ITEM_NAME']     = $this->getTitle();
537
        $tags['ITEM_SUBNAME']  = $this->getSubtitle();
538
        $tags['CATEGORY_NAME'] = $this->getCategoryName();
539
        $tags['CATEGORY_URL']  = PUBLISHER_URL . '/category.php?categoryid=' . $this->categoryid();
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Publisher\PUBLISHER_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
540
        $tags['ITEM_BODY']     = $this->body();
0 ignored issues
show
Bug introduced by
The method body() does not exist on XoopsModules\Publisher\Item. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

540
        /** @scrutinizer ignore-call */ 
541
        $tags['ITEM_BODY']     = $this->body();
Loading history...
541
        $tags['DATESUB']       = $this->getDatesub();
542
        foreach ($notifications as $notification) {
543
            switch ($notification) {
544
                case Constants::PUBLISHER_NOTIFY_ITEM_PUBLISHED:
545
                    $tags['ITEM_URL'] = PUBLISHER_URL . '/item.php?itemid=' . $this->itemid();
546
                    $notificationHandler->triggerEvent('global_item', 0, 'published', $tags, [], $this->helper->getModule()->getVar('mid'));
547
                    $notificationHandler->triggerEvent('category_item', $this->categoryid(), 'published', $tags, [], $this->helper->getModule()->getVar('mid'));
548
                    $notificationHandler->triggerEvent('item', $this->itemid(), 'approved', $tags, [], $this->helper->getModule()->getVar('mid'));
549
                    break;
550
                case Constants::PUBLISHER_NOTIFY_ITEM_SUBMITTED:
551
                    $tags['WAITINGFILES_URL'] = PUBLISHER_URL . '/admin/item.php?itemid=' . $this->itemid();
552
                    $notificationHandler->triggerEvent('global_item', 0, 'submitted', $tags, [], $this->helper->getModule()->getVar('mid'));
553
                    $notificationHandler->triggerEvent('category_item', $this->categoryid(), 'submitted', $tags, [], $this->helper->getModule()->getVar('mid'));
554
                    break;
555
                case Constants::PUBLISHER_NOTIFY_ITEM_REJECTED:
556
                    $notificationHandler->triggerEvent('item', $this->itemid(), 'rejected', $tags, [], $this->helper->getModule()->getVar('mid'));
557
                    break;
558
                case -1:
559
                default:
560
                    break;
561
            }
562
        }
563
    }
564
565
    /**
566
     * Sets default permissions for this item
567
     */
568
    public function setDefaultPermissions()
569
    {
570
        $memberHandler = \xoops_getHandler('member');
571
        $groups        = $memberHandler->getGroupList();
0 ignored issues
show
Bug introduced by
The method getGroupList() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

571
        /** @scrutinizer ignore-call */ 
572
        $groups        = $memberHandler->getGroupList();
Loading history...
572
        $groupIds      = 0 < \count($groups) ? \array_keys($groups) : [];
573
        /*
574
        $j             = 0;
575
        $groupIds      = [];
576
        foreach (array_keys($groups) as $i) {
577
            $groupIds[$j] = $i;
578
            ++$j;
579
        }
580
        */
581
        $this->groupsRead = $groupIds;
582
    }
583
584
    /**
585
     * @param $groupIds
586
     * @deprecated - NOT USED
587
     *
588
     * @todo       look at this
589
     */
590
    public function setPermissions($groupIds)
591
    {
592
        if (!isset($groupIds)) {
593
            $this->setDefaultPermissions();
594
            /*
595
            $memberHandler = xoops_getHandler('member');
596
            $groups        = $memberHandler->getGroupList();
597
            $j             = 0;
598
            $groupIds      = [];
599
            foreach (array_keys($groups) as $i) {
600
                $groupIds[$j] = $i;
601
                ++$j;
602
            }
603
            */
604
        }
605
    }
606
607
    /**
608
     * @return bool
609
     */
610
    public function notLoaded()
611
    {
612
        return -1 == $this->getVar('itemid');
613
    }
614
615
    /**
616
     * @return string
617
     */
618
    public function getItemUrl()
619
    {
620
        return Publisher\Seo::generateUrl('item', $this->itemid(), $this->short_url());
0 ignored issues
show
Bug introduced by
It seems like $this->short_url() can also be of type array and array; however, parameter $shortUrl of XoopsModules\Publisher\Seo::generateUrl() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

620
        return Publisher\Seo::generateUrl('item', $this->itemid(), /** @scrutinizer ignore-type */ $this->short_url());
Loading history...
621
    }
622
623
    /**
624
     * @param bool $class
625
     * @param int  $maxsize
626
     *
627
     * @return string
628
     */
629
    public function getItemLink($class = false, $maxsize = 0)
630
    {
631
        if ($class) {
632
            return '<a class="' . $class . '" href="' . $this->getItemUrl() . '">' . $this->getTitle($maxsize) . '</a>';
0 ignored issues
show
Bug introduced by
Are you sure $class of type true can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

632
            return '<a class="' . /** @scrutinizer ignore-type */ $class . '" href="' . $this->getItemUrl() . '">' . $this->getTitle($maxsize) . '</a>';
Loading history...
633
        }
634
635
        return '<a href="' . $this->getItemUrl() . '">' . $this->getTitle($maxsize) . '</a>';
636
    }
637
638
    /**
639
     * @return string
640
     */
641
    public function getWhoAndWhen()
642
    {
643
        $posterName = $this->getLinkedPosterName();
644
        $postdate   = $this->getDatesub();
645
646
        return \sprintf(\_CO_PUBLISHER_POSTEDBY, $posterName, $postdate);
647
    }
648
649
    /**
650
     * @return string
651
     */
652
    public function getWho()
653
    {
654
        $posterName = $this->getLinkedPosterName();
655
656
        return $posterName;
657
    }
658
659
    /**
660
     * @return string
661
     */
662
    public function getWhen()
663
    {
664
        $postdate = $this->getDatesub();
665
666
        return $postdate;
667
    }
668
669
    /**
670
     * @param null|string $body
671
     *
672
     * @return string
673
     */
674
    public function plainMaintext($body = null)
675
    {
676
        $ret = '';
677
        if (!$body) {
678
            $body = $this->body();
679
        }
680
        $ret .= \str_replace('[pagebreak]', '<br><br>', $body);
681
682
        return $ret;
683
    }
684
685
    /**
686
     * @param int         $itemPageId
687
     * @param null|string $body
688
     *
689
     * @return string
690
     */
691
    public function buildMainText($itemPageId = -1, $body = null)
692
    {
693
        if (null === $body) {
694
            $body = $this->body();
695
        }
696
        $bodyParts = \explode('[pagebreak]', $body);
697
        $this->setVar('pagescount', \count($bodyParts));
698
        if (\count($bodyParts) <= 1) {
699
            return $this->plainMaintext($body);
700
        }
701
        $ret = '';
702
        if (-1 == $itemPageId) {
703
            $ret .= \trim($bodyParts[0]);
704
705
            return $ret;
706
        }
707
        if ($itemPageId >= \count($bodyParts)) {
708
            $itemPageId = \count($bodyParts) - 1;
709
        }
710
        $ret .= \trim($bodyParts[$itemPageId]);
711
712
        return $ret;
713
    }
714
715
    /**
716
     * @return mixed
717
     */
718
    public function getImages()
719
    {
720
        static $ret;
721
        $itemid = $this->getVar('itemid');
722
        if (!isset($ret[$itemid])) {
723
            $ret[$itemid]['main']   = '';
724
            $ret[$itemid]['others'] = [];
725
            $imagesIds              = [];
726
            $image                  = $this->getVar('image');
727
            $images                 = $this->getVar('images');
728
            if ('' != $images) {
729
                $imagesIds = \explode('|', $images);
0 ignored issues
show
Bug introduced by
It seems like $images can also be of type array and array; however, parameter $string of explode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

729
                $imagesIds = \explode('|', /** @scrutinizer ignore-type */ $images);
Loading history...
730
            }
731
            if ($image > 0) {
732
                $imagesIds = \array_merge($imagesIds, [$image]);
733
            }
734
            $imageObjs = [];
735
            if (\count($imagesIds) > 0) {
736
                $imageHandler = \xoops_getHandler('image');
737
                $criteria     = new \CriteriaCompo(new \Criteria('image_id', '(' . \implode(',', $imagesIds) . ')', 'IN'));
738
                $imageObjs    = $imageHandler->getObjects($criteria, true);
0 ignored issues
show
Bug introduced by
The method getObjects() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of said class. However, the method does not exist in XoopsRankHandler or XoUserHandler or XoopsModules\Publisher\PermissionHandler. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

738
                /** @scrutinizer ignore-call */ 
739
                $imageObjs    = $imageHandler->getObjects($criteria, true);
Loading history...
739
                unset($criteria);
740
            }
741
            foreach ($imageObjs as $id => $imageObj) {
742
                if ($id == $image) {
743
                    $ret[$itemid]['main'] = $imageObj;
744
                } else {
745
                    $ret[$itemid]['others'][] = $imageObj;
746
                }
747
                unset($imageObj);
748
            }
749
            unset($imageObjs);
750
        }
751
752
        return $ret[$itemid];
753
    }
754
755
    /**
756
     * @param string $display
757
     * @param int    $maxCharTitle
758
     * @param int    $maxCharSummary
759
     * @param bool   $fullSummary
760
     *
761
     * @return array
762
     */
763
    public function toArraySimple($display = 'default', $maxCharTitle = 0, $maxCharSummary = 300, $fullSummary = false)
0 ignored issues
show
Unused Code introduced by
The parameter $fullSummary is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

763
    public function toArraySimple($display = 'default', $maxCharTitle = 0, $maxCharSummary = 300, /** @scrutinizer ignore-unused */ $fullSummary = false)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
764
    {
765
        $itemPageId = -1;
766
        if (\is_numeric($display)) {
767
            $itemPageId = $display;
768
            $display    = 'all';
769
        }
770
        $item['itemid']     = $this->itemid();
0 ignored issues
show
Comprehensibility Best Practice introduced by
$item was never initialized. Although not strictly required by PHP, it is generally a good practice to add $item = array(); before regardless.
Loading history...
771
        $item['uid']        = $this->uid();
772
        $item['itemurl']    = $this->getItemUrl();
773
        $item['titlelink']  = $this->getItemLink('titlelink', $maxCharTitle);
774
        $item['subtitle']   = $this->subtitle();
775
        $item['datesub']    = $this->getDatesub();
776
        $item['dateexpire'] = $this->getDateExpire();
777
        $item['counter']    = $this->counter();
778
        $item['hits']      = '&nbsp;' . $this->counter() . ' ' . _READS . '';
779
        $item['who']        = $this->getWho();
780
        $item['when']       = $this->getWhen();
781
        $item['category']   = $this->getCategoryName();
782
		$item['categorylink'] = $this->getCategoryLink();
783
		$item['cancomment']   = $this->cancomment();
784
        $comments = $this->comments();
785
            if ($comments > 0) {
786
                //shows 1 comment instead of 1 comm. if comments ==1
787
                //langugage file modified accordingly
788
                if (1 == $comments) {
789
                    $item['comments'] = '&nbsp;' . \_MD_PUBLISHER_ONECOMMENT . '&nbsp;';
790
                } else {
791
                    $item['comments'] = '&nbsp;' . $comments . '&nbsp;' . \_MD_PUBLISHER_COMMENTS . '&nbsp;';
792
                }
793
            } else {
794
                $item['comments'] = '&nbsp;' . \_MD_PUBLISHER_NO_COMMENTS . '&nbsp;';
795
            }
796
        $item               = $this->getMainImage($item);
797
        switch ($display) {
798
            case 'summary':
799
			    $item = $this->toArrayFull($item);
800
                $item = $this->toArrayAll($item, $itemPageId);
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment if this fall-through is intended.
Loading history...
801
            case 'list':
802
			    $item = $this->toArrayFull($item);
803
                $item = $this->toArrayAll($item, $itemPageId);
804
                //break;
805
            case 'full':
806
			    $item = $this->toArrayFull($item);
807
                $item = $this->toArrayAll($item, $itemPageId);
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment if this fall-through is intended.
Loading history...
808
            case 'wfsection':
809
			    $item = $this->toArrayFull($item);
810
                $item = $this->toArrayAll($item, $itemPageId);
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment if this fall-through is intended.
Loading history...
811
            case 'default':
812
			    $item = $this->toArrayFull($item);
813
                $item = $this->toArrayAll($item, $itemPageId);
814
                $summary = $this->getSummary($maxCharSummary);
815
                if (!$summary) {
816
                    $summary = $this->getBody($maxCharSummary);
817
                }
818
                $item['summary']   = $summary;
819
                $item['truncated'] = $maxCharSummary > 0 && mb_strlen($summary) > $maxCharSummary;
820
                $item              = $this->toArrayFull($item);
821
                break;
822
            case 'all':
823
                $item = $this->toArrayFull($item);
824
                $item = $this->toArrayAll($item, $itemPageId);
825
                break;
826
        }
827
        // Highlighting searched words
828
        $highlight = true;
829
        if ($highlight && Request::getString('keywords', '', 'GET')) {
830
            $myts     = \MyTextSanitizer::getInstance();
831
            $keywords = $myts->htmlSpecialChars(\trim(\urldecode(Request::getString('keywords', '', 'GET'))));
832
            $fields   = ['title', 'maintext', 'summary'];
833
            foreach ($fields as $field) {
834
                if (isset($item[$field])) {
835
                    $item[$field] = $this->highlight($item[$field], $keywords);
836
                }
837
            }
838
        }
839
840
        return $item;
841
    }
842
843
    /**
844
     * @param array $item
845
     *
846
     * @return array
847
     */
848
    public function toArrayFull($item)
849
    {
850
        $item['title']        = $this->getTitle();
851
        $item['clean_title']  = $this->getTitle();
852
        $item['itemurl']      = $this->getItemUrl();
853
        
854
        $item['adminlink']    = $this->getAdminLinks();
855
		$item['pdfbutton']    = $this->getPdfButton();
856
		$item['printlink']    = $this->getPrintLinks();
857
        $item['categoryPath'] = $this->getCategoryPath($this->helper->getConfig('format_linked_path'));
858
        $item['who_when']     = $this->getWhoAndWhen();
859
        $item['who']          = $this->getWho();
860
        $item['when']         = $this->getWhen();
861
        $item['category']     = $this->getCategoryName();
862
		$item['body']         = $this->getBody();
863
		$item['more']         = $this->getItemUrl();
864
        $item                 = $this->getMainImage($item);
865
866
        return $item;
867
    }
868
869
    /**
870
     * @param array $item
871
     * @param int   $itemPageId
872
     *
873
     * @return array
874
     */
875
    public function toArrayAll($item, $itemPageId)
876
    {
877
        $item['maintext'] = $this->buildMainText($itemPageId, $this->getBody());
878
        $item             = $this->getOtherImages($item);
879
880
        return $item;
881
    }
882
883
    /**
884
     * @param array $item
885
     *
886
     * @return array
887
     */
888
    public function getMainImage($item = [])
889
    {
890
        $images             = $this->getImages();
891
        $item['image_path'] = '';
892
        $item['image_name'] = '';
893
        if (\is_object($images['main'])) {
894
            $dimensions           = \getimagesize($GLOBALS['xoops']->path('uploads/' . $images['main']->getVar('image_name')));
895
            $item['image_width']  = $dimensions[0];
896
            $item['image_height'] = $dimensions[1];
897
            $item['image_path']   = XOOPS_URL . '/uploads/' . $images['main']->getVar('image_name');
898
            // check to see if GD function exist
899
            if (!\function_exists('imagecreatetruecolor')) {
900
                $item['image_thumb'] = XOOPS_URL . '/uploads/' . $images['main']->getVar('image_name');
901
            } else {
902
                $item['image_thumb'] = PUBLISHER_URL . '/thumb.php?src=' . XOOPS_URL . '/uploads/' . $images['main']->getVar('image_name') . '&amp;h=180';
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Publisher\PUBLISHER_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
903
            }
904
            $item['image_name'] = $images['main']->getVar('image_nicename');
905
        }
906
907
        return $item;
908
    }
909
910
    /**
911
     * @param array $item
912
     *
913
     * @return array
914
     */
915
    public function getOtherImages($item = [])
916
    {
917
        $images         = $this->getImages();
918
        $item['images'] = [];
919
        $i              = 0;
920
        foreach ($images['others'] as $image) {
921
            $dimensions                   = \getimagesize($GLOBALS['xoops']->path('uploads/' . $image->getVar('image_name')));
922
            $item['images'][$i]['width']  = $dimensions[0];
923
            $item['images'][$i]['height'] = $dimensions[1];
924
            $item['images'][$i]['path']   = XOOPS_URL . '/uploads/' . $image->getVar('image_name');
925
            // check to see if GD function exist
926
            if (!\function_exists('imagecreatetruecolor')) {
927
                $item['images'][$i]['thumb'] = XOOPS_URL . '/uploads/' . $image->getVar('image_name');
928
            } else {
929
                $item['images'][$i]['thumb'] = PUBLISHER_URL . '/thumb.php?src=' . XOOPS_URL . '/uploads/' . $image->getVar('image_name') . '&amp;w=240';
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Publisher\PUBLISHER_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
930
            }
931
            $item['images'][$i]['name'] = $image->getVar('image_nicename');
932
            ++$i;
933
        }
934
935
        return $item;
936
    }
937
938
    /**
939
     * @param string       $content
940
     * @param string|array $keywords
941
     *
942
     * @return string Text
943
     */
944
    public function highlight($content, $keywords)
945
    {
946
        $color = $this->helper->getConfig('format_highlight_color');
947
        if (0 !== mb_strpos($color, '#')) {
948
            $color = '#' . $color;
949
        }
950
        require_once __DIR__ . '/Highlighter.php';
951
        $highlighter = new Highlighter();
952
        $highlighter->setReplacementString('<span style="font-weight: bolder; background-color: ' . $color . ';">\1</span>');
953
954
        return $highlighter->highlight($content, $keywords);
955
    }
956
957
    /**
958
     *  Create metada and assign it to template
959
     */
960
    public function createMetaTags()
961
    {
962
        $publisherMetagen = new Publisher\Metagen($this->getTitle(), $this->meta_keywords(), $this->meta_description(), $this->category->categoryPath);
0 ignored issues
show
Bug introduced by
The method meta_keywords() does not exist on XoopsModules\Publisher\Item. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

962
        $publisherMetagen = new Publisher\Metagen($this->getTitle(), $this->/** @scrutinizer ignore-call */ meta_keywords(), $this->meta_description(), $this->category->categoryPath);
Loading history...
Bug introduced by
It seems like $this->meta_keywords() can also be of type array and array; however, parameter $keywords of XoopsModules\Publisher\Metagen::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

962
        $publisherMetagen = new Publisher\Metagen($this->getTitle(), /** @scrutinizer ignore-type */ $this->meta_keywords(), $this->meta_description(), $this->category->categoryPath);
Loading history...
Bug introduced by
$this->category->categoryPath of type array is incompatible with the type string expected by parameter $categoryPath of XoopsModules\Publisher\Metagen::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

962
        $publisherMetagen = new Publisher\Metagen($this->getTitle(), $this->meta_keywords(), $this->meta_description(), /** @scrutinizer ignore-type */ $this->category->categoryPath);
Loading history...
Bug introduced by
The method meta_description() does not exist on XoopsModules\Publisher\Item. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

962
        $publisherMetagen = new Publisher\Metagen($this->getTitle(), $this->meta_keywords(), $this->/** @scrutinizer ignore-call */ meta_description(), $this->category->categoryPath);
Loading history...
Bug introduced by
It seems like $this->meta_description() can also be of type array and array; however, parameter $description of XoopsModules\Publisher\Metagen::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

962
        $publisherMetagen = new Publisher\Metagen($this->getTitle(), $this->meta_keywords(), /** @scrutinizer ignore-type */ $this->meta_description(), $this->category->categoryPath);
Loading history...
963
        $publisherMetagen->createMetaTags();
964
    }
965
966
    /**
967
     * @param string $str
968
     *
969
     * @return string
970
     */
971
    protected function convertForJapanese($str)
972
    {
973
        // no action, if not flag
974
        if (!\defined('_PUBLISHER_FLAG_JP_CONVERT')) {
975
            return $str;
976
        }
977
        // no action, if not Japanese
978
        if ('japanese' !== $GLOBALS['xoopsConfig']['language']) {
979
            return $str;
980
        }
981
        // presume OS Browser
982
        $agent   = Request::getString('HTTP_USER_AGENT', '', 'SERVER');
983
        $os      = '';
984
        $browser = '';
985
        //        if (preg_match("/Win/i", $agent)) {
986
        if (false !== mb_stripos($agent, 'Win')) {
987
            $os = 'win';
988
        }
989
        //        if (preg_match("/MSIE/i", $agent)) {
990
        if (false !== mb_stripos($agent, 'MSIE')) {
991
            $browser = 'msie';
992
        }
993
        // if msie
994
        if (('win' === $os) && ('msie' === $browser)) {
995
            // if multibyte
996
            if (\function_exists('mb_convert_encoding')) {
997
                $str = mb_convert_encoding($str, 'SJIS', 'EUC-JP');
998
                $str = \rawurlencode($str);
999
            }
1000
        }
1001
1002
        return $str;
1003
    }
1004
1005
    /**
1006
     * @param string $title
1007
     * @param bool   $checkperm
1008
     *
1009
     * @return \XoopsModules\Publisher\Form\ItemForm
1010
     */
1011
    public function getForm($title = 'default', $checkperm = true)
1012
    {
1013
        //        require_once $GLOBALS['xoops']->path('modules/' . PUBLISHER_DIRNAME . '/class/form/item.php');
1014
        $form = new Publisher\Form\ItemForm($title, 'form', \xoops_getenv('SCRIPT_NAME'), 'post', true);
1015
        $form->setCheckPermissions($checkperm);
1016
        $form->createElements($this);
1017
1018
        return $form;
1019
    }
1020
1021
    /**
1022
     * Checks if a user has access to a selected item. if no item permissions are
1023
     * set, access permission is denied. The user needs to have necessary category
1024
     * permission as well.
1025
     * Also, the item needs to be Published
1026
     *
1027
     * @return bool : TRUE if the no errors occured
1028
     */
1029
    public function accessGranted()
1030
    {
1031
        if (Publisher\Utility::userIsAdmin()) {
1032
            return true;
1033
        }
1034
        if (Constants::PUBLISHER_STATUS_PUBLISHED != $this->getVar('status')) {
1035
            return false;
1036
        }
1037
        // Do we have access to the parent category
1038
        if ($this->helper->getHandler('Permission')->isGranted('category_read', $this->categoryid())) {
1039
            return true;
1040
        }
1041
1042
        return false;
1043
    }
1044
1045
    /**
1046
     * The name says it all
1047
     */
1048
    public function setVarsFromRequest()
1049
    {
1050
        //Required fields
1051
        //        if (!empty($categoryid = Request::getInt('categoryid', 0, 'POST'))) {
1052
        //            $this->setVar('categoryid', $categoryid);}
1053
1054
        $this->setVar('categoryid', Request::getInt('categoryid', 0, 'POST'));
1055
        $this->setVar('title', Request::getString('title', '', 'POST'));
1056
        $this->setVar('body', Request::getText('body', '', 'POST'));
1057
1058
        //Not required fields
1059
        $this->setVar('summary', Request::getText('summary', '', 'POST'));
1060
        $this->setVar('subtitle', Request::getString('subtitle', '', 'POST'));
1061
        $this->setVar('item_tag', Request::getString('item_tag', '', 'POST'));
1062
1063
        if ('' !== ($imageFeatured = Request::getString('image_featured', '', 'POST'))) {
1064
            $imageItem = Request::getArray('image_item', [], 'POST');
1065
            //            $imageFeatured = Request::getString('image_featured', '', 'POST');
1066
            //Todo: get a better image class for xoops!
1067
            //Image hack
1068
            $imageItemIds = [];
1069
1070
            $sql    = 'SELECT image_id, image_name FROM ' . $GLOBALS['xoopsDB']->prefix('image');
1071
            $result = $GLOBALS['xoopsDB']->query($sql, 0, 0);
1072
            while (false !== ($myrow = $GLOBALS['xoopsDB']->fetchArray($result))) {
1073
                $imageName = $myrow['image_name'];
1074
                $id        = $myrow['image_id'];
1075
                if ($imageName == $imageFeatured) {
1076
                    $this->setVar('image', $id);
1077
                }
1078
                if (\in_array($imageName, $imageItem)) {
1079
                    $imageItemIds[] = $id;
1080
                }
1081
            }
1082
            $this->setVar('images', \implode('|', $imageItemIds));
1083
        } else {
1084
            $this->setVar('image', 0);
1085
            $this->setVar('images', '');
1086
        }
1087
1088
        if (false !== ($authorAlias = Request::getString('author_alias', '', 'POST'))) {
0 ignored issues
show
introduced by
The condition false !== $authorAlias =...hor_alias', '', 'POST') is always true.
Loading history...
1089
            $this->setVar('author_alias', $authorAlias);
1090
            if ('' !== $this->getVar('author_alias')) {
1091
                $this->setVar('uid', 0);
1092
            }
1093
        }
1094
1095
        //mb TODO check on version
1096
        //check if date is set and convert it to GMT date
1097
        //        if (($datesub = Request::getString('datesub', '', 'POST'))) {
1098
        if ('' !== Request::getString('datesub', '', 'POST')) {
1099
            //            if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
1100
            //                $this->setVar('datesub', strtotime(Request::getArray('datesub', array(), 'POST')['date']) + Request::getArray('datesub', array(), 'POST')['time']);
1101
            //            } else {
1102
            $resDate = Request::getArray('datesub', [], 'POST');
1103
            $resTime = Request::getArray('datesub', [], 'POST');
1104
            //            $this->setVar('datesub', strtotime($resDate['date']) + $resTime['time']);
1105
            //$localTimestamp = strtotime($resDate['date']) + $resTime['time'];
1106
            $dateTimeObj = \DateTime::createFromFormat(_SHORTDATESTRING, $resDate['date']);
1107
            $dateTimeObj->setTime(0, 0, 0);
1108
            $localTimestamp = $dateTimeObj->getTimestamp() + $resTime['time'];
1109
1110
            // get user Timezone offset and use it to find out the Timezone, needed for PHP DataTime
1111
            $userTimeoffset = $GLOBALS['xoopsUser']->getVar('timezone_offset');
1112
            $tz             = \timezone_name_from_abbr(null, $userTimeoffset * 3600);
1113
            if (false === $tz) {
1114
                $tz = \timezone_name_from_abbr(null, $userTimeoffset * 3600, false);
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type integer expected by parameter $isdst of timezone_name_from_abbr(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1114
                $tz = \timezone_name_from_abbr(null, $userTimeoffset * 3600, /** @scrutinizer ignore-type */ false);
Loading history...
1115
            }
1116
1117
            $userTimezone = new \DateTimeZone($tz);
1118
            $gmtTimezone  = new \DateTimeZone('GMT');
1119
            $myDateTime   = new \DateTime('now', $gmtTimezone);
1120
            $offset       = $userTimezone->getOffset($myDateTime);
1121
1122
            $gmtTimestamp = $localTimestamp - $offset;
1123
            $this->setVar('datesub', $gmtTimestamp);
1124
            //            }
1125
        } elseif ($this->isNew()) {
1126
            $this->setVar('datesub', \time());
1127
        }
1128
        
1129
        // date expire
1130
        if (0 !== Request::getInt('use_expire_yn', 0, 'POST')) {
1131
            if ('' !== Request::getString('dateexpire', '', 'POST')) {
1132
                $resExDate = Request::getArray('dateexpire', [], 'POST');
1133
                $resExTime = Request::getArray('dateexpire', [], 'POST');
1134
                //$localTimestamp = strtotime($resExDate['date']) + $resExTime['time'];
1135
                $dateTimeObj = \DateTime::createFromFormat(_SHORTDATESTRING, $resExDate['date']);
1136
                $dateTimeObj->setTime(0, 0, 0);
1137
                $localTimestamp = $dateTimeObj->getTimestamp() + $resExTime['time'];
1138
1139
                // get user Timezone offset and use it to find out the Timezone, needed for PHP DataTime
1140
                $userTimeoffset = $GLOBALS['xoopsUser']->getVar('timezone_offset');
1141
                $tz             = \timezone_name_from_abbr(null, $userTimeoffset * 3600);
1142
                if (false === $tz) {
1143
                    $tz = \timezone_name_from_abbr(null, $userTimeoffset * 3600, false);
1144
                }
1145
1146
                $userTimezone = new \DateTimeZone($tz);
1147
                $gmtTimezone  = new \DateTimeZone('GMT');
1148
                $myDateTime   = new \DateTime('now', $gmtTimezone);
1149
                $offset       = $userTimezone->getOffset($myDateTime);
1150
1151
                $gmtTimestamp = $localTimestamp - $offset;
1152
                $this->setVar('dateexpire', $gmtTimestamp);
1153
            }
1154
        } else {
1155
            $this->setVar('dateexpire', 0);
1156
        }
1157
1158
        $this->setVar('short_url', Request::getString('item_short_url', '', 'POST'));
1159
        $this->setVar('meta_keywords', Request::getString('item_meta_keywords', '', 'POST'));
1160
        $this->setVar('meta_description', Request::getString('item_meta_description', '', 'POST'));
1161
        $this->setVar('weight', Request::getInt('weight', 0, 'POST'));
1162
1163
        if ($this->isNew()) {
1164
            $this->setVar('uid', \is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->uid() : 0);
1165
            $this->setVar('cancoment', $this->helper->getConfig('submit_allowcomments'));
1166
            $this->setVar('status', $this->helper->getConfig('submit_status'));
1167
            $this->setVar('dohtml', $this->helper->getConfig('submit_dohtml'));
1168
            $this->setVar('dosmiley', $this->helper->getConfig('submit_dosmiley'));
1169
            $this->setVar('doxcode', $this->helper->getConfig('submit_doxcode'));
1170
            $this->setVar('doimage', $this->helper->getConfig('submit_doimage'));
1171
            $this->setVar('dobr', $this->helper->getConfig('submit_dobr'));
1172
        } else {
1173
            $this->setVar('uid', Request::getInt('uid', 0, 'POST'));
1174
            $this->setVar('cancomment', Request::getInt('allowcomments', 1, 'POST'));
1175
            $this->setVar('status', Request::getInt('status', 1, 'POST'));
1176
            $this->setVar('dohtml', Request::getInt('dohtml', 1, 'POST'));
1177
            $this->setVar('dosmiley', Request::getInt('dosmiley', 1, 'POST'));
1178
            $this->setVar('doxcode', Request::getInt('doxcode', 1, 'POST'));
1179
            $this->setVar('doimage', Request::getInt('doimage', 1, 'POST'));
1180
            $this->setVar('dobr', Request::getInt('dolinebreak', 1, 'POST'));
1181
        }
1182
1183
        $this->setVar('notifypub', Request::getString('notify', '', 'POST'));
1184
    }
1185
}
1186