primo commit
This commit is contained in:
428
components/com_content/src/Controller/ArticleController.php
Normal file
428
components/com_content/src/Controller/ArticleController.php
Normal file
@ -0,0 +1,428 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Content\Site\Controller;
|
||||
|
||||
use Joomla\CMS\Application\SiteApplication;
|
||||
use Joomla\CMS\Language\Multilanguage;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Controller\FormController;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
use Joomla\CMS\Versioning\VersionableControllerTrait;
|
||||
use Joomla\Utilities\ArrayHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Content article class.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*/
|
||||
class ArticleController extends FormController
|
||||
{
|
||||
use VersionableControllerTrait;
|
||||
|
||||
/**
|
||||
* The URL view item variable.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $view_item = 'form';
|
||||
|
||||
/**
|
||||
* The URL view list variable.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $view_list = 'categories';
|
||||
|
||||
/**
|
||||
* The URL edit variable.
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2
|
||||
*/
|
||||
protected $urlVar = 'a.id';
|
||||
|
||||
/**
|
||||
* Method to add a new record.
|
||||
*
|
||||
* @return mixed True if the record can be added, an error object if not.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if (!parent::add()) {
|
||||
// Redirect to the return page.
|
||||
$this->setRedirect($this->getReturnPage());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Redirect to the edit screen.
|
||||
$this->setRedirect(
|
||||
Route::_(
|
||||
'index.php?option=' . $this->option . '&view=' . $this->view_item . '&a_id=0'
|
||||
. $this->getRedirectToItemAppend(),
|
||||
false
|
||||
)
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method override to check if you can add a new record.
|
||||
*
|
||||
* @param array $data An array of input data.
|
||||
*
|
||||
* @return boolean
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function allowAdd($data = [])
|
||||
{
|
||||
$user = $this->app->getIdentity();
|
||||
$categoryId = ArrayHelper::getValue($data, 'catid', $this->input->getInt('catid'), 'int');
|
||||
$allow = null;
|
||||
|
||||
if ($categoryId) {
|
||||
// If the category has been passed in the data or URL check it.
|
||||
$allow = $user->authorise('core.create', 'com_content.category.' . $categoryId);
|
||||
}
|
||||
|
||||
if ($allow === null) {
|
||||
// In the absence of better information, revert to the component permissions.
|
||||
return parent::allowAdd();
|
||||
}
|
||||
|
||||
return $allow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method override to check if you can edit an existing record.
|
||||
*
|
||||
* @param array $data An array of input data.
|
||||
* @param string $key The name of the key for the primary key; default is id.
|
||||
*
|
||||
* @return boolean
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function allowEdit($data = [], $key = 'id')
|
||||
{
|
||||
$recordId = (int) isset($data[$key]) ? $data[$key] : 0;
|
||||
$user = $this->app->getIdentity();
|
||||
|
||||
// Zero record (id:0), return component edit permission by calling parent controller method
|
||||
if (!$recordId) {
|
||||
return parent::allowEdit($data, $key);
|
||||
}
|
||||
|
||||
// Check edit on the record asset (explicit or inherited)
|
||||
if ($user->authorise('core.edit', 'com_content.article.' . $recordId)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check edit own on the record asset (explicit or inherited)
|
||||
if ($user->authorise('core.edit.own', 'com_content.article.' . $recordId)) {
|
||||
// Existing record already has an owner, get it
|
||||
$record = $this->getModel()->getItem($recordId);
|
||||
|
||||
if (empty($record)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Grant if current user is owner of the record
|
||||
return $user->id == $record->created_by;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to cancel an edit.
|
||||
*
|
||||
* @param string $key The name of the primary key of the URL variable.
|
||||
*
|
||||
* @return boolean True if access level checks pass, false otherwise.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function cancel($key = 'a_id')
|
||||
{
|
||||
$result = parent::cancel($key);
|
||||
|
||||
/** @var SiteApplication $app */
|
||||
$app = $this->app;
|
||||
|
||||
// Load the parameters.
|
||||
$params = $app->getParams();
|
||||
|
||||
$customCancelRedir = (bool) $params->get('custom_cancel_redirect');
|
||||
|
||||
if ($customCancelRedir) {
|
||||
$cancelMenuitemId = (int) $params->get('cancel_redirect_menuitem');
|
||||
|
||||
if ($cancelMenuitemId > 0) {
|
||||
$item = $app->getMenu()->getItem($cancelMenuitemId);
|
||||
$lang = '';
|
||||
|
||||
if (Multilanguage::isEnabled()) {
|
||||
$lang = !\is_null($item) && $item->language != '*' ? '&lang=' . $item->language : '';
|
||||
}
|
||||
|
||||
// Redirect to the user specified return page.
|
||||
$redirlink = $item->link . $lang . '&Itemid=' . $cancelMenuitemId;
|
||||
} else {
|
||||
// Redirect to the same article submission form (clean form).
|
||||
$redirlink = $app->getMenu()->getActive()->link . '&Itemid=' . $app->getMenu()->getActive()->id;
|
||||
}
|
||||
} else {
|
||||
$menuitemId = (int) $params->get('redirect_menuitem');
|
||||
|
||||
if ($menuitemId > 0) {
|
||||
$lang = '';
|
||||
$item = $app->getMenu()->getItem($menuitemId);
|
||||
|
||||
if (Multilanguage::isEnabled()) {
|
||||
$lang = !\is_null($item) && $item->language != '*' ? '&lang=' . $item->language : '';
|
||||
}
|
||||
|
||||
// Redirect to the general (redirect_menuitem) user specified return page.
|
||||
$redirlink = $item->link . $lang . '&Itemid=' . $menuitemId;
|
||||
} else {
|
||||
// Redirect to the return page.
|
||||
$redirlink = $this->getReturnPage();
|
||||
}
|
||||
}
|
||||
|
||||
$this->setRedirect(Route::_($redirlink, false));
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to edit an existing record.
|
||||
*
|
||||
* @param string $key The name of the primary key of the URL variable.
|
||||
* @param string $urlVar The name of the URL variable if different from the primary key
|
||||
* (sometimes required to avoid router collisions).
|
||||
*
|
||||
* @return boolean True if access level check and checkout passes, false otherwise.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function edit($key = null, $urlVar = 'a_id')
|
||||
{
|
||||
$result = parent::edit($key, $urlVar);
|
||||
|
||||
if (!$result) {
|
||||
$this->setRedirect(Route::_($this->getReturnPage(), false));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a model object, loading it if required.
|
||||
*
|
||||
* @param string $name The model name. Optional.
|
||||
* @param string $prefix The class prefix. Optional.
|
||||
* @param array $config Configuration array for model. Optional.
|
||||
*
|
||||
* @return object The model.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public function getModel($name = 'Form', $prefix = 'Site', $config = ['ignore_request' => true])
|
||||
{
|
||||
return parent::getModel($name, $prefix, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URL arguments to append to an item redirect.
|
||||
*
|
||||
* @param integer $recordId The primary key id for the item.
|
||||
* @param string $urlVar The name of the URL variable for the id.
|
||||
*
|
||||
* @return string The arguments to append to the redirect URL.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getRedirectToItemAppend($recordId = null, $urlVar = 'a_id')
|
||||
{
|
||||
// Need to override the parent method completely.
|
||||
$tmpl = $this->input->get('tmpl');
|
||||
|
||||
$append = '';
|
||||
|
||||
// Setup redirect info.
|
||||
if ($tmpl) {
|
||||
$append .= '&tmpl=' . $tmpl;
|
||||
}
|
||||
|
||||
// @todo This is a bandaid, not a long term solution.
|
||||
/**
|
||||
* if ($layout)
|
||||
* {
|
||||
* $append .= '&layout=' . $layout;
|
||||
* }
|
||||
*/
|
||||
|
||||
$append .= '&layout=edit';
|
||||
|
||||
if ($recordId) {
|
||||
$append .= '&' . $urlVar . '=' . $recordId;
|
||||
}
|
||||
|
||||
$itemId = $this->input->getInt('Itemid');
|
||||
$return = $this->getReturnPage();
|
||||
$catId = $this->input->getInt('catid');
|
||||
|
||||
if ($itemId) {
|
||||
$append .= '&Itemid=' . $itemId;
|
||||
}
|
||||
|
||||
if ($catId) {
|
||||
$append .= '&catid=' . $catId;
|
||||
}
|
||||
|
||||
if ($return) {
|
||||
$append .= '&return=' . base64_encode($return);
|
||||
}
|
||||
|
||||
return $append;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the return URL.
|
||||
*
|
||||
* If a "return" variable has been passed in the request
|
||||
*
|
||||
* @return string The return URL.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getReturnPage()
|
||||
{
|
||||
$return = $this->input->get('return', null, 'base64');
|
||||
|
||||
if (empty($return) || !Uri::isInternal(base64_decode($return))) {
|
||||
return Uri::base();
|
||||
}
|
||||
|
||||
return base64_decode($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to save a record.
|
||||
*
|
||||
* @param string $key The name of the primary key of the URL variable.
|
||||
* @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions).
|
||||
*
|
||||
* @return boolean True if successful, false otherwise.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function save($key = null, $urlVar = 'a_id')
|
||||
{
|
||||
$result = parent::save($key, $urlVar);
|
||||
|
||||
if (\in_array($this->getTask(), ['save2copy', 'apply'], true)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$app = $this->app;
|
||||
$articleId = $app->getInput()->getInt('a_id');
|
||||
|
||||
// Load the parameters.
|
||||
$params = $app->getParams();
|
||||
$menuitem = (int) $params->get('redirect_menuitem');
|
||||
|
||||
// Check for redirection after submission when creating a new article only
|
||||
if ($menuitem > 0 && $articleId == 0) {
|
||||
$lang = '';
|
||||
|
||||
if (Multilanguage::isEnabled()) {
|
||||
$item = $app->getMenu()->getItem($menuitem);
|
||||
$lang = !\is_null($item) && $item->language != '*' ? '&lang=' . $item->language : '';
|
||||
}
|
||||
|
||||
// If ok, redirect to the return page.
|
||||
if ($result) {
|
||||
$this->setRedirect(Route::_('index.php?Itemid=' . $menuitem . $lang, false));
|
||||
}
|
||||
} elseif ($this->getTask() === 'save2copy') {
|
||||
// Redirect to the article page, use the redirect url set from parent controller
|
||||
} else {
|
||||
// If ok, redirect to the return page.
|
||||
if ($result) {
|
||||
$this->setRedirect(Route::_($this->getReturnPage(), false));
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to reload a record.
|
||||
*
|
||||
* @param string $key The name of the primary key of the URL variable.
|
||||
* @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions).
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.8.0
|
||||
*/
|
||||
public function reload($key = null, $urlVar = 'a_id')
|
||||
{
|
||||
parent::reload($key, $urlVar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to save a vote.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function vote()
|
||||
{
|
||||
// Check for request forgeries.
|
||||
$this->checkToken();
|
||||
|
||||
$user_rating = $this->input->getInt('user_rating', -1);
|
||||
|
||||
if ($user_rating > -1) {
|
||||
$url = $this->input->getString('url', '');
|
||||
$id = $this->input->getInt('id', 0);
|
||||
$viewName = $this->input->getString('view', $this->default_view);
|
||||
$model = $this->getModel($viewName);
|
||||
|
||||
// Don't redirect to an external URL.
|
||||
if (!Uri::isInternal($url)) {
|
||||
$url = Route::_('index.php');
|
||||
}
|
||||
|
||||
if ($model->storeVote($id, $user_rating)) {
|
||||
$this->setRedirect($url, Text::_('COM_CONTENT_ARTICLE_VOTE_SUCCESS'));
|
||||
} else {
|
||||
$this->setRedirect($url, Text::_('COM_CONTENT_ARTICLE_VOTE_FAILURE'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
126
components/com_content/src/Controller/DisplayController.php
Normal file
126
components/com_content/src/Controller/DisplayController.php
Normal file
@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Content\Site\Controller;
|
||||
|
||||
use Joomla\CMS\Application\CMSApplication;
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Content Component Controller
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class DisplayController extends \Joomla\CMS\MVC\Controller\BaseController
|
||||
{
|
||||
/**
|
||||
* @param array $config An optional associative array of configuration settings.
|
||||
* Recognized key values include 'name', 'default_task', 'model_path', and
|
||||
* 'view_path' (this list is not meant to be comprehensive).
|
||||
* @param ?MVCFactoryInterface $factory The factory.
|
||||
* @param ?CMSApplication $app The Application for the dispatcher
|
||||
* @param ?\Joomla\CMS\Input\Input $input The Input object for the request
|
||||
*
|
||||
* @since 3.0.1
|
||||
*/
|
||||
public function __construct($config = [], ?MVCFactoryInterface $factory = null, $app = null, $input = null)
|
||||
{
|
||||
$this->input = Factory::getApplication()->getInput();
|
||||
|
||||
// Article frontpage Editor pagebreak proxying:
|
||||
if ($this->input->get('view') === 'article' && $this->input->get('layout') === 'pagebreak') {
|
||||
$config['base_path'] = JPATH_COMPONENT_ADMINISTRATOR;
|
||||
} elseif ($this->input->get('view') === 'articles' && $this->input->get('layout') === 'modal') {
|
||||
// Article frontpage Editor article proxying:
|
||||
$config['base_path'] = JPATH_COMPONENT_ADMINISTRATOR;
|
||||
}
|
||||
|
||||
parent::__construct($config, $factory, $app, $input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to display a view.
|
||||
*
|
||||
* @param boolean $cachable If true, the view output will be cached.
|
||||
* @param boolean $urlparams An array of safe URL parameters and their variable types.
|
||||
* @see \Joomla\CMS\Filter\InputFilter::clean() for valid values.
|
||||
*
|
||||
* @return DisplayController This object to support chaining.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public function display($cachable = false, $urlparams = false)
|
||||
{
|
||||
$cachable = true;
|
||||
|
||||
/**
|
||||
* Set the default view name and format from the Request.
|
||||
* Note we are using a_id to avoid collisions with the router and the return page.
|
||||
* Frontend is a bit messier than the backend.
|
||||
*/
|
||||
$id = $this->input->getInt('a_id');
|
||||
$vName = $this->input->getCmd('view', 'categories');
|
||||
$this->input->set('view', $vName);
|
||||
|
||||
$user = $this->app->getIdentity();
|
||||
|
||||
if (
|
||||
$user->id
|
||||
|| ($this->input->getMethod() === 'POST'
|
||||
&& (($vName === 'category' && $this->input->get('layout') !== 'blog') || $vName === 'archive'))
|
||||
) {
|
||||
$cachable = false;
|
||||
}
|
||||
|
||||
$safeurlparams = [
|
||||
'catid' => 'INT',
|
||||
'id' => 'INT',
|
||||
'cid' => 'ARRAY',
|
||||
'year' => 'INT',
|
||||
'month' => 'INT',
|
||||
'limit' => 'UINT',
|
||||
'limitstart' => 'UINT',
|
||||
'showall' => 'INT',
|
||||
'return' => 'BASE64',
|
||||
'filter' => 'STRING',
|
||||
'filter_order' => 'CMD',
|
||||
'filter_order_Dir' => 'CMD',
|
||||
'filter-search' => 'STRING',
|
||||
'print' => 'BOOLEAN',
|
||||
'lang' => 'CMD',
|
||||
'Itemid' => 'INT', ];
|
||||
|
||||
// Check for edit form.
|
||||
if ($vName === 'form' && !$this->checkEditId('com_content.edit.article', $id)) {
|
||||
// Somehow the person just went to the form - we don't allow that.
|
||||
throw new \Exception(Text::sprintf('JLIB_APPLICATION_ERROR_UNHELD_ID', $id), 403);
|
||||
}
|
||||
|
||||
if ($vName === 'article' && \in_array($this->input->getMethod(), ['GET', 'POST'])) {
|
||||
// Get/Create the model
|
||||
if ($model = $this->getModel($vName)) {
|
||||
if (ComponentHelper::getParams('com_content')->get('record_hits', 1) == 1) {
|
||||
$model->hit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parent::display($cachable, $safeurlparams);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
58
components/com_content/src/Dispatcher/Dispatcher.php
Normal file
58
components/com_content/src/Dispatcher/Dispatcher.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Content\Site\Dispatcher;
|
||||
|
||||
use Joomla\CMS\Dispatcher\ComponentDispatcher;
|
||||
use Joomla\CMS\Language\Text;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* ComponentDispatcher class for com_content
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class Dispatcher extends ComponentDispatcher
|
||||
{
|
||||
/**
|
||||
* Dispatch a controller task. Redirecting the user if appropriate.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function dispatch()
|
||||
{
|
||||
$checkCreateEdit = ($this->input->get('view') === 'articles' && $this->input->get('layout') === 'modal')
|
||||
|| ($this->input->get('view') === 'article' && $this->input->get('layout') === 'pagebreak');
|
||||
|
||||
if ($checkCreateEdit) {
|
||||
// Can create in any category (component permission) or at least in one category
|
||||
$canCreateRecords = $this->app->getIdentity()->authorise('core.create', 'com_content')
|
||||
|| \count($this->app->getIdentity()->getAuthorisedCategories('com_content', 'core.create')) > 0;
|
||||
|
||||
// Instead of checking edit on all records, we can use **same** check as the form editing view
|
||||
$values = (array) $this->app->getUserState('com_content.edit.article.id');
|
||||
$isEditingRecords = \count($values);
|
||||
$hasAccess = $canCreateRecords || $isEditingRecords;
|
||||
|
||||
if (!$hasAccess) {
|
||||
$this->app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'warning');
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
parent::dispatch();
|
||||
}
|
||||
}
|
||||
150
components/com_content/src/Helper/AssociationHelper.php
Normal file
150
components/com_content/src/Helper/AssociationHelper.php
Normal file
@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright (C) 2012 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Content\Site\Helper;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Associations;
|
||||
use Joomla\CMS\Language\LanguageHelper;
|
||||
use Joomla\CMS\Language\Multilanguage;
|
||||
use Joomla\Component\Categories\Administrator\Helper\CategoryAssociationHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Content Component Association Helper
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
abstract class AssociationHelper extends CategoryAssociationHelper
|
||||
{
|
||||
/**
|
||||
* Method to get the associations for a given item
|
||||
*
|
||||
* @param integer $id Id of the item
|
||||
* @param string $view Name of the view
|
||||
* @param string $layout View layout
|
||||
*
|
||||
* @return array Array of associations for the item
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
public static function getAssociations($id = 0, $view = null, $layout = null)
|
||||
{
|
||||
$jinput = Factory::getApplication()->getInput();
|
||||
$view = $view ?? $jinput->get('view');
|
||||
$component = $jinput->getCmd('option');
|
||||
$id = empty($id) ? $jinput->getInt('id') : $id;
|
||||
|
||||
if ($layout === null && $jinput->get('view') == $view && $component == 'com_content') {
|
||||
$layout = $jinput->get('layout', '', 'string');
|
||||
}
|
||||
|
||||
if ($view === 'article') {
|
||||
if ($id) {
|
||||
$user = Factory::getUser();
|
||||
$groups = implode(',', $user->getAuthorisedViewLevels());
|
||||
$db = Factory::getDbo();
|
||||
$advClause = [];
|
||||
|
||||
// Filter by user groups
|
||||
$advClause[] = 'c2.access IN (' . $groups . ')';
|
||||
|
||||
// Filter by current language
|
||||
$advClause[] = 'c2.language != ' . $db->quote(Factory::getLanguage()->getTag());
|
||||
|
||||
if (!$user->authorise('core.edit.state', 'com_content') && !$user->authorise('core.edit', 'com_content')) {
|
||||
// Filter by start and end dates.
|
||||
$date = Factory::getDate();
|
||||
|
||||
$nowDate = $db->quote($date->toSql());
|
||||
|
||||
$advClause[] = '(c2.publish_up IS NULL OR c2.publish_up <= ' . $nowDate . ')';
|
||||
$advClause[] = '(c2.publish_down IS NULL OR c2.publish_down >= ' . $nowDate . ')';
|
||||
|
||||
// Filter by published
|
||||
$advClause[] = 'c2.state = 1';
|
||||
}
|
||||
|
||||
$associations = Associations::getAssociations(
|
||||
'com_content',
|
||||
'#__content',
|
||||
'com_content.item',
|
||||
$id,
|
||||
'id',
|
||||
'alias',
|
||||
'catid',
|
||||
$advClause
|
||||
);
|
||||
|
||||
$return = [];
|
||||
|
||||
foreach ($associations as $tag => $item) {
|
||||
$return[$tag] = RouteHelper::getArticleRoute($item->id, (int) $item->catid, $item->language, $layout);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
||||
if ($view === 'category' || $view === 'categories') {
|
||||
return self::getCategoryAssociations($id, 'com_content', $layout);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to display in frontend the associations for a given article
|
||||
*
|
||||
* @param integer $id Id of the article
|
||||
*
|
||||
* @return array An array containing the association URL and the related language object
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
public static function displayAssociations($id)
|
||||
{
|
||||
$return = [];
|
||||
|
||||
if ($associations = self::getAssociations($id, 'article')) {
|
||||
$levels = Factory::getUser()->getAuthorisedViewLevels();
|
||||
$languages = LanguageHelper::getLanguages();
|
||||
|
||||
foreach ($languages as $language) {
|
||||
// Do not display language when no association
|
||||
if (empty($associations[$language->lang_code])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Do not display language without frontend UI
|
||||
if (!\array_key_exists($language->lang_code, LanguageHelper::getInstalledLanguages(0))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Do not display language without specific home menu
|
||||
if (!\array_key_exists($language->lang_code, Multilanguage::getSiteHomePages())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Do not display language without authorized access level
|
||||
if (isset($language->access) && $language->access && !\in_array($language->access, $levels)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$return[$language->lang_code] = ['item' => $associations[$language->lang_code], 'language' => $language];
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
230
components/com_content/src/Helper/QueryHelper.php
Normal file
230
components/com_content/src/Helper/QueryHelper.php
Normal file
@ -0,0 +1,230 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright (C) 2007 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Content\Site\Helper;
|
||||
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\Database\DatabaseInterface;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Content Component Query Helper
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class QueryHelper
|
||||
{
|
||||
/**
|
||||
* Translate an order code to a field for category ordering.
|
||||
*
|
||||
* @param string $orderby The ordering code.
|
||||
*
|
||||
* @return string The SQL field(s) to order by.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public static function orderbyPrimary($orderby)
|
||||
{
|
||||
switch ($orderby) {
|
||||
case 'alpha':
|
||||
$orderby = 'c.path, ';
|
||||
break;
|
||||
|
||||
case 'ralpha':
|
||||
$orderby = 'c.path DESC, ';
|
||||
break;
|
||||
|
||||
case 'order':
|
||||
$orderby = 'c.lft, ';
|
||||
break;
|
||||
|
||||
default:
|
||||
$orderby = '';
|
||||
break;
|
||||
}
|
||||
|
||||
return $orderby;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate an order code to a field for article ordering.
|
||||
*
|
||||
* @param string $orderby The ordering code.
|
||||
* @param string $orderDate The ordering code for the date.
|
||||
* @param ?DatabaseInterface $db The database
|
||||
*
|
||||
* @return string The SQL field(s) to order by.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public static function orderbySecondary($orderby, $orderDate = 'created', ?DatabaseInterface $db = null)
|
||||
{
|
||||
$db = $db ?: Factory::getDbo();
|
||||
|
||||
$queryDate = self::getQueryDate($orderDate, $db);
|
||||
|
||||
switch ($orderby) {
|
||||
case 'date':
|
||||
$orderby = $queryDate;
|
||||
break;
|
||||
|
||||
case 'rdate':
|
||||
$orderby = $queryDate . ' DESC ';
|
||||
break;
|
||||
|
||||
case 'alpha':
|
||||
$orderby = 'a.title';
|
||||
break;
|
||||
|
||||
case 'ralpha':
|
||||
$orderby = 'a.title DESC';
|
||||
break;
|
||||
|
||||
case 'hits':
|
||||
$orderby = 'a.hits DESC';
|
||||
break;
|
||||
|
||||
case 'rhits':
|
||||
$orderby = 'a.hits';
|
||||
break;
|
||||
|
||||
case 'rorder':
|
||||
$orderby = 'a.ordering DESC';
|
||||
break;
|
||||
|
||||
case 'author':
|
||||
$orderby = 'author';
|
||||
break;
|
||||
|
||||
case 'rauthor':
|
||||
$orderby = 'author DESC';
|
||||
break;
|
||||
|
||||
case 'front':
|
||||
$orderby = 'a.featured DESC, fp.ordering, ' . $queryDate . ' DESC ';
|
||||
break;
|
||||
|
||||
case 'random':
|
||||
$orderby = $db->getQuery(true)->rand();
|
||||
break;
|
||||
|
||||
case 'vote':
|
||||
$orderby = 'a.id DESC ';
|
||||
|
||||
if (PluginHelper::isEnabled('content', 'vote')) {
|
||||
$orderby = 'rating_count DESC ';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'rvote':
|
||||
$orderby = 'a.id ASC ';
|
||||
|
||||
if (PluginHelper::isEnabled('content', 'vote')) {
|
||||
$orderby = 'rating_count ASC ';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'rank':
|
||||
$orderby = 'a.id DESC ';
|
||||
|
||||
if (PluginHelper::isEnabled('content', 'vote')) {
|
||||
$orderby = 'rating DESC ';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'rrank':
|
||||
$orderby = 'a.id ASC ';
|
||||
|
||||
if (PluginHelper::isEnabled('content', 'vote')) {
|
||||
$orderby = 'rating ASC ';
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$orderby = 'a.ordering';
|
||||
break;
|
||||
}
|
||||
|
||||
return $orderby;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate an order code to a field for date ordering.
|
||||
*
|
||||
* @param string $orderDate The ordering code.
|
||||
* @param ?DatabaseInterface $db The database
|
||||
*
|
||||
* @return string The SQL field(s) to order by.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public static function getQueryDate($orderDate, ?DatabaseInterface $db = null)
|
||||
{
|
||||
$db = $db ?: Factory::getDbo();
|
||||
|
||||
switch ($orderDate) {
|
||||
case 'modified':
|
||||
$queryDate = ' CASE WHEN a.modified IS NULL THEN a.created ELSE a.modified END';
|
||||
break;
|
||||
|
||||
// Use created if publish_up is not set
|
||||
case 'published':
|
||||
$queryDate = ' CASE WHEN a.publish_up IS NULL THEN a.created ELSE a.publish_up END ';
|
||||
break;
|
||||
|
||||
case 'unpublished':
|
||||
$queryDate = ' CASE WHEN a.publish_down IS NULL THEN a.created ELSE a.publish_down END ';
|
||||
break;
|
||||
case 'created':
|
||||
default:
|
||||
$queryDate = ' a.created ';
|
||||
break;
|
||||
}
|
||||
|
||||
return $queryDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get join information for the voting query.
|
||||
*
|
||||
* @param \Joomla\Registry\Registry $params An options object for the article.
|
||||
*
|
||||
* @return array A named array with "select" and "join" keys.
|
||||
*
|
||||
* @since 1.5
|
||||
*
|
||||
* @deprecated 4.3 will be removed in 6.0
|
||||
* Will be removed without replacement
|
||||
*/
|
||||
public static function buildVotingQuery($params = null)
|
||||
{
|
||||
if (!$params) {
|
||||
$params = ComponentHelper::getParams('com_content');
|
||||
}
|
||||
|
||||
$voting = $params->get('show_vote');
|
||||
|
||||
if ($voting) {
|
||||
// Calculate voting count
|
||||
$select = ' , ROUND(v.rating_sum / v.rating_count) AS rating, v.rating_count';
|
||||
$join = ' LEFT JOIN #__content_rating AS v ON a.id = v.content_id';
|
||||
} else {
|
||||
$select = '';
|
||||
$join = '';
|
||||
}
|
||||
|
||||
return ['select' => $select, 'join' => $join];
|
||||
}
|
||||
}
|
||||
108
components/com_content/src/Helper/RouteHelper.php
Normal file
108
components/com_content/src/Helper/RouteHelper.php
Normal file
@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright (C) 2007 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Content\Site\Helper;
|
||||
|
||||
use Joomla\CMS\Categories\CategoryNode;
|
||||
use Joomla\CMS\Language\Multilanguage;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Content Component Route Helper.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
abstract class RouteHelper
|
||||
{
|
||||
/**
|
||||
* Get the article route.
|
||||
*
|
||||
* @param integer $id The route of the content item.
|
||||
* @param integer $catid The category ID.
|
||||
* @param string $language The language code.
|
||||
* @param string $layout The layout value.
|
||||
*
|
||||
* @return string The article route.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public static function getArticleRoute($id, $catid = 0, $language = null, $layout = null)
|
||||
{
|
||||
// Create the link
|
||||
$link = 'index.php?option=com_content&view=article&id=' . $id;
|
||||
|
||||
if ((int) $catid > 1) {
|
||||
$link .= '&catid=' . $catid;
|
||||
}
|
||||
|
||||
if (!empty($language) && $language !== '*' && Multilanguage::isEnabled()) {
|
||||
$link .= '&lang=' . $language;
|
||||
}
|
||||
|
||||
if ($layout) {
|
||||
$link .= '&layout=' . $layout;
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the category route.
|
||||
*
|
||||
* @param integer $catid The category ID.
|
||||
* @param integer $language The language code.
|
||||
* @param string $layout The layout value.
|
||||
*
|
||||
* @return string The article route.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public static function getCategoryRoute($catid, $language = 0, $layout = null)
|
||||
{
|
||||
if ($catid instanceof CategoryNode) {
|
||||
$id = $catid->id;
|
||||
} else {
|
||||
$id = (int) $catid;
|
||||
}
|
||||
|
||||
if ($id < 1) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$link = 'index.php?option=com_content&view=category&id=' . $id;
|
||||
|
||||
if ($language && $language !== '*' && Multilanguage::isEnabled()) {
|
||||
$link .= '&lang=' . $language;
|
||||
}
|
||||
|
||||
if ($layout) {
|
||||
$link .= '&layout=' . $layout;
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the form route.
|
||||
*
|
||||
* @param integer $id The form ID.
|
||||
*
|
||||
* @return string The article route.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public static function getFormRoute($id)
|
||||
{
|
||||
return 'index.php?option=com_content&task=article.edit&a_id=' . (int) $id;
|
||||
}
|
||||
}
|
||||
214
components/com_content/src/Model/ArchiveModel.php
Normal file
214
components/com_content/src/Model/ArchiveModel.php
Normal file
@ -0,0 +1,214 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Content\Site\Model;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\Component\Content\Administrator\Extension\ContentComponent;
|
||||
use Joomla\Component\Content\Site\Helper\QueryHelper;
|
||||
use Joomla\Database\ParameterType;
|
||||
use Joomla\Database\QueryInterface;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Content Component Archive Model
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class ArchiveModel extends ArticlesModel
|
||||
{
|
||||
/**
|
||||
* Model context string.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $_context = 'com_content.archive';
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @param string $ordering The field to order on.
|
||||
* @param string $direction The direction to order on.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function populateState($ordering = null, $direction = null)
|
||||
{
|
||||
parent::populateState();
|
||||
|
||||
$app = Factory::getApplication();
|
||||
$input = $app->getInput();
|
||||
|
||||
// Add archive properties
|
||||
$params = $this->state->get('params');
|
||||
|
||||
// Filter on archived articles
|
||||
$this->setState('filter.published', ContentComponent::CONDITION_ARCHIVED);
|
||||
|
||||
// Filter on month, year
|
||||
$this->setState('filter.month', $input->getInt('month'));
|
||||
$this->setState('filter.year', $input->getInt('year'));
|
||||
|
||||
// Optional filter text
|
||||
$this->setState('list.filter', $input->getString('filter-search'));
|
||||
|
||||
// Get list limit
|
||||
$itemid = $input->get('Itemid', 0, 'int');
|
||||
$limit = $app->getUserStateFromRequest('com_content.archive.list' . $itemid . '.limit', 'limit', $params->get('display_num', 20), 'uint');
|
||||
$this->setState('list.limit', $limit);
|
||||
|
||||
// Set the archive ordering
|
||||
$articleOrderby = $params->get('orderby_sec', 'rdate');
|
||||
$articleOrderDate = $params->get('order_date');
|
||||
|
||||
// No category ordering
|
||||
$secondary = QueryHelper::orderbySecondary($articleOrderby, $articleOrderDate, $this->getDatabase());
|
||||
|
||||
$this->setState('list.ordering', $secondary . ', a.created DESC');
|
||||
$this->setState('list.direction', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the main query for retrieving a list of articles subject to the model state.
|
||||
*
|
||||
* @return QueryInterface
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getListQuery()
|
||||
{
|
||||
$params = $this->state->params;
|
||||
$app = Factory::getApplication();
|
||||
$catids = $app->getInput()->get('catid', [], 'array');
|
||||
$catids = array_values(array_diff($catids, ['']));
|
||||
|
||||
$articleOrderDate = $params->get('order_date');
|
||||
|
||||
// Create a new query object.
|
||||
$db = $this->getDatabase();
|
||||
$query = parent::getListQuery();
|
||||
|
||||
// Add routing for archive
|
||||
$query->select(
|
||||
[
|
||||
$this->getSlugColumn($query, 'a.id', 'a.alias') . ' AS ' . $db->quoteName('slug'),
|
||||
$this->getSlugColumn($query, 'c.id', 'c.alias') . ' AS ' . $db->quoteName('catslug'),
|
||||
]
|
||||
);
|
||||
|
||||
// Filter on month, year
|
||||
// First, get the date field
|
||||
$queryDate = QueryHelper::getQueryDate($articleOrderDate, $this->getDatabase());
|
||||
|
||||
if ($month = (int) $this->getState('filter.month')) {
|
||||
$query->where($query->month($queryDate) . ' = :month')
|
||||
->bind(':month', $month, ParameterType::INTEGER);
|
||||
}
|
||||
|
||||
if ($year = (int) $this->getState('filter.year')) {
|
||||
$query->where($query->year($queryDate) . ' = :year')
|
||||
->bind(':year', $year, ParameterType::INTEGER);
|
||||
}
|
||||
|
||||
if (\count($catids) > 0) {
|
||||
$query->whereIn($db->quoteName('c.id'), $catids);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the archived article list
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
* @deprecated 5.2.0 will be removed in 7.0
|
||||
* Use getItems() instead
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
@trigger_error('ArchiveModel::getData() is deprecated. Use getItems() instead. Will be removed in 7.0.', E_USER_DEPRECATED);
|
||||
|
||||
return $this->getItems();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the archived articles years
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 3.6.0
|
||||
*/
|
||||
public function getYears()
|
||||
{
|
||||
$db = $this->getDatabase();
|
||||
$nowDate = Factory::getDate()->toSql();
|
||||
$query = $db->getQuery(true);
|
||||
$queryDate = QueryHelper::getQueryDate($this->state->params->get('order_date'), $db);
|
||||
$years = $query->year($queryDate);
|
||||
|
||||
$query->select('DISTINCT ' . $years)
|
||||
->from($db->quoteName('#__content', 'a'))
|
||||
->where($db->quoteName('a.state') . ' = ' . ContentComponent::CONDITION_ARCHIVED)
|
||||
->extendWhere(
|
||||
'AND',
|
||||
[
|
||||
$db->quoteName('a.publish_up') . ' IS NULL',
|
||||
$db->quoteName('a.publish_up') . ' <= :publishUp',
|
||||
],
|
||||
'OR'
|
||||
)
|
||||
->extendWhere(
|
||||
'AND',
|
||||
[
|
||||
$db->quoteName('a.publish_down') . ' IS NULL',
|
||||
$db->quoteName('a.publish_down') . ' >= :publishDown',
|
||||
],
|
||||
'OR'
|
||||
)
|
||||
->bind(':publishUp', $nowDate)
|
||||
->bind(':publishDown', $nowDate)
|
||||
->order('1 ASC');
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
return $db->loadColumn();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate column expression for slug or catslug.
|
||||
*
|
||||
* @param \Joomla\Database\DatabaseQuery $query Current query instance.
|
||||
* @param string $id Column id name.
|
||||
* @param string $alias Column alias name.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private function getSlugColumn($query, $id, $alias)
|
||||
{
|
||||
$db = $this->getDatabase();
|
||||
|
||||
return 'CASE WHEN '
|
||||
. $query->charLength($db->quoteName($alias), '!=', '0')
|
||||
. ' THEN '
|
||||
. $query->concatenate([$query->castAsChar($db->quoteName($id)), $db->quoteName($alias)], ':')
|
||||
. ' ELSE '
|
||||
. $query->castAsChar($id) . ' END';
|
||||
}
|
||||
}
|
||||
435
components/com_content/src/Model/ArticleModel.php
Normal file
435
components/com_content/src/Model/ArticleModel.php
Normal file
@ -0,0 +1,435 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Content\Site\Model;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Multilanguage;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Model\ItemModel;
|
||||
use Joomla\CMS\Table\Table;
|
||||
use Joomla\Component\Content\Administrator\Extension\ContentComponent;
|
||||
use Joomla\Database\ParameterType;
|
||||
use Joomla\Registry\Registry;
|
||||
use Joomla\Utilities\IpHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Content Component Article Model
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class ArticleModel extends ItemModel
|
||||
{
|
||||
/**
|
||||
* Model context string.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_context = 'com_content.article';
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @since 1.6
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function populateState()
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
|
||||
// Load state from the request.
|
||||
$pk = $app->getInput()->getInt('id');
|
||||
$this->setState('article.id', $pk);
|
||||
|
||||
$offset = $app->getInput()->getUint('limitstart');
|
||||
$this->setState('list.offset', $offset);
|
||||
|
||||
// Load the parameters.
|
||||
$params = $app->getParams();
|
||||
$this->setState('params', $params);
|
||||
|
||||
$user = $this->getCurrentUser();
|
||||
|
||||
// If $pk is set then authorise on complete asset, else on component only
|
||||
$asset = empty($pk) ? 'com_content' : 'com_content.article.' . $pk;
|
||||
|
||||
if ((!$user->authorise('core.edit.state', $asset)) && (!$user->authorise('core.edit', $asset))) {
|
||||
$this->setState('filter.published', ContentComponent::CONDITION_PUBLISHED);
|
||||
$this->setState('filter.archived', ContentComponent::CONDITION_ARCHIVED);
|
||||
}
|
||||
|
||||
$this->setState('filter.language', Multilanguage::isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get article data.
|
||||
*
|
||||
* @param integer $pk The id of the article.
|
||||
*
|
||||
* @return object|boolean Menu item data object on success, boolean false
|
||||
*/
|
||||
public function getItem($pk = null)
|
||||
{
|
||||
$user = $this->getCurrentUser();
|
||||
|
||||
$pk = (int) ($pk ?: $this->getState('article.id'));
|
||||
|
||||
if ($this->_item === null) {
|
||||
$this->_item = [];
|
||||
}
|
||||
|
||||
if (!isset($this->_item[$pk])) {
|
||||
try {
|
||||
$db = $this->getDatabase();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
$query->select(
|
||||
$this->getState(
|
||||
'item.select',
|
||||
[
|
||||
$db->quoteName('a.id'),
|
||||
$db->quoteName('a.asset_id'),
|
||||
$db->quoteName('a.title'),
|
||||
$db->quoteName('a.alias'),
|
||||
$db->quoteName('a.introtext'),
|
||||
$db->quoteName('a.fulltext'),
|
||||
$db->quoteName('a.state'),
|
||||
$db->quoteName('a.catid'),
|
||||
$db->quoteName('a.created'),
|
||||
$db->quoteName('a.created_by'),
|
||||
$db->quoteName('a.created_by_alias'),
|
||||
$db->quoteName('a.modified'),
|
||||
$db->quoteName('a.modified_by'),
|
||||
$db->quoteName('a.checked_out'),
|
||||
$db->quoteName('a.checked_out_time'),
|
||||
$db->quoteName('a.publish_up'),
|
||||
$db->quoteName('a.publish_down'),
|
||||
$db->quoteName('a.images'),
|
||||
$db->quoteName('a.urls'),
|
||||
$db->quoteName('a.attribs'),
|
||||
$db->quoteName('a.version'),
|
||||
$db->quoteName('a.ordering'),
|
||||
$db->quoteName('a.metakey'),
|
||||
$db->quoteName('a.metadesc'),
|
||||
$db->quoteName('a.access'),
|
||||
$db->quoteName('a.hits'),
|
||||
$db->quoteName('a.metadata'),
|
||||
$db->quoteName('a.featured'),
|
||||
$db->quoteName('a.language'),
|
||||
]
|
||||
)
|
||||
)
|
||||
->select(
|
||||
[
|
||||
$db->quoteName('fp.featured_up'),
|
||||
$db->quoteName('fp.featured_down'),
|
||||
$db->quoteName('c.title', 'category_title'),
|
||||
$db->quoteName('c.alias', 'category_alias'),
|
||||
$db->quoteName('c.access', 'category_access'),
|
||||
$db->quoteName('c.language', 'category_language'),
|
||||
$db->quoteName('fp.ordering'),
|
||||
$db->quoteName('u.name', 'author'),
|
||||
$db->quoteName('parent.title', 'parent_title'),
|
||||
$db->quoteName('parent.id', 'parent_id'),
|
||||
$db->quoteName('parent.path', 'parent_route'),
|
||||
$db->quoteName('parent.alias', 'parent_alias'),
|
||||
$db->quoteName('parent.language', 'parent_language'),
|
||||
'ROUND(' . $db->quoteName('v.rating_sum') . ' / ' . $db->quoteName('v.rating_count') . ', 1) AS '
|
||||
. $db->quoteName('rating'),
|
||||
$db->quoteName('v.rating_count', 'rating_count'),
|
||||
]
|
||||
)
|
||||
->from($db->quoteName('#__content', 'a'))
|
||||
->join(
|
||||
'INNER',
|
||||
$db->quoteName('#__categories', 'c'),
|
||||
$db->quoteName('c.id') . ' = ' . $db->quoteName('a.catid')
|
||||
)
|
||||
->join('LEFT', $db->quoteName('#__content_frontpage', 'fp'), $db->quoteName('fp.content_id') . ' = ' . $db->quoteName('a.id'))
|
||||
->join('LEFT', $db->quoteName('#__users', 'u'), $db->quoteName('u.id') . ' = ' . $db->quoteName('a.created_by'))
|
||||
->join('LEFT', $db->quoteName('#__categories', 'parent'), $db->quoteName('parent.id') . ' = ' . $db->quoteName('c.parent_id'))
|
||||
->join('LEFT', $db->quoteName('#__content_rating', 'v'), $db->quoteName('a.id') . ' = ' . $db->quoteName('v.content_id'))
|
||||
->where(
|
||||
[
|
||||
$db->quoteName('a.id') . ' = :pk',
|
||||
$db->quoteName('c.published') . ' > 0',
|
||||
]
|
||||
)
|
||||
->bind(':pk', $pk, ParameterType::INTEGER);
|
||||
|
||||
// Filter by language
|
||||
if ($this->getState('filter.language')) {
|
||||
$query->whereIn($db->quoteName('a.language'), [Factory::getLanguage()->getTag(), '*'], ParameterType::STRING);
|
||||
}
|
||||
|
||||
if (
|
||||
!$user->authorise('core.edit.state', 'com_content.article.' . $pk)
|
||||
&& !$user->authorise('core.edit', 'com_content.article.' . $pk)
|
||||
) {
|
||||
// Filter by start and end dates.
|
||||
$nowDate = Factory::getDate()->toSql();
|
||||
|
||||
$query->extendWhere(
|
||||
'AND',
|
||||
[
|
||||
$db->quoteName('a.publish_up') . ' IS NULL',
|
||||
$db->quoteName('a.publish_up') . ' <= :publishUp',
|
||||
],
|
||||
'OR'
|
||||
)
|
||||
->extendWhere(
|
||||
'AND',
|
||||
[
|
||||
$db->quoteName('a.publish_down') . ' IS NULL',
|
||||
$db->quoteName('a.publish_down') . ' >= :publishDown',
|
||||
],
|
||||
'OR'
|
||||
)
|
||||
->bind([':publishUp', ':publishDown'], $nowDate);
|
||||
}
|
||||
|
||||
// Filter by published state.
|
||||
$published = $this->getState('filter.published');
|
||||
$archived = $this->getState('filter.archived');
|
||||
|
||||
if (is_numeric($published)) {
|
||||
$query->whereIn($db->quoteName('a.state'), [(int) $published, (int) $archived]);
|
||||
}
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
$data = $db->loadObject();
|
||||
|
||||
if (empty($data)) {
|
||||
throw new \Exception(Text::_('COM_CONTENT_ERROR_ARTICLE_NOT_FOUND'), 404);
|
||||
}
|
||||
|
||||
// Check for published state if filter set.
|
||||
if ((is_numeric($published) || is_numeric($archived)) && ($data->state != $published && $data->state != $archived)) {
|
||||
throw new \Exception(Text::_('COM_CONTENT_ERROR_ARTICLE_NOT_FOUND'), 404);
|
||||
}
|
||||
|
||||
// Convert parameter fields to objects.
|
||||
$registry = new Registry($data->attribs);
|
||||
|
||||
$data->params = clone $this->getState('params');
|
||||
$data->params->merge($registry);
|
||||
|
||||
$data->metadata = new Registry($data->metadata);
|
||||
|
||||
// Technically guest could edit an article, but lets not check that to improve performance a little.
|
||||
if (!$user->guest) {
|
||||
$userId = $user->id;
|
||||
$asset = 'com_content.article.' . $data->id;
|
||||
|
||||
// Check general edit permission first.
|
||||
if ($user->authorise('core.edit', $asset)) {
|
||||
$data->params->set('access-edit', true);
|
||||
} elseif (!empty($userId) && $user->authorise('core.edit.own', $asset)) {
|
||||
// Now check if edit.own is available.
|
||||
// Check for a valid user and that they are the owner.
|
||||
if ($userId == $data->created_by) {
|
||||
$data->params->set('access-edit', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Compute view access permissions.
|
||||
if ($access = $this->getState('filter.access')) {
|
||||
// If the access filter has been set, we already know this user can view.
|
||||
$data->params->set('access-view', true);
|
||||
} else {
|
||||
// If no access filter is set, the layout takes some responsibility for display of limited information.
|
||||
$user = $this->getCurrentUser();
|
||||
$groups = $user->getAuthorisedViewLevels();
|
||||
|
||||
if ($data->catid == 0 || $data->category_access === null) {
|
||||
$data->params->set('access-view', \in_array($data->access, $groups));
|
||||
} else {
|
||||
$data->params->set('access-view', \in_array($data->access, $groups) && \in_array($data->category_access, $groups));
|
||||
}
|
||||
}
|
||||
|
||||
$this->_item[$pk] = $data;
|
||||
} catch (\Exception $e) {
|
||||
if ($e->getCode() == 404) {
|
||||
// Need to go through the error handler to allow Redirect to work.
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->setError($e);
|
||||
$this->_item[$pk] = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_item[$pk];
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the hit counter for the article.
|
||||
*
|
||||
* @param integer $pk Optional primary key of the article to increment.
|
||||
*
|
||||
* @return boolean True if successful; false otherwise and internal error set.
|
||||
*/
|
||||
public function hit($pk = 0)
|
||||
{
|
||||
$input = Factory::getApplication()->getInput();
|
||||
$hitcount = $input->getInt('hitcount', 1);
|
||||
|
||||
if ($hitcount) {
|
||||
$pk = (!empty($pk)) ? $pk : (int) $this->getState('article.id');
|
||||
|
||||
$table = Table::getInstance('Content', '\\Joomla\\CMS\\Table\\');
|
||||
$table->hit($pk);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save user vote on article
|
||||
*
|
||||
* @param integer $pk Joomla Article Id
|
||||
* @param integer $rate Voting rate
|
||||
*
|
||||
* @return boolean Return true on success
|
||||
*/
|
||||
public function storeVote($pk = 0, $rate = 0)
|
||||
{
|
||||
$pk = (int) $pk;
|
||||
$rate = (int) $rate;
|
||||
|
||||
if ($rate >= 1 && $rate <= 5 && $pk > 0) {
|
||||
$userIP = IpHelper::getIp();
|
||||
|
||||
// Initialize variables.
|
||||
$db = $this->getDatabase();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// Create the base select statement.
|
||||
$query->select('*')
|
||||
->from($db->quoteName('#__content_rating'))
|
||||
->where($db->quoteName('content_id') . ' = :pk')
|
||||
->bind(':pk', $pk, ParameterType::INTEGER);
|
||||
|
||||
// Set the query and load the result.
|
||||
$db->setQuery($query);
|
||||
|
||||
// Check for a database error.
|
||||
try {
|
||||
$rating = $db->loadObject();
|
||||
} catch (\RuntimeException $e) {
|
||||
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// There are no ratings yet, so lets insert our rating
|
||||
if (!$rating) {
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// Create the base insert statement.
|
||||
$query->insert($db->quoteName('#__content_rating'))
|
||||
->columns(
|
||||
[
|
||||
$db->quoteName('content_id'),
|
||||
$db->quoteName('lastip'),
|
||||
$db->quoteName('rating_sum'),
|
||||
$db->quoteName('rating_count'),
|
||||
]
|
||||
)
|
||||
->values(':pk, :ip, :rate, 1')
|
||||
->bind(':pk', $pk, ParameterType::INTEGER)
|
||||
->bind(':ip', $userIP)
|
||||
->bind(':rate', $rate, ParameterType::INTEGER);
|
||||
|
||||
// Set the query and execute the insert.
|
||||
$db->setQuery($query);
|
||||
|
||||
try {
|
||||
$db->execute();
|
||||
} catch (\RuntimeException $e) {
|
||||
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
|
||||
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if ($userIP != $rating->lastip) {
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// Create the base update statement.
|
||||
$query->update($db->quoteName('#__content_rating'))
|
||||
->set(
|
||||
[
|
||||
$db->quoteName('rating_count') . ' = ' . $db->quoteName('rating_count') . ' + 1',
|
||||
$db->quoteName('rating_sum') . ' = ' . $db->quoteName('rating_sum') . ' + :rate',
|
||||
$db->quoteName('lastip') . ' = :ip',
|
||||
]
|
||||
)
|
||||
->where($db->quoteName('content_id') . ' = :pk')
|
||||
->bind(':rate', $rate, ParameterType::INTEGER)
|
||||
->bind(':ip', $userIP)
|
||||
->bind(':pk', $pk, ParameterType::INTEGER);
|
||||
|
||||
// Set the query and execute the update.
|
||||
$db->setQuery($query);
|
||||
|
||||
try {
|
||||
$db->execute();
|
||||
} catch (\RuntimeException $e) {
|
||||
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
|
||||
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$this->cleanCache();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Factory::getApplication()->enqueueMessage(Text::sprintf('COM_CONTENT_INVALID_RATING', $rate), 'error');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans the cache of com_content and content modules
|
||||
*
|
||||
* @param string $group The cache group
|
||||
* @param integer $clientId No longer used, will be removed without replacement
|
||||
* @deprecated 4.3 will be removed in 6.0
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.9.9
|
||||
*/
|
||||
protected function cleanCache($group = null, $clientId = 0)
|
||||
{
|
||||
parent::cleanCache('com_content');
|
||||
parent::cleanCache('mod_articles_archive');
|
||||
parent::cleanCache('mod_articles_categories');
|
||||
parent::cleanCache('mod_articles_category');
|
||||
parent::cleanCache('mod_articles_latest');
|
||||
parent::cleanCache('mod_articles_news');
|
||||
parent::cleanCache('mod_articles_popular');
|
||||
}
|
||||
}
|
||||
841
components/com_content/src/Model/ArticlesModel.php
Normal file
841
components/com_content/src/Model/ArticlesModel.php
Normal file
@ -0,0 +1,841 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Content\Site\Model;
|
||||
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Helper\TagsHelper;
|
||||
use Joomla\CMS\Language\Associations;
|
||||
use Joomla\CMS\Language\Multilanguage;
|
||||
use Joomla\CMS\MVC\Model\ListModel;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\Component\Content\Administrator\Extension\ContentComponent;
|
||||
use Joomla\Component\Content\Site\Helper\AssociationHelper;
|
||||
use Joomla\Database\ParameterType;
|
||||
use Joomla\Database\QueryInterface;
|
||||
use Joomla\Registry\Registry;
|
||||
use Joomla\String\StringHelper;
|
||||
use Joomla\Utilities\ArrayHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* This models supports retrieving lists of articles.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class ArticlesModel extends ListModel
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $config An optional associative array of configuration settings.
|
||||
*
|
||||
* @see \JController
|
||||
* @since 1.6
|
||||
*/
|
||||
public function __construct($config = [])
|
||||
{
|
||||
if (empty($config['filter_fields'])) {
|
||||
$config['filter_fields'] = [
|
||||
'id', 'a.id',
|
||||
'title', 'a.title',
|
||||
'alias', 'a.alias',
|
||||
'checked_out', 'a.checked_out',
|
||||
'checked_out_time', 'a.checked_out_time',
|
||||
'catid', 'a.catid', 'category_title',
|
||||
'state', 'a.state',
|
||||
'access', 'a.access', 'access_level',
|
||||
'created', 'a.created',
|
||||
'created_by', 'a.created_by',
|
||||
'ordering', 'a.ordering',
|
||||
'featured', 'a.featured',
|
||||
'language', 'a.language',
|
||||
'hits', 'a.hits',
|
||||
'publish_up', 'a.publish_up',
|
||||
'publish_down', 'a.publish_down',
|
||||
'images', 'a.images',
|
||||
'urls', 'a.urls',
|
||||
'filter_tag',
|
||||
];
|
||||
}
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* This method should only be called once per instantiation and is designed
|
||||
* to be called on the first call to the getState() method unless the model
|
||||
* configuration flag to ignore the request is set.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @param string $ordering An optional ordering field.
|
||||
* @param string $direction An optional direction (asc|desc).
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.0.1
|
||||
*/
|
||||
protected function populateState($ordering = 'ordering', $direction = 'ASC')
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$input = $app->getInput();
|
||||
|
||||
// List state information
|
||||
$value = $input->get('limit', $app->get('list_limit', 0), 'uint');
|
||||
$this->setState('list.limit', $value);
|
||||
|
||||
$value = $input->get('limitstart', 0, 'uint');
|
||||
$this->setState('list.start', $value);
|
||||
|
||||
$value = $input->get('filter_tag', 0, 'uint');
|
||||
$this->setState('filter.tag', $value);
|
||||
|
||||
$orderCol = $input->get('filter_order', 'a.ordering');
|
||||
|
||||
if (!\in_array($orderCol, $this->filter_fields)) {
|
||||
$orderCol = 'a.ordering';
|
||||
}
|
||||
|
||||
$this->setState('list.ordering', $orderCol);
|
||||
|
||||
$listOrder = $input->get('filter_order_Dir', 'ASC');
|
||||
|
||||
if (!\in_array(strtoupper($listOrder), ['ASC', 'DESC', ''])) {
|
||||
$listOrder = 'ASC';
|
||||
}
|
||||
|
||||
$this->setState('list.direction', $listOrder);
|
||||
|
||||
$params = $app->getParams();
|
||||
$this->setState('params', $params);
|
||||
|
||||
$user = $this->getCurrentUser();
|
||||
|
||||
if ((!$user->authorise('core.edit.state', 'com_content')) && (!$user->authorise('core.edit', 'com_content'))) {
|
||||
// Filter on published for those who do not have edit or edit.state rights.
|
||||
$this->setState('filter.published', ContentComponent::CONDITION_PUBLISHED);
|
||||
}
|
||||
|
||||
$this->setState('filter.language', Multilanguage::isEnabled());
|
||||
|
||||
// Process show_noauth parameter
|
||||
if ((!$params->get('show_noauth')) || (!ComponentHelper::getParams('com_content')->get('show_noauth'))) {
|
||||
$this->setState('filter.access', true);
|
||||
} else {
|
||||
$this->setState('filter.access', false);
|
||||
}
|
||||
|
||||
$this->setState('layout', $input->getString('layout'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a store id based on model configuration state.
|
||||
*
|
||||
* This is necessary because the model is used by the component and
|
||||
* different modules that might need different sets of data or different
|
||||
* ordering requirements.
|
||||
*
|
||||
* @param string $id A prefix for the store id.
|
||||
*
|
||||
* @return string A store id.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getStoreId($id = '')
|
||||
{
|
||||
// Compile the store id.
|
||||
$id .= ':' . serialize($this->getState('filter.published'));
|
||||
$id .= ':' . $this->getState('filter.access');
|
||||
$id .= ':' . $this->getState('filter.featured');
|
||||
$id .= ':' . serialize($this->getState('filter.article_id'));
|
||||
$id .= ':' . $this->getState('filter.article_id.include');
|
||||
$id .= ':' . serialize($this->getState('filter.category_id'));
|
||||
$id .= ':' . $this->getState('filter.category_id.include');
|
||||
$id .= ':' . serialize($this->getState('filter.author_id'));
|
||||
$id .= ':' . $this->getState('filter.author_id.include');
|
||||
$id .= ':' . serialize($this->getState('filter.author_alias'));
|
||||
$id .= ':' . $this->getState('filter.author_alias.include');
|
||||
$id .= ':' . $this->getState('filter.date_filtering');
|
||||
$id .= ':' . $this->getState('filter.date_field');
|
||||
$id .= ':' . $this->getState('filter.start_date_range');
|
||||
$id .= ':' . $this->getState('filter.end_date_range');
|
||||
$id .= ':' . $this->getState('filter.relative_date');
|
||||
$id .= ':' . serialize($this->getState('filter.tag'));
|
||||
|
||||
return parent::getStoreId($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the master query for retrieving a list of articles subject to the model state.
|
||||
*
|
||||
* @return QueryInterface
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getListQuery()
|
||||
{
|
||||
$user = $this->getCurrentUser();
|
||||
|
||||
// Create a new query object.
|
||||
$db = $this->getDatabase();
|
||||
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
$nowDate = Factory::getDate()->toSql();
|
||||
|
||||
$conditionArchived = ContentComponent::CONDITION_ARCHIVED;
|
||||
$conditionUnpublished = ContentComponent::CONDITION_UNPUBLISHED;
|
||||
|
||||
// Select the required fields from the table.
|
||||
$query->select(
|
||||
$this->getState(
|
||||
'list.select',
|
||||
[
|
||||
$db->quoteName('a.id'),
|
||||
$db->quoteName('a.title'),
|
||||
$db->quoteName('a.alias'),
|
||||
$db->quoteName('a.introtext'),
|
||||
$db->quoteName('a.fulltext'),
|
||||
$db->quoteName('a.checked_out'),
|
||||
$db->quoteName('a.checked_out_time'),
|
||||
$db->quoteName('a.catid'),
|
||||
$db->quoteName('a.created'),
|
||||
$db->quoteName('a.created_by'),
|
||||
$db->quoteName('a.created_by_alias'),
|
||||
$db->quoteName('a.modified'),
|
||||
$db->quoteName('a.modified_by'),
|
||||
// Use created if publish_up is null
|
||||
'CASE WHEN ' . $db->quoteName('a.publish_up') . ' IS NULL THEN ' . $db->quoteName('a.created')
|
||||
. ' ELSE ' . $db->quoteName('a.publish_up') . ' END AS ' . $db->quoteName('publish_up'),
|
||||
$db->quoteName('a.publish_down'),
|
||||
$db->quoteName('a.images'),
|
||||
$db->quoteName('a.urls'),
|
||||
$db->quoteName('a.attribs'),
|
||||
$db->quoteName('a.metadata'),
|
||||
$db->quoteName('a.metakey'),
|
||||
$db->quoteName('a.metadesc'),
|
||||
$db->quoteName('a.access'),
|
||||
$db->quoteName('a.hits'),
|
||||
$db->quoteName('a.featured'),
|
||||
$db->quoteName('a.language'),
|
||||
$query->length($db->quoteName('a.fulltext')) . ' AS ' . $db->quoteName('readmore'),
|
||||
$db->quoteName('a.ordering'),
|
||||
]
|
||||
)
|
||||
)
|
||||
->select(
|
||||
[
|
||||
$db->quoteName('fp.featured_up'),
|
||||
$db->quoteName('fp.featured_down'),
|
||||
// Published/archived article in archived category is treated as archived article. If category is not published then force 0.
|
||||
'CASE WHEN ' . $db->quoteName('c.published') . ' = 2 AND ' . $db->quoteName('a.state') . ' > 0 THEN ' . $conditionArchived
|
||||
. ' WHEN ' . $db->quoteName('c.published') . ' != 1 THEN ' . $conditionUnpublished
|
||||
. ' ELSE ' . $db->quoteName('a.state') . ' END AS ' . $db->quoteName('state'),
|
||||
$db->quoteName('c.title', 'category_title'),
|
||||
$db->quoteName('c.path', 'category_route'),
|
||||
$db->quoteName('c.access', 'category_access'),
|
||||
$db->quoteName('c.alias', 'category_alias'),
|
||||
$db->quoteName('c.language', 'category_language'),
|
||||
$db->quoteName('c.published'),
|
||||
$db->quoteName('c.published', 'parents_published'),
|
||||
$db->quoteName('c.lft'),
|
||||
'CASE WHEN ' . $db->quoteName('a.created_by_alias') . ' > ' . $db->quote(' ') . ' THEN ' . $db->quoteName('a.created_by_alias')
|
||||
. ' ELSE ' . $db->quoteName('ua.name') . ' END AS ' . $db->quoteName('author'),
|
||||
$db->quoteName('ua.email', 'author_email'),
|
||||
$db->quoteName('uam.name', 'modified_by_name'),
|
||||
$db->quoteName('parent.title', 'parent_title'),
|
||||
$db->quoteName('parent.id', 'parent_id'),
|
||||
$db->quoteName('parent.path', 'parent_route'),
|
||||
$db->quoteName('parent.alias', 'parent_alias'),
|
||||
$db->quoteName('parent.language', 'parent_language'),
|
||||
]
|
||||
)
|
||||
->from($db->quoteName('#__content', 'a'))
|
||||
->join('LEFT', $db->quoteName('#__categories', 'c'), $db->quoteName('c.id') . ' = ' . $db->quoteName('a.catid'))
|
||||
->join('LEFT', $db->quoteName('#__users', 'ua'), $db->quoteName('ua.id') . ' = ' . $db->quoteName('a.created_by'))
|
||||
->join('LEFT', $db->quoteName('#__users', 'uam'), $db->quoteName('uam.id') . ' = ' . $db->quoteName('a.modified_by'))
|
||||
->join('LEFT', $db->quoteName('#__categories', 'parent'), $db->quoteName('parent.id') . ' = ' . $db->quoteName('c.parent_id'));
|
||||
|
||||
$params = $this->getState('params');
|
||||
$orderby_sec = $params->get('orderby_sec');
|
||||
|
||||
// Join over the frontpage articles if required.
|
||||
$frontpageJoin = 'LEFT';
|
||||
|
||||
if ($this->getState('filter.frontpage')) {
|
||||
if ($orderby_sec === 'front') {
|
||||
$query->select($db->quoteName('fp.ordering'));
|
||||
$frontpageJoin = 'INNER';
|
||||
} else {
|
||||
$query->where($db->quoteName('a.featured') . ' = 1');
|
||||
}
|
||||
|
||||
$query->where(
|
||||
[
|
||||
'(' . $db->quoteName('fp.featured_up') . ' IS NULL OR ' . $db->quoteName('fp.featured_up') . ' <= :frontpageUp)',
|
||||
'(' . $db->quoteName('fp.featured_down') . ' IS NULL OR ' . $db->quoteName('fp.featured_down') . ' >= :frontpageDown)',
|
||||
]
|
||||
)
|
||||
->bind(':frontpageUp', $nowDate)
|
||||
->bind(':frontpageDown', $nowDate);
|
||||
} elseif ($orderby_sec === 'front' || $this->getState('list.ordering') === 'fp.ordering') {
|
||||
$query->select($db->quoteName('fp.ordering'));
|
||||
}
|
||||
|
||||
$query->join($frontpageJoin, $db->quoteName('#__content_frontpage', 'fp'), $db->quoteName('fp.content_id') . ' = ' . $db->quoteName('a.id'));
|
||||
|
||||
if (PluginHelper::isEnabled('content', 'vote')) {
|
||||
// Join on voting table
|
||||
$query->select(
|
||||
[
|
||||
'COALESCE(NULLIF(ROUND(' . $db->quoteName('v.rating_sum') . ' / ' . $db->quoteName('v.rating_count') . ', 1), 0), 0)'
|
||||
. ' AS ' . $db->quoteName('rating'),
|
||||
'COALESCE(NULLIF(' . $db->quoteName('v.rating_count') . ', 0), 0) AS ' . $db->quoteName('rating_count'),
|
||||
]
|
||||
)
|
||||
->join('LEFT', $db->quoteName('#__content_rating', 'v'), $db->quoteName('a.id') . ' = ' . $db->quoteName('v.content_id'));
|
||||
}
|
||||
|
||||
// Filter by access level.
|
||||
if ($this->getState('filter.access', true)) {
|
||||
$groups = $this->getState('filter.viewlevels', $user->getAuthorisedViewLevels());
|
||||
$query->whereIn($db->quoteName('a.access'), $groups)
|
||||
->whereIn($db->quoteName('c.access'), $groups);
|
||||
}
|
||||
|
||||
// Filter by published state
|
||||
$condition = $this->getState('filter.published');
|
||||
|
||||
if (is_numeric($condition) && $condition == 2) {
|
||||
/**
|
||||
* If category is archived then article has to be published or archived.
|
||||
* Or category is published then article has to be archived.
|
||||
*/
|
||||
$query->where('((' . $db->quoteName('c.published') . ' = 2 AND ' . $db->quoteName('a.state') . ' > :conditionUnpublished)'
|
||||
. ' OR (' . $db->quoteName('c.published') . ' = 1 AND ' . $db->quoteName('a.state') . ' = :conditionArchived))')
|
||||
->bind(':conditionUnpublished', $conditionUnpublished, ParameterType::INTEGER)
|
||||
->bind(':conditionArchived', $conditionArchived, ParameterType::INTEGER);
|
||||
} elseif (is_numeric($condition)) {
|
||||
$condition = (int) $condition;
|
||||
|
||||
// Category has to be published
|
||||
$query->where($db->quoteName('c.published') . ' = 1 AND ' . $db->quoteName('a.state') . ' = :condition')
|
||||
->bind(':condition', $condition, ParameterType::INTEGER);
|
||||
} elseif (\is_array($condition)) {
|
||||
// Category has to be published
|
||||
$query->where(
|
||||
$db->quoteName('c.published') . ' = 1 AND ' . $db->quoteName('a.state')
|
||||
. ' IN (' . implode(',', $query->bindArray($condition)) . ')'
|
||||
);
|
||||
}
|
||||
|
||||
// Filter by featured state
|
||||
$featured = $this->getState('filter.featured');
|
||||
|
||||
switch ($featured) {
|
||||
case 'hide':
|
||||
$query->extendWhere(
|
||||
'AND',
|
||||
[
|
||||
$db->quoteName('a.featured') . ' = 0',
|
||||
'(' . $db->quoteName('fp.featured_up') . ' IS NOT NULL AND ' . $db->quoteName('fp.featured_up') . ' >= :featuredUp)',
|
||||
'(' . $db->quoteName('fp.featured_down') . ' IS NOT NULL AND ' . $db->quoteName('fp.featured_down') . ' <= :featuredDown)',
|
||||
],
|
||||
'OR'
|
||||
)
|
||||
->bind(':featuredUp', $nowDate)
|
||||
->bind(':featuredDown', $nowDate);
|
||||
break;
|
||||
|
||||
case 'only':
|
||||
$query->where(
|
||||
[
|
||||
$db->quoteName('a.featured') . ' = 1',
|
||||
'(' . $db->quoteName('fp.featured_up') . ' IS NULL OR ' . $db->quoteName('fp.featured_up') . ' <= :featuredUp)',
|
||||
'(' . $db->quoteName('fp.featured_down') . ' IS NULL OR ' . $db->quoteName('fp.featured_down') . ' >= :featuredDown)',
|
||||
]
|
||||
)
|
||||
->bind(':featuredUp', $nowDate)
|
||||
->bind(':featuredDown', $nowDate);
|
||||
break;
|
||||
|
||||
case 'show':
|
||||
default:
|
||||
// Normally we do not discriminate between featured/unfeatured items.
|
||||
break;
|
||||
}
|
||||
|
||||
// Filter by a single or group of articles.
|
||||
$articleId = $this->getState('filter.article_id');
|
||||
|
||||
if (is_numeric($articleId)) {
|
||||
$articleId = (int) $articleId;
|
||||
$type = $this->getState('filter.article_id.include', true) ? ' = ' : ' <> ';
|
||||
$query->where($db->quoteName('a.id') . $type . ':articleId')
|
||||
->bind(':articleId', $articleId, ParameterType::INTEGER);
|
||||
} elseif (\is_array($articleId)) {
|
||||
$articleId = ArrayHelper::toInteger($articleId);
|
||||
|
||||
if ($this->getState('filter.article_id.include', true)) {
|
||||
$query->whereIn($db->quoteName('a.id'), $articleId);
|
||||
} else {
|
||||
$query->whereNotIn($db->quoteName('a.id'), $articleId);
|
||||
}
|
||||
}
|
||||
|
||||
// Filter by a single or group of categories
|
||||
$categoryId = $this->getState('filter.category_id');
|
||||
|
||||
if (is_numeric($categoryId)) {
|
||||
$type = $this->getState('filter.category_id.include', true) ? ' = ' : ' <> ';
|
||||
|
||||
// Add subcategory check
|
||||
$includeSubcategories = $this->getState('filter.subcategories', false);
|
||||
|
||||
if ($includeSubcategories) {
|
||||
$categoryId = (int) $categoryId;
|
||||
$levels = (int) $this->getState('filter.max_category_levels', 1);
|
||||
|
||||
// Create a subquery for the subcategory list
|
||||
$subQuery = $db->getQuery(true)
|
||||
->select($db->quoteName('sub.id'))
|
||||
->from($db->quoteName('#__categories', 'sub'))
|
||||
->join(
|
||||
'INNER',
|
||||
$db->quoteName('#__categories', 'this'),
|
||||
$db->quoteName('sub.lft') . ' > ' . $db->quoteName('this.lft')
|
||||
. ' AND ' . $db->quoteName('sub.rgt') . ' < ' . $db->quoteName('this.rgt')
|
||||
)
|
||||
->where($db->quoteName('this.id') . ' = :subCategoryId');
|
||||
|
||||
$query->bind(':subCategoryId', $categoryId, ParameterType::INTEGER);
|
||||
|
||||
if ($levels >= 0) {
|
||||
$subQuery->where($db->quoteName('sub.level') . ' <= ' . $db->quoteName('this.level') . ' + :levels');
|
||||
$query->bind(':levels', $levels, ParameterType::INTEGER);
|
||||
}
|
||||
|
||||
// Add the subquery to the main query
|
||||
$query->where(
|
||||
'(' . $db->quoteName('a.catid') . $type . ':categoryId OR ' . $db->quoteName('a.catid') . ' IN (' . $subQuery . '))'
|
||||
);
|
||||
$query->bind(':categoryId', $categoryId, ParameterType::INTEGER);
|
||||
} else {
|
||||
$query->where($db->quoteName('a.catid') . $type . ':categoryId');
|
||||
$query->bind(':categoryId', $categoryId, ParameterType::INTEGER);
|
||||
}
|
||||
} elseif (\is_array($categoryId) && (\count($categoryId) > 0)) {
|
||||
$categoryId = ArrayHelper::toInteger($categoryId);
|
||||
|
||||
if (!empty($categoryId)) {
|
||||
if ($this->getState('filter.category_id.include', true)) {
|
||||
$query->whereIn($db->quoteName('a.catid'), $categoryId);
|
||||
} else {
|
||||
$query->whereNotIn($db->quoteName('a.catid'), $categoryId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter by author
|
||||
$authorId = $this->getState('filter.author_id');
|
||||
$authorWhere = '';
|
||||
|
||||
if (is_numeric($authorId)) {
|
||||
$authorId = (int) $authorId;
|
||||
$type = $this->getState('filter.author_id.include', true) ? ' = ' : ' <> ';
|
||||
$authorWhere = $db->quoteName('a.created_by') . $type . ':authorId';
|
||||
$query->bind(':authorId', $authorId, ParameterType::INTEGER);
|
||||
} elseif (\is_array($authorId)) {
|
||||
$authorId = array_values(array_filter($authorId, 'is_numeric'));
|
||||
|
||||
if ($authorId) {
|
||||
$type = $this->getState('filter.author_id.include', true) ? ' IN' : ' NOT IN';
|
||||
$authorWhere = $db->quoteName('a.created_by') . $type . ' (' . implode(',', $query->bindArray($authorId)) . ')';
|
||||
}
|
||||
}
|
||||
|
||||
// Filter by author alias
|
||||
$authorAlias = $this->getState('filter.author_alias');
|
||||
$authorAliasWhere = '';
|
||||
|
||||
if (\is_string($authorAlias)) {
|
||||
$type = $this->getState('filter.author_alias.include', true) ? ' = ' : ' <> ';
|
||||
$authorAliasWhere = $db->quoteName('a.created_by_alias') . $type . ':authorAlias';
|
||||
$query->bind(':authorAlias', $authorAlias);
|
||||
} elseif (\is_array($authorAlias) && !empty($authorAlias)) {
|
||||
$type = $this->getState('filter.author_alias.include', true) ? ' IN' : ' NOT IN';
|
||||
$authorAliasWhere = $db->quoteName('a.created_by_alias') . $type
|
||||
. ' (' . implode(',', $query->bindArray($authorAlias, ParameterType::STRING)) . ')';
|
||||
}
|
||||
|
||||
if (!empty($authorWhere) && !empty($authorAliasWhere)) {
|
||||
$query->where('(' . $authorWhere . ' OR ' . $authorAliasWhere . ')');
|
||||
} elseif (!empty($authorWhere) || !empty($authorAliasWhere)) {
|
||||
// One of these is empty, the other is not so we just add both
|
||||
$query->where($authorWhere . $authorAliasWhere);
|
||||
}
|
||||
|
||||
// Filter by start and end dates.
|
||||
if (
|
||||
!(is_numeric($condition) && $condition == ContentComponent::CONDITION_UNPUBLISHED)
|
||||
&& !(\is_array($condition) && \in_array(ContentComponent::CONDITION_UNPUBLISHED, $condition))
|
||||
) {
|
||||
$query->where(
|
||||
[
|
||||
'(' . $db->quoteName('a.publish_up') . ' IS NULL OR ' . $db->quoteName('a.publish_up') . ' <= :publishUp)',
|
||||
'(' . $db->quoteName('a.publish_down') . ' IS NULL OR ' . $db->quoteName('a.publish_down') . ' >= :publishDown)',
|
||||
]
|
||||
)
|
||||
->bind(':publishUp', $nowDate)
|
||||
->bind(':publishDown', $nowDate);
|
||||
}
|
||||
|
||||
// Filter by Date Range or Relative Date
|
||||
$dateFiltering = $this->getState('filter.date_filtering', 'off');
|
||||
$dateField = $db->escape($this->getState('filter.date_field', 'a.created'));
|
||||
|
||||
switch ($dateFiltering) {
|
||||
case 'range':
|
||||
$startDateRange = $this->getState('filter.start_date_range', '');
|
||||
$endDateRange = $this->getState('filter.end_date_range', '');
|
||||
|
||||
if ($startDateRange || $endDateRange) {
|
||||
$query->where($db->quoteName($dateField) . ' IS NOT NULL');
|
||||
|
||||
if ($startDateRange) {
|
||||
$query->where($db->quoteName($dateField) . ' >= :startDateRange')
|
||||
->bind(':startDateRange', $startDateRange);
|
||||
}
|
||||
|
||||
if ($endDateRange) {
|
||||
$query->where($db->quoteName($dateField) . ' <= :endDateRange')
|
||||
->bind(':endDateRange', $endDateRange);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'relative':
|
||||
$relativeDate = (int) $this->getState('filter.relative_date', 0);
|
||||
$query->where(
|
||||
$db->quoteName($dateField) . ' IS NOT NULL AND '
|
||||
. $db->quoteName($dateField) . ' >= ' . $query->dateAdd($db->quote($nowDate), -1 * $relativeDate, 'DAY')
|
||||
);
|
||||
break;
|
||||
|
||||
case 'off':
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Process the filter for list views with user-entered filters
|
||||
if (\is_object($params) && ($params->get('filter_field') !== 'hide') && ($filter = $this->getState('list.filter'))) {
|
||||
// Clean filter variable
|
||||
$filter = StringHelper::strtolower($filter);
|
||||
$monthFilter = $filter;
|
||||
$hitsFilter = (int) $filter;
|
||||
$textFilter = '%' . $filter . '%';
|
||||
|
||||
switch ($params->get('filter_field')) {
|
||||
case 'author':
|
||||
$query->where(
|
||||
'LOWER(CASE WHEN ' . $db->quoteName('a.created_by_alias') . ' > ' . $db->quote(' ')
|
||||
. ' THEN ' . $db->quoteName('a.created_by_alias') . ' ELSE ' . $db->quoteName('ua.name') . ' END) LIKE :search'
|
||||
)
|
||||
->bind(':search', $textFilter);
|
||||
break;
|
||||
|
||||
case 'hits':
|
||||
$query->where($db->quoteName('a.hits') . ' >= :hits')
|
||||
->bind(':hits', $hitsFilter, ParameterType::INTEGER);
|
||||
break;
|
||||
|
||||
case 'month':
|
||||
if ($monthFilter != '') {
|
||||
$monthStart = date("Y-m-d", strtotime($monthFilter)) . ' 00:00:00';
|
||||
$monthEnd = date("Y-m-t", strtotime($monthFilter)) . ' 23:59:59';
|
||||
|
||||
$query->where(
|
||||
[
|
||||
':monthStart <= CASE WHEN a.publish_up IS NULL THEN a.created ELSE a.publish_up END',
|
||||
':monthEnd >= CASE WHEN a.publish_up IS NULL THEN a.created ELSE a.publish_up END',
|
||||
]
|
||||
)
|
||||
->bind(':monthStart', $monthStart)
|
||||
->bind(':monthEnd', $monthEnd);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'title':
|
||||
default:
|
||||
// Default to 'title' if parameter is not valid
|
||||
$query->where('LOWER(' . $db->quoteName('a.title') . ') LIKE :search')
|
||||
->bind(':search', $textFilter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter by language
|
||||
if ($this->getState('filter.language')) {
|
||||
$query->whereIn($db->quoteName('a.language'), [Factory::getApplication()->getLanguage()->getTag(), '*'], ParameterType::STRING);
|
||||
}
|
||||
|
||||
// Filter by a single or group of tags.
|
||||
$tagId = $this->getState('filter.tag');
|
||||
|
||||
if (\is_array($tagId) && \count($tagId) === 1) {
|
||||
$tagId = current($tagId);
|
||||
}
|
||||
|
||||
if (\is_array($tagId)) {
|
||||
$tagId = ArrayHelper::toInteger($tagId);
|
||||
|
||||
if ($tagId) {
|
||||
$subQuery = $db->getQuery(true)
|
||||
->select('DISTINCT ' . $db->quoteName('content_item_id'))
|
||||
->from($db->quoteName('#__contentitem_tag_map'))
|
||||
->where(
|
||||
[
|
||||
$db->quoteName('tag_id') . ' IN (' . implode(',', $query->bindArray($tagId)) . ')',
|
||||
$db->quoteName('type_alias') . ' = ' . $db->quote('com_content.article'),
|
||||
]
|
||||
);
|
||||
|
||||
$query->join(
|
||||
'INNER',
|
||||
'(' . $subQuery . ') AS ' . $db->quoteName('tagmap'),
|
||||
$db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
|
||||
);
|
||||
}
|
||||
} elseif ($tagId = (int) $tagId) {
|
||||
$query->join(
|
||||
'INNER',
|
||||
$db->quoteName('#__contentitem_tag_map', 'tagmap'),
|
||||
$db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
|
||||
. ' AND ' . $db->quoteName('tagmap.type_alias') . ' = ' . $db->quote('com_content.article')
|
||||
)
|
||||
->where($db->quoteName('tagmap.tag_id') . ' = :tagId')
|
||||
->bind(':tagId', $tagId, ParameterType::INTEGER);
|
||||
}
|
||||
|
||||
// Add the list ordering clause.
|
||||
$query->order(
|
||||
$db->escape($this->getState('list.ordering', 'a.ordering')) . ' ' . $db->escape($this->getState('list.direction', 'ASC'))
|
||||
);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a list of articles.
|
||||
*
|
||||
* Overridden to inject convert the attribs field into a Registry object.
|
||||
*
|
||||
* @return mixed An array of objects on success, false on failure.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getItems()
|
||||
{
|
||||
$items = parent::getItems();
|
||||
|
||||
$user = $this->getCurrentUser();
|
||||
$userId = $user->id;
|
||||
$guest = $user->guest;
|
||||
$groups = $user->getAuthorisedViewLevels();
|
||||
$input = Factory::getApplication()->getInput();
|
||||
|
||||
// Get the global params
|
||||
$globalParams = ComponentHelper::getParams('com_content', true);
|
||||
|
||||
$taggedItems = [];
|
||||
|
||||
// Convert the parameter fields into objects.
|
||||
foreach ($items as $item) {
|
||||
$articleParams = new Registry($item->attribs);
|
||||
|
||||
// Unpack readmore and layout params
|
||||
$item->alternative_readmore = $articleParams->get('alternative_readmore');
|
||||
$item->layout = $articleParams->get('layout');
|
||||
|
||||
$item->params = clone $this->getState('params');
|
||||
|
||||
/**
|
||||
* For blogs, article params override menu item params only if menu param = 'use_article'
|
||||
* Otherwise, menu item params control the layout
|
||||
* If menu item is 'use_article' and there is no article param, use global
|
||||
*/
|
||||
if (
|
||||
($input->getString('layout') === 'blog') || ($input->getString('view') === 'featured')
|
||||
|| ($this->getState('params')->get('layout_type') === 'blog')
|
||||
) {
|
||||
// Create an array of just the params set to 'use_article'
|
||||
$menuParamsArray = $this->getState('params')->toArray();
|
||||
$articleArray = [];
|
||||
|
||||
foreach ($menuParamsArray as $key => $value) {
|
||||
if ($value === 'use_article') {
|
||||
// If the article has a value, use it
|
||||
if ($articleParams->get($key) != '') {
|
||||
// Get the value from the article
|
||||
$articleArray[$key] = $articleParams->get($key);
|
||||
} else {
|
||||
// Otherwise, use the global value
|
||||
$articleArray[$key] = $globalParams->get($key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Merge the selected article params
|
||||
if (\count($articleArray) > 0) {
|
||||
$articleParams = new Registry($articleArray);
|
||||
$item->params->merge($articleParams);
|
||||
}
|
||||
} else {
|
||||
// For non-blog layouts, merge all of the article params
|
||||
$item->params->merge($articleParams);
|
||||
}
|
||||
|
||||
// Get display date
|
||||
switch ($item->params->get('list_show_date')) {
|
||||
case 'modified':
|
||||
$item->displayDate = $item->modified;
|
||||
break;
|
||||
|
||||
case 'published':
|
||||
$item->displayDate = ($item->publish_up == 0) ? $item->created : $item->publish_up;
|
||||
break;
|
||||
|
||||
default:
|
||||
case 'created':
|
||||
$item->displayDate = $item->created;
|
||||
break;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the asset access permissions.
|
||||
* Technically guest could edit an article, but lets not check that to improve performance a little.
|
||||
*/
|
||||
if (!$guest) {
|
||||
$asset = 'com_content.article.' . $item->id;
|
||||
|
||||
// Check general edit permission first.
|
||||
if ($user->authorise('core.edit', $asset)) {
|
||||
$item->params->set('access-edit', true);
|
||||
} elseif (!empty($userId) && $user->authorise('core.edit.own', $asset)) {
|
||||
// Now check if edit.own is available.
|
||||
// Check for a valid user and that they are the owner.
|
||||
if ($userId == $item->created_by) {
|
||||
$item->params->set('access-edit', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$access = $this->getState('filter.access');
|
||||
|
||||
if ($access) {
|
||||
// If the access filter has been set, we already have only the articles this user can view.
|
||||
$item->params->set('access-view', true);
|
||||
} else {
|
||||
// If no access filter is set, the layout takes some responsibility for display of limited information.
|
||||
if ($item->catid == 0 || $item->category_access === null) {
|
||||
$item->params->set('access-view', \in_array($item->access, $groups));
|
||||
} else {
|
||||
$item->params->set('access-view', \in_array($item->access, $groups) && \in_array($item->category_access, $groups));
|
||||
}
|
||||
}
|
||||
|
||||
// Some contexts may not use tags data at all, so we allow callers to disable loading tag data
|
||||
if ($this->getState('load_tags', $item->params->get('show_tags', '1'))) {
|
||||
$item->tags = new TagsHelper();
|
||||
$taggedItems[$item->id] = $item;
|
||||
}
|
||||
|
||||
if (Associations::isEnabled() && $item->params->get('show_associations')) {
|
||||
$item->associations = AssociationHelper::displayAssociations($item->id);
|
||||
}
|
||||
}
|
||||
|
||||
// Load tags of all items.
|
||||
if ($taggedItems) {
|
||||
$tagsHelper = new TagsHelper();
|
||||
$itemIds = array_keys($taggedItems);
|
||||
|
||||
foreach ($tagsHelper->getMultipleItemTags('com_content.article', $itemIds) as $id => $tags) {
|
||||
$taggedItems[$id]->tags->itemTags = $tags;
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the starting number of items for the data set.
|
||||
*
|
||||
* @return integer The starting number of items available in the data set.
|
||||
*
|
||||
* @since 3.0.1
|
||||
*/
|
||||
public function getStart()
|
||||
{
|
||||
return $this->getState('list.start');
|
||||
}
|
||||
|
||||
/**
|
||||
* Count Items by Month
|
||||
*
|
||||
* @return mixed An array of objects on success, false on failure.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*/
|
||||
public function countItemsByMonth()
|
||||
{
|
||||
// Create a new query object.
|
||||
$db = $this->getDatabase();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// Get the list query.
|
||||
$listQuery = $this->getListQuery();
|
||||
$bounded = $listQuery->getBounded();
|
||||
|
||||
// Bind list query variables to our new query.
|
||||
$keys = array_keys($bounded);
|
||||
$values = array_column($bounded, 'value');
|
||||
$dataTypes = array_column($bounded, 'dataType');
|
||||
|
||||
$query->bind($keys, $values, $dataTypes);
|
||||
|
||||
$query
|
||||
->select(
|
||||
'DATE(' .
|
||||
$query->concatenate(
|
||||
[
|
||||
$query->year($db->quoteName('publish_up')),
|
||||
$db->quote('-'),
|
||||
$query->month($db->quoteName('publish_up')),
|
||||
$db->quote('-01'),
|
||||
]
|
||||
) . ') AS ' . $db->quoteName('d')
|
||||
)
|
||||
->select('COUNT(*) AS ' . $db->quoteName('c'))
|
||||
->from('(' . $this->getListQuery() . ') AS ' . $db->quoteName('b'))
|
||||
->group($db->quoteName('d'))
|
||||
->order($db->quoteName('d') . ' DESC');
|
||||
|
||||
return $db->setQuery($query)->loadObjectList();
|
||||
}
|
||||
}
|
||||
155
components/com_content/src/Model/CategoriesModel.php
Normal file
155
components/com_content/src/Model/CategoriesModel.php
Normal file
@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Content\Site\Model;
|
||||
|
||||
use Joomla\CMS\Categories\Categories;
|
||||
use Joomla\CMS\Categories\CategoryNode;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\MVC\Model\ListModel;
|
||||
use Joomla\Registry\Registry;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* This models supports retrieving lists of article categories.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class CategoriesModel extends ListModel
|
||||
{
|
||||
/**
|
||||
* Model context string.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $_context = 'com_content.categories';
|
||||
|
||||
/**
|
||||
* The category context (allows other extensions to derived from this model).
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_extension = 'com_content';
|
||||
|
||||
/**
|
||||
* Parent category of the current one
|
||||
*
|
||||
* @var CategoryNode|null
|
||||
*/
|
||||
private $_parent = null;
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @param string $ordering The field to order on.
|
||||
* @param string $direction The direction to order on.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function populateState($ordering = null, $direction = null)
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$this->setState('filter.extension', $this->_extension);
|
||||
|
||||
// Get the parent id if defined.
|
||||
$parentId = $app->getInput()->getInt('id');
|
||||
$this->setState('filter.parentId', $parentId);
|
||||
|
||||
$params = $app->getParams();
|
||||
$this->setState('params', $params);
|
||||
|
||||
$this->setState('filter.published', 1);
|
||||
$this->setState('filter.access', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a store id based on model configuration state.
|
||||
*
|
||||
* This is necessary because the model is used by the component and
|
||||
* different modules that might need different sets of data or different
|
||||
* ordering requirements.
|
||||
*
|
||||
* @param string $id A prefix for the store id.
|
||||
*
|
||||
* @return string A store id.
|
||||
*/
|
||||
protected function getStoreId($id = '')
|
||||
{
|
||||
// Compile the store id.
|
||||
$id .= ':' . $this->getState('filter.extension');
|
||||
$id .= ':' . $this->getState('filter.published');
|
||||
$id .= ':' . $this->getState('filter.access');
|
||||
$id .= ':' . $this->getState('filter.parentId');
|
||||
|
||||
return parent::getStoreId($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redefine the function and add some properties to make the styling easier
|
||||
*
|
||||
* @param bool $recursive True if you want to return children recursively.
|
||||
*
|
||||
* @return mixed An array of data items on success, false on failure.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getItems($recursive = false)
|
||||
{
|
||||
$store = $this->getStoreId();
|
||||
|
||||
if (!isset($this->cache[$store])) {
|
||||
$app = Factory::getApplication();
|
||||
$menu = $app->getMenu();
|
||||
$active = $menu->getActive();
|
||||
|
||||
if ($active) {
|
||||
$params = $active->getParams();
|
||||
} else {
|
||||
$params = new Registry();
|
||||
}
|
||||
|
||||
$options = [];
|
||||
$options['countItems'] = $params->get('show_cat_num_articles_cat', 1) || !$params->get('show_empty_categories_cat', 0);
|
||||
$categories = Categories::getInstance('Content', $options);
|
||||
$this->_parent = $categories->get($this->getState('filter.parentId', 'root'));
|
||||
|
||||
if (\is_object($this->_parent)) {
|
||||
$this->cache[$store] = $this->_parent->getChildren($recursive);
|
||||
} else {
|
||||
$this->cache[$store] = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->cache[$store];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parent.
|
||||
*
|
||||
* @return object An array of data items on success, false on failure.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
if (!\is_object($this->_parent)) {
|
||||
$this->getItems();
|
||||
}
|
||||
|
||||
return $this->_parent;
|
||||
}
|
||||
}
|
||||
473
components/com_content/src/Model/CategoryModel.php
Normal file
473
components/com_content/src/Model/CategoryModel.php
Normal file
@ -0,0 +1,473 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Content\Site\Model;
|
||||
|
||||
use Joomla\CMS\Categories\Categories;
|
||||
use Joomla\CMS\Categories\CategoryNode;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Multilanguage;
|
||||
use Joomla\CMS\MVC\Model\ListModel;
|
||||
use Joomla\CMS\Table\Table;
|
||||
use Joomla\Component\Content\Site\Helper\QueryHelper;
|
||||
use Joomla\Utilities\ArrayHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* This models supports retrieving a category, the articles associated with the category,
|
||||
* sibling, child and parent categories.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class CategoryModel extends ListModel
|
||||
{
|
||||
/**
|
||||
* Category items data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_item = null;
|
||||
|
||||
/**
|
||||
* Array of articles in the category
|
||||
*
|
||||
* @var \stdClass[]
|
||||
*/
|
||||
protected $_articles = null;
|
||||
|
||||
/**
|
||||
* Category left and right of this one
|
||||
*
|
||||
* @var CategoryNode[]|null
|
||||
*/
|
||||
protected $_siblings = null;
|
||||
|
||||
/**
|
||||
* Array of child-categories
|
||||
*
|
||||
* @var CategoryNode[]|null
|
||||
*/
|
||||
protected $_children = null;
|
||||
|
||||
/**
|
||||
* Parent category of the current one
|
||||
*
|
||||
* @var CategoryNode|null
|
||||
*/
|
||||
protected $_parent = null;
|
||||
|
||||
/**
|
||||
* Model context string.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_context = 'com_content.category';
|
||||
|
||||
/**
|
||||
* The category that applies.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $_category = null;
|
||||
|
||||
/**
|
||||
* The list of categories.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_categories = null;
|
||||
|
||||
/**
|
||||
* @param array $config An optional associative array of configuration settings.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function __construct($config = [])
|
||||
{
|
||||
if (empty($config['filter_fields'])) {
|
||||
$config['filter_fields'] = [
|
||||
'id', 'a.id',
|
||||
'title', 'a.title',
|
||||
'alias', 'a.alias',
|
||||
'checked_out', 'a.checked_out',
|
||||
'checked_out_time', 'a.checked_out_time',
|
||||
'catid', 'a.catid', 'category_title',
|
||||
'state', 'a.state',
|
||||
'access', 'a.access', 'access_level',
|
||||
'created', 'a.created',
|
||||
'created_by', 'a.created_by',
|
||||
'modified', 'a.modified',
|
||||
'ordering', 'a.ordering',
|
||||
'featured', 'a.featured',
|
||||
'language', 'a.language',
|
||||
'hits', 'a.hits',
|
||||
'publish_up', 'a.publish_up',
|
||||
'publish_down', 'a.publish_down',
|
||||
'author', 'a.author',
|
||||
'filter_tag',
|
||||
];
|
||||
}
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @param string $ordering The field to order on.
|
||||
* @param string $direction The direction to order on.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function populateState($ordering = null, $direction = null)
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
|
||||
$pk = $app->getInput()->getInt('id');
|
||||
$this->setState('category.id', $pk);
|
||||
|
||||
// Load the parameters. Merge Global and Menu Item params into new object
|
||||
$params = $app->getParams();
|
||||
$this->setState('params', $params);
|
||||
|
||||
$user = $this->getCurrentUser();
|
||||
$asset = 'com_content';
|
||||
|
||||
if ($pk) {
|
||||
$asset .= '.category.' . $pk;
|
||||
}
|
||||
|
||||
if ((!$user->authorise('core.edit.state', $asset)) && (!$user->authorise('core.edit', $asset))) {
|
||||
// Limit to published for people who can't edit or edit.state.
|
||||
$this->setState('filter.published', 1);
|
||||
} else {
|
||||
$this->setState('filter.published', [0, 1]);
|
||||
}
|
||||
|
||||
// Process show_noauth parameter
|
||||
if (!$params->get('show_noauth')) {
|
||||
$this->setState('filter.access', true);
|
||||
} else {
|
||||
$this->setState('filter.access', false);
|
||||
}
|
||||
|
||||
$itemid = $app->getInput()->get('id', 0, 'int') . ':' . $app->getInput()->get('Itemid', 0, 'int');
|
||||
|
||||
$value = $this->getUserStateFromRequest('com_content.category.filter.' . $itemid . '.tag', 'filter_tag', 0, 'int', false);
|
||||
$this->setState('filter.tag', $value);
|
||||
|
||||
// Optional filter text
|
||||
$search = $app->getUserStateFromRequest('com_content.category.list.' . $itemid . '.filter-search', 'filter-search', '', 'string');
|
||||
$this->setState('list.filter', $search);
|
||||
|
||||
// Filter.order
|
||||
$orderCol = $app->getUserStateFromRequest('com_content.category.list.' . $itemid . '.filter_order', 'filter_order', '', 'string');
|
||||
|
||||
if (!\in_array($orderCol, $this->filter_fields)) {
|
||||
$orderCol = 'a.ordering';
|
||||
}
|
||||
|
||||
$this->setState('list.ordering', $orderCol);
|
||||
|
||||
$listOrder = $app->getUserStateFromRequest('com_content.category.list.' . $itemid . '.filter_order_Dir', 'filter_order_Dir', '', 'cmd');
|
||||
|
||||
if (!\in_array(strtoupper($listOrder), ['ASC', 'DESC', ''])) {
|
||||
$listOrder = 'ASC';
|
||||
}
|
||||
|
||||
$this->setState('list.direction', $listOrder);
|
||||
|
||||
$this->setState('list.start', $app->getInput()->get('limitstart', 0, 'uint'));
|
||||
|
||||
// Set limit for query. If list, use parameter. If blog, add blog parameters for limit.
|
||||
if (($app->getInput()->get('layout') === 'blog') || $params->get('layout_type') === 'blog') {
|
||||
$limit = $params->get('num_leading_articles') + $params->get('num_intro_articles') + $params->get('num_links');
|
||||
$this->setState('list.links', $params->get('num_links'));
|
||||
} else {
|
||||
$limit = $app->getUserStateFromRequest('com_content.category.list.' . $itemid . '.limit', 'limit', $params->get('display_num'), 'uint');
|
||||
}
|
||||
|
||||
$this->setState('list.limit', $limit);
|
||||
|
||||
// Set the depth of the category query based on parameter
|
||||
$showSubcategories = $params->get('show_subcategory_content', '0');
|
||||
|
||||
if ($showSubcategories) {
|
||||
$this->setState('filter.max_category_levels', $params->get('show_subcategory_content', '1'));
|
||||
$this->setState('filter.subcategories', true);
|
||||
}
|
||||
|
||||
$this->setState('filter.language', Multilanguage::isEnabled());
|
||||
|
||||
$this->setState('layout', $app->getInput()->getString('layout'));
|
||||
|
||||
// Set the featured articles state
|
||||
$this->setState('filter.featured', $params->get('show_featured'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the articles in the category
|
||||
*
|
||||
* @return array|bool An array of articles or false if an error occurs.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public function getItems()
|
||||
{
|
||||
$limit = $this->getState('list.limit');
|
||||
|
||||
if ($this->_articles === null && $category = $this->getCategory()) {
|
||||
$model = $this->bootComponent('com_content')->getMVCFactory()
|
||||
->createModel('Articles', 'Site', ['ignore_request' => true]);
|
||||
$model->setState('params', Factory::getApplication()->getParams());
|
||||
$model->setState('filter.category_id', $category->id);
|
||||
$model->setState('filter.published', $this->getState('filter.published'));
|
||||
$model->setState('filter.access', $this->getState('filter.access'));
|
||||
$model->setState('filter.language', $this->getState('filter.language'));
|
||||
$model->setState('filter.featured', $this->getState('filter.featured'));
|
||||
$model->setState('list.ordering', $this->_buildContentOrderBy());
|
||||
$model->setState('list.start', $this->getState('list.start'));
|
||||
$model->setState('list.limit', $limit);
|
||||
$model->setState('list.direction', $this->getState('list.direction'));
|
||||
$model->setState('list.filter', $this->getState('list.filter'));
|
||||
$model->setState('filter.tag', $this->getState('filter.tag'));
|
||||
|
||||
// Filter.subcategories indicates whether to include articles from subcategories in the list or blog
|
||||
$model->setState('filter.subcategories', $this->getState('filter.subcategories'));
|
||||
$model->setState('filter.max_category_levels', $this->getState('filter.max_category_levels'));
|
||||
$model->setState('list.links', $this->getState('list.links'));
|
||||
|
||||
if ($limit >= 0) {
|
||||
$this->_articles = $model->getItems();
|
||||
|
||||
if ($this->_articles === false) {
|
||||
$this->setError($model->getError());
|
||||
}
|
||||
} else {
|
||||
$this->_articles = [];
|
||||
}
|
||||
|
||||
$this->_pagination = $model->getPagination();
|
||||
}
|
||||
|
||||
return $this->_articles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the orderby for the query
|
||||
*
|
||||
* @return string $orderby portion of query
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
protected function _buildContentOrderBy()
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$db = $this->getDatabase();
|
||||
$params = $this->state->params;
|
||||
$itemid = $app->getInput()->get('id', 0, 'int') . ':' . $app->getInput()->get('Itemid', 0, 'int');
|
||||
$orderCol = $app->getUserStateFromRequest('com_content.category.list.' . $itemid . '.filter_order', 'filter_order', '', 'string');
|
||||
$orderDirn = $app->getUserStateFromRequest('com_content.category.list.' . $itemid . '.filter_order_Dir', 'filter_order_Dir', '', 'cmd');
|
||||
$orderby = ' ';
|
||||
|
||||
if (!\in_array($orderCol, $this->filter_fields)) {
|
||||
$orderCol = null;
|
||||
}
|
||||
|
||||
if (!\in_array(strtoupper($orderDirn), ['ASC', 'DESC', ''])) {
|
||||
$orderDirn = 'ASC';
|
||||
}
|
||||
|
||||
if ($orderCol && $orderDirn) {
|
||||
$orderby .= $db->escape($orderCol) . ' ' . $db->escape($orderDirn) . ', ';
|
||||
}
|
||||
|
||||
$articleOrderby = $params->get('orderby_sec', 'rdate');
|
||||
$articleOrderDate = $params->get('order_date');
|
||||
$categoryOrderby = $params->def('orderby_pri', '');
|
||||
$secondary = QueryHelper::orderbySecondary($articleOrderby, $articleOrderDate, $this->getDatabase()) . ', ';
|
||||
$primary = QueryHelper::orderbyPrimary($categoryOrderby);
|
||||
|
||||
$orderby .= $primary . ' ' . $secondary . ' a.created ';
|
||||
|
||||
return $orderby;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a JPagination object for the data set.
|
||||
*
|
||||
* @return \Joomla\CMS\Pagination\Pagination A JPagination object for the data set.
|
||||
*
|
||||
* @since 3.0.1
|
||||
*/
|
||||
public function getPagination()
|
||||
{
|
||||
if (empty($this->_pagination)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->_pagination;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get category data for the current category
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public function getCategory()
|
||||
{
|
||||
if (!\is_object($this->_item)) {
|
||||
if (isset($this->state->params)) {
|
||||
$params = $this->state->params;
|
||||
$options = [];
|
||||
$options['countItems'] = $params->get('show_cat_num_articles', 1) || !$params->get('show_empty_categories_cat', 0);
|
||||
$options['access'] = $params->get('check_access_rights', 1);
|
||||
} else {
|
||||
$options['countItems'] = 0;
|
||||
}
|
||||
|
||||
$categories = Categories::getInstance('Content', $options);
|
||||
$this->_item = $categories->get($this->getState('category.id', 'root'));
|
||||
|
||||
// Compute selected asset permissions.
|
||||
if (\is_object($this->_item)) {
|
||||
$user = $this->getCurrentUser();
|
||||
$asset = 'com_content.category.' . $this->_item->id;
|
||||
|
||||
// Check general create permission.
|
||||
if ($user->authorise('core.create', $asset)) {
|
||||
$this->_item->getParams()->set('access-create', true);
|
||||
}
|
||||
|
||||
// @todo: Why aren't we lazy loading the children and siblings?
|
||||
$this->_children = $this->_item->getChildren();
|
||||
$this->_parent = false;
|
||||
|
||||
if ($this->_item->getParent()) {
|
||||
$this->_parent = $this->_item->getParent();
|
||||
}
|
||||
|
||||
$this->_rightsibling = $this->_item->getSibling();
|
||||
$this->_leftsibling = $this->_item->getSibling(false);
|
||||
} else {
|
||||
$this->_children = false;
|
||||
$this->_parent = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parent category.
|
||||
*
|
||||
* @return mixed An array of categories or false if an error occurs.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
if (!\is_object($this->_item)) {
|
||||
$this->getCategory();
|
||||
}
|
||||
|
||||
return $this->_parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the left sibling (adjacent) categories.
|
||||
*
|
||||
* @return mixed An array of categories or false if an error occurs.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function &getLeftSibling()
|
||||
{
|
||||
if (!\is_object($this->_item)) {
|
||||
$this->getCategory();
|
||||
}
|
||||
|
||||
return $this->_leftsibling;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the right sibling (adjacent) categories.
|
||||
*
|
||||
* @return mixed An array of categories or false if an error occurs.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function &getRightSibling()
|
||||
{
|
||||
if (!\is_object($this->_item)) {
|
||||
$this->getCategory();
|
||||
}
|
||||
|
||||
return $this->_rightsibling;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the child categories.
|
||||
*
|
||||
* @return mixed An array of categories or false if an error occurs.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function &getChildren()
|
||||
{
|
||||
if (!\is_object($this->_item)) {
|
||||
$this->getCategory();
|
||||
}
|
||||
|
||||
// Order subcategories
|
||||
if ($this->_children) {
|
||||
$params = $this->getState()->get('params');
|
||||
|
||||
$orderByPri = $params->get('orderby_pri');
|
||||
|
||||
if ($orderByPri === 'alpha' || $orderByPri === 'ralpha') {
|
||||
$this->_children = ArrayHelper::sortObjects($this->_children, 'title', ($orderByPri === 'alpha') ? 1 : (-1));
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the hit counter for the category.
|
||||
*
|
||||
* @param int $pk Optional primary key of the category to increment.
|
||||
*
|
||||
* @return boolean True if successful; false otherwise and internal error set.
|
||||
*/
|
||||
public function hit($pk = 0)
|
||||
{
|
||||
$input = Factory::getApplication()->getInput();
|
||||
$hitcount = $input->getInt('hitcount', 1);
|
||||
|
||||
if ($hitcount) {
|
||||
$pk = (!empty($pk)) ? $pk : (int) $this->getState('category.id');
|
||||
|
||||
$table = Table::getInstance('Category', '\\Joomla\\CMS\\Table\\');
|
||||
$table->hit($pk);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
169
components/com_content/src/Model/FeaturedModel.php
Normal file
169
components/com_content/src/Model/FeaturedModel.php
Normal file
@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Content\Site\Model;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\Component\Content\Administrator\Extension\ContentComponent;
|
||||
use Joomla\Component\Content\Site\Helper\QueryHelper;
|
||||
use Joomla\Database\QueryInterface;
|
||||
use Joomla\Registry\Registry;
|
||||
use Joomla\Utilities\ArrayHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Frontpage Component Model
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class FeaturedModel extends ArticlesModel
|
||||
{
|
||||
/**
|
||||
* Model context string.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $_context = 'com_content.frontpage';
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @param string $ordering The field to order on.
|
||||
* @param string $direction The direction to order on.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function populateState($ordering = null, $direction = null)
|
||||
{
|
||||
parent::populateState($ordering, $direction);
|
||||
|
||||
$app = Factory::getApplication();
|
||||
$input = $app->getInput();
|
||||
$user = $app->getIdentity();
|
||||
|
||||
// List state information
|
||||
$limitstart = $input->getUint('limitstart', 0);
|
||||
$this->setState('list.start', $limitstart);
|
||||
|
||||
$params = $this->state->params;
|
||||
|
||||
if ($menu = $app->getMenu()->getActive()) {
|
||||
$menuParams = $menu->getParams();
|
||||
} else {
|
||||
$menuParams = new Registry();
|
||||
}
|
||||
|
||||
$mergedParams = clone $menuParams;
|
||||
$mergedParams->merge($params);
|
||||
|
||||
$this->setState('params', $mergedParams);
|
||||
|
||||
$limit = $params->get('num_leading_articles') + $params->get('num_intro_articles') + $params->get('num_links');
|
||||
$this->setState('list.limit', $limit);
|
||||
$this->setState('list.links', $params->get('num_links'));
|
||||
|
||||
$this->setState('filter.frontpage', true);
|
||||
|
||||
if ((!$user->authorise('core.edit.state', 'com_content')) && (!$user->authorise('core.edit', 'com_content'))) {
|
||||
// Filter on published for those who do not have edit or edit.state rights.
|
||||
$this->setState('filter.published', ContentComponent::CONDITION_PUBLISHED);
|
||||
} else {
|
||||
$this->setState('filter.published', [ContentComponent::CONDITION_UNPUBLISHED, ContentComponent::CONDITION_PUBLISHED]);
|
||||
}
|
||||
|
||||
// Process show_noauth parameter
|
||||
if (!$params->get('show_noauth')) {
|
||||
$this->setState('filter.access', true);
|
||||
} else {
|
||||
$this->setState('filter.access', false);
|
||||
}
|
||||
|
||||
// Check for category selection
|
||||
if ($params->get('featured_categories') && implode(',', $params->get('featured_categories')) == true) {
|
||||
$featuredCategories = $params->get('featured_categories');
|
||||
$this->setState('filter.frontpage.categories', $featuredCategories);
|
||||
}
|
||||
|
||||
$articleOrderby = $params->get('orderby_sec', 'rdate');
|
||||
$articleOrderDate = $params->get('order_date');
|
||||
$categoryOrderby = $params->def('orderby_pri', '');
|
||||
|
||||
$secondary = QueryHelper::orderbySecondary($articleOrderby, $articleOrderDate, $this->getDatabase());
|
||||
$primary = QueryHelper::orderbyPrimary($categoryOrderby);
|
||||
|
||||
$this->setState('list.ordering', $primary . $secondary . ', a.created DESC');
|
||||
$this->setState('list.direction', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a list of articles.
|
||||
*
|
||||
* @return mixed An array of objects on success, false on failure.
|
||||
*/
|
||||
public function getItems()
|
||||
{
|
||||
$params = clone $this->getState('params');
|
||||
$limit = $params->get('num_leading_articles') + $params->get('num_intro_articles') + $params->get('num_links');
|
||||
|
||||
if ($limit > 0) {
|
||||
$this->setState('list.limit', $limit);
|
||||
|
||||
return parent::getItems();
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a store id based on model configuration state.
|
||||
*
|
||||
* This is necessary because the model is used by the component and
|
||||
* different modules that might need different sets of data or different
|
||||
* ordering requirements.
|
||||
*
|
||||
* @param string $id A prefix for the store id.
|
||||
*
|
||||
* @return string A store id.
|
||||
*/
|
||||
protected function getStoreId($id = '')
|
||||
{
|
||||
// Compile the store id.
|
||||
$id .= $this->getState('filter.frontpage');
|
||||
|
||||
return parent::getStoreId($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of items.
|
||||
*
|
||||
* @return QueryInterface
|
||||
*/
|
||||
protected function getListQuery()
|
||||
{
|
||||
// Create a new query object.
|
||||
$query = parent::getListQuery();
|
||||
|
||||
// Filter by categories
|
||||
$featuredCategories = $this->getState('filter.frontpage.categories');
|
||||
|
||||
if (\is_array($featuredCategories) && !\in_array('', $featuredCategories)) {
|
||||
$query->where('a.catid IN (' . implode(',', ArrayHelper::toInteger($featuredCategories)) . ')');
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
336
components/com_content/src/Model/FormModel.php
Normal file
336
components/com_content/src/Model/FormModel.php
Normal file
@ -0,0 +1,336 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Content\Site\Model;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Form\Form;
|
||||
use Joomla\CMS\Helper\TagsHelper;
|
||||
use Joomla\CMS\Language\Associations;
|
||||
use Joomla\CMS\Language\Multilanguage;
|
||||
use Joomla\CMS\Object\CMSObject;
|
||||
use Joomla\CMS\Table\Table;
|
||||
use Joomla\Database\ParameterType;
|
||||
use Joomla\Registry\Registry;
|
||||
use Joomla\Utilities\ArrayHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Content Component Article Model
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class FormModel extends \Joomla\Component\Content\Administrator\Model\ArticleModel
|
||||
{
|
||||
/**
|
||||
* 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 = Factory::getApplication();
|
||||
$input = $app->getInput();
|
||||
|
||||
// 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 = $input->getInt('a_id');
|
||||
$this->setState('article.id', $pk);
|
||||
|
||||
$this->setState('article.catid', $input->getInt('catid', $catId));
|
||||
|
||||
$return = $input->get('return', '', 'base64');
|
||||
$this->setState('return_page', base64_decode($return));
|
||||
|
||||
$this->setState('layout', $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, CMSObject::class);
|
||||
|
||||
// Convert attrib field to Registry.
|
||||
$value->params = new Registry($value->attribs);
|
||||
|
||||
// Compute selected asset permissions.
|
||||
$user = $this->getCurrentUser();
|
||||
$userId = $user->id;
|
||||
$asset = 'com_content.article.' . $value->id;
|
||||
|
||||
// Check general edit permission first.
|
||||
if ($user->authorise('core.edit', $asset)) {
|
||||
$value->params->set('access-edit', true);
|
||||
} elseif (!empty($userId) && $user->authorise('core.edit.own', $asset)) {
|
||||
// Now check if edit.own is available.
|
||||
// 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 .= '<hr id="system-readmore">' . $value->fulltext;
|
||||
}
|
||||
|
||||
// Convert the metadata field to an array.
|
||||
$registry = new Registry($value->metadata);
|
||||
$value->metadata = $registry->toArray();
|
||||
|
||||
if ($itemId) {
|
||||
$value->tags = new TagsHelper();
|
||||
$value->tags->getTagIds($value->id, 'com_content.article');
|
||||
$value->metadata['tags'] = $value->tags;
|
||||
|
||||
$value->featured_up = null;
|
||||
$value->featured_down = null;
|
||||
|
||||
if ($value->featured) {
|
||||
// Get featured dates.
|
||||
$db = $this->getDatabase();
|
||||
$query = $db->getQuery(true)
|
||||
->select(
|
||||
[
|
||||
$db->quoteName('featured_up'),
|
||||
$db->quoteName('featured_down'),
|
||||
]
|
||||
)
|
||||
->from($db->quoteName('#__content_frontpage'))
|
||||
->where($db->quoteName('content_id') . ' = :id')
|
||||
->bind(':id', $value->id, ParameterType::INTEGER);
|
||||
|
||||
$featured = $db->setQuery($query)->loadObject();
|
||||
|
||||
if ($featured) {
|
||||
$value->featured_up = $featured->featured_up;
|
||||
$value->featured_down = $featured->featured_down;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the return URL.
|
||||
*
|
||||
* @return string The return URL.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getReturnPage()
|
||||
{
|
||||
return base64_encode($this->getState('return_page', ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to save the form data.
|
||||
*
|
||||
* @param array $data The form data.
|
||||
*
|
||||
* @return boolean True on success.
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
public function save($data)
|
||||
{
|
||||
// Associations are not edited in frontend ATM so we have to inherit them
|
||||
if (
|
||||
Associations::isEnabled() && !empty($data['id'])
|
||||
&& $associations = Associations::getAssociations('com_content', '#__content', 'com_content.item', $data['id'])
|
||||
) {
|
||||
foreach ($associations as $tag => $associated) {
|
||||
$associations[$tag] = (int) $associated->id;
|
||||
}
|
||||
|
||||
$data['associations'] = $associations;
|
||||
}
|
||||
|
||||
if (!Multilanguage::isEnabled()) {
|
||||
$data['language'] = '*';
|
||||
}
|
||||
|
||||
return parent::save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the record form.
|
||||
*
|
||||
* @param array $data Data for the form.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
*
|
||||
* @return Form|boolean A Form object on success, false on failure
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getForm($data = [], $loadData = true)
|
||||
{
|
||||
$form = parent::getForm($data, $loadData);
|
||||
|
||||
if (empty($form)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$app = Factory::getApplication();
|
||||
$user = $app->getIdentity();
|
||||
|
||||
// On edit article, we get ID of article from article.id state, but on save, we use data from input
|
||||
$id = (int) $this->getState('article.id', $app->getInput()->getInt('a_id'));
|
||||
|
||||
// Existing record. We can't edit the category in frontend if not edit.state.
|
||||
if ($id > 0 && !$user->authorise('core.edit.state', 'com_content.article.' . $id)) {
|
||||
$form->setFieldAttribute('catid', 'readonly', 'true');
|
||||
$form->setFieldAttribute('catid', 'required', 'false');
|
||||
$form->setFieldAttribute('catid', 'filter', 'unset');
|
||||
}
|
||||
|
||||
// Prevent messing with article language and category when editing existing article with associations
|
||||
if ($this->getState('article.id') && Associations::isEnabled()) {
|
||||
$associations = Associations::getAssociations('com_content', '#__content', 'com_content.item', $id);
|
||||
|
||||
// Make fields read only
|
||||
if (!empty($associations)) {
|
||||
$form->setFieldAttribute('language', 'readonly', 'true');
|
||||
$form->setFieldAttribute('catid', 'readonly', 'true');
|
||||
$form->setFieldAttribute('language', 'filter', 'unset');
|
||||
$form->setFieldAttribute('catid', 'filter', 'unset');
|
||||
}
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows preprocessing of the JForm object.
|
||||
*
|
||||
* @param Form $form The form object
|
||||
* @param array $data The data to be merged into the form object
|
||||
* @param string $group The plugin group to be executed
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
protected function preprocessForm(Form $form, $data, $group = 'content')
|
||||
{
|
||||
$params = $this->getState()->get('params');
|
||||
|
||||
if ($params && $params->get('enable_category') == 1 && $params->get('catid')) {
|
||||
$form->setFieldAttribute('catid', 'default', $params->get('catid'));
|
||||
$form->setFieldAttribute('catid', 'readonly', 'true');
|
||||
|
||||
if (Multilanguage::isEnabled()) {
|
||||
$categoryId = (int) $params->get('catid');
|
||||
|
||||
$db = $this->getDatabase();
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName('language'))
|
||||
->from($db->quoteName('#__categories'))
|
||||
->where($db->quoteName('id') . ' = :categoryId')
|
||||
->bind(':categoryId', $categoryId, ParameterType::INTEGER);
|
||||
$db->setQuery($query);
|
||||
|
||||
$result = $db->loadResult();
|
||||
|
||||
if ($result != '*') {
|
||||
$form->setFieldAttribute('language', 'readonly', 'true');
|
||||
$form->setFieldAttribute('language', 'default', $result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!Multilanguage::isEnabled()) {
|
||||
$form->setFieldAttribute('language', 'type', 'hidden');
|
||||
$form->setFieldAttribute('language', 'default', '*');
|
||||
}
|
||||
|
||||
parent::preprocessForm($form, $data, $group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a table object, load it if necessary.
|
||||
*
|
||||
* @param string $name The table name. Optional.
|
||||
* @param string $prefix The class prefix. Optional.
|
||||
* @param array $options Configuration array for model. Optional.
|
||||
*
|
||||
* @return Table A Table object
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getTable($name = 'Article', $prefix = 'Administrator', $options = [])
|
||||
{
|
||||
return parent::getTable($name, $prefix, $options);
|
||||
}
|
||||
}
|
||||
40
components/com_content/src/Service/Category.php
Normal file
40
components/com_content/src/Service/Category.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Content\Site\Service;
|
||||
|
||||
use Joomla\CMS\Categories\Categories;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Content Component Category Tree
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class Category extends Categories
|
||||
{
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param array $options Array of options
|
||||
*
|
||||
* @since 1.7.0
|
||||
*/
|
||||
public function __construct($options = [])
|
||||
{
|
||||
$options['table'] = '#__content';
|
||||
$options['extension'] = 'com_content';
|
||||
|
||||
parent::__construct($options);
|
||||
}
|
||||
}
|
||||
288
components/com_content/src/Service/Router.php
Normal file
288
components/com_content/src/Service/Router.php
Normal file
@ -0,0 +1,288 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Content\Site\Service;
|
||||
|
||||
use Joomla\CMS\Application\SiteApplication;
|
||||
use Joomla\CMS\Categories\CategoryFactoryInterface;
|
||||
use Joomla\CMS\Categories\CategoryInterface;
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Joomla\CMS\Component\Router\RouterView;
|
||||
use Joomla\CMS\Component\Router\RouterViewConfiguration;
|
||||
use Joomla\CMS\Component\Router\Rules\MenuRules;
|
||||
use Joomla\CMS\Component\Router\Rules\NomenuRules;
|
||||
use Joomla\CMS\Component\Router\Rules\StandardRules;
|
||||
use Joomla\CMS\Menu\AbstractMenu;
|
||||
use Joomla\Database\DatabaseInterface;
|
||||
use Joomla\Database\ParameterType;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Routing class of com_content
|
||||
*
|
||||
* @since 3.3
|
||||
*/
|
||||
class Router extends RouterView
|
||||
{
|
||||
/**
|
||||
* Flag to remove IDs
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $noIDs = false;
|
||||
|
||||
/**
|
||||
* The category factory
|
||||
*
|
||||
* @var CategoryFactoryInterface
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private $categoryFactory;
|
||||
|
||||
/**
|
||||
* The category cache
|
||||
*
|
||||
* @var array
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private $categoryCache = [];
|
||||
|
||||
/**
|
||||
* The db
|
||||
*
|
||||
* @var DatabaseInterface
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private $db;
|
||||
|
||||
/**
|
||||
* Content Component router constructor
|
||||
*
|
||||
* @param SiteApplication $app The application object
|
||||
* @param AbstractMenu $menu The menu object to work with
|
||||
* @param CategoryFactoryInterface $categoryFactory The category object
|
||||
* @param DatabaseInterface $db The database object
|
||||
*/
|
||||
public function __construct(SiteApplication $app, AbstractMenu $menu, CategoryFactoryInterface $categoryFactory, DatabaseInterface $db)
|
||||
{
|
||||
$this->categoryFactory = $categoryFactory;
|
||||
$this->db = $db;
|
||||
|
||||
$params = ComponentHelper::getParams('com_content');
|
||||
$this->noIDs = (bool) $params->get('sef_ids');
|
||||
$categories = new RouterViewConfiguration('categories');
|
||||
$categories->setKey('id');
|
||||
$this->registerView($categories);
|
||||
$category = new RouterViewConfiguration('category');
|
||||
$category->setKey('id')->setParent($categories, 'catid')->setNestable()->addLayout('blog');
|
||||
$this->registerView($category);
|
||||
$article = new RouterViewConfiguration('article');
|
||||
$article->setKey('id')->setParent($category, 'catid');
|
||||
$this->registerView($article);
|
||||
$this->registerView(new RouterViewConfiguration('archive'));
|
||||
$this->registerView(new RouterViewConfiguration('featured'));
|
||||
$form = new RouterViewConfiguration('form');
|
||||
$form->setKey('a_id');
|
||||
$this->registerView($form);
|
||||
|
||||
parent::__construct($app, $menu);
|
||||
|
||||
$this->attachRule(new MenuRules($this));
|
||||
$this->attachRule(new StandardRules($this));
|
||||
$this->attachRule(new NomenuRules($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the segment(s) for a category
|
||||
*
|
||||
* @param string $id ID of the category to retrieve the segments for
|
||||
* @param array $query The request that is built right now
|
||||
*
|
||||
* @return array|string The segments of this item
|
||||
*/
|
||||
public function getCategorySegment($id, $query)
|
||||
{
|
||||
$category = $this->getCategories(['access' => true])->get($id);
|
||||
|
||||
if ($category) {
|
||||
$path = array_reverse($category->getPath(), true);
|
||||
$path[0] = '1:root';
|
||||
|
||||
if ($this->noIDs) {
|
||||
foreach ($path as &$segment) {
|
||||
list($id, $segment) = explode(':', $segment, 2);
|
||||
}
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the segment(s) for a category
|
||||
*
|
||||
* @param string $id ID of the category to retrieve the segments for
|
||||
* @param array $query The request that is built right now
|
||||
*
|
||||
* @return array|string The segments of this item
|
||||
*/
|
||||
public function getCategoriesSegment($id, $query)
|
||||
{
|
||||
return $this->getCategorySegment($id, $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the segment(s) for an article
|
||||
*
|
||||
* @param string $id ID of the article to retrieve the segments for
|
||||
* @param array $query The request that is built right now
|
||||
*
|
||||
* @return array|string The segments of this item
|
||||
*/
|
||||
public function getArticleSegment($id, $query)
|
||||
{
|
||||
if (!strpos($id, ':')) {
|
||||
$id = (int) $id;
|
||||
$dbquery = $this->db->getQuery(true);
|
||||
$dbquery->select($this->db->quoteName('alias'))
|
||||
->from($this->db->quoteName('#__content'))
|
||||
->where($this->db->quoteName('id') . ' = :id')
|
||||
->bind(':id', $id, ParameterType::INTEGER);
|
||||
$this->db->setQuery($dbquery);
|
||||
|
||||
$id .= ':' . $this->db->loadResult();
|
||||
}
|
||||
|
||||
if ($this->noIDs) {
|
||||
list($void, $segment) = explode(':', $id, 2);
|
||||
|
||||
return [$void => $segment];
|
||||
}
|
||||
|
||||
return [(int) $id => $id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the segment(s) for a form
|
||||
*
|
||||
* @param string $id ID of the article form to retrieve the segments for
|
||||
* @param array $query The request that is built right now
|
||||
*
|
||||
* @return array|string The segments of this item
|
||||
*
|
||||
* @since 3.7.3
|
||||
*/
|
||||
public function getFormSegment($id, $query)
|
||||
{
|
||||
return $this->getArticleSegment($id, $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the id for a category
|
||||
*
|
||||
* @param string $segment Segment to retrieve the ID for
|
||||
* @param array $query The request that is parsed right now
|
||||
*
|
||||
* @return mixed The id of this item or false
|
||||
*/
|
||||
public function getCategoryId($segment, $query)
|
||||
{
|
||||
if (isset($query['id'])) {
|
||||
$category = $this->getCategories(['access' => false])->get($query['id']);
|
||||
|
||||
if ($category) {
|
||||
foreach ($category->getChildren() as $child) {
|
||||
if ($this->noIDs) {
|
||||
if ($child->alias == $segment) {
|
||||
return $child->id;
|
||||
}
|
||||
} else {
|
||||
if ($child->id == (int) $segment) {
|
||||
return $child->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the segment(s) for a category
|
||||
*
|
||||
* @param string $segment Segment to retrieve the ID for
|
||||
* @param array $query The request that is parsed right now
|
||||
*
|
||||
* @return mixed The id of this item or false
|
||||
*/
|
||||
public function getCategoriesId($segment, $query)
|
||||
{
|
||||
return $this->getCategoryId($segment, $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the segment(s) for an article
|
||||
*
|
||||
* @param string $segment Segment of the article to retrieve the ID for
|
||||
* @param array $query The request that is parsed right now
|
||||
*
|
||||
* @return mixed The id of this item or false
|
||||
*/
|
||||
public function getArticleId($segment, $query)
|
||||
{
|
||||
if ($this->noIDs) {
|
||||
$dbquery = $this->db->getQuery(true);
|
||||
$dbquery->select($this->db->quoteName('id'))
|
||||
->from($this->db->quoteName('#__content'))
|
||||
->where($this->db->quoteName('alias') . ' = :segment')
|
||||
->bind(':segment', $segment);
|
||||
|
||||
if (isset($query['id']) && $query['id']) {
|
||||
$dbquery->where($this->db->quoteName('catid') . ' = :id')
|
||||
->bind(':id', $query['id'], ParameterType::INTEGER);
|
||||
}
|
||||
|
||||
$this->db->setQuery($dbquery);
|
||||
|
||||
return (int) $this->db->loadResult();
|
||||
}
|
||||
|
||||
return (int) $segment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get categories from cache
|
||||
*
|
||||
* @param array $options The options for retrieving categories
|
||||
*
|
||||
* @return CategoryInterface The object containing categories
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private function getCategories(array $options = []): CategoryInterface
|
||||
{
|
||||
$key = serialize($options);
|
||||
|
||||
if (!isset($this->categoryCache[$key])) {
|
||||
$this->categoryCache[$key] = $this->categoryFactory->createCategory($options);
|
||||
}
|
||||
|
||||
return $this->categoryCache[$key];
|
||||
}
|
||||
}
|
||||
258
components/com_content/src/View/Archive/HtmlView.php
Normal file
258
components/com_content/src/View/Archive/HtmlView.php
Normal file
@ -0,0 +1,258 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Content\Site\View\Archive;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\HTML\HTMLHelper;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\View\GenericDataException;
|
||||
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* HTML View class for the Content component
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class HtmlView extends BaseHtmlView
|
||||
{
|
||||
/**
|
||||
* The model state
|
||||
*
|
||||
* @var \Joomla\Registry\Registry
|
||||
*/
|
||||
protected $state = null;
|
||||
|
||||
/**
|
||||
* An array containing archived articles
|
||||
*
|
||||
* @var \stdClass[]
|
||||
*/
|
||||
protected $items = [];
|
||||
|
||||
/**
|
||||
* The pagination object
|
||||
*
|
||||
* @var \Joomla\CMS\Pagination\Pagination|null
|
||||
*/
|
||||
protected $pagination = null;
|
||||
|
||||
/**
|
||||
* The years that are available to filter on.
|
||||
*
|
||||
* @var array
|
||||
*
|
||||
* @since 3.6.0
|
||||
*/
|
||||
protected $years = [];
|
||||
|
||||
/**
|
||||
* Object containing the year, month and limit field to be displayed
|
||||
*
|
||||
* @var \stdClass|null
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $form = null;
|
||||
|
||||
/**
|
||||
* The page parameters
|
||||
*
|
||||
* @var \Joomla\Registry\Registry|null
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $params = null;
|
||||
|
||||
/**
|
||||
* The search query used on any archived articles (note this may not be displayed depending on the value of the
|
||||
* filter_field component parameter)
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $filter = '';
|
||||
|
||||
/**
|
||||
* The user object
|
||||
*
|
||||
* @var \Joomla\CMS\User\User
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $user = null;
|
||||
|
||||
/**
|
||||
* The page class suffix
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $pageclass_sfx = '';
|
||||
|
||||
/**
|
||||
* Execute and display a template script.
|
||||
*
|
||||
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws GenericDataException
|
||||
*/
|
||||
public function display($tpl = null)
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$user = $this->getCurrentUser();
|
||||
$state = $this->get('State');
|
||||
$items = $this->get('Items');
|
||||
$pagination = $this->get('Pagination');
|
||||
|
||||
if ($errors = $this->getModel()->getErrors()) {
|
||||
throw new GenericDataException(implode("\n", $errors), 500);
|
||||
}
|
||||
|
||||
// Flag indicates to not add limitstart=0 to URL
|
||||
$pagination->hideEmptyLimitstart = true;
|
||||
|
||||
// Get the page/component configuration
|
||||
$params = &$state->params;
|
||||
|
||||
PluginHelper::importPlugin('content');
|
||||
|
||||
foreach ($items as $item) {
|
||||
$item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;
|
||||
|
||||
// No link for ROOT category
|
||||
if ($item->parent_alias === 'root') {
|
||||
$item->parent_id = null;
|
||||
}
|
||||
|
||||
$item->event = new \stdClass();
|
||||
|
||||
// Old plugins: Ensure that text property is available
|
||||
if (!isset($item->text)) {
|
||||
$item->text = $item->introtext;
|
||||
}
|
||||
|
||||
Factory::getApplication()->triggerEvent('onContentPrepare', ['com_content.archive', &$item, &$item->params, 0]);
|
||||
|
||||
// Old plugins: Use processed text as introtext
|
||||
$item->introtext = $item->text;
|
||||
|
||||
$results = Factory::getApplication()->triggerEvent('onContentAfterTitle', ['com_content.archive', &$item, &$item->params, 0]);
|
||||
$item->event->afterDisplayTitle = trim(implode("\n", $results));
|
||||
|
||||
$results = Factory::getApplication()->triggerEvent('onContentBeforeDisplay', ['com_content.archive', &$item, &$item->params, 0]);
|
||||
$item->event->beforeDisplayContent = trim(implode("\n", $results));
|
||||
|
||||
$results = Factory::getApplication()->triggerEvent('onContentAfterDisplay', ['com_content.archive', &$item, &$item->params, 0]);
|
||||
$item->event->afterDisplayContent = trim(implode("\n", $results));
|
||||
}
|
||||
|
||||
$form = new \stdClass();
|
||||
|
||||
// Month Field
|
||||
$months = [
|
||||
'' => Text::_('COM_CONTENT_MONTH'),
|
||||
'1' => Text::_('JANUARY_SHORT'),
|
||||
'2' => Text::_('FEBRUARY_SHORT'),
|
||||
'3' => Text::_('MARCH_SHORT'),
|
||||
'4' => Text::_('APRIL_SHORT'),
|
||||
'5' => Text::_('MAY_SHORT'),
|
||||
'6' => Text::_('JUNE_SHORT'),
|
||||
'7' => Text::_('JULY_SHORT'),
|
||||
'8' => Text::_('AUGUST_SHORT'),
|
||||
'9' => Text::_('SEPTEMBER_SHORT'),
|
||||
'10' => Text::_('OCTOBER_SHORT'),
|
||||
'11' => Text::_('NOVEMBER_SHORT'),
|
||||
'12' => Text::_('DECEMBER_SHORT'),
|
||||
];
|
||||
$form->monthField = HTMLHelper::_(
|
||||
'select.genericlist',
|
||||
$months,
|
||||
'month',
|
||||
[
|
||||
'list.attr' => 'class="form-select"',
|
||||
'list.select' => $state->get('filter.month'),
|
||||
'option.key' => null,
|
||||
]
|
||||
);
|
||||
|
||||
// Year Field
|
||||
$this->years = $this->getModel()->getYears();
|
||||
$years = [];
|
||||
$years[] = HTMLHelper::_('select.option', null, Text::_('JYEAR'));
|
||||
|
||||
foreach ($this->years as $year) {
|
||||
$years[] = HTMLHelper::_('select.option', $year, $year);
|
||||
}
|
||||
|
||||
$form->yearField = HTMLHelper::_(
|
||||
'select.genericlist',
|
||||
$years,
|
||||
'year',
|
||||
['list.attr' => 'class="form-select"', 'list.select' => $state->get('filter.year')]
|
||||
);
|
||||
$form->limitField = $pagination->getLimitBox();
|
||||
|
||||
// Escape strings for HTML output
|
||||
$this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx', ''));
|
||||
|
||||
$this->filter = $state->get('list.filter');
|
||||
$this->form = &$form;
|
||||
$this->items = &$items;
|
||||
$this->params = &$params;
|
||||
$this->user = &$user;
|
||||
$this->pagination = &$pagination;
|
||||
$this->pagination->setAdditionalUrlParam('month', $state->get('filter.month'));
|
||||
$this->pagination->setAdditionalUrlParam('year', $state->get('filter.year'));
|
||||
$this->pagination->setAdditionalUrlParam('filter-search', $state->get('list.filter'));
|
||||
$this->pagination->setAdditionalUrlParam('catid', $app->getInput()->get->get('catid', [], 'array'));
|
||||
|
||||
$this->_prepareDocument();
|
||||
|
||||
parent::display($tpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the document
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _prepareDocument()
|
||||
{
|
||||
// Because the application sets a default page title,
|
||||
// we need to get it from the menu item itself
|
||||
$menu = Factory::getApplication()->getMenu()->getActive();
|
||||
|
||||
if ($menu) {
|
||||
$this->params->def('page_heading', $this->params->get('page_title', $menu->title));
|
||||
} else {
|
||||
$this->params->def('page_heading', Text::_('JGLOBAL_ARTICLES'));
|
||||
}
|
||||
|
||||
$this->setDocumentTitle($this->params->get('page_title', ''));
|
||||
|
||||
if ($this->params->get('menu-meta_description')) {
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
}
|
||||
}
|
||||
363
components/com_content/src/View/Article/HtmlView.php
Normal file
363
components/com_content/src/View/Article/HtmlView.php
Normal file
@ -0,0 +1,363 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Content\Site\View\Article;
|
||||
|
||||
use Joomla\CMS\Categories\Categories;
|
||||
use Joomla\CMS\Event\Content;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Helper\TagsHelper;
|
||||
use Joomla\CMS\Language\Associations;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Layout\FileLayout;
|
||||
use Joomla\CMS\MVC\View\GenericDataException;
|
||||
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
use Joomla\Component\Content\Site\Helper\AssociationHelper;
|
||||
use Joomla\Component\Content\Site\Helper\RouteHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* HTML Article View class for the Content component
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class HtmlView extends BaseHtmlView
|
||||
{
|
||||
/**
|
||||
* The article object
|
||||
*
|
||||
* @var \stdClass
|
||||
*/
|
||||
protected $item;
|
||||
|
||||
/**
|
||||
* The page parameters
|
||||
*
|
||||
* @var \Joomla\Registry\Registry|null
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $params = null;
|
||||
|
||||
/**
|
||||
* Should the print button be displayed or not?
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $print = false;
|
||||
|
||||
/**
|
||||
* The model state
|
||||
*
|
||||
* @var \Joomla\Registry\Registry
|
||||
*/
|
||||
protected $state;
|
||||
|
||||
/**
|
||||
* The user object
|
||||
*
|
||||
* @var \Joomla\CMS\User\User|null
|
||||
*/
|
||||
protected $user = null;
|
||||
|
||||
/**
|
||||
* The page class suffix
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $pageclass_sfx = '';
|
||||
|
||||
/**
|
||||
* The flag to mark if the active menu item is linked to the being displayed article
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $menuItemMatchArticle = false;
|
||||
|
||||
/**
|
||||
* Execute and display a template script.
|
||||
*
|
||||
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function display($tpl = null)
|
||||
{
|
||||
if ($this->getLayout() == 'pagebreak') {
|
||||
parent::display($tpl);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$app = Factory::getApplication();
|
||||
$user = $this->getCurrentUser();
|
||||
|
||||
$this->item = $this->get('Item');
|
||||
$this->print = $app->getInput()->getBool('print', false);
|
||||
$this->state = $this->get('State');
|
||||
$this->user = $user;
|
||||
|
||||
// Check for errors.
|
||||
if (\count($errors = $this->get('Errors'))) {
|
||||
throw new GenericDataException(implode("\n", $errors), 500);
|
||||
}
|
||||
|
||||
// Create a shortcut for $item.
|
||||
$item = $this->item;
|
||||
$item->tagLayout = new FileLayout('joomla.content.tags');
|
||||
|
||||
// Add router helpers.
|
||||
$item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;
|
||||
|
||||
// No link for ROOT category
|
||||
if ($item->parent_alias === 'root') {
|
||||
$item->parent_id = null;
|
||||
}
|
||||
|
||||
// @todo Change based on shownoauth
|
||||
$item->readmore_link = Route::_(RouteHelper::getArticleRoute($item->slug, $item->catid, $item->language));
|
||||
|
||||
// Merge article params. If this is single-article view, menu params override article params
|
||||
// Otherwise, article params override menu item params
|
||||
$this->params = $this->state->get('params');
|
||||
$active = $app->getMenu()->getActive();
|
||||
$temp = clone $this->params;
|
||||
|
||||
// Check to see which parameters should take priority. If the active menu item link to the current article, then
|
||||
// the menu item params take priority
|
||||
if (
|
||||
$active
|
||||
&& $active->component == 'com_content'
|
||||
&& isset($active->query['view'], $active->query['id'])
|
||||
&& $active->query['view'] == 'article'
|
||||
&& $active->query['id'] == $item->id
|
||||
) {
|
||||
$this->menuItemMatchArticle = true;
|
||||
|
||||
// Load layout from active query (in case it is an alternative menu item)
|
||||
if (isset($active->query['layout'])) {
|
||||
$this->setLayout($active->query['layout']);
|
||||
} elseif ($layout = $item->params->get('article_layout')) {
|
||||
// Check for alternative layout of article
|
||||
$this->setLayout($layout);
|
||||
}
|
||||
|
||||
// $item->params are the article params, $temp are the menu item params
|
||||
// Merge so that the menu item params take priority
|
||||
$item->params->merge($temp);
|
||||
} else {
|
||||
// The active menu item is not linked to this article, so the article params take priority here
|
||||
// Merge the menu item params with the article params so that the article params take priority
|
||||
$temp->merge($item->params);
|
||||
$item->params = $temp;
|
||||
|
||||
// Check for alternative layouts (since we are not in a single-article menu item)
|
||||
// Single-article menu item layout takes priority over alt layout for an article
|
||||
if ($layout = $item->params->get('article_layout')) {
|
||||
$this->setLayout($layout);
|
||||
}
|
||||
}
|
||||
|
||||
$offset = (int) $this->state->get('list.offset');
|
||||
|
||||
// Check the view access to the article (the model has already computed the values).
|
||||
if ($item->params->get('access-view') == false && ($item->params->get('show_noauth', '0') == '0')) {
|
||||
$app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'error');
|
||||
$app->setHeader('status', 403, true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for no 'access-view' and empty fulltext,
|
||||
* - Redirect guest users to login
|
||||
* - Deny access to logged users with 403 code
|
||||
* NOTE: we do not recheck for no access-view + show_noauth disabled ... since it was checked above
|
||||
*/
|
||||
if ($item->params->get('access-view') == false && !\strlen($item->fulltext)) {
|
||||
if ($this->user->guest) {
|
||||
$return = base64_encode(Uri::getInstance());
|
||||
$login_url_with_return = Route::_('index.php?option=com_users&view=login&return=' . $return);
|
||||
$app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'notice');
|
||||
$app->redirect($login_url_with_return, 403);
|
||||
} else {
|
||||
$app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'error');
|
||||
$app->setHeader('status', 403, true);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* NOTE: The following code (usually) sets the text to contain the fulltext, but it is the
|
||||
* responsibility of the layout to check 'access-view' and only use "introtext" for guests
|
||||
*/
|
||||
if ($item->params->get('show_intro', '1') == '1') {
|
||||
$item->text = $item->introtext . ' ' . $item->fulltext;
|
||||
} elseif ($item->fulltext) {
|
||||
$item->text = $item->fulltext;
|
||||
} else {
|
||||
$item->text = $item->introtext;
|
||||
}
|
||||
|
||||
$item->tags = new TagsHelper();
|
||||
$item->tags->getItemTags('com_content.article', $this->item->id);
|
||||
|
||||
if (Associations::isEnabled() && $item->params->get('show_associations')) {
|
||||
$item->associations = AssociationHelper::displayAssociations($item->id);
|
||||
}
|
||||
|
||||
$dispatcher = $this->getDispatcher();
|
||||
|
||||
// Process the content plugins.
|
||||
PluginHelper::importPlugin('content', null, true, $dispatcher);
|
||||
|
||||
$contentEventArguments = [
|
||||
'context' => 'com_content.article',
|
||||
'subject' => $item,
|
||||
'params' => $item->params,
|
||||
'page' => $offset,
|
||||
];
|
||||
|
||||
$dispatcher->dispatch('onContentPrepare', new Content\ContentPrepareEvent('onContentPrepare', $contentEventArguments));
|
||||
|
||||
// Extra content from events
|
||||
$item->event = new \stdClass();
|
||||
$contentEvents = [
|
||||
'afterDisplayTitle' => new Content\AfterTitleEvent('onContentAfterTitle', $contentEventArguments),
|
||||
'beforeDisplayContent' => new Content\BeforeDisplayEvent('onContentBeforeDisplay', $contentEventArguments),
|
||||
'afterDisplayContent' => new Content\AfterDisplayEvent('onContentAfterDisplay', $contentEventArguments),
|
||||
];
|
||||
|
||||
foreach ($contentEvents as $resultKey => $event) {
|
||||
$results = $dispatcher->dispatch($event->getName(), $event)->getArgument('result', []);
|
||||
|
||||
$item->event->{$resultKey} = $results ? trim(implode("\n", $results)) : '';
|
||||
}
|
||||
|
||||
// Escape strings for HTML output
|
||||
$this->pageclass_sfx = htmlspecialchars($this->item->params->get('pageclass_sfx', ''));
|
||||
|
||||
$this->_prepareDocument();
|
||||
|
||||
parent::display($tpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the document.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _prepareDocument()
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$pathway = $app->getPathway();
|
||||
|
||||
/**
|
||||
* Because the application sets a default page title,
|
||||
* we need to get it from the menu item itself
|
||||
*/
|
||||
$menu = $app->getMenu()->getActive();
|
||||
|
||||
if ($menu) {
|
||||
$this->params->def('page_heading', $this->params->get('page_title', $menu->title));
|
||||
} else {
|
||||
$this->params->def('page_heading', Text::_('JGLOBAL_ARTICLES'));
|
||||
}
|
||||
|
||||
// If the menu item is not linked to this article
|
||||
if (!$this->menuItemMatchArticle) {
|
||||
// If a browser page title is defined, use that, then fall back to the article title if set, then fall back to the page_title option
|
||||
$title = $this->item->params->get('article_page_title', $this->item->title);
|
||||
|
||||
// Get ID of the category from active menu item
|
||||
if (
|
||||
$menu && $menu->component == 'com_content' && isset($menu->query['view'])
|
||||
&& \in_array($menu->query['view'], ['categories', 'category'])
|
||||
) {
|
||||
$id = $menu->query['id'];
|
||||
} else {
|
||||
$id = 0;
|
||||
}
|
||||
|
||||
$path = [['title' => $this->item->title, 'link' => '']];
|
||||
$category = Categories::getInstance('Content')->get($this->item->catid);
|
||||
|
||||
while ($category !== null && $category->id != $id && $category->id !== 'root') {
|
||||
$path[] = ['title' => $category->title, 'link' => RouteHelper::getCategoryRoute($category->id, $category->language)];
|
||||
$category = $category->getParent();
|
||||
}
|
||||
|
||||
$path = array_reverse($path);
|
||||
|
||||
foreach ($path as $item) {
|
||||
$pathway->addItem($item['title'], $item['link']);
|
||||
}
|
||||
} else {
|
||||
/**
|
||||
* This case the menu item links directly to the article, browser will be determined by following
|
||||
* order:
|
||||
* 1. Browser page title set from menu item itself
|
||||
* 2. Browser page title set for the article
|
||||
* 3. Article title
|
||||
*/
|
||||
$menuItemParams = $menu->getParams();
|
||||
$title = $menuItemParams->get(
|
||||
'page_title',
|
||||
$this->item->params->get('article_page_title', $this->item->title)
|
||||
);
|
||||
}
|
||||
|
||||
$this->setDocumentTitle($title);
|
||||
|
||||
if ($this->item->metadesc) {
|
||||
$this->getDocument()->setDescription($this->item->metadesc);
|
||||
} elseif ($this->params->get('menu-meta_description')) {
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
|
||||
if ($app->get('MetaAuthor') == '1') {
|
||||
$author = $this->item->created_by_alias ?: $this->item->author;
|
||||
$this->getDocument()->setMetaData('author', $author);
|
||||
}
|
||||
|
||||
$mdata = $this->item->metadata->toArray();
|
||||
|
||||
foreach ($mdata as $k => $v) {
|
||||
if ($v) {
|
||||
$this->getDocument()->setMetaData($k, $v);
|
||||
}
|
||||
}
|
||||
|
||||
// If there is a pagebreak heading or title, add it to the page title
|
||||
if (!empty($this->item->page_title)) {
|
||||
$this->item->title .= ' - ' . $this->item->page_title;
|
||||
$this->setDocumentTitle(
|
||||
$this->item->page_title . ' - ' . Text::sprintf('PLG_CONTENT_PAGEBREAK_PAGE_NUM', $this->state->get('list.offset') + 1)
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->print) {
|
||||
$this->getDocument()->setMetaData('robots', 'noindex, nofollow');
|
||||
}
|
||||
}
|
||||
}
|
||||
39
components/com_content/src/View/Categories/HtmlView.php
Normal file
39
components/com_content/src/View/Categories/HtmlView.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Content\Site\View\Categories;
|
||||
|
||||
use Joomla\CMS\MVC\View\CategoriesView;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Content categories view.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class HtmlView extends CategoriesView
|
||||
{
|
||||
/**
|
||||
* Language key for default page heading
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2
|
||||
*/
|
||||
protected $pageHeading = 'JGLOBAL_ARTICLES';
|
||||
|
||||
/**
|
||||
* @var string The name of the extension for the category
|
||||
* @since 3.2
|
||||
*/
|
||||
protected $extension = 'com_content';
|
||||
}
|
||||
81
components/com_content/src/View/Category/FeedView.php
Normal file
81
components/com_content/src/View/Category/FeedView.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Content\Site\View\Category;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\HTML\HTMLHelper;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\View\CategoryFeedView;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\Component\Content\Site\Helper\RouteHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* HTML View class for the Content component
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class FeedView extends CategoryFeedView
|
||||
{
|
||||
/**
|
||||
* @var string The name of the view to link individual items to
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
protected $viewName = 'article';
|
||||
|
||||
/**
|
||||
* Method to reconcile non-standard names from components to usage in this class.
|
||||
* Typically overridden in the component feed view class.
|
||||
*
|
||||
* @param object $item The item for a feed, an element of the $items array.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
protected function reconcileNames($item)
|
||||
{
|
||||
// Get description, intro_image, author and date
|
||||
$app = Factory::getApplication();
|
||||
$params = $app->getParams();
|
||||
$item->description = '';
|
||||
$obj = json_decode($item->images);
|
||||
|
||||
if (!empty($obj->image_intro)) {
|
||||
$item->description = '<p>' . HTMLHelper::_('image', $obj->image_intro, $obj->image_intro_alt) . '</p>';
|
||||
}
|
||||
|
||||
$item->description .= ($params->get('feed_summary', 0) ? $item->introtext . $item->fulltext : $item->introtext);
|
||||
|
||||
// Add readmore link to description if introtext is shown, show_readmore is true and fulltext exists
|
||||
if (!$item->params->get('feed_summary', 0) && $item->params->get('feed_show_readmore', 0) && $item->fulltext) {
|
||||
// Compute the article slug
|
||||
$item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;
|
||||
|
||||
// URL link to article
|
||||
$link = Route::_(
|
||||
RouteHelper::getArticleRoute($item->slug, $item->catid, $item->language),
|
||||
true,
|
||||
$app->get('force_ssl') == 2 ? Route::TLS_FORCE : Route::TLS_IGNORE,
|
||||
true
|
||||
);
|
||||
|
||||
$item->description .= '<p class="feed-readmore"><a target="_blank" href="' . $link . '" rel="noopener">'
|
||||
. Text::_('COM_CONTENT_FEED_READMORE') . '</a></p>';
|
||||
}
|
||||
|
||||
$item->author = $item->created_by_alias ?: $item->author;
|
||||
}
|
||||
}
|
||||
227
components/com_content/src/View/Category/HtmlView.php
Normal file
227
components/com_content/src/View/Category/HtmlView.php
Normal file
@ -0,0 +1,227 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Content\Site\View\Category;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\MVC\View\CategoryView;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\Component\Content\Site\Helper\RouteHelper;
|
||||
use Joomla\Registry\Registry;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* HTML View class for the Content component
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class HtmlView extends CategoryView
|
||||
{
|
||||
/**
|
||||
* @var array Array of leading items for blog display
|
||||
* @since 3.2
|
||||
*/
|
||||
protected $lead_items = [];
|
||||
|
||||
/**
|
||||
* @var array Array of intro items for blog display
|
||||
* @since 3.2
|
||||
*/
|
||||
protected $intro_items = [];
|
||||
|
||||
/**
|
||||
* @var array Array of links in blog display
|
||||
* @since 3.2
|
||||
*/
|
||||
protected $link_items = [];
|
||||
|
||||
/**
|
||||
* @var string The name of the extension for the category
|
||||
* @since 3.2
|
||||
*/
|
||||
protected $extension = 'com_content';
|
||||
|
||||
/**
|
||||
* @var string Default title to use for page title
|
||||
* @since 3.2
|
||||
*/
|
||||
protected $defaultPageTitle = 'JGLOBAL_ARTICLES';
|
||||
|
||||
/**
|
||||
* @var string The name of the view to link individual items to
|
||||
* @since 3.2
|
||||
*/
|
||||
protected $viewName = 'article';
|
||||
|
||||
/**
|
||||
* Execute and display a template script.
|
||||
*
|
||||
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function display($tpl = null)
|
||||
{
|
||||
$this->commonCategoryDisplay();
|
||||
|
||||
// Flag indicates to not add limitstart=0 to URL
|
||||
$this->pagination->hideEmptyLimitstart = true;
|
||||
|
||||
// Prepare the data
|
||||
// Get the metrics for the structural page layout.
|
||||
$params = $this->params;
|
||||
$numLeading = $params->def('num_leading_articles', 1);
|
||||
$numIntro = $params->def('num_intro_articles', 4);
|
||||
$numLinks = $params->def('num_links', 4);
|
||||
$this->vote = PluginHelper::isEnabled('content', 'vote');
|
||||
|
||||
PluginHelper::importPlugin('content');
|
||||
|
||||
$app = Factory::getApplication();
|
||||
|
||||
// Compute the article slugs and prepare introtext (runs content plugins).
|
||||
foreach ($this->items as $item) {
|
||||
$item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;
|
||||
|
||||
// No link for ROOT category
|
||||
if ($item->parent_alias === 'root') {
|
||||
$item->parent_id = null;
|
||||
}
|
||||
|
||||
$item->event = new \stdClass();
|
||||
|
||||
// Old plugins: Ensure that text property is available
|
||||
if (!isset($item->text)) {
|
||||
$item->text = $item->introtext;
|
||||
}
|
||||
|
||||
$app->triggerEvent('onContentPrepare', ['com_content.category', &$item, &$item->params, 0]);
|
||||
|
||||
// Old plugins: Use processed text as introtext
|
||||
$item->introtext = $item->text;
|
||||
|
||||
$results = $app->triggerEvent('onContentAfterTitle', ['com_content.category', &$item, &$item->params, 0]);
|
||||
$item->event->afterDisplayTitle = trim(implode("\n", $results));
|
||||
|
||||
$results = $app->triggerEvent('onContentBeforeDisplay', ['com_content.category', &$item, &$item->params, 0]);
|
||||
$item->event->beforeDisplayContent = trim(implode("\n", $results));
|
||||
|
||||
$results = $app->triggerEvent('onContentAfterDisplay', ['com_content.category', &$item, &$item->params, 0]);
|
||||
$item->event->afterDisplayContent = trim(implode("\n", $results));
|
||||
}
|
||||
|
||||
// For blog layouts, preprocess the breakdown of leading, intro and linked articles.
|
||||
// This makes it much easier for the designer to just interrogate the arrays.
|
||||
if ($params->get('layout_type') === 'blog' || $this->getLayout() === 'blog') {
|
||||
foreach ($this->items as $i => $item) {
|
||||
if ($i < $numLeading) {
|
||||
$this->lead_items[] = $item;
|
||||
} elseif ($i >= $numLeading && $i < $numLeading + $numIntro) {
|
||||
$this->intro_items[] = $item;
|
||||
} elseif ($i < $numLeading + $numIntro + $numLinks) {
|
||||
$this->link_items[] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Because the application sets a default page title,
|
||||
// we need to get it from the menu item itself
|
||||
$active = $app->getMenu()->getActive();
|
||||
|
||||
if ($this->menuItemMatchCategory) {
|
||||
$this->params->def('page_heading', $this->params->get('page_title', $active->title));
|
||||
$title = $this->params->get('page_title', $active->title);
|
||||
} else {
|
||||
$this->params->def('page_heading', $this->category->title);
|
||||
$title = $this->category->title;
|
||||
$this->params->set('page_title', $title);
|
||||
}
|
||||
|
||||
if (empty($title)) {
|
||||
$title = $this->category->title;
|
||||
}
|
||||
|
||||
$this->setDocumentTitle($title);
|
||||
|
||||
if ($this->category->metadesc) {
|
||||
$this->getDocument()->setDescription($this->category->metadesc);
|
||||
} elseif ($this->params->get('menu-meta_description')) {
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
|
||||
if (!\is_object($this->category->metadata)) {
|
||||
$this->category->metadata = new Registry($this->category->metadata);
|
||||
}
|
||||
|
||||
if (($app->get('MetaAuthor') == '1') && $this->category->get('author', '')) {
|
||||
$this->getDocument()->setMetaData('author', $this->category->get('author', ''));
|
||||
}
|
||||
|
||||
$mdata = $this->category->metadata->toArray();
|
||||
|
||||
foreach ($mdata as $k => $v) {
|
||||
if ($v) {
|
||||
$this->getDocument()->setMetaData($k, $v);
|
||||
}
|
||||
}
|
||||
|
||||
parent::display($tpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the document
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareDocument()
|
||||
{
|
||||
parent::prepareDocument();
|
||||
|
||||
$this->addFeed();
|
||||
|
||||
if ($this->menuItemMatchCategory) {
|
||||
// If the active menu item is linked directly to the category being displayed, no further process is needed
|
||||
return;
|
||||
}
|
||||
|
||||
// Get ID of the category from active menu item
|
||||
$menu = $this->menu;
|
||||
|
||||
if (
|
||||
$menu && $menu->component == 'com_content' && isset($menu->query['view'])
|
||||
&& \in_array($menu->query['view'], ['categories', 'category'])
|
||||
) {
|
||||
$id = $menu->query['id'];
|
||||
} else {
|
||||
$id = 0;
|
||||
}
|
||||
|
||||
$path = [['title' => $this->category->title, 'link' => '']];
|
||||
$category = $this->category->getParent();
|
||||
|
||||
while ($category !== null && $category->id !== 'root' && $category->id != $id) {
|
||||
$path[] = ['title' => $category->title, 'link' => RouteHelper::getCategoryRoute($category->id, $category->language)];
|
||||
$category = $category->getParent();
|
||||
}
|
||||
|
||||
$path = array_reverse($path);
|
||||
|
||||
foreach ($path as $item) {
|
||||
$this->pathway->addItem($item['title'], $item['link']);
|
||||
}
|
||||
}
|
||||
}
|
||||
120
components/com_content/src/View/Featured/FeedView.php
Normal file
120
components/com_content/src/View/Featured/FeedView.php
Normal file
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Content\Site\View\Featured;
|
||||
|
||||
use Joomla\CMS\Categories\Categories;
|
||||
use Joomla\CMS\Document\Feed\FeedItem;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\HTML\HTMLHelper;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\View\AbstractView;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\Component\Content\Site\Helper\RouteHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Frontpage View class
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class FeedView extends AbstractView
|
||||
{
|
||||
/**
|
||||
* Execute and display a template script.
|
||||
*
|
||||
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function display($tpl = null)
|
||||
{
|
||||
// Parameters
|
||||
$app = Factory::getApplication();
|
||||
$params = $app->getParams();
|
||||
$feedEmail = $app->get('feed_email', 'none');
|
||||
$siteEmail = $app->get('mailfrom');
|
||||
|
||||
// If the feed has been disabled, we want to bail out here
|
||||
if ($params->get('show_feed_link', 1) == 0) {
|
||||
throw new \Exception(Text::_('JGLOBAL_RESOURCE_NOT_FOUND'), 404);
|
||||
}
|
||||
|
||||
$this->getDocument()->link = Route::_('index.php?option=com_content&view=featured');
|
||||
|
||||
// Get some data from the model
|
||||
$app->getInput()->set('limit', $app->get('feed_limit'));
|
||||
$categories = Categories::getInstance('Content');
|
||||
$rows = $this->get('Items');
|
||||
|
||||
foreach ($rows as $row) {
|
||||
// Strip html from feed item title
|
||||
$title = htmlspecialchars($row->title, ENT_QUOTES, 'UTF-8');
|
||||
$title = html_entity_decode($title, ENT_COMPAT, 'UTF-8');
|
||||
|
||||
// Compute the article slug
|
||||
$row->slug = $row->alias ? ($row->id . ':' . $row->alias) : $row->id;
|
||||
|
||||
// URL link to article
|
||||
$link = RouteHelper::getArticleRoute($row->slug, $row->catid, $row->language);
|
||||
|
||||
$description = '';
|
||||
$obj = json_decode($row->images);
|
||||
|
||||
if (!empty($obj->image_intro)) {
|
||||
$description = '<p>' . HTMLHelper::_('image', $obj->image_intro, $obj->image_intro_alt) . '</p>';
|
||||
}
|
||||
|
||||
$description .= ($params->get('feed_summary', 0) ? $row->introtext . $row->fulltext : $row->introtext);
|
||||
$author = $row->created_by_alias ?: $row->author;
|
||||
|
||||
// Load individual item creator class
|
||||
$item = new FeedItem();
|
||||
$item->title = $title;
|
||||
$item->link = Route::_($link);
|
||||
$item->date = $row->publish_up;
|
||||
$item->category = [];
|
||||
|
||||
// All featured articles are categorized as "Featured"
|
||||
$item->category[] = Text::_('JFEATURED');
|
||||
|
||||
for ($item_category = $categories->get($row->catid); $item_category !== null; $item_category = $item_category->getParent()) {
|
||||
// Only add non-root categories
|
||||
if ($item_category->id > 1) {
|
||||
$item->category[] = $item_category->title;
|
||||
}
|
||||
}
|
||||
|
||||
$item->author = $author;
|
||||
|
||||
if ($feedEmail === 'site') {
|
||||
$item->authorEmail = $siteEmail;
|
||||
} elseif ($feedEmail === 'author') {
|
||||
$item->authorEmail = $row->author_email;
|
||||
}
|
||||
|
||||
// Add readmore link to description if introtext is shown, show_readmore is true and fulltext exists
|
||||
if (!$params->get('feed_summary', 0) && $params->get('feed_show_readmore', 0) && $row->fulltext) {
|
||||
$link = Route::_($link, true, $app->get('force_ssl') == 2 ? Route::TLS_FORCE : Route::TLS_IGNORE, true);
|
||||
$description .= '<p class="feed-readmore"><a target="_blank" href="' . $link . '" rel="noopener">'
|
||||
. Text::_('COM_CONTENT_FEED_READMORE') . '</a></p>';
|
||||
}
|
||||
|
||||
// Load item description and add div
|
||||
$item->description = '<div class="feed-description">' . $description . '</div>';
|
||||
|
||||
// Loads item info into rss array
|
||||
$this->getDocument()->addItem($item);
|
||||
}
|
||||
}
|
||||
}
|
||||
248
components/com_content/src/View/Featured/HtmlView.php
Normal file
248
components/com_content/src/View/Featured/HtmlView.php
Normal file
@ -0,0 +1,248 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Content\Site\View\Featured;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\View\GenericDataException;
|
||||
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\CMS\Router\Route;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Frontpage View class
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class HtmlView extends BaseHtmlView
|
||||
{
|
||||
/**
|
||||
* The model state
|
||||
*
|
||||
* @var \Joomla\Registry\Registry
|
||||
*/
|
||||
protected $state = null;
|
||||
|
||||
/**
|
||||
* The featured articles array
|
||||
*
|
||||
* @var \stdClass[]
|
||||
*/
|
||||
protected $items = null;
|
||||
|
||||
/**
|
||||
* The pagination object.
|
||||
*
|
||||
* @var \Joomla\CMS\Pagination\Pagination
|
||||
*/
|
||||
protected $pagination = null;
|
||||
|
||||
/**
|
||||
* The featured articles to be displayed as lead items.
|
||||
*
|
||||
* @var \stdClass[]
|
||||
*/
|
||||
protected $lead_items = [];
|
||||
|
||||
/**
|
||||
* The featured articles to be displayed as intro items.
|
||||
*
|
||||
* @var \stdClass[]
|
||||
*/
|
||||
protected $intro_items = [];
|
||||
|
||||
/**
|
||||
* The featured articles to be displayed as link items.
|
||||
*
|
||||
* @var \stdClass[]
|
||||
*/
|
||||
protected $link_items = [];
|
||||
|
||||
/**
|
||||
* @var \Joomla\Database\DatabaseDriver
|
||||
*
|
||||
* @since 3.6.3
|
||||
*
|
||||
* @deprecated 4.3 will be removed in 6.0
|
||||
* Will be removed without replacement use database from the container instead
|
||||
* Example: Factory::getContainer()->get(DatabaseInterface::class);
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* The user object
|
||||
*
|
||||
* @var \Joomla\CMS\User\User|null
|
||||
*/
|
||||
protected $user = null;
|
||||
|
||||
/**
|
||||
* The page class suffix
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $pageclass_sfx = '';
|
||||
|
||||
/**
|
||||
* The page parameters
|
||||
*
|
||||
* @var \Joomla\Registry\Registry|null
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $params = null;
|
||||
|
||||
/**
|
||||
* Execute and display a template script.
|
||||
*
|
||||
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function display($tpl = null)
|
||||
{
|
||||
$user = $this->getCurrentUser();
|
||||
|
||||
$state = $this->get('State');
|
||||
$items = $this->get('Items');
|
||||
$pagination = $this->get('Pagination');
|
||||
|
||||
// Flag indicates to not add limitstart=0 to URL
|
||||
$pagination->hideEmptyLimitstart = true;
|
||||
|
||||
// Check for errors.
|
||||
if (\count($errors = $this->get('Errors'))) {
|
||||
throw new GenericDataException(implode("\n", $errors), 500);
|
||||
}
|
||||
|
||||
/** @var \Joomla\Registry\Registry $params */
|
||||
$params = &$state->params;
|
||||
|
||||
// PREPARE THE DATA
|
||||
|
||||
// Get the metrics for the structural page layout.
|
||||
$numLeading = (int) $params->def('num_leading_articles', 1);
|
||||
$numIntro = (int) $params->def('num_intro_articles', 4);
|
||||
|
||||
PluginHelper::importPlugin('content');
|
||||
|
||||
// Compute the article slugs and prepare introtext (runs content plugins).
|
||||
foreach ($items as &$item) {
|
||||
$item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;
|
||||
|
||||
// No link for ROOT category
|
||||
if ($item->parent_alias === 'root') {
|
||||
$item->parent_id = null;
|
||||
}
|
||||
|
||||
$item->event = new \stdClass();
|
||||
|
||||
// Old plugins: Ensure that text property is available
|
||||
if (!isset($item->text)) {
|
||||
$item->text = $item->introtext;
|
||||
}
|
||||
|
||||
Factory::getApplication()->triggerEvent('onContentPrepare', ['com_content.featured', &$item, &$item->params, 0]);
|
||||
|
||||
// Old plugins: Use processed text as introtext
|
||||
$item->introtext = $item->text;
|
||||
|
||||
$results = Factory::getApplication()->triggerEvent('onContentAfterTitle', ['com_content.featured', &$item, &$item->params, 0]);
|
||||
$item->event->afterDisplayTitle = trim(implode("\n", $results));
|
||||
|
||||
$results = Factory::getApplication()->triggerEvent('onContentBeforeDisplay', ['com_content.featured', &$item, &$item->params, 0]);
|
||||
$item->event->beforeDisplayContent = trim(implode("\n", $results));
|
||||
|
||||
$results = Factory::getApplication()->triggerEvent('onContentAfterDisplay', ['com_content.featured', &$item, &$item->params, 0]);
|
||||
$item->event->afterDisplayContent = trim(implode("\n", $results));
|
||||
}
|
||||
|
||||
// Preprocess the breakdown of leading, intro and linked articles.
|
||||
// This makes it much easier for the designer to just integrate the arrays.
|
||||
$max = \count($items);
|
||||
|
||||
// The first group is the leading articles.
|
||||
$limit = $numLeading;
|
||||
|
||||
for ($i = 0; $i < $limit && $i < $max; $i++) {
|
||||
$this->lead_items[$i] = &$items[$i];
|
||||
}
|
||||
|
||||
// The second group is the intro articles.
|
||||
$limit = $numLeading + $numIntro;
|
||||
|
||||
// Order articles across, then down (or single column mode)
|
||||
for ($i = $numLeading; $i < $limit && $i < $max; $i++) {
|
||||
$this->intro_items[$i] = &$items[$i];
|
||||
}
|
||||
|
||||
// The remainder are the links.
|
||||
for ($i = $numLeading + $numIntro; $i < $max; $i++) {
|
||||
$this->link_items[$i] = &$items[$i];
|
||||
}
|
||||
|
||||
// Escape strings for HTML output
|
||||
$this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx', ''));
|
||||
|
||||
$this->params = &$params;
|
||||
$this->items = &$items;
|
||||
$this->pagination = &$pagination;
|
||||
$this->user = &$user;
|
||||
$this->db = Factory::getDbo();
|
||||
|
||||
$this->_prepareDocument();
|
||||
|
||||
parent::display($tpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the document.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _prepareDocument()
|
||||
{
|
||||
// Because the application sets a default page title,
|
||||
// we need to get it from the menu item itself
|
||||
$menu = Factory::getApplication()->getMenu()->getActive();
|
||||
|
||||
if ($menu) {
|
||||
$this->params->def('page_heading', $this->params->get('page_title', $menu->title));
|
||||
} else {
|
||||
$this->params->def('page_heading', Text::_('JGLOBAL_ARTICLES'));
|
||||
}
|
||||
|
||||
$this->setDocumentTitle($this->params->get('page_title', ''));
|
||||
|
||||
if ($this->params->get('menu-meta_description')) {
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
|
||||
// Add feed links
|
||||
if ($this->params->get('show_feed_link', 1)) {
|
||||
$link = '&format=feed&limitstart=';
|
||||
$attribs = ['type' => 'application/rss+xml', 'title' => htmlspecialchars($this->getDocument()->getTitle())];
|
||||
$this->getDocument()->addHeadLink(Route::_($link . '&type=rss'), 'alternate', 'rel', $attribs);
|
||||
$attribs = ['type' => 'application/atom+xml', 'title' => htmlspecialchars($this->getDocument()->getTitle())];
|
||||
$this->getDocument()->addHeadLink(Route::_($link . '&type=atom'), 'alternate', 'rel', $attribs);
|
||||
}
|
||||
}
|
||||
}
|
||||
233
components/com_content/src/View/Form/HtmlView.php
Normal file
233
components/com_content/src/View/Form/HtmlView.php
Normal file
@ -0,0 +1,233 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Site
|
||||
* @subpackage com_content
|
||||
*
|
||||
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Content\Site\View\Form;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Helper\TagsHelper;
|
||||
use Joomla\CMS\Language\Multilanguage;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\View\GenericDataException;
|
||||
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* HTML Article View class for the Content component
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
class HtmlView extends BaseHtmlView
|
||||
{
|
||||
/**
|
||||
* The Form object
|
||||
*
|
||||
* @var \Joomla\CMS\Form\Form
|
||||
*/
|
||||
protected $form;
|
||||
|
||||
/**
|
||||
* The item being created
|
||||
*
|
||||
* @var \stdClass
|
||||
*/
|
||||
protected $item;
|
||||
|
||||
/**
|
||||
* The page to return to after the article is submitted
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $return_page = '';
|
||||
|
||||
/**
|
||||
* The model state
|
||||
*
|
||||
* @var \Joomla\Registry\Registry
|
||||
*/
|
||||
protected $state;
|
||||
|
||||
/**
|
||||
* The page parameters
|
||||
*
|
||||
* @var \Joomla\Registry\Registry|null
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $params = null;
|
||||
|
||||
/**
|
||||
* The page class suffix
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $pageclass_sfx = '';
|
||||
|
||||
/**
|
||||
* The user object
|
||||
*
|
||||
* @var \Joomla\CMS\User\User
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
protected $user = null;
|
||||
|
||||
/**
|
||||
* Should we show a captcha form for the submission of the article?
|
||||
*
|
||||
* @var boolean
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
protected $captchaEnabled = false;
|
||||
|
||||
/**
|
||||
* Should we show Save As Copy button?
|
||||
*
|
||||
* @var boolean
|
||||
* @since 4.1.0
|
||||
*/
|
||||
protected $showSaveAsCopy = false;
|
||||
|
||||
/**
|
||||
* Execute and display a template script.
|
||||
*
|
||||
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
|
||||
*
|
||||
* @return void|boolean
|
||||
*/
|
||||
public function display($tpl = null)
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
$user = $app->getIdentity();
|
||||
|
||||
// Get model data.
|
||||
$this->state = $this->get('State');
|
||||
$this->item = $this->get('Item');
|
||||
$this->form = $this->get('Form');
|
||||
$this->return_page = $this->get('ReturnPage');
|
||||
|
||||
if (empty($this->item->id)) {
|
||||
$catid = $this->state->params->get('catid');
|
||||
|
||||
if ($this->state->params->get('enable_category') == 1 && $catid) {
|
||||
$authorised = $user->authorise('core.create', 'com_content.category.' . $catid);
|
||||
} else {
|
||||
$authorised = $user->authorise('core.create', 'com_content') || \count($user->getAuthorisedCategories('com_content', 'core.create'));
|
||||
}
|
||||
} else {
|
||||
$authorised = $this->item->params->get('access-edit');
|
||||
}
|
||||
|
||||
if ($authorised !== true) {
|
||||
$app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'error');
|
||||
$app->setHeader('status', 403, true);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->item->tags = new TagsHelper();
|
||||
|
||||
if (!empty($this->item->id)) {
|
||||
$this->item->tags->getItemTags('com_content.article', $this->item->id);
|
||||
|
||||
$this->item->images = json_decode($this->item->images);
|
||||
$this->item->urls = json_decode($this->item->urls);
|
||||
|
||||
$tmp = new \stdClass();
|
||||
$tmp->images = $this->item->images;
|
||||
$tmp->urls = $this->item->urls;
|
||||
$this->form->bind($tmp);
|
||||
}
|
||||
|
||||
// Check for errors.
|
||||
if (\count($errors = $this->get('Errors'))) {
|
||||
throw new GenericDataException(implode("\n", $errors), 500);
|
||||
}
|
||||
|
||||
// Create a shortcut to the parameters.
|
||||
$params = &$this->state->params;
|
||||
|
||||
// Escape strings for HTML output
|
||||
$this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx', ''));
|
||||
|
||||
$this->params = $params;
|
||||
|
||||
// Override global params with article specific params
|
||||
$this->params->merge($this->item->params);
|
||||
$this->user = $user;
|
||||
|
||||
// Propose current language as default when creating new article
|
||||
if (empty($this->item->id) && Multilanguage::isEnabled() && $params->get('enable_category') != 1) {
|
||||
$lang = $this->getLanguage()->getTag();
|
||||
$this->form->setFieldAttribute('language', 'default', $lang);
|
||||
}
|
||||
|
||||
$captchaSet = $params->get('captcha', Factory::getApplication()->get('captcha', '0'));
|
||||
|
||||
foreach (PluginHelper::getPlugin('captcha') as $plugin) {
|
||||
if ($captchaSet === $plugin->name) {
|
||||
$this->captchaEnabled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If the article is being edited and the current user has permission to create article
|
||||
if (
|
||||
$this->item->id
|
||||
&& ($user->authorise('core.create', 'com_content') || \count($user->getAuthorisedCategories('com_content', 'core.create')))
|
||||
) {
|
||||
$this->showSaveAsCopy = true;
|
||||
}
|
||||
|
||||
$this->_prepareDocument();
|
||||
|
||||
parent::display($tpl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the document
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _prepareDocument()
|
||||
{
|
||||
$app = Factory::getApplication();
|
||||
|
||||
// Because the application sets a default page title,
|
||||
// we need to get it from the menu item itself
|
||||
$menu = $app->getMenu()->getActive();
|
||||
|
||||
if ($menu) {
|
||||
$this->params->def('page_heading', $this->params->get('page_title', $menu->title));
|
||||
} else {
|
||||
$this->params->def('page_heading', Text::_('COM_CONTENT_FORM_EDIT_ARTICLE'));
|
||||
}
|
||||
|
||||
$title = $this->params->def('page_title', Text::_('COM_CONTENT_FORM_EDIT_ARTICLE'));
|
||||
|
||||
$this->setDocumentTitle($title);
|
||||
|
||||
$app->getPathway()->addItem($title);
|
||||
|
||||
if ($this->params->get('menu-meta_description')) {
|
||||
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
|
||||
}
|
||||
|
||||
if ($this->params->get('robots')) {
|
||||
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user