X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=diaspora%2FDiaspora_Connection.php;h=a33bf608950f1ef8a4f9b6d546dc1d8d8103d595;hb=addf6b591166cd425c52da48dd42689bbed57dca;hp=fae6432e2636e6d88ead7cdde778e4e7edce04ad;hpb=e7558b1873a96913b30d8a6f20a3f10dabbe4432;p=friendica-addons.git diff --git a/diaspora/Diaspora_Connection.php b/diaspora/Diaspora_Connection.php index fae6432e..a33bf608 100644 --- a/diaspora/Diaspora_Connection.php +++ b/diaspora/Diaspora_Connection.php @@ -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('/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; }