139a89382SEsther Brunner<?php 239a89382SEsther Brunner/** 339a89382SEsther Brunner * Renderer for metadata 439a89382SEsther Brunner * 539a89382SEsther Brunner * @author Esther Brunner <wikidesign@gmail.com> 639a89382SEsther Brunner */ 7*fa8adffeSAndreas Gohrif(!defined('DOKU_INC')) die('meh.'); 839a89382SEsther Brunner 939a89382SEsther Brunnerif ( !defined('DOKU_LF') ) { 1039a89382SEsther Brunner // Some whitespace to help View > Source 1139a89382SEsther Brunner define ('DOKU_LF',"\n"); 1239a89382SEsther Brunner} 1339a89382SEsther Brunner 1439a89382SEsther Brunnerif ( !defined('DOKU_TAB') ) { 1539a89382SEsther Brunner // Some whitespace to help View > Source 1639a89382SEsther Brunner define ('DOKU_TAB',"\t"); 1739a89382SEsther Brunner} 1839a89382SEsther Brunner 1939a89382SEsther Brunnerrequire_once DOKU_INC . 'inc/parser/renderer.php'; 2039a89382SEsther Brunner 2139a89382SEsther Brunner/** 2239a89382SEsther Brunner * The Renderer 2339a89382SEsther Brunner */ 2439a89382SEsther Brunnerclass Doku_Renderer_metadata extends Doku_Renderer { 2539a89382SEsther Brunner 2639a89382SEsther Brunner var $doc = ''; 2739a89382SEsther Brunner var $meta = array(); 280a7e3bceSchris var $persistent = array(); 2939a89382SEsther Brunner 3039a89382SEsther Brunner var $headers = array(); 3139a89382SEsther Brunner var $capture = true; 3239a89382SEsther Brunner var $store = ''; 3339a89382SEsther Brunner 345f70445dSAndreas Gohr function getFormat(){ 355f70445dSAndreas Gohr return 'metadata'; 365f70445dSAndreas Gohr } 375f70445dSAndreas Gohr 3839a89382SEsther Brunner function document_start(){ 390a7e3bceSchris // reset metadata to persistent values 400a7e3bceSchris $this->meta = $this->persistent; 4139a89382SEsther Brunner } 4239a89382SEsther Brunner 4339a89382SEsther Brunner function document_end(){ 44b8595a66SAndreas Gohr // store internal info in metadata (notoc,nocache) 45b8595a66SAndreas Gohr $this->meta['internal'] = $this->info; 46b8595a66SAndreas Gohr 4739a89382SEsther Brunner if (!$this->meta['description']['abstract']){ 4839a89382SEsther Brunner // cut off too long abstracts 4939a89382SEsther Brunner $this->doc = trim($this->doc); 5039a89382SEsther Brunner if (strlen($this->doc) > 500) 51bc769d32SAndreas Gohr $this->doc = utf8_substr($this->doc, 0, 500).'…'; 5239a89382SEsther Brunner $this->meta['description']['abstract'] = $this->doc; 5339a89382SEsther Brunner } 5439a89382SEsther Brunner } 5539a89382SEsther Brunner 56e7856beaSchris function toc_additem($id, $text, $level) { 5739a89382SEsther Brunner global $conf; 5839a89382SEsther Brunner 59e7856beaSchris //only add items within configured levels 6039a89382SEsther Brunner if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){ 6139a89382SEsther Brunner // the TOC is one of our standard ul list arrays ;-) 6239a89382SEsther Brunner $this->meta['description']['tableofcontents'][] = array( 63e7856beaSchris 'hid' => $id, 6439a89382SEsther Brunner 'title' => $text, 6539a89382SEsther Brunner 'type' => 'ul', 6639a89382SEsther Brunner 'level' => $level-$conf['toptoclevel']+1 6739a89382SEsther Brunner ); 6839a89382SEsther Brunner } 6939a89382SEsther Brunner 70e7856beaSchris } 71e7856beaSchris 72e7856beaSchris function header($text, $level, $pos) { 73e7856beaSchris 74e7856beaSchris if (!$this->meta['title']) $this->meta['title'] = $text; 75e7856beaSchris 76e7856beaSchris // add the header to the TOC 77e7856beaSchris $hid = $this->_headerToLink($text,'true'); 78e7856beaSchris $this->toc_additem($hid, $text, $level); 79e7856beaSchris 8039a89382SEsther Brunner // add to summary 8139a89382SEsther Brunner if ($this->capture && ($level > 1)) $this->doc .= DOKU_LF.$text.DOKU_LF; 8239a89382SEsther Brunner } 8339a89382SEsther Brunner 8439a89382SEsther Brunner function section_open($level){} 8539a89382SEsther Brunner function section_close(){} 8639a89382SEsther Brunner 8739a89382SEsther Brunner function cdata($text){ 8839a89382SEsther Brunner if ($this->capture) $this->doc .= $text; 8939a89382SEsther Brunner } 9039a89382SEsther Brunner 9139a89382SEsther Brunner function p_open(){ 9239a89382SEsther Brunner if ($this->capture) $this->doc .= DOKU_LF; 9339a89382SEsther Brunner } 9439a89382SEsther Brunner 9539a89382SEsther Brunner function p_close(){ 9639a89382SEsther Brunner if ($this->capture){ 9739a89382SEsther Brunner if (strlen($this->doc) > 250) $this->capture = false; 9839a89382SEsther Brunner else $this->doc .= DOKU_LF; 9939a89382SEsther Brunner } 10039a89382SEsther Brunner } 10139a89382SEsther Brunner 10239a89382SEsther Brunner function linebreak(){ 10339a89382SEsther Brunner if ($this->capture) $this->doc .= DOKU_LF; 10439a89382SEsther Brunner } 10539a89382SEsther Brunner 10639a89382SEsther Brunner function hr(){ 10739a89382SEsther Brunner if ($this->capture){ 10839a89382SEsther Brunner if (strlen($this->doc) > 250) $this->capture = false; 10939a89382SEsther Brunner else $this->doc .= DOKU_LF.'----------'.DOKU_LF; 11039a89382SEsther Brunner } 11139a89382SEsther Brunner } 11239a89382SEsther Brunner 11339a89382SEsther Brunner function strong_open(){} 11439a89382SEsther Brunner function strong_close(){} 11539a89382SEsther Brunner 11639a89382SEsther Brunner function emphasis_open(){} 11739a89382SEsther Brunner function emphasis_close(){} 11839a89382SEsther Brunner 11939a89382SEsther Brunner function underline_open(){} 12039a89382SEsther Brunner function underline_close(){} 12139a89382SEsther Brunner 12239a89382SEsther Brunner function monospace_open(){} 12339a89382SEsther Brunner function monospace_close(){} 12439a89382SEsther Brunner 12539a89382SEsther Brunner function subscript_open(){} 12639a89382SEsther Brunner function subscript_close(){} 12739a89382SEsther Brunner 12839a89382SEsther Brunner function superscript_open(){} 12939a89382SEsther Brunner function superscript_close(){} 13039a89382SEsther Brunner 13139a89382SEsther Brunner function deleted_open(){} 13239a89382SEsther Brunner function deleted_close(){} 13339a89382SEsther Brunner 13439a89382SEsther Brunner /** 13539a89382SEsther Brunner * Callback for footnote start syntax 13639a89382SEsther Brunner * 13739a89382SEsther Brunner * All following content will go to the footnote instead of 13839a89382SEsther Brunner * the document. To achieve this the previous rendered content 13939a89382SEsther Brunner * is moved to $store and $doc is cleared 14039a89382SEsther Brunner * 14139a89382SEsther Brunner * @author Andreas Gohr <andi@splitbrain.org> 14239a89382SEsther Brunner */ 14339a89382SEsther Brunner function footnote_open() { 14439a89382SEsther Brunner if ($this->capture){ 14539a89382SEsther Brunner // move current content to store and record footnote 14639a89382SEsther Brunner $this->store = $this->doc; 14739a89382SEsther Brunner $this->doc = ''; 14839a89382SEsther Brunner } 14939a89382SEsther Brunner } 15039a89382SEsther Brunner 15139a89382SEsther Brunner /** 15239a89382SEsther Brunner * Callback for footnote end syntax 15339a89382SEsther Brunner * 15439a89382SEsther Brunner * All rendered content is moved to the $footnotes array and the old 15539a89382SEsther Brunner * content is restored from $store again 15639a89382SEsther Brunner * 15739a89382SEsther Brunner * @author Andreas Gohr 15839a89382SEsther Brunner */ 15939a89382SEsther Brunner function footnote_close() { 16039a89382SEsther Brunner if ($this->capture){ 16139a89382SEsther Brunner // restore old content 16239a89382SEsther Brunner $this->doc = $this->store; 16339a89382SEsther Brunner $this->store = ''; 16439a89382SEsther Brunner } 16539a89382SEsther Brunner } 16639a89382SEsther Brunner 16739a89382SEsther Brunner function listu_open(){ 16839a89382SEsther Brunner if ($this->capture) $this->doc .= DOKU_LF; 16939a89382SEsther Brunner } 17039a89382SEsther Brunner 17139a89382SEsther Brunner function listu_close(){ 17239a89382SEsther Brunner if ($this->capture && (strlen($this->doc) > 250)) $this->capture = false; 17339a89382SEsther Brunner } 17439a89382SEsther Brunner 17539a89382SEsther Brunner function listo_open(){ 17639a89382SEsther Brunner if ($this->capture) $this->doc .= DOKU_LF; 17739a89382SEsther Brunner } 17839a89382SEsther Brunner 17939a89382SEsther Brunner function listo_close(){ 18039a89382SEsther Brunner if ($this->capture && (strlen($this->doc) > 250)) $this->capture = false; 18139a89382SEsther Brunner } 18239a89382SEsther Brunner 18339a89382SEsther Brunner function listitem_open($level){ 18439a89382SEsther Brunner if ($this->capture) $this->doc .= str_repeat(DOKU_TAB, $level).'* '; 18539a89382SEsther Brunner } 18639a89382SEsther Brunner 18739a89382SEsther Brunner function listitem_close(){ 18839a89382SEsther Brunner if ($this->capture) $this->doc .= DOKU_LF; 18939a89382SEsther Brunner } 19039a89382SEsther Brunner 19139a89382SEsther Brunner function listcontent_open(){} 19239a89382SEsther Brunner function listcontent_close(){} 19339a89382SEsther Brunner 19439a89382SEsther Brunner function unformatted($text){ 19539a89382SEsther Brunner if ($this->capture) $this->doc .= $text; 19639a89382SEsther Brunner } 19739a89382SEsther Brunner 19839a89382SEsther Brunner function php($text){} 19939a89382SEsther Brunner 20007f89c3cSAnika Henke function phpblock($text){} 20107f89c3cSAnika Henke 20239a89382SEsther Brunner function html($text){} 20339a89382SEsther Brunner 20407f89c3cSAnika Henke function htmlblock($text){} 20507f89c3cSAnika Henke 20639a89382SEsther Brunner function preformatted($text){ 20739a89382SEsther Brunner if ($this->capture) $this->doc .= $text; 20839a89382SEsther Brunner } 20939a89382SEsther Brunner 21039a89382SEsther Brunner function file($text){ 21139a89382SEsther Brunner if ($this->capture){ 21239a89382SEsther Brunner $this->doc .= DOKU_LF.$text; 21339a89382SEsther Brunner if (strlen($this->doc) > 250) $this->capture = false; 21439a89382SEsther Brunner else $this->doc .= DOKU_LF; 21539a89382SEsther Brunner } 21639a89382SEsther Brunner } 21739a89382SEsther Brunner 21839a89382SEsther Brunner function quote_open(){ 21971b40da2SAnika Henke if ($this->capture) $this->doc .= DOKU_LF.DOKU_TAB.'"'; 22039a89382SEsther Brunner } 22139a89382SEsther Brunner 22239a89382SEsther Brunner function quote_close(){ 22339a89382SEsther Brunner if ($this->capture){ 22471b40da2SAnika Henke $this->doc .= '"'; 22539a89382SEsther Brunner if (strlen($this->doc) > 250) $this->capture = false; 22639a89382SEsther Brunner else $this->doc .= DOKU_LF; 22739a89382SEsther Brunner } 22839a89382SEsther Brunner } 22939a89382SEsther Brunner 23039a89382SEsther Brunner function code($text, $language = NULL){ 23139a89382SEsther Brunner if ($this->capture){ 23239a89382SEsther Brunner $this->doc .= DOKU_LF.$text; 23339a89382SEsther Brunner if (strlen($this->doc) > 250) $this->capture = false; 23439a89382SEsther Brunner else $this->doc .= DOKU_LF; 23539a89382SEsther Brunner } 23639a89382SEsther Brunner } 23739a89382SEsther Brunner 23839a89382SEsther Brunner function acronym($acronym){ 23939a89382SEsther Brunner if ($this->capture) $this->doc .= $acronym; 24039a89382SEsther Brunner } 24139a89382SEsther Brunner 24239a89382SEsther Brunner function smiley($smiley){ 24339a89382SEsther Brunner if ($this->capture) $this->doc .= $smiley; 24439a89382SEsther Brunner } 24539a89382SEsther Brunner 24639a89382SEsther Brunner function entity($entity){ 24739a89382SEsther Brunner if ($this->capture) $this->doc .= $entity; 24839a89382SEsther Brunner } 24939a89382SEsther Brunner 25039a89382SEsther Brunner function multiplyentity($x, $y){ 25139a89382SEsther Brunner if ($this->capture) $this->doc .= $x.'×'.$y; 25239a89382SEsther Brunner } 25339a89382SEsther Brunner 25439a89382SEsther Brunner function singlequoteopening(){ 25571b40da2SAnika Henke global $lang; 25671b40da2SAnika Henke if ($this->capture) $this->doc .= $lang['singlequoteopening']; 25739a89382SEsther Brunner } 25839a89382SEsther Brunner 25939a89382SEsther Brunner function singlequoteclosing(){ 26071b40da2SAnika Henke global $lang; 26171b40da2SAnika Henke if ($this->capture) $this->doc .= $lang['singlequoteclosing']; 26239a89382SEsther Brunner } 26339a89382SEsther Brunner 26457d757d1SAndreas Gohr function apostrophe() { 26557d757d1SAndreas Gohr global $lang; 266b58f5d31STom N Harris if ($this->capture) $this->doc .= $lang['apostrophe']; 26757d757d1SAndreas Gohr } 26857d757d1SAndreas Gohr 26939a89382SEsther Brunner function doublequoteopening(){ 27071b40da2SAnika Henke global $lang; 27171b40da2SAnika Henke if ($this->capture) $this->doc .= $lang['doublequoteopening']; 27239a89382SEsther Brunner } 27339a89382SEsther Brunner 27439a89382SEsther Brunner function doublequoteclosing(){ 27571b40da2SAnika Henke global $lang; 27671b40da2SAnika Henke if ($this->capture) $this->doc .= $lang['doublequoteclosing']; 27739a89382SEsther Brunner } 27839a89382SEsther Brunner 27939a89382SEsther Brunner function camelcaselink($link) { 28039a89382SEsther Brunner $this->internallink($link, $link); 28139a89382SEsther Brunner } 28239a89382SEsther Brunner 28339a89382SEsther Brunner function locallink($hash, $name = NULL){} 28439a89382SEsther Brunner 28539a89382SEsther Brunner /** 28639a89382SEsther Brunner * keep track of internal links in $this->meta['relation']['references'] 28739a89382SEsther Brunner */ 28839a89382SEsther Brunner function internallink($id, $name = NULL){ 28939a89382SEsther Brunner global $ID; 29039a89382SEsther Brunner 29139a89382SEsther Brunner $default = $this->_simpleTitle($id); 29239a89382SEsther Brunner 29339a89382SEsther Brunner // first resolve and clean up the $id 29439a89382SEsther Brunner resolve_pageid(getNS($ID), $id, $exists); 2953be6e394Schris list($page, $hash) = split('#', $id, 2); 29639a89382SEsther Brunner 29739a89382SEsther Brunner // set metadata 2983be6e394Schris $this->meta['relation']['references'][$page] = $exists; 29939a89382SEsther Brunner // $data = array('relation' => array('isreferencedby' => array($ID => true))); 30039a89382SEsther Brunner // p_set_metadata($id, $data); 30139a89382SEsther Brunner 30239a89382SEsther Brunner // add link title to summary 30339a89382SEsther Brunner if ($this->capture){ 30439a89382SEsther Brunner $name = $this->_getLinkTitle($name, $default, $id); 30539a89382SEsther Brunner $this->doc .= $name; 30639a89382SEsther Brunner } 30739a89382SEsther Brunner } 30839a89382SEsther Brunner 30939a89382SEsther Brunner function externallink($url, $name = NULL){ 31039a89382SEsther Brunner if ($this->capture){ 31139a89382SEsther Brunner if ($name) $this->doc .= $name; 31239a89382SEsther Brunner else $this->doc .= '<'.$url.'>'; 31339a89382SEsther Brunner } 31439a89382SEsther Brunner } 31539a89382SEsther Brunner 31639a89382SEsther Brunner function interwikilink($match, $name = NULL, $wikiName, $wikiUri){ 31739a89382SEsther Brunner if ($this->capture){ 31839a89382SEsther Brunner list($wikiUri, $hash) = explode('#', $wikiUri, 2); 31939a89382SEsther Brunner $name = $this->_getLinkTitle($name, $wikiName.'>'.$wikiUri); 32039a89382SEsther Brunner $this->doc .= $name; 32139a89382SEsther Brunner } 32239a89382SEsther Brunner } 32339a89382SEsther Brunner 32439a89382SEsther Brunner function windowssharelink($url, $name = NULL){ 32539a89382SEsther Brunner if ($this->capture){ 32639a89382SEsther Brunner if ($name) $this->doc .= $name; 32739a89382SEsther Brunner else $this->doc .= '<'.$url.'>'; 32839a89382SEsther Brunner } 32939a89382SEsther Brunner } 33039a89382SEsther Brunner 33139a89382SEsther Brunner function emaillink($address, $name = NULL){ 33239a89382SEsther Brunner if ($this->capture){ 33339a89382SEsther Brunner if ($name) $this->doc .= $name; 33439a89382SEsther Brunner else $this->doc .= '<'.$address.'>'; 33539a89382SEsther Brunner } 33639a89382SEsther Brunner } 33739a89382SEsther Brunner 33839a89382SEsther Brunner function internalmedia($src, $title=NULL, $align=NULL, $width=NULL, 33939a89382SEsther Brunner $height=NULL, $cache=NULL, $linking=NULL){ 34039a89382SEsther Brunner if ($this->capture && $title) $this->doc .= '['.$title.']'; 34139a89382SEsther Brunner } 34239a89382SEsther Brunner 34339a89382SEsther Brunner function externalmedia($src, $title=NULL, $align=NULL, $width=NULL, 34439a89382SEsther Brunner $height=NULL, $cache=NULL, $linking=NULL){ 34539a89382SEsther Brunner if ($this->capture && $title) $this->doc .= '['.$title.']'; 34639a89382SEsther Brunner } 34739a89382SEsther Brunner 348ce6b63d9Schris function rss($url,$params) { 349ce6b63d9Schris $this->meta['relation']['haspart'][$url] = true; 35064e9144aSchris 35164e9144aSchris $this->meta['date']['valid']['age'] = 35264e9144aSchris isset($this->meta['date']['valid']['age']) ? 35364e9144aSchris min($this->meta['date']['valid']['age'],$params['refresh']) : 35464e9144aSchris $params['refresh']; 355ce6b63d9Schris } 35639a89382SEsther Brunner 35739a89382SEsther Brunner function table_open($maxcols = NULL, $numrows = NULL){} 35839a89382SEsther Brunner function table_close(){} 35939a89382SEsther Brunner 36039a89382SEsther Brunner function tablerow_open(){} 36139a89382SEsther Brunner function tablerow_close(){} 36239a89382SEsther Brunner 36339a89382SEsther Brunner function tableheader_open($colspan = 1, $align = NULL){} 36439a89382SEsther Brunner function tableheader_close(){} 36539a89382SEsther Brunner 36639a89382SEsther Brunner function tablecell_open($colspan = 1, $align = NULL){} 36739a89382SEsther Brunner function tablecell_close(){} 36839a89382SEsther Brunner 36939a89382SEsther Brunner //---------------------------------------------------------- 37039a89382SEsther Brunner // Utils 37139a89382SEsther Brunner 37239a89382SEsther Brunner /** 37339a89382SEsther Brunner * Removes any Namespace from the given name but keeps 37439a89382SEsther Brunner * casing and special chars 37539a89382SEsther Brunner * 37639a89382SEsther Brunner * @author Andreas Gohr <andi@splitbrain.org> 37739a89382SEsther Brunner */ 37839a89382SEsther Brunner function _simpleTitle($name){ 37939a89382SEsther Brunner global $conf; 38039a89382SEsther Brunner 3819bee852eSAndreas Gohr if(is_array($name)) return ''; 3829bee852eSAndreas Gohr 38339a89382SEsther Brunner if($conf['useslash']){ 38439a89382SEsther Brunner $nssep = '[:;/]'; 38539a89382SEsther Brunner }else{ 38639a89382SEsther Brunner $nssep = '[:;]'; 38739a89382SEsther Brunner } 38839a89382SEsther Brunner $name = preg_replace('!.*'.$nssep.'!','',$name); 3893be6e394Schris //if there is a hash we use the anchor name only 39039a89382SEsther Brunner $name = preg_replace('!.*#!','',$name); 39139a89382SEsther Brunner return $name; 39239a89382SEsther Brunner } 39339a89382SEsther Brunner 39439a89382SEsther Brunner /** 39539a89382SEsther Brunner * Creates a linkid from a headline 39639a89382SEsther Brunner * 39739a89382SEsther Brunner * @param string $title The headline title 39839a89382SEsther Brunner * @param boolean $create Create a new unique ID? 39939a89382SEsther Brunner * @author Andreas Gohr <andi@splitbrain.org> 40039a89382SEsther Brunner */ 40139a89382SEsther Brunner function _headerToLink($title, $create=false) { 4025fe80182Schris $title = str_replace(':','',cleanID($title)); 40339a89382SEsther Brunner $title = ltrim($title,'0123456789._-'); 40439a89382SEsther Brunner if(empty($title)) $title='section'; 40539a89382SEsther Brunner 40639a89382SEsther Brunner if($create){ 40739a89382SEsther Brunner // make sure tiles are unique 40839a89382SEsther Brunner $num = ''; 40939a89382SEsther Brunner while(in_array($title.$num,$this->headers)){ 41039a89382SEsther Brunner ($num) ? $num++ : $num = 1; 41139a89382SEsther Brunner } 41239a89382SEsther Brunner $title = $title.$num; 41339a89382SEsther Brunner $this->headers[] = $title; 41439a89382SEsther Brunner } 41539a89382SEsther Brunner 41639a89382SEsther Brunner return $title; 41739a89382SEsther Brunner } 41839a89382SEsther Brunner 41939a89382SEsther Brunner /** 42039a89382SEsther Brunner * Construct a title and handle images in titles 42139a89382SEsther Brunner * 42239a89382SEsther Brunner * @author Harry Fuecks <hfuecks@gmail.com> 42339a89382SEsther Brunner */ 42439a89382SEsther Brunner function _getLinkTitle($title, $default, $id=NULL) { 42539a89382SEsther Brunner global $conf; 42639a89382SEsther Brunner 42744881bd0Shenning.noren $isImage = false; 42839a89382SEsther Brunner if (is_null($title)){ 429fe9ec250SChris Smith if (useHeading('content') && $id){ 430fc18c0fbSchris $heading = p_get_first_heading($id,false); 43139a89382SEsther Brunner if ($heading) return $heading; 43239a89382SEsther Brunner } 43339a89382SEsther Brunner return $default; 43439a89382SEsther Brunner } else if (is_string($title)){ 43539a89382SEsther Brunner return $title; 43639a89382SEsther Brunner } else if (is_array($title)){ 43739a89382SEsther Brunner return '['.$title.']'; 43839a89382SEsther Brunner } 43939a89382SEsther Brunner } 44039a89382SEsther Brunner 44139a89382SEsther Brunner} 44239a89382SEsther Brunner 44339a89382SEsther Brunner//Setup VIM: ex: et ts=4 enc=utf-8 : 444