Compare commits

...

15 commits

Author SHA1 Message Date
Michael 852ddb8acc Tumblr: Use the UUID to address the blog 2023-04-09 04:43:12 +00:00
Michael 37cdd74d73 Tumblr: Possible fixes 2023-04-08 16:49:52 +00:00
Hypolite Petovan c1830d8fd1 Merge pull request 'Tumblr: Fix #11551 and introduce NPF' (#1364) from heluecht/friendica-addons:tumblr-npf into 2023.03-rc
Reviewed-on: friendica/friendica-addons#1364
2023-04-06 23:23:04 +02:00
Michael 7dc1b44d1e Tumblr: Fix #11551 and introduce NPF 2023-04-06 19:10:32 +00:00
Hypolite Petovan 94129d3aa5 Merge pull request 'migrate transifex config to the new client' (#1363) from tobias/friendica-addons:20230406-transifexconfig into 2023.03-rc
Reviewed-on: friendica/friendica-addons#1363
2023-04-06 14:07:28 +02:00
Tobias Diekershoff 5ea5930d82 migrate transifex config to the new client 2023-04-06 11:12:54 +02:00
Hypolite Petovan efdc4fa3c0 Merge pull request 'Tumblr: Transmit multiple photos' (#1361) from heluecht/friendica-addons:tumblr-photos into develop
Reviewed-on: friendica/friendica-addons#1361
2023-03-09 22:02:22 +01:00
Michael 888dec1593 Remove media to avoid duplicated images 2023-03-09 20:59:42 +00:00
Michael 82376e4f17 Tumblr: Transmit multiple photos 2023-03-09 06:37:02 +00:00
Hypolite Petovan 2805395f77 Merge pull request '"getAttachedData" has been removed' (#1359) from heluecht/friendica-addons:no-attached-data into develop
Reviewed-on: friendica/friendica-addons#1359
2023-03-06 16:06:13 +01:00
Michael f5d1316212 Merge remote-tracking branch 'upstream/develop' into no-attached-data 2023-03-06 06:33:09 +00:00
Michael 878538c151 Access media via index 2023-03-06 00:49:30 +00:00
Michael a959a90582 Class added 2023-03-05 21:37:28 +00:00
Michael c8b6e7661b Unused variable removed 2023-03-05 21:35:14 +00:00
Michael 9183371062 "getAttachedData" has been removed 2023-03-05 21:17:14 +00:00
4 changed files with 429 additions and 555 deletions

View file

@ -1,399 +1,399 @@
[main]
host = https://www.transifex.com
host = https://api.transifex.com
[friendica.addon_advancedcontentfilter_messagespo]
[o:Friendica:p:friendica:r:addon_advancedcontentfilter_messagespo]
file_filter = advancedcontentfilter/lang/<lang>/messages.po
source_file = advancedcontentfilter/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_blackout_messagespo]
[o:Friendica:p:friendica:r:addon_blackout_messagespo]
file_filter = blackout/lang/<lang>/messages.po
source_file = blackout/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_blockem_messagespo]
[o:Friendica:p:friendica:r:addon_blockem_messagespo]
file_filter = blockem/lang/<lang>/messages.po
source_file = blockem/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_blogger_messagespo]
[o:Friendica:p:friendica:r:addon_blogger_messagespo]
file_filter = blogger/lang/<lang>/messages.po
source_file = blogger/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_buffer_messagespo]
[o:Friendica:p:friendica:r:addon_buffer_messagespo]
file_filter = buffer/lang/<lang>/messages.po
source_file = buffer/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_buglink_messagespo]
[o:Friendica:p:friendica:r:addon_buglink_messagespo]
file_filter = buglink/lang/<lang>/messages.po
source_file = buglink/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_catavatar_messagespo]
[o:Friendica:p:friendica:r:addon_catavatar_messagespo]
file_filter = catavatar/lang/<lang>/messages.po
source_file = catavatar/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_cookienotice_messagespo]
[o:Friendica:p:friendica:r:addon_cookienotice_messagespo]
file_filter = cookienotice/lang/<lang>/messages.po
source_file = cookienotice/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_curweather_messagespo]
[o:Friendica:p:friendica:r:addon_curweather_messagespo]
file_filter = curweather/lang/<lang>/messages.po
source_file = curweather/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_diaspora_messagespo]
[o:Friendica:p:friendica:r:addon_diaspora_messagespo]
file_filter = diaspora/lang/<lang>/messages.po
source_file = diaspora/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_dwpost_messagespo]
[o:Friendica:p:friendica:r:addon_dwpost_messagespo]
file_filter = dwpost/lang/<lang>/messages.po
source_file = dwpost/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_forumdirectory_messagespo]
[o:Friendica:p:friendica:r:addon_forumdirectory_messagespo]
file_filter = forumdirectory/lang/<lang>/messages.po
source_file = forumdirectory/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_fromapp_messagespo]
[o:Friendica:p:friendica:r:addon_fromapp_messagespo]
file_filter = fromapp/lang/<lang>/messages.po
source_file = fromapp/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_fromgplus_messagespo]
[o:Friendica:p:friendica:r:addon_fromgplus_messagespo]
file_filter = fromgplus/lang/<lang>/messages.po
source_file = fromgplus/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_geonames_messagespo]
[o:Friendica:p:friendica:r:addon_geonames_messagespo]
file_filter = geonames/lang/<lang>/messages.po
source_file = geonames/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_gnot_messagespo]
[o:Friendica:p:friendica:r:addon_gnot_messagespo]
file_filter = gnot/lang/<lang>/messages.po
source_file = gnot/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_gravatar_messagespo]
[o:Friendica:p:friendica:r:addon_gravatar_messagespo]
file_filter = gravatar/lang/<lang>/messages.po
source_file = gravatar/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_group_text_messagespo]
[o:Friendica:p:friendica:r:addon_group_text_messagespo]
file_filter = group_text/lang/<lang>/messages.po
source_file = group_text/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_ifttt_messagespo]
[o:Friendica:p:friendica:r:addon_ifttt_messagespo]
file_filter = ifttt/lang/<lang>/messages.po
source_file = ifttt/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_ijpost_messagespo]
[o:Friendica:p:friendica:r:addon_ijpost_messagespo]
file_filter = ijpost/lang/<lang>/messages.po
source_file = ijpost/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_impressum_messagespo]
[o:Friendica:p:friendica:r:addon_impressum_messagespo]
file_filter = impressum/lang/<lang>/messages.po
source_file = impressum/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_infiniteimprobabilitydrive_messagespo]
[o:Friendica:p:friendica:r:addon_infiniteimprobabilitydrive_messagespo]
file_filter = infiniteimprobabilitydrive/lang/<lang>/messages.po
source_file = infiniteimprobabilitydrive/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_irc_messagespo]
[o:Friendica:p:friendica:r:addon_irc_messagespo]
file_filter = irc/lang/<lang>/messages.po
source_file = irc/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_jappixmini_messagespo]
[o:Friendica:p:friendica:r:addon_jappixmini_messagespo]
file_filter = jappixmini/lang/<lang>/messages.po
source_file = jappixmini/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_js_upload_messagespo]
[o:Friendica:p:friendica:r:addon_js_upload_messagespo]
file_filter = js_upload/lang/<lang>/messages.po
source_file = js_upload/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_krynn_messagespo]
[o:Friendica:p:friendica:r:addon_krynn_messagespo]
file_filter = krynn/lang/<lang>/messages.po
source_file = krynn/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_langfilter_messagespo]
[o:Friendica:p:friendica:r:addon_langfilter_messagespo]
file_filter = langfilter/lang/<lang>/messages.po
source_file = langfilter/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_libertree_messagespo]
[o:Friendica:p:friendica:r:addon_libertree_messagespo]
file_filter = libertree/lang/<lang>/messages.po
source_file = libertree/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_libravatar_messagespo]
[o:Friendica:p:friendica:r:addon_libravatar_messagespo]
file_filter = libravatar/lang/<lang>/messages.po
source_file = libravatar/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_ljpost_messagespo]
[o:Friendica:p:friendica:r:addon_ljpost_messagespo]
file_filter = ljpost/lang/<lang>/messages.po
source_file = ljpost/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_mailstream_messagespo]
[o:Friendica:p:friendica:r:addon_mailstream_messagespo]
file_filter = mailstream/lang/<lang>/messages.po
source_file = mailstream/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_mathjax_messagespo]
[o:Friendica:p:friendica:r:addon_mathjax_messagespo]
file_filter = mathjax/lang/<lang>/messages.po
source_file = mathjax/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_membersince_messagespo]
[o:Friendica:p:friendica:r:addon_membersince_messagespo]
file_filter = membersince/lang/<lang>/messages.po
source_file = membersince/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_morechoice_messagespo]
[o:Friendica:p:friendica:r:addon_morechoice_messagespo]
file_filter = morechoice/lang/<lang>/messages.po
source_file = morechoice/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_morepokes_messagespo]
[o:Friendica:p:friendica:r:addon_morepokes_messagespo]
file_filter = morepokes/lang/<lang>/messages.po
source_file = morepokes/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_newmemberwidget_messagespo]
[o:Friendica:p:friendica:r:addon_newmemberwidget_messagespo]
file_filter = newmemberwidget/lang/<lang>/messages.po
source_file = newmemberwidget/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_notifyall_messagespo]
[o:Friendica:p:friendica:r:addon_notifyall_messagespo]
file_filter = notifyall/lang/<lang>/messages.po
source_file = notifyall/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_notimeline_messagespo]
[o:Friendica:p:friendica:r:addon_notimeline_messagespo]
file_filter = notimeline/lang/<lang>/messages.po
source_file = notimeline/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_nsfw_messagespo]
[o:Friendica:p:friendica:r:addon_nsfw_messagespo]
file_filter = nsfw/lang/<lang>/messages.po
source_file = nsfw/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_numfriends_messagespo]
[o:Friendica:p:friendica:r:addon_numfriends_messagespo]
file_filter = numfriends/lang/<lang>/messages.po
source_file = numfriends/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_openstreetmap_messagespo]
[o:Friendica:p:friendica:r:addon_openstreetmap_messagespo]
file_filter = openstreetmap/lang/<lang>/messages.po
source_file = openstreetmap/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_pageheader_messagespo]
[o:Friendica:p:friendica:r:addon_pageheader_messagespo]
file_filter = pageheader/lang/<lang>/messages.po
source_file = pageheader/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_piwik_messagespo]
[o:Friendica:p:friendica:r:addon_piwik_messagespo]
file_filter = piwik/lang/<lang>/messages.po
source_file = piwik/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_planets_messagespo]
[o:Friendica:p:friendica:r:addon_planets_messagespo]
file_filter = planets/lang/<lang>/messages.po
source_file = planets/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_public_server_messagespo]
[o:Friendica:p:friendica:r:addon_public_server_messagespo]
file_filter = public_server/lang/<lang>/messages.po
source_file = public_server/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_pumpio_messagespo]
[o:Friendica:p:friendica:r:addon_pumpio_messagespo]
file_filter = pumpio/lang/<lang>/messages.po
source_file = pumpio/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_qcomment_messagespo]
[o:Friendica:p:friendica:r:addon_qcomment_messagespo]
file_filter = qcomment/lang/<lang>/messages.po
source_file = qcomment/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_randplace_messagespo]
[o:Friendica:p:friendica:r:addon_randplace_messagespo]
file_filter = randplace/lang/<lang>/messages.po
source_file = randplace/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_remote_permissions_messagespo]
[o:Friendica:p:friendica:r:addon_remote_permissions_messagespo]
file_filter = remote_permissions/lang/<lang>/messages.po
source_file = remote_permissions/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_rendertime_messagespo]
[o:Friendica:p:friendica:r:addon_rendertime_messagespo]
file_filter = rendertime/lang/<lang>/messages.po
source_file = rendertime/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_securemail_messagespo]
[o:Friendica:p:friendica:r:addon_securemail_messagespo]
file_filter = securemail/lang/<lang>/messages.po
source_file = securemail/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_showmore_messagespo]
[o:Friendica:p:friendica:r:addon_showmore_messagespo]
file_filter = showmore/lang/<lang>/messages.po
source_file = showmore/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_smileybutton_messagespo]
[o:Friendica:p:friendica:r:addon_smileybutton_messagespo]
file_filter = smileybutton/lang/<lang>/messages.po
source_file = smileybutton/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_startpage_messagespo]
[o:Friendica:p:friendica:r:addon_startpage_messagespo]
file_filter = startpage/lang/<lang>/messages.po
source_file = startpage/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_statusnet_messagespo]
[o:Friendica:p:friendica:r:addon_statusnet_messagespo]
file_filter = statusnet/lang/<lang>/messages.po
source_file = statusnet/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_superblock_messagespo]
[o:Friendica:p:friendica:r:addon_superblock_messagespo]
file_filter = superblock/lang/<lang>/messages.po
source_file = superblock/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_testdrive_messagespo]
[o:Friendica:p:friendica:r:addon_testdrive_messagespo]
file_filter = testdrive/lang/<lang>/messages.po
source_file = testdrive/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_tictac_messagespo]
[o:Friendica:p:friendica:r:addon_tictac_messagespo]
file_filter = tictac/lang/<lang>/messages.po
source_file = tictac/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_tumblr_messagespo]
[o:Friendica:p:friendica:r:addon_tumblr_messagespo]
file_filter = tumblr/lang/<lang>/messages.po
source_file = tumblr/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_twitter_messagespo]
[o:Friendica:p:friendica:r:addon_twitter_messagespo]
file_filter = twitter/lang/<lang>/messages.po
source_file = twitter/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_viewsrc_messagespo]
[o:Friendica:p:friendica:r:addon_viewsrc_messagespo]
file_filter = viewsrc/lang/<lang>/messages.po
source_file = viewsrc/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_webrtc_messagespo]
[o:Friendica:p:friendica:r:addon_webrtc_messagespo]
file_filter = webrtc/lang/<lang>/messages.po
source_file = webrtc/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_widgets_messagespo]
[o:Friendica:p:friendica:r:addon_widgets_messagespo]
file_filter = widgets/lang/<lang>/messages.po
source_file = widgets/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_windowsphonepush_messagespo]
[o:Friendica:p:friendica:r:addon_windowsphonepush_messagespo]
file_filter = windowsphonepush/lang/<lang>/messages.po
source_file = windowsphonepush/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_wppost_messagespo]
[o:Friendica:p:friendica:r:addon_wppost_messagespo]
file_filter = wppost/lang/<lang>/messages.po
source_file = wppost/lang/C/messages.po
source_lang = en
type = PO
type = PO
[friendica.addon_xmpp_messagespo]
[o:Friendica:p:friendica:r:addon_xmpp_messagespo]
file_filter = xmpp/lang/<lang>/messages.po
source_file = xmpp/lang/C/messages.po
source_lang = en
type = PO
type = PO

