forked from friendica/friendica-addons
Merge pull request 'Tumblr: Possible fixes' (#1366) from heluecht/friendica-addons:tumblr into 2023.03-rc
Reviewed-on: friendica/friendica-addons#1366
This commit is contained in:
commit
9732ad543b
|
@ -14,6 +14,7 @@ use Friendica\Content\Text\NPF;
|
|||
use Friendica\Core\Hook;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Photo;
|
||||
|
@ -24,6 +25,7 @@ use Friendica\Util\Network;
|
|||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Psr7\Uri as Uri;
|
||||
use GuzzleHttp\Subscriber\Oauth\Oauth1;
|
||||
|
||||
function tumblr_install()
|
||||
|
@ -125,7 +127,7 @@ function tumblr_connect()
|
|||
$url = $tum_oauth->getAuthorizeURL($request_token['oauth_token']);
|
||||
|
||||
// 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
|
||||
|
@ -214,12 +216,12 @@ function tumblr_settings(array &$data)
|
|||
|
||||
$oauth_token = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'tumblr', 'oauth_token');
|
||||
$oauth_token_secret = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'tumblr', 'oauth_token_secret');
|
||||
|
||||
if ($oauth_token && $oauth_token_secret) {
|
||||
$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');
|
||||
|
||||
if ($consumer_key && $consumer_secret && $oauth_token && $oauth_token_secret) {
|
||||
$page = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'tumblr', 'page');
|
||||
|
||||
$blogs = [];
|
||||
|
||||
$connection = tumblr_client($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret);
|
||||
|
@ -227,10 +229,16 @@ function tumblr_settings(array &$data)
|
|||
$userinfo = tumblr_get($connection, 'user/info');
|
||||
if (!empty($userinfo['success'])) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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];
|
||||
|
|
Loading…
Reference in a new issue