Source for file cms.php

Documentation is available at cms.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Site
  4.  * @subpackage  com_config
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Prototype admin model.
  14.  *
  15.  * @package     Joomla.Site
  16.  * @subpackage  com_config
  17.  * @since       3.2
  18.  */
  19. abstract class ConfigModelCms extends JModelDatabase
  20. {
  21.     /**
  22.      * The model (base) name
  23.      *
  24.      * @var    string 
  25.      * @since  3.2
  26.      */
  27.     protected $name;
  28.  
  29.     /**
  30.      * The URL option for the component.
  31.      *
  32.      * @var    string 
  33.      * @since  3.2
  34.      */
  35.     protected $option = null;
  36.  
  37.     /**
  38.      * The prefix to use with controller messages.
  39.      *
  40.      * @var    string 
  41.      * @since  3.2
  42.      */
  43.     protected $text_prefix = null;
  44.  
  45.     /**
  46.      * Indicates if the internal state has been set
  47.      *
  48.      * @var    boolean 
  49.      * @since  3.2
  50.      */
  51.     protected $__state_set = null;
  52.  
  53.     /**
  54.      * Constructor
  55.      *
  56.      * @param   array  $config  An array of configuration options (name, state, dbo, table_path, ignore_request).
  57.      *
  58.      * @since   3.2
  59.      * @throws  Exception
  60.      */
  61.     public function __construct($config array())
  62.     {
  63.         // Guess the option from the class name (Option)Model(View).
  64.         if (empty($this->option))
  65.         {
  66.             $r null;
  67.  
  68.             if (!preg_match('/(.*)Model/i'get_class($this)$r))
  69.             {
  70.                 throw new Exception(JText::_('JLIB_APPLICATION_ERROR_MODEL_GET_NAME')500);
  71.             }
  72.  
  73.             $this->option = 'com_' strtolower($r[1]);
  74.         }
  75.  
  76.         // Set the view name
  77.         if (empty($this->name))
  78.         {
  79.             if (array_key_exists('name'$config))
  80.             {
  81.                 $this->name = $config['name'];
  82.             }
  83.             else
  84.             {
  85.                 $this->name = $this->getName();
  86.             }
  87.         }
  88.  
  89.         // Set the model state
  90.         if (array_key_exists('state'$config))
  91.         {
  92.             $this->state = $config['state'];
  93.         }
  94.         else
  95.         {
  96.             $this->state = new JRegistry;
  97.         }
  98.  
  99.         // Set the model dbo
  100.         if (array_key_exists('dbo'$config))
  101.         {
  102.             $this->db = $config['dbo'];
  103.         }
  104.  
  105.         // Register the paths for the form
  106.         $paths $this->registerTablePaths($config);
  107.  
  108.         // Set the internal state marker - used to ignore setting state from the request
  109.         if (!empty($config['ignore_request']))
  110.         {
  111.             $this->__state_set = true;
  112.         }
  113.  
  114.         // Set the clean cache event
  115.         if (isset($config['event_clean_cache']))
  116.         {
  117.             $this->event_clean_cache $config['event_clean_cache'];
  118.         }
  119.         elseif (empty($this->event_clean_cache))
  120.         {
  121.             $this->event_clean_cache 'onContentCleanCache';
  122.         }
  123.  
  124.         $state new JRegistry($config);
  125.  
  126.         parent::__construct($state);
  127.     }
  128.  
  129.     /**
  130.      * Method to get the model name
  131.      *
  132.      * The model name. By default parsed using the classname or it can be set
  133.      * by passing a $config['name'] in the class constructor
  134.      *
  135.      * @return  string  The name of the model
  136.      *
  137.      * @since   3.2
  138.      * @throws  Exception
  139.      */
  140.     public function getName()
  141.     {
  142.         if (empty($this->name))
  143.         {
  144.             $r null;
  145.  
  146.             if (!preg_match('/Model(.*)/i'get_class($this)$r))
  147.             {
  148.                 throw new Exception(JText::_('JLIB_APPLICATION_ERROR_MODEL_GET_NAME')500);
  149.             }
  150.  
  151.             $this->name = strtolower($r[1]);
  152.         }
  153.  
  154.         return $this->name;
  155.     }
  156.  
  157.     /**
  158.      * Method to get model state variables
  159.      *
  160.      * @return  object  The property where specified, the state object where omitted
  161.      *
  162.      * @since   3.2
  163.      */
  164.     public function getState()
  165.     {
  166.         if (!$this->__state_set)
  167.         {
  168.             // Protected method to auto-populate the model state.
  169.             $this->populateState();
  170.  
  171.             // Set the model state set flag to true.
  172.             $this->__state_set = true;
  173.         }
  174.  
  175.         return $this->state;
  176.     }
  177.  
  178.     /**
  179.      * Method to register paths for tables
  180.      *
  181.      * @param   array  $config  Configuration array
  182.      *
  183.      * @return  object  The property where specified, the state object where omitted
  184.      *
  185.      * @since   3.2
  186.      */
  187.     public function registerTablePaths($config array())
  188.     {
  189.         // Set the default view search path
  190.         if (array_key_exists('table_path'$config))
  191.         {
  192.             $this->addTablePath($config['table_path']);
  193.         }
  194.         elseif (defined('JPATH_COMPONENT_ADMINISTRATOR'))
  195.         {
  196.             // Register the paths for the form
  197.             $paths new SplPriorityQueue;
  198.             $paths->insert(JPATH_COMPONENT_ADMINISTRATOR '/table''normal');
  199.  
  200.             // For legacy purposes. Remove for 4.0
  201.             $paths->insert(JPATH_COMPONENT_ADMINISTRATOR '/tables''normal');
  202.         }
  203.     }
  204.  
  205.     /**
  206.      * Clean the cache
  207.      *
  208.      * @param   string   $group      The cache group
  209.      * @param   integer  $client_id  The ID of the client
  210.      *
  211.      * @return  void 
  212.      *
  213.      * @since   3.2
  214.      */
  215.     protected function cleanCache($group null$client_id 0)
  216.     {
  217.         $conf JFactory::getConfig();
  218.         $dispatcher JEventDispatcher::getInstance();
  219.  
  220.         $options array(
  221.             'defaultgroup' => ($group$group (isset($this->option$this->option : JFactory::getApplication()->input->get('option')),
  222.             'cachebase' => ($client_idJPATH_ADMINISTRATOR '/cache' $conf->get('cache_path'JPATH_SITE '/cache'));
  223.  
  224.         $cache JCache::getInstance('callback'$options);
  225.         $cache->clean();
  226.  
  227.         // Trigger the onContentCleanCache event.
  228.         $dispatcher->trigger($this->event_clean_cache$options);
  229.     }
  230.  
  231.     /**
  232.      * Method to auto-populate the model state.
  233.      *
  234.      * This method should only be called once per instantiation and is designed
  235.      * to be called on the first call to the getState() method unless the model
  236.      * configuration flag to ignore the request is set.
  237.      *
  238.      * @return  void 
  239.      *
  240.      * @note    Calling getState in this method will result in recursion.
  241.      * @since   3.2
  242.      */
  243.     protected function populateState()
  244.     {
  245.         $this->loadState();
  246.     }
  247.  
  248.     /**
  249.      * Method to test whether a record can be deleted.
  250.      *
  251.      * @param   object  $record  A record object.
  252.      *
  253.      * @return  boolean  True if allowed to delete the record. Defaults to the permission set in the component.
  254.      *
  255.      * @since   3.2
  256.      */
  257.     protected function canDelete($record)
  258.     {
  259.         if (!empty($record->id))
  260.         {
  261.             if ($record->published != -2)
  262.             {
  263.                 return;
  264.             }
  265.  
  266.             $user JFactory::getUser();
  267.  
  268.             return $user->authorise('core.delete'$this->option);
  269.         }
  270.     }
  271.  
  272.     /**
  273.      * Method to test whether a record can have its state changed.
  274.      *
  275.      * @param   object  $record  A record object.
  276.      *
  277.      * @return  boolean  True if allowed to change the state of the record. Defaults to the permission set in the component.
  278.      *
  279.      * @since   3.2
  280.      */
  281.     protected function canEditState($record)
  282.     {
  283.         $user JFactory::getUser();
  284.  
  285.         return $user->authorise('core.edit.state'$this->option);
  286.     }
  287. }

Documentation generated on Tue, 19 Nov 2013 14:56:00 +0100 by phpDocumentor 1.4.3