protected function get_repeated_sections_callback($match) { $text = trim($match[2]); if (in_array($text, $this->repeated_sections)) { $this->returnvalues['repeated_sections'][] = $text; return parser_utils::h('p', $text); } else { $this->repeated_sections[] = $text; } return $match[0]; }
/** * Default table generator */ public static function wiki_parser_table_callback($table) { $html = ""; $headers = $table[0]; $columncount = count($headers); $headerhtml = ""; foreach ($headers as $h) { $text = trim($h[1]); if ($h[0] == 'header') { $headerhtml .= "\n" . parser_utils::h('th', $text) . "\n"; $hasheaders = true; } else { if ($h[0] == 'normal') { $headerhtml .= "\n" . parser_utils::h("td", $text) . "\n"; } } } $headerhtml = "\n" . parser_utils::h('tr', $headerhtml) . "\n"; $bodyhtml = ""; if (isset($hasheaders)) { $html = "\n" . parser_utils::h('thead', $headerhtml) . "\n"; } else { $bodyhtml .= $headerhtml; } array_shift($table); foreach ($table as $row) { $htmlrow = ""; for ($i = 0; $i < $columncount; $i++) { $text = ""; if (!isset($row[$i])) { $htmlrow .= "\n" . parser_utils::h('td', $text) . "\n"; } else { $text = trim($row[$i][1]); if ($row[$i][0] == 'header') { $htmlrow .= "\n" . parser_utils::h('th', $text) . "\n"; } else { if ($row[$i][0] == 'normal') { $htmlrow .= "\n" . parser_utils::h('td', $text) . "\n"; } } } } $bodyhtml .= "\n" . parser_utils::h('tr', $htmlrow) . "\n"; } $html .= "\n" . parser_utils::h('tbody', $bodyhtml) . "\n"; return "\n" . parser_utils::h('table', $html) . "\n"; }
protected function format_image($src, $alt, $caption = "", $align = 'left') { $src = $this->real_path($src); return parser_utils::h('div', parser_utils::h('p', $caption) . '<img src="' . $src . '" alt="' . $alt . '" />', array('class' => 'wiki_image_' . $align)); }
protected function attach_tag_rule($match) { $parts = explode("|", $match[1]); $url = array_shift($parts); if (count($parts) > 0) { $text = array_shift($parts); } $extension = substr($url, strrpos($url, ".")); $text = empty($text) ? $url : $text; $imageextensions = array('jpg', 'jpeg', 'png', 'bmp', 'gif', 'tif'); if (in_array($extension, $imageextensions)) { $align = 'left'; if (count($parts) > 0) { switch (strtolower($text)) { case 'right': $align = 'right'; break; case 'center': $align = 'center'; break; default: $align = 'left'; } $text = $parts[0]; } return $this->format_image($url, $text, $text, $align); } else { $url = $this->real_path($url); return parser_utils::h('a', $text, array('href' => $url, 'class' => 'wiki-attachment')); } }
/** * Header generation * * @param string $text * @param int $level * @return string */ protected function generate_header($text, $level) { $toctext = $text = trim($text); $normlevel = $level - $this->minheaderlevel + 1; if (!$this->pretty_print && $normlevel == 1) { $editlink = '[' . get_string('editsection', 'wiki') . ']'; $url = array('href' => "edit.php?pageid={$this->wiki_page_id}§ion=" . urlencode($text), 'class' => 'wiki_edit_section'); $text .= ' ' . parser_utils::h('a', $this->protect($editlink), $url); $toctext .= ' ' . parser_utils::h('a', $editlink, $url); } if ($normlevel <= $this->maxheaderdepth) { $this->toc[] = array($normlevel, $toctext); $num = count($this->toc); $text = parser_utils::h('a', "", array('name' => "toc-{$num}")) . $text; } return parser_utils::h('h' . $level, $text) . "\n\n"; }
private function tag_callback($match) { $rule = end($this->rulestack); $stuff = $this->{$rule['callback']}($match); if(is_array($stuff)) { return parser_utils::h($rule['rule']['tag'], $stuff[0], $stuff[1]); } else { return $stuff; } }