예제 #1
0
 /** Create the settings table for Xmap and add initial default values */
 function create()
 {
     $db =& JFactory::getDBO();
     jimport('joomla.filesystem.file');
     $fields = array();
     $fields[] = "`name` varchar(30) not null primary key";
     $fields[] = "`value` varchar(100)";
     $query = "CREATE TABLE IF NOT EXISTS #__xmap (" . implode(', ', $fields) . ")";
     $db->setQuery($query);
     if ($db->query() === FALSE) {
         echo _XMAP_ERR_NO_CREATE . "<br />\n";
         echo stripslashes($db->getErrorMsg());
         return false;
     }
     $fields = array();
     $fields[] = "`id` int not null primary key auto_increment";
     $fields[] = "`extension` varchar(100) not null";
     $fields[] = "`published` int(1) default 0";
     $fields[] = "`params` text";
     $query = "CREATE TABLE IF NOT EXISTS #__xmap_ext (" . implode(', ', $fields) . ")";
     $db->setQuery($query);
     if ($db->query() === FALSE) {
         echo _XMAP_ERR_NO_CREATE . "<br />\n";
         echo stripslashes($db->getErrorMsg());
         return false;
     }
     $extensions = array(array('com_agora', 1), array('com_content', 1), array('com_eventlist', 1), array('com_g2bridge', 1), array('com_glossary', 1), array('com_hotproperty', 1), array('com_jcalpro', 1), array('com_jdownloads', 1), array('com_jevents', 1), array('com_jomres', 1), array('com_kb', 1), array('com_kunena', 1), array('com_mtree', 1), array('com_myblog', 1), array('com_remository', 1), array('com_resource', 1), array('com_rokdownloads', 1), array('com_rsgallery2', 1), array('com_sectionex', 1), array('com_sobi2', 1), array('com_virtuemart', 1));
     foreach ($extensions as $ext) {
         $query = "SELECT COUNT(*) FROM `#__xmap_ext` WHERE extension='{$ext['0']}'";
         $db->setQuery($query);
         if ($db->loadResult() == 0) {
             $extension = new XmapPlugin($db);
             $extension->extension = $ext[0];
             $extension->published = $ext[1];
             $xmlfile = $extension->getXmlPath();
             JFile::move("{$xmlfile}.txt", $xmlfile);
             $extension->setParams($extension->loadDefaultsParams(true), '-1');
             $extension->store();
         }
     }
     $vars = get_class_vars('XmapSitemap');
     $fields = '';
     foreach ($vars as $name => $value) {
         if ($name[0] !== '_') {
             if ($name == 'id') {
                 $fields[] = 'id INT NOT NULL PRIMARY KEY AUTO_INCREMENT';
             } else {
                 switch (gettype($value)) {
                     case 'integer':
                         $fields[] = "`{$name}` INTEGER NULL";
                         break;
                     case 'string':
                         if ($name == 'menus') {
                             $fields[] = "`{$name}` TEXT NULL";
                         } else {
                             $fields[] = "`{$name}` VARCHAR(255) NULL";
                         }
                         break;
                 }
             }
         }
     }
     $query = "CREATE TABLE IF NOT EXISTS #__xmap_sitemap (" . implode(', ', $fields) . ")";
     $db->setQuery($query);
     if ($db->query() === FALSE) {
         echo _XMAP_ERR_NO_CREATE . "<br />\n";
         echo stripslashes($db->getErrorMsg());
         return false;
     }
     $query = "CREATE TABLE IF NOT EXISTS #__xmap_items ( uid varchar(100) not null, itemid int not null, view varchar(10) not null, sitemap_id int not null, properties varchar(300), primary key (uid,itemid,view,sitemap_id),index (uid,itemid),index (view));";
     $db->setQuery($query);
     if ($db->query() === FALSE) {
         echo _XMAP_ERR_NO_CREATE . "<br />\n";
         echo stripslashes($db->getErrorMsg());
         return false;
     }
     echo _XMAP_MSG_SET_DB_CREATED . "<br />\n";
     // Insert default Settings
     $query = "SELECT COUNT(*) from `#__xmap_sitemap`";
     $db->setQuery($query);
     if ($db->loadResult() == 0) {
         $sitemap = new XmapSitemap($db);
         $sitemap->save();
     }
     $query = "SELECT COUNT(*) from `#__xmap`";
     $db->setQuery($query);
     if ($db->loadResult() == 0) {
         $fields = array();
         $vars = get_class_vars('XmapConfig');
         foreach ($vars as $name => $value) {
             if ($name == 'sitemap_default') {
                 $value = $sitemap->id;
             }
             $query = "INSERT INTO #__xmap (`name`,`value`) values ('{$name}','{$value}')";
             $db->setQuery($query);
             if ($db->query() === FALSE) {
                 echo _XMAP_ERR_NO_DEFAULT_SET . "<br />\n";
                 echo stripslashes($db->getErrorMsg());
                 return false;
             }
         }
     }
     echo _XMAP_MSG_SET_DEF_INSERT . "<br />\n";
     return true;
 }
