xref: /dokuwiki/inc/parser/metadata.php (revision c0322273adef5540c5e780c7a82329b5862a0871)
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    }
48ef47e298SAndreas Gohr    if(!isset($this->persistent['creator'])){
49ef47e298SAndreas Gohr        $this->persistent['creator'] = '';
50ef47e298SAndreas Gohr    }
510a7e3bceSchris    // reset metadata to persistent values
520a7e3bceSchris    $this->meta = $this->persistent;
5339a89382SEsther Brunner  }
5439a89382SEsther Brunner
5539a89382SEsther Brunner  function document_end(){
56482cff99SAndreas Gohr    global $ID;
57482cff99SAndreas Gohr
58b8595a66SAndreas Gohr    // store internal info in metadata (notoc,nocache)
59b8595a66SAndreas Gohr    $this->meta['internal'] = $this->info;
60b8595a66SAndreas Gohr
61c66972f2SAdrian Lang    if (!isset($this->meta['description']['abstract'])){
6239a89382SEsther Brunner      // cut off too long abstracts
6339a89382SEsther Brunner      $this->doc = trim($this->doc);
6439a89382SEsther Brunner      if (strlen($this->doc) > 500)
65bc769d32SAndreas Gohr        $this->doc = utf8_substr($this->doc, 0, 500).'…';
6639a89382SEsther Brunner      $this->meta['description']['abstract'] = $this->doc;
6739a89382SEsther Brunner    }
68aa5a2937SAndreas Gohr
69aa5a2937SAndreas Gohr    $this->meta['relation']['firstimage'] = $this->firstimage;
70482cff99SAndreas Gohr
71*c0322273SAdrian Lang    if(!isset($this->meta['date']['modified'])){
72482cff99SAndreas Gohr        $this->meta['date']['modified'] = filemtime(wikiFN($ID));
73482cff99SAndreas Gohr    }
74482cff99SAndreas Gohr
7539a89382SEsther Brunner  }
7639a89382SEsther Brunner
77e7856beaSchris  function toc_additem($id, $text, $level) {
7839a89382SEsther Brunner    global $conf;
7939a89382SEsther Brunner
80e7856beaSchris    //only add items within configured levels
8139a89382SEsther Brunner    if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){
8239a89382SEsther Brunner      // the TOC is one of our standard ul list arrays ;-)
8339a89382SEsther Brunner      $this->meta['description']['tableofcontents'][] = array(
84e7856beaSchris        'hid'   => $id,
8539a89382SEsther Brunner        'title' => $text,
8639a89382SEsther Brunner        'type'  => 'ul',
8739a89382SEsther Brunner        'level' => $level-$conf['toptoclevel']+1
8839a89382SEsther Brunner      );
8939a89382SEsther Brunner    }
9039a89382SEsther Brunner
91e7856beaSchris  }
92e7856beaSchris
93e7856beaSchris  function header($text, $level, $pos) {
94c66972f2SAdrian Lang    if (!isset($this->meta['title'])) $this->meta['title'] = $text;
95e7856beaSchris
96e7856beaSchris    // add the header to the TOC
97e7856beaSchris    $hid = $this->_headerToLink($text,'true');
98e7856beaSchris    $this->toc_additem($hid, $text, $level);
99e7856beaSchris
10039a89382SEsther Brunner    // add to summary
10139a89382SEsther Brunner    if ($this->capture && ($level > 1)) $this->doc .= DOKU_LF.$text.DOKU_LF;
10239a89382SEsther Brunner  }
10339a89382SEsther Brunner
10439a89382SEsther Brunner  function section_open($level){}
10539a89382SEsther Brunner  function section_close(){}
10639a89382SEsther Brunner
10739a89382SEsther Brunner  function cdata($text){
10839a89382SEsther Brunner    if ($this->capture) $this->doc .= $text;
10939a89382SEsther Brunner  }
11039a89382SEsther Brunner
11139a89382SEsther Brunner  function p_open(){
11239a89382SEsther Brunner    if ($this->capture) $this->doc .= DOKU_LF;
11339a89382SEsther Brunner  }
11439a89382SEsther Brunner
11539a89382SEsther Brunner  function p_close(){
11639a89382SEsther Brunner    if ($this->capture){
11739a89382SEsther Brunner      if (strlen($this->doc) > 250) $this->capture = false;
11839a89382SEsther Brunner      else $this->doc .= DOKU_LF;
11939a89382SEsther Brunner    }
12039a89382SEsther Brunner  }
12139a89382SEsther Brunner
12239a89382SEsther Brunner  function linebreak(){
12339a89382SEsther Brunner    if ($this->capture) $this->doc .= DOKU_LF;
12439a89382SEsther Brunner  }
12539a89382SEsther Brunner
12639a89382SEsther Brunner  function hr(){
12739a89382SEsther Brunner    if ($this->capture){
12839a89382SEsther Brunner      if (strlen($this->doc) > 250) $this->capture = false;
12939a89382SEsther Brunner      else $this->doc .= DOKU_LF.'----------'.DOKU_LF;
13039a89382SEsther Brunner    }
13139a89382SEsther Brunner  }
13239a89382SEsther Brunner
13339a89382SEsther Brunner  function strong_open(){}
13439a89382SEsther Brunner  function strong_close(){}
13539a89382SEsther Brunner
13639a89382SEsther Brunner  function emphasis_open(){}
13739a89382SEsther Brunner  function emphasis_close(){}
13839a89382SEsther Brunner
13939a89382SEsther Brunner  function underline_open(){}
14039a89382SEsther Brunner  function underline_close(){}
14139a89382SEsther Brunner
14239a89382SEsther Brunner  function monospace_open(){}
14339a89382SEsther Brunner  function monospace_close(){}
14439a89382SEsther Brunner
14539a89382SEsther Brunner  function subscript_open(){}
14639a89382SEsther Brunner  function subscript_close(){}
14739a89382SEsther Brunner
14839a89382SEsther Brunner  function superscript_open(){}
14939a89382SEsther Brunner  function superscript_close(){}
15039a89382SEsther Brunner
15139a89382SEsther Brunner  function deleted_open(){}
15239a89382SEsther Brunner  function deleted_close(){}
15339a89382SEsther Brunner
15439a89382SEsther Brunner  /**
15539a89382SEsther Brunner   * Callback for footnote start syntax
15639a89382SEsther Brunner   *
15739a89382SEsther Brunner   * All following content will go to the footnote instead of
15839a89382SEsther Brunner   * the document. To achieve this the previous rendered content
15939a89382SEsther Brunner   * is moved to $store and $doc is cleared
16039a89382SEsther Brunner   *
16139a89382SEsther Brunner   * @author Andreas Gohr <andi@splitbrain.org>
16239a89382SEsther Brunner   */
16339a89382SEsther Brunner  function footnote_open() {
16439a89382SEsther Brunner    if ($this->capture){
16539a89382SEsther Brunner      // move current content to store and record footnote
16639a89382SEsther Brunner      $this->store = $this->doc;
16739a89382SEsther Brunner      $this->doc   = '';
16839a89382SEsther Brunner    }
16939a89382SEsther Brunner  }
17039a89382SEsther Brunner
17139a89382SEsther Brunner  /**
17239a89382SEsther Brunner   * Callback for footnote end syntax
17339a89382SEsther Brunner   *
17439a89382SEsther Brunner   * All rendered content is moved to the $footnotes array and the old
17539a89382SEsther Brunner   * content is restored from $store again
17639a89382SEsther Brunner   *
17739a89382SEsther Brunner   * @author Andreas Gohr
17839a89382SEsther Brunner   */
17939a89382SEsther Brunner  function footnote_close() {
18039a89382SEsther Brunner    if ($this->capture){
18139a89382SEsther Brunner      // restore old content
18239a89382SEsther Brunner      $this->doc = $this->store;
18339a89382SEsther Brunner      $this->store = '';
18439a89382SEsther Brunner    }
18539a89382SEsther Brunner  }
18639a89382SEsther Brunner
18739a89382SEsther Brunner  function listu_open(){
18839a89382SEsther Brunner    if ($this->capture) $this->doc .= DOKU_LF;
18939a89382SEsther Brunner  }
19039a89382SEsther Brunner
19139a89382SEsther Brunner  function listu_close(){
19239a89382SEsther Brunner    if ($this->capture && (strlen($this->doc) > 250)) $this->capture = false;
19339a89382SEsther Brunner  }
19439a89382SEsther Brunner
19539a89382SEsther Brunner  function listo_open(){
19639a89382SEsther Brunner    if ($this->capture) $this->doc .= DOKU_LF;
19739a89382SEsther Brunner  }
19839a89382SEsther Brunner
19939a89382SEsther Brunner  function listo_close(){
20039a89382SEsther Brunner    if ($this->capture && (strlen($this->doc) > 250)) $this->capture = false;
20139a89382SEsther Brunner  }
20239a89382SEsther Brunner
20339a89382SEsther Brunner  function listitem_open($level){
20439a89382SEsther Brunner    if ($this->capture) $this->doc .= str_repeat(DOKU_TAB, $level).'* ';
20539a89382SEsther Brunner  }
20639a89382SEsther Brunner
20739a89382SEsther Brunner  function listitem_close(){
20839a89382SEsther Brunner    if ($this->capture) $this->doc .= DOKU_LF;
20939a89382SEsther Brunner  }
21039a89382SEsther Brunner
21139a89382SEsther Brunner  function listcontent_open(){}
21239a89382SEsther Brunner  function listcontent_close(){}
21339a89382SEsther Brunner
21439a89382SEsther Brunner  function unformatted($text){
21539a89382SEsther Brunner    if ($this->capture) $this->doc .= $text;
21639a89382SEsther Brunner  }
21739a89382SEsther Brunner
21839a89382SEsther Brunner  function php($text){}
21939a89382SEsther Brunner
22007f89c3cSAnika Henke  function phpblock($text){}
22107f89c3cSAnika Henke
22239a89382SEsther Brunner  function html($text){}
22339a89382SEsther Brunner
22407f89c3cSAnika Henke  function htmlblock($text){}
22507f89c3cSAnika Henke
22639a89382SEsther Brunner  function preformatted($text){
22739a89382SEsther Brunner    if ($this->capture) $this->doc .= $text;
22839a89382SEsther Brunner  }
22939a89382SEsther Brunner
230c66972f2SAdrian Lang  function file($text, $lang = null, $file = null){
23139a89382SEsther Brunner    if ($this->capture){
23239a89382SEsther Brunner      $this->doc .= DOKU_LF.$text;
23339a89382SEsther Brunner      if (strlen($this->doc) > 250) $this->capture = false;
23439a89382SEsther Brunner      else $this->doc .= DOKU_LF;
23539a89382SEsther Brunner    }
23639a89382SEsther Brunner  }
23739a89382SEsther Brunner
23839a89382SEsther Brunner  function quote_open(){
23971b40da2SAnika Henke    if ($this->capture) $this->doc .= DOKU_LF.DOKU_TAB.'"';
24039a89382SEsther Brunner  }
24139a89382SEsther Brunner
24239a89382SEsther Brunner  function quote_close(){
24339a89382SEsther Brunner    if ($this->capture){
24471b40da2SAnika Henke      $this->doc .= '"';
24539a89382SEsther Brunner      if (strlen($this->doc) > 250) $this->capture = false;
24639a89382SEsther Brunner      else $this->doc .= DOKU_LF;
24739a89382SEsther Brunner    }
24839a89382SEsther Brunner  }
24939a89382SEsther Brunner
250c66972f2SAdrian Lang  function code($text, $language = NULL, $file = null){
25139a89382SEsther Brunner    if ($this->capture){
25239a89382SEsther Brunner      $this->doc .= DOKU_LF.$text;
25339a89382SEsther Brunner      if (strlen($this->doc) > 250) $this->capture = false;
25439a89382SEsther Brunner      else $this->doc .= DOKU_LF;
25539a89382SEsther Brunner    }
25639a89382SEsther Brunner  }
25739a89382SEsther Brunner
25839a89382SEsther Brunner  function acronym($acronym){
25939a89382SEsther Brunner    if ($this->capture) $this->doc .= $acronym;
26039a89382SEsther Brunner  }
26139a89382SEsther Brunner
26239a89382SEsther Brunner  function smiley($smiley){
26339a89382SEsther Brunner    if ($this->capture) $this->doc .= $smiley;
26439a89382SEsther Brunner  }
26539a89382SEsther Brunner
26639a89382SEsther Brunner  function entity($entity){
26739a89382SEsther Brunner    if ($this->capture) $this->doc .= $entity;
26839a89382SEsther Brunner  }
26939a89382SEsther Brunner
27039a89382SEsther Brunner  function multiplyentity($x, $y){
27139a89382SEsther Brunner    if ($this->capture) $this->doc .= $x.'×'.$y;
27239a89382SEsther Brunner  }
27339a89382SEsther Brunner
27439a89382SEsther Brunner  function singlequoteopening(){
27571b40da2SAnika Henke    global $lang;
27671b40da2SAnika Henke    if ($this->capture) $this->doc .= $lang['singlequoteopening'];
27739a89382SEsther Brunner  }
27839a89382SEsther Brunner
27939a89382SEsther Brunner  function singlequoteclosing(){
28071b40da2SAnika Henke    global $lang;
28171b40da2SAnika Henke    if ($this->capture) $this->doc .= $lang['singlequoteclosing'];
28239a89382SEsther Brunner  }
28339a89382SEsther Brunner
28457d757d1SAndreas Gohr  function apostrophe() {
28557d757d1SAndreas Gohr    global $lang;
286b58f5d31STom N Harris    if ($this->capture) $this->doc .= $lang['apostrophe'];
28757d757d1SAndreas Gohr  }
28857d757d1SAndreas Gohr
28939a89382SEsther Brunner  function doublequoteopening(){
29071b40da2SAnika Henke    global $lang;
29171b40da2SAnika Henke    if ($this->capture) $this->doc .= $lang['doublequoteopening'];
29239a89382SEsther Brunner  }
29339a89382SEsther Brunner
29439a89382SEsther Brunner  function doublequoteclosing(){
29571b40da2SAnika Henke    global $lang;
29671b40da2SAnika Henke    if ($this->capture) $this->doc .= $lang['doublequoteclosing'];
29739a89382SEsther Brunner  }
29839a89382SEsther Brunner
29939a89382SEsther Brunner  function camelcaselink($link) {
30039a89382SEsther Brunner    $this->internallink($link, $link);
30139a89382SEsther Brunner  }
30239a89382SEsther Brunner
30339a89382SEsther Brunner  function locallink($hash, $name = NULL){}
30439a89382SEsther Brunner
30539a89382SEsther Brunner  /**
30639a89382SEsther Brunner   * keep track of internal links in $this->meta['relation']['references']
30739a89382SEsther Brunner   */
30839a89382SEsther Brunner  function internallink($id, $name = NULL){
30939a89382SEsther Brunner    global $ID;
31039a89382SEsther Brunner
311aa5a2937SAndreas Gohr    if(is_array($name))
312aa5a2937SAndreas Gohr        $this->_firstimage($name['src']);
313aa5a2937SAndreas Gohr
31439a89382SEsther Brunner    $default = $this->_simpleTitle($id);
31539a89382SEsther Brunner
31639a89382SEsther Brunner    // first resolve and clean up the $id
31739a89382SEsther Brunner    resolve_pageid(getNS($ID), $id, $exists);
3184b7f9e70STom N Harris    list($page, $hash) = explode('#', $id, 2);
31939a89382SEsther Brunner
32039a89382SEsther Brunner    // set metadata
3213be6e394Schris    $this->meta['relation']['references'][$page] = $exists;
32239a89382SEsther Brunner    // $data = array('relation' => array('isreferencedby' => array($ID => true)));
32339a89382SEsther Brunner    // p_set_metadata($id, $data);
32439a89382SEsther Brunner
32539a89382SEsther Brunner    // add link title to summary
32639a89382SEsther Brunner    if ($this->capture){
32739a89382SEsther Brunner      $name = $this->_getLinkTitle($name, $default, $id);
32839a89382SEsther Brunner      $this->doc .= $name;
32939a89382SEsther Brunner    }
33039a89382SEsther Brunner  }
33139a89382SEsther Brunner
33239a89382SEsther Brunner  function externallink($url, $name = NULL){
333aa5a2937SAndreas Gohr    if(is_array($name))
334aa5a2937SAndreas Gohr        $this->_firstimage($name['src']);
335aa5a2937SAndreas Gohr
33639a89382SEsther Brunner    if ($this->capture){
33739a89382SEsther Brunner      if ($name) $this->doc .= $name;
33839a89382SEsther Brunner      else $this->doc .= '<'.$url.'>';
33939a89382SEsther Brunner    }
34039a89382SEsther Brunner  }
34139a89382SEsther Brunner
34239a89382SEsther Brunner  function interwikilink($match, $name = NULL, $wikiName, $wikiUri){
343aa5a2937SAndreas Gohr    if(is_array($name))
344aa5a2937SAndreas Gohr        $this->_firstimage($name['src']);
345aa5a2937SAndreas Gohr
34639a89382SEsther Brunner    if ($this->capture){
34739a89382SEsther Brunner      list($wikiUri, $hash) = explode('#', $wikiUri, 2);
34839a89382SEsther Brunner      $name = $this->_getLinkTitle($name, $wikiName.'>'.$wikiUri);
34939a89382SEsther Brunner      $this->doc .= $name;
35039a89382SEsther Brunner    }
35139a89382SEsther Brunner  }
35239a89382SEsther Brunner
35339a89382SEsther Brunner  function windowssharelink($url, $name = NULL){
354aa5a2937SAndreas Gohr    if(is_array($name))
355aa5a2937SAndreas Gohr        $this->_firstimage($name['src']);
356aa5a2937SAndreas Gohr
35739a89382SEsther Brunner    if ($this->capture){
35839a89382SEsther Brunner      if ($name) $this->doc .= $name;
35939a89382SEsther Brunner      else $this->doc .= '<'.$url.'>';
36039a89382SEsther Brunner    }
36139a89382SEsther Brunner  }
36239a89382SEsther Brunner
36339a89382SEsther Brunner  function emaillink($address, $name = NULL){
364aa5a2937SAndreas Gohr    if(is_array($name))
365aa5a2937SAndreas Gohr        $this->_firstimage($name['src']);
366aa5a2937SAndreas Gohr
36739a89382SEsther Brunner    if ($this->capture){
36839a89382SEsther Brunner      if ($name) $this->doc .= $name;
36939a89382SEsther Brunner      else $this->doc .= '<'.$address.'>';
37039a89382SEsther Brunner    }
37139a89382SEsther Brunner  }
37239a89382SEsther Brunner
37339a89382SEsther Brunner  function internalmedia($src, $title=NULL, $align=NULL, $width=NULL,
37439a89382SEsther Brunner                         $height=NULL, $cache=NULL, $linking=NULL){
37539a89382SEsther Brunner    if ($this->capture && $title) $this->doc .= '['.$title.']';
376aa5a2937SAndreas Gohr    $this->_firstimage($src);
37739a89382SEsther Brunner  }
37839a89382SEsther Brunner
37939a89382SEsther Brunner  function externalmedia($src, $title=NULL, $align=NULL, $width=NULL,
38039a89382SEsther Brunner                         $height=NULL, $cache=NULL, $linking=NULL){
38139a89382SEsther Brunner    if ($this->capture && $title) $this->doc .= '['.$title.']';
382aa5a2937SAndreas Gohr    $this->_firstimage($src);
38339a89382SEsther Brunner  }
38439a89382SEsther Brunner
385ce6b63d9Schris  function rss($url,$params) {
386ce6b63d9Schris    $this->meta['relation']['haspart'][$url] = true;
38764e9144aSchris
38864e9144aSchris    $this->meta['date']['valid']['age'] =
38964e9144aSchris            isset($this->meta['date']['valid']['age']) ?
39064e9144aSchris                min($this->meta['date']['valid']['age'],$params['refresh']) :
39164e9144aSchris                $params['refresh'];
392ce6b63d9Schris  }
39339a89382SEsther Brunner
39439a89382SEsther Brunner  function table_open($maxcols = NULL, $numrows = NULL){}
39539a89382SEsther Brunner  function table_close(){}
39639a89382SEsther Brunner
39739a89382SEsther Brunner  function tablerow_open(){}
39839a89382SEsther Brunner  function tablerow_close(){}
39939a89382SEsther Brunner
40025b97867Shakan.sandell  function tableheader_open($colspan = 1, $align = NULL, $rowspan = 1){}
40139a89382SEsther Brunner  function tableheader_close(){}
40239a89382SEsther Brunner
40325b97867Shakan.sandell  function tablecell_open($colspan = 1, $align = NULL, $rowspan = 1){}
40439a89382SEsther Brunner  function tablecell_close(){}
40539a89382SEsther Brunner
40639a89382SEsther Brunner  //----------------------------------------------------------
40739a89382SEsther Brunner  // Utils
40839a89382SEsther Brunner
40939a89382SEsther Brunner  /**
41039a89382SEsther Brunner   * Removes any Namespace from the given name but keeps
41139a89382SEsther Brunner   * casing and special chars
41239a89382SEsther Brunner   *
41339a89382SEsther Brunner   * @author Andreas Gohr <andi@splitbrain.org>
41439a89382SEsther Brunner   */
41539a89382SEsther Brunner  function _simpleTitle($name){
41639a89382SEsther Brunner    global $conf;
41739a89382SEsther Brunner
4189bee852eSAndreas Gohr    if(is_array($name)) return '';
4199bee852eSAndreas Gohr
42039a89382SEsther Brunner    if($conf['useslash']){
42139a89382SEsther Brunner        $nssep = '[:;/]';
42239a89382SEsther Brunner    }else{
42339a89382SEsther Brunner        $nssep = '[:;]';
42439a89382SEsther Brunner    }
42539a89382SEsther Brunner    $name = preg_replace('!.*'.$nssep.'!','',$name);
4263be6e394Schris    //if there is a hash we use the anchor name only
42739a89382SEsther Brunner    $name = preg_replace('!.*#!','',$name);
42839a89382SEsther Brunner    return $name;
42939a89382SEsther Brunner  }
43039a89382SEsther Brunner
43139a89382SEsther Brunner  /**
43239a89382SEsther Brunner   * Creates a linkid from a headline
43339a89382SEsther Brunner   *
43439a89382SEsther Brunner   * @param string  $title   The headline title
43539a89382SEsther Brunner   * @param boolean $create  Create a new unique ID?
43639a89382SEsther Brunner   * @author Andreas Gohr <andi@splitbrain.org>
43739a89382SEsther Brunner   */
43839a89382SEsther Brunner  function _headerToLink($title, $create=false) {
43939a89382SEsther Brunner      if($create){
440620f4930SAndreas Gohr          return sectionID($title,$this->headers);
441620f4930SAndreas Gohr      }else{
442620f4930SAndreas Gohr          $check = false;
443620f4930SAndreas Gohr          return sectionID($title,$check);
44439a89382SEsther Brunner      }
44539a89382SEsther Brunner  }
44639a89382SEsther Brunner
44739a89382SEsther Brunner  /**
44839a89382SEsther Brunner   * Construct a title and handle images in titles
44939a89382SEsther Brunner   *
45039a89382SEsther Brunner   * @author Harry Fuecks <hfuecks@gmail.com>
45139a89382SEsther Brunner   */
45239a89382SEsther Brunner  function _getLinkTitle($title, $default, $id=NULL) {
45339a89382SEsther Brunner    global $conf;
45439a89382SEsther Brunner
45544881bd0Shenning.noren    $isImage = false;
45639a89382SEsther Brunner    if (is_null($title)){
457fe9ec250SChris Smith      if (useHeading('content') && $id){
458fc18c0fbSchris        $heading = p_get_first_heading($id,false);
45939a89382SEsther Brunner        if ($heading) return $heading;
46039a89382SEsther Brunner      }
46139a89382SEsther Brunner      return $default;
46239a89382SEsther Brunner    } else if (is_string($title)){
46339a89382SEsther Brunner      return $title;
46439a89382SEsther Brunner    } else if (is_array($title)){
465aa5a2937SAndreas Gohr      return '['.$title['title'].']';
46639a89382SEsther Brunner    }
46739a89382SEsther Brunner  }
46839a89382SEsther Brunner
469aa5a2937SAndreas Gohr  function _firstimage($src){
470aa5a2937SAndreas Gohr    if($this->firstimage) return;
471aa5a2937SAndreas Gohr    global $ID;
472aa5a2937SAndreas Gohr
473aa5a2937SAndreas Gohr    list($src,$hash) = explode('#',$src,2);
474aa5a2937SAndreas Gohr    if(!preg_match('/^https?:\/\//i',$src)){
475aa5a2937SAndreas Gohr        resolve_mediaid(getNS($ID),$src, $exists);
476aa5a2937SAndreas Gohr    }
477aa5a2937SAndreas Gohr    if(preg_match('/.(jpe?g|gif|png)$/i',$src)){
478aa5a2937SAndreas Gohr        $this->firstimage = $src;
479aa5a2937SAndreas Gohr    }
480aa5a2937SAndreas Gohr  }
48139a89382SEsther Brunner}
48239a89382SEsther Brunner
48339a89382SEsther Brunner//Setup VIM: ex: et ts=4 enc=utf-8 :
484