Source for file article.php

Documentation is available at article.php

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

Documentation generated on Tue, 19 Nov 2013 14:53:55 +0100 by phpDocumentor 1.4.3