- md5
- a10d44fab93849bb01353d316c6f3379
- sha1
- c28f4e7053f445e366de3ef4eb912602a88dbf79
- sha256
- bd892708a480e113ffcf2218f24cefd9da9a12bb0f262d9e41c7889784b37ea0
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
<?php
/**
* Joomla! Content Management System
*
* @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\CMS\Button;
use Joomla\CMS\Date\Date;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
/**
* The PublishedButton class.
*
* @since 4.0.0
*/
class PublishedButton extends ActionButton
{
/**
* Configure this object.
*
* @return void
*
* @since 4.0.0
*/
protected function preprocess()
{
$this->addState(1, 'unpublish', 'publish', 'JLIB_HTML_UNPUBLISH_ITEM', ['tip_title' => 'JPUBLISHED']);
$this->addState(0, 'publish', 'unpublish', 'JLIB_HTML_PUBLISH_ITEM', ['tip_title' => 'JUNPUBLISHED']);
$this->addState(2, 'unpublish', 'archive', 'JLIB_HTML_UNPUBLISH_ITEM', ['tip_title' => 'JARCHIVED']);
$this->addState(-2, 'publish', 'trash', 'JLIB_HTML_PUBLISH_ITEM', ['tip_title' => 'JTRASHED']);
}
/**
* Render action button by item value.
*
* @param mixed $value Current value of this item.
* @param string $row The row number of this item.
* @param array $options The options to override group options.
* @param string|Date $publishUp The date which item publish up.
* @param string|Date $publishDown The date which item publish down.
*
* @return string Rendered HTML.
*
* @since 4.0.0
*/
public function render(string $value = null, string $row = null, array $options = [], $publishUp = null, $publishDown = null): string
{
if ($publishUp || $publishDown)
{
$bakState = $this->getState($value);
$default = $this->getState($value) ? : $this->getState('_default');
$nullDate = Factory::getDbo()->getNullDate();
$nowDate = Factory::getDate()->toUnix();
$tz = Factory::getUser()->getTimezone();
$publishUp = ($publishUp !== $nullDate) ? Factory::getDate($publishUp, 'UTC')->setTimeZone($tz) : null;
$publishDown = ($publishDown !== $nullDate) ? Factory::getDate($publishDown, 'UTC')->setTimeZone($tz) : null;
// Add tips and special titles
// Create special titles for published items
if ($value === '1')
{
// Create tip text, only we have publish up or down settings
$tips = array();
if ($publishUp)
{
$tips[] = Text::sprintf('JLIB_HTML_PUBLISHED_START', HTMLHelper::_('date', $publishUp, Text::_('DATE_FORMAT_LC5'), 'UTC'));
}
if ($publishDown)
{
$tips[] = Text::sprintf('JLIB_HTML_PUBLISHED_FINISHED', HTMLHelper::_('date', $publishDown, Text::_('DATE_FORMAT_LC5'), 'UTC'));
}
$tip = empty($tips) ? false : implode('<br>', $tips);
$default['title'] = $tip;
$options['tip_title'] = 'JLIB_HTML_PUBLISHED_ITEM';
if ($publishUp > $nullDate && $nowDate < $publishUp->toUnix())
{
$options['tip_title'] = 'JLIB_HTML_PUBLISHED_PENDING_ITEM';
$default['icon'] = 'pending';
}
if ($publishDown > $nullDate && $nowDate > $publishDown->toUnix())
{
$options['tip_title'] = 'JLIB_HTML_PUBLISHED_EXPIRED_ITEM';
$default['icon'] = 'expired';
}
}
$this->states[$value] = $default;
$html = parent::render($value, $row, $options);
$this->states[$value] = $bakState;
return $html;
}
return parent::render($value, $row, $options);
}
}
The same content is in 3 releases, Joomla 4.0.0-alpha3 to 4.0.0-alpha6. See them all, or every version of this file.