Show
Ignore:
Timestamp:
10/18/08 19:19:22 (3 months ago)
Author:
dom
Message:

Correctly validate web site URLs during edit and display,
and truncate URLs that are too long (fixes #21)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/OpenGuides/Template.pm

    r1105 r1231  
    1313use Template; 
    1414use URI::Escape; 
     15use Data::Validate::URI qw( is_web_uri ); 
    1516 
    1617=head1 NAME 
     
    348349    } @loclist; 
    349350 
    350     # The 'website' attribute might contain a URL so we wiki-format it here 
    351     # rather than just CGI::escapeHTMLing it all in the template. 
    352351    my $website = $args{metadata} ? $metadata{website}[0] 
    353352                                  : $q->param("website"); 
    354353    my $formatted_website_text = ""; 
    355     if ( $website && $website ne "http://" ) { 
    356         $formatted_website_text = $class->format_website_text( 
    357             formatter => $formatter, 
    358             text      => $website 
    359         ); 
     354    if ( $website && $website ne "http://" && is_web_uri( $website ) ) { 
     355        my $trunc_website = substr( $website, 0, $config->website_link_max_chars ); 
     356        unless ($website eq $trunc_website ) { 
     357            $trunc_website .= '...'; 
     358        } 
     359        $formatted_website_text = '<a href="' . $website . '">' . $trunc_website . '</a>'; 
    360360    } 
    361361 
     
    583583} 
    584584 
    585 sub format_website_text { 
    586     my ($class, %args) = @_; 
    587     my ($formatter, $text) = @args{ qw( formatter text ) }; 
    588     my $formatted = $formatter->format($text); 
    589  
    590     # Strip out paragraph markers put in by formatter since we want this 
    591     # to be a single string to put in a <ul>. 
    592     $formatted =~ s/<p>//g; 
    593     $formatted =~ s/<\/p>//g; 
    594  
    595     return $formatted; 
    596 } 
    597  
    598  
    599585=back 
    600586 
     
    605591=head1 COPYRIGHT 
    606592 
    607   Copyright (C) 2003-2007 The OpenGuides Project.  All Rights Reserved. 
     593  Copyright (C) 2003-2008 The OpenGuides Project.  All Rights Reserved. 
    608594 
    609595This module is free software; you can redistribute it and/or modify it