1
0

Don't attempt to shorten root album's URL if the module's not been configured yet.

This commit is contained in:
Chad Kieffer 2010-12-29 22:28:24 -07:00
parent 7077fd9d0b
commit 354ed39dcd
2 changed files with 22 additions and 23 deletions

View File

@ -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;
}

View File

@ -7,7 +7,7 @@
"bitly_url" => "http://bit.ly")) ?>
</p>
<div class="g-block-content">
<? if (!empty($login) && !empty($api_key) && $valid_config): ?>
<? if (!empty($g3_url)): ?>
<div class="g-module-status g-success">
<?= 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 <a href=\"%g3_url\">%g3_url</a>", array('g3_url' => $g3_url)) ?>
</div>