Esempio n. 1
0
 function display($tpl = null)
 {
     //initialise variables
     $app = JFactory::getApplication();
     $document = JFactory::getDocument();
     $user = JFactory::getUser();
     //$authorparams = flexicontent_db::getUserConfig($user->id);
     //add css to document
     $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/flexicontentbackend.css');
     if (FLEXI_J30GE) {
         $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/j3x.css');
     } else {
         if (FLEXI_J16GE) {
             $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/j25.css');
         } else {
             $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/j15.css');
         }
     }
     //create the toolbar
     JToolBarHelper::title(JText::_('FLEXI_EDIT_FILE'), 'fileedit');
     if (FLEXI_J16GE) {
         JToolBarHelper::apply('filemanager.apply');
         JToolBarHelper::save('filemanager.save');
         JToolBarHelper::cancel('filemanager.cancel');
     } else {
         JToolBarHelper::apply();
         JToolBarHelper::save();
         JToolBarHelper::cancel();
     }
     //Get data from the model
     $model = $this->getModel();
     if (FLEXI_J16GE) {
         $form = $this->get('Form');
     }
     $row = $this->get('File');
     // fail if checked out not by 'me'
     if ($row->id) {
         if ($model->isCheckedOut($user->get('id'))) {
             JError::raiseWarning('SOME_ERROR_CODE', $row->name . ' ' . JText::_('FLEXI_EDITED_BY_ANOTHER_ADMIN'));
             $app->redirect('index.php?option=com_flexicontent&view=filemanager');
         }
     }
     //build access level list
     if (FLEXI_J16GE) {
         $lists['access'] = JHTML::_('access.assetgrouplist', 'access', $row->access);
     } else {
         if (FLEXI_ACCESS) {
             $lists['access'] = FAccess::TabGmaccess($row, 'field', 1, 0, 0, 0, 0, 0, 0, 0, 0);
         } else {
             $lists['access'] = JHTML::_('list.accesslevel', $row);
         }
     }
     // Build languages list
     //$allowed_langs = !$authorparams ? null : $authorparams->get('langs_allowed',null);
     //$allowed_langs = !$allowed_langs ? null : FLEXIUtilities::paramToArray($allowed_langs);
     $allowed_langs = null;
     if (FLEXI_FISH || FLEXI_J16GE) {
         $lists['language'] = flexicontent_html::buildlanguageslist('language', '', $row->language, 3, $allowed_langs, $published_only = false);
     } else {
         $lists['language'] = flexicontent_html::getSiteDefaultLang() . '<input type="hidden" name="language" value="' . flexicontent_html::getSiteDefaultLang() . '" />';
     }
     //clean data
     JFilterOutput::objectHTMLSafe($row, ENT_QUOTES);
     //assign data to template
     if (FLEXI_J16GE) {
         $this->assignRef('form', $form);
     }
     $this->assignRef('row', $row);
     $this->assignRef('lists', $lists);
     $this->assignRef('document', $document);
     parent::display($tpl);
 }
Esempio n. 2
0
 function display($tpl = null)
 {
     //initialise variables
     $app = JFactory::getApplication();
     $document = JFactory::getDocument();
     $cparams = JComponentHelper::getParams('com_flexicontent');
     $user = JFactory::getUser();
     //add css to document
     $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/flexicontentbackend.css');
     if (FLEXI_J30GE) {
         $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/j3x.css');
     } else {
         if (FLEXI_J16GE) {
             $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/j25.css');
         } else {
             $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/j15.css');
         }
     }
     //add js function to overload the joomla submitform
     FLEXI_J30GE ? JHtml::_('behavior.framework', true) : JHTML::_('behavior.mootools');
     JHTML::_('behavior.tooltip');
     flexicontent_html::loadFramework('jQuery');
     flexicontent_html::loadFramework('select2');
     $document->addScript(JURI::root() . 'components/com_flexicontent/assets/js/admin.js');
     $document->addScript(JURI::root() . 'components/com_flexicontent/assets/js/validate.js');
     //Load pane behavior
     jimport('joomla.html.pane');
     //Import File system
     jimport('joomla.filesystem.file');
     //Get data from the model
     $model = $this->getModel();
     $row = $this->get('Field');
     if (FLEXI_J16GE) {
         $form = $this->get('Form');
     }
     $types = $this->get('Typeslist');
     $typesselected = $this->get('Typesselected');
     //create the toolbar
     if ($row->id) {
         JToolBarHelper::title(JText::_('FLEXI_EDIT_FIELD'), 'fieldedit');
     } else {
         JToolBarHelper::title(JText::_('FLEXI_ADD_FIELD'), 'fieldadd');
     }
     $ctrl = FLEXI_J16GE ? 'fields.' : '';
     JToolBarHelper::apply($ctrl . 'apply');
     JToolBarHelper::save($ctrl . 'save');
     JToolBarHelper::custom($ctrl . 'saveandnew', 'savenew.png', 'savenew.png', 'FLEXI_SAVE_AND_NEW', false);
     JToolBarHelper::cancel($ctrl . 'cancel');
     // Import Joomla plugin that implements the type of current flexi field
     JPluginHelper::importPlugin('flexicontent_fields', $row->iscore ? 'core' : $row->field_type);
     // load plugin's english language file then override with current language file
     $extension_name = 'plg_flexicontent_fields_' . ($row->iscore ? 'core' : $row->field_type);
     JFactory::getLanguage()->load($extension_name, JPATH_ADMINISTRATOR, 'en-GB', true);
     JFactory::getLanguage()->load($extension_name, JPATH_ADMINISTRATOR, null, true);
     //check which properties are supported by current field
     $ft_support = FlexicontentFields::getPropertySupport($row->field_type, $row->iscore);
     $supportsearch = $ft_support->supportsearch;
     $supportadvsearch = $ft_support->supportadvsearch;
     $supportfilter = $ft_support->supportfilter;
     $supportadvfilter = $ft_support->supportadvfilter;
     $supportuntranslatable = $ft_support->supportuntranslatable;
     $supportvalueseditable = $ft_support->supportvalueseditable;
     $supportformhidden = $ft_support->supportformhidden;
     $supportedithelp = $ft_support->supportedithelp;
     //build selectlists, (for J1.6+ most of these are defined via XML file and custom form field classes)
     $lists = array();
     //build field_type list
     if (!$row->field_type) {
         $row->field_type = 'text';
     }
     if ($row->iscore == 1) {
         $class = 'disabled="disabled"';
     } else {
         $class = '';
         $_field_id = '#' . (FLEXI_J16GE ? 'jform_' : '') . 'field_type';
         $_row_id = FLEXI_J16GE ? $form->getValue("id") : $row->id;
         $_ctrl_task = FLEXI_J16GE ? 'task=fields.getfieldspecificproperties' : 'controller=fields&task=getfieldspecificproperties';
         $document->addScriptDeclaration("\n\t\t\t\tjQuery(document).ready(function() {\n\t\t\t\t\tjQuery('" . $_field_id . "').on('change', function() {\n\t\t\t\t\t\tjQuery('#fieldspecificproperties').html('<p class=\"centerimg\"><img src=\"components/com_flexicontent/assets/images/ajax-loader.gif\" align=\"center\"></p>');\n\t\t\t\t\t\tjQuery.ajax({\n\t\t\t\t\t\t\ttype: \"GET\",\n\t\t\t\t\t\t\turl: 'index.php?option=com_flexicontent&" . $_ctrl_task . "&cid=" . $_row_id . "&field_type='+this.value+'&format=raw',\n\t\t\t\t\t\t\tsuccess: function(str) {\n\t\t\t\t\t\t\t\tjQuery('#fieldspecificproperties').html(str);\n\t\t\t\t\t\t\t\tvar JTooltips = new Tips(jQuery('#fieldspecificproperties .hasTip'), { maxTitleChars: 50, fixed: false});\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tjQuery('#field_typename').html(jQuery('" . $_field_id . "').val());\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t");
     }
     //build field select list
     $lists['field_type'] = flexicontent_html::buildfieldtypeslist('field_type', $class, $row->field_type, $group = true);
     //build type select list
     $attribs = 'class="use_select2_lib" multiple="multiple" size="6"';
     $attribs .= $row->iscore ? ' disabled="disabled"' : '';
     $types_fieldname = FLEXI_J16GE ? 'jform[tid][]' : 'tid[]';
     $lists['tid'] = flexicontent_html::buildtypesselect($types, $types_fieldname, $typesselected, false, $attribs);
     // **************************************************************************
     // Create fields for J1.5 (J2.5+ uses JForm XML file for most of form fields)
     // **************************************************************************
     if (!FLEXI_J16GE) {
         //build formhidden selector
         $formhidden[] = JHTML::_('select.option', 0, JText::_('FLEXI_NO'));
         $formhidden[] = JHTML::_('select.option', 1, JText::_('FLEXI_FRONTEND'));
         $formhidden[] = JHTML::_('select.option', 2, JText::_('FLEXI_BACKEND'));
         $formhidden[] = JHTML::_('select.option', 3, JText::_('FLEXI_BOTH'));
         $formhidden_fieldname = FLEXI_J16GE ? 'jform[formhidden]' : 'formhidden';
         $lists['formhidden'] = JHTML::_('select.radiolist', $formhidden, $formhidden_fieldname, '', 'value', 'text', $row->formhidden);
         if (FLEXI_ACCESS) {
             $valueseditable[] = JHTML::_('select.option', 0, JText::_('FLEXI_ANY_EDITOR'));
             $valueseditable[] = JHTML::_('select.option', 1, JText::_('FLEXI_USE_ACL_PERMISSION'));
             $valueseditable_fieldname = FLEXI_J16GE ? 'jform[valueseditable]' : 'valueseditable';
             $lists['valueseditable'] = JHTML::_('select.radiolist', $valueseditable, $valueseditable_fieldname, '', 'value', 'text', $row->valueseditable);
         }
         $edithelp[] = JHTML::_('select.option', 0, JText::_('FLEXI_EDIT_HELP_NONE'));
         $edithelp[] = JHTML::_('select.option', 1, JText::_('FLEXI_EDIT_HELP_LABEL_TOOLTIP'));
         $edithelp[] = JHTML::_('select.option', 2, JText::_('FLEXI_EDIT_HELP_LABEL_TOOLTIP_WICON'));
         $edithelp[] = JHTML::_('select.option', 3, JText::_('FLEXI_EDIT_HELP_INLINE'));
         $edithelp_fieldname = FLEXI_J16GE ? 'jform[edithelp]' : 'edithelp';
         $lists['edithelp'] = JHTML::_('select.radiolist', $edithelp, $edithelp_fieldname, '', 'value', 'text', $row->edithelp);
         // build the html select list for ordering
         $query = 'SELECT ordering AS value, label AS text' . ' FROM #__flexicontent_fields' . ' WHERE published >= 0' . ' ORDER BY ordering';
         $row->ordering = @$row->ordering;
         $lists['ordering'] = $row->id ? JHTML::_('list.specificordering', $row, $row->id, $query) : JHTML::_('list.specificordering', $row, '', $query);
         //build access level list
         if (FLEXI_ACCESS) {
             $lang = JFactory::getLanguage();
             $lang->_strings['FLEXIACCESS_PADD'] = 'Edit-Value';
             $lists['access'] = FAccess::TabGmaccess($row, 'field', 1, 1, 0, 1, 0, 1, 0, 1, 1);
         } else {
             $lists['access'] = JHTML::_('list.accesslevel', $row);
         }
     }
     if (!FLEXI_J16GE) {
         // Create the parameter 's form object parsing the file XML
         $pluginpath = JPATH_PLUGINS . DS . 'flexicontent_fields' . DS . $row->field_type . '.xml';
         if (JFile::exists($pluginpath)) {
             $form = new JParameter('', $pluginpath);
         } else {
             $form = new JParameter('', JPATH_PLUGINS . DS . 'flexicontent_fields' . DS . 'core.xml');
         }
         // Special and Core Groups
         $form->loadINI($row->attribs);
     }
     // fail if checked out not by 'me'
     if ($row->id) {
         if ($model->isCheckedOut($user->get('id'))) {
             JError::raiseWarning('SOME_ERROR_CODE', $row->name . ' ' . JText::_('FLEXI_EDITED_BY_ANOTHER_ADMIN'));
             $app->redirect('index.php?option=com_flexicontent&view=fields');
         }
     }
     //clean data
     JFilterOutput::objectHTMLSafe($row, ENT_QUOTES);
     // assign permissions for J2.5
     if (FLEXI_J16GE) {
         $permission = FlexicontentHelperPerm::getPerm();
         $this->assignRef('permission', $permission);
     }
     //assign data to template
     $this->assignRef('document', $document);
     $this->assignRef('row', $row);
     $this->assignRef('lists', $lists);
     $this->assignRef('form', $form);
     $this->assignRef('typesselected', $typesselected);
     $this->assignRef('supportsearch', $supportsearch);
     $this->assignRef('supportadvsearch', $supportadvsearch);
     $this->assignRef('supportfilter', $supportfilter);
     $this->assignRef('supportadvfilter', $supportadvfilter);
     $this->assignRef('supportuntranslatable', $supportuntranslatable);
     $this->assignRef('supportvalueseditable', $supportvalueseditable);
     $this->assignRef('supportformhidden', $supportformhidden);
     $this->assignRef('supportedithelp', $supportedithelp);
     parent::display($tpl);
 }
