# Official website: http://spgm.sourceforge.net # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ###### Toggles ############# define("MODE_TRACE", false); // toggles debug mode define("MODE_WARNING", true); // toggles warning mode define("REGISTER_GLOBALS", false); // toggle for register_globals mode // must match the php.ini configuration define("DIR_GAL", "gal/"); // galleries base directory (relative path from // spgm.php or the file requiring it if there's one) define("DIR_LANG", "lang/"); // language packs (relative path from spgm.php or // the file requiring it if there's one) define("DIR_THEMES", "flavors/"); // themes base directory (relative path from // spgm.php or the file requiring it // if there's one) //define("DIR_THUMBS", "thumbnails/"); // if defined, points to the directory // where thumbnails reside, relatively // from the gallery directory define("FILE_GAL_TITLE", "gal-title.txt"); // default title file for a gallery define("FILE_GAL_SORT", "gal-sort.txt"); // file for explicit gallery sort define("FILE_GAL_CAPTION", "gal-desc.txt"); // default caption file for a gallery define("FILE_PIC_SORT", "pic-sort.txt"); // file for explicit picture sort define("FILE_PIC_CAPTIONS", "pic-desc.txt"); // default caption file for pictures/thumbnails define("FILE_THEME", "spgm.thm"); // theme file define("FILE_CONF", "spgm.conf"); // config file define("FILE_LANG", "lang"); // language file short name (without extension) define("PREF_THUMB", "_thb_"); // prefix for thumbnail pictures define("EXT_PIC_CAPTION", ".cmt"); // file extension for pictures comment (DEPRECATED) define("CAPTION_DELIMITER", '|'); define("PARAM_PREFIX", "spgm"); // MUST NOT be empty define("PARAM_NAME_GALID", PARAM_PREFIX."Gal"); define("PARAM_NAME_PICID", PARAM_PREFIX."Pic"); define("PARAM_NAME_PAGE", PARAM_PREFIX."Page"); define("PARAM_NAME_FILTER", PARAM_PREFIX."Filters"); define("PARAM_VALUE_FILTER_NEW", "n"); define("PARAM_VALUE_FILTER_NOTHUMBS", "t"); define("PARAM_VALUE_FILTER_SLIDESHOW", "s"); define("CLASS_TABLE_WRAPPER", "table-wrapper"); define("CLASS_TABLE_MAIN_TITLE", "table-main-title"); define("CLASS_TD_SPGM_LINK", "td-main-title-spgm-link"); define("CLASS_A_SPGM_LINK", "a-spgm-link"); define("CLASS_TABLE_GALLISTING_GRID", "table-gallisting-grid"); define("CLASS_TD_GALLISTING_CELL", "td-gallisting-cell"); define("CLASS_TABLE_GALITEM", "table-galitem"); define("CLASS_TD_GALITEM_ICON", "td-galitem-icon"); define("CLASS_TD_GALITEM_TITLE", "td-galitem-title"); define("CLASS_TD_GALITEM_CAPTION", "td-galitem-caption"); define("CLASS_TABLE_PICTURE", "table-picture"); define("CLASS_TD_PICTURE_NAVI", "td-picture-navi"); define("CLASS_TD_ZOOM_FACTORS", "td-zoom-factors"); define("ID_PICTURE", "picture"); define("ID_PICTURE_CAPTION", "picture-caption"); define("CLASS_BUTTON_ZOOM_FACTORS", "button-zoom-factors"); define("CLASS_TD_PICTURE_PIC", "td-picture-pic"); define("ID_PICTURE_NAVI", "pic-navi"); define("CLASS_TD_PICTURE_FILENAME", "td-picture-filename"); define("CLASS_TD_PICTURE_CAPTION", "td-picture-caption"); define("CLASS_TABLE_THUMBNAILS", "table-thumbnails"); define("CLASS_TD_THUMBNAILS_THUMB", "td-thumbnails-thumb"); define("CLASS_TD_THUMBNAILS_THUMB_SELECTED", "td-thumbnails-thumb-selected"); define("CLASS_TD_THUMBNAILS_NAVI", "td-thumbnails-navi"); define("CLASS_DIV_THUMBNAILS_CAPTION", "div-thumbnails-caption"); define("CLASS_TABLE_SHADOWS", "table-shadows"); define("CLASS_TD_SHADOWS_RIGHT", "td-shadows-right"); define("CLASS_TD_SHADOWS_BOTTOM", "td-shadows-bottom"); define("CLASS_TD_SHADOWS_BOTTOMRIGHT", "td-shadows-bottomright"); define("CLASS_TD_SHADOWS_MAIN", "td-shadows-main"); define("CLASS_SPAN_FILTERS", "span-filters"); define("CLASS_IMG_PICTURE", "img-picture"); define("CLASS_IMG_THUMBNAIL", "img-thumbnail"); define("CLASS_IMG_THUMBNAIL_SELECTED", "img-thumbnail-selected"); define("CLASS_IMG_FOLDER", "img-folder"); define("CLASS_IMG_GALICON", "img-galicon"); define("CLASS_IMG_PICTURE_PREV", "img-picture-prev"); define("CLASS_IMG_PICTURE_NEXT", "img-picture-next"); define("CLASS_IMG_THMBNAVI_PREV", "img-thmbnavi-prev"); define("CLASS_IMG_THMBNAVI_NEXT", "img-thmbnavi-next"); define("CLASS_IMG_NEW", "img-new"); define("CLASS_DIV_GALHEADER", "div-galheader"); define("ERRMSG_UNKNOWN_GALLERY", "unknown gallery"); define("ERRMSG_UNKNOWN_PICTURE", "unknown picture"); define("ERRMSG_INVALID_NUMBER_OF_PICTURES", "invalid number of picture"); define("ERRMSG_INVALID_VALUE", "invalid value"); define("WARNMSG_FILE_INSUFFICIENT_PERMISSIONS", "insufficient permissions (644 required)"); define("WARNMSG_THUMBNAIL_UNREADABLE", "no associated thumbnail or insufficient permissions"); define("WARNMSG_DIR_INSUFFICIENT_PERMISSIONS", "insufficient permissions (755 required)"); define("GALICON_NONE", 0); define("GALICON_RANDOM", 1); define("ORIGINAL_SIZE", 0); define("SORTTYPE_CREATION_DATE", 0); define("SORTTYPE_NAME", 1); define("SORT_ASCENDING", 0); define("SORT_DESCENDING", 1); define("RIGHT", 0); define("BOTTOM", 1); /* multi-language support... */ define("PATTERN_SPGM_LINK", ">SPGM_LINK<"); define("PATTERN_CURRENT_PAGE", ">CURRENT_PAGE<"); define("PATTERN_NB_PAGES", ">NB_PAGES<"); define("PATTERN_CURRENT_PIC", ">CURRENT_PIC<"); define("PATTERN_NB_PICS", ">NB_PICS<"); // Used for variable variables in main function $strVarGalleryId = PARAM_NAME_GALID; $strVarPictureId = PARAM_NAME_PICID; $strVarPageIndex = PARAM_NAME_PAGE; $strVarFilterFlags = PARAM_NAME_FILTER; $cfg = array(); $cfg['conf']['newStatusDuration'] = 30; $cfg['conf']['thumbnailsPerPage'] = 9; $cfg['conf']['thumbnailsPerRow'] = 3; $cfg['conf']['galleryListingCols'] = 2; $cfg['conf']['galleryCaptionPos'] = RIGHT; $cfg['conf']['subGalleryLevel'] = 1; $cfg['conf']['gallerySortType'] = SORTTYPE_NAME; $cfg['conf']['gallerySortOptions'] = SORT_ASCENDING; $cfg['conf']['pictureSortType'] = SORTTYPE_NAME; $cfg['conf']['pictureSortOptions'] = SORT_ASCENDING; $cfg['conf']['pictureInfoedThumbnails'] = false; $cfg['conf']['captionedThumbnails'] = false; $cfg['conf']['pictureCaptionedThumbnails'] = false; $cfg['conf']['filenameWithThumbnails'] = false; $cfg['conf']['filenameWithPictures'] = false; $cfg['conf']['enableSlideshow'] = false; $cfg['conf']['enableDropShadows'] = true; $cfg['conf']['popupPictures'] = false; $cfg['conf']['popupFitPicture'] = true; $cfg['conf']['popupWidth'] = 750; $cfg['conf']['popupHeight'] = 600; $cfg['conf']['filters'] = ''; $cfg['conf']['exifInfo'] = array(); $cfg['conf']['zoomFactors'] = array(); $cfg['conf']['galleryIconType'] = GALICON_NONE; $cfg['conf']['galleryIconHeight'] = ORIGINAL_SIZE; $cfg['conf']['galleryIconWidth'] = ORIGINAL_SIZE; $cfg['conf']['theme'] = 'default'; $cfg['conf']['language'] = 'en'; $cfg['locale']['spgmLink'] = 'a gallery generated by '.PATTERN_SPGM_LINK; $cfg['locale']['thumbnailNaviBar'] = 'Page '.PATTERN_CURRENT_PAGE.' of '.PATTERN_NB_PAGES; $cfg['locale']['filter'] = 'filter'; $cfg['locale']['filterNew'] = 'new'; $cfg['locale']['filterAll'] = 'all'; $cfg['locale']['filterSlideshow'] = 'Slideshow'; $cfg['locale']['pictureNaviBar'] = 'Picture '.PATTERN_CURRENT_PIC.' of '.PATTERN_NB_PICS; $cfg['locale']['newPictures'] = 'new pictures'; $cfg['locale']['newPicture'] = 'new picture'; $cfg['locale']['newGallery'] = 'new gallery'; $cfg['locale']['pictures'] = 'pictures'; $cfg['locale']['picture'] = 'picture'; $cfg['locale']['rootGallery'] = 'Main gallery'; $cfg['locale']['exifHeading'] = 'EXIF data for'; $cfg['theme']['gallerySmallIcon'] = ''; $cfg['theme']['galleryBigIcon'] = ''; $cfg['theme']['newItemIcon'] = ''; $cfg['theme']['previousPictureIcon'] = ''; $cfg['theme']['nextPictureIcon'] = ''; $cfg['theme']['previousPageIcon'] = '«'; $cfg['theme']['previousPageIconNot'] = '«'; $cfg['theme']['nextPageIcon'] = '»'; $cfg['theme']['nextPageIconNot'] = '»'; $cfg['theme']['firstPageIcon'] = '««'; $cfg['theme']['firstPageIconNot'] = '««'; $cfg['theme']['lastPageIcon'] = '»»'; $cfg['theme']['lastPageIconNot'] = '»»'; $cfg['global']['supportedExtensions'] = array('.jpg', '.png', '.gif'); // supported picture file extensions $cfg['global']['propagateFilters'] = false; // used to propagate filters in URLs $cfg['global']['documentSelf'] = ''; $cfg['global']['tmpPathToPics'] = ''; // hack to avoid comparisons of long // strings (only used by the // spgm_CallbackCompareMTime // callback function) $cfg['global']['URLExtraParams'] = ''; // Contains the extra paramaters for SPGM // to be able to link back in template mode # A bit of logic to set a few of the variables above... if (REGISTER_GLOBALS) { if (isset($$strVarFilterFlags) ) $cfg['global']['propagateFilters'] = true; $cfg['global']['documentSelf'] = basename($PHP_SELF); } else { if (isset($_GET[PARAM_NAME_FILTER]) ) $cfg['global']['propagateFilters'] = true; $cfg['global']['documentSelf'] = basename( $_SERVER['PHP_SELF'] ); } // Auto-template mode foreach ($_GET as $key => $value) { if (substr($key, 0, strlen(PARAM_PREFIX)) != PARAM_PREFIX) { $cfg['global']['URLExtraParams'] .= '&'.$key.'='.$value; } } ###### REPORTING FUNCTIONS ############################################# function spgm_Error($strErrorMessage) { print '
'.$strErrorMessage.'
'."\n"; } function spgm_Warning($strWarningMessage) { if (MODE_WARNING) { print '
'.$strWarningMessage.'
'."\n"; } } function spgm_Trace($strTrace) { if (MODE_TRACE) { print '
'.$strTrace.'
'."\n"; } } ################## DISPLAY INFO FUNCTIONS ##################################### function spgm_DispSPGMLink() { global $cfg; spgm_Trace( '

