Merge pull request 'Tumblr: Possible fixes' (#1366) from heluecht/friendica-addons:tumblr into 2023.03-rc

Reviewed-on: https://git.friendi.ca/friendica/friendica-addons/pulls/1366
This commit is contained in:
Hypolite Petovan 2023-04-08 19:14:27 +02:00
commit 9732ad543b

View file

@ -14,6 +14,7 @@ use Friendica\Content\Text\NPF;
use Friendica\Core\Hook; use Friendica\Core\Hook;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\Core\System;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Photo; use Friendica\Model\Photo;
@ -24,6 +25,7 @@ use Friendica\Util\Network;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\HandlerStack; use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Uri as Uri;
use GuzzleHttp\Subscriber\Oauth\Oauth1; use GuzzleHttp\Subscriber\Oauth\Oauth1;
function tumblr_install() function tumblr_install()
@ -125,7 +127,7 @@ function tumblr_connect()
$url = $tum_oauth->getAuthorizeURL($request_token['oauth_token']); $url = $tum_oauth->getAuthorizeURL($request_token['oauth_token']);
// Redirect the user to the login URL given to us by Tumblr // Redirect the user to the login URL given to us by Tumblr
header('Location: ' . $url); System::externalRedirect($url);
/* /*
* That's it for our side. The user is sent to a Tumblr Login page and * That's it for our side. The user is sent to a Tumblr Login page and
@ -214,11 +216,11 @@ function tumblr_settings(array &$data)
$oauth_token = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'tumblr', 'oauth_token'); $oauth_token = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'tumblr', 'oauth_token');
$oauth_token_secret = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'tumblr', 'oauth_token_secret'); $oauth_token_secret = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'tumblr', 'oauth_token_secret');
$consumer_key = DI::config()->get('tumblr', 'consumer_key');
$consumer_secret = DI::config()->get('tumblr', 'consumer_secret');
if ($oauth_token && $oauth_token_secret) { if ($consumer_key && $consumer_secret && $oauth_token && $oauth_token_secret) {
$page = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'tumblr', 'page'); $page = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'tumblr', 'page');
$consumer_key = DI::config()->get('tumblr', 'consumer_key');
$consumer_secret = DI::config()->get('tumblr', 'consumer_secret');
$blogs = []; $blogs = [];
@ -227,10 +229,16 @@ function tumblr_settings(array &$data)
$userinfo = tumblr_get($connection, 'user/info'); $userinfo = tumblr_get($connection, 'user/info');
if (!empty($userinfo['success'])) { if (!empty($userinfo['success'])) {
foreach ($userinfo['data']->response->user->blogs as $blog) { foreach ($userinfo['data']->response->user->blogs as $blog) {
$url = parse_url($blog->url, PHP_URL_HOST); $uri = new Uri($blog->url);
$url = trim($uri->getHost() . $uri->getPath(), '/');
$blogs[$url] = $url; $blogs[$url] = $url;
} }
} }
if (empty($page) && !empty($blogs)) {
$page = reset($blogs);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'tumblr', 'page', $page);
}
} }
$page_select = ['tumblr_page', DI::l10n()->t('Post to page:'), $page, '', $blogs]; $page_select = ['tumblr_page', DI::l10n()->t('Post to page:'), $page, '', $blogs];