public function __construct($id) { $this->dir = luminous::root() . '/cache/'; $this->subdir = substr($id, 0, 2); $this->filename = substr($id, 2); $this->path = rtrim($this->dir, '/') . '/' . $this->subdir . '/' . $this->filename; parent::__construct($id); }
public function hook($params = array()) { $CI =& get_instance(); $output = $CI->output->get_output(); if (!isset($params['header']) || $params['header'] === true) { if (isset($params['theme'])) { luminous::set('theme', $params['theme']); } if (!function_exists('base_url')) { $CI->load->helper('url'); } luminous::set('relative-root', base_url() . 'application/hooks/ci-syntax-highlight/luminous/'); $head = luminous::head_html(); // insert the stylesheets $output = preg_replace('%</head%i', "{$head}\n" . '$0', $output, 1); } $exps = array("/\n \\[(code)(.*?)\\][ \t]*(?:[\r\n]|\r\n)?\n (.*?)\n \\s*\n \\[\\/code\\]\n /xs", "/\n <(pre|code)(.*?)>[ \t]*(?:[\r\n]|\r\n)?\n (.*?)\n \\s*\n <\\/\\1>\n /xs"); foreach ($exps as $e) { $output = preg_replace_callback($e, array($this, 'hook_cb'), $output); } echo $output; }
/** * */ public static function printHtmlHeader() { \luminous::set(array('relative_root' => '../vendor/luminous/luminous')); echo '<html> <head> <link href="../vendor/twbs/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script src="../vendor/twbs/bootstrap/dist/js/bootstrap.min.js"></script>'; echo \luminous::head_html(); // outputs CSS includes to highlight xml, intended to go in <head> echo ' </head> <body role="document"> <div class="container theme-showcase" role="main"> <div class="jumbotron"> <h1>Demo Tessera Sanitaria.</h1> <p>Questo è un semplice demo che mostra l\'utilizzo del Package Padosoft TesseraSanitaria.<br /> Il package permette la creazione di file XML delle prestazioni mediche per il servizio nazionale sanità secondo il formato XML della tessera sanitaria definito nel DM 31/07/2015.<br /> Per maggiori info si veda il <a href="http://sistemats1.sanita.finanze.it/wps/portal/" target="_blank">Portale della Tessera Sanitaria</a> </p> </div> '; }
/** * Sets up a formatter instance according to our current options/settings */ private function set_formatter_options(&$formatter) { $formatter->wrap_length = $this->settings->wrap_width; $formatter->line_numbers = $this->settings->line_numbers; $formatter->link = $this->settings->auto_link; $formatter->height = $this->settings->max_height; $formatter->strict_standards = $this->settings->html_strict; $formatter->set_theme(luminous::theme($this->settings->theme)); }
* That's the test. */ $filenames = glob(realpath(__DIR__ . '/../regression') . '/*/*'); sort($filenames); foreach ($filenames as $filename) { if (strpos($filename, '.luminous') !== false) { continue; } if (preg_match('/~$/', $filename)) { continue; } $real_language = basename(dirname($filename)); $best = array('lang' => '', 'score' => -1, 'codes' => array(null)); $real = array('lang' => '', 'score' => -1, 'codes' => array(null)); $text = file_get_contents($filename); foreach (luminous::scanners() as $name => $codes) { $scanner = $luminous_->scanners->GetScanner($codes[0]); $score = $scanner->guess_language($text) . "\n"; if ($score > $best['score']) { $best['score'] = $score; $best['lang'] = $name; $best['codes'] = $codes; } if (in_array($real_language, $codes)) { $real['score'] = $score; $real['lang'] = $name; $real['codes'] = $codes; } } if (!in_array($real_language, $best['codes'])) { echo 'failed for ' . basename($filename) . "\n";
<div style='text-align:center'> <form method='post' action='interface.php'> <select name='lang'> <option value='guess'>Guess Language</option> <?php foreach (luminous::scanners() as $lang => $codes) { $def = isset($_POST['lang']) && $_POST['lang'] === $codes[0] ? ' selected' : ''; echo "<option value='{$codes[0]}'{$def}>{$lang}</option>\n"; } ?> <option value='no_such_scanner'>error case</option> </select> <br/> <select name='theme'> <?php foreach (luminous::themes() as $t) { $def = isset($_POST['theme']) && $_POST['theme'] === $t ? ' selected' : ''; echo sprintf("<option value='%s'%s>%s</option>\n", $t, $def, preg_replace('/\\.css$/i', '', $t)); } ?> </select> <br/> <select name='format'> <?php foreach (array('html', 'html-full', 'latex') as $f) { $def = isset($_POST['format']) && $_POST['format'] === $f ? ' selected' : ''; echo sprintf("<option value='%s'%s>%s</option>\n", $f, $def, $f); } ?> </select> <br/>
#!/usr/bin/php <?php if (php_sapi_name() !== 'cli') { die('This must be run from the command line'); } include 'functions.php'; if ($argc == 1) { echo "Usage : {$argv[0]} [options] FILE ...\n"; } $targets = array(); for ($i = 1; $i < $argc; $i++) { $x = $argv[$i]; if ($x == '-html') { $output_ext = '._html.luminous'; luminous::set('format', 'html'); luminous::set('max-height', -1); } else { $targets[] = $argv[$i]; } } if (empty($targets)) { $targets = $default_target; } foreach ($targets as $t) { recurse($t, 'generate'); }
$inline = true; } elseif ($a == '-v') { $verbose = true; } elseif ($a == '--help' || !array_key_exists($a, $doctypes)) { print_help(); } else { $doctypes_[] = $argv[$i]; } } // set_error_handler('err_handler'); $out = array(); $num_requests = count($samples) * count($doctypes_); $req = 0; luminous::set('format', $inline ? 'html_inline' : 'html'); foreach ($samples as $s) { $formatter = luminous::formatter(); $formatter->line_numbers = true; $formatter->link = true; // At the moment, this just stops TARGET attributes on links, which happen // to be highly convenient but the w3c in their infinite wisdom decided // were invalid in HTML4 strict. $formatter->strict_standards = true; $src = file_get_contents($s); $output = $formatter->format($src); $out[$s] = array(); foreach ($doctypes_ as $spec) { $doctype = $doctypes[$spec]; $html = @htmlify($output, $doctype); try { $return = validate($html); } catch (Exception $e) {
private function set_theme($value) { if (self::check_type($value, 'string')) { if (!preg_match('/\\.css$/', $value)) { $value .= '.css'; } if (!luminous::theme_exists($value)) { throw new Exception('No such theme: ' . luminous::root() . '/style/' . $value); } else { $this->theme = $value; } } }
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"; }
<?php /* * This is a horrible routine to register all the default * scanners. The code is distracting at best so it's been factored into this one * file. * * We include it into the main program with a require statement, which * due to the literal way PHP includes work, when done within a function gives * us access to that function's scope. * We are in the scope of a method inside the Luminous_ object, so we refer to * $this as being the $luminous_ singleton object. */ $language_dir = luminous::root() . '/languages/'; // this is a dummy file which includes ECMAScript dependencies in a // non-circular way. $this->scanners->AddScanner('ecma-includes', null, null, "{$language_dir}/include/ecma.php"); $this->scanners->AddScanner(array('ada', 'adb', 'ads'), 'LuminousAdaScanner', 'Ada', "{$language_dir}/ada.php"); $this->scanners->AddScanner(array('as', 'actionscript'), 'LuminousActionScriptScanner', 'ActionScript', "{$language_dir}/as.php", 'ecma'); $this->scanners->AddScanner(array('bnf'), 'LuminousBNFScanner', 'Backus Naur Form', "{$language_dir}/bnf.php"); $this->scanners->AddScanner(array('bash', 'sh'), 'LuminousBashScanner', 'Bash', "{$language_dir}/bash.php"); $this->scanners->AddScanner(array('c', 'cpp', 'h', 'hpp', 'cxx', 'hxx'), 'LuminousCppScanner', 'C/C++', "{$language_dir}/cpp.php"); $this->scanners->AddScanner(array('cs', 'csharp', 'c#'), 'LuminousCSharpScanner', 'C#', "{$language_dir}/csharp.php"); $this->scanners->AddScanner('css', 'LuminousCSSScanner', 'CSS', "{$language_dir}/css.php"); $this->scanners->AddScanner(array('diff', 'patch'), 'LuminousDiffScanner', 'Diff', "{$language_dir}/diff.php"); $this->scanners->AddScanner(array('prettydiff', 'prettypatch', 'diffpretty', 'patchpretty'), 'LuminousPrettyDiffScanner', 'Diff-Pretty', "{$language_dir}/diff.php"); $this->scanners->AddScanner(array('html', 'htm'), 'LuminousHTMLScanner', 'HTML', "{$language_dir}/html.php", array('js', 'css')); $this->scanners->AddScanner(array('ecma', 'ecmascript'), 'LuminousECMAScriptScanner', 'ECMAScript', "{$language_dir}/ecmascript.php", 'ecma-includes'); $this->scanners->AddScanner(array('erlang', 'erl', 'hrl'), 'LuminousErlangScanner', 'Erlang', "{$language_dir}/erlang.php"); $this->scanners->AddScanner('go', 'LuminousGoScanner', 'Go', "{$language_dir}/go.php"); $this->scanners->AddScanner(array('groovy'), 'LuminousGroovyScanner', 'Groovy', "{$language_dir}/groovy.php");
public function __construct($id) { $this->dir = luminous::root() . '/cache/'; $this->path = $this->dir . '/' . $id; parent::__construct($id); }
<?php // very easy, set the format to html-full require_once 'helper.php'; Luminous::set('format', 'html-full'); echo luminous::highlightFile('php', 'themeswitcher.php', $useCache);
} /** * 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); }
protected function get_layout() { // this path info shouldn't really be here $path = luminous::root() . '/style/luminous.css'; $this->css = file_get_contents($path); }