/**
  *
  * @staticvar array $instances
  * @param type $option
  * @param type $view
  * @param type $config
  * @return FOFToolbar
  */
 public static function &getAnInstance($option = null, $config = array())
 {
     static $instances = array();
     // Make sure $config is an array
     if (is_object($config)) {
         $config = (array) $config;
     } elseif (!is_array($config)) {
         $config = array();
     }
     $hash = $option;
     if (!array_key_exists($hash, $instances)) {
         if (array_key_exists('input', $config)) {
             if ($config['input'] instanceof FOFInput) {
                 $input = $config['input'];
             } else {
                 $input = new FOFInput($config['input']);
             }
         } else {
             $input = new FOFInput();
         }
         $config['option'] = !is_null($option) ? $option : $input->getCmd('option', 'com_foobar');
         $input->set('option', $config['option']);
         $config['input'] = $input;
         $className = ucfirst(str_replace('com_', '', $config['option'])) . 'Toolbar';
         if (!class_exists($className)) {
             list($isCli, $isAdmin) = FOFDispatcher::isCliAdmin();
             if ($isAdmin) {
                 $basePath = JPATH_ADMINISTRATOR;
             } elseif ($isCli) {
                 $basePath = JPATH_ROOT;
             } else {
                 $basePath = JPATH_SITE;
             }
             $searchPaths = array($basePath . '/components/' . $config['option'], $basePath . '/components/' . $config['option'] . '/toolbars', JPATH_ADMINISTRATOR . '/components/' . $config['option'], JPATH_ADMINISTRATOR . '/components/' . $config['option'] . '/toolbars');
             if (array_key_exists('searchpath', $config)) {
                 array_unshift($searchPaths, $config['searchpath']);
             }
             JLoader::import('joomla.filesystem.path');
             $path = JPath::find($searchPaths, 'toolbar.php');
             if ($path) {
                 require_once $path;
             }
         }
         if (!class_exists($className)) {
             $className = 'FOFToolbar';
         }
         $instance = new $className($config);
         $instances[$hash] = $instance;
     }
     return $instances[$hash];
 }
Beispiel #2
0
 /**
  * Echoes any HTML to show before the view template
  *
  * @param   string    $view    The current view
  * @param   string    $task    The current task
  * @param   FOFInput  $input   The input array (request parameters)
  * @param   array     $config  The view configuration array
  *
  * @return  void
  */
 public function preRender($view, $task, $input, $config = array())
 {
     $format = $input->getCmd('format', 'html');
     if (empty($format)) {
         $format = 'html';
     }
     if ($format != 'html') {
         return;
     }
     // Render the submenu and toolbar
     if ($input->getBool('render_toolbar', true)) {
         $this->renderButtons($view, $task, $input, $config);
         $this->renderLinkbar($view, $task, $input, $config);
     }
 }
Beispiel #3
0
 /**
  * Echoes any HTML to show after the view template
  *
  * @param   string    $view    The current view
  * @param   string    $task    The current task
  * @param   FOFInput  $input   The input array (request parameters)
  * @param   array     $config  The view configuration array
  *
  * @return  void
  */
 public function postRender($view, $task, $input, $config = array())
 {
     $format = $input->getCmd('format', 'html');
     if (empty($format)) {
         $format = 'html';
     }
     if ($format != 'html') {
         return;
     }
     // Closing tag only if we're not in CLI
     if (FOFPlatform::getInstance()->isCli()) {
         return;
     }
     echo "</div>\n";
     // Closes akeeba-renderjoomla div
 }
Beispiel #4
0
 /**
  * Gets an instance of a component's toolbar
  *
  * @param   string  $option  The name of the component
  * @param   array   $config  The configuration array for the component
  *
  * @return  FOFToolbar  The toolbar instance for the component
  */
 public static function &getAnInstance($option = null, $config = array())
 {
     static $instances = array();
     // Make sure $config is an array
     if (is_object($config)) {
         $config = (array) $config;
     } elseif (!is_array($config)) {
         $config = array();
     }
     $hash = $option;
     if (!array_key_exists($hash, $instances)) {
         if (array_key_exists('input', $config)) {
             if ($config['input'] instanceof FOFInput) {
                 $input = $config['input'];
             } else {
                 $input = new FOFInput($config['input']);
             }
         } else {
             $input = new FOFInput();
         }
         $config['option'] = !is_null($option) ? $option : $input->getCmd('option', 'com_foobar');
         $input->set('option', $config['option']);
         $config['input'] = $input;
         $className = ucfirst(str_replace('com_', '', $config['option'])) . 'Toolbar';
         if (!class_exists($className)) {
             $componentPaths = FOFPlatform::getInstance()->getComponentBaseDirs($config['option']);
             $searchPaths = array($componentPaths['main'], $componentPaths['main'] . '/toolbars', $componentPaths['alt'], $componentPaths['alt'] . '/toolbars');
             if (array_key_exists('searchpath', $config)) {
                 array_unshift($searchPaths, $config['searchpath']);
             }
             $filesystem = FOFPlatform::getInstance()->getIntegrationObject('filesystem');
             $path = $filesystem->pathFind($searchPaths, 'toolbar.php');
             if ($path) {
                 require_once $path;
             }
         }
         if (!class_exists($className)) {
             $className = 'FOFToolbar';
         }
         $instance = new $className($config);
         $instances[$hash] = $instance;
     }
     return $instances[$hash];
 }