Esempio n. 3
0
 function display($tpl = null)
 {
     global $globalcats;
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $document = JFactory::getDocument();
     if (FLEXI_J16GE) {
         JFactory::getLanguage()->load('com_categories', JPATH_ADMINISTRATOR, 'en-GB', true);
         JFactory::getLanguage()->load('com_categories', JPATH_ADMINISTRATOR, null, true);
     }
     // ***********************************************************
     // Get category data, and check if item is already checked out
     // ***********************************************************
     // Get data from the model
     $model = $this->getModel();
     if (FLEXI_J16GE) {
         $row = $this->get('Item');
         $form = $this->get('Form');
     } else {
         $row = $this->get('Category');
     }
     $catparams = FLEXI_J16GE ? new JRegistry($row->params) : new JParameter($row->params);
     $cid = $row->id;
     $isnew = !$cid;
     // Check category is checked out by different editor / administrator
     if (!$isnew && $model->isCheckedOut($user->get('id'))) {
         JError::raiseWarning('SOME_ERROR_CODE', $row->title . ' ' . JText::_('FLEXI_EDITED_BY_ANOTHER_ADMIN'));
         $app->redirect('index.php?option=com_flexicontent&view=categories');
     }
     // ***************************************************************************
     // Currently access checking for category add/edit form , it is done here, for
     // most other views we force going though the controller and checking it there
     // ***************************************************************************
     // *********************************************************************************************
     // Global Permssions checking (needed because this view can be called without a controller task)
     // *********************************************************************************************
     // Get global permissions
     $perms = FlexicontentHelperPerm::getPerm();
     // handles super admins correctly
     // Check no access to categories management (Global permission)
     if (!$perms->CanCats) {
         $app->redirect('index.php?option=com_flexicontent', JText::_('FLEXI_NO_ACCESS'));
     }
     // Check no privilege to create new categories (Global permission)
     if ($isnew && !$perms->CanAddCats) {
         JError::raiseWarning(403, JText::_('FLEXI_NO_ACCESS_CREATE'));
         $app->redirect('index.php?option=com_flexicontent');
     }
     // ************************************************************************************
     // Record Permssions (needed because this view can be called without a controller task)
     // ************************************************************************************
     // Get edit privilege for current category
     if (!$isnew) {
         if (FLEXI_J16GE) {
             $isOwner = $row->get('created_by') == $user->id;
             $rights = FlexicontentHelperPerm::checkAllItemAccess($user->id, 'category', $cid);
             $canedit_cat = in_array('edit', $rights) || in_array('edit.own', $rights) && $isOwner;
         } else {
             if (FLEXI_ACCESS) {
                 $rights = FAccess::checkAllItemAccess('com_content', 'users', $user->gmid, 0, $row->id);
                 $canedit_cat = $user->gid < 25 ? in_array('edit', $rights) || in_array('editown', $rights) : 1;
             } else {
                 $canedit_cat = true;
             }
         }
     }
     // Get if we can create inside at least one (com_content) category
     if (!FLEXI_J16GE || $user->authorise('core.create', 'com_flexicontent')) {
         $cancreate_cat = true;
     } else {
         $usercats = FlexicontentHelperPerm::getAllowedCats($user, $actions_allowed = array('core.create'), $require_all = true, $check_published = true, $specific_catids = false, $find_first = true);
         $cancreate_cat = count($usercats) > 0;
     }
     // Creating new category: Check if user can create inside any existing category
     if ($isnew && !$cancreate_cat) {
         $acc_msg = JText::_('FLEXI_NO_ACCESS_CREATE') . "<br/>" . (FLEXI_J16GE ? JText::_('FLEXI_CANNOT_ADD_CATEGORY_REASON') : "");
         JError::raiseWarning(403, $acc_msg);
         $app->redirect('index.php?option=com_flexicontent&view=categories');
     }
     // Editing existing category: Check if user can edit existing (current) category
     if (!$isnew && !$canedit_cat) {
         $acc_msg = JText::_('FLEXI_NO_ACCESS_EDIT') . "<br/>" . JText::_('FLEXI_CANNOT_EDIT_CATEGORY_REASON');
         JError::raiseWarning(403, $acc_msg);
         $app->redirect('index.php?option=com_flexicontent&view=categories');
     }
     // **************************************************
     // Include needed files and add needed js / css files
     // **************************************************
     FLEXI_J30GE ? JHtml::_('behavior.framework', true) : JHTML::_('behavior.mootools');
     flexicontent_html::loadFramework('jQuery');
     flexicontent_html::loadFramework('select2');
     // Load pane behavior
     jimport('joomla.html.pane');
     // Load tooltips
     JHTML::_('behavior.tooltip');
     // Add css to document
     $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/flexicontentbackend.css');
     if (FLEXI_J30GE) {
         $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/j3x.css');
     } else {
         if (FLEXI_J16GE) {
             $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/j25.css');
         } else {
             $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/j15.css');
         }
     }
     // Add js function to overload the joomla submitform
     $document->addScript(JURI::root() . 'components/com_flexicontent/assets/js/admin.js');
     $document->addScript(JURI::root() . 'components/com_flexicontent/assets/js/validate.js');
     // ********************
     // Initialise variables
     // ********************
     $editor_name = $user->getParam('editor', $app->getCfg('editor'));
     $editor = JFactory::getEditor($editor_name);
     $cparams = JComponentHelper::getParams('com_flexicontent');
     $bar = JToolBar::getInstance('toolbar');
     if (!FLEXI_J16GE) {
         $pane = JPane::getInstance('sliders');
         $tpane = JPane::getInstance('tabs', array('startOffset' => 0, 'allowAllClose' => true, 'opacityTransition' => true, 'duration' => 600));
     }
     $categories = $globalcats;
     // ******************
     // Create the toolbar
     // ******************
     // Create Toolbar title and add the preview button
     if (!$isnew) {
         JToolBarHelper::title(JText::_('FLEXI_EDIT_CATEGORY'), 'fc_categoryedit');
         $autologin = $cparams->get('autoflogin', 1) ? '&fcu=' . $user->username . '&fcp=' . $user->password : '';
         $previewlink = JRoute::_(JURI::root() . FlexicontentHelperRoute::getCategoryRoute($categories[$cid]->slug)) . $autologin;
         // Add a preview button
         $bar->appendButton('Custom', '<a class="preview btn btn-small" href="' . $previewlink . '" target="_blank"><span title="' . JText::_('Preview') . '" class="icon-32-preview"></span>' . JText::_('Preview') . '</a>', 'preview');
     } else {
         JToolBarHelper::title(JText::_('FLEXI_NEW_CATEGORY'), 'fc_categoryadd');
     }
     // Add apply and save buttons
     if (FLEXI_J16GE) {
         JToolBarHelper::apply('category.apply');
         JToolBarHelper::save('category.save');
     } else {
         JToolBarHelper::apply();
         JToolBarHelper::save();
     }
     // Add a save and new button, if user can create inside at least one (com_content) category
     if ($cancreate_cat) {
         if (FLEXI_J16GE) {
             JToolBarHelper::save2new('category.save2new');
         } else {
             JToolBarHelper::custom('saveandnew', 'savenew.png', 'savenew.png', 'FLEXI_SAVE_AND_NEW', false);
         }
     }
     // Add a save as copy button, if editing an existing category (J2.5 only)
     if (FLEXI_J16GE && !$isnew && $cancreate_cat) {
         JToolBarHelper::save2copy('category.save2copy');
     }
     // Add a cancel or close button
     if ($isnew) {
         if (FLEXI_J16GE) {
             JToolBarHelper::cancel('category.cancel');
         } else {
             JToolBarHelper::cancel();
         }
     } else {
         if (FLEXI_J16GE) {
             JToolBarHelper::cancel('category.cancel', 'JTOOLBAR_CLOSE');
         } else {
             JToolBarHelper::custom('cancel', 'cancel.png', 'cancel.png', 'CLOSE', false);
         }
     }
     // *******************************************
     // Prepare data to pass to the form's template
     // *******************************************
     if (!FLEXI_J16GE) {
         //clean data
         JFilterOutput::objectHTMLSafe($row, ENT_QUOTES, 'description');
         // Create the form
         $form = new JParameter($row->params, JPATH_COMPONENT . DS . 'models' . DS . 'category.xml');
         //$form->loadINI($row->attribs);
         //echo "<pre>"; print_r($form->_xml['templates']->_children[0]);  echo "<pre>"; print_r($form->_xml['templates']->param[0]); exit;
         foreach ($form->_xml['templates']->_children as $i => $child) {
             if (isset($child->_attributes['enableparam']) && !$cparams->get($child->_attributes['enableparam'])) {
                 unset($form->_xml['templates']->_children[$i]);
                 unset($form->_xml['templates']->param[$i]);
             }
         }
         foreach ($form->_xml['special']->_children as $i => $child) {
             if (isset($child->_attributes['enableparam']) && !$cparams->get($child->_attributes['enableparam'])) {
                 unset($form->_xml['special']->_children[$i]);
                 unset($form->_xml['special']->param[$i]);
             }
         }
     }
     // **********************************************************************************
     // Get Templates and apply Template Parameters values into the form fields structures
     // **********************************************************************************
     $themes = flexicontent_tmpl::getTemplates();
     $tmpls = $themes->category;
     foreach ($tmpls as $tmpl) {
         if (FLEXI_J16GE) {
             $jform = new JForm('com_flexicontent.template.category', array('control' => 'jform', 'load_data' => true));
             $jform->load($tmpl->params);
             $tmpl->params = $jform;
             // ... values applied at the template form file
         } else {
             $tmpl->params->loadINI($row->params);
         }
     }
     //build selectlists
     $Lists = array();
     if (!FLEXI_J16GE) {
         $javascript = "onchange=\"javascript:if (document.forms[0].image.options[selectedIndex].value!='') {document.imagelib.src='../images/stories/' + document.forms[0].image.options[selectedIndex].value} else {document.imagelib.src='../images/blank.png'}\"";
         $Lists['imagelist'] = JHTML::_('list.images', 'image', $row->image, $javascript, '/images/stories/');
         $Lists['access'] = JHTML::_('list.accesslevel', $row);
         // build granular access list
         if (FLEXI_ACCESS) {
             $Lists['access'] = FAccess::TabGmaccess($row, 'category', 1, 1, 1, 1, 1, 1, 1, 1, 1);
         }
     }
     $check_published = false;
     $check_perms = true;
     $actions_allowed = array('core.create');
     $fieldname = FLEXI_J16GE ? 'jform[parent_id]' : 'parent_id';
     $Lists['parent_id'] = flexicontent_cats::buildcatselect($categories, $fieldname, $row->parent_id, $top = 1, 'class="use_select2_lib"', $check_published, $check_perms, $actions_allowed, $require_all = true, $skip_subtrees = array(), $disable_subtrees = array($row->id));
     $check_published = false;
     $check_perms = true;
     $actions_allowed = array('core.edit', 'core.edit.own');
     $fieldname = FLEXI_J16GE ? 'jform[copycid]' : 'copycid';
     $Lists['copycid'] = flexicontent_cats::buildcatselect($categories, $fieldname, '', $top = 2, 'class="use_select2_lib"', $check_published, $check_perms, $actions_allowed, $require_all = false);
     $custom_options[''] = 'FLEXI_USE_GLOBAL';
     $custom_options['0'] = 'FLEXI_COMPONENT_ONLY';
     $custom_options['-1'] = 'FLEXI_PARENT_CAT_MULTI_LEVEL';
     $check_published = false;
     $check_perms = true;
     $actions_allowed = array('core.edit', 'core.edit.own');
     $fieldname = FLEXI_J16GE ? 'jform[special][inheritcid]' : 'params[inheritcid]';
     $Lists['inheritcid'] = flexicontent_cats::buildcatselect($categories, $fieldname, $catparams->get('inheritcid', ''), $top = false, 'class="use_select2_lib"', $check_published, $check_perms, $actions_allowed, $require_all = false, $skip_subtrees = array(), $disable_subtrees = array(), $custom_options);
     // ************************
     // Assign variables to view
     // ************************
     $this->assignRef('document', $document);
     $this->assignRef('Lists', $Lists);
     $this->assignRef('row', $row);
     $this->assignRef('form', $form);
     $this->assignRef('perms', $perms);
     $this->assignRef('editor', $editor);
     $this->assignRef('tmpls', $tmpls);
     $this->assignRef('cparams', $cparams);
     if (!FLEXI_J16GE) {
         $this->assignRef('pane', $pane);
         $this->assignRef('tpane', $tpane);
     }
     parent::display($tpl);
 }
