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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71f76b700cbeee61a2da9f769fb2c50c266809a4
4
- data.tar.gz: 42258aef7d0cddad2730a8eaf1e3004704be2b71
3
+ metadata.gz: 6284a87a3edbd77cb74a40d458a2774f350ec86d
4
+ data.tar.gz: 2e2e203e7321cd7e453f50e18e3bd73a56ade1e0
5
5
  SHA512:
6
- metadata.gz: 0a6e0d9a253cd2eda029a9e859f161621c93d92e6f6cfefd3528fa4f022d4b57057085510779a2f5d5f212266cc92d5d89a88e0c3f9f7b0072ca7f02cfe2a85e
7
- data.tar.gz: 64bbc89d7885b4c54da395bfcc9a31ea9011badeae4da7d31ee99d552ca401e1f36aaf97e0281306b1c15eb780f577e4f5b51a8b9018e2107d1325502c57f10c
6
+ metadata.gz: af6c86905744a6da99816a166be42e52dd4d785cba77e4e7fa17d4b097262ad7e57ebe27abea5120fcfd2d5db2bff1fdf3a7ba81f1b743616307315fa90fa787
7
+ data.tar.gz: 7e68883159aa1313539b1501689aafd5f6080359d587d7b138c36c5b1f334188a37a9f5b02c150148dbaa48af0f570ad68432842ec37960bfb89d6cead4203e2
data/lib/onebox/engine.rb CHANGED
@@ -164,3 +164,4 @@ require_relative "engine/imgur_onebox"
164
164
  require_relative "engine/steam_store_widget_onebox"
165
165
  require_relative "engine/pastebin_onebox"
166
166
  require_relative "engine/slides_onebox"
167
+ require_relative "engine/xkcd_onebox"
@@ -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['repository_path'] = "#{ulink.host}/#{ulink.path.split('/')[1]}/#{ulink.path.split('/')[2]}"
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
- repository_path: "#{ulink.host}/#{ulink.path.split('/')[1]}/#{ulink.path.split('/')[2]}",
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['repository_path'] = "#{ulink.host}/#{ulink.path.split('/')[1]}/#{ulink.path.split('/')[2]}"
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
- if uri.path =~ /^\/[\p{Alnum}_\-]+\/[\p{Alnum}_\-]+$/
12
- "<iframe src=\"//slides.com#{uri.path}/embed?style=light\" width=\"576\" height=\"420\" scrolling=\"no\" frameborder=\"0\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>"
13
- end
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
- # get_opengraph_data
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 = get_oembed_data[:html]
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
- "<img src='#{get_oembed_data[:thumbnail_url]}'>"
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
- def set?
22
- url =~ /\/sets\//
23
- end
24
-
25
- def get_oembed_data
26
- if set?
27
- Onebox::Helpers.symbolize_keys(::MultiJson.load(Onebox::Helpers.fetch_response("https://soundcloud.com/oembed.json?url=#{url}").body))
28
- else
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
- end
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.push(regexp)
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 /(.*\.)?gfycat\.com\//, 'http://gfycat.com/cajax/oembed'
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
- StandardEmbed.oembed_providers.each do |regexp, endpoint|
39
- if url =~ regexp
40
- fetch_oembed_raw("#{endpoint}?url=#{url}")
41
- return @raw if @raw
42
- end
43
- end
31
+ og = get_opengraph
32
+ twitter = get_twitter
33
+ oembed = get_oembed
44
34
 
45
- response = Onebox::Helpers.fetch_response(url)
46
- html_doc = Nokogiri::HTML(response.body)
35
+ @raw = {}
47
36
 
48
- StandardEmbed.opengraph_providers.each do |regexp|
49
- if url =~ regexp
50
- @raw = parse_open_graph(html_doc, url)
51
- return @raw if @raw
52
- end
53
- end
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
- # Determine if we should use oEmbed or OpenGraph (prefers oEmbed)
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
- open_graph = parse_open_graph(html_doc, url)
61
- if @raw
62
- @raw[:image] = open_graph.images.first if @raw[:image].nil? && open_graph && open_graph.images
63
- return @raw
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
- @raw = open_graph
67
- end
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
- private
56
+ text_json = html_doc.at("//link[@type='text/json+oembed']/@href")
57
+ oembed_url ||= text_json.value if text_json
70
58
 
71
- def fetch_oembed_raw(oembed_url)
72
- return unless oembed_url
73
- oembed_url = oembed_url['href'] unless oembed_url['href'].nil?
74
- oembed_data = Onebox::Helpers.symbolize_keys(::MultiJson.load(Onebox::Helpers.fetch_response(oembed_url).body))
75
- @raw =
76
- if oembed_data[:html] && oembed_data[:html].bytesize > 4000
77
- # fallback to OpenGraph if oEmbed data size is more than 4000 bytes
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
- def parse_open_graph(html, og_url)
87
- og = Struct.new(:url, :type, :title, :description, :images, :metadata, :html).new
88
- og.url = og_url
89
- og.images = []
90
- og.metadata = {}
91
-
92
- attrs_list = %w(title url type description)
93
- html.css('meta').each do |m|
94
- if m.attribute('property') && m.attribute('property').to_s.match(/^og:/i)
95
- # og properties
96
- m_content = m.attribute('content').to_s.strip
97
- m_name = m.attribute('property').to_s.gsub('og:', '')
98
- og.metadata[m_name.to_sym] ||= []
99
- og.metadata[m_name.to_sym].push m_content
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
- if m.attribute('name') && m.attribute('name').to_s.match(/^twitter:/i)
113
- # twitter properties
114
- m_content = m.attribute('content').to_s.strip if m.attribute('content')
115
- m_content = m.attribute('value').to_s.strip if m.attribute('value')
116
- m_name = m.attribute('name').to_s
117
- og.metadata[m_name.to_sym] ||= []
118
- og.metadata[m_name.to_sym].push m_content
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(23hq.com
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
- change.org)
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 coverts http:// -> https://
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
- return WhitelistedGenericOnebox.host_matches(other, WhitelistedGenericOnebox.whitelist) ||
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
- result = nil
230
- return to_html if article_type?
231
- result = image_html if (data[:html] && data[:html] =~ /iframe/) || data[:video] || photo_type?
232
- result || to_html
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
- if raw.is_a?(Hash)
237
- raw[:link] ||= link
238
- raw[:title] = HTMLEntities.new.decode(raw[:title])
239
- return raw
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
- data_hash = { link: link, title: HTMLEntities.new.decode(raw.title), description: raw.description }
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
- if raw.metadata && raw.metadata[:"video:secure_url"] && raw.metadata[:"video:secure_url"].first
247
- data_hash[:video] = raw.metadata[:"video:secure_url"].first
248
- elsif raw.metadata && raw.metadata[:video] && raw.metadata[:video].first
249
- data_hash[:video] = raw.metadata[:video].first
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
- if raw.metadata && raw.metadata[:"twitter:label1"] && raw.metadata[:"twitter:data1"]
253
- data_hash[:twitter_label1] = raw.metadata[:"twitter:label1"].first
254
- data_hash[:twitter_data1] = raw.metadata[:"twitter:data1"].first
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
- if raw.metadata && raw.metadata[:"twitter:label2"] && raw.metadata[:"twitter:data2"]
258
- data_hash[:twitter_label2] = raw.metadata[:"twitter:label2"].first
259
- data_hash[:twitter_data2] = raw.metadata[:"twitter:data2"].first
229
+ def is_article?
230
+ data[:type] =~ /article/ &&
231
+ has_text?
260
232
  end
261
233
 
262
- data_hash
263
- end
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
- @image_html
280
- end
281
-
282
- def html_for_video(video)
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
- if video_url
293
- # opengraph support multiple elements (videos, images ,etc).
294
- # We attempt to find a video element with the type of video/mp4
295
- # and generate a native <video> element for it.
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
- html << "></iframe>"
325
- end
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
- end
328
- return html
263
+ def article_html
264
+ layout.to_html
329
265
  end
330
- end
331
266
 
332
- def append_attribute(attribute, html, video)
333
- if video.is_a?(Hash) && video[attribute] && video[attribute].first
334
- val = video[attribute].first[:_value]
335
- html << " #{attribute.to_s}=\"#{val}\""
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
- def add_thumbnail_class(data)
340
- fragment = Nokogiri::HTML::fragment(data)
341
- if fragment
342
- fragment.search('img').each do |img|
343
- img['class'] = "thumbnail"
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
- return fragment.to_html
348
- end
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