- md5
- 0a71a860ad3734ba9fb213f13bfd4f29
- sha1
- a95ce560ec673d84df94c536204de2d69061b241
- sha256
- fc5178beb42e1964d5164112629a54a4a973d15d86bc6ffc22a09e5c81dada26
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
<?php
/**
* @package Joomla.Administrator
* @subpackage com_content
*
* @copyright (C) 2008 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Content\Administrator\View\Article;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\ContentHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\FormView;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\Component\Content\Administrator\Service\PreviewTokenService;
use Joomla\Component\Content\Site\Helper\RouteHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* View to edit an article.
*
* @since 1.6
*/
class HtmlView extends FormView
{
/**
* Pagebreak TOC alias
*
* @var string
*/
protected $eName;
/**
* Set to true, if saving to menu should be supported
*
* @var boolean
*/
protected $supportSaveMenu = true;
/**
* Holds the extension for categories, if available
*
* @var string
*/
protected $categorySection = 'com_content';
/**
* Constructor
*
* @param array $config An optional associative array of configuration settings.
*
* @since 6.0.0
*/
public function __construct(array $config)
{
if (empty($config['option'])) {
$config['option'] = 'com_content';
}
$config['help_link'] = 'Articles:_Edit';
$config['toolbar_icon'] = 'pencil-alt article-add';
parent::__construct($config);
}
/**
* Prepare view data
*
* @return void
*
* @since 6.0.0
*/
protected function initializeView()
{
if ($this->getLayout() == 'pagebreak') {
return;
}
parent::initializeView();
$this->canDo = ContentHelper::getActions('com_content', 'article', $this->item->id);
$url = RouteHelper::getArticleRoute($this->item->id . ':' . $this->item->alias, $this->item->catid, $this->item->language);
// Generate preview token if editing an existing article
if ($this->item->id > 0) {
$params = ComponentHelper::getParams('com_content');
$expiration = (int) $params->get('preview_token_expiration', 15);
$tokenHelper = new PreviewTokenService(Factory::getApplication()->get('secret'));
$token = $tokenHelper->createToken((int) $this->item->id, $expiration);
// Append token using proper URL query parameter handling
$url .= (!str_contains($url, '?') ? '?' : '&') . 'preview_token=' . $token;
}
$this->previewLink = $url;
$this->jooa11yLink = $url . '&jooa11y=1';
if ($this->getLayout() === 'modalreturn') {
return;
}
$input = Factory::getApplication()->getInput();
$forcedLanguage = $input->get('forcedLanguage', '', 'cmd');
// If we are forcing a language in modal (used for associations).
if ($this->getLayout() === 'modal' && $forcedLanguage) {
// Set the language field to the forcedLanguage and disable changing it.
$this->form->setValue('language', null, $forcedLanguage);
$this->form->setFieldAttribute('language', 'readonly', 'true');
// Only allow to select categories with All language or with the forced language.
$this->form->setFieldAttribute('catid', 'language', '*,' . $forcedLanguage);
// Only allow to select tags with All language or with the forced language.
$this->form->setFieldAttribute('tags', 'language', '*,' . $forcedLanguage);
}
// Add form control fields
$this->form
->addControlField('task')
->addControlField('return', $input->getBase64('return', ''))
->addControlField('forcedLanguage', $forcedLanguage);
}
/**
* Add the page title and toolbar.
*
* @return void
*
* @since 1.6
*
* @throws \Exception
*/
protected function addToolbar()
{
if ($this->getLayout() === 'pagebreak') {
return;
}
if ($this->getLayout() === 'modal') {
$this->addModalToolbar();
return;
}
$user = $this->getCurrentUser();
$userId = $user->id;
$isNew = ($this->item->id == 0);
$checkedOut = !(\is_null($this->item->checked_out) || $this->item->checked_out == $userId);
$this->toolbarTitle = Text::_('COM_CONTENT_PAGE_' . ($checkedOut ? 'VIEW_ARTICLE' : ($isNew ? 'ADD_ARTICLE' : 'EDIT_ARTICLE')));
parent::addToolbar();
}
/**
* Add the modal toolbar.
*
* @return void
*
* @since 5.0.0
*
* @throws \Exception
*/
protected function addModalToolbar()
{
$user = $this->getCurrentUser();
$userId = $user->id;
$isNew = ($this->item->id == 0);
$checkedOut = !(\is_null($this->item->checked_out) || $this->item->checked_out == $userId);
$toolbar = $this->getDocument()->getToolbar();
// Build the actions for new and existing records.
$canDo = $this->canDo;
ToolbarHelper::title(
Text::_('COM_CONTENT_PAGE_' . ($checkedOut ? 'VIEW_ARTICLE' : ($isNew ? 'ADD_ARTICLE' : 'EDIT_ARTICLE'))),
'pencil-alt article-add'
);
$canCreate = $isNew && (\count($user->getAuthorisedCategories('com_content', 'core.create')) > 0);
$canEdit = $canDo->get('core.edit') || ($canDo->get('core.edit.own') && $this->item->created_by == $userId);
// For new records, check the create permission.
if ($canCreate || $canEdit) {
$toolbar->apply('article.apply');
$toolbar->save('article.save');
}
$toolbar->cancel('article.cancel');
}
}
No other release has this exact content. See every version of this file.