Esempio n. 1
0
 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;
 }
Esempio n. 2
0
    /**
     *
     */
    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 &egrave; 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&agrave;
							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>
				';
    }
Esempio n. 3
0
#!/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');
}
Esempio n. 4
0
    $a = $argv[$i];
    if ($a == '-i') {
        $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 {
Esempio n. 5
0
function net2ftp_module_printCss()
{
    // --------------
    // This function prints CSS code and includes
    // --------------
    global $net2ftp_settings, $net2ftp_globals;
    // Include
    echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . $net2ftp_globals["application_rootdir_url"] . "/skins/" . $net2ftp_globals["skin"] . "/css/main.css.php?ltr=" . __("ltr") . "&amp;image_url=" . urlEncode2($net2ftp_globals["image_url"]) . "\" />\n";
    // CSS for Luminous syntax highlighter
    $filename_extension = get_filename_extension($net2ftp_globals["entry"]);
    if (getFileType($net2ftp_globals["entry"]) == "IMAGE") {
        $filetype = "image";
    } elseif ($filename_extension == "swf") {
        $filetype = "flash";
    } else {
        $filetype = "text";
    }
    if ($filetype == "text") {
        luminous::set("cache", FALSE);
        luminous::set("format", "html");
        luminous::set("line-numbers", TRUE);
        luminous::set("relative-root", $net2ftp_globals["application_rootdir_url"] . "/plugins/luminous/");
        //		luminous::set("theme", "luminous_dark");
        echo luminous::head_html();
    }
}
Esempio n. 6
0
#!/usr/bin/php
<?php 
if (php_sapi_name() !== 'cli') {
    die('This must be run from the command line');
}
/**
 * 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;
Esempio n. 7
0
 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);
 }
Esempio n. 8
0
#!/usr/bin/php
<?php 
if (php_sapi_name() !== 'cli') {
    die('This must be run from the command line');
}
// TODO: this no longer works, rewrite it for the new testing structure.
/**
 * tests the LaTeX formatter by formatting some code as LaTeX
 * then compiling it to pdf.
 * Requires pdflatex and the ability to call programs
 */
require_once dirname(__FILE__) . '/../../luminous.php';
$testfiles = glob(__DIR__ . '/samples/output/*');
$EXIT_STATUS = 0;
luminous::set('format', 'latex');
foreach ($testfiles as $t) {
    $ts = luminous::themes();
    $theme = $ts[array_rand(luminous::themes())];
    $formatter = luminous::formatter();
    $formatter->set_theme(file_get_contents('../../style/' . $theme));
    $src = file_get_contents($t);
    $t = preg_replace('%.*/%', '', $t);
    $fmt = $formatter->format($src);
    file_put_contents(__DIR__ . "/filedump/{$t}.tex", $fmt);
    chdir('filedump');
    system("pdflatex {$t}.tex >> /dev/null", $i);
    if ($i) {
        echo "latex formatter test failed on file {$t}, pdflatex exit status: {$i}\n";
        $EXIT_STATUS = 1;
    }
    chdir(getcwd() . '/../');