[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/modules/mod_stats_admin/src/Helper/ -> StatsAdminHelper.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  mod_stats_admin
   6   *
   7   * @copyright   (C) 2012 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\StatsAdmin\Administrator\Helper;
  12  
  13  use Joomla\CMS\Application\CMSApplication;
  14  use Joomla\CMS\Language\Text;
  15  use Joomla\CMS\Plugin\PluginHelper;
  16  use Joomla\CMS\Router\Route;
  17  use Joomla\Database\DatabaseInterface;
  18  use Joomla\Registry\Registry;
  19  
  20  // phpcs:disable PSR1.Files.SideEffects
  21  \defined('_JEXEC') or die;
  22  // phpcs:enable PSR1.Files.SideEffects
  23  
  24  /**
  25   * Helper class for admin stats module
  26   *
  27   * @since  3.0
  28   */
  29  class StatsAdminHelper
  30  {
  31      /**
  32       * Method to retrieve information about the site
  33       *
  34       * @param   Registry           $params  The module parameters
  35       * @param   CMSApplication     $app     The application
  36       * @param   DatabaseInterface  $db      The database
  37       *
  38       * @return  array  Array containing site information
  39       *
  40       * @since   3.0
  41       */
  42      public static function getStats(Registry $params, CMSApplication $app, DatabaseInterface $db)
  43      {
  44          $user = $app->getIdentity();
  45  
  46          $rows  = array();
  47          $query = $db->getQuery(true);
  48  
  49          $serverinfo = $params->get('serverinfo', 0);
  50          $siteinfo   = $params->get('siteinfo', 0);
  51  
  52          $i = 0;
  53  
  54          if ($serverinfo) {
  55              $rows[$i]        = new \stdClass();
  56              $rows[$i]->title = Text::_('MOD_STATS_PHP');
  57              $rows[$i]->icon  = 'cogs';
  58              $rows[$i]->data  = PHP_VERSION;
  59              $i++;
  60  
  61              $rows[$i]        = new \stdClass();
  62              $rows[$i]->title = Text::_($db->name);
  63              $rows[$i]->icon  = 'database';
  64              $rows[$i]->data  = $db->getVersion();
  65              $i++;
  66  
  67              $rows[$i]        = new \stdClass();
  68              $rows[$i]->title = Text::_('MOD_STATS_CACHING');
  69              $rows[$i]->icon  = 'tachometer-alt';
  70              $rows[$i]->data  = $app->get('caching') ? Text::_('JENABLED') : Text::_('JDISABLED');
  71              $i++;
  72  
  73              $rows[$i]        = new \stdClass();
  74              $rows[$i]->title = Text::_('MOD_STATS_GZIP');
  75              $rows[$i]->icon  = 'bolt';
  76              $rows[$i]->data  = $app->get('gzip') ? Text::_('JENABLED') : Text::_('JDISABLED');
  77              $i++;
  78          }
  79  
  80          if ($siteinfo) {
  81              $query->select('COUNT(id) AS count_users')
  82                  ->from('#__users');
  83              $db->setQuery($query);
  84  
  85              try {
  86                  $users = $db->loadResult();
  87              } catch (\RuntimeException $e) {
  88                  $users = false;
  89              }
  90  
  91              $query->clear()
  92                  ->select('COUNT(id) AS count_items')
  93                  ->from('#__content')
  94                  ->where('state = 1');
  95              $db->setQuery($query);
  96  
  97              try {
  98                  $items = $db->loadResult();
  99              } catch (\RuntimeException $e) {
 100                  $items = false;
 101              }
 102  
 103              if ($users) {
 104                  $rows[$i]        = new \stdClass();
 105                  $rows[$i]->title = Text::_('MOD_STATS_USERS');
 106                  $rows[$i]->icon  = 'users';
 107                  $rows[$i]->data  = $users;
 108  
 109                  if ($user->authorise('core.manage', 'com_users')) {
 110                      $rows[$i]->link = Route::_('index.php?option=com_users');
 111                  }
 112  
 113                  $i++;
 114              }
 115  
 116              if ($items) {
 117                  $rows[$i]        = new \stdClass();
 118                  $rows[$i]->title = Text::_('MOD_STATS_ARTICLES');
 119                  $rows[$i]->icon  = 'file';
 120                  $rows[$i]->data  = $items;
 121                  $rows[$i]->link  = Route::_('index.php?option=com_content&view=articles&filter[published]=1');
 122                  $i++;
 123              }
 124          }
 125  
 126          // Include additional data defined by published system plugins
 127          PluginHelper::importPlugin('system');
 128  
 129          $arrays = (array) $app->triggerEvent('onGetStats', array('mod_stats_admin'));
 130  
 131          foreach ($arrays as $response) {
 132              foreach ($response as $row) {
 133                  // We only add a row if the title and data are given
 134                  if (isset($row['title']) && isset($row['data'])) {
 135                      $rows[$i]        = new \stdClass();
 136                      $rows[$i]->title = $row['title'];
 137                      $rows[$i]->icon  = $row['icon'] ?? 'info';
 138                      $rows[$i]->data  = $row['data'];
 139                      $rows[$i]->link  = isset($row['link']) ? $row['link'] : null;
 140                      $i++;
 141                  }
 142              }
 143          }
 144  
 145          return $rows;
 146      }
 147  }


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