private function hook_cb($matches) { $meta = $matches[2]; $code = $matches[3]; // parse the classes, don't worry about this if it's a [code] if (strlen($matches[0]) && $matches[0][0] === '<') { // code in <...> tags are legit. html so we need to unescape whatever they // had to escape $code = htmlspecialchars_decode($code); if (!preg_match('/class=([\'"])(.*?)(\\1)/', $meta, $m)) { return $matches[0]; } $classes = preg_split('/\\s+/', $m[2]); if (!in_array('highlight', $classes)) { return $matches[0]; } } $language = 'plain'; if (preg_match('/lang(uage)?=(.*)/', $meta, $m)) { $language = $m[2]; if (strlen($language) && ($language[0] === '"' || $language[0] === "'")) { if (($pos = strpos($language, $language[0], 1)) !== false) { $language = substr($language, 1, $pos - 1); } } } return luminous::highlight($language, $code); }
/** * @param $strXML * @param bool|false $textarea * * @throws \Exception */ public static function printXML($strXML, $textarea = false) { if ($textarea) { echo 'XML Generato: <br /><textarea name="xml" cols=130 rows=25>' . $strXML . '</textarea><br /><br />'; } else { echo '<div style="height:500px; overflow:auto">' . \luminous::highlight('xml', $strXML) . "</div>"; } }
if ($lang === 'guess') { $s = microtime(true); $guesses = luminous::guessLanguageFull($_POST['src']); $e = microtime(true); $lang = luminous::guessLanguage($_POST['src']); $printable_guesses = array(); foreach ($guesses as $g) { $printable_guesses[$g['language']] = $g['p']; } echo sprintf('Language guessed in %f seconds:', $e - $s); echo '<pre>'; print_r($printable_guesses); echo '</pre>'; } $t = microtime(true); $out = luminous::highlight($lang, $_POST['src'], false); $t1 = microtime(true); if ($e = luminous::cacheErrors()) { echo '<pre>'; echo implode("<br/>", $e); echo '</pre>'; } echo $t1 - $t . 'seconds <br>'; echo strlen($_POST['src']) . '<br>'; echo $out; } ?> <div style='text-align:center'> <form method='post' action='interface.php'> <select name='lang'> <option value='guess'>Guess Language</option>
function net2ftp_module_printBody() { // -------------- // This function prints the login screen // -------------- // ------------------------------------------------------------------------- // Global variables // ------------------------------------------------------------------------- global $net2ftp_settings, $net2ftp_globals, $net2ftp_messages, $net2ftp_result; // ------------------------------------------------------------------------- // Variables // ------------------------------------------------------------------------- $filename_extension = get_filename_extension($net2ftp_globals["entry"]); // ------------------------ // Set the state2 variable depending on the file extension !!!!! // ------------------------ if (getFileType($net2ftp_globals["entry"]) == "IMAGE") { $filetype = "image"; } elseif ($filename_extension == "swf") { $filetype = "flash"; } else { $filetype = "text"; } // Form name, back and forward buttons $formname = "ViewForm"; $back_onclick = "document.forms['" . $formname . "'].state.value='browse';document.forms['" . $formname . "'].state2.value='main';document.forms['" . $formname . "'].submit();"; // Next screen $nextscreen = 2; // ------------------------------------------------------------------------- // Text // ------------------------------------------------------------------------- if ($filetype == "text") { // Title $title = __("View file %1\$s", $net2ftp_globals["entry"]); // ------------------------ // luminous_text // ------------------------ setStatus(2, 10, __("Reading the file")); $luminous_text = ftp_readfile("", $net2ftp_globals["directory"], $net2ftp_globals["entry"]); if ($net2ftp_result["success"] == false) { return false; } // ------------------------ // luminous_language // ------------------------ $luminous_language = ""; $list_language_extensions = array('html' => array('html', 'htm'), 'javascript' => array('js'), 'css' => array('css'), 'php' => array('php', 'php5', 'phtml', 'phps'), 'perl' => array('pl', 'pm', 'cgi'), 'sql' => array('sql'), 'java' => array('java'), 'ada' => array('a', 'ada', 'adb', 'ads'), 'as' => array('as'), 'asp' => array('asp'), 'cpp' => array('cpp'), 'csharp' => array('csharp'), 'diff' => array('diff'), 'go' => array('go'), 'latex' => array('latex'), 'matlab' => array('matlab'), 'python' => array('py'), 'rails' => array('rails'), 'ruby' => array('ruby'), 'sql' => array('sql'), 'vb' => array('bas'), 'vim' => array('vim'), 'xml' => array('xml')); while (list($language, $extensions) = each($list_language_extensions)) { if (in_array($filename_extension, $extensions)) { $luminous_language = $language; break; } } // ------------------------ // Call luminous // ------------------------ setStatus(4, 10, __("Parsing the file")); $luminous_text = luminous::highlight($luminous_language, $luminous_text, FALSE); } elseif ($filetype == "image") { $title = __("View image %1\$s", htmlEncode2($net2ftp_globals["entry"])); $image_url = printPHP_SELF("view"); $image_alt = __("Image") . $net2ftp_globals["entry"]; } elseif ($filetype == "flash") { $title = __("View Macromedia ShockWave Flash movie %1\$s", htmlEncode2($net2ftp_globals["entry"])); $flash_url = printPHP_SELF("view"); } // ------------------------------------------------------------------------- // Print the output // ------------------------------------------------------------------------- require_once $net2ftp_globals["application_skinsdir"] . "/" . $net2ftp_globals["skin"] . "/manage.template.php"; }
} /** * Raw formatter test. * Luminous raw output is pretty much XML, so we test it's properly formed * by making it proper XML (a very simple transformation), and then * we try loading it into an XML parser which is error intolerant. */ require_once 'helpers.inc'; $samples = glob('./samples/src/*'); luminous::set('format', null); libxml_use_internal_errors(true); $errors = array(); foreach ($samples as $s) { $language = substr($s, strrpos($s, '.') + 1); $src = file_get_contents($s); $out = luminous::highlight($language, $src, false); $out = <<<EOF <?xml version='1.0' encoding='UTF-8'?> <LUMINOUS> {$out} </LUMINOUS> EOF; $xml = simplexml_load_string($out); if ($xml === false) { $errors[$s] = array(); foreach (libxml_get_errors() as $error) { $errors[$s][] = $error->message; } } libxml_clear_errors(); }
function highlight() { $this->parse_args(); // figure out the code // error cases are: // no input file or source code, if ($this->options['code'] === null && $this->options['input-file'] === null) { $this->error('No input file or source code specified'); } elseif ($this->options['code'] !== null && $this->options['input-file'] !== null) { $this->error('Input file (-i) and source code specified. You probably ' . 'didn\'t mean this'); } // is there an input file? use that. if ($this->options['input-file'] !== null) { $c = @file_get_contents($this->options['input-file']); if ($c === false) { $this->error('Could not read from ' . $this->options['input-file']); } else { $this->options['code'] = $c; } } elseif ($this->options['code'] === '-') { $code = ''; while (($line = fgets(STDIN)) !== false) { $code .= $line; } $this->options['code'] = $code; } // set the formatter luminous::set('format', $this->options['format']); // lame check that the formatter is okay try { luminous::formatter(); } catch (Exception $e) { $this->error('Unknown formatter ' . $this->options['format']); } // set the theme $valid_themes = luminous::themes(); $theme = $this->options['theme']; if (!preg_match('/\\.css$/', $theme)) { $theme .= '.css'; } if (!luminous::theme_exists($theme)) { $this->error('No such theme: ' . $theme); } else { luminous::set('theme', $theme); } // set the language if ($this->options['lang'] === null) { // guessing $this->options['lang'] = luminous::guess_language($this->options['code']); } // user provided language $scanners = luminous::scanners(); $valid_scanner = false; foreach ($scanners as $lang => $codes) { if (in_array($this->options['lang'], $codes)) { $valid_scanner = true; break; } } if (!$valid_scanner) { $this->error('No such language: ' . $this->options['lang']); } // other options luminous::set('max-height', $this->options['height']); luminous::set('line-numbers', $this->options['line-numbers']); $h = luminous::highlight($this->options['lang'], $this->options['code']); if ($this->options['output-file'] !== null) { $r = @file_put_contents($this->options['output-file'], $h, LOCK_EX); if ($r === false) { $this->error('Could not write to ' . $this->options['output-file']); } } else { echo $h; } exit(0); }