コード例 #1
0
ファイル: JTableNestedTest.php プロジェクト: raquelsa/Joomla
 /**
  * Tests JTableNested::isLeaf
  *
  * @return  void
  *
  * @since   11.3
  */
 public function testIsLeaf()
 {
     $this->assertFalse($this->object->isLeaf(1), 'Root node is not a leaf');
     $this->assertFalse($this->object->isLeaf(23), 'Templates node is not a leaf');
     $this->assertFalse($this->object->isLeaf(-1), 'Invalid node is not a leaf');
     $this->assertTrue($this->object->isLeaf(25), 'Plugins is a leaf');
 }
コード例 #2
0
ファイル: category.php プロジェクト: Glonum/tz_portfolio
 /**
  * Method to delete a node and, optionally, its child nodes from the table.
  *
  * @param   integer  $pk        The primary key of the node to delete.
  * @param   boolean  $children  True to delete child nodes, false to move them up a level.
  *
  * @return  boolean  True on success.
  *
  * @see     http://docs.joomla.org/JTableNested/delete
  * @since   2.5
  */
 public function delete($pk = null, $children = false)
 {
     if ($pk) {
         $query = 'DELETE FROM #__tz_portfolio_categories' . ' WHERE catid = ' . $pk;
         $db = JFactory::getDbo();
         $db->setQuery($query);
         if (!$db->query()) {
             var_dump($db->getErrorMsg());
             return false;
         }
     }
     return parent::delete($pk, $children);
 }
コード例 #3
0
ファイル: categoryClass.php プロジェクト: madseller/coperio
 function store()
 {
     $success = parent::store();
     if (!JVersion::isCompatible("1.6.0")) {
         if (isset($this->_catextra)) {
             $this->_catextra->id = $this->id;
             $this->_catextra->store();
         }
     }
     if ($success) {
         JPluginHelper::importPlugin("jevents");
         $dispatcher =& JDispatcher::getInstance();
         $set = $dispatcher->trigger('afterSaveCategory', array($this));
     }
     return $success;
 }
コード例 #4
0
ファイル: categoryClass.php プロジェクト: hriggs/cs-website
 function store($updateNulls = false)
 {
     $success = parent::store();
     if ($success) {
         JPluginHelper::importPlugin("jevents");
         $dispatcher = JEventDispatcher::getInstance();
         $set = $dispatcher->trigger('afterSaveCategory', array($this));
         /*			
         			$table = JTable::getInstance('Category', 'JTable', array('dbo' => JFactory::getDbo()));
         			if (!$table->rebuild())
         			{
         				throw new Exception( $table->getError(), 500);
         			}
         */
     }
     return $success;
 }
コード例 #5
0
ファイル: category.php プロジェクト: RuDers/JoomlaSQL
 /**
  * Method to delete a node and, optionally, its child nodes from the table.
  *
  * @param   integer  $pk        The primary key of the node to delete.
  * @param   boolean  $children  True to delete child nodes, false to move them up a level.
  *
  * @return  boolean  True on success.
  *
  * @see     http://docs.joomla.org/JTableNested/delete
  * @since   2.5
  */
 public function delete($pk = null, $children = false)
 {
     return parent::delete($pk, $children);
 }
コード例 #6
0
 public function createCategories($cats)
 {
     $tables = array();
     foreach ($cats as $key => $category) {
         //$this->out("Category Object --> " . print_r($category,true));
         $k2_catid = $category->id;
         $table[$k2_catid] = JTableCategory::getInstance('category', 'JTable');
         $nulldate = JFactory::getDbo()->getNullDate();
         $params = json_decode($category->params);
         //$this->out(print_r($params,true));
         $table[$k2_catid]->id = 0;
         if ($category->extraFieldsGroup == 1) {
             $table[$k2_catid]->extension = 'com_akrecipes';
             $this->recipe_catids = $this->recipe_catids . ', ' . $category->id;
         } else {
             $table[$k2_catid]->extension = 'com_content';
             $this->article_catids = $this->article_catids . ', ' . $category->id;
         }
         $table[$k2_catid]->title = $category->name;
         $table[$k2_catid]->alias = $category->alias;
         $table[$k2_catid]->description = $category->description;
         $table[$k2_catid]->published = $category->published;
         $table[$k2_catid]->language = $category->language;
         $table[$k2_catid]->version = 1;
         $table[$k2_catid]->params = '{"category_layout":"","image":""}';
         $table[$k2_catid]->metadata = '{"author":"","robots":""}';
         $table[$k2_catid]->metadesc = $params->catMetaDesc;
         $table[$k2_catid]->checked_out_time = $nulldate;
         $table[$k2_catid]->setLocation(1, 'last-child');
         if (!$table[$k2_catid]->check()) {
             $this->out("Error in table" . $table[$k2_catid]->getError());
             return false;
         }
         if (!$table[$k2_catid]->store()) {
             $this->out("Error in table" . $table[$k2_catid]->getError());
             return false;
         }
         if (!$table[$k2_catid]->checkin()) {
             $this->out("Error in table" . $table[$k2_catid]->getError());
             return false;
         }
         $primary_keys = $table[$k2_catid]->getPrimaryKey();
         $this->out("Primary Key Object --> " . print_r($primary_keys, true));
         $this->categories[$category->id] = $primary_keys['id'];
         if ($category->extraFieldsGroup == 1) {
             $this->recipe_category_map[$k2_catid] = $primary_keys['id'];
         } else {
             $this->article_category_map[$k2_catid] = $primary_keys['id'];
         }
     }
     foreach ($cats as $key => $category) {
         $k2_catid = $category->id;
         $k2_parentid = $category->parent;
         if (isset($k2_parentid) && $k2_parentid != 0) {
             $new_parentid = $this->categories[$k2_parentid];
             $table[$k2_catid]->moveByReference($new_parentid, 'last-child');
         }
     }
 }
コード例 #7
0
 /**
  * Make a #__faq_categories entry
  *
  * @param   object  $tbl
  * @return  integer
  */
 public function section($tbl)
 {
     $category = new \JTableCategory($this->db);
     $category->title = $tbl->title;
     $category->alias = $tbl->alias;
     $category->description = $tbl->description;
     $category->state = $tbl->published;
     $category->access = $tbl->access;
     $category->section = $tbl->parent_id;
     $category->store();
     return $category->id;
 }
コード例 #8
0
ファイル: category.php プロジェクト: kaantunc/MYK-BOR
 function mosCategory(&$db)
 {
     parent::__construct($db);
 }
コード例 #9
0
 /**
  * method to install the component
  *
  * @return void
  */
 function install($parent)
 {
     //Create category
     require_once JPATH_SITE . DS . 'libraries' . DS . 'joomla' . DS . 'database' . DS . 'table' . DS . 'category.php';
     $db = JFactory::getDbo();
     $user = JFactory::getUser();
     $category = array();
     $category['parent_id'] = '1';
     $category['extension'] = "com_smarticons";
     $category['title'] = 'Standard';
     $category['published'] = '1';
     $category['access'] = '1';
     $category['level'] = '1';
     $category['description'] = "<p>Standard icons that come with every Joomla! installation.</p>";
     $category['language'] = "*";
     $category['created_user_id'] = $user->id;
     $categoryTable = new JTableCategory($db);
     $categoryTable->setLocation($category['parent_id'], 'last-child');
     $categoryTable->setRules('{"core.view":{"1":1},"core.delete":[],"core.edit":[],"core.edit.state":[]}');
     if ($categoryTable->save($category)) {
         //Get category ID
         $query = $db->getQuery(true);
         $query->select('id');
         $query->from('#__categories');
         $query->where('extension = \'com_smarticons\'');
         $query->where('title = \'Standard\'');
         $db->setQuery($query);
         if ($id = (int) $db->loadResult()) {
             echo '<p>' . JText::_('COM_SMARTICONS_INSTALLER_CATEGORY_ADDSUCCESS') . '</p>';
         } else {
             echo '<p>' . JText::_('COM_SMARTICONS_INSTALLER_CATEGORY_ADDFAIL') . '</p>';
         }
     } else {
         echo '<p>' . JText::_('COM_SMARTICONS_INSTALLER_CATEGORY_ADDFAIL') . '</p>';
     }
     //Create icons
     $icons = array();
     $icons[] = array('catid' => $id, 'Name' => 'MOD_QUICKICON_ADD_NEW_ARTICLE', 'Title' => 'MOD_QUICKICON_ADD_NEW_ARTICLE', 'Target' => 'index.php?option=com_content&task=article.add', 'Icon' => 'images/smarticons/icon-48-article-add.png', 'Display' => 1, 'published' => 1, 'ordering' => 1);
     $icons[] = array('catid' => $id, 'Name' => 'MOD_QUICKICON_ARTICLE_MANAGER', 'Title' => 'MOD_QUICKICON_ARTICLE_MANAGER', 'Target' => 'index.php?option=com_content', 'Icon' => 'images/smarticons/icon-48-article.png', 'Display' => 1, 'published' => 1, 'ordering' => 2);
     $icons[] = array('catid' => $id, 'Name' => 'MOD_QUICKICON_CATEGORY_MANAGER', 'Title' => 'MOD_QUICKICON_CATEGORY_MANAGER', 'Target' => 'index.php?option=com_categories&extension=com_content', 'Icon' => 'images/smarticons/icon-48-category.png', 'Display' => 1, 'published' => 1, 'ordering' => 3);
     $icons[] = array('catid' => $id, 'Name' => 'MOD_QUICKICON_MEDIA_MANAGER', 'Title' => 'MOD_QUICKICON_MEDIA_MANAGER', 'Target' => 'index.php?option=com_media', 'Icon' => 'images/smarticons/icon-48-media.png', 'Display' => 1, 'published' => 1, 'ordering' => 4);
     $icons[] = array('catid' => $id, 'Name' => 'MOD_QUICKICON_MENU_MANAGER', 'Title' => 'MOD_QUICKICON_MENU_MANAGER', 'Target' => 'index.php?option=com_menus', 'Icon' => 'images/smarticons/icon-48-menumgr.png', 'Display' => 1, 'published' => 1, 'ordering' => 5);
     $icons[] = array('catid' => $id, 'Name' => 'MOD_QUICKICON_USER_MANAGER', 'Title' => 'MOD_QUICKICON_USER_MANAGER', 'Target' => 'index.php?option=com_users', 'Icon' => 'images/smarticons/icon-48-user.png', 'Display' => 1, 'published' => 1, 'ordering' => 6);
     $icons[] = array('catid' => $id, 'Name' => 'MOD_QUICKICON_MODULE_MANAGER', 'Title' => 'MOD_QUICKICON_MODULE_MANAGER', 'Target' => 'index.php?option=com_modules', 'Icon' => 'images/smarticons/icon-48-module.png', 'Display' => 1, 'published' => 1, 'ordering' => 7);
     $icons[] = array('catid' => $id, 'Name' => 'MOD_QUICKICON_EXTENSION_MANAGER', 'Title' => 'MOD_QUICKICON_EXTENSION_MANAGER', 'Target' => 'index.php?option=com_installer', 'Icon' => 'images/smarticons/icon-48-extension.png', 'Display' => 1, 'published' => 1, 'ordering' => 8);
     $icons[] = array('catid' => $id, 'Name' => 'MOD_QUICKICON_LANGUAGE_MANAGER', 'Title' => 'MOD_QUICKICON_LANGUAGE_MANAGER', 'Target' => 'index.php?option=com_languages', 'Icon' => 'images/smarticons/icon-48-language.png', 'Display' => 1, 'published' => 1, 'ordering' => 9);
     $icons[] = array('catid' => $id, 'Name' => 'MOD_QUICKICON_GLOBAL_CONFIGURATION', 'Title' => 'MOD_QUICKICON_GLOBAL_CONFIGURATION', 'Target' => 'index.php?option=com_config', 'Icon' => 'images/smarticons/icon-48-config.png', 'Display' => 1, 'published' => 1, 'ordering' => 10);
     $icons[] = array('catid' => $id, 'Name' => 'MOD_QUICKICON_TEMPLATE_MANAGER', 'Title' => 'MOD_QUICKICON_TEMPLATE_MANAGER', 'Target' => 'index.php?option=com_templates', 'Icon' => 'images/smarticons/icon-48-themes.png', 'Display' => 1, 'published' => 1, 'ordering' => 11);
     $icons[] = array('catid' => $id, 'Name' => 'MOD_QUICKICON_PROFILE', 'Title' => 'MOD_QUICKICON_PROFILE', 'Target' => 'index.php?option=com_admin&task=profile.edit', 'Icon' => 'images/smarticons/icon-48-info.png', 'Display' => 1, 'published' => 1, 'ordering' => 12);
     require_once JPATH_BASE . DS . 'components' . DS . 'com_smarticons' . DS . 'tables' . DS . 'icon.php';
     $iconsSaved = 0;
     foreach ($icons as $icon) {
         $iconsTable = new SmartIconsTableIcon($db);
         $iconsTable->setRules('{"core.view":{"1":1},"core.delete":[],"core.edit":[],"core.edit.state":[]}');
         if ($iconsTable->save($icon)) {
             $iconsSaved++;
         }
     }
     echo '<p>' . JText::plural('COM_SMARTICONS_INSTALLER_N_ICONS_SAVED', $iconsSaved) . '</p>';
     //Copy images to image folder
     $sourceDir = JPATH_BASE . DS . 'components' . DS . 'com_smarticons' . DS . 'images';
     $targetDir = JPATH_SITE . DS . 'images' . DS . 'smarticons';
     if (!JFolder::exists($targetDir)) {
         if (JFolder::copy($sourceDir, $targetDir)) {
             JFolder::delete($sourceDir);
             echo '<p>' . JText::_('COM_SMARTICONS_INSTALLER_IMAGES_COPYSUCCESS') . '</p>';
         } else {
             echo '<p>' . JText::_('COM_SMARTICONS_INSTALLER_IMAGES_COPYFAIL') . '</p>';
         }
     } else {
         echo '<p>' . JText::_('COM_SMARTICONS_INSTALLER_IMAGES_EXISTS') . '</p>';
     }
     //Install module
     jimport('joomla.installer.installer');
     $modulePath = JPATH_BASE . DS . 'components' . DS . 'com_smarticons' . DS . 'module';
     $installer = new JInstaller();
     $installer->setOverwrite(true);
     if ($installer->install($modulePath)) {
         JFolder::delete($modulePath);
         echo '<p>' . JText::_('COM_SMARTICONS_INSTALLER_MODULE_INSTALL_SUCCESS') . '</p>';
     } else {
         echo '<p style="color:red">' . JText::_('COM_SMARTICONS_INSTALLER_MODULE_INSTALL_FAIL') . '</p>';
         echo nl2br($installer->message);
     }
     //Enable module
     $query = $db->getQuery(true);
     $query->select('id');
     $query->from('#__modules');
     $query->where('module = ' . $db->Quote('mod_smarticons'));
     $db->setQuery($query);
     if ($id = $db->loadResult()) {
         $query = $db->getQuery(true);
         $query->update('#__modules');
         $query->set('published = 1');
         $query->set('position = \'icon\'');
         $query->set('ordering = 1');
         $query->set('access = 3');
         $query->where('id = ' . $db->Quote($id));
         $db->setQuery($query);
         if ($db->query()) {
             $query = $db->getQuery(true);
             $query->insert('#__modules_menu');
             $query->set('moduleid = ' . $db->Quote($id));
             $query->set('menuid = 0');
             $db->setQuery($query);
             if ($db->query()) {
                 echo '<p>' . JText::_('COM_SMARTICONS_INSTALLER_MODULE_ENABLE_SUCCESS') . '</p>';
             } else {
                 echo '<p>' . JText::_('COM_SMARTICONS_INSTALLER_MODULE_ENABLE_FAIL') . '</p>';
             }
         } else {
             echo '<p>' . JText::_('COM_SMARTICONS_INSTALLER_MODULE_ENABLE_FAIL') . '</p>';
         }
     } else {
         echo '<p>' . JText::_('COM_SMARTICONS_INSTALLER_MODULE_ENABLE_FAIL') . '</p>';
     }
     //Disable mod_quickicons
     $query = $db->getQuery(true);
     $query->select('id');
     $query->from('#__modules');
     $query->where('module = ' . $db->Quote('mod_quickicon'));
     $db->setQuery($query);
     if ($id = $db->loadResult()) {
         $query = $db->getQuery(true);
         $query->update('#__modules');
         $query->set('published = 0');
         $query->where('id = ' . $db->Quote($id));
         $db->setQuery($query);
         if ($db->query()) {
             echo '<p>' . JText::_('COM_SMARTICONS_INSTALLER_QUICKICON_DISABLE_SUCCESS') . '</p>';
         } else {
             echo '<p>' . JText::_('COM_SMARTICONS_INSTALLER_QUICKICON_DISABLE_FAIL') . '</p>';
         }
     } else {
         echo '<p>' . JText::_('COM_SMARTICONS_INSTALLER_QUICKICON_DISABLE_FAIL') . '</p>';
     }
 }
