123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- <?php
- header('Content-Type: text/html; charset=utf-8');
- error_reporting(E_ALL);
- if (is_readable('../geshi.php')) {
- $path = '../';
- } elseif (is_readable('geshi.php')) {
- $path = './';
- } else {
- die('Could not find geshi.php - make sure it is in your include path!');
- }
- require $path . 'geshi.php';
- $fill_source = false;
- if (isset($_POST['submit'])) {
- if (get_magic_quotes_gpc()) {
- $_POST['source'] = stripslashes($_POST['source']);
- }
- if (!strlen(trim($_POST['source']))) {
- $_POST['language'] = preg_replace('#[^a-zA-Z0-9\-_]#', '', $_POST['language']);
- $_POST['source'] = implode('', @file($path . 'geshi/' . $_POST['language'] . '.php'));
- $_POST['language'] = 'php';
- } else {
- $fill_source = true;
- }
-
-
-
-
-
- $geshi = new GeSHi($_POST['source'], $_POST['language']);
-
-
-
-
-
-
- $geshi->set_header_type(GESHI_HEADER_PRE_VALID);
-
-
- $geshi->enable_classes();
-
- $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5);
-
-
-
- $geshi->set_overall_style('font: normal normal 90% monospace; color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0;', false);
-
-
-
-
-
-
-
-
-
- $geshi->set_line_style('color: #003030;', 'font-weight: bold; color: #006060;', true);
- $geshi->set_code_style('color: #000020;', true);
-
-
- $geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
- $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
-
-
-
- $geshi->set_header_content('<SPEED> <TIME> GeSHi © 2004-2007, Nigel McNie, 2007-2008 Benny Baumann. View source of example.php for example of using GeSHi');
- $geshi->set_header_content_style('font-family: sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-bottom: 1px solid #d0d0d0; padding: 2px;');
-
- $geshi->set_footer_content('Parsed in <TIME> seconds at <SPEED>, using GeSHi <VERSION>');
- $geshi->set_footer_content_style('font-family: sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-top: 1px solid #d0d0d0; padding: 2px;');
- } else {
-
- $_POST['language'] = null;
- }
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <title>GeSHi examples</title>
- <style type="text/css">
- <!--
- <?php
- if (isset($_POST['submit'])) {
-
- echo $geshi->get_stylesheet(true);
- }
- ?>
- html {
- background-color:
- }
- body {
- font-family: Verdana, Arial, sans-serif;
- margin: 10px;
- border: 2px solid
- background-color:
- padding: 5px;
- }
- h2 {
- margin: .1em 0 .2em .5em;
- border-bottom: 1px solid
- color:
- font-weight: normal;
- font-size: 150%;
- }
- h3 {
- margin: .1em 0 .2em .5em;
- color:
- font-weight: normal;
- font-size: 120%;
- }
-
- text-align: center;
- font-size: 80%;
- color:
- }
-
- color:
- }
- textarea {
- border: 1px solid
- font-size: 90%;
- color:
- margin-left: 20px;
- }
- select, input {
- margin-left: 20px;
- }
- p {
- font-size: 90%;
- margin-left: .5em;
- }
- -->
- </style>
- </head>
- <body>
- <h2>GeSHi Example Script</h2>
- <p>To use this script, make sure that <strong>geshi.php</strong> is in the parent directory or in your
- include_path, and that the language files are in a subdirectory of GeSHi's directory called <strong>geshi/</strong>.</p>
- <p>Enter your source and a language to highlight the source in and submit, or just choose a language to
- have that language file highlighted in PHP.</p>
- <?php
- if (isset($_POST['submit'])) {
- // The fun part :)
- echo $geshi->parse_code();
- echo '<hr />';
- }
- ?>
- <form action="<?php echo basename($_SERVER['PHP_SELF']); ?>" method="post">
- <h3>Source to highlight</h3>
- <p>
- <textarea rows="10" cols="60" name="source" id="source"><?php echo $fill_source ? htmlspecialchars($_POST['source']) : '' ?></textarea>
- </p>
- <h3>Choose a language</h3>
- <p>
- <select name="language" id="language">
- <?php
- if (!($dir = @opendir(dirname(__FILE__) . '/geshi'))) {
- if (!($dir = @opendir(dirname(__FILE__) . '/../geshi'))) {
- echo '<option>No languages available!</option>';
- }
- }
- $languages = array();
- while ($file = readdir($dir)) {
- if ( $file[0] == '.' || strpos($file, '.', 1) === false) {
- continue;
- }
- $lang = substr($file, 0, strpos($file, '.'));
- $languages[] = $lang;
- }
- closedir($dir);
- sort($languages);
- foreach ($languages as $lang) {
- if (isset($_POST['language']) && $_POST['language'] == $lang) {
- $selected = 'selected="selected"';
- } else {
- $selected = '';
- }
- echo '<option value="' . $lang . '" '. $selected .'>' . $lang . "</option>\n";
- }
- ?>
- </select>
- </p>
- <p>
- <input type="submit" name="submit" value="Highlight Source" />
- <input type="submit" name="clear" onclick="document.getElementById('source').value='';document.getElementById('language').value='';return false" value="clear" />
- </p>
- </form>
- <div id="footer">GeSHi © Nigel McNie, 2004, released under the GNU GPL<br />
- For a better demonstration, check out the <a href="http://qbnz.com/highlighter/demo.php">online demo</a>
- </div>
- </body>
- </html>
|