FUNCTIONS |
+// +-----------------------------------------------------------------------+
- $pictures = array();
- if ($opendir = opendir($dir))
+function pwg_test_start()
+{
+ //~ pwg_log('>>>>> pwg_test_start() >>>>>'."\n");
+
+ global $g_message, $conf;
+
+ if (isset($_REQUEST['version']))
{
- while ($file = readdir($opendir))
+ if ($_REQUEST['version'] != $conf['version'])
{
- if (in_array(get_extension($file), $conf['file_ext']))
- {
- array_push($pictures, $file);
- if (!preg_match('/^[a-zA-Z0-9-_.]+$/', $file))
- {
- echo 'PWG-WARNING-2: "'.$file.'" : ';
- echo 'The name of the file should be composed of ';
- echo 'letters, figures, "-", "_" or "." ONLY';
- echo "\n";
- }
- }
+ $g_message = '0';
+ }
+ else
+ {
+ $g_message = '1';
}
}
- return $pictures;
+ else
+ {
+ $g_message = '1';
+ }
+ $_SESSION['scan_step'] = 'exit';
+
+ //~ pwg_log('<<<<< pwg_test_start() <<<<<'."\n");
}
-/**
- * returns an array with all thumbnails according to $conf['picture_ext']
- * and $conf['prefix_thumbnail']
- *
- * @param string $dir
- * @return array
- */
-function get_thumb_files($dir)
+function pwg_test_exit()
{
- global $conf;
+ //~ pwg_log('>>>>> pwg_test_exit() >>>>>'."\n");
- $prefix_length = strlen($conf['prefix_thumbnail']);
-
- $thumbnails = array();
- if (is_dir($dir.'/thumbnail'))
+ global $g_header, $g_message, $g_footer, $conf, $pwg_conf;
+
+ if (pwg_referer_is_me())
{
- if ($opendir = opendir($dir.'/thumbnail'))
+ $g_header = ' : Test'."\n";
+ $g_message = ' This script is tagged : '.$conf['version'].''."\n";
+ $g_footer = '
'."\n";
+ }
+ else
+ {
+ // compare version in GET parameter with $conf['version']
+ if ($g_message == '1')
{
- while ($file = readdir($opendir))
- {
- if (in_array(get_extension($file), $conf['picture_ext'])
- and substr($file,0,$prefix_length) == $conf['prefix_thumbnail'])
- {
- array_push($thumbnails, $file);
- }
- }
+ exit('PWG-INFO-2: test successful
');
+ }
+ else
+ {
+ exit('PWG-ERROR-4: PhpWebGallery versions differs
');
}
}
- return $thumbnails;
+
+ //~ pwg_log('<<<<< pwg_test_exit() <<<<<'."\n");
}
-/**
- * returns an array with representative picture files of a directory
- * according to $conf['picture_ext']
- *
- * @param string $dir
- * @return array
- */
-function get_representative_files($dir)
+function pwg_clean_start()
{
- global $conf;
-
- $pictures = array();
- if (is_dir($dir.'/pwg_representative'))
+ //~ pwg_log('>>>>> pwg_clean_start() >>>>>'."\n");
+
+ global $g_message;
+
+ if(@unlink('./listing.xml'))
{
- if ($opendir = opendir($dir.'/pwg_representative'))
+ $g_message = '1';
+ }
+ else
+ {
+ $g_message = '0';
+ }
+
+ $_SESSION['scan_step'] = 'exit';
+
+ //~ pwg_log('<<<<< pwg_clean_start() <<<<<'."\n");
+}
+
+function pwg_clean_exit()
+{
+ //~ pwg_log('>>>>> pwg_clean_exit() >>>>>'."\n");
+
+ global $g_header, $g_message, $g_footer, $conf, $pwg_conf;
+
+ if(pwg_referer_is_me())
+ {
+ $g_header = ' : Clean';
+ if ($g_message == '1')
{
- while ($file = readdir($opendir))
- {
- if (in_array(get_extension($file), $conf['picture_ext']))
- {
- array_push($pictures, $file);
- }
- }
+ $g_message = ' Success - listing.xml file deleted'."\n";
+ }
+ else
+ {
+ $g_message = ' Failure - listing.xml does not exist or is read only'."\n";
+ }
+ $g_footer = '
';
+ }
+ else
+ {
+ if ($g_message == '1')
+ {
+ exit('PWG-INFO-3 : listing.xml file deleted
');
+ }
+ else
+ {
+ exit('PWG-ERROR-3 : listing.xml does not exist
');
}
}
- return $pictures;
+
+ //~ pwg_log('<<<<< pwg_clean_exit() <<<<<'."\n");
}
-/**
- * returns an array with high quality/resolution picture files of a directory
- * according to $conf['picture_ext']
- *
- * @param string $dir
- * @return array
- */
-function get_high_files($dir)
+function pwg_protect_start()
{
- global $conf;
-
- $pictures = array();
- if (is_dir($dir.'/pwg_high'))
+ //~ 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)
{
- if ($opendir = opendir($dir.'/pwg_high'))
+ $_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 = ' : Protect';
+ $g_message = ' '."\n".$_SESSION['scan_logs'].'
'."\n";
+ $g_message .= ' '.$_SESSION['scan_cnt_fold'].' directories protected
'."\n";
+ $g_message .= ' Gallery protected in : '.$time_elapsed.' s
';
+ $g_footer = '
';
+
+ // 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");
+ //~ pwg_log("GENARATE start >>>\n".var_export($_SESSION['scan_list_fold'], true)."\n".var_export($_SESSION['scan_list_file'], true)."\nGENERATE start >>>\n");
+
+ global $g_listing, $conf;
+
+ // Flush line
+ $xml_header_url = 'http://'.dirname($_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']).'/';
+ $xml_header_date = date('Y-m-d');
+ $xml_header_version = htmlentities($conf['version']);
+
+ $attrs = array();
+ if ($conf['use_iptc'])
+ {
+ $attrs = array_merge($attrs, array_keys($conf['use_iptc_mapping']) );
+ }
+ if ($conf['use_exif'])
+ {
+ $attrs = array_merge($attrs, array_keys($conf['use_exif_mapping']) );
+ }
+ $xml_header_metadata = implode(',',array_unique($attrs));
+
+ $xml_header = ' 0)
+ {
+ $_SESSION['scan_step'] = 'list';
+ }
+ else
+ {
+ $_SESSION['scan_step'] = 'stop';
+ }
+
+ //~ pwg_log("GENARATE start <<<\n".var_export($_SESSION['scan_list_fold'], true)."\n".var_export($_SESSION['scan_list_file'], true)."\nGENERATE start <<<\n");
+ //~ pwg_log('<<<<< pwg_generate_start() <<<<<'."\n");
+}
+
+function pwg_generate_list()
+{
+ //~ pwg_log('>>>>> pwg_generate_list() >>>>>'."\n");
+ //~ pwg_log("GENARATE list >>>\n".var_export($_SESSION['scan_list_fold'], true)."\n".var_export($_SESSION['scan_list_file'], true)."\nGENERATE list >>>\n");
+
+ global $g_listing;
+
+ // Flush line in xml file
+ $dirname = basename($_SESSION['scan_list_fold'][0]);
+ $line = pwg_get_indent('dir').''."\n";
+ fwrite($g_listing, $line);
+
+ // Get list of files and directories
+ $_SESSION['scan_logs'] .= pwg_get_file_list($_SESSION['scan_list_fold'][0]);
+ sort($_SESSION['scan_list_fold']); // Mandatory to keep the tree order
+ sort($_SESSION['scan_list_file']); // Easier to read when sorted
+
+ // Flush line
+ $line = pwg_get_indent('root').''."\n";
+ fwrite($g_listing, $line);
+
+ // What are we doing at next step
+ $_SESSION['scan_step'] = 'scan';
+
+ //~ pwg_log("GENARATE list <<<\n".var_export($_SESSION['scan_list_fold'], true)."\n".var_export($_SESSION['scan_list_file'], true)."\nGENERATE list <<<\n");
+ //~ pwg_log('<<<<< pwg_generate_list() <<<<<'."\n");
+}
+
+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;
+
+ 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)
{
- while ($file = readdir($opendir))
+ fwrite($g_listing, $line);
+ }
+ //~ pwg_log('---<< Pull of $_SESSION[scan_list_file] value "'.$_SESSION['scan_list_file'][0].'"'."\n");
+ array_shift($_SESSION['scan_list_file']);
+ $_SESSION['scan_cnt_file']++;
+ }
+
+ if (count($_SESSION['scan_list_file']) <= 0)
+ {
+ // Flush line
+ $line = pwg_get_indent('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))
{
- if (in_array(get_extension($file), $conf['picture_ext']))
- {
- array_push($pictures, $file);
- }
- }
+ fwrite($g_listing, pwg_close_level($current_level, $current_level-$next_level+1));
+ } // Nothing to do if current_level < next_level
}
}
- return $pictures;
+
+ //~ 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_stop()
+{
+ //~ pwg_log('>>>>> pwg_generate_stop() >>>>>'."\n");
+ //~ pwg_log("GENARATE stop >>>\n".var_export($_SESSION['scan_list_fold'], true)."\n".var_export($_SESSION['scan_list_file'], true)."\nGENERATE stop >>>\n");
+
+ global $pwg_conf, $g_listing, $g_header, $g_message, $g_footer;
+
+ // Flush line
+ fwrite($g_listing, ''."\n");
+
+ // backup error log before cleaning session
+ $time_elapsed = number_format(pwg_get_moment() - $_SESSION['scan_time'], 3, '.', ' ');
+
+ $g_header = ' : Generate';
+ $g_message = ' '."\n".$_SESSION['scan_logs'].'
'."\n";
+ $g_message .= ' '.$_SESSION['scan_cnt_fold'].' directories parsed
'."\n";
+ $g_message .= ' '.$_SESSION['scan_cnt_file'].' files scanned
'."\n";
+ $g_message .= ' '."\n";
+ $g_message .= ' Listing generated in : '.$time_elapsed.' s
';
+ $g_footer = '
';
+
+ // What are we doing at next step
+ $_SESSION['scan_step'] = 'exit';
+
+ //~ pwg_log("GENARATE stop <<<\n".var_export($_SESSION['scan_list_fold'], true)."\n".var_export($_SESSION['scan_list_file'], true)."\nGENERATE stop <<<\n");
+ //~ pwg_log('<<<<< pwg_generate_stop() <<<<<'."\n");
+}
+
+// +-----------------------------------------------------------------------+
+// | ALWAYS CALLED FUNCTIONS |
+// +-----------------------------------------------------------------------+
+
/**
- * search in $basedir the sub-directories and calls get_pictures
+ * This function check step and time ellapsed to determine end of loop
*
- * @return void
+ * @return bool
*/
-function get_dirs($basedir, $indent, $level)
+function pwg_continue()
{
- $fs_dirs = array();
- $dirs = "";
- global $conf_safe_mode;
-
- // Refresh the max_execution_time to avoid timout error
- // By default time to scan a directory (without subdirs) is fixed to 30 seconds
- if (!$conf_safe_mode)
+ //~ pwg_log('>>>>> pwg_continue() >>>>>'."\n");
+
+ global $conf, $pwg_conf, $g_refresh, $g_header, $g_message, $g_footer, $start_time;
+
+ if (!isset($_SESSION['scan_step']) or $_SESSION['scan_step'] == 'exit')
{
- set_time_limit(30);
+ // evident end of process
+ $return = false;
}
-
- if ($opendir = opendir($basedir))
+ else
{
- while ($file = readdir($opendir))
+ if ($pwg_conf['safe_mode'])
{
- if ($file != '.'
- and $file != '..'
- and $file != '.svn'
- and $file != 'thumbnail'
- and $file != 'pwg_high'
- and $file != 'pwg_representative'
- and is_dir ($basedir.'/'.$file))
+ // can not reset the time
+ $time_elapsed = pwg_get_moment() - $start_time;
+ if ($time_elapsed < $conf['max_execution_time'])
{
- array_push($fs_dirs, $file);
- if (!preg_match('/^[a-zA-Z0-9-_.]+$/', $file))
- {
- echo 'PWG-WARNING-1: "'.$file.'" : ';
- echo 'The name of the directory should be composed of ';
- echo 'letters, figures, "-", "_" or "." ONLY';
- echo "\n";
- }
- }
- }
- }
- // write of the dirs
- foreach ($fs_dirs as $fs_dir)
- {
- $dirs.= "\n".$indent.'';
- $dirs.= get_pictures($basedir.'/'.$fs_dir, $indent.' ');
- $dirs.= get_dirs($basedir.'/'.$fs_dir, $indent.' ', $level + 1);
- $dirs.= "\n".$indent.'';
- }
- return $dirs;
-}
-
-// get_extension returns the part of the string after the last "."
-function get_extension($filename)
-{
- return substr(strrchr($filename, '.'), 1, strlen ($filename));
-}
-
-// get_filename_wo_extension returns the part of the string before the last
-// ".".
-// get_filename_wo_extension('test.tar.gz') -> 'test.tar'
-function get_filename_wo_extension($filename)
-{
- return substr($filename, 0, strrpos($filename, '.'));
-}
-
-function get_pictures($dir, $indent)
-{
- global $conf, $page;
-
- // fs means FileSystem : $fs_files contains files in the filesystem found
- // in $dir that can be managed by PhpWebGallery (see get_pwg_files
- // function), $fs_thumbnails contains thumbnails, $fs_representatives
- // contains potentially representative pictures for non picture files
- $fs_files = get_pwg_files($dir);
- $fs_thumbnails = get_thumb_files($dir);
- $fs_representatives = get_representative_files($dir);
- $fs_highs = get_high_files($dir);
-
- $elements = array();
-
- $print_dir = preg_replace('/^\.\//', '', $dir);
- $print_dir = preg_replace('/\/*$/', '/', $print_dir);
-
- foreach ($fs_files as $fs_file)
- {
- $element = array();
- $element['file'] = $fs_file;
- $element['path'] = $page['url'].$print_dir.$fs_file;
- $element['filesize'] = floor(filesize($dir.'/'.$fs_file) / 1024);
-
- $file_wo_ext = get_filename_wo_extension($fs_file);
-
- foreach ($conf['picture_ext'] as $ext)
- {
- $test = $conf['prefix_thumbnail'].$file_wo_ext.'.'.$ext;
- if (!in_array($test, $fs_thumbnails))
- {
- continue;
+ $return = true;
}
else
{
- $element['tn_ext'] = $ext;
- break;
- }
- }
+ $start_time = $_SESSION['scan_time'];
+ $formated_time = number_format(pwg_get_moment() - $start_time, 3, '.', ' ');
- // 2 cases : the element is a picture or not. Indeed, for a picture
- // thumbnail is mandatory, high is optional and for non picture element,
- // thumbnail and representative is optionnal
- if (in_array(get_extension($fs_file), $conf['picture_ext']))
- {
- // if we found a thumnbnail corresponding to our picture...
- if (isset($element['tn_ext']))
- {
- if ($image_size = @getimagesize($dir.'/'.$fs_file))
+ $g_refresh = ''."\n";
+ $g_header = ' : '.ucfirst($_SESSION['scan_action']).'';
+ $g_message = '';
+ if ($_SESSION['scan_cnt_fold'] != 0)
{
- $element['width'] = $image_size[0];
- $element['height'] = $image_size[1];
+ $g_message .= ''.$_SESSION['scan_cnt_fold'].' directories scanned
'."\n";
}
-
- if ( in_array($fs_file, $fs_highs) )
+ if ($_SESSION['scan_cnt_file'] != 0)
{
- $element['has_high'] = 'true';
+ $g_message .= ''.$_SESSION['scan_cnt_file'].' files scanned
'."\n";
}
-
- if ($conf['use_exif'])
+ $nb = count($_SESSION['scan_list_fold']);
+ if ($nb > 0)
{
- // Verify activation of exif module
- if (extension_loaded('exif'))
- {
- if ($exif = read_exif_data($dir.'/'.$fs_file))
- {
- foreach ($conf['use_exif_mapping'] as $pwg_key => $exif_key )
- {
- if (isset($exif[$exif_key]))
- {
- if ( in_array($pwg_key, array('date_creation','date_available') ) )
- {
- if (preg_match('/^(\d{4}):(\d{2}):(\d{2})/'
- ,$exif[$exif_key]
- ,$matches))
- {
- $element[$pwg_key] =
- $matches[1].'-'.$matches[2].'-'.$matches[3];
- }
- }
- else
- {
- $element[$pwg_key] = $exif[$exif_key];
- }
- }
- }
- }
- }
+ $g_message .= ''.$nb.' directories to scan
'."\n";
}
-
- if ($conf['use_iptc'])
+ $nb = count($_SESSION['scan_list_file']);
+ if ($nb > 0)
{
- $iptc = get_sync_iptc_data($dir.'/'.$fs_file);
- if (count($iptc) > 0)
- {
- foreach (array_keys($iptc) as $key)
- {
- $element[$key] = $iptc[$key];
- }
- }
+ $g_message .= ''.$nb.' files to scan
'."\n";
}
-
- array_push($elements, $element);
- }
- else
- {
- echo 'PWG-ERROR-1: The thumbnail is missing for '.$dir.'/'.$fs_file;
- echo '-> '.$dir.'/thumbnail/';
- echo $conf['prefix_thumbnail'].$file_wo_ext.'.xxx';
- echo ' ("xxx" can be : ';
- echo implode(', ', $conf['picture_ext']);
- echo ')'."\n";
+ $g_message .= ' Time elapsed : '.$formated_time.' s
';
+ $g_footer = '
'."\n";
+
+ $return = false;
}
}
else
{
- foreach ($conf['picture_ext'] as $ext)
- {
- $candidate = $file_wo_ext.'.'.$ext;
- if (!in_array($candidate, $fs_representatives))
- {
- continue;
- }
- else
- {
- $element['representative_ext'] = $ext;
- break;
- }
- }
-
- array_push($elements, $element);
+ // reset the time
+ set_time_limit(intval(ini_get('max_execution_time')));
+ $return = true;
}
}
+ //~ pwg_log('<<<<< pwg_continue() returns '.var_export($return, true).' <<<<<'."\n");
+
+ return $return;
+}
- $xml = "\n".$indent.'';
- $attributes = array('file','tn_ext','representative_ext','filesize',
- 'width','height','date_creation','author','keywords',
- 'name','comment','has_high', 'path');
- foreach ($elements as $element)
+/**
+ * This function :
+ * -> Verify the script call
+ * -> Lock the script
+ * -> Open listing.xml if action is 'generate'
+ * -> Initialize output and session variables
+ *
+ * @return nothing
+ */
+function pwg_init()
+{
+ //~ pwg_log('>>>>> pwg_init() >>>>>'."\n");
+
+ global $g_message, $g_listing, $g_footer, $conf, $pwg_conf, $start_time;
+
+ // Lock other script sessions, this lock will be remove during 'exit' step
+ if (!isset($_SESSION['scan_step']))
{
- $xml.= "\n".$indent.' ';
- $xml.= 'Failure - Another script is running';
+ $g_message .= '
';
+ $g_message .= "\n";
+ $g_footer = '
'."\n";
+ $_SESSION['scan_step'] = 'exit';
+ //~ pwg_log('<<<<< pwg_init() failure <<<<<'."\n");
+ return;
+ }
+ else
+ {
+ fwrite($fp, session_id()); // Writing session_id to trace lock
+ fclose($fp);
+ $_SESSION['scan_step'] = 'init';
+ }
+ }
+
+ // Verify and backup parameter action. This backup will be removed during step 'exit'
+ if (isset($_REQUEST['action']))
+ {
+ if (in_array($_REQUEST['action'], $pwg_conf['scan_action']))
+ {
+ if (isset($_SESSION['scan_action']))
{
- $xml.= ' '.$attribute.'="'.$element{$attribute}.'"';
+ if ($_SESSION['scan_action'] != $_REQUEST['action'])
+ {
+ // Fatal error
+ $g_message = ' Failure - Parameter action differs between url and session';
+ $g_message .= "\n";
+ $g_footer = '
'."\n";
+ $_SESSION['scan_step'] = 'exit';
+ //~ pwg_log('<<<<< pwg_init() failure <<<<<'."\n");
+ return;
+ }
+ }
+ else
+ {
+ $_SESSION['scan_action'] = $_REQUEST['action'];
}
}
- $xml.= ' />';
+ else
+ {
+ // Fatal error
+ $g_message = ' Failure - Problem with action parameter';
+ $g_message .= '
';
+ $g_message .= "\n";
+ $g_footer = '
'."\n";
+ $_SESSION['scan_step'] = 'exit';
+ //~ pwg_log('<<<<< pwg_init() failure <<<<<'."\n");
+ return;
+ }
}
- $xml.= "\n".$indent.'';
+ else
+ {
+ // Here we are on welcome page
+ $g_message = ' '."\n";
+ $g_message .= ' - Test
'."\n";
+ $g_message .= ' - Clean
'."\n";
+ $g_message .= ' - Listing
'."\n";
+ $g_message .= ' - Protect
'."\n";
+ $g_message .= '
'."\n";
+ $g_footer = '';
+ $g_footer .= '
'."\n";
+ $_SESSION['scan_step'] = 'exit';
+ }
+
+ // Open listing.xml
+ if ($_SESSION['scan_action'] == 'generate')
+ {
+ $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)
+ {
+ $g_header = $_SESSION['scan_action'];
+ $g_message = ' Failure - Can not write file listing.xml';
+ $g_message .= "\n";
+ $g_footer = '
'."\n";
+ $_SESSION['scan_step'] = 'exit';
+ //~ pwg_log('<<<<< pwg_init() failure <<<<<'."\n");
+ return;
+ }
+ }
+
+ // Initializing session counters. This counters will be completely unset during step 'exit'
+ if ($_SESSION['scan_step'] == 'init')
+ {
+ $_SESSION['scan_list_file'] = array();
+ $_SESSION['scan_list_fold'] = array();
+ $_SESSION['scan_cnt_file'] = 0;
+ $_SESSION['scan_cnt_fold'] = 0;
+ $_SESSION['scan_time'] = $start_time;
+ $_SESSION['scan_step'] = 'start';
+ $_SESSION['scan_logs'] = '';
+ }
+
+ //~ pwg_log('<<<<< pwg_init() success <<<<<'."\n");
+}
- return $xml;
+/**
+ * This function :
+ * -> Close listing.xml if action is 'generate'
+ * -> Unlock the script
+ * -> Erase session variables
+ *
+ * @return nothing
+ */
+function pwg_exit()
+{
+ //~ pwg_log('>>>>> pwg_exit() >>>>>'."\n");
+
+ global $g_listing;
+
+ // Close XML file
+ if ($_SESSION['scan_action'] == 'generate' and $g_listing != false)
+ {
+ fclose($g_listing);
+ }
+
+ // Unlock script
+ unlink(__FILE__.'.lock');
+
+ // Erase session counters
+ unset($_SESSION['scan_list_file']);
+ unset($_SESSION['scan_list_fold']);
+ unset($_SESSION['scan_cnt_file']);
+ unset($_SESSION['scan_cnt_fold']);
+ unset($_SESSION['scan_time']);
+ unset($_SESSION['scan_step']);
+ $local_action = $_SESSION['scan_action'];
+ unset($_SESSION['scan_action']);
+ unset($_SESSION['scan_logs']);
+
+
+ // Call specific action post process
+ if (is_callable('pwg_'.$local_action.'_exit'))
+ {
+ call_user_func('pwg_'.$local_action.'_exit');
+ }
+
+ //~ pwg_log('<<<<< pwg_exit() <<<<<'."\n");
}
// +-----------------------------------------------------------------------+
// | script |
// +-----------------------------------------------------------------------+
-if (isset($_GET['action']))
-{
- $page['action'] = $_GET['action'];
-}
-else
-{
- $page['action'] = '';
-}
+session_start();
-// Looking at the safe_mode configuration for execution time
-$conf_safe_mode = TRUE;
-if (ini_get('safe_mode') == 0)
-{
- $conf_safe_mode = FALSE;
-}
+$start_time = pwg_get_moment();
-echo '';
-switch ($page['action'])
+// Initializing message for web page
+$g_refresh = '';
+$g_header = '';
+$g_message = '';
+$g_footer = '';
+$g_listing = '';
+
+pwg_init();
+
+while(pwg_continue())
{
- case 'generate' :
+ if (is_callable('pwg_'.$_SESSION['scan_action'].'_'.$_SESSION['scan_step']))
{
- $start = get_moment();
-
- $listing = ''."\n";
-
- $listing.= get_dirs('.', '', 0);
-
- if ($fp = @fopen("./listing.xml","w"))
- {
- fwrite($fp, $listing);
- fclose($fp);
- echo 'PWG-INFO-1: listing.xml created in ';
- echo get_elapsed_time($start, get_moment());
- echo "\n";
- }
- else
- {
- echo "PWG-ERROR-2: I can't write the file listing.xml"."\n";
- }
- break;
+ call_user_func('pwg_'.$_SESSION['scan_action'].'_'.$_SESSION['scan_step']); // Run the step : start, list, scan, stop are available
}
- case 'test' :
+ else
{
- if (isset($_GET['version']))
- {
- if ($_GET['version'] != $conf['version'])
- {
- echo 'PWG-ERROR-4: PhpWebGallery versions differs'."\n";
- }
- else
- {
- echo 'PWG-INFO-2: test successful'."\n";
- }
- }
- else
- {
- echo 'PWG-INFO-2: test successful'."\n";
- }
- break;
- }
- case 'clean' :
- {
- if( @unlink('./listing.xml'))
- {
- echo 'PWG-INFO-3 : listing.xml file deleted'."\n";
- }
- else
- {
- echo 'PWG-ERROR-3 : listing.xml does not exist'."\n";
- }
- break;
- }
- default :
- {
- // Menu de lancement pour la mise à jour manuel des sites distant
- echo '
-
-';
+ $g_header = $_SESSION['scan_action'];
+ $g_message = ' Failure - INTERNAL STEP ERROR : pwg_'.$_SESSION['scan_action'].'_'.$_SESSION['scan_step'].'() undefined';
+ $g_message .= "\n";
+ $g_footer = '
'."\n";
+ $_SESSION['scan_step'] = 'exit';
}
}
-echo '
';
+
+if ($_SESSION['scan_step'] == 'exit')
+{
+ pwg_exit();
+}
+
?>
+
+
+
+ Manage distant gallery
+
+
+
+
+
+
+
+
+
+