Esempio n. 4
0
    function display($tpl = null)
    {
        //initialise variables
        $app = JFactory::getApplication();
        $option = JRequest::getVar('option');
        $document = JFactory::getDocument();
        $cparams = JComponentHelper::getParams('com_flexicontent');
        $user = JFactory::getUser();
        //add css to document
        $document->addStyleSheetVersion(JURI::base(true) . '/components/com_flexicontent/assets/css/flexicontentbackend.css', FLEXI_VHASH);
        $document->addStyleSheetVersion(JURI::base(true) . '/components/com_flexicontent/assets/css/j3x.css', FLEXI_VHASH);
        // Add JS frameworks
        flexicontent_html::loadFramework('select2');
        // Add js function to overload the joomla submitform validation
        JHTML::_('behavior.formvalidation');
        // load default validation JS to make sure it is overriden
        $document->addScriptVersion(JURI::root(true) . '/components/com_flexicontent/assets/js/admin.js', FLEXI_VHASH);
        $document->addScriptVersion(JURI::root(true) . '/components/com_flexicontent/assets/js/validate.js', FLEXI_VHASH);
        //Load pane behavior
        jimport('joomla.html.pane');
        //Import File system
        jimport('joomla.filesystem.file');
        //Get data from the model
        $model = $this->getModel();
        $row = $this->get('Field');
        $form = $this->get('Form');
        $types = $this->get('Typeslist');
        $typesselected = $this->get('Typesselected');
        //create the toolbar
        if ($row->id) {
            JToolBarHelper::title(JText::_('FLEXI_EDIT_FIELD'), 'fieldedit');
        } else {
            JToolBarHelper::title(JText::_('FLEXI_ADD_FIELD'), 'fieldadd');
        }
        $ctrl = FLEXI_J16GE ? 'fields.' : '';
        JToolBarHelper::apply($ctrl . 'apply');
        JToolBarHelper::save($ctrl . 'save');
        JToolBarHelper::custom($ctrl . 'saveandnew', 'savenew.png', 'savenew.png', 'FLEXI_SAVE_AND_NEW', false);
        JToolBarHelper::cancel($ctrl . 'cancel');
        // Import Joomla plugin that implements the type of current flexi field
        $extfolder = 'flexicontent_fields';
        $extname = $row->iscore ? 'core' : $row->field_type;
        JPluginHelper::importPlugin('flexicontent_fields', $row->iscore ? 'core' : $row->field_type);
        // Create class name of the plugin and then create a plugin instance
        $classname = 'plg' . ucfirst($extfolder) . $extname;
        // Check max allowed version
        if (property_exists($classname, 'prior_to_version')) {
            // Set a system message with warning of failed PHP limits
            $prior_to_version = $app->getUserStateFromRequest($option . '.flexicontent.prior_to_version_' . $row->field_type, 'prior_to_version_' . $row->field_type, 0, 'int');
            $app->setUserState($option . '.flexicontent.prior_to_version_' . $row->field_type, $prior_to_version + 1);
            if ($prior_to_version < 2) {
                $close_btn = FLEXI_J30GE ? '<a class="close" data-dismiss="alert">&#215;</a>' : '<a class="fc-close" onclick="this.parentNode.parentNode.removeChild(this.parentNode);">&#215;</a>';
                $manifest_path = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_flexicontent' . DS . 'manifest.xml';
                $com_xml = JApplicationHelper::parseXMLInstallFile($manifest_path);
                $ver_exceeded = version_compare(str_replace(' ', '.', $com_xml['version']), str_replace(' ', '.', $classname::$prior_to_version), '>=');
                if ($ver_exceeded) {
                    echo '
					<span class="fc-note fc-mssg-inline">
						' . $close_btn . '
						Warning: installed version of Field: \'<b>' . $extname . '</b>\' was given to be free for FLEXIcontent versions prior to: v' . $classname::$prior_to_version . ' <br/> It may or may not work properly in later versions
					</span>';
                } else {
                    echo '
					<span class="fc-info fc-mssg-inline">
						' . $close_btn . '
						Note: installed version of Field: \'<b>' . $extname . '</b>\' is given free for FLEXIcontent versions prior to: v' . $classname::$prior_to_version . ', &nbsp; &nbsp; nevertheless it will continue to function after FLEXIcontent is upgraded.
					</span>';
                }
            }
        }
        // load plugin's english language file then override with current language file
        $extension_name = 'plg_flexicontent_fields_' . ($row->iscore ? 'core' : $row->field_type);
        JFactory::getLanguage()->load($extension_name, JPATH_ADMINISTRATOR, 'en-GB', true);
        JFactory::getLanguage()->load($extension_name, JPATH_ADMINISTRATOR, null, true);
        //check which properties are supported by current field
        $ft_support = FlexicontentFields::getPropertySupport($row->field_type, $row->iscore);
        $supportsearch = $ft_support->supportsearch;
        $supportadvsearch = $ft_support->supportadvsearch;
        $supportfilter = $ft_support->supportfilter;
        $supportadvfilter = $ft_support->supportadvfilter;
        $supportuntranslatable = $ft_support->supportuntranslatable;
        $supportvalueseditable = $ft_support->supportvalueseditable;
        $supportformhidden = $ft_support->supportformhidden;
        $supportedithelp = $ft_support->supportedithelp;
        //build selectlists, (for J1.6+ most of these are defined via XML file and custom form field classes)
        $lists = array();
        //build field_type list
        if (!$row->field_type) {
            $row->field_type = 'text';
        }
        $_attribs = ' class="use_select2_lib fc_skip_highlight" ';
        if ($row->iscore == 1) {
            $_attribs .= ' disabled="disabled" ';
        } else {
            $_field_id = 'jform_field_type';
            $_row_id = $form->getValue("id");
            $_ctrl_task = 'task=fields.getfieldspecificproperties';
            $document->addScriptDeclaration("\n\t\t\t\tjQuery(document).ready(function() {\n\t\t\t\t\tjQuery('#" . $_field_id . "').on('change', function() {\n\t\t\t\t\t\tjQuery('#fieldspecificproperties').html('<p class=\"centerimg\"><img src=\"components/com_flexicontent/assets/images/ajax-loader.gif\" align=\"center\"></p>');\n\t\t\t\t\t\tjQuery.ajax({\n\t\t\t\t\t\t\ttype: \"GET\",\n\t\t\t\t\t\t\turl: 'index.php?option=com_flexicontent&" . $_ctrl_task . "&cid=" . $_row_id . "&field_type='+this.value+'&format=raw',\n\t\t\t\t\t\t\tsuccess: function(str) {\n\t\t\t\t\t\t\t\tjQuery('#fieldspecificproperties').html(str);\n\t\t\t\t\t\t\t\t" . (FLEXI_J30GE ? "\n\t\t\t\t\t\t\t\t\tjQuery('.hasTooltip').tooltip({'html': true,'container': jQuery('#fieldspecificproperties')});\n\t\t\t\t\t\t\t\t" : "\n\t\t\t\t\t\t\t\tvar tipped_elements = jQuery('#fieldspecificproperties .hasTip');\n\t\t\t\t\t\t\t\ttipped_elements.each(function() {\n\t\t\t\t\t\t\t\t\tvar title = this.get('title');\n\t\t\t\t\t\t\t\t\tif (title) {\n\t\t\t\t\t\t\t\t\t\tvar parts = title.split('::', 2);\n\t\t\t\t\t\t\t\t\t\tthis.store('tip:title', parts[0]);\n\t\t\t\t\t\t\t\t\t\tthis.store('tip:text', parts[1]);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tvar ajax_JTooltips = new Tips(\$('fieldspecificproperties').getElements('.hasTip'), { maxTitleChars: 50, fixed: false});\n\t\t\t\t\t\t\t\t") . "\n\t\t\t\t\t\t\t\ttabberAutomatic(tabberOptions, 'fieldspecificproperties');\n\t\t\t\t\t\t\t\tfc_bindFormDependencies('#fieldspecificproperties', 0, '');\n\t\t\t\t\t\t\t\tjQuery('#field_typename').html(jQuery('#" . $_field_id . "').val());\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t");
        }
        //build field select list
        $fieldtypes = flexicontent_db::getFieldTypes($_grouped = true, $_usage = false, $_published = true);
        $fftypes = array();
        foreach ($fieldtypes as $field_group => $ft_types) {
            $fftypes[] = $field_group;
            foreach ($ft_types as $field_type => $ftdata) {
                $fftypes[] = array('value' => $ftdata->field_type, 'text' => $ftdata->friendly);
            }
            $fftypes[] = '';
        }
        $lists['field_type'] = flexicontent_html::buildfieldtypeslist($fftypes, 'jform[field_type]', $row->field_type, $_grouped ? 1 : 0, $_attribs);
        //build type select list
        $attribs = 'class="use_select2_lib" multiple="multiple" size="6"';
        $attribs .= $row->iscore ? ' disabled="disabled"' : '';
        $types_fieldname = FLEXI_J16GE ? 'jform[tid][]' : 'tid[]';
        $lists['tid'] = flexicontent_html::buildtypesselect($types, $types_fieldname, $typesselected, false, $attribs);
        // **************************************************************************
        // Create fields for J1.5 (J2.5+ uses JForm XML file for most of form fields)
        // **************************************************************************
        if (!FLEXI_J16GE) {
            //build formhidden selector
            $formhidden[] = JHTML::_('select.option', 0, JText::_('FLEXI_NO'));
            $formhidden[] = JHTML::_('select.option', 1, JText::_('FLEXI_FRONTEND'));
            $formhidden[] = JHTML::_('select.option', 2, JText::_('FLEXI_BACKEND'));
            $formhidden[] = JHTML::_('select.option', 3, JText::_('FLEXI_BOTH'));
            $formhidden_fieldname = FLEXI_J16GE ? 'jform[formhidden]' : 'formhidden';
            $lists['formhidden'] = JHTML::_('select.radiolist', $formhidden, $formhidden_fieldname, '', 'value', 'text', $row->formhidden);
            if (FLEXI_ACCESS) {
                $valueseditable[] = JHTML::_('select.option', 0, JText::_('FLEXI_ANY_EDITOR'));
                $valueseditable[] = JHTML::_('select.option', 1, JText::_('FLEXI_USE_ACL_PERMISSION'));
                $valueseditable_fieldname = FLEXI_J16GE ? 'jform[valueseditable]' : 'valueseditable';
                $lists['valueseditable'] = JHTML::_('select.radiolist', $valueseditable, $valueseditable_fieldname, '', 'value', 'text', $row->valueseditable);
            }
            $edithelp[] = JHTML::_('select.option', 0, JText::_('FLEXI_EDIT_HELP_NONE'));
            $edithelp[] = JHTML::_('select.option', 1, JText::_('FLEXI_EDIT_HELP_LABEL_TOOLTIP'));
            $edithelp[] = JHTML::_('select.option', 2, JText::_('FLEXI_EDIT_HELP_LABEL_TOOLTIP_WICON'));
            $edithelp[] = JHTML::_('select.option', 3, JText::_('FLEXI_EDIT_HELP_INLINE'));
            $edithelp_fieldname = FLEXI_J16GE ? 'jform[edithelp]' : 'edithelp';
            $lists['edithelp'] = JHTML::_('select.radiolist', $edithelp, $edithelp_fieldname, '', 'value', 'text', $row->edithelp);
            // build the html select list for ordering
            $query = 'SELECT ordering AS value, label AS text' . ' FROM #__flexicontent_fields' . ' WHERE published >= 0' . ' ORDER BY ordering';
            $row->ordering = @$row->ordering;
            $lists['ordering'] = $row->id ? JHTML::_('list.specificordering', $row, $row->id, $query) : JHTML::_('list.specificordering', $row, '', $query);
            //build access level list
            if (FLEXI_ACCESS) {
                $lang = JFactory::getLanguage();
                $lang->_strings['FLEXIACCESS_PADD'] = 'Edit-Value';
                $lists['access'] = FAccess::TabGmaccess($row, 'field', 1, 1, 0, 1, 0, 1, 0, 1, 1);
            } else {
                $lists['access'] = JHTML::_('list.accesslevel', $row);
            }
        }
        if (!FLEXI_J16GE) {
            // Create the parameter 's form object parsing the file XML
            $pluginpath = JPATH_PLUGINS . DS . 'flexicontent_fields' . DS . $row->field_type . '.xml';
            if (JFile::exists($pluginpath)) {
                $form = new JParameter('', $pluginpath);
            } else {
                $form = new JParameter('', JPATH_PLUGINS . DS . 'flexicontent_fields' . DS . 'core.xml');
            }
            // Special and Core Groups
            $form->loadINI($row->attribs);
        }
        // fail if checked out not by 'me'
        if ($row->id) {
            if ($model->isCheckedOut($user->get('id'))) {
                JError::raiseWarning('SOME_ERROR_CODE', $row->name . ' ' . JText::_('FLEXI_EDITED_BY_ANOTHER_ADMIN'));
                $app->redirect('index.php?option=com_flexicontent&view=fields');
            }
        }
        //clean data
        JFilterOutput::objectHTMLSafe($row, ENT_QUOTES);
        // assign permissions for J2.5
        $permission = FlexicontentHelperPerm::getPerm();
        $this->assignRef('permission', $permission);
        //assign data to template
        $this->assignRef('document', $document);
        $this->assignRef('row', $row);
        $this->assignRef('lists', $lists);
        $this->assignRef('form', $form);
        $this->assignRef('typesselected', $typesselected);
        $this->assignRef('supportsearch', $supportsearch);
        $this->assignRef('supportadvsearch', $supportadvsearch);
        $this->assignRef('supportfilter', $supportfilter);
        $this->assignRef('supportadvfilter', $supportadvfilter);
        $this->assignRef('supportuntranslatable', $supportuntranslatable);
        $this->assignRef('supportvalueseditable', $supportvalueseditable);
        $this->assignRef('supportformhidden', $supportformhidden);
        $this->assignRef('supportedithelp', $supportedithelp);
        parent::display($tpl);
    }
Esempio n. 5
0
 function display($tpl = null)
 {
     //initialise variables
     $app = JFactory::getApplication();
     $document = JFactory::getDocument();
     $cparams = JComponentHelper::getParams('com_flexicontent');
     $user = JFactory::getUser();
     //add css to document
     $document->addStyleSheetVersion(JURI::base(true) . '/components/com_flexicontent/assets/css/flexicontentbackend.css', FLEXI_VHASH);
     $document->addStyleSheetVersion(JURI::base(true) . '/components/com_flexicontent/assets/css/j3x.css', FLEXI_VHASH);
     // Add JS frameworks
     flexicontent_html::loadFramework('select2');
     // Add js function to overload the joomla submitform validation
     JHTML::_('behavior.formvalidation');
     // load default validation JS to make sure it is overriden
     $document->addScriptVersion(JURI::root(true) . '/components/com_flexicontent/assets/js/admin.js', FLEXI_VHASH);
     $document->addScriptVersion(JURI::root(true) . '/components/com_flexicontent/assets/js/validate.js', FLEXI_VHASH);
     //Load pane behavior
     jimport('joomla.html.pane');
     //Get data from the model
     $model = $this->getModel();
     $row = $this->get(FLEXI_J16GE ? 'Item' : 'Type');
     $form = $this->get('Form');
     $themes = flexicontent_tmpl::getTemplates();
     $tmpls = $themes->items;
     //create the toolbar
     if ($row->id) {
         JToolBarHelper::title(JText::_('FLEXI_EDIT_TYPE'), 'typeedit');
     } else {
         JToolBarHelper::title(JText::_('FLEXI_ADD_TYPE'), 'typeadd');
     }
     $ctrl = FLEXI_J16GE ? 'types.' : '';
     JToolBarHelper::apply($ctrl . 'apply');
     JToolBarHelper::save($ctrl . 'save');
     JToolBarHelper::custom($ctrl . 'saveandnew', 'savenew.png', 'savenew.png', 'FLEXI_SAVE_AND_NEW', false);
     JToolBarHelper::cancel($ctrl . 'cancel');
     // fail if checked out not by 'me'
     if ($row->id) {
         if ($model->isCheckedOut($user->get('id'))) {
             JError::raiseWarning('SOME_ERROR_CODE', $row->name . ' ' . JText::_('FLEXI_EDITED_BY_ANOTHER_ADMIN'));
             $app->redirect('index.php?option=com_flexicontent&view=types');
         }
     }
     if (FLEXI_ACCESS) {
         $itemscreatable[] = JHTML::_('select.option', 0, JText::_('FLEXI_ANY_AUTHOR'));
         $itemscreatable[] = JHTML::_('select.option', 1, JText::_('FLEXI_USE_ACL_TO_HIDE'));
         $itemscreatable[] = JHTML::_('select.option', 2, JText::_('FLEXI_USE_ACL_TO_DISABLE'));
         $itemscreatable_fieldname = FLEXI_J16GE ? 'jform[itemscreatable]' : 'itemscreatable';
         $lists['itemscreatable'] = JHTML::_('select.genericlist', $itemscreatable, $itemscreatable_fieldname, '', 'value', 'text', $row->itemscreatable);
     }
     //build access level list
     if (!FLEXI_J16GE) {
         if (FLEXI_ACCESS) {
             $lang = JFactory::getLanguage();
             $lang->_strings['FLEXIACCESS_PADD'] = 'Create Items';
             $lists['access'] = FAccess::TabGmaccess($row, 'type', 1, 1, 0, 0, 0, 0, 0, 0, 0);
         } else {
             $lists['access'] = JHTML::_('list.accesslevel', $row);
         }
     }
     if (!FLEXI_J16GE) {
         //clean data
         JFilterOutput::objectHTMLSafe($row, ENT_QUOTES);
         //create the parameter form
         $form = new JParameter($row->attribs, JPATH_COMPONENT . DS . 'models' . DS . 'type.xml');
         //$form->loadINI($row->attribs);
         //echo "<pre>"; print_r($form->_xml['themes']->_children[0]);  echo "<pre>"; print_r($form->_xml['themes']->param[0]); exit;
         foreach ($form->_xml['themes']->_children as $i => $child) {
             if (isset($child->_attributes['enableparam']) && !$cparams->get($child->_attributes['enableparam'])) {
                 unset($form->_xml['themes']->_children[$i]);
                 unset($form->_xml['themes']->param[$i]);
             }
         }
     }
     // Apply Template Parameters values into the form fields structures
     foreach ($tmpls as $tmpl) {
         if (FLEXI_J16GE) {
             $jform = new JForm('com_flexicontent.template.item', array('control' => 'jform', 'load_data' => true));
             $jform->load($tmpl->params);
             $tmpl->params = $jform;
             // ... values applied at the template form file
         } else {
             $tmpl->params->loadINI($row->attribs);
         }
     }
     //assign data to template
     // assign permissions for J2.5
     if (FLEXI_J16GE) {
         $permission = FlexicontentHelperPerm::getPerm();
         $this->assignRef('permission', $permission);
     }
     $this->assignRef('document', $document);
     $this->assignRef('row', $row);
     $this->assignRef('form', $form);
     $this->assignRef('tmpls', $tmpls);
     if (!FLEXI_J16GE) {
         $pane = JPane::getInstance('sliders');
         $this->assignRef('pane', $pane);
         $this->assignRef('lists', $lists);
     }
     parent::display($tpl);
 }
