/** * function to provide the upload-View */ function sync() { JSession::checkToken(); $app = JFactory::getApplication(); $username = JRequest::getString('username'); $key = JRequest::getString('key'); $albums = EventgalleryHelpersImageHelper::picasaweb_ListAlbums($username, $key); /** * @var EventgalleryModelPicasasync $model */ $model = $this->getModel(); $albumsAdded = 0; foreach ($albums as $album) { if (!$model->eventExists($album->folder)) { $model->addEvent($album); $albumsAdded++; } } $app->enqueueMessage(JText::sprintf('COM_EVENTGALLERY_PICASASYNC_DONE', $albumsAdded)); $this->display(); }
/** * Returns the parsed picasa album object. * * @return object */ public function getAlbum() { if ($this->_album == NULL) { $this->_album = EventgalleryHelpersImageHelper::picasaweb_ListAlbum($this->getUserId(), $this->getAlbumId(), $this->getPicasaKey()); } return $this->_album; }
/** * The following values are valid for the thumbsize and imgmax query parameters and are embeddable on a webpage. These images * are available as both cropped(c) and uncropped(u) sizes by appending c or u to the size. As an example, to retrieve a 72 pixel * image that is cropped, you would specify 72c, while to retrieve the uncropped image, you would specify 72u for the thumbsize or * imgmax query parameter values. * * 32, 48, 64, 72, 104, 144, 150, 160 * * The following values are valid for the thumbsize and imgmax query parameters and are embeddable on a webpage. These images are * available as only uncropped(u) sizes by appending u to the size or just passing the size value without appending anything. * * 94, 110, 128, 200, 220, 288, 320, 400, 512, 576, 640, 720, 800, 912, 1024, 1152, 1280, 1440, 1600 * * @param string $userName * @param string $albumNameOrId * @param string $picasaKey * @param int $imagesize * * @return object */ public static function picasaweb_ListAlbum($userName, $albumNameOrId, $picasaKey = NULL, $imagesize = 1280) { self::initCacheDirs(); set_time_limit(30); $params = JComponentHelper::getParams('com_eventgallery'); $cachelifetime = $params->get('cache_picasa_lifetime', self::$cache_life); $filename = md5($userName . $albumNameOrId . $picasaKey) . '.obj'; $serOBjectPath = self::$cachebasedir . $filename; if (file_exists($serOBjectPath) && time() - filemtime($serOBjectPath) <= $cachelifetime) { $c = file_get_contents($serOBjectPath); return unserialize($c); } #echo "Initial:". memory_get_usage() . "<br>"; #$thumbsizeArray = array(32,48,64,72,104,144,150,160,'32u','48u','64u','72u','104u','144u','150u','160u',94,110,128,200,220,288,320,400,512,576,640,720,800,912,1024,1152,1280,1440); $thumbsizeArray = array(104, '104u'); $thumbsize = implode(',', $thumbsizeArray); $authkeyParam = strlen($picasaKey) > 0 ? "authkey={$picasaKey}&" : ""; $prettyprint = "false"; if (is_numeric($albumNameOrId)) { $url = 'http://picasaweb.google.com/data/feed/api/user/' . urlencode($userName) . '/albumid/' . urlencode($albumNameOrId) . "?" . $authkeyParam . "thumbsize={$thumbsize}&imgmax={$imagesize}&prettyprint={$prettyprint}"; } else { $url = 'http://picasaweb.google.com/data/feed/api/user/' . urlencode($userName) . '/album/' . urlencode($albumNameOrId) . "?" . $authkeyParam . "thumbsize={$thumbsize}&imgmax={$imagesize}&prettyprint={$prettyprint}"; } $album = array(); $photos = array(); $xmlFile = EventgalleryHelpersImageHelper::getPicasawebResult($url); $dom = new DOMDocument(); if (!@$dom->load($xmlFile)) { JLog::add('unable to load xml content from file. File Name: ' . $xmlFile, JLog::INFO, 'com_eventgallery'); $album['photos'] = $photos; $album['overallCount'] = 0; return (object) $album; } #echo "After DOM loaded:". memory_get_usage() . "<br>"; $xpath = new domxpath($dom); $nodes = $xpath->query('//entry'); foreach ($nodes as $node) { $photo = array(); /** * @var DOMNodeList $thumbnailNodes */ $thumbnailNodes = $xpath->query('.//media:thumbnail', $node); $thumbnails = array(); $thumbnailsCrop = array(); /** * @var DOMElement $thumbnailNode */ foreach ($thumbnailNodes as $thumbnailNode) { //if url contains a thumbsize like /s123-c/ it's a crop image if (preg_match("/\\/s[0-9]+-c\\//", $thumbnailNode->getAttribute('url')) == 1) { $thumbnailsCrop[$thumbnailNode->getAttribute('width')] = $thumbnailNode->getAttribute('url'); } else { $thumbnails[$thumbnailNode->getAttribute('width')] = $thumbnailNode->getAttribute('url'); } } /** * @var DOMElement $image */ $image = $xpath->query('.//media:content', $node)->item(0); $photo['image'] = $image->getAttribute('url'); $photo['originalImage'] = str_replace('/s' . $imagesize . '/', "/d/", $photo['image']); $photo['width'] = $image->getAttribute('width'); $photo['height'] = $image->getAttribute('height'); $photo['thumbs'] = $thumbnails; //$photo['thumbsCrop'] = $thumbnails; // this works because picasa can deliver every image as a crop $photo['thumbsCrop'] = EventgalleryHelpersImageHelper::createCropThumbArray($photo['image'], $thumbsizeArray, "s" . $photo['width']); //print_r($photo['thumbs']); $photo['caption'] = $xpath->query('.//summary', $node)->item(0)->textContent; $photo['title'] = ""; $photo['folder'] = $userName . '@' . $albumNameOrId; $photo['file'] = $xpath->query('.//gphoto:id', $node)->item(0)->textContent; $photo['commentCount'] = $xpath->query('.//gphoto:commentCount', $node)->item(0)->textContent; $exif = array(); $items = $xpath->query('.//exif:tags/exif:fstop', $node); $items->length > 0 ? $exif['fstop'] = $items->item(0)->textContent : ($exif['fstop'] = ''); $items = $xpath->query('.//exif:tags/exif:focallength', $node); $items->length > 0 ? $exif['focallength'] = $items->item(0)->textContent : ($exif['focallength'] = ''); $items = $xpath->query('.//exif:tags/exif:model', $node); $items->length > 0 ? $exif['model'] = $items->item(0)->textContent : ($exif['model'] = ''); $items = $xpath->query('.//exif:tags/exif:iso', $node); $items->length > 0 ? $exif['iso'] = $items->item(0)->textContent : ($exif['iso'] = ''); $photo['exif'] = (object) $exif; $photo['allowcomments'] = 0; $photo['published'] = 1; $photos[] = $photo; unset($photo); } $album['folder'] = $userName . '@' . $albumNameOrId; $album['photos'] = $photos; $album['overallCount'] = $xpath->query('//feed/openSearch:totalResults')->item(0)->textContent; $album['date'] = strftime("%Y-%m-%d %H:%M:%S", $xpath->query('//feed/gphoto:timestamp')->item(0)->textContent / 1000); $album['text'] = $xpath->query('//feed/subtitle')->item(0)->textContent; $album['description'] = $xpath->query('//title')->item(0)->textContent; $album['thumbs'] = EventgalleryHelpersImageHelper::createCropThumbArray($xpath->query('//icon')->item(0)->textContent, $thumbsizeArray); $album['width'] = 1440; $album['height'] = 1440; $album['thumbsCrop'] = $album['thumbs']; $dom = NULL; $xpath = NULL; #echo "Finally:". memory_get_usage() . "<br>"; #echo memory_get_peak_usage() . "<br>"; #echo "<pre>"; print_r($album); echo "</pre>"; $album = (object) $album; $c = serialize($album); file_put_contents($serOBjectPath, $c); $db = JFactory::getDBO(); $query = $db->getQuery(true); $query->delete('#__eventgallery_file')->where('folder=' . $db->quote($userName . '@' . $albumNameOrId)); $db->setQuery($query); $db->execute(); if (count($photos) > 0) { $query = $db->getQuery(true); $query->insert($db->quoteName('#__eventgallery_file'))->columns('folder,file,published,' . 'userid,created,modified,ordering')->values(implode(',', array($db->quote($userName . '@' . $albumNameOrId), $db->quote('dummy'), '1', '0', 'now()', 'now()', 0))); $db->setQuery($query); $db->execute(); } return $album; }