View file

@ -6,6 +6,7 @@
* The first PHP Library to support OAuth for Tumblr's REST API. (Originally for Twitter, modified for Tumblr by Lucas)
*/
use Friendica\DI;
use Friendica\Security\OAuth1\OAuthConsumer;
use Friendica\Security\OAuth1\OAuthRequest;
use Friendica\Security\OAuth1\Signature\OAuthSignatureMethod_HMAC_SHA1;
@ -17,301 +18,91 @@ use Friendica\Security\OAuth1\OAuthUtil;
*/
class TumblrOAuth
{
/* Set up the API root URL. */
public $host = "https://api.tumblr.com/v2/";
/* Set timeout default. */
public $timeout = 30;
/* Set connect timeout. */
public $connecttimeout = 30;
/* Verify SSL Cert. */
public $ssl_verifypeer = FALSE;
/* Response format. */
public $format = 'json';
/* Decode returned json data. */
public $decode_json = TRUE;
/* Set the useragent. */
public $useragent = 'TumblrOAuth v0.2.0-beta2';
/* Contains the last HTTP status code returned. */
public $http_code;
/* Contains the last API call. */
public $url;
/**
* Contains the last HTTP headers returned.
* @var array
*/
public $http_header;
/**
* Contains the last HTTP request info
* @var string
*/
public $http_info;
/** @var OAuthToken */
private $token;
/** @var OAuthConsumer */
private $consumer;
/** @var \Friendica\Security\OAuth1\Signature\OAuthSignatureMethod_HMAC_SHA1 */
private $sha1_method;
/**
* Set API URLS
*/
function accessTokenURL()
{
return 'https://www.tumblr.com/oauth/access_token';
}
// API URLs
const accessTokenURL = 'https://www.tumblr.com/oauth/access_token';
const authorizeURL = 'https://www.tumblr.com/oauth/authorize';
const requestTokenURL = 'https://www.tumblr.com/oauth/request_token';
function authenticateURL()
{
return 'https://www.tumblr.com/oauth/authorize';
}
function authorizeURL()
{
return 'https://www.tumblr.com/oauth/authorize';
}
function requestTokenURL()
{
return 'https://www.tumblr.com/oauth/request_token';
}
function __construct($consumer_key, $consumer_secret, $oauth_token = null, $oauth_token_secret = null)
function __construct(string $consumer_key, string $consumer_secret)
{
$this->sha1_method = new OAuthSignatureMethod_HMAC_SHA1();
$this->consumer = new OAuthConsumer($consumer_key, $consumer_secret);
if (!empty($oauth_token) && !empty($oauth_token_secret)) {
$this->token = new OAuthToken($oauth_token, $oauth_token_secret);
} else {
$this->token = null;
}
$this->consumer = new OAuthConsumer($consumer_key, $consumer_secret);
}
/**
* Get a request_token from Tumblr
*
* @param callback $oauth_callback
* @param string $oauth_callback
* @return array
*/
function getRequestToken($oauth_callback = null)
function getRequestToken(string $oauth_callback): array
{
$parameters = [];
if (!empty($oauth_callback)) {
$parameters['oauth_callback'] = $oauth_callback;
}
$request = $this->oAuthRequest($this->requestTokenURL(), 'GET', $parameters);
$token = OAuthUtil::parse_parameters($request);
$this->token = new OAuthToken($token['oauth_token'], $token['oauth_token_secret']);
return $token;
$request = $this->oAuthRequest(self::requestTokenURL, ['oauth_callback' => $oauth_callback]);
return OAuthUtil::parse_parameters($request);
}
/**
* Get the authorize URL
*
* @param array $token
* @param bool $sign_in_with_tumblr
* @param string $oauth_token
* @return string
*/
function getAuthorizeURL($token, $sign_in_with_tumblr = TRUE)
function getAuthorizeURL(string $oauth_token): string
{
if (is_array($token)) {
$token = $token['oauth_token'];
}
if (empty($sign_in_with_tumblr)) {
return $this->authorizeURL() . "?oauth_token={$token}";
} else {
return $this->authenticateURL() . "?oauth_token={$token}";
}
return self::authorizeURL . "?oauth_token={$oauth_token}";
}
/**
* Exchange request token and secret for an access token and
* secret, to sign API calls.
*
* @param bool $oauth_verifier
* @param string $oauth_verifier
* @param string $request_token
* @param string $request_token_secret
* @return array ("oauth_token" => "the-access-token",
* "oauth_token_secret" => "the-access-secret",
* "user_id" => "9436992",
* "screen_name" => "abraham")
*/
function getAccessToken($oauth_verifier = FALSE)
function getAccessToken(string $oauth_verifier, string $request_token, string $request_token_secret): array
{
$token = new OAuthToken($request_token, $request_token_secret);
$parameters = [];
if (!empty($oauth_verifier)) {
$parameters['oauth_verifier'] = $oauth_verifier;
}
$request = $this->oAuthRequest($this->accessTokenURL(), 'GET', $parameters);
$token = OAuthUtil::parse_parameters($request);
$this->token = new OAuthToken($token['oauth_token'], $token['oauth_token_secret']);
return $token;
}
/**
* One time exchange of username and password for access token and secret.
*
* @param string $username
* @param string $password
* @return array ("oauth_token" => "the-access-token",
* "oauth_token_secret" => "the-access-secret",
* "user_id" => "9436992",
* "screen_name" => "abraham",
* "x_auth_expires" => "0")
*/
function getXAuthToken($username, $password)
{
$parameters = [];
$parameters['x_auth_username'] = $username;
$parameters['x_auth_password'] = $password;
$parameters['x_auth_mode'] = 'client_auth';
$request = $this->oAuthRequest($this->accessTokenURL(), 'POST', $parameters);
$token = OAuthUtil::parse_parameters($request);
$this->token = new OAuthToken($token['oauth_token'], $token['oauth_token_secret']);
return $token;
}
/**
* GET wrapper for oAuthRequest.
*
* @param string $url
* @param array $parameters
* @return mixed|string
*/
function get($url, $parameters = [])
{
$response = $this->oAuthRequest($url, 'GET', $parameters);
if ($this->format === 'json' && $this->decode_json) {
return json_decode($response);
}
return $response;
}
/**
* POST wrapper for oAuthRequest.
*
* @param string $url
* @param array $parameters
* @return mixed|string
*/
function post($url, $parameters = [])
{
$response = $this->oAuthRequest($url, 'POST', $parameters);
if ($this->format === 'json' && $this->decode_json) {
return json_decode($response);
}
return $response;
}
/**
* DELETE wrapper for oAuthReqeust.
*
* @param string $url
* @param array $parameters
* @return mixed|string
*/
function delete($url, $parameters = [])
{
$response = $this->oAuthRequest($url, 'DELETE', $parameters);
if ($this->format === 'json' && $this->decode_json) {
return json_decode($response);
}
return $response;
$request = $this->oAuthRequest(self::accessTokenURL, $parameters, $token);
return OAuthUtil::parse_parameters($request);
}
/**
* Format and sign an OAuth / API request
*
* @param string $url
* @param string $method
* @param array $parameters
* @return mixed|string
* @param string $url
* @param array $parameters
* @param OAuthToken $token $name
* @return string
*/
function oAuthRequest($url, $method, $parameters)
private function oAuthRequest(string $url, array $parameters, OAuthToken $token = null): string
{
if (strrpos($url, 'https://') !== 0 && strrpos($url, 'http://') !== 0) {
$url = "{$this->host}{$url}";
$request = OAuthRequest::from_consumer_and_token($this->consumer, 'GET', $url, $parameters, $token);
$request->sign_request($this->sha1_method, $this->consumer, $token);
$curlResult = DI::httpClient()->get($request->to_url());
$this->http_code = $curlResult->getReturnCode();
if ($curlResult->isSuccess()) {
return $curlResult->getBody();
}
$request = OAuthRequest::from_consumer_and_token($this->consumer, $method, $url, $parameters, $this->token);
$request->sign_request($this->sha1_method, $this->consumer, $this->token);
switch ($method) {
case 'GET':
return $this->http($request->to_url(), 'GET');
default:
return $this->http($request->get_normalized_http_url(), $method, $request->to_postdata());
}
}
/**
* Make an HTTP request
*
* @param string $url
* @param string $method
* @param mixed $postfields
* @return string API results
*/
function http($url, $method, $postfields = null)
{
$this->http_info = [];
$ci = curl_init();
/* Curl settings */
curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);
curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
curl_setopt($ci, CURLOPT_HEADER, FALSE);
switch ($method) {
case 'POST':
curl_setopt($ci, CURLOPT_POST, TRUE);
if (!empty($postfields)) {
curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
}
break;
case 'DELETE':
curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
if (!empty($postfields)) {
$url = "{$url}?{$postfields}";
}
}
curl_setopt($ci, CURLOPT_URL, $url);
$response = curl_exec($ci);
$this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
$this->http_info = array_merge($this->http_info, curl_getinfo($ci));
$this->url = $url;
curl_close($ci);
return $response;
}
/**
* Get the header info to store.
*
* @param resource $ch
* @param string $header
* @return int
*/
function getHeader($ch, $header)
{
$i = strpos($header, ':');
if (!empty($i)) {
$key = str_replace('-', '_', strtolower(substr($header, 0, $i)));
$value = trim(substr($header, $i + 2));
$this->http_header[$key] = $value;
}
return strlen($header);
return '';
}
}

