- md5
- 0b76f907e20cecca1ebaf097b47a8bf2
- sha1
- 1214b48a1d328eca23d71b78d926c1166a6321f8
- sha256
- eb0870c2952bbed2f3bd30092ebfdda77d071f64bed21078c77e4fb12e054b83
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
<?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
*/
namespace Joomla\Component\Content\Administrator\Extension;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Application\SiteApplication;
use Joomla\CMS\Association\AssociationServiceInterface;
use Joomla\CMS\Association\AssociationServiceTrait;
use Joomla\CMS\Categories\CategoryServiceInterface;
use Joomla\CMS\Categories\CategoryServiceTrait;
use Joomla\CMS\Component\Router\RouterServiceInterface;
use Joomla\CMS\Component\Router\RouterServiceTrait;
use Joomla\CMS\Extension\BootableExtensionInterface;
use Joomla\CMS\Extension\MVCComponent;
use Joomla\CMS\Factory;
use Joomla\CMS\Fields\FieldsServiceInterface;
use Joomla\CMS\Form\Form;
use Joomla\CMS\HTML\HTMLRegistryAwareTrait;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Workflow\WorkflowServiceInterface;
use Joomla\CMS\Workflow\WorkflowServiceTrait;
use Joomla\Component\Content\Administrator\Helper\ContentHelper;
use Joomla\Component\Content\Administrator\Service\HTML\AdministratorService;
use Joomla\Component\Content\Administrator\Service\HTML\Icon;
use Psr\Container\ContainerInterface;
/**
* Component class for com_content
*
* @since 4.0.0
*/
class ContentComponent extends MVCComponent implements
BootableExtensionInterface, CategoryServiceInterface, FieldsServiceInterface, AssociationServiceInterface,
WorkflowServiceInterface, RouterServiceInterface
{
use CategoryServiceTrait;
use AssociationServiceTrait;
use RouterServiceTrait;
use HTMLRegistryAwareTrait;
use WorkflowServiceTrait;
/**
* The trashed condition
*
* @since 4.0.0
*/
const CONDITION_NAMES = [
self::CONDITION_PUBLISHED => 'JPUBLISHED',
self::CONDITION_UNPUBLISHED => 'JUNPUBLISHED',
self::CONDITION_ARCHIVED => 'JARCHIVED',
self::CONDITION_TRASHED => 'JTRASHED',
];
/**
* The archived condition
*
* @since 4.0.0
*/
const CONDITION_ARCHIVED = 2;
/**
* The published condition
*
* @since 4.0.0
*/
const CONDITION_PUBLISHED = 1;
/**
* The unpublished condition
*
* @since 4.0.0
*/
const CONDITION_UNPUBLISHED = 0;
/**
* The trashed condition
*
* @since 4.0.0
*/
const CONDITION_TRASHED = -2;
/**
* Booting the extension. This is the function to set up the environment of the extension like
* registering new class loaders, etc.
*
* If required, some initial set up can be done from services of the container, eg.
* registering HTML services.
*
* @param ContainerInterface $container The container
*
* @return void
*
* @since 4.0.0
*/
public function boot(ContainerInterface $container)
{
$this->getRegistry()->register('contentadministrator', new AdministratorService);
$this->getRegistry()->register('contenticon', new Icon($container->get(SiteApplication::class)));
// The layout joomla.content.icons does need a general icon service
$this->getRegistry()->register('icon', $this->getRegistry()->getService('contenticon'));
}
/**
* Returns a valid section for the given section. If it is not valid then null
* is returned.
*
* @param string $section The section to get the mapping for
* @param object $item The item
*
* @return string|null The new section
*
* @since 4.0.0
*/
public function validateSection($section, $item = null)
{
if (Factory::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 4.0.0
*/
public function getContexts(): array
{
Factory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR);
$contexts = array(
'com_content.article' => Text::_('COM_CONTENT'),
'com_content.categories' => Text::_('JCATEGORY')
);
return $contexts;
}
/**
* Returns the table for the count items functions for the given section.
*
* @param string $section The section
*
* @return string|null
*
* @since 4.0.0
*/
protected function getTableNameForSection(string $section = null)
{
return '#__content';
}
/**
* Method to filter transitions by given id of state.
*
* @param array $transitions The Transitions to filter
* @param int $pk Id of the state
*
* @return array
*
* @since 4.0.0
*/
public function filterTransitions($transitions, $pk): array
{
return ContentHelper::filterTransitions($transitions, $pk);
}
/**
* Adds Count Items for Category Manager.
*
* @param \stdClass[] $items The category objects
* @param string $section The section
*
* @return void
*
* @since 4.0.0
*/
public function countItems(array $items, string $section)
{
$db = Factory::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($db->quoteName('condition'))
->select('COUNT(*) AS ' . $db->quoteName('count'))
->from($db->quoteName('#__content', 'c'))
->from($db->quoteName('#__workflow_stages', 's'))
->from($db->quoteName('#__workflow_associations', 'a'))
->where($db->quoteName('a.item_id') . ' = ' . $db->quoteName('c.id'))
->where($db->quoteName('s.id') . ' = ' . $db->quoteName('a.stage_id'))
->where($db->quoteName('catid') . ' = ' . (int) $item->id)
->where($db->quoteName('a.extension') . '= ' . $db->quote('com_content'))
->group($db->quoteName('condition'));
$articles = $db->setQuery($query)->loadObjectList();
foreach ($articles as $article)
{
if ($article->condition == self::CONDITION_PUBLISHED)
{
$item->count_published = $article->count;
}
if ($article->condition == self::CONDITION_UNPUBLISHED)
{
$item->count_unpublished = $article->count;
}
if ($article->condition == self::CONDITION_ARCHIVED)
{
$item->count_archived = $article->count;
}
if ($article->condition == self::CONDITION_TRASHED)
{
$item->count_trashed = $article->count;
}
}
}
}
/**
* Adds Count Items for Tag Manager.
*
* @param \stdClass[] $items The content objects
* @param string $extension The name of the active view.
*
* @return void
*
* @since 4.0.0
* @throws \Exception
*/
public function countTagItems(array $items, string $extension)
{
$db = Factory::getDbo();
$parts = explode('.', $extension);
$section = null;
if (count($parts) > 1)
{
$section = $parts[1];
}
$join = $db->quoteName('#__content', 'c') . ' ON ct.content_item_id=c.id';
$state = $db->quoteName('state');
if ($section === 'category')
{
$join = $db->quoteName('#__categories') . ' AS c ON ct.content_item_id=c.id';
$state = $db->quoteName('published', '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->quoteName('#__contentitem_tag_map', 'ct'))
->where($db->quoteName('ct.tag_id') . ' = ' . (int) $item->id)
->where($db->quoteName('ct.type_alias') . ' = ' . $db->quote($extension))
->join('LEFT', $join)
->group($db->quoteName('state'));
$db->setQuery($query);
$contents = $db->loadObjectList();
foreach ($contents as $content)
{
if ($content->state == self::CONDITION_PUBLISHED)
{
$item->count_published = $content->count;
}
if ($content->state == self::CONDITION_UNPUBLISHED)
{
$item->count_unpublished = $content->count;
}
if ($content->state == self::CONDITION_ARCHIVED)
{
$item->count_archived = $content->count;
}
if ($content->state == self::CONDITION_TRASHED)
{
$item->count_trashed = $content->count;
}
}
}
}
/**
* Prepares the category form
*
* @param Form $form The form to prepare
* @param array|object $data The form data
*
* @return void
*/
public function prepareForm(Form $form, $data)
{
ContentHelper::onPrepareForm($form, $data);
}
/**
* Method to change state of multiple ids
*
* @param array $pks Array of IDs
* @param int $condition Condition of the workflow state
*
* @return boolean
*
* @since 4.0.0
*/
public static function updateContentState($pks, $condition): bool
{
return ContentHelper::updateContentState($pks, $condition);
}
}
No other release has this exact content. See every version of this file.