line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::LinkEmbedder::Link::Text::HTML; |
2
|
1
|
|
|
1
|
|
1608
|
use Mojo::Base 'Mojolicious::Plugin::LinkEmbedder::Link::Text'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
has audio => ''; |
5
|
|
|
|
|
|
|
has canon_url => sub { shift->url }; |
6
|
|
|
|
|
|
|
has description => ''; |
7
|
|
|
|
|
|
|
has image => ''; |
8
|
|
|
|
|
|
|
has title => ''; |
9
|
|
|
|
|
|
|
has type => ''; |
10
|
|
|
|
|
|
|
has video => ''; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub learn { |
13
|
0
|
|
|
0
|
0
|
|
my ($self, $c, $cb) = @_; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$self->ua->get( |
16
|
|
|
|
|
|
|
$self->url, |
17
|
|
|
|
|
|
|
sub { |
18
|
0
|
|
|
0
|
|
|
my ($ua, $tx) = @_; |
19
|
0
|
0
|
|
|
|
|
my $dom = $tx->success ? $tx->res->dom : undef; |
20
|
0
|
0
|
|
|
|
|
$self->_tx($tx)->_learn_from_dom($dom) if $dom; |
21
|
0
|
|
|
|
|
|
$self->$cb; |
22
|
|
|
|
|
|
|
}, |
23
|
0
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
$self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub to_embed { |
29
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
30
|
|
|
|
|
|
|
|
31
|
0
|
0
|
|
|
|
|
if ($self->image) { |
32
|
|
|
|
|
|
|
return $self->tag( |
33
|
|
|
|
|
|
|
div => class => 'link-embedder text-html', |
34
|
|
|
|
|
|
|
sub { |
35
|
|
|
|
|
|
|
return join( |
36
|
|
|
|
|
|
|
'', |
37
|
|
|
|
|
|
|
$self->tag( |
38
|
|
|
|
|
|
|
div => class => 'link-embedder-media', |
39
|
0
|
|
|
|
|
|
sub { $self->tag(img => src => $self->image, alt => $self->title) } |
40
|
|
|
|
|
|
|
), |
41
|
|
|
|
|
|
|
$self->tag(h3 => $self->title), |
42
|
|
|
|
|
|
|
$self->tag(p => $self->description), |
43
|
|
|
|
|
|
|
$self->tag( |
44
|
|
|
|
|
|
|
div => class => 'link-embedder-link', |
45
|
|
|
|
|
|
|
sub { |
46
|
0
|
|
|
|
|
|
$self->tag(a => href => $self->canon_url, title => $self->canon_url, $self->canon_url); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
) |
49
|
0
|
|
|
0
|
|
|
); |
50
|
|
|
|
|
|
|
} |
51
|
0
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
return $self->SUPER::to_embed(@_); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _learn_from_dom { |
58
|
0
|
|
|
0
|
|
|
my ($self, $dom) = @_; |
59
|
0
|
|
|
|
|
|
my $e; |
60
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
$self->audio($e->{content}) if $e = $dom->at('meta[property="og:audio"]'); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$self->description($e->{content} || $e->{value}) |
64
|
0
|
0
|
0
|
|
|
|
if $e = $dom->at('meta[property="og:description"]') || $dom->at('meta[name="twitter:description"]'); |
|
|
|
0
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$self->image($e->{content} || $e->{value}) |
67
|
0
|
0
|
0
|
|
|
|
if $e |
|
|
|
0
|
|
|
|
|
68
|
|
|
|
|
|
|
= $dom->at('meta[property="og:image"]') |
69
|
|
|
|
|
|
|
|| $dom->at('meta[property="og:image:url"]') |
70
|
|
|
|
|
|
|
|| $dom->at('meta[name="twitter:image"]'); |
71
|
|
|
|
|
|
|
|
72
|
0
|
0
|
0
|
|
|
|
$self->title($e->{content} || $e->{value} || $e->text || '') |
|
|
|
0
|
|
|
|
|
73
|
|
|
|
|
|
|
if $e = $dom->at('meta[property="og:title"]') || $dom->at('meta[name="twitter:title"]') || $dom->at('title'); |
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
0
|
|
|
|
$self->type($e->{content}) if $e = $dom->at('meta[property="og:type"]') || $dom->at('meta[name="twitter:card"]'); |
76
|
0
|
0
|
|
|
|
|
$self->video($e->{content}) if $e = $dom->at('meta[property="og:video"]'); |
77
|
|
|
|
|
|
|
$self->canon_url($e->{content} || $e->{value}) |
78
|
0
|
0
|
0
|
|
|
|
if $e = $dom->at('meta[property="og:url"]') || $dom->at('meta[name="twitter:url"]'); |
|
|
|
0
|
|
|
|
|
79
|
0
|
0
|
0
|
|
|
|
$self->media_id($self->canon_url) if $self->canon_url and !defined $self->{media_id}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |