function ScanSourceFiles($path = '') { global $ExVarArray, $FuncArray, $ClassArray, $ConstArray, $VarArray, $LineArray, $FileArray; global $SourceDir, $TargetDir, $FileExtArray, $JSFileExtArray, $JSFuncArray, $ReplaceJS, $ReplaceFunctions, $ReplaceVariables, $ReplaceConstants, $MaxFiles; global $RecursiveScan, $CopyAllFiles; // File system option... global $StdExcJSFuncArray, $UdExcVarArray, $UdExcVarArrayWild, $UdExcFuncArray, $UdExcConstArray, $UdExcFileArrayRegEx, $UdExcDirArrayRegEx; $dir = dir($SourceDir . $path . '/'); while ($FileNaam = $dir->read()) { $fileName = $path . '/' . $FileNaam; $excludeFile = FALSE; $excludeDirectory = FALSE; if (is_file($SourceDir . $fileName)) { // check if file has the proper suffix $extpos = strrpos($FileNaam, "."); if ($extpos > 0) { $Suffix = substr($FileNaam, $extpos + 1); } else { $Suffix = md5(rand()); } // generate some non existing extension if ((in_array($Suffix, $FileExtArray) || $extpos == 0 && in_array(".", $FileExtArray) || in_array($Suffix, $JSFileExtArray) && $ReplaceJS) && sizeof($FileArray) < $MaxFiles) { // check if the file is in UdExcFileArray foreach ($UdExcFileArrayRegEx as $value) { // compare file name with regular expression if (preg_match($value, $FileNaam)) { $excludeFile = TRUE; } } if ($excludeFile == FALSE) { if (in_array($Suffix, $JSFileExtArray)) { // it is JavaScript file echo "<b>+ Scanning JavaScript File: " . substr($fileName, 1) . "</b><br>\n"; array_push($FileArray, substr($fileName, 1)); $LineArray = file($SourceDir . $fileName); flush(); for ($rgl = 0; $rgl < sizeof($LineArray); $rgl++) { $Line = trim(strtolower($LineArray[$rgl])); if ($ReplaceJS && substr($Line, 0, 9) == "function ") { // we have to find out if function is JavaScript Function or PHP function $posEinde = strpos($Line, "("); $FunctieNaam = substr(trim($LineArray[$rgl]), 0, $posEinde); $FunctieNaam = trim(preg_replace("/function /i", "", $FunctieNaam)); $FunctieNaam = trim(preg_replace("/\\&/i", "", $FunctieNaam)); if (empty($JSFuncArray[$FunctieNaam]) and !in_array($FunctieNaam, $StdExcJSFuncArray)) { $JSFuncArray[$FunctieNaam] = "F" . substr(md5($FunctieNaam), 0, 8); } } if ($ReplaceJS) { SearchVars($LineArray[$rgl]); } // *** Search JavaScript Variables } } else { // it should be PHP file echo "<b>+ Scanning File: " . substr($fileName, 1) . "</b><br>\n"; array_push($FileArray, substr($fileName, 1)); $LineArray = file($SourceDir . $fileName); flush(); for ($rgl = 0; $rgl < sizeof($LineArray); $rgl++) { $Line = trim(strtolower($LineArray[$rgl])); if (($ReplaceFunctions || $ReplaceJS) && substr($Line, 0, 9) == "function ") { $posEinde = strpos($Line, "("); $FunctieNaam = substr(trim($LineArray[$rgl]), 0, $posEinde); $FunctieNaam = trim(preg_replace("/function /i", "", $FunctieNaam)); $FunctieNaam = trim(preg_replace("/\\&/i", "", $FunctieNaam)); if ($FunctieNaam == 'doLoad') { $FunctieNaam = 'doLoad'; } // we have to find out if the function is JavaScript Function or PHP function // we do it by checking if function is between '<script' and '</script' tags if (findScriptTagInFile($rgl, $LineArray)) { // it is JS function if (empty($JSFuncArray[$FunctieNaam]) and !in_array($FunctieNaam, $StdExcJSFuncArray)) { $JSFuncArray[$FunctieNaam] = "F" . substr(md5($FunctieNaam), 0, 8); } } else { // it is PHP function if (empty($FuncArray[$FunctieNaam]) and !in_array($FunctieNaam, $UdExcFuncArray)) { $FuncArray[$FunctieNaam] = "F" . substr(md5($FunctieNaam), 0, 8); } } } else { if ($ReplaceFunctions && preg_match("/^[ \t]*class[ \t]+([0-9a-zA-Z_]+)[ \t\n\r\\{]/U", $LineArray[$rgl], $matches)) { // store class name to the functions array - class name has to be same as constructor name $FunctieNaam = $matches[1]; if (empty($FuncArray[$FunctieNaam]) and !in_array($FunctieNaam, $UdExcFuncArray)) { $FuncArray[$FunctieNaam] = "F" . substr(md5($FunctieNaam), 0, 8); } if (!in_array($FunctieNaam, $ClassArray) and !in_array($FunctieNaam, $UdExcFuncArray)) { $ClassArray[] = $FunctieNaam; } } elseif ($ReplaceConstants && preg_match("/define[ \t(]/i", substr($Line, 0, 7))) { $posStart = strpos($Line, "("); $posEnd = strpos($Line, ","); $ConstantName = substr(trim($LineArray[$rgl]), $posStart + 1, $posEnd - $posStart - 1); $ConstantName = preg_replace('/[\\"\']/', "", $ConstantName); $posDollar = strpos($ConstantName, "\$"); // name of constant may not be a variable if ($posDollar === FALSE && $ConstantName != 'SID') { // doesn't convert SID constant (PHP4) if (!$ConstArray[$ConstantName] and !in_array($ConstantName, $UdExcConstArray)) { $ConstArray[$ConstantName] = "C" . substr(md5($ConstantName), 0, 8); } } } } if ($ReplaceVariables || $ReplaceJS) { SearchVars($LineArray[$rgl]); } // *** Search Variables } } } else { // file was excluded, just copy it echo "- <font color=blue>Excluded</font>, just copy Filename: " . substr($fileName, 1) . "<br>\n"; copy($SourceDir . $fileName, $TargetDir . $fileName); } } elseif ($CopyAllFiles) { echo "- Copy Filename: " . substr($fileName, 1) . "<br>\n"; copy($SourceDir . $fileName, $TargetDir . $fileName); } } else { if ($RecursiveScan && is_dir($SourceDir . $fileName) && $FileNaam != "." && $FileNaam != "..") { // check if the directory is in UdExcDirArray foreach ($UdExcDirArrayRegEx as $value) { // compare directory name with regular expression if (preg_match($value, $SourceDir . $fileName)) { $excludeDirectory = TRUE; } } if ($excludeDirectory == TRUE) { echo "<font color=blue>Directory {$SourceDir}.{$fileName} excluded, not copied!</font><br>"; } else { if (!is_dir($TargetDir . $fileName)) { if (@mkdir($TargetDir . $fileName, 0707)) { echo 'Creating Directory : ' . $TargetDir . $fileName . '.<br>'; } else { echo '- Creating Directory : ' . $TargetDir . $fileName . ' <FONT COLOR=orange>Warning: Creation failed.</b></FONT><br>'; } } ScanSourceFiles($fileName); } } } } $dir->close(); }
public function scan_source_files($path = '') { global $ExVarArray, $FuncArray, $ClassArray, $ConstArray, $VarArray, $LineArray, $FileArray; global $SourceDir, $TargetDir, $FileExtArray, $JSFileExtArray, $JSFuncArray, $ReplaceJS, $ReplaceFunctions, $ReplaceVariables, $ReplaceConstants, $MaxFiles; # global $RecursiveScan, $CopyAllFiles; // File system option... global $StdExcJSFuncArray, $UdExcVarArray, $UdExcVarArrayWild, $UdExcFuncArray, $UdExcConstArray; $dir = dir($SourceDir . $path . '/'); while ($FileNaam = $dir->read()) { if ($FileNaam == '.' || $FileNaam == '..') { continue; } $fileName = $path . '/' . $FileNaam; $excludeFile = false; $excludeDirectory = false; if (is_file($SourceDir . $fileName)) { // check if file has the proper suffix $extpos = strrpos($FileNaam, '.'); if ($extpos > 0) { $Suffix = substr($FileNaam, $extpos + 1); } else { $Suffix = md5(rand()); // generate some non existing extension } if ((in_array($Suffix, $FileExtArray) || $extpos == 0 && in_array('.', $FileExtArray) || in_array($Suffix, $JSFileExtArray) && $ReplaceJS) && sizeof($FileArray) < $MaxFiles) { // check if the file is in UdExcFileArray foreach ($this->UdExcFileArrayRegEx as $value) { // compare file name with regular expression if (preg_match($value, $FileNaam)) { $excludeFile = true; } } if (false === $excludeFile) { if (in_array($Suffix, $JSFileExtArray)) { // is JavaScript file echo '<b>+ Scanning JavaScript File: ' . substr($fileName, 1) . '</b><br>' . "\n"; array_push($FileArray, substr($fileName, 1)); $LineArray = file($SourceDir . $fileName); ob_flush(); for ($rgl = 0; $rgl < sizeof($LineArray); $rgl++) { $Line = trim(strtolower($LineArray[$rgl])); if ($ReplaceJS && substr($Line, 0, 9) == 'function ') { // Search for Function declaration // we have to find out if function is JavaScript Function or PHP function $posEinde = strpos($Line, '('); $FunctieNaam = substr(trim($LineArray[$rgl]), 0, $posEinde); $FunctieNaam = trim(preg_replace('/function /i', '', $FunctieNaam)); $FunctieNaam = trim(preg_replace('/\\&/i', '', $FunctieNaam)); if (empty($JSFuncArray[$FunctieNaam]) && !in_array($FunctieNaam, $StdExcJSFuncArray)) { $JSFuncArray[$FunctieNaam] = 'F' . substr(md5($FunctieNaam), 0, 8); } } if ($ReplaceJS) { SearchVars($LineArray[$rgl]); // Search JavaScript Variables } } } else { // it should be PHP file echo '<b>+ Scanning File: ' . substr($fileName, 1) . '</b><br>' . "\n"; array_push($FileArray, substr($fileName, 1)); $LineArray = file($SourceDir . $fileName); ob_flush(); for ($rgl = 0; $rgl < sizeof($LineArray); $rgl++) { $Line = trim(strtolower($LineArray[$rgl])); if (($ReplaceFunctions || $ReplaceJS) && substr($Line, 0, 9) == "function ") { // Search for Function declaration $posEinde = strpos($Line, '('); $FunctieNaam = substr(trim($LineArray[$rgl]), 0, $posEinde); $FunctieNaam = trim(preg_replace("/function /i", "", $FunctieNaam)); $FunctieNaam = trim(preg_replace("/\\&/i", "", $FunctieNaam)); if ($FunctieNaam == 'doLoad') { $FunctieNaam = 'doLoad'; } // we have to find out if the function is JavaScript Function or PHP function // we do it by checking if function is between '<script' and '</script' tags if (findScriptTagInFile($rgl, $LineArray)) { // a JS function if (empty($JSFuncArray[$FunctieNaam]) && !in_array($FunctieNaam, $StdExcJSFuncArray)) { $JSFuncArray[$FunctieNaam] = 'F' . substr(md5($FunctieNaam), 0, 8); } } else { // is a PHP function if (empty($FuncArray[$FunctieNaam]) && !in_array($FunctieNaam, $UdExcFuncArray)) { $FuncArray[$FunctieNaam] = 'F' . substr(md5($FunctieNaam), 0, 8); } } } elseif ($ReplaceFunctions && preg_match("/^[ \t]*class[ \t]+([0-9a-zA-Z_]+)[ \t\n\r\\{]/U", $LineArray[$rgl], $matches)) { // Search for Class declaration // store class name to the functions array - class name has to be same as constructor name $FunctieNaam = $matches[1]; if (empty($FuncArray[$FunctieNaam]) && !in_array($FunctieNaam, $UdExcFuncArray)) { $FuncArray[$FunctieNaam] = 'F' . substr(md5($FunctieNaam), 0, 8); } if (!in_array($FunctieNaam, $ClassArray) && !in_array($FunctieNaam, $UdExcFuncArray)) { $ClassArray[] = $FunctieNaam; } } elseif ($ReplaceConstants && preg_match("/define[ \t(]/i", substr($Line, 0, 7))) { // Search for Constant declaration $posStart = strpos($Line, '('); $posEnd = strpos($Line, ","); $ConstantName = substr(trim($LineArray[$rgl]), $posStart + 1, $posEnd - $posStart - 1); $ConstantName = preg_replace('/[\\"\']/', "", $ConstantName); $posDollar = strpos($ConstantName, "\$"); // name of constant may not be a variable if ($posDollar === FALSE && $ConstantName != 'SID') { // doesn't convert SID constant (PHP4) if (!$ConstArray[$ConstantName] && !in_array($ConstantName, $UdExcConstArray)) { $ConstArray[$ConstantName] = 'C' . substr(md5($ConstantName), 0, 8); } } } if ($ReplaceVariables || $ReplaceJS) { SearchVars($LineArray[$rgl]); } // *** Search Variables } } } else { // file was excluded, just copy it echo '- <font color=blue>Excluded</font>, just copy Filename: ' . substr($fileName, 1) . '<br>' . "\n"; copy($SourceDir . $fileName, $TargetDir . $fileName); } } elseif ($_POST['CopyAllFiles']) { echo '- Copy Filename: ' . substr($fileName, 1) . '<br>' . "\n"; copy($SourceDir . $fileName, $TargetDir . $fileName); } } elseif ($_POST['RecursiveScan'] && is_dir($SourceDir . $fileName)) { // while looping, this file is a dir // check if the directory is in UdExcDirArray foreach ($this->UdExcDirArrayRegEx as $val) { // compare directory name with regular expression if (preg_match($val, $SourceDir . $fileName)) { $excludeDirectory = true; break; } } if (TRUE === $excludeDirectory) { echo '<font color="blue">Directory ' . $SourceDir . $fileName . ' excluded, not copied!</font><br />'; } else { die('fppp'); if (!is_dir($TargetDir . $fileName)) { if (@mkdir($TargetDir . $fileName, 0707)) { echo 'Creating Directory : ' . $TargetDir . $fileName . '.<br />'; } else { echo '- Creating Directory : ' . $TargetDir . $fileName . ' <font color=orange>Warning: Creation failed.</b></font><br />'; } } $this->scan_source_files($fileName); } } } $dir->close(); }