Source for file controller.php

Documentation is available at controller.php

  1. <?php
  2. /**
  3.  * @package    FrameworkOnFramework
  4.  * @subpackage controller
  5.  * @copyright  Copyright (C) 2010 - 2012 Akeeba Ltd. All rights reserved.
  6.  * @license    GNU General Public License version 2 or later; see LICENSE.txt
  7.  */
  8.  
  9. // Protect from unauthorized access
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * FrameworkOnFramework controller class. FOF is based on the thin controller
  14.  * paradigm, where the controller is mainly used to set up the model state and
  15.  * spawn the view.
  16.  *
  17.  * @package  FrameworkOnFramework
  18.  * @since    1.0
  19.  */
  20. class FOFController extends JObject
  21. {
  22.     /**
  23.      * @var int Bit mask to enable JRoute'ing on redirects.
  24.      *  0 = never
  25.      *  1 = frontend only
  26.      *  2 = backend  only
  27.      *  3 = always
  28.      */
  29.     protected $autoRouting = 0;
  30.  
  31.     /**
  32.      * The current component's name without the com_ prefix
  33.      *
  34.      * @var    string 
  35.      */
  36.     protected $bareComponent = 'foobar';
  37.  
  38.     /**
  39.      * The base path of the controller
  40.      *
  41.      * @var    string 
  42.      */
  43.     protected $basePath;
  44.  
  45.     /**
  46.      * The tasks for which caching should be enabled by default
  47.      *
  48.      * @var array 
  49.      */
  50.     protected $cacheableTasks = array('browse''read');
  51.  
  52.     /**
  53.      * The current component's name; you can override it in the configuration
  54.      *
  55.      * @var    string 
  56.      */
  57.     protected $component = 'com_foobar';
  58.  
  59.     /**
  60.      * A cached copy of the class configuration parameter passed during initialisation
  61.      *
  62.      * @var    array 
  63.      */
  64.     protected $config = array();
  65.  
  66.     /**
  67.      * An instance of FOFConfigProvider to provision configuration overrides
  68.      *
  69.      * @var    FOFConfigProvider 
  70.      */
  71.     protected $configProvider = null;
  72.  
  73.     /**
  74.      * Set to true to enable CSRF protection on selected tasks. The possible
  75.      * values are:
  76.      * 0    Disabled; no token checks are performed
  77.      * 1    Enabled; token checks are always performed
  78.      * 2    Only on HTML requests and backend; token checks are always performed in the back-end and in the front-end only when format is 'html'
  79.      * 3    Only on back-end; token checks are performer only in the back-end
  80.      *
  81.      * @var    integer 
  82.      */
  83.     protected $csrfProtection = 2;
  84.  
  85.     /**
  86.      * The default view for the display method.
  87.      *
  88.      * @var    string 
  89.      */
  90.     protected $default_view;
  91.  
  92.     /**
  93.      * The mapped task that was performed.
  94.      *
  95.      * @var    string 
  96.      */
  97.     protected $doTask;
  98.  
  99.     /**
  100.      * The input object for this MVC triad; you can override it in the configuration
  101.      *
  102.      * @var    FOFInput 
  103.      */
  104.     protected $input = array();
  105.  
  106.     /**
  107.      * Redirect message.
  108.      *
  109.      * @var    string 
  110.      */
  111.     protected $message;
  112.  
  113.     /**
  114.      * Redirect message type.
  115.      *
  116.      * @var    string 
  117.      */
  118.     protected $messageType;
  119.  
  120.     /**
  121.      * The current layout; you can override it in the configuration
  122.      *
  123.      * @var    string 
  124.      */
  125.     protected $layout = null;
  126.  
  127.     /**
  128.      * Array of class methods
  129.      *
  130.      * @var    array 
  131.      */
  132.     protected $methods;
  133.  
  134.     /**
  135.      * The prefix of the models
  136.      *
  137.      * @var    string 
  138.      */
  139.     protected $model_prefix;
  140.  
  141.     /**
  142.      * Overrides the name of the view's default model
  143.      *
  144.      * @var    string 
  145.      */
  146.     protected $modelName = null;
  147.  
  148.     /**
  149.      * The set of search directories for resources (views).
  150.      *
  151.      * @var    array 
  152.      */
  153.     protected $paths;
  154.  
  155.     /**
  156.      * URL for redirection.
  157.      *
  158.      * @var    string 
  159.      */
  160.     protected $redirect;
  161.  
  162.     /**
  163.      * Current or most recently performed task.
  164.      *
  165.      * @var    string 
  166.      */
  167.     protected $task;
  168.  
  169.     /**
  170.      * Array of class methods to call for a given task.
  171.      *
  172.      * @var    array 
  173.      */
  174.     protected $taskMap;
  175.  
  176.     /**
  177.      * The name of the controller
  178.      *
  179.      * @var    array 
  180.      */
  181.     protected $name;
  182.  
  183.     /**
  184.      * The current view name; you can override it in the configuration
  185.      *
  186.      * @var    string 
  187.      */
  188.     protected $view = '';
  189.  
  190.     /**
  191.      * Overrides the name of the view's default view
  192.      *
  193.      * @var    string 
  194.      */
  195.     protected $viewName = null;
  196.  
  197.     /**
  198.      * A copy of the FOFView object used in this triad
  199.      *
  200.      * @var    FOFView 
  201.      */
  202.     private $_viewObject null;
  203.  
  204.     /**
  205.      * A cache for the view item objects created in this controller
  206.      *
  207.      * @var   array 
  208.      */
  209.     protected $viewsCache = array();
  210.  
  211.     /**
  212.      * A copy of the FOFModel object used in this triad
  213.      *
  214.      * @var    FOFModel 
  215.      */
  216.     private $_modelObject null;
  217.  
  218.     /**
  219.      * Does this tried have a FOFForm which will be used to render it?
  220.      *
  221.      * @var    boolean 
  222.      */
  223.     protected $hasForm = false;
  224.  
  225.     /**
  226.      * Gets a static (Singleton) instance of a controller class. It loads the
  227.      * relevant controller file from the component's directory or, if it doesn't
  228.      * exist, creates a new controller object out of thin air.
  229.      *
  230.      * @param   string  $option  Component name, e.g. com_foobar
  231.      * @param   string  $view    The view name, also used for the controller name
  232.      * @param   array   $config  Configuration parameters
  233.      *
  234.      * @return  FOFController 
  235.      */
  236.     public static function &getAnInstance($option null$view null$config array())
  237.     {
  238.         static $instances array();
  239.  
  240.         // Make sure $config is an array
  241.         if (is_object($config))
  242.         {
  243.             $config = (array) $config;
  244.         }
  245.         elseif (!is_array($config))
  246.         {
  247.             $config array();
  248.         }
  249.  
  250.         $hash $option $view;
  251.  
  252.         if (!array_key_exists($hash$instances))
  253.         {
  254.             $instances[$hashself::getTmpInstance($option$view$config);
  255.         }
  256.  
  257.         return $instances[$hash];
  258.     }
  259.  
  260.     /**
  261.      * Gets a temporary instance of a controller object. A temporary instance is
  262.      * not a Singleton and can be disposed off after use.
  263.      *
  264.      * @param   string  $option  The component name, e.g. com_foobar
  265.      * @param   string  $view    The view name, e.g. cpanel
  266.      * @param   array   $config  Configuration parameters
  267.      *
  268.      * @return  \className  A disposable class instance
  269.      */
  270.     public static function &getTmpInstance($option null$view null$config array())
  271.     {
  272.         // Make sure $config is an array
  273.         if (is_object($config))
  274.         {
  275.             $config = (array) $config;
  276.         }
  277.         elseif (!is_array($config))
  278.         {
  279.             $config array();
  280.         }
  281.  
  282.         // Get an input object
  283.         if (array_key_exists('input'$config))
  284.         {
  285.             $input $config['input'];
  286.         }
  287.         else
  288.         {
  289.             $input null;
  290.         }
  291.  
  292.         if (array_key_exists('input_options'$config))
  293.         {
  294.             $input_options $config['input_options'];
  295.         }
  296.         else
  297.         {
  298.             $input_options array();
  299.         }
  300.  
  301.         if (!($input instanceof FOFInput))
  302.         {
  303.             $input new FOFInput($input$input_options);
  304.         }
  305.  
  306.         // Determine the option (component name) and view
  307.         $config['option'!is_null($option$option $input->getCmd('option''com_foobar');
  308.         $config['view'!is_null($view$view $input->getCmd('view''cpanel');
  309.  
  310.         // Get the class base name, e.g. FoobarController
  311.         $classBaseName ucfirst(str_replace('com_'''$config['option'])) 'Controller';
  312.  
  313.         // Get the class name suffixes, in the order to be searched for: plural, singular, 'default'
  314.         $classSuffixes array(
  315.             FOFInflector::pluralize($config['view']),
  316.             FOFInflector::singularize($config['view']),
  317.             'default'
  318.         );
  319.  
  320.         JLoader::import('joomla.filesystem.path');
  321.  
  322.         // Get the path names for the component
  323.         $componentPaths FOFPlatform::getInstance()->getComponentBaseDirs($config['option']);
  324.  
  325.         // Look for the best classname match
  326.         foreach ($classSuffixes as $suffix)
  327.         {
  328.             $className $classBaseName ucfirst($suffix);
  329.  
  330.             if (class_exists($className))
  331.             {
  332.                 // The class is already loaded. We have a match!
  333.                 break;
  334.             }
  335.  
  336.             // The class is not already loaded. Try to find and load it.
  337.             $searchPaths array(
  338.                 $componentPaths['main''/controllers',
  339.                 $componentPaths['admin''/controllers'
  340.             );
  341.  
  342.             // If we have a searchpath in the configuration please search it first
  343.  
  344.             if (array_key_exists('searchpath'$config))
  345.             {
  346.                 array_unshift($searchPaths$config['searchpath']);
  347.             }
  348.             else
  349.             {
  350.                 $configProvider new FOFConfigProvider;
  351.                 $searchPath $configProvider->get($config['option''.views.' FOFInflector::singularize($config['view']'.config.searchpath'null);
  352.  
  353.                 if ($searchPath)
  354.                 {
  355.                     array_unshift($searchPaths$componentPaths['admin''/' $searchPath);
  356.                     array_unshift($searchPaths$componentPaths['main''/' $searchPath);
  357.                 }
  358.             }
  359.  
  360.             /**
  361.              * Try to find the path to this file. First try to find the
  362.              * format-specific controller file, e.g. foobar.json.php for
  363.              * format=json, then the regular one-size-fits-all controller
  364.              */
  365.  
  366.             $format $input->getCmd('format''html');
  367.             $path null;
  368.  
  369.             if (!empty($format))
  370.             {
  371.                 $path JPath::find(
  372.                     $searchPathsstrtolower($suffix'.' strtolower($format'.php'
  373.                 );
  374.             }
  375.  
  376.             if (!$path)
  377.             {
  378.                 $path JPath::find(
  379.                         $searchPathsstrtolower($suffix'.php'
  380.                 );
  381.             }
  382.  
  383.             // The path is found. Load the file and make sure the expected class name exists.
  384.  
  385.             if ($path)
  386.             {
  387.                 require_once $path;
  388.  
  389.                 if (class_exists($className))
  390.                 {
  391.                     // The class was loaded successfully. We have a match!
  392.                     break;
  393.                 }
  394.             }
  395.         }
  396.  
  397.         if (!class_exists($className))
  398.         {
  399.             // If no specialised class is found, instantiate the generic FOFController
  400.             $className 'FOFController';
  401.         }
  402.  
  403.         $instance new $className($config);
  404.  
  405.         return $instance;
  406.     }
  407.  
  408.     /**
  409.      * Public constructor of the Controller class
  410.      *
  411.      * @param   array  $config  Optional configuration parameters
  412.      */
  413.     public function __construct($config array())
  414.     {
  415.         // Make sure $config is an array
  416.         if (is_object($config))
  417.         {
  418.             $config = (array) $config;
  419.         }
  420.         elseif (!is_array($config))
  421.         {
  422.             $config array();
  423.         }
  424.  
  425.         $this->methods array();
  426.         $this->message null;
  427.         $this->messageType 'message';
  428.         $this->paths array();
  429.         $this->redirect = null;
  430.         $this->taskMap array();
  431.  
  432.         // Cache the config
  433.         $this->config $config;
  434.  
  435.         // Get the input for this MVC triad
  436.  
  437.         if (array_key_exists('input'$config))
  438.         {
  439.             $input $config['input'];
  440.         }
  441.         else
  442.         {
  443.             $input null;
  444.         }
  445.  
  446.         if (array_key_exists('input_options'$config))
  447.         {
  448.             $input_options $config['input_options'];
  449.         }
  450.         else
  451.         {
  452.             $input_options array();
  453.         }
  454.  
  455.         if ($input instanceof FOFInput)
  456.         {
  457.             $this->input $input;
  458.         }
  459.         else
  460.         {
  461.             $this->input new FOFInput($input$input_options);
  462.         }
  463.  
  464.         // Load the configuration provider
  465.         $this->configProvider new FOFConfigProvider;
  466.  
  467.         // Determine the methods to exclude from the base class.
  468.         $xMethods get_class_methods('FOFController');
  469.  
  470.         // Some methods must always be considered valid tasks
  471.         $iMethods array('accesspublic''accessregistered''accessspecial',
  472.             'add''apply''browse''cancel''copy''edit''orderdown',
  473.             'orderup''publish''read''remove''save''savenew',
  474.             'saveorder''unpublish''display''archive''trash');
  475.  
  476.         // Get the public methods in this class using reflection.
  477.         $r new ReflectionClass($this);
  478.         $rMethods $r->getMethods(ReflectionMethod::IS_PUBLIC);
  479.  
  480.         foreach ($rMethods as $rMethod)
  481.         {
  482.             $mName $rMethod->getName();
  483.  
  484.             // Add default display method if not explicitly declared.
  485.             if (!in_array($mName$xMethods|| in_array($mName$iMethods))
  486.             {
  487.                 $this->methods[strtolower($mName);
  488.  
  489.                 // Auto register the methods as tasks.
  490.                 $this->taskMap[strtolower($mName)$mName;
  491.             }
  492.         }
  493.  
  494.         // Get the default values for the component and view names
  495.         $classNameParts FOFInflector::explode(get_class($this));
  496.  
  497.         if (count($classNameParts== 3)
  498.         {
  499.             $defComponent "com_" $classNameParts[0];
  500.             $defView $classNameParts[2];
  501.         }
  502.         else
  503.         {
  504.             $defComponent 'com_foobar';
  505.             $defView 'cpanel';
  506.         }
  507.  
  508.         $this->component $this->input->get('option'$defComponent'cmd');
  509.         $this->view $this->input->get('view'$defView'cmd');
  510.         $this->layout $this->input->get('layout'null'cmd');
  511.  
  512.         // Overrides from the config
  513.         if (array_key_exists('option'$config))
  514.         {
  515.             $this->component $config['option'];
  516.         }
  517.  
  518.         if (array_key_exists('view'$config))
  519.         {
  520.             $this->view $config['view'];
  521.         }
  522.  
  523.         if (array_key_exists('layout'$config))
  524.         {
  525.             $this->layout $config['layout'];
  526.         }
  527.  
  528.         $this->layout $this->configProvider->get($this->component '.views.' FOFInflector::singularize($this->view'.config.layout'$this->layout);
  529.  
  530.         $this->input->set('option'$this->component);
  531.  
  532.         // Set the bareComponent variable
  533.         $this->bareComponent str_replace('com_'''strtolower($this->component));
  534.  
  535.         // Set the $name variable
  536.         $this->name $this->bareComponent;
  537.  
  538.         // Set the basePath variable
  539.         $componentPaths FOFPlatform::getInstance()->getComponentBaseDirs($this->component);
  540.         $basePath $componentPaths['main'];
  541.  
  542.         if (array_key_exists('base_path'$config))
  543.         {
  544.             $basePath $config['base_path'];
  545.         }
  546.  
  547.         $altBasePath $this->configProvider->get(
  548.             $this->component '.views.' .
  549.             FOFInflector::singularize($this->view'.config.base_path'null
  550.         );
  551.  
  552.         if (!is_null($altBasePath))
  553.         {
  554.             $basePath JPATH_SITE '/' $altBasePath;
  555.         }
  556.  
  557.         $this->basePath $basePath;
  558.  
  559.         // If the default task is set, register it as such
  560.         $defaultTask $this->configProvider->get(
  561.             $this->component '.views.' .
  562.             FOFInflector::singularize($this->view'.config.default_task''display'
  563.         );
  564.  
  565.         if (array_key_exists('default_task'$config))
  566.         {
  567.             $this->registerDefaultTask($config['default_task']);
  568.         }
  569.         else
  570.         {
  571.             $this->registerDefaultTask($defaultTask);
  572.         }
  573.  
  574.         // Set the models prefix
  575.  
  576.         if (empty($this->model_prefix))
  577.         {
  578.             if (array_key_exists('model_prefix'$config))
  579.             {
  580.                 // User-defined prefix
  581.                 $this->model_prefix $config['model_prefix'];
  582.             }
  583.             else
  584.             {
  585.                 $this->model_prefix $this->name 'Model';
  586.                 $this->model_prefix $this->configProvider->get(
  587.                     $this->component '.views.' .
  588.                     FOFInflector::singularize($this->view'.config.model_prefix'$this->model_prefix
  589.                 );
  590.             }
  591.         }
  592.  
  593.         // Set the default model search path
  594.  
  595.         if (array_key_exists('model_path'$config))
  596.         {
  597.             // User-defined dirs
  598.             $this->addModelPath($config['model_path']$this->model_prefix);
  599.         }
  600.         else
  601.         {
  602.             $modelPath $this->basePath '/models';
  603.             $altModelPath $this->configProvider->get(
  604.                 $this->component '.views.' .
  605.                 FOFInflector::singularize($this->view'.config.model_path'null
  606.             );
  607.  
  608.             if (!is_null($altModelPath))
  609.             {
  610.                 $modelPath $this->basePath '/' $altModelPath;
  611.             }
  612.  
  613.             $this->addModelPath($modelPath$this->model_prefix);
  614.         }
  615.  
  616.         // Set the default view search path
  617.  
  618.         if (array_key_exists('view_path'$config))
  619.         {
  620.             // User-defined dirs
  621.             $this->setPath('view'$config['view_path']);
  622.         }
  623.         else
  624.         {
  625.             $viewPath $this->basePath '/views';
  626.             $altViewPath $this->configProvider->get(
  627.                 $this->component '.views.' .
  628.                 FOFInflector::singularize($this->view'.config.view_path'null
  629.             );
  630.  
  631.             if (!is_null($altViewPath))
  632.             {
  633.                 $viewPath $this->basePath '/' $altViewPath;
  634.             }
  635.  
  636.             $this->setPath('view'$viewPath);
  637.         }
  638.  
  639.         // Set the default view.
  640.  
  641.         if (array_key_exists('default_view'$config))
  642.         {
  643.             $this->default_view $config['default_view'];
  644.         }
  645.         else
  646.         {
  647.             if (empty($this->default_view))
  648.             {
  649.                 $this->default_view $this->getName();
  650.             }
  651.  
  652.             $this->default_view $this->configProvider->get(
  653.                 $this->component '.views.' .
  654.                 FOFInflector::singularize($this->view'.config.default_view'$this->default_view
  655.             );
  656.         }
  657.  
  658.         // Set the CSRF protection
  659.  
  660.         if (array_key_exists('csrf_protection'$config))
  661.         {
  662.             $this->csrfProtection $config['csrf_protection'];
  663.         }
  664.  
  665.         $this->csrfProtection $this->configProvider->get(
  666.             $this->component '.views.' .
  667.             FOFInflector::singularize($this->view'.config.csrf_protection'$this->csrfProtection
  668.         );
  669.  
  670.         // Set any model/view name overrides
  671.  
  672.         if (array_key_exists('viewName'$config))
  673.         {
  674.             $this->setThisViewName($config['viewName']);
  675.         }
  676.         else
  677.         {
  678.             $overrideViewName $this->configProvider->get(
  679.                 $this->component '.views.' .
  680.                 FOFInflector::singularize($this->view'.config.viewName'null
  681.             );
  682.  
  683.             if ($overrideViewName)
  684.             {
  685.                 $this->setThisViewName($overrideViewName);
  686.             }
  687.         }
  688.  
  689.         if (array_key_exists('modelName'$config))
  690.         {
  691.             $this->setThisModelName($config['modelName']);
  692.         }
  693.         else
  694.         {
  695.             $overrideModelName $this->configProvider->get(
  696.                 $this->component '.views.' .
  697.                 FOFInflector::singularize($this->view'.config.modelName'null
  698.             );
  699.  
  700.             if ($overrideModelName)
  701.             {
  702.                 $this->setThisModelName($overrideModelName);
  703.             }
  704.         }
  705.  
  706.         // Caching
  707.  
  708.         if (array_key_exists('cacheableTasks'$config))
  709.         {
  710.             if (is_array($config['cacheableTasks']))
  711.             {
  712.                 $this->cacheableTasks $config['cacheableTasks'];
  713.             }
  714.         }
  715.         else
  716.         {
  717.             $cacheableTasks $this->configProvider->get(
  718.                 $this->component '.views.' .
  719.                 FOFInflector::singularize($this->view'.config.cacheableTasks'null
  720.             );
  721.  
  722.             if ($cacheableTasks)
  723.             {
  724.                 $cacheableTasks explode(','$cacheableTasks);
  725.  
  726.                 if (count($cacheableTasks))
  727.                 {
  728.                     $temp array();
  729.  
  730.                     foreach ($cacheableTasks as $t)
  731.                     {
  732.                         $temp[trim($t);
  733.                     }
  734.  
  735.                     $temp array_unique($temp);
  736.                     $this->cacheableTasks $temp;
  737.                 }
  738.             }
  739.         }
  740.  
  741.         // Bit mask for auto routing on setRedirect
  742.         $this->autoRouting $this->configProvider->get(
  743.             $this->component '.views.' .
  744.             FOFInflector::singularize($this->view'.config.autoRouting'$this->autoRouting
  745.         );
  746.  
  747.         if (array_key_exists('autoRouting'$config))
  748.         {
  749.             $this->autoRouting $config['autoRouting'];
  750.         }
  751.  
  752.         // Apply task map
  753.         $taskmap $this->configProvider->get(
  754.             $this->component '.views.' .
  755.             FOFInflector::singularize($this->view'.taskmap'
  756.         );
  757.  
  758.         if (is_array($taskmap&& !empty($taskmap))
  759.         {
  760.             foreach ($taskmap as $aliasedtask => $realmethod)
  761.             {
  762.                 $this->registerTask($aliasedtask$realmethod);
  763.             }
  764.         }
  765.     }
  766.  
  767.     /**
  768.      * Adds to the stack of model paths in LIFO order.
  769.      *
  770.      * @param   mixed   $path    The directory (string) , or list of directories (array) to add.
  771.      * @param   string  $prefix  A prefix for models
  772.      *
  773.      * @return  void 
  774.      */
  775.     public static function addModelPath($path$prefix '')
  776.     {
  777.         FOFModel::addIncludePath($path$prefix);
  778.     }
  779.  
  780.     /**
  781.      * Adds to the search path for templates and resources.
  782.      *
  783.      * @param   string  $type  The path type (e.g. 'model', 'view').
  784.      * @param   mixed   $path  The directory string  or stream array to search.
  785.      *
  786.      * @return  FOFController  A FOFController object to support chaining.
  787.      */
  788.     protected function addPath($type$path)
  789.     {
  790.         // Just force path to array
  791.         settype($path'array');
  792.  
  793.         if (!isset($this->paths[$type]))
  794.         {
  795.             $this->paths[$typearray();
  796.         }
  797.  
  798.         // Loop through the path directories
  799.         foreach ($path as $dir)
  800.         {
  801.             // No surrounding spaces allowed!
  802.             $dir rtrim(JPath::check($dir'/')'/''/';
  803.  
  804.             // Add to the top of the search dirs
  805.             array_unshift($this->paths[$type]$dir);
  806.         }
  807.  
  808.         return $this;
  809.     }
  810.  
  811.     /**
  812.      * Add one or more view paths to the controller's stack, in LIFO order.
  813.      *
  814.      * @param   mixed  $path  The directory (string) or list of directories (array) to add.
  815.      *
  816.      * @return  FOFController  This object to support chaining.
  817.      */
  818.     public function addViewPath($path)
  819.     {
  820.         $this->addPath('view'$path);
  821.  
  822.         return $this;
  823.     }
  824.  
  825.     /**
  826.      * Authorisation check
  827.      *
  828.      * @param   string  $task  The ACO Section Value to check access on.
  829.      *
  830.      * @return  boolean  True if authorised
  831.      *
  832.      * @deprecated  2.0  Use JAccess instead.
  833.      */
  834.     public function authorise($task)
  835.     {
  836.         JLog::add(__METHOD__ . ' is deprecated. Use checkACL() instead.'JLog::WARNING'deprecated');
  837.  
  838.         return true;
  839.     }
  840.  
  841.     /**
  842.      * Create the filename for a resource.
  843.      *
  844.      * @param   string  $type   The resource type to create the filename for.
  845.      * @param   array   $parts  An associative array of filename information. Optional.
  846.      *
  847.      * @return  string  The filename.
  848.      */
  849.     protected static function createFileName($type$parts array())
  850.     {
  851.         $filename '';
  852.  
  853.         switch ($type)
  854.         {
  855.             case 'controller':
  856.                 if (!empty($parts['format']))
  857.                 {
  858.                     if ($parts['format'== 'html')
  859.                     {
  860.                         $parts['format''';
  861.                     }
  862.                     else
  863.                     {
  864.                         $parts['format''.' $parts['format'];
  865.                     }
  866.                 }
  867.                 else
  868.                 {
  869.                     $parts['format''';
  870.                 }
  871.  
  872.                 $filename strtolower($parts['name'$parts['format''.php');
  873.                 break;
  874.  
  875.             case 'view':
  876.                 if (!empty($parts['type']))
  877.                 {
  878.                     $parts['type''.' $parts['type'];
  879.                 }
  880.                 else
  881.                 {
  882.                     $parts['type''';
  883.                 }
  884.  
  885.                 $filename strtolower($parts['name''/view' $parts['type''.php');
  886.                 break;
  887.         }
  888.  
  889.         return $filename;
  890.     }
  891.  
  892.     /**
  893.      * Executes a given controller task. The onBefore<task> and onAfter<task>
  894.      * methods are called automatically if they exist.
  895.      *
  896.      * @param   string  $task  The task to execute, e.g. "browse"
  897.      *
  898.      * @return  null|bool False on execution failure
  899.      */
  900.     public function execute($task)
  901.     {
  902.         $this->task $task;
  903.  
  904.         $method_name 'onBefore' ucfirst($task);
  905.  
  906.         if (!method_exists($this$method_name))
  907.         {
  908.             $result $this->onBeforeGenericTask($task);
  909.         }
  910.         elseif (method_exists($this$method_name))
  911.         {
  912.             $result $this->$method_name();
  913.         }
  914.         else
  915.         {
  916.             $result true;
  917.         }
  918.  
  919.         if ($result)
  920.         {
  921.             $plugin_event FOFInflector::camelize('on before ' $this->bareComponent ' controller ' $this->view ' ' $task);
  922.             $plugin_result FOFPlatform::getInstance()->runPlugins($plugin_eventarray(&$this&$this->input));
  923.  
  924.             if (in_array(false$plugin_resulttrue))
  925.             {
  926.                 $result false;
  927.             }
  928.         }
  929.  
  930.         if (!$result)
  931.         {
  932.             throw new Exception(JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN')403);
  933.         }
  934.  
  935.         // Do not allow the display task to be directly called
  936.         $task strtolower($task);
  937.  
  938.         if (isset($this->taskMap[$task]))
  939.         {
  940.             $doTask $this->taskMap[$task];
  941.         }
  942.         elseif (isset($this->taskMap['__default']))
  943.         {
  944.             $doTask $this->taskMap['__default'];
  945.         }
  946.         else
  947.         {
  948.             $doTask null;
  949.         }
  950.  
  951.         if ($doTask == 'display')
  952.         {
  953.             JResponse::setHeader('Status''400 Bad Request'true);
  954.  
  955.             throw new Exception('Bad Request'400);
  956.         }
  957.  
  958.         $this->doTask $doTask;
  959.  
  960.         $ret $this->$doTask();
  961.  
  962.         $method_name 'onAfter' ucfirst($task);
  963.  
  964.         if (method_exists($this$method_name))
  965.         {
  966.             $result $this->$method_name();
  967.         }
  968.         else
  969.         {
  970.             $result true;
  971.         }
  972.  
  973.         if ($result)
  974.         {
  975.             $plugin_event FOFInflector::camelize('on after ' $this->bareComponent ' controller ' $this->view ' ' $task);
  976.             $plugin_result FOFPlatform::getInstance()->runPlugins($plugin_eventarray(&$this&$this->input&$ret));
  977.  
  978.             if (in_array(false$plugin_resulttrue))
  979.             {
  980.                 $result false;
  981.             }
  982.         }
  983.  
  984.         if (!$result)
  985.         {
  986.             throw new Exception(JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN')403);
  987.         }
  988.  
  989.         return $ret;
  990.     }
  991.  
  992.     /**
  993.      * Default task. Assigns a model to the view and asks the view to render
  994.      * itself.
  995.      *
  996.      * YOU MUST NOT USETHIS TASK DIRECTLY IN A URL. It is supposed to be
  997.      * used ONLY inside your code. In the URL, use task=browse instead.
  998.      *
  999.      * @param   bool  $cachable   Is this view cacheable?
  1000.      * @param   bool  $urlparams  Add your safe URL parameters (see further down in the code)
  1001.      *
  1002.      * @return  void 
  1003.      */
  1004.     public function display($cachable false$urlparams false)
  1005.     {
  1006.         $document FOFPlatform::getInstance()->getDocument();
  1007.  
  1008.         if ($document instanceof JDocument)
  1009.         {
  1010.             $viewType $document->getType();
  1011.         }
  1012.         else
  1013.         {
  1014.             $viewType $this->input->getCmd('format''html');
  1015.         }
  1016.  
  1017.         $view $this->getThisView();
  1018.  
  1019.         // Get/Create the model
  1020.  
  1021.         if ($model $this->getThisModel())
  1022.         {
  1023.             // Push the model into the view (as default)
  1024.             $view->setModel($modeltrue);
  1025.         }
  1026.  
  1027.         // Set the layout
  1028.         $view->setLayout(is_null($this->layout'default' $this->layout);
  1029.  
  1030.         // Display the view
  1031.         $conf JFactory::getConfig();
  1032.  
  1033.         if (!FOFPlatform::getInstance()->isCli(&& JFactory::getApplication()->isSite(&& $cachable && ($viewType != 'feed'&& $conf->get('caching'>= 1)
  1034.         {
  1035.             // Get a JCache object
  1036.             $option $this->input->get('option''com_foobar''cmd');
  1037.             $cache JFactory::getCache($option'view');
  1038.  
  1039.             // Set up a cache ID based on component, view, task and user group assignment
  1040.             $user FOFPlatform::getInstance()->getUser();
  1041.  
  1042.             if ($user->guest)
  1043.             {
  1044.                 $groups array();
  1045.             }
  1046.             else
  1047.             {
  1048.                 $groups $user->groups;
  1049.             }
  1050.  
  1051.             // Set up safe URL parameters
  1052.  
  1053.             if (!is_array($urlparams))
  1054.             {
  1055.                 $urlparams array(
  1056.                     'option'        => 'CMD',
  1057.                     'view'            => 'CMD',
  1058.                     'task'            => 'CMD',
  1059.                     'format'        => 'CMD',
  1060.                     'layout'        => 'CMD',
  1061.                     'id'            => 'INT',
  1062.                 );
  1063.             }
  1064.  
  1065.             if (is_array($urlparams))
  1066.             {
  1067.                 $app JFactory::getApplication();
  1068.  
  1069.                 $registeredurlparams null;
  1070.  
  1071.                 if (FOFPlatform::getInstance()->checkVersion(JVERSION'3.0''ge'))
  1072.                 {
  1073.                     if (property_exists($app'registeredurlparams'))
  1074.                     {
  1075.                         $registeredurlparams $app->registeredurlparams;
  1076.                     }
  1077.                 }
  1078.                 else
  1079.                 {
  1080.                     $registeredurlparams $app->get('registeredurlparams');
  1081.                 }
  1082.  
  1083.                 if (empty($registeredurlparams))
  1084.                 {
  1085.                     $registeredurlparams new stdClass;
  1086.                 }
  1087.  
  1088.                 foreach ($urlparams AS $key => $value)
  1089.                 {
  1090.                     // Add your safe url parameters with variable type as value {@see JFilterInput::clean()}.
  1091.                     $registeredurlparams->$key $value;
  1092.                 }
  1093.  
  1094.                 if (FOFPlatform::getInstance()->checkVersion(JVERSION'3.0''ge'))
  1095.                 {
  1096.                     $app->registeredurlparams $registeredurlparams;
  1097.                 }
  1098.                 else
  1099.                 {
  1100.                     $app->set('registeredurlparams'$registeredurlparams);
  1101.                 }
  1102.             }
  1103.  
  1104.             // Create the cache ID after setting the registered URL params, as they are used to generate the ID
  1105.             $cacheId md5(serialize(array(JCache::makeId()$view->getName()$this->doTask$groups)));
  1106.  
  1107.             // Get the cached view or cache the current view
  1108.             $cache->get($view'display'$cacheId);
  1109.         }
  1110.         else
  1111.         {
  1112.             // Display without caching
  1113.             $view->display();
  1114.         }
  1115.  
  1116.         return true;
  1117.     }
  1118.  
  1119.     /**
  1120.      * Implements a default browse task, i.e. read a bunch of records and send
  1121.      * them to the browser.
  1122.      *
  1123.      * @return  void 
  1124.      */
  1125.     public function browse()
  1126.     {
  1127.         if ($this->input->get('savestate'-999'int'== -999)
  1128.         {
  1129.             $this->input->set('savestate'true);
  1130.         }
  1131.  
  1132.         // Do I have a form?
  1133.         $model $this->getThisModel();
  1134.  
  1135.         if (empty($this->layout))
  1136.         {
  1137.             $formname 'form.default';
  1138.         }
  1139.         else
  1140.         {
  1141.             $formname 'form.' $this->layout;
  1142.         }
  1143.  
  1144.         $model->setState('form_name'$formname);
  1145.  
  1146.         $form $model->getForm();
  1147.  
  1148.         if ($form !== false)
  1149.         {
  1150.             $this->hasForm true;
  1151.         }
  1152.  
  1153.         $this->display(in_array('browse'$this->cacheableTasks));
  1154.  
  1155.         return true;
  1156.     }
  1157.  
  1158.     /**
  1159.      * Single record read. The id set in the request is passed to the model and
  1160.      * then the item layout is used to render the result.
  1161.      *
  1162.      * @return  void 
  1163.      */
  1164.     public function read()
  1165.     {
  1166.         // Load the model
  1167.         $model $this->getThisModel();
  1168.  
  1169.         if (!$model->getId())
  1170.         {
  1171.             $model->setIDsFromRequest();
  1172.         }
  1173.  
  1174.         // Set the layout to item, if it's not set in the URL
  1175.  
  1176.         if (is_null($this->layout))
  1177.         {
  1178.             $this->layout 'item';
  1179.         }
  1180.  
  1181.         // Do I have a form?
  1182.         $model->setState('form_name''form.' $this->layout);
  1183.  
  1184.         $item $model->getItem();
  1185.  
  1186.         if (!($item instanceof FOFTable))
  1187.         {
  1188.             return false;
  1189.         }
  1190.  
  1191.         $itemKey $item->getKeyName();
  1192.  
  1193.         if ($item->$itemKey != $model->getId())
  1194.         {
  1195.             return false;
  1196.         }
  1197.  
  1198.         $formData is_object($item$item->getData(array();
  1199.         $form $model->getForm($formData);
  1200.  
  1201.         if ($form !== false)
  1202.         {
  1203.             $this->hasForm true;
  1204.         }
  1205.  
  1206.         // Display
  1207.         $this->display(in_array('read'$this->cacheableTasks));
  1208.  
  1209.         return true;
  1210.     }
  1211.  
  1212.     /**
  1213.      * Single record add. The form layout is used to present a blank page.
  1214.      *
  1215.      * @return  void 
  1216.      */
  1217.     public function add()
  1218.     {
  1219.         // Load and reset the model
  1220.         $model $this->getThisModel();
  1221.         $model->reset();
  1222.  
  1223.         // Set the layout to form, if it's not set in the URL
  1224.  
  1225.         if (is_null($this->layout))
  1226.         {
  1227.             $this->layout 'form';
  1228.         }
  1229.  
  1230.         // Do I have a form?
  1231.         $model->setState('form_name''form.' $this->layout);
  1232.  
  1233.         $item $model->getItem();
  1234.  
  1235.         if (!($item instanceof FOFTable))
  1236.         {
  1237.             return false;
  1238.         }
  1239.  
  1240.         $formData is_object($item$item->getData(array();
  1241.         $form $model->getForm($formData);
  1242.  
  1243.         if ($form !== false)
  1244.         {
  1245.             $this->hasForm true;
  1246.         }
  1247.  
  1248.         // Display
  1249.         $this->display(in_array('add'$this->cacheableTasks));
  1250.     }
  1251.  
  1252.     /**
  1253.      * Single record edit. The ID set in the request is passed to the model,
  1254.      * then the form layout is used to edit the result.
  1255.      *
  1256.      * @return  void 
  1257.      */
  1258.     public function edit()
  1259.     {
  1260.         // Load the model
  1261.         $model $this->getThisModel();
  1262.  
  1263.         if (!$model->getId())
  1264.         {
  1265.             $model->setIDsFromRequest();
  1266.         }
  1267.  
  1268.         $status $model->checkout();
  1269.  
  1270.         if (!$status)
  1271.         {
  1272.             // Redirect on error
  1273.  
  1274.             if ($customURL $this->input->get('returnurl''''string'))
  1275.             {
  1276.                 $customURL base64_decode($customURL);
  1277.             }
  1278.  
  1279.             $url !empty($customURL$customURL 'index.php?option=' $this->component '&view=' FOFInflector::pluralize($this->view);
  1280.             $this->setRedirect($url$model->getError()'error');
  1281.  
  1282.             return false;
  1283.         }
  1284.  
  1285.         // Set the layout to form, if it's not set in the URL
  1286.  
  1287.         if (is_null($this->layout))
  1288.         {
  1289.             $this->layout 'form';
  1290.         }
  1291.  
  1292.         // Do I have a form?
  1293.         $model->setState('form_name''form.' $this->layout);
  1294.  
  1295.         $item $model->getItem();
  1296.  
  1297.         if (!($item instanceof FOFTable))
  1298.         {
  1299.             return false;
  1300.         }
  1301.  
  1302.         $itemKey $item->getKeyName();
  1303.  
  1304.         if ($item->$itemKey != $model->getId())
  1305.         {
  1306.             return false;
  1307.         }
  1308.  
  1309.         $formData is_object($item$item->getData(array();
  1310.         $form $model->getForm($formData);
  1311.  
  1312.         if ($form !== false)
  1313.         {
  1314.             $this->hasForm true;
  1315.         }
  1316.  
  1317.         // Display
  1318.         $this->display(in_array('edit'$this->cacheableTasks));
  1319.  
  1320.         return true;
  1321.     }
  1322.  
  1323.     /**
  1324.      * Save the incoming data and then return to the Edit task
  1325.      *
  1326.      * @return  void 
  1327.      */
  1328.     public function apply()
  1329.     {
  1330.         // CSRF prevention
  1331.  
  1332.         if ($this->csrfProtection)
  1333.         {
  1334.             $this->_csrfProtection();
  1335.         }
  1336.  
  1337.         $model $this->getThisModel();
  1338.         $result $this->applySave();
  1339.  
  1340.         // Redirect to the edit task
  1341.  
  1342.         if ($result)
  1343.         {
  1344.             $id $this->input->get('id'0'int');
  1345.             $textkey strtoupper($this->component'_LBL_' strtoupper($this->view'_SAVED';
  1346.  
  1347.             if ($customURL $this->input->get('returnurl''''string'))
  1348.             {
  1349.                 $customURL base64_decode($customURL);
  1350.             }
  1351.  
  1352.             $url !empty($customURL$customURL 'index.php?option=' $this->component '&view=' $this->view '&task=edit&id=' $id;
  1353.             $this->setRedirect($urlJText::_($textkey));
  1354.         }
  1355.  
  1356.         return $result;
  1357.     }
  1358.  
  1359.     /**
  1360.      * Duplicates selected items
  1361.      *
  1362.      * @return  void 
  1363.      */
  1364.     public function copy()
  1365.     {
  1366.         // CSRF prevention
  1367.  
  1368.         if ($this->csrfProtection)
  1369.         {
  1370.             $this->_csrfProtection();
  1371.         }
  1372.  
  1373.         $model $this->getThisModel();
  1374.  
  1375.         if (!$model->getId())
  1376.         {
  1377.             $model->setIDsFromRequest();
  1378.         }
  1379.  
  1380.         $status $model->copy();
  1381.  
  1382.         // Redirect
  1383.  
  1384.         if ($customURL $this->input->get('returnurl''''string'))
  1385.         {
  1386.             $customURL base64_decode($customURL);
  1387.         }
  1388.  
  1389.         $url !empty($customURL$customURL 'index.php?option=' $this->component '&view=' FOFInflector::pluralize($this->view);
  1390.  
  1391.         if (!$status)
  1392.         {
  1393.             $this->setRedirect($url$model->getError()'error');
  1394.  
  1395.             return false;
  1396.         }
  1397.         else
  1398.         {
  1399.             JResponse::setHeader('Status''201 Created'true);
  1400.             $this->setRedirect($url);
  1401.  
  1402.             return true;
  1403.         }
  1404.     }
  1405.  
  1406.     /**
  1407.      * Save the incoming data and then return to the Browse task
  1408.      *
  1409.      * @return  void 
  1410.      */
  1411.     public function save()
  1412.     {
  1413.         // CSRF prevention
  1414.         if ($this->csrfProtection)
  1415.         {
  1416.             $this->_csrfProtection();
  1417.         }
  1418.  
  1419.         $result $this->applySave();
  1420.  
  1421.         // Redirect to the display task
  1422.  
  1423.         if ($result)
  1424.         {
  1425.             $textkey strtoupper($this->component'_LBL_' strtoupper($this->view'_SAVED';
  1426.  
  1427.             if ($customURL $this->input->get('returnurl''''string'))
  1428.             {
  1429.                 $customURL base64_decode($customURL);
  1430.             }
  1431.  
  1432.             $url !empty($customURL$customURL 'index.php?option=' $this->component '&view=' FOFInflector::pluralize($this->view);
  1433.             $this->setRedirect($urlJText::_($textkey));
  1434.         }
  1435.  
  1436.         return $result;
  1437.     }
  1438.  
  1439.     /**
  1440.      * Save the incoming data and then return to the Add task
  1441.      *
  1442.      * @return  void 
  1443.      */
  1444.     public function savenew()
  1445.     {
  1446.         // CSRF prevention
  1447.         if ($this->csrfProtection)
  1448.         {
  1449.             $this->_csrfProtection();
  1450.         }
  1451.  
  1452.         $result $this->applySave();
  1453.  
  1454.         // Redirect to the display task
  1455.  
  1456.         if ($result)
  1457.         {
  1458.             $textkey strtoupper($this->component'_LBL_' strtoupper($this->view'_SAVED';
  1459.  
  1460.             if ($customURL $this->input->get('returnurl''''string'))
  1461.             {
  1462.                 $customURL base64_decode($customURL);
  1463.             }
  1464.  
  1465.             $url !empty($customURL$customURL 'index.php?option=' $this->component '&view=' $this->view '&task=add';
  1466.             $this->setRedirect($urlJText::_($textkey));
  1467.         }
  1468.  
  1469.         return $result;
  1470.     }
  1471.  
  1472.     /**
  1473.      * Cancel the edit, check in the record and return to the Browse task
  1474.      *
  1475.      * @return  void 
  1476.      */
  1477.     public function cancel()
  1478.     {
  1479.         $model $this->getThisModel();
  1480.  
  1481.         if (!$model->getId())
  1482.         {
  1483.             $model->setIDsFromRequest();
  1484.         }
  1485.  
  1486.         $model->checkin();
  1487.  
  1488.         // Remove any saved data
  1489.         JFactory::getSession()->set($model->getHash('savedata'null);
  1490.  
  1491.         // Redirect to the display task
  1492.  
  1493.         if ($customURL $this->input->get('returnurl''''string'))
  1494.         {
  1495.             $customURL base64_decode($customURL);
  1496.         }
  1497.  
  1498.         $url !empty($customURL$customURL 'index.php?option=' $this->component '&view=' FOFInflector::pluralize($this->view);
  1499.         $this->setRedirect($url);
  1500.  
  1501.         return true;
  1502.     }
  1503.  
  1504.     /**
  1505.      * Sets the access to public. Joomla! 1.5 compatibility.
  1506.      *
  1507.      * @return  void 
  1508.      *
  1509.      * @deprecated since 2.0
  1510.      */
  1511.     public function accesspublic()
  1512.     {
  1513.         // CSRF prevention
  1514.  
  1515.         if ($this->csrfProtection)
  1516.         {
  1517.             $this->_csrfProtection();
  1518.         }
  1519.  
  1520.         return $this->setaccess(0);
  1521.     }
  1522.  
  1523.     /**
  1524.      * Sets the access to registered. Joomla! 1.5 compatibility.
  1525.      *
  1526.      * @return  void 
  1527.      *
  1528.      * @deprecated since 2.0
  1529.      */
  1530.     public function accessregistered()
  1531.     {
  1532.         // CSRF prevention
  1533.  
  1534.         if ($this->csrfProtection)
  1535.         {
  1536.             $this->_csrfProtection();
  1537.         }
  1538.  
  1539.         return $this->setaccess(1);
  1540.     }
  1541.  
  1542.     /**
  1543.      * Sets the access to special. Joomla! 1.5 compatibility.
  1544.      *
  1545.      * @return  void 
  1546.      *
  1547.      * @deprecated since 2.0
  1548.      */
  1549.     public function accessspecial()
  1550.     {
  1551.         // CSRF prevention
  1552.  
  1553.         if ($this->csrfProtection)
  1554.         {
  1555.             $this->_csrfProtection();
  1556.         }
  1557.  
  1558.         return $this->setaccess(2);
  1559.     }
  1560.  
  1561.     /**
  1562.      * Publish (set enabled = 1) an item.
  1563.      *
  1564.      * @return  void 
  1565.      */
  1566.     public function publish()
  1567.     {
  1568.         // CSRF prevention
  1569.         if ($this->csrfProtection)
  1570.         {
  1571.             $this->_csrfProtection();
  1572.         }
  1573.  
  1574.         return $this->setstate(1);
  1575.     }
  1576.  
  1577.     /**
  1578.      * Unpublish (set enabled = 0) an item.
  1579.      *
  1580.      * @return  void 
  1581.      */
  1582.     public function unpublish()
  1583.     {
  1584.         // CSRF prevention
  1585.         if ($this->csrfProtection)
  1586.         {
  1587.             $this->_csrfProtection();
  1588.         }
  1589.  
  1590.         return $this->setstate(0);
  1591.     }
  1592.  
  1593.     /**
  1594.      * Archive (set enabled = 2) an item.
  1595.      *
  1596.      * @return  void 
  1597.      */
  1598.     public function archive()
  1599.     {
  1600.         // CSRF prevention
  1601.         if ($this->csrfProtection)
  1602.         {
  1603.             $this->_csrfProtection();
  1604.         }
  1605.  
  1606.         return $this->setstate(2);
  1607.     }
  1608.  
  1609.     /**
  1610.      * Trash (set enabled = -2) an item.
  1611.      *
  1612.      * @return  void 
  1613.      */
  1614.     public function trash()
  1615.     {
  1616.         // CSRF prevention
  1617.         if ($this->csrfProtection)
  1618.         {
  1619.             $this->_csrfProtection();
  1620.         }
  1621.  
  1622.         return $this->setstate(-2);
  1623.     }
  1624.  
  1625.     /**
  1626.      * Saves the order of the items
  1627.      *
  1628.      * @return  void 
  1629.      */
  1630.     public function saveorder()
  1631.     {
  1632.         // CSRF prevention
  1633.  
  1634.         if ($this->csrfProtection)
  1635.         {
  1636.             $this->_csrfProtection();
  1637.         }
  1638.  
  1639.         $model $this->getThisModel();
  1640.  
  1641.         if (!$model->getId())
  1642.         {
  1643.             $model->setIDsFromRequest();
  1644.         }
  1645.  
  1646.         $ids $model->getIds();
  1647.         $orders $this->input->get('order'array()'array');
  1648.  
  1649.         if ($n count($ids))
  1650.         {
  1651.             for ($i 0$i $n$i++)
  1652.             {
  1653.                 $model->setId($ids[$i]);
  1654.                 $neworder = (int) $orders[$i];
  1655.  
  1656.                 $item $model->getItem();
  1657.  
  1658.                 if (!($item instanceof FOFTable))
  1659.                 {
  1660.                     return false;
  1661.                 }
  1662.  
  1663.                 $key $item->getKeyName();
  1664.  
  1665.                 if ($item->$key == $ids[$i])
  1666.                 {
  1667.                     $item->ordering = $neworder;
  1668.                     $model->save($item);
  1669.                 }
  1670.             }
  1671.         }
  1672.  
  1673.         $status $model->reorder();
  1674.  
  1675.         // Redirect
  1676.  
  1677.         if ($customURL $this->input->get('returnurl''''string'))
  1678.         {
  1679.             $customURL base64_decode($customURL);
  1680.         }
  1681.  
  1682.         $url !empty($customURL$customURL 'index.php?option=' $this->component '&view=' FOFInflector::pluralize($this->view);
  1683.         $this->setRedirect($url);
  1684.  
  1685.         return $status;
  1686.     }
  1687.  
  1688.     /**
  1689.      * Moves selected items one position down the ordering list
  1690.      *
  1691.      * @return  void 
  1692.      */
  1693.     public function orderdown()
  1694.     {
  1695.         // CSRF prevention
  1696.  
  1697.         if ($this->csrfProtection)
  1698.         {
  1699.             $this->_csrfProtection();
  1700.         }
  1701.  
  1702.         $model $this->getThisModel();
  1703.  
  1704.         if (!$model->getId())
  1705.         {
  1706.             $model->setIDsFromRequest();
  1707.         }
  1708.  
  1709.         $status $model->move(1);
  1710.  
  1711.         // Redirect
  1712.  
  1713.         if ($customURL $this->input->get('returnurl''''string'))
  1714.         {
  1715.             $customURL base64_decode($customURL);
  1716.         }
  1717.  
  1718.         $url !empty($customURL$customURL 'index.php?option=' $this->component '&view=' FOFInflector::pluralize($this->view);
  1719.  
  1720.         if (!$status)
  1721.         {
  1722.             $this->setRedirect($url$model->getError()'error');
  1723.         }
  1724.         else
  1725.         {
  1726.             $this->setRedirect($url);
  1727.         }
  1728.  
  1729.         return $status;
  1730.     }
  1731.  
  1732.     /**
  1733.      * Moves selected items one position up the ordering list
  1734.      *
  1735.      * @return  void 
  1736.      */
  1737.     public function orderup()
  1738.     {
  1739.         // CSRF prevention
  1740.  
  1741.         if ($this->csrfProtection)
  1742.         {
  1743.             $this->_csrfProtection();
  1744.         }
  1745.  
  1746.         $model $this->getThisModel();
  1747.  
  1748.         if (!$model->getId())
  1749.         {
  1750.             $model->setIDsFromRequest();
  1751.         }
  1752.  
  1753.         $status $model->move(-1);
  1754.  
  1755.         // Redirect
  1756.  
  1757.         if ($customURL $this->input->get('returnurl''''string'))
  1758.         {
  1759.             $customURL base64_decode($customURL);
  1760.         }
  1761.  
  1762.         $url !empty($customURL$customURL 'index.php?option=' $this->component '&view=' FOFInflector::pluralize($this->view);
  1763.  
  1764.         if (!$status)
  1765.         {
  1766.             $this->setRedirect($url$model->getError()'error');
  1767.         }
  1768.         else
  1769.         {
  1770.             $this->setRedirect($url);
  1771.         }
  1772.  
  1773.         return $status;
  1774.     }
  1775.  
  1776.     /**
  1777.      * Delete selected item(s)
  1778.      *
  1779.      * @return  void 
  1780.      */
  1781.     public function remove()
  1782.     {
  1783.         // CSRF prevention
  1784.  
  1785.         if ($this->csrfProtection)
  1786.         {
  1787.             $this->_csrfProtection();
  1788.         }
  1789.  
  1790.         $model $this->getThisModel();
  1791.  
  1792.         if (!$model->getId())
  1793.         {
  1794.             $model->setIDsFromRequest();
  1795.         }
  1796.  
  1797.         $status $model->delete();
  1798.  
  1799.         // Redirect
  1800.  
  1801.         if ($customURL $this->input->get('returnurl''''string'))
  1802.         {
  1803.             $customURL base64_decode($customURL);
  1804.         }
  1805.  
  1806.         $url !empty($customURL$customURL 'index.php?option=' $this->component '&view=' FOFInflector::pluralize($this->view);
  1807.  
  1808.         if (!$status)
  1809.         {
  1810.             $this->setRedirect($url$model->getError()'error');
  1811.         }
  1812.         else
  1813.         {
  1814.             $this->setRedirect($url);
  1815.         }
  1816.  
  1817.         return $status;
  1818.     }
  1819.  
  1820.     /**
  1821.      * Redirects the browser or returns false if no redirect is set.
  1822.      *
  1823.      * @return  boolean  False if no redirect exists.
  1824.      */
  1825.     public function redirect()
  1826.     {
  1827.         if ($this->redirect)
  1828.         {
  1829.             $app JFactory::getApplication();
  1830.             $app->redirect($this->redirect$this->message$this->messageType);
  1831.  
  1832.             return true;
  1833.         }
  1834.  
  1835.         return false;
  1836.     }
  1837.  
  1838.     /**
  1839.      * Returns true if there is a redirect set in the controller
  1840.      *
  1841.      * @return  boolean 
  1842.      */
  1843.     public function hasRedirect()
  1844.     {
  1845.         return !empty($this->redirect);
  1846.     }
  1847.  
  1848.     /**
  1849.      * Register the default task to perform if a mapping is not found.
  1850.      *
  1851.      * @param   string  $method  The name of the method in the derived class to perform if a named task is not found.
  1852.      *
  1853.      * @return  FOFController  A FOFController object to support chaining.
  1854.      */
  1855.     public function registerDefaultTask($method)
  1856.     {
  1857.         $this->registerTask('__default'$method);
  1858.  
  1859.         return $this;
  1860.     }
  1861.  
  1862.     /**
  1863.      * Register (map) a task to a method in the class.
  1864.      *
  1865.      * @param   string  $task    The task.
  1866.      * @param   string  $method  The name of the method in the derived class to perform for this task.
  1867.      *
  1868.      * @return  FOFController  A FOFController object to support chaining.
  1869.      */
  1870.     public function registerTask($task$method)
  1871.     {
  1872.         if (in_array(strtolower($method)$this->methods))
  1873.         {
  1874.             $this->taskMap[strtolower($task)$method;
  1875.         }
  1876.  
  1877.         return $this;
  1878.     }
  1879.  
  1880.     /**
  1881.      * Unregister (unmap) a task in the class.
  1882.      *
  1883.      * @param   string  $task  The task.
  1884.      *
  1885.      * @return  FOFController  This object to support chaining.
  1886.      */
  1887.     public function unregisterTask($task)
  1888.     {
  1889.         unset($this->taskMap[strtolower($task)]);
  1890.  
  1891.         return $this;
  1892.     }
  1893.  
  1894.     /**
  1895.      * Sets the internal message that is passed with a redirect
  1896.      *
  1897.      * @param   string  $text  Message to display on redirect.
  1898.      * @param   string  $type  Message type. Optional, defaults to 'message'.
  1899.      *
  1900.      * @return  string  Previous message
  1901.      */
  1902.     public function setMessage($text$type 'message')
  1903.     {
  1904.         $previous $this->message;
  1905.         $this->message $text;
  1906.         $this->messageType $type;
  1907.  
  1908.         return $previous;
  1909.     }
  1910.  
  1911.     /**
  1912.      * Sets an entire array of search paths for resources.
  1913.      *
  1914.      * @param   string  $type  The type of path to set, typically 'view' or 'model'.
  1915.      * @param   string  $path  The new set of search paths. If null or false, resets to the current directory only.
  1916.      *
  1917.      * @return  void 
  1918.      */
  1919.     protected function setPath($type$path)
  1920.     {
  1921.         // Clear out the prior search dirs
  1922.         $this->paths[$typearray();
  1923.  
  1924.         // Actually add the user-specified directories
  1925.         $this->addPath($type$path);
  1926.     }
  1927.  
  1928.     /**
  1929.      * Registers a redirection with an optional message. The redirection is
  1930.      * carried out when you use the redirect method.
  1931.      *
  1932.      * @param   string  $url   The URL to redirect to
  1933.      * @param   string  $msg   The message to be pushed to the application
  1934.      * @param   string  $type  The message type to be pushed to the application, e.g. 'error'
  1935.      *
  1936.      * @return  FOFController  This object to support chaining
  1937.      */
  1938.     public function setRedirect($url$msg null$type null)
  1939.     {
  1940.         // Do the logic only if we're parsing a raw url (index.php?foo=bar&etc=etc)
  1941.         if (strpos($url'index.php'=== 0)
  1942.         {
  1943.             $isAdmin FOFPlatform::getInstance()->isBackend();
  1944.             $auto false;
  1945.  
  1946.             if (($this->autoRouting == || $this->autoRouting == 3&& $isAdmin)
  1947.             {
  1948.                 $auto true;
  1949.             }
  1950.             elseif (($this->autoRouting == || $this->autoRouting == 3&& !$isAdmin)
  1951.             {
  1952.                 $auto true;
  1953.             }
  1954.  
  1955.             if ($auto)
  1956.             {
  1957.                 $url JRoute::_($urlfalse);
  1958.             }
  1959.         }
  1960.  
  1961.         $this->redirect = $url;
  1962.  
  1963.         if ($msg !== null)
  1964.         {
  1965.             // Controller may have set this directly
  1966.             $this->message $msg;
  1967.         }
  1968.  
  1969.         // Ensure the type is not overwritten by a previous call to setMessage.
  1970.         if (empty($type))
  1971.         {
  1972.             if (empty($this->messageType))
  1973.             {
  1974.                 $this->messageType 'message';
  1975.             }
  1976.         }
  1977.  
  1978.         // If the type is explicitly set, set it.
  1979.         else
  1980.         {
  1981.             $this->messageType $type;
  1982.         }
  1983.  
  1984.         return $this;
  1985.     }
  1986.  
  1987.     /**
  1988.      * Sets the published state (the enabled field) of the selected item(s)
  1989.      *
  1990.      * @param   integer  $state  The desired state. 0 is unpublished, 1 is published.
  1991.      *
  1992.      * @return  void 
  1993.      */
  1994.     final protected function setstate($state 0)
  1995.     {
  1996.         $model $this->getThisModel();
  1997.  
  1998.         if (!$model->getId())
  1999.         {
  2000.             $model->setIDsFromRequest();
  2001.         }
  2002.  
  2003.         $status $model->publish($state);
  2004.  
  2005.         // Redirect
  2006.  
  2007.         if ($customURL $this->input->get('returnurl''''string'))
  2008.         {
  2009.             $customURL base64_decode($customURL);
  2010.         }
  2011.  
  2012.         $url !empty($customURL$customURL 'index.php?option=' $this->component '&view=' FOFInflector::pluralize($this->view);
  2013.  
  2014.         if (!$status)
  2015.         {
  2016.             $this->setRedirect($url$model->getError()'error');
  2017.         }
  2018.         else
  2019.         {
  2020.             $this->setRedirect($url);
  2021.         }
  2022.  
  2023.         return $status;
  2024.     }
  2025.  
  2026.     /**
  2027.      * Sets the access level of the selected item(s).
  2028.      *
  2029.      * @param   integer  $level  The desired viewing access level ID
  2030.      *
  2031.      * @return  void 
  2032.      */
  2033.     final protected function setaccess($level 0)
  2034.     {
  2035.         $model $this->getThisModel();
  2036.  
  2037.         if (!$model->getId())
  2038.         {
  2039.             $model->setIDsFromRequest();
  2040.         }
  2041.  
  2042.         $id $model->getId();
  2043.  
  2044.         $item $model->getItem();
  2045.  
  2046.         if (!($item instanceof FOFTable))
  2047.         {
  2048.             return false;
  2049.         }
  2050.  
  2051.         $key $item->getKeyName();
  2052.         $loadedid $item->$key;
  2053.  
  2054.         if ($id == $loadedid)
  2055.         {
  2056.             $item->access $level;
  2057.             $status $model->save($item);
  2058.         }
  2059.         else
  2060.         {
  2061.             $status false;
  2062.         }
  2063.  
  2064.         // Redirect
  2065.  
  2066.         if ($customURL $this->input->get('returnurl''''string'))
  2067.         {
  2068.             $customURL base64_decode($customURL);
  2069.         }
  2070.  
  2071.         $url !empty($customURL$customURL 'index.php?option=' $this->component '&view=' FOFInflector::pluralize($this->view);
  2072.  
  2073.         if (!$status)
  2074.         {
  2075.             $this->setRedirect($url$model->getError()'error');
  2076.         }
  2077.         else
  2078.         {
  2079.             $this->setRedirect($url);
  2080.         }
  2081.  
  2082.         return $status;
  2083.     }
  2084.  
  2085.     /**
  2086.      * Common method to handle apply and save tasks
  2087.      *
  2088.      * @return  boolean  Returns true on success
  2089.      */
  2090.     final protected function applySave()
  2091.     {
  2092.         // Load the model
  2093.         $model $this->getThisModel();
  2094.  
  2095.         if (!$model->getId())
  2096.         {
  2097.             $model->setIDsFromRequest();
  2098.         }
  2099.  
  2100.         $id $model->getId();
  2101.  
  2102.         $data $this->input->getData();
  2103.  
  2104.         if (!$this->onBeforeApplySave($data))
  2105.         {
  2106.             return false;
  2107.         }
  2108.  
  2109.         // Set the layout to form, if it's not set in the URL
  2110.  
  2111.         if (is_null($this->layout))
  2112.         {
  2113.             $this->layout 'form';
  2114.         }
  2115.  
  2116.         // Do I have a form?
  2117.         $model->setState('form_name''form.' $this->layout);
  2118.  
  2119.         $status $model->save($data);
  2120.  
  2121.         if ($status && ($id != 0))
  2122.         {
  2123.             JResponse::setHeader('Status''201 Created'true);
  2124.  
  2125.             // Try to check-in the record if it's not a new one
  2126.             $status $model->checkin();
  2127.  
  2128.             if ($status)
  2129.             {
  2130.                 $status $this->onAfterApplySave();
  2131.             }
  2132.         }
  2133.  
  2134.         $this->input->set('id'$model->getId());
  2135.  
  2136.         if (!$status)
  2137.         {
  2138.             // Redirect on error
  2139.             $id $model->getId();
  2140.  
  2141.             if ($customURL $this->input->get('returnurl''''string'))
  2142.             {
  2143.                 $customURL base64_decode($customURL);
  2144.             }
  2145.  
  2146.             if (!empty($customURL))
  2147.             {
  2148.                 $url $customURL;
  2149.             }
  2150.             elseif ($id != 0)
  2151.             {
  2152.                 $url 'index.php?option=' $this->component '&view=' $this->view '&task=edit&id=' $id;
  2153.             }
  2154.             else
  2155.             {
  2156.                 $url 'index.php?option=' $this->component '&view=' $this->view '&task=add';
  2157.             }
  2158.  
  2159.             $this->setRedirect($url'<li>' implode('</li><li>'$model->getErrors()) '</li>''error');
  2160.  
  2161.             return false;
  2162.         }
  2163.         else
  2164.         {
  2165.             $session JFactory::getSession();
  2166.             $session->set($model->getHash('savedata'null);
  2167.  
  2168.             return true;
  2169.         }
  2170.     }
  2171.  
  2172.     /**
  2173.      * Returns the default model associated with the current view
  2174.      *
  2175.      * @param   array  $config  Configuration variables for the model
  2176.      *
  2177.      * @return  FOFModel  The global instance of the model (singleton)
  2178.      */
  2179.     final public function getThisModel($config array())
  2180.     {
  2181.         if (!is_object($this->_modelObject))
  2182.         {
  2183.             // Make sure $config is an array
  2184.             if (is_object($config))
  2185.             {
  2186.                 $config = (array) $config;
  2187.             }
  2188.             elseif (!is_array($config))
  2189.             {
  2190.                 $config array();
  2191.             }
  2192.  
  2193.             if (!empty($this->modelName))
  2194.             {
  2195.                 $parts FOFInflector::explode($this->modelName);
  2196.                 $modelName ucfirst(array_pop($parts));
  2197.                 $prefix FOFInflector::implode($parts);
  2198.             }
  2199.             else
  2200.             {
  2201.                 $prefix ucfirst($this->bareComponent'Model';
  2202.                 $modelName ucfirst(FOFInflector::pluralize($this->view));
  2203.             }
  2204.  
  2205.             if (!array_key_exists('input'$config|| !($config['input'instanceof FOFInput))
  2206.             {
  2207.                 $config['input'$this->input;
  2208.             }
  2209.  
  2210.             $this->_modelObject $this->getModel($modelName$prefix$config);
  2211.         }
  2212.  
  2213.         return $this->_modelObject;
  2214.     }
  2215.  
  2216.     /**
  2217.      * Method to get a model object, loading it if required.
  2218.      *
  2219.      * @param   string  $name    The model name. Optional.
  2220.      * @param   string  $prefix  The class prefix. Optional.
  2221.      * @param   array   $config  Configuration array for model. Optional.
  2222.      *
  2223.      * @return  object  The model.
  2224.      */
  2225.     public function getModel($name ''$prefix ''$config array())
  2226.     {
  2227.         // Make sure $config is an array
  2228.  
  2229.         if (is_object($config))
  2230.         {
  2231.             $config = (array) $config;
  2232.         }
  2233.         elseif (!is_array($config))
  2234.         {
  2235.             $config array();
  2236.         }
  2237.  
  2238.         if (empty($name))
  2239.         {
  2240.             $name $this->getName();
  2241.         }
  2242.  
  2243.         if (empty($prefix))
  2244.         {
  2245.             $prefix $this->model_prefix;
  2246.         }
  2247.  
  2248.         if ($model $this->createModel($name$prefix$config))
  2249.         {
  2250.             // Task is a reserved state
  2251.             $model->setState('task'$this->task);
  2252.  
  2253.             // Let's get the application object and set menu information if it's available
  2254.             if (!FOFPlatform::getInstance()->isCli())
  2255.             {
  2256.                 $app JFactory::getApplication();
  2257.                 $menu $app->getMenu();
  2258.  
  2259.                 if (is_object($menu))
  2260.                 {
  2261.                     if ($item $menu->getActive())
  2262.                     {
  2263.                         $params $menu->getParams($item->id);
  2264.  
  2265.                         // Set default state data
  2266.                         $model->setState('parameters.menu'$params);
  2267.                     }
  2268.                 }
  2269.             }
  2270.         }
  2271.  
  2272.         return $model;
  2273.     }
  2274.  
  2275.     /**
  2276.      * Returns current view object
  2277.      *
  2278.      * @param   array  $config  Configuration variables for the model
  2279.      *
  2280.      * @return  FOFView  The global instance of the view object (singleton)
  2281.      */
  2282.     final public function getThisView($config array())
  2283.     {
  2284.         if (!is_object($this->_viewObject))
  2285.         {
  2286.             // Make sure $config is an array
  2287.             if (is_object($config))
  2288.             {
  2289.                 $config = (array) $config;
  2290.             }
  2291.             elseif (!is_array($config))
  2292.             {
  2293.                 $config array();
  2294.             }
  2295.  
  2296.             $prefix null;
  2297.             $viewName null;
  2298.             $viewType null;
  2299.  
  2300.             if (!empty($this->viewName))
  2301.             {
  2302.                 $parts FOFInflector::explode($this->viewName);
  2303.                 $viewName ucfirst(array_pop($parts));
  2304.                 $prefix FOFInflector::implode($parts);
  2305.             }
  2306.             else
  2307.             {
  2308.                 $prefix ucfirst($this->bareComponent'View';
  2309.                 $viewName ucfirst($this->view);
  2310.             }
  2311.  
  2312.             $document FOFPlatform::getInstance()->getDocument();
  2313.  
  2314.             if ($document instanceof JDocument)
  2315.             {
  2316.                 $viewType $document->getType();
  2317.             }
  2318.             else
  2319.             {
  2320.                 $viewType $this->input->getCmd('format''html');
  2321.             }
  2322.  
  2323.             if (($viewType == 'html'&& $this->hasForm)
  2324.             {
  2325.                 $viewType 'form';
  2326.             }
  2327.  
  2328.             if (!array_key_exists('input'$config|| !($config['input'instanceof FOFInput))
  2329.             {
  2330.                 $config['input'$this->input;
  2331.             }
  2332.  
  2333.             $config['input']->set('base_path'$this->basePath);
  2334.  
  2335.             $this->_viewObject $this->getView($viewName$viewType$prefix$config);
  2336.         }
  2337.  
  2338.         return $this->_viewObject;
  2339.     }
  2340.  
  2341.     /**
  2342.      * Method to get the controller name
  2343.      *
  2344.      * The dispatcher name is set by default parsed using the classname, or it can be set
  2345.      * by passing a $config['name'] in the class constructor
  2346.      *
  2347.      * @return  string  The name of the dispatcher
  2348.      */
  2349.     public function getName()
  2350.     {
  2351.         if (empty($this->name))
  2352.         {
  2353.             if (empty($this->bareComponent))
  2354.             {
  2355.                 $r null;
  2356.  
  2357.                 if (!preg_match('/(.*)Controller/i'get_class($this)$r))
  2358.                 {
  2359.                     throw new Exception(JText::_('JLIB_APPLICATION_ERROR_CONTROLLER_GET_NAME')500);
  2360.                 }
  2361.  
  2362.                 $this->name strtolower($r[1]);
  2363.             }
  2364.             else
  2365.             {
  2366.                 $this->name $this->bareComponent;
  2367.             }
  2368.         }
  2369.  
  2370.         return $this->name;
  2371.     }
  2372.  
  2373.     /**
  2374.      * Get the last task that is being performed or was most recently performed.
  2375.      *
  2376.      * @return  string  The task that is being performed or was most recently performed.
  2377.      */
  2378.     public function getTask()
  2379.     {
  2380.         return $this->task;
  2381.     }
  2382.  
  2383.     /**
  2384.      * Gets the available tasks in the controller.
  2385.      *
  2386.      * @return  array  Array[i] of task names.
  2387.      */
  2388.     public function getTasks()
  2389.     {
  2390.         return $this->methods;
  2391.     }
  2392.  
  2393.     /**
  2394.      * Method to get a reference to the current view and load it if necessary.
  2395.      *
  2396.      * @param   string  $name    The view name. Optional, defaults to the controller name.
  2397.      * @param   string  $type    The view type. Optional.
  2398.      * @param   string  $prefix  The class prefix. Optional.
  2399.      * @param   array   $config  Configuration array for view. Optional.
  2400.      *
  2401.      * @return  FOFView  Reference to the view or an error.
  2402.      */
  2403.     public function getView($name ''$type ''$prefix ''$config array())
  2404.     {
  2405.         // Make sure $config is an array
  2406.         if (is_object($config))
  2407.         {
  2408.             $config = (array) $config;
  2409.         }
  2410.         elseif (!is_array($config))
  2411.         {
  2412.             $config array();
  2413.         }
  2414.  
  2415.         if (empty($name))
  2416.         {
  2417.             $name $this->getName();
  2418.         }
  2419.  
  2420.         if (empty($prefix))
  2421.         {
  2422.             $prefix $this->getName('View';
  2423.         }
  2424.  
  2425.         $signature md5($name $type $prefix serialize($config));
  2426.  
  2427.         if (empty($this->viewsCache[$signature]))
  2428.         {
  2429.             if ($view $this->createView($name$prefix$type$config))
  2430.             {
  2431.                 $this->viewsCache[$signature$view;
  2432.             }
  2433.             else
  2434.             {
  2435.                 throw new Exception(JText::sprintf('JLIB_APPLICATION_ERROR_VIEW_NOT_FOUND'$name$type$prefix)500);
  2436.             }
  2437.         }
  2438.  
  2439.         return $this->viewsCache[$signature];
  2440.     }
  2441.  
  2442.     /**
  2443.      * Creates a new model object
  2444.      *
  2445.      * @param   string  $name    The name of the model class, e.g. Items
  2446.      * @param   string  $prefix  The prefix of the model class, e.g. FoobarModel
  2447.      * @param   array   $config  The configuration parameters for the model class
  2448.      *
  2449.      * @return  FOFModel  The model object
  2450.      */
  2451.     protected function createModel($name$prefix ''$config array())
  2452.     {
  2453.         // Make sure $config is an array
  2454.  
  2455.         if (is_object($config))
  2456.         {
  2457.             $config = (array) $config;
  2458.         }
  2459.         elseif (!is_array($config))
  2460.         {
  2461.             $config array();
  2462.         }
  2463.  
  2464.         $result null;
  2465.  
  2466.         // Clean the model name
  2467.         $modelName preg_replace('/[^A-Z0-9_]/i'''$name);
  2468.         $classPrefix preg_replace('/[^A-Z0-9_]/i'''$prefix);
  2469.  
  2470.         $result FOFModel::getAnInstance($modelName$classPrefix$config);
  2471.  
  2472.         return $result;
  2473.     }
  2474.  
  2475.     /**
  2476.      * Method to load and return a model object.
  2477.      *
  2478.      * @param   string  $name    The name of the model.
  2479.      * @param   string  $prefix  Optional model prefix.
  2480.      * @param   array   $config  Configuration array for the model. Optional.
  2481.      *
  2482.      * @return  mixed   Model object on success; otherwise null
  2483.      */
  2484.     protected function &_createModel($name$prefix ''$config array())
  2485.     {
  2486.         JLog::add(__METHOD__ . ' is deprecated. Use createModel() instead.'JLog::WARNING'deprecated');
  2487.  
  2488.         return $this->createModel($name$prefix$config);
  2489.     }
  2490.  
  2491.     /**
  2492.      * Creates a View object instance and returns it
  2493.      *
  2494.      * @param   string  $name    The name of the view, e.g. Items
  2495.      * @param   string  $prefix  The prefix of the view, e.g. FoobarView
  2496.      * @param   string  $type    The type of the view, usually one of Html, Raw, Json or Csv
  2497.      * @param   array   $config  The configuration variables to use for creating the view
  2498.      *
  2499.      * @return  FOFView 
  2500.      */
  2501.     protected function createView($name$prefix ''$type ''$config array())
  2502.     {
  2503.         // Make sure $config is an array
  2504.  
  2505.         if (is_object($config))
  2506.         {
  2507.             $config = (array) $config;
  2508.         }
  2509.         elseif (!is_array($config))
  2510.         {
  2511.             $config array();
  2512.         }
  2513.  
  2514.         $result null;
  2515.  
  2516.         // Clean the view name
  2517.         $viewName preg_replace('/[^A-Z0-9_]/i'''$name);
  2518.         $classPrefix preg_replace('/[^A-Z0-9_]/i'''$prefix);
  2519.         $viewType preg_replace('/[^A-Z0-9_]/i'''$type);
  2520.  
  2521.         if (!isset($config['input']))
  2522.         {
  2523.             $config['input'$this->input;
  2524.         }
  2525.  
  2526.         if (($config['input'instanceof FOFInput))
  2527.         {
  2528.             $tmpInput $config['input'];
  2529.         }
  2530.         else
  2531.         {
  2532.             $tmpInput new FOFInput($config['input']);
  2533.         }
  2534.  
  2535.         // Guess the component name and view
  2536.  
  2537.         if (!empty($prefix))
  2538.         {
  2539.             preg_match('/(.*)View$/'$prefix$m);
  2540.             $component 'com_' strtolower($m[1]);
  2541.         }
  2542.         else
  2543.         {
  2544.             $component '';
  2545.         }
  2546.  
  2547.         if (empty($component&& array_key_exists('input'$config))
  2548.         {
  2549.             $component $tmpInput->get('option'$component'cmd');
  2550.         }
  2551.  
  2552.         if (array_key_exists('option'$config))
  2553.         {
  2554.             if ($config['option'])
  2555.             {
  2556.                 $component $config['option'];
  2557.             }
  2558.         }
  2559.  
  2560.         $config['option'$component;
  2561.  
  2562.         $view strtolower($viewName);
  2563.  
  2564.         if (empty($view&& array_key_exists('input'$config))
  2565.         {
  2566.             $view $tmpInput->get('view'$view'cmd');
  2567.         }
  2568.  
  2569.         if (array_key_exists('view'$config))
  2570.         {
  2571.             if ($config['view'])
  2572.             {
  2573.                 $view $config['view'];
  2574.             }
  2575.         }
  2576.  
  2577.         $config['view'$view;
  2578.  
  2579.         if (array_key_exists('input'$config))
  2580.         {
  2581.             $tmpInput->set('option'$config['option']);
  2582.             $tmpInput->set('view'$config['view']);
  2583.             $config['input'$tmpInput;
  2584.         }
  2585.  
  2586.         // Get the component directories
  2587.         $componentPaths FOFPlatform::getInstance()->getComponentBaseDirs($config['option']);
  2588.  
  2589.         // Get the base paths where the view class files are expected to live
  2590.         $basePaths array(
  2591.             $componentPaths['main'],
  2592.             $componentPaths['alt']
  2593.         );
  2594.         $basePaths array_merge($this->paths['view']);
  2595.  
  2596.         // Get the alternate (singular/plural) view name
  2597.         $altViewName FOFInflector::isPlural($viewNameFOFInflector::singularize($viewNameFOFInflector::pluralize($viewName);
  2598.  
  2599.         $suffixes array(
  2600.             $viewName,
  2601.             $altViewName,
  2602.             'default'
  2603.         );
  2604.         JLoader::import('joomla.filesystem.path');
  2605.  
  2606.         foreach ($suffixes as $suffix)
  2607.         {
  2608.             // Build the view class name
  2609.             $viewClass $classPrefix ucfirst($suffix);
  2610.  
  2611.             if (class_exists($viewClass))
  2612.             {
  2613.                 // The class is already loaded
  2614.                 break;
  2615.             }
  2616.  
  2617.             // The class is not loaded. Let's load it!
  2618.             $viewPath $this->createFileName('view'array('name'     => $suffix'type'     => $viewType));
  2619.             $path JPath::find($basePaths$viewPath);
  2620.  
  2621.             if ($path)
  2622.             {
  2623.                 require_once $path;
  2624.             }
  2625.  
  2626.             if (class_exists($viewClass))
  2627.             {
  2628.                 // The class was loaded successfully
  2629.                 break;
  2630.             }
  2631.         }
  2632.  
  2633.         if (!class_exists($viewClass))
  2634.         {
  2635.             $viewClass 'FOFView' ucfirst($type);
  2636.         }
  2637.  
  2638.         $templateOverridePath FOFPlatform::getInstance()->getTemplateOverridePath($config['option']);
  2639.  
  2640.         // Setup View configuration options
  2641.  
  2642.         if (!array_key_exists('template_path'$config))
  2643.         {
  2644.             $config['template_path'][$componentPaths['main''/views/' FOFInflector::pluralize($config['view']'/tmpl';
  2645.  
  2646.             if ($templateOverridePath)
  2647.             {
  2648.                 $config['template_path'][$templateOverridePath '/' FOFInflector::pluralize($config['view']);
  2649.             }
  2650.  
  2651.             $config['template_path'][$componentPaths['main''/views/' FOFInflector::singularize($config['view']'/tmpl';
  2652.  
  2653.             if ($templateOverridePath)
  2654.             {
  2655.                 $config['template_path'][$templateOverridePath '/' FOFInflector::singularize($config['view']);
  2656.             }
  2657.  
  2658.             $config['template_path'][$componentPaths['main''/views/' $config['view''/tmpl';
  2659.  
  2660.             if ($templateOverridePath)
  2661.             {
  2662.                 $config['template_path'][$templateOverridePath '/' $config['view'];
  2663.             }
  2664.         }
  2665.  
  2666.         $extraTemplatePath $this->configProvider->get($config['option''.views.' $config['view''.config.template_path'null);
  2667.  
  2668.         if ($extraTemplatePath)
  2669.         {
  2670.             array_unshift($config['template_path']$componentPaths['main''/' $extraTemplatePath);
  2671.         }
  2672.  
  2673.         if (!array_key_exists('helper_path'$config))
  2674.         {
  2675.             $config['helper_path'array(
  2676.                 $componentPaths['main''/helpers',
  2677.                 $componentPaths['admin''/helpers'
  2678.             );
  2679.         }
  2680.  
  2681.         $extraHelperPath $this->configProvider->get($config['option''.views.' $config['view''.config.helper_path'null);
  2682.  
  2683.         if ($extraHelperPath)
  2684.         {
  2685.             $config['helper_path'][$componentPaths['main''/' $extraHelperPath;
  2686.         }
  2687.  
  2688.         // Set the use_hypermedia flag in $config if it's not already set
  2689.  
  2690.         if (!isset($config['use_hypermedia']))
  2691.         {
  2692.             $config['use_hypermedia'$this->configProvider->get($config['option''.views.' $config['view''.config.use_hypermedia'false);
  2693.         }
  2694.  
  2695.         $result new $viewClass($config);
  2696.  
  2697.         return $result;
  2698.     }
  2699.  
  2700.     /**
  2701.      * Deprecated function to create a View object instance
  2702.      *
  2703.      * @param   string  $name    The name of the view, e.g. 'Items'
  2704.      * @param   string  $prefix  The prefix of the view, e.g. 'FoobarView'
  2705.      * @param   string  $type    The view type, e.g. 'html'
  2706.      * @param   array   $config  The configuration array for the view
  2707.      *
  2708.      * @return  FOFView 
  2709.      *
  2710.      * @see FOFController::createView
  2711.      *
  2712.      * @deprecated since version 2.0
  2713.      */
  2714.     protected function &_createView($name$prefix ''$type ''$config array())
  2715.     {
  2716.         JLog::add(__METHOD__ . ' is deprecated. Use createView() instead.'JLog::WARNING'deprecated');
  2717.  
  2718.         return $this->createView($name$prefix$type$config);
  2719.     }
  2720.  
  2721.     /**
  2722.      * Set the name of the view to be used by this Controller
  2723.      *
  2724.      * @param   string  $viewName  The name of the view
  2725.      *
  2726.      * @return  void 
  2727.      */
  2728.     public function setThisViewName($viewName)
  2729.     {
  2730.         $this->viewName $viewName;
  2731.     }
  2732.  
  2733.     /**
  2734.      * Set the name of the model to be used by this Controller
  2735.      *
  2736.      * @param   string  $modelName  The name of the model
  2737.      *
  2738.      * @return  void 
  2739.      */
  2740.     public function setThisModelName($modelName)
  2741.     {
  2742.         $this->modelName $modelName;
  2743.     }
  2744.  
  2745.     /**
  2746.      * Checks if the current user has enough privileges for the requested ACL
  2747.      * area.
  2748.      *
  2749.      * @param   string  $area  The ACL area, e.g. core.manage.
  2750.      *
  2751.      * @return  boolean  True if the user has the ACL privilege specified
  2752.      */
  2753.     protected function checkACL($area)
  2754.     {
  2755.         if (in_array(strtolower($area)array('false','0','no','403')))
  2756.         {
  2757.             return false;
  2758.         }
  2759.  
  2760.         if (in_array(strtolower($area)array('true','1','yes')))
  2761.         {
  2762.             return true;
  2763.         }
  2764.         elseif (empty($area))
  2765.         {
  2766.             return true;
  2767.         }
  2768.         else
  2769.         {
  2770.             // Check if we're dealing with ids
  2771.             $ids null;
  2772.  
  2773.             // First, check if there is an asset for this record
  2774.             $table $this->getThisModel()->getTable();
  2775.  
  2776.             if ($table && $table->isAssetsTracked())
  2777.             {
  2778.                 $ids $this->getThisModel()->getId($this->getThisModel()->getId(null;
  2779.             }
  2780.  
  2781.             // Generic or Asset tracking
  2782.  
  2783.             if (empty($ids))
  2784.             {
  2785.                 return FOFPlatform::getInstance()->authorise($area$this->component);
  2786.             }
  2787.             else
  2788.             {
  2789.                 if (!is_array($ids))
  2790.                 {
  2791.                     $ids array($ids);
  2792.                 }
  2793.  
  2794.                 $resource FOFInflector::singularize($this->view);
  2795.  
  2796.                 foreach ($ids as $id)
  2797.                 {
  2798.                     $asset $this->component '.' $resource '.' $id;
  2799.  
  2800.                     // Dedicated permission found, check it!
  2801.  
  2802.                     if (FOFPlatform::getInstance()->authorise($area$asset) )
  2803.                     {
  2804.                         return true;
  2805.                     }
  2806.  
  2807.                     // Fallback on edit.own. First test if the permission is available.
  2808.  
  2809.                     if (FOFPlatform::getInstance()->authorise('core.edit.own'$asset))
  2810.                     {
  2811.                         $table $this->getThisModel()->getTable();
  2812.  
  2813.                         if ($table && isset($table->created_by))
  2814.                         {
  2815.                             // Now test the owner is the user.
  2816.                             $owner_id = (int) $table->created_by;
  2817.  
  2818.                             // If the owner matches 'me' then do the test.
  2819.                             if ($owner_id == FOFPlatform::getInstance()->getUser()->id)
  2820.                             {
  2821.                                 return true;
  2822.                             }
  2823.                             else
  2824.                             {
  2825.                                 return false;
  2826.                             }
  2827.                         }
  2828.                         else
  2829.                         {
  2830.                             return false;
  2831.                         }
  2832.                     }
  2833.                 }
  2834.             }
  2835.         }
  2836.     }
  2837.  
  2838.     /**
  2839.      * A catch-all method for all tasks without a corresponding onBefore
  2840.      * method. Applies the ACL preferences defined in fof.xml.
  2841.      *
  2842.      * @param   string  $task  The task being executed
  2843.      *
  2844.      * @return  boolean  True to allow execution of the task
  2845.      */
  2846.     protected function onBeforeGenericTask($task)
  2847.     {
  2848.         $privilege $this->configProvider->get(
  2849.             $this->component '.views.' .
  2850.             FOFInflector::singularize($this->view'.acl.' $task''
  2851.         );
  2852.  
  2853.         return $this->checkACL($privilege);
  2854.     }
  2855.  
  2856.     /**
  2857.      * Execute something before applySave is called. Return false to prevent
  2858.      * applySave from executing.
  2859.      *
  2860.      * @param   array  &$data  The data upon which applySave will act
  2861.      *
  2862.      * @return  boolean  True to allow applySave to run
  2863.      */
  2864.     protected function onBeforeApplySave(&$data)
  2865.     {
  2866.         return true;
  2867.     }
  2868.  
  2869.     /**
  2870.      * Execute something after applySave has run.
  2871.      *
  2872.      * @return  boolean  True to allow normal return, false to cause a 403 error
  2873.      */
  2874.     protected function onAfterApplySave()
  2875.     {
  2876.         return true;
  2877.     }
  2878.  
  2879.     /**
  2880.      * ACL check before changing the access level; override to customise
  2881.      *
  2882.      * @return  boolean  True to allow accesspublic() to run
  2883.      */
  2884.     protected function onBeforeAccesspublic()
  2885.     {
  2886.         $privilege $this->configProvider->get(
  2887.             $this->component '.views.' .
  2888.             FOFInflector::singularize($this->view'.acl.accesspublic''core.edit.state');
  2889.  
  2890.         return $this->checkACL($privilege);
  2891.     }
  2892.  
  2893.     /**
  2894.      * ACL check before changing the access level; override to customise
  2895.      *
  2896.      * @return  boolean  True to allow the method to run
  2897.      */
  2898.     protected function onBeforeAccessregistered()
  2899.     {
  2900.         $privilege $this->configProvider->get(
  2901.             $this->component '.views.' .
  2902.             FOFInflector::singularize($this->view'.acl.accessregistered''core.edit.state'
  2903.         );
  2904.  
  2905.         return $this->checkACL($privilege);
  2906.     }
  2907.  
  2908.     /**
  2909.      * ACL check before changing the access level; override to customise
  2910.      *
  2911.      * @return  boolean  True to allow the method to run
  2912.      */
  2913.     protected function onBeforeAccessspecial()
  2914.     {
  2915.         $privilege $this->configProvider->get(
  2916.             $this->component '.views.' .
  2917.             FOFInflector::singularize($this->view'.acl.accessspecial''core.edit.state'
  2918.         );
  2919.  
  2920.         return $this->checkACL($privilege);
  2921.     }
  2922.  
  2923.     /**
  2924.      * ACL check before adding a new record; override to customise
  2925.      *
  2926.      * @return  boolean  True to allow the method to run
  2927.      */
  2928.     protected function onBeforeAdd()
  2929.     {
  2930.         $privilege $this->configProvider->get(
  2931.             $this->component '.views.' .
  2932.             FOFInflector::singularize($this->view'.acl.add''core.create'
  2933.         );
  2934.  
  2935.         return $this->checkACL($privilege);
  2936.     }
  2937.  
  2938.     /**
  2939.      * ACL check before saving a new/modified record; override to customise
  2940.      *
  2941.      * @return  boolean  True to allow the method to run
  2942.      */
  2943.     protected function onBeforeApply()
  2944.     {
  2945.         $privilege $this->configProvider->get(
  2946.             $this->component '.views.' .
  2947.             FOFInflector::singularize($this->view'.acl.apply''core.edit'
  2948.         );
  2949.  
  2950.         return $this->checkACL($privilege);
  2951.     }
  2952.  
  2953.     /**
  2954.      * ACL check before allowing someone to browse
  2955.      *
  2956.      * @return  boolean  True to allow the method to run
  2957.      */
  2958.     protected function onBeforeBrowse()
  2959.     {
  2960.         $defaultPrivilege '';
  2961.  
  2962.         $privilege $this->configProvider->get(
  2963.             $this->component '.views.' .
  2964.             FOFInflector::singularize($this->view'.acl.browse'$defaultPrivilege
  2965.         );
  2966.  
  2967.         return $this->checkACL($privilege);
  2968.     }
  2969.  
  2970.     /**
  2971.      * ACL check before cancelling an edit
  2972.      *
  2973.      * @return  boolean  True to allow the method to run
  2974.      */
  2975.     protected function onBeforeCancel()
  2976.     {
  2977.         $privilege $this->configProvider->get(
  2978.             $this->component '.views.' .
  2979.             FOFInflector::singularize($this->view'.acl.cancel''core.edit'
  2980.         );
  2981.  
  2982.         return $this->checkACL($privilege);
  2983.     }
  2984.  
  2985.     /**
  2986.      * ACL check before editing a record; override to customise
  2987.      *
  2988.      * @return  boolean  True to allow the method to run
  2989.      */
  2990.     protected function onBeforeEdit()
  2991.     {
  2992.         $privilege $this->configProvider->get(
  2993.             $this->component '.views.' .
  2994.             FOFInflector::singularize($this->view'.acl.edit''core.edit'
  2995.         );
  2996.  
  2997.         // Else go with the generic one
  2998.  
  2999.         return $this->checkACL($privilege);
  3000.     }
  3001.  
  3002.     /**
  3003.      * ACL check before changing the ordering of a record; override to customise
  3004.      *
  3005.      * @return  boolean  True to allow the method to run
  3006.      */
  3007.     protected function onBeforeOrderdown()
  3008.     {
  3009.         $privilege $this->configProvider->get(
  3010.             $this->component '.views.' .
  3011.             FOFInflector::singularize($this->view'.acl.orderdown''core.edit.state'
  3012.         );
  3013.  
  3014.         return $this->checkACL($privilege);
  3015.     }
  3016.  
  3017.     /**
  3018.      * ACL check before changing the ordering of a record; override to customise
  3019.      *
  3020.      * @return  boolean  True to allow the method to run
  3021.      */
  3022.     protected function onBeforeOrderup()
  3023.     {
  3024.         $privilege $this->configProvider->get(
  3025.             $this->component '.views.' .
  3026.             FOFInflector::singularize($this->view'.acl.orderup''core.edit.state'
  3027.         );
  3028.  
  3029.         return $this->checkACL($privilege);
  3030.     }
  3031.  
  3032.     /**
  3033.      * ACL check before changing the publish status of a record; override to customise
  3034.      *
  3035.      * @return  boolean  True to allow the method to run
  3036.      */
  3037.     protected function onBeforePublish()
  3038.     {
  3039.         $privilege $this->configProvider->get(
  3040.             $this->component '.views.' .
  3041.             FOFInflector::singularize($this->view'.acl.publish''core.edit.state'
  3042.         );
  3043.  
  3044.         return $this->checkACL($privilege);
  3045.     }
  3046.  
  3047.     /**
  3048.      * ACL check before removing a record; override to customise
  3049.      *
  3050.      * @return  boolean  True to allow the method to run
  3051.      */
  3052.     protected function onBeforeRemove()
  3053.     {
  3054.         $privilege $this->configProvider->get(
  3055.             $this->component '.views.' .
  3056.             FOFInflector::singularize($this->view'.acl.remove''core.delete'
  3057.         );
  3058.  
  3059.         return $this->checkACL($privilege);
  3060.     }
  3061.  
  3062.     /**
  3063.      * ACL check before saving a new/modified record; override to customise
  3064.      *
  3065.      * @return  boolean  True to allow the method to run
  3066.      */
  3067.     protected function onBeforeSave()
  3068.     {
  3069.         $privilege $this->configProvider->get(
  3070.             $this->component '.views.' .
  3071.             FOFInflector::singularize($this->view'.acl.save''core.edit'
  3072.         );
  3073.  
  3074.         return $this->checkACL($privilege);
  3075.     }
  3076.  
  3077.     /**
  3078.      * ACL check before saving a new/modified record; override to customise
  3079.      *
  3080.      * @return  boolean  True to allow the method to run
  3081.      */
  3082.     protected function onBeforeSavenew()
  3083.     {
  3084.         $privilege $this->configProvider->get(
  3085.             $this->component '.views.' .
  3086.             FOFInflector::singularize($this->view'.acl.savenew''core.edit'
  3087.         );
  3088.  
  3089.         return $this->checkACL($privilege);
  3090.     }
  3091.  
  3092.     /**
  3093.      * ACL check before changing the ordering of a record; override to customise
  3094.      *
  3095.      * @return  boolean  True to allow the method to run
  3096.      */
  3097.     protected function onBeforeSaveorder()
  3098.     {
  3099.         $privilege $this->configProvider->get(
  3100.             $this->component '.views.' .
  3101.             FOFInflector::singularize($this->view'.acl.saveorder''core.edit.state'
  3102.         );
  3103.  
  3104.         return $this->checkACL($privilege);
  3105.     }
  3106.  
  3107.     /**
  3108.      * ACL check before changing the publish status of a record; override to customise
  3109.      *
  3110.      * @return  boolean  True to allow the method to run
  3111.      */
  3112.     protected function onBeforeUnpublish()
  3113.     {
  3114.         $privilege $this->configProvider->get(
  3115.             $this->component '.views.' .
  3116.             FOFInflector::singularize($this->view'.acl.unpublish''core.edit.state'
  3117.         );
  3118.  
  3119.         return $this->checkACL($privilege);
  3120.     }
  3121.  
  3122.     /**
  3123.      * Applies CSRF protection by means of a standard Joomla! token (nonce) check.
  3124.      * Raises a 403 Access Forbidden error through JError or an exception
  3125.      * (depending the Joomla! version) if the check fails.
  3126.      *
  3127.      * @return  boolean  True if the CSRF check is successful
  3128.      */
  3129.     protected function _csrfProtection()
  3130.     {
  3131.         static $isCli null$isAdmin null;
  3132.  
  3133.         if (is_null($isCli))
  3134.         {
  3135.             $isCli FOFPlatform::getInstance()->isCli();
  3136.             $iAdmin FOFPlatform::getInstance()->isBackend();
  3137.         }
  3138.  
  3139.         switch ($this->csrfProtection)
  3140.         {
  3141.             // Never
  3142.             case 0:
  3143.                 return true;
  3144.                 break;
  3145.  
  3146.             // Always
  3147.             case 1:
  3148.                 break;
  3149.  
  3150.             // Only back-end and HTML format
  3151.             case 2:
  3152.                 if ($isCli)
  3153.                 {
  3154.                     return true;
  3155.                 }
  3156.                 elseif (!$isAdmin && ($this->input->get('format''html''cmd'!= 'html'))
  3157.                 {
  3158.                     return true;
  3159.                 }
  3160.                 break;
  3161.  
  3162.             // Only back-end
  3163.             case 3:
  3164.                 if (!$isAdmin)
  3165.                 {
  3166.                     return true;
  3167.                 }
  3168.                 break;
  3169.         }
  3170.  
  3171.         $hasToken false;
  3172.         $session JFactory::getSession();
  3173.  
  3174.         // Joomla! 1.5/1.6/1.7/2.5 (classic Joomla! API) method
  3175.  
  3176.         if (method_exists('JUtility''getToken'))
  3177.         {
  3178.             $token JUtility::getToken();
  3179.             $hasToken $this->input->get($tokenfalse'none'== 1;
  3180.  
  3181.             if (!$hasToken)
  3182.             {
  3183.                 $hasToken $this->input->get('_token'null'none'== $token;
  3184.             }
  3185.         }
  3186.  
  3187.         // Joomla! 2.5+ (Platform 12.1+) method
  3188.  
  3189.         if (!$hasToken)
  3190.         {
  3191.             if (method_exists($session'getToken'))
  3192.             {
  3193.                 $token $session->getToken();
  3194.                 $hasToken $this->input->get($tokenfalse'none'== 1;
  3195.  
  3196.                 if (!$hasToken)
  3197.                 {
  3198.                     $hasToken $this->input->get('_token'null'none'== $token;
  3199.                 }
  3200.             }
  3201.         }
  3202.  
  3203.         // Joomla! 2.5+ formToken method
  3204.  
  3205.         if (!$hasToken)
  3206.         {
  3207.             if (method_exists($session'getFormToken'))
  3208.             {
  3209.                 $token $session->getFormToken();
  3210.                 $hasToken $this->input->get($tokenfalse'none'== 1;
  3211.  
  3212.                 if (!$hasToken)
  3213.                 {
  3214.                     $hasToken $this->input->get('_token'null'none'== $token;
  3215.                 }
  3216.             }
  3217.         }
  3218.  
  3219.         if (!$hasToken)
  3220.         {
  3221.             if (FOFPlatform::getInstance()->checkVersion(JVERSION'3.0''ge'))
  3222.             {
  3223.                 throw new Exception(JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN')403);
  3224.             }
  3225.             else
  3226.             {
  3227.                 JError::raiseError('403'JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'));
  3228.             }
  3229.  
  3230.             return false;
  3231.         }
  3232.     }
  3233. }

Documentation generated on Tue, 19 Nov 2013 14:57:21 +0100 by phpDocumentor 1.4.3