KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache/2.4.62
System : FreeBSD fbsdweb2.web.rcn.net 14.1-RELEASE FreeBSD 14.1-RELEASE releng/14.1-n267679-10e31f0946d8 GENERIC amd64
User : www ( 80)
PHP Version : 8.3.8
Disable Function : NONE
Directory :  /domains/owens.enteract/inc/libs/photocropper/js/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /domains/owens.enteract/inc/libs/photocropper/js/photoapi.js
(function(window){
	
	/*
	Author:
	D. Ferrell
	Ted Perez + Associates
	*/
	
	/*
	 - Address photo scaling - CSS? Javascript?
	 - Limit to Facebook photos
	 - Method for instagram photo pull
	 - Determine photoQueryLimit, possibly pagination?  (Maybe store the last returned 'created' and use that in a follow-up query)


	TODO:
	//Get all of the user's photos
	SELECT object_id, aid, src_big, created, place_id FROM photo WHERE aid in (SELECT aid FROM album WHERE owner=me()) AND src_big != "" ORDER BY created

	//Get friends tagged in selected photo - requires friends_photos
	SELECT subject FROM photo_tag WHERE object_id = {*object_id*} AND subject != me();

	//get location from the selected photo
	SELECT name,latitude,longitude FROM place WHERE page_id = {*page_id"}

	//Get all friends tagged in all of the user's photos
	SELECT subject FROM photo_tag WHERE pid IN (SELECT pid, aid, src_big, created, caption_tags FROM photo WHERE aid in (SELECT aid FROM album WHERE owner=me()))
	*/

	//a class for loading / handling content
	
	function PhotoAPI(){};
	
	PhotoAPI.minWidth = 500;
	PhotoAPI.minHeight = 500;
	PhotoAPI.genericErrorMessage = "<p class='error'>Sorry, we were unable to find any photos.</p>";
	PhotoAPI.fbPermissionsDenied = "<p class='error'>We can't view your photos without permission!</p>";
	PhotoAPI.fbPhotoObj;
	PhotoAPI.fbNumPages;
	PhotoAPI.igPermissionsDenied = "<p class='error'>We can't view your photos without permission!</p>";
	PhotoAPI.igPhotoObj;
	PhotoAPI.igNumPages;
	PhotoAPI.photoSizeSQL = " AND (src_big_width >= "+ minWidth +" AND src_big_height >= "+ minHeight +") ";
	PhotoAPI.IgToken;
	PhotoAPI.photosPerPage = 12;
	PhotoAPI.photoQueryLimit = PhotoAPI.photosPerPage * 25;
	PhotoAPI.fql = "SELECT owner, object_id, aid, src_big, src_big_width, src_big_height, src, src_width, src_height, created, place_id ";
	PhotoAPI.fql += "FROM photo WHERE (aid in (SELECT aid FROM album WHERE owner=me()) ";
	PhotoAPI.fql += "OR pid IN (SELECT pid FROM photo_tag WHERE subject=me()) ) ";
	PhotoAPI.fql += PhotoAPI.photoSizeSQL;
	PhotoAPI.fql +=  'AND src_big != "" AND src != "" ORDER BY created DESC LIMIT '+PhotoAPI.photoQueryLimit;

	PhotoAPI.browser;

	
	/**
	-------------------------------------------------- FACEBOOK PHOTO API -------------------------------------------------------
	**/

	/**
	 * Request a specific page of photos from Facebook.  This is the only method that should be called by the user.
	 * @param pageNum The page number to be returned (0 index)
	 * @param cbFunc a callback function to be called on success.
	 */
	PhotoAPI.getFbPhotos = function(pageNum, cbFunc){
		if (!PhotoAPI.fbPhotoObj){
			//load the facebook photo object now.
			PhotoAPI.loadFacebookPhotos(pageNum, cbFunc);
			return;
		}
		//we have the fbPhotoObj now, so callback with the requested page's images
		PhotoAPI.callback(cbFunc, {status:'success', result:PhotoAPI.buildFacebookResults(pageNum), curPage:pageNum, totalPages:PhotoAPI.fbNumPages});

	}

	/**
	 * Load the user's photos from Facebook.
	 */
	PhotoAPI.loadFacebookPhotos = function(pageNum, cbFunc){
		//facebook user_photos permission is required.
		if (!FBUtil.hasPermission("user_photos")){
			//request permission, handle return
			requestLogin({scope:'user_photos'}, function(session, perms){
				
				//check for user_photos in returned perms
				if (session){
					if (perms.indexOf('user_photos') > -1){
						PhotoAPI.makeAuthorizedFacebookRequest(pageNum, cbFunc);
					} else {
						PhotoAPI.callback(cbFunc, {status:'error', result:PhotoAPI.fbPermissionsDenied});
					}
				} else {
					PhotoAPI.callback(cbFunc, {status:'error', result:PhotoAPI.fbPermissionsDenied});
				}
			});
		} else {
			PhotoAPI.makeAuthorizedFacebookRequest(pageNum, cbFunc);
		}
	}

	PhotoAPI.makeAuthorizedFacebookRequest = function(pageNum, cbFunc){
		FB.api({
				method: 'fql.query',
				query: PhotoAPI.fql
			},
			function(response) {
				if (response) {
					//check for errors
					if(response.error){
						PhotoAPI.callback(cbFunc, {status:'error', result:PhotoAPI.reportError(response.error.type + ": "+ response.error.message)});
					} else {
						PhotoAPI.fbPhotoObj = response;
						PhotoAPI.fbNumPages = Math.ceil(response.length / PhotoAPI.photosPerPage);
						PhotoAPI.callback(cbFunc, {status:'success', result:PhotoAPI.buildFacebookResults(pageNum), curPage:pageNum, totalPages:PhotoAPI.fbNumPages});
					}
				} else {
					//no response recieved, return generic error message
					PhotoAPI.callback(cbFunc, {status:'error', result:PhotoAPI.genericErrorMessage});
				}
			}
		);
	}

	/**
	 * Build the photo block from facebook results
	 */
	PhotoAPI.buildFacebookResults = function(pageNum){
		var photoStr = '';
		var myClass, posType, posVal, sizeType, sizeVal, data = PhotoAPI.fbPhotoObj;
		var maxItem = ((pageNum + 1) * PhotoAPI.photosPerPage > data.length) ? data.length : (pageNum + 1) * PhotoAPI.photosPerPage;
		for (var i = pageNum * PhotoAPI.photosPerPage; i < maxItem; i++){
			var fbPhotoDim = data[i].src_big_width + "x" + data[i].src_big_height;
			if (data[i].src_big_width > data[i].src_big_height){
				myClass = "cropped vert";
				sizeType = "min-width";
				sizeVal = Math.round(data[i].src_big_width * 93 / data[i].src_big_height);
				posType = "left";
				posVal = Math.round(46.5 - (sizeVal / 2));

			}else{
				myClass = "cropped horiz";
				sizeType = "height";
				sizeVal = Math.round(data[i].src_big_height * 93 / data[i].src_big_width);
				posType = "top";
				posVal = Math.round(46.5 - (sizeVal / 2));
			} 
			//apply the class for crop positioning, apply the data-source so we know it's from facebook, data-objid for friend tagging lookup, and apply the data-placeid for location lookup once selected. 
			photoStr += '<div class="button '+myClass+'" data-source="facebook" data-dim="'+ fbPhotoDim +'" data-url-large="'+ setProtocol(data[i].src_big) + '" data-objid="'+ data[i].object_id + '" data-placeid="'+data[i].place_id+'">';
			photoStr += '<div class="photoThumb"><img src="' + setProtocol(data[i].src_big) + '" style="'+posType+': '+posVal+'px; '+sizeType+': '+sizeVal+'px;" /></div>';
			photoStr += '</div>'
		}
		//console.log('photoStr: '+photoStr);
		return photoStr;
	}

	var setProtocol = function(url){
		/*if (!PhotoAPI.browser){
			try{
				if (jQuery.browser.mozilla){
					PhotoAPI.browser = "Firefox";
				} else {
					PhotoAPI.browser = "notFirefox";
				}
			}catch(er){
				PhotoAPI.browser = "notFirefox";
			}
		}
		if (PhotoAPI.browser == "Firefox"){
			return url.replace("https:","http:");
		} else {
			return url.replace("http:","https:");
		}*/
		return url.replace("https:","http:");
	}

	/**
	-------------------------------------------------- INSTAGRAM PHOTO API ------------------------------------------------------
	**/

	/**
	 * Request a specific page of photos from Instagram.  This is the only method that should be called by the user.
	 * @param pageNum The page number to be returned (0 index)
	 * @param cbFunc a callback function to be called on success.
	 */
	PhotoAPI.getIgPhotos = function(pageNum, cbFunc){
		if (!PhotoAPI.igPhotoObj){
			//load the facebook photo object now.
			PhotoAPI.loadInstagramPhotos(pageNum, cbFunc);
			return;
		}
		//we have the fbPhotoObj now, so callback with the requested page's images
		PhotoAPI.callback(cbFunc, {status:'success', result:PhotoAPI.buildInstagramResults(pageNum), curPage:pageNum, totalPages:PhotoAPI.igNumPages});

	}
	
	/**
	 * Load the user's photos from Instagram.
	 * @param cbFunc a callback function to be called on success.
	 */
	PhotoAPI.loadInstagramPhotos = function(pageNum, cbFunc){
		// client side code flow
		IG.login(function (response) {
			if (response.session) {
				//store token
				PhotoAPI.IgToken = response.session.access_token;
				//request photos now
				PhotoAPI.makeAuthorizedInstagramRequest(pageNum, cbFunc);
			} else {
				PhotoAPI.callback(cbFunc, {status:'error', result:PhotoAPI.igPermissionsDenied});
			}
		}, {response_type: 'token'});
	}

	/**
	 * 
	 */
	PhotoAPI.makeAuthorizedInstagramRequest = function(pageNum, cbFunc){
		$.ajax({
			type: "GET",
			dataType: "jsonp",
			cache: false,
			//url: "https://api.instagram.com/v1/users/self/feed?count=100&access_token="+PhotoAPI.IgToken,
			//url: "https://api.instagram.com/v1/users/self/media/recent/?min_timestamp=1325397600&access_token="+PhotoAPI.IgToken, //photos from 1-1-2012
			url: "https://api.instagram.com/v1/users/self/media/recent/?min_timestamp=1293861600&access_token="+PhotoAPI.IgToken, //photos from 1-1-2011
			success: function(response) {
				//handle 'success' errors
				if (response.meta.error_type){
					//there was an error
					PhotoAPI.callback(cbFunc, {status:'error', result:PhotoAPI.reportError(response.meta.error_type + ": "+ response.meta.error_message)});
				}else {
					//build results with data here
					PhotoAPI.igPhotoObj = response.data;
					PhotoAPI.igNumPages = Math.ceil(response.data.length / PhotoAPI.photosPerPage);
					/* console.log('igNumPages: '+PhotoAPI.igNumPages); */
					PhotoAPI.callback(cbFunc, {status:'success', result:PhotoAPI.buildInstagramResults(pageNum), curPage:pageNum, totalPages:PhotoAPI.igNumPages});
				}
			},
			error: function() {
				//handle error here
				PhotoAPI.callback(cbFunc, {status:'error', result:PhotoAPI.genericErrorMessage});
			}
		});
	}

	PhotoAPI.buildInstagramResults = function(pageNum){
		var photoStr = '', data = PhotoAPI.igPhotoObj;
		var maxItem = ((pageNum + 1) * PhotoAPI.photosPerPage > data.length) ? data.length : (pageNum + 1) * PhotoAPI.photosPerPage;
		for (var i = pageNum * PhotoAPI.photosPerPage; i < maxItem; i++){
			/* console.log('data['+i+']: '+data[i]); */
			photoStr += '<div class="button square" data-source="instagram" data-url-large="'+ data[i].images.standard_resolution.url.replace("http:","https:") + '" data-objid="'+ data[i].id + '"';
			if (data[i].location) {
				photoStr += 'data-name="'+data[i].location.name+'" data-lat="'+data[i].location.latitude+'" data-lng="'+data[i].location.longitude+'">';
			}else{
				photoStr += 'data-name="" data-lat="" data-lng="">';
			}
			photoStr += '<div class="photoThumb"><img src="' + data[i].images.thumbnail.url.replace("http:","") + '" /></div>';
			photoStr += '</div>'
		}
		return photoStr;
	}

	/**
	-------------------------------------------------- CLASS METHODS ------------------------------------------------------
	**/

	/**
	 * Display the error.
	 * @param errorStr The error returned from the photo API
	 */
	PhotoAPI.reportError = function(errorStr){
		return "<p class='error'>Sorry, we were unable to get your photos at this time.</p><p class='error'>" + errorStr + "</p>";
	}

	/**
	 * Attempt callback function (internal method)
	 */
	PhotoAPI.callback = function(cbFunc, params){
		if (cbFunc == null) return;
		var myFunc;
		if (typeof cbFunc === "function"){
			myFunc = cbFunc;
		}else if (typeof cbFunc === "string"){
			myFunc = window[cbFunc];
		}
		try{
			myFunc.call(null, params);
		}catch(er){
			//console.log('callback error: '+er.message);
		}
	}

	window.PhotoAPI = PhotoAPI;

}(window));

Anon7 - 2021