1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: use Xoops\Core\Kernel\Criteria;
13: use Xoops\Core\Kernel\CriteriaCompo;
14: use Xoops\Form\ContainerInterface;
15: use Xoops\Form\Tab;
16: use Xoops\Form\TabTray;
17:
18: include_once dirname(dirname(__DIR__)) . '/include/common.php';
19:
20: $publisher = Publisher::getInstance();
21:
22: 23: 24: 25: 26: 27: 28: 29: 30: 31:
32: class PublisherItemForm extends Xoops\Form\SimpleForm
33: {
34: private $checkperm = true;
35:
36: private $tabs = array(
37: _CO_PUBLISHER_TAB_MAIN => 'mainTab', _CO_PUBLISHER_TAB_IMAGES => 'imagesTab',
38: _CO_PUBLISHER_TAB_FILES => 'filesTab', _CO_PUBLISHER_TAB_OTHERS => 'othersTab'
39: );
40:
41: private $mainTab = array(
42: _PUBLISHER_SUBTITLE, _PUBLISHER_ITEM_SHORT_URL, _PUBLISHER_ITEM_TAG, _PUBLISHER_SUMMARY, _PUBLISHER_DOHTML,
43: _PUBLISHER_DOSMILEY, _PUBLISHER_DOXCODE, _PUBLISHER_DOIMAGE, _PUBLISHER_DOLINEBREAK, _PUBLISHER_DATESUB,
44: _PUBLISHER_STATUS, _PUBLISHER_AUTHOR_ALIAS, _PUBLISHER_NOTIFY, _PUBLISHER_AVAILABLE_PAGE_WRAP, _PUBLISHER_UID
45: );
46:
47: private $imagesTab = array(
48: _PUBLISHER_IMAGE_ITEM
49: );
50:
51: private $filesTab = array(
52: _PUBLISHER_ITEM_UPLOAD_FILE
53: );
54:
55: private $othersTab = array(
56: _PUBLISHER_ITEM_META_KEYWORDS, _PUBLISHER_ITEM_META_DESCRIPTION, _PUBLISHER_WEIGHT, _PUBLISHER_ALLOWCOMMENTS
57: );
58:
59: 60: 61: 62: 63:
64: public function __construct(PublisherItem $obj)
65: {
66: $xoops = Xoops::getInstance();
67:
68: parent::__construct('title', 'form', $xoops->getEnv('PHP_SELF'));
69: $this->setExtra('enctype="multipart/form-data"');
70:
71: $tabTray = new TabTray('', 'uniqueid');
72:
73: $mainTab = new Tab(_CO_PUBLISHER_TAB_MAIN, 'maintab');
74: $this->buildMainTab($obj, $mainTab);
75: $tabTray->addElement($mainTab);
76:
77: if ($xoops->isActiveModule('images') && $this->hasTab(_CO_PUBLISHER_TAB_IMAGES)) {
78: $imagesTab = new Tab(_CO_PUBLISHER_TAB_IMAGES, 'imagestab');
79: $this->buildImagesTab($obj, $imagesTab);
80: $tabTray->addElement($imagesTab);
81: }
82:
83: if ($this->hasTab(_CO_PUBLISHER_TAB_FILES)) {
84: $filesTab = new Tab(_CO_PUBLISHER_TAB_FILES, 'filestab');
85: $this->buildFilesTab($obj, $filesTab);
86: $tabTray->addElement($filesTab);
87: }
88:
89: if ($this->hasTab(_CO_PUBLISHER_TAB_OTHERS)) {
90: $othersTab = new Tab(_CO_PUBLISHER_TAB_OTHERS, 'otherstab');
91: $this->buildOthersTab($obj, $othersTab);
92: $tabTray->addElement($othersTab);
93: }
94: $this->addElement($tabTray);
95:
96:
97:
98: $buttonTray = new Xoops\Form\ElementTray('', '');
99:
100: if (!$obj->isNew()) {
101: $buttonTray->addElement(new Xoops\Form\Button('', 'additem', XoopsLocale::A_SUBMIT, 'submit'));
102:
103: } else {
104: $buttonTray->addElement(new Xoops\Form\Button('', 'additem', _CO_PUBLISHER_CREATE, 'submit'));
105: $buttonTray->addElement(new Xoops\Form\Button('', '', _CO_PUBLISHER_CLEAR, 'reset'));
106: }
107:
108: $buttonTray->addElement(new Xoops\Form\Button('', 'preview', _CO_PUBLISHER_PREVIEW, 'submit'));
109:
110: $buttonCancel = new Xoops\Form\Button('', '', _CO_PUBLISHER_CANCEL, 'button');
111: $buttonCancel->set('onclick', 'history.go(-1);');
112: $buttonTray->addElement($buttonCancel);
113:
114: $this->addElement($buttonTray);
115:
116: $hidden = new Xoops\Form\Hidden('itemid', $obj->getVar('itemid'));
117: $this->addElement($hidden);
118: unset($hidden);
119: }
120:
121: 122: 123: 124: 125: 126: 127: 128:
129: private function buildMainTab(PublisherItem $obj, ContainerInterface $mainTab)
130: {
131: $xoops = Xoops::getInstance();
132: $publisher = Publisher::getInstance();
133:
134:
135: $category_select = new Xoops\Form\Select(_CO_PUBLISHER_CATEGORY, 'categoryid', $obj->getVar('categoryid', 'e'));
136: $category_select->setDescription(_CO_PUBLISHER_CATEGORY_DSC);
137: $category_select->addOptionArray($publisher->getCategoryHandler()->getCategoriesForSubmit());
138: $mainTab->addElement($category_select);
139:
140:
141: $mainTab->addElement(
142: new Xoops\Form\Text(_CO_PUBLISHER_TITLE, 'title', 50, 255, $obj->getVar('title', 'e')),
143: true
144: );
145:
146:
147: if ($this->isGranted(_PUBLISHER_SUBTITLE)) {
148: $mainTab->addElement(
149: new Xoops\Form\Text(_CO_PUBLISHER_SUBTITLE, 'subtitle', 50, 255, $obj->getVar('subtitle', 'e'))
150: );
151: }
152:
153:
154: if ($this->isGranted(_PUBLISHER_ITEM_SHORT_URL)) {
155: $text_short_url = new Xoops\Form\Text(
156: _CO_PUBLISHER_ITEM_SHORT_URL,
157: 'item_short_url',
158: 50,
159: 255,
160: $obj->getVar('short_url', 'e')
161: );
162: $text_short_url->setDescription(_CO_PUBLISHER_ITEM_SHORT_URL_DSC);
163: $mainTab->addElement($text_short_url);
164: }
165:
166:
167: if ($xoops->isActiveModule('tag') && $this->isGranted(_PUBLISHER_ITEM_TAG)) {
168: include_once $xoops->path('modules/tag/include/formtag.php');
169: $text_tags = new Tag('item_tag', 60, 255, $obj->getVar('item_tag', 'e'), 0);
170: $mainTab->addElement($text_tags);
171: }
172:
173: $this->buildEditors($obj, $mainTab);
174: $this->buildTSOptions($obj, $mainTab);
175:
176:
177: if ($this->isGranted(_PUBLISHER_AVAILABLE_PAGE_WRAP)) {
178: $wrap_pages = XoopsLists::getHtmlListAsArray(PublisherUtils::getUploadDir(true, 'content'));
179: $available_wrap_pages_text = array();
180: foreach ($wrap_pages as $page) {
181: $available_wrap_pages_text[] = "<span onclick='publisherPageWrap(\"body\", \"[pagewrap=$page] \");'"
182: . " onmouseover='style.cursor=\"pointer\"'>$page</span>";
183: }
184: $available_wrap_pages = new Xoops\Form\Label(
185: _CO_PUBLISHER_AVAILABLE_PAGE_WRAP,
186: implode(', ', $available_wrap_pages_text)
187: );
188: $available_wrap_pages->setDescription(_CO_PUBLISHER_AVAILABLE_PAGE_WRAP_DSC);
189: $mainTab->addElement($available_wrap_pages);
190: }
191:
192:
193: 194: 195:
196:
197: if ($this->isGranted(_PUBLISHER_UID)) {
198: $uid_select =
199: new Xoops\Form\SelectUser(_CO_PUBLISHER_UID, 'uid', true, array($obj->getVar('uid', 'e')), 1, false);
200: $uid_select->setDescription(_CO_PUBLISHER_UID_DSC);
201: $mainTab->addElement($uid_select);
202: }
203:
204:
205: if ($this->isGranted(_PUBLISHER_AUTHOR_ALIAS)) {
206: $element = new Xoops\Form\Text(
207: _CO_PUBLISHER_AUTHOR_ALIAS,
208: 'author_alias',
209: 50,
210: 255,
211: $obj->getVar('author_alias', 'e')
212: );
213: $element->setDescription(_CO_PUBLISHER_AUTHOR_ALIAS_DSC);
214: $mainTab->addElement($element);
215: unset($element);
216: }
217:
218:
219: if ($this->isGranted(_PUBLISHER_STATUS)) {
220: $options = array(
221: _PUBLISHER_STATUS_PUBLISHED => _CO_PUBLISHER_PUBLISHED,
222: _PUBLISHER_STATUS_OFFLINE => _CO_PUBLISHER_OFFLINE,
223: _PUBLISHER_STATUS_SUBMITTED => _CO_PUBLISHER_SUBMITTED,
224: _PUBLISHER_STATUS_REJECTED => _CO_PUBLISHER_REJECTED
225: );
226: $status_select = new Xoops\Form\Select(_CO_PUBLISHER_STATUS, 'status', $obj->getVar('status'));
227: $status_select->addOptionArray($options);
228: $status_select->setDescription(_CO_PUBLISHER_STATUS_DSC);
229: $mainTab->addElement($status_select);
230: unset($status_select);
231: }
232:
233:
234: if ($this->isGranted(_PUBLISHER_DATESUB)) {
235: $datesub = ($obj->getVar('datesub') == 0) ? time() : $obj->getVar('datesub');
236: $datesub_datetime = new Xoops\Form\DateTime(_CO_PUBLISHER_DATESUB, 'datesub', $datesub);
237: $datesub_datetime->setDescription(_CO_PUBLISHER_DATESUB_DSC);
238: $mainTab->addElement($datesub_datetime);
239: }
240:
241:
242: if ($this->isGranted(_PUBLISHER_NOTIFY)) {
243: $notify_radio = new Xoops\Form\RadioYesNo(_CO_PUBLISHER_NOTIFY, 'notify', $obj->getVar('notifypub'));
244: $mainTab->addElement($notify_radio);
245: }
246:
247: }
248:
249: 250: 251: 252: 253: 254: 255: 256:
257: private function buildEditors(PublisherItem $obj, ContainerInterface $mainTab)
258: {
259: $xoops = Xoops::getInstance();
260: $publisher = Publisher::getInstance();
261:
262:
263: $allowed_editors = PublisherUtils::getEditors($publisher->getPermissionHandler()->getGrantedItems('editors'));
264:
265: $nohtml = false;
266: if (count($allowed_editors) == 1) {
267: $editor = $allowed_editors[0];
268: } else {
269: if (count($allowed_editors) > 0) {
270: $editor = @$_POST['editor'];
271: if (!empty($editor)) {
272: PublisherUtils::setCookieVar('publisher_editor', $editor);
273: } else {
274: $editor = PublisherUtils::getCookieVar('publisher_editor');
275: if (empty($editor) && $xoops->isUser()) {
276: $editor = $xoops->user->getVar('publisher_editor');
277: }
278: }
279: $editor = (empty($editor) || !in_array($editor, $allowed_editors))
280: ? $publisher->getConfig('submit_editor') : $editor;
281:
282: $form_editor = new Xoops\Form\SelectEditor($this, 'editor', $editor, $nohtml, $allowed_editors);
283: $mainTab->addElement($form_editor);
284: } else {
285: $editor = $publisher->getConfig('submit_editor');
286: }
287: }
288:
289: $editor_configs = array();
290: $editor_configs["rows"] = !$publisher->getConfig('submit_editor_rows')
291: ? 35 : $publisher->getConfig('submit_editor_rows');
292: $editor_configs["cols"] = !$publisher->getConfig('submit_editor_cols')
293: ? 60 : $publisher->getConfig('submit_editor_cols');
294: $editor_configs["width"] = !$publisher->getConfig('submit_editor_width')
295: ? "100%" : $publisher->getConfig('submit_editor_width');
296: $editor_configs["height"] = !$publisher->getConfig('submit_editor_height')
297: ? "400px" : $publisher->getConfig('submit_editor_height');
298:
299:
300: if ($this->isGranted(_PUBLISHER_SUMMARY)) {
301:
302: $editor_configs["name"] = "summary";
303: $editor_configs["value"] = $obj->getVar('summary', 'e');
304: $summary_text =
305: new Xoops\Form\Editor(_CO_PUBLISHER_SUMMARY, $editor, $editor_configs, $nohtml, $onfailure = null);
306: $summary_text->setDescription(_CO_PUBLISHER_SUMMARY_DSC);
307: $mainTab->addElement($summary_text);
308: }
309:
310:
311: $editor_configs["name"] = "body";
312: $editor_configs["value"] = $obj->getVar('body', 'e');
313: $body_text = new Xoops\Form\Editor(_CO_PUBLISHER_BODY, $editor, $editor_configs, $nohtml, $onfailure = null);
314: $body_text->setDescription(_CO_PUBLISHER_BODY_DSC);
315: $mainTab->addElement($body_text);
316:
317: }
318:
319: 320: 321: 322: 323: 324: 325: 326:
327: private function buildTSOptions(PublisherItem $obj, ContainerInterface $mainTab)
328: {
329:
330: if ($this->isGranted(_PUBLISHER_DOHTML)) {
331: $html_radio = new Xoops\Form\RadioYesNo(_CO_PUBLISHER_DOHTML, 'dohtml', $obj->getVar('dohtml'));
332: $mainTab->addElement($html_radio);
333: }
334: if ($this->isGranted(_PUBLISHER_DOSMILEY)) {
335: $smiley_radio = new Xoops\Form\RadioYesNo(_CO_PUBLISHER_DOSMILEY, 'dosmiley', $obj->getVar('dosmiley'));
336: $mainTab->addElement($smiley_radio);
337: }
338: if ($this->isGranted(_PUBLISHER_DOXCODE)) {
339: $xcode_radio = new Xoops\Form\RadioYesNo(_CO_PUBLISHER_DOXCODE, 'doxcode', $obj->getVar('doxcode'));
340: $mainTab->addElement($xcode_radio);
341: }
342: if ($this->isGranted(_PUBLISHER_DOIMAGE)) {
343: $image_radio = new Xoops\Form\RadioYesNo(_CO_PUBLISHER_DOIMAGE, 'doimage', $obj->getVar('doimage'));
344: $mainTab->addElement($image_radio);
345: }
346: if ($this->isGranted(_PUBLISHER_DOLINEBREAK)) {
347: $linebreak_radio =
348: new Xoops\Form\RadioYesNo(_CO_PUBLISHER_DOLINEBREAK, 'dolinebreak', $obj->getVar('dobr'));
349: $mainTab->addElement($linebreak_radio);
350: }
351: }
352:
353:
354: 355: 356: 357: 358: 359: 360: 361:
362: private function buildFilesTab(PublisherItem $obj, ContainerInterface $filesTab)
363: {
364: $publisher = Publisher::getInstance();
365:
366:
367: if ($this->isGranted(_PUBLISHER_ITEM_UPLOAD_FILE)) {
368:
369: $name_text = new Xoops\Form\Text(_CO_PUBLISHER_FILENAME, 'item_file_name', 50, 255, '');
370: $name_text->setDescription(_CO_PUBLISHER_FILE_NAME_DSC);
371: $filesTab->addElement($name_text);
372: unset($name_text);
373:
374:
375: $description_text =
376: new Xoops\Form\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:
382: $status_select = new Xoops\Form\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 Xoops\Form\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 = $publisher->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>"
401: . _AM_PUBLISHER_FILENAME . "</strong></td>";
402: $table .= "<td class='bg3' align='left'><strong>"
403: . _AM_PUBLISHER_DESCRIPTION . "</strong></td>";
404: $table .= "<td width='60' class='bg3' align='center'><strong>"
405: . _AM_PUBLISHER_HITS . "</strong></td>";
406: $table .= "<td width='100' class='bg3' align='center'><strong>"
407: . _AM_PUBLISHER_UPLOADED_DATE . "</strong></td>";
408: $table .= "<td width='60' class='bg3' align='center'><strong>"
409: . _AM_PUBLISHER_ACTION . "</strong></td>";
410: $table .= "</tr>";
411:
412:
413: foreach ($filesObj as $fileObj) {
414: $modify = "<a href='file.php?op=mod&fileid=" . $fileObj->getVar('fileid')
415: . "'><img src='" . PUBLISHER_URL . "/images/links/edit.gif' title='"
416: . _CO_PUBLISHER_EDITFILE . "' alt='" . _CO_PUBLISHER_EDITFILE . "' /></a>";
417: $delete = "<a href='file.php?op=del&fileid=" . $fileObj->getVar('fileid')
418: . "'><img src='" . PUBLISHER_URL . "/images/links/delete.png' title='"
419: . _CO_PUBLISHER_DELETEFILE . "' alt='" . _CO_PUBLISHER_DELETEFILE . "'/></a>";
420: if ($fileObj->getVar('status') == 0) {
421: $notVisible = "<img src='" . PUBLISHER_URL . "/images/no.gif'/>";
422: } else {
423: $notVisible = '';
424: }
425: $table .= "<tr>";
426: $table .= "<td class='head' align='center'>" . $fileObj->getVar('fileid') . "</td>";
427: $table .= "<td class='odd' align='left'>" . $notVisible . $fileObj->getFileLink() . "</td>";
428: $table .= "<td class='even' align='left'>" . $fileObj->getVar('description') . "</td>";
429: $table .= "<td class='even' align='center'>" . $fileObj->getVar('counter') . "";
430: $table .= "<td class='even' align='center'>" . $fileObj->datesub() . "</td>";
431: $table .= "<td class='even' align='center'> {$modify} {$delete} </td>";
432: $table .= "</tr>";
433: }
434: $table .= "</table>";
435:
436: $files_box = new Xoops\Form\Label(_CO_PUBLISHER_FILES_LINKED, $table);
437: $filesTab->addElement($files_box);
438: unset($files_box, $filesObj, $fileObj);
439: }
440: }
441: }
442:
443: }
444:
445: 446: 447: 448: 449: 450: 451: 452:
453: private function buildImagesTab(PublisherItem $obj, ContainerInterface $imagesTab)
454: {
455: $xoops = Xoops::getInstance();
456: $group = $xoops->getUserGroups();
457:
458:
459: if ($this->isGranted(_PUBLISHER_IMAGE_ITEM)) {
460: $imgcat_handler = Images::getInstance()->getHandlerCategories();
461: $image_handler = Images::getInstance()->getHandlerImages();
462:
463: $objimages = $obj->getImages();
464: $mainarray = is_object($objimages['main']) ? array($objimages['main']) : array();
465: $mergedimages = array_merge($mainarray, $objimages['others']);
466: $objimage_array = array();
467:
468: foreach ($mergedimages as $imageObj) {
469: $objimage_array[$imageObj->getVar('image_name')] = $imageObj->getVar('image_nicename');
470: }
471:
472: $catlist = $imgcat_handler->getListByPermission($group, 'imgcat_read', 1);
473: $catids = array_keys($catlist);
474:
475: $imageObjs = array();
476: if (!empty($catids)) {
477: $criteria = new CriteriaCompo(new Criteria('imgcat_id', '(' . implode(',', $catids) . ')', 'IN'));
478: $criteria->add(new Criteria('image_display', 1));
479: $criteria->setSort('image_nicename');
480: $criteria->setOrder('ASC');
481: $imageObjs = $image_handler->getObjects($criteria, true);
482: unset($criteria);
483: }
484: $image_array = array();
485: foreach ($imageObjs as $imageObj) {
486: $image_array[$imageObj->getVar('image_name')] = $imageObj->getVar('image_nicename');
487: }
488:
489: $image_array = array_diff($image_array, $objimage_array);
490:
491: $image_select = new Xoops\Form\Select('', 'image_notused', '', 5);
492: $image_select->addOptionArray($image_array);
493: $image_select->set(
494: 'onchange',
495: 'showImgSelected("image_display", "image_notused", "uploads/", "", "'
496: . \XoopsBaseConfig::get('url') . '")'
497: );
498: unset($image_array);
499:
500: $image_select2 = new Xoops\Form\Select('', 'image_item', '', 5, true);
501: $image_select2->addOptionArray($objimage_array);
502: $image_select2->set(
503: 'onchange',
504: 'publisher_updateSelectOption("image_item", "image_featured"), '
505: . 'showImgSelected("image_display", "image_item", "uploads/", "", "'
506: . \XoopsBaseConfig::get('url') . '");'
507: );
508:
509: $buttonadd = new Xoops\Form\Button('', 'buttonadd', _CO_PUBLISHER_ADD);
510: $buttonadd->set(
511: 'onclick',
512: 'publisher_appendSelectOption("image_notused", "image_item"), '
513: . 'publisher_updateSelectOption("image_item", "image_featured");'
514: );
515:
516: $buttonremove = new Xoops\Form\Button('', 'buttonremove', _CO_PUBLISHER_REMOVE);
517: $buttonremove->set(
518: 'onclick',
519: 'publisher_appendSelectOption("image_item", "image_notused"), '
520: . 'publisher_updateSelectOption("image_item", "image_featured");'
521: );
522:
523: $opentable = new Xoops\Form\Label('', "<table><tr><td>");
524: $addcol = new Xoops\Form\Label('', "</td><td>");
525: $addbreak = new Xoops\Form\Label('', "<br />");
526: $closetable = new Xoops\Form\Label('', "</td></tr></table>");
527:
528: $xoops->theme()->addScript(PUBLISHER_URL . '/js/ajaxupload.3.9.js');
529:
530: $js_data = new Xoops\Form\Label('', '
531: <script type= "text/javascript">/*<![CDATA[*/
532: $(document).ready(function(){
533: var button = $("#publisher_upload_button"), interval;
534: new AjaxUpload(button,{
535: action: "' . PUBLISHER_URL . '/include/ajax_upload.php", // I disabled uploads in this example for security reasons
536: responseType: "text/html",
537: name: "publisher_upload_file",
538: onSubmit : function(file, ext){
539: // change button text, when user selects file
540: $("#publisher_upload_message").html(" ");
541: button.html("<img src=\'' . PUBLISHER_URL . '/images/loadingbar.gif\'/>"); this.setData({
542: "image_nicename": $("#image_nicename").val(),
543: "imgcat_id" : $("#imgcat_id").val()
544: });
545: // If you want to allow uploading only 1 file at time,
546: // you can disable upload button
547: this.disable();
548: interval = window.setInterval(function(){
549: }, 200);
550: },
551: onComplete: function(file, response){
552: button.text("' . _CO_PUBLISHER_IMAGE_UPLOAD_NEW . '");
553: window.clearInterval(interval);
554: // enable upload button
555: this.enable();
556: // add file to the list
557: var result = eval(response);
558: if (result[0] == "success") {
559: $("#image_item").append("<option value=\'" + result[1] + "\' selected=\'selected\'>" + result[2] + "</option>");
560: publisher_updateSelectOption(\'image_item\', \'image_featured\');
561: showImgSelected(\'image_display\', \'image_item\', \'uploads/\', \'\', \'' . \XoopsBaseConfig::get('url') . '\')
562: } else {
563: $("#publisher_upload_message").html("<div class=\'errorMsg\'>" + result[1] + "</div>");
564: }
565: }
566: });
567: });
568: /*]]>*/</script>
569: ');
570: $messages = new Xoops\Form\Label('', "<div id='publisher_upload_message'></div>");
571: $button = new Xoops\Form\Label(
572: '',
573: "<div id='publisher_upload_button'>" . _CO_PUBLISHER_IMAGE_UPLOAD_NEW . "</div>"
574: );
575: $nicename = new Xoops\Form\Text('', 'image_nicename', 30, 30, _CO_PUBLISHER_IMAGE_NICENAME);
576:
577: $catlist = $imgcat_handler->getListByPermission($group, 'imgcat_read', 1);
578: $imagecat = new Xoops\Form\Select('', 'imgcat_id', '', 1);
579: $imagecat->addOptionArray($catlist);
580:
581: $image_upload_tray = new Xoops\Form\ElementTray(_CO_PUBLISHER_IMAGE_UPLOAD, '');
582: $image_upload_tray->addElement($js_data);
583: $image_upload_tray->addElement($messages);
584: $image_upload_tray->addElement($opentable);
585:
586: $image_upload_tray->addElement($imagecat);
587:
588: $image_upload_tray->addElement($addbreak);
589:
590: $image_upload_tray->addElement($nicename);
591:
592: $image_upload_tray->addElement($addbreak);
593:
594: $image_upload_tray->addElement($button);
595:
596: $image_upload_tray->addElement($closetable);
597: $imagesTab->addElement($image_upload_tray);
598:
599: $image_tray = new Xoops\Form\ElementTray(_CO_PUBLISHER_IMAGE_ITEMS, '');
600: $image_tray->addElement($opentable);
601:
602: $image_tray->addElement($image_select);
603: $image_tray->addElement($addbreak);
604: $image_tray->addElement($buttonadd);
605:
606: $image_tray->addElement($addcol);
607:
608: $image_tray->addElement($image_select2);
609: $image_tray->addElement($addbreak);
610: $image_tray->addElement($buttonremove);
611:
612: $image_tray->addElement($closetable);
613: $image_tray->setDescription(_CO_PUBLISHER_IMAGE_ITEMS_DSC);
614: $imagesTab->addElement($image_tray);
615:
616: $imagename = is_object($objimages['main']) ? $objimages['main']->getVar('image_name') : '';
617: $imageforpath = ($imagename != '') ? $imagename : 'blank.gif';
618:
619: $image_select3 = new Xoops\Form\Select(_CO_PUBLISHER_IMAGE_ITEM, 'image_featured', $imagename, 1);
620: $image_select3->addOptionArray($objimage_array);
621: $image_select3->set(
622: 'onchange',
623: 'showImgSelected("image_display", "image_featured", "uploads/", "", "'
624: . \XoopsBaseConfig::get('url') . '");'
625: );
626: $image_select3->setDescription(_CO_PUBLISHER_IMAGE_ITEM_DSC);
627: $imagesTab->addElement($image_select3);
628:
629: $imgTag = new Xoops\Html\Img([
630: 'src' => $xoops->url('uploads/' . $imageforpath),
631: 'width' => 500,
632: 'name' => 'image_display',
633: 'id' => 'image_display',
634: 'alt' => '',
635:
636: ]);
637: $image_preview = new Xoops\Form\Label(_CO_PUBLISHER_IMAGE_PREVIEW, $imgTag->render());
638: $imagesTab->addElement($image_preview);
639: }
640: }
641:
642: 643: 644: 645: 646: 647: 648: 649:
650: private function buildOthersTab(PublisherItem $obj, ContainerInterface $othersTab)
651: {
652:
653: if ($this->isGranted(_PUBLISHER_ITEM_META_KEYWORDS)) {
654: $text_meta_keywords = new Xoops\Form\TextArea(
655: _CO_PUBLISHER_ITEM_META_KEYWORDS,
656: 'item_meta_keywords',
657: $obj->getVar('meta_keywords', 'e'),
658: 7,
659: 60
660: );
661: $text_meta_keywords->setDescription(_CO_PUBLISHER_ITEM_META_KEYWORDS_DSC);
662: $othersTab ->addElement($text_meta_keywords);
663: }
664:
665:
666: if ($this->isGranted(_PUBLISHER_ITEM_META_DESCRIPTION)) {
667: $text_meta_description = new Xoops\Form\TextArea(
668: _CO_PUBLISHER_ITEM_META_DESCRIPTION,
669: 'item_meta_description',
670: $obj->getVar('meta_description', 'e'),
671: 7,
672: 60
673: );
674: $text_meta_description->setDescription(_CO_PUBLISHER_ITEM_META_DESCRIPTION_DSC);
675: $othersTab ->addElement($text_meta_description);
676: }
677:
678:
679: if ($this->isGranted(_PUBLISHER_ALLOWCOMMENTS)) {
680: $addcomments_radio = new Xoops\Form\RadioYesNo(
681: _CO_PUBLISHER_ALLOWCOMMENTS,
682: 'allowcomments',
683: $obj->getVar('cancomment')
684: );
685: $othersTab ->addElement($addcomments_radio);
686: }
687:
688:
689: if ($this->isGranted(_PUBLISHER_WEIGHT)) {
690: $othersTab ->addElement(
691: new Xoops\Form\Text(_CO_PUBLISHER_WEIGHT, 'weight', 5, 5, $obj->getVar('weight'))
692: );
693: }
694: }
695:
696: 697: 698: 699: 700: 701: 702:
703: public function setCheckPermissions($checkperm)
704: {
705: $this->checkperm = (bool)$checkperm;
706: }
707:
708: 709: 710: 711: 712: 713: 714:
715: private function isGranted($item)
716: {
717: $publisher = Publisher::getInstance();
718: $ret = false;
719: if (!$this->checkperm || $publisher->getPermissionHandler()->isGranted('form_view', $item)) {
720: $ret = true;
721: }
722: return $ret;
723: }
724:
725: 726: 727: 728: 729: 730: 731:
732: private function hasTab($tab)
733: {
734: if (!isset($tab) || !isset($this->tabs[$tab])) {
735: return false;
736: }
737:
738: $tabRef = $this->tabs[$tab];
739: $items = $this->$tabRef;
740: foreach ($items as $item) {
741: if ($this->isGranted($item)) {
742: return true;
743: }
744: }
745:
746: return false;
747: }
748: }
749: