Ejemplo n.º 1
0
 /**
  * Returns the alternate view template paths (a.k.a. template overrides in Joomla!-speak) for the given View name
  *
  * @param string $viewName The name of the view triggering this event
  *
  * @return array The template override paths
  */
 public function onGetViewTemplatePaths($viewName)
 {
     $container = $this->subject->getContainer();
     $application_name = $container->application_name;
     $component_name = 'com_' . strtolower($application_name);
     // That's the path in the site's current template containing template overrides
     $overridePath = Helper::getTemplateOverridePath($component_name, true);
     // The alternative view name (pluralised if the view is singular, singularised if the view is plural)
     $altViewName = Inflector::isPlural($viewName) ? Inflector::singularize($viewName) : Inflector::pluralize($viewName);
     // Remember, each path is pushed to the TOP of the path stack. This means that the least important directory
     // must go FIRST so that it ends add being added LAST.
     return array($overridePath . '/' . $altViewName, $overridePath . '/' . $viewName);
 }
Ejemplo n.º 2
0
 /**
  * Asks each observer to handle an event based on the provided arguments. The first observer to return a non-null
  * result wins. This is a *very* simplistic implementation of the Chain of Command pattern.
  *
  * Please note that in this implementation the Joomla! plugins are queried first. If any of them handled the event
  * no Observer will run. However, since Joomla! doesn't implement a chain handler, ALL Joomla! plugins handling
  * $event will fire, even if the first plugin to fire did handle the event successfully (non-null result).
  *
  * @param   string  $event  The event name to handle
  * @param   array   $args   The arguments to the event
  *
  * @return  mixed  Null if the event can't be handled by any observer
  */
 public function chainHandle($event, $args = array())
 {
     // First try using Joomla! plugins
     $resultsJoomla = Helper::runPlugins($event, $args);
     if (!empty($resultsJoomla)) {
         foreach ($resultsJoomla as $result) {
             if (!is_null($result)) {
                 return $result;
             }
         }
     }
     // Finally use the AWF Observers
     return parent::chainHandle($event, $args);
 }
Ejemplo n.º 3
0
 /**
  * Checks if the current user has enough privileges for the requested ACL
  * area.
  *
  * @param string $area The ACL area, e.g. core.manage.
  *
  * @return bool True if the user has the ACL privilege specified
  */
 protected function checkACL($controller_name, $area)
 {
     // If the area is one of false, 0, no or 403 we cancel the action
     if (in_array(strtolower($area), array('false', '0', 'no', '403'))) {
         return false;
     }
     // If the area is one of true, 1, yes we proceed with the action
     if (in_array(strtolower($area), array('true', '1', 'yes'))) {
         return true;
     }
     // If no ACL area is specified we proceed with the action
     if (empty($area)) {
         return true;
     }
     // Get the controller, model and table
     $container = $this->subject->getContainer();
     $application_name = $container->application_name;
     $component_name = 'com_' . strtolower($application_name);
     /** @var DataController $controller */
     $controller = Controller::getInstance($application_name, $controller_name, $container);
     $model = $controller->getModel();
     // If it's not a data model or it's not assets tracked just perform a regular ACL check on the component
     if (!$model instanceof DataModel || !$model->getState('_isAssetsTracked', false)) {
         return Helper::authorise($area, $component_name);
     }
     // Initialise
     $ids = null;
     // Get the IDs in the request
     $ids = $controller->getIDsFromRequest($model, false);
     // If there are no IDs there is no asset tracking, fall back to the generic ACL check
     if (empty($ids)) {
         return Helper::authorise($area, $component_name);
     }
     // This should never happen unless you screw up overriding getIDsFromRequest in your model...
     if (!is_array($ids)) {
         $ids = array($ids);
     }
     // Check the asset permissions of each record
     $resource = Inflector::singularize($controller_name);
     $isEditState = $area == 'core.edit.state';
     foreach ($ids as $id) {
         $asset = $component_name . '.' . $resource . '.' . $id;
         // Dedicated permission found, check it!
         if (Helper::authorise($area, $asset)) {
             return true;
         }
         // No dedicated permissions. Fallback on edit.own.
         if (!$isEditState && Helper::authorise('core.edit.own', $asset) && $model->hasField('created_by')) {
             // Load the record
             $model->find(array('id' => $id));
             // Make sure the record can be loaded
             if ($model->getId()) {
                 // Now test the owner is the user.
                 $owner_id = (int) $model->created_by;
                 // If I am the owner the test is successful
                 if ($owner_id == \JFactory::getUser()->id) {
                     return true;
                 }
             }
         }
     }
     return false;
 }
