[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_installer/src/Model/ -> WarningsModel.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_installer
   6   *
   7   * @copyright   (C) 2008 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\Component\Installer\Administrator\Model;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Language\Text;
  15  use Joomla\CMS\MVC\Model\ListModel;
  16  
  17  // phpcs:disable PSR1.Files.SideEffects
  18  \defined('_JEXEC') or die;
  19  // phpcs:enable PSR1.Files.SideEffects
  20  
  21  /**
  22   * Installer Warnings Model
  23   *
  24   * @since  1.6
  25   */
  26  class WarningsModel extends ListModel
  27  {
  28      /**
  29       * Extension Type
  30       * @var string
  31       */
  32      public $type = 'warnings';
  33  
  34      /**
  35       * Return the byte value of a particular string.
  36       *
  37       * @param   string  $val  String optionally with G, M or K suffix
  38       *
  39       * @return  integer   size in bytes
  40       *
  41       * @since 1.6
  42       */
  43      public function return_bytes($val)
  44      {
  45          if (empty($val)) {
  46              return 0;
  47          }
  48  
  49          $val = trim($val);
  50  
  51          preg_match('#([0-9]+)[\s]*([a-z]+)#i', $val, $matches);
  52  
  53          $last = '';
  54  
  55          if (isset($matches[2])) {
  56              $last = $matches[2];
  57          }
  58  
  59          if (isset($matches[1])) {
  60              $val = (int) $matches[1];
  61          }
  62  
  63          switch (strtolower($last)) {
  64              case 'g':
  65              case 'gb':
  66                  $val *= (1024 * 1024 * 1024);
  67                  break;
  68              case 'm':
  69              case 'mb':
  70                  $val *= (1024 * 1024);
  71                  break;
  72              case 'k':
  73              case 'kb':
  74                  $val *= 1024;
  75                  break;
  76          }
  77  
  78          return (int) $val;
  79      }
  80  
  81      /**
  82       * Load the data.
  83       *
  84       * @return  array  Messages
  85       *
  86       * @since   1.6
  87       */
  88      public function getItems()
  89      {
  90          static $messages;
  91  
  92          if ($messages) {
  93              return $messages;
  94          }
  95  
  96          $messages = [];
  97  
  98          // 16MB
  99          $minLimit = 16 * 1024 * 1024;
 100  
 101          $file_uploads = ini_get('file_uploads');
 102  
 103          if (!$file_uploads) {
 104              $messages[] = [
 105                  'message'     => Text::_('COM_INSTALLER_MSG_WARNINGS_FILEUPLOADSDISABLED'),
 106                  'description' => Text::_('COM_INSTALLER_MSG_WARNINGS_FILEUPLOADISDISABLEDDESC'),
 107              ];
 108          }
 109  
 110          $upload_dir = ini_get('upload_tmp_dir');
 111  
 112          if (!$upload_dir) {
 113              $messages[] = [
 114                  'message'     => Text::_('COM_INSTALLER_MSG_WARNINGS_PHPUPLOADNOTSET'),
 115                  'description' => Text::_('COM_INSTALLER_MSG_WARNINGS_PHPUPLOADNOTSETDESC'),
 116              ];
 117          } elseif (!is_writable($upload_dir)) {
 118              $messages[] = [
 119                  'message'     => Text::_('COM_INSTALLER_MSG_WARNINGS_PHPUPLOADNOTWRITEABLE'),
 120                  'description' => Text::sprintf('COM_INSTALLER_MSG_WARNINGS_PHPUPLOADNOTWRITEABLEDESC', $upload_dir),
 121              ];
 122          }
 123  
 124          $tmp_path = Factory::getApplication()->get('tmp_path');
 125  
 126          if (!$tmp_path) {
 127              $messages[] = [
 128                  'message'     => Text::_('COM_INSTALLER_MSG_WARNINGS_JOOMLATMPNOTSET'),
 129                  'description' => Text::_('COM_INSTALLER_MSG_WARNINGS_JOOMLATMPNOTSETDESC'),
 130              ];
 131          } elseif (!is_writable($tmp_path)) {
 132              $messages[] = [
 133                  'message'     => Text::_('COM_INSTALLER_MSG_WARNINGS_JOOMLATMPNOTWRITEABLE'),
 134                  'description' => Text::sprintf('COM_INSTALLER_MSG_WARNINGS_JOOMLATMPNOTWRITEABLEDESC', $tmp_path),
 135              ];
 136          }
 137  
 138          $memory_limit = $this->return_bytes(ini_get('memory_limit'));
 139  
 140          if ($memory_limit > -1) {
 141              if ($memory_limit < $minLimit) {
 142                  // 16MB
 143                  $messages[] = [
 144                      'message'     => Text::_('COM_INSTALLER_MSG_WARNINGS_LOWMEMORYWARN'),
 145                      'description' => Text::_('COM_INSTALLER_MSG_WARNINGS_LOWMEMORYDESC'),
 146                  ];
 147              } elseif ($memory_limit < ($minLimit * 1.5)) {
 148                  // 24MB
 149                  $messages[] = [
 150                      'message'     => Text::_('COM_INSTALLER_MSG_WARNINGS_MEDMEMORYWARN'),
 151                      'description' => Text::_('COM_INSTALLER_MSG_WARNINGS_MEDMEMORYDESC'),
 152                  ];
 153              }
 154          }
 155  
 156          $post_max_size       = $this->return_bytes(ini_get('post_max_size'));
 157          $upload_max_filesize = $this->return_bytes(ini_get('upload_max_filesize'));
 158  
 159          if ($post_max_size > 0 && $post_max_size < $upload_max_filesize) {
 160              $messages[] = [
 161                  'message'     => Text::_('COM_INSTALLER_MSG_WARNINGS_UPLOADBIGGERTHANPOST'),
 162                  'description' => Text::_('COM_INSTALLER_MSG_WARNINGS_UPLOADBIGGERTHANPOSTDESC'),
 163              ];
 164          }
 165  
 166          if ($post_max_size > 0 && $post_max_size < $minLimit) {
 167              $messages[] = [
 168                  'message'     => Text::_('COM_INSTALLER_MSG_WARNINGS_SMALLPOSTSIZE'),
 169                  'description' => Text::_('COM_INSTALLER_MSG_WARNINGS_SMALLPOSTSIZEDESC'),
 170              ];
 171          }
 172  
 173          if ($upload_max_filesize > 0 && $upload_max_filesize < $minLimit) {
 174              $messages[] = [
 175                  'message'     => Text::_('COM_INSTALLER_MSG_WARNINGS_SMALLUPLOADSIZE'),
 176                  'description' => Text::_('COM_INSTALLER_MSG_WARNINGS_SMALLUPLOADSIZEDESC'),
 177              ];
 178          }
 179  
 180          return $messages;
 181      }
 182  }


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