public
Description: Blog Modules for CMS Made Simple 2.0
Homepage: http://cmsmadesimple.org
Clone URL: git://github.com/tedkulp/cmsms-blog.git
Added rss display, with different feed for just categories
Added auto feed to header, with different feed showing if you're viewing 
the page of a particular category


git-svn-id: http://svn.cmsmadesimple.org/svn/blog/trunk@17 
b11ec80d-081b-0410-a2d1-923984365dec
wishy (author)
Sat Mar 08 14:32:18 -0800 2008
commit  45e6bc007ff3c2a1dd558118c8e484be1cf61dff
tree    51b7c5f1447a9faae2ec099d150d47de2fc175fb
parent  629b1e4a2a890a0702225c2287f6dae0ed5769b5
...
67
68
69
70
 
 
 
71
72
73
...
78
79
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
82
83
...
181
182
183
184
185
186
187
188
189
190
 
 
 
 
 
 
 
191
192
193
194
 
 
 
195
196
197
198
 
 
 
199
200
 
201
202
203
204
205
206
207
208
209
210
211
212
 
 
 
 
 
 
 
213
214
215
216
 
 
 
217
218
 
219
220
221
222
 
 
 
223
224
225
226
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
228
229
...
67
68
69
 
70
71
72
73
74
75
...
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
...
209
210
211
 
 
 
 
 
 
 
212
213
214
215
216
217
218
219
 
 
 
220
221
222
223
 
 
 
224
225
226
227
 
228
229
230
231
232
233
 
 
 
 
 
 
 
234
235
236
237
238
239
240
241
 
 
 
242
243
244
245
 
246
247
 
 
 
248
249
250
251
 
 
 
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
0
@@ -67,7 +67,9 @@ class Blog extends CmsModuleBase
0
     
0
     $this->register_module_plugin('blog');
0
 
0
- $this->register_route('/blog\/category\/(?P<category>[a-zA-Z\-_\ ]+)$/', array('action' => 'list_by_category'));
0
+ $this->register_route('/blog\/rss\.xml$/', array('action' => 'default', 'rss' => true, 'showtemplate' => false));
0
+ $this->register_route('/blog\/category\/(?P<category>[a-zA-Z\-_\ ]+)\.xml$/', array('action' => 'list_by_category', 'rss' => true, 'showtemplate' => false));
0
+ $this->register_route('/blog\/category\/(?P<category>[a-zA-Z\-_\ ]+)$/', array('action' => 'list_by_category'));
0
     $this->register_route('/blog\/(?P<url>[0-9]{4}\/[0-9]{2}\/[0-9]{2}\/.*?)$/', array('action' => 'detail'));
0
     $this->register_route('/blog\/(?P<year>[0-9]{4})$/', array('action' => 'filter_list', 'month' => '-1', 'day' => '-1'));
0
     $this->register_route('/blog\/(?P<year>[0-9]{4})\/(?P<month>[0-9]{2})$/', array('action' => 'filter_list', 'day' => '-1'));
0
@@ -78,6 +80,32 @@ class Blog extends CmsModuleBase
0
     $this->add_xmlrpc_method('getPost', 'metaWeblog');
0
     $this->add_xmlrpc_method('newPost', 'metaWeblog');
0
     $this->add_xmlrpc_method('editPost', 'metaWeblog');
0
+
0
+ $this->add_temp_event_handler('Core', 'HeaderTagRender', 'handle_header_callback');
0
+ }
0
+
0
+ public function handle_header_callback($modulename, $eventname, &$params)
0
+ {
0
+ //We only add this link if another action hasn't done so already -- view by category does it's own thing, for example.
0
+ if (!$this->has_added_header_text())
0
+ $params['content'] .= '<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="' . $this->generate_rss_link() . '" />' . "\n";
0
+ }
0
+
0
+ protected function generate_rss_link($params = array(), $category = '')
0
+ {
0
+ $pretty_url = 'blog/rss.xml';
0
+ if ($category != '')
0
+ {
0
+ $pretty_url = 'blog/category/' . $category . '.xml';
0
+ if (!array_key_exists('category', $params))
0
+ $params['category'] = $category;
0
+ }
0
+ return $this->create_link('cntnt01', 'rss', $this->get_default_return_id(), '', $params, '', true, false, '', false, $pretty_url);
0
+ }
0
+
0
+ private function get_default_return_id()
0
+ {
0
+ return cmsms()->get('pageinfo')->return_id;
0
   }
0
   
0
   public function getRecentPosts($blog_id, $username, $password, $number_of_posts)
0
@@ -181,49 +209,71 @@ class Blog extends CmsModuleBase
0
   public function get_default_summary_template()
