Exemple #1
0
 public function __construct(AContainer $container = null)
 {
     if (is_null($container)) {
         $container = AApplication::getInstance()->getContainer();
     }
     $this->container = $container;
 }
Exemple #2
0
 public function __construct(array $values = array())
 {
     parent::__construct($values);
     // Application service
     if (!isset($this['application'])) {
         $this['application'] = function (AContainer $c) {
             return AApplication::getTmpInstance($c->application_name, array(), 'Angie', $c);
         };
     }
     // Input Access service
     if (!isset($this['input'])) {
         $this['input'] = function (AContainer $c) {
             return new AInput();
         };
     }
     // Application Dispatcher service
     if (!isset($this['dispatcher'])) {
         $this['dispatcher'] = function (AContainer $c) {
             return ADispatcher::getTmpInstance(null, null, array(), $c);
         };
     }
     if (!isset($this['session'])) {
         $this['session'] = function (AContainer $c) {
             return ASession::getInstance();
         };
     }
 }
 public function fix()
 {
     try {
         $this->getThisModel()->fix();
         $this->setRedirect('index.php?view=main');
     } catch (Exception $exc) {
         AApplication::getInstance()->enqueueMessage($exc->getMessage(), 'error');
         $this->task = 'main';
         $this->doTask = 'main';
         $this->main();
     }
 }
Exemple #4
0
 /**
  * Gets a temporary instance of a Dispatcher
  *
  * @param   string      $option     The component name
  * @param   string      $view       The View name
  * @param   array       $config     Configuration data
  * @param   AContainer  $container  Application container
  *
  * @return ADispatcher
  */
 public static function &getTmpInstance($option = null, $view = null, $config = array(), AContainer $container = null)
 {
     if (is_null($container)) {
         $container = AApplication::getInstance()->getContainer();
     }
     // TODO Check the following code to use only the container
     if (array_key_exists('input', $config)) {
         if ($config['input'] instanceof AInput) {
             $input = $config['input'];
         } else {
             if (!is_array($config['input'])) {
                 $config['input'] = (array) $config['input'];
             }
             $config['input'] = array_merge($_REQUEST, $config['input']);
             $input = new AInput($config['input']);
         }
     } else {
         $input = $container->input;
     }
     $defaultApp = $container->application->getName();
     if (!is_null($option)) {
         $config['option'] = $option;
     } else {
         $config['option'] = $input->getCmd('option', $defaultApp);
     }
     if (!is_null($view)) {
         $config['view'] = $view;
     } else {
         $config['view'] = $input->getCmd('view', '');
     }
     $input->set('option', $config['option']);
     $input->set('view', $config['view']);
     $config['input'] = $input;
     $className = ucfirst($config['option']) . 'Dispatcher';
     if (!class_exists($className)) {
         $basePath = APATH_INSTALLATION;
         $searchPaths = array($basePath . '/' . $config['option'] . '/platform', $basePath . '/' . $config['option'] . '/platform/dispatchers', $basePath . '/platform', $basePath . '/platform/dispatchers', $basePath . '/' . $config['option'], $basePath . '/' . $config['option'] . '/dispatchers');
         if (array_key_exists('searchpath', $config)) {
             array_unshift($searchPaths, $config['searchpath']);
         }
         $path = AUtilsPath::find($searchPaths, 'dispatcher.php');
         if ($path) {
             require_once $path;
         }
     }
     if (!class_exists($className) && class_exists($className . 'Default')) {
         $className = $className . 'Default';
     } elseif (!class_exists($className)) {
         $className = 'ADispatcher';
     }
     $instance = new $className($config, $container);
     return $instance;
 }
