Location: PHPKode > projects > HAE > hae/admin/checkrecent.php
<?php
/*
	Copyright 2007 Hugo Wood

    This file is part of HAE.

    HAE is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    HAE is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see http://www.gnu.org/licenses/.
*/
?>

<?php
include('../php/vars.php');
$temps_debut = microtime(true); // Timer pour mesurer le temps d'execution
$i = 0;
global $monitoredFolders;
$recent = array();
$files = array();

echo count($monitoredFolders).' folders to check.<br /><br />';

for($index=0; $index < count($monitoredFolders); $index++){
	$folderinfos = $monitoredFolders[$index];
	echo 'Checking '.$folderinfos[0].'<br />';
	$i = 0;
	$recent = array();
	$files = array();
	$rec = "";
	verifymodif('../../'.$folderinfos[0], "", $rec);
	writexml($recent, $files, $folderinfos[2] ,$folderinfos[3] ,$folderinfos[1]);
	echo 'Writing XML to '.$folderinfos[1].'.<br /><br />';
}

echo "<br /><br />Modifications checked!<br /><br /><br />\n";
$temps_fin = microtime(true);
echo 'Generated in: ',round($temps_fin - $temps_debut, 4),'s.';

function verifymodif($dir, $path2, $rec) {
	global $i;
	global $recent;
	global $files;
	global $foldersExeptions;
	global $extensionsExeptions;
	global $filesExeptions;
	global $modifExeptions;
	$path1 = $dir.'/';
	//echo $dir,"<br />\n";
	$dir = opendir($dir);
	while($f = readdir($dir)) {
		if($f==".") {
		}
		elseif($f=="..") {
		}
		elseif(is_dir($path1.$f) && !in_array($f, $foldersExeptions) && !in_array($f, $modifExeptions)) {
			echo "Directory : ",$path1.$f,"/<br />\n";
			verifymodif($path1.$f."/", $path2.$f."/", $rec);
		}
		elseif(is_file($path1.$f) && !in_array(get_ext($f), $extensionsExeptions) && !in_array($f, $filesExeptions) && !in_array(get_ext($f), $modifExeptions) && !in_array($f, $modifExeptions)) {
			echo $i.") ".$path1.$f,"<br />";
			$i++;
			compare(filemtime($rec.$path1.$f), $rec.$path2.$f);
			echo "\n";
		}
	}
	closedir($dir);
}

function compare($filetime, $file){
	global $recent;
	global $files;
	if ($filetime > $recent[count($recent)-1]) {
	$n = 0;
	if (count($recent)==0) {
		$n = -1;
	}
	while ($n <= count($recent)-1) {
		if ($filetime > $recent[$n]) {
			if (count($recent)>99) {
				array_pop($recent);
				array_pop($files);
			}
			$recentTemp = array_splice($recent, $n);
			$filesTemp = array_splice($files, $n);
			$recent[] = $filetime;
			$files[] = $file;
			foreach ($recentTemp as $value) {
				$recent[] = $value;
			}
			foreach ($filesTemp as $value) {
				$files[] = $value;
			}
			break;
		}
		$n+=1;
	}
	}
	elseif (count($recent)<99) {
		$recent[] = $filetime;
		$files[] = $file;
	}
}

function writexml($recent, $files, $title='New files', $desc='Latest modified files', $xmlpath='recent.xml') {
	global $serverAlias;
	global $serverName;
	global $rssfolder;
	// édition du début du fichier XML
	$xml = '<?XML version="1.0"?'.'>
	';
	$xml = '<rss version="2.0">
	';
	$xml .= ' <channel>'; 
	$xml .= '   <title>'.$serverName.' : '.$title.'</title>
	';
	$xml .= '   <link>http://'.$serverAlias.'</link>
	';
	$xml .= '   <description>'.$desc.'</description>
	';
	
	$u=0;
	$count=count($recent);
	while($u<$count){   
		$tmp = explode('/', $files[$u]);
		$xml .= '    <item>
		';
		$xml .= '      <title>'.$tmp[count($tmp)-1].'</title>
		';
		$xml .= '      <link>http://'.$serverAlias.'/'.$files[$u].'</link>
		';
		$xml .= '      <pubDate>'.date('d/m/Y', $recent[$u]).'</pubDate>
		'; 
		$xml .= '      <description>http://'.$serverAlias.'/index.php?dir='.get_parent_dir($files[$u]).'</description>
		';
		$xml .= '    </item>
		';
		$u++;
	}
	
	
	// édition de la fin du fichier XML
	$xml .= ' </channel>
	';
	$xml .= '</rss>';
	
	// écriture dans le fichier
	$fp = fopen('../../'.$rssfolder.'/'.$xmlpath, 'w+');
	fputs($fp, utf8_encode($xml));
	fclose($fp);
}

// On trouve le dossier parent
function get_parent_dir($p) {
	$tmp_hash = explode('/',$p);
	$i=count($tmp_hash)-2;
	if($i>-1) {
		$parent='';
		for ($a=0;$a<=$i;$a++) {
			$parent=$parent.$tmp_hash[$a].'/';
		}
		return $parent;
	}
	else {
		return './';
	}
}

function get_ext($file, $case=false) {
	$tmp_hash=explode(".",$file);
	$ext=$tmp_hash[count($tmp_hash)-1];
	if ($case==false) {$ext = strtolower($ext);}
	return $ext;
}
?>
Return current item: HAE