Permalink
Browse files

Moved status messages from helper to controller, shouldn't generate t…

…hem when other modules shorten links, i.e. Twitter, etc. Log bit.ly errors. Added README.
  • Loading branch information...
1 parent b7d8647 commit 00806139bb1ff97414b5a0914438749091795e07 @ckieffer ckieffer committed Feb 12, 2011
Showing with 12 additions and 7 deletions.
  1. +8 −1 3.1/modules/bitly/controllers/bitly.php
  2. +4 −6 3.1/modules/bitly/helpers/bitly.php
@@ -33,8 +33,15 @@ public function shorten($item_id) {
access::required("view", $item);
access::required("edit", $item);
- // Get the item's URL and shorten it
+ // Shorten the item's URL
$short_url = bitly::shorten_url($item_id);
+
+ if ($short_url) {
+ message::success("Item URL shortened to $short_url");
+ } else {
+
+ message::error("Unable to shorten " . url::abs_site($item->relative_url_cache));
+ }
// Redirect back to the item
url::redirect(url::abs_site($item->relative_url_cache));
@@ -187,23 +187,21 @@ static function shorten_url($item_id, $format='json') {
$request = self::_build_http_request('shorten', $parameters);
$response = self::_http_post($request, self::$api_host);
$json_response = json_decode($response->body[0]);
+ $status_txt = $json_response->status_txt;
- if ('OK' == $json_response->status_txt) {
+ if ('OK' == $status_txt) {
$short_url = $json_response->data->url;
// Save the link hash to the database
$link = ORM::factory("bitly_link");
$link->item_id = $item_id;
$link->hash = $json_response->data->hash;
$link->global_hash = $json_response->data->global_hash;
$link->save();
-
- message::success("$long_url has been shortened to $short_url");
-
return $json_response->data->url;
} else {
- message::error("Unable to shorten $long_url");
- // @todo log the error
+ $status_code = $json_response->status_code;
+ log::error("content", "Shortened URL", "Error: $status_code $status_txt <a href=\"{$long_url}\">item</a>");
return false;
}
}

0 comments on commit 0080613

Please sign in to comment.