From 354ed39dcde9e9ea1ce5784ff3fd8d9cb13136c7 Mon Sep 17 00:00:00 2001
From: Chad Kieffer
Date: Wed, 29 Dec 2010 22:28:24 -0700
Subject: [PATCH] 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)) ?>