From 405ee9af6fddf2f80b92e48d0b55aa907075c23d Mon Sep 17 00:00:00 2001 From: stagprom Date: Tue, 25 Nov 2014 13:28:43 +0100 Subject: [PATCH] Added many comments to sourcees modified: appinfo/formatphonenumber.php modified: appinfo/ocsmsapp.php modified: controller/smscontroller.php modified: db/smsmapper.php --- appinfo/formatphonenumber.php | 43 +++++++++++++++++++---------------- appinfo/ocsmsapp.php | 7 +++++- controller/smscontroller.php | 1 + db/smsmapper.php | 8 +++---- 4 files changed, 34 insertions(+), 25 deletions(-) diff --git a/appinfo/formatphonenumber.php b/appinfo/formatphonenumber.php index 876b7ec..f64224f 100644 --- a/appinfo/formatphonenumber.php +++ b/appinfo/formatphonenumber.php @@ -14,16 +14,16 @@ namespace OCA\OcSms\AppInfo; class FormatPhoneNumber { public static function formatPhoneNumber($pn) { - $ipnrxp = array( + $ipnrxp = array( // match international numbers with 1,2,3 digits '#^(00|\+)(1\d\d\d)#', // NANP - '#^(00|\+)(2[1|2|3|4|5|6|8|9]\d)#', // +2(1|2|3|4|5|6|8|9)x - '#^(00|\+)(2[0|7])#', // +2x - '#^(00|\+)(3[5|7|8]\d)#', // +3(5|7|8)x - '#^(00|\+)(3[0|1|2|3|4|6|9])#', // +3x - '#^(00|\+)(4[2]\d)#', // +4(2)x + '#^(00|\+)(2[1|2|3|4|5|6|8|9]\d)#', // +2(1|2|3|4|5|6|8|9)x + '#^(00|\+)(2[0|7])#', // +2x + '#^(00|\+)(3[5|7|8]\d)#', // +3(5|7|8)x + '#^(00|\+)(3[0|1|2|3|4|6|9])#', // +3x + '#^(00|\+)(4[2]\d)#', // +4(2)x '#^(00|\+)(4[0|1|3|4|5|6|7|8|9])#', // +4x - '#^(00|\+)(5[0|9]\d)#', // +5(0|9)x - '#^(00|\+)(5[1|2|3|4|5|6|7|8])#', // +5x + '#^(00|\+)(5[0|9]\d)#', // +5(0|9)x + '#^(00|\+)(5[1|2|3|4|5|6|7|8])#', // +5x '#^(00|\+)(6[7|8|9]\d)#', // +6(7|8|9)x '#^(00|\+)(6[0|1|2|3|4|5|6])#', // +6x '#^(00|\+)(7)#', // +7 @@ -31,26 +31,29 @@ class FormatPhoneNumber { '#^(00|\+)(8[1|2|3|4|6])#', // +8x '#^(00|\+)(9[6|7|9]\d)#', // +9(6|7|9)x '#^(00|\+)(9[0|1|2|3|4|5|8])#' // +9x - ); + ); - $lpnrxp = array( - '#(^0)([^0])#', - ); - $lpnrpl = '+49$2'; + $ignrxp = array( // match non digits and + + '#\(\d*\)|[^\d\+]#', + ); - $ignrxp = array( - '#\(\d*\)|[^\d\+]#', - ); + /* + ToDo : make local settings in web-page + */ + $lpnrxp = array( // match local numbers + '#(^0)([^0])#', // in germany : 0-xx[x[x]]-123456 + ); // + $lpnrpl = '+49$2'; // replace with +49 -xx[x[x]]-123456 $tpn = trim($pn); $fpn = ''; $xpn = ''; if( preg_match('#^[\d\+].*#',$tpn)) { // start with digit or + - $fpn = preg_replace($ignrxp, '', $tpn); // replace with '' - $xpn = preg_replace($lpnrxp, $lpnrpl, $fpn); // - $ypn = preg_replace($ipnrxp, '+$2', $xpn); // + $fpn = preg_replace($ignrxp, '', $tpn); // replace everything but digits/+ with '' + $xpn = preg_replace($lpnrxp, $lpnrpl, $fpn); // replace local prenumbers + $ypn = preg_replace($ipnrxp, '+$2', $xpn); // format to international coding +x[x[x]]..... } else - $ypn = $tpn; + $ypn = $tpn; // some SMS_adresses are strings return $ypn; } } diff --git a/appinfo/ocsmsapp.php b/appinfo/ocsmsapp.php index 425a0e9..633b80d 100644 --- a/appinfo/ocsmsapp.php +++ b/appinfo/ocsmsapp.php @@ -27,6 +27,9 @@ class OcSmsApp extends App { /** * @var array used to cache the parsed contacts for every request */ + /* + caching dosn´t work because on every call all will be reinstantiated + */ private static $contacts; // dosn´t work private static $contactsInverted; // dosn´t work @@ -135,6 +138,9 @@ class OcSmsApp extends App { } } + /* + all numbers will be formatted + */ private function pushPhoneNumberToCache($rawPhone, $contactName) { $phoneNb = FormatPhoneNumber::formatPhoneNumber($rawPhone); @@ -143,6 +149,5 @@ class OcSmsApp extends App { if (!isset(self::$contactsInverted[$contactName])) self::$contactsInverted[$contactName] = array(); array_push(self::$contactsInverted[$contactName], $phoneNb); - } } diff --git a/controller/smscontroller.php b/controller/smscontroller.php index dc6eadc..21039a2 100644 --- a/controller/smscontroller.php +++ b/controller/smscontroller.php @@ -133,6 +133,7 @@ class SmsController extends Controller { $msgCount = 0; // Contact resolved if ($contactName != "" && isset($iContacts[$contactName])) { + // forall numbers in iContacts foreach($iContacts[$contactName] as $cnumber) { $messages = $messages + $this->smsMapper->getAllMessagesForPhoneNumber($this->userId, $cnumber, $lastDate); $msgCount += $this->smsMapper->countMessagesForPhoneNumber($this->userId, $cnumber); diff --git a/db/smsmapper.php b/db/smsmapper.php index dff4021..0a5f7c2 100644 --- a/db/smsmapper.php +++ b/db/smsmapper.php @@ -86,7 +86,10 @@ class SmsMapper extends Mapper { } return $phoneList; } - + + /* + get all possible SMS_adresses for a given formated phonenumber + */ public function getAllPhoneNumbersForFPN ($userId,$phoneNumber) { $query = \OCP\DB::prepare('SELECT sms_address FROM ' . '*PREFIX*ocsms_smsdatas WHERE user_id = ? AND sms_mailbox IN (?,?)'); @@ -98,7 +101,6 @@ class SmsMapper extends Mapper { if (!isset($phoneList[$fmtPN])) { $phoneList[$fmtPN] = array(); } - //if (!in_array($pn, $phoneList[$fmtPN])) { if(!isset($phoneList[$fmtPN][$pn])) { $phoneList[$fmtPN][$pn] = 0; } @@ -163,8 +165,6 @@ class SmsMapper extends Mapper { $phoneList = array(); while ($row = $result->fetchRow()) { - //$phoneNumber = preg_replace("#[ ]#", "/", $row["sms_address"]); - //$phoneNumber = \OCA\OcSms\AppInfo\FormatPhoneNumber::formatPhoneNumber($row["sms_address"]); $phoneNumber = $row["sms_address"]; if (!in_array($phoneNumber, $phoneList)) { $phoneList[$phoneNumber] = $row["mx"];