public function dispatch() { // Look for controllers in the plugins folder $option = $this->input->get('option', 'com_foobar', 'cmd'); $view = $this->input->get('view', $this->defaultView, 'cmd'); $c = FOFInflector::singularize($view); $alt_path = JPATH_SITE . '/components/' . $option . '/plugins/controllers/' . $c . '.php'; JLoader::import('joomla.filesystem.file'); if (JFile::exists($alt_path)) { // The requested controller exists and there you load it... require_once $alt_path; } $this->input->set('view', $this->view); parent::dispatch(); }
/** * Renders the submenu (toolbar links) for all detected views of this component * * @return void */ public function renderSubmenu() { $views = $this->getMyViews(); if (empty($views)) { return; } $activeView = $this->input->getCmd('view', 'cpanel'); foreach ($views as $view) { // Get the view name $key = strtoupper($this->component) . '_TITLE_' . strtoupper($view); if (strtoupper(JText::_($key)) == $key) { $altview = FOFInflector::isPlural($view) ? FOFInflector::singularize($view) : FOFInflector::pluralize($view); $key2 = strtoupper($this->component) . '_TITLE_' . strtoupper($altview); if (strtoupper(JText::_($key2)) == $key2) { $name = ucfirst($view); } else { $name = JText::_($key2); } } else { $name = JText::_($key); } $link = 'index.php?option=' . $this->component . '&view=' . $view; $active = $view == $activeView; $this->appendLink($name, $link, $active); } }
/** * Get the content type for ucm * * @return string The content type alias */ public function getContentType() { if ($this->contentType) { return $this->contentType; } /** * When tags was first introduced contentType variable didn't exist - so we guess one * This will fail if content history behvaiour is enabled. This code is deprecated * and will be removed in FOF 3.0 in favour of the content type class variable */ $component = $this->input->get('option'); $view = FOFInflector::singularize($this->input->get('view')); $alias = $component . '.' . $view; return $alias; }
/** * The main code of the Dispatcher. It spawns the necessary controller and * runs it. * * @throws Exception * * @return null */ public function dispatch() { $platform = FOFPlatform::getInstance(); if (!$platform->authorizeAdmin($this->input->getCmd('option', 'com_foobar'))) { return $platform->raiseError(403, JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN')); } $this->transparentAuthentication(); // Merge English and local translations $platform->loadTranslations($this->component); $canDispatch = true; if ($platform->isCli()) { $canDispatch = $canDispatch && $this->onBeforeDispatchCLI(); } $canDispatch = $canDispatch && $this->onBeforeDispatch(); if (!$canDispatch) { $platform->setHeader('Status', '403 Forbidden', true); return $platform->raiseError(403, JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN')); } // Get and execute the controller $option = $this->input->getCmd('option', 'com_foobar'); $view = $this->input->getCmd('view', $this->defaultView); $task = $this->input->getCmd('task', null); if (empty($task)) { $task = $this->getTask($view); } // Pluralise/sungularise the view name for typical tasks if (in_array($task, array('edit', 'add', 'read'))) { $view = FOFInflector::singularize($view); } elseif (in_array($task, array('browse'))) { $view = FOFInflector::pluralize($view); } $this->input->set('view', $view); $this->input->set('task', $task); $config = $this->config; $config['input'] = $this->input; $controller = FOFController::getTmpInstance($option, $view, $config); $status = $controller->execute($task); if (!$this->onAfterDispatch()) { $platform->setHeader('Status', '403 Forbidden', true); return $platform->raiseError(403, JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN')); } $format = $this->input->get('format', 'html', 'cmd'); $format = empty($format) ? 'html' : $format; if ($format == 'html') { // In HTML views perform a redirection if ($controller->redirect()) { return; } } else { // In non-HTML views just exit the application with the proper HTTP headers if ($controller->hasRedirect()) { $headers = $platform->sendHeaders(); jexit(); } } }
public function dispatch() { if (!class_exists('AkeebaControllerDefault')) { require_once JPATH_ADMINISTRATOR . '/components/com_akeeba/controllers/default.php'; } // Merge the language overrides $paths = array(JPATH_ROOT, JPATH_ADMINISTRATOR); $jlang = JFactory::getLanguage(); $jlang->load($this->component, $paths[0], 'en-GB', true); $jlang->load($this->component, $paths[0], null, true); $jlang->load($this->component, $paths[1], 'en-GB', true); $jlang->load($this->component, $paths[1], null, true); $jlang->load($this->component . '.override', $paths[0], 'en-GB', true); $jlang->load($this->component . '.override', $paths[0], null, true); $jlang->load($this->component . '.override', $paths[1], 'en-GB', true); $jlang->load($this->component . '.override', $paths[1], null, true); FOFInflector::addWord('alice', 'alices'); // 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); } // Necessary defines for Akeeba Engine if (!defined('AKEEBAENGINE')) { define('AKEEBAENGINE', 1); // Required for accessing Akeeba Engine's factory class define('AKEEBAROOT', dirname(__FILE__) . '/akeeba'); define('ALICEROOT', dirname(__FILE__) . '/alice'); } // Setup Akeeba's ACLs, honoring laxed permissions in component's parameters, if set // Access check, Joomla! 1.6 style. $user = JFactory::getUser(); if (!$user->authorise('core.manage', 'com_akeeba')) { return JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR')); } // Make sure we have a profile set throughout the component's lifetime $session = JFactory::getSession(); $profile_id = $session->get('profile', null, 'akeeba'); if (is_null($profile_id)) { // No profile is set in the session; use default profile $session->set('profile', 1, 'akeeba'); } // Load the factory require_once JPATH_COMPONENT_ADMINISTRATOR . '/akeeba/factory.php'; @(include_once JPATH_COMPONENT_ADMINISTRATOR . '/alice/factory.php'); // Load the Akeeba Backup configuration and check user access permission $aeconfig = AEFactory::getConfiguration(); AEPlatform::getInstance()->load_configuration(); unset($aeconfig); // Preload helpers require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/includes.php'; require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/escape.php'; // Load the utils helper library AEPlatform::getInstance()->load_version_defines(); // Create a versioning tag for our static files $staticFilesVersioningTag = md5(AKEEBA_VERSION . AKEEBA_DATE); define('AKEEBAMEDIATAG', $staticFilesVersioningTag); // If JSON functions don't exist, load our compatibility layer if (!function_exists('json_encode') || !function_exists('json_decode')) { require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/jsonlib.php'; } // Look for controllers in the plugins folder $option = $this->input->get('option', 'com_foobar', 'cmd'); $view = $this->input->get('view', $this->defaultView, 'cmd'); $c = FOFInflector::singularize($view); $alt_path = JPATH_ADMINISTRATOR . '/components/' . $option . '/plugins/controllers/' . $c . '.php'; JLoader::import('joomla.filesystem.file'); if (JFile::exists($alt_path)) { // The requested controller exists and there you load it... require_once $alt_path; } $this->input->set('view', $this->view); parent::dispatch(); }
/** * Return a list of the view template paths for this component. * * @param string $component The name of the component. For Joomla! this * is something like "com_example" * @param string $view The name of the view you're looking a * template for * @param string $layout The layout name to load, e.g. 'default' * @param string $tpl The sub-template name to load (null by default) * @param boolean $strict If true, only the specified layout will be searched for. * Otherwise we'll fall back to the 'default' layout if the * specified layout is not found. * * @see FOFPlatformInterface::getViewTemplateDirs() * * @return array */ public function getViewTemplatePaths($component, $view, $layout = 'default', $tpl = null, $strict = false) { $isAdmin = $this->isBackend(); $basePath = $isAdmin ? 'admin:' : 'site:'; $basePath .= $component . '/'; $altBasePath = $basePath; $basePath .= $view . '/'; $altBasePath .= (FOFInflector::isSingular($view) ? FOFInflector::pluralize($view) : FOFInflector::singularize($view)) . '/'; if ($strict) { $paths = array($basePath . $layout . ($tpl ? "_{$tpl}" : ''), $altBasePath . $layout . ($tpl ? "_{$tpl}" : '')); } else { $paths = array($basePath . $layout . ($tpl ? "_{$tpl}" : ''), $basePath . $layout, $basePath . 'default' . ($tpl ? "_{$tpl}" : ''), $basePath . 'default', $altBasePath . $layout . ($tpl ? "_{$tpl}" : ''), $altBasePath . $layout, $altBasePath . 'default' . ($tpl ? "_{$tpl}" : ''), $altBasePath . 'default'); $paths = array_unique($paths); } return $paths; }
/** * Normalises the format of a relation name * * @param string $itemName The raw relation name * @param boolean $pluralise Should I pluralise the name? If not, I will singularise it * * @return string The normalised relation key name */ protected function normaliseItemName($itemName, $pluralise = false) { // Explode the item name $itemNameParts = explode('_', $itemName); // If we have multiple parts the first part is considered to be the component name if (count($itemNameParts) > 1) { $prefix = array_shift($itemNameParts); } else { $prefix = null; } // If we still have multiple parts we need to pluralise/singularise the last part and join everything in // CamelCase format if (count($itemNameParts) > 1) { $name = array_pop($itemNameParts); $name = $pluralise ? FOFInflector::pluralize($name) : FOFInflector::singularize($name); $itemNameParts[] = $name; $itemName = FOFInflector::implode($itemNameParts); } else { $name = array_pop($itemNameParts); $itemName = $pluralise ? FOFInflector::pluralize($name) : FOFInflector::singularize($name); } if (!empty($prefix)) { $itemName = $prefix . '_' . $itemName; } return $itemName; }
/** * Overrides the built-in loadTemplate function with an FOF-specific one. * Our overriden function uses loadAnyTemplate to provide smarter view * template loading. * * @param string $tpl The name of the template file to parse * @param boolean $strict Should we use strict naming, i.e. force a non-empty $tpl? * * @return mixed A string if successful, otherwise a JError object */ public function loadTemplate($tpl = null, $strict = false) { list($isCli, $isAdmin) = FOFDispatcher::isCliAdmin(); $basePath = $isAdmin ? 'admin:' : 'site:'; $basePath .= $this->config['option'] . '/'; $altBasePath = $basePath; $basePath .= $this->config['view'] . '/'; $altBasePath .= (FOFInflector::isSingular($this->config['view']) ? FOFInflector::pluralize($this->config['view']) : FOFInflector::singularize($this->config['view'])) . '/'; if ($strict) { $paths = array($basePath . $this->getLayout() . ($tpl ? "_{$tpl}" : ''), $altBasePath . $this->getLayout() . ($tpl ? "_{$tpl}" : '')); } else { $paths = array($basePath . $this->getLayout() . ($tpl ? "_{$tpl}" : ''), $basePath . $this->getLayout(), $basePath . 'default' . ($tpl ? "_{$tpl}" : ''), $basePath . 'default', $altBasePath . $this->getLayout() . ($tpl ? "_{$tpl}" : ''), $altBasePath . $this->getLayout(), $altBasePath . 'default' . ($tpl ? "_{$tpl}" : ''), $altBasePath . 'default'); } foreach ($paths as $path) { $result = $this->loadAnyTemplate($path); if (!$result instanceof Exception) { break; } } if (version_compare(JVERSION, '3.0', 'lt') && $result instanceof Exception) { JError::raiseError($result->getCode(), $result->getMessage()); } return $result; }
/** * Guesses the best candidate for the path to use for a particular form. * * @param string $source The name of the form file to load, without the .xml extension. * @param array $paths The paths to look into. You can declare this to override the default FOF paths. * * @return mixed A string if the path and filename of the form to load is found, false otherwise. * * @since 2.0 */ public function findFormFilename($source, $paths = array()) { $option = $this->input->getCmd('option', 'com_foobar'); $view = $this->input->getCmd('view', 'cpanels'); $componentPaths = FOFPlatform::getInstance()->getComponentBaseDirs($option); $file_root = $componentPaths['main']; $alt_file_root = $componentPaths['alt']; $template_root = FOFPlatform::getInstance()->getTemplateOverridePath($option); if (empty($paths)) { // Set up the paths to look into $paths = array($template_root . '/' . $view, $template_root . '/' . FOFInflector::singularize($view), $template_root . '/' . FOFInflector::pluralize($view), $file_root . '/views/' . $view . '/tmpl', $file_root . '/views/' . FOFInflector::singularize($view) . '/tmpl', $file_root . '/views/' . FOFInflector::pluralize($view) . '/tmpl', $alt_file_root . '/views/' . $view . '/tmpl', $alt_file_root . '/views/' . FOFInflector::singularize($view) . '/tmpl', $alt_file_root . '/views/' . FOFInflector::pluralize($view) . '/tmpl', $file_root . '/models/forms', $alt_file_root . '/models/forms'); } // Set up the suffixes to look into $suffixes = array(); $temp_suffixes = FOFPlatform::getInstance()->getTemplateSuffixes(); if (!empty($temp_suffixes)) { foreach ($temp_suffixes as $suffix) { $suffixes[] = $suffix . '.xml'; } } $suffixes[] = '.xml'; // Look for all suffixes in all paths JLoader::import('joomla.filesystem.file'); $result = false; foreach ($paths as $path) { foreach ($suffixes as $suffix) { $filename = $path . '/' . $source . $suffix; if (JFile::exists($filename)) { $result = $filename; break; } } if ($result) { break; } } return $result; }
/** * ACL check before changing the publish status of a record; override to customise * * @return boolean True to allow the method to run */ protected function onBeforeUnpublish() { $privilege = $this->configProvider->get($this->component . '.views.' . FOFInflector::singularize($this->view) . '.acl.unpublish', 'core.edit.state'); return $this->checkACL($privilege); }
/** * Get the content type for ucm * * @return string The content type alias */ public function getContentType() { $component = $this->input->get('option'); $view = FOFInflector::singularize($this->input->get('view')); $alias = $component . '.' . $view; return $alias; }
/** * Guesses the best candidate for the path to use for a particular form. * * @param string $source The name of the form file to load, without the .xml extension * * @return string The path and filename of the form to load * * @since 2.0 */ public function findFormFilename($source) { // Get some useful variables list($isCli, $isAdmin) = FOFDispatcher::isCliAdmin(); $option = $this->input->getCmd('option', 'com_foobar'); $view = $this->input->getCmd('view', 'cpanels'); if (!$isCli) { $template = JFactory::getApplication()->getTemplate(); } else { $template = 'cli'; } $file_root = $isAdmin ? JPATH_ADMINISTRATOR : JPATH_SITE; $file_root .= '/components/' . $option; $alt_file_root = $isAdmin ? JPATH_SITE : JPATH_ADMINISTRATOR; $alt_file_root .= '/components/' . $option; $template_root = $isAdmin ? JPATH_ADMINISTRATOR : JPATH_SITE; $template_root .= '/templates/' . $template . '/html/' . $option; // Set up the paths to look into $paths = array($template_root . '/' . $view, $template_root . '/' . FOFInflector::singularize($view), $template_root . '/' . FOFInflector::pluralize($view), $file_root . '/views/' . $view . '/tmpl', $file_root . '/views/' . FOFInflector::singularize($view) . '/tmpl', $file_root . '/views/' . FOFInflector::pluralize($view) . '/tmpl', $alt_file_root . '/views/' . $view . '/tmpl', $alt_file_root . '/views/' . FOFInflector::singularize($view) . '/tmpl', $alt_file_root . '/views/' . FOFInflector::pluralize($view) . '/tmpl', $file_root . '/models/forms', $alt_file_root . '/models/forms'); // Set up the suffixes to look into $jversion = new JVersion(); $versionParts = explode('.', $jversion->RELEASE); $majorVersion = array_shift($versionParts); $suffixes = array('.j' . str_replace('.', '', $jversion->getHelpVersion()) . '.xml', '.j' . $majorVersion . '.xml', '.xml'); unset($jversion, $versionParts, $majorVersion); // Look for all suffixes in all paths JLoader::import('joomla.filesystem.file'); $result = false; foreach ($paths as $path) { foreach ($suffixes as $suffix) { $filename = $path . '/' . $source . $suffix; if (JFile::exists($filename)) { $result = $filename; break; } } if ($result) { break; } } return $result; }
/** * Returns a static object instance of a particular table type * * @param string $type The table name * @param string $prefix The prefix of the table class * @param array $config Optional configuration variables * * @return FOFTable */ public static function &getAnInstance($type = null, $prefix = 'JTable', $config = array()) { static $instances = array(); // Make sure $config is an array if (is_object($config)) { $config = (array) $config; } elseif (!is_array($config)) { $config = array(); } // Guess the component name if (!array_key_exists('input', $config)) { $config['input'] = new FOFInput(); } if ($config['input'] instanceof FOFInput) { $tmpInput = $config['input']; } else { $tmpInput = new FOFInput($config['input']); } $option = $tmpInput->getCmd('option', ''); $tmpInput->set('option', $option); $config['input'] = $tmpInput; if (!in_array($prefix, array('Table', 'JTable'))) { preg_match('/(.*)Table$/', $prefix, $m); $option = 'com_' . strtolower($m[1]); } if (array_key_exists('option', $config)) { $option = $config['option']; } $config['option'] = $option; if (!array_key_exists('view', $config)) { $config['view'] = $config['input']->getCmd('view', 'cpanel'); } if (is_null($type)) { if ($prefix == 'JTable') { $prefix = 'Table'; } $type = $config['view']; } $type = preg_replace('/[^A-Z0-9_\\.-]/i', '', $type); $tableClass = $prefix . ucfirst($type); $configProvider = new FOFConfigProvider(); $configProviderKey = $option . '.views.' . FOFInflector::singularize($type) . '.config.'; if (!array_key_exists($tableClass, $instances)) { if (!class_exists($tableClass)) { list($isCLI, $isAdmin) = FOFDispatcher::isCliAdmin(); if (!$isAdmin) { $basePath = JPATH_SITE; } else { $basePath = JPATH_ADMINISTRATOR; } $searchPaths = array($basePath . '/components/' . $config['option'] . '/tables', JPATH_ADMINISTRATOR . '/components/' . $config['option'] . '/tables'); if (array_key_exists('tablepath', $config)) { array_unshift($searchPaths, $config['tablepath']); } $altPath = $configProvider->get($configProviderKey . 'table_path', null); if ($altPath) { array_unshift($searchPaths, JPATH_ADMINISTRATOR . '/components/' . $option . '/' . $altPath); } JLoader::import('joomla.filesystem.path'); $path = JPath::find($searchPaths, strtolower($type) . '.php'); if ($path) { require_once $path; } } if (!class_exists($tableClass)) { $tableClass = 'FOFTable'; } $tbl_common = str_replace('com_', '', $config['option']) . '_'; if (!array_key_exists('tbl', $config)) { $config['tbl'] = strtolower('#__' . $tbl_common . strtolower(FOFInflector::pluralize($type))); } $altTbl = $configProvider->get($configProviderKey . 'tbl', null); if ($altTbl) { $config['tbl'] = $altTbl; } if (!array_key_exists('tbl_key', $config)) { $keyName = FOFInflector::singularize($type); $config['tbl_key'] = strtolower($tbl_common . $keyName . '_id'); } $altTblKey = $configProvider->get($configProviderKey . 'tbl_key', null); if ($altTblKey) { $config['tbl_key'] = $altTblKey; } if (!array_key_exists('db', $config)) { $config['db'] = JFactory::getDBO(); } $instance = new $tableClass($config['tbl'], $config['tbl_key'], $config['db']); $instance->setInput($tmpInput); if (array_key_exists('trigger_events', $config)) { $instance->setTriggerEvents($config['trigger_events']); } $instances[$tableClass] = $instance; } return $instances[$tableClass]; }
public static function getPluralization($name, $form = 'singular') { static $cache = array(); if (!empty($cache[$name . '.' . $form])) { return $cache[$name . '.' . $form]; } //Pluralization if (JFile::exists(JPATH_LIBRARIES . '/fof/include.php')) { if (!defined('FOF_INCLUDED')) { require_once JPATH_LIBRARIES . '/fof/include.php'; } } else { if (JFile::exists(JPATH_LIBRARIES . '/fof/inflector/inflector.php')) { require_once JPATH_LIBRARIES . '/fof/inflector/inflector.php'; } else { require_once JPATH_COMPONENT . '/helpers/fofinflector.php'; } } $plural = null; //$inflector = new FOFInflector(); //see if name is singular, if so get a plural if (FOFInflector::isSingular($name)) { $plural = FOFInflector::pluralize($name); } //if still no plural check if name is plural if (empty($plural)) { if (FOFInflector::isPlural($name)) { //if its a plural switch them $plural = $name; //and get a singular $name = FOFInflector::singularize($name); } } //if still no plural just make one anyway if (empty($plural)) { $plural = $name . 's'; } $cache[$name . '.plural'] = $plural; $cache[$name . '.singular'] = $name; return $cache[$name . '.' . $form]; }
/** * Public constructor. Instantiates a FOFView object. * * @param array $config The configuration data array */ public function __construct($config = array()) { // Make sure $config is an array if (is_object($config)) { $config = (array) $config; } elseif (!is_array($config)) { $config = array(); } // Get the input if (array_key_exists('input', $config)) { if ($config['input'] instanceof FOFInput) { $this->input = $config['input']; } else { $this->input = new FOFInput($config['input']); } } else { $this->input = new FOFInput(); } parent::__construct($config); $component = 'com_foobar'; // Get the component name if (array_key_exists('input', $config)) { if ($config['input'] instanceof FOFInput) { $tmpInput = $config['input']; } else { $tmpInput = new FOFInput($config['input']); } $component = $tmpInput->getCmd('option', ''); } else { $tmpInput = $this->input; } if (array_key_exists('option', $config)) { if ($config['option']) { $component = $config['option']; } } $config['option'] = $component; // Get the view name $view = null; if (array_key_exists('input', $config)) { $view = $tmpInput->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 if (array_key_exists('input', $config)) { $tmpInput->set('option', $config['option']); $tmpInput->set('view', $config['view']); } // Set the view name if (array_key_exists('name', $config)) { $this->_name = $config['name']; } else { $this->_name = $config['view']; } $tmpInput->set('view', $this->_name); $config['input'] = $tmpInput; $config['name'] = $this->_name; $config['view'] = $this->_name; // Get the component directories $componentPaths = FOFPlatform::getInstance()->getComponentBaseDirs($config['option']); // Set the charset (used by the variable escaping functions) if (array_key_exists('charset', $config)) { FOFPlatform::getInstance()->logDeprecated('Setting a custom charset for escaping in FOFView\'s constructor is deprecated. Override FOFView::escape() instead.'); $this->_charset = $config['charset']; } // User-defined escaping callback if (array_key_exists('escape', $config)) { $this->setEscape($config['escape']); } // Set a base path for use by the view if (array_key_exists('base_path', $config)) { $this->_basePath = $config['base_path']; } else { $this->_basePath = $componentPaths['main']; } // Set the default template search path if (array_key_exists('template_path', $config)) { // User-defined dirs $this->_setPath('template', $config['template_path']); } else { $altView = FOFInflector::isSingular($this->getName()) ? FOFInflector::pluralize($this->getName()) : FOFInflector::singularize($this->getName()); $this->_setPath('template', $this->_basePath . '/views/' . $altView . '/tmpl'); $this->_addPath('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; if (!FOFPlatform::getInstance()->isCli()) { $this->baseurl = FOFPlatform::getInstance()->URIbase(true); $fallback = FOFPlatform::getInstance()->getTemplateOverridePath($component) . '/' . $this->getName(); $this->_addPath('template', $fallback); } }
/** * Guesses the best candidate for the path to use for a particular form. * * @param string $source The name of the form file to load, without the .xml extension. * @param array $paths The paths to look into. You can declare this to override the default FOF paths. * * @return mixed A string if the path and filename of the form to load is found, false otherwise. * * @since 2.0 */ public function findFormFilename($source, $paths = array()) { // TODO Should we read from internal variables instead of the input? With a temp instance we have no input $option = $this->input->getCmd('option', 'com_foobar'); $view = $this->name; $componentPaths = FOFPlatform::getInstance()->getComponentBaseDirs($option); $file_root = $componentPaths['main']; $alt_file_root = $componentPaths['alt']; $template_root = FOFPlatform::getInstance()->getTemplateOverridePath($option); if (empty($paths)) { // Set up the paths to look into // PLEASE NOTE: If you ever change this, please update Model Unit tests, too, since we have to // copy these default folders (we have to add the protocol for the virtual filesystem) $paths = array($template_root . '/' . $view, $template_root . '/' . FOFInflector::singularize($view), $template_root . '/' . FOFInflector::pluralize($view), $file_root . '/views/' . $view . '/tmpl', $file_root . '/views/' . FOFInflector::singularize($view) . '/tmpl', $file_root . '/views/' . FOFInflector::pluralize($view) . '/tmpl', $alt_file_root . '/views/' . $view . '/tmpl', $alt_file_root . '/views/' . FOFInflector::singularize($view) . '/tmpl', $alt_file_root . '/views/' . FOFInflector::pluralize($view) . '/tmpl', $file_root . '/models/forms', $alt_file_root . '/models/forms'); } $paths = array_unique($paths); // Set up the suffixes to look into $suffixes = array(); $temp_suffixes = FOFPlatform::getInstance()->getTemplateSuffixes(); if (!empty($temp_suffixes)) { foreach ($temp_suffixes as $suffix) { $suffixes[] = $suffix . '.xml'; } } $suffixes[] = '.xml'; // Look for all suffixes in all paths $result = false; $filesystem = FOFPlatform::getInstance()->getIntegrationObject('filesystem'); foreach ($paths as $path) { foreach ($suffixes as $suffix) { $filename = $path . '/' . $source . $suffix; if ($filesystem->fileExists($filename)) { $result = $filename; break; } } if ($result) { break; } } return $result; }
/** * Autoload Helpers * * @param string $class_name The name of the class to load * * @return void */ public function autoload_fof_helper($class_name) { JLog::add(__METHOD__ . "() autoloading {$class_name}", JLog::DEBUG, 'fof'); static $isCli = null, $isAdmin = null; if (is_null($isCli) && is_null($isAdmin)) { list($isCli, $isAdmin) = FOFDispatcher::isCliAdmin(); } if (strpos($class_name, 'Helper') === false) { return; } // Change from camel cased into a lowercase array $class_modified = preg_replace('/(\\s)+/', '_', $class_name); $class_modified = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $class_modified)); $parts = explode('_', $class_modified); // We need three parts in the name if (count($parts) != 3) { return; } // We need the second part to be "model" if ($parts[1] != 'helper') { return; } // Get the information about this class $component_raw = $parts[0]; $component = 'com_' . $parts[0]; $view = $parts[2]; // Is this an FOF 2.1 or later component? if (!$this->isFOFComponent($component)) { return; } // Get the alternate view and class name (opposite singular/plural name) $alt_view = FOFInflector::isSingular($view) ? FOFInflector::pluralize($view) : FOFInflector::singularize($view); $alt_class = FOFInflector::camelize($component_raw . '_helper_' . $alt_view); // Get the proper and alternate paths and file names $componentPaths = FOFPlatform::getInstance()->getComponentBaseDirs($component); $file = "/helpers/{$view}.php"; $altFile = "/helpers/{$alt_view}.php"; $path = $componentPaths['main']; $altPath = $componentPaths['alt']; // Try to find the proper class in the proper path if (file_exists($path . $file)) { @(include_once $path . $file); } // Try to find the proper class in the alternate path if (!class_exists($class_name) && file_exists($altPath . $file)) { @(include_once $altPath . $file); } // Try to find the alternate class in the proper path if (!class_exists($alt_class) && file_exists($path . $altFile)) { @(include_once $path . $altFile); } // Try to find the alternate class in the alternate path if (!class_exists($alt_class) && file_exists($altPath . $altFile)) { @(include_once $altPath . $altFile); } // If the alternate class exists just map the class to the alternate if (!class_exists($class_name) && class_exists($alt_class)) { $this->class_alias($alt_class, $class_name); } }
/** * The main code of the Dispatcher. It spawns the necessary controller and * runs it. * * @return null|Exception */ public function dispatch() { // Timezone fix; avoids errors printed out by PHP 5.3.3+ list($isCli, $isAdmin) = self::isCliAdmin(); if ($isAdmin) { // Master access check for the back-end, Joomla! 1.6 style. $user = JFactory::getUser(); if (!$user->authorise('core.manage', $this->input->getCmd('option', 'com_foobar')) && !$user->authorise('core.admin', $this->input->getCmd('option', 'com_foobar'))) { if (version_compare(JVERSION, '3.0', 'ge')) { throw new Exception(JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403); } else { return JError::raiseError('403', JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN')); } } } elseif (!$isCli) { // Perform transparent authentication for front-end requests $this->transparentAuthentication(); } // Merge English and local translations if ($isAdmin) { $paths = array(JPATH_ROOT, JPATH_ADMINISTRATOR); } else { $paths = array(JPATH_ADMINISTRATOR, JPATH_ROOT); } $jlang = JFactory::getLanguage(); $jlang->load($this->component, $paths[0], 'en-GB', true); $jlang->load($this->component, $paths[0], null, true); $jlang->load($this->component, $paths[1], 'en-GB', true); $jlang->load($this->component, $paths[1], null, true); $canDispatch = true; if ($isCli) { $canDispatch = $canDispatch && $this->onBeforeDispatchCLI(); } $canDispatch = $canDispatch && $this->onBeforeDispatch(); if (!$canDispatch) { JResponse::setHeader('Status', '403 Forbidden', true); if (version_compare(JVERSION, '3.0', 'ge')) { throw new Exception(JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403); } else { return JError::raiseError('403', JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN')); } } // Get and execute the controller $option = $this->input->getCmd('option', 'com_foobar'); $view = $this->input->getCmd('view', $this->defaultView); $task = $this->input->getCmd('task', ''); if (empty($task)) { $task = $this->getTask($view); } // Pluralise/sungularise the view name for typical tasks if (in_array($task, array('edit', 'add', 'read'))) { $view = FOFInflector::singularize($view); } elseif (in_array($task, array('browse'))) { $view = FOFInflector::pluralize($view); } $this->input->set('view', $view); $this->input->set('task', $task); $config = $this->config; $config['input'] = $this->input; $controller = FOFController::getTmpInstance($option, $view, $config); $status = $controller->execute($task); if (!$this->onAfterDispatch()) { JResponse::setHeader('Status', '403 Forbidden', true); if (version_compare(JVERSION, '3.0', 'ge')) { throw new Exception(JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403); } else { return JError::raiseError('403', JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN')); } } $format = $this->input->get('format', 'html', 'cmd'); $format = empty($format) ? 'html' : $format; if ($format == 'html') { // In HTML views perform a redirection if ($controller->redirect()) { return; } } else { // In non-HTML views just exit the application with the proper HTTP headers if ($controller->hasRedirect()) { $headers = JResponse::sendHeaders(); jexit(); } } }