예제 #1
0
파일: article.php 프로젝트: hamby/SEBLOD
 public static function getRow($id, $content_type = '')
 {
     if (!$id) {
         return NULL;
     }
     $index = $id . '_' . $content_type;
     if (isset(self::$_items[$index])) {
         return self::$_items[$index];
     }
     $row = JTable::getInstance('content');
     $row->load($id);
     if (!$content_type) {
         $content_type = JCckDatabase::loadResult('SELECT cck FROM #__cck_core WHERE storage_location = "joomla_article" AND pk = ' . (int) $row->id);
     }
     if ($content_type) {
         $tables = JCckDatabaseCache::getTableList(true);
         $hasMore = isset($tables[JFactory::getConfig()->get('dbprefix') . 'cck_store_form_' . $content_type]);
         if ($hasMore) {
             $fields = JCckDatabase::loadObject('SELECT * FROM #__cck_store_form_' . $content_type . ' WHERE id = ' . (int) $row->id);
             if (count($fields)) {
                 foreach ($fields as $k => $v) {
                     $row->{$k} = $v;
                 }
             }
         }
     }
     self::$_items[$index] = $row;
     return $row;
 }
예제 #2
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;
     }
 }
예제 #3
0
파일: content.php 프로젝트: hamby/SEBLOD
 public function load($identifier, $data = true)
 {
     $this->_type = '';
     $this->_pk = '';
     $this->_id = '';
     if (is_array($identifier)) {
         $this->_object = $identifier[0];
         $this->_columns = $this->_getProperties();
         $this->_instance_base = JTable::getInstance($this->_columns['table_object'][0], $this->_columns['table_object'][1]);
         if (!isset($identifier[1])) {
             return;
         }
         $core = JCckDatabase::loadObject('SELECT id, cck, pk, storage_location FROM #__cck_core WHERE storage_location = "' . (string) $identifier[0] . '" AND pk = ' . (int) $identifier[1]);
     } else {
         $core = JCckDatabase::loadObject('SELECT id, cck, pk, storage_location FROM #__cck_core WHERE id = ' . (int) $identifier);
         $this->_object = $core->storage_location;
         $this->_columns = $this->_getProperties();
         $this->_instance_base = JTable::getInstance($this->_columns['table_object'][0], $this->_columns['table_object'][1]);
     }
     if (!(@$core->id && @$core->pk)) {
         return false;
     }
     $this->_type = $core->cck;
     $this->_pk = $core->pk;
     $this->_id = $core->id;
     $this->_instance_core->load($this->_id);
     $this->_instance_base->load($this->_pk);
     if (!$this->_columns['table']) {
         return;
     }
     $this->_table = $this->_columns['table'];
     $tables = JCckDatabaseCache::getTableList(true);
     $hasMore = isset($tables[JFactory::getConfig()->get('dbprefix') . 'cck_store_form_' . $this->_type]);
     if ($hasMore) {
         $this->_instance_more = JCckTable::getInstance('#__cck_store_form_' . $this->_type);
         $this->_instance_more->load($this->_pk);
     }
     if ($data === true) {
         if ($hasMore) {
             $this->_properties = JCckDatabase::loadObject('SELECT a.*, b.* FROM ' . $this->_table . ' AS a' . ' LEFT JOIN #__cck_store_form_' . $this->_type . ' AS b ON b.id = a.' . $this->_columns['key'] . ' WHERE a.' . $this->_columns['key'] . ' = ' . (int) $this->_pk);
         } else {
             $this->_properties = JCckDatabase::loadObject('SELECT a.* FROM ' . $this->_table . ' AS a' . ' WHERE a.' . $this->_columns['key'] . ' = ' . (int) $this->_pk);
         }
     } elseif (is_array($data)) {
         if (isset($data[$this->_table])) {
             $select = implode(',', $data[$this->_table]);
             unset($data[$this->_table]);
         } else {
             $select = '*';
         }
         $b = 'a';
         $i = 98;
         foreach ($data as $k => $v) {
             $a = chr($i);
             $select .= ', ' . $a . '.' . implode(', ' . $a . '.', $v);
             $join .= ' LEFT JOIN ' . $k . ' AS ' . $a . ' ON ' . $a . '.id = ' . $b . '.' . $this->_columns['key'];
             $b = $a;
             $i++;
         }
         $query = 'SELECT a.' . $select . ' FROM ' . $this->_table . ' AS a' . $join . ' WHERE a.' . $this->_columns['key'] . ' = ' . (int) $this->_pk;
         $this->_properties = JCckDatabase::loadObject($query);
     }
 }