[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/HTML/Helpers/ -> Content.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2009 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\HTML\Helpers;
  11  
  12  use Joomla\CMS\Date\Date;
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\HTML\HTMLHelper;
  15  use Joomla\CMS\Object\CMSObject;
  16  use Joomla\CMS\Plugin\PluginHelper;
  17  use Joomla\Registry\Registry;
  18  
  19  // phpcs:disable PSR1.Files.SideEffects
  20  \defined('JPATH_PLATFORM') or die;
  21  // phpcs:enable PSR1.Files.SideEffects
  22  
  23  /**
  24   * Utility class to fire onContentPrepare for non-article based content.
  25   *
  26   * @since  1.5
  27   */
  28  abstract class Content
  29  {
  30      /**
  31       * Fire onContentPrepare for content that isn't part of an article.
  32       *
  33       * @param   string  $text     The content to be transformed.
  34       * @param   array   $params   The content params.
  35       * @param   string  $context  The context of the content to be transformed.
  36       *
  37       * @return  string   The content after transformation.
  38       *
  39       * @since   1.5
  40       */
  41      public static function prepare($text, $params = null, $context = 'text')
  42      {
  43          if ($params === null) {
  44              $params = new CMSObject();
  45          }
  46  
  47          $article = new \stdClass();
  48          $article->text = $text;
  49          PluginHelper::importPlugin('content');
  50          Factory::getApplication()->triggerEvent('onContentPrepare', array($context, &$article, &$params, 0));
  51  
  52          return $article->text;
  53      }
  54  
  55      /**
  56       * Returns an array of months.
  57       *
  58       * @param   Registry  $state  The state object.
  59       *
  60       * @return  array
  61       *
  62       * @since   3.9.0
  63       */
  64      public static function months($state)
  65      {
  66          /** @var \Joomla\Component\Content\Administrator\Extension\ContentComponent $contentComponent */
  67          $contentComponent = Factory::getApplication()->bootComponent('com_content');
  68  
  69          /** @var \Joomla\Component\Content\Site\Model\ArticlesModel $model */
  70          $model = $contentComponent->getMVCFactory()
  71              ->createModel('Articles', 'Site', ['ignore_request' => true]);
  72  
  73          foreach ($state as $key => $value) {
  74              $model->setState($key, $value);
  75          }
  76  
  77          $model->setState('filter.category_id', $state->get('category.id'));
  78          $model->setState('list.start', 0);
  79          $model->setState('list.limit', -1);
  80          $model->setState('list.direction', 'asc');
  81          $model->setState('list.filter', '');
  82  
  83          $items = array();
  84  
  85          foreach ($model->countItemsByMonth() as $item) {
  86              $date    = new Date($item->d);
  87              $items[] = HTMLHelper::_('select.option', $item->d, $date->format('F Y') . ' [' . $item->c . ']');
  88          }
  89  
  90          return $items;
  91      }
  92  }


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