Beispiel #5
0
	private function setToolbarTitle()
	{
		$subtitle_key = FOFInput::getCmd('option', 'com_overload', $this->input).
						'_TITLE_'.strtoupper(FOFInput::getCmd('view', '', $this->input));
	
		JToolBarHelper::title(
						JText::_( FOFInput::getCmd('option', 'com_overload', $this->input)).
						' &ndash; <small>'.JText::_($subtitle_key).'</small>',
						'generic.png');
	}
Beispiel #6
0
 /**
  * Imports an exported profile .json file
  */
 public function import()
 {
     $this->_csrfProtection();
     $user = JFactory::getUser();
     if (!$user->authorise('akeeba.configure', 'com_akeeba')) {
         return JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR'));
     }
     // Get the user
     $user = JFactory::getUser();
     // Get some data from the request
     $file = FOFInput::getVar('importfile', '', $_FILES, 'array');
     if (isset($file['name'])) {
         // Load the file data
         $data = JFile::read($file['tmp_name']);
         @unlink($file['tmp_name']);
         // JSON decode
         $data = json_decode($data, true);
         // Check for data validity
         $isValid = is_array($data) && !empty($data);
         if ($isValid) {
             $isValid = $isValid && array_key_exists('description', $data);
         }
         if ($isValid) {
             $isValid = $isValid && array_key_exists('configuration', $data);
         }
         if ($isValid) {
             $isValid = $isValid && array_key_exists('filters', $data);
         }
         if (!$isValid) {
             $this->setRedirect('index.php?option=com_akeeba&view=profiles', JText::_('COM_AKEEBA_PROFILES_ERR_IMPORT_INVALID'), 'error');
             return false;
         }
         // Unset the id, if it exists
         if (array_key_exists('id', $data)) {
             unset($data['id']);
         }
         // Try saving the profile
         $result = $this->getThisModel()->getTable()->save($data);
         if ($result) {
             $this->setRedirect('index.php?option=com_akeeba&view=profiles', JText::_('COM_AKEEBA_PROFILES_MSG_IMPORT_COMPLETE'));
         } else {
             $this->setRedirect('index.php?option=com_akeeba&view=profiles', JText::_('COM_AKEEBA_PROFILES_ERR_IMPORT_FAILED'), 'error');
         }
     } else {
         $this->setRedirect('index.php?option=com_akeeba&view=profiles', JText::_('MSG_UPLOAD_INVALID_REQUEST'), 'error');
         return false;
     }
 }
 /**
  * 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;
 }
 /**
  * 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
  *
  */
 protected function _setPath($type, $path)
 {
     list($isCli, ) = FOFDispatcher::isCliAdmin();
     // 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
             if (!$isCli) {
                 $app = JFactory::getApplication();
                 $component = preg_replace('/[^A-Z0-9_\\.-]/i', '', $this->input->getCmd('option'));
                 $fallback = JPATH_THEMES . '/' . $app->getTemplate() . '/html/' . $component . '/' . $this->getName();
                 $this->_addPath('template', $fallback);
             }
             break;
     }
 }
