forked from Wavyzz/dolibarr
Merge branch 'patch-2' of github.com:marcosgdf/dolibarr into
marcosgdf-patch-2 Conflicts: test/phpunit/Functions2LibTest.php
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
* Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
|
||||
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
|
||||
* Copyright (C) 2013 Alexandre Spangaro <alexandre.spangaro@gmail.com>
|
||||
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -32,11 +33,7 @@
|
||||
* This file contains all frequently used functions.
|
||||
*/
|
||||
|
||||
|
||||
if (! function_exists('json_encode'))
|
||||
{
|
||||
include_once DOL_DOCUMENT_ROOT .'/core/lib/json.lib.php';
|
||||
}
|
||||
include_once DOL_DOCUMENT_ROOT .'/core/lib/json.lib.php';
|
||||
|
||||
/**
|
||||
* Function to return value of a static property when class
|
||||
@@ -46,26 +43,16 @@ if (! function_exists('json_encode'))
|
||||
* @param string $class Class name
|
||||
* @param string $member Name of property
|
||||
* @return mixed Return value of static property
|
||||
* @deprecated PHP 5.3 is now the minimum requirement, this is no longer necessary
|
||||
*/
|
||||
function getStaticMember($class, $member)
|
||||
{
|
||||
if (is_object($class)) $class = get_class($class);
|
||||
$classObj = new ReflectionClass($class);
|
||||
$result = null;
|
||||
|
||||
$found=0;
|
||||
foreach($classObj->getStaticProperties() as $prop => $value)
|
||||
{
|
||||
if ($prop == $member)
|
||||
{
|
||||
$result = $value;
|
||||
$found++;
|
||||
break;
|
||||
}
|
||||
if (isset($class::$member)) {
|
||||
return $class::$member;
|
||||
}
|
||||
|
||||
if (! $found) dol_print_error('','Try to get a static member "'.$member.'" in class "'.$class.'" that does not exists or is not static.');
|
||||
return $result;
|
||||
dol_print_error('','Try to get a static member "'.$member.'" in class "'.$class.'" that does not exists or is not static.');
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1495,19 +1482,11 @@ function dol_print_address($address, $htmlid, $mode, $id)
|
||||
*/
|
||||
function isValidEmail($address)
|
||||
{
|
||||
if (preg_match("/.*<(.+)>/i", $address, $regs)) {
|
||||
$address = $regs[1];
|
||||
}
|
||||
// 2 letters domains extensions are for countries
|
||||
// 3 letters domains extensions: biz|com|edu|gov|int|mil|net|org|pro|...
|
||||
if (preg_match("/^[^@\s\t]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2,3}|asso|aero|coop|info|name)\$/i",$address))
|
||||
{
|
||||
if (filter_var($address, FILTER_VALIDATE_EMAIL)) {
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3654,24 +3633,19 @@ function dol_string_nohtmltag($StringHtml,$removelinefeed=1,$pagecodeto='UTF-8')
|
||||
|
||||
|
||||
/**
|
||||
* Replace CRLF in string with a HTML BR tag
|
||||
* Replace CRLF in string with a HTML BR tag
|
||||
*
|
||||
* @param string $stringtoencode String to encode
|
||||
* @param string $nl2brmode 0=Adding br before \n, 1=Replacing \n by br
|
||||
* @param string $forxml false=Use <br>, true=Use <br />
|
||||
* @return string String encoded
|
||||
* @param string $stringtoencode String to encode
|
||||
* @param int $nl2brmode 0=Adding br before \n, 1=Replacing \n by br
|
||||
* @param bool $forxml false=Use <br>, true=Use <br />
|
||||
* @return string String encoded
|
||||
*/
|
||||
function dol_nl2br($stringtoencode,$nl2brmode=0,$forxml=false)
|
||||
{
|
||||
if (! $nl2brmode)
|
||||
{
|
||||
// We use @ to avoid warning on PHP4 that does not support entity encoding from UTF8;
|
||||
if (version_compare(PHP_VERSION, '5.3.0') < 0) return @nl2br($stringtoencode);
|
||||
else return @nl2br($stringtoencode,$forxml);
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret=preg_replace('/(\r\n|\r|\n)/i',($forxml?'<br />':'<br>'),$stringtoencode);
|
||||
if (!$nl2brmode) {
|
||||
return nl2br($stringtoencode, $forxml);
|
||||
} else {
|
||||
$ret=preg_replace('/(\r\n|\r|\n)/i', ($forxml?'<br />':'<br>'), $stringtoencode);
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
@@ -3767,12 +3741,11 @@ function dol_html_entity_decode($a,$b,$c='UTF-8')
|
||||
* @param string $encoding Encoding
|
||||
* @param bool $double_encode When double_encode is turned off PHP will not encode existing html entities
|
||||
* @return string $ret Encoded string
|
||||
* @deprecated Since PHP4 support is no longer available, this function does not make sense
|
||||
*/
|
||||
function dol_htmlentities($string, $flags=null, $encoding='UTF-8', $double_encode=false)
|
||||
{
|
||||
// We use @ to avoid warning on PHP4 that does not support entity decoding to UTF8;
|
||||
$ret=@htmlentities($string, $flags, $encoding, $double_encode);
|
||||
return $ret;
|
||||
return htmlentities($string, $flags, $encoding, $double_encode);
|
||||
}
|
||||
|
||||
|
||||
@@ -3803,7 +3776,7 @@ function dol_string_is_good_iso($s)
|
||||
* Return nb of lines of a clear text
|
||||
*
|
||||
* @param string $s String to check
|
||||
* @param string $maxchar Not yet used
|
||||
* @param int $maxchar Not yet used
|
||||
* @return int Number of lines
|
||||
*/
|
||||
function dol_nboflines($s,$maxchar=0)
|
||||
@@ -3858,12 +3831,12 @@ function dol_nboflines_bis($text,$maxlinesize=0,$charset='UTF-8')
|
||||
/**
|
||||
* Same function than microtime in PHP 5 but compatible with PHP4
|
||||
*
|
||||
* @return float Time (millisecondes) with microsecondes in decimal part
|
||||
* @return float Time (millisecondes) with microsecondes in decimal part
|
||||
* @deprecated Dolibarr does not support PHP4, you should use native function
|
||||
*/
|
||||
function dol_microtime_float()
|
||||
{
|
||||
list($usec, $sec) = explode(" ", microtime());
|
||||
return ((float) $usec + (float) $sec);
|
||||
return microtime(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user