Skip to content
Browse files

added bit.ly support to update links using the post permalink

  • Loading branch information...
1 parent dd0088e commit 29b9bf38fbd0451e078fd5ec592cf630652ffb73 @zagraves zagraves committed Oct 30, 2009
Showing with 66 additions and 6 deletions.
  1. +8 −1 yupdates_hooks.php
  2. +26 −5 yupdates_options.php
  3. +32 −0 yupdates_utils.php
View
9 yupdates_hooks.php
@@ -45,6 +45,13 @@ function yupdates_publish_post($postid) {
if($session->hasSession) {
$post = get_post($postid);
+ $permalink = get_permalink($postid);
+
+ $bitly_options = yupdates_get_bitly_options();
+ if($bitly_options->apiKey && $bitly_options->login) {
+ $bitly_permalink = yupdates_bitly_shorten($permalink, $bitly_options->apiKey, $bitly_options->login);
+ $permalink = $bitly_permalink;
+ }
$title_template = get_option("yupdates_title_template");
$title_patterns = array('/#blog_title/', '/#blog_name/');
@@ -53,7 +60,7 @@ function yupdates_publish_post($postid) {
$update = new stdclass();
$update->title = preg_replace($title_patterns, $title_replacements, $title_template);
$update->description = substr($post->post_content, 0, 256);
- $update->link = get_bloginfo("url");
+ $update->link = $permalink;
$response = $session->application->insertUpdate(null, $update->description, $update->title, $update->link);
View
31 yupdates_options.php
@@ -50,6 +50,8 @@ function yupdates_plugin_options() {
$ck = get_option('yupdates_consumer_key');
$cks = get_option('yupdates_consumer_secret');
$appid = get_option('yupdates_application_id');
+ $bitly_key = get_option("yupdates_bitly_apiKey");
+ $bitly_login = get_option("yupdates_bitly_login");
$title_template = get_option('yupdates_title_template');
if($title_template == "") $title_template = "posted '#blog_title' on their WordPress blog '#blog_name'";
@@ -99,8 +101,8 @@ function switchDisplay(obj) {
</tr>
</table>
- <p><em>Don't know what these are, or how to get them?</em> <a onclick="switchDisplay('ydnhelp');" title="Switch the Menu">S
- how/hide instructions for how to get a Yahoo! API key.</a> (It's quick and free.)</p>
+ <p><em>Don't know what these are, or how to get them?</em> <a onclick="switchDisplay('ydnhelp');" title="Switch the Menu">
+ Show/hide instructions for how to get a Yahoo! API key.</a> (It's quick and free.)</p>
<div id="ydnhelp" style="display:none; border: 1px solid #cccccc; margin: 10px; padding: 20px;">
@@ -144,8 +146,8 @@ function switchDisplay(obj) {
</ol>
</div>
-<hr noshade="noshade" />
- <h3 class="authTitle">Yahoo! Updates Settings</h3>
+ <hr noshade="noshade" />
+ <h3 class="authTitle">Yahoo! Updates Settings</h3>
<table class="form-table">
<tr valign="top">
<th scope="row">Customize your Yahoo! Updates event display:</th>
@@ -161,8 +163,27 @@ function switchDisplay(obj) {
</td>
</tr>
</table>
+
+ <hr noshade="noshade" />
+ <h3 class="authTitle">bit.ly Settings (optional)</h3>
+ Configure your <a href="http://bit.ly/account/">bit.ly account</a>. This allows us to shorten the link
+ back to your blog posts in the update, and allows you to track clicks in <a href="http://bit.ly/app/history/">your history</a>:
+ <?php if($bitly_key && $bitly_login) { ?>
+ <br/>To stop using bit.ly, just remove your credentials below and save.
+ <?php } ?>
+ <table class="form-table">
+ <tr valign="top">
+ <th scope="row">bit.ly API Key</th>
+ <td><input type="text" size="64" name="yupdates_bitly_apiKey" value="<?php echo $bitly_key; ?>" /></td>
+ </tr>
+ <tr valign="top">
+ <th scope="row">bit.ly Username</th>
+ <td><input type="text" size="20" name="yupdates_bitly_login" value="<?php echo $bitly_login; ?>" /></td>
+ </tr>
+ </table>
+
<input type="hidden" name="action" value="update" />
- <input type="hidden" name="page_options" value="yupdates_consumer_key,yupdates_consumer_secret,yupdates_application_id,yupdates_title_template" />
+ <input type="hidden" name="page_options" value="yupdates_consumer_key,yupdates_consumer_secret,yupdates_application_id,yupdates_title_template,yupdates_bitly_apiKey,yupdates_bitly_login" />
<p class="submit">
<input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" />
</p>
View
32 yupdates_utils.php
@@ -139,6 +139,38 @@ function yupdates_get_session($user=NULL) {
return $session;
}
+
+ function yupdates_get_bitly_options() {
+ $options = new stdclass();
+ $options->apiKey = get_option("yupdates_bitly_apiKey");
+ $options->login = get_option("yupdates_bitly_login");
+
+ return $options;
+ }
+
+ function yupdates_bitly_shorten($permalink, $apiKey, $login) {
+ $params = array();
+ $params["apiKey"] = $apiKey;
+ $params["login"] = $login;
+ $params["longUrl"] = $permalink;
+ $params["version"] = "2.0.1";
+ $params["history"] = "1";
+
+ $base_url = "http://api.bit.ly/shorten";
+
+ $http = YahooCurl::fetch($base_url, $params);
+ $rsp = $http["response_body"];
+ $data = json_decode($rsp);
+
+ if($data && $data->statusCode == "OK" && $data->results) {
+ $results = get_object_vars($data->results);
+ $site = $results[$permalink];
+ $shortUrl = $site->shortUrl;
+ return $shortUrl;
+ } else {
+ return $permalink;
+ }
+ }
function yupdates_close_popup() {
?>

0 comments on commit 29b9bf3

Please sign in to comment.
Something went wrong with that request. Please try again.