- $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'windowsphonepush' AND `k` = 'enable' AND `v` = 1");
- if (count($r)) {
- foreach ($r as $rr) {
- // load stored information for the user-id of the current loop
- $device_url = PConfig::get($rr['uid'], 'windowsphonepush', 'device_url');
- $lastpushid = PConfig::get($rr['uid'], 'windowsphonepush', 'lastpushid');
-
- // pushing only possible if device_url (the URI on Microsoft server) is available or not "NA" (which will be sent
- // by app if user has switched the server setting in app - sending blank not possible as this would return an update error)
- if (( $device_url == "" ) || ( $device_url == "NA" )) {
- // no Device-URL for the user availabe, but addon is enabled --> write info to Logger
- logger("WARN: windowsphonepush is enable for user " . $rr['uid'] . ", but no Device-URL is specified for the user.");
- } else {
- // retrieve the number of unseen items and the id of the latest one (if there are more than
- // one new entries since last poller run, only the latest one will be pushed)
- $count = q("SELECT count(`id`) as count, max(`id`) as max FROM `item` WHERE `unseen` = 1 AND `type` <> 'activity' AND `uid` = %d", intval($rr['uid']));
-
- // send number of unseen items to the device (the number will be displayed on Start screen until
- // App will be started by user) - this update will be sent every 10 minutes to update the number to 0 if
- // user has loaded the timeline through app or website
- $res_tile = send_tile_update($device_url, "", $count[0]['count'], "");
- switch (trim($res_tile)) {
- case "Received":
- // ok, count has been pushed, let's save it in personal settings
- PConfig::set($rr['uid'], 'windowsphonepush', 'counterunseen', $count[0]['count']);
- break;
- case "QueueFull":
- // maximum of 30 messages reached, server rejects any further push notification until device reconnects
- logger("INFO: Device-URL '" . $device_url . "' returns a QueueFull.");
- break;
- case "Suppressed":
- // notification received and dropped as something in app was not enabled
- logger("WARN. Device-URL '" . $device_url . "' returns a Suppressed. Unexpected error in Mobile App?");
- break;
- case "Dropped":
- // mostly combines with Expired, in that case Device-URL will be deleted from pconfig (function send_push)
- break;
- default:
- // error, mostly called by "" which means that the url (not "" which has been checked)
- // didn't not received Microsoft Notification Server -> wrong url
- logger("ERROR: specified Device-URL '" . $device_url . "' didn't produced any response.");
- }
+ $pconfigs = DBA::selectToArray('pconfig', ['uid'], ['cat' => 'windowsphonepush', 'k' => 'enable', 'v' => true]);
+ foreach ($pconfigs as $rr) {
+ // load stored information for the user-id of the current loop
+ $device_url = DI::pConfig()->get($rr['uid'], 'windowsphonepush', 'device_url');
+ $lastpushid = DI::pConfig()->get($rr['uid'], 'windowsphonepush', 'lastpushid');
+
+ // pushing only possible if device_url (the URI on Microsoft server) is available or not "NA" (which will be sent
+ // by app if user has switched the server setting in app - sending blank not possible as this would return an update error)
+ if (( $device_url == "" ) || ( $device_url == "NA" )) {
+ // no Device-URL for the user availabe, but addon is enabled --> write info to Logger
+ Logger::notice("WARN: windowsphonepush is enable for user " . $rr['uid'] . ", but no Device-URL is specified for the user.");
+ } else {
+ // retrieve the number of unseen items and the id of the latest one (if there are more than
+ // one new entries since last poller run, only the latest one will be pushed)
+ $count = DBA::fetchFirst("SELECT count(`id`) AS count, max(`id`) AS max FROM `post-view` WHERE `unseen` AND `type` != ? AND `uid` = ?", 'activity', $rr['uid']);
+
+ // send number of unseen items to the device (the number will be displayed on Start screen until
+ // App will be started by user) - this update will be sent every 10 minutes to update the number to 0 if
+ // user has loaded the timeline through app or website
+ $res_tile = send_tile_update($device_url, "", $count['count'], "");
+ switch (trim($res_tile)) {
+ case "Received":
+ // ok, count has been pushed, let's save it in personal settings
+ DI::pConfig()->set($rr['uid'], 'windowsphonepush', 'counterunseen', $count['count']);
+ break;
+ case "QueueFull":
+ // maximum of 30 messages reached, server rejects any further push notification until device reconnects
+ Logger::notice("INFO: Device-URL '" . $device_url . "' returns a QueueFull.");
+ break;
+ case "Suppressed":
+ // notification received and dropped as something in app was not enabled
+ Logger::notice("WARN. Device-URL '" . $device_url . "' returns a Suppressed. Unexpected error in Mobile App?");
+ break;
+ case "Dropped":
+ // mostly combines with Expired, in that case Device-URL will be deleted from pconfig (function send_push)
+ break;
+ default:
+ // error, mostly called by "" which means that the url (not "" which has been checked)
+ // didn't not received Microsoft Notification Server -> wrong url
+ Logger::notice("ERROR: specified Device-URL '" . $device_url . "' didn't produced any response.");
+ }