Esempio n. 6
0
 function display($tpl = null)
 {
     global $globalcats;
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $document = JFactory::getDocument();
     JFactory::getLanguage()->load('com_categories', JPATH_ADMINISTRATOR, 'en-GB', true);
     JFactory::getLanguage()->load('com_categories', JPATH_ADMINISTRATOR, null, true);
     // ***********************************************************
     // Get category data, and check if item is already checked out
     // ***********************************************************
     // Get data from the model
     $model = $this->getModel();
     if (FLEXI_J16GE) {
         $row = $this->get('Item');
         $form = $this->get('Form');
     } else {
         $row = $this->get('Category');
     }
     $catparams = new JRegistry($row->params);
     $cid = $row->id;
     $isnew = !$cid;
     // Check category is checked out by different editor / administrator
     if (!$isnew && $model->isCheckedOut($user->get('id'))) {
         JError::raiseWarning('SOME_ERROR_CODE', $row->title . ' ' . JText::_('FLEXI_EDITED_BY_ANOTHER_ADMIN'));
         $app->redirect('index.php?option=com_flexicontent&view=categories');
     }
     // ***************************************************************************
     // Currently access checking for category add/edit form , it is done here, for
     // most other views we force going though the controller and checking it there
     // ***************************************************************************
     // *********************************************************************************************
     // Global Permssions checking (needed because this view can be called without a controller task)
     // *********************************************************************************************
     // Get global permissions
     $perms = FlexicontentHelperPerm::getPerm();
     // handles super admins correctly
     // Check no access to categories management (Global permission)
     if (!$perms->CanCats) {
         $app->redirect('index.php?option=com_flexicontent', JText::_('FLEXI_NO_ACCESS'));
     }
     // Check no privilege to create new categories (Global permission)
     if ($isnew && !$perms->CanAddCats) {
         JError::raiseWarning(403, JText::_('FLEXI_NO_ACCESS_CREATE'));
         $app->redirect('index.php?option=com_flexicontent');
     }
     // ************************************************************************************
     // Record Permssions (needed because this view can be called without a controller task)
     // ************************************************************************************
     // Get edit privilege for current category
     if (!$isnew) {
         if (FLEXI_J16GE) {
             $isOwner = $row->get('created_by') == $user->id;
             $rights = FlexicontentHelperPerm::checkAllItemAccess($user->id, 'category', $cid);
             $canedit_cat = in_array('edit', $rights) || in_array('edit.own', $rights) && $isOwner;
         } else {
             if (FLEXI_ACCESS) {
                 $rights = FAccess::checkAllItemAccess('com_content', 'users', $user->gmid, 0, $row->id);
                 $canedit_cat = $user->gid < 25 ? in_array('edit', $rights) || in_array('editown', $rights) : 1;
             } else {
                 $canedit_cat = true;
             }
         }
     }
     // Get if we can create inside at least one (com_content) category
     if ($user->authorise('core.create', 'com_flexicontent')) {
         $cancreate_cat = true;
     } else {
         $usercats = FlexicontentHelperPerm::getAllowedCats($user, $actions_allowed = array('core.create'), $require_all = true, $check_published = true, $specific_catids = false, $find_first = true);
         $cancreate_cat = count($usercats) > 0;
     }
     // Creating new category: Check if user can create inside any existing category
     if ($isnew && !$cancreate_cat) {
         $acc_msg = JText::_('FLEXI_NO_ACCESS_CREATE') . "<br/>" . (FLEXI_J16GE ? JText::_('FLEXI_CANNOT_ADD_CATEGORY_REASON') : "");
         JError::raiseWarning(403, $acc_msg);
         $app->redirect('index.php?option=com_flexicontent&view=categories');
     }
     // Editing existing category: Check if user can edit existing (current) category
     if (!$isnew && !$canedit_cat) {
         $acc_msg = JText::_('FLEXI_NO_ACCESS_EDIT') . "<br/>" . JText::_('FLEXI_CANNOT_EDIT_CATEGORY_REASON');
         JError::raiseWarning(403, $acc_msg);
         $app->redirect('index.php?option=com_flexicontent&view=categories');
     }
     // **************************************************
     // Include needed files and add needed js / css files
     // **************************************************
     // Add css to document
     $document->addStyleSheetVersion(JURI::base(true) . '/components/com_flexicontent/assets/css/flexicontentbackend.css', FLEXI_VERSION);
     $document->addStyleSheetVersion(JURI::base(true) . '/components/com_flexicontent/assets/css/j3x.css', FLEXI_VERSION);
     // Add JS frameworks
     flexicontent_html::loadFramework('select2');
     // Add js function to overload the joomla submitform validation
     JHTML::_('behavior.formvalidation');
     // load default validation JS to make sure it is overriden
     $document->addScriptVersion(JURI::root(true) . '/components/com_flexicontent/assets/js/admin.js', FLEXI_VERSION);
     $document->addScriptVersion(JURI::root(true) . '/components/com_flexicontent/assets/js/validate.js', FLEXI_VERSION);
     //Load pane behavior
     jimport('joomla.html.pane');
     // ********************
     // Initialise variables
     // ********************
     $editor_name = $user->getParam('editor', $app->getCfg('editor'));
     $editor = JFactory::getEditor($editor_name);
     $cparams = JComponentHelper::getParams('com_flexicontent');
     $categories = $globalcats;
     $bar = JToolBar::getInstance('toolbar');
     $tip_class = FLEXI_J30GE ? ' hasTooltip' : ' hasTip';
     // ******************
     // Create the toolbar
     // ******************
     // Create Toolbar title and add the preview button
     if (!$isnew) {
         JToolBarHelper::title(JText::_('FLEXI_EDIT_CATEGORY'), 'fc_categoryedit');
     } else {
         JToolBarHelper::title(JText::_('FLEXI_NEW_CATEGORY'), 'fc_categoryadd');
     }
     // Add apply and save buttons
     JToolBarHelper::apply('category.apply', 'FLEXI_APPLY');
     /*if ( !$isnew ) flexicontent_html::addToolBarButton(
     		'FLEXI_FAST_APPLY', $btn_name='apply_ajax', $full_js="Joomla.submitbutton('category.apply_ajax')", $msg_alert='', $msg_confirm='',
     		$btn_task='category.apply_ajax', $extra_js='', $btn_list=false, $btn_menu=true, $btn_confirm=false, $btn_class="", $btn_icon="icon-loop");*/
     JToolBarHelper::save('category.save');
     // Add a save and new button, if user can create inside at least one (com_content) category
     if ($cancreate_cat) {
         JToolBarHelper::save2new('category.save2new');
     }
     // Add a save as copy button, if editing an existing category (J2.5 only)
     if (!$isnew && $cancreate_cat) {
         JToolBarHelper::save2copy('category.save2copy');
     }
     // Add a cancel or close button
     if ($isnew) {
         JToolBarHelper::cancel('category.cancel');
     } else {
         JToolBarHelper::cancel('category.cancel', 'JTOOLBAR_CLOSE');
     }
     // ******************
     // Add preview button
     // ******************
     if (!$isnew) {
         JToolBarHelper::divider();
         $autologin = '';
         //$cparams->get('autoflogin', 1) ? '&fcu='.$user->username . '&fcp='.$user->password : '';
         $previewlink = JRoute::_(JURI::root() . FlexicontentHelperRoute::getCategoryRoute($categories[$cid]->slug)) . $autologin;
         // Add a preview button
         $bar->appendButton('Custom', '<a class="preview btn btn-small btn-info spaced-btn" href="' . $previewlink . '" target="_blank" ><span title="' . JText::_('Preview') . '" class="icon-screen"></span>' . JText::_('Preview') . '</a>', 'preview');
     }
     // ************************
     // Add modal layout editing
     // ************************
     if (!$isnew && $perms->CanTemplates) {
         $inheritcid_comp = $cparams->get('inheritcid', -1);
         $inheritcid = $catparams->get('inheritcid', '');
         $inherit_parent = $inheritcid === '-1' || $inheritcid === '' && $inheritcid_comp;
         if (!$inherit_parent || $row->parent_id === '1') {
             $row_clayout = $catparams->get('clayout', $cparams->get('clayout', 'blog'));
         } else {
             $row_clayout = $catparams->get('clayout', '');
             if (!$row_clayout) {
                 $_ancestors = $this->getModel()->getParentParams($row->id);
                 // This is ordered by level ASC
                 $row_clayout = $cparams->get('clayout', 'blog');
                 $cats_params = array();
                 foreach ($_ancestors as $_cid => $_cat) {
                     $cats_params = new JRegistry($_cat->params);
                     $row_clayout = $cats_params->get('clayout', '') ? $cats_params->get('clayout', '') : $row_clayout;
                 }
             }
         }
         flexicontent_html::addToolBarButton('FLEXI_EDIT_LAYOUT', $btn_name = 'apply_ajax', $full_js = "var url = jQuery(this).attr('data-href'); fc_showDialog(url, 'fc_modal_popup_container'); return false;", $msg_alert = '', $msg_confirm = '', $btn_task = 'items.apply_ajax', $extra_js = '', $btn_list = false, $btn_menu = true, $btn_confirm = false, $btn_class = "btn-info" . $tip_class, $btn_icon = "icon-pencil", 'data-placement="bottom" data-href="index.php?option=com_flexicontent&amp;view=template&amp;type=category&amp;tmpl=component&amp;ismodal=1&amp;folder=' . $row_clayout . '" title="Edit the display layout of this category. <br/><br/>Note: this layout maybe assigned to other categories, thus changing it will effect them too"');
     }
     // *******************************************
     // Prepare data to pass to the form's template
     // *******************************************
     if (!FLEXI_J16GE) {
         //clean data
         JFilterOutput::objectHTMLSafe($row, ENT_QUOTES, 'description');
         // Create the form
         $form = new JParameter($row->params, JPATH_COMPONENT . DS . 'models' . DS . 'category.xml');
         //$form->loadINI($row->attribs);
         //echo "<pre>"; print_r($form->_xml['templates']->_children[0]);  echo "<pre>"; print_r($form->_xml['templates']->param[0]); exit;
         foreach ($form->_xml['templates']->_children as $i => $child) {
             if (isset($child->_attributes['enableparam']) && !$cparams->get($child->_attributes['enableparam'])) {
                 unset($form->_xml['templates']->_children[$i]);
                 unset($form->_xml['templates']->param[$i]);
             }
         }
         foreach ($form->_xml['special']->_children as $i => $child) {
             if (isset($child->_attributes['enableparam']) && !$cparams->get($child->_attributes['enableparam'])) {
                 unset($form->_xml['special']->_children[$i]);
                 unset($form->_xml['special']->param[$i]);
             }
         }
     }
     // **********************************************************************************
     // Get Templates and apply Template Parameters values into the form fields structures
     // **********************************************************************************
     $themes = flexicontent_tmpl::getTemplates();
     $tmpls = $themes->category;
     foreach ($tmpls as $tmpl) {
         $jform = new JForm('com_flexicontent.template.category', array('control' => 'jform', 'load_data' => true));
         $jform->load($tmpl->params);
         $tmpl->params = $jform;
         // ... values applied at the template form file
     }
     //build selectlists
     $Lists = array();
     if (!FLEXI_J16GE) {
         $javascript = "onchange=\"javascript:if (document.forms[0].image.options[selectedIndex].value!='') {document.imagelib.src='../images/stories/' + document.forms[0].image.options[selectedIndex].value} else {document.imagelib.src='../images/blank.png'}\"";
         $Lists['imagelist'] = JHTML::_('list.images', 'image', $row->image, $javascript, '/images/stories/');
         $Lists['access'] = JHTML::_('list.accesslevel', $row);
         // build granular access list
         if (FLEXI_ACCESS) {
             $Lists['access'] = FAccess::TabGmaccess($row, 'category', 1, 1, 1, 1, 1, 1, 1, 1, 1);
         }
     }
     $check_published = false;
     $check_perms = true;
     $actions_allowed = array('core.create');
     $fieldname = FLEXI_J16GE ? 'jform[parent_id]' : 'parent_id';
     $Lists['parent_id'] = flexicontent_cats::buildcatselect($categories, $fieldname, $row->parent_id, $top = 1, 'class="use_select2_lib"', $check_published, $check_perms, $actions_allowed, $require_all = true, $skip_subtrees = array(), $disable_subtrees = array($row->id));
     $check_published = false;
     $check_perms = true;
     $actions_allowed = array('core.edit', 'core.edit.own');
     $fieldname = FLEXI_J16GE ? 'jform[copycid]' : 'copycid';
     $Lists['copycid'] = flexicontent_cats::buildcatselect($categories, $fieldname, '', $top = 2, 'class="use_select2_lib"', $check_published, $check_perms, $actions_allowed, $require_all = false);
     $custom_options[''] = 'FLEXI_USE_GLOBAL';
     $custom_options['0'] = 'FLEXI_COMPONENT_ONLY';
     $custom_options['-1'] = 'FLEXI_PARENT_CAT_MULTI_LEVEL';
     $check_published = false;
     $check_perms = true;
     $actions_allowed = array('core.edit', 'core.edit.own');
     $fieldname = FLEXI_J16GE ? 'jform[special][inheritcid]' : 'params[inheritcid]';
     $Lists['inheritcid'] = flexicontent_cats::buildcatselect($categories, $fieldname, $catparams->get('inheritcid', ''), $top = false, 'class="use_select2_lib"', $check_published, $check_perms, $actions_allowed, $require_all = false, $skip_subtrees = array(), $disable_subtrees = array(), $custom_options);
     // ************************
     // Assign variables to view
     // ************************
     $this->assignRef('document', $document);
     $this->assignRef('Lists', $Lists);
     $this->assignRef('row', $row);
     $this->assignRef('form', $form);
     $this->assignRef('perms', $perms);
     $this->assignRef('editor', $editor);
     $this->assignRef('tmpls', $tmpls);
     $this->assignRef('cparams', $cparams);
     parent::display($tpl);
 }
