Skip to content

Added bit.ly functionality to Official Twitter #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions digg-digg/include/dd-class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 9 additions & 2 deletions digg-digg/include/dd-global-variable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -345,4 +352,4 @@
/*******
* Digg Digg Floating Display (End)
****************************************/
?>
?>
17 changes: 16 additions & 1 deletion digg-digg/include/template/dd-template-global.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,21 @@ function dd_print_global_form($ddGlobalConfig){
<p>This user will be @ mentioned in the suggested tweet.</p>
</td>
</tr>
<!-- //mod start bitly -->
<tr valign="top">
<th scope="row">2.2 Tweet Shortened Urls Bit.ly Generic Access Token</th>
<td>
<input type="text" value="<?php echo $ddGlobalConfig[DD_GLOBAL_TWITTER_OPTION][DD_GLOBAL_TWITTER_OPTION_BITLY_KEY]; ?>" name="<?php echo DD_GLOBAL_TWITTER_OPTION_BITLY_KEY;?>" />
<p>Leave blank to disable. Invalid keys will be ignored when page is rendered.</p>
<ol>
<li><a href='https://bitly.com/a/oauth_apps' target='_blank'>Go here for Generic Acess Token</a></li>
<li>Sign in or create an account</li>
<li>Click the Generate Token button</li>
<li>Copy and paste the token into the text field located above</li>
</ol>
</td>
</tr>
<!-- //mod endbitly -->
</table>

<div class="submit">
Expand Down Expand Up @@ -290,4 +305,4 @@ function dd_print_global_form($ddGlobalConfig){
</div>
<?php
}
?>
?>