| Total Complexity | 171 |
| Total Lines | 1183 |
| Duplicated Lines | 0 % |
| Changes | 18 | ||
| Bugs | 1 | Features | 1 |
Complex classes like Item often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Item, and based on these observations, apply Extract Interface, too.
| 1 | <?php declare(strict_types=1); |
||
| 32 | class Item extends \XoopsObject |
||
| 33 | { |
||
| 34 | public const PAGEWRAP = '[pagewrap='; |
||
| 35 | public const BODYTAG = '<body>'; |
||
| 36 | /** |
||
| 37 | * @var Helper |
||
| 38 | */ |
||
| 39 | public $helper; |
||
| 40 | /** @var \XoopsMySQLDatabase */ |
||
| 41 | public $db; |
||
| 42 | public $groupsRead = []; |
||
| 43 | /** |
||
| 44 | * @var Category |
||
| 45 | */ |
||
| 46 | public $category; |
||
| 47 | public $groups_read; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @param int|null $id |
||
| 51 | */ |
||
| 52 | public function __construct($id = null) |
||
| 53 | { |
||
| 54 | // $this->helper = Helper::getInstance(); |
||
| 55 | $this->db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 56 | $this->initVar('itemid', \XOBJ_DTYPE_INT, 0); |
||
| 57 | $this->initVar('categoryid', \XOBJ_DTYPE_INT, 0, false); |
||
| 58 | $this->initVar('title', \XOBJ_DTYPE_TXTBOX, '', true, 255); |
||
| 59 | $this->initVar('subtitle', \XOBJ_DTYPE_TXTBOX, '', false, 255); |
||
| 60 | $this->initVar('summary', \XOBJ_DTYPE_TXTAREA, '', false); |
||
| 61 | $this->initVar('body', \XOBJ_DTYPE_TXTAREA, '', false); |
||
| 62 | $this->initVar('uid', \XOBJ_DTYPE_INT, 0, false); |
||
| 63 | $this->initVar('author_alias', \XOBJ_DTYPE_TXTBOX, '', false, 255); |
||
| 64 | $this->initVar('datesub', \XOBJ_DTYPE_INT, '', false); |
||
| 65 | $this->initVar('dateexpire', \XOBJ_DTYPE_INT, '', false); |
||
| 66 | $this->initVar('status', \XOBJ_DTYPE_INT, -1, false); |
||
| 67 | $this->initVar('image', \XOBJ_DTYPE_INT, 0, false); |
||
| 68 | $this->initVar('images', \XOBJ_DTYPE_TXTBOX, '', false, 255); |
||
| 69 | $this->initVar('counter', \XOBJ_DTYPE_INT, 0, false); |
||
| 70 | $this->initVar('rating', \XOBJ_DTYPE_OTHER, 0, false); |
||
| 71 | $this->initVar('votes', \XOBJ_DTYPE_INT, 0, false); |
||
| 72 | $this->initVar('weight', \XOBJ_DTYPE_INT, 0, false); |
||
| 73 | $this->initVar('dohtml', \XOBJ_DTYPE_INT, 1, true); |
||
| 74 | $this->initVar('dosmiley', \XOBJ_DTYPE_INT, 1, true); |
||
| 75 | $this->initVar('doimage', \XOBJ_DTYPE_INT, 1, true); |
||
| 76 | $this->initVar('dobr', \XOBJ_DTYPE_INT, 1, false); |
||
| 77 | $this->initVar('doxcode', \XOBJ_DTYPE_INT, 1, true); |
||
| 78 | $this->initVar('cancomment', \XOBJ_DTYPE_INT, 1, true); |
||
| 79 | $this->initVar('comments', \XOBJ_DTYPE_INT, 0, false); |
||
| 80 | $this->initVar('notifypub', \XOBJ_DTYPE_INT, 1, false); |
||
| 81 | $this->initVar('meta_keywords', \XOBJ_DTYPE_TXTAREA, '', false); |
||
| 82 | $this->initVar('meta_description', \XOBJ_DTYPE_TXTAREA, '', false); |
||
| 83 | $this->initVar('short_url', \XOBJ_DTYPE_TXTBOX, '', false, 255); |
||
| 84 | $this->initVar('item_tag', \XOBJ_DTYPE_TXTAREA, '', false); |
||
| 85 | $this->initVar('votetype', \XOBJ_DTYPE_INT, 0, false); |
||
| 86 | // Non consistent values |
||
| 87 | $this->initVar('pagescount', \XOBJ_DTYPE_INT, 0, false); |
||
| 88 | if (null !== $id) { |
||
| 89 | $item = $this->helper->getHandler('Item') |
||
| 90 | ->get($id); |
||
| 91 | foreach ($item->vars as $k => $v) { |
||
| 92 | $this->assignVar($k, $v['value']); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @param string $method |
||
| 99 | * @param array $args |
||
| 100 | * |
||
| 101 | * @return mixed |
||
| 102 | */ |
||
| 103 | public function __call(string $method, array $args) |
||
| 104 | { |
||
| 105 | $arg = $args[0] ?? ''; //mb changed to empty string as in PHP 8.1 Passing null to parameter of type string is deprecated (in object.php on line 441) |
||
| 106 | |||
| 107 | return $this->getVar($method, $arg); |
||
| 108 | } |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @return null|Category |
||
| 112 | */ |
||
| 113 | public function getCategory() |
||
| 114 | { |
||
| 115 | if (null === $this->category) { |
||
| 116 | $this->category = $this->helper->getHandler('Category') |
||
| 117 | ->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) { |
||
| 135 | $ret = Utility::substr($ret, 0, $maxLength); |
||
|
|
|||
| 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) { |
||
| 155 | $ret = Utility::substr($ret, 0, $maxLength); |
||
| 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); |
||
| 175 | } |
||
| 176 | if (0 != $maxLength) { |
||
| 177 | if (!XOOPS_USE_MULTIBYTES) { |
||
| 178 | if (\mb_strlen($ret) >= $maxLength) { |
||
| 179 | //$ret = Utility::substr($ret , 0, $maxLength); |
||
| 180 | // $ret = Utility::truncateTagSafe($ret, $maxLength, $etc = '...', $breakWords = false); |
||
| 181 | $ret = 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 = Utility::getUploadDir(true, 'content') . $fileName; |
||
| 219 | if (\is_file($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, self::BODYTAG); |
||
| 226 | if ($bodyStartPos) { |
||
| 227 | $bodyEndPos = \mb_strpos($content, '</body>', $bodyStartPos); |
||
| 228 | $content = \mb_substr($content, $bodyStartPos + \mb_strlen(self::BODYTAG), $bodyEndPos - \mb_strlen(self::BODYTAG) - $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, self::PAGEWRAP); |
||
| 253 | if (!(false === $wrapPos)) { |
||
| 254 | $wrapPages = []; |
||
| 255 | $wrapCodeLength = \mb_strlen(self::PAGEWRAP); |
||
| 256 | while (!(false === $wrapPos)) { |
||
| 257 | $endWrapPos = \mb_strpos($ret, ']', $wrapPos); |
||
| 258 | if ($endWrapPos) { |
||
| 259 | $wrapPagename = \mb_substr($ret, $wrapPos + $wrapCodeLength, $endWrapPos - $wrapCodeLength - $wrapPos); |
||
| 260 | $wrapPages[] = $wrapPagename; |
||
| 261 | } |
||
| 262 | $wrapPos = \mb_strpos($ret, self::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 = Utility::substr($ret , 0, $maxLength); |
||
| 282 | $ret = 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|false |
||
| 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; |
||
| 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) |
||
| 340 | } |
||
| 341 | |||
| 342 | /** |
||
| 343 | * @return string |
||
| 344 | */ |
||
| 345 | public function posterAvatar() |
||
| 346 | { |
||
| 347 | $ret = 'blank.gif'; |
||
| 348 | /** @var \XoopsMemberHandler $memberHandler */ |
||
| 349 | $memberHandler = \xoops_getHandler('member'); |
||
| 350 | $thisUser = $memberHandler->getUser($this->uid()); |
||
| 351 | if (\is_object($thisUser)) { |
||
| 352 | $ret = $thisUser->getVar('user_avatar'); |
||
| 353 | } |
||
| 354 | |||
| 355 | return $ret; |
||
| 356 | } |
||
| 357 | |||
| 358 | /** |
||
| 359 | * @return string |
||
| 360 | */ |
||
| 361 | public function getLinkedPosterName() |
||
| 362 | { |
||
| 363 | \xoops_load('XoopsUserUtility'); |
||
| 364 | $ret = $this->author_alias(); |
||
| 365 | if ('' === $ret) { |
||
| 366 | $ret = \XoopsUserUtility::getUnameFromId($this->uid(), $this->helper->getConfig('format_realname'), true); |
||
| 367 | } |
||
| 368 | |||
| 369 | return $ret; |
||
| 370 | } |
||
| 371 | |||
| 372 | /** |
||
| 373 | * @return mixed |
||
| 374 | */ |
||
| 375 | public function updateCounter() |
||
| 376 | { |
||
| 377 | return $this->helper->getHandler('Item') |
||
| 378 | ->updateCounter($this->itemid()); |
||
| 379 | } |
||
| 380 | |||
| 381 | /** |
||
| 382 | * @param bool $force |
||
| 383 | * |
||
| 384 | * @return bool |
||
| 385 | */ |
||
| 386 | public function store($force = true) |
||
| 387 | { |
||
| 388 | $isNew = $this->isNew(); |
||
| 389 | if (!$this->helper->getHandler('Item') |
||
| 390 | ->insert($this, $force)) { |
||
| 391 | return false; |
||
| 392 | } |
||
| 393 | if ($isNew && Constants::PUBLISHER_STATUS_PUBLISHED == $this->getVar('status')) { |
||
| 394 | // Increment user posts |
||
| 395 | $userHandler = \xoops_getHandler('user'); |
||
| 396 | /** @var \XoopsMemberHandler $memberHandler */ |
||
| 397 | $memberHandler = \xoops_getHandler('member'); |
||
| 398 | /** @var \XoopsUser $poster */ |
||
| 399 | $poster = $userHandler->get($this->uid()); |
||
| 400 | if (\is_object($poster) && !$poster->isNew()) { |
||
| 401 | $poster->setVar('posts', $poster->getVar('posts') + 1); |
||
| 402 | if (!$memberHandler->insertUser($poster, true)) { |
||
| 403 | $this->setErrors('Article created but could not increment user posts.'); |
||
| 404 | |||
| 405 | return false; |
||
| 406 | } |
||
| 407 | } |
||
| 408 | } |
||
| 409 | |||
| 410 | return true; |
||
| 411 | } |
||
| 412 | |||
| 413 | /** |
||
| 414 | * @return string |
||
| 415 | */ |
||
| 416 | public function getCategoryName() |
||
| 417 | { |
||
| 418 | return $this->getCategory() |
||
| 419 | ->name(); |
||
| 420 | } |
||
| 421 | |||
| 422 | /** |
||
| 423 | * @return string |
||
| 424 | */ |
||
| 425 | public function getCategoryUrl() |
||
| 426 | { |
||
| 427 | return $this->getCategory() |
||
| 428 | ->getCategoryUrl(); |
||
| 429 | } |
||
| 430 | |||
| 431 | /** |
||
| 432 | * @return string |
||
| 433 | */ |
||
| 434 | public function getCategoryLink() |
||
| 435 | { |
||
| 436 | return $this->getCategory() |
||
| 437 | ->getCategoryLink(); |
||
| 438 | } |
||
| 439 | |||
| 440 | /** |
||
| 441 | * @param bool $withAllLink |
||
| 442 | * |
||
| 443 | * @return array|bool|string |
||
| 444 | */ |
||
| 445 | public function getCategoryPath($withAllLink = true) |
||
| 446 | { |
||
| 447 | return $this->getCategory() |
||
| 448 | ->getCategoryPath($withAllLink); |
||
| 449 | } |
||
| 450 | |||
| 451 | /** |
||
| 452 | * @return string |
||
| 453 | */ |
||
| 454 | public function getCategoryImagePath() |
||
| 455 | { |
||
| 456 | return Utility::getImageDir('category', false) . $this->getCategory() |
||
| 457 | ->getImage(); |
||
| 458 | } |
||
| 459 | |||
| 460 | /** |
||
| 461 | * @return mixed |
||
| 462 | */ |
||
| 463 | public function getFiles() |
||
| 464 | { |
||
| 465 | return $this->helper->getHandler('File') |
||
| 466 | ->getAllFiles($this->itemid(), Constants::PUBLISHER_STATUS_FILE_ACTIVE); |
||
| 467 | } |
||
| 468 | |||
| 469 | /** |
||
| 470 | * @param $icons |
||
| 471 | * @return string |
||
| 472 | */ |
||
| 473 | public function getAdminLinks($icons) |
||
| 474 | { |
||
| 475 | $adminLinks = ''; |
||
| 476 | if (\is_object($GLOBALS['xoopsUser']) |
||
| 477 | && (Utility::userIsAdmin() || Utility::userIsAuthor($this) |
||
| 478 | || $this->helper->getHandler('Permission') |
||
| 479 | ->isGranted('item_submit', $this->categoryid()))) { |
||
| 480 | if (Utility::userIsAdmin() || Utility::userIsAuthor($this) || Utility::userIsModerator($this)) { |
||
| 481 | if ($this->helper->getConfig('perm_edit') || Utility::userIsModerator($this) || Utility::userIsAdmin()) { |
||
| 482 | // Edit button |
||
| 483 | $adminLinks .= "<a href='" . PUBLISHER_URL . '/submit.php?itemid=' . $this->itemid() . "'>" . $icons['edit'] . '</a>'; |
||
| 484 | $adminLinks .= ' '; |
||
| 485 | } |
||
| 486 | if ($this->helper->getConfig('perm_delete') || Utility::userIsModerator($this) || Utility::userIsAdmin()) { |
||
| 487 | // Delete button |
||
| 488 | $adminLinks .= "<a href='" . PUBLISHER_URL . '/submit.php?op=del&itemid=' . $this->itemid() . "'>" . $icons['delete'] . '</a>'; |
||
| 489 | $adminLinks .= ' '; |
||
| 490 | } |
||
| 491 | } |
||
| 492 | if ($this->helper->getConfig('perm_clone') || Utility::userIsModerator($this) || Utility::userIsAdmin()) { |
||
| 493 | // Duplicate button |
||
| 494 | $adminLinks .= "<a href='" . PUBLISHER_URL . '/submit.php?op=clone&itemid=' . $this->itemid() . "'>" . $icons['clone'] . '</a>'; |
||
| 495 | $adminLinks .= ' '; |
||
| 496 | } |
||
| 497 | } |
||
| 498 | |||
| 499 | return $adminLinks; |
||
| 500 | } |
||
| 501 | |||
| 502 | /** |
||
| 503 | * @param $icons |
||
| 504 | * @return string |
||
| 505 | */ |
||
| 506 | public function getPdfButton($icons) |
||
| 507 | { |
||
| 508 | $pdfButton = ''; |
||
| 509 | // PDF button |
||
| 510 | if (\is_file(XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php')) { |
||
| 511 | $pdfButton .= "<a href='" . PUBLISHER_URL . '/makepdf.php?itemid=' . $this->itemid() . "' rel='nofollow' target='_blank'>" . $icons['pdf'] . '</a> '; |
||
| 512 | $pdfButton .= ' '; |
||
| 513 | } |
||
| 514 | // if (is_object($GLOBALS['xoopsUser']) && Utility::userIsAdmin()) { |
||
| 515 | // $GLOBALS['xoTheme']->addStylesheet('/modules/system/css/jquery.jgrowl.min.css'); |
||
| 516 | // $GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/plugins/jquery.jgrowl.js'); |
||
| 517 | // $adminLinks .= '<script type="text/javascript"> |
||
| 518 | // (function($){ |
||
| 519 | // $(document).ready(function(){ |
||
| 520 | // $.jGrowl("' . _MD_PUBLISHER_ERROR_NO_PDF . '");}); |
||
| 521 | // })(jQuery); |
||
| 522 | // </script>'; |
||
| 523 | // } |
||
| 524 | |||
| 525 | return $pdfButton; |
||
| 526 | } |
||
| 527 | |||
| 528 | /** |
||
| 529 | * @param $icons |
||
| 530 | * @return string |
||
| 531 | */ |
||
| 532 | public function getPrintLinks($icons) |
||
| 533 | { |
||
| 534 | $printLinks = ''; |
||
| 535 | // Print button |
||
| 536 | $printLinks .= "<a href='" . Seo::generateUrl('print', $this->itemid(), $this->short_url()) . "' rel='nofollow' target='_blank'>" . $icons['print'] . '</a> '; |
||
| 537 | $printLinks .= ' '; |
||
| 538 | |||
| 539 | return $printLinks; |
||
| 540 | } |
||
| 541 | |||
| 542 | /** |
||
| 543 | * @param array $notifications |
||
| 544 | */ |
||
| 545 | public function sendNotifications($notifications = []): void |
||
| 546 | { |
||
| 547 | /** @var \XoopsNotificationHandler $notificationHandler */ |
||
| 548 | $notificationHandler = \xoops_getHandler('notification'); |
||
| 549 | $tags = []; |
||
| 550 | |||
| 551 | $tags['MODULE_NAME'] = $this->helper->getModule() |
||
| 552 | ->getVar('name'); |
||
| 553 | $tags['ITEM_NAME'] = $this->getTitle(); |
||
| 554 | $tags['ITEM_SUBNAME'] = $this->getSubtitle(); |
||
| 555 | $tags['CATEGORY_NAME'] = $this->getCategoryName(); |
||
| 556 | $tags['CATEGORY_URL'] = PUBLISHER_URL . '/category.php?categoryid=' . $this->categoryid(); |
||
| 557 | $tags['ITEM_BODY'] = $this->body(); |
||
| 558 | $tags['DATESUB'] = $this->getDatesub(); |
||
| 559 | foreach ($notifications as $notification) { |
||
| 560 | switch ($notification) { |
||
| 561 | case Constants::PUBLISHER_NOTIFY_ITEM_PUBLISHED: |
||
| 562 | $tags['ITEM_URL'] = PUBLISHER_URL . '/item.php?itemid=' . $this->itemid(); |
||
| 563 | $notificationHandler->triggerEvent('global_item', 0, 'published', $tags, [], $this->helper->getModule() |
||
| 564 | ->getVar('mid')); |
||
| 565 | $notificationHandler->triggerEvent('category_item', $this->categoryid(), 'published', $tags, [], $this->helper->getModule() |
||
| 566 | ->getVar('mid')); |
||
| 567 | $notificationHandler->triggerEvent('item', $this->itemid(), 'approved', $tags, [], $this->helper->getModule() |
||
| 568 | ->getVar('mid')); |
||
| 569 | break; |
||
| 570 | case Constants::PUBLISHER_NOTIFY_ITEM_SUBMITTED: |
||
| 571 | $tags['WAITINGFILES_URL'] = PUBLISHER_URL . '/admin/item.php?itemid=' . $this->itemid(); |
||
| 572 | $notificationHandler->triggerEvent('global_item', 0, 'submitted', $tags, [], $this->helper->getModule() |
||
| 573 | ->getVar('mid')); |
||
| 574 | $notificationHandler->triggerEvent('category_item', $this->categoryid(), 'submitted', $tags, [], $this->helper->getModule() |
||
| 575 | ->getVar('mid')); |
||
| 576 | break; |
||
| 577 | case Constants::PUBLISHER_NOTIFY_ITEM_REJECTED: |
||
| 578 | $notificationHandler->triggerEvent('item', $this->itemid(), 'rejected', $tags, [], $this->helper->getModule() |
||
| 579 | ->getVar('mid')); |
||
| 580 | break; |
||
| 581 | case -1: |
||
| 582 | default: |
||
| 583 | break; |
||
| 584 | } |
||
| 585 | } |
||
| 586 | } |
||
| 587 | |||
| 588 | /** |
||
| 589 | * Sets default permissions for this item |
||
| 590 | */ |
||
| 591 | public function setDefaultPermissions(): void |
||
| 592 | { |
||
| 593 | $memberHandler = \xoops_getHandler('member'); |
||
| 594 | $groups = $memberHandler->getGroupList(); |
||
| 595 | $groupIds = \count($groups) > 0 ? \array_keys($groups) : []; |
||
| 596 | /* |
||
| 597 | $j = 0; |
||
| 598 | $groupIds = []; |
||
| 599 | foreach (array_keys($groups) as $i) { |
||
| 600 | $groupIds[$j] = $i; |
||
| 601 | ++$j; |
||
| 602 | } |
||
| 603 | */ |
||
| 604 | $this->groupsRead = $groupIds; |
||
| 605 | } |
||
| 606 | |||
| 607 | /** |
||
| 608 | * @param $groupIds |
||
| 609 | * @deprecated - NOT USED |
||
| 610 | * |
||
| 611 | * @todo look at this |
||
| 612 | */ |
||
| 613 | public function setPermissions($groupIds): void |
||
| 617 | /* |
||
| 618 | $memberHandler = xoops_getHandler('member'); |
||
| 619 | $groups = $memberHandler->getGroupList(); |
||
| 620 | $j = 0; |
||
| 621 | $groupIds = []; |
||
| 622 | foreach (array_keys($groups) as $i) { |
||
| 623 | $groupIds[$j] = $i; |
||
| 624 | ++$j; |
||
| 625 | } |
||
| 626 | */ |
||
| 627 | } |
||
| 628 | } |
||
| 629 | |||
| 630 | /** |
||
| 631 | * @return bool |
||
| 632 | */ |
||
| 633 | public function notLoaded() |
||
| 634 | { |
||
| 635 | return -1 == $this->getVar('itemid'); |
||
| 636 | } |
||
| 637 | |||
| 638 | /** |
||
| 639 | * @return string |
||
| 640 | */ |
||
| 641 | public function getItemUrl() |
||
| 642 | { |
||
| 643 | return Seo::generateUrl('item', $this->itemid(), $this->short_url()); |
||
| 644 | } |
||
| 645 | |||
| 646 | /** |
||
| 647 | * @param bool $class |
||
| 648 | * @param int $maxsize |
||
| 649 | * |
||
| 650 | * @return string |
||
| 651 | */ |
||
| 652 | public function getItemLink($class = false, $maxsize = 0) |
||
| 653 | { |
||
| 654 | if ($class) { |
||
| 655 | return '<a class="' . $class . '" href="' . $this->getItemUrl() . '">' . $this->getTitle($maxsize) . '</a>'; |
||
| 656 | } |
||
| 657 | |||
| 658 | return '<a href="' . $this->getItemUrl() . '">' . $this->getTitle($maxsize) . '</a>'; |
||
| 659 | } |
||
| 660 | |||
| 661 | /** |
||
| 662 | * @return string |
||
| 663 | */ |
||
| 664 | public function getWhoAndWhen() |
||
| 665 | { |
||
| 666 | $posterName = $this->getLinkedPosterName(); |
||
| 667 | $postdate = $this->getDatesub(); |
||
| 668 | |||
| 669 | return \sprintf(\_CO_PUBLISHER_POSTEDBY, $posterName, $postdate); |
||
| 670 | } |
||
| 671 | |||
| 672 | /** |
||
| 673 | * @return string |
||
| 674 | */ |
||
| 675 | public function getWho() |
||
| 676 | { |
||
| 677 | $posterName = $this->getLinkedPosterName(); |
||
| 678 | |||
| 679 | return $posterName; |
||
| 680 | } |
||
| 681 | |||
| 682 | /** |
||
| 683 | * @return string |
||
| 684 | */ |
||
| 685 | public function getWhen() |
||
| 686 | { |
||
| 687 | $postdate = $this->getDatesub(); |
||
| 688 | |||
| 689 | return $postdate; |
||
| 690 | } |
||
| 691 | |||
| 692 | /** |
||
| 693 | * @param null|string $body |
||
| 694 | * |
||
| 695 | * @return string |
||
| 696 | */ |
||
| 697 | public function plainMaintext($body = null) |
||
| 698 | { |
||
| 699 | $ret = ''; |
||
| 700 | if (!$body) { |
||
| 701 | $body = $this->body(); |
||
| 702 | } |
||
| 703 | $ret .= \str_replace('[pagebreak]', '<br><br>', $body); |
||
| 704 | |||
| 705 | return $ret; |
||
| 706 | } |
||
| 707 | |||
| 708 | /** |
||
| 709 | * @param int $itemPageId |
||
| 710 | * @param null|string $body |
||
| 711 | * |
||
| 712 | * @return string |
||
| 713 | */ |
||
| 714 | public function buildMainText($itemPageId = -1, $body = null) |
||
| 715 | { |
||
| 716 | if (null === $body) { |
||
| 717 | $body = $this->body(); |
||
| 718 | } |
||
| 719 | /** @var array $bodyParts */ |
||
| 720 | $bodyParts = \explode('[pagebreak]', $body); |
||
| 721 | $this->setVar('pagescount', \count($bodyParts)); |
||
| 722 | if (\count($bodyParts) <= 1) { |
||
| 723 | return $this->plainMaintext($body); |
||
| 724 | } |
||
| 725 | $ret = ''; |
||
| 726 | if (-1 == $itemPageId) { |
||
| 727 | $ret .= \trim($bodyParts[0]); |
||
| 728 | |||
| 729 | return $ret; |
||
| 730 | } |
||
| 731 | if ($itemPageId >= \count($bodyParts)) { |
||
| 732 | $itemPageId = \count($bodyParts) - 1; |
||
| 733 | } |
||
| 734 | $ret .= \trim($bodyParts[$itemPageId]); |
||
| 735 | |||
| 736 | return $ret; |
||
| 737 | } |
||
| 738 | |||
| 739 | /** |
||
| 740 | * @return mixed |
||
| 741 | */ |
||
| 742 | public function getImages() |
||
| 743 | { |
||
| 744 | static $ret; |
||
| 745 | $itemId = (int)$this->getVar('itemid'); |
||
| 746 | if (!isset($ret[$itemId])) { |
||
| 747 | $ret[$itemId]['main'] = ''; |
||
| 748 | $ret[$itemId]['others'] = []; |
||
| 749 | /** @var array $imagesIds */ |
||
| 750 | $imagesIds = []; |
||
| 751 | $image = $this->getVar('image'); |
||
| 752 | $images = $this->getVar('images'); |
||
| 753 | if ('' != $images) { |
||
| 754 | $imagesIds = \explode('|', $images); |
||
| 755 | } |
||
| 756 | if ($image > 0 && $imagesIds) { |
||
| 757 | $imagesIds[] = $image; |
||
| 758 | } |
||
| 759 | $imageObjs = []; |
||
| 760 | if (\count($imagesIds) > 0) { |
||
| 761 | $imageHandler = \xoops_getHandler('image'); |
||
| 762 | $criteria = new \CriteriaCompo(new \Criteria('image_id', '(' . \implode(',', $imagesIds) . ')', 'IN')); |
||
| 763 | $imageObjs = $imageHandler->getObjects($criteria, true); |
||
| 764 | unset($criteria); |
||
| 765 | } |
||
| 766 | foreach ($imageObjs as $id => $imageObj) { |
||
| 767 | if ($id == $image) { |
||
| 768 | $ret[$itemId]['main'] = $imageObj; |
||
| 769 | } else { |
||
| 770 | $ret[$itemId]['others'][] = $imageObj; |
||
| 771 | } |
||
| 772 | unset($imageObj); |
||
| 773 | } |
||
| 774 | unset($imageObjs); |
||
| 775 | } |
||
| 776 | |||
| 777 | return $ret[$itemId]; |
||
| 778 | } |
||
| 779 | |||
| 780 | /** |
||
| 781 | * @param string $display |
||
| 782 | * @param int $maxCharTitle |
||
| 783 | * @param int $maxCharSummary |
||
| 784 | * @param bool $fullSummary |
||
| 785 | * |
||
| 786 | * @return array |
||
| 787 | */ |
||
| 788 | public function toArraySimple($display = 'default', $maxCharTitle = 0, $maxCharSummary = 300, $fullSummary = false) |
||
| 789 | { |
||
| 790 | $itemPageId = -1; |
||
| 791 | if (\is_numeric($display)) { |
||
| 792 | $itemPageId = $display; |
||
| 793 | $display = 'all'; |
||
| 794 | } |
||
| 795 | $item['itemid'] = $this->itemid(); |
||
| 796 | $item['uid'] = $this->uid(); |
||
| 797 | $item['itemurl'] = $this->getItemUrl(); |
||
| 798 | $item['titlelink'] = $this->getItemLink('titlelink', $maxCharTitle); |
||
| 799 | $item['subtitle'] = $this->subtitle(); |
||
| 800 | $item['datesub'] = $this->getDatesub(); |
||
| 801 | $item['dateexpire'] = $this->getDateExpire(); |
||
| 802 | $item['counter'] = $this->counter(); |
||
| 803 | $item['hits'] = ' ' . $this->counter() . ' ' . \_READS; |
||
| 804 | $item['who'] = $this->getWho(); |
||
| 805 | $item['when'] = $this->getWhen(); |
||
| 806 | $item['category'] = $this->getCategoryName(); |
||
| 807 | $item['categorylink'] = $this->getCategoryLink(); |
||
| 808 | $item['cancomment'] = $this->cancomment(); |
||
| 809 | $item['votetype'] = $this->votetype(); |
||
| 810 | $comments = $this->comments(); |
||
| 811 | if ($comments > 0) { |
||
| 812 | //shows 1 comment instead of 1 comm. if comments ==1 |
||
| 813 | //langugage file modified accordingly |
||
| 814 | if (1 == $comments) { |
||
| 815 | $item['comments'] = ' ' . \_MD_PUBLISHER_ONECOMMENT . ' '; |
||
| 816 | } else { |
||
| 817 | $item['comments'] = ' ' . $comments . ' ' . \_MD_PUBLISHER_COMMENTS . ' '; |
||
| 818 | } |
||
| 819 | } else { |
||
| 820 | $item['comments'] = ' ' . \_MD_PUBLISHER_NO_COMMENTS . ' '; |
||
| 821 | } |
||
| 822 | $item = $this->getMainImage($item); |
||
| 823 | switch ($display) { |
||
| 824 | case 'summary': |
||
| 825 | $item = $this->toArrayFull($item); |
||
| 826 | $item = $this->toArrayAll($item, $itemPageId); |
||
| 827 | // no break |
||
| 828 | case 'list': |
||
| 829 | $item = $this->toArrayFull($item); |
||
| 830 | $item = $this->toArrayAll($item, $itemPageId); |
||
| 831 | //break; |
||
| 832 | // no break |
||
| 833 | case 'full': |
||
| 834 | $item = $this->toArrayFull($item); |
||
| 835 | $item = $this->toArrayAll($item, $itemPageId); |
||
| 836 | // no break |
||
| 837 | case 'wfsection': |
||
| 838 | $item = $this->toArrayFull($item); |
||
| 839 | $item = $this->toArrayAll($item, $itemPageId); |
||
| 840 | // no break |
||
| 841 | case 'default': |
||
| 842 | $item = $this->toArrayFull($item); |
||
| 843 | $item = $this->toArrayAll($item, $itemPageId); |
||
| 844 | $summary = $this->getSummary($maxCharSummary); |
||
| 845 | if (!$summary) { |
||
| 846 | $summary = $this->getBody($maxCharSummary); |
||
| 847 | } |
||
| 848 | $item['summary'] = $summary; |
||
| 849 | $item['truncated'] = $maxCharSummary > 0 && \mb_strlen($summary) > $maxCharSummary; |
||
| 850 | $item = $this->toArrayFull($item); |
||
| 851 | break; |
||
| 852 | case 'all': |
||
| 853 | $item = $this->toArrayFull($item); |
||
| 854 | $item = $this->toArrayAll($item, $itemPageId); |
||
| 855 | break; |
||
| 856 | } |
||
| 857 | // Highlighting searched words |
||
| 858 | $highlight = true; |
||
| 859 | if ($highlight && Request::getString('keywords', '', 'GET')) { |
||
| 860 | $keywords = \htmlspecialchars(\trim(\urldecode(Request::getString('keywords', '', 'GET'))), \ENT_QUOTES | \ENT_HTML5); |
||
| 861 | $fields = ['title', 'maintext', 'summary']; |
||
| 862 | foreach ($fields as $field) { |
||
| 863 | if (isset($item[$field])) { |
||
| 864 | $item[$field] = $this->highlight($item[$field], $keywords); |
||
| 865 | } |
||
| 866 | } |
||
| 867 | } |
||
| 868 | |||
| 869 | return $item; |
||
| 870 | } |
||
| 871 | |||
| 872 | /** |
||
| 873 | * @param array $item |
||
| 874 | * |
||
| 875 | * @return array |
||
| 876 | */ |
||
| 877 | public function toArrayFull($item) |
||
| 878 | { |
||
| 879 | $configurator = new Common\Configurator(); |
||
| 880 | $icons = $configurator->icons; |
||
| 881 | |||
| 882 | $item['title'] = $this->getTitle(); |
||
| 883 | $item['clean_title'] = $this->getTitle(); |
||
| 884 | $item['itemurl'] = $this->getItemUrl(); |
||
| 885 | |||
| 886 | $item['adminlink'] = $this->getAdminLinks($icons); |
||
| 887 | $item['pdfbutton'] = $this->getPdfButton($icons); |
||
| 888 | $item['printlink'] = $this->getPrintLinks($icons); |
||
| 889 | $item['categoryPath'] = $this->getCategoryPath($this->helper->getConfig('format_linked_path')); |
||
| 890 | $item['who_when'] = $this->getWhoAndWhen(); |
||
| 891 | $item['who'] = $this->getWho(); |
||
| 892 | $item['when'] = $this->getWhen(); |
||
| 893 | $item['category'] = $this->getCategoryName(); |
||
| 894 | $item['body'] = $this->getBody(); |
||
| 895 | $item['more'] = $this->getItemUrl(); |
||
| 896 | $item = $this->getMainImage($item); |
||
| 897 | |||
| 898 | return $item; |
||
| 899 | } |
||
| 900 | |||
| 901 | /** |
||
| 902 | * @param array $item |
||
| 903 | * @param int $itemPageId |
||
| 904 | * |
||
| 905 | * @return array |
||
| 906 | */ |
||
| 907 | public function toArrayAll($item, $itemPageId) |
||
| 908 | { |
||
| 909 | $item['maintext'] = $this->buildMainText($itemPageId, $this->getBody()); |
||
| 910 | $item = $this->getOtherImages($item); |
||
| 911 | |||
| 912 | return $item; |
||
| 913 | } |
||
| 914 | |||
| 915 | /** |
||
| 916 | * @param array $item |
||
| 917 | * |
||
| 918 | * @return array |
||
| 919 | */ |
||
| 920 | public function getMainImage($item = []) |
||
| 921 | { |
||
| 922 | $images = $this->getImages(); |
||
| 923 | $item['image_path'] = ''; |
||
| 924 | $item['image_name'] = ''; |
||
| 925 | if (\is_object($images['main'])) { |
||
| 926 | /** @var array $dimensions */ |
||
| 927 | $dimensions = \getimagesize($GLOBALS['xoops']->path('uploads/' . $images['main']->getVar('image_name'))); |
||
| 928 | $item['image_width'] = $dimensions[0]; |
||
| 929 | $item['image_height'] = $dimensions[1]; |
||
| 930 | $item['image_path'] = XOOPS_URL . '/uploads/' . $images['main']->getVar('image_name'); |
||
| 931 | // check to see if GD function exist |
||
| 932 | if (\function_exists('imagecreatetruecolor')) { |
||
| 933 | $item['image_thumb'] = PUBLISHER_URL . '/thumb.php?src=' . XOOPS_URL . '/uploads/' . $images['main']->getVar('image_name') . '&h=180'; |
||
| 934 | } else { |
||
| 935 | $item['image_thumb'] = XOOPS_URL . '/uploads/' . $images['main']->getVar('image_name'); |
||
| 936 | } |
||
| 937 | $item['image_name'] = $images['main']->getVar('image_nicename'); |
||
| 938 | } |
||
| 939 | |||
| 940 | return $item; |
||
| 941 | } |
||
| 942 | |||
| 943 | /** |
||
| 944 | * @param array $item |
||
| 945 | * |
||
| 946 | * @return array |
||
| 947 | */ |
||
| 948 | public function getOtherImages($item = []) |
||
| 949 | { |
||
| 950 | $images = $this->getImages(); |
||
| 951 | $item['images'] = []; |
||
| 952 | $i = 0; |
||
| 953 | foreach ($images['others'] as $image) { |
||
| 954 | /** @var array $dimensions */ |
||
| 955 | $dimensions = \getimagesize($GLOBALS['xoops']->path('uploads/' . $image->getVar('image_name'))); |
||
| 956 | $item['images'][$i]['width'] = $dimensions[0]; |
||
| 957 | $item['images'][$i]['height'] = $dimensions[1]; |
||
| 958 | $item['images'][$i]['path'] = XOOPS_URL . '/uploads/' . $image->getVar('image_name'); |
||
| 959 | // check to see if GD function exist |
||
| 960 | if (\function_exists('imagecreatetruecolor')) { |
||
| 961 | $item['images'][$i]['thumb'] = PUBLISHER_URL . '/thumb.php?src=' . XOOPS_URL . '/uploads/' . $image->getVar('image_name') . '&w=240'; |
||
| 962 | } else { |
||
| 963 | $item['images'][$i]['thumb'] = XOOPS_URL . '/uploads/' . $image->getVar('image_name'); |
||
| 964 | } |
||
| 965 | $item['images'][$i]['name'] = $image->getVar('image_nicename'); |
||
| 966 | ++$i; |
||
| 967 | } |
||
| 968 | |||
| 969 | return $item; |
||
| 970 | } |
||
| 971 | |||
| 972 | /** |
||
| 973 | * @param string $content |
||
| 974 | * @param string|array $keywords |
||
| 975 | * |
||
| 976 | * @return string Text |
||
| 977 | */ |
||
| 978 | public function highlight($content, $keywords) |
||
| 979 | { |
||
| 980 | $color = $this->helper->getConfig('format_highlight_color'); |
||
| 981 | if (0 !== \mb_strpos($color, '#')) { |
||
| 982 | $color = '#' . $color; |
||
| 983 | } |
||
| 984 | require_once __DIR__ . '/Highlighter.php'; |
||
| 985 | $highlighter = new Highlighter(); |
||
| 986 | $highlighter->setReplacementString('<span style="font-weight: bolder; background-color: ' . $color . ';">\1</span>'); |
||
| 987 | |||
| 988 | return $highlighter->highlight($content, $keywords); |
||
| 989 | } |
||
| 990 | |||
| 991 | /** |
||
| 992 | * Create metada and assign it to template |
||
| 993 | */ |
||
| 994 | public function createMetaTags(): void |
||
| 995 | { |
||
| 996 | $publisherMetagen = new Metagen($this->getTitle(), $this->meta_keywords(), $this->meta_description(), $this->category->categoryPath); |
||
| 997 | $publisherMetagen->createMetaTags(); |
||
| 998 | } |
||
| 999 | |||
| 1000 | /** |
||
| 1001 | * @param string $str |
||
| 1002 | * |
||
| 1003 | * @return string |
||
| 1004 | */ |
||
| 1005 | protected function convertForJapanese($str) |
||
| 1006 | { |
||
| 1007 | // no action, if not flag |
||
| 1008 | if (!\defined('_PUBLISHER_FLAG_JP_CONVERT')) { |
||
| 1009 | return $str; |
||
| 1010 | } |
||
| 1011 | // no action, if not Japanese |
||
| 1012 | if ('japanese' !== $GLOBALS['xoopsConfig']['language']) { |
||
| 1013 | return $str; |
||
| 1014 | } |
||
| 1015 | // presume OS Browser |
||
| 1016 | $agent = Request::getString('HTTP_USER_AGENT', '', 'SERVER'); |
||
| 1017 | $os = ''; |
||
| 1018 | $browser = ''; |
||
| 1019 | // if (preg_match("/Win/i", $agent)) { |
||
| 1020 | if (false !== \mb_stripos($agent, 'Win')) { |
||
| 1021 | $os = 'win'; |
||
| 1022 | } |
||
| 1023 | // if (preg_match("/MSIE/i", $agent)) { |
||
| 1024 | if (false !== \mb_stripos($agent, 'MSIE')) { |
||
| 1025 | $browser = 'msie'; |
||
| 1026 | } |
||
| 1027 | // if msie |
||
| 1028 | if (('win' === $os) && ('msie' === $browser)) { |
||
| 1029 | // if multibyte |
||
| 1030 | if (\function_exists('mb_convert_encoding')) { |
||
| 1031 | $str = \mb_convert_encoding($str, 'SJIS', 'EUC-JP'); |
||
| 1032 | $str = \rawurlencode($str); |
||
| 1033 | } |
||
| 1034 | } |
||
| 1035 | |||
| 1036 | return $str; |
||
| 1037 | } |
||
| 1038 | |||
| 1039 | /** |
||
| 1040 | * @param string $title |
||
| 1041 | * @param bool $checkperm |
||
| 1042 | * |
||
| 1043 | * @return Form\ItemForm |
||
| 1044 | */ |
||
| 1045 | public function getForm($title = 'default', $checkperm = true) |
||
| 1053 | } |
||
| 1054 | |||
| 1055 | /** |
||
| 1056 | * Checks if a user has access to a selected item. if no item permissions are |
||
| 1057 | * set, access permission is denied. The user needs to have necessary category |
||
| 1058 | * permission as well. |
||
| 1059 | * Also, the item needs to be Published |
||
| 1060 | * |
||
| 1061 | * @return bool : TRUE if the no errors occured |
||
| 1062 | */ |
||
| 1063 | public function accessGranted() |
||
| 1064 | { |
||
| 1065 | if (Utility::userIsAdmin()) { |
||
| 1066 | return true; |
||
| 1067 | } |
||
| 1068 | if (Constants::PUBLISHER_STATUS_PUBLISHED != $this->getVar('status')) { |
||
| 1069 | return false; |
||
| 1070 | } |
||
| 1071 | // Do we have access to the parent category |
||
| 1078 | } |
||
| 1079 | |||
| 1080 | /** |
||
| 1081 | * The name says it all |
||
| 1082 | */ |
||
| 1083 | public function setVarsFromRequest(): void |
||
| 1202 | } |
||
| 1203 | } |
||
| 1204 | |||
| 1205 | public function assignOtherProperties(): void |
||
| 1206 | { |
||
| 1215 | } |
||
| 1216 | } |
||
| 1217 |