/lenasys/0.1

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

« back to all changes in this revision

Viewing changes to trunk/CodeViewer/Codeviewer/showcode.php

  • Committer: gustav.hartvigsson at gmail
  • Date: 2013-04-02 13:00:31 UTC
  • mfrom: (4.7.8 GammaBear)
  • Revision ID: gustav.hartvigsson@gmail.com-20130402130031-442y89s0cfzmw3r2
Merged stuff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
 
 
3
 
        function menulayout($forward,$backward,$downloadlink,$heading,$headinglink,$filecontent)
4
 
        {
5
 
                        echo "<body onload='resize();' onresize='resize();'>";
6
 
 
7
 
echo "<div class='Topmenu'>";
8
 
                        echo "<table style='width:100%;height:100%;border:solid 1px;'>";
9
 
                        echo "<tr>";
10
 
 
11
 
                        echo "<td class='buttonstyle'>";
12
 
                        if($backward!=""){
13
 
                                        echo "<a href='".$backward."'><img src='CodeViewerLeftbutton.png'></a>";
14
 
                        }else{
15
 
                                        echo "<img src='CodeViewerLeftbuttonGrayed.png'>";
16
 
                        }
17
 
                        echo "</td>";
18
 
 
19
 
                        echo "<td class='buttonstyle'>";
20
 
                        if($forward!=""){
21
 
                                        echo "<a href='".$forward."'><img src='CodeViewerRightbutton.png'></a>";
22
 
                        }else{
23
 
                                        echo "<img src='CodeViewerLeftbuttonGrayed.png'>";
24
 
                        }
25
 
                        echo "</td>";
26
 
 
27
 
                        echo "<td class='buttonstyle'>";
28
 
                                        echo "<a href='../Lindex.html'><img src='CodeViewerRightbutton.png'></a>";
29
 
                        echo "</td>";
30
 
 
31
 
                        echo "<td class='verticalaligntext'>";
32
 
                        echo "<a STYLE='text-decoration:none' href='".$headinglink."'>".$heading."</a>";
33
 
                        echo "</td>";
34
 
 
35
 
                        echo "<td class='buttonstyle'>";
36
 
                        if($downloadlink!=""){
37
 
                                        echo "<a href='".$downloadlink."'><img src='CodeViewerDownloadbutton.png'></a>";
38
 
                        }else{
39
 
                                        echo "<img src='CodeViewerLeftbuttonGrayed.png'>";
40
 
                        }
41
 
                        echo "</td>";
42
 
 
43
 
                        echo "</tr>";
44
 
                        echo "</table>";
45
 
 
46
 
echo "</div>";
47
 
 
48
 
echo "<div id='bottom' class='RestContainer'>";
49
 
 
50
 
                        echo "<div style='float:left;'>";
51
 
                                        echo "<div id='panel' class='panel' onmousemove='resizepanel(event)' onmousedown='mdpanel(event)' onmouseup='mupanel(event)'>";
52
 
 
53
 
                                        include($filecontent);
54
 
                        
55
 
                                        echo "</div>";
56
 
                        echo "</div>";
57
 
                        echo "<div class='codecontent'>";
58
 
        }
59
 
 
60
 
        function menulayoutend()
61
 
        {
62
 
                echo "</div>";
63
 
                echo "</div>";
64
 
                echo "<div style='clear:both;'></div>";
65
 
                echo "</body>";
66
 
        }
67
 
 
68
 
        function showfile($interestingrows,$keywords,$highlight,$filename)
