function display($tpl = null) { JToolBarHelper::title(JText::_('COM_SEF_JOOMSEF') . ' - ' . JText::_('COM_SEF_UPGRADE_MANAGER'), 'update.png'); JToolBarHelper::back('COM_SEF_BACK', 'index.php?option=com_sef'); $exts = $this->get('UpgradeExts'); $this->assignRef('extensions', $exts); $oldVer = SEFTools::getSEFVersion(); $this->assignRef('oldVer', $oldVer); $newVer = $this->get('newSEFVersion'); $this->assignRef('newVer', $newVer); $regInfo = $this->get('RegisteredInfo'); $this->assignRef('regInfo', $regInfo); $isPaidVersion = $this->get('IsPaidVersion'); $this->assignRef('isPaidVersion', $isPaidVersion); JHTML::_('behavior.tooltip'); JHTML::_('behavior.modal'); parent::display($tpl); }
function upgrade() { $extDir = JPATH_ROOT . DS . 'components' . DS . 'com_sef' . DS . 'sef_ext'; $fromServer = JRequest::getVar('fromserver'); $extension = JRequest::getVar('ext'); if (!empty($extension) && !JFile::exists($extDir . DS . $extension . '.php')) { $this->setState('message', JText::_('You are not allowed to upgrade this extension.')); return false; } if (is_null($fromServer)) { $this->setState('message', JText::_('Upgrade source not given.')); return false; } if ($fromServer == 1) { $package = $this->_getPackageFromServer($extension); } else { $package = $this->_getPackageFromUpload(); } // was the package unpacked? if (!$package) { $this->setState('message', 'Unable to find install package.'); return false; } // create an array of upgrade files $upgradeDir = $package['dir'] . DS . 'upgrade'; $upgradeFiles = JFolder::files($upgradeDir, '.php$'); if (empty($upgradeFiles)) { $this->setState('message', JText::_('This package does not contain any upgrade informations.')); JFolder::delete($package['dir']); return false; } // Find the XML file in the package $xmlFile = $package['dir'] . DS . 'sef.xml'; if (!JFile::exists($xmlFile)) { // Try to find the extension XML file $xmlFiles = JFolder::files($package['dir'], '^com_[^.]+\\.xml$'); if (empty($xmlFiles)) { $this->setState('message', 'Could not find the installation XML file.'); return false; } // Set the file and the extension $xmlFile = $xmlFiles[0]; $extension = substr($xmlFile, 0, -4); } // get current version if (empty($extension)) { $curVersion = SEFTools::getSEFVersion(); } else { $curVersion = SEFTools::getExtVersion($extension); } if (empty($curVersion)) { $this->setState('message', JText::_('Could not find current version.')); JFolder::delete($package['dir']); return false; } // check if current version is upgradeable with downloaded package $reinstall = false; if (!in_array($curVersion . '.php', $upgradeFiles)) { if (empty($extension)) { // check if current version is being manually reinstalled with the same version package $xmlFile = $package['dir'] . DS . 'sef.xml'; $packVersion = $this->_getXmlText($xmlFile, 'version'); if ($packVersion == $curVersion && JFile::exists($upgradeDir . DS . 'reinstall.php')) { // initiate the reinstall $reinstall = true; $mainframe =& JFactory::getApplication(); $mainframe->enqueueMessage(JText::_('INFO_SEF_REINSTALL')); } } if (!$reinstall) { $this->setState('message', JText::_('ERROR_CANT_UPGRADE')); JFolder::delete($package['dir']); return false; } } natcasesort($upgradeFiles); // prepare arrays of upgrade operations and functions to manipulate them $this->_fileError = false; $this->_fileList = array(); $this->_sqlList = array(); $this->_scriptList = array(); if (!$reinstall) { // load each upgrade file starting with current version in ascending order foreach ($upgradeFiles as $uFile) { //if (!eregi("^[0-9]+\.[0-9]+\.[0-9]+\.php$", $uFile)) { if (!preg_match("/^[0-9]+\\.[0-9]+\\.[0-9]+\\.php\$/i", $uFile)) { continue; } if (strnatcasecmp($uFile, $curVersion . ".php") >= 0) { require_once $upgradeDir . DS . $uFile; } } } else { // create list of all files to upgrade require_once $upgradeDir . DS . 'reinstall.php'; } // Check if the free/paid version of JoomSEF is being changed if (empty($extension) && !$reinstall) { $xmlFile = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_sef' . DS . 'sef.xml'; $license = $this->_getXmlText($xmlFile, 'license'); $packXmlFile = $package['dir'] . DS . 'sef.xml'; $packLicense = $this->_getXmlText($packXmlFile, 'license'); $curFree = stripos($license, 'gpl') !== false; $packFree = stripos($packLicense, 'gpl') !== false; if ($curFree != $packFree) { // Add all the files like during reinstall require_once $upgradeDir . DS . 'reinstall.php'; } } if ($this->_fileError == false) { // set errors variable $errors = false; // first of all check if all the files are writeable // ONLY IF FTP IS DISABLED jimport('joomla.client.helper'); $ftpOptions = JClientHelper::getCredentials('ftp'); if ($ftpOptions['enabled'] != 1) { foreach ($this->_fileList as $dest => $op) { $file = JPath::clean(JPATH_ROOT . DS . $dest); // check if source file is present in upgrade package if ($op->operation == 'upgrade') { $from = JPath::clean($package['dir'] . DS . $op->packagePath); if (!JFile::exists($from)) { JError::raiseWarning(100, JText::_('File does not exist in upgrade package') . ': ' . $op->packagePath); $errors = true; } } if ($op->operation == 'delete' && JFile::exists($file) || $op->operation == 'upgrade' && !JFile::exists($file)) { // if the file is to be deleted or created, the file's directory must be writable $dir = dirname($file); if (!JFolder::exists($dir)) { // we need to create the directory where the file is to be created if (!JFolder::create($dir)) { JError::raiseWarning(100, JText::_('Directory could not be created') . ': ' . $dir); $errors = true; } } if (!is_writable($dir)) { if (!JPath::setPermissions($dir, '0755', '0777')) { JError::raiseWarning(100, JText::_('Directory not writeable') . ': ' . $dir); $errors = true; } } } elseif ($op->operation == 'upgrade') { // the file itself must be writeable if (!is_writable($file)) { if (!JPath::setPermissions($file, '0755', '0777')) { JError::raiseWarning(100, JText::_('File not writeable') . ': ' . $file); $errors = true; } } } } } // If there are no errors, let's upgrade if (!$errors) { $db =& JFactory::getDBO(); // execute SQL queries foreach ($this->_sqlList as $sql) { $db->setQuery($sql); if (!$db->query()) { JError::raiseWarning(100, JText::_('Unable to execute SQL query') . ': ' . $sql); $errors = true; } } // perform file operations foreach ($this->_fileList as $dest => $op) { if ($op->operation == 'delete') { $file = JPath::clean(JPATH_ROOT . DS . $dest); if (JFile::exists($file)) { $success = JFile::delete($file); if (!$success) { JError::raiseWarning(100, JText::_('Could not delete file. Please, check the write permissions on') . ' ' . $dest); $errors = true; } } } elseif ($op->operation == 'upgrade') { $from = JPath::clean($package['dir'] . DS . $op->packagePath); $to = JPath::clean(JPATH_ROOT . DS . $dest); $destDir = dirname($to); // create the destination directory if needed if (!JFolder::exists($destDir)) { JFolder::create($destDir); } $success = JFile::copy($from, $to); if (!$success) { JError::raiseWarning(100, JText::_('Could not rewrite file. Please, check the write permissions on') . ' ' . $dest); $errors = true; } } } // run scripts foreach ($this->_scriptList as $script) { $file = JPath::clean($package['dir'] . DS . $script); if (!JFile::exists($file)) { JError::raiseWarning(100, JText::_('Could not find script file') . ': ' . $script); $errors = true; } else { include $file; } } } if (!$errors) { $what = empty($extension) ? JText::_('JoomSEF') : JText::_('SEF Extension') . ' ' . $extension; $this->setState('message', $what . ' ' . JText::_('successfully upgraded.')); } else { $this->setState('message', JText::_('ERROR_UPGRADE_PROBLEM')); } } JFolder::delete($package['dir']); return true; }
function findUpdate($data) { $this->_update_site_id = $data["update_site_id"]; $this->base = array(); $this->update_sites = array(); $this->updates = array(); $ext_data = SEFTools::postRequest($data['location']); $details = $ext_data->content; $db = JFactory::getDBO(); if (!strlen($details)) { $query = $db->getQuery(true); $query->update('#__update_sites')->set('enabled=0')->where('update_site=' . $data["update_site_id"]); $db->query(); JError::raiseWarning('101', JText::sprintf('JLIB_UPDATER_ERROR_SEFEXT_OPEN_URL', $data["url"])); return false; } if (preg_match("/^[0-9]{2}/", $details, $status)) { $details = $status[0]; $url = explode("/", $data['location']); $ext = array_pop($url); $ext = str_replace('.xml', '', $ext); if (substr_count($ext, "-")) { $ext_name_arr = explode("-", $ext); $ext_name = $ext_name_arr[0]; } else { $ext_name = $ext; } if (substr_count($ext, 'com_joomsef4')) { $data["name"] = "Artio JoomSEF 4"; } else { $query = $db->getQuery(true); $query->select('name')->from('#__extensions')->where('element=' . $db->quote($ext_name))->where('type=' . $db->quote('sef_ext')); $db->setQuery($query); $data["name"] = $db->loadResult(); if (is_null($data['name'])) { // Extension not found return true; } $data['name'] .= ' (JoomSEF extension)'; } } switch ($details) { case '20': JError::raiseWarning('101', $data["name"] . ': ' . JText::sprintf('COM_SEF_EXPIRED', $data["name"])); break; case '30': JError::raiseWarning('101', $data["name"] . ': ' . JText::sprintf('COM_SEF_NOT_ACTIVATED', $data["name"])); break; case '40': JError::raiseWarning('101', $data["name"] . ': ' . JText::sprintf('COM_SEF_ERR_DOMAIN_NOT_MATCH', $data["name"])); break; case '50': JError::raiseWarning('101', $data["name"] . ': ' . JText::sprintf('COM_SEF_DOWLOAD_ID_INVALID', $data["name"])); break; case '90': // Commercial extension $location_match = array(); if (preg_match("/(-([A-Za-z0-9]*)).xml/", $data["location"], $location_match)) { JError::raiseWarning('101', $data["name"] . ': ' . JText::sprintf('COM_SEF_ERROR_DOWNLOAD_ID_NOT_FOUND', $location_match[2])); // Free extension } else { JError::raiseWarning('101', $data["name"] . ': ' . JText::sprintf('COM_SEF_NOT_FOUND', $data["name"])); } break; default: $xml = simplexml_load_string($details); if (is_object($xml)) { foreach ($xml->children() as $update) { $table = JTable::getInstance('update'); $table->update_site_id = $this->_update_site_id; $table->version = (string) $update->version; if ((string) $update->element == 'com_joomsef4') { $sef_version = SEFTools::getSEFVersion(); $table->name = (string) $update->name; $table->element = 'com_sef'; $table->client_id = 1; $table->type = 'component'; } else { $sefext_version = SEFTools::getExtVersion((string) $update->name); $table->name = (string) $update->name; $table->element = (string) $update->element; $table->client_id = 0; $table->type = 'sef_ext'; } $table->detailsurl = $data["location"]; $this->updates[] = $table; } } } return array('update_sites' => $this->update_sites, 'updates' => $this->updates); }