Beispiel #9
0
 /**
  * Renders the toolbar for the current view and task
  *
  * @param   string    $view   The view of the component
  * @param   string    $task   The exact task of the view
  * @param   FOFInput  $input  An optional input object used to determine the defaults
  *
  * @return  void
  */
 public function renderToolbar($view = null, $task = null, $input = null)
 {
     if (!empty($input)) {
         $saveInput = $this->input;
         $this->input = $input;
     }
     // If tmpl=component the default behaviour is to not render the toolbar
     if ($this->input->getCmd('tmpl', '') == 'component') {
         $render_toolbar = false;
     } else {
         $render_toolbar = true;
     }
     // If there is a render_toolbar=0 in the URL, do not render a toolbar
     $render_toolbar = $this->input->getBool('render_toolbar', $render_toolbar);
     if (!$render_toolbar) {
         return;
     }
     // Get the view and task
     if (empty($view)) {
         $view = $this->input->getCmd('view', 'cpanel');
     }
     if (empty($task)) {
         $task = $this->input->getCmd('task', 'default');
     }
     $this->view = $view;
     $this->task = $task;
     $view = FOFInflector::pluralize($view);
     $component = $input->get('option', 'com_foobar', 'cmd');
     $configProvider = new FOFConfigProvider();
     $toolbar = $configProvider->get($component . '.views.' . '.toolbar');
     // If we have a toolbar config specified
     if (!empty($toolbar)) {
         return $this->renderFromConfig($toolbar);
     }
     // Check for an onViewTask method
     $methodName = 'on' . ucfirst($view) . ucfirst($task);
     if (method_exists($this, $methodName)) {
         return $this->{$methodName}();
     }
     // Check for an onView method
     $methodName = 'on' . ucfirst($view);
     if (method_exists($this, $methodName)) {
         return $this->{$methodName}();
     }
     // Check for an onTask method
     $methodName = 'on' . ucfirst($task);
     if (method_exists($this, $methodName)) {
         return $this->{$methodName}();
     }
     if (!empty($input)) {
         $this->input = $saveInput;
     }
 }
Beispiel #10
0
 /**
  * This method will try retrieving a variable from the request (input) data.
  *
  * @param   string    $key           The user state key for the variable
  * @param   string    $request       The request variable name for the variable
  * @param   FOFInput  $input         The FOFInput object with the request (input) data
  * @param   mixed     $default       The default value. Default: null
  * @param   string    $type          The filter type for the variable data. Default: none (no filtering)
  * @param   boolean   $setUserState  Should I set the user state with the fetched value?
  *
  * @see FOFPlatformInterface::getUserStateFromRequest()
  *
  * @return  mixed  The value of the variable
  */
 public function getUserStateFromRequest($key, $request, $input, $default = null, $type = 'none', $setUserState = true)
 {
     return $input->get($request, $default, $type);
 }
Beispiel #11
0
 /**
  * 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;
 }
Beispiel #12
0
 /**
  * Renders the toolbar buttons
  *
  * @param   string    $view    The active view name
  * @param   string    $task    The current task
  * @param   FOFInput  $input   The input object
  * @param   array     $config  Extra configuration variables for the toolbar
  *
  * @return  void
  */
 protected function renderButtons($view, $task, $input, $config = array())
 {
     // On command line don't do anything
     if (FOFPlatform::getInstance()->isCli()) {
         return;
     }
     // Do not render buttons unless we are in the the frontend area and we are asked to do so
     $toolbar = FOFToolbar::getAnInstance($input->getCmd('option', 'com_foobar'), $config);
     $renderFrontendButtons = $toolbar->getRenderFrontendButtons();
     if (FOFPlatform::getInstance()->isBackend() || !$renderFrontendButtons) {
         return;
     }
     // Load main backend language, in order to display toolbar strings
     // (JTOOLBAR_BACK, JTOOLBAR_PUBLISH etc etc)
     FOFPlatform::getInstance()->loadTranslations('joomla');
     $title = JFactory::getApplication()->get('JComponentTitle');
     $bar = JToolBar::getInstance('toolbar');
     // Delete faux links, since if SEF is on, Joomla will follow the link instead of submitting the form
     $bar_content = str_replace('href="#"', '', $bar->render());
     echo '<div id="FOFHeaderHolder">', $bar_content, $title, '<div style="clear:both"></div>', '</div>';
 }
