[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Button/ -> PublishedButton.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  namespace Joomla\CMS\Button;
  11  
  12  use Joomla\CMS\Date\Date;
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\HTML\HTMLHelper;
  15  use Joomla\CMS\Language\Text;
  16  
  17  // phpcs:disable PSR1.Files.SideEffects
  18  \defined('_JEXEC') or die;
  19  // phpcs:enable PSR1.Files.SideEffects
  20  
  21  /**
  22   * The PublishedButton class.
  23   *
  24   * @since  4.0.0
  25   */
  26  class PublishedButton extends ActionButton
  27  {
  28      /**
  29       * Configure this object.
  30       *
  31       * @return  void
  32       *
  33       * @since  4.0.0
  34       */
  35      protected function preprocess()
  36      {
  37          $this->addState(1, 'unpublish', 'publish', Text::_('JLIB_HTML_UNPUBLISH_ITEM'), ['tip_title' => Text::_('JPUBLISHED')]);
  38          $this->addState(0, 'publish', 'unpublish', Text::_('JLIB_HTML_PUBLISH_ITEM'), ['tip_title' => Text::_('JUNPUBLISHED')]);
  39          $this->addState(2, 'unpublish', 'archive', Text::_('JLIB_HTML_UNPUBLISH_ITEM'), ['tip_title' => Text::_('JARCHIVED')]);
  40          $this->addState(-2, 'publish', 'trash', Text::_('JLIB_HTML_PUBLISH_ITEM'), ['tip_title' => Text::_('JTRASHED')]);
  41      }
  42  
  43      /**
  44       * Render action button by item value.
  45       *
  46       * @param   integer|null  $value        Current value of this item.
  47       * @param   integer|null  $row          The row number of this item.
  48       * @param   array         $options      The options to override group options.
  49       * @param   string|Date   $publishUp    The date which item publish up.
  50       * @param   string|Date   $publishDown  The date which item publish down.
  51       *
  52       * @return  string  Rendered HTML.
  53       *
  54       * @since  4.0.0
  55       */
  56      public function render(?int $value = null, ?int $row = null, array $options = [], $publishUp = null, $publishDown = null): string
  57      {
  58          if ($publishUp || $publishDown) {
  59              $bakState = $this->getState($value);
  60              $default  = $this->getState($value) ?? $this->unknownState;
  61  
  62              $nullDate = Factory::getDbo()->getNullDate();
  63              $nowDate = Factory::getDate()->toUnix();
  64  
  65              $tz = Factory::getUser()->getTimezone();
  66  
  67              $publishUp   = ($publishUp !== null && $publishUp !== $nullDate) ? Factory::getDate($publishUp, 'UTC')->setTimezone($tz) : false;
  68              $publishDown = ($publishDown !== null && $publishDown !== $nullDate) ? Factory::getDate($publishDown, 'UTC')->setTimezone($tz) : false;
  69  
  70              // Add tips and special titles
  71              // Create special titles for published items
  72              if ($value === 1) {
  73                  // Create tip text, only we have publish up or down settings
  74                  $tips = array();
  75  
  76                  if ($publishUp) {
  77                      $tips[] = Text::sprintf('JLIB_HTML_PUBLISHED_START', HTMLHelper::_('date', $publishUp, Text::_('DATE_FORMAT_LC5'), 'UTC'));
  78                      $tips[] = Text::_('JLIB_HTML_PUBLISHED_UNPUBLISH');
  79                  }
  80  
  81                  if ($publishDown) {
  82                      $tips[] = Text::sprintf('JLIB_HTML_PUBLISHED_FINISHED', HTMLHelper::_('date', $publishDown, Text::_('DATE_FORMAT_LC5'), 'UTC'));
  83                  }
  84  
  85                  $tip = empty($tips) ? false : implode('<br>', $tips);
  86  
  87                  $default['title'] = $tip;
  88  
  89                  $options['tip_title'] = Text::_('JLIB_HTML_PUBLISHED_ITEM');
  90  
  91                  if ($publishUp && $nowDate < $publishUp->toUnix()) {
  92                      $options['tip_title'] = Text::_('JLIB_HTML_PUBLISHED_PENDING_ITEM');
  93                      $default['icon'] = 'pending';
  94                  }
  95  
  96                  if ($publishDown && $nowDate > $publishDown->toUnix()) {
  97                      $options['tip_title'] = Text::_('JLIB_HTML_PUBLISHED_EXPIRED_ITEM');
  98                      $default['icon'] = 'expired';
  99                  }
 100  
 101                  if (array_key_exists('category_published', $options)) {
 102                      $categoryPublished = $options['category_published'];
 103  
 104                      if ($categoryPublished === 0) {
 105                          $options['tip_title'] = Text::_('JLIB_HTML_ITEM_PUBLISHED_BUT_CATEGORY_UNPUBLISHED');
 106                          $default['icon'] = 'expired';
 107                      }
 108  
 109                      if ($categoryPublished === -2) {
 110                          $options['tip_title'] = Text::_('JLIB_HTML_ITEM_PUBLISHED_BUT_CATEGORY_TRASHED');
 111                          $default['icon'] = 'expired';
 112                      }
 113                  }
 114              }
 115  
 116              $this->states[$value] = $default;
 117  
 118              $html = parent::render($value, $row, $options);
 119  
 120              $this->states[$value] = $bakState;
 121  
 122              return $html;
 123          }
 124  
 125          return parent::render($value, $row, $options);
 126      }
 127  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer