Skip to content
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- Update link to featured

UPDATE `#__menu`
SET `link` = 'index.php?option=com_content&view=articles&featured=1'
SET `link` = 'index.php?option=com_content&view=articles&filter[featured]=1'
WHERE `link` = 'index.php?option=com_content&view=featured'
AND `client_id` = 1;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- Update link to featured

UPDATE "#__menu"
SET "link" = 'index.php?option=com_content&view=articles&featured=1'
SET "link" = 'index.php?option=com_content&view=articles&filter[featured]=1'
WHERE "link" = 'index.php?option=com_content&view=featured'
AND "client_id" = 1;
26 changes: 14 additions & 12 deletions administrator/components/com_content/forms/filter_articles.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<form>
<field
name="featured"
type="list"
label="JFEATURED"
filtermode="selector"
onchange="Joomla.resetFilters(this)"
validate="options"
>
<option value="">COM_CONTENT_SELECT_FEATURED</option>
<option value="0">COM_CONTENT_FILTER_FEATURED_NO</option>
<option value="1">COM_CONTENT_FILTER_FEATURED_YES</option>
</field>
<fields name="filter">
<field
name="search"
Expand Down Expand Up @@ -65,6 +53,20 @@
class="js-select-submit-on-change"
/>


<field
name="featured"
type="list"
label="JFEATURED"
filtermode="selector"
class="js-select-submit-on-change"
validate="options"
>
<option value="">COM_CONTENT_SELECT_FEATURED</option>
<option value="0">COM_CONTENT_FILTER_FEATURED_NO</option>
<option value="1">COM_CONTENT_FILTER_FEATURED_YES</option>
</field>

<field
name="author_id"
type="author"
Expand Down
2 changes: 1 addition & 1 deletion administrator/components/com_content/presets/content.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
title="COM_CONTENT_MENUS_FEATURED"
type="component"
element="com_content"
link="index.php?option=com_content&amp;view=articles&amp;featured=1"
link="index.php?option=com_content&amp;view=articles&amp;filter[featured]=1"
class="class:featured"
/>
</menuitem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\Response\JsonResponse;
use Joomla\CMS\Router\Route;
use Joomla\Component\Content\Administrator\Model\ArticlesModel;
use Joomla\Input\Input;
use Joomla\Utilities\ArrayHelper;

Expand Down Expand Up @@ -165,9 +166,14 @@ public function getQuickiconContent()
*/
public function getQuickiconFeatured()
{
/**
* @var ArticlesModel $model
*/
$model = $this->getModel('articles');

$amount = (int) $model->getTotal($featured = '1');
$model->setState('filter.featured', '1');

$amount = (int) $model->getTotal();

$result = [];

Expand All @@ -177,55 +183,4 @@ public function getQuickiconFeatured()

echo new JsonResponse($result);
}

/**
* Removes an item.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function delete()
{
// Check for request forgeries
$this->checkToken();

$articlesModel = $this->getModel('articles');
$featured = $articlesModel->isFeatured();

// Delete unfeatured items.
if ($featured === '0') {
parent::delete();
return;
}

// Delete featured items.
$user = $this->app->getIdentity();
$ids = (array) $this->input->get('cid', [], 'array');

// Access checks.
foreach ($ids as $i => $id) {
if (!$user->authorise('core.delete', 'com_content.article.' . (int) $id)) {
// Prune items that you can't delete.
unset($ids[$i]);
$this->app->enqueueMessage(Text::_('JERROR_CORE_DELETE_NOT_PERMITTED'), 'notice');
}
}

if (empty($ids)) {
$this->app->enqueueMessage(Text::_('JERROR_NO_ITEMS_SELECTED'), 'error');
return;
}

/** @var \Joomla\Component\Content\Administrator\Model\FeatureModel $model */
$featureModel = $this->getModel('Feature');

// Remove the items.
if (!$featureModel->featured($ids, 0)) {
$this->app->enqueueMessage($featureModel->getError(), 'error');
}

$this->setMessage(Text::plural('COM_CONTENT_N_ITEMS_DELETED', \count($ids)));
$this->setRedirect('index.php?option=com_content&view=articles&featured=1');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public function display($cachable = false, $urlparams = [])
return false;
}

if ($view === 'featured') {
$this->setRedirect(Route::_('index.php?option=com_content&view=articles&featured=1', false));
if ($view === 'featured' || $this->input->getInt('featured')) {
$this->setRedirect(Route::_('index.php?option=com_content&view=articles&filter[featured]=1', false));
return false;
}

Expand Down
62 changes: 13 additions & 49 deletions administrator/components/com_content/src/Model/ArticlesModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,9 @@ public function __construct($config = [], ?MVCFactoryInterface $factory = null)
'rating_count', 'rating',
'stage', 'wa.stage_id',
'ws.title',
'fp.ordering',
];

if ($this->isFeatured() === '1') {
$config['filter_fields'][] = 'fp.ordering';
}

if (Associations::isEnabled()) {
$config['filter_fields'][] = 'association';
}
Expand Down Expand Up @@ -179,6 +176,7 @@ protected function getStoreId($id = '')
$id .= ':' . $this->getState('filter.search');
$id .= ':' . serialize($this->getState('filter.access'));
$id .= ':' . $this->getState('filter.published');
$id .= ':' . $this->getState('filter.featured');
$id .= ':' . serialize($this->getState('filter.category_id'));
$id .= ':' . serialize($this->getState('filter.author_id'));
$id .= ':' . $this->getState('filter.language');
Expand Down Expand Up @@ -314,19 +312,22 @@ protected function getListQuery()
}

