line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Livedoor::Wiki::Utils; |
2
|
14
|
|
|
14
|
|
72
|
use warnings; |
|
14
|
|
|
|
|
28
|
|
|
14
|
|
|
|
|
377
|
|
3
|
14
|
|
|
14
|
|
70
|
use strict; |
|
14
|
|
|
|
|
23
|
|
|
14
|
|
|
|
|
9328
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub escape { |
6
|
499
|
|
|
499
|
1
|
908
|
my $str = shift; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#$str =~ s/&/&/g; allow user to use html escape. |
9
|
499
|
|
|
|
|
1081
|
$str =~ s/</g; |
10
|
499
|
|
|
|
|
999
|
$str =~ s/>/>/g; |
11
|
499
|
|
|
|
|
1065
|
$str =~ s/"/"/g; |
12
|
|
|
|
|
|
|
|
13
|
499
|
|
|
|
|
2117
|
return $str; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub escape_more { |
18
|
43
|
|
|
43
|
1
|
78
|
my $str = shift; |
19
|
43
|
|
|
|
|
143
|
$str =~ s/&/&/g; |
20
|
43
|
|
|
|
|
99
|
$str =~ s/#/#/g; # for #contents |
21
|
43
|
|
|
|
|
235
|
return escape( $str ); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub sanitize_uri { |
25
|
2
|
|
|
2
|
1
|
3
|
my $str = shift; |
26
|
2
|
|
|
|
|
6
|
$str =~ s/^\s+//; |
27
|
2
|
|
|
|
|
4
|
$str =~ s/\s+$//; |
28
|
2
|
|
|
|
|
10
|
$str |
29
|
12
|
|
|
|
|
44
|
=~ s/([^A-Za-z0-9;\/\?\:\@\&\=\+\$,\[\]\-\_\.\!\~\*\'\(\)%\#])/'%'.unpack('H2', $1)/eg; |
30
|
2
|
|
|
|
|
10
|
return $str; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub is_image_url { |
34
|
35
|
|
|
35
|
1
|
60
|
my $url = shift; |
35
|
35
|
100
|
|
|
|
75
|
return unless &is_url( $url ); |
36
|
|
|
|
|
|
|
# bmp >_< |
37
|
29
|
100
|
|
|
|
218
|
return $url =~ /\.(jpg|jpeg|png|gif|bmp)(\?.*|#.*)?$/i ? 1 : 0; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
sub is_url { |
40
|
35
|
|
|
35
|
1
|
43
|
my $url = shift; |
41
|
35
|
100
|
|
|
|
260
|
return $url =~ /^(?:http|https|ftp):\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#]+$/ ? 1 : 0; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub get_width_height { |
45
|
30
|
|
|
30
|
1
|
50
|
my $value= shift; |
46
|
30
|
|
|
|
|
46
|
my $default = shift; |
47
|
|
|
|
|
|
|
|
48
|
30
|
|
|
|
|
48
|
my $width = $default->{width}; |
49
|
30
|
|
|
|
|
39
|
my $height = $default->{height}; |
50
|
|
|
|
|
|
|
|
51
|
30
|
100
|
|
|
|
172
|
if ($value =~ m/(\d+),(\d+)/ ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
52
|
7
|
|
|
|
|
39
|
($width , $height ) = $value =~ m/(\d+),(\d+)/; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
elsif($value =~ m/,(\d+)/ ) { |
55
|
3
|
|
|
|
|
15
|
( $height ) = $value =~ m/,(\d+)/; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
elsif($value =~ m/(\d+)/ ) { |
58
|
5
|
|
|
|
|
22
|
( $width ) = $value =~ m/(\d+)/; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
30
|
|
|
|
|
107
|
return ( $width , $height ); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 NAME |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Text::Livedoor::Wiki::Utils - utilities |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 DESCRIPTION |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
utilities |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 FUNCTION |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 escape |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
escape HTML |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 escape_more |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
escape more HTML |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 get_width_height |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
getting width and height |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 is_image_url |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
check its image URL or not |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 is_url |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
check its URL or not |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 sanitize_uri |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sanitize URL |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 AUTHOR |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
polocky |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |