getAlbum($groupAlbumId, 1, null, null); $albumName = $album->album->getName(); } if( $tagId != "" ) { $tags = DataModel::getInstance()->getImageTags( $groupAlbumId, $tagId, null ) ; foreach( $tags as $tag ) { $tagName = $tag->name; break; } } $output = ""; if ( $tagId != "" ) { $output .= "Photos tagged "$tagName""; } if ( $tagId != "" && $groupAlbumId != "" ) { $output .= " in "; } if ( $groupAlbumId != "" ) { $output .= "$albumName"; } return $output; } function getGroupMetadata( $groupAlbumId, $tagId ) { if( $groupAlbumId == "" ) { return ""; } $album = DataModel::getInstance()->getAlbum($groupAlbumId, 1, null, null); $albumName = $album->album->getName(); $imageLarge = $album->image->getUrlForSize( "1024x768" ); $caption = preg_replace("/[\r\n]+/", " ", $album->album->caption_safe); $url = $album->album->getFriendlyUrl(); $output = "\n"; $output .= "\n"; $output .= "\n"; $output .= "\n"; return $output; } function getAlbumCaption( $groupAlbumId, $tagId ) { $retVal = ""; $album = DataModel::getInstance()->getAlbum($groupAlbumId, 1, null, null); $breadcrumbs = formatBreadcrumbs( $album->album ); $retVal .= "
"; if( ! $album->album->isAlbumGroup() ) { $retVal .= " By William McKeehan on {$album->album->date}"; } $retVal .="
"; if ( $album->album->caption != "" ) { $cap = preg_replace("/[\r\n]+/", "

\n

", $album->album->caption); $retVal .= "

$cap

"; } if ( $tagId != "" ) { $tags = DataModel::getInstance()->getImageTags( $groupAlbumId, $tagId, null ); if ( $groupAlbumId != "" ) { foreach( $tags as $tag ) { $retVal .= "

View all images tagged "{$tag->name}"

"; break; } } else { foreach( $tags as $tag ) { $retVal .= "

All images tagged "{$tag->name}"

"; break; } } } return $retVal; } /////////////////////////////////////////// // END Group/Album Functions /////////////////////////////////////////// /////////////////////////////////////////// // BEGIN Single Image Functions /////////////////////////////////////////// function getSingleTitle( $imageId ) { $imageAlbums = DataModel::getInstance()->getImageById( $imageId ); foreach( $imageAlbums as $imageAlbum ) { return $imageAlbum->image->getTitle(); } return ""; } function getSingleMetadata( $imageId ) { $imageAlbums = DataModel::getInstance()->getImageById($imageId); foreach( $imageAlbums as $imageAlbum ) { $imageLarge = $imageAlbum->image->getUrlForSize( "1024x768" ); $caption = preg_replace("/[\r\n]+/", " ", $imageAlbum->image->caption); $url = $imageAlbum->image->getPageUrl(); break; } $imageTitle = $imageAlbum->image->getTitle(); $output = "\n"; $output .= "\n"; $output .= "\n"; $output .= "\n"; return $output; } /////////////////////////////////////////// // END Single Image Functions /////////////////////////////////////////// /////////////////////////////////////////// // BEGIN Album Group Formatters // // These are formatters to handle formatting // for a group of articles. /////////////////////////////////////////// /** * For a given groupPath, format the album into $groupType (i.e., "ul") groups of $groupSize * each will be given a rel= tag of the $groupName and the groups will be given the $groupClass */ function formatGroupOfAlbums( $groupAlbumId, $groupName, $groupType, $groupClass, $groupSize, $limit, $offset ) { $albums = DataModel::getInstance()->getAlbum($groupAlbumId, 0, $limit, $offset); $elementType = getElementTypeForGroupType( $groupType ); $groupCounter = 0; $elementCounter = 0; $isEmpty = 1; foreach ( $albums as $album ) { if ( !($elementCounter % $groupSize) ) { $groupCounter++; printGroupClose( $groupName, $groupType, $groupClass, $groupCounter, $isEmpty ); printGroupOpen( $groupName, $groupType, $groupClass, $groupCounter, $isEmpty ); } formatAlbumThumbnailInGroup( $album, $groupName, $elementType, $elementCounter++ ); $isEmpty = 0; } printGroupClose( $groupName, $groupType, $groupClass, $groupCounter, $isEmpty ); } function formatAlbumThumbnailInGroup( $album, $groupName, $elementType, $elementCounter ) { $albumUrl = $album->album->getFriendlyUrl( ); $albumName = $album->album->getName( ); $albumCaption = limit_text($album->album->caption_safe, 15); $imageTitle = $album->image->getTitle(); $imageLarge = $album->image->getUrlForSize( "1024x768" ); $imageThumb = $album->image->getUrlForSize( "160x120" ); $albumLinkCaption = "Click here to view $albumName"; if( ! $album->album->isAlbumGroup() ) { $albumLinkCaption .= " Gallery"; } $albumLinkCaption = htmlentities($albumLinkCaption, ENT_QUOTES); if ( $imageTitle != "" ) { $imageTitle = "$albumName - $imageTitle"; } else { $imageTitle = "$albumName"; } $class=""; $href=$albumUrl; $elementId = "$groupName-image-$elementCounter"; echo " <$elementType id='$elementId' class='thumbnail' >\n"; echo " \n"; echo " $imageTitle\n"; echo " \n"; echo " \n"; echo "
$albumName
\n"; echo "
\n"; if ( $albumCaption != "" ) { echo "
$albumCaption
\n"; } echo " \n"; } /////////////////////////////////////////// // END Article Group Formatters /////////////////////////////////////////// /////////////////////////////////////////// // BEGIN Image Group Formatters // // These are formatters to handle formatting // for a group of articles. /////////////////////////////////////////// function formatPageLinks ( $groupAlbumId, $tagId, $groupName, $groupType, $groupClass, $groupSize, $limit, $offset ) { $images = DataModel::getInstance()->getImages($groupAlbumId, $tagId ); if( count($images) == 0 ) return ""; $numPages = floor( count($images) / 21 ) + 1; if( $numPages == 1 ) return ""; $album = $images[0]->album; echo "
"; for( $i = 1 ; $i <= $numPages ; $i++ ) { if( $tagId != "" ) { $url = "/pics/index.php?tag=" .$tagId ; if( $groupAlbumId != "" ) { $url .= "&group=" . $groupAlbumId ; } $url .= "&page=" . $i; } else { $url = $album->getFriendlyUrlForPage($i); } echo "\n\t$i"; } echo "\n
\n"; } function formatGroupOfImages( $groupAlbumId, $tagId, $groupName, $groupType, $groupClass, $groupSize, $limit, $offset ) { $images = DataModel::getInstance()->getImages($groupAlbumId, $tagId, $limit, $offset); if( count($images) == 0 ) return ""; $elementType = getElementTypeForGroupType( $groupType ); $groupCounter = 0; $elementCounter = 0; $isEmpty = 1; foreach ( $images as $image ) { if ( !($elementCounter % $groupSize) ) { $groupCounter++; printGroupClose( $groupName, $groupType, $groupClass, $groupCounter, $isEmpty ); printGroupOpen( $groupName, $groupType, $groupClass, $groupCounter, $isEmpty ); } $tags = DataModel::getInstance()->getImageTags( $groupAlbumId, $tagId, $image->image->id ) ; formatImageInGroup( $image->image, $groupName, $elementType, $elementCounter++, $tags ); $isEmpty = 0; } printGroupClose( $groupName, $groupType, $groupClass, $groupCounter, $isEmpty ); } function formatImageInGroup( $image, $groupName, $elementType, $elementCounter, $tags ) { $imageCaption = limit_text($image->caption_safe, 15); $imageTitle = $image->getTitle(); $imageLarge = $image->getUrlForSize( "1024x768" ); $imageThumb = $image->getUrlForSize( "160x120" ); $imagePageUrl = $image->getPageUrl(); $imageTitleWithTags = $image->getTitleWithTags($tags); $imageCaptionHtml = ""; if ( $imageCaption != "" ) { $imageCaptionHtml = "
$imageCaption
"; } $elementId = "$groupName-image-$elementCounter"; echo " <$elementType id='$elementId' class='thumbnail' > $imageTitle
$imageTitle
$imageCaptionHtml \n"; } /////////////////////////////////////////// // END Image Group Formatters /////////////////////////////////////////// /////////////////////////////////////////// // BEGIN Cloud Formatters // // These are formatters for a list of // tags and albums /////////////////////////////////////////// function formatTagCloud( $groupAlbumId, $tagId, $imageId ) { if ( $tagId != "" ) return ""; $tags = DataModel::getInstance()->getImageTags( $groupAlbumId, "", $imageId ) ; if( count($tags) == 0 ) { return ""; } $limit = ""; $offset = ""; if( $groupAlbumId != "" ) { $images = DataModel::getInstance()->getImages($groupAlbumId, "", $limit, $offset); $albumImageCount = count($images); } else { $albumImageCount = 0; } $label = "Filter By Tag:"; if( $imageId != null ) { $label = "Tags:"; } echo "

$label

"; } function formatAlbumCloud( $groupAlbumId, $tagId ) { if ( $groupAlbumId != "" ) { return ""; } $limit = ""; $offset = ""; $images = DataModel::getInstance()->getImages($groupAlbumId, $tagId, $limit, $offset); $albumImageCount = count($images); $albums = array(); $albumCounts = array(); foreach( $images as $image ) { if( array_key_exists( "{$image->image->albumId}", $albums ) ) { $albumCounts["{$image->image->albumId}"] += 1; } else { $albumCounts["{$image->image->albumId}"] = 1; $albums["{$image->image->albumId}"] = $image->album; } } echo "

These images are in these albums:

"; } function formatBreadcrumbs( $album ) { $hierarchy = $album->getHierarchy(); $url = "/pics"; $breadcrumbs = "» Photo Albums "; foreach ( $hierarchy as $element ) { if ( $element != "" ) { $to_replace_from = array( '(', ')', '_', '-', ' ', "'"); $to_replace_to = array( '', '', ' ', ' ', '_', ''); $clean_url = str_replace($to_replace_from, $to_replace_to, strtolower( $element ) ); $clean_url = preg_replace( '/__*/', '_', $clean_url ); $clean_url = preg_replace( '/&.*;/', '', $clean_url ); $url .= "/$clean_url"; $breadcrumbs .= " » $element "; } } return $breadcrumbs; } /////////////////////////////////////////// // END Cloud Formatters /////////////////////////////////////////// /////////////////////////////////////////// // BEGIN Album Image AJAX Formatters // // These are formatters to handle formatting // for a group of articles. /////////////////////////////////////////// function formatImagesAjaxArray ( $albumId ) { $tagId = ""; $limit = ""; $ofset = ""; $images = DataModel::getInstance()->getImages( $albumId, $tagId, $limit, $offset ); $imageCollection = array(); foreach ( $images as $image ) { $js = $image->image->getAsJson() ; array_push( $imageCollection, $js ); } echo "{ \"images\": [ " . implode( ",\n", $imageCollection ) . "] }"; } function formatImagesAjaxGallery( $class, $albumId, $limit, $offset ) { echo "\n"; } /////////////////////////////////////////// // END Album Image AJAX Formatters /////////////////////////////////////////// /////////////////////////////////////////// // BEGIN Utilities // General purpose functions that are used // in a variety of formatters /////////////////////////////////////////// function getElementTypeForGroupType ( $groupType ) { switch ( $groupType ) { case "ul": return "li"; break; default: return "span"; } } function printGroupOpen ( $groupName, $groupType, $groupClass, $groupCounter, $isEmpty ) { echo "<$groupType id='$groupName-$groupCounter' class='$groupClass'>\n"; } function printGroupClose ( $groupName, $groupType, $groupClass, $groupCounter, $isEmpty ) { if ( !$isEmpty ) echo "\n"; } /** * Given some text, return a subset of a maximum of $limit characters, * splitting on word boundries and adding ... if the string it truncated. */ function limit_text($text, $limit) { if (str_word_count($text, 0) > $limit) { $words = str_word_count($text, 2); $pos = array_keys($words); $text = substr($text, 0, $pos[$limit]) . '...'; } return $text; } /////////////////////////////////////////// // END Utilities /////////////////////////////////////////// ?>