Exemplo n.º 1
0
 /**
  * Creates the page's display
  *
  * @since 1.0
  */
 function display($tpl = null)
 {
     // check for form layout
     if ($this->getLayout() == 'form' || in_array(JRequest::getVar('task'), array('add', 'edit'))) {
         // Important set layout to be form since various category view SEF links have this variable set
         $this->setLayout('form');
         $this->_displayForm($tpl);
         return;
     } else {
         $this->setLayout('item');
     }
     // Get Content Types with no category links in item view pathways, and for unroutable (non-linkable) categories
     global $globalnoroute, $globalnopath, $globalcats;
     if (!is_array($globalnopath)) {
         $globalnopath = array();
     }
     if (!is_array($globalnoroute)) {
         $globalnoroute = array();
     }
     //initialize variables
     $dispatcher = JDispatcher::getInstance();
     $app = JFactory::getApplication();
     $session = JFactory::getSession();
     $document = JFactory::getDocument();
     $menus = $app->getMenu();
     $menu = $menus->getActive();
     $uri = JFactory::getURI();
     $user = JFactory::getUser();
     $aid = JAccess::getAuthorisedViewLevels($user->id);
     $db = JFactory::getDBO();
     $nullDate = $db->getNullDate();
     // ******************************************************
     // Get item, model and create form (that loads item data)
     // ******************************************************
     // Get model
     $model = $this->getModel();
     $cid = $model->_cid ? $model->_cid : $model->get('catid');
     // Get current category id
     // Decide version to load
     $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)
     $preview = JRequest::getVar('preview', 0, 'request', 'int');
     // Preview versioned data FLAG ... if previewing and version is not set then ... we load version -1 (=latest version)
     $version = $preview && !$version ? -1 : $version;
     // Allow iLayout from HTTP request, this will be checked during loading item parameters
     $model->setItemLayout('__request__');
     // Try to load existing item, an 404 error will be raised if item is not found. Also value 2 for check_view_access
     // indicates to raise 404 error for ZERO primary key too, instead of creating and returning a new item object
     $start_microtime = microtime(true);
     $item = $model->getItem(null, $check_view_access = 2, $no_cache = $version || $preview, $force_version = $version || $preview ? $version : 0);
     // ZERO means unversioned data
     $_run_time = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
     // Get item parameters as VIEW's parameters (item parameters are merged parameters in order: component/category/layout/type/item/menu/access)
     $params =& $item->parameters;
     // Get item 's layout as this may have been altered
     $ilayout = $params->get('ilayout');
     $print_logging_info = $params->get('print_logging_info');
     if ($print_logging_info) {
         global $fc_run_times;
     }
     if ($print_logging_info) {
         $fc_run_times['get_item_data'] = $_run_time;
     }
     // ********************************
     // Load needed JS libs & CSS styles
     // ********************************
     //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');
     }
     //special to hide the joomfish language selector on item views
     if ($params->get('disable_lang_select', 0)) {
         $css = '#jflanguageselection { visibility:hidden; }';
         $document->addStyleDeclaration($css);
     }
     // *************************************************************
     // Get cached template data, loading any template language files
     // *************************************************************
     $themes = flexicontent_tmpl::getTemplates($lang_files = array($ilayout));
     // *****************
     // Get Item's Fields
     // *****************
     $_items = array(&$item);
     FlexicontentFields::getFields($_items, FLEXI_ITEMVIEW, $params, $aid);
     $fields = $item->fields;
     // ****************************************
     // 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];
     		}*/
     // **********************************************************
     // Calculate a (browser window) page title and a page heading
     // **********************************************************
     // Verify menu item points to current FLEXIcontent object
     if ($menu) {
         $view_ok = FLEXI_ITEMVIEW == @$menu->query['view'] || 'article' == @$menu->query['view'];
         $cid_ok = JRequest::getInt('cid') == (int) @$menu->query['cid'];
         $id_ok = JRequest::getInt('id') == (int) @$menu->query['id'];
         $menu_matches = $view_ok && $id_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 {
         // 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 !! ...
         $default_heading = $item->title;
         // 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);
     }
     // Prevent showing the page heading if (a) IT IS same as item title and (b) item title is already configured to be shown
     if ($params->get('show_title', 1)) {
         if ($params->get('page_heading') == $item->title) {
             $params->set('show_page_heading', 0);
         }
         if ($params->get('page_title') == $item->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 = !$params->get('override_title', 0) ? $params->get('page_title') : $params->get('custom_ititle', $item->title);
     // Check and prepend category title
     if ($params->get('addcat_title', 1) && count($parents)) {
         $parentcat = end($parents);
         if (isset($item->category_title)) {
             if ($params->get('addcat_title', 1) == 1) {
                 // On Left
                 $doc_title = JText::sprintf('FLEXI_PAGETITLE_SEPARATOR', $item->category_title, $doc_title);
             } else {
                 // On Right
                 $doc_title = JText::sprintf('FLEXI_PAGETITLE_SEPARATOR', $doc_title, $item->category_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);
     }
     // Set item's META data: desc, keyword, title, author
     if ($item->metadesc) {
         $document->setDescription($item->metadesc);
     }
     if ($item->metakey) {
         $document->setMetadata('keywords', $item->metakey);
     }
     // ?? Deprecated <title> tag is used instead by search engines
     if ($app->getCfg('MetaTitle') == '1') {
         $document->setMetaData('title', $item->title);
     }
     if ($app->getCfg('MetaAuthor') == '1') {
         $document->setMetaData('author', $item->author);
     }
     // Set remaining META keys
     $mdata = $item->metadata->toArray();
     foreach ($mdata as $k => $v) {
         if ($v) {
             $document->setMetadata($k, $v);
         }
     }
     // 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);
         }
     }
     // ****************************************************************
     // 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
         $ucanonical = $domain . JRoute::_(FlexicontentHelperRoute::getItemRoute($item->slug, $globalcats[$item->maincatid]->slug, 0, $item));
         // $item->categoryslug
         // 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)]);
         }
     }
     // *************************
     // increment the hit counter
     // *************************
     // MOVED to flexisystem plugin due to ...
     /*if (FLEXIUtilities::count_new_hit($item->id) ) {
     			$model->hit();
     		}*/
     // Load template css/js and set template data variable
     $tmplvar = $themes->items->{$ilayout}->tmplvar;
     if ($ilayout) {
         // Add the templates css files if availables
         if (isset($themes->items->{$ilayout}->css)) {
             foreach ($themes->items->{$ilayout}->css as $css) {
                 $document->addStyleSheet($this->baseurl . '/' . $css);
             }
         }
         // Add the templates js files if availables
         if (isset($themes->items->{$ilayout}->js)) {
             foreach ($themes->items->{$ilayout}->js as $js) {
                 $document->addScript($this->baseurl . '/' . $js);
             }
         }
         // Set the template var
         $tmpl = $themes->items->{$ilayout}->tmplvar;
     } else {
         $tmpl = '.items.default';
     }
     // 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 : '';
     // Maybe here not to import all plugins but just those for description field ???
     // Anyway these events are usually not very time consuming, so lets trigger all of them ???
     JPluginHelper::importPlugin('content');
     // Suppress some plugins from triggering for compatibility reasons, e.g.
     // (a) jcomments, jom_comment_bot plugins, because we will get comments HTML manually inside the template files
     $suppress_arr = array('jcomments', 'jom_comment_bot');
     FLEXIUtilities::suppressPlugins($suppress_arr, 'suppress');
     // Do some compatibility steps, Set the view and option to 'article' and 'com_content'
     JRequest::setVar('view', 'article');
     JRequest::setVar('option', 'com_content');
     JRequest::setVar("isflexicontent", "yes");
     $limitstart = JRequest::getVar('limitstart', 0, '', 'int');
     // 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.article', &$item, &$params, $limitstart));
     $item->event->afterDisplayTitle = trim(implode("\n", $results));
     $results = $dispatcher->trigger('onContentBeforeDisplay', array('com_content.article', &$item, &$params, $limitstart));
     $item->event->beforeDisplayContent = trim(implode("\n", $results));
     $results = $dispatcher->trigger('onContentAfterDisplay', array('com_content.article', &$item, &$params, $limitstart));
     $item->event->afterDisplayContent = trim(implode("\n", $results));
     // Reverse the compatibility steps, set the view and option back to 'items' and 'com_flexicontent'
     JRequest::setVar('view', FLEXI_ITEMVIEW);
     JRequest::setVar('option', 'com_flexicontent');
     // Restore suppressed plugins
     FLEXIUtilities::suppressPlugins($suppress_arr, 'restore');
     // 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
     if (!empty($item->positions)) {
         foreach ($item->positions as $pos_fields) {
             foreach ($pos_fields as $pos_field) {
                 if ($pos_field->name !== 'text') {
                     continue;
                 }
                 $pos_field->display =& $item->text;
             }
         }
     }
     $item->fields['text']->display =& $item->text;
     // (TOC) TABLE OF Contents has been created inside description field (named 'text') by
     // the pagination plugin, this should be assigned to item as a property with same name
     if (isset($item->fields['text']->toc)) {
         $item->toc =& $item->fields['text']->toc;
     }
     // ********************************************************************************************
     // 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)) {
         // For some Content Types the pathway should not be populated with category links
         if (in_array($item->type_id, $globalnopath)) {
             break;
         }
         // 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++;
     }
     if ($params->get('add_item_pathway', 1)) {
         $pathway->addItem($this->escape($item->title), JRoute::_(FlexicontentHelperRoute::getItemRoute($item->slug, $item->categoryslug, 0, $item)));
     }
     // **********************************************************************
     // 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';
     //$print_link = JRoute::_('index.php?view='.FLEXI_ITEMVIEW.'&cid='.$item->categoryslug.'&id='.$item->slug.'&pop=1&tmpl=component&print=1');
     $pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx'));
     $this->assignRef('item', $item);
     $this->assignRef('user', $user);
     $this->assignRef('params', $params);
     $this->assignRef('print_link', $print_link);
     $this->assignRef('pageclass_sfx', $pageclass_sfx);
     $this->assignRef('parentcat', $parentcat);
     $this->assignRef('fields', $item->fields);
     $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 ($ilayout) {
         $this->addTemplatePath(JPATH_COMPONENT . DS . 'templates' . DS . $ilayout);
         $this->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS . 'com_flexicontent' . DS . 'templates' . DS . $ilayout);
     }
     if ($print_logging_info) {
         $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.º 2
0
 /**
  * Method to selectively trigger content plugins for the text of the specified field
  * 
  * @access public
  * @return object
  * @since 1.5
  */
 static function triggerContentPlugins(&$field, &$item, $method, $view = FLEXI_ITEMVIEW)
 {
     $debug = false;
     static $_plgs_loaded = array();
     static $_fields_plgs = array();
     static $_initialize = false;
     static $_view, $_option, $limitstart;
     static $dispatcher, $fcdispatcher;
     //$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;
     if (!$_initialize) {
         // some request and other variables
         $_view = JRequest::getVar('view');
         $_option = JRequest::getVar('option');
         $limitstart = JRequest::getVar('limitstart', 0, '', 'int');
         $_initialize = true;
         // ***********************************************************************
         // We use a custom Dispatcher to allow selective Content Plugin triggering
         // ***********************************************************************
         require_once JPATH_SITE . DS . 'components' . DS . 'com_flexicontent' . DS . 'helpers' . DS . 'dispatcher.php';
         $dispatcher = JDispatcher::getInstance();
         $fcdispatcher = FCDispatcher::getInstance_FC($debug);
     }
     if ($debug) {
         echo "<br><br>Executing plugins for <b>" . $field->name . "</b>:<br>";
     }
     if (!@$_fields_plgs[$field->name]) {
         // Make sure the necessary plugin are already loaded, but do not try to load them again since this will harm performance
         if (!$field->parameters->get('plugins')) {
             $_plgs = null;
             if (!@$_plgs_loaded['__ALL__']) {
                 JPluginHelper::importPlugin('content', $plugin = null, $autocreate = true, $dispatcher);
                 $_plgs_loaded['__ALL__'] = 1;
             }
         } else {
             $_plgs = $field->parameters->get('plugins');
             $_plgs = $_plgs ? $_plgs : array();
             $_plgs = is_array($_plgs) ? $_plgs : explode('|', $_plgs);
             // compatibility because old versions did not JSON encode the parameters
             if (!@$_plgs_loaded['__ALL__']) {
                 foreach ($_plgs as $_plg) {
                     if (!@$_plgs_loaded[$_plg]) {
                         JPluginHelper::importPlugin('content', $_plg, $autocreate = true, $dispatcher);
                         $_plgs_loaded[$_plg] = 1;
                     }
                 }
             }
         }
         $_fields_plgs[$field->name] = $_plgs;
     }
     $plg_arr = $_fields_plgs[$field->name];
     // Suppress some plugins from triggering for compatibility reasons, e.g.
     // (a) jcomments, jom_comment_bot plugins, because we will get comments HTML manually inside the template files
     $suppress_arr = array('jcomments', 'jom_comment_bot');
     FLEXIUtilities::suppressPlugins($suppress_arr, 'suppress');
     // Initialize field for plugin triggering
     $field->text = isset($field->{$method}) ? $field->{$method} : '';
     $field->introtext = $field->text;
     // needed by some plugins that do not use or clear ->text property
     $field->created_by = $item->created_by;
     $field->title = $item->title;
     $field->slug = isset($item->slug) ? $item->slug : $item->id;
     $field->sectionid = !FLEXI_J16GE ? $item->sectionid : false;
     $field->catid = $item->catid;
     $field->catslug = @$item->categoryslug;
     $field->fieldid = $field->id;
     $field->id = $item->id;
     $field->state = $item->state;
     $field->type_id = $item->type_id;
     // CASE: FLEXIcontent item view:
     // Set triggering 'context' to 'com_content.article', (and also set the 'view' request variable)
     if ($view == FLEXI_ITEMVIEW) {
         JRequest::setVar('view', 'article');
         $context = 'com_content.article';
     } else {
         JRequest::setVar('view', 'category');
         $context = 'com_content.category';
     }
     // Set the 'option' to 'com_content' but set a flag 'isflexicontent' to indicate triggering from inside FLEXIcontent ... code
     JRequest::setVar('option', 'com_content');
     JRequest::setVar("isflexicontent", "yes");
     // Trigger content plugins on field's HTML display, as if they were a "joomla article"
     if (FLEXI_J16GE) {
         $results = $fcdispatcher->trigger('onContentPrepare', array($context, &$field, &$item->parameters, $limitstart), $plg_arr);
     } else {
         $results = $fcdispatcher->trigger('onPrepareContent', array(&$field, &$item->parameters, $limitstart), false, $plg_arr);
     }
     // Restore 'view' and 'option' request variables
     JRequest::setVar('view', $_view);
     JRequest::setVar('option', $_option);
     $field->id = $field->fieldid;
     $field->{$method} = $field->text;
     // Restore suppressed plugins
     FLEXIUtilities::suppressPlugins($suppress_arr, 'restore');
 }
Exemplo n.º 3
0
 /**
  * Creates the page's display
  *
  * @since 1.0
  */
 function display($tpl = null)
 {
     // check for form layout
     if ($this->getLayout() == 'form' || in_array(JRequest::getVar('task'), array('add', 'edit'))) {
         // Important set layout to be form since various category view SEF links have this variable set
         $this->setLayout('form');
         $this->_displayForm($tpl);
         return;
     } else {
         $this->setLayout('item');
     }
     // Get Content Types with no category links in item view pathways, and for unroutable (non-linkable) categories
     global $globalnoroute, $globalnopath, $globalcats;
     if (!is_array($globalnopath)) {
         $globalnopath = array();
     }
     if (!is_array($globalnoroute)) {
         $globalnoroute = array();
     }
     //initialize variables
     $dispatcher = JDispatcher::getInstance();
     $app = JFactory::getApplication();
     $session = JFactory::getSession();
     $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');
     $db = JFactory::getDBO();
     $nullDate = $db->getNullDate();
     // ******************************************************
     // Get item, model and create form (that loads item data)
     // ******************************************************
     // Get various data from the model
     $model = $this->getModel();
     $cid = $model->_cid ? $model->_cid : $model->get('catid');
     // Get current category id
     // we are in display() task, so we will load the current item version by default
     // 'preview' request variable will force last, and finally 'version' request variable will force specific
     // NOTE: preview and version variables cannot be used by users that cannot edit the item
     JRequest::setVar('loadcurrent', true);
     // Try to load existing item, an 404 error will be raised if item is not found. Also value 2 for check_view_access
     // indicates to raise 404 error for ZERO primary key too, instead of creating and returning a new item object
     $start_microtime = microtime(true);
     $item = $model->getItem(null, $check_view_access = 2);
     $_run_time = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
     // Set item parameters as VIEW's parameters (item parameters are merged with component/page/type/current category/access parameters already)
     $params = $item->parameters;
     $print_logging_info = $params->get('print_logging_info');
     if ($print_logging_info) {
         global $fc_run_times;
     }
     if ($print_logging_info) {
         $fc_run_times['get_item_data'] = $_run_time;
     }
     // ********************************
     // Load needed JS libs & CSS styles
     // ********************************
     //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');
     }
     //special to hide the joomfish language selector on item views
     if ($params->get('disable_lang_select', 0)) {
         $css = '#jflanguageselection { visibility:hidden; }';
         $document->addStyleDeclaration($css);
     }
     // ********************
     // ITEM LAYOUT handling
     // ********************
     // (a) Decide to use mobile or normal item 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;
     }
     $_ilayout = $useMobile ? 'ilayout_mobile' : 'ilayout';
     // (b) Get from item parameters, allowing URL override
     $ilayout = JRequest::getVar($_ilayout, false);
     if (!$ilayout) {
         $desktop_ilayout = $params->get('ilayout', 'default');
         $ilayout = !$useMobile ? $desktop_ilayout : $params->get('ilayout_mobile', $desktop_ilayout);
     }
     // (c) Create the type parameters
     $tparams = $this->get('Typeparams');
     $tparams = FLEXI_J16GE ? new JRegistry($tparams) : new JParameter($tparams);
     // (d) Verify the layout is within templates, Content Type default template OR 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);
         }
     }
     // (e) 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;
     }
     // (f) Get cached template data
     $themes = flexicontent_tmpl::getTemplates($lang_files = array($ilayout));
     // (g) 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;
         if (FLEXI_FISH || FLEXI_J16GE) {
             FLEXIUtilities::loadTemplateLanguageFile($ilayout);
         }
         // Manually load Template-Specific language file of back fall ilayout
     }
     // (h) finally set the template name back into the item's parameters
     $params->set('ilayout', $ilayout);
     // Bind Fields
     $_items = array(&$item);
     FlexicontentFields::getFields($_items, FLEXI_ITEMVIEW, $params, $aid);
     // Note : This parameter doesn't exist yet but it will be used by the future gallery template
     /*if ($params->get('use_panes', 1)) {
     			jimport('joomla.html.pane');
     			$pane = JPane::getInstance('Tabs');
     			$this->assignRef('pane', $pane);
     		}*/
     $fields = $item->fields;
     // 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];
         }
     }
     // **********************************************************
     // Calculate a (browser window) page title and a page heading
     // **********************************************************
     // Verify menu item points to current FLEXIcontent object
     if ($menu) {
         $view_ok = FLEXI_ITEMVIEW == @$menu->query['view'] || 'article' == @$menu->query['view'];
         $cid_ok = JRequest::getInt('cid') == (int) @$menu->query['cid'];
         $id_ok = JRequest::getInt('id') == (int) @$menu->query['id'];
         $menu_matches = $view_ok && $id_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 !! ...
         $default_heading = $item->title;
         // 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);
     }
     // Prevent showing the page heading if (a) IT IS same as item title and (b) item title is already configured to be shown
     if ($params->get('show_title', 1)) {
         if ($params->get('page_heading') == $item->title) {
             $params->set('show_page_heading', 0);
         }
         if ($params->get('page_title') == $item->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 = !$params->get('override_title', 0) ? $params->get('page_title') : $params->get('custom_ititle', $item->title);
     // Check and prepend category title
     if ($params->get('addcat_title', 1) && count($parents)) {
         $parentcat = end($parents);
         $doc_title = (isset($parentcat->title) ? $parentcat->title . ' - ' : '') . $doc_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);
     }
     // Set item's META data: desc, keyword, title, author
     if ($item->metadesc) {
         $document->setDescription($item->metadesc);
     }
     if ($item->metakey) {
         $document->setMetadata('keywords', $item->metakey);
     }
     // ?? Deprecated <title> tag is used instead by search engines
     if ($app->getCfg('MetaTitle') == '1') {
         $document->setMetaData('title', $item->title);
     }
     if ($app->getCfg('MetaAuthor') == '1') {
         $document->setMetaData('author', $item->author);
     }
     // Set remaining META keys
     $mdata = $item->metadata->toArray();
     foreach ($mdata as $k => $v) {
         if ($v) {
             $document->setMetadata($k, $v);
         }
     }
     // 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();
     $ucanonical = $base . JRoute::_(FlexicontentHelperRoute::getItemRoute($item->slug, $globalcats[$item->maincatid]->slug, 0, $item));
     // $item->categoryslug
     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]);
         }
     }
     // *************************
     // increment the hit counter
     // *************************
     // MOVED to flexisystem plugin due to ...
     /*if (FLEXIUtilities::count_new_hit($item->id) ) {
     			$model->hit();
     		}*/
     // Load template css/js and set template data variable
     $tmplvar = $themes->items->{$ilayout}->tmplvar;
     if ($ilayout) {
         // Add the templates css files if availables
         if (isset($themes->items->{$ilayout}->css)) {
             foreach ($themes->items->{$ilayout}->css as $css) {
                 $document->addStyleSheet($this->baseurl . '/' . $css);
             }
         }
         // Add the templates js files if availables
         if (isset($themes->items->{$ilayout}->js)) {
             foreach ($themes->items->{$ilayout}->js as $js) {
                 $document->addScript($this->baseurl . '/' . $js);
             }
         }
         // Set the template var
         $tmpl = $themes->items->{$ilayout}->tmplvar;
     } else {
         $tmpl = '.items.default';
     }
     // 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 : '';
     // Maybe here not to import all plugins but just those for description field ???
     // Anyway these events are usually not very time consuming, so lets trigger all of them ???
     JPluginHelper::importPlugin('content');
     // Suppress some plugins from triggering for compatibility reasons, e.g.
     // (a) jcomments, jom_comment_bot plugins, because we will get comments HTML manually inside the template files
     $suppress_arr = array('jcomments', 'jom_comment_bot');
     FLEXIUtilities::suppressPlugins($suppress_arr, 'suppress');
     // Do some compatibility steps, Set the view and option to 'article' and 'com_content'
     JRequest::setVar('view', 'article');
     JRequest::setVar('option', 'com_content');
     JRequest::setVar("isflexicontent", "yes");
     $limitstart = JRequest::getVar('limitstart', 0, '', 'int');
     // 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.article', &$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.article', &$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.article', &$item, &$params, 0));
     } else {
         $results = $dispatcher->trigger('onAfterDisplayContent', array(&$item, &$params, $limitstart));
     }
     $item->event->afterDisplayContent = trim(implode("\n", $results));
     // Reverse the compatibility steps, set the view and option back to 'items' and 'com_flexicontent'
     JRequest::setVar('view', FLEXI_ITEMVIEW);
     JRequest::setVar('option', 'com_flexicontent');
     // Restore suppressed plugins
     FLEXIUtilities::suppressPlugins($suppress_arr, 'restore');
     // 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
     if (!empty($item->positions)) {
         foreach ($item->positions as $pos_fields) {
             foreach ($pos_fields as $pos_field) {
                 if ($pos_field->name !== 'text') {
                     continue;
                 }
                 $pos_field->display =& $item->text;
             }
         }
     }
     $item->fields['text']->display =& $item->text;
     // (TOC) TABLE OF Contents has been created inside description field (named 'text') by
     // the pagination plugin, this should be assigned to item as a property with same name
     if (isset($item->fields['text']->toc)) {
         $item->toc =& $item->fields['text']->toc;
     }
     // ********************************************************************************************
     // 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)) {
         // For some Content Types the pathway should not be populated with category links
         if (in_array($item->type_id, $globalnopath)) {
             break;
         }
         // 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++;
     }
     if ($params->get('add_item_pathway', 1)) {
         $pathway->addItem($this->escape($item->title), JRoute::_(FlexicontentHelperRoute::getItemRoute($item->slug, $item->categoryslug, 0, $item)));
     }
     // **********************************************************************
     // 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';
     //$print_link = JRoute::_('index.php?view='.FLEXI_ITEMVIEW.'&cid='.$item->categoryslug.'&id='.$item->slug.'&pop=1&tmpl=component&print=1');
     $pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx'));
     $this->assignRef('item', $item);
     $this->assignRef('user', $user);
     $this->assignRef('params', $params);
     $this->assignRef('print_link', $print_link);
     $this->assignRef('pageclass_sfx', $pageclass_sfx);
     $this->assignRef('parentcat', $parentcat);
     $this->assignRef('fields', $item->fields);
     $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 ($ilayout) {
         $this->addTemplatePath(JPATH_COMPONENT . DS . 'templates' . DS . $ilayout);
         $this->addTemplatePath(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'html' . DS . 'com_flexicontent' . DS . 'templates' . DS . $ilayout);
     }
     if ($print_logging_info) {
         $start_microtime = microtime(true);
     }
     parent::display($tpl);
     if ($print_logging_info) {
         $fc_run_times['template_render'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
     }
 }