xref: /dokuwiki/inc/parser/metadata.php (revision 482cff99db7d1adceafa4fd4b55412aeb6bd94a3)
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(){
400a7e3bceSchris    // reset metadata to persistent values
410a7e3bceSchris    $this->meta = $this->persistent;
4239a89382SEsther Brunner  }
4339a89382SEsther Brunner
4439a89382SEsther Brunner  function document_end(){
45*482cff99SAndreas Gohr    global $ID;
46*482cff99SAndreas Gohr
47b8595a66SAndreas Gohr    // store internal info in metadata (notoc,nocache)
48b8595a66SAndreas Gohr    $this->meta['internal'] = $this->info;
49b8595a66SAndreas Gohr
5039a89382SEsther Brunner    if (!$this->meta['description']['abstract']){
5139a89382SEsther Brunner      // cut off too long abstracts
5239a89382SEsther Brunner      $this->doc = trim($this->doc);
5339a89382SEsther Brunner      if (strlen($this->doc) > 500)
54bc769d32SAndreas Gohr        $this->doc = utf8_substr($this->doc, 0, 500).'…';
5539a89382SEsther Brunner      $this->meta['description']['abstract'] = $this->doc;
5639a89382SEsther Brunner    }
57aa5a2937SAndreas Gohr
58aa5a2937SAndreas Gohr    $this->meta['relation']['firstimage'] = $this->firstimage;
59*482cff99SAndreas Gohr
60*482cff99SAndreas Gohr    // create missing data on externally created pages
61*482cff99SAndreas Gohr
62*482cff99SAndreas Gohr    if(!$this->meta['date']['modified']){
63*482cff99SAndreas Gohr        $this->meta['date']['modified'] = filemtime(wikiFN($ID));
64*482cff99SAndreas Gohr    }
65*482cff99SAndreas Gohr
66*482cff99SAndreas Gohr    if(!$this->meta['date']['created']){
67*482cff99SAndreas Gohr        $this->meta['date']['created'] = $this->meta['date']['modified'];
68*482cff99SAndreas Gohr    }
69*482cff99SAndreas Gohr
70*482cff99SAndreas Gohr    if(!isset($this->meta['creator'])){
71*482cff99SAndreas Gohr        $this->meta['creator'] = '';
72*482cff99SAndreas Gohr    }
7339a89382SEsther Brunner  }
7439a89382SEsther Brunner
75e7856beaSchris  function toc_additem($id, $text, $level) {
7639a89382SEsther Brunner    global $conf;
7739a89382SEsther Brunner
78e7856beaSchris    //only add items within configured levels
7939a89382SEsther Brunner    if($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']){
8039a89382SEsther Brunner      // the TOC is one of our standard ul list arrays ;-)
8139a89382SEsther Brunner      $this->meta['description']['tableofcontents'][] = array(
82e7856beaSchris        'hid'   => $id,
8339a89382SEsther Brunner        'title' => $text,
8439a89382SEsther Brunner        'type'  => 'ul',
8539a89382SEsther Brunner        'level' => $level-$conf['toptoclevel']+1
8639a89382SEsther Brunner      );
8739a89382SEsther Brunner    }
8839a89382SEsther Brunner
89e7856beaSchris  }
90e7856beaSchris
91e7856beaSchris  function header($text, $level, $pos) {
92e7856beaSchris    if (!$this->meta['title']) $this->meta['title'] = $text;
93e7856beaSchris
94e7856beaSchris    // add the header to the TOC
95e7856beaSchris    $hid = $this->_headerToLink($text,'true');
96e7856beaSchris    $this->toc_additem($hid, $text, $level);
97e7856beaSchris
9839a89382SEsther Brunner    // add to summary
9939a89382SEsther Brunner    if ($this->capture && ($level > 1)) $this->doc .= DOKU_LF.$text.DOKU_LF;
10039a89382SEsther Brunner  }
10139a89382SEsther Brunner
10239a89382SEsther Brunner  function section_open($level){}
10339a89382SEsther Brunner  function section_close(){}
10439a89382SEsther Brunner
10539a89382SEsther Brunner  function cdata($text){
10639a89382SEsther Brunner    if ($this->capture) $this->doc .= $text;
10739a89382SEsther Brunner  }
10839a89382SEsther Brunner
10939a89382SEsther Brunner  function p_open(){
11039a89382SEsther Brunner    if ($this->capture) $this->doc .= DOKU_LF;
11139a89382SEsther Brunner  }
11239a89382SEsther Brunner
11339a89382SEsther Brunner  function p_close(){
11439a89382SEsther Brunner    if ($this->capture){
11539a89382SEsther Brunner      if (strlen($this->doc) > 250) $this->capture = false;
11639a89382SEsther Brunner      else $this->doc .= DOKU_LF;
11739a89382SEsther Brunner    }
11839a89382SEsther Brunner  }
11939a89382SEsther Brunner
12039a89382SEsther Brunner  function linebreak(){
12139a89382SEsther Brunner    if ($this->capture) $this->doc .= DOKU_LF;
12239a89382SEsther Brunner  }
12339a89382SEsther Brunner
12439a89382SEsther Brunner  function hr(){
12539a89382SEsther Brunner    if ($this->capture){
12639a89382SEsther Brunner      if (strlen($this->doc) > 250) $this->capture = false;
12739a89382SEsther Brunner      else $this->doc .= DOKU_LF.'----------'.DOKU_LF;
12839a89382SEsther Brunner    }
12939a89382SEsther Brunner  }
13039a89382SEsther Brunner
13139a89382SEsther Brunner  function strong_open(){}
13239a89382SEsther Brunner  function strong_close(){}
13339a89382SEsther Brunner
13439a89382SEsther Brunner  function emphasis_open(){}
13539a89382SEsther Brunner  function emphasis_close(){}
13639a89382SEsther Brunner
13739a89382SEsther Brunner  function underline_open(){}
13839a89382SEsther Brunner  function underline_close(){}
13939a89382SEsther Brunner
14039a89382SEsther Brunner  function monospace_open(){}
14139a89382SEsther Brunner  function monospace_close(){}
14239a89382SEsther Brunner
14339a89382SEsther Brunner  function subscript_open(){}
14439a89382SEsther Brunner  function subscript_close(){}
14539a89382SEsther Brunner
14639a89382SEsther Brunner  function superscript_open(){}
14739a89382SEsther Brunner  function superscript_close(){}
14839a89382SEsther Brunner
14939a89382SEsther Brunner  function deleted_open(){}
15039a89382SEsther Brunner  function deleted_close(){}
15139a89382SEsther Brunner
15239a89382SEsther Brunner  /**
15339a89382SEsther Brunner   * Callback for footnote start syntax
15439a89382SEsther Brunner   *
15539a89382SEsther Brunner   * All following content will go to the footnote instead of
15639a89382SEsther Brunner   * the document. To achieve this the previous rendered content
15739a89382SEsther Brunner   * is moved to $store and $doc is cleared
15839a89382SEsther Brunner   *
15939a89382SEsther Brunner   * @author Andreas Gohr <andi@splitbrain.org>
16039a89382SEsther Brunner   */
16139a89382SEsther Brunner  function footnote_open() {
16239a89382SEsther Brunner    if ($this->capture){
16339a89382SEsther Brunner      // move current content to store and record footnote
16439a89382SEsther Brunner      $this->store = $this->doc;
16539a89382SEsther Brunner      $this->doc   = '';
16639a89382SEsther Brunner    }
16739a89382SEsther Brunner  }
16839a89382SEsther Brunner
16939a89382SEsther Brunner  /**
17039a89382SEsther Brunner   * Callback for footnote end syntax
17139a89382SEsther Brunner   *
17239a89382SEsther Brunner   * All rendered content is moved to the $footnotes array and the old
17339a89382SEsther Brunner   * content is restored from $store again
17439a89382SEsther Brunner   *
17539a89382SEsther Brunner   * @author Andreas Gohr
17639a89382SEsther Brunner   */
17739a89382SEsther Brunner  function footnote_close() {
17839a89382SEsther Brunner    if ($this->capture){
17939a89382SEsther Brunner      // restore old content
18039a89382SEsther Brunner      $this->doc = $this->store;
18139a89382SEsther Brunner      $this->store = '';
18239a89382SEsther Brunner    }
18339a89382SEsther Brunner  }
18439a89382SEsther Brunner
18539a89382SEsther Brunner  function listu_open(){
18639a89382SEsther Brunner    if ($this->capture) $this->doc .= DOKU_LF;
18739a89382SEsther Brunner  }
18839a89382SEsther Brunner
18939a89382SEsther Brunner  function listu_close(){
19039a89382SEsther Brunner    if ($this->capture && (strlen($this->doc) > 250)) $this->capture = false;
19139a89382SEsther Brunner  }
19239a89382SEsther Brunner
19339a89382SEsther Brunner  function listo_open(){
19439a89382SEsther Brunner    if ($this->capture) $this->doc .= DOKU_LF;
19539a89382SEsther Brunner  }
19639a89382SEsther Brunner
19739a89382SEsther Brunner  function listo_close(){
19839a89382SEsther Brunner    if ($this->capture && (strlen($this->doc) > 250)) $this->capture = false;
19939a89382SEsther Brunner  }
20039a89382SEsther Brunner
20139a89382SEsther Brunner  function listitem_open($level){
20239a89382SEsther Brunner    if ($this->capture) $this->doc .= str_repeat(DOKU_TAB, $level).'* ';
20339a89382SEsther Brunner  }
20439a89382SEsther Brunner
20539a89382SEsther Brunner  function listitem_close(){
20639a89382SEsther Brunner    if ($this->capture) $this->doc .= DOKU_LF;
20739a89382SEsther Brunner  }
20839a89382SEsther Brunner
20939a89382SEsther Brunner  function listcontent_open(){}
21039a89382SEsther Brunner  function listcontent_close(){}
21139a89382SEsther Brunner
21239a89382SEsther Brunner  function unformatted($text){
21339a89382SEsther Brunner    if ($this->capture) $this->doc .= $text;
21439a89382SEsther Brunner  }
21539a89382SEsther Brunner
21639a89382SEsther Brunner  function php($text){}
21739a89382SEsther Brunner
21807f89c3cSAnika Henke  function phpblock($text){}
21907f89c3cSAnika Henke
22039a89382SEsther Brunner  function html($text){}
22139a89382SEsther Brunner
22207f89c3cSAnika Henke  function htmlblock($text){}
22307f89c3cSAnika Henke
22439a89382SEsther Brunner  function preformatted($text){
22539a89382SEsther Brunner    if ($this->capture) $this->doc .= $text;
22639a89382SEsther Brunner  }
22739a89382SEsther Brunner
22839a89382SEsther Brunner  function file($text){
22939a89382SEsther Brunner    if ($this->capture){
23039a89382SEsther Brunner      $this->doc .= DOKU_LF.$text;
23139a89382SEsther Brunner      if (strlen($this->doc) > 250) $this->capture = false;
23239a89382SEsther Brunner      else $this->doc .= DOKU_LF;
23339a89382SEsther Brunner    }
23439a89382SEsther Brunner  }
23539a89382SEsther Brunner
23639a89382SEsther Brunner  function quote_open(){
23771b40da2SAnika Henke    if ($this->capture) $this->doc .= DOKU_LF.DOKU_TAB.'"';
23839a89382SEsther Brunner  }
23939a89382SEsther Brunner
24039a89382SEsther Brunner  function quote_close(){
24139a89382SEsther Brunner    if ($this->capture){
24271b40da2SAnika Henke      $this->doc .= '"';
24339a89382SEsther Brunner      if (strlen($this->doc) > 250) $this->capture = false;
24439a89382SEsther Brunner      else $this->doc .= DOKU_LF;
24539a89382SEsther Brunner    }
24639a89382SEsther Brunner  }
24739a89382SEsther Brunner
24839a89382SEsther Brunner  function code($text, $language = NULL){
24939a89382SEsther Brunner    if ($this->capture){
25039a89382SEsther Brunner      $this->doc .= DOKU_LF.$text;
25139a89382SEsther Brunner      if (strlen($this->doc) > 250) $this->capture = false;
25239a89382SEsther Brunner      else $this->doc .= DOKU_LF;
25339a89382SEsther Brunner    }
25439a89382SEsther Brunner  }
25539a89382SEsther Brunner
25639a89382SEsther Brunner  function acronym($acronym){
25739a89382SEsther Brunner    if ($this->capture) $this->doc .= $acronym;
25839a89382SEsther Brunner  }
25939a89382SEsther Brunner
26039a89382SEsther Brunner  function smiley($smiley){
26139a89382SEsther Brunner    if ($this->capture) $this->doc .= $smiley;
26239a89382SEsther Brunner  }
26339a89382SEsther Brunner
26439a89382SEsther Brunner  function entity($entity){
26539a89382SEsther Brunner    if ($this->capture) $this->doc .= $entity;
26639a89382SEsther Brunner  }
26739a89382SEsther Brunner
26839a89382SEsther Brunner  function multiplyentity($x, $y){
26939a89382SEsther Brunner    if ($this->capture) $this->doc .= $x.'×'.$y;
27039a89382SEsther Brunner  }
27139a89382SEsther Brunner
27239a89382SEsther Brunner  function singlequoteopening(){
27371b40da2SAnika Henke    global $lang;
27471b40da2SAnika Henke    if ($this->capture) $this->doc .= $lang['singlequoteopening'];
27539a89382SEsther Brunner  }
27639a89382SEsther Brunner
27739a89382SEsther Brunner  function singlequoteclosing(){
27871b40da2SAnika Henke    global $lang;
27971b40da2SAnika Henke    if ($this->capture) $this->doc .= $lang['singlequoteclosing'];
28039a89382SEsther Brunner  }
28139a89382SEsther Brunner
28257d757d1SAndreas Gohr  function apostrophe() {
28357d757d1SAndreas Gohr    global $lang;
284b58f5d31STom N Harris    if ($this->capture) $this->doc .= $lang['apostrophe'];
28557d757d1SAndreas Gohr  }
28657d757d1SAndreas Gohr
28739a89382SEsther Brunner  function doublequoteopening(){
28871b40da2SAnika Henke    global $lang;
28971b40da2SAnika Henke    if ($this->capture) $this->doc .= $lang['doublequoteopening'];
29039a89382SEsther Brunner  }
29139a89382SEsther Brunner
29239a89382SEsther Brunner  function doublequoteclosing(){
29371b40da2SAnika Henke    global $lang;
29471b40da2SAnika Henke    if ($this->capture) $this->doc .= $lang['doublequoteclosing'];
29539a89382SEsther Brunner  }
29639a89382SEsther Brunner
29739a89382SEsther Brunner  function camelcaselink($link) {
29839a89382SEsther Brunner    $this->internallink($link, $link);
29939a89382SEsther Brunner  }
30039a89382SEsther Brunner
30139a89382SEsther Brunner  function locallink($hash, $name = NULL){}
30239a89382SEsther Brunner
30339a89382SEsther Brunner  /**
30439a89382SEsther Brunner   * keep track of internal links in $this->meta['relation']['references']
30539a89382SEsther Brunner   */
30639a89382SEsther Brunner  function internallink($id, $name = NULL){
30739a89382SEsther Brunner    global $ID;
30839a89382SEsther Brunner
309aa5a2937SAndreas Gohr    if(is_array($name))
310aa5a2937SAndreas Gohr        $this->_firstimage($name['src']);
311aa5a2937SAndreas Gohr
31239a89382SEsther Brunner    $default = $this->_simpleTitle($id);
31339a89382SEsther Brunner
31439a89382SEsther Brunner    // first resolve and clean up the $id
31539a89382SEsther Brunner    resolve_pageid(getNS($ID), $id, $exists);
3163be6e394Schris    list($page, $hash) = split('#', $id, 2);
31739a89382SEsther Brunner
31839a89382SEsther Brunner    // set metadata
3193be6e394Schris    $this->meta['relation']['references'][$page] = $exists;
32039a89382SEsther Brunner    // $data = array('relation' => array('isreferencedby' => array($ID => true)));
32139a89382SEsther Brunner    // p_set_metadata($id, $data);
32239a89382SEsther Brunner
32339a89382SEsther Brunner    // add link title to summary
32439a89382SEsther Brunner    if ($this->capture){
32539a89382SEsther Brunner      $name = $this->_getLinkTitle($name, $default, $id);
32639a89382SEsther Brunner      $this->doc .= $name;
32739a89382SEsther Brunner    }
32839a89382SEsther Brunner  }
32939a89382SEsther Brunner
33039a89382SEsther Brunner  function externallink($url, $name = NULL){
331aa5a2937SAndreas Gohr    if(is_array($name))
332aa5a2937SAndreas Gohr        $this->_firstimage($name['src']);
333aa5a2937SAndreas Gohr
33439a89382SEsther Brunner    if ($this->capture){
33539a89382SEsther Brunner      if ($name) $this->doc .= $name;
33639a89382SEsther Brunner      else $this->doc .= '<'.$url.'>';
33739a89382SEsther Brunner    }
33839a89382SEsther Brunner  }
33939a89382SEsther Brunner
34039a89382SEsther Brunner  function interwikilink($match, $name = NULL, $wikiName, $wikiUri){
341aa5a2937SAndreas Gohr    if(is_array($name))
342aa5a2937SAndreas Gohr        $this->_firstimage($name['src']);
343aa5a2937SAndreas Gohr
34439a89382SEsther Brunner    if ($this->capture){
34539a89382SEsther Brunner      list($wikiUri, $hash) = explode('#', $wikiUri, 2);
34639a89382SEsther Brunner      $name = $this->_getLinkTitle($name, $wikiName.'>'.$wikiUri);
34739a89382SEsther Brunner      $this->doc .= $name;
34839a89382SEsther Brunner    }
34939a89382SEsther Brunner  }
35039a89382SEsther Brunner
35139a89382SEsther Brunner  function windowssharelink($url, $name = NULL){
352aa5a2937SAndreas Gohr    if(is_array($name))
353aa5a2937SAndreas Gohr        $this->_firstimage($name['src']);
354aa5a2937SAndreas Gohr
35539a89382SEsther Brunner    if ($this->capture){
35639a89382SEsther Brunner      if ($name) $this->doc .= $name;
35739a89382SEsther Brunner      else $this->doc .= '<'.$url.'>';
35839a89382SEsther Brunner    }
35939a89382SEsther Brunner  }
36039a89382SEsther Brunner
36139a89382SEsther Brunner  function emaillink($address, $name = NULL){
362aa5a2937SAndreas Gohr    if(is_array($name))
363aa5a2937SAndreas Gohr        $this->_firstimage($name['src']);
364aa5a2937SAndreas Gohr
36539a89382SEsther Brunner    if ($this->capture){
36639a89382SEsther Brunner      if ($name) $this->doc .= $name;
36739a89382SEsther Brunner      else $this->doc .= '<'.$address.'>';
36839a89382SEsther Brunner    }
36939a89382SEsther Brunner  }
37039a89382SEsther Brunner
37139a89382SEsther Brunner  function internalmedia($src, $title=NULL, $align=NULL, $width=NULL,
37239a89382SEsther Brunner                         $height=NULL, $cache=NULL, $linking=NULL){
37339a89382SEsther Brunner    if ($this->capture && $title) $this->doc .= '['.$title.']';
374aa5a2937SAndreas Gohr    $this->_firstimage($src);
37539a89382SEsther Brunner  }
37639a89382SEsther Brunner
37739a89382SEsther Brunner  function externalmedia($src, $title=NULL, $align=NULL, $width=NULL,
37839a89382SEsther Brunner                         $height=NULL, $cache=NULL, $linking=NULL){
37939a89382SEsther Brunner    if ($this->capture && $title) $this->doc .= '['.$title.']';
380aa5a2937SAndreas Gohr    $this->_firstimage($src);
38139a89382SEsther Brunner  }
38239a89382SEsther Brunner
383ce6b63d9Schris  function rss($url,$params) {
384ce6b63d9Schris    $this->meta['relation']['haspart'][$url] = true;
38564e9144aSchris
38664e9144aSchris    $this->meta['date']['valid']['age'] =
38764e9144aSchris            isset($this->meta['date']['valid']['age']) ?
38864e9144aSchris                min($this->meta['date']['valid']['age'],$params['refresh']) :
38964e9144aSchris                $params['refresh'];
390ce6b63d9Schris  }
39139a89382SEsther Brunner
39239a89382SEsther Brunner  function table_open($maxcols = NULL, $numrows = NULL){}
39339a89382SEsther Brunner  function table_close(){}
39439a89382SEsther Brunner
39539a89382SEsther Brunner  function tablerow_open(){}
39639a89382SEsther Brunner  function tablerow_close(){}
39739a89382SEsther Brunner
39839a89382SEsther Brunner  function tableheader_open($colspan = 1, $align = NULL){}
39939a89382SEsther Brunner  function tableheader_close(){}
40039a89382SEsther Brunner
40139a89382SEsther Brunner  function tablecell_open($colspan = 1, $align = NULL){}
40239a89382SEsther Brunner  function tablecell_close(){}
40339a89382SEsther Brunner
40439a89382SEsther Brunner  //----------------------------------------------------------
40539a89382SEsther Brunner  // Utils
40639a89382SEsther Brunner
40739a89382SEsther Brunner  /**
40839a89382SEsther Brunner   * Removes any Namespace from the given name but keeps
40939a89382SEsther Brunner   * casing and special chars
41039a89382SEsther Brunner   *
41139a89382SEsther Brunner   * @author Andreas Gohr <andi@splitbrain.org>
41239a89382SEsther Brunner   */
41339a89382SEsther Brunner  function _simpleTitle($name){
41439a89382SEsther Brunner    global $conf;
41539a89382SEsther Brunner
4169bee852eSAndreas Gohr    if(is_array($name)) return '';
4179bee852eSAndreas Gohr
41839a89382SEsther Brunner    if($conf['useslash']){
41939a89382SEsther Brunner        $nssep = '[:;/]';
42039a89382SEsther Brunner    }else{
42139a89382SEsther Brunner        $nssep = '[:;]';
42239a89382SEsther Brunner    }
42339a89382SEsther Brunner    $name = preg_replace('!.*'.$nssep.'!','',$name);
4243be6e394Schris    //if there is a hash we use the anchor name only
42539a89382SEsther Brunner    $name = preg_replace('!.*#!','',$name);
42639a89382SEsther Brunner    return $name;
42739a89382SEsther Brunner  }
42839a89382SEsther Brunner
42939a89382SEsther Brunner  /**
43039a89382SEsther Brunner   * Creates a linkid from a headline
43139a89382SEsther Brunner   *
43239a89382SEsther Brunner   * @param string  $title   The headline title
43339a89382SEsther Brunner   * @param boolean $create  Create a new unique ID?
43439a89382SEsther Brunner   * @author Andreas Gohr <andi@splitbrain.org>
43539a89382SEsther Brunner   */
43639a89382SEsther Brunner  function _headerToLink($title, $create=false) {
4375fe80182Schris    $title = str_replace(':','',cleanID($title));
43839a89382SEsther Brunner    $title = ltrim($title,'0123456789._-');
43939a89382SEsther Brunner    if(empty($title)) $title='section';
44039a89382SEsther Brunner
44139a89382SEsther Brunner    if($create){
44239a89382SEsther Brunner      // make sure tiles are unique
44339a89382SEsther Brunner      $num = '';
44439a89382SEsther Brunner      while(in_array($title.$num,$this->headers)){
44539a89382SEsther Brunner        ($num) ? $num++ : $num = 1;
44639a89382SEsther Brunner      }
44739a89382SEsther Brunner      $title = $title.$num;
44839a89382SEsther Brunner      $this->headers[] = $title;
44939a89382SEsther Brunner    }
45039a89382SEsther Brunner
45139a89382SEsther Brunner    return $title;
45239a89382SEsther Brunner  }
45339a89382SEsther Brunner
45439a89382SEsther Brunner  /**
45539a89382SEsther Brunner   * Construct a title and handle images in titles
45639a89382SEsther Brunner   *
45739a89382SEsther Brunner   * @author Harry Fuecks <hfuecks@gmail.com>
45839a89382SEsther Brunner   */
45939a89382SEsther Brunner  function _getLinkTitle($title, $default, $id=NULL) {
46039a89382SEsther Brunner    global $conf;
46139a89382SEsther Brunner
46244881bd0Shenning.noren    $isImage = false;
46339a89382SEsther Brunner    if (is_null($title)){
464fe9ec250SChris Smith      if (useHeading('content') && $id){
465fc18c0fbSchris        $heading = p_get_first_heading($id,false);
46639a89382SEsther Brunner        if ($heading) return $heading;
46739a89382SEsther Brunner      }
46839a89382SEsther Brunner      return $default;
46939a89382SEsther Brunner    } else if (is_string($title)){
47039a89382SEsther Brunner      return $title;
47139a89382SEsther Brunner    } else if (is_array($title)){
472aa5a2937SAndreas Gohr      return '['.$title['title'].']';
47339a89382SEsther Brunner    }
47439a89382SEsther Brunner  }
47539a89382SEsther Brunner
476aa5a2937SAndreas Gohr  function _firstimage($src){
477aa5a2937SAndreas Gohr    if($this->firstimage) return;
478aa5a2937SAndreas Gohr    global $ID;
479aa5a2937SAndreas Gohr
480aa5a2937SAndreas Gohr    list($src,$hash) = explode('#',$src,2);
481aa5a2937SAndreas Gohr    if(!preg_match('/^https?:\/\//i',$src)){
482aa5a2937SAndreas Gohr        resolve_mediaid(getNS($ID),$src, $exists);
483aa5a2937SAndreas Gohr    }
484aa5a2937SAndreas Gohr    if(preg_match('/.(jpe?g|gif|png)$/i',$src)){
485aa5a2937SAndreas Gohr        $this->firstimage = $src;
486aa5a2937SAndreas Gohr    }
487aa5a2937SAndreas Gohr  }
48839a89382SEsther Brunner}
48939a89382SEsther Brunner
49039a89382SEsther Brunner//Setup VIM: ex: et ts=4 enc=utf-8 :
491