mirror of
https://github.com/nerzhul/ocsms.git
synced 2025-06-07 16:06:15 +00:00
Move formatphonenumber.php to proper dir and rename.
* fix some coding styles * Add contributor
This commit is contained in:
parent
2211252004
commit
5f0263f71e
@ -20,7 +20,7 @@ use \OCA\OcSms\Controller\SmsController;
|
||||
use \OCA\OcSms\Db\Sms;
|
||||
use \OCA\OcSms\Db\SmsMapper;
|
||||
|
||||
use \OCA\OcSms\AppInfo\FormatPhoneNumber;
|
||||
use \OCA\OcSms\Lib\PhoneNumberFormatter;
|
||||
|
||||
class OcSmsApp extends App {
|
||||
|
||||
@ -143,7 +143,7 @@ class OcSmsApp extends App {
|
||||
*/
|
||||
private function pushPhoneNumberToCache($rawPhone, $contactName) {
|
||||
|
||||
$phoneNb = FormatPhoneNumber::formatPhoneNumber($rawPhone);
|
||||
$phoneNb = PhoneNumberFormatter::format($rawPhone);
|
||||
self::$contacts[$phoneNb] = $contactName;
|
||||
// Inverted contacts
|
||||
if (!isset(self::$contactsInverted[$contactName])) {
|
||||
|
@ -18,7 +18,7 @@ use \OCP\AppFramework\Controller;
|
||||
use \OCP\AppFramework\Http\JSONResponse;
|
||||
use \OCA\OcSms\AppInfo\OcSmsApp;
|
||||
use \OCA\OcSms\Db\SmsMapper;
|
||||
use \OCA\OcSms\AppInfo\FormatPhoneNumber;
|
||||
use \OCA\OcSms\Lib\PhoneNumberFormatter;
|
||||
|
||||
class SmsController extends Controller {
|
||||
|
||||
@ -100,7 +100,7 @@ class SmsController extends Controller {
|
||||
|
||||
$countPhone = count($phoneList);
|
||||
foreach ($phoneList as $number => $ts) {
|
||||
$fmtPN = FormatPhoneNumber::formatPhoneNumber($number);
|
||||
$fmtPN = PhoneNumberFormatter::format($number);
|
||||
if (isset($contactsSrc[$number])) {
|
||||
$contacts[$number] = $contactsSrc[$number];
|
||||
} elseif (isset($contactsSrc[$fmtPN])) {
|
||||
@ -123,7 +123,7 @@ class SmsController extends Controller {
|
||||
$contacts = $this->app->getContacts();
|
||||
$iContacts = $this->app->getInvertedContacts();
|
||||
$contactName = "";
|
||||
$fmtPN = FormatPhoneNumber::formatPhoneNumber($phoneNumber);
|
||||
$fmtPN = PhoneNumberFormatter::format($phoneNumber);
|
||||
if (isset($contacts[$fmtPN])) {
|
||||
$contactName = $contacts[$fmtPN];
|
||||
}
|
||||
@ -137,7 +137,7 @@ class SmsController extends Controller {
|
||||
foreach($iContacts[$contactName] as $cnumber) {
|
||||
$messages = $messages + $this->smsMapper->getAllMessagesForPhoneNumber($this->userId, $cnumber, $lastDate);
|
||||
$msgCount += $this->smsMapper->countMessagesForPhoneNumber($this->userId, $cnumber);
|
||||
$phoneNumbers[] = FormatPhoneNumber::formatPhoneNumber($cnumber);
|
||||
$phoneNumbers[] = PhoneNumberFormatter::format($cnumber);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -149,7 +149,7 @@ class SmsController extends Controller {
|
||||
$msgCount += $this->smsMapper->countMessagesForPhoneNumber($this->userId, $cnumber);
|
||||
}
|
||||
}
|
||||
$phoneNumbers[] = FormatPhoneNumber::formatPhoneNumber($phoneNumber);
|
||||
$phoneNumbers[] = PhoneNumberFormatter::format($phoneNumber);
|
||||
}
|
||||
// Order by id (date)
|
||||
ksort($messages);
|
||||
|
@ -15,7 +15,7 @@ use \OCP\IDb;
|
||||
|
||||
use \OCP\AppFramework\Db\Mapper;
|
||||
use \OCA\OcSms\AppInfo\OcSmsApp;
|
||||
use \OCA\OcSms\AppInfo\FormatPhoneNumber;
|
||||
use \OCA\OcSms\Lib\PhoneNumberFormatter;
|
||||
|
||||
class SmsMapper extends Mapper {
|
||||
/*
|
||||
@ -97,7 +97,7 @@ class SmsMapper extends Mapper {
|
||||
$phoneList = array();
|
||||
while($row = $result->fetchRow()) {
|
||||
$pn = $row["sms_address"];
|
||||
$fmtPN = FormatPhoneNumber::formatPhoneNumber($pn);
|
||||
$fmtPN = PhoneNumberFormatter::format($pn);
|
||||
if (!isset($phoneList[$fmtPN])) {
|
||||
$phoneList[$fmtPN] = array();
|
||||
}
|
||||
@ -106,7 +106,7 @@ class SmsMapper extends Mapper {
|
||||
}
|
||||
$phoneList[$fmtPN][$pn] += 1;
|
||||
}
|
||||
$fpn = FormatPhoneNumber::formatPhoneNumber($phoneNumber);
|
||||
$fpn = PhoneNumberFormatter::format($phoneNumber);
|
||||
if(isset($phoneList[$fpn])){
|
||||
return $phoneList[$fpn];
|
||||
}
|
||||
|
@ -6,16 +6,15 @@
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Loic Blot <loic.blot@unix-experience.fr>
|
||||
* @contributor: stagprom <https://github.com/stagprom/>
|
||||
* @copyright Loic Blot 2014
|
||||
*/
|
||||
|
||||
namespace OCA\OcSms\AppInfo;
|
||||
namespace OCA\OcSms\Lib;
|
||||
|
||||
|
||||
class FormatPhoneNumber {
|
||||
|
||||
public static function formatPhoneNumber($pn) {
|
||||
|
||||
class PhoneNumberFormatter {
|
||||
public static function format ($pn) {
|
||||
$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
|
||||
@ -40,6 +39,7 @@ class FormatPhoneNumber {
|
||||
'#(.+)([\(\[\{]\d*[\)\]\}])#', // braces inside the number: +49 (0) 123 456789
|
||||
'#[^\d\+]#' // everything but digits and +
|
||||
);
|
||||
|
||||
$ignrpl = array( // replacements
|
||||
'',
|
||||
'$1',
|
||||
@ -47,20 +47,23 @@ class FormatPhoneNumber {
|
||||
);
|
||||
|
||||
/*
|
||||
ToDo : make local settings in web-page
|
||||
@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);
|
||||
if( preg_match('#^[\d\+\(\[\{].*#',$tpn)) { // start with digit, +, (, [ or {
|
||||
|
||||
if (preg_match('#^[\d\+\(\[\{].*#',$tpn)) { // start with digit, +, (, [ or {
|
||||
$fpn = preg_replace($ignrxp, $ignrpl, $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; // some SMS_adresses are strings
|
||||
}
|
||||
|
||||
return $ypn;
|
||||
}
|
||||
}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user