示例#1
0
 protected function convertToLink($href, $label, $varspace = array())
 {
     $href = trim($href);
     if ($href === '') {
         return $label;
     }
     if (is_array($varspace) && count($varspace)) {
         $href = $this->replaceMarkup($href, $varspace);
     }
     if (strpos($href, '://') !== false) {
         // embed external link in header
         // externallink() is adding to renderer->doc() ...
         // --> remove from doc afterwards, thus store its length now
         $length = strlen($this->renderer->doc);
         $this->renderer->externallink($href, $label);
         // --> now extract rendered link from doc
         $label = substr($this->renderer->doc, $length);
         $this->renderer->doc = substr_replace($this->renderer->doc, '', $length);
     } else {
         // embed internal link in header
         resolve_pageid(getNS(self::getPageID()), $href, $exists);
         $label = $this->renderer->internallink($href, $label, NULL, true);
     }
     return $label;
 }
示例#2
0
/**
 * Convenience function to quickly build a wikilink
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function html_wikilink($id, $name = NULL, $search = '')
{
    static $xhtml_renderer = NULL;
    if (is_null($xhtml_renderer)) {
        require_once DOKU_INC . 'inc/parser/xhtml.php';
        $xhtml_renderer = new Doku_Renderer_xhtml();
    }
    return $xhtml_renderer->internallink($id, $name, $search, true, 'navigation');
}
示例#3
0
 function internallink($id, $name = null, $search = null, $returnonly = false, $linktype = 'content')
 {
     $name = trim($name);
     if (!$name) {
         $id = trim($id);
         if (preg_match('/(.*?\\?)$/', $id, $matches)) {
             $name = $matches[1];
         }
     }
     parent::internallink($id, $name, $search, $returnonly, $linktype);
 }
示例#4
0
 /**
  *  Produced by syntax like [[?do=index|my caption]]
  */
 function test_empty_internallink_index_with_caption()
 {
     $page = 'my:space';
     $caption = 'my caption';
     global $ID;
     $ID = $page;
     global $conf;
     $conf['basedir'] = '/';
     $conf['useheading'] = 0;
     $conf['userewrite'] = 0;
     $conf['useslash'] = 0;
     $conf['canonical'] = 0;
     $p = new Doku_Renderer_xhtml();
     $p->internallink('?do=index', $caption);
     if (page_exists($page)) {
         $class = 'wikilink1';
         $rel = '';
     } else {
         $class = 'wikilink2';
         $rel = ' rel="nofollow"';
     }
     $expect = '<span class="curid"><a href="/./doku.php?id=' . $page . '&amp;do=index" class="' . $class . '" title="' . $page . '"' . $rel . '>' . $caption . '</a></span>';
     $this->assertEqual($p->doc, $expect);
 }
 /**
  * Return XHTML formated data, depending on column type
  *
  * @param array               $column
  * @param string              $value
  * @param Doku_Renderer_xhtml $R
  * @return string
  */
 function _formatData($column, $value, Doku_Renderer_xhtml $R)
 {
     global $conf;
     $vals = explode("\n", $value);
     $outs = array();
     //multivalued line from db result for pageid and wiki has only in first value the ID
     $storedID = '';
     foreach ($vals as $val) {
         $val = trim($val);
         if ($val == '') {
             continue;
         }
         $type = $column['type'];
         if (is_array($type)) {
             $type = $type['type'];
         }
         switch ($type) {
             case 'page':
                 $val = $this->_addPrePostFixes($column['type'], $val);
                 $val = $this->ensureAbsoluteId($val);
                 $outs[] = $R->internallink($val, null, null, true);
                 break;
             case 'title':
                 list($id, $title) = explode('|', $val, 2);
                 $id = $this->_addPrePostFixes($column['type'], $id);
                 $id = $this->ensureAbsoluteId($id);
                 $outs[] = $R->internallink($id, $title, null, true);
                 break;
             case 'pageid':
                 list($id, $title) = explode('|', $val, 2);
                 //use ID from first value of the multivalued line
                 if ($title == null) {
                     $title = $id;
                     if (!empty($storedID)) {
                         $id = $storedID;
                     }
                 } else {
                     $storedID = $id;
                 }
                 $id = $this->_addPrePostFixes($column['type'], $id);
                 $outs[] = $R->internallink($id, $title, null, true);
                 break;
             case 'nspage':
                 // no prefix/postfix here
                 $val = ':' . $column['key'] . ":{$val}";
                 $outs[] = $R->internallink($val, null, null, true);
                 break;
             case 'mail':
                 list($id, $title) = explode(' ', $val, 2);
                 $id = $this->_addPrePostFixes($column['type'], $id);
                 $id = obfuscate(hsc($id));
                 if (!$title) {
                     $title = $id;
                 } else {
                     $title = hsc($title);
                 }
                 if ($conf['mailguard'] == 'visible') {
                     $id = rawurlencode($id);
                 }
                 $outs[] = '<a href="mailto:' . $id . '" class="mail" title="' . $id . '">' . $title . '</a>';
                 break;
             case 'url':
                 $val = $this->_addPrePostFixes($column['type'], $val);
                 $outs[] = $this->external_link($val, false, 'urlextern');
                 break;
             case 'tag':
                 // per default use keyname as target page, but prefix on aliases
                 if (!is_array($column['type'])) {
                     $target = $column['key'] . ':';
                 } else {
                     $target = $this->_addPrePostFixes($column['type'], '');
                 }
                 $outs[] = '<a href="' . wl(str_replace('/', ':', cleanID($target)), $this->_getTagUrlparam($column, $val)) . '" title="' . sprintf($this->getLang('tagfilter'), hsc($val)) . '" class="wikilink1">' . hsc($val) . '</a>';
                 break;
             case 'timestamp':
                 $outs[] = dformat($val);
                 break;
             case 'wiki':
                 global $ID;
                 $oldid = $ID;
                 list($ID, $data) = explode('|', $val, 2);
                 //use ID from first value of the multivalued line
                 if ($data == null) {
                     $data = $ID;
                     $ID = $storedID;
                 } else {
                     $storedID = $ID;
                 }
                 $data = $this->_addPrePostFixes($column['type'], $data);
                 // Trim document_{start,end}, p_{open,close} from instructions
                 $allinstructions = p_get_instructions($data);
                 $wraps = 1;
                 if (isset($allinstructions[1]) && $allinstructions[1][0] == 'p_open') {
                     $wraps++;
                 }
                 $instructions = array_slice($allinstructions, $wraps, -$wraps);
                 $outs[] = p_render('xhtml', $instructions, $byref_ignore);
                 $ID = $oldid;
                 break;
             default:
                 $val = $this->_addPrePostFixes($column['type'], $val);
                 //type '_img' or '_img<width>'
                 if (substr($type, 0, 3) == 'img') {
                     $width = (int) substr($type, 3);
                     if (!$width) {
                         $width = $this->getConf('image_width');
                     }
                     list($mediaid, $title) = explode('|', $val, 2);
                     if ($title === null) {
                         $title = $column['key'] . ': ' . basename(str_replace(':', '/', $mediaid));
                     } else {
                         $title = trim($title);
                     }
                     if (media_isexternal($val)) {
                         $html = $R->externalmedia($mediaid, $title, $align = null, $width, $height = null, $cache = null, $linking = 'direct', true);
                     } else {
                         $html = $R->internalmedia($mediaid, $title, $align = null, $width, $height = null, $cache = null, $linking = 'direct', true);
                     }
                     if (strpos($html, 'mediafile') === false) {
                         $html = str_replace('href', 'rel="lightbox" href', $html);
                     }
                     $outs[] = $html;
                 } else {
                     $outs[] = hsc($val);
                 }
         }
     }
     return join(', ', $outs);
 }