Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/wiki/parser/utils.php
Go to the documentation of this file.
00001 <?php
00002 
00012 require_once($CFG->dirroot . "/lib/outputcomponents.php");
00013     
00014 class parser_utils {
00015         
00016     public static function h($tag, $text = null, $options = array(), $escape_text = false) {
00017         $tag = htmlentities($tag);
00018         if(!empty($text) && $escape_text) {
00019                 $text = htmlentities($text);
00020             }
00021         return html_writer::tag($tag, $text, $options);
00022     }
00023     
00028     public static function wiki_parser_link_callback($link, $options) {
00029         $l = urlencode($link);
00030         if(!empty($options['anchor'])) {
00031             $l .= "#".urlencode($options['anchor']);
00032         }
00033         return array('content' => $link, 'url' => "http://".$l);
00034     }
00035 
00036 
00041     public static function wiki_parser_table_callback($table) {
00042         $html = "";
00043         $headers = $table[0];
00044         $columncount = count($headers);
00045         $headerhtml = "";
00046         foreach($headers as $h) {
00047             $text = trim($h[1]);
00048             if($h[0] == 'header') {
00049                 $headerhtml .= "\n".parser_utils::h('th', $text)."\n";
00050                 $hasheaders = true;
00051             }
00052             else if($h[0] == 'normal'){
00053                 $headerhtml .= "\n".parser_utils::h("td", $text)."\n";
00054             }
00055         }
00056         $headerhtml = "\n".parser_utils::h('tr', $headerhtml)."\n";
00057         $bodyhtml = "";
00058         if(isset($hasheaders)) {
00059             $html = "\n".parser_utils::h('thead', $headerhtml)."\n";
00060         }
00061         else {
00062             $bodyhtml .= $headerhtml;
00063         }
00064 
00065         array_shift($table);
00066         foreach($table as $row) {
00067             $htmlrow = "";
00068             for($i = 0; $i < $columncount; $i++) {
00069                 $text = "";
00070                 if(!isset($row[$i])) {
00071                     $htmlrow .= "\n".parser_utils::h('td', $text)."\n";
00072                 }
00073                 else {
00074                     $text = trim($row[$i][1]);
00075                     if($row[$i][0] == 'header') {
00076                         $htmlrow .= "\n".parser_utils::h('th', $text)."\n";
00077                     }
00078                     else if($row[$i][0] == 'normal'){
00079                         $htmlrow .= "\n".parser_utils::h('td', $text)."\n";
00080                     }   
00081                 }
00082             }
00083             $bodyhtml .= "\n".parser_utils::h('tr', $htmlrow)."\n";
00084         }
00085 
00086         $html .= "\n".parser_utils::h('tbody', $bodyhtml)."\n";
00087         return "\n".parser_utils::h('table', $html)."\n";
00088     }
00089     
00094     public static function wiki_parser_real_path($url) {
00095         return $url;
00096     }
00097 }
00098 
 All Data Structures Namespaces Files Functions Variables Enumerations