Exemplo n.º 1
0
 function getInput()
 {
     if (FLEXI_J16GE) {
         $node =& $this->element;
         $attributes = get_object_vars($node->attributes());
         $attributes = $attributes['@attributes'];
     } else {
         $attributes =& $node->_attributes;
     }
     $themes = flexicontent_tmpl::getTemplates();
     $tmpls = $themes->category;
     $view = JRequest::getVar('view');
     $value = FLEXI_J16GE ? $this->value : $value;
     $value = $value ? $value : $attributes['default'];
     $lays = array();
     foreach ($tmpls as $tmpl) {
         $lays[] = $tmpl->name;
     }
     $lays = implode("','", $lays);
     if (@$attributes['enableparam']) {
         $cparams = JComponentHelper::getParams('com_flexicontent');
         if (!$cparams->get($attributes['enableparam'])) {
             return FLEXI_J16GE ? '' : JText::_('FLEXI_DISABLED');
         }
     }
     if (!@$attributes['skipparams']) {
         $doc = JFactory::getDocument();
         $js = "\nvar tmpl = ['" . $lays . "'];\t\n\nfunction disablePanel(element) {\n\tvar panel \t= \$(element+'-attribs-options').getNext();\n\tvar selects = panel.getElements('select');\n\tvar inputs \t= panel.getElements('input');\n\tpanel.getParent().addClass('pane-disabled');\n\tselects.each(function(el){\n\t\tel.setProperty('disabled', 'disabled');\n\t});\n\tinputs.each(function(el){\n\t\tel.setProperty('disabled', 'disabled');\n\t});\n\tpanel.getParent().setStyle('display','none');\n}\n\nfunction enablePanel(element) {\n\tvar panel \t= \$(element+'-attribs-options').getNext();\n\tvar selects = panel.getElements('select');\n\tvar inputs \t= panel.getElements('input');\n\tpanel.getParent().removeClass('pane-disabled');\n\tselects.each(function(el){\n    \tel.setProperty('disabled', '');\n\t});\n\tinputs.each(function(el){\n    \tel.setProperty('disabled', '');\n\t});\n\tpanel.getParent().setStyle('display','');\n}\n\nfunction activatePanel(active) {\n\tvar inactives = tmpl.filter(function(item, index){\n\t\treturn item != active;\n\t\t});\n\t\t\t\n\tinactives.each(function(el){\n\t\tdisablePanel(el);\n\t\t});\n\t\t\n\tif (active) enablePanel(active);\n}\n\nwindow.addEvent('domready', function(){\n\tactivatePanel('" . $value . "');\t\t\t\n});\n";
         $doc->addScriptDeclaration($js);
     }
     $layouts = array();
     if (@$attributes['firstoption']) {
         $layouts[] = JHTMLSelect::option('', JText::_($attributes['firstoption']));
     }
     if ($tmpls !== false) {
         if ($view != 'category' && $view != 'user') {
             $layouts[] = JHTMLSelect::option('', JText::_('FLEXI_USE_GLOBAL'));
         }
         foreach ($tmpls as $tmpl) {
             $layouts[] = JHTMLSelect::option($tmpl->name, $tmpl->name);
         }
     }
     $fieldname = FLEXI_J16GE ? $this->name : $control_name . '[' . $name . ']';
     $element_id = FLEXI_J16GE ? $this->id : $control_name . $name;
     $attribs = !FLEXI_J16GE ? ' style="float:left;" ' : '';
     if (@$attributes['multiple'] == 'multiple' || @$attributes['multiple'] == 'true') {
         $attribs .= ' multiple="multiple" ';
         $attribs .= @$attributes['size'] ? ' size="' . @$attributes['size'] . '" ' : ' size="6" ';
         $fieldname .= !FLEXI_J16GE ? "[]" : "";
         // NOTE: this added automatically in J2.5
     } else {
         $attribs .= 'class="inputbox"';
     }
     if (!@$attributes['skipparams']) {
         $attribs .= ' onchange="activatePanel(this.value);"';
     }
     return JHTML::_('select.genericlist', $layouts, $fieldname, $attribs, 'value', 'text', $value, $element_id);
 }
Exemplo n.º 2
0
 /**
  * Method to get the template list and their properties
  *
  * @access	private
  * @return	array
  * @since	1.5
  */
 function _getTemplates()
 {
     $folders = flexicontent_tmpl::getThemes();
     $tmpl = flexicontent_tmpl::getTemplates();
     $themes = array();
     foreach ($folders as $folder) {
         $themes[$folder] = new stdClass();
         $themes[$folder]->name = $folder;
         $themes[$folder]->items = isset($tmpl->items->{$folder}) ? $tmpl->items->{$folder} : '';
         $themes[$folder]->category = isset($tmpl->category->{$folder}) ? $tmpl->category->{$folder} : '';
     }
     return $themes;
 }
Exemplo n.º 3
0
 protected function getInput()
 {
     $node =& $this->element;
     $attributes = get_object_vars($node->attributes());
     $attributes = $attributes['@attributes'];
     $themes = flexicontent_tmpl::getTemplates();
     $tmpls = $themes->category ? $themes->category : array();
     $values = $this->value;
     if (empty($values)) {
         $values = array();
     }
     if (!is_array($values)) {
         $values = preg_split("/[\\|,]/", $values);
     }
     $fieldname = $this->name;
     $element_id = $this->id;
     // Field parameter (attributes)
     $attribs = '';
     $classes = 'use_select2_lib ';
     $classes .= @$attributes['required'] && @$attributes['required'] != 'false' ? ' required' : '';
     $classes .= @$attributes['class'] ? ' ' . $attributes['class'] : '';
     $attribs = ' class="' . $classes . '" ' . $attribs;
     $attribs .= ' style="float:left;" ';
     if (@$attributes['multiple'] == 'multiple' || @$attributes['multiple'] == 'true') {
         $attribs .= ' multiple="multiple" ';
         $attribs .= @$attributes['size'] ? ' size="' . $attributes['size'] . '" ' : ' size="6" ';
     } else {
         array_unshift($types, JHTML::_('select.option', '', JText::_('FLEXI_PLEASE_SELECT')));
         $attribs .= 'class="inputbox"';
     }
     if ($onchange = @$attributes['onchange']) {
         $attribs .= ' onchange="' . $onchange . '"';
     }
     // Field data (the templates)
     $lays = array();
     foreach ($tmpls as $tmpl) {
         $lays[] = $tmpl->name;
     }
     $lays = implode("','", $lays);
     if ($tmpls !== false) {
         foreach ($tmpls as $tmpl) {
             $layouts[] = JHTMLSelect::option($tmpl->name, $tmpl->name);
         }
     }
     return JHTML::_('select.genericlist', $layouts, $fieldname, $attribs, 'value', 'text', $values, $element_id);
 }
Exemplo n.º 4
0
 /**
  * Method to get the object
  *
  * @access	private
  * @return	array
  * @since	1.5
  */
 function _getLayout()
 {
     $tmpl = flexicontent_tmpl::getTemplates();
     $layout = $tmpl->{$this->_type}->{$this->_folder};
     return $layout;
 }
Exemplo n.º 5
0
    /**
     * Creates the item submit form
     *
     * @since 1.0
     */
    function _displayForm($tpl)
    {
        jimport('joomla.html.parameter');
        // ... we use some strings from administrator part
        // load english language file for 'com_content' component then override with current language file
        JFactory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR, 'en-GB', true);
        JFactory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR, null, true);
        // load english language file for 'com_flexicontent' component then override with current language file
        JFactory::getLanguage()->load('com_flexicontent', JPATH_ADMINISTRATOR, 'en-GB', true);
        JFactory::getLanguage()->load('com_flexicontent', JPATH_ADMINISTRATOR, null, true);
        // ********************************
        // Initialize variables, flags, etc
        // ********************************
        $app = JFactory::getApplication();
        $dispatcher = JDispatcher::getInstance();
        $document = JFactory::getDocument();
        $session = JFactory::getSession();
        $user = JFactory::getUser();
        $db = JFactory::getDBO();
        $uri = JFactory::getURI();
        $nullDate = $db->getNullDate();
        $menu = $app->getMenu()->getActive();
        // We do not have item parameters yet, but we need to do some work before creating the item
        // Get the COMPONENT only parameter
        $params = new JRegistry();
        $cparams = JComponentHelper::getParams('com_flexicontent');
        $params->merge($cparams);
        // Merge the active menu parameters
        if ($menu) {
            $params->merge($menu->params);
        }
        // Some flags
        $enable_translation_groups = flexicontent_db::useAssociations();
        //$params->get("enable_translation_groups");
        $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');
        flexicontent_html::loadFramework('flexi-lib');
        // Load custom behaviours: form validation, popup tooltips
        JHTML::_('behavior.formvalidation');
        // load default validation JS to make sure it is overriden
        JHTML::_('behavior.tooltip');
        if (FLEXI_J30GE) {
            JHtml::_('bootstrap.tooltip');
        }
        //JHTML::_('script', 'joomla.javascript.js', 'includes/js/');
        // Add css files to the document <head> section (also load CSS joomla template override)
        $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/flexicontent.css');
        if (file_exists(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'css' . DS . 'flexicontent.css')) {
            $document->addStyleSheet($this->baseurl . '/templates/' . $app->getTemplate() . '/css/flexicontent.css');
        }
        // Fields common CSS
        $document->addStyleSheet($this->baseurl . '/components/com_flexicontent/assets/css/flexi_form_fields.css');
        // Load backend / frontend shared and Joomla version specific CSS (different for frontend / backend)
        FLEXI_J30GE ? $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/j3x.css') : $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/j25.css');
        // Add js function to overload the joomla submitform
        $document->addScript(JURI::base(true) . '/components/com_flexicontent/assets/js/admin.js');
        $document->addScript(JURI::base(true) . '/components/com_flexicontent/assets/js/validate.js');
        // Add js function for custom code used by FLEXIcontent item form
        $document->addScript(JURI::base(true) . '/components/com_flexicontent/assets/js/itemscreen.js');
        // *********************************************************
        // Get item data and create item form (that loads item data)
        // *********************************************************
        if ($print_logging_info) {
            $start_microtime = microtime(true);
        }
        $model = $this->getModel();
        // ** WE NEED TO get OR decide the Content Type, before we call the getItem
        // ** We rely on typeid Request variable to decide type for new items so make sure this is set,
        // ZERO means allow user to select type, but if user is only allowed a single type, then autoselect it!
        // Try type from session
        $jdata = $app->getUserState('com_flexicontent.edit.item.data');
        //print_r($jdata);
        if (!empty($jdata['type_id'])) {
            JRequest::setVar('typeid', (int) $jdata['type_id']);
            // This also forces zero if value not set
        } else {
            if ($menu && isset($menu->query['typeid'])) {
                JRequest::setVar('typeid', (int) $menu->query['typeid']);
                // This also forces zero if value not set
            }
        }
        $new_typeid = JRequest::getVar('typeid', 0, '', 'int');
        // Verify type is allowed to the user
        if (!$new_typeid) {
            $types = $model->getTypeslist($type_ids_arr = false, $check_perms = true, $_published = true);
            if ($types && count($types) == 1) {
                $new_typeid = $types[0]->id;
            }
            JRequest::setVar('typeid', $new_typeid);
            $canCreateType = true;
        }
        // FORCE model to load versioned data (URL specified version or latest version (last saved))
        $version = JRequest::getVar('version', 0, 'request', 'int');
        // Load specific item version (non-zero), 0 version: is unversioned data, -1 version: is latest version (=default for edit form)
        $item = $model->getItem(null, $check_view_access = false, $no_cache = true, $force_version = $version != 0 ? $version : -1);
        // -1 version means latest
        // Replace component/menu 'params' with thee merged component/category/type/item/menu ETC ... parameters
        $params =& $item->parameters;
        if ($print_logging_info) {
            $fc_run_times['get_item_data'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
        }
        // Load permissions (used by form template)
        $perms = $this->_getItemPerms($item);
        // Create submit configuration (for new items) into the session, this is needed before creating the item form
        $submitConf = $this->_createSubmitConf($item, $perms);
        // Most core field are created via calling methods of the form (J2.5)
        $form = $this->get('Form');
        // is new item and ownership Flags
        $isnew = !$item->id;
        $isOwner = $item->created_by == $user->get('id');
        // Get available types and the currently selected/requested type
        $types = $model->getTypeslist();
        $typesselected = $model->getTypesselected();
        // Get type parameters, these are needed besides the 'merged' item parameters, e.g. to get Type's default layout
        $tparams = $this->get('Typeparams');
        $tparams = new JRegistry($tparams);
        // *********************************************************************************************************
        // Get language stuff, and also load Template-Specific language file to override or add new language strings
        // *********************************************************************************************************
        if ($enable_translation_groups) {
            $langAssocs = $params->get('uselang_fe') == 1 ? $this->get('LangAssocs') : false;
        }
        $langs = FLEXIUtilities::getLanguages('code');
        FLEXIUtilities::loadTemplateLanguageFile($params->get('ilayout', 'default'));
        // *************************************
        // Create captcha field via custom logic
        // *************************************
        // create and set (into HTTP request) a unique item id for plugins that needed it
        if ($item->id) {
            $unique_tmp_itemid = $item->id;
        } else {
            $unique_tmp_itemid = $app->getUserState('com_flexicontent.edit.item.unique_tmp_itemid');
            $unique_tmp_itemid = $unique_tmp_itemid ? $unique_tmp_itemid : date('_Y_m_d_h_i_s_', time()) . uniqid(true);
        }
        //print_r($unique_tmp_itemid);
        JRequest::setVar('unique_tmp_itemid', $unique_tmp_itemid);
        // Component / Menu Item parameters
        $allowunauthorize = $params->get('allowunauthorize', 0);
        // allow unauthorised user to submit new content
        $unauthorized_page = $params->get('unauthorized_page', '');
        // page URL for unauthorized users (via global configuration)
        $notauth_itemid = $params->get('notauthurl', '');
        // menu itemid (to redirect) when user is not authorized to create content
        // Create captcha field or messages
        // Maybe some code can be removed by using Joomla's built-in form element (in XML file), instead of calling the captcha plugin ourselves
        $use_captcha = $params->get('use_captcha', 1);
        // 1 for guests, 2 for any user
        $captcha_formop = $params->get('captcha_formop', 0);
        // 0 for submit, 1 for submit/edit (aka always)
        $display_captcha = $use_captcha >= 2 || $use_captcha == 1 && $user->guest;
        $display_captcha = $display_captcha && ($isnew || $captcha_formop);
        // Trigger the configured captcha plugin
        if ($display_captcha) {
            // Get configured captcha plugin
            $c_plugin = $params->get('captcha', $app->getCfg('captcha'));
            // TODO add param to override default
            if ($c_plugin) {
                $c_name = 'captcha_response_field';
                $c_id = $c_plugin == 'recaptcha' ? 'dynamic_recaptcha_1' : 'fc_dynamic_captcha';
                $c_class = ' required';
                $c_namespace = 'fc_item_form';
                // Try to load the configured captcha plugin, (check if disabled or uninstalled), Joomla will enqueue an error message if needed
                $captcha_obj = JCaptcha::getInstance($c_plugin, array('namespace' => $c_namespace));
                if ($captcha_obj) {
                    $captcha_field = $captcha_obj->display($c_name, $c_id, $c_class);
                    $label_class = 'flexi_label';
                    $label_class .= FLEXI_J30GE ? ' hasTooltip' : ' hasTip';
                    $label_tooltip = flexicontent_html::getToolTip(null, 'FLEXI_CAPTCHA_ENTER_CODE_DESC', 1, 1);
                    $captcha_field = '
						<label id="' . $c_name . '-lbl" for="' . $c_name . '" class="' . $label_class . '" title="' . $label_tooltip . '" >
						' . JText::_('FLEXI_CAPTCHA_ENTER_CODE') . '
						</label>
						<div id="container_fcfield_' . $c_plugin . '" class="container_fcfield container_fcfield_name_' . $c_plugin . '">
							<div class="fcfieldval_container valuebox fcfieldval_container_' . $c_plugin . '">
							' . $captcha_field . '
							</div>
						</div>';
                }
            }
        }
        // *******************************
        // CHECK EDIT / CREATE PERMISSIONS
        // *******************************
        // User Group / Author parameters
        $authorparams = flexicontent_db::getUserConfig($user->id);
        $max_auth_limit = intval($authorparams->get('max_auth_limit', 0));
        // maximum number of content items the user can create
        $hasTmpEdit = false;
        $hasCoupon = false;
        // Check session
        if ($session->has('rendered_uneditable', 'flexicontent')) {
            $rendered_uneditable = $session->get('rendered_uneditable', array(), 'flexicontent');
            $hasTmpEdit = !empty($rendered_uneditable[$model->get('id')]);
            $hasCoupon = !empty($rendered_uneditable[$model->get('id')]) && $rendered_uneditable[$model->get('id')] == 2;
            // editable via coupon
        }
        if (!$isnew) {
            // EDIT action
            // Finally check if item is currently being checked-out (currently being edited)
            if ($model->isCheckedOut($user->get('id'))) {
                $msg = JText::sprintf('FLEXI_DESCBEINGEDITTED', $model->get('title'));
                $app->redirect(JRoute::_('index.php?view=' . FLEXI_ITEMVIEW . '&cid=' . $model->get('catid') . '&id=' . $model->get('id'), false), $msg);
            }
            //Checkout the item
            $model->checkout();
            // Get edit access, this includes privileges edit and edit-own and the temporary EDIT flag ('rendered_uneditable')
            $canEdit = $model->getItemAccess()->get('access-edit');
            // If no edit privilege, check if edit COUPON was provided
            if (!$canEdit) {
                $edittok = JRequest::getCmd('edittok', false);
                if ($edittok) {
                    $query = 'SHOW TABLES LIKE "' . $app->getCfg('dbprefix') . 'flexicontent_edit_coupons"';
                    $db->setQuery($query);
                    $tbl_exists = (bool) count($db->loadObjectList());
                    if ($tbl_exists) {
                        $query = 'SELECT * FROM #__flexicontent_edit_coupons ' . ' WHERE token = ' . $db->Quote($edittok) . ' AND id = ' . $model->get('id');
                        $db->setQuery($query);
                        $tokdata = $db->loadObject();
                        if ($tokdata) {
                            $hasCoupon = true;
                            $rendered_uneditable = $session->get('rendered_uneditable', array(), 'flexicontent');
                            $rendered_uneditable[$model->get('id')] = 2;
                            // 2: indicates, that has edit via EDIT Coupon
                            $session->set('rendered_uneditable', $rendered_uneditable, 'flexicontent');
                            $canEdit = 1;
                        } else {
                            JError::raiseNotice(403, JText::_('EDIT_TOKEN_IS_INVALID') . ' : ' . $edittok);
                        }
                    }
                }
            }
            // Edit check finished, throw error if needed
            if (!$canEdit) {
                if ($user->guest) {
                    $uri = JFactory::getURI();
                    $return = $uri->toString();
                    $fcreturn = serialize(array('id' => @$this->_item->id, 'cid' => $cid));
                    // a special url parameter, used by some SEF code
                    $com_users = FLEXI_J16GE ? 'com_users' : 'com_user';
                    $url = $params->get('login_page', 'index.php?option=' . $com_users . '&view=login');
                    $return = strtr(base64_encode($return), '+/=', '-_,');
                    $url .= '&return=' . $return;
                    //$url .= '&return='.urlencode(base64_encode($return));
                    $url .= '&fcreturn=' . base64_encode($fcreturn);
                    JError::raiseWarning(403, JText::sprintf("FLEXI_LOGIN_TO_ACCESS", $url));
                    $app->redirect($url);
                } else {
                    if ($unauthorized_page) {
                        //  unauthorized page via global configuration
                        JError::raiseNotice(403, JText::_('FLEXI_ALERTNOTAUTH_TASK'));
                        $app->redirect($unauthorized_page);
                    } else {
                        // user isn't authorize to edit this content
                        $msg = JText::_('FLEXI_ALERTNOTAUTH_TASK');
                        if (FLEXI_J16GE) {
                            throw new Exception($msg, 403);
                        } else {
                            JError::raiseError(403, $msg);
                        }
                    }
                }
            }
        } else {
            // CREATE action
            // Get create access, this includes check of creating in at least one category, and type's "create items"
            $canAdd = $model->getItemAccess()->get('access-create');
            $not_authorised = !$canAdd;
            // Check if Content Type can be created by current user
            if (empty($canCreateType)) {
                if ($new_typeid) {
                    // not needed, already done be model when type_id is set, check and remove
                    $canCreateType = $model->canCreateType(array($new_typeid));
                    // Can create given Content Type
                } else {
                    // needed not done be model yet
                    $canCreateType = $model->canCreateType();
                    // Can create at least one Content Type
                }
            }
            $not_authorised = $not_authorised || !$canCreateType;
            // Allow item submission by unauthorized users, ... even guests ...
            if ($allowunauthorize == 2) {
                $allowunauthorize = !$user->guest;
            }
            if ($not_authorised && !$allowunauthorize) {
                if (!$canCreateType) {
                    $type_name = isset($types[$new_typeid]) ? '"' . JText::_($types[$new_typeid]->name) . '"' : JText::_('FLEXI_ANY');
                    $msg = JText::sprintf('FLEXI_NO_ACCESS_CREATE_CONTENT_OF_TYPE', $type_name);
                } else {
                    $msg = JText::_('FLEXI_ALERTNOTAUTH_CREATE');
                }
            } else {
                if ($max_auth_limit) {
                    $db->setQuery('SELECT COUNT(id) FROM #__content WHERE created_by = ' . $user->id);
                    $authored_count = $db->loadResult();
                    $content_is_limited = $authored_count >= $max_auth_limit;
                    $msg = $content_is_limited ? JText::sprintf('FLEXI_ALERTNOTAUTH_CREATE_MORE', $max_auth_limit) : '';
                }
            }
            if ($not_authorised && !$allowunauthorize || @$content_is_limited) {
                // User isn't authorize to add ANY content
                if ($notauth_menu = $app->getMenu()->getItem($notauth_itemid)) {
                    // a. custom unauthorized submission page via menu item
                    $internal_link_vars = @$notauth_menu->component ? '&Itemid=' . $notauth_itemid . '&option=' . $notauth_menu->component : '';
                    $notauthurl = JRoute::_($notauth_menu->link . $internal_link_vars, false);
                    JError::raiseNotice(403, $msg);
                    $app->redirect($notauthurl);
                } else {
                    if ($unauthorized_page) {
                        // b. General unauthorized page via global configuration
                        JError::raiseNotice(403, $msg);
                        $app->redirect($unauthorized_page);
                    } else {
                        // c. Finally fallback to raising a 403 Exception/Error that will redirect to site's default 403 unauthorized page
                        if (FLEXI_J16GE) {
                            throw new Exception($msg, 403);
                        } else {
                            JError::raiseError(403, $msg);
                        }
                    }
                }
            }
        }
        // *****************************************************************************
        // 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'
        // *****************************************************************************
        // Check if saving an item that translates an original content in site's default language
        $site_default = substr(flexicontent_html::getSiteDefaultLang(), 0, 2);
        $is_content_default_lang = $site_default == 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;
        if ($print_logging_info) {
            $start_microtime = microtime(true);
        }
        $fields = $this->get('Extrafields');
        $item->fields =& $fields;
        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);
        }
        $jcustom = $app->getUserState('com_flexicontent.edit.item.custom');
        //print_r($jcustom);
        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 (isset($jcustom[$field->name])) {
                    $field->value = array();
                    foreach ($jcustom[$field->name] as $i => $_val) {
                        $field->value[$i] = $_val;
                    }
                }
                $is_editable = !$field->valueseditable || $user->authorise('flexicontent.editfieldvalues', 'com_flexicontent.field.' . $field->id);
                if ($is_editable) {
                    FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayField', array(&$field, &$item));
                    if ($field->untranslatable) {
                        $field->html = '<div class="alert alert-info fc-small fc-iblock">' . JText::_('FLEXI_FIELD_VALUE_IS_NON_TRANSLATABLE') . '</div>' . "\n" . $field->html;
                    }
                } else {
                    if ($field->valueseditable == 1) {
                        $field->html = '<div class="fc-mssg fc-note">' . JText::_($field->parameters->get('no_acc_msg_form') ? $field->parameters->get('no_acc_msg_form') : 'FLEXI_NO_ACCESS_LEVEL_TO_EDIT_FIELD') . '</div>';
                    } else {
                        if ($field->valueseditable == 2) {
                            FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayFieldValue', array(&$field, $item));
                            $field->html = '<div class="fc-mssg fc-note">' . JText::_($field->parameters->get('no_acc_msg_form') ? $field->parameters->get('no_acc_msg_form') : 'FLEXI_NO_ACCESS_LEVEL_TO_EDIT_FIELD') . '</div>' . "\n" . $field->display;
                        } else {
                            if ($field->valueseditable == 3) {
                                FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayFieldValue', array(&$field, $item));
                                $field->html = $field->display;
                            } else {
                                if ($field->valueseditable == 4) {
                                    $field->html = '';
                                    $field->formhidden = 4;
                                }
                            }
                        }
                    }
                }
            }
            // 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;
        }
        // Tags used by the item
        $usedtagsids = $this->get('UsedtagsIds');
        // NOTE: This will normally return the already set versioned value of tags ($item->tags)
        $usedtagsdata = $model->getUsedtagsData($usedtagsids);
        // Get the edit lists
        $lists = $this->_buildEditLists($perms, $params, $authorparams);
        // Get number of subscribers
        $subscribers = $this->get('SubscribersCount');
        // Get menu overridden categories/main category fields
        $menuCats = $this->_getMenuCats($item, $perms);
        // Create placement configuration for CORE properties
        $placementConf = $this->_createPlacementConf($item, $fields);
        // Item language related vars
        $languages = FLEXIUtilities::getLanguages();
        $itemlang = new stdClass();
        $itemlang->shortcode = substr($item->language, 0, 2);
        $itemlang->name = $languages->{$item->language}->name;
        $itemlang->image = '<img src="' . @$languages->{$item->language}->imgsrc . '" alt="' . $languages->{$item->language}->name . '" />';
        //Load the JEditor object
        $editor = JFactory::getEditor();
        // **********************************************************
        // Calculate a (browser window) page title and a page heading
        // **********************************************************
        // Verify menu item points to current FLEXIcontent object
        if ($menu) {
            $menu_matches = false;
            $view_ok = FLEXI_ITEMVIEW == @$menu->query['view'] || 'article' == @$menu->query['view'];
            $menu_matches = $view_ok;
            //$menu_params = $menu->params;  // Get active menu item parameters
        } else {
            $menu_matches = false;
        }
        // MENU ITEM matched, use its page heading (but use menu title if the former is not set)
        if ($menu_matches) {
            $default_heading = FLEXI_J16GE ? $menu->title : $menu->name;
            // Cross set (show_) page_heading / page_title for compatibility of J2.5+ with J1.5 template (and for J1.5 with J2.5 template)
            $params->def('page_heading', $params->get('page_title', $default_heading));
            $params->def('page_title', $params->get('page_heading', $default_heading));
            $params->def('show_page_heading', $params->get('show_page_title', 0));
            $params->def('show_page_title', $params->get('show_page_heading', 0));
        } else {
            // Calculate default page heading (=called page title in J1.5), which in turn will be document title below !! ...
            $default_heading = !$isnew ? JText::_('FLEXI_EDIT') : JText::_('FLEXI_NEW');
            // Decide to show page heading (=J1.5 page title), there is no need for this in item view
            $show_default_heading = 0;
            // Set both (show_) page_heading / page_title for compatibility of J2.5+ with J1.5 template (and for J1.5 with J2.5 template)
            $params->set('page_title', $default_heading);
            $params->set('page_heading', $default_heading);
            $params->set('show_page_heading', $show_default_heading);
            $params->set('show_page_title', $show_default_heading);
        }
        // ************************************************************
        // Create the document title, by from page title and other data
        // ************************************************************
        // Use the page heading as document title, (already calculated above via 'appropriate' logic ...)
        $doc_title = $params->get('page_title');
        // Check and prepend or append site name
        // Add Site Name to page title
        if ($app->getCfg('sitename_pagetitles', 0) == 1) {
            $doc_title = $app->getCfg('sitename') . " - " . $doc_title;
        } elseif ($app->getCfg('sitename_pagetitles', 0) == 2) {
            $doc_title = $doc_title . " - " . $app->getCfg('sitename');
        }
        // Finally, set document title
        $document->setTitle($doc_title);
        // Add title to pathway
        $pathway = $app->getPathWay();
        $pathway->addItem($doc_title, '');
        // Get pageclass suffix
        $pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx'));
        // Ensure the row data is safe html
        // @TODO: check if this is really required as it conflicts with the escape function in the tmpl
        //JFilterOutput::objectHTMLSafe( $item );
        $this->assign('action', $uri->toString());
        $this->assignRef('item', $item);
        $this->assignRef('form', $form);
        // most core field are created via calling methods of the form (J2.5)
        if ($enable_translation_groups) {
            $this->assignRef('lang_assocs', $langAssocs);
        }
        $this->assignRef('langs', $langs);
        $this->assignRef('params', $params);
        $this->assignRef('lists', $lists);
        $this->assignRef('subscribers', $subscribers);
        $this->assignRef('editor', $editor);
        $this->assignRef('user', $user);
        $this->assignRef('usedtagsdata', $usedtagsdata);
        $this->assignRef('fields', $fields);
        $this->assignRef('tparams', $tparams);
        $this->assignRef('perms', $perms);
        $this->assignRef('document', $document);
        $this->assignRef('nullDate', $nullDate);
        $this->assignRef('menuCats', $menuCats);
        $this->assignRef('submitConf', $submitConf);
        $this->assignRef('placementConf', $placementConf);
        $this->assignRef('itemlang', $itemlang);
        $this->assignRef('pageclass_sfx', $pageclass_sfx);
        $this->assign('captcha_errmsg', @$captcha_errmsg);
        $this->assign('captcha_field', @$captcha_field);
        // ****************************************************************
        // SET INTO THE FORM, parameter values for various parameter groups
        // ****************************************************************
        if (JHTML::_('date', $item->publish_down, 'Y') <= 1969 || $item->publish_down == $nullDate) {
            $item->publish_down = 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();
        }
        if (!is_array($allowed_tmpls)) {
            $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);
            }
        }
        $this->assignRef('tmpls', $tmpls);
        // Clear custom form data from session
        $app->setUserState($form->option . '.edit.' . $form->context . '.custom', false);
        $app->setUserState($form->option . '.edit.' . $form->context . '.jfdata', false);
        $app->setUserState($form->option . '.edit.' . $form->context . '.unique_tmp_itemid', false);
        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;
        }
    }
