From dbf31cd3207b7a2b1b9617d75224a77409abcee7 Mon Sep 17 00:00:00 2001 From: Chad Kieffer Date: Tue, 28 Dec 2010 21:15:09 -0700 Subject: [PATCH] Don't show shorten link if the link's already short! Only show the shorten link to the item's owner. --- 3.1/modules/bitly/controllers/admin_bitly.php | 2 +- 3.1/modules/bitly/helpers/bitly.php | 12 +++++++ 3.1/modules/bitly/helpers/bitly_event.php | 33 +++++++++++-------- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/3.1/modules/bitly/controllers/admin_bitly.php b/3.1/modules/bitly/controllers/admin_bitly.php index f4240a63..8576c9d7 100644 --- a/3.1/modules/bitly/controllers/admin_bitly.php +++ b/3.1/modules/bitly/controllers/admin_bitly.php @@ -85,7 +85,7 @@ class Admin_Bitly_Controller extends Admin_Controller { if ($valid_config) { $link = ORM::factory("bitly_link")->where("item_id", "=", 1)->find(); if ($link->loaded()) { - $view->content->g3_url = "http://" . module::get_var("bitly", "domain") . "/$link->hash"; + $view->content->g3_url = bitly::bitly_link($link->hash); } else { $view->content->g3_url = bitly::shorten_url(1); } diff --git a/3.1/modules/bitly/helpers/bitly.php b/3.1/modules/bitly/helpers/bitly.php index 2ba90670..f89093e8 100644 --- a/3.1/modules/bitly/helpers/bitly.php +++ b/3.1/modules/bitly/helpers/bitly.php @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class bitly_Core { + public static $test_mode = TEST_MODE; public static $api_host = "api.bit.ly"; @@ -207,4 +208,15 @@ class bitly_Core { } } + /** + * Build a bit.ly link for a specified hash + * @param string $hash + * @return string + */ + static function bitly_link($hash) { + if (!empty($hash)) { + return "http://" . module::get_var("bitly", "domain") . "/$hash"; + } + } + } diff --git a/3.1/modules/bitly/helpers/bitly_event.php b/3.1/modules/bitly/helpers/bitly_event.php index 29463606..86c970f3 100644 --- a/3.1/modules/bitly/helpers/bitly_event.php +++ b/3.1/modules/bitly/helpers/bitly_event.php @@ -18,6 +18,9 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class bitly_event_Core { + + public static $shorten_link_text = "Shorten link with bit.ly"; + static function admin_menu($menu, $theme) { $menu->get("settings_menu") ->append(Menu::factory("link") @@ -27,23 +30,25 @@ class bitly_event_Core { } static function site_menu($menu, $theme) { - if ($theme->item->owner->id == identity::active_user()->id) { - $menu->get("options_menu") - ->append(Menu::factory("link") - ->id("bitly") - ->label(t("Shorten link with bit.ly")) - ->url(url::site("bitly/shorten/{$theme->item->id}?csrf=$theme->csrf")) - ->css_id("g-bitly-link") - ->css_class("g-bitly-shorten ui-icon-link")); - } - } - - static function context_menu($menu, $theme, $item) { - if ($theme->item->owner->id == identity::active_user()->id) { + $link = ORM::factory("bitly_link")->where("item_id", "=", $theme->item->id)->find(); + if (!$link->loaded() && $theme->item->owner->id == identity::active_user()->id) { $menu->get("options_menu") ->append(Menu::factory("link") ->id("bitly") - ->label(t("Shorten link with bit.ly")) + ->label(t(self::$shorten_link_text)) + ->url(url::site("bitly/shorten/{$theme->item->id}?csrf=$theme->csrf")) + ->css_id("g-bitly-shorten") + ->css_class("g-bitly-shorten ui-icon-link")); + } + } + + static function context_menu($menu, $theme, $item) { + $link = ORM::factory("bitly_link")->where("item_id", "=", $item->id)->find(); + if (!$link->loaded() && $theme->item->owner->id == identity::active_user()->id) { + $menu->get("options_menu") + ->append(Menu::factory("link") + ->id("bitly") + ->label(t(self::$shorten_link_text)) ->url(url::site("bitly/shorten/$item->id?csrf=$theme->csrf")) ->css_class("g-bitly-shorten ui-icon-link")); }