Ejemplo n.º 4
0
 public function initialise()
 {
     // Put a small marker to indicate that we run inside another CMS
     $this->container->segment->set('insideCMS', true);
     // Load the configuration
     $this->container->appConfig->loadConfiguration();
     // Attach the Joomla!-specific observer for Controller ACL checks
     $this->container->eventDispatcher->attach(new ControllerAcl($this->container->eventDispatcher));
     // Attach the Joomla!-specific observer for template override support
     $this->container->eventDispatcher->attach(new ViewAlternatePaths($this->container->eventDispatcher));
     // Set up the template (theme) to use – different for front-end and back-end
     if (empty($this->template) || $this->template == $this->container->application_name) {
         $template = Helper::isBackend() ? 'backend' : 'frontend';
         $this->setTemplate($template);
     }
     // Load the extra language files
     $appName = $this->container->application_name;
     if (Helper::isBackend() && substr($appName, -5) == 'Admin') {
         $appName = substr($appName, 0, -5);
     }
     $appNameLower = strtolower($appName);
     $languageTag = \JFactory::getLanguage()->getTag();
     Text::loadLanguage('en-GB', $appName, '.com_' . $appNameLower . '.ini', false, $this->container->languagePath);
     Text::loadLanguage($languageTag, $appName, '.com_' . $appNameLower . '.ini', true, $this->container->languagePath);
     // Load the framework's language file
     Text::loadLanguage('en-GB', 'lib_awf', '.ini', false, $this->container->languagePath);
     Text::loadLanguage($languageTag, 'lib_awf', '.ini', false, $this->container->languagePath);
     // In the back-end, also load front-end languages
     if (Helper::isBackend()) {
         Text::loadLanguage('en-GB', $appName, '.com_' . $appNameLower . '.ini', true, JPATH_SITE . '/language');
         Text::loadLanguage($languageTag, $appName, '.com_' . $appNameLower . '.ini', true, JPATH_SITE . '/language');
         Text::loadLanguage('en-GB', 'lib_awf', '.ini', true, JPATH_SITE . '/language');
         Text::loadLanguage($languageTag, 'lib_awf', '.ini', false, JPATH_SITE . '/language');
     }
 }
