Show
Ignore:
Timestamp:
09/06/06 10:58:06 (5 years ago)
Author:
benoitg
Message:

* Remove most inclusions of MainUI in classes. That completely
broke authentication (circular dependencies). Fixes 245.

Unfixes 242. Exceptions should not be caught in the context

they are thrown in. Else there no point in throwing exception in the
first place.
* HyperLink?.php: Fix bug where a link with identical text as
it's link would see the text replaced by the clickthrough-tracked
equivalent.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/wifidog/classes/HyperLink.php

    r1080 r1091  
    4747 * Load required classes 
    4848 */ 
    49 require_once('classes/User.php'); 
     49require_once ('classes/User.php'); 
    5050 
    5151/** 
     
    5757 */ 
    5858class HyperLink { 
     59    const pattern = '/(<a\s.*?HREF=[\'"]?)((?:http|https|ftp).*?)([\'"\s].*?>)/mi'; 
     60 
    5961    /** 
    6062     * Find http, https and ftp hyperlinks in a string 
     
    6567     
    6668     */ 
    67     public static function findHyperLinks(&$string) { 
    68         $pattern = '/<a\s.*?HREF=[\'"]?((?:http|https|ftp).*?)[\'"\s].*?>/mi'; 
    69         //pretty_print_r($pattern); 
     69    private static function findHyperLinks(& $string) { 
     70        //pretty_print_r(self::pattern); 
    7071        $matches = null; 
    71         $num_matches = preg_match_all($pattern, $string, $matches); 
    72         //pretty_print_r($matches); 
    73         return $matches[1]; 
     72        $num_matches = preg_match_all(self :: pattern, $string, $matches); 
     73 
     74        return $matches; 
    7475    } 
    7576 
    76 /** Get the  clickthrough-logged equivalent of a sincle URL (http, https or ftp) */ 
    77     public static function getClickThroughLink($hyperlink, Content &$content, $node, $user) { 
    78         $node?$node_id=urlencode($node->getId()):$node_id=null; 
    79         $user?$user_id=urlencode($user->getId()):$user_id=null; 
    80         return BASE_URL_PATH . "clickthrough.php?destination_url=" . urlencode($hyperlink) . "&content_id=".urlencode($content->getId())."&node_id={$node_id}&user_id={$user_id}"; 
     77    /** Get the  clickthrough-logged equivalent of a sincle URL (http, https or ftp) */ 
     78    private static function getClickThroughLink($hyperlink, Content & $content, $node, $user) { 
     79        $node ? $node_id = urlencode($node->getId()) : $node_id = null; 
     80        $user ? $user_id = urlencode($user->getId()) : $user_id = null; 
     81        return BASE_URL_PATH . "clickthrough.php?destination_url=" . urlencode($hyperlink) . "&content_id=" . urlencode($content->getId()) . "&node_id={$node_id}&user_id={$user_id}"; 
    8182    } 
    8283 
    83 /** Replace all hyperlinks in the source string with their clickthrough-logged equivalents */ 
    84     public static function replaceHyperLinks(&$string, Content &$content) { 
    85         $links = self :: findHyperLinks($string); 
    86         if(!empty($links)) 
    87         { 
    88             $node = Node::getCurrentNode(); 
    89         $user = User::getCurrentUser(); 
    90         foreach ($links as $link) { 
    91             $replacements[] = self :: getClickThroughLink($link, $content, $node, $user); 
    92         } 
    93         //pretty_print_r($replacements); 
    94         return str_replace($links, $replacements, $string); 
    95         } 
    96         else 
    97         { 
     84    /** Replace all hyperlinks in the source string with their clickthrough-logged equivalents */ 
     85    public static function replaceHyperLinks(& $string, Content & $content) { 
     86        $matches = self :: findHyperLinks($string); 
     87        //pretty_print_r($matches); 
     88        if (!empty ($matches[2])) { 
     89            $node = Node :: getCurrentNode(); 
     90            $user = User :: getCurrentUser(); 
     91            $i = 0; 
     92            foreach ($matches[2] as $link) { 
     93                $new_link = self :: getClickThroughLink($link, $content, $node, $user); 
     94                $replacements[] = $matches[1][$i] . $new_link . $matches[3][$i]; 
     95                $i++; 
     96            } 
     97            //pretty_print_r($replacements); 
     98            return str_replace($matches[0], $replacements, $string); 
     99        } else { 
    98100            return $string; 
    99101        }