Changeset 37413 for platform/tdiary
- Timestamp:
- 05/07/10 01:44:49 (3 years ago)
- Files:
-
- 1 modified
-
platform/tdiary/plugin/blackbird-pie.rb (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
platform/tdiary/plugin/blackbird-pie.rb
r37408 r37413 3 3 # blackbird-pie.rb - BlackBird plugin for tDiary 4 4 # 5 # Copyright (C) 20 09, hb <smallstyle@gmail.com>5 # Copyright (C) 2010, hb <smallstyle@gmail.com> 6 6 # 7 7 # usage: … … 16 16 require 'rexml/document' 17 17 require 'time' 18 require 'uri' 18 19 19 20 def twitter_statuses_show_api( tweet_id ) … … 34 35 35 36 def blackbird_pie( src ) 36 if %r|http://twitter.com/ (.{1,15})/status(es)?/([0-9]{3,15})|i =~ src.to_s37 src = $ 337 if %r|http://twitter.com/[^/]{1,15}/status(?:es)?/([0-9]+)| =~ src.to_s.downcase 38 src = $1 38 39 end 39 40 return unless / ([0-9]{3,15})/i=~ src.to_s40 41 return unless /\A[0-9]+\z/ =~ src.to_s 41 42 42 43 cache = "#{@cache_path}/blackbird.pstore" … … 45 46 db = PStore.new( cache ) 46 47 db.transaction do 47 key = src 48 key = src 48 49 db[key] ||= {} 49 50 if db[key][:xml] … … 60 61 61 62 doc = REXML::Document::new( REXML::Source.new( xml ) ).root 62 63 63 64 tweet_id = doc.elements['//id'].text 64 65 screen_name = doc.elements['//user/screen_name'].text … … 70 71 timestamp = Time.parse( doc.elements['//created_at'].text ).to_s 71 72 content = doc.elements['//text'].text 72 content.gsub!( %r|(http://\S+)| ){ %Q|<a href="#{$1}">#{$1}</a>| } 73 content.gsub!( /@([a-z0-9_-]{1,15})/ ){ %Q|<a href="http://twitter.com/#{$1}">@#{$1}</a>| } 74 content.gsub!( /\s*\#([a-zA-Z0-9]*)[\s\r]*/ ){ %Q|<a href="http://twitter.com/search?q=%23#{$1}">##{$1}</a>| } 75 73 content.gsub!( URI.regexp( %w|http https| ) ){ %Q|<a href="#{$&}">#{$&}</a>| } 74 content = content.split( /(<[^>]*>)/ ).map do |s| 75 next s if s[/\A</] 76 s.gsub!( /@(?>([a-zA-Z0-9_]{1,15}))(?![a-zA-Z0-9_])/ ){ %Q|<a href="http://twitter.com/#{$1}">#{$&}</a>| } 77 s.gsub( /#([a-zA-Z0-9]{1,16})/ ){ %Q|<a href="http://twitter.com/search?q=%23#{$1}">#{$&}</a>| } 78 end.join 79 76 80 r = <<-HTML 77 81 <!-- http://twitter.com/#{screen_name}/status/#{tweet_id} --> 78 82 <div class="bbpBox" style= 79 83 "background:url(#{background_url}) #{profile_background_color};padding:20px;"> 80 <p class= 'bbpTweet'style=84 <p class="bbpTweet" style= 81 85 "background:#fff;padding:10px 12px 10px 12px;margin:0;min-height:48px;color:#000;font-size:16px !important;line-height:22px;-moz-border-radius:5px;-webkit-border-radius:5px;"> 82 86 #{content} <span class="bbpTimestamp" style= … … 88 92 "http://twitter.com/#{screen_name}"><img alt="#{name}" src= 89 93 "#{avatar}" style= 90 "float:left;margin:0 7px 0 0 px;width:38px;height:38px;"></a>94 "float:left;margin:0 7px 0 0;width:38px;height:38px;"></a> 91 95 <strong><a href= 92 96 "http://twitter.com/#{screen_name}">#{screen_name}</a></strong><br>
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)