[phpwebapp-commits] CVS: web_app/boxes/codeViewer codeViewer.php,1.6,1.7
Brought to you by:
dashohoxha
From: Dashamir H. <das...@us...> - 2004-07-22 16:25:52
|
Update of /cvsroot/phpwebapp/web_app/boxes/codeViewer In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9224/boxes/codeViewer Modified Files: codeViewer.php Log Message: reformated and modified the copyleft notice Index: codeViewer.php =================================================================== RCS file: /cvsroot/phpwebapp/web_app/boxes/codeViewer/codeViewer.php,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** codeViewer.php 25 Aug 2003 13:18:35 -0000 1.6 --- codeViewer.php 22 Jul 2004 16:25:39 -0000 1.7 *************** *** 1,21 **** <?php /* ! Copyright 2001,2002,2003 Dashamir Hoxha, das...@us... ! This file is part of phpWebApp. ! phpWebApp is free software; you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation; either version 2 of the License, or ! (at your option) any later version. ! phpWebApp is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! You should have received a copy of the GNU General Public License ! along with phpWebApp; if not, write to the Free Software ! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ --- 1,22 ---- <?php /* ! This file is part of phpWebApp, which is a framework for building web ! application based on relational databases. ! Copyright 2001,2002,2003,2004 Dashamir Hoxha, das...@us... ! phpWebApp is free software; you can redistribute it and/or modify it ! under the terms of the GNU General Public License as published by the ! Free Software Foundation; either version 2 of the License, or (at your ! option) any later version. ! phpWebApp is distributed in the hope that it will be useful, but ! WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ! General Public License for more details. ! You should have received a copy of the GNU General Public License ! along with phpWebApp; if not, write to the Free Software Foundation, ! Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ *************** *** 28,43 **** { function onRender() ! { ! $file = $this->getSVar("codeFile"); ! $lines = $this->getSVar("showLines"); ! if ($lines==UNDEFINED) $lines=""; ! $highlights = $this->getSVar("highlightLines"); ! if ($highlights==UNDEFINED) $highlights=""; ! $this->add_line_recordset($file, $show_nr, $lines, $highlights); ! $show_nr = $this->getSVar("showLineNr"); ! if ($show_nr==UNDEFINED) $show_nr=false; ! WebApp::addVar("show_nr", ($show_nr ? "true" : "false")); ! } /** --- 29,44 ---- { function onRender() ! { ! $file = $this->getSVar("codeFile"); ! $lines = $this->getSVar("showLines"); ! if ($lines==UNDEFINED) $lines=""; ! $highlights = $this->getSVar("highlightLines"); ! if ($highlights==UNDEFINED) $highlights=""; ! $this->add_line_recordset($file, $show_nr, $lines, $highlights); ! $show_nr = $this->getSVar("showLineNr"); ! if ($show_nr==UNDEFINED) $show_nr=false; ! WebApp::addVar("show_nr", ($show_nr ? "true" : "false")); ! } /** *************** *** 46,128 **** */ function add_line_recordset($file, $show_nr, $lines, $highlights) ! { ! ////create a code colorizer object ! //$highlighter = $this->initColorizer(); ! $code_lines = file($file); ! if ($lines=="") //display all the lines ! { ! $display_ranges[] = array("start"=>1, "end"=>sizeof($code_lines) ); ! } ! else ! { ! $display_ranges = $this->getRanges($lines); ! } ! $highlight_ranges = $this->getRanges($highlights); ! $rs = new EditableRS("lines"); ! //for each range of lines ! $nr_ranges = sizeof($display_ranges); ! for ($r=1; $r <= $nr_ranges; $r++) ! { ! $range = $display_ranges[$r-1]; ! $start_line = $range["start"]; ! $end_line = $range["end"]; ! //for each line in the range ! for ($line_nr=$start_line; $line_nr<=$end_line; $line_nr++) ! { ! $line = $code_lines[$line_nr-1]; ! $html_line = $this->get_html_line($line); ! //if the line is highlighted use other styles ! if ($this->inRange($line_nr, $highlight_ranges)) ! { ! $cssClass_nr = "codeViewer-nr-highlighted"; ! $cssClass_line = "codeViewer-line-highlighted"; ! } ! else ! { ! $cssClass_nr = "codeViewer-nr"; ! $cssClass_line = "codeViewer-line"; ! } ! //add line to recordset ! $rec = array( ! "nr" => $line_nr, ! "class-nr" => $cssClass_nr, ! "line" => $html_line, ! "class-line" => $cssClass_line ! ); ! $rs->addRec($rec); ! } ! //add a separating line after each range ! //(except for the last one) ! if ($r < $nr_ranges) ! { ! $rec = array( ! "nr" => "--", ! "class-nr" => "codeViewer-nr", ! "line" => "----------", ! "class-line" => "codeViewer-line" ! ); ! $rs->addRec($rec); ! } ! } ! global $webPage; ! $webPage->addRecordset($rs); ! } function get_html_line($line) ! { ! $line = chop($line); ! $line = str_replace("\t", " ", $line); ! $line = str_replace("{{", "{{#", $line); ! $line = htmlentities($line); ! if ($line=="") $line=" "; ! return $line; ! } /** --- 47,129 ---- */ function add_line_recordset($file, $show_nr, $lines, $highlights) ! { ! ////create a code colorizer object ! //$highlighter = $this->initColorizer(); ! $code_lines = file($file); ! if ($lines=="") //display all the lines ! { ! $display_ranges[] = array("start"=>1, "end"=>sizeof($code_lines) ); ! } ! else ! { ! $display_ranges = $this->getRanges($lines); ! } ! $highlight_ranges = $this->getRanges($highlights); ! $rs = new EditableRS("lines"); ! //for each range of lines ! $nr_ranges = sizeof($display_ranges); ! for ($r=1; $r <= $nr_ranges; $r++) ! { ! $range = $display_ranges[$r-1]; ! $start_line = $range["start"]; ! $end_line = $range["end"]; ! //for each line in the range ! for ($line_nr=$start_line; $line_nr<=$end_line; $line_nr++) ! { ! $line = $code_lines[$line_nr-1]; ! $html_line = $this->get_html_line($line); ! //if the line is highlighted use other styles ! if ($this->inRange($line_nr, $highlight_ranges)) ! { ! $cssClass_nr = "codeViewer-nr-highlighted"; ! $cssClass_line = "codeViewer-line-highlighted"; ! } ! else ! { ! $cssClass_nr = "codeViewer-nr"; ! $cssClass_line = "codeViewer-line"; ! } ! //add line to recordset ! $rec = array( ! "nr" => $line_nr, ! "class-nr" => $cssClass_nr, ! "line" => $html_line, ! "class-line" => $cssClass_line ! ); ! $rs->addRec($rec); ! } ! //add a separating line after each range ! //(except for the last one) ! if ($r < $nr_ranges) ! { ! $rec = array( ! "nr" => "--", ! "class-nr" => "codeViewer-nr", ! "line" => "----------", ! "class-line" => "codeViewer-line" ! ); ! $rs->addRec($rec); ! } ! } ! global $webPage; ! $webPage->addRecordset($rs); ! } function get_html_line($line) ! { ! $line = chop($line); ! $line = str_replace("\t", " ", $line); ! $line = str_replace("{{", "{{#", $line); ! $line = htmlentities($line); ! if ($line=="") $line=" "; ! return $line; ! } /** *************** *** 131,146 **** */ function getRanges($line_ranges) ! { ! $ranges = explode(",", $line_ranges); ! while (list($i,$range) = each($ranges)) ! { ! list($start,$end) = explode("-", $range); ! if ($end=="") $end = $start; ! $arr_ranges[$i]["start"] = $start; ! $arr_ranges[$i]["end"] = $end; ! } ! return $arr_ranges; ! } /** --- 132,147 ---- */ function getRanges($line_ranges) ! { ! $ranges = explode(",", $line_ranges); ! while (list($i,$range) = each($ranges)) ! { ! list($start,$end) = explode("-", $range); ! if ($end=="") $end = $start; ! $arr_ranges[$i]["start"] = $start; ! $arr_ranges[$i]["end"] = $end; ! } ! return $arr_ranges; ! } /** *************** *** 149,178 **** */ function inRange($number, $arr_ranges) ! { ! while (list($i,$range) = each($arr_ranges)) ! { ! $start = $range["start"]; ! $end = $range["end"]; ! if (($number >= $start) and ($number <= $end)) ! { ! return true; ! } ! } ! return false; ! } /** load, initialize and return the code colorizer */ function initColorizer() ! { ! global $BEAUT_PATH; ! $BEAUT_PATH = CODEVIEWER_PATH."codeColorizer"; ! require_once "$BEAUT_PATH/Beautifier/Core.php"; ! require_once "$BEAUT_PATH/HFile/HFile_mixedphp.php"; ! require_once "$BEAUT_PATH/Output/Output_HTML.php"; ! $highlighter = new Core(new HFile_plain(), new Output_HTML()); ! return $highlighter; ! } } ?> \ No newline at end of file --- 150,179 ---- */ function inRange($number, $arr_ranges) ! { ! while (list($i,$range) = each($arr_ranges)) ! { ! $start = $range["start"]; ! $end = $range["end"]; ! if (($number >= $start) and ($number <= $end)) ! { ! return true; ! } ! } ! return false; ! } /** load, initialize and return the code colorizer */ function initColorizer() ! { ! global $BEAUT_PATH; ! $BEAUT_PATH = CODEVIEWER_PATH."codeColorizer"; ! require_once "$BEAUT_PATH/Beautifier/Core.php"; ! require_once "$BEAUT_PATH/HFile/HFile_mixedphp.php"; ! require_once "$BEAUT_PATH/Output/Output_HTML.php"; ! $highlighter = new Core(new HFile_plain(), new Output_HTML()); ! return $highlighter; ! } } ?> \ No newline at end of file |