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