/** 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; }
/** * Custom uninstall method * * @access public * @param int $cid The id of the extension to uninstall * @param int $clientId The id of the client (unused) * @return boolean True on success * @since 1.5 */ function uninstall($id, $clientId) { // Initialize variables $row = null; $retval = true; $db =& $this->parent->getDBO(); // First order of business will be to load the module object table from the database. // This should give us the necessary information to proceed. $row = new XmapPlugin($db, (int) $id); // Set the extension root path $this->parent->setPath('extension_root', JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_xmap' . DS . 'extensions'); // Because extensions don't have their own folders we cannot use the standard method of finding an installation manifest $manifestFile = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_xmap' . DS . 'extensions' . DS . $row->extension . '.xml'; if (file_exists($manifestFile)) { $xml =& JFactory::getXMLParser('Simple'); // If we cannot load the xml file return null if (!$xml->loadFile($manifestFile)) { JError::raiseWarning(100, JText::_('Plugin') . ' ' . JText::_('Uninstall') . ': ' . JText::_('Could not load manifest file')); return false; } /* * Check for a valid XML root tag. * @todo: Remove backwards compatability in a future version * Should be 'install', but for backward compatability we will accept 'mosinstall'. */ $root =& $xml->document; if ($root->name() != 'install' && $root->name() != 'mosinstall') { JError::raiseWarning(100, JText::_('Plugin') . ' ' . JText::_('Uninstall') . ': ' . JText::_('Invalid manifest file')); return false; } // Remove the extension files $this->parent->removeFiles($root->getElementByPath('images'), -1); $this->parent->removeFiles($root->getElementByPath('files'), -1); JFile::delete($manifestFile); // Remove all media and languages as well $this->parent->removeFiles($root->getElementByPath('media')); $this->parent->removeFiles($root->getElementByPath('languages'), 1); } else { JError::raiseWarning(100, 'Plugin Uninstall: Manifest File invalid or not found'); return false; } // Now we will no longer need the extension object, so lets delete it $row->extension = $row->extension . '.bak'; $row->store(); unset($row); return $retval; }
# $config->load(); $config->sitemap_default = $id; if ($config->save()) { echo '1'; } else { echo $database->getErrorMsg(); } break; case 'change_plugin_state': $id = intval(JRequest::getVar('plugin', '', "REQUEST")); if (!$id || $id != JRequest::getVar('plugin', '', "REQUEST")) { die("Invalid Plugin ID"); } $plugin = new XmapPlugin($database, $id); $plugin->published = $plugin->published ? 0 : 1; if ($plugin->store()) { echo $plugin->published; } else { echo $database->getErrorMsg(); } break; case 'clean_cache_sitemap': $id = intval(JRequest::getVar('sitemap', '', "REQUEST")); if (!$id || $id != JRequest::getVar('sitemap', '', "REQUEST")) { die("Invalid Sitemap ID"); } $sitemap = new XmapSitemap($database); if ($sitemap->load($id)) { if (XmapCache::cleanCache($sitemap)) { echo _XMAP_MSG_CACHE_CLEANED; } else {