Documentation is available at example.php
1 <?php
2
3 /**
4 * GeSHi example script
5 * --------------------
6 * Just point your browser at this script (with geshi.php in the parent directory,
7 * and the language files in subdirectory "../geshi/")
8 */
9
10 include('../geshi.php');
11 if ( isset($_POST['submit']) )
12 {
13 if ( get_magic_quotes_gpc() ) $_POST['source'] = stripslashes($_POST['source']);
14 if ( !strlen(trim($_POST['source'])) )
15 {
16 $_POST['source'] = implode('', @file('../geshi/' . $_POST['language'] . '.php'));
17 $_POST['language'] = 'php';
18 }
19 $geshi = new GeSHi($_POST['source'], $_POST['language'], '../geshi/');
20 $geshi->set_header_type(GESHI_HEADER_PRE);
21 $geshi->enable_classes();
22 $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5);
23 $geshi->set_overall_style('color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0;', true);
24 // Note the use of set_code_style to revert colours...
25 $geshi->set_line_style('font: normal normal 95% \'Courier New\', Courier, monospace; color: #003030;', 'font-weight: bold; color: #006060;', true);
26 $geshi->set_code_style('color: #000020;', 'color: #000020;');
27
28 $geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
29 $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
30
31 $geshi->set_header_content('GeSHi © 2004, Nigel McNie. View source of example.php for example of using GeSHi');
32 $geshi->set_header_content_style('font-family: Verdana, Arial, sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-bottom: 1px solid #d0d0d0; padding: 2px;');
33
34 $geshi->set_footer_content('Parsed in <TIME> seconds, using GeSHi <VERSION>');
35 $geshi->set_footer_content_style('font-family: Verdana, Arial, sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-top: 1px solid #d0d0d0; padding: 2px;');
36 }
37 ?>
38 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
39 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
40 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
41 <head>
42 <title>GeSHi examples</title>
43 <style type="text/css">
44 <!--
45 <?php
46 if ( isset($_POST['submit']) )
47 {
48 echo $geshi->get_stylesheet();
49 }
50 ?>
51 html {
52 background-color: #f0f0f0;
53 }
54 body {
55 font-family: Verdana, Arial, sans-serif;
56 margin: 10px;
57 border: 2px solid #e0e0e0;
58 background-color: #fcfcfc;
59 padding: 5px;
60 }
61 h2 {
62 margin: .1em 0 .2em .5em;
63 border-bottom: 1px solid #b0b0b0;
64 color: #b0b0b0;
65 font-weight: normal;
66 font-size: 150%;
67 }
68 h3 {
69 margin: .1em 0 .2em .5em;
70 color: #b0b0b0;
71 font-weight: normal;
72 font-size: 120%;
73 }
74 #footer {
75 text-align: center;
76 font-size: 80%;
77 color: #a9a9a9;
78 }
79 #footer a {
80 color: #9999ff;
81 }
82 textarea {
83 border: 1px solid #b0b0b0;
84 font-size: 90%;
85 color: #333;
86 margin-left: 20px;
87 }
88 select, input {
89 margin-left: 20px;
90 }
91 p {
92 font-size: 90%;
93 margin-left: .5em;
94 }
95 -->
96 </style>
97 </head>
98 <body>
99 <h2>GeSHi Example Script</h2>
100 <p>To use this script, make sure that <strong>geshi.php</strong> is in the parent directory, and that
101 the language files are in a subdirectory of the parent directory called <strong>geshi/</strong></p>
102 <p>Enter your source and a language to highlight the source in and submit, or just choose a language to
103 have that language file highlighted in PHP.</p>
104 <?php
105 if ( isset($_POST['submit']) )
106 {
107 echo $geshi->parse_code();
108 echo '<hr />';
109 }
110 ?>
111 <form action="example.php" method="post">
112 <h3>Source to highlight</h3>
113 <textarea rows="10" cols="60" name="source"></textarea>
114 <h3>Choose a language</h3>
115 <select name="language">
116 <?php
117 $dir = @opendir('../geshi');
118
119 while ( $file = readdir($dir) )
120 {
121 if ( $file == '..' || $file == '.' || !stristr($file, '.') || $file == 'css-gen.cfg' ) continue;
122 $lang = substr($file, 0, strpos($file, '.'));
123 echo '<option value="' . $lang . '">' . $lang . "</option>\n";
124 }
125
126 closedir($dir);
127
128 ?>
129 </select><br />
130 <input type="submit" name="submit" value="Highlight Source">
131 </form>
132 <div id="footer">GeSHi © Nigel McNie, 2004, released under the GNU GPL<br />
133 For a better demonstration, check out the <a href="http://qbnz.com/highlighter/demo.php">online demo</a>
134 </body>
135 </html>
Documentation generated on Tue, 26 Jul 2005 17:10:19 +1200 by phpDocumentor 1.2.3