Beispiel #13
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
  *
  * @return FOFDispatcher
  */
 public static function &getTmpInstance($option = null, $view = null, $config = array())
 {
     if (array_key_exists('input', $config)) {
         if ($config['input'] instanceof FOFInput) {
             $input = $config['input'];
         } else {
             if (!is_array($config['input'])) {
                 $config['input'] = (array) $config['input'];
             }
             $config['input'] = array_merge($_REQUEST, $config['input']);
             $input = new FOFInput($config['input']);
         }
     } else {
         $input = new FOFInput();
     }
     $config['option'] = !is_null($option) ? $option : $input->getCmd('option', 'com_foobar');
     $config['view'] = !is_null($view) ? $view : $input->getCmd('view', '');
     $input->set('option', $config['option']);
     $input->set('view', $config['view']);
     $config['input'] = $input;
     $className = ucfirst(str_replace('com_', '', $config['option'])) . 'Dispatcher';
     if (!class_exists($className)) {
         $componentPaths = FOFPlatform::getInstance()->getComponentBaseDirs($config['option']);
         $searchPaths = array($componentPaths['main'], $componentPaths['main'] . '/dispatchers', $componentPaths['admin'], $componentPaths['admin'] . '/dispatchers');
         if (array_key_exists('searchpath', $config)) {
             array_unshift($searchPaths, $config['searchpath']);
         }
         $filesystem = FOFPlatform::getInstance()->getIntegrationObject('filesystem');
         $path = $filesystem->pathFind($searchPaths, 'dispatcher.php');
         if ($path) {
             require_once $path;
         }
     }
     if (!class_exists($className)) {
         $className = 'FOFDispatcher';
     }
     $instance = new $className($config);
     return $instance;
 }
 /**
  * This method will try retrieving a variable from the request (input) data.
  *
  * @param   string    $key           The user state key for the variable
  * @param   string    $request       The request variable name for the variable
  * @param   FOFInput  $input         The FOFInput object with the request (input) data
  * @param   mixed     $default       The default value. Default: null
  * @param   string    $type          The filter type for the variable data. Default: none (no filtering)
  * @param   boolean   $setUserState  Should I set the user state with the fetched value?
  *
  * @see FOFPlatformInterface::getUserStateFromRequest()
  *
  * @return  mixed  The value of the variable
  */
 public function getUserStateFromRequest($key, $request, $input, $default = null, $type = 'none', $setUserState = true)
 {
     list($isCLI, $isAdmin) = $this->isCliAdmin();
     if ($isCLI) {
         return $input->get($request, $default, $type);
     }
     $app = JFactory::getApplication();
     if (method_exists($app, 'getUserState')) {
         $old_state = $app->getUserState($key, $default);
     } else {
         $old_state = null;
     }
     $cur_state = !is_null($old_state) ? $old_state : $default;
     $new_state = $input->get($request, null, $type);
     // Save the new value only if it was set in this request
     if ($setUserState) {
         if ($new_state !== null) {
             $app->setUserState($key, $new_state);
         } else {
             $new_state = $cur_state;
         }
     } elseif (is_null($new_state)) {
         $new_state = $cur_state;
     }
     return $new_state;
 }
 /**
  * Renders a FOFForm for a Browse view and returns the corresponding HTML
  *
  * @param   FOFForm   $form      The form to render
  * @param   FOFModel  $model     The model providing our data
  * @param   FOFInput  $input     The input object
  *
  * @return  string    The HTML rendering of the form
  */
 protected function renderFormEdit(FOFForm &$form, FOFModel $model, FOFInput $input)
 {
     // Get the key for this model's table
     $key = $model->getTable()->getKeyName();
     $keyValue = $model->getId();
     $html = '';
     if ($validate = $form->getAttribute('validate')) {
         JHTML::_('behavior.formvalidation');
         $class = ' form-validate';
         $this->loadValidationScript($form);
     } else {
         $class = '';
     }
     // Check form enctype. Use enctype="multipart/form-data" to upload binary files in your form.
     $template_form_enctype = $form->getAttribute('enctype');
     if (!empty($template_form_enctype)) {
         $enctype = ' enctype="' . $form->getAttribute('enctype') . '" ';
     } else {
         $enctype = '';
     }
     // Check form name. Use name="yourformname" to modify the name of your form.
     $formname = $form->getAttribute('name');
     if (empty($formname)) {
         $formname = 'adminForm';
     }
     // Check form ID. Use id="yourformname" to modify the id of your form.
     $formid = $form->getAttribute('name');
     if (empty($formname)) {
         $formid = 'adminForm';
     }
     $html .= '<form action="index.php" method="post" name="' . $formname . '" id="' . $formid . '"' . $enctype . ' class="form-horizontal' . $class . '">' . PHP_EOL;
     $html .= "\t" . '<input type="hidden" name="option" value="' . $input->getCmd('option') . '" />' . PHP_EOL;
     $html .= "\t" . '<input type="hidden" name="view" value="' . $input->getCmd('view', 'edit') . '" />' . PHP_EOL;
     $html .= "\t" . '<input type="hidden" name="task" value="" />' . PHP_EOL;
     $html .= "\t" . '<input type="hidden" name="' . $key . '" value="' . $keyValue . '" />' . PHP_EOL;
     $html .= "\t" . '<input type="hidden" name="' . JFactory::getSession()->getFormToken() . '" value="1" />' . PHP_EOL;
     foreach ($form->getFieldsets() as $fieldset) {
         $fields = $form->getFieldset($fieldset->name);
         if (isset($fieldset->class)) {
             $class = 'class="' . $fieldset->class . '"';
         } else {
             $class = '';
         }
         $html .= "\t" . '<div id="' . $fieldset->name . '" ' . $class . '>' . PHP_EOL;
         if (isset($fieldset->label) && !empty($fieldset->label)) {
             $html .= "\t\t" . '<h3>' . JText::_($fieldset->label) . '</h3>' . PHP_EOL;
         }
         foreach ($fields as $field) {
             $title = $field->title;
             $required = $field->required;
             $labelClass = $field->labelClass;
             $description = $field->description;
             $input = $field->input;
             if (!is_null($title)) {
                 $html .= "\t\t\t" . '<div class="control-group">' . PHP_EOL;
                 $html .= "\t\t\t\t" . '<label class="control-label ' . $labelClass . '" for="' . $field->id . '">' . PHP_EOL;
                 $html .= "\t\t\t\t" . JText::_($title) . PHP_EOL;
                 if ($required) {
                     $html .= ' *';
                 }
                 $html .= "\t\t\t\t" . '</label>' . PHP_EOL;
                 $html .= "\t\t\t\t" . '<div class="controls">' . PHP_EOL;
                 $html .= "\t\t\t\t" . $input . PHP_EOL;
                 if (!empty($description)) {
                     $html .= "\t\t\t\t" . '<span class="help-block">';
                     $html .= JText::_($description) . '</span>' . PHP_EOL;
                 }
                 $html .= "\t\t\t\t" . '</div>' . PHP_EOL;
                 $html .= "\t\t\t" . '</div>' . PHP_EOL;
             } else {
                 $html .= "\t\t\t\t" . $input . PHP_EOL;
             }
         }
         $html .= "\t" . '</div>' . PHP_EOL;
     }
     $html .= '</form>';
     return $html;
 }
 /**
  * Renders a raw FOFForm and returns the corresponding HTML
  *
  * @param   FOFForm   &$form     The form to render
  * @param   FOFModel  $model     The model providing our data
  * @param   FOFInput  $input     The input object
  * @param   string    $formType  The form type e.g. 'edit' or 'read'
  *
  * @return  string    The HTML rendering of the form
  */
 protected function renderFormRaw(FOFForm &$form, FOFModel $model, FOFInput $input, $formType)
 {
     $html = '';
     foreach ($form->getFieldsets() as $fieldset) {
         $fields = $form->getFieldset($fieldset->name);
         if (isset($fieldset->class)) {
             $class = 'class="' . $fieldset->class . '"';
         } else {
             $class = '';
         }
         $html .= "\t" . '<div id="' . $fieldset->name . '" ' . $class . '>' . PHP_EOL;
         if (isset($fieldset->label) && !empty($fieldset->label)) {
             $html .= "\t\t" . '<h3>' . JText::_($fieldset->label) . '</h3>' . PHP_EOL;
         }
         foreach ($fields as $field) {
             $required = $field->required;
             $labelClass = $field->labelClass;
             $groupClass = $form->getFieldAttribute($field->fieldname, 'groupclass', '', $field->group);
             // Auto-generate label and description if needed
             // Field label
             $title = $form->getFieldAttribute($field->fieldname, 'label', '', $field->group);
             $emptylabel = $form->getFieldAttribute($field->fieldname, 'emptylabel', false, $field->group);
             if (empty($title) && !$emptylabel) {
                 $model->getName();
                 $title = strtoupper($input->get('option') . '_' . $model->getName() . '_' . $field->id . '_LABEL');
             }
             // Field description
             $description = $form->getFieldAttribute($field->fieldname, 'description', '', $field->group);
             /**
              * The following code is backwards incompatible. Most forms don't require a description in their form
              * fields. Having to use emptydescription="1" on each one of them is an overkill. Removed.
              */
             /*
             $emptydescription   = $form->getFieldAttribute($field->fieldname, 'emptydescription', false, $field->group);
             if (empty($description) && !$emptydescription)
             {
             	$description = strtoupper($input->get('option') . '_' . $model->getName() . '_' . $field->id . '_DESC');
             }
             */
             if ($formType == 'read') {
                 $inputField = $field->static;
             } elseif ($formType == 'edit') {
                 $inputField = $field->input;
             }
             if (empty($title)) {
                 $html .= "\t\t\t" . $inputField . PHP_EOL;
                 if (!empty($description) && $formType == 'edit') {
                     $html .= "\t\t\t\t" . '<span class="help-block">';
                     $html .= JText::_($description) . '</span>' . PHP_EOL;
                 }
             } else {
                 $html .= "\t\t\t" . '<div class="control-group ' . $groupClass . '">' . PHP_EOL;
                 $html .= "\t\t\t\t" . '<label class="control-label ' . $labelClass . '" for="' . $field->id . '">' . PHP_EOL;
                 $html .= "\t\t\t\t" . JText::_($title) . PHP_EOL;
                 if ($required) {
                     $html .= ' *';
                 }
                 $html .= "\t\t\t\t" . '</label>' . PHP_EOL;
                 $html .= "\t\t\t\t" . '<div class="controls">' . PHP_EOL;
                 $html .= "\t\t\t\t" . $inputField . PHP_EOL;
                 if (!empty($description)) {
                     $html .= "\t\t\t\t" . '<span class="help-block">';
                     $html .= JText::_($description) . '</span>' . PHP_EOL;
                 }
                 $html .= "\t\t\t\t" . '</div>' . PHP_EOL;
                 $html .= "\t\t\t" . '</div>' . PHP_EOL;
             }
         }
         $html .= "\t" . '</div>' . PHP_EOL;
     }
     return $html;
 }
