aliased.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * Another GeSHi example script
  4. *
  5. * Configure your Apache server with 'AcceptPathInfo true' and something like
  6. * 'Alias /viewmysource /var/www/geshi/contrib/aliased.php'. Don't forget
  7. * to protect this alias as necessary.
  8. *
  9. * Usage - visit /viewmysource/file.name.ext to see that file with syntax
  10. * highlighting, where "viewmysource" is the name of the alias you set up.
  11. * You can use this without an alias too, just by visiting
  12. * aliased.php/file.name.ext.
  13. *
  14. * @author Ross Golder <ross@golder.org>
  15. * @version $Id: aliased.php 881 2007-01-10 11:14:38Z oracleshinoda $
  16. */
  17. // Your config here
  18. define("SOURCE_ROOT", "/var/www/your/source/root/");
  19. // Assume you've put geshi in the include_path already
  20. require_once("geshi.php");
  21. // Get path info
  22. $path = SOURCE_ROOT.$_SERVER['PATH_INFO'];
  23. // Check for dickheads trying to use '../' to get to sensitive areas
  24. $base_path_len = strlen(SOURCE_ROOT);
  25. $real_path = realpath($path);
  26. if(strncmp($real_path, SOURCE_ROOT, $base_path_len)) {
  27. exit("Stop that.");
  28. }
  29. // Check file exists
  30. if(!file_exists($path)) {
  31. exit("File not found ($path).");
  32. }
  33. // Gather contents
  34. $contents = file_get_contents($path);
  35. // Prepare GeSHi instance
  36. $geshi =& new GeSHi($contents, "PHP");
  37. $geshi->set_header_type(GESHI_HEADER_PRE);
  38. $geshi->enable_classes();
  39. $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 10);
  40. $geshi->set_overall_style('color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0;', true);
  41. $geshi->set_line_style('font: normal normal 95% \'Courier New\', Courier, monospace; color: #003030;', 'font-weight: bold; color: #006060;', true);
  42. $geshi->set_code_style('color: #000020;', 'color: #000020;');
  43. $geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
  44. $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
  45. $geshi->set_header_content('Source code viewer');
  46. $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;');
  47. $geshi->set_footer_content('Parsed in <TIME> seconds, using GeSHi <VERSION>');
  48. $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;');
  49. ?>
  50. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  51. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  52. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  53. <head>
  54. <title>Source code viewer - <?php echo $path; ?></title>
  55. <style type="text/css">
  56. <!--
  57. <?php
  58. // Output the stylesheet. Note it doesn't output the <style> tag
  59. echo $geshi->get_stylesheet();
  60. ?>
  61. html {
  62. background-color: #f0f0f0;
  63. }
  64. body {
  65. font-family: Verdana, Arial, sans-serif;
  66. margin: 10px;
  67. border: 2px solid #e0e0e0;
  68. background-color: #fcfcfc;
  69. padding: 5px;
  70. }
  71. h2 {
  72. margin: .1em 0 .2em .5em;
  73. border-bottom: 1px solid #b0b0b0;
  74. color: #b0b0b0;
  75. font-weight: normal;
  76. font-size: 150%;
  77. }
  78. h3 {
  79. margin: .1em 0 .2em .5em;
  80. color: #b0b0b0;
  81. font-weight: normal;
  82. font-size: 120%;
  83. }
  84. #footer {
  85. text-align: center;
  86. font-size: 80%;
  87. color: #a9a9a9;
  88. }
  89. #footer a {
  90. color: #9999ff;
  91. }
  92. textarea {
  93. border: 1px solid #b0b0b0;
  94. font-size: 90%;
  95. color: #333;
  96. margin-left: 20px;
  97. }
  98. select, input {
  99. margin-left: 20px;
  100. }
  101. p {
  102. font-size: 90%;
  103. margin-left: .5em;
  104. }
  105. -->
  106. </style>
  107. </head>
  108. <body>
  109. <?php
  110. // The fun part :)
  111. echo $geshi->parse_code();
  112. ?>
  113. <hr/>
  114. </body>
  115. </html>