]> git.mxchange.org Git - friendica-addons.git/blobdiff - windowsphonepush/windowsphonepush.php
Merge pull request #488 from MrPetovan/task/fix-scrutinizer-issues
[friendica-addons.git] / windowsphonepush / windowsphonepush.php
index ffebd410c3f299071388586e1ae1b5c6c9f11b67..66b23a7ccbc4ec4acce5eb6049900369c0da5ad1 100644 (file)
@@ -247,10 +247,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 +269,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 +284,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 +336,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 +374,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 +455,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"');