/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 codeigniter/application/models/codeviewer_model.php

  • Committer: Gustav Hartvigsson
  • Date: 2013-04-11 16:45:55 UTC
  • mfrom: (23.2.1 lenasys)
  • Revision ID: gustav.hartvigsson@gmail.com-20130411164555-ljhmrb2ys3xatogt
commited implementation group one's team branch.
20130411.

Merge proposal comment:
Removed codeigniter user guide, shouldn't be in the repo
Added and implemented CKEditor Wysiwyg editor for editing of pages
Made already uploaded code files visible as you edit a page
Implemented Adams dropdown menu in codeviewer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.'&nbsp;&nbsp;&nbsp;&nbsp;'.$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("&", "&amp;", $buffer);
18
 
                                $buffer = str_replace("<", "&lt;", $buffer);
19
 
                                $buffer = str_replace(">", "&gt;", $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
 
}