clean up spacing and braces according to PSR-2 rules

This commit is contained in:
Piotr KUCHARSKI 2014-11-26 19:47:05 +01:00
parent a57b081377
commit 814cc39fbe

65
rss.php
View file

@ -1,7 +1,7 @@
<?php
/*==========================*/
/*============================*/
/* Gallery address definition */
/*==========================*/
/*============================*/
$gallery_protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$gallery_domain = $_SERVER['HTTP_HOST'].'/';
$gallery_path = dirname($_SERVER['REQUEST_URI']);
@ -16,29 +16,28 @@ $gallery_link = $gallery_protocol.$gallery_domain.$gallery_path;
function ListFiles($gallery_link, &$content, $Folder, $SkipFileExts, $SkipObjects)
{
$dir = opendir($Folder);
while (false !== ($Current = readdir($dir))) // Loop on all contained on the folder
{
if ($Current !='.' && $Current != '..' && in_array($Current, $SkipObjects)===false)
{
if(is_dir($Folder.'/'.$Current)) // If the current element is a folder
{
ListFiles($gallery_link, $content, $Folder.'/'.$Current, $SkipFileExts, $SkipObjects); // Recursivity
}
else
{
// 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);
} else {
$FileExt = strtolower(substr(strrchr($Current, '.'), 1));
if (in_array($FileExt, $SkipFileExts)===false) // Should we display this extension ?
// Should we display this extension ?
if (in_array($FileExt, $SkipFileExts) === false) {
$current_adress = $gallery_link . "/" . $Folder.'/'. $Current;
$content .= $current_adress. "\n";
}
}
}
}
closedir($dir);
return $content;
}
# Paul's Simple Diff Algorithm v 0.1 : http://paulbutler.org/archives/a-simple-diff-algorithm-in-php/
function diff($old, $new){
function diff($old, $new)
{
$matrix = array();
$maxlen = 0;
foreach ($old as $oindex => $ovalue) {
@ -53,18 +52,21 @@ $gallery_link = $gallery_protocol.$gallery_domain.$gallery_path;
}
}
}
if($maxlen == 0) return array(array('d'=>$old, 'i'=>$new));
if ($maxlen == 0)
return array(array('d'=>$old, 'i'=>$new));
return array_merge(
diff(array_slice($old, 0, $omax), array_slice($new, 0, $nmax)),
array_slice($new, $nmax, $maxlen),
diff(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen)));
}
function print_array($array_to_display) {
function print_array($array_to_display)
{
echo '<pre>';
print_r($array_to_display);
echo '</pre>';
}
/*===================*/
/* Variables */
/*===================*/
@ -78,16 +80,13 @@ $gallery_link = $gallery_protocol.$gallery_domain.$gallery_path;
$content = ListFiles($gallery_link, $content, $Folder, $SkipExts, $SkipObjects);
$to_store = "";
// Init files
if (!file_exists($old_files_list))
{
if (!file_exists($old_files_list)) {
file_put_contents($old_files_list, "");
}
if (!file_exists($db_feed_source))
{
if (!file_exists($db_feed_source)) {
file_put_contents($db_feed_source, "");
}
if (!file_exists($db_rss_timestamp))
{
if (!file_exists($db_rss_timestamp)) {
file_put_contents($db_rss_timestamp, "");
}
@ -99,8 +98,7 @@ $gallery_link = $gallery_protocol.$gallery_domain.$gallery_path;
$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)
{
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.
@ -108,14 +106,10 @@ $gallery_link = $gallery_protocol.$gallery_domain.$gallery_path;
$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)
{
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";
}
}
@ -144,15 +138,13 @@ $gallery_link = $gallery_protocol.$gallery_domain.$gallery_path;
for ($i=0; $i < $nb_items_rss; $i++) {
$pieceOfTitle = strrchr ($temp[$i] , "/");
$titleLenght = strlen($pieceOfTitle) - strlen(strrchr($pieceOfTitle, "."));
echo
"<item>
echo "<item>
<title>" . substr($pieceOfTitle, 1, $titleLenght-1) . "</title>
<link>". $temp[$i] . "</link>
<description>
<![CDATA[ <img src=\"" . $temp[$i] . "\"> ]]>
</description>
</item>"
;
</item>";
if ($temp[$i+1] == NULL)
break;
}
@ -160,4 +152,3 @@ $gallery_link = $gallery_protocol.$gallery_domain.$gallery_path;
</channel>
</rss>
";
?>