[ PHPXref.com ] [ Generated: Sun Jul 20 17:32:46 2008 ] [ eSPG 1.72 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/ -> sp_def_vars.php (source)

   1  <?php
   2  //require('sp_config.php');

   3  
   4  define("VERSION","Enhanced Simple PHP Gallery 1.7");
   5  
   6  if ($editmode==true)
   7  {
   8      $modrewrite = false;
   9      $image_fade_in = false;
  10  }
  11  
  12  //DETECT AND STORE GD VERSION IF THIS IS THE FIRST TIME THE SCRIPT IS RUN.

  13  if(!isset($gd_version))
  14  {
  15      $config_file = @fopen('sp_config.php','r');
  16      $contents = fread($config_file, filesize('sp_config.php'));
  17      @fclose($config_file);
  18      $gd_version = gd_version();
  19      $contents = str_replace('?>','$gd_version = "' . $gd_version . "\";\n?" . ">",$contents);
  20      $config_file = @fopen('sp_config.php','w');
  21      @fwrite($config_file, $contents);
  22      //header("Location: $_SERVER[PHP_SELF]");

  23      //echo 'GD Detected!  Version: '.$gd_version.'.  Please reload this page to view your gallery.  You will not see this message again.';

  24  }
  25  
  26  //CREATE THE CACHE FOLDER IF CACHING IS ENABLED AND IT DOES NOT ALREADY EXIST.

  27  //IF THE FOLDER CANNOT BE CREATED, DISABLE CACHING

  28  
  29  if($cachethumbs && !file_exists($cachefolder))
  30  {
  31  //    if(!mkdir($cachefolder, 0755))

  32  if(!is_writable($cachefolder) || !mkdir($cachefolder, 0755))
  33      {
  34              $cachethumbs = false;
  35      }
  36  }
  37  if($cacheresized && !file_exists($cacheresizedfolder))
  38  {
  39  //    if(!mkdir($cacheresizedfolder, 0755))

  40  if(!is_writable($cachefolder) || !mkdir($cacheresizedfolder, 0755))
  41          $cacheresized = false;    
  42  }
  43  
  44  //CREATE THE cache.ini FILE IF IT DOES NOT EXIST.  PARSE INTO THE $cache_ini VARIABLE.

  45  if($cachethumbs)
  46  {
  47      $cache_ini = @fopen($cachefolder . "/cache.ini","a");
  48      @fclose($cache_ini);
  49      $cache_ini = @parse_ini_file($cachefolder . "/cache.ini",true);
  50  }
  51  
  52  //CREATE THE resized_cache.ini FILE IF IT DOES NOT EXIST.  PARSE INTO THE $resized_cache_ini VARIABLE.

  53  
  54  if($cacheresized)
  55  {
  56      $resized_cache_ini = @fopen($cacheresizedfolder . "/resized_cache.ini","a");
  57      @fclose($resized_cache_ini);
  58      $resized_cache_ini = @parse_ini_file($cacheresizedfolder . "/resized_cache.ini",true);
  59  }
  60  
  61  if(!$cachethumbs)
  62      clearThumbCache();
  63      
  64  if(!$cacheresized)
  65      clearResizedCache();
  66  
  67  //PARSE THE DESCRIPTIONS FILE

  68  $descriptions = @parse_ini_file('sp_descriptions.ini',true);
  69      if (! $descriptions) {
  70        die('Unable to read sp_descriptions.ini file.');
  71  }
  72  
  73  $parts = pathinfo($_SERVER['PHP_SELF']);
  74  $current_working_directory = !empty($parts['dirinfo']) ? $parts['dirinfo'] : '';
  75  
  76  $hide_folders[] = '.';
  77  $hide_folders[] = '..';
  78  $hide_folders[] = 'imagefade';
  79  $hide_folders[] = 'lang';
  80  $hide_folders[] = 'config';
  81  $hide_folders[] = $cachefolder;
  82  $hide_folders[] = $cacheresizedfolder;
  83  
  84  //IF A DIRECTORY LIST REQUEST WAS MADE, PARSE IT INTO THE $dir VARIABLE.

  85  
  86  $dir='.';
  87  if(isset($_GET['dir']))
  88      $dir = stripslashes($_GET['dir']);
  89      if($_GET['dir']=='')$dir='.';
  90  
  91  if($dir!=strip_tags($dir)){
  92      $dir='.';
  93      $_SERVER["QUERY_STRING"]='';
  94  }
  95  if(isset($_GET['file'])){
  96      $getfile=$_GET['file'];
  97      if($getfile!=strip_tags($_GET['file'])){
  98          $_GET['file']='';
  99          $_SERVER["QUERY_STRING"]='';
 100      }
 101      if($_GET['file']=='')$_GET['file']='';
 102  }
 103  
 104  //PREVENT REQUESTS FOR PARENT DIRECTORIES

 105  if(eregi('^(\.\.)',$dir))
 106      $dir='.';
 107  if(eregi('^/',$dir))
 108      $dir='.';
 109  if(!(strpos($dir,'..') === false))
 110      $dir='.';
 111      
 112  //GET THE NAME OF THE CURRENT FOLDER.

 113  $patharr = explode('/',$dir);
 114  $current = $patharr[count($patharr)-1];
 115  $alias = '';
 116  
 117  //GET THE FOLDER ALIAS, IF IT EXISTS

 118  $test_file = $current;
 119  if(is_numeric($test_file)) $test_file += 0;
 120  //if($descriptions[$current]['title'] != '')

 121  if(!empty($descriptions[$current]['title']))
 122      $alias = $descriptions[$test_file]['title'];
 123  else
 124      $alias = $current;
 125  
 126  //IF A FILE WAS REQUESTED FOR DISPLAY, READ THE PATH INTO THE $display_file VARIABLE

 127  $resize_file = !empty($_GET['file']) ? stripslashes($_GET['file']) : '';
 128  $display_file = eregi_replace('\./',returnCurrentWorkingDirectory() . '/',stripslashes($_GET['file']));
 129  //$display_file = str_replace('\./', returnCurrentWorkingDirectory() . '/', $resize_file);

 130  
 131  if($display_file != '')
 132  {
 133      if(!file_exists($resize_file))
 134      {
 135  //        $hash = md5(substr($resize_file,2,strlen($resize_file)-2));

 136          $hash = md5(substr($resize_file,2,strlen($resize_file)-2)."|".$maxwidth."x".$maxheight."|".$resizequality);
 137          if($cachethumbs)
 138          {
 139              @unlink($cachefolder . "/" . $hash . ".jpg");
 140              unset($cache_ini[$hash]);
 141              write_ini_file($cachefolder . "/cache.ini",$cache_ini);
 142          }
 143          if($cacheresized)
 144          {
 145              @unlink($cacheresizedfolder . "/" . $hash . ".jpg");
 146          }
 147          $location = returnCurrentWorkingDirectory();
 148          if(empty($location))
 149              $location = '/';
 150          header("Location: " . $location);
 151      }
 152      if(eregi(".*(\.jpg|\.gif|\.png|\.jpeg)",basename($_GET['file'])))
 153          $current = basename($_GET['file']);
 154      else
 155      {
 156          exit;
 157      }
 158      if (!empty($descriptions[$current]['title']))
 159          $alias = stripslashes($descriptions[$current]['title']);
 160      else
 161          $alias = $current;
 162  
 163      // DEFINE IMAGE WIDTH AND HEIGHT ATTRIBUTES

 164      list($img_attr_width,$img_attr_height,,$img_attr) = getimagesize($resize_file);
 165      if(function_exists('imagecreate') && $maxwidth != 0 && $maxheight != 0 && $resize)
 166      {
 167          $xratio = $maxwidth /$img_attr_width;
 168          $yratio = $maxheight/$img_attr_height;
 169          if($xratio < 1 || $yratio < 1 && $gd_version >= 2)
 170          {
 171              if($xratio < $yratio)
 172              {
 173                  $img_attr_width  = $maxwidth;
 174                  $img_attr_height = floor($img_attr_height*$xratio);
 175              }
 176              else
 177              {
 178                  $img_attr_width  = floor($img_attr_width*$yratio);
 179                  $img_attr_height = $maxheight;
 180              }
 181          }
 182          $img_attr = 'width="' . $img_attr_width . '" height="' . $img_attr_height . '"';
 183      }
 184  }
 185  
 186  if($alias != '.' && $alias != '')
 187      $page_title = $title . ": " . $alias;
 188  else 
 189      $page_title = $title;
 190      
 191  if(!empty($_GET['dir']) || (empty($_GET['dir']) && empty($_GET['file'])))
 192  {
 193      $imglink = array(); //AN ARRAY TO HOLD LINKS TO THE IMAGES

 194      $dirlink = array(); //AN ARRAY TO HOLD LINKS TO SUB-DIRECTORIES

 195  
 196      foreach(getDirList() as $file)
 197      {
 198          $path = $dir . "/" . $file;
 199          $webpath = substr($path,2,strlen($path)-2);
 200          
 201          //IF THE CURRENT ITEM IS AN IMAGE, ADD A THE LINK TEXT TO THE $imglink ARRAY

 202          if( eregi(".*(\.jpg|\.gif|\.png|\.jpeg)", $file))
 203          {
 204              $cached_img = $cachefolder . "/" . md5($webpath) . ".jpg";
 205  
 206              // DEFINE IMAGE WIDTH AND HEIGHT ATTRIBUTES

 207              list($img_attr_width, $img_attr_height) = getimagesize($path);
 208              $xratio = $maxthumbwidth /$img_attr_width;
 209              $yratio = $maxthumbheight/$img_attr_height;
 210  
 211              if($xratio < 1 || $yratio < 1 && $gd_version >= 2)
 212              {
 213                  if($xratio < $yratio)
 214                  {
 215                      $img_attr_width  = $maxthumbwidth;
 216                      $img_attr_height = floor($img_attr_height*$xratio);
 217                  }
 218                  else
 219                  {
 220                      $img_attr_width  = floor($img_attr_width*$yratio);
 221                      $img_attr_height = $maxthumbheight;
 222                  }
 223              }
 224              $img_attr = 'width="' . $img_attr_width . '" height="' . $img_attr_height . '"';
 225  
 226              $link = "\t<div class=\"imgwrapper\">";
 227  
 228              if ($modrewrite)
 229              {
 230                  $link .= "<a href=\"" . returnCurrentWorkingDirectory() . "/file/$webpath\">";
 231                  if($cachethumbs && file_exists($cached_img) && sizeMatches($cached_img) && cacheLinkMatch(md5($webpath)) && cacheFilesizeMatch(md5($webpath),filesize($webpath)))
 232                      $link .= "<img src=\"" . returnCurrentWorkingDirectory() . '/' . $cached_img . "\" " .  $img_attr . " alt=\"". (!empty($descriptions[$file]['alt']) ? stripslashes($descriptions[$file]['alt']) : '') . "\" title=\"\" />";
 233                  else
 234                      $link .= "<img src=\"" . returnCurrentWorkingDirectory() . "/thumb/$webpath\" " . $img_attr . " alt=\"". (!empty($descriptions[$file]['alt']) ? stripslashes($descriptions[$file]['alt']) : '') . "\" title=\"\" />";
 235              }
 236              else
 237              {
 238                  $link .= "<a href=\"".$_SERVER['PHP_SELF']."?file=$path\">";
 239                  if($cachethumbs && file_exists($cached_img) && sizeMatches($cached_img) && cacheLinkMatch(md5($webpath)) && cacheFilesizeMatch(md5($webpath),filesize($webpath)))
 240                      $link .= "<img src=\"" . $current_working_directory . $cached_img . "\" " . $img_attr . " alt=\"". (!empty($descriptions[$file]['alt']) ? stripslashes($descriptions[$file]['alt']) : '') . "\" title=\"\" />";
 241                  else
 242                      $link .= "<img src=\"sp_getthumb.php?source=$webpath\" " . $img_attr . " alt=\"".(!empty($descriptions[$file]['alt']) ? stripslashes($descriptions[$file]['alt']) : '') ."\" title=\"\" />";
 243              }
 244              if($showimgtitles || $showdatesonthumbspage)
 245              {
 246                  $link .= "<span>";
 247                  if($showimgtitles)
 248                  {
 249                      if(!empty($descriptions[$file]['title']))
 250                          $link .= stripslashes($descriptions[$file]['title']);
 251                      else
 252                          $link .= $file;
 253                  }
 254                  if($showimgtitles && $showdatesonthumbspage && !empty($descriptions[$file]['date']))
 255                      $link .= "<br/>";
 256                  if($showdatesonthumbspage && !empty($descriptions[$file]['date']))
 257                      $link .= $descriptions[$file]['date'];
 258                  $link .= "</span>";
 259              }
 260              $link .= "</a></div>\n";
 261              $imglink[] = $link;
 262          }
 263          //IF THE CURRENT ITEM IS A DIRECTORY, ADD THE LINK TEXT TO THE $dirlink ARRAY

 264          else if(is_dir($path) && !in_array($file, $hide_folders))
 265          {
 266              $num_images = getNumImages($path);
 267              $num_dir = getNumDir($path);
 268              if($num_images != 0 || $num_dir != 0 || $editmode==true) //DWW
 269              {
 270                  $test_file = $file;
 271                  if(is_numeric($test_file)) $test_file += 0;
 272                  if(!empty($descriptions[$file]['title']))
 273                      $file = stripslashes($descriptions[$test_file]['title']);
 274                      
 275                  if($cat_thumbs==true){
 276                      $random= randImg($webpath);
 277                      $ins_img = $random;
 278                  }else{
 279                      $ins_img = '';
 280                  }
 281  
 282                  if($modrewrite)
 283                      $dir_string = "<a href=\"" . returnCurrentWorkingDirectory() . "/folder/$webpath\">".$ins_img. $file . "</a>";        
 284                  else
 285                      $dir_string = "<a href=\"" . $_SERVER['PHP_SELF'] . "?dir=$path\">".$ins_img. $file . "</a>";
 286  
 287                  if($showfolderdetails)
 288                  {
 289                      $img_s = ($num_images == 1) ? $GLOBALS['lang_img']:$GLOBALS['lang_imgs'];
 290                      $dir_s = ($num_dir == 1) ? $GLOBALS['lang_dir']:$GLOBALS['lang_dirs'];
 291                      if($num_images != 0 || $num_dir != 0)
 292                          $dir_string .= " (";
 293                      if($num_images != 0)
 294                      {
 295                          $dir_string .= $num_images . $img_s;
 296                          if($num_dir != 0)
 297                              $dir_string .= ', ';
 298                          else
 299                              $dir_string .= ')';
 300                      }
 301                      if($num_dir != 0)
 302                      {
 303                          $dir_string .= $num_dir .  $dir_s . ')';
 304                      }                
 305                  }
 306                  $dirlink[$file] = $dir_string;
 307              }
 308          if ($sortfoldersbytitle) uksort($dirlink, "strnatcasecmp");
 309          }
 310          //IF THE CURRENT ITEM IS NOT AN IMAGE AND IS NOT A DIRECTORY, IGNORE IT

 311      }
 312  }
 313  if(!empty($_GET['dir']) || (empty($_GET['dir']) && empty($_GET['file'])))
 314  {
 315      $imglist = array(); //AN ARRAY TO HOLD A LIST OF THE IMAGES

 316      foreach(getDirList() as $file)
 317      {
 318          $path = $dir . "/" . $file;
 319          $webpath = substr($path,2,strlen($path)-2);
 320  
 321          //IF THE CURRENT ITEM IS AN IMAGE, ADD FILE AND PATH TO $imglist ARRAY

 322          if( eregi(".*(\.jpg|\.gif|\.png|\.jpeg)", $file))
 323          {
 324              if($modrewrite)
 325              {
 326                  $list  = returnCurrentWorkingDirectory() . "/file/$webpath";
 327              }
 328              else
 329              {
 330                  $list  = $_SERVER['PHP_SELF']."?file=".$path;
 331              }
 332              $imglist[] = $list;
 333          }
 334      }
 335  }
 336  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]