xref: /dokuwiki/inc/parser/metadata.php (revision 0ea51e63908793de4c5d5fa2b4d82c2769fec559)
139a89382SEsther Brunner<?php
239a89382SEsther Brunner/**
339a89382SEsther Brunner * Renderer for metadata
439a89382SEsther Brunner *
539a89382SEsther Brunner * @author Esther Brunner <wikidesign@gmail.com>
639a89382SEsther Brunner */
7fa8adffeSAndreas Gohrif(!defined('DOKU_INC')) die('meh.');
839a89382SEsther Brunner
939a89382SEsther Brunnerif ( !defined('DOKU_LF') ) {
1039a89382SEsther Brunner    // Some whitespace to help View > Source
1139a89382SEsther Brunner    define ('DOKU_LF',"\n");
1239a89382SEsther Brunner}
1339a89382SEsther Brunner
1439a89382SEsther Brunnerif ( !defined('DOKU_TAB') ) {
1539a89382SEsther Brunner    // Some whitespace to help View > Source
1639a89382SEsther Brunner    define ('DOKU_TAB',"\t");
1739a89382SEsther Brunner}
1839a89382SEsther Brunner
1939a89382SEsther Brunnerrequire_once DOKU_INC . 'inc/parser/renderer.php';
2039a89382SEsther Brunner
2139a89382SEsther Brunner/**
2239a89382SEsther Brunner * The Renderer
2339a89382SEsther Brunner */
2439a89382SEsther Brunnerclass Doku_Renderer_metadata extends Doku_Renderer {
2539a89382SEsther Brunner
2639a89382SEsther Brunner    var $doc  = '';
2739a89382SEsther Brunner    var $meta = array();
280a7e3bceSchris    var $persistent = array();
2939a89382SEsther Brunner
3039a89382SEsther Brunner    var $headers = array();
3139a89382SEsther Brunner    var $capture = true;
3239a89382SEsther Brunner    var $store   = '';
33aa5a2937SAndreas Gohr    var $firstimage = '';
3439a89382SEsther Brunner
355f70445dSAndreas Gohr    function getFormat(){
365f70445dSAndreas Gohr        return 'metadata';
375f70445dSAndreas Gohr    }
385f70445dSAndreas Gohr
3939a89382SEsther Brunner    function document_start(){
40ef47e298SAndreas Gohr        global $ID;
41620f4930SAndreas Gohr
42620f4930SAndreas Gohr        $this->headers = array();
43620f4930SAndreas Gohr
44ef47e298SAndreas Gohr        // external pages are missing create date
45ef47e298SAndreas Gohr        if(!$this->persistent['date']['created']){
46ef47e298SAndreas Gohr            $this->persistent['date']['created'] = filectime(wikiFN($ID));
47ef47e298SAndreas Gohr        }
48a8e72133SAndreas Gohr        if(!isset($this->persistent['user'])){
49a8e72133SAndreas Gohr            $this->persistent['user'] = '';
50a8e72133SAndreas Gohr        }
51ef47e298SAndreas Gohr        if(!isset($this->persistent['creator'])){
52ef47e298SAndreas Gohr            $this->persistent['creator'] = '';
53ef47e298SAndreas Gohr        }
540a7e3bceSchris        // reset metadata to persistent values
550a7e3bceSchris        $this->meta = $this->persistent;
5639a89382SEsther Brunner    }
5739a89382SEsther Brunner
5839a89382SEsther Brunner    function document_end(){
59482cff99SAndreas Gohr        global $ID;
60482cff99SAndreas Gohr
61b8595a66SAndreas Gohr        // store internal info in metadata (notoc,nocache)
62b8595a66SAndreas Gohr        $this->meta['internal'] = $this->info;
63b8595a66SAndreas Gohr
64c66972f2SAdrian Lang        if (!isset($this->meta['description']['abstract'])){
6539a89382SEsther Brunner            // cut off too long abstracts
6639a89382SEsther Brunner            $this->doc = trim($this->doc);
6739a89382SEsther Brunner            if (strlen($this->doc) > 500)
68bc769d32SAndreas Gohr                $this->doc = utf8_substr($this->doc, 0, 500).'…';
6939a89382SEsther Brunner            $this->meta['description']['abstract'] = $this->doc;
7039a89382SEsther Brunner        }
71aa5a2937SAndreas Gohr
72aa5a2937SAndreas Gohr        $this->meta['relation']['firstimage'] = $this->firstimage;
73482cff99SAndreas Gohr
74c0322273SAdrian Lang        if(!isset($this->meta['date']['modified'])){
75482cff99SAndreas Gohr            $this->meta['date']['modified'] = filemtime(wikiFN($ID));
76482cff99SAndreas Gohr        }
77482cff99SAndreas Gohr
7839a89382SEsther Brunner    }
7939a89382SEsther Brunner
80e7856beaSchris    function toc_additem($id, $text, $level) {
8139a89382SEsther Brunner        global $conf;
8239a89382SEsther Brunner
83e7856beaSchris        //only add items within configured levels
8439a89382SEsther Brunner        if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){
8539a89382SEsther Brunner            // the TOC is one of our standard ul list arrays ;-)
8639a89382SEsther Brunner            $this->meta['description']['tableofcontents'][] = array(
87e7856beaSchris              'hid'   => $id,
8839a89382SEsther Brunner              'title' => $text,
8939a89382SEsther Brunner              'type'  => 'ul',
9039a89382SEsther Brunner              'level' => $level-$conf['toptoclevel']+1
9139a89382SEsther Brunner            );
9239a89382SEsther Brunner        }
9339a89382SEsther Brunner
94e7856beaSchris    }
95e7856beaSchris
96e7856beaSchris    function header($text, $level, $pos) {
97c66972f2SAdrian Lang        if (!isset($this->meta['title'])) $this->meta['title'] = $text;
98e7856beaSchris
99e7856beaSchris        // add the header to the TOC
100e7856beaSchris        $hid = $this->_headerToLink($text,'true');
101e7856beaSchris        $this->toc_additem($hid, $text, $level);
102e7856beaSchris
10339a89382SEsther Brunner        // add to summary
10439a89382SEsther Brunner        if ($this->capture && ($level > 1)) $this->doc .= DOKU_LF.$text.DOKU_LF;
10539a89382SEsther Brunner    }
10639a89382SEsther Brunner
10739a89382SEsther Brunner    function section_open($level){}
10839a89382SEsther Brunner    function section_close(){}
10939a89382SEsther Brunner
11039a89382SEsther Brunner    function cdata($text){
11139a89382SEsther Brunner      if ($this->capture) $this->doc .= $text;
11239a89382SEsther Brunner    }
11339a89382SEsther Brunner
11439a89382SEsther Brunner    function p_open(){
11539a89382SEsther Brunner      if ($this->capture) $this->doc .= DOKU_LF;
11639a89382SEsther Brunner    }
11739a89382SEsther Brunner
11839a89382SEsther Brunner    function p_close(){
11939a89382SEsther Brunner        if ($this->capture){
12039a89382SEsther Brunner            if (strlen($this->doc) > 250) $this->capture = false;
12139a89382SEsther Brunner            else $this->doc .= DOKU_LF;
12239a89382SEsther Brunner        }
12339a89382SEsther Brunner    }
12439a89382SEsther Brunner
12539a89382SEsther Brunner    function linebreak(){
12639a89382SEsther Brunner        if ($this->capture) $this->doc .= DOKU_LF;
12739a89382SEsther Brunner    }
12839a89382SEsther Brunner
12939a89382SEsther Brunner    function hr(){
13039a89382SEsther Brunner        if ($this->capture){
13139a89382SEsther Brunner            if (strlen($this->doc) > 250) $this->capture = false;
13239a89382SEsther Brunner            else $this->doc .= DOKU_LF.'----------'.DOKU_LF;
13339a89382SEsther Brunner        }
13439a89382SEsther Brunner    }
13539a89382SEsther Brunner
13639a89382SEsther Brunner    /**
13739a89382SEsther Brunner     * Callback for footnote start syntax
13839a89382SEsther Brunner     *
13939a89382SEsther Brunner     * All following content will go to the footnote instead of
14039a89382SEsther Brunner     * the document. To achieve this the previous rendered content
14139a89382SEsther Brunner     * is moved to $store and $doc is cleared
14239a89382SEsther Brunner     *
14339a89382SEsther Brunner     * @author Andreas Gohr <andi@splitbrain.org>
14439a89382SEsther Brunner     */
14539a89382SEsther Brunner    function footnote_open() {
14639a89382SEsther Brunner        if ($this->capture){
14739a89382SEsther Brunner            // move current content to store and record footnote
14839a89382SEsther Brunner            $this->store = $this->doc;
14939a89382SEsther Brunner            $this->doc   = '';
15039a89382SEsther Brunner        }
15139a89382SEsther Brunner    }
15239a89382SEsther Brunner
15339a89382SEsther Brunner    /**
15439a89382SEsther Brunner     * Callback for footnote end syntax
15539a89382SEsther Brunner     *
15639a89382SEsther Brunner     * All rendered content is moved to the $footnotes array and the old
15739a89382SEsther Brunner     * content is restored from $store again
15839a89382SEsther Brunner     *
15939a89382SEsther Brunner     * @author Andreas Gohr
16039a89382SEsther Brunner     */
16139a89382SEsther Brunner    function footnote_close() {
16239a89382SEsther Brunner        if ($this->capture){
16339a89382SEsther Brunner            // restore old content
16439a89382SEsther Brunner            $this->doc = $this->store;
16539a89382SEsther Brunner            $this->store = '';
16639a89382SEsther Brunner        }
16739a89382SEsther Brunner    }
16839a89382SEsther Brunner
16939a89382SEsther Brunner    function listu_open(){
17039a89382SEsther Brunner        if ($this->capture) $this->doc .= DOKU_LF;
17139a89382SEsther Brunner    }
17239a89382SEsther Brunner
17339a89382SEsther Brunner    function listu_close(){
17439a89382SEsther Brunner        if ($this->capture && (strlen($this->doc) > 250)) $this->capture = false;
17539a89382SEsther Brunner    }
17639a89382SEsther Brunner
17739a89382SEsther Brunner    function listo_open(){
17839a89382SEsther Brunner        if ($this->capture) $this->doc .= DOKU_LF;
17939a89382SEsther Brunner    }
18039a89382SEsther Brunner
18139a89382SEsther Brunner    function listo_close(){
18239a89382SEsther Brunner        if ($this->capture && (strlen($this->doc) > 250)) $this->capture = false;
18339a89382SEsther Brunner    }
18439a89382SEsther Brunner
18539a89382SEsther Brunner    function listitem_open($level){
18639a89382SEsther Brunner        if ($this->capture) $this->doc .= str_repeat(DOKU_TAB, $level).'* ';
18739a89382SEsther Brunner    }
18839a89382SEsther Brunner
18939a89382SEsther Brunner    function listitem_close(){
19039a89382SEsther Brunner        if ($this->capture) $this->doc .= DOKU_LF;
19139a89382SEsther Brunner    }
19239a89382SEsther Brunner
19339a89382SEsther Brunner    function listcontent_open(){}
19439a89382SEsther Brunner    function listcontent_close(){}
19539a89382SEsther Brunner
19639a89382SEsther Brunner    function unformatted($text){
19739a89382SEsther Brunner        if ($this->capture) $this->doc .= $text;
19839a89382SEsther Brunner    }
19939a89382SEsther Brunner
20039a89382SEsther Brunner    function preformatted($text){
20139a89382SEsther Brunner        if ($this->capture) $this->doc .= $text;
20239a89382SEsther Brunner    }
20339a89382SEsther Brunner
204c66972f2SAdrian Lang    function file($text, $lang = null, $file = null){
20539a89382SEsther Brunner        if ($this->capture){
20639a89382SEsther Brunner            $this->doc .= DOKU_LF.$text;
20739a89382SEsther Brunner            if (strlen($this->doc) > 250) $this->capture = false;
20839a89382SEsther Brunner            else $this->doc .= DOKU_LF;
20939a89382SEsther Brunner        }
21039a89382SEsther Brunner    }
21139a89382SEsther Brunner
21239a89382SEsther Brunner    function quote_open(){
21371b40da2SAnika Henke        if ($this->capture) $this->doc .= DOKU_LF.DOKU_TAB.'"';
21439a89382SEsther Brunner    }
21539a89382SEsther Brunner
21639a89382SEsther Brunner    function quote_close(){
21739a89382SEsther Brunner        if ($this->capture){
21871b40da2SAnika Henke            $this->doc .= '"';
21939a89382SEsther Brunner            if (strlen($this->doc) > 250) $this->capture = false;
22039a89382SEsther Brunner            else $this->doc .= DOKU_LF;
22139a89382SEsther Brunner        }
22239a89382SEsther Brunner    }
22339a89382SEsther Brunner
224*0ea51e63SMatt Perry    function code($text, $language = null, $file = null){
22539a89382SEsther Brunner        if ($this->capture){
22639a89382SEsther Brunner            $this->doc .= DOKU_LF.$text;
22739a89382SEsther Brunner            if (strlen($this->doc) > 250) $this->capture = false;
22839a89382SEsther Brunner            else $this->doc .= DOKU_LF;
22939a89382SEsther Brunner      }
23039a89382SEsther Brunner    }
23139a89382SEsther Brunner
23239a89382SEsther Brunner    function acronym($acronym){
23339a89382SEsther Brunner        if ($this->capture) $this->doc .= $acronym;
23439a89382SEsther Brunner    }
23539a89382SEsther Brunner
23639a89382SEsther Brunner    function smiley($smiley){
23739a89382SEsther Brunner        if ($this->capture) $this->doc .= $smiley;
23839a89382SEsther Brunner    }
23939a89382SEsther Brunner
24039a89382SEsther Brunner    function entity($entity){
24139a89382SEsther Brunner        if ($this->capture) $this->doc .= $entity;
24239a89382SEsther Brunner    }
24339a89382SEsther Brunner
24439a89382SEsther Brunner    function multiplyentity($x, $y){
24539a89382SEsther Brunner        if ($this->capture) $this->doc .= $x.'×'.$y;
24639a89382SEsther Brunner    }
24739a89382SEsther Brunner
24839a89382SEsther Brunner    function singlequoteopening(){
24971b40da2SAnika Henke        global $lang;
25071b40da2SAnika Henke        if ($this->capture) $this->doc .= $lang['singlequoteopening'];
25139a89382SEsther Brunner    }
25239a89382SEsther Brunner
25339a89382SEsther Brunner    function singlequoteclosing(){
25471b40da2SAnika Henke        global $lang;
25571b40da2SAnika Henke        if ($this->capture) $this->doc .= $lang['singlequoteclosing'];
25639a89382SEsther Brunner    }
25739a89382SEsther Brunner
25857d757d1SAndreas Gohr    function apostrophe() {
25957d757d1SAndreas Gohr        global $lang;
260b58f5d31STom N Harris        if ($this->capture) $this->doc .= $lang['apostrophe'];
26157d757d1SAndreas Gohr    }
26257d757d1SAndreas Gohr
26339a89382SEsther Brunner    function doublequoteopening(){
26471b40da2SAnika Henke        global $lang;
26571b40da2SAnika Henke        if ($this->capture) $this->doc .= $lang['doublequoteopening'];
26639a89382SEsther Brunner    }
26739a89382SEsther Brunner
26839a89382SEsther Brunner    function doublequoteclosing(){
26971b40da2SAnika Henke        global $lang;
27071b40da2SAnika Henke        if ($this->capture) $this->doc .= $lang['doublequoteclosing'];
27139a89382SEsther Brunner    }
27239a89382SEsther Brunner
27339a89382SEsther Brunner    function camelcaselink($link) {
27439a89382SEsther Brunner        $this->internallink($link, $link);
27539a89382SEsther Brunner    }
27639a89382SEsther Brunner
277*0ea51e63SMatt Perry    function locallink($hash, $name = null){}
27839a89382SEsther Brunner
27939a89382SEsther Brunner    /**
28039a89382SEsther Brunner     * keep track of internal links in $this->meta['relation']['references']
28139a89382SEsther Brunner     */
282*0ea51e63SMatt Perry    function internallink($id, $name = null){
28339a89382SEsther Brunner        global $ID;
28439a89382SEsther Brunner
285ffec1009SMichael Hamann        if(is_array($name)) {
286aa5a2937SAndreas Gohr            $this->_firstimage($name['src']);
287ffec1009SMichael Hamann            if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']);
288ffec1009SMichael Hamann        }
289aa5a2937SAndreas Gohr
29066d935e7SMichael Hamann        $parts = explode('?', $id, 2);
29166d935e7SMichael Hamann        if (count($parts) === 2) {
29266d935e7SMichael Hamann            $id = $parts[0];
29366d935e7SMichael Hamann        }
29466d935e7SMichael Hamann
29566d935e7SMichael Hamann
29639a89382SEsther Brunner        $default = $this->_simpleTitle($id);
29739a89382SEsther Brunner
29839a89382SEsther Brunner        // first resolve and clean up the $id
29939a89382SEsther Brunner        resolve_pageid(getNS($ID), $id, $exists);
3004b7f9e70STom N Harris        list($page, $hash) = explode('#', $id, 2);
30139a89382SEsther Brunner
30239a89382SEsther Brunner        // set metadata
3033be6e394Schris        $this->meta['relation']['references'][$page] = $exists;
30439a89382SEsther Brunner        // $data = array('relation' => array('isreferencedby' => array($ID => true)));
30539a89382SEsther Brunner        // p_set_metadata($id, $data);
30639a89382SEsther Brunner
30739a89382SEsther Brunner        // add link title to summary
30839a89382SEsther Brunner        if ($this->capture){
30939a89382SEsther Brunner            $name = $this->_getLinkTitle($name, $default, $id);
31039a89382SEsther Brunner            $this->doc .= $name;
31139a89382SEsther Brunner        }
31239a89382SEsther Brunner    }
31339a89382SEsther Brunner
314*0ea51e63SMatt Perry    function externallink($url, $name = null){
315ffec1009SMichael Hamann        if(is_array($name)) {
316aa5a2937SAndreas Gohr            $this->_firstimage($name['src']);
317ffec1009SMichael Hamann            if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']);
318ffec1009SMichael Hamann        }
319aa5a2937SAndreas Gohr
32039a89382SEsther Brunner        if ($this->capture){
321a2ea2dc1SAdrian Lang            $this->doc .= $this->_getLinkTitle($name, '<' . $url . '>');
32239a89382SEsther Brunner        }
32339a89382SEsther Brunner    }
32439a89382SEsther Brunner
325*0ea51e63SMatt Perry    function interwikilink($match, $name = null, $wikiName, $wikiUri){
326ffec1009SMichael Hamann        if(is_array($name)) {
327aa5a2937SAndreas Gohr            $this->_firstimage($name['src']);
328ffec1009SMichael Hamann            if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']);
329ffec1009SMichael Hamann        }
330aa5a2937SAndreas Gohr
33139a89382SEsther Brunner        if ($this->capture){
33239a89382SEsther Brunner            list($wikiUri, $hash) = explode('#', $wikiUri, 2);
333a2ea2dc1SAdrian Lang            $name = $this->_getLinkTitle($name, $wikiUri);
33439a89382SEsther Brunner            $this->doc .= $name;
33539a89382SEsther Brunner        }
33639a89382SEsther Brunner    }
33739a89382SEsther Brunner
338*0ea51e63SMatt Perry    function windowssharelink($url, $name = null){
339ffec1009SMichael Hamann        if(is_array($name)) {
340aa5a2937SAndreas Gohr            $this->_firstimage($name['src']);
341ffec1009SMichael Hamann            if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']);
342ffec1009SMichael Hamann        }
343aa5a2937SAndreas Gohr
34439a89382SEsther Brunner        if ($this->capture){
34539a89382SEsther Brunner            if ($name) $this->doc .= $name;
34639a89382SEsther Brunner            else $this->doc .= '<'.$url.'>';
34739a89382SEsther Brunner        }
34839a89382SEsther Brunner    }
34939a89382SEsther Brunner
350*0ea51e63SMatt Perry    function emaillink($address, $name = null){
351ffec1009SMichael Hamann        if(is_array($name)) {
352aa5a2937SAndreas Gohr            $this->_firstimage($name['src']);
353ffec1009SMichael Hamann            if ($name['type'] == 'internalmedia') $this->_recordMediaUsage($name['src']);
354ffec1009SMichael Hamann        }
355aa5a2937SAndreas Gohr
35639a89382SEsther Brunner        if ($this->capture){
35739a89382SEsther Brunner            if ($name) $this->doc .= $name;
35839a89382SEsther Brunner            else $this->doc .= '<'.$address.'>';
35939a89382SEsther Brunner        }
36039a89382SEsther Brunner    }
36139a89382SEsther Brunner
362*0ea51e63SMatt Perry    function internalmedia($src, $title=null, $align=null, $width=null,
363*0ea51e63SMatt Perry                           $height=null, $cache=null, $linking=null){
36439a89382SEsther Brunner        if ($this->capture && $title) $this->doc .= '['.$title.']';
365aa5a2937SAndreas Gohr        $this->_firstimage($src);
366ffec1009SMichael Hamann        $this->_recordMediaUsage($src);
36739a89382SEsther Brunner    }
36839a89382SEsther Brunner
369*0ea51e63SMatt Perry    function externalmedia($src, $title=null, $align=null, $width=null,
370*0ea51e63SMatt Perry                           $height=null, $cache=null, $linking=null){
37139a89382SEsther Brunner        if ($this->capture && $title) $this->doc .= '['.$title.']';
372aa5a2937SAndreas Gohr        $this->_firstimage($src);
37339a89382SEsther Brunner    }
37439a89382SEsther Brunner
375ce6b63d9Schris    function rss($url,$params) {
376ce6b63d9Schris        $this->meta['relation']['haspart'][$url] = true;
37764e9144aSchris
37864e9144aSchris        $this->meta['date']['valid']['age'] =
37964e9144aSchris              isset($this->meta['date']['valid']['age']) ?
38064e9144aSchris                  min($this->meta['date']['valid']['age'],$params['refresh']) :
38164e9144aSchris                  $params['refresh'];
382ce6b63d9Schris    }
38339a89382SEsther Brunner
38439a89382SEsther Brunner    //----------------------------------------------------------
38539a89382SEsther Brunner    // Utils
38639a89382SEsther Brunner
38739a89382SEsther Brunner    /**
38839a89382SEsther Brunner     * Removes any Namespace from the given name but keeps
38939a89382SEsther Brunner     * casing and special chars
39039a89382SEsther Brunner     *
39139a89382SEsther Brunner     * @author Andreas Gohr <andi@splitbrain.org>
39239a89382SEsther Brunner     */
39339a89382SEsther Brunner    function _simpleTitle($name){
39439a89382SEsther Brunner        global $conf;
39539a89382SEsther Brunner
3969bee852eSAndreas Gohr        if(is_array($name)) return '';
3979bee852eSAndreas Gohr
39839a89382SEsther Brunner        if($conf['useslash']){
39939a89382SEsther Brunner            $nssep = '[:;/]';
40039a89382SEsther Brunner        }else{
40139a89382SEsther Brunner            $nssep = '[:;]';
40239a89382SEsther Brunner        }
40339a89382SEsther Brunner        $name = preg_replace('!.*'.$nssep.'!','',$name);
4043be6e394Schris        //if there is a hash we use the anchor name only
40539a89382SEsther Brunner        $name = preg_replace('!.*#!','',$name);
40639a89382SEsther Brunner        return $name;
40739a89382SEsther Brunner    }
40839a89382SEsther Brunner
40939a89382SEsther Brunner    /**
41039a89382SEsther Brunner     * Creates a linkid from a headline
41139a89382SEsther Brunner     *
41239a89382SEsther Brunner     * @param string  $title   The headline title
41339a89382SEsther Brunner     * @param boolean $create  Create a new unique ID?
41439a89382SEsther Brunner     * @author Andreas Gohr <andi@splitbrain.org>
41539a89382SEsther Brunner     */
41639a89382SEsther Brunner    function _headerToLink($title, $create=false) {
41739a89382SEsther Brunner        if($create){
418620f4930SAndreas Gohr            return sectionID($title,$this->headers);
419620f4930SAndreas Gohr        }else{
420620f4930SAndreas Gohr            $check = false;
421620f4930SAndreas Gohr            return sectionID($title,$check);
42239a89382SEsther Brunner        }
42339a89382SEsther Brunner    }
42439a89382SEsther Brunner
42539a89382SEsther Brunner    /**
42639a89382SEsther Brunner     * Construct a title and handle images in titles
42739a89382SEsther Brunner     *
42839a89382SEsther Brunner     * @author Harry Fuecks <hfuecks@gmail.com>
42939a89382SEsther Brunner     */
430*0ea51e63SMatt Perry    function _getLinkTitle($title, $default, $id=null) {
43139a89382SEsther Brunner        global $conf;
43239a89382SEsther Brunner
43344881bd0Shenning.noren        $isImage = false;
43485038eabSDanny        if (is_array($title)){
43585038eabSDanny            if($title['title']) return '['.$title['title'].']';
43685038eabSDanny        } else if (is_null($title) || trim($title)==''){
437fe9ec250SChris Smith            if (useHeading('content') && $id){
43820f04039SDanny                $heading = p_get_first_heading($id,METADATA_DONT_RENDER);
43939a89382SEsther Brunner                if ($heading) return $heading;
44039a89382SEsther Brunner            }
44139a89382SEsther Brunner            return $default;
44285038eabSDanny        } else {
44339a89382SEsther Brunner            return $title;
44439a89382SEsther Brunner        }
44539a89382SEsther Brunner    }
44639a89382SEsther Brunner
447aa5a2937SAndreas Gohr    function _firstimage($src){
448aa5a2937SAndreas Gohr        if($this->firstimage) return;
449aa5a2937SAndreas Gohr        global $ID;
450aa5a2937SAndreas Gohr
451aa5a2937SAndreas Gohr        list($src,$hash) = explode('#',$src,2);
4523e7e6067SKlap-in        if(!media_isexternal($src)){
453aa5a2937SAndreas Gohr            resolve_mediaid(getNS($ID),$src, $exists);
454aa5a2937SAndreas Gohr        }
455aa5a2937SAndreas Gohr        if(preg_match('/.(jpe?g|gif|png)$/i',$src)){
456aa5a2937SAndreas Gohr            $this->firstimage = $src;
457aa5a2937SAndreas Gohr        }
458aa5a2937SAndreas Gohr    }
459ffec1009SMichael Hamann
460ffec1009SMichael Hamann    function _recordMediaUsage($src) {
461ffec1009SMichael Hamann        global $ID;
462ffec1009SMichael Hamann
463ffec1009SMichael Hamann        list ($src, $hash) = explode('#', $src, 2);
464ffec1009SMichael Hamann        if (media_isexternal($src)) return;
465ffec1009SMichael Hamann        resolve_mediaid(getNS($ID), $src, $exists);
466ffec1009SMichael Hamann        $this->meta['relation']['media'][$src] = $exists;
467ffec1009SMichael Hamann    }
46839a89382SEsther Brunner}
46939a89382SEsther Brunner
470e3776c06SMichael Hamann//Setup VIM: ex: et ts=4 :
471