microblogging: Added API token functionality for announcing articles via

pirat.ly.
This commit is contained in:
Grischa Brockhaus 2012-11-03 13:33:00 +01:00
parent 7424e09a72
commit c290734a01
7 changed files with 40 additions and 9 deletions

View file

@ -8,6 +8,10 @@ TODO:
* Twitter announcements/credentials etc. per author instead of
only per central blog
1.47 (brockhaus)
--------------------------
* Added API token functionality for announcing articles via pirat.ly.
1.46 (brockhaus)
--------------------------
* Check tweetbacks (search) converted to API 1.1 (optional). You need to choose an OAuth acc handling the search.

View file

@ -143,6 +143,9 @@
@define('PLUGIN_EVENT_TWITTER_ANNOUNCE_BITLYLOGIN', 'bit.ly Benutzername');
@define('PLUGIN_EVENT_TWITTER_ANNOUNCE_BITLYAPIKEY', 'bit.ly API Key');
@define('PLUGIN_EVENT_TWITTER_ANNOUNCE_PIRATLYDESC', '<h3>pirat.ly API Token</h3>Für <b>pirat.ly</b> KurzURLs kannst Du Dir ein API token abholen, <a href="http://pirat.ly/account" target="_blank">indem Du Dich kostenlos bei dem Service registrierst</a>. Wenn das API Token bei der Artikel Ankündigung verwendet wird, kannst Du die Klick Raten der URL über das piratly Webinterface oder auf dem Android Handy mittels der <a href="http://pirat.ly/shortenerrr" target="_blank">Shortenerrr App</a> beobachten.');
@define('PLUGIN_EVENT_TWITTER_ANNOUNCE_PIRATLYAPIKEY', 'Dein persönliches piratly API Token');
@define('PLUGIN_EVENT_TWITTER_CFGTAB_TWEETTHIS', 'Tweet This!');
@define('PLUGIN_EVENT_TWITTER_TWEETTHIS_TITLE', 'Tweet This!');
@define('PLUGIN_EVENT_TWITTER_DO_TWEETTHIS', 'Tweet This! benutzen');

View file

