diff options
Diffstat (limited to 'inc/parser')
-rw-r--r-- | inc/parser/action.php | 93 | ||||
-rw-r--r-- | inc/parser/handler.php | 27 | ||||
-rw-r--r-- | inc/parser/parser.php | 13 | ||||
-rw-r--r-- | inc/parser/xhtml.php | 95 |
4 files changed, 102 insertions, 126 deletions
diff --git a/inc/parser/action.php b/inc/parser/action.php index 3935bbeae..4426c1ac5 100644 --- a/inc/parser/action.php +++ b/inc/parser/action.php @@ -7,8 +7,14 @@ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); -require_once(DOKU_INC.'inc/utils.php'); +require_once(DOKU_INC.'inc/confutils.php'); +/** + * turns a page into a list of instructions + * + * @author Harry Fuecks <hfuecks@gmail.com> + * @author Andreas Gohr <andi@splitbrain.org> + */ function parse_to_instructions($text){ global $conf; @@ -46,7 +52,6 @@ function parse_to_instructions($text){ $Parser->addMode('file',new Doku_Parser_Mode_File()); $Parser->addMode('quote',new Doku_Parser_Mode_Quote()); - // FIXME These need data files... $Parser->addMode('smiley',new Doku_Parser_Mode_Smiley(array_keys(getSmileys()))); $Parser->addMode('acronym',new Doku_Parser_Mode_Acronym(array_keys(getAcronyms()))); #$Parser->addMode('wordblock',new Doku_Parser_Mode_Wordblock(getBadWords())); @@ -60,6 +65,7 @@ function parse_to_instructions($text){ } $Parser->addMode('internallink',new Doku_Parser_Mode_InternalLink()); + $Parser->addMode('rss',new Doku_Parser_Mode_RSS()); $Parser->addMode('media',new Doku_Parser_Mode_Media()); $Parser->addMode('externallink',new Doku_Parser_Mode_ExternalLink()); $Parser->addMode('email',new Doku_Parser_Mode_Email()); @@ -71,6 +77,12 @@ function parse_to_instructions($text){ return $Parser->parse($text); } +/** + * Renders a list of instruction to XHTML + * + * @author Harry Fuecks <hfuecks@gmail.com> + * @author Andreas Gohr <andi@splitbrain.org> + */ function render_as_xhtml($instructions){ #dbg($instructions); @@ -79,7 +91,6 @@ function render_as_xhtml($instructions){ require_once DOKU_INC . 'inc/parser/xhtml.php'; $Renderer = & new Doku_Renderer_XHTML(); - //FIXME add data $Renderer->smileys = getSmileys(); $Renderer->entities = getEntities(); $Renderer->acronyms = getAcronyms(); @@ -95,80 +106,4 @@ function render_as_xhtml($instructions){ return $Renderer->doc; } -/** - * Returns a full media id - * - * @author Andreas Gohr <andi@splitbrain.org> - * @todo move to utils? - */ -function resolve_mediaid(&$page,&$exists){ - global $ID; - global $conf; - $ns = getNS($ID); - //if links starts with . add current namespace - if($page{0} == '.'){ - $page = $ns.':'.substr($page,1); - } - - //if link contains no namespace. add current namespace (if any) - if($ns !== false && strpos($page,':') === false){ - $page = $ns.':'.$page; - } - - $page = cleanID($page); - $file = mediaFN($page); - $exists = @file_exists($file); -} - -/** - * Returns a full page id - * - * @todo move to utils? - */ -function resolve_pageid(&$page,&$exists){ - global $ID; - global $conf; - $ns = getNS($ID); - - //if links starts with . add current namespace - if($page{0} == '.'){ - $page = $ns.':'.substr($page,1); - } - - //if link contains no namespace. add current namespace (if any) - if($ns !== false && strpos($page,':') === false){ - $page = $ns.':'.$page; - } - - //keep hashlink if exists then clean both parts - list($page,$hash) = split('#',$page,2); - $page = cleanID($page); - $hash = cleanID($hash); - - $file = wikiFN($page); - - $exists = false; - - //check alternative plural/nonplural form - if(!@file_exists($file)){ - if( $conf['autoplural'] ){ - if(substr($page,-1) == 's'){ - $try = substr($page,0,-1); - }else{ - $try = $page.'s'; - } - if(@file_exists(wikiFN($try))){ - $page = $try; - $exists = true; - } - } - }else{ - $exists = true; - } - - //add hash if any - if(!empty($hash)) $page.'#'.$hash; -} - - //Setup VIM: ex: et ts=2 enc=utf-8 : diff --git a/inc/parser/handler.php b/inc/parser/handler.php index 108a522a5..f36a4f151 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -357,12 +357,7 @@ class Doku_Handler { // If the title is an image, convert it to an array containing the image details } else if ( preg_match('/^\{\{[^\}]+\}\}$/',$link[1]) ) { - $media = Doku_Handler_Parse_Media($link[1]); - - // Check it's really an image, not a link to a file - if ( !strpos($media['type'], 'link') ) { - $link[1] = $media; - } + $link[1] = Doku_Handler_Parse_Media($link[1]); } //decide which kind of link it is @@ -421,18 +416,18 @@ class Doku_Handler { function media($match, $state, $pos) { $p = Doku_Handler_Parse_Media($match); - // If it's not an image, build a normal link - if ( strpos($p['type'], 'link') ) { - $this->__addCall($p['type'],array($p['src'], $p['title']), $pos); - } else { - $this->__addCall( - $p['type'], - array($p['src'], $p['title'], $p['align'], $p['width'], $p['height'], $p['cache']), - $pos - ); - } + $this->__addCall( + $p['type'], + array($p['src'], $p['title'], $p['align'], $p['width'], $p['height'], $p['cache']), + $pos + ); return TRUE; } + + function rss($match, $state, $pos) { + $link = preg_replace(array('/^\{\{rss>/','/\}\}$/'),'',$match); + $this->__addCall('rss',array($link),$pos); + } function externallink($match, $state, $pos) { // Prevent use of multibyte strings in URLs diff --git a/inc/parser/parser.php b/inc/parser/parser.php index d1d039ad7..7e122bffc 100644 --- a/inc/parser/parser.php +++ b/inc/parser/parser.php @@ -660,6 +660,15 @@ class Doku_Parser_Mode_Media extends Doku_Parser_Mode { } //------------------------------------------------------------------- +class Doku_Parser_Mode_RSS extends Doku_Parser_Mode { + + function connectTo($mode) { + $this->Lexer->addSpecialPattern("\{\{rss>[^\}]+\}\}",$mode,'rss'); + } + +} + +//------------------------------------------------------------------- class Doku_Parser_Mode_ExternalLink extends Doku_Parser_Mode { var $schemes = array('http','https','telnet','gopher','wais','ftp','ed2k','irc'); var $patterns = array(); @@ -801,7 +810,7 @@ function Doku_Parser_Substition() { 'acronym','smiley','wordblock','entity','camelcaselink', 'internallink','media','externallink','linebreak','email', 'windowssharelink','filelink','notoc','multiplyentity', - 'quotes', + 'quotes','rss' ); return $modes; @@ -826,4 +835,4 @@ function Doku_Parser_Disabled() { } -//Setup VIM: ex: et ts=2 enc=utf-8 : +//Setup VIM: ex: et ts=4 enc=utf-8 : diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 377b514be..83d498b47 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -1,4 +1,11 @@ <?php +/** + * Renderer for XHTML output + * + * @author Harry Fuecks <hfuecks@gmail.com> + * @author Andreas Gohr <andi@splitbrain.org> + */ + if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); if ( !defined('DOKU_LF') ) { @@ -14,8 +21,8 @@ if ( !defined('DOKU_TAB') ) { require_once DOKU_INC . 'inc/parser/renderer.php'; /** -* @TODO Probably useful for have constant for linefeed formatting -*/ + * The Renderer + */ class Doku_Renderer_XHTML extends Doku_Renderer { var $doc = ''; @@ -381,10 +388,6 @@ class Doku_Renderer_XHTML extends Doku_Renderer { $this->internallink($link,$link); } - /** - * @TODO Support media - * @TODO correct attributes - */ function internallink($id, $name = NULL) { global $conf; @@ -416,37 +419,38 @@ class Doku_Renderer_XHTML extends Doku_Renderer { echo $this->__formatLink($link); } - - /** - * @TODO Should list assume blacklist check already made? - * @TODO External link icon - * @TODO correct attributes - */ - function externallink($link, $title = NULL) { - - echo '<a'; - - $title = $this->__getLinkTitle($title, $link, $isImage); + function externallink($url, $name = NULL) { + global $conf; + + $name = $this->__getLinkTitle($name, $url, $isImage); if ( !$isImage ) { - echo ' class="urlextern"'; + $class='urlextern'; } else { - echo ' class="media"'; + $class='media'; } - echo ' target="_blank" href="'.$this->__xmlEntities($link).'"'; - - echo ' onclick="return svchk()" onkeypress="return svchk()">'; - - echo $title; - - echo '</a>'; + //prepare for formating + $link['target'] = $conf['target']['extern']; + $link['style'] = ''; + $link['pre'] = ''; + $link['suf'] = ''; + $link['more'] = 'onclick="return svchk()" onkeypress="return svchk()"'; + $link['class'] = $class; + $link['url'] = $url; + $link['name'] = $name; + $link['title'] = $this->__xmlEntities($url); + if($conf['relnofollow']) $link['more'] .= ' rel="nofollow"'; + + //output formatted + echo $this->__formatLink($link); } /** * @TODO Remove hard coded link to splitbrain.org on style */ function interwikilink($link, $title = NULL, $wikiName, $wikiUri) { + global $conf; // RESOLVE THE URL if ( isset($this->interwiki[$wikiName]) ) { @@ -615,10 +619,44 @@ class Doku_Renderer_XHTML extends Doku_Renderer { } /** + * Renders an RSS feed using magpie + * + * @author Andreas Gohr <andi@splitbrain.org> + */ + function rss ($url){ + global $lang; + define('MAGPIE_CACHE_ON', false); //we do our own caching + define('MAGPIE_DIR', DOKU_INC.'inc/magpie/'); + define('MAGPIE_OUTPUT_ENCODING','UTF-8'); //return all feeds as UTF-8 + require_once(MAGPIE_DIR.'/rss_fetch.inc'); + + //disable warning while fetching + $elvl = error_reporting(E_ERROR); + $rss = fetch_rss($url); + error_reporting($elvl); + + print '<ul class="rss">'; + if($rss){ + foreach ($rss->items as $item ) { + print '<li>'; + $this->externallink($item['link'],$item['title']); + print '</li>'; + } + }else{ + print '<li>'; + print '<em>'.$lang['rssfailed'].'</em>'; + $this->externallink($url); + print '</li>'; + } + print '</ul>'; + } + + /** * Renders internal and external media * * @author Andreas Gohr <andi@splitbrain.org> * @todo handle center align + * @todo move to bottom */ function __media ($src, $title=NULL, $align=NULL, $width=NULL, $height=NULL, $cache=NULL) { @@ -629,9 +667,8 @@ class Doku_Renderer_XHTML extends Doku_Renderer { if(substr($mime,0,5) == 'image'){ //add image tag $ret .= '<img class="media" src="'. - DOKU_BASE.'fetch.php?media='.urlencode($src). - '&w='.$width.'&h='.$height. - '&cache='.$cache.'"'; + DOKU_BASE.'fetch.php?w='.$width.'&h='.$height. + '&cache='.$cache.'&media='.urlencode($src).'"'; if (!is_null($title)) $ret .= ' title="'.$this->__xmlEntities($title).'"'; |