69
 
        {
70
 
                        echo "<pre>";
71
 
                        $handle = @fopen($filename, "r");
72
 
                        if ($handle) {
73
 
                                        $lineno=1;
74
 
                                        
75
 
                                        $commentkind=0;
76
 
                                        $commenton=0;
77
 
                                        
78
 
                            while (($buffer = fgets($handle, 4096)) !== false) {
79
 
                                                        $buffer = str_replace("\n","", $buffer);
80
 
                                                        $buffer = str_replace("\r","", $buffer);
81
 
                                                        $buffer=str_pad($buffer,150," ", STR_PAD_RIGHT);
82
 
                                $buffer=str_replace("&","&amp;",$buffer);
83
 
                                $buffer=str_replace("<","&lt;",$buffer);
84
 
                                $buffer=str_replace(">","&gt;",$buffer);
85
 
                                $buffer=str_replace("\t","&nbsp;",$buffer);
86
 
                                                                
87
 
                                                        $interesting=0;
88
 
                                $startspan=0;
89
 
                                foreach($interestingrows as $row){
90
 
                                                if($lineno>=$row[0]&&$lineno<=$row[1]){
91
 
                                                                                                $interesting=true;
92
 
                                                }
93
 
                                }
94
 
 
95
 
                                foreach($keywords as $keyword){
96
 
                                                                        if($interesting){
97
 
                                                                                        $buffer=str_replace($keyword,"<span class='keywordinteresting'>".$keyword."</span>",$buffer);
98
 
                                                                        }else{
99
 
                                                                                        $buffer=str_replace($keyword,"<span class='keyword'>".$keyword."</span>",$buffer);
100
 
                                                                        }
101
 
                                }
102
 
                                
103
 
                                                        // Detect comments - 0 == No comment 1 == Line comment 2 == Start Comment 3 == End Comment
104
 
                                                        $commentkind=0;
105
 
 
106
 
                                                        $commentpos=strpos($buffer,"/*");
107
 
                                                        
108
 
                                                        if($commentpos>=0){
109
 
                                                                        $subby=substr($buffer,$commentpos+2,1);
110
 
                                                        }else{
111
 
                                                                        $subby="Foo";
112
 
                                                        }
113
 
                                                        
114
 
                                                        if($commentpos&&$subby!='"'){
115
 
                                                                        $commentkind=2;
116
 
                                                                        $commenton=1;
117
 
                                                        }                                                       
118
 
 
119
 
                                                        $commentpos=strpos($buffer,"*/");
120
 
                                                        if($commentpos){
121
 
                                                                        $commentkind=3;
122
 
                                                                        $commenton=0;
123
 
                                                        }                                                       
124
 
 
125
 
                                                        $commentpos=strpos($buffer,"//");
126
 
                                                        if($commentpos){
127
 
                                                                        $commentkind=1;
128
 
                                                                        $commenton=0;
129
 
                                                        }                                                       
130
 
 
131
 
                                foreach($highlight as $highlightkeyword){
132
 
                                                                                $foundpos=strpos($buffer,$highlightkeyword[0]);
133
 
                                                                                
134
 
                                                                                // If line comment and keyword before comment marker
135
 
                                                                                if(($foundpos<=$commentpos&&($commentkind==1||$commentkind==2))||($commentkind==0)||($foundpos>$commentpos&&$commentkind==3)){
136
 
                                                                                        if(!($commentkind==0&&$commenton==1)) $buffer=str_replace($highlightkeyword[0],"<span class='".$highlightkeyword[1]."'>".$highlightkeyword[0]."</span>",$buffer);
137
 
                                                                                }
138
 
 
139
 
                                }
140
 
 
141
 
                                                        // echo $commentkind.$commenton;
142
 
                               
143
 
                                if($commentkind>0){
144
 
                                                                        if($commentkind==1){
145
 
                                                                                        $buffer=str_replace("//","<span class='commented'>//",$buffer);
146
 
                                                                                        $buffer.="</span>";
147
 
                                                                        }
148
 
                                                                        if($commentkind==2) $buffer=str_replace("/*","<span class='commented'>/*",$buffer);
149
 
                                                                        if($commentkind==3) $buffer=str_replace("*/","*/</span>",$buffer);
150
 
                                }
151
 
 
152
 
                        
153
 
                                                        $linenostr=$lineno;
154
 
                                                        $linenostr=str_pad($linenostr,3," ",STR_PAD_RIGHT);
155
 
                        
156
 
                                                        if($interesting){
157
 
                                                echo "<span class='interesting'>";
158
 
                                                echo "<span class='linenointeresting'>".$linenostr."</span>&nbsp;";
159
 
                                                        $startspan=1;
160
 
                                                        }else{
161
 
                                                echo "<span class='lineno'>".$linenostr."</span>&nbsp;";                                
162
 
                                                        }
163
 
                        
164
 
                                echo $buffer;
165
 
                        
166
 
                                                        if($startspan) echo "</span>";
167
 
                        
168
 
                                $lineno++;
169
 
 
170
 
                                echo "<br>";
171
 
                            }
172
 
                            if (!feof($handle)) {
173
 
                                echo "Error: unexpected fgets() fail\n";
174
 
                            }
175
 
                            fclose($handle);
176
 
                        }
177
 
                        echo "</pre>";  
 
2
        /* function menulayout
 
3
         * Takes 6 arguments and outputs a HTML navigation menu 
 
4
         * $forward = link to "next page", i.e. "nextPage.html"
 
5
         * $backward = link to "previous page", i.e. "previousPage.html"
 
6
         * $downloadlink = link to download source file, on download button, i.e. "sourceFile.txt"
 
7
         * headinglink = link in heading, i.e. "sourceFile.txt"
 
8
         * filecontent = file containing info in the left panel, i.e. "panelContent.txt"
 
9
        */
 
10
        function menulayout($forward,$backward,$downloadlink,$heading,$headinglink,$filecontent) {
 
11
                if($backward != ""){
 
12
                        $backwardButton = "<a href='".$backward."'><img src='CodeViewerLeftbutton.png'></a>";
 
13
                }else{
 
14
                        $backwardButton = "<img src='CodeViewerLeftbuttonGrayed.png'>";
 
15
                }
 
16
 
 
17
                if($forward != ""){
 
18
                        $forwardButton = "<a href='".$forward."'><img src='CodeViewerRightbutton.png'></a>";
 
19
                }else{
 
20
                        $forwardButton = "<img src='CodeViewerLeftbuttonGrayed.png'>";
 
21
                }
 
22
 
 
23
                if($downloadlink != ""){
 
24
                        $downloadButton = "<a href='".$downloadlink."'><img src='CodeViewerDownloadbutton.png'></a>";
 
25
                }else{
 
26
                        $downloadButton = "<img src='CodeViewerLeftbuttonGrayed.png'>";
 
27
                }
 
28
 
 
29
                ?>
 
30
                <body onload='resize();' onresize='resize();'>
 
31
                        <div class='Topmenu'>
 
32
                                <table style='width:100%;height:100%;border:solid 1px;'>
 
33
                                        <tr>
 
34
                                                <td class="buttonstyle">
 
35
                                                        <?=$backwardButton;?>
 
36
                                                </td>
 
37
                                                <td class='buttonstyle'>
 
38
                                                        <?=$forwardButton;?>
 
39
                                                </td>
 
40
                                                <td class="buttonstyle">
 
41
                                                        <a href='../Lindex.html'><img src='CodeViewerRightbutton.png'></a>
 
42
                                                </td>
 
43
                                                <td class="verticalaligntext">
 
44
                                                        <a href="<?=$headinglink;?>" style="text-decoration: none"><?=$heading;?></a>
 
45
                                                </td>
 
46
                                                <td class='buttonstyle'>
 
47
                                                        <?=$downloadButton;?>
 
48
                                                </td>
 
49
                                        </tr>
 
50
                                </table>
 
51
                        </div>
 
52
                        <div id="bottom" class="restContainer">
 
53
                                <div style="float: left;">
 
54
                                        <div id="panel" class="panel" onmousemove='resizepanel(event)' onmousedown='mdpanel(event)' onmouseup='mupanel(event)'>
 
55
                                                <?php include($filecontent); ?>
 
56
                                        </div>
 
57
                                </div>
 
58
                                <div class="codecontent">
 
59
                <?php
 
60
        }
 
61
 
 
62
        /* function menulayoutend
 
63
         * Outputs ending tags in HTML
 
64
         */
 
65
        function menulayoutend() {
 
66
                ?>
 
67
                                </div>
 
68
                        </div>
 
69
                        <div style="clear: both;"></div>
 
70
                </body>
 
71
                <?php
 
72
        }
 
73
 
 
74
        /* function showfile 
 
75
         * Outputs html with syntax highlighting.
 
76
         * Takes 4 arguments_
 
77
         * interestingrows: array containing arrays, each with 3 set values -- start line number, end line number, comment
 
78
         * keywords: array containing keywords 
 
79
         * highlight: array containing arrays, each with two values - string to highlight, and HTML class to apply to highlight */
 
80
        function showfile($interestingrows,$keywords,$highlight,$filename) {
 
81
                echo "<pre>";
 
82
                $handle = @fopen($filename, "r");
 
83
                if ($handle) {
 
84
 
 
85
                        $lineno = 1;
 
86
                        $commentkind = 0;
 
87
                        $commenton = 0;
 
88
 
 
89
                        while (($buffer = fgets($handle, 4096)) !== false) {
 
90
                                $buffer = str_replace("\n","", $buffer);
 
91
                                $buffer = str_replace("\r","", $buffer);
 
92
                                $buffer=str_pad($buffer,150," ", STR_PAD_RIGHT);
 
93
                                $buffer=str_replace("&","&amp;",$buffer);
 
94
                                $buffer=str_replace("<","&lt;",$buffer);
 
95
                                $buffer=str_replace(">","&gt;",$buffer);
 
96
                                $buffer=str_replace("\t","&nbsp;",$buffer);
 
97
 
 
98
                                $interesting = 0;
 
99
                                $startspan = 0;
 
100
                                foreach($interestingrows as $row){
 
101
                                        if($lineno >= $row[0] && $lineno <= $row[1]){
 
102
                                                $interesting = true;
 
103
                                        }
 
104
                                }
 
105
 
 
106
                                foreach($keywords as $keyword){
 
107
                                        if($interesting){
 
108
                                                $buffer = str_replace($keyword,"<span class='keywordinteresting'>".$keyword."</span>", $buffer);
 
109
                                        }else{
 
110
                                                $buffer = str_replace($keyword,"<span class='keyword'>".$keyword."</span>", $buffer);
 
111
                                        }
 
112
                                }
 
113
 
 
114
                                // Detect comments - 0 == No comment 1 == Line comment 2 == Start Comment 3 == End Comment
 
115
                                $commentkind = 0;
 
116
                                $commentpos = strpos($buffer,"/*");
 
117
 
 
118
                                if($commentpos >= 0){
 
119
                                        $subby = substr($buffer,$commentpos+2,1);
 
120
                                }else{
 
121
                                        $subby = "Foo";
 
122
                                }
 
123
 
 
124
                                if($commentpos && $subby != '"'){
 
125
                                        $commentkind = 2;
 
126
                                        $commenton = 1;
 
127
                                }                                                       
 
128
 
 
129
                                $commentpos = strpos($buffer,"*/");
 
130
 
 
131
                                if($commentpos){
 
132
                                        $commentkind = 3;
 
133
                                        $commenton = 0;
 
134
                                }                                                       
 
135
 
 
136
                                $commentpos=strpos($buffer,"//");
 
137
 
 
138
                                if($commentpos){
 
139
                                        $commentkind = 1;
 
140
                                        $commenton = 0;
 
141
                                }                                                       
 
142
 
 
143
                                foreach($highlight as $highlightkeyword){
 
144
                                        $foundpos = strpos($buffer, $highlightkeyword[0]);
 
145
 
 
146
                                        // If line comment and keyword before comment marker
 
147
                                        if(($foundpos <= $commentpos && ($commentkind == 1 || $commentkind == 2)) || ($commentkind == 0) || ($foundpos > $commentpos && $commentkind == 3)) {
 
148
                                                if(!($commentkind==0&&$commenton==1)) {
 
149
                                                        $buffer = str_replace($highlightkeyword[0],"<span class='".$highlightkeyword[1]."'>".$highlightkeyword[0]."</span>",$buffer);
 
150
                                                }
 
151
                                        }
 
152
 
 
153
                                }
 
154
 
 
155
                                // echo $commentkind.$commenton;
 
156
                                if($commentkind > 0){
 
157
                                        if($commentkind == 1){
 
158
                                                $buffer = str_replace("//","<span class='commented'>//",$buffer);
 
159
                                                $buffer .= "</span>";
 
160
                                        }
 
161
                                        if($commentkind==2) {
 
162
                                                $buffer=str_replace("/*","<span class='commented'>/*",$buffer);
 
163
                                        } 
 
164
                                        if($commentkind==3) {
 
165
                                                $buffer=str_replace("*/","*/</span>",$buffer);
 
166
                                        }
 
167
                                }
 
168
 
 
169
                                $linenostr = $lineno;
 
170
                                $linenostr = str_pad($linenostr,3," ",STR_PAD_RIGHT);
 
171
                                
 
172
                                if($interesting){
 
173
                                        echo "<span class='interesting'>";
 
174
                                        echo "<span class='linenointeresting'>".$linenostr."</span>&nbsp;";
 
175
                                        $startspan = 1;
 
176
                                } else {
 
177
                                        echo "<span class='lineno'>".$linenostr."</span>&nbsp;";                                
 
178
                                }
 
179
                                
 
180
                                echo $buffer;
 
181
                                
 
182
                                if($startspan) {
 
183
                                        echo "</span>";
 
184
                                }
 
185
                                
 
186
                                $lineno++;
 
187
                                echo "<br>";
 
188
                        }
 
189
                        if (!feof($handle)) {
 
190
                                echo "Error: unexpected fgets() fail\n";
 
191
                        }
 
192
                        fclose($handle);
 
193
                }
 
194
                echo "</pre>";  
178
195
        }
179
196
?>
 
 
b'\\ No newline at end of file'