예제 #1
0
 /**
  * The final string should be an URL
  *
  * @param string $rawvalue
  * @return int|string|void
  */
 public function validate($rawvalue)
 {
     $rawvalue = parent::validate($rawvalue);
     $url = $this->buildURL($rawvalue);
     $schemes = getSchemes();
     $regex = '^(' . join('|', $schemes) . '):\\/\\/.+';
     if (!preg_match("/{$regex}/i", $url)) {
         throw new ValidationException('Url invalid', $url);
     }
     return $rawvalue;
 }
예제 #2
0
파일: xhtml.php 프로젝트: sawachan/dokuwiki
 /**
  * Render an external link
  *
  * @param string       $url        full URL with scheme
  * @param string|array $name       name for the link, array for media file
  * @param bool         $returnonly whether to return html or write to doc attribute
  */
 function externallink($url, $name = null, $returnonly = false)
 {
     global $conf;
     $name = $this->_getLinkTitle($name, $url, $isImage);
     // url might be an attack vector, only allow registered protocols
     if (is_null($this->schemes)) {
         $this->schemes = getSchemes();
     }
     list($scheme) = explode('://', $url);
     $scheme = strtolower($scheme);
     if (!in_array($scheme, $this->schemes)) {
         $url = '';
     }
     // is there still an URL?
     if (!$url) {
         $this->doc .= $name;
         return;
     }
     // set class
     if (!$isImage) {
         $class = 'urlextern';
     } else {
         $class = 'media';
     }
     //prepare for formating
     $link = array();
     $link['target'] = $conf['target']['extern'];
     $link['style'] = '';
     $link['pre'] = '';
     $link['suf'] = '';
     $link['more'] = '';
     $link['class'] = $class;
     $link['url'] = $url;
     $link['name'] = $name;
     $link['title'] = $this->_xmlEntities($url);
     if ($conf['relnofollow']) {
         $link['more'] .= ' rel="nofollow"';
     }
     //output formatted
     if ($returnonly) {
         return $this->_formatLink($link);
     } else {
         $this->doc .= $this->_formatLink($link);
     }
 }
예제 #3
0
 function preConnect()
 {
     if (count($this->patterns)) {
         return;
     }
     $ltrs = '\\w';
     $gunk = '/\\#~:.?+=&%@!\\-\\[\\]';
     $punc = '.:?\\-;,';
     $host = $ltrs . $punc;
     $any = $ltrs . $gunk . $punc;
     $this->schemes = getSchemes();
     foreach ($this->schemes as $scheme) {
         $this->patterns[] = '\\b(?i)' . $scheme . '(?-i)://[' . $any . ']+?(?=[' . $punc . ']*[^' . $any . '])';
     }
     $this->patterns[] = '\\b(?i)www?(?-i)\\.[' . $host . ']+?\\.[' . $host . ']+?[' . $any . ']+?(?=[' . $punc . ']*[^' . $any . '])';
     $this->patterns[] = '\\b(?i)ftp?(?-i)\\.[' . $host . ']+?\\.[' . $host . ']+?[' . $any . ']+?(?=[' . $punc . ']*[^' . $any . '])';
 }
예제 #4
0
 /**
  * Return XHTML formated data, depending on column type
  *
  * @param array         $column
  * @param string        $value
  * @param Doku_Renderer $R
  * @return string
  */
 function _formatDataOld($column, $value, Doku_Renderer $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));
                 $titleId = $id;
                 if (!$title) {
                     $title = $id;
                 } else {
                     $title = hsc($title);
                 }
                 if ($conf['mailguard'] == 'visible') {
                     $id = rawurlencode($id);
                 }
                 $outs[] = '<a href="mailto:' . $id . '" class="mail" title="' . $titleId . '">' . $title . '</a>';
                 break;
             case 'url':
                 $val = $this->_addPrePostFixes($column['type'], $val);
                 $url = $val;
                 $schemes = getSchemes();
                 list($scheme) = explode('://', $url);
                 if (!in_array($scheme, $schemes)) {
                     $url = '';
                 }
                 // is there still an URL?
                 if (!$url) {
                     $outs[] = $val;
                 } else {
                     $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'], '');
                 }
                 $params = buildURLparams($this->_getTagUrlparam($column, $val));
                 $url = str_replace('/', ':', cleanID($target)) . '?' . $params;
                 $outs[] = $R->internallink($url, hsc($val), true);
                 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);
 }