[pumpio] Replace share_header calls with BBCode::getShareOpeningTag
[friendica-addons.git/.git] / diaspora / Diaspora_Connection.php
index fae6432..a33bf60 100644 (file)
@@ -29,7 +29,7 @@ class Diaspora_Connection {
                        $this->setPassword($password);
                }
 
-               $this->cookiejar = tempnam(sys_get_temp_dir(), 'cookies');
+               $this->cookiejar = tempnam(get_temppath(), 'cookies');
                return $this;
        }
 
@@ -46,7 +46,11 @@ class Diaspora_Connection {
        public function setDiasporaID($id) {
                $parts = explode('@', $id);
                $this->user = $parts[0];
-               $this->host = $parts[1];
+               if (count($parts) > 1) {
+                       $this->host = $parts[1];
+               } else {
+                       $this->host = '';
+               }
        }
 
        public function getDiasporaID() {
@@ -69,7 +73,7 @@ class Diaspora_Connection {
                return ($this->tls) ? 'https' : 'http';
        }
 
-       private function doHttpRequest($url, $data = array(), $headers = array()) {
+       private function doHttpRequest($url, $data = [], $headers = []) {
                if (0 === strpos($url, '/')) {
                        $url = $this->getScheme() . '://' . $this->host . $url;
                }
@@ -122,21 +126,21 @@ class Diaspora_Connection {
                return $this->last_http_result;
        }
 
-       private function doHttpDelete($url, $data = array(), $headers = array()) {
+       private function doHttpDelete($url, $data = [], $headers = []) {
                $this->http_method = 'DELETE';
                $this->doHttpRequest($url, $data, $headers);
                $this->http_method = null; // reset for next request
        }
 
        private function parseAuthenticityToken($str) {
-               $m = array();
+               $m = [];
                preg_match('/<meta (?:name="csrf-token" content="(.*?)"|content="(.*?)" name="csrf-token")/', $str, $m);
                if (empty($m[1]) && !empty($m[2])) {
                        $token = $m[2];
                } elseif (!empty($m[1])) {
                        $token = $m[1];
                }
-               return (!empty($token)) ? $token : false;
+               return !empty($token) ? $token : false;
        }
 
        private function readJsonResponse($response) {
@@ -151,11 +155,11 @@ class Diaspora_Connection {
        public function logIn() {
                $this->doHttpRequest('/users/sign_in');
 
-               $params = array(
+               $params = [
                        'user[username]' => $this->user,
                        'user[password]' => $this->password,
                        'authenticity_token' => $this->csrf_token
-               );
+               ];
                $this->doHttpRequest('/users/sign_in', $params);
                $this->doHttpRequest('/stream');
                return (200 === $this->last_http_result->info['http_code']) ? true : false;
@@ -163,16 +167,16 @@ class Diaspora_Connection {
 
        public function getAspects() {
                $this->doHttpRequest('/bookmarklet');
-               $m = array();
+               $m = [];
                preg_match('/"aspects"\:(\[.+?\])/', $this->last_http_result->response, $m);
-               return (!empty($m[1])) ? json_decode($m[1]) : false;
+               return !empty($m[1]) ? json_decode($m[1]) : false;
        }
 
        public function getServices() {
                $this->doHttpRequest('/bookmarklet');
-               $m = array();
+               $m = [];
                preg_match('/"configured_services"\:(\[.+?\])/', $this->last_http_result->response, $m);
-               return (!empty($m[1])) ? json_decode($m[1]) : false;
+               return !empty($m[1]) ? json_decode($m[1]) : false;
        }
 
        public function getNotifications($notification_type = '', $show = '') {
@@ -196,24 +200,24 @@ class Diaspora_Connection {
                return $this->readJsonResponse($this->last_http_result->response);
        }
 
-       public function postStatusMessage($msg, $aspect_ids = 'all_aspects', $additional_data = array()) {
-               $data = array(
+       public function postStatusMessage($msg, $aspect_ids = 'all_aspects', $additional_data = []) {
+               $data = [
                        'aspect_ids' => $aspect_ids,
-                       'status_message' => array(
+                       'status_message' => [
                                'text' => $msg,
                                'provider_display_name' => $this->provider
-                       )
-               );
+                       ]
+               ];
 
                if (!empty($additional_data)) {
                        $data += $additional_data;
                }
 
-               $headers = array(
+               $headers = [
                        'Content-Type: application/json',
                        'Accept: application/json',
                        'X-CSRF-Token: ' . $this->csrf_token
-               );
+               ];
 
                $this->http_method = 'POST';
                $this->doHttpRequest('/status_messages', json_encode($data), $headers);
@@ -228,18 +232,18 @@ class Diaspora_Connection {
        }
 
        public function postPhoto($file) {
-               $params = array(
+               $params = [
                        'photo[pending]' => 'true',
                        'qqfile' => basename($file)
-               );
+               ];
                $query_string = '?' . http_build_query($params);
-               $headers = array(
+               $headers = [
                        'Accept: application/json',
                        'X-Requested-With: XMLHttpRequest',
                        'X-CSRF-Token: ' . $this->csrf_token,
                        'X-File-Name: ' . basename($file),
                        'Content-Type: application/octet-stream',
-               );
+               ];
                if ($size = @filesize($file)) {
                        $headers[] = "Content-Length: $size";
                }
@@ -249,14 +253,14 @@ class Diaspora_Connection {
        }
 
        public function deletePost($id) {
-               $headers = array('X-CSRF-Token: ' . $this->csrf_token);
-               $this->doHttpDelete("/posts/$id", array(), $headers);
+               $headers = ['X-CSRF-Token: ' . $this->csrf_token];
+               $this->doHttpDelete("/posts/$id", [], $headers);
                return (204 === $this->last_http_result->info['http_code']) ? true : false;
        }
 
        public function deleteComment($id) {
-               $headers = array('X-CSRF-Token: ' . $this->csrf_token);
-               $this->doHttpDelete("/comments/$id", array(), $headers);
+               $headers = ['X-CSRF-Token: ' . $this->csrf_token];
+               $this->doHttpDelete("/comments/$id", [], $headers);
                return (204 === $this->last_http_result->info['http_code']) ? true : false;
        }