Exemple #5
0
 public static function detectLanguage()
 {
     if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
         $languages = strtolower($_SERVER["HTTP_ACCEPT_LANGUAGE"]);
         // $languages = ' fr-ch;q=0.3, da, en-us;q=0.8, en;q=0.5, fr;q=0.3';
         // need to remove spaces from strings to avoid error
         $languages = str_replace(' ', '', $languages);
         $languages = explode(",", $languages);
         foreach ($languages as $language_list) {
             // pull out the language, place languages into array of full and primary
             // string structure:
             $temp_array = array();
             // slice out the part before ; on first step, the part before - on second, place into array
             $temp_array[0] = substr($language_list, 0, strcspn($language_list, ';'));
             //full language
             $temp_array[1] = substr($language_list, 0, 2);
             // cut out primary language
             if (strlen($temp_array[0]) == 5 && (substr($temp_array[0], 2, 1) == '-' || substr($temp_array[0], 2, 1) == '_')) {
                 $langLocation = strtoupper(substr($temp_array[0], 3, 2));
                 $temp_array[0] = $temp_array[1] . '-' . $langLocation;
             }
             //place this array into main $user_languages language array
             $user_languages[] = $temp_array;
         }
         $baseName = APATH_INSTALLATION . '/' . AApplication::getInstance()->getName() . '/language/';
         foreach ($user_languages as $languageStruct) {
             // Search for exact language
             $langFilename = $baseName . $languageStruct[0] . '.ini';
             if (!file_exists($langFilename)) {
                 $langFilename = '';
                 if (function_exists('glob')) {
                     $allFiles = glob($baseName . $languageStruct[1] . '-*.ini');
                     if (count($allFiles)) {
                         $langFilename = array_shift($allFiles);
                     }
                 }
             }
             if (!empty($langFilename) && file_exists($langFilename)) {
                 return basename($langFilename, '.ini');
             }
         }
     }
     return 'en-GB';
 }
 /**
  * Check if the installer is password protected. If it is and the user has
  * not yet entered a password forward him to the password entry page.
  * 
  * @return  boolean
  */
 private function passwordProtection()
 {
     $filePath = APATH_INSTALLATION . '/password.php';
     if (file_exists($filePath)) {
         include_once $filePath;
     }
     $view = $this->input->get('view', $this->defaultView);
     if (defined('AKEEBA_PASSHASH')) {
         $savedHash = ASession::getInstance()->get('angie.passhash', null);
         $parts = explode(':', AKEEBA_PASSHASH);
         $correctHash = $parts[0];
         $allowedViews = array('password', 'session', 'ftpbrowser');
         if (defined('AKEEBA_PASSHASH') && !in_array($view, $allowedViews) && $savedHash != $correctHash) {
             AApplication::getInstance()->redirect('index.php?view=password');
             return true;
         }
     } elseif (!defined('AKEEBA_PASSHASH') && $this->input->get('view', $this->defaultView) == 'password') {
         return false;
     }
     return true;
 }
Exemple #7
0
 /**
  * Gets an instance of the database restoration class based on the $dbkey.
  * If it doesn't exist, a new instance is created based on $dbkey and
  * $dbiniValues provided.
  *
  * @staticvar  array  $instances  The array of ADatabaseRestore instances
  *
  * @param   string      $dbkey        The key of the database being restored
  * @param   array       $dbiniValues  The database restoration configuration variables
  * @param   AContainer  $container      Application container
  *
  * @return  ADatabaseRestore
  *
  * @throws Exception
  */
 public static function getInstance($dbkey, $dbiniValues = null, AContainer $container = null)
 {
     static $instances = array();
     if (!array_key_exists($dbkey, $instances)) {
         if (empty($dbiniValues)) {
             throw new Exception(AText::sprintf('ANGI_RESTORE_ERROR_UNKNOWNKEY', $dbkey));
         }
         if (is_object($dbiniValues)) {
             $dbiniValues = (array) $dbiniValues;
         }
         if (is_null($container)) {
             $container = AApplication::getInstance()->getContainer();
         }
         $class = 'ADatabaseRestore' . ucfirst($dbiniValues['dbtype']);
         $instances[$dbkey] = new $class($dbkey, $dbiniValues, $container);
     }
     return $instances[$dbkey];
 }