Exemplo n.º 6
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;
        }
    }
Exemplo n.º 7
0
<?php
if (!$this->items) {
	// No items exist
	if ($this->getModel()->getState('limit')) {
		// Not creating a category view without items
		echo '<div class="noitems group">' . JText::_( 'FLEXI_NO_ITEMS_FOUND' ) . '</div>';
	}
	return;
}

// routine to determine all used columns for this table
$show_title  = $this->params->get('show_title', 1);
$link_titles = $this->params->get('link_titles', 0);

$layout = $this->params->get('clayout', 'default');
$fbypos = flexicontent_tmpl::getFieldsByPositions($layout, 'category');
$columns = array();
foreach ($this->items as $item) :
	if (isset($item->positions['table'])) :
		foreach ($fbypos['table']->fields as $f) :
			if ( ! @ $columns[$f] ) :
				$columns[$f] = @ $item->fields[$f]->label;
			endif;
		endforeach;
	endif;
endforeach;

$items = & $this->items;

// Decide whether to show the edit column
$buttons_exists = false;
Exemplo n.º 8
0
 /**
  * Method to check if the field positions were converted
  * and if not, convert them
  *
  * @access public
  * @return	boolean	True on success
  */
 function getFieldsPositions()
 {
     $query = "SELECT name, positions" . " FROM #__flexicontent_fields" . " WHERE positions <> ''";
     $this->_db->setQuery($query);
     $fields = $this->_db->loadObjectList();
     if ($fields) {
         // create a temporary table to store the positions
         $this->_db->setQuery("DROP TABLE IF EXISTS #__flexicontent_positions_tmp");
         $this->_db->query();
         $query = "\r\n\t\t\t\t\tCREATE TABLE #__flexicontent_positions_tmp (\r\n\t\t\t\t\t  `field` varchar(100) NOT NULL default '',\r\n\t\t\t\t\t  `view` varchar(30) NOT NULL default '',\r\n\t\t\t\t\t  `folder` varchar(100) NOT NULL default '',\r\n\t\t\t\t\t  `position` varchar(255) NOT NULL default ''\r\n\t\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8\r\n\t\t\t\t\t";
         $this->_db->setQuery($query);
         $this->_db->query();
         foreach ($fields as $field) {
             $field->positions = explode("\n", $field->positions);
             foreach ($field->positions as $pos) {
                 $pos = explode('.', $pos);
                 $query = 'INSERT INTO #__flexicontent_positions_tmp (`field`, `view`, `folder`, `position`) VALUES(' . $this->_db->Quote($field->name) . ',' . $this->_db->Quote($pos[1]) . ',' . $this->_db->Quote($pos[2]) . ',' . $this->_db->Quote($pos[0]) . ')';
                 $this->_db->setQuery($query);
                 $this->_db->query();
             }
         }
         $templates = flexicontent_tmpl::getTemplates();
         $folders = flexicontent_tmpl::getThemes();
         $views = array('items', 'category');
         foreach ($folders as $folder) {
             foreach ($views as $view) {
                 $groups = @$templates->{$view}->{$folder}->positions;
                 if ($groups) {
                     foreach ($groups as $group) {
                         $query = 'SELECT field' . ' FROM #__flexicontent_positions_tmp' . ' WHERE view = ' . $this->_db->Quote($view) . ' AND folder = ' . $this->_db->Quote($folder) . ' AND position = ' . $this->_db->Quote($group);
                         $this->_db->setQuery($query);
                         $fieldstopos = FLEXI_J16GE ? $this->_db->loadColumn() : $this->_db->loadResultArray();
                         if ($fieldstopos) {
                             $field = implode(',', $fieldstopos);
                             $query = 'INSERT INTO #__flexicontent_templates (`template`, `layout`, `position`, `fields`) VALUES(' . $this->_db->Quote($folder) . ',' . $this->_db->Quote($view) . ',' . $this->_db->Quote($group) . ',' . $this->_db->Quote($field) . ')';
                             $this->_db->setQuery($query);
                             $this->_db->query();
                         }
                     }
                 }
             }
         }
         // delete the temporary table
         $query = 'DROP TABLE #__flexicontent_positions_tmp';
         $this->_db->setQuery($query);
         $this->_db->query();
         // delete the old positions
         $query = "UPDATE #__flexicontent_fields SET positions = ''";
         $this->_db->setQuery($query);
         $this->_db->query();
         // alter ordering field for releases prior to beta5
         $query = "ALTER TABLE #__flexicontent_cats_item_relations MODIFY `ordering` int(11) NOT NULL default '0'";
         $this->_db->setQuery($query);
         $this->_db->query();
         $query = "ALTER TABLE #__flexicontent_fields_type_relations MODIFY `ordering` int(11) NOT NULL default '0'";
         $this->_db->setQuery($query);
         $this->_db->query();
     }
     return $fields;
 }
Exemplo n.º 9
0
 /**
  * Method to check if the field positions were converted
  * and if not, convert them
  *
  * @access public
  * @return	boolean	True on success
  */
 function convertOldFieldsPositions()
 {
     static $return;
     if ($return !== null) {
         return $return;
     }
     $return = true;
     // only call once
     $query = "SELECT name, positions" . " FROM #__flexicontent_fields" . " WHERE positions <> ''";
     $this->_db->setQuery($query);
     $fields = $this->_db->loadObjectList();
     if (empty($fields)) {
         return $return;
     }
     // create a temporary table to store the positions
     $this->_db->setQuery("DROP TABLE IF EXISTS #__flexicontent_positions_tmp");
     $this->_db->query();
     $query = "\r\n\t\t\t\tCREATE TABLE #__flexicontent_positions_tmp (\r\n\t\t\t\t  `field` varchar(100) NOT NULL default '',\r\n\t\t\t\t  `view` varchar(30) NOT NULL default '',\r\n\t\t\t\t  `folder` varchar(100) NOT NULL default '',\r\n\t\t\t\t  `position` varchar(255) NOT NULL default ''\r\n\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8\r\n\t\t\t\t";
     $this->_db->setQuery($query);
     $this->_db->query();
     foreach ($fields as $field) {
         $field->positions = explode("\n", $field->positions);
         foreach ($field->positions as $pos) {
             $pos = explode('.', $pos);
             $query = 'INSERT INTO #__flexicontent_positions_tmp (`field`, `view`, `folder`, `position`) VALUES(' . $this->_db->Quote($field->name) . ',' . $this->_db->Quote($pos[1]) . ',' . $this->_db->Quote($pos[2]) . ',' . $this->_db->Quote($pos[0]) . ')';
             $this->_db->setQuery($query);
             $this->_db->query();
         }
     }
     $templates = flexicontent_tmpl::getTemplates();
     $folders = flexicontent_tmpl::getThemes();
     $views = array('items', 'category');
     foreach ($folders as $folder) {
         foreach ($views as $view) {
             $groups = @$templates->{$view}->{$folder}->positions;
             if ($groups) {
                 foreach ($groups as $group) {
                     $query = 'SELECT field' . ' FROM #__flexicontent_positions_tmp' . ' WHERE view = ' . $this->_db->Quote($view) . ' AND folder = ' . $this->_db->Quote($folder) . ' AND position = ' . $this->_db->Quote($group);
                     $this->_db->setQuery($query);
                     $fieldstopos = FLEXI_J16GE ? $this->_db->loadColumn() : $this->_db->loadResultArray();
                     if ($fieldstopos) {
                         $field = implode(',', $fieldstopos);
                         $query = 'INSERT INTO #__flexicontent_templates (`template`, `layout`, `position`, `fields`) VALUES(' . $this->_db->Quote($folder) . ',' . $this->_db->Quote($view) . ',' . $this->_db->Quote($group) . ',' . $this->_db->Quote($field) . ')';
                         $this->_db->setQuery($query);
                         // By catching SQL error (e.g. layout configuration of template already exists),
                         // we will allow execution to continue, thus clearing "positions" column in fields table
                         try {
                             $this->_db->query();
                         } catch (Exception $e) {
                         }
                         if ($this->_db->getErrorNum()) {
                             echo $this->_db->getErrorMsg();
                         }
                     }
                 }
             }
         }
     }
     // delete the temporary table
     $query = 'DROP TABLE #__flexicontent_positions_tmp';
     $this->_db->setQuery($query);
     $this->_db->query();
     // delete the old positions
     $query = "UPDATE #__flexicontent_fields SET positions = ''";
     $this->_db->setQuery($query);
     $this->_db->query();
     // alter ordering field for releases prior to beta5
     $query = "ALTER TABLE #__flexicontent_cats_item_relations MODIFY `ordering` int(11) NOT NULL default '0'";
     $this->_db->setQuery($query);
     $this->_db->query();
     $query = "ALTER TABLE #__flexicontent_fields_type_relations MODIFY `ordering` int(11) NOT NULL default '0'";
     $this->_db->setQuery($query);
     $this->_db->query();
     return $return;
 }
Exemplo n.º 10
0
 /**
  * Method to decide which item layout to use
  *
  * @access	public
  * @param	int item identifier
  */
 function decideLayout(&$compParams, &$typeParams, &$itemParams)
 {
     // Decide to use mobile or normal item template layout
     $useMobile = $compParams->get('use_mobile_layouts', 0);
     if ($useMobile) {
         $force_desktop_layout = $compParams->get('force_desktop_layout', 0);
         $mobileDetector = flexicontent_html::getMobileDetector();
         $isMobile = $mobileDetector->isMobile();
         $isTablet = $mobileDetector->isTablet();
         $useMobile = $force_desktop_layout ? $isMobile && !$isTablet : $isMobile;
     }
     $_ilayout = $useMobile ? 'ilayout_mobile' : 'ilayout';
     // Get item layout (... if not already set), from the configuration parameter (that was decided above)
     $ilayout = $this->_ilayout == '__request__' ? JRequest::getVar($_ilayout, false) : false;
     if (!$ilayout) {
         $desktop_ilayout = $itemParams->get('ilayout', $typeParams->get('ilayout', 'default'));
         $ilayout = !$useMobile ? $desktop_ilayout : $itemParams->get('ilayout_mobile', $typeParams->get('ilayout_mobile', $desktop_ilayout));
     }
     // Verify the layout is within allowed templates, that is Content Type 's default template OR Content Type allowed templates
     $allowed_tmpls = $typeParams->get('allowed_ilayouts');
     $type_default_layout = $typeParams->get('ilayout', 'default');
     if (empty($allowed_tmpls)) {
         $allowed_tmpls = array();
     } else {
         if (!is_array($allowed_tmpls)) {
             $allowed_tmpls = explode("|", $allowed_tmpls);
         }
     }
     // Verify the item layout is within templates: Content Type default template OR Content Type allowed templates
     if ($ilayout != $type_default_layout && count($allowed_tmpls) && !in_array($ilayout, $allowed_tmpls)) {
         $app->enqueueMessage("<small>Current item Layout (template) is '{$ilayout}':<br/>- This is neither the Content Type Default Template, nor does it belong to the Content Type allowed templates.<br/>- Please correct this in the URL or in Content Type configuration.<br/>- Using Content Type Default Template Layout: '{$type_default_layout}'</small>", 'notice');
         $ilayout = $type_default_layout;
     }
     // Get cached template data, without loading language file, (this will be done at the view)
     $themes = flexicontent_tmpl::getTemplates(null);
     // Verify the item layout exists
     if (!isset($themes->items->{$ilayout})) {
         $fixed_ilayout = isset($themes->items->{$type_default_layout}) ? $type_default_layout : 'default';
         $app->enqueueMessage("<small>Current Item Layout Template is '{$ilayout}' does not exist<br/>- Please correct this in the URL or in Content Type configuration.<br/>- Using Template Layout: '{$fixed_ilayout}'</small>", 'notice');
         $ilayout = $fixed_ilayout;
         FLEXIUtilities::loadTemplateLanguageFile($ilayout);
         // Manually load Template-Specific language file of back fall ilayout
     }
     // Finally set the ilayout (template name) into model / item's parameters / HTTP Request
     $this->setItemLayout($ilayout);
     $itemParams->set('ilayout', $ilayout);
     JRequest::setVar('ilayout', $ilayout);
 }
Exemplo n.º 11
0
 function fetchElement($name, $value, &$node, $control_name)
 {
     if (FLEXI_J16GE) {
         $node =& $this->element;
         $attributes = get_object_vars($node->attributes());
         $attributes = $attributes['@attributes'];
     } else {
         $attributes =& $node->_attributes;
     }
     $themes = flexicontent_tmpl::getTemplates();
     $tmpls_all = $themes->items ? $themes->items : array();
     $value = FLEXI_J16GE ? $this->value : $value;
     $view = JRequest::getVar('view');
     $controller = JRequest::getVar('controller');
     $app = JFactory::getApplication();
     $db = JFactory::getDBO();
     $cparams = JComponentHelper::getParams('com_flexicontent');
     // GET LIMITING to specific templates according to item's type, or according to type of new item
     $allowed_tmpls = array();
     $all_tmpl_allowed = true;
     $type_default_layout = '';
     $type_default_layout_mobile = '';
     if ($view == FLEXI_ITEMVIEW || $app->isAdmin() && 'items' == $controller) {
         // Get item id
         if (!$app->isAdmin()) {
             // FRONTEND, use "id" from request
             $pk = JRequest::getVar('id', 0, 'default', 'int');
         } else {
             // BACKEND, use "cid" array from request
             $cid = JRequest::getVar('cid', array(0), $hash = 'default', 'array');
             $pk = (int) $cid[0];
         }
         // Get type attibutes
         if ($pk) {
             $query = 'SELECT t.id as id, t.attribs attribs' . ' FROM #__flexicontent_items_ext as ie' . ' JOIN #__flexicontent_types as t ON ie.type_id=t.id' . ' WHERE ie.item_id = ' . (int) $pk;
         } else {
             $typeid = (int) JRequest::getInt('typeid', 0);
             $query = 'SELECT t.id,t.attribs' . ' FROM #__flexicontent_types as t' . ' WHERE t.id = ' . (int) $typeid;
         }
         $db->setQuery($query);
         $typedata = $db->loadObject();
         // Finally get allowed templates
         if ($typedata) {
             $tparams = FLEXI_J16GE ? new JRegistry($typedata->attribs) : new JParameter($typedata->attribs);
             $type_default_layout = $tparams->get('ilayout', 'default');
             $type_default_layout_mobile = $tparams->get('ilayout_mobile', JText::_('FLEXI_USE_DESKTOP'));
             $allowed_tmpls = $tparams->get('allowed_ilayouts');
             if (empty($allowed_tmpls)) {
                 $allowed_tmpls = array();
             } else {
                 if (!is_array($allowed_tmpls)) {
                     $allowed_tmpls = !FLEXI_J16GE ? array($allowed_tmpls) : explode("|", $allowed_tmpls);
                 }
             }
             $all_tmpl_allowed = count($allowed_tmpls) == 0;
             if (!in_array($type_default_layout, $allowed_tmpls)) {
                 $allowed_tmpls[] = $type_default_layout;
             }
             $use_mobile_layouts = $cparams->get('use_mobile_layouts', 0);
             if ($use_mobile_layouts && $type_default_layout_mobile) {
                 if (!in_array($type_default_layout_mobile, $allowed_tmpls)) {
                     $allowed_tmpls[] = $type_default_layout_mobile;
                 }
             }
             //echo "Allowed Templates: "; print_r($allowed_tmpls); echo "<br>\n";
         }
     }
     $tmpls = array();
     $lays = array();
     foreach ($tmpls_all as $tmpl) {
         if ($all_tmpl_allowed || in_array($tmpl->name, $allowed_tmpls)) {
             $tmpls[] = $tmpl;
             $lays[] = $tmpl->name;
         }
     }
     $lays = implode("','", $lays);
     if (@$attributes['enableparam']) {
         $cparams = JComponentHelper::getParams('com_flexicontent');
         if (!$cparams->get($attributes['enableparam'])) {
             return FLEXI_J16GE ? '' : JText::_('FLEXI_DISABLED');
         }
     }
     if (!@$attributes['skipparams']) {
         $doc = JFactory::getDocument();
         $js = "\nvar tmpl = ['" . $lays . "'];\t\n\nfunction disablePanel(element) {\n\tif ( ! \$('params-'+element) ) return;\n\t\n\tvar panel \t= \$('params-'+element).getNext();\n\tvar selects = panel.getElements('select');\n\tvar inputs \t= panel.getElements('input');\n\tpanel.getParent().addClass('pane-disabled');\n\tselects.each(function(el){\n\t\tel.setProperty('disabled', 'disabled');\n\t});\n\tinputs.each(function(el){\n\t\tel.setProperty('disabled', 'disabled');\n\t});\n\tpanel.getParent().setStyle('display','none');\n}\n\nfunction enablePanel(element) {\n\tif ( ! \$('params-'+element) ) return;\n\t\n\tvar panel \t= \$('params-'+element).getNext();\n\tvar selects = panel.getElements('select');\n\tvar inputs \t= panel.getElements('input');\n\tpanel.getParent().removeClass('pane-disabled');\n\tselects.each(function(el){\n    \tel.setProperty('disabled', '');\n\t});\n\tinputs.each(function(el){\n    \tel.setProperty('disabled', '');\n\t});\n\tpanel.getParent().setStyle('display','');\n}\n\nfunction activatePanel(active) {\n\tvar inactives = tmpl.filter(function(item, index){\n\t\treturn item != active;\n\t});\n\n\tinactives.each(function(el){\n\t\tdisablePanel(el);\n\t});\n\t\n\tif (active) {\n\t\tenablePanel(active);\n\t\tif ( \$('__content_type_default_layout__') ) \$('__content_type_default_layout__').setStyle('display','none');\n\t} else {\n\t\tif ( \$('__content_type_default_layout__') ) \$('__content_type_default_layout__').setStyle('display','');\n\t}\n}\nwindow.addEvent('domready', function() {\n\tactivatePanel('" . $value . "');\n});\n";
         $doc->addScriptDeclaration($js);
     }
     $layouts = array();
     if ($view != 'type') {
         $type_layout = $attributes['name'] == 'ilayout_mobile' ? $type_default_layout_mobile : $type_default_layout;
         $layouts[] = JHTMLSelect::option('', JText::_('FLEXI_TYPE_DEFAULT') . ' :: ' . $type_layout . ' ::');
     } else {
         if (@$attributes['firstoption']) {
             $layouts[] = JHTMLSelect::option('', JText::_($attributes['firstoption']));
         }
     }
     foreach ($tmpls as $tmpl) {
         $layouts[] = JHTMLSelect::option($tmpl->name, ':: ' . $tmpl->name . ' ::');
     }
     $fieldname = FLEXI_J16GE ? $this->name : $control_name . '[' . $name . ']';
     $element_id = FLEXI_J16GE ? $this->id : $control_name . $name;
     $attribs = !FLEXI_J16GE ? ' style="float:left;" ' : '';
     if (@$attributes['multiple'] == 'multiple' || @$attributes['multiple'] == 'true') {
         $attribs .= ' multiple="multiple" ';
         $attribs .= @$attributes['size'] ? ' size="' . @$attributes['size'] . '" ' : ' size="6" ';
         $fieldname .= !FLEXI_J16GE ? "[]" : "";
         // NOTE: this added automatically in J2.5
     }
     if (@$attributes['class']) {
         $attribs .= 'class="' . $attributes['class'] . '"';
     }
     if (!@$attributes['skipparams']) {
         $attribs .= ' onchange="activatePanel(this.value);"';
     }
     return JHTML::_('select.genericlist', $layouts, $fieldname, $attribs, 'value', 'text', $value, $element_id);
 }
