started to refactor functions to classes and use PSR-4 autoloader and namespacing

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2018-12-18 08:38:34 +01:00
parent ba93265ac6
commit c3cc3d1f62
14 changed files with 660 additions and 661 deletions

View File

@@ -1,41 +0,0 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
* Copyright (c) 2010 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org> (2003-2009)
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Functions
*
*/
/**
* Returns Array, whose elements have been checked whether thay are empty or not
*
* @param array $source
* The array to trim
* @return array The trim'med array
* @author Florian Lippert <flo@syscp.org>
*/
function array_trim($source)
{
$returnval = array();
if (is_array($source)) {
foreach ($source as $var => $val) {
if ($val != ' ' && $val != '') {
$returnval[$var] = $val;
}
}
} else {
$returnval = $source;
}
return $returnval;
}

View File

@@ -1,33 +0,0 @@
<?php
/**
* ipv6 aware gethostbynamel function
*
* @param string $host
* @param boolean $try_a default true
* @return boolean|array
*/
function gethostbynamel6($host, $try_a = true)
{
$dns6 = dns_get_record($host, DNS_AAAA);
if ($try_a == true) {
$dns4 = dns_get_record($host, DNS_A);
$dns = array_merge($dns4, $dns6);
} else {
$dns = $dns6;
}
$ips = array();
foreach ($dns as $record) {
if ($record["type"] == "A") {
$ips[] = $record["ip"];
}
if ($record["type"] == "AAAA") {
$ips[] = $record["ipv6"];
}
}
if (count($ips) < 1) {
return false;
} else {
return $ips;
}
}

View File

@@ -1,58 +0,0 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2003-2009 the SysCP Team (see authors).
* Copyright (c) 2010 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Florian Lippert <flo@syscp.org> (2003-2009)
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Functions
*
*/
/**
* Replaces all occurrences of variables defined in the second argument
* in the first argument with their values.
*
* @param string The string that should be searched for variables
* @param array The array containing the variables with their values
* @return string The submitted string with the variables replaced.
* @author Michael Duergner
*/
function replace_variables($text, $vars)
{
$pattern = "/\{([a-zA-Z0-9\-_]+)\}/";
// --- martin @ 08.08.2005 -------------------------------------------------------
// fixing usage of uninitialised variable
$matches = array();
// -------------------------------------------------------------------------------
if(count($vars) > 0
&& preg_match_all($pattern, $text, $matches))
{
for ($i = 0;$i < count($matches[1]);$i++)
{
$current = $matches[1][$i];
if(isset($vars[$current]))
{
$var = $vars[$current];
$text = str_replace("{" . $current . "}", $var, $text);
}
}
}
$text = str_replace('\n', "\n", $text);
return $text;
}

View File

@@ -1,36 +0,0 @@
<?php
/**
* Return human readable sizes
*
* @author Aidan Lister <aidan@php.net>
* @version 1.3.0
* @link http://aidanlister.com/2004/04/human-readable-file-sizes/
* @param int $size size in bytes
* @param string $max maximum unit
* @param string $system 'si' for SI, 'bi' for binary prefixes
* @param string $retstring return string format
*/
function size_readable($size, $max = null, $system = 'si', $retstring = '%01.2f %s')
{
// Pick units
$systems['si']['prefix'] = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
$systems['si']['size'] = 1000;
$systems['bi']['prefix'] = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB');
$systems['bi']['size'] = 1024;
$sys = isset($systems[$system]) ? $systems[$system] : $systems['si'];
// Max unit to display
$depth = count($sys['prefix']) - 1;
if ($max && false !== $d = array_search($max, $sys['prefix'])) {
$depth = $d;
}
// Loop
$i = 0;
while ($size >= $sys['size'] && $i < $depth) {
$size /= $sys['size'];
$i++;
}
return sprintf($retstring, $size, $sys['prefix'][$i]);
}