/** * 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, '?') ? '&' : '?') . 'pop=1&tmpl=component&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; } }
/** * Method to load the Category * * @access public * @return array */ function getCategory($pk = null, $raiseErrors = true, $checkAccess = true) { //initialize some vars $app = JFactory::getApplication(); $user = JFactory::getUser(); $cparams = $this->_params; if ($pk) { $this->_id = $pk; } // Set a specific id $cat_required = $this->_layout == ''; $cat_usable = !$this->_layout || $this->_layout != 'mcats'; // Clear category id, if current layout cannot be limited to a specific category $this->_id = $cat_usable ? $this->_id : 0; if ($this->_id) { require_once JPATH_SITE . DS . 'components' . DS . 'com_flexicontent' . DS . 'classes' . DS . 'flexicontent.categories.php'; // If category model is loaded from 3rd party code $catshelper = new flexicontent_cats($this->_id); $parents = $catshelper->getParentlist($all_cols = false); $parents_published = true; foreach ($parents as $parent) { if (!$parent->published) { $parents_published = false; break; } } if ($parents_published) { // ************************************************************************************************************ // Retrieve category data, but ONLY if current layout can use it, ('mcats' does not since it uses multiple ids) // ************************************************************************************************************ $query = 'SELECT c.*,' . ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as slug' . ' FROM #__categories AS c' . ' WHERE c.id = ' . $this->_id . ' AND c.published = 1 AND c.extension=' . $this->_db->Quote(FLEXI_CAT_EXTENSION); $this->_db->setQuery($query); $_category = $this->_db->loadObject(); // False if not found or unpublished if ($this->_db->getErrorNum()) { JFactory::getApplication()->enqueueMessage(__FUNCTION__ . '(): SQL QUERY ERROR:<br/>' . nl2br($this->_db->getErrorMsg()), 'error'); } } else { $_category = false; // A parent category is unpublished } } else { $_category = false; // No category id given, or category id is not applicable for current layout } // ******************************************************************************* // Check category was found / is published, and throw an error. Note that an empty // layout means single category view, so raise an error if category id is missing // ******************************************************************************* if (($this->_id || $cat_required) && !$_category) { $err_mssg = $err_type = false; if (!$_category) { $err_mssg = JText::sprintf('FLEXI_CONTENT_CATEGORY_NOT_FOUND_OR_NOT_PUBLISHED', $this->_id); $err_type = 404; } // Throw error -OR- return if errors suppresed if ($err_mssg) { if (!$raiseErrors) { return false; } if (FLEXI_J16GE) { throw new Exception($err_mssg, $err_type); } else { JError::raiseError($err_type, $err_mssg); } } } // ********************************************************************* // Some layouts optionally limit to a specific category, for these // create an empty category data object (if one was not created already) // ********************************************************************* if ($this->_layout) { if ($this->_layout != 'mcats' && !empty($_category)) { $this->_category = $_category; } else { $this->_category = new stdClass(); $this->_category->published = 1; $this->_category->id = $this->_id; // can be zero for layouts: author/myitems/favs/tags, etc $this->_category->title = ''; $this->_category->description = ''; $this->_category->slug = ''; $this->_category->ids = $this->_ids; // mcats layout but it can be empty, to allow all categories } } else { $this->_category = $_category; } // ***************************************************** // Check for proper layout configuration and throw error // ***************************************************** if ($this->_layout) { $err_mssg = $err_type = false; if (!in_array($this->_layout, array('favs', 'tags', 'mcats', 'myitems', 'author'))) { $err_mssg = JText::sprintf('FLEXI_CONTENT_LIST_LAYOUT_IS_NOT_SUPPORTED', $this->_layout); $err_type = 404; } else { if ($this->_layout == 'author' && !$this->_authorid) { $err_mssg = JText::_('FLEXI_CANNOT_LIST_CONTENT_AUTHORID_NOT_SET'); $err_type = 404; } else { if ($this->_layout == 'tags' && !$this->_tagid) { $err_mssg = JText::_('FLEXI_CANNOT_LIST_CONTENT_TAGID_NOT_SET'); $err_type = 404; } else { if ($this->_layout == 'myitems' && !$this->_authorid) { $err_mssg = JText::_('FLEXI_LOGIN_TO_DISPLAY_YOUR_CONTENT'); $err_type = 403; $login_redirect = true; } else { if ($this->_layout == 'favs' && !$this->_authorid) { $err_mssg = JText::_('FLEXI_LOGIN_TO_DISPLAY_YOUR_CONTENT'); $err_type = 403; $login_redirect = true; } } } } } // Raise a notice and redirect if ($err_mssg) { if (!$raiseErrors) { return false; } if (!empty($login_redirect)) { // redirect unlogged user to login $uri = JFactory::getURI(); $return = $uri->toString(); $com_users = FLEXI_J16GE ? 'com_users' : 'com_user'; $url = $cparams->get('login_page', 'index.php?option=' . $com_users . '&view=login'); $return = strtr(base64_encode($return), '+/=', '-_,'); $url .= '&return=' . $return; // '&return='.base64_encode($return); $url .= '&isfcurl=1'; JError::raiseWarning($err_type, $err_mssg); $app->redirect($url); } else { if (FLEXI_J16GE) { throw new Exception($err_mssg, $err_type); } else { JError::raiseError($err_type, $err_mssg); } } } } // ******************************************************* // Set category parameters, these have already been loaded // ******************************************************* $this->_category->parameters = $this->_params; // ****************************************************************** // Check whether category access level allows access and throw errors // but skip checking Access if so requested via function parameter // ****************************************************************** if (!$checkAccess) { return $this->_category; } // Check access level of category and of its parents $canread = true; if ($this->_id) { $aid_arr = JAccess::getAuthorisedViewLevels($user->id); $allowed_levels = array_flip($aid_arr); $canread = isset($allowed_levels[$this->_category->access]); if ($canread) { foreach ($parents as $parent) { if (!isset($allowed_levels[$parent->access])) { $canread = false; break; } } } } // Handle unreadable category (issue 403 unauthorized error, redirecting unlogged users to login) if ($this->_id && !$canread) { if ($user->guest) { // Redirect to login $uri = JFactory::getURI(); $return = $uri->toString(); $com_users = FLEXI_J16GE ? 'com_users' : 'com_user'; $url = $cparams->get('login_page', 'index.php?option=' . $com_users . '&view=login'); $return = strtr(base64_encode($return), '+/=', '-_,'); $url .= '&return=' . $return; // '&return='.base64_encode($return); $url .= '&isfcurl=1'; JError::raiseWarning(403, JText::sprintf("FLEXI_LOGIN_TO_ACCESS", $url)); $app->redirect($url); } else { if ($cparams->get('unauthorized_page', '')) { $app->redirect($cparams->get('unauthorized_page')); } else { JError::raiseWarning(403, JText::_("FLEXI_ALERTNOTAUTH_VIEW")); $app->redirect('index.php'); } } } return $this->_category; }
/** * 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 = 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'); $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'); // ************************ // 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 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::_('FLEXICONTENT_MYITEMS'); break; case 'author': $default_heading = JText::_('FLEXICONTENT_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::_('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 = 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); // ************************************ // Add rel canonical html head link tag (TODO: improve multi-page handing) // ************************************ $port = $uri->getPort(); $base = $uri->getScheme() . '://' . $uri->getHost() . ($port ? ':' . $port : ''); $start = JRequest::getInt('start', ''); $start = $start ? "&start=" . $start : ""; // ******************************************************************************************** // 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; $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'); foreach ($items as $item) { $item->event = new stdClass(); $item->params = new JRegistry($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 (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(); $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(); $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 = JURI::base(true) . '/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 = '&h=' . $cat_image_height; $w = '&w=' . $cat_image_width; $aoe = '&aoe=1'; $q = '&q=95'; $zc = $cat_image_method ? '&zc=' . $cat_image_method : ''; } if ($cat_default_image) { $src = JURI::base(true) . "/" . $joomla_image_url . $cat_default_image; $ext = pathinfo($src, PATHINFO_EXTENSION); $f = in_array($ext, array('png', 'ico', 'gif')) ? '&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 = JURI::base(true) . "/" . $joomla_image_url . $cat->image; $ext = pathinfo($src, PATHINFO_EXTENSION); $f = in_array($ext, array('png', 'ico', 'gif')) ? '&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 = pathinfo($src, PATHINFO_EXTENSION); $f = in_array($ext, array('png', 'ico', 'gif')) ? '&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 = $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 = '&h=' . $cat_image_height; $w = '&w=' . $cat_image_width; $aoe = '&aoe=1'; $q = '&q=95'; $zc = $cat_image_method ? '&zc=' . $cat_image_method : ''; } if ($cat_default_image) { $src = JURI::base(true) . "/" . $joomla_image_url . $cat_default_image; $ext = pathinfo($src, PATHINFO_EXTENSION); $f = in_array($ext, array('png', 'ico', 'gif')) ? '&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 = JURI::base(true) . "/" . $joomla_image_url . $cat->image; $ext = pathinfo($src, PATHINFO_EXTENSION); $f = in_array($ext, array('png', 'ico', 'gif')) ? '&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 = pathinfo($src, PATHINFO_EXTENSION); $f = in_array($ext, array('png', 'ico', 'gif')) ? '&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 = $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 = '&h=' . $cat_image_height; $w = '&w=' . $cat_image_width; $aoe = '&aoe=1'; $q = '&q=95'; $zc = $cat_image_method ? '&zc=' . $cat_image_method : ''; } if ($cat_default_image) { $src = JURI::base(true) . "/" . $joomla_image_url . $cat_default_image; $ext = pathinfo($src, PATHINFO_EXTENSION); $f = in_array($ext, array('png', 'ico', 'gif')) ? '&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 = JURI::base(true) . "/" . $joomla_image_url . $cat->image; $ext = pathinfo($src, PATHINFO_EXTENSION); $f = in_array($ext, array('png', 'ico', 'gif')) ? '&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 = pathinfo($src, PATHINFO_EXTENSION); $f = in_array($ext, array('png', 'ico', 'gif')) ? '&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 = $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'); $resultsCounter = $pageNav->getResultsCounter(); // for overriding model's result counter // ********************************************************************** // Print link ... must include layout and current filtering url vars, etc // ********************************************************************** $curr_url = $_SERVER['REQUEST_URI']; $print_link = $curr_url . (strstr($curr_url, '?') ? '&' : '?') . 'pop=1&tmpl=component&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); //HERE WE NEED TO PRINT THE DATA || But I think it is not protected yet echo @json_encode($items); }
/** * Method to CHECK item's -VIEWING- ACCESS, this could be moved to the controller, * if we do this, then we must check the view variable, because DISPLAY() CONTROLLER TASK * is shared among all views ... or create a separate FRONTEND controller for the ITEM VIEW * * @access private * @return array * @since 1.5 */ function _check_viewing_access($version = false) { global $globalcats; $app = JFactory::getApplication(); $user = JFactory::getUser(); $session = JFactory::getSession(); $aid = (int) $user->get('aid'); $gid = (int) $user->get('gid'); $cid = $this->_cid; $params = $this->_item->parameters; $cparams = $this->_cparams; $fcreturn = serialize(array('id' => @$this->_item->id, 'cid' => $cid)); // a special url parameter, used by some SEF code $referer = @$_SERVER['HTTP_REFERER']; // the previously viewed page (refer) if (!flexicontent_html::is_safe_url($referer)) { $referer = JURI::base(); } // Ignore it if potentially non safe URL, e.g. non-internal // a basic item title string $title_str = "<br />" . JText::_('FLEXI_TITLE') . ": " . $this->_item->title . '[id: ' . $this->_item->id . ']'; // Since we will check access for VIEW (=read) only, we skip checks if TASK Variable is set, // the edit() or add() or other controller task, will be responsible for checking permissions. if (@$this->_item->id && !JRequest::getVar('task', false) && JRequest::getVar('view') == FLEXI_ITEMVIEW) { //************************************************************* // STEP A: Calculate ownership, edit permission and read access // (a) isOwner, (b) canedititem, (c) canviewitem //************************************************************* // (a) Calculate if owned by current user $isOwner = $this->_item->created_by == $user->get('id'); // (b) Calculate edit access ... // NOTE: we will allow view access if current user can edit the item (but set a warning message about it, see bellow) $canedititem = $params->get('access-edit'); $caneditstate = $params->get('access-edit-state'); if (!$caneditstate) { // Item not editable, check if item is editable till logoff if ($session->has('rendered_uneditable', 'flexicontent')) { $rendered_uneditable = $session->get('rendered_uneditable', array(), 'flexicontent'); $canedititem = isset($rendered_uneditable[$this->_item->id]); } } // (c) Calculate read access ... also considering the access level of parent categories $_cid_ = $cid ? $cid : $this->_item->catid; if (!isset($this->_item->ancestor_cats_accessible)) { $aid_arr = JAccess::getAuthorisedViewLevels($user->id); $allowed_levels = array_flip($aid_arr); $catshelper = new flexicontent_cats($_cid_); $parents = $catshelper->getParentlist($all_cols = false); $ancestor_cats_accessible = true; foreach ($parents as $parent) { if (!isset($allowed_levels[$parent->access])) { $ancestor_cats_accessible = false; break; } } $this->_item->ancestor_cats_accessible = $ancestor_cats_accessible; } $canviewitem = $params->get('access-view') && $this->_item->ancestor_cats_accessible; // ********************************************************************************************* // STEP B: Calculate SOME ITEM PUBLICATION STATE FLAGS, used to decide if current item is active // FLAGS: item_is_published, item_is_scheduled, item_is_expired, ancestor_cats_published // ********************************************************************************************* $item_is_published = $this->_item->state == 1 || $this->_item->state == -5 || $this->_item->state == (FLEXI_J16GE ? 2 : -1); $item_is_scheduled = $this->_item->publication_scheduled; $item_is_expired = $this->_item->publication_expired; if ($cid) { // cid is set, check state of current item category only // NOTE: J1.6+ all ancestor categories from current one to the root, for J1.5 only the current one ($cid) if (!isset($this->_item->ancestor_cats_published)) { $ancestor_cats_published = true; foreach ($globalcats[$cid]->ancestorsarray as $pcid) { $ancestor_cats_published = $ancestor_cats_published && $globalcats[$pcid]->published == 1; } $this->_item->ancestor_cats_published = $ancestor_cats_published; } $ancestor_cats_published = $this->_item->ancestor_cats_published; //$this->_item->catpublished; $cats_np_err_mssg = JText::sprintf('FLEXI_CONTENT_UNAVAILABLE_ITEM_CURRCAT_UNPUBLISHED', $cid); } else { // cid is not set, we have no current category, the item is visible if it belongs to at one published category $itemcats = $this->_item->categories; $ancestor_cats_published = true; foreach ($itemcats as $catid) { if (!isset($globalcats[$catid])) { continue; } $ancestor_cats_published |= $globalcats[$catid]->published; // For J1.6+ check all ancestor categories from current one to the root foreach ($globalcats[$catid]->ancestorsarray as $pcid) { $ancestor_cats_published = $ancestor_cats_published && $globalcats[$pcid]->published == 1; } } $cats_np_err_mssg = JText::_('FLEXI_CONTENT_UNAVAILABLE_ITEM_ALLCATS_UNPUBLISHED'); } // Calculate if item is active ... and viewable is also it's (current or All) categories are published $item_active = $item_is_published && !$item_is_scheduled && !$item_is_expired; $item_n_cat_active = $item_active && $ancestor_cats_published; $previewing_and_unlogged = $version && $user->guest; // this is a flag indicates to redirect to login instead of 404 error $ignore_publication = $canedititem || $caneditstate || $isOwner || $previewing_and_unlogged; $inactive_notice_set = false; $item_state_pending = $this->_item->state == -3; $item_state_draft = $this->_item->state == -4; //*********************************************************************************************************************** // STEP C: CHECK item state, if publication state is not ignored terminate with 404 NOT found, otherwise add a notice // NOTE: Asking all users to login when item is not active maybe wrong approach, so instead we raise 404 error, but we // will ask them to login only if previewing a latest or specific version (so ignore publication FLAG includes this case) // (a) Check that item is PUBLISHED (1,-5) or ARCHIVED (-1) // (b) Check that item has expired publication date // (c) Check that item has scheduled publication date // (d) Check that current item category or all items categories are published //*********************************************************************************************************************** // (a) Check that item is PUBLISHED (1,-5) or ARCHIVED (-1) if (!$caneditstate && ($item_state_pending || $item_state_draft) && $isOwner) { // SPECIAL workflow case, regardless of (view/edit privilege), allow users to view unpublished owned content, (a) if waiting for approval, or (b) if can request approval $inactive_notice_set = true; } else { if (!$item_is_published && !$ignore_publication) { // Raise error that the item is unpublished $msg = JText::_('FLEXI_CONTENT_UNAVAILABLE_ITEM_UNPUBLISHED') . $title_str; if (FLEXI_J16GE) { throw new Exception($msg, 404); } else { JError::raiseError(404, $msg); } } else { if (!$item_is_published && !$inactive_notice_set) { // Item edittable, set warning that ... JError::raiseNotice(404, JText::_('FLEXI_CONTENT_UNAVAILABLE_ITEM_UNPUBLISHED')); $inactive_notice_set = true; } } } // NOTE: First, we check for expired publication, since if item expired, scheduled publication is meaningless // (b) Check that item has expired publication date if ($item_is_expired && !$ignore_publication) { // Raise error that the item is scheduled for publication $msg = JText::_('FLEXI_CONTENT_UNAVAILABLE_ITEM_EXPIRED') . $title_str; if (FLEXI_J16GE) { throw new Exception($msg, 404); } else { JError::raiseError(404, $msg); } } else { if ($item_is_expired && !$inactive_notice_set) { // Item edittable, set warning that ... JError::raiseNotice(404, JText::_('FLEXI_CONTENT_UNAVAILABLE_ITEM_EXPIRED')); $inactive_notice_set = true; } } // (c) Check that item has scheduled publication date if ($item_is_scheduled && !$ignore_publication) { // Raise error that the item is scheduled for publication $msg = JText::_('FLEXI_CONTENT_UNAVAILABLE_ITEM_SCHEDULED') . $title_str; if (FLEXI_J16GE) { throw new Exception($msg, 404); } else { JError::raiseError(404, $msg); } } else { if ($item_is_scheduled && !$inactive_notice_set) { // Item edittable, set warning that ... JError::raiseNotice(404, JText::_('FLEXI_CONTENT_UNAVAILABLE_ITEM_SCHEDULED')); $inactive_notice_set = true; } } // (d) Check that current item category or all items categories are published if (!$ancestor_cats_published && !$ignore_publication) { // Terminate execution with a HTTP not-found Server Error $msg = $cats_np_err_mssg . $title_str; if (FLEXI_J16GE) { throw new Exception($msg, 404); } else { JError::raiseError(404, $msg); } } else { if (!$ancestor_cats_published && !$inactive_notice_set) { // Item edittable, set warning that item's (ancestor) category is unpublished JError::raiseNotice(404, $cats_np_err_mssg); $inactive_notice_set = true; } } //******************************************************************************************* // STEP D: CHECK viewing access in relation to if user being logged and being owner / editor // (a) redirect user previewing a non-current item version, to either current item version or to refer if has no edit permission // (b) redirect item owner to previous page if user has no access (read/edit) to the item // (c) redirect unlogged user to login, so that user can possible login to privileged account // (d) redirect unauthorized logged user to the unauthorized page (if this is set) // (e) finally raise a 403 forbidden Server Error if user is unauthorized to access item //******************************************************************************************* // SPECIAL case when previewing an non-current version of an item, this is allowed only if user can edit the item $current_version = FLEXIUtilities::getCurrentVersions($this->_id, true); // Get current item version if ($version && $version != $current_version && !$canedititem && !$previewing_and_unlogged) { // (a) redirect user previewing a non-current item version, to either current item version or to refer if has no edit permission JError::raiseNotice(403, JText::_('FLEXI_ALERTNOTAUTH_PREVIEW_UNEDITABLE') . "<br />" . JText::_('FLEXI_ALERTNOTAUTH_TASK')); if ($item_n_cat_active && $canviewitem) { $app->redirect(JRoute::_(FlexicontentHelperRoute::getItemRoute($this->_item->slug, $this->_item->categoryslug, 0, $this->_item))); } else { $app->redirect($referer); // Item not viewable OR no view access, redirect to refer page } } else { if (!$item_n_cat_active && !$previewing_and_unlogged) { if (!$caneditstate && ($item_state_pending || $item_state_draft) && $isOwner) { // no redirect, SET message to owners, to wait for approval or to request approval of their content $app->enqueueMessage(JText::_($item_state_pending ? 'FLEXI_ALERT_VIEW_OWN_PENDING_STATE' : 'FLEXI_ALERT_VIEW_OWN_DRAFT_STATE'), 'notice'); } else { if (!$canedititem && !$caneditstate && $isOwner) { // (b) redirect item owner to previous page if user cannot access (read/edit) the item JError::raiseNotice(403, JText::_($item_state_pending ? 'FLEXI_ALERTNOTAUTH_VIEW_OWN_PENDING' : 'FLEXI_ALERTNOTAUTH_VIEW_OWN_UNPUBLISHED')); $app->redirect($referer); } else { if ($canedititem || $caneditstate) { // no redirect, SET notice to the editors, that they are viewing unreadable content because they can edit the item $app->enqueueMessage(JText::_('FLEXI_CONTENT_ACCESS_ALLOWED_BECAUSE_EDITABLE_PUBLISHABLE'), 'notice'); } else { $app->enqueueMessage('INTERNAL ERROR: item inactive but checks were ignored despite current user not begin item owner or item assigned editor', 'notice'); $app->redirect($referer); } } } } else { if (!$canviewitem && !$canedititem || !$item_n_cat_active) { if ($user->guest) { // (c) redirect unlogged user to login, so that user can possible login to privileged account $uri = JFactory::getURI(); $return = $uri->toString(); $com_users = FLEXI_J16GE ? 'com_users' : 'com_user'; $url = $cparams->get('login_page', 'index.php?option=' . $com_users . '&view=login'); $return = strtr(base64_encode($return), '+/=', '-_,'); $url .= '&return=' . $return; //$url .= '&return='.base64_encode($return); $url .= '&fcreturn=' . base64_encode($fcreturn); JError::raiseWarning(403, JText::sprintf("FLEXI_LOGIN_TO_ACCESS", $url)); $app->redirect($url); } else { $msg = JText::_('FLEXI_ALERTNOTAUTH_VIEW'); $msg .= $item->type_id && !$this->_item->has_type_access ? "<br/>" . JText::_("FLEXI_ALERTNOTAUTH_VIEW_TYPE") : ''; $msg .= $item->catid && !$this->_item->has_mcat_access ? "<br/>" . JText::_("FLEXI_ALERTNOTAUTH_VIEW_MCAT") : ''; $msg .= $cid && !$this->_item->ancestor_cats_accessible ? "<br/>" . JText::_("FLEXI_ALERTNOTAUTH_VIEW_MCAT") : ''; if ($cparams->get('unauthorized_page', '')) { // (d) redirect unauthorized logged user to the unauthorized page (if this is set) JError::raiseNotice(403, $msg); $app->redirect($cparams->get('unauthorized_page')); } else { // (e) finally raise a 403 forbidden Server Error if user is unauthorized to access item if (FLEXI_J16GE) { throw new Exception($msg, 403); } else { JError::raiseError(403, $msg); } } } } else { } } } } // End of Existing item (not new) }