Exemplo n.º 12
0
    /**
     * Creates the Entrypage
     *
     * @since 1.0
     */
    function display($tpl = null)
    {
        $app = JFactory::getApplication();
        $config = JFactory::getConfig();
        $params = JComponentHelper::getParams('com_flexicontent');
        $document = JFactory::getDocument();
        $session = JFactory::getSession();
        $user = JFactory::getUser();
        $db = JFactory::getDBO();
        $print_logging_info = $params->get('print_logging_info');
        // Special displaying when getting flexicontent version
        $layout = JRequest::getVar('layout', 'default');
        if ($layout == 'fversion') {
            $this->fversion($tpl, $params);
            return;
        }
        // Load the file system librairies
        jimport('joomla.filesystem.folder');
        jimport('joomla.filesystem.file');
        // activate the tooltips
        //JHTML::_('behavior.tooltip');
        // handle jcomments integration
        if (JPluginHelper::isEnabled('system', 'jcomments')) {
            $JComments_Installed = 1;
            $destpath = JPATH_SITE . DS . 'components' . DS . 'com_jcomments' . DS . 'plugins';
            $dest = $destpath . DS . 'com_flexicontent.plugin.php';
            $source = JPATH_SITE . DS . 'components' . DS . 'com_flexicontent' . DS . 'librairies' . DS . 'jcomments' . DS . 'com_flexicontent.plugin.php';
            if (!JFile::exists($dest)) {
                if (!JFolder::exists($destpath)) {
                    if (!JFolder::create($destpath)) {
                        JError::raiseWarning(100, JText::_('FLEXIcontent: Unable to create jComments plugin folder'));
                    }
                }
                if (!JFile::copy($source, $dest)) {
                    JError::raiseWarning(100, JText::_('FLEXIcontent: Unable to copy jComments plugin'));
                } else {
                    $app->enqueueMessage(JText::_('Copied FLEXIcontent jComments plugin'));
                }
            }
        } else {
            $JComments_Installed = 0;
        }
        // handle joomfish integration
        if (JPluginHelper::isEnabled('system', 'jfdatabase')) {
            $files = new stdClass();
            $files->fields = new stdClass();
            $files->files = new stdClass();
            $files->tags = new stdClass();
            $files->fields->dest = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomfish' . DS . 'contentelements' . DS . 'flexicontent_fields.xml';
            $files->fields->source = JPATH_SITE . DS . 'components' . DS . 'com_flexicontent' . DS . 'librairies' . DS . 'joomfish' . DS . 'flexicontent_fields.xml';
            $files->files->dest = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomfish' . DS . 'contentelements' . DS . 'flexicontent_files.xml';
            $files->files->source = JPATH_SITE . DS . 'components' . DS . 'com_flexicontent' . DS . 'librairies' . DS . 'joomfish' . DS . 'flexicontent_files.xml';
            $files->tags->dest = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomfish' . DS . 'contentelements' . DS . 'flexicontent_tags.xml';
            $files->tags->source = JPATH_SITE . DS . 'components' . DS . 'com_flexicontent' . DS . 'librairies' . DS . 'joomfish' . DS . 'flexicontent_tags.xml';
            foreach ($files as $file) {
                if (!JFile::exists($file->dest)) {
                    JFile::copy($file->source, $file->dest);
                }
            }
        }
        // Get model
        $model = $this->getModel('flexicontent');
        // initialise template related variables
        if (!FLEXI_J16GE) {
            $pane = JPane::getInstance('sliders');
        }
        $template = $app->getTemplate();
        $themes = flexicontent_tmpl::getThemes();
        // Get data from the model
        if ($print_logging_info) {
            global $fc_run_times;
        }
        if ($print_logging_info) {
            $start_microtime = microtime(true);
        }
        $totalrows = array();
        $_total = 0;
        $draft = $model->getDraft($_total);
        $totalrows['draft'] = $_total;
        $pending = $model->getPending($_total);
        $totalrows['pending'] = $_total;
        $revised = $model->getRevised($_total);
        $totalrows['revised'] = $_total;
        $inprogress = $model->getInprogress($_total);
        $totalrows['inprogress'] = $_total;
        if ($print_logging_info) {
            $fc_run_times['quick_sliders'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
        }
        // 1. CHECK REQUIRED NON-AUTOMATIC TASKs
        //  THEY ARE TASKs THAT USER MUST COMPLETE MANUALLY
        $existcat = $model->getExistcat();
        if (!FLEXI_J16GE) {
            $existsec = $model->getExistsec();
        }
        $existmenu = $model->getExistmenu();
        // 2. OPTIONAL AUTOMATIC TASKS,
        //  THESE ARE SEPARETELY CHECKED, AS THEY ARE NOT OBLIGATORY BUT RATHER RECOMMENDED
        $allplgpublish = $session->get('flexicontent.allplgpublish');
        if ($allplgpublish === NULL || $allplgpublish === false) {
            $allplgpublish = $model->getAllPluginsPublished();
        }
        $optional_tasks = !$allplgpublish;
        // || ..
        // 3. OBLIGATORY AUTOMATIC TASKS, THAT WILL BLOCK COMPONENT USE UNTIL THEY ARE COMPLETED
        $postinst_integrity_ok = $session->get('flexicontent.postinstall');
        // THE FOLLOWING WILL ONLY BE DISPLAYED IF $DOPOSTINSTALL IS INCOMPLETE
        // SO WHY CALCULATE THEM, WE SKIP THEM, USER MUST LOG OUT ANYWAY TO SEE THEM ...
        if ($postinst_integrity_ok === NULL || $postinst_integrity_ok === false) {
            $use_versioning = $params->get('use_versioning', 1);
            $existtype = $model->getExistType();
            $existmenuitems = $model->getExistMenuItems();
            $existfields = $model->getExistFields();
            $existfplg = $model->getExistFieldsPlugins();
            $existseplg = $model->getExistSearchPlugin();
            $existsyplg = $model->getExistSystemPlugin();
            $existcats = !$model->getItemsNoCat();
            $existlang = $model->getExistLanguageColumns() && !$model->getItemsNoLang();
            $existversions = $model->getExistVersionsTable();
            $existversionsdata = !$use_versioning || $model->getExistVersionsPopulated();
            $existauthors = $model->getExistAuthorsTable();
            $deprecatedfiles = $model->getDeprecatedFiles();
            $nooldfieldsdata = $model->getNoOldFieldsData();
            $missingversion = true;
            //!$use_versioning || !$model->checkCurrentVersionData();
            $cachethumb = $model->getCacheThumbChmod();
            $existdbindexes = !(bool) ($missingindexes = $model->getExistDBindexes($check_only = false));
            $itemcountingdok = $model->getItemCountingDataOK();
            $initialpermission = $model->checkInitialPermission();
        } else {
            if ($optional_tasks) {
                // IF optional tasks do not recheck instead just set the FLAGS to true
                $existtype = $existmenuitems = $existfields = true;
                $existfplg = $existseplg = $existsyplg = true;
                $existcats = $existlang = $existversions = $existversionsdata = $existauthors = true;
                $deprecatedfiles = $nooldfieldsdata = $missingversion = $cachethumb = true;
                $existdbindexes = $itemcountingdok = $initialpermission = true;
                $missingindexes = array();
            }
        }
        // **************************
        // Add css and js 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);
        $css = '.install-ok { background: url(components/com_flexicontent/assets/images/accept.png) 0% 50% no-repeat transparent; padding:1px 0; width: 20px; height:16px; display:block; }
				 .install-notok { background: url(components/com_flexicontent/assets/images/delete.png) 0% 50% no-repeat transparent; padding:1px 0; width: 20px; height:16px; display:block; float:left;}';
        $document->addStyleDeclaration($css);
        // *****************************
        // Get user's global permissions
        // *****************************
        $perms = FlexicontentHelperPerm::getPerm();
        // ************************
        // Create Submenu & Toolbar
        // ************************
        // Create Submenu (and also check access to current view)
        FLEXISubmenu('notvariable');
        // Create document/toolbar titles
        $doc_title = JText::_('FLEXI_DASHBOARD');
        $site_title = $document->getTitle();
        JToolBarHelper::title($doc_title, 'flexicontent');
        $document->setTitle($doc_title . ' - ' . $site_title);
        // Create the toolbar
        if (version_compare(PHP_VERSION, '5.0.0', '>')) {
            $js = "jQuery(document).ready(function(){";
            if ($perms->CanConfig) {
                $toolbar = JToolBar::getInstance('toolbar');
                $btn_task = '';
                $popup_load_url = JURI::base() . 'index.php?option=com_flexicontent&layout=import&tmpl=component';
                if (!FLEXI_J16GE) {
                    $js .= "\n\t\t\t\t\t\tjQuery('#toolbar-download a.toolbar, #toolbar-download button')\n\t\t\t\t\t\t\t.attr('onclick', 'javascript:;')\n\t\t\t\t\t\t\t.attr('href', '" . $popup_load_url . "')\n\t\t\t\t\t\t\t.attr('rel', '{handler: \\'iframe\\', size: {x: 800, y: 500}, onClose: function() {}}');\n\t\t\t\t\t";
                    JToolBarHelper::custom($btn_task, 'download.png', 'download_f2.png', 'FLEXI_IMPORT_JOOMLA', false);
                    JHtml::_('behavior.modal', '#toolbar-download a.toolbar, #toolbar-download button');
                } else {
                    //$toolbar->appendButton('Popup', 'download', JText::_('FLEXI_IMPORT_JOOMLA'), str_replace('&', '&amp;', $popup_load_url), 400, 300);
                }
                /*$btn_task = '';
                		$popup_load_url = JURI::base().'index.php?option=com_flexicontent&layout=language&tmpl=component';
                		if (FLEXI_J16GE) {
                			$js .= "
                				jQuery('#toolbar-language a.toolbar, #toolbar-language button')
                					.attr('onclick', 'javascript:;')
                					.attr('href', '".$popup_load_url."')
                					.attr('rel', '{handler: \'iframe\', size: {x: 800, y: 500}, onClose: function() {}}');
                			";
                			JToolBarHelper::custom( $btn_task, 'language.png', 'language_f2.png', 'FLEXI_SEND_LANGUAGE', false );
                			JHtml::_('behavior.modal', '#toolbar-language a.toolbar, #toolbar-language button');
                		} else {
                			$toolbar->appendButton('Popup', 'language', JText::_('FLEXI_SEND_LANGUAGE'), str_replace('&', '&amp;', $popup_load_url), 800, 500);
                		}*/
                $session = JFactory::getSession();
                $fc_screen_width = (int) $session->get('fc_screen_width', 0, 'flexicontent');
                $_width = $fc_screen_width && $fc_screen_width - 84 > 940 ? $fc_screen_width - 84 > 1400 ? 1400 : $fc_screen_width - 84 : 940;
                $fc_screen_height = (int) $session->get('fc_screen_height', 0, 'flexicontent');
                $_height = $fc_screen_height && $fc_screen_height - 128 > 550 ? $fc_screen_height - 128 > 1000 ? 1000 : $fc_screen_height - 128 : 550;
                JToolBarHelper::preferences('com_flexicontent', $_height, $_width, 'Configuration');
            }
            $js .= "});";
            $document->addScriptDeclaration($js);
        }
        // Lists
        jimport('joomla.filesystem.folder');
        $lists = array();
        $options = array();
        $folder = JPATH_ADMINISTRATOR . DS . 'language';
        $langs = JFolder::folders($folder);
        $activelang = JComponentHelper::getParams('com_languages')->get('administrator', 'en-GB');
        foreach ($langs as $lang) {
            $options[] = JHTML::_('select.option', $lang, $lang);
        }
        $lists['languages'] = JHTML::_('select.genericlist', $options, 'lang', '', 'value', 'text', $activelang);
        // Missing files
        $lists['missing_lang'] = $model->processlanguagefiles();
        // Get the default copyright values to populate the form automatically
        $mailfrom = $app->getCfg('mailfrom');
        $fromname = $app->getCfg('fromname');
        $website = $app->getCfg('live_site');
        $this->assignRef('pending', $pending);
        $this->assignRef('revised', $revised);
        $this->assignRef('draft', $draft);
        $this->assignRef('inprogress', $inprogress);
        $this->assignRef('totalrows', $totalrows);
        $this->assignRef('existcat', $existcat);
        if (!FLEXI_J16GE) {
            $this->assignRef('existsec', $existsec);
        }
        $this->assignRef('existmenu', $existmenu);
        $this->assignRef('template', $template);
        $this->assignRef('params', $params);
        $this->assignRef('lists', $lists);
        $this->assignRef('activelang', $activelang);
        $this->assignRef('mailfrom', $mailfrom);
        $this->assignRef('fromname', $fromname);
        $this->assignRef('website', $website);
        // install check
        $this->assignRef('dopostinstall', $postinst_integrity_ok);
        $this->assignRef('allplgpublish', $allplgpublish);
        $this->assignRef('existtype', $existtype);
        $this->assignRef('existmenuitems', $existmenuitems);
        $this->assignRef('existfields', $existfields);
        $this->assignRef('existfplg', $existfplg);
        $this->assignRef('existseplg', $existseplg);
        $this->assignRef('existsyplg', $existsyplg);
        $this->assignRef('existcats', $existcats);
        $this->assignRef('existlang', $existlang);
        $this->assignRef('existversions', $existversions);
        $this->assignRef('existversionsdata', $existversionsdata);
        $this->assignRef('existauthors', $existauthors);
        $this->assignRef('deprecatedfiles', $deprecatedfiles);
        $this->assignRef('nooldfieldsdata', $nooldfieldsdata);
        $this->assignRef('missingversion', $missingversion);
        $this->assignRef('cachethumb', $cachethumb);
        $this->assignRef('existdbindexes', $existdbindexes);
        $this->assignRef('missingindexes', $missingindexes);
        $this->assignRef('itemcountingdok', $itemcountingdok);
        $this->assignRef('initialpermission', $initialpermission);
        // assign Rights to the template
        $this->assignRef('perms', $perms);
        $this->assignRef('document', $document);
        $this->sidebar = FLEXI_J30GE ? JHtmlSidebar::render() : null;
        parent::display($tpl);
    }
Exemplo n.º 13
0
 /**
  * Method to get the layout parameters of an item
  * 
  * @return string
  * @since 1.5
  */
 function getLayoutparams($force = false)
 {
     return $this->_clayout ? flexicontent_tmpl::getLayoutparams('category', $this->_clayout, $force) : '';
 }
Exemplo n.º 14
0
 function display($tpl = null)
 {
     global $mainframe;
     //initialise variables
     $document = JFactory::getDocument();
     $db = JFactory::getDBO();
     $me = JFactory::getUser();
     $cid = JRequest::getVar('cid', array(0), '', 'array');
     JArrayHelper::toInteger($cid, array(0));
     $edit = JRequest::getVar('edit', true);
     if (!$cid) {
         $edit = false;
     }
     if (FLEXI_J16GE) {
         $form = $this->get('Form');
         $form->setValue('password', null);
         $form->setValue('password2', null);
     }
     $form_folder = FLEXI_J16GE ? 'forms' . DS : '';
     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');
     // load language file for com_users component
     JFactory::getLanguage()->load('com_users', JPATH_ADMINISTRATOR, 'en-GB', true);
     JFactory::getLanguage()->load('com_users', JPATH_ADMINISTRATOR, null, true);
     //create the toolbar
     if ($edit) {
         JToolBarHelper::title(JText::_('FLEXI_EDIT_AUTHOR'), 'authoredit');
     } else {
         JToolBarHelper::title(JText::_('FLEXI_ADD_AUTHOR'), 'authoradd');
     }
     $ctrl = FLEXI_J16GE ? 'users.' : '';
     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');
     JToolBarHelper::help('screen.users.edit');
     $user = $edit ? JUser::getInstance($cid[0]) : JUser::getInstance();
     $myuser = JFactory::getUser();
     $acl = JFactory::getACL();
     // Check for post data in the event that we are returning
     // from a unsuccessful attempt to save data
     $post = JRequest::get('post');
     if ($post) {
         $user->bind($post);
     }
     if ($user->get('id')) {
         $query = 'SELECT *' . ' FROM #__contact_details' . ' WHERE user_id = ' . (int) $cid[0];
         $db->setQuery($query);
         $contact = $db->loadObjectList();
     } else {
         $contact = NULL;
         // Get the default group id for a new user
         $config = JComponentHelper::getParams('com_users');
         $newGrp = $config->get('new_usertype');
         if (!FLEXI_J16GE) {
             $user->set('gid', $acl->get_group_id($newGrp, null, 'ARO'));
         } else {
             $user->set('gid', $newGrp);
         }
     }
     // **************************************************
     // Include needed files and add needed js / css files
     // **************************************************
     // Load pane behavior
     jimport('joomla.html.pane');
     // Load tooltips
     FLEXI_J30GE ? JHtml::_('behavior.framework', true) : JHTML::_('behavior.mootools');
     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('components/com_flexicontent/assets/js/admin.js');
     $document->addScript('components/com_flexicontent/assets/js/validate.js');
     // ********************
     // Initialise variables
     // ********************
     $cparams = JComponentHelper::getParams('com_flexicontent');
     if (!FLEXI_J16GE) {
         $pane = JPane::getInstance('sliders');
         $tpane = JPane::getInstance('tabs', array('startOffset' => 2, 'allowAllClose' => true, 'opacityTransition' => true, 'duration' => 600));
     }
     // *************************************************************************************************
     // Get author extended data, basic (described in author.xml) and category (described incategory.xml)
     // *************************************************************************************************
     JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_flexicontent' . DS . 'tables');
     $author_user_id = (int) $cid[0];
     $flexiauthor_extdata = JTable::getInstance('flexicontent_authors_ext', '');
     $flexiauthor_extdata->load($author_user_id);
     //echo "<pre>"; print_r($flexiauthor_extdata); echo "</pre>"; exit;
     // ***********************
     // AUTHOR basic parameters
     // ***********************
     // Load the DB parameter values and the XML description from file,
     // NOTE: this is one step for J1.5 via a JParameter object, but in J1.6+ the use of XML file
     // in JParameter is deprecated, instead we will JForm to load XML description and thus be able to render it
     $auth_xml = JPATH_COMPONENT . DS . 'models' . DS . $form_folder . 'author.xml';
     if (FLEXI_J16GE) {
         $params_authorbasic = new JRegistry($flexiauthor_extdata->author_basicparams);
     } else {
         $params_authorbasic = new JParameter($flexiauthor_extdata->author_basicparams, $auth_xml);
     }
     //echo "<pre>"; print_r($params_authorbasic); echo "</pre>"; exit;
     if (FLEXI_J16GE) {
         // Read XML file
         $xml_string = str_replace('name="params"', 'name="authorbasicparams"', file_get_contents($auth_xml));
         // Load the form description from the XML string
         $jform_authorbasic = new JForm('com_flexicontent.author', array('control' => 'jform', 'load_data' => true));
         $jform_authorbasic->load($xml_string, $isFile = false);
         // Set DB parameter values into the JForm object
         foreach ($jform_authorbasic->getFieldset() as $fsetname => $field) {
             $jform_authorbasic->setValue($field->fieldname, $group = 'authorbasicparams', $value = $params_authorbasic->get($field->fieldname));
         }
     }
     // **************************
     // AUTHOR category parameters
     // **************************
     // Load the DB parameter values and the XML description from file,
     // NOTE: this is one step for J1.5 via a JParameter object, but in J1.6+ the use of XML file
     // in JParameter is deprecated, instead we will JForm to load XML description and thus be able to render it
     $cat_xml = JPATH_COMPONENT . DS . 'models' . DS . $form_folder . 'category.xml';
     if (FLEXI_J16GE) {
         $params_authorcat = new JRegistry($flexiauthor_extdata->author_catparams);
     } else {
         $params_authorcat = new JParameter($flexiauthor_extdata->author_catparams, $cat_xml);
     }
     //echo "<pre>"; print_r($params_authorcat); echo "</pre>"; exit;
     if (FLEXI_J16GE) {
         // Read XML file
         $xml_string = str_replace('name="params"', 'name="authorcatparams"', file_get_contents($cat_xml));
         // Load the form description from the XML string
         $jform_authorcat = new JForm('com_flexicontent.category', array('control' => 'jform', 'load_data' => true));
         $jform_authorcat->load($xml_string, $isFile = false);
         // Set DB parameter values into the JForm object
         foreach ($jform_authorcat->getFieldset() as $fsetname => $field) {
             $jform_authorcat->setValue($field->fieldname, $group = 'authorcatparams', $value = $params_authorcat->get($field->fieldname));
         }
     }
     // **********************************************************************************
     // Get Templates and apply Template Parameters values into the form fields structures
     // **********************************************************************************
     $themes = flexicontent_tmpl::getTemplates();
     $tmpls = $themes->category;
     if (FLEXI_J16GE) {
         $params_author = new JRegistry($user->params);
     }
     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($flexiauthor_extdata->author_catparams);
         }
     }
     //$lists = array();
     //$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', $flexiauthor_extdata->image, $javascript, '/images/stories/' );
     if (!FLEXI_J16GE) {
         $userObjectID = $acl->get_object_id('users', $user->get('id'), 'ARO');
         $userGroups = $acl->get_object_groups($userObjectID, 'ARO');
         $userGroupName = strtolower($acl->get_group_name($userGroups[0], 'ARO'));
         $userIsAdmin = $userGroupName == 'administrator';
         $myObjectID = $acl->get_object_id('users', $myuser->get('id'), 'ARO');
         $myGroups = $acl->get_object_groups($myObjectID, 'ARO');
         $myGroupName = strtolower($acl->get_group_name($myGroups[0], 'ARO'));
         $myIsAdmin = $myGroupName == 'administrator';
     } else {
     }
     // ensure user can't add/edit group higher than themselves
     /* NOTE : This check doesn't work commented out for the time being
     		if ( is_array( $myGroups ) && count( $myGroups ) > 0 )
     		{
     			$excludeGroups = (array) $acl->get_group_children( $myGroups[0], 'ARO', 'RECURSE' );
     		}
     		else
     		{
     			$excludeGroups = array();
     		}
     
     		if ( in_array( $userGroups[0], $excludeGroups ) )
     		{
     			echo 'not auth';
     			$mainframe->redirect( 'index.php?option=com_flexicontent&amp;controller=users&amp;view=users', JText::_('NOT_AUTH') );
     		}
     		*/
     /*
     if ( $userGroupName == 'super administrator' )
     {
     	// super administrators can't change
     	 		$lists['gid'] = '<input type="hidden" name="gid" value="'. $currentUser->gid .'" /><strong>'. JText::_( 'Super Administrator' ) .'</strong>';
     }
     else if ( $userGroupName == $myGroupName && $myGroupName == 'administrator' ) {
     */
     if (FLEXI_ACCESS) {
         // Create the list of all groups except public and registered
         $query = 'SELECT id AS value, name AS text, level, ordering' . ' FROM #__flexiaccess_groups' . ' WHERE level > 1' . ' ORDER BY ordering ASC';
         $db->setQuery($query);
         $allgroups = $db->loadObjectList();
         if ($user->get('id')) {
             // get all the groups from the user
             $query = 'SELECT group_id' . ' FROM #__flexiaccess_members' . ' WHERE member_id = ' . (int) $cid[0];
             $db->setQuery($query);
             $usergroups = FLEXI_J16GE ? $db->loadColumn() : $db->loadResultArray();
         } else {
             $usergroups = array();
         }
         $lists['access'] = JHTML::_('select.genericlist', $allgroups, 'groups[]', 'size="10" multiple="multiple"', 'value', 'text', $usergroups);
     }
     if (!FLEXI_J16GE) {
         if ($userIsAdmin && $myIsAdmin) {
             // administrators can't change each other
             $lists['gid'] = '<input type="hidden" name="gid" value="' . $user->get('gid') . '" /><strong>' . JText::_('Administrator') . '</strong>';
         } else {
             $gtree = $acl->get_group_children_tree(null, 'USERS', false);
             // remove users 'above' me
             //$i = 0;
             //while ($i < count( $gtree )) {
             //	if ( in_array( $gtree[$i]->value, (array)$excludeGroups ) ) {
             //		array_splice( $gtree, $i, 1 );
             //	} else {
             //		$i++;
             //	}
             //}
             $lists['gid'] = JHTML::_('select.genericlist', $gtree, 'gid', 'size="10"', 'value', 'text', $user->get('gid'));
         }
     } else {
         if (!$user->get('id')) {
             $new_usertype = JComponentHelper::getParams('com_users')->get('new_usertype');
             $usergroups = $new_usertype ? array($new_usertype) : array();
         } else {
             $ugrps_qtmpl = 'SELECT group_id FROM #__user_usergroup_map AS ug WHERE ug.user_id = %d';
             $query = sprintf($ugrps_qtmpl, intval($user->get('id')));
             $db->setQuery($query);
             $usergroups = FLEXI_J16GE ? $db->loadColumn() : $db->loadResultArray();
             if ($db->getErrorMsg()) {
                 echo $db->getErrorMsg();
             }
         }
     }
     // build the html select list
     $lists['block'] = JHTML::_('select.booleanlist', 'block', 'class="inputbox" size="1"', $user->get('block'));
     // build the html select list
     $lists['sendEmail'] = JHTML::_('select.booleanlist', 'sendEmail', 'class="inputbox" size="1"', $user->get('sendEmail'));
     $this->assignRef('me', $me);
     $this->assignRef('document', $document);
     $this->assignRef('lists', $lists);
     if (!FLEXI_J16GE) {
         $this->assignRef('pane', $pane);
         $this->assignRef('tpane', $tpane);
     }
     $this->assignRef('user', $user);
     $this->assignRef('usergroups', $usergroups);
     $this->assignRef('contact', $contact);
     $this->assignRef('cparams', $cparams);
     $this->assignRef('params_authorbasic', $params_authorbasic);
     $this->assignRef('params_authorcat', $params_authorcat);
     if (FLEXI_J16GE) {
         $this->assignRef('jform_authorbasic', $jform_authorbasic);
         $this->assignRef('jform_authorcat', $jform_authorcat);
     }
     $this->assignRef('tmpls', $tmpls);
     if (FLEXI_J16GE) {
         $this->assignRef('form', $form);
         $this->assignRef('params_author', $params_author);
     }
     parent::display($tpl);
 }
 static function getTemplates($lang_files = 'all')
 {
     static $tmpls = null;
     if ($tmpls !== null) {
         return $tmpls;
     }
     $flexiparams = JComponentHelper::getParams('com_flexicontent');
     $print_logging_info = $flexiparams->get('print_logging_info');
     $debug = JDEBUG || $print_logging_info;
     // Log content plugin and other performance information
     if ($print_logging_info) {
         global $fc_run_times;
         $start_microtime = microtime(true);
     }
     $apply_cache = FLEXI_CACHE;
     if ($apply_cache) {
         // Get templates from cache
         $tmplcache = JFactory::getCache('com_flexicontent_tmpl');
         // Get Joomla Cache of '...tmpl' Caching Group
         $tmplcache->setCaching(1);
         // Force cache ON
         $tmplcache->setLifeTime(FLEXI_CACHE_TIME);
         // Set expire time (default is 1 hour)
         $tmpls = $tmplcache->call(array('flexicontent_tmpl', 'parseTemplates'));
         // Check, clean, update cache if needed
         $xml_modified = flexicontent_tmpl::checkXmlModified($tmpls);
         if (!empty($xml_modified)) {
             if ($debug) {
                 JFactory::getApplication()->enqueueMessage("Re-reading XMLs, XML file modified: " . print_r($xml_modified, true), 'message');
             }
             $tmplcache->clean();
             $tmplcache->gc();
             $tmpls = $tmplcache->call(array('flexicontent_tmpl', 'parseTemplates'));
         }
     } else {
         $tmpls = flexicontent_tmpl::parseTemplates();
     }
     // Compile LESS to CSS, if files have been modified
     flexicontent_tmpl::checkCompileLess($tmpls);
     // Load Template-Specific language file(s) to override or add new language strings
     if ($lang_files == 'all') {
         foreach ($tmpls->category as $tmpl => $d) {
             FLEXIUtilities::loadTemplateLanguageFile($tmpl);
         }
     } else {
         if (is_array($lang_files)) {
             foreach ($lang_files as $tmpl) {
                 FLEXIUtilities::loadTemplateLanguageFile($tmpl);
             }
         } else {
             if (is_string($lang_files)) {
                 FLEXIUtilities::loadTemplateLanguageFile($lang_files);
             }
         }
     }
     if ($print_logging_info) {
         $fc_run_times[$apply_cache ? 'templates_parsing_cached' : 'templates_parsing_noncached'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
     }
     return $tmpls;
 }
Exemplo n.º 16
0
 /**
  * Helper method to bind form posted item parameters and and metadata to the item
  * 
  * @return object
  * @since 1.5
  */
 function mergeAttributes(&$item, &$params, &$metadata)
 {
     // Build item parameters INI string
     if (is_array($params)) {
         $item->attribs = FLEXI_J16GE ? new JRegistry($item->attribs) : new JParameter($item->attribs);
         $new_ilayout = isset($params['ilayout']) ? $params['ilayout'] : null;
         // a non-set will return null, but let's make this cleaner
         $old_ilayout = $item->attribs->get('ilayout');
         //echo "new_ilayout: $new_ilayout,  old_ilayout: $old_ilayout <br/>";
         //echo "<pre>"; print_r($params); exit;
         if ($new_ilayout !== null && $new_ilayout == '' || $new_ilayout != '' && $new_ilayout != $old_ilayout) {
             $themes = flexicontent_tmpl::getTemplates();
             foreach ($themes->items as $tmpl_name => $tmpl) {
                 //if ( $tmpl_name == @$params['ilayout'] ) continue;
                 $tmpl_params = $tmpl->params;
                 if (FLEXI_J16GE) {
                     $jform = new JForm('com_flexicontent.template.item', array('control' => 'jform', 'load_data' => true));
                     $jform->load($tmpl_params);
                     foreach ($jform->getGroup('attribs') as $p) {
                         if (!empty($p->fieldname)) {
                             $item->attribs->set($p->fieldname, null);
                         }
                     }
                 } else {
                     if (!empty($tmpl_params->_xml['_default'])) {
                         foreach ($tmpl_params->_xml['_default']->children() as $p) {
                             if (!empty($p->_attributes['name'])) {
                                 $item->attribs->set($p->_attributes['name'], null);
                             }
                         }
                     }
                 }
             }
         }
         if (isset($params['layouts'])) {
             if (isset($params['layouts'][$new_ilayout])) {
                 foreach ($params['layouts'][$new_ilayout] as $k => $v) {
                     //echo "$k: $v <br/>";
                     $item->attribs->set($k, $v);
                 }
             }
             unset($params['layouts']);
         }
         foreach ($params as $k => $v) {
             //$v = is_array($v) ? implode('|', $v) : $v;
             $item->attribs->set($k, $v);
         }
         //echo "<pre>"; print_r($params); print_r($item->attribs); exit;
         $item->attribs = $item->attribs->toString();
     }
     // Build item metadata INI string
     if (is_array($metadata)) {
         $item->metadata = FLEXI_J16GE ? new JRegistry($item->metadata) : new JParameter($item->metadata);
         foreach ($metadata as $k => $v) {
             if ($k == 'description' && !FLEXI_J16GE) {
                 // is jform field in J1.6+
                 $item->metadesc = $v;
             } elseif ($k == 'keywords' && !FLEXI_J16GE) {
                 // is jform field in J1.6+
                 $item->metakey = $v;
             } else {
                 $item->metadata->set($k, $v);
             }
         }
         $item->metadata = $item->metadata->toString();
     }
 }
Exemplo n.º 17
0
 /**
  * Creates the page's display
  *
  * @since 1.0
  */
 function display($tpl = null)
 {
     // Get Non-routing Categories, and Category Tree
     global $globalnoroute, $globalcats;
     if (!is_array($globalnoroute)) {
         $globalnoroute = array();
     }
     //initialize variables
     $dispatcher = JDispatcher::getInstance();
     $app = JFactory::getApplication();
     $session = JFactory::getSession();
     $option = JRequest::getVar('option');
     $format = JRequest::getCmd('format', 'html');
     $document = JFactory::getDocument();
     // Check for Joomla issue with system plugins creating JDocument in early events forcing it to be wrong type, when format as url suffix is enabled
     if ($format && $document->getType() != strtolower($format)) {
         echo '<div class="alert">WARNING: &nbsp; Document format should be: <b>' . $format . '</b> but current document is: <b>' . $document->getType() . '</b> <br/>Some system plugin may have forced current document type</div>';
     }
     $menus = $app->getMenu();
     $menu = $menus->getActive();
     $uri = JFactory::getURI();
     $user = JFactory::getUser();
     $aid = JAccess::getAuthorisedViewLevels($user->id);
     // Get model
     $model = $this->getModel();
     // Get category and set category parameters as VIEW's parameters (category parameters are merged with component/page/author parameters already)
     $category = $this->get('Category');
     $params = $category->parameters;
     if ($category->id) {
         $meta_params = new JRegistry($category->metadata);
     }
     // Get various data from the model
     $categories = $this->get('Childs');
     // this will also count sub-category items is if  'show_itemcount'  is enabled
     $peercats = $this->get('Peers');
     // this will also count sub-category items is if  'show_subcatcount_peercat'  is enabled
     $items = $this->get('Data');
     $total = $this->get('Total');
     $filters = $this->get('Filters');
     if ($params->get('show_comments_count', 0)) {
         $comments = $this->get('CommentsInfo');
     } else {
         $comments = null;
     }
     $alpha = $params->get('show_alpha', 1) ? $this->get('Alphaindex') : array();
     // This is somwhat expensive so calculate it only if required
     // Request variables, WARNING, must be loaded after retrieving items, because limitstart may have been modified
     $limitstart = JRequest::getInt('limitstart');
     // ********************************
     // Load needed JS libs & CSS styles
     // ********************************
     FLEXI_J30GE ? JHtml::_('behavior.framework', true) : JHTML::_('behavior.mootools');
     flexicontent_html::loadFramework('jQuery');
     flexicontent_html::loadFramework('flexi_tmpl_common');
     // Add css files to the document <head> section (also load CSS joomla template override)
     if (!$params->get('disablecss', '')) {
         $document->addStyleSheetVersion($this->baseurl . '/components/com_flexicontent/assets/css/flexicontent.css', FLEXI_VHASH);
         //$document->addCustomTag('<!--[if IE]><style type="text/css">.floattext {zoom:1;}</style><![endif]-->');
     }
     if (file_exists(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'css' . DS . 'flexicontent.css')) {
         $document->addStyleSheetVersion($this->baseurl . '/templates/' . $app->getTemplate() . '/css/flexicontent.css', FLEXI_VHASH);
     }
     // ************************
     // CATEGORY LAYOUT handling
     // ************************
     // (a) Decide to use mobile or normal category template layout
     $useMobile = $params->get('use_mobile_layouts', 0);
     if ($useMobile) {
         $force_desktop_layout = $params->get('force_desktop_layout', 0);
         $mobileDetector = flexicontent_html::getMobileDetector();
         $isMobile = $mobileDetector->isMobile();
         $isTablet = $mobileDetector->isTablet();
         $useMobile = $force_desktop_layout ? $isMobile && !$isTablet : $isMobile;
     }
     $_clayout = $useMobile ? 'clayout_mobile' : 'clayout';
     // (b) Get from category parameters, allowing URL override
     $clayout = JRequest::getCmd($_clayout, false);
     if (!$clayout) {
         $desktop_clayout = $params->get('clayout', 'blog');
         $clayout = !$useMobile ? $desktop_clayout : $params->get('clayout_mobile', $desktop_clayout);
     }
     // (c) Get cached template data
     $themes = flexicontent_tmpl::getTemplates($lang_files = array($clayout));
     // (d) Verify the category layout exists
     if (!isset($themes->category->{$clayout})) {
         $fixed_clayout = 'blog';
         $app->enqueueMessage("<small>Current Category Layout Template is '{$clayout}' does not exist<br>- Please correct this in the URL or in Content Type configuration.<br>- Using Template Layout: '{$fixed_clayout}'</small>", 'notice');
         $clayout = $fixed_clayout;
         FLEXIUtilities::loadTemplateLanguageFile($clayout);
         // Manually load Template-Specific language file of back fall clayout
     }
     // (e) finally set the template name back into the category's parameters
     $params->set('clayout', $clayout);
     // Get URL variables
     $layout_vars = flexicontent_html::getCatViewLayoutVars($model);
     $layout = $layout_vars['layout'];
     $authorid = $layout_vars['authorid'];
     $tagid = $layout_vars['tagid'];
     $cids = $layout_vars['cids'];
     $cid = $layout_vars['cid'];
     // Get Tag data if current layout is 'tags'
     if ($tagid) {
         $tag = $this->get('Tag');
     }
     $authordescr_item = false;
     if ($authorid && $params->get('authordescr_itemid') && $format != 'feed') {
         $authordescr_itemid = $params->get('authordescr_itemid');
     }
     // Bind Fields to items and render their display HTML, but check for document type, due to Joomla issue
     // with system plugins creating JDocument in early events forcing it to be wrong type, when format as url suffix is enabled
     if ($format != 'feed') {
         $items = FlexicontentFields::getFields($items, 'category', $params, $aid);
     }
     //Set layout
     $this->setLayout('category');
     $limit = $app->getUserStateFromRequest('com_flexicontent' . $category->id . '.category.limit', 'limit', $params->def('limit', 0), 'int');
     // Get category titles needed by pathway, this will allow Falang to translate them
     $catshelper = new flexicontent_cats($cid);
     $parents = $catshelper->getParentlist($all_cols = false);
     //echo "<pre>".print_r($parents,true)."</pre>";
     /*$parents = array();
     		if ( $cid && isset($globalcats[$cid]->ancestorsarray) ) {
     			$parent_ids = $globalcats[$cid]->ancestorsarray;
     			foreach ($parent_ids as $parent_id) $parents[] = $globalcats[$parent_id];
     		}*/
     $rootcat = (int) $params->get('rootcat');
     if ($rootcat) {
         $root_parents = $globalcats[$rootcat]->ancestorsarray;
     }
     // **********************************************************
     // Calculate a (browser window) page title and a page heading
     // **********************************************************
     // Verify menu item points to current FLEXIcontent object
     if ($menu) {
         $view_ok = 'category' == @$menu->query['view'];
         $cid_ok = $cid == (int) @$menu->query['cid'];
         $layout_ok = $layout == @$menu->query['layout'];
         // null is equal to empty string
         $authorid_ok = $authorid == (int) @$menu->query['authorid'];
         // null is equal to zero
         $tagid_ok = $tagid == (int) @$menu->query['tagid'];
         // null is equal to zero
         $menu_matches = $view_ok && $cid_ok && $layout_ok && $authorid_ok && $tagid_ok;
         //$menu_params = FLEXI_J16GE ? $menu->params : new JParameter($menu->params);  // Get active menu item parameters
     } else {
         $menu_matches = false;
     }
     // MENU ITEM matched, use its page heading (but use menu title if the former is not set)
     if ($menu_matches) {
         $default_heading = FLEXI_J16GE ? $menu->title : $menu->name;
         // Cross set (show_) page_heading / page_title for compatibility of J2.5+ with J1.5 template (and for J1.5 with J2.5 template)
         $params->def('page_heading', $params->get('page_title', $default_heading));
         $params->def('page_title', $params->get('page_heading', $default_heading));
         $params->def('show_page_heading', $params->get('show_page_title', 0));
         $params->def('show_page_title', $params->get('show_page_heading', 0));
     } else {
         // Clear some menu parameters
         //$params->set('pageclass_sfx',	'');  // CSS class SUFFIX is behavior, so do not clear it ?
         // Calculate default page heading (=called page title in J1.5), which in turn will be document title below !! ...
         switch ($layout) {
             case '':
                 $default_heading = $category->title;
                 break;
             case 'myitems':
                 $default_heading = JText::_('FLEXI_MY_CONTENT');
                 break;
             case 'author':
                 $default_heading = JText::_('FLEXI_CONTENT_BY_AUTHOR') . ': ' . JFactory::getUser($authorid)->get('name');
                 break;
             case 'tags':
                 $default_heading = JText::_('FLEXI_ITEMS_WITH_TAG') . ': ' . $tag->name;
                 break;
             case 'favs':
                 $default_heading = JText::_('FLEXI_YOUR_FAVOURED_ITEMS');
                 break;
             default:
                 $default_heading = JText::_('FLEXI_CONTENT_IN_CATEGORY');
         }
         if ($layout && $cid) {
             // Non-single category listings, limited to a specific category
             $default_heading .= ', ' . JText::_('FLEXI_IN_CATEGORY') . ': ' . $category->title;
         }
         // Decide to show page heading (=J1.5 page title) only if a custom layout is used (=not a single category layout)
         $show_default_heading = $layout ? 1 : 0;
         // Set both (show_) page_heading / page_title for compatibility of J2.5+ with J1.5 template (and for J1.5 with J2.5 template)
         $params->set('page_title', $default_heading);
         $params->set('page_heading', $default_heading);
         $params->set('show_page_heading', $show_default_heading);
         $params->set('show_page_title', $show_default_heading);
     }
     // Prevent showing the page heading if (a) IT IS same as category title and (b) category title is already configured to be shown
     if ($params->get('show_cat_title', 1)) {
         if ($params->get('page_heading') == $category->title) {
             $params->set('show_page_heading', 0);
         }
         if ($params->get('page_title') == $category->title) {
             $params->set('show_page_title', 0);
         }
     }
     // ************************************************************
     // Create the document title, by from page title and other data
     // ************************************************************
     // Use the page heading as document title, (already calculated above via 'appropriate' logic ...)
     // or the overriden custom <title> ... set via parameter
     $doc_title = empty($meta_params) ? $params->get('page_title') : $meta_params->get('page_title', $params->get('page_title'));
     // Check and prepend or append site name to page title
     if ($doc_title != $app->getCfg('sitename')) {
         if ($app->getCfg('sitename_pagetitles', 0) == 1) {
             $doc_title = JText::sprintf('JPAGETITLE', $app->getCfg('sitename'), $doc_title);
         } elseif ($app->getCfg('sitename_pagetitles', 0) == 2) {
             $doc_title = JText::sprintf('JPAGETITLE', $doc_title, $app->getCfg('sitename'));
         }
     }
     // Finally, set document title
     $document->setTitle($doc_title);
     // ************************
     // Set document's META tags
     // ************************
     // Workaround for Joomla not setting the default value for 'robots', so component must do it
     $app_params = $app->getParams();
     if ($_mp = $app_params->get('robots')) {
         $document->setMetadata('robots', $_mp);
     }
     if ($category->id) {
         // possibly not set for author items OR my items
         if ($category->metadesc) {
             $document->setDescription($category->metadesc);
         }
         if ($category->metakey) {
             $document->setMetadata('keywords', $category->metakey);
         }
         // meta_params are always set if J1.6+ and category id is set
         if ($meta_params->get('robots')) {
             $document->setMetadata('robots', $meta_params->get('robots'));
         }
         // ?? Deprecated <title> tag is used instead by search engines
         if ($app->getCfg('MetaTitle') == '1') {
             $meta_title = $meta_params->get('page_title') ? $meta_params->get('page_title') : $category->title;
             $document->setMetaData('title', $meta_title);
         }
         if ($app->getCfg('MetaAuthor') == '1') {
             if ($meta_params->get('author')) {
                 $meta_author = $meta_params->get('author');
             } else {
                 $table = JUser::getTable();
                 $meta_author = $table->load($category->created_user_id) ? $table->name : '';
             }
             $document->setMetaData('author', $meta_author);
         }
     }
     // Overwrite with menu META data if menu matched
     if ($menu_matches) {
         if ($_mp = $menu->params->get('menu-meta_description')) {
             $document->setDescription($_mp);
         }
         if ($_mp = $menu->params->get('menu-meta_keywords')) {
             $document->setMetadata('keywords', $_mp);
         }
         if ($_mp = $menu->params->get('robots')) {
             $document->setMetadata('robots', $_mp);
         }
         if ($_mp = $menu->params->get('secure')) {
             $document->setMetadata('secure', $_mp);
         }
     }
     // *********************************************************************
     // Create category link, but also consider current 'layout', and use the
     // layout specific variables so that filtering form will work properly
     // *********************************************************************
     $non_sef_link = null;
     $category_link = flexicontent_html::createCatLink($category->slug, $non_sef_link, $model);
     // ****************************************************************
     // Make sure Joomla SEF plugin has inserted a correct REL canonical
     // or that it has not insert any REL if current URL is sufficient
     // ****************************************************************
     if ($params->get('add_canonical')) {
         // Get canonical URL that SEF plugin adds, also $domain passed by reference, to get the domain configured in SEF plugin (multi-domain website)
         $domain = null;
         $defaultCanonical = flexicontent_html::getDefaultCanonical($domain);
         $domain = $domain ? $domain : $uri->toString(array('scheme', 'host', 'port'));
         // Create desired REL canonical URL
         $start = JRequest::getInt('start', '');
         $ucanonical = $domain . JRoute::_(FlexicontentHelperRoute::getCategoryRoute($category->slug) . ($start ? "&start=" . $start : ''));
         // Check if SEF plugin inserted a different REL canonical
         if ($defaultCanonical != $ucanonical) {
             // Add REL canonical only if different than current URL
             $head_obj = $document->addHeadLink(htmlspecialchars($ucanonical), 'canonical', 'rel', '');
             if ($uri->toString() == $ucanonical) {
                 unset($head_obj->_links[htmlspecialchars($ucanonical)]);
             }
             // Remove canonical inserted by SEF plugin
             unset($head_obj->_links[htmlspecialchars($defaultCanonical)]);
         }
     }
     if ($params->get('show_feed_link', 1) == 1) {
         //add alternate feed link
         $link = $non_sef_link . '&format=feed';
         $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0');
         $document->addHeadLink(JRoute::_($link . '&type=rss'), 'alternate', 'rel', $attribs);
         $attribs = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0');
         $document->addHeadLink(JRoute::_($link . '&type=atom'), 'alternate', 'rel', $attribs);
     }
     // ********************************************************************************************
     // Create pathway, if automatic pathways is enabled, then path will be cleared before populated
     // ********************************************************************************************
     $pathway = $app->getPathWay();
     // Clear pathway, if automatic pathways are enabled
     if ($params->get('automatic_pathways', 0)) {
         $pathway_arr = $pathway->getPathway();
         $pathway->setPathway(array());
         //$pathway->set('_count', 0);  // not needed ??
         $item_depth = 0;
         // menu item depth is now irrelevant ???, ignore it
     } else {
         $item_depth = $params->get('item_depth', 0);
     }
     // Respect menu item depth, defined in menu item
     $p = $item_depth;
     while ($p < count($parents)) {
         // Do not add the directory root category or its parents (this when coming from a directory view)
         if (!empty($root_parents) && in_array($parents[$p]->id, $root_parents)) {
             $p++;
             continue;
         }
         // Do not add to pathway unroutable categories
         if (in_array($parents[$p]->id, $globalnoroute)) {
             $p++;
             continue;
         }
         // Add current parent category
         $pathway->addItem($this->escape($parents[$p]->title), JRoute::_(FlexicontentHelperRoute::getCategoryRoute($parents[$p]->slug)));
         $p++;
     }
     //echo "<pre>"; print_r($pathway); echo "</pre>";
     $authordescr_item_html = false;
     if ($authordescr_item) {
         $flexi_html_helper = new flexicontent_html();
         $authordescr_item_html = $flexi_html_helper->renderItem($authordescr_itemid);
     }
     //echo $authordescr_item_html; exit();
     if ($clayout) {
         // Add the templates css files if availables
         if (isset($themes->category->{$clayout}->css)) {
             foreach ($themes->category->{$clayout}->css as $css) {
                 $document->addStyleSheet($this->baseurl . '/' . $css);
             }
         }
         // Add the templates js files if availables
         if (isset($themes->category->{$clayout}->js)) {
             foreach ($themes->category->{$clayout}->js as $js) {
                 $document->addScript($this->baseurl . '/' . $js);
             }
         }
         // Set the template var
         $tmpl = $themes->category->{$clayout}->tmplvar;
     } else {
         $tmpl = '.category.default';
     }
     // @TODO trigger the plugin selectively
     // and delete the plugins tags if not active
     if ($params->get('trigger_onprepare_content_cat')) {
         JPluginHelper::importPlugin('content');
         // Allow to trigger content plugins on category description
         // NOTE: for J2.5, we will trigger the plugins as if description text was an article text, using ... 'com_content.article'
         $category->text = $category->description;
         $results = $dispatcher->trigger('onContentPrepare', array('com_content.article', &$category, &$params, 0));
         JRequest::setVar('layout', $layout);
         // Restore LAYOUT variable should some plugin have modified it
         $category->description = $category->text;
     }
     // Maybe here not to import all plugins but just those for description field or add a parameter for this
     // Anyway these events are usually not very time consuming as is the the event onPrepareContent(J1.5)/onContentPrepare(J1.6+)
     JPluginHelper::importPlugin('content');
     $noroute_cats = array_flip($globalnoroute);
     $type_attribs = flexicontent_db::getTypeAttribs($force = true, $typeid = 0);
     $type_params = array();
     foreach ($items as $item) {
         $item->event = new stdClass();
         if (!isset($type_params[$item->type_id])) {
             $type_params[$item->type_id] = new JRegistry($type_attribs[$item->type_id]);
         }
         $item->params = clone $type_params[$item->type_id];
         $item->params->merge(new JRegistry($item->attribs));
         //$item->cats = isset($item->cats) ? $item->cats : array();
         // !!! The triggering of the event onPrepareContent(J1.5)/onContentPrepare(J1.6+) of content plugins
         // !!! for description field (maintext) along with all other flexicontent
         // !!! fields is handled by flexicontent.fields.php
         // !!! Had serious performance impact
         // CODE REMOVED
         // We must check if the current category is in the categories of the item ..
         $item_in_category = false;
         if ($item->catid == $category->id) {
             $item_in_category = true;
         } else {
             foreach ($item->cats as $cat) {
                 if ($cat->id == $category->id) {
                     $item_in_category = true;
                     break;
                 }
             }
         }
         // ADVANCED CATEGORY ROUTING (=set the most appropriate category for the item ...)
         // CHOOSE APPROPRIATE category-slug FOR THE ITEM !!! ( )
         if ($item_in_category && !isset($noroute_cats[$category->id])) {
             // 1. CATEGORY SLUG: CURRENT category
             // Current category IS a category of the item and ALSO routing (creating links) to this category is allowed
             $item->categoryslug = $category->slug;
         } else {
             if (!isset($noroute_cats[$item->catid])) {
                 // 2. CATEGORY SLUG: ITEM's MAIN category   (already SET, ... no assignment needed)
                 // Since we cannot use current category (above), we will use item's MAIN category
                 // ALSO routing (creating links) to this category is allowed
             } else {
                 // 3. CATEGORY SLUG: ANY ITEM's category
                 // We will use the first for which routing (creating links) to the category is allowed
                 $allcats = array();
                 foreach ($item->cats as $cat) {
                     if (!isset($noroute_cats[$cat->id])) {
                         $item->categoryslug = $globalcats[$cat->id]->slug;
                         break;
                     }
                 }
             }
         }
         // Just put item's text (description field) inside property 'text' in case the events modify the given text,
         $item->text = isset($item->fields['text']->display) ? $item->fields['text']->display : '';
         // Set the view and option to 'category' and 'com_content'  (actually view is already called category)
         JRequest::setVar('option', 'com_content');
         JRequest::setVar("isflexicontent", "yes");
         // These events return text that could be displayed at appropriate positions by our templates
         $item->event = new stdClass();
         $results = $dispatcher->trigger('onContentAfterTitle', array('com_content.category', &$item, &$params, 0));
         $item->event->afterDisplayTitle = trim(implode("\n", $results));
         $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_content.category', &$item, &$params, 0));
         $item->event->beforeDisplayContent = trim(implode("\n", $results));
         $results = $dispatcher->trigger('onContentAfterDisplay', array('com_content.category', &$item, &$params, 0));
         $item->event->afterDisplayContent = trim(implode("\n", $results));
         // Set the option back to 'com_flexicontent'
         JRequest::setVar('option', 'com_flexicontent');
         // Put text back into the description field, THESE events SHOULD NOT modify the item text, but some plugins may do it anyway... , so we assign text back for compatibility
         $item->fields['text']->display =& $item->text;
     }
     // Calculate CSS classes needed to add special styling markups to the items
     flexicontent_html::calculateItemMarkups($items, $params);
     // *****************************************************
     // Remove unroutable categories from sub/peer categories
     // *****************************************************
     // sub-cats
     $_categories = array();
     foreach ($categories as $i => $cat) {
         if (in_array($cat->id, $globalnoroute)) {
             continue;
         }
         $_categories[] = $categories[$i];
     }
     $categories = $_categories;
     // peer-cats
     $_categories = array();
     foreach ($peercats as $i => $cat) {
         if (in_array($cat->id, $globalnoroute)) {
             continue;
         }
         $_categories[] = $peercats[$i];
     }
     $peercats = $_categories;
     // ************************************
     // Get some variables needed for images
     // ************************************
     $joomla_image_path = $app->getCfg('image_path', '');
     $joomla_image_url = str_replace(DS, '/', $joomla_image_path);
     $joomla_image_path = $joomla_image_path ? $joomla_image_path . DS : '';
     $joomla_image_url = $joomla_image_url ? $joomla_image_url . '/' : '';
     $phpThumbURL = $this->baseurl . '/components/com_flexicontent/librairies/phpthumb/phpThumb.php?src=';
     // **************
     // CATEGORY IMAGE
     // **************
     // category image params
     $show_cat_image = $params->get('show_description_image', 0);
     // we use different name for variable
     $cat_image_source = $params->get('cat_image_source', 2);
     // 0: extract, 1: use param, 2: use both
     $cat_link_image = $params->get('cat_link_image', 1);
     $cat_image_method = $params->get('cat_image_method', 1);
     $cat_image_width = $params->get('cat_image_width', 80);
     $cat_image_height = $params->get('cat_image_height', 80);
     $cat_default_image = $params->get('cat_default_image', '');
     if ($show_cat_image) {
         $h = '&amp;h=' . $cat_image_height;
         $w = '&amp;w=' . $cat_image_width;
         $aoe = '&amp;aoe=1';
         $q = '&amp;q=95';
         $zc = $cat_image_method ? '&amp;zc=' . $cat_image_method : '';
     }
     if ($cat_default_image) {
         $src = $this->baseurl . "/" . $joomla_image_url . $cat_default_image;
         $ext = strtolower(pathinfo($src, PATHINFO_EXTENSION));
         $f = in_array($ext, array('png', 'ico', 'gif')) ? '&amp;f=' . $ext : '';
         $conf = $w . $h . $aoe . $q . $zc . $f;
         $default_image = $phpThumbURL . $src . $conf;
         $default_image = '<img class="fccat_image" style="float:' . $cat_image_float . '" src="' . $default_image . '" alt="%s" title="%s"/>';
     } else {
         $default_image = '';
     }
     // Create category image/description/etc data
     $cat = $category;
     $image = "";
     if ($cat) {
         if ($cat->id && $show_cat_image) {
             $cat->image = $params->get('image');
             $cat->introtext =& $cat->description;
             $cat->fulltext = "";
             if ($cat_image_source && $cat->image && JFile::exists(JPATH_SITE . DS . $joomla_image_path . $cat->image)) {
                 $src = $this->baseurl . "/" . $joomla_image_url . $cat->image;
                 $ext = strtolower(pathinfo($src, PATHINFO_EXTENSION));
                 $f = in_array($ext, array('png', 'ico', 'gif')) ? '&amp;f=' . $ext : '';
                 $conf = $w . $h . $aoe . $q . $zc . $f;
                 $image = $phpThumbURL . $src . $conf;
             } else {
                 if ($cat_image_source != 1 && ($src = flexicontent_html::extractimagesrc($cat))) {
                     $ext = strtolower(pathinfo($src, PATHINFO_EXTENSION));
                     $f = in_array($ext, array('png', 'ico', 'gif')) ? '&amp;f=' . $ext : '';
                     $conf = $w . $h . $aoe . $q . $zc . $f;
                     $base_url = !preg_match("#^http|^https|^ftp|^/#i", $src) ? $this->baseurl . '/' : '';
                     $src = $base_url . $src;
                     $image = $phpThumbURL . $src . $conf;
                 }
             }
             $cat->image_src = @$src;
             // Also add image category URL for developers
             if ($image) {
                 $image = '<img class="fccat_image" src="' . $image . '" alt="' . $this->escape($cat->title) . '" title="' . $this->escape($cat->title) . '"/>';
             } else {
                 if ($default_image) {
                     $image = sprintf($default_image, $cat->title, $cat->title);
                 }
             }
             if ($cat_link_image && $image) {
                 $image = '<a href="' . JRoute::_(FlexicontentHelperRoute::getCategoryRoute($cat->slug)) . '">' . $image . '</a>';
             }
         }
         $cat->image = $image;
     }
     // ******************************
     // SUBCATEGORIES (some templates)
     // ******************************
     // sub-category image params
     $show_cat_image = $params->get('show_description_image_subcat', 1);
     // we use different name for variable
     $cat_image_source = $params->get('subcat_image_source', 2);
     // 0: extract, 1: use param, 2: use both
     $cat_link_image = $params->get('subcat_link_image', 1);
     $cat_image_method = $params->get('subcat_image_method', 1);
     $cat_image_width = $params->get('subcat_image_width', 24);
     $cat_image_height = $params->get('subcat_image_height', 24);
     $cat_default_image = $params->get('subcat_default_image', '');
     if ($show_cat_image) {
         $h = '&amp;h=' . $cat_image_height;
         $w = '&amp;w=' . $cat_image_width;
         $aoe = '&amp;aoe=1';
         $q = '&amp;q=95';
         $zc = $cat_image_method ? '&amp;zc=' . $cat_image_method : '';
     }
     if ($cat_default_image) {
         $src = $this->baseurl . "/" . $joomla_image_url . $cat_default_image;
         $ext = strtolower(pathinfo($src, PATHINFO_EXTENSION));
         $f = in_array($ext, array('png', 'ico', 'gif')) ? '&amp;f=' . $ext : '';
         $conf = $w . $h . $aoe . $q . $zc . $f;
         $default_image = $phpThumbURL . $src . $conf;
         $default_image = '<img class="fccat_image" style="float:' . $cat_image_float . '" src="' . $default_image . '" alt="%s" title="%s"/>';
     } else {
         $default_image = '';
     }
     // Create sub-category image/description/etc data
     foreach ($categories as $cat) {
         $image = "";
         if ($show_cat_image) {
             if (!is_object($cat->params)) {
                 $cat->params = new JRegistry($cat->params);
             }
             $cat->image = $cat->params->get('image');
             $cat->introtext =& $cat->description;
             $cat->fulltext = "";
             if ($cat_image_source && $cat->image && JFile::exists(JPATH_SITE . DS . $joomla_image_path . $cat->image)) {
                 $src = $this->baseurl . "/" . $joomla_image_url . $cat->image;
                 $ext = strtolower(pathinfo($src, PATHINFO_EXTENSION));
                 $f = in_array($ext, array('png', 'ico', 'gif')) ? '&amp;f=' . $ext : '';
                 $conf = $w . $h . $aoe . $q . $zc . $f;
                 $image = $phpThumbURL . $src . $conf;
             } else {
                 if ($cat_image_source != 1 && ($src = flexicontent_html::extractimagesrc($cat))) {
                     $ext = strtolower(pathinfo($src, PATHINFO_EXTENSION));
                     $f = in_array($ext, array('png', 'ico', 'gif')) ? '&amp;f=' . $ext : '';
                     $conf = $w . $h . $aoe . $q . $zc . $f;
                     $base_url = !preg_match("#^http|^https|^ftp|^/#i", $src) ? $this->baseurl . '/' : '';
                     $src = $base_url . $src;
                     $image = $phpThumbURL . $src . $conf;
                 }
             }
             $cat->image_src = @$src;
             // Also add image category URL for developers
             if ($image) {
                 $image = '<img class="fccat_image" src="' . $image . '" alt="' . $this->escape($cat->title) . '" title="' . $this->escape($cat->title) . '"/>';
             } else {
                 if ($default_image) {
                     $image = sprintf($default_image, $cat->title, $cat->title);
                 }
             }
             if ($cat_link_image && $image) {
                 $image = '<a href="' . JRoute::_(FlexicontentHelperRoute::getCategoryRoute($cat->slug)) . '">' . $image . '</a>';
             }
         }
         $cat->image = $image;
     }
     // *******************************
     // PEERCATEGORIES (some templates)
     // *******************************
     // peer-category image params
     $show_cat_image = $params->get('show_description_image_peercat', 1);
     // we use different name for variable
     $cat_image_source = $params->get('peercat_image_source', 2);
     // 0: extract, 1: use param, 2: use both
     $cat_link_image = $params->get('peercat_link_image', 1);
     $cat_image_method = $params->get('peercat_image_method', 1);
     $cat_image_width = $params->get('peercat_image_width', 24);
     $cat_image_height = $params->get('peercat_image_height', 24);
     $cat_default_image = $params->get('peercat_default_image', '');
     if ($show_cat_image) {
         $h = '&amp;h=' . $cat_image_height;
         $w = '&amp;w=' . $cat_image_width;
         $aoe = '&amp;aoe=1';
         $q = '&amp;q=95';
         $zc = $cat_image_method ? '&amp;zc=' . $cat_image_method : '';
     }
     if ($cat_default_image) {
         $src = $this->baseurl . "/" . $joomla_image_url . $cat_default_image;
         $ext = strtolower(pathinfo($src, PATHINFO_EXTENSION));
         $f = in_array($ext, array('png', 'ico', 'gif')) ? '&amp;f=' . $ext : '';
         $conf = $w . $h . $aoe . $q . $zc . $f;
         $default_image = $phpThumbURL . $src . $conf;
         $default_image = '<img class="fccat_image" style="float:' . $cat_image_float . '" src="' . $default_image . '" alt="%s" title="%s"/>';
     } else {
         $default_image = '';
     }
     // Create peer-category image/description/etc data
     foreach ($peercats as $cat) {
         $image = "";
         if ($show_cat_image) {
             if (!is_object($cat->params)) {
                 $cat->params = new JRegistry($cat->params);
             }
             $cat->image = $cat->params->get('image');
             $cat->introtext =& $cat->description;
             $cat->fulltext = "";
             if ($cat_image_source && $cat->image && JFile::exists(JPATH_SITE . DS . $joomla_image_path . $cat->image)) {
                 $src = $this->baseurl . "/" . $joomla_image_url . $cat->image;
                 $ext = strtolower(pathinfo($src, PATHINFO_EXTENSION));
                 $f = in_array($ext, array('png', 'ico', 'gif')) ? '&amp;f=' . $ext : '';
                 $conf = $w . $h . $aoe . $q . $zc . $f;
                 $image = $phpThumbURL . $src . $conf;
             } else {
                 if ($cat_image_source != 1 && ($src = flexicontent_html::extractimagesrc($cat))) {
                     $ext = strtolower(pathinfo($src, PATHINFO_EXTENSION));
                     $f = in_array($ext, array('png', 'ico', 'gif')) ? '&amp;f=' . $ext : '';
                     $conf = $w . $h . $aoe . $q . $zc . $f;
                     $base_url = !preg_match("#^http|^https|^ftp|^/#i", $src) ? $this->baseurl . '/' : '';
                     $src = $base_url . $src;
                     $image = $phpThumbURL . $src . $conf;
                 }
             }
             $cat->image_src = @$src;
             // Also add image category URL for developers
             if ($image) {
                 $image = '<img class="fccat_image" src="' . $image . '" alt="' . $this->escape($cat->title) . '" title="' . $this->escape($cat->title) . '"/>';
             } else {
                 if ($default_image) {
                     $image = sprintf($default_image, $cat->title, $cat->title);
                 }
             }
             if ($cat_link_image && $image) {
                 $image = '<a href="' . JRoute::_(FlexicontentHelperRoute::getCategoryRoute($cat->slug)) . '">' . $image . '</a>';
             }
         }
         $cat->image = $image;
     }
     // remove previous alpha index filter
     //$uri->delVar('letter');
     // remove filter variables (includes search box and sort order)
     preg_match_all('/filter[^=]*/', $uri->toString(), $matches);
     foreach ($matches[0] as $match) {
         //$uri->delVar($match);
     }
     // Build Lists
     $lists = array();
     //ordering
     $lists['filter_order'] = JRequest::getCmd('filter_order', 'i.title', 'default');
     $lists['filter_order_Dir'] = JRequest::getCmd('filter_order_Dir', 'ASC', 'default');
     $lists['filter'] = JRequest::getString('filter', '', 'default');
     // Add html to filter objects
     $form_name = 'adminForm';
     if ($filters) {
         FlexicontentFields::renderFilters($params, $filters, $form_name);
     }
     // ****************************
     // Create the pagination object
     // ****************************
     $pageNav = $this->get('pagination');
     $_revert = array('%21' => '!', '%2A' => '*', '%27' => "'", '%28' => '(', '%29' => ')');
     // URL-encode filter values
     foreach ($_GET as $i => $v) {
         if (substr($i, 0, 6) === "filter") {
             if (is_array($v)) {
                 foreach ($v as $ii => &$vv) {
                     $vv = str_replace('&', '__amp__', $vv);
                     $vv = strtr(rawurlencode($vv), $_revert);
                     $pageNav->setAdditionalUrlParam($i . '[' . $ii . ']', $vv);
                 }
                 unset($vv);
             } else {
                 $v = str_replace('&', '__amp__', $v);
                 $v = strtr(rawurlencode($v), $_revert);
                 $pageNav->setAdditionalUrlParam($i, $v);
             }
         }
     }
     $resultsCounter = $pageNav->getResultsCounter();
     // for overriding model's result counter
     // **********************************************************************
     // Print link ... must include layout and current filtering url vars, etc
     // **********************************************************************
     $curr_url = str_replace('&', '&amp;', $_SERVER['REQUEST_URI']);
     $print_link = $curr_url . (strstr($curr_url, '?') ? '&amp;' : '?') . 'pop=1&amp;tmpl=component&amp;print=1';
     $pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx'));
     $this->assignRef('layout_vars', $layout_vars);
     $this->assignRef('action', $category_link);
     $this->assignRef('print_link', $print_link);
     $this->assignRef('category', $category);
     $this->assignRef('categories', $categories);
     $this->assignRef('peercats', $peercats);
     $this->assignRef('items', $items);
     $this->assignRef('authordescr_item_html', $authordescr_item_html);
     $this->assignRef('lists', $lists);
     $this->assignRef('params', $params);
     $this->assignRef('pageNav', $pageNav);
     $this->assignRef('pageclass_sfx', $pageclass_sfx);
     $this->assignRef('pagination', $pageNav);
     // compatibility Alias for old templates
     $this->assignRef('resultsCounter', $resultsCounter);
     // for overriding model's result counter
     $this->assignRef('limitstart', $limitstart);
     // compatibility shortcut
     $this->assignRef('filters', $filters);
     $this->assignRef('comments', $comments);
     $this->assignRef('alpha', $alpha);
     $this->assignRef('tmpl', $tmpl);
     // NOTE: Moved decision of layout into the model, function decideLayout() layout variable should never be empty
     // It will consider things like: template exists, is allowed, client is mobile, current frontend user override, etc
     // !!! The following method of loading layouts, is Joomla legacy view loading of layouts
     // TODO: EXAMINE IF NEEDED to re-use these layouts, and use JLayout ??
     // Despite layout variable not being empty, there may be missing some sub-layout files,
     // e.g. category_somefilename.php for this reason we will use a fallback layout that surely has these files
     $fallback_layout = $params->get('category_fallback_layout', 'blog');
     // parameter does not exist yet
     if ($clayout != $fallback_layout) {
         $this->addTemplatePath(JPATH_COMPONENT . DS . 'templates' . DS . $fallback_layout);
         $this->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS . 'com_flexicontent' . DS . 'templates' . DS . $fallback_layout);
     }
     $this->addTemplatePath(JPATH_COMPONENT . DS . 'templates' . DS . $clayout);
     $this->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS . 'com_flexicontent' . DS . 'templates' . DS . $clayout);
     // **************************************************
     // increment the hit counter ONLY once per user visit
     // **************************************************
     // MOVED to flexisystem plugin due to ...
     $print_logging_info = $params->get('print_logging_info');
     if ($print_logging_info) {
         global $fc_run_times;
         $start_microtime = microtime(true);
     }
     parent::display($tpl);
     if ($print_logging_info) {
         @($fc_run_times['template_render'] += round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10);
     }
 }
