- md5
- 3220cf4fe0ec17a99927f407bf04ab18
- sha1
- d58e3610d3f12833892f2ed9cd7d309a1e206cc3
- sha256
- 6f0cccce3dc92b6157ab56d353af3ee2f7ccb507918a4fee27cacb780601ea21
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
<?php
/**
* @package Joomla.Administrator
* @subpackage com_content
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
/**
* Content component helper.
*
* @since 1.6
*/
class ContentHelper extends JHelperContent
{
public static $extension = 'com_content';
/**
* Configure the Linkbar.
*
* @param string $vName The name of the active view.
*
* @return void
*
* @since 1.6
*/
public static function addSubmenu($vName)
{
JHtmlSidebar::addEntry(
JText::_('JGLOBAL_ARTICLES'),
'index.php?option=com_content&view=articles',
$vName == 'articles'
);
JHtmlSidebar::addEntry(
JText::_('COM_CONTENT_SUBMENU_CATEGORIES'),
'index.php?option=com_categories&extension=com_content',
$vName == 'categories'
);
JHtmlSidebar::addEntry(
JText::_('COM_CONTENT_SUBMENU_FEATURED'),
'index.php?option=com_content&view=featured',
$vName == 'featured'
);
if (JComponentHelper::isEnabled('com_fields') && JComponentHelper::getParams('com_content')->get('custom_fields_enable', '1'))
{
JHtmlSidebar::addEntry(
JText::_('JGLOBAL_FIELDS'),
'index.php?option=com_fields&context=com_content.article',
$vName == 'fields.fields'
);
JHtmlSidebar::addEntry(
JText::_('JGLOBAL_FIELD_GROUPS'),
'index.php?option=com_fields&view=groups&context=com_content.article',
$vName == 'fields.groups'
);
}
}
/**
* Applies the content tag filters to arbitrary text as per settings for current user group
*
* @param text $text The string to filter
*
* @return string The filtered string
*
* @deprecated 4.0 Use JComponentHelper::filterText() instead.
*/
public static function filterText($text)
{
try
{
JLog::add(
sprintf('%s() is deprecated. Use JComponentHelper::filterText() instead', __METHOD__),
JLog::WARNING,
'deprecated'
);
}
catch (RuntimeException $exception)
{
// Informational log only
}
return JComponentHelper::filterText($text);
}
/**
* Adds Count Items for Category Manager.
*
* @param stdClass[] $items The banner category objects
*
* @return stdClass[]
*
* @since 3.5
*/
public static function countItems(&$items)
{
$db = JFactory::getDbo();
foreach ($items as $item)
{
$item->count_trashed = 0;
$item->count_archived = 0;
$item->count_unpublished = 0;
$item->count_published = 0;
$query = $db->getQuery(true);
$query->select('state, count(*) AS count')
->from($db->qn('#__content'))
->where('catid = ' . (int) $item->id)
->group('state');
$db->setQuery($query);
$articles = $db->loadObjectList();
foreach ($articles as $article)
{
if ($article->state == 1)
{
$item->count_published = $article->count;
}
if ($article->state == 0)
{
$item->count_unpublished = $article->count;
}
if ($article->state == 2)
{
$item->count_archived = $article->count;
}
if ($article->state == -2)
{
$item->count_trashed = $article->count;
}
}
}
return $items;
}
/**
* Adds Count Items for Tag Manager.
*
* @param stdClass[] $items The content objects
* @param string $extension The name of the active view.
*
* @return stdClass[]
*
* @since 3.6
*/
public static function countTagItems(&$items, $extension)
{
$db = JFactory::getDbo();
$parts = explode('.', $extension);
$section = null;
if (count($parts) > 1)
{
$section = $parts[1];
}
$join = $db->qn('#__content') . ' AS c ON ct.content_item_id=c.id';
$state = 'state';
if ($section === 'category')
{
$join = $db->qn('#__categories') . ' AS c ON ct.content_item_id=c.id';
$state = 'published as state';
}
foreach ($items as $item)
{
$item->count_trashed = 0;
$item->count_archived = 0;
$item->count_unpublished = 0;
$item->count_published = 0;
$query = $db->getQuery(true);
$query->select($state . ', count(*) AS count')
->from($db->qn('#__contentitem_tag_map') . 'AS ct ')
->where('ct.tag_id = ' . (int) $item->id)
->where('ct.type_alias =' . $db->q($extension))
->join('LEFT', $join)
->group('state');
$db->setQuery($query);
$contents = $db->loadObjectList();
foreach ($contents as $content)
{
if ($content->state == 1)
{
$item->count_published = $content->count;
}
if ($content->state == 0)
{
$item->count_unpublished = $content->count;
}
if ($content->state == 2)
{
$item->count_archived = $content->count;
}
if ($content->state == -2)
{
$item->count_trashed = $content->count;
}
}
}
return $items;
}
/**
* Returns a valid section for articles. If it is not valid then null
* is returned.
*
* @param string $section The section to get the mapping for
*
* @return string|null The new section
*
* @since 3.7.0
*/
public static function validateSection($section)
{
if (JFactory::getApplication()->isClient('site'))
{
// On the front end we need to map some sections
switch ($section)
{
// Editing an article
case 'form':
// Category list view
case 'featured':
case 'category':
$section = 'article';
}
}
if ($section != 'article')
{
// We don't know other sections
return null;
}
return $section;
}
/**
* Returns valid contexts
*
* @return array
*
* @since 3.7.0
*/
public static function getContexts()
{
JFactory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR);
$contexts = array(
'com_content.article' => JText::_('COM_CONTENT'),
'com_content.categories' => JText::_('JCATEGORY')
);
return $contexts;
}
}
The same content is in 16 releases, Joomla 3.8.9-rc to 3.9.0. See them all, or every version of this file.