External
|
|
|
|
<? //////////////////////////////////////////////////////////////////////////////////////////
//
// Name: Encode a full Web Site/Project using Zend Encoder
// Last Edited: Date: 16 November 2001 15:23:22 GMT
// Description:
// This small script was written to solve a problem i had when encoding a large amount of
// files using the zend encoder on windows (*nix has a .sh file to do this i believe).
// It mirrors a copy of your site/project keeping the directory structure whilst encoding
// any php files with the encoder.
// It filters out the filetypes in the $extensions variable.
// So include any file extensions you want to be encoded in there...
//
// Tested on Win2k/Apache/PHP v1.1 RC1
// (PHP 1.0.* seems to have loads of problems with opening external programs on win32)
// I cant test on any other platform as the zend license is bound to that machine :/
//
// Authors: David Arthur
// E-mail: davidATno#spam#indigomultimedia.com
//
//////////////////////////////////////////////////////////////////////////////////////////
function encodeArray($root){
global $nonencodeArray,$encodeArray,$dirArray;
$extensions = array('php','php3','php4','phtml');
$handle=opendir($root);
while ($file = readdir($handle)){
$fileArray[count($fileArray)] = $file;
}
closedir($handle);
for ($i=0;$i<count($fileArray);$i++){
if ($fileArray[$i] != "." && $fileArray[$i] != ".."){
$path = str_replace("//","/",$root.$fileArray[$i]);
if (is_dir($root.$fileArray[$i])){
encodeArray($root.$fileArray[$i]."/");
$dirArray[] = $root.$fileArray[$i]."/";
} else {
$namearray = explode(".",strtolower($fileArray[$i]));
$extension = $namearray[count($namearray)-1];
for ($m = 0; $m < count($extensions); $m++){
if ($extensions[$m] == $extension){
$allowed = 1;
}
}
if ($allowed == 1){
$encodeArray[] = $path;
} else {
$nonencodeArray[] = $path;
}
$allowed = 0;
}
}
}
}
function encode($fromdir,$todir,$zendEncoder){
global $nonencodeArray,$encodeArray,$dirArray;
if (!ereg("^.+/$",$fromdir)){
$fromdir .= "/";
}
if (!ereg("^.+/$",$todir)){
$todir .= "/";
}
@mkdir($todir, 0755);
encodeArray($fromdir);
sort($dirArray);
for ($i=0;$i<count($dirArray);$i++){
@mkdir(substr(str_replace($fromdir,$todir,$dirArray[$i]),0,-1), 0755);
}
for ($i=0;$i<count($encodeArray);$i++){
exec("$zendEncoder ".$encodeArray[$i]." ".str_replace($fromdir,$todir,$encodeArray[$i]));
print "Encoded: ".$encodeArray[$i]."<br>to -> ".str_replace($fromdir,$todir,$encodeArray[$i])."<br>n";
}
print "Encoding Finished.<br><br>";
for ($i=0;$i<count($nonencodeArray);$i++){
@copy($nonencodeArray[$i],str_replace($fromdir,$todir,$nonencodeArray[$i]));
print "Copied: ".$nonencodeArray[$i]."<br>to -> ".str_replace($fromdir,$todir,$nonencodeArray[$i])."<br>n";
}
print "Copying Finished.";
}
// The only part that should need changing are below.
?>
|
|
|
Usage Example
|
encode("c:/your/php/project/","c:/the/directory/you/want/it/to/copy/to/","c:/path/to/zend/encoder");
|
|
|
Rate This Script
|
|
|
|