function template() { global $Silas, $wp_query; $current = $wp_query->get_queried_object(); if ($current->post_title) { $photoAlbumTitle = $current->post_title; } else { $photoAlbumTitle = 'Photo Gallery'; } if (!isset($_SERVER['_TANTAN_FLICKR_REQUEST_URI'])) { return; } $auth_token = get_option('silas_flickr_token'); $photoTemplate = 'error.html'; if ($auth_token) { require_once dirname(__FILE__) . '/lib.flickr.php'; $flickr = new TanTanFlickr(); $flickr->setToken($auth_token); $flickr->setOption(array('hidePrivatePhotos' => get_option('silas_flickr_hideprivate'))); $parts = explode('/', substr($_SERVER['_TANTAN_FLICKR_REQUEST_URI'], strlen(TANTAN_FLICKR_BASEURL))); $request = array(); $title = ''; $i = 0; if (isset($_POST['refreshCache']) && $_POST['refreshCache']) { $flickr->startClearCache(); } while ($i < count($parts)) { // figgure out the album and/or photo to show if (($parts[$i] == 'tags' || $parts[$i] == 'album' || $parts[$i] == 'group' || $parts[$i] == 'photo') && !ereg(".html\$", $parts[$i])) { $request[$parts[$i]] = $parts[$i + 1]; } $i += 1; } $per_page = 30; // max specified by the Flickr API TOS $page = 1; if (isset($_GET['page'])) { $page = (int) $_GET['page']; } if ($request['photo']) { if ($request['album']) { // within context of album $album = $flickr->getAlbum($request['album']); $context = $flickr->getContext($request['photo'], $request['album']); } elseif ($request['group']) { // within context of group $group = $flickr->getGroup($request['group']); $context = $flickr->getContextByGroup($request['photo'], $request['group']); if ($photo['visibility']['ispublic'] <= 0) { $photo = array(); // sorry, no private photos } add_action('wp_head', array(&$this, 'meta_noindex')); } else { // just an individual photo $context = $flickr->getContext($request['photo']); } $photo = $flickr->getPhoto($request['photo']); if ($flickr->getOption('hidePrivatePhotos') && $photo['visibility']['ispublic'] <= 0) { $photo = array(); } else { $sizes = $flickr->getPhotoSizes($request['photo']); $comments = $flickr->getComments($request['photo']); } $user = $flickr->auth_checkToken(); $nsid = $user['user']['nsid']; if (count($photo['urls'])) { $photourl = array_pop($photo['urls']); } else { $photourl = 'http://www.flickr.com/photos/' . $photo['owner']['nsid'] . '/' . $photo['id'] . '/'; } if ($request['group'] && !TANTAN_FLICKR_DISPLAYGROUPS) { $message = __("Sorry, this feature is not enabled.", 'tantan-flickr'); $photoTemplate = 'error.html'; } elseif ($photo['owner']['nsid'] != $nsid) { if ((int) $photo['license'] > 0 && $photo['usage']['canblog']) { $owner = $flickr->people_getInfo($photo['owner']['nsid']); $photoTemplate = 'photoalbum-photo.html'; } else { $message = __("This photo is not available. ", 'tantan-flickr'); if (count($photo['urls'])) { $message .= '<a href="' . array_pop($photo['urls']) . '">' . __('View this photo at Flickr', 'tantan-flickr') . '</a>'; } $photoTemplate = 'error.html'; } } else { if ($photo['media'] == 'video') { $photoTemplate = 'photoalbum-video.html'; } else { $photoTemplate = 'photoalbum-photo.html'; } } } elseif ($request['album']) { $album = $flickr->getAlbum($request['album']); $user = $flickr->auth_checkToken(); $nsid = $user['user']['nsid']; if ($album['owner'] != $nsid) { $message = __("This album is not available. ", 'tantan-flickr') . '<a href="http://www.flickr.com/photos/' . $album['owner'] . '/sets/' . $album['id'] . '/">' . __('View this album on Flickr', 'tantan-flickr') . '</a>'; $photoTemplate = 'error.html'; } elseif (isset($request['tags'])) { $message = __("Sorry, this feature is not supported", 'tantan-flickr'); $photoTemplate = 'error.html'; if ($request['tags']) { } else { // return popular tags for an album $message = __("Sorry, this feature is not supported", 'tantan-flickr'); $photoTemplate = 'error.html'; } } else { $photos = $flickr->getPhotos($request['album'], NULL, $per_page, $page); if (isset($photos[$album['primary']])) { $primary = $photos[$album['primary']]; } else { $primary = $flickr->getPhoto($album['primary']); $primary['sizes'] = $flickr->getPhotoSizes($album['primary']); } $photoTemplate = 'photoalbum-album.html'; } } elseif ($request['group']) { if (!TANTAN_FLICKR_DISPLAYGROUPS) { $message = __("Sorry, this feature is not enabled.", 'tantan-flickr'); $photoTemplate = 'error.html'; } else { $group = $flickr->getGroup($request['group']); if (isset($request['tags'])) { if ($request['tags']) { $photos = $flickr->getPhotosByGroup($request['group'], $request['tags'], NULL, NULL, $per_page, $page); $photoTemplate = 'photoalbum-tags-group.html'; } else { // return popular tags for a group $message = __("Sorry, this feature is not supported", 'tantan-flickr'); $photoTemplate = 'error.html'; } } else { $photos = $flickr->getPhotosByGroup($request['group'], NULL, NULL, NULL, $per_page, $page); $photoTemplate = 'photoalbum-group.html'; } } } elseif (isset($request['tags'])) { if ($request['tags']) { $photos = $flickr->getPhotosByTags($request['tags']); //$related = $flickr->getRelatedTags($request['tags']); $photoTemplate = 'photoalbum-tags.html'; } else { $tags = $flickr->getTags(); $photoTemplate = 'photoalbum-tagcloud.html'; } } else { $title = $photoAlbumTitle; $albums = $flickr->manualSort($flickr->getAlbums(), get_option('silas_flickr_albumorder')); $hideAlbums = get_option('silas_flickr_hidealbums'); // remove albums marked as hidden if (is_array($hideAlbums)) { foreach ($albums as $k => $a) { if (in_array($a['id'], $hideAlbums)) { unset($albums[$k]); } } } $photoTemplate = 'photoalbum-albums-index.html'; } $this->request = $request; if ($request['group']) { add_action('wp_head', array(&$this, 'meta_noindex')); } add_action('wp_head', array(&$this, 'rss_feed')); add_action('wp_head', array(&$this, 'header')); add_action('wp_footer', array(&$this, 'footer')); $errorMessages = $flickr->getErrorMsgs(); if (is_object($Silas)) { if ($request['photo']) { if ($album) { $Silas->addBreadCrumb($photoAlbumTitle, '../../../../'); $Silas->addBreadCrumb($album['title'], '../../' . $album['pagename']); } else { $Silas->addBreadCrumb($photoAlbumTitle, '../../'); } $Silas->setPageTitle($photo['title']); } elseif ($request['album']) { $Silas->addBreadCrumb($photoAlbumTitle, '../../'); $Silas->setPageTitle($album['title']); } else { $Silas->setPageTitle($photoAlbumTitle); } } else { if ($request['photo']) { $this->setPageTitle($photo['title']); } elseif ($request['album']) { $this->setPageTitle($album['title']); } else { $this->setPageTitle($photoAlbumTitle); } add_filter('wp_title', array(&$this, 'wp_title')); } } else { $message = __("The photo album has not been configured.", 'tantan-flickr'); } if (file_exists(TEMPLATEPATH . '/photoalbum-resources.php')) { require_once TEMPLATEPATH . '/photoalbum-resources.php'; } else { require_once dirname(__FILE__) . '/../templates/photoalbum-resources.php'; } if (file_exists(TEMPLATEPATH . '/photoalbum-index.php')) { include TEMPLATEPATH . '/photoalbum-index.php'; } elseif (file_exists(dirname(__FILE__) . '/../templates/photoalbum-index.php')) { include dirname(__FILE__) . '/../templates/photoalbum-index.php'; } elseif (file_exists(TEMPLATEPATH . '/photos.php')) { include TEMPLATEPATH . '/photos.php'; } else { include dirname(__FILE__) . '/view.php'; } if (count($errorMessages) > 0) { echo "<!-- \n" . $errorMessages . "\n-->\n"; } $flickr->clearCacheStale(); exit; }