onebox 1.5.50 → 1.5.60
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/onebox/engine.rb +1 -0
- data/lib/onebox/engine/github_commit_onebox.rb +1 -2
- data/lib/onebox/engine/github_issue_onebox.rb +1 -2
- data/lib/onebox/engine/github_pullrequest_onebox.rb +1 -2
- data/lib/onebox/engine/slides_onebox.rb +12 -15
- data/lib/onebox/engine/soundcloud_onebox.rb +12 -13
- data/lib/onebox/engine/standard_embed.rb +61 -84
- data/lib/onebox/engine/whitelisted_generic_onebox.rb +98 -142
- data/lib/onebox/engine/xkcd_onebox.rb +30 -0
- data/lib/onebox/engine/youtube_onebox.rb +111 -102
- data/lib/onebox/helpers.rb +8 -0
- data/lib/onebox/layout.rb +37 -44
- data/lib/onebox/matcher.rb +1 -3
- data/lib/onebox/version.rb +1 -1
- data/spec/fixtures/meetup.response.html +4419 -0
- data/spec/fixtures/{meetup.response → meetup_oembed.response} +0 -0
- data/spec/fixtures/xkcd.response +1 -0
- data/spec/lib/onebox/engine/slides_onebox_spec.rb +2 -3
- data/spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb +4 -2
- data/spec/lib/onebox/engine/xkcd_spec.rb +27 -0
- data/spec/lib/onebox/engine/youtube_onebox_spec.rb +16 -34
- data/templates/_layout.mustache +3 -6
- data/templates/xkcd.mustache +8 -0
- metadata +12 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6284a87a3edbd77cb74a40d458a2774f350ec86d
|
4
|
+
data.tar.gz: 2e2e203e7321cd7e453f50e18e3bd73a56ade1e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af6c86905744a6da99816a166be42e52dd4d785cba77e4e7fa17d4b097262ad7e57ebe27abea5120fcfd2d5db2bff1fdf3a7ba81f1b743616307315fa90fa787
|
7
|
+
data.tar.gz: 7e68883159aa1313539b1501689aafd5f6080359d587d7b138c36c5b1f334188a37a9f5b02c150148dbaa48af0f570ad68432842ec37960bfb89d6cead4203e2
|
data/lib/onebox/engine.rb
CHANGED
@@ -29,8 +29,7 @@ module Onebox
|
|
29
29
|
|
30
30
|
ulink = URI(link)
|
31
31
|
result['commit_date'] = Time.parse(result['commit']['author']['date']).strftime("%I:%M%p - %d %b %y")
|
32
|
-
result['
|
33
|
-
result['repository_url'] = "https://#{result['repository_path']}"
|
32
|
+
result['domain'] = "#{ulink.host}/#{ulink.path.split('/')[1]}/#{ulink.path.split('/')[2]}"
|
34
33
|
result
|
35
34
|
end
|
36
35
|
end
|
@@ -41,8 +41,7 @@ module Onebox
|
|
41
41
|
closed_at: (@raw['closed_at'].nil? ? "" : @raw['closed_at'].split("T")[0]),
|
42
42
|
closed_by: @raw['closed_by'],
|
43
43
|
avatar: "https://avatars1.githubusercontent.com/u/#{@raw['user']['id']}?v=2&s=96",
|
44
|
-
|
45
|
-
repository_url: "https://#{ulink.host}/#{ulink.path.split('/')[1]}/#{ulink.path.split('/')[2]}",
|
44
|
+
domain: "#{ulink.host}/#{ulink.path.split('/')[1]}/#{ulink.path.split('/')[2]}",
|
46
45
|
}
|
47
46
|
end
|
48
47
|
end
|
@@ -23,8 +23,7 @@ module Onebox
|
|
23
23
|
result['link'] = link
|
24
24
|
result['created_at'] = Time.parse(result['created_at']).strftime("%I:%M%p - %d %b %y")
|
25
25
|
ulink = URI(link)
|
26
|
-
result['
|
27
|
-
result['repository_url'] = "https://#{result['repository_path']}"
|
26
|
+
result['domain'] = "#{ulink.host}/#{ulink.path.split('/')[1]}/#{ulink.path.split('/')[2]}"
|
28
27
|
result
|
29
28
|
end
|
30
29
|
end
|
@@ -6,27 +6,24 @@ module Onebox
|
|
6
6
|
|
7
7
|
matches_regexp(/^https?:\/\/slides\.com\/[\p{Alnum}_\-]+\/[\p{Alnum}_\-]+$/)
|
8
8
|
|
9
|
-
|
10
9
|
def to_html
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
<<-HTML
|
11
|
+
<iframe src="//slides.com#{uri.path}/embed?style=light"
|
12
|
+
width="576"
|
13
|
+
height="420"
|
14
|
+
scrolling="no"
|
15
|
+
frameborder="0"
|
16
|
+
webkitallowfullscreen
|
17
|
+
mozallowfullscreen
|
18
|
+
allowfullscreen>
|
19
|
+
</iframe>"
|
20
|
+
HTML
|
14
21
|
end
|
15
22
|
|
16
23
|
def placeholder_html
|
17
|
-
#
|
18
|
-
"<img src='#{get_opengraph_data[:images].first}'>"
|
24
|
+
"<img src='#{raw[:image]}'>"
|
19
25
|
end
|
20
26
|
|
21
|
-
private
|
22
|
-
|
23
|
-
def get_opengraph_data
|
24
|
-
return @opengraph_data if @opengraph_data
|
25
|
-
response = Onebox::Helpers.fetch_response(url)
|
26
|
-
html_doc = Nokogiri::HTML(response.body)
|
27
|
-
|
28
|
-
@opengraph_data = parse_open_graph(html_doc, url)
|
29
|
-
end
|
30
27
|
end
|
31
28
|
end
|
32
29
|
end
|
@@ -8,27 +8,26 @@ module Onebox
|
|
8
8
|
always_https
|
9
9
|
|
10
10
|
def to_html
|
11
|
-
oembed_data
|
12
|
-
oembed_data.gsub!('visual=true', 'visual=false') || oembed_data
|
11
|
+
oembed_data[:html].gsub('visual=true', 'visual=false')
|
13
12
|
end
|
14
13
|
|
15
14
|
def placeholder_html
|
16
|
-
|
15
|
+
return if Onebox::Helpers.blank?(oembed_data[:thumbnail_url])
|
16
|
+
"<img src='#{oembed_data[:thumbnail_url]}'>"
|
17
17
|
end
|
18
18
|
|
19
19
|
private
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
Onebox::Helpers.symbolize_keys(::MultiJson.load(Onebox::Helpers.fetch_response("https://soundcloud.com/oembed.json?url=#{url}&maxheight=166").body))
|
21
|
+
def oembed_data
|
22
|
+
@oembed_data ||= begin
|
23
|
+
oembed_url = "https://soundcloud.com/oembed.json?url=#{url}"
|
24
|
+
oembed_url << "&maxheight=166" if url["/sets/"]
|
25
|
+
Onebox::Helpers.symbolize_keys(::MultiJson.load(Onebox::Helpers.fetch_response(oembed_url).body))
|
26
|
+
rescue
|
27
|
+
{}
|
28
|
+
end
|
30
29
|
end
|
31
|
-
|
30
|
+
|
32
31
|
end
|
33
32
|
end
|
34
33
|
end
|
@@ -6,27 +6,20 @@ module Onebox
|
|
6
6
|
@@oembed_providers ||= {}
|
7
7
|
end
|
8
8
|
|
9
|
-
def self.opengraph_providers
|
10
|
-
@@opengraph_providers ||= Array.new
|
11
|
-
end
|
12
|
-
|
13
9
|
def self.add_oembed_provider(regexp, endpoint)
|
14
10
|
oembed_providers[regexp] = endpoint
|
15
11
|
end
|
16
12
|
|
13
|
+
def self.opengraph_providers
|
14
|
+
@@opengraph_providers ||= []
|
15
|
+
end
|
16
|
+
|
17
17
|
def self.add_opengraph_provider(regexp)
|
18
|
-
opengraph_providers
|
18
|
+
opengraph_providers << regexp
|
19
19
|
end
|
20
20
|
|
21
21
|
# Some oembed providers (like meetup.com) don't provide links to themselves
|
22
|
-
add_oembed_provider
|
23
|
-
add_oembed_provider /www\.kickstarter\.com\//, 'https://www.kickstarter.com/services/oembed'
|
24
|
-
add_oembed_provider /www\.meetup\.com\//, 'http://api.meetup.com/oembed'
|
25
|
-
add_oembed_provider /www\.ted\.com\//, 'http://www.ted.com/services/v1/oembed.json'
|
26
|
-
add_oembed_provider /(.*\.)?vimeo\.com\//, 'http://vimeo.com/api/oembed.json'
|
27
|
-
|
28
|
-
# Sites that work better with OpenGraph
|
29
|
-
add_opengraph_provider /nytimes\.com\//
|
22
|
+
add_oembed_provider(/www\.meetup\.com\//, 'http://api.meetup.com/oembed')
|
30
23
|
|
31
24
|
def always_https?
|
32
25
|
WhitelistedGenericOnebox.host_matches(uri, WhitelistedGenericOnebox.https_hosts)
|
@@ -35,92 +28,76 @@ module Onebox
|
|
35
28
|
def raw
|
36
29
|
return @raw if @raw
|
37
30
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
return @raw if @raw
|
42
|
-
end
|
43
|
-
end
|
31
|
+
og = get_opengraph
|
32
|
+
twitter = get_twitter
|
33
|
+
oembed = get_oembed
|
44
34
|
|
45
|
-
|
46
|
-
html_doc = Nokogiri::HTML(response.body)
|
35
|
+
@raw = {}
|
47
36
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
37
|
+
og.each { |k, v| @raw[k] ||= v unless Onebox::Helpers::blank?(v) }
|
38
|
+
twitter.each { |k, v| @raw[k] ||= v unless Onebox::Helpers::blank?(v) }
|
39
|
+
oembed.each { |k, v| @raw[k] ||= v unless Onebox::Helpers::blank?(v) }
|
40
|
+
|
41
|
+
@raw
|
42
|
+
end
|
54
43
|
|
55
|
-
|
56
|
-
oembed_alternate = html_doc.at("//link[@type='application/json+oembed']") || html_doc.at("//link[@type='text/json+oembed']")
|
57
|
-
# Do not use oEmbed for WordPress sites (https://meta.discourse.org/t/onebox-for-wordpress-4-4-sites/36765)
|
58
|
-
fetch_oembed_raw(oembed_alternate) unless oembed_alternate.nil? || oembed_alternate['href'] =~ /public-api.wordpress.com\/oembed/ || oembed_alternate['href'] =~ /wp-json\/oembed/
|
44
|
+
private
|
59
45
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
46
|
+
def html_doc
|
47
|
+
return @html_doc if @html_doc
|
48
|
+
response = Onebox::Helpers.fetch_response(url)
|
49
|
+
@html_doc = Nokogiri::HTML(response.body)
|
64
50
|
end
|
65
51
|
|
66
|
-
|
67
|
-
|
52
|
+
def get_oembed
|
53
|
+
application_json = html_doc.at("//link[@type='application/json+oembed']/@href")
|
54
|
+
oembed_url = application_json.value if application_json
|
68
55
|
|
69
|
-
|
56
|
+
text_json = html_doc.at("//link[@type='text/json+oembed']/@href")
|
57
|
+
oembed_url ||= text_json.value if text_json
|
70
58
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
nil
|
79
|
-
else
|
80
|
-
oembed_data
|
59
|
+
if Onebox::Helpers.blank?(oembed_url)
|
60
|
+
StandardEmbed.oembed_providers.each do |regexp, endpoint|
|
61
|
+
if url[regexp]
|
62
|
+
oembed_url = "#{endpoint}?url=#{url}"
|
63
|
+
break
|
64
|
+
end
|
65
|
+
end
|
81
66
|
end
|
82
|
-
rescue Errno::ECONNREFUSED, Net::HTTPError, MultiJson::LoadError
|
83
|
-
@raw = nil
|
84
|
-
end
|
85
67
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
if m_name == "image"
|
101
|
-
image_uri = URI.parse(m_content) rescue nil
|
102
|
-
if image_uri
|
103
|
-
if image_uri.host.nil?
|
104
|
-
image_uri.host = URI.parse(og_url).host
|
105
|
-
end
|
106
|
-
og.images.push image_uri.to_s
|
107
|
-
end
|
108
|
-
elsif attrs_list.include? m_name
|
109
|
-
og.send("#{m_name}=", m_content) unless m_content.empty?
|
68
|
+
return {} if Onebox::Helpers.blank?(oembed_url)
|
69
|
+
|
70
|
+
Onebox::Helpers.symbolize_keys(::MultiJson.load(Onebox::Helpers.fetch_response(oembed_url).body))
|
71
|
+
rescue Errno::ECONNREFUSED, Net::HTTPError, MultiJson::LoadError
|
72
|
+
{}
|
73
|
+
end
|
74
|
+
|
75
|
+
def get_opengraph
|
76
|
+
og = {}
|
77
|
+
|
78
|
+
html_doc.css('meta').each do |m|
|
79
|
+
if m["property"] && m["property"][/^og:(.+)$/i]
|
80
|
+
value = m["content"].to_s
|
81
|
+
og[$1.tr('-:','_').to_sym] ||= value unless Onebox::Helpers::blank?(value)
|
110
82
|
end
|
111
83
|
end
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
84
|
+
|
85
|
+
og
|
86
|
+
end
|
87
|
+
|
88
|
+
def get_twitter
|
89
|
+
twitter = {}
|
90
|
+
|
91
|
+
html_doc.css('meta').each do |m|
|
92
|
+
if m["name"] && m["name"][/^twitter:(.+)$/i]
|
93
|
+
value = (m["content"] || m["value"]).to_s
|
94
|
+
twitter[$1.tr('-:','_').to_sym] ||= value unless Onebox::Helpers::blank?(value)
|
95
|
+
end
|
119
96
|
end
|
97
|
+
|
98
|
+
twitter
|
120
99
|
end
|
121
100
|
|
122
|
-
og
|
123
|
-
end
|
124
101
|
end
|
125
102
|
end
|
126
103
|
end
|
@@ -16,7 +16,8 @@ module Onebox
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.default_whitelist
|
19
|
-
%w(
|
19
|
+
%w(
|
20
|
+
23hq.com
|
20
21
|
500px.com
|
21
22
|
8tracks.com
|
22
23
|
abc.net.au
|
@@ -32,13 +33,14 @@ module Onebox
|
|
32
33
|
blip.tv
|
33
34
|
bloomberg.com
|
34
35
|
businessinsider.com
|
36
|
+
change.org
|
35
37
|
clikthrough.com
|
36
38
|
cnet.com
|
37
39
|
cnn.com
|
40
|
+
codepen.io
|
38
41
|
collegehumor.com
|
39
42
|
consider.it
|
40
43
|
coursera.org
|
41
|
-
codepen.io
|
42
44
|
cracked.com
|
43
45
|
dailymail.co.uk
|
44
46
|
dailymotion.com
|
@@ -62,8 +64,8 @@ module Onebox
|
|
62
64
|
gfycat.com
|
63
65
|
groupon.com
|
64
66
|
howtogeek.com
|
65
|
-
huffingtonpost.com
|
66
67
|
huffingtonpost.ca
|
68
|
+
huffingtonpost.com
|
67
69
|
hulu.com
|
68
70
|
ign.com
|
69
71
|
ikea.com
|
@@ -75,9 +77,9 @@ module Onebox
|
|
75
77
|
khanacademy.org
|
76
78
|
kickstarter.com
|
77
79
|
kinomap.com
|
80
|
+
lessonplanet.com
|
78
81
|
liveleak.com
|
79
82
|
livestream.com
|
80
|
-
lessonplanet.com
|
81
83
|
mashable.com
|
82
84
|
medium.com
|
83
85
|
meetup.com
|
@@ -86,8 +88,8 @@ module Onebox
|
|
86
88
|
myshopify.com
|
87
89
|
myspace.com
|
88
90
|
nba.com
|
89
|
-
nytimes.com
|
90
91
|
npr.org
|
92
|
+
nytimes.com
|
91
93
|
photobucket.com
|
92
94
|
pinterest.com
|
93
95
|
reference.com
|
@@ -122,16 +124,16 @@ module Onebox
|
|
122
124
|
vine.co
|
123
125
|
walmart.com
|
124
126
|
washingtonpost.com
|
127
|
+
wi.st
|
125
128
|
wikia.com
|
126
129
|
wikihow.com
|
127
130
|
wired.com
|
128
131
|
wistia.com
|
129
|
-
wi.st
|
130
132
|
wonderhowto.com
|
131
133
|
wsj.com
|
132
134
|
zappos.com
|
133
135
|
zillow.com
|
134
|
-
|
136
|
+
)
|
135
137
|
end
|
136
138
|
|
137
139
|
# Often using the `html` attribute is not what we want, like for some blogs that
|
@@ -149,7 +151,7 @@ module Onebox
|
|
149
151
|
@html_providers = new_provs
|
150
152
|
end
|
151
153
|
|
152
|
-
# A re-written URL
|
154
|
+
# A re-written URL converts http:// -> https://
|
153
155
|
def self.rewrites
|
154
156
|
@rewrites ||= https_hosts.dup
|
155
157
|
end
|
@@ -176,176 +178,130 @@ module Onebox
|
|
176
178
|
|
177
179
|
def self.===(other)
|
178
180
|
if other.kind_of?(URI)
|
179
|
-
|
180
|
-
WhitelistedGenericOnebox.probable_wordpress(other) ||
|
181
|
-
WhitelistedGenericOnebox.probable_discourse(other)
|
181
|
+
host_matches(other, whitelist) || probable_wordpress(other) || probable_discourse(other)
|
182
182
|
else
|
183
183
|
super
|
184
184
|
end
|
185
185
|
end
|
186
186
|
|
187
|
-
# Generates the HTML for the embedded content
|
188
|
-
def photo_type?
|
189
|
-
( (data[:type] =~ /photo/ || data[:type] =~ /image/) && data[:type] !~ /photostream/ )
|
190
|
-
end
|
191
|
-
|
192
|
-
def article_type?
|
193
|
-
data[:type] == "article"
|
194
|
-
end
|
195
|
-
|
196
|
-
def rewrite_https(html)
|
197
|
-
return html unless html
|
198
|
-
uri = URI(@url)
|
199
|
-
if WhitelistedGenericOnebox.host_matches(uri, WhitelistedGenericOnebox.rewrites)
|
200
|
-
html.gsub!(/http:\/\//, 'https://')
|
201
|
-
end
|
202
|
-
html
|
203
|
-
end
|
204
|
-
|
205
|
-
def html_type?
|
206
|
-
return data &&
|
207
|
-
data[:html] &&
|
208
|
-
(
|
209
|
-
(data[:html] =~ /iframe/) ||
|
210
|
-
WhitelistedGenericOnebox.html_providers.include?(data[:provider_name])
|
211
|
-
)
|
212
|
-
end
|
213
|
-
|
214
|
-
def generic_html
|
215
|
-
return add_thumbnail_class(data[:html]) if html_type?
|
216
|
-
return layout.to_html if article_type?
|
217
|
-
return html_for_video(data[:video]) if data[:video]
|
218
|
-
return image_html if photo_type?
|
219
|
-
return nil if data[:title].nil? || data[:title].empty?
|
220
|
-
|
221
|
-
layout.to_html
|
222
|
-
end
|
223
|
-
|
224
187
|
def to_html
|
225
188
|
rewrite_https(generic_html)
|
226
189
|
end
|
227
190
|
|
228
191
|
def placeholder_html
|
229
|
-
|
230
|
-
return
|
231
|
-
|
232
|
-
|
192
|
+
return article_html if is_article?
|
193
|
+
return image_html if has_image? && (is_video? || is_image?)
|
194
|
+
return article_html if has_text? && is_embedded?
|
195
|
+
to_html
|
233
196
|
end
|
234
197
|
|
235
198
|
def data
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
199
|
+
@data ||= begin
|
200
|
+
html_entities = HTMLEntities.new
|
201
|
+
d = { link: link }.merge(raw)
|
202
|
+
if !Onebox::Helpers.blank?(d[:title])
|
203
|
+
d[:title] = html_entities.decode(Onebox::Helpers.truncate(d[:title]))
|
204
|
+
end
|
205
|
+
if !Onebox::Helpers.blank?(d[:description])
|
206
|
+
d[:description] = html_entities.decode(Onebox::Helpers.truncate(d[:description], 250))
|
207
|
+
end
|
208
|
+
d
|
240
209
|
end
|
210
|
+
end
|
241
211
|
|
242
|
-
|
243
|
-
data_hash[:image] = raw.images.first if raw.images && raw.images.first
|
244
|
-
data_hash[:type] = raw.type if raw.type
|
212
|
+
private
|
245
213
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
214
|
+
def rewrite_https(html)
|
215
|
+
return unless html
|
216
|
+
uri = URI(@url)
|
217
|
+
html.gsub!("http://", "https://") if WhitelistedGenericOnebox.host_matches(uri, WhitelistedGenericOnebox.rewrites)
|
218
|
+
html
|
250
219
|
end
|
251
220
|
|
252
|
-
|
253
|
-
|
254
|
-
|
221
|
+
def generic_html
|
222
|
+
return article_html if is_article?
|
223
|
+
return embedded_html if is_embedded?
|
224
|
+
return video_html if is_video?
|
225
|
+
return image_html if is_image?
|
226
|
+
return article_html if has_text?
|
255
227
|
end
|
256
228
|
|
257
|
-
|
258
|
-
|
259
|
-
|
229
|
+
def is_article?
|
230
|
+
data[:type] =~ /article/ &&
|
231
|
+
has_text?
|
260
232
|
end
|
261
233
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
private
|
266
|
-
|
267
|
-
def image_html
|
268
|
-
return @image_html if @image_html
|
269
|
-
|
270
|
-
return @image_html = "<img src=\"#{data[:image]}\">" if data[:image]
|
271
|
-
|
272
|
-
if data[:thumbnail_url]
|
273
|
-
@image_html = "<img src=\"#{data[:thumbnail_url]}\""
|
274
|
-
@image_html << " width=\"#{data[:thumbnail_width]}\"" if data[:thumbnail_width]
|
275
|
-
@image_html << " height=\"#{data[:thumbnail_height]}\"" if data[:thumbnail_height]
|
276
|
-
@image_html << ">"
|
234
|
+
def has_text?
|
235
|
+
!Onebox::Helpers.blank?(data[:title]) &&
|
236
|
+
!Onebox::Helpers.blank?(data[:description])
|
277
237
|
end
|
278
238
|
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
if video.is_a?(String)
|
284
|
-
video_url = video
|
285
|
-
elsif video.is_a?(Hash)
|
286
|
-
video_url = video[:_value]
|
287
|
-
else
|
288
|
-
return
|
239
|
+
def is_image?
|
240
|
+
data[:type] =~ /photo|image/ &&
|
241
|
+
data[:type] !~ /photostream/ &&
|
242
|
+
has_image?
|
289
243
|
end
|
290
244
|
|
245
|
+
def has_image?
|
246
|
+
!Onebox::Helpers.blank?(data[:image]) ||
|
247
|
+
!Onebox::Helpers.blank?(data[:thumbnail_url])
|
248
|
+
end
|
291
249
|
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
if (@raw.metadata && @raw.metadata[:"video:type"])
|
298
|
-
video_type = @raw.metadata[:"video:type"]
|
299
|
-
if video_type.include? "video/mp4" # find if there is a video with type
|
300
|
-
if video_type.size > 1 # if more then one video item based on provided video_type
|
301
|
-
ind = video_type.find_index("video/mp4") # get the first video index with type video/mp4
|
302
|
-
video_url = @raw.metadata[:video][ind] # update video_url
|
303
|
-
end
|
304
|
-
|
305
|
-
attr = append_attribute(:width, attr, video)
|
306
|
-
attr = append_attribute(:height, attr, video)
|
307
|
-
|
308
|
-
site_name_and_title = ( ("<span style='color:#fff;background:#9B9B9B;border-radius:3px;padding:3px;margin-right: 5px;'>" + CGI::escapeHTML(@raw.metadata[:site_name][0].to_s) + '</span> ') + CGI::escapeHTML((@raw.title || @raw.description).to_s) )
|
309
|
-
orig_url = @raw.url
|
310
|
-
html_v2 = %Q(
|
311
|
-
<div style='position:relative;padding-top:29px;'>
|
312
|
-
<span style='position: absolute;top:0px;z-index:2;color:#000;white-space:nowrap;text-overflow:ellipsis;word-wrap: break-word;overflow: hidden;display: inline-block;padding: 3px;border-radius: 4px;max-width: 100%;'><a href='#{orig_url}' target='_blank'>#{site_name_and_title}</a></span>
|
313
|
-
<video style='max-width:100%' #{attr} title="#{data[:title]}" controls="" ><source src="#{video_url}"></video>
|
314
|
-
</div>
|
315
|
-
)
|
316
|
-
html = html_v2
|
317
|
-
|
318
|
-
else
|
319
|
-
|
320
|
-
html = "<iframe src=\"#{video_url}\" frameborder=\"0\" title=\"#{data[:title]}\""
|
321
|
-
append_attribute(:width, html, video)
|
322
|
-
append_attribute(:height, html, video)
|
250
|
+
def is_video?
|
251
|
+
data[:type] =~ /video/ &&
|
252
|
+
!Onebox::Helpers.blank?(data[:video])
|
253
|
+
end
|
323
254
|
|
324
|
-
|
325
|
-
|
255
|
+
def is_embedded?
|
256
|
+
data[:html] &&
|
257
|
+
(
|
258
|
+
data[:html]["iframe"] ||
|
259
|
+
WhitelistedGenericOnebox.html_providers.include?(data[:provider_name])
|
260
|
+
)
|
261
|
+
end
|
326
262
|
|
327
|
-
|
328
|
-
|
263
|
+
def article_html
|
264
|
+
layout.to_html
|
329
265
|
end
|
330
|
-
end
|
331
266
|
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
267
|
+
def image_html
|
268
|
+
src = data[:image] || data[:thumbnail_url]
|
269
|
+
return if Onebox::Helpers.blank?(src)
|
270
|
+
|
271
|
+
alt = data[:description] || data[:title]
|
272
|
+
width = data[:image_width] || data[:thumbnail_width]
|
273
|
+
height = data[:image_height] || data[:thumbnail_height]
|
274
|
+
"<img src='#{src}' alt='#{alt}' width='#{width}' height='#{height}'>"
|
336
275
|
end
|
337
|
-
end
|
338
276
|
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
277
|
+
def video_html
|
278
|
+
if data[:video_type] == "video/mp4"
|
279
|
+
<<-HTML
|
280
|
+
<video title='#{data[:title]}'
|
281
|
+
width='#{data[:video_width]}'
|
282
|
+
height='#{data[:video_height]}'
|
283
|
+
style='max-width:100%'
|
284
|
+
controls=''>
|
285
|
+
<source src='#{data[:video]}'>
|
286
|
+
</video>
|
287
|
+
HTML
|
288
|
+
else
|
289
|
+
<<-HTML
|
290
|
+
<iframe src='#{data[:video]}'
|
291
|
+
title='#{data[:title]}'
|
292
|
+
width='#{data[:video_width]}'
|
293
|
+
height='#{data[:video_height]}'
|
294
|
+
frameborder='0'>
|
295
|
+
</iframe>
|
296
|
+
HTML
|
344
297
|
end
|
345
298
|
end
|
346
299
|
|
347
|
-
|
348
|
-
|
300
|
+
def embedded_html
|
301
|
+
fragment = Nokogiri::HTML::fragment(data[:html])
|
302
|
+
fragment.css("img").each { |img| img["class"] = "thumbnail" }
|
303
|
+
fragment.to_html
|
304
|
+
end
|
349
305
|
end
|
350
306
|
end
|
351
307
|
end
|