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:
- 6606 Bytes
1 | # BlogRequest is a fake Request object, created so blog.url_for will work. |
2 | class BlogRequest |
3 | |
4 | attr_accessor :protocol, :host_with_port, :path, :symbolized_path_parameters, :relative_url_root |
5 | |
6 | def initialize(root) |
7 | @protocol = @host_with_port = @path = '' |
8 | @symbolized_path_parameters = {} |
9 | @relative_url_root = root.gsub(%r{/^},'') |
10 | end |
11 | end |
12 | |
13 | # The Blog class represents one blog. It stores most configuration settings |
14 | # and is linked to most of the assorted content classes via has_many. |
15 | # |
16 | # Typo decides which Blog object to use by searching for a Blog base_url that |
17 | # matches the base_url computed for each request. |
18 | class Blog < CachedModel |
19 | include ConfigManager |
20 | |
21 | has_many :contents |
22 | has_many :trackbacks |
23 | has_many :articles |
24 | has_many :comments |
25 | has_many :pages, :order => "id DESC" |
26 | has_many(:published_articles, :class_name => "Article", |
27 | :conditions => {:published => true}, |
28 | :include => [:categories, :tags], |
29 | :order => "contents.published_at DESC") do |
30 | def before(date = Time.now) |
31 | find(:all, :conditions => ["contents.created_at < ?", date]) |
32 | end |
33 | end |
34 | |
35 | has_many :pages |
36 | has_many :comments |
37 | has_many :sidebars, :order => 'active_position ASC' |
38 | |
39 | serialize :settings, Hash |
40 | |
41 | # Description |
42 | setting :blog_name, :string, 'My Shiny Weblog!' |
43 | setting :blog_subtitle, :string, '' |
44 | setting :title_prefix, :integer, 0 |
45 | setting :geourl_location, :string, '' |
46 | setting :canonical_server_url, :string, '' # Deprecated |
47 | |
48 | # Spam |
49 | setting :sp_global, :boolean, false |
50 | setting :sp_article_auto_close, :integer, 0 |
51 | setting :sp_allow_non_ajax_comments, :boolean, true |
52 | setting :sp_url_limit, :integer, 0 |
53 | setting :sp_akismet_key, :string, '' |
54 | |
55 | # Podcasting |
56 | setting :itunes_explicit, :boolean, false |
57 | setting :itunes_author, :string, '' |
58 | setting :itunes_subtitle, :string, '' |
59 | setting :itunes_summary, :string, '' |
60 | setting :itunes_owner, :string, '' |
61 | setting :itunes_email, :string, '' |
62 | setting :itunes_name, :string, '' |
63 | setting :itunes_copyright, :string, '' |
64 | |
65 | # Mostly Behaviour |
66 | setting :text_filter, :string, '' |
67 | setting :comment_text_filter, :string, '' |
68 | setting :limit_article_display, :integer, 10 |
69 | setting :limit_rss_display, :integer, 10 |
70 | setting :default_allow_pings, :boolean, false |
71 | setting :default_allow_comments, :boolean, true |
72 | setting :default_moderate_comments, :boolean, false |
73 | setting :link_to_author, :boolean, false |
74 | setting :show_extended_on_rss, :boolean, true |
75 | setting :theme, :string, 'azure' |
76 | setting :use_gravatar, :boolean, false |
77 | setting :global_pings_disable, :boolean, false |
78 | setting :ping_urls, :string, "http://rpc.technorati.com/rpc/ping\nhttp://ping.blo.gs/\nhttp://rpc.weblogs.com/RPC2" |
79 | setting :send_outbound_pings, :boolean, true |
80 | setting :email_from, :string, 'typo@example.com' |
81 | |
82 | # Jabber config |
83 | setting :jabber_address, :string, '' |
84 | setting :jabber_password, :string, '' |
85 | |
86 | def initialize(*args) |
87 | super |
88 | # Yes, this is weird - PDC |
89 | begin |
90 | self.settings ||= {} |
91 | rescue Exception => e |
92 | self.settings = {} |
93 | end |
94 | end |
95 | |
96 | # Find the Blog that matches a specific base URL. If no Blog object is found |
97 | # that matches, then grab the default blog. If *that* fails, then create a new |
98 | # Blog. The last case should only be used when Typo is first installed. |
99 | def self.find_blog(base_url) |
100 | (Blog.find_by_base_url(base_url) rescue nil)|| Blog.default || Blog.new |
101 | end |
102 | |
103 | # The default Blog. This is the lowest-numbered blog, almost always id==1. |
104 | def self.default |
105 | find(:first, :order => 'id') |
106 | end |
107 | |
108 | def ping_article!(settings) |
109 | settings[:blog_id] = self.id |
110 | article_id = settings[:id] |
111 | settings.delete(:id) |
112 | trackback = published_articles.find(article_id).trackbacks.create!(settings) |
113 | end |
114 | |
115 | # Check that all required blog settings have a value. |
116 | def is_ok? |
117 | settings.has_key?('blog_name') |
118 | end |
119 | |
120 | # The +Theme+ object for the current theme. |
121 | def current_theme |
122 | @cached_theme ||= Theme.find(theme) |
123 | end |
124 | |
125 | # Generate a URL based on the +base_url+. This allows us to generate URLs |
126 | # without needing a controller handy, so we can produce URLs from within models |
127 | # where appropriate. |
128 | # |
129 | # It also uses our new RouteCache, so repeated URL generation requests should be |
130 | # fast, as they bypass all of Rails' route logic. |
131 | def url_for(options = {}, *extra_params) |
132 | case options |
133 | when String then options # They asked for 'url_for "/some/path"', so return it unedited. |
134 | when Hash |
135 | unless RouteCache[options] |
136 | options.reverse_merge!(:only_path => true, :controller => '/articles', |
137 | :action => 'permalink') |
138 | # Remove internal semi-hack that valiantly attempts to isolate |
139 | # code from needing a Controller but does so at the expense of |
140 | # assuming protocol and port, based on the admin-set blog base |
141 | # URL. Replace it with global (ugh) set in prime_url_writer, |
142 | # a before_filter in application.rb. |
143 | # |
144 | # @url ||= ActionController::UrlRewriter.new(BlogRequest.new(self.base_url), {}) |
145 | @url ||= ActionController::UrlRewriter.new($url_writer_request_information, {}) |
146 | RouteCache[options] = @url.rewrite(options) |
147 | end |
148 | |
149 | return RouteCache[options] |
150 | else |
151 | raise "Invalid URL in url_for: #{options.inspect}" |
152 | end |
153 | end |
154 | |
155 | # The URL for a static file. |
156 | def file_url(filename) |
157 | "#{base_url}/files/#{filename}" |
158 | end |
159 | |
160 | # The base server URL. |
161 | def server_url |
162 | base_url |
163 | end |
164 | |
165 | # Deprecated |
166 | def canonical_server_url |
167 | typo_deprecated "Use base_url instead" |
168 | base_url |
169 | end |
170 | |
171 | def [](key) # :nodoc: |
172 | typo_deprecated "Use blog.#{key}" |
173 | self.send(key) |
174 | end |
175 | |
176 | def []=(key, value) # :nodoc: |
177 | typo_deprecated "Use blog.#{key}=" |
178 | self.send("#{key}=", value) |
179 | end |
180 | |
181 | def has_key?(key) # :nodoc: |
182 | typo_deprecated "Why?" |
183 | self.class.fields.has_key?(key.to_s) |
184 | end |
185 | |
186 | def find_already_published(content_type) # :nodoc: |
187 | typo_deprecated "Use #{content_type}.find_already_published" |
188 | self.send(content_type).find_already_published |
189 | end |
190 | |
191 | def current_theme_path # :nodoc: |
192 | typo_deprecated "use current_theme.path" |
193 | Theme.themes_root + "/" + theme |
194 | end |
195 | end |
196 |