function spgm_DispSPGMLink

'."\n" ); // multi-language support $cfg['locale']['spgmLink'] = ereg_replace(PATTERN_SPGM_LINK, 'SPGM', $cfg['locale']['spgmLink']); // print $cfg['locale']['spgmLink']; } ################################################################################ # Checks if a file or directory is "new" function spgm_IsNew($strFilePath) { global $cfg; spgm_Trace( '

function spgm_IsNew

'."\n" .'strFilePath: '.$strFilePath.'
'."\n" ); if (! file_exists($strFilePath) || $cfg['conf']['newStatusDuration'] == 0) return false; return (filemtime($strFilePath) > (time()-$cfg['conf']['newStatusDuration']*24*3600)); } ################################################################################ # Checks for permissions on either pictures, galleries, config files, etc... function spgm_CheckPerms($strFilePath) { spgm_Trace( '

function spgm_CheckPerms

'."\n" .'strFilePath: '.$strFilePath.'
'."\n" ); return is_readable($strFilePath); } ################################################################################ # Checks if the filname exists, refers to a picture associated to a thumbnail # and is granted the necessary access rigths function spgm_IsPicture($strPictureFileName, $strGalleryId) { global $cfg; $strPicturePath = DIR_GAL.$strGalleryId.'/'.$strPictureFileName; $strThumbnailPath = DIR_GAL.$strGalleryId.'/'.PREF_THUMB.$strPictureFileName; if ( defined('DIR_THUMBS') ) { $strThumbnailPath = DIR_GAL.$strGalleryId.'/'.DIR_THUMBS.PREF_THUMB.$strPictureFileName; } spgm_Trace( '

function spgm_IsPicture

'."\n" .'strPictureFileName: '.$strPictureFileName.'
'."\n" .'strGalleryId: '.$strGalleryId.'
'."\n" .'strPicturePath: '.$strPicturePath.'
'."\n" .'strThumbnailPath: '.$strThumbnailPath.'
'."\n" ); // check filename patterns if ( eregi('^'.PREF_THUMB.'*', $strPictureFileName) ) return false; $validated = false; $extnb = count($cfg['global']['supportedExtensions']); for ($i=0; $i<$extnb; $i++) { if ( eregi($cfg['global']['supportedExtensions'][$i].'$', $strPictureFileName) ) { $validated = true; break; } } if (! $validated) return false; // does it exist, is it a regular file and does it have the expected permissions ? if (! spgm_CheckPerms($strPicturePath) ) { return false; } // an associated thumbnail is required... same job again ! if (! spgm_CheckPerms($strThumbnailPath) ) { spgm_Warning( $strPicturePath.': '.WARNMSG_THUMBNAIL_UNREADABLE.'
' ); return false; } return true; } ############################################################################## # Checks if the directory corresponding the gallery is well-formed, exists # and is granted the necessary access rights # $galid can be empty function spgm_IsGallery($strGalleryId) { $strPathToPictures = DIR_GAL.$strGalleryId; spgm_Trace( '

function spgm_IsGallery

'."\n" .'strGalleryId: '.$strGalleryId.'
'."\n" .'strPathToPictures: '.$strPathToPictures.'
'."\n" ); // searching for hazardous patterns if ( ereg('^/', $strGalleryId) || ereg('\.\.', $strGalleryId) || ereg('/$', $strGalleryId) ) { return false; } // does it exist, is it a directory and does it have the expected permissions ? if (! is_dir($strPathToPictures)) return false; if (! spgm_CheckPerms($strPathToPictures) ) { spgm_Warning( $strPathToPictures.': '.WARNMSG_FILE_INSUFFICIENT_PERMISSIONS.'
' ); return false; } if ( defined('DIR_THUMBS') ) { if (basename($strGalleryId).'/' == DIR_THUMBS) { return false; } } return true; } ################################################################################ # Loads a flavor function spgm_LoadFlavor($strThemeName) { global $cfg; spgm_Trace( '

function spgm_LoadFlavor

'."\n" .'strThemeName: '.$strThemeName.'
'."\n" ); if ( spgm_CheckPerms(DIR_THEMES.$strThemeName.'/'.FILE_THEME) ) { include(DIR_THEMES.$strThemeName.'/'.FILE_THEME); } else spgm_Warning( 'unable to load '.DIR_THEMES.$strThemeName.'/'.FILE_THEME.': ' .WARNMSG_FILE_INSUFFICIENT_PERMISSIONS.'
' ); } ################################################################################ # Loads textual ressources from an SPGM language file. function spgm_LoadLanguage($strCountryCode) { global $cfg; spgm_Trace( '