Ejemplo n.º 5
0
}
// Include the autoloader
if (false == (include_once JPATH_LIBRARIES . '/awf/Autoloader/Autoloader.php')) {
    echo 'ERROR: Autoloader not found' . PHP_EOL;
    exit(1);
}
// Add our app to the autoloader, if it's not already set
$componentName = 'com_' . strtolower($appName);
$prefixes = Awf\Autoloader\Autoloader::getInstance()->getPrefixes();
if (!array_key_exists($appName . '\\', $prefixes)) {
    \Awf\Autoloader\Autoloader::getInstance()->addMap($appName . '\\', JPATH_SITE . '/components/' . $componentName)->addMap($appName . 'Admin\\', JPATH_ADMINISTRATOR . '/components/' . $componentName)->addMap($appName . '\\', JPATH_SITE . '/components/' . $componentName . '/' . $appName)->addMap($appName . 'Admin\\', JPATH_ADMINISTRATOR . '/components/' . $componentName . '/' . $appName . 'Admin');
}
// Load Joomla!-specific translation files
\Awf\Platform\Joomla\Helper\Helper::loadTranslations($componentName);
// Find the name of the DI container class suitable for this component
$appName = \Awf\Platform\Joomla\Helper\Helper::isBackend() ? $appName . 'Admin' : $appName;
$containerClass = "\\{$appName}\\Container\\Container";
if (!class_exists($containerClass, true)) {
    $containerClass = '\\Awf\\Platform\\Joomla\\Container\\Container';
}
if (!isset($containerOverrides)) {
    $containerOverrides = array();
}
if (!isset($containerOverrides['application_name'])) {
    $containerOverrides['application_name'] = $appName;
}
// Try to create a new DI container
try {
    /** @var \Awf\Platform\Joomla\Container\Container $container */
    $container = new $containerClass($containerOverrides);
} catch (Exception $exc) {
Ejemplo n.º 6
0
 public function __construct(array $values = array())
 {
     $appNameForPaths = $values['application_name'];
     if (Helper::isBackend() && substr($appNameForPaths, -5) == 'Admin') {
         $appNameForPaths = substr($appNameForPaths, 0, -5);
     }
     // Set up the filesystem path
     if (empty($values['filesystemBase'])) {
         $values['filesystemBase'] = JPATH_ROOT;
     }
     // Set up the base path
     if (empty($values['basePath'])) {
         $basePath = '/components/com_' . $appNameForPaths . '/' . $values['application_name'];
         $values['basePath'] = (Helper::isBackend() ? JPATH_ADMINISTRATOR : JPATH_ROOT) . $basePath;
     }
     // Set up the template path
     if (empty($values['templatePath'])) {
         $values['templatePath'] = __DIR__ . '/../templates';
     }
     // Set up the temporary path
     if (empty($values['temporaryPath'])) {
         $values['temporaryPath'] = \JFactory::getConfig()->get('tmp_path', sys_get_temp_dir());
     }
     // Set up the language path
     if (empty($values['languagePath'])) {
         $values['languagePath'] = (Helper::isBackend() ? JPATH_ADMINISTRATOR : JPATH_ROOT) . '/language';
     }
     // Set up the SQL files path
     if (empty($values['sqlPath'])) {
         $values['sqlPath'] = JPATH_ADMINISTRATOR . '/components/com_' . $appNameForPaths . '/sql/xml';
     }
     // Application service
     if (!isset($this['application'])) {
         $this['application'] = function (Container $c) {
             return Application::getInstance($c->application_name, $c);
         };
     }
     // Session Manager service
     if (!isset($this['session'])) {
         $this['session'] = function () {
             return new \Awf\Platform\Joomla\Session\Manager(new \Awf\Platform\Joomla\Session\SegmentFactory(), new \Awf\Platform\Joomla\Session\CsrfTokenFactory());
         };
     }
     // Application Session Segment service
     if (!isset($this['segment'])) {
         $this['segment'] = function (Container $c) {
             if (empty($c->session_segment_name)) {
                 $c->session_segment_name = $c->application_name;
             }
             return $c->session->newSegment($c->session_segment_name);
         };
     }
     // Database Driver service
     if (!isset($this['db'])) {
         $this['db'] = function (Container $c) {
             $db = \JFactory::getDbo();
             $options = array('connection' => $db->getConnection(), 'prefix' => $db->getPrefix(), 'driver' => 'mysqli');
             switch ($db->name) {
                 case 'mysql':
                     $options['driver'] = 'Mysql';
                     break;
                 default:
                 case 'mysqli':
                     $options['driver'] = 'Mysqli';
                     break;
                 case 'sqlsrv':
                 case 'mssql':
                 case 'sqlazure':
                     $options['driver'] = 'Sqlsrv';
                     break;
                 case 'postgresql':
                     $options['driver'] = 'Postgresql';
                     break;
                 case 'pdo':
                     $options['driver'] = 'Pdo';
                     break;
                 case 'sqlite':
                     $options['driver'] = 'Sqlite';
                     break;
             }
             return Driver::getInstance($options);
         };
     }
     // Application Event Dispatcher service
     if (!isset($this['eventDispatcher'])) {
         $this['eventDispatcher'] = function (Container $c) {
             return new Dispatcher($c);
         };
     }
     // Application Configuration service
     if (!isset($values['appConfig'])) {
         $values['appConfig'] = function (Container $c) {
             return new Configuration($c);
         };
     }
     // Application Router service
     if (!isset($values['router'])) {
         $values['router'] = function (Container $c) {
             return new Router($c);
         };
     }
     // User Manager service
     if (!isset($values['userManager'])) {
         $values['userManager'] = function (Container $c) {
             return new Manager($c);
         };
     }
     parent::__construct($values);
     // Mailer Object service – returns a Joomla! JMail object
     // IMPORTANT! It has to appear AFTER the parent __construct method
     $this['mailer'] = $this->factory(function (Container $c) {
         return \JFactory::getMailer();
     });
 }
Ejemplo n.º 7
0
 public function __construct(Container $container)
 {
     \Awf\Router\Router::__construct($container);
     $this->isBackend = Helper::isBackend();
 }