[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_content/controllers/ -> article.php (source)

   1  <?php
   2  /**
   3   * @package     Joomla.Administrator
   4   * @subpackage  com_content
   5   *
   6   * @copyright   Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   7   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  // No direct access
  11  defined('_JEXEC') or die;
  12  
  13  jimport('joomla.application.component.controllerform');
  14  
  15  /**
  16   * @package     Joomla.Administrator
  17   * @subpackage  com_content
  18   * @since       1.6
  19   */
  20  class ContentControllerArticle extends JControllerForm
  21  {
  22      /**
  23       * Class constructor.
  24       *
  25       * @param   array  $config  A named array of configuration variables.
  26       *
  27       * @since    1.6
  28       */
  29  	function __construct($config = array())
  30      {
  31          // An article edit form can come from the articles or featured view.
  32          // Adjust the redirect view on the value of 'return' in the request.
  33          if (JRequest::getCmd('return') == 'featured')
  34          {
  35              $this->view_list = 'featured';
  36              $this->view_item = 'article&return=featured';
  37          }
  38  
  39          parent::__construct($config);
  40      }
  41  
  42      /**
  43       * Method override to check if you can add a new record.
  44       *
  45       * @param   array  $data  An array of input data.
  46       *
  47       * @return  boolean
  48       *
  49       * @since   1.6
  50       */
  51  	protected function allowAdd($data = array())
  52      {
  53          // Initialise variables.
  54          $user = JFactory::getUser();
  55          $categoryId = JArrayHelper::getValue($data, 'catid', JRequest::getInt('filter_category_id'), 'int');
  56          $allow = null;
  57  
  58          if ($categoryId)
  59          {
  60              // If the category has been passed in the data or URL check it.
  61              $allow = $user->authorise('core.create', 'com_content.category.' . $categoryId);
  62          }
  63  
  64          if ($allow === null)
  65          {
  66              // In the absense of better information, revert to the component permissions.
  67              return parent::allowAdd();
  68          }
  69          else
  70          {
  71              return $allow;
  72          }
  73      }
  74  
  75      /**
  76       * Method override to check if you can edit an existing record.
  77       *
  78       * @param   array   $data  An array of input data.
  79       * @param   string  $key   The name of the key for the primary key.
  80       *
  81       * @return  boolean
  82       *
  83       * @since   1.6
  84       */
  85  	protected function allowEdit($data = array(), $key = 'id')
  86      {
  87          // Initialise variables.
  88          $recordId = (int) isset($data[$key]) ? $data[$key] : 0;
  89          $user = JFactory::getUser();
  90          $userId = $user->get('id');
  91  
  92          // Check general edit permission first.
  93          if ($user->authorise('core.edit', 'com_content.article.' . $recordId))
  94          {
  95              return true;
  96          }
  97  
  98          // Fallback on edit.own.
  99          // First test if the permission is available.
 100          if ($user->authorise('core.edit.own', 'com_content.article.' . $recordId))
 101          {
 102              // Now test the owner is the user.
 103              $ownerId = (int) isset($data['created_by']) ? $data['created_by'] : 0;
 104              if (empty($ownerId) && $recordId)
 105              {
 106                  // Need to do a lookup from the model.
 107                  $record = $this->getModel()->getItem($recordId);
 108  
 109                  if (empty($record))
 110                  {
 111                      return false;
 112                  }
 113  
 114                  $ownerId = $record->created_by;
 115              }
 116  
 117              // If the owner matches 'me' then do the test.
 118              if ($ownerId == $userId)
 119              {
 120                  return true;
 121              }
 122          }
 123  
 124          // Since there is no asset tracking, revert to the component permissions.
 125          return parent::allowEdit($data, $key);
 126      }
 127  
 128      /**
 129       * Method to run batch operations.
 130       *
 131       * @param   object  $model  The model.
 132       *
 133       * @return  boolean     True if successful, false otherwise and internal error is set.
 134       *
 135       * @since   1.6
 136       */
 137  	public function batch($model = null)
 138      {
 139          JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
 140  
 141          // Set the model
 142          $model = $this->getModel('Article', '', array());
 143  
 144          // Preset the redirect
 145          $this->setRedirect(JRoute::_('index.php?option=com_content&view=articles' . $this->getRedirectToListAppend(), false));
 146  
 147          return parent::batch($model);
 148      }
 149  }


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1