Example #1
0
 public function onCCK_FieldPrepareForm(&$field, $value = '', &$config = array(), $inherit = array(), $return = false)
 {
     if (self::$type != $field->type) {
         return;
     }
     self::$path = parent::g_getPath(self::$type . '/');
     parent::g_onCCK_FieldPrepareForm($field, $config);
     // Init
     if (count($inherit)) {
         $id = isset($inherit['id']) && $inherit['id'] != '' ? $inherit['id'] : $field->name;
         $name = isset($inherit['name']) && $inherit['name'] != '' ? $inherit['name'] : $field->name;
     } else {
         $id = $field->name;
         $name = $field->name;
     }
     $value = $value != '' ? $value : $field->defaultvalue;
     $name = @$field->bool3 ? $name . '[]' : $name;
     $divider = '';
     if ($field->bool3) {
         $divider = $field->divider != '' ? $field->divider : ',';
         if (!is_array($value)) {
             $value = explode($divider, $value);
         }
     } else {
         $field->divider = '';
     }
     // Validate
     $validate = '';
     if ($config['doValidation'] > 1) {
         plgCCK_Field_ValidationRequired::onCCK_Field_ValidationPrepareForm($field, $id, $config);
         $validate = count($field->validate) ? ' validate[' . implode(',', $field->validate) . ']' : '';
     }
     // Prepare
     if (parent::g_isStaticVariation($field, $field->variation, true)) {
         $form = '';
         $field->text = '';
         parent::g_getDisplayVariation($field, $field->variation, $value, $field->text, $form, $id, $name, '<select', '', '', $config);
     } else {
         $attr = array('option.attr' => 'data-cck');
         $auto = 1;
         $items = array();
         $opts = array();
         if ($field->location) {
             $attribs = explode('||', $field->location);
             $attrib = count($attribs);
         } else {
             $attribs = array();
             $attrib = 0;
         }
         if (trim($field->selectlabel)) {
             if ($config['doTranslation']) {
                 $field->selectlabel = JText::_('COM_CCK_' . str_replace(' ', '_', trim($field->selectlabel)));
             }
             if ($attrib) {
                 $attr['attr'] = '';
                 foreach ($attribs as $k => $a) {
                     $attr['attr'] .= ' ' . $a . '=""';
                 }
                 $opts[] = JHtml::_('select.option', '', '- ' . $field->selectlabel . ' -', $attr);
             } else {
                 $opts[] = JHtml::_('select.option', '', '- ' . $field->selectlabel . ' -', 'value', 'text');
             }
             if ($field->required) {
                 $auto++;
             }
         }
         $count2 = JCck::getConfig_Param('development_attr', 6);
         $opt_attr = '';
         $opt_attrs = array();
         $options2 = JCckDev::fromJSON($field->options2);
         $optgroups = false;
         if ($field->bool4 == 1 || $field->bool4 == 3) {
             $results = self::_getStaticOption($field, $field->options, $config, $optgroups);
             $static = count($results);
             if ($field->bool4 == 3) {
                 if ($static > 0) {
                     $current = 0;
                     $half = (int) ($static / 2);
                     $half = $static % 2 ? $half + 1 : $half;
                     for ($current = 0; $current < $half; $current++) {
                         $opts[] = $results[$current];
                     }
                 }
             } else {
                 foreach ($results as $result) {
                     $opts[] = $result;
                 }
             }
         }
         if ($field->bool2 == 0) {
             $opt_table = isset($options2['table']) ? ' FROM ' . $options2['table'] : '';
             $opt_name = isset($options2['name']) ? $options2['name'] : '';
             $opt_value = isset($options2['value']) ? $options2['value'] : '';
             if ($count2) {
                 for ($i = 1; $i <= $count2; $i++) {
                     $opt_attrs[] = isset($options2['attr' . $i]) && $options2['attr' . $i] != '' ? $options2['attr' . $i] : '';
                 }
             }
             $opt_where = @$options2['where'] != '' ? ' WHERE ' . $options2['where'] : '';
             $opt_orderby = @$options2['orderby'] != '' ? ' ORDER BY ' . $options2['orderby'] . ' ' . (@$options2['orderby_direction'] != '' ? $options2['orderby_direction'] : 'ASC') : '';
             $opt_limit = @$options2['limit'] > 0 ? ' LIMIT ' . $options2['limit'] : '';
             // Language Detection
             $count2 = count($opt_attrs);
             $lang_code = '';
             self::_languageDetection($lang_code, $value, $options2);
             $opt_value = str_replace('[lang]', $lang_code, $opt_value);
             $opt_name = str_replace('[lang]', $lang_code, $opt_name);
             $opt_where = str_replace('[lang]', $lang_code, $opt_where);
             $opt_orderby = str_replace('[lang]', $lang_code, $opt_orderby);
             $opt_group = '';
             if ($count2) {
                 foreach ($opt_attrs as $k => $v) {
                     if ($v != '') {
                         $v = str_replace('[lang]', $lang_code, $v) . ' AS attr' . ($k + 1);
                         $opt_attr .= ',' . $v;
                     }
                 }
                 if ($opt_attr == ',') {
                     $opt_attr = '';
                 }
             }
             if ($opt_name && $opt_value && $opt_table) {
                 $query = 'SELECT ' . $opt_name . ',' . $opt_value . $opt_attr . $opt_table . $opt_where . $opt_orderby . $opt_limit;
                 $query = JCckDevHelper::replaceLive($query);
                 if ($config['client'] == '' || $config['client'] == 'dev') {
                     $tables = JCckDatabaseCache::getTableList();
                     $prefix = JFactory::getDbo()->getPrefix();
                     $items = in_array(str_replace('#__', $prefix, $options2['table']), $tables) ? JCckDatabase::loadObjectList($query) : array();
                 } else {
                     $items = JCckDatabase::loadObjectList($query);
                 }
             }
         } else {
             if (@$options2['query'] != '') {
                 // Language Detection
                 $lang_code = '';
                 self::_languageDetection($lang_code, $value, $options2);
                 $query = str_replace('[lang]', $lang_code, $options2['query']);
                 $query = JCckDevHelper::replaceLive($query);
                 if (strpos($query, ' value ') !== false || strpos($query, 'AS value') !== false || strpos($query, ' value,') !== false) {
                     $items = JCckDatabase::loadObjectList($query);
                 } else {
                     $opts2 = JCckDatabase::loadColumn($query);
                     if (count($opts2)) {
                         $opts2 = array_combine(array_values($opts2), $opts2);
                     }
                     $opts = array_merge($opts, $opts2);
                 }
             }
             $opt_name = 'text';
             $opt_value = 'value';
             $opt_group = 'optgroup';
         }
         if (count($items)) {
             if ($opt_group) {
                 $group = '';
                 foreach ($items as $o) {
                     if (isset($o->optgroup) && $o->optgroup != $group) {
                         if ($group) {
                             $opts[] = JHtml::_('select.option', '</OPTGROUP>');
                         }
                         $opts[] = JHtml::_('select.option', '<OPTGROUP>', $o->optgroup);
                         $group = $o->optgroup;
                     }
                     if ($attrib) {
                         $attr['attr'] = '';
                         foreach ($attribs as $k => $a) {
                             $ka = 'attr' . ($k + 1);
                             if (isset($o->{$ka})) {
                                 $va = $o->{$ka};
                             } else {
                                 $ka = isset($options2['attr' . ($k + 1)]) ? $options2['attr' . ($k + 1)] : '';
                                 $va = $ka != '' && isset($o->{$ka}) ? $o->{$ka} : '';
                             }
                             $attr['attr'] .= ' ' . $a . '="' . $va . '"';
                         }
                         $opts[] = JHtml::_('select.option', $o->value, $o->text, $attr);
                     } else {
                         $opts[] = JHtml::_('select.option', $o->value, $o->text, 'value', 'text');
                     }
                 }
                 if ($group) {
                     $opts[] = JHtml::_('select.option', '</OPTGROUP>');
                 }
             } else {
                 if ($attrib) {
                     foreach ($items as $o) {
                         $attr['attr'] = '';
                         foreach ($attribs as $k => $a) {
                             $ka = 'attr' . ($k + 1);
                             if (isset($o->{$ka})) {
                                 $va = $o->{$ka};
                             } else {
                                 $ka = isset($options2['attr' . ($k + 1)]) ? $options2['attr' . ($k + 1)] : '';
                                 $va = $ka != '' && isset($o->{$ka}) ? $o->{$ka} : '';
                             }
                             $attr['attr'] .= ' ' . $a . '="' . $va . '"';
                         }
                         $opts[] = JHtml::_('select.option', $o->{$opt_value}, $o->{$opt_name}, $attr);
                     }
                 } else {
                     foreach ($items as $o) {
                         $opts[] = JHtml::_('select.option', $o->{$opt_value}, $o->{$opt_name}, 'value', 'text');
                     }
                 }
             }
         }
         if ($optgroups !== false) {
             $opts[] = JHtml::_('select.option', '</OPTGROUP>');
         }
         if ($field->bool4 == 2 || $field->bool4 == 3) {
             if ($field->bool4 == 3) {
                 if ($static > 1 && isset($current) && isset($half) && isset($static) && isset($results)) {
                     for (; $current < $static; $current++) {
                         $opts[] = $results[$current];
                     }
                 }
             } else {
                 $results = self::_getStaticOption($field, $field->options, $config);
                 foreach ($results as $result) {
                     $opts[] = $result;
                 }
             }
         }
         $class = 'inputbox select' . $validate . ($field->css ? ' ' . $field->css : '');
         if ($value != '') {
             $class .= ' has-value';
         }
         $multi = @$field->bool3 ? ' multiple="multiple"' : '';
         $size = !@$field->bool3 ? '1' : (@$field->rows ? $field->rows : count($opts));
         $size = (int) $size > 1 ? ' size="' . $size . '"' : '';
         $attr = 'class="' . $class . '"' . $size . $multi . ($field->attributes ? ' ' . $field->attributes : '');
         $count = count($opts);
         $form = '';
         if ($field->variation == 'hidden_auto') {
             if ($auto == $count && is_object($opts[$auto - 1])) {
                 $count = 0;
                 $field->variation = 'hidden';
                 $value = $opts[$auto - 1]->value;
                 if (!$field->live) {
                     JCckDevHelper::secureField($field, $value);
                 }
             } else {
                 $field->variation = '';
             }
         }
         if ($count) {
             if ($attrib) {
                 $attr = array('id' => $id, 'list.attr' => $attr, 'list.select' => $value, 'list.translate' => false, 'option.attr' => 'data-cck', 'option.key' => 'value', 'option.text' => 'text');
                 $form = JHtml::_('select.genericlist', $opts, $name, $attr);
             } else {
                 $form = JHtml::_('select.genericlist', $opts, $name, $attr, 'value', 'text', $value, $id);
             }
         }
         /* tmp */
         $jtext = $config['doTranslation'];
         $config['doTranslation'] = 0;
         /* tmp */
         // Set
         if (!$field->variation) {
             $field->form = $form;
             if ($field->script) {
                 parent::g_addScriptDeclaration($field->script);
             }
         } else {
             $options_2 = self::_getOptionsList($options2, $field->bool2, $lang_code);
             if ($field->options) {
                 if ($field->bool4 == 3) {
                     $current = 0;
                     $static_opts = explode('||', $field->options);
                     $static_opts1 = array();
                     $static_opts2 = array();
                     foreach ($static_opts as $static_opt) {
                         if ($current < $half) {
                             $static_opts1[] = $static_opt;
                         } else {
                             $static_opts2[] = $static_opt;
                         }
                         $current++;
                     }
                     $field->optionsList = implode('||', $static_opts1) . '||' . $options_2 . '||' . implode('||', $static_opts2);
                 } elseif ($field->bool4 == 2) {
                     $field->optionsList = $options_2 . '||' . $field->options;
                 } else {
                     $field->optionsList = $field->options . '||' . $options_2;
                 }
             } else {
                 $field->optionsList = $options_2;
             }
             if ($field->bool4) {
                 $field->text = parent::g_getOptionText($value, $field->optionsList, $divider, $config);
             } else {
                 $field->text = parent::g_getOptionText($value, $options_2, $divider, $config);
             }
             parent::g_getDisplayVariation($field, $field->variation, $value, $field->text, $form, $id, $name, '<select', '', '', $config);
         }
         /* tmp */
         $config['doTranslation'] = $jtext;
         /* tmp */
     }
     $field->value = $value;
     // Return
     if ($return === true) {
         return $field;
     }
 }
Example #2
0
        } else {
            if ($field->live) {
                $dispatcher->trigger('onCCK_Field_LivePrepareForm', array(&$field, &$value, &$config));
                if (!($field->variation == 'hidden_auto' || $field->variation == 'hidden_isfilled')) {
                    JCckDevHelper::secureField($field, $value);
                }
            } else {
                $value = isset($lives[$name]) ? $lives[$name] : $field->live_value;
            }
        }
    }
    $field->value = $value;
    if ($field->variation == 'hidden_isfilled') {
        if ($value != '') {
            $field->variation = 'hidden';
            JCckDevHelper::secureField($field, $value);
        } else {
            $field->variation = '';
        }
    }
    $dispatcher->trigger('onCCK_FieldPrepareForm', array(&$field, $value, &$config, array()));
    $position = $field->position;
    $positions[$position][] = $field->name;
    // Was it the last one?
    if ($config['error']) {
        break;
    }
}
// Merge
if (count($config['fields'])) {
    $fields = array_merge($fields, $config['fields']);