Source for file form.php

Documentation is available at form.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Site
  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. // Base this model on the backend version.
  13. require_once JPATH_ADMINISTRATOR.'/components/com_content/models/article.php';
  14.  
  15. /**
  16.  * Content Component Article Model
  17.  *
  18.  * @package     Joomla.Site
  19.  * @subpackage  com_content
  20.  * @since       1.5
  21.  */
  22. {
  23.     /**
  24.      * Model typeAlias string. Used for version history.
  25.      *
  26.      * @var        string 
  27.      */
  28.     public $typeAlias = 'com_content.article';
  29.  
  30.     /**
  31.      * Method to auto-populate the model state.
  32.      *
  33.      * Note. Calling getState in this method will result in recursion.
  34.      *
  35.      * @return  void 
  36.      *
  37.      * @since   1.6
  38.      */
  39.     protected function populateState()
  40.     {
  41.         $app JFactory::getApplication();
  42.  
  43.         // Load state from the request.
  44.         $pk $app->input->getInt('a_id');
  45.         $this->setState('article.id'$pk);
  46.  
  47.         $this->setState('article.catid'$app->input->getInt('catid'));
  48.  
  49.         $return $app->input->get('return'null'base64');
  50.         $this->setState('return_page'base64_decode($return));
  51.  
  52.         // Load the parameters.
  53.         $params    $app->getParams();
  54.         $this->setState('params'$params);
  55.  
  56.         $this->setState('layout'$app->input->get('layout'));
  57.     }
  58.  
  59.     /**
  60.      * Method to get article data.
  61.      *
  62.      * @param   integer  $itemId  The id of the article.
  63.      *
  64.      * @return  mixed  Content item data object on success, false on failure.
  65.      */
  66.     public function getItem($itemId null)
  67.     {
  68.         $itemId = (int) (!empty($itemId)) $itemId $this->getState('article.id');
  69.  
  70.         // Get a row instance.
  71.         $table $this->getTable();
  72.  
  73.         // Attempt to load the row.
  74.         $return $table->load($itemId);
  75.  
  76.         // Check for a table object error.
  77.         if ($return === false && $table->getError())
  78.         {
  79.             $this->setError($table->getError());
  80.  
  81.             return false;
  82.         }
  83.  
  84.         $properties $table->getProperties(1);
  85.         $value JArrayHelper::toObject($properties'JObject');
  86.  
  87.         // Convert attrib field to Registry.
  88.         $value->params new JRegistry;
  89.         $value->params->loadString($value->attribs);
  90.  
  91.         // Compute selected asset permissions.
  92.         $user    JFactory::getUser();
  93.         $userId    $user->get('id');
  94.         $asset    'com_content.article.' $value->id;
  95.  
  96.         // Check general edit permission first.
  97.         if ($user->authorise('core.edit'$asset))
  98.         {
  99.             $value->params->set('access-edit'true);
  100.         }
  101.  
  102.         // Now check if edit.own is available.
  103.         elseif (!empty($userId&& $user->authorise('core.edit.own'$asset))
  104.         {
  105.             // Check for a valid user and that they are the owner.
  106.             if ($userId == $value->created_by)
  107.             {
  108.                 $value->params->set('access-edit'true);
  109.             }
  110.         }
  111.  
  112.         // Check edit state permission.
  113.         if ($itemId)
  114.         {
  115.             // Existing item
  116.             $value->params->set('access-change'$user->authorise('core.edit.state'$asset));
  117.         }
  118.         else
  119.         {
  120.             // New item.
  121.             $catId = (int) $this->getState('article.catid');
  122.  
  123.             if ($catId)
  124.             {
  125.                 $value->params->set('access-change'$user->authorise('core.edit.state''com_content.category.' $catId));
  126.                 $value->catid $catId;
  127.             }
  128.             else
  129.             {
  130.                 $value->params->set('access-change'$user->authorise('core.edit.state''com_content'));
  131.             }
  132.         }
  133.  
  134.         $value->articletext $value->introtext;
  135.  
  136.         if (!empty($value->fulltext))
  137.         {
  138.             $value->articletext .= '<hr id="system-readmore" />' $value->fulltext;
  139.         }
  140.  
  141.         // Convert the metadata field to an array.
  142.         $registry new JRegistry;
  143.         $registry->loadString($value->metadata);
  144.         $value->metadata $registry->toArray();
  145.  
  146.         if ($itemId)
  147.         {
  148.             $value->tags new JHelperTags;
  149.             $value->tags->getTagIds($value->id'com_content.article');
  150.             $value->metadata['tags'$value->tags;
  151.         }
  152.  
  153.         return $value;
  154.     }
  155.  
  156.     /**
  157.      * Get the return URL.
  158.      *
  159.      * @return  string    The return URL.
  160.      *
  161.      * @since   1.6
  162.      */
  163.     public function getReturnPage()
  164.     {
  165.         return base64_encode($this->getState('return_page'));
  166.     }
  167.  
  168.     /**
  169.      * Method to save the form data.
  170.      *
  171.      * @param   array  $data  The form data.
  172.      *
  173.      * @return  boolean  True on success.
  174.      *
  175.      * @since   3.2
  176.      */
  177.     public function save($data)
  178.     {
  179.         // Associations are not edited in frontend ATM so we have to inherit them
  180.         if (JLanguageAssociations::isEnabled(&& !empty($data['id']))
  181.         {
  182.             if ($associations JLanguageAssociations::getAssociations('com_content''#__content''com_content.item'$data['id']))
  183.             {
  184.                 foreach ($associations as $tag => $associated)
  185.                 {
  186.                     $associations[$tag= (int) $associated->id;
  187.                 }
  188.  
  189.                 $data['associations'$associations;
  190.             }
  191.         }
  192.  
  193.         return parent::save($data);
  194.     }
  195. }

Documentation generated on Tue, 19 Nov 2013 15:03:41 +0100 by phpDocumentor 1.4.3