Pelzini

This is the code documentation for the Pelzini project

source of /viewer/controllers/file_source.php

Shows the source of a specific file
  1. <?php
  2. /*
  3. Copyright 2008 Josh Heidenreich
  4.  
  5. This file is part of Pelzini.
  6.  
  7. Pelzini is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation, either version 3 of the License, or
  10. (at your option) any later version.
  11.  
  12. Pelzini is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Pelzini. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20.  
  21. /**
  22.  * Shows the source of a specific file
  23.  *
  24.  * @package Viewer
  25.  * @author Josh Heidenreich
  26.  * @since 0.1
  27.  * @see ParserFile
  28.  * @tag i18n-done
  29.  **/
  30.  
  31.  
  32. require_once 'functions.php';
  33. require_once 'geshi/geshi.php';
  34.  
  35.  
  36. // Get the details of this file
  37. $sql_name = db_quote($_GET['name']);
  38. $q = "SELECT name, description, source FROM files WHERE name = {$sql_name} AND projectid = {$project['id']} LIMIT 1";
  39. $res = db_query ($q);
  40. $file = db_fetch_assoc ($res);
  41.  
  42.  
  43. if ($file == null) {
  44. require_once 'head.php';
  45. echo '<h2>', str(STR_ERROR_TITLE), '</h2>';
  46. echo '<p>', str(STR_FILE_INVALID), '</p>';
  47. require_once 'foot.php';
  48. return;
  49. }
  50.  
  51.  
  52. $skin['page_name'] = str(STR_FILE_SOURCE_BROWSER_TITLE, 'name', $file['name']);
  53. require_once 'head.php';
  54.  
  55. echo '<h2>', str(STR_FILE_SOURCE_PAGE_TITLE, 'name', $file['name']), '</h2>';
  56. echo process_inline($file['description']);
  57.  
  58. // Set up code highlight settings
  59. $geshi = new GeSHi($file['source'], 'php');
  60. $geshi->enable_classes();
  61. $geshi->set_overall_id('src-lines');
  62. $geshi->enable_ids();
  63. $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
  64. $geshi->set_line_style('background: #f8f8f8;');
  65.  
  66. // Line highlighting
  67. if (!empty($_GET['highlight'])) {
  68. $line_numbers = array();
  69.  
  70. $parts = explode(',', $_GET['highlight']);
  71. foreach ($parts as $line) {
  72. $line = explode('-', $line);
  73. if (count($line) == 1) {
  74. $line_numbers[] = $line[0];
  75. } else if (count($line) == 2) {
  76. $line_numbers[] = array_merge($line_numbers, range($line[0], $line[1]));
  77. }
  78. }
  79.  
  80. $geshi->highlight_lines_extra($line_numbers);
  81. }
  82.  
  83. // Output highlighted code
  84. echo '<style type="text/css">', $geshi->get_stylesheet(), '</style>';
  85. echo $geshi->parse_code();
  86.  
  87. require_once 'foot.php';
  88.  
  89.