10cecf9d5Sandi<?php 2b625487dSandi/** 3b625487dSandi * Renderer for XHTML output 4b625487dSandi * 5b625487dSandi * @author Harry Fuecks <hfuecks@gmail.com> 6b625487dSandi * @author Andreas Gohr <andi@splitbrain.org> 7b625487dSandi */ 8fa8adffeSAndreas Gohrif(!defined('DOKU_INC')) die('meh.'); 90cecf9d5Sandi 100cecf9d5Sandiif ( !defined('DOKU_LF') ) { 110cecf9d5Sandi // Some whitespace to help View > Source 120cecf9d5Sandi define ('DOKU_LF',"\n"); 130cecf9d5Sandi} 140cecf9d5Sandi 150cecf9d5Sandiif ( !defined('DOKU_TAB') ) { 160cecf9d5Sandi // Some whitespace to help View > Source 170cecf9d5Sandi define ('DOKU_TAB',"\t"); 180cecf9d5Sandi} 190cecf9d5Sandi 200e1c636eSandirequire_once DOKU_INC . 'inc/parser/renderer.php'; 2156fa9a3fSAndreas Gohrrequire_once DOKU_INC . 'inc/html.php'; 220e1c636eSandi 230cecf9d5Sandi/** 24b625487dSandi * The Renderer 250cecf9d5Sandi */ 26ac83b9d8Sandiclass Doku_Renderer_xhtml extends Doku_Renderer { 270cecf9d5Sandi 28c5a8fd96SAndreas Gohr // @access public 29c5a8fd96SAndreas Gohr var $doc = ''; // will contain the whole document 30c5a8fd96SAndreas Gohr var $toc = array(); // will contain the Table of Contents 314bde2196Slisps var $date_at = ''; // link pages and media against this revision 32c5a8fd96SAndreas Gohr 33fb838798SDanny var $sectionedits = array(); // A stack of section edit data 34b04a190dSMichael Hamann private $lastsecid = 0; // last section edit id, used by startSectionEdit 350cecf9d5Sandi 360cecf9d5Sandi var $headers = array(); 3716ec3e37SAndreas Gohr /** @var array a list of footnotes, list starts at 1! */ 380cecf9d5Sandi var $footnotes = array(); 3991459163SAnika Henke var $lastlevel = 0; 4091459163SAnika Henke var $node = array(0,0,0,0,0); 417764a90aSandi var $store = ''; 427764a90aSandi 43b5742cedSPierre Spring var $_counter = array(); // used as global counter, introduced for table classes 443d491f75SAndreas Gohr var $_codeblock = 0; // counts the code and file blocks, used to provide download links 45b5742cedSPierre Spring 4690df9a4dSAdrian Lang /** 4790df9a4dSAdrian Lang * Register a new edit section range 4890df9a4dSAdrian Lang * 4990df9a4dSAdrian Lang * @param $type string The section type identifier 5090df9a4dSAdrian Lang * @param $title string The section title 5190df9a4dSAdrian Lang * @param $start int The byte position for the edit start 5290df9a4dSAdrian Lang * @return string A marker class for the starting HTML element 5390df9a4dSAdrian Lang * @author Adrian Lang <lang@cosmocode.de> 5490df9a4dSAdrian Lang */ 553f9e3215SAdrian Lang public function startSectionEdit($start, $type, $title = null) { 56b04a190dSMichael Hamann $this->sectionedits[] = array(++$this->lastsecid, $start, $type, $title); 57b04a190dSMichael Hamann return 'sectionedit' . $this->lastsecid; 5890df9a4dSAdrian Lang } 5990df9a4dSAdrian Lang 6090df9a4dSAdrian Lang /** 6190df9a4dSAdrian Lang * Finish an edit section range 6290df9a4dSAdrian Lang * 63d9e36cbeSAdrian Lang * @param $end int The byte position for the edit end; null for the rest of 64c404cb3bSMatt Perry * the page 6590df9a4dSAdrian Lang * @author Adrian Lang <lang@cosmocode.de> 6690df9a4dSAdrian Lang */ 673f9e3215SAdrian Lang public function finishSectionEdit($end = null) { 6890df9a4dSAdrian Lang list($id, $start, $type, $title) = array_pop($this->sectionedits); 69d9e36cbeSAdrian Lang if (!is_null($end) && $end <= $start) { 7000c13053SAdrian Lang return; 7100c13053SAdrian Lang } 7240868f2fSAdrian Lang $this->doc .= "<!-- EDIT$id " . strtoupper($type) . ' '; 7340868f2fSAdrian Lang if (!is_null($title)) { 7440868f2fSAdrian Lang $this->doc .= '"' . str_replace('"', '', $title) . '" '; 7540868f2fSAdrian Lang } 76d9e36cbeSAdrian Lang $this->doc .= "[$start-" . (is_null($end) ? '' : $end) . '] -->'; 7790df9a4dSAdrian Lang } 7890df9a4dSAdrian Lang 795f70445dSAndreas Gohr function getFormat(){ 805f70445dSAndreas Gohr return 'xhtml'; 815f70445dSAndreas Gohr } 825f70445dSAndreas Gohr 835f70445dSAndreas Gohr 840cecf9d5Sandi function document_start() { 85c5a8fd96SAndreas Gohr //reset some internals 86c5a8fd96SAndreas Gohr $this->toc = array(); 87c5a8fd96SAndreas Gohr $this->headers = array(); 880cecf9d5Sandi } 890cecf9d5Sandi 900cecf9d5Sandi function document_end() { 9190df9a4dSAdrian Lang // Finish open section edits. 9290df9a4dSAdrian Lang while (count($this->sectionedits) > 0) { 9390df9a4dSAdrian Lang if ($this->sectionedits[count($this->sectionedits) - 1][1] <= 1) { 9490df9a4dSAdrian Lang // If there is only one section, do not write a section edit 9590df9a4dSAdrian Lang // marker. 9690df9a4dSAdrian Lang array_pop($this->sectionedits); 9790df9a4dSAdrian Lang } else { 98d9e36cbeSAdrian Lang $this->finishSectionEdit(); 9990df9a4dSAdrian Lang } 10090df9a4dSAdrian Lang } 10190df9a4dSAdrian Lang 1020cecf9d5Sandi if ( count ($this->footnotes) > 0 ) { 103a2d649c4Sandi $this->doc .= '<div class="footnotes">'.DOKU_LF; 104d74aace9Schris 10516ec3e37SAndreas Gohr foreach ( $this->footnotes as $id => $footnote ) { 106d74aace9Schris // check its not a placeholder that indicates actual footnote text is elsewhere 107d74aace9Schris if (substr($footnote, 0, 5) != "@@FNT") { 108d74aace9Schris 109d74aace9Schris // open the footnote and set the anchor and backlink 110d74aace9Schris $this->doc .= '<div class="fn">'; 11116cc7ed7SAnika Henke $this->doc .= '<sup><a href="#fnt__'.$id.'" id="fn__'.$id.'" class="fn_bot">'; 11229bfcd16SAndreas Gohr $this->doc .= $id.')</a></sup> '.DOKU_LF; 113d74aace9Schris 114d74aace9Schris // get any other footnotes that use the same markup 115d74aace9Schris $alt = array_keys($this->footnotes, "@@FNT$id"); 116d74aace9Schris 117d74aace9Schris if (count($alt)) { 118d74aace9Schris foreach ($alt as $ref) { 119d74aace9Schris // set anchor and backlink for the other footnotes 12016ec3e37SAndreas Gohr $this->doc .= ', <sup><a href="#fnt__'.($ref).'" id="fn__'.($ref).'" class="fn_bot">'; 12116ec3e37SAndreas Gohr $this->doc .= ($ref).')</a></sup> '.DOKU_LF; 122d74aace9Schris } 123d74aace9Schris } 124d74aace9Schris 125d74aace9Schris // add footnote markup and close this footnote 126a2d649c4Sandi $this->doc .= $footnote; 127d74aace9Schris $this->doc .= '</div>' . DOKU_LF; 128d74aace9Schris } 1290cecf9d5Sandi } 130a2d649c4Sandi $this->doc .= '</div>'.DOKU_LF; 1310cecf9d5Sandi } 132c5a8fd96SAndreas Gohr 133b8595a66SAndreas Gohr // Prepare the TOC 134851f2e89SAnika Henke global $conf; 135851f2e89SAnika Henke if($this->info['toc'] && is_array($this->toc) && $conf['tocminheads'] && count($this->toc) >= $conf['tocminheads']){ 136b8595a66SAndreas Gohr global $TOC; 137b8595a66SAndreas Gohr $TOC = $this->toc; 1380cecf9d5Sandi } 1393e55d035SAndreas Gohr 1403e55d035SAndreas Gohr // make sure there are no empty paragraphs 14127918226Schris $this->doc = preg_replace('#<p>\s*</p>#','',$this->doc); 142e41c4da9SAndreas Gohr } 1430cecf9d5Sandi 144e7856beaSchris function toc_additem($id, $text, $level) { 145af587fa8Sandi global $conf; 146af587fa8Sandi 147c5a8fd96SAndreas Gohr //handle TOC 148c5a8fd96SAndreas Gohr if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){ 1497d91652aSAndreas Gohr $this->toc[] = html_mktocitem($id, $text, $level-$conf['toptoclevel']+1); 150c5a8fd96SAndreas Gohr } 151e7856beaSchris } 152e7856beaSchris 153e7856beaSchris function header($text, $level, $pos) { 15490df9a4dSAdrian Lang global $conf; 15590df9a4dSAdrian Lang 156bdd8111bSAndreas Gohr if(!$text) return; //skip empty headlines 157e7856beaSchris 158e7856beaSchris $hid = $this->_headerToLink($text,true); 159e7856beaSchris 160e7856beaSchris //only add items within configured levels 161e7856beaSchris $this->toc_additem($hid, $text, $level); 162c5a8fd96SAndreas Gohr 16391459163SAnika Henke // adjust $node to reflect hierarchy of levels 16491459163SAnika Henke $this->node[$level-1]++; 16591459163SAnika Henke if ($level < $this->lastlevel) { 16691459163SAnika Henke for ($i = 0; $i < $this->lastlevel-$level; $i++) { 16791459163SAnika Henke $this->node[$this->lastlevel-$i-1] = 0; 16891459163SAnika Henke } 16991459163SAnika Henke } 17091459163SAnika Henke $this->lastlevel = $level; 17191459163SAnika Henke 17290df9a4dSAdrian Lang if ($level <= $conf['maxseclevel'] && 17390df9a4dSAdrian Lang count($this->sectionedits) > 0 && 17490df9a4dSAdrian Lang $this->sectionedits[count($this->sectionedits) - 1][2] === 'section') { 1756c1f778cSAdrian Lang $this->finishSectionEdit($pos - 1); 17690df9a4dSAdrian Lang } 17790df9a4dSAdrian Lang 178c5a8fd96SAndreas Gohr // write the header 17990df9a4dSAdrian Lang $this->doc .= DOKU_LF.'<h'.$level; 18090df9a4dSAdrian Lang if ($level <= $conf['maxseclevel']) { 18190df9a4dSAdrian Lang $this->doc .= ' class="' . $this->startSectionEdit($pos, 'section', $text) . '"'; 18290df9a4dSAdrian Lang } 18316cc7ed7SAnika Henke $this->doc .= ' id="'.$hid.'">'; 184a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 18516cc7ed7SAnika Henke $this->doc .= "</h$level>".DOKU_LF; 1860cecf9d5Sandi } 1870cecf9d5Sandi 1880cecf9d5Sandi function section_open($level) { 1899864e7b1SAdrian Lang $this->doc .= '<div class="level' . $level . '">' . DOKU_LF; 1900cecf9d5Sandi } 1910cecf9d5Sandi 1920cecf9d5Sandi function section_close() { 193a2d649c4Sandi $this->doc .= DOKU_LF.'</div>'.DOKU_LF; 1940cecf9d5Sandi } 1950cecf9d5Sandi 1960cecf9d5Sandi function cdata($text) { 197a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 1980cecf9d5Sandi } 1990cecf9d5Sandi 2000cecf9d5Sandi function p_open() { 20159869a4bSAnika Henke $this->doc .= DOKU_LF.'<p>'.DOKU_LF; 2020cecf9d5Sandi } 2030cecf9d5Sandi 2040cecf9d5Sandi function p_close() { 20559869a4bSAnika Henke $this->doc .= DOKU_LF.'</p>'.DOKU_LF; 2060cecf9d5Sandi } 2070cecf9d5Sandi 2080cecf9d5Sandi function linebreak() { 209a2d649c4Sandi $this->doc .= '<br/>'.DOKU_LF; 2100cecf9d5Sandi } 2110cecf9d5Sandi 2120cecf9d5Sandi function hr() { 2134beabca9SAnika Henke $this->doc .= '<hr />'.DOKU_LF; 2140cecf9d5Sandi } 2150cecf9d5Sandi 2160cecf9d5Sandi function strong_open() { 217a2d649c4Sandi $this->doc .= '<strong>'; 2180cecf9d5Sandi } 2190cecf9d5Sandi 2200cecf9d5Sandi function strong_close() { 221a2d649c4Sandi $this->doc .= '</strong>'; 2220cecf9d5Sandi } 2230cecf9d5Sandi 2240cecf9d5Sandi function emphasis_open() { 225a2d649c4Sandi $this->doc .= '<em>'; 2260cecf9d5Sandi } 2270cecf9d5Sandi 2280cecf9d5Sandi function emphasis_close() { 229a2d649c4Sandi $this->doc .= '</em>'; 2300cecf9d5Sandi } 2310cecf9d5Sandi 2320cecf9d5Sandi function underline_open() { 23302e51121SAnika Henke $this->doc .= '<em class="u">'; 2340cecf9d5Sandi } 2350cecf9d5Sandi 2360cecf9d5Sandi function underline_close() { 23702e51121SAnika Henke $this->doc .= '</em>'; 2380cecf9d5Sandi } 2390cecf9d5Sandi 2400cecf9d5Sandi function monospace_open() { 241a2d649c4Sandi $this->doc .= '<code>'; 2420cecf9d5Sandi } 2430cecf9d5Sandi 2440cecf9d5Sandi function monospace_close() { 245a2d649c4Sandi $this->doc .= '</code>'; 2460cecf9d5Sandi } 2470cecf9d5Sandi 2480cecf9d5Sandi function subscript_open() { 249a2d649c4Sandi $this->doc .= '<sub>'; 2500cecf9d5Sandi } 2510cecf9d5Sandi 2520cecf9d5Sandi function subscript_close() { 253a2d649c4Sandi $this->doc .= '</sub>'; 2540cecf9d5Sandi } 2550cecf9d5Sandi 2560cecf9d5Sandi function superscript_open() { 257a2d649c4Sandi $this->doc .= '<sup>'; 2580cecf9d5Sandi } 2590cecf9d5Sandi 2600cecf9d5Sandi function superscript_close() { 261a2d649c4Sandi $this->doc .= '</sup>'; 2620cecf9d5Sandi } 2630cecf9d5Sandi 2640cecf9d5Sandi function deleted_open() { 265a2d649c4Sandi $this->doc .= '<del>'; 2660cecf9d5Sandi } 2670cecf9d5Sandi 2680cecf9d5Sandi function deleted_close() { 269a2d649c4Sandi $this->doc .= '</del>'; 2700cecf9d5Sandi } 2710cecf9d5Sandi 2723fd0b676Sandi /** 2733fd0b676Sandi * Callback for footnote start syntax 2743fd0b676Sandi * 2753fd0b676Sandi * All following content will go to the footnote instead of 276d74aace9Schris * the document. To achieve this the previous rendered content 2773fd0b676Sandi * is moved to $store and $doc is cleared 2783fd0b676Sandi * 2793fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 2803fd0b676Sandi */ 2810cecf9d5Sandi function footnote_open() { 2827764a90aSandi 2837764a90aSandi // move current content to store and record footnote 2847764a90aSandi $this->store = $this->doc; 2857764a90aSandi $this->doc = ''; 2860cecf9d5Sandi } 2870cecf9d5Sandi 2883fd0b676Sandi /** 2893fd0b676Sandi * Callback for footnote end syntax 2903fd0b676Sandi * 2913fd0b676Sandi * All rendered content is moved to the $footnotes array and the old 2923fd0b676Sandi * content is restored from $store again 2933fd0b676Sandi * 2943fd0b676Sandi * @author Andreas Gohr 2953fd0b676Sandi */ 2960cecf9d5Sandi function footnote_close() { 29716ec3e37SAndreas Gohr /** @var $fnid int takes track of seen footnotes, assures they are unique even across multiple docs FS#2841 */ 29816ec3e37SAndreas Gohr static $fnid = 0; 29916ec3e37SAndreas Gohr // assign new footnote id (we start at 1) 30016ec3e37SAndreas Gohr $fnid++; 3017764a90aSandi 302d74aace9Schris // recover footnote into the stack and restore old content 303d74aace9Schris $footnote = $this->doc; 3047764a90aSandi $this->doc = $this->store; 3057764a90aSandi $this->store = ''; 306d74aace9Schris 307d74aace9Schris // check to see if this footnote has been seen before 308d74aace9Schris $i = array_search($footnote, $this->footnotes); 309d74aace9Schris 310d74aace9Schris if ($i === false) { 311d74aace9Schris // its a new footnote, add it to the $footnotes array 31216ec3e37SAndreas Gohr $this->footnotes[$fnid] = $footnote; 313d74aace9Schris } else { 31416ec3e37SAndreas Gohr // seen this one before, save a placeholder 31516ec3e37SAndreas Gohr $this->footnotes[$fnid] = "@@FNT".($i); 316d74aace9Schris } 317d74aace9Schris 3186b379cbfSAndreas Gohr // output the footnote reference and link 31916ec3e37SAndreas Gohr $this->doc .= '<sup><a href="#fn__'.$fnid.'" id="fnt__'.$fnid.'" class="fn_top">'.$fnid.')</a></sup>'; 3200cecf9d5Sandi } 3210cecf9d5Sandi 3220cecf9d5Sandi function listu_open() { 323a2d649c4Sandi $this->doc .= '<ul>'.DOKU_LF; 3240cecf9d5Sandi } 3250cecf9d5Sandi 3260cecf9d5Sandi function listu_close() { 327a2d649c4Sandi $this->doc .= '</ul>'.DOKU_LF; 3280cecf9d5Sandi } 3290cecf9d5Sandi 3300cecf9d5Sandi function listo_open() { 331a2d649c4Sandi $this->doc .= '<ol>'.DOKU_LF; 3320cecf9d5Sandi } 3330cecf9d5Sandi 3340cecf9d5Sandi function listo_close() { 335a2d649c4Sandi $this->doc .= '</ol>'.DOKU_LF; 3360cecf9d5Sandi } 3370cecf9d5Sandi 3380cecf9d5Sandi function listitem_open($level) { 33959869a4bSAnika Henke $this->doc .= '<li class="level'.$level.'">'; 3400cecf9d5Sandi } 3410cecf9d5Sandi 3420cecf9d5Sandi function listitem_close() { 343a2d649c4Sandi $this->doc .= '</li>'.DOKU_LF; 3440cecf9d5Sandi } 3450cecf9d5Sandi 3460cecf9d5Sandi function listcontent_open() { 34790db23d7Schris $this->doc .= '<div class="li">'; 3480cecf9d5Sandi } 3490cecf9d5Sandi 3500cecf9d5Sandi function listcontent_close() { 35159869a4bSAnika Henke $this->doc .= '</div>'.DOKU_LF; 3520cecf9d5Sandi } 3530cecf9d5Sandi 3540cecf9d5Sandi function unformatted($text) { 355a2d649c4Sandi $this->doc .= $this->_xmlEntities($text); 3560cecf9d5Sandi } 3570cecf9d5Sandi 3580cecf9d5Sandi /** 3593fd0b676Sandi * Execute PHP code if allowed 3603fd0b676Sandi * 361d9764001SMichael Hamann * @param string $text PHP code that is either executed or printed 3625d568b99SChris Smith * @param string $wrapper html element to wrap result if $conf['phpok'] is okff 3635d568b99SChris Smith * 3643fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3650cecf9d5Sandi */ 3665d568b99SChris Smith function php($text, $wrapper='code') { 36735a56260SChris Smith global $conf; 36835a56260SChris Smith 369d86d5af0SChris Smith if($conf['phpok']){ 370bad0b545Sandi ob_start(); 3714de671bcSandi eval($text); 3723fd0b676Sandi $this->doc .= ob_get_contents(); 373bad0b545Sandi ob_end_clean(); 374d86d5af0SChris Smith } else { 3755d568b99SChris Smith $this->doc .= p_xhtml_cached_geshi($text, 'php', $wrapper); 376d86d5af0SChris Smith } 3770cecf9d5Sandi } 3780cecf9d5Sandi 37907f89c3cSAnika Henke function phpblock($text) { 3805d568b99SChris Smith $this->php($text, 'pre'); 38107f89c3cSAnika Henke } 38207f89c3cSAnika Henke 3830cecf9d5Sandi /** 3843fd0b676Sandi * Insert HTML if allowed 3853fd0b676Sandi * 386d9764001SMichael Hamann * @param string $text html text 3875d568b99SChris Smith * @param string $wrapper html element to wrap result if $conf['htmlok'] is okff 3885d568b99SChris Smith * 3893fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 3900cecf9d5Sandi */ 3915d568b99SChris Smith function html($text, $wrapper='code') { 39235a56260SChris Smith global $conf; 39335a56260SChris Smith 394d86d5af0SChris Smith if($conf['htmlok']){ 395a2d649c4Sandi $this->doc .= $text; 396d86d5af0SChris Smith } else { 3975d568b99SChris Smith $this->doc .= p_xhtml_cached_geshi($text, 'html4strict', $wrapper); 398d86d5af0SChris Smith } 3994de671bcSandi } 4000cecf9d5Sandi 40107f89c3cSAnika Henke function htmlblock($text) { 4025d568b99SChris Smith $this->html($text, 'pre'); 40307f89c3cSAnika Henke } 40407f89c3cSAnika Henke 4050cecf9d5Sandi function quote_open() { 40696331712SAnika Henke $this->doc .= '<blockquote><div class="no">'.DOKU_LF; 4070cecf9d5Sandi } 4080cecf9d5Sandi 4090cecf9d5Sandi function quote_close() { 41096331712SAnika Henke $this->doc .= '</div></blockquote>'.DOKU_LF; 4110cecf9d5Sandi } 4120cecf9d5Sandi 4133d491f75SAndreas Gohr function preformatted($text) { 414c9250713SAnika Henke $this->doc .= '<pre class="code">' . trim($this->_xmlEntities($text),"\n\r") . '</pre>'. DOKU_LF; 4153d491f75SAndreas Gohr } 4163d491f75SAndreas Gohr 4173d491f75SAndreas Gohr function file($text, $language=null, $filename=null) { 4183d491f75SAndreas Gohr $this->_highlight('file',$text,$language,$filename); 4193d491f75SAndreas Gohr } 4203d491f75SAndreas Gohr 4213d491f75SAndreas Gohr function code($text, $language=null, $filename=null) { 4223d491f75SAndreas Gohr $this->_highlight('code',$text,$language,$filename); 4233d491f75SAndreas Gohr } 4243d491f75SAndreas Gohr 4250cecf9d5Sandi /** 4263d491f75SAndreas Gohr * Use GeSHi to highlight language syntax in code and file blocks 4273fd0b676Sandi * 4283fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 4290cecf9d5Sandi */ 4303d491f75SAndreas Gohr function _highlight($type, $text, $language=null, $filename=null) { 4314de671bcSandi global $conf; 4323d491f75SAndreas Gohr global $ID; 4333d491f75SAndreas Gohr global $lang; 4343d491f75SAndreas Gohr 4353d491f75SAndreas Gohr if($filename){ 436190c56e8SAndreas Gohr // add icon 43727bf7924STom N Harris list($ext) = mimetype($filename,false); 438190c56e8SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 439190c56e8SAndreas Gohr $class = 'mediafile mf_'.$class; 440190c56e8SAndreas Gohr 4413d491f75SAndreas Gohr $this->doc .= '<dl class="'.$type.'">'.DOKU_LF; 442190c56e8SAndreas Gohr $this->doc .= '<dt><a href="'.exportlink($ID,'code',array('codeblock'=>$this->_codeblock)).'" title="'.$lang['download'].'" class="'.$class.'">'; 4433d491f75SAndreas Gohr $this->doc .= hsc($filename); 4443d491f75SAndreas Gohr $this->doc .= '</a></dt>'.DOKU_LF.'<dd>'; 4453d491f75SAndreas Gohr } 4460cecf9d5Sandi 447d43aac1cSGina Haeussge if ($text{0} == "\n") { 448d43aac1cSGina Haeussge $text = substr($text, 1); 449d43aac1cSGina Haeussge } 450d43aac1cSGina Haeussge if (substr($text, -1) == "\n") { 451d43aac1cSGina Haeussge $text = substr($text, 0, -1); 452d43aac1cSGina Haeussge } 453d43aac1cSGina Haeussge 4540cecf9d5Sandi if ( is_null($language) ) { 4553d491f75SAndreas Gohr $this->doc .= '<pre class="'.$type.'">'.$this->_xmlEntities($text).'</pre>'.DOKU_LF; 4560cecf9d5Sandi } else { 4573d491f75SAndreas Gohr $class = 'code'; //we always need the code class to make the syntax highlighting apply 4583d491f75SAndreas Gohr if($type != 'code') $class .= ' '.$type; 4593d491f75SAndreas Gohr 4603d491f75SAndreas Gohr $this->doc .= "<pre class=\"$class $language\">".p_xhtml_cached_geshi($text, $language, '').'</pre>'.DOKU_LF; 4610cecf9d5Sandi } 4623d491f75SAndreas Gohr 4633d491f75SAndreas Gohr if($filename){ 4643d491f75SAndreas Gohr $this->doc .= '</dd></dl>'.DOKU_LF; 4653d491f75SAndreas Gohr } 4663d491f75SAndreas Gohr 4673d491f75SAndreas Gohr $this->_codeblock++; 4680cecf9d5Sandi } 4690cecf9d5Sandi 4700cecf9d5Sandi function acronym($acronym) { 4710cecf9d5Sandi 4720cecf9d5Sandi if ( array_key_exists($acronym, $this->acronyms) ) { 4730cecf9d5Sandi 474433bef32Sandi $title = $this->_xmlEntities($this->acronyms[$acronym]); 4750cecf9d5Sandi 476940db3a3SAnika Henke $this->doc .= '<abbr title="'.$title 477940db3a3SAnika Henke .'">'.$this->_xmlEntities($acronym).'</abbr>'; 4780cecf9d5Sandi 4790cecf9d5Sandi } else { 480a2d649c4Sandi $this->doc .= $this->_xmlEntities($acronym); 4810cecf9d5Sandi } 4820cecf9d5Sandi } 4830cecf9d5Sandi 4840cecf9d5Sandi function smiley($smiley) { 4850cecf9d5Sandi if ( array_key_exists($smiley, $this->smileys) ) { 486433bef32Sandi $title = $this->_xmlEntities($this->smileys[$smiley]); 487f62ea8a1Sandi $this->doc .= '<img src="'.DOKU_BASE.'lib/images/smileys/'.$this->smileys[$smiley]. 4888e38227fSAnika Henke '" class="icon" alt="'. 489433bef32Sandi $this->_xmlEntities($smiley).'" />'; 4900cecf9d5Sandi } else { 491a2d649c4Sandi $this->doc .= $this->_xmlEntities($smiley); 4920cecf9d5Sandi } 4930cecf9d5Sandi } 4940cecf9d5Sandi 495f62ea8a1Sandi /* 4964de671bcSandi * not used 4970cecf9d5Sandi function wordblock($word) { 4980cecf9d5Sandi if ( array_key_exists($word, $this->badwords) ) { 499a2d649c4Sandi $this->doc .= '** BLEEP **'; 5000cecf9d5Sandi } else { 501a2d649c4Sandi $this->doc .= $this->_xmlEntities($word); 5020cecf9d5Sandi } 5030cecf9d5Sandi } 5044de671bcSandi */ 5050cecf9d5Sandi 5060cecf9d5Sandi function entity($entity) { 5070cecf9d5Sandi if ( array_key_exists($entity, $this->entities) ) { 508a2d649c4Sandi $this->doc .= $this->entities[$entity]; 5090cecf9d5Sandi } else { 510a2d649c4Sandi $this->doc .= $this->_xmlEntities($entity); 5110cecf9d5Sandi } 5120cecf9d5Sandi } 5130cecf9d5Sandi 5140cecf9d5Sandi function multiplyentity($x, $y) { 515a2d649c4Sandi $this->doc .= "$x×$y"; 5160cecf9d5Sandi } 5170cecf9d5Sandi 5180cecf9d5Sandi function singlequoteopening() { 51971b40da2SAnika Henke global $lang; 52071b40da2SAnika Henke $this->doc .= $lang['singlequoteopening']; 5210cecf9d5Sandi } 5220cecf9d5Sandi 5230cecf9d5Sandi function singlequoteclosing() { 52471b40da2SAnika Henke global $lang; 52571b40da2SAnika Henke $this->doc .= $lang['singlequoteclosing']; 5260cecf9d5Sandi } 5270cecf9d5Sandi 52857d757d1SAndreas Gohr function apostrophe() { 52957d757d1SAndreas Gohr global $lang; 530a8bd192aSAndreas Gohr $this->doc .= $lang['apostrophe']; 53157d757d1SAndreas Gohr } 53257d757d1SAndreas Gohr 5330cecf9d5Sandi function doublequoteopening() { 53471b40da2SAnika Henke global $lang; 53571b40da2SAnika Henke $this->doc .= $lang['doublequoteopening']; 5360cecf9d5Sandi } 5370cecf9d5Sandi 5380cecf9d5Sandi function doublequoteclosing() { 53971b40da2SAnika Henke global $lang; 54071b40da2SAnika Henke $this->doc .= $lang['doublequoteclosing']; 5410cecf9d5Sandi } 5420cecf9d5Sandi 5430cecf9d5Sandi /** 5440cecf9d5Sandi */ 5450cecf9d5Sandi function camelcaselink($link) { 54611d0aa47Sandi $this->internallink($link,$link); 5470cecf9d5Sandi } 5480cecf9d5Sandi 5490b7c14c2Sandi 5500ea51e63SMatt Perry function locallink($hash, $name = null){ 5510b7c14c2Sandi global $ID; 5520b7c14c2Sandi $name = $this->_getLinkTitle($name, $hash, $isImage); 5530b7c14c2Sandi $hash = $this->_headerToLink($hash); 554e260f93bSAnika Henke $title = $ID.' ↵'; 5550b7c14c2Sandi $this->doc .= '<a href="#'.$hash.'" title="'.$title.'" class="wikilink1">'; 5560b7c14c2Sandi $this->doc .= $name; 5570b7c14c2Sandi $this->doc .= '</a>'; 5580b7c14c2Sandi } 5590b7c14c2Sandi 560cffcc403Sandi /** 5613fd0b676Sandi * Render an internal Wiki Link 5623fd0b676Sandi * 563fe9ec250SChris Smith * $search,$returnonly & $linktype are not for the renderer but are used 564cffcc403Sandi * elsewhere - no need to implement them in other renderers 5653fd0b676Sandi * 5663fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 567cffcc403Sandi */ 5680ea51e63SMatt Perry function internallink($id, $name = null, $search=null,$returnonly=false,$linktype='content') { 569ba11bd29Sandi global $conf; 57037e34a5eSandi global $ID; 571c4dda6afSAnika Henke global $INFO; 57244653a53SAdrian Lang 5733d5e07d9SAdrian Lang $params = ''; 5743d5e07d9SAdrian Lang $parts = explode('?', $id, 2); 5753d5e07d9SAdrian Lang if (count($parts) === 2) { 5763d5e07d9SAdrian Lang $id = $parts[0]; 5773d5e07d9SAdrian Lang $params = $parts[1]; 57844653a53SAdrian Lang } 57944653a53SAdrian Lang 580fda14ffcSIzidor Matušov // For empty $id we need to know the current $ID 581fda14ffcSIzidor Matušov // We need this check because _simpleTitle needs 582fda14ffcSIzidor Matušov // correct $id and resolve_pageid() use cleanID($id) 583fda14ffcSIzidor Matušov // (some things could be lost) 584fda14ffcSIzidor Matušov if ($id === '') { 585fda14ffcSIzidor Matušov $id = $ID; 586fda14ffcSIzidor Matušov } 587fda14ffcSIzidor Matušov 5880339c872Sjan // default name is based on $id as given 5890339c872Sjan $default = $this->_simpleTitle($id); 590ad32e47eSAndreas Gohr 5910339c872Sjan // now first resolve and clean up the $id 59290bee600Slisps resolve_pageid(getNS($ID),$id,$exists,$this->date_at,true); 593fda14ffcSIzidor Matušov 594fe9ec250SChris Smith $name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype); 5950e1c636eSandi if ( !$isImage ) { 5960e1c636eSandi if ( $exists ) { 597ba11bd29Sandi $class='wikilink1'; 5980cecf9d5Sandi } else { 599ba11bd29Sandi $class='wikilink2'; 60044a6b4c7SAndreas Gohr $link['rel']='nofollow'; 6010cecf9d5Sandi } 6020cecf9d5Sandi } else { 603ba11bd29Sandi $class='media'; 6040cecf9d5Sandi } 6050cecf9d5Sandi 606a1685bedSandi //keep hash anchor 607ce6b63d9Schris list($id,$hash) = explode('#',$id,2); 608943dedc6SAndreas Gohr if(!empty($hash)) $hash = $this->_headerToLink($hash); 609a1685bedSandi 610ba11bd29Sandi //prepare for formating 611ba11bd29Sandi $link['target'] = $conf['target']['wiki']; 612ba11bd29Sandi $link['style'] = ''; 613ba11bd29Sandi $link['pre'] = ''; 614ba11bd29Sandi $link['suf'] = ''; 61540eb54bbSjan // highlight link to current page 616c4dda6afSAnika Henke if ($id == $INFO['id']) { 61792795d04Sandi $link['pre'] = '<span class="curid">'; 61892795d04Sandi $link['suf'] = '</span>'; 61940eb54bbSjan } 6205e163278SAndreas Gohr $link['more'] = ''; 621ba11bd29Sandi $link['class'] = $class; 6225c2eed9aSlisps if($this->date_at) { 6235c2eed9aSlisps $params['at'] = $this->date_at; 6245c2eed9aSlisps } 62544653a53SAdrian Lang $link['url'] = wl($id, $params); 626ba11bd29Sandi $link['name'] = $name; 627ba11bd29Sandi $link['title'] = $id; 628723d78dbSandi //add search string 629723d78dbSandi if($search){ 630546d3a99SAndreas Gohr ($conf['userewrite']) ? $link['url'].='?' : $link['url'].='&'; 631546d3a99SAndreas Gohr if(is_array($search)){ 632546d3a99SAndreas Gohr $search = array_map('rawurlencode',$search); 633546d3a99SAndreas Gohr $link['url'] .= 's[]='.join('&s[]=',$search); 634546d3a99SAndreas Gohr }else{ 635546d3a99SAndreas Gohr $link['url'] .= 's='.rawurlencode($search); 636546d3a99SAndreas Gohr } 637723d78dbSandi } 638723d78dbSandi 639a1685bedSandi //keep hash 640a1685bedSandi if($hash) $link['url'].='#'.$hash; 641a1685bedSandi 642ba11bd29Sandi //output formatted 643cffcc403Sandi if($returnonly){ 644cffcc403Sandi return $this->_formatLink($link); 645cffcc403Sandi }else{ 646a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6470cecf9d5Sandi } 648cffcc403Sandi } 6490cecf9d5Sandi 6500ea51e63SMatt Perry function externallink($url, $name = null) { 651b625487dSandi global $conf; 6520cecf9d5Sandi 653433bef32Sandi $name = $this->_getLinkTitle($name, $url, $isImage); 6546f0c5dbfSandi 655b52b1596SAndreas Gohr // url might be an attack vector, only allow registered protocols 656b52b1596SAndreas Gohr if(is_null($this->schemes)) $this->schemes = getSchemes(); 657b52b1596SAndreas Gohr list($scheme) = explode('://',$url); 658b52b1596SAndreas Gohr $scheme = strtolower($scheme); 659b52b1596SAndreas Gohr if(!in_array($scheme,$this->schemes)) $url = ''; 660b52b1596SAndreas Gohr 661b52b1596SAndreas Gohr // is there still an URL? 662b52b1596SAndreas Gohr if(!$url){ 663b52b1596SAndreas Gohr $this->doc .= $name; 664b52b1596SAndreas Gohr return; 665b52b1596SAndreas Gohr } 666b52b1596SAndreas Gohr 667b52b1596SAndreas Gohr // set class 6680cecf9d5Sandi if ( !$isImage ) { 669b625487dSandi $class='urlextern'; 6700cecf9d5Sandi } else { 671b625487dSandi $class='media'; 6720cecf9d5Sandi } 6730cecf9d5Sandi 674b625487dSandi //prepare for formating 675b625487dSandi $link['target'] = $conf['target']['extern']; 676b625487dSandi $link['style'] = ''; 677b625487dSandi $link['pre'] = ''; 678b625487dSandi $link['suf'] = ''; 6795e163278SAndreas Gohr $link['more'] = ''; 680b625487dSandi $link['class'] = $class; 681b625487dSandi $link['url'] = $url; 682e1c10e4dSchris 683b625487dSandi $link['name'] = $name; 684433bef32Sandi $link['title'] = $this->_xmlEntities($url); 685b625487dSandi if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"'; 6860cecf9d5Sandi 687b625487dSandi //output formatted 688a2d649c4Sandi $this->doc .= $this->_formatLink($link); 6890cecf9d5Sandi } 6900cecf9d5Sandi 6910cecf9d5Sandi /** 6920cecf9d5Sandi */ 6930ea51e63SMatt Perry function interwikilink($match, $name = null, $wikiName, $wikiUri) { 694b625487dSandi global $conf; 6950cecf9d5Sandi 69697a3e4e3Sandi $link = array(); 69797a3e4e3Sandi $link['target'] = $conf['target']['interwiki']; 69897a3e4e3Sandi $link['pre'] = ''; 69997a3e4e3Sandi $link['suf'] = ''; 7005e163278SAndreas Gohr $link['more'] = ''; 701433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $wikiUri, $isImage); 7020cecf9d5Sandi 70397a3e4e3Sandi //get interwiki URL 7041f82fabeSAndreas Gohr $url = $this->_resolveInterWiki($wikiName,$wikiUri); 7050cecf9d5Sandi 70697a3e4e3Sandi if ( !$isImage ) { 7079d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName); 7089d2ddea4SAndreas Gohr $link['class'] = "interwiki iw_$class"; 7091c2d1019SAndreas Gohr } else { 7101c2d1019SAndreas Gohr $link['class'] = 'media'; 71197a3e4e3Sandi } 7120cecf9d5Sandi 71397a3e4e3Sandi //do we stay at the same server? Use local target 71497a3e4e3Sandi if( strpos($url,DOKU_URL) === 0 ){ 71597a3e4e3Sandi $link['target'] = $conf['target']['wiki']; 71697a3e4e3Sandi } 7170cecf9d5Sandi 71897a3e4e3Sandi $link['url'] = $url; 71997a3e4e3Sandi $link['title'] = htmlspecialchars($link['url']); 72097a3e4e3Sandi 72197a3e4e3Sandi //output formatted 722a2d649c4Sandi $this->doc .= $this->_formatLink($link); 7230cecf9d5Sandi } 7240cecf9d5Sandi 7250cecf9d5Sandi /** 7260cecf9d5Sandi */ 7270ea51e63SMatt Perry function windowssharelink($url, $name = null) { 7281d47afe1Sandi global $conf; 7291d47afe1Sandi global $lang; 7301d47afe1Sandi //simple setup 7311d47afe1Sandi $link['target'] = $conf['target']['windows']; 7321d47afe1Sandi $link['pre'] = ''; 7331d47afe1Sandi $link['suf'] = ''; 7341d47afe1Sandi $link['style'] = ''; 7350cecf9d5Sandi 736433bef32Sandi $link['name'] = $this->_getLinkTitle($name, $url, $isImage); 7370cecf9d5Sandi if ( !$isImage ) { 7381d47afe1Sandi $link['class'] = 'windows'; 7390cecf9d5Sandi } else { 7401d47afe1Sandi $link['class'] = 'media'; 7410cecf9d5Sandi } 7420cecf9d5Sandi 743433bef32Sandi $link['title'] = $this->_xmlEntities($url); 7441d47afe1Sandi $url = str_replace('\\','/',$url); 7451d47afe1Sandi $url = 'file:///'.$url; 7461d47afe1Sandi $link['url'] = $url; 7470cecf9d5Sandi 7481d47afe1Sandi //output formatted 749a2d649c4Sandi $this->doc .= $this->_formatLink($link); 7500cecf9d5Sandi } 7510cecf9d5Sandi 7520ea51e63SMatt Perry function emaillink($address, $name = null) { 75371352defSandi global $conf; 75471352defSandi //simple setup 75571352defSandi $link = array(); 75671352defSandi $link['target'] = ''; 75771352defSandi $link['pre'] = ''; 75871352defSandi $link['suf'] = ''; 75971352defSandi $link['style'] = ''; 76071352defSandi $link['more'] = ''; 7610cecf9d5Sandi 762c078fc55SAndreas Gohr $name = $this->_getLinkTitle($name, '', $isImage); 7630cecf9d5Sandi if ( !$isImage ) { 764be96545cSAnika Henke $link['class']='mail'; 7650cecf9d5Sandi } else { 766be96545cSAnika Henke $link['class']='media'; 7670cecf9d5Sandi } 7680cecf9d5Sandi 76907738714SAndreas Gohr $address = $this->_xmlEntities($address); 77000a7b5adSEsther Brunner $address = obfuscate($address); 77100a7b5adSEsther Brunner $title = $address; 7728c128049SAndreas Gohr 77371352defSandi if(empty($name)){ 77400a7b5adSEsther Brunner $name = $address; 77571352defSandi } 7760cecf9d5Sandi 777776b36ecSAndreas Gohr if($conf['mailguard'] == 'visible') $address = rawurlencode($address); 778776b36ecSAndreas Gohr 779776b36ecSAndreas Gohr $link['url'] = 'mailto:'.$address; 78071352defSandi $link['name'] = $name; 78171352defSandi $link['title'] = $title; 7820cecf9d5Sandi 78371352defSandi //output formatted 784a2d649c4Sandi $this->doc .= $this->_formatLink($link); 7850cecf9d5Sandi } 7860cecf9d5Sandi 7870ea51e63SMatt Perry function internalmedia ($src, $title=null, $align=null, $width=null, 788c5393ecbSAnika Henke $height=null, $cache=null, $linking=null, $return=NULL) { 78937e34a5eSandi global $ID; 79091df343aSAndreas Gohr list($src,$hash) = explode('#',$src,2); 791*cdb5e961Slisps resolve_mediaid(getNS($ID),$src, $exists,$this->date_at,true); 7920cecf9d5Sandi 793d98d4540SBen Coburn $noLink = false; 7948acb3108SAndreas Gohr $render = ($linking == 'linkonly') ? false : true; 795b739ff0fSPierre Spring $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 7963685f775Sandi 79727bf7924STom N Harris list($ext,$mime,$dl) = mimetype($src,false); 798b739ff0fSPierre Spring if(substr($mime,0,5) == 'image' && $render){ 79952dc5eadSlisps $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache,'rev'=>$this->_getLastMediaRevisionAt($src)),($linking=='direct')); 800f50634f0SAnika Henke }elseif(($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render){ 8012a2a2ba2SAnika Henke // don't link movies 80244881bd0Shenning.noren $noLink = true; 80355efc227SAndreas Gohr }else{ 8042ca14335SEsther Brunner // add file icons 8059d2ddea4SAndreas Gohr $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 8069d2ddea4SAndreas Gohr $link['class'] .= ' mediafile mf_'.$class; 80752dc5eadSlisps $link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache,'rev'=>$this->_getLastMediaRevisionAt($src)),true); 80891328684SMichael Hamann if ($exists) $link['title'] .= ' (' . filesize_h(filesize(mediaFN($src))).')'; 80955efc227SAndreas Gohr } 8103685f775Sandi 81191df343aSAndreas Gohr if($hash) $link['url'] .= '#'.$hash; 81291df343aSAndreas Gohr 8136fe20453SGina Haeussge //markup non existing files 8144a24b459SKate Arzamastseva if (!$exists) { 8156fe20453SGina Haeussge $link['class'] .= ' wikilink2'; 8164a24b459SKate Arzamastseva } 8176fe20453SGina Haeussge 8183685f775Sandi //output formatted 819f50634f0SAnika Henke if ($return) { 820f50634f0SAnika Henke if ($linking == 'nolink' || $noLink) return $link['name']; 821f50634f0SAnika Henke else return $this->_formatLink($link); 822f50634f0SAnika Henke } else { 823dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 8242ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 8250cecf9d5Sandi } 826f50634f0SAnika Henke } 8270cecf9d5Sandi 8280ea51e63SMatt Perry function externalmedia ($src, $title=null, $align=null, $width=null, 8290ea51e63SMatt Perry $height=null, $cache=null, $linking=null) { 83091df343aSAndreas Gohr list($src,$hash) = explode('#',$src,2); 831d98d4540SBen Coburn $noLink = false; 8328acb3108SAndreas Gohr $render = ($linking == 'linkonly') ? false : true; 833b739ff0fSPierre Spring $link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render); 834b739ff0fSPierre Spring 835b739ff0fSPierre Spring $link['url'] = ml($src,array('cache'=>$cache)); 8363685f775Sandi 83727bf7924STom N Harris list($ext,$mime,$dl) = mimetype($src,false); 838b739ff0fSPierre Spring if(substr($mime,0,5) == 'image' && $render){ 8392ca14335SEsther Brunner // link only jpeg images 84044881bd0Shenning.noren // if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true; 841f50634f0SAnika Henke }elseif(($mime == 'application/x-shockwave-flash' || media_supportedav($mime)) && $render){ 8422a2a2ba2SAnika Henke // don't link movies 84344881bd0Shenning.noren $noLink = true; 8442ca14335SEsther Brunner }else{ 8452ca14335SEsther Brunner // add file icons 84627bf7924STom N Harris $class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext); 84727bf7924STom N Harris $link['class'] .= ' mediafile mf_'.$class; 8482ca14335SEsther Brunner } 8492ca14335SEsther Brunner 85091df343aSAndreas Gohr if($hash) $link['url'] .= '#'.$hash; 85191df343aSAndreas Gohr 8523685f775Sandi //output formatted 853dc673a5bSjoe.lapp if ($linking == 'nolink' || $noLink) $this->doc .= $link['name']; 8542ca14335SEsther Brunner else $this->doc .= $this->_formatLink($link); 8550cecf9d5Sandi } 8560cecf9d5Sandi 8574826ab45Sandi /** 8583db95becSAndreas Gohr * Renders an RSS feed 859b625487dSandi * 860b625487dSandi * @author Andreas Gohr <andi@splitbrain.org> 861b625487dSandi */ 8623db95becSAndreas Gohr function rss ($url,$params){ 863b625487dSandi global $lang; 8643db95becSAndreas Gohr global $conf; 8653db95becSAndreas Gohr 8663db95becSAndreas Gohr require_once(DOKU_INC.'inc/FeedParser.php'); 8673db95becSAndreas Gohr $feed = new FeedParser(); 86800077af8SAndreas Gohr $feed->set_feed_url($url); 869b625487dSandi 870b625487dSandi //disable warning while fetching 871bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); } 8723db95becSAndreas Gohr $rc = $feed->init(); 873bad905f1SBen Coburn if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); } 874b625487dSandi 8753db95becSAndreas Gohr //decide on start and end 8763db95becSAndreas Gohr if($params['reverse']){ 8773db95becSAndreas Gohr $mod = -1; 8783db95becSAndreas Gohr $start = $feed->get_item_quantity()-1; 8793db95becSAndreas Gohr $end = $start - ($params['max']); 880b2a412b0SAndreas Gohr $end = ($end < -1) ? -1 : $end; 8813db95becSAndreas Gohr }else{ 8823db95becSAndreas Gohr $mod = 1; 8833db95becSAndreas Gohr $start = 0; 8843db95becSAndreas Gohr $end = $feed->get_item_quantity(); 885d91ab76fSMatt Perry $end = ($end > $params['max']) ? $params['max'] : $end; 8863db95becSAndreas Gohr } 8873db95becSAndreas Gohr 888a2d649c4Sandi $this->doc .= '<ul class="rss">'; 8893db95becSAndreas Gohr if($rc){ 8903db95becSAndreas Gohr for ($x = $start; $x != $end; $x += $mod) { 8911bde1582SAndreas Gohr $item = $feed->get_item($x); 8923db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 893d2ea3363SAndreas Gohr // support feeds without links 894d2ea3363SAndreas Gohr $lnkurl = $item->get_permalink(); 895d2ea3363SAndreas Gohr if($lnkurl){ 896793361f8SAndreas Gohr // title is escaped by SimplePie, we unescape here because it 897793361f8SAndreas Gohr // is escaped again in externallink() FS#1705 8981bde1582SAndreas Gohr $this->externallink($item->get_permalink(), 899b9b9b28bSMichael Hamann html_entity_decode($item->get_title(), ENT_QUOTES, 'UTF-8')); 900d2ea3363SAndreas Gohr }else{ 901d2ea3363SAndreas Gohr $this->doc .= ' '.$item->get_title(); 902d2ea3363SAndreas Gohr } 9033db95becSAndreas Gohr if($params['author']){ 9041bde1582SAndreas Gohr $author = $item->get_author(0); 9051bde1582SAndreas Gohr if($author){ 9061bde1582SAndreas Gohr $name = $author->get_name(); 9071bde1582SAndreas Gohr if(!$name) $name = $author->get_email(); 9081bde1582SAndreas Gohr if($name) $this->doc .= ' '.$lang['by'].' '.$name; 9091bde1582SAndreas Gohr } 9103db95becSAndreas Gohr } 9113db95becSAndreas Gohr if($params['date']){ 9122e7e0c29SAndreas Gohr $this->doc .= ' ('.$item->get_local_date($conf['dformat']).')'; 9133db95becSAndreas Gohr } 9141bde1582SAndreas Gohr if($params['details']){ 9153db95becSAndreas Gohr $this->doc .= '<div class="detail">'; 916173dccb7STom N Harris if($conf['htmlok']){ 9171bde1582SAndreas Gohr $this->doc .= $item->get_description(); 9183db95becSAndreas Gohr }else{ 9191bde1582SAndreas Gohr $this->doc .= strip_tags($item->get_description()); 9203db95becSAndreas Gohr } 9213db95becSAndreas Gohr $this->doc .= '</div>'; 9223db95becSAndreas Gohr } 9233db95becSAndreas Gohr 9243db95becSAndreas Gohr $this->doc .= '</div></li>'; 925b625487dSandi } 926b625487dSandi }else{ 9273db95becSAndreas Gohr $this->doc .= '<li><div class="li">'; 928a2d649c4Sandi $this->doc .= '<em>'.$lang['rssfailed'].'</em>'; 929b625487dSandi $this->externallink($url); 93045e147ccSAndreas Gohr if($conf['allowdebug']){ 93145e147ccSAndreas Gohr $this->doc .= '<!--'.hsc($feed->error).'-->'; 93245e147ccSAndreas Gohr } 9333db95becSAndreas Gohr $this->doc .= '</div></li>'; 934b625487dSandi } 935a2d649c4Sandi $this->doc .= '</ul>'; 936b625487dSandi } 937b625487dSandi 9380cecf9d5Sandi // $numrows not yet implemented 939619736fdSAdrian Lang function table_open($maxcols = null, $numrows = null, $pos = null){ 94090df9a4dSAdrian Lang global $lang; 941b5742cedSPierre Spring // initialize the row counter used for classes 942b5742cedSPierre Spring $this->_counter['row_counter'] = 0; 943619736fdSAdrian Lang $class = 'table'; 944619736fdSAdrian Lang if ($pos !== null) { 945619736fdSAdrian Lang $class .= ' ' . $this->startSectionEdit($pos, 'table'); 946619736fdSAdrian Lang } 947619736fdSAdrian Lang $this->doc .= '<div class="' . $class . '"><table class="inline">' . 948619736fdSAdrian Lang DOKU_LF; 9490cecf9d5Sandi } 9500cecf9d5Sandi 951619736fdSAdrian Lang function table_close($pos = null){ 952a8574918SAnika Henke $this->doc .= '</table></div>'.DOKU_LF; 953619736fdSAdrian Lang if ($pos !== null) { 95490df9a4dSAdrian Lang $this->finishSectionEdit($pos); 9550cecf9d5Sandi } 956619736fdSAdrian Lang } 9570cecf9d5Sandi 9580cecf9d5Sandi function tablerow_open(){ 959b5742cedSPierre Spring // initialize the cell counter used for classes 960b5742cedSPierre Spring $this->_counter['cell_counter'] = 0; 961b5742cedSPierre Spring $class = 'row' . $this->_counter['row_counter']++; 962b5742cedSPierre Spring $this->doc .= DOKU_TAB . '<tr class="'.$class.'">' . DOKU_LF . DOKU_TAB . DOKU_TAB; 9630cecf9d5Sandi } 9640cecf9d5Sandi 9650cecf9d5Sandi function tablerow_close(){ 966a2d649c4Sandi $this->doc .= DOKU_LF . DOKU_TAB . '</tr>' . DOKU_LF; 9670cecf9d5Sandi } 9680cecf9d5Sandi 9690ea51e63SMatt Perry function tableheader_open($colspan = 1, $align = null, $rowspan = 1){ 970b5742cedSPierre Spring $class = 'class="col' . $this->_counter['cell_counter']++; 9710cecf9d5Sandi if ( !is_null($align) ) { 972b5742cedSPierre Spring $class .= ' '.$align.'align'; 9730cecf9d5Sandi } 974b5742cedSPierre Spring $class .= '"'; 975b5742cedSPierre Spring $this->doc .= '<th ' . $class; 9760cecf9d5Sandi if ( $colspan > 1 ) { 977a28fd914SAndreas Gohr $this->_counter['cell_counter'] += $colspan-1; 978a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 9790cecf9d5Sandi } 98025b97867Shakan.sandell if ( $rowspan > 1 ) { 98125b97867Shakan.sandell $this->doc .= ' rowspan="'.$rowspan.'"'; 98225b97867Shakan.sandell } 983a2d649c4Sandi $this->doc .= '>'; 9840cecf9d5Sandi } 9850cecf9d5Sandi 9860cecf9d5Sandi function tableheader_close(){ 987a2d649c4Sandi $this->doc .= '</th>'; 9880cecf9d5Sandi } 9890cecf9d5Sandi 9900ea51e63SMatt Perry function tablecell_open($colspan = 1, $align = null, $rowspan = 1){ 991b5742cedSPierre Spring $class = 'class="col' . $this->_counter['cell_counter']++; 9920cecf9d5Sandi if ( !is_null($align) ) { 993b5742cedSPierre Spring $class .= ' '.$align.'align'; 9940cecf9d5Sandi } 995b5742cedSPierre Spring $class .= '"'; 996b5742cedSPierre Spring $this->doc .= '<td '.$class; 9970cecf9d5Sandi if ( $colspan > 1 ) { 998a28fd914SAndreas Gohr $this->_counter['cell_counter'] += $colspan-1; 999a2d649c4Sandi $this->doc .= ' colspan="'.$colspan.'"'; 10000cecf9d5Sandi } 100125b97867Shakan.sandell if ( $rowspan > 1 ) { 100225b97867Shakan.sandell $this->doc .= ' rowspan="'.$rowspan.'"'; 100325b97867Shakan.sandell } 1004a2d649c4Sandi $this->doc .= '>'; 10050cecf9d5Sandi } 10060cecf9d5Sandi 10070cecf9d5Sandi function tablecell_close(){ 1008a2d649c4Sandi $this->doc .= '</td>'; 10090cecf9d5Sandi } 10100cecf9d5Sandi 10110cecf9d5Sandi //---------------------------------------------------------- 10120cecf9d5Sandi // Utils 10130cecf9d5Sandi 1014ba11bd29Sandi /** 10153fd0b676Sandi * Build a link 10163fd0b676Sandi * 10173fd0b676Sandi * Assembles all parts defined in $link returns HTML for the link 1018ba11bd29Sandi * 1019ba11bd29Sandi * @author Andreas Gohr <andi@splitbrain.org> 1020ba11bd29Sandi */ 1021433bef32Sandi function _formatLink($link){ 1022ba11bd29Sandi //make sure the url is XHTML compliant (skip mailto) 1023ba11bd29Sandi if(substr($link['url'],0,7) != 'mailto:'){ 1024ba11bd29Sandi $link['url'] = str_replace('&','&',$link['url']); 1025ba11bd29Sandi $link['url'] = str_replace('&amp;','&',$link['url']); 1026ba11bd29Sandi } 1027ba11bd29Sandi //remove double encodings in titles 1028ba11bd29Sandi $link['title'] = str_replace('&amp;','&',$link['title']); 1029ba11bd29Sandi 1030453493f2SAndreas Gohr // be sure there are no bad chars in url or title 1031453493f2SAndreas Gohr // (we can't do this for name because it can contain an img tag) 1032453493f2SAndreas Gohr $link['url'] = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22')); 1033453493f2SAndreas Gohr $link['title'] = strtr($link['title'],array('>'=>'>','<'=>'<','"'=>'"')); 1034453493f2SAndreas Gohr 1035ba11bd29Sandi $ret = ''; 1036ba11bd29Sandi $ret .= $link['pre']; 1037ba11bd29Sandi $ret .= '<a href="'.$link['url'].'"'; 1038bb4866bdSchris if(!empty($link['class'])) $ret .= ' class="'.$link['class'].'"'; 1039bb4866bdSchris if(!empty($link['target'])) $ret .= ' target="'.$link['target'].'"'; 1040bb4866bdSchris if(!empty($link['title'])) $ret .= ' title="'.$link['title'].'"'; 1041bb4866bdSchris if(!empty($link['style'])) $ret .= ' style="'.$link['style'].'"'; 104244a6b4c7SAndreas Gohr if(!empty($link['rel'])) $ret .= ' rel="'.$link['rel'].'"'; 1043bb4866bdSchris if(!empty($link['more'])) $ret .= ' '.$link['more']; 1044ba11bd29Sandi $ret .= '>'; 1045ba11bd29Sandi $ret .= $link['name']; 1046ba11bd29Sandi $ret .= '</a>'; 1047ba11bd29Sandi $ret .= $link['suf']; 1048ba11bd29Sandi return $ret; 1049ba11bd29Sandi } 1050ba11bd29Sandi 1051ba11bd29Sandi /** 10523fd0b676Sandi * Renders internal and external media 10533fd0b676Sandi * 10543fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 10553fd0b676Sandi */ 10560ea51e63SMatt Perry function _media ($src, $title=null, $align=null, $width=null, 10570ea51e63SMatt Perry $height=null, $cache=null, $render = true) { 10583fd0b676Sandi 10593fd0b676Sandi $ret = ''; 10603fd0b676Sandi 1061ecebf3a8SAndreas Gohr list($ext,$mime,$dl) = mimetype($src); 10623fd0b676Sandi if(substr($mime,0,5) == 'image'){ 1063b739ff0fSPierre Spring // first get the $title 1064b739ff0fSPierre Spring if (!is_null($title)) { 1065b739ff0fSPierre Spring $title = $this->_xmlEntities($title); 1066b739ff0fSPierre Spring }elseif($ext == 'jpg' || $ext == 'jpeg'){ 1067b739ff0fSPierre Spring //try to use the caption from IPTC/EXIF 1068b739ff0fSPierre Spring require_once(DOKU_INC.'inc/JpegMeta.php'); 106967f9913dSAndreas Gohr $jpeg =new JpegMeta(mediaFN($src)); 1070b739ff0fSPierre Spring if($jpeg !== false) $cap = $jpeg->getTitle(); 1071b739ff0fSPierre Spring if($cap){ 1072b739ff0fSPierre Spring $title = $this->_xmlEntities($cap); 1073b739ff0fSPierre Spring } 1074b739ff0fSPierre Spring } 1075b739ff0fSPierre Spring if (!$render) { 1076b739ff0fSPierre Spring // if the picture is not supposed to be rendered 1077b739ff0fSPierre Spring // return the title of the picture 1078b739ff0fSPierre Spring if (!$title) { 1079b739ff0fSPierre Spring // just show the sourcename 10803009a773SAndreas Gohr $title = $this->_xmlEntities(utf8_basename(noNS($src))); 1081b739ff0fSPierre Spring } 1082b739ff0fSPierre Spring return $title; 1083b739ff0fSPierre Spring } 10843fd0b676Sandi //add image tag 108552dc5eadSlisps $ret .= '<img src="'.ml($src,array('w'=>$width,'h'=>$height,'cache'=>$cache,'rev'=>$this->_getLastMediaRevisionAt($src))).'"'; 10863fd0b676Sandi $ret .= ' class="media'.$align.'"'; 10873fd0b676Sandi 1088b739ff0fSPierre Spring if ($title) { 1089b739ff0fSPierre Spring $ret .= ' title="' . $title . '"'; 1090b739ff0fSPierre Spring $ret .= ' alt="' . $title .'"'; 10913fd0b676Sandi }else{ 10923fd0b676Sandi $ret .= ' alt=""'; 10933fd0b676Sandi } 10943fd0b676Sandi 10953fd0b676Sandi if ( !is_null($width) ) 10963fd0b676Sandi $ret .= ' width="'.$this->_xmlEntities($width).'"'; 10973fd0b676Sandi 10983fd0b676Sandi if ( !is_null($height) ) 10993fd0b676Sandi $ret .= ' height="'.$this->_xmlEntities($height).'"'; 11003fd0b676Sandi 11013fd0b676Sandi $ret .= ' />'; 11023fd0b676Sandi 1103f50634f0SAnika Henke }elseif(media_supportedav($mime, 'video')){ 11042a2a2ba2SAnika Henke // first get the $title 11052a2a2ba2SAnika Henke if (!is_null($title)) { 11062a2a2ba2SAnika Henke $title = $this->_xmlEntities($title); 11072a2a2ba2SAnika Henke } 11082a2a2ba2SAnika Henke if (!$title) { 11092a2a2ba2SAnika Henke // just show the sourcename 11102a2a2ba2SAnika Henke $title = $this->_xmlEntities(utf8_basename(noNS($src))); 11112a2a2ba2SAnika Henke } 11122a2a2ba2SAnika Henke if (!$render) { 11132a2a2ba2SAnika Henke // if the video is not supposed to be rendered 11142a2a2ba2SAnika Henke // return the title of the video 11152a2a2ba2SAnika Henke return $title; 11162a2a2ba2SAnika Henke } 11172a2a2ba2SAnika Henke 11182a2a2ba2SAnika Henke $att = array(); 11192a2a2ba2SAnika Henke $att['class'] = "media$align"; 11202a2a2ba2SAnika Henke 11212a2a2ba2SAnika Henke //add video(s) 112279e53fe5SAnika Henke $ret .= $this->_video($src, $width, $height, $att); 11232a2a2ba2SAnika Henke 1124f50634f0SAnika Henke }elseif(media_supportedav($mime, 'audio')){ 1125b44a5dceSAnika Henke // first get the $title 1126b44a5dceSAnika Henke if (!is_null($title)) { 1127b44a5dceSAnika Henke $title = $this->_xmlEntities($title); 1128b44a5dceSAnika Henke } 1129b44a5dceSAnika Henke if (!$title) { 1130b44a5dceSAnika Henke // just show the sourcename 1131b44a5dceSAnika Henke $title = $this->_xmlEntities(utf8_basename(noNS($src))); 1132b44a5dceSAnika Henke } 1133b44a5dceSAnika Henke if (!$render) { 1134b44a5dceSAnika Henke // if the video is not supposed to be rendered 1135b44a5dceSAnika Henke // return the title of the video 1136b44a5dceSAnika Henke return $title; 1137b44a5dceSAnika Henke } 1138b44a5dceSAnika Henke 1139b44a5dceSAnika Henke $att = array(); 1140b44a5dceSAnika Henke $att['class'] = "media$align"; 1141b44a5dceSAnika Henke 1142b44a5dceSAnika Henke //add audio 1143b44a5dceSAnika Henke $ret .= $this->_audio($src, $att); 1144b44a5dceSAnika Henke 11453fd0b676Sandi }elseif($mime == 'application/x-shockwave-flash'){ 11461c882ba8SAndreas Gohr if (!$render) { 11471c882ba8SAndreas Gohr // if the flash is not supposed to be rendered 11481c882ba8SAndreas Gohr // return the title of the flash 11491c882ba8SAndreas Gohr if (!$title) { 11501c882ba8SAndreas Gohr // just show the sourcename 11513009a773SAndreas Gohr $title = utf8_basename(noNS($src)); 11521c882ba8SAndreas Gohr } 115307bf32b2SAndreas Gohr return $this->_xmlEntities($title); 11541c882ba8SAndreas Gohr } 11551c882ba8SAndreas Gohr 115607bf32b2SAndreas Gohr $att = array(); 115707bf32b2SAndreas Gohr $att['class'] = "media$align"; 115807bf32b2SAndreas Gohr if($align == 'right') $att['align'] = 'right'; 115907bf32b2SAndreas Gohr if($align == 'left') $att['align'] = 'left'; 1160c471e6a6SAndreas Gohr $ret .= html_flashobject(ml($src,array('cache'=>$cache),true,'&'),$width,$height, 116107bf32b2SAndreas Gohr array('quality' => 'high'), 116207bf32b2SAndreas Gohr null, 116307bf32b2SAndreas Gohr $att, 116407bf32b2SAndreas Gohr $this->_xmlEntities($title)); 11650f428d7dSAndreas Gohr }elseif($title){ 11663fd0b676Sandi // well at least we have a title to display 11673fd0b676Sandi $ret .= $this->_xmlEntities($title); 11683fd0b676Sandi }else{ 11695291ca3aSAndreas Gohr // just show the sourcename 11703009a773SAndreas Gohr $ret .= $this->_xmlEntities(utf8_basename(noNS($src))); 11713fd0b676Sandi } 11723fd0b676Sandi 11733fd0b676Sandi return $ret; 11743fd0b676Sandi } 11753fd0b676Sandi 1176433bef32Sandi function _xmlEntities($string) { 1177de117061Schris return htmlspecialchars($string,ENT_QUOTES,'UTF-8'); 11780cecf9d5Sandi } 11790cecf9d5Sandi 11808a831f2bSAndreas Gohr /** 11818a831f2bSAndreas Gohr * Creates a linkid from a headline 1182c5a8fd96SAndreas Gohr * 1183c5a8fd96SAndreas Gohr * @param string $title The headline title 1184c5a8fd96SAndreas Gohr * @param boolean $create Create a new unique ID? 1185c5a8fd96SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 11868a831f2bSAndreas Gohr */ 1187c5a8fd96SAndreas Gohr function _headerToLink($title,$create=false) { 1188c5a8fd96SAndreas Gohr if($create){ 11894ceab83fSAndreas Gohr return sectionID($title,$this->headers); 11904ceab83fSAndreas Gohr }else{ 1191443d207bSAndreas Gohr $check = false; 1192443d207bSAndreas Gohr return sectionID($title,$check); 1193c5a8fd96SAndreas Gohr } 11940cecf9d5Sandi } 11950cecf9d5Sandi 1196af587fa8Sandi /** 11973fd0b676Sandi * Construct a title and handle images in titles 11983fd0b676Sandi * 11990b7c14c2Sandi * @author Harry Fuecks <hfuecks@gmail.com> 12003fd0b676Sandi */ 12010ea51e63SMatt Perry function _getLinkTitle($title, $default, & $isImage, $id=null, $linktype='content') { 1202bb0a59d4Sjan global $conf; 1203bb0a59d4Sjan 120444881bd0Shenning.noren $isImage = false; 120529657f9eSAndreas Gohr if ( is_array($title) ) { 120629657f9eSAndreas Gohr $isImage = true; 120729657f9eSAndreas Gohr return $this->_imageTitle($title); 120829657f9eSAndreas Gohr } elseif ( is_null($title) || trim($title)=='') { 1209fe9ec250SChris Smith if (useHeading($linktype) && $id) { 121067c15eceSMichael Hamann $heading = p_get_first_heading($id); 1211bb0a59d4Sjan if ($heading) { 1212433bef32Sandi return $this->_xmlEntities($heading); 1213bb0a59d4Sjan } 1214bb0a59d4Sjan } 1215433bef32Sandi return $this->_xmlEntities($default); 121668c26e6dSMichael Klier } else { 121768c26e6dSMichael Klier return $this->_xmlEntities($title); 12180cecf9d5Sandi } 12190cecf9d5Sandi } 12200cecf9d5Sandi 12210cecf9d5Sandi /** 12223fd0b676Sandi * Returns an HTML code for images used in link titles 12233fd0b676Sandi * 12243fd0b676Sandi * @todo Resolve namespace on internal images 12253fd0b676Sandi * @author Andreas Gohr <andi@splitbrain.org> 12260cecf9d5Sandi */ 1227433bef32Sandi function _imageTitle($img) { 1228d9baf1a7SKazutaka Miyasaka global $ID; 1229d9baf1a7SKazutaka Miyasaka 1230d9baf1a7SKazutaka Miyasaka // some fixes on $img['src'] 1231d9baf1a7SKazutaka Miyasaka // see internalmedia() and externalmedia() 1232d9baf1a7SKazutaka Miyasaka list($img['src'],$hash) = explode('#',$img['src'],2); 1233d9baf1a7SKazutaka Miyasaka if ($img['type'] == 'internalmedia') { 1234*cdb5e961Slisps resolve_mediaid(getNS($ID),$img['src'],$exists,$this->date_at,true); 1235d9baf1a7SKazutaka Miyasaka } 1236d9baf1a7SKazutaka Miyasaka 1237433bef32Sandi return $this->_media($img['src'], 12384826ab45Sandi $img['title'], 12394826ab45Sandi $img['align'], 12404826ab45Sandi $img['width'], 12414826ab45Sandi $img['height'], 12424826ab45Sandi $img['cache']); 12430cecf9d5Sandi } 1244b739ff0fSPierre Spring 1245b739ff0fSPierre Spring /** 1246b739ff0fSPierre Spring * _getMediaLinkConf is a helperfunction to internalmedia() and externalmedia() 1247b739ff0fSPierre Spring * which returns a basic link to a media. 1248b739ff0fSPierre Spring * 1249b739ff0fSPierre Spring * @author Pierre Spring <pierre.spring@liip.ch> 1250b739ff0fSPierre Spring * @param string $src 1251b739ff0fSPierre Spring * @param string $title 1252b739ff0fSPierre Spring * @param string $align 1253b739ff0fSPierre Spring * @param string $width 1254b739ff0fSPierre Spring * @param string $height 1255b739ff0fSPierre Spring * @param string $cache 1256b739ff0fSPierre Spring * @param string $render 1257b739ff0fSPierre Spring * @access protected 1258b739ff0fSPierre Spring * @return array 1259b739ff0fSPierre Spring */ 1260d91ab76fSMatt Perry function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render) { 1261b739ff0fSPierre Spring global $conf; 1262b739ff0fSPierre Spring 1263b739ff0fSPierre Spring $link = array(); 1264b739ff0fSPierre Spring $link['class'] = 'media'; 1265b739ff0fSPierre Spring $link['style'] = ''; 1266b739ff0fSPierre Spring $link['pre'] = ''; 1267b739ff0fSPierre Spring $link['suf'] = ''; 1268b739ff0fSPierre Spring $link['more'] = ''; 1269b739ff0fSPierre Spring $link['target'] = $conf['target']['media']; 1270b739ff0fSPierre Spring $link['title'] = $this->_xmlEntities($src); 1271b739ff0fSPierre Spring $link['name'] = $this->_media($src, $title, $align, $width, $height, $cache, $render); 1272b739ff0fSPierre Spring 1273b739ff0fSPierre Spring return $link; 1274b739ff0fSPierre Spring } 127591459163SAnika Henke 1276df0e21b4Slisps 1277df0e21b4Slisps /** 1278df0e21b4Slisps * Embed video(s) in HTML 1279df0e21b4Slisps * 1280df0e21b4Slisps * @author Anika Henke <anika@selfthinker.org> 1281df0e21b4Slisps * 1282df0e21b4Slisps * @param string $src - ID of video to embed 1283df0e21b4Slisps * @param int $width - width of the video in pixels 1284df0e21b4Slisps * @param int $height - height of the video in pixels 1285df0e21b4Slisps * @param array $atts - additional attributes for the <video> tag 1286df0e21b4Slisps * @return string 1287df0e21b4Slisps */ 1288df0e21b4Slisps function _video($src,$width,$height,$atts=null){ 1289df0e21b4Slisps 1290df0e21b4Slisps // prepare width and height 1291df0e21b4Slisps if(is_null($atts)) $atts = array(); 1292df0e21b4Slisps $atts['width'] = (int) $width; 1293df0e21b4Slisps $atts['height'] = (int) $height; 1294df0e21b4Slisps if(!$atts['width']) $atts['width'] = 320; 1295df0e21b4Slisps if(!$atts['height']) $atts['height'] = 240; 1296df0e21b4Slisps 1297df0e21b4Slisps // prepare alternative formats 1298df0e21b4Slisps $extensions = array('webm', 'ogv', 'mp4'); 1299df0e21b4Slisps $alternatives = media_alternativefiles($src, $extensions); 1300df0e21b4Slisps $poster = media_alternativefiles($src, array('jpg', 'png'), true); 1301df0e21b4Slisps $posterUrl = ''; 1302df0e21b4Slisps if (!empty($poster)) { 1303df0e21b4Slisps $posterUrl = ml(reset($poster),array('cache'=>$cache),true,'&'); 1304df0e21b4Slisps } 1305df0e21b4Slisps 1306df0e21b4Slisps $out = ''; 1307df0e21b4Slisps // open video tag 1308df0e21b4Slisps $out .= '<video '.buildAttributes($atts).' controls="controls"'; 1309df0e21b4Slisps if ($posterUrl) $out .= ' poster="'.hsc($posterUrl).'"'; 1310df0e21b4Slisps $out .= '>'.NL; 1311df0e21b4Slisps $fallback = ''; 1312df0e21b4Slisps 1313df0e21b4Slisps // output source for each alternative video format 1314df0e21b4Slisps foreach($alternatives as $mime => $file) { 1315df0e21b4Slisps $url = ml($file,array('cache'=>$cache),true,'&'); 1316df0e21b4Slisps $title = $this->_xmlEntities(utf8_basename(noNS($file))); 1317df0e21b4Slisps 1318df0e21b4Slisps $out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL; 1319df0e21b4Slisps // alternative content (just a link to the file) 1320df0e21b4Slisps $fallback .= $this->internalmedia($file, $title, NULL, NULL, NULL, $cache=NULL, $linking='linkonly', $return=true); 1321df0e21b4Slisps } 1322df0e21b4Slisps 1323df0e21b4Slisps // finish 1324df0e21b4Slisps $out .= $fallback; 1325df0e21b4Slisps $out .= '</video>'.NL; 1326df0e21b4Slisps return $out; 1327df0e21b4Slisps } 1328df0e21b4Slisps 1329df0e21b4Slisps /** 1330df0e21b4Slisps * Embed audio in HTML 1331df0e21b4Slisps * 1332df0e21b4Slisps * @author Anika Henke <anika@selfthinker.org> 1333df0e21b4Slisps * 1334df0e21b4Slisps * @param string $src - ID of audio to embed 1335df0e21b4Slisps * @param array $atts - additional attributes for the <audio> tag 1336df0e21b4Slisps * @return string 1337df0e21b4Slisps */ 1338df0e21b4Slisps function _audio($src,$atts=null){ 1339df0e21b4Slisps 1340df0e21b4Slisps // prepare alternative formats 1341df0e21b4Slisps $extensions = array('ogg', 'mp3', 'wav'); 1342df0e21b4Slisps $alternatives = media_alternativefiles($src, $extensions); 1343df0e21b4Slisps 1344df0e21b4Slisps $out = ''; 1345df0e21b4Slisps // open audio tag 1346df0e21b4Slisps $out .= '<audio '.buildAttributes($atts).' controls="controls">'.NL; 1347df0e21b4Slisps $fallback = ''; 1348df0e21b4Slisps 1349df0e21b4Slisps // output source for each alternative audio format 1350df0e21b4Slisps foreach($alternatives as $mime => $file) { 1351df0e21b4Slisps $url = ml($file,array('cache'=>$cache),true,'&'); 1352df0e21b4Slisps $title = $this->_xmlEntities(utf8_basename(noNS($file))); 1353df0e21b4Slisps 1354df0e21b4Slisps $out .= '<source src="'.hsc($url).'" type="'.$mime.'" />'.NL; 1355df0e21b4Slisps // alternative content (just a link to the file) 1356df0e21b4Slisps $fallback .= $this->internalmedia($file, $title, NULL, NULL, NULL, $cache=NULL, $linking='linkonly', $return=true); 1357df0e21b4Slisps } 1358df0e21b4Slisps 1359df0e21b4Slisps // finish 1360df0e21b4Slisps $out .= $fallback; 1361df0e21b4Slisps $out .= '</audio>'.NL; 1362df0e21b4Slisps return $out; 1363df0e21b4Slisps } 1364df0e21b4Slisps 13655c2eed9aSlisps /** 136652dc5eadSlisps * _getLastMediaRevisionAt is a helperfunction to internalmedia() and _media() 13675c2eed9aSlisps * which returns an existing media revision less or equal to rev or date_at 13685c2eed9aSlisps * 13695c2eed9aSlisps * @author lisps 13705c2eed9aSlisps * @param string $media_id 13715c2eed9aSlisps * @access protected 13725c2eed9aSlisps * @return string revision ('' for current) 13735c2eed9aSlisps */ 137452dc5eadSlisps function _getLastMediaRevisionAt($media_id){ 137552dc5eadSlisps if(!$this->date_at || media_isexternal($media_id)) return ''; 137678b874e6Slisps $pagelog = new MediaChangeLog($media_id); 137778b874e6Slisps return $pagelog->getLastRevisionAt($this->date_at); 13785c2eed9aSlisps } 13795c2eed9aSlisps 13800cecf9d5Sandi} 13810cecf9d5Sandi 1382e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 : 1383