Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
/**
4
 * Parser utils and default callbacks.
5
 *
6
 * @author Josep Arús
7
 *
8
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
9
 * @package mod_wiki
10
 */
11
 
12
class parser_utils {
13
 
14
    public static function h($tag, $text = null, $options = array(), $escape_text = false) {
15
        $tag = htmlentities($tag, ENT_COMPAT, 'UTF-8');
16
        if(!empty($text) && $escape_text) {
17
                $text = htmlentities($text, ENT_COMPAT, 'UTF-8');
18
            }
19
        return html_writer::tag($tag, $text, $options);
20
    }
21
 
22
    /**
23
     * Default link generator
24
     */
25
 
26
    public static function wiki_parser_link_callback($link, $options) {
27
        $l = urlencode($link);
28
        if(!empty($options['anchor'])) {
29
            $l .= "#".urlencode($options['anchor']);
30
        }
31
        return array('content' => $link, 'url' => "http://".$l);
32
    }
33
 
34
 
35
    /**
36
     * Default table generator
37
     */
38
 
39
    public static function wiki_parser_table_callback($table) {
40
        $html = "";
41
        $headers = $table[0];
42
        $columncount = count($headers);
43
        $headerhtml = "";
44
        foreach($headers as $h) {
45
            $text = trim($h[1]);
46
            if($h[0] == 'header') {
47
                $headerhtml .= "\n".parser_utils::h('th', $text)."\n";
48
                $hasheaders = true;
49
            }
50
            else if($h[0] == 'normal'){
51
                $headerhtml .= "\n".parser_utils::h("td", $text)."\n";
52
            }
53
        }
54
        $headerhtml = "\n".parser_utils::h('tr', $headerhtml)."\n";
55
        $bodyhtml = "";
56
        if(isset($hasheaders)) {
57
            $html = "\n".parser_utils::h('thead', $headerhtml)."\n";
58
        }
59
        else {
60
            $bodyhtml .= $headerhtml;
61
        }
62
 
63
        array_shift($table);
64
        foreach($table as $row) {
65
            $htmlrow = "";
66
            for($i = 0; $i < $columncount; $i++) {
67
                $text = "";
68
                if(!isset($row[$i])) {
69
                    $htmlrow .= "\n".parser_utils::h('td', $text)."\n";
70
                }
71
                else {
72
                    $text = trim($row[$i][1]);
73
                    if($row[$i][0] == 'header') {
74
                        $htmlrow .= "\n".parser_utils::h('th', $text)."\n";
75
                    }
76
                    else if($row[$i][0] == 'normal'){
77
                        $htmlrow .= "\n".parser_utils::h('td', $text)."\n";
78
                    }
79
                }
80
            }
81
            $bodyhtml .= "\n".parser_utils::h('tr', $htmlrow)."\n";
82
        }
83
 
84
        $html .= "\n".parser_utils::h('tbody', $bodyhtml)."\n";
85
        return "\n".parser_utils::h('table', $html)."\n";
86
    }
87
 
88
    /**
89
     * Default path converter
90
     */
91
 
92
    public static function wiki_parser_real_path($url) {
93
        return $url;
94
    }
95
}