1
0

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

This commit is contained in:
Bharat Mediratta 2011-04-10 15:13:44 -07:00
commit bfa56061fe
5 changed files with 90 additions and 12 deletions

View File

@ -8,8 +8,15 @@ SUPPORT/BUG REPORTS:
http://gallery.menalto.com/node/100791
ROADMAP:
* Provide a reset access token button on the user's profile.
* Display Twitter profile/follow links on Gallery user profile pages.
* Provide "Share on Twitter" for anonymous users.
* Display item (re)tweets.
* Twitter identity provider (log into Gallery with Twitter)
HISTORY:
2011-03-15 - 1 beta2
- Allow users to change from one Twitter account to another from their profile page.
- Compose Tweet JavaScript widget fixes to read default options, accept custom widget options.
- Disable the "Tweet" button if the message is over 140 characters.
- Truncate default tweet values longer than 140.
2011-02-15 - 1 beta1

View File

@ -133,6 +133,27 @@ class Twitter_Controller extends Controller {
}
}
/**
* Reset a user's Twitter OAuth access token
* @param int $user_id
*/
public function reset($user_id) {
if (identity::active_user()->id == $user_id) {
$u = ORM::factory("twitter_user")->where("user_id", "=", $user_id)->find();
if ($u->loaded()) {
$u->oauth_token = "";
$u->oauth_token_secret = "";
$u->twitter_user_id = "";
$u->screen_name = "";
$u->save();
message::success(t("Your Twitter access token has been reset."));
Session::instance()->set("twitter_item_redirect",
url::abs_site("user_profile/show/{$user_id}"));
url::redirect("twitter/redirect");
}
}
}
/**
* Post a status update to Twitter
* @param int $item_id
@ -238,17 +259,20 @@ class Twitter_Controller extends Controller {
/**
* Save or update the current user's Twitter credentials.
* @param array $access_token
* @todo Ensure only one record per twitter_screen_name
*/
private function _save_user($access_token) {
$u = ORM::factory("twitter_user");
$u = ORM::factory("twitter_user")
->where("user_id", "=", identity::active_user()->id)
->find();
if (!$u->loaded()) {
$u = ORM::factory("twitter_user");
}
$u->oauth_token = $access_token["oauth_token"];
$u->oauth_token_secret = $access_token["oauth_token_secret"];
$u->twitter_user_id = $access_token["user_id"];
$u->screen_name = $access_token["screen_name"];
$u->user_id = identity::active_user()->id;
$u->save();
message::success(t("Success! You may now share Gallery items on Twitter."));
}

View File

@ -20,6 +20,8 @@
class twitter_Core {
static $test_mode = TEST_MODE;
static $url = "http://twitter.com/";
static $character_count = 140;
@ -60,7 +62,6 @@ class twitter_Core {
* Get tweet form
* @param object $item
* @return Forge
* @todo Truncate the $tweet at 140 - strlen($url)
*/
static function get_tweet_form($item) {
$long_url = url::abs_site($item->relative_url_cache);
@ -77,7 +78,8 @@ class twitter_Core {
$tweet = preg_replace("/%title/", $item->title, $tweet);
$tweet = preg_replace("/%description/", $item->description, $tweet);
// If bit.ly module's enabled, get the item's URL and shorten it
if (!empty($item->id) && module::is_active("bitly") && module::get_var("twitter", "shorten_urls")) {
if (!empty($item->id) && module::is_active("bitly")
&& module::get_var("twitter", "shorten_urls")) {
$url = bitly::shorten_url($item->id);
} else {
$url = url::abs_site($item->relative_url_cache);

View File

@ -49,5 +49,37 @@ class twitter_event_Core {
->url(url::site("twitter/dialog/{$item->id}")));
}
}
/**
* Add Twitter account info to user profiles
* @param object $data
*/
static function show_user_profile($data) {
$twitter_account = ORM::factory("twitter_user")->where("user_id", "=", $data->user->id)->find();
if ($twitter_account->loaded()) {
$v = new View("user_profile_info.html");
$v->user_profile_data = array();
$fields = array(
"screen_name" => t("Screen name")
);
foreach ($fields as $field => $label) {
if (!empty($twitter_account->$field)) {
$value = $twitter_account->$field;
if ($field == "screen_name") {
$value = html::mark_clean(html::anchor(twitter::$url .
$twitter_account->screen_name,
"@{$twitter_account->screen_name}"));
}
$v->user_profile_data[(string) $label] = $value;
}
}
if (identity::active_user()->id == $data->user->id) {
$button = html::mark_clean(html::anchor(url::site("twitter/reset/"
. $data->user->id), t("Switch to another Twitter screen name")));
$v->user_profile_data[""] = $button;
}
$data->content[] = (object) array("title" => t("Twitter account"), "view" => $v);
}
}
}

View File

@ -1,23 +1,36 @@
/**
* @todo Add shorten/expand urls toggle button
*/
(function($) {
$.widget("ui.gallery_twitter", {
_init: function() {
var self = this;
this._set_count();
$(this.element).bind("keyup", this._set_count);
this.element.keyup(function(event) {
self._set_count(event.currentTarget);
return false;
});
},
_set_count: function() {
var self = this;
var character_array = $("#g-tweet").val().split("");
var count = character_array.length;
var remaining = 140 - count; //self.options.max_count - count;
var remaining = self.options.max_count - count;
var count_container = $("#g-twitter-character-count");
var color = "#000000";
var warn_color = "#7F0005"; //this.options.warn_color;
var error_color = "#FF0000"; //this.options.error_color;
if (remaining < 10) {
color = error_color;
color = self.options.error_color;
} else if (remaining < 20) {
color = warn_color;
color = self.options.warn_color;
}
if (remaining < 0) {
$("#g-dialog form :submit").addClass("ui-state-disabled")
.attr("disabled", "disabled");
} else {
$("#g-dialog form :submit").removeClass("ui-state-disabled")
.attr("disabled", null);
}
$(count_container).css("color", color);
$(count_container).html(remaining);