]> git.mxchange.org Git - friendica-addons.git/blobdiff - windowsphonepush/windowsphonepush.php
Addon class
[friendica-addons.git] / windowsphonepush / windowsphonepush.php
index ffebd410c3f299071388586e1ae1b5c6c9f11b67..377d2cd4f1b1e76babe60d50f46eb8879cd5933f 100644 (file)
@@ -26,6 +26,7 @@
  *        count only unseen elements which are not type=activity (likes and dislikes not seen as new elements)
  */
 use Friendica\App;
+use Friendica\Core\Addon;
 use Friendica\Core\PConfig;
 use Friendica\Model\User;
 
@@ -35,15 +36,15 @@ function windowsphonepush_install()
         * The first is within cron - so the push notifications will be
         * sent every 10 minutes (or whatever is set in crontab).
         */
-       register_hook('cron', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_cron');
+       Addon::registerHook('cron', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_cron');
 
        /* Then we'll attach into the plugin settings page, and also the
         * settings post hook so that we can create and update
         * user preferences. User shall be able to activate the plugin and
         * define whether he allows pushing first characters of item text
         */
-       register_hook('plugin_settings', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings');
-       register_hook('plugin_settings_post', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings_post');
+       Addon::registerHook('plugin_settings', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings');
+       Addon::registerHook('plugin_settings_post', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings_post');
 
        logger("installed windowsphonepush");
 }
@@ -53,9 +54,9 @@ function windowsphonepush_uninstall()
        /* uninstall unregisters any hooks created with register_hook
         * during install. Don't delete data in table `pconfig`.
         */
-       unregister_hook('cron', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_cron');
-       unregister_hook('plugin_settings', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings');
-       unregister_hook('plugin_settings_post', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings_post');
+       Addon::unregisterHook('cron', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_cron');
+       Addon::unregisterHook('plugin_settings', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings');
+       Addon::unregisterHook('plugin_settings_post', 'addon/windowsphonepush/windowsphonepush.php', 'windowsphonepush_settings_post');
 
        logger("removed windowsphonepush");
 }
@@ -247,10 +248,10 @@ function send_tile_update($device_url, $image_url, $count, $title, $priority = 1
                "</wp:Tile> " .
                "</wp:Notification>";
 
-       $result = send_push($device_url, array(
+       $result = send_push($device_url, [
                'X-WindowsPhone-Target: token',
                'X-NotificationClass: ' . $priority,
-               ), $msg);
+               ], $msg);
        return $result;
 }
 
@@ -269,10 +270,10 @@ function send_toast($device_url, $title, $message, $priority = 2)
                "</wp:Toast>" .
                "</wp:Notification>";
 
-       $result = send_push($device_url, array(
+       $result = send_push($device_url, [
                'X-WindowsPhone-Target: toast',
                'X-NotificationClass: ' . $priority,
-               ), $msg);
+               ], $msg);
        return $result;
 }
 
@@ -284,11 +285,11 @@ function send_push($device_url, $headers, $msg)
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HEADER, true);
-       curl_setopt($ch, CURLOPT_HTTPHEADER, $headers + array(
+       curl_setopt($ch, CURLOPT_HTTPHEADER, $headers + [
                'Content-Type: text/xml',
                'charset=utf-8',
                'Accept: application/*',
-               )
+               ]
        );
        curl_setopt($ch, CURLOPT_POSTFIELDS, $msg);
 
@@ -336,13 +337,13 @@ function windowsphonepush_content(App $a)
                        case "update_settings":
                                $ret = windowsphonepush_updatesettings($a);
                                header("Content-Type: application/json; charset=utf-8");
-                               echo json_encode(array('status' => $ret));
+                               echo json_encode(['status' => $ret]);
                                killme();
                                break;
                        case "update_counterunseen":
                                $ret = windowsphonepush_updatecounterunseen();
                                header("Content-Type: application/json; charset=utf-8");
-                               echo json_encode(array('status' => $ret));
+                               echo json_encode(['status' => $ret]);
                                killme();
                                break;
                        default:
@@ -374,13 +375,13 @@ function windowsphonepush_showsettings()
        }
 
        header("Content-Type: application/json");
-       echo json_encode(array('uid' => local_user(),
+       echo json_encode(['uid' => local_user(),
                'enable' => $enable,
                'device_url' => $device_url,
                'senditemtext' => $senditemtext,
                'lastpushid' => $lastpushid,
                'counterunseen' => $counterunseen,
-               'addonversion' => $addonversion));
+               'addonversion' => $addonversion]);
 }
 
 /* update_settings is used to transfer the device_url from WP device to the Friendica server
@@ -455,19 +456,10 @@ function windowsphonepush_login(App $a)
                die('This api requires login');
        }
 
-       $user = $_SERVER['PHP_AUTH_USER'];
-       $encrypted = hash('whirlpool',trim($_SERVER['PHP_AUTH_PW']));
+       $user_id = User::authenticate($_SERVER['PHP_AUTH_USER'], trim($_SERVER['PHP_AUTH_PW']));
 
-       // check if user specified by app is available in the user table
-       $r = q("SELECT * FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' )
-           AND `password` = '%s' AND `blocked` = 0 AND `account_expired` = 0 AND `account_removed` = 0 AND `verified` = 1 LIMIT 1",
-           dbesc(trim($user)),
-           dbesc(trim($user)),
-           dbesc($encrypted)
-       );
-
-       if(count($r)){
-           $record = $r[0];
+       if ($user_id) {
+               $record = dba::selectFirst('user', [], ['uid' => $user_id]);
        } else {
                logger('API_login failure: ' . print_r($_SERVER, true), LOGGER_DEBUG);
                header('WWW-Authenticate: Basic realm="Friendica"');