diff options
author | Andreas Gohr <andi@splitbrain.org> | 2013-10-28 20:22:05 +0100 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2013-10-28 20:22:05 +0100 |
commit | 23a363f01514464eb2238ac09ec7723d03d57ecb (patch) | |
tree | 42c7dcff8c5b0e506a25d08ee5583ed2a24e8602 /inc/parser/metadata.php | |
parent | 25e48e54df60b3df6efa365daceb3a8966c8f427 (diff) | |
parent | 75cf672f10a71f7dee6d50eb70b742689838bc36 (diff) | |
download | rpg-23a363f01514464eb2238ac09ec7723d03d57ecb.tar.gz rpg-23a363f01514464eb2238ac09ec7723d03d57ecb.tar.bz2 |
Merge branch 'master' into stable
* master: (413 commits)
release preparation
fixed strict violation in ACL plugin
Fix issues from teams:i18n:translation-check in localizations
ensure locale is set back to the original value
skip FS#2867 test if \s doesn't match \xA0 after attempting to change the locale
unittests for auth_loadACL
translation update
allow charset for SSO to be configured FS#2148
Mailer: avoid overlong headers in content ids FS#2868
translation update
translation update
replace \s, \S with [ \t], [^ \t] in regexs used with acls
translation update
translation update
translation update
translation update
Fix handling of the legacy subscription action name
remove obsolete opera handling and session closing
remove no longer used ajax.php
fix proxy CONNECT where HTTP 1.1 answer is given
...
Diffstat (limited to 'inc/parser/metadata.php')
-rw-r--r-- | inc/parser/metadata.php | 759 |
1 files changed, 392 insertions, 367 deletions
diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php index 8638ffa6a..437559370 100644 --- a/inc/parser/metadata.php +++ b/inc/parser/metadata.php @@ -23,422 +23,447 @@ require_once DOKU_INC . 'inc/parser/renderer.php'; */ class Doku_Renderer_metadata extends Doku_Renderer { - var $doc = ''; - var $meta = array(); - var $persistent = array(); + var $doc = ''; + var $meta = array(); + var $persistent = array(); - var $headers = array(); - var $capture = true; - var $store = ''; - var $firstimage = ''; + var $headers = array(); + var $capture = true; + var $store = ''; + var $firstimage = ''; - function getFormat(){ - return 'metadata'; - } + function getFormat(){ + return 'metadata'; + } + + function document_start(){ + global $ID; + + $this->headers = array(); + + // external pages are missing create date + if(!$this->persistent['date']['created']){ + $this->persistent['date']['created'] = filectime(wikiFN($ID)); + } + if(!isset($this->persistent['user'])){ + $this->persistent['user'] = ''; + } + if(!isset($this->persistent['creator'])){ + $this->persistent['creator'] = ''; + } + // reset metadata to persistent values + $this->meta = $this->persistent; + } + + function document_end(){ + global $ID; + + // store internal info in metadata (notoc,nocache) + $this->meta['internal'] = $this->info; - function document_start(){ - global $ID; + if (!isset($this->meta['description']['abstract'])){ + // cut off too long abstracts + $this->doc = trim($this->doc); + if (strlen($this->doc) > 500) + $this->doc = utf8_substr($this->doc, 0, 500).'…'; + $this->meta['description']['abstract'] = $this->doc; + } - $this->headers = array(); + $this->meta['relation']['firstimage'] = $this->firstimage; + + if(!isset($this->meta['date']['modified'])){ + $this->meta['date']['modified'] = filemtime(wikiFN($ID)); + } - // external pages are missing create date - if(!$this->persistent['date']['created']){ - $this->persistent['date']['created'] = filectime(wikiFN($ID)); } - if(!isset($this->persistent['user'])){ - $this->persistent['user'] = ''; + + function toc_additem($id, $text, $level) { + global $conf; + + //only add items within configured levels + if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){ + // the TOC is one of our standard ul list arrays ;-) + $this->meta['description']['tableofcontents'][] = array( + 'hid' => $id, + 'title' => $text, + 'type' => 'ul', + 'level' => $level-$conf['toptoclevel']+1 + ); + } + } - if(!isset($this->persistent['creator'])){ - $this->persistent['creator'] = ''; + + function header($text, $level, $pos) { + if (!isset($this->meta['title'])) $this->meta['title'] = $text; + + // add the header to the TOC + $hid = $this->_headerToLink($text,'true'); + $this->toc_additem($hid, $text, $level); + + // add to summary + if ($this->capture && ($level > 1)) $this->doc .= DOKU_LF.$text.DOKU_LF; } - // reset metadata to persistent values - $this->meta = $this->persistent; - } - function document_end(){ - global $ID; + function section_open($level){} + function section_close(){} - // store internal info in metadata (notoc,nocache) - $this->meta['internal'] = $this->info; + function cdata($text){ + if ($this->capture) $this->doc .= $text; + } - if (!isset($this->meta['description']['abstract'])){ - // cut off too long abstracts - $this->doc = trim($this->doc); - if (strlen($this->doc) > 500) - $this->doc = utf8_substr($this->doc, 0, 500).'…'; - $this->meta['description']['abstract'] = $this->doc; + function p_open(){ + if ($this->capture) $this->doc .= DOKU_LF; } - $this->meta['relation']['firstimage'] = $this->firstimage; + function p_close(){ + if ($this->capture){ + if (strlen($this->doc) > 250) $this->capture = false; + else $this->doc .= DOKU_LF; + } + } - if(!isset($this->meta['date']['modified'])){ - $this->meta['date']['modified'] = filemtime(wikiFN($ID)); + function linebreak(){ + if ($this->capture) $this->doc .= DOKU_LF; } - } + function hr(){ + if ($this->capture){ + if (strlen($this->doc) > 250) $this->capture = false; + else $this->doc .= DOKU_LF.'----------'.DOKU_LF; + } + } - function toc_additem($id, $text, $level) { - global $conf; + /** + * Callback for footnote start syntax + * + * All following content will go to the footnote instead of + * the document. To achieve this the previous rendered content + * is moved to $store and $doc is cleared + * + * @author Andreas Gohr <andi@splitbrain.org> + */ + function footnote_open() { + if ($this->capture){ + // move current content to store and record footnote + $this->store = $this->doc; + $this->doc = ''; + } + } - //only add items within configured levels - if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){ - // the TOC is one of our standard ul list arrays ;-) - $this->meta['description']['tableofcontents'][] = array( - 'hid' => $id, - 'title' => $text, - 'type' => 'ul', - 'level' => $level-$conf['toptoclevel']+1 - ); + /** + * Callback for footnote end syntax + * + * All rendered content is moved to the $footnotes array and the old + * content is restored from $store again + * + * @author Andreas Gohr + */ + function footnote_close() { + if ($this->capture){ + // restore old content + $this->doc = $this->store; + $this->store = ''; + } } - } + function listu_open(){ + if ($this->capture) $this->doc .= DOKU_LF; + } - function header($text, $level, $pos) { - if (!isset($this->meta['title'])) $this->meta['title'] = $text; + function listu_close(){ + if ($this->capture && (strlen($this->doc) > 250)) $this->capture = false; + } - // add the header to the TOC - $hid = $this->_headerToLink($text,'true'); - $this->toc_additem($hid, $text, $level); + function listo_open(){ + if ($this->capture) $this->doc .= DOKU_LF; + } - // add to summary - if ($this->capture && ($level > 1)) $this->doc .= DOKU_LF.$text.DOKU_LF; - } + function listo_close(){ + if ($this->capture && (strlen($this->doc) > 250)) $this->capture = false; + } - function section_open($level){} - function section_close(){} + function listitem_open($level){ + if ($this->capture) $this->doc .= str_repeat(DOKU_TAB, $level).'* '; + } - function cdata($text){ - if ($this->capture) $this->doc .= $text; - } + function listitem_close(){ + if ($this->capture) $this->doc .= DOKU_LF; + } - function p_open(){ - if ($this->capture) $this->doc .= DOKU_LF; - } + function listcontent_open(){} + function listcontent_close(){} - function p_close(){ - if ($this->capture){ - if (strlen($this->doc) > 250) $this->capture = false; - else $this->doc .= DOKU_LF; + function unformatted($text){ + if ($this->capture) $this->doc .= $text; } - } - function linebreak(){ - if ($this->capture) $this->doc .= DOKU_LF; - } + function preformatted($text){ + if ($this->capture) $this->doc .= $text; + } - function hr(){ - if ($this->capture){ - if (strlen($this->doc) > 250) $this->capture = false; - else $this->doc .= DOKU_LF.'----------'.DOKU_LF; + function file($text, $lang = null, $file = null){ + if ($this->capture){ + $this->doc .= DOKU_LF.$text; + if (strlen($this->doc) > 250) $this->capture = false; + else $this->doc .= DOKU_LF; + } } - } - /** - * Callback for footnote start syntax - * - * All following content will go to the footnote instead of - * the document. To achieve this the previous rendered content - * is moved to $store and $doc is cleared - * - * @author Andreas Gohr <andi@splitbrain.org> - */ - function footnote_open() { - if ($this->capture){ - // move current content to store and record footnote - $this->store = $this->doc; - $this->doc = ''; + function quote_open(){ + if ($this->capture) $this->doc .= DOKU_LF.DOKU_TAB.'"'; } - } - /** - * Callback for footnote end syntax - * - * All rendered content is moved to the $footnotes array and the old - * content is restored from $store again - * - * @author Andreas Gohr - */ - function footnote_close() { - if ($this->capture){ - // restore old content - $this->doc = $this->store; - $this->store = ''; - } - } - - function listu_open(){ - if ($this->capture) $this->doc .= DOKU_LF; - } - - function listu_close(){ - if ($this->capture && (strlen($this->doc) > 250)) $this->capture = false; - } - - function listo_open(){ - if ($this->capture) $this->doc .= DOKU_LF; - } - - function listo_close(){ - if ($this->capture && (strlen($this->doc) > 250)) $this->capture = false; - } - - function listitem_open($level){ - if ($this->capture) $this->doc .= str_repeat(DOKU_TAB, $level).'* '; - } - - function listitem_close(){ - if ($this->capture) $this->doc .= DOKU_LF; - } - - function listcontent_open(){} - function listcontent_close(){} - - function unformatted($text){ - if ($this->capture) $this->doc .= $text; - } - - function preformatted($text){ - if ($this->capture) $this->doc .= $text; - } - - function file($text, $lang = null, $file = null){ - if ($this->capture){ - $this->doc .= DOKU_LF.$text; - if (strlen($this->doc) > 250) $this->capture = false; - else $this->doc .= DOKU_LF; - } - } - - function quote_open(){ - if ($this->capture) $this->doc .= DOKU_LF.DOKU_TAB.'"'; - } - - function quote_close(){ - if ($this->capture){ - $this->doc .= '"'; - if (strlen($this->doc) > 250) $this->capture = false; - else $this->doc .= DOKU_LF; - } - } - - function code($text, $language = NULL, $file = null){ - if ($this->capture){ - $this->doc .= DOKU_LF.$text; - if (strlen($this->doc) > 250) $this->capture = false; - else $this->doc .= DOKU_LF; - } - } - - function acronym($acronym){ - if ($this->capture) $this->doc .= $acronym; - } - - function smiley($smiley){ - if ($this->capture) $this->doc .= $smiley; - } - - function entity($entity){ - if ($this->capture) $this->doc .= $entity; - } - - function multiplyentity($x, $y){ - if ($this->capture) $this->doc .= $x.'×'.$y; - } + function quote_close(){ + if ($this->capture){ + $this->doc .= '"'; + if (strlen($this->doc) > 250) $this->capture = false; + else $this->doc .= DOKU_LF; + } + } - function singlequoteopening(){ - global $lang; - if ($this->capture) $this->doc .= $lang['singlequoteopening']; - } + function code($text, $language = null, $file = null){ + if ($this->capture){ + $this->doc .= DOKU_LF.$text; + if (strlen($this->doc) > 250) $this->capture = false; + else $this->doc .= DOKU_LF; + } + } - function singlequoteclosing(){ - global $lang; - if ($this->capture) $this->doc .= $lang['singlequoteclosing']; - } + function acronym($acronym){ + if ($this->capture) $this->doc .= $acronym; + } - function apostrophe() { - global $lang; - if ($this->capture) $this->doc .= $lang['apostrophe']; - } + function smiley($smiley){ + if ($this->capture) $this->doc .= $smiley; + } - function doublequoteopening(){ - global $lang; - if ($this->capture) $this->doc .= $lang['doublequoteopening']; - } + function entity($entity){ + if ($this->capture) $this->doc .= $entity; + } - function doublequoteclosing(){ - global $lang; - if ($this->capture) $this->doc .= $lang['doublequoteclosing']; - } + function multiplyentity($x, $y){ + if ($this->capture) $this->doc .= $x.'×'.$y; + } - function camelcaselink($link) { - $this->internallink($link, $link); - } + function singlequoteopening(){ + global $lang; + if ($this->capture) $this->doc .= $lang['singlequoteopening']; + } - function locallink($hash, $name = NULL){} + function singlequoteclosing(){ + global $lang; + if ($this->capture) $this->doc .= $lang['singlequoteclosing']; + } - /** - * keep track of internal links in $this->meta['relation']['references'] - */ - function internallink($id, $name = NULL){ - global $ID; + function apostrophe() { + global $lang; + if ($this->capture) $this->doc .= $lang['apostrophe']; + } - if(is_array($name)) - $this->_firstimage($name['src']); + function doublequoteopening(){ + global $lang; + if ($this->capture) $this->doc .= $lang['doublequoteopening']; + } - $default = $this->_simpleTitle($id); - - // first resolve and clean up the $id - resolve_pageid(getNS($ID), $id, $exists); - list($page, $hash) = explode('#', $id, 2); - - // set metadata - $this->meta['relation']['references'][$page] = $exists; - // $data = array('relation' => array('isreferencedby' => array($ID => true))); - // p_set_metadata($id, $data); - - // add link title to summary - if ($this->capture){ - $name = $this->_getLinkTitle($name, $default, $id); - $this->doc .= $name; - } - } - - function externallink($url, $name = NULL){ - if(is_array($name)) - $this->_firstimage($name['src']); - - if ($this->capture){ - $this->doc .= $this->_getLinkTitle($name, '<' . $url . '>'); - } - } - - function interwikilink($match, $name = NULL, $wikiName, $wikiUri){ - if(is_array($name)) - $this->_firstimage($name['src']); - - if ($this->capture){ - list($wikiUri, $hash) = explode('#', $wikiUri, 2); - $name = $this->_getLinkTitle($name, $wikiUri); - $this->doc .= $name; - } - } - - function windowssharelink($url, $name = NULL){ - if(is_array($name)) - $this->_firstimage($name['src']); - - if ($this->capture){ - if ($name) $this->doc .= $name; - else $this->doc .= '<'.$url.'>'; - } - } - - function emaillink($address, $name = NULL){ - if(is_array($name)) - $this->_firstimage($name['src']); - - if ($this->capture){ - if ($name) $this->doc .= $name; - else $this->doc .= '<'.$address.'>'; - } - } - - function internalmedia($src, $title=NULL, $align=NULL, $width=NULL, - $height=NULL, $cache=NULL, $linking=NULL){ - if ($this->capture && $title) $this->doc .= '['.$title.']'; - $this->_firstimage($src); - } - - function externalmedia($src, $title=NULL, $align=NULL, $width=NULL, - $height=NULL, $cache=NULL, $linking=NULL){ - if ($this->capture && $title) $this->doc .= '['.$title.']'; - $this->_firstimage($src); - } - - function rss($url,$params) { - $this->meta['relation']['haspart'][$url] = true; - - $this->meta['date']['valid']['age'] = - isset($this->meta['date']['valid']['age']) ? - min($this->meta['date']['valid']['age'],$params['refresh']) : - $params['refresh']; - } - - //---------------------------------------------------------- - // Utils - - /** - * Removes any Namespace from the given name but keeps - * casing and special chars - * - * @author Andreas Gohr <andi@splitbrain.org> - */ - function _simpleTitle($name){ - global $conf; - - if(is_array($name)) return ''; - - if($conf['useslash']){ - $nssep = '[:;/]'; - }else{ - $nssep = '[:;]'; - } - $name = preg_replace('!.*'.$nssep.'!','',$name); - //if there is a hash we use the anchor name only - $name = preg_replace('!.*#!','',$name); - return $name; - } - - /** - * Creates a linkid from a headline - * - * @param string $title The headline title - * @param boolean $create Create a new unique ID? - * @author Andreas Gohr <andi@splitbrain.org> - */ - 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 <hfuecks@gmail.com> - */ - function _getLinkTitle($title, $default, $id=NULL) { - global $conf; - - $isImage = false; - if (is_array($title)){ - if($title['title']) return '['.$title['title'].']'; - } else if (is_null($title) || trim($title)==''){ - if (useHeading('content') && $id){ - $heading = p_get_first_heading($id,METADATA_DONT_RENDER); - if ($heading) return $heading; - } - return $default; - } else { - return $title; + function doublequoteclosing(){ + global $lang; + if ($this->capture) $this->doc .= $lang['doublequoteclosing']; } - } - function _firstimage($src){ - if($this->firstimage) return; - global $ID; + function camelcaselink($link) { + $this->internallink($link, $link); + } + + function locallink($hash, $name = null){} + + /** + * keep track of internal links in $this->meta['relation']['references'] + */ + function internallink($id, $name = null){ + global $ID; + + if(is_array($name)) { + $this->_firstimage($name['src']); + if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); + } + + $parts = explode('?', $id, 2); + if (count($parts) === 2) { + $id = $parts[0]; + } + + $default = $this->_simpleTitle($id); + + // first resolve and clean up the $id + resolve_pageid(getNS($ID), $id, $exists); + list($page, $hash) = explode('#', $id, 2); + + // set metadata + $this->meta['relation']['references'][$page] = $exists; + // $data = array('relation' => array('isreferencedby' => array($ID => true))); + // p_set_metadata($id, $data); + + // add link title to summary + if ($this->capture){ + $name = $this->_getLinkTitle($name, $default, $id); + $this->doc .= $name; + } + } + + function externallink($url, $name = null){ + if(is_array($name)) { + $this->_firstimage($name['src']); + if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); + } + + if ($this->capture){ + $this->doc .= $this->_getLinkTitle($name, '<' . $url . '>'); + } + } + + function interwikilink($match, $name = null, $wikiName, $wikiUri){ + if(is_array($name)) { + $this->_firstimage($name['src']); + if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); + } + + if ($this->capture){ + list($wikiUri, $hash) = explode('#', $wikiUri, 2); + $name = $this->_getLinkTitle($name, $wikiUri); + $this->doc .= $name; + } + } + + function windowssharelink($url, $name = null){ + if(is_array($name)) { + $this->_firstimage($name['src']); + if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); + } + + if ($this->capture){ + if ($name) $this->doc .= $name; + else $this->doc .= '<'.$url.'>'; + } + } - list($src,$hash) = explode('#',$src,2); - if(!preg_match('/^https?:\/\//i',$src)){ - resolve_mediaid(getNS($ID),$src, $exists); + function emaillink($address, $name = null){ + if(is_array($name)) { + $this->_firstimage($name['src']); + if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); + } + + if ($this->capture){ + if ($name) $this->doc .= $name; + else $this->doc .= '<'.$address.'>'; + } + } + + function internalmedia($src, $title=null, $align=null, $width=null, + $height=null, $cache=null, $linking=null){ + if ($this->capture && $title) $this->doc .= '['.$title.']'; + $this->_firstimage($src); + $this->_recordMediaUsage($src); + } + + function externalmedia($src, $title=null, $align=null, $width=null, + $height=null, $cache=null, $linking=null){ + if ($this->capture && $title) $this->doc .= '['.$title.']'; + $this->_firstimage($src); + } + + function rss($url,$params) { + $this->meta['relation']['haspart'][$url] = true; + + $this->meta['date']['valid']['age'] = + isset($this->meta['date']['valid']['age']) ? + min($this->meta['date']['valid']['age'],$params['refresh']) : + $params['refresh']; + } + + //---------------------------------------------------------- + // Utils + + /** + * Removes any Namespace from the given name but keeps + * casing and special chars + * + * @author Andreas Gohr <andi@splitbrain.org> + */ + function _simpleTitle($name){ + global $conf; + + if(is_array($name)) return ''; + + if($conf['useslash']){ + $nssep = '[:;/]'; + }else{ + $nssep = '[:;]'; + } + $name = preg_replace('!.*'.$nssep.'!','',$name); + //if there is a hash we use the anchor name only + $name = preg_replace('!.*#!','',$name); + return $name; + } + + /** + * Creates a linkid from a headline + * + * @param string $title The headline title + * @param boolean $create Create a new unique ID? + * @author Andreas Gohr <andi@splitbrain.org> + */ + 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 <hfuecks@gmail.com> + */ + function _getLinkTitle($title, $default, $id=null) { + global $conf; + + $isImage = false; + if (is_array($title)){ + if($title['title']) return '['.$title['title'].']'; + } else if (is_null($title) || trim($title)==''){ + if (useHeading('content') && $id){ + $heading = p_get_first_heading($id,METADATA_DONT_RENDER); + if ($heading) return $heading; + } + return $default; + } else { + return $title; + } } - if(preg_match('/.(jpe?g|gif|png)$/i',$src)){ - $this->firstimage = $src; + + function _firstimage($src){ + if($this->firstimage) return; + global $ID; + + list($src,$hash) = explode('#',$src,2); + if(!media_isexternal($src)){ + resolve_mediaid(getNS($ID),$src, $exists); + } + if(preg_match('/.(jpe?g|gif|png)$/i',$src)){ + $this->firstimage = $src; + } + } + + function _recordMediaUsage($src) { + global $ID; + + list ($src, $hash) = explode('#', $src, 2); + if (media_isexternal($src)) return; + resolve_mediaid(getNS($ID), $src, $exists); + $this->meta['relation']['media'][$src] = $exists; } - } } //Setup VIM: ex: et ts=4 : |