mirror of
https://github.com/nextcloud/ocsms.git
synced 2026-10-13 22:51:36 +00:00
new file: appinfo/formatphonenumber.php
modified: appinfo/ocsmsapp.php modified: controller/smscontroller.php modified: db/smsmapper.php A lot of changes in Code dealing with phonenumbers
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* ownCloud - ocsms
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Loic Blot <loic.blot@unix-experience.fr>
|
||||
* @copyright Loic Blot 2014
|
||||
*/
|
||||
|
||||
namespace OCA\OcSms\AppInfo;
|
||||
|
||||
class FormatPhoneNumber {
|
||||
|
||||
public static function formatPhoneNumber($pn) {
|
||||
$ipnrxp = array(
|
||||
'#^(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|\+)(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|\+)(6[7|8|9]\d)#', // +6(7|8|9)x
|
||||
'#^(00|\+)(6[0|1|2|3|4|5|6])#', // +6x
|
||||
'#^(00|\+)(7)#', // +7
|
||||
'#^(00|\+)(8[5|7|8|9]\d)#', // +8(5|7|8|9)x
|
||||
'#^(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(
|
||||
'#\(\d*\)|[^\d\+]#',
|
||||
);
|
||||
|
||||
$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); //
|
||||
} else
|
||||
$ypn = $tpn;
|
||||
return $ypn;
|
||||
}
|
||||
}
|
||||
+8
-66
@@ -9,6 +9,7 @@
|
||||
* @copyright Loic Blot 2014
|
||||
*/
|
||||
|
||||
|
||||
namespace OCA\OcSms\AppInfo;
|
||||
|
||||
|
||||
@@ -19,15 +20,16 @@ use \OCA\OcSms\Controller\SmsController;
|
||||
use \OCA\OcSms\Db\Sms;
|
||||
use \OCA\OcSms\Db\SmsMapper;
|
||||
|
||||
use \OCA\OcSms\AppInfo\FormatPhoneNumber;
|
||||
|
||||
class OcSmsApp extends App {
|
||||
|
||||
/**
|
||||
* @var array used to cache the parsed contacts for every request
|
||||
*/
|
||||
private static $contacts;
|
||||
private static $contacts; // dosn´t work
|
||||
|
||||
private static $contactsInverted;
|
||||
private static $contactsInverted; // dosn´t work
|
||||
|
||||
private $c;
|
||||
|
||||
@@ -80,19 +82,19 @@ class OcSmsApp extends App {
|
||||
|
||||
public function getContacts() {
|
||||
// Only load contacts if they aren't in the buffer
|
||||
// dosn´t work
|
||||
if(count(self::$contacts) == 0) {
|
||||
$this->loadContacts();
|
||||
}
|
||||
|
||||
return self::$contacts;
|
||||
}
|
||||
|
||||
public function getInvertedContacts() {
|
||||
// Only load contacts if they aren't in the buffer
|
||||
// dosn´t work
|
||||
if(count(self::$contactsInverted) == 0) {
|
||||
$this->loadContacts();
|
||||
}
|
||||
|
||||
return self::$contactsInverted;
|
||||
}
|
||||
|
||||
@@ -134,73 +136,13 @@ class OcSmsApp extends App {
|
||||
}
|
||||
|
||||
private function pushPhoneNumberToCache($rawPhone, $contactName) {
|
||||
// We try to add many combinaisons
|
||||
$phoneNb = preg_replace("#[ ]#", "/", $rawPhone);
|
||||
|
||||
/*
|
||||
* At this point, spaces are slashes.
|
||||
*/
|
||||
|
||||
// Spaces removed
|
||||
$phoneNbNoSpaces = preg_replace("#[/]#", "", $phoneNb);
|
||||
// Parenthesis removed
|
||||
$phoneNbNoParenthesis = preg_replace("#[(]|[)]#", "", $phoneNb);
|
||||
// Dashes removed
|
||||
$phoneNbNoDashes = preg_replace("#[-]#", "", $phoneNb);
|
||||
|
||||
// Spaces and parenthesis
|
||||
$phoneNbNoSpacesParenthesis = preg_replace("#[/]|[(]|[)]#", "", $phoneNb);
|
||||
// Spaces and dashes
|
||||
$phoneNbNoSpacesDashes = preg_replace("#[/]|[-]#", "", $phoneNb);
|
||||
// parenthesis and dashes
|
||||
$phoneNbNoDashesParenthesis = preg_replace("#[-]|[(]|[)]#", "", $phoneNb);
|
||||
|
||||
// Nothing
|
||||
$phoneNbNothing = preg_replace("#[/]|[(]|[)]|[-]#", "", $phoneNb);
|
||||
|
||||
// Contacts
|
||||
$phoneNb = FormatPhoneNumber::formatPhoneNumber($rawPhone);
|
||||
self::$contacts[$phoneNb] = $contactName;
|
||||
self::$contacts[$phoneNbNoSpaces] = $contactName;
|
||||
self::$contacts[$phoneNbNoParenthesis] = $contactName;
|
||||
self::$contacts[$phoneNbNoDashes] = $contactName;
|
||||
self::$contacts[$phoneNbNoSpacesParenthesis] = $contactName;
|
||||
self::$contacts[$phoneNbNoSpacesDashes] = $contactName;
|
||||
self::$contacts[$phoneNbNoDashesParenthesis] = $contactName;
|
||||
self::$contacts[$phoneNbNothing] = $contactName;
|
||||
|
||||
// Inverted contacts
|
||||
if (!isset(self::$contactsInverted[$contactName])) {
|
||||
if (!isset(self::$contactsInverted[$contactName]))
|
||||
self::$contactsInverted[$contactName] = array();
|
||||
}
|
||||
|
||||
array_push(self::$contactsInverted[$contactName], $phoneNb);
|
||||
|
||||
if (!in_array($phoneNbNoSpaces, self::$contactsInverted[$contactName])) {
|
||||
array_push(self::$contactsInverted[$contactName], $phoneNbNoSpaces);
|
||||
}
|
||||
|
||||
if (!in_array($phoneNbNoParenthesis, self::$contactsInverted[$contactName])) {
|
||||
array_push(self::$contactsInverted[$contactName], $phoneNbNoParenthesis);
|
||||
}
|
||||
|
||||
if (!in_array($phoneNbNoDashes, self::$contactsInverted[$contactName])) {
|
||||
array_push(self::$contactsInverted[$contactName], $phoneNbNoDashes);
|
||||
}
|
||||
|
||||
if (!in_array($phoneNbNoSpacesParenthesis, self::$contactsInverted[$contactName])) {
|
||||
array_push(self::$contactsInverted[$contactName], $phoneNbNoSpacesParenthesis);
|
||||
}
|
||||
|
||||
if (!in_array($phoneNbNoSpacesDashes, self::$contactsInverted[$contactName])) {
|
||||
array_push(self::$contactsInverted[$contactName], $phoneNbNoSpacesDashes);
|
||||
}
|
||||
|
||||
if (!in_array($phoneNbNoDashesParenthesis, self::$contactsInverted[$contactName])) {
|
||||
array_push(self::$contactsInverted[$contactName], $phoneNbNoDashesParenthesis);
|
||||
}
|
||||
|
||||
if (!in_array($phoneNbNothing, self::$contactsInverted[$contactName])) {
|
||||
array_push(self::$contactsInverted[$contactName], $phoneNbNothing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user