[ PHPXref.com ] [ Generated: Sun Jul 20 20:59:36 2008 ] [ Weatimages 1.7.1 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/ -> index.php (source)

   1  <?php
   2  ////////////////////////////////////////////////////////////////////////////////////

   3  //

   4  // Weatimages 1.7.1, powerful easy to use albums publishing script

   5  // Copyright (c) 2003-2006 Vladimir Nazarkin

   6  // http://nazarkin.name/projects/weatimages/

   7  // weatimages@nazarkin.name

   8  //

   9  // This program is free software; you can redistribute it and/or

  10  // modify it under the terms of the GNU General Public License

  11  // as published by the Free Software Foundation; either version 2

  12  // of the License, or (at your option) any later version.

  13  //

  14  // This program is distributed in the hope that it will be useful,

  15  // but WITHOUT ANY WARRANTY; without even the implied warranty of

  16  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

  17  // GNU General Public License for more details.

  18  //

  19  // You should have received a copy of the GNU General Public License

  20  // along with this program; if not, write to the Free Software

  21  // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

  22  //

  23  // $Id: index.php,v 1.46 2006/05/09 13:52:04 Vova Exp $

  24  //

  25  ////////////////////////////////////////////////////////////////////////////////////

  26  
  27  //Do some initializations

  28  error_reporting(E_ALL ^ E_NOTICE);
  29  $limit_cpu = ini_get('max_execution_time');
  30  $limit_mem = ini_get('memory_limit');
  31  if ($limit_cpu && ($limit_cpu < 60)) { @ini_set('max_execution_time', '60'); }
  32  if ($limit_mem && (rtrim($limit_mem, 'M') < 64)) { @ini_set('memory_limit', '64M'); }
  33  
  34  //Langpack strings

  35  $langpack['albums'] = 'Albums';
  36  $langpack['nested_albums_available'] = 'Nested albums available at the first page';
  37  $langpack['additional_items'] = 'Additional items';
  38  $langpack['additional_items_available'] = 'Additional items available at the first page';
  39  $langpack['album_zip'] = 'Download entire album in single archive';
  40  $langpack['page'] = 'page';
  41  $langpack['next_image'] = 'next image';
  42  $langpack['previous_image'] = 'previous image';
  43  $langpack['return_to_album'] = 'return to album';
  44  $langpack['first_image'] = 'first image';
  45  $langpack['last_image'] = 'last image';
  46  $langpack['close_window'] = 'close window';
  47  $langpack['slideshow_start'] = 'start slideshow';
  48  $langpack['slideshow_stop'] = 'stop slideshow';
  49  $langpack['original'] = 'Original';
  50  $langpack['resized'] = 'Resized';
  51  $langpack['switch_size_bottomhelp'] = 'Click image to switch between full-size view and resized view';
  52  $langpack['switch_size_toresized'] = 'Click to view resized image';
  53  $langpack['switch_size_tofullsize'] = 'Click to view full size image';
  54  $langpack['thumbnail_hint'] = 'Click to view big image';
  55  $langpack['kilobytes'] = 'Kb';
  56  $langpack['powered_by'] = 'Powered by';
  57  
  58  //kill oneself if user trying to access resource with '/../' in path

  59  if (strstr(urldecode($_SERVER['REQUEST_URI']), '/../')) { fatal_error('Suspicious query rejected'); }
  60  
  61  //$_SERVER['PATH_INFO'] and $_SERVER['PHP_SELF'] variables is very unstable with different php versions and with different web servers

  62  //so it is better to compute them manually

  63  if ( preg_match('|('.$_SERVER['SCRIPT_NAME'].'([^\?]*))\???|', urldecode($_SERVER['REQUEST_URI']), $matches) ) {
  64      //PATH_INFO is the text between SCRIPT_NAME and QUERY_STRING.

  65      //$_SERVER['REQUEST_URI'] is not urldecode'd by default on Apache (unlike IIS).

  66      $SERVER_PHP_SELF = rtrim($matches[1], '/') . '/'; //ensure that we have trailing slash

  67      $REQUEST_PATH = trim($matches[2], '/');//cut hampering slashes

  68  }
  69  else {
  70      $SERVER_PHP_SELF = $_SERVER['SCRIPT_NAME'] . '/';
  71  }
  72  if (!$REQUEST_PATH) {
  73      if ($_GET['path']) { //compatibility mode enabled and we have some path
  74          $REQUEST_PATH = $_GET['path'];
  75          $SERVER_PHP_SELF = $_SERVER['SCRIPT_NAME'] . '/' . $REQUEST_PATH . '/';
  76      }
  77      else { //we are in the root directory
  78          $REQUEST_PATH = '.';
  79      }
  80  }
  81  //$REQUEST_PATH never has starting and trailing slashes

  82  //$SERVER_PHP_SELF always has starting and trailing slashes

  83  
  84  //ini file name

  85  $ini_ini_filename = 'weatimages.ini';
  86  //read ini file if it present

  87  if (@is_readable($ini_ini_filename)) {
  88      $ini = parse_ini_file($ini_ini_filename, FALSE);
  89  }
  90  
  91  //process nested configs

  92  if ($ini['enable_nested_ini'] && '.' != $REQUEST_PATH) {
  93      $possible_ini_places = explode('/' , $REQUEST_PATH);
  94      $current_search_path = '.';
  95      while (count($possible_ini_places)) {
  96          $current_search_path .= '/' . array_shift($possible_ini_places);
  97          $current_config = $current_search_path . '/' . $ini_ini_filename;
  98          if (@is_readable($current_config)) {
  99              $ini_override = parse_ini_file($current_config, FALSE);
 100              foreach ($ini_override as $key => $value) {
 101                  $ini[$key] = $value;
 102              }
 103              unset($ini_override);
 104          }//if (@is_readable(

 105      }//while (count($possible_ini_places

 106      unset($possible_ini_places, $current_search_path, $current_config);
 107  }//if ($ini['enable_nested_ini']

 108  
 109  //set default options if it absent in ini file of file doesn't exists

 110  if (!isset($ini['cols'])) { $ini['cols'] = 4; }
 111  if (!isset($ini['rows'])) { $ini['rows'] = 6; }
 112  if (!isset($ini['enable_albums_listing'])) { $ini['enable_albums_listing'] = 1; }
 113  if (!isset($ini['enable_albums_thumbs'])) { $ini['enable_albums_thumbs'] = 1; }
 114  if (!isset($ini['albums_thumbs_index'])) { $ini['albums_thumbs_index'] = "index"; }
 115  if (!isset($ini['enable_index_image_hide'])) { $ini['enable_index_image_hide'] = 1; }
 116  if (!isset($ini['albums_cols'])) { $ini['albums_cols'] = 2; }
 117  if (!isset($ini['enable_albums_mtime_sort'])) { $ini['enable_albums_mtime_sort'] = 0; }
 118  if (!isset($ini['enable_albums_reverse_sort'])) { $ini['enable_albums_reverse_sort'] = 0; }
 119  if (!isset($ini['enable_files_mtime_sort'])) { $ini['enable_files_mtime_sort'] = 0; }
 120  if (!isset($ini['enable_files_reverse_sort'])) { $ini['enable_files_reverse_sort'] = 0; }
 121  if (!isset($ini['albums'])) { $ini['albums'] = 50; }
 122  if (!isset($ini['enable_additional_listing'])) { $ini['enable_additional_listing'] = 1; }
 123  if (!isset($ini['additionals'])) { $ini['additionals'] = 20; }
 124  if (!isset($ini['enable_album_zip'])) { $ini['enable_album_zip'] = 0; }
 125  if (!isset($ini['enable_new_window'])) { $ini['enable_new_window'] = 0; }
 126  if (!isset($ini['enable_size_lookup'])) { $ini['enable_size_lookup'] = 1; }
 127  if (!isset($ini['enable_description'])) { $ini['enable_description'] = 1; }
 128  if (!isset($ini['enable_exif'])) { $ini['enable_exif'] = 1; }
 129  if (!isset($ini['enable_exif_date'])) { $ini['enable_exif_date'] = 0; }
 130  if (!isset($ini['enable_cell_border'])) { $ini['enable_cell_border'] = 1; }
 131  if (!isset($ini['enable_albums_edging'])) { $ini['enable_albums_edging'] = -1; }
 132  if (!isset($ini['description_filename'])) { $ini['description_filename'] = 'desc.txt'; }
 133  if (!isset($ini['description_delimiter'])) { $ini['description_delimiter'] = ' '; }
 134  if (!isset($ini['enable_omit_ext'])) { $ini['enable_omit_ext'] = 1; }
 135  if (!isset($ini['enable_filename_display'])) { $ini['enable_filename_display'] = 1; }
 136  if (!isset($ini['enable_filename_cleaning'])) { $ini['enable_filename_cleaning'] = 1; }
 137  if (!isset($ini['enable_html_container'])) { $ini['enable_html_container'] = 1; }
 138  if (!isset($ini['enable_slideshow'])) { $ini['enable_slideshow'] = 1; }
 139  if (!isset($ini['slideshow_delay'])) { $ini['slideshow_delay'] = 3; }
 140  if (!isset($ini['charset'])) { $ini['charset'] = 'windows-1251'; }
 141  if (!isset($ini['jpeg_quality'])) { $ini['jpeg_quality'] = 80; }
 142  if (!isset($ini['hidden_prefix'])) { $ini['hidden_prefix'] = '.'; }
 143  if (!isset($ini['enable_custom_container'])) { $ini['enable_custom_container'] = 0; }
 144  if (!isset($ini['cache_dir'])) { $ini['cache_dir'] = "weatimages-cache"; }
 145  if (!isset($ini['external_css'])) { $ini['external_css'] = ''; }
 146  if (!isset($ini['langpack'])) { $ini['langpack'] = ''; }
 147  if (!isset($ini['enable_compatibility_mode'])) { $ini['enable_compatibility_mode'] = 0; }
 148  
 149  if (!isset($ini['thumb_size'])) { $ini['thumb_size'] = 150; }
 150  if (!isset($ini['enable_thumbs_cache'])) { $ini['enable_thumbs_cache'] = 1; }
 151  
 152  if (!isset($ini['enable_resize'])) { $ini['enable_resize'] = 1; }
 153  if (!isset($ini['resize_size'])) { $ini['resize_size'] = 800; }
 154  if (!isset($ini['enable_smart_resize'])) { $ini['enable_smart_resize'] = 1; }
 155  if (!isset($ini['default_size_resize'])) { $ini['default_size_resize'] = 1; }
 156  if (!isset($ini['enable_resize_cache'])) { $ini['enable_resize_cache'] = 1; }
 157  
 158  //proccess options dependences

 159  // if 'enable_resize' disabled, we should to disable remaining resizing options

 160  if (!$ini['enable_resize']) {
 161      $ini['resize_size'] = 0;
 162      $ini['enable_smart_resize'] = 0;
 163      $ini['default_size_resize'] = 0;
 164      $ini['enable_resize_cache'] = 0;
 165  }
 166  //'enable_smart_resize' feature requires 'enable_size_lookup' option enabled

 167  if (!$ini['enable_size_lookup']) {
 168      $ini['enable_smart_resize'] = 0;
 169  }
 170  //'enable_omit_ext' feature is reasonable only when descriptions enabled

 171  if (!$ini['enable_description']) {
 172      $ini['enable_omit_ext'] = 0;
 173  }
 174  //turn off exif lookup if exif module not found

 175  if ($ini['enable_exif'] && !extension_loaded('exif')) {
 176      $ini['enable_exif'] = 0;
 177      $ini['enable_exif_date'] = 0;
 178  }
 179  if (!$ini['enable_html_container']) {
 180      $ini['enable_slideshow'] = 0;
 181  }
 182  
 183  //Check for GD2 lib

 184  if (!function_exists(imagecopyresampled)) {
 185      echo "Fatal error: GD2 library is not presented";
 186      exit;
 187  }
 188  
 189  //advanced options which aren't included in ini file

 190  //Assume that thumbnail creation supported for next file extensions

 191  $ini['thumbnailable_exts'] = 'jpg|jpeg|gif|png';
 192  //Always ignore files with next extensions

 193  $ini['ignore_exts'] = 'php|css|htm|html|sem';
 194  //Array containing list of filenames which should be omitted during directory loading. Wildcards aren't allowed.

 195  $ini['ignore_files'] = array('.', '..', $ini_ini_filename, $ini['description_filename'], $ini['cache_dir'], basename($_SERVER['SCRIPT_NAME']), '.htaccess', '.htpasswd', 'Thumbs.db', 'error_log', 'access_log', 'cgi-bin', '_notes');
 196  //EXIF comment strings which must be not shown.

 197  $ini['exif_comment_ignore_strings'] = array('MINOLTA DIGITAL CAMERA', 'KONICA MINOLTA DIGITAL CAMERA', 'OLYMPUS DIGITAL CAMERA');
 198  //Formatting of the timestamp taken from EXIF tags

 199  $ini['exif_date_format'] = 'd.m.Y H:i';
 200  
 201  //Load langpack file

 202  if ('' != $ini['langpack'] && 'thumb' != $_GET['action'] && 'resize' != $_GET['action']) {
 203      @include($ini['langpack']);
 204  }
 205  
 206  //begin html page

 207  function html_begin($title, $start, $header, $comment) {
 208      global $ini, $langpack;
 209      if (!$title || '.' == $title) {
 210          $title = $langpack['albums'];
 211      }
 212  ?>
 213  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 214  <html xmlns="http://www.w3.org/1999/xhtml">
 215  <head>
 216  <title><?php echo $title ?></title>
 217  <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $ini['charset'] ?>"/>
 218  <meta name="Generator" content="Weatimages"/>
 219  <?php
 220      if ('' != $ini['external_css'] && is_readable($ini['external_css'])) {
 221          print('<link href="' . ( ('/' != dirname($_SERVER['SCRIPT_NAME'])) ? dirname($_SERVER['SCRIPT_NAME']) : '' ) . '/' . $ini['external_css'] . '" rel="stylesheet" type="text/css">');
 222      }
 223      else {
 224  ?>
 225  <style type="text/css">
 226  <!--
 227  body {
 228      font-family: "Trebuchet MS", Verdana, Helvetica, Arial, sans-serif;
 229      color: #333333;
 230      font-size: 11px;
 231      text-align: center;
 232      margin-top: 0px;
 233      padding-top: 0px;
 234      margin-bottom: 2px;
 235      margin-left: 0px;
 236      margin-right: 0px;
 237      padding: 0px;
 238      background-color: #FFFFFF;
 239  }
 240  a, a:link, a:visited {
 241      color: #002277;
 242      text-decoration: underline;
 243  }
 244  a:hover {
 245      color: #EE5500;
 246  }
 247  a:active {
 248      color: #FF0000;
 249  }
 250  .weatimages_thumbnail_cell {/* cell displayed in album view and containing image thumbnail, filename, description */
 251      font-family: Helvetica, Arial, sans-serif;
 252      padding: 4px 4px 8px 4px;
 253      border-style: solid;
 254      border-color: #DDDDDD;
 255      text-align: center;
 256      vertical-align: top;
 257  }
 258  .weatimages_thumb_border {/* border of thumbnail */
 259      padding: 0px;
 260      border-width: 1px;
 261      border-style: solid;
 262      border-color: #999999;
 263      margin: 6px 6px 2px 6px;
 264  }
 265  .weatimages_link_size {/* links to original/resized image displayed under thumbnail in album */
 266      font-size: 9px;
 267      text-decoration: underline;
 268      color: #333366;
 269      text-align: center;
 270  }
 271  .weatimages_filename {/* filename displayed under image thumbnail in album */
 272      font-size: 9px;
 273      color: #666666;
 274      font-weight: bold;
 275      text-align: center;
 276  }
 277  .weatimages_image_desc {/* description (from textfile or exif) displayed under image thumbnail in album */
 278      color: #555555;
 279      text-align: center;
 280  }
 281  .weatimages_pages_navigator {/* pager */
 282      font-size: 12px;
 283      color: #003366;
 284      text-align: center;
 285  }
 286  .weatimages_header {/* page title line - album/image name (or description) */
 287      font-size: 15px;
 288      color: #333333;
 289      margin-top: 4px;
 290      margin-bottom: 2px;
 291      margin-left: 20px;
 292      margin-right: 20px;
 293  }
 294  .weatimages_comment {/* string under page title - album/image description */
 295      font-size: 12px;
 296      color: #555555;
 297      margin-bottom: 3px;
 298      margin-left: 20px;
 299      margin-right: 20px;
 300  }
 301  .weatimages_thumb_album_name {/* album name shown on the right of album thumbnail */
 302      font-size: 14px;
 303      color: #333333;
 304  }
 305  .weatimages_thumb_album_desc {/* album decsription shown on the right of album thumbnail */
 306      font-size: 12px;
 307      color: #555555;
 308  }
 309  .weatimages_bigimage {/* style for big version of image */
 310      padding: 0px;
 311      border-width: 1px;
 312      border-style: solid;
 313      border-color: #444444;
 314      margin: 5px;
 315      text-align: center;
 316  }
 317  .weatimages_container_navig {/* links to next/previous images displayed at the page vith big version of image */
 318      font-size: 11px;
 319      text-decoration: underline;
 320  }
 321  .weatimages_toppest_navig {/* style for a div containing top navigational links - to parent albums and next/prev images */
 322      color: #555555;
 323      background-color: #FAFBFB;
 324      padding-left: 20px;
 325      padding-right: 20px;
 326      margin-bottom: 5px;
 327  }
 328  .weatimages_hotkey_tip {/* tips beside links to next/previous images */
 329      font-size: 11px;
 330      color: #BBBBBB;
 331  }
 332  -->
 333  </style>
 334  <?php
 335      }//if ($ini['enable_external_css']) { ... } else {

 336  ?>
 337  <script language="javascript" type="text/javascript">
 338  <!--
 339  var slideshow_onload = null; //should be implemented as a function later in this document if it must be called onload

 340  var slideshow = null; //should be implemented as a function later in this document when this function is needle

 341  
 342  function go_link(link_object) {
 343      location.href = link_object.href;
 344  }
 345  function ev(e) { //process window events
 346      if (!e) var e = window.event;
 347      var key = (e.keyCode)? e.keyCode : ((e.which)?e.which:0);
 348      link_id = false;
 349      link_obj = null;
 350      if ((35 == key) && (true == e.ctrlKey)) { //ctrl + end
 351          link_id = 'page_last';
 352      }
 353      else if ((36 == key) && (true == e.ctrlKey)) { //ctrl + home
 354          link_id = 'page_first';
 355      }
 356      else if ((37 == key) && (true == e.ctrlKey)) { //ctrl + arrow left
 357          link_id = 'page_previous';
 358      }
 359      else if ((38 == key) && (true == e.ctrlKey)) { //ctrl + arrow up
 360          link_id = 'page_up';
 361      }
 362      else if ((39 == key) && (true == e.ctrlKey)) { //ctrl + arrow right
 363          link_id = 'page_next';
 364      }
 365      else if ((40 == key) && (true == e.ctrlKey)) { //ctrl + arrow down
 366          if (slideshow) {
 367              slideshow();
 368          }
 369      }
 370      if (link_id) link_obj = document.getElementById(link_id);
 371      if (link_obj) go_link(link_obj);
 372  }
 373  document.onkeydown = ev;
 374  
 375  function onload_init() {
 376      if (slideshow_onload) {
 377          slideshow_onload();
 378      }
 379  }
 380  //-->

 381  </script>
 382  </head>
 383  <body onload="onload_init();">
 384  <?php
 385      if ($ini['enable_custom_container']) {
 386          @include('weatimages_top.inc.php');
 387      }
 388      print($start);
 389      if ($header && '.' != $header) {
 390          print('<div align="center" class="weatimages_header">' . $header . '</div>');
 391      }
 392      if ($comment) {
 393          print('<div align="center" class="weatimages_comment">' . $comment . '</div>');
 394      }
 395  }//function html_begin(

 396  
 397  
 398  function html_end() {
 399      global $ini, $langpack;
 400  //You should not to remove the following software signature

 401  ?>
 402  <div align="right" style="font-size:9px; color:#909090; margin:15px;"> <?php echo $langpack['powered_by'] ?> <a href="http://nazarkin.name/projects/weatimages/">Weatimages</a></div>
 403  <?php
 404      if ($ini['enable_custom_container']) {
 405          @include('weatimages_bottom.inc.php');
 406      }
 407  ?>
 408  </body>
 409  </html>
 410  <?php
 411  }//function html_end(

 412  
 413  function fatal_error($title = 'Unknown error', $comment = '') {
 414      html_begin($title, '', $title, $comment);
 415      html_end();
 416      exit();
 417  }
 418  
 419  //calculate size of image after resizing

 420  function calc_size_after_resize($imagesize, $max_size) {
 421      //$imagesize - array containing size of source image: $imagesize[0] - width, $imagesize[1] - height

 422      //$max_size - maximal dimension of resulting image in pixels, or in percents

 423      //returns $resizedsize - size of image after resizing: $resizesize[0] - width, $resizesize[1] - height

 424      if (0 == $imagesize[0] || 0 == $imagesize[1]) { return array(0, 0); }
 425      if (preg_match('/([\.\d]+)\%$/', $max_size, $matches)) {
 426          $scale_factor = $matches[1] / 100;
 427          $resizedsize[0] = ceil( $imagesize[0] * $scale_factor );
 428          $resizedsize[1] = ceil( $imagesize[1] * $scale_factor );
 429          return $resizedsize;
 430      }
 431      if ($imagesize[0] > $imagesize[1]) { //if width > height
 432          $resizedsize[0] = $max_size; //width

 433          $resizedsize[1] = ceil( ($imagesize[1] / $imagesize[0]) * $resizedsize[0] ); //calculate height

 434      }
 435      else { //if height > width
 436          $resizedsize[1] = $max_size;
 437          $resizedsize[0] = ceil( ($imagesize[0] / $imagesize[1]) * $resizedsize[1] );
 438      }
 439      return $resizedsize;
 440  }//function calc_size_after_resize(

 441  
 442  
 443  //immediate image resizing function

 444  function resize_image ($image_input, $image_output, $max_size, $jpeg_quality) {
 445      //$image_input - path to file with original image

 446      //$image_output - path to file in which this function must to save resized image. if it empty then output image directly to browser

 447      //$max_size - maximal dimension of resulting image in pixels

 448      //$jpeg_quality - quality of resulting jpeg image

 449      $imagesize = getimagesize($image_input);
 450      if (!$imagesize) { fatal_error("Fatal error: getimagesize($image_input) failed"); }
 451      if (0 == $imagesize[0] || 0 == $imagesize[1]) { fatal_error("Fatal error: zero size happened"); }
 452      $resizedsize = calc_size_after_resize($imagesize, $max_size);
 453      //create image from source file

 454      switch ($imagesize[2]) { //find out a format of source image
 455          case 1: //gif
 456              $image = imagecreatefromgif($image_input);
 457              break;
 458          case 2: //jpg
 459              $image = imagecreatefromjpeg($image_input);
 460              break;
 461          case 3: //png
 462              $image = imagecreatefrompng($image_input);
 463              break;
 464          default: //unknown image type
 465              fatal_error("Fatal error: unsupported file type");
 466      }
 467      if (!$image) { fatal_error("Fatal error: cannot create image from source"); }
 468      $resized = imagecreatetruecolor($resizedsize[0], $resizedsize[1]);
 469      imagecopyresampled($resized, $image, 0, 0, 0, 0, $resizedsize[0], $resizedsize[1], $imagesize[0], $imagesize[1]);
 470      if (!$image_output) { //in this case we output image directly to the browser
 471          header('Content-Type: image/jpeg');
 472      }
 473      @imagejpeg($resized, $image_output, $jpeg_quality);
 474  }//function resize_image (

 475  
 476  
 477  //manages images resizing proccess and perform caching of resized images

 478  function resize_manager($image_input, $max_size, $cache_suffix, $is_cache_enabled) {
 479      //$image_input - path to file with original image

 480      //$max_size - maximal dimension of resulting image in pixels

 481      //$cache_suffix - suffix used to get filename of cached thumbnail from source image filename

 482      //$is_cache_enabled - indicates enabled or disabled caching of resized images

 483      global $ini;
 484      if (!@is_readable($image_input)) { fatal_error("Fatal error: requested image is not readable"); }
 485      $is_resized_sent = FALSE;
 486      if ($is_cache_enabled) {
 487          $file_cache = $ini['cache_dir'] . '/' . $image_input . $cache_suffix;
 488          if (!@is_readable($file_cache)) { //thumbnail file still don't exists
 489              $file_cache_dir = dirname($file_cache);
 490              if (!@is_dir($file_cache_dir)) {
 491                  //we need to create a copy of directories tree under cache directory

 492                  $dirs_must_exist = array($file_cache_dir);
 493                  while ('.' != $dirs_must_exist[count($dirs_must_exist)-1] && '/' != $dirs_must_exist[count($dirs_must_exist)-1]) {
 494                      array_push( $dirs_must_exist, dirname($dirs_must_exist[count($dirs_must_exist)-1]) );
 495                  }
 496                  array_pop($dirs_must_exist);
 497                  while (count($dirs_must_exist) > 0) {
 498                      $tmp_dir_new = array_pop($dirs_must_exist);
 499                      if (@is_dir($tmp_dir_new)) {
 500                          continue;
 501                      }
 502                      @mkdir($tmp_dir_new, 0777);
 503                      @chmod($tmp_dir_new, 0777);
 504                      clearstatcache();
 505                  }
 506              }
 507              if (@is_writable(dirname($file_cache))) {
 508                  $file_mutex = $ini['cache_dir'] . '/' . 'weatimages-mutex';//we allow only single image resizing proccess in a time to avoid memory issues on the server

 509                  $FP = @fopen($file_mutex, 'r');
 510                  if (FALSE === $FP) {
 511                      $FP = @fopen($file_mutex, 'w');
 512                      @chmod($file_mutex, 0666);
 513                  }
 514                  @flock($FP, LOCK_EX);
 515                  resize_image($image_input, $file_cache, $max_size, $ini['jpeg_quality']);
 516                  @chmod($file_cache, 0666);
 517                  @flock($FP, LOCK_UN);
 518                  @fclose($FP);
 519              }
 520              clearstatcache();
 521          }//if (!@is_readable($file_cache)) {

 522          if (@is_readable($file_cache)) { //check that we successfully created thumbnail file at the previous step
 523              header('Content-Type: image/jpeg');
 524              readfile($file_cache);
 525              $is_resized_sent = TRUE;
 526          }//if (@is_readable($file_cache)) {

 527       }
 528      if (!$is_resized_sent) { //we still don't have cached image. Let's resize image and output result to user's browser
 529          resize_image($image_input, '', $max_size, $ini['jpeg_quality']);
 530      }
 531  }//function resize_manager(

 532  
 533  
 534  //show pages-navigation-bar on thumbnails page if there are more then one page

 535  function show_pages_navigator($objects_count, $objects_on_page, $page_current, $page_query_string) {
 536      //$objects_count - total objects amount

 537      //$objects_on_page - amount of objects on a single page

 538      //$page_current - current page number

 539      //$page_query_string - string used as pagenumber variable name in http query

 540      global $ini, $langpack, $SERVER_PHP_SELF;
 541      if ($objects_count > $objects_on_page) {
 542          print('<div class="weatimages_pages_navigator"><span style="font-size:12px; color:#333333;">' . $langpack['page'] . ':&nbsp;&nbsp;</span>');
 543          //print link to previous page if current page isn't first

 544          if (1 != $page_current) {
 545              print('<a href="'
 546                  . url_compat( $SERVER_PHP_SELF . '?' . $page_query_string . '=' . ($page_current-1) )
 547                  . '" style="font-size:15px; font-weight:bold;">&lsaquo;&nbsp;&nbsp;</a>');
 548          }
 549          for ($i = 1; $objects_count > ($i-1)*$objects_on_page; $i++) {
 550              if ($i != $page_current) {
 551                  print('<a href="'
 552                      . url_compat($SERVER_PHP_SELF . '?' . $page_query_string . '=' . $i)
 553                      . '">&nbsp;' . $i . ' </a>');
 554              }
 555              else {
 556                  print('<font style="font-size: 14px; color:#555555; background-color:#F2F2F2; text-decoration:underline;">&nbsp;' . $i . '&nbsp;</font>');
 557              }
 558          }
 559          //print link to next page if current page isn't last

 560          if ( $objects_count > ($page_current*$objects_on_page) ) {
 561              print('<a href="'
 562                  . url_compat($SERVER_PHP_SELF . '?' . $page_query_string . '=' . ($page_current+1))
 563                  . '" style="font-size:15px; font-weight:bold;">&nbsp;&nbsp;&rsaquo;</a>');
 564          }
 565          print('</div>');
 566      }
 567  }//function show_pages_navigator(

 568  
 569  
 570  //load descriptions from desc file if feature enabled and file exists

 571  function load_descriptions($REQUEST_PATH) {
 572      global $ini;
 573      $descs = array();
 574      if ($ini['enable_description']) {
 575          $desc_filefullname = $REQUEST_PATH . '/' . $ini['description_filename'];
 576          if (@is_readable($desc_filefullname)) {
 577              $desc_file = file($desc_filefullname);
 578              if (is_array($desc_file)) {