コード例 #10
0
 /**
  * Up
  **/
 public function up()
 {
     // Create assets table (all of this will only run the first time the table is created)
     if (!$this->db->tableExists('#__assets')) {
         $query = "CREATE  TABLE IF NOT EXISTS `#__assets` (\n\t\t\t\t`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,\n\t\t\t\t`parent_id` INT(11) NOT NULL DEFAULT '0' ,\n\t\t\t\t`lft` INT(11) NOT NULL DEFAULT '0' ,\n\t\t\t\t`rgt` INT(11) NOT NULL DEFAULT '0' ,\n\t\t\t\t`level` INT(10) UNSIGNED NOT NULL ,\n\t\t\t\t`name` VARCHAR(50) NOT NULL ,\n\t\t\t\t`title` VARCHAR(100) NOT NULL ,\n\t\t\t\t`rules` VARCHAR(5120) NOT NULL ,\n\t\t\t\tPRIMARY KEY (`id`) ,\n\t\t\t\tUNIQUE INDEX `idx_asset_name` (`name` ASC) ,\n\t\t\t\tINDEX `idx_lft_rgt` (`lft` ASC, `rgt` ASC) ,\n\t\t\t\tINDEX `idx_parent_id` (`parent_id` ASC) )\n\t\t\tENGINE = MYISAM\n\t\t\tDEFAULT CHARACTER SET = utf8\n\t\t\tCOLLATE = utf8_general_ci;";
         $this->db->setQuery($query);
         $this->db->query();
         // Insert some default values
         $query = "INSERT INTO `#__assets` (`id`, `parent_id`, `lft`, `rgt`, `level`, `name`, `title`, `rules`)\n\t\t\tVALUES\n\t\t\t\t(1,0,0,0,0, 'root.1', 'Root Asset', '{\"core.login.site\":{\"1\":1,\"6\":1,\"2\":1},\"core.login.admin\":{\"6\":1},\"core.admin\":{\"8\":1},\"core.manage\":{\"7\":1},\"core.create\":{\"6\":1,\"3\":1},\"core.delete\":{\"6\":1},\"core.edit\":{\"6\":1,\"4\":1},\"core.edit.state\":{\"6\":1,\"5\":1},\"core.edit.own\":{\"6\":1,\"3\":1}}'),\n\t\t\t\t(2,1,0,0,1,'com_admin','com_admin','{}'),\n\t\t\t\t(3,1,0,0,1,'com_banners','com_banners','{\"core.admin\":{\"7\":1},\"core.manage\":{\"6\":1},\"core.create\":[],\"core.delete\":[],\"core.edit\":[],\"core.edit.state\":[]}'),\n\t\t\t\t(4,1,0,0,1,'com_cache','com_cache','{\"core.admin\":{\"7\":1},\"core.manage\":{\"7\":1}}'),\n\t\t\t\t(5,1,0,0,1,'com_checkin','com_checkin','{\"core.admin\":{\"7\":1},\"core.manage\":{\"7\":1}}'),\n\t\t\t\t(6,1,0,0,1,'com_config','com_config','{}'),\n\t\t\t\t(7,1,0,0,1,'com_contact','com_contact','{\"core.admin\":{\"7\":1},\"core.manage\":{\"6\":1},\"core.create\":[],\"core.delete\":[],\"core.edit\":[],\"core.edit.state\":[],\"core.edit.own\":[]}'),\n\t\t\t\t(8,1,0,0,1,'com_content','com_content','{\"core.admin\":{\"7\":1},\"core.manage\":{\"6\":1},\"core.create\":{\"3\":1},\"core.delete\":[],\"core.edit\":{\"4\":1},\"core.edit.state\":{\"5\":1},\"core.edit.own\":[]}'),\n\t\t\t\t(9,1,0,0,1,'com_cpanel','com_cpanel','{}'),\n\t\t\t\t(10,1,0,0,1,'com_installer','com_installer','{\"core.admin\":{\"7\":0},\"core.manage\":{\"7\":0},\"core.delete\":{\"7\":0},\"core.edit.state\":{\"7\":0}}'),\n\t\t\t\t(11,1,0,0,1,'com_languages','com_languages','{\"core.admin\":{\"7\":1},\"core.manage\":[],\"core.create\":[],\"core.delete\":[],\"core.edit\":[],\"core.edit.state\":[]}'),\n\t\t\t\t(12,1,0,0,1,'com_login','com_login','{}'),\n\t\t\t\t(13,1,0,0,1,'com_mailto','com_mailto','{}'),\n\t\t\t\t(14,1,0,0,1,'com_massmail','com_massmail','{}'),\n\t\t\t\t(15,1,0,0,1,'com_media','com_media','{\"core.admin\":{\"7\":1},\"core.manage\":{\"6\":1},\"core.create\":{\"3\":1},\"core.delete\":{\"5\":1}}'),\n\t\t\t\t(16,1,0,0,1,'com_menus','com_menus','{\"core.admin\":{\"7\":1},\"core.manage\":[],\"core.create\":[],\"core.delete\":[],\"core.edit\":[],\"core.edit.state\":[]}'),\n\t\t\t\t(17,1,0,0,1,'com_messages','com_messages','{\"core.admin\":{\"7\":1},\"core.manage\":{\"7\":1}}'),\n\t\t\t\t(18,1,0,0,1,'com_modules','com_modules','{\"core.admin\":{\"7\":1},\"core.manage\":[],\"core.create\":[],\"core.delete\":[],\"core.edit\":[],\"core.edit.state\":[]}'),\n\t\t\t\t(19,1,0,0,1,'com_newsfeeds','com_newsfeeds','{\"core.admin\":{\"7\":1},\"core.manage\":{\"6\":1},\"core.create\":[],\"core.delete\":[],\"core.edit\":[],\"core.edit.state\":[],\"core.edit.own\":[]}'),\n\t\t\t\t(20,1,0,0,1,'com_plugins','com_plugins','{\"core.admin\":{\"7\":1},\"core.manage\":[],\"core.edit\":[],\"core.edit.state\":[]}'),\n\t\t\t\t(21,1,0,0,1,'com_redirect','com_redirect','{\"core.admin\":{\"7\":1},\"core.manage\":[]}'),\n\t\t\t\t(22,1,0,0,1,'com_search','com_search','{\"core.admin\":{\"7\":1},\"core.manage\":{\"6\":1}}'),\n\t\t\t\t(23,1,0,0,1,'com_templates','com_templates','{\"core.admin\":{\"7\":1},\"core.manage\":[],\"core.create\":[],\"core.delete\":[],\"core.edit\":[],\"core.edit.state\":[]}'),\n\t\t\t\t(24,1,0,0,1,'com_users','com_users','{\"core.admin\":{\"7\":1},\"core.manage\":[],\"core.create\":[],\"core.delete\":[],\"core.edit\":[],\"core.edit.own\":{\"6\":1},\"core.edit.state\":[]}'),\n\t\t\t\t(25,1,0,0,1,'com_weblinks','com_weblinks','{\"core.admin\":{\"7\":1},\"core.manage\":{\"6\":1},\"core.create\":{\"3\":1},\"core.delete\":[],\"core.edit\":{\"4\":1},\"core.edit.state\":{\"5\":1},\"core.edit.own\":[]}'),\n\t\t\t\t(26,1,0,0,1,'com_wrapper','com_wrapper','{}');";
         $this->db->setQuery($query);
         $this->db->query();
         // Insert all components as assets (parent is 0 because we don't need more than 1 entry per component - i.e. no sub items used for menus in 1.5)
         $this->db->setQuery('SELECT * FROM `#__components` WHERE parent = 0');
         $components = $this->db->loadObjectList();
         if (count($components) > 0) {
             // Build default ruleset
             $defaulRules = array("core.admin" => array("7" => 1), "core.manage" => array("6" => 1), "core.create" => array(), "core.delete" => array(), "core.edit" => array(), "core.edit.state" => array());
             foreach ($components as $com) {
                 // Make sure it isn't already in there
                 $query = "SELECT id FROM `#__assets` WHERE `name` = " . $this->db->Quote($com->option);
                 $this->db->setQuery($query);
                 if ($this->db->loadResult()) {
                     continue;
                 }
                 // Craft query
                 $query = "INSERT INTO `#__assets` (`parent_id`, `lft`, `rgt`, `level`, `name`, `title`, `rules`) VALUES ";
                 $query .= "(";
                 $query .= '1,';
                 // parent_id 1 is the root asset
                 $query .= $this->db->Quote('') . ',';
                 // lft
                 $query .= $this->db->Quote('') . ',';
                 // rgt
                 $query .= '1,';
                 // level
                 $query .= $this->db->Quote($com->option) . ',';
                 // name
                 $query .= $this->db->Quote($com->option) . ',';
                 // title
                 $query .= $this->db->Quote(json_encode($defaulRules));
                 // rules
                 $query .= ");";
                 $this->db->setQuery($query);
                 $this->db->query();
             }
         }
         // Insert existing categories as assets (ignore root item)
         $this->db->setQuery('SELECT * FROM `#__categories` WHERE extension != "system"');
         $categories = $this->db->loadObjectList();
         if (count($categories) > 0) {
             foreach ($categories as $cat) {
                 // Make sure it isn't already in there
                 $query = "SELECT id FROM `#__assets` WHERE `name` = " . $this->db->Quote($cat->extension . '.category.' . $cat->id);
                 $this->db->setQuery($query);
                 if ($this->db->loadResult()) {
                     continue;
                 }
                 // Query for parent id
                 $query = "SELECT `id` FROM `#__assets` WHERE `name` = " . $this->db->Quote($cat->extension);
                 $this->db->setQuery($query);
                 $result = $this->db->loadResult();
                 if (!is_numeric($result)) {
                     // If we don't find the component entry, continue
                     continue;
                 }
                 $query = "INSERT INTO `#__assets` (`parent_id`, `lft`, `rgt`, `level`, `name`, `title`, `rules`) VALUES (";
                 $query .= $this->db->Quote($result) . ',';
                 // parent_id (from list entered above)
                 $query .= $this->db->Quote('') . ',';
                 // lft
                 $query .= $this->db->Quote('') . ',';
                 // rgt
                 $query .= $cat->level + 1 . ',';
                 // level
                 $query .= $this->db->Quote($cat->extension . '.category.' . $cat->id) . ',';
                 // name
                 $query .= $this->db->Quote($cat->extension) . ',';
                 // title
                 $query .= $this->db->Quote('{"core.create":[],"core.delete":[],"core.edit":[],"core.edit.state":[]}');
                 // rules
                 $query .= ");";
                 $this->db->setQuery($query);
                 $this->db->query();
                 // Now, update the categories table with the asset id
                 $id = $this->db->insertid();
                 $query = "UPDATE `#__categories` SET `asset_id` = {$id} WHERE `id` = {$cat->id};";
                 $this->db->setQuery($query);
                 $this->db->query();
             }
         }
         // Now, go back and set parent_id for categories that are level 2 (those were original 1.5 categories, i.e. below sections)
         $query = "SELECT * FROM `#__categories` WHERE level = 2";
         $this->db->setQuery($query);
         $results = $this->db->loadObjectList();
         if (count($results) > 0) {
             foreach ($results as $r) {
                 // Get the category id from the assets table
                 $query = "SELECT `id` FROM `#__assets` WHERE name = " . $this->db->Quote('com_content.category.' . $r->id);
                 $this->db->setQuery($query);
                 $id = $this->db->loadResult();
                 // Get the category parent id from the assets table
                 $query = "SELECT `id` FROM `#__assets` WHERE name = " . $this->db->Quote('com_content.category.' . $r->parent_id);
                 $this->db->setQuery($query);
                 $parent_id = $this->db->loadResult();
                 // Update the assets table
                 $query = "UPDATE `#__assets` SET parent_id = {$parent_id} WHERE `id` = {$id}";
                 $this->db->setQuery($query);
                 $this->db->query();
             }
         }
         // We're going to go ahead and add asset_id here, as we need to insert into below
         if (!$this->db->tableHasField('#__content', 'asset_id') && $this->db->tableHasField('#__content', 'id')) {
             $query = "ALTER TABLE `#__content` ADD COLUMN `asset_id` INTEGER UNSIGNED NOT NULL DEFAULT 0 COMMENT 'FK to the #_assets table.' AFTER `id`;";
             $this->db->setQuery($query);
             $this->db->query();
         }
         // Insert articles
         $this->db->setQuery('SELECT * FROM `#__content`');
         $articles = $this->db->loadObjectList();
         if (count($articles) > 0) {
             foreach ($articles as $art) {
                 // Query for parent ID
                 $query = "SELECT `id`, `level` FROM `#__assets` WHERE `name` = " . $this->db->Quote('com_content.category.' . $art->catid);
                 $this->db->setQuery($query);
                 $obj = $this->db->loadObject();
                 $level = is_object($obj) && is_numeric($obj->level) ? $obj->level + 1 : 4;
                 if (is_object($obj) && is_numeric($obj->id)) {
                     $result = $obj->id;
                 } else {
                     // We didn't find a parent id, so just use the 'uncategorised' category
                     $query = "SELECT `asset_id` FROM `#__categories` WHERE `extension` = 'com_content' AND `alias` = 'uncategorised';";
                     $this->db->setQuery($query);
                     if (!($result = $this->db->loadResult())) {
                         continue;
                     }
                 }
                 $query = "INSERT INTO `#__assets` (`parent_id`, `lft`, `rgt`, `level`, `name`, `title`, `rules`) VALUES (";
                 $query .= $this->db->Quote($result) . ',';
                 // parent_id
                 $query .= $this->db->Quote('') . ',';
                 // lft
                 $query .= $this->db->Quote('') . ',';
                 // rgt
                 $query .= $level . ',';
                 // level
                 $query .= $this->db->Quote('com_content.article.' . $art->id) . ',';
                 // name
                 $query .= $this->db->Quote($art->title) . ',';
                 // title
                 $query .= $this->db->Quote('{"core.delete":[],"core.edit":[],"core.edit.state":[]}');
                 // rules
                 $query .= ")";
                 $this->db->setQuery($query);
                 $this->db->query();
                 // Now, update the content table with the asset id
                 $id = $this->db->insertid();
                 $query = "UPDATE `#__content` SET `asset_id` = {$id} WHERE `id` = {$art->id};";
                 $this->db->setQuery($query);
                 $this->db->query();
             }
         }
         // Rule set for super admins only
         $rules = array("core.admin" => array("7" => 1), "core.manage" => array("7" => 1), "core.create" => array("7" => 1), "core.delete" => array("7" => 1), "core.edit" => array("7" => 1), "core.edit.state" => array("7" => 1));
         $this->db->setQuery("UPDATE `#__assets` SET rules='" . json_encode($rules) . "' WHERE NAME= 'com_mailto' OR NAME='com_massmail' OR NAME='com_config';");
         $this->db->query();
         // If we have the nested set class available, use it to rebuild lft/rgt
         if (class_exists('JTableNested') && method_exists('JTableNested', 'rebuild')) {
             // Rebuild categories
             // Use the MySQL driver for this
             $config = \JFactory::getConfig();
             $database = \JDatabase::getInstance(array('driver' => 'mysql', 'host' => $config->getValue('host'), 'user' => $config->getValue('user'), 'password' => $config->getValue('password'), 'database' => $config->getValue('db')));
             $table = new \JTableCategory($database);
             $table->rebuild();
             // Rebuild assets
             $this->rebuildAssets();
         }
     }
 }
