xref: /dokuwiki/inc/parser/metadata.php (revision aa5a29376d31a6787c8fa1025af1d1fb4d64dec8)
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   = '';
33*aa5a2937SAndreas Gohr  var $firstimage = '';
3439a89382SEsther Brunner
355f70445dSAndreas Gohr  function getFormat(){
365f70445dSAndreas Gohr    return 'metadata';
375f70445dSAndreas Gohr  }
385f70445dSAndreas Gohr
3939a89382SEsther Brunner  function document_start(){
400a7e3bceSchris    // reset metadata to persistent values
410a7e3bceSchris    $this->meta = $this->persistent;
4239a89382SEsther Brunner  }
4339a89382SEsther Brunner
4439a89382SEsther Brunner  function document_end(){
45b8595a66SAndreas Gohr    // store internal info in metadata (notoc,nocache)
46b8595a66SAndreas Gohr    $this->meta['internal'] = $this->info;
47b8595a66SAndreas Gohr
4839a89382SEsther Brunner    if (!$this->meta['description']['abstract']){
4939a89382SEsther Brunner      // cut off too long abstracts
5039a89382SEsther Brunner      $this->doc = trim($this->doc);
5139a89382SEsther Brunner      if (strlen($this->doc) > 500)
52bc769d32SAndreas Gohr        $this->doc = utf8_substr($this->doc, 0, 500).'…';
5339a89382SEsther Brunner      $this->meta['description']['abstract'] = $this->doc;
5439a89382SEsther Brunner    }
55*aa5a2937SAndreas Gohr
56*aa5a2937SAndreas Gohr    $this->meta['relation']['firstimage'] = $this->firstimage;
5739a89382SEsther Brunner  }
5839a89382SEsther Brunner
59e7856beaSchris  function toc_additem($id, $text, $level) {
6039a89382SEsther Brunner    global $conf;
6139a89382SEsther Brunner
62e7856beaSchris    //only add items within configured levels
6339a89382SEsther Brunner    if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){
6439a89382SEsther Brunner      // the TOC is one of our standard ul list arrays ;-)
6539a89382SEsther Brunner      $this->meta['description']['tableofcontents'][] = array(
66e7856beaSchris        'hid'   => $id,
6739a89382SEsther Brunner        'title' => $text,
6839a89382SEsther Brunner        'type'  => 'ul',
6939a89382SEsther Brunner        'level' => $level-$conf['toptoclevel']+1
7039a89382SEsther Brunner      );
7139a89382SEsther Brunner    }
7239a89382SEsther Brunner
73e7856beaSchris  }
74e7856beaSchris
75e7856beaSchris  function header($text, $level, $pos) {
76e7856beaSchris    if (!$this->meta['title']) $this->meta['title'] = $text;
77e7856beaSchris
78e7856beaSchris    // add the header to the TOC
79e7856beaSchris    $hid = $this->_headerToLink($text,'true');
80e7856beaSchris    $this->toc_additem($hid, $text, $level);
81e7856beaSchris
8239a89382SEsther Brunner    // add to summary
8339a89382SEsther Brunner    if ($this->capture && ($level > 1)) $this->doc .= DOKU_LF.$text.DOKU_LF;
8439a89382SEsther Brunner  }
8539a89382SEsther Brunner
8639a89382SEsther Brunner  function section_open($level){}
8739a89382SEsther Brunner  function section_close(){}
8839a89382SEsther Brunner
8939a89382SEsther Brunner  function cdata($text){
9039a89382SEsther Brunner    if ($this->capture) $this->doc .= $text;
9139a89382SEsther Brunner  }
9239a89382SEsther Brunner
9339a89382SEsther Brunner  function p_open(){
9439a89382SEsther Brunner    if ($this->capture) $this->doc .= DOKU_LF;
9539a89382SEsther Brunner  }
9639a89382SEsther Brunner
9739a89382SEsther Brunner  function p_close(){
9839a89382SEsther Brunner    if ($this->capture){
9939a89382SEsther Brunner      if (strlen($this->doc) > 250) $this->capture = false;
10039a89382SEsther Brunner      else $this->doc .= DOKU_LF;
10139a89382SEsther Brunner    }
10239a89382SEsther Brunner  }
10339a89382SEsther Brunner
10439a89382SEsther Brunner  function linebreak(){
10539a89382SEsther Brunner    if ($this->capture) $this->doc .= DOKU_LF;
10639a89382SEsther Brunner  }
10739a89382SEsther Brunner
10839a89382SEsther Brunner  function hr(){
10939a89382SEsther Brunner    if ($this->capture){
11039a89382SEsther Brunner      if (strlen($this->doc) > 250) $this->capture = false;
11139a89382SEsther Brunner      else $this->doc .= DOKU_LF.'----------'.DOKU_LF;
11239a89382SEsther Brunner    }
11339a89382SEsther Brunner  }
11439a89382SEsther Brunner
11539a89382SEsther Brunner  function strong_open(){}
11639a89382SEsther Brunner  function strong_close(){}
11739a89382SEsther Brunner
11839a89382SEsther Brunner  function emphasis_open(){}
11939a89382SEsther Brunner  function emphasis_close(){}
12039a89382SEsther Brunner
12139a89382SEsther Brunner  function underline_open(){}
12239a89382SEsther Brunner  function underline_close(){}
12339a89382SEsther Brunner
12439a89382SEsther Brunner  function monospace_open(){}
12539a89382SEsther Brunner  function monospace_close(){}
12639a89382SEsther Brunner
12739a89382SEsther Brunner  function subscript_open(){}
12839a89382SEsther Brunner  function subscript_close(){}
12939a89382SEsther Brunner
13039a89382SEsther Brunner  function superscript_open(){}
13139a89382SEsther Brunner  function superscript_close(){}
13239a89382SEsther Brunner
13339a89382SEsther Brunner  function deleted_open(){}
13439a89382SEsther Brunner  function deleted_close(){}
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 php($text){}
20139a89382SEsther Brunner
20207f89c3cSAnika Henke  function phpblock($text){}
20307f89c3cSAnika Henke
20439a89382SEsther Brunner  function html($text){}
20539a89382SEsther Brunner
20607f89c3cSAnika Henke  function htmlblock($text){}
20707f89c3cSAnika Henke
20839a89382SEsther Brunner  function preformatted($text){
20939a89382SEsther Brunner    if ($this->capture) $this->doc .= $text;
21039a89382SEsther Brunner  }
21139a89382SEsther Brunner
21239a89382SEsther Brunner  function file($text){
21339a89382SEsther Brunner    if ($this->capture){
21439a89382SEsther Brunner      $this->doc .= DOKU_LF.$text;
21539a89382SEsther Brunner      if (strlen($this->doc) > 250) $this->capture = false;
21639a89382SEsther Brunner      else $this->doc .= DOKU_LF;
21739a89382SEsther Brunner    }
21839a89382SEsther Brunner  }
21939a89382SEsther Brunner
22039a89382SEsther Brunner  function quote_open(){
22171b40da2SAnika Henke    if ($this->capture) $this->doc .= DOKU_LF.DOKU_TAB.'"';
22239a89382SEsther Brunner  }
22339a89382SEsther Brunner
22439a89382SEsther Brunner  function quote_close(){
22539a89382SEsther Brunner    if ($this->capture){
22671b40da2SAnika Henke      $this->doc .= '"';
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 code($text, $language = NULL){
23339a89382SEsther Brunner    if ($this->capture){
23439a89382SEsther Brunner      $this->doc .= DOKU_LF.$text;
23539a89382SEsther Brunner      if (strlen($this->doc) > 250) $this->capture = false;
23639a89382SEsther Brunner      else $this->doc .= DOKU_LF;
23739a89382SEsther Brunner    }
23839a89382SEsther Brunner  }
23939a89382SEsther Brunner
24039a89382SEsther Brunner  function acronym($acronym){
24139a89382SEsther Brunner    if ($this->capture) $this->doc .= $acronym;
24239a89382SEsther Brunner  }
24339a89382SEsther Brunner
24439a89382SEsther Brunner  function smiley($smiley){
24539a89382SEsther Brunner    if ($this->capture) $this->doc .= $smiley;
24639a89382SEsther Brunner  }
24739a89382SEsther Brunner
24839a89382SEsther Brunner  function entity($entity){
24939a89382SEsther Brunner    if ($this->capture) $this->doc .= $entity;
25039a89382SEsther Brunner  }
25139a89382SEsther Brunner
25239a89382SEsther Brunner  function multiplyentity($x, $y){
25339a89382SEsther Brunner    if ($this->capture) $this->doc .= $x.'×'.$y;
25439a89382SEsther Brunner  }
25539a89382SEsther Brunner
25639a89382SEsther Brunner  function singlequoteopening(){
25771b40da2SAnika Henke    global $lang;
25871b40da2SAnika Henke    if ($this->capture) $this->doc .= $lang['singlequoteopening'];
25939a89382SEsther Brunner  }
26039a89382SEsther Brunner
26139a89382SEsther Brunner  function singlequoteclosing(){
26271b40da2SAnika Henke    global $lang;
26371b40da2SAnika Henke    if ($this->capture) $this->doc .= $lang['singlequoteclosing'];
26439a89382SEsther Brunner  }
26539a89382SEsther Brunner
26657d757d1SAndreas Gohr  function apostrophe() {
26757d757d1SAndreas Gohr    global $lang;
268b58f5d31STom N Harris    if ($this->capture) $this->doc .= $lang['apostrophe'];
26957d757d1SAndreas Gohr  }
27057d757d1SAndreas Gohr
27139a89382SEsther Brunner  function doublequoteopening(){
27271b40da2SAnika Henke    global $lang;
27371b40da2SAnika Henke    if ($this->capture) $this->doc .= $lang['doublequoteopening'];
27439a89382SEsther Brunner  }
27539a89382SEsther Brunner
27639a89382SEsther Brunner  function doublequoteclosing(){
27771b40da2SAnika Henke    global $lang;
27871b40da2SAnika Henke    if ($this->capture) $this->doc .= $lang['doublequoteclosing'];
27939a89382SEsther Brunner  }
28039a89382SEsther Brunner
28139a89382SEsther Brunner  function camelcaselink($link) {
28239a89382SEsther Brunner    $this->internallink($link, $link);
28339a89382SEsther Brunner  }
28439a89382SEsther Brunner
28539a89382SEsther Brunner  function locallink($hash, $name = NULL){}
28639a89382SEsther Brunner
28739a89382SEsther Brunner  /**
28839a89382SEsther Brunner   * keep track of internal links in $this->meta['relation']['references']
28939a89382SEsther Brunner   */
29039a89382SEsther Brunner  function internallink($id, $name = NULL){
29139a89382SEsther Brunner    global $ID;
29239a89382SEsther Brunner
293*aa5a2937SAndreas Gohr    if(is_array($name))
294*aa5a2937SAndreas Gohr        $this->_firstimage($name['src']);
295*aa5a2937SAndreas Gohr
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);
3003be6e394Schris    list($page, $hash) = split('#', $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
31439a89382SEsther Brunner  function externallink($url, $name = NULL){
315*aa5a2937SAndreas Gohr    if(is_array($name))
316*aa5a2937SAndreas Gohr        $this->_firstimage($name['src']);
317*aa5a2937SAndreas Gohr
31839a89382SEsther Brunner    if ($this->capture){
31939a89382SEsther Brunner      if ($name) $this->doc .= $name;
32039a89382SEsther Brunner      else $this->doc .= '<'.$url.'>';
32139a89382SEsther Brunner    }
32239a89382SEsther Brunner  }
32339a89382SEsther Brunner
32439a89382SEsther Brunner  function interwikilink($match, $name = NULL, $wikiName, $wikiUri){
325*aa5a2937SAndreas Gohr    if(is_array($name))
326*aa5a2937SAndreas Gohr        $this->_firstimage($name['src']);
327*aa5a2937SAndreas Gohr
32839a89382SEsther Brunner    if ($this->capture){
32939a89382SEsther Brunner      list($wikiUri, $hash) = explode('#', $wikiUri, 2);
33039a89382SEsther Brunner      $name = $this->_getLinkTitle($name, $wikiName.'>'.$wikiUri);
33139a89382SEsther Brunner      $this->doc .= $name;
33239a89382SEsther Brunner    }
33339a89382SEsther Brunner  }
33439a89382SEsther Brunner
33539a89382SEsther Brunner  function windowssharelink($url, $name = NULL){
336*aa5a2937SAndreas Gohr    if(is_array($name))
337*aa5a2937SAndreas Gohr        $this->_firstimage($name['src']);
338*aa5a2937SAndreas Gohr
33939a89382SEsther Brunner    if ($this->capture){
34039a89382SEsther Brunner      if ($name) $this->doc .= $name;
34139a89382SEsther Brunner      else $this->doc .= '<'.$url.'>';
34239a89382SEsther Brunner    }
34339a89382SEsther Brunner  }
34439a89382SEsther Brunner
34539a89382SEsther Brunner  function emaillink($address, $name = NULL){
346*aa5a2937SAndreas Gohr    if(is_array($name))
347*aa5a2937SAndreas Gohr        $this->_firstimage($name['src']);
348*aa5a2937SAndreas Gohr
34939a89382SEsther Brunner    if ($this->capture){
35039a89382SEsther Brunner      if ($name) $this->doc .= $name;
35139a89382SEsther Brunner      else $this->doc .= '<'.$address.'>';
35239a89382SEsther Brunner    }
35339a89382SEsther Brunner  }
35439a89382SEsther Brunner
35539a89382SEsther Brunner  function internalmedia($src, $title=NULL, $align=NULL, $width=NULL,
35639a89382SEsther Brunner                         $height=NULL, $cache=NULL, $linking=NULL){
35739a89382SEsther Brunner    if ($this->capture && $title) $this->doc .= '['.$title.']';
358*aa5a2937SAndreas Gohr    $this->_firstimage($src);
35939a89382SEsther Brunner  }
36039a89382SEsther Brunner
36139a89382SEsther Brunner  function externalmedia($src, $title=NULL, $align=NULL, $width=NULL,
36239a89382SEsther Brunner                         $height=NULL, $cache=NULL, $linking=NULL){
36339a89382SEsther Brunner    if ($this->capture && $title) $this->doc .= '['.$title.']';
364*aa5a2937SAndreas Gohr    $this->_firstimage($src);
36539a89382SEsther Brunner  }
36639a89382SEsther Brunner
367ce6b63d9Schris  function rss($url,$params) {
368ce6b63d9Schris    $this->meta['relation']['haspart'][$url] = true;
36964e9144aSchris
37064e9144aSchris    $this->meta['date']['valid']['age'] =
37164e9144aSchris            isset($this->meta['date']['valid']['age']) ?
37264e9144aSchris                min($this->meta['date']['valid']['age'],$params['refresh']) :
37364e9144aSchris                $params['refresh'];
374ce6b63d9Schris  }
37539a89382SEsther Brunner
37639a89382SEsther Brunner  function table_open($maxcols = NULL, $numrows = NULL){}
37739a89382SEsther Brunner  function table_close(){}
37839a89382SEsther Brunner
37939a89382SEsther Brunner  function tablerow_open(){}
38039a89382SEsther Brunner  function tablerow_close(){}
38139a89382SEsther Brunner
38239a89382SEsther Brunner  function tableheader_open($colspan = 1, $align = NULL){}
38339a89382SEsther Brunner  function tableheader_close(){}
38439a89382SEsther Brunner
38539a89382SEsther Brunner  function tablecell_open($colspan = 1, $align = NULL){}
38639a89382SEsther Brunner  function tablecell_close(){}
38739a89382SEsther Brunner
38839a89382SEsther Brunner  //----------------------------------------------------------
38939a89382SEsther Brunner  // Utils
39039a89382SEsther Brunner
39139a89382SEsther Brunner  /**
39239a89382SEsther Brunner   * Removes any Namespace from the given name but keeps
39339a89382SEsther Brunner   * casing and special chars
39439a89382SEsther Brunner   *
39539a89382SEsther Brunner   * @author Andreas Gohr <andi@splitbrain.org>
39639a89382SEsther Brunner   */
39739a89382SEsther Brunner  function _simpleTitle($name){
39839a89382SEsther Brunner    global $conf;
39939a89382SEsther Brunner
4009bee852eSAndreas Gohr    if(is_array($name)) return '';
4019bee852eSAndreas Gohr
40239a89382SEsther Brunner    if($conf['useslash']){
40339a89382SEsther Brunner        $nssep = '[:;/]';
40439a89382SEsther Brunner    }else{
40539a89382SEsther Brunner        $nssep = '[:;]';
40639a89382SEsther Brunner    }
40739a89382SEsther Brunner    $name = preg_replace('!.*'.$nssep.'!','',$name);
4083be6e394Schris    //if there is a hash we use the anchor name only
40939a89382SEsther Brunner    $name = preg_replace('!.*#!','',$name);
41039a89382SEsther Brunner    return $name;
41139a89382SEsther Brunner  }
41239a89382SEsther Brunner
41339a89382SEsther Brunner  /**
41439a89382SEsther Brunner   * Creates a linkid from a headline
41539a89382SEsther Brunner   *
41639a89382SEsther Brunner   * @param string  $title   The headline title
41739a89382SEsther Brunner   * @param boolean $create  Create a new unique ID?
41839a89382SEsther Brunner   * @author Andreas Gohr <andi@splitbrain.org>
41939a89382SEsther Brunner   */
42039a89382SEsther Brunner  function _headerToLink($title, $create=false) {
4215fe80182Schris    $title = str_replace(':','',cleanID($title));
42239a89382SEsther Brunner    $title = ltrim($title,'0123456789._-');
42339a89382SEsther Brunner    if(empty($title)) $title='section';
42439a89382SEsther Brunner
42539a89382SEsther Brunner    if($create){
42639a89382SEsther Brunner      // make sure tiles are unique
42739a89382SEsther Brunner      $num = '';
42839a89382SEsther Brunner      while(in_array($title.$num,$this->headers)){
42939a89382SEsther Brunner        ($num) ? $num++ : $num = 1;
43039a89382SEsther Brunner      }
43139a89382SEsther Brunner      $title = $title.$num;
43239a89382SEsther Brunner      $this->headers[] = $title;
43339a89382SEsther Brunner    }
43439a89382SEsther Brunner
43539a89382SEsther Brunner    return $title;
43639a89382SEsther Brunner  }
43739a89382SEsther Brunner
43839a89382SEsther Brunner  /**
43939a89382SEsther Brunner   * Construct a title and handle images in titles
44039a89382SEsther Brunner   *
44139a89382SEsther Brunner   * @author Harry Fuecks <hfuecks@gmail.com>
44239a89382SEsther Brunner   */
44339a89382SEsther Brunner  function _getLinkTitle($title, $default, $id=NULL) {
44439a89382SEsther Brunner    global $conf;
44539a89382SEsther Brunner
44644881bd0Shenning.noren    $isImage = false;
44739a89382SEsther Brunner    if (is_null($title)){
448fe9ec250SChris Smith      if (useHeading('content') && $id){
449fc18c0fbSchris        $heading = p_get_first_heading($id,false);
45039a89382SEsther Brunner        if ($heading) return $heading;
45139a89382SEsther Brunner      }
45239a89382SEsther Brunner      return $default;
45339a89382SEsther Brunner    } else if (is_string($title)){
45439a89382SEsther Brunner      return $title;
45539a89382SEsther Brunner    } else if (is_array($title)){
456*aa5a2937SAndreas Gohr      return '['.$title['title'].']';
45739a89382SEsther Brunner    }
45839a89382SEsther Brunner  }
45939a89382SEsther Brunner
460*aa5a2937SAndreas Gohr  function _firstimage($src){
461*aa5a2937SAndreas Gohr    if($this->firstimage) return;
462*aa5a2937SAndreas Gohr    global $ID;
463*aa5a2937SAndreas Gohr
464*aa5a2937SAndreas Gohr    list($src,$hash) = explode('#',$src,2);
465*aa5a2937SAndreas Gohr    if(!preg_match('/^https?:\/\//i',$src)){
466*aa5a2937SAndreas Gohr        resolve_mediaid(getNS($ID),$src, $exists);
467*aa5a2937SAndreas Gohr    }
468*aa5a2937SAndreas Gohr    if(preg_match('/.(jpe?g|gif|png)$/i',$src)){
469*aa5a2937SAndreas Gohr        $this->firstimage = $src;
470*aa5a2937SAndreas Gohr    }
471*aa5a2937SAndreas Gohr  }
47239a89382SEsther Brunner}
47339a89382SEsther Brunner
47439a89382SEsther Brunner//Setup VIM: ex: et ts=4 enc=utf-8 :
475