Permalink
Browse files

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

  • Loading branch information...
bharat committed Feb 14, 2011
2 parents 782f837 + a5907ea commit 05d9cf5efd051bc6d2ccb874773023dbe0451bf3
View
@@ -0,0 +1,12 @@
+ABOUT:
+Shorten Gallery's album and item links using bit.ly's URL shortening service.
+
+INSTALLATION AND CONFIGURATION INSTRUCTIONS:
+http://codex.gallery2.org/Gallery3:Modules:bitly
+
+QUESTIONS, COMMENTS?
+http://2tbsp.com/content/bitly-module-gallery-3
+
+ROADMAP:
+- Provide multi-user support.
+- Display shortened link statistics (clicks, etc.)
@@ -33,8 +33,14 @@ public function shorten($item_id) {
access::required("view", $item);
access::required("edit", $item);
- // Get the item's URL and shorten it
+ // Shorten the item's URL
$short_url = bitly::shorten_url($item_id);
+
+ if ($short_url) {
+ message::success("Item URL shortened to $short_url");
+ } else {
+ message::error("Unable to shorten " . url::abs_site($item->relative_url_cache));
+ }
// Redirect back to the item
url::redirect(url::abs_site($item->relative_url_cache));
@@ -61,8 +61,8 @@ static function get_configure_form() {
/**
* Check a login and an API Key against bit.ly to make sure they're valid
- * @param string $login the login
- * @param string $api_key the API key
+ * @param string $login bit.ly login
+ * @param string $api_key bit.ly API key
* @return boolean
*/
static function validate_config($login, $api_key) {
@@ -115,15 +115,15 @@ static function check_config() {
}
/**
- *
- * @param <type> $type
- * @param <type> $parameters
+ * Assemble a bitly API request
+ * @param string $type Type of API request, ex. shorten
+ * @param array $params Query string key/value pairs
* @return string
*/
- private static function _build_http_request($type, $parameters) {
+ private static function _build_http_request($type, $params) {
$http_request = '';
- if (!empty($type) && count($parameters)) {
- foreach($parameters as $k => $v) {
+ if (!empty($type) && count($params)) {
+ foreach($params as $k => $v) {
$query_string[] = "$k=" . urlencode($v);
}
$path = "/" . self::$api_version . "/$type?" . implode('&', $query_string);
@@ -175,35 +175,30 @@ static function shorten_url($item_id, $format='json') {
$item = ORM::factory("item", $item_id);
$short_url = '';
$long_url = url::abs_site($item->relative_url_cache);
-
$parameters = array(
"login" => module::get_var("bitly", "login"),
'apiKey' => module::get_var("bitly", "api_key"),
'longUrl' => $long_url,
'domain' => module::get_var("bitly", "domain"),
'format' => $format,
);
-
$request = self::_build_http_request('shorten', $parameters);
$response = self::_http_post($request, self::$api_host);
$json_response = json_decode($response->body[0]);
+ $status_txt = $json_response->status_txt;
- if ('OK' == $json_response->status_txt) {
+ if ('OK' == $status_txt) {
$short_url = $json_response->data->url;
// Save the link hash to the database
$link = ORM::factory("bitly_link");
$link->item_id = $item_id;
$link->hash = $json_response->data->hash;
$link->global_hash = $json_response->data->global_hash;
$link->save();
-
- message::success("$long_url has been shortened to $short_url");
-
return $json_response->data->url;
-
} else {
- message::error("Unable to shorten $long_url");
- // @todo log the error
+ $status_code = $json_response->status_code;
+ log::error("content", "Shortened URL", "Error: $status_code $status_txt <a href=\"{$long_url}\">item</a>");
return false;
}
}
@@ -36,7 +36,7 @@ static function site_menu($menu, $theme) {
->label(t("Shorten link with bit.ly"))
->url(url::site("bitly/shorten/{$theme->item->id}?csrf={$theme->csrf}"))
->css_id("g-bitly-shorten")
- ->css_class("g-bitly-shorten ui-icon-link"));
+ ->css_class("g-bitly-shorten"));
}
}
@@ -0,0 +1,67 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2011 Bharat Mediratta
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+class Admin_Twitter_Controller extends Admin_Controller {
+
+ public $default_tweet;
+
+ function __construct() {
+ parent::__construct();
+ $this->default_tweet = t("Check out this %type, '%title': %description %url");
+ }
+
+ /**
+ * bit.ly module's settings
+ * @todo Show default tweet value after resetting it!
+ */
+ public function index() {
+ $form = twitter::get_configure_form();
+ if (request::method() == "post") {
+ access::verify_csrf();
+ if ($form->validate()) {
+ $consumer_key = $form->twitter_oauth->consumer_key->value;
+ $consumer_secret = $form->twitter_oauth->consumer_secret->value;
+ $reset_tweet = $form->twitter_message->reset_tweet->value;
+ if ($reset_tweet) {
+ $default_tweet = $this->default_tweet;
+ $form->twitter_message->default_tweet->value = $this->default_tweet;
+ } else {
+ $default_tweet = $form->twitter_message->default_tweet->value;
+ }
+ $shorten_urls = $form->urls->shorten_urls->value;
+
+ module::set_var("twitter", "consumer_key", $consumer_key);
+ module::set_var("twitter", "consumer_secret", $consumer_secret);
+ module::set_var("twitter", "default_tweet", $default_tweet);
+ module::set_var("twitter", "shorten_urls", $shorten_urls);
+ message::success("Twitter settings saved");
+ }
+ }
+ $is_registered = twitter::is_registered();
+
+ $v = new Admin_View("admin.html");
+ $v->page_title = t("Twitter");
+ $v->content = new View("admin_twitter.html");
+ $v->content->form = $form;
+ $v->content->is_registered = $is_registered;
+
+ print $v;
+ }
+
+}
Oops, something went wrong.

0 comments on commit 05d9cf5

Please sign in to comment.