1: <?php
  2: 
  3: require_once 'Text/Wiki/Render/Xhtml/Wikilink.php';
  4: 
  5:   6:   7: 
  8: class Text_Wiki_Render_Xhtml_Wikilink2 extends Text_Wiki_Render_Xhtml_Wikilink
  9: {
 10:      11:  12:  13:  14:  15:  16:  17:  18:  19: 
 20:     public function token($options)
 21:     {
 22:         
 23:         extract($options);
 24: 
 25:         
 26:         
 27:         
 28:         
 29:         if (isset($this->conf['exists_callback'])) {
 30:             $callback =& $this->conf['exists_callback'];
 31:         } else {
 32:             $callback = false;
 33:         }
 34: 
 35:         if ($callback) {
 36:             
 37:             $exists = call_user_func($callback, $page);
 38:         } else {
 39:             
 40:             $list = $this->getConf('pages');
 41:             if (is_array($list)) {
 42:                 
 43:                 $exists = in_array($page, $list);
 44:             } else {
 45:                 
 46:                 $exists = true;
 47:             }
 48:         }
 49: 
 50:         $anchor = $this->urlEncode(substr($anchor, 1));
 51:         if (strlen($anchor)) {
 52:             $anchor = '#' . $anchor;
 53:         }
 54: 
 55:         
 56:         if ($exists) {
 57:             $href = sprintf(preg_replace('/%(?!s)/', '%%', $this->getConf('view_url')), $GLOBALS['conf']['urls']['pretty'] == 'rewrite' ? htmlspecialchars($page) : $this->urlEncode($page)) . $anchor;
 58: 
 59:             
 60:             $css = ' class="'.$this->textEncode($this->getConf('css')).'"';
 61: 
 62:             $start = '<a'.$css.' href="'.$this->textEncode($href).'">';
 63:             $end = '</a>';
 64:         } else {
 65:             $new_url = $this->getConf('new_url');
 66:             if (!$new_url) {
 67:                 return $this->textEncode($text);
 68:             }
 69: 
 70:             $href = sprintf(preg_replace('/%(?!s)/', '%%', $new_url), $GLOBALS['conf']['urls']['pretty'] == 'rewrite' ? htmlspecialchars($page) : $this->urlEncode($page));
 71: 
 72:             
 73:             $css = ' class="'.$this->textEncode($this->getConf('css_new')).'"';
 74:             $new = $this->getConf('new_text');
 75: 
 76:             
 77:             $pos = $this->getConf('new_text_pos');
 78:             if (! $pos || ! $new) {
 79:                 
 80: 
 81:                 $start = '<a'.$css.' href="'.$this->textEncode($href).'">';
 82:                 $end = '</a>';
 83:             } elseif ($pos == 'before') {
 84:                 
 85:                 $start = '<a'.$css.' href="'.$this->textEncode($href).'">'.$this->textEncode($new).'</a>';
 86:                 $end = '';
 87:             } else {
 88:                 
 89:                 $start = '';
 90:                 $end = '<a'.$css.' href="'.$this->textEncode($href).'">'.$this->textEncode($new).'</a>';
 91:             }
 92:         }
 93:         if (!strlen($text)) {
 94:             $start .= $this->textEncode($page);
 95:         }
 96:         if (isset($type)) {
 97:             switch ($type) {
 98:             case 'start':
 99:                 $output = $start;
100:                 break;
101:             case 'end':
102:                 $output = $end;
103:                 break;
104:             }
105:         } else {
106:             $output = $start.$this->textEncode($text).$end;
107:         }
108:         return $output;
109:     }
110: }
111: