Changeset 1823 for trunk/tools


Ignore:
Timestamp:
Feb 15, 2007, 7:50:08 PM (17 years ago)
Author:
laurent_duretz
Message:

Integration of remote site protection in generate action

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/create_listing_file.php

    r1775 r1823  
    3030// +-----------------------------------------------------------------------+
    3131
     32// ****** Gallery configuration ****** //
    3233// Srcipt version
    3334$conf['version'] = 'Alligator';
    3435
     36// URL of main gallery
     37$conf['gallery'] = 'http://';
     38
    3539// prefix for thumbnails in "thumbnail" sub directories
    3640$conf['prefix_thumbnail'] = 'TN-';
    3741
    3842// $conf['file_ext'] lists all extensions (case insensitive) allowed for your PhpWebGallery installation
    39 $conf['file_ext'] = array('jpg','JPG','png','PNG','gif','GIF','mpg','zip', 'avi','mp3','ogg');
     43$conf['file_ext'] = array('jpg','JPG','jpeg','JPEG','png','PNG','gif','GIF','mpg','zip', 'avi','mp3','ogg');
    4044
    4145// $conf['picture_ext'] must be a subset of $conf['file_ext']
    42 $conf['picture_ext'] = array('jpg','JPG','png','PNG','gif','GIF');
    43 
    44 // URL of main gallery
    45 $conf['gallery'] = 'http://';
    46 
    47 // max excution time before refresh in seconds
     46$conf['picture_ext'] = array('jpg','JPG','jpeg','JPEG','png','PNG','gif','GIF');
     47
     48// ****** Time limitation functionality ****** //
     49// max execution time before refresh in seconds
    4850$conf['max_execution_time'] = (5*ini_get('max_execution_time'))/6; // 25 seconds with default PHP configuration
    4951
     
    5153$conf['refresh_delay'] = 0;
    5254
    53 // $conf['file_ext'] lists all extensions (case insensitive) allowed for your PhpWebGallery installation
    54 $conf['file_ext'] = array('jpg','JPG','jpeg','JPEG','png','PNG','gif','GIF','mpg','zip', 'avi','mp3','ogg');
    55 
     55// ****** EXIF support functionality ****** //
    5656// $conf['use_exif'] set to true if you want to use Exif information
    57 $conf['use_exif'] = true;
     57$conf['use_exif'] = false;
    5858
    5959// use_exif_mapping: same behaviour as use_iptc_mapping
     
    6262  );
    6363
     64// ****** IPTC support functionality ****** //
    6465// $conf['use_iptc'] set to true if you want to use IPTC informations of the
    6566// element according to get_sync_iptc_data function mapping, otherwise, set
     
    7778  'comment'         => '2#120');
    7879
     80// ****** Directory protection functionality ****** //
     81// Define if directories have to be protected if they are not
     82$conf['protect'] = false;
     83
    7984// index.php content for command 'protect'
    8085$conf['protect_content'] = '<?php header("Location: '.$conf['gallery'].'") ?>';
    8186
     87// true/false : show/hide warnings
     88$conf['protect_warnings'] = true;
     89
     90// ****** Thumbnails generation functionality ****** //
     91// Define if images have to be reduced if they are not
     92$conf['thumbnail'] = false;
     93
     94// Define method to generate thumbnails :
     95// - fixed (width and height required);
     96// - width (only width required);
     97// - height (only height required);
     98// - ratio (only ratio is required)
     99// - exif (no other parameter required)
     100$conf['thumbnail_method'] = 'ratio';
     101
     102// Height in pixels (greater than 0)
     103$conf['thumbnail_height'] = 96;
     104
     105// Width in pixels (greater than 0)
     106$conf['thumbnail_width'] = 96;
     107
     108// Ratio between original and thumbnail size (strictly between 0 and 1)
     109$conf['thumbnail_ratio'] = 0.2;
     110
     111// Define thumbnail format : jpeg, png or gif (will be verified)
     112$conf['thumbnail_format'] = 'jpeg';
     113
     114// ****** Directory mapping ****** //
    82115// directories names
    83116$conf['thumbs'] = 'thumbnail'; // thumbnails
     
    93126
    94127// list of actions managed by this script
    95 $pwg_conf['scan_action'] = array('clean', 'test', 'generate', 'protect');
     128$pwg_conf['scan_action'] = array('clean', 'test', 'generate');
    96129
    97130// url of this script
     
    107140$pwg_conf['safe_mode'] = (ini_get('safe_mode') == '1') ? true : false;
    108141
    109 // Error level management
    110 // true  : show warnings
    111 // false : hide warnings
    112 $pwg_conf['warning']['protect'] = true;
     142// This parameter will be fixed in pwg_init()
     143$pwg_conf['gd_version_major'] = '';
     144$pwg_conf['gd_version_full'] = '';
     145$pwg_conf['gd_supported_format'] = array();
    113146
    114147// +-----------------------------------------------------------------------+
    115 // |                               functions                               |
     148// |                               Functions                               |
    116149// +-----------------------------------------------------------------------+
    117150
     
    127160  fwrite($log_file, $line);
    128161  fclose($log_file);
     162}
     163
     164/**
     165 * Check web server graphical capabilities
     166 *
     167 * @return string
     168 */
     169function pwg_check_graphics()
     170{
     171  //~ pwg_log('>>>>> pwg_check_graphics() >>>>>'."\n");
     172 
     173  global $conf, $pwg_conf;
     174  $log = '';
     175 
     176  // Verify gd library for thumbnail generation
     177  if ($conf['thumbnail'] and !is_callable('gd_info'))
     178  {
     179    $log .= '          <code class="warning">Warning -</code> Your server can not generate thumbnails. Thumbnail creation switched off.<br />'."\n";
     180    // Switch off thumbnail generation
     181    $conf['thumbnail'] = false;
     182    return $log;
     183  }
     184 
     185  // Verify thumnail format
     186  if ($conf['thumbnail'])
     187  {
     188    $info = gd_info();
     189   
     190    // Backup GD major version
     191    $pwg_conf['gd_version_full'] = ereg_replace('[[:alpha:][:space:]()]+', '', $info['GD Version']);
     192    list($pwg_conf['gd_version_major']) = preg_split('/[.]+/', $pwg_conf['gd_version_full']);
     193   
     194    // Backup input/output format support
     195    array_push($pwg_conf['gd_supported_format'], $info['JPG Support'] ? 'jpeg' : NULL);
     196    array_push($pwg_conf['gd_supported_format'], $info['PNG Support'] ? 'png' : NULL);
     197    array_push($pwg_conf['gd_supported_format'], ($info['GIF Read Support'] and $info['GIF Create Support']) ? 'gif' : NULL);
     198   
     199    // Check output format support
     200    if (!in_array($conf['thumbnail_format'], $pwg_conf['gd_supported_format']))
     201    {
     202      $log .= '          <code class="warning">Warning -</code> Your server does not support thumbnail\'s <code>';
     203      $log .= $conf['thumbnail_format'].'</code> format. Thumbnail creation switched off.<br />'."\n";
     204    }
     205   
     206    switch ($conf['thumbnail_method'])
     207    {
     208      case 'exif':
     209      {
     210        // exif_thumbnail() must be callable
     211        if (!is_callable('exif_thumbnail'))
     212        {
     213          $log .= '          <code class="warning">Warning -</code> Your server does not support thumbnail creation through EXIF datas. Thumbnail creation switched off.<br />'."\n";
     214        }
     215        break;
     216      }
     217      case 'fixed':
     218      {
     219        // $conf['thumbnail_width'] > 0
     220        if (!is_numeric($conf['thumbnail_width']) or $conf['thumbnail_width'] <= 0)
     221        {
     222          $log .= '          <code class="failure">Failure -</code> Bad value <code>thumbnail_width = ';
     223          $log .= var_export($conf['thumbnail_width'], true).'</code>. Thumbnail creation switched off.<br />'."\n";
     224        }
     225        // $conf['thumbnail_height'] > 0
     226        if (!is_numeric($conf['thumbnail_height']) or $conf['thumbnail_height'] <= 0)
     227        {
     228          $log .= '          <code class="failure">Failure -</code> Bad value <code>thumbnail_height = ';
     229          $log .= var_export($conf['thumbnail_height'], true).'</code>. Thumbnail creation switched off.<br />'."\n";
     230        }
     231        break;
     232      }
     233      case 'ratio':
     234      {
     235        // 0 < $conf['thumbnail_ratio'] < 1
     236        if (!is_numeric($conf['thumbnail_ratio']) or $conf['thumbnail_ratio'] <= 0 or $conf['thumbnail_ratio'] >= 1)
     237        {
     238          $log .= '          <code class="failure">Failure -</code> Bad value <code>thumbnail_ratio = ';
     239          $log .= var_export($conf['thumbnail_ratio'], true).'</code>. Thumbnail creation switched off.<br />'."\n";
     240        }
     241        break;
     242      }
     243      case 'width':
     244      {
     245        // $conf['thumbnail_width'] > 0
     246        if (!is_numeric($conf['thumbnail_width']) or $conf['thumbnail_width'] <= 0)
     247        {
     248          $log .= '          <code class="failure">Failure -</code> Bad value <code>thumbnail_width = ';
     249          $log .= var_export($conf['thumbnail_width'], true).'</code>. Thumbnail creation switched off.<br />'."\n";
     250        }
     251        break;
     252      }
     253      case 'height':
     254      {
     255        // $conf['thumbnail_height'] > 0
     256        if (!is_numeric($conf['thumbnail_height']) or $conf['thumbnail_height'] <= 0)
     257        {
     258          $log .= '          <code class="failure">Failure -</code> Bad value <code>thumbnail_height = ';
     259          $log .= var_export($conf['thumbnail_height'], true).'</code>. Thumbnail creation switched off.<br />'."\n";
     260        }
     261        break;
     262      }
     263      default:
     264      {
     265        // unknown method
     266          $log .= '          <code class="failure">Failure -</code> Bad value <code>thumbnail_method = ';
     267          $log .= var_export($conf['thumbnail_method'], true).'</code>. Thumbnail creation switched off.<br />'."\n";
     268        break;
     269      }
     270    }
     271   
     272    if (strlen($log))
     273    {
     274      $conf['thumbnail'] = false;
     275    }
     276  }
     277 
     278  //~ pwg_log('<<<<< pwg_check_graphics() returns '.var_export($log, TRUE).' <<<<<'."\n");
     279  return $log;
    129280}
    130281
     
    335486
    336487/**
    337  * return extension of the thumbnail
     488 * return extension of the thumbnail and complete error_log
    338489 *
    339490 * @param string $file_dir
    340491 * @param string $file_short
     492 * @param string $file_ext
     493 * @param string &$error_log
    341494 * @return string
    342495 */
    343 function pwg_get_thumbnail_ext($file_dir, $file_short)
     496function pwg_get_thumbnail_ext($file_dir, $file_short, $file_ext, &$error_log)
    344497{
    345498  //~ pwg_log('>>>>> pwg_get_thumbnail_ext($file_dir = '.var_export($file_dir, TRUE).', $file_short = '.var_export($file_short, TRUE).') >>>>>'."\n");
     
    357510  }
    358511 
     512  if ($thumb_ext == '')
     513  {
     514    if ($conf['thumbnail'])
     515    {
     516      $log = pwg_icon_file($file_dir, $file_short, $file_ext);
     517      if (strpos($log, 'success'))
     518      {
     519        $thumb_ext = $conf['thumbnail_format'];
     520      }
     521      $error_log .= $log; 
     522    }
     523  }
     524 
    359525  //~ pwg_log('<<<<< pwg_get_thumbnail_ext() returns '.var_export($thumb_ext, TRUE).' <<<<<'."\n");
    360526  return $thumb_ext;
     527}
     528
     529
     530/**
     531 * return error logs
     532 *
     533 * @param string $file_dir
     534 * @param string $file_short
     535 * @param string $file_ext
     536 * @return string
     537 */
     538function pwg_icon_file($file_dir, $file_short, $file_ext)
     539{
     540  //~ pwg_log('>>>>> pwg_icon_file($file_dir = '.var_export($file_dir, TRUE).', $file_short = '.var_export($file_short, TRUE).') >>>>>'."\n");
     541 
     542  global $conf, $pwg_conf;
     543 
     544  $error_log = '';
     545 
     546  // Get original properties (width, height)
     547  if ($image_size = getimagesize($file_dir.'/'.$file_short.'.'.$file_ext))
     548  {
     549    $src_width = $image_size[0];
     550    $src_height = $image_size[1];
     551  }
     552  else
     553  {
     554    $error_log .= '          <code class="failure">Failure -</code> Can not generate icon for <code>';
     555    $error_log .= $file_dir.'/'.$file_short.'.'.$file_ext.'</code>';
     556    $error_log .= ' <img src="'.$pwg_conf['icon_dir'].'add_tag.png" title="width/height are unreadable" /><br />'."\n";
     557    return $error_log;
     558  }
     559 
     560  // Check input format
     561  $dst_format = $conf['thumbnail_format'];
     562  $src_format = ($file_ext == 'jpg' or $file_ext == 'JPG') ? 'jpeg' : strtolower($file_ext);
     563  if (!in_array($src_format, $pwg_conf['gd_supported_format']))
     564  {
     565    $error_log .= '          <code class="failure">Failure -</code> Can not generate icon for <code>';
     566    $error_log .= $file_dir.'/'.$file_short.'.'.$file_ext.'</code>';
     567    $error_log .= ' <img src="'.$pwg_conf['icon_dir'].'add_tag.png" title="format not supported" /><br />'."\n";
     568    return $error_log;
     569  }
     570 
     571  // Calculate icon properties (width, height)
     572  switch ($conf['thumbnail_method'])
     573  {
     574    case 'fixed':
     575    {
     576      $dst_width  = $conf['thumbnail_width'];
     577      $dst_height = $conf['thumbnail_height'];
     578      break;
     579    }
     580    case 'width':
     581    {
     582      $dst_width  = $conf['thumbnail_width'];
     583      $dst_height = $dst_width * $src_height / $src_width;
     584      break;
     585    }
     586    case 'height':
     587    {
     588      $dst_height = $conf['thumbnail_height'];
     589      $dst_width  = $dst_height * $src_width / $src_height;
     590      break;
     591    }
     592    case 'ratio':
     593    {
     594      $dst_width  = round($src_width * $conf['thumbnail_ratio']);
     595      $dst_height = round($src_height * $conf['thumbnail_ratio']);
     596      break;
     597    }
     598    case 'exif':
     599    default:
     600    {
     601      // Nothing to do
     602    }
     603  }
     604 
     605  // Creating icon
     606  if ($conf['thumbnail_method'] == 'exif')
     607  {
     608    $src = exif_thumbnail($file_dir.'/'.$file_short.'.'.$file_ext, $width, $height, $imagetype);
     609    if ($src === false)
     610    {
     611      $error_log .= '          <code class="failure">Failure -</code> No EXIF thumbnail in <code>';
     612      $error_log .= $file_dir.'/'.$file_short.'.'.$file_ext.'</code><br />'."\n";
     613      return $error_log;
     614    }
     615    $dst = imagecreatefromstring($src);
     616    if ($src === false)
     617    {
     618      $error_log .= '          <code class="failure">Failure -</code> EXIF thumbnail format not supported in <code>';
     619      $error_log .= $file_dir.'/'.$file_short.'.'.$file_ext.'</code><br />'."\n";
     620      return $error_log;
     621    }
     622  }
     623  else
     624  {
     625    if (($pwg_conf['gd_version_major'] != 2)) // or ($conf['thumbnail_format'] == 'gif'))
     626    {
     627      $dst = imagecreate($dst_width, $dst_height);
     628    }
     629    else
     630    {
     631      $dst = imagecreatetruecolor($dst_width, $dst_height);
     632    }
     633    $src = call_user_func('imagecreatefrom'.$src_format, $file_dir.'/'.$file_short.'.'.$file_ext);
     634    if (!$src)
     635    {
     636      $error_log .= '          <code class="failure">Failure -</code> Internal error for <code>imagecreatefrom'.$src_format.'()</code>';
     637      $error_log .= 'with <code>'.$file_dir.'/'.$file_short.'.'.$file_ext.'</code><br />'."\n";
     638      return $error_log;
     639    }
     640     
     641    if (($pwg_conf['gd_version_major'] != 2))
     642    {
     643      if (!imagecopyresized($dst, $src, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height))
     644      {
     645        $error_log .= '          <code class="failure">Failure -</code> Internal error for <code>imagecopyresized()</code>';
     646        $error_log .= 'with <code>'.$file_dir.'/'.$file_short.'.'.$file_ext.'</code><br />'."\n";
     647        return $error_log;
     648      }
     649    }
     650    else
     651    {
     652      if (!imagecopyresampled($dst, $src, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height))
     653      {
     654        $error_log .= '          <code class="failure">Failure -</code> Internal error for <code>imagecopyresampled()</code>';
     655        $error_log .= 'with <code>'.$file_dir.'/'.$file_short.'.'.$file_ext.'</code><br />'."\n";
     656        return $error_log;
     657      }
     658    }
     659  }
     660 
     661  if (!call_user_func('image'.$dst_format, $dst, $file_dir.'/'.$conf['thumbs'].'/'.$conf['prefix_thumbnail'].$file_short.'.'.$conf['thumbnail_format']))
     662  {
     663    $error_log .= '          <code class="failure">Failure -</code> Can not write <code>';
     664    $error_log .= $file_dir.'/'.$conf['thumbs'].'/'.$conf['prefix_thumbnail'].$file_short.'.'.$file_ext.'</code> to generate thumbnail<br />'."\n";
     665    return $error_log;
     666  }
     667 
     668  $error_log .= '          <code class="success">Success -</code> Thumbnail generated for <code>';
     669  $error_log .= $file_dir.'/'.$file_short.'.'.$file_ext.'</code><br />'."\n";
     670
     671  //~ pwg_log('<<<<< pwg_icon_file() returns '.var_export($error_log, TRUE).' <<<<<'."\n");
     672  return $error_log;
    361673}
    362674
     
    387699  {
    388700    // Here we scan a picture : thumbnail is mandatory, high is optionnal, representative is not scanned
    389     $element['tn_ext'] = pwg_get_thumbnail_ext($file_dir, $file_short);
     701    $element['tn_ext'] = pwg_get_thumbnail_ext($file_dir, $file_short, $file_ext, $error_log);
    390702    if ($element['tn_ext'] != '')
    391703    {
     
    540852function pwg_protect_directories($directory)
    541853{
    542   global $conf, $pwg_conf;
    543  
    544854  //~ pwg_log('>>>>> pwg_protect_directories($directory = '.var_export($directory, true).') >>>>>'."\n");
     855 
     856  global $conf;
     857 
    545858  $error_log = '';
    546859  $dirlist = array($directory, $directory.'/'.$conf['thumbs'], $directory.'/'.$conf['high'], $directory.'/'.$conf['represent']);
     
    555868        if ($file != false)
    556869        {
    557           fwrite($file, $pwg_conf['protect_content']); // the return code should be verified
     870          fwrite($file, $conf['protect_content']); // the return code should be verified
    558871          $error_log .= '          <code class="success">Success -</code> index.php created in directory <a href="'.$dir.'">'.$dir."</a><br />\n";
    559           $_SESSION['scan_cnt_fold']++;
    560872        }
    561873        else
     
    566878      else
    567879      {
    568         if ($pwg_conf['warning']['protect'])
     880        if ($conf['protect_warnings'])
    569881        {
    570882          $error_log .= '          <code class="warning">Warning -</code> index.php already exists in directory <a href="'.$dir.'">'.$dir."</a><br />\n";
    571           $_SESSION['scan_cnt_fold']++;
    572883        }
    573884      }
     
    6941005  $response = false;
    6951006  $server = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];
    696   $caller = $_SERVER['HTTP_REFERER'];
     1007  $caller = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : '';
    6971008
    6981009  if (strcasecmp($server, $caller) == 0) {
     
    7051016
    7061017// +-----------------------------------------------------------------------+
    707 // |                                pwg_<ACTION>_<STEP> FUNCTIONS          |
     1018// |                                pwg_<ACTION>_<STEP> Functions          |
    7081019// +-----------------------------------------------------------------------+
    7091020
     
    7431054  {
    7441055    $g_header  = ' : <span class="success">Test</span>'."\n";
    745     $g_message = '        This script is tagged : <code class="failure">'.$conf['version'].'</code>'."\n";
    7461056    $g_footer  = '<a href="'.$pwg_conf['this_url'].'" title="Main menu"><img src="'.$pwg_conf['icon_dir'].'up.png" /></a>'."\n";
     1057   
     1058    // Write version
     1059    $g_message  = '        <h3>Script version</h3>'."\n";
     1060    $g_message .= '        This script is tagged : <code class="failure">'.$conf['version'].'</code>'."\n";
     1061    // write GD support
     1062    if (!is_callable('gd_info'))
     1063    {
     1064      $g_message .= '        <code class="failure">Failure -</code> Your server can not generate imagess<br />'."\n";
     1065    }
     1066    else
     1067    {
     1068      $info = gd_info();
     1069      $gd_full_version = ereg_replace('[[:alpha:][:space:]()]+', '', $info['GD Version']);
     1070      list($gd_version) = preg_split('/[.]+/', $gd_full_version);
     1071     
     1072      $g_message .= '        <h3>Image generation</h3>'."\n";
     1073      $g_message .= '        <code class="success">Success -</code> Your server can generate images<br />'."\n";
     1074      $g_message .= '        <code class="warning">Warning -</code> Your server support GD'.$gd_version.' (v'.$gd_full_version.')<br />'."\n";
     1075      $format_list = array();
     1076      $format = ($info['GIF Create Support']) ? '<code>gif</code>' : NULL;
     1077      array_push($format_list, $format);
     1078      $format = ($info['JPG Support']) ? '<code>jpg</code>' : NULL;
     1079      array_push($format_list, $format);
     1080      $format = ($info['PNG Support']) ? '<code>png</code>' : NULL;
     1081      array_push($format_list, $format);
     1082      $g_message .= '        <code class="warning">Warning -</code> Your server support format: '.implode(', ', $format_list)."\n";
     1083    }
     1084   
     1085    $g_message .= '        <h3>Directory parsing</h3>'."\n";
     1086    if ($pwg_conf['safe_mode'])
     1087    {
     1088      $g_message .= '        <code class="warning">Warning -</code> Your server does not support to resize execution time'."\n";
     1089    }
     1090    else
     1091    {
     1092      $g_message .= '        <code class="success">Success -</code> Your server supports to resize execution time'."\n";
     1093    }
    7471094  }
    7481095  else
     
    8141161 
    8151162  //~ pwg_log('<<<<< pwg_clean_exit() <<<<<'."\n");
    816 }
    817 
    818 function pwg_protect_start()
    819 {
    820   //~ pwg_log('>>>>> pwg_protect_start() >>>>>'."\n");
    821  
    822   $_SESSION['scan_logs'] = pwg_get_file_list('.');
    823   sort($_SESSION['scan_list_fold']);
    824  
    825   // Erase first file list because root directory does not contain images.
    826   $_SESSION['scan_list_file'] = array();
    827  
    828   // What are we doing at next step
    829   if(count($_SESSION['scan_list_fold']) > 0)
    830   {
    831     $_SESSION['scan_step'] = 'list';
    832   }
    833   else
    834   {
    835     $_SESSION['scan_step'] = 'stop';
    836   }
    837  
    838   //~ pwg_log('<<<<< pwg_protect_start() <<<<<'."\n");
    839 }
    840 
    841 function pwg_protect_list()
    842 {
    843   //~ pwg_log('>>>>> pwg_protect_list() >>>>>'."\n");
    844 
    845   // Get list of files and directories
    846   $_SESSION['scan_logs'] .= pwg_get_file_list($_SESSION['scan_list_fold'][0]);
    847   sort($_SESSION['scan_list_fold']);
    848  
    849   // Delete unused file list
    850   $_SESSION['scan_list_file'] = array();
    851  
    852   // Position next step
    853   $_SESSION['scan_step'] = 'scan';
    854  
    855   //~ pwg_log('<<<<< pwg_protect_list() <<<<<'."\n");
    856 }
    857 
    858 function pwg_protect_scan()
    859 {
    860   //~ pwg_log('>>>>> pwg_protect_scan() >>>>>'."\n");
    861  
    862   $_SESSION['scan_logs'] .= pwg_protect_directories($_SESSION['scan_list_fold'][0]);
    863  
    864   if (isset($_SESSION['scan_list_fold'][1]))
    865   {
    866     array_shift($_SESSION['scan_list_fold']);
    867     $_SESSION['scan_step'] = 'list';
    868   }
    869   else
    870   {
    871     $_SESSION['scan_step'] = 'stop';
    872   }
    873  
    874   //~ pwg_log('<<<<< pwg_protect_scan() <<<<<'."\n");
    875 }
    876 
    877 function pwg_protect_stop()
    878 {
    879   //~ pwg_log('>>>>> pwg_protect_stop() >>>>>'."\n");
    880  
    881   global $g_header, $g_message, $g_footer, $pwg_conf;
    882  
    883   $time_elapsed = number_format(pwg_get_moment() - $_SESSION['scan_time'], 3, '.', ' ');
    884 
    885   $g_header   = ' : <span class="success">Protect</span>';
    886   $g_message  = '        <div>'."\n".$_SESSION['scan_logs'].'        </div>'."\n";
    887   $g_message .= '        <div><code class="success">'.$_SESSION['scan_cnt_fold'].'</code> directories protected</div>'."\n";
    888   $g_message .= '        <div style="{text-align: right;}">Gallery protected in : <code>'.$time_elapsed.' s</code></div>';
    889   $g_footer   = '<a href="'.$pwg_conf['this_url'].'" title="Main menu"><img src="'.$pwg_conf['icon_dir'].'up.png" /></a>';
    890  
    891   // What are we doing at next step
    892   $_SESSION['scan_step'] = 'exit';
    893  
    894   //~ pwg_log('<<<<< pwg_protect_stop() <<<<<'."\n");
    8951163}
    8961164
     
    9301198  $_SESSION['scan_list_fold'] = array();
    9311199  $_SESSION['scan_list_file'] = array();
    932   $_SESSION['scan_logs'] = pwg_get_file_list('.');
     1200  $_SESSION['scan_logs'] .= pwg_get_file_list('.');
    9331201  sort($_SESSION['scan_list_fold']);
    9341202         
     
    9831251  //~ pwg_log("GENARATE scan >>>\n".var_export($_SESSION['scan_list_fold'], true)."\n".var_export($_SESSION['scan_list_file'], true)."\nGENERATE scan >>>\n");
    9841252 
    985   global $g_listing;
     1253  global $g_listing, $conf;
    9861254 
    9871255  while (pwg_continue() and count($_SESSION['scan_list_file']) > 0)
     
    9891257    $line = '';
    9901258    $_SESSION['scan_logs'] .= pwg_scan_file($_SESSION['scan_list_file'][0], $line);
     1259   
    9911260    if (strlen($line) > 0)
    9921261    {
     
    10001269  if (count($_SESSION['scan_list_file']) <= 0)
    10011270  {
    1002     // Flush line </root>
    1003     $line = pwg_get_indent('root').'</root>'."\n";
    1004     fwrite($g_listing, $line);
    1005    
    1006     // How many directories to close
    1007     $current_level = pwg_get_level($_SESSION['scan_list_fold'][0]);
    1008     if (isset($_SESSION['scan_list_fold'][1]))
    1009     {
    1010       //~ pwg_log('---<< Pull of $_SESSION[scan_list_fold] value "'.$_SESSION['scan_list_fold'][0].'"'."\n");
    1011       array_shift($_SESSION['scan_list_fold']);
    1012       $_SESSION['scan_cnt_fold']++;
    1013       $next_level = pwg_get_level($_SESSION['scan_list_fold'][0]);
    1014       $_SESSION['scan_step'] = 'list';
    1015     }
    1016     else
    1017     {
    1018       $next_level = -1;
    1019       $_SESSION['scan_step'] = 'stop';
    1020     }
    1021    
    1022     if ($current_level == $next_level)
    1023     {
    1024       fwrite($g_listing, pwg_close_level($current_level, 1));
    1025     }
    1026     else
    1027     {
    1028       if (($current_level > $next_level))
    1029       {
    1030         fwrite($g_listing, pwg_close_level($current_level, $current_level-$next_level+1));
    1031       } // Nothing to do if current_level < next_level
    1032     }
     1271    $_SESSION['scan_step'] = 'prot';
    10331272  }
    10341273 
    10351274  //~ pwg_log("GENERATE scan <<<\n".var_export($_SESSION['scan_list_fold'], true)."\n".var_export($_SESSION['scan_list_file'], true)."\nGENERATE scan <<<\n");
    10361275  //~ pwg_log('<<<<< pwg_generate_scan() <<<<<'."\n");
     1276}
     1277
     1278function pwg_generate_prot()
     1279{
     1280  //~ pwg_log('>>>>> pwg_generate_prot() >>>>>'."\n");
     1281  //~ pwg_log("GENARATE prot >>>\n".var_export($_SESSION['scan_list_fold'], true)."\n".var_export($_SESSION['scan_list_file'], true)."\nGENERATE prot >>>\n");
     1282 
     1283  global $conf, $g_listing;
     1284 
     1285  // Flush line </root>
     1286  $line = pwg_get_indent('root').'</root>'."\n";
     1287  fwrite($g_listing, $line);
     1288 
     1289  if ($conf['protect'])
     1290  {
     1291    $_SESSION['scan_logs'] .= pwg_protect_directories($_SESSION['scan_list_fold'][0]);
     1292  }
     1293 
     1294  // How many directories to close
     1295  $current_level = pwg_get_level($_SESSION['scan_list_fold'][0]);
     1296  if (isset($_SESSION['scan_list_fold'][1]))
     1297  {
     1298    //~ pwg_log('---<< Pull of $_SESSION[scan_list_fold] value "'.$_SESSION['scan_list_fold'][0].'"'."\n");
     1299    array_shift($_SESSION['scan_list_fold']);
     1300    $_SESSION['scan_cnt_fold']++;
     1301    $next_level = pwg_get_level($_SESSION['scan_list_fold'][0]);
     1302    $_SESSION['scan_step'] = 'list';
     1303  }
     1304  else
     1305  {
     1306    $next_level = -1;
     1307    $_SESSION['scan_cnt_fold']++;
     1308    $_SESSION['scan_step'] = 'stop';
     1309  }
     1310 
     1311  if ($current_level == $next_level)
     1312  {
     1313    fwrite($g_listing, pwg_close_level($current_level, 1));
     1314  }
     1315  else
     1316  {
     1317    if (($current_level > $next_level))
     1318    {
     1319      fwrite($g_listing, pwg_close_level($current_level, $current_level-$next_level+1));
     1320    } // Nothing to do if current_level < next_level
     1321  }
     1322
     1323  //~ pwg_log("GENERATE prot <<<\n".var_export($_SESSION['scan_list_fold'], true)."\n".var_export($_SESSION['scan_list_file'], true)."\nGENERATE prot <<<\n");
     1324  //~ pwg_log('<<<<< pwg_generate_prot() <<<<<'."\n");
    10371325}
    10381326
     
    11531441
    11541442  global $g_message, $g_listing, $g_footer, $conf, $pwg_conf, $start_time;
     1443  $init_message = '';
    11551444 
    11561445  // Lock other script sessions, this lock will be remove during 'exit' step
     
    12191508    $g_message .= '          <li><a href="'.$pwg_conf['this_url'].'?action=clean" title="Delete listing.xml if exists">Clean</a></li>'."\n";
    12201509    $g_message .= '          <li><a href="'.$pwg_conf['this_url'].'?action=generate" title="Scan all images from this directory and write informations in listing.xml">Listing</a></li>'."\n";
    1221     $g_message .= '          <li><a href="'.$pwg_conf['this_url'].'?action=protect" title="Protect all directories from this point with index.php">Protect</a></li>'."\n";
    12221510    $g_message .= '        </ul>'."\n";
    12231511    $g_footer   = '<a href="'.$conf['gallery'].'/admin.php?page=site_manager" title="Main gallery :: site manager">';
    12241512    $g_footer  .= '<img src="'.$pwg_conf['icon_dir'].'home.png" /></a>'."\n";
    12251513    $_SESSION['scan_step'] = 'exit';
    1226   }
    1227  
    1228   // Open listing.xml
     1514    $_SESSION['scan_action'] = '';
     1515  }
     1516 
     1517  // Actions to do at the init of generate
    12291518  if ($_SESSION['scan_action'] == 'generate')
    12301519  {
     1520    // Open XML file
    12311521    $mode = ($_SESSION['scan_step'] == 'init') ? 'w' : 'a'; // Erase old listing.xml at the beginning of generation (mode w)
    12321522    $g_listing = @fopen('listing.xml', $mode);
     
    12411531      return;
    12421532    }
    1243   }
    1244  
     1533   
     1534    // Check graphical capabilities
     1535    $init_message = pwg_check_graphics();
     1536  }
     1537   
    12451538  // Initializing session counters. This counters will be completely unset during step 'exit'
    12461539  if ($_SESSION['scan_step'] == 'init')
     
    12521545    $_SESSION['scan_time'] = $start_time;
    12531546    $_SESSION['scan_step'] = 'start';
    1254     $_SESSION['scan_logs'] = '';
     1547    $_SESSION['scan_logs'] = $init_message;
    12551548  }
    12561549 
     
    12911584  unset($_SESSION['scan_action']);
    12921585  unset($_SESSION['scan_logs']);
    1293 
    1294 
     1586  session_destroy();
     1587 
    12951588  // Call specific action post process
    12961589  if (is_callable('pwg_'.$local_action.'_exit'))
     
    13031596
    13041597// +-----------------------------------------------------------------------+
    1305 // |                                script                                 |
     1598// |                                Script                                 |
    13061599// +-----------------------------------------------------------------------+
     1600session_save_path('.');
    13071601session_start();
    13081602
Note: See TracChangeset for help on using the changeset viewer.