2424require 'json'
2525
2626def twitter_quote_option_keys
27- %w( consumer_key consumer_secret token token_secret ) . map { |k | "twitter_quote.oauth_ #{ k } " }
27+ %w( oauth_consumer_key oauth_consumer_secret oauth_token oauth_token_secret, render_method ) . map { |k | "twitter_quote.#{ k } " }
2828end
2929
3030def twitter_statuses_show_api ( tweet_id )
@@ -61,24 +61,17 @@ def twitter_statuses_show_api( tweet_id )
6161 end
6262end
6363
64- def twitter_status_json_to_html ( json )
65- tweet_id = json [ 'id_str' ]
66- screen_name = json [ 'user' ] [ 'screen_name' ]
67- name = json [ 'user' ] [ 'name' ]
68- background_url = json [ 'user' ] [ 'profile_background_image_url' ]
69- profile_background_color = "##{ json [ 'user' ] [ 'profile_background_color' ] } "
70- avatar = json [ 'user' ] [ 'profile_image_url' ]
71- source = json [ 'source' ]
72- timestamp = Time . parse ( json [ 'created_at' ] )
73- content = json [ 'text' ]
74- content . gsub! ( URI . regexp ( %w| http https | ) ) { %Q|<a href="#{ $&} ">#{ $&} </a>| }
75- content = content . split ( /(<[^>]*>)/ ) . map { |s |
76- next s if s [ /\A </ ]
77- s . gsub! ( /@(?>([a-zA-Z0-9_]{1,15}))(?![a-zA-Z0-9_])/ ) { %Q|<a href="http://twitter.com/#{ $1} ">#{ $&} </a>| }
78- s . gsub ( /#([a-zA-Z0-9]{1,16})/ ) { %Q|<a href="http://twitter.com/search?q=%23#{ $1} ">#{ $&} </a>| }
79- } . join
80-
81- <<-HTML
64+ def render_widget ( tweet_id , screen_name , name , background_url , profile_backgound_color , avatar , source , timestamp , content )
65+ <<-HTML
66+ < blockquote class ="twitter-tweet "> < p > #{ content } </ p>
67+ — #{ @name } (#{ @screen_name } ) < a href ="http://twitter.com/ #{ screen_name } /status/#{ tweet_id } "> #{ timestamp } </ a>
68+ </ blockquote>
69+ < script async src ="//platform.twitter.com/widgets.js " charset ="utf-8 "> </ script >
70+ HTML
71+ end
72+
73+ def render_bbp ( tweet_id , screen_name , name , background_url , profile_backgound_color , avatar , source , timestamp , content )
74+ <<-HTML
8275 <!-- http://twitter.com/#{ screen_name } /status/#{ tweet_id } -->
8376 < div class ="bbpBox " style ="background:url( #{ background_url } ) #{ profile_background_color } ;padding:20px;">
8477 < p class ="bbpTweet " style =
@@ -105,6 +98,30 @@ def twitter_status_json_to_html( json )
10598 HTML
10699end
107100
101+ def twitter_status_json_to_html ( json )
102+ tweet_id = json [ 'id_str' ]
103+ screen_name = json [ 'user' ] [ 'screen_name' ]
104+ name = json [ 'user' ] [ 'name' ]
105+ background_url = json [ 'user' ] [ 'profile_background_image_url' ]
106+ profile_background_color = "##{ json [ 'user' ] [ 'profile_background_color' ] } "
107+ avatar = json [ 'user' ] [ 'profile_image_url' ]
108+ source = json [ 'source' ]
109+ timestamp = Time . parse ( json [ 'created_at' ] )
110+ content = json [ 'text' ]
111+ content . gsub! ( URI . regexp ( %w| http https | ) ) { %Q|<a href="#{ $&} ">#{ $&} </a>| }
112+ content = content . split ( /(<[^>]*>)/ ) . map { |s |
113+ next s if s [ /\A </ ]
114+ s . gsub! ( /@(?>([a-zA-Z0-9_]{1,15}))(?![a-zA-Z0-9_])/ ) { %Q|<a href="http://twitter.com/#{ $1} ">#{ $&} </a>| }
115+ s . gsub ( /#([a-zA-Z0-9]{1,16})/ ) { %Q|<a href="http://twitter.com/search?q=%23#{ $1} ">#{ $&} </a>| }
116+ } . join
117+
118+ if @conf [ 'twitter_quote.render_method' ] == 'widget'
119+ render_widget ( tweet_id , screen_name , name , background_url , profile_backgound_color , avatar , source , timestamp , content )
120+ else
121+ render_bbp ( tweet_id , screen_name , name , background_url , profile_backgound_color , avatar , source , timestamp , content )
122+ end
123+ end
124+
108125def tweet_quote ( src )
109126 return unless twitter_quote_option_keys . all? { |v | @options . key? v }
110127
@@ -152,6 +169,12 @@ def tweet_quote( src )
152169 < p > < input type ="text " name ="twitter_quote.oauth_token " value ="#{ h @conf [ "twitter_quote.oauth_token" ] } " size="80"> </ p>
153170 < h3 > Access token secret</ h3 >
154171 < p > < input type ="text " name ="twitter_quote.oauth_token_secret " value ="#{ h @conf [ "twitter_quote.oauth_token_secret" ] } " size="80"> </ p>
172+ < h3 > Render method</ h3 >
173+ < select name ="twitter_quote.render_method ">
174+ < option value ="bbp "#{ ' selected' if @conf [ 'twitter_quote.render_method' ] == 'bbp' } > Bbp</ option>
175+ < option value ="widget "#{ ' selected' if @conf [ 'twitter_quote.render_method' ] == 'widget' } > Widget</ option>
176+ </ select>
177+ </ p>
155178 HTML
156179end
157180
0 commit comments