[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/modules/mod_stats/src/Helper/ -> StatsHelper.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Site
   5   * @subpackage  mod_stats
   6   *
   7   * @copyright   (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  namespace Joomla\Module\Stats\Site\Helper;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\HTML\HTMLHelper;
  15  use Joomla\CMS\Language\Text;
  16  use Joomla\CMS\Plugin\PluginHelper;
  17  use Joomla\Component\Content\Administrator\Extension\ContentComponent;
  18  
  19  // phpcs:disable PSR1.Files.SideEffects
  20  \defined('_JEXEC') or die;
  21  // phpcs:enable PSR1.Files.SideEffects
  22  
  23  /**
  24   * Helper for mod_stats
  25   *
  26   * @since  1.5
  27   */
  28  class StatsHelper
  29  {
  30      /**
  31       * Get list of stats
  32       *
  33       * @param   \Joomla\Registry\Registry  &$params  module parameters
  34       *
  35       * @return  array
  36       */
  37      public static function &getList(&$params)
  38      {
  39          $app        = Factory::getApplication();
  40          $db         = Factory::getDbo();
  41          $rows       = array();
  42          $query      = $db->getQuery(true);
  43          $serverinfo = $params->get('serverinfo', 0);
  44          $siteinfo   = $params->get('siteinfo', 0);
  45          $counter    = $params->get('counter', 0);
  46          $increase   = $params->get('increase', 0);
  47  
  48          $i = 0;
  49  
  50          if ($serverinfo) {
  51              $rows[$i] = new \stdClass();
  52              $rows[$i]->title = Text::_('MOD_STATS_OS');
  53              $rows[$i]->data  = substr(php_uname(), 0, 7);
  54              $i++;
  55  
  56              $rows[$i] = new \stdClass();
  57              $rows[$i]->title = Text::_('MOD_STATS_PHP');
  58              $rows[$i]->data  = PHP_VERSION;
  59              $i++;
  60  
  61              $rows[$i] = new \stdClass();
  62              $rows[$i]->title = Text::_($db->name);
  63              $rows[$i]->data  = $db->getVersion();
  64              $i++;
  65  
  66              $rows[$i] = new \stdClass();
  67              $rows[$i]->title = Text::_('MOD_STATS_TIME');
  68              $rows[$i]->data  = HTMLHelper::_('date', 'now', 'H:i');
  69              $i++;
  70  
  71              $rows[$i] = new \stdClass();
  72              $rows[$i]->title = Text::_('MOD_STATS_CACHING');
  73              $rows[$i]->data  = $app->get('caching') ? Text::_('JENABLED') : Text::_('JDISABLED');
  74              $i++;
  75  
  76              $rows[$i] = new \stdClass();
  77              $rows[$i]->title = Text::_('MOD_STATS_GZIP');
  78              $rows[$i]->data  = $app->get('gzip') ? Text::_('JENABLED') : Text::_('JDISABLED');
  79              $i++;
  80          }
  81  
  82          if ($siteinfo) {
  83              $query->select('COUNT(' . $db->quoteName('id') . ') AS count_users')
  84                  ->from($db->quoteName('#__users'));
  85              $db->setQuery($query);
  86  
  87              try {
  88                  $users = $db->loadResult();
  89              } catch (\RuntimeException $e) {
  90                  $users = false;
  91              }
  92  
  93              $query->clear()
  94                  ->select('COUNT(' . $db->quoteName('c.id') . ') AS count_items')
  95                  ->from($db->quoteName('#__content', 'c'))
  96                  ->where($db->quoteName('c.state') . ' = ' . ContentComponent::CONDITION_PUBLISHED);
  97              $db->setQuery($query);
  98  
  99              try {
 100                  $items = $db->loadResult();
 101              } catch (\RuntimeException $e) {
 102                  $items = false;
 103              }
 104  
 105              if ($users) {
 106                  $rows[$i] = new \stdClass();
 107                  $rows[$i]->title = Text::_('MOD_STATS_USERS');
 108                  $rows[$i]->data  = $users;
 109                  $i++;
 110              }
 111  
 112              if ($items) {
 113                  $rows[$i] = new \stdClass();
 114                  $rows[$i]->title = Text::_('MOD_STATS_ARTICLES');
 115                  $rows[$i]->data  = $items;
 116                  $i++;
 117              }
 118          }
 119  
 120          if ($counter) {
 121              $query->clear()
 122                  ->select('SUM(' . $db->quoteName('hits') . ') AS count_hits')
 123                  ->from($db->quoteName('#__content'))
 124                  ->where($db->quoteName('state') . ' = ' . ContentComponent::CONDITION_PUBLISHED);
 125              $db->setQuery($query);
 126  
 127              try {
 128                  $hits = $db->loadResult();
 129              } catch (\RuntimeException $e) {
 130                  $hits = false;
 131              }
 132  
 133              if ($hits) {
 134                  $rows[$i] = new \stdClass();
 135                  $rows[$i]->title = Text::_('MOD_STATS_ARTICLES_VIEW_HITS');
 136                  $rows[$i]->data  = $hits + $increase;
 137                  $i++;
 138              }
 139          }
 140  
 141          // Include additional data defined by published system plugins
 142          PluginHelper::importPlugin('system');
 143  
 144          $arrays = (array) $app->triggerEvent('onGetStats', array('mod_stats'));
 145  
 146          foreach ($arrays as $response) {
 147              foreach ($response as $row) {
 148                  // We only add a row if the title and data are given
 149                  if (isset($row['title']) && isset($row['data'])) {
 150                      $rows[$i]        = new \stdClass();
 151                      $rows[$i]->title = $row['title'];
 152                      $rows[$i]->icon  = $row['icon'] ?? 'info';
 153                      $rows[$i]->data  = $row['data'];
 154                      $i++;
 155                  }
 156              }
 157          }
 158  
 159          return $rows;
 160      }
 161  }


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