Example #1
0
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);
}
Example #2
0
function mmcache_encoder_web()
{
    echo "<html><head><title>Turck MMCache Encoder</title></head>" . "<body><h1 align=\"center\">Turck MMCache Encoder " . MMCACHE_VERSION . "</h1>";
    $error = "";
    $source = "";
    $target = "";
    $s = "php";
    $suffixies = "php";
    if (isset($_POST["submit"])) {
        if (isset($_POST["source"])) {
            $source = $_POST["source"];
        }
        if (isset($_POST["target"])) {
            $target = $_POST["target"];
        }
        if (isset($_POST["suffixies"])) {
            $suffixies = $_POST["suffixies"];
            if (strpos($suffixies, ",") !== false) {
                $s = explode(",", $suffixies);
            } else {
                $s = $suffixies;
            }
        }
        $all = isset($_POST["all"]) ? $_POST["all"] : false;
        $links = isset($_POST["links"]) ? $_POST["links"] : false;
        $recursive = isset($_POST["recursive"]) ? $_POST["recursive"] : false;
        $copy = isset($_POST["copy"]) ? $_POST["copy"] : false;
        $force = isset($_POST["force"]) ? $_POST["force"] : false;
        if (empty($source)) {
            $error = "ERROR: Source is not specified!";
        } else {
            if (!file_exists($source)) {
                $error = "ERROR: Source file \"{$source}\" doesn't exist.\n";
            } else {
                if (is_dir($source)) {
                    if (mmcache_mkdir($target, $force, 1)) {
                        if ($all) {
                            $s = "";
                        }
                        mmcache_encode_dir($source, $target, $s, $recursive, $links, $copy, $force, 1);
                    }
                } else {
                    mmcache_encode_file($source, $target, $force, $copy, 1);
                }
                global $web_error;
                if (empty($web_error)) {
                    echo "<br><b>DONE</b></html>";
                    return;
                } else {
                    $error = $web_error;
                }
            }
        }
    }
    echo "<h3 align=\"center\"><font color=\"#ff0000\">{$error}</font></h3>" . "<form method=\"POST\">" . "<table border=\"0\" cellpadding=\"3\" cellspacing=\"1\" width=\"600\" bgcolor=\"#000000\" align=\"center\">" . "<tr valign=\"baseline\" bgcolor=\"#cccccc\"><td width=\"50%\" bgcolor=\"#ccccff\"><b>Souce file or directory name:</b></td><td width=\"50%\"><input type=\"text\" name=\"source\" size=\"32\" value=\"{$source}\" style=\"width:100%\"></td></tr>" . "<tr valign=\"baseline\" bgcolor=\"#cccccc\"><td width=\"50%\" bgcolor=\"#ccccff\"><b>Target file or directory name:</b></td><td width=\"50%\"><input type=\"text\" name=\"target\" size=\"32\" value=\"{$target}\" style=\"width:100%\"></td></tr>" . "<tr valign=\"baseline\" bgcolor=\"#cccccc\"><td width=\"50%\" bgcolor=\"#ccccff\"><b>PHP suffixies <small>(comma separated list)</small>:</b></td><td width=\"50%\"><input type=\"text\" name=\"suffixies\" size=\"32\" value=\"{$suffixies}\" style=\"width:100%\"></td></tr>" . "<tr valign=\"baseline\" bgcolor=\"#cccccc\"><td width=\"50%\" bgcolor=\"#ccccff\"><b>Options:</b></td><td width=\"50%\">" . "<input type=\"checkbox\" id=\"all\" name=\"all\"" . (empty($all) ? "" : " checked") . "> - <label for=\"all\">encode all files</label><br>" . "<input type=\"checkbox\" id=\"links\" name=\"links\"" . (empty($links) ? "" : " checked") . "> - <label for=\"links\">follow symbolic links</label><br>" . "<input type=\"checkbox\" id=\"recursive\" name=\"recursive\"" . (empty($recursive) ? "" : " checked") . "> - <label for=\"recursive\">encode directories recursively</label><br>" . "<input type=\"checkbox\" id=\"copy\" name=\"copy\"" . (empty($copy) ? "" : " checked") . "> - <label for=\"copy\">copy files those shouldn't be encoded</label><br>" . "<input type=\"checkbox\" id=\"force\" name=\"force\"" . (empty($force) ? "" : " checked") . "> - <label for=\"force\">overwrite existing files</label><br>" . "</td></tr>" . "<tr><td colspan=\"2\" align=\"center\" bgcolor=\"#cccccc\"><input type=\"submit\" name=\"submit\" value=\"OK\" style=\"width:100px\"></td></tr>" . "</form></body></html>";
}