Skip to content

Commit

Permalink
Merge pull request #18 from juliopontes/2.5.x-with-pre-upgrade-check
Browse files Browse the repository at this point in the history
new helper for find extension manifest
new compatibility controller for redirect actions
new strings language
  • Loading branch information
nicksavov committed Mar 8, 2013
2 parents 2e8759b + 110b903 commit 805a30f
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 235 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_joomlaupdate
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @since 2.5.4
*/

defined('_JEXEC') or die;

/**
* The Joomla! update controller for the Update view
*
* @package Joomla.Administrator
* @subpackage com_joomlaupdate
* @since 2.5.10
*/
class JoomlaupdateControllerCompatibility extends JControllerLegacy
{
/**
* Method to display a view.
*
* @param boolean $cachable If true, the view output will be cached
* @param array $urlparams An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
*
* @return JController This object to support chaining.
*
* @since 2.5.10
*/
public function display($cachable = false, $urlparams = false)
{
// Get the document object.
$app = JFactory::getApplication();
$document = JFactory::getDocument();
$input = $app->input;

// Set the default view name and format from the Request.
$vName = $input->getCmd('view', 'compatibility');
$vFormat = $document->getType();
$lName = $input->getCmd('layout', 'default');
$extension = $input->getCmd('extension');

//check if extension are not empty
if (is_null($extension)) {
$app->redirect('index.php?option=com_joomlaupdate', 'COM_JOOMLAUPDATE_COMPATIBILITY_EMPTY_EXTENSION_VALUE');
}

// Get and render the view.
if ($view = $this->getView($vName, $vFormat)) {
// Get the model for the view.
$model = $this->getModel($vName);

//validate if extension exists
if (!$model->extensionExists($extension)) {
$app->redirect('index.php?option=com_joomlaupdate', 'COM_JOOMLAUPDATE_COMPATIBILITY_INVALID_EXTENSION_VALUE', 'warning');
}
// Push the model into the view (as default).
$view->setModel($model, true);

$view->display();
}

return $this;
}
}
118 changes: 118 additions & 0 deletions administrator/components/com_joomlaupdate/helpers/manifest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_joomlaupdate
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

// No direct access.
defined('_JEXEC') or die;

/**
* Smart download helper. Automatically uses cURL or URL fopen() wrappers to
* fetch the package.
*
* @package Joomla.Administrator
* @since 2.5.10
*/
class ManifestHelper
{
/**
* Downloads from a URL and saves the result as a local file
*
* @param JTableExtension $extension The extension loaded
*
* @return array Array with package folder and manifest filename
*
* @since 2.5.4
*/
public static function getPackageFolder($extension)
{
$return = array(
'package_folder' => null,
'manifest_filename' => null
);

// Guess the manifest path and name
switch($extension->type){
case 'component':
// A "component" type extension. We'll have to look for its manifest.
$return['package_folder'] = JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $extension->element);
break;

case 'file':
// A "file" type extension. Its manifest is strictly named and in a predictable path.
$return['package_folder'] = JPath::clean(JPATH_MANIFESTS . '/files');
$return['manifest_filename'] = $extension->element . '.xml';
break;

case 'language':
if ($extension->client_id == 0)
{
// A site language
$base_path = JPATH_SITE;
}
else
{
// An administrator language
$base_path = JPATH_ADMINISTRATOR;
}
$return['package_folder'] = JPath::clean($base_path . '/language/' . $extension->element);
// A "language" type extension. Its manifest is strictly named and in a predictable path.
$return['manifest_filename'] = $extension->element . '.xml';
break;

case 'library':
// A "library" type extension. Its manifest is strictly named and in a predictable path.
$return['package_folder'] = JPATH_MANIFESTS . '/libraries/' . $extension->element;
$return['manifest_filename'] = $extension->element . '.xml';
break;

case 'module':
// A "module" type extension. We'll have to look for its manifest.
if ($extension->client_id == 0)
{
// A site language
$base_path = JPATH_SITE;
}
else
{
// An administrator language
$base_path = JPATH_ADMINISTRATOR;
}
$return['package_folder'] = JPath::clean($base_path . '/modules/' . $extension->element);
break;

case 'package':
// A "package" type extension. Its manifest is strictly named and in a predictable path.
$return['package_folder'] = JPATH_MANIFESTS . '/packages/' . $extension->element;
$return['manifest_filename'] = $extension->element . '.xml';
break;

case 'plugin':
// A "plugin" type extension. We'll have to look for its manifest.
$return['package_folder'] = JPath::clean(JPATH_SITE . '/plugins/' . $extension->folder . '/' . $extension->element);
break;

case 'template':
// A "tempalte" type extension. We'll have to look for its manifest.
if ($extension->client_id == 0)
{
// A site language
$base_path = JPATH_SITE;
}
else
{
// An administrator language
$base_path = JPATH_ADMINISTRATOR;
}
$return['package_folder'] = JPath::clean($base_path . '/templates/' . $extension->element);
break;
}

return $return;
}


}
3 changes: 3 additions & 0 deletions administrator/components/com_joomlaupdate/joomlaupdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
}

// Register manifest helper
JLoader::register('ManifestHelper', JPATH_COMPONENT.'/helpers/manifest.php');

$controller = JControllerLegacy::getInstance('Joomlaupdate');
$controller->execute(JRequest::getCmd('task'));
$controller->redirect();
Loading

0 comments on commit 805a30f

Please sign in to comment.