PageRenderTime 60ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/mysql-profiler/lib/geshi/contrib/example.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 193 lines | 138 code | 12 blank | 43 comment | 8 complexity | 4ae7e388f6fa46c2940989ab7d0d4c13 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0
  1. <?php
  2. /**
  3. * GeSHi example script
  4. *
  5. * Just point your browser at this script (with geshi.php in the parent directory,
  6. * and the language files in subdirectory "../geshi/")
  7. *
  8. * @author Nigel McNie
  9. * @version $Id: example.php 706 2006-05-19 11:40:16Z oracleshinoda $
  10. */
  11. // Rudimentary checking of where GeSHi is. In a default install it will be in ../, but
  12. // it could be in the current directory if the include_path is set. There's nowhere else
  13. // we can reasonably guess.
  14. if (!@include '../geshi.php') {
  15. if (!@include 'geshi.php') {
  16. die('Could not find geshi.php - make sure it is in your include path!');
  17. } else {
  18. $path = './';
  19. }
  20. } else {
  21. $path = '../';
  22. }
  23. if ( isset($_POST['submit']) )
  24. {
  25. if ( get_magic_quotes_gpc() ) $_POST['source'] = stripslashes($_POST['source']);
  26. if ( !strlen(trim($_POST['source'])) )
  27. {
  28. $_POST['language'] = preg_replace('#[^a-zA-Z0-9\-_]#', '', $_POST['language']);
  29. $_POST['source'] = implode('', @file($path . 'geshi/' . $_POST['language'] . '.php'));
  30. $_POST['language'] = 'php';
  31. }
  32. // Here's a free demo of how GeSHi works.
  33. // First the initialisation: source code to highlight and the language to use. Make sure
  34. // you sanitise correctly if you use $_POST of course - this very script has had a security
  35. // advisory against it in the past because of this. Please try not to use this script on a
  36. // live site.
  37. $geshi =& new GeSHi($_POST['source'], $_POST['language']);
  38. // Use the PRE header. This means less output source since we don't have to output &nbsp;
  39. // everywhere. Of course it also means you can't set the tab width.
  40. $geshi->set_header_type(GESHI_HEADER_PRE);
  41. // Enable CSS classes. You can use get_stylesheet() to output a stylesheet for your code. Using
  42. // CSS classes results in much less output source.
  43. $geshi->enable_classes();
  44. // Enable line numbers. We want fancy line numbers, and we want every 5th line number to be fancy
  45. $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 5);
  46. // Set the style for the PRE around the code. The line numbers are contained within this box (not
  47. // XHTML compliant btw, but if you are liberally minded about these things then you'll appreciate
  48. // the reduced source output).
  49. $geshi->set_overall_style('color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0;', true);
  50. // Set the style for line numbers. In order to get style for line numbers working, the <li> element
  51. // is being styled. This means that the code on the line will also be styled, and most of the time
  52. // you don't want this. So the set_code_style reverts styles for the line (by using a <div> on the line).
  53. // So the source output looks like this:
  54. //
  55. // <pre style="[set_overall_style styles]"><ol>
  56. // <li style="[set_line_style styles]"><div style="[set_code_style styles]>...</div></li>
  57. // ...
  58. // </ol></pre>
  59. $geshi->set_line_style('font: normal normal 95% \'Courier New\', Courier, monospace; color: #003030;', 'font-weight: bold; color: #006060;', true);
  60. $geshi->set_code_style('color: #000020;', 'color: #000020;');
  61. // Styles for hyperlinks in the code. GESHI_LINK for default styles, GESHI_HOVER for hover style etc...
  62. // note that classes must be enabled for this to work.
  63. $geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
  64. $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
  65. // Use the header/footer functionality. This puts a div with content within the PRE element, so it is
  66. // affected by the styles set by set_overall_style. So if the PRE has a border then the header/footer will
  67. // appear inside it.
  68. $geshi->set_header_content('GeSHi &copy; 2004, Nigel McNie. View source of example.php for example of using GeSHi');
  69. $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;');
  70. // You can use <TIME> and <VERSION> as placeholders
  71. $geshi->set_footer_content('Parsed in <TIME> seconds, using GeSHi <VERSION>');
  72. $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;');
  73. }
  74. ?>
  75. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  76. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  77. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  78. <head>
  79. <title>GeSHi examples</title>
  80. <style type="text/css">
  81. <!--
  82. <?php
  83. if ( isset($_POST['submit']) )
  84. {
  85. // Output the stylesheet. Note it doesn't output the <style> tag
  86. echo $geshi->get_stylesheet();
  87. }
  88. ?>
  89. html {
  90. background-color: #f0f0f0;
  91. }
  92. body {
  93. font-family: Verdana, Arial, sans-serif;
  94. margin: 10px;
  95. border: 2px solid #e0e0e0;
  96. background-color: #fcfcfc;
  97. padding: 5px;
  98. }
  99. h2 {
  100. margin: .1em 0 .2em .5em;
  101. border-bottom: 1px solid #b0b0b0;
  102. color: #b0b0b0;
  103. font-weight: normal;
  104. font-size: 150%;
  105. }
  106. h3 {
  107. margin: .1em 0 .2em .5em;
  108. color: #b0b0b0;
  109. font-weight: normal;
  110. font-size: 120%;
  111. }
  112. #footer {
  113. text-align: center;
  114. font-size: 80%;
  115. color: #a9a9a9;
  116. }
  117. #footer a {
  118. color: #9999ff;
  119. }
  120. textarea {
  121. border: 1px solid #b0b0b0;
  122. font-size: 90%;
  123. color: #333;
  124. margin-left: 20px;
  125. }
  126. select, input {
  127. margin-left: 20px;
  128. }
  129. p {
  130. font-size: 90%;
  131. margin-left: .5em;
  132. }
  133. -->
  134. </style>
  135. </head>
  136. <body>
  137. <h2>GeSHi Example Script</h2>
  138. <p>To use this script, make sure that <strong>geshi.php</strong> is in the parent directory or in your
  139. include_path, and that the language files are in a subdirectory of GeSHi's directory called <strong>geshi/</strong>.</p>
  140. <p>Enter your source and a language to highlight the source in and submit, or just choose a language to
  141. have that language file highlighted in PHP.</p>
  142. <?php
  143. if ( isset($_POST['submit']) )
  144. {
  145. // The fun part :)
  146. echo $geshi->parse_code();
  147. echo '<hr />';
  148. }
  149. ?>
  150. <form action="example.php" method="post">
  151. <h3>Source to highlight</h3>
  152. <textarea rows="10" cols="60" name="source"></textarea>
  153. <h3>Choose a language</h3>
  154. <select name="language">
  155. <?php
  156. if (!($dir = @opendir(dirname(__FILE__) . '/geshi'))) {
  157. if (!($dir = @opendir(dirname(__FILE__) . '/../geshi'))) {
  158. echo '<option>No languages available!</option>';
  159. }
  160. }
  161. $languages = array();
  162. while ( $file = readdir($dir) )
  163. {
  164. if ( $file == '..' || $file == '.' || !stristr($file, '.') || $file == 'css-gen.cfg' ) continue;
  165. $lang = substr($file, 0, strpos($file, '.'));
  166. $languages[] = $lang;
  167. }
  168. closedir($dir);
  169. sort($languages);
  170. foreach ($languages as $lang) {
  171. echo '<option value="' . $lang . '">' . $lang . "</option>\n";
  172. }
  173. ?>
  174. </select><br />
  175. <input type="submit" name="submit" value="Highlight Source">
  176. </form>
  177. <div id="footer">GeSHi &copy; Nigel McNie, 2004, released under the GNU GPL<br />
  178. For a better demonstration, check out the <a href="http://qbnz.com/highlighter/demo.php">online demo</a>
  179. </body>
  180. </html>