/**
  * Sets the list of IDs from the request data
  *
  * @return FOFModel
  */
 public function setIDsFromRequest()
 {
     // Get the ID or list of IDs from the request or the configuration
     $cid = $this->input->get('cid', array(), 'array');
     $id = $this->input->getInt('id', 0);
     $kid = $this->input->getInt($this->getTable($this->table)->getKeyName(), 0);
     if (is_array($cid) && !empty($cid)) {
         $this->setIds($cid);
     } else {
         if (empty($id)) {
             $this->setId($kid);
         } else {
             $this->setId($id);
         }
     }
     return $this;
 }
 /**
  * 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;
 }
Exemple #3
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;
     }
 }
Exemple #4
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);
 }
Exemple #5
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;
 }
 /**
  * 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;
 }
Exemple #7
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;
 }
 /**
  * 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;
 }
Exemple #10
0
 /**
  * Renders a raw fieldset of a FOFForm and returns the corresponding HTML
  *
  * @param   stdClass  &$fieldset   The fieldset to render
  * @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'
  * @param   boolean   $showHeader  Should I render the fieldset's header?
  *
  * @return  string    The HTML rendering of the fieldset
  */
 protected function renderFieldset(stdClass &$fieldset, FOFForm &$form, FOFModel $model, FOFInput $input, $formType, $showHeader = true)
 {
     $html = '';
     $fields = $form->getFieldset($fieldset->name);
     if (isset($fieldset->class)) {
         $class = 'class="' . $fieldset->class . '"';
     } else {
         $class = '';
     }
     $element = empty($fields) ? 'div' : 'fieldset';
     $html .= "\t" . '<' . $element . ' id="' . $fieldset->name . '" ' . $class . '>' . PHP_EOL;
     $isTabbedFieldset = $this->isTabFieldset($fieldset);
     if (isset($fieldset->label) && !empty($fieldset->label) && !$isTabbedFieldset) {
         $html .= "\t\t" . '<h3>' . JText::_($fieldset->label) . '</h3>' . PHP_EOL;
     }
     foreach ($fields as $field) {
         $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="fof-row ' . $groupClass . '">' . PHP_EOL;
             $html .= $this->renderFieldsetLabel($field, $form, $title);
             $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" . '</div>' . PHP_EOL;
         }
     }
     $element = empty($fields) ? 'div' : 'fieldset';
     $html .= "\t" . '</' . $element . '>' . PHP_EOL;
     return $html;
 }