0
   {
0
     return '{foreach from=$posts item=entry}
0
- <h3><a href="{$entry->url}">{$entry->title}</a></h3>
0
- <small>
0
- {$entry->post_date}
0
- {if $entry->author ne null}
0
- {mod_lang string=by} {$entry->author->full_name()}
0
- {/if}
0
- </small>
0
+<h3><a href="{$entry->url}">{$entry->title}</a></h3>
0
+<small>
0
+ {$entry->post_date}
0
+ {if $entry->author ne null}
0
+ {mod_lang string=by} {$entry->author->full_name()}
0
+ {/if}
0
+</small>
0
 
0
- <div>
0
- {$entry->get_summary_for_frontend()}
0
- </div>
0
+<div>
0
+{$entry->get_summary_for_frontend()}
0
+</div>
0
 
0
- {if $entry->has_more() eq true}
0
- <a href="{$entry->url}">{mod_lang string=hasmore} &gt;&gt;</a>
0
- {/if}
0
+{if $entry->has_more() eq true}
0
+ <a href="{$entry->url}">{mod_lang string=hasmore} &gt;&gt;</a>
0
+{/if}
0
 
0
- {/foreach}';
0
+{/foreach}';
0
   }
0
   
0
   public function get_default_detail_template()
0
   {
0
     return '{if $post ne null}
0
- <h3>{$post->title}</h3>
0
- <small>
0
- {$post->post_date}
0
- {if $post->author ne null}
0
- {mod_lang string=by} {$post->author->full_name()}
0
- {/if}
0
- </small>
0
+<h3>{$post->title}</h3>
0
+<small>
0
+ {$post->post_date}
0
+ {if $post->author ne null}
0
+ {mod_lang string=by} {$post->author->full_name()}
0
+ {/if}
0
+</small>
0
 
0
- <div>
0
- {$post->content}
0
- </div>
0
+<div>
0
+{$post->content}
0
+</div>
0
 
0
- <hr />
0
+<hr />
0
 
0
- <p>
0
- {cms_module module="comments" module_name="blog" content_id=$post->id}
0
- </p>
0
+<p>
0
+{cms_module module="comments" module_name="blog" content_id=$post->id}
0
+</p>
0
 
0
- {else}
0
- {mod_lang string=postnotfound}
0
- {/if}';
0
+{else}
0
+{mod_lang string=postnotfound}
0
+{/if}';
0
+ }
0
+
0
+ public function get_default_rss_template()
0
+ {
0
+ return '<?xml version="1.0"?>
0
+<rss version="2.0">
0
+ <channel>
0
+ <title>{$sitename|escape}</title>
0
+ <link>{root_url}</link>
0
+ {foreach from=$posts item=entry}
0
+ <item>
0
+ <title><![CDATA[{$entry->title}]]></title>
0
+ <link>{$entry->url}</link>
0
+ <guid>{$entry->url}</guid>
0
+ <pubDate>{$entry->post_date}</pubDate>
0
+ <category><![CDATA[]]></category>
0
+ <description><![CDATA[{$entry->get_summary_for_frontend()}]]></description>
0
+ </item>
0
+ {/foreach}
0
+ </channel>
0
+</rss>
0
+';
0
   }
0
 }
0
 
...
3
4
5
6
 
 
 
 
7
8
9
...
3
4
5
 
6
7
8
9
10
11
12
0
@@ -3,7 +3,10 @@ if (!isset($gCms)) die("Can't call actions directly!");
0
 
0
 $smarty->assign('posts', cms_orm('BlogPost')->find_all(array('order' => 'id desc', 'conditions' => array('status = ?', 'publish'))));
0
 
0
-echo $this->process_template_from_database($id, $return_id, 'summary');
0
+if (coalesce_key($params, 'rss', false) == true)
0
+ echo $this->process_template_from_database($id, $return_id, 'rss');
0
+else
0
+ echo $this->process_template_from_database($id, $return_id, 'summary');
0
 
0
 # vim:ts=4 sw=4 noet
0
 ?>
...
9
10
11
 
 
12
13
14
 
 
 
 
15
16
17
18
...
9
10
11
12
13
14
15
 
16
17
18
19
20
21
22
23
0
@@ -9,9 +9,14 @@ if ($category != null)
0
   $posts = $category->published_posts;
0
 }
0
 
0
+$this->add_header_text('<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="' . $this->generate_rss_link(array(), $params['category']) . '" />');
0
+
0
 $smarty->assign('posts', $posts);
0
 
0
-echo $this->process_template_from_database($id, $return_id, 'summary');
0
+if (coalesce_key($params, 'rss', false) == true)
0
+ echo $this->process_template_from_database($id, $return_id, 'rss');
0
+else
0
+ echo $this->process_template_from_database($id, $return_id, 'summary');
0
 
0
 # vim:ts=4 sw=4 noet
0
 ?>
0
\ No newline at end of file
...
37
38
39
 
40
41
42
...
37
38
39
40
41
42
43
0
@@ -37,6 +37,7 @@ $this->create_table('blog_post_categories', "
0
 
0
 $this->set_template('summary', 'Default Template', $this->get_default_summary_template());
0
 $this->set_template('detail', 'Default Template', $this->get_default_detail_template());
0
+$this->set_template('rss', 'Default Template', $this->get_default_rss_template());
0
 
0
 $category = new BlogCategory();
0
 $category->name = 'General';

Comments

    No one has commented yet.