コード例 #11
0
 public function testMoveByReference()
 {
     $table = $this->object;
     // Save original tree for future reference
     $treeOriginal = $table->getTree('1');
     // Check original tree for starting integrity
     $this->checkLftRgt($treeOriginal);
     //Move Modules category (22) to after Plugins (25)
     $this->assertTrue($table->moveByReference('25', 'after', '22'), 'Line: ' . __LINE__ . ' MovebyReference should succeed');
     $treeTemp = $table->getTree('1');
     $this->assertEquals(68, count($treeTemp), 'Line: ' . __LINE__ . ' Root tree should have 68 nodes');
     $this->checkLftRgt($treeTemp);
     $this->assertEquals('23', $treeTemp[9]->id, 'Line: ' . __LINE__ . ' id for element 9 should be 23');
     $this->assertEquals('69', $treeTemp[10]->id, 'Line: ' . __LINE__ . ' id for element 10 should be 69');
     $this->assertEquals('24', $treeTemp[14]->id, 'Line: ' . __LINE__ . ' id for element 14 should be 24');
     $this->assertEquals('25', $treeTemp[15]->id, 'Line: ' . __LINE__ . ' id for element 15 should be 25');
     $this->assertEquals('22', $treeTemp[16]->id, 'Line: ' . __LINE__ . ' id for element 16 should be 22');
     $this->assertEquals('25', $treeTemp[15]->id, 'Line: ' . __LINE__ . ' id for element 21 should be 25');
     // Move Modules category (22) back to before Templates (23)
     $this->assertTrue($table->moveByReference('23', 'before', '22'), 'Line: ' . __LINE__ . ' MovebyReference should succeed');
     $treeOriginalNew = $table->getTree('1');
     $this->assertEquals(68, count($treeOriginalNew), 'Line: ' . __LINE__ . ' Root tree should have 68 nodes');
     $this->compareTrees($treeOriginal, $treeOriginalNew);
     // Move Templates (23) to first child under Menu Module (75)
     $this->assertTrue($table->moveByReference('75', 'first-child', '23'), 'Line: ' . __LINE__ . ' MovebyReference should succeed');
     $treeTemp = $table->getTree('1');
     $this->checkLftRgt($treeTemp);
     $this->assertEquals('23', $treeTemp[15]->id, 'Line: ' . __LINE__ . ' id for element 15 should be 23');
     $this->assertEquals(6, $treeTemp[15]->level, 'Line: ' . __LINE__ . ' level for element 15 should be 6');
     $this->assertEquals('75', $treeTemp[15]->parent_id, 'Line: ' . __LINE__ . ' parent_id for element 15 should be 75');
     $this->assertEquals('69', $treeTemp[16]->id, 'Line: ' . __LINE__ . ' id for element 16 should be 69');
     $this->assertEquals(7, $treeTemp[16]->level, 'Line: ' . __LINE__ . ' level for element 16 should be 7');
     $this->assertEquals('23', $treeTemp[16]->parent_id, 'Line: ' . __LINE__ . ' parent_id for element 16 should be 23');
     // Move Templates (23) back to original position - after Modules (22)
     $this->assertTrue($table->moveByReference('22', 'after', '23'), 'Line: ' . __LINE__ . ' MovebyReference should succeed');
     $treeOriginalNew = $table->getTree('1');
     $this->assertEquals(68, count($treeOriginalNew), 'Line: ' . __LINE__ . ' Root tree should have 68 nodes');
     $this->compareTrees($treeOriginal, $treeOriginalNew);
     // Move Components (21) to be last-child of Extensions (20)
     $this->assertTrue($table->moveByReference('20', 'last-child', '21'), 'Line: ' . __LINE__ . ' MovebyReference should succeed');
     $treeTemp = $table->getTree('1');
     $this->assertEquals(68, count($treeTemp), 'Line: ' . __LINE__ . ' Root tree should have 68 nodes');
     $this->checkLftRgt($treeTemp);
     $this->assertEquals('22', $treeTemp[8]->id, 'Line: ' . __LINE__ . ' id for element 8 should be 22');
     $this->assertEquals('21', $treeTemp[21]->id, 'Line: ' . __LINE__ . ' id for element 21 should be 21');
     // Move Components (21) back to first-child of Extensions (20)
     $this->assertTrue($table->moveByReference('20', 'first-child', '21'), 'Line: ' . __LINE__ . ' MovebyReference should succeed');
     $treeOriginalNew = $table->getTree('1');
     $this->assertEquals(68, count($treeOriginalNew), 'Line: ' . __LINE__ . ' Root tree should have 68 nodes');
     $this->compareTrees($treeOriginal, $treeOriginalNew);
     // Try to move Modules (22) to first-child of User Modules (65)
     // Should be invalid since 65 is child of 22
     $this->assertFalse($table->moveByReference('65', 'first-child', '22'), 'Line: ' . __LINE__ . ' MovebyReference should fail');
     // Move Sample Data Articles (14) to before Sample Data Weblinks (18)
     $this->assertTrue($table->moveByReference('18', 'before', '14'), 'Line: ' . __LINE__ . ' MovebyReference should succeed');
     $treeTemp = $table->getTree('1');
     $this->assertEquals(68, count($treeTemp), 'Line: ' . __LINE__ . ' Root tree should have 68 nodes');
     $this->checkLftRgt($treeTemp);
     $this->assertEquals('14', $treeTemp[1]->id, 'Line: ' . __LINE__ . ' id for element 1 should be 14');
     $this->assertEquals('19', $treeTemp[2]->id, 'Line: ' . __LINE__ . ' id for element 2 should be 19');
     $this->assertEquals('18', $treeTemp[26]->id, 'Line: ' . __LINE__ . ' id for element 26 should be 18');
     $this->assertEquals('31', $treeTemp[27]->id, 'Line: ' . __LINE__ . ' id for element 27 should be 31');
     // Move Sample Data Weblinks (18) to be first-child of ROOT (1)
     // Should put it back to original state
     $this->assertTrue($table->moveByReference('1', 'first-child', '18'), 'Line: ' . __LINE__ . ' MovebyReference should succeed');
     $treeOriginalNew = $table->getTree('1');
     $this->assertEquals(68, count($treeOriginalNew), 'Root tree should have 68 nodes');
     $this->compareTrees($treeOriginal, $treeOriginalNew);
     // Move with blank reference id
     // Default behavior is to move the node to the last child of the root node (ignores the position parameter)
     $this->assertTrue($table->moveByReference('', 'before', '18'), 'Line: ' . __LINE__ . ' MovebyReference should succeed');
     $treeTemp = $table->getTree('1');
     $this->assertEquals(68, count($treeTemp), 'Line: ' . __LINE__ . ' Root tree should have 68 nodes');
     $this->checkLftRgt($treeTemp);
     $this->assertEquals('14', $treeTemp[1]->id, 'Line: ' . __LINE__ . ' id for element 1 should be 14');
     $this->assertEquals('19', $treeTemp[2]->id, 'Line: ' . __LINE__ . ' id for element 2 should be 19');
     $this->assertEquals('18', $treeTemp[64]->id, 'Line: ' . __LINE__ . ' id for element 26 should be 18');
     $this->assertEquals('31', $treeTemp[65]->id, 'Line: ' . __LINE__ . ' id for element 27 should be 31');
     // Call with no id should return false
     $this->assertFalse($table->moveByReference('', 'first-child', ''), 'Line: ' . __LINE__ . ' MovebyReference should fail');
     // Can set id with load method
     $table->load('18');
     // Move Sample Data Weblinks back to first-child under Root
     $this->assertTrue($table->moveByReference('1', 'first-child'), 'Line: ' . __LINE__ . ' MovebyReference should succeed');
     $treeOriginalNew = $table->getTree('1');
     $this->assertEquals(68, count($treeOriginalNew), 'Line: ' . __LINE__ . ' Root tree should have 68 nodes');
     $this->compareTrees($treeOriginal, $treeOriginalNew);
     // Test db error
     $badTable = new JTableCategory($this->badDB);
     $this->assertFalse($badTable->moveByReference('1', 'first-child'), 'Line: ' . __LINE__ . ' Should fail with db error');
 }
