function mmcache_encode_dir($src, $out, $s, $r, $l, $c, $f) { if (!($dir = opendir($src))) { return mmcache_error("Can't open source directory \"{$src}\""); } while (($file = readdir($dir)) !== false) { if ($file == '.' || $file == '..') { continue; } $i = "{$src}/{$file}"; $o = empty($out) ? $out : "{$out}/{$file}"; if (is_link($i)) { if ($c && !empty($o)) { mmcache_copy_link($i, $o, $f); global $web_error; if (!empty($web_error)) { echo "<font color=\"#ff0000\">{$web_error}</font><br />\n"; flush(); $web_error = ''; } continue; } else { if (!$l) { continue; } } } if (is_dir($i)) { if ($r && mmcache_copy_dir($i, $o, $f)) { mmcache_encode_dir($i, $o, $s, $r, $l, $c, $f); } } else { if (is_file($i)) { if (empty($s)) { mmcache_encode_file($i, $o, $f, $c); } else { if (is_string($s)) { if (preg_match('/' . preg_quote(".{$s}") . '$/i', $file)) { mmcache_encode_file($i, $o, $f, $c); } else { if (!empty($o) && $c) { mmcache_copy_file($i, $o, $f); } } } else { if (is_array($s)) { $encoded = false; foreach ($s as $z) { if (preg_match('/' . preg_quote(".{$z}") . '$/i', $file)) { mmcache_encode_file($i, $o, $f, $c); $encoded = true; break; } } if (!$encoded && !empty($o) && $c) { mmcache_copy_file($i, $o, $f); } } } } } } global $web_error; if (!empty($web_error)) { echo "<font color=\"#ff0000\">{$web_error}</font><br />\n"; flush(); $web_error = ''; } } closedir($dir); }
function mmcache_encoder_main() { $argc = $_SERVER['argc']; $argv = $_SERVER['argv']; $src = array(); $out = null; unset($s); $r = false; $l = false; $a = false; $c = false; $f = false; for ($i = 1; $i < $argc; $i++) { $arg = $argv[$i]; if (!empty($arg)) { if ($arg[0] == '-') { if ($arg[1] == "o") { if (!empty($out)) { mmcache_encoder_usage(); } if (strlen($arg) == 2) { if ($argc <= $i || empty($argv[$i + 1]) || $argv[$i + 1][0] == "-") { mmcache_encoder_usage(); } $out = $argv[++$i]; } else { $out = substr($arg, 2); } } else { if ($arg[1] == "s") { if (strlen($arg) == 2) { $s[] = $argv[++$i]; } else { $s[] = substr($arg, 2); } } else { if (strlen($arg) == 2 && $arg[1] == "r") { $r = true; } else { if (strlen($arg) == 2 && $arg[1] == "l") { $l = true; } else { if (strlen($arg) == 2 && $arg[1] == "a") { $a = true; } else { if (strlen($arg) == 2 && $arg[1] == "c") { $c = true; } else { if (strlen($arg) == 2 && $arg[1] == "f") { $f = true; } else { $len = strlen($arg); if ($len > 1) { $n = 1; while ($n < $len) { if ($arg[$n] == "r") { $r = true; } else { if ($arg[$n] == "l") { $l = true; } else { if ($arg[$n] == "a") { $a = true; } else { if ($arg[$n] == "c") { $c = true; } else { if ($arg[$n] == "f") { $f = true; } else { if ($arg[$n] != "o" && $arg[$n] != "s") { echo "MMCache Encoder ERROR: Unknown option \"-" . $arg[$n] . "\"\n\n"; } mmcache_encoder_usage(); } } } } } ++$n; } } else { echo "MMCache Encoder ERROR: Unknown option \"{$arg}\"\n\n"; mmcache_encoder_usage(); } } } } } } } } } else { $src[] = $arg; } } } if (isset($src) && is_array($src) && count($src) > 0) { $cnt = count($src); if ($a) { $s = ""; } else { if (!isset($s)) { $s = "php"; } } if ($cnt > 1) { if (!mmcache_mkdir($out, $f, 0)) { return; } } foreach ($src as $file) { if (!file_exists($file)) { echo "MMCache Encoder ERROR: Source file \"{$file}\" doesn't exist.\n"; } else { if (is_dir($file)) { if ($cnt == 1) { if (mmcache_mkdir($out, $f, 0)) { mmcache_encode_dir($file, $out, $s, $r, $l, $c, $f, 0); } } else { if (mmcache_copy_dir($file, $out . "/" . basename($file), $f, 0)) { mmcache_encode_dir($file, $out . "/" . basename($file), $s, $r, $l, $c, $f, 0); } } } else { if ($cnt == 1) { mmcache_encode_file($file, $out, $f, $c, 0); } else { if (empty($out)) { mmcache_encode_file($file, $out, $f, $c, 0); } else { mmcache_encode_file($file, $out . "/" . basename($file), $f, $c, 0); } } } } } } else { mmcache_encoder_usage(); } }