Exemplo n.º 1
0
 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;
 }