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