// Filter by featured.
$featured = $this->isFeatured();
$featured = $this->getState('filter.featured');

if ($featured === '1') {
$query->select($db->quoteName('fp.ordering'));
$defaultOrdering = 'fp.ordering';
} else {
$defaultOrdering = 'a.id';
}
$defaultOrdering = 'a.id';

if (\in_array($featured, ['0', '1'])) {
if (is_numeric($featured) && \in_array($featured, [0, 1])) {
$featured = (int) $featured;
$query->where($db->quoteName('a.featured') . ' = :featured')
->bind(':featured', $featured, ParameterType::INTEGER);

$query->where($db->quoteName('a.featured') . ' = :featured')
->bind(':featured', $featured, ParameterType::INTEGER);

if ($featured) {
$query->select($db->quoteName('fp.ordering'));
$defaultOrdering = 'fp.ordering';
}
}

// Filter by access level on categories.
Expand Down Expand Up @@ -643,41 +644,4 @@ public function getItems()

return $items;
}

/**
* Get total of articles
*
* @param string $featured Featured selector
*
* @return integer Total number of articles
*
* @since __DEPLOY_VERSION__
*/
public function getTotal($featured = '')
{
$db = $this->getDatabase();
$query = $db->getQuery(true);

$query->select('COUNT(*)')
->from($db->quoteName('#__content'))
->where($db->quoteName('state') . ' = 1');

if ($featured) {
$query->where($db->quoteName('featured') . ' = 1');
}

return (int) $db->setQuery($query)->loadResult();
}

/**
* Method to get the value of featured selector.
*
* @return string Returns the value of featured selector.
*
* @since __DEPLOY_VERSION__
*/
public function isFeatured()
{
return $this->getUserStateFromRequest($this->context . '.featured', 'featured', 'int');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ public function display($tpl = null)
$this->vote = PluginHelper::isEnabled('content', 'vote');
$this->hits = ComponentHelper::getParams('com_content')->get('record_hits', 1) == 1;

$featured = $this->state->get('filter.featured');

if (!\count($this->items) && $this->isEmptyState = $model->getIsEmptyState()) {
$this->setLayout('emptystate');
}
Expand All @@ -134,7 +132,7 @@ public function display($tpl = null)

// Check for errors.

if (\count($errors = $model->getErrors()) || $this->transitions === false && $featured === '1') {
if (\count($errors = $model->getErrors()) || $this->transitions === false) {
throw new GenericDataException(implode("\n", $errors), 500);
}

Expand Down Expand Up @@ -186,14 +184,9 @@ protected function addToolbar()
{
$canDo = ContentHelper::getActions('com_content', 'category', $this->state->get('filter.category_id'));
$user = $this->getCurrentUser();
$featured = $this->state->get('filter.featured');
$toolbar = $this->getDocument()->getToolbar();

if ($featured === '1') {
ToolbarHelper::title(Text::_('COM_CONTENT_FEATURED_TITLE'), 'star featured');
} else {
ToolbarHelper::title(Text::_('COM_CONTENT_ARTICLES_TITLE'), 'copy article');
}
ToolbarHelper::title(Text::_('COM_CONTENT_ARTICLES_TITLE'), 'copy article');

if ($canDo->get('core.create') || \count($user->getAuthorisedCategories('com_content', 'core.create')) > 0) {
$toolbar->addNew('article.add');
Expand Down Expand Up @@ -252,7 +245,6 @@ protected function addToolbar()
if (
$user->authorise('core.create', 'com_content')
&& $user->authorise('core.edit', 'com_content')
&& $featured !== '1'
) {
$childBar->popupButton('batch', 'JTOOLBAR_BATCH')
->popupType('inline')
Expand Down
4 changes: 2 additions & 2 deletions administrator/components/com_menus/presets/alternate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
quicktask-title="COM_CONTENT_MENUS_NEW_ARTICLE"
type="component"
element="com_content"
link="index.php?option=com_content&amp;view=articles&amp;featured=0"
link="index.php?option=com_content&amp;view=articles"
quicktask="index.php?option=com_content&amp;task=article.add"
/>

Expand All @@ -294,7 +294,7 @@
title="COM_CONTENT_MENUS_FEATURED"
type="component"
element="com_content"
link="index.php?option=com_content&amp;view=articles&amp;featured=1"
link="index.php?option=com_content&amp;view=articles&amp;filter[featured]=1"
/>

<menuitem
Expand Down
4 changes: 2 additions & 2 deletions administrator/components/com_menus/presets/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
quicktask-title="COM_CONTENT_MENUS_NEW_ARTICLE"
type="component"
element="com_content"
link="index.php?option=com_content&amp;view=articles&amp;featured=0"
link="index.php?option=com_content&amp;view=articles"
quicktask="index.php?option=com_content&amp;task=article.add"
/>

Expand All @@ -41,7 +41,7 @@
title="COM_CONTENT_MENUS_FEATURED"
type="component"
element="com_content"
link="index.php?option=com_content&amp;view=articles&amp;featured=1"
link="index.php?option=com_content&amp;view=articles&amp;filter[featured]=1"
class="class:featured"
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public function getButtons(Registry $params, ?CMSApplication $application = null
if ($params->get('show_featured')) {
$tmp = [
'image' => 'icon-star featured',
'link' => Route::_('index.php?option=com_content&view=articles&featured=1'),
'link' => Route::_('index.php?option=com_content&view=articles&filter[featured]=1'),
'name' => 'MOD_QUICKICON_FEATURED_MANAGER',
'access' => ['core.manage', 'com_content'],
'group' => 'MOD_QUICKICON_SITE',
Expand Down