/** * Checks if the user should be granted access to the current view, * based on his Master Password setting. * * @param string view Optional. The string to check. Leave null to use the current view. * * @return bool */ public function accessAllowed($view = null) { if (interface_exists('JModel')) { $params = JModelLegacy::getInstance('Storage', 'AdmintoolsModel'); } else { $params = JModel::getInstance('Storage', 'AdmintoolsModel'); } if (empty($view)) { $view = $this->input->get('view', 'cpanel'); } $altView = F0FInflector::isPlural($view) ? F0FInflector::singularize($view) : F0FInflector::pluralize($view); if (!in_array($view, $this->views) && !in_array($altView, $this->views)) { return true; } $masterHash = $params->getValue('masterpassword', ''); if (!empty($masterHash)) { $masterHash = md5($masterHash); // Compare the master pw with the one the user entered $session = JFactory::getSession(); $userHash = $session->get('userpwhash', '', 'admintools'); if ($userHash != $masterHash) { // The login is invalid. If the view is locked I'll have to kick the user out. $lockedviews_raw = $params->getValue('lockedviews', ''); if (!empty($lockedviews_raw)) { $lockedViews = explode(",", $lockedviews_raw); if (in_array($view, $lockedViews) || in_array($altView, $lockedViews)) { return false; } } } } return true; }
private function addSubmenuLink($view, $parent = null, $icon = null) { static $activeView = null; if (empty($activeView)) { $activeView = $this->input->getCmd('view', 'cpanel'); } if ($activeView == 'cpanels') { $activeView = 'cpanel'; } $key = strtoupper($this->component) . '_TITLE_' . strtoupper($view); if (strtoupper(JText::_($key)) == $key) { $altview = F0FInflector::isPlural($view) ? F0FInflector::singularize($view) : F0FInflector::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, $icon, $parent); }
/** * Creates a View object instance and returns it * * @param string $name The name of the view, e.g. Items * @param string $prefix The prefix of the view, e.g. FoobarView * @param string $type The type of the view, usually one of Html, Raw, Json or Csv * @param array $config The configuration variables to use for creating the view * * @return F0FView */ protected function createView($name, $prefix = '', $type = '', $config = array()) { // Make sure $config is an array if (is_object($config)) { $config = (array) $config; } elseif (!is_array($config)) { $config = array(); } $result = null; // Clean the view name $viewName = preg_replace('/[^A-Z0-9_]/i', '', $name); $classPrefix = preg_replace('/[^A-Z0-9_]/i', '', $prefix); $viewType = preg_replace('/[^A-Z0-9_]/i', '', $type); if (!isset($config['input'])) { $config['input'] = $this->input; } if ($config['input'] instanceof F0FInput) { $tmpInput = $config['input']; } else { $tmpInput = new F0FInput($config['input']); } // Guess the component name and view if (!empty($prefix)) { preg_match('/(.*)View$/', $prefix, $m); $component = 'com_' . strtolower($m[1]); } else { $component = ''; } if (empty($component) && array_key_exists('input', $config)) { $component = $tmpInput->get('option', $component, 'cmd'); } if (array_key_exists('option', $config)) { if ($config['option']) { $component = $config['option']; } } $config['option'] = $component; $view = strtolower($viewName); if (empty($view) && array_key_exists('input', $config)) { $view = $tmpInput->get('view', $view, 'cmd'); } if (array_key_exists('view', $config)) { if ($config['view']) { $view = $config['view']; } } $config['view'] = $view; if (array_key_exists('input', $config)) { $tmpInput->set('option', $config['option']); $tmpInput->set('view', $config['view']); $config['input'] = $tmpInput; } // Get the component directories $componentPaths = F0FPlatform::getInstance()->getComponentBaseDirs($config['option']); // Get the base paths where the view class files are expected to live $basePaths = array($componentPaths['main'], $componentPaths['alt']); $basePaths = array_merge($this->paths['view']); // Get the alternate (singular/plural) view name $altViewName = F0FInflector::isPlural($viewName) ? F0FInflector::singularize($viewName) : F0FInflector::pluralize($viewName); $suffixes = array($viewName, $altViewName, 'default'); $filesystem = F0FPlatform::getInstance()->getIntegrationObject('filesystem'); foreach ($suffixes as $suffix) { // Build the view class name $viewClass = $classPrefix . ucfirst($suffix); if (class_exists($viewClass)) { // The class is already loaded break; } // The class is not loaded. Let's load it! $viewPath = $this->createFileName('view', array('name' => $suffix, 'type' => $viewType)); $path = $filesystem->pathFind($basePaths, $viewPath); if ($path) { require_once $path; } if (class_exists($viewClass)) { // The class was loaded successfully break; } } if (!class_exists($viewClass)) { $viewClass = 'F0FView' . ucfirst($type); } $templateOverridePath = F0FPlatform::getInstance()->getTemplateOverridePath($config['option']); // Setup View configuration options if (!array_key_exists('template_path', $config)) { $config['template_path'][] = $componentPaths['main'] . '/views/' . F0FInflector::pluralize($config['view']) . '/tmpl'; if ($templateOverridePath) { $config['template_path'][] = $templateOverridePath . '/' . F0FInflector::pluralize($config['view']); } $config['template_path'][] = $componentPaths['main'] . '/views/' . F0FInflector::singularize($config['view']) . '/tmpl'; if ($templateOverridePath) { $config['template_path'][] = $templateOverridePath . '/' . F0FInflector::singularize($config['view']); } $config['template_path'][] = $componentPaths['main'] . '/views/' . $config['view'] . '/tmpl'; if ($templateOverridePath) { $config['template_path'][] = $templateOverridePath . '/' . $config['view']; } } $extraTemplatePath = $this->configProvider->get($config['option'] . '.views.' . $config['view'] . '.config.template_path', null); if ($extraTemplatePath) { array_unshift($config['template_path'], $componentPaths['main'] . '/' . $extraTemplatePath); } if (!array_key_exists('helper_path', $config)) { $config['helper_path'] = array($componentPaths['main'] . '/helpers', $componentPaths['admin'] . '/helpers'); } $extraHelperPath = $this->configProvider->get($config['option'] . '.views.' . $config['view'] . '.config.helper_path', null); if ($extraHelperPath) { $config['helper_path'][] = $componentPaths['main'] . '/' . $extraHelperPath; } // Set up the page title $setFrontendPageTitle = $this->configProvider->get($config['option'] . '.views.' . $config['view'] . '.config.setFrontendPageTitle', null); if ($setFrontendPageTitle) { $setFrontendPageTitle = strtolower($setFrontendPageTitle); $config['setFrontendPageTitle'][] = in_array($setFrontendPageTitle, array('1', 'yes', 'true', 'on')); } $defaultPageTitle = $this->configProvider->get($config['option'] . '.views.' . $config['view'] . '.config.defaultPageTitle', null); if ($defaultPageTitle) { $config['defaultPageTitle'][] = in_array($defaultPageTitle, array('1', 'yes', 'true', 'on')); } // Set the use_hypermedia flag in $config if it's not already set if (!isset($config['use_hypermedia'])) { $config['use_hypermedia'] = $this->configProvider->get($config['option'] . '.views.' . $config['view'] . '.config.use_hypermedia', false); } // Set also the linkbar_style if (!isset($config['linkbar_style'])) { $style = $this->configProvider->get($config['option'] . '.views.' . $config['view'] . '.config.linkbar_style', false); if ($style) { $config['linkbar_style'] = $style; } } /** * Some administrative templates force format=utf (yeah, I know, what the heck, right?) when a format * URL parameter does not exist in the URL. Of course there is no such thing as F0FViewUtf (why the heck would * it be, there is no such thing as a format=utf in Joomla! for crying out loud) which causes a Fatal Error. So * we have to detect that and force $type='html'... */ if (!class_exists($viewClass) && $type != 'html') { $type = 'html'; $result = $this->createView($name, $prefix, $type, $config); } else { $result = new $viewClass($config); } return $result; }
/** * 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); //Do we have a translation for this key? if (strtoupper(JText::_($key)) == $key) { $altview = F0FInflector::isPlural($view) ? F0FInflector::singularize($view) : F0FInflector::pluralize($view); $key2 = strtoupper($this->component) . '_TITLE_' . strtoupper($altview); // Maybe we have for the alternative view? if (strtoupper(JText::_($key2)) == $key2) { // Nope, let's use the raw name $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); } }
/** * Tries to guess the controller task to execute based on the view name and * the HTTP request method. * * @param string $view The name of the view * * @return string The best guess of the task to execute */ protected function getTask($view) { // Get a default task based on plural/singular view $request_task = $this->input->getCmd('task', null); $task = F0FInflector::isPlural($view) ? 'browse' : 'edit'; // Get a potential ID, we might need it later $id = $this->input->get('id', null, 'int'); if ($id == 0) { $ids = $this->input->get('ids', array(), 'array'); if (!empty($ids)) { $id = array_shift($ids); } } // Check the request method if (!isset($_SERVER['REQUEST_METHOD'])) { $_SERVER['REQUEST_METHOD'] = 'GET'; } $requestMethod = strtoupper($_SERVER['REQUEST_METHOD']); switch ($requestMethod) { case 'POST': case 'PUT': if (!is_null($id)) { $task = 'save'; } break; case 'DELETE': if ($id != 0) { $task = 'delete'; } break; case 'GET': default: // If it's an edit without an ID or ID=0, it's really an add if ($task == 'edit' && $id == 0) { $task = 'add'; } elseif ($task == 'edit' && F0FPlatform::getInstance()->isFrontend()) { $task = 'read'; } break; } return $task; }
/** * addSubmenuLink * * @param object $view Param * @param object $parent Param * * @return void */ private function addSubmenuLink($view, $parent = null) { static $activeView = null; if (empty($activeView)) { $activeView = $this->input->getCmd('view', 'cpanel'); } if ($activeView == 'cpanels') { $activeView = 'cpanel'; } $icon_key = strtoupper($this->component) . '_ICON_' . strtoupper($view); $icon = JText::_($icon_key); $key = strtoupper($this->component) . '_TITLE_' . strtoupper($view); if (strtoupper(JText::_($key)) == $key) { $altview = F0FInflector::isPlural($view) ? F0FInflector::singularize($view) : F0FInflector::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); } if ($view == 'usermanual') { $link = 'http://documentation.extly.com/'; } elseif ($view == 'options') { $component = urlencode($this->component); $uri = (string) JUri::getInstance(); $return = urlencode(base64_encode($uri)); $link = 'index.php?option=com_config&view=component&component=' . $component . '&path=&return=' . $return; } else { $link = 'index.php?option=' . $this->component . '&view=' . $view; } $active = $view == $activeView; $this->appendLink($icon . ' ' . $name, $link, $active, null, $parent); }