From ba387e0c47007d6ab7e577ce890b6d7b48b4714f Mon Sep 17 00:00:00 2001 From: Piotr KUCHARSKI Date: Wed, 26 Nov 2014 22:43:51 +0100 Subject: [PATCH] if rss script is in read-only directory, skip file generation and diff calculations. --- rss.php | 96 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 51 insertions(+), 45 deletions(-) diff --git a/rss.php b/rss.php index 2fa71d8..a3083cc 100644 --- a/rss.php +++ b/rss.php @@ -92,61 +92,67 @@ function print_array($array_to_display) /*===================*/ require("config-default.php"); include("config.php"); -#$content = ""; -$old_files_list = "db_old_files"; //list of files in ./photos -$db_feed_source = "db_feed_source"; -$db_rss_timestamp = "db_rss_timestamp"; -$Folder = 'photos'; -$content = ListFiles($gallery_link, $content, $Folder, $SkipExts, $SkipObjects); -$to_store = ""; -// Init files -if (!file_exists($old_files_list)) { - file_put_contents($old_files_list, ""); -} -if (!file_exists($db_feed_source)) { - file_put_contents($db_feed_source, ""); -} -if (!file_exists($db_rss_timestamp)) { - file_put_contents($db_rss_timestamp, ""); -} -/*===================*/ -/* Computing */ -/*===================*/ -#Todo : ajouter une condition : dois-je regénérer le flux ou utiliser les anciens fichiers ? -$temp = file_get_contents($db_feed_source); -$last_rss_gen = file_get_contents($db_rss_timestamp); -$current_time = time(); -// If the RSS generation is already launched, don't do a second generation at the same time -if (($current_time - $last_rss_gen) > $rss_refresh_interval && file_exists("rss.locker") == false) { - file_put_contents("rss.locker", ""); - file_put_contents($db_rss_timestamp, time()); - // Load the list from files. - $old_files_list_content = explode("\n", file_get_contents($old_files_list)); - $new_files_list_content = explode("\n", $content); #debug - // Generate and stock new elements - $differences = diff($old_files_list_content, $new_files_list_content); - for ($i=0; $i < count($differences); $i++) { - if (is_array($differences[$i])) { - for ($j=0; $j < count($differences[$i]["i"]); $j++) { - if (strlen($differences[$i]["i"][$j]) > 2) { - $to_store .= $differences[$i]["i"][$j] . "\n"; +$content = ""; +$folder = "photos"; +$content = listFiles($gallery_link, $content, $folder, $SkipExts, $SkipObjects); + +if (is_writeable(".")) { + $to_store = ""; + $old_files_list = "db_old_files"; //list of files in ./photos + $db_feed_source = "db_feed_source"; + $db_rss_timestamp = "db_rss_timestamp"; + + // Init files + if (!file_exists($old_files_list)) { + file_put_contents($old_files_list, ""); + } + if (!file_exists($db_feed_source)) { + file_put_contents($db_feed_source, ""); + } + if (!file_exists($db_rss_timestamp)) { + file_put_contents($db_rss_timestamp, ""); + } + + /*===================*/ + /* Computing */ + /*===================*/ + #Todo : ajouter une condition : dois-je regénérer le flux ou utiliser les anciens fichiers ? + $temp = file_get_contents($db_feed_source); + $last_rss_gen = file_get_contents($db_rss_timestamp); + $current_time = time(); + // If the RSS generation is already launched, don't do a second generation at the same time + if (($current_time - $last_rss_gen) > $rss_refresh_interval && file_exists("rss.locker") == false) { + file_put_contents("rss.locker", ""); + file_put_contents($db_rss_timestamp, time()); + // Load the list from files. + $old_files_list_content = explode("\n", file_get_contents($old_files_list)); + $new_files_list_content = explode("\n", $content); #debug + // Generate and stock new elements + $differences = diff($old_files_list_content, $new_files_list_content); + for ($i=0; $i < count($differences); $i++) { + if (is_array($differences[$i])) { + for ($j=0; $j < count($differences[$i]["i"]); $j++) { + if (strlen($differences[$i]["i"][$j]) > 2) { + $to_store .= $differences[$i]["i"][$j] . "\n"; + } } } } + // Add new elements at the top of the feed's source + $temp = $to_store . $temp; + file_put_contents($db_feed_source, $temp); + // Store the current file list for the next generation + file_put_contents($old_files_list, $content); + unlink("rss.locker"); } - // Add new elements at the top of the feed's source - $temp = $to_store . $temp; - file_put_contents($db_feed_source, $temp); - // Store the current file list for the next generation - file_put_contents($old_files_list, $content); - unlink("rss.locker"); + $content = $temp; } /*===================*/ /* XML Gen */ /*===================*/ -$temp = explode("\n", $temp); +$temp = explode("\n", $content); echo "\n"; echo "$title"; echo "$gallery_link";