mirror of
https://github.com/nerzhul/ocsms.git
synced 2025-06-07 16:06:15 +00:00
changed tabs and braces
modified: appinfo/formatphonenumber.php modified: appinfo/ocsmsapp.php modified: controller/smscontroller.php modified: db/smsmapper.php
This commit is contained in:
parent
405ee9af6f
commit
6816a92b89
@ -8,52 +8,50 @@
|
||||
* @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( // 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|\+)(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
|
||||
);
|
||||
|
||||
$ignrxp = array( // match non digits and +
|
||||
'#\(\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 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;
|
||||
public static function formatPhoneNumber($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
|
||||
'#^(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
|
||||
);
|
||||
|
||||
$ignrxp = array( // match non digits and +
|
||||
'#\(\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);
|
||||
if( preg_match('#^[\d\+].*#',$tpn)) { // start with digit or +
|
||||
$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; // some SMS_adresses are strings
|
||||
}
|
||||
return $ypn;
|
||||
}
|
||||
}
|
||||
|
@ -30,10 +30,10 @@ class OcSmsApp extends App {
|
||||
/*
|
||||
caching dosn´t work because on every call all will be reinstantiated
|
||||
*/
|
||||
private static $contacts; // dosn´t work
|
||||
|
||||
private static $contacts; // dosn´t work
|
||||
|
||||
private static $contactsInverted; // dosn´t work
|
||||
|
||||
|
||||
private $c;
|
||||
|
||||
public function __construct (array $urlParams=array()) {
|
||||
@ -42,7 +42,7 @@ class OcSmsApp extends App {
|
||||
$container = $this->getContainer();
|
||||
$this->c = $container;
|
||||
$app = $this;
|
||||
|
||||
|
||||
/**
|
||||
* Controllers
|
||||
*/
|
||||
@ -91,7 +91,7 @@ class OcSmsApp extends App {
|
||||
}
|
||||
return self::$contacts;
|
||||
}
|
||||
|
||||
|
||||
public function getInvertedContacts() {
|
||||
// Only load contacts if they aren't in the buffer
|
||||
// dosn´t work
|
||||
@ -100,7 +100,7 @@ class OcSmsApp extends App {
|
||||
}
|
||||
return self::$contactsInverted;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Partially importe this function from owncloud Chat app
|
||||
* https://github.com/owncloud/chat/blob/master/app/chat.php
|
||||
@ -108,12 +108,12 @@ class OcSmsApp extends App {
|
||||
private function loadContacts() {
|
||||
self::$contacts = array();
|
||||
self::$contactsInverted = array();
|
||||
|
||||
|
||||
$cm = $this->c['ContactsManager'];
|
||||
if ($cm == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$result = array();
|
||||
try {
|
||||
$result = $cm->search('',array('FN'));
|
||||
@ -146,8 +146,9 @@ class OcSmsApp extends App {
|
||||
$phoneNb = FormatPhoneNumber::formatPhoneNumber($rawPhone);
|
||||
self::$contacts[$phoneNb] = $contactName;
|
||||
// Inverted contacts
|
||||
if (!isset(self::$contactsInverted[$contactName]))
|
||||
if (!isset(self::$contactsInverted[$contactName])) {
|
||||
self::$contactsInverted[$contactName] = array();
|
||||
}
|
||||
array_push(self::$contactsInverted[$contactName], $phoneNb);
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ class SmsController extends Controller {
|
||||
private $userId;
|
||||
private $smsMapper;
|
||||
private $errorMsg;
|
||||
|
||||
|
||||
public function __construct ($appName, IRequest $request, $userId, SmsMapper $mapper, OcSmsApp $app){
|
||||
parent::__construct($appName, $request);
|
||||
$this->app = $app;
|
||||
@ -145,7 +145,7 @@ class SmsController extends Controller {
|
||||
$msgCount = $this->smsMapper->countMessagesForPhoneNumber($this->userId, $phoneNumber);
|
||||
if(isset($peerNumber[$fmtPN])) {
|
||||
foreach($peerNumber[$fmtPN] as $cnumber) {
|
||||
$messages = $messages + $this->smsMapper->getAllMessagesForPhoneNumber($this->userId, $cnumber, $lastDate);
|
||||
$messages = $messages + $this->smsMapper->getAllMessagesForPhoneNumber($this->userId, $cnumber, $lastDate);
|
||||
$msgCount += $this->smsMapper->countMessagesForPhoneNumber($this->userId, $cnumber);
|
||||
}
|
||||
}
|
||||
@ -153,7 +153,7 @@ class SmsController extends Controller {
|
||||
}
|
||||
// Order by id (date)
|
||||
ksort($messages);
|
||||
|
||||
|
||||
// Set the last read message for the conversation (all phone numbers)
|
||||
if (count($messages) > 0) {
|
||||
$maxDate = max(array_keys($messages));
|
||||
|
@ -100,7 +100,7 @@ class SmsMapper extends Mapper {
|
||||
$fmtPN = FormatPhoneNumber::formatPhoneNumber($pn);
|
||||
if (!isset($phoneList[$fmtPN])) {
|
||||
$phoneList[$fmtPN] = array();
|
||||
}
|
||||
}
|
||||
if(!isset($phoneList[$fmtPN][$pn])) {
|
||||
$phoneList[$fmtPN][$pn] = 0;
|
||||
}
|
||||
@ -110,12 +110,13 @@ class SmsMapper extends Mapper {
|
||||
if(isset($phoneList[$fpn])){
|
||||
return $phoneList[$fpn];
|
||||
}
|
||||
else
|
||||
else {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
public function getAllMessagesForPhoneNumber ($userId, $phoneNumber, $minDate = 0) {
|
||||
|
||||
|
||||
$phlst = $this->getAllPhoneNumbersForFPN ($userId,$phoneNumber);
|
||||
$messageList = array();
|
||||
$query = \OCP\DB::prepare('SELECT sms_date, sms_msg, sms_type FROM ' .
|
||||
|
Loading…
x
Reference in New Issue
Block a user