Renamed Photark Specific files

git-svn-id: https://svn.apache.org/repos/asf/incubator/photark/mobile/trunk@1376851 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/assets/www/scripts/photark_facebook.js b/assets/www/scripts/photark_facebook.js
new file mode 100644
index 0000000..5ab0572
--- /dev/null
+++ b/assets/www/scripts/photark_facebook.js
@@ -0,0 +1,103 @@
+
+if ((typeof cordova == 'undefined') && (typeof Cordova == 'undefined')) alert('Cordova variable does not exist. Check that you have included cordova.js correctly');
+if (typeof CDV == 'undefined') alert('CDV variable does not exist. Check that you have included cdv-plugin-fb-connect.js correctly');
+if (typeof FB == 'undefined') alert('FB variable does not exist. Check that you have included the Facebook JS SDK file.');
+					
+FB.Event.subscribe('auth.login', function(response) {
+	//alert('auth.login event');
+});
+					
+FB.Event.subscribe('auth.logout', function(response) {
+		   alert('auth.logout event');
+});
+					
+FB.Event.subscribe('auth.sessionChange', function(response) {
+		   alert('auth.sessionChange event');
+});
+					
+FB.Event.subscribe('auth.statusChange', function(response) {
+		   //alert('auth.statusChange event');
+});
+					
+function getLoginStatus() {
+		FB.getLoginStatus(function(response) {
+		if (response.status == 'connected') 
+		{
+			alert('logged in');
+		}
+		else 
+		{
+			alert('not logged in');
+		}
+	});
+}
+var fdata;
+var count=0;
+function me() {
+	if(count===0)
+	{
+		login();
+	}
+	FB.api('/me/photos?limit=8&offset='+count, { fields: 'id, name, picture' },  function(response) {
+	if (response.error) {
+	alert(JSON.stringify(response.error));
+	} 
+	else 
+	{
+			var data = document.getElementById('facebook');
+			$('#facebookMore').remove();
+			fdata=response.data;
+			response.data.forEach(function(item) {
+				var d = document.createElement('div');
+				if(item.name===undefined)
+				{
+					d.innerHTML = "<div class='cell'><a href="+"#"+"><img class='image' src="+item.picture+"/></a><br />"+"No caption"+"</div>";
+				}
+				else
+				{
+					d.innerHTML = "<div class='cell'><a href="+"#"+"><img class='image' src="+item.picture+"/></a><br />"+item.name.substr(0,20)+"..."+"</div>";
+				}
+				data.appendChild(d);
+			});
+	}
+	count=count+8;
+	//$('#facebook').append($('<a data-role="button" data-inline="true" data-direction="reverse" data-transition="fade" data-theme="a" href="#page1" data-icon="arrow-d" data-iconpos="right" id="facebookMore" class="more" data-role="button" data-icon="forward" onclick="me()" />').text('More..'));
+	$('#facebook').append('<a data-role="button" data-inline="true" data-theme="a" data-icon="arrow-d" data-iconpos="right" id="facebookMore" class="more" onclick="me()">More...</a>');
+   });
+}         
+function login() {
+	FB.login(
+		function(response) {
+			if (response.session) {
+				alert('logged in');
+			} 
+			else {
+				//alert('not logged in');
+			}
+		},
+		{ scope: "user_photos" }
+	);
+	//me();
+}            
+document.addEventListener('deviceready', function() {
+						  try {
+							  FB.init({ appId: "423746790989627", nativeInterface: CDV.FB, useCachedDialogs: false });
+						  } catch (e) {
+							  alert(e);
+						  }
+ }, false);
+$(document).ready(function(){
+	$('#facebookSwitch').off('change');
+	$("#facebook").empty();
+	$('#facebookSwitch').on('change', function()
+	{
+		if($(this).val()==="off")
+		{
+			$("#facebook").empty();
+		}
+		else
+		{
+			me();
+		}
+	});
+});
\ No newline at end of file
diff --git a/assets/www/scripts/photark_flickr.js b/assets/www/scripts/photark_flickr.js
new file mode 100644
index 0000000..cad9cb2
--- /dev/null
+++ b/assets/www/scripts/photark_flickr.js
@@ -0,0 +1,147 @@
+var mini_token="";
+var token='';
+var api_key="29faca132af9e790d4479d374871db9d";
+var secret="2038072bc6c01e24";
+var oath_token='';
+var oauth_token_secret='';
+var page=0;
+function get_userphotos(oauth_token,oauth_token_secret)
+{
+	page=page+1;
+	var foo = new Date; // Generic JS date object
+    var unixtime_ms = foo.getTime(); // Returns milliseconds since the epoch
+    var unixtime = parseInt(unixtime_ms / 1000);
+	var method='flickr.people.getPhotos';
+	var oauth_nonce=$.md5(unixtime.toString()+Math.floor((Math.random()*40)+1).toString());
+	console.log(oauth_nonce);
+	var baseSign = "GET" + "&" + encodeURIComponent("http://api.flickr.com/services/rest").toString() + "&"+encodeURIComponent("content_type") + "%3D" + encodeURIComponent('1')
+     + "%26"+ encodeURIComponent("format") + "%3D" + encodeURIComponent('json')
+     + "%26"
+	 + encodeURIComponent("method") + "%3D" + encodeURIComponent(method)
+	 + "%26"+ encodeURIComponent("nojsoncallback") + "%3D" + encodeURIComponent('1')
+	 + "%26"+ encodeURIComponent("oauth_consumer_key") + "%3D" + encodeURIComponent(api_key)
+     + "%26"
+     + encodeURIComponent("oauth_nonce") + "%3D" + encodeURIComponent(oauth_nonce)
+     + "%26"
+     + encodeURIComponent("oauth_signature_method") + "%3D" + encodeURIComponent("HMAC-SHA1")
+     + "%26"
+     + encodeURIComponent("oauth_timestamp") + "%3D" + encodeURIComponent(unixtime)
+	 + "%26"
+     + encodeURIComponent("oauth_token") + "%3D" + encodeURIComponent(oauth_token)
+     + "%26"
+     + encodeURIComponent("oauth_version") + "%3D" + encodeURIComponent("1.0")+ "%26"
+     + encodeURIComponent("page") + "%3D" + encodeURIComponent(page)+ "%26"
+     + encodeURIComponent("per_page") + "%3D" + encodeURIComponent('8')+ "%26"
+     + encodeURIComponent("user_id") + "%3D" + encodeURIComponent('me');
+	console.log(baseSign);
+	var secret_key=secret+'&'+oauth_token_secret;
+	console.log(secret_key);
+	var oauth_signature = encodeURIComponent(b64_hmac_sha1(secret_key, baseSign)+'=');
+	console.log(oauth_signature);
+	var url='http://api.flickr.com/services/rest?nojsoncallback=1&oauth_nonce='+oauth_nonce+'&format=json&oauth_consumer_key='+api_key+'&oauth_timestamp='+unixtime+'&oauth_signature_method=HMAC-SHA1&oauth_version=1.0&oauth_token='+oauth_token+'&user_id=me'+'&content_type=1'+'&per_page=8'+'&page='+page+'&oauth_signature='+oauth_signature+'&method='+method;
+	console.log(url);
+	$.ajax({
+		url:url,
+		success: function(data) {
+					$('#flickrMore').remove();
+					console.log(data);
+					photos_page_max = data.photos.pages;
+					console.log(photos_page_max);
+					data.photos.photo.forEach(function(item){
+						if(item.title===undefined)
+						{
+							('#flickr').append('<div class="cell"><a href='+"#"+'><img class="image" src="http://farm'+item.farm+'.staticflickr.com/'+item.server+'/'+item.id+'_'+item.secret+'_t.jpg" /></a><br />No Caption<br /></div>');
+						}
+						else
+						{
+							$('#flickr').append('<div class="cell"><a href='+"#"+'><img class="image" src="http://farm'+item.farm+'.staticflickr.com/'+item.server+'/'+item.id+'_'+item.secret+'_t.jpg" /></a><br />'+item.title.substr(0,20)+"..."+'<br /></div>');
+						}
+					});
+					console.log(page);
+					console.log(photos_page_max);
+					if(photos_page_max!=page)
+					{
+						$('#flickr').append($('<a data-role="button" data-inline="true" data-theme="a" data-icon="arrow-d" data-iconpos="right" id="flickrMore" class="more" onclick="get_userphotos(oauth_token,oauth_token_secret)" />').text('More..'));
+					}
+				},
+		error: function( error ){
+
+				    	// Log any error.
+						alert("ERROR:"+error.responseText);
+				    	console.log( "ERROR:"+error.responseText,error);
+
+				},
+		async:false
+	});
+}
+function oauth_get(auth_token)
+{
+	method = 'flickr.auth.oauth.getAccessToken';
+	sig_string=secret+'api_key'+api_key+'auth_token'+auth_token+'method'+method;
+	console.log(sig_string);
+	api_sig=$.md5(sig_string);
+	url='http://api.flickr.com/services/rest/'+'?method='+method+'&api_key='+api_key+'&auth_token='+auth_token+'&api_sig='+api_sig;
+	console.log(url); 
+	$.ajax({
+		url:url,
+		success: function(data) {
+					console.log(data);
+					oauth_token = $(data).find("access_token").attr('oauth_token');
+					oauth_token_secret = $(data).find("access_token").attr('oauth_token_secret');
+					console.log(oauth_token);
+					console.log(oauth_token_secret);
+				},
+		async:false
+	});
+	console.log(oauth_token);
+	console.log(oauth_token_secret);
+	get_userphotos(oauth_token,oauth_token_secret);
+}
+function mini_token_get()
+{
+	mini_token=prompt("What is the provided Flickr minitoken?");
+	if(mini_token.length===9)
+	{
+		var method = 'flickr.auth.getFullToken';
+		var sig_string=secret+'api_key'+api_key+'method'+method+'mini_token';
+		sig_string+=mini_token;
+		console.log(sig_string);
+		var api_sig=$.md5(sig_string);
+		var url='http://api.flickr.com/services/rest/'+'?method='+method+'&api_key='+api_key+'&mini_token='+mini_token+'&api_sig='+api_sig;//+'&format=json&nojsoncallback=1';
+		var full_token='';
+		console.log(url); 
+		$.ajax({
+			url:url,
+			success: function(data) {
+						console.log(data);
+						full_token = $(data).find("token").text();
+						console.log(full_token);
+					},
+			async:   false
+		});
+		console.log(full_token);
+		oauth_get(full_token);
+	}
+	else
+	{
+		alert("Enter correct Mini-Token");
+		mini_token_get();
+	}
+}
+
+$(document).ready(function() {
+	$('#flickrSwitch').off('change');
+	$("#flickr").empty();
+	$('#flickrSwitch').on('change', function()
+	{
+		if($(this).val()==="off")
+		{
+			$("#flickr").empty();
+		}
+		else
+		{
+			window.plugins.childBrowser.showWebPage("http://www.flickr.com/auth-72157630235879408", { showLocationBar: true });
+			window.plugins.childBrowser.onClose=mini_token_get;
+		}
+	});
+});
\ No newline at end of file
diff --git a/assets/www/scripts/photark_picasa.js b/assets/www/scripts/photark_picasa.js
new file mode 100644
index 0000000..15cdbc2
--- /dev/null
+++ b/assets/www/scripts/photark_picasa.js
@@ -0,0 +1,94 @@
+/*Picasa Connect*/
+var GOOGLE_AUTH_URL = "https://accounts.google.com/o/oauth2/auth";
+var GOOGLE_TOKEN_URL = "https://accounts.google.com/o/oauth2/token";
+var GOOGLE_CLIENT_ID = "694561233653-n00sia1lg2cces16024ac0nfuo37ulng.apps.googleusercontent.com";
+var GOOGLE_CLIENT_SECRET='qaMMEsUoGJz9OlB0p3yCc0xU';
+var PICASA_SCOPE = "https://picasaweb.google.com/data/";
+var redirect_uri='urn:ietf:wg:oauth:2.0:oob';
+var code='';
+var access_token='';
+var refresh_token='';
+var start=-7;
+function listing_photos(access_token,refresh_token){
+	start=start+8;
+	var photos_url='https://picasaweb.google.com/data/feed/api/user/default?kind=photo&thumbsize=104&max-results=8&start-index='+start+'&access_token='+access_token+'&fields=link[@rel="next"],entry(summary,media:group(media:thumbnail))';
+	console.log(photos_url);
+	$.ajax({
+		type: "GET",
+		url:photos_url,
+		contentType: 'application/x-www-form-urlencoded',
+		success: function(data) {
+					$('#picasaMore').remove();
+					$(data).find("entry").each(function()
+					{
+						if($(this).find('summary').text()==='')
+						{
+							$('#picasa').append('<div class="cell"><a href='+"#"+'><img class="image" src="'+$(this).find('thumbnail').attr('url')+'" /></a><br />No Caption<br /></div>');
+						}
+						else
+						{
+							console.log($(this).find('thumbnail').attr('url')+'----'+$(this).find('summary').text());
+							$('#picasa').append('<div class="cell"><a href='+"#"+'><img class="image" src="'+$(this).find('thumbnail').attr('url')+'" /><br />'+$(this).find('summary').text().substr(0,20)+"..."+'<br /></div>');
+						}
+					});
+					if($(data).find('link').attr('rel')!=undefined)
+					{
+						console.log($(data).find('link').attr('rel'));
+						$('#picasa').append($('<a data-role="button" data-inline="true" data-theme="a" data-icon="arrow-d" data-iconpos="right" id="picasaMore" class="more" onclick="listing_photos(access_token,refresh_token);" />').text('More..'));
+					}
+				},
+		error: function( error ){
+						// Log any error.
+						alert("ERROR:"+error.responseText);
+				    	console.log( "ERROR:"+error.responseText);
+						alert(JSON.stringify(error));
+				},
+		async:false
+	});
+}
+function get_accesstoken(){
+	code=prompt('Paste the authorization code received here.');
+	console.log(code);
+	var token_url=GOOGLE_TOKEN_URL;
+	var token_data='code='+encodeURIComponent(code)+'&redirect_uri='+encodeURIComponent(redirect_uri)+'&client_id='+encodeURIComponent(GOOGLE_CLIENT_ID)+'&scope='+'&client_secret='+encodeURIComponent(GOOGLE_CLIENT_SECRET)+'&grant_type=authorization_code';
+	console.log(token_url);
+	$.ajax({
+		type: "POST",
+		url:token_url,
+		contentType: 'application/x-www-form-urlencoded',
+		data: token_data,
+		success: function(data) {
+					console.log(data);
+					access_token=(data).access_token;
+					refresh_token=(data).refresh_token;
+					console.log(access_token);
+					console.log(refresh_token);
+					listing_photos(access_token,refresh_token);
+				},
+		error: function( error ){
+						// Log any error.
+						alert("ERROR:"+error.responseText);
+				    	console.log( "ERROR:"+error.responseText);
+						alert(JSON.stringify(error));
+				},
+		async:false
+	});
+}
+$(document).ready(function() {
+	$('#picasaSwitch').off('change');
+	$("#picasa").empty();
+	$('#picasaSwitch').on('change', function()
+	{
+		if($(this).val()==="off")
+		{
+			$("#picasa").empty();
+		}
+		else
+		{
+			var login_url=GOOGLE_AUTH_URL+'?scope='+PICASA_SCOPE+'&redirect_uri='+redirect_uri+'&response_type=code&client_id='+GOOGLE_CLIENT_ID+'&approval_prompt=force'+'&access_type=offline';
+			console.log(login_url);
+			window.plugins.childBrowser.showWebPage(login_url, { showLocationBar: true });
+			window.plugins.childBrowser.onClose=get_accesstoken;
+		}
+	});
+});