Merge branch 'marcosgdf-patch-2' into develop

This commit is contained in:
Laurent Destailleur 2014-07-31 17:22:04 +02:00
commit 37d22d1e94
15 changed files with 113 additions and 94 deletions

View File

@ -32,7 +32,6 @@ if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't nee
//if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session)
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php';
$langs->load('compta');
@ -115,4 +114,4 @@ $toJsonArray['result'] = price($result); // Return value to user format
$toJsonArray['resultnum'] = price2num($result); // Return value to numeric format
// Encode to JSON to return
echo dol_json_encode($toJsonArray); // Printing the call's result
echo json_encode($toJsonArray); // Printing the call's result

View File

@ -104,8 +104,7 @@ class box_graph_invoices_permonth extends ModeleBoxes
}
else
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php';
$tmparray=dol_json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode],true);
$tmparray=json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode],true);
$endyear=$tmparray['year'];
$shownb=$tmparray['shownb'];
$showtot=$tmparray['showtot'];

View File

@ -103,8 +103,7 @@ class box_graph_invoices_supplier_permonth extends ModeleBoxes
}
else
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php';
$tmparray=dol_json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode],true);
$tmparray=json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode],true);
$endyear=$tmparray['year'];
$shownb=$tmparray['shownb'];
$showtot=$tmparray['showtot'];

View File

@ -104,8 +104,7 @@ class box_graph_orders_permonth extends ModeleBoxes
}
else
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php';
$tmparray=dol_json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode],true);
$tmparray=json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode],true);
$endyear=$tmparray['year'];
$shownb=$tmparray['shownb'];
$showtot=$tmparray['showtot'];

View File

@ -103,8 +103,7 @@ class box_graph_orders_supplier_permonth extends ModeleBoxes
}
else
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php';
$tmparray=dol_json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode],true);
$tmparray=json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode],true);
$endyear=$tmparray['year'];
$shownb=$tmparray['shownb'];
$showtot=$tmparray['showtot'];

View File

@ -96,8 +96,7 @@ class box_graph_product_distribution extends ModeleBoxes
}
else
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php';
$tmparray=dol_json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode],true);
$tmparray=json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode],true);
$year=$tmparray['year'];
$showinvoicenb=$tmparray['showinvoicenb'];
$showpropalnb=$tmparray['showpropalnb'];

View File

@ -104,8 +104,7 @@ class box_graph_propales_permonth extends ModeleBoxes
}
else
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php';
$tmparray=dol_json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode],true);
$tmparray=json_decode($_COOKIE['DOLUSERCOOKIE_box_'.$this->boxcode],true);
$endyear=$tmparray['year'];
$shownb=$tmparray['shownb'];
$showtot=$tmparray['showtot'];

View File

