From ffec100965184c6bf045f0096101768def108b43 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Wed, 31 Jul 2013 17:30:08 +0200 Subject: Index media file usage in the metadata index and use it in ft_mediause() --- inc/parser/metadata.php | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'inc/parser/metadata.php') diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php index e17b82f8b..d64fe4d77 100644 --- a/inc/parser/metadata.php +++ b/inc/parser/metadata.php @@ -282,8 +282,10 @@ class Doku_Renderer_metadata extends Doku_Renderer { function internallink($id, $name = NULL){ global $ID; - if(is_array($name)) + if(is_array($name)) { $this->_firstimage($name['src']); + if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); + } $default = $this->_simpleTitle($id); @@ -304,8 +306,10 @@ class Doku_Renderer_metadata extends Doku_Renderer { } function externallink($url, $name = NULL){ - if(is_array($name)) + 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 . '>'); @@ -313,8 +317,10 @@ class Doku_Renderer_metadata extends Doku_Renderer { } function interwikilink($match, $name = NULL, $wikiName, $wikiUri){ - if(is_array($name)) + 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); @@ -324,8 +330,10 @@ class Doku_Renderer_metadata extends Doku_Renderer { } function windowssharelink($url, $name = NULL){ - if(is_array($name)) + if(is_array($name)) { $this->_firstimage($name['src']); + if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); + } if ($this->capture){ if ($name) $this->doc .= $name; @@ -334,8 +342,10 @@ class Doku_Renderer_metadata extends Doku_Renderer { } function emaillink($address, $name = NULL){ - if(is_array($name)) + if(is_array($name)) { $this->_firstimage($name['src']); + if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); + } if ($this->capture){ if ($name) $this->doc .= $name; @@ -347,6 +357,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { $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, @@ -439,6 +450,15 @@ class Doku_Renderer_metadata extends Doku_Renderer { $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 : -- cgit v1.2.3 From 66d935e75f9ebbb37332c14e0a9425170c7c9330 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Sat, 17 Aug 2013 21:33:32 +0200 Subject: Fix backlinks for internal links with parameters This adds the parameter extraction code from the xhtml renderer to the metadata renderer in order to not to include the parameters in the id that is recorded as link target. A test case checks that the link is actually returned as backlink (fails without the fix). --- inc/parser/metadata.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'inc/parser/metadata.php') diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php index d64fe4d77..7d186e069 100644 --- a/inc/parser/metadata.php +++ b/inc/parser/metadata.php @@ -287,6 +287,12 @@ class Doku_Renderer_metadata extends Doku_Renderer { 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 -- cgit v1.2.3 From 7ef8e99fe605c5da36ab6b5d317b22fcd17f665b Mon Sep 17 00:00:00 2001 From: Matt Perry Date: Thu, 22 Aug 2013 01:01:41 -0700 Subject: Fix CodeSniffer violations Change indentation to ensure code confirms to CodeSniffer rules. --- inc/parser/metadata.php | 724 ++++++++++++++++++++++++------------------------ 1 file changed, 362 insertions(+), 362 deletions(-) (limited to 'inc/parser/metadata.php') diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php index 7d186e069..2d9da823d 100644 --- a/inc/parser/metadata.php +++ b/inc/parser/metadata.php @@ -23,448 +23,448 @@ 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 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)); + function getFormat(){ + return 'metadata'; } - if(!isset($this->persistent['user'])){ - $this->persistent['user'] = ''; - } - if(!isset($this->persistent['creator'])){ - $this->persistent['creator'] = ''; + + 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; } - // reset metadata to persistent values - $this->meta = $this->persistent; - } - function document_end(){ - global $ID; + function document_end(){ + global $ID; - // store internal info in metadata (notoc,nocache) - $this->meta['internal'] = $this->info; + // store internal info in metadata (notoc,nocache) + $this->meta['internal'] = $this->info; - 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; - } + 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->meta['relation']['firstimage'] = $this->firstimage; + $this->meta['relation']['firstimage'] = $this->firstimage; + + if(!isset($this->meta['date']['modified'])){ + $this->meta['date']['modified'] = filemtime(wikiFN($ID)); + } - if(!isset($this->meta['date']['modified'])){ - $this->meta['date']['modified'] = filemtime(wikiFN($ID)); } - } + function toc_additem($id, $text, $level) { + global $conf; - 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 + ); + } - //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 - ); } - } - - function header($text, $level, $pos) { - if (!isset($this->meta['title'])) $this->meta['title'] = $text; + 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 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; - } + // add to summary + if ($this->capture && ($level > 1)) $this->doc .= DOKU_LF.$text.DOKU_LF; + } - function section_open($level){} - function section_close(){} + function section_open($level){} + function section_close(){} - function cdata($text){ - if ($this->capture) $this->doc .= $text; - } + function cdata($text){ + if ($this->capture) $this->doc .= $text; + } - function p_open(){ - if ($this->capture) $this->doc .= DOKU_LF; - } + function p_open(){ + if ($this->capture) $this->doc .= DOKU_LF; + } - function p_close(){ - if ($this->capture){ - if (strlen($this->doc) > 250) $this->capture = false; - else $this->doc .= DOKU_LF; + function p_close(){ + if ($this->capture){ + if (strlen($this->doc) > 250) $this->capture = false; + else $this->doc .= DOKU_LF; + } } - } - function linebreak(){ - if ($this->capture) $this->doc .= DOKU_LF; - } + 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 hr(){ + if ($this->capture){ + if (strlen($this->doc) > 250) $this->capture = false; + else $this->doc .= DOKU_LF.'----------'.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 - */ - function footnote_open() { - if ($this->capture){ - // move current content to store and record footnote - $this->store = $this->doc; - $this->doc = ''; + /** + * 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 + */ + function footnote_open() { + if ($this->capture){ + // move current content to store and record footnote + $this->store = $this->doc; + $this->doc = ''; + } } - } - /** - * 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; - } - } + /** + * 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 acronym($acronym){ - if ($this->capture) $this->doc .= $acronym; - } + function listu_open(){ + if ($this->capture) $this->doc .= DOKU_LF; + } - function smiley($smiley){ - if ($this->capture) $this->doc .= $smiley; - } + function listu_close(){ + if ($this->capture && (strlen($this->doc) > 250)) $this->capture = false; + } - function entity($entity){ - if ($this->capture) $this->doc .= $entity; - } + function listo_open(){ + if ($this->capture) $this->doc .= DOKU_LF; + } - function multiplyentity($x, $y){ - if ($this->capture) $this->doc .= $x.'×'.$y; - } + function listo_close(){ + if ($this->capture && (strlen($this->doc) > 250)) $this->capture = false; + } - function singlequoteopening(){ - global $lang; - if ($this->capture) $this->doc .= $lang['singlequoteopening']; - } + function listitem_open($level){ + if ($this->capture) $this->doc .= str_repeat(DOKU_TAB, $level).'* '; + } - function singlequoteclosing(){ - global $lang; - if ($this->capture) $this->doc .= $lang['singlequoteclosing']; - } + function listitem_close(){ + if ($this->capture) $this->doc .= DOKU_LF; + } - function apostrophe() { - global $lang; - if ($this->capture) $this->doc .= $lang['apostrophe']; - } + function listcontent_open(){} + function listcontent_close(){} - function doublequoteopening(){ - global $lang; - if ($this->capture) $this->doc .= $lang['doublequoteopening']; - } + function unformatted($text){ + if ($this->capture) $this->doc .= $text; + } - function doublequoteclosing(){ - global $lang; - if ($this->capture) $this->doc .= $lang['doublequoteclosing']; - } + function preformatted($text){ + if ($this->capture) $this->doc .= $text; + } - function camelcaselink($link) { - $this->internallink($link, $link); - } + 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 locallink($hash, $name = NULL){} + function quote_open(){ + if ($this->capture) $this->doc .= DOKU_LF.DOKU_TAB.'"'; + } - /** - * keep track of internal links in $this->meta['relation']['references'] - */ - function internallink($id, $name = NULL){ - global $ID; + function quote_close(){ + if ($this->capture){ + $this->doc .= '"'; + if (strlen($this->doc) > 250) $this->capture = false; + else $this->doc .= DOKU_LF; + } + } - if(is_array($name)) { - $this->_firstimage($name['src']); - if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); + 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; + } } - $parts = explode('?', $id, 2); - if (count($parts) === 2) { - $id = $parts[0]; + function acronym($acronym){ + if ($this->capture) $this->doc .= $acronym; } + function smiley($smiley){ + if ($this->capture) $this->doc .= $smiley; + } - $default = $this->_simpleTitle($id); + function entity($entity){ + if ($this->capture) $this->doc .= $entity; + } - // first resolve and clean up the $id - resolve_pageid(getNS($ID), $id, $exists); - list($page, $hash) = explode('#', $id, 2); + function multiplyentity($x, $y){ + if ($this->capture) $this->doc .= $x.'×'.$y; + } - // set metadata - $this->meta['relation']['references'][$page] = $exists; - // $data = array('relation' => array('isreferencedby' => array($ID => true))); - // p_set_metadata($id, $data); + function singlequoteopening(){ + global $lang; + if ($this->capture) $this->doc .= $lang['singlequoteopening']; + } - // add link title to summary - if ($this->capture){ - $name = $this->_getLinkTitle($name, $default, $id); - $this->doc .= $name; + function singlequoteclosing(){ + global $lang; + if ($this->capture) $this->doc .= $lang['singlequoteclosing']; } - } - function externallink($url, $name = NULL){ - if(is_array($name)) { - $this->_firstimage($name['src']); - if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); + function apostrophe() { + global $lang; + if ($this->capture) $this->doc .= $lang['apostrophe']; } - if ($this->capture){ - $this->doc .= $this->_getLinkTitle($name, '<' . $url . '>'); + function doublequoteopening(){ + global $lang; + if ($this->capture) $this->doc .= $lang['doublequoteopening']; } - } - function interwikilink($match, $name = NULL, $wikiName, $wikiUri){ - if(is_array($name)) { - $this->_firstimage($name['src']); - if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); + function doublequoteclosing(){ + global $lang; + if ($this->capture) $this->doc .= $lang['doublequoteclosing']; } - if ($this->capture){ - list($wikiUri, $hash) = explode('#', $wikiUri, 2); - $name = $this->_getLinkTitle($name, $wikiUri); - $this->doc .= $name; + function camelcaselink($link) { + $this->internallink($link, $link); } - } - function windowssharelink($url, $name = NULL){ - if(is_array($name)) { - $this->_firstimage($name['src']); - if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); + 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; + } } - if ($this->capture){ - if ($name) $this->doc .= $name; - else $this->doc .= '<'.$url.'>'; + 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 emaillink($address, $name = NULL){ - if(is_array($name)) { - $this->_firstimage($name['src']); - if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); + 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; + } } - if ($this->capture){ - if ($name) $this->doc .= $name; - else $this->doc .= '<'.$address.'>'; + 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.'>'; + } } - } - 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 emaillink($address, $name = NULL){ + if(is_array($name)) { + $this->_firstimage($name['src']); + if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['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); - } + if ($this->capture){ + if ($name) $this->doc .= $name; + else $this->doc .= '<'.$address.'>'; + } + } - function rss($url,$params) { - $this->meta['relation']['haspart'][$url] = true; + 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); + } - $this->meta['date']['valid']['age'] = - isset($this->meta['date']['valid']['age']) ? - min($this->meta['date']['valid']['age'],$params['refresh']) : - $params['refresh']; - } + 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); + } - //---------------------------------------------------------- - // Utils + function rss($url,$params) { + $this->meta['relation']['haspart'][$url] = true; - /** - * Removes any Namespace from the given name but keeps - * casing and special chars - * - * @author Andreas Gohr - */ - function _simpleTitle($name){ - global $conf; + $this->meta['date']['valid']['age'] = + isset($this->meta['date']['valid']['age']) ? + min($this->meta['date']['valid']['age'],$params['refresh']) : + $params['refresh']; + } - 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 - */ - 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, $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; + //---------------------------------------------------------- + // Utils + + /** + * Removes any Namespace from the given name but keeps + * casing and special chars + * + * @author Andreas Gohr + */ + 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; } - } - function _firstimage($src){ - if($this->firstimage) return; - global $ID; + /** + * 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); + } + } - list($src,$hash) = explode('#',$src,2); - if(!media_isexternal($src)){ - resolve_mediaid(getNS($ID),$src, $exists); + /** + * Construct a title and handle images in titles + * + * @author Harry Fuecks + */ + 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; + 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; - } + 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 : -- cgit v1.2.3 From 0ea51e63908793de4c5d5fa2b4d82c2769fec559 Mon Sep 17 00:00:00 2001 From: Matt Perry Date: Fri, 23 Aug 2013 02:41:39 -0700 Subject: Fix CodeSniffer violations for PHP files Fix violations for Generic.PHP.LowerCaseConstant.Found --- inc/parser/metadata.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'inc/parser/metadata.php') diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php index 2d9da823d..094c3ad05 100644 --- a/inc/parser/metadata.php +++ b/inc/parser/metadata.php @@ -221,7 +221,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { } } - function code($text, $language = NULL, $file = null){ + function code($text, $language = null, $file = null){ if ($this->capture){ $this->doc .= DOKU_LF.$text; if (strlen($this->doc) > 250) $this->capture = false; @@ -274,12 +274,12 @@ class Doku_Renderer_metadata extends Doku_Renderer { $this->internallink($link, $link); } - function locallink($hash, $name = NULL){} + function locallink($hash, $name = null){} /** * keep track of internal links in $this->meta['relation']['references'] */ - function internallink($id, $name = NULL){ + function internallink($id, $name = null){ global $ID; if(is_array($name)) { @@ -311,7 +311,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { } } - function externallink($url, $name = NULL){ + function externallink($url, $name = null){ if(is_array($name)) { $this->_firstimage($name['src']); if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); @@ -322,7 +322,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { } } - function interwikilink($match, $name = NULL, $wikiName, $wikiUri){ + function interwikilink($match, $name = null, $wikiName, $wikiUri){ if(is_array($name)) { $this->_firstimage($name['src']); if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); @@ -335,7 +335,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { } } - function windowssharelink($url, $name = NULL){ + function windowssharelink($url, $name = null){ if(is_array($name)) { $this->_firstimage($name['src']); if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); @@ -347,7 +347,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { } } - function emaillink($address, $name = NULL){ + function emaillink($address, $name = null){ if(is_array($name)) { $this->_firstimage($name['src']); if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); @@ -359,15 +359,15 @@ class Doku_Renderer_metadata extends Doku_Renderer { } } - function internalmedia($src, $title=NULL, $align=NULL, $width=NULL, - $height=NULL, $cache=NULL, $linking=NULL){ + 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){ + 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); } @@ -427,7 +427,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { * * @author Harry Fuecks */ - function _getLinkTitle($title, $default, $id=NULL) { + function _getLinkTitle($title, $default, $id=null) { global $conf; $isImage = false; -- cgit v1.2.3 From 2f7a0e94cadfbc1ece3bd1d3ff23483b845cd420 Mon Sep 17 00:00:00 2001 From: Matt Perry Date: Tue, 10 Sep 2013 22:17:43 -0700 Subject: Fix CodeSniffer whitespace violoations Removed extraneous whitespace to eliminate errors reported by the Squiz.WhiteSpace.SuperfluousWhitespace sniff. --- inc/parser/metadata.php | 1 - 1 file changed, 1 deletion(-) (limited to 'inc/parser/metadata.php') diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php index 094c3ad05..437559370 100644 --- a/inc/parser/metadata.php +++ b/inc/parser/metadata.php @@ -292,7 +292,6 @@ class Doku_Renderer_metadata extends Doku_Renderer { $id = $parts[0]; } - $default = $this->_simpleTitle($id); // first resolve and clean up the $id -- cgit v1.2.3 From 9269d0b1fb78c217069efd497734c183df9937be Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Tue, 29 Oct 2013 20:52:27 +0100 Subject: Fix the media usage index to include local links --- inc/parser/metadata.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'inc/parser/metadata.php') diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php index 437559370..8ba159d62 100644 --- a/inc/parser/metadata.php +++ b/inc/parser/metadata.php @@ -274,7 +274,12 @@ class Doku_Renderer_metadata extends Doku_Renderer { $this->internallink($link, $link); } - function locallink($hash, $name = null){} + function locallink($hash, $name = null){ + if(is_array($name)) { + $this->_firstimage($name['src']); + if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']); + } + } /** * keep track of internal links in $this->meta['relation']['references'] -- cgit v1.2.3