Exemplo n.º 18
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);
 }
Exemplo n.º 19
0
 function fetchElement($name, $value, &$node, $control_name)
 {
     if (FLEXI_J16GE) {
         $node =& $this->element;
         $attributes = get_object_vars($node->attributes());
         $attributes = $attributes['@attributes'];
     } else {
         $attributes =& $node->_attributes;
     }
     $themes = flexicontent_tmpl::getTemplates();
     $tmpls = $themes->items;
     $values = FLEXI_J16GE ? $this->value : $value;
     if (empty($values)) {
         $values = array();
     } else {
         if (!is_array($values)) {
             $values = !FLEXI_J16GE ? array($values) : explode("|", $values);
         }
     }
     $fieldname = FLEXI_J16GE ? $this->name : $control_name . '[' . $name . ']';
     $element_id = FLEXI_J16GE ? $this->id : $control_name . $name;
     // Field parameter (attributes)
     $attribs = '';
     $classes = 'use_select2_lib ';
     if ($node->attributes('required') && $node->attributes('required') == 'true') {
         $classes .= 'required ';
     }
     if ($node->attributes('validation_class')) {
         $classes .= $node->attributes('validation_class');
     }
     $attribs = ' class="' . $classes . '" ' . $attribs;
     $attribs .= ' style="float:left;" ';
     if (@$attributes['multiple'] == 'multiple' || @$attributes['multiple'] == 'true') {
         $attribs .= ' multiple="multiple" ';
         $attribs .= @$attributes['size'] ? ' size="' . $attributes['size'] . '" ' : ' size="6" ';
         $fieldname .= !FLEXI_J16GE ? "[]" : "";
         // NOTE: this added automatically in J2.5
         //$maximize_link = "<a style='display:inline-block;".(FLEXI_J16GE ? 'float:left; margin: 6px 0px 0px 18px;':'margin:0px 0px 6px 12px')."' href='javascript:;' onclick='$element_id = document.getElementById(\"$element_id\"); if ($element_id.size<16) { ${element_id}_oldsize=$element_id.size; $element_id.size=16;} else { $element_id.size=${element_id}_oldsize; } ' >Maximize/Minimize</a>";
     } else {
         array_unshift($types, JHTML::_('select.option', '', JText::_('FLEXI_PLEASE_SELECT')));
         $attribs .= 'class="inputbox"';
         //$maximize_link = '';
     }
     $maximize_link = '';
     if ($onchange = @$attributes['onchange']) {
         $attribs .= ' onchange="' . $onchange . '"';
     }
     // Field data (the templates)
     $lays = array();
     foreach ($tmpls as $tmpl) {
         $lays[] = $tmpl->name;
     }
     $lays = implode("','", $lays);
     if ($tmpls !== false) {
         foreach ($tmpls as $tmpl) {
             $layouts[] = JHTMLSelect::option($tmpl->name, $tmpl->name);
         }
     }
     $html = JHTML::_('select.genericlist', $layouts, $fieldname, $attribs, 'value', 'text', $values, $element_id);
     return $html . $maximize_link;
 }