View file

@ -9,15 +9,23 @@
require_once __DIR__ . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR . 'tumblroauth.php';
use Friendica\App;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\NPF;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\Renderer;
use Friendica\Database\DBA;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Photo;
use Friendica\Model\Post;
use Friendica\Model\Tag;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Subscriber\Oauth\Oauth1;
function tumblr_install()
{
@ -34,7 +42,9 @@ function tumblr_install()
* existence of this method is checked to figure out if the addon offers a
* module.
*/
function tumblr_module() {}
function tumblr_module()
{
}
function tumblr_content()
{
@ -45,11 +55,11 @@ function tumblr_content()
if (isset(DI::args()->getArgv()[1])) {
switch (DI::args()->getArgv()[1]) {
case "connect":
case 'connect':
$o = tumblr_connect();
break;
case "callback":
case 'callback':
$o = tumblr_callback();
break;
@ -66,13 +76,13 @@ function tumblr_content()
function tumblr_addon_admin(string &$o)
{
$t = Renderer::getMarkupTemplate( "admin.tpl", "addon/tumblr/" );
$t = Renderer::getMarkupTemplate('admin.tpl', 'addon/tumblr/');
$o = Renderer::replaceMacros($t, [
'$submit' => DI::l10n()->t('Save Settings'),
// name, label, value, help, [extra values]
'$consumer_key' => ['consumer_key', DI::l10n()->t('Consumer Key'), DI::config()->get('tumblr', 'consumer_key' ), ''],
'$consumer_secret' => ['consumer_secret', DI::l10n()->t('Consumer Secret'), DI::config()->get('tumblr', 'consumer_secret' ), ''],
'$consumer_key' => ['consumer_key', DI::l10n()->t('Consumer Key'), DI::config()->get('tumblr', 'consumer_key'), ''],
'$consumer_secret' => ['consumer_secret', DI::l10n()->t('Consumer Secret'), DI::config()->get('tumblr', 'consumer_secret'), ''],
]);
}
@ -87,9 +97,6 @@ function tumblr_connect()
// Start a session. This is necessary to hold on to a few keys the callback script will also need
session_start();
// Include the TumblrOAuth library
//require_once('addon/tumblr/tumblroauth/tumblroauth.php');
// Define the needed keys
$consumer_key = DI::config()->get('tumblr', 'consumer_key');
$consumer_secret = DI::config()->get('tumblr', 'consumer_secret');
@ -109,17 +116,17 @@ function tumblr_connect()
$request_token = $tum_oauth->getRequestToken($callback_url);
// Store the request token and Request Token Secret as out callback.php script will need this
$_SESSION['request_token'] = $token = $request_token['oauth_token'];
$_SESSION['request_token_secret'] = $request_token['oauth_token_secret'];
DI::session()->set('request_token', $request_token['oauth_token']);
DI::session()->set('request_token_secret', $request_token['oauth_token_secret']);
// Check the HTTP Code. It should be a 200 (OK), if it's anything else then something didn't work.
switch ($tum_oauth->http_code) {
case 200:
// Ask Tumblr to give us a special address to their login page
$url = $tum_oauth->getAuthorizeURL($token);
$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
@ -141,10 +148,9 @@ function tumblr_callback()
{
// Start a session, load the library
session_start();
//require_once('addon/tumblr/tumblroauth/tumblroauth.php');
// Define the needed keys
$consumer_key = DI::config()->get('tumblr', 'consumer_key');
$consumer_key = DI::config()->get('tumblr', 'consumer_key');
$consumer_secret = DI::config()->get('tumblr', 'consumer_secret');
// Once the user approves your app at Tumblr, they are sent back to this script.
@ -154,14 +160,14 @@ function tumblr_callback()
// Create instance of TumblrOAuth.
// It'll need our Consumer Key and Secret as well as our Request Token and Secret
$tum_oauth = new TumblrOAuth($consumer_key, $consumer_secret, $_SESSION['request_token'], $_SESSION['request_token_secret']);
$tum_oauth = new TumblrOAuth($consumer_key, $consumer_secret);
// Ok, let's get an Access Token. We'll need to pass along our oauth_verifier which was given to us in the URL.
$access_token = $tum_oauth->getAccessToken($_REQUEST['oauth_verifier']);
$access_token = $tum_oauth->getAccessToken($_REQUEST['oauth_verifier'], DI::session()->get('request_token'), DI::session()->get('request_token_secret'));
// We're done with the Request Token and Secret so let's remove those.
unset($_SESSION['request_token']);
unset($_SESSION['request_token_secret']);
DI::session()->remove('request_token');
DI::session()->remove('request_token_secret');
// Make sure nothing went wrong.
if (200 == $tum_oauth->http_code) {
@ -174,7 +180,7 @@ function tumblr_callback()
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'tumblr', 'oauth_token', $access_token['oauth_token']);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'tumblr', 'oauth_token_secret', $access_token['oauth_token_secret']);
$o = DI::l10n()->t("You are now authenticated to tumblr.");
$o = DI::l10n()->t('You are now authenticated to tumblr.');
$o .= '<br /><a href="' . DI::baseUrl() . '/settings/connectors">' . DI::l10n()->t("return to the connector page") . '</a>';
return $o;
@ -186,13 +192,13 @@ function tumblr_jot_nets(array &$jotnets_fields)
return;
}
if (DI::pConfig()->get(DI::userSession()->getLocalUserId(),'tumblr','post')) {
if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'tumblr', 'post')) {
$jotnets_fields[] = [
'type' => 'checkbox',
'field' => [
'tumblr_enable',
DI::l10n()->t('Post to Tumblr'),
DI::pConfig()->get(DI::userSession()->getLocalUserId(),'tumblr','post_by_default')
DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'tumblr', 'post_by_default')
]
];
}
@ -209,20 +215,30 @@ 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');
$consumer_key = DI::config()->get('tumblr', 'consumer_key');
$consumer_secret = DI::config()->get('tumblr', 'consumer_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');
$tum_oauth = new TumblrOAuth($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret);
$userinfo = $tum_oauth->get('user/info');
$blogs = [];
$blogs = array_map(function ($blog) {
return substr(str_replace(["http://", "https://"], ["", ""], $blog->url), 0, -1);
}, $userinfo->response->user->blogs);
$connection = tumblr_client($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret);
if ($connection) {
$userinfo = tumblr_get($connection, 'user/info');
if (!empty($userinfo['success'])) {
foreach ($userinfo['data']->response->user->blogs as $blog) {
$blogs[$blog->uuid] = $blog->name;
}
}
$page_select = ['tumblr-page', DI::l10n()->t('Post to page:'), $page, '', $blogs];
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];
}
$t = Renderer::getMarkupTemplate('connector_settings.tpl', 'addon/tumblr/');
@ -265,8 +281,10 @@ function tumblr_hook_fork(array &$b)
$post = $b['data'];
if ($post['deleted'] || $post['private'] || ($post['created'] !== $post['edited']) ||
!strstr($post['postopts'] ?? '', 'tumblr') || ($post['parent'] != $post['id'])) {
if (
$post['deleted'] || $post['private'] || ($post['created'] !== $post['edited']) ||
!strstr($post['postopts'] ?? '', 'tumblr') || ($post['parent'] != $post['id'])
) {
$b['execute'] = false;
return;
}
@ -307,138 +325,208 @@ function tumblr_post_local(array &$b)
$b['postopts'] .= 'tumblr';
}
function tumblr_send(array &$b) {
function tumblr_send(array &$b)
{
if ($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited'])) {
return;
}
if (! strstr($b['postopts'],'tumblr')) {
if (!strstr($b['postopts'], 'tumblr')) {
return;
}
if ($b['parent'] != $b['id']) {
if ($b['gravity'] != Item::GRAVITY_PARENT) {
return;
}
// Dont't post if the post doesn't belong to us.
// This is a check for forum postings
$self = DBA::selectFirst('contact', ['id'], ['uid' => $b['uid'], 'self' => true]);
if ($b['contact-id'] != $self['id']) {
if (tumblr_send_npf($b)) {
return;
}
$b['body'] = Post\Media::addAttachmentsToBody($b['uri-id'], DI::contentItem()->addSharedPost($b));
$connection = tumblr_connection($b['uid']);
if (empty($connection)) {
return;
}
$oauth_token = DI::pConfig()->get($b['uid'], "tumblr", "oauth_token");
$oauth_token_secret = DI::pConfig()->get($b['uid'], "tumblr", "oauth_token_secret");
$page = DI::pConfig()->get($b['uid'], "tumblr", "page");
$tmbl_blog = 'blog/' . $page . '/post';
$b['body'] = BBCode::removeAttachment($b['body']);
if ($oauth_token && $oauth_token_secret && $tmbl_blog) {
$tags = Tag::getByURIId($b['uri-id']);
$title = trim($b['title']);
$tag_arr = [];
$media = Post\Media::getByURIId($b['uri-id'], [Post\Media::HTML, Post\Media::AUDIO, Post\Media::VIDEO, Post\Media::IMAGE]);
foreach($tags as $tag) {
$tag_arr[] = $tag['name'];
}
$photo = array_search(Post\Media::IMAGE, array_column($media, 'type'));
$link = array_search(Post\Media::HTML, array_column($media, 'type'));
$audio = array_search(Post\Media::AUDIO, array_column($media, 'type'));
$video = array_search(Post\Media::VIDEO, array_column($media, 'type'));
if (count($tag_arr)) {
$tags = implode(',', $tag_arr);
}
$params = [
'state' => 'published',
'tags' => implode(',', array_column(Tag::getByURIId($b['uri-id']), 'name')),
'tweet' => 'off',
'format' => 'html',
];
$title = trim($b['title']);
$body = BBCode::removeShareInformation($b['body']);
$body = Post\Media::removeFromEndOfBody($body);
$siteinfo = BBCode::getAttachedData($b["body"]);
$params = [
'state' => 'published',
'tags' => $tags,
'tweet' => 'off',
'format' => 'html',
];
if (!isset($siteinfo["type"])) {
$siteinfo["type"] = "";
}
if (($title == "") && isset($siteinfo["title"])) {
$title = $siteinfo["title"];
}
if (isset($siteinfo["text"])) {
$body = $siteinfo["text"];
} else {
$body = BBCode::removeShareInformation($b["body"]);
}
switch ($siteinfo["type"]) {
case "photo":
$params['type'] = "photo";
$params['caption'] = BBCode::convertForUriId($b['uri-id'], $body, BBCode::CONNECTORS);;
if (isset($siteinfo["url"])) {
$params['link'] = $siteinfo["url"];
if ($photo !== false) {
$params['type'] = 'photo';
$params['caption'] = BBCode::convertForUriId($b['uri-id'], $body, BBCode::CONNECTORS);
$params['data'] = [];
foreach ($media as $photo) {
if ($photo['type'] == Post\Media::IMAGE) {
if (Network::isLocalLink($photo['url']) && ($data = Photo::getResourceData($photo['url']))) {
$photo = Photo::selectFirst([], ["`resource-id` = ? AND `scale` > ?", $data['guid'], 0]);
if (!empty($photo)) {
$params['data'][] = Photo::getImageDataForPhoto($photo);
}
}
$params['source'] = $siteinfo["image"];
break;
case "link":
$params['type'] = "link";
$params['title'] = $title;
$params['url'] = $siteinfo["url"];
$params['description'] = BBCode::convertForUriId($b['uri-id'], $body, BBCode::CONNECTORS);
break;
case "audio":
$params['type'] = "audio";
$params['external_url'] = $siteinfo["url"];
$params['caption'] = BBCode::convertForUriId($b['uri-id'], $body, BBCode::CONNECTORS);
break;
case "video":
$params['type'] = "video";
$params['embed'] = $siteinfo["url"];
$params['caption'] = BBCode::convertForUriId($b['uri-id'], $body, BBCode::CONNECTORS);
break;
default:
$params['type'] = "text";
$params['title'] = $title;
$params['body'] = BBCode::convertForUriId($b['uri-id'], $b['body'], BBCode::CONNECTORS);
break;
}
}
} elseif ($link !== false) {
$params['type'] = 'link';
$params['title'] = $media[$link]['name'];
$params['url'] = $media[$link]['url'];
$params['description'] = BBCode::convertForUriId($b['uri-id'], $body, BBCode::CONNECTORS);
if (isset($params['caption']) && (trim($title) != "")) {
$params['caption'] = '<h1>'.$title."</h1>".
"<p>".$params['caption']."</p>";
if (!empty($media[$link]['preview'])) {
$params['thumbnail'] = $media[$link]['preview'];
}
if (empty($params['caption']) && !empty($siteinfo["description"])) {
$params['caption'] = BBCode::convertForUriId($b['uri-id'], "[quote]" . $siteinfo["description"] . "[/quote]", BBCode::CONNECTORS);
if (!empty($media[$link]['description'])) {
$params['excerpt'] = $media[$link]['description'];
}
$consumer_key = DI::config()->get('tumblr','consumer_key');
$consumer_secret = DI::config()->get('tumblr','consumer_secret');
$tum_oauth = new TumblrOAuth($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret);
// Make an API call with the TumblrOAuth instance.
$x = $tum_oauth->post($tmbl_blog,$params);
$ret_code = $tum_oauth->http_code;
//print_r($params);
if ($ret_code == 201) {
Logger::notice('tumblr_send: success');
} elseif ($ret_code == 403) {
Logger::notice('tumblr_send: authentication failure');
} else {
Logger::notice('tumblr_send: general error', ['error' => $x]);
if (!empty($media[$link]['author-name'])) {
$params['author'] = $media[$link]['author-name'];
}
} elseif ($audio !== false) {
$params['type'] = 'audio';
$params['external_url'] = $media[$audio]['url'];
$params['caption'] = BBCode::convertForUriId($b['uri-id'], $body, BBCode::CONNECTORS);
} elseif ($video !== false) {
$params['type'] = 'video';
$params['embed'] = $media[$video]['url'];
$params['caption'] = BBCode::convertForUriId($b['uri-id'], $body, BBCode::CONNECTORS);
} else {
$params['type'] = 'text';
$params['title'] = $title;
$params['body'] = BBCode::convertForUriId($b['uri-id'], $b['body'], BBCode::CONNECTORS);
}
if (isset($params['caption']) && (trim($title) != '')) {
$params['caption'] = '<h1>' . $title . '</h1>' .
'<p>' . $params['caption'] . '</p>';
}
$page = DI::pConfig()->get($b['uid'], 'tumblr', 'page');
$result = tumblr_post($connection, 'blog/' . $page . '/post', $params);
if ($result['success']) {
Logger::info('success', ['blog' => $page, 'params' => $params]);
return true;
} else {
Logger::notice('error', ['blog' => $page, 'params' => $params, 'result' => $result['data']]);
return false;
}
}
function tumblr_send_npf(array $post): bool
{
$page = DI::pConfig()->get($post['uid'], 'tumblr', 'page');
$connection = tumblr_connection($post['uid']);
if (empty($connection)) {
Logger::notice('Missing data, post will not be send to Tumblr.', ['uid' => $post['uid'], 'page' => $page, 'id' => $post['id']]);
// "true" is returned, since the legacy function will fail as well.
return true;
}
$post['body'] = Post\Media::addAttachmentsToBody($post['uri-id'], $post['body']);
if (!empty($post['title'])) {
$post['body'] = '[h1]' . $post['title'] . "[/h1]\n" . $post['body'];
}
$params = [
'content' => NPF::fromBBCode($post['body'], $post['uri-id']),
'state' => 'published',
'date' => DateTimeFormat::utc($post['created'], DateTimeFormat::ATOM),
'tags' => implode(',', array_column(Tag::getByURIId($post['uri-id']), 'name')),
'is_private' => false,
'interactability_reblog' => 'everyone'
];
$result = tumblr_post($connection, 'blog/' . $page . '/posts', $params);
if ($result['success']) {
Logger::info('success', ['blog' => $page, 'params' => $params]);
return true;
} else {
Logger::notice('error', ['blog' => $page, 'params' => $params, 'result' => $result['data']]);
return false;
}
}
function tumblr_connection(int $uid): GuzzleHttp\Client|null
{
$oauth_token = DI::pConfig()->get($uid, 'tumblr', 'oauth_token');
$oauth_token_secret = DI::pConfig()->get($uid, 'tumblr', 'oauth_token_secret');
$page = DI::pConfig()->get($uid, '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) {
Logger::notice('Missing data, connection is not established', ['uid' => $uid, 'page' => $page]);
return null;
}
return tumblr_client($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret);
}
function tumblr_client(string $consumer_key, string $consumer_secret, string $oauth_token, string $oauth_token_secret): GuzzleHttp\Client
{
$stack = HandlerStack::create();
$middleware = new Oauth1([
'consumer_key' => $consumer_key,
'consumer_secret' => $consumer_secret,
'token' => $oauth_token,
'token_secret' => $oauth_token_secret
]);
$stack->push($middleware);
return new Client([
'base_uri' => 'https://api.tumblr.com/v2/',
'handler' => $stack
]);
}
function tumblr_get($connection, string $url)
{
try {
$res = $connection->get($url, ['auth' => 'oauth']);
$success = true;
$data = json_decode($res->getBody()->getContents());
} catch (RequestException $exception) {
$success = false;
Logger::notice('Request failed', ['code' => $exception->getCode(), 'message' => $exception->getMessage()]);
$data = json_decode($exception->getResponse()->getBody()->getContents());
}
return ['success' => $success, 'data' => $data];
}
function tumblr_post($connection, string $url, array $parameter)
{
try {
$res = $connection->post($url, ['auth' => 'oauth', 'json' => $parameter]);
$success = true;
$data = json_decode($res->getBody()->getContents());
} catch (RequestException $exception) {
$success = false;
Logger::notice('Post failed', ['code' => $exception->getCode(), 'message' => $exception->getMessage()]);
$data = json_decode($exception->getResponse()->getBody()->getContents());
}
return ['success' => $success, 'data' => $data];
}

View file

@ -6,7 +6,6 @@
* Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
*/
use Friendica\App;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
use Friendica\Core\Hook;
@ -14,6 +13,7 @@ use Friendica\Core\Logger;
use Friendica\Core\Renderer;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Util\XML;
@ -33,13 +33,13 @@ function wppost_jot_nets(array &$jotnets_fields)
return;
}
if (DI::pConfig()->get(DI::userSession()->getLocalUserId(),'wppost','post')) {
if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'wppost', 'post')) {
$jotnets_fields[] = [
'type' => 'checkbox',
'field' => [
'wppost_enable',
DI::l10n()->t('Post to Wordpress'),
DI::pConfig()->get(DI::userSession()->getLocalUserId(),'wppost','post_by_default')
DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'wppost', 'post_by_default')
]
];
}
@ -84,14 +84,14 @@ function wppost_settings(array &$data)
function wppost_settings_post(array &$b)
{
if(!empty($_POST['wppost-submit'])) {
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'wppost', 'post' , intval($_POST['wppost']));
if (!empty($_POST['wppost-submit'])) {
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'wppost', 'post', intval($_POST['wppost']));
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'wppost', 'post_by_default', intval($_POST['wp_bydefault']));
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'wppost', 'wp_username' , trim($_POST['wp_username']));
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'wppost', 'wp_password' , trim($_POST['wp_password']));
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'wppost', 'wp_blog' , trim($_POST['wp_blog']));
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'wppost', 'backlink' , intval($_POST['wp_backlink']));
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'wppost', 'shortcheck' , intval($_POST['wp_shortcheck']));
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'wppost', 'wp_username', trim($_POST['wp_username']));
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'wppost', 'wp_password', trim($_POST['wp_password']));
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'wppost', 'wp_blog', trim($_POST['wp_blog']));
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'wppost', 'backlink', intval($_POST['wp_backlink']));
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'wppost', 'shortcheck', intval($_POST['wp_shortcheck']));
$wp_backlink_text = BBCode::convert(trim($_POST['wp_backlink_text']), false, BBCode::BACKLINK);
$wp_backlink_text = HTML::toPlaintext($wp_backlink_text, 0, true);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'wppost', 'wp_backlink_text', $wp_backlink_text);
@ -106,14 +106,17 @@ function wppost_hook_fork(array &$b)
$post = $b['data'];
if ($post['deleted'] || $post['private'] || ($post['created'] !== $post['edited']) ||
!strstr($post['postopts'] ?? '', 'wppost') || ($post['parent'] != $post['id'])) {
if (
$post['deleted'] || $post['private'] || ($post['created'] !== $post['edited']) ||
!strstr($post['postopts'] ?? '', 'wppost') || ($post['parent'] != $post['id'])
) {
$b['execute'] = false;
return;
}
}
function wppost_post_local(array &$b) {
function wppost_post_local(array &$b)
{
// This can probably be changed to allow editing by pointing to a different API endpoint
@ -153,15 +156,15 @@ function wppost_post_local(array &$b) {
function wppost_send(array &$b)
{
if($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited'])) {
if ($b['deleted'] || $b['private'] || ($b['created'] !== $b['edited'])) {
return;
}
if(! strstr($b['postopts'],'wppost')) {
if (!strstr($b['postopts'], 'wppost')) {
return;
}
if($b['parent'] != $b['id']) {
if ($b['gravity'] != Item::GRAVITY_PARENT) {
return;
}
@ -176,8 +179,8 @@ function wppost_send(array &$b)
$wp_username = XML::escape(DI::pConfig()->get($b['uid'], 'wppost', 'wp_username'));
$wp_password = XML::escape(DI::pConfig()->get($b['uid'], 'wppost', 'wp_password'));
$wp_blog = DI::pConfig()->get($b['uid'],'wppost','wp_blog');
$wp_backlink_text = DI::pConfig()->get($b['uid'],'wppost','wp_backlink_text');
$wp_blog = DI::pConfig()->get($b['uid'], 'wppost', 'wp_blog');
$wp_backlink_text = DI::pConfig()->get($b['uid'], 'wppost', 'wp_backlink_text');
if ($wp_backlink_text == '') {
$wp_backlink_text = DI::l10n()->t('Read the orig­i­nal post and com­ment stream on Friendica');
}
@ -187,15 +190,7 @@ function wppost_send(array &$b)
if (intval(DI::pConfig()->get($b['uid'], 'wppost', 'shortcheck'))) {
// Checking, if its a post that is worth a blog post
$postentry = false;
$siteinfo = BBCode::getAttachedData($b["body"]);
// Is it a link to an aricle, a video or a photo?
if (isset($siteinfo["type"])) {
if (in_array($siteinfo["type"], ["link", "audio", "video", "photo"])) {
$postentry = true;
}
}
$postentry = (bool)Post\Media::getByURIId($b['uri-id'], [Post\Media::HTML, Post\Media::AUDIO, Post\Media::VIDEO, Post\Media::IMAGE]);
// Does it have a title?
if ($wptitle != "") {
@ -215,9 +210,9 @@ function wppost_send(array &$b)
// If the title is empty then try to guess
if ($wptitle == '') {
// Fetch information about the post
$siteinfo = BBCode::getAttachedData($b["body"]);
if (isset($siteinfo["title"])) {
$wptitle = $siteinfo["title"];
$media = Post\Media::getByURIId($b['uri-id'], [Post\Media::HTML]);
if (!empty($media) && !empty($media[0]['name']) && ($media[0]['name'] != $media[0]['url'])) {
$wptitle = $media[0]['name'];
}
// If no bookmark is found then take the first line
@ -225,7 +220,7 @@ function wppost_send(array &$b)
// Remove the share element before fetching the first line
$title = trim(preg_replace("/\[share.*?\](.*?)\[\/share\]/ism", "\n$1\n", $b['body']));
$title = BBCode::toPlaintext($title)."\n";
$title = BBCode::toPlaintext($title) . "\n";
$pos = strpos($title, "\n");
$trailer = "";
if (($pos == 0) || ($pos > 100)) {
@ -233,7 +228,7 @@ function wppost_send(array &$b)
$trailer = "...";
}
$wptitle = substr($title, 0, $pos).$trailer;
$wptitle = substr($title, 0, $pos) . $trailer;
}
}
@ -244,10 +239,10 @@ function wppost_send(array &$b)
$post = preg_replace('/<a.*?href="(https?:\/\/www.youtube.com\/.*?)".*?>(.*?)<\/a>/ism', "\n$1\n", $post);
$post = preg_replace('/<a.*?href="(https?:\/\/youtu.be\/.*?)".*?>(.*?)<\/a>/ism', "\n$1\n", $post);
$post = $title.$post;
$post = $title . $post;
$wp_backlink = intval(DI::pConfig()->get($b['uid'],'wppost','backlink'));
if($wp_backlink && $b['plink']) {
$wp_backlink = intval(DI::pConfig()->get($b['uid'], 'wppost', 'backlink'));
if ($wp_backlink && $b['plink']) {
$post .= '<p><a href="' . $b['plink'] . '">' . $wp_backlink_text . '</a></p>';
}