コード例 #1
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;
 }
コード例 #2
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>';
     }
 }
コード例 #3
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;
 }