* @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\Registry\Registry; use Joomla\Utilities\ArrayHelper; // Base this model on the backend version. JLoader::register('ContentModelArticle', JPATH_ADMINISTRATOR . '/components/com_content/models/article.php'); /** * Content Component Article Model * * @since 1.5 */ class ContentModelForm extends ContentModelArticle { /** * Model typeAlias string. Used for version history. * * @var string */ public $typeAlias = 'com_content.article'; /** * Method to auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @return void * * @since 1.6 */ protected function populateState() { $app = JFactory::getApplication(); // Load the parameters. $params = $app->getParams(); $this->setState('params', $params); if ($params && $params->get('enable_category') == 1 && $params->get('catid')) { $catId = $params->get('catid'); } else { $catId = 0; } // Load state from the request. $pk = $app->input->getInt('a_id'); $this->setState('article.id', $pk); $this->setState('article.catid', $app->input->getInt('catid', $catId)); $return = $app->input->get('return', null, 'base64'); $this->setState('return_page', base64_decode($return)); $this->setState('layout', $app->input->getString('layout')); } /** * Method to get article data. * * @param integer $itemId The id of the article. * * @return mixed Content item data object on success, false on failure. */ public function getItem($itemId = null) { $itemId = (int) (!empty($itemId)) ? $itemId : $this->getState('article.id'); // Get a row instance. $table = $this->getTable(); // Attempt to load the row. $return = $table->load($itemId); // Check for a table object error. if ($return === false && $table->getError()) { $this->setError($table->getError()); return false; } $properties = $table->getProperties(1); $value = ArrayHelper::toObject($properties, 'JObject'); // Convert attrib field to Registry. $value->params = new Registry($value->attribs); // Compute selected asset permissions. $user = JFactory::getUser(); $userId = $user->get('id'); $asset = 'com_content.article.' . $value->id; // Check general edit permission first. if ($user->authorise('core.edit', $asset)) { $value->params->set('access-edit', true); } // Now check if edit.own is available. elseif (!empty($userId) && $user->authorise('core.edit.own', $asset)) { // Check for a valid user and that they are the owner. if ($userId == $value->created_by) { $value->params->set('access-edit', true); } } // Check edit state permission. if ($itemId) { // Existing item $value->params->set('access-change', $user->authorise('core.edit.state', $asset)); } else { // New item. $catId = (int) $this->getState('article.catid'); if ($catId) { $value->params->set('access-change', $user->authorise('core.edit.state', 'com_content.category.' . $catId)); $value->catid = $catId; } else { $value->params->set('access-change', $user->authorise('core.edit.state', 'com_content')); } } $value->articletext = $value->introtext; if (!empty($value->fulltext)) { $value->articletext .= '