Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 193
- Log:
First stage commit of Typo 4.1, modified for the ROOL site.
Includes all local modifications but a final pass needs to be
made to delete any files left over from earlier Typo versions
that shouldn't be here anymore. See the 'tags' section of the
repository for a clean Typo 4.1 tree.Note that symlinks to shared files in the RISC OS Open theme
directory have been deliberately included this time around; I
decided that on balance it was better to leave them in as
placeholders, since unlike symlinks in app/views/shared, the
Typo theme structure is not a standard Rails concept.
- Author:
- rool
- Date:
- Wed Apr 04 18:51:02 +0100 2007
- Size:
- 3040 Bytes
1 | require 'rexml/document' |
2 | |
3 | class Ping < ActiveRecord::Base |
4 | belongs_to :article |
5 | |
6 | class Pinger |
7 | attr_accessor :article |
8 | attr_accessor :blog |
9 | |
10 | def send_pingback_or_trackback |
11 | begin |
12 | @response = Net::HTTP.get_response(URI.parse(ping.url)) |
13 | send_pingback or send_trackback |
14 | rescue Timeout::Error => err |
15 | return |
16 | rescue => err |
17 | raise err |
18 | # Ignore |
19 | end |
20 | end |
21 | |
22 | def pingback_url |
23 | if @response["X-Pingback"] |
24 | @response["X-Pingback"] |
25 | elsif |
26 | response.body =~ /<link rel="pingback" href="([^"]+)" ?\/?>/ |
27 | $1 |
28 | else |
29 | nil |
30 | end |
31 | end |
32 | |
33 | def origin_url |
34 | @origin_url |
35 | end |
36 | |
37 | def response |
38 | @response |
39 | end |
40 | |
41 | def ping |
42 | @ping |
43 | end |
44 | |
45 | def send_xml_rpc(*args) |
46 | ping.send(:send_xml_rpc, *args) |
47 | end |
48 | |
49 | def trackback_url |
50 | rdfs = response.body.scan(/<rdf:RDF.*?<\/rdf:RDF>/m) |
51 | rdfs.each do |rdf| |
52 | xml = REXML::Document.new(rdf) |
53 | xml.elements.each("//rdf:Description") do |desc| |
54 | if rdfs.size == 1 || desc.attributes["dc:identifier"] == ping.url |
55 | return desc.attributes["trackback:ping"] |
56 | end |
57 | end |
58 | end |
59 | # Didn't find a trackback url, so fall back to the url itself. |
60 | @ping.url |
61 | end |
62 | |
63 | def send_pingback |
64 | if pingback_url |
65 | send_xml_rpc(pingback_url, "pingback.ping", origin_url, ping.url) |
66 | return true |
67 | else |
68 | return false |
69 | end |
70 | end |
71 | |
72 | def send_trackback |
73 | ping.send_trackback(trackback_url, origin_url) |
74 | end |
75 | |
76 | private |
77 | |
78 | def initialize(origin_url, ping) |
79 | @origin_url = origin_url |
80 | @ping = ping |
81 | # Make sure these are fetched now for thread safety purposes. |
82 | self.article = ping.article |
83 | self.blog = article.blog |
84 | end |
85 | end |
86 | |
87 | def send_pingback_or_trackback(origin_url) |
88 | Pinger.new(origin_url, self).send_pingback_or_trackback |
89 | end |
90 | |
91 | def send_trackback(trackback_url, origin_url) |
92 | trackback_uri = URI.parse(trackback_url) |
93 | |
94 | post = "title=#{CGI.escape(article.title)}" |
95 | post << "&excerpt=#{CGI.escape(article.html(:body).strip_html[0..254])}" |
96 | post << "&url=#{origin_url}" |
97 | post << "&blog_name=#{CGI.escape(article.blog.blog_name)}" |
98 | |
99 | Net::HTTP.start(trackback_uri.host, trackback_uri.port) do |http| |
100 | path = trackback_uri.path |
101 | path += "?#{trackback_uri.query}" if trackback_uri.query |
102 | http.post(path, post, 'Content-type' => 'application/x-www-form-urlencoded; charset=utf-8') |
103 | end |
104 | end |
105 | |
106 | def send_weblogupdatesping(server_url, origin_url) |
107 | send_xml_rpc(self.url, "weblogUpdates.ping", article.blog.blog_name, |
108 | server_url, origin_url) |
109 | end |
110 | |
111 | protected |
112 | |
113 | def send_xml_rpc(xml_rpc_url, name, *args) |
114 | begin |
115 | server = XMLRPC::Client.new2(URI.parse(xml_rpc_url).to_s) |
116 | |
117 | begin |
118 | result = server.call(name, *args) |
119 | rescue XMLRPC::FaultException => e |
120 | logger.error(e) |
121 | end |
122 | rescue Exception => e |
123 | logger.error(e) |
124 | end |
125 | end |
126 | end |