funtion spgm_LoadLanguage

'."\n" .'country code: '.$strCountryCode.'
'."\n" ); if ($strCountryCode != '') { $filename_lang = DIR_LANG.FILE_LANG.'.'.$strCountryCode; if (file_exists($filename_lang) ) { if ( spgm_CheckPerms($filename_lang) ) { include($filename_lang); } } else spgm_Warning( 'No support for lang. '.$strCountryCode.' » default: english
' ); } } ############################################################################### # Loads picture/thumbnail captions for a given gallery function spgm_LoadPictureCaptions($strGalleryId) { global $cfg; spgm_Trace( '

funtion spgm_LoadPictureCaption

'."\n" .'strGalleryId: '.$strGalleryId.'
'."\n" ); $strCaptionsFilename = DIR_GAL.$strGalleryId.'/'.FILE_PIC_CAPTIONS; if ( spgm_CheckPerms($strCaptionsFilename) ) { //goo $arrCaptions = file($strCaptionsFilename); $_max = count($arrCaptions); for ($i=0; $i<$_max; $i++) { list($strPictureFilename, $strCaption) = explode(CAPTION_DELIMITER, $arrCaptions[$i]); $cfg['captions'][trim($strPictureFilename)] = trim($strCaption); } } } ################################################################## # Loads Exif Data from and returns it as an XHTML-formatted string function spgm_LoadExif($strPictureURL) { global $cfg; $arrExifData = exif_read_data($strPictureURL); $strExifData = ''; if ( $cfg['conf']['exifInfo'][0] == 'ALL' ) { foreach ($arrExifData as $key => $value) { if (! is_array($arrExifData[$key]) ) { $strExifData .= '<b>'.$key.'</b> '.$value.'<br />'; } } $strExifData = ereg_replace("\n", '', $strExifData); } else { $max = count( $cfg['conf']['exifInfo'] ); for ($i=0; $i<$max; $i++) { $key = $cfg['conf']['exifInfo'][$i]; $strExifData .= '<b>'.$key.'</b> '.$arrExifData[$key].'<br />'; } } return $strExifData; } ################################################################################ function spgm_PostInitCheck() { global $cfg; spgm_Trace( '

funtion spgm_PostInitCheck

'."\n" ); $_mix = $cfg['conf']['newStatusDuration']; if (! is_int($_mix) || ($_mix < 0) ) spgm_Error('cfg[conf][newStatusDuration]: '.ERRMSG_INVALID_VALUE); $_mix = $cfg['conf']['thumbnailsPerPage']; if (! is_int($_mix) || ($_mix < 1) ) spgm_Error('cfg[conf][thumbnailsPerPage]: '.ERRMSG_INVALID_VALUE); $_mix = $cfg['conf']['thumbnailsPerRow']; if (! is_int($_mix) || ($_mix < 1) ) spgm_Error('cfg[conf][thumbnailsPerRow]: '.ERRMSG_INVALID_VALUE); $_mix = $cfg['conf']['galleryListingCols']; if (! is_int($_mix) || ($_mix < 1) ) spgm_Error('cfg[conf][galleryListingCols]: '.ERRMSG_INVALID_VALUE); $_mix = $cfg['conf']['subGalleryLevel']; if (! is_int($_mix) || ($_mix < 0) ) spgm_Error('cfg[conf][subGalleryLevel]: '.ERRMSG_INVALID_VALUE); $_mix = $cfg['conf']['galleryIconType']; if ( ! is_int($_mix) || ($_mix != GALICON_NONE && $_mix != GALICON_RANDOM) ) spgm_Error('cfg[conf][galleryIconType]: '.ERRMSG_INVALID_VALUE); $_mix = $cfg['conf']['galleryIconHeight']; if (! is_int($_mix) || ($_mix < ORIGINAL_SIZE) ) spgm_Error('cfg[conf][galleryIconHeight]: '.ERRMSG_INVALID_VALUE); $_mix = $cfg['conf']['galleryIconWidth']; if (! is_int($_mix) || ($_mix < ORIGINAL_SIZE) ) spgm_Error('cfg[conf][galleryIconWidth]: '.ERRMSG_INVALID_VALUE); $_mix = $cfg['conf']['galleryCaptionPos']; if ( ! is_int($_mix) || ($_mix != RIGHT && $_mix != BOTTOM) ) spgm_Error('cfg[conf][galleryCaptionPos]: '.ERRMSG_INVALID_VALUE); $_mix = $cfg['conf']['gallerySortType']; if ( ! is_int($_mix) || ($_mix != SORTTYPE_CREATION_DATE && $_mix != SORTTYPE_NAME) ) spgm_Error('cfg[conf][gallerySortType]: '.ERRMSG_INVALID_VALUE); $_mix = $cfg['conf']['gallerySortOptions']; if ( ! is_int($_mix) || ($_mix != SORT_ASCENDING && $_mix != SORT_DESCENDING) ) spgm_Error('cfg[conf][gallerySortOptions]: '.ERRMSG_INVALID_VALUE); $_mix = $cfg['conf']['pictureSortType']; if ( ! is_int($_mix) || ($_mix != SORTTYPE_CREATION_DATE && $_mix != SORTTYPE_NAME) ) spgm_Error('cfg[conf][pictureSortType]: '.ERRMSG_INVALID_VALUE); $_mix = $cfg['conf']['pictureSortOptions']; if ( ! is_int($_mix) || ($_mix != SORT_ASCENDING && $_mix != SORT_DESCENDING) ) spgm_Error('cfg[conf][pictureSortOptions]: '.ERRMSG_INVALID_VALUE); if ( ! is_bool($cfg['conf']['pictureInfoedThumbnails']) ) spgm_Error('cfg[conf][pictureInfoedThumbnail]: '.ERRMSG_INVALID_VALUE); if ( ! is_bool($cfg['conf']['captionedThumbnails']) ) spgm_Error('cfg[conf][captionedThumbnails]: '.ERRMSG_INVALID_VALUE); if ( ! is_bool($cfg['conf']['pictureCaptionedThumbnails']) ) spgm_Error('cfg[conf][pictureCaptionedThumbnails]: '.ERRMSG_INVALID_VALUE); if ( ! is_bool($cfg['conf']['popupPictures']) ) spgm_Error('cfg[conf][popupPictures]: '.ERRMSG_INVALID_VALUE); $_mix = $cfg['conf']['popupWidth']; if ( ! is_int($_mix) || $_mix < 1) spgm_Error('cfg[conf][popupWidth]: '.ERRMSG_INVALID_VALUE); $_mix = $cfg['conf']['popupHeight']; if ( ! is_int($_mix) || $_mix < 1) spgm_Error('cfg[conf][popupHeight]: '.ERRMSG_INVALID_VALUE); if ( ! is_string($cfg['conf']['filters']) ) spgm_Error('cfg[conf][filters]: '.ERRMSG_INVALID_VALUE); if ( ! is_array($cfg['conf']['zoomFactors']) ) spgm_Error('cfg[conf][zoomFactors]: '.ERRMSG_INVALID_VALUE); if ( ! is_array($cfg['conf']['exifInfo']) ) spgm_Error('cfg[conf][exifInfo]: '.ERRMSG_INVALID_VALUE); if ( ! is_string($cfg['conf']['theme']) ) spgm_Error('cfg[conf][theme]: '.ERRMSG_INVALID_VALUE); if ( ! is_string($cfg['conf']['language']) ) spgm_Error('cfg[conf][language]: '.ERRMSG_INVALID_VALUE); # Link labels initialization $arrIconInfo = array( // key in $cfg | ALT value | CLASS value | alternative (if resource is N/A) array('gallerySmallIcon', '', CLASS_IMG_FOLDER, ''), array('galleryBigIcon', '', CLASS_IMG_FOLDER, '»'), array('previousPageIcon', 'Previous thumbnail page', CLASS_IMG_THMBNAVI_PREV, '«'), array('previousPageIconNot', 'Disabled previous thumbnail page', CLASS_IMG_THMBNAVI_PREV, '«'), array('firstPageIcon', 'First thumbnail page', CLASS_IMG_THMBNAVI_PREV, '««'), array('firstPageIconNot', 'Disabled first thumbnail page', CLASS_IMG_THMBNAVI_PREV, '««'), array('nextPageIcon', 'Next thumbnail page', CLASS_IMG_THMBNAVI_NEXT, '»'), array('nextPageIconNot', 'Disabled next thumbnail page', CLASS_IMG_THMBNAVI_NEXT, '»'), array('lastPageIcon', 'Last thumbnail page', CLASS_IMG_THMBNAVI_NEXT, '»»'), array('lastPageIconNot', 'Disabled last thumbnail page', CLASS_IMG_THMBNAVI_NEXT, '»»'), array('previousPictureIcon', 'Previous picture', CLASS_IMG_PICTURE_PREV, '«'), array('nextPictureIcon', 'Next picture', CLASS_IMG_PICTURE_NEXT, '»'), array('newItemIcon', '', CLASS_IMG_NEW, '') ); $dim = array(); $iIconNumber = count($arrIconInfo); $strIconFileName = ''; $_key = ''; $_lblAlt = ''; $_lblClass = ''; $_lblNa = ''; for ($i=0; $i<$iIconNumber; $i++) { $_key = $arrIconInfo[$i][0]; $_lblAlt = $arrIconInfo[$i][1]; $_lblClass = $arrIconInfo[$i][2]; $_lblNa = $arrIconInfo[$i][3]; $strIconFileName = DIR_THEMES.$cfg['conf']['theme'].'/'.$cfg['theme'][$_key]; if ( $cfg['theme'][$_key] != '' && spgm_CheckPerms($strIconFileName) ) { $dim = getimagesize($strIconFileName); $cfg['theme'][$_key] = ''; } else { if ($_lblNa != '') $cfg['theme'][$_key] = $_lblNa; } } } ################################################################################ # Loads config files from the possible different locations. # To allow properties inheritance, it includes all the config file from the # top level gallery to the gallery itself. # TODO: support for INI files (PHP4) ? function spgm_LoadConfig($strGalleryId) { global $cfg; spgm_Trace( '

funtion spgm_LoadConfig

'."\n" .'strGalleryId: '.$strGalleryId.'
'."\n" ); if ( spgm_IsGallery($strGalleryId) ) { // always load the default config file $strConfigurationFileName = DIR_GAL.FILE_CONF; if ( spgm_CheckPerms($strConfigurationFileName) ) { include($strConfigurationFileName); } // now, include all the possible config files if ( $strGalleryId != '' ) { $strConfigurationPathElements = explode('/', $strGalleryId); $iPathDepth = count($strConfigurationPathElements); $_strConfigurationPath = ''; // grows inside the follwing loop ("gal1" -> "gal1/gal2"...) for ($i=0; $i<$iPathDepth; $i++) { // use "foreach ($strConfigurationPathElements as $dir_name) {" in PHP4 $_strConfigurationPath .= $strConfigurationPathElements[$i].'/'; $strConfigurationFileName = DIR_GAL.$_strConfigurationPath.FILE_CONF; if ( spgm_CheckPerms($strConfigurationFileName) ) { include($strConfigurationFileName); } } } } spgm_LoadLanguage($cfg['conf']['language']); spgm_LoadFlavor($cfg['conf']['theme']); spgm_PostInitCheck(); } ################################################################################ # returns an array containing various information for a given gallery and its # provided pictures. # returned array: # $array[0] = total number of pictures # $array[1] = number of new pictures # $array[2] = the thumbnail's filename to use for the gallery icon function spgm_GetGalleryInfo($strGalleryId, $arrPictureFilenames) { global $cfg; $iPictureNumber = 0; $iNewPictureNumber = 0; $strPathToGalleries = DIR_GAL.$strGalleryId; $iPictureNumber = count($arrPictureFilenames); $iNewPictureNumber = 0; for ($i=0; $i<$iPictureNumber; $i++) if (spgm_IsNew($strPathToGalleries.'/'.$arrPictureFilenames[$i]) ) $iNewPictureNumber++; spgm_Trace( '

function spgm_GetGalleryInfo

'."\n" .'strGalleryId: '.$strGalleryId.'
'."\n" .'iPictureNumber: '.$iPictureNumber.'
'."\n" .'strPathToGalleries: '.$strPathToGalleries.'
'."\n" ); $arrGalleryInfo[0] = $iPictureNumber; $arrGalleryInfo[1] = $iNewPictureNumber; if ($cfg['conf']['galleryIconType'] == GALICON_RANDOM && $iPictureNumber > 0) @$arrGalleryInfo[2] = $arrPictureFilenames[rand(0, $iPictureNumber - 1)]; else $arrGalleryInfo[2] = ''; return $arrGalleryInfo; } ############################################################################### # Callback function used to sort galleries/pictures against modification date # The two parameters are automatically passed by the usort() function function spgm_CallbackCompareMTime($strFilePath1, $strFilePath2) { global $cfg; if ( !strcmp($strFilePath1, $strFilePath2) ) return 0; return ( filemtime($cfg['global']['tmpPathToPics'].$strFilePath1) > filemtime($cfg['global']['tmpPathToPics'].$strFilePath2) ) ? 1 : -1; } ################################################################################ # Creates a sorted array containing first level sub-galleries of a given gallery # $galid - the gallery ID to introspect # $display - boolean indicating that galleries will be rendered and that sort # options consequently have to be turned on # returns: a sorted array containing the sub-gallery filenames for the given # gallery function spgm_CreateGalleryArray($strGalleryId, $bToBeDisplayed) { global $cfg; $strPathToGallery = DIR_GAL.$strGalleryId; spgm_Trace( '

function spgm_CreateGalleryArray

'."\n" .'strGalleryId: '.$strGalleryId.'
'."\n" .'strPathToGallery: '.$strPathToGallery.'
'."\n" .'bToBeDisplayed: '.$bToBeDisplayed.'
'."\n" ); if ( spgm_IsGallery($strGalleryId) ) $_hDir = @opendir($strPathToGallery); else spgm_Error($strGalleryId.': '.ERRMSG_UNKNOWN_GALLERY); if ($strGalleryId != '') $strGalleryId .= '/'; // little hack if ($strPathToGallery == DIR_GAL) $strSortFilePath = $strPathToGallery.FILE_GAL_SORT; else $strSortFilePath = $strPathToGallery.'/'.FILE_GAL_SORT; $arrSubGalleries = array(); if ( spgm_CheckPerms($strSortFilePath) ) { $strGalleryNames = file($strSortFilePath); $iGalleryNumber = count($strGalleryNames); for ($i=0; $i<$iGalleryNumber; $i++) { $strGalleryName = trim($strGalleryNames[$i]); if (spgm_IsGallery($strGalleryId.$strGalleryName)) $arrSubGalleries[] = $strGalleryName; } } else { while ($_strFilename = readdir($_hDir)) { if ($_strFilename != '.' && $_strFilename != '..' && spgm_IsGallery($strGalleryId.$_strFilename)) $arrSubGalleries[] = $_strFilename; } closedir($_hDir); // Apply sort options if needed if ($bToBeDisplayed) { if (count($arrSubGalleries) > 0) { if ($cfg['conf']['gallerySortType'] == SORTTYPE_NAME) { if ($cfg['conf']['gallerySortOptions'] == SORT_DESCENDING) rsort($arrSubGalleries); else sort($arrSubGalleries); } else if ($cfg['conf']['gallerySortType'] == SORTTYPE_CREATION_DATE) { $cfg['global']['tmpPathToPics'] = DIR_GAL.$strGalleryId; usort($arrSubGalleries, 'spgm_CallbackCompareMTime'); // TODO: omit it ? if ($cfg['conf']['gallerySortOptions'] == SORT_DESCENDING) $arrSubGalleries = array_reverse($arrSubGalleries); } } } } return $arrSubGalleries; } ################################################################################ # Creates a sorted array of the pictures to diplay for a given gallery # $galid - the gallery ID (must be always valid) # $filter - the filter that defines the pictures to include in the list # $display - boolean indicating that thumbnails will be rendered and that sort # options consequently have to be turned on # returns: a sorted array containing the thumbnails' basenames of the gallery function spgm_CreatePictureArray($strGalleryId, $strFilterFlags, $bForDisplayPurpose) { global $cfg; $strPathToGallery = DIR_GAL.$strGalleryId.'/'; $hDir=opendir($strPathToGallery); spgm_Trace( '

function spgm_CreatePictureArray

'."\n" .'strGalleryId: '.$strGalleryId.'
'."\n" .'strFilterFlags: '.$strFilterFlags.'
'."\n" .'strPathToGallery: '.$strPathToGallery.'
'."\n" .'bForDisplayPurpose: '.$bForDisplayPurpose.'
'."\n" ); $arrPictureFilenames = array(); $strPathToSortFile = $strPathToGallery.FILE_PIC_SORT; if ( spgm_CheckPerms($strPathToSortFile) ) { $arrSortedPictureFilenames = file($strPathToSortFile); $_max = count($arrSortedPictureFilenames); for ($i=0; $i<$_max; $i++) { $strPictureName = trim($arrSortedPictureFilenames[$i]); if ( spgm_IsPicture($strPictureName, $strGalleryId) ) { if ( strstr($strFilterFlags, PARAM_VALUE_FILTER_NEW) ) { if ( spgm_IsNew($strPathToGallery.$strPictureName) ) $arrPictureFilenames[] = $strPictureName; } else $arrPictureFilenames[] = $strPictureName; } } } else { while ($strFileName = readdir($hDir)) { if ( spgm_IsPicture($strFileName, $strGalleryId) ) { if ( strstr($strFilterFlags, PARAM_VALUE_FILTER_NEW) ) { if ( spgm_IsNew($strPathToGallery.$strFileName) ) $arrPictureFilenames[] = $strFileName; } else $arrPictureFilenames[] = $strFileName; } } closedir($hDir); // Apply sort optionsif needed if ($bForDisplayPurpose) { if (count($arrPictureFilenames) > 0) { if ($cfg['conf']['pictureSortType'] == SORTTYPE_NAME) { if ($cfg['conf']['pictureSortOptions'] == SORT_DESCENDING) rsort($arrPictureFilenames); else sort($arrPictureFilenames); } else if ($cfg['conf']['pictureSortType'] == SORTTYPE_CREATION_DATE) { $cfg['global']['tmpPathToPics'] = $strPathToGallery; usort($arrPictureFilenames, 'spgm_CallbackCompareMTime'); // TODO: omit it ? if ($cfg['conf']['pictureSortOptions'] == SORT_DESCENDING) $arrPictureFilenames = array_reverse($arrPictureFilenames); } } } } return $arrPictureFilenames; } ################################################################################ function spgm_DisplayThumbnailNavibar($iCurrentPageIndex, $iPageNumber, $strGalleryId, $strFilterFlags) { global $cfg; spgm_Trace( '

function spgm_DisplayThumbnailNavibar

'."\n" .'iCurrentPageIndex: '.$iCurrentPageIndex.'
'."\n" .'iPageNumber: '.$iPageNumber.'
'."\n" .'strGalleryId: '.$strGalleryId.'
'."\n" ); // display left arrows if ($iCurrentPageIndex > 1) { $iPreviousPageIndex = $iCurrentPageIndex - 1; print ''.$cfg['theme']['firstPageIcon'].' '; print '· '; print ''.$cfg['theme']['previousPageIcon'].' '; } else { print ' '.$cfg['theme']['firstPageIconNot']; print ' · '.$cfg['theme']['previousPageIconNot']; } print ' · '; // display the page numbers for ($i = 1; $i <= $iPageNumber; $i++) { if ($i != $iCurrentPageIndex) print ''.$i.''; else print $i; // don't make it an anchor if this is the current page if ($i < $iPageNumber) print ' · '; } // display right arrows print ' ·'; if ($iCurrentPageIndex < $iPageNumber) { $iNextPageIndex = $iCurrentPageIndex + 1; print ' '.$cfg['theme']['nextPageIcon'].' '; print '· '; print ''.$cfg['theme']['lastPageIcon'].' '; } else { print ' '.$cfg['theme']['nextPageIconNot']; print ' · '.$cfg['theme']['lastPageIconNot']; } } ################################################################################ function spgm_DisplayFilterToggles($strGalleryId, $strFilterFlags, $arrGalleryInfo) { global $cfg; spgm_Trace( '

function spgm_DisplayFilterToggles

'."\n" .'strGalleryId: '.$strGalleryId.'
'."\n" .'strFilterFlags: '.$strFilterFlags.'
'."\n" ); $strHtmlToggles = ''; $bFilterNewOn = strstr($strFilterFlags, PARAM_VALUE_FILTER_NEW); if (($arrGalleryInfo[1] > 0 && $arrGalleryInfo[0] != $arrGalleryInfo[1]) || $bFilterNewOn) { if ( $bFilterNewOn ) { $strHtmlToggles .= ''; $strHtmlToggles .= $cfg['locale']['filterAll'].''; } else { $strHtmlToggles .= ''.$cfg['locale']['filterNew'].''; } print '   ['.$cfg['locale']['filter'].' » '.$strHtmlToggles.']'."\n"; } } ################################################################################ # Prerequisite: spgm_IsGallery($galid) == true function spgm_DisplayGalleryNavibar($strGalleryId, $strFilterFlags, $mixPictureId = '', $arrPictureFilenames) { global $cfg; spgm_Trace( '

function spgm_DisplayGalleryNavibar

'."\n" .'strGalleryId: '.$strGalleryId.'
'."\n" .'strFilterFlags: '.$strFilterFlags.'
'."\n" .'mixPictureId: '.$mixPictureId.'
'."\n" ); $arrExplodedPathToGallery = explode('/', $strGalleryId); // display main gallery link print '
'."\n"; print ' '; if ( $cfg['theme']['gallerySmallIcon'] != '' ) { print $cfg['theme']['gallerySmallIcon']; } else { print $cfg['locale']['rootGallery']; } print ''; // display each gallery of the hierarchy $strHtmlGalleryLink = $arrExplodedPathToGallery[0]; // to avoid the first '/' $_max = count($arrExplodedPathToGallery); $_strGalleryId = ''; for ($i=0; $i<$_max; $i++) { $_strGalleryId .= $arrExplodedPathToGallery[$i].'/'; $_strPathToGallery = DIR_GAL.$_strGalleryId; $_strPathToGalleryTitle = $_strPathToGallery.FILE_GAL_TITLE; $strHtmlGalleryName = ''; if (spgm_CheckPerms($_strPathToGalleryTitle)) { $arrTitle = file($_strPathToGalleryTitle); $strHtmlGalleryName = $arrTitle[0]; } else { $strHtmlGalleryName = ereg_replace('_', ' ', $arrExplodedPathToGallery[$i]); } print ' » '; if ($i < ($_max - 1)) { print ''.$strHtmlGalleryName.''; $strHtmlGalleryLink .= '/'.$arrExplodedPathToGallery[$i+1]; } else { // Final gallery display $iCurrentPageIndex = 1; if ( strstr($strFilterFlags, PARAM_VALUE_FILTER_NOTHUMBS) || strstr($strFilterFlags, PARAM_VALUE_FILTER_SLIDESHOW) ) { if ($mixPictureId == '') { print $strHtmlGalleryName; } else { $iCurrentPageIndex = ((int)($mixPictureId / $cfg['conf']['thumbnailsPerPage'])) + 1; print ''.$strHtmlGalleryName.''; } } else { print $strHtmlGalleryName; } } } // Notify if we are in "new picture mode" if ( strstr($strFilterFlags, PARAM_VALUE_FILTER_NEW) ) print ' ('.$cfg['locale']['newPictures'].')'; // Link to slideshow mode if ($cfg['conf']['enableSlideshow'] == true) { if ( ! strstr($strFilterFlags, PARAM_VALUE_FILTER_SLIDESHOW) && count($arrPictureFilenames) > 0 ) { print ' ['.$cfg['locale']['filterSlideshow']; print ']'; } } print "\n".'
'."\n"; } ################################################################################ # Recursive function to display all galleries as a hierarchy function spgm_DisplayGalleryHierarchy($strGalleryId, $iGalleryDepth, $strFilterFlags) { global $cfg; $strPathToGallery = DIR_GAL.$strGalleryId; spgm_Trace( '

function spgm_DisplayGalleryHierarchy

'."\n" .'strGalleryId: '.$strGalleryId.'
'."\n" .'iGalleryDepth: '.$iGalleryDepth.'
'."\n" .'strFilterFlags: '.$strFilterFlags.'
'."\n" .'strPathToGallery: '.$strPathToGallery.'
'."\n" ); $strHtmlOffset = ''; // check for super gallery. if ($strGalleryId == '') { $strPathToSuperGallery = ''; } else { $strPathToSuperGallery = $strGalleryId.'/'; for ($i=0; $i < $iGalleryDepth; $i++) $strHtmlOffset .= '          '; } # 'new' label tuning according to the actual new item if ($cfg['theme']['newItemIcon'] != '') { $strHtmlNewGallery = $cfg['theme']['newItemIcon']; $strHtmlNewPictures = $cfg['theme']['newItemIcon']; $strNewPicture = $cfg['theme']['newItemIcon']; } else { $strHtmlSpanNewItem = ''; $strHtmlNewGallery = $strHtmlSpanNewItem.$cfg['locale']['newGallery'].''; $strHtmlNewPictures = $strHtmlSpanNewItem.$cfg['locale']['newPictures'].''; $strNewPicture = $strHtmlSpanNewItem.$cfg['locale']['newPicture'].''; } $arrSubGalleryFilenames = spgm_CreateGalleryArray($strGalleryId, true); $_max = count($arrSubGalleryFilenames); if ($iGalleryDepth == 1 && $_max > 0) { print ''."\n"; print ''."\n"; } for ($i=0; $i<$_max; $i++) { $strGalleryName = $arrSubGalleryFilenames[$i]; //* $strPathToSubGallery = $strPathToSuperGallery.$strGalleryName; //* $strPathToGalleryTitle = $strPathToGallery.'/'.$strGalleryName.'/'.FILE_GAL_TITLE; $strGalleryThumbnailBasename = DIR_GAL.$strPathToSuperGallery.PREF_THUMB.$strGalleryName; $strHtmlGalleryName = ''; if (spgm_CheckPerms($strPathToGalleryTitle)) { $arrTitle = file($strPathToGalleryTitle); $strHtmlGalleryName = $arrTitle[0]; } else { $strHtmlGalleryName = ereg_replace('_', ' ', $strGalleryName); } $arrPictureFilenames = spgm_CreatePictureArray($strPathToSubGallery, '', false); // no filter is provided to get all the pictures $arrGalleryInfo = spgm_GetGalleryInfo($strPathToSubGallery, $arrPictureFilenames); $iPictureNumber = $arrGalleryInfo[0]; $iNewPictureNumber = $arrGalleryInfo[1]; $strRandomPictureFilename = $arrGalleryInfo[2]; // should never happen if ($iPictureNumber < 0 || $iNewPictureNumber < 0) spgm_Error('Error while generating gallery ' + ERRMSG_INVALID_NUMBER_OF_PICTURES); else { if ($cfg['conf']['thumbnailsPerPage'] > 0) $strUrlParamPage = '&'.PARAM_NAME_PAGE.'=1'; if ($iPictureNumber == 0) $strHtmlPictureNumber = ''; else { if ($iPictureNumber > 1) $strHtmlPictureNumber = '  ['.$iPictureNumber.' '.$cfg['locale']['pictures']; else $strHtmlPictureNumber = '  ['.$iPictureNumber.' '.$cfg['locale']['picture']; $bAllPicturesNew = ($iPictureNumber == $iNewPictureNumber); if ($bAllPicturesNew) $strHtmlPictureNumber = $strHtmlNewGallery.' '.$strHtmlPictureNumber; if ($iNewPictureNumber>0 && !$bAllPicturesNew) { $strHtmlPictureNumber .= ' - '.$iNewPictureNumber.' '; if ($iNewPictureNumber == 1) $strHtmlPictureNumber .= $strNewPicture.''; else $strHtmlPictureNumber .= $strHtmlNewPictures.''; } $strHtmlPictureNumber .= ']'; } if ($iGalleryDepth <= 1) { if ( ($i % $cfg['conf']['galleryListingCols'] == 0) && ($i != 0) ) print ' '."\n".' '."\n"; print ' '."\n"; } // endfor if ($iGalleryDepth == 1 && $_max > 0) { print ' '."\n"; print '
'."\n"; } print ' '."\n"; print ' '."\n"; // display the gallery icon $iRowSpan = ($cfg['conf']['galleryCaptionPos'] == BOTTOM) ? 1 : 2; print ' '."\n"; if ($cfg['conf']['galleryCaptionPos'] == BOTTOM) print ' '."\n".' '."\n"; // display the gallery title print ' '."\n"; print ' '."\n"; // display the gallery caption print ' '."\n"; print ' '."\n"; print ' '."\n"; print '
'."\n"; if ($strHtmlOffset != '') print ' '.$strHtmlOffset."\n"; print ' '; // no '\n' above to prevent trailing whitespaces within the link // TODO: clean up the following part $bGalleryThumbnailFound = false; $iSupportedExtensionNumber = count($cfg['global']['supportedExtensions']); for ($j=0; $j<$iSupportedExtensionNumber; $j++) { $strGalleryThumbnailFilename = $strGalleryThumbnailBasename.$cfg['global']['supportedExtensions'][$j]; if ( spgm_CheckPerms($strGalleryThumbnailFilename) ) { $arrPictureSize = getimagesize($strGalleryThumbnailFilename); print ''; $bGalleryThumbnailFound = true; break; } } if (! $bGalleryThumbnailFound) { if ($strRandomPictureFilename != '') { $strGalleryThumbnailFilename = DIR_GAL.$strPathToSubGallery.'/'.PREF_THUMB.$strRandomPictureFilename; $arrPictureSize = getimagesize($strGalleryThumbnailFilename); if ($cfg['conf']['galleryIconHeight'] != ORIGINAL_SIZE) $strHtmlHeight = 'height="'.$cfg['conf']['galleryIconHeight'].'"'; else { if ($cfg['conf']['galleryIconWidth'] != ORIGINAL_SIZE) { $iHeight = (int)$arrPictureSize[1]*($cfg['conf']['galleryIconWidth']/$arrPictureSize[0]); $strHtmlHeight = 'height="'.$iHeight.'"'; } else $strHtmlHeight = 'height="'.$arrPictureSize[1].'"'; } if ($cfg['conf']['galleryIconWidth'] != ORIGINAL_SIZE) $strHtmlWidth = 'width="'.$cfg['conf']['galleryIconWidth'].'"'; else { if ($cfg['conf']['galleryIconHeight'] != ORIGINAL_SIZE) { $iWidth = (int)$arrPictureSize[0]*($cfg['conf']['galleryIconHeight']/$arrPictureSize[1]); $strHtmlWidth = 'width="'.$iWidth.'"'; } else $strHtmlWidth = 'width="'.$arrPictureSize[0].'"'; } print ''; } else { if ($cfg['conf']['galleryIconType'] == GALICON_NONE) { $fnameGalleryIcon = $cfg['theme']['gallerySmallIcon']; } else { $fnameGalleryIcon = $cfg['theme']['galleryBigIcon']; } ($fnameGalleryIcon != '') ? print $fnameGalleryIcon : print '»'; } } print ''."\n"; print '
'."\n"; print ' '.$strHtmlGalleryName.' '.$strHtmlPictureNumber.' '."\n"; print '
'."\n"; $strPathToGalleryCaption = $strPathToGallery.'/'.$strGalleryName.'/'.FILE_GAL_CAPTION; if (spgm_CheckPerms($strPathToGalleryCaption)) { // check perms print ' '; include($strPathToGalleryCaption); } print '
'."\n"; } // TODO check this: one test ? if ($cfg['conf']['subGalleryLevel'] == 0) spgm_DisplayGalleryHierarchy($strPathToSubGallery, $iGalleryDepth+1, $strFilterFlags); else if ($iGalleryDepth < $cfg['conf']['subGalleryLevel'] - 1) spgm_DisplayGalleryHierarchy($strPathToSubGallery, $iGalleryDepth+1, $strFilterFlags); if ($iGalleryDepth <= 1) print '
'."\n"; } } ################################################################################ function spgm_DisplayPicture($strGalleryId, $iPictureId, $strFilterFlags) { global $cfg; $arrPictureFilenames = spgm_CreatePictureArray($strGalleryId, $strFilterFlags, true); $iPictureNumber = count($arrPictureFilenames); $strPathToPictures = DIR_GAL.$strGalleryId.'/'; $strPictureFilename = $arrPictureFilenames[$iPictureId]; $_strFileExtension = strrchr($strPictureFilename, '.'); $strPictureBasename = substr($strPictureFilename, 0, -strlen($_strFileExtension)); $strPictureURL = $strPathToPictures.$strPictureFilename; $strCaptionURL = $strPictureURL.EXT_PIC_CAPTION; // DEPRECATED $strGalleryName = ereg_replace('_', ' ', $strGalleryId); $strGalleryName = ereg_replace('/', ' » ', $strGalleryName); $bSlideshowMode = strstr($strFilterFlags, PARAM_VALUE_FILTER_SLIDESHOW) != FALSE; if ($cfg['conf']['thumbnailsPerPage'] != 0) { $iPageNumber = $iPictureNumber / $cfg['conf']['thumbnailsPerPage']; if ($iPageNumber > (int)($iPictureNumber / $cfg['conf']['thumbnailsPerPage'])) $iPageNumber = (int)++$iPageNumber; } spgm_Trace( '

function spgm_DisplayPicture

'."\n" .'strGalleryId: '.$strGalleryId.'
'."\n" .'strPictureFilename: '.$strPictureFilename.'
'."\n" .'strPathToPictures: '.$strPathToPictures.'
'."\n" .'strPictureURL: '.$strPictureURL.'
'."\n" ); if (($iPictureId < 0) || ($iPictureId > $iPictureNumber-1) || $iPictureId == '') spgm_Error(ERRMSG_UNKNOWN_PICTURE); if (! spgm_IsGallery($strGalleryId) ) spgm_Error(ERRMSG_UNKNOWN_GALLERY); if ( spgm_IsPicture($strPictureFilename, $strGalleryId) ) { $arrPictureDim = getimagesize($strPictureURL); $iPreviousPictureId = $iPictureId - 1; $iNextPictureId = $iPictureId + 1; // always display the gallery header spgm_DisplayGalleryNavibar($strGalleryId, $strFilterFlags, $iPictureId, $arrPictureFilenames); // thumbnails are only displayed if wanted if ( ! strstr($strFilterFlags, PARAM_VALUE_FILTER_NOTHUMBS) && ! $bSlideshowMode ) { spgm_DisplayThumbnails($strGalleryId, $arrPictureFilenames, $iPictureId, '', $strFilterFlags); } // Prepare layout for stuff left print '

'."\n"; print ''."\n"; // display the previous/next arrow section if we are not in slideshow mode if ( ! $bSlideshowMode ) { print ' '."\n"; print ' '."\n".' '."\n"; } // Client side zoom buttons if (count($cfg['conf']['zoomFactors']) > 0) { print ''."\n".''."\n".' '."\n".''."\n"; } // EXIF data if ( count($cfg['conf']['exifInfo']) > 0 ) { if ( extension_loaded('exif') ) { // ... where available print ''."\n"; } } // Load pictures if slideshow mode is enabled if ( $bSlideshowMode ) { print ''."\n"; } // Eventually display the picture print ''."\n"; print ' '."\n"; print ''."\n"; // display the picture's filename if needed if ($cfg['conf']['filenameWithPictures'] == true) { print ''."\n"; print ' '."\n"; print ''."\n"; } // display the caption print ''."\n"; print ' '."\n"; print ''."\n"; print '
'."\n"; if ($iPreviousPictureId >= 0) print ' '.$cfg['theme']['previousPictureIcon'].' '; //multi-language support $cfg['locale']['pictureNaviBar'] = ereg_replace(PATTERN_CURRENT_PIC, "$iNextPictureId", $cfg['locale']['pictureNaviBar']); $cfg['locale']['pictureNaviBar'] = ereg_replace(PATTERN_NB_PICS, "$iPictureNumber", $cfg['locale']['pictureNaviBar']); print ' '.$cfg['locale']['pictureNaviBar'].' '; if ($iNextPictureId < $iPictureNumber) print ''.$cfg['theme']['nextPictureIcon'].''."\n"; print '
'."\n"; for ($i=0; $i'."\n"; } print "\n".'
'."\n"; $strExifData = spgm_LoadExif($strPictureURL); print '[Exif]'; print '
'."\n"; // Overlib hidden span for EXIF data print ' '."\n"; // if drop shadows are enabled, draw the beginning of the table if ($cfg['conf']['enableDropShadows']) { print ' '."\n"; print ' '."\n"; print ' '."\n"; print ' '."\n"; print ' '."\n"; print ' '."\n"; print ' '."\n"; print ' '."\n"; print ' '."\n"; print '
'."\n"; } if (! ($iNextPictureId < $iPictureNumber) ) $iNextPictureId = 0; // to link to the appropriate next pic if ( ! $bSlideshowMode ) { print ' '; } print ''.$strPictureURL;
    print ''; if ( ! $bSlideshowMode ) { print ''."\n"; } // if drop shadows are enabled, draw the end of the table if ($cfg['conf']['enableDropShadows']) { print '  
  
'."\n"; } print '
'."\n"; print $strPictureBasename.'
'."\n"; print '
 '."\n"; if ( isset($cfg['captions'][$strPictureFilename]) ) { print $cfg['captions'][$strPictureFilename]; } print '
'."\n"; if ( $bSlideshowMode ) { print ''."\n"; } } else spgm_Error(ERRMSG_UNKNOWN_PICTURE); } ################################################################################ function spgm_DisplayGallery($strGalleryId, $iPageIndex, $strFilterFlags) { spgm_Trace( '

function spgm_DisplayGallery

'."\n" .'strGalleryId: '.$strGalleryId.'
'."\n" .'iPageIndex: '.$iPageIndex.'
'."\n" .'strFilterFlags: '.$strFilterFlags.'
'."\n" ); if (! spgm_IsGallery($strGalleryId) ) spgm_Error(ERRMSG_UNKNOWN_GALLERY); else { $arrPictureFilenames = spgm_CreatePictureArray($strGalleryId, $strFilterFlags, true); if ($iPageIndex == '') $iPageIndex = 1; spgm_DisplayGalleryNavibar($strGalleryId, $strFilterFlags, '', $arrPictureFilenames); // display sub-galleries in a hierarchical manner spgm_DisplayGalleryHierarchy($strGalleryId, 1, $strFilterFlags); if (count($arrPictureFilenames) > 0) spgm_DisplayThumbnails($strGalleryId, $arrPictureFilenames, '', $iPageIndex, $strFilterFlags); // extra vertical padding before displaying the subgalleries print '
'."\n\n"; } } ################################################################################ function spgm_DisplayThumbnails($strGalleryId, $arrPictureFilenames, $iPictureId, $iPageIndex, $strFilterFlags) { global $cfg; $strPathToPictures = DIR_GAL.$strGalleryId.'/'; $iPictureNumber = count($arrPictureFilenames); $iPageNumber = $iPictureNumber / $cfg['conf']['thumbnailsPerPage']; if ($iPageNumber > (int)($iPictureNumber / $cfg['conf']['thumbnailsPerPage'])) $iPageNumber = (int)++$iPageNumber; if (! isset($iPageIndex) ) { $iPictureOffsetStart = 0; $iPageFrom = 1; } else { if (($iPageIndex == '') || ($iPageIndex < 1) || ($iPageIndex > $iPageNumber)) $iPageIndex = 1; } if ($iPictureId == '') $iPictureId = -1; // so picture information are not highlighted else $iPageIndex = ((int)($iPictureId / $cfg['conf']['thumbnailsPerPage'])) + 1; $iPictureOffsetStart = ($iPageIndex-1)*$cfg['conf']['thumbnailsPerPage']; $iPictureOffsetStop = $iPictureOffsetStart + $cfg['conf']['thumbnailsPerPage']; if ($iPictureOffsetStop > $iPictureNumber) $iPictureOffsetStop = $iPictureNumber; $iPageFrom = $iPageIndex; spgm_Trace( '

function spgm_DisplayThumbnails

'."\n" .'strPathToPictures: '.$strPathToPictures.'
'."\n" .'iPictureNumber: '.$iPictureNumber.'
'."\n" .'iPictureId: '.$iPictureId.'
'."\n" .'iPictureOffsetStart: '.$iPictureOffsetStart.'
'."\n" .'iPictureOffsetStop: '.$iPictureOffsetStop.'
'."\n" .'iPageFrom: '.$iPageFrom.'
'."\n" .'iPageNumber: '.$iPageNumber.'
'."\n" .'iPageIndex: '.$iPageIndex.'
'."\n" ); print ''."\n"; print ''."\n"; $iItemCounter = 0; for ($i = $iPictureOffsetStart; $i < $iPictureOffsetStop; $i++) { $strPictureFilename = $arrPictureFilenames[$i]; $_strFileExtension = strrchr($strPictureFilename, '.'); $strPictureBasename = substr($strPictureFilename, 0, -strlen($_strFileExtension)); $strPictureURL = $strPathToPictures.$strPictureFilename; $strThumbnailFilename = PREF_THUMB.$arrPictureFilenames[$i]; if ( defined('DIR_THUMBS') ) { $strThumbnailFilename = DIR_THUMBS.PREF_THUMB.$arrPictureFilenames[$i]; } $strThumbnailURL = $strPathToPictures.$strThumbnailFilename; $arrThumbnailDim = getimagesize($strThumbnailURL); $iCurrentPictureIndex = $i + 1; // index that is displayed $strClassThumbnailThumb = CLASS_TD_THUMBNAILS_THUMB; $strClassImgThumbnail = CLASS_IMG_THUMBNAIL; if ($i == $iPictureId) { $strClassThumbnailThumb = CLASS_TD_THUMBNAILS_THUMB_SELECTED; $strClassImgThumbnail = CLASS_IMG_THUMBNAIL_SELECTED; } // new line if ( ($iItemCounter++ % $cfg['conf']['thumbnailsPerRow']) == 0) if ($iItemCounter > 1) print ''."\n".''."\n"; // test for HTML 4.01 compatibility // TD opening for XHTML compliance when MODE_TRACE is on // TODO: valign=top does not work when new pictures reside amongst old ones print ' '."\n"; } // navi bar generation if ($iPictureNumber > 0) { print ''."\n"; print ''."\n"; print ' '."\n"; print ''."\n"; print '
'."\n"; // ... if ( spgm_IsNew($strPictureURL) && ! strstr($strFilterFlags, PARAM_VALUE_FILTER_NEW) ) { if ($cfg['theme']['newItemIcon'] != '' ) { $strHtmlNew = $cfg['theme']['newItemIcon'].'
'."\n"; } else { $strHtmlNew = '
'.$cfg['locale']['filterNew']; $strHtmlNew .= '
'."\n"; } } else $strHtmlNew = ''; $arrPictureDim = getimagesize($strPictureURL); // ... print ' '.$strHtmlNew."\n"; // if drop shadows are enabled, draw the beginning of the table if ($cfg['conf']['enableDropShadows']) { print ' '."\n"; print ' '."\n"; print ' '."\n"; print ' '."\n"; print ' '."\n"; print ' '."\n"; print ' '."\n"; print ' '."\n"; print ' '."\n"; print '
'."\n"; } if ($cfg['conf']['popupPictures']) { if ( ! strstr($strFilterFlags, PARAM_VALUE_FILTER_NOTHUMBS) ) { $strFilterFlags .= PARAM_VALUE_FILTER_NOTHUMBS; } $iWidth = $cfg['conf']['popupWidth']; $iHeight = $cfg['conf']['popupHeight']; $strURL = $cfg['global']['documentSelf'].'?'.PARAM_NAME_GALID.'='.$strGalleryId.'&'.PARAM_NAME_PICID.'='.$i.'&'.PARAM_NAME_FILTER.'='.ereg_replace(PARAM_VALUE_FILTER_SLIDESHOW, '', $strFilterFlags).$cfg['global']['URLExtraParams'].'#pic'; ; $strJustPicture = 'false'; if ($cfg['conf']['popupFitPicture'] == true) { $iWidth = $arrPictureDim[0]; $iHeight = $arrPictureDim[1]; $strURL = $strPictureURL; $strJustPicture = 'true'; } print ' '; } else { print ' '; } print ''.$strThumbnailURL;
    print ''."\n"; // if drop shadows are enabled, draw the end of the table if ($cfg['conf']['enableDropShadows']) { print '  
  
'."\n"; } print '
'."\n"; // display picture extra information if wanted if ($cfg['conf']['filenameWithThumbnails'] == true) { print $strPictureBasename.'
'; } if ($cfg['conf']['pictureInfoedThumbnails'] == true) { $picsize = (int) (filesize($strPictureURL) / 1024); print ' [ '.$arrPictureDim[0].'x'.$arrPictureDim[1].' - '.$picsize.' KB ]'."\n"; } // display caption along with the thumbnail if ($cfg['conf']['captionedThumbnails'] == true) { if ( isset($cfg['captions'][PREF_THUMB.$strPictureFilename]) ) { print '
'; print $cfg['captions'][PREF_THUMB.$strPictureFilename]; print '
'."\n"; } else if ($cfg['conf']['pictureCaptionedThumbnails']) { if ( isset($cfg['captions'][$strPictureFilename]) ) { print "\n".'
'; print $cfg['captions'][$strPictureFilename]; print '
'."\n"; } } } print '
'; // display "thumbnail navi" if all the thumbs are not displayed on the same page spgm_DisplayThumbnailNavibar($iPageIndex, $iPageNumber, $strGalleryId, $strFilterFlags); // toggles $galleryInfo = spgm_GetGalleryInfo($strGalleryId, $arrPictureFilenames); spgm_DisplayFilterToggles($strGalleryId, $strFilterFlags, $galleryInfo); } // for HTML 4.01 compatibility ... // if there are no thumbnails, then format the markup correctly if ($iItemCounter == 0) print ' '."\n"; print '
'."\n"; } ############# # Main ############# $strParamGalleryId = ''; $strParamPictureId = ''; $strParamPageIndex = ''; $strParamFilterFlags = ''; if (REGISTER_GLOBALS) { if ( isset($$strVarGalleryId) ) { $strParamGalleryId = $$strVarGalleryId; } if ( isset($$strVarPictureId) ) { $strParamPictureId = $$strVarPictureId; } if ( isset($$strVarPageIndex) ) { $strParamPageIndex = $$strVarPageIndex; } if ( isset($$strVarFilterFlags) ) {$strParamFilterFlags = $$strVarFilterFlags; } } else { if (isset($_GET[PARAM_NAME_GALID])) $strParamGalleryId = $_GET[PARAM_NAME_GALID]; if (isset($_GET[PARAM_NAME_PICID])) $strParamPictureId = $_GET[PARAM_NAME_PICID]; if (isset($_GET[PARAM_NAME_PAGE])) $strParamPageIndex = $_GET[PARAM_NAME_PAGE]; if (isset($_GET[PARAM_NAME_FILTER])) $strParamFilterFlags = $_GET[PARAM_NAME_FILTER]; } spgm_LoadConfig($strParamGalleryId); spgm_LoadPictureCaptions($strParamGalleryId); // User filter initialization if ($cfg['conf']['filters'] != '') { if (! $cfg['global']['propagateFilters']) { if ( strstr($cfg['conf']['filters'], PARAM_VALUE_FILTER_NOTHUMBS) && ! strstr($strParamFilterFlags, PARAM_VALUE_FILTER_NOTHUMBS) ) $strParamFilterFlags .= PARAM_VALUE_FILTER_NOTHUMBS; if ( strstr($cfg['conf']['filters'], PARAM_VALUE_FILTER_NEW) && ! strstr($strParamFilterFlags, PARAM_VALUE_FILTER_NEW) ) $strParamFilterFlags .= PARAM_VALUE_FILTER_NEW; } } print "\n\n".''."\n".''."\n".' '."\n"; if ($strParamGalleryId == '') { // the gallery is not specified -> generate the gallery "tree" spgm_DisplayGalleryHierarchy('', 0, $strParamFilterFlags); } else { print ' '."\n"; } print ' '."\n"; // display the link to SPGM website print ' '."\n".' '."\n".' '."\n"; print '
'."\n"; if ($strParamPictureId == '') { // we've got a gallery but no picture -> display thumbnails spgm_DisplayGallery($strParamGalleryId, $strParamPageIndex, $strParamFilterFlags); } else { spgm_DisplayPicture($strParamGalleryId, $strParamPictureId, $strParamFilterFlags); } print '
'."\n"; spgm_DispSPGMLink(); print '
'."\n".''."\n\n"; ?>