Пример #1
0
function parseFile($download = false, $config)
{
    $code = "";
    $stylist = new phpStylist();
    if (!isset($config->file) || $config->file == "") {
        return false;
    }
    $code = loadFile($config->file);
    if (isset($config->iso8859)) {
        $code = utf8_encode($code);
    }
    if (!empty($code)) {
        $stylist->options = $config;
        if (isset($config->indent_with_tabs) && $config->indent_with_tabs) {
            $stylist->indent_char = "\t";
        }
        if (!empty($config->indent_size)) {
            $stylist->indent_size = $config->indent_size;
        }
        if (strpos($code, '<?') === false) {
            $code = '<?php ' . $code . ' ?>';
        }
        $formatted = $stylist->formatCode($code);
    }
    return $formatted;
}
Пример #2
0
function parseFile($download = false)
{
    global $HTTP_POST_FILES;
    $code = "";
    $stylist = new phpStylist();
    if (isset($_REQUEST['file']) && $_REQUEST['file'] != "" || isset($HTTP_POST_FILES['file']['tmp_name']) && $HTTP_POST_FILES['file']['tmp_name'] != "none" && $HTTP_POST_FILES['file']['tmp_name'] != "") {
        $file = isset($_REQUEST['file']) ? $_REQUEST['file'] : $HTTP_POST_FILES['file']['tmp_name'];
        $code = loadFile($file);
        if (isset($_REQUEST["iso8859"]) && $_REQUEST["iso8859"] != "off" && !isDownload()) {
            $code = utf8_encode($code);
        }
    } elseif (isset($_REQUEST["download"]) && $_REQUEST["download"] == '2') {
        $code = getSampleCode();
    } elseif (isset($_REQUEST["ta"]) && $_REQUEST["ta"] != '') {
        $code = stripslashes($_REQUEST["ta"]);
        if (isset($_REQUEST["iso8859"]) && $_REQUEST["iso8859"] != "off" && isDownload()) {
            $code = utf8_decode($code);
        }
    }
    if (!empty($code)) {
        foreach ($_REQUEST as $k => $v) {
            if (isset($stylist->options[strtoupper($k)])) {
                $stylist->options[strtoupper($k)] = $v != "off";
            }
        }
        if (isset($_REQUEST["indent_with_tabs"]) && $_REQUEST["indent_with_tabs"] != "off") {
            $stylist->indent_char = "\t";
        }
        if (isset($_REQUEST["indent_size"]) && $_REQUEST["indent_size"] != "" && $_REQUEST["indent_size"] != "null") {
            $stylist->indent_size = $_REQUEST["indent_size"];
        }
        if (strpos($code, '<?') === false) {
            $code = '<?php ' . $code . ' ?' . '>';
        }
        $formatted = $stylist->formatCode($code);
        $highlight = highlight_string($formatted, true);
        if (isset($HTTP_POST_FILES['file']['tmp_name']) && file_exists($HTTP_POST_FILES['file']['tmp_name'])) {
            unlink($HTTP_POST_FILES['file']['tmp_name']);
        }
        $nowrap = isset($_REQUEST["nowrap"]) && $_REQUEST["nowrap"] == 'on' ? "nowrap" : "";
        $tawrap = $nowrap == "" ? "" : "wrap='off' ";
        $display = isset($_REQUEST["textarea"]) && $_REQUEST["textarea"] == 'on' ? "" : "style='display: none;'";
        $textarea = "<tr id='tx' {$display}><td valign=top><textarea {$tawrap} style='width: 100%; height: 100%;' id='ta' name='ta'>" . htmlspecialchars($formatted) . "</textarea></td></tr>";
        $display = isset($_REQUEST["textarea"]) && $_REQUEST["textarea"] == 'on' ? "style='display: none;'" : "";
        $frame = "<tr id='hl' {$display}><td valign=top {$nowrap}>{$highlight}</td></tr>";
    } else {
        $nowrap = isset($_REQUEST["nowrap"]) && $_REQUEST["nowrap"] == 'on' ? "nowrap" : "";
        $tawrap = $nowrap == "" ? "" : "wrap='off' ";
        $textarea = "<tr id='tx'><td valign=top><textarea {$tawrap} style='width: 100%; height=100%;' id='ta' name='ta'></textarea></td></tr>";
        $frame = "<tr id='hl' style='display: none;'><td valign=top {$nowrap}></td></tr>";
    }
    if ($download) {
        return isset($formatted) ? $formatted : "";
    } else {
        return $textarea . $frame;
    }
}