Created
August 13, 2017 11:31
-
-
Save cheiff/d788600c0132dcf89e8583059f8cae3e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Command-line extension installer. This file is meant to be copied into your Joomla! 3 site's cli directory. | |
*/ | |
// Define ourselves as a parent file | |
define('_JEXEC', 1); | |
// Required by the CMS [67/49428] | |
define('DS', DIRECTORY_SEPARATOR); | |
// Timezone fix; avoids errors printed out by PHP 5.3.3+ (thanks Yannick!) | |
if (function_exists('date_default_timezone_get') && function_exists('date_default_timezone_set')) | |
{ | |
if (function_exists('error_reporting')) | |
{ | |
$oldLevel = error_reporting(0); | |
} | |
$serverTimezone = @date_default_timezone_get(); | |
if (empty($serverTimezone) || !is_string($serverTimezone)) | |
{ | |
$serverTimezone = 'UTC'; | |
} | |
if (function_exists('error_reporting')) | |
{ | |
error_reporting($oldLevel); | |
} | |
@date_default_timezone_set($serverTimezone); | |
} | |
// Load system defines | |
if (file_exists(__DIR__ . '/defines.php')) | |
{ | |
include_once __DIR__ . '/defines.php'; | |
} | |
if (!defined('_JDEFINES')) | |
{ | |
$path = rtrim(__DIR__, DIRECTORY_SEPARATOR); | |
$rpos = strrpos($path, DIRECTORY_SEPARATOR); | |
$path = substr($path, 0, $rpos); | |
define('JPATH_BASE', $path); | |
require_once JPATH_BASE . '/includes/defines.php'; | |
} | |
// Load the rest of the framework include files | |
if (file_exists(JPATH_LIBRARIES . '/import.legacy.php')) | |
{ | |
require_once JPATH_LIBRARIES . '/import.legacy.php'; | |
} | |
else | |
{ | |
require_once JPATH_LIBRARIES . '/import.php'; | |
} | |
require_once JPATH_LIBRARIES . '/cms.php'; | |
// Load the configuration | |
require_once JPATH_CONFIGURATION . '/configuration.php'; | |
// Load the JApplicationCli class | |
JLoader::import('joomla.application.cli'); | |
JLoader::import('joomla.application.component.helper'); | |
JLoader::import('cms.component.helper'); | |
class JoomlaExtensionInstallerCli extends JApplicationCli | |
{ | |
/** | |
* JApplicationCli didn't want to run on PHP CGI. I have my way of becoming | |
* VERY convincing. Now obey your true master, you petty class! | |
* | |
* @param JInputCli $input | |
* @param JRegistry $config | |
* @param JDispatcher $dispatcher | |
*/ | |
public function __construct(JInputCli $input = null, JRegistry $config = null, JDispatcher $dispatcher = null) | |
{ | |
// Initialise the session | |
$session = \JFactory::getSession(); | |
$session->initialise(new \JInput()); | |
// Close the application if we are not executed from the command line, Akeeba style (allow for PHP CGI) | |
if (array_key_exists('REQUEST_METHOD', $_SERVER)) | |
{ | |
die('You are not supposed to access this script from the web. You have to run it from the command line. If you don\'t understand what this means, you must not try to use this file before reading the documentation. Thank you.'); | |
} | |
$cgiMode = false; | |
if (!defined('STDOUT') || !defined('STDIN') || !isset($_SERVER['argv'])) | |
{ | |
$cgiMode = true; | |
} | |
// If a input object is given use it. | |
if ($input instanceof JInput) | |
{ | |
$this->input = $input; | |
} | |
// Create the input based on the application logic. | |
else | |
{ | |
if (class_exists('JInput')) | |
{ | |
if ($cgiMode) | |
{ | |
$query = ""; | |
if (!empty($_GET)) | |
{ | |
foreach ($_GET as $k => $v) | |
{ | |
$query .= " $k"; | |
if ($v != "") | |
{ | |
$query .= "=$v"; | |
} | |
} | |
} | |
$query = ltrim($query); | |
$argv = explode(' ', $query); | |
$argc = count($argv); | |
$_SERVER['argv'] = $argv; | |
} | |
if (class_exists('JInputCLI')) | |
{ | |
echo "JInputCLI exists\n"; | |
$this->input = new JInputCLI(); | |
} | |
else | |
{ | |
echo "JInputCLI does NOT exist\n"; | |
$this->input = new \Joomla\CMS\Input\Cli(); | |
} | |
} | |
} | |
} | |
} | |
$app = JApplicationCli::getInstance('JoomlaExtensionInstallerCli'); | |
JFactory::$application = $app; | |
$app->execute(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment