| | 1 | <?php |
| | 2 | /** |
| | 3 | * Display template for the Weather module |
| | 4 | * |
| | 5 | * @url $URL: http://svn.mythtv.org/svn/trunk/mythplugins/mythweb/modules/gallery/tmpl/default/gallery.php $ |
| | 6 | * @date $Date: 2006-12-19 09:17:33 +0100 (Di, 19 Dez 2006) $ |
| | 7 | * @version $Revision: 12295 $ |
| | 8 | * @author $Author: xris $ |
| | 9 | * @license GPL |
| | 10 | * |
| | 11 | * @package MythWeb |
| | 12 | * |
| | 13 | /**/ |
| | 14 | |
| | 15 | // Page title |
| | 16 | $page_title = 'MythWeb - '.t('Gallery'); |
| | 17 | |
| | 18 | // Load this page's custom stylesheet |
| | 19 | $headers[] = '<link rel="stylesheet" type="text/css" href="'.root.skin_dir.'/gallery.css" />'; |
| | 20 | |
| | 21 | // Print the page header |
| | 22 | require 'modules/_shared/tmpl/'.tmpl.'/header.php'; |
| | 23 | require_once tmpl_dir.'gallery_config.php'; |
| | 24 | |
| | 25 | // Print the gallery part |
| | 26 | $gallery = new Gallery($data, $main); |
| | 27 | $gallery->start(); |
| | 28 | |
| | 29 | // Print the page footer |
| | 30 | require 'modules/_shared/tmpl/'.tmpl.'/footer.php'; |
| | 31 | |
| | 32 | class Gallery { |
| | 33 | |
| | 34 | var $data; |
| | 35 | var $main; |
| | 36 | var $config; |
| | 37 | |
| | 38 | function Gallery($data, $main) { |
| | 39 | $this->data = $data; |
| | 40 | $this->main = $main; |
| | 41 | } |
| | 42 | |
| | 43 | |
| | 44 | // ======================================================= |
| | 45 | function start() { |
| | 46 | // load default configuration |
| | 47 | $galleryConfig = new GalleryConfig(); |
| | 48 | $this->config = $galleryConfig->getConfig(); |
| | 49 | // the current selected directory where the cached images are stored |
| | 50 | $current_path = $this->getImagePath(); |
| | 51 | // the path to the real images |
| | 52 | $image_path = $this->config['image_path']; |
| | 53 | // the filename of a selected image |
| | 54 | $image_name = $this->getImageName(); |
| | 55 | // the current viewsize mode |
| | 56 | $image_viewsize = $this->getImageViewSize(); |
| | 57 | // get the image index for the viewsize medium |
| | 58 | $image_index = $this->getImageIndex(); |
| | 59 | // get the contents of the folders |
| | 60 | $folderList = $this->getFolderList( $current_path ); |
| | 61 | // check what kind of images should be displayed |
| | 62 | if ($image_viewsize == 'fullsize') { |
| | 63 | // create the images if there are not yet in the directory |
| | 64 | $this->makeImages( $current_path, $folderList, $image_viewsize, $image_index ); |
| | 65 | // display the big image |
| | 66 | $this->showFullsizeImage( $current_path, $folderList, $image_index ); |
| | 67 | // there is nothing else to do |
| | 68 | exit; |
| | 69 | } |
| | 70 | // show the horizontal navigation bar |
| | 71 | $this->showGalleryHeader( $current_path, $image_viewsize, $image_index ); |
| | 72 | // check if the thumbnail directory is there, if not create it |
| | 73 | $this->makeDirectory( $current_path ); |
| | 74 | // create the images if there are not yet in the directory |
| | 75 | $this->makeImages( $current_path, $folderList, $image_viewsize, $image_index ); |
| | 76 | echo '<table width="100%" cellspacing="0" cellpadding="0">'."\n". |
| | 77 | '<tr>'."\n". |
| | 78 | '<td class="folder_navigation">'."\n"; |
| | 79 | $this->showFolderTree( $current_path, $folderList ); |
| | 80 | echo '</td>'."\n". |
| | 81 | '<td class="image_listing">'."\n"; |
| | 82 | if ($this->onlyDirectoriesAvailable( $current_path, $folderList, $image_viewsize, $image_index ) == false ) { |
| | 83 | echo '<table class="imagelist_and_navigation" cellspacing="0" cellpadding="0">'."\n". |
| | 84 | '<tr>'."\n". |
| | 85 | '<td>'."\n"; |
| | 86 | $this->showNavigation( $current_path, $folderList, $image_viewsize, $image_index ); |
| | 87 | echo '</td>'."\n". |
| | 88 | '</tr>'."\n". |
| | 89 | '<tr>'."\n". |
| | 90 | '<td>'."\n"; |
| | 91 | $this->showImages( $current_path, $folderList, $image_viewsize, $image_index ); |
| | 92 | echo '</td>'."\n". |
| | 93 | '</tr>'."\n". |
| | 94 | '</tr>'."\n". |
| | 95 | '</table>'."\n"; |
| | 96 | } else { |
| | 97 | echo ' '; |
| | 98 | } |
| | 99 | echo '</td>'."\n". |
| | 100 | '</tr>'."\n". |
| | 101 | '</table>'."\n"; |
| | 102 | } |
| | 103 | |
| | 104 | // ======================================================= |
| | 105 | function getViewSizesList() { |
| | 106 | $viewsizesList = explode(';',preg_replace('/ /','',$this->config['viewsizes'])); |
| | 107 | return $viewsizesList; |
| | 108 | } |
| | 109 | |
| | 110 | |
| | 111 | // ======================================================= |
| | 112 | function getImagePath() { |
| | 113 | switch ($_SERVER['REQUEST_METHOD']) { |
| | 114 | case 'GET': |
| | 115 | $current_path = stripslashes($_GET[path]); |
| | 116 | break; |
| | 117 | case 'POST': |
| | 118 | $current_path = stripslashes($_POST[path]); |
| | 119 | break; |
| | 120 | } |
| | 121 | if (!is_dir($current_path) ) { |
| | 122 | $current_path = $this->config['image_path']; |
| | 123 | } |
| | 124 | return $current_path; |
| | 125 | } |
| | 126 | |
| | 127 | // ======================================================= |
| | 128 | function getImageViewSize() { |
| | 129 | switch ($_SERVER['REQUEST_METHOD']) { |
| | 130 | case 'GET': |
| | 131 | $viewsize = stripslashes($_GET[viewsize]); |
| | 132 | break; |
| | 133 | case 'POST': |
| | 134 | $viewsize = stripslashes($_POST[viewsize]); |
| | 135 | break; |
| | 136 | } |
| | 137 | // check if the given viewsize is one of the viewsizes |
| | 138 | // specified in the config. fullsize is also needed |
| | 139 | if (isset($viewsize) && |
| | 140 | (($viewsize == 'fullsize') || |
| | 141 | in_array($viewsize, $this->getViewSizesList()))) { |
| | 142 | return $viewsize; |
| | 143 | } else { |
| | 144 | return $this->config['default_viewsize']; |
| | 145 | } |
| | 146 | } |
| | 147 | |
| | 148 | // ======================================================= |
| | 149 | function getImageName() { |
| | 150 | switch ($_SERVER['REQUEST_METHOD']) { |
| | 151 | case 'GET': |
| | 152 | $image_name = $_GET['file']; |
| | 153 | break; |
| | 154 | case 'POST': |
| | 155 | $image_name = $_POST['file']; |
| | 156 | break; |
| | 157 | } |
| | 158 | return $image_name; |
| | 159 | } |
| | 160 | |
| | 161 | // ======================================================= |
| | 162 | function getImageIndex() { |
| | 163 | if (isset($_GET['index'])) |
| | 164 | return $_GET['index']; |
| | 165 | return 1; |
| | 166 | } |
| | 167 | |
| | 168 | |
| | 169 | // ======================================================= |
| | 170 | // displays the path of the choosen directories horizontally |
| | 171 | // so one can navigate back |
| | 172 | function showGalleryHeader( $current_path, $image_viewsize, $image_index ) { |
| | 173 | echo '<table class="current_path_and_viewsize" cellspacing="0" cellpadding="0">'."\n". |
| | 174 | '<tr>'."\n". |
| | 175 | '<td class="current_path">'. |
| | 176 | t('Current path').': '; |
| | 177 | $folders = explode('/', $current_path); |
| | 178 | for ($i=1; $i < count($folders); $i++) { |
| | 179 | echo '<a class="header" href="'.root.'gallery/gallery.php?'.path.'='; |
| | 180 | // show thefolders in the navigation bar |
| | 181 | for ($j=1; $j <= $i; $j++) { |
| | 182 | echo '/'.$folders[$j]; |
| | 183 | } |
| | 184 | echo '&'.viewsize.'='.$this->getImageViewSize().'">'. |
| | 185 | $folders[$i].'</a>'."\n"; |
| | 186 | // don't show the separators when there are no more subfolders |
| | 187 | if ($i < (count($folders)-1)) { |
| | 188 | echo ' / '; |
| | 189 | } |
| | 190 | } |
| | 191 | // display the menu where one can shoose between small and medium images |
| | 192 | echo '</td>'."\n". |
| | 193 | '<td class="change_viewsize_text">'. |
| | 194 | t('Switch view mode').': '. |
| | 195 | '</td>'."\n". |
| | 196 | '<form name="change_viewsize" method="post">'."\n". |
| | 197 | '<td class="change_viewsize_selection">'."\n". |
| | 198 | '<select class="change_viewsize" name="'. |
| | 199 | viewsize.'" onChange="submit()" size="1">'."\n"; |
| | 200 | $viewsizesList = $this->getViewSizesList(); |
| | 201 | for ($i=0; $i < count($viewsizesList); $i++) { |
| | 202 | echo '<option value="'.$viewsizesList[$i].'" '; |
| | 203 | if ($this->getImageViewSize() == $viewsizesList[$i]) { |
| | 204 | echo 'selected'; |
| | 205 | } |
| | 206 | $str = strtr($viewsizesList[$i], ',','x'); |
| | 207 | echo '>'.$str.' '.t('Images per page').'</option>'."\n"; |
| | 208 | } |
| | 209 | echo '</select>'."\n". |
| | 210 | '<input type="hidden" name="'.index.'" value="'.$image_index.'">'. |
| | 211 | '<input type="hidden" name="'.path.'" value="'.$current_path.'">'; |
| | 212 | echo '</td></form>'."\n". |
| | 213 | '</tr>'."\n". |
| | 214 | '</table>'."\n"; |
| | 215 | } |
| | 216 | |
| | 217 | // ======================================================= |
| | 218 | function showFolderTree( $current_path, $folderList ) { |
| | 219 | |
| | 220 | // dont go into the directory if there are not subdirs |
| | 221 | if ($this->getFolderCount( $current_path, $folderList[$i]) == 0) { |
| | 222 | $current_path = substr($current_path, 0, strrpos($current_path, '/')); |
| | 223 | $folderList = $this->getFolderList( $current_path ); |
| | 224 | } |
| | 225 | // displays the directory tree and the pictures |
| | 226 | echo '<table class="folder_navigation" width="100%" cellspacing="0" cellpadding="0">'."\n". |
| | 227 | '<tr>'."\n". |
| | 228 | '<td>'."\n"; |
| | 229 | // display the directories |
| | 230 | for ($i = 0; $i < count( $folderList ); $i++) { |
| | 231 | // only display folders that are not hidden or special |
| | 232 | if ((is_dir( $current_path.'/'.$folderList[$i] )) && |
| | 233 | ($folderList[$i] != '..')){ |
| | 234 | echo '<div class="folder_navigation" '. |
| | 235 | 'onmouseover="this.className=\'folder_navigation_active\'" '. |
| | 236 | 'onmouseout="this.className=\'folder_navigation\'">'; |
| | 237 | $link = $this->getFolderLink( $current_path, $folderList[$i] ); |
| | 238 | $folderCount = $this->getFolderCount( $current_path, $folderList[$i] ); |
| | 239 | // display the folder as a link and the number of subfolder next to it |
| | 240 | $this->displayFolderLink( $link, $folderList[$i], $folderCount ); |
| | 241 | echo '</div>'; |
| | 242 | } |
| | 243 | } |
| | 244 | echo '</td>'."\n". |
| | 245 | '</tr>'."\n". |
| | 246 | '</table>'."\n"; |
| | 247 | } |
| | 248 | |
| | 249 | // ======================================================= |
| | 250 | function getFolderList( $current_path ) { |
| | 251 | if ($current_path != $this->config['cache_path'] ) { |
| | 252 | $folderList[] = '..'; |
| | 253 | } |
| | 254 | // get the image extensions |
| | 255 | $extenstionList = explode(',',$this->config['valid_image_files']); |
| | 256 | // get the directories and files |
| | 257 | if ($dh = opendir($current_path)) { |
| | 258 | while (($file = readdir($dh)) !== false) { |
| | 259 | // only add the file/dir if its a directory or a file |
| | 260 | // with the specified extension |
| | 261 | if ((substr($file,0,1) != '.') && |
| | 262 | (is_dir($current_path.'/'.$file)) || |
| | 263 | (in_array(strtolower(substr($file,-3)), $extenstionList))) |
| | 264 | { |
| | 265 | $folderList[] = $file; |
| | 266 | } |
| | 267 | } |
| | 268 | } |
| | 269 | // delete the first entry when we are at the image_path |
| | 270 | // to prevent from going a directory up |
| | 271 | if ($current_path == $this->config['image_path']) |
| | 272 | array_shift($folderList); |
| | 273 | // sort the array alphabetically |
| | 274 | sort($folderList); |
| | 275 | return $folderList; |
| | 276 | } |
| | 277 | |
| | 278 | // ======================================================= |
| | 279 | function getFolderLink( $current_path, $folder ) { |
| | 280 | $link = '<a class="folderlist" href="'.root.'gallery/gallery.php?'.path.'='; |
| | 281 | // display the .. directory only if there is another |
| | 282 | // directory above this one. |
| | 283 | if (($folder == '..') && ($current_path != $this->config['cache_path'])) { |
| | 284 | $folderList = explode( '/', $current_path.'/'); |
| | 285 | for( $i=1; $i < count($folderList)-2; $i++ ) { |
| | 286 | $link .= '/'.$folderList[$i]; |
| | 287 | } |
| | 288 | } else { |
| | 289 | $link .= $current_path.'/'.$folder; |
| | 290 | } |
| | 291 | $link .= '&'.viewsize.'='.$this->getImageViewSize().'">'; |
| | 292 | return $link; |
| | 293 | } |
| | 294 | |
| | 295 | // ======================================================= |
| | 296 | function displayFolderLink( $link, $folder, $folderCount ) { |
| | 297 | echo '<table class="folderlink_inactive" cellspacing="0" cellpadding="0">'. |
| | 298 | '<tr>'. |
| | 299 | '<td align="left" width="30px">'. |
| | 300 | '<img class="navigation" src="'.root.skin_dir.'/img/gallery/dir.png">'. |
| | 301 | '</td>'. |
| | 302 | '<td align="left" width="auto">'. |
| | 303 | $link.$folder.'</a>'; |
| | 304 | $this->displayFolderCount( $folderCount ); |
| | 305 | echo '</td>'. |
| | 306 | '</tr>'. |
| | 307 | '</table>'."\n"; |
| | 308 | } |
| | 309 | |
| | 310 | // ======================================================= |
| | 311 | function getFolderCount($current_path, $folder) { |
| | 312 | // dont get the folder count if its the .. directory |
| | 313 | if ($folder != '..') { |
| | 314 | return count(glob($current_path.'/'.$folder.'/*',GLOB_ONLYDIR)); |
| | 315 | } |
| | 316 | } |
| | 317 | |
| | 318 | // ======================================================= |
| | 319 | // shows how many sub directories the specified folder has |
| | 320 | function displayFolderCount( $folderCount ) { |
| | 321 | if ($folderCount == 1) { |
| | 322 | echo ' ('.$folderCount.')';// '.t('subfolder'); |
| | 323 | } |
| | 324 | if ($folderCount > 1) { |
| | 325 | echo ' ('.$folderCount.')';// '.t('subfolders'); |
| | 326 | } |
| | 327 | } |
| | 328 | |
| | 329 | |
| | 330 | // ======================================================= |
| | 331 | // creates the directory for the thumbnails. the directory |
| | 332 | // structure is identical to the one of original pictures |
| | 333 | function makeDirectory( $current_path ) { |
| | 334 | if (!file_exists( $this->config['cache_path'].$current_path )) { |
| | 335 | // add the document root to the thumbnail directory |
| | 336 | // because mkdir works with absolute paths |
| | 337 | $cache_path = $_SERVER[DOCUMENT_ROOT].$this->config['cache_path']; |
| | 338 | // split the directory string into separate directories |
| | 339 | $folderList = explode( '/', $current_path ); |
| | 340 | // go through all folder and create each one |
| | 341 | for($i=1; $i < count($folderList); $i++) { |
| | 342 | $cache_path .= '/'.$folderList[$i]; |
| | 343 | // check if the directory is already there |
| | 344 | if (!file_exists($cache_path)) { |
| | 345 | mkdir ($cache_path); |
| | 346 | } |
| | 347 | } |
| | 348 | } |
| | 349 | } |
| | 350 | |
| | 351 | // ======================================================= |
| | 352 | // check if the images are there, if not create them |
| | 353 | function makeImages( $current_path, $folderList, $image_viewsize, $image_index ) { |
| | 354 | $path = $_SERVER[DOCUMENT_ROOT].$this->config['cache_path'].$current_path; |
| | 355 | // use the image_viewsize numbers as a prefix if fullsize is not requested |
| | 356 | if ( $image_viewsize != fullsize ) { |
| | 357 | // only so many images will be created that will be displayed on the screen |
| | 358 | $max_cols = substr($image_viewsize, 0, 1); |
| | 359 | $max_rows = substr($image_viewsize, 2, 1); |
| | 360 | $max_number = ($max_cols * $max_rows); |
| | 361 | // the prefix that will be added to a file so that |
| | 362 | // different sizes have different names |
| | 363 | $file_prefix = strtr($image_viewsize, ',','_').'_'; |
| | 364 | } else { |
| | 365 | $max_number = 1; |
| | 366 | // the prefix that will be added to a file so that |
| | 367 | // different sizes have different names |
| | 368 | $file_prefix = $image_viewsize.'_'; |
| | 369 | } |
| | 370 | // get the amount of subfolders. increase the count in the loop by these |
| | 371 | // subfolders |
| | 372 | $folder_count = count(glob($current_path.'/'.$folder.'/*',GLOB_ONLYDIR)); |
| | 373 | for ($i = $image_index; $i < ($max_number + $image_index + $folder_count); $i++) { |
| | 374 | // show the picture only if its not hidden and not a directory |
| | 375 | if (!is_dir( $current_path.'/'.$folderList[$i] )) { |
| | 376 | // check if there is already a thumbnail available, if not create it |
| | 377 | if (!file_exists( $path.'/'.$file_prefix.$folderList[$i] )) { |
| | 378 | // get the extension of the file |
| | 379 | $fileParts = explode('.', $folderList[$i]); |
| | 380 | $file_extension = strtolower($fileParts[count($fileParts)-1]); |
| | 381 | // get image pointer |
| | 382 | $image_p = null; |
| | 383 | if ($file_extension == 'jpg') |
| | 384 | $image_p = @imagecreatefromjpeg( $current_path.'/'.$folderList[$i] ); |
| | 385 | if ($file_extension == 'png') |
| | 386 | $image_p = @imagecreatefrompng( $current_path.'/'.$folderList[$i] ); |
| | 387 | if ($file_extension == 'gif') |
| | 388 | $image_p = @imagecreatefromgif( $current_path.'/'.$folderList[$i] ); |
| | 389 | // proceed if we have an image pointer |
| | 390 | if ($image_p) { |
| | 391 | // get the image size for the cached images |
| | 392 | $size = getimagesize( $current_path.'/'.$folderList[$i]); |
| | 393 | $width = $size[0]; |
| | 394 | $height = $size[1]; |
| | 395 | // get the width for the choosen viewsize |
| | 396 | // calculate it from the columns and rows if fullsize is not |
| | 397 | // requested, otherwise use the original image size |
| | 398 | if ( $image_viewsize != fullsize ) { |
| | 399 | $new_width = (( $this->config['screen_width'] / $max_cols ) - 50 ); |
| | 400 | // calculate new image dimensions |
| | 401 | $new_height = ($height/$width) * $new_width; |
| | 402 | if ( $height > $width ) { |
| | 403 | $new_width = ($width/$height) * $new_height; |
| | 404 | } |
| | 405 | } else { |
| | 406 | $new_width = $width; |
| | 407 | $new_height = $height; |
| | 408 | } |
| | 409 | // get a new image pointer |
| | 410 | $new_image_p = imagecreatetruecolor($new_width, $new_height); |
| | 411 | // resample the old image to the new one |
| | 412 | imagecopyresampled($new_image_p, $image_p, 0, 0, 0, 0, |
| | 413 | $new_width, $new_height, $width, $height ); |
| | 414 | // save the image |
| | 415 | if ($file_extension == 'jpg') |
| | 416 | imagejpeg($new_image_p, $path.'/'.$file_prefix.$folderList[$i] ); |
| | 417 | if ($file_extension == 'png') |
| | 418 | imagepng($new_image_p, $path.'/'.$file_prefix.$folderList[$i] ); |
| | 419 | if ($file_extension == 'gif') |
| | 420 | imagegif($new_image_p, $path.'/'.$file_prefix.$folderList[$i] ); |
| | 421 | // destroy the old pointers |
| | 422 | imagedestroy( $image_p ); |
| | 423 | imagedestroy( $new_image_p ); |
| | 424 | } |
| | 425 | } |
| | 426 | } |
| | 427 | } |
| | 428 | } |
| | 429 | |
| | 430 | // ======================================================= |
| | 431 | function showImages( $current_path, $folderList, $image_viewsize, $image_index ) { |
| | 432 | |
| | 433 | $path = $_SERVER[DOCUMENT_ROOT].$this->config['cache_path'].$current_path; |
| | 434 | // get the column and row values, display that many images in a row |
| | 435 | $max_cols = substr($image_viewsize, 0, 1); |
| | 436 | $max_rows = substr($image_viewsize, 2, 1); |
| | 437 | // counter for the current column and row |
| | 438 | $current_col = 0; |
| | 439 | // the prefix that will be added to a file so that different sizes have different names |
| | 440 | $file_prefix = strtr($image_viewsize, ',','_').'_'; |
| | 441 | |
| | 442 | // get the amount of subfolders |
| | 443 | $folder_count = count(glob($current_path.'/'.$folder.'/*',GLOB_ONLYDIR)); |
| | 444 | // increase the index by the folder count |
| | 445 | for ($i = 1; $i <= $folder_count; $i++) { |
| | 446 | $image_index += 1; |
| | 447 | } |
| | 448 | echo '<table width="100%" cellspacing="0" cellpadding="0">'."\n". |
| | 449 | '<tr>'. |
| | 450 | '<td colspan="'.$max_cols.'">'. |
| | 451 | ' '. |
| | 452 | '</td>'. |
| | 453 | '</tr>'; |
| | 454 | // go through all entries in the folderList |
| | 455 | for ($i = $image_index; $i < (($max_cols * $max_rows)+$image_index); $i++) { |
| | 456 | if (( file_exists( $path.'/'.$file_prefix.$folderList[$i] )) && |
| | 457 | ( isset($folderList[$i]) )) { |
| | 458 | // if the column is zero then start a new row |
| | 459 | // the specified number of images will be displayed side by side |
| | 460 | if ( $current_col == 0 ) echo '<tr>'."\n"; |
| | 461 | // stretch the table cells to equal size |
| | 462 | echo '<td class="single_image" style="width:'; |
| | 463 | // calculate the width of the cells |
| | 464 | echo floor( 100 / $max_cols ); |
| | 465 | echo '%;">'."\n". |
| | 466 | // display the image centered and put border around it |
| | 467 | '<div align="center">'."\n". |
| | 468 | '<a href="'.root.'gallery/gallery.php?'. |
| | 469 | path.'='.$current_path. |
| | 470 | '&'.index.'='.$i. |
| | 471 | '&'.viewsize.'='.fullsize. |
| | 472 | '" target="blank">'."\n". |
| | 473 | '<img class="single_image" src="'. |
| | 474 | $this->config['cache_path'].$current_path.'/'. |
| | 475 | $file_prefix.$folderList[$i].'" '. |
| | 476 | 'onmouseover="this.className=\'single_image_active\'" '. |
| | 477 | 'onmouseout="this.className=\'single_image\'">'."\n". |
| | 478 | '</a>'."\n". |
| | 479 | '</div>'."\n". |
| | 480 | '<div align="center">'."\n". |
| | 481 | // show the filename |
| | 482 | $folderList[$i]."\n". |
| | 483 | '</div>'."\n". |
| | 484 | '</td>'."\n"; |
| | 485 | // if the max number of columns are reached close the row |
| | 486 | if ( $current_col == $max_cols ) echo '</tr>'."\n"; |
| | 487 | // reset the column count back to zero |
| | 488 | $current_col++; |
| | 489 | if ( $current_col == $max_cols ) $current_col = 0; |
| | 490 | } |
| | 491 | } |
| | 492 | echo '</table>'; |
| | 493 | } |
| | 494 | |
| | 495 | |
| | 496 | // ======================================================= |
| | 497 | function onlyDirectoriesAvailable( $current_path, $folderList, $image_viewsize, $image_index ) { |
| | 498 | $path = $_SERVER[DOCUMENT_ROOT].$this->config['cache_path'].$current_path; |
| | 499 | // only so many images will be created that will be displayed on the screen |
| | 500 | $max_cols = substr($image_viewsize, 0, 1); |
| | 501 | $max_rows = substr($image_viewsize, 2, 1); |
| | 502 | $max_number = ($max_cols * $max_rows); |
| | 503 | // the prefix that will be added to a file so that different sizes have different names |
| | 504 | $file_prefix = strtr($image_viewsize, ',','_').'_'; |
| | 505 | |
| | 506 | // go through the folderList. if there are only directories in it |
| | 507 | // then dont display the navigation stuff |
| | 508 | $only_dirs = true; |
| | 509 | for ($i = 0; $i < count($folderList); $i++) { |
| | 510 | if ( file_exists( $path.'/'.$file_prefix.$folderList[$i] )) { |
| | 511 | $only_dirs = false; |
| | 512 | break; |
| | 513 | } |
| | 514 | } |
| | 515 | return $only_dirs; |
| | 516 | } |
| | 517 | |
| | 518 | // ======================================================= |
| | 519 | function showNavigation( $current_path, $folderList, $image_viewsize, $image_index ) { |
| | 520 | $path = $_SERVER[DOCUMENT_ROOT].$this->config['cache_path'].$current_path; |
| | 521 | // only so many images will be created that will be displayed on the screen |
| | 522 | $max_cols = substr($image_viewsize, 0, 1); |
| | 523 | $max_rows = substr($image_viewsize, 2, 1); |
| | 524 | $max_number = ($max_cols * $max_rows); |
| | 525 | // the prefix that will be added to a file so that different sizes have different names |
| | 526 | $file_prefix = strtr($image_viewsize, ',','_').'_'; |
| | 527 | |
| | 528 | echo '<table width="100%" cellspacing="0" cellpadding="0">'."\n". |
| | 529 | '<tr>'."\n". |
| | 530 | '<td class="image_navigation"> '."\n". |
| | 531 | '</td>'."\n". |
| | 532 | '<td class="image_navigation">'."\n"; |
| | 533 | // display the goto first page link |
| | 534 | if ($image_index != 1) { |
| | 535 | echo '<a href="'.root.'gallery/gallery.php?'. |
| | 536 | '&'.path.'='.$current_path. |
| | 537 | '&'.index.'=1'. |
| | 538 | '&'.viewsize.'='.$image_viewsize.'">'."\n". |
| | 539 | // display the right arrow |
| | 540 | '<img src="'.root.skin_dir.'/img/gallery/first_page.png">'. |
| | 541 | '</a>'."\n"; |
| | 542 | } else { |
| | 543 | echo '<img src="'.root.skin_dir.'/img/gallery/first_page_disabled.png">'."\n"; |
| | 544 | } |
| | 545 | // display the previous page icon if there are more than one entries |
| | 546 | if ($image_index != 1) { |
| | 547 | echo '<a href="'.root.'gallery/gallery.php?'. |
| | 548 | '&'.path.'='.$current_path. |
| | 549 | '&'.index.'='; |
| | 550 | if ($image_index < $max_number) { |
| | 551 | echo 1; |
| | 552 | } else { |
| | 553 | echo ($image_index - $max_number); |
| | 554 | } |
| | 555 | echo '&'.viewsize.'='.$image_viewsize.'">'."\n". |
| | 556 | // display the left arrow |
| | 557 | '<img src="'.root.skin_dir.'/img/gallery/prev_page.png">'. |
| | 558 | '</a>'."\n"; |
| | 559 | } else { |
| | 560 | echo '<img src="'.root.skin_dir.'/img/gallery/prev_page_disabled.png">'."\n"; |
| | 561 | } |
| | 562 | echo '</td>'."\n". |
| | 563 | '<td class="image_navigation">'."\n". |
| | 564 | // display an info in what page we are right now |
| | 565 | '( '.$image_index.' '.t('to').' '; |
| | 566 | if (($image_index + $max_number) < count($folderList)) { |
| | 567 | echo ($image_index+$max_number-1); |
| | 568 | } else { |
| | 569 | echo (count($folderList)-1); |
| | 570 | } |
| | 571 | echo ' '.t('of').' '.(count($folderList)-1).' )'."\n". |
| | 572 | '</td>'."\n". |
| | 573 | '<td class="image_navigation">'."\n"; |
| | 574 | // display the next page link |
| | 575 | if (($image_index + $max_number) < count($folderList)) { |
| | 576 | echo '<a href="'.root.'gallery/gallery.php?'. |
| | 577 | '&'.path.'='.$current_path. |
| | 578 | '&'.index.'='.($image_index + $max_number). |
| | 579 | '&'.viewsize.'='.$image_viewsize.'">'."\n". |
| | 580 | // display the right arrow |
| | 581 | '<img src="'.root.skin_dir.'/img/gallery/next_page.png">'. |
| | 582 | '</a>'."\n"; |
| | 583 | } else { |
| | 584 | echo '<img src="'.root.skin_dir.'/img/gallery/next_page_disabled.png">'."\n"; |
| | 585 | } |
| | 586 | // display the goto last page link |
| | 587 | if (($image_index + $max_number) < count($folderList)) { |
| | 588 | echo '<a href="'.root.'gallery/gallery.php?'. |
| | 589 | '&'.path.'='.$current_path. |
| | 590 | '&'.index.'='. |
| | 591 | (count($folderList) - (count($folderList) % $max_number)+1). |
| | 592 | '&'.viewsize.'='.$image_viewsize.'">'."\n". |
| | 593 | // display the right arrow |
| | 594 | '<img src="'.root.skin_dir.'/img/gallery/last_page.png">'. |
| | 595 | '</a>'."\n"; |
| | 596 | } else { |
| | 597 | echo '<img src="'.root.skin_dir.'/img/gallery/last_page_disabled.png">'."\n"; |
| | 598 | } |
| | 599 | echo '</td>'."\n". |
| | 600 | '<td class="image_navigation"> '."\n". |
| | 601 | '</td>'."\n". |
| | 602 | '</tr>'."\n". |
| | 603 | '</table>'."\n"; |
| | 604 | } |
| | 605 | |
| | 606 | // ======================================================= |
| | 607 | function showFullsizeImage( $current_path, $folderList, $image_index ) { |
| | 608 | echo '<html>'."\n". |
| | 609 | '<head>'."\n". |
| | 610 | '<title>'.$folderList[$image_index].'</title>'."\n". |
| | 611 | '</head>'."\n". |
| | 612 | '<body>'."\n". |
| | 613 | '<div>'."\n". |
| | 614 | '<img src="'."\n". |
| | 615 | $this->config['cache_path'].$current_path.'/'. |
| | 616 | fullsize.'_'.$folderList[$image_index].'">'."\n". |
| | 617 | '</div>'."\n". |
| | 618 | '</body>'."\n". |
| | 619 | '</html>'; |
| | 620 | } |
| | 621 | |
| | 622 | // ======================================================= |
| | 623 | } |