ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
aliased.php
Go to the documentation of this file.
1 <?php
18 // Your config here
19 define("SOURCE_ROOT", "/var/www/your/source/root/");
20 
21 // Assume you've put geshi in the include_path already
22 require_once("geshi.php");
23 
24 // Get path info
25 $path = SOURCE_ROOT.$_SERVER['PATH_INFO'];
26 
27 // Check for dickheads trying to use '../' to get to sensitive areas
29 $real_path = realpath($path);
30 if(strncmp($real_path, SOURCE_ROOT, $base_path_len)) {
31  exit("Access outside acceptable path.");
32 }
33 
34 // Check file exists
35 if(!file_exists($path)) {
36  exit("File not found ($path).");
37 }
38 
39 // Prepare GeSHi instance
40 $geshi = new GeSHi();
41 $geshi->set_language('text');
42 $geshi->load_from_file($path);
43 $geshi->set_header_type(GESHI_HEADER_PRE);
44 $geshi->enable_classes();
45 $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 10);
46 $geshi->set_overall_style('color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0;', true);
47 $geshi->set_line_style('font: normal normal 95% \'Courier New\', Courier, monospace; color: #003030;', 'font-weight: bold; color: #006060;', true);
48 $geshi->set_code_style('color: #000020;', 'color: #000020;');
49 $geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
50 $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
51 $geshi->set_header_content('Source code viewer - ' . $path . ' - ' . $geshi->get_language_name());
52 $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;');
53 $geshi->set_footer_content('Parsed in <TIME> seconds, using GeSHi <VERSION>');
54 $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;');
55 
56 ?>
57 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
58  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
59 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
60 <head>
61  <title>Source code viewer - <?php echo $path; ?> - <?php $geshi->get_language_name(); ?></title>
62  <style type="text/css">
63  <!--
64  <?php
65  // Output the stylesheet. Note it doesn't output the <style> tag
66  echo $geshi->get_stylesheet();
67  ?>
68  html {
69  background-color: #f0f0f0;
70  }
71  body {
72  font-family: Verdana, Arial, sans-serif;
73  margin: 10px;
74  border: 2px solid #e0e0e0;
75  background-color: #fcfcfc;
76  padding: 5px;
77  }
78  h2 {
79  margin: .1em 0 .2em .5em;
80  border-bottom: 1px solid #b0b0b0;
81  color: #b0b0b0;
82  font-weight: normal;
83  font-size: 150%;
84  }
85  h3 {
86  margin: .1em 0 .2em .5em;
87  color: #b0b0b0;
88  font-weight: normal;
89  font-size: 120%;
90  }
91  #footer {
92  text-align: center;
93  font-size: 80%;
94  color: #a9a9a9;
95  }
96  #footer a {
97  color: #9999ff;
98  }
99  textarea {
100  border: 1px solid #b0b0b0;
101  font-size: 90%;
102  color: #333;
103  margin-left: 20px;
104  }
105  select, input {
106  margin-left: 20px;
107  }
108  p {
109  font-size: 90%;
110  margin-left: .5em;
111  }
112  -->
113  </style>
114 </head>
115 <body>
116 <?php
117 // The fun part :)
118 echo $geshi->parse_code();
119 ?>
120 <hr/>
121 </body>
122 </html>
$path
Definition: aliased.php:25
if(strncmp($real_path, SOURCE_ROOT, $base_path_len)) if(!file_exists($path)) $geshi
Definition: aliased.php:40
if(PHP_SAPI !='cli') color
Definition: langcheck.php:120
margin left
Definition: langcheck.php:164
"color:#CC0000 style
Definition: example_001.php:92
const GESHI_HOVER
Links in the source in the :hover state.
Definition: geshi.php:105
p
Definition: langcheck.php:169
Set default font
Definition: 02types-xls.php:55
$real_path
Definition: aliased.php:29
$base_path_len
Definition: aliased.php:28
textarea
Definition: langcheck.php:160
font size
Definition: langcheck.php:162
input
Definition: langcheck.php:166
const GESHI_HEADER_PRE
Use a "pre" to surround the source.
Definition: geshi.php:75
const GESHI_LINK
Links in the source in the :link state.
Definition: geshi.php:103
const GESHI_FANCY_LINE_NUMBERS
Use fancy line numbers when building the result.
Definition: geshi.php:67
select
Definition: langcheck.php:166
const SOURCE_ROOT
Another GeSHi example script.
Definition: aliased.php:19