Exemplo n.º 20
0
 /**
  * Creates the page's display
  *
  * @since 1.0
  */
 function display($tpl = null)
 {
     // Get Non-routing Categories, and Category Tree
     global $globalnoroute, $globalcats;
     if (!is_array($globalnoroute)) {
         $globalnoroute = array();
     }
     //initialize variables
     $dispatcher = JDispatcher::getInstance();
     $app = JFactory::getApplication();
     $session = JFactory::getSession();
     $option = JRequest::getVar('option');
     $document = JFactory::getDocument();
     $menus = $app->getMenu();
     $menu = $menus->getActive();
     $uri = JFactory::getURI();
     $user = JFactory::getUser();
     $aid = FLEXI_J16GE ? JAccess::getAuthorisedViewLevels($user->id) : (int) $user->get('aid');
     // Get category and set category parameters as VIEW's parameters (category parameters are merged with component/page/author parameters already)
     $category = $this->get('Category');
     $params = $category->parameters;
     if ($category->id && FLEXI_J16GE) {
         $meta_params = new JRegistry($category->metadata);
     } else {
         $meta_params = false;
     }
     // Get various data from the model
     $categories = $this->get('Childs');
     // this will also count sub-category items is if  'show_itemcount'  is enabled
     $peercats = $this->get('Peers');
     // this will also count sub-category items is if  'show_subcatcount_peercat'  is enabled
     $items = $this->get('Data');
     $total = $this->get('Total');
     $filters = $this->get('Filters');
     if ($params->get('show_comments_count', 0)) {
         $comments = $this->get('CommentsInfo');
     } else {
         $comments = null;
     }
     $alpha = $params->get('show_alpha', 1) ? $this->get('Alphaindex') : array();
     // This is somwhat expensive so calculate it only if required
     // Request variables, WARNING, must be loaded after retrieving items, because limitstart may have been modified
     $limitstart = JRequest::getInt('limitstart');
     $format = JRequest::getCmd('format', null);
     // ********************************
     // Load needed JS libs & CSS styles
     // ********************************
     FLEXI_J30GE ? JHtml::_('behavior.framework', true) : JHTML::_('behavior.mootools');
     flexicontent_html::loadFramework('jQuery');
     flexicontent_html::loadFramework('flexi_tmpl_common');
     //add css file
     if (!$params->get('disablecss', '')) {
         $document->addStyleSheet($this->baseurl . '/components/com_flexicontent/assets/css/flexicontent.css');
         $document->addCustomTag('<!--[if IE]><style type="text/css">.floattext {zoom:1;}</style><![endif]-->');
     }
     //allow css override
     if (file_exists(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'css' . DS . 'flexicontent.css')) {
         $document->addStyleSheet($this->baseurl . '/templates/' . $app->getTemplate() . '/css/flexicontent.css');
     }
     // ************************
     // CATEGORY LAYOUT handling
     // ************************
     // (a) Decide to use mobile or normal category template layout
     $useMobile = $params->get('use_mobile_layouts', 0);
     if ($useMobile) {
         $force_desktop_layout = $params->get('force_desktop_layout', 0);
         $mobileDetector = flexicontent_html::getMobileDetector();
         $isMobile = $mobileDetector->isMobile();
         $isTablet = $mobileDetector->isTablet();
         $useMobile = $force_desktop_layout ? $isMobile && !$isTablet : $isMobile;
     }
     $_clayout = $useMobile ? 'clayout_mobile' : 'clayout';
     // (b) Get from category parameters, allowing URL override
     $clayout = JRequest::getCmd($_clayout, false);
     if (!$clayout) {
         $desktop_clayout = $params->get('clayout', 'blog');
         $clayout = !$useMobile ? $desktop_clayout : $params->get('clayout_mobile', $desktop_clayout);
     }
     // (c) Get cached template data
     $themes = flexicontent_tmpl::getTemplates($lang_files = array($clayout));
     // (d) Verify the category layout exists
     if (!isset($themes->category->{$clayout})) {
         $fixed_clayout = 'blog';
         $app->enqueueMessage("<small>Current Category Layout Template is '{$clayout}' does not exist<br>- Please correct this in the URL or in Content Type configuration.<br>- Using Template Layout: '{$fixed_clayout}'</small>", 'notice');
         $clayout = $fixed_clayout;
         if (FLEXI_FISH || FLEXI_J16GE) {
             FLEXIUtilities::loadTemplateLanguageFile($clayout);
         }
         // Manually load Template-Specific language file of back fall clayout
     }
     // (e) finally set the template name back into the category's parameters
     $params->set('clayout', $clayout);
     // Get URL variables
     $cid = JRequest::getInt('cid', 0);
     $authorid = JRequest::getInt('authorid', 0);
     $tagid = JRequest::getInt('tagid', 0);
     $layout = JRequest::getCmd('layout', '');
     $mcats_list = JRequest::getVar('cids', '');
     if (!is_array($mcats_list)) {
         $mcats_list = preg_replace('/[^0-9,]/i', '', (string) $mcats_list);
         $mcats_list = explode(',', $mcats_list);
     }
     // make sure given data are integers ... !!
     $cids = array();
     foreach ($mcats_list as $i => $_id) {
         if ((int) $_id) {
             $cids[] = (int) $_id;
         }
     }
     $cids = implode(',', $cids);
     $authordescr_item = false;
     if ($authorid && $params->get('authordescr_itemid') && $format != 'feed') {
         $authordescr_itemid = $params->get('authordescr_itemid');
     }
     // Bind Fields
     if ($format != 'feed') {
         $items = FlexicontentFields::getFields($items, 'category', $params, $aid);
     }
     //Set layout
     $this->setLayout('category');
     $limit = $app->getUserStateFromRequest('com_flexicontent' . $category->id . '.category.limit', 'limit', $params->def('limit', 0), 'int');
     // Pathway needed variables
     //$catshelper = new flexicontent_cats($cid);
     //$parents    = $catshelper->getParentlist();
     //echo "<pre>".print_r($parents,true)."</pre>";
     $parents = array();
     if ($cid && isset($globalcats[$cid]->ancestorsarray)) {
         $parent_ids = $globalcats[$cid]->ancestorsarray;
         foreach ($parent_ids as $parent_id) {
             $parents[] = $globalcats[$parent_id];
         }
     }
     $rootcat = (int) $params->get('rootcat');
     if ($rootcat) {
         $root_parents = $globalcats[$rootcat]->ancestorsarray;
     }
     // **********************************************************
     // Calculate a (browser window) page title and a page heading
     // **********************************************************
     // Verify menu item points to current FLEXIcontent object
     if ($menu) {
         $view_ok = 'category' == @$menu->query['view'];
         $cid_ok = $cid == (int) @$menu->query['cid'];
         $layout_ok = $layout == @$menu->query['layout'];
         // null is equal to empty string
         $authorid_ok = $authorid == (int) @$menu->query['authorid'];
         // null is equal to zero
         $tagid_ok = $tagid == (int) @$menu->query['tagid'];
         // null is equal to zero
         $menu_matches = $view_ok && $cid_ok && $layout_ok && $authorid_ok && $tagid_ok;
         //$menu_params = FLEXI_J16GE ? $menu->params : new JParameter($menu->params);  // Get active menu item parameters
     } else {
         $menu_matches = false;
     }
     // MENU ITEM matched, use its page heading (but use menu title if the former is not set)
     if ($menu_matches) {
         $default_heading = FLEXI_J16GE ? $menu->title : $menu->name;
         // Cross set (show_) page_heading / page_title for compatibility of J2.5+ with J1.5 template (and for J1.5 with J2.5 template)
         $params->def('page_heading', $params->get('page_title', $default_heading));
         $params->def('page_title', $params->get('page_heading', $default_heading));
         $params->def('show_page_heading', $params->get('show_page_title', 0));
         $params->def('show_page_title', $params->get('show_page_heading', 0));
     } else {
         // Clear some menu parameters
         //$params->set('pageclass_sfx',	'');  // CSS class SUFFIX is behavior, so do not clear it ?
         // Calculate default page heading (=called page title in J1.5), which in turn will be document title below !! ...
         switch ($layout) {
             case '':
                 $default_heading = $category->title;
                 break;
             case 'myitems':
                 $default_heading = JText::_('FLEXICONTENT_MYITEMS');
                 break;
             case 'author':
                 $default_heading = JText::_('FLEXICONTENT_AUTHOR') . ': ' . JFactory::getUser($authorid)->get('name');
                 break;
             default:
                 $default_heading = JText::_('FLEXICONTENT_CATEGORY');
         }
         if ($layout && $cid) {
             // Non-single category listings, limited to a specific category
             $default_heading .= ', ' . JText::_('FLEXI_IN_CATEGORY') . ': ' . $category->title;
         }
         // Decide to show page heading (=J1.5 page title) only if a custom layout is used (=not a single category layout)
         $show_default_heading = $layout ? 1 : 0;
         // Set both (show_) page_heading / page_title for compatibility of J2.5+ with J1.5 template (and for J1.5 with J2.5 template)
         $params->set('page_title', $default_heading);
         $params->set('page_heading', $default_heading);
         $params->set('show_page_heading', $show_default_heading);
         $params->set('show_page_title', $show_default_heading);
     }
     // Prevent showing the page heading if (a) IT IS same as category title and (b) category title is already configured to be shown
     if ($params->get('show_cat_title', 1)) {
         if ($params->get('page_heading') == $category->title) {
             $params->set('show_page_heading', 0);
         }
         if ($params->get('page_title') == $category->title) {
             $params->set('show_page_title', 0);
         }
     }
     // ************************************************************
     // Create the document title, by from page title and other data
     // ************************************************************
     // Use the page heading as document title, (already calculated above via 'appropriate' logic ...)
     // or the overriden custom <title> ... set via parameter
     $doc_title = !$meta_params ? $params->get('page_title') : $meta_params->get('page_title', $params->get('page_title'));
     // Check and prepend or append site name
     if (FLEXI_J16GE) {
         // Not available in J1.5
         // Add Site Name to page title
         if ($app->getCfg('sitename_pagetitles', 0) == 1) {
             $doc_title = $app->getCfg('sitename') . " - " . $doc_title;
         } elseif ($app->getCfg('sitename_pagetitles', 0) == 2) {
             $doc_title = $doc_title . " - " . $app->getCfg('sitename');
         }
     }
     // Finally, set document title
     $document->setTitle($doc_title);
     // ************************
     // Set document's META tags
     // ************************
     // Workaround for Joomla not setting the default value for 'robots', so component must do it
     $app_params = $app->getParams();
     if ($_mp = $app_params->get('robots')) {
         $document->setMetadata('robots', $_mp);
     }
     if ($category->id) {
         // possibly not set for author items OR my items
         if (FLEXI_J16GE) {
             if ($category->metadesc) {
                 $document->setDescription($category->metadesc);
             }
             if ($category->metakey) {
                 $document->setMetadata('keywords', $category->metakey);
             }
             // meta_params are always set if J1.6+ and category id is set
             if ($meta_params->get('robots')) {
                 $document->setMetadata('robots', $meta_params->get('robots'));
             }
             // ?? Deprecated <title> tag is used instead by search engines
             if ($app->getCfg('MetaTitle') == '1') {
                 $meta_title = $meta_params->get('page_title') ? $meta_params->get('page_title') : $category->title;
                 $document->setMetaData('title', $meta_title);
             }
             if ($app->getCfg('MetaAuthor') == '1') {
                 if ($meta_params->get('author')) {
                     $meta_author = $meta_params->get('author');
                 } else {
                     $table = JUser::getTable();
                     $meta_author = $table->load($category->created_user_id) ? $table->name : '';
                 }
                 $document->setMetaData('author', $meta_author);
             }
         } else {
             // ?? Deprecated <title> tag is used instead by search engines
             if ($app->getCfg('MetaTitle') == '1') {
                 $document->setMetaData('title', $category->title);
             }
         }
     }
     // Overwrite with menu META data if menu matched
     if (FLEXI_J16GE) {
         if ($menu_matches) {
             if ($_mp = $menu->params->get('menu-meta_description')) {
                 $document->setDescription($_mp);
             }
             if ($_mp = $menu->params->get('menu-meta_keywords')) {
                 $document->setMetadata('keywords', $_mp);
             }
             if ($_mp = $menu->params->get('robots')) {
                 $document->setMetadata('robots', $_mp);
             }
             if ($_mp = $menu->params->get('secure')) {
                 $document->setMetadata('secure', $_mp);
             }
         }
     }
     // ************************************
     // Add rel canonical html head link tag (TODO: improve multi-page handing)
     // ************************************
     $base = $uri->getScheme() . '://' . $uri->getHost();
     $start = JRequest::getInt('start', '');
     $start = $start ? "&start=" . $start : "";
     $ucanonical = $base . JRoute::_(FlexicontentHelperRoute::getCategoryRoute($category->slug) . $start);
     if ($params->get('add_canonical')) {
         $head_obj = $document->addHeadLink($ucanonical, 'canonical', 'rel', '');
         $defaultCanonical = flexicontent_html::getDefaultCanonical();
         if (FLEXI_J30GE && $defaultCanonical != $ucanonical) {
             unset($head_obj->_links[$defaultCanonical]);
         }
     }
     if ($params->get('show_feed_link', 1) == 1) {
         //add alternate feed link
         $link = '&format=feed';
         $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0');
         $document->addHeadLink(JRoute::_($link . '&type=rss'), 'alternate', 'rel', $attribs);
         $attribs = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0');
         $document->addHeadLink(JRoute::_($link . '&type=atom'), 'alternate', 'rel', $attribs);
     }
     // ********************************************************************************************
     // Create pathway, if automatic pathways is enabled, then path will be cleared before populated
     // ********************************************************************************************
     $pathway = $app->getPathWay();
     // Clear pathway, if automatic pathways are enabled
     if ($params->get('automatic_pathways', 0)) {
         $pathway_arr = $pathway->getPathway();
         $pathway->setPathway(array());
         //$pathway->set('_count', 0);  // not needed ??
         $item_depth = 0;
         // menu item depth is now irrelevant ???, ignore it
     } else {
         $item_depth = $params->get('item_depth', 0);
     }
     // Respect menu item depth, defined in menu item
     $p = $item_depth;
     while ($p < count($parents)) {
         // Do not add the directory root category or its parents (this when coming from a directory view)
         if (!empty($root_parents) && in_array($parents[$p]->id, $root_parents)) {
             $p++;
             continue;
         }
         // Do not add to pathway unroutable categories
         if (in_array($parents[$p]->id, $globalnoroute)) {
             $p++;
             continue;
         }
         // Add current parent category
         $pathway->addItem($this->escape($parents[$p]->title), JRoute::_(FlexicontentHelperRoute::getCategoryRoute($parents[$p]->slug)));
         $p++;
     }
     $authordescr_item_html = false;
     if ($authordescr_item) {
         $flexi_html_helper = new flexicontent_html();
         $authordescr_item_html = $flexi_html_helper->renderItem($authordescr_itemid);
     }
     //echo $authordescr_item_html; exit();
     if ($clayout) {
         // Add the templates css files if availables
         if (isset($themes->category->{$clayout}->css)) {
             foreach ($themes->category->{$clayout}->css as $css) {
                 $document->addStyleSheet($this->baseurl . '/' . $css);
             }
         }
         // Add the templates js files if availables
         if (isset($themes->category->{$clayout}->js)) {
             foreach ($themes->category->{$clayout}->js as $js) {
                 $document->addScript($this->baseurl . '/' . $js);
             }
         }
         // Set the template var
         $tmpl = $themes->category->{$clayout}->tmplvar;
     } else {
         $tmpl = '.category.default';
     }
     // @TODO trigger the plugin selectively
     // and delete the plugins tags if not active
     if ($params->get('trigger_onprepare_content_cat')) {
         JPluginHelper::importPlugin('content');
         // Allow to trigger content plugins on category description
         // NOTE: for J2.5, we will trigger the plugins as if description text was an article text, using ... 'com_content.article'
         $category->text = $category->description;
         if (FLEXI_J16GE) {
             $results = $dispatcher->trigger('onContentPrepare', array('com_content.article', &$category, &$params, 0));
         } else {
             $results = $dispatcher->trigger('onPrepareContent', array(&$category, &$params, 0));
         }
         $category->description = $category->text;
     }
     // Maybe here not to import all plugins but just those for description field or add a parameter for this
     // Anyway these events are usually not very time consuming as is the the event onPrepareContent(J1.5)/onContentPrepare(J1.6+)
     JPluginHelper::importPlugin('content');
     foreach ($items as $item) {
         $item->event = new stdClass();
         $item->params = FLEXI_J16GE ? new JRegistry($item->attribs) : new JParameter($item->attribs);
         // !!! The triggering of the event onPrepareContent(J1.5)/onContentPrepare(J1.6+) of content plugins
         // !!! for description field (maintext) along with all other flexicontent
         // !!! fields is handled by flexicontent.fields.php
         // !!! Had serious performance impact
         // CODE REMOVED
         // We must check if the current category is in the categories of the item ..
         $item_in_category = false;
         if ($item->catid == $category->id) {
             $item_in_category = true;
         } else {
             foreach ($item->cats as $cat) {
                 if ($cat->id == $category->id) {
                     $item_in_category = true;
                     break;
                 }
             }
         }
         // ADVANCED CATEGORY ROUTING (=set the most appropriate category for the item ...)
         // CHOOSE APPROPRIATE category-slug FOR THE ITEM !!! ( )
         if ($item_in_category && !in_array($category->id, $globalnoroute)) {
             // 1. CATEGORY SLUG: CURRENT category
             // Current category IS a category of the item and ALSO routing (creating links) to this category is allowed
             $item->categoryslug = $category->slug;
         } else {
             if (!in_array($item->catid, $globalnoroute)) {
                 // 2. CATEGORY SLUG: ITEM's MAIN category   (alread SET, ... no assignment needed)
                 // Since we cannot use current category (above), we will use item's MAIN category
                 // ALSO routing (creating links) to this category is allowed
             } else {
                 // 3. CATEGORY SLUG: ANY ITEM's category
                 // We will use the first for which routing (creating links) to the category is allowed
                 $allcats = array();
                 $item->cats = $item->cats ? $item->cats : array();
                 foreach ($item->cats as $cat) {
                     if (!in_array($cat->id, $globalnoroute)) {
                         $item->categoryslug = $globalcats[$cat->id]->slug;
                         break;
                     }
                 }
             }
         }
         // Just put item's text (description field) inside property 'text' in case the events modify the given text,
         $item->text = isset($item->fields['text']->display) ? $item->fields['text']->display : '';
         // Set the view and option to 'category' and 'com_content'  (actually view is already called category)
         JRequest::setVar('option', 'com_content');
         JRequest::setVar("isflexicontent", "yes");
         // These events return text that could be displayed at appropriate positions by our templates
         $item->event = new stdClass();
         if (FLEXI_J16GE) {
             $results = $dispatcher->trigger('onContentAfterTitle', array('com_content.category', &$item, &$params, 0));
         } else {
             $results = $dispatcher->trigger('onAfterDisplayTitle', array(&$item, &$params, $limitstart));
         }
         $item->event->afterDisplayTitle = trim(implode("\n", $results));
         if (FLEXI_J16GE) {
             $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_content.category', &$item, &$params, 0));
         } else {
             $results = $dispatcher->trigger('onBeforeDisplayContent', array(&$item, &$params, $limitstart));
         }
         $item->event->beforeDisplayContent = trim(implode("\n", $results));
         if (FLEXI_J16GE) {
             $results = $dispatcher->trigger('onContentAfterDisplay', array('com_content.category', &$item, &$params, 0));
         } else {
             $results = $dispatcher->trigger('onAfterDisplayContent', array(&$item, &$params, $limitstart));
         }
         $item->event->afterDisplayContent = trim(implode("\n", $results));
         // Set the option back to 'com_flexicontent'
         JRequest::setVar('option', 'com_flexicontent');
         // Put text back into the description field, THESE events SHOULD NOT modify the item text, but some plugins may do it anyway... , so we assign text back for compatibility
         $item->fields['text']->display =& $item->text;
     }
     // Calculate CSS classes needed to add special styling markups to the items
     flexicontent_html::calculateItemMarkups($items, $params);
     // *****************************************************
     // Remove unroutable categories from sub/peer categories
     // *****************************************************
     // sub-cats
     $_categories = array();
     foreach ($categories as $i => $cat) {
         if (in_array($cat->id, $globalnoroute)) {
             continue;
         }
         $_categories[] = $categories[$i];
     }
     $categories = $_categories;
     // peer-cats
     $_categories = array();
     foreach ($peercats as $i => $cat) {
         if (in_array($cat->id, $globalnoroute)) {
             continue;
         }
         $_categories[] = $peercats[$i];
     }
     $peercats = $_categories;
     // ************************************
     // Get some variables needed for images
     // ************************************
     $joomla_image_path = $app->getCfg('image_path', FLEXI_J16GE ? '' : 'images' . DS . 'stories');
     $joomla_image_url = str_replace(DS, '/', $joomla_image_path);
     $joomla_image_path = $joomla_image_path ? $joomla_image_path . DS : '';
     $joomla_image_url = $joomla_image_url ? $joomla_image_url . '/' : '';
     // **************
     // CATEGORY IMAGE
     // **************
     // category image params
     $show_cat_image = $params->get('show_description_image', 0);
     // we use different name for variable
     $cat_image_source = $params->get('cat_image_source', 2);
     // 0: extract, 1: use param, 2: use both
     $cat_link_image = $params->get('cat_link_image', 1);
     $cat_image_method = $params->get('cat_image_method', 1);
     $cat_image_width = $params->get('cat_image_width', 80);
     $cat_image_height = $params->get('cat_image_height', 80);
     $cat = $category;
     $image = "";
     if ($cat) {
         if ($cat->id && $show_cat_image) {
             $cat->image = FLEXI_J16GE ? $params->get('image') : $cat->image;
             $image = "";
             $cat->introtext =& $cat->description;
             $cat->fulltext = "";
             if ($cat_image_source && $cat->image && JFile::exists(JPATH_SITE . DS . $joomla_image_path . $cat->image)) {
                 $src = JURI::base(true) . "/" . $joomla_image_url . $cat->image;
                 $h = '&amp;h=' . $cat_image_height;
                 $w = '&amp;w=' . $cat_image_width;
                 $aoe = '&amp;aoe=1';
                 $q = '&amp;q=95';
                 $zc = $cat_image_method ? '&amp;zc=' . $cat_image_method : '';
                 $ext = pathinfo($src, PATHINFO_EXTENSION);
                 $f = in_array($ext, array('png', 'ico', 'gif')) ? '&amp;f=' . $ext : '';
                 $conf = $w . $h . $aoe . $q . $zc . $f;
                 $image = JURI::base(true) . '/components/com_flexicontent/librairies/phpthumb/phpThumb.php?src=' . $src . $conf;
             } else {
                 if ($cat_image_source != 1 && ($src = flexicontent_html::extractimagesrc($cat))) {
                     $h = '&amp;h=' . $cat_image_height;
                     $w = '&amp;w=' . $cat_image_width;
                     $aoe = '&amp;aoe=1';
                     $q = '&amp;q=95';
                     $zc = $cat_image_method ? '&amp;zc=' . $cat_image_method : '';
                     $ext = pathinfo($src, PATHINFO_EXTENSION);
                     $f = in_array($ext, array('png', 'ico', 'gif')) ? '&amp;f=' . $ext : '';
                     $conf = $w . $h . $aoe . $q . $zc . $f;
                     $base_url = !preg_match("#^http|^https|^ftp|^/#i", $src) ? JURI::base(true) . '/' : '';
                     $src = $base_url . $src;
                     $image = JURI::base(true) . '/components/com_flexicontent/librairies/phpthumb/phpThumb.php?src=' . $src . $conf;
                 }
             }
             $cat->image_src = @$src;
             // Also add image category URL for developers
             if ($image) {
                 $image = '<img class="fccat_image" src="' . $image . '" alt="' . $this->escape($cat->title) . '" title="' . $this->escape($cat->title) . '"/>';
             } else {
                 //$image = '<div class="fccat_image" style="height:'.$cat_image_height.'px;width:'.$cat_image_width.'px;" ></div>';
             }
             if ($cat_link_image && $image) {
                 $image = '<a href="' . JRoute::_(FlexicontentHelperRoute::getCategoryRoute($cat->slug)) . '">' . $image . '</a>';
             }
         }
         $cat->image = $image;
     }
     // ******************************
     // SUBCATEGORIES (some templates)
     // ******************************
     // sub-category image params
     $show_cat_image = $params->get('show_description_image_subcat', 1);
     // we use different name for variable
     $cat_image_source = $params->get('subcat_image_source', 2);
     // 0: extract, 1: use param, 2: use both
     $cat_link_image = $params->get('subcat_link_image', 1);
     $cat_image_method = $params->get('subcat_image_method', 1);
     $cat_image_width = $params->get('subcat_image_width', 24);
     $cat_image_height = $params->get('subcat_image_height', 24);
     // Create sub-category image/description/etc data
     foreach ($categories as $cat) {
         $image = "";
         if ($show_cat_image) {
             if (FLEXI_J16GE && !is_object($cat->params)) {
                 $cat->params = new JRegistry($cat->params);
             }
             $cat->image = FLEXI_J16GE ? $cat->params->get('image') : $cat->image;
             $image = "";
             $cat->introtext =& $cat->description;
             $cat->fulltext = "";
             if ($cat_image_source && $cat->image && JFile::exists(JPATH_SITE . DS . $joomla_image_path . $cat->image)) {
                 $src = JURI::base(true) . "/" . $joomla_image_url . $cat->image;
                 $h = '&amp;h=' . $cat_image_height;
                 $w = '&amp;w=' . $cat_image_width;
                 $aoe = '&amp;aoe=1';
                 $q = '&amp;q=95';
                 $zc = $cat_image_method ? '&amp;zc=' . $cat_image_method : '';
                 $ext = pathinfo($src, PATHINFO_EXTENSION);
                 $f = in_array($ext, array('png', 'ico', 'gif')) ? '&amp;f=' . $ext : '';
                 $conf = $w . $h . $aoe . $q . $zc . $f;
                 $image = JURI::base(true) . '/components/com_flexicontent/librairies/phpthumb/phpThumb.php?src=' . $src . $conf;
             } else {
                 if ($cat_image_source != 1 && ($src = flexicontent_html::extractimagesrc($cat))) {
                     $h = '&amp;h=' . $cat_image_height;
                     $w = '&amp;w=' . $cat_image_width;
                     $aoe = '&amp;aoe=1';
                     $q = '&amp;q=95';
                     $zc = $cat_image_method ? '&amp;zc=' . $cat_image_method : '';
                     $ext = pathinfo($src, PATHINFO_EXTENSION);
                     $f = in_array($ext, array('png', 'ico', 'gif')) ? '&amp;f=' . $ext : '';
                     $conf = $w . $h . $aoe . $q . $zc . $f;
                     $base_url = !preg_match("#^http|^https|^ftp|^/#i", $src) ? JURI::base(true) . '/' : '';
                     $src = $base_url . $src;
                     $image = JURI::base(true) . '/components/com_flexicontent/librairies/phpthumb/phpThumb.php?src=' . $src . $conf;
                 }
             }
             $cat->image_src = @$src;
             // Also add image category URL for developers
             if ($image) {
                 $image = '<img class="fccat_image" src="' . $image . '" alt="' . $this->escape($cat->title) . '" title="' . $this->escape($cat->title) . '"/>';
             } else {
                 //$image = '<div class="fccat_image" style="height:'.$cat_image_height.'px;width:'.$cat_image_width.'px;" ></div>';
             }
             if ($cat_link_image && $image) {
                 $image = '<a href="' . JRoute::_(FlexicontentHelperRoute::getCategoryRoute($cat->slug)) . '">' . $image . '</a>';
             }
         }
         $cat->image = $image;
     }
     // *******************************
     // PEERCATEGORIES (some templates)
     // *******************************
     // peer-category image params
     $show_cat_image = $params->get('show_description_image_peercat', 1);
     // we use different name for variable
     $cat_image_source = $params->get('peercat_image_source', 2);
     // 0: extract, 1: use param, 2: use both
     $cat_link_image = $params->get('peercat_link_image', 1);
     $cat_image_method = $params->get('peercat_image_method', 1);
     $cat_image_width = $params->get('peercat_image_width', 24);
     $cat_image_height = $params->get('peercat_image_height', 24);
     // Create peer-category image/description/etc data
     foreach ($peercats as $cat) {
         $image = "";
         if ($show_cat_image) {
             if (FLEXI_J16GE && !is_object($cat->params)) {
                 $cat->params = new JRegistry($cat->params);
             }
             $cat->image = FLEXI_J16GE ? $cat->params->get('image') : $cat->image;
             $image = "";
             $cat->introtext =& $cat->description;
             $cat->fulltext = "";
             if ($cat_image_source && $cat->image && JFile::exists(JPATH_SITE . DS . $joomla_image_path . $cat->image)) {
                 $src = JURI::base(true) . "/" . $joomla_image_url . $cat->image;
                 $h = '&amp;h=' . $cat_image_height;
                 $w = '&amp;w=' . $cat_image_width;
                 $aoe = '&amp;aoe=1';
                 $q = '&amp;q=95';
                 $zc = $cat_image_method ? '&amp;zc=' . $cat_image_method : '';
                 $ext = pathinfo($src, PATHINFO_EXTENSION);
                 $f = in_array($ext, array('png', 'ico', 'gif')) ? '&amp;f=' . $ext : '';
                 $conf = $w . $h . $aoe . $q . $zc . $f;
                 $image = JURI::base(true) . '/components/com_flexicontent/librairies/phpthumb/phpThumb.php?src=' . $src . $conf;
             } else {
                 if ($cat_image_source != 1 && ($src = flexicontent_html::extractimagesrc($cat))) {
                     $h = '&amp;h=' . $cat_image_height;
                     $w = '&amp;w=' . $cat_image_width;
                     $aoe = '&amp;aoe=1';
                     $q = '&amp;q=95';
                     $zc = $cat_image_method ? '&amp;zc=' . $cat_image_method : '';
                     $ext = pathinfo($src, PATHINFO_EXTENSION);
                     $f = in_array($ext, array('png', 'ico', 'gif')) ? '&amp;f=' . $ext : '';
                     $conf = $w . $h . $aoe . $q . $zc . $f;
                     $base_url = !preg_match("#^http|^https|^ftp|^/#i", $src) ? JURI::base(true) . '/' : '';
                     $src = $base_url . $src;
                     $image = JURI::base(true) . '/components/com_flexicontent/librairies/phpthumb/phpThumb.php?src=' . $src . $conf;
                 }
             }
             $cat->image_src = @$src;
             // Also add image category URL for developers
             if ($image) {
                 $image = '<img class="fccat_image" src="' . $image . '" alt="' . $this->escape($cat->title) . '" title="' . $this->escape($cat->title) . '"/>';
             } else {
                 //$image = '<div class="fccat_image" style="height:'.$cat_image_height.'px;width:'.$cat_image_width.'px;" ></div>';
             }
             if ($cat_link_image && $image) {
                 $image = '<a href="' . JRoute::_(FlexicontentHelperRoute::getCategoryRoute($cat->slug)) . '">' . $image . '</a>';
             }
         }
         $cat->image = $image;
     }
     // remove previous alpha index filter
     //$uri->delVar('letter');
     // remove filter variables (includes search box and sort order)
     preg_match_all('/filter[^=]*/', $uri->toString(), $matches);
     foreach ($matches[0] as $match) {
         //$uri->delVar($match);
     }
     // Build Lists
     $lists = array();
     //ordering
     $lists['filter_order'] = JRequest::getCmd('filter_order', 'i.title', 'default');
     $lists['filter_order_Dir'] = JRequest::getCmd('filter_order_Dir', 'ASC', 'default');
     $lists['filter'] = JRequest::getString('filter', '', 'default');
     // Add html to filter objects
     $form_name = 'adminForm';
     if ($filters) {
         FlexicontentFields::renderFilters($params, $filters, $form_name);
     }
     // ****************************
     // Create the pagination object
     // ****************************
     $pageNav = $this->get('pagination');
     $resultsCounter = $pageNav->getResultsCounter();
     // for overriding model's result counter
     // *********************************************************************
     // Create category link, but also consider current 'layout', and use the
     // layout specific variables so that filtering form will work properly
     // *********************************************************************
     $Itemid = $menu ? $menu->id : 0;
     $layout_vars = array();
     if ($layout) {
         $layout_vars['layout'] = $layout;
     }
     if ($authorid) {
         $layout_vars['authorid'] = $authorid;
     }
     if ($tagid) {
         $layout_vars['tagid'] = $tagid;
     }
     if ($cids) {
         $layout_vars['cids'] = $cids;
     }
     // Category link for single/multiple category(-ies)  --OR--  "current layout" link for myitems/author layouts
     if ($cid) {
         $category_link = JRoute::_(FlexicontentHelperRoute::getCategoryRoute($category->slug, $Itemid, $layout_vars), false);
     } else {
         $urlvars_str = '';
         foreach ($layout_vars as $urlvar_name => $urlvar_val) {
             $urlvars_str .= '&' . $urlvar_name . '=' . $urlvar_val;
         }
         $category_link = JRoute::_('index.php?Itemid=' . $Itemid . '&option=com_flexicontent&view=category' . $urlvars_str . ($Itemid ? '&Itemid=' . $Itemid : ''));
     }
     // **********************************************************************
     // Print link ... must include layout and current filtering url vars, etc
     // **********************************************************************
     $curr_url = $_SERVER['REQUEST_URI'];
     $print_link = $curr_url . (strstr($curr_url, '?') ? '&amp;' : '?') . 'pop=1&amp;tmpl=component&amp;print=1';
     $pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx'));
     $this->assignRef('action', $category_link);
     // $uri->toString()
     $this->assignRef('print_link', $print_link);
     $this->assignRef('category', $category);
     $this->assignRef('categories', $categories);
     $this->assignRef('peercats', $peercats);
     $this->assignRef('items', $items);
     $this->assignRef('authordescr_item_html', $authordescr_item_html);
     $this->assignRef('lists', $lists);
     $this->assignRef('params', $params);
     $this->assignRef('pageNav', $pageNav);
     $this->assignRef('pageclass_sfx', $pageclass_sfx);
     $this->assignRef('pagination', $pageNav);
     // compatibility Alias for old templates
     $this->assignRef('resultsCounter', $resultsCounter);
     // for overriding model's result counter
     $this->assignRef('limitstart', $limitstart);
     // compatibility shortcut
     $this->assignRef('filters', $filters);
     $this->assignRef('comments', $comments);
     $this->assignRef('alpha', $alpha);
     $this->assignRef('tmpl', $tmpl);
     /*
      * Set template paths : this procedure is issued from K2 component
      *
      * "K2" Component by JoomlaWorks for Joomla! 1.5.x - Version 2.1
      * Copyright (c) 2006 - 2009 JoomlaWorks Ltd. All rights reserved.
      * Released under the GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
      * More info at http://www.joomlaworks.gr and http://k2.joomlaworks.gr
      * Designed and developed by the JoomlaWorks team
      */
     $this->addTemplatePath(JPATH_COMPONENT . DS . 'templates');
     $this->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS . 'com_flexicontent' . DS . 'templates');
     $this->addTemplatePath(JPATH_COMPONENT . DS . 'templates' . DS . 'default');
     $this->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS . 'com_flexicontent' . DS . 'templates' . DS . 'default');
     if ($clayout) {
         $this->addTemplatePath(JPATH_COMPONENT . DS . 'templates' . DS . $clayout);
         $this->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS . 'com_flexicontent' . DS . 'templates' . DS . $clayout);
     }
     // **************************************************
     // increment the hit counter ONLY once per user visit
     // **************************************************
     // MOVED to flexisystem plugin due to ...
     /*if (FLEXI_J16GE && $category->id && empty($layout)) {
     			$hit_accounted = false;
     			$hit_arr = array();
     			if ($session->has('cats_hit', 'flexicontent')) {
     				$hit_arr 	= $session->get('cats_hit', array(), 'flexicontent');
     				$hit_accounted = isset($hit_arr[$category->id]);
     			}
     			if (!$hit_accounted) {
     				//add hit to session hit array
     				$hit_arr[$category->id] = $timestamp = time();  // Current time as seconds since Unix epoc;
     				$session->set('cats_hit', $hit_arr, 'flexicontent');
     				$this->getModel()->hit();
     			}
     		}*/
     $print_logging_info = $params->get('print_logging_info');
     if ($print_logging_info) {
         global $fc_run_times;
         $start_microtime = microtime(true);
     }
     parent::display($tpl);
     if ($print_logging_info) {
         @($fc_run_times['template_render'] += round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10);
     }
 }
