[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * HTML parser implementation. It only implements links. 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 include_once ("nwiki.php"); 12 13 class html_parser extends nwiki_parser { 14 protected $blockrules = array(); 15 16 protected $section_editing = true; 17 18 public function __construct() { 19 parent::__construct(); 20 // The order is important, headers should be parsed before links. 21 $this->tagrules = array( 22 // Headers are considered tags here. 23 'header' => array( 24 'expression' => "/<\s*h([1-$this->maxheaderdepth])\s*>(.+?)<\/h[1-$this->maxheaderdepth]>/is" 25 ), 26 'link' => $this->tagrules['link'], 27 'url' => $this->tagrules['url'] 28 ); 29 } 30 31 protected function before_parsing() { 32 parent::before_parsing(); 33 34 $this->rules($this->string); 35 } 36 37 /** 38 * Header tag rule 39 * @param array $match Header regex match 40 * @return string 41 */ 42 protected function header_tag_rule($match) { 43 return $this->generate_header($match[2], $match[1]); 44 } 45 46 /** 47 * Section editing: Special for HTML Parser (It parses <h1></h1>) 48 */ 49 50 public function get_section($header, $text, $clean = false) { 51 if ($clean) { 52 $text = preg_replace('/\r\n/', "\n", $text); 53 $text = preg_replace('/\r/', "\n", $text); 54 $text .= "\n\n"; 55 } 56 57 $h1 = array("<\s*h1\s*>", "<\/h1>"); 58 59 $regex = "/(.*?)({$h1[0]}\s*".preg_quote($header, '/')."\s*{$h1[1]}.*?)((?:\n{$h1[0]}.*)|$)/is"; 60 preg_match($regex, $text, $match); 61 62 if (!empty($match)) { 63 return array($match[1], $match[2], $match[3]); 64 } else { 65 return false; 66 } 67 } 68 69 protected function get_repeated_sections(&$text, $repeated = array()) { 70 $this->repeated_sections = $repeated; 71 return preg_replace_callback($this->tagrules['header'], array($this, 'get_repeated_sections_callback'), $text); 72 } 73 74 protected function get_repeated_sections_callback($match) { 75 $text = trim($match[2]); 76 77 if (in_array($text, $this->repeated_sections)) { 78 $this->returnvalues['repeated_sections'][] = $text; 79 return parser_utils::h('p', $text); 80 } else { 81 $this->repeated_sections[] = $text; 82 } 83 84 return $match[0]; 85 } 86 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |