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