Changeset 43c40f0 in github


Ignore:
Timestamp:
Feb 15, 2012 8:24:04 AM (15 months ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.8
Children:
b138a9b
Parents:
3ed9e80
Message:
  • Don't list mailto: and anchor links
  • List only unique URLs
File:
1 edited

Legend:

Unmodified
Added
Removed
  • program/lib/html2text.php

    rf359950 r43c40f0  
    318318     *  Contains URL addresses from links to be rendered in plain text. 
    319319     * 
    320      *  @var string $_link_list 
     320     *  @var array $_link_list 
    321321     *  @access private 
    322322     *  @see _build_link_list() 
    323323     */ 
    324     var $_link_list = ''; 
    325  
    326     /** 
    327      *  Number of valid links detected in the text, used for plain text 
    328      *  display (rendered similar to footnotes). 
    329      * 
    330      *  @var integer $_link_count 
    331      *  @access private 
    332      *  @see _build_link_list() 
    333      */ 
    334     var $_link_count = 0; 
     324    var $_link_list = array(); 
    335325 
    336326    /** 
     
    473463    { 
    474464        // Variables used for building the link list 
    475         $this->_link_count = 0; 
    476         $this->_link_list = ''; 
     465        $this->_link_list = array(); 
    477466 
    478467        $text = trim(stripslashes($this->html)); 
     
    482471 
    483472        // Add link list 
    484         if ( !empty($this->_link_list) ) { 
    485             $text .= "\n\nLinks:\n------\n" . $this->_link_list; 
     473        if (!empty($this->_link_list)) { 
     474            $text .= "\n\nLinks:\n------\n"; 
     475            foreach ($this->_link_list as $idx => $url) { 
     476                $text .= '[' . ($idx+1) . '] ' . $url . "\n"; 
     477            } 
    486478        } 
    487479 
     
    564556    function _build_link_list( $link, $display ) 
    565557    { 
    566             if ( !$this->_do_links ) 
     558            if (!$this->_do_links || empty($link)) { 
    567559                return $display; 
    568  
    569             if ( preg_match('!^(https?://|mailto:)!', $link) ) { 
    570             $this->_link_count++; 
    571             $this->_link_list .= '[' . $this->_link_count . "] $link\n"; 
    572             $additional = ' [' . $this->_link_count . ']'; 
    573             } elseif ( substr($link, 0, 11) == 'javascript:' ) { 
    574                     // Don't count the link; ignore it 
    575                     $additional = ''; 
    576                 // what about href="#anchor" ? 
    577         } else { 
    578             $this->_link_count++; 
    579             $this->_link_list .= '[' . $this->_link_count . '] ' . $this->url; 
    580             if ( substr($link, 0, 1) != '/' ) { 
    581                 $this->_link_list .= '/'; 
     560            } 
     561 
     562        // Ignored link types 
     563            if (preg_match('!^(javascript|mailto|#):!i', $link)) { 
     564                    return $display; 
     565        } 
     566 
     567            if (preg_match('!^(https?://)!i', $link)) { 
     568            $url = $link; 
     569        } 
     570        else { 
     571            $url = $this->url; 
     572            if (substr($link, 0, 1) != '/') { 
     573                $url .= '/'; 
    582574            } 
    583             $this->_link_list .= "$link\n"; 
    584             $additional = ' [' . $this->_link_count . ']'; 
    585         } 
    586  
    587         return $display . $additional; 
     575            $url .= "$link"; 
     576        } 
     577 
     578        if (($index = array_search($url, $this->_link_list)) === false) { 
     579            $this->_link_list[] = $url; 
     580            $index = count($this->_link_list); 
     581        } 
     582 
     583        return $display . ' [' . ($index+1) . ']'; 
    588584    } 
    589585 
Note: See TracChangeset for help on using the changeset viewer.