Exemplo n.º 21
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);
 }
Exemplo n.º 22
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);
 }
Exemplo n.º 23
0
 protected function getInput()
 {
     $node =& $this->element;
     $attributes = get_object_vars($node->attributes());
     $attributes = $attributes['@attributes'];
     $themes = flexicontent_tmpl::getTemplates();
     $tmpls_all = $themes->category ? $themes->category : array();
     $value = $this->value;
     //$value = $value ? $value : @$attributes['default'];
     $view = JRequest::getVar('view');
     $controller = JRequest::getVar('controller');
     $app = JFactory::getApplication();
     $db = JFactory::getDBO();
     $cparams = JComponentHelper::getParams('com_flexicontent');
     // GET LIMITING to specific templates according to item's type, or according to type of new item
     $allowed_tmpls = array();
     $all_tmpl_allowed = true;
     $conf_default_layout = '';
     $conf_default_layout_mobile = '';
     $tmpls = array();
     $lays = array();
     foreach ($tmpls_all as $tmpl) {
         if ($all_tmpl_allowed || in_array($tmpl->name, $allowed_tmpls)) {
             $tmpls[] = $tmpl;
             $lays[] = $tmpl->name;
         }
     }
     $lays = implode("','", $lays);
     if (@$attributes['enableparam']) {
         $cparams = JComponentHelper::getParams('com_flexicontent');
         if (!$cparams->get($attributes['enableparam'])) {
             return FLEXI_J16GE ? '' : JText::_('FLEXI_DISABLED');
         }
     }
     if (!@$attributes['skipparams']) {
         $doc = JFactory::getDocument();
         $js = "\nvar tmpl = ['" . $lays . "'];\n\nfunction disablePanel(element) {\n\tif ( ! jQuery('#'+element+'-attribs-options') ) return;\n\t\n\tvar panel \t= jQuery('#'+element+'-attribs-options').next();\n\tvar selects = panel.find('select');\n\tvar inputs \t= panel.find('input');\n\tpanel.parent().addClass('pane-disabled');\n\tselects.each(function(index){\n\t\tjQuery(this).attr('disabled', 'disabled');\n\t});\n\tinputs.each(function(index){\n\t\tjQuery(this).attr('disabled', 'disabled');\n\t});\n\tpanel.parent().css('display','none');\n}\n\nfunction enablePanel(element) {\n\tif ( ! jQuery('#'+element+'-attribs-options') ) return;\n\t\n\tvar panel \t= jQuery('#'+element+'-attribs-options').next();\n\tvar selects = panel.find('select');\n\tvar inputs \t= panel.find('input');\n\tpanel.parent().removeClass('pane-disabled');\n\tselects.each(function(index){\n\t\tjQuery(this).removeAttr('disabled');\n\t});\n\tinputs.each(function(index){\n\t\tjQuery(this).removeAttr('disabled');\n\t});\n\tpanel.parent().css('display','');\n}\n\nfunction activatePanel(active) {\n\tvar inactives = jQuery.grep(tmpl, function( item, index ) {\n\t\treturn item != active;\n\t});\n\t\n\tinactives.each(function(el){\n\t\tdisablePanel(el);\n\t});\n\t\n\tif (active) {\n\t\tenablePanel(active);\n\t}\n}\n\njQuery(document).ready(function() {\n\tactivatePanel('" . $value . "');\n});\n";
         $doc->addScriptDeclaration($js);
     }
     $layouts = array();
     if (@$attributes['firstoption']) {
         $layouts[] = JHTMLSelect::option('', JText::_($attributes['firstoption']));
     } else {
         $layouts[] = JHTMLSelect::option('', '-- ' . JText::_('FLEXI_USE_GLOBAL') . ' --');
     }
     foreach ($tmpls as $tmpl) {
         $layouts[] = JHTMLSelect::option($tmpl->name, $tmpl->name);
     }
     $fieldname = $this->name;
     $element_id = $this->id;
     $attribs = '';
     if (@$attributes['multiple'] == 'multiple' || @$attributes['multiple'] == 'true') {
         $attribs .= ' multiple="multiple" ';
         $attribs .= @$attributes['size'] ? ' size="' . @$attributes['size'] . '" ' : ' size="6" ';
     }
     if (@$attributes['class']) {
         $attribs .= 'class="' . $attributes['class'] . '"';
     }
     if (!@$attributes['skipparams']) {
         $attribs .= ' onchange="activatePanel(this.value);"';
     }
     if ($inline_tip = @$attributes['inline_tip']) {
         $tip_img = @$attributes['tip_img'];
         $tip_img = $tip_img ? $tip_img : 'comment.png';
         $preview_img = @$attributes['preview_img'];
         $preview_img = $preview_img ? $preview_img : '';
         $tip_class = @$attributes['tip_class'];
         $tip_class .= FLEXI_J30GE ? ' hasTooltip' : ' hasTip';
         $hintmage = JHTML::image('administrator/components/com_flexicontent/assets/images/' . $tip_img, JText::_('FLEXI_NOTES'), ' style="max-height:24px; padding:0px; margin-left:12px; margin-right:0px;" ');
         $previewimage = $preview_img ? JHTML::image('administrator/components/com_flexicontent/assets/images/' . $preview_img, JText::_('FLEXI_NOTES'), ' style="max-height:24px; padding:0px; margin:0px;" ') : '';
         $tip_text = '<span class="' . $tip_class . '" style="" title="' . flexicontent_html::getToolTip(null, $inline_tip, 1, 1) . '">' . $hintmage . $previewimage . '</span>';
     }
     if ($inline_tip = @$attributes['inline_tip2']) {
         $tip_img = @$attributes['tip_img2'];
         $tip_img = $tip_img ? $tip_img : 'comment.png';
         $preview_img = @$attributes['preview_img2'];
         $preview_img = $preview_img ? $preview_img : '';
         $tip_class = @$attributes['tip_class2'];
         $tip_class .= FLEXI_J30GE ? ' hasTooltip' : ' hasTip';
         $hintmage = JHTML::image('administrator/components/com_flexicontent/assets/images/' . $tip_img, JText::_('FLEXI_NOTES'), ' style="max-height:24px; padding:0px; margin-left:12px; margin-right:0px;" ');
         $previewimage = $preview_img ? JHTML::image('administrator/components/com_flexicontent/assets/images/' . $preview_img, JText::_('FLEXI_NOTES'), ' style="max-height:24px; padding:0px; margin:0px;" ') : '';
         $tip_text2 = '<span class="' . $tip_class . '" style="" title="' . flexicontent_html::getToolTip(null, $inline_tip, 1, 1) . '">' . $hintmage . $previewimage . '</span>';
     }
     return JHTML::_('select.genericlist', $layouts, $fieldname, $attribs, 'value', 'text', $value, $element_id) . @$tip_text . @$tip_text2;
 }
 static function getTemplates($lang_files = 'all')
 {
     $flexiparams = JComponentHelper::getParams('com_flexicontent');
     $print_logging_info = $flexiparams->get('print_logging_info');
     // Log content plugin and other performance information
     if ($print_logging_info) {
         global $fc_run_times;
         $start_microtime = microtime(true);
     }
     if (!FLEXI_J30GE) {
         // && FLEXI_CACHE  ,  Ignore cache settings since XML parsing in J1.5/J2.5 is costly
         // add the templates to templates cache
         $tmplcache = JFactory::getCache('com_flexicontent_tmpl');
         $tmplcache->setCaching(1);
         // Force cache ON
         $tmplcache->setLifeTime(24 * 3600);
         // Set expire time (hard-code this to 1 day), since it is costly
         $tmpls = $tmplcache->call(array('flexicontent_tmpl', 'parseTemplates'));
         $cached = 1;
     } else {
         $tmpls = flexicontent_tmpl::parseTemplates();
         $cached = 0;
     }
     // Load Template-Specific language file(s) to override or add new language strings
     if ($lang_files == 'all') {
         foreach ($tmpls->category as $tmpl => $d) {
             FLEXIUtilities::loadTemplateLanguageFile($tmpl);
         }
     } else {
         if (is_array($lang_files)) {
             foreach ($lang_files as $tmpl) {
                 FLEXIUtilities::loadTemplateLanguageFile($tmpl);
             }
         } else {
             if (is_string($lang_files)) {
                 FLEXIUtilities::loadTemplateLanguageFile($lang_files);
             }
         }
     }
     if ($print_logging_info) {
         $fc_run_times[$cached ? 'templates_parsing_cached' : 'templates_parsing_noncached'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
     }
     return $tmpls;
 }
Exemplo n.º 25
0
 /**
  * Method to decide which item layout to use
  *
  * @access	public
  * @param	int item identifier
  */
 function decideLayout(&$params)
 {
     // *********************************************************************************
     // Get category layout from configuration if not already set (e.g. via HTTP Request)
     // *********************************************************************************
     //echo "decideLayout: ". $this->_clayout ."<br/>";
     $clayout = $this->_clayout;
     if (!$clayout) {
         // Decide to use mobile or normal category template layout
         $useMobile = $params->get('use_mobile_layouts', 0);
         if ($useMobile) {
             $force_desktop_layout = $params->get('force_desktop_layout', 0);
             $mobileDetector = flexicontent_html::getMobileDetector();
             $isMobile = $mobileDetector->isMobile();
             $isTablet = $mobileDetector->isTablet();
             $useMobile = $force_desktop_layout ? $isMobile && !$isTablet : $isMobile;
         }
         $desktop_clayout = $params->get('clayout', 'blog');
         $clayout = !$useMobile ? $desktop_clayout : $params->get('clayout_mobile', $desktop_clayout);
     }
     // Get cached template data, without loading language file, (this will be done at the view)
     $themes = flexicontent_tmpl::getTemplates(null);
     // *********************************
     // Verify the category layout exists
     // *********************************
     if (!isset($themes->category->{$clayout})) {
         $cat_default_layout = 'blog';
         // Layout default
         $fixed_clayout = isset($themes->category->{$cat_default_layout}) ? $cat_default_layout : 'default';
         JFactory::getApplication()->enqueueMessage("<small>Current category Layout (template) is '{$clayout}' does not exist<br/>- Please correct this in the URL or in Content Type configuration.<br/>- Using Template Layout: '{$fixed_clayout}'</small>", 'notice');
         $clayout = $fixed_clayout;
         FLEXIUtilities::loadTemplateLanguageFile($clayout);
         // Manually load Template-Specific language file of back fall clayout
     }
     // *****************************************************************************************
     // Finally set the clayout (template name) into model / category's parameters / HTTP Request
     // *****************************************************************************************
     $this->setCatLayout($clayout);
     $params->set('clayout', $clayout);
     JRequest::setVar('clayout', $clayout);
 }
Exemplo n.º 26
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();
        $config = JFactory::getConfig();
        $session = JFactory::getSession();
        $user = JFactory::getUser();
        $db = JFactory::getDBO();
        $option = JRequest::getVar('option');
        $nullDate = $db->getNullDate();
        // Get the COMPONENT only parameters
        // Get component parameters
        $params = new JRegistry();
        $cparams = JComponentHelper::getParams('com_flexicontent');
        $params->merge($cparams);
        $params = clone JComponentHelper::getParams('com_flexicontent');
        // Some flags
        $enable_translation_groups = flexicontent_db::useAssociations();
        //$params->get("enable_translation_groups");
        $print_logging_info = $params->get('print_logging_info');
        if ($print_logging_info) {
            global $fc_run_times;
        }
        // *****************
        // Load 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);
        // Fields common CSS
        $document->addStyleSheetVersion(JURI::root(true) . '/components/com_flexicontent/assets/css/flexi_form_fields.css', FLEXI_VERSION);
        // Add JS frameworks
        flexicontent_html::loadFramework('select2');
        $prettycheckable_added = flexicontent_html::loadFramework('prettyCheckable');
        flexicontent_html::loadFramework('flexi-lib');
        // 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);
        // Add js function for custom code used by FLEXIcontent item form
        $document->addScriptVersion(JURI::root(true) . '/components/com_flexicontent/assets/js/itemscreen.js', FLEXI_VERSION);
        // ***********************
        // Get data from the model
        // ***********************
        if ($print_logging_info) {
            $start_microtime = microtime(true);
        }
        $model = $this->getModel();
        $item = $model->getItem();
        $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');
        }
        $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
        if ($cid) {
            $unique_tmp_itemid = $cid;
        } else {
            $unique_tmp_itemid = $app->getUserState('com_flexicontent.edit.item.unique_tmp_itemid');
            $unique_tmp_itemid = $unique_tmp_itemid ? $unique_tmp_itemid : date('_Y_m_d_h_i_s_', time()) . uniqid(true);
        }
        //print_r($unique_tmp_itemid);
        JRequest::setVar('unique_tmp_itemid', $unique_tmp_itemid);
        // 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);
        // Create display of average rating
        $ratings = $model->getRatingDisplay();
        // *****************
        // 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 = new JRegistry($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);
        if (!$perms['canparams']) {
            $document->addStyleDeclaration('#details-options {display:none;}');
        }
        // ******************
        // Create the toolbar
        // ******************
        $toolbar = JToolBar::getInstance('toolbar');
        $tip_class = FLEXI_J30GE ? ' hasTooltip' : ' hasTip';
        // 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
        }
        // **************
        // Common Buttons
        // **************
        // Applying new item type is a special case that has not loaded custom fieds yet
        JToolBarHelper::apply($item->type_id ? 'items.apply' : 'items.apply_type', !$isnew ? 'FLEXI_APPLY' : ($typesselected->id ? 'FLEXI_ADD' : 'FLEXI_APPLY_TYPE'), false);
        /*if (!$isnew || $item->version) flexicontent_html::addToolBarButton(
        		'FLEXI_FAST_APPLY', $btn_name='apply_ajax', $full_js="Joomla.submitbutton('items.apply_ajax')", $msg_alert='', $msg_confirm='',
        		$btn_task='items.apply_ajax', $extra_js='', $btn_list=false, $btn_menu=true, $btn_confirm=false, $btn_class="".$tip_class, $btn_icon="icon-loop",
        		'data-placement="bottom" title="Fast saving, without reloading the form. <br/><br/>Note: new files will not be uploaded, <br/>- in such a case please use \'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');
        // ***********************
        // Add a preview button(s)
        // ***********************
        //$_sh404sef = JPluginHelper::isEnabled('system', 'sh404sef') && $config->get('sef');
        $_sh404sef = defined('SH404SEF_IS_RUNNING') && $config->get('sef');
        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
            // we do not remove 'isAdmin' check so that we can copy later without change, e.g. to a plugin
            $isAdmin = JFactory::getApplication()->isAdmin();
            if ($isAdmin && !$_sh404sef) {
                JFactory::$application = JApplication::getInstance('site');
            }
            // Create the URL
            $item_url = FlexicontentHelperRoute::getItemRoute($item->id . ':' . $item->alias, $categories[$item->catid]->slug) . ($item->language != '*' ? '&lang=' . substr($item->language, 0, 2) : '');
            $item_url = $_sh404sef ? Sh404sefHelperGeneral::getSefFromNonSef($item_url, $fullyQualified = true, $xhtml = false, $ssl = null) : JRoute::_($item_url);
            // 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 && !$_sh404sef) {
                $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');
            }
            $previewlink = $item_url . (strstr($item_url, '?') ? '&amp;' : '?') . 'preview=1' . $autologin;
            //$previewlink     = str_replace('&amp;', '&', $previewlink);
            //$previewlink = JRoute::_(JURI::root() . FlexicontentHelperRoute::getItemRoute($item->id.':'.$item->alias, $categories[$item->catid]->slug)) .$autologin;
            // PREVIEW for latest version
            if (!$params->get('use_versioning', 1) || $item->version == $item->current_version && $item->version == $item->last_version) {
                $toolbar->appendButton('Custom', '<button class="preview btn btn-small btn-info spaced-btn" onClick="window.open(\'' . $previewlink . '\');"><span title="' . JText::_('Preview') . '" class="icon-screen"></span>' . JText::_('Preview') . '</button>', 'preview');
            } else {
                // Add a preview button for (currently) LOADED version of the item
                $previewlink_loaded_ver = $previewlink . '&version=' . $item->version;
                $toolbar->appendButton('Custom', '<button class="preview btn btn-small" onClick="window.open(\'' . $previewlink_loaded_ver . '\');" target="_blank"><span title="' . JText::_('Preview') . '" class="icon-screen"></span>' . JText::_('FLEXI_PREVIEW_FORM_LOADED_VERSION') . ' [' . $item->version . ']</button>', 'preview');
                // Add a preview button for currently ACTIVE version of the item
                $previewlink_active_ver = $previewlink . '&version=' . $item->current_version;
                $toolbar->appendButton('Custom', '<button class="preview btn btn-small" onClick="window.open(\'' . $previewlink_active_ver . '\');" target="_blank"><span title="' . JText::_('Preview') . '" class="icon-screen"></span>' . JText::_('FLEXI_PREVIEW_FRONTEND_ACTIVE_VERSION') . ' [' . $item->current_version . ']</button>', 'preview');
                // Add a preview button for currently LATEST version of the item
                $previewlink_last_ver = $previewlink;
                //'&version='.$item->last_version;
                $toolbar->appendButton('Custom', '<button class="preview btn btn-small" onClick="window.open(\'' . $previewlink_last_ver . '\');" target="_blank"><span title="' . JText::_('Preview') . '" class="icon-screen"></span>' . JText::_('FLEXI_PREVIEW_LATEST_SAVED_VERSION') . ' [' . $item->last_version . ']</button>', 'preview');
            }
            JToolBarHelper::spacer();
            JToolBarHelper::divider();
            JToolBarHelper::spacer();
        }
        // ************************
        // Add modal layout editing
        // ************************
        if ($perms['cantemplates']) {
            JToolBarHelper::divider();
            if (!$isnew || $item->version) {
                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=items&amp;tmpl=component&amp;ismodal=1&amp;folder=' . $item->itemparams->get('ilayout', $tparams->get('ilayout', 'default')) . '" title="Edit the display layout of this item. <br/><br/>Note: this layout maybe assigned to content types or other items, thus changing it will effect them too"');
            }
        }
        // Check if saving an item that translates an original content in site's default language
        $site_default = substr(flexicontent_html::getSiteDefaultLang(), 0, 2);
        $is_content_default_lang = $site_default == substr($item->language, 0, 2);
        // *****************************************************************************
        // 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');
        $item->fields =& $fields;
        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);
        }
        $jcustom = $app->getUserState('com_flexicontent.edit.item.custom');
        //print_r($jcustom);
        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 (isset($jcustom[$field->name])) {
                    $field->value = array();
                    foreach ($jcustom[$field->name] as $i => $_val) {
                        $field->value[$i] = $_val;
                    }
                }
                $is_editable = !$field->valueseditable || $user->authorise('flexicontent.editfieldvalues', 'com_flexicontent.field.' . $field->id);
                if ($is_editable) {
                    FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayField', array(&$field, &$item));
                    if ($field->untranslatable) {
                        $field->html = (!isset($field->html) ? '<div class="fc-mssg-inline fc-warning" style="margin:0 4px 6px 4px; max-width: unset;">' . JText::_('FLEXI_PLEASE_PUBLISH_THIS_PLUGIN') . '</div><div class="clear"></div>' : '') . '<div class="alert alert-info fc-small fc-iblock" style="margin:0 4px 6px 4px; max-width: unset;">' . JText::_('FLEXI_FIELD_VALUE_IS_NON_TRANSLATABLE') . '</div>' . "\n" . (isset($field->html) ? '<div class="clear"></div>' . $field->html : '');
                    }
                } else {
                    if ($field->valueseditable == 1) {
                        $field->html = '<div class="fc-mssg fc-note">' . JText::_($field->parameters->get('no_acc_msg_form') ? $field->parameters->get('no_acc_msg_form') : 'FLEXI_NO_ACCESS_LEVEL_TO_EDIT_FIELD') . '</div>';
                    } else {
                        if ($field->valueseditable == 2) {
                            FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayFieldValue', array(&$field, $item));
                            $field->html = '<div class="fc-mssg fc-note">' . JText::_($field->parameters->get('no_acc_msg_form') ? $field->parameters->get('no_acc_msg_form') : 'FLEXI_NO_ACCESS_LEVEL_TO_EDIT_FIELD') . '</div>' . "\n" . $field->display;
                        } else {
                            if ($field->valueseditable == 3) {
                                FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayFieldValue', array(&$field, $item));
                                $field->html = $field->display;
                            } else {
                                if ($field->valueseditable == 4) {
                                    $field->html = '';
                                    $field->formhidden = 4;
                                }
                            }
                        }
                    }
                }
            }
            // 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 state list
        $non_publishers_stategrp = $perms['isSuperAdmin'] || $item->state == -3 || $item->state == -4;
        $special_privelege_stategrp = $item->state == 2 || $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 == 2 || $perms['canarchive']) {
            $state[] = JHTML::_('select.option', 2, 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 = 'jform[state]';
        $elementid = 'jform_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-labeltext="' . JText::_($option_label) . '" data-labelPosition="right" data-customClass="fcradiocheck"';
                $lists['featured'] .= ' <input type="radio" id="' . $elementid_no . '" data-element-grpid="' . $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 = 'jform[vstate]';
        $elementid = 'jform_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-labeltext="' . JText::_($option_label) . '" data-labelPosition="right" data-customClass="fcradiocheck"';
            $lists['vstate'] .= ' <input type="radio" id="' . $elementid_no . '" data-element-grpid="' . $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 = 'jform[notify]';
                $elementid = 'jform_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-labeltext="' . $lbltxt . '" data-labelPosition="right" data-customClass="fcradiocheck"';
                $lists['notify'] = ' <input type="checkbox" id="' . $elementid . '" data-element-grpid="' . $elementid . '" name="' . $fieldname . '" ' . $attribs . ' value="1" ' . $extra_params . ' checked="checked" />';
                if (!$prettycheckable_added) {
                    $lists['notify'] .= '&nbsp;' . $lbltxt . '</label>';
                }
            }
        }
        // Retrieve author configuration
        $authorparams = flexicontent_db::getUserConfig($user->id);
        // Get author's maximum allowed categories per item and set js limitation
        $max_cat_assign = intval($authorparams->get('max_cat_assign', 0));
        $document->addScriptDeclaration('
			max_cat_assign_fc = ' . $max_cat_assign . ';
			existing_cats_fc  = ["' . implode('","', $selectedcats) . '"];
		');
        JText::script('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);
            $disabled_cats = $params->get('featured_cats_parent_disable', 1) ? array($featured_cats_parent) : array();
            $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 = 'jform[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, $require_all = true, $skip_subtrees = array(), $disable_subtrees = array(), $custom_options = array(), $disabled_cats);
        } 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);
                $disabled_cats = $tparams->get('cid_allowed_parent_disable', 1) ? array($tparams->get('cid_allowed_parent')) : array();
            } else {
                $cid_tree =& $categories;
                $disabled_cats = array();
            }
            // 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) . '"];
			');
            $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 = 'jform[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(), $custom_options = array(), $disabled_cats);
        } 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 = 'jform[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);
            $disabled_cats = $tparams->get('catid_allowed_parent_disable', 1) ? array($tparams->get('catid_allowed_parent')) : array();
        } else {
            $catid_tree =& $categories;
            $disabled_cats = array();
        }
        $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, $require_all = true, $skip_subtrees = array(), $disable_subtrees = array(), $custom_options = array(), $disabled_cats);
        } else {
            if (!$isnew && $item->catid) {
                $lists['catid'] = $globalcats[$item->catid]->title;
            }
        }
        //buid types selectlist
        $class = 'required use_select2_lib';
        $attribs = 'class="' . $class . '"';
        $fieldname = 'jform[type_id]';
        $elementid = 'jform_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
        $lists['languages'] = flexicontent_html::buildlanguageslist('jform[language]', 'class="use_select2_lib"', $item->language, 2, $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 (JHTML::_('date', $item->publish_down, 'Y') <= 1969 || $item->publish_down == $db->getNullDate() || empty($item->publish_down)) {
            $form->setValue('publish_down', null, '');
            // Setting to text will break form date element
        }
        // ****************************
        // 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 = 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) {
            $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);
                }
            }
        }
        // ******************************
        // 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('ratings', $ratings);
        $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);
        // Clear custom form data from session
        $app->setUserState($form->option . '.edit.' . $form->context . '.custom', false);
        $app->setUserState($form->option . '.edit.' . $form->context . '.jfdata', false);
        $app->setUserState($form->option . '.edit.' . $form->context . '.unique_tmp_itemid', false);
        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;
        }
    }
Exemplo n.º 27
0
 /**
  * Method to get the fields in their positions
  * 
  * @access private
  * @return object
  * @since 1.5
  */
 static function &renderPositions(&$items, $view = FLEXI_ITEMVIEW, $params = null, $use_tmpl = true, &$_rendered = array())
 {
     if (!$items) {
         return;
     }
     if (!$params) {
         return $items;
     }
     if ($view == 'category') {
         $layout = 'clayout';
     }
     if ($view == FLEXI_ITEMVIEW) {
         $layout = 'ilayout';
     }
     // field's source code, can use this JRequest variable, to detect who rendered the fields (e.g. they can detect rendering from 'module')
     JRequest::setVar("flexi_callview", $view);
     if ($use_tmpl && ($view == 'category' || $view == FLEXI_ITEMVIEW)) {
         $fbypos = flexicontent_tmpl::getFieldsByPositions($params->get($layout, 'default'), $view);
     } else {
         // $view == 'module', or other
         // Create a fake template position, for fields defined via parameters
         $fbypos[0] = new stdClass();
         $fbypos[0]->fields = explode(',', $params->get('fields'));
         $fbypos[0]->methods = explode(',', $params->get('methods'));
         $fbypos[0]->position = $view;
     }
     $always_create_fields_display = $params->get('always_create_fields_display', 0);
     // Render some fields by default, this is done for compatibility reasons, but avoid rendering these fields again (2nd time),
     // since some of them may also be in template positions. NOTE: this is not needed since renderField() should detect this case
     if ($always_create_fields_display != 3) {
         // value 3 means never create for any view (blog template incompatible)
         $item = reset($items);
         // get the first item ... so that we can get the name of CORE fields out of it
         // 'description' item field is implicitly used by category layout of some templates (blog), render it
         $custom_values = null;
         if ($view == 'category') {
             if (isset($item->fields['text']) && !isset($_rendered['ALL']['text'])) {
                 $_field_name_ = 'text';
                 FlexicontentFields::renderField($items, $_field_name_, $custom_values, $method = 'display', $view);
             }
             $_rendered['ALL']['text'] = 1;
         } else {
             if ($view == FLEXI_ITEMVIEW) {
                 foreach ($item->fields as $field) {
                     if ($field->iscore && !isset($_rendered['ALL'][$field->name])) {
                         $_field_name_ = $field->name;
                         FlexicontentFields::renderField($items, $_field_name_, $custom_values, $method = 'display', $view);
                     }
                 }
                 $_rendered['ALL']['core'] = 1;
             }
         }
     }
     // *** RENDER fields on DEMAND, (if present in template positions)
     foreach ($fbypos as $pos) {
         // RENDER fields if they are present in a template position (or in a dummy template position ... e.g. when called by module)
         foreach ($pos->fields as $c => $f) {
             // CORE/CUSTOM: Render field (if already rendered above, the function will return result immediately)
             $method = isset($pos->methods[$c]) && $pos->methods[$c] ? $pos->methods[$c] : 'display';
             // Render ANY CORE field with single call for all items, CORE fields are assigned to ALL types,
             // try to get field out of first item, if it does not exist, then field is a CUSTOM field
             $item = reset($items);
             $field = @$item->fields[$f];
             if ($field && $field->iscore) {
                 // Check if already rendered
                 if (!isset($_rendered['ALL']['core']) && !isset($_rendered['ALL'][$f])) {
                     // No custom values for CORE fields, values are decided inside the CORE field
                     $values = null;
                     FlexicontentFields::renderField($items, $f, $values, $method, $view);
                 }
                 $_rendered['ALL'][$f] = 1;
             } else {
                 foreach ($items as $item) {
                     // Check that field with given name: $f exists for current item (AKA, that it is assigned to the item's type)
                     if (!isset($item->fields[$f])) {
                         continue;
                     }
                     // Check if already rendered
                     if (isset($_rendered['ALL'][$f]) || isset($_rendered[$item->id][$f])) {
                         continue;
                     }
                     // Get field and field values, currently, custom field values can be passed only for CUSTOM fields, OR versioned CORE/CUSTOM fields too ...
                     $field = $item->fields[$f];
                     $values = isset($item->fieldvalues[$field->id]) ? $item->fieldvalues[$field->id] : array();
                     // Render the field's display
                     $field = FlexicontentFields::renderField($item, $field, $values, $method, $view);
                     $_rendered[$item->id][$f] = 1;
                 }
             }
             foreach ($items as $item) {
                 // Check that field with given name: $f exists for current item (AKA, that it is assigned to the item's type)
                 if (!isset($item->fields[$f])) {
                     continue;
                 }
                 $field = $item->fields[$f];
                 // Skip field if empty display was produced
                 if (!isset($field->display) || !strlen($field->display)) {
                     continue;
                 }
                 // Set field display HTML/data in the template position,
                 if (!isset($item->positions[$pos->position])) {
                     $item->positions[$pos->position] = new stdClass();
                 }
                 $item->positions[$pos->position]->{$f} = new stdClass();
                 $item->positions[$pos->position]->{$f}->id = $field->id;
                 $item->positions[$pos->position]->{$f}->id = $field->id;
                 $item->positions[$pos->position]->{$f}->name = $field->name;
                 $item->positions[$pos->position]->{$f}->label = $field->parameters->get('display_label') ? $field->label : '';
                 $item->positions[$pos->position]->{$f}->display = $field->display;
             }
         }
     }
     return $items;
 }
