diff options
author | laurent.duretz <laurent.duretz@piwigo.org> | 2007-02-15 18:50:08 +0000 |
---|---|---|
committer | laurent.duretz <laurent.duretz@piwigo.org> | 2007-02-15 18:50:08 +0000 |
commit | e1c10b7e35930d9eaec636fbb1b4b4c8daf041eb (patch) | |
tree | 981c2766d58274ed205534126839abc0a090243a /tools | |
parent | bfc5e81f8d5eede2b1edd10a584d83735ad62dbf (diff) |
Integration of remote site protection in generate action
git-svn-id: http://piwigo.org/svn/trunk@1823 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r-- | tools/create_listing_file.php | 588 |
1 files changed, 441 insertions, 147 deletions
diff --git a/tools/create_listing_file.php b/tools/create_listing_file.php index b5ab6491a..1342cbc84 100644 --- a/tools/create_listing_file.php +++ b/tools/create_listing_file.php @@ -29,38 +29,39 @@ // | User configuration | // +-----------------------------------------------------------------------+ +// ****** Gallery configuration ****** // // Srcipt version $conf['version'] = 'Alligator'; +// URL of main gallery +$conf['gallery'] = 'http://'; + // prefix for thumbnails in "thumbnail" sub directories $conf['prefix_thumbnail'] = 'TN-'; // $conf['file_ext'] lists all extensions (case insensitive) allowed for your PhpWebGallery installation -$conf['file_ext'] = array('jpg','JPG','png','PNG','gif','GIF','mpg','zip', 'avi','mp3','ogg'); +$conf['file_ext'] = array('jpg','JPG','jpeg','JPEG','png','PNG','gif','GIF','mpg','zip', 'avi','mp3','ogg'); // $conf['picture_ext'] must be a subset of $conf['file_ext'] -$conf['picture_ext'] = array('jpg','JPG','png','PNG','gif','GIF'); +$conf['picture_ext'] = array('jpg','JPG','jpeg','JPEG','png','PNG','gif','GIF'); -// URL of main gallery -$conf['gallery'] = 'http://'; - -// max excution time before refresh in seconds +// ****** Time limitation functionality ****** // +// max execution time before refresh in seconds $conf['max_execution_time'] = (5*ini_get('max_execution_time'))/6; // 25 seconds with default PHP configuration // refresh delay is seconds $conf['refresh_delay'] = 0; -// $conf['file_ext'] lists all extensions (case insensitive) allowed for your PhpWebGallery installation -$conf['file_ext'] = array('jpg','JPG','jpeg','JPEG','png','PNG','gif','GIF','mpg','zip', 'avi','mp3','ogg'); - +// ****** EXIF support functionality ****** // // $conf['use_exif'] set to true if you want to use Exif information -$conf['use_exif'] = true; +$conf['use_exif'] = false; // use_exif_mapping: same behaviour as use_iptc_mapping $conf['use_exif_mapping'] = array( 'date_creation' => 'DateTimeOriginal' ); +// ****** IPTC support functionality ****** // // $conf['use_iptc'] set to true if you want to use IPTC informations of the // element according to get_sync_iptc_data function mapping, otherwise, set // to false @@ -76,9 +77,41 @@ $conf['use_iptc_mapping'] = array( 'name' => '2#005', 'comment' => '2#120'); +// ****** Directory protection functionality ****** // +// Define if directories have to be protected if they are not +$conf['protect'] = false; + // index.php content for command 'protect' $conf['protect_content'] = '<?php header("Location: '.$conf['gallery'].'") ?>'; +// true/false : show/hide warnings +$conf['protect_warnings'] = true; + +// ****** Thumbnails generation functionality ****** // +// Define if images have to be reduced if they are not +$conf['thumbnail'] = false; + +// Define method to generate thumbnails : +// - fixed (width and height required); +// - width (only width required); +// - height (only height required); +// - ratio (only ratio is required) +// - exif (no other parameter required) +$conf['thumbnail_method'] = 'ratio'; + +// Height in pixels (greater than 0) +$conf['thumbnail_height'] = 96; + +// Width in pixels (greater than 0) +$conf['thumbnail_width'] = 96; + +// Ratio between original and thumbnail size (strictly between 0 and 1) +$conf['thumbnail_ratio'] = 0.2; + +// Define thumbnail format : jpeg, png or gif (will be verified) +$conf['thumbnail_format'] = 'jpeg'; + +// ****** Directory mapping ****** // // directories names $conf['thumbs'] = 'thumbnail'; // thumbnails $conf['high'] = 'pwg_high'; // high resolution @@ -92,7 +125,7 @@ $conf['represent'] = 'pwg_representative'; // non pictures representative files $pwg_conf['icon_dir'] = $conf['gallery'].'/template/yoga/icon/'; // list of actions managed by this script -$pwg_conf['scan_action'] = array('clean', 'test', 'generate', 'protect'); +$pwg_conf['scan_action'] = array('clean', 'test', 'generate'); // url of this script $pwg_conf['this_url'] = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']; @@ -106,13 +139,13 @@ $pwg_conf['protect_content'] = '<?php header("Location: '.$conf['gallery'].'") ? // backup of PHP safe_mode INI parameter (used for time limitation) $pwg_conf['safe_mode'] = (ini_get('safe_mode') == '1') ? true : false; -// Error level management -// true : show warnings -// false : hide warnings -$pwg_conf['warning']['protect'] = true; +// This parameter will be fixed in pwg_init() +$pwg_conf['gd_version_major'] = ''; +$pwg_conf['gd_version_full'] = ''; +$pwg_conf['gd_supported_format'] = array(); // +-----------------------------------------------------------------------+ -// | functions | +// | Functions | // +-----------------------------------------------------------------------+ /** @@ -129,6 +162,124 @@ function pwg_log($line) } /** + * Check web server graphical capabilities + * + * @return string + */ +function pwg_check_graphics() +{ + //~ pwg_log('>>>>> pwg_check_graphics() >>>>>'."\n"); + + global $conf, $pwg_conf; + $log = ''; + + // Verify gd library for thumbnail generation + if ($conf['thumbnail'] and !is_callable('gd_info')) + { + $log .= ' <code class="warning">Warning -</code> Your server can not generate thumbnails. Thumbnail creation switched off.<br />'."\n"; + // Switch off thumbnail generation + $conf['thumbnail'] = false; + return $log; + } + + // Verify thumnail format + if ($conf['thumbnail']) + { + $info = gd_info(); + + // Backup GD major version + $pwg_conf['gd_version_full'] = ereg_replace('[[:alpha:][:space:]()]+', '', $info['GD Version']); + list($pwg_conf['gd_version_major']) = preg_split('/[.]+/', $pwg_conf['gd_version_full']); + + // Backup input/output format support + array_push($pwg_conf['gd_supported_format'], $info['JPG Support'] ? 'jpeg' : NULL); + array_push($pwg_conf['gd_supported_format'], $info['PNG Support'] ? 'png' : NULL); + array_push($pwg_conf['gd_supported_format'], ($info['GIF Read Support'] and $info['GIF Create Support']) ? 'gif' : NULL); + + // Check output format support + if (!in_array($conf['thumbnail_format'], $pwg_conf['gd_supported_format'])) + { + $log .= ' <code class="warning">Warning -</code> Your server does not support thumbnail\'s <code>'; + $log .= $conf['thumbnail_format'].'</code> format. Thumbnail creation switched off.<br />'."\n"; + } + + switch ($conf['thumbnail_method']) + { + case 'exif': + { + // exif_thumbnail() must be callable + if (!is_callable('exif_thumbnail')) + { + $log .= ' <code class="warning">Warning -</code> Your server does not support thumbnail creation through EXIF datas. Thumbnail creation switched off.<br />'."\n"; + } + break; + } + case 'fixed': + { + // $conf['thumbnail_width'] > 0 + if (!is_numeric($conf['thumbnail_width']) or $conf['thumbnail_width'] <= 0) + { + $log .= ' <code class="failure">Failure -</code> Bad value <code>thumbnail_width = '; + $log .= var_export($conf['thumbnail_width'], true).'</code>. Thumbnail creation switched off.<br />'."\n"; + } + // $conf['thumbnail_height'] > 0 + if (!is_numeric($conf['thumbnail_height']) or $conf['thumbnail_height'] <= 0) + { + $log .= ' <code class="failure">Failure -</code> Bad value <code>thumbnail_height = '; + $log .= var_export($conf['thumbnail_height'], true).'</code>. Thumbnail creation switched off.<br />'."\n"; + } + break; + } + case 'ratio': + { + // 0 < $conf['thumbnail_ratio'] < 1 + if (!is_numeric($conf['thumbnail_ratio']) or $conf['thumbnail_ratio'] <= 0 or $conf['thumbnail_ratio'] >= 1) + { + $log .= ' <code class="failure">Failure -</code> Bad value <code>thumbnail_ratio = '; + $log .= var_export($conf['thumbnail_ratio'], true).'</code>. Thumbnail creation switched off.<br />'."\n"; + } + break; + } + case 'width': + { + // $conf['thumbnail_width'] > 0 + if (!is_numeric($conf['thumbnail_width']) or $conf['thumbnail_width'] <= 0) + { + $log .= ' <code class="failure">Failure -</code> Bad value <code>thumbnail_width = '; + $log .= var_export($conf['thumbnail_width'], true).'</code>. Thumbnail creation switched off.<br />'."\n"; + } + break; + } + case 'height': + { + // $conf['thumbnail_height'] > 0 + if (!is_numeric($conf['thumbnail_height']) or $conf['thumbnail_height'] <= 0) + { + $log .= ' <code class="failure">Failure -</code> Bad value <code>thumbnail_height = '; + $log .= var_export($conf['thumbnail_height'], true).'</code>. Thumbnail creation switched off.<br />'."\n"; + } + break; + } + default: + { + // unknown method + $log .= ' <code class="failure">Failure -</code> Bad value <code>thumbnail_method = '; + $log .= var_export($conf['thumbnail_method'], true).'</code>. Thumbnail creation switched off.<br />'."\n"; + break; + } + } + + if (strlen($log)) + { + $conf['thumbnail'] = false; + } + } + + //~ pwg_log('<<<<< pwg_check_graphics() returns '.var_export($log, TRUE).' <<<<<'."\n"); + return $log; +} + +/** * returns xml </dirX> lines * * @param integer $dir_start @@ -334,13 +485,15 @@ function pwg_get_filename_wo_extension($filename) } /** - * return extension of the thumbnail + * return extension of the thumbnail and complete error_log * * @param string $file_dir * @param string $file_short + * @param string $file_ext + * @param string &$error_log * @return string */ -function pwg_get_thumbnail_ext($file_dir, $file_short) +function pwg_get_thumbnail_ext($file_dir, $file_short, $file_ext, &$error_log) { //~ pwg_log('>>>>> pwg_get_thumbnail_ext($file_dir = '.var_export($file_dir, TRUE).', $file_short = '.var_export($file_short, TRUE).') >>>>>'."\n"); @@ -356,10 +509,169 @@ function pwg_get_thumbnail_ext($file_dir, $file_short) } } + if ($thumb_ext == '') + { + if ($conf['thumbnail']) + { + $log = pwg_icon_file($file_dir, $file_short, $file_ext); + if (strpos($log, 'success')) + { + $thumb_ext = $conf['thumbnail_format']; + } + $error_log .= $log; + } + } + //~ pwg_log('<<<<< pwg_get_thumbnail_ext() returns '.var_export($thumb_ext, TRUE).' <<<<<'."\n"); return $thumb_ext; } + +/** + * return error logs + * + * @param string $file_dir + * @param string $file_short + * @param string $file_ext + * @return string + */ +function pwg_icon_file($file_dir, $file_short, $file_ext) +{ + //~ pwg_log('>>>>> pwg_icon_file($file_dir = '.var_export($file_dir, TRUE).', $file_short = '.var_export($file_short, TRUE).') >>>>>'."\n"); + + global $conf, $pwg_conf; + + $error_log = ''; + + // Get original properties (width, height) + if ($image_size = getimagesize($file_dir.'/'.$file_short.'.'.$file_ext)) + { + $src_width = $image_size[0]; + $src_height = $image_size[1]; + } + else + { + $error_log .= ' <code class="failure">Failure -</code> Can not generate icon for <code>'; + $error_log .= $file_dir.'/'.$file_short.'.'.$file_ext.'</code>'; + $error_log .= ' <img src="'.$pwg_conf['icon_dir'].'add_tag.png" title="width/height are unreadable" /><br />'."\n"; + return $error_log; + } + + // Check input format + $dst_format = $conf['thumbnail_format']; + $src_format = ($file_ext == 'jpg' or $file_ext == 'JPG') ? 'jpeg' : strtolower($file_ext); + if (!in_array($src_format, $pwg_conf['gd_supported_format'])) + { + $error_log .= ' <code class="failure">Failure -</code> Can not generate icon for <code>'; + $error_log .= $file_dir.'/'.$file_short.'.'.$file_ext.'</code>'; + $error_log .= ' <img src="'.$pwg_conf['icon_dir'].'add_tag.png" title="format not supported" /><br />'."\n"; + return $error_log; + } + + // Calculate icon properties (width, height) + switch ($conf['thumbnail_method']) + { + case 'fixed': + { + $dst_width = $conf['thumbnail_width']; + $dst_height = $conf['thumbnail_height']; + break; + } + case 'width': + { + $dst_width = $conf['thumbnail_width']; + $dst_height = $dst_width * $src_height / $src_width; + break; + } + case 'height': + { + $dst_height = $conf['thumbnail_height']; + $dst_width = $dst_height * $src_width / $src_height; + break; + } + case 'ratio': + { + $dst_width = round($src_width * $conf['thumbnail_ratio']); + $dst_height = round($src_height * $conf['thumbnail_ratio']); + break; + } + case 'exif': + default: + { + // Nothing to do + } + } + + // Creating icon + if ($conf['thumbnail_method'] == 'exif') + { + $src = exif_thumbnail($file_dir.'/'.$file_short.'.'.$file_ext, $width, $height, $imagetype); + if ($src === false) + { + $error_log .= ' <code class="failure">Failure -</code> No EXIF thumbnail in <code>'; + $error_log .= $file_dir.'/'.$file_short.'.'.$file_ext.'</code><br />'."\n"; + return $error_log; + } + $dst = imagecreatefromstring($src); + if ($src === false) + { + $error_log .= ' <code class="failure">Failure -</code> EXIF thumbnail format not supported in <code>'; + $error_log .= $file_dir.'/'.$file_short.'.'.$file_ext.'</code><br />'."\n"; + return $error_log; + } + } + else + { + if (($pwg_conf['gd_version_major'] != 2)) // or ($conf['thumbnail_format'] == 'gif')) + { + $dst = imagecreate($dst_width, $dst_height); + } + else + { + $dst = imagecreatetruecolor($dst_width, $dst_height); + } + $src = call_user_func('imagecreatefrom'.$src_format, $file_dir.'/'.$file_short.'.'.$file_ext); + if (!$src) + { + $error_log .= ' <code class="failure">Failure -</code> Internal error for <code>imagecreatefrom'.$src_format.'()</code>'; + $error_log .= 'with <code>'.$file_dir.'/'.$file_short.'.'.$file_ext.'</code><br />'."\n"; + return $error_log; + } + + if (($pwg_conf['gd_version_major'] != 2)) + { + if (!imagecopyresized($dst, $src, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height)) + { + $error_log .= ' <code class="failure">Failure -</code> Internal error for <code>imagecopyresized()</code>'; + $error_log .= 'with <code>'.$file_dir.'/'.$file_short.'.'.$file_ext.'</code><br />'."\n"; + return $error_log; + } + } + else + { + if (!imagecopyresampled($dst, $src, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height)) + { + $error_log .= ' <code class="failure">Failure -</code> Internal error for <code>imagecopyresampled()</code>'; + $error_log .= 'with <code>'.$file_dir.'/'.$file_short.'.'.$file_ext.'</code><br />'."\n"; + return $error_log; + } + } + } + + if (!call_user_func('image'.$dst_format, $dst, $file_dir.'/'.$conf['thumbs'].'/'.$conf['prefix_thumbnail'].$file_short.'.'.$conf['thumbnail_format'])) + { + $error_log .= ' <code class="failure">Failure -</code> Can not write <code>'; + $error_log .= $file_dir.'/'.$conf['thumbs'].'/'.$conf['prefix_thumbnail'].$file_short.'.'.$file_ext.'</code> to generate thumbnail<br />'."\n"; + return $error_log; + } + + $error_log .= ' <code class="success">Success -</code> Thumbnail generated for <code>'; + $error_log .= $file_dir.'/'.$file_short.'.'.$file_ext.'</code><br />'."\n"; + + //~ pwg_log('<<<<< pwg_icon_file() returns '.var_export($error_log, TRUE).' <<<<<'."\n"); + return $error_log; +} + /** * completes xml line <element .../> and returns error log * @@ -386,7 +698,7 @@ function pwg_scan_file($file_full, &$line) if (in_array($file_ext, $conf['picture_ext'])) { // Here we scan a picture : thumbnail is mandatory, high is optionnal, representative is not scanned - $element['tn_ext'] = pwg_get_thumbnail_ext($file_dir, $file_short); + $element['tn_ext'] = pwg_get_thumbnail_ext($file_dir, $file_short, $file_ext, $error_log); if ($element['tn_ext'] != '') { // picture has a thumbnail, get image width, heigth, size in Mo @@ -539,9 +851,10 @@ function pwg_get_indent($element_type) */ function pwg_protect_directories($directory) { - global $conf, $pwg_conf; - //~ pwg_log('>>>>> pwg_protect_directories($directory = '.var_export($directory, true).') >>>>>'."\n"); + + global $conf; + $error_log = ''; $dirlist = array($directory, $directory.'/'.$conf['thumbs'], $directory.'/'.$conf['high'], $directory.'/'.$conf['represent']); @@ -554,9 +867,8 @@ function pwg_protect_directories($directory) $file = @fopen($dir.'/index.php', 'w'); if ($file != false) { - fwrite($file, $pwg_conf['protect_content']); // the return code should be verified + fwrite($file, $conf['protect_content']); // the return code should be verified $error_log .= ' <code class="success">Success -</code> index.php created in directory <a href="'.$dir.'">'.$dir."</a><br />\n"; - $_SESSION['scan_cnt_fold']++; } else { @@ -565,10 +877,9 @@ function pwg_protect_directories($directory) } else { - if ($pwg_conf['warning']['protect']) + if ($conf['protect_warnings']) { $error_log .= ' <code class="warning">Warning -</code> index.php already exists in directory <a href="'.$dir.'">'.$dir."</a><br />\n"; - $_SESSION['scan_cnt_fold']++; } } } @@ -693,7 +1004,7 @@ function pwg_referer_is_me() $response = false; $server = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']; - $caller = $_SERVER['HTTP_REFERER']; + $caller = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : ''; if (strcasecmp($server, $caller) == 0) { $response = true; @@ -704,7 +1015,7 @@ function pwg_referer_is_me() } // +-----------------------------------------------------------------------+ -// | pwg_<ACTION>_<STEP> FUNCTIONS | +// | pwg_<ACTION>_<STEP> Functions | // +-----------------------------------------------------------------------+ function pwg_test_start() @@ -742,8 +1053,44 @@ function pwg_test_exit() if (pwg_referer_is_me()) { $g_header = ' : <span class="success">Test</span>'."\n"; - $g_message = ' This script is tagged : <code class="failure">'.$conf['version'].'</code>'."\n"; $g_footer = '<a href="'.$pwg_conf['this_url'].'" title="Main menu"><img src="'.$pwg_conf['icon_dir'].'up.png" /></a>'."\n"; + + // Write version + $g_message = ' <h3>Script version</h3>'."\n"; + $g_message .= ' This script is tagged : <code class="failure">'.$conf['version'].'</code>'."\n"; + // write GD support + if (!is_callable('gd_info')) + { + $g_message .= ' <code class="failure">Failure -</code> Your server can not generate imagess<br />'."\n"; + } + else + { + $info = gd_info(); + $gd_full_version = ereg_replace('[[:alpha:][:space:]()]+', '', $info['GD Version']); + list($gd_version) = preg_split('/[.]+/', $gd_full_version); + + $g_message .= ' <h3>Image generation</h3>'."\n"; + $g_message .= ' <code class="success">Success -</code> Your server can generate images<br />'."\n"; + $g_message .= ' <code class="warning">Warning -</code> Your server support GD'.$gd_version.' (v'.$gd_full_version.')<br />'."\n"; + $format_list = array(); + $format = ($info['GIF Create Support']) ? '<code>gif</code>' : NULL; + array_push($format_list, $format); + $format = ($info['JPG Support']) ? '<code>jpg</code>' : NULL; + array_push($format_list, $format); + $format = ($info['PNG Support']) ? '<code>png</code>' : NULL; + array_push($format_list, $format); + $g_message .= ' <code class="warning">Warning -</code> Your server support format: '.implode(', ', $format_list)."\n"; + } + + $g_message .= ' <h3>Directory parsing</h3>'."\n"; + if ($pwg_conf['safe_mode']) + { + $g_message .= ' <code class="warning">Warning -</code> Your server does not support to resize execution time'."\n"; + } + else + { + $g_message .= ' <code class="success">Success -</code> Your server supports to resize execution time'."\n"; + } } else { @@ -815,85 +1162,6 @@ function pwg_clean_exit() //~ pwg_log('<<<<< pwg_clean_exit() <<<<<'."\n"); } -function pwg_protect_start() -{ - //~ pwg_log('>>>>> pwg_protect_start() >>>>>'."\n"); - - $_SESSION['scan_logs'] = pwg_get_file_list('.'); - sort($_SESSION['scan_list_fold']); - - // Erase first file list because root directory does not contain images. - $_SESSION['scan_list_file'] = array(); - - // What are we doing at next step - if(count($_SESSION['scan_list_fold']) > 0) - { - $_SESSION['scan_step'] = 'list'; - } - else - { - $_SESSION['scan_step'] = 'stop'; - } - - //~ pwg_log('<<<<< pwg_protect_start() <<<<<'."\n"); -} - -function pwg_protect_list() -{ - //~ pwg_log('>>>>> pwg_protect_list() >>>>>'."\n"); - - // Get list of files and directories - $_SESSION['scan_logs'] .= pwg_get_file_list($_SESSION['scan_list_fold'][0]); - sort($_SESSION['scan_list_fold']); - - // Delete unused file list - $_SESSION['scan_list_file'] = array(); - - // Position next step - $_SESSION['scan_step'] = 'scan'; - - //~ pwg_log('<<<<< pwg_protect_list() <<<<<'."\n"); -} - -function pwg_protect_scan() -{ - //~ pwg_log('>>>>> pwg_protect_scan() >>>>>'."\n"); - - $_SESSION['scan_logs'] .= pwg_protect_directories($_SESSION['scan_list_fold'][0]); - - if (isset($_SESSION['scan_list_fold'][1])) - { - array_shift($_SESSION['scan_list_fold']); - $_SESSION['scan_step'] = 'list'; - } - else - { - $_SESSION['scan_step'] = 'stop'; - } - - //~ pwg_log('<<<<< pwg_protect_scan() <<<<<'."\n"); -} - -function pwg_protect_stop() -{ - //~ pwg_log('>>>>> pwg_protect_stop() >>>>>'."\n"); - - global $g_header, $g_message, $g_footer, $pwg_conf; - - $time_elapsed = number_format(pwg_get_moment() - $_SESSION['scan_time'], 3, '.', ' '); - - $g_header = ' : <span class="success">Protect</span>'; - $g_message = ' <div>'."\n".$_SESSION['scan_logs'].' </div>'."\n"; - $g_message .= ' <div><code class="success">'.$_SESSION['scan_cnt_fold'].'</code> directories protected</div>'."\n"; - $g_message .= ' <div style="{text-align: right;}">Gallery protected in : <code>'.$time_elapsed.' s</code></div>'; - $g_footer = '<a href="'.$pwg_conf['this_url'].'" title="Main menu"><img src="'.$pwg_conf['icon_dir'].'up.png" /></a>'; - - // What are we doing at next step - $_SESSION['scan_step'] = 'exit'; - - //~ pwg_log('<<<<< pwg_protect_stop() <<<<<'."\n"); -} - function pwg_generate_start() { //~ pwg_log('>>>>> pwg_generate_start() >>>>>'."\n"); @@ -929,7 +1197,7 @@ function pwg_generate_start() // Initialization of directory and file lists $_SESSION['scan_list_fold'] = array(); $_SESSION['scan_list_file'] = array(); - $_SESSION['scan_logs'] = pwg_get_file_list('.'); + $_SESSION['scan_logs'] .= pwg_get_file_list('.'); sort($_SESSION['scan_list_fold']); // Erase first file list because root directory does not contain images. @@ -982,12 +1250,13 @@ function pwg_generate_scan() //~ pwg_log('>>>>> pwg_generate_scan() >>>>>'."\n"); //~ pwg_log("GENARATE scan >>>\n".var_export($_SESSION['scan_list_fold'], true)."\n".var_export($_SESSION['scan_list_file'], true)."\nGENERATE scan >>>\n"); - global $g_listing; + global $g_listing, $conf; while (pwg_continue() and count($_SESSION['scan_list_file']) > 0) { $line = ''; $_SESSION['scan_logs'] .= pwg_scan_file($_SESSION['scan_list_file'][0], $line); + if (strlen($line) > 0) { fwrite($g_listing, $line); @@ -999,43 +1268,62 @@ function pwg_generate_scan() if (count($_SESSION['scan_list_file']) <= 0) { - // Flush line </root> - $line = pwg_get_indent('root').'</root>'."\n"; - fwrite($g_listing, $line); - - // How many directories to close - $current_level = pwg_get_level($_SESSION['scan_list_fold'][0]); - if (isset($_SESSION['scan_list_fold'][1])) - { - //~ pwg_log('---<< Pull of $_SESSION[scan_list_fold] value "'.$_SESSION['scan_list_fold'][0].'"'."\n"); - array_shift($_SESSION['scan_list_fold']); - $_SESSION['scan_cnt_fold']++; - $next_level = pwg_get_level($_SESSION['scan_list_fold'][0]); - $_SESSION['scan_step'] = 'list'; - } - else - { - $next_level = -1; - $_SESSION['scan_step'] = 'stop'; - } - - if ($current_level == $next_level) - { - fwrite($g_listing, pwg_close_level($current_level, 1)); - } - else - { - if (($current_level > $next_level)) - { - fwrite($g_listing, pwg_close_level($current_level, $current_level-$next_level+1)); - } // Nothing to do if current_level < next_level - } + $_SESSION['scan_step'] = 'prot'; } //~ pwg_log("GENERATE scan <<<\n".var_export($_SESSION['scan_list_fold'], true)."\n".var_export($_SESSION['scan_list_file'], true)."\nGENERATE scan <<<\n"); //~ pwg_log('<<<<< pwg_generate_scan() <<<<<'."\n"); } +function pwg_generate_prot() +{ + //~ pwg_log('>>>>> pwg_generate_prot() >>>>>'."\n"); + //~ pwg_log("GENARATE prot >>>\n".var_export($_SESSION['scan_list_fold'], true)."\n".var_export($_SESSION['scan_list_file'], true)."\nGENERATE prot >>>\n"); + + global $conf, $g_listing; + + // Flush line </root> + $line = pwg_get_indent('root').'</root>'."\n"; + fwrite($g_listing, $line); + + if ($conf['protect']) + { + $_SESSION['scan_logs'] .= pwg_protect_directories($_SESSION['scan_list_fold'][0]); + } + + // How many directories to close + $current_level = pwg_get_level($_SESSION['scan_list_fold'][0]); + if (isset($_SESSION['scan_list_fold'][1])) + { + //~ pwg_log('---<< Pull of $_SESSION[scan_list_fold] value "'.$_SESSION['scan_list_fold'][0].'"'."\n"); + array_shift($_SESSION['scan_list_fold']); + $_SESSION['scan_cnt_fold']++; + $next_level = pwg_get_level($_SESSION['scan_list_fold'][0]); + $_SESSION['scan_step'] = 'list'; + } + else + { + $next_level = -1; + $_SESSION['scan_cnt_fold']++; + $_SESSION['scan_step'] = 'stop'; + } + + if ($current_level == $next_level) + { + fwrite($g_listing, pwg_close_level($current_level, 1)); + } + else + { + if (($current_level > $next_level)) + { + fwrite($g_listing, pwg_close_level($current_level, $current_level-$next_level+1)); + } // Nothing to do if current_level < next_level + } + + //~ pwg_log("GENERATE prot <<<\n".var_export($_SESSION['scan_list_fold'], true)."\n".var_export($_SESSION['scan_list_file'], true)."\nGENERATE prot <<<\n"); + //~ pwg_log('<<<<< pwg_generate_prot() <<<<<'."\n"); +} + function pwg_generate_stop() { //~ pwg_log('>>>>> pwg_generate_stop() >>>>>'."\n"); @@ -1152,6 +1440,7 @@ function pwg_init() //~ pwg_log('>>>>> pwg_init() >>>>>'."\n"); global $g_message, $g_listing, $g_footer, $conf, $pwg_conf, $start_time; + $init_message = ''; // Lock other script sessions, this lock will be remove during 'exit' step if (!isset($_SESSION['scan_step'])) @@ -1218,16 +1507,17 @@ function pwg_init() $g_message .= ' <li><a href="'.$pwg_conf['this_url'].'?action=test" title="Display/Compare script version">Test</a></li>'."\n"; $g_message .= ' <li><a href="'.$pwg_conf['this_url'].'?action=clean" title="Delete listing.xml if exists">Clean</a></li>'."\n"; $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"; - $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"; $g_message .= ' </ul>'."\n"; $g_footer = '<a href="'.$conf['gallery'].'/admin.php?page=site_manager" title="Main gallery :: site manager">'; $g_footer .= '<img src="'.$pwg_conf['icon_dir'].'home.png" /></a>'."\n"; $_SESSION['scan_step'] = 'exit'; + $_SESSION['scan_action'] = ''; } - // Open listing.xml + // Actions to do at the init of generate if ($_SESSION['scan_action'] == 'generate') { + // Open XML file $mode = ($_SESSION['scan_step'] == 'init') ? 'w' : 'a'; // Erase old listing.xml at the beginning of generation (mode w) $g_listing = @fopen('listing.xml', $mode); if ($g_listing === false) @@ -1240,8 +1530,11 @@ function pwg_init() //~ pwg_log('<<<<< pwg_init() failure <<<<<'."\n"); return; } + + // Check graphical capabilities + $init_message = pwg_check_graphics(); } - + // Initializing session counters. This counters will be completely unset during step 'exit' if ($_SESSION['scan_step'] == 'init') { @@ -1251,7 +1544,7 @@ function pwg_init() $_SESSION['scan_cnt_fold'] = 0; $_SESSION['scan_time'] = $start_time; $_SESSION['scan_step'] = 'start'; - $_SESSION['scan_logs'] = ''; + $_SESSION['scan_logs'] = $init_message; } //~ pwg_log('<<<<< pwg_init() success <<<<<'."\n"); @@ -1290,8 +1583,8 @@ function pwg_exit() $local_action = $_SESSION['scan_action']; unset($_SESSION['scan_action']); unset($_SESSION['scan_logs']); - - + session_destroy(); + // Call specific action post process if (is_callable('pwg_'.$local_action.'_exit')) { @@ -1302,8 +1595,9 @@ function pwg_exit() } // +-----------------------------------------------------------------------+ -// | script | +// | Script | // +-----------------------------------------------------------------------+ +session_save_path('.'); session_start(); $start_time = pwg_get_moment(); |