/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk

« back to all changes in this revision

Viewing changes to Code Viewer Alt/Codeviewer/showcode.php

  • Committer: Gustav Hartvigsson
  • Date: 2013-04-12 19:13:58 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20130412191358-lvnmll48cw7idkzk
added:
* COPYING - licensing information
* COPYRIGHT_HEADER - the header that should be in every file related to
  the project.
* README - Information about the project.
* lgpl-3.0 - The license that is used by this project.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
        function menulayout($forward, $backward, $downloadlink, $heading, $headinglink, $filecontent) {
 
4
                echo "<body onload='resize();' onresize='resize();'>";
 
5
                echo "<script language=\"javascript\" src=\"../../js/jquery.js\"></script>";
 
6
 
 
7
                echo "<div class='Topmenu'>";
 
8
                        echo "<table style='width:100%;height:100%;border:solid 1px;'>";
 
9
                                echo "<tr>";
 
10
                                        echo "<td class='buttonstyle'>";
 
11
                                                echo "<a href='http://wwwlab.iki.his.se/~gush/Webbprogrammering/' title='Back to examples page'><img src='../../media/codevieweralt/back.png'></a>";
 
12
                                        echo "</td>";
 
13
                                        
 
14
                                        if($backward != "") {
 
15
                                                echo "<td class='buttonstyle'>";
 
16
                                                        echo "<a href='".$backward."'><img src='../../media/codeviewer/CodeViewerLeftbutton.png'></a>";
 
17
                                                echo "</td>";
 
18
                                        }
 
19
                                        
 
20
                                        if($forward != "") {
 
21
                                                echo "<td class='buttonstyle'>";
 
22
                                                        echo "<a href='".$forward."'><img src='../../media/codeviewer/CodeViewerRightbutton.png'></a>";
 
23
                                                echo "</td>";
 
24
                                        }
 
25
 
 
26
                                        echo "<td class='verticalaligntext'>";
 
27
                                                echo "<a STYLE='text-decoration:none'>".$heading."</a>";
 
28
                                        echo "</td>";
 
29
 
 
30
                                        echo "<td class='buttonstyle'>";
 
31
                                                echo "<a href=\"$headinglink\"><img src='../img/play.png'></a>";
 
32
                                        echo "</td>";
 
33
 
 
34
                                        echo "<td class='buttonstyle'>";
 
35
                                                echo "<img src='../img/code.png' onclick=\"$('.lineno').toggle();$('.linenointeresting').toggle();$('.panel').toggle();\">";
 
36
                                        echo "</td>";
 
37
 
 
38
                                echo "</tr>";
 
39
                        echo "</table>";
 
40
 
 
41
                echo "</div>";
 
42
 
 
43
                echo "<div id='bottom' class='RestContainer'>";
 
44
 
 
45
                echo "<div style='float:left;'>";
 
46
                echo "<div id='panel' class='panel' onmousemove='resizepanel(event)' onmousedown='mdpanel(event)' onmouseup='mupanel(event)'>";
 
47
                        include($filecontent);
 
48
                echo "</div>";
 
49
                echo "</div>";
 
50
                echo "<div class='codecontent'>";
 
51
        }
 
52
 
 
53
        function menulayoutend() {
 
54
                echo "</div>";
 
55
                echo "</div>";
 
56
                echo "<div style='clear:both;'></div>";
 
57
                echo "</body>";
 
58
        }
 
59
 
 
60
        function showfile($interestingrows, $keywords, $highlight, $filename) {
 
61
                echo "<pre>";
 
62
                $handle = @fopen($filename, "r");
 
63
                if ($handle) {
 
64
                        $lineno = 1;
 
65
                        while (($buffer = fgets($handle, 4096)) !== false) {
 
66
                                $buffer = str_replace("\n", "", $buffer);
 
67
                                $buffer = str_replace("\r", "", $buffer);
 
68
                                $buffer = str_pad($buffer, 150, " ", STR_PAD_RIGHT);
 
69
                                $buffer = str_replace("<", "&lt;", $buffer);
 
70
                                $buffer = str_replace(">", "&gt;", $buffer);
 
71
                                $buffer = str_replace("\t", "&nbsp;" , $buffer);
 
72
 
 
73
                                $interesting = 0;
 
74
                                $startspan = 0;
 
75
                                foreach($interestingrows as $row) {
 
76
                                        if($lineno >= $row[0] && $lineno <= $row[1]){
 
77
                                                $interesting = true;
 
78
                                        }
 
79
                                }
 
80
 
 
81
                                foreach($keywords as $keyword) {
 
82
                                        if($interesting) {
 
83
                                                $buffer = str_replace($keyword, "<span class='keywordinteresting'>".$keyword."</span>", $buffer);
 
84
                                        } else {
 
85
                                                $buffer = str_replace($keyword, "<span class='keyword'>".$keyword."</span>", $buffer);
 
86
                                        }
 
87
                                }
 
88
 
 
89
                                $commentpos = strpos($buffer, "//");
 
90
                                if(!$commentpos) {
 
91
                                        $commentpos = 5000;
 
92
                                }
 
93
                                foreach($highlight as $highlightkeyword) {
 
94
                                        $foundpos = strpos($buffer, $highlightkeyword[0]);
 
95
                                        if($foundpos <= $commentpos) {
 
96
                                                $buffer = str_replace($highlightkeyword[0], "<span class='".$highlightkeyword[1]."'>".$highlightkeyword[0]."</span>", $buffer);
 
97
                                        }
 
98
                                }
 
99
 
 
100
                                if($commentpos < 5000) {
 
101
                                        $buffer = str_replace("//","<span class='commented'>//", $buffer);
 
102
                                        $buffer .= "</span>";
 
103
                                }
 
104
 
 
105
                                $linenostr = $lineno;
 
106
                                $linenostr = str_pad($linenostr, 3, " ", STR_PAD_RIGHT);
 
107
 
 
108
                                if($interesting) {
 
109
                                        echo "<span class='interesting'>";
 
110
                                        echo "<span class='linenointeresting'>".$linenostr."</span>&nbsp;";
 
111
                                        $startspan = 1;
 
112
                                } else {
 
113
                                        echo "<span class='lineno'>".$linenostr."</span>&nbsp;";                                
 
114
                                }
 
115
 
 
116
                                echo $buffer;
 
117
 
 
118
                                if($startspan) {
 
119
                                        echo "</span>";
 
120
                                }
 
121
                                $lineno++;
 
122
 
 
123
                                echo "<br>";
 
124
                        }
 
125
                        if (!feof($handle)) {
 
126
                                echo "Error: unexpected fgets() fail\n";
 
127
                        }
 
128
                        fclose($handle);
 
129
                }
 
130
                echo "</pre>";  
 
131
        }
 
132
?>