| Total Complexity | 65 |
| Total Lines | 632 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like ItemForm 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 ItemForm, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 57 | class ItemForm extends SimpleForm |
||
| 58 | { |
||
| 59 | private $checkperm = true; |
||
| 60 | |||
| 61 | private $tabs = [ |
||
| 62 | _CO_PUBLISHER_TAB_MAIN => 'mainTab', |
||
| 63 | _CO_PUBLISHER_TAB_IMAGES => 'imagesTab', |
||
| 64 | _CO_PUBLISHER_TAB_FILES => 'filesTab', |
||
| 65 | _CO_PUBLISHER_TAB_OTHERS => 'othersTab', |
||
| 66 | ]; |
||
| 67 | |||
| 68 | private $mainTab = [ |
||
| 69 | \_PUBLISHER_SUBTITLE, |
||
| 70 | \_PUBLISHER_ITEM_SHORT_URL, |
||
| 71 | \_PUBLISHER_ITEM_TAG, |
||
| 72 | \_PUBLISHER_SUMMARY, |
||
| 73 | \_PUBLISHER_DOHTML, |
||
| 74 | \_PUBLISHER_DOSMILEY, |
||
| 75 | \_PUBLISHER_DOXCODE, |
||
| 76 | \_PUBLISHER_DOIMAGE, |
||
| 77 | \_PUBLISHER_DOLINEBREAK, |
||
| 78 | \_PUBLISHER_DATESUB, |
||
| 79 | \_PUBLISHER_STATUS, |
||
| 80 | \_PUBLISHER_AUTHOR_ALIAS, |
||
| 81 | \_PUBLISHER_NOTIFY, |
||
| 82 | \_PUBLISHER_AVAILABLE_PAGE_WRAP, |
||
| 83 | \_PUBLISHER_UID, |
||
| 84 | ]; |
||
| 85 | |||
| 86 | private $imagesTab = [ |
||
| 87 | \_PUBLISHER_IMAGE_ITEM, |
||
| 88 | ]; |
||
| 89 | |||
| 90 | private $filesTab = [ |
||
| 91 | \_PUBLISHER_ITEM_UPLOAD_FILE, |
||
| 92 | ]; |
||
| 93 | |||
| 94 | private $othersTab = [ |
||
| 95 | \_PUBLISHER_ITEM_META_KEYWORDS, |
||
| 96 | \_PUBLISHER_ITEM_META_DESCRIPTION, |
||
| 97 | \_PUBLISHER_WEIGHT, |
||
| 98 | \_PUBLISHER_ALLOWCOMMENTS, |
||
| 99 | ]; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * __construct |
||
| 103 | * |
||
| 104 | * @param Publisher\Item $obj source object for form variables |
||
| 105 | */ |
||
| 106 | public function __construct(Publisher\Item $obj) |
||
| 107 | { |
||
| 108 | $xoops = Xoops::getInstance(); |
||
| 109 | |||
| 110 | parent::__construct('title', 'form', $xoops->getEnv('PHP_SELF')); |
||
| 111 | $this->setExtra('enctype="multipart/form-data"'); |
||
| 112 | |||
| 113 | $tabTray = new TabTray('', 'uniqueid'); |
||
| 114 | |||
| 115 | $mainTab = new Tab(_CO_PUBLISHER_TAB_MAIN, 'maintab'); |
||
| 116 | $this->buildMainTab($obj, $mainTab); |
||
| 117 | $tabTray->addElement($mainTab); |
||
| 118 | |||
| 119 | if ($xoops->isActiveModule('images') && $this->hasTab(_CO_PUBLISHER_TAB_IMAGES)) { |
||
| 120 | $imagesTab = new Tab(_CO_PUBLISHER_TAB_IMAGES, 'imagestab'); |
||
| 121 | $this->buildImagesTab($obj, $imagesTab); |
||
| 122 | $tabTray->addElement($imagesTab); |
||
| 123 | } |
||
| 124 | |||
| 125 | if ($this->hasTab(_CO_PUBLISHER_TAB_FILES)) { |
||
| 126 | $filesTab = new Tab(_CO_PUBLISHER_TAB_FILES, 'filestab'); |
||
| 127 | $this->buildFilesTab($obj, $filesTab); |
||
| 128 | $tabTray->addElement($filesTab); |
||
| 129 | } |
||
| 130 | |||
| 131 | if ($this->hasTab(_CO_PUBLISHER_TAB_OTHERS)) { |
||
| 132 | $othersTab = new Tab(_CO_PUBLISHER_TAB_OTHERS, 'otherstab'); |
||
| 133 | $this->buildOthersTab($obj, $othersTab); |
||
| 134 | $tabTray->addElement($othersTab); |
||
| 135 | } |
||
| 136 | $this->addElement($tabTray); |
||
| 137 | |||
| 138 | //COMMON TO ALL TABS |
||
| 139 | |||
| 140 | $buttonTray = new ElementTray('', ''); |
||
| 141 | |||
| 142 | if (!$obj->isNew()) { |
||
| 143 | $buttonTray->addElement(new Button('', 'additem', XoopsLocale::A_SUBMIT, 'submit')); //orclone |
||
| 144 | } else { |
||
| 145 | $buttonTray->addElement(new Button('', 'additem', _CO_PUBLISHER_CREATE, 'submit')); |
||
| 146 | $buttonTray->addElement(new Button('', '', _CO_PUBLISHER_CLEAR, 'reset')); |
||
| 147 | } |
||
| 148 | |||
| 149 | $buttonTray->addElement(new Button('', 'preview', _CO_PUBLISHER_PREVIEW, 'submit')); |
||
| 150 | |||
| 151 | $buttonCancel = new Button('', '', _CO_PUBLISHER_CANCEL, 'button'); |
||
| 152 | $buttonCancel->set('onclick', 'history.go(-1);'); |
||
| 153 | $buttonTray->addElement($buttonCancel); |
||
| 154 | |||
| 155 | $this->addElement($buttonTray); |
||
| 156 | |||
| 157 | $hidden = new Hidden('itemid', $obj->getVar('itemid')); |
||
|
|
|||
| 158 | $this->addElement($hidden); |
||
| 159 | unset($hidden); |
||
| 160 | } |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Build the main tab |
||
| 164 | * |
||
| 165 | * @param Publisher\Item $obj data source |
||
| 166 | * @param ContainerInterface $mainTab add elements to this tab/form |
||
| 167 | */ |
||
| 168 | private function buildMainTab(Publisher\Item $obj, ContainerInterface $mainTab): void |
||
| 169 | { |
||
| 170 | $xoops = Xoops::getInstance(); |
||
| 171 | $helper = Helper::getInstance(); |
||
| 172 | |||
| 173 | // Category |
||
| 174 | $category_select = new Select(_CO_PUBLISHER_CATEGORY, 'categoryid', $obj->getVar('categoryid', 'e')); |
||
| 175 | $category_select->setDescription(_CO_PUBLISHER_CATEGORY_DSC); |
||
| 176 | $category_select->addOptionArray($helper->getCategoryHandler()->getCategoriesForSubmit()); |
||
| 177 | $mainTab->addElement($category_select); |
||
| 178 | |||
| 179 | // ITEM TITLE |
||
| 180 | $mainTab->addElement(new Text(_CO_PUBLISHER_TITLE, 'title', 50, 255, $obj->getVar('title', 'e')), true); |
||
| 181 | |||
| 182 | // SUBTITLE |
||
| 183 | if ($this->isGranted(\_PUBLISHER_SUBTITLE)) { |
||
| 184 | $mainTab->addElement(new Text(_CO_PUBLISHER_SUBTITLE, 'subtitle', 50, 255, $obj->getVar('subtitle', 'e'))); |
||
| 185 | } |
||
| 186 | |||
| 187 | // SHORT URL |
||
| 188 | if ($this->isGranted(\_PUBLISHER_ITEM_SHORT_URL)) { |
||
| 189 | $text_short_url = new Text(_CO_PUBLISHER_ITEM_SHORT_URL, 'item_short_url', 50, 255, $obj->getVar('short_url', 'e')); |
||
| 190 | $text_short_url->setDescription(_CO_PUBLISHER_ITEM_SHORT_URL_DSC); |
||
| 191 | $mainTab->addElement($text_short_url); |
||
| 192 | } |
||
| 193 | |||
| 194 | // TAGS |
||
| 195 | if ($xoops->isActiveModule('tag') && $this->isGranted(\_PUBLISHER_ITEM_TAG)) { |
||
| 196 | require_once $xoops->path('modules/tag/include/formtag.php'); |
||
| 197 | $text_tags = new \Tag('item_tag', 60, 255, $obj->getVar('item_tag', 'e'), 0); |
||
| 198 | $mainTab->addElement($text_tags); |
||
| 199 | } |
||
| 200 | |||
| 201 | $this->buildEditors($obj, $mainTab); |
||
| 202 | $this->buildTSOptions($obj, $mainTab); |
||
| 203 | |||
| 204 | // Available pages to wrap |
||
| 205 | if ($this->isGranted(\_PUBLISHER_AVAILABLE_PAGE_WRAP)) { |
||
| 206 | $wrap_pages = XoopsLists::getHtmlListAsArray(Publisher\Utils::getUploadDir(true, 'content')); |
||
| 207 | $available_wrap_pages_text = []; |
||
| 208 | foreach ($wrap_pages as $page) { |
||
| 209 | $available_wrap_pages_text[] = "<span onclick='publisherPageWrap(\"body\", \"[pagewrap=$page] \");'" . " onmouseover='style.cursor=\"pointer\"'>$page</span>"; |
||
| 210 | } |
||
| 211 | $available_wrap_pages = new Label(_CO_PUBLISHER_AVAILABLE_PAGE_WRAP, \implode(', ', $available_wrap_pages_text)); |
||
| 212 | $available_wrap_pages->setDescription(_CO_PUBLISHER_AVAILABLE_PAGE_WRAP_DSC); |
||
| 213 | $mainTab->addElement($available_wrap_pages); |
||
| 214 | } |
||
| 215 | |||
| 216 | // Uid |
||
| 217 | /* We need to retrieve the users manually because for some reason, on the frxoops.org server, |
||
| 218 | the method users::getobjects encounters a memory error |
||
| 219 | */ |
||
| 220 | // Trabis : well, maybe is because you are getting 6000 objects into memory , no??? LOL |
||
| 221 | if ($this->isGranted(\_PUBLISHER_UID)) { |
||
| 222 | $uid_select = new SelectUser(_CO_PUBLISHER_UID, 'uid', true, [$obj->getVar('uid', 'e')], 1, false); |
||
| 223 | $uid_select->setDescription(_CO_PUBLISHER_UID_DSC); |
||
| 224 | $mainTab->addElement($uid_select); |
||
| 225 | } |
||
| 226 | |||
| 227 | // Author Alias |
||
| 228 | if ($this->isGranted(\_PUBLISHER_AUTHOR_ALIAS)) { |
||
| 229 | $element = new Text(_CO_PUBLISHER_AUTHOR_ALIAS, 'author_alias', 50, 255, $obj->getVar('author_alias', 'e')); |
||
| 230 | $element->setDescription(_CO_PUBLISHER_AUTHOR_ALIAS_DSC); |
||
| 231 | $mainTab->addElement($element); |
||
| 232 | unset($element); |
||
| 233 | } |
||
| 234 | |||
| 235 | // STATUS |
||
| 236 | if ($this->isGranted(\_PUBLISHER_STATUS)) { |
||
| 237 | $options = [ |
||
| 238 | \_PUBLISHER_STATUS_PUBLISHED => _CO_PUBLISHER_PUBLISHED, |
||
| 239 | \_PUBLISHER_STATUS_OFFLINE => _CO_PUBLISHER_OFFLINE, |
||
| 240 | \_PUBLISHER_STATUS_SUBMITTED => _CO_PUBLISHER_SUBMITTED, |
||
| 241 | \_PUBLISHER_STATUS_REJECTED => _CO_PUBLISHER_REJECTED, |
||
| 242 | ]; |
||
| 243 | $status_select = new Select(_CO_PUBLISHER_STATUS, 'status', $obj->getVar('status')); |
||
| 244 | $status_select->addOptionArray($options); |
||
| 245 | $status_select->setDescription(_CO_PUBLISHER_STATUS_DSC); |
||
| 246 | $mainTab->addElement($status_select); |
||
| 247 | unset($status_select); |
||
| 248 | } |
||
| 249 | |||
| 250 | // Datesub |
||
| 251 | if ($this->isGranted(\_PUBLISHER_DATESUB)) { |
||
| 252 | $datesub = (0 == $obj->getVar('datesub')) ? \time() : $obj->getVar('datesub'); |
||
| 253 | $datesub_datetime = new DateTimeSelect(_CO_PUBLISHER_DATESUB, 'datesub', $datesub); |
||
| 254 | $datesub_datetime->setDescription(_CO_PUBLISHER_DATESUB_DSC); |
||
| 255 | $mainTab->addElement($datesub_datetime); |
||
| 256 | } |
||
| 257 | |||
| 258 | // NOTIFY ON PUBLISH |
||
| 259 | if ($this->isGranted(\_PUBLISHER_NOTIFY)) { |
||
| 260 | $notify_radio = new RadioYesNo(_CO_PUBLISHER_NOTIFY, 'notify', $obj->getVar('notifypub')); |
||
| 261 | $mainTab->addElement($notify_radio); |
||
| 262 | } |
||
| 263 | } |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Build the summary and body editors |
||
| 267 | * |
||
| 268 | * @param Publisher\Item $obj data source |
||
| 269 | * @param ContainerInterface $mainTab add elements to this tab/form |
||
| 270 | */ |
||
| 271 | private function buildEditors(Publisher\Item $obj, ContainerInterface $mainTab): void |
||
| 272 | { |
||
| 273 | $xoops = Xoops::getInstance(); |
||
| 274 | $helper = Helper::getInstance(); |
||
| 275 | |||
| 276 | // SELECT EDITOR |
||
| 277 | $allowed_editors = Publisher\Utils::getEditors($helper->getPermissionHandler()->getGrantedItems('editors')); |
||
| 278 | |||
| 279 | $nohtml = false; |
||
| 280 | if (1 == \count($allowed_editors)) { |
||
| 281 | $editor = $allowed_editors[0]; |
||
| 282 | } else { |
||
| 283 | if (\count($allowed_editors) > 0) { |
||
| 284 | $editor = @$_POST['editor']; |
||
| 285 | if (!empty($editor)) { |
||
| 286 | Publisher\Utils::setCookieVar('publisher_editor', $editor); |
||
| 287 | } else { |
||
| 288 | $editor = Publisher\Utils::getCookieVar('publisher_editor'); |
||
| 289 | if (empty($editor) && $xoops->isUser()) { |
||
| 290 | $editor = $xoops->user->getVar('publisher_editor'); // Need set through user profile |
||
| 291 | } |
||
| 292 | } |
||
| 293 | $editor = (empty($editor) || !\in_array($editor, $allowed_editors)) ? $helper->getConfig('submit_editor') : $editor; |
||
| 294 | |||
| 295 | $form_editor = new SelectEditor($this, 'editor', $editor, $nohtml, $allowed_editors); |
||
| 296 | $mainTab->addElement($form_editor); |
||
| 297 | } else { |
||
| 298 | $editor = $helper->getConfig('submit_editor'); |
||
| 299 | } |
||
| 300 | } |
||
| 301 | |||
| 302 | $editor_configs = []; |
||
| 303 | $editor_configs['rows'] = !$helper->getConfig('submit_editor_rows') ? 35 : $helper->getConfig('submit_editor_rows'); |
||
| 304 | $editor_configs['cols'] = !$helper->getConfig('submit_editor_cols') ? 60 : $helper->getConfig('submit_editor_cols'); |
||
| 305 | $editor_configs['width'] = !$helper->getConfig('submit_editor_width') ? '100%' : $helper->getConfig('submit_editor_width'); |
||
| 306 | $editor_configs['height'] = !$helper->getConfig('submit_editor_height') ? '400px' : $helper->getConfig('submit_editor_height'); |
||
| 307 | |||
| 308 | // SUMMARY |
||
| 309 | if ($this->isGranted(\_PUBLISHER_SUMMARY)) { |
||
| 310 | // Description |
||
| 311 | $editor_configs['name'] = 'summary'; |
||
| 312 | $editor_configs['value'] = $obj->getVar('summary', 'e'); |
||
| 313 | $summary_text = new Editor(_CO_PUBLISHER_SUMMARY, $editor, $editor_configs, $nohtml, $onfailure = null); |
||
| 314 | $summary_text->setDescription(_CO_PUBLISHER_SUMMARY_DSC); |
||
| 315 | $mainTab->addElement($summary_text); |
||
| 316 | } |
||
| 317 | |||
| 318 | // BODY |
||
| 319 | $editor_configs['name'] = 'body'; |
||
| 320 | $editor_configs['value'] = $obj->getVar('body', 'e'); |
||
| 321 | $body_text = new Editor(_CO_PUBLISHER_BODY, $editor, $editor_configs, $nohtml, $onfailure = null); |
||
| 322 | $body_text->setDescription(_CO_PUBLISHER_BODY_DSC); |
||
| 323 | $mainTab->addElement($body_text); |
||
| 324 | } |
||
| 325 | |||
| 326 | /** |
||
| 327 | * Build the option selectors for Text\Sanitizer display processing |
||
| 328 | * |
||
| 329 | * @param Publisher\Item $obj data source |
||
| 330 | * @param ContainerInterface $mainTab add elements to this tab/form |
||
| 331 | */ |
||
| 332 | private function buildTSOptions(Publisher\Item $obj, ContainerInterface $mainTab): void |
||
| 333 | { |
||
| 334 | // VARIOUS OPTIONS |
||
| 335 | if ($this->isGranted(\_PUBLISHER_DOHTML)) { |
||
| 336 | $html_radio = new RadioYesNo(_CO_PUBLISHER_DOHTML, 'dohtml', $obj->getVar('dohtml')); |
||
| 337 | $mainTab->addElement($html_radio); |
||
| 338 | } |
||
| 339 | if ($this->isGranted(\_PUBLISHER_DOSMILEY)) { |
||
| 340 | $smiley_radio = new RadioYesNo(_CO_PUBLISHER_DOSMILEY, 'dosmiley', $obj->getVar('dosmiley')); |
||
| 341 | $mainTab->addElement($smiley_radio); |
||
| 342 | } |
||
| 343 | if ($this->isGranted(\_PUBLISHER_DOXCODE)) { |
||
| 344 | $xcode_radio = new RadioYesNo(_CO_PUBLISHER_DOXCODE, 'doxcode', $obj->getVar('doxcode')); |
||
| 345 | $mainTab->addElement($xcode_radio); |
||
| 346 | } |
||
| 347 | if ($this->isGranted(\_PUBLISHER_DOIMAGE)) { |
||
| 348 | $image_radio = new RadioYesNo(_CO_PUBLISHER_DOIMAGE, 'doimage', $obj->getVar('doimage')); |
||
| 349 | $mainTab->addElement($image_radio); |
||
| 350 | } |
||
| 351 | if ($this->isGranted(\_PUBLISHER_DOLINEBREAK)) { |
||
| 352 | $linebreak_radio = new RadioYesNo(_CO_PUBLISHER_DOLINEBREAK, 'dolinebreak', $obj->getVar('dobr')); |
||
| 353 | $mainTab->addElement($linebreak_radio); |
||
| 354 | } |
||
| 355 | } |
||
| 356 | |||
| 357 | /** |
||
| 358 | * Build the files tab |
||
| 359 | * |
||
| 360 | * @param Publisher\Item $obj data source |
||
| 361 | * @param ContainerInterface $filesTab add elements to this tab/form |
||
| 362 | */ |
||
| 363 | private function buildFilesTab(Publisher\Item $obj, ContainerInterface $filesTab): void |
||
| 364 | { |
||
| 365 | $helper = Helper::getInstance(); |
||
| 366 | |||
| 367 | // File upload UPLOAD |
||
| 368 | if ($this->isGranted(\_PUBLISHER_ITEM_UPLOAD_FILE)) { |
||
| 369 | // NAME |
||
| 370 | $name_text = new Text(_CO_PUBLISHER_FILENAME, 'item_file_name', 50, 255, ''); |
||
| 371 | $name_text->setDescription(_CO_PUBLISHER_FILE_NAME_DSC); |
||
| 372 | $filesTab->addElement($name_text); |
||
| 373 | unset($name_text); |
||
| 374 | |||
| 375 | // DESCRIPTION |
||
| 376 | $description_text = new TextArea(_CO_PUBLISHER_FILE_DESCRIPTION, 'item_file_description', ''); |
||
| 377 | $description_text->setDescription(_CO_PUBLISHER_FILE_DESCRIPTION_DSC); |
||
| 378 | $filesTab->addElement($description_text); |
||
| 379 | unset($description_text); |
||
| 380 | |||
| 381 | //1 - active |
||
| 382 | $status_select = new RadioYesNo(_CO_PUBLISHER_FILE_STATUS, 'item_file_status', 1); |
||
| 383 | $status_select->setDescription(_CO_PUBLISHER_FILE_STATUS_DSC); |
||
| 384 | $filesTab->addElement($status_select); |
||
| 385 | unset($status_select); |
||
| 386 | |||
| 387 | $file_box = new File(_CO_PUBLISHER_ITEM_UPLOAD_FILE, 'item_upload_file'); |
||
| 388 | $file_box->setDescription(_CO_PUBLISHER_ITEM_UPLOAD_FILE_DSC); |
||
| 389 | $file_box->set('size', 50); |
||
| 390 | $filesTab->addElement($file_box); |
||
| 391 | unset($file_box); |
||
| 392 | |||
| 393 | if (!$obj->isNew()) { |
||
| 394 | $filesObj = $helper->getFileHandler()->getAllFiles($obj->getVar('itemid')); |
||
| 395 | if (\count($filesObj) > 0) { |
||
| 396 | $table = ''; |
||
| 397 | $table .= "<table width='100%' cellspacing=1 cellpadding=3 border=0 class = outer>"; |
||
| 398 | $table .= '<tr>'; |
||
| 399 | $table .= "<td width='50' class='bg3' align='center'><strong>ID</strong></td>"; |
||
| 400 | $table .= "<td width='150' class='bg3' align='left'><strong>" . _AM_PUBLISHER_FILENAME . '</strong></td>'; |
||
| 401 | $table .= "<td class='bg3' align='left'><strong>" . _AM_PUBLISHER_DESCRIPTION . '</strong></td>'; |
||
| 402 | $table .= "<td width='60' class='bg3' align='center'><strong>" . _AM_PUBLISHER_HITS . '</strong></td>'; |
||
| 403 | $table .= "<td width='100' class='bg3' align='center'><strong>" . _AM_PUBLISHER_UPLOADED_DATE . '</strong></td>'; |
||
| 404 | $table .= "<td width='60' class='bg3' align='center'><strong>" . _AM_PUBLISHER_ACTION . '</strong></td>'; |
||
| 405 | $table .= '</tr>'; |
||
| 406 | |||
| 407 | /* @var Publisher\File $fileObj */ |
||
| 408 | foreach ($filesObj as $fileObj) { |
||
| 409 | $modify = "<a href='file.php?op=mod&fileid=" . $fileObj->getVar('fileid') . "'><img src='" . \PUBLISHER_URL . "/images/links/edit.gif' title='" . _CO_PUBLISHER_EDITFILE . "' alt='" . _CO_PUBLISHER_EDITFILE . "'></a>"; |
||
| 410 | $delete = "<a href='file.php?op=del&fileid=" . $fileObj->getVar('fileid') . "'><img src='" . \PUBLISHER_URL . "/images/links/delete.png' title='" . _CO_PUBLISHER_DELETEFILE . "' alt='" . _CO_PUBLISHER_DELETEFILE . "'></a>"; |
||
| 411 | if (0 == $fileObj->getVar('status')) { |
||
| 412 | $notVisible = "<img src='" . \PUBLISHER_URL . "/images/no.gif'>"; |
||
| 413 | } else { |
||
| 414 | $notVisible = ''; |
||
| 415 | } |
||
| 416 | $table .= '<tr>'; |
||
| 417 | $table .= "<td class='head' align='center'>" . $fileObj->getVar('fileid') . '</td>'; |
||
| 418 | $table .= "<td class='odd' align='left'>" . $notVisible . $fileObj->getFileLink() . '</td>'; |
||
| 419 | $table .= "<td class='even' align='left'>" . $fileObj->getVar('description') . '</td>'; |
||
| 420 | $table .= "<td class='even' align='center'>" . $fileObj->getVar('counter') . ''; |
||
| 421 | $table .= "<td class='even' align='center'>" . $fileObj->datesub() . '</td>'; |
||
| 422 | $table .= "<td class='even' align='center'> {$modify} {$delete} </td>"; |
||
| 423 | $table .= '</tr>'; |
||
| 424 | } |
||
| 425 | $table .= '</table>'; |
||
| 426 | |||
| 427 | $files_box = new Label(_CO_PUBLISHER_FILES_LINKED, $table); |
||
| 428 | $filesTab->addElement($files_box); |
||
| 429 | unset($files_box, $filesObj, $fileObj); |
||
| 430 | } |
||
| 431 | } |
||
| 432 | } |
||
| 433 | } |
||
| 434 | |||
| 435 | /** |
||
| 436 | * Build the images tab |
||
| 437 | * |
||
| 438 | * @param Publisher\Item $obj data source |
||
| 439 | * @param ContainerInterface $imagesTab add elements to this tab/form |
||
| 440 | */ |
||
| 441 | private function buildImagesTab(Publisher\Item $obj, ContainerInterface $imagesTab): void |
||
| 602 | } |
||
| 603 | } |
||
| 604 | |||
| 605 | /** |
||
| 606 | * Build the others tab |
||
| 607 | * |
||
| 608 | * @param Publisher\Item $obj data source |
||
| 609 | * @param ContainerInterface $othersTab add elements to this tab/form |
||
| 610 | */ |
||
| 611 | private function buildOthersTab(Publisher\Item $obj, ContainerInterface $othersTab): void |
||
| 612 | { |
||
| 613 | // Meta Keywords |
||
| 614 | if ($this->isGranted(\_PUBLISHER_ITEM_META_KEYWORDS)) { |
||
| 615 | $text_meta_keywords = new TextArea(_CO_PUBLISHER_ITEM_META_KEYWORDS, 'item_meta_keywords', $obj->getVar('meta_keywords', 'e'), 7, 60); |
||
| 616 | $text_meta_keywords->setDescription(_CO_PUBLISHER_ITEM_META_KEYWORDS_DSC); |
||
| 617 | $othersTab->addElement($text_meta_keywords); |
||
| 618 | } |
||
| 619 | |||
| 620 | // Meta Description |
||
| 621 | if ($this->isGranted(\_PUBLISHER_ITEM_META_DESCRIPTION)) { |
||
| 622 | $text_meta_description = new TextArea(_CO_PUBLISHER_ITEM_META_DESCRIPTION, 'item_meta_description', $obj->getVar('meta_description', 'e'), 7, 60); |
||
| 623 | $text_meta_description->setDescription(_CO_PUBLISHER_ITEM_META_DESCRIPTION_DSC); |
||
| 624 | $othersTab->addElement($text_meta_description); |
||
| 625 | } |
||
| 626 | |||
| 627 | // COMMENTS |
||
| 628 | if ($this->isGranted(\_PUBLISHER_ALLOWCOMMENTS)) { |
||
| 629 | $addcomments_radio = new RadioYesNo(_CO_PUBLISHER_ALLOWCOMMENTS, 'allowcomments', $obj->getVar('cancomment')); |
||
| 630 | $othersTab->addElement($addcomments_radio); |
||
| 631 | } |
||
| 632 | |||
| 633 | // WEIGHT |
||
| 634 | if ($this->isGranted(\_PUBLISHER_WEIGHT)) { |
||
| 635 | $othersTab->addElement(new Text(_CO_PUBLISHER_WEIGHT, 'weight', 5, 5, $obj->getVar('weight'))); |
||
| 636 | } |
||
| 637 | } |
||
| 638 | |||
| 639 | /** |
||
| 640 | * setCheckPermissions |
||
| 641 | * |
||
| 642 | * @param bool $checkperm true to check permissions, false to ignore permissions |
||
| 643 | */ |
||
| 644 | public function setCheckPermissions($checkperm): void |
||
| 645 | { |
||
| 646 | $this->checkperm = (bool)$checkperm; |
||
| 647 | } |
||
| 648 | |||
| 649 | /** |
||
| 650 | * isGranted |
||
| 651 | * |
||
| 652 | * @param int $item permission item to check |
||
| 653 | * |
||
| 654 | * @return bool true if permission is granted, false if not |
||
| 655 | */ |
||
| 656 | private function isGranted($item): bool |
||
| 657 | { |
||
| 658 | $helper = Helper::getInstance(); |
||
| 659 | $ret = false; |
||
| 660 | if (!$this->checkperm || $helper->getPermissionHandler()->isGranted('form_view', $item)) { |
||
| 661 | $ret = true; |
||
| 662 | } |
||
| 663 | |||
| 664 | return $ret; |
||
| 665 | } |
||
| 666 | |||
| 667 | /** |
||
| 668 | * hasTab |
||
| 669 | * |
||
| 670 | * @param string $tab tab name |
||
| 671 | * |
||
| 672 | * @return bool true if form has tab named $tab |
||
| 673 | */ |
||
| 674 | private function hasTab($tab): bool |
||
| 689 | } |
||
| 690 | } |
||
| 691 |