function AkeebasubsParseRoute($segments) { // accepted views: $views = array('new', 'thankyou', 'cancelled', 'level', 'levels', 'message', 'subscribe', 'subscription', 'subscriptions', 'callback', 'validate', 'userinfo', 'invoices', 'invoice'); // accepted layouts: $layoutsAccepted = array('message' => array('order', 'cancel'), 'invoice' => array('item')); // default view $default = 'levels'; $mObject = JFactory::getApplication()->getMenu()->getActive(); $menu = is_object($mObject) ? $mObject->query : array(); // circumvent the auto-segment decoding $segments = str_replace(':', '-', $segments); $vars = array(); // if there's no view, but the menu item has view info, we use that if (count($segments)) { if (!in_array($segments[0], $views)) { $vars['view'] = array_key_exists('view', $menu) ? $menu['view'] : $default; } else { $vars['view'] = array_shift($segments); } switch ($vars['view']) { case 'new': $vars['view'] = 'level'; break; case 'invoices': $vars['view'] = 'invoices'; $vars['layout'] = 'default'; break; case 'invoice': $vars['view'] = 'invoice'; $vars['layout'] = 'item'; break; case 'thankyou': $vars['view'] = 'message'; $vars['layout'] = 'order'; break; case 'cancelled': $vars['view'] = 'message'; $vars['layout'] = 'cancel'; break; case 'userinfo': $vars['view'] = 'userinfo'; $vars['layout'] = 'default'; break; } array_push($segments, $vars['view']); if (array_key_exists('layout', $vars)) { array_unshift($segments, $vars['layout']); } $layouts = array_key_exists($vars['view'], $layoutsAccepted) ? $layoutsAccepted[$vars['view']] : array(); if (!in_array($segments[0], $layouts)) { $vars['layout'] = array_key_exists('layout', $menu) ? $menu['layout'] : 'default'; } else { $vars['layout'] = array_shift($segments); } // if we are in a singular view, the next item is the slug, unless we are in the userinfo view if (F0FInflector::isSingular($vars['view']) && $vars['view'] != 'userinfo') { if (in_array($vars['view'], array('subscription', 'invoice'))) { $vars['id'] = array_shift($segments); } else { $vars['slug'] = array_shift($segments); } } } return $vars; }
/** * 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 F0FPlatformInterface::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 .= (F0FInflector::isSingular($view) ? F0FInflector::pluralize($view) : F0FInflector::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; }
/** * Public constructor. Instantiates a F0FView 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 F0FInput) { $this->input = $config['input']; } else { $this->input = new F0FInput($config['input']); } } else { $this->input = new F0FInput(); } parent::__construct($config); $component = 'com_foobar'; // Get the component name if (array_key_exists('input', $config)) { if ($config['input'] instanceof F0FInput) { $tmpInput = $config['input']; } else { $tmpInput = new F0FInput($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 = F0FPlatform::getInstance()->getComponentBaseDirs($config['option']); // Set the charset (used by the variable escaping functions) if (array_key_exists('charset', $config)) { F0FPlatform::getInstance()->logDeprecated('Setting a custom charset for escaping in F0FView\'s constructor is deprecated. Override F0FView::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 = F0FInflector::isSingular($this->getName()) ? F0FInflector::pluralize($this->getName()) : F0FInflector::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 (!F0FPlatform::getInstance()->isCli()) { $this->baseurl = F0FPlatform::getInstance()->URIbase(true); $fallback = F0FPlatform::getInstance()->getTemplateOverridePath($component) . '/' . $this->getName(); $this->_addPath('template', $fallback); } }
/** * Autoload Helpers * * @param string $class_name The name of the class to load * * @return void */ public function autoload_fof_helper($class_name) { F0FPlatform::getInstance()->logDebug(__METHOD__ . "() autoloading {$class_name}"); static $isCli = null, $isAdmin = null; if (is_null($isCli) && is_null($isAdmin)) { list($isCli, $isAdmin) = F0FDispatcher::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 F0F 2.1 or later component? if (!$this->isF0FComponent($component)) { return; } // Get the alternate view and class name (opposite singular/plural name) $alt_view = F0FInflector::isSingular($view) ? F0FInflector::pluralize($view) : F0FInflector::singularize($view); $alt_class = F0FInflector::camelize($component_raw . '_helper_' . $alt_view); // Get the proper and alternate paths and file names $componentPaths = F0FPlatform::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); } }
} if ($shGETVars['layout'] == 'order') { $newView = 'thankyou'; } else { $newView = 'cancelled'; } shRemoveFromGETVarsList('layout'); } elseif ($newView == 'userinfo') { if (!array_key_exists('layout', $shGETVars)) { shRemoveFromGETVarsList('layout'); } } $title[] = $newView; shRemoveFromGETVarsList('view'); shRemoveFromGETVarsList('layout'); // Add the slug if ($newView != 'userinfo') { if (array_key_exists('slug', $shGETVars) && (F0FInflector::isSingular($title[1]) || $title[1] == 'new')) { $title[2] = $shGETVars['slug']; shRemoveFromGETVarsList('slug'); } elseif (array_key_exists('id', $shGETVars) && $title[1] == 'subscription') { $title[2] = $shGETVars['id']; shRemoveFromGETVarsList('id'); } } $title[] = '/'; // ------------------ standard plugin finalize function - don't change --------------------------- if ($dosef) { $string = shFinalizePlugin($string, $title, $shAppendString, $shItemidString, isset($limit) ? @$limit : null, isset($limitstart) ? @$limitstart : null, isset($shLangName) ? @$shLangName : null); } // ------------------ standard plugin finalize function - don't change ---------------------------