Exemplo n.º 28
0
    /**
     * Creates the item submit form
     *
     * @since 1.0
     */
    function _displayForm($tpl)
    {
        jimport('joomla.html.parameter');
        // ... we use some strings from administrator part
        // load english language file for 'com_content' component then override with current language file
        JFactory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR, 'en-GB', true);
        JFactory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR, null, true);
        // load english language file for 'com_flexicontent' component then override with current language file
        JFactory::getLanguage()->load('com_flexicontent', JPATH_ADMINISTRATOR, 'en-GB', true);
        JFactory::getLanguage()->load('com_flexicontent', JPATH_ADMINISTRATOR, null, true);
        // ********************************
        // Initialize variables, flags, etc
        // ********************************
        $app = JFactory::getApplication();
        $dispatcher = JDispatcher::getInstance();
        $document = JFactory::getDocument();
        $session = JFactory::getSession();
        $user = JFactory::getUser();
        $db = JFactory::getDBO();
        $uri = JFactory::getURI();
        $nullDate = $db->getNullDate();
        $menu = $app->getMenu()->getActive();
        // Get the COMPONENT only parameters, then merge the menu parameters
        $comp_params = JComponentHelper::getComponent('com_flexicontent')->params;
        $params = FLEXI_J16GE ? clone $comp_params : new JParameter($comp_params);
        // clone( JComponentHelper::getParams('com_flexicontent') );
        if ($menu) {
            $menu_params = FLEXI_J16GE ? $menu->params : new JParameter($menu->params);
            $params->merge($menu_params);
        }
        // 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');
        // Load custom behaviours: form validation, popup tooltips
        //JHTML::_('behavior.formvalidation');
        JHTML::_('behavior.tooltip');
        if (FLEXI_J30GE) {
            JHtml::_('bootstrap.tooltip');
        }
        //JHTML::_('script', 'joomla.javascript.js', 'includes/js/');
        // Add css files to the document <head> section (also load CSS joomla template override)
        $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/flexicontent.css');
        if (file_exists(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'css' . DS . 'flexicontent.css')) {
            $document->addStyleSheet(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'css' . DS . 'flexicontent.css');
        }
        if (!FLEXI_J16GE) {
            $document->addStyleSheet($this->baseurl . '/administrator/templates/khepri/css/general.css');
        }
        //$document->addCustomTag('<!--[if IE]><style type="text/css">.floattext{zoom:1;}, * html #flexicontent dd { height: 1%; }</style><![endif]-->');
        // Load backend / frontend shared and Joomla version specific CSS (different for frontend / backend)
        $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/flexi_shared.css');
        // NOTE: this is imported by main Frontend CSS file
        if (FLEXI_J30GE) {
            $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/j3x.css');
        } else {
            if (FLEXI_J16GE) {
                $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/j25.css');
            } else {
                $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/j15.css');
            }
        }
        // Add js function to overload the joomla submitform
        $document->addScript(JURI::base(true) . '/components/com_flexicontent/assets/js/admin.js');
        $document->addScript(JURI::base(true) . '/components/com_flexicontent/assets/js/validate.js');
        // Add js function for custom code used by FLEXIcontent item form
        $document->addScript(JURI::base(true) . '/components/com_flexicontent/assets/js/itemscreen.js');
        // ***********************************************
        // Get item and create form (that loads item data)
        // ***********************************************
        if ($print_logging_info) {
            $start_microtime = microtime(true);
        }
        $model = $this->getModel();
        // ** WE NEED TO get OR decide the Content Type, before we call the getItem
        // ** We rely on typeid Request variable to decide type for new items so make sure this is set,
        // ZERO means allow user to select type, but if user is only allowed a single type, then autoselect it!
        if ($menu && isset($menu->query['typeid'])) {
            JRequest::setVar('typeid', (int) $menu->query['typeid']);
            // This also forces zero if value not set
        }
        $new_typeid = JRequest::getVar('typeid', 0, '', 'int');
        if (!$new_typeid) {
            $types = $model->getTypeslist($type_ids_arr = false, $check_perms = true);
            if ($types && count($types) == 1) {
                $new_typeid = $types[0]->id;
            }
            JRequest::setVar('typeid', $new_typeid);
            $canCreateType = true;
        }
        $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 language stuff, and also load Template-Specific language file to override or add new language strings
        // *********************************************************************************************************
        if ($enable_translation_groups) {
            $langAssocs = $this->get('LangAssocs');
        }
        if (FLEXI_FISH || FLEXI_J16GE) {
            $langs = FLEXIUtilities::getLanguages('code');
        }
        if (FLEXI_FISH || FLEXI_J16GE) {
            FLEXIUtilities::loadTemplateLanguageFile($item->parameters->get('ilayout', 'default'));
        }
        // ****************************************************************************************
        // CHECK EDIT / CREATE PERMISSIONS (this is duplicate since it also done at the controller)
        // ****************************************************************************************
        // new item and ownership variables
        $isnew = !$item->id;
        $isOwner = $item->created_by == $user->get('id');
        // create and set (into HTTP request) a unique item id for plugins that needed it
        JRequest::setVar('unique_tmp_itemid', $item->id ? $item->id : date('_Y_m_d_h_i_s_', time()) . uniqid(true));
        // Component / Menu Item parameters
        $allowunauthorize = $params->get('allowunauthorize', 0);
        // allow unauthorised user to submit new content
        $unauthorized_page = $params->get('unauthorized_page', '');
        // page URL for unauthorized users (via global configuration)
        $notauth_itemid = $params->get('notauthurl', '');
        // menu itemid (to redirect) when user is not authorized to create content
        // Create captcha field or messages
        if (FLEXI_J16GE) {
            $use_captcha = $params->get('use_captcha', 1);
            // 1 for guests, 2 for any user
            $captcha_formop = $params->get('captcha_formop', 0);
            // 0 for submit, 1 for submit/edit (aka always)
            $display_captcha = $use_captcha >= 2 || $use_captcha == 1 && $user->guest;
            $display_captcha = $display_captcha && ($isnew || $captcha_formop);
            // Force using recaptcha
            if ($display_captcha) {
                // Try to force the use of recaptcha plugin
                JFactory::getConfig()->set('captcha', 'recaptcha');
                if (!$app->getCfg('captcha')) {
                    $captcha_errmsg = '-- Please select <b>CAPTCHA Type</b> at global Joomla parameters';
                } else {
                    if ($app->getCfg('captcha') != 'recaptcha') {
                        $captcha_errmsg = '-- Captcha Type: <b>' . $app->getCfg('captcha') . '</b> not supported';
                    } else {
                        if (!JPluginHelper::isEnabled('captcha', 'recaptcha')) {
                            $captcha_errmsg = '-- Please enable & configure the Joomla <b>ReCaptcha Plugin</b>';
                        } else {
                            $captcha_errmsg = '';
                            JPluginHelper::importPlugin('captcha');
                            $dispatcher->trigger('onInit', 'dynamic_recaptcha_1');
                            $field_description = JText::_('FLEXI_CAPTCHA_ENTER_CODE_DESC');
                            $label_tooltip = 'class="hasTip flexi_label" title="' . '::' . htmlspecialchars($field_description, ENT_COMPAT, 'UTF-8') . '"';
                            $captcha_field = '
						<label id="recaptcha_response_field-lbl" for="recaptcha_response_field" ' . $label_tooltip . ' >
						' . JText::_('FLEXI_CAPTCHA_ENTER_CODE') . '
						</label>
						<div class="container_fcfield container_fcfield_name_captcha">
							<div id="dynamic_recaptcha_1"></div>
						</div>
						';
                        }
                    }
                }
            }
        }
        // User Group / Author parameters
        $db->setQuery('SELECT author_basicparams FROM #__flexicontent_authors_ext WHERE user_id = ' . $user->id);
        $authorparams = $db->loadResult();
        $authorparams = FLEXI_J16GE ? new JRegistry($authorparams) : new JParameter($authorparams);
        $max_auth_limit = $authorparams->get('max_auth_limit', 0);
        // maximum number of content items the user can create
        if (!$isnew) {
            // EDIT action
            // Finally check if item is currently being checked-out (currently being edited)
            if ($model->isCheckedOut($user->get('id'))) {
                $msg = JText::sprintf('FLEXI_DESCBEINGEDITTED', $model->get('title'));
                $app->redirect(JRoute::_('index.php?view=' . FLEXI_ITEMVIEW . '&cid=' . $model->get('catid') . '&id=' . $model->get('id'), false), $msg);
            }
            //Checkout the item
            $model->checkout();
            if (FLEXI_J16GE) {
                $canEdit = $model->getItemAccess()->get('access-edit');
                // includes privileges edit and edit-own
                // ALTERNATIVE 1
                //$asset = 'com_content.article.' . $model->get('id');
                //$canEdit = $user->authorise('core.edit', $asset) || ($user->authorise('core.edit.own', $asset) && $model->get('created_by') == $user->get('id'));
                // ALTERNATIVE 2
                //$rights = FlexicontentHelperPerm::checkAllItemAccess($user->get('id'), 'item', $model->get('id'));
                //$canEdit = in_array('edit', $rights) || (in_array('edit.own', $rights) && $model->get('created_by') == $user->get('id')) ;
            } else {
                if ($user->gid >= 25) {
                    $canEdit = true;
                } else {
                    if (FLEXI_ACCESS) {
                        $rights = FAccess::checkAllItemAccess('com_content', 'users', $user->gmid, $model->get('id'), $model->get('catid'));
                        $canEdit = in_array('edit', $rights) || in_array('editown', $rights) && $model->get('created_by') == $user->get('id');
                    } else {
                        $canEdit = $user->authorize('com_content', 'edit', 'content', 'all') || $user->authorize('com_content', 'edit', 'content', 'own') && $model->get('created_by') == $user->get('id');
                        //$canEdit = ($user->gid >= 20);  // At least J1.5 Editor
                    }
                }
            }
            if (!$canEdit) {
                // No edit privilege, check if item is editable till logoff
                if ($session->has('rendered_uneditable', 'flexicontent')) {
                    $rendered_uneditable = $session->get('rendered_uneditable', array(), 'flexicontent');
                    $canEdit = isset($rendered_uneditable[$model->get('id')]) && $rendered_uneditable[$model->get('id')];
                }
            }
            if (!$canEdit) {
                if ($user->guest) {
                    $uri = JFactory::getURI();
                    $return = $uri->toString();
                    $fcreturn = serialize(array('id' => @$this->_item->id, 'cid' => $cid));
                    // a special url parameter, used by some SEF code
                    $com_users = FLEXI_J16GE ? 'com_users' : 'com_user';
                    $url = $params->get('login_page', 'index.php?option=' . $com_users . '&view=login');
                    $return = strtr(base64_encode($return), '+/=', '-_,');
                    $url .= '&return=' . $return;
                    //$url .= '&return='.urlencode(base64_encode($return));
                    $url .= '&fcreturn=' . base64_encode($fcreturn);
                    JError::raiseWarning(403, JText::sprintf("FLEXI_LOGIN_TO_ACCESS", $url));
                    $app->redirect($url);
                } else {
                    if ($unauthorized_page) {
                        //  unauthorized page via global configuration
                        JError::raiseNotice(403, JText::_('FLEXI_ALERTNOTAUTH_TASK'));
                        $app->redirect($unauthorized_page);
                    } else {
                        // user isn't authorize to edit this content
                        $msg = JText::_('FLEXI_ALERTNOTAUTH_TASK');
                        if (FLEXI_J16GE) {
                            throw new Exception($msg, 403);
                        } else {
                            JError::raiseError(403, $msg);
                        }
                    }
                }
            }
        } else {
            // CREATE action
            if (FLEXI_J16GE) {
                $canAdd = $model->getItemAccess()->get('access-create');
                // includes check of creating in at least one category
                $not_authorised = !$canAdd;
            } else {
                if ($user->gid >= 25) {
                    $not_authorised = 0;
                } else {
                    if (FLEXI_ACCESS) {
                        $canAdd = FAccess::checkUserElementsAccess($user->gmid, 'submit');
                        $not_authorised = !(@$canAdd['content'] || @$canAdd['category']);
                    } else {
                        $canAdd = $user->authorize('com_content', 'add', 'content', 'all');
                        //$canAdd = ($user->gid >= 19);  // At least J1.5 Author
                        $not_authorised = !$canAdd;
                    }
                }
            }
            // Check if Content Type can be created by current user
            if (empty($canCreateType)) {
                if ($new_typeid) {
                    $canCreateType = $model->canCreateType(array($new_typeid));
                    // Can create given Content Type
                } else {
                    $canCreateType = $model->canCreateType();
                    // Can create at least one Content Type
                }
            }
            $not_authorised = $not_authorised || !$canCreateType;
            // Allow item submission by unauthorized users, ... even guests ...
            if ($allowunauthorize == 2) {
                $allowunauthorize = !$user->guest;
            }
            if ($not_authorised && !$allowunauthorize) {
                if (!$canCreateType) {
                    $type_name = isset($types[$new_typeid]) ? '"' . JText::_($types[$new_typeid]->name) . '"' : JText::_('FLEXI_ANY');
                    $msg = JText::sprintf('FLEXI_NO_ACCESS_CREATE_CONTENT_OF_TYPE', $type_name);
                } else {
                    $msg = JText::_('FLEXI_ALERTNOTAUTH_CREATE');
                }
            } else {
                if ($max_auth_limit) {
                    $db->setQuery('SELECT COUNT(id) FROM #__content WHERE created_by = ' . $user->id);
                    $authored_count = $db->loadResult();
                    $content_is_limited = $authored_count >= $max_auth_limit;
                    $msg = $content_is_limited ? JText::sprintf('FLEXI_ALERTNOTAUTH_CREATE_MORE', $max_auth_limit) : '';
                }
            }
            if ($not_authorised && !$allowunauthorize || @$content_is_limited) {
                // User isn't authorize to add ANY content
                if ($notauth_menu = $app->getMenu()->getItem($notauth_itemid)) {
                    // a. custom unauthorized submission page via menu item
                    $internal_link_vars = @$notauth_menu->component ? '&Itemid=' . $notauth_itemid . '&option=' . $notauth_menu->component : '';
                    $notauthurl = JRoute::_($notauth_menu->link . $internal_link_vars, false);
                    JError::raiseNotice(403, $msg);
                    $app->redirect($notauthurl);
                } else {
                    if ($unauthorized_page) {
                        // b. General unauthorized page via global configuration
                        JError::raiseNotice(403, $msg);
                        $app->redirect($unauthorized_page);
                    } else {
                        // c. Finally fallback to raising a 403 Exception/Error that will redirect to site's default 403 unauthorized page
                        if (FLEXI_J16GE) {
                            throw new Exception($msg, 403);
                        } else {
                            JError::raiseError(403, $msg);
                        }
                    }
                }
            }
        }
        // *********************************************
        // Get more variables to push into the FORM view
        // *********************************************
        // Get available types and the currently selected/requested type
        $types = $model->getTypeslist();
        $typesselected = $model->getTypesselected();
        // Create the type parameters
        $tparams = $this->get('Typeparams');
        $tparams = FLEXI_J16GE ? new JRegistry($tparams) : new JParameter($tparams);
        // Merge item parameters, or type/menu parameters for new item
        if ($isnew) {
            if ($new_typeid) {
                $params->merge($tparams);
            }
            // Apply type configuration if it type is set
            if ($menu) {
                $params->merge($menu_params);
            }
            // Apply menu configuration if it menu is set, to override type configuration
        } else {
            $params = $item->parameters;
        }
        // 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;
        }
        // Tags used by the item
        $usedtagsids = $this->get('UsedtagsIds');
        // NOTE: This will normally return the already set versioned value of tags ($item->tags)
        //$usedtagsIds 	= $isnew ? array() : $fields['tags']->value;
        $usedtagsdata = $model->getUsedtagsData($usedtagsids);
        //echo "<br/>usedtagsIds: "; print_r($usedtagsids);
        //echo "<br/>usedtags (data): "; print_r($usedtagsdata);
        // Compatibility for old overriden templates ...
        if (!FLEXI_J16GE) {
            $tags = $this->get('Alltags');
            $usedtags = $this->get('UsedtagsIds');
        }
        // Load permissions (used by form template)
        $perms = $this->_getItemPerms($item, $typesselected);
        // Get the edit lists
        $lists = $this->_buildEditLists($perms, $params, $authorparams, $typesselected, $tparams);
        // Get number of subscribers
        $subscribers = $this->get('SubscribersCount');
        // Get menu overridden categories/main category fields
        $menuCats = $this->_getMenuCats($item, $perms, $params);
        // Create submit configuration (for new items) into the session
        $submitConf = $this->_createSubmitConf($item, $perms, $params);
        // Create placement configuration for CORE properties
        $placementConf = $this->_createPlacementConf($fields, $params, $item);
        // Item language related vars
        if (FLEXI_FISH || FLEXI_J16GE) {
            $languages = FLEXIUtilities::getLanguages();
            $itemlang = new stdClass();
            $itemlang->shortcode = substr($item->language, 0, 2);
            $itemlang->name = $languages->{$item->language}->name;
            $itemlang->image = '<img src="' . @$languages->{$item->language}->imgsrc . '" alt="' . $languages->{$item->language}->name . '" />';
        }
        //Load the JEditor object
        $editor = JFactory::getEditor();
        // **********************************************************
        // Calculate a (browser window) page title and a page heading
        // **********************************************************
        // Verify menu item points to current FLEXIcontent object
        if ($menu) {
            $menu_matches = false;
            $view_ok = FLEXI_ITEMVIEW == @$menu->query['view'] || 'article' == @$menu->query['view'];
            $menu_matches = $view_ok;
            //$menu_params = FLEXI_J16GE ? $menu->params : new JParameter($menu->params);  // Get active menu item parameters
        } else {
            $menu_matches = false;
        }
        // MENU ITEM matched, use its page heading (but use menu title if the former is not set)
        if ($menu_matches) {
            $default_heading = FLEXI_J16GE ? $menu->title : $menu->name;
            // Cross set (show_) page_heading / page_title for compatibility of J2.5+ with J1.5 template (and for J1.5 with J2.5 template)
            $params->def('page_heading', $params->get('page_title', $default_heading));
            $params->def('page_title', $params->get('page_heading', $default_heading));
            $params->def('show_page_heading', $params->get('show_page_title', 0));
            $params->def('show_page_title', $params->get('show_page_heading', 0));
        } else {
            // Calculate default page heading (=called page title in J1.5), which in turn will be document title below !! ...
            $default_heading = !$isnew ? JText::_('FLEXI_EDIT') : JText::_('FLEXI_NEW');
            // Decide to show page heading (=J1.5 page title), there is no need for this in item view
            $show_default_heading = 0;
            // Set both (show_) page_heading / page_title for compatibility of J2.5+ with J1.5 template (and for J1.5 with J2.5 template)
            $params->set('page_title', $default_heading);
            $params->set('page_heading', $default_heading);
            $params->set('show_page_heading', $show_default_heading);
            $params->set('show_page_title', $show_default_heading);
        }
        // ************************************************************
        // Create the document title, by from page title and other data
        // ************************************************************
        // Use the page heading as document title, (already calculated above via 'appropriate' logic ...)
        $doc_title = $params->get('page_title');
        // Check and prepend or append site name
        if (FLEXI_J16GE) {
            // Not available in J1.5
            // Add Site Name to page title
            if ($app->getCfg('sitename_pagetitles', 0) == 1) {
                $doc_title = $app->getCfg('sitename') . " - " . $doc_title;
            } elseif ($app->getCfg('sitename_pagetitles', 0) == 2) {
                $doc_title = $doc_title . " - " . $app->getCfg('sitename');
            }
        }
        // Finally, set document title
        $document->setTitle($doc_title);
        // Add title to pathway
        $pathway = $app->getPathWay();
        $pathway->addItem($doc_title, '');
        // Get pageclass suffix
        $pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx'));
        // Ensure the row data is safe html
        // @TODO: check if this is really required as it conflicts with the escape function in the tmpl
        //JFilterOutput::objectHTMLSafe( $item );
        $this->assign('action', $uri->toString());
        $this->assignRef('item', $item);
        if (FLEXI_J16GE) {
            // most core field are created via calling methods of the form (J2.5)
            $this->assignRef('form', $form);
        }
        if ($enable_translation_groups) {
            $this->assignRef('lang_assocs', $langAssocs);
        }
        if (FLEXI_FISH || FLEXI_J16GE) {
            $this->assignRef('langs', $langs);
        }
        $this->assignRef('params', $params);
        $this->assignRef('lists', $lists);
        $this->assignRef('subscribers', $subscribers);
        $this->assignRef('editor', $editor);
        $this->assignRef('user', $user);
        if (!FLEXI_J16GE) {
            // compatibility old templates
            $this->assignRef('tags', $tags);
            $this->assignRef('usedtags', $usedtags);
        }
        $this->assignRef('usedtagsdata', $usedtagsdata);
        $this->assignRef('fields', $fields);
        $this->assignRef('tparams', $tparams);
        $this->assignRef('perms', $perms);
        $this->assignRef('document', $document);
        $this->assignRef('nullDate', $nullDate);
        $this->assignRef('menuCats', $menuCats);
        $this->assignRef('submitConf', $submitConf);
        $this->assignRef('placementConf', $placementConf);
        $this->assignRef('itemlang', $itemlang);
        $this->assignRef('pageclass_sfx', $pageclass_sfx);
        $this->assign('captcha_errmsg', @$captcha_errmsg);
        $this->assign('captcha_field', @$captcha_field);
        // **************************************************************************************
        // Load a different template file for parameters depending on whether we use FLEXI_ACCESS
        // **************************************************************************************
        if (!FLEXI_J16GE) {
            if (FLEXI_ACCESS) {
                $formparams = new JParameter('', JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_flexicontent' . DS . 'models' . DS . 'item2.xml');
            } else {
                $formparams = new JParameter('', JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_flexicontent' . DS . 'models' . DS . 'item.xml');
            }
        }
        // ****************************************************************
        // SET INTO THE FORM, parameter values for various parameter groups
        // ****************************************************************
        if (!FLEXI_J16GE) {
            // Permissions (Access) Group
            if (!FLEXI_ACCESS) {
                $formparams->set('access', $item->access);
            }
            // Set: (Publication) Details Group
            $created_by = intval($item->created_by) ? intval($item->created_by) : $user->get('id');
            $formparams->set('created_by', $created_by);
            $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 == $nullDate || 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'));
            }
            // Set:  Attributes (parameters) Group, (these are retrieved from the item table column 'attribs')
            // (also contains templates parameters, but we will use these individual for every template ... see below)
            $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]);
                }
            }
            // Set: Metadata (parameters) Group
            // NOTE: (2 params from 2 item table columns, and then multiple params from item table column 'metadata')
            $formparams->set('description', $item->metadesc);
            $formparams->set('keywords', $item->metakey);
            if (!empty($item->metadata)) {
                $formparams->loadINI($item->metadata->toString());
            }
            // Now create the sliders object,
            // And also push the Form Parameters object into the template (Template Parameters object is seperate)
            jimport('joomla.html.pane');
            $pane = JPane::getInstance('Sliders');
            //$tabs_pane = JPane::getInstance('Tabs');
            $this->assignRef('pane', $pane);
            //$this->assignRef('tabs_pane'	, $tabs_pane);
            $this->assignRef('formparams', $formparams);
        } else {
            if (JHTML::_('date', $item->publish_down, 'Y') <= 1969 || $item->publish_down == $nullDate) {
                $item->publish_down = 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);
            }
        }
        $this->assignRef('tmpls', $tmpls);
        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;
        }
    }