From dbf31cd3207b7a2b1b9617d75224a77409abcee7 Mon Sep 17 00:00:00 2001
From: Chad Kieffer
Date: Tue, 28 Dec 2010 21:15:09 -0700
Subject: [PATCH 1/3] 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"));
}
From 7077fd9d0b47326af0aebb7f3a739cbfa6b9d1f9 Mon Sep 17 00:00:00 2001
From: Chad Kieffer
Date: Wed, 29 Dec 2010 21:37:22 -0700
Subject: [PATCH 2/3] The settings link label should be bit.ly instead of
Bit.ly.
---
3.1/modules/bitly/helpers/bitly_event.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/3.1/modules/bitly/helpers/bitly_event.php b/3.1/modules/bitly/helpers/bitly_event.php
index 86c970f3..899357ce 100644
--- a/3.1/modules/bitly/helpers/bitly_event.php
+++ b/3.1/modules/bitly/helpers/bitly_event.php
@@ -25,7 +25,7 @@ class bitly_event_Core {
$menu->get("settings_menu")
->append(Menu::factory("link")
->id("bitly_menu")
- ->label(t("Bit.ly"))
+ ->label(t("bit.ly"))
->url(url::site("admin/bitly")));
}
From 354ed39dcde9e9ea1ce5784ff3fd8d9cb13136c7 Mon Sep 17 00:00:00 2001
From: Chad Kieffer
Date: Wed, 29 Dec 2010 22:28:24 -0700
Subject: [PATCH 3/3] Don't attempt to shorten root album's URL if the module's
not been configured yet.
---
3.1/modules/bitly/controllers/admin_bitly.php | 43 +++++++++----------
3.1/modules/bitly/views/admin_bitly.html.php | 2 +-
2 files changed, 22 insertions(+), 23 deletions(-)
diff --git a/3.1/modules/bitly/controllers/admin_bitly.php b/3.1/modules/bitly/controllers/admin_bitly.php
index 8576c9d7..4f82f913 100644
--- a/3.1/modules/bitly/controllers/admin_bitly.php
+++ b/3.1/modules/bitly/controllers/admin_bitly.php
@@ -25,14 +25,14 @@ class Admin_Bitly_Controller extends Admin_Controller {
*/
public function index() {
$form = bitly::get_configure_form();
- $valid_config = true;
-
+ $login = module::get_var("bitly", "login");
+ $api_key = module::get_var("bitly", "api_key");
+ $domain = module::get_var("bitly", "domain");
+ $valid_config = false;
+
if (request::method() == "post") {
access::verify_csrf();
if ($form->validate()) {
- $current_login = module::get_var("bitly", "login");
- $current_key = module::get_var("bitly", "api_key");
- $current_domain = module::get_var("bitly", "domain");
$new_login = $form->configure_bitly->login->value;
$new_key = $form->configure_bitly->api_key->value;
$new_domain = $form->configure_bitly->domain->value;
@@ -44,24 +44,24 @@ class Admin_Bitly_Controller extends Admin_Controller {
if (!bitly::check_config()) {
url::redirect("admin/bitly");
} else {
- if ($current_login && !$new_login) {
+ if ($login && !$new_login) {
message::success(t("Your bit.ly login has been cleared."));
- } else if ($current_login && $new_login && $current_login != $new_login) {
+ } else if ($login && $new_login && $login != $new_login) {
message::success(t("Your bit.ly login has been changed."));
- } else if (!$current_login && $new_login) {
+ } else if (!$login && $new_login) {
message::success(t("Your bit.ly login has been saved."));
}
- if ($current_key && !$new_key) {
+ if ($api_key && !$new_key) {
message::success(t("Your bit.ly API key has been cleared."));
- } else if ($current_key && $new_key && $current_key != $new_key) {
+ } else if ($api_key && $new_key && $api_key != $new_key) {
message::success(t("Your bit.ly API key has been changed."));
- } else if (!$current_key && $new_key) {
+ } else if (!$api_key && $new_key) {
message::success(t("Your bit.ly API key has been saved."));
}
- if ($current_domain && $new_domain && $current_domain != $new_domain) {
+ if ($domain && $new_domain && $domain != $new_domain) {
message::success(t("Your preferrend bit.ly domain has been changed."));
- } else if (!$current_domain && $new_domain) {
- message::success(t("Your preferred bit.ly domain has been set."));
+ } else if (!$domain && $new_domain) {
+ message::success(t("Your preferred bit.ly domain has been saved."));
}
log::success("bitly", t("bit.ly login changed to %new_login",
array("new_login" => $new_login)));
@@ -79,17 +79,16 @@ class Admin_Bitly_Controller extends Admin_Controller {
$view->content->login = $form->configure_bitly->login->value;
$view->content->api_key = $form->configure_bitly->api_key->value;
$view->content->domain = $form->configure_bitly->domain->value;
- $view->content->valid_config = $valid_config;
$view->content->form = $form;
- if ($valid_config) {
- $link = ORM::factory("bitly_link")->where("item_id", "=", 1)->find();
- if ($link->loaded()) {
- $view->content->g3_url = bitly::bitly_link($link->hash);
- } else {
- $view->content->g3_url = bitly::shorten_url(1);
- }
+ $link = ORM::factory("bitly_link")->where("item_id", "=", 1)->find();
+
+ if ($link->loaded()) {
+ $view->content->g3_url = bitly::bitly_link($link->hash);
+ } else if ($valid_config && !empty($login) && !empty($api_key) && !empty($domain)) {
+ $view->content->g3_url = bitly::shorten_url(1);
}
+
print $view;
}
diff --git a/3.1/modules/bitly/views/admin_bitly.html.php b/3.1/modules/bitly/views/admin_bitly.html.php
index da84df54..d1d6703a 100644
--- a/3.1/modules/bitly/views/admin_bitly.html.php
+++ b/3.1/modules/bitly/views/admin_bitly.html.php
@@ -7,7 +7,7 @@
"bitly_url" => "http://bit.ly")) ?>
- if (!empty($login) && !empty($api_key) && $valid_config): ?>
+ if (!empty($g3_url)): ?>
= t("Your bit.ly login and API key are valid. Your Gallery URLs can now be shortened! This is the shortened URL for this Gallery
%g3_url", array('g3_url' => $g3_url)) ?>