コード例 #12
0
ファイル: jed.php プロジェクト: richardje/je
 protected function getCategory($params)
 {
     $breadcrumbs = $params->get('data.breadcrumbs');
     $breadcrumbs = preg_replace('#^\\s*<a[^>]*>.*?</a>\\s*<img[^>]*>\\s*#is', '', $breadcrumbs);
     $breadcrumbs = preg_replace('#\\s*<img[^>]*>\\s*$#is', '', $breadcrumbs);
     $breadcrumbs = preg_replace('#\\s*<img[^>]*>\\s*#is', '|', $breadcrumbs);
     $breadcrumbs = strip_tags($breadcrumbs);
     $breadcrumbs = htmlspecialchars_decode($breadcrumbs);
     $breadcrumbs = explode('|', $breadcrumbs);
     $db = JFactory::getDbo();
     $parentId = 1;
     $depth = $params->get('depth');
     foreach ($breadcrumbs as $title) {
         $depth++;
         $alias = JApplication::stringURLSafe($title);
         $table = new JTableCategory($db);
         $table->load(array('alias' => $alias, 'extension' => 'com_jed'));
         if (empty($table->id)) {
             $table->title = $title;
             $table->alias = $alias;
             $table->description = $this->params->get("data.{$depth}", '');
             $table->extension = 'com_jed';
             $table->published = 1;
             $table->access = 1;
             $table->created_user_id = 42;
             $table->language = '*';
             $table->setLocation($parentId, 'last-child');
             // Store the data.
             if (!$table->store()) {
                 $this->setError($table->getError());
                 return false;
             }
             // Rebuild the path for the category:
             if (!$table->rebuildPath($table->id)) {
                 $this->setError($table->getError());
                 return false;
             }
             // Rebuild the paths of the category's children:
             if (!$table->rebuild($table->id, $table->lft, $table->level, $table->path)) {
                 $this->setError($table->getError());
                 return false;
             }
         } else {
             if ($this->params->get("data.{$depth}", '') != '') {
                 $table->description = $this->params->get("data.{$depth}", '');
                 $table->store();
             }
         }
         $parentId = $table->id;
     }
     return $parentId;
 }
