diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php index f0188598c09..fd44199a1a7 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -316,7 +316,7 @@ class BillOfMaterials extends CommonObject if ($key=='t.rowid') { $sqlwhere[] = $key . '='. $value; } - elseif (strpos($key,'date') !== false) { + elseif (strpos($key, 'date') !== false) { $sqlwhere[] = $key.' = \''.$this->db->idate($value).'\''; } elseif ($key=='customsql') { diff --git a/htdocs/core/class/menubase.class.php b/htdocs/core/class/menubase.class.php index 16c1f54ee31..d1d7534af23 100644 --- a/htdocs/core/class/menubase.class.php +++ b/htdocs/core/class/menubase.class.php @@ -91,7 +91,7 @@ class Menubase * @param DoliDB $db Database handler * @param string $menu_handler Menu handler */ - function __construct($db, $menu_handler = '') + public function __construct($db, $menu_handler = '') { $this->db = $db; $this->menu_handler = $menu_handler; @@ -105,7 +105,7 @@ class Menubase * @param User $user User that create * @return int <0 if KO, Id of record if OK */ - function create($user = null) + public function create($user = null) { global $conf, $langs; @@ -245,7 +245,7 @@ class Menubase * @param int $notrigger 0=no, 1=yes (no update trigger) * @return int <0 if KO, >0 if OK */ - function update($user = null, $notrigger = 0) + public function update($user = null, $notrigger = 0) { global $conf, $langs; @@ -310,7 +310,7 @@ class Menubase * @param User $user User that load * @return int <0 if KO, >0 if OK */ - function fetch($id, $user = null) + public function fetch($id, $user = null) { global $langs; @@ -384,7 +384,7 @@ class Menubase * @param User $user User that delete * @return int <0 if KO, >0 if OK */ - function delete($user) + public function delete($user) { global $conf, $langs; @@ -410,7 +410,7 @@ class Menubase * * @return void */ - function initAsSpecimen() + public function initAsSpecimen() { $this->id=0; @@ -443,7 +443,7 @@ class Menubase * @param array $tabMenu If array with menu entries already loaded, we put this array here (in most cases, it's empty) * @return array Return array with menu entries for top menu */ - function menuTopCharger($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu) + public function menuTopCharger($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu) { global $langs, $user, $conf; // To export to dol_eval function global $mainmenu,$leftmenu; // To export to dol_eval function @@ -472,7 +472,7 @@ class Menubase * @param array $tabMenu Array with menu entries already loaded * @return Menu Menu array for particular mainmenu value or full tabArray */ - function menuLeftCharger($newmenu, $mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu) + public function menuLeftCharger($newmenu, $mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu) { global $langs, $user, $conf; // To export to dol_eval function global $mainmenu,$leftmenu; // To export to dol_eval function @@ -480,16 +480,16 @@ class Menubase $mainmenu=$mymainmenu; // To export to dol_eval function $leftmenu=$myleftmenu; // To export to dol_eval function - // Detect what is top mainmenu id + // Detect what is top mainmenu id $menutopid=''; foreach($tabMenu as $key => $val) { - // Define menutopid of mainmenu - if (empty($menutopid) && $val['type'] == 'top' && $val['mainmenu'] == $mainmenu) - { - $menutopid=$val['rowid']; - break; - } + // Define menutopid of mainmenu + if (empty($menutopid) && $val['type'] == 'top' && $val['mainmenu'] == $mainmenu) + { + $menutopid=$val['rowid']; + break; + } } // We initialize newmenu with first already found menu entries @@ -561,7 +561,7 @@ class Menubase * @param array $tabMenu Array to store new entries found (in most cases, it's empty, but may be alreay filled) * @return int >0 if OK, <0 if KO */ - function menuLoad($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu) + public function menuLoad($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu) { global $langs, $user, $conf; // To export to dol_eval function global $mainmenu, $leftmenu; // To export to dol_eval function @@ -577,10 +577,10 @@ class Menubase if ($type_user == 0) $sql.= " AND m.usertype IN (0,2)"; if ($type_user == 1) $sql.= " AND m.usertype IN (1,2)"; $sql.= " ORDER BY m.position, m.rowid"; - //print $sql; + //print $sql; - //$tmp1=microtime(true); - //print '>>> 1 0
'; + //$tmp1=microtime(true); + //print '>>> 1 0
'; dol_syslog(get_class($this)."::menuLoad mymainmenu=".$mymainmenu." myleftmenu=".$myleftmenu." type_user=".$type_user." menu_handler=".$menu_handler." tabMenu size=".count($tabMenu)."", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) @@ -647,8 +647,8 @@ class Menubase $title = $langs->trans($menu['titre']); } } - //$tmp4=microtime(true); - //print '>>> 3 '.($tmp4 - $tmp3).'
'; + //$tmp4=microtime(true); + //print '>>> 3 '.($tmp4 - $tmp3).'
'; // We complete tabMenu $tabMenu[$b]['rowid'] = $menu['rowid']; diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index 772b3db29e3..a599137109d 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -90,7 +90,7 @@ class Notify * * @param DoliDB $db Database handler */ - function __construct($db) + public function __construct($db) { $this->db = $db; } @@ -105,7 +105,7 @@ class Notify * @param Object $object Object the notification is about * @return string Message */ - function confirmMessage($action, $socid, $object) + public function confirmMessage($action, $socid, $object) { global $langs; $langs->load("mails"); @@ -146,7 +146,7 @@ class Notify * @param array $scope Scope where to search * @return array|int <0 if KO, array of notifications to send if OK */ - function getNotificationsArray($notifcode, $socid = 0, $object = null, $userid = 0, $scope = array('thirdparty', 'user', 'global')) + public function getNotificationsArray($notifcode, $socid = 0, $object = null, $userid = 0, $scope = array('thirdparty', 'user', 'global')) { global $conf, $user; @@ -309,7 +309,7 @@ class Notify * @param array $mimefilename_list List of attached file name in message * @return int <0 if KO, or number of changes if OK */ - function send($notifcode, $object, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array()) + public function send($notifcode, $object, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array()) { global $user,$conf,$langs,$mysoc; global $hookmanager; @@ -530,7 +530,7 @@ class Notify if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message']; } - $mailfile = new CMailFile( + $mailfile = new CMailFile( $subject, $sendto, $replyto, @@ -542,7 +542,7 @@ class Notify '', 0, -1 - ); + ); if ($mailfile->sendfile()) { @@ -758,7 +758,7 @@ class Notify if (! empty($hookmanager->resArray['subject'])) $subject.=$hookmanager->resArray['subject']; if (! empty($hookmanager->resArray['message'])) $message.=$hookmanager->resArray['message']; } - $mailfile = new CMailFile( + $mailfile = new CMailFile( $subject, $sendto, $replyto, diff --git a/htdocs/core/class/openid.class.php b/htdocs/core/class/openid.class.php index 32838f0deb2..2612aa5057b 100644 --- a/htdocs/core/class/openid.class.php +++ b/htdocs/core/class/openid.class.php @@ -26,18 +26,18 @@ */ class SimpleOpenID { - var $openid_url_identity; - var $URLs = array(); - var $error = array(); - var $fields = array( - 'required' => array(), - 'optional' => array(), + public $openid_url_identity; + public $URLs = array(); + public $error = array(); + public $fields = array( + 'required' => array(), + 'optional' => array(), ); /** * Constructor */ - function __construct() + public function __construct() { if (!function_exists('curl_exec')) { @@ -45,66 +45,66 @@ class SimpleOpenID } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * SetOpenIDServer * * @param string $a Server * @return void */ - function SetOpenIDServer($a) + public function SetOpenIDServer($a) { // phpcs:enable $this->URLs['openid_server'] = $a; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * SetOpenIDServer * * @param string $a Server * @return void */ - function SetTrustRoot($a) + public function SetTrustRoot($a) { // phpcs:enable $this->URLs['trust_root'] = $a; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * SetOpenIDServer * * @param string $a Server * @return void */ - function SetCancelURL($a) + public function SetCancelURL($a) { // phpcs:enable $this->URLs['cancel'] = $a; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * SetApprovedURL * * @param string $a Server * @return void */ - function SetApprovedURL($a) + public function SetApprovedURL($a) { // phpcs:enable $this->URLs['approved'] = $a; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * SetRequiredFields * * @param string $a Server * @return void */ - function SetRequiredFields($a) + public function SetRequiredFields($a) { // phpcs:enable if (is_array($a)) { @@ -114,14 +114,14 @@ class SimpleOpenID } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * SetOptionalFields * * @param string $a Server * @return void */ - function SetOptionalFields($a) + public function SetOptionalFields($a) { // phpcs:enable if (is_array($a)) { @@ -131,14 +131,14 @@ class SimpleOpenID } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * SetIdentity * * @param string $a Server * @return void */ - function SetIdentity($a) + public function SetIdentity($a) { // phpcs:enable // Set Identity URL @@ -162,33 +162,33 @@ class SimpleOpenID $this->openid_url_identity = $a; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * GetIdentity * * @return string */ - function GetIdentity() + public function GetIdentity() { // phpcs:enable // Get Identity return $this->openid_url_identity; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * SetOpenIDServer * * @return void */ - function GetError() + public function GetError() { // phpcs:enable $e = $this->error; return array('code'=>$e[0],'description'=>$e[1]); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * ErrorStore * @@ -196,7 +196,7 @@ class SimpleOpenID * @param string $desc Description * @return void */ - function ErrorStore($code, $desc = null) + public function ErrorStore($code, $desc = null) { // phpcs:enable $errs['OPENID_NOSERVERSFOUND'] = 'Cannot find OpenID Server TAG on Identity page.'; @@ -206,13 +206,13 @@ class SimpleOpenID $this->error = array($code,$desc); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * IsError * * @return boolean */ - function IsError() + public function IsError() { // phpcs:enable if (count($this->error) > 0) @@ -231,7 +231,7 @@ class SimpleOpenID * @param string $response Server * @return void */ - function splitResponse($response) + public function splitResponse($response) { $r = array(); $response = explode("\n", $response); @@ -245,14 +245,14 @@ class SimpleOpenID return $r; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * OpenID_Standarize * * @param string $openid_identity Server * @return string */ - function OpenID_Standarize($openid_identity = null) + public function OpenID_Standarize($openid_identity = null) { // phpcs:enable if ($openid_identity === null) @@ -279,7 +279,7 @@ class SimpleOpenID * @param array $arr An array * @return false|string false if KO, string of url if OK */ - function array2url($arr) + public function array2url($arr) { // converts associated array to URL Query String if (!is_array($arr)){ @@ -292,7 +292,7 @@ class SimpleOpenID return $query; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * FSOCK_Request * @@ -301,7 +301,7 @@ class SimpleOpenID * @param string $params Params * @return boolean|unknown */ - function FSOCK_Request($url, $method = "GET", $params = "") + public function FSOCK_Request($url, $method = "GET", $params = "") { // phpcs:enable $fp = fsockopen("ssl://www.myopenid.com", 443, $errno, $errstr, 3); // Connection timeout is 3 seconds @@ -326,7 +326,7 @@ class SimpleOpenID } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * CURL_Request * @@ -335,7 +335,7 @@ class SimpleOpenID * @param string $params Params * @return string */ - function CURL_Request($url, $method = "GET", $params = "") + public function CURL_Request($url, $method = "GET", $params = "") { // phpcs:enable // Remember, SSL MUST BE SUPPORTED @@ -359,14 +359,14 @@ class SimpleOpenID return $response; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * HTML2OpenIDServer * * @param string $content Content * @return array Array of servers */ - function HTML2OpenIDServer($content) + public function HTML2OpenIDServer($content) { // phpcs:enable $get = array(); @@ -387,20 +387,20 @@ class SimpleOpenID } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Get openid server * * @param string $url Url to found endpoint * @return string Endpoint */ - function GetOpenIDServer($url = '') + public function GetOpenIDServer($url = '') { // phpcs:enable global $conf; - include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php'; - if (empty($url)) $url=$conf->global->MAIN_AUTHENTICATION_OPENID_URL; + include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php'; + if (empty($url)) $url=$conf->global->MAIN_AUTHENTICATION_OPENID_URL; $response = getURLContent($url); @@ -417,13 +417,13 @@ class SimpleOpenID return $servers[0]; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * GetRedirectURL * * @return string */ - function GetRedirectURL() + public function GetRedirectURL() { // phpcs:enable $params = array(); @@ -443,13 +443,13 @@ class SimpleOpenID return $this->URLs['openid_server'] . "?". $this->array2url($params); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Redirect * * @return void */ - function Redirect() + public function Redirect() { // phpcs:enable $redirect_to = $this->GetRedirectURL(); @@ -465,19 +465,19 @@ class SimpleOpenID } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * ValidateWithServer * * @return boolean */ - function ValidateWithServer() + public function ValidateWithServer() { // phpcs:enable $params = array( - 'openid.assoc_handle' => urlencode($_GET['openid_assoc_handle']), - 'openid.signed' => urlencode($_GET['openid_signed']), - 'openid.sig' => urlencode($_GET['openid_sig']) + 'openid.assoc_handle' => urlencode($_GET['openid_assoc_handle']), + 'openid.signed' => urlencode($_GET['openid_signed']), + 'openid.sig' => urlencode($_GET['openid_sig']) ); // Send only required parameters to confirm validity $arr_signed = explode(",", str_replace('sreg.', 'sreg_', $_GET['openid_signed'])); @@ -518,36 +518,36 @@ class SimpleOpenID * @param string $url Url of endpoint to request * @return string First endpoint OpenID server found. False if it failed to found. */ - function sendDiscoveryRequestToGetXRDS($url = '') + public function sendDiscoveryRequestToGetXRDS($url = '') { - global $conf; + global $conf; - include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php'; - if (empty($url)) $url=$conf->global->MAIN_AUTHENTICATION_OPENID_URL; + include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php'; + if (empty($url)) $url=$conf->global->MAIN_AUTHENTICATION_OPENID_URL; - dol_syslog(get_class($this).'::sendDiscoveryRequestToGetXRDS get XRDS'); + dol_syslog(get_class($this).'::sendDiscoveryRequestToGetXRDS get XRDS'); - $addheaders=array('Accept: application/xrds+xml'); + $addheaders=array('Accept: application/xrds+xml'); $response = getURLContent($url, 'GET', '', 1, $addheaders); - /* response should like this: - - - - - http://specs.openid.net/auth/2.0/server - http://openid.net/srv/ax/1.0 - ... - https://www.google.com/accounts/o8/ud - - - - */ - $content=$response['content']; + /* response should like this: + + + + + http://specs.openid.net/auth/2.0/server + http://openid.net/srv/ax/1.0 + ... + https://www.google.com/accounts/o8/ud + + + + */ + $content=$response['content']; $server=''; if (preg_match('/'.preg_quote('', '/').'(.*)'.preg_quote('', '/').'/is', $content, $reg)) { - $server=$reg[1]; + $server=$reg[1]; } if (empty($server)) @@ -557,9 +557,9 @@ class SimpleOpenID } else { - dol_syslog(get_class($this).'::sendDiscoveryRequestToGetXRDS found endpoint = '.$server); - $this->SetOpenIDServer($server); - return $server; - } + dol_syslog(get_class($this).'::sendDiscoveryRequestToGetXRDS found endpoint = '.$server); + $this->SetOpenIDServer($server); + return $server; + } } } diff --git a/htdocs/core/class/rssparser.class.php b/htdocs/core/class/rssparser.class.php index 7683137767b..1dcd7ef64e5 100644 --- a/htdocs/core/class/rssparser.class.php +++ b/htdocs/core/class/rssparser.class.php @@ -32,9 +32,9 @@ class RssParser public $db; /** - * @var string Error code (or message) - */ - public $error=''; + * @var string Error code (or message) + */ + public $error=''; private $_format=''; private $_urlRSS; @@ -61,7 +61,7 @@ class RssParser */ public function __construct($db) { - $this->db = $db; + $this->db = $db; } /** @@ -252,28 +252,28 @@ class RssParser if ($str !== false) { - // Convert $str into xml - if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) - { - //print 'xx'.LIBXML_NOCDATA; - libxml_use_internal_errors(false); - $rss = simplexml_load_string($str, "SimpleXMLElement", LIBXML_NOCDATA); - } - else - { - $xmlparser=xml_parser_create(''); - if (!is_resource($xmlparser)) { - $this->error="ErrorFailedToCreateParser"; return -1; - } + // Convert $str into xml + if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) + { + //print 'xx'.LIBXML_NOCDATA; + libxml_use_internal_errors(false); + $rss = simplexml_load_string($str, "SimpleXMLElement", LIBXML_NOCDATA); + } + else + { + $xmlparser=xml_parser_create(''); + if (!is_resource($xmlparser)) { + $this->error="ErrorFailedToCreateParser"; return -1; + } - xml_set_object($xmlparser, $this); - xml_set_element_handler($xmlparser, 'feed_start_element', 'feed_end_element'); - xml_set_character_data_handler($xmlparser, 'feed_cdata'); - $status = xml_parse($xmlparser, $str); - xml_parser_free($xmlparser); - $rss=$this; - //var_dump($rss->_format);exit; - } + xml_set_object($xmlparser, $this); + xml_set_element_handler($xmlparser, 'feed_start_element', 'feed_end_element'); + xml_set_character_data_handler($xmlparser, 'feed_cdata'); + $status = xml_parse($xmlparser, $str); + xml_parser_free($xmlparser); + $rss=$this; + //var_dump($rss->_format);exit; + } } // If $rss loaded @@ -287,16 +287,16 @@ class RssParser $fp = fopen($newpathofdestfile, 'w'); if ($fp) { - fwrite($fp, $str); - fclose($fp); - if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK; - @chmod($newpathofdestfile, octdec($newmask)); + fwrite($fp, $str); + fclose($fp); + if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK; + @chmod($newpathofdestfile, octdec($newmask)); - $this->_lastfetchdate=$nowgmt; + $this->_lastfetchdate=$nowgmt; } else { - print 'Error, failed to open file '.$newpathofdestfile.' for write'; + print 'Error, failed to open file '.$newpathofdestfile.' for write'; } } @@ -435,13 +435,13 @@ class RssParser // Add record to result array $this->_rssarray[$i] = array( - 'link'=>$itemLink, - 'title'=>$itemTitle, - 'description'=>$itemDescription, - 'pubDate'=>$itemPubDate, - 'category'=>$itemCategory, - 'id'=>$itemId, - 'author'=>$itemAuthor); + 'link'=>$itemLink, + 'title'=>$itemTitle, + 'description'=>$itemDescription, + 'pubDate'=>$itemPubDate, + 'category'=>$itemCategory, + 'id'=>$itemId, + 'author'=>$itemAuthor); //var_dump($this->_rssarray); $i++; @@ -461,7 +461,7 @@ class RssParser - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Triggered when opened tag is found * @@ -470,7 +470,7 @@ class RssParser * @param array $attrs Attributes of tags * @return void */ - function feed_start_element($p, $element, &$attrs) + public function feed_start_element($p, $element, &$attrs) { // phpcs:enable $el = $element = strtolower($element); @@ -581,7 +581,7 @@ class RssParser } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Triggered when CDATA is found * @@ -589,7 +589,7 @@ class RssParser * @param string $text Tag * @return void */ - function feed_cdata($p, $text) + public function feed_cdata($p, $text) { // phpcs:enable if ($this->_format == 'atom' and $this->incontent) @@ -603,7 +603,7 @@ class RssParser } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Triggered when closed tag is found * @@ -611,7 +611,7 @@ class RssParser * @param string $el Tag * @return void */ - function feed_end_element($p, $el) + public function feed_end_element($p, $el) { // phpcs:enable $el = strtolower($el); @@ -666,7 +666,7 @@ class RssParser * @param string $str2 Str2 * @return string String cancatenated */ - function concat(&$str1, $str2 = "") + public function concat(&$str1, $str2 = "") { if (!isset($str1) ) { $str1=""; @@ -674,14 +674,14 @@ class RssParser $str1 .= $str2; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Enter description here ... * * @param string $text Text * @return void */ - function append_content($text) + public function append_content($text) { // phpcs:enable if ( $this->initem ) { @@ -699,7 +699,7 @@ class RssParser * @param string $text Text * @return void */ - function append($el, $text) + public function append($el, $text) { if (!$el) { return; diff --git a/htdocs/core/class/smtps.class.php b/htdocs/core/class/smtps.class.php index 695464f536f..24e7b2acc59 100644 --- a/htdocs/core/class/smtps.class.php +++ b/htdocs/core/class/smtps.class.php @@ -45,109 +45,109 @@ */ class SMTPs { - /** - * Host Name or IP of SMTP Server to use - */ - var $_smtpsHost = 'localhost'; + /** + * Host Name or IP of SMTP Server to use + */ + private $_smtpsHost = 'localhost'; - /** - * SMTP Server Port definition. 25 is default value - * This can be defined via a INI file or via a setter method - */ - var $_smtpsPort = '25'; + /** + * SMTP Server Port definition. 25 is default value + * This can be defined via a INI file or via a setter method + */ + private $_smtpsPort = '25'; - /** - * Secure SMTP Server access ID - * This can be defined via a INI file or via a setter method - */ - var $_smtpsID = null; + /** + * Secure SMTP Server access ID + * This can be defined via a INI file or via a setter method + */ + private $_smtpsID = null; - /** - * Secure SMTP Server access Password - * This can be defined via a INI file or via a setter method - */ - var $_smtpsPW = null; + /** + * Secure SMTP Server access Password + * This can be defined via a INI file or via a setter method + */ + private $_smtpsPW = null; - /** - * Who sent the Message - * This can be defined via a INI file or via a setter method - */ - var $_msgFrom = null; + /** + * Who sent the Message + * This can be defined via a INI file or via a setter method + */ + private $_msgFrom = null; - /** - * Where are replies and errors to be sent to - * This can be defined via a INI file or via a setter method - */ - var $_msgReplyTo = null; + /** + * Where are replies and errors to be sent to + * This can be defined via a INI file or via a setter method + */ + private $_msgReplyTo = null; - /** - * Who will the Message be sent to; TO, CC, BCC - * Multi-diminsional array containg addresses the message will - * be sent TO, CC or BCC - */ - var $_msgRecipients = null; + /** + * Who will the Message be sent to; TO, CC, BCC + * Multi-diminsional array containg addresses the message will + * be sent TO, CC or BCC + */ + private $_msgRecipients = null; - /** - * Message Subject - */ - var $_msgSubject = null; + /** + * Message Subject + */ + private $_msgSubject = null; - /** - * Message Content - */ - var $_msgContent = null; + /** + * Message Content + */ + private $_msgContent = null; - /** - * Custom X-Headers - */ - var $_msgXheader = null; + /** + * Custom X-Headers + */ + private $_msgXheader = null; - /** - * Character set - * Defaulted to 'iso-8859-1' - */ - var $_smtpsCharSet = 'iso-8859-1'; + /** + * Character set + * Defaulted to 'iso-8859-1' + */ + private $_smtpsCharSet = 'iso-8859-1'; - /** - * Message Sensitivity - * Defaults to ZERO - None - */ - var $_msgSensitivity = 0; + /** + * Message Sensitivity + * Defaults to ZERO - None + */ + private $_msgSensitivity = 0; - /** - * Message Sensitivity - */ - var $_arySensitivity = array ( false, + /** + * Message Sensitivity + */ + private $_arySensitivity = array ( false, 'Personal', 'Private', 'Company Confidential' ); - /** - * Message Sensitivity - * Defaults to 3 - Normal - */ - var $_msgPriority = 3; + /** + * Message Sensitivity + * Defaults to 3 - Normal + */ + private $_msgPriority = 3; - /** - * Message Priority - */ - var $_aryPriority = array ( 'Bulk', + /** + * Message Priority + */ + private $_aryPriority = array ( 'Bulk', 'Highest', 'High', 'Normal', 'Low', 'Lowest' ); - /** - * Content-Transfer-Encoding - * Defaulted to 0 - 7bit - */ - var $_smtpsTransEncodeType = 0; + /** + * Content-Transfer-Encoding + * Defaulted to 0 - 7bit + */ + private $_smtpsTransEncodeType = 0; - /** - * Content-Transfer-Encoding - */ - var $_smtpsTransEncodeTypes = array( '7bit', // Simple 7-bit ASCII + /** + * Content-Transfer-Encoding + */ + private $_smtpsTransEncodeTypes = array( '7bit', // Simple 7-bit ASCII '8bit', // 8-bit coding with line termination characters 'base64', // 3 octets encoded into 4 sextets with offset 'binary', // Arbitrary binary stream @@ -155,78 +155,78 @@ class SMTPs 'quoted-printable', // Mostly 7-bit, with 8-bit characters encoded as "=HH" 'uuencode' ); // UUENCODE encoding - /** - * Content-Transfer-Encoding - * Defaulted to '7bit' - */ - var $_smtpsTransEncode = '7bit'; + /** + * Content-Transfer-Encoding + * Defaulted to '7bit' + */ + private $_smtpsTransEncode = '7bit'; - /** - * Boundary String for MIME seperation - */ - var $_smtpsBoundary = null; + /** + * Boundary String for MIME seperation + */ + private $_smtpsBoundary = null; - /** - * Related Boundary - */ - var $_smtpsRelatedBoundary = null; + /** + * Related Boundary + */ + private $_smtpsRelatedBoundary = null; - /** - * Alternative Boundary - */ - var $_smtpsAlternativeBoundary = null; + /** + * Alternative Boundary + */ + private $_smtpsAlternativeBoundary = null; - /** - * Determines the method inwhich the message are to be sent. - * - 'sockets' [0] - conect via network to SMTP server - default - * - 'pipe [1] - use UNIX path to EXE - * - 'phpmail [2] - use the PHP built-in mail function - * NOTE: Only 'sockets' is implemented - */ - var $_transportType = 0; + /** + * Determines the method inwhich the message are to be sent. + * - 'sockets' [0] - conect via network to SMTP server - default + * - 'pipe [1] - use UNIX path to EXE + * - 'phpmail [2] - use the PHP built-in mail function + * NOTE: Only 'sockets' is implemented + */ + private $_transportType = 0; - /** - * If '$_transportType' is set to '1', then this variable is used - * to define the UNIX file system path to the sendmail execuable - */ - var $_mailPath = '/usr/lib/sendmail'; + /** + * If '$_transportType' is set to '1', then this variable is used + * to define the UNIX file system path to the sendmail execuable + */ + private $_mailPath = '/usr/lib/sendmail'; - /** - * Sets the SMTP server timeout in seconds. - */ - var $_smtpTimeout = 10; + /** + * Sets the SMTP server timeout in seconds. + */ + private $_smtpTimeout = 10; - /** - * Determines whether to calculate message MD5 checksum. - */ - var $_smtpMD5 = false; + /** + * Determines whether to calculate message MD5 checksum. + */ + private $_smtpMD5 = false; - /** - * Class error codes and messages - */ - var $_smtpsErrors = null; + /** + * Class error codes and messages + */ + private $_smtpsErrors = null; - /** - * Defines log level - * 0 - no logging - * 1 - connectivity logging - * 2 - message generation logging - * 3 - detail logging - */ - var $_log_level = 0; + /** + * Defines log level + * 0 - no logging + * 1 - connectivity logging + * 2 - message generation logging + * 3 - detail logging + */ + private $_log_level = 0; - /** - * Place Class in" debug" mode - */ - var $_debug = false; + /** + * Place Class in" debug" mode + */ + private $_debug = false; - // @CHANGE LDR - var $log = ''; - var $_errorsTo = ''; - var $_deliveryReceipt = 0; - var $_trackId = ''; - var $_moreInHeader = ''; + // @CHANGE LDR + private $log = ''; + private $_errorsTo = ''; + private $_deliveryReceipt = 0; + private $_trackId = ''; + private $_moreInHeader = ''; /** @@ -235,20 +235,20 @@ class SMTPs * @param int $_val Value * @return void */ - function setDeliveryReceipt($_val = 0) - { - $this->_deliveryReceipt = $_val; - } + public function setDeliveryReceipt($_val = 0) + { + $this->_deliveryReceipt = $_val; + } /** * get delivery receipt * * @return int Delivery receipt */ - function getDeliveryReceipt() - { - return $this->_deliveryReceipt; - } + public function getDeliveryReceipt() + { + return $this->_deliveryReceipt; + } /** * Set trackid @@ -256,10 +256,10 @@ class SMTPs * @param string $_val Value * @return void */ - function setTrackId($_val = '') - { - $this->_trackId = $_val; - } + public function setTrackId($_val = '') + { + $this->_trackId = $_val; + } /** * Set moreInHeader @@ -267,30 +267,30 @@ class SMTPs * @param string $_val Value * @return void */ - function setMoreInHeader($_val = '') - { - $this->_moreinheader = $_val; - } + public function setMoreInHeader($_val = '') + { + $this->_moreinheader = $_val; + } - /** + /** * get trackid * * @return string Track id */ - function getTrackId() - { - return $this->_trackId; - } + public function getTrackId() + { + return $this->_trackId; + } - /** - * get moreInHeader - * - * @return string moreInHeader - */ - function getMoreInHeader() - { - return $this->_moreinheader; - } + /** + * get moreInHeader + * + * @return string moreInHeader + */ + public function getMoreInHeader() + { + return $this->_moreinheader; + } /** * Set errors to @@ -298,11 +298,11 @@ class SMTPs * @param string $_strErrorsTo Errors to * @return void */ - function setErrorsTo($_strErrorsTo) - { - if ( $_strErrorsTo ) - $this->_errorsTo = $this->_strip_email($_strErrorsTo); - } + public function setErrorsTo($_strErrorsTo) + { + if ( $_strErrorsTo ) + $this->_errorsTo = $this->_strip_email($_strErrorsTo); + } /** * Get errors to @@ -310,1524 +310,1524 @@ class SMTPs * @param boolean $_part Variant * @return string Errors to */ - function getErrorsTo($_part = true) - { - $_retValue = ''; + public function getErrorsTo($_part = true) + { + $_retValue = ''; - if ( $_part === true ) - $_retValue = $this->_errorsTo; - else - $_retValue = $this->_errorsTo[$_part]; + if ( $_part === true ) + $_retValue = $this->_errorsTo; + else + $_retValue = $this->_errorsTo[$_part]; - return $_retValue; - } + return $_retValue; + } - /** - * Set debug - * - * @param boolean $_vDebug Value for debug - * @return void - */ - function setDebug($_vDebug = false) - { - $this->_debug = $_vDebug; - } + /** + * Set debug + * + * @param boolean $_vDebug Value for debug + * @return void + */ + public function setDebug($_vDebug = false) + { + $this->_debug = $_vDebug; + } - /** - * build RECIPIENT List, all addresses who will recieve this message - * - * @return void - */ - function buildRCPTlist() - { - // Pull TO list - $_aryToList = $this->getTO(); - } + /** + * build RECIPIENT List, all addresses who will recieve this message + * + * @return void + */ + public function buildRCPTlist() + { + // Pull TO list + $_aryToList = $this->getTO(); + } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps - /** - * Attempt a connection to mail server - * - * @return mixed $_retVal Boolean indicating success or failure on connection - */ - function _server_connect() - { + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Attempt a connection to mail server + * + * @return mixed $_retVal Boolean indicating success or failure on connection + */ + private function _server_connect() + { // phpcs:enable - // Default return value - $_retVal = true; + // Default return value + $_retVal = true; - // We have to make sure the HOST given is valid - // This is done here because '@fsockopen' will not give me this - // information if it failes to connect because it can't find the HOST - $host=$this->getHost(); - $usetls = preg_match('@tls://@i', $host); + // We have to make sure the HOST given is valid + // This is done here because '@fsockopen' will not give me this + // information if it failes to connect because it can't find the HOST + $host=$this->getHost(); + $usetls = preg_match('@tls://@i', $host); - $host=preg_replace('@tcp://@i', '', $host); // Remove prefix - $host=preg_replace('@ssl://@i', '', $host); // Remove prefix - $host=preg_replace('@tls://@i', '', $host); // Remove prefix + $host=preg_replace('@tcp://@i', '', $host); // Remove prefix + $host=preg_replace('@ssl://@i', '', $host); // Remove prefix + $host=preg_replace('@tls://@i', '', $host); // Remove prefix - // @CHANGE LDR - include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; + // @CHANGE LDR + include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; - if ( (! is_ip($host)) && ((gethostbyname($host)) == $host)) - { - $this->_setErr(99, $host . ' is either offline or is an invalid host name.'); - $_retVal = false; - } - else - { - //See if we can connect to the SMTP server + if ( (! is_ip($host)) && ((gethostbyname($host)) == $host)) + { + $this->_setErr(99, $host . ' is either offline or is an invalid host name.'); + $_retVal = false; + } + else + { + //See if we can connect to the SMTP server if ($this->socket = @fsockopen( - preg_replace('@tls://@i', '', $this->getHost()), // Host to 'hit', IP or domain - $this->getPort(), // which Port number to use - $this->errno, // actual system level error - $this->errstr, // and any text that goes with the error - $this->_smtpTimeout // timeout for reading/writing data over the socket - )) { - // Fix from PHP SMTP class by 'Chris Ryan' - // Sometimes the SMTP server takes a little longer to respond - // so we will give it a longer timeout for the first read - // Windows still does not have support for this timeout function - if (function_exists('stream_set_timeout')) stream_set_timeout($this->socket, $this->_smtpTimeout, 0); + preg_replace('@tls://@i', '', $this->getHost()), // Host to 'hit', IP or domain + $this->getPort(), // which Port number to use + $this->errno, // actual system level error + $this->errstr, // and any text that goes with the error + $this->_smtpTimeout // timeout for reading/writing data over the socket + )) { + // Fix from PHP SMTP class by 'Chris Ryan' + // Sometimes the SMTP server takes a little longer to respond + // so we will give it a longer timeout for the first read + // Windows still does not have support for this timeout function + if (function_exists('stream_set_timeout')) stream_set_timeout($this->socket, $this->_smtpTimeout, 0); - // Check response from Server - if ( $_retVal = $this->server_parse($this->socket, "220") ) - $_retVal = $this->socket; - } - // This connection attempt failed. - else - { - // @CHANGE LDR - if (empty($this->errstr)) $this->errstr='Failed to connect with fsockopen host='.$this->getHost().' port='.$this->getPort(); - $this->_setErr($this->errno, $this->errstr); - $_retVal = false; - } - } + // Check response from Server + if ( $_retVal = $this->server_parse($this->socket, "220") ) + $_retVal = $this->socket; + } + // This connection attempt failed. + else + { + // @CHANGE LDR + if (empty($this->errstr)) $this->errstr='Failed to connect with fsockopen host='.$this->getHost().' port='.$this->getPort(); + $this->_setErr($this->errno, $this->errstr); + $_retVal = false; + } + } - return $_retVal; - } + return $_retVal; + } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps - /** - * Attempt mail server authentication for a secure connection - * - * @return boolean|null $_retVal Boolean indicating success or failure of authentication - */ - function _server_authenticate() - { + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Attempt mail server authentication for a secure connection + * + * @return boolean|null $_retVal Boolean indicating success or failure of authentication + */ + private function _server_authenticate() + { // phpcs:enable - global $conf; + global $conf; - // Send the RFC2554 specified EHLO. - // This improvment as provided by 'SirSir' to - // accomodate both SMTP AND ESMTP capable servers - $host=$this->getHost(); - $usetls = preg_match('@tls://@i', $host); + // Send the RFC2554 specified EHLO. + // This improvment as provided by 'SirSir' to + // accomodate both SMTP AND ESMTP capable servers + $host=$this->getHost(); + $usetls = preg_match('@tls://@i', $host); - $host=preg_replace('@tcp://@i', '', $host); // Remove prefix - $host=preg_replace('@ssl://@i', '', $host); // Remove prefix - $host=preg_replace('@tls://@i', '', $host); // Remove prefix + $host=preg_replace('@tcp://@i', '', $host); // Remove prefix + $host=preg_replace('@ssl://@i', '', $host); // Remove prefix + $host=preg_replace('@tls://@i', '', $host); // Remove prefix - if ($usetls) $host='tls://'.$host; + if ($usetls) $host='tls://'.$host; - $hosth = $host; + $hosth = $host; - if (! empty($conf->global->MAIL_SMTP_USE_FROM_FOR_HELO)) - { - // If the from to is 'aaa ', we will keep 'ccc.com' - $hosth = $this->getFrom('addr'); - $hosth = preg_replace('/^.*.*$/', '', $hosth); - $hosth = preg_replace('/.*@/', '', $hosth); - } + if (! empty($conf->global->MAIL_SMTP_USE_FROM_FOR_HELO)) + { + // If the from to is 'aaa ', we will keep 'ccc.com' + $hosth = $this->getFrom('addr'); + $hosth = preg_replace('/^.*.*$/', '', $hosth); + $hosth = preg_replace('/.*@/', '', $hosth); + } - if ( $_retVal = $this->socket_send_str('EHLO ' . $hosth, '250') ) - { - if ($usetls) - { - /* - The following dialog illustrates how a client and server can start a TLS STARTTLS session - S: - C: - S: 220 mail.imc.org SMTP service ready - C: EHLO mail.ietf.org - S: 250-mail.imc.org offers a warm hug of welcome - S: 250 STARTTLS - C: STARTTLS - S: 220 Go ahead - C: - C & S: - C & S: + if ( $_retVal = $this->socket_send_str('EHLO ' . $hosth, '250') ) + { + if ($usetls) + { + /* + The following dialog illustrates how a client and server can start a TLS STARTTLS session + S: + C: + S: 220 mail.imc.org SMTP service ready + C: EHLO mail.ietf.org + S: 250-mail.imc.org offers a warm hug of welcome + S: 250 STARTTLS + C: STARTTLS + S: 220 Go ahead + C: + C & S: + C & S: // Second pass EHLO C: EHLO client-domain.com S: 250-server-domain.com S: 250 AUTH LOGIN - C: socket_send_str('STARTTLS', 220)) - { - $this->_setErr(131, 'STARTTLS connection is not supported.'); - return $_retVal; - } + C: socket_send_str('STARTTLS', 220)) + { + $this->_setErr(131, 'STARTTLS connection is not supported.'); + return $_retVal; + } - // Before 5.6.7: - // STREAM_CRYPTO_METHOD_SSLv23_CLIENT = STREAM_CRYPTO_METHOD_SSLv2_CLIENT|STREAM_CRYPTO_METHOD_SSLv3_CLIENT - // STREAM_CRYPTO_METHOD_TLS_CLIENT = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT - // PHP >= 5.6.7: - // STREAM_CRYPTO_METHOD_SSLv23_CLIENT = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT - // STREAM_CRYPTO_METHOD_TLS_CLIENT = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT + // Before 5.6.7: + // STREAM_CRYPTO_METHOD_SSLv23_CLIENT = STREAM_CRYPTO_METHOD_SSLv2_CLIENT|STREAM_CRYPTO_METHOD_SSLv3_CLIENT + // STREAM_CRYPTO_METHOD_TLS_CLIENT = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT + // PHP >= 5.6.7: + // STREAM_CRYPTO_METHOD_SSLv23_CLIENT = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT + // STREAM_CRYPTO_METHOD_TLS_CLIENT = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT - $crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT; - if (defined('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) { - $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT; - $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT; - } + $crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT; + if (defined('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) { + $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT; + $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT; + } - if (!stream_socket_enable_crypto($this->socket, true, $crypto_method)) - { - $this->_setErr(132, 'STARTTLS connection failed.'); - return $_retVal; - } - // Most server servers expect a 2nd pass of EHLO after TLS is established to get another time - // the answer with list of supported AUTH methods. They may differs between non STARTTLS and with STARTTLS. - if (!$_retVal = $this->socket_send_str('EHLO '.$host, '250')) - { - $this->_setErr(126, '"' . $host . '" does not support authenticated connections.'); - return $_retVal; - } - } - // Send Authentication to Server - // Check for errors along the way - $this->socket_send_str('AUTH LOGIN', '334'); + if (!stream_socket_enable_crypto($this->socket, true, $crypto_method)) + { + $this->_setErr(132, 'STARTTLS connection failed.'); + return $_retVal; + } + // Most server servers expect a 2nd pass of EHLO after TLS is established to get another time + // the answer with list of supported AUTH methods. They may differs between non STARTTLS and with STARTTLS. + if (!$_retVal = $this->socket_send_str('EHLO '.$host, '250')) + { + $this->_setErr(126, '"' . $host . '" does not support authenticated connections.'); + return $_retVal; + } + } + // Send Authentication to Server + // Check for errors along the way + $this->socket_send_str('AUTH LOGIN', '334'); - // User name will not return any error, server will take anything we give it. - $this->socket_send_str(base64_encode($this->_smtpsID), '334'); + // User name will not return any error, server will take anything we give it. + $this->socket_send_str(base64_encode($this->_smtpsID), '334'); - // The error here just means the ID/password combo doesn't work. - // There is not a method to determine which is the problem, ID or password - if ( ! $_retVal = $this->socket_send_str(base64_encode($this->_smtpsPW), '235') ) - $this->_setErr(130, 'Invalid Authentication Credentials.'); - } - else - { - $this->_setErr(126, '"' . $host . '" does not support authenticated connections.'); - } + // The error here just means the ID/password combo doesn't work. + // There is not a method to determine which is the problem, ID or password + if ( ! $_retVal = $this->socket_send_str(base64_encode($this->_smtpsPW), '235') ) + $this->_setErr(130, 'Invalid Authentication Credentials.'); + } + else + { + $this->_setErr(126, '"' . $host . '" does not support authenticated connections.'); + } - return $_retVal; - } + return $_retVal; + } - /** - * Now send the message - * - * @param boolean $_bolTestMsg whether to run this method in 'Test' mode. - * @param boolean $_bolDebug whether to log all communication between this Class and the Mail Server. - * @return boolean|null void - * $_strMsg If this is run in 'Test' mode, the actual message structure will be returned - */ - function sendMsg($_bolTestMsg = false, $_bolDebug = false) - { - global $conf; + /** + * Now send the message + * + * @param boolean $_bolTestMsg whether to run this method in 'Test' mode. + * @param boolean $_bolDebug whether to log all communication between this Class and the Mail Server. + * @return boolean|null void + * $_strMsg If this is run in 'Test' mode, the actual message structure will be returned + */ + public function sendMsg($_bolTestMsg = false, $_bolDebug = false) + { + global $conf; - /** - * Default return value - */ - $_retVal = false; + /** + * Default return value + */ + $_retVal = false; - // Connect to Server - if ( $this->socket = $this->_server_connect() ) - { - // If a User ID *and* a password is given, assume Authentication is desired - if( !empty($this->_smtpsID) && !empty($this->_smtpsPW) ) - { - // Send the RFC2554 specified EHLO. - $_retVal = $this->_server_authenticate(); - } + // Connect to Server + if ( $this->socket = $this->_server_connect() ) + { + // If a User ID *and* a password is given, assume Authentication is desired + if( !empty($this->_smtpsID) && !empty($this->_smtpsPW) ) + { + // Send the RFC2554 specified EHLO. + $_retVal = $this->_server_authenticate(); + } - // This is a "normal" SMTP Server "handshack" - else - { - // Send the RFC821 specified HELO. - $host=$this->getHost(); - $usetls = preg_match('@tls://@i', $host); + // This is a "normal" SMTP Server "handshack" + else + { + // Send the RFC821 specified HELO. + $host=$this->getHost(); + $usetls = preg_match('@tls://@i', $host); - $host=preg_replace('@tcp://@i', '', $host); // Remove prefix - $host=preg_replace('@ssl://@i', '', $host); // Remove prefix - $host=preg_replace('@tls://@i', '', $host); // Remove prefix + $host=preg_replace('@tcp://@i', '', $host); // Remove prefix + $host=preg_replace('@ssl://@i', '', $host); // Remove prefix + $host=preg_replace('@tls://@i', '', $host); // Remove prefix - $hosth = $host; + $hosth = $host; - if (! empty($conf->global->MAIL_SMTP_USE_FROM_FOR_HELO)) - { - // If the from to is 'aaa ', we will keep 'ccc.com' - $hosth = $this->getFrom('addr'); - $hosth = preg_replace('/^.*.*$/', '', $hosth); - $hosth = preg_replace('/.*@/', '', $hosth); - } + if (! empty($conf->global->MAIL_SMTP_USE_FROM_FOR_HELO)) + { + // If the from to is 'aaa ', we will keep 'ccc.com' + $hosth = $this->getFrom('addr'); + $hosth = preg_replace('/^.*.*$/', '', $hosth); + $hosth = preg_replace('/.*@/', '', $hosth); + } - $_retVal = $this->socket_send_str('HELO ' . $hosth, '250'); - } + $_retVal = $this->socket_send_str('HELO ' . $hosth, '250'); + } - // Well, did we get to the server? - if ( $_retVal ) - { - // From this point onward most server response codes should be 250 - // Specify who the mail is from.... - // This has to be the raw email address, strip the "name" off - $this->socket_send_str('MAIL FROM: ' . $this->getFrom('addr'), '250'); + // Well, did we get to the server? + if ( $_retVal ) + { + // From this point onward most server response codes should be 250 + // Specify who the mail is from.... + // This has to be the raw email address, strip the "name" off + $this->socket_send_str('MAIL FROM: ' . $this->getFrom('addr'), '250'); - // 'RCPT TO:' must be given a single address, so this has to loop - // through the list of addresses, regardless of TO, CC or BCC - // and send it out "single file" - foreach ($this->get_RCPT_list() as $_address) - { - /* Note: - * BCC email addresses must be listed in the RCPT TO command list, + // 'RCPT TO:' must be given a single address, so this has to loop + // through the list of addresses, regardless of TO, CC or BCC + // and send it out "single file" + foreach ($this->get_RCPT_list() as $_address) + { + /* Note: + * BCC email addresses must be listed in the RCPT TO command list, * but the BCC header should not be printed under the DATA command. - * http://stackoverflow.com/questions/2750211/sending-bcc-emails-using-a-smtp-server - */ + * http://stackoverflow.com/questions/2750211/sending-bcc-emails-using-a-smtp-server + */ - /* - * TODO - * After each 'RCPT TO:' is sent, we need to make sure it was kosher, - * if not, the whole message will fail - * If any email address fails, we will need to RESET the connection, - * mark the last address as "bad" and start the address loop over again. - * If any address fails, the entire message fails. - */ - $this->socket_send_str('RCPT TO: <' . $_address . '>', '250'); - } + /* + * TODO + * After each 'RCPT TO:' is sent, we need to make sure it was kosher, + * if not, the whole message will fail + * If any email address fails, we will need to RESET the connection, + * mark the last address as "bad" and start the address loop over again. + * If any address fails, the entire message fails. + */ + $this->socket_send_str('RCPT TO: <' . $_address . '>', '250'); + } - // Tell the server we are ready to start sending data - // with any custom headers... - // This is the last response code we look for until the end of the message. - $this->socket_send_str('DATA', '354'); + // Tell the server we are ready to start sending data + // with any custom headers... + // This is the last response code we look for until the end of the message. + $this->socket_send_str('DATA', '354'); - // Now we are ready for the message... - // Ok, all the ingredients are mixed in let's cook this puppy... - $this->socket_send_str($this->getHeader().$this->getBodyContent() . "\r\n" . '.', '250'); + // Now we are ready for the message... + // Ok, all the ingredients are mixed in let's cook this puppy... + $this->socket_send_str($this->getHeader().$this->getBodyContent() . "\r\n" . '.', '250'); - // Now tell the server we are done and close the socket... - fputs($this->socket, 'QUIT'); - fclose($this->socket); - } - } + // Now tell the server we are done and close the socket... + fputs($this->socket, 'QUIT'); + fclose($this->socket); + } + } - return $_retVal; - } + return $_retVal; + } - // ============================================================= - // ** Setter & Getter methods + // ============================================================= + // ** Setter & Getter methods - // ** Basic System configuration + // ** Basic System configuration - /** - * setConfig() is used to populate select class properties from either - * a user defined INI file or the systems 'php.ini' file - * - * If a user defined INI is to be used, the files complete path is passed - * as the method single parameter. The INI can define any class and/or - * user properties. Only properties defined within this file will be setter - * and/or orverwritten - * - * If the systems 'php.ini' file is to be used, the method is called without - * parameters. In this case, only HOST, PORT and FROM properties will be set - * as they are the only properties that are defined within the 'php.ini'. - * - * If secure SMTP is to be used, the user ID and Password can be defined with - * the user INI file, but the properties are not defined with the systems - * 'php.ini'file, they must be defined via their setter methods - * - * This method can be called twice, if desired. Once without a parameter to - * load the properties as defined within the systems 'php.ini' file, and a - * second time, with a path to a user INI file for other properties to be - * defined. - * - * @param mixed $_strConfigPath path to config file or VOID - * @return boolean - */ - function setConfig($_strConfigPath = null) - { - /** - * Returns constructed SELECT Object string or boolean upon failure - * Default value is set at true - */ - $_retVal = true; + /** + * setConfig() is used to populate select class properties from either + * a user defined INI file or the systems 'php.ini' file + * + * If a user defined INI is to be used, the files complete path is passed + * as the method single parameter. The INI can define any class and/or + * user properties. Only properties defined within this file will be setter + * and/or orverwritten + * + * If the systems 'php.ini' file is to be used, the method is called without + * parameters. In this case, only HOST, PORT and FROM properties will be set + * as they are the only properties that are defined within the 'php.ini'. + * + * If secure SMTP is to be used, the user ID and Password can be defined with + * the user INI file, but the properties are not defined with the systems + * 'php.ini'file, they must be defined via their setter methods + * + * This method can be called twice, if desired. Once without a parameter to + * load the properties as defined within the systems 'php.ini' file, and a + * second time, with a path to a user INI file for other properties to be + * defined. + * + * @param mixed $_strConfigPath path to config file or VOID + * @return boolean + */ + public function setConfig($_strConfigPath = null) + { + /** + * Returns constructed SELECT Object string or boolean upon failure + * Default value is set at true + */ + $_retVal = true; - // if we have a path... - if ( ! empty($_strConfigPath) ) - { - // If the path is not valid, this will NOT generate an error, - // it will simply return false. - if ( ! @include $_strConfigPath) - { - $this->_setErr(110, '"' . $_strConfigPath . '" is not a valid path.'); - $_retVal = false; - } - } + // if we have a path... + if ( ! empty($_strConfigPath) ) + { + // If the path is not valid, this will NOT generate an error, + // it will simply return false. + if ( ! @include $_strConfigPath) + { + $this->_setErr(110, '"' . $_strConfigPath . '" is not a valid path.'); + $_retVal = false; + } + } - // Read the Systems php.ini file - else - { - // Set these properties ONLY if they are set in the php.ini file. - // Otherwise the default values will be used. - if ( $_host = ini_get('SMTPs') ) - $this->setHost($_host); + // Read the Systems php.ini file + else + { + // Set these properties ONLY if they are set in the php.ini file. + // Otherwise the default values will be used. + if ( $_host = ini_get('SMTPs') ) + $this->setHost($_host); - if ( $_port = ini_get('smtp_port') ) - $this->setPort($_port); + if ( $_port = ini_get('smtp_port') ) + $this->setPort($_port); - if ( $_from = ini_get('sendmail_from') ) - $this->setFrom($_from); - } + if ( $_from = ini_get('sendmail_from') ) + $this->setFrom($_from); + } - // Send back what we have - return $_retVal; - } + // Send back what we have + return $_retVal; + } - /** - * Determines the method inwhich the messages are to be sent. - * - 'sockets' [0] - conect via network to SMTP server - * - 'pipe [1] - use UNIX path to EXE - * - 'phpmail [2] - use the PHP built-in mail function - * - * @param int $_type Interger value representing Mail Transport Type - * @return void - */ - function setTransportType($_type = 0) - { - if ( ( is_numeric($_type) ) && - ( ( $_type >= 0 ) && ( $_type <= 3 ) ) ) - $this->_transportType = $_type; - } + /** + * Determines the method inwhich the messages are to be sent. + * - 'sockets' [0] - conect via network to SMTP server + * - 'pipe [1] - use UNIX path to EXE + * - 'phpmail [2] - use the PHP built-in mail function + * + * @param int $_type Interger value representing Mail Transport Type + * @return void + */ + public function setTransportType($_type = 0) + { + if ((is_numeric($_type)) && (($_type >= 0) && ($_type <= 3))) { + $this->_transportType = $_type; + } + } - /** - * Return the method inwhich the message is to be sent. - * - 'sockets' [0] - conect via network to SMTP server - * - 'pipe [1] - use UNIX path to EXE - * - 'phpmail [2] - use the PHP built-in mail function - * - * @return int $_strHost Host Name or IP of the Mail Server to use - */ - function getTransportType() - { - return $this->_transportType; - } + /** + * Return the method inwhich the message is to be sent. + * - 'sockets' [0] - conect via network to SMTP server + * - 'pipe [1] - use UNIX path to EXE + * - 'phpmail [2] - use the PHP built-in mail function + * + * @return int $_strHost Host Name or IP of the Mail Server to use + */ + public function getTransportType() + { + return $this->_transportType; + } - /** - * Path to the sendmail execuable - * - * @param string $_path Path to the sendmail execuable - * @return boolean - * - */ - function setMailPath($_path) - { - // This feature is not yet implemented - return true; + /** + * Path to the sendmail execuable + * + * @param string $_path Path to the sendmail execuable + * @return boolean + * + */ + public function setMailPath($_path) + { + // This feature is not yet implemented + return true; - //if ( $_path ) $this->_mailPath = $_path; - } + //if ( $_path ) $this->_mailPath = $_path; + } - /** - * Defines the Host Name or IP of the Mail Server to use. - * This is defaulted to 'localhost' - * This is used only with 'socket' based mail transmission - * - * @param string $_strHost Host Name or IP of the Mail Server to use - * @return void - */ - function setHost($_strHost) - { - if ( $_strHost ) - $this->_smtpsHost = $_strHost; - } + /** + * Defines the Host Name or IP of the Mail Server to use. + * This is defaulted to 'localhost' + * This is used only with 'socket' based mail transmission + * + * @param string $_strHost Host Name or IP of the Mail Server to use + * @return void + */ + public function setHost($_strHost) + { + if ( $_strHost ) + $this->_smtpsHost = $_strHost; + } - /** - * Retrieves the Host Name or IP of the Mail Server to use - * This is used only with 'socket' based mail transmission - * - * @return string $_strHost Host Name or IP of the Mail Server to use - */ - function getHost() - { - return $this->_smtpsHost; - } + /** + * Retrieves the Host Name or IP of the Mail Server to use + * This is used only with 'socket' based mail transmission + * + * @return string $_strHost Host Name or IP of the Mail Server to use + */ + public function getHost() + { + return $this->_smtpsHost; + } - /** - * Defines the Port Number of the Mail Server to use - * This is defaulted to '25' - * This is used only with 'socket' based mail transmission - * - * @param int $_intPort Port Number of the Mail Server to use - * @return void - */ - function setPort($_intPort) - { - if ( ( is_numeric($_intPort) ) && - ( ( $_intPort >= 1 ) && ( $_intPort <= 65536 ) ) ) - $this->_smtpsPort = $_intPort; - } + /** + * Defines the Port Number of the Mail Server to use + * This is defaulted to '25' + * This is used only with 'socket' based mail transmission + * + * @param int $_intPort Port Number of the Mail Server to use + * @return void + */ + public function setPort($_intPort) + { + if ( ( is_numeric($_intPort) ) && + ( ( $_intPort >= 1 ) && ( $_intPort <= 65536 ) ) ) + $this->_smtpsPort = $_intPort; + } - /** - * Retrieves the Port Number of the Mail Server to use - * This is used only with 'socket' based mail transmission - * - * @return string Port Number of the Mail Server to use - */ - function getPort() - { - return $this->_smtpsPort; - } + /** + * Retrieves the Port Number of the Mail Server to use + * This is used only with 'socket' based mail transmission + * + * @return string Port Number of the Mail Server to use + */ + public function getPort() + { + return $this->_smtpsPort; + } - /** - * User Name for authentication on Mail Server - * - * @param string $_strID User Name for authentication on Mail Server - * @return void - */ - function setID($_strID) - { - $this->_smtpsID = $_strID; - } + /** + * User Name for authentication on Mail Server + * + * @param string $_strID User Name for authentication on Mail Server + * @return void + */ + public function setID($_strID) + { + $this->_smtpsID = $_strID; + } - /** - * Retrieves the User Name for authentication on Mail Server - * - * @return string User Name for authentication on Mail Server - */ - function getID() - { - return $this->_smtpsID; - } + /** + * Retrieves the User Name for authentication on Mail Server + * + * @return string User Name for authentication on Mail Server + */ + public function getID() + { + return $this->_smtpsID; + } - /** - * User Password for authentication on Mail Server - * - * @param string $_strPW User Password for authentication on Mail Server - * @return void - */ - function setPW($_strPW) - { - $this->_smtpsPW = $_strPW; - } + /** + * User Password for authentication on Mail Server + * + * @param string $_strPW User Password for authentication on Mail Server + * @return void + */ + public function setPW($_strPW) + { + $this->_smtpsPW = $_strPW; + } - /** - * Retrieves the User Password for authentication on Mail Server - * - * @return string User Password for authentication on Mail Server - */ - function getPW() - { - return $this->_smtpsPW; - } + /** + * Retrieves the User Password for authentication on Mail Server + * + * @return string User Password for authentication on Mail Server + */ + public function getPW() + { + return $this->_smtpsPW; + } - /** - * Character set used for current message - * Character set is defaulted to 'iso-8859-1'; - * - * @param string $_strCharSet Character set used for current message - * @return void - */ - function setCharSet($_strCharSet) - { - if ( $_strCharSet ) - $this->_smtpsCharSet = $_strCharSet; - } + /** + * Character set used for current message + * Character set is defaulted to 'iso-8859-1'; + * + * @param string $_strCharSet Character set used for current message + * @return void + */ + public function setCharSet($_strCharSet) + { + if ( $_strCharSet ) + $this->_smtpsCharSet = $_strCharSet; + } - /** - * Retrieves the Character set used for current message - * - * @return string $_smtpsCharSet Character set used for current message - */ - function getCharSet() - { - return $this->_smtpsCharSet; - } + /** + * Retrieves the Character set used for current message + * + * @return string $_smtpsCharSet Character set used for current message + */ + public function getCharSet() + { + return $this->_smtpsCharSet; + } - /** - * Content-Transfer-Encoding, Defaulted to '7bit' - * This can be changed for 2byte characers sets - * Known Encode Types - * - 7bit Simple 7-bit ASCII - * - 8bit 8-bit coding with line termination characters - * - base64 3 octets encoded into 4 sextets with offset - * - binary Arbitrary binary stream - * - mac-binhex40 Macintosh binary to hex encoding - * - quoted-printable Mostly 7-bit, with 8-bit characters encoded as "=HH" - * - uuencode UUENCODE encoding - * - * @param string $_strTransEncode Content-Transfer-Encoding - * @return void - */ - function setTransEncode($_strTransEncode) - { - if (array_search($_strTransEncode, $this->_smtpsTransEncodeTypes)) - $this->_smtpsTransEncode = $_strTransEncode; - } + /** + * Content-Transfer-Encoding, Defaulted to '7bit' + * This can be changed for 2byte characers sets + * Known Encode Types + * - 7bit Simple 7-bit ASCII + * - 8bit 8-bit coding with line termination characters + * - base64 3 octets encoded into 4 sextets with offset + * - binary Arbitrary binary stream + * - mac-binhex40 Macintosh binary to hex encoding + * - quoted-printable Mostly 7-bit, with 8-bit characters encoded as "=HH" + * - uuencode UUENCODE encoding + * + * @param string $_strTransEncode Content-Transfer-Encoding + * @return void + */ + public function setTransEncode($_strTransEncode) + { + if (array_search($_strTransEncode, $this->_smtpsTransEncodeTypes)) + $this->_smtpsTransEncode = $_strTransEncode; + } - /** - * Retrieves the Content-Transfer-Encoding - * - * @return string $_smtpsTransEncode Content-Transfer-Encoding - */ - function getTransEncode() - { - return $this->_smtpsTransEncode; - } + /** + * Retrieves the Content-Transfer-Encoding + * + * @return string $_smtpsTransEncode Content-Transfer-Encoding + */ + public function getTransEncode() + { + return $this->_smtpsTransEncode; + } - /** - * Content-Transfer-Encoding, Defaulted to '0' [ZERO] - * This can be changed for 2byte characers sets - * Known Encode Types - * - [0] 7bit Simple 7-bit ASCII - * - [1] 8bit 8-bit coding with line termination characters - * - [2] base64 3 octets encoded into 4 sextets with offset - * - [3] binary Arbitrary binary stream - * - [4] mac-binhex40 Macintosh binary to hex encoding - * - [5] quoted-printable Mostly 7-bit, with 8-bit characters encoded as "=HH" - * - [6] uuencode UUENCODE encoding - * - * @param string $_strTransEncodeType Content-Transfer-Encoding - * @return void - * - */ - function setTransEncodeType($_strTransEncodeType) - { - if (array_search($_strTransEncodeType, $this->_smtpsTransEncodeTypes)) - $this->_smtpsTransEncodeType = $_strTransEncodeType; - } + /** + * Content-Transfer-Encoding, Defaulted to '0' [ZERO] + * This can be changed for 2byte characers sets + * Known Encode Types + * - [0] 7bit Simple 7-bit ASCII + * - [1] 8bit 8-bit coding with line termination characters + * - [2] base64 3 octets encoded into 4 sextets with offset + * - [3] binary Arbitrary binary stream + * - [4] mac-binhex40 Macintosh binary to hex encoding + * - [5] quoted-printable Mostly 7-bit, with 8-bit characters encoded as "=HH" + * - [6] uuencode UUENCODE encoding + * + * @param string $_strTransEncodeType Content-Transfer-Encoding + * @return void + * + */ + public function setTransEncodeType($_strTransEncodeType) + { + if (array_search($_strTransEncodeType, $this->_smtpsTransEncodeTypes)) + $this->_smtpsTransEncodeType = $_strTransEncodeType; + } - /** - * Retrieves the Content-Transfer-Encoding - * - * @return string Content-Transfer-Encoding - */ - function getTransEncodeType() - { - return $this->_smtpsTransEncodeTypes[$this->_smtpsTransEncodeType]; - } + /** + * Retrieves the Content-Transfer-Encoding + * + * @return string Content-Transfer-Encoding + */ + public function getTransEncodeType() + { + return $this->_smtpsTransEncodeTypes[$this->_smtpsTransEncodeType]; + } - // ** Message Construction + // ** Message Construction - /** - * FROM Address from which mail will be sent - * - * @param string $_strFrom Address from which mail will be sent - * @return void - */ - function setFrom($_strFrom) - { - if ( $_strFrom ) - $this->_msgFrom = $this->_strip_email($_strFrom); - } + /** + * FROM Address from which mail will be sent + * + * @param string $_strFrom Address from which mail will be sent + * @return void + */ + public function setFrom($_strFrom) + { + if ( $_strFrom ) + $this->_msgFrom = $this->_strip_email($_strFrom); + } - /** - * Retrieves the Address from which mail will be sent - * - * @param boolean $_part To "strip" 'Real name' from address - * @return string Address from which mail will be sent - */ - function getFrom($_part = true) - { - $_retValue = ''; + /** + * Retrieves the Address from which mail will be sent + * + * @param boolean $_part To "strip" 'Real name' from address + * @return string Address from which mail will be sent + */ + public function getFrom($_part = true) + { + $_retValue = ''; - if ( $_part === true ) - $_retValue = $this->_msgFrom; - else - $_retValue = $this->_msgFrom[$_part]; + if ( $_part === true ) + $_retValue = $this->_msgFrom; + else + $_retValue = $this->_msgFrom[$_part]; - return $_retValue; - } + return $_retValue; + } - /** - * Reply-To Address from which mail will be the reply-to - * - * @param string $_strReplyTo Address from which mail will be the reply-to - * @return void - */ - function setReplyTo($_strReplyTo) - { - if ( $_strReplyTo ) - $this->_msgReplyTo = $this->_strip_email($_strReplyTo); - } + /** + * Reply-To Address from which mail will be the reply-to + * + * @param string $_strReplyTo Address from which mail will be the reply-to + * @return void + */ + public function setReplyTo($_strReplyTo) + { + if ( $_strReplyTo ) + $this->_msgReplyTo = $this->_strip_email($_strReplyTo); + } - /** - * Retrieves the Address from which mail will be the reply-to - * - * @param boolean $_part To "strip" 'Real name' from address - * @return string Address from which mail will be the reply-to - */ - function getReplyTo($_part = true) - { - $_retValue = ''; + /** + * Retrieves the Address from which mail will be the reply-to + * + * @param boolean $_part To "strip" 'Real name' from address + * @return string Address from which mail will be the reply-to + */ + public function getReplyTo($_part = true) + { + $_retValue = ''; - if ( $_part === true ) - $_retValue = $this->_msgReplyTo; - else - $_retValue = $this->_msgReplyTo[$_part]; + if ( $_part === true ) + $_retValue = $this->_msgReplyTo; + else + $_retValue = $this->_msgReplyTo[$_part]; - return $_retValue; - } + return $_retValue; + } - /** - * Inserts given addresses into structured format. - * This method takes a list of given addresses, via an array - * or a COMMA delimted string, and inserts them into a highly - * structured array. This array is designed to remove duplicate - * addresses and to sort them by Domain. - * - * @param string $_type TO, CC, or BCC lists to add addrresses into - * @param mixed $_addrList Array or COMMA delimited string of addresses - * @return void - * - */ - function _buildAddrList($_type, $_addrList) - { - // Pull existing list - $aryHost = $this->_msgRecipients; + /** + * Inserts given addresses into structured format. + * This method takes a list of given addresses, via an array + * or a COMMA delimted string, and inserts them into a highly + * structured array. This array is designed to remove duplicate + * addresses and to sort them by Domain. + * + * @param string $_type TO, CC, or BCC lists to add addrresses into + * @param mixed $_addrList Array or COMMA delimited string of addresses + * @return void + * + */ + private function _buildAddrList($_type, $_addrList) + { + // Pull existing list + $aryHost = $this->_msgRecipients; - // Only run this if we have something - if ( !empty($_addrList)) - { - // $_addrList can be a STRING or an array - if ( is_string($_addrList) ) - { - // This could be a COMMA delimited string - if ( strstr($_addrList, ',') ) - // "explode "list" into an array - $_addrList = explode(',', $_addrList); + // Only run this if we have something + if ( !empty($_addrList)) + { + // $_addrList can be a STRING or an array + if ( is_string($_addrList) ) + { + // This could be a COMMA delimited string + if ( strstr($_addrList, ',') ) + // "explode "list" into an array + $_addrList = explode(',', $_addrList); - // Stick it in an array - else - $_addrList = array($_addrList); - } + // Stick it in an array + else + $_addrList = array($_addrList); + } - // take the array of addresses and split them further - foreach ($_addrList as $_strAddr) - { - // Strip off the end '>' - $_strAddr = str_replace('>', '', $_strAddr); + // take the array of addresses and split them further + foreach ($_addrList as $_strAddr) + { + // Strip off the end '>' + $_strAddr = str_replace('>', '', $_strAddr); - // Seperate "Real Name" from eMail address - $_tmpaddr = null; - $_tmpaddr = explode('<', $_strAddr); + // Seperate "Real Name" from eMail address + $_tmpaddr = null; + $_tmpaddr = explode('<', $_strAddr); - // We have a "Real Name" and eMail address - if ( count($_tmpaddr) == 2 ) - { - $_tmpHost = explode('@', $_tmpaddr[1]); - $_tmpaddr[0] = trim($_tmpaddr[0], ' ">'); - $aryHost[$_tmpHost[1]][$_type][$_tmpHost[0]] = $_tmpaddr[0]; - } - // We only have an eMail address - else - { - // Strip off the beggining '<' - $_strAddr = str_replace('<', '', $_strAddr); + // We have a "Real Name" and eMail address + if ( count($_tmpaddr) == 2 ) + { + $_tmpHost = explode('@', $_tmpaddr[1]); + $_tmpaddr[0] = trim($_tmpaddr[0], ' ">'); + $aryHost[$_tmpHost[1]][$_type][$_tmpHost[0]] = $_tmpaddr[0]; + } + // We only have an eMail address + else + { + // Strip off the beggining '<' + $_strAddr = str_replace('<', '', $_strAddr); - $_tmpHost = explode('@', $_strAddr); - $_tmpHost[0] = trim($_tmpHost[0]); - $_tmpHost[1] = trim($_tmpHost[1]); + $_tmpHost = explode('@', $_strAddr); + $_tmpHost[0] = trim($_tmpHost[0]); + $_tmpHost[1] = trim($_tmpHost[1]); - $aryHost[$_tmpHost[1]][$_type][$_tmpHost[0]] = ''; - } - } - } - // replace list - $this->_msgRecipients = $aryHost; - } + $aryHost[$_tmpHost[1]][$_type][$_tmpHost[0]] = ''; + } + } + } + // replace list + $this->_msgRecipients = $aryHost; + } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps - /** - * Returns an array of the various parts of an email address - * This assumes a well formed address: - * - "Real name" - * - "Real Name" is optional - * - if "Real Name" does not exist, the angle brackets are optional - * This will split an email address into 4 or 5 parts. - * - $_aryEmail[org] = orignal string - * - $_aryEmail[real] = "real name" - if there is one - * - $_aryEmail[addr] = address part "username@domain.tld" - * - $_aryEmail[host] = "domain.tld" - * - $_aryEmail[user] = "userName" - * - * @param string $_strAddr Email address - * @return array An array of the various parts of an email address - */ - function _strip_email($_strAddr) - { + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Returns an array of the various parts of an email address + * This assumes a well formed address: + * - "Real name" + * - "Real Name" is optional + * - if "Real Name" does not exist, the angle brackets are optional + * This will split an email address into 4 or 5 parts. + * - $_aryEmail[org] = orignal string + * - $_aryEmail[real] = "real name" - if there is one + * - $_aryEmail[addr] = address part "username@domain.tld" + * - $_aryEmail[host] = "domain.tld" + * - $_aryEmail[user] = "userName" + * + * @param string $_strAddr Email address + * @return array An array of the various parts of an email address + */ + private function _strip_email($_strAddr) + { // phpcs:enable - // Keep the orginal - $_aryEmail['org'] = $_strAddr; + // Keep the orginal + $_aryEmail['org'] = $_strAddr; - // Set entire string to Lower Case - $_strAddr = strtolower($_strAddr); + // Set entire string to Lower Case + $_strAddr = strtolower($_strAddr); - // Drop "stuff' off the end - $_strAddr = trim($_strAddr, ' ">'); + // Drop "stuff' off the end + $_strAddr = trim($_strAddr, ' ">'); - // Seperate "Real Name" from eMail address, if we have one - $_tmpAry = explode('<', $_strAddr); + // Seperate "Real Name" from eMail address, if we have one + $_tmpAry = explode('<', $_strAddr); - // Do we have a "Real name" - if ( count($_tmpAry) == 2 ) - { - // We may not really have a "Real Name" - if ( $_tmpAry[0]) - $_aryEmail['real'] = trim($_tmpAry[0], ' ">'); + // Do we have a "Real name" + if ( count($_tmpAry) == 2 ) + { + // We may not really have a "Real Name" + if ( $_tmpAry[0]) + $_aryEmail['real'] = trim($_tmpAry[0], ' ">'); - $_aryEmail['addr'] = $_tmpAry[1]; - } - else - $_aryEmail['addr'] = $_tmpAry[0]; + $_aryEmail['addr'] = $_tmpAry[1]; + } + else + $_aryEmail['addr'] = $_tmpAry[0]; - // Pull User Name and Host.tld apart - list($_aryEmail['user'], $_aryEmail['host'] ) = explode('@', $_aryEmail['addr']); + // Pull User Name and Host.tld apart + list($_aryEmail['user'], $_aryEmail['host'] ) = explode('@', $_aryEmail['addr']); - // Put the brackets back around the address - $_aryEmail['addr'] = '<' . $_aryEmail['addr'] . '>'; + // Put the brackets back around the address + $_aryEmail['addr'] = '<' . $_aryEmail['addr'] . '>'; - return $_aryEmail; - } + return $_aryEmail; + } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps - /** - * Returns an array of bares addresses for use with 'RCPT TO:' - * This is a "build as you go" method. Each time this method is called - * the underlaying array is destroyed and reconstructed. - * - * @return array Returns an array of bares addresses - */ - function get_RCPT_list() - { + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Returns an array of bares addresses for use with 'RCPT TO:' + * This is a "build as you go" method. Each time this method is called + * the underlaying array is destroyed and reconstructed. + * + * @return array Returns an array of bares addresses + */ + public function get_RCPT_list() + { // phpcs:enable - /** - * An array of bares addresses for use with 'RCPT TO:' - */ - $_RCPT_list=array(); + /** + * An array of bares addresses for use with 'RCPT TO:' + */ + $_RCPT_list=array(); - // walk down Recipients array and pull just email addresses - foreach ($this->_msgRecipients as $_host => $_list) - { - foreach ($_list as $_subList) - { - foreach ($_subList as $_name => $_addr) - { - // build RCPT list - $_RCPT_list[] = $_name . '@' . $_host; - } - } - } + // walk down Recipients array and pull just email addresses + foreach ($this->_msgRecipients as $_host => $_list) + { + foreach ($_list as $_subList) + { + foreach ($_subList as $_name => $_addr) + { + // build RCPT list + $_RCPT_list[] = $_name . '@' . $_host; + } + } + } - return $_RCPT_list; - } + return $_RCPT_list; + } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps - /** - * Returns an array of addresses for a specific type; TO, CC or BCC - * - * @param string $_which Which collection of addresses to return ('to', 'cc', 'bcc') - * @return string|false Array of emaill address - */ - function get_email_list($_which = null) - { + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Returns an array of addresses for a specific type; TO, CC or BCC + * + * @param string $_which Which collection of addresses to return ('to', 'cc', 'bcc') + * @return string|false Array of emaill address + */ + public function get_email_list($_which = null) + { // phpcs:enable - // We need to know which address segment to pull - if ( $_which ) - { - // Make sure we have addresses to process - if ( $this->_msgRecipients ) - { - $_RCPT_list=array(); - // walk down Recipients array and pull just email addresses - foreach ($this->_msgRecipients as $_host => $_list) - { - if ( $this->_msgRecipients[$_host][$_which] ) - { - foreach ($this->_msgRecipients[$_host][$_which] as $_addr => $_realName) - { - if ( $_realName ) // @CHANGE LDR - { - $_realName = '"' . $_realName . '"'; - $_RCPT_list[] = $_realName . ' <' . $_addr . '@' . $_host . '>'; - } - else - { - $_RCPT_list[] = $_addr . '@' . $_host; - } - } - } - } + // We need to know which address segment to pull + if ( $_which ) + { + // Make sure we have addresses to process + if ( $this->_msgRecipients ) + { + $_RCPT_list=array(); + // walk down Recipients array and pull just email addresses + foreach ($this->_msgRecipients as $_host => $_list) + { + if ( $this->_msgRecipients[$_host][$_which] ) + { + foreach ($this->_msgRecipients[$_host][$_which] as $_addr => $_realName) + { + if ( $_realName ) // @CHANGE LDR + { + $_realName = '"' . $_realName . '"'; + $_RCPT_list[] = $_realName . ' <' . $_addr . '@' . $_host . '>'; + } + else + { + $_RCPT_list[] = $_addr . '@' . $_host; + } + } + } + } - return implode(', ', $_RCPT_list); - } - else - { - $this->_setErr(101, 'No eMail Address for message to be sent to.'); - return false; - } - } - else - { - $this->_setErr(102, 'eMail type not defined.'); - return false; - } - } + return implode(', ', $_RCPT_list); + } + else + { + $this->_setErr(101, 'No eMail Address for message to be sent to.'); + return false; + } + } + else + { + $this->_setErr(102, 'eMail type not defined.'); + return false; + } + } - /** - * TO Address[es] inwhich to send mail to - * - * @param string $_addrTo TO Address[es] inwhich to send mail to - * @return void - */ - function setTO($_addrTo) - { - if ( $_addrTo ) - $this->_buildAddrList('to', $_addrTo); - } + /** + * TO Address[es] inwhich to send mail to + * + * @param string $_addrTo TO Address[es] inwhich to send mail to + * @return void + */ + public function setTO($_addrTo) + { + if ( $_addrTo ) + $this->_buildAddrList('to', $_addrTo); + } - /** - * Retrieves the TO Address[es] inwhich to send mail to - * - * @return string TO Address[es] inwhich to send mail to - */ - function getTo() - { - return $this->get_email_list('to'); - } + /** + * Retrieves the TO Address[es] inwhich to send mail to + * + * @return string TO Address[es] inwhich to send mail to + */ + public function getTo() + { + return $this->get_email_list('to'); + } - /** - * CC Address[es] inwhich to send mail to - * - * @param string $_strCC CC Address[es] inwhich to send mail to - * @return void - */ - function setCC($_strCC) - { - if ( $_strCC ) - $this->_buildAddrList('cc', $_strCC); - } + /** + * CC Address[es] inwhich to send mail to + * + * @param string $_strCC CC Address[es] inwhich to send mail to + * @return void + */ + public function setCC($_strCC) + { + if ( $_strCC ) + $this->_buildAddrList('cc', $_strCC); + } - /** - * Retrieves the CC Address[es] inwhich to send mail to - * - * @return string CC Address[es] inwhich to send mail to - */ - function getCC() - { - return $this->get_email_list('cc'); - } + /** + * Retrieves the CC Address[es] inwhich to send mail to + * + * @return string CC Address[es] inwhich to send mail to + */ + public function getCC() + { + return $this->get_email_list('cc'); + } - /** - * BCC Address[es] inwhich to send mail to - * - * @param string $_strBCC Recipients BCC Address[es] inwhich to send mail to - * @return void - */ - function setBCC($_strBCC) - { - if ( $_strBCC ) - $this->_buildAddrList('bcc', $_strBCC); - } + /** + * BCC Address[es] inwhich to send mail to + * + * @param string $_strBCC Recipients BCC Address[es] inwhich to send mail to + * @return void + */ + public function setBCC($_strBCC) + { + if ( $_strBCC ) + $this->_buildAddrList('bcc', $_strBCC); + } - /** - * Retrieves the BCC Address[es] inwhich to send mail to - * - * @return string BCC Address[es] inwhich to send mail to - */ - function getBCC() - { - return $this->get_email_list('bcc'); - } + /** + * Retrieves the BCC Address[es] inwhich to send mail to + * + * @return string BCC Address[es] inwhich to send mail to + */ + public function getBCC() + { + return $this->get_email_list('bcc'); + } - /** - * Message Subject - * - * @param string $_strSubject Message Subject - * @return void - */ - function setSubject($_strSubject = '') - { - if ( $_strSubject ) - $this->_msgSubject = $_strSubject; - } + /** + * Message Subject + * + * @param string $_strSubject Message Subject + * @return void + */ + public function setSubject($_strSubject = '') + { + if ( $_strSubject ) + $this->_msgSubject = $_strSubject; + } - /** - * Retrieves the Message Subject - * - * @return string Message Subject - */ - function getSubject() - { - return $this->_msgSubject; - } + /** + * Retrieves the Message Subject + * + * @return string Message Subject + */ + public function getSubject() + { + return $this->_msgSubject; + } - /** - * Constructes and returns message header - * - * @return string Complete message header - */ - function getHeader() - { - global $conf; + /** + * Constructes and returns message header + * + * @return string Complete message header + */ + public function getHeader() + { + global $conf; - $_header = 'From: ' . $this->getFrom('org') . "\r\n" - . 'To: ' . $this->getTO() . "\r\n"; + $_header = 'From: ' . $this->getFrom('org') . "\r\n" + . 'To: ' . $this->getTO() . "\r\n"; - if ( $this->getCC() ) - $_header .= 'Cc: ' . $this->getCC() . "\r\n"; + if ( $this->getCC() ) + $_header .= 'Cc: ' . $this->getCC() . "\r\n"; - /* Note: - * BCC email addresses must be listed in the RCPT TO command list, - * but the BCC header should not be printed under the DATA command. - * So it is included into the function sendMsg() but not here. - * http://stackoverflow.com/questions/2750211/sending-bcc-emails-using-a-smtp-server - */ - /* - if ( $this->getBCC() ) - $_header .= 'Bcc: ' . $this->getBCC() . "\r\n"; + /* Note: + * BCC email addresses must be listed in the RCPT TO command list, + * but the BCC header should not be printed under the DATA command. + * So it is included into the function sendMsg() but not here. + * http://stackoverflow.com/questions/2750211/sending-bcc-emails-using-a-smtp-server + */ + /* + if ( $this->getBCC() ) + $_header .= 'Bcc: ' . $this->getBCC() . "\r\n"; */ - $host=$this->getHost(); - $usetls = preg_match('@tls://@i', $host); - - $host=preg_replace('@tcp://@i', '', $host); // Remove prefix - $host=preg_replace('@ssl://@i', '', $host); // Remove prefix - $host=preg_replace('@tls://@i', '', $host); // Remove prefix - - $host=dol_getprefix('email'); - - //NOTE: Message-ID should probably contain the username of the user who sent the msg - $_header .= 'Subject: ' . $this->getSubject() . "\r\n"; - $_header .= 'Date: ' . date("r") . "\r\n"; - - $trackid = $this->getTrackId(); - if ($trackid) - { - // References is kept in response and Message-ID is returned into In-Reply-To: - $_header .= 'Message-ID: <' . time() . '.SMTPs-dolibarr-'.$trackid.'@' . $host . ">\r\n"; - $_header .= 'References: <' . time() . '.SMTPs-dolibarr-'.$trackid.'@' . $host . ">\r\n"; - $_header .= 'X-Dolibarr-TRACKID: ' . $trackid . '@' . $host . "\r\n"; - } - else - { - $_header .= 'Message-ID: <' . time() . '.SMTPs@' . $host . ">\r\n"; - } - if (! empty($_SERVER['REMOTE_ADDR'])) $_header .= "X-RemoteAddr: " . $_SERVER['REMOTE_ADDR']. "\r\n"; - if ( $this->getMoreInHeader() ) - $_header .= $this->getMoreInHeader(); // Value must include the "\r\n"; - - //$_header .= - // 'Read-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n" - // 'Return-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n"; - - if ( $this->getSensitivity() ) - $_header .= 'Sensitivity: ' . $this->getSensitivity() . "\r\n"; - - if ( $this->_msgPriority != 3 ) - $_header .= $this->getPriority(); - - - // @CHANGE LDR - if ( $this->getDeliveryReceipt() ) - $_header .= 'Disposition-Notification-To: '.$this->getFrom('addr') . "\r\n"; - if ( $this->getErrorsTo() ) - $_header .= 'Errors-To: '.$this->getErrorsTo('addr') . "\r\n"; - if ( $this->getReplyTo() ) - $_header .= "Reply-To: ".$this->getReplyTo('addr') ."\r\n"; - - $_header .= 'X-Mailer: Dolibarr version ' . DOL_VERSION .' (using SMTPs Mailer)' . "\r\n"; - $_header .= 'X-Dolibarr-Option: '.($conf->global->MAIN_MAIL_USE_MULTI_PART?'MAIN_MAIL_USE_MULTI_PART':'No MAIN_MAIL_USE_MULTI_PART') . "\r\n"; - $_header .= 'Mime-Version: 1.0' . "\r\n"; - - - return $_header; - } - - /** - * Message Content - * - * @param string $strContent Message Content - * @param string $strType Type - * @return void - */ - function setBodyContent($strContent, $strType = 'plain') - { - //if ( $strContent ) - //{ - if ( $strType == 'html' ) - $strMimeType = 'text/html'; - else - $strMimeType = 'text/plain'; - - // Make RFC821 Compliant, replace bare linefeeds - $strContent = preg_replace("/(?]*>/", " ", $strContent); - $strContentAltText = html_entity_decode(strip_tags($strContentAltText)); - $strContentAltText = rtrim(wordwrap($strContentAltText, 75, "\r\n")); - } - - // Make RFC2045 Compliant - //$strContent = rtrim(chunk_split($strContent)); // Function chunck_split seems ko if not used on a base64 content - $strContent = rtrim(wordwrap($strContent, 75, "\r\n")); // TODO Using this method creates unexpected line break on text/plain content. - - $this->_msgContent[$strType] = array(); - - $this->_msgContent[$strType]['mimeType'] = $strMimeType; - $this->_msgContent[$strType]['data'] = $strContent; - $this->_msgContent[$strType]['dataText'] = $strContentAltText; - - if ( $this->getMD5flag() ) - $this->_msgContent[$strType]['md5'] = dol_hash($strContent, 3); - //} - } - - /** - * Retrieves the Message Content - * - * @return string Message Content - */ - function getBodyContent() - { - global $conf; - - // Generate a new Boundary string - $this->_setBoundary(); - - // What type[s] of content do we have - $_types = array_keys($this->_msgContent); - - // How many content types do we have - $keyCount = count($_types); - - // If we have ZERO, we have a problem - if( $keyCount === 0 ) - die("Sorry, no content"); - - // If we have ONE, we can use the simple format - elseif( $keyCount === 1 && empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) - { - $_msgData = $this->_msgContent; - $_msgData = $_msgData[$_types[0]]; - - $content = 'Content-Type: ' . $_msgData['mimeType'] . '; charset="' . $this->getCharSet() . '"' . "\r\n" - . 'Content-Transfer-Encoding: ' . $this->getTransEncodeType() . "\r\n" - . 'Content-Disposition: inline' . "\r\n" - . 'Content-Description: Message' . "\r\n"; - - if ( $this->getMD5flag() ) - $content .= 'Content-MD5: ' . $_msgData['md5'] . "\r\n"; - - $content .= "\r\n" - . $_msgData['data'] . "\r\n"; - } - - // If we have more than ONE, we use the multi-part format - elseif( $keyCount >= 1 || ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) - { - // Since this is an actual multi-part message - // We need to define a content message Boundary - // NOTE: This was 'multipart/alternative', but Windows based mail servers have issues with this. - - //$content = 'Content-Type: multipart/related; boundary="' . $this->_getBoundary() . '"' . "\r\n"; - $content = 'Content-Type: multipart/mixed; boundary="' . $this->_getBoundary('mixed') . '"' . "\r\n"; - - // . "\r\n" - // . 'This is a multi-part message in MIME format.' . "\r\n"; - $content .= "Content-Transfer-Encoding: 8bit\r\n"; - $content .= "\r\n"; - - $content .= "--" . $this->_getBoundary('mixed') . "\r\n"; - - if (key_exists('image', $this->_msgContent)) // If inline image found - { - $content.= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"' . "\r\n"; - $content .= "\r\n"; - $content .= "--" . $this->_getBoundary('alternative') . "\r\n"; - } - - - // $this->_msgContent must be sorted with key 'text' or 'html' first then 'image' then 'attachment' - - - // Loop through message content array - foreach ($this->_msgContent as $type => $_content) - { - if ( $type == 'attachment' ) - { - // loop through all attachments - foreach ($_content as $_file => $_data) - { - $content .= "--" . $this->_getBoundary('mixed') . "\r\n" - . 'Content-Disposition: attachment; filename="' . $_data['fileName'] . '"' . "\r\n" - . 'Content-Type: ' . $_data['mimeType'] . '; name="' . $_data['fileName'] . '"' . "\r\n" - . 'Content-Transfer-Encoding: base64' . "\r\n" - . 'Content-Description: ' . $_data['fileName'] ."\r\n"; - - if ( $this->getMD5flag() ) - $content .= 'Content-MD5: ' . $_data['md5'] . "\r\n"; - - $content .= "\r\n" . $_data['data'] . "\r\n\r\n"; - } - } - // @CHANGE LDR - elseif ( $type == 'image' ) - { - // loop through all images - foreach ($_content as $_image => $_data) - { - $content .= "--" . $this->_getBoundary('related') . "\r\n"; // always related for an inline image - - $content .= 'Content-Type: ' . $_data['mimeType'] . '; name="' . $_data['imageName'] . '"' . "\r\n" - . 'Content-Transfer-Encoding: base64' . "\r\n" - . 'Content-Disposition: inline; filename="' . $_data['imageName'] . '"' . "\r\n" - . 'Content-ID: <' . $_data['cid'] . '> ' . "\r\n"; - - if ( $this->getMD5flag() ) - $content .= 'Content-MD5: ' . $_data['md5'] . "\r\n"; - - $content .= "\r\n" - . $_data['data'] . "\r\n"; - } - - // always end related and end alternative after inline images - $content.= "--" . $this->_getBoundary('related') . "--" . "\r\n"; - $content.= "\r\n" . "--" . $this->_getBoundary('alternative') . "--" . "\r\n"; - $content.= "\r\n"; - } - else - { - if (key_exists('image', $this->_msgContent)) - { - $content.= "Content-Type: text/plain; charset=" . $this->getCharSet() . "\r\n"; - $content.= "\r\n" . ($_content['dataText']?$_content['dataText']:strip_tags($_content['data'])) . "\r\n"; // Add plain text message - $content.= "--" . $this->_getBoundary('alternative') . "\r\n"; - $content.= 'Content-Type: multipart/related; boundary="' . $this->_getBoundary('related') . '"' . "\r\n"; - $content.= "\r\n"; - $content.= "--" . $this->_getBoundary('related') . "\r\n"; - } - - if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part before html part - { - $content.= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"' . "\r\n"; - $content .= "\r\n"; - $content .= "--" . $this->_getBoundary('alternative') . "\r\n"; - - $content.= "Content-Type: text/plain; charset=" . $this->getCharSet() . "\r\n"; - $content.= "\r\n". $_content['dataText'] . "\r\n"; - $content.= "--" . $this->_getBoundary('alternative') . "\r\n"; - } - - $content .= 'Content-Type: ' . $_content['mimeType'] . '; ' - // . 'charset="' . $this->getCharSet() . '"'; - . 'charset=' . $this->getCharSet() . ''; - - // $content .= ( $type == 'html') ? '; name="HTML Part"' : ''; - $content .= "\r\n"; - // $content .= 'Content-Transfer-Encoding: '; - // $content .= ($type == 'html') ? 'quoted-printable' : $this->getTransEncodeType(); - // $content .= "\r\n" - // . 'Content-Disposition: inline' . "\r\n" - // . 'Content-Description: ' . $type . ' message' . "\r\n"; - - if ( $this->getMD5flag() ) - $content .= 'Content-MD5: ' . $_content['md5'] . "\r\n"; - - $content .= "\r\n" . $_content['data'] . "\r\n"; - - if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part after html part - { - $content.= "--" . $this->_getBoundary('alternative') . "--". "\r\n"; - } - - $content .= "\r\n"; - } - } - - // Close message boundries - // $content .= "\r\n--" . $this->_getBoundary() . '--' . "\r\n" ; - $content .= "--" . $this->_getBoundary('mixed') . '--' . "\r\n" ; - } - - return $content; - } - - /** - * File attachments are added to the content array as sub-arrays, - * allowing for multiple attachments for each outbound email - * - * @param string $strContent File data to attach to message - * @param string $strFileName File Name to give to attachment - * @param string $strMimeType File Mime Type of attachment - * @return void - */ - function setAttachment($strContent, $strFileName = 'unknown', $strMimeType = 'unknown') - { - if ( $strContent ) - { - $strContent = rtrim(chunk_split(base64_encode($strContent), 76, "\r\n")); // 76 max is defined into http://tools.ietf.org/html/rfc2047 - - $this->_msgContent['attachment'][$strFileName]['mimeType'] = $strMimeType; - $this->_msgContent['attachment'][$strFileName]['fileName'] = $strFileName; - $this->_msgContent['attachment'][$strFileName]['data'] = $strContent; - - if ( $this->getMD5flag() ) - $this->_msgContent['attachment'][$strFileName]['md5'] = dol_hash($strContent, 3); - } - } - - - // @CHANGE LDR - - /** - * Image attachments are added to the content array as sub-arrays, - * allowing for multiple images for each outbound email - * - * @param string $strContent Image data to attach to message - * @param string $strImageName Image Name to give to attachment - * @param string $strMimeType Image Mime Type of attachment - * @param string $strImageCid CID - * @return void - */ - function setImageInline($strContent, $strImageName = 'unknown', $strMimeType = 'unknown', $strImageCid = 'unknown') - { - if ($strContent) - { - $this->_msgContent['image'][$strImageName]['mimeType'] = $strMimeType; - $this->_msgContent['image'][$strImageName]['imageName'] = $strImageName; - $this->_msgContent['image'][$strImageName]['cid'] = $strImageCid; - $this->_msgContent['image'][$strImageName]['data'] = $strContent; - - if ( $this->getMD5flag() ) - $this->_msgContent['image'][$strImageName]['md5'] = dol_hash($strContent, 3); - } - } - // END @CHANGE LDR - - - /** - * Message Content Sensitivity - * Message Sensitivity values: - * - [0] None - default - * - [1] Personal - * - [2] Private - * - [3] Company Confidential - * - * @param integer $_value Message Sensitivity - * @return void - */ - function setSensitivity($_value = 0) - { - if ( ( is_numeric($_value) ) && - ( ( $_value >= 0 ) && ( $_value <= 3 ) ) ) - $this->_msgSensitivity = $_value; - } - - /** - * Returns Message Content Sensitivity string - * Message Sensitivity values: - * - [0] None - default - * - [1] Personal - * - [2] Private - * - [3] Company Confidential - * - * @return void - */ - function getSensitivity() - { - return $this->_arySensitivity[$this->_msgSensitivity]; - } - - /** - * Message Content Priority - * Message Priority values: - * - [0] 'Bulk' - * - [1] 'Highest' - * - [2] 'High' - * - [3] 'Normal' - default - * - [4] 'Low' - * - [5] 'Lowest' - * - * @param integer $_value Message Priority - * @return void - */ - function setPriority($_value = 3) - { - if ( ( is_numeric($_value) ) && - ( ( $_value >= 0 ) && ( $_value <= 5 ) ) ) - $this->_msgPriority = $_value; - } - - /** - * Message Content Priority - * Message Priority values: - * - [0] 'Bulk' - * - [1] 'Highest' - * - [2] 'High' - * - [3] 'Normal' - default - * - [4] 'Low' - * - [5] 'Lowest' - * - * @return string - */ - function getPriority() - { - return 'Importance: ' . $this->_aryPriority[$this->_msgPriority] . "\r\n" - . 'Priority: ' . $this->_aryPriority[$this->_msgPriority] . "\r\n" - . 'X-Priority: ' . $this->_msgPriority . ' (' . $this->_aryPriority[$this->_msgPriority] . ')' . "\r\n"; - } - - /** - * Set flag which determines whether to calculate message MD5 checksum. - * - * @param string $_flag Message Priority - * @return void - */ - function setMD5flag($_flag = false) - { - $this->_smtpMD5 = $_flag; - } - - /** - * Gets flag which determines whether to calculate message MD5 checksum. - * - * @return boolean Message Priority - */ - function getMD5flag() - { - return $this->_smtpMD5; - } - - /** - * Message X-Header Content - * This is a simple "insert". Whatever is given will be placed - * "as is" into the Xheader array. - * - * @param string $strXdata Message X-Header Content - * @return void - */ - function setXheader($strXdata) - { - if ( $strXdata ) - $this->_msgXheader[] = $strXdata; - } - - /** - * Retrieves the Message X-Header Content - * - * @return string[] $_msgContent Message X-Header Content - */ - function getXheader() - { - return $this->_msgXheader; - } - - /** - * Generates Random string for MIME message Boundary - * - * @return void - */ - function _setBoundary() - { - $this->_smtpsBoundary = "multipart_x." . time() . ".x_boundary"; - $this->_smtpsRelatedBoundary = 'mul_'.dol_hash(uniqid("dolibarr2"), 3); - $this->_smtpsAlternativeBoundary = 'mul_'.dol_hash(uniqid("dolibarr3"), 3); - } - - /** - * Retrieves the MIME message Boundary - * - * @param string $type Type of boundary - * @return string $_smtpsBoundary MIME message Boundary - */ - function _getBoundary($type = 'mixed') - { - if ($type == 'mixed') return $this->_smtpsBoundary; - elseif ($type == 'related') return $this->_smtpsRelatedBoundary; - elseif ($type == 'alternative') return $this->_smtpsAlternativeBoundary; - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps - /** - * This function has been modified as provided by SirSir to allow multiline responses when - * using SMTP Extensions - * - * @param Handler $socket Socket handler - * @param string $response Response. Example: "550 5.7.1 https://support.google.com/a/answer/6140680#invalidcred j21sm814390wre.3" - * @return boolean True or false - */ - function server_parse($socket, $response) - { + $host=$this->getHost(); + $usetls = preg_match('@tls://@i', $host); + + $host=preg_replace('@tcp://@i', '', $host); // Remove prefix + $host=preg_replace('@ssl://@i', '', $host); // Remove prefix + $host=preg_replace('@tls://@i', '', $host); // Remove prefix + + $host=dol_getprefix('email'); + + //NOTE: Message-ID should probably contain the username of the user who sent the msg + $_header .= 'Subject: ' . $this->getSubject() . "\r\n"; + $_header .= 'Date: ' . date("r") . "\r\n"; + + $trackid = $this->getTrackId(); + if ($trackid) + { + // References is kept in response and Message-ID is returned into In-Reply-To: + $_header .= 'Message-ID: <' . time() . '.SMTPs-dolibarr-'.$trackid.'@' . $host . ">\r\n"; + $_header .= 'References: <' . time() . '.SMTPs-dolibarr-'.$trackid.'@' . $host . ">\r\n"; + $_header .= 'X-Dolibarr-TRACKID: ' . $trackid . '@' . $host . "\r\n"; + } + else + { + $_header .= 'Message-ID: <' . time() . '.SMTPs@' . $host . ">\r\n"; + } + if (! empty($_SERVER['REMOTE_ADDR'])) $_header .= "X-RemoteAddr: " . $_SERVER['REMOTE_ADDR']. "\r\n"; + if ( $this->getMoreInHeader() ) + $_header .= $this->getMoreInHeader(); // Value must include the "\r\n"; + + //$_header .= + // 'Read-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n" + // 'Return-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n"; + + if ( $this->getSensitivity() ) + $_header .= 'Sensitivity: ' . $this->getSensitivity() . "\r\n"; + + if ( $this->_msgPriority != 3 ) + $_header .= $this->getPriority(); + + + // @CHANGE LDR + if ( $this->getDeliveryReceipt() ) + $_header .= 'Disposition-Notification-To: '.$this->getFrom('addr') . "\r\n"; + if ( $this->getErrorsTo() ) + $_header .= 'Errors-To: '.$this->getErrorsTo('addr') . "\r\n"; + if ( $this->getReplyTo() ) + $_header .= "Reply-To: ".$this->getReplyTo('addr') ."\r\n"; + + $_header .= 'X-Mailer: Dolibarr version ' . DOL_VERSION .' (using SMTPs Mailer)' . "\r\n"; + $_header .= 'X-Dolibarr-Option: '.($conf->global->MAIN_MAIL_USE_MULTI_PART?'MAIN_MAIL_USE_MULTI_PART':'No MAIN_MAIL_USE_MULTI_PART') . "\r\n"; + $_header .= 'Mime-Version: 1.0' . "\r\n"; + + + return $_header; + } + + /** + * Message Content + * + * @param string $strContent Message Content + * @param string $strType Type + * @return void + */ + public function setBodyContent($strContent, $strType = 'plain') + { + //if ( $strContent ) + //{ + if ( $strType == 'html' ) + $strMimeType = 'text/html'; + else + $strMimeType = 'text/plain'; + + // Make RFC821 Compliant, replace bare linefeeds + $strContent = preg_replace("/(?]*>/", " ", $strContent); + $strContentAltText = html_entity_decode(strip_tags($strContentAltText)); + $strContentAltText = rtrim(wordwrap($strContentAltText, 75, "\r\n")); + } + + // Make RFC2045 Compliant + //$strContent = rtrim(chunk_split($strContent)); // Function chunck_split seems ko if not used on a base64 content + $strContent = rtrim(wordwrap($strContent, 75, "\r\n")); // TODO Using this method creates unexpected line break on text/plain content. + + $this->_msgContent[$strType] = array(); + + $this->_msgContent[$strType]['mimeType'] = $strMimeType; + $this->_msgContent[$strType]['data'] = $strContent; + $this->_msgContent[$strType]['dataText'] = $strContentAltText; + + if ( $this->getMD5flag() ) + $this->_msgContent[$strType]['md5'] = dol_hash($strContent, 3); + //} + } + + /** + * Retrieves the Message Content + * + * @return string Message Content + */ + public function getBodyContent() + { + global $conf; + + // Generate a new Boundary string + $this->_setBoundary(); + + // What type[s] of content do we have + $_types = array_keys($this->_msgContent); + + // How many content types do we have + $keyCount = count($_types); + + // If we have ZERO, we have a problem + if( $keyCount === 0 ) + die("Sorry, no content"); + + // If we have ONE, we can use the simple format + elseif( $keyCount === 1 && empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) + { + $_msgData = $this->_msgContent; + $_msgData = $_msgData[$_types[0]]; + + $content = 'Content-Type: ' . $_msgData['mimeType'] . '; charset="' . $this->getCharSet() . '"' . "\r\n" + . 'Content-Transfer-Encoding: ' . $this->getTransEncodeType() . "\r\n" + . 'Content-Disposition: inline' . "\r\n" + . 'Content-Description: Message' . "\r\n"; + + if ( $this->getMD5flag() ) + $content .= 'Content-MD5: ' . $_msgData['md5'] . "\r\n"; + + $content .= "\r\n" + . $_msgData['data'] . "\r\n"; + } + + // If we have more than ONE, we use the multi-part format + elseif( $keyCount >= 1 || ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) + { + // Since this is an actual multi-part message + // We need to define a content message Boundary + // NOTE: This was 'multipart/alternative', but Windows based mail servers have issues with this. + + //$content = 'Content-Type: multipart/related; boundary="' . $this->_getBoundary() . '"' . "\r\n"; + $content = 'Content-Type: multipart/mixed; boundary="' . $this->_getBoundary('mixed') . '"' . "\r\n"; + + // . "\r\n" + // . 'This is a multi-part message in MIME format.' . "\r\n"; + $content .= "Content-Transfer-Encoding: 8bit\r\n"; + $content .= "\r\n"; + + $content .= "--" . $this->_getBoundary('mixed') . "\r\n"; + + if (key_exists('image', $this->_msgContent)) // If inline image found + { + $content.= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"' . "\r\n"; + $content .= "\r\n"; + $content .= "--" . $this->_getBoundary('alternative') . "\r\n"; + } + + + // $this->_msgContent must be sorted with key 'text' or 'html' first then 'image' then 'attachment' + + + // Loop through message content array + foreach ($this->_msgContent as $type => $_content) + { + if ( $type == 'attachment' ) + { + // loop through all attachments + foreach ($_content as $_file => $_data) + { + $content .= "--" . $this->_getBoundary('mixed') . "\r\n" + . 'Content-Disposition: attachment; filename="' . $_data['fileName'] . '"' . "\r\n" + . 'Content-Type: ' . $_data['mimeType'] . '; name="' . $_data['fileName'] . '"' . "\r\n" + . 'Content-Transfer-Encoding: base64' . "\r\n" + . 'Content-Description: ' . $_data['fileName'] ."\r\n"; + + if ( $this->getMD5flag() ) + $content .= 'Content-MD5: ' . $_data['md5'] . "\r\n"; + + $content .= "\r\n" . $_data['data'] . "\r\n\r\n"; + } + } + // @CHANGE LDR + elseif ( $type == 'image' ) + { + // loop through all images + foreach ($_content as $_image => $_data) + { + $content .= "--" . $this->_getBoundary('related') . "\r\n"; // always related for an inline image + + $content .= 'Content-Type: ' . $_data['mimeType'] . '; name="' . $_data['imageName'] . '"' . "\r\n" + . 'Content-Transfer-Encoding: base64' . "\r\n" + . 'Content-Disposition: inline; filename="' . $_data['imageName'] . '"' . "\r\n" + . 'Content-ID: <' . $_data['cid'] . '> ' . "\r\n"; + + if ( $this->getMD5flag() ) + $content .= 'Content-MD5: ' . $_data['md5'] . "\r\n"; + + $content .= "\r\n" + . $_data['data'] . "\r\n"; + } + + // always end related and end alternative after inline images + $content.= "--" . $this->_getBoundary('related') . "--" . "\r\n"; + $content.= "\r\n" . "--" . $this->_getBoundary('alternative') . "--" . "\r\n"; + $content.= "\r\n"; + } + else + { + if (key_exists('image', $this->_msgContent)) + { + $content.= "Content-Type: text/plain; charset=" . $this->getCharSet() . "\r\n"; + $content.= "\r\n" . ($_content['dataText']?$_content['dataText']:strip_tags($_content['data'])) . "\r\n"; // Add plain text message + $content.= "--" . $this->_getBoundary('alternative') . "\r\n"; + $content.= 'Content-Type: multipart/related; boundary="' . $this->_getBoundary('related') . '"' . "\r\n"; + $content.= "\r\n"; + $content.= "--" . $this->_getBoundary('related') . "\r\n"; + } + + if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part before html part + { + $content.= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"' . "\r\n"; + $content .= "\r\n"; + $content .= "--" . $this->_getBoundary('alternative') . "\r\n"; + + $content.= "Content-Type: text/plain; charset=" . $this->getCharSet() . "\r\n"; + $content.= "\r\n". $_content['dataText'] . "\r\n"; + $content.= "--" . $this->_getBoundary('alternative') . "\r\n"; + } + + $content .= 'Content-Type: ' . $_content['mimeType'] . '; ' + // . 'charset="' . $this->getCharSet() . '"'; + . 'charset=' . $this->getCharSet() . ''; + + // $content .= ( $type == 'html') ? '; name="HTML Part"' : ''; + $content .= "\r\n"; + // $content .= 'Content-Transfer-Encoding: '; + // $content .= ($type == 'html') ? 'quoted-printable' : $this->getTransEncodeType(); + // $content .= "\r\n" + // . 'Content-Disposition: inline' . "\r\n" + // . 'Content-Description: ' . $type . ' message' . "\r\n"; + + if ( $this->getMD5flag() ) + $content .= 'Content-MD5: ' . $_content['md5'] . "\r\n"; + + $content .= "\r\n" . $_content['data'] . "\r\n"; + + if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part after html part + { + $content.= "--" . $this->_getBoundary('alternative') . "--". "\r\n"; + } + + $content .= "\r\n"; + } + } + + // Close message boundries + // $content .= "\r\n--" . $this->_getBoundary() . '--' . "\r\n" ; + $content .= "--" . $this->_getBoundary('mixed') . '--' . "\r\n" ; + } + + return $content; + } + + /** + * File attachments are added to the content array as sub-arrays, + * allowing for multiple attachments for each outbound email + * + * @param string $strContent File data to attach to message + * @param string $strFileName File Name to give to attachment + * @param string $strMimeType File Mime Type of attachment + * @return void + */ + public function setAttachment($strContent, $strFileName = 'unknown', $strMimeType = 'unknown') + { + if ( $strContent ) + { + $strContent = rtrim(chunk_split(base64_encode($strContent), 76, "\r\n")); // 76 max is defined into http://tools.ietf.org/html/rfc2047 + + $this->_msgContent['attachment'][$strFileName]['mimeType'] = $strMimeType; + $this->_msgContent['attachment'][$strFileName]['fileName'] = $strFileName; + $this->_msgContent['attachment'][$strFileName]['data'] = $strContent; + + if ( $this->getMD5flag() ) + $this->_msgContent['attachment'][$strFileName]['md5'] = dol_hash($strContent, 3); + } + } + + + // @CHANGE LDR + + /** + * Image attachments are added to the content array as sub-arrays, + * allowing for multiple images for each outbound email + * + * @param string $strContent Image data to attach to message + * @param string $strImageName Image Name to give to attachment + * @param string $strMimeType Image Mime Type of attachment + * @param string $strImageCid CID + * @return void + */ + public function setImageInline($strContent, $strImageName = 'unknown', $strMimeType = 'unknown', $strImageCid = 'unknown') + { + if ($strContent) + { + $this->_msgContent['image'][$strImageName]['mimeType'] = $strMimeType; + $this->_msgContent['image'][$strImageName]['imageName'] = $strImageName; + $this->_msgContent['image'][$strImageName]['cid'] = $strImageCid; + $this->_msgContent['image'][$strImageName]['data'] = $strContent; + + if ( $this->getMD5flag() ) + $this->_msgContent['image'][$strImageName]['md5'] = dol_hash($strContent, 3); + } + } + // END @CHANGE LDR + + + /** + * Message Content Sensitivity + * Message Sensitivity values: + * - [0] None - default + * - [1] Personal + * - [2] Private + * - [3] Company Confidential + * + * @param integer $_value Message Sensitivity + * @return void + */ + public function setSensitivity($_value = 0) + { + if ( ( is_numeric($_value) ) && + ( ( $_value >= 0 ) && ( $_value <= 3 ) ) ) + $this->_msgSensitivity = $_value; + } + + /** + * Returns Message Content Sensitivity string + * Message Sensitivity values: + * - [0] None - default + * - [1] Personal + * - [2] Private + * - [3] Company Confidential + * + * @return void + */ + public function getSensitivity() + { + return $this->_arySensitivity[$this->_msgSensitivity]; + } + + /** + * Message Content Priority + * Message Priority values: + * - [0] 'Bulk' + * - [1] 'Highest' + * - [2] 'High' + * - [3] 'Normal' - default + * - [4] 'Low' + * - [5] 'Lowest' + * + * @param integer $_value Message Priority + * @return void + */ + public function setPriority($_value = 3) + { + if ( ( is_numeric($_value) ) && + ( ( $_value >= 0 ) && ( $_value <= 5 ) ) ) + $this->_msgPriority = $_value; + } + + /** + * Message Content Priority + * Message Priority values: + * - [0] 'Bulk' + * - [1] 'Highest' + * - [2] 'High' + * - [3] 'Normal' - default + * - [4] 'Low' + * - [5] 'Lowest' + * + * @return string + */ + public function getPriority() + { + return 'Importance: ' . $this->_aryPriority[$this->_msgPriority] . "\r\n" + . 'Priority: ' . $this->_aryPriority[$this->_msgPriority] . "\r\n" + . 'X-Priority: ' . $this->_msgPriority . ' (' . $this->_aryPriority[$this->_msgPriority] . ')' . "\r\n"; + } + + /** + * Set flag which determines whether to calculate message MD5 checksum. + * + * @param string $_flag Message Priority + * @return void + */ + public function setMD5flag($_flag = false) + { + $this->_smtpMD5 = $_flag; + } + + /** + * Gets flag which determines whether to calculate message MD5 checksum. + * + * @return boolean Message Priority + */ + public function getMD5flag() + { + return $this->_smtpMD5; + } + + /** + * Message X-Header Content + * This is a simple "insert". Whatever is given will be placed + * "as is" into the Xheader array. + * + * @param string $strXdata Message X-Header Content + * @return void + */ + public function setXheader($strXdata) + { + if ( $strXdata ) + $this->_msgXheader[] = $strXdata; + } + + /** + * Retrieves the Message X-Header Content + * + * @return string[] $_msgContent Message X-Header Content + */ + public function getXheader() + { + return $this->_msgXheader; + } + + /** + * Generates Random string for MIME message Boundary + * + * @return void + */ + private function _setBoundary() + { + $this->_smtpsBoundary = "multipart_x." . time() . ".x_boundary"; + $this->_smtpsRelatedBoundary = 'mul_'.dol_hash(uniqid("dolibarr2"), 3); + $this->_smtpsAlternativeBoundary = 'mul_'.dol_hash(uniqid("dolibarr3"), 3); + } + + /** + * Retrieves the MIME message Boundary + * + * @param string $type Type of boundary + * @return string $_smtpsBoundary MIME message Boundary + */ + private function _getBoundary($type = 'mixed') + { + if ($type == 'mixed') return $this->_smtpsBoundary; + elseif ($type == 'related') return $this->_smtpsRelatedBoundary; + elseif ($type == 'alternative') return $this->_smtpsAlternativeBoundary; + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * This function has been modified as provided by SirSir to allow multiline responses when + * using SMTP Extensions + * + * @param Handler $socket Socket handler + * @param string $response Response. Example: "550 5.7.1 https://support.google.com/a/answer/6140680#invalidcred j21sm814390wre.3" + * @return boolean True or false + */ + public function server_parse($socket, $response) + { // phpcs:enable - /** - * Returns constructed SELECT Object string or boolean upon failure - * Default value is set at true - */ - $_retVal = true; + /** + * Returns constructed SELECT Object string or boolean upon failure + * Default value is set at true + */ + $_retVal = true; - $server_response = ''; + $server_response = ''; // avoid infinite loop $limit=0; - while (substr($server_response, 3, 1) != ' ' && $limit<100) - { - if (! ($server_response = fgets($socket, 256))) - { - $this->_setErr(121, "Couldn't get mail server response codes"); - $_retVal = false; - break; - } + while (substr($server_response, 3, 1) != ' ' && $limit<100) + { + if (! ($server_response = fgets($socket, 256))) + { + $this->_setErr(121, "Couldn't get mail server response codes"); + $_retVal = false; + break; + } $limit++; - } + } - if (! (substr($server_response, 0, 3) == $response)) - { - $this->_setErr(120, "Ran into problems sending Mail.\r\nResponse: $server_response"); - $_retVal = false; - } + if (! (substr($server_response, 0, 3) == $response)) + { + $this->_setErr(120, "Ran into problems sending Mail.\r\nResponse: $server_response"); + $_retVal = false; + } - return $_retVal; - } + return $_retVal; + } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps - /** - * Send str - * - * @param string $_strSend String to send - * @param string $_returnCode Return code - * @param string $CRLF CRLF - * @return boolean|null True or false - */ - function socket_send_str($_strSend, $_returnCode = null, $CRLF = "\r\n") - { - // phpcs:enable - if ($this->_debug) $this->log.=$_strSend; // @CHANGE LDR for log - fputs($this->socket, $_strSend . $CRLF); - if ($this->_debug) $this->log.=' ('.$_returnCode.')' . $CRLF; - - if ( $_returnCode ) - return $this->server_parse($this->socket, $_returnCode); - } - - // ============================================================= - // ** Error handling methods - - /** - * Defines errors codes and messages for Class - * - * @param int $_errNum Error Code Number - * @param string $_errMsg Error Message - * @return void + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Send str + * + * @param string $_strSend String to send + * @param string $_returnCode Return code + * @param string $CRLF CRLF + * @return boolean|null True or false */ - function _setErr($_errNum, $_errMsg) + public function socket_send_str($_strSend, $_returnCode = null, $CRLF = "\r\n") + { + // phpcs:enable + if ($this->_debug) $this->log.=$_strSend; // @CHANGE LDR for log + fputs($this->socket, $_strSend . $CRLF); + if ($this->_debug) $this->log.=' ('.$_returnCode.')' . $CRLF; + + if ( $_returnCode ) + return $this->server_parse($this->socket, $_returnCode); + } + + // ============================================================= + // ** Error handling methods + + /** + * Defines errors codes and messages for Class + * + * @param int $_errNum Error Code Number + * @param string $_errMsg Error Message + * @return void + */ + private function _setErr($_errNum, $_errMsg) { $this->_smtpsErrors[] = array( 'num' => $_errNum, @@ -1835,25 +1835,25 @@ class SMTPs ); } - /** - * Returns errors codes and messages for Class - * - * @return string $_errMsg Error Message - */ - function getErrors() - { - $_errMsg = array(); + /** + * Returns errors codes and messages for Class + * + * @return string $_errMsg Error Message + */ + public function getErrors() + { + $_errMsg = array(); - if (is_array($this->_smtpsErrors)) - { - foreach ($this->_smtpsErrors as $_err => $_info) - { - $_errMsg[] = 'Error [' . $_info['num'] .']: '. $_info['msg']; - } - } + if (is_array($this->_smtpsErrors)) + { + foreach ($this->_smtpsErrors as $_err => $_info) + { + $_errMsg[] = 'Error [' . $_info['num'] .']: '. $_info['msg']; + } + } - return implode("\n", $_errMsg); - } + return implode("\n", $_errMsg); + } } diff --git a/htdocs/core/class/stats.class.php b/htdocs/core/class/stats.class.php index bbdebab81b0..b35e9947644 100644 --- a/htdocs/core/class/stats.class.php +++ b/htdocs/core/class/stats.class.php @@ -42,7 +42,7 @@ abstract class Stats * @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is month number, 2=Label of absiss is first letter of month * @return array Array of values */ - function getNbByMonthWithPrevYear($endyear, $startyear, $cachedelay = 0, $format = 0) + public function getNbByMonthWithPrevYear($endyear, $startyear, $cachedelay = 0, $format = 0) { global $conf,$user,$langs; @@ -136,7 +136,7 @@ abstract class Stats * @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is month number, 2=Label of absiss is first letter of month * @return array Array of values */ - function getAmountByMonthWithPrevYear($endyear, $startyear, $cachedelay = 0, $format = 0) + public function getAmountByMonthWithPrevYear($endyear, $startyear, $cachedelay = 0, $format = 0) { global $conf,$user,$langs; @@ -228,8 +228,8 @@ abstract class Stats * @param int $startyear End year * @return array Array of values */ - function getAverageByMonthWithPrevYear($endyear, $startyear) - { + public function getAverageByMonthWithPrevYear($endyear, $startyear) + { if ($startyear > $endyear) return -1; $datay=array(); @@ -264,9 +264,9 @@ abstract class Stats * @param int $cachedelay Delay we accept for cache file (0=No read, no save of cache, -1=No read but save) * @return array Array of values */ - function getAllByProductEntry($year, $cachedelay = 0) - { - global $conf,$user,$langs; + public function getAllByProductEntry($year, $cachedelay = 0) + { + global $conf,$user,$langs; $datay=array(); @@ -333,14 +333,16 @@ abstract class Stats // Here we have low level of shared code called by XxxStats.class.php - /** + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore + /** * Return nb of elements by year * * @param string $sql SQL request * @return array */ - function _getNbByYear($sql) - { + protected function _getNbByYear($sql) + { + // phpcs:enable $result = array(); dol_syslog(get_class($this).'::'.__FUNCTION__."", LOG_DEBUG); @@ -363,14 +365,16 @@ abstract class Stats return $result; } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore /** * Return nb of elements, total amount and avg amount each year * * @param string $sql SQL request * @return array Array with nb, total amount, average for each year */ - function _getAllByYear($sql) + protected function _getAllByYear($sql) { + // phpcs:enable $result = array(); dol_syslog(get_class($this).'::'.__FUNCTION__."", LOG_DEBUG); @@ -405,6 +409,7 @@ abstract class Stats return $result; } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore /** * Renvoie le nombre de proposition par mois pour une annee donnee * @@ -412,9 +417,10 @@ abstract class Stats * @param string $sql SQL * @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is month number, 2=Label of absiss is first letter of month * @return array Array of nb each month - */ - function _getNbByMonth($year, $sql, $format = 0) - { + */ + protected function _getNbByMonth($year, $sql, $format = 0) + { + // phpcs:enable global $langs; $result=array(); @@ -462,6 +468,7 @@ abstract class Stats } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore /** * Renvoie le nombre d'element par mois pour une annee donnee * @@ -470,8 +477,9 @@ abstract class Stats * @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is month number, 2=Label of absiss is first letter of month * @return array */ - function _getAmountByMonth($year, $sql, $format = 0) - { + protected function _getAmountByMonth($year, $sql, $format = 0) + { + // phpcs:enable global $langs; $result=array(); @@ -514,18 +522,20 @@ abstract class Stats } return $data; - } + } - /** - * Renvoie le montant moyen par mois pour une annee donnee - * - * @param int $year Year - * @param string $sql SQL - * @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is month number, 2=Label of absiss is first letter of month - * @return array - */ - function _getAverageByMonth($year, $sql, $format = 0) - { + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore + /** + * Renvoie le montant moyen par mois pour une annee donnee + * + * @param int $year Year + * @param string $sql SQL + * @param int $format 0=Label of absiss is a translated text, 1=Label of absiss is month number, 2=Label of absiss is first letter of month + * @return array + */ + protected function _getAverageByMonth($year, $sql, $format = 0) + { + // phpcs:enable global $langs; $result=array(); @@ -567,18 +577,20 @@ abstract class Stats } return $data; - } + } - /** - * Return number or total of product refs - * - * @param string $sql SQL - * @param int $limit Limit - * @return array - */ - function _getAllByProduct($sql, $limit = 10) - { + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore + /** + * Return number or total of product refs + * + * @param string $sql SQL + * @param int $limit Limit + * @return array + */ + protected function _getAllByProduct($sql, $limit = 10) + { + // phpcs:enable global $langs; $result=array(); @@ -592,16 +604,16 @@ abstract class Stats $i = 0; $other=0; while ($i < $num) { - $row = $this->db->fetch_row($resql); + $row = $this->db->fetch_row($resql); if ($i < $limit || $num == $limit) $result[$i] = array($row[0],$row[1]); // Ref of product, nb else $other += $row[1]; $i++; - } + } if ($num > $limit) $result[$i] = array($langs->transnoentitiesnoconv("Other"),$other); $this->db->free($resql); } else dol_print_error($this->db); return $result; - } + } } diff --git a/htdocs/core/class/translate.class.php b/htdocs/core/class/translate.class.php index bc104bb2b79..e0865a640e4 100644 --- a/htdocs/core/class/translate.class.php +++ b/htdocs/core/class/translate.class.php @@ -48,7 +48,7 @@ class Translate * @param string $dir Force directory that contains /langs subdirectory (value is sometimes '..' like into install/* pages or support/* pages). Use '' by default. * @param Conf $conf Object with Dolibarr configuration */ - function __construct($dir, $conf) + public function __construct($dir, $conf) { if (! empty($conf->file->character_set_client)) $this->charset_output=$conf->file->character_set_client; // If charset output is forced if ($dir) $this->dir=array($dir); @@ -62,7 +62,7 @@ class Translate * @param string $srclang Language to use. If '' or 'auto', we use browser lang. * @return void */ - function setDefaultLang($srclang = 'en_US') + public function setDefaultLang($srclang = 'en_US') { global $conf; @@ -132,7 +132,7 @@ class Translate * @param int $mode 0=Long language code, 1=Short language code (en, fr, es, ...) * @return string Language code used (en_US, en_AU, fr_FR, ...) */ - function getDefaultLang($mode = 0) + public function getDefaultLang($mode = 0) { if (empty($mode)) return $this->defaultlang; else return substr($this->defaultlang, 0, 2); @@ -145,7 +145,7 @@ class Translate * @param array $domains Array of lang files to load * @return int <0 if KO, 0 if already loaded or loading not required, >0 if OK */ - function loadLangs($domains) + public function loadLangs($domains) { foreach($domains as $domain) { @@ -173,7 +173,7 @@ class Translate * @return int <0 if KO, 0 if already loaded or loading not required, >0 if OK * @see loadLangs */ - function load($domain, $alt = 0, $stopafterdirection = 0, $forcelangdir = '', $loadfromfileonly = 0) + public function load($domain, $alt = 0, $stopafterdirection = 0, $forcelangdir = '', $loadfromfileonly = 0) { global $conf,$db; @@ -399,7 +399,7 @@ class Translate * @param Database $db Database handler * @return int <0 if KO, 0 if already loaded or loading not required, >0 if OK */ - function loadFromDatabase($db) + public function loadFromDatabase($db) { global $conf; @@ -537,8 +537,8 @@ class Translate * @param string $key Key to translate * @return string Translated string (translated with transnoentitiesnoconv) */ - private function getTradFromKey($key) - { + private function getTradFromKey($key) + { global $conf, $db; if (! is_string($key)) return 'ErrorBadValueForParamNotAString'; // Avoid multiple errors with code not using function correctly. @@ -577,7 +577,7 @@ class Translate }*/ return $newstr; - } + } /** @@ -593,9 +593,9 @@ class Translate * @param string $param4 chaine de param4 * @param int $maxsize Max length of text * @return string Translated string (encoded into HTML entities and UTF8) - */ - function trans($key, $param1 = '', $param2 = '', $param3 = '', $param4 = '', $maxsize = 0) - { + */ + public function trans($key, $param1 = '', $param2 = '', $param3 = '', $param4 = '', $maxsize = 0) + { global $conf; if (! empty($this->tab_translate[$key])) // Translation is available @@ -638,7 +638,7 @@ class Translate //if ($key[0] == '$') { return dol_eval($key,1); } return $this->getTradFromKey($key); } - } + } /** @@ -655,7 +655,7 @@ class Translate * @param string $param5 chaine de param5 * @return string Translated string (encoded into UTF8) */ - function transnoentities($key, $param1 = '', $param2 = '', $param3 = '', $param4 = '', $param5 = '') + public function transnoentities($key, $param1 = '', $param2 = '', $param3 = '', $param4 = '', $param5 = '') { return $this->convToOutputCharset($this->transnoentitiesnoconv($key, $param1, $param2, $param3, $param4, $param5)); } @@ -676,7 +676,7 @@ class Translate * @param string $param5 chaine de param5 * @return string Translated string */ - function transnoentitiesnoconv($key, $param1 = '', $param2 = '', $param3 = '', $param4 = '', $param5 = '') + public function transnoentitiesnoconv($key, $param1 = '', $param2 = '', $param3 = '', $param4 = '', $param5 = '') { global $conf; @@ -719,7 +719,7 @@ class Translate * @param string $countrycode country code (FR, ...) * @return string translated string */ - function transcountry($str, $countrycode) + public function transcountry($str, $countrycode) { if ($this->tab_translate["$str$countrycode"]) return $this->trans("$str$countrycode"); else return $this->trans($str); @@ -733,7 +733,7 @@ class Translate * @param string $countrycode country code (FR, ...) * @return string translated string */ - function transcountrynoentities($str, $countrycode) + public function transcountrynoentities($str, $countrycode) { if ($this->tab_translate["$str$countrycode"]) return $this->transnoentities("$str$countrycode"); else return $this->transnoentities($str); @@ -747,7 +747,7 @@ class Translate * @param string $pagecodefrom Page code of src string * @return string Converted string */ - function convToOutputCharset($str, $pagecodefrom = 'UTF-8') + public function convToOutputCharset($str, $pagecodefrom = 'UTF-8') { if ($pagecodefrom == 'ISO-8859-1' && $this->charset_output == 'UTF-8') $str=utf8_encode($str); if ($pagecodefrom == 'UTF-8' && $this->charset_output == 'ISO-8859-1') $str=utf8_decode(str_replace('€', chr(128), $str)); @@ -755,7 +755,7 @@ class Translate } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return list of all available languages * @@ -764,8 +764,8 @@ class Translate * @param int $usecode 1=Show code instead of country name for language variant, 2=Show only code * @return array List of languages */ - function get_available_languages($langdir = DOL_DOCUMENT_ROOT, $maxlength = 0, $usecode = 0) - { + public function get_available_languages($langdir = DOL_DOCUMENT_ROOT, $maxlength = 0, $usecode = 0) + { // phpcs:enable global $conf; @@ -793,10 +793,10 @@ class Translate } } return $langs_available; - } + } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return if a filename $filename exists for current language (or alternate language) * @@ -804,8 +804,8 @@ class Translate * @param integer $searchalt Search also alernate language file * @return boolean true if exists and readable */ - function file_exists($filename, $searchalt = 0) - { + public function file_exists($filename, $searchalt = 0) + { // phpcs:enable // Test si fichier dans repertoire de la langue foreach($this->dir as $searchdir) @@ -822,7 +822,7 @@ class Translate } return false; - } + } /** @@ -836,8 +836,8 @@ class Translate * 10 if setDefaultLang was en_US => ten * 123 if setDefaultLang was fr_FR => cent vingt trois */ - function getLabelFromNumber($number, $isamount = 0) - { + public function getLabelFromNumber($number, $isamount = 0) + { global $conf; $newnumber=$number; @@ -861,7 +861,7 @@ class Translate } return $newnumber; - } + } /** @@ -879,8 +879,8 @@ class Translate * @return string Label in UTF8 (but without entities) * @see dol_getIdFromCode */ - function getLabelFromKey($db, $key, $tablename, $fieldkey, $fieldlabel, $keyforselect = '', $filteronentity = 0) - { + public function getLabelFromKey($db, $key, $tablename, $fieldkey, $fieldlabel, $keyforselect = '', $filteronentity = 0) + { // If key empty if ($key == '') return ''; @@ -919,7 +919,7 @@ class Translate $this->error=$db->lasterror(); return -1; } - } + } /** @@ -931,7 +931,7 @@ class Translate * @deprecated Use method price to output a price * @see price() */ - function getCurrencyAmount($currency_code, $amount) + public function getCurrencyAmount($currency_code, $amount) { $symbol=$this->getCurrencySymbol($currency_code); @@ -947,8 +947,8 @@ class Translate * @param integer $forceloadall 1=Force to load all currencies into cache. We know we need to use all of them. By default read and cache only required currency. * @return string Currency symbol encoded into UTF8 */ - function getCurrencySymbol($currency_code, $forceloadall = 0) - { + public function getCurrencySymbol($currency_code, $forceloadall = 0) + { $currency_sign = ''; // By default return iso code if (function_exists("mb_convert_encoding")) @@ -965,7 +965,7 @@ class Translate } return ($currency_sign?$currency_sign:$currency_code); - } + } /** * Load into the cache this->cache_currencies, all currencies @@ -1021,23 +1021,23 @@ class Translate } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return an array with content of all loaded translation keys (found into this->tab_translate) so * we get a substitution array we can use for substitutions (for mail or ODT generation for example) * * @return array Array of translation keys lang_key => string_translation_loaded */ - function get_translations_for_substitutions() - { + public function get_translations_for_substitutions() + { // phpcs:enable - $substitutionarray = array(); + $substitutionarray = array(); - foreach($this->tab_translate as $code => $label) { - $substitutionarray['lang_'.$code] = $label; - $substitutionarray['__('.$code.')__'] = $label; - } + foreach($this->tab_translate as $code => $label) { + $substitutionarray['lang_'.$code] = $label; + $substitutionarray['__('.$code.')__'] = $label; + } - return $substitutionarray; - } + return $substitutionarray; + } } diff --git a/htdocs/core/class/utils.class.php b/htdocs/core/class/utils.class.php index f0850dabae1..a5a3bd8aca9 100644 --- a/htdocs/core/class/utils.class.php +++ b/htdocs/core/class/utils.class.php @@ -843,7 +843,7 @@ class Utils $this->output = 'Archive log files (keeping last SYSLOG_FILE_SAVES='.$nbSaves.' files) done.'; return 0; - } + } /** Backup the db OR just a table without mysqldump binary, with PHP only (does not require any exec permission) * Author: David Walsh (http://davidwalsh.name/backup-mysql-database-php) diff --git a/htdocs/core/class/vcard.class.php b/htdocs/core/class/vcard.class.php index 3a2b9e70830..fc240a88dcc 100644 --- a/htdocs/core/class/vcard.class.php +++ b/htdocs/core/class/vcard.class.php @@ -92,13 +92,13 @@ class vCard /** - * mise en forme du numero de telephone + * mise en forme du numero de telephone * - * @param int $number numero de telephone - * @param string $type Type - * @return void + * @param int $number numero de telephone + * @param string $type Type + * @return void */ - function setPhoneNumber($number, $type = "") + public function setPhoneNumber($number, $type = "") { // type may be PREF | WORK | HOME | VOICE | FAX | MSG | CELL | PAGER | BBS | CAR | MODEM | ISDN | VIDEO or any senseful combination, e.g. "PREF;WORK;VOICE" $key = "TEL"; @@ -115,7 +115,7 @@ class vCard * @param string $photo Photo * @return void */ - function setPhoto($type, $photo) + public function setPhoto($type, $photo) { // $type = "GIF" | "JPEG" $this->properties["PHOTO;TYPE=$type;ENCODING=BASE64"] = base64_encode($photo); @@ -127,7 +127,7 @@ class vCard * @param string $name Name * @return void */ - function setFormattedName($name) + public function setFormattedName($name) { $this->properties["FN;CHARSET=".$this->encoding] = encode($name); } @@ -142,7 +142,7 @@ class vCard * @param string $suffix Suffix * @return void */ - function setName($family = "", $first = "", $additional = "", $prefix = "", $suffix = "") + public function setName($family = "", $first = "", $additional = "", $prefix = "", $suffix = "") { $this->properties["N;CHARSET=".$this->encoding] = encode($family).";".encode($first).";".encode($additional).";".encode($prefix).";".encode($suffix); $this->filename = "$first%20$family.vcf"; @@ -155,7 +155,7 @@ class vCard * @param timestamp $date Date * @return void */ - function setBirthday($date) + public function setBirthday($date) { // $date format is YYYY-MM-DD - RFC 2425 and RFC 2426 $this->properties["BDAY"] = dol_print_date($date, 'dayrfc'); @@ -174,7 +174,7 @@ class vCard * @param string $type Type * @return void */ - function setAddress($postoffice = "", $extended = "", $street = "", $city = "", $region = "", $zip = "", $country = "", $type = "HOME;POSTAL") + public function setAddress($postoffice = "", $extended = "", $street = "", $city = "", $region = "", $zip = "", $country = "", $type = "HOME;POSTAL") { // $type may be DOM | INTL | POSTAL | PARCEL | HOME | WORK or any combination of these: e.g. "WORK;PARCEL;POSTAL" $key = "ADR"; @@ -189,19 +189,19 @@ class vCard } /** - * mise en forme du label + * mise en forme du label * - * @param string $postoffice Postoffice - * @param string $extended Extended - * @param string $street Street - * @param string $city City - * @param string $region Region - * @param string $zip Zip - * @param string $country Country - * @param string $type Type - * @return void + * @param string $postoffice Postoffice + * @param string $extended Extended + * @param string $street Street + * @param string $city City + * @param string $region Region + * @param string $zip Zip + * @param string $country Country + * @param string $type Type + * @return void */ - function setLabel($postoffice = "", $extended = "", $street = "", $city = "", $region = "", $zip = "", $country = "", $type = "HOME;POSTAL") + public function setLabel($postoffice = "", $extended = "", $street = "", $city = "", $region = "", $zip = "", $country = "", $type = "HOME;POSTAL") { $label = ""; if ($postoffice!="") $label.= "$postoffice\r\n"; @@ -222,7 +222,7 @@ class vCard * @param string $type Vcard type * @return void */ - function setEmail($address, $type = "internet,pref") + public function setEmail($address, $type = "internet,pref") { $this->properties["EMAIL;TYPE=".$type] = $address; } @@ -233,7 +233,7 @@ class vCard * @param string $note Note * @return void */ - function setNote($note) + public function setNote($note) { $this->properties["NOTE;CHARSET=".$this->encoding] = encode($note); } @@ -244,19 +244,19 @@ class vCard * @param string $title Title * @return void */ - function setTitle($title) + public function setTitle($title) { $this->properties["TITLE;CHARSET=".$this->encoding] = encode($title); } /** - * mise en forme de la societe + * mise en forme de la societe * - * @param string $org Org - * @return void + * @param string $org Org + * @return void */ - function setOrg($org) + public function setOrg($org) { $this->properties["ORG;CHARSET=".$this->encoding] = encode($org); } @@ -268,7 +268,7 @@ class vCard * @param string $prodid Prodid * @return void */ - function setProdId($prodid) + public function setProdId($prodid) { $this->properties["PRODID;CHARSET=".$this->encoding] = encode($prodid); } @@ -280,7 +280,7 @@ class vCard * @param string $uid Uid * @return void */ - function setUID($uid) + public function setUID($uid) { $this->properties["UID;CHARSET=".$this->encoding] = encode($uid); } @@ -293,7 +293,7 @@ class vCard * @param string $type Type * @return void */ - function setURL($url, $type = "") + public function setURL($url, $type = "") { // $type may be WORK | HOME $key = "URL"; @@ -306,7 +306,7 @@ class vCard * * @return string */ - function getVCard() + public function getVCard() { $text = "BEGIN:VCARD\r\n"; $text.= "VERSION:3.0\r\n"; @@ -326,7 +326,7 @@ class vCard * * @return string Filename */ - function getFileName() + public function getFileName() { return $this->filename; } diff --git a/htdocs/core/modules/product/doc/doc_generic_product_odt.modules.php b/htdocs/core/modules/product/doc/doc_generic_product_odt.modules.php index 048c0e06846..edb54b13ace 100644 --- a/htdocs/core/modules/product/doc/doc_generic_product_odt.modules.php +++ b/htdocs/core/modules/product/doc/doc_generic_product_odt.modules.php @@ -61,7 +61,7 @@ class doc_generic_product_odt extends ModelePDFProduct * * @param DoliDB $db Database handler */ - function __construct($db) + public function __construct($db) { global $conf, $langs, $mysoc; @@ -101,12 +101,12 @@ class doc_generic_product_odt extends ModelePDFProduct /** - * Return description of a module + * Return description of a module * - * @param Translate $langs Lang object to use for output - * @return string Description + * @param Translate $langs Lang object to use for output + * @return string Description */ - function info($langs) + public function info($langs) { global $conf, $langs; @@ -205,7 +205,7 @@ class doc_generic_product_odt extends ModelePDFProduct return $texte; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Function to build a document on disk using the generic odt module. * @@ -217,7 +217,7 @@ class doc_generic_product_odt extends ModelePDFProduct * @param int $hideref Do not show ref * @return int 1 if OK, <=0 if KO */ - function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0) + public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0) { // phpcs:enable global $product,$langs,$conf,$mysoc,$hookmanager,$user; @@ -320,8 +320,8 @@ class doc_generic_product_odt extends ModelePDFProduct $contactobject=null; if (! empty($usecontact)) { - // On peut utiliser le nom de la societe du contact - if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) { + // On peut utiliser le nom de la societe du contact + if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) { $socobject = $object->contact; } else { $socobject = $object->thirdparty; diff --git a/htdocs/core/modules/product/doc/pdf_standard.modules.php b/htdocs/core/modules/product/doc/pdf_standard.modules.php index d5bfd453322..6a52af58c8d 100644 --- a/htdocs/core/modules/product/doc/pdf_standard.modules.php +++ b/htdocs/core/modules/product/doc/pdf_standard.modules.php @@ -148,7 +148,7 @@ class pdf_standard extends ModelePDFProduct } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Function to build a document on disk using the generic odt module. * @@ -160,8 +160,8 @@ class pdf_standard extends ModelePDFProduct * @param int $hideref Do not show ref * @return int 1 if OK, <=0 if KO */ - function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0) - { + public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0) + { // phpcs:enable global $user,$langs,$conf,$mysoc,$db,$hookmanager; @@ -204,7 +204,7 @@ class pdf_standard extends ModelePDFProduct if (file_exists($dir)) { - // Add pdfgeneration hook + // Add pdfgeneration hook if (! is_object($hookmanager)) { include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; @@ -592,7 +592,7 @@ class pdf_standard extends ModelePDFProduct $this->error=$langs->trans("ErrorConstantNotDefined", "PRODUCT_OUTPUTDIR"); return 0; } - } + } /** @@ -608,7 +608,7 @@ class pdf_standard extends ModelePDFProduct * @param string $currency Currency code * @return void */ - function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '') + private function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '') { global $conf; @@ -718,7 +718,7 @@ class pdf_standard extends ModelePDFProduct * @param string $titlekey Translation key to show as title of document * @return void */ - function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey = "") + private function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $titlekey = "") { global $conf,$langs,$hookmanager; @@ -855,22 +855,22 @@ class pdf_standard extends ModelePDFProduct */ } - $pdf->SetTextColor(0, 0, 0); - } + $pdf->SetTextColor(0, 0, 0); + } - /** - * Show footer of page. Need this->emetteur object - * - * @param TCPDF $pdf PDF - * @param Object $object Object to show - * @param Translate $outputlangs Object lang for output - * @param int $hidefreetext 1=Hide free text - * @return int Return height of bottom margin including footer text - */ - function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0) - { - global $conf; - $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS; - return pdf_pagefoot($pdf, $outputlangs, 'PRODUCT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext); - } + /** + * Show footer of page. Need this->emetteur object + * + * @param TCPDF $pdf PDF + * @param Object $object Object to show + * @param Translate $outputlangs Object lang for output + * @param int $hidefreetext 1=Hide free text + * @return int Return height of bottom margin including footer text + */ + private function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0) + { + global $conf; + $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS; + return pdf_pagefoot($pdf, $outputlangs, 'PRODUCT_FREE_TEXT', $this->emetteur, $this->marge_basse, $this->marge_gauche, $this->page_hauteur, $object, $showdetails, $hidefreetext); + } } diff --git a/htdocs/core/modules/product/mod_codeproduct_elephant.php b/htdocs/core/modules/product/mod_codeproduct_elephant.php index 8d48d4aa85e..7cea4aca5a3 100644 --- a/htdocs/core/modules/product/mod_codeproduct_elephant.php +++ b/htdocs/core/modules/product/mod_codeproduct_elephant.php @@ -72,7 +72,7 @@ class mod_codeproduct_elephant extends ModeleProductCode /** * Constructor */ - function __construct() + public function __construct() { $this->code_null = 0; $this->code_modifiable = 1; @@ -83,13 +83,14 @@ class mod_codeproduct_elephant extends ModeleProductCode } - /** Return description of module - * - * @param Translate $langs Object langs - * @return string Description of module - */ - function info($langs) - { + /** + * Return description of module + * + * @param Translate $langs Object langs + * @return string Description of module + */ + public function info($langs) + { global $conf, $mc; global $form; @@ -127,7 +128,7 @@ class mod_codeproduct_elephant extends ModeleProductCode $texte.= ''; return $texte; - } + } /** @@ -138,7 +139,7 @@ class mod_codeproduct_elephant extends ModeleProductCode * @param int $type Type of third party (1:customer, 2:supplier, -1:autodetect) * @return string Return string example */ - function getExample($langs, $objproduct = 0, $type = -1) + public function getExample($langs, $objproduct = 0, $type = -1) { if ($type == 0 || $type == -1) { @@ -179,7 +180,7 @@ class mod_codeproduct_elephant extends ModeleProductCode * @param int $type Produit ou service (0:product, 1:service) * @return string Value if OK, '' if module not configured, <0 if KO */ - function getNextValue($objproduct = 0, $type = -1) + public function getNextValue($objproduct = 0, $type = -1) { global $db,$conf; @@ -219,13 +220,13 @@ class mod_codeproduct_elephant extends ModeleProductCode } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Check if mask/numbering use prefix * * @return int 0 or 1 */ - function verif_prefixIsUsed() + public function verif_prefixIsUsed() { // phpcs:enable global $conf; @@ -254,7 +255,7 @@ class mod_codeproduct_elephant extends ModeleProductCode * -4 ErrorPrefixRequired * -5 Other (see this->error) */ - function verif($db, &$code, $product, $type) + public function verif($db, &$code, $product, $type) { global $conf; @@ -298,14 +299,14 @@ class mod_codeproduct_elephant extends ModeleProductCode // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps /** - * Renvoi si un code est pris ou non (par autre tiers) + * Renvoi si un code est pris ou non (par autre tiers) * - * @param DoliDB $db Handler acces base - * @param string $code Code a verifier - * @param Product $product Objet product - * @return int 0 if available, <0 if KO + * @param DoliDB $db Handler acces base + * @param string $code Code a verifier + * @param Product $product Objet product + * @return int 0 if available, <0 if KO */ - function verif_dispo($db, $code, $product) + public function verif_dispo($db, $code, $product) { // phpcs:enable $sql = "SELECT ref FROM ".MAIN_DB_PREFIX."product"; diff --git a/htdocs/core/modules/product/mod_codeproduct_leopard.php b/htdocs/core/modules/product/mod_codeproduct_leopard.php index 1cf17fef6e7..a7b03eed2f0 100644 --- a/htdocs/core/modules/product/mod_codeproduct_leopard.php +++ b/htdocs/core/modules/product/mod_codeproduct_leopard.php @@ -71,7 +71,7 @@ class mod_codeproduct_leopard extends ModeleProductCode /** * Constructor */ - function __construct() + public function __construct() { $this->code_null = 1; $this->code_modifiable = 1; @@ -81,12 +81,13 @@ class mod_codeproduct_leopard extends ModeleProductCode } - /** Return description of module + /** + * Return description of module * - * @param Translate $langs Object langs - * @return string Description of module + * @param Translate $langs Object langs + * @return string Description of module */ - function info($langs) + public function info($langs) { $langs->load("companies"); return $langs->trans("LeopardNumRefModelDesc"); @@ -100,7 +101,7 @@ class mod_codeproduct_leopard extends ModeleProductCode * @param int $type Type of third party (1:customer, 2:supplier, -1:autodetect) * @return string Return next value */ - function getNextValue($objproduct = 0, $type = -1) + public function getNextValue($objproduct = 0, $type = -1) { global $langs; return ''; @@ -108,19 +109,19 @@ class mod_codeproduct_leopard extends ModeleProductCode /** - * Check validity of code according to its rules + * Check validity of code according to its rules * - * @param DoliDB $db Database handler - * @param string $code Code to check/correct - * @param Product $product Object product + * @param DoliDB $db Database handler + * @param string $code Code to check/correct + * @param Product $product Object product * @param int $type 0 = product , 1 = service - * @return int 0 if OK - * -1 ErrorBadProductCodeSyntax - * -2 ErrorProductCodeRequired - * -3 ErrorProductCodeAlreadyUsed - * -4 ErrorPrefixRequired + * @return int 0 if OK + * -1 ErrorBadProductCodeSyntax + * -2 ErrorProductCodeRequired + * -3 ErrorProductCodeAlreadyUsed + * -4 ErrorPrefixRequired */ - function verif($db, &$code, $product, $type) + public function verif($db, &$code, $product, $type) { global $conf; @@ -131,7 +132,7 @@ class mod_codeproduct_leopard extends ModeleProductCode { $result=0; } - elseif (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) ) + elseif (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED))) { $result=-2; } diff --git a/htdocs/core/modules/product/modules_product.class.php b/htdocs/core/modules/product/modules_product.class.php index c0f83c1eace..3ab05e1e4de 100644 --- a/htdocs/core/modules/product/modules_product.class.php +++ b/htdocs/core/modules/product/modules_product.class.php @@ -33,10 +33,10 @@ */ abstract class ModelePDFProduct extends CommonDocGenerator { - /** - * @var string Error code (or message) - */ - public $error=''; + /** + * @var string Error code (or message) + */ + public $error=''; // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps @@ -47,33 +47,33 @@ abstract class ModelePDFProduct extends CommonDocGenerator * @param integer $maxfilenamelength Max length of value to show * @return array List of templates */ - static function liste_modeles($db, $maxfilenamelength = 0) - { + public static function liste_modeles($db, $maxfilenamelength = 0) + { // phpcs:enable - global $conf; + global $conf; - $type='product'; - $liste=array(); + $type='product'; + $liste=array(); - include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; - $liste=getListOfModels($db, $type, $maxfilenamelength); - return $liste; - } + include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; + $liste=getListOfModels($db, $type, $maxfilenamelength); + return $liste; + } } abstract class ModeleProductCode { /** - * @var string Error code (or message) - */ - public $error=''; + * @var string Error code (or message) + */ + public $error=''; /** Renvoi la description par defaut du modele de numerotation * * @param Translate $langs Object langs * @return string Texte descripif */ - function info($langs) + public function info($langs) { $langs->load("bills"); return $langs->trans("NoDescription"); @@ -84,7 +84,7 @@ abstract class ModeleProductCode * @param Translate $langs Object langs * @return string Nom du module */ - function getNom($langs) + public function getNom($langs) { return empty($this->name)?$this->nom:$this->name; } @@ -95,7 +95,7 @@ abstract class ModeleProductCode * @param Translate $langs Object langs * @return string Example */ - function getExample($langs) + public function getExample($langs) { $langs->load("bills"); return $langs->trans("NoExample"); @@ -106,7 +106,7 @@ abstract class ModeleProductCode * * @return boolean false si conflit, true si ok */ - function canBeActivated() + public function canBeActivated() { return true; } @@ -118,7 +118,7 @@ abstract class ModeleProductCode * @param int $type Type * @return string Value */ - function getNextValue($objproduct = 0, $type = -1) + public function getNextValue($objproduct = 0, $type = -1) { global $langs; return $langs->trans("Function_getNextValue_InModuleNotWorking"); @@ -129,7 +129,7 @@ abstract class ModeleProductCode * * @return string Version */ - function getVersion() + public function getVersion() { global $langs; $langs->load("admin"); @@ -141,7 +141,7 @@ abstract class ModeleProductCode return $langs->trans("NotAvailable"); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Renvoi la liste des modeles de numérotation * @@ -149,7 +149,7 @@ abstract class ModeleProductCode * @param integer $maxfilenamelength Max length of value to show * @return array List of numbers */ - static function liste_modeles($db, $maxfilenamelength = 0) + public static function liste_modeles($db, $maxfilenamelength = 0) { // phpcs:enable $liste=array(); @@ -175,22 +175,24 @@ abstract class ModeleProductCode } /** - * Return description of module parameters + * Return description of module parameters * - * @param Translate $langs Output language - * @param Product $product Product object - * @param int $type -1=Nothing, 0=Customer, 1=Supplier - * @return string HTML translated description + * @param Translate $langs Output language + * @param Product $product Product object + * @param int $type -1=Nothing, 0=Customer, 1=Supplier + * @return string HTML translated description */ - function getToolTip($langs, $product, $type) + public function getToolTip($langs, $product, $type) { global $conf; $langs->load("admin"); $s=''; - if ($type == -1) $s.=$langs->trans("Name").': '.$this->getNom($langs).'
'; - if ($type == -1) $s.=$langs->trans("Version").': '.$this->getVersion().'
'; + if ($type == -1) { + $s.=$langs->trans("Name").': '.$this->getNom($langs).'
'; + $s.=$langs->trans("Version").': '.$this->getVersion().'
'; + } if ($type == 0) $s.=$langs->trans("ProductCodeDesc").'
'; if ($type == 1) $s.=$langs->trans("ServiceCodeDesc").'
'; if ($type != -1) $s.=$langs->trans("ValidityControledByModule").': '.$this->getNom($langs).'
'; @@ -243,11 +245,11 @@ abstract class ModeleProductCode // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps /** - * Check if mask/numbering use prefix - * - * @return int 0=no, 1=yes - */ - function verif_prefixIsUsed() + * Check if mask/numbering use prefix + * + * @return int 0=no, 1=yes + */ + public function verif_prefixIsUsed() { // phpcs:enable return 0; diff --git a/htdocs/core/modules/product_batch/modules_product_batch.class.php b/htdocs/core/modules/product_batch/modules_product_batch.class.php index 5708033a8ea..38cd9dda385 100644 --- a/htdocs/core/modules/product_batch/modules_product_batch.class.php +++ b/htdocs/core/modules/product_batch/modules_product_batch.class.php @@ -38,30 +38,30 @@ */ abstract class ModelePDFProductBatch extends CommonDocGenerator { - /** - * @var string Error code (or message) - */ - public $error=''; - - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps /** - * Return list of active generation modules - * + * @var string Error code (or message) + */ + public $error=''; + + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Return list of active generation modules + * * @param DoliDB $db Database handler * @param integer $maxfilenamelength Max length of value to show * @return array List of templates */ - static function liste_modeles($db, $maxfilenamelength = 0) - { + public static function liste_modeles($db, $maxfilenamelength = 0) + { // phpcs:enable - global $conf; + global $conf; - $type='product_batch'; - $list = array(); + $type = 'product_batch'; + $list = array(); - include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; - $list = getListOfModels($db, $type, $maxfilenamelength); - return $list; - } + include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; + $list = getListOfModels($db, $type, $maxfilenamelength); + return $list; + } }