/** * Method to render a field * * @access public * @return object * @since 1.5 */ static function renderField(&$_item, &$_field, &$values, $method = 'display', $view = FLEXI_ITEMVIEW) { static $_trigger_plgs_ft = array(); static $_created = array(); $flexiview = JRequest::getVar('view'); static $cparams = null; if ($cparams === null) { $cparams = JComponentHelper::getParams('com_flexicontent'); } static $aid; if ($aid === null) { $user = JFactory::getUser(); $aid = FLEXI_J16GE ? JAccess::getAuthorisedViewLevels($user->id) : (int) $user->get('aid'); } if (is_array($_item) && is_string($_field)) { } else { if (is_object($_item) && is_object($_field)) { } else { echo "renderField() must be called with: renderField(array of items, 'field_name',...) or renderField(item object, field object,...)<br/>"; exit; } } // If $method (e.g. display method) is already created, // then return the field object without recreating the method if (is_object($_field) && isset($_field->{$method})) { return $_field; } // Handle multi-item call if (!is_array($_item)) { $all_items = array(&$_item); $field_name = $_field->name; $first_item_field =& $_field; } else { $all_items =& $_item; $field_name = $_field; $item = reset($_item); $first_item_field =& $item->fields[$field_name]; } // Skip items that have already created the given 'method' for this 'field' and for the given view // we also use VIEW so that we can reder different displays of the field e.g. item VIEW and module view $items = array(); foreach ($all_items as $_item_) { // Commented out, TODO: examine if we can return cached value here !! //if (isset($_created[$view][$method][$field_name][$_item_->id])) continue; // Skip this item $items[] = $_item_; $_created[$view][$method][$field_name][$_item_->id] = 1; } // Check if item array is empty (all items already rendered) if (empty($items)) { return !is_object($_field) ? null : $_field; } // *********************************************************************************************************** // Create field parameters (and values) in an optimized way, and also apply Type Customization for CORE fields // *********************************************************************************************************** foreach ($items as $item) { $field = is_object($_field) ? $_field : $item->fields[$field_name]; // only rendering 1 item the field object was given $field->item_id = (int) $item->id; // CHECK IF only rendering single field object for a single item --> thus we need to use custom values if these were given ! // NOTE: values are overwritten by onDisplayCoreFieldValue() of CORE fields, and only used by onDisplayFieldValue() of CUSTOM fields if (is_object($_field) && $values !== null) { // CUSTOM VALUEs give for single field rendering, TODO (maybe): in future we may make values an array indexed by item ID $field->value = $values; } else { // CUSTOM VALUEs not given or rendering multiple items $field->value = isset($item->fieldvalues[$field->id]) ? $item->fieldvalues[$field->id] : array(); } FlexicontentFields::loadFieldConfig($field, $item); } // ********************************************** // Return no access message if user has no ACCESS // ********************************************** // Calculate has_access flag if it is missing ... FLEXI_ACCESS ... no longer supported here ... if (!isset($first_item_field->has_access)) { $first_item_field->has_access = FLEXI_J16GE ? in_array($first_item_field->access, $aid) : $first_item_field->access <= $aid; } if (!$first_item_field->has_access) { // Get configuration out of the field of the first item, any CONFIGURATION that is different // per content TYPE, must not use this, instead it must be retrieved inside the item loops $show_acc_msg = $first_item_field->parameters->get('show_acc_msg', 0); $no_acc_msg = $first_item_field->parameters->get('no_acc_msg'); $no_acc_msg = JText::_($no_acc_msg ? $no_acc_msg : 'FLEXI_FIELD_NO_ACCESS'); foreach ($items as $item) { $field = is_object($_field) ? $_field : $item->fields[$field_name]; // only rendering 1 item the field object was given $field->{$method} = $show_acc_msg ? '<span class="fc-noauth fcfield_inaccessible_' . $field->id . '">' . $no_acc_msg . '</span>' : ''; } // Return field only if single item was given (with a field object) return !is_object($_field) ? null : $_field; } // *************************************************************************************************** // 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 $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 ($first_item_field->iscore == 1) { //$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, & $_item, &$_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 { // DOES NOT support multiple items YET, do it 1 at a time foreach ($items as $item) { $field = is_object($_field) ? $_field : $item->fields[$field_name]; // only rendering 1 item the field object was given //$results = $dispatcher->trigger('onDisplayFieldValue', array( &$field, $item )); FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayFieldValue', array(&$field, $item, 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 // ***************************************** // Get configuration out of the field of the first item, if this CONFIGURATION was // different per content TYPE, then we should move this inside the item loop (below) if (!is_array($_item)) { $field = $_field; } else { $item = reset($items); $field = $item->fields[$field_name]; } 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; } // DOES NOT support multiple items, do it 1 at a time if ($_trigger_plgs_ft[$field_name]) { //echo "RENDER: ".$field_name."<br/>"; foreach ($items as $item) { $field = is_object($_field) ? $_field : $item->fields[$field_name]; // only rendering 1 item the field object was given 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 only if single item was given (with a field object) return !is_object($_field) ? null : $_field; }