From e5e1a0b07da0cc4ea83b866b6ad7d7261a125a21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Thu, 28 Feb 2019 19:15:50 +0100 Subject: [PATCH 1/7] The property $fk_doc was declared of type integer --- htdocs/accountancy/class/bookkeeping.class.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index bf3594e967d..8f8c9599c8e 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -167,10 +167,10 @@ class BookKeeping extends CommonObject $this->doc_ref = trim($this->doc_ref); } if (isset($this->fk_doc)) { - $this->fk_doc = trim($this->fk_doc); + $this->fk_doc = (int) $this->fk_doc; } if (isset($this->fk_docdet)) { - $this->fk_docdet = trim($this->fk_docdet); + $this->fk_docdet = (int) $this->fk_docdet; } if (isset($this->thirdparty_code)) { $this->thirdparty_code = trim($this->thirdparty_code); @@ -487,10 +487,10 @@ class BookKeeping extends CommonObject $this->doc_ref = trim($this->doc_ref); } if (isset($this->fk_doc)) { - $this->fk_doc = trim($this->fk_doc); + $this->fk_doc = (int) $this->fk_doc; } if (isset($this->fk_docdet)) { - $this->fk_docdet = trim($this->fk_docdet); + $this->fk_docdet = (int) $this->fk_docdet; } if (isset($this->thirdparty_code)) { $this->thirdparty_code = trim($this->thirdparty_code); @@ -1104,10 +1104,10 @@ class BookKeeping extends CommonObject $this->doc_ref = trim($this->doc_ref); } if (isset($this->fk_doc)) { - $this->fk_doc = trim($this->fk_doc); + $this->fk_doc = (int) $this->fk_doc; } if (isset($this->fk_docdet)) { - $this->fk_docdet = trim($this->fk_docdet); + $this->fk_docdet = (int) $this->fk_docdet; } if (isset($this->thirdparty_code)) { $this->thirdparty_code = trim($this->thirdparty_code); @@ -1473,8 +1473,8 @@ class BookKeeping extends CommonObject $this->doc_date = $now; $this->doc_type = ''; $this->doc_ref = ''; - $this->fk_doc = ''; - $this->fk_docdet = ''; + $this->fk_doc = 0; + $this->fk_docdet = 0; $this->thirdparty_code = 'CU001'; $this->subledger_account = '41100001'; $this->subledger_label = 'My customer company'; From 4e1e39192189ea2dc61e08887a3cbed328fa4286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Thu, 28 Feb 2019 19:53:14 +0100 Subject: [PATCH 2/7] phpcs fix --- htdocs/core/class/html.formfile.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 2243b4e06c1..94710cd53f8 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -187,7 +187,7 @@ class FormFile $out .= ''; if (! empty($options)) $out .= ''.$options.''; $out .= ''; - $out .= ' '.$langs->trans("SaveUploadedFileWithMask", preg_replace('/__file__/',$langs->transnoentitiesnoconv("OriginFileName"),$savingdocmask), $langs->transnoentitiesnoconv("OriginFileName")); + $out .= ' '.$langs->trans("SaveUploadedFileWithMask", preg_replace('/__file__/', $langs->transnoentitiesnoconv("OriginFileName"), $savingdocmask), $langs->transnoentitiesnoconv("OriginFileName")); $out .= ''; $out .= ''; } From 4fcde0eaa3e7880858c116014e79709c7a52276a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 2 Mar 2019 01:37:49 +0100 Subject: [PATCH 3/7] Update facture-rec.class.php --- htdocs/compta/facture/class/facture-rec.class.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index 2e0d346e62f..aaed882aab4 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -323,6 +323,8 @@ class FactureRec extends CommonInvoice { global $conf; + $error = 0; + $sql = "UPDATE ".MAIN_DB_PREFIX."facture_rec SET"; $sql.= " fk_soc = ".$this->fk_soc; // TODO Add missing fields From 728a3fcbba377c103a3fa13cd341e2622e116e4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 2 Mar 2019 08:43:09 +0100 Subject: [PATCH 4/7] Update facture-rec.class.php --- htdocs/compta/facture/class/facture-rec.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index aaed882aab4..a22372ca90d 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -3,7 +3,7 @@ * Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2009-2012 Regis Houssin * Copyright (C) 2010-2011 Juanjo Menent - * Copyright (C) 2012 Cedric Salvador + * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2013 Florian Henry * Copyright (C) 2015 Marcos García * Copyright (C) 2017 Frédéric France @@ -225,7 +225,7 @@ class FactureRec extends CommonInvoice $tva_tx = $facsrc->lines[$i]->tva_tx; if (! empty($facsrc->lines[$i]->vat_src_code) && ! preg_match('/\(/', $tva_tx)) $tva_tx .= ' ('.$facsrc->lines[$i]->vat_src_code.')'; - $result_insert = $this->addline( + $result_insert = $this->addline( $facsrc->lines[$i]->desc, $facsrc->lines[$i]->subprice, $facsrc->lines[$i]->qty, @@ -1084,7 +1084,7 @@ class FactureRec extends CommonInvoice $parameters = array( 'restrictioninvoiceid' => $restrictioninvoiceid, 'forcevalidation' => $forcevalidation, - ); + ); $reshook = $hookmanager->executeHooks('beforeCreationOfRecurringInvoices', $parameters, $sql); // note that $sql might be modified by hooks $resql = $db->query($sql); @@ -1185,7 +1185,7 @@ class FactureRec extends CommonInvoice 'invoiceidgenerated' => $invoiceidgenerated, 'facturerec' => $facturerec, // it's an object which PHP passes by "reference", so modifiable by hooks. 'this' => $this, // it's an object which PHP passes by "reference", so modifiable by hooks. - ); + ); $reshook = $hookmanager->executeHooks('afterCreationOfRecurringInvoice', $parameters, $facture); // note: $facture can be modified by hooks (warning: $facture can be null) $i++; From 40d34940f12e73ab4dd06387bd59824634f5fab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 2 Mar 2019 10:00:51 +0100 Subject: [PATCH 5/7] fix exclude from phpcs --- .travis.yml | 2 +- dev/setup/codesniffer/ruleset.xml | 4 +- htdocs/core/class/html.formfile.class.php | 6 +- htdocs/core/js/lib_foot.js.php | 15 ++-- htdocs/core/js/lib_gravatar.js.php | 20 ++--- htdocs/core/js/lib_head.js.php | 14 ++-- htdocs/core/js/timepicker.js.php | 14 ++-- htdocs/core/lib/json.lib.php | 29 ++++--- .../modulebuilder/template/js/mymodule.js.php | 6 +- htdocs/projet/jsgantt_language.js.php | 14 ++-- test/phpunit/JsonLibTest.php | 84 +++++++++---------- 11 files changed, 102 insertions(+), 106 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9fcd300e224..5d15e8843dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -309,7 +309,7 @@ script: set -e # Exclusions are defined in the ruleset.xml file #phpcs -s -n -p -d memory_limit=-1 --colors --tab-width=4 --standard=dev/setup/codesniffer/ruleset.xml --encoding=utf-8 . - phpcs -s -p -d memory_limit=-1 --colors --tab-width=4 --standard=dev/setup/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true . + phpcs -s -p -d memory_limit=-1 --extensions=php --colors --tab-width=4 --standard=dev/setup/codesniffer/ruleset.xml --encoding=utf-8 --runtime-set ignore_warnings_on_exit true . set +e echo diff --git a/dev/setup/codesniffer/ruleset.xml b/dev/setup/codesniffer/ruleset.xml index 296c6cb9b6f..75d6c2c3c85 100644 --- a/dev/setup/codesniffer/ruleset.xml +++ b/dev/setup/codesniffer/ruleset.xml @@ -11,10 +11,8 @@ htdocs/conf.php */nltechno* */htdocs/includes - *.min.css - *.js - + diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 2243b4e06c1..0c1abbe8e24 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -183,11 +183,11 @@ class FormFile else { $rename='checked'; } - + $out .= ''; if (! empty($options)) $out .= ''.$options.''; $out .= ''; - $out .= ' '.$langs->trans("SaveUploadedFileWithMask", preg_replace('/__file__/',$langs->transnoentitiesnoconv("OriginFileName"),$savingdocmask), $langs->transnoentitiesnoconv("OriginFileName")); + $out .= ' '.$langs->trans("SaveUploadedFileWithMask", preg_replace('/__file__/', $langs->transnoentitiesnoconv("OriginFileName"), $savingdocmask), $langs->transnoentitiesnoconv("OriginFileName")); $out .= ''; $out .= ''; } @@ -1571,7 +1571,7 @@ class FormFile { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref=(isset($reg[1])?$reg[1]:''); } - + if (! $id && ! $ref) continue; $found=0; if (! empty($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) diff --git a/htdocs/core/js/lib_foot.js.php b/htdocs/core/js/lib_foot.js.php index cfa05289f4b..fd13eb2fd26 100644 --- a/htdocs/core/js/lib_foot.js.php +++ b/htdocs/core/js/lib_foot.js.php @@ -21,13 +21,13 @@ * \brief File that include javascript functions (included if option use_javascript activated) */ -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK',1); -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); -if (! defined('NOLOGIN')) define('NOLOGIN',1); -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU',1); -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML',1); -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); +if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); +if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', 1); +if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1); +if (! defined('NOLOGIN')) define('NOLOGIN', 1); +if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', 1); +if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', 1); +if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); session_cache_limiter('public'); @@ -159,4 +159,3 @@ print ' } }); });'."\n"; - diff --git a/htdocs/core/js/lib_gravatar.js.php b/htdocs/core/js/lib_gravatar.js.php index dad6482460a..e1e900b6d00 100644 --- a/htdocs/core/js/lib_gravatar.js.php +++ b/htdocs/core/js/lib_gravatar.js.php @@ -22,16 +22,16 @@ * JQuery (providing object $) library must be loaded before this file. */ -//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language -//if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); -//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); // Not disabled cause need to do translations -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK',1); -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); -if (! defined('NOLOGIN')) define('NOLOGIN',1); -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU',1); -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML',1); -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); +//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Not disabled cause need to load personalized language +//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); +if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); +//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Not disabled cause need to do translations +if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', 1); +if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1); +if (! defined('NOLOGIN')) define('NOLOGIN', 1); +if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', 1); +if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', 1); +if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); session_cache_limiter('public'); diff --git a/htdocs/core/js/lib_head.js.php b/htdocs/core/js/lib_head.js.php index 5b909c6e148..07a47090792 100644 --- a/htdocs/core/js/lib_head.js.php +++ b/htdocs/core/js/lib_head.js.php @@ -24,13 +24,13 @@ * JQuery (providing object $) and JQuery-UI (providing $datepicker) libraries must be loaded before this file. */ -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK',1); -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); -if (! defined('NOLOGIN')) define('NOLOGIN',1); -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU',1); -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML',1); -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); +if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); +if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', 1); +if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1); +if (! defined('NOLOGIN')) define('NOLOGIN', 1); +if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', 1); +if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', 1); +if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); session_cache_limiter('public'); diff --git a/htdocs/core/js/timepicker.js.php b/htdocs/core/js/timepicker.js.php index 38c450b8e23..6acabbaf421 100644 --- a/htdocs/core/js/timepicker.js.php +++ b/htdocs/core/js/timepicker.js.php @@ -21,13 +21,13 @@ * \brief File that include javascript functions for timepicker */ -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK',1); -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); -if (! defined('NOLOGIN')) define('NOLOGIN',1); -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU',1); -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML',1); -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); +if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); +if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', 1); +if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1); +if (! defined('NOLOGIN')) define('NOLOGIN', 1); +if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', 1); +if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', 1); +if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); session_cache_limiter('public'); diff --git a/htdocs/core/lib/json.lib.php b/htdocs/core/lib/json.lib.php index f58d1b44dbf..7c9e9b66698 100644 --- a/htdocs/core/lib/json.lib.php +++ b/htdocs/core/lib/json.lib.php @@ -214,7 +214,7 @@ if (! function_exists('json_decode')) * @param bool $assoc False return an object, true return an array * @return mixed Object or Array */ - function json_decode($json, $assoc=false) + function json_decode($json, $assoc = false) { return dol_json_decode($json, $assoc); } @@ -229,7 +229,7 @@ if (! function_exists('json_decode')) * @return mixed Object or Array or false on error * @see json_decode() */ -function dol_json_decode($json, $assoc=false) +function dol_json_decode($json, $assoc = false) { dol_syslog("For better performance, enable the native json in your PHP", LOG_WARNING); @@ -242,8 +242,8 @@ function dol_json_decode($json, $assoc=false) if (! $comment) { if (($json[$i] == '{') || ($json[$i] == '[')) $out.= 'array('; - else if (($json[$i] == '}') || ($json[$i] == ']')) $out.= ')'; - else if ($json[$i] == ':') $out.= ' => '; + elseif (($json[$i] == '}') || ($json[$i] == ']')) $out.= ')'; + elseif ($json[$i] == ':') $out.= ' => '; else $out.=$json[$i]; } else $out.= $json[$i]; @@ -282,19 +282,18 @@ function dol_json_decode($json, $assoc=false) /** * Return text according to type * - * @param string $val Value to decode - * @return string Formated value + * @param string $val Value to decode + * @return string Formated value */ function _unval($val) { - while (preg_match('/\\\u([0-9A-F]{2})([0-9A-F]{2})/i', $val, $reg)) - { - // single, escaped unicode character - $utf16 = chr(hexdec($reg[1])) . chr(hexdec($reg[2])); - $utf8 = utf162utf8($utf16); - $val=preg_replace('/\\\u'.$reg[1].$reg[2].'/i',$utf8,$val); - } - return $val; + while (preg_match('/\\\u([0-9A-F]{2})([0-9A-F]{2})/i', $val, $reg)) { + // single, escaped unicode character + $utf16 = chr(hexdec($reg[1])) . chr(hexdec($reg[2])); + $utf8 = utf162utf8($utf16); + $val=preg_replace('/\\\u'.$reg[1].$reg[2].'/i', $utf8, $val); + } + return $val; } /** @@ -310,7 +309,7 @@ function _unval($val) function utf162utf8($utf16) { // oh please oh please oh please oh please oh please - if(function_exists('mb_convert_encoding')) { + if (function_exists('mb_convert_encoding')) { return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16'); } diff --git a/htdocs/modulebuilder/template/js/mymodule.js.php b/htdocs/modulebuilder/template/js/mymodule.js.php index 6a3447625a5..3e5c0ca31ba 100644 --- a/htdocs/modulebuilder/template/js/mymodule.js.php +++ b/htdocs/modulebuilder/template/js/mymodule.js.php @@ -18,15 +18,15 @@ */ if (!defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); -if (!defined('NOREQUIREDB')) define('NOREQUIREDB','1'); +if (!defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); -if (!defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); +if (!defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', 1); if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1); if (!defined('NOLOGIN')) define('NOLOGIN', 1); if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', 1); if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', 1); -if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); +if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); /** diff --git a/htdocs/projet/jsgantt_language.js.php b/htdocs/projet/jsgantt_language.js.php index 79280868ecb..99123cc45ef 100644 --- a/htdocs/projet/jsgantt_language.js.php +++ b/htdocs/projet/jsgantt_language.js.php @@ -20,13 +20,13 @@ * \brief Fichier de javascript de traduction pour JSGantt */ -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK',1); -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); -if (! defined('NOLOGIN')) define('NOLOGIN',1); -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU',1); -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML',1); -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); +if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); +if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', 1); +if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1); +if (! defined('NOLOGIN')) define('NOLOGIN', 1); +if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', 1); +if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', 1); +if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); require_once __DIR__.'/../main.inc.php'; diff --git a/test/phpunit/JsonLibTest.php b/test/phpunit/JsonLibTest.php index 113d263eca4..82f02133a98 100644 --- a/test/phpunit/JsonLibTest.php +++ b/test/phpunit/JsonLibTest.php @@ -18,9 +18,9 @@ /** * \file test/phpunit/JsonLibTest.php - * \ingroup test + * \ingroup test * \brief PHPUnit test - * \remarks To run this script as CLI: phpunit filename.php + * \remarks To run this script as CLI: phpunit filename.php */ global $conf,$user,$langs,$db; @@ -28,16 +28,16 @@ global $conf,$user,$langs,$db; //require_once 'PHPUnit/Autoload.php'; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; -if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); -if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); -if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no menu to show -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); -if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session) +if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); +if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); +if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); +if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); +if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); +if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); +if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no menu to show +if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php +if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); +if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) /** @@ -62,9 +62,9 @@ class JsonLibTest extends PHPUnit_Framework_TestCase */ function __construct() { - parent::__construct(); + parent::__construct(); - //$this->sharedFixture + //$this->sharedFixture global $conf,$user,$langs,$db; $this->savconf=$conf; $this->savuser=$user; @@ -94,11 +94,11 @@ class JsonLibTest extends PHPUnit_Framework_TestCase print __METHOD__."\n"; } - /** - * Init phpunit tests - * - * @return void - */ + /** + * Init phpunit tests + * + * @return void + */ protected function setUp() { global $conf,$user,$langs,$db; @@ -109,11 +109,11 @@ class JsonLibTest extends PHPUnit_Framework_TestCase print __METHOD__."\n"; } - /** - * End phpunit tests - * - * @return void - */ + /** + * End phpunit tests + * + * @return void + */ protected function tearDown() { print __METHOD__."\n"; @@ -122,7 +122,7 @@ class JsonLibTest extends PHPUnit_Framework_TestCase /** * testJsonEncode * - * @return void + * @return void */ public function testJsonEncode() { @@ -135,39 +135,39 @@ class JsonLibTest extends PHPUnit_Framework_TestCase // Do a test with an array starting with 0 $arraytotest=array(0=>array('key'=>1,'value'=>'PRODREF','label'=>'Product ref with é and special chars \\ \' "')); - $arrayencodedexpected='[{"key":1,"value":"PRODREF","label":"Product ref with \u00e9 and special chars \\\\ \' \""}]'; + $arrayencodedexpected='[{"key":1,"value":"PRODREF","label":"Product ref with \u00e9 and special chars \\\\ \' \""}]'; $encoded=json_encode($arraytotest); - $this->assertEquals($arrayencodedexpected,$encoded); - $decoded=json_decode($encoded,true); - $this->assertEquals($arraytotest,$decoded,'test for json_xxx'); + $this->assertEquals($arrayencodedexpected, $encoded); + $decoded=json_decode($encoded, true); + $this->assertEquals($arraytotest, $decoded, 'test for json_xxx'); $encoded=dol_json_encode($arraytotest); - $this->assertEquals($arrayencodedexpected,$encoded); - $decoded=dol_json_decode($encoded,true); - $this->assertEquals($arraytotest,$decoded,'test for dol_json_xxx'); + $this->assertEquals($arrayencodedexpected, $encoded); + $decoded=dol_json_decode($encoded, true); + $this->assertEquals($arraytotest, $decoded, 'test for dol_json_xxx'); - // Same test but array start with 2 instead of 0 + // Same test but array start with 2 instead of 0 $arraytotest=array(2=>array('key'=>1,'value'=>'PRODREF','label'=>'Product ref with é and special chars \\ \' "')); - $arrayencodedexpected='{"2":{"key":1,"value":"PRODREF","label":"Product ref with \u00e9 and special chars \\\\ \' \""}}'; + $arrayencodedexpected='{"2":{"key":1,"value":"PRODREF","label":"Product ref with \u00e9 and special chars \\\\ \' \""}}'; $encoded=json_encode($arraytotest); - $this->assertEquals($arrayencodedexpected,$encoded); - $decoded=json_decode($encoded,true); - $this->assertEquals($arraytotest,$decoded,'test for json_xxx'); + $this->assertEquals($arrayencodedexpected, $encoded); + $decoded=json_decode($encoded, true); + $this->assertEquals($arraytotest, $decoded, 'test for json_xxx'); $encoded=dol_json_encode($arraytotest); - $this->assertEquals($arrayencodedexpected,$encoded); - $decoded=dol_json_decode($encoded,true); - $this->assertEquals($arraytotest,$decoded,'test for dol_json_xxx'); + $this->assertEquals($arrayencodedexpected, $encoded); + $decoded=dol_json_decode($encoded, true); + $this->assertEquals($arraytotest, $decoded, 'test for dol_json_xxx'); // Test with object - $now=gmmktime(12,0,0,1,1,1970); + $now=gmmktime(12, 0, 0, 1, 1, 1970); $objecttotest=new stdClass(); $objecttotest->property1='abc'; $objecttotest->property2=1234; $objecttotest->property3=$now; $encoded=dol_json_encode($objecttotest); - $this->assertEquals('{"property1":"abc","property2":1234,"property3":43200}',$encoded); + $this->assertEquals('{"property1":"abc","property2":1234,"property3":43200}', $encoded); } } From 8c23b41f9a528b5fe00bf8a94c3436a0020052f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 2 Mar 2019 14:32:52 +0100 Subject: [PATCH 6/7] autoloader for egulias lib needed by swiftmailer --- htdocs/core/class/CMailFile.class.php | 88 +++++++++-------------- htdocs/core/class/html.formfile.class.php | 6 +- 2 files changed, 38 insertions(+), 56 deletions(-) diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php index c64b408336c..5636b8d172e 100644 --- a/htdocs/core/class/CMailFile.class.php +++ b/htdocs/core/class/CMailFile.class.php @@ -352,71 +352,55 @@ class CMailFile elseif ($this->sendmode == 'swiftmailer') { // Use Swift Mailer library - // ------------------------------------------ - $host = dol_getprefix('email'); require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lexer/lib/Doctrine/Common/Lexer/AbstractLexer.php'; - require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Exception/InvalidEmail.php'; - require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Exception/NoDomainPart.php'; - require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/EmailParser.php'; - require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/EmailLexer.php'; - require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/EmailValidator.php'; - require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Warning/Warning.php'; - require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Warning/LocalTooLong.php'; - require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Parser/Parser.php'; - require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Parser/DomainPart.php'; - require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Parser/LocalPart.php'; - require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/EmailValidation.php'; - require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/RFCValidation.php'; + // egulias autoloader lib + require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/autoload.php'; - require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/InputByteStream.php'; - require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/Signer.php'; - require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/Signers/HeaderSigner.php'; - require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/Signers/DKIMSigner.php'; - //require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/SignedMessage.php'; - require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/swift_required.php'; - // Create the message - //$this->message = Swift_Message::newInstance(); - $this->message = new Swift_Message(); + require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/swift_required.php'; + + // Create the message + //$this->message = Swift_Message::newInstance(); + $this->message = new Swift_Message(); //$this->message = new Swift_SignedMessage(); // Adding a trackid header to a message - $headers = $this->message->getHeaders(); - $headers->addTextHeader('X-Dolibarr-TRACKID', $trackid . '@' . $host); - $headerID = time() . '.swiftmailer-dolibarr-' . $trackid . '@' . $host; - $msgid = $headers->get('Message-ID'); - $msgid->setId($headerID); - $headers->addIdHeader('References', $headerID); - // TODO if (! empty($moreinheader)) ... + $headers = $this->message->getHeaders(); + $headers->addTextHeader('X-Dolibarr-TRACKID', $trackid . '@' . $host); + $headerID = time() . '.swiftmailer-dolibarr-' . $trackid . '@' . $host; + $msgid = $headers->get('Message-ID'); + $msgid->setId($headerID); + $headers->addIdHeader('References', $headerID); + // TODO if (! empty($moreinheader)) ... - // Give the message a subject - try { - $result = $this->message->setSubject($subject); - } catch (Exception $e) { - $this->errors[] = $e->getMessage(); - } + // Give the message a subject + try { + $result = $this->message->setSubject($subject); + } catch (Exception $e) { + $this->errors[] = $e->getMessage(); + } - // Set the From address with an associative array - //$this->message->setFrom(array('john@doe.com' => 'John Doe')); - if (! empty($from)) { + // Set the From address with an associative array + //$this->message->setFrom(array('john@doe.com' => 'John Doe')); + if (! empty($from)) { try { - $result = $this->message->setFrom($this->getArrayAddress($from)); + $result = $this->message->setFrom($this->getArrayAddress($from)); } catch (Exception $e) { $this->errors[] = $e->getMessage(); } } - // Set the To addresses with an associative array - if (! empty($to)) { + // Set the To addresses with an associative array + if (! empty($to)) { try { - $result = $this->message->setTo($this->getArrayAddress($to)); + $result = $this->message->setTo($this->getArrayAddress($to)); } catch (Exception $e) { $this->errors[] = $e->getMessage(); } } - if (! empty($replyto)) { + if (! empty($replyto)) { try { $result = $this->message->SetReplyTo($this->getArrayAddress($replyto)); } catch (Exception $e) { @@ -424,16 +408,14 @@ class CMailFile } } - try { - $result = $this->message->setCharSet($conf->file->character_set_client); - } catch (Exception $e) { - $this->errors[] = $e->getMessage(); - } + try { + $result = $this->message->setCharSet($conf->file->character_set_client); + } catch (Exception $e) { + $this->errors[] = $e->getMessage(); + } - if (! empty($this->html)) - { - if (!empty($css)) - { + if (! empty($this->html)) { + if (!empty($css)) { $this->css = $css; $this->buildCSS(); } diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 2243b4e06c1..0c1abbe8e24 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -183,11 +183,11 @@ class FormFile else { $rename='checked'; } - + $out .= ''; if (! empty($options)) $out .= ''.$options.''; $out .= ''; - $out .= ' '.$langs->trans("SaveUploadedFileWithMask", preg_replace('/__file__/',$langs->transnoentitiesnoconv("OriginFileName"),$savingdocmask), $langs->transnoentitiesnoconv("OriginFileName")); + $out .= ' '.$langs->trans("SaveUploadedFileWithMask", preg_replace('/__file__/', $langs->transnoentitiesnoconv("OriginFileName"), $savingdocmask), $langs->transnoentitiesnoconv("OriginFileName")); $out .= ''; $out .= ''; } @@ -1571,7 +1571,7 @@ class FormFile { preg_match('/(.*)\/[^\/]+$/', $relativefile, $reg); $ref=(isset($reg[1])?$reg[1]:''); } - + if (! $id && ! $ref) continue; $found=0; if (! empty($this->cache_objects[$modulepart.'_'.$id.'_'.$ref])) From 73740bc10e8c3d032b1759473ce3de3548809a56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 2 Mar 2019 14:35:05 +0100 Subject: [PATCH 7/7] autoloader for egulias lib needed by swiftmailer --- htdocs/includes/swiftmailer/autoload.php | 13 +++ .../egulias/email-validator/AutoLoader.php | 82 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 htdocs/includes/swiftmailer/autoload.php create mode 100644 htdocs/includes/swiftmailer/egulias/email-validator/AutoLoader.php diff --git a/htdocs/includes/swiftmailer/autoload.php b/htdocs/includes/swiftmailer/autoload.php new file mode 100644 index 00000000000..b796c9cf3e8 --- /dev/null +++ b/htdocs/includes/swiftmailer/autoload.php @@ -0,0 +1,13 @@ +register(); diff --git a/htdocs/includes/swiftmailer/egulias/email-validator/AutoLoader.php b/htdocs/includes/swiftmailer/egulias/email-validator/AutoLoader.php new file mode 100644 index 00000000000..06339e869bf --- /dev/null +++ b/htdocs/includes/swiftmailer/egulias/email-validator/AutoLoader.php @@ -0,0 +1,82 @@ + + */ +class EguliasAutoLoader +{ + /** + * @var string The namespace prefix for this instance. + */ + protected $namespace = ''; + + /** + * @var string The filesystem prefix to use for this instance + */ + protected $path = ''; + + /** + * Build the instance of the autoloader + * + * @param string $namespace The prefixed namespace this instance will load + * @param string $path The filesystem path to the root of the namespace + */ + public function __construct($namespace, $path) + { + $this->namespace = ltrim($namespace, '\\'); + $this->path = rtrim($path, '/\\') . DIRECTORY_SEPARATOR; + } + + /** + * Try to load a class + * + * @param string $class The class name to load + * + * @return boolean If the loading was successful + */ + public function load($class) + { + $class = ltrim($class, '\\'); + if (strpos($class, $this->namespace) === 0) { + $nsparts = explode('\\', $class); + $class = array_pop($nsparts); + $path = $this->path . 'swiftmailer/egulias/email-validator/EmailValidator/'; + $max=count($nsparts); + for ($i=2; $i<$max;$i++) { + $path .= $nsparts[$i].'/'; + } + $nsparts = array(); + $path .= str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php'; + if (file_exists($path)) { + require $path; + return true; + } + } + + return false; + } + + /** + * Register the autoloader to PHP + * + * @return boolean The status of the registration + */ + public function register() + { + return spl_autoload_register(array($this, 'load')); + } + + /** + * Unregister the autoloader to PHP + * + * @return boolean The status of the unregistration + */ + public function unregister() + { + return spl_autoload_unregister(array($this, 'load')); + } +}