*/
function html($text, $wrapper='code') {
global $conf;
if($conf['htmlok']){
$this->doc .= $text;
} else {
$this->doc .= p_xhtml_cached_geshi($text, 'html4strict', $wrapper);
}
}
function htmlblock($text) {
$this->html($text, 'pre');
}
function preformatted($text) {
$this->doc .= '' . trim($this->_xmlEntities($text),"\n\r") . '
'. DOKU_LF;
}
function file($text) {
$this->doc .= '' . trim($this->_xmlEntities($text),"\n\r"). '
'. DOKU_LF;
}
function quote_open() {
$this->doc .= ''.DOKU_LF;
}
function quote_close() {
$this->doc .= '
'.DOKU_LF;
}
/**
* Callback for code text
*
* Uses GeSHi to highlight language syntax
*
* @author Andreas Gohr
*/
function code($text, $language = NULL) {
global $conf;
if ( is_null($language) ) {
$this->preformatted($text);
} else {
$this->doc .= p_xhtml_cached_geshi($text, $language);
}
}
function acronym($acronym) {
if ( array_key_exists($acronym, $this->acronyms) ) {
$title = $this->_xmlEntities($this->acronyms[$acronym]);
$this->doc .= ''.$this->_xmlEntities($acronym).'';
} else {
$this->doc .= $this->_xmlEntities($acronym);
}
}
function smiley($smiley) {
if ( array_key_exists($smiley, $this->smileys) ) {
$title = $this->_xmlEntities($this->smileys[$smiley]);
$this->doc .= '
';
} else {
$this->doc .= $this->_xmlEntities($smiley);
}
}
/*
* not used
function wordblock($word) {
if ( array_key_exists($word, $this->badwords) ) {
$this->doc .= '** BLEEP **';
} else {
$this->doc .= $this->_xmlEntities($word);
}
}
*/
function entity($entity) {
if ( array_key_exists($entity, $this->entities) ) {
$this->doc .= $this->entities[$entity];
} else {
$this->doc .= $this->_xmlEntities($entity);
}
}
function multiplyentity($x, $y) {
$this->doc .= "$x×$y";
}
function singlequoteopening() {
global $lang;
$this->doc .= $lang['singlequoteopening'];
}
function singlequoteclosing() {
global $lang;
$this->doc .= $lang['singlequoteclosing'];
}
function apostrophe() {
global $lang;
$this->doc .= $lang['apostrophe'];
}
function doublequoteopening() {
global $lang;
$this->doc .= $lang['doublequoteopening'];
}
function doublequoteclosing() {
global $lang;
$this->doc .= $lang['doublequoteclosing'];
}
/**
*/
function camelcaselink($link) {
$this->internallink($link,$link);
}
function locallink($hash, $name = NULL){
global $ID;
$name = $this->_getLinkTitle($name, $hash, $isImage);
$hash = $this->_headerToLink($hash);
$title = $ID.' ↵';
$this->doc .= '';
$this->doc .= $name;
$this->doc .= '';
}
/**
* Render an internal Wiki Link
*
* $search,$returnonly & $linktype are not for the renderer but are used
* elsewhere - no need to implement them in other renderers
*
* @author Andreas Gohr
*/
function internallink($id, $name = NULL, $search=NULL,$returnonly=false,$linktype='content') {
global $conf;
global $ID;
// default name is based on $id as given
$default = $this->_simpleTitle($id);
// now first resolve and clean up the $id
resolve_pageid(getNS($ID),$id,$exists);
$name = $this->_getLinkTitle($name, $default, $isImage, $id, $linktype);
if ( !$isImage ) {
if ( $exists ) {
$class='wikilink1';
} else {
$class='wikilink2';
$link['rel']='nofollow';
}
} else {
$class='media';
}
//keep hash anchor
list($id,$hash) = explode('#',$id,2);
if(!empty($hash)) $hash = $this->_headerToLink($hash);
//prepare for formating
$link['target'] = $conf['target']['wiki'];
$link['style'] = '';
$link['pre'] = '';
$link['suf'] = '';
// highlight link to current page
if ($id == $ID) {
$link['pre'] = '';
$link['suf'] = '';
}
$link['more'] = '';
$link['class'] = $class;
$link['url'] = wl($id);
$link['name'] = $name;
$link['title'] = $id;
//add search string
if($search){
($conf['userewrite']) ? $link['url'].='?' : $link['url'].='&';
if(is_array($search)){
$search = array_map('rawurlencode',$search);
$link['url'] .= 's[]='.join('&s[]=',$search);
}else{
$link['url'] .= 's='.rawurlencode($search);
}
}
//keep hash
if($hash) $link['url'].='#'.$hash;
//output formatted
if($returnonly){
return $this->_formatLink($link);
}else{
$this->doc .= $this->_formatLink($link);
}
}
function externallink($url, $name = NULL) {
global $conf;
$name = $this->_getLinkTitle($name, $url, $isImage);
if ( !$isImage ) {
$class='urlextern';
} else {
$class='media';
}
//prepare for formating
$link['target'] = $conf['target']['extern'];
$link['style'] = '';
$link['pre'] = '';
$link['suf'] = '';
$link['more'] = '';
$link['class'] = $class;
$link['url'] = $url;
$link['name'] = $name;
$link['title'] = $this->_xmlEntities($url);
if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"';
//output formatted
$this->doc .= $this->_formatLink($link);
}
/**
*/
function interwikilink($match, $name = NULL, $wikiName, $wikiUri) {
global $conf;
$link = array();
$link['target'] = $conf['target']['interwiki'];
$link['pre'] = '';
$link['suf'] = '';
$link['more'] = '';
$link['name'] = $this->_getLinkTitle($name, $wikiUri, $isImage);
//get interwiki URL
$url = $this->_resolveInterWiki($wikiName,$wikiUri);
if ( !$isImage ) {
$class = preg_replace('/[^_\-a-z0-9]+/i','_',$wikiName);
$link['class'] = "interwiki iw_$class";
} else {
$link['class'] = 'media';
}
//do we stay at the same server? Use local target
if( strpos($url,DOKU_URL) === 0 ){
$link['target'] = $conf['target']['wiki'];
}
$link['url'] = $url;
$link['title'] = htmlspecialchars($link['url']);
//output formatted
$this->doc .= $this->_formatLink($link);
}
/**
*/
function windowssharelink($url, $name = NULL) {
global $conf;
global $lang;
//simple setup
$link['target'] = $conf['target']['windows'];
$link['pre'] = '';
$link['suf'] = '';
$link['style'] = '';
$link['name'] = $this->_getLinkTitle($name, $url, $isImage);
if ( !$isImage ) {
$link['class'] = 'windows';
} else {
$link['class'] = 'media';
}
$link['title'] = $this->_xmlEntities($url);
$url = str_replace('\\','/',$url);
$url = 'file:///'.$url;
$link['url'] = $url;
//output formatted
$this->doc .= $this->_formatLink($link);
}
function emaillink($address, $name = NULL) {
global $conf;
//simple setup
$link = array();
$link['target'] = '';
$link['pre'] = '';
$link['suf'] = '';
$link['style'] = '';
$link['more'] = '';
$name = $this->_getLinkTitle($name, $address, $isImage);
if ( !$isImage ) {
$link['class']='mail JSnocheck';
} else {
$link['class']='media JSnocheck';
}
$address = $this->_xmlEntities($address);
$address = obfuscate($address);
$title = $address;
if(empty($name)){
$name = $address;
}
#elseif($isImage{
# $name = $this->_xmlEntities($name);
# }
if($conf['mailguard'] == 'visible') $address = rawurlencode($address);
$link['url'] = 'mailto:'.$address;
$link['name'] = $name;
$link['title'] = $title;
//output formatted
$this->doc .= $this->_formatLink($link);
}
function internalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
$height=NULL, $cache=NULL, $linking=NULL) {
global $ID;
list($src,$hash) = explode('#',$src,2);
resolve_mediaid(getNS($ID),$src, $exists);
$noLink = false;
$render = ($linking == 'linkonly') ? false : true;
$link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
list($ext,$mime,$dl) = mimetype($src);
if(substr($mime,0,5) == 'image' && $render){
$link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),($linking=='direct'));
}elseif($mime == 'application/x-shockwave-flash' && $render){
// don't link flash movies
$noLink = true;
}else{
// add file icons
$class = preg_replace('/[^_\-a-z0-9]+/i','_',$ext);
$link['class'] .= ' mediafile mf_'.$class;
$link['url'] = ml($src,array('id'=>$ID,'cache'=>$cache),true);
}
if($hash) $link['url'] .= '#'.$hash;
//markup non existing files
if (!$exists)
$link['class'] .= ' wikilink2';
//output formatted
if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
else $this->doc .= $this->_formatLink($link);
}
function externalmedia ($src, $title=NULL, $align=NULL, $width=NULL,
$height=NULL, $cache=NULL, $linking=NULL) {
list($src,$hash) = explode('#',$src,2);
$noLink = false;
$render = ($linking == 'linkonly') ? false : true;
$link = $this->_getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render);
$link['url'] = ml($src,array('cache'=>$cache));
list($ext,$mime,$dl) = mimetype($src);
if(substr($mime,0,5) == 'image' && $render){
// link only jpeg images
// if ($ext != 'jpg' && $ext != 'jpeg') $noLink = true;
}elseif($mime == 'application/x-shockwave-flash' && $render){
// don't link flash movies
$noLink = true;
}else{
// add file icons
$link['class'] .= ' mediafile mf_'.$ext;
}
if($hash) $link['url'] .= '#'.$hash;
//output formatted
if ($linking == 'nolink' || $noLink) $this->doc .= $link['name'];
else $this->doc .= $this->_formatLink($link);
}
/**
* Renders an RSS feed
*
* @author Andreas Gohr
*/
function rss ($url,$params){
global $lang;
global $conf;
require_once(DOKU_INC.'inc/FeedParser.php');
$feed = new FeedParser();
$feed->set_feed_url($url);
//disable warning while fetching
if (!defined('DOKU_E_LEVEL')) { $elvl = error_reporting(E_ERROR); }
$rc = $feed->init();
if (!defined('DOKU_E_LEVEL')) { error_reporting($elvl); }
//decide on start and end
if($params['reverse']){
$mod = -1;
$start = $feed->get_item_quantity()-1;
$end = $start - ($params['max']);
$end = ($end < -1) ? -1 : $end;
}else{
$mod = 1;
$start = 0;
$end = $feed->get_item_quantity();
$end = ($end > $params['max']) ? $params['max'] : $end;;
}
$this->doc .= '';
}
// $numrows not yet implemented
function table_open($maxcols = NULL, $numrows = NULL){
// initialize the row counter used for classes
$this->_counter['row_counter'] = 0;
$this->doc .= ''.DOKU_LF;
}
function table_close(){
$this->doc .= '
'.DOKU_LF;
}
function tablerow_open(){
// initialize the cell counter used for classes
$this->_counter['cell_counter'] = 0;
$class = 'row' . $this->_counter['row_counter']++;
$this->doc .= DOKU_TAB . '' . DOKU_LF . DOKU_TAB . DOKU_TAB;
}
function tablerow_close(){
$this->doc .= DOKU_LF . DOKU_TAB . '
' . DOKU_LF;
}
function tableheader_open($colspan = 1, $align = NULL){
$class = 'class="col' . $this->_counter['cell_counter']++;
if ( !is_null($align) ) {
$class .= ' '.$align.'align';
}
$class .= '"';
$this->doc .= ' 1 ) {
$this->_counter['cell_counter'] += $colspan-1;
$this->doc .= ' colspan="'.$colspan.'"';
}
$this->doc .= '>';
}
function tableheader_close(){
$this->doc .= ' | ';
}
function tablecell_open($colspan = 1, $align = NULL){
$class = 'class="col' . $this->_counter['cell_counter']++;
if ( !is_null($align) ) {
$class .= ' '.$align.'align';
}
$class .= '"';
$this->doc .= ' 1 ) {
$this->_counter['cell_counter'] += $colspan-1;
$this->doc .= ' colspan="'.$colspan.'"';
}
$this->doc .= '>';
}
function tablecell_close(){
$this->doc .= ' | ';
}
//----------------------------------------------------------
// Utils
/**
* Build a link
*
* Assembles all parts defined in $link returns HTML for the link
*
* @author Andreas Gohr
*/
function _formatLink($link){
//make sure the url is XHTML compliant (skip mailto)
if(substr($link['url'],0,7) != 'mailto:'){
$link['url'] = str_replace('&','&',$link['url']);
$link['url'] = str_replace('&','&',$link['url']);
}
//remove double encodings in titles
$link['title'] = str_replace('&','&',$link['title']);
// be sure there are no bad chars in url or title
// (we can't do this for name because it can contain an img tag)
$link['url'] = strtr($link['url'],array('>'=>'%3E','<'=>'%3C','"'=>'%22'));
$link['title'] = strtr($link['title'],array('>'=>'>','<'=>'<','"'=>'"'));
$ret = '';
$ret .= $link['pre'];
$ret .= '
*/
function _media ($src, $title=NULL, $align=NULL, $width=NULL,
$height=NULL, $cache=NULL, $render = true) {
$ret = '';
list($ext,$mime,$dl) = mimetype($src);
if(substr($mime,0,5) == 'image'){
// first get the $title
if (!is_null($title)) {
$title = $this->_xmlEntities($title);
}elseif($ext == 'jpg' || $ext == 'jpeg'){
//try to use the caption from IPTC/EXIF
require_once(DOKU_INC.'inc/JpegMeta.php');
$jpeg =& new JpegMeta(mediaFN($src));
if($jpeg !== false) $cap = $jpeg->getTitle();
if($cap){
$title = $this->_xmlEntities($cap);
}
}
if (!$render) {
// if the picture is not supposed to be rendered
// return the title of the picture
if (!$title) {
// just show the sourcename
$title = $this->_xmlEntities(basename(noNS($src)));
}
return $title;
}
//add image tag
$ret .= '
_xmlEntities($width).'"';
if ( !is_null($height) )
$ret .= ' height="'.$this->_xmlEntities($height).'"';
$ret .= ' />';
}elseif($mime == 'application/x-shockwave-flash'){
if (!$render) {
// if the flash is not supposed to be rendered
// return the title of the flash
if (!$title) {
// just show the sourcename
$title = basename(noNS($src));
}
return $this->_xmlEntities($title);
}
$att = array();
$att['class'] = "media$align";
if($align == 'right') $att['align'] = 'right';
if($align == 'left') $att['align'] = 'left';
$ret .= html_flashobject(ml($src,array('cache'=>$cache)),$width,$height,
array('quality' => 'high'),
null,
$att,
$this->_xmlEntities($title));
}elseif($title){
// well at least we have a title to display
$ret .= $this->_xmlEntities($title);
}else{
// just show the sourcename
$ret .= $this->_xmlEntities(basename(noNS($src)));
}
return $ret;
}
function _xmlEntities($string) {
return htmlspecialchars($string,ENT_QUOTES,'UTF-8');
}
/**
* Creates a linkid from a headline
*
* @param string $title The headline title
* @param boolean $create Create a new unique ID?
* @author Andreas Gohr
*/
function _headerToLink($title,$create=false) {
if($create){
return sectionID($title,$this->headers);
}else{
$check = false;
return sectionID($title,$check);
}
}
/**
* Construct a title and handle images in titles
*
* @author Harry Fuecks
*/
function _getLinkTitle($title, $default, & $isImage, $id=NULL, $linktype='content') {
global $conf;
$isImage = false;
if ( is_null($title) || trim($title)=='') {
if (useHeading($linktype) && $id) {
$heading = p_get_first_heading($id,true);
if ($heading) {
return $this->_xmlEntities($heading);
}
}
return $this->_xmlEntities($default);
} else if ( is_array($title) ) {
$isImage = true;
return $this->_imageTitle($title);
} else {
return $this->_xmlEntities($title);
}
}
/**
* Returns an HTML code for images used in link titles
*
* @todo Resolve namespace on internal images
* @author Andreas Gohr
*/
function _imageTitle($img) {
return $this->_media($img['src'],
$img['title'],
$img['align'],
$img['width'],
$img['height'],
$img['cache']);
}
/**
* _getMediaLinkConf is a helperfunction to internalmedia() and externalmedia()
* which returns a basic link to a media.
*
* @author Pierre Spring
* @param string $src
* @param string $title
* @param string $align
* @param string $width
* @param string $height
* @param string $cache
* @param string $render
* @access protected
* @return array
*/
function _getMediaLinkConf($src, $title, $align, $width, $height, $cache, $render)
{
global $conf;
$link = array();
$link['class'] = 'media';
$link['style'] = '';
$link['pre'] = '';
$link['suf'] = '';
$link['more'] = '';
$link['target'] = $conf['target']['media'];
$link['title'] = $this->_xmlEntities($src);
$link['name'] = $this->_media($src, $title, $align, $width, $height, $cache, $render);
return $link;
}
}
//Setup VIM: ex: et ts=4 enc=utf-8 :