[ PHPXref.com ] [ Generated: Sun Jul 20 18:39:36 2008 ] [ MG2 0.5.1 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/includes/ -> mg2_functions.php (source)

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

   3  //                                                                              //

   4  //    MG2                                                                       //

   5  //    A PHP/HTML based image gallery script.                                    //

   6  //                                                                              //

   7  //    Copyright 2005 by Thomas Rybak                                            //

   8  //    http://www.minigal.dk                                                     //

   9  //    support@minigal.dk                                                        //

  10  //                                                                              //

  11  //    The script utilises Exif reader v 1.2 (free to use)                       //

  12  //    Exif reader v 1.2                                                         //

  13  //    By Richard James Kendall (richard@richardjameskendall.com)                //

  14  //                                                                              //

  15  //    -----------------                                                         //

  16  //                                                                              //

  17  //    MG2 is free software; you can redistribute it and/or modify               //

  18  //    it under the terms of the GNU General Public License as published by      //

  19  //    the Free Software Foundation; either version 2 of the License, or         //

  20  //    (at your option) any later version.                                       //

  21  //                                                                              //

  22  //    MG2 is distributed in the hope that it will be useful,                    //

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

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

  25  //    GNU General Public License for more details.                              //

  26  //                                                                              //

  27  //    TO COMPLY WITH THIS LICENSE, DO NOT REMOVE THE LINK TO THE MINIGAL        //

  28  //    WEBSITE FROM YOUR GALLERY FRONT PAGE. THIS IS THE LEAST YOU CAN DO TO     //

  29  //    SUPPORT THE DEVELOPMENT OF MG2!                                           //

  30  //                                                                              //

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

  32  //    along with this program; if not, you can find it here:                    //

  33  //    http://www.gnu.org/copyleft/gpl.html                                      //

  34  //                                                                              //

  35  //    -----------------                                                         //

  36  //                                                                              //

  37  //    If you find this script useful, please make a donation via the main       //

  38  //    website:                                                                  //

  39  //                          http://www.minigal.dk                               //

  40  //                                                                              //

  41  //////////////////////////////////////////////////////////////////////////////////

  42  
  43  class mg2db{
  44  
  45    //

  46    // SORT SEARCH RESULTS

  47    //

  48    function sort($datatable,$field,$mode) {
  49       $i_cnt = count($datatable);
  50       for($i=0;$i<$i_cnt;$i++) {
  51         foreach($datatable[$i] as $key => $value) {
  52             $array[$key][$i] = $value;
  53         }
  54       }
  55       $mode == 0 ? asort($array[$field]) :  arsort($array[$field]);
  56       $_keys = array_keys($array[$field]);
  57       for($i=0;$i<$i_cnt;$i++) {
  58         foreach($array as $key => $value) {
  59             $_hash[$i][$key] = $array[$key][$_keys[$i]];
  60         }
  61       }
  62       return $_hash;
  63    }
  64  
  65    //

  66    // UPDATE DATABASE FROM TEMP FILES

  67    //

  68    function updateDB(){
  69      $iDB = "mg2db_idatabase.php";
  70      $iDB_temp = "mg2db_idatabase_temp.php";
  71  
  72      $fDB = "mg2db_fdatabase.php";
  73      $fDB_temp = "mg2db_fdatabase_temp.php";
  74  
  75      //OVERWRITE ORIGINAL WITH TEMP FILE IF CHANGED

  76      if (IS_FILE($iDB) && IS_FILE($iDB_temp) && filemtime($iDB) < filemtime($iDB_temp)){
  77        if (!copy($iDB_temp, $iDB)) {
  78            $this->log("ERROR: Failed to copy temporary image database file");
  79          echo "MG2 ERROR: Failed to copy temp file (function 'readDB')";
  80          exit();
  81        }
  82  
  83      }
  84      if (IS_FILE($fDB) && IS_FILE($fDB_temp) && filemtime($fDB) < filemtime($fDB_temp)){
  85        if (!copy($fDB_temp, $fDB)) {
  86            $this->log("ERROR: Failed to copy temporary folder database file");
  87          echo "MG2 ERROR: Failed to copy temp file (function 'readDB')";
  88          exit();
  89        }
  90      }
  91    }
  92  
  93    //

  94    // READ ENTIRE DATABASE

  95    //

  96    function readdb(){
  97      $iDB = "mg2db_idatabase.php";
  98      $fDB = "mg2db_fdatabase.php";
  99  
 100      $this->updateDB();
 101      if (is_file($iDB)){
 102        $fd = fopen($iDB,"r");
 103        $this->autoid = trim(fgets($fd,4096));
 104        while (!feof ($fd)) {
 105          if(fgets($fd,2) == "*")
 106            $this->all_images[] = fgetcsv($fd,4096,"*");
 107        }
 108        fclose($fd);
 109      }else {
 110        $fd = fopen($iDB,"w");
 111        fclose($fd);
 112      }
 113  
 114      if (is_file($fDB)){
 115        $fd = fopen($fDB,"r");
 116        $this->folderautoid = trim(fgets($fd,4096));
 117        while (!feof ($fd)) {
 118          if(fgets($fd,2) == "*")
 119            $this->all_folders[] = fgetcsv($fd,4096,"*");
 120        }
 121        fclose($fd);
 122      }else {
 123        $fd = fopen($fDB,"w");
 124        fwrite($fd,"1\n");
 125        fwrite($fd,"*1*root*root*1*0*****");
 126        fclose($fd);
 127      }
 128    }
 129  
 130    //

 131    // SELECT ENTRIES FROM DATABASE

 132    //

 133    function select($key,$array,$row,$sortrow,$sortmode){
 134      for ($idx=0; $idx < count($array); $idx++){
 135        if ($array[$idx][$row] == $key) $selectarray[] = $array[$idx];
 136      }
 137      if ($key == "*")
 138        $selectarray = $array;
 139      if (is_array($selectarray))
 140        $selectarray = $this->sort($selectarray,$sortrow,$sortmode);
 141      return $selectarray;
 142    }
 143  
 144    function insert($filename="", $folder="1", $password="", $description="", $filesize="", $width="", $height="", $tn_width="", $tn_height="", $filetime=""){
 145      $this->all_images[] = array(($this->autoid+1), $filename, $folder, $password, $description, $filesize, $width, $height, $tn_width, $tn_height, $filetime);
 146      $this->autoid = $this->autoid + 1;
 147    }
 148    
 149    //

 150    // WRITE IMAGE DATABASE

 151    //

 152    function write_iDB(){
 153      if (count($this->all_images) > 0) {
 154        unset($buffer);
 155        for ($i=0; $i < count($this->all_images); $i++){
 156          for ($j=0; $j < count($this->all_images[$i]); $j++){
 157            $buffer .= "*" . $this->all_images[$i][$j];
 158          }
 159          $buffer .= "\n";
 160        $fd = fopen("mg2db_idatabase_temp.php","w+");
 161        if (flock($fd, LOCK_EX)) { // do an exclusive lock
 162          ftruncate($fd, 0);
 163          fwrite($fd, $this->autoid . "\n");
 164          fwrite($fd, $buffer);
 165          flock($fd, LOCK_UN); // release the lock

 166          fclose($fd);
 167        } else {
 168          $this->log("ERROR: Could not lock image database for writing");
 169          echo "MG2 ERROR: Could not lock temp file (function 'write_iDB')";
 170          }
 171        }
 172        $this->log("Writing image database");
 173      } else $this->log("ERROR: Writing image database - Image array empty!");
 174    }
 175  
 176    //

 177    // WRITE FOLDER DATABASE

 178    //

 179    function write_fDB(){
 180      if (count($this->all_folders) > 0) {
 181        unset($buffer);
 182        for ($i=0; $i < count($this->all_folders); $i++){
 183          for ($j=0; $j < count($this->all_folders[$i]); $j++){
 184            $buffer .= "*" . $this->all_folders[$i][$j];
 185          }
 186          $buffer .= "\n";
 187        $fd = fopen("mg2db_fdatabase_temp.php","w+");
 188        if (flock($fd, LOCK_EX)) { // do an exclusive lock
 189          ftruncate($fd, 0);
 190          fwrite($fd, $this->folderautoid . "\n");
 191          fwrite($fd, $buffer);
 192          flock($fd, LOCK_UN); // release the lock

 193          fclose($fd);
 194        } else {
 195          $this->log("ERROR: Could not lock folder database file for writing");
 196          echo "MG2 ERROR: Could not lock temp file (function 'write_fDB')";
 197          }
 198        }
 199        $this->log("Writing folder database");
 200      } else $this->log("ERROR: Writing image database - Image array empty!");
 201    }
 202  
 203    //

 204    // SEARCH DATABASE FOR FILENAME

 205    //

 206    function inDB($filename){
 207      $search = $this->select($filename,$this->all_images,1,1,0);
 208      if (count($search) == 0){
 209        return false;
 210      } else return true;
 211    }
 212  
 213    //

 214    // NEW DATABASE ENTRY

 215    //

 216    function addnew($filename, $folder="1"){
 217      if (is_file("pictures/" . $filename) && $this->inDB == false){
 218  
 219        list($width, $height, $type, $attr) = getimagesize("pictures/" . $filename);
 220        $filesize = filesize("pictures/" . $filename);
 221  
 222        if (is_file("pictures/" . $this->thumb($filename))){
 223          list($tn_width, $tn_height, $type, $attr) = getimagesize("pictures/" . $this->thumb($filename));
 224        }
 225          $filetime = filectime("pictures/" . $filename);
 226        $this->insert($filename, $folder, $password, $description, $filesize, $width, $height, $tn_width, $tn_height, $filetime);
 227        return true;
 228      } else return false;
 229    }
 230  
 231    //

 232    // IMPORT NEW IMAGES

 233    //

 234    function importnewimages(){
 235      $allowed_extensions = explode(",", $this->extensions);
 236      if (!$_REQUEST['list']) $_REQUEST['list'] = "1";
 237      if ($handle = opendir("pictures/")) {
 238        while (false !== ($file = readdir($handle))) {
 239          $fileInfo = pathinfo("pictures/" . $file);
 240          $extension = strtolower($fileInfo["extension"]);
 241          if(is_file("pictures/" . $file) && !$this->inDB($file) && in_array(strtolower($extension), $allowed_extensions) && strpos($file, "_medium") === false && strpos($file, "_thumb") === false){
 242            $this->log("Importing '$file' (" . filesize("pictures/" . $file). " bytes)");
 243            $imported++;
 244            @chmod("pictures/" . $file,0644);
 245            $this->createthumb($file);
 246            $this->log(" * finished creating thumbnails");
 247            $this->addnew($file,$_REQUEST['list']);
 248            $this->log(" * finished adding file to database");
 249            $this->log(" = finished importing '$file'");
 250          }
 251        }
 252      $this->write_iDB();
 253      closedir($handle);
 254      $this->updateDB();
 255      return $imported;
 256      }
 257    }
 258  
 259    //

 260    // IMAGE NAVIGATION

 261    //

 262    function imagenavigation($result){
 263      $result = $this->select($result,$this->all_images,2,$this->folder_sortby,$this->folder_sortway);
 264      $folders = $this->select($result[0][2],$this->all_folders,1,0,0);
 265      for($i=0; $i < count($result);$i++){
 266        if ($_REQUEST['id'] == $result[$i][0]){
 267          $this->page = ceil(($i + 1 + count($folders)) / ($this->imagerows * $this->imagecolumns));
 268      $this->nav_current = $i + 1;
 269      break;
 270        }
 271      }
 272      $this->nav_total = count($result);
 273      $navtxt_total = $this->lang['total'];
 274      if ($result[$this->nav_current - 2][0] != "") $this->nav_prev = "<a href=\"" . $this->indexfile . "?id=" . $result[$this->nav_current - 2][0] . "\">" . $this->lang['prev']. "</a>";
 275      else $this->nav_prev = $this->lang['prev'];
 276  
 277      if ($result[0][0] != $_REQUEST['id']) $this->nav_first = "<a href=\"" . $this->indexfile . "?id=" . $result[0][0] . "\">" . $this->lang['first']. "</a>";
 278      else $this->nav_first = $this->lang['first'];
 279  
 280      if ($result[$this->nav_current][0] != "") $this->nav_next = "<a href=\"" . $this->indexfile . "?id=" . $result[$this->nav_current][0] . "\">" . $this->lang['next']. "</a>";
 281      else $this->nav_next = $this->lang['next'];
 282  
 283      if ($this->nav_total != $this->nav_current) $this->nav_last = "<a href=\"" . $this->indexfile . "?id=" . $result[$this->nav_total - 1][0] . "\">" . $this->lang['last']. "</a>";
 284      else $this->nav_last = $this->lang['last'];
 285    }
 286  
 287    //

 288    // GALLERY NAVIGATION

 289    //

 290    function gallerynavigation($delimiter){
 291      echo "&nbsp;";
 292      if ($_REQUEST['list'] != "") $result = $_REQUEST['list'];
 293      if ($_REQUEST['id'] != "") {
 294        $getfolder = $this->select($_REQUEST['id'],$this->all_images,0,1,0);
 295        $result = $getfolder[0][2];
 296        $imgdisplay = 1;
 297      }
 298      while ($result != "1" && $result != ""){
 299        $result = $this->select($result,$this->all_folders,0,1,0);
 300        $folders[] = $result[0][1];
 301        $result = $result[0][1];
 302      }
 303  
 304        if ($this->websitelink != "") echo "<a href=\"$this->websitelink\" target=\"_self\">" . $this->lang['website'] . "</a>";
 305  
 306      for ($i=count($folders) - 1; $i >= 0; $i--){
 307        if ($folders[$i] == "1"){
 308          if ($this->websitelink != "") echo " $delimiter ";
 309          echo "<a href=\"?list=" . $folders[$i] . "\">" . $this->lang['gallery'] . "</a>";
 310        }else
 311        echo " $delimiter <a href=\"?list=" . $folders[$i] . "\">" . $this->getfoldername($folders[$i]) . "</a>";
 312      }
 313      if ($imgdisplay == 1){
 314        if ($getfolder[0][2] == "1"){
 315          if ($this->websitelink != "") echo " $delimiter ";
 316          echo "<a href=\"?list=" . $folders[$i] . "\">" . $this->lang['gallery'] . "</a>";
 317        }else
 318        echo " $delimiter <a href=\"?list=" . $getfolder[0][2] . "\">" . $this->getfoldername($getfolder[0][2]) . "</a>";
 319      }
 320    }
 321  
 322    //

 323    // PAGE NAVIGATION

 324    //

 325    function pagenavigation($pages, $list) {
 326      if ($pages > 1) {
 327        echo "<p align=\"center\">" . $this->lang['page'] . " ";
 328        for ($i=1; $i <= $pages; $i++) {
 329      if ($i == $_REQUEST['page']) {
 330        echo "| $i ";
 331      } else
 332      echo "| <a href=\"" . $this->galleryindex . "?list=$list&amp;page=$i\" target=\"_self\">" . $i . "</a> ";
 333        }
 334        if ($_REQUEST['page'] == "all") {
 335          echo "| " . $this->lang['all'];
 336        } else
 337        echo "| <a href=\"" . $this->galleryindex . "?list=$list&amp;page=all\" target=\"_self\">" . $this->lang['all']. "</a>";
 338        echo "</p>";
 339      }
 340    
 341    }
 342  
 343    //

 344    // SEARCH IMAGE DATABASE

 345    //

 346    function search_iDB($string, $field){
 347      for ($i=0; $i < count($this->all_images); $i++) {
 348        if ($this->all_images[$i][$field] == $string) {
 349      return $i;
 350        }
 351      }
 352    }
 353  
 354    //

 355    // SEARCH FOLDER DATABASE

 356    //

 357    function search_fDB($string, $field){
 358      for ($i=0; $i < count($this->all_folders); $i++) {
 359        if ($this->all_folders[$i][$field] == $string) {
 360      return $i;
 361        }
 362      }
 363    }
 364  
 365    //

 366    // DETERMINE THUMBNAIL

 367    //

 368    function getthumb($folder){
 369      unset($this->subfolder_class);
 370      unset($this->icon_comp);
 371      $subfiles = $this->select($folder,$this->all_images,2,1,0);
 372      $subfolders = $this->select($folder,$this->all_folders,1,1,0);
 373      $currentfolder = $this->select($folder,$this->all_folders,0,1,0);
 374  
 375      // DOES STANDARD THUMB EXIST?

 376      if ($currentfolder[0][7] != "") {
 377        if ($this->foldericons == 1) {
 378          $this->width = 150;
 379          $this->height = 100;
 380          $icon_comp = 2;
 381          $this->subfolder_class = "subfolder";
 382          return "skins/$this->activeskin/images/folder.gif";
 383        }
 384        $this->width = $currentfolder[0][8];
 385        $this->height = $currentfolder[0][9];
 386        $this->subfolder_class = "subfolder border";
 387        return "pictures/" . $currentfolder[0][7];
 388      }
 389      
 390      // IS FOLDER LOCKED?

 391      else if ($currentfolder[0][5] != "") {
 392        $this->width = 150;
 393        $this->height = 100;
 394        $this->subfolder_class = "subfolder";
 395        $icon_comp = 2;
 396        return "skins/$this->activeskin/images/locked.gif";
 397      }
 398  
 399      // DOES FOLDER CONTAIN IMAGES?

 400      if (count($subfiles) > 0){
 401        if ($this->foldericons == 1) {
 402          $this->width = 150;
 403          $this->height = 100;
 404          $this->subfolder_class = "subfolder";
 405          $icon_comp = 2;
 406          return "skins/$this->activeskin/images/folder.gif";
 407        }
 408        $random = array_rand($subfiles);
 409        $this->width = $subfiles[$random][8];
 410        $this->height = $subfiles[$random][9];
 411        $this->subfolder_class = "subfolder border";
 412        return "pictures/" . $this->thumb($subfiles[$random][1]);
 413  
 414      // DOES FOLDER CONTAIN FOLDERS?

 415      }else if (count($subfolders) > 0) {
 416        $this->width = 150;
 417        $this->height = 100;
 418        $this->subfolder_class = "subfolder";
 419        $icon_comp = 2;
 420        return "skins/$this->activeskin/images/folder.gif";
 421      }
 422  
 423      // FOLDER IS EMPTY

 424      else{
 425        $this->width = "150";
 426        $this->height = "100";
 427        $this->subfolder_class = "subfolder";
 428        $this->icon_comp = 2;
 429        return "skins/$this->activeskin/images/emptyfolder.gif";
 430      }
 431    }
 432  
 433    //

 434    // READ FOLDER SORTING SETTINGS

 435    //

 436    function getfoldersettings($list){
 437      $this->folder_pwd = 0;
 438      $result = $this->select($list,$this->all_folders,0,0,0);
 439      if($result[0][3] == "") $this->folder_sortby = 1;
 440      else $this->folder_sortby = $result[0][3];
 441      if($result[0][4] == "") $this->folder_sortway = 1;
 442      else $this->folder_sortway = $result[0][4];
 443      $this->introtext = $result[0][10];
 444      if($result[0][5] != "") $this->folder_pwd = 1;
 445    }
 446    
 447    //

 448    // DELETE DATABASE ENTRY

 449    //

 450    function array_delete ( $array, $index ) {
 451     if ( is_array ( $array ) ) {
 452       unset ( $array[$index] );
 453       array_unshift ( $array, array_shift ( $array ) );
 454       return $array;
 455       }
 456     else {
 457       return false;
 458       }
 459      $this->log("Database entry deleted");
 460     }
 461  
 462    //

 463    // DECIMAL TO FRACTION

 464    //

 465    function dec2frac( $decimal ) {
 466      $decimal = (string)$decimal;
 467      $num = '';
 468      $den = 1;
 469      $dec = false;
 470  
 471      // find least reduced fractional form of number

 472      for( $i = 0, $ix = strlen( $decimal ); $i < $ix; $i++ )
 473      {
 474       // build the denominator as we 'shift' the decimal to the right

 475       if( $dec ) $den *= 10;
 476  
 477       // find the decimal place/ build the numberator

 478       if( $decimal{$i} == '.' ) $dec = true;
 479       else $num .= $decimal{$i};
 480      }
 481      $num = (int)$num;
 482  
 483      // whole number, just return it

 484      if( $den == 1 ) return $num;
 485  
 486      $num2 = $num;
 487      $den2 = $den;
 488      $rem  = 1;
 489      // Euclid's Algorithm (to find the gcd)

 490      while( $num2 % $den2 ) {
 491       $rem = $num2 % $den2;
 492       $num2 = $den2;
 493       $den2 = $rem;
 494      }
 495      if( $den2 != $den ) $rem = $den2;
 496  
 497      // now $rem holds the gcd of the numerator and denominator of our fraction

 498      return ($num / $rem ) . "/" . ($den / $rem);
 499    }
 500  
 501    //

 502    // GET GD LIB VERSION

 503    //

 504    function gd_version() {
 505      $gdInfo = gd_info();
 506      $this->gd_version_number = trim(ereg_replace("[A-Za-z()]", "", $gdInfo["GD Version"]));
 507      return $this->gd_version_number;
 508    }
 509  
 510    //

 511    // GET FOLDER NAME

 512    //

 513    function getfoldername($id) {
 514      $result = $this->select($id,$this->all_folders,0,1,0);
 515      if ($result[0][2] == "1") $result[0][2] = "root";
 516      return $result[0][2];
 517    }
 518  
 519    //

 520    // SUBGALLERY SECURITY

 521    //

 522    function gallerysecurity($folderpassword) {
 523      if (md5(strrev(md5($_REQUEST["password"]))) == $folderpassword) {
 524        $_SESSION["folderpassword"] = md5(strrev(md5($_REQUEST["password"])));
 525      }else if ($_SESSION["folderpassword"] == $folderpassword) {
 526      }else if ($folderpassword != "" && md5(strrev(md5($_REQUEST["password"]))) != $folderpassword) {
 527        include("skins/$this->activeskin/templates/thumbnails_password.php");
 528        exit();
 529      }
 530    }
 531  
 532    function charfix($string) {
 533      $string = str_replace("*","#",$string);
 534      $string = str_replace(chr(92).chr(34),"&quot;",$string);
 535      $string = str_replace("\'","'",$string);
 536      $string = str_replace(chr(34),"&quot;",$string);
 537      return $string;
 538    }
 539  
 540    function readcomments($filename) {
 541      if (is_file($filename)){
 542        $fd = fopen($filename,"r");
 543        while (!feof ($fd)) {
 544          if(fgets($fd,2) == "*")
 545            $this->comments[] = fgetcsv($fd,4096,"*");
 546        }
 547        fclose($fd);
 548        $this->comments = $this->sort($this->comments,0,1);
 549        $this->log("Read file comments from '$filename'");
 550      }
 551    }
 552  
 553    function writecomments($filename) {
 554      $filename = "pictures/" . $filename;
 555      unset($buffer);
 556      if (count($this->comments) != 0) {
 557      for ($i=0; $i < count($this->comments); $i++){
 558        for ($j=0; $j < count($this->comments[$i]); $j++){
 559          $buffer .= "*" . $this->comments[$i][$j];
 560        }
 561        $buffer .= "\n";
 562      $fd = fopen($filename,"w+");
 563      if (flock($fd, LOCK_EX)) { // do an exclusive lock
 564        ftruncate($fd, 0);
 565        fwrite($fd, $buffer);
 566        flock($fd, LOCK_UN); // release the lock

 567        fclose($fd);
 568        $this->log("Wrote comment to '$filename'");
 569      } else {
 570        $this->log("ERROR: Could not lock commentfile '$filename' for writing");
 571        echo "MG2 ERROR: Could not lock $filename (function 'writecomments')";
 572        }
 573      }
 574      } else unlink($filename);
 575    }
 576  
 577    function addcomment() {
 578      $_REQUEST['filename'] = $this->charfix($_REQUEST['filename']);
 579      $_REQUEST['input'] = $this->charfix($_REQUEST['input']);
 580      $_REQUEST['email'] = $this->charfix($_REQUEST['email']);
 581      $_REQUEST['name'] = $this->charfix($_REQUEST['name']);
 582      $_REQUEST['input'] = strip_tags($_REQUEST['input'], "<b></b><i></i><u></u><strong></strong><em></em>");
 583      $_REQUEST['input'] = str_replace("\n","<br />",$_REQUEST['input']);
 584      $_REQUEST['input'] = str_replace("\r","",$_REQUEST['input']);
 585      if ($_REQUEST['input'] != "" && $_REQUEST['name'] != "" && $_REQUEST['email'] != "") {
 586        $this->readcomments("pictures/" . $_REQUEST['filename'] . ".comment");
 587        $comment_exists = $this->select($_REQUEST['input'],$this->comments,3,1,0);
 588        $comment_exists = $this->select($_REQUEST['name'],$comment_exists,1,1,0);
 589        $comment_exists = $this->select($_REQUEST['email'],$comment_exists,2,1,0);
 590        if (count($comment_exists) == 0) {
 591          $this->comments[] = array(time(), $_REQUEST['name'], $_REQUEST['email'], $_REQUEST['input']);
 592          $this->writecomments($_REQUEST['filename'] . ".comment");
 593  
 594      // SEND COMMENT EMAIL

 595      if ($this->sendmail == 1) {
 596            mail($this->adminemail, $this->gallerytitle . ": " . $this->lang['commentadded'], strtoupper($this->lang['from']) . ":\n" . $_REQUEST['name'] . "(" . $_REQUEST['email'] .  ")\n\n" . strtoupper($this->lang['comment']) . ":\n" . str_replace("<br />", "\n",$_REQUEST['input']) . "\n\n" . "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . "?id=" . $_REQUEST['id'], "From: " . $_REQUEST["email"] . "\nReply-to: " . $_REQUEST["email"]);
 597      $this->log("Sent comment email");
 598      }
 599          echo "<div align=\"center\"><strong><b>" . $this->lang['commentadded'] . "</b></strong></div>";
 600        } else echo "<div align=\"center\"><strong><b>" . $this->lang['commentexists'] . "</b></strong></div>";
 601      } else echo "<div align=\"center\"><strong><b>" . $this->lang['commentmissing'] . "</b></strong></div>";
 602      unset($this->comments);
 603    }
 604  
 605    function getlanguages() {
 606      $workdir = opendir("lang");
 607      while (false !== ($pointer = readdir($workdir))) {
 608        if ($pointer !== "." && $pointer !== "..") {
 609          $this->languages[] = ucfirst(substr($pointer,0,(strlen($pointer)-4)));
 610        }
 611      }
 612      sort($this->languages);
 613    }
 614  
 615    function output($var) {
 616      if (isset($this->$var)) {
 617        echo $this->$var;
 618      } else echo "No data (" . $var . ")";
 619    }
 620  
 621    function log($entry) {
 622      $logfile = "mg2_log.txt";
 623      // DELETE LARGE LOG FILE

 624      if (is_file($logfile) && filesize($logfile) > 300000) unlink($logfile);
 625      // CREATE NEW LOGFILE

 626      if (!is_file($logfile)) {
 627        $fd = fopen($logfile,"a+");
 628        fwrite($fd,"MG2 LFS (Log File System)\n\n");
 629        fwrite($fd,"Version: " . $this->version . "\n");
 630        fwrite($fd,"Install date: " . date("Y-m-d",$this->installdate) . "\n\n---LOG BEGIN------------------\n\n");
 631        fwrite($fd,date("Ymd, H.i.s : ") . $entry . "\n");
 632      } else {
 633        $fd = fopen($logfile,"a+");
 634        fwrite($fd,date("Ymd, H.i.s : ") . $entry . "\n");
 635      }
 636    }
 637  
 638    function medium($name) {
 639      $ext = strrchr($name, '.');
 640      if($ext !== false) {
 641          $name = substr($name, 0, -strlen($ext)) . "_medium." . end(explode('.',$name));
 642      }
 643      return $name;
 644    }
 645  
 646    function thumb($name) {
 647      $ext = strrchr($name, '.');
 648      if($ext !== false) {
 649          $name = substr($name, 0, -strlen($ext)) . "_thumb." . end(explode('.',$name));
 650      }
 651      return $name;
 652    }
 653  
 654    function name_remove($name) {
 655      $name = str_replace("_medium", "", $name);
 656      $name = str_replace("_thumb", "", $name);
 657      return $name;
 658    }
 659  
 660  }
 661  ?>


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