X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=include%2Fapi.php;h=8291d189269bdbfe26056df68c4a53632fe0e9b3;hb=d3722c945b99955b33a813a7369ee4581a784f8a;hp=62c69767f343bd36f0e126e3f32d42f8d58faacc;hpb=72c198990e3d6dd23628ad15600b2089882e03c4;p=friendica.git diff --git a/include/api.php b/include/api.php index 62c69767f3..8291d18926 100644 --- a/include/api.php +++ b/include/api.php @@ -186,23 +186,6 @@ function api_register_func($path, $func, $auth = false, $method = API_METHOD_ANY */ function api_login(App $a) { - $oauth1 = new FKOAuth1(); - // login with oauth - try { - $request = OAuthRequest::from_request(); - list($consumer, $token) = $oauth1->verify_request($request); - if (!is_null($token)) { - $oauth1->loginUser($token->uid); - Session::set('allow_api', true); - return; - } - echo __FILE__.__LINE__.__FUNCTION__ . "
"; - var_dump($consumer, $token); - die(); - } catch (Exception $e) { - Logger::warning(API_LOG_PREFIX . 'error', ['module' => 'api', 'action' => 'login', 'exception' => $e->getMessage()]); - } - // workaround for HTTP-auth in CGI mode if (!empty($_SERVER['REDIRECT_REMOTE_USER'])) { $userpass = base64_decode(substr($_SERVER["REDIRECT_REMOTE_USER"], 6)); @@ -214,6 +197,24 @@ function api_login(App $a) } if (empty($_SERVER['PHP_AUTH_USER'])) { + // Try OAuth when no user is provided + $oauth1 = new FKOAuth1(); + // login with oauth + try { + $request = OAuthRequest::from_request(); + list($consumer, $token) = $oauth1->verify_request($request); + if (!is_null($token)) { + $oauth1->loginUser($token->uid); + Session::set('allow_api', true); + return; + } + echo __FILE__.__LINE__.__FUNCTION__ . ""; + var_dump($consumer, $token); + die(); + } catch (Exception $e) { + Logger::warning(API_LOG_PREFIX . 'OAuth error', ['module' => 'api', 'action' => 'login', 'exception' => $e->getMessage()]); + } + Logger::debug(API_LOG_PREFIX . 'failed', ['module' => 'api', 'action' => 'login', 'parameters' => $_SERVER]); header('WWW-Authenticate: Basic realm="Friendica"'); throw new UnauthorizedException("This API requires login"); @@ -783,7 +784,7 @@ function api_item_get_user(App $a, $item) $author_user = $status_user; - $status_user["protected"] = $item['private'] == Item::PRIVATE; + $status_user["protected"] = isset($item['private']) && ($item['private'] == Item::PRIVATE); if (($item['thr-parent'] ?? '') == ($item['uri'] ?? '')) { $owner_user = api_get_user($a, $item['owner-id'] ?? null); @@ -4733,13 +4734,8 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $ } } - if ($filetype == "") { - $filetype = Images::guessType($filename); - } - $imagedata = @getimagesize($src); - if ($imagedata) { - $filetype = $imagedata['mime']; - } + $filetype = Images::getMimeTypeBySource($src, $filename, $filetype); + Logger::log( "File upload src: " . $src . " - filename: " . $filename . " - size: " . $filesize . " - type: " . $filetype, @@ -5823,7 +5819,7 @@ function api_friendica_activity($type) $id = $_REQUEST['id'] ?? 0; - $res = Item::performLike($id, $verb); + $res = Item::performActivity($id, $verb); if ($res) { if ($type == "xml") {