Changeset 406 for veekun/trunk/lib/Vee/Utils.pm
- Timestamp:
- 02/08/08 02:44:39 (2 years ago)
- Files:
-
- 1 modified
-
veekun/trunk/lib/Vee/Utils.pm (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
veekun/trunk/lib/Vee/Utils.pm
r283 r406 50 50 51 51 sub postrank { 52 my ($post ct) = @_;52 my ($post_count) = @_; 53 53 for my $rank ( 54 54 sort { $b <=> $a } 55 55 keys %{ Vee->config->{site}->{post_ranks} } 56 56 ) { 57 return Vee->config->{site}->{post_ranks}->{$rank} if $rank <= $post ct;57 return Vee->config->{site}->{post_ranks}->{$rank} if $rank <= $post_count; 58 58 } 59 59 return "ERRORZ0RZ"; … … 63 63 # XXX: decide the best way to do this, preferably a smooth log curve 64 64 sub post_width { 65 my ($post ct) = @_;66 return $post ct / 1000;65 my ($post_count) = @_; 66 return $post_count / 1000; 67 67 } 68 68 … … 109 109 } 110 110 111 # URL-validation regex 112 # Inferred from the W3's BNF: http://www.w3.org/Addressing/URL/5_BNF.html 113 # n.b.: Technically, the BNF says hostname parts (as delimited by dots) 114 # should begin with a letter, but given that 'xalpha' includes dot this was 115 # a bit clumsy to pull off in practice, so I left it lazy. 116 my $url_xalphas = qr/[-$_@.&+!*"'(),a-zA-Z0-9]/; 117 our $IsValidURL = qr/ ^ 118 (?: http | https | ftp ) :\/\/ # protocol 119 (?: 120 [a-zA-Z] $url_xalphas* # hostname 121 | (?: \d{1,3} \. ){3} \d{1,3} # IP 122 ) 123 (?: : [0-9]+ )? # port 124 (?: \/ # path: leading slash 125 (?: $url_xalphas* # path: path part name 126 | %[a-fA-F][a-fA-F] )* # path: escape 127 )* # path: as many as you want 128 (?: \? $url_xalphas+ )? # query string 129 (?: \# $url_xalphas+ )? # anchor 130 $ /x; 131 132 111 133 sub pad { sprintf "%0$_[1]d", $_[0] } 112 134 sub round { $_[1] ||= 0; return int($_[0] * 10 ** $_[1] + .5) / 10 ** $_[1]; }
