public function onContentAfterDelete($context, $data) { switch ($context) { case 'com_content.article': $base = 'content'; $custom = 'introtext'; $pk = $data->id; break; case 'com_categories.category': $base = 'categories'; $custom = 'description'; $pk = $data->id; break; default: return true; } preg_match('#::cck::(.*)::/cck::#U', $data->{$custom}, $matches); $id = $matches[1]; if (!$id) { return true; } $table = JCckTable::getInstance('#__cck_core', 'id', $id); $type = $table->cck; $table->delete(); // Processing JLoader::register('JCckToolbox', JPATH_PLATFORM . '/cms/cck/toolbox.php'); if (JCckToolbox::getConfig()->get('processing', 0)) { $event = 'onContentAfterDelete'; $processing = JCckDatabaseCache::loadObjectListArray('SELECT type, scriptfile FROM #__cck_more_toolbox_processings WHERE published = 1 ORDER BY ordering', 'type'); if (isset($processing[$event])) { foreach ($processing[$event] as $p) { if (is_file(JPATH_SITE . $p->scriptfile)) { include_once JPATH_SITE . $p->scriptfile; /* Variables: $id, $pk, $type */ } } } } $tables = JCckDatabase::loadColumn('SHOW TABLES'); $prefix = JFactory::getApplication()->getCfg('dbprefix'); if (in_array($prefix . 'cck_store_item_' . $base, $tables)) { $table = JCckTable::getInstance('#__cck_store_item_' . $base, 'id', $pk); if ($table->id) { $table->delete(); } } if (in_array($prefix . 'cck_store_form_' . $type, $tables)) { $table = JCckTable::getInstance('#__cck_store_form_' . $type, 'id', $pk); if ($table->id) { $table->delete(); } } return true; }
function postInstallMessage($event, $pk = 0) { if (!version_compare(JVERSION, '3.2', 'ge')) { return; } if (!$pk) { $db = JFactory::getDbo(); $query = 'SELECT extension_id FROM #__extensions WHERE type = "component" AND element = "com_cck"'; $db->setQuery($query); $pk = $db->loadResult(); if (!$pk) { return false; } } $lang = JFactory::getLanguage(); $title = (string) $this->cck->element; $lang->load($title); $lang->load('lib_cck', JPATH_SITE, 'en-GB', true); $title = JText::_($title . '_addon'); if (isset($this->cck->xml->version)) { $title = str_replace(' for SEBLOD', '', $title) . ' ' . (string) $this->cck->xml->version; } $user = JFactory::getUser(); $user_name = '<a href="index.php?option=com_cck&view=form&return_o=users&return_v=users&type=user&id=' . $user->id . '" target="_blank">' . $user->name . '</a>'; $version = '3.2.0'; jimport('joomla.filesystem.file'); if (JFile::exists(JPATH_ADMINISTRATOR . '/components/com_cck/_VERSION.php')) { require_once JPATH_ADMINISTRATOR . '/components/com_cck/_VERSION.php'; if (class_exists('JCckVersion')) { $version = new JCckVersion(); $version = $version->getShortVersion(); } else { $version = JFile::read(JPATH_ADMINISTRATOR . '/components/com_cck/_VERSION.php'); } } require_once JPATH_SITE . '/libraries/cms/cck/cck.php'; require_once JPATH_SITE . '/libraries/cms/cck/database.php'; require_once JPATH_SITE . '/libraries/cms/cck/table.php'; $table = JCckTable::getInstance('#__postinstall_messages'); $table->extension_id = $pk; $table->title_key = $title; $table->description_key = JText::sprintf('LIB_CCK_POSTINSTALL_' . strtoupper($event) . '_DESCRIPTION', $user_name, JFactory::getDate()->format(JText::_('DATE_FORMAT_LC2'))); $table->language_extension = 'lib_cck'; $table->type = 'message'; $table->version_introduced = $version; $table->store(); return true; }
public static function importTables($data) { $db = JFactory::getDbo(); $path = $data['root'] . '/tables'; if (file_exists($path)) { $items = JFolder::files($path, '\\.xml$'); if (count($items)) { $prefix = JFactory::getConfig()->get('dbprefix'); $tables = array_flip(JCckDatabase::loadColumn('SHOW TABLES')); foreach ($items as $item) { $xml = JCckDev::fromXML($path . '/' . $item); if (!$xml || (string) $xml->attributes()->type != 'tables') { return; } $name = (string) $xml->table->name; $table_key = (string) $xml->table->primary_key; $short = str_replace('#__', $prefix, $name); if (isset($tables[$short])) { $table = JCckTable::getInstance($name); $table_fields = $table->getFields(); $previous = ''; // Fields $fields = $xml->fields->children(); if (count($fields)) { foreach ($fields as $field) { $column = (string) $field; $type = (string) $field->attributes()->type; $default = (string) $field->attributes()->default; if (!isset($table_fields[$column])) { $query = 'ALTER TABLE ' . $name . ' ADD ' . JCckDatabase::quoteName($column) . ' ' . $type . ' NOT NULL'; $query .= $default != '' ? ' DEFAULT "' . $default . '"' : ''; $query .= $previous != '' ? ' AFTER ' . JCckDatabase::quoteName($previous) : ' FIRST'; JCckDatabase::execute($query); } else { if ($type != $table_fields[$column]->Type) { $query = 'ALTER TABLE ' . $name . ' CHANGE ' . JCckDatabase::quoteName($column) . ' ' . JCckDatabase::quoteName($column) . ' ' . $type . ' NOT NULL'; $query .= $default != '' ? ' DEFAULT "' . $default . '"' : ''; JCckDatabase::execute($query); } } $previous = $column; } } // Indexes $indexes = $xml->indexes->children(); $indexes2 = array(); if (count($indexes)) { foreach ($indexes as $index) { $idx = (string) $index; $indexes2[$idx][(string) $index->attributes()->seq_in_type] = (string) $index->attributes()->column_name; } } if (count($indexes2)) { foreach ($indexes2 as $k => $v) { if ($k == 'PRIMARY') { JCckDatabase::execute('ALTER TABLE ' . $name . ' DROP PRIMARY KEY, ADD PRIMARY KEY ( ' . implode(',', $v) . ' )'); } else { // todo } } } } else { $sql_query = ''; // Fields $fields = $xml->fields->children(); if (count($fields)) { foreach ($fields as $field) { $type = (string) $field->attributes()->type; $default = (string) $field->attributes()->default; $sql_query .= ' ' . JCckDatabase::quoteName((string) $field) . ' ' . $type . ' NOT NULL'; if ($default != '') { $sql_query .= ' DEFAULT "' . $default . '"'; } $sql_query .= ','; } } // Indexes $indexes = $xml->indexes->children(); $indexes2 = array(); if (count($indexes)) { foreach ($indexes as $index) { $idx = (string) $index; $indexes2[$idx][(string) $index->attributes()->seq_in_type] = (string) $index->attributes()->column_name; } } if (count($indexes2)) { foreach ($indexes2 as $k => $v) { $sql_query .= $k == 'PRIMARY' ? ' PRIMARY KEY ( ' . implode(',', $v) . ' ),' : ' KEY ' . $k . ' ( ' . implode(',', $v) . ' ),'; } } $sql_query = $sql_query ? substr($sql_query, 0, -1) : ''; JCckDatabase::execute('CREATE TABLE IF NOT EXISTS ' . $name . ' (' . $sql_query . ') ENGINE=InnoDB DEFAULT CHARSET=utf8;'); } } } } }
protected static function _getTable($pk = 0, $table = '', &$config = array()) { $table = JCckTable::getInstance($table, 'id'); $pk = $pk ? $pk : $config['pk']; if ($pk > 0) { $table->load($pk, true); } return $table; }
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 function mergeArray($data) { if (count($this->_tbl_rows)) { foreach ($this->_tbl_rows as $key => $val) { if (isset($data[$key])) { if (count($data[$key])) { foreach ($data[$key] as $k => $v) { if (isset($val->{$k})) { $val->{$k} = $v; } } } unset($data[$key]); } else { unset($this->_tbl_rows[$key]); } } } if (count($data)) { foreach ($data as $key => $val) { $obj = JCckTable::getInstance($this->_tbl); if (count($val)) { foreach ($val as $k => $v) { if (property_exists($obj, $k)) { $obj->{$k} = $v; } } } $this->_tbl_rows[$key] = $obj; } } }
function _postInstallMessage($event, $parent) { if (!version_compare(JVERSION, '3.2', 'ge')) { return; } $db = JFactory::getDbo(); $title = 'com_cck'; $query = 'SELECT extension_id FROM #__extensions WHERE type = "component" AND element = "' . $title . '"'; $db->setQuery($query); $pk = $db->loadResult(); if (!$pk) { return false; } JFactory::getLanguage()->load($title); $version = (string) $parent->getParent()->getManifest()->version; if ($event == 'install') { $text = JText::_('LIB_CCK_POSTINSTALL_WELCOME_DESCRIPTION'); } else { $user = JFactory::getUser(); $user_id = $user->id; $user_type = JCckDatabase::loadResult('SELECT cck FROM #__cck_core WHERE storage_location = "joomla_user" AND pk = ' . $user_id); if ($user_type) { $user_link = 'index.php?option=com_cck&view=form&return_o=users&return_v=users&type=' . $user_type . '&id=' . $user_id; } else { $user_link = 'index.php?option=com_users&task=user.edit&id=' . $user_id; } $user_name = '<a href="' . $user_link . '" target="_blank">' . $user->name . '</a>'; $text = JText::sprintf('LIB_CCK_POSTINSTALL_' . strtoupper($event) . '_DESCRIPTION', $user_name, JFactory::getDate()->format(JText::_('DATE_FORMAT_LC2'))); } $title = 'SEBLOD ' . $version; require_once JPATH_SITE . '/libraries/cms/cck/cck.php'; require_once JPATH_SITE . '/libraries/cms/cck/database.php'; require_once JPATH_SITE . '/libraries/cms/cck/table.php'; $table = JCckTable::getInstance('#__postinstall_messages'); $table->extension_id = $pk; $table->title_key = $title; $table->description_key = $text; $table->language_extension = 'lib_cck'; $table->type = 'message'; $table->version_introduced = $version; $table->store(); return true; }
public function onContentAfterDelete($context, $data) { $db = JFactory::getDbo(); $query = $db->getQuery(true)->select('name AS object')->from('#__cck_core_objects')->where('context = ' . $db->quote($context)); $db->setQuery($query); $object = $db->loadResult(); if (!$object) { return true; } $tableKey = $data->getKeyName(); $pk = $data->{$tableKey}; $base = str_replace('#__', '', $data->getTableName()); require_once JPATH_SITE . '/plugins/cck_storage_location/' . $object . '/' . $object . '.php'; $properties = array('custom'); $properties = JCck::callFunc('plgCCK_Storage_Location' . $object, 'getStaticProperties', $properties); $custom = $properties['custom']; $type = ''; // Core if ($custom) { preg_match('#::cck::(.*)::/cck::#U', $data->{$custom}, $matches); $id = $matches[1]; if (!$id) { return true; } $table = JCckTable::getInstance('#__cck_core', 'id', $id); $type = $table->cck; } else { $table = JCckTable::getInstance('#__cck_core'); if ($table->load(array('pk' => $pk, 'storage_location' => $object))) { $type = $table->cck; } } if ($table->pk > 0) { // -- Leave nothing behind if ($type != '') { require_once JPATH_LIBRARIES . '/cck/base/form/form.php'; JPluginHelper::importPlugin('cck_field'); JPluginHelper::importPlugin('cck_storage'); JPluginHelper::importPlugin('cck_storage_location'); $config = array('pk' => $table->pk, 'storages' => array(), 'type' => $table->cck); $dispatcher = JDispatcher::getInstance(); $parent = JCckDatabase::loadResult('SELECT parent FROM #__cck_core_types WHERE name = "' . $type . '"'); $fields = CCK_Form::getFields(array($type, $parent), 'all', -1, '', true); if (count($fields)) { foreach ($fields as $field) { $Pt = $field->storage_table; $value = ''; /* Yes but, .. */ if ($Pt && !isset($config['storages'][$Pt])) { $config['storages'][$Pt] = ''; $dispatcher->trigger('onCCK_Storage_LocationPrepareDelete', array(&$field, &$config['storages'][$Pt], $pk, &$config)); } $dispatcher->trigger('onCCK_StoragePrepareDelete', array(&$field, &$value, &$config['storages'][$Pt], &$config)); $dispatcher->trigger('onCCK_FieldDelete', array(&$field, $value, &$config, array())); } } } // -- Leave nothing behind $table->delete(); } // Processing JLoader::register('JCckToolbox', JPATH_PLATFORM . '/cms/cck/toolbox.php'); if (JCckToolbox::getConfig()->get('processing', 0)) { $event = 'onContentAfterDelete'; $processing = JCckDatabaseCache::loadObjectListArray('SELECT type, scriptfile FROM #__cck_more_processings WHERE published = 1 ORDER BY ordering', 'type'); if (isset($processing[$event])) { foreach ($processing[$event] as $p) { if (is_file(JPATH_SITE . $p->scriptfile)) { include_once JPATH_SITE . $p->scriptfile; /* Variables: $id, $pk, $type */ } } } } $tables = JCckDatabase::loadColumn('SHOW TABLES'); $prefix = JFactory::getConfig()->get('dbprefix'); if (in_array($prefix . 'cck_store_item_' . $base, $tables)) { $table = JCckTable::getInstance('#__cck_store_item_' . $base, 'id', $pk); if ($table->id) { $table->delete(); } } if (in_array($prefix . 'cck_store_form_' . $type, $tables)) { $table = JCckTable::getInstance('#__cck_store_form_' . $type, 'id', $pk); if ($table->id) { $table->delete(); } } return true; }
public function ajax_session_del() { $app = JFactory::getApplication(); $user = JFactory::getUser(); if (!$user->authorise('core.admin')) { return; } $session_id = $app->input->getInt('sid', 0); $table = JCckTable::getInstance('#__cck_more_sessions'); $table->load($session_id); $table->delete(); }
public function g_doBridge($type, $pk, $location, &$config, $params) { // Todo: move to plug-in if ($type == 'joomla_category') { $core = JCckTable::getInstance('#__cck_core', 'id'); $core->load($config['id']); JLoader::register('JTableCategory', JPATH_PLATFORM . '/joomla/database/table/category.php'); $bridge = JTable::getInstance('category'); $dispatcher = JDispatcher::getInstance(); if ($core->pkb > 0) { $bridge->load($core->pkb); $bridge->description = ''; $isNew = false; } else { $bridge->access = ''; $bridge->published = ''; $bridge->created_user_id = $config['author']; self::g_initTable($bridge, $params, false, 'bridge_'); if (!isset($config['storages']['#__categories']['parent_id'])) { $config['storages']['#__categories']['parent_id'] = $params['bridge_default-parent_id']; } $isNew = true; } if ($bridge->parent_id != $config['storages']['#__categories']['parent_id'] || $config['storages']['#__categories']['id'] == 0) { $bridge->setLocation($config['storages']['#__categories']['parent_id'], 'last-child'); } if (isset($config['storages']['#__categories'])) { $bridge->bind($config['storages']['#__categories']); } if ($params['bridge_default_title_mode'] && $params['bridge_default_title'] != '' && strpos($params['bridge_default_title'], '#') !== false) { $title = $params['bridge_default_title']; $matches = array(); preg_match_all('#\\#([a-zA-Z0-9_]*)\\##U', $params['bridge_default_title'], $matches); if (count($matches[1])) { $fieldnames = '"' . implode('","', $matches[1]) . '"'; $fields = JCckDatabase::loadObjectList('SELECT name, storage, storage_table, storage_field FROM #__cck_core_fields WHERE name IN (' . $fieldnames . ') AND storage_field2 = ""', 'name'); foreach ($matches[1] as $match) { $value = ''; if (isset($fields[$match])) { if (isset($config['storages'][$fields[$match]->storage_table][$fields[$match]->storage_field])) { $value = $config['storages'][$fields[$match]->storage_table][$fields[$match]->storage_field]; } } $title = str_replace('#' . $match . '#', $value, $title); } $bridge->title = trim($title); } } if (!$bridge->title) { $bridge->title = ucwords(str_replace('_', ' ', $location['_']->location)) . ' - ' . $pk; } if (!$bridge->parent_id) { $bridge->parent_id = 2; } $bridge->description = '::cck::' . $config['id'] . '::/cck::' . $bridge->description; if (!$core->pkb) { // setLocation, etc.. } $bridge->check(); $bridge->extension = 'com_content'; if ($bridge->parent_id > 1) { $bridgeParent = JTable::getInstance('category'); $bridgeParent->load($bridge->parent_id); $bridge->path = $bridgeParent->path . '/'; } else { $bridge->path = ''; } $bridge->path .= $bridge->alias; if (empty($bridge->language)) { $bridge->language = '*'; } JPluginHelper::importPlugin('content'); $dispatcher->trigger('onContentBeforeSave', array('com_categories.category', &$bridge, $isNew)); if (!$bridge->store()) { if ($isNew) { $test = JTable::getInstance('category'); for ($i = 2; $i < 69; $i++) { $alias = $bridge->alias . '-' . $i; if (!$test->load(array('alias' => $alias, 'parent_id' => $bridge->parent_id, 'extension' => $bridge->extension))) { $bridge->alias = $alias; $bridge->store(); break; } } } } $config['author'] = $config['author'] == 0 ? $bridge->created_user_id : $config['author']; $config['parent_id'] = $config['parent_id'] == 0 ? $bridge->parent_id : $config['parent_id']; $core->pkb = $bridge->id > 0 ? $bridge->id : 0; $core->cck = $config['type']; if (!$core->pk) { $core->author_id = $config['author']; $core->date_time = JFactory::getDate()->toSql(); } $core->pk = $pk; $core->storage_location = $location['_']->location; $core->author_id = $config['author']; $core->parent_id = $config['parent']; $core->storeIt(); $dispatcher->trigger('onContentAfterSave', array('com_categories.category', &$bridge, $isNew)); } else { $core = JCckTable::getInstance('#__cck_core', 'id'); $core->load($config['id']); JLoader::register('JTableContent', JPATH_PLATFORM . '/joomla/database/table/content.php'); $bridge = JTable::getInstance('content'); $dispatcher = JDispatcher::getInstance(); if ($core->pkb > 0) { $bridge->load($core->pkb); $bridge->introtext = ''; $isNew = false; } else { $bridge->access = ''; $bridge->state = ''; $bridge->created_by = $config['author']; self::g_initTable($bridge, $params, false, 'bridge_'); $isNew = true; } if (isset($config['storages']['#__content'])) { $bridge->bind($config['storages']['#__content']); } if ($params['bridge_default_title_mode'] && $params['bridge_default_title'] != '' && strpos($params['bridge_default_title'], '#') !== false) { $title = $params['bridge_default_title']; $matches = array(); preg_match_all('#\\#([a-zA-Z0-9_]*)\\##U', $params['bridge_default_title'], $matches); if (count($matches[1])) { $fieldnames = '"' . implode('","', $matches[1]) . '"'; $fields = JCckDatabase::loadObjectList('SELECT name, storage, storage_table, storage_field FROM #__cck_core_fields WHERE name IN (' . $fieldnames . ') AND storage_field2 = ""', 'name'); foreach ($matches[1] as $match) { $value = ''; if (isset($fields[$match])) { if (isset($config['storages'][$fields[$match]->storage_table][$fields[$match]->storage_field])) { $value = $config['storages'][$fields[$match]->storage_table][$fields[$match]->storage_field]; } } $title = str_replace('#' . $match . '#', $value, $title); } $bridge->title = trim($title); } } if (!$bridge->title) { $bridge->title = ucwords(str_replace('_', ' ', $location['_']->location)) . ' - ' . $pk; } if (!$bridge->catid) { $bridge->catid = 2; } $bridge->introtext = '::cck::' . $config['id'] . '::/cck::' . $bridge->introtext; $bridge->version++; if ($bridge->state == 1 && intval($bridge->publish_up) == 0) { $bridge->publish_up = JFactory::getDate()->toSql(); } if (!$core->pkb) { $bridge->reorder('catid = ' . (int) $bridge->catid . ' AND state >= 0'); } $bridge->check(); if (empty($bridge->language)) { $bridge->language = '*'; } JPluginHelper::importPlugin('content'); $dispatcher->trigger('onContentBeforeSave', array('com_content.article', &$bridge, $isNew)); if (!$bridge->store()) { if ($isNew) { $test = JTable::getInstance('content'); for ($i = 2; $i < 69; $i++) { $alias = $bridge->alias . '-' . $i; if (!$test->load(array('alias' => $alias, 'catid' => $bridge->catid))) { $bridge->alias = $alias; $bridge->store(); break; } } } } $config['author'] = $config['author'] == 0 ? $bridge->created_by : $config['author']; $config['parent_id'] = $config['parent_id'] == 0 ? $bridge->catid : $config['parent_id']; $core->pkb = $bridge->id > 0 ? $bridge->id : 0; $core->cck = $config['type']; if (!$core->pk) { $core->author_id = $config['author']; $core->date_time = JFactory::getDate()->toSql(); } $core->pk = $pk; $core->storage_location = $location['_']->location; $core->author_id = $config['author']; $core->parent_id = $config['parent']; $core->storeIt(); $dispatcher->trigger('onContentAfterSave', array('com_content.article', &$bridge, $isNew)); } }
public static function getTemplateStyleInstance($id, $template, $template2, $params, $tag, $force = false) { if (!$template) { return 0; } $default = self::getDefaultStyle($template); if (is_array($params)) { $params = JCckDev::toJSON($params); } $update = 0; if ($template != $template2) { $id = $default->id; $update = 1; //or ajax reload of template params.. } if ($id == $default->id) { if ($params != '{}' && $params != $default->params && $update != 1) { $ck = JCckTable::getInstance('#__template_styles'); $ck->load($id); if ($ck->id > 0) { $ck->id = 0; $ck->title = $ck->template . ' - ' . $tag; $ck->params = $params; $ck->store(); $id = $ck->id ? $ck->id : $id; } } } else { $ck = JCckTable::getInstance('#__template_styles'); $ck->load($id); if ($ck->id > 0) { if ($force != false) { $ck->id = 0; $ck->title = $ck->template . ' - ' . $tag; } $ck->params = $params; $ck->store(); $id = $ck->id ? $ck->id : $id; } } return $id; }
protected function _delete($pk, $location, $base) { $id = JCckDatabase::loadResult('SELECT id FROM #__cck_core WHERE storage_location = "' . (string) $location . '" AND pk = ' . (int) $pk); if (!$id) { return true; } $table = JCckTable::getInstance('#__cck_core', 'id', $id); $type = $table->cck; $pkb = (int) $table->pkb; $table->delete(); if ($pkb > 0) { $table = JTable::getInstance('content'); $table->delete($pkb); } $tables = JCckDatabase::loadColumn('SHOW TABLES'); $prefix = JFactory::getApplication()->getCfg('dbprefix'); if (in_array($prefix . 'cck_store_item_' . $base, $tables)) { $table = JCckTable::getInstance('#__cck_store_item_' . $base, 'id', $pk); if ($table->id) { $table->delete(); } } if (in_array($prefix . 'cck_store_form_' . $type, $tables)) { $table = JCckTable::getInstance('#__cck_store_form_' . $type, 'id', $pk); if ($table->id) { $table->delete(); } } }
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); } }
public static function exportTables(&$data) { $db = JFactory::getDbo(); $elemtype = 'table'; $plural = $elemtype . 's'; $dest = CCK_Export::createDir($data['root_elements'] . '/' . $plural); foreach ($data['elements']['tables'] as $name => $fields) { if (isset($data['tables'][str_replace('#__', $data['db_prefix'], $name)])) { if ($name && $name != '#__cck_core' && !isset($data['tables_excluded'][$name])) { $table = JCckTable::getInstance($name); $table_fields = $table->getFields(); $table_keys = $db->getTableKeys($name); $table_pkeys = array(); $xml = new JCckDevXml('<cck />'); $xml->addAttribute('type', $plural); $xml->addChild('author', 'Octopoos'); $xml->addChild('authorEmail', '*****@*****.**'); $xml->addChild('authorUrl', 'http://www.seblod.com'); $xml->addChild('copyright', 'Copyright (C) 2013 SEBLOD. All Rights Reserved.'); $xml->addChild('license', 'GNU General Public License version 2 or later.'); $xml->addChild('description', 'SEBLOD 3.x - www.seblod.com'); $xml2 = $xml->addChild($elemtype); $xml2->addChild('name', $name); $xml3 = $xml->addChild('indexes'); $i = 1; foreach ($table_keys as $k => $v) { if ($v->Key_name == 'PRIMARY') { $table_pkeys[] = $v->Column_name; } $index = $xml3->addChild('index' . $i, $v->Key_name); $index->addAttribute('column_name', $v->Column_name); $index->addAttribute('index_type', $v->Index_type); $index->addAttribute('seq_in_type', $v->Seq_in_index); $i++; } $xml4 = $xml->addChild('fields'); $i = 1; foreach ($table_fields as $k => $v) { if (isset($fields[$k]) || in_array($k, $table_pkeys) || $k == 'cck') { $field = $xml4->addChild('field' . $i, $k); $field->addAttribute('type', $v->Type); $field->addAttribute('default', $v->Default); $i++; } } // Set $buffer = '<?xml version="1.0" encoding="utf-8"?>' . $xml->asIndentedXML(); $path = $dest . '/' . $elemtype . '_' . str_replace('#__', '', $name) . '.xml'; JFile::write($path, $buffer); } } } }