$extLength) && (strtolower(substr($file, -($extLength))) === ($ftype))) {
$file = str_replace($cfg["docroot"], '', $fullpath);
$fileList['files'][$file] = md5_file($fullpath);
if ($talk)
sendLine('.');
}
}
}
}
closedir($dirHandle);
}
/**
* print file-list
*
* @param $basedir
* @param $type 1 = list, 2 = checksums
* @param $mode 1 = text, 2 = html
*/
function printFileList($basedir, $type = 1, $mode = 2) {
global $fileList;
if (((strlen($basedir) > 0)) && (substr($basedir, -1 ) != "/"))
$basedir .= "/";
$dir = substr($basedir, 0 , -1);
if (!is_dir($dir))
return false;
define('_URL_SVNLOG','http://svn.berlios.de/wsvn/tf-b4rt/trunk/?rev=');
define('_URL_SVNLOG_SUFFIX','&sc=1');
define('_URL_SVNFILE','http://svn.berlios.de/wsvn/tf-b4rt/trunk/html/');
define('_URL_SVNFILE_SUFFIX','?op=log&rev=0&sc=0&isdir=0');
$fileList = array();
$fileList['files'] = array();
$fileList['types'] = array(".php", ".dist", ".pl", ".pm", ".tmpl", ".html", ".js", ".css", ".xml", ".xsd", ".py");
$fileList['count'] = 0;
$fileList['size'] = 0;
$fileList['revision'] = 1;
_printFileList($basedir, $dir, $type, $mode);
// footer in html
if (($type == 1) && ($mode == 2)) {
sendLine('
Processed '.$fileList['count'].' files. ('.formatHumanSize($fileList['size']).')');
sendLine('
Highest Revision-Number : ');
sendLine(''.$fileList['revision'].'');
sendLine('');
}
}
/**
* print file list worker
*
* @param $basedir
* @param $dir
* @param $type 1 = list, 2 = checksums
* @param $mode 1 = text, 2 = html
* @return revision-list as html-snip
*/
function _printFileList($basedir, $dir, $type = 1, $mode = 2) {
global $fileList;
if (!is_dir($dir))
return false;
$dirHandle = opendir($dir);
while ($file = readdir($dirHandle)) {
$fullpath = $dir.'/'.$file;
if (is_dir($fullpath)) {
if ($file{0} != '.')
_printFileList($basedir, $fullpath, $type, $mode);
} else {
$stringLength = strlen($file);
foreach ($fileList['types'] as $ftype) {
$extLength = strlen($ftype);
if (($stringLength > $extLength) && (strtolower(substr($file, -($extLength))) === ($ftype))) {
// count
$fileList['count'] += 1;
// file
$_file = str_replace($basedir, '', $fullpath);
switch ($type) {
default:
case 1:
// vars
$_size = filesize($fullpath);
$_rev = getSVNRevisionFromId($fullpath);
// size
$fileList['size'] += $_size;
// rev
if ($_rev != 'NoID') {
$intrev = intval($_rev);
if ($intrev > $fileList['revision'])
$fileList['revision'] = $intrev;
}
// print
switch ($mode) {
default:
case 1:
echo $_file.';'.$_size.';'.$_rev."\n";
break;
case 2:
$line = ''.$_file.' | ';
$line .= formatHumanSize($_size).' | ';
$line .= ($_rev != 'NoID')
? ''.$_rev.''
: 'NoID';
$line .= '
';
sendLine($line);
break;
}
break;
case 2:
// vars
$_md5 = md5_file($fullpath);
// print
switch ($mode) {
default:
case 1:
echo $_file.';'.$_md5."\n";
break;
case 2:
sendLine($_file." ".$_md5."
");
break;
}
break;
}
}
}
}
}
closedir($dirHandle);
}
/**
* get svn-revision from id-tag of a file
*
* @param $filename
* @return string
*/
function getSVNRevisionFromId($filename) {
$data = file_get_contents($filename);
$len = strlen($data);
for ($i = 0; $i < $len; $i++) {
if ($data{$i} == '$') {
if (($data{$i+1} == 'I') && ($data{$i+2} == 'd')) {
$revision = "";
$j = $i + 3;
while ($j < $len) {
if ($data{$j} == '$') {
$rev = explode(" ", $revision);
return trim($rev[2]);
} else {
$revision .= $data{$j};
}
$j++;
}
}
}
}
return 'NoID';
}
/**
* get data of a url
*
* @param $url the url
* @return data
*/
function getDataFromUrl($url) {
ini_set("allow_url_fopen", "1");
ini_set("user_agent", "torrentflux-b4rt/". _VERSION);
if ($urlHandle = @fopen($url, 'r')) {
stream_set_timeout($urlHandle, 15);
$info = stream_get_meta_data($urlHandle);
$data = null;
while ((!feof($urlHandle)) && (!$info['timed_out'])) {
$data .= @fgets($urlHandle, 4096);
$info = stream_get_meta_data($urlHandle);
}
@fclose ($urlHandle);
return $data;
}
}
?>