/** * Creates the page's display * * @since 1.0 */ function display($tpl = null) { $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; // Get various data from the model $items = $this->get('Data'); // Get field values $_vars = null; FlexicontentFields::getItemFields($items, $_vars, $_view = 'category', $aid); // Zero unneeded search index text foreach ($items as $item) { $item->search_index = ''; } // Use &test=1 to test / preview item data of first item if (JRequest::getCmd('test', 0)) { $item = reset($items); echo "<pre>"; print_r($item); exit; } // Output items in JSON FORMAT echo @json_encode($items); }
/** * Creates the page's display * * @since 1.0 */ function display($tpl = null) { $user = JFactory::getUser(); $aid = JAccess::getAuthorisedViewLevels($user->id); // Get model $model = $this->getModel(); // Indicate to model that current view IS item form $model->isForm = false; $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__'); // Indicate to model to merge menu parameters if menu matches $model->mergeMenuParams = 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 // Get the item, loading item data and doing parameters merging $item = $model->getItem(null, $check_view_access = 2, $no_cache = $version || $preview, $force_version = $version || $preview ? $version : 0); // ZERO means unversioned data // 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 field values $items = array($item); $_vars = null; FlexicontentFields::getItemFields($items, $_vars, $_view = FLEXI_ITEMVIEW, $aid); // Zero unneeded search index text foreach ($items as $item) { $item->search_index = ''; } $item->search_index = ''; // Use &test=1 to test / preview item data if (JRequest::getCmd('test', 0)) { echo "<pre>"; print_r($item); exit; } // Output item in JSON FORMAT echo @json_encode($item); }
/** * Method to bind fields to an items object * * @access private * @return object * @since 1.5 */ static function &getFields(&$_items, $view = FLEXI_ITEMVIEW, $params = null, $aid = false, $use_tmpl = true) { static $expired_cleaned = false; if (!$_items) { return $_items; } if (!is_array($_items)) { $items = array(&$_items); } else { $items =& $_items; } $user = JFactory::getUser(); $cparams = JComponentHelper::getParams('com_flexicontent'); $print_logging_info = $cparams->get('print_logging_info'); if ($print_logging_info) { global $fc_run_times; $start_microtime = microtime(true); } // Calculate access for current user if it was not given or if given access is invalid if (FLEXI_J16GE) { $aid = is_array($aid) ? $aid : JAccess::getAuthorisedViewLevels($user->id); } else { $aid = $aid !== false ? (int) $aid : (int) $user->get('aid'); } // Apply cache to public (unlogged) users only /*$apply_cache = !$user->id && FLEXI_CACHE; if ($apply_cache) { $itemcache = JFactory::getCache('com_flexicontent_items'); // Get Joomla Cache of '...items' Caching Group $itemcache->setCaching(1); // Force cache ON $itemcache->setLifeTime(FLEXI_CACHE_TIME); // Set expire time (default is 1 hour) $filtercache = JFactory::getCache('com_flexicontent_filters'); // Get Joomla Cache of '...filters' Caching Group $filtercache->setCaching(1); // Force cache ON $filtercache->setLifeTime(FLEXI_CACHE_TIME); // Set expire time (default is 1 hour) // Auto-clean expired item & filters cache, only done here once if (FLEXI_GC && !$expired_cleaned) { $itemcache->gc(); $filtercache->gc(); $expired_cleaned = true; } // ... now retrieved CACHED ... code removed ... }*/ // @TODO : move to the constructor // This is optimized regarding the use of SINGLE QUERY to retrieve the core item data $vars['tags'] = FlexicontentFields::_getTags($items); $vars['cats'] = FlexicontentFields::_getCategories($items); $vars['favourites'] = FlexicontentFields::_getFavourites($items); $vars['favoured'] = FlexicontentFields::_getFavoured($items); $vars['authors'] = FlexicontentFields::_getAuthors($items); $vars['modifiers'] = FlexicontentFields::_getModifiers($items); $vars['typenames'] = FlexicontentFields::_getTypenames($items); $vars['votes'] = FlexicontentFields::_getVotes($items); $vars['custom'] = FlexicontentFields::_getCustomValues($items); FlexicontentFields::getItemFields($items, $vars, $view, $aid); if ($print_logging_info) { @($fc_run_times['field_values_params'] += round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10); } $_rendered = array(); if ($params) { $always_create_fields_display = $cparams->get('always_create_fields_display', 0); $flexiview = JRequest::getVar('view'); // CHECK if 'always_create_fields_display' enabled and create the display for all item's fields // *** This should be normally set to ZERO (never), to avoid a serious performance penalty !!! // 0: never, 1: always, 2: only in item view, 3: never unless in a template position, this effects function: renderPositions() if ($always_create_fields_display == 1 || $always_create_fields_display == 2 && $flexiview == FLEXI_ITEMVIEW && $view == FLEXI_ITEMVIEW) { $field_names = array(); foreach ($items as $i => $item) { if ($items[$i]->fields) { foreach ($items[$i]->fields as $field) { $values = isset($items[$i]->fieldvalues[$field->id]) ? $items[$i]->fieldvalues[$field->id] : array(); $field = FlexicontentFields::renderField($items[$i], $field, $values, $method = 'display', $view); $field_names[$field->name] = 1; } } } foreach ($field_names as $field_name => $_ignore) { $_rendered['ALL'][$field_name] = 1; } } // Render field positions $items = FlexicontentFields::renderPositions($items, $view, $params, $use_tmpl, $_rendered); } return $items; }