From e76c886ea79401a89a7ef0cf42fb180d855e325a Mon Sep 17 00:00:00 2001 From: Lucas Cimon Date: Sun, 31 May 2015 16:52:46 +0200 Subject: [PATCH] Fixing rss.php --- rss.php | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/rss.php b/rss.php index b9fbe75..20a5f75 100644 --- a/rss.php +++ b/rss.php @@ -33,20 +33,20 @@ $gallery_link = $g_protocol . '://' . $g_host . $g_port . $g_path; /*===================*/ # Hardly inspired from here : codes-sources.commentcamarche.net/source/35937-creation-d-une-arborescenceI # Listing all files of a folder and sub folders. -function ListFiles($gallery_link, &$content, $Folder, $SkipFileExts, $SkipObjects) +function listFiles(&$content, $Folder, $SkipFileExts, $SkipObjects) { $dir = opendir($Folder); // Loop on all contained on the folder while (false !== ($Current = readdir($dir))) { if ($Current !='.' && $Current != '..' && in_array($Current, $SkipObjects) === false) { if (is_dir($Folder.'/'.$Current)) { - ListFiles($gallery_link, $content, $Folder . '/' . $Current, $SkipFileExts, $SkipObjects); + ListFiles($content, $Folder . '/' . $Current, $SkipFileExts, $SkipObjects); } else { $FileExt = strtolower(substr(strrchr($Current, '.'), 1)); // Should we display this extension ? if (in_array($FileExt, $SkipFileExts) === false) { - $current_adress = $gallery_link . "/" . $Folder.'/'. $Current; - $content .= $current_adress. "\n"; + $current_adress = $Folder.'/'. $Current; + array_push($content, $current_adress); } } } @@ -80,22 +80,16 @@ function diff($old, $new) diff(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen))); } -function print_array($array_to_display) -{ - echo '
';
-    print_r($array_to_display);
-    echo '
'; -} - /*===================*/ /* Variables */ /*===================*/ require("config-default.php"); include("config.php"); - -$content = ""; $folder = "photos"; -$content = listFiles($gallery_link, $content, $folder, $SkipExts, $SkipObjects); + +$content = array(); +$content = listFiles($content, $folder, $SkipExts, $SkipObjects); +usort($content, function ($a, $b) { return filemtime($a) < filemtime($b); }); if (is_writeable(".")) { $to_store = ""; @@ -127,7 +121,7 @@ if (is_writeable(".")) { 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 + $new_files_list_content = $content; #debug // Generate and stock new elements $differences = diff($old_files_list_content, $new_files_list_content); for ($i=0; $i < count($differences); $i++) { @@ -143,30 +137,31 @@ if (is_writeable(".")) { $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); + file_put_contents($old_files_list, join("/n", $content)); unlink("rss.locker"); } - $content = $temp; + $content = explode("\n", $temp); } /*===================*/ /* XML Gen */ /*===================*/ header('Content-Type: text/xml'); -$temp = explode("\n", $content); -echo "\n"; +echo "\n"; echo "\n"; echo "$title"; echo "$gallery_link"; echo "$description\n"; -for ($i=0; $i < $nb_items_rss && $i < count($temp); $i++) { - if (empty($temp[$i])) +for ($i=0; $i < $nb_items_rss && $i < count($content); $i++) { + if (empty($content[$i])) continue; + $link = $gallery_link . '/' . $content[$i]; echo "\n"; - echo " " . basename($temp[$i]) . "\n"; - echo " ". $temp[$i] . "\n"; - echo " ". $temp[$i] . "\n"; - echo " ]]>\n"; + echo " " . basename($link) . "\n"; + echo " ". $link . "\n"; + echo " ". $link . "\n"; + echo " ]]>\n"; + echo " " . date ("D, j M Y H:i:s O", filemtime($content[$i])) . ""; echo "\n"; } echo "\n";