Esempio n. 7
0
    /**
     * Creates the item page
     *
     * @since 1.0
     */
    function display($tpl = null)
    {
        // ********************************
        // Initialize variables, flags, etc
        // ********************************
        global $globalcats;
        $categories = $globalcats;
        $app = JFactory::getApplication();
        $dispatcher = JDispatcher::getInstance();
        $document = JFactory::getDocument();
        $session = JFactory::getSession();
        $user = JFactory::getUser();
        $db = JFactory::getDBO();
        $option = JRequest::getVar('option');
        $nullDate = $db->getNullDate();
        // Get the COMPONENT only parameters
        $params = clone JComponentHelper::getParams('com_flexicontent');
        if (!FLEXI_J16GE) {
            jimport('joomla.html.pane');
            $pane = JPane::getInstance('sliders');
            $editor = JFactory::getEditor();
        }
        // Some flags
        $enable_translation_groups = $params->get("enable_translation_groups") && (FLEXI_J16GE || FLEXI_FISH);
        $print_logging_info = $params->get('print_logging_info');
        if ($print_logging_info) {
            global $fc_run_times;
        }
        // *****************
        // Load JS/CSS files
        // *****************
        FLEXI_J30GE ? JHtml::_('behavior.framework', true) : JHTML::_('behavior.mootools');
        flexicontent_html::loadFramework('jQuery');
        flexicontent_html::loadFramework('select2');
        $prettycheckable_added = flexicontent_html::loadFramework('prettyCheckable');
        // Load custom behaviours: form validation, popup tooltips
        //JHTML::_('behavior.formvalidation');
        JHTML::_('behavior.tooltip');
        // Add css to document
        $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/flexicontentbackend.css');
        if (FLEXI_J30GE) {
            $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/j3x.css');
        } else {
            if (FLEXI_J16GE) {
                $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/j25.css');
            } else {
                $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/j15.css');
            }
        }
        // Add js function to overload the joomla submitform
        $document->addScript(JURI::root() . 'components/com_flexicontent/assets/js/admin.js');
        $document->addScript(JURI::root() . 'components/com_flexicontent/assets/js/validate.js');
        // Add js function for custom code used by FLEXIcontent item form
        $document->addScript(JURI::root() . 'components/com_flexicontent/assets/js/itemscreen.js');
        // ***********************
        // Get data from the model
        // ***********************
        if ($print_logging_info) {
            $start_microtime = microtime(true);
        }
        $model = $this->getModel();
        $item = $this->get('Item');
        if (FLEXI_J16GE) {
            $form = $this->get('Form');
        }
        if ($print_logging_info) {
            $fc_run_times['get_item_data'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
        }
        // ***************************
        // Get Associated Translations
        // ***************************
        if ($enable_translation_groups) {
            $langAssocs = $this->get('LangAssocs');
        }
        if (FLEXI_FISH || FLEXI_J16GE) {
            $langs = FLEXIUtilities::getLanguages('code');
        }
        // Get item id and new flag
        $cid = $model->getId();
        $isnew = !$cid;
        // Create and set a unique item id for plugins that needed it
        JRequest::setVar('unique_tmp_itemid', $cid ? $cid : date('_Y_m_d_h_i_s_', time()) . uniqid(true));
        // Get number of subscribers
        $subscribers = $model->getSubscribersCount();
        // ******************
        // Version Panel data
        // ******************
        // Get / calculate some version related variables
        $versioncount = $model->getVersionCount();
        $versionsperpage = $params->get('versionsperpage', 10);
        $pagecount = (int) ceil($versioncount / $versionsperpage);
        // Data need by version panel: (a) current version page, (b) currently active version
        $current_page = 1;
        $k = 1;
        $allversions = $model->getVersionList();
        foreach ($allversions as $v) {
            if ($k > 1 && ($k - 1) % $versionsperpage == 0) {
                $current_page++;
            }
            if ($v->nr == $item->version) {
                break;
            }
            $k++;
        }
        // Finally fetch the version data for versions in current page
        $versions = $model->getVersionList(($current_page - 1) * $versionsperpage, $versionsperpage);
        // *****************
        // Type related data
        // *****************
        // Get available types and the currently selected/requested type
        $types = $model->getTypeslist();
        $typesselected = $model->getTypesselected();
        // Get and merge type parameters
        $tparams = $this->get('Typeparams');
        $tparams = FLEXI_J16GE ? new JRegistry($tparams) : new JParameter($tparams);
        $params->merge($tparams);
        // Apply type configuration if it type is set
        // Get user allowed permissions on the item ... to be used by the form rendering
        // Also hide parameters panel if user can not edit parameters
        $perms = $this->_getItemPerms($item, $typesselected);
        if (!$perms['canparams']) {
            $document->addStyleDeclaration((FLEXI_J16GE ? '#details-options' : '#det-pane') . '{display:none;}');
        }
        // ******************
        // Create the toolbar
        // ******************
        $toolbar = JToolBar::getInstance('toolbar');
        // SET toolbar title
        if ($cid) {
            JToolBarHelper::title(JText::_('FLEXI_EDIT_ITEM'), 'itemedit');
            // Editing existing item
        } else {
            JToolBarHelper::title(JText::_('FLEXI_NEW_ITEM'), 'itemadd');
            // Creating new item
        }
        // Add a preview button for LATEST version of the item
        if ($cid) {
            // Domain URL and autologin vars
            $server = JURI::getInstance()->toString(array('scheme', 'host', 'port'));
            $autologin = '';
            //$params->get('autoflogin', 1) ? '&fcu='.$user->username . '&fcp='.$user->password : '';
            // Check if we are in the backend, in the back end we need to set the application to the site app instead
            $isAdmin = JFactory::getApplication()->isAdmin();
            if ($isAdmin && FLEXI_J16GE) {
                JFactory::$application = JApplication::getInstance('site');
            }
            // Create the URL
            $item_url = JRoute::_(FlexicontentHelperRoute::getItemRoute($item->id . ':' . $item->alias, $categories[$item->catid]->slug) . $autologin);
            // Check if we are in the backend again
            // In backend we need to remove administrator from URL as it is added even though we've set the application to the site app
            if ($isAdmin) {
                if (FLEXI_J16GE) {
                    $admin_folder = str_replace(JURI::root(true), '', JURI::base(true));
                    $item_url = str_replace($admin_folder, '', $item_url);
                    // Restore application
                    JFactory::$application = JApplication::getInstance('administrator');
                } else {
                    $item_url = JURI::root(true) . '/' . $item_url;
                }
            }
            $previewlink = $item_url . (strstr($item_url, '?') ? '&' : '?') . 'preview=1';
            //$previewlink     = str_replace('&amp;', '&', $previewlink);
            //$previewlink = JRoute::_(JURI::root() . FlexicontentHelperRoute::getItemRoute($item->id.':'.$item->alias, $categories[$item->catid]->slug)) .$autologin;
            if (!$params->get('use_versioning', 1) || $item->version == $item->current_version && $item->version == $item->last_version) {
                $toolbar->appendButton('Custom', '<a class="preview btn btn-small" href="' . $previewlink . '" target="_blank"><span title="' . JText::_('Preview') . '" class="icon-32-preview"></span>' . JText::_('Preview') . '</a>', 'preview');
            } else {
                // Add a preview button for (currently) LOADED version of the item
                $previewlink_loaded_ver = $previewlink . '&version=' . $item->version;
                $toolbar->appendButton('Custom', '<a class="preview btn btn-small" href="' . $previewlink_loaded_ver . '" target="_blank"><span title="' . JText::_('Preview') . '" class="icon-32-preview"></span>' . JText::_('FLEXI_PREVIEW_FORM_LOADED_VERSION') . ' [' . $item->version . ']</a>', 'preview');
                // Add a preview button for currently ACTIVE version of the item
                $previewlink_active_ver = $previewlink . '&version=' . $item->current_version;
                $toolbar->appendButton('Custom', '<a class="preview btn btn-small" href="' . $previewlink_active_ver . '" target="_blank"><span title="' . JText::_('Preview') . '" class="icon-32-preview"></span>' . JText::_('FLEXI_PREVIEW_FRONTEND_ACTIVE_VERSION') . ' [' . $item->current_version . ']</a>', 'preview');
                // Add a preview button for currently LATEST version of the item
                $previewlink_last_ver = $previewlink;
                //'&version='.$item->last_version;
                $toolbar->appendButton('Custom', '<a class="preview btn btn-small" href="' . $previewlink_last_ver . '" target="_blank"><span title="' . JText::_('Preview') . '" class="icon-32-preview"></span>' . JText::_('FLEXI_PREVIEW_LATEST_SAVED_VERSION') . ' [' . $item->last_version . ']</a>', 'preview');
            }
            JToolBarHelper::spacer();
            JToolBarHelper::divider();
            JToolBarHelper::spacer();
        }
        // Common Buttons
        if (FLEXI_J16GE) {
            JToolBarHelper::apply('items.apply');
            if (!$isnew || $item->version) {
                JToolBarHelper::save('items.save');
            }
            if (!$isnew || $item->version) {
                JToolBarHelper::custom('items.saveandnew', 'savenew.png', 'savenew.png', 'FLEXI_SAVE_AND_NEW', false);
            }
            JToolBarHelper::cancel('items.cancel');
        } else {
            JToolBarHelper::apply();
            if (!$isnew || $item->version) {
                JToolBarHelper::save();
            }
            if (!$isnew || $item->version) {
                JToolBarHelper::custom('saveandnew', 'savenew.png', 'savenew.png', 'FLEXI_SAVE_AND_NEW', false);
            }
            JToolBarHelper::cancel();
        }
        // Check if saving an item that translates an original content in site's default language
        $is_content_default_lang = substr(flexicontent_html::getSiteDefaultLang(), 0, 2) == substr($item->language, 0, 2);
        $modify_untraslatable_values = $enable_translation_groups && !$is_content_default_lang && $item->lang_parent_id && $item->lang_parent_id != $item->id;
        // *****************************************************************************
        // Get (CORE & CUSTOM) fields and their VERSIONED values and then
        // (a) Apply Content Type Customization to CORE fields (label, description, etc)
        // (b) Create the edit html of the CUSTOM fields by triggering 'onDisplayField'
        // *****************************************************************************
        if ($print_logging_info) {
            $start_microtime = microtime(true);
        }
        $fields = $this->get('Extrafields');
        if ($print_logging_info) {
            $fc_run_times['get_field_vals'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
        }
        if ($print_logging_info) {
            $start_microtime = microtime(true);
        }
        foreach ($fields as $field) {
            // a. Apply CONTENT TYPE customizations to CORE FIELDS, e.g a type specific label & description
            // NOTE: the field parameters are already created so there is not need to call this for CUSTOM fields, which do not have CONTENT TYPE customizations
            if ($field->iscore) {
                FlexicontentFields::loadFieldConfig($field, $item);
            }
            // b. Create field 's editing HTML (the form field)
            // NOTE: this is DONE only for CUSTOM fields, since form field html is created by the form for all CORE fields, EXCEPTION is the 'text' field (see bellow)
            if (!$field->iscore) {
                if (FLEXI_J16GE) {
                    $is_editable = !$field->valueseditable || $user->authorise('flexicontent.editfieldvalues', 'com_flexicontent.field.' . $field->id);
                } else {
                    if (FLEXI_ACCESS && $user->gid < 25) {
                        $is_editable = !$field->valueseditable || FAccess::checkAllContentAccess('com_content', 'submit', 'users', $user->gmid, 'field', $field->id);
                    } else {
                        $is_editable = 1;
                    }
                }
                if (!$is_editable) {
                    $field->html = '<div class="fc-mssg fc-warning">' . JText::_('FLEXI_NO_ACCESS_LEVEL_TO_EDIT_FIELD') . '</div>';
                } else {
                    if ($modify_untraslatable_values && $field->untranslatable) {
                        $field->html = '<div class="fc-mssg fc-note">' . JText::_('FLEXI_FIELD_VALUE_IS_UNTRANSLATABLE') . '</div>';
                    } else {
                        FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayField', array(&$field, &$item));
                    }
                }
            }
            // c. Create main text field, via calling the display function of the textarea field (will also check for tabs)
            if ($field->field_type == 'maintext') {
                if (isset($item->item_translations)) {
                    $shortcode = substr($item->language, 0, 2);
                    foreach ($item->item_translations as $lang_id => $t) {
                        if ($shortcode == $t->shortcode) {
                            continue;
                        }
                        $field->name = array('jfdata', $t->shortcode, 'text');
                        $field->value[0] = html_entity_decode($t->fields->text->value, ENT_QUOTES, 'UTF-8');
                        FLEXIUtilities::call_FC_Field_Func('textarea', 'onDisplayField', array(&$field, &$item));
                        $t->fields->text->tab_labels = $field->tab_labels;
                        $t->fields->text->html = $field->html;
                        unset($field->tab_labels);
                        unset($field->html);
                    }
                }
                $field->name = 'text';
                // NOTE: We use the text created by the model and not the text retrieved by the CORE plugin code, which maybe overwritten with JoomFish/Falang data
                $field->value[0] = $item->text;
                // do not decode special characters this was handled during saving !
                // Render the field's (form) HTML
                FLEXIUtilities::call_FC_Field_Func('textarea', 'onDisplayField', array(&$field, &$item));
            }
        }
        if ($print_logging_info) {
            $fc_run_times['render_field_html'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
        }
        // *************************
        // Get tags used by the item
        // *************************
        $usedtagsIds = $this->get('UsedtagsIds');
        // NOTE: This will normally return the already set versioned value of tags ($item->tags)
        $usedtags = $model->getUsedtagsData($usedtagsIds);
        // *******************************
        // Get categories used by the item
        // *******************************
        if ($isnew) {
            // Case for preselected main category for new items
            $maincat = $item->catid ? $item->catid : JRequest::getInt('maincat', 0);
            if (!$maincat) {
                $maincat = $app->getUserStateFromRequest($option . '.items.filter_cats', 'filter_cats', '', 'int');
            }
            if ($maincat) {
                $selectedcats = array($maincat);
                $item->catid = $maincat;
            } else {
                $selectedcats = array();
            }
            if ($tparams->get('cid_default')) {
                $selectedcats = $tparams->get('cid_default');
            }
            if ($tparams->get('catid_default')) {
                $item->catid = $tparams->get('catid_default');
            }
        } else {
            // NOTE: This will normally return the already set versioned value of categories ($item->categories)
            $selectedcats = $this->get('Catsselected');
        }
        //$selectedcats 	= $isnew ? array() : $fields['categories']->value;
        //echo "<br/>row->tags: "; print_r($item->tags);
        //echo "<br/>usedtagsIds: "; print_r($usedtagsIds);
        //echo "<br/>usedtags (data): "; print_r($usedtags);
        //echo "<br/>row->categories: "; print_r($item->categories);
        //echo "<br/>selectedcats: "; print_r($selectedcats);
        // *********************************************************************************************
        // Build select lists for the form field. Only few of them are used in J1.6+, since we will use:
        // (a) form XML file to declare them and then (b) getInput() method form field to create them
        // *********************************************************************************************
        // First clean form data, we do this after creating the description field which may contain HTML
        JFilterOutput::objectHTMLSafe($item, ENT_QUOTES);
        $lists = array();
        // build granular access list
        if (!FLEXI_J16GE) {
            if (FLEXI_ACCESS) {
                if (isset($user->level)) {
                    $lists['access'] = FAccess::TabGmaccess($item, 'item', 1, 0, 0, 1, 0, 1, 0, 1, 1);
                } else {
                    $lists['access'] = JText::_('Your profile has been changed, please logout to access to the permissions');
                }
            } else {
                $lists['access'] = JHTML::_('list.accesslevel', $item);
                // created but not used in J1.5 backend form
            }
        }
        // build state list
        $_arc_ = FLEXI_J16GE ? 2 : -1;
        $non_publishers_stategrp = $perms['isSuperAdmin'] || $item->state == -3 || $item->state == -4;
        $special_privelege_stategrp = $item->state == $_arc_ || $perms['canarchive'] || ($item->state == -2 || $perms['candelete']);
        $state = array();
        // Using <select> groups
        if ($non_publishers_stategrp || $special_privelege_stategrp) {
            $state[] = JHTML::_('select.optgroup', JText::_('FLEXI_PUBLISHERS_WORKFLOW_STATES'));
        }
        $state[] = JHTML::_('select.option', 1, JText::_('FLEXI_PUBLISHED'));
        $state[] = JHTML::_('select.option', 0, JText::_('FLEXI_UNPUBLISHED'));
        $state[] = JHTML::_('select.option', -5, JText::_('FLEXI_IN_PROGRESS'));
        // States reserved for workflow
        if ($non_publishers_stategrp) {
            $state[] = JHTML::_('select.optgroup', '');
            $state[] = JHTML::_('select.optgroup', JText::_('FLEXI_NON_PUBLISHERS_WORKFLOW_STATES'));
        }
        if ($item->state == -3 || $perms['isSuperAdmin']) {
            $state[] = JHTML::_('select.option', -3, JText::_('FLEXI_PENDING'));
        }
        if ($item->state == -4 || $perms['isSuperAdmin']) {
            $state[] = JHTML::_('select.option', -4, JText::_('FLEXI_TO_WRITE'));
        }
        // Special access states
        if ($special_privelege_stategrp) {
            $state[] = JHTML::_('select.optgroup', '');
            $state[] = JHTML::_('select.optgroup', JText::_('FLEXI_SPECIAL_ACTION_STATES'));
        }
        if ($item->state == $_arc_ || $perms['canarchive']) {
            $state[] = JHTML::_('select.option', $_arc_, JText::_('FLEXI_ARCHIVED'));
        }
        if ($item->state == -2 || $perms['candelete']) {
            $state[] = JHTML::_('select.option', -2, JText::_('FLEXI_TRASHED'));
        }
        // Close last <select> group
        if ($non_publishers_stategrp || $special_privelege_stategrp) {
            $state[] = JHTML::_('select.optgroup', '');
        }
        $fieldname = FLEXI_J16GE ? 'jform[state]' : 'state';
        $elementid = FLEXI_J16GE ? 'jform_state' : 'state';
        $class = 'use_select2_lib';
        $attribs = 'class="' . $class . '"';
        $lists['state'] = JHTML::_('select.genericlist', $state, $fieldname, $attribs, 'value', 'text', $item->state, $elementid);
        if (!FLEXI_J16GE) {
            $lists['state'] = str_replace('<optgroup label="">', '</optgroup>', $lists['state']);
        }
        // *** BOF: J2.5 SPECIFIC SELECT LISTS
        if (FLEXI_J16GE) {
            // build featured flag
            $fieldname = 'jform[featured]';
            $elementid = 'jform_featured';
            /*
            $options = array();
            $options[] = JHTML::_('select.option',  0, JText::_( 'FLEXI_NO' ) );
            $options[] = JHTML::_('select.option',  1, JText::_( 'FLEXI_YES' ) );
            $attribs = FLEXI_J16GE ? ' style ="float:none!important;" '  :  '';   // this is not right for J1.5' style ="float:left!important;" ';
            $lists['featured'] = JHTML::_('select.radiolist', $options, $fieldname, $attribs, 'value', 'text', $item->featured, $elementid);
            */
            $classes = !$prettycheckable_added ? '' : ' use_prettycheckable ';
            $attribs = ' class="' . $classes . '" ';
            $i = 1;
            $options = array(0 => JText::_('FLEXI_NO'), 1 => JText::_('FLEXI_YES'));
            $lists['featured'] = '';
            foreach ($options as $option_id => $option_label) {
                $checked = $option_id == $item->featured ? ' checked="checked"' : '';
                $elementid_no = $elementid . '_' . $i;
                if (!$prettycheckable_added) {
                    $lists['featured'] .= '<label class="fccheckradio_lbl" for="' . $elementid_no . '">';
                }
                $extra_params = !$prettycheckable_added ? '' : ' data-label="' . JText::_($option_label) . '" data-labelPosition="right" data-customClass="fcradiocheck"';
                $lists['featured'] .= ' <input type="radio" id="' . $elementid_no . '" element_group_id="' . $elementid . '" name="' . $fieldname . '" ' . $attribs . ' value="' . $option_id . '" ' . $checked . $extra_params . ' />';
                if (!$prettycheckable_added) {
                    $lists['featured'] .= '&nbsp;' . JText::_($option_label) . '</label>';
                }
                $i++;
            }
        }
        // *** EOF: J1.5 SPECIFIC SELECT LISTS
        // build version approval list
        $fieldname = FLEXI_J16GE ? 'jform[vstate]' : 'vstate';
        $elementid = FLEXI_J16GE ? 'jform_vstate' : 'vstate';
        /*
        $options = array();
        $options[] = JHTML::_('select.option',  1, JText::_( 'FLEXI_NO' ) );
        $options[] = JHTML::_('select.option',  2, JText::_( 'FLEXI_YES' ) );
        $attribs = FLEXI_J16GE ? ' style ="float:left!important;" '  :  '';   // this is not right for J1.5' style ="float:left!important;" ';
        $lists['vstate'] = JHTML::_('select.radiolist', $options, $fieldname, $attribs, 'value', 'text', 2, $elementid);
        */
        $classes = !$prettycheckable_added ? '' : ' use_prettycheckable ';
        $attribs = ' class="' . $classes . '" ';
        $i = 1;
        $options = array(1 => JText::_('FLEXI_NO'), 2 => JText::_('FLEXI_YES'));
        $lists['vstate'] = '';
        foreach ($options as $option_id => $option_label) {
            $checked = $option_id == 2 ? ' checked="checked"' : '';
            $elementid_no = $elementid . '_' . $i;
            if (!$prettycheckable_added) {
                $lists['vstate'] .= '<label class="fccheckradio_lbl" for="' . $elementid_no . '">';
            }
            $extra_params = !$prettycheckable_added ? '' : ' data-label="' . JText::_($option_label) . '" data-labelPosition="right" data-customClass="fcradiocheck"';
            $lists['vstate'] .= ' <input type="radio" id="' . $elementid_no . '" element_group_id="' . $elementid . '" name="' . $fieldname . '" ' . $attribs . ' value="' . $option_id . '" ' . $checked . $extra_params . ' />';
            if (!$prettycheckable_added) {
                $lists['vstate'] .= '&nbsp;' . JText::_($option_label) . '</label>';
            }
            $i++;
        }
        // build field for notifying subscribers
        if (!$subscribers) {
            $lists['notify'] = !$isnew ? JText::_('FLEXI_NO_SUBSCRIBERS_EXIST') : '';
        } else {
            // b. Check if notification emails to subscribers , were already sent during current session
            $subscribers_notified = $session->get('subscribers_notified', array(), 'flexicontent');
            if (!empty($subscribers_notified[$item->id])) {
                $lists['notify'] = JText::_('FLEXI_SUBSCRIBERS_ALREADY_NOTIFIED');
            } else {
                // build favs notify field
                $fieldname = FLEXI_J16GE ? 'jform[notify]' : 'notify';
                $elementid = FLEXI_J16GE ? 'jform_notify' : 'notify';
                /*
                $attribs = FLEXI_J16GE ? ' style ="float:none!important;" '  :  '';   // this is not right for J1.5' style ="float:left!important;" ';
                $lists['notify'] = '<input type="checkbox" name="jform[notify]" id="jform_notify" '.$attribs.' /> '. $lbltxt;
                */
                $classes = !$prettycheckable_added ? '' : ' use_prettycheckable ';
                $attribs = ' class="' . $classes . '" ';
                $lbltxt = $subscribers . ' ' . JText::_($subscribers > 1 ? 'FLEXI_SUBSCRIBERS' : 'FLEXI_SUBSCRIBER');
                if (!$prettycheckable_added) {
                    $lists['notify'] .= '<label class="fccheckradio_lbl" for="' . $elementid . '">';
                }
                $extra_params = !$prettycheckable_added ? '' : ' data-label="' . $lbltxt . '" data-labelPosition="right" data-customClass="fcradiocheck"';
                $lists['notify'] = ' <input type="checkbox" id="' . $elementid . '" element_group_id="' . $elementid . '" name="' . $fieldname . '" ' . $attribs . ' value="1" ' . $extra_params . ' checked="checked" />';
                if (!$prettycheckable_added) {
                    $lists['notify'] .= '&nbsp;' . $lbltxt . '</label>';
                }
            }
        }
        // Retrieve author configuration
        $db->setQuery('SELECT author_basicparams FROM #__flexicontent_authors_ext WHERE user_id = ' . $user->id);
        if ($authorparams = $db->loadResult()) {
            $authorparams = FLEXI_J16GE ? new JRegistry($authorparams) : new JParameter($authorparams);
        }
        // Get author's maximum allowed categories per item and set js limitation
        $max_cat_assign = !$authorparams ? 0 : intval($authorparams->get('max_cat_assign', 0));
        $document->addScriptDeclaration('
			max_cat_assign_fc = ' . $max_cat_assign . ';
			existing_cats_fc  = ["' . implode('","', $selectedcats) . '"];
			max_cat_overlimit_msg_fc = "' . JText::_('FLEXI_TOO_MANY_ITEM_CATEGORIES', true) . '";
		');
        // Creating categorories tree for item assignment, we use the 'create' privelege
        $actions_allowed = array('core.create');
        // Featured categories form field
        $featured_cats_parent = $params->get('featured_cats_parent', 0);
        $featured_cats = array();
        $enable_featured_cid_selector = $perms['multicat'] && $perms['canchange_featcat'];
        if ($featured_cats_parent) {
            $featured_tree = flexicontent_cats::getCategoriesTree($published_only = 1, $parent_id = $featured_cats_parent, $depth_limit = 0);
            $featured_sel = array();
            foreach ($selectedcats as $item_cat) {
                if (isset($featured_tree[$item_cat])) {
                    $featured_sel[] = $item_cat;
                }
            }
            $class = "use_select2_lib select2_list_selected";
            $attribs = 'class="' . $class . '" multiple="multiple" size="8"';
            $attribs .= $enable_featured_cid_selector ? '' : ' disabled="disabled"';
            $fieldname = FLEXI_J16GE ? 'jform[featured_cid][]' : 'featured_cid[]';
            $lists['featured_cid'] = ($enable_featured_cid_selector ? '' : '<label class="label" style="float:none; margin:0 6px 0 0 !important;">locked</label>') . flexicontent_cats::buildcatselect($featured_tree, $fieldname, $featured_sel, 3, $attribs, true, true, $actions_allowed);
        } else {
            // Do not display, if not configured or not allowed to the user
            $lists['featured_cid'] = false;
        }
        // Multi-category form field, for user allowed to use multiple categories
        $lists['cid'] = '';
        $enable_cid_selector = $perms['multicat'] && $perms['canchange_seccat'];
        if (1) {
            if ($tparams->get('cid_allowed_parent')) {
                $cid_tree = flexicontent_cats::getCategoriesTree($published_only = 1, $parent_id = $tparams->get('cid_allowed_parent'), $depth_limit = 0);
            } else {
                $cid_tree =& $categories;
            }
            // Get author's maximum allowed categories per item and set js limitation
            $max_cat_assign = !$authorparams ? 0 : intval($authorparams->get('max_cat_assign', 0));
            $document->addScriptDeclaration('
				max_cat_assign_fc = ' . $max_cat_assign . ';
				existing_cats_fc  = ["' . implode('","', $selectedcats) . '"];
				max_cat_overlimit_msg_fc = "' . JText::_('FLEXI_TOO_MANY_ITEM_CATEGORIES', true) . '";
			');
            $class = "mcat use_select2_lib select2_list_selected";
            $class .= $max_cat_assign ? " validate-fccats" : " validate";
            $attribs = 'class="' . $class . '" multiple="multiple" size="20"';
            $attribs .= $enable_cid_selector ? '' : ' disabled="disabled"';
            $fieldname = FLEXI_J16GE ? 'jform[cid][]' : 'cid[]';
            $skip_subtrees = $featured_cats_parent ? array($featured_cats_parent) : array();
            $lists['cid'] = ($enable_cid_selector ? '' : '<label class="label" style="float:none; margin:0 6px 0 0 !important;">locked</label>') . flexicontent_cats::buildcatselect($cid_tree, $fieldname, $selectedcats, false, $attribs, true, true, $actions_allowed, $require_all = true, $skip_subtrees, $disable_subtrees = array());
        } else {
            if (count($selectedcats) > 1) {
                foreach ($selectedcats as $catid) {
                    $cat_titles[$catid] = $globalcats[$catid]->title;
                }
                $lists['cid'] .= implode(', ', $cat_titles);
            } else {
                $lists['cid'] = false;
            }
        }
        // Main category form field
        $class = 'scat use_select2_lib';
        if ($perms['multicat']) {
            $class .= ' validate-catid';
        } else {
            $class .= ' required';
        }
        $attribs = 'class="' . $class . '"';
        $fieldname = FLEXI_J16GE ? 'jform[catid]' : 'catid';
        $enable_catid_selector = $isnew && !$tparams->get('catid_default') || !$isnew && empty($item->catid) || $perms['canchange_cat'];
        if ($tparams->get('catid_allowed_parent')) {
            $catid_tree = flexicontent_cats::getCategoriesTree($published_only = 1, $parent_id = $tparams->get('catid_allowed_parent'), $depth_limit = 0);
        } else {
            $catid_tree =& $categories;
        }
        $lists['catid'] = false;
        if (!empty($catid_tree)) {
            $disabled = $enable_catid_selector ? '' : ' disabled="disabled"';
            $attribs .= $disabled;
            $lists['catid'] = ($enable_catid_selector ? '' : '<label class="label" style="float:none; margin:0 6px 0 0 !important;">locked</label>') . flexicontent_cats::buildcatselect($catid_tree, $fieldname, $item->catid, 2, $attribs, true, true, $actions_allowed);
        } else {
            if (!$isnew && $item->catid) {
                $lists['catid'] = $globalcats[$item->catid]->title;
            }
        }
        //buid types selectlist
        $class = 'required use_select2_lib';
        $attribs = 'class="' . $class . '"';
        $fieldname = FLEXI_J16GE ? 'jform[type_id]' : 'type_id';
        $elementid = FLEXI_J16GE ? 'jform_type_id' : 'type_id';
        $lists['type'] = flexicontent_html::buildtypesselect($types, $fieldname, $typesselected->id, 1, $attribs, $elementid, $check_perms = true);
        //build languages list
        $allowed_langs = !$authorparams ? null : $authorparams->get('langs_allowed', null);
        $allowed_langs = !$allowed_langs ? null : FLEXIUtilities::paramToArray($allowed_langs);
        if (!$isnew && $allowed_langs) {
            $allowed_langs[] = $item->language;
        }
        // We will not use the default getInput() function of J1.6+ since we want to create a radio selection field with flags
        // we could also create a new class and override getInput() method but maybe this is an overkill, we may do it in the future
        $language_fieldname = FLEXI_J16GE ? 'jform[language]' : 'language';
        if (FLEXI_FISH || FLEXI_J16GE) {
            $lists['languages'] = flexicontent_html::buildlanguageslist($language_fieldname, '', $item->language, 3, $allowed_langs);
        }
        // Label for current item state: published, unpublished, archived etc
        switch ($item->state) {
            case 0:
                $published = JText::_('FLEXI_UNPUBLISHED');
                break;
            case 1:
                $published = JText::_('FLEXI_PUBLISHED');
                break;
            case -1:
                $published = JText::_('FLEXI_ARCHIVED');
                break;
            case -3:
                $published = JText::_('FLEXI_PENDING');
                break;
            case -5:
                $published = JText::_('FLEXI_IN_PROGRESS');
                break;
            case -4:
            default:
                $published = JText::_('FLEXI_TO_WRITE');
                break;
        }
        // **************************************************************
        // Handle Item Parameters Creation and Load their values for J1.5
        // In J1.6+ we declare them in the item form XML file
        // **************************************************************
        if (!FLEXI_J16GE) {
            // Create the form parameters object
            if (FLEXI_ACCESS) {
                $formparams = new JParameter('', JPATH_COMPONENT . DS . 'models' . DS . 'item2.xml');
            } else {
                $formparams = new JParameter('', JPATH_COMPONENT . DS . 'models' . DS . 'item.xml');
            }
            // Details Group
            $active = intval($item->created_by) ? intval($item->created_by) : $user->get('id');
            if (!FLEXI_ACCESS) {
                $formparams->set('access', $item->access);
            }
            $formparams->set('created_by', $active);
            $formparams->set('created_by_alias', $item->created_by_alias);
            $formparams->set('created', JHTML::_('date', $item->created, '%Y-%m-%d %H:%M:%S'));
            $formparams->set('publish_up', JHTML::_('date', $item->publish_up, '%Y-%m-%d %H:%M:%S'));
            if (JHTML::_('date', $item->publish_down, '%Y') <= 1969 || $item->publish_down == $db->getNullDate() || empty($item->publish_down)) {
                $formparams->set('publish_down', JText::_('FLEXI_NEVER'));
            } else {
                $formparams->set('publish_down', JHTML::_('date', $item->publish_down, '%Y-%m-%d %H:%M:%S'));
            }
            // Advanced Group
            $formparams->loadINI($item->attribs);
            //echo "<pre>"; print_r($formparams->_xml['themes']->_children[0]);  echo "<pre>"; print_r($formparams->_xml['themes']->param[0]); exit;
            foreach ($formparams->_xml['themes']->_children as $i => $child) {
                if (isset($child->_attributes['enableparam']) && !$params->get($child->_attributes['enableparam'])) {
                    unset($formparams->_xml['themes']->_children[$i]);
                    unset($formparams->_xml['themes']->param[$i]);
                }
            }
            // Metadata Group
            $formparams->set('description', $item->metadesc);
            $formparams->set('keywords', $item->metakey);
            $formparams->loadINI($item->metadata);
        } else {
            if (JHTML::_('date', $item->publish_down, 'Y') <= 1969 || $item->publish_down == $db->getNullDate() || empty($item->publish_down)) {
                $form->setValue('publish_down', null, JText::_('FLEXI_NEVER'));
            }
        }
        // ****************************
        // Handle Template related work
        // ****************************
        // (a) Get the templates structures used to create form fields for template parameters
        $themes = flexicontent_tmpl::getTemplates();
        $tmpls_all = $themes->items;
        // (b) Get Content Type allowed templates
        $allowed_tmpls = $tparams->get('allowed_ilayouts');
        $type_default_layout = $tparams->get('ilayout', 'default');
        if (empty($allowed_tmpls)) {
            $allowed_tmpls = array();
        } else {
            if (!is_array($allowed_tmpls)) {
                $allowed_tmpls = !FLEXI_J16GE ? array($allowed_tmpls) : explode("|", $allowed_tmpls);
            }
        }
        // (c) Add default layout, unless all templates allowed (=array is empty)
        if (count($allowed_tmpls) && !in_array($type_default_layout, $allowed_tmpls)) {
            $allowed_tmpls[] = $type_default_layout;
        }
        // (d) Create array of template data according to the allowed templates for current content type
        if (count($allowed_tmpls)) {
            foreach ($tmpls_all as $tmpl) {
                if (in_array($tmpl->name, $allowed_tmpls)) {
                    $tmpls[] = $tmpl;
                }
            }
        } else {
            $tmpls = $tmpls_all;
        }
        // (e) Apply Template Parameters values into the form fields structures
        foreach ($tmpls as $tmpl) {
            if (FLEXI_J16GE) {
                $jform = new JForm('com_flexicontent.template.item', array('control' => 'jform', 'load_data' => true));
                $jform->load($tmpl->params);
                $tmpl->params = $jform;
                foreach ($tmpl->params->getGroup('attribs') as $field) {
                    $fieldname = $field->__get('fieldname');
                    $value = $item->itemparams->get($fieldname);
                    if (strlen($value)) {
                        $tmpl->params->setValue($fieldname, 'attribs', $value);
                    }
                }
            } else {
                $tmpl->params->loadINI($item->attribs);
            }
        }
        // ******************************
        // Assign data to VIEW's template
        // ******************************
        $this->assignRef('document', $document);
        $this->assignRef('lists', $lists);
        $this->assignRef('row', $item);
        if (FLEXI_J16GE) {
            $this->assignRef('form', $form);
        } else {
            $this->assignRef('editor', $editor);
            $this->assignRef('pane', $pane);
            $this->assignRef('formparams', $formparams);
        }
        if ($enable_translation_groups) {
            $this->assignRef('lang_assocs', $langAssocs);
        }
        if (FLEXI_FISH || FLEXI_J16GE) {
            $this->assignRef('langs', $langs);
        }
        $this->assignRef('typesselected', $typesselected);
        $this->assignRef('published', $published);
        $this->assignRef('nullDate', $nullDate);
        $this->assignRef('subscribers', $subscribers);
        $this->assignRef('fields', $fields);
        $this->assignRef('versions', $versions);
        $this->assignRef('pagecount', $pagecount);
        $this->assignRef('params', $params);
        $this->assignRef('tparams', $tparams);
        $this->assignRef('tmpls', $tmpls);
        $this->assignRef('usedtags', $usedtags);
        $this->assignRef('perms', $perms);
        $this->assignRef('current_page', $current_page);
        if ($print_logging_info) {
            $start_microtime = microtime(true);
        }
        parent::display($tpl);
        if ($print_logging_info) {
            $fc_run_times['form_rendering'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
        }
    }
Esempio n. 8
0
    /**
     * Creates the HTML of various form fields used in the item edit form
     *
     * @since 1.0
     */
    function _buildEditLists(&$perms, &$params, &$authorparams, &$typesselected, &$tparams)
    {
        $db = JFactory::getDBO();
        $user = JFactory::getUser();
        // get current user
        $item = $this->get('Item');
        // get the item from the model
        $document = JFactory::getDocument();
        $session = JFactory::getSession();
        global $globalcats;
        $categories = $globalcats;
        // get the categories tree
        $types = $this->get('Typeslist');
        $subscribers = $this->get('SubscribersCount');
        //$typesselected = new stdClass();
        //$typesselected->id = 0;
        $isnew = !$item->id;
        // *******************************
        // Get categories used by the item
        // *******************************
        if ($isnew) {
            // Case for preselected main category for new items
            $maincat = $item->catid ? $item->catid : JRequest::getInt('maincat', 0);
            if ($maincat) {
                $selectedcats = array($maincat);
                $item->catid = $maincat;
            } else {
                $selectedcats = array();
            }
            if ($tparams->get('cid_default')) {
                $selectedcats = $tparams->get('cid_default');
            }
            if ($tparams->get('catid_default')) {
                $item->catid = $tparams->get('catid_default');
            }
        } else {
            // NOTE: This will normally return the already set versioned value of categories ($item->categories)
            $selectedcats = $this->get('Catsselected');
        }
        // *********************************************************************************************
        // Build select lists for the form field. Only few of them are used in J1.6+, since we will use:
        // (a) form XML file to declare them and then (b) getInput() method form field to create them
        // *********************************************************************************************
        // First clean form data, we do this after creating the description field which may contain HTML
        JFilterOutput::objectHTMLSafe($item, ENT_QUOTES);
        flexicontent_html::loadFramework('select2');
        $prettycheckable_added = flexicontent_html::loadFramework('prettyCheckable');
        $lists = array();
        // build granular access list
        if (!FLEXI_J16GE) {
            if (FLEXI_ACCESS) {
                if (isset($user->level)) {
                    $lists['access'] = FAccess::TabGmaccess($item, 'item', 1, 0, 0, 1, 0, 1, 0, 1, 1);
                } else {
                    $lists['access'] = JText::_('Your profile has been changed, please logout to access to the permissions');
                }
            } else {
                $lists['access'] = JHTML::_('list.accesslevel', $item);
                // created but not used in J1.5 backend form
            }
        }
        // build state list
        $_arc_ = FLEXI_J16GE ? 2 : -1;
        $non_publishers_stategrp = $perms['isSuperAdmin'] || $item->state == -3 || $item->state == -4;
        $special_privelege_stategrp = $item->state == $_arc_ || $perms['canarchive'] || ($item->state == -2 || $perms['candelete']);
        $state = array();
        // Using <select> groups
        if ($non_publishers_stategrp || $special_privelege_stategrp) {
            $state[] = JHTML::_('select.optgroup', JText::_('FLEXI_PUBLISHERS_WORKFLOW_STATES'));
        }
        $state[] = JHTML::_('select.option', 1, JText::_('FLEXI_PUBLISHED'));
        $state[] = JHTML::_('select.option', 0, JText::_('FLEXI_UNPUBLISHED'));
        $state[] = JHTML::_('select.option', -5, JText::_('FLEXI_IN_PROGRESS'));
        // States reserved for workflow
        if ($non_publishers_stategrp) {
            $state[] = JHTML::_('select.optgroup', '');
            $state[] = JHTML::_('select.optgroup', JText::_('FLEXI_NON_PUBLISHERS_WORKFLOW_STATES'));
        }
        if ($item->state == -3 || $perms['isSuperAdmin']) {
            $state[] = JHTML::_('select.option', -3, JText::_('FLEXI_PENDING'));
        }
        if ($item->state == -4 || $perms['isSuperAdmin']) {
            $state[] = JHTML::_('select.option', -4, JText::_('FLEXI_TO_WRITE'));
        }
        // Special access states
        if ($special_privelege_stategrp) {
            $state[] = JHTML::_('select.optgroup', '');
            $state[] = JHTML::_('select.optgroup', JText::_('FLEXI_SPECIAL_ACTION_STATES'));
        }
        if ($item->state == $_arc_ || $perms['canarchive']) {
            $state[] = JHTML::_('select.option', $_arc_, JText::_('FLEXI_ARCHIVED'));
        }
        if ($item->state == -2 || $perms['candelete']) {
            $state[] = JHTML::_('select.option', -2, JText::_('FLEXI_TRASHED'));
        }
        // Close last <select> group
        if ($non_publishers_stategrp || $special_privelege_stategrp) {
            $state[] = JHTML::_('select.optgroup', '');
        }
        $fieldname = FLEXI_J16GE ? 'jform[state]' : 'state';
        $elementid = FLEXI_J16GE ? 'jform_state' : 'state';
        $class = 'use_select2_lib';
        $attribs = 'class="' . $class . '"';
        $lists['state'] = JHTML::_('select.genericlist', $state, $fieldname, $attribs, 'value', 'text', $item->state, $elementid);
        if (!FLEXI_J16GE) {
            $lists['state'] = str_replace('<optgroup label="">', '</optgroup>', $lists['state']);
        }
        // *** BOF: J2.5 SPECIFIC SELECT LISTS
        if (FLEXI_J16GE) {
        }
        // *** EOF: J1.5 SPECIFIC SELECT LISTS
        // build version approval list
        $fieldname = FLEXI_J16GE ? 'jform[vstate]' : 'vstate';
        $elementid = FLEXI_J16GE ? 'jform_vstate' : 'vstate';
        /*
        $options = array();
        $options[] = JHTML::_('select.option',  1, JText::_( 'FLEXI_NO' ) );
        $options[] = JHTML::_('select.option',  2, JText::_( 'FLEXI_YES' ) );
        $attribs = FLEXI_J16GE ? ' style ="float:left!important;" '  :  '';   // this is not right for J1.5' style ="float:left!important;" ';
        $lists['vstate'] = JHTML::_('select.radiolist', $options, $fieldname, $attribs, 'value', 'text', 2, $elementid);
        */
        $classes = !$prettycheckable_added ? '' : ' use_prettycheckable ';
        $attribs = ' class="' . $classes . '" ';
        $i = 1;
        $options = array(1 => JText::_('FLEXI_NO'), 2 => JText::_('FLEXI_YES'));
        $lists['vstate'] = '';
        foreach ($options as $option_id => $option_label) {
            $checked = $option_id == 2 ? ' checked="checked"' : '';
            $elementid_no = $elementid . '_' . $i;
            if (!$prettycheckable_added) {
                $lists['vstate'] .= '<label class="fccheckradio_lbl" for="' . $elementid_no . '">';
            }
            $extra_params = !$prettycheckable_added ? '' : ' data-label="' . JText::_($option_label) . '" data-labelPosition="right" data-customClass="fcradiocheck"';
            $lists['vstate'] .= ' <input type="radio" id="' . $elementid_no . '" element_group_id="' . $elementid . '" name="' . $fieldname . '" ' . $attribs . ' value="' . $option_id . '" ' . $checked . $extra_params . ' />';
            if (!$prettycheckable_added) {
                $lists['vstate'] .= '&nbsp;' . JText::_($option_label) . '</label>';
            }
            $i++;
        }
        // build field for notifying subscribers
        if (!$subscribers) {
            $lists['notify'] = !$isnew ? JText::_('FLEXI_NO_SUBSCRIBERS_EXIST') : '';
        } else {
            // b. Check if notification emails to subscribers , were already sent during current session
            $subscribers_notified = $session->get('subscribers_notified', array(), 'flexicontent');
            if (!empty($subscribers_notified[$item->id])) {
                $lists['notify'] = JText::_('FLEXI_SUBSCRIBERS_ALREADY_NOTIFIED');
            } else {
                // build favs notify field
                $fieldname = FLEXI_J16GE ? 'jform[notify]' : 'notify';
                $elementid = FLEXI_J16GE ? 'jform_notify' : 'notify';
                /*
                $attribs = FLEXI_J16GE ? ' style ="float:none!important;" '  :  '';   // this is not right for J1.5' style ="float:left!important;" ';
                $lists['notify'] = '<input type="checkbox" name="jform[notify]" id="jform_notify" '.$attribs.' /> '. $lbltxt;
                */
                $classes = !$prettycheckable_added ? '' : ' use_prettycheckable ';
                $attribs = ' class="' . $classes . '" ';
                $lbltxt = $subscribers . ' ' . JText::_($subscribers > 1 ? 'FLEXI_SUBSCRIBERS' : 'FLEXI_SUBSCRIBER');
                if (!$prettycheckable_added) {
                    $lists['notify'] .= '<label class="fccheckradio_lbl" for="' . $elementid . '">';
                }
                $extra_params = !$prettycheckable_added ? '' : ' data-label="' . $lbltxt . '" data-labelPosition="right" data-customClass="fcradiocheck"';
                $lists['notify'] = ' <input type="checkbox" id="' . $elementid . '" element_group_id="' . $elementid . '" name="' . $fieldname . '" ' . $attribs . ' value="1" ' . $extra_params . ' checked="checked" />';
                if (!$prettycheckable_added) {
                    $lists['notify'] .= '&nbsp;' . $lbltxt . '</label>';
                }
            }
        }
        // Get author's maximum allowed categories per item and set js limitation
        $max_cat_assign = !$authorparams ? 0 : intval($authorparams->get('max_cat_assign', 0));
        $document->addScriptDeclaration('
			max_cat_assign_fc = ' . $max_cat_assign . ';
			existing_cats_fc  = ["' . implode('","', $selectedcats) . '"];
			max_cat_overlimit_msg_fc = "' . JText::_('FLEXI_TOO_MANY_ITEM_CATEGORIES', true) . '";
		');
        // Creating categorories tree for item assignment, we use the 'create' privelege
        $actions_allowed = array('core.create');
        // Featured categories form field
        $featured_cats_parent = $params->get('featured_cats_parent', 0);
        $featured_cats = array();
        $enable_featured_cid_selector = $perms['multicat'] && $perms['canchange_featcat'];
        if ($featured_cats_parent) {
            $featured_tree = flexicontent_cats::getCategoriesTree($published_only = 1, $parent_id = $featured_cats_parent, $depth_limit = 0);
            $featured_sel = array();
            foreach ($selectedcats as $featured_cat) {
                if (isset($featured_tree[$featured_cat])) {
                    $featured_sel[] = $featured_cat;
                }
            }
            $class = "use_select2_lib select2_list_selected";
            $attribs = 'class="' . $class . '" multiple="multiple" size="8"';
            $attribs .= $enable_featured_cid_selector ? '' : ' disabled="disabled"';
            $fieldname = FLEXI_J16GE ? 'jform[featured_cid][]' : 'featured_cid[]';
            $lists['featured_cid'] = ($enable_featured_cid_selector ? '' : '<label class="label" style="float:none; margin:0 6px 0 0 !important;">locked</label>') . flexicontent_cats::buildcatselect($featured_tree, $fieldname, $featured_sel, 3, $attribs, true, true, $actions_allowed);
        } else {
            // Do not display, if not configured or not allowed to the user
            $lists['featured_cid'] = false;
        }
        // Multi-category form field, for user allowed to use multiple categories
        $lists['cid'] = '';
        $enable_cid_selector = $perms['multicat'] && $perms['canchange_seccat'];
        if (1) {
            if ($tparams->get('cid_allowed_parent')) {
                $cid_tree = flexicontent_cats::getCategoriesTree($published_only = 1, $parent_id = $tparams->get('cid_allowed_parent'), $depth_limit = 0);
            } else {
                $cid_tree =& $categories;
            }
            // Get author's maximum allowed categories per item and set js limitation
            $max_cat_assign = !$authorparams ? 0 : intval($authorparams->get('max_cat_assign', 0));
            $document->addScriptDeclaration('
				max_cat_assign_fc = ' . $max_cat_assign . ';
				existing_cats_fc  = ["' . implode('","', $selectedcats) . '"];
				max_cat_overlimit_msg_fc = "' . JText::_('FLEXI_TOO_MANY_ITEM_CATEGORIES', true) . '";
			');
            $class = "mcat use_select2_lib select2_list_selected";
            $class .= $max_cat_assign ? " validate-fccats" : " validate";
            $attribs = 'class="' . $class . '" multiple="multiple" size="20"';
            $attribs .= $enable_cid_selector ? '' : ' disabled="disabled"';
            $fieldname = FLEXI_J16GE ? 'jform[cid][]' : 'cid[]';
            $skip_subtrees = $featured_cats_parent ? array($featured_cats_parent) : array();
            $lists['cid'] = ($enable_cid_selector ? '' : '<label class="label" style="float:none; margin:0 6px 0 0 !important;">locked</label>') . flexicontent_cats::buildcatselect($cid_tree, $fieldname, $selectedcats, false, $attribs, true, true, $actions_allowed, $require_all = true, $skip_subtrees, $disable_subtrees = array());
        } else {
            if (count($selectedcats) > 1) {
                foreach ($selectedcats as $catid) {
                    $cat_titles[$catid] = $globalcats[$catid]->title;
                }
                $lists['cid'] .= implode(', ', $cat_titles);
            } else {
                $lists['cid'] = false;
            }
        }
        // Main category form field
        $class = 'scat use_select2_lib';
        if ($perms['multicat']) {
            $class .= ' validate-catid';
        } else {
            $class .= ' required';
        }
        $attribs = 'class="' . $class . '"';
        $fieldname = FLEXI_J16GE ? 'jform[catid]' : 'catid';
        $enable_catid_selector = $isnew && !$tparams->get('catid_default') || !$isnew && empty($item->catid) || $perms['canchange_cat'];
        if ($tparams->get('catid_allowed_parent')) {
            $catid_tree = flexicontent_cats::getCategoriesTree($published_only = 1, $parent_id = $tparams->get('catid_allowed_parent'), $depth_limit = 0);
        } else {
            $catid_tree =& $categories;
        }
        $lists['catid'] = false;
        if (!empty($catid_tree)) {
            $disabled = $enable_catid_selector ? '' : ' disabled="disabled"';
            $attribs .= $disabled;
            $lists['catid'] = ($enable_catid_selector ? '' : '<label class="label" style="float:none; margin:0 6px 0 0 !important;">locked</label>') . flexicontent_cats::buildcatselect($catid_tree, $fieldname, $item->catid, 2, $attribs, true, true, $actions_allowed);
        } else {
            if (!$isnew && $item->catid) {
                $lists['catid'] = $globalcats[$item->catid]->title;
            }
        }
        //buid types selectlist
        $class = 'required use_select2_lib';
        $attribs = 'class="' . $class . '"';
        $fieldname = FLEXI_J16GE ? 'jform[type_id]' : 'type_id';
        $elementid = FLEXI_J16GE ? 'jform_type_id' : 'type_id';
        $lists['type'] = flexicontent_html::buildtypesselect($types, $fieldname, $typesselected->id, 1, $attribs, $elementid, $check_perms = true);
        // build version approval list
        if ($params->get('allowdisablingcomments_fe')) {
            // Set to zero if disabled or to "" (aka use default) for any other value.  THIS WILL FORCE comment field use default Global/Category/Content Type setting or disable it,
            // thus a per item commenting system cannot be selected. This is OK because it makes sense to have a different commenting system per CONTENT TYPE by not per Content Item
            $isdisabled = !$params->get('comments') && strlen($params->get('comments'));
            $fieldvalue = $isdisabled ? 0 : "";
            $fieldname = FLEXI_J16GE ? 'jform[attribs][comments]' : 'params[comments]';
            $elementid = FLEXI_J16GE ? 'jform_attribs_comments' : 'params_comments';
            /*
            $options = array();
            $options[] = JHTML::_('select.option', "",  JText::_( 'FLEXI_DEFAULT_BEHAVIOR' ) );
            $options[] = JHTML::_('select.option', 0, JText::_( 'FLEXI_DISABLE' ) );
            $attribs = FLEXI_J16GE ? ' style ="float:none!important;" ' : '';
            $lists['disable_comments'] = JHTML::_('select.radiolist', $options, $fieldname, $attribs, 'value', 'text', $fieldvalue, $elementid);
            */
            $classes = !$prettycheckable_added ? '' : ' use_prettycheckable ';
            $attribs = ' class="' . $classes . '" ';
            $i = 1;
            $options = array("" => JText::_('FLEXI_DEFAULT_BEHAVIOR'), 0 => JText::_('FLEXI_DISABLE'));
            $lists['disable_comments'] = '';
            foreach ($options as $option_id => $option_label) {
                $checked = $option_id === $fieldvalue ? ' checked="checked"' : '';
                $elementid_no = $elementid . '_' . $i;
                if (!$prettycheckable_added) {
                    $lists['disable_comments'] .= '<label class="fccheckradio_lbl" for="' . $elementid_no . '">';
                }
                $extra_params = !$prettycheckable_added ? '' : ' data-label="' . JText::_($option_label) . '" data-labelPosition="right" data-customClass="fcradiocheck"';
                $lists['disable_comments'] .= ' <input type="radio" id="' . $elementid_no . '" element_group_id="' . $elementid . '" name="' . $fieldname . '" ' . $attribs . ' value="' . $option_id . '" ' . $checked . $extra_params . ' />';
                if (!$prettycheckable_added) {
                    $lists['disable_comments'] .= '&nbsp;' . JText::_($option_label) . '</label>';
                }
                $i++;
            }
        }
        // find user's allowed languages
        $allowed_langs = !$authorparams ? null : $authorparams->get('langs_allowed', null);
        $allowed_langs = !$allowed_langs ? null : FLEXIUtilities::paramToArray($allowed_langs);
        if (!$isnew && $allowed_langs) {
            $allowed_langs[] = $item->language;
        }
        // find globaly or per content type disabled languages
        $disable_langs = $params->get('disable_languages_fe', array());
        // Build languages list
        if (FLEXI_J16GE || FLEXI_FISH) {
            $item_lang = $item->language;
            // Model has already set default language according to parameters
            $langdisplay = $params->get('langdisplay_fe', 3);
            $langconf = array();
            $langconf['flags'] = $params->get('langdisplay_flags_fe', 1);
            $langconf['texts'] = $params->get('langdisplay_texts_fe', 1);
            $field_attribs = $langdisplay == 2 ? 'class="use_select2_lib"' : '';
            $lists['languages'] = flexicontent_html::buildlanguageslist(FLEXI_J16GE ? 'jform[language]' : 'language', $field_attribs, $item->language, $langdisplay, $allowed_langs, $published_only = 1, $disable_langs, $add_all = true, $langconf);
        }
        return $lists;
    }