line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- cperl -*- |
2
|
|
|
|
|
|
|
# copyright (C) 2005 Topia . all rights reserved. |
3
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it |
4
|
|
|
|
|
|
|
# under the same terms as Perl itself. |
5
|
|
|
|
|
|
|
# $Id: EntryParserMixin.pm 108 2005-02-05 10:36:41Z topia $ |
6
|
|
|
|
|
|
|
# $URL: file:///usr/minetools/svnroot/mixi/trunk/WWW-Mixi-OO/lib/WWW/Mixi/OO/Util/EntryParserMixin.pm $ |
7
|
|
|
|
|
|
|
package WWW::Mixi::OO::Util::EntryParserMixin; |
8
|
2
|
|
|
2
|
|
16025
|
use strict; |
|
2
|
|
|
|
|
382
|
|
|
2
|
|
|
|
|
76
|
|
9
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
54
|
|
10
|
2
|
|
|
2
|
|
12
|
use URI; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
38
|
|
11
|
2
|
|
|
2
|
|
11
|
use URI::QueryParam; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1387
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
WWW::Mixi::OO::Util::EntryParserMixin - WWW::Mixi::OO's Entry Parser Mixin |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
package WWW::Mixi:OO::FooPage; |
20
|
|
|
|
|
|
|
# use base's order is important! |
21
|
|
|
|
|
|
|
use base qw(WWW::Mixi::OO::Page); # or your super class |
22
|
|
|
|
|
|
|
use base qw(WWW::Mixi::OO::Util::EntryParserMixin); |
23
|
|
|
|
|
|
|
# and use... |
24
|
|
|
|
|
|
|
my $this->parse_entry($entry_text); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DESCRIPTION |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
entry parser mixin. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 METHODS |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=over 4 |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=item parse_image_thumbnail |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my @items = $util->parse_image_thumbnail(''); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
parse image thumbnail html parts, and return array of |
41
|
|
|
|
|
|
|
image's information hashrefs. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
image's information items: |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=over 4 |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=item link |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
URI of image. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=item subject |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
subject of image(img/alt). |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=item thumbnail_link |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
URI of image thumbnail. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=back |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub parse_image_thumbnail { |
64
|
0
|
|
|
0
|
1
|
|
my ($this, $text) = @_; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $maybe_attrs_regex = $this->regex_parts->{html_maybe_attrs}; |
67
|
0
|
0
|
|
|
|
|
return () unless $text =~ m||iosx; |
69
|
|
|
|
|
|
|
return map { |
70
|
0
|
0
|
|
|
|
|
if (m||sio) { |
|
0
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $anchor = $this->generate_ignore_case_hash( |
72
|
|
|
|
|
|
|
$this->html_attrs_to_hash($1)); |
73
|
0
|
|
|
|
|
|
my $img = $this->generate_ignore_case_hash( |
74
|
|
|
|
|
|
|
$this->html_attrs_to_hash($2)); |
75
|
0
|
|
|
|
|
|
my $data = { |
76
|
|
|
|
|
|
|
link => $this->absolute_linked_uri($anchor->{href}), |
77
|
|
|
|
|
|
|
}; |
78
|
0
|
0
|
0
|
|
|
|
if (URI->new($data->{link})->scheme eq 'javascript' && |
79
|
|
|
|
|
|
|
exists $anchor->{onclick}) { |
80
|
0
|
0
|
|
|
|
|
if ($anchor->{onclick} =~ /MM_open\w*Window\('([^\']+)',/) { |
81
|
0
|
|
|
|
|
|
$this->copy_hash_val( |
82
|
|
|
|
|
|
|
{$this->analyze_uri($this->absolute_linked_uri($1))}, |
83
|
|
|
|
|
|
|
$data, |
84
|
|
|
|
|
|
|
[qw(image link)]); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
0
|
|
|
|
|
|
$this->copy_hash_val($img, $data, [qw(alt subject)]); |
88
|
0
|
0
|
|
|
|
|
$data->{thumbnail_link} = $this->absolute_linked_uri($img->{src}) |
89
|
|
|
|
|
|
|
if exists $img->{src}; |
90
|
0
|
|
|
|
|
|
$data; |
91
|
|
|
|
|
|
|
} else { |
92
|
|
|
|
|
|
|
() |
93
|
0
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} $this->extract_balanced_html_parts( |
95
|
|
|
|
|
|
|
exclude_border_element => 1, |
96
|
|
|
|
|
|
|
element => 'td', |
97
|
|
|
|
|
|
|
text => $1); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item parse_entry |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
my $data = $util->parse_entry('....'); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
parse entry text, and return hashref. items: |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=over 4 |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item body |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
body text. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item images |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
arrayref of images (see parse_image_thumbnail). |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=back |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub parse_entry { |
121
|
0
|
|
|
0
|
1
|
|
my ($this, $text) = @_; |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
my $data = {}; |
124
|
0
|
0
|
|
|
|
|
if ($text =~ //) {
125
|
0
|
|
|
|
|
|
$data->{images} = [map { |
126
|
|
|
|
|
|
|
# remove this |
127
|
0
|
|
|
|
|
|
$text =~ s/\Q$_\E\s*//s; |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
$this->parse_image_thumbnail($_); |
130
|
|
|
|
|
|
|
} $this->extract_balanced_html_parts( |
131
|
|
|
|
|
|
|
element => 'table', |
132
|
|
|
|
|
|
|
text => "$text ")]; |
133
|
|
|
|
|
|
|
# XXX: this stringify is avoid unknown warning |
134
|
|
|
|
|
|
|
# Malformed UTF-8 character (unexpected end of string) in subroutine entry |
135
|
|
|
|
|
|
|
# at extract_balanced_html_parts/HTML::Parser->parse. |
136
|
|
|
|
|
|
|
} |
137
|
0
|
|
|
|
|
|
$data->{body} = $text; |
138
|
0
|
|
|
|
|
|
$data; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
__END__ |
|