@ -81,7 +81,7 @@ abstract class Stats
if ($foundintocache) // Cache file found and is not too old
{
dol_syslog(get_class($this).'::'.__FUNCTION__." read data from cache file ".$newpathofdestfile." ".$filedate.".");
$data = dol_json_decode(file_get_contents($newpathofdestfile), true);
$data = json_decode(file_get_contents($newpathofdestfile), true);
}
else
{
@ -112,7 +112,7 @@ abstract class Stats
dol_syslog(get_class($this).'::'.__FUNCTION__." save cache file ".$newpathofdestfile." onto disk.");
if (! dol_is_dir($conf->user->dir_temp)) dol_mkdir($conf->user->dir_temp);
$fp = fopen($newpathofdestfile, 'w');
fwrite($fp, dol_json_encode($data));
fwrite($fp, json_encode($data));
fclose($fp);
if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
@chmod($newpathofdestfile, octdec($newmask));
@ -172,7 +172,7 @@ abstract class Stats
if ($foundintocache) // Cache file found and is not too old
{
dol_syslog(get_class($this).'::'.__FUNCTION__." read data from cache file ".$newpathofdestfile." ".$filedate.".");
$data = dol_json_decode(file_get_contents($newpathofdestfile), true);
$data = json_decode(file_get_contents($newpathofdestfile), true);
}
else
{
@ -203,7 +203,7 @@ abstract class Stats
dol_syslog(get_class($this).'::'.__FUNCTION__." save cache file ".$newpathofdestfile." onto disk.");
if (! dol_is_dir($conf->user->dir_temp)) dol_mkdir($conf->user->dir_temp);
$fp = fopen($newpathofdestfile, 'w');
fwrite($fp, dol_json_encode($data));
fwrite($fp, json_encode($data));
fclose($fp);
if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
@chmod($newpathofdestfile, octdec($newmask));
@ -295,7 +295,7 @@ abstract class Stats
if ($foundintocache) // Cache file found and is not too old
{
dol_syslog(get_class($this).'::'.__FUNCTION__." read data from cache file ".$newpathofdestfile." ".$filedate.".");
$data = dol_json_decode(file_get_contents($newpathofdestfile), true);
$data = json_decode(file_get_contents($newpathofdestfile), true);
}
else
{
@ -309,7 +309,7 @@ abstract class Stats
dol_syslog(get_class($this).'::'.__FUNCTION__." save cache file ".$newpathofdestfile." onto disk.");
if (! dol_is_dir($conf->user->dir_temp)) dol_mkdir($conf->user->dir_temp);
$fp = fopen($newpathofdestfile, 'w');
fwrite($fp, dol_json_encode($data));
fwrite($fp, json_encode($data));
fclose($fp);
if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
@chmod($newpathofdestfile, octdec($newmask));

View File

@ -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);
}
/**

View File

@ -256,15 +256,7 @@ class ImportCsv extends ModeleImports
{
global $conf;
$arrayres=array();
if (version_compare(phpversion(), '5.3') < 0)
{
$arrayres=fgetcsv($this->handle,100000,$this->separator,$this->enclosure);
}
else
{
$arrayres=fgetcsv($this->handle,100000,$this->separator,$this->enclosure,$this->escape);
}
$arrayres=fgetcsv($this->handle,100000,$this->separator,$this->enclosure,$this->escape);
// End of file
if ($arrayres === false) return false;

View File

@ -166,7 +166,6 @@ require_once 'filefunc.inc.php';
// If there is a POST parameter to tell to save automatically some POST parameters into a cookies, we do it
if (! empty($_POST["DOL_AUTOSET_COOKIE"]))
{
require_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php';
$tmpautoset=explode(':',$_POST["DOL_AUTOSET_COOKIE"],2);
$tmplist=explode(',',$tmpautoset[1]);
$cookiearrayvalue='';
@ -177,7 +176,7 @@ if (! empty($_POST["DOL_AUTOSET_COOKIE"]))
if (! empty($_POST[$postkey])) $cookiearrayvalue[$tmpkey]=$_POST[$postkey];
}
$cookiename=$tmpautoset[0];
$cookievalue=dol_json_encode($cookiearrayvalue);
$cookievalue=json_encode($cookiearrayvalue);
//var_dump('setcookie cookiename='.$cookiename.' cookievalue='.$cookievalue);
setcookie($cookiename, empty($cookievalue)?'':$cookievalue, empty($cookievalue)?0:(time()+(86400*354)), '/'); // keep cookie 1 year
if (empty($cookievalue)) unset($_COOKIE[$cookiename]);

View File

@ -25,7 +25,6 @@
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
@ -65,7 +64,7 @@ $limit = $conf->liste_limit;
$offset = $limit * $page ;
$listofdata=array();
if (! empty($_SESSION['massstockmove'])) $listofdata=dol_json_decode($_SESSION['massstockmove'],true);
if (! empty($_SESSION['massstockmove'])) $listofdata=json_decode($_SESSION['massstockmove'],true);
/*
@ -106,7 +105,7 @@ if ($action == 'addline')
if (count(array_keys($listofdata)) > 0) $id=max(array_keys($listofdata)) + 1;
else $id=1;
$listofdata[$id]=array('id'=>$id, 'id_product'=>$id_product, 'qty'=>$qty, 'id_sw'=>$id_sw, 'id_tw'=>$id_tw);
$_SESSION['massstockmove']=dol_json_encode($listofdata);
$_SESSION['massstockmove']=json_encode($listofdata);
unset($id_product);
//unset($id_sw);
@ -118,7 +117,7 @@ if ($action == 'addline')
if ($action == 'delline' && $idline != '')
{
if (! empty($listofdata[$idline])) unset($listofdata[$idline]);
if (count($listofdata) > 0) $_SESSION['massstockmove']=dol_json_encode($listofdata);
if (count($listofdata) > 0) $_SESSION['massstockmove']=json_encode($listofdata);
else unset($_SESSION['massstockmove']);
}

View File

@ -146,12 +146,54 @@ class Functions2LibTest extends PHPUnit_Framework_TestCase
*/
public function testIsValidUrl()
{
$result=isValidUrl('http://www.google.com',1);
print __METHOD__." result=".$result."\n";
$this->assertEquals(1,$result);
$result=isValidUrl('www.google.com',2);
print __METHOD__." result=".$result."\n";
$this->assertEquals(0,$result);
//Simple check
$result = isValidUrl('http://google.com');
$this->assertEquals($result, 1);
$result = isValidUrl('gooçgle');
$this->assertEquals($result, 0);
//With scheme check
$result = isValidUrl('http://www.google.com', 1);
$this->assertEquals($result, 1);
$result = isValidUrl('ftp://www.google.com', 1);
$this->assertEquals($result, 0);
//With password check
$result = isValidUrl('http://user:password@http://www.google.com', 1, 1);
$this->assertEquals($result, 1);
$result = isValidUrl('http://www.google.com', 1, 1);
$this->assertEquals($result, 0);
//With port check
$result = isValidUrl('http://google.com:8080', 0, 0, 1);
$this->assertEquals($result, 1);
$result = isValidUrl('http://google.com', 0, 0, 1);
$this->assertEquals($result, 0);
//With path check
$result = isValidUrl('http://google.com/search', 0, 0, 0, 1);
$this->assertEquals($result, 1);
$result = isValidUrl('http://google.com', 0, 0, 0, 1);
$this->assertEquals($result, 0);
//With query check
$result = isValidUrl('http://google.com/search?test=test', 0, 0, 0, 0, 1);
$this->assertEquals($result, 1);
$result = isValidUrl('http://google.com', 0, 0, 0, 0, 1);
$this->assertEquals($result, 0);
//With anchor check
$result = isValidUrl('http://google.com/search#done', 0, 0, 0, 0, 0, 1);
$this->assertEquals($result, 1);
$result = isValidUrl('http://google.com/search', 0, 0, 0, 0, 0, 1);
$this->assertEquals($result, 0);
}
/**

View File

@ -787,4 +787,26 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase
$this->assertEquals('{"AA":"B\/B","CC":"","EE":"FF","HH":"GG;"}',json_encode($tmp));
}
/**
* dol_nl2br
*
* @return void
*/
public function testDolNl2Br() {
//String to encode
$string = "a\na";
$this->assertEquals(dol_nl2br($string), "a<br>\na");
//With $forxml parameter
$this->assertEquals(dol_nl2br($string, 0, 1), "a<br />\na");
//Replacing \n by br
$this->assertEquals(dol_nl2br($string, 1), "a<br>a");
//With $forxml parameter
$this->assertEquals(dol_nl2br($string, 1, 1), "a<br />a");
}
}

View File

@ -27,7 +27,6 @@ global $conf,$user,$langs,$db;
//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver
//require_once 'PHPUnit/Autoload.php';
require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
require_once dirname(__FILE__).'/../../htdocs/core/lib/json.lib.php';
if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1');
if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1');