[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Utility/ -> Utility.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2006 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\Utility;
  11  
  12  use Joomla\CMS\HTML\HTMLHelper;
  13  
  14  // phpcs:disable PSR1.Files.SideEffects
  15  \defined('JPATH_PLATFORM') or die;
  16  // phpcs:enable PSR1.Files.SideEffects
  17  
  18  /**
  19   * JUtility is a utility functions class
  20   *
  21   * @since  1.7.0
  22   */
  23  class Utility
  24  {
  25      /**
  26       * Method to extract key/value pairs out of a string with XML style attributes
  27       *
  28       * @param   string  $string  String containing XML style attributes
  29       *
  30       * @return  array  Key/Value pairs for the attributes
  31       *
  32       * @since   1.7.0
  33       */
  34      public static function parseAttributes($string)
  35      {
  36          $attr = array();
  37          $retarray = array();
  38  
  39          // Let's grab all the key/value pairs using a regular expression
  40          preg_match_all('/([\w:-]+)[\s]?=[\s]?"([^"]*)"/i', $string, $attr);
  41  
  42          if (\is_array($attr)) {
  43              $numPairs = \count($attr[1]);
  44  
  45              for ($i = 0; $i < $numPairs; $i++) {
  46                  $retarray[$attr[1][$i]] = $attr[2][$i];
  47              }
  48          }
  49  
  50          return $retarray;
  51      }
  52  
  53      /**
  54       * Method to get the maximum allowed file size for the HTTP uploads based on the active PHP configuration
  55       *
  56       * @param   mixed  $custom  A custom upper limit, if the PHP settings are all above this then this will be used
  57       *
  58       * @return  mixed  Size in number of bytes
  59       *
  60       * @since   3.7.0
  61       */
  62      public static function getMaxUploadSize($custom = null)
  63      {
  64          if ($custom) {
  65              $custom = HTMLHelper::_('number.bytes', $custom, '');
  66  
  67              if ($custom > 0) {
  68                  $sizes[] = $custom;
  69              }
  70          }
  71  
  72          /*
  73           * Read INI settings which affects upload size limits
  74           * and Convert each into number of bytes so that we can compare
  75           */
  76          $sizes[] = HTMLHelper::_('number.bytes', ini_get('post_max_size'), '');
  77          $sizes[] = HTMLHelper::_('number.bytes', ini_get('upload_max_filesize'), '');
  78  
  79          // The minimum of these is the limiting factor
  80          return min($sizes);
  81      }
  82  }


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