コード例 #13
0
 public function save($xmlData)
 {
     //Create category
     require_once JPATH_SITE . DS . 'libraries' . DS . 'joomla' . DS . 'database' . DS . 'table' . DS . 'category.php';
     $db =& JFactory::getDbo();
     $user =& JFactory::getUser();
     foreach ($xmlData->children() as $xmlCategory) {
         //Check to see if the category is already in the database
         //Get category ID
         $query = $db->getQuery(true);
         $query->select('id');
         $query->from("#__categories");
         $query->where("extension = 'com_smarticons'");
         $query->where("title = " . $db->quote($xmlCategory->title));
         $db->setQuery($query);
         $categoryId = (int) $db->loadResult();
         //If no result was found, create the category
         if ($categoryId == 0) {
             $category = array();
             $category['parent_id'] = '1';
             $category['extension'] = "com_smarticons";
             $category['title'] = (string) $xmlCategory->title;
             $category['alias'] = (string) $xmlCategory->alias;
             $category['published'] = '1';
             $category['access'] = '1';
             $category['level'] = '1';
             $category['description'] = (string) $xmlCategory->description;
             $category['language'] = "*";
             $category['created_user_id'] = (int) $user->id;
             $categoryTable = new JTableCategory($db);
             $categoryTable->setLocation($category['parent_id'], 'last-child');
             $categoryTable->setRules('{"core.view":{"1":1},"core.delete":[],"core.edit":[],"core.edit.state":[]}');
             if ($categoryTable->save($category)) {
                 //Get category ID
                 $query = $db->getQuery(true);
                 $query->select('id');
                 $query->from('#__categories');
                 $query->where('extension = \'com_smarticons\'');
                 $query->where("title = " . $db->quote($xmlCategory->title));
                 $db->setQuery($query);
                 $categoryId = (int) $db->loadResult();
             }
         }
         foreach ($xmlCategory->icons->children() as $xmlIcon) {
             $icon = array();
             $icon['catid'] = $categoryId;
             $icon['Name'] = (string) $xmlIcon->name;
             $icon['Title'] = (string) $xmlIcon->title;
             $icon['Text'] = (string) $xmlIcon->text;
             $icon['Target'] = (string) $xmlIcon->target;
             $icon['Icon'] = (string) $xmlIcon->icon;
             $icon['Display'] = (string) $xmlIcon->display;
             $icon['ordering'] = (string) $xmlIcon->ordering;
             $icon['published'] = (string) $xmlIcon->published;
             $icon['params'] = (string) $xmlIcon->params;
             $iconsTable = $this->getTable();
             $iconsTable->setRules('{"core.view":{"1":1},"core.delete":[],"core.edit":[],"core.edit.state":[]}');
             $iconsTable->save($icon);
         }
     }
     //If all went well, we return true
     return true;
 }
コード例 #14
0
 /**
  * getContentCategories
  *
  * @param   array  $article_cat  Param.
  *
  * @return	array
  */
 public static function getContentCategories($article_cat)
 {
     $cat_ids = array();
     $cat_names = array();
     $cat_alias = array();
     $row = JTable::getInstance('category');
     // JomSocial Conflict Category ?
     if (!method_exists($row, 'load')) {
         if (EXTLY_J3) {
             include_once JPATH_SITE . '/libraries/legacy/table/category.php';
         } else {
             include_once JPATH_SITE . '/libraries/joomla/database/table/category.php';
         }
         $db = JFactory::getDbo();
         $row = new JTableCategory($db);
     }
     $row->load($article_cat);
     while ($row->parent_id > 0) {
         $cat_ids[] = $row->id;
         $cat_names[] = $row->title;
         $cat_alias[] = $row->alias;
         $row->load($row->parent_id);
     }
     return array($cat_ids, $cat_names, $cat_alias);
 }