@@ -9,112 +9,112 @@ |
||
| 9 | 9 | use SKien\PNServer\PNPayload; |
| 10 | 10 | use SKien\PNServer\PNServer; |
| 11 | 11 | |
| 12 | - // check, if PHP version is sufficient and all required extensions are installed |
|
| 13 | - $bExit = false; |
|
| 14 | - if (version_compare(phpversion(), '7.1', '<')) {
|
|
| 15 | - trigger_error('At least PHP Version 7.1 is required (current Version is ' . phpversion() . ')!', E_USER_WARNING);
|
|
| 16 | - $bExit = true; |
|
| 17 | - } |
|
| 18 | - $aExt = array('curl', 'gmp', 'mbstring', 'openssl', 'bcmath');
|
|
| 19 | - foreach ($aExt as $strExt) {
|
|
| 20 | - if (!extension_loaded($strExt)) {
|
|
| 21 | - trigger_error('Extension ' . $strExt . ' must be installed!', E_USER_WARNING);
|
|
| 22 | - $bExit = true; |
|
| 23 | - } |
|
| 24 | - } |
|
| 25 | - if ($bExit) {
|
|
| 26 | - exit(); |
|
| 27 | - } |
|
| 12 | + // check, if PHP version is sufficient and all required extensions are installed |
|
| 13 | + $bExit = false; |
|
| 14 | + if (version_compare(phpversion(), '7.1', '<')) {
|
|
| 15 | + trigger_error('At least PHP Version 7.1 is required (current Version is ' . phpversion() . ')!', E_USER_WARNING);
|
|
| 16 | + $bExit = true; |
|
| 17 | + } |
|
| 18 | + $aExt = array('curl', 'gmp', 'mbstring', 'openssl', 'bcmath');
|
|
| 19 | + foreach ($aExt as $strExt) {
|
|
| 20 | + if (!extension_loaded($strExt)) {
|
|
| 21 | + trigger_error('Extension ' . $strExt . ' must be installed!', E_USER_WARNING);
|
|
| 22 | + $bExit = true; |
|
| 23 | + } |
|
| 24 | + } |
|
| 25 | + if ($bExit) {
|
|
| 26 | + exit(); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - // for test use SQLite database - will be cretaed at first instantiation |
|
| 30 | - $oDP = new PNDataProviderSQLite(); |
|
| 29 | + // for test use SQLite database - will be cretaed at first instantiation |
|
| 30 | + $oDP = new PNDataProviderSQLite(); |
|
| 31 | 31 | |
| 32 | - // or may use any MySQL database |
|
| 33 | - // $oDP = new PNDataProviderMySQL('localhost', 'username', 'password', 'db-name');
|
|
| 32 | + // or may use any MySQL database |
|
| 33 | + // $oDP = new PNDataProviderMySQL('localhost', 'username', 'password', 'db-name');
|
|
| 34 | 34 | |
| 35 | - if (!$oDP->isConnected()) {
|
|
| 36 | - echo $oDP->getError(); |
|
| 37 | - exit(); |
|
| 38 | - } |
|
| 35 | + if (!$oDP->isConnected()) {
|
|
| 36 | + echo $oDP->getError(); |
|
| 37 | + exit(); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - // just add expired (unsubscribed) subscription to demonstrate response of |
|
| 41 | - // push service and the auto-remove option |
|
| 42 | - if (!$oDP->saveSubscription( |
|
| 43 | - '{'
|
|
| 44 | - .' "endpoint": "https://fcm.googleapis.com/fcm/send/f8PIq7EL6xI:APA91bFgD2qA0Goo_6sWgWVDKclh5Sm1Gf1BtYZw3rePs_GHqmC9l2N92I4QhLQtPmyB18HYYseFHLhvMbpq-oGz2Jtt8AVExmNU9R3K9Z-Gaiq6rQxig1WT4ND_5PSXTjuth-GoGggt",' |
|
| 45 | - .' "expirationTime": "1589291569000",' |
|
| 46 | - .' "keys": {'
|
|
| 47 | - .' "p256dh": "BEQrfuNX-ZrXPf0Mm-IdVMO1LMpu5N3ifgcyeUD2nYwuUhRUDmn_wVOM3eQyYux5vW2B8-TyTYco4-bFKKR02IA",' |
|
| 48 | - .' "auth": "jOfywakW_srfHhMF-NiZ3Q"' |
|
| 49 | - .' }' |
|
| 50 | - .'}' |
|
| 51 | - )) {
|
|
| 52 | - echo $oDP->getError(); |
|
| 53 | - exit(); |
|
| 54 | - } |
|
| 40 | + // just add expired (unsubscribed) subscription to demonstrate response of |
|
| 41 | + // push service and the auto-remove option |
|
| 42 | + if (!$oDP->saveSubscription( |
|
| 43 | + '{'
|
|
| 44 | + .' "endpoint": "https://fcm.googleapis.com/fcm/send/f8PIq7EL6xI:APA91bFgD2qA0Goo_6sWgWVDKclh5Sm1Gf1BtYZw3rePs_GHqmC9l2N92I4QhLQtPmyB18HYYseFHLhvMbpq-oGz2Jtt8AVExmNU9R3K9Z-Gaiq6rQxig1WT4ND_5PSXTjuth-GoGggt",' |
|
| 45 | + .' "expirationTime": "1589291569000",' |
|
| 46 | + .' "keys": {'
|
|
| 47 | + .' "p256dh": "BEQrfuNX-ZrXPf0Mm-IdVMO1LMpu5N3ifgcyeUD2nYwuUhRUDmn_wVOM3eQyYux5vW2B8-TyTYco4-bFKKR02IA",' |
|
| 48 | + .' "auth": "jOfywakW_srfHhMF-NiZ3Q"' |
|
| 49 | + .' }' |
|
| 50 | + .'}' |
|
| 51 | + )) {
|
|
| 52 | + echo $oDP->getError(); |
|
| 53 | + exit(); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - echo 'Count of subscriptions: ' . $oDP->count() . '<br/><br/>' . PHP_EOL; |
|
| 57 | - if ($oDP->init()) {
|
|
| 58 | - while (($strJsonSub = $oDP->fetch()) !== false) {
|
|
| 59 | - echo 'UA: ' . $oDP->getColumn(PNDataProvider::COL_USERAGENT); |
|
| 60 | - echo ' (Lastupdated: ' . date('Y-m-d H:i:s', $oDP->getColumn(PNDataProvider::COL_LASTUPDATED)) . ')<br/>' . PHP_EOL;
|
|
| 61 | - $strPrintable = json_encode(json_decode($strJsonSub), JSON_PRETTY_PRINT); |
|
| 62 | - $strPrintable = str_replace("\n", '<br/>', $strPrintable);
|
|
| 63 | - $strPrintable = str_replace(" ", ' ', $strPrintable);
|
|
| 64 | - echo '<span style="font-size: 10pt; font-family: courier; overflow:scroll; white-space: nowrap">' . $strPrintable . '</span><br/><br/>' . PHP_EOL; |
|
| 65 | - } |
|
| 66 | - } else {
|
|
| 67 | - echo $oDP->getError(); |
|
| 68 | - exit(); |
|
| 69 | - } |
|
| 56 | + echo 'Count of subscriptions: ' . $oDP->count() . '<br/><br/>' . PHP_EOL; |
|
| 57 | + if ($oDP->init()) {
|
|
| 58 | + while (($strJsonSub = $oDP->fetch()) !== false) {
|
|
| 59 | + echo 'UA: ' . $oDP->getColumn(PNDataProvider::COL_USERAGENT); |
|
| 60 | + echo ' (Lastupdated: ' . date('Y-m-d H:i:s', $oDP->getColumn(PNDataProvider::COL_LASTUPDATED)) . ')<br/>' . PHP_EOL;
|
|
| 61 | + $strPrintable = json_encode(json_decode($strJsonSub), JSON_PRETTY_PRINT); |
|
| 62 | + $strPrintable = str_replace("\n", '<br/>', $strPrintable);
|
|
| 63 | + $strPrintable = str_replace(" ", ' ', $strPrintable);
|
|
| 64 | + echo '<span style="font-size: 10pt; font-family: courier; overflow:scroll; white-space: nowrap">' . $strPrintable . '</span><br/><br/>' . PHP_EOL; |
|
| 65 | + } |
|
| 66 | + } else {
|
|
| 67 | + echo $oDP->getError(); |
|
| 68 | + exit(); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - // the server to handle all |
|
| 72 | - $oServer = new PNServer($oDP); |
|
| 71 | + // the server to handle all |
|
| 72 | + $oServer = new PNServer($oDP); |
|
| 73 | 73 | |
| 74 | - // set the VAPID key |
|
| 75 | - /* |
|
| 74 | + // set the VAPID key |
|
| 75 | + /* |
|
| 76 | 76 | $oVapid = new PNVapid( |
| 77 | 77 | "mailto:[email protected]", |
| 78 | 78 | "the-generated-public-key", |
| 79 | 79 | "the-generated-private-key" |
| 80 | 80 | ); |
| 81 | 81 | */ |
| 82 | - $oVapid = new PNVapid( |
|
| 83 | - "mailto:[email protected]", |
|
| 84 | - "BDtOCcUUTYvuUzx9ktgYs3mB6tQCjFLNfOkuiaIi_2LNosLbHQY6P91eMzQ8opTDLK_PjJHsjMSiJ-MUOeSjV8E", |
|
| 85 | - "juLDCbPNbObvn-89_o0SEbnBZLMWxlVEjGypyxHEh2M" |
|
| 86 | - ); |
|
| 82 | + $oVapid = new PNVapid( |
|
| 83 | + "mailto:[email protected]", |
|
| 84 | + "BDtOCcUUTYvuUzx9ktgYs3mB6tQCjFLNfOkuiaIi_2LNosLbHQY6P91eMzQ8opTDLK_PjJHsjMSiJ-MUOeSjV8E", |
|
| 85 | + "juLDCbPNbObvn-89_o0SEbnBZLMWxlVEjGypyxHEh2M" |
|
| 86 | + ); |
|
| 87 | 87 | |
| 88 | - $oServer->setVapid($oVapid); |
|
| 88 | + $oServer->setVapid($oVapid); |
|
| 89 | 89 | |
| 90 | - // create payload |
|
| 91 | - // - we don't set a title - so service worker uses default |
|
| 92 | - // - URL to icon can be |
|
| 93 | - // * relative to the origin location of the service worker |
|
| 94 | - // * absolute from the homepage (begining with a '/') |
|
| 95 | - // * complete URL (beginning with https://) |
|
| 96 | - $oPayload = new PNPayload('', "...first text to display.", './elephpant.png');
|
|
| 97 | - // set tag to group the notifications but always show the popup |
|
| 98 | - $oPayload->setTag('news', true);
|
|
| 99 | - // and lead the user to thr page of your choice |
|
| 100 | - $oPayload->setURL('/where-to-go.php');
|
|
| 90 | + // create payload |
|
| 91 | + // - we don't set a title - so service worker uses default |
|
| 92 | + // - URL to icon can be |
|
| 93 | + // * relative to the origin location of the service worker |
|
| 94 | + // * absolute from the homepage (begining with a '/') |
|
| 95 | + // * complete URL (beginning with https://) |
|
| 96 | + $oPayload = new PNPayload('', "...first text to display.", './elephpant.png');
|
|
| 97 | + // set tag to group the notifications but always show the popup |
|
| 98 | + $oPayload->setTag('news', true);
|
|
| 99 | + // and lead the user to thr page of your choice |
|
| 100 | + $oPayload->setURL('/where-to-go.php');
|
|
| 101 | 101 | |
| 102 | - $oServer->setPayload($oPayload); |
|
| 102 | + $oServer->setPayload($oPayload); |
|
| 103 | 103 | |
| 104 | - // load subscriptions from database (incluing the expired one created above...) |
|
| 105 | - if (!$oServer->loadSubscriptions()) {
|
|
| 106 | - echo $oDP->getError(); |
|
| 107 | - exit(); |
|
| 108 | - } |
|
| 104 | + // load subscriptions from database (incluing the expired one created above...) |
|
| 105 | + if (!$oServer->loadSubscriptions()) {
|
|
| 106 | + echo $oDP->getError(); |
|
| 107 | + exit(); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - // ... and finally push ! |
|
| 111 | - if (!$oServer->push()) {
|
|
| 112 | - echo '<h2>' . $oServer->getError() . '</h2>' . PHP_EOL; |
|
| 113 | - } else {
|
|
| 114 | - $aLog = $oServer->getLog(); |
|
| 115 | - echo '<h2>Push - Log:</h2>' . PHP_EOL; |
|
| 116 | - foreach ($aLog as $strEndpoint => $aMsg ) {
|
|
| 117 | - echo '<h3>' . PNSubscription::getOrigin($strEndpoint) . '</h3>' . PHP_EOL; |
|
| 118 | - echo $aMsg['msg'] . '<br/>resonse code: ' . $aMsg['curl_response_code'] . ' (' . $aMsg['curl_response'] . ')';
|
|
| 119 | - } |
|
| 120 | - } |
|
| 110 | + // ... and finally push ! |
|
| 111 | + if (!$oServer->push()) {
|
|
| 112 | + echo '<h2>' . $oServer->getError() . '</h2>' . PHP_EOL; |
|
| 113 | + } else {
|
|
| 114 | + $aLog = $oServer->getLog(); |
|
| 115 | + echo '<h2>Push - Log:</h2>' . PHP_EOL; |
|
| 116 | + foreach ($aLog as $strEndpoint => $aMsg ) {
|
|
| 117 | + echo '<h3>' . PNSubscription::getOrigin($strEndpoint) . '</h3>' . PHP_EOL; |
|
| 118 | + echo $aMsg['msg'] . '<br/>resonse code: ' . $aMsg['curl_response_code'] . ' (' . $aMsg['curl_response'] . ')';
|
|
| 119 | + } |
|
| 120 | + } |
|
@@ -113,8 +113,8 @@ |
||
| 113 | 113 | } else {
|
| 114 | 114 | $aLog = $oServer->getLog(); |
| 115 | 115 | echo '<h2>Push - Log:</h2>' . PHP_EOL; |
| 116 | - foreach ($aLog as $strEndpoint => $aMsg ) {
|
|
| 116 | + foreach ($aLog as $strEndpoint => $aMsg) {
|
|
| 117 | 117 | echo '<h3>' . PNSubscription::getOrigin($strEndpoint) . '</h3>' . PHP_EOL; |
| 118 | - echo $aMsg['msg'] . '<br/>resonse code: ' . $aMsg['curl_response_code'] . ' (' . $aMsg['curl_response'] . ')';
|
|
| 118 | + echo $aMsg['msg'] . '<br/>resonse code: ' . $aMsg['curl_response_code'] . ' (' . $aMsg['curl_response'] . ')';
|
|
| 119 | 119 | } |
| 120 | 120 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * |
| 48 | 48 | * @param PNDataProvider $oDP |
| 49 | 49 | */ |
| 50 | - public function __construct(PNDataProvider $oDP=null) { |
|
| 50 | + public function __construct(PNDataProvider $oDP = null) { |
|
| 51 | 51 | if ($oDP->isConnected()) { |
| 52 | 52 | $this->oDP = $oDP; |
| 53 | 53 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * set VAPID subject and keys. |
| 70 | 70 | * @param PNVapid $oVapid |
| 71 | 71 | */ |
| 72 | - public function setVapid (PNVapid $oVapid) { |
|
| 72 | + public function setVapid(PNVapid $oVapid) { |
|
| 73 | 73 | $this->oVapid = $oVapid; |
| 74 | 74 | } |
| 75 | 75 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | * set payload used for all push notifications. |
| 78 | 78 | * @param mixed $payload string or PNPayload object |
| 79 | 79 | */ |
| 80 | - public function setPayload ($payload) { |
|
| 80 | + public function setPayload($payload) { |
|
| 81 | 81 | if (self::className($payload) == 'PNPayload') { |
| 82 | 82 | $this->strPayload = $payload->toJSON(); |
| 83 | 83 | } else { |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | * has only affect, if data loaded through DataProvider |
| 124 | 124 | * @param bool $bAutoRemove |
| 125 | 125 | */ |
| 126 | - public function setAutoRemove ($bAutoRemove=true) { |
|
| 126 | + public function setAutoRemove($bAutoRemove = true) { |
|
| 127 | 127 | $this->bAutoRemove = $bAutoRemove; |
| 128 | 128 | } |
| 129 | 129 | |
@@ -142,9 +142,9 @@ discard block |
||
| 142 | 142 | public function push() { |
| 143 | 143 | if (!$this->oVapid) { |
| 144 | 144 | $this->strError = 'no VAPID-keys set!'; |
| 145 | - } elseif(!$this->oVapid->isValid()) { |
|
| 145 | + } elseif (!$this->oVapid->isValid()) { |
|
| 146 | 146 | $this->strError = 'VAPID error: ' . $this->oVapid->getError(); |
| 147 | - } elseif(count($this->aSubscription) == 0) { |
|
| 147 | + } elseif (count($this->aSubscription) == 0) { |
|
| 148 | 148 | $this->strError = 'no valid Subscriptions set!'; |
| 149 | 149 | } else { |
| 150 | 150 | // create multi requests... |
@@ -119,18 +119,18 @@ |
||
| 119 | 119 | return $result; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - public static function modSub($minuend, $subtrahend, $modulus) |
|
| 123 | - { |
|
| 124 | - return self::mod(self::sub($minuend, $subtrahend), $modulus); |
|
| 125 | - } |
|
| 122 | + public static function modSub($minuend, $subtrahend, $modulus) |
|
| 123 | + { |
|
| 124 | + return self::mod(self::sub($minuend, $subtrahend), $modulus); |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - public static function modMul($multiplier, $muliplicand, $modulus) |
|
| 128 | - { |
|
| 129 | - return self::mod(self::mul($multiplier, $muliplicand), $modulus); |
|
| 130 | - } |
|
| 127 | + public static function modMul($multiplier, $muliplicand, $modulus) |
|
| 128 | + { |
|
| 129 | + return self::mod(self::mul($multiplier, $muliplicand), $modulus); |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - public static function modDiv($dividend, $divisor, $modulus) |
|
| 133 | - { |
|
| 134 | - return self::mul($dividend, self::inverseMod($divisor, $modulus), $modulus); |
|
| 135 | - } |
|
| 132 | + public static function modDiv($dividend, $divisor, $modulus) |
|
| 133 | + { |
|
| 134 | + return self::mul($dividend, self::inverseMod($divisor, $modulus), $modulus); |
|
| 135 | + } |
|
| 136 | 136 | } |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | if (!file_exists($this->strDBName)) { |
| 67 | 67 | $strDir = pathinfo($this->strDBName, PATHINFO_DIRNAME) == '' ? __DIR__ : pathinfo($this->strDBName, PATHINFO_DIRNAME); |
| 68 | 68 | if (!is_writable($strDir)) { |
| 69 | - $this->strLastError .= ' (no rights to write on directory ' . $strDir . ')'; |
|
| 69 | + $this->strLastError .= ' (no rights to write on directory ' . $strDir . ')'; |
|
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | } |
| 84 | 84 | } else if (!$this->tableExist()) { |
| 85 | 85 | if (strlen($this->strLastError) == 0) { |
| 86 | - $this->strLastError = 'database table ' . $this->strTableName . ' not exist!'; |
|
| 86 | + $this->strLastError = 'database table ' . $this->strTableName . ' not exist!'; |
|
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | 89 | return ($this->db && $this->bTableExist); |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | if ($this->isConnected()) { |
| 210 | 210 | $iCount = $this->db->querySingle("SELECT count(*) FROM " . $this->strTableName); |
| 211 | 211 | if ($iCount === false) { |
| 212 | - $this->strLastError = 'SQLite3: ' . $this->db->lastErrorMsg(); |
|
| 212 | + $this->strLastError = 'SQLite3: ' . $this->db->lastErrorMsg(); |
|
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | return $iCount; |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * @param string $strDBName name of DB file - if null, file 'pnsub.sqlite' is used and created if not exist |
| 43 | 43 | * @param string $strTableName tablename for the subscriptions - if null, 'tPNSubscription' is used and created if not exist |
| 44 | 44 | */ |
| 45 | - public function __construct($strDir=null, $strDBName=null, $strTableName=null) { |
|
| 45 | + public function __construct($strDir = null, $strDBName = null, $strTableName = null) { |
|
| 46 | 46 | $this->strTableName = isset($strTableName) ? $strTableName : 'tPNSubscription'; |
| 47 | 47 | $this->strDBName = isset($strDBName) ? $strDBName : 'pnsub.sqlite'; |
| 48 | 48 | $this->strLastError = ''; |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | $this->db = null; |
| 65 | 65 | $this->strLastError = $e->getMessage(); |
| 66 | 66 | if (!file_exists($this->strDBName)) { |
| 67 | - $strDir = pathinfo($this->strDBName, PATHINFO_DIRNAME) == '' ? __DIR__ : pathinfo($this->strDBName, PATHINFO_DIRNAME); |
|
| 67 | + $strDir = pathinfo($this->strDBName, PATHINFO_DIRNAME) == '' ? __DIR__ : pathinfo($this->strDBName, PATHINFO_DIRNAME); |
|
| 68 | 68 | if (!is_writable($strDir)) { |
| 69 | 69 | $this->strLastError .= ' (no rights to write on directory ' . $strDir . ')'; |
| 70 | 70 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | $strUserAgent = isset($oSubscription['userAgent']) ? $oSubscription['userAgent'] : 'unknown UserAgent'; |
| 104 | 104 | |
| 105 | 105 | $strSQL = "REPLACE INTO " . $this->strTableName . " ("; |
| 106 | - $strSQL .= self::COL_ENDPOINT; |
|
| 106 | + $strSQL .= self::COL_ENDPOINT; |
|
| 107 | 107 | $strSQL .= "," . self::COL_EXPIRES; |
| 108 | 108 | $strSQL .= "," . self::COL_SUBSCRIPTION; |
| 109 | 109 | $strSQL .= "," . self::COL_USERAGENT; |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * (non-PHPdoc) |
| 158 | 158 | * @see \lib\PNServer\PNDataProvider::init() |
| 159 | 159 | */ |
| 160 | - public function init($bAutoRemove=true) { |
|
| 160 | + public function init($bAutoRemove = true) { |
|
| 161 | 161 | $bSucceeded = false; |
| 162 | 162 | $this->dbres = false; |
| 163 | 163 | $this->row = null; |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * @param string $strDBName DB Name |
| 51 | 51 | * @param string $strTableName tablename for the subscriptions - if null, 'tPNSubscription' is used and created if not exist |
| 52 | 52 | */ |
| 53 | - public function __construct($strDBHost, $strDBUser, $strDBPwd, $strDBName, $strTableName=null) { |
|
| 53 | + public function __construct($strDBHost, $strDBUser, $strDBPwd, $strDBName, $strTableName = null) { |
|
| 54 | 54 | $this->strDBHost = $strDBHost; |
| 55 | 55 | $this->strDBUser = $strDBUser; |
| 56 | 56 | $this->strDBPwd = $strDBPwd; |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | $strUserAgent = isset($oSubscription['userAgent']) ? $oSubscription['userAgent'] : 'unknown UserAgent'; |
| 99 | 99 | |
| 100 | 100 | $strSQL = "INSERT INTO " . $this->strTableName . " ("; |
| 101 | - $strSQL .= self::COL_ENDPOINT; |
|
| 101 | + $strSQL .= self::COL_ENDPOINT; |
|
| 102 | 102 | $strSQL .= "," . self::COL_EXPIRES; |
| 103 | 103 | $strSQL .= "," . self::COL_SUBSCRIPTION; |
| 104 | 104 | $strSQL .= "," . self::COL_USERAGENT; |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | $strSQL .= ",'" . $strJSON . "'"; |
| 109 | 109 | $strSQL .= ",'" . $strUserAgent . "'"; |
| 110 | 110 | $strSQL .= ") "; |
| 111 | - $strSQL .= "ON DUPLICATE KEY UPDATE "; // in case of UPDATE UA couldn't have been changed - endpoint is the UNIQUE key! |
|
| 111 | + $strSQL .= "ON DUPLICATE KEY UPDATE "; // in case of UPDATE UA couldn't have been changed - endpoint is the UNIQUE key! |
|
| 112 | 112 | $strSQL .= " expires = " . $tsExpires; |
| 113 | 113 | $strSQL .= ",subscription = '" . $strJSON . "'"; |
| 114 | 114 | $strSQL .= ";"; |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | * (non-PHPdoc) |
| 147 | 147 | * @see \lib\PNServer\PNDataProvider::init() |
| 148 | 148 | */ |
| 149 | - public function init($bAutoRemove=true) { |
|
| 149 | + public function init($bAutoRemove = true) { |
|
| 150 | 150 | $bSucceeded = false; |
| 151 | 151 | $this->dbres = false; |
| 152 | 152 | $this->row = null; |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | } |
| 172 | 172 | if ($bSucceeded) { |
| 173 | 173 | $strSQL = "SELECT "; |
| 174 | - $strSQL .= self::COL_ID; |
|
| 174 | + $strSQL .= self::COL_ID; |
|
| 175 | 175 | $strSQL .= "," . self::COL_ENDPOINT; |
| 176 | 176 | $strSQL .= ",UNIX_TIMESTAMP(" . self::COL_EXPIRES . ") AS " . self::COL_EXPIRES; |
| 177 | 177 | $strSQL .= "," . self::COL_SUBSCRIPTION; |
@@ -64,9 +64,9 @@ discard block |
||
| 64 | 64 | $der = self::p256PrivateKey($strPrivateKey); |
| 65 | 65 | $der .= $strPublicKey; |
| 66 | 66 | |
| 67 | - $pem = '-----BEGIN EC PRIVATE KEY-----'.PHP_EOL; |
|
| 67 | + $pem = '-----BEGIN EC PRIVATE KEY-----' . PHP_EOL; |
|
| 68 | 68 | $pem .= chunk_split(base64_encode($der), 64, PHP_EOL); |
| 69 | - $pem .= '-----END EC PRIVATE KEY-----'.PHP_EOL; |
|
| 69 | + $pem .= '-----END EC PRIVATE KEY-----' . PHP_EOL; |
|
| 70 | 70 | |
| 71 | 71 | return $pem; |
| 72 | 72 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | if ($R !== false && $S !== false) { |
| 124 | - $sig = \pack('H*', $R.$S); |
|
| 124 | + $sig = \pack('H*', $R . $S); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | return $sig; |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @param number $timeExpiration |
| 38 | 38 | * @param string $strEncoding |
| 39 | 39 | */ |
| 40 | - public function __construct($strEndpoint, $strPublicKey, $strAuth, $timeExpiration=0, $strEncoding='aesgcm') { |
|
| 40 | + public function __construct($strEndpoint, $strPublicKey, $strAuth, $timeExpiration = 0, $strEncoding = 'aesgcm') { |
|
| 41 | 41 | $this->strEndpoint = $strEndpoint; |
| 42 | 42 | $this->strPublicKey = $strPublicKey; |
| 43 | 43 | $this->strAuth = $strAuth; |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | isset($this->strEndpoint) && strlen($this->strEndpoint) > 0 && |
| 86 | 86 | isset($this->strPublicKey) && strlen($this->strPublicKey) > 0 && |
| 87 | 87 | isset($this->strAuth) && strlen($this->strAuth) > 0 && |
| 88 | - ($this->strEncoding == 'aesgcm'|| $this->strEncoding == 'aes128gcm') |
|
| 88 | + ($this->strEncoding == 'aesgcm' || $this->strEncoding == 'aes128gcm') |
|
| 89 | 89 | ); |
| 90 | 90 | } |
| 91 | 91 | return $bValid; |
@@ -94,63 +94,63 @@ discard block |
||
| 94 | 94 | /** |
| 95 | 95 | * @return string |
| 96 | 96 | */ |
| 97 | - public function getEndpoint () { |
|
| 97 | + public function getEndpoint() { |
|
| 98 | 98 | return $this->strEndpoint; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
| 102 | 102 | * @return string |
| 103 | 103 | */ |
| 104 | - public function getPublicKey () { |
|
| 104 | + public function getPublicKey() { |
|
| 105 | 105 | return $this->strPublicKey; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
| 109 | 109 | * @return string |
| 110 | 110 | */ |
| 111 | - public function getAuth () { |
|
| 111 | + public function getAuth() { |
|
| 112 | 112 | return $this->strAuth; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
| 116 | 116 | * @return string |
| 117 | 117 | */ |
| 118 | - public function getEncoding () { |
|
| 118 | + public function getEncoding() { |
|
| 119 | 119 | return $this->strEncoding; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
| 123 | 123 | * @param string $strEndpoint |
| 124 | 124 | */ |
| 125 | - public function setEndpoint ($strEndpoint) { |
|
| 125 | + public function setEndpoint($strEndpoint) { |
|
| 126 | 126 | $this->strEndpoint = $strEndpoint; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
| 130 | 130 | * @param string $strPublicKey |
| 131 | 131 | */ |
| 132 | - public function setPublicKey ($strPublicKey) { |
|
| 132 | + public function setPublicKey($strPublicKey) { |
|
| 133 | 133 | $this->strPublicKey = $strPublicKey; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
| 137 | 137 | * @param string $strAuth |
| 138 | 138 | */ |
| 139 | - public function setAuth ($strAuth) { |
|
| 139 | + public function setAuth($strAuth) { |
|
| 140 | 140 | $this->strAuth = $strAuth; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
| 144 | 144 | * @param number $timeExpiration |
| 145 | 145 | */ |
| 146 | - public function setExpiration ($timeExpiration) { |
|
| 146 | + public function setExpiration($timeExpiration) { |
|
| 147 | 147 | $this->timeExpiration = $timeExpiration; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
| 151 | 151 | * @param string $strEncoding |
| 152 | 152 | */ |
| 153 | - public function setEncoding ($strEncoding) { |
|
| 153 | + public function setEncoding($strEncoding) { |
|
| 154 | 154 | $this->strEncoding = $strEncoding; |
| 155 | 155 | } |
| 156 | 156 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * @param string $strText A string representing an extra content to display within the notification. |
| 41 | 41 | * @param string $strIcon containing the URL of an image to be used as an icon by the notification. |
| 42 | 42 | */ |
| 43 | - public function __construct($strTitle, $strText=null, $strIcon=null) { |
|
| 43 | + public function __construct($strTitle, $strText = null, $strIcon = null) { |
|
| 44 | 44 | $this->aPayload = array( |
| 45 | 45 | 'title' => $strTitle, |
| 46 | 46 | 'opt' => array( |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | public function setURL($strURL) { |
| 58 | 58 | if (is_array($this->aPayload) && isset($this->aPayload['opt']) && is_array($this->aPayload['opt'])) { |
| 59 | - if (!isset($this->aPayload['opt']['data']) || !is_array($this->aPayload['opt']['data'] )) { |
|
| 59 | + if (!isset($this->aPayload['opt']['data']) || !is_array($this->aPayload['opt']['data'])) { |
|
| 60 | 60 | $this->aPayload['opt']['data'] = array(); |
| 61 | 61 | } |
| 62 | 62 | $this->aPayload['opt']['data']['url'] = $strURL; |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | * @param string $strTag |
| 73 | 73 | * @param bool $bReNotify |
| 74 | 74 | */ |
| 75 | - public function setTag($strTag, $bReNotify=false) { |
|
| 75 | + public function setTag($strTag, $bReNotify = false) { |
|
| 76 | 76 | if (is_array($this->aPayload) && isset($this->aPayload['opt']) && is_array($this->aPayload['opt'])) { |
| 77 | 77 | $this->aPayload['opt']['tag'] = $strTag; |
| 78 | 78 | $this->aPayload['opt']['renotify'] = $bReNotify; |
@@ -119,9 +119,9 @@ discard block |
||
| 119 | 119 | * @param string $strIcon containing the URL of an icon to display with the action. |
| 120 | 120 | * @param string $strCustom custom info - not part of the showNotification()- Options! |
| 121 | 121 | */ |
| 122 | - public function addAction($strAction, $strTitle, $strIcon=null, $strCustom='') { |
|
| 122 | + public function addAction($strAction, $strTitle, $strIcon = null, $strCustom = '') { |
|
| 123 | 123 | if (is_array($this->aPayload) && isset($this->aPayload['opt']) && is_array($this->aPayload['opt'])) { |
| 124 | - if (!isset($this->aPayload['opt']['actions']) || !is_array($this->aPayload['opt']['actions'] )) { |
|
| 124 | + if (!isset($this->aPayload['opt']['actions']) || !is_array($this->aPayload['opt']['actions'])) { |
|
| 125 | 125 | $this->aPayload['opt']['actions'] = array(); |
| 126 | 126 | } |
| 127 | 127 | $this->aPayload['opt']['actions'][] = array('action' => $strAction, 'title' => $strTitle, 'icon' => $strIcon, 'custom' => $strCustom); |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | * |
| 160 | 160 | * @param bool $bSet |
| 161 | 161 | */ |
| 162 | - public function requireInteraction($bSet=true) { |
|
| 162 | + public function requireInteraction($bSet = true) { |
|
| 163 | 163 | if (is_array($this->aPayload) && isset($this->aPayload['opt']) && is_array($this->aPayload['opt'])) { |
| 164 | 164 | $this->aPayload['opt']['requireInteraction'] = $bSet; |
| 165 | 165 | } |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | * If this 'mute' function is activated, a previously set vibration is reset to prevent a TypeError exception. |
| 171 | 171 | * @param bool $bSet |
| 172 | 172 | */ |
| 173 | - public function setSilent($bSet=true) { |
|
| 173 | + public function setSilent($bSet = true) { |
|
| 174 | 174 | if (is_array($this->aPayload) && isset($this->aPayload['opt']) && is_array($this->aPayload['opt'])) { |
| 175 | 175 | $this->aPayload['opt']['silent'] = $bSet; |
| 176 | 176 | if ($bSet && isset($this->aPayload['opt']['vibrate'])) { |
@@ -57,7 +57,7 @@ |
||
| 57 | 57 | * @param bool $bAutoRemove automatic remove of expired subscriptions |
| 58 | 58 | * @return bool true on success |
| 59 | 59 | */ |
| 60 | - public function init($bAutoRemove=true); |
|
| 60 | + public function init($bAutoRemove = true); |
|
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | 63 | * get count of subscriptions. |