Top Level Namespace

Defined Under Namespace

Modules: AccountHelper, ActionController, ApplicationHelper, AtomHelper, AuthHelper, BackendHelper, CssHelper, DraftHelper, ImageHelper, LinkHelper, PaginationHelper, PingHelper, PostHelper, RssHelper, TagsHelper, UserHelper, UsersHelper Classes: AccountController, ApplicationController, AtomController, AuthController, BackendController, Comment, CssController, Draft, DraftController, Face, FeedKiller, Image, ImageController, ImageSize, Link, LinkController, Ping, PingController, Post, PostController, RssController, Stylesheet, Tag, TagsController, User, UserController

Instance Method Summary collapse

Instance Method Details

#send_trackback(post, url, app_config) ⇒ Object


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/trackback.rb', line 1

def send_trackback(post, url, app_config)
  require 'uri'
  require 'net/http'
  begin
    uri = URI.parse(url)
    oururi = URI.parse(url_for(:controller => 'ping', :action => 'trackback', :only_path => false))
    if oururi.host == uri.host && oururi.port == uri.port
      # This is the same EJ instance, which may not be able to handle
      # simultaneous connections (webrick), so dump this ping right to the DB
      if /.*\/(\d{1,7})/ =~ url
        origpost       = Post.find($1) rescue nil
        return if origpost.nil?
        ping           = origpost.build_to_pings
        ping.title     = post.subject
        logger.info "LOGGING #{strip_html(post.rendered, false)[0..255]}"
        ping.excerpt   = strip_html(post.rendered, false)[0..255]
        ping.url       = url_for(:controller => 'journal', :action => 'view', :id => post.id, :only_path => false)
        ping.blog_name = post.user.title
        ping.save
      end
      return
    end
    qrystr = "title=#{URI.escape(post.subject)}"
    qrystr << "&excerpt=#{strip_html(post.rendered)[0..255]}"
    qrystr << "&url=#{@request.protocol}#{@request.host_with_port}/journal/view/#{post.id}"
    qrystr << "&blog_name=#{URI.escape(post.user.title)}"

    Net::HTTP.start(uri.host, uri.port) do |http|
      http.post("#{uri.path}?#{uri.query}", qrystr)
      # I don't really care if this fails or not right now.
    end
  rescue
  end
end

#strip_html(text, escape = true) ⇒ Object


36
37
38
39
40
41
42
43
44
45
# File 'lib/trackback.rb', line 36

def strip_html(text, escape=true)
  attribute_key = /[\w:_-]+/
  attribute_value = /(?:[A-Za-z0-9]+|(?:'[^']*?'|"[^"]*?"))/
  attribute = /(?:#{attribute_key}(?:\s*=\s*#{attribute_value})?)/
  attributes = /(?:#{attribute}(?:\s+#{attribute})*)/
  tag_key = attribute_key
  tag = %r{<[!/?\[]?(?:#{tag_key}|--)(?:\s+#{attributes})?\s*(?:[!/?\]]+|--)?>}
  text.gsub(tag, '').gsub(/\s+/, ' ').strip
  escape ? CGI::escape(text) : text
end