First commit

This commit is contained in:
Pierre Hubert
2016-11-19 12:08:12 +01:00
commit 990540b2b9
4706 changed files with 931207 additions and 0 deletions

4
3rdparty/luminous/examples/.htaccess vendored Executable file
View File

@ -0,0 +1,4 @@
allow from localhost
allow from ::1
options +Indexes

73
3rdparty/luminous/examples/ajax.php vendored Executable file
View File

@ -0,0 +1,73 @@
<?php
/* Example using AJAX to prettify inline code */
require_once('helper.inc');
luminous::set('line-numbers', false);
luminous::set('include-javascript', true);
luminous::set('format', 'html-inline');
// define a quick and dirty AJAX interface
function do_ajax() {
global $use_cache;
$language = $_POST['language'];
$code = $_POST['code'];
// Arbitrarily sized security check
if (strlen($code) < 500)
echo luminous::highlight($language, $code, $use_cache);
die(0); // we're done now.
}
if (!empty($_POST)) {
// php is stupid.
if(get_magic_quotes_gpc()) {
foreach($_POST as &$p)
$p = stripslashes($p);
}
do_ajax();
}
?><!DOCTYPE html>
<html>
<head>
<title>Inline code highlighting with AJAX example</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
echo luminous::head_html();
?>
<script type='text/javascript'>
$(document).ready(function() {
$('pre.code_eg').each(function(i, e) {
$.post('ajax.php', {code : $(e).text(), language: 'c'},
function (data) {
$new = $(data);
$(e).replaceWith($new);
}
);
});
});
</script>
<style type='text/css'>
/* elegant fallback if JS is disabled */
pre.code_eg {
display:inline-block;
font-weight:bold;
background-color:#e0e0e0;
margin-top: 0;
margin-bottom:0;
padding-left: 0.5em;
padding-right:0.5em;
}
</style>
</head>
<body>
<p>
This example shows how to write some short single-line code snippets inside a paragraph, and then use JavaScript and AJAX to highlight it with Luminous. Viewing this page without JavaScript shows an elegant fallback.
</p>
Lorem ipsum dolor sit amet, <pre class='code_eg'>#include &lt;stdio.h&gt;</pre> consectetur adipiscing elit. Pellentesque <pre class='code_eg'>int main() </pre> orci eros, pellentesque sed elementum eu, mattis nec neque. Vestibulum hendrerit leo vel mi tristique mollis. Mauris magna odio, porta ut fringilla iaculis, <pre class='code_eg'>printf("hello, world!\n");</pre>
placerat eu urna. Vivamus non nisi nec <pre class='code_eg'>return 0;</pre> ante euismod vehicula. Curabitur nec enim tortor. Proin viverra ligula nec quam pulvinar vehicula. Vivamus turpis diam
</body>
</html>

134
3rdparty/luminous/examples/example.php vendored Executable file
View File

@ -0,0 +1,134 @@
<?php
/**
* \file example.php
* \brief A short example for calling Luminous
*/
require_once('helper.inc');
// Luminous shouldn't ever get caught in an infinite loop even on the most
// terrible and malformed input, but I think you'd be daft to run it with no
// safeguard. Also, if you allow your users to give it arbitrary inputs, large
// inputs are pretty much asking for a denial of service attack. Ideally you
// would enforce your own byte-limit, but I think a time limit is also sensible.
set_time_limit(3);
$use_cache = !isset($_GET['nocache'])
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<!-- Luminous is HTML4 strict/loose and HTML5 valid //-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title> Example </title>
<?php
echo luminous::head_html();
?>
</head>
<body>
<h1> A simple usage example for Luminous </h1>
<p> Inspect the source code to see what's going on. Look at both the PHP
code and the HTML markup. </p>
<p>
<?php if (!$use_cache)
echo "Caching is <strong>disabled</strong>, click <a href='example.php'>here</a> to enable it";
else
echo "Caching is <strong>enabled</strong>. If you are seeing errors, you will need to make the directory: "
. realpath(dirname(__FILE__) . "/../") . "/cache/, and make it writable to your server if you intend to use the caching system. Click <a href='example.php?nocache'>here</a> to view this page with caching disabled";
?>
</p>
<?php echo luminous::highlight('cpp', <<<EOF
#include <stdio.h>
int main()
{
printf("hello, world");
return 0;
}
EOF
, $use_cache); ?>
<p> You can also set specific runtime options in the highlight call (here we set 'max-height' = 250), which will be
forgotten at the next highlight.
<?php
echo luminous::highlight('php', <<<EOF
<?php
/**
* \\ingroup LuminousUtils
* \\internal
* \\brief Decodes a PCRE error code into a string
* \\param errcode The error code to decode (integer)
* \\return A string which is simply the name of the constant which matches the
* error code (e.g. 'PREG_BACKTRACK_LIMIT_ERROR')
*
* \\todo this should all be namespaced
*/
function pcre_error_decode(\$errcode)
{
switch (\$errcode)
{
case PREG_NO_ERROR:
return 'PREG_NO_ERROR';
case PREG_INTERNAL_ERROR:
return 'PREG_INTERNAL_ERROR';
case PREG_BACKTRACK_LIMIT_ERROR:
return 'PREG_BACKTRACK_LIMIT_ERROR';
case PREG_RECURSION_LIMIT_ERROR:
return 'PREG_RECURSION_LIMIT_ERROR';
case PREG_BAD_UTF8_ERROR:
return 'PREG_BAD_UTF8_ERROR';
case PREG_BAD_UTF8_OFFSET_ERROR:
return 'PREG_BAD_UTF8_OFFSET_ERROR';
default:
return 'Unknown error code';
}
}
EOF
, array('cache' => $use_cache, 'max-height' => '250'));
?>
<p> See:
<?php echo luminous::highlight('php', <<<EOF
<?php
/**
* \\ingroup LuminousUtils
* \\internal
* \\brief Decodes a PCRE error code into a string
* \\param errcode The error code to decode (integer)
* \\return A string which is simply the name of the constant which matches the
* error code (e.g. 'PREG_BACKTRACK_LIMIT_ERROR')
*
* \\todo this should all be namespaced
*/
function pcre_error_decode(\$errcode)
{
switch (\$errcode)
{
case PREG_NO_ERROR:
return 'PREG_NO_ERROR';
case PREG_INTERNAL_ERROR:
return 'PREG_INTERNAL_ERROR';
case PREG_BACKTRACK_LIMIT_ERROR:
return 'PREG_BACKTRACK_LIMIT_ERROR';
case PREG_RECURSION_LIMIT_ERROR:
return 'PREG_RECURSION_LIMIT_ERROR';
case PREG_BAD_UTF8_ERROR:
return 'PREG_BAD_UTF8_ERROR';
case PREG_BAD_UTF8_OFFSET_ERROR:
return 'PREG_BAD_UTF8_OFFSET_ERROR';
default:
return 'Unknown error code';
}
}
EOF
, $use_cache); ?>
</body>
</html>

5
3rdparty/luminous/examples/fullpage.php vendored Executable file
View File

@ -0,0 +1,5 @@
<?php
// very easy, set the format to html-full
require_once('helper.inc');
luminous::set('format', 'html-full');
echo luminous::highlight_file('php', 'themeswitcher.php', $use_cache);

13
3rdparty/luminous/examples/helper.inc vendored Executable file
View File

@ -0,0 +1,13 @@
<?php
require_once('../luminous.php');
set_time_limit(2);
// This var is because on my dev machine I symlink some directories and
// from that, PHP/Luminous cannot figure out where it is relative to the
// document root.
$http_path = '../';
$use_cache = false;
luminous::set('relative-root', $http_path);
luminous::set('include-jquery', true);

153
3rdparty/luminous/examples/index.php vendored Executable file
View File

