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::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(); } } }
public static function getTargets($id) { static $cache = array(); if (!isset($cache[$id])) { $cache[$id] = JCckDatabase::loadColumn('SELECT product_id FROM #__cck_more_ecommerce_promotion_product WHERE promotion_id = ' . (int) $id); $cache[$id] = array_flip($cache[$id]); } return $cache[$id]; }
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; }
public function getItems() { jimport('joomla.filesystem.folder'); $folders = JFolder::folders(JPATH_LIBRARIES . '/cck/rendering/variations'); $i = 0; $items = array(); $variations = array('empty' => '', 'joomla' => '', 'seb_css3' => '', 'seb_css3b' => ''); // Filter Search $location = $this->getState('filter.location'); $search = $this->getState('filter.search'); // Library if (count($folders) && $location != 'template_name') { foreach ($folders as $k => $v) { if ($search && strpos($v, $search) === false) { continue; } $items[$i] = new stdClass(); $items[$i]->folder = '/libraries/cck/rendering/variations/'; $items[$i]->template = ''; $items[$i]->title = $v; $items[$i]->type = isset($variations[$v]) ? 0 : 1; $items[$i++]->id = $i; } } // Templates if ($search && $location == 'template_name') { $templates = array(0 => $search); $search = ''; } else { $templates = JCckDatabase::loadColumn('SELECT name FROM #__cck_core_templates'); } if (count($templates)) { foreach ($templates as $k => $template) { $path = '/templates/' . $template . '/variations'; if (JFolder::exists(JPATH_SITE . $path)) { $folders = JFolder::folders(JPATH_SITE . $path); if (count($folders)) { foreach ($folders as $k => $v) { if ($search && strpos($v, $search) === false) { continue; } $items[$i] = new stdClass(); $items[$i]->folder = $path; $items[$i]->template = $template; $items[$i]->title = $v; $items[$i]->type = 1; $items[$i++]->id = $i; } } } } } return $items; }
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 static function onCCK_Storage_LocationDelete($pk, &$config = array()) { $app = JFactory::getApplication(); $dispatcher = JDispatcher::getInstance(); $item = JCckDatabase::loadObject('SELECT id, cck as type, pk, storage_table FROM #__cck_core WHERE cck = "' . $config['type'] . '" AND pk = ' . (int) $pk); if (!is_object($item)) { return false; } $table = JCckTable::getInstance($item->storage_table, 'id'); $table->load($pk); if (!$table) { return false; } // Check $user = JCck::getUser(); $canDelete = $user->authorise('core.delete', 'com_cck.form.' . $config['type_id']); $canDeleteOwn = $user->authorise('core.delete.own', 'com_cck.form.' . $config['type_id']); if (!$canDelete && !$canDeleteOwn || !$canDelete && $canDeleteOwn && $config['author'] != $user->get('id') || $canDelete && !$canDeleteOwn && $config['author'] == $user->get('id')) { $app->enqueueMessage(JText::_('COM_CCK_ERROR_DELETE_NOT_PERMITTED'), 'error'); return; } // Process // -- onContentBeforeDelete? if (!$table->delete($pk)) { return false; } // Delete Core if ($item->id) { $table = JCckTable::getInstance('#__cck_core', 'id', $item->id); $table->delete(); } // Delete More $base = str_replace('#__', '', $item->storage_table); $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_' . $item->type, $tables)) { $table = JCckTable::getInstance('#__cck_store_form_' . $item->type, 'id', $pk); if ($table->id) { $table->delete(); } } // -- onContentAfterDelete? 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;'); } } } } }
public static function getUserZones() { $user = JCck::getUser(); $zones = array(); if (!(isset($user->country) && $user->country != '')) { return $zones; } $where = 'countries = "' . $user->country . '" OR countries LIKE "' . $user->country . '||%" OR countries LIKE "%||' . $user->country . '" OR countries LIKE "%||' . $user->country . '||%"'; $zones = JCckDatabase::loadColumn('SELECT id FROM #__cck_more_ecommerce_zones WHERE published = 1 AND (' . $where . ') ORDER BY CHARACTER_LENGTH(countries) ASC'); return $zones; }
public function prepareExport($id = 0, $elements = array(), $dependencies = array(), $options = array()) { $config = JFactory::getConfig(); $tmp_path = $config->get('tmp_path'); $tmp_dir = uniqid('cck_'); $path = $tmp_path . '/' . $tmp_dir; $folders = isset($elements['subfolders']) ? Helper_Folder::getBranch($id, ',') : $id; $folders = JCckDatabase::loadObjectList('SELECT * FROM #__cck_core_folders WHERE id IN (' . (string) $folders . ') ORDER BY lft'); if (!@$folders[0]) { return; } $isApp = false; $isCck = false; $name = $folders[0]->name; if (!$name) { return; } // Core jimport('joomla.filesystem.file'); jimport('cck.base.install.export'); $data = array('root' => $path, 'root_content' => $path . '/content', 'root_elements' => $path . '/elements', 'root_extensions' => $path . '/extensions', 'root_sql' => $path . '/sql', 'root_category' => '', 'elements' => array(), 'db_prefix' => $config->get('dbprefix')); $extensions = array(0 => (object) array('type' => 'plugin', 'id' => 'plg_system_blank', 'group' => 'system', '_file' => 'plg_system_blank.zip')); $data['folders'] = JCckDatabase::loadObjectList('SELECT id, name, path FROM #__cck_core_folders WHERE lft', 'id'); $data['folders2'] = JCckDatabase::loadObjectList('SELECT id, name, path FROM #__cck_core_folders WHERE lft', 'name'); $data['plugins'] = CCK_Export::getCorePlugins(); $data['plugins']['cck_field_live']['stage'] = true; $data['processings'] = JCckDatabase::loadObjectList('SELECT * FROM #__cck_more_processings', 'id'); $data['processings2'] = JCckDatabase::loadObjectList('SELECT folder FROM #__cck_more_processings', 'folder'); $data['styles'] = JCckDatabase::loadObjectList('SELECT * FROM #__template_styles', 'id'); $data['tables'] = array_flip(JCckDatabase::loadColumn('SHOW TABLES')); $data['tables_excluded'] = CCK_Export::getCoreTables(); $data['variations'] = array('empty' => true, 'joomla' => true, 'seb_css3' => true, 'seb_css3b' => true); // Copyright if (JCckDatabase::loadResult('SELECT extension_id FROM #__extensions WHERE type = "component" AND element = "com_cck_packager"') > 0) { $params = JComponentHelper::getParams('com_cck_packager'); $copyright = $params->get('copyright'); } else { $copyright = ''; } CCK_Export::createDir($data['root_content']); CCK_Export::createDir($data['root_elements']); CCK_Export::createDir($data['root_extensions']); CCK_Export::createDir($data['root_sql']); if (isset($dependencies['categories'])) { $data['root_category'] = CCK_Export::exportRootCategory($folders['0'], $data, $extensions); } if (isset($dependencies['menu'])) { $data['root_menu'] = CCK_Export::exportMenus($dependencies['menu'], $data, $extensions); } foreach ($folders as $i => $folder) { if ($i == 0) { if ($folder->path && $folder->path != $folder->name) { $branch = explode('/', $folder->path); array_pop($branch); if (count($branch)) { $parent_id = 2; foreach ($branch as $k => $v) { $elem = JCckDatabase::loadObject('SELECT * FROM #__cck_core_folders WHERE name = "' . (string) $v . '" AND parent_id = ' . (int) $parent_id); $parent_id = $elem->id; CCK_Export::createDir($data['root_elements'] . '/folder' . 's'); CCK_Export::exportElement('folder', $elem, $data, $extensions, 0); } } } } CCK_Export::exportElements('folder', $folders, $data, $extensions, 0, $copyright); if (isset($elements['fields'])) { $fields = JCckDatabase::loadObjectList('SELECT a.* FROM #__cck_core_fields AS a WHERE a.folder = ' . (int) $folder->id); CCK_Export::exportElements('field', $fields, $data, $extensions, 500, $copyright); } if (isset($elements['templates'])) { $templates = JCckDatabase::loadObjectList('SELECT a.* FROM #__cck_core_templates AS a WHERE a.folder = ' . (int) $folder->id); CCK_Export::exportElements('template', $templates, $data, $extensions, 0, $copyright); } if (isset($elements['types'])) { $types = JCckDatabase::loadObjectList('SELECT a.* FROM #__cck_core_types AS a WHERE a.folder = ' . (int) $folder->id); if (count($types)) { $isApp = true; } CCK_Export::exportElements('type', $types, $data, $extensions, 0, $copyright); } if (isset($elements['searchs'])) { $searchs = JCckDatabase::loadObjectList('SELECT a.* FROM #__cck_core_searchs AS a WHERE a.folder = ' . (int) $folder->id); if (count($searchs)) { $isApp = true; } CCK_Export::exportElements('search', $searchs, $data, $extensions, 0, $copyright); } } if (count($data['elements']['tables'])) { CCK_Export::exportTables($data); } if (count($data['elements']['processings'])) { $isCck = true; CCK_Export::exportProcessings($data, $extensions); } // Name & Root if ($isApp) { $filename = 'app_cck_' . $name; } else { if ($isCck) { $filename = 'cck_' . $name; } else { $filename = $name; } if (isset($dependencies['categories']) && file_exists($data['root_content'] . '/joomla_category')) { $items = JFolder::files($data['root_content'] . '/joomla_category', '\\.xml$'); if (count($items) == 1 && isset($items[0]) && $data['root_category'] != '' && JFile::stripExt($items[0]) == $data['root_category']) { JFolder::delete($data['root_content'] . '/joomla_category'); } } } // Elements if ($copyright) { CCK_Export::update($data['root_elements'], $copyright); } // Xml $folders[0]->description = 'SEBLOD 3.x ' . $folders[0]->title . ' App - www.seblod.com'; $folders[0]->name = $filename; $folders[0]->title = 'pkg_' . $folders['0']->name; $manifest = NULL; $xml = CCK_Export::preparePackage($folders[0]); if (is_object($xml)) { $manifest = JPATH_ADMINISTRATOR . '/manifests/packages/pkg_' . $filename . '.xml'; if (is_file($manifest)) { if ($copyright) { CCK_Export::update($manifest, $copyright); } $manifest = JCckDev::fromXML($manifest); $tags = array('copyright', 'creationDate', 'description', 'packager', 'packageurl', 'version'); if (is_object($manifest)) { foreach ($tags as $tag) { if (isset($manifest->{$tag}) && isset($xml->{$tag}) && $manifest->{$tag} != $xml->{$tag}) { $xml->{$tag} = (string) $manifest->{$tag}; } } } } } // Filename $path_zip = $tmp_path . '/' . $filename; if (isset($options['filename_version']) && $options['filename_version']) { $path_zip .= '_' . (isset($manifest->version) ? $manifest->version : '1.0.0'); } if (isset($options['filename_date']) && $options['filename_date']) { $path_zip .= '_' . JFactory::getDate()->format('Y_m_d'); } $path_zip .= '.zip'; // Script if (is_file(JPATH_ADMINISTRATOR . '/manifests/packages/' . $name . '/pkg_script.php')) { if ($copyright) { CCK_Export::update(JPATH_ADMINISTRATOR . '/manifests/packages/' . $name . '/pkg_script.php', $copyright); } } // todo: else $script = $xml->addChild('scriptfile', 'pkg_script.php'); JFile::copy(JPATH_SITE . '/libraries/cck/development/apps/script.php', $path . '/pkg_script.php'); $buffer = JFile::read($path . '/pkg_script.php'); $buffer = str_replace('%class%', $filename, $buffer); JFile::write($path . '/pkg_script.php', $buffer); if ($copyright) { CCK_Export::update($path . '/pkg_script.php', $copyright); } // Extensions $files = $xml->addChild('files'); $files->addAttribute('folder', 'extensions'); $names = array(); foreach ($extensions as $ext) { $file = $files->addChild('file', $ext->_file); $names[$ext->_file] = ''; foreach ($ext as $k => $v) { if ($k != '_file') { $file->addAttribute($k, $v); } } } if (isset($manifest->files->file) && count($manifest->files->file)) { foreach ($manifest->files->file as $f) { $f_name = (string) $f; if (!isset($names[$f_name])) { $f_file = array('_' => $f_name); $f_client = (string) $f->attributes()->client; $f_id = (string) $f->attributes()->id; $f_type = (string) $f->attributes()->type; if ($f_type == 'template') { $f_file['lang_root'] = JPATH_SITE; $f_file['src'] = JPATH_SITE . '/templates/' . (strpos($f_id, 'tpl_') !== false && strpos($f_id, 'tpl_') == 0 ? substr($f_id, 4) : $f_id); $f_file['lang_src'] = $f_file['src'] . '/templateDetails.xml'; } else { // todo } if (is_array($f_file) && $f_file['src'] != '') { CCK_Export::exportFile($f_type, $data, $f_file, array(), $copyright); $file = $files->addChild('file', $f_name); $file->addAttribute('type', $f_type); $file->addAttribute('id', $f_id); $file->addAttribute('client', $f_client); } } } } // Languages $dest = CCK_Export::createDir($path . '/languages'); $languages = JCckDatabase::loadColumn('SELECT element FROM #__extensions WHERE type = "language" AND client_id = 0'); if (count($languages)) { $lang = $xml->addChild('languages'); $lang->addAttribute('folder', 'languages'); foreach ($languages as $language) { if (is_file(JPATH_SITE . '/language/' . $language . '/' . $language . '.pkg_' . $filename . '.ini')) { $l = $lang->addChild('language', $language . '/' . $language . '.pkg_' . $filename . '.ini'); $l->addAttribute('tag', $language); CCK_Export::createDir($path . '/languages/' . $language); if ($copyright) { CCK_Export::update(JPATH_SITE . '/language/' . $language . '/' . $language . '.pkg_' . $filename . '.ini', $copyright); } JFile::copy(JPATH_SITE . '/language/' . $language . '/' . $language . '.pkg_' . $filename . '.ini', $dest . '/' . $language . '/' . $language . '.pkg_' . $filename . '.ini'); } if (is_file(JPATH_SITE . '/language/' . $language . '/' . $language . '.pkg_' . $filename . '.sys.ini')) { $l = $lang->addChild('language', $language . '/' . $language . '.pkg_' . $filename . '.sys.ini'); $l->addAttribute('tag', $language); CCK_Export::createDir($path . '/languages/' . $language); if ($copyright) { CCK_Export::update(JPATH_SITE . '/language/' . $language . '/' . $language . '.pkg_' . $filename . '.sys.ini', $copyright); } JFile::copy(JPATH_SITE . '/language/' . $language . '/' . $language . '.pkg_' . $filename . '.sys.ini', $dest . '/' . $language . '/' . $language . '.pkg_' . $filename . '.sys.ini'); } } } // Media if (file_exists(JPATH_SITE . '/media/cck/apps/' . $name)) { JFolder::copy(JPATH_SITE . '/media/cck/apps/' . $name, $path . '/media'); } // Manifest JFile::copy(JPATH_LIBRARIES . '/cck/base/install/_plg_system_blank.zip', $path . '/extensions/plg_system_blank.zip'); if (is_object($manifest) && isset($manifest->updateservers)) { $servers = $xml->addChild('updateservers'); if (count($manifest->updateservers->server)) { foreach ($manifest->updateservers->server as $server) { $s = $servers->addChild('server', (string) $server); $s->addAttribute('type', (string) $server->attributes()->type); $s->addAttribute('priority', (string) $server->attributes()->priority); $s->addAttribute('name', (string) $server->attributes()->name); } } } CCK_Export::clean($path); CCK_Export::createFile($path . '/pkg_' . $filename . '.xml', '<?xml version="1.0" encoding="utf-8"?>' . $xml->asIndentedXML()); if ($copyright) { CCK_Export::update($path . '/pkg_' . $filename . '.xml', $copyright); } return CCK_Export::zip($path, $path_zip); }
public static function rebuildTree($parent_id = 0, $lft = 0, $depth = 0, $more = '') { $childs = JCckDatabase::loadColumn('SELECT id FROM #__cck_core' . $more . '_folders WHERE parent_id = ' . (int) $parent_id . ' ORDER BY parent_id, title'); $n = count($childs); $rgt = $lft + 1; for ($i = 0; $i < $n; $i++) { $depth++; $rgt = self::rebuildTree($childs[$i], $rgt, $depth); $depth--; if ($rgt === false) { return false; } } if (!JCckDatabase::doQuery('UPDATE #__cck_core_folders SET depth = ' . (int) $depth . ', lft = ' . (int) $lft . ', rgt = ' . (int) $rgt . ' WHERE id =' . (int) $parent_id)) { return false; } return $rgt + 1; }
public static function getBranch($table, $pk) { $query = 'SELECT s.id, (COUNT(parent.id) - (branch.depth2 + 1)) AS depth2' . ' FROM ' . $table . ' AS s,' . $table . ' AS parent,' . $table . ' AS subparent,' . ' (' . ' SELECT s.id, (COUNT(parent.id) - 1) AS depth2' . ' FROM ' . $table . ' AS s,' . $table . ' AS parent' . ' WHERE s.lft BETWEEN parent.lft AND parent.rgt' . ' AND s.id =' . (int) $pk . ' GROUP BY s.id' . ' ORDER BY s.lft' . ' ) AS branch' . ' WHERE s.lft BETWEEN parent.lft AND parent.rgt' . ' AND s.lft BETWEEN subparent.lft AND subparent.rgt' . ' AND subparent.id = branch.id' . ' GROUP BY s.id' . ' ORDER BY s.lft'; $items = JCckDatabase::loadColumn($query); return $items; }
public static function getCoreTables() { $core = array(); $plugins = JCckDatabase::loadColumn('SELECT element FROM #__extensions WHERE folder = "cck_storage_location"'); if (count($plugins)) { foreach ($plugins as $plugin) { if ($plugin != '' && is_file(JPATH_SITE . '/plugins/cck_storage_location/' . $plugin . '/' . $plugin . '.php')) { require_once JPATH_SITE . '/plugins/cck_storage_location/' . $plugin . '/' . $plugin . '.php'; $properties = array('table'); $properties = JCck::callFunc('plgCCK_Storage_Location' . $plugin, 'getStaticProperties', $properties); if ($properties['table']) { $core[$properties['table']] = ''; } } } } return $core; }
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; } if ($config['client'] == 'admin' && !$config['pk'] && !$value) { $value = array(2); } elseif ($value && is_string($value) && strpos($value, ',') !== false) { $value = explode(',', $value); } elseif (is_null($value)) { $value = $field->defaultvalue; } if (!is_array($value)) { $value = array($value); } // Validate $validate = ''; if ($config['doValidation'] > 1) { plgCCK_Field_ValidationRequired::onCCK_Field_ValidationPrepareForm($field, $id, $config); $validate = count($field->validate) ? ' validate[' . implode(',', $field->validate) . ']' : ''; } // Prepare $class = $field->css ? ' class="' . $field->css . '"' : ''; $form = JHtml::_('access.usergroups', $name, $value); // JForm UserGroups ?! $form = '<div id="' . $name . '"' . $class . '>' . $form . '</div>'; // Set if (!$field->variation) { $field->form = $form; if ($field->script) { parent::g_addScriptDeclaration($field->script); } } else { $values = is_array($value) ? implode(',', $value) : $value; $field->text = JCckDatabase::loadColumn('SELECT title FROM #__usergroups WHERE id IN (' . (string) $values . ')'); $field->text = implode(',', $field->text); //todo parent::g_getDisplayVariation($field, $field->variation, $values, $field->text, $form, $id, $name, '<input', '', '', $config); } $field->value = $value; // Return if ($return === true) { return $field; } }
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; } }
function postflight($type, $parent) { $app = JFactory::getApplication(); $db = JFactory::getDbo(); // Force { CCK } Plugins + { CCK } Library to be published $db->setQuery('UPDATE #__extensions SET enabled = 1 WHERE element = "cck"'); $db->execute(); // Rename Menu Item $db->setQuery('UPDATE #__menu SET alias = "SEBLOD 3.x", path="SEBLOD 3.x" WHERE link = "index.php?option=com_cck"'); $db->execute(); // Re-build menu $query = 'SELECT id, level, lft, path FROM #__menu WHERE link = "index.php?option=com_cck"'; $db->setQuery($query); $seblod = $db->loadObject(); if ($seblod->id > 0) { $query = 'SELECT extension_id as id, element FROM #__extensions WHERE type = "component" AND element LIKE "com_cck_%" ORDER BY name'; $db->setQuery($query); $addons = $db->loadObjectList(); if (count($addons)) { JLoader::register('JTableMenu', JPATH_PLATFORM . '/joomla/database/table/menu.php'); $titles = array('com_cck_builder' => 'Builder', 'com_cck_developer' => 'Developer', 'com_cck_ecommerce' => 'eCommerce', 'com_cck_exporter' => 'Exporter', 'com_cck_importer' => 'Importer', 'com_cck_manager' => 'Manager', 'com_cck_multilingual' => 'Multilingual', 'com_cck_packager' => 'Packager', 'com_cck_toolbox' => 'Toolbox', 'com_cck_updater' => 'Updater', 'com_cck_webservices' => 'WebServices'); foreach ($addons as $addon) { $addon->title = $titles[$addon->element]; self::_addAddon($addon, $seblod); } } } // Reorder Plugins $i = 2; $ids = ''; $query = 'SELECT extension_id FROM #__extensions WHERE type = "plugin" AND folder = "content" AND element != "cck" ORDER BY ordering'; $db->setQuery($query); $plgs = $db->loadObjectList(); $sql = 'UPDATE #__extensions SET ordering = CASE extension_id'; foreach ($plgs as $p) { $ids .= $p->extension_id . ','; $sql .= ' WHEN ' . $p->extension_id . ' THEN ' . $i; $i++; } $ids = substr($ids, 0, -1); $sql .= ' END WHERE extension_id IN (' . $ids . ')'; $db->setQuery($sql); $db->execute(); $db->setQuery('UPDATE #__extensions SET ordering = 1 WHERE type = "plugin" AND folder = "content" AND element = "cck"'); $db->execute(); if ($type == 'install') { // Manage Modules $modules = array(0 => array('name' => 'mod_cck_menu', 'update' => 'title = "Admin Menu - SEBLOD", access = 3, published = 1, position = "menu", ordering = 2'), 1 => array('name' => 'mod_cck_quickadd', 'update' => 'title = "Quick Add - SEBLOD", access = 3, published = 1, position = "status", ordering = 0'), 2 => array('name' => 'mod_cck_quickicon', 'update' => 'title = "Quick Icons - SEBLOD", access = 3, published = 1, position = "icon", ordering = 2'), 3 => array('name' => 'mod_cck_breadcrumbs', 'update' => 'title = "Breadcrumbs - SEBLOD"'), 4 => array('name' => 'mod_cck_form', 'update' => 'title = "Form - SEBLOD"'), 5 => array('name' => 'mod_cck_list', 'update' => 'title = "List - SEBLOD"'), 6 => array('name' => 'mod_cck_search', 'update' => 'title = "Search - SEBLOD"')); foreach ($modules as $module) { $query = 'UPDATE #__modules SET ' . $module['update'] . ' WHERE module = "' . $module['name'] . '"'; $db->setQuery($query); $db->execute(); $query = 'SELECT id FROM #__modules WHERE module="' . $module['name'] . '"'; $db->setQuery($query); $mid = $db->loadResult(); $query = 'INSERT INTO #__modules_menu (moduleid, menuid) VALUES (' . $mid . ', 0)'; $db->setQuery($query); $db->execute(); } // Publish Plugins $query = 'UPDATE #__extensions SET enabled = 1 WHERE folder LIKE "cck_%"'; $db->setQuery($query); $db->execute(); // Revert Version for Joomla! 2.5.x if (!JCck::on()) { $query = 'SELECT id FROM #__cck_core_types WHERE version = 2 ORDER BY id'; $db->setQuery($query); $forms = $db->loadObjectList(); if (count($forms)) { require_once JPATH_ADMINISTRATOR . '/components/com_cck/helpers/helper_version.php'; foreach ($forms as $f) { Helper_Version::revert('type', $f->id, '1'); } } } // Set Template Styles $query = 'SELECT id FROM #__template_styles WHERE template="seb_one" ORDER BY id'; $db->setQuery($query); $style = $db->loadResult(); $query = 'SELECT id FROM #__template_styles WHERE template="seb_blog" ORDER BY id'; $db->setQuery($query); $style2 = $db->loadResult(); // $query = 'UPDATE #__cck_core_types SET template_admin = ' . $style . ', template_site = ' . $style . ', template_content = ' . $style . ', template_intro = ' . $style; $db->setQuery($query); $db->execute(); // $query = 'UPDATE #__cck_core_searchs SET template_search = ' . $style . ', template_filter = ' . $style . ', template_list = ' . $style2 . ', template_item = ' . $style; $db->setQuery($query); $db->execute(); // Add Categories $categories = array(0 => array('title' => 'Users', 'published' => '1', 'access' => '2', 'language' => '*', 'parent_id' => 1, 'plg_name' => 'joomla_user'), 1 => array('title' => 'User Groups', 'published' => '1', 'access' => '2', 'language' => '*', 'parent_id' => 1, 'plg_name' => 'joomla_user_group')); JLoader::register('JTableCategory', JPATH_PLATFORM . '/joomla/database/table/category.php'); foreach ($categories as $category) { $table = JTable::getInstance('category'); $table->access = 2; $table->setLocation(1, 'last-child'); $table->bind($category); $rules = new JAccessRules('{"core.create":{"1":0},"core.delete":[],"core.edit":[],"core.edit.state":[],"core.edit.own":[]}'); $table->setRules($rules); $table->check(); $table->extension = 'com_content'; $table->path .= $table->alias; $table->language = '*'; $table->store(); $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('content'); $dispatcher->trigger('onContentBeforeSave', array('', &$table, true)); $table->store(); $dispatcher->trigger('onContentAfterSave', array('', &$table, true)); // $query = 'SELECT extension_id as id, params FROM #__extensions WHERE type="plugin" AND folder="cck_storage_location" AND element="' . $category['plg_name'] . '"'; $db->setQuery($query); $plugin = $db->loadObject(); $params = str_replace('"bridge_default-catid":"2"', '"bridge_default-catid":"' . $table->id . '"', $plugin->params); $query = 'UPDATE #__extensions SET params = "' . $db->escape($params) . '" WHERE extension_id = ' . (int) $plugin->id; $db->setQuery($query); $db->execute(); } // Init Default Author $res = JCckDatabase::loadResult('SELECT id FROM #__users ORDER BY id ASC'); $params = JComponentHelper::getParams('com_cck'); $params->set('integration_user_default_author', (int) $res); $db->setQuery('UPDATE #__extensions SET params = "' . $db->escape($params) . '" WHERE name = "com_cck"'); $db->execute(); // Init ACL require_once JPATH_ADMINISTRATOR . '/components/com_cck/helpers/helper_admin.php'; $pks = JCckDatabase::loadColumn('SELECT id FROM #__cck_core_folders ORDER BY lft'); if (count($pks)) { $rules = '{"core.create":[],"core.delete":[],"core.delete.own":[],"core.edit":[],"core.edit.state":[],"core.edit.own":[]}'; Helper_Admin::initACL(array('table' => 'folder', 'name' => 'folder', 'rules' => $rules), $pks); } $pks = JCckDatabase::loadColumn('SELECT id FROM #__cck_core_types ORDER BY id'); if (count($pks)) { $rules = '{"core.create":[],"core.create.max.parent":{"8":0},"core.create.max.parent.author":{"8":0},"core.create.max.author":{"8":0},' . '"core.delete":[],"core.delete.own":[],"core.edit":[],"core.edit.own":[]}'; $rules2 = array(8 => '{"core.create":{"1":1,"2":0},"core.create.max.parent":{"8":0},"core.create.max.parent.author":{"8":0},"core.create.max.author":{"8":0},' . '"core.delete":[],"core.delete.own":[],"core.edit":{"4":0},"core.edit.own":{"2":1}}'); Helper_Admin::initACL(array('table' => 'type', 'name' => 'form', 'rules' => $rules), $pks, $rules2); } } else { $new = $app->cck_core_version; $old = $app->cck_core_version_old; $root = JPATH_ADMINISTRATOR . '/components/com_cck'; require_once JPATH_ADMINISTRATOR . '/components/' . CCK_COM . '/helpers/helper_folder.php'; // ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** // $versions = array(0 => '2.0.0', 1 => '2.0.0.RC2', 2 => '2.0.0.RC2-1', 3 => '2.0.0.RC2-2', 4 => '2.0.0.RC2-3', 5 => '2.0.0.RC3', 6 => '2.0.0.RC4', 7 => '2.0.0.GA', 8 => '2.0.5', 9 => '2.0.6', 10 => '2.0.7', 11 => '2.1.0', 12 => '2.1.5', 13 => '2.2.0', 14 => '2.2.5', 15 => '2.3.0', 16 => '2.3.1', 17 => '2.3.5', 18 => '2.3.6', 19 => '2.3.7', 20 => '2.3.8', 21 => '2.3.9', 22 => '2.3.9.2', 23 => '2.4.5', 24 => '2.4.6', 25 => '2.4.7', 26 => '2.4.8', 27 => '2.4.8.5', 28 => '2.4.9', 29 => '2.4.9.1', 30 => '2.4.9.2', 31 => '2.4.9.5', 32 => '2.4.9.6', 33 => '2.4.9.7', 34 => '2.4.9.8', 35 => '2.5.0', 36 => '2.5.1', 37 => '2.5.2', 38 => '2.6.0', 39 => '2.7.0', 40 => '2.8.0', 41 => '2.9.0', 42 => '3.0.0', 43 => '3.0.1', 44 => '3.0.2', 45 => '3.0.3', 46 => '3.0.4', 47 => '3.0.5', 48 => '3.1.0', 49 => '3.1.1', 50 => '3.1.2', 51 => '3.1.3', 52 => '3.1.4', 53 => '3.1.5', 54 => '3.2.0', 55 => '3.2.1', 56 => '3.2.2', 57 => '3.3.0', 58 => '3.3.1', 59 => '3.3.2', 60 => '3.3.3', 61 => '3.3.4', 62 => '3.3.5', 63 => '3.3.6', 64 => '3.3.7', 65 => '3.3.8', 66 => '3.4.0', 67 => '3.4.1', 68 => '3.4.2', 69 => '3.4.3', 70 => '3.5.0', 71 => '3.5.1', 72 => '3.6.0', 73 => '3.6.1', 74 => '3.6.2', 75 => '3.6.3', 76 => '3.6.4', 77 => '3.6.5', 78 => '3.7.0', 79 => '3.7.1', 80 => '3.7.2', 81 => '3.7.3', 82 => '3.7.4', 83 => '3.7.5', 82 => '3.8.0'); // ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** ******** // $i = array_search($old, $versions); $i2 = $i; $n = array_search($new, $versions); if ($i < 7) { // ONLY < 2.0 GA $prefix = JFactory::getConfig()->get('dbprefix'); $tables = JCckDatabase::loadColumn('SHOW TABLES'); if (count($tables)) { foreach ($tables as $table) { if (strpos($table, $prefix . 'cck_item_') !== false) { $replace = str_replace($prefix . 'cck_item_', $prefix . 'cck_store_item_', $table); if ($replace) { JCckDatabase::doQuery('ALTER TABLE ' . $table . ' RENAME ' . $replace); } } elseif (strpos($table, $prefix . 'cck_type_') !== false) { $replace = str_replace($prefix . 'cck_type_', $prefix . 'cck_store_form_', $table); if ($replace) { JCckDatabase::doQuery('ALTER TABLE ' . $table . ' RENAME ' . $replace); } } } } $fields = JCckDatabase::loadObjectList('SELECT id, storage_table FROM #__cck_core_fields WHERE storage_table LIKE "#__cck_item_%"'); if (count($fields)) { foreach ($fields as $field) { $replace = str_replace('#__cck_item_', '#__cck_store_item_', $field->storage_table); JCckDatabase::doQuery('UPDATE #__cck_core_fields SET storage_table = "' . $replace . '" WHERE id = ' . (int) $field->id); } } $fields = JCckDatabase::loadObjectList('SELECT id, storage_table FROM #__cck_core_fields WHERE storage_table LIKE "#__cck_type_%"'); if (count($fields)) { foreach ($fields as $field) { $replace = str_replace('#__cck_type_', '#__cck_store_form_', $field->storage_table); JCckDatabase::doQuery('UPDATE #__cck_core_fields SET storage_table = "' . $replace . '" WHERE id = ' . (int) $field->id); } } $fields = JCckDatabase::loadObjectList('SELECT id, options2 FROM #__cck_core_fields WHERE type = "select_dynamic"'); if (count($fields)) { foreach ($fields as $field) { $options2 = $field->options2; if (strpos($options2, '#__cck_item_') !== false) { $options2 = str_replace('#__cck_item_', '#__cck_store_item_', $options2); } if (strpos($options2, '#__cck_type_') !== false) { $options2 = str_replace('#__cck_type_', '#__cck_store_form_', $options2); } if ($options2 != $field->options2) { JCckDatabase::doQuery('UPDATE #__cck_core_fields SET options2 = "' . $db->escape($options2) . '" WHERE id = ' . (int) $field->id); } } } } if ($i < 23) { // ONLY < 2.4.5 JCckDatabase::doQuery('ALTER TABLE #__cck_core_folders ADD path VARCHAR( 1024 ) NOT NULL AFTER parent_id;'); require_once JPATH_ADMINISTRATOR . '/components/' . CCK_COM . '/helpers/helper_folder.php'; $folders = JCckDatabase::loadColumn('SELECT id FROM #__cck_core_folders WHERE lft ORDER BY lft'); foreach ($folders as $f) { $path = Helper_Folder::getPath($f, '/'); JCckDatabase::doQuery('UPDATE #__cck_core_folders SET path = "' . $path . '" WHERE id = ' . (int) $f); } if (JCckDatabase::doQuery('INSERT IGNORE #__cck_core_folders (id) VALUES (29)')) { require_once JPATH_ADMINISTRATOR . '/components/' . CCK_COM . '/tables/folder.php'; $folder = JTable::getInstance('folder', 'CCK_Table'); $folder->load(29); $folder_data = array('parent_id' => 13, 'path' => 'joomla/user/profile', 'title' => 'Profile', 'name' => 'profile', 'color' => '#0090d1', 'introchar' => 'U.', 'colorchar' => '#ffffff', 'elements' => 'field', 'featured' => 0, 'published' => 1); $rules = new JAccessRules('{"core.create":[],"core.delete":[],"core.edit":[],"core.edit.state":[],"core.edit.own":[]}'); $folder->setRules($rules); $folder->bind($folder_data); $folder->store(); } } for ($i = $i + 1; $i <= $n; $i++) { $file = $root . '/install/upgrades/' . strtolower($versions[$i]) . '.sql'; if (JFile::exists($file)) { $buffer = file_get_contents($file); $queries = JInstallerHelper::splitSql($buffer); foreach ($queries as $query) { $query = trim($query); if ($query != '' && $query[0] != '#') { $db->setQuery($query); $db->execute(); } } } } if ($i2 < 23) { // ONLY < 2.4.5 $bool = true; $live = JCckDatabase::loadObjectList('SELECT typeid, fieldid, client, live, live_value FROM #__cck_core_type_field WHERE live IN ("url_var_int","url_var_string","user_profile")'); if (count($live)) { foreach ($live as $l) { if ($l->live == 'user_profile') { $live_type = 'joomla_user'; $live_options = '{"content":"","property":"' . $l->live_value . '"}'; } elseif ($l->live == 'url_var_int') { $live_type = 'url_variable'; $live_options = '{"variable":"' . $l->live_value . '","type":"int"}'; } elseif ($l->live == 'url_var_string') { $live_type = 'url_variable'; $live_options = '{"variable":"' . $l->live_value . '","type":"string"}'; } if (!JCckDatabase::doQuery('UPDATE #__cck_core_type_field SET live = "' . $live_type . '", live_options = "' . $db->escape($live_options) . '" WHERE typeid = ' . $l->typeid . ' AND fieldid = ' . $l->fieldid . ' AND client = "' . $l->client . '"')) { $bool = false; } } } $live = JCckDatabase::loadObjectList('SELECT searchid, fieldid, client, live, live_value FROM #__cck_core_search_field WHERE live IN ("url_var_int","url_var_string","user_profile")'); if (count($live)) { foreach ($live as $l) { if ($l->live == 'user_profile') { $live_type = 'joomla_user'; $live_options = '{"content":"","property":"' . $l->live_value . '"}'; } elseif ($l->live == 'url_var_int') { $live_type = 'url_variable'; $live_options = '{"variable":"' . $l->live_value . '","type":"int"}'; } elseif ($l->live == 'url_var_string') { $live_type = 'url_variable'; $live_options = '{"variable":"' . $l->live_value . '","type":"string"}'; } if (!JCckDatabase::doQuery('UPDATE #__cck_core_search_field SET live = "' . $live_type . '", live_options = "' . $db->escape($live_options) . '" WHERE searchid = ' . $l->searchid . ' AND fieldid = ' . $l->fieldid . ' AND client = "' . $l->client . '"')) { $bool = false; } } } if ($bool) { JCckDatabase::doQuery('UPDATE #__extensions SET enabled = 0 WHERE element IN ("url_var_int","url_var_string","user_profile") AND folder = "cck_field_live"'); } } if ($i2 < 25) { $table = JTable::getInstance('asset'); $table->loadByName('com_cck'); if ($table->rules) { $rules = (array) json_decode($table->rules); $rules['core.delete.own'] = array(6 => "1"); $table->rules = json_encode($rules); $table->store(); } } if ($i2 < 31) { $src = JPATH_ADMINISTRATOR . '/components/com_cck/install/src/tmp/joomla_message'; if (JFolder::exists($src)) { JFolder::copy($src, JPATH_SITE . '/plugins/cck_storage_location/joomla_message', '', true); } } if ($i2 < 33) { $folders = array(10, 11, 12, 13, 14); foreach ($folders as $folder) { Helper_Folder::rebuildBranch($folder); } } if ($i2 < 35) { $objects = array('joomla_article' => 'article', 'joomla_category' => 'category', 'joomla_user' => 'user', 'joomla_user_group' => 'user_group'); foreach ($objects as $k => $v) { $params = JCckDatabase::loadResult('SELECT options FROM #__cck_core_objects WHERE name = "' . $k . '"'); $params = json_decode($params); $params->default_type = JCck::getConfig_Param('integration_' . $v, ''); $params->add_redirect = $params->default_type != '' ? '1' : '0'; $params->edit = JCck::getConfig_Param('integration_' . $v . '_edit', '0'); if ($k == 'joomla_category') { $params->exclude = JCck::getConfig_Param('integration_' . $v . '_exclude', ''); } JCckDatabase::doQuery('UPDATE #__cck_core_objects SET options = "' . $db->escape(json_encode($params)) . '" WHERE name = "' . $k . '"'); } } if ($i2 < 45) { $table = '#__cck_store_item_users'; $columns = $db->getTableColumns($table); if (isset($columns['password2'])) { JCckDatabase::doQuery('ALTER TABLE ' . JCckDatabase::quoteName($table) . ' DROP ' . JCckDatabase::quoteName('password2')); } } if ($i2 < 66) { $path = JPATH_ADMINISTRATOR . '/components/com_cck/download.php'; if (JFile::exists($path)) { JFile::delete($path); } } if ($i2 < 70) { $plg_image = JPluginHelper::getPlugin('cck_field', 'upload_image'); $plg_params = new JRegistry($plg_image->params); $com_cck = JComponentHelper::getComponent('com_cck'); $com_cck->params->set('media_quality_jpeg', $plg_params->get('quality_jpeg', '90')); $com_cck->params->set('media_quality_png', $plg_params->get('quality_png', '3')); JCckDatabase::doQuery('UPDATE #__extensions SET params = "' . $db->escape($com_cck->params->toString()) . '" WHERE type = "component" AND element = "com_cck"'); } // Folder Tree Helper_Folder::rebuildTree(2, 1); } // Overrides $path = JPATH_ADMINISTRATOR . '/components/com_cck/install/src'; if (JFolder::exists($path)) { $folders = JFolder::folders($path, '^joomla'); $folders = array_reverse($folders); $count = count($folders); foreach ($folders as $folder) { $version = str_replace('joomla', '', $folder); if (version_compare(JVERSION, $version, 'lt')) { $path .= '/' . $folder; $len = strlen($path); $items = JFolder::files($path, '.', true, true, array('index.html')); if (count($items)) { foreach ($items as $item) { $dest = JPATH_SITE . substr($item, $len); JFile::copy($item, $dest); } } break; } } } // Tmp $path = JPATH_ADMINISTRATOR . '/components/com_cck/install/src/tmp'; if (JFolder::exists($path)) { JFolder::delete($path); } }
$columns = array('' => '- ' . JText::_('COM_CCK_SELECT') . ' -', 'bool' => 'bool', 'bool2' => 'bool2', 'bool3' => 'bool3', 'bool4' => 'bool4', 'bool5' => 'bool5', 'bool6' => 'bool6', 'bool7' => 'bool7', 'json[options2][...]' => 'options2'); } else { $desc = JText::_('COM_CCK_SELECT_TO_MAP_EXISTING_COLUMN'); $location = $this->item->title; $prefix = $app->getCfg('dbprefix'); if (strpos($location, '#__') !== false || strpos($location, $prefix) !== false) { $properties = array('table' => str_replace($prefix, '#__', $location)); } else { $properties = array('table'); if ($location != '') { require_once JPATH_SITE . '/plugins/cck_storage_location/' . $location . '/' . $location . '.php'; $properties = JCck::callFunc('plgCCK_Storage_Location' . $location, 'getStaticProperties', $properties); } } if (isset($properties['table']) && $properties['table'] != '') { $columns = JCckDatabase::loadColumn('SHOW COLUMNS FROM ' . $properties['table']); if (count($columns)) { natsort($columns); $columns = array_combine($columns, $columns); } $columns = array_merge(array('' => '- ' . JText::_('COM_CCK_SELECT') . ' -'), $columns); } else { $columns = array('' => '- ' . JText::_('COM_CCK_SELECT') . ' -'); } } $field = new stdClass(); $field->type = 'select_simple'; $form = JHtml::_('select.genericlist', $columns, 'map', 'size="1" class="inputbox select" style="max-width:175px;"', 'value', 'text', '', 'map'); } else { $desc = ''; $field = JCckDatabase::loadObject('SELECT * FROM #__cck_core_fields WHERE name = "' . $this->item->name . '"');
public static function getFields($element, $item, $featured = '', $exclusion = false, $force = false, $pos = '') { jimport('cck.construction.field.generic_more'); $table = $element . '_field'; if (!isset($item->id)) { $fields = array(); if ($featured != '') { $where = 'WHERE ' . $featured . ' AND a.storage != "dev" AND ( a.storage_table NOT LIKE "#__cck_store_form_%" )'; $fields = JCckDatabase::loadObjectList('SELECT DISTINCT a.id, a.title, a.name, a.folder, a.type, a.label FROM #__cck_core_fields AS a ' . $where . ' ORDER BY a.ordering ASC'); if (count($fields)) { $list = array(); foreach ($fields as $f) { $f->position = $pos; $list[$pos][] = $f; } $fields = $list; } } return $fields; } if ($exclusion !== false) { $query = 'SELECT a.fieldid FROM #__cck_core_' . $table . ' AS a WHERE a.' . $element . 'id = ' . (int) $item->id . ' AND a.client = "' . $item->client . '"'; $fields = JCckDatabase::loadColumn($query); if (!is_array($fields)) { return ''; } $fields = implode(',', $fields); } else { $and = $force === true ? ' ' . $featured : ''; $query = ' SELECT DISTINCT a.id, a.title, a.name, a.folder, a.type, a.label, c.client, ' . plgCCK_FieldGeneric_More::gm_getConstruction_Columns($table, '_get') . ' FROM #__cck_core_fields AS a ' . ' LEFT JOIN #__cck_core_' . $table . ' AS c ON c.fieldid = a.id' . ' WHERE c.' . $element . 'id = ' . (int) $item->id . ' AND c.client = "' . $item->client . '"' . $and . ' ORDER BY c.ordering ASC'; $fields = JCckDatabase::loadObjectListArray($query, 'position'); if (!$fields) { return array(); } } return $fields; }
public function onAfterInitialise() { $app = JFactory::getApplication(); if ($app->isSite()) { $router = JCck::on('3.3') ? $app::getRouter() : $app->getRouter(); $router->attachBuildRule(array($this, 'buildRule')); } elseif ($app->isAdmin() && $app->input->get('option') == 'com_config' && strpos($app->input->get('component'), 'com_cck') !== false) { JFactory::getLanguage()->load('com_cck_core'); } if ($this->multisite !== true) { return; } $user = JFactory::getUser(); if ($user->get('id') > 0 && @$user->guest != 1) { if ($app->isSite()) { $this->_setHomepage($this->site_cfg->get('homepage', 0)); $style = $this->site_cfg->get('template_style', ''); if ($style != '') { $this->site_cfg->set('set_template_style', true); $this->_setTemplateStyle($style); } } if (isset($user->cck_multisite)) { return; } if (!$this->site) { JFactory::getSession()->set('user', JFactory::getUser($user->get('id'))); return; } // Groups $authgroups = $user->getAuthorisedGroups(); $nogroups = JCckDatabase::loadColumn('SELECT groups FROM #__cck_core_sites WHERE id != ' . $this->site->id); $nogroups = is_null($nogroups) ? '' : ',' . implode(',', $nogroups) . ','; $multisite = false; foreach ($user->groups as $g) { if (strpos($nogroups, ',' . $g . ',') !== false) { $multisite = true; break; } } // Viewlevels $authlevels = $user->getAuthorisedViewLevels(); $nolevels = JCckDatabase::loadColumn('SELECT viewlevels FROM #__cck_core_sites WHERE id != ' . $this->site->id); $nolevels = is_null($nolevels) ? array() : explode(',', implode(',', $nolevels)); if ($multisite) { $viewlevels = array_diff($authlevels, $nolevels); } else { $viewlevels = $authlevels; } if ($app->isAdmin() && $this->site->guest_only_viewlevel > 0) { $viewlevels[] = $this->site->guest_only_viewlevel; } if (count(array_diff($authlevels, $viewlevels)) || count(array_diff($viewlevels, $authlevels))) { jimport('cck.joomla.user.user'); $shadow = new CCKUser($user->get('id')); $shadow->setAuthorisedViewLevels($viewlevels); $shadow->makeHimLive(); } } else { if ($app->isAdmin()) { return; } $session = JFactory::getSession(); $session->set('user', JFactory::getUser(0)); if (!$this->site) { return; } $user = new JUser($this->site->guest); $user->guest = 1; $session->set('user', $user); $this->_setHomepage($this->site_cfg->get('homepage', 0)); $style = $this->site_cfg->get('template_style', ''); if ($style != '') { $this->site_cfg->set('set_template_style', true); $this->_setTemplateStyle($style); } } }