public static function getConfig() { if (!self::$_config) { if (JCckDatabaseCache::loadResult('SELECT extension_id FROM #__extensions WHERE type = "component" AND element = "' . 'com_' . self::$_me . '"') > 0) { self::$_config = JComponentHelper::getParams('com_' . self::$_me); } else { self::$_config = new JRegistry(); } } return self::$_config; }
public function create($cck, $data_content, $data_more = null) { if ($this->_id) { return; } $this->_type = $cck; if (empty($this->_object)) { $this->_object = JCckDatabaseCache::loadResult('SELECT storage_location FROM #__cck_core_types WHERE name = "' . $this->_type . '"'); $this->_columns = $this->_getProperties(); } $this->_instance_core = JTable::getInstance($this->_columns['table_object'][0], $this->_columns['table_object'][1]); $author_id = 0; // TODO: Get default author id $parent_id = 0; // TODO: Get default parent_id // Set the author_id if (isset($this->_columns['author']) && $this->_columns['author'] && isset($data_content[$this->_columns['author']])) { $author_id = $data_content[$this->_columns['author']]; } else { $user_id = JFactory::getUser()->get('id'); if ($user_id) { $author_id = $user_id; } } // Set the parent_id if (isset($this->_columns['parent']) && $this->_columns['parent'] && isset($data_content[$this->_columns['parent']])) { $parent_id = $data_content[$this->_columns['parent']]; } // -------- -------- -------- if (!$this->save('core', $data_content)) { return false; } if (!$this->save('base', array('cck' => $this->_type, 'pk' => $this->_pk, 'storage_location' => $this->_object, 'author_id' => $author_id, 'parent_id' => $parent_id, 'date_time' => JFactory::getDate()->toSql()))) { return false; } if (is_array($data_more) && count($data_more)) { $this->_instance_more = JCckTable::getInstance('#__cck_store_form_' . $this->_type); $this->_instance_more->load($this->_pk, true); if (!$this->save('more', $data_more)) { return false; } } //TODO : Load instance info return $this->_pk; }
public static function parseRoute(&$vars, $segments, $n, $config) { $join = ''; $where = ''; $vars['option'] = 'com_content'; $vars['view'] = 'categories'; if ($n == 2) { if ($config['doSEF'][0] == '3') { $join = ' LEFT JOIN #__cck_core AS b on b.' . $config['join_key'] . ' = a.id'; $where = ' AND b.cck = "' . (string) $segments[0] . '"'; } else { $join = ' LEFT JOIN #__categories AS b on b.id = a.parent_id'; if ($config['doSEF'] == '1') { $where = ' AND b.id = ' . (int) $segments[0]; $vars['catid'] = $segments[0]; } else { $segments[0] = str_replace(':', '-', $segments[0]); $where = ' AND b.alias = "' . $segments[0] . '"'; } } } else { if ($config['doSEF'][0] == '2' && isset($config['doSEF'][1]) && $config['doSEF'][1] == '4') { $active = JFactory::getApplication()->getMenu()->getActive(); if (isset($active->query['search']) && $active->query['search']) { $cck = JCckDatabaseCache::loadResult('SELECT sef_route FROM #__cck_core_searchs WHERE name = "' . $active->query['search'] . '"'); if ($cck) { $join = ' LEFT JOIN #__cck_core AS b on b.' . $config['join_key'] . ' = a.id'; $where = strpos($cck, ',') !== false ? ' AND b.cck IN ("' . str_replace(',', '","', $cck) . '")' : ' AND b.cck = "' . $cck . '"'; } } } } if (self::$sef[$config['doSEF']] == 'full') { list($id, $alias) = explode(':', $segments[$n - 1], 2); $vars['id'] = $id; } else { if (is_numeric($segments[$n - 1])) { $vars['id'] = $segments[$n - 1]; } else { $segments[$n - 1] = str_replace(':', '-', $segments[$n - 1]); $query = 'SELECT a.id FROM ' . self::$table . ' AS a' . $join . ' WHERE a.alias = "' . $segments[$n - 1] . '"' . $where; $vars['id'] = JCckDatabaseCache::loadResult($query); } } }
public function create($cck, $data_content, $data_more = null) { $db = JFactory::getDbo(); if ($this->_id) { return; } //if object is joomla_user do validate first //login and email must be unique if ($this->_object == "joomla_user") { $username = $data_content['username']; $email = $data_content['email']; $query = $db->getQuery(true); $field = array('id'); $table = '#__users'; $query->select($db->quoteName($field)); $query->from($db->quoteName($table)); $query->where($db->quoteName('username') . '= ' . $db->quote($username), 'OR'); $query->where($db->quoteName('email') . '= ' . $db->quote($email)); $db->setQuery($query); $result = $db->loadObject(); if ($result) { return false; } } $this->_type = $cck; if (empty($this->_object)) { $this->_object = JCckDatabaseCache::loadResult('SELECT storage_location FROM #__cck_core_types WHERE name = "' . $this->_type . '"'); $this->_columns = $this->_getProperties(); } $this->_instance_core = JTable::getInstance($this->_columns['table_object'][0], $this->_columns['table_object'][1]); $author_id = 0; // TODO: Get default author id $parent_id = 0; // TODO: Get default parent_id // Set the author_id if (isset($this->_columns['author']) && $this->_columns['author'] && isset($data_content[$this->_columns['author']])) { $author_id = $data_content[$this->_columns['author']]; } else { $user_id = JFactory::getUser()->get('id'); if ($user_id) { $author_id = $user_id; } } // Set the parent_id if (isset($this->_columns['parent']) && $this->_columns['parent'] && isset($data_content[$this->_columns['parent']])) { $parent_id = $data_content[$this->_columns['parent']]; } // -------- -------- -------- if (!$this->save('core', $data_content)) { return false; } if (!$this->save('base', array('cck' => $this->_type, 'pk' => $this->_pk, 'storage_location' => $this->_object, 'author_id' => $author_id, 'parent_id' => $parent_id, 'date_time' => JFactory::getDate()->toSql()))) { return false; } if (is_array($data_more) && count($data_more)) { $this->_instance_more = JCckTable::getInstance('#__cck_store_form_' . $this->_type); $this->_instance_more->load($this->_pk, true); if (!$this->save('more', $data_more)) { return false; } } return $this->_pk; }
public static function access($pk) { return JCckDatabaseCache::loadResult('SELECT ' . self::$key . ' FROM ' . self::$table . ' WHERE ' . self::$key . ' = ' . $pk . ' AND ' . self::$access . ' IN (' . implode(',', JFactory::getUser()->getAuthorisedViewLevels()) . ') AND ' . self::$status . ' = 1'); }
public static function getDefaultTemplate() { $name = JCckDatabaseCache::loadResult('SELECT name FROM #__cck_core_templates WHERE featured = 1 ORDER BY id'); if (!$name) { $name = 'seb_one'; } return $name; }
public function onContentSearch($text = '', $phrase = '', $ordering = '', $areas = NULL, $fields = array(), $fields_order = array(), &$config = array(), $current = array(), $options = NULL, $user = NULL) { if (is_array($areas)) { if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) { return array(); } } else { return array(); } if (!count($fields)) { return array(); } if (!$user) { $user = JCck::getUser(); } if (!is_object($options)) { $options = new JRegistry(); } $app = JFactory::getApplication(); $db = JFactory::getDbo(); $dispatcher = JDispatcher::getInstance(); $doClean = false; $doCount = (int) $options->get('count'); $doLimit = false; $limit = (int) $options->get('limit'); $doLimit = $limit > 0 ? false : true; $isLoadingMore = $app->input->get('format') == 'raw' && $app->input->get('infinite') > 0 ? 1 : 0; $glues = 1; $order = ''; $order_string = ''; $where = ''; $w = -1; $where2 = array(); $t = 1; $t2 = 1; $tables = array('#__cck_core' => array('_' => 't0', 'fields' => array(), 'join' => 1)); $colums = array(); if (isset($config['joins'][$current['stage']]) && is_array($config['joins'][$current['stage']])) { foreach ($config['joins'][$current['stage']] as $j) { if ($j->table) { if (!isset($tables[$j->table])) { $tables[$j->table] = array('_' => 't' . $t++, 'fields' => array(), 'key' => $j->column, 'join' => 2, 'join_key' => $j->column2, 'join_table' => $j->table2, 'join_and' => @$j->and, 'join_type' => @$j->type, 'join_mode' => @$j->mode, 'join_query' => @$j->query); } elseif (@$j->and != '') { $tables[$j->table . '@' . md5($j->and)] = array('_' => 't' . $t++, 'fields' => array(), 'key' => $j->column, 'join' => 2, 'join_key' => $j->column2, 'join_table' => $j->table2, 'join_and' => $j->and, 'join_type' => @$j->type, 'join_mode' => @$j->mode, 'join_query' => @$j->query); } } } $t2 = count($tables); } foreach ($fields as $field) { if (!$field->state) { continue; } if ($current['stage'] != (int) $field->stage) { continue; } $hasSQL = true; $name2 = $field->match_collection != '' ? '\\\\|[0-9]+\\\\|' . $field->match_collection : ''; // - if ($field->live == 'stage') { $live_options = new JRegistry(); $live_options->loadString($field->live_options); $live_value = $live_options->get('value', $field->live_value); $live_value = $live_value ? $live_value : 1; $value = $current['stages'][$live_value]; if ($value == '' && $live_options->get('default_value') != '') { $value = (string) $live_options->get('default_value'); } } else { $value = $field->value; } // - $Pf = $field->storage_field; $Pt = $field->storage_table; if (($value !== '' && $field->match_mode != 'none' || ($field->match_mode == 'empty' || $field->match_mode == 'not_empty' || $field->match_mode == 'not_null')) && $field->storage != 'none' || $field->type == 'search_operator' && $field->match_mode != 'none') { $glue = ''; $sql = ''; if ($field->match_options != '') { $field->match_options = new JRegistry($field->match_options); } // Glue if ($glues == 1) { $glue = $where != '' ? 'AND' : ''; $where .= $glue; if ($glue != '') { $where2[++$w] = $glue; } $glue = ''; } // Sql if ($field->type == 'search_generic') { if (count($field->children)) { $sql = '('; $k = 0; foreach ($field->children as $child) { if ($k > 0) { $sql .= ' OR '; } $child->match_mode = $field->match_mode; $child->match_options = $field->match_options; $child->match_value = $field->match_value; if ($child->storage && $child->storage != 'none') { $Pf = $child->storage_field; $Pt = $child->storage_table; // - if ($Pt && !isset($tables[$Pt])) { $tables[$Pt] = array('_' => 't' . $t, 'fields' => array(), 'join' => 1); $t++; } $tables[$Pt]['location'] = $child->storage_location; // - $name = $child->storage_field2 ? $child->storage_field2 : $child->name; if ($Pt != '') { $target = $tables[$Pt]['_'] . '.' . $Pf; $tables[$Pt]['fields'][$Pf] = $Pt == '#__cck_core' ? $value : $name; } if (JCck::callFunc('plgCCK_Field' . $child->type, 'isFriendly')) { if (isset($fields[$child->name])) { $value2 = JCck::callFunc_Array('plgCCK_Field' . $child->type, 'getValueFromOptions', array($fields[$child->name], $value, $config)); } else { $value2 = JCck::callFunc_Array('plgCCK_Field' . $child->type, 'getValueFromOptions', array($child, $value, $config)); } } else { $value2 = $value; } require_once JPATH_PLUGINS . '/cck_storage/' . $child->storage . '/' . $child->storage . '.php'; $sql .= JCck::callFunc_Array('plgCCK_Storage' . $child->storage, 'onCCK_StoragePrepareSearch', array(&$child, $child->match_mode, $value2, $name, $name2, $target, $fields, &$config)); } $k++; } $sql .= ')'; } } elseif ($field->type == 'search_ordering') { $sql = ''; array_pop($where2); if (isset($field->children[$value])) { if (!isset($fields_order[$field->children[$value]->name])) { $fields_order[$field->children[$value]->name] = $field->children[$value]; } } } elseif ($field->type == 'search_operator') { // Glue if ($field->value == '((') { $glues = 0; $sql = '('; } elseif ($field->value == '))') { $glues = 1; $sql = ')'; } else { if ($where2[$w] != '(') { $glue = $field->value; $sql = $glue; } } $doClean = true; } else { // - if ($Pt && !isset($tables[$Pt])) { $tables[$Pt] = array('_' => 't' . $t, 'fields' => array(), 'join' => 1); $t++; } $tables[$Pt]['location'] = $field->storage_location; // - $name = $field->storage_field2 ? $field->storage_field2 : $field->name; if ($Pt != '') { $target = $tables[$Pt]['_'] . '.' . $Pf; $tables[$Pt]['fields'][$Pf] = $Pt == '#__cck_core' ? $value : $name; } else { $target = $Pf; $hasSQL = false; } require_once JPATH_PLUGINS . '/cck_storage/' . $field->storage . '/' . $field->storage . '.php'; $sql = JCck::callFunc_Array('plgCCK_Storage' . $field->storage, 'onCCK_StoragePrepareSearch', array(&$field, $field->match_mode, $value, $name, $name2, $target, $fields, &$config)); } if ($hasSQL === false) { if ($glues == 1) { if ($where != '') { $where = substr($where, 0, -3); $where2[$w] = ''; } } $config['query_parts']['having'][] = $sql; $sql = ''; } else { $where .= $sql; $where2[++$w] = $sql; } } else { if (@$glue) { $where2[$w] = ''; } // unset( $fields[$field->name] ); } } // Finalize $where = implode(' ', $where2); if ($doClean !== false) { $where = preg_replace('/\\s+/', ' ', $where); $where = str_replace('AND ( )', '', $where); $where = str_replace('AND ( )', '', $where); $where = str_replace('OR OR', 'OR', $where); $where = str_replace('( OR', '(', $where); $where = str_replace('OR ) )', ')', $where); $where = str_replace('OR )', ')', $where); } $where = str_replace('AND ()', '', $where); // -------- -------- Order if (!$order) { $order = ' t1.title ASC'; } $inherit = array('bridge' => '', 'query' => ''); $query = NULL; $query2 = ''; $results = array(); self::_setStorage($tables, $config, $inherit); JPluginHelper::importPlugin('cck_storage_location'); if (isset($config['location']) && $config['location']) { $dispatcher->trigger('onCCK_Storage_LocationSearch', array($config['location'], $tables, $fields, $fields_order, &$config, &$inherit, &$results)); $query = $inherit['query']; } if ($config['doQuery'] !== false) { if ($current['stage'] == 0) { if (isset($config['query_variables']) && count($config['query_variables'])) { foreach ($config['query_variables'] as $var) { if ($var != '') { $db->setQuery($var); $db->execute(); } } } $query = $db->getQuery(true); $query->select('t0.id AS pid,t0.pk AS pk,t0.pkb AS pkb,t0.parent_id AS parent,t0.author_id AS author'); $query->from('`#__cck_core` AS t0'); self::_buildQuery($dispatcher, $query, $tables, $t, $config, $inherit, $user, $config['doSelect']); $query->select('t0.cck AS cck,t0.storage_location AS loc'); if ($config['location'] == 'cck_type') { $query->select($tables['#__cck_core_types']['_'] . '.id AS type_id,' . $tables['#__cck_core_types']['_'] . '.alias AS type_alias'); } else { $query->select('tt.id AS type_id,tt.alias AS type_alias'); $query->join('LEFT', '`#__cck_core_types` AS tt ON tt.name = t0.cck'); } if (isset($config['query_parts']['select'])) { if (is_string($config['query_parts']['select']) && $config['query_parts']['select'] != '' || count($config['query_parts']['select'])) { $query->select($config['query_parts']['select']); } } if ($where != '') { $query->where($where); } if (isset($config['query_parts']['having'])) { if (is_string($config['query_parts']['having']) && $config['query_parts']['having'] != '' || count($config['query_parts']['having'])) { $query->having($config['query_parts']['having']); } } if (isset($config['query_parts']['group']) && count($config['query_parts']['group'])) { $query->group($config['query_parts']['group']); } self::_buildQueryOrdering($order, $ordering, $fields_order, $dispatcher, $query, $tables, $t, $config, $current, $inherit, $user); if ($doLimit && $config['limitstart'] >= 0) { $db->setQuery($query, $config['limitstart'], $config['limitend']); } else { $db->setQuery($query, 0, $limit); } $results = $db->loadObjectList(); if ($doLimit) { $count = count($results); if ($count < $config['limitend'] && !$config['limitstart'] || $isLoadingMore) { $config['total'] = $count; } else { if ($doCount == 1 && strpos(JUri::getInstance()->toString(), 'task=') === false) { $query2 = 'SELECT COUNT(id) FROM #__cck_core WHERE cck = "' . $tables['#__cck_core']['fields']['cck'] . '"'; $config['total'] = JCckDatabaseCache::loadResult($query2); } else { if (JCck::on()) { $query1 = (string) $query; if (strpos($query1, 'HAVING') !== false) { $query->clear('order')->clear('limit'); $query2 = $db->getQuery(true); $query2->select('COUNT(*)'); $query2->from('(' . (string) $query . ') AS Count'); $db->setQuery($query2); $config['total'] = $db->loadResult(); $query2 = (string) $query2; } else { $query->clear('order')->clear('limit'); $query->clear('select')->select('COUNT(t0.id)'); $db->setQuery($query); $config['total'] = $db->loadResult(); $query2 = (string) $query; } } else { $query2 = $db->getQuery(true); $query2->select('COUNT(t0.id)'); $query2->from('`#__cck_core` AS t0'); self::_buildQuery($dispatcher, $query2, $tables, $t, $config, $inherit, $user, $config['doSelect']); if ($where != '') { $query2->where($where); } $db->setQuery($query2, 0, 0); $config['total'] = $db->loadResult(); $query2 = (string) $query2; } } } } } else { $query = $db->getQuery(true); $query->select('t0.pk as pk'); $query->from('`#__cck_core` AS t0'); self::_buildQuery($dispatcher, $query, $tables, $t, $config, $inherit, $user, false); if ($where != '') { $query->where($where); } $db->setQuery($query); $results = $db->loadColumn(); } } // Debug if ($options->get('debug')) { if (!isset($query1)) { $query1 = (string) $query; } if ($query2) { $query2 .= '<br />'; } echo str_replace(array('SELECT', 'FROM', 'LEFT JOIN', 'RIGHT JOIN', 'INNER JOIN', 'WHERE', 'AND', 'ORDER BY', 'LIMIT', 'UNION', ') AS Count'), array('<br />SELECT', '<br />FROM', '<br />LEFT JOIN', '<br />RIGHT JOIN', '<br />INNER JOIN', '<br />WHERE', '<br /> AND', '<br />ORDER BY', '<br />LIMIT', '<br />UNION', '<br />) AS Count'), $query1 . '<br />' . $query2) . '<br />'; } unset($fields); unset($fields_order); unset($tables); return $results; }
public function delete() { if ($this->_object == '') { return false; } if (!($this->_id && $this->_pk)) { return false; } $config = array('author' => $this->_instance_core->author_id, 'type' => $this->_instance_core->cck, 'type_id' => 0); $nb = 0; if ($config['type']) { $config['type_id'] = JCckDatabaseCache::loadResult('SELECT id FROM #__cck_core_types WHERE name = "' . $config['type'] . '"'); } if (!$config['type_id']) { return false; } JPluginHelper::importPlugin('content'); if (JCck::callFunc_Array('plgCCK_Storage_Location' . $this->_object, 'onCCK_Storage_LocationDelete', array($this->_pk, &$config))) { $nb++; } return $nb ? true : false; }