@ -0,0 +1,153 @@
<?php
require dirname(__FILE__) . '/helper.inc';
$files = array(
'Standard example' => 'example.php',
'AJAX interface' => 'ajax.php',
'Full page output' => 'fullpage.php',
'Inline code' => 'inline.php',
'Theme switcher' => 'themeswitcher.php',
'Setting options' => 'options.php',
);
if(isset($_GET['file']) && in_array($_GET['file'], $files)) {
luminous::set('include-jquery', true);
$source = luminous::highlight('php',
file_get_contents(dirname(__FILE__) . '/' . $_GET['file']));
luminous::set('theme', 'github');
$head = luminous::head_html();
echo <<<EOF
<!DOCTYPE html>
<html>
<head>
<title></title>
<style> body { font-size: smaller; margin: 0;} </style>
$head
</head>
<body>
$source
</body>
</html>
EOF;
exit(0);
}?><!DOCTYPE html>
<html>
<head>
<title>Luminous examples</title>
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script>
$(document).ready(function() {
var $menuLinks = $('.menu a');
$menuLinks.click(function() {
var indexSelector = ':eq(' + $(this).data('index') + ')';
$('.menu > li').add('.examples > li').addClass('inactive');
$('.menu > li' + indexSelector)
.add('.examples > li' + indexSelector)
.removeClass('inactive');
$('.examples > li.inactive').slideUp();
$('.examples > li:not(.inactive)').slideDown();
return false;
});
$('.tabs a').click(function() {
var shouldShowSource = $(this).hasClass('show-source'),
$container = $(this).parents('li:eq(0)'),
hideSelect = shouldShowSource? '.source' : '.example',
showSelect = shouldShowSource? '.example' : '.source';
$container.find(showSelect).slideUp();
$container.find(hideSelect).slideDown();
$container.find('a').addClass('inactive');
$(this).removeClass('inactive');
return false;
});
// figure out the iframe height
$(window).resize(function() {
var windowHeight = $(window).height(),
$el = $('.examples iframe:visible'),
offset = $el.offset().top;
$('.examples iframe').css('height', Math.max(250, windowHeight - offset - 20) + 'px');
});
$menuLinks.eq(0).trigger('click');
$('.tabs a.show-output').trigger('click');
$(window).trigger('resize');
});
</script>
<style>
body {
font-family: sans-serif;
}
iframe {
border: 1px solid #bbb;
width: 100%;
}
ul {
margin: 0;
padding: 0;
list-style: none;
}
ul.menu {
}
ul.menu li {
float: left;
padding-right: 1em;
}
ul.menu:after {
display: block;
content: " ";
clear: both;
}
li {
margin: 0;
padding: 0;
}
li .tabs a, .menu a {
font-weight: bold;
}
li .tabs a.inactive, .menu .inactive a {
font-weight: normal;
}
.tabs {
text-align: right;
}
.examples li {
height: 100%;
}
</style>
</head>
<body>
<h1>Luminous Examples</h1>
<p>Usage and calling examples for Luminous</p>
<ul class='menu'>
<?php $i=0; foreach ($files as $description=>$filename): ?>
<li class='inactive'>
<a href='#' data-index="<?= $i ?>"><?= $description ?></a>
</li>
<?php $i++; endforeach; ?>
</ul>
<ul class='examples'>
<?php $i=0; foreach ($files as $description=>$filename): ?>
<li class='inactive'>
<div class='tabs'>
<a href='#' class='show-output'>Example</a>
<a href='#' class='show-source inactive'>Source</a>
</div>
<ul class='inner'>
<li class='example'><iframe src='<?=$filename?>'></iframe></li>
<li class='source inactive'><iframe src='?file=<?=$filename?>'></iframe></li>
</ul>
</li>
<?php $i++; endforeach; ?>
</ul>
</body>
</html>

21
3rdparty/luminous/examples/inline.php vendored Executable file
View File

@ -0,0 +1,21 @@
<?php
include 'helper.inc';
luminous::set('format', 'html-inline');
luminous::set('include-javascript', false);
?><!DOCTYPE HTML>
<!DOCTYPE html>
<html>
<head>
<title>Inline code highlighting with AJAX example</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
echo luminous::head_html();
?>
</head>
<body>
Lorem ipsum dolor sit amet, <?php echo luminous::highlight('c', '#include <stdio.h>') ;?> consectetur adipiscing elit. Pellentesque <?php echo luminous::highlight('c', 'int main()');?> orci eros, pellentesque sed elementum eu, mattis nec neque. Vestibulum hendrerit leo vel mi tristique mollis. Mauris magna odio, porta ut fringilla iaculis, <?php echo luminous::highlight('c', 'printf("hello, world!\n");');?>
placerat eu urna. Vivamus non nisi nec <?php echo luminous::highlight('c', 'return 0;');?> ante euismod vehicula. Curabitur nec enim tortor. Proin viverra ligula nec quam pulvinar vehicula. Vivamus turpis diam
</body>
</html>

34
3rdparty/luminous/examples/options.php vendored Executable file
View File

@ -0,0 +1,34 @@
<?php
include dirname(__FILE__) . '/helper.inc';
$code = <<<EOF
// here's some jquery - http://www.jquery.com
$('a').click(function() {
return false;
});
EOF;
$language = 'js';
?>
<!DOCTYPE html>
<html>
<head>
<title>Setting options</title>
<?= luminous::head_html() ?>
</head>
<body>
<p> There are two ways you can set options: globally via the set() method, and per-call
in the highlight() method. Let's disable auto-linking and make all
highlights begin at line 17 via the global call.
<?php
// NOTE: this is equivalent to calling luminous::set(array('auto-link' => false, 'start-line' => 17));
luminous::set('auto-link', false);
luminous::set('start-line', 17);
echo luminous::highlight($language, $code);
?>
<p> Now let's override both of those for the duration of the next call
<?= luminous::highlight($language, $code, array('auto-link' => true, 'start-line' => 1)) ?>
<p> When we next call highlight(), the options will be back to their global states:
<?= luminous::highlight($language, $code); ?>
<p> We can get the current value for an option by calling setting(): auto-link is: <?=var_dump(luminous::setting('auto-link')) ?>.
</body>
</html>

62
3rdparty/luminous/examples/themeswitcher.php vendored Executable file
View File

@ -0,0 +1,62 @@
<?php
// Theme switcher example
require_once('helper.inc');
luminous::set('include-javascript', true);
// This isn't an injection or XSS vulnerability. You don't have to worry
// about sanitising this, Luminous won't use it if it's not a valid theme file.
if (!empty($_GET))
luminous::set('theme', $_GET['theme_switcher']);
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Theme Switcher Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php echo luminous::head_html(); ?>
<script type='text/javascript'>
$(document).ready(function() {
// theme switcher change handler
$('#theme_switcher').change(function(){
// get the /path/to/style/ via the current theme's href attribute
var current_url = $('#luminous-theme').attr('href');
var base_url = current_url.replace(/[^/]*$/, '');
// now replace the href with the new theme's path
$('#luminous-theme').attr('href',
base_url + $(this).val()
);
return false;
});
});
</script>
</head>
<body>
<p>
<form action='themeswitcher.php'>
Change Theme: <select name='theme_switcher' id='theme_switcher'>
<?php
// Build the theme switcher by getting a list of legal themes from Luminous.
// The luminous_get_html_head() function by default outputs the theme
// in LUMINOUS_THEME. This can be overridden by the first argument, but as we
// didn't, that's what we need to check against to determine the default
// theme for the selector. However, it might not have the .css suffix.
$default_theme = luminous::setting('theme');
if (!preg_match('/\.css$/', $default_theme))
$default_theme .= '.css';
foreach(luminous::themes() as $theme): ?>
<option id='<?=$theme?>'
<?=($theme == $default_theme)? ' selected' : ''?>>
<?= $theme ?>
</option>
<?php endforeach ?>
</select>
<noscript><input type='submit' value='Switch'></noscript>
</form>
<p>
<?php echo luminous::highlight_file('php', __FILE__, $use_cache); ?>
</body>
</html>