Exemple #8
0
    include __DIR__ . '/php/buttons.php';
    ?>
					</div>
				</div>
			</div>
		</div>
		<div class="container">
<?php 
}
?>
			<?php 
include __DIR__ . '/php/messages.php';
?>
			<?php 
echo $this->getBuffer();
if (AApplication::getInstance()->getInput()->getCmd('tmpl', '') != 'component') {
    ?>
		</div>
	</div>
	<div id="footer">
		<div class="container">
			<p class="muted credit">
				Copyright &copy;2006 &ndash; <?php 
    echo date('Y');
    ?>
 Akeeba Ltd. All rights reserved.<br/>
				ANGIE is Free Software distributed under the
				<a href="http://www.gnu.org/licenses/gpl.html">GNU GPL version 3</a> or any later version published by the FSF.
			</p>
		</div>
	</div>
Exemple #9
0
    include __DIR__ . '/php/buttons.php';
    ?>
					</div>
				</div>
			</div>
		</div>
		<div class="container">
<?php 
}
?>
			<?php 
include __DIR__ . '/php/messages.php';
?>
			<?php 
echo $this->getBuffer();
if (AApplication::getInstance()->getContainer()->input->getCmd('tmpl', '') != 'component') {
    ?>
		</div>
	</div>
	<div id="footer">
		<div class="container">
			<p class="muted credit pull-left">
				Copyright &copy;2006 &ndash; <?php 
    echo date('Y');
    ?>
 Akeeba Ltd. All rights reserved.<br/>
				ANGIE is Free Software distributed under the
				<a href="http://www.gnu.org/licenses/gpl.html">GNU GPL version 3</a> or any later version published by the FSF.
			</p>
            <div class="nav-collapse collapse pull-right btn-group" style="margin-top: 15px;">
                <?php 
Exemple #10
0
 /**
  * Constructor
  *
  * @param   array $config A named configuration array for object construction.<br/>
  *                          name: the name (optional) of the view (defaults to the view class name suffix).<br/>
  *                          escape: the name (optional) of the function to use for escaping strings<br/>
  *                          base_path: the parent path (optional) of the views directory (defaults to the component folder)<br/>
  *                          template_plath: the path (optional) of the layout directory (defaults to base_path + /views/ + view name<br/>
  *                          helper_path: the path (optional) of the helper files (defaults to base_path + /helpers/)<br/>
  *                          layout: the layout (optional) to use to display the view<br/>
  *
  * @param   \AContainer $container
  *
  * @throws \AExceptionApp
  * @throws \Exception
  */
 public function __construct($config = array(), AContainer $container = null)
 {
     if (is_null($container)) {
         $container = AApplication::getInstance()->getContainer();
     }
     $this->container = $container;
     $this->input = $this->container->input;
     // Get the component name
     if (array_key_exists('option', $config)) {
         if ($config['option']) {
             $component = $config['option'];
         }
     }
     $config['option'] = $component;
     // Get the view name
     $view = $this->input->getCmd('view', '');
     if (array_key_exists('view', $config)) {
         if ($config['view']) {
             $view = $config['view'];
         }
     }
     $config['view'] = $view;
     // Set the component and the view to the input array
     $this->input->set('option', $config['option']);
     $this->input->set('view', $config['view']);
     // Set the view name
     if (array_key_exists('name', $config)) {
         $this->_name = $config['name'];
     } else {
         $this->_name = $config['view'];
     }
     $this->input->set('view', $this->_name);
     $config['input'] = $this->input;
     $config['name'] = $this->_name;
     $config['view'] = $this->_name;
     // Set a base path for use by the view
     if (array_key_exists('base_path', $config)) {
         $this->_basePath = $config['base_path'];
     } else {
         $this->_basePath = APATH_INSTALLATION . '/' . $config['option'];
     }
     // Set the default template search path
     if (array_key_exists('template_path', $config)) {
         // User-defined dirs
         $this->_setPath('template', $config['template_path']);
     } else {
         $this->_setPath('template', $this->_basePath . '/views/' . $this->getName() . '/tmpl');
     }
     // Set the default helper search path
     if (array_key_exists('helper_path', $config)) {
         // User-defined dirs
         $this->_setPath('helper', $config['helper_path']);
     } else {
         $this->_setPath('helper', $this->_basePath . '/helpers');
     }
     // Set the layout
     if (array_key_exists('layout', $config)) {
         $this->setLayout($config['layout']);
     } else {
         $this->setLayout('default');
     }
     $this->config = $config;
     $app = $this->container->application;
     $component = preg_replace('/[^A-Z0-9_\\.-]/i', '', $component);
     $fallback = APATH_THEMES . '/' . $app->getTemplate() . '/html/' . $component . '/' . $this->getName();
     $this->_addPath('template', $fallback);
     $this->baseurl = AUri::base(true);
 }
Exemple #11
0
// Required by the Joomla! CMS version file (mind. blown!)
define('JPATH_PLATFORM', 1);
// Required for lang strings. This is what happens when you use Joomla! core code.
define('_QQ_', '&quot;');
// Debug
// define('AKEEBA_DEBUG', 1);
if (defined('AKEEBA_DEBUG')) {
    error_reporting(E_ALL | E_NOTICE | E_DEPRECATED);
    ini_set('display_errors', 1);
}
// Load the framework autoloader
require_once __DIR__ . '/framework/autoloader.php';
require_once __DIR__ . '/defines.php';
try {
    // Create the application
    $application = AApplication::getInstance('angie');
    // Initialise the application
    $application->initialise();
    // Dispatch the application
    $application->dispatch();
    // Render
    $application->render();
    // Clean-up and shut down
    $application->close();
} catch (Exception $exc) {
    $filename = null;
    if (isset($application)) {
        if ($application instanceof AApplication) {
            $template = $application->getTemplate();
            if (file_exists(APATH_THEMES . '/' . $template . '/error.php')) {
                $filename = APATH_THEMES . '/' . $template . '/error.php';
Exemple #12
0
<?php

/**
 * @package angi4j
 * @copyright Copyright (C) 2009-2016 Nicholas K. Dionysopoulos. All rights reserved.
 * @author Nicholas K. Dionysopoulos - http://www.dionysopoulos.me
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL v3 or later
 */
defined('_AKEEBA') or die;
foreach (array('error', 'warning', 'success', 'info') as $type) {
    $messages = AApplication::getInstance()->getMessageQueueFor($type);
    $class = $type == 'warning' ? '' : "alert-{$type}";
    if (!empty($messages)) {
        ?>
<div class="alert <?php 
        echo $class;
        ?>
">
<?php 
        foreach ($messages as $message) {
            ?>
	<button type="button" class="close" data-dismiss="alert">&times;</button>
	<p><?php 
            echo $message;
            ?>
</p>
<?php 
        }
        ?>
</div>
<?php 
 /**
  * The main code of the Dispatcher. It spawns the necessary controller and
  * runs it.
  * 
  * @return  null
  * 
  * @throws  Exception
  */
 public function dispatch()
 {
     if (!$this->onBeforeDispatch()) {
         // For json, don't use normal 403 page, but a json encoded message
         if ($this->input->get('format', '') == 'json') {
             echo json_encode(array('code' => '403', 'error' => $this->getError()));
             exit;
         }
         throw new Exception(AText::_('ANGI_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
     }
     // Get and execute the controller
     $defaultApp = AApplication::getInstance()->getName();
     $option = $this->input->getCmd('option', $defaultApp);
     $view = $this->input->getCmd('view', $this->defaultView);
     $task = $this->input->getCmd('task', 'default');
     if (empty($task)) {
         $task = $this->getTask($view);
     }
     $this->input->set('view', $view);
     $this->input->set('task', $task);
     $config = $this->config;
     $config['input'] = $this->input;
     $controller = AController::getTmpInstance($option, $view, $config);
     $status = $controller->execute($task);
     if ($status === false) {
         throw new Exception(AText::_('ANGI_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
     }
     if (!$this->onAfterDispatch()) {
         throw new Exception(AText::_('ANGI_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
     }
     $controller->redirect();
 }
Exemple #14
0
 /**
  * Public class constructor
  *
  * @param array $config
  * @param AContainer $container Application container
  */
 public function __construct($config = array(), AContainer $container = null)
 {
     if (is_null($container)) {
         $container = AApplication::getInstance()->getContainer();
     }
     $this->container = $container;
     // Get the input
     $this->input = $this->container->input;
     // Set the $name variable
     $component = $this->input->getCmd('option', 'com_foobar');
     if (array_key_exists('option', $config)) {
         $component = $config['option'];
     }
     $name = strtolower($component);
     if (array_key_exists('name', $config)) {
         $name = $config['name'];
     }
     $this->input->set('option', $component);
     $this->name = $name;
     $this->option = $component;
     // Get the view name
     $className = get_class($this);
     if ($className == 'AModel') {
         if (array_key_exists('view', $config)) {
             $view = $config['view'];
         }
         if (empty($view)) {
             $view = $this->input->getCmd('view', 'cpanel');
         }
     } else {
         $eliminatePart = ucfirst($name) . 'Model';
         $view = strtolower(str_replace($eliminatePart, '', $className));
     }
     // Set the model state
     if (array_key_exists('state', $config)) {
         $this->state = $config['state'];
     } else {
         $this->state = new AObject();
     }
     // Set the internal state marker - used to ignore setting state from the request
     if (!empty($config['ignore_request'])) {
         $this->_state_set = true;
     }
 }
Exemple #15
0
 /**
  * Public constructor of the Controller class
  *
  * @param   array  $config  Optional configuration parameters
  * @param   AContainer  $container  Application container
  */
 public function __construct($config = array(), AContainer $container = null)
 {
     if (is_null($container)) {
         $container = AApplication::getInstance()->getContainer();
     }
     $this->container = $container;
     // Initialise
     $this->methods = array();
     $this->message = null;
     $this->messageType = 'message';
     $this->paths = array();
     $this->redirect = null;
     $this->taskMap = array();
     // Get the input
     $this->input = $this->container->input;
     // Determine the methods to exclude from the base class.
     $xMethods = get_class_methods('AController');
     // Get the public methods in this class using reflection.
     $r = new ReflectionClass($this);
     $rMethods = $r->getMethods(ReflectionMethod::IS_PUBLIC);
     foreach ($rMethods as $rMethod) {
         $mName = $rMethod->getName();
         // Add default display method if not explicitly declared.
         if (!in_array($mName, $xMethods) || $mName == 'display' || $mName == 'main') {
             $this->methods[] = strtolower($mName);
             // Auto register the methods as tasks.
             $this->taskMap[strtolower($mName)] = $mName;
         }
     }
     // Get the default values for the component and view names
     $defaultApp = $this->container->application->getName();
     $this->component = $this->input->get('option', $defaultApp, 'cmd');
     $this->view = $this->input->get('view', 'cpanel', 'cmd');
     $this->layout = $this->input->get('layout', null, 'cmd');
     // Overrides from the config
     if (array_key_exists('option', $config)) {
         $this->component = $config['option'];
     }
     if (array_key_exists('view', $config)) {
         $this->view = $config['view'];
     }
     if (array_key_exists('layout', $config)) {
         $this->layout = $config['layout'];
     }
     $this->input->set('option', $this->component);
     // Set the $name variable
     $this->name = $this->component;
     // Set the basePath variable
     $basePath = APATH_INSTALLATION . '/' . $this->component;
     if (array_key_exists('base_path', $config)) {
         $basePath = $config['base_path'];
     }
     $this->basePath = $basePath;
     // If the default task is set, register it as such
     if (array_key_exists('default_task', $config)) {
         $this->registerDefaultTask($config['default_task']);
     } else {
         $this->registerDefaultTask('main');
     }
     // Set the models prefix
     if (empty($this->model_prefix)) {
         if (array_key_exists('model_prefix', $config)) {
             // User-defined prefix
             $this->model_prefix = $config['model_prefix'];
         } else {
             $this->model_prefix = ucfirst($this->name) . 'Model';
         }
     }
     // Set the default view search path
     if (array_key_exists('view_path', $config)) {
         // User-defined dirs
         $this->setPath('view', $config['view_path']);
     } else {
         $this->setPath('view', $this->basePath . '/views');
     }
     // Set the default view.
     if (array_key_exists('default_view', $config)) {
         $this->default_view = $config['default_view'];
     } elseif (empty($this->default_view)) {
         $this->default_view = $this->getName();
     }
     // Cache the config
     $this->config = $config;
     // Set any model/view name overrides
     if (array_key_exists('viewName', $config)) {
         $this->setThisViewName($config['viewName']);
     }
     if (array_key_exists('modelName', $config)) {
         $this->setThisModelName($config['modelName']);
     }
 }
Exemple #16
0
 /**
  * Sets an entire array of search paths for templates or resources.
  *
  * @param   string  $type  The type of path to set, typically 'template'.
  * @param   mixed   $path  The new search path, or an array of search paths.  If null or false, resets to the current directory only.
  *
  * @return  void
  *
  * @since   12.2
  */
 protected function _setPath($type, $path)
 {
     // Clear out the prior search dirs
     $this->_path[$type] = array();
     // Actually add the user-specified directories
     $this->_addPath($type, $path);
     // Always add the fallback directories as last resort
     switch (strtolower($type)) {
         case 'template':
             // Set the alternative template search dir
             $app = AApplication::getInstance();
             $component = preg_replace('/[^A-Z0-9_\\.-]/i', '', $this->input->getCmd('option'));
             $fallback = APATH_THEMES . '/' . $app->getTemplate() . '/html/' . $component . '/' . $this->getName();
             $this->_addPath('template', $fallback);
             break;
     }
 }
Exemple #17
0
 public function render()
 {
     $template = AApplication::getInstance()->getTemplate();
     $templatePath = APATH_THEMES . '/' . $template;
     include $templatePath . '/index.php';
 }
Exemple #18
0
 /**
  * Gets the currently active substep
  *
  * @return string
  */
 public function getActiveSubstep()
 {
     $steps = $this->getSteps();
     $activeStep = $this->getActiveStep();
     $keys = $steps[$activeStep];
     if (empty($keys)) {
         return null;
     }
     $cursubstep = AApplication::getInstance()->getInput()->getCmd('substep', null);
     if (!in_array($cursubstep, $keys)) {
         $cursubstep = array_shift($keys);
     }
     return $cursubstep;
 }
Exemple #19
0
 public function getHash()
 {
     static $hash = null;
     if (is_null($hash)) {
         $defaultApp = AApplication::getInstance()->getName();
         $option = $this->input->getCmd('option', $defaultApp);
         $view = $this->input->getCmd('view', 'cpanel');
         $hash = "{$option}.{$view}.";
     }
     return $hash;
 }
 /**
  * Redirects the browser or returns false if no redirect is set.
  *
  * @return  boolean  False if no redirect exists.
  *
  * @since   12.2
  */
 public function redirect()
 {
     if ($this->redirect) {
         $app = AApplication::getInstance();
         $app->redirect($this->redirect, $this->message, $this->messageType);
     }
     return false;
 }