[Mapbender-commits] r5574 - trunk/mapbender/http/plugins
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Sat Feb 20 10:02:40 EST 2010
Author: christoph
Date: 2010-02-20 10:02:40 -0500 (Sat, 20 Feb 2010)
New Revision: 5574
Modified:
trunk/mapbender/http/plugins/mb_cookie.js
trunk/mapbender/http/plugins/mb_twitter.php
trunk/mapbender/http/plugins/mb_twitter_signin.js
Log:
Modified: trunk/mapbender/http/plugins/mb_cookie.js
===================================================================
--- trunk/mapbender/http/plugins/mb_cookie.js 2010-02-20 14:57:13 UTC (rev 5573)
+++ trunk/mapbender/http/plugins/mb_cookie.js 2010-02-20 15:02:40 UTC (rev 5574)
@@ -60,7 +60,9 @@
cookieExists = true;
var storedMapState = $.parseJSON('(' + cookieData[i].replace(cookieName + '=','') + ')');
-
+ if (!storedMapState) {
+ return;
+ }
currentMapState.epsg = storedMapState.epsg;
var currentWmsLayers = [];
Modified: trunk/mapbender/http/plugins/mb_twitter.php
===================================================================
--- trunk/mapbender/http/plugins/mb_twitter.php 2010-02-20 14:57:13 UTC (rev 5573)
+++ trunk/mapbender/http/plugins/mb_twitter.php 2010-02-20 15:02:40 UTC (rev 5574)
@@ -23,17 +23,45 @@
$ajaxResponse->send();
}
+function isSignedIn ($token = null) {
+ global $Twitter;
+
+ if (!is_null($token)) {
+ try {
+ $Twitter->setToken($token);
+ $accessToken = $Twitter->getAccessToken();
+ Mapbender::session()->set("twitter_token", $accessToken->oauth_token);
+ Mapbender::session()->set("twitter_token_secret", $accessToken->oauth_token_secret);
+ }
+ catch (Exception $e) {
+ Mapbender::session()->delete("twitter_token");
+ Mapbender::session()->delete("twitter_token_secret");
+ return false;
+ }
+ }
+
+ if (Mapbender::session()->exists("twitter_token") && Mapbender::session()->exists("twitter_token_secret")) {
+ $Twitter->setToken(
+ Mapbender::session()->exists("twitter_token"),
+ Mapbender::session()->exists("twitter_token_secret")
+ );
+ return true;
+
+ }
+ return false;
+}
+
$Twitter = new EpiTwitter($consumerKey, $consumerSecret);
switch ($ajaxResponse->getMethod()) {
case "isSignedIn" :
$token = $ajaxResponse->getParameter("token");
- if (!is_null($token)) {
- $ajaxResponse->setSuccess(true);
+
+ if (isSignedIn($token)) {
$ajaxResponse->setResult(array("signedIn" => true));
$ajaxResponse->setMessage(_mb("Signed in."));
$ajaxResponse->send();
- }
+ }
$ajaxResponse->setResult(array("signedIn" => false));
$ajaxResponse->setMessage(_mb("Not signed in."));
@@ -55,20 +83,21 @@
break;
case "signout" :
- try {
- $url = $Twitter->getAuthenticateUrl();
- }
- catch (Exception $e) {
- $ajaxResponse->setSuccess(false);
- $ajaxResponse->setMessage(_mb("Could not connect to Twitter."));
- $ajaxResponse->send();
- }
+ Mapbender::session()->delete("twitter_token");
+ Mapbender::session()->delete("twitter_token_secret");
- $ajaxResponse->setResult(array("url" => $url));
+ $ajaxResponse->setResult(array("signedOut" => true));
+ $ajaxResponse->setMessage(_mb("Signed out."));
$ajaxResponse->setSuccess(true);
break;
case "update":
+ if (!isSignedId()) {
+ $ajaxResponse->setResult(array("signedIn" => false));
+ $ajaxResponse->setMessage(_mb("Not signed in."));
+ $ajaxResponse->setSuccess(true);
+ $ajaxResponse->send();
+ }
$Twitter = new EpiTwitter($consumerKey, $consumerSecret);
$status = $ajaxResponse->getParameter("status");
$lat = $ajaxResponse->getParameter("lat");
Modified: trunk/mapbender/http/plugins/mb_twitter_signin.js
===================================================================
--- trunk/mapbender/http/plugins/mb_twitter_signin.js 2010-02-20 14:57:13 UTC (rev 5573)
+++ trunk/mapbender/http/plugins/mb_twitter_signin.js 2010-02-20 15:02:40 UTC (rev 5574)
@@ -44,57 +44,65 @@
var $this = $(this);
-$this.mapbender({
- signedIn: false
-});
+var originalI18nObject = {
+ "logIn" : "Log in at Twitter",
+ "logOut" : "Log out at Twitter"
+};
-var getOauthToken = function () {
- var getString = document.location.search.substr(1,document.location.search.length);
- if (getString === '') {
- return null;
- }
+var translatedI18nObject = Mapbender.cloneObject(originalI18nObject);
- var gArr = getString.split('&');
- for (i = 0; i < gArr.length; ++i) {
- var v = '';
- vArr = gArr[i].split('=');
- if (vArr.length > 1) {
- v = vArr[1];
- }
- var key = unescape(vArr[0]);
- if (key === "oauth_token") {
- return unescape(v);
- }
- }
- return null;
-}
+var TwitterSignin = function (options) {
+ this.isSignedIn = function () {
+ var req = new Mapbender.Ajax.Request({
+ url: "../plugins/mb_twitter.php",
+ method: "isSignedIn",
+ parameters: {
+ token: getOauthToken()
+ },
+ callback: function (obj, result, message) {
+ if (!result) {
+ alert(message);
+ $this.text(translatedI18nObject.logIn);
+ return;
+ }
+ if (obj.signedIn) {
+ alert(message);
+ $this.text(translatedI18nObject.logOut);
+ }
+ $this.mapbender("signedIn", obj.signedIn);
+ }
+ });
+ req.send();
+
+ };
+
+ this.signedIn = false;
-Mapbender.events.init.register(function () {
-
- // check if signed in
- var req = new Mapbender.Ajax.Request({
- url: "../plugins/mb_twitter.php",
- method: "isSignedIn",
- parameters: {
- token: getOauthToken()
- },
- callback: function (obj, result, message) {
- if (!result) {
- alert(message);
- return;
+ var getOauthToken = function () {
+ var getString = document.location.search.substr(1,document.location.search.length);
+ if (getString === '') {
+ return null;
+ }
+
+ var gArr = getString.split('&');
+ for (i = 0; i < gArr.length; ++i) {
+ var v = '';
+ vArr = gArr[i].split('=');
+ if (vArr.length > 1) {
+ v = vArr[1];
}
- if (obj.signedIn) {
- alert(message);
+ var key = unescape(vArr[0]);
+ if (key === "oauth_token") {
+ return unescape(v);
}
- $this.mapbender("signedIn", obj.signedIn);
- alert($this.mapbender("signedIn"));
}
- });
- req.send();
+ return null;
+ };
-
$this.click(function () {
+
+
var req = new Mapbender.Ajax.Request({
url: "../plugins/mb_twitter.php",
method: "signin",
@@ -111,5 +119,32 @@
}
});
req.send();
+ });
+
+};
+
+$this.mapbender(new TwitterSignin());
+
+Mapbender.events.init.register(function () {
+ // check if signed in
+ $this.mapbender(function () {
+ this.isSignedIn();
});
-});
+
+ Mapbender.events.localize.register(function () {
+ Mapbender.modules.i18n.queue(options.id, originalI18nObj, function (translatedObj) {
+ if (typeof translatedObj !== "object") {
+ return;
+ }
+ translatedI18nObj = translatedObj;
+ try {
+ $this.mapbender(function () {
+ this.isSignedIn();
+ });
+ }
+ catch (exc) {
+ new Mb_warning("Error when translating: " . exc.message);
+ }
+ });
+ });
+});
\ No newline at end of file
More information about the Mapbender_commits
mailing list