YaPiG PHP Cross Reference Image Galleries

Source: /admin_func.php - 766 lines - 22249 bytes - Summary - Text - Print

Description: This module contains all funtions used by all admin modules. I.e: admin.php, add_gallery.php, modify_gallery.php, delete_gallery.php

   1  <?php
   2  include ("view_func.php");
   3  
   4  /**

   5   * This module contains all funtions used by all admin modules. I.e:

   6   *

   7   *  admin.php, add_gallery.php, modify_gallery.php, delete_gallery.php

   8   *

   9   * @package admin

  10   */
  11  
  12  
  13  /**

  14   * load_gd tries to load gd library in case it is not automatically loaded.

  15   * Then checks the availability of some functions included in this library.

  16   *

  17   * Note: this function does not check if gd library is 2 or higher.

  18   *

  19   * @param bool $debug if true shows some debug messages. Used in installation.

  20   * @return bool true if library loaded, false if not.

  21   */
  22  
  23  function load_gd($debug=false){
  24  
  25    if (!extension_loaded('gd')) {
  26      if ($debug) warning(_y("GD library not loaded. Trying to load it."));
  27      if (!function_exists('dl')){
  28        if ($debug)
  29      warning(_y("Function dynamic extension load not available."));
  30        return(false);
  31      }
  32  
  33      if (dl('php_gd2.dll')|| dl('php_gd.dll') ){
  34        if ($debug) msg(_y("php_gd(2).dll sucessfully loaded."));
  35      }
  36      else {
  37        if(!dl('gd.so'))    {
  38      if ($debug) warning(_y("GD library not available"));
  39      return(false);
  40        }
  41        if ($debug) msg(_y("gd.so sucessfully loaded."));
  42      }
  43    }
  44  
  45    //these functions are needed.

  46    if (!function_exists('getimagesize')) {
  47      if ($debug) warning(_y("Function getimagesize does not exist"));
  48        return(false);
  49    }
  50    if (!function_exists('imagecreatetruecolor')&&
  51        !function_exists('imagecreate')){
  52      if ($debug) warning(_y("Function imagecreate(truecolor) does not exist"));
  53      return(false);
  54    }
  55    if (!function_exists('imagecreatefromjpeg')) {
  56      if ($debug) warning(_y("Function imacreatefromjpeg does not exist"));
  57      return(false);
  58    }
  59    if ($debug) msg(_y("GD library is loaded."));
  60    return(true);
  61  }
  62  
  63  /**

  64   * 

  65   */
  66  
  67  function get_dirs($dirname,  &$dir) {
  68      //echo "- $dirname<br />";

  69      $dir[] = $dirname;
  70      $handle = opendir($dirname);
  71      while( ( $name = readdir($handle)) !== false) {
  72      //echo "name: $name<br />";

  73      $full_name = $dirname . $name;
  74      if (is_dir($full_name)) {
  75          //echo "name is a dir: $name ($full_name)<br />";

  76          $yd = 'yapig_data';
  77          if (($name!= ".") && ($name !="..") && 
  78          (strcmp(substr($name,0,strlen($yd)),$yd) != 0)) {
  79          //Append '/' if required 

  80          if (!preg_match("/\/\$/",$dirname)){
  81              $dirname.='/';
  82          }
  83          
  84          if (!get_dirs($dirname . $name, &$dir)) {
  85             // echo "Return False 2";

  86              return false;
  87          }
  88          }
  89      }
  90      
  91      }
  92      closedir($handle);
  93      return true;
  94  }
  95  
  96  /**

  97   * 

  98   * Gets all dirs of a directory

  99   * except '.','..' and the ones that begin with 'yapig_data'

 100   * 

 101   * @return array with the dirs or false if any problem

 102   */
 103  function get_all_gid_dirs() {
 104      
 105      global $BASE_DIR;
 106      
 107      $list = array();
 108      if (! get_dirs($BASE_DIR, &$list)) {
 109      return false;
 110      }
 111      //debug($list,'get_all_dirs');

 112  
 113      return $list;
 114  }
 115  
 116  
 117  /**

 118   * Prints admin login form. Uses login_form.

 119   *

 120   * @return none

 121   * @global template directory

 122   *

 123   */
 124  
 125  
 126  function login_form() {
 127      global $TEMPLATE_DIR;
 128      
 129      //Admin login form internationalization.

 130      $I_LOGIN=_y('Please login as administrator');
 131      $I_USER=_y('User');
 132      $I_PASSWORD=_y('Password');
 133      $I_SUBMIT=_y('Submit');
 134      include($TEMPLATE_DIR . 'login_form.php');
 135  }
 136  
 137  /**

 138   * Admin task bar contains all possible task the YaPiG admin can do.

 139   * This function prints this task bar. Uses admin_task_bar.php

 140   *

 141   * @global template location

 142   */
 143  
 144  function print_admin_taskbar() {
 145      global $TEMPLATE_DIR;
 146      //I18n

 147      $I_ADMIN_TASKS=_y("Administrative tasks");
 148      $I_UPLOAD=_y('Upload files');
 149      $I_ADD=_y('Add gallery');
 150      $I_MODIFY=_y('Modify gallery');
 151      $I_DELETE=_y('Delete gallery');
 152      $I_CHANGE=_y('Configuration');
 153      $I_LOGOUT=_y('Logout');
 154      include ($TEMPLATE_DIR . 'admin_task_bar.php');
 155      
 156  }
 157  
 158  /*

 159   * Prints add/modify gallery information form. Used for adding a gallery

 160   * and for modifying gallery information such as title, author, description..

 161   *

 162   * @param string $D_ACTION destination url of the action attribute

 163   * @param string $D_TITLE gallery title

 164   * @param string $D_AUTHOR gallery author

 165   * @param string $D_DIR gallery dir

 166   * @param string $D_DESCRIPTION gallery description

 167   * @param string $D_PASSWORD gallery password

 168   * @global galleries base directory

 169   * @global directory where template is located

 170   */
 171  
 172  function print_gallery_form($D_ACTION, $gallery_info=array()) {
 173      global $BASE_DIR,$TEMPLATE_DIR;
 174      
 175      $D_TITLE=$gallery_info['title'];
 176      $D_AUTHOR=$gallery_info['author'];
 177      $D_DESCRIPTION=$gallery_info['desc'];
 178      $D_PASSWORD=$gallery_info['gallery_password'];
 179      $D_DATE=$gallery_info['date'];
 180      if ($gallery_info['no_comments']=="on") {
 181      $D_CHECKED="checked=\"checked\"";
 182      }
 183      
 184      if (count($gallery_info) == 0) {
 185      if (!$list = get_all_gid_dirs()) {
 186       echo "hello World";   
 187      }
 188      }
 189      $I_GALLERY_TITLE=_y('Gallery title');
 190      $I_AUTHOR = _y('Author');
 191      $I_DATE= _y('Date');
 192      $I_DATE_WARNING=_y("Leave it blank for today's date.");
 193      $I_LOCATION = _y('Location');
 194      $I_PASSWORD = _y('Password');
 195      $I_PASS_WARNING= _y('set this option for restricted access to gallery');
 196      $I_DESCRIPTION = _y('Description');
 197      $I_NO_COMMENTS=_y("Hide comments");
 198      $I_SEND=_y('Send');
 199      
 200      $D_BASE_DIR=$BASE_DIR;
 201      
 202      
 203      include($TEMPLATE_DIR . "gallery_form.php");
 204  }
 205  
 206  /////////// ACTIONS WITH GALLERIES ///////////////////

 207  
 208  
 209  
 210  /**

 211   * Creates a thumbnail image from a jpeg file.

 212   *

 213   * It takes as arguments the paths to the source image and the path/name of

 214   * the destination image. Uses the global variables to set the destination

 215   * image size.

 216   *

 217   * @param string $path_dest Destination Path + name of output file

 218   * @param string $path_origen Source image path. Includes de name of the image

 219   *

 220   * @global max size in pixels

 221   * @global jpeg quality of thumbs

 222   *

 223   * @returns bool false if there was any problem :)

 224   *

 225   */
 226  
 227  function create_thumb ($path_dest,$path_origen) {
 228      global $THUMB_SIZE, $THUMB_QUALITY, $GD_VERSION;
 229      
 230      echo  "<div> $path_origen";
 231      if (!file_exists($path_origen)) return(false);
 232      
 233      if (!($sz_orig = getimagesize ($path_origen))) return(false);
 234      
 235      
 236      $img_pixels=$sz_orig[0] * $sz_orig[1];
 237      if ($img_pixels>3900000){
 238      warning( $path_origen . _y(" is a huge image, it might cause memory issues."));
 239      }
 240      /*

 241       * Cut from getimagesize() documentation:

 242       * Returns an array with 4 elements. Index 0 contains the width of the

 243       * image in pixels. Index 1 contains the height. Index 2 is a flag

 244       * indicating the type of the image: 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF,

 245       * 5 = PSD, 6 = BMP, 7 = TIFF(intel byte order), 8 = TIFF(motorola

 246       * byte order), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC,

 247       * 14 = IFF. These values correspond to the IMAGETYPE constants that

 248       * were added in PHP 4.3.

 249       */
 250      switch($sz_orig[2]) {
 251       case 1:
 252      //$im_orig=imagecreatefromgif ($path_origen);

 253      return(true);
 254      break;
 255       case 2:
 256      $im_orig=imagecreatefromjpeg ($path_origen);
 257      break;
 258       case 3:
 259         //warning(_y("PNG files not supported in this version"));

 260         //return(true);

 261         $im_orig=imagecreatefrompng ($path_origen);
 262  
 263      break;
 264       default: return(false);
 265      }
 266      //Now We calculate the thumbnail size.

 267      $ratio=$sz_orig[1]/$sz_orig[0];
 268      if ($ratio>1) {
 269      $height=$THUMB_SIZE;
 270      $width=(int)($THUMB_SIZE/$ratio);
 271      }
 272      else {
 273      $width=$THUMB_SIZE;
 274      $height=(int) ($THUMB_SIZE*$ratio);
 275      }
 276  
 277      if ($GD_VERSION==2) {// GD v2.0
 278        if(!($im_dest = imagecreatetruecolor ($width,$height)))
 279      return(false);
 280      }
 281      else{
 282        if(!($im_dest = imagecreate ($width,$height)))
 283      return(false);
 284      }
 285  
 286  
 287  
 288      echo " ({$sz_orig[0]}x{$sz_orig[1]}) -> <b>$path_dest ({$width}x{$height}))</b></div>";
 289      if ($GD_VERSION==2) {
 290          if(!imagecopyresampled($im_dest,$im_orig,0,0,0,0,$width,$height,
 291                 $sz_orig[0],$sz_orig[1])) return(false);
 292      }
 293      else {
 294        if(!imagecopyresized($im_dest,$im_orig,0,0,0,0,$width,$height,
 295                 $sz_orig[0],$sz_orig[1])) return(false);
 296      }
 297  
 298      if (!imagejpeg($im_dest, $path_dest, $THUMB_QUALITY)) return(false);
 299      return(true);
 300  }
 301  
 302  /**

 303   * This function creates all thumbnails

 304   *

 305   * files are stored in src_dir and will be stored in dest_dir prefixing $THUMB_PREFIX

 306   * to de image name.

 307   *

 308   * @param string $dest_dir  Path to destination dir

 309   * @param string $src_dir   Path to source dir

 310   * @param array $array_filenames  Contains the names of the source images (ex: file.jpg)

 311   *

 312   * @global string $THUMB_PREFIX

 313   * @return bool

 314   */
 315  
 316  function create_all_thumbs ($dest_dir,$src_dir,$array_filenames) {
 317      global $THUMB_PREFIX;
 318  
 319      //First of all check if gd library is already loaded

 320       if(!load_gd(true)) {
 321        error(_y("GD library not loaded. Please read installation documentation"));
 322       }
 323  
 324  
 325      foreach($array_filenames as $src_file) {
 326      $src_path= $src_dir . $src_file;
 327      $dest_path= $dest_dir . $THUMB_PREFIX . $src_file;
 328      if (!create_thumb($dest_path,$src_path)) return(false);
 329      }
 330      return(true);
 331  }
 332  
 333  /**

 334   * Gets all image filenames of the dir

 335   *

 336   * This function scans all filenames that are in a directory and

 337   * returns the names of the image files that are cotained in.

 338   *

 339   * @param string $dir path of the dir.

 340   *

 341   * @global string preceding the name of the thumbnail

 342   * @global array with the valid extensions of the images

 343   * @return array With the image filenames that the directory contains.

 344   */
 345  
 346  function get_all_image_filenames ($dir) {
 347      global $THUMB_PREFIX,$IMAGE_EXT;
 348  
 349      $list=array();
 350      if (!is_dir($dir)) return(false);
 351      if (!($dh = opendir($dir))) return(false);
 352      while (($file = readdir($dh)) !== false) {
 353      if (is_file($dir . $file)) {
 354          $fileinfo = pathinfo($file);
 355          if(in_array(strtolower($fileinfo["extension"]),$IMAGE_EXT)){
 356          if(!preg_match("/^$THUMB_PREFIX/",$fileinfo['basename'])){
 357            array_push($list,$file);
 358          }
 359          }
 360      }
 361      }
 362      closedir($dh);
 363      return($list);
 364  }
 365  
 366  /**

 367   * creates phid filenames correspondence file with this line format:

 368   *  phid $EQUAL filename\n

 369   *

 370   * This is just an alias of create_data_file

 371   *

 372   * @param string $gid_dir directory where images are stored (with $BASE_DIR)

 373   * @param array $filenames array with this format: array[phid]=filename.

 374   * @global name of the created file

 375   * @return bool true if ok, false if not.

 376   *

 377   */
 378  
 379  function create_phid_filenames_file($gid_dir,$filenames) {
 380      global $PHID_FILENAMES;
 381      return(create_data_file($gid_dir . $PHID_FILENAMES, $filenames));
 382  }
 383  
 384  /**

 385   * Creates file which contains information about the gallery.Called

 386   * $GID_INFO_FILE which is a php file that contains

 387   *

 388   * $new array has these keys:

 389   *

 390   * - root_gid: not used

 391   * - title: gallery title

 392   * - author: author of the gallery.

 393   * - gallery_password: password of the gallery.

 394   * - thumb_phid : thumbnail phid.

 395   * - no_comments: do not allow, comments (1|0)

 396   * - num_images : number of images

 397   * - num_subgids: number of sub galleries. Not used

 398   * - date: date of creation

 399   * - desc: lines describing the contents of the gallery.

 400   *

 401   * if file does not exist => all keys need to be set.

 402   * @param string $gallery_path path to gallery, includes $BASE_DIR

 403   * @param array $new array with gallery information

 404   * @return bool true if ok, false if error :D

 405  */
 406  function create_info_file($gallery_path,$new,$update=true){
 407      global $GID_INFO_FILE, $TEMPLATE_DIR;
 408  
 409      //gif_path=gid_info_file path

 410      $gif_path=$gallery_path . $GID_INFO_FILE;
 411  
 412      //If file exists => only update values included in new)

 413      //If it not an update => overwrite file.

 414      if (!file_exists($gif_path)||(!$update)){
 415        $info=$new;
 416      }
 417      else {
 418      include($gif_path);
 419      foreach ($gid_info as $key => $value) {
 420        //echo "{gid_info[$key]}=> $value; new[{$new[$key]}] [$set] <br />\n";

 421        if (isset($new[$key]))  $info[$key]=$new[$key];
 422        else
 423          $info[$key]=$gid_info[$key];
 424      }//end foreach

 425      }
 426  
 427      //echo "<pre>";print_r($info);echo"</pre>";

 428      if (!($fd=fopen($gallery_path . $GID_INFO_FILE,"w+"))) return(false);
 429      fputs($fd,"<?php\n");
 430      fputs($fd,"\$gid_info['root_gid']=\"" . $info['root_gid']. "\";\n");
 431      fputs($fd,"\$gid_info['title']=\"". str_replace("\\'","'",$info['title']). "\";\n");
 432      fputs($fd,"\$gid_info['author']=\"". str_replace("\\'","'",$info['author']). "\";\n");
 433      fputs($fd,"\$gid_info['gallery_password']=\"".
 434             $info['gallery_password']. "\";\n");
 435      fputs($fd,"\$gid_info['thumb_phid']=\"" . $info['thumb_phid'] . "\";\n");
 436      fputs($fd,"\$gid_info['no_comments']=\"" . $info['no_comments'] . "\";\n");
 437      fputs($fd,"\$gid_info['num_images']=\"". $info['num_images']. "\";\n");
 438      fputs($fd,"\$gid_info['num_subgids']=\"". $info['num_subgids']. "\";\n");
 439      fputs($fd,"\$gid_info['date']=\"". $info['date']. "\";\n");
 440      fputs($fd,"\$gid_info['desc']=\"". str_replace("\\'","'",$info['desc']). "\";\n");
 441      fputs($fd,"?>");
 442      fclose($fd);
 443      return(true);
 444  }
 445  
 446  /**

 447   * Gets the value of the gid counter and increases it one unit.

 448   * @global counter file which is incremented each time this func is called

 449   * @return integer valid gallery identificator., that is,one not being used.

 450   */
 451  
 452  function get_gid_counter() {
 453      global  $GID_COUNTER_FILE;
 454  
 455      if (!file_exists($GID_COUNTER_FILE)){
 456      if (!($fd=fopen($GID_COUNTER_FILE,'w'))){
 457          error(_y("Opening gid counter file: " . $GID_COUNTER_FILE));
 458      }
 459      fputs($fd,'1');
 460      fclose($fd);
 461      return(1);
 462      }
 463      if (!($fd=fopen($GID_COUNTER_FILE,'r+'))){
 464      error(_y("Opening gid counter file: " . $GID_COUNTER_FILE));
 465      }
 466      $counter=fgets($fd,10);
 467      $counter++;
 468      rewind($fd);
 469      fputs($fd,$counter);
 470      fclose($fd);
 471      return($counter);
 472  
 473  }
 474  /**

 475   * Checks if dir is being used by other gallery.

 476   *

 477   * Searchs in $GID_DIR file if $dir is being used by another

 478   * gallery.

 479   *

 480   * @param string $dir to check. Ended in '/'. Without $BASE_DIR

 481   * @global gid dirs correspondence file

 482   * @global field separator

 483   * @return bool true if dir is being used. false if not.

 484   */
 485  function gid_dir_being_used($dir) {
 486   global $GID_DIRS, $EQUAL;
 487  
 488      //If it is first gallery => not being used

 489      if(!file_exists($GID_DIRS)) return(false);
 490      if(filesize($GID_DIRS)==0) return(false);
 491      //If could not load => Print warning.

 492      if (!($tmp=get_all_data($GID_DIRS))) {
 493      warning("gid_dir_being_used: Check file permissions of: " . $GID_DIR);
 494      return(false);
 495      }
 496      if (in_array($dir, $tmp)) return(true);
 497      return(false);
 498  }
 499  
 500  /**

 501   * Adds $dir to file $GID_DIRS, which contains gid->dir correspondence

 502   *

 503   * @param string $dir dir name without $BASE_DIR

 504   * @global gid->dirs correspondence filename.

 505   * @global gid->dirs field separator

 506   * @return bool true if ok, false if error.

 507   */
 508  
 509  function add_to_gid_dirs($dir) {
 510      global $GID_DIRS, $EQUAL;
 511  
 512      //Load file

 513      $tmp=array();
 514      if (file_exists($GID_DIRS)) $tmp=file($GID_DIRS);
 515      //Update file

 516      if (!($fd=fopen($GID_DIRS,"w+"))) return(false);
 517      fputs($fd, get_gid_counter() . $EQUAL . $dir . "\n");
 518      foreach ($tmp as $line)
 519        fputs($fd,$line);
 520      fclose($fd);
 521      return(true);
 522  }
 523  
 524  /**

 525   * shows modify gid options (links)

 526   *

 527   * @param string $gid_dir gallery directory with $BASE_DIR

 528   * @param integer $gid gallery identificator

 529   * @param bool $gallery_bar if true then prints prev and next gallery bar.

 530   *

 531   * @global file with info about the contents of the gallery

 532   * @global template dir

 533   * @global phid comments stats file.

 534   * @global gid stats file.

 535   * @global total counter stats identifier.

 536   * @return bool true if ok false if not.

 537   */
 538  
 539  function print_modify_gid($gid_dir,$gid,$gallery_bar=false){
 540    global $GID_INFO_FILE,$TEMPLATE_DIR,$PHID_COMMENTS,$GID_STATS,$TOTAL_LIST;
 541  
 542    if (!file_exists($gid_dir . $GID_INFO_FILE)) return(false);
 543  
 544    include ($gid_dir . $GID_INFO_FILE);
 545    
 546    $D_VISITS=get_data($GID_STATS,$gid);
 547    $D_COMMENTS=get_data($gid_dir. $PHID_COMMENTS, $TOTAL_LIST);
 548    $D_TITLE=$gid_info['title'];
 549    $D_AUTHOR=$gid_info['author'];
 550    $D_NUMBER_IMAGES=$gid_info['num_images'];
 551    $D_DATE=$gid_info['date'];
 552    $D_DESC=$gid_info['desc'];
 553    $D_THUMB=get_thumb_path($gid_dir, $gid_info['thumb_phid'],true);
 554    $I_MOD_INFO=_y('Modify gallery info');
 555    $I_SEL_THUMB=_y('Select thumbnail');
 556    $I_MOD_PHIDS=_y('Modify imagelist');
 557    $I_DEL_STUFF=_y('Delete gallery');
 558    $D_GID=$gid;
 559    $I_NUMBER_IMAGES=_y('Number of images');
 560    $I_TITLE=_y('Title');
 561    $I_AUTHOR=_y('Author');
 562    $I_VIEW_GALLERY=_y('View this gallery');
 563    $I_GALLERY=_y('Gallery');
 564    $I_VISITS=_y('Visits');
 565    $I_COMMENTS=_y('Comments');
 566    $I_DATE=_y('Date');
 567    $I_DESCRIPTION=_y('Description');
 568    $I_MOVE_UP=_y('Up');
 569    $I_MOVE_DOWN=_y('Down');
 570    $I_MOVE_UP_DESC=_y('Move up this gallery on index');
 571    $I_MOVE_DOWN_DESC=_y('Move down this gallery on index');
 572  
 573    if ($gallery_bar) {
 574      print_gallery_navigation_bar($gid,"modify_gallery.php?action=view_phids&amp;");
 575    }
 576    include($TEMPLATE_DIR . 'modify_gid.php');
 577    return(true);
 578  }
 579  
 580  
 581  /**

 582   * Shows form when admin wants to delete a gallery.

 583   *

 584   * Uses 'delete_gallery_form.php'

 585   *

 586   * @param integer $D_GID gallery identificator

 587   * @global template directory

 588   *

 589   */
 590  function print_delete_gallery_form($D_GID){
 591    global $TEMPLATE_DIR;
 592  
 593    $I_SELECT_OPT=_y('Select deletion options:');
 594    $I_NOT_LIST=_y('Do not list gallery in gallery index any more.');
 595    $I_DEL_COMMENTS=_y('Clear all image comments.');
 596    $I_DEL_IMG_COUNTERS=_y('Clear all image visit counters.');
 597    $I_DEL_GAL_COUNTERS=_y('Clear gallery visit counters.');
 598    $I_DEL_THUMBS=_y('Delete gallery thumbnails.');
 599    $I_DEL_ALL_FILES=_y('Delete all files in directory.');
 600    $I_DEL_CAPTIONS=_y('Delete all image captions.');  
 601    $I_SEND=_y('send');
 602  
 603    include($TEMPLATE_DIR . 'delete_gallery_form.php');
 604  }
 605  
 606  /**

 607   * Obtains the images from a list that do not have a thumbnail already

 608   * created

 609   *

 610   * @param array $all_list list with filenames

 611   * @param string $gid_dir is the directory where images are stored

 612   * @return mixed false if problem. array with images without thumb if ok.

 613   */
 614  
 615  function get_images_without_thumb($gid_dir,$all_list) {
 616    global $THUMB_PREFIX;
 617  
 618    if (!is_array($all_list)) return(false);
 619    foreach ($all_list as $one_image) {
 620      if (!@file_exists($gid_dir . $THUMB_PREFIX . $one_image)) {
 621        $return_list[]=$one_image;
 622      }
 623    }
 624    if (!is_array($return_list)) return(false);
 625    return($return_list);
 626  
 627  }
 628  
 629  /**

 630   * Creates a new file with the contents of $TEMPLATE_DIR . index_file.php 

 631   * (default template content of this file is a meta refresh).

 632   * User should include a refresh url where this file will point.

 633   *

 634   *

 635   * Default output filename is index.html.

 636   *

 637   * @param string $dir_path Path where filename will be created

 638   * @param string $refresh_url URL where filename will be redirected.

 639   * @param string $filename Output filename.

 640   * @global TEMPLATE_DIR Template directory.

 641   * @return boolean True if success.

 642   *

 643   */
 644  
 645  function new_index_file($dir_path, $refresh_url='../', $filename='index.html'){
 646    global $TEMPLATE_DIR;
 647  
 648    if (file_exists($dir_path . $filename)) {
 649        return true;
 650    }
 651      
 652    if (!($fd=fopen($dir_path . $filename,"w+"))) {
 653        return (false);
 654    }
 655    
 656    //Follow yapig template variable name conventions.

 657    $D_REFRESH_URL=$refresh_url;
 658  
 659    //Interface variables

 660    $I_IF_NOT_REFRESHED=_y('If the page is not automatically refreshed.');
 661    $I_PRESS_HERE=_y('Press here');
 662  
 663    include($TEMPLATE_DIR . 'index_file.php');
 664    //index_file defines a variable called INDEX_FILE

 665    //with the contents of filename.

 666    
 667    fputs($fd,$INDEX_FILE);
 668    fclose($fd);
 669    return(true);
 670  }
 671  
 672  
 673  /**

 674   * rotates an image. Got from PHP.net

 675   *

 676   * @link http://es.php.net/manual/es/function.imageinterlace.php

 677   * 

 678   * @param string $imagePath - path to image; rotated image overwriting the 

 679   * old one

 680   * @param int $rtt MUST be 90 or -90 - cw/ccw

 681   */
 682  
 683  function rotate_image($imagePath, $rtt=90){
 684      
 685      /*

 686       if(preg_match("/\.(png)/i", $imagePath)) 

 687       $src_img=ImageCreateFromPNG($imagePath);

 688       elseif(preg_match("/\.(jpg)/i", $imagePath)) 

 689       $src_img=ImageCreateFromJPEG($imagePath);

 690       elseif(preg_match("/\.(bmp)/i", $imagePath)) 

 691       $src_img=ImageCreateFromWBMP($imagePath);

 692       */
 693  
 694      //Check if exists

 695      if (!file_exists($imagePath)) {
 696      return(false);
 697      }
 698      
 699      //First of all check if GD rotateimage exists, if not => Use custom one

 700     //TODO

 701     
 702      $size=GetImageSize($imagePath);
 703      $width= $size[0];
 704      $height= $size[1];
 705  
 706      if (!($src_img=ImageCreateFromJPEG($imagePath))) {
 707      return false;
 708      }
 709      
 710      if ($GD_VERSION==2) {// GD v2.0
 711      if(!($im_dest = imagecreatetruecolor ($height, $width)))
 712        return(false);
 713      }
 714      else {
 715      
 716      if(!($im_dest = imagecreate ($height, $width))) {
 717          return(false);
 718      }
 719      }
 720    //echo "$size[1] x $size[0]";

 721    
 722    $dst_img=ImageCreateTrueColor($size[1],$size[0]);
 723    if($rtt==-90){
 724      $t=0;
 725      $b=$size[1]-1;
 726      while($t<=$b){
 727        $l=0;
 728        $r=$size[0]-1;
 729        while($l<=$r){
 730      imagecopy($dst_img,$src_img,$t,$r,$r,$b,1,1);
 731      imagecopy($dst_img,$src_img,$t,$l,$l,$b,1,1);
 732      imagecopy($dst_img,$src_img,$b,$r,$r,$t,1,1);
 733      imagecopy($dst_img,$src_img,$b,$l,$l,$t,1,1);
 734      $l++;
 735      $r--;
 736        }
 737        $t++;
 738        $b--;
 739      }
 740    }
 741    elseif($rtt==90){
 742      $t=0;
 743      $b=$size[1]-1;
 744      while($t<=$b){
 745        $l=0;
 746        $r=$size[0]-1;
 747        while($l<=$r){
 748      imagecopy($dst_img,$src_img,$t,$l,$r,$t,1,1);
 749      imagecopy($dst_img,$src_img,$t,$r,$l,$t,1,1);
 750      imagecopy($dst_img,$src_img,$b,$l,$r,$b,1,1);
 751      imagecopy($dst_img,$src_img,$b,$r,$l,$b,1,1);
 752      $l++;
 753      $r--;
 754        }
 755        $t++;
 756        $b--;
 757      }
 758    }
 759    ImageDestroy($src_img);
 760    ImageInterlace($dst_img,0);
 761    @ImageJPEG($dst_img,$imagePath);
 762    return(true);
 763  }
 764  
 765  
 766  ?>

title

Description

title

Description

title

Description

title

title

Body