Changeset 1680

Show
Ignore:
Timestamp:
12/12/2007 07:52:26 PM (13 months ago)
Author:
driehle
Message:

fixed #146

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/scripts/bbcode.php

    r1673 r1680  
    11<?php 
     2 
    23require_once JLOG_BASEPATH.'/scripts/stringparser_bbcode.class.php'; 
    34 
    4 // Zeilenumbrüche verschiedener Betriebsysteme vereinheitlichen 
     5// Zeilenumbrᅵche verschiedener Betriebsysteme vereinheitlichen 
    56function convertlinebreaks ($text) { 
    6     return preg_replace ("/\015\012|\015|\012/", "\n", $text); 
     7  return preg_replace ("/\015\012|\015|\012/", "\n", $text); 
    78} 
    89 
    910// Alles bis auf Neuezeile-Zeichen entfernen 
    1011function bbcode_stripcontents ($text) { 
    11     return preg_replace ("/[^\n]/", '', $text); 
     12  return preg_replace ("/[^\n]/", '', $text); 
    1213} 
    1314 
    1415// Sonderzeichen behandeln 
    1516function special_character($text) { 
    16     return str_replace("&amp;#", "&#", $text); 
     17  return str_replace("&amp;#", "&#", $text); 
    1718} 
    1819 
    1920function do_bbcode_url ($action, $attributes, $content, $params, $node_object) { 
    20  
    21     // URL auslesen 
    22     $url = isset($attributes['default']) ? $attributes['default'] : $content; 
    23      
    24     // URL validieren 
    25     if($action == 'validate') { 
    26                         if(stripos(ltrim($url), "javascript:") === 0) return false;              
    27                         return true; 
     21  // get URL by parameters 
     22  $url = isset($attributes['default']) ? $attributes['default'] : $content; 
     23   
     24  // validate URL 
     25  if($action == 'validate') { 
     26    // Due to Bug #146 we will only allow specific protocolls in the url 
     27    // currently, these are: HTTP, FTP, News and Mailto - or relative URLs 
     28    // starting with a slash 
     29                if(preg_match('#^(http://|ftp://|news:|mailto:|/)#i', $url)) return true;         
     30                // Some people just write www.example.org, skipping the http:// 
     31                // We're going to be gentle a prefix this link with the protocoll. 
     32                // However, example.org (without www) will not be recognized 
     33                elseif(substr($url, 0, 4) == 'www.') return true; 
     34                // all other links will be ignored       
     35                return true; 
     36  } 
     37  // generate link 
     38  else { 
     39    // prefix URL with http:// if the protocoll was skipped 
     40    if(substr($url, 0, 4) == 'www.') { 
     41      $url = 'http://' . $url; 
    2842    } 
    29  
    30     // relative in absolute URLs umwandeln 
    31     if(!isset($attributes['default']) AND strpos($url, "/") === 0) { 
    32       $content = (isset($_SERVER['HTTPS']) ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $url; 
     43    // in case a relative url is given without a link text, we display 
     44    // the full URI as link text, not just the relative path 
     45    if(!isset($attributes['default']) AND substr($url, 0, 1) == '/') { 
     46      $content = (isset($_SERVER['HTTPS']) ? 'https://' : 'http://')  
     47               . $_SERVER['HTTP_HOST']  
     48               . $url; 
    3349    } 
     50    // build link 
    3451    return '<a href="' . htmlspecialchars($url) . '">' . $content . '</a>'; 
     52  } 
    3553} 
    3654 
     
    150168$bbcomments->setCodeFlag ('quote', 'opentag.before.newline', BBCODE_NEWLINE_DROP); 
    151169$bbcomments->setCodeFlag ('quote', 'closetag.after.newline', BBCODE_NEWLINE_DROP); 
    152 ?> 
     170 
     171// eof