Commit db050e1c authored by sreg's avatar sreg

- Mise en open source (oss)

parents
Pipeline #1392 failed with stages

Too many changes to show.

To preserve performance only 219 of 219+ files are displayed.

<?php
function displayErrors($errors)
{
$cnt=count($errors);
printf("failed - %ld error%s\n",$cnt,$cnt>1?'s':'');
foreach($errors as $error)
echo "$error\n";
}
function checkingName($dir,$authorized,$path='',$mode='EXACT')
{
$errors=array();
if($mode=='EXACT')
foreach($dir as $name=>$value)
if(!in_array($name,$authorized))
$errors[]=sprintf(" WTF: %s%s ???",$path,$name);
if($mode=='EXACT' || $mode=='EXISTS')
foreach($authorized as $k=>$name)
if(!array_key_exists($name,$dir))
$errors[]=sprintf(" Where is: %s%s ???",$path,$name);
return $errors;
}
function checkingPattern(&$array,$pattern,$recurse='')
{
$errors=array();
foreach($array as $name=>$value)
{
$isRep=preg_match('#^.*/$#',$name);
if($recurse!==false && $isRep)
$errors=array_merge($errors,checkingPattern($array[$name],$pattern,"$recurse$name"));
if(!$isRep && !preg_match($pattern,$name))
$errors[]=sprintf(" %s%s ???",$recurse,$name);
}
return $errors;
}
function checkingContent(&$array,$patternFiles,$callback,$recurse='')
{
$errors=array();
foreach($array as $name=>$value)
{
$isRep=preg_match('#^.*/$#',$name);
if($recurse!==false && $isRep)
$errors=array_merge($errors,checkingContent($array[$name],$patternFiles,$callback,"$recurse$name"));
if(!$isRep && preg_match($patternFiles,$name))
if($error=$callback($recurse,$name)) //sprintf(" %s%s ???",$recurse,$name);
$errors[]=$error;
}
return $errors;
}
function recalcIntegrity()
{
$array=array();
showDir('../',true,0,$array);
//print_r($array); die;
checkingContent($array['sys/']['quark/'],'#^.*\.php$#',
function($path,$name)
{
$fileName=__DIR__."/../$path$name";
if($content=file_get_contents($fileName))
if($content=preg_replace('#//Integrity:.*$#mi','//Integrity:',$content))
{
$content=preg_replace('#//Integrity:.*$#mi','//Integrity: '.sha1($content),$content);
file_put_contents($fileName,$content);
}
},'sys/quark/');
}
//print_r(scandir('../../')); die;
function showDir($path,$recurs=false,$level=0,&$array)
{
if($dir=@opendir($path))
{
if(($oldPath=getcwd())!==false)
if(chdir($path))
{
while(($f=@readdir($dir))!==false)
{
if(preg_match('#^\..*$#',$f)) continue;
$p=is_dir("$f")?'/':'';
//echo str_repeat(' ',$level*4)."$f$p\n";
if($p=='/') $array["$f$p"]=array();
else $array[$f]=$f;
if($recurs && $p) showDir($f,$recurs,$level+1,$array["$f$p"]);
}
chdir($oldPath);
}
closedir($dir);
}
}