From aaa79da07e054918ac3606d5088608663f74d8be Mon Sep 17 00:00:00 2001 From: Clem Davies Date: Mon, 7 Jul 2014 17:35:55 +0800 Subject: [PATCH 1/3] Added bit.ly functionality to official twitter --- digg-digg/include/dd-class.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/digg-digg/include/dd-class.php b/digg-digg/include/dd-class.php index 6773bc5..9bd2169 100644 --- a/digg-digg/include/dd-class.php +++ b/digg-digg/include/dd-class.php @@ -314,6 +314,35 @@ public function DD_Twitter() { } public function constructURL($url, $title,$button, $postId, $lazy, $globalcfg = ''){ + + + //mod start bitly + $long_url = $url; + $short_url = null; + $bitly_key = $globalcfg[DD_GLOBAL_TWITTER_OPTION][DD_GLOBAL_TWITTER_OPTION_BITLY_KEY]; + if ( !is_null($bitly_key) && strlen($bitly_key) > 0 && ctype_alnum($bitly_key) ) { + // alphanumeric keys only + // use bitly api to retrieve shortened url + $bitly_url = 'https://api-ssl.bitly.com/v3/shorten?access_token='.$bitly_key.'&longUrl='.urlencode($long_url); + + $bitly_object = json_decode(file_get_contents($bitly_url)); + if ( is_object($bitly_object) && property_exists($bitly_object,'data') && + is_object($bitly_object->data) && property_exists($bitly_object->data,'url') && + is_string($bitly_object->data->url)) { + $short_url = $bitly_object->data->url; + } + + if (!is_null($short_url)) { + // short_url successfully retrieved + $this->baseURL = str_replace('data-url=', "data-counturl=\"".$long_url."\" data-url=", $this->baseURL); + $url = $short_url; + } + } + /* if successful + $url = contains bit.ly representation of passed url + and the tweet counter is now counting the full url and not the bit.ly url. Which usually doesnt count properly. + */ + //mod end bitly if($this->isEncodeRequired){ $title = rawurlencode($title); From 6226890f1fab6861cc04dc7330cafbb47e6305a1 Mon Sep 17 00:00:00 2001 From: Clem Davies Date: Mon, 7 Jul 2014 17:36:36 +0800 Subject: [PATCH 2/3] Added bit.ly functionality to official twitter --- digg-digg/include/dd-global-variable.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/digg-digg/include/dd-global-variable.php b/digg-digg/include/dd-global-variable.php index 9dddd9e..c0b105f 100644 --- a/digg-digg/include/dd-global-variable.php +++ b/digg-digg/include/dd-global-variable.php @@ -150,10 +150,17 @@ define('DD_GLOBAL_FLATTR_OPTION','dd_global_flattr_option'); define('DD_GLOBAL_FLATTR_OPTION_UID','dd_global_flattr_option_uid'); +//mod start bitly +define('DD_GLOBAL_TWITTER_OPTION_BITLY_KEY', 'dd_global_twitter_option_bitly_key'); +//mod end bitly + global $ddGlobalConfig; $ddGlobalConfig = array( DD_GLOBAL_TWITTER_OPTION => array( - DD_GLOBAL_TWITTER_OPTION_SOURCE => DD_EMPTY_VALUE + DD_GLOBAL_TWITTER_OPTION_SOURCE => DD_EMPTY_VALUE, + //mod start bitly + DD_GLOBAL_TWITTER_OPTION_BITLY_KEY => DD_EMPTY_VALUE + //mod end bitly ), DD_GLOBAL_BUFFER_OPTION => array( DD_GLOBAL_BUFFER_OPTION_SOURCE => DD_EMPTY_VALUE @@ -345,4 +352,4 @@ /******* * Digg Digg Floating Display (End) ****************************************/ -?> \ No newline at end of file +?> From 94cf700a9716247a09ada5d6529d75003011f010 Mon Sep 17 00:00:00 2001 From: Clem Davies Date: Mon, 7 Jul 2014 17:38:08 +0800 Subject: [PATCH 3/3] Added bit.ly functionality to official twitter --- .../include/template/dd-template-global.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/digg-digg/include/template/dd-template-global.php b/digg-digg/include/template/dd-template-global.php index 895747d..5d03338 100644 --- a/digg-digg/include/template/dd-template-global.php +++ b/digg-digg/include/template/dd-template-global.php @@ -138,6 +138,21 @@ function dd_print_global_form($ddGlobalConfig){

This user will be @ mentioned in the suggested tweet.

+ + + 2.2 Tweet Shortened Urls Bit.ly Generic Access Token + + +

Leave blank to disable. Invalid keys will be ignored when page is rendered.

+
    +
  1. Go here for Generic Acess Token
  2. +
  3. Sign in or create an account
  4. +
  5. Click the Generate Token button
  6. +
  7. Copy and paste the token into the text field located above
  8. +
+ + +
@@ -290,4 +305,4 @@ function dd_print_global_form($ddGlobalConfig){
\ No newline at end of file +?>