1
0

Merge branch 'master' of git://github.com/ckieffer/gallery3-contrib

This commit is contained in:
Bharat Mediratta 2010-12-29 22:26:02 -08:00
commit dff361c6bd
4 changed files with 54 additions and 38 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 = "http://" . module::get_var("bitly", "domain") . "/$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

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

View File

@ -18,32 +18,37 @@
* 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")
->id("bitly_menu")
->label(t("Bit.ly"))
->label(t("bit.ly"))
->url(url::site("admin/bitly")));
}
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"));
}

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>