Beispiel #17
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
  */
 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
             if (!FOFPlatform::getInstance()->isCli()) {
                 $fallback = FOFPlatform::getInstance()->getTemplateOverridePath($this->input->getCmd('option', '')) . '/' . $this->getName();
                 $this->_addPath('template', $fallback);
             }
             break;
     }
 }
Beispiel #18
0
 /**
  * Method to get the field options.
  *
  * @return  array  The field option objects.
  */
 protected function getOptions()
 {
     $options = array();
     $this->value = array();
     $value_field = $this->element['value_field'] ? (string) $this->element['value_field'] : 'title';
     $input = new FOFInput();
     $component = ucfirst(str_replace('com_', '', $input->getString('option')));
     $view = ucfirst($input->getString('view'));
     $relation = FOFInflector::pluralize((string) $this->element['name']);
     $model = FOFModel::getTmpInstance(ucfirst($relation), $component . 'Model');
     $table = $model->getTable();
     $key = $table->getKeyName();
     $value = $table->getColumnAlias($value_field);
     foreach ($model->getItemList(true) as $option) {
         $options[] = JHtml::_('select.option', $option->{$key}, $option->{$value});
     }
     if ($id = FOFModel::getAnInstance($view)->getId()) {
         $table = FOFTable::getInstance($view, $component . 'Table');
         $table->load($id);
         $relations = $table->getRelations()->getMultiple($relation);
         foreach ($relations as $item) {
             $this->value[] = $item->getId();
         }
     }
     return $options;
 }
 /**
  * Applies CSRF protection by means of a standard Joomla! token (nonce) check.
  * Raises a 403 Access Forbidden error through JError or an exception
  * (depending the Joomla! version) if the check fails.
  *
  * @return  boolean  True if the CSRF check is successful
  *
  * @throws Exception
  */
 protected function _csrfProtection()
 {
     static $isCli = null, $isAdmin = null;
     if (is_null($isCli)) {
         $isCli = FOFPlatform::getInstance()->isCli();
         $isAdmin = FOFPlatform::getInstance()->isBackend();
     }
     switch ($this->csrfProtection) {
         // Never
         case 0:
             return true;
             break;
             // Always
         // Always
         case 1:
             break;
             // Only back-end and HTML format
         // Only back-end and HTML format
         case 2:
             if ($isCli) {
                 return true;
             } elseif (!$isAdmin && $this->input->get('format', 'html', 'cmd') != 'html') {
                 return true;
             }
             break;
             // Only back-end
         // Only back-end
         case 3:
             if (!$isAdmin) {
                 return true;
             }
             break;
     }
     $hasToken = false;
     $session = JFactory::getSession();
     // Joomla! 1.5/1.6/1.7/2.5 (classic Joomla! API) method
     if (method_exists('JUtility', 'getToken')) {
         $token = JUtility::getToken();
         $hasToken = $this->input->get($token, false, 'none') == 1;
         if (!$hasToken) {
             $hasToken = $this->input->get('_token', null, 'none') == $token;
         }
     }
     // Joomla! 2.5+ (Platform 12.1+) method
     if (!$hasToken) {
         if (method_exists($session, 'getToken')) {
             $token = $session->getToken();
             $hasToken = $this->input->get($token, false, 'none') == 1;
             if (!$hasToken) {
                 $hasToken = $this->input->get('_token', null, 'none') == $token;
             }
         }
     }
     // Joomla! 2.5+ formToken method
     if (!$hasToken) {
         if (method_exists($session, 'getFormToken')) {
             $token = $session->getFormToken();
             $hasToken = $this->input->get($token, false, 'none') == 1;
             if (!$hasToken) {
                 $hasToken = $this->input->get('_token', null, 'none') == $token;
             }
         }
     }
     if (!$hasToken) {
         if (version_compare(JVERSION, '3.0', 'ge')) {
             throw new Exception(JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
         } else {
             JError::raiseError('403', JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'));
         }
         return false;
     }
 }
 /**
  * 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;
 }
<?php

/**
 * @package AkeebaBackup
 * @copyright Copyright (c)2009-2013 Nicholas K. Dionysopoulos
 * @license GNU General Public License version 3, or later
 * @since 1.3
 */
defined('_JEXEC') or die;
$data = $this->item->getData();
if (substr($data['configuration'], 0, 12) == '###AES128###') {
    // Load the server key file if necessary
    jimport('joomla.filesystem.file');
    if (!defined('AKEEBA_SERVERKEY')) {
        $filename = JPATH_COMPONENT_ADMINISTRATOR . '/akeeba/serverkey.php';
        include_once $filename;
    }
    $key = AEUtilSecuresettings::getKey();
    $data['configuration'] = AEUtilSecuresettings::decryptSettings($data['configuration'], $key);
}
$defaultName = FOFInput::getCmd('view', 'joomla', $this->input);
$filename = FOFInput::getCmd('basename', $defaultName, $this->input);
$document = JFactory::getDocument();
$document->setName($filename);
echo json_encode($data);
Beispiel #22
0
 /**
  * Old static methods are now deprecated. This magic method makes sure there
  * is a continuity in our approach. The downside is that it's only compatible
  * with PHP 5.3.0. Sorry!
  *
  * @param   string  $name       Name of the method we're calling
  * @param   array   $arguments  The arguments passed to the method
  *
  * @return  mixed
  */
 public static function __callStatic($name, $arguments)
 {
     FOFPlatform::getInstance()->logDeprecated('FOFInput: static getXXX() methods are deprecated. Use the input object\'s methods instead.');
     if (substr($name, 0, 3) == 'get') {
         // Initialise arguments
         $key = array_shift($arguments);
         $default = array_shift($arguments);
         $input = array_shift($arguments);
         $type = 'none';
         $mask = 0;
         $type = strtolower(substr($name, 3));
         if ($type == 'var') {
             $type = array_shift($arguments);
             $mask = array_shift($arguments);
         }
         if (is_null($type)) {
             $type = 'none';
         }
         if (is_null($mask)) {
             $mask = 0;
         }
         if (!$input instanceof FOFInput && !$input instanceof JInput) {
             $input = new FOFInput($input);
         }
         return $input->get($key, $default, $type, $mask);
     }
     return false;
 }
 /**
  * Generic check for whether dependancies exist for this object in the db schema
  */
 public function canDelete($oid = null, $joins = null)
 {
     $k = $this->_tbl_key;
     if ($oid) {
         $this->{$k} = intval($oid);
     }
     if (is_array($joins)) {
         $db = $this->_db;
         $query = $db->getQuery(true)->select($db->qn('master') . '.' . $db->qn($k))->from($db->qn($this->_tbl) . ' AS ' . $db->qn('master'));
         $tableNo = 0;
         foreach ($joins as $table) {
             $tableNo++;
             $query->select(array('COUNT(DISTINCT ' . $db->qn('t' . $tableNo) . '.' . $db->qn($table['idfield']) . ') AS ' . $db->qn($table['idalias'])));
             $query->join('LEFT', $db->qn($table['name']) . ' AS ' . $db->qn('t' . $tableNo) . ' ON ' . $db->qn('t' . $tableNo) . '.' . $db->qn($table['joinfield']) . ' = ' . $db->qn('master') . '.' . $db->qn($k));
         }
         $query->where($db->qn('master') . '.' . $db->qn($k) . ' = ' . $db->q($this->{$k}));
         $query->group($db->qn('master') . '.' . $db->qn($k));
         $this->_db->setQuery((string) $query);
         if (version_compare(JVERSION, '3.0', 'ge')) {
             try {
                 $obj = $this->_db->loadObject();
             } catch (JDatabaseException $e) {
                 $this->setError($e->getMessage());
             }
         } else {
             if (!($obj = $this->_db->loadObject())) {
                 $this->setError($this->_db->getErrorMsg());
                 return false;
             }
         }
         $msg = array();
         $i = 0;
         foreach ($joins as $table) {
             $k = $table['idalias'];
             if ($obj->{$k} > 0) {
                 $msg[] = JText::_($table['label']);
             }
             $i++;
         }
         if (count($msg)) {
             $option = $this->input->getCmd('option', 'com_foobar');
             $comName = str_replace('com_', '', $option);
             $tview = str_replace('#__' . $comName . '_', '', $this->_tbl);
             $prefix = $option . '_' . $tview . '_NODELETE_';
             foreach ($msg as $key) {
                 $this->setError(JText::_($prefix . $key));
             }
             return false;
         } else {
             return true;
         }
     }
     return true;
 }
 /**
  * Autoload Views
  *
  * @param   string  $class_name  The name of the class to load
  *
  * @return  void
  */
 public function autoload_fof_view($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, 'View') === 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 at least three parts in the name
     if (count($parts) < 3) {
         return;
     }
     // We need the second part to be "view"
     if ($parts[1] != 'view') {
         return;
     }
     // Get the information about this class
     $component_raw = $parts[0];
     $component = 'com_' . $parts[0];
     $view = $parts[2];
     if (count($parts) > 3) {
         $format = $parts[3];
     } else {
         $input = new FOFInput();
         $format = $input->getCmd('format', 'html', 'cmd');
     }
     // 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 . '_view_' . $alt_view);
     // Get the proper and alternate paths and file names
     $componentPaths = FOFPlatform::getInstance()->getComponentBaseDirs($component);
     $protoFile = "/models/{$view}";
     $protoAltFile = "/models/{$alt_view}";
     $path = $componentPaths['main'];
     $altPath = $componentPaths['alt'];
     $formats = array($format);
     if ($format != 'html') {
         $formats[] = 'raw';
     }
     foreach ($formats as $currentFormat) {
         $file = $protoFile . '.' . $currentFormat . '.php';
         $altFile = $protoAltFile . '.' . $currentFormat . '.php';
         // Try to find the proper class in the proper path
         if (!class_exists($class_name) && 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);
     } elseif (!class_exists($class_name)) {
         if ($view != 'default') {
             $defaultClass = FOFInflector::camelize($component_raw . '_view_default');
             $this->class_alias($defaultClass, $class_name);
         } else {
             if (!file_exists(self::$fofPath . '/view/' . $format . '.php')) {
                 $default_class = 'FOFView';
             } else {
                 $default_class = 'FOFView' . ucfirst($format);
             }
             $this->class_alias($default_class, $class_name, true);
         }
     }
 }
 /**
  * Gets a temporary instance of a Dispatcher
  *
  * @param   string  $option  The component name
  * @param   string  $view    The View name
  * @param   array   $config  Configuration data
  *
  * @return FOFDispatcher
  */
 public static function &getTmpInstance($option = null, $view = null, $config = array())
 {
     if (array_key_exists('input', $config)) {
         if ($config['input'] instanceof FOFInput) {
             $input = $config['input'];
         } else {
             if (!is_array($config['input'])) {
                 $config['input'] = (array) $config['input'];
             }
             $config['input'] = array_merge($_REQUEST, $config['input']);
             $input = new FOFInput($config['input']);
         }
     } else {
         $input = new FOFInput();
     }
     $config['option'] = !is_null($option) ? $option : $input->getCmd('option', 'com_foobar');
     $config['view'] = !is_null($view) ? $view : $input->getCmd('view', '');
     $input->set('option', $config['option']);
     $input->set('view', $config['view']);
     $config['input'] = $input;
     $className = ucfirst(str_replace('com_', '', $config['option'])) . 'Dispatcher';
     if (!class_exists($className)) {
         list($isCli, $isAdmin) = self::isCliAdmin();
         if ($isAdmin) {
             $basePath = JPATH_ADMINISTRATOR;
         } elseif ($isCli) {
             $basePath = JPATH_ROOT;
         } else {
             $basePath = JPATH_SITE;
         }
         $searchPaths = array($basePath . '/components/' . $config['option'], $basePath . '/components/' . $config['option'] . '/dispatchers', JPATH_ADMINISTRATOR . '/components/' . $config['option'], JPATH_ADMINISTRATOR . '/components/' . $config['option'] . '/dispatchers');
         if (array_key_exists('searchpath', $config)) {
             array_unshift($searchPaths, $config['searchpath']);
         }
         JLoader::import('joomla.filesystem.path');
         $path = JPath::find($searchPaths, 'dispatcher.php');
         if ($path) {
             require_once $path;
         }
     }
     if (!class_exists($className)) {
         $className = 'FOFDispatcher';
     }
     $instance = new $className($config);
     return $instance;
 }