bzr branch
http://gegoxaren.bato24.eu/bzr/lenasys/trunk
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
1 |
<?php
|
2 |
class Codeviewer_model extends CI_Model { |
|
3 |
||
4 |
function __construct(){ |
|
5 |
$this->load->database(); |
|
6 |
}
|
|
7 |
||
8 |
function showFile($filename, $lang, $interestingrows = array()) { |
|
9 |
$output = ""; |
|
10 |
$output .= '<div class="editorinfo">'.$lang.' '.$filename.'</div>'; |
|
11 |
$output .= '<div id="ace_'.str_replace(".", "", $filename).'" class="ace">'; |
|
12 |
$handle = @fopen($filename, "r"); |
|
13 |
if ($handle) { |
|
14 |
||
15 |
while (($buffer = fgets($handle, 4096)) !== false) { |
|
16 |
||
17 |
$buffer = str_replace("&", "&", $buffer); |
|
18 |
$buffer = str_replace("<", "<", $buffer); |
|
19 |
$buffer = str_replace(">", ">", $buffer); |
|
20 |
||
21 |
$output .= $buffer; |
|
22 |
}
|
|
23 |
if (!feof($handle)) { |
|
24 |
$output .= "Error: unexpected fgets() fail\n"; |
|
25 |
}
|
|
26 |
fclose($handle); |
|
27 |
}
|
|
28 |
$output .= '</div>'; |
|
29 |
||
30 |
$output .= '<script type="text/javascript"> |
|
31 |
var Range = require("ace/range").Range;
|
|
32 |
var editor = ace.edit("ace_'.str_replace(".", "", $filename).'"); |
|
33 |
editor.setTheme("ace/theme/merbivore");
|
|
34 |
editor.getSession().setMode("ace/mode/'.$lang.'"); |
|
35 |
editor.setReadOnly(true);
|
|
36 |
editor.setShowPrintMargin(false);
|
|
37 |
editor.setDisplayIndentGuides(false);
|
|
38 |
editor.setHighlightSelectedWord(true);
|
|
39 |
lines = editor.getSession().getLength();
|
|
40 |
$("#ace_'.str_replace(".", "", $filename).'").height(Math.min(500,lines*16)); |
|
41 |
aceeditors.push("ace_'.str_replace(".", "", $filename).'");'; |
|
42 |
for($i = 0; $i < count($interestingrows); $i++) { |
|
43 |
$output .= 'editor.getSession().addMarker(new Range('.$interestingrows[$i][0].', 0, ' |
|
44 |
.$interestingrows[$i][1].', Number.POSITIVE_INFINITY), "interesting", "text",false);'; |
|
45 |
}
|
|
46 |
$output .= '</script>'; |
|
47 |
||
48 |
return $output; |
|
49 |
}
|
|
50 |
||
51 |
function getFiles($course, $example, $page){ |
|
52 |
$files = array(); |
|
53 |
if ($handle = opendir("../courses/".$course."/". $example."/".$page."/")) { |
|
54 |
while (false !== ($entry = readdir($handle))) { |
|
55 |
if($entry == "." || $entry == "..") continue; |
|
56 |
$files[] = "../courses/".$course."/". $example."/".$page."/".$entry; |
|
57 |
}
|
|
58 |
}
|
|
59 |
||
60 |
return $files; |
|
61 |
}
|
|
62 |
||
63 |
function getDoc($cid, $example, $page){ |
|
64 |
$this->db->select('documentation'); |
|
65 |
$query = $this->db->get_where('pages', array('cid' => $cid, 'example' => $example, 'page' => $page)); |
|
66 |
$result = $query->result(); |
|
67 |
return $result[0]->documentation; |
|
68 |
}
|
|
69 |
||
70 |
}
|