예제 #2
0
 /**
  * Custom install method
  *
  * @access	public
  * @return	boolean	True on success
  * @since	1.5
  */
 function install()
 {
     // Get a database connector object
     $db =& $this->parent->getDBO();
     // Get the extension manifest object
     $manifest =& $this->parent->getManifest();
     $this->manifest =& $manifest->document;
     /**
      * ---------------------------------------------------------------------------------------------
      * Manifest Document Setup Section
      * ---------------------------------------------------------------------------------------------
      */
     // Set the extensions name
     $name =& $this->manifest->getElementByPath('name');
     $name = JFilterInput::clean($name->data(), 'cmd');
     $this->set('name', $name);
     // Get the component description
     $description =& $this->manifest->getElementByPath('description');
     if (is_a($description, 'JSimpleXMLElement')) {
         $this->parent->set('message', $description->data());
     } else {
         $this->parent->set('message', '');
     }
     /*
      * Backward Compatability
      * @todo Deprecate in future version
      */
     $type = $this->manifest->attributes('type');
     // Set the installation path
     $element =& $this->manifest->getElementByPath('files');
     if (is_a($element, 'JSimpleXMLElement') && count($element->children())) {
         $files =& $element->children();
         foreach ($files as $file) {
             if ($file->attributes($type)) {
                 $pname = $file->attributes($type);
                 break;
             }
         }
     }
     if (!empty($pname)) {
         $this->parent->setPath('extension_root', JPATH_ROOT . DS . '/administrator/components/com_xmap/extensions');
     } else {
         $this->parent->abort(JText::_('Plugin') . ' ' . JText::_('Install') . ': ' . JText::_('No extension file specified'));
         return false;
     }
     /**
      * ---------------------------------------------------------------------------------------------
      * Filesystem Processing Section
      * ---------------------------------------------------------------------------------------------
      */
     // If the extension directory does not exist, lets create it
     $created = false;
     if (!file_exists($this->parent->getPath('extension_root'))) {
         if (!($created = JFolder::create($this->parent->getPath('extension_root')))) {
             $this->parent->abort(JText::_('Plugin') . ' ' . JText::_('Install') . ': ' . JText::_('Failed to create directory') . ': "' . $this->parent->getPath('extension_root') . '"');
             return false;
         }
     }
     /*
      * If we created the extension directory and will want to remove it if we
      * have to roll back the installation, lets add it to the installation
      * step stack
      */
     if ($created) {
         $this->parent->pushStep(array('type' => 'folder', 'path' => $this->parent->getPath('extension_root')));
     }
     // Copy all necessary files
     if ($this->parent->parseFiles($element, -1) === false) {
         // Install failed, roll back changes
         $this->parent->abort();
         return false;
     }
     /**
      * ---------------------------------------------------------------------------------------------
      * Database Processing Section
      * ---------------------------------------------------------------------------------------------
      */
     // Check to see if a extension by the same name is already installed
     $query = 'SELECT `id`' . ' FROM `#__xmap_ext`' . ' WHERE extension = ' . $db->Quote($pname);
     $db->setQuery($query);
     if (!$db->Query()) {
         // Install failed, roll back changes
         $this->parent->abort('Extension Install: ' . $db->stderr(true));
         return false;
     }
     $id = $db->loadResult();
     // Was there a module already installed with the same name?
     if ($id) {
         if (!$this->parent->getOverwrite()) {
             // Install failed, roll back changes
             $this->parent->abort('Extension Install: Extension "' . $pname . '" already exists!');
             return false;
         }
     } else {
         // Check to see if there is a backup for this extension
         $query = 'SELECT `id`' . ' FROM `#__xmap_ext`' . ' WHERE extension = ' . $db->Quote($pname . '.bak');
         $db->setQuery($query);
         if (!$db->Query()) {
             // Install failed, roll back changes
             $this->parent->abort('Extension Install: ' . $db->stderr(true));
             return false;
         }
         $id = $db->loadResult();
         $row = new XmapPlugin($db, $id);
         $row->extension = $pname;
         $row->published = 0;
         if (!$id) {
             $row->setParams($this->parent->getParams(), '-1');
         }
         if (!$row->store()) {
             // Install failed, roll back changes
             $this->parent->abort(JText::_('Plugin') . ' ' . JText::_('Install') . ': ' . $db->stderr(true));
             return false;
         }
         // Since we have created a extension item, we add it to the installation step stack
         // so that if we have to rollback the changes we can undo it.
         $this->parent->pushStep(array('type' => 'xmap_ext', 'id' => $row->id));
     }
     /**
      * ---------------------------------------------------------------------------------------------
      * Finalization and Cleanup Section
      * ---------------------------------------------------------------------------------------------
      */
     // Lastly, we will copy the manifest file to its appropriate place.
     if (!$this->parent->copyManifest(-1)) {
         // Install failed, rollback changes
         $this->parent->abort(JText::_('Plugin') . ' ' . JText::_('Install') . ': ' . JText::_('Could not copy setup file'));
         return false;
     }
     return true;
 }
예제 #3
0
     $id = intval(JRequest::getVar('id', '', "REQUEST"));
     if (!$id || $id != JRequest::getVar('id', '', "REQUEST")) {
         die("Invalid Plugin ID");
     }
     $plugin = new XmapPlugin($database, $id);
     if ($plugin->id) {
         $params = JRequest::getVar('params', '', "POST");
         $itemid = JRequest::getVar('itemid', '-1', "POST");
         if (is_array($params)) {
             $plugin->parseParams();
             $txt = array();
             foreach ($params as $k => $v) {
                 $txt[] = "{$k}=" . str_replace("\n", '<br />', $v);
             }
             $params = implode("\n", $txt);
             $plugin->setParams($params, $itemid);
             if ($plugin->store()) {
                 echo 1;
             } else {
                 echo $database->getErrorMsg();
             }
         }
     } else {
         die("Invalid Plugin ID");
     }
     break;
 case 'set_default':
     $id = intval(JRequest::getVar('sitemap', '', "REQUEST"));
     if (!$id || $id != JRequest::getVar('sitemap', '', "REQUEST")) {
         die("Invalid Sitemap ID");
     }