X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=windowsphonepush%2Fwindowsphonepush.php;h=30c6cf60f399642b1e705d5d017a1b6a3400965f;hb=1acfd0b31c2c977e67f62a91a206762d2cbb658f;hp=38ab60b3bf7affc8243127b469440772a1f43a6a;hpb=7a376aeaadc0d7be73de1ffedf561bbf332e6372;p=friendica-addons.git diff --git a/windowsphonepush/windowsphonepush.php b/windowsphonepush/windowsphonepush.php index 38ab60b3..30c6cf60 100644 --- a/windowsphonepush/windowsphonepush.php +++ b/windowsphonepush/windowsphonepush.php @@ -29,10 +29,11 @@ use Friendica\App; use Friendica\Content\Text\BBCode; use Friendica\Content\Text\HTML; -use Friendica\Core\Addon; -use Friendica\Core\Authentication; +use Friendica\Core\Hook; use Friendica\Core\L10n; +use Friendica\Core\Logger; use Friendica\Core\PConfig; +use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\Model\Item; use Friendica\Model\User; @@ -43,17 +44,17 @@ function windowsphonepush_install() * The first is within cron - so the push notifications will be * sent every 10 minutes (or whatever is set in crontab). */ - Addon::registerHook('cron', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_cron'); + Hook::register('cron', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_cron'); /* Then we'll attach into the addon settings page, and also the * settings post hook so that we can create and update * user preferences. User shall be able to activate the addon and * define whether he allows pushing first characters of item text */ - Addon::registerHook('addon_settings', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings'); - Addon::registerHook('addon_settings_post', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings_post'); + Hook::register('addon_settings', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings'); + Hook::register('addon_settings_post', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings_post'); - logger("installed windowsphonepush"); + Logger::log("installed windowsphonepush"); } function windowsphonepush_uninstall() @@ -61,11 +62,11 @@ function windowsphonepush_uninstall() /* uninstall unregisters any hooks created with register_hook * during install. Don't delete data in table `pconfig`. */ - Addon::unregisterHook('cron', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_cron'); - Addon::unregisterHook('addon_settings', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings'); - Addon::unregisterHook('addon_settings_post', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings_post'); + Hook::unregister('cron', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_cron'); + Hook::unregister('addon_settings', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings'); + Hook::unregister('addon_settings_post', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings_post'); - logger("removed windowsphonepush"); + Logger::log("removed windowsphonepush"); } /* declare the windowsphonepush function so that /windowsphonepush url requests will land here */ @@ -81,7 +82,7 @@ function windowsphonepush_module() */ function windowsphonepush_settings_post($a, $post) { - if (!local_user() || (!x($_POST, 'windowsphonepush-submit'))) { + if (!local_user() || empty($_POST['windowsphonepush-submit'])) { return; } $enable = intval($_POST['windowsphonepush']); @@ -160,7 +161,7 @@ function windowsphonepush_cron() // 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."); + Logger::log("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) @@ -177,11 +178,11 @@ function windowsphonepush_cron() 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."); + Logger::log("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?"); + Logger::log("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) @@ -189,7 +190,7 @@ function windowsphonepush_cron() 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."); + Logger::log("ERROR: specified Device-URL '" . $device_url . "' didn't produced any response."); } // additionally user receives the text of the newest item (function checks against last successfully pushed item) @@ -306,7 +307,7 @@ function send_push($device_url, $headers, $msg) $subscriptionStatus = get_header_value($output, 'X-SubscriptionStatus'); if ($subscriptionStatus == "Expired") { PConfig::set(local_user(), 'windowsphonepush', 'device_url', ""); - logger("ERROR: the stored Device-URL " . $device_url . "returned an 'Expired' error, it has been deleted now."); + Logger::log("ERROR: the stored Device-URL " . $device_url . "returned an 'Expired' error, it has been deleted now."); } // the notification status shall be returned to windowsphonepush_cron (will @@ -337,19 +338,19 @@ function windowsphonepush_content(App $a) switch ($path2) { case "show_settings": windowsphonepush_showsettings($a); - killme(); + exit(); break; case "update_settings": $ret = windowsphonepush_updatesettings($a); header("Content-Type: application/json; charset=utf-8"); echo json_encode(['status' => $ret]); - killme(); + exit(); break; case "update_counterunseen": $ret = windowsphonepush_updatecounterunseen(); header("Content-Type: application/json; charset=utf-8"); echo json_encode(['status' => $ret]); - killme(); + exit(); break; default: echo "Fehler"; @@ -407,7 +408,7 @@ function windowsphonepush_updatesettings() // check if sent url is empty - don't save and send return code to app $device_url = $_POST['deviceurl']; if ($device_url == "") { - logger("ERROR: no valid Device-URL specified - client transferred '" . $device_url . "'"); + Logger::log("ERROR: no valid Device-URL specified - client transferred '" . $device_url . "'"); return "No valid Device-URL specified"; } @@ -422,13 +423,13 @@ function windowsphonepush_updatesettings() if (count($r)) { foreach ($r as $rr) { PConfig::set($rr['uid'], 'windowsphonepush', 'device_url', ''); - logger("WARN: the sent URL was already registered with user '" . $rr['uid'] . "'. Deleted for this user as we expect to be correct now for user '" . local_user() . "'."); + Logger::log("WARN: the sent URL was already registered with user '" . $rr['uid'] . "'. Deleted for this user as we expect to be correct now for user '" . local_user() . "'."); } } PConfig::set(local_user(), 'windowsphonepush', 'device_url', $device_url); // output the successfull update of the device URL to the logger for error analysis if necessary - logger("INFO: Device-URL for user '" . local_user() . "' has been updated with '" . $device_url . "'"); + Logger::log("INFO: Device-URL for user '" . local_user() . "' has been updated with '" . $device_url . "'"); return "Device-URL updated successfully!"; } @@ -455,7 +456,7 @@ function windowsphonepush_updatecounterunseen() function windowsphonepush_login(App $a) { if (!isset($_SERVER['PHP_AUTH_USER'])) { - logger('API_login: ' . print_r($_SERVER, true), LOGGER_DEBUG); + Logger::log('API_login: ' . print_r($_SERVER, true), Logger::DEBUG); header('WWW-Authenticate: Basic realm="Friendica"'); header('HTTP/1.0 401 Unauthorized'); die('This api requires login'); @@ -466,13 +467,13 @@ function windowsphonepush_login(App $a) if ($user_id) { $record = DBA::selectFirst('user', [], ['uid' => $user_id]); } else { - logger('API_login failure: ' . print_r($_SERVER, true), LOGGER_DEBUG); + Logger::log('API_login failure: ' . print_r($_SERVER, true), Logger::DEBUG); header('WWW-Authenticate: Basic realm="Friendica"'); header('HTTP/1.0 401 Unauthorized'); die('This api requires login'); } - Authentication::setAuthenticatedSessionForUser($record); + Session::setAuthenticatedForUser($a, $record); $_SESSION["allow_api"] = true; - Addon::callHooks('logged_in', $a->user); + Hook::callAll('logged_in', $a->user); }