/com_flexicontent_v2.x/site/classes/flexicontent.fields.php
PHP | 3300 lines | 2156 code | 526 blank | 618 comment | 526 complexity | 2069c6a2b4cbc71ed7cea742ffd2753f MD5 | raw file
Possible License(s): MIT, GPL-2.0, Apache-2.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * @version 1.5 stable $Id: flexicontent.fields.php 1884 2014-04-13 10:38:52Z ggppdk $
- * @package Joomla
- * @subpackage FLEXIcontent
- * @copyright (C) 2009 Emmanuel Danan - www.vistamedia.fr
- * @license GNU/GPL v2
- *
- * FLEXIcontent is a derivative work of the excellent QuickFAQ component
- * @copyright (C) 2008 Christoph Lukes
- * see www.schlu.net for more information
- *
- * FLEXIcontent is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
- defined( '_JEXEC' ) or die( 'Restricted access' );
- // Include com_content helper files, these are needed by some content plugins
- require_once (JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php');
- require_once (JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'query.php');
- //include constants file
- require_once (JPATH_ADMINISTRATOR.DS.'components'.DS.'com_flexicontent'.DS.'defineconstants.php');
- class FlexicontentFields
- {
- /**
- * Function to render the field display variables for the given items
- *
- * @param int $item_id
- * @return string : the HTML of the item view, also the CSS / JS file would have been loaded
- * @since 1.5
- */
- static function renderFields( $item_per_field=true, $item_ids=array(), $field_names=array(), $view=FLEXI_ITEMVIEW, $methods=array(), $cfparams=array() )
- {
- require_once (JPATH_ADMINISTRATOR.DS.'components/com_flexicontent/defineconstants.php');
- JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_flexicontent'.DS.'tables');
- //require_once("components/com_flexicontent/classes/flexicontent.fields.php");
- require_once("components/com_flexicontent/classes/flexicontent.helper.php");
-
-
- // ***************************
- // Check if no data were given
- // ***************************
-
- if ( empty($item_ids) || empty($field_names) ) return false;
-
- // Get item data, needed for rendering fields
- $db = JFactory::getDBO();
-
- $item_ids = array_unique(array_map('intval', $item_ids));
- $item_ids_list = implode("," , $item_ids) ;
-
- $query = 'SELECT i.id, i.*, ie.*, '
- . ' CASE WHEN CHAR_LENGTH(i.alias) THEN CONCAT_WS(\':\', i.id, i.alias) ELSE i.id END as slug,'
- . ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as categoryslug'
- . ' FROM #__content AS i'
- . ' LEFT JOIN #__flexicontent_items_ext AS ie ON ie.item_id = i.id'
- . ' LEFT JOIN #__categories AS c ON c.id = i.catid'
- . ' WHERE i.id IN ('. $item_ids_list .')'
- . ' GROUP BY i.id';
- $db->setQuery($query);
- $items = $db->loadObjectList();
- if ($db->getErrorNum()) JFactory::getApplication()->enqueueMessage(__FUNCTION__.'(): SQL QUERY ERROR:<br/>'.nl2br($db->getErrorMsg()),'error');
- if (!$items) return false;
- foreach ($items as $i => $item) $_item_id_map[$item->id] = & $items[$i];
-
-
- // **************
- // Get Field info
- // **************
- /*if ( $using_ids )
- {
- $field_ids = array_unique(array_map('intval', $_field_ids));
- $field_ids_list = implode("," , $field_ids) ;
-
- $field_where = ' WHERE f.id IN ('. $field_ids_list .')';
- }
- else {
- foreach ($field_names as $i => $field_name) {
- $field_names[$i] = preg_replace("/[\"'\\\]/u", "", $field_name);
- }
- $field_names_list = "'". implode("','" , $field_names) ."'";
-
- $field_where = 'f.name IN ('. $field_names_list .')';
- }
-
- $query = 'SELECT f.*'
- . ' FROM #__flexicontent_fields AS f'
- . ' WHERE 1 '.$field_where
- ;
- $db->setQuery($query);
- $fields = $db->loadObjectList('id');
- if (!$fields) return false;*/
-
-
- // *********************************
- // Render Display Variable of Fields
- // *********************************
-
- // Get Field values at once to minimized performance impact, null 'params' mean only retrieve values
- /*if ($item_per_field && count($items)>1)
- // we have at least 2 item and item is per field, this will retrieve all values with single SQL query
- FlexicontentFields::getFields($items, $view, $params = null, $aid = false);*/
-
- $return = array();
- foreach ($field_names as $i => $field_name)
- {
- $method = isset( $methods[$i] ) ? $methods[$i] : 'display';
- if ( $item_per_field )
- {
- if ( !isset( $_item_id_map[ $item_ids[$i] ] ) ) { echo "not found item: ".$item_ids[$i] ." <br/>"; continue;}
-
- // Render Display variable of Field for respective item
- $_item = & $_item_id_map[$item_ids[$i]];
- FlexicontentFields::getFieldDisplay($_item, $field_name, $values=null, $method, $view);
- // Add to return array
- $return[$_item->id][$field_name] = $_item->fields[$field_name]->$method;
- }
- else
- {
- // Render Display variable of Field for all items
- FlexicontentFields::getFieldDisplay($items, $field_name, $values=null, $method, $view);
- // Add to return array
- foreach ($items as $item) {
- $return[$item->id][$field_name] = $item->fields[$field_name]->display;
- }
- }
- }
- return $return;
- }
-
-
-
- /**
- * 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 $apply_cache = null;
- static $expired_cleaned = false;
-
- if (!$_items) return $_items;
- if (!is_array($_items)) $items = array( & $_items ); else $items = & $_items ;
-
- $user = JFactory::getUser();
- $mainframe = JFactory::getApplication();
- $cparams = $mainframe->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 if it was not providden
- if (FLEXI_J16GE) {
- $aid = is_array($aid) ? $aid : $user->getAuthorisedViewLevels();
- } else {
- $aid = $aid!==false ? (int) $aid : (int) $user->get('aid');
- }
-
- // Apply cache to public (unlogged) users only
- /*if ($apply_cache === null) {
- if (FLEXI_J16GE) {
- $apply_cache = max($aid) <= 1; // ACCESS LEVEL : PUBLIC 1 , REGISTERED 2
- } else {
- //$apply_cache = FLEXI_ACCESS ? ($user->gmid == '0' || $user->gmid == '0,1') : ($user->gid <= 18); // This is for registered too
- $apply_cache = $aid <= 0; // ACCESS LEVEL : PUBLIC 0 , REGISTERED 1
- }
- $apply_cache = $apply_cache && 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 expiration to default e.g. one 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 expiration to default e.g. one hour
-
- // Auto-clean expired item & filters cache, only done here once
- if (FLEXI_GC && !$expired_cleaned) {
- $itemcache->gc();
- $filtercache->gc();
- $expired_cleaned = true;
- }
- }*/
-
- // @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;
-
- if ($params) // NULL/empty parameters mean only retrieve field values
- {
- // 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 !!!
- foreach ($items as $i => $item)
- {
- $always_create_fields_display = $cparams->get('always_create_fields_display',0);
- $flexiview = JRequest::getVar('view', false);
- // 0: never, 1: always, 2: only in item view
- if ($always_create_fields_display==1 || ($always_create_fields_display==2 && $flexiview==FLEXI_ITEMVIEW) ) {
- 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);
- }
- }
- }
- }
-
- // Render field positions
- $items = FlexicontentFields::renderPositions($items, $view, $params, $use_tmpl);
- }
- return $items;
- }
- /**
- * Method to fetch the fields from an item object
- *
- * @access private
- * @return object
- * @since 1.5
- */
- static function & getItemFields(&$items, &$vars, $view=FLEXI_ITEMVIEW, $aid=false)
- {
- if ( empty($items) ) return;
-
- static $type_fields = array();
-
- $mainframe = JFactory::getApplication();
- $dispatcher = JDispatcher::getInstance();
- $db = JFactory::getDBO();
- $user = JFactory::getUser();
- jimport('joomla.html.parameter');
-
- foreach ($items as $i => $item)
- {
- if (!FLEXI_J16GE && $item->sectionid != FLEXI_SECTION) continue;
-
- $item_id = $item->id;
-
- $cats = isset($vars['cats'][$item_id]) ? $vars['cats'][$item_id] : array();
- $tags = isset($vars['tags'][$item_id]) ? $vars['tags'][$item_id] : array();
- $favourites= isset($vars['favourites'][$item_id])? $vars['favourites'][$item_id]->favs : 0;
- $favoured = isset($vars['favoured'][$item_id]) ? $vars['favoured'][$item_id]->fav : 0;
- $author = isset($vars['authors'][$item_id]) ? $vars['authors'][$item_id] : '';
- $modifier = isset($vars['modifiers'][$item_id]) ? $vars['modifiers'][$item_id] : '';
- $typename = isset($vars['typenames'][$item_id]) ? $vars['typenames'][$item_id] : '';
- $vote = isset($vars['votes'][$item_id]) ? $vars['votes'][$item_id] : '';
- $custom = isset($vars['custom'][$item_id]) ? $vars['custom'][$item_id] : array();
-
-
- // ONCE per Content Item Type
- if ( !isset($type_fields[$item->type_id]) )
- {
- if (FLEXI_J16GE) {
- $aid_arr = is_array($aid) ? $aid : $user->getAuthorisedViewLevels();
- $aid_list = implode(",", $aid);
- $andaccess = ' AND fi.access IN (0,'.$aid_list.')' ;
- $joinaccess = '';
- } else {
- $aid = $aid!==false ? (int) $aid : (int) $user->get('aid');
- $andaccess = FLEXI_ACCESS ? ' AND (gi.aro IN ( '.$user->gmid.' ) OR fi.access <= '. $aid . ')' : ' AND fi.access <= '.$aid ;
- $joinaccess = FLEXI_ACCESS ? ' LEFT JOIN #__flexiaccess_acl AS gi ON fi.id = gi.axo AND gi.aco = "read" AND gi.axosection = "field"' : '' ;
- }
-
- $query = 'SELECT fi.*'
- . ' FROM #__flexicontent_fields AS fi'
- . ' LEFT JOIN #__flexicontent_fields_type_relations AS ftrel ON ftrel.field_id = fi.id AND ftrel.type_id = '.$item->type_id
- . $joinaccess
- . ' WHERE fi.published = 1'
- . $andaccess
- . ' GROUP BY fi.id'
- . ' ORDER BY ftrel.ordering, fi.ordering, fi.name'
- ;
- $db->setQuery($query);
- $type_fields[$item->type_id] = $db->loadObjectList('name');
- }
- $item->fields = array();
- if ($type_fields[$item->type_id]) foreach($type_fields[$item->type_id] as $field_name => $field_data)
- $item->fields[$field_name] = clone($field_data);
- $item->fields = $item->fields ? $item->fields : array();
-
- if (!isset($item->parameters)) $item->parameters = FLEXI_J16GE ? new JRegistry($item->attribs) : new JParameter($item->attribs);
- $item->params = $item->parameters;
-
- $item->text = $item->introtext . chr(13).chr(13) . $item->fulltext;
- $item->tags = $tags;
- $item->cats = $cats;
- $item->favs = $favourites;
- $item->fav = $favoured;
-
- $item->creator = @$author->alias ? $author->alias : (@$author->name ? $author->name : '') ;
- $item->author = & $item->creator; // An alias ... of creator
- $item->modifier = @$modifier->name ? $modifier->name : $item->creator; // If never modified, set modifier to be the creator
- $item->modified = ($item->modified != $db->getNulldate()) ? $item->modified : $item->created; // If never modified, set modification date to be the creation date
-
- $item->cmail = @$author->email ? $author->email : '' ;
- $item->cuname = @$author->username ? $author->username : '' ;
- $item->mmail = @$modifier->email ? $modifier->email : $item->cmail;
- $item->muname = @$modifier->muname ? $modifier->muname : $item->cuname;
-
- $item->typename = @$typename->name ? $typename->name : JText::_('Article');
- $item->vote = @$vote ? $vote : '';
-
- // some aliases to much CORE field names
- $item->categories = & $item->cats;
- $item->favourites = & $item->favs;
- $item->document_type = & $item->typename;
- $item->voting = & $item->vote;
-
- // custom field values
- $item->fieldvalues = $custom;
-
- /*if ($item->fields) {
- // IMPORTANT the items model and possibly other will set item PROPERTY version_id to indicate loading an item version,
- // It is not the responisibility of this CODE to try to detect previewing of an item version, it is better left to the model
- $item->fieldvalues = FlexicontentFields::_getFieldsvalues($item->id, $item->fields, !empty($item->version_id) ? $item->version_id : 0);
- }*/
- }
-
- return $items;
- }
-
-
- /**
- * Method to render (display method) a field on demand and return the display
- *
- * @access public
- * @return object
- * @since 1.5.5
- */
- static function &getFieldDisplay(&$item_arr, $fieldname, $single_item_vals=null, $method='display', $view = FLEXI_ITEMVIEW)
- {
- // 1. Convert to array of items if not an array already
- if ( empty($item_arr) )
- return __FUNCTION__."(): empty item data given";
- else if ( !is_array($item_arr) )
- $items = array( & $item_arr );
- else
- $items = & $item_arr;
-
- // 2. Make sure that fields have been created for all given items
- $_items = array();
- foreach ($items as $i => $item) if (!isset($item->fields)) $_items[] = & $items[$i];
- if ( count($_items) ) FlexicontentFields::getFields($_items, $view);
-
- // 3. Check and create HTML display for the given field name
- $_return = array();
- foreach ($items as $item)
- {
- // Check if we have already created the display and skip current item
- if ( isset($item->onDemandFields[$fieldname]->{$method}) ) continue;
-
- // Find the field inside item
- foreach ($item->fields as $field) {
- if ( !empty($field->name) && $field->name==$fieldname ) break;
- }
-
- // Check for not found field, and skip it, this is either due to no access or wrong name ...
- $item->onDemandFields[$fieldname] = new stdClass();
- if ( empty($field->name) || $field->name!=$fieldname) {
- $item->onDemandFields[$fieldname]->label = '';
- $item->onDemandFields[$fieldname]->noaccess = true;
- $item->onDemandFields[$fieldname]->errormsg = 'field not assigned to this type of item or current user has no access';
- $item->onDemandFields[$fieldname]->{$method} = '';
- continue;
- }
-
- // Get field's values if they were custom values were not given
- if ( $single_item_vals!==null && count($items) == 1 ) {
- // $values is used only if rendering a single item
- $values = $single_item_vals;
- } else {
- $values = isset($item->fieldvalues[$field->id]) ? $item->fieldvalues[$field->id] : array();
- }
-
- // Set other field data like label and field itself !!!
- $item->onDemandFields[$fieldname]->label = $field->label;
- $item->onDemandFields[$fieldname]->noaccess = false;
- $item->onDemandFields[$fieldname]->field = & $field;
-
- // Render the (display) method of the field
- if (!isset($field->{$method})) $field = FlexicontentFields::renderField($item, $field, $values, $method, $view);
- if (!isset($field->{$method})) $field->{$method} = '';
- $item->onDemandFields[$fieldname]->{$method} = & $field->{$method};
- $_method_html[$item->id] = & $field->{$method};
- }
-
- // Return field(s) HTML (in case of multiple items this will be an array indexable by item ids
- if ( !is_array($item_arr) ) {
- $_method_html = @ $_method_html[$item_arr->id]; // Suppress field name not found ...
- }
- return $_method_html;
- }
-
- /**
- * Method to render a field
- *
- * @access public
- * @return object
- * @since 1.5
- */
- static function renderField(&$_items, &$_field, &$values, $method='display', $view=FLEXI_ITEMVIEW)
- {
- static $_trigger_plgs_ft = array();
- $flexiview = JRequest::getVar('view');
-
- // If $method (e.g. display method) is already created, then return the $field without recreating the $method
- if ( is_object($_field) && isset($_field->{$method}) ) return $_field;
-
- // Handle multi-item call
- if (!is_array($_items)) $items = array( & $_items ); else $items = & $_items ;
-
- // **********************************************************************************************
- // Create field parameters in an optimized way, and also apply Type Customization for CORE fields
- // **********************************************************************************************
- foreach($items as $item) {
- $field = is_object($_field) ? $_field : $item->fields[$_field];
- $field->item_id = (int)$item->id;
- $field->value = $values; // NOTE: currently ignored and overwritten by all CORE fields
- FlexicontentFields::loadFieldConfig($field, $item);
- }
-
-
- // ***************************************************************************************************
- // Create field HTML by calling the appropriate DISPLAY-CREATING field plugin method.
- // NOTE 1: We will not pass the 'values' method parameter to the display-creating field method,
- // instead we have set it above as the 'value' field property
- // NOTE 2: For CUSTOM fields the 'values' method parameter is prefered over the 'value' field property
- // For CORE field, both the above ('values' method parameter and 'value' field property) are
- // ignored and instead the other method parameters are used, along with the ITEM properties
- // ****************************************************************************************************
- // Log content plugin and other performance information
-
- $cparams = JComponentHelper::getParams('com_flexicontent');
- $print_logging_info = $cparams->get('print_logging_info');
- if ($print_logging_info) global $fc_run_times;
- if ($print_logging_info) $start_microtime = microtime(true);
-
- if ($field->iscore == 1) // CORE field
- {
- //$results = $dispatcher->trigger('onDisplayCoreFieldValue', array( &$field, $item, &$item->parameters, $item->tags, $item->cats, $item->favs, $item->fav, $item->vote ));
- //FLEXIUtilities::call_FC_Field_Func('core', 'onDisplayCoreFieldValue', array( &$_field, & $items, &$item->parameters, $item->tags, $item->cats, $item->favs, $item->fav, $item->vote, null, $method ) );
- $items_params = null;
- FLEXIUtilities::call_FC_Field_Func('core', 'onDisplayCoreFieldValue', array( &$_field, & $items, & $items_params, false, false, false, false, false, null, $method ) );
- }
- else // NON CORE field
- {
- //$results = $dispatcher->trigger('onDisplayFieldValue', array( &$field, $item ));
- FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayFieldValue', array(&$field, $_items, null, $method) );
- }
- if ($print_logging_info) {
- $field_render_time = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
- if ( isset($fc_run_times['render_subfields'][$item->id."_".$field->id]) ) {
- $field_render_time = $field_render_time - $fc_run_times['render_subfields'][$item->id."_".$field->id];
- @$fc_run_times['render_subfields'][$field->field_type] += $fc_run_times['render_subfields'][$item->id."_".$field->id];
- unset($fc_run_times['render_subfields'][$item->id."_".$field->id]);
- }
- @$fc_run_times['render_field'][$field->field_type] += $field_render_time;
- }
-
-
- // *****************************************
- // Trigger content plugins on the field text
- // *****************************************
- if ( !isset($_trigger_plgs_ft[$field->name]) ) {
- $_t = $field->parameters->get('trigger_onprepare_content', 0);
- if ($flexiview=='category') $_t = $_t && $field->parameters->get('trigger_plgs_incatview', 1);
- $_trigger_plgs_ft[$field->name] = $_t;
- }
-
- if ( $_trigger_plgs_ft[$field->name] ) {
- if ($print_logging_info) $start_microtime = microtime(true);
- FlexicontentFields::triggerContentPlugins($field, $item, $method, $view);
- if ( $print_logging_info ) @$fc_run_times['content_plg'] += round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
- }
-
- return $field;
- }
-
-
- /**
- * 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->title = $item->title;
- $field->slug = $item->slug;
- $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';
- }
-
- // ALL OTHER CASES: (FLEXIcontent category, FLEXIcontent module, etc),
- // Set triggering 'context' to 'com_content.article', (and also set the 'view' request variable)
- 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' );
- }
- /**
- * Method to get the fields in their positions
- *
- * @access private
- * @return object
- * @since 1.5
- */
- static function &renderPositions(&$items, $view = FLEXI_ITEMVIEW, $params = null, $use_tmpl = true)
- {
- if (!$items) return;
- if (!$params) return $items;
-
- if ($view == 'category') $layout = 'clayout';
- if ($view == FLEXI_ITEMVIEW) $layout = 'ilayout';
-
- // field's source code, can use this JRequest variable, to detect who rendered the fields (e.g. they can detect rendering from 'module')
- JRequest::setVar("flexi_callview", $view);
- if ( $use_tmpl && ($view == 'category' || $view == FLEXI_ITEMVIEW) ) {
- $fbypos = flexicontent_tmpl::getFieldsByPositions($params->get($layout, 'default'), $view);
- } else { // $view == 'module', or other
- // Create a fake template position, for fields defined via parameters
- $fbypos[0] = new stdClass();
- $fbypos[0]->fields = explode(',', $params->get('fields'));
- $fbypos[0]->methods = explode(',', $params->get('methods'));
- $fbypos[0]->position = $view;
- }
-
- $always_create_fields_display = $params->get('always_create_fields_display',0);
-
- foreach ($items as $item)
- {
- if ($always_create_fields_display != 3) { // value 3 means never create for any view (blog template incompatible)
-
- // 'description' item field is implicitly used by category layout of some templates (blog), render it
- $custom_values = false;
- if ($view == 'category') {
- if (isset($item->fields['text'])) {
- $field = $item->fields['text'];
- $field = FlexicontentFields::renderField($item, $field, $custom_values, $method='display', $view);
- }
- }
- // 'core' item fields are IMPLICITLY used by some item layout of some templates (blog), render them
- else if ($view == FLEXI_ITEMVIEW) {
- foreach ($item->fields as $field) {
- if ($field->iscore) {
- $field = FlexicontentFields::renderField($item, $field, $custom_values, $method='display', $view);
- }
- }
- }
- }
- }
-
-
- // *** RENDER fields on DEMAND, (if present in template positions)
- foreach ($fbypos as $pos) {
- // RENDER fields if they are present in a template position (or in a dummy template position ... e.g. when called by module)
- foreach ($pos->fields as $c => $f) {
-
- // Render field (if already rendered above, the function will return result immediately)
- $method = (isset($pos->methods[$c]) && $pos->methods[$c]) ? $pos->methods[$c] : 'display';
-
- // Check that field with given name: $f exists, (this will handle deleted fields, that still exist in a template position)
- $item = reset($items);
- if (!isset($item->fields[$f])) continue;
- $field = $item->fields[$f];
-
- if ($field->iscore) {
- $values = null;
- FlexicontentFields::renderField($items, $f, $values, $method, $view);
- }
-
- else foreach ($items as $item) {
- $field = $item->fields[$f];
-
- // Set field values, currently, this exists for CUSTOM fields only, OR versioned CORE/CUSTOM fields too ...
- $values = isset($item->fieldvalues[$field->id]) ? $item->fieldvalues[$field->id] : array();
-
- $field = FlexicontentFields::renderField($item, $field, $values, $method, $view);
- }
-
- foreach ($items as $item) {
- $field = $item->fields[$f];
-
- // Set template position field data
- if (isset($field->display) && strlen($field->display))
- {
- if (!isset($item->positions[$pos->position]))
- $item->positions[$pos->position] = new stdClass();
- $item->positions[$pos->position]->{$f} = new stdClass();
-
- $item->positions[$pos->position]->{$f}->id = $field->id;
- $item->positions[$pos->position]->{$f}->id = $field->id;
- $item->positions[$pos->position]->{$f}->name = $field->name;
- $item->positions[$pos->position]->{$f}->label = $field->parameters->get('display_label') ? $field->label : '';
- $item->positions[$pos->position]->{$f}->display = $field->display;
- }
- }
- }
- }
- return $items;
- }
- /**
- * Method to get the values of the fields for an item
- *
- * @access private
- * @return object
- * @since 1.5
- */
- static function _getFieldsvalues($item, $fields, $version=0)
- {
- $db = JFactory::getDBO();
- $query = 'SELECT field_id, value'
- .( $version ? ' FROM #__flexicontent_items_versions':' FROM #__flexicontent_fields_item_relations')
- .' WHERE item_id = ' . (int)$item
- .( $version ? ' AND version=' . (int)$version:'')
- .' AND value > "" '
- .' ORDER BY field_id, valueorder'
- ;
- $db->setQuery($query);
- $values = $db->loadObjectList();
- $fieldvalues = array();
- foreach ($fields as $f) {
- foreach ($values as $v) {
- if ((int)$f->id == (int)$v->field_id) {
- $fieldvalues[$f->id][] = $v->value;
- }
- }
- }
- return $fieldvalues;
- }
-
-
- /**
- * Method to get the values of the fields for multiple items at once
- *
- * @access private
- * @return object
- * @since 1.5
- */
- static function _getCustomValues($items)
- {
- $versioned_item = count($items)==1 && !empty($items[0]->version_id) && !empty($items[0]->created_by);
- $version = $versioned_item ? $items[0]->version_id : 0;
-
- $item_ids = array();
- foreach ($items as $item) $item_ids[] = $item->id;
-
- $db = JFactory::getDBO();
- $query = 'SELECT field_id, value, item_id'
- .( $version ? ' FROM #__flexicontent_items_versions':' FROM #__flexicontent_fields_item_relations')
- .' WHERE item_id IN (' . implode(',', $item_ids) .')'
- .( $version ? ' AND version=' . (int)$version:'')
- .' AND value > "" '
- .' ORDER BY item_id, field_id, valueorder' // first 2 parts are not needed ...
- ;
- $db->setQuery($query);
- $values = $db->loadObjectList();
-
- $fieldvalues = array();
- foreach ($values as $v) {
- $fieldvalues[$v->item_id][$v->field_id][] = $v->value;
- }
- return $fieldvalues;
- }
-
-
- /**
- * Method to get the tags
- *
- * @access private
- * @return object
- * @since 1.5
- */
- static function _getTags($items)
- {
- // This is fix for versioned field of creator in items view when previewing
- $versioned_item = count($items)==1 && !empty($items[0]->version_id) && !empty($items[0]->tags);
-
- $db = JFactory::getDBO();
- if ($versioned_item) {
- if (!count($items[0]->tags)) return array();
- $tids = $items[0]->tags;
- $query = 'SELECT DISTINCT t.id, t.name, ' . $items[0]->id .' as itemid, '
- . ' CASE WHEN CHAR_LENGTH(t.alias) THEN CONCAT_WS(\':\', t.id, t.alias) ELSE t.id END as slug'
- . ' FROM #__flexicontent_tags AS t'
- . " WHERE t.id IN ('" . implode("','", $tids) . "')"
- . ' AND t.published = 1'
- . ' ORDER BY t.name'
- ;
- } else {
- $cids = array();
- foreach ($items as $item) { array_push($cids, $item->id); }
- $query = 'SELECT DISTINCT t.id, t.name, i.itemid,'
- . ' CASE WHEN CHAR_LENGTH(t.alias) THEN CONCAT_WS(\':\', t.id, t.alias) ELSE t.id END as slug'
- . ' FROM #__flexicontent_tags AS t'
- . ' JOIN #__flexicontent_tags_item_relations AS i ON i.tid = t.id'
- . " WHERE i.itemid IN ('" . implode("','", $cids) . "')"
- . ' AND t.published = 1'
- . ' ORDER BY t.name'
- ;
- }
- $db->setQuery( $query );
- $tags = $db->loadObjectList();
-
- // improve performance by doing a single pass of tags to aggregate them per item
- $taglists = array();
- foreach ($tags as $tag) {
- $taglists[$tag->itemid][] = $tag;
- }
- return $taglists;
- }
- /**
- * Method to get the categories
- *
- * @access private
- * @return object
- * @since 1.5
- */
- static function _getCategories($items)
- {
- // This is fix for versioned field of creator in items view when previewing
- $versioned_item = count($items)==1 && !empty($items[0]->version_id) && !empty($items[0]->categories);
-
- $db = JFactory::getDBO();
-
- if ($versioned_item) {
- $catids = $items[0]->categories;
- $query = 'SELECT DISTINCT c.id, c.title, ' . $items[0]->id .' as itemid, '
- . ' 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 IN ('" . implode("','", $catids) . "')"
- ;
- } else {
- $cids = array();
- foreach ($items as $item) { array_push($cids, $item->id); }
- $query = 'SELECT DISTINCT c.id, c.title, rel.itemid,'
- . ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as slug'
- . ' FROM #__categories AS c'
- . ' JOIN #__flexicontent_cats_item_relations AS rel ON rel.catid = c.id'
- . " WHERE rel.itemid IN ('" . implode("','", $cids) . "')"
- ;
- }
- $db->setQuery( $query );
- $cats = $db->loadObjectList();
- // improve performance by doing a single pass of cats to aggregate them per item
- $catlists = array();
- foreach ($cats as $cat) {
- $catlists[$cat->itemid][] = $cat;
- }
- return $catlists;
- }
- /**
- * Method to get the nr of favourites
- *
- * @access private
- * @return object
- * @since 1.5
- */
- static function _getFavourites($items)
- {
- $db = JFactory::getDBO();
- $cids = array();
- foreach ($items as $item) { array_push($cids, $item->id); }
- $query = 'SELECT itemid, COUNT(id) AS favs FROM #__flexicontent_favourites'
- . " WHERE itemid IN ('" . implode("','", $cids) . "')"
- . ' GROUP BY itemid'
- ;
- $db->setQuery($query);
- $favs = $db->loadObjectList('itemid');
- return $favs;
- }
- /**
- * Method to get the favourites of an user
- *
- * @access private
- * @return object
- * @since 1.5
- */
- static function _getFavoured($items)
- {
- $db = JFactory::getDBO();
- $cids = array();
- foreach ($items as $item) { array_push($cids, $item->id); }
- $user = JFactory::getUser();
- $query = 'SELECT itemid, COUNT(id) AS fav FROM #__flexicontent_favourites'
- . " WHERE itemid IN ('" . implode("','", $cids) . "')"
- . " AND userid = '" . ((int)$user->id) ."'"
- . ' GROUP BY itemid'
- ;
- $db->setQuery($query);
- $fav = $db->loadObjectList('itemid');
- return $fav;
- }
- /**
- * Method to get the modifiers of the items
- *
- * @access private
- * @return object
- * @since 1.5
- */
- static function _getModifiers($items)
- {
- // This is fix for versioned field of modifier in items view when previewing
- $versioned_item = count($items)==1 && !empty($items[0]->version_id) && !empty($items[0]->modified_by);
-
- $db = JFactory::getDBO();
- $cids = array();
- foreach ($items as $item) { array_push($cids, $item->id); }
-
- $query = 'SELECT i.id, u.name, u.username, u.email FROM #__content AS i'
- . ' LEFT JOIN #__users AS u ON ' . ( $versioned_item ? 'u.id = '.$items[0]->modified_by : 'u.id = i.modified_by' )
- . " WHERE i.id IN ('" . implode("','", $cids) . "')"
- ;
- $db->setQuery($query);
- $modifiers = $db->loadObjectList('id');
-
- return $modifiers;
- }
- /**
- * Method to get the authors of the items
- *
- * @access private
- * @return object
- * @since 1.5
- */
- static function _getAuthors($items)
- {
- // This is fix for versioned field of creator in items view when previewing
- $versioned_item = count($items)==1 && !empty($items[0]->version_id) && !empty($items[0]->created_by);
-
- $db = JFactory::getDBO();
- $cids = array();
- foreach ($items as $item) { array_push($cids, $item->id); }
- $query = 'SELECT i.id, u.name, i.created_by_alias as alias, u.username, u.email FROM #__content AS i'
- . ' LEFT JOIN #__users AS u ON ' . ( $versioned_item ? 'u.id = '.$items[0]->created_by : 'u.id = i.created_by' )
- . " WHERE i.id IN ('" . implode("','", $cids) . "')"
- ;
- $db->setQuery($query);
- $authors = $db->loadObjectList('id');
-
- return $authors;
- }
- /**
- * Method to get the types names of the items
- *
- * @access private
- * @return object
- * @since 1.5
- */
- static function _getTypenames($items)
- {
- $db = JFactory::getDBO();
- $type_ids = array();
- foreach ($items as $item) { $type_ids[$item->type_id]=1; }
- $type_ids = array_keys($type_ids);
-
- $query = 'SELECT id, name FROM #__flexicontent_types'
- . " WHERE id IN ('" . implode("','", $type_ids) . "')"
- ;
- $db->setQuery($query);
- $types = $db->loadObjectList('id');
-
- $typenames = array();
- foreach ($items as $item) {
- $typenames[$item->id] = new stdClass();
- $typenames[$item->id]->name = $types[$item->type_id]->name;
- }
-
- return $typenames;
- }
- /**
- * Method to get the votes of the items
- *
- * @access private
- * @return object
- * @since 1.5
- */
- static function _getVotes($items)
- {
- $db = JFactory::getDBO();
- $cids = array();
- foreach ($items as $item) { array_push($cids, $item->id); }
- $query = 'SELECT * FROM #__content_rating'
- . " WHERE content_id IN ('" . implode("','", $cids) . "')"
- ;
- $db->setQuery($query);
- $votes = $db->loadObjectList('content_id');
-
- $query = 'SELECT *, field_id as extra_id FROM #__flexicontent_items_extravote'
- . " WHERE content_id IN ('" . implode("','", $cids) . "')"
- ;
- $db->setQuery($query);
- $extra_votes= $db->loadObjectList();
-
- // Assign each item 's extra votes to the item's votes as member variable "extra"
- foreach ($extra_votes as $extra_vote ) {
- $votes[$extra_vote->content_id]->extra[$extra_vote->extra_id] = $extra_vote;
- }
-
- return $votes;
- }
-
-
-
-
-
- // ***********************************************************
- // Methods for creating field configuration in an OPTMIZED way
- // ***********************************************************
-
- // Method to create field parameters in an optimized way, and also apply Type Customization for CORE fields
- static function loadFieldConfig(&$field, &$item, $name='', $field_type='', $label='', $desc='', $iscore=1) {
- $db = JFactory::getDBO();
- static $tparams = array();
- static $tinfo = array();
- static $fdata = array();
- static $no_typeparams = null;
- if ($no_typeparams) $no_typeparams = FLEXI_J16GE ? new JRegistry() : new JParameter("");
- static $is_form=null;
- if ($is_form===null) $is_form = JRequest::getVar('task')=='edit' && JRequest::getVar('option')=='com_flexicontent';
-
- // Create basic field data if no field given
- if (!empty($name)) {
- $field->iscore = $iscore; $field->name = $name; $field->field_type = $field_type; $field->label = $label; $field->description = $desc; $field->attribs = '';
- }
-
- // Get Content Type parameters if not already retrieved
- $type_id = @$item->type_id;
- if ($type_id && ( !isset($tinfo[$type_id]) || !isset($tparams[$type_id]) ) )
- {
- $tinfo[$type_id] = $tparams[$type_id] = null;
- FlexicontentFields::_getTypeToCoreFieldParams ($type_id, $tinfo[$type_id], $tparams[$type_id]);
- }
-
- // Set Content Type parameters otherwise set empty defaults (e.g. new item form with not typeid set)
- $type_data_exist = $type_id && $tinfo[$type_id] && $tparams[$type_id] ;
-
- $typename = $type_data_exist ? $tinfo[$type_id]['typename'] : '';
- $typealias = $type_data_exist ? $tinfo[$type_id]['typealias'] : '';
- $tindex = $type_data_exist ? $typename.'_'.$typealias : 'no_type';
- if ($type_data_exist) $typeparams = & $tparams[$type_id]; else $typeparams = & $no_typeparams;
-
- // Create the (CREATED ONCE per field) SHARED object that will contain: (a) label, (b) description, (c) all (merged) field parameters
- // Create parameters once per custom field OR once per pair of: Core FIELD type - Item CONTENT type
- if ( !isset($fdata[$tindex][$field->name]) ) {
-
- if ( !$field->iscore || !$type_id ) {
-
- // CUSTOM field or CORE field with no type
- $fdata[$tindex][$field->name] = new stdClass();
- $fdata[$tindex][$field->name]->parameters = FLEXI_J16GE ? new JRegistry($field->attribs) : new JParameter($field->attribs);
-
- } else {
-
- $pn_prefix = $field->field_type!='maintext' ? $field->name : $field->field_type;
-
- // Initialize an empty object, and create parameters object of the field
- $fdata[$tindex][$field->name] = new stdClass();
- $fdata[$tindex][$field->name]->parameters = FLEXI_J16GE ? new JRegistry($field->attribs) : new JParameter($field->attribs);
-
- // SET a type specific label, description for the current CORE field (according to current language)
- $field_label_type = $tparams[$type_id]->get($pn_prefix.'_label', '');
- $field_desc_type = $tparams[$type_id]->get($pn_prefix.($is_form ? '_desc' : '_viewdesc'), '');
- FlexicontentFields::_getLangSpecificValue ($type_id, $field_label_type, 'label', $fdata[$tindex][$field->name]);
- FlexicontentFields::_getLangSpecificValue ($type_id, $field_desc_type, 'description', $fdata[$tindex][$field->name]);
-
- // Override field parameters with Type specific Parameters
- if ( isset($tinfo[$type_id]['params'][$pn_prefix]) ) {
- foreach ($tinfo[$type_id]['params'][$pn_prefix] as $param_name => $param_value) {
- $fdata[$tindex][$field->name]->parameters->set( $param_name, $param_value) ;
- }
- }
-
- // SPECIAL CASE: check if it exists a FAKE (custom) field that customizes CORE field per Content Type
- $query = "SELECT attribs, published FROM #__flexicontent_fields WHERE name=".$db->Quote($field->name."_".$typealias);
- $db->setQuery($query); //echo $query;
- $data = $db->loadObject(); //print_r($data);
- if (@$data->published) JFactory::getApplication()->enqueueMessage(__FUNCTION__."(): Please unpublish plugin with name: ".$field->name."_".$typealias." it is used for customizing a core field",'error');
-
- // Finally merge custom field parameters with the type specific parameters ones
- if ($data) {
- $ts_params = FLEXI_J16GE ? new JRegistry($data->attribs) : new JParameter($data->attribs);
- $fdata[$tindex][$field->name]->parameters->merge($ts_params);
- }
- }
- }
-
- // Set custom label, description or maintain default
- $field->label = isset($fdata[$tindex][$field->name]->label) ? $fdata[$tindex][$field->name]->label : $field->label;
- $field->description = isset($fdata[$tindex][$field->name]->description) ? $fdata[$tindex][$field->name]->description : $field->description;
- $field->label = JText::_($field->label);
-
- // Finally set field's parameters, but to clone ... or not to clone, better clone to allow customizations for individual item fields ...
- $field->parameters = clone($fdata[$tindex][$field->name]->parameters);
-
- return $field;
- }
-
-
- // Method to override PARAMETER VALUES with their Type Specific values
- static function _getTypeToCoreFieldParams ($type_id, & $tinfo, & $tparams) {
-
- static $core_field_names = null;
- if ( $core_field_names == null ) {
- $query = "SELECT field_type FROM #__flexicontent_fields WHERE iscore=1";
- //echo $query;
- $db = JFactory::getDBO();
- $db->setQuery($query);
- $core_field_names = FLEXI_J16GE ? $db->loadColumn() : $db->loadResultArray();
-
- $core_field_names[] = 'maintext';
- $core_field_names = array_flip($core_field_names);
- unset($core_field_names['text']);
- }
-
- $query = 'SELECT t.attribs, t.name, t.alias FROM #__flexicontent_types AS t WHERE t.id = ' . $type_id;
- $db = JFactory::getDBO();
- $db->setQuery($query);
- $typedata = $db->loadObject();
- if ( $typedata ) {
- $tinfo['typename'] = $typedata->name;
- $tinfo['typealias'] = $typedata->alias;
- $tparams = FLEXI_J16GE ? new JRegistry($typedata->attribs) : new JParameter($typedata->attribs);
-
- $_tparams = $tparams->toArray();
- $tinfo['params'] = array();
-
- // Extra voting parameters of --voting-- field parameters are overriden contiditionally
- if ( $tparams->get('voting_override_extra_votes', 0) ) {
- $tinfo['params']['voting']['voting_extra_votes'] = $tparams->get('voting_extra_votes', '');
- $main_label = $tparams->get('voting_main_label', '') ? $tparams->get('voting_main_label', '') : JText::_('FLEXI_OVERALL'); // Set default label in case of empty
- $tinfo['params']['voting']['main_label'] = $main_label;
- }
-
- foreach ($_tparams as $param_name => $param_value) {
- $res = preg_split('/_/', $param_name, 2);
- if ( count($res) < 2 ) continue;
-
- $o_field_type = $res[0]; $o_param_name = $res[1];
- if ( !isset($core_field_names[$o_field_type]) ) continue;
-
- //echo "$o_field_type _ $o_param_name = $param_value <br>\n";
- $skipparam = false;
-
- if ( strlen($param_value) ) {
- if ($o_field_type=='voting') {
- $skipparam = in_array($o_param_name, array('override_extra_votes','voting_extra_votes','voting_main_label'));
- } else if ( in_array($o_param_name, array('label','desc','viewdesc')) ) {
- $skipparam = true;
- }
- if (!$skipparam) {
- $tinfo['params'][$o_field_type][$o_param_name] = $param_value;
- //echo "$o_field_type _ $o_param_name = $param_value <br>\n";
- }
- }
- }
- //echo "<pre>"; print_r($tinfo['params']); echo "</pre>";
- }
- }
-
-
- // Method get a language specific value from given Content Type (or other) Data
- static function _getLangSpecificValue ($type_id, $type_prop_value, $prop_name, & $fdata)
- {
- //--. Get a 2 character language tag
- static $lang = null;
- $cntLang = substr(JFactory::getLanguage()->getTag(), 0,2); // Current Content language (Can be natively switched in J2.5)
- $urlLang = JRequest::getWord('lang', '' ); // Language from URL (Can be switched via Joomfish in J1.5)
- $lang = (FLEXI_J16GE || empty($urlLang)) ? $cntLang : $urlLang;
-
- // --. SET a type specific label for the current field
- // a. Try field label to get for current language
- $result = preg_match("/(\[$lang\])=([^[]+)/i", $type_prop_value, $matches);
- if ($result) {
- $fdata->{$prop_name} = $matches[2];
- } else if ($type_prop_value) {
- // b. Try to get default for all languages
- $result = preg_match("/(\[default\])=([^[]+)/i", $type_prop_value, $matches);
- if ($result) {
- $fdata->{$prop_name} = $matches[2];
- } else {
- // c. Check that no languages specific string are defined
- $result = preg_match("/(\[??\])=([^[]+)/i", $type_prop_value, $matches);
- if (!$result) {
- $fdata->{$prop_name} = $type_prop_value;
- }
- }
- } else {
- // d. Maintain field 's default label
- }
- }
-
-
-
-
-
- // **************************************************************************************
- // Methods (a) for INDEXED FIELDs, and (b) for replacement field values / item properties
- // **************************************************************************************
-
- // Common method to get the allowed element values (field values with index,label,... properties) for fields that use indexed values
- static function indexedField_getElements(&$field, $item, $extra_props=array(), &$item_pros=true, $create_filter=false)
- {
- static $_elements_cache = null;
- if ( isset($_elements_cache[$field->id]) ) return $_elements_cache[$field->id];
- $canCache = true;
-
- $sql_mode = $field->parameters->get( 'sql_mode', 0 ) ; // For fields that use this parameter
- $field_elements = $field->parameters->get( 'field_elements', '' ) ;
-
- if ($create_filter) {
- $filter_customize_options = $field->parameters->get('filter_customize_options', 0);
- $filter_custom_options = $field->parameters->get('filter_custom_options', '');
- if ( $filter_customize_options && $filter_custom_options) {
- // Custom query for value retrieval
- $sql_mode = $filter_customize_options==1;
- $field_elements = $filter_custom_options;
- } else if ( !$field_elements ) {
- $field_elements = "SELECT value, value as text FROM #__flexicontent_fields_item_relations as fir WHERE field_id='{field_id}' AND value != '' GROUP BY value";
- }
- // Set parameters may be used later
- $field->parameters->set('sql_mode', $sql_mode);
- $field->parameters->set('field_elements', $field_elements);
- }
-
- // TODO: examine this in combination with canCache
- //$field_elements = FlexicontentFields::replaceFieldValue( $field, $item, $field_elements, 'field_elements' );
-
- if ($sql_mode) { // SQL mode, parameter field_elements contains an SQL query
-
- $db = JFactory::getDBO…
Large files files are truncated, but you can click here to view the full file