@ -14,12 +14,18 @@ class UrlShortener {
var $bitly_login = 'bitlyapidemo';
var $bitly_apikey = 'R_0da49e0a9118ff35f52f629d2d71bf07';
var $piratly_apikey = "0"; // This is the generic API token representing anonymous user
function setBitlyLogin($login, $apikey) {
if (empty($login) || empty($apikey)) return;
$this->bitly_login = $login;
$this->bitly_apikey = $apikey;
}
function setPiratlyToken($apitoken) {
if (empty($apitoken)) return;
$this->piratly_apikey = $apitoken;
}
/**
* Fills up the shorturls hash with shorturls identified by service name.
*/
@ -121,7 +127,7 @@ class UrlShortener {
function shorten_via_piratly( $url, &$shorturls ) {
$url = urlencode($url);
UrlShortener::shorten_via_simple($shorturls, 'piratly', "http://pirat.ly/shortener/createplain/0/?$url");
UrlShortener::shorten_via_simple($shorturls, 'piratly', "http://pirat.ly/shortener/api/createplain/{$this->piratly_apikey}/?$url");
}
// is.gd returns different short urls for same URL! How to handle this?!

View file

@ -143,6 +143,9 @@
@define('PLUGIN_EVENT_TWITTER_ANNOUNCE_BITLYLOGIN', 'bit.ly Benutzername');
@define('PLUGIN_EVENT_TWITTER_ANNOUNCE_BITLYAPIKEY', 'bit.ly API Key');
@define('PLUGIN_EVENT_TWITTER_ANNOUNCE_PIRATLYDESC', '<h3>pirat.ly API Token</h3>Für <b>pirat.ly</b> KurzURLs kannst Du Dir ein API token abholen, <a href="http://pirat.ly/account" target="_blank">indem Du Dich kostenlos bei dem Service registrierst</a>. Wenn das API Token bei der Artikel Ankündigung verwendet wird, kannst Du die Klick Raten der URL über das piratly Webinterface oder auf dem Android Handy mittels der <a href="http://pirat.ly/shortenerrr" target="_blank">Shortenerrr App</a> beobachten.');
@define('PLUGIN_EVENT_TWITTER_ANNOUNCE_PIRATLYAPIKEY', 'Dein persönliches piratly API Token');
@define('PLUGIN_EVENT_TWITTER_CFGTAB_TWEETTHIS', 'Tweet This!');
@define('PLUGIN_EVENT_TWITTER_TWEETTHIS_TITLE', 'Tweet This!');
@define('PLUGIN_EVENT_TWITTER_DO_TWEETTHIS', 'Tweet This! benutzen');

View file

@ -143,6 +143,9 @@
@define('PLUGIN_EVENT_TWITTER_ANNOUNCE_BITLYLOGIN', 'bit.ly username');
@define('PLUGIN_EVENT_TWITTER_ANNOUNCE_BITLYAPIKEY', 'bit.ly API key');
@define('PLUGIN_EVENT_TWITTER_ANNOUNCE_PIRATLYDESC', '<h3>pirat.ly API token</h3>For <b>pirat.ly</b> shorturls you can <a href="http://pirat.ly/account" target="_blank">get an API token by registering for free at the piratly service</a>. By using this API token when announcing your articles you can watch the clickrate on the web interface or on your Android mobile using the <a href="http://pirat.ly/shortenerrr" target="_blank">Shortenerrr app</a>.');
@define('PLUGIN_EVENT_TWITTER_ANNOUNCE_PIRATLYAPIKEY', 'Your personal piratly API token');
@define('PLUGIN_EVENT_TWITTER_CFGTAB_TWEETTHIS', 'Tweet This!');
@define('PLUGIN_EVENT_TWITTER_TWEETTHIS_TITLE', 'Tweet This!');
@define('PLUGIN_EVENT_TWITTER_DO_TWEETTHIS', 'Enable Tweet This!');

View file

@ -1,4 +1,4 @@
<?php
// Actual version of both plugins
@define('PLUGIN_TWITTER_VERSION', '1.46');
@define('PLUGIN_TWITTER_VERSION', '1.47');

View file

@ -87,7 +87,7 @@ class serendipity_event_twitter extends serendipity_plugin {
$config_announce = array(
'announce_articles_title', 'announce_articles', 'announce_via_accounts',
'announce_format', 'announce_with_tags', 'anounce_url_service', 'announce_articles_default_no',
'announce_bitly_description', 'announce_bitly_login','announce_bitly_apikey'
'announce_bitly_description', 'announce_bitly_login','announce_bitly_apikey','announce_piratly_description', 'announce_piratly_apikey'
);
$config_twitter = array(
@ -484,7 +484,17 @@ class serendipity_event_twitter extends serendipity_plugin {
$propbag->add('default', 'R_0da49e0a9118ff35f52f629d2d71bf07');
break;
// Tweetbacks
case 'announce_piratly_description':
$propbag->add('type', 'content');
$propbag->add('default', PLUGIN_EVENT_TWITTER_ANNOUNCE_PIRATLYDESC);
break;
case 'announce_piratly_apikey':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_EVENT_TWITTER_ANNOUNCE_PIRATLYAPIKEY);
$propbag->add('default', '0');
break;
// Tweetbacks
case 'twitter_api' :
$apis = array(
'api10' => PLUGIN_EVENT_TWITTER_API_10,
@ -727,12 +737,14 @@ class serendipity_event_twitter extends serendipity_plugin {
function get_urlshortener() {
$urlshortener = new UrlShortener();
$login = $this->get_config('announce_bitly_login');
$apikey = $this->get_config('announce_bitly_apikey');
$this->log("blogin:" . $login . " bapi: " . $apikey);
$urlshortener->setBitlyLogin($login, $apikey);
$bitlylogin = $this->get_config('announce_bitly_login');
$bitlyapikey = $this->get_config('announce_bitly_apikey');
$piratlyapikey = $this->get_config('announce_piratly_apikey','0');
$this->log("blogin:" . $bitlylogin . " bapi: " . $bitlyapikey);
$urlshortener->setBitlyLogin($bitlylogin, $bitlyapikey);
$this->log("slogin:" . $urlshortener->bitly_login . " sapi: " . $urlshortener->bitly_apikey);
return $urlshortener;
$urlshortener->setPiratlyToken($piratlyapikey);
return $urlshortener;
}
function generate_content(&$title) {