Source

joomla-picasa / site / models / joomlapicasa2.php

<?php

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport( 'joomla.application.component.model' );

class JoomlaPicasa2ModelJoomlaPicasa2 extends JModel
{

	function loadZendClasses()
	{
		global $mainframe;

		$absolute_path = $mainframe->getCfg( 'absolute_path' );

		ini_set("include_path", ini_get("include_path") . PATH_SEPARATOR . JPATH_COMPONENT . DS . 'libraries');

		require_once('Zend' . DS . 'Loader.php');

		Zend_Loader::loadClass('Zend_Gdata_Photos');
		Zend_Loader::loadClass('Zend_Gdata_Photos_UserQuery');
		Zend_Loader::loadClass('Zend_Gdata_Photos_AlbumQuery');
		Zend_Loader::loadClass('Zend_Gdata_Photos_PhotoQuery');
	}

	function getService()
	{
		// Singleton Pattern
		if (!isset($service))
			$service = new Zend_Gdata_Photos();
		return $service;
	}

	function getPicasaUsername()
	{
		global $mainframe;
		$params = &$mainframe->getParams();
		$picasaUsername = $params->get('picasaUsername');
		return $picasaUsername;
	}

	function getMaxPhotosPerPage()
	{
		global $mainframe;
		$params = &$mainframe->getParams();
		$maxPhotosPerPage = $params->get('picasaMaxPhotosPerPage');
		return $maxPhotosPerPage;
	}

	function getAlbumFeed()
	{

		$db =& JFactory::getDBO();

		if (!isset($albumQuery)){
			$this->loadZendClasses();
			$albumQuery = new Zend_Gdata_Photos_AlbumQuery();
		}

		$picasaUsername = $this->getPicasaUsername();
		$maxPhotosPerPage = $this->getMaxPhotosPerPage();
		$albumQuery->setUser($picasaUsername);
		$albumQuery->setAlbumId( $db->getEscaped(JRequest::getVar('album')) );
		$albumQuery->setMaxResults($maxPhotosPerPage);
		$albumQuery->setStartIndex($maxPhotosPerPage * ($db->getEscaped(JRequest::getVar('page'))-1) );

		// FIXME
		// This should FIX the T_OPERATOR_OBJECT error
		// Waiting for feedbacks
		if (!isset($albumFeed)){
			$service = $this->getService();
			$albumFeed = $service->getAlbumFeed($albumQuery);
		}

		return $albumFeed;

	}

	function getUserFeed()
	{

		if (!isset($userQuery)){
			$this->loadZendClasses();
			$userQuery = new Zend_Gdata_Photos_UserQuery();
		}

		$picasaUsername = $this->getPicasaUsername();

		$userQuery->setUser($picasaUsername);

		if (!isset($userFeed)){
			$service = $this->getService();
			$userFeed = $service->getUserFeed(null, $userQuery);
		}

		return $userFeed;

	}

	function getAlbumsList()
	{
		$userFeed = $this->getUserFeed();
		$albumsList = $userFeed->getEntry();
		return $albumsList;
	}

	function getPhotoEntry( $photoId )
	{

		$db =& JFactory::getDBO();

		if (!isset($photoQuery)){
      $this->loadZendClasses();
      $photoQuery = new Zend_Gdata_Photos_PhotoQuery();
    }

    $picasaUsername = $this->getPicasaUsername();

    $photoQuery->setUser($picasaUsername);
		$photoQuery->setType("entry");
		$photoQuery->setAlbumId( $db->getEscaped(JRequest::getVar('album')) );
		$photoQuery->setPhotoId($photoId);

		$service = $this->getService();
		$photoEntry = $service->getPhotoEntry($photoQuery);
		return $photoEntry;

	}

	function getAlbum()
	{
		$albumFeed = $this->getAlbumFeed();
		$albumTitle = $albumFeed->getTitle();
		
		$numPhotos = $albumFeed->getGphotoNumPhotos();
		$numPhotosText = $numPhotos->getText();
		$photosEntry = $albumFeed->getEntry();
		$photosList = array();

		foreach ($photosEntry as $photo){
			$photoId = $photo->getGphotoId();
			$photoEntry = $this->getPhotoEntry( $photoId->getText() );
			$photoTitle = $photoEntry->getTitle();
			$photoMediaGroup = $photoEntry->getMediaGroup();
			$mediaGroupContent = $photoMediaGroup->getContent();
			$photoURL = $mediaGroupContent[0]->getUrl();
			$photoThumbnail = $photoMediaGroup->getThumbnail();
			$thumbnailURL = $photoThumbnail[1]->getUrl();
			$photoObject = 	array ('photoURL' => $photoURL,
											 'thumbnailURL' => $thumbnailURL,
											 'photoTitle' => $photoTitle->getText());
			$photosList[] = $photoObject;
		}

		$album = array('albumTitle' => $albumTitle->getText(),
									 'numPhotos' => $numPhotosText,
									 'photosList' => $photosList);

		return $album;
	}

}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.