public
Description: Blog Modules for CMS Made Simple 2.0
Homepage: http://cmsmadesimple.org
Clone URL: git://github.com/tedkulp/cmsms-blog.git
Added detail action
Added RESTful filtering of posts


git-svn-id: http://svn.cmsmadesimple.org/svn/blog/trunk@7 
b11ec80d-081b-0410-a2d1-923984365dec
wishy (author)
Tue Feb 19 16:08:13 -0800 2008
commit  36d2dfa4496497f07155efe4b407dcb811d992d9
tree    010e59c88b05a0a395600518f2e40907c850f37e
parent  e79a1c477da40ebeb533d312f439236c07915a1b
...
61
62
63
 
 
 
 
 
 
64
65
66
...
95
96
97
98
99
 
 
100
101
102
103
 
104
105
106
107
108
 
109
110
111
112
 
113
114
115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
117
118
...
61
62
63
64
65
66
67
68
69
70
71
72
...
101
102
103
 
 
104
105
106
107
108
 
109
110
111
112
113
 
114
115
116
117
 
118
119
120
 
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
0
@@ -61,6 +61,12 @@ class Blog extends CmsModuleBase
0
     $this->register_data_object('BlogCategory');
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\/(?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
+ $this->register_route('/blog\/(?P<year>[0-9]{4})\/(?P<month>[0-9]{2})\/(?P<day>[0-9]{2})$/', array('action' => 'filter_list'));
0
   }
0
   
0
   public function get_categories($add_any = false)
0
@@ -95,24 +101,49 @@ class Blog extends CmsModuleBase
0
   
0
   public function get_default_summary_template()
0
   {
0
- return "{foreach from=$posts item=entry}
0
- <h3>{$entry->title}</h3>
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
- by {$entry->author->full_name()}
0
+ {mod_lang string=by} {$entry->author->full_name()}
0
      {/if}
0
     </small>
0
 
0
     <div>
0
- {$entry->summary()}
0
+ {$entry->get_summary_for_frontend()}
0
     </div>
0
 
0
     {if $entry->has_more() eq true}
0
- <a href=\"{$entry->detailurl}\">{tr}hasmore{/tr} &gt;&gt;</a>
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
+
0
+ <div>
0
+ {$post->content}
0
+ </div>
0
+
0
+ <hr />
0
+
0
+ <p>
0
+ Comments Go Here
0
+ </p>
0
+ {else}
0
+ {mod_lang string=postnotfound}
0
+ {/if}';
0
   }
0
 }
0
 
...
39
40
41
42
 
43
44
45
 
46
47
48
49
 
50
51
 
52
53
54
...
59
60
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
63
64
...
70
71
72
73
 
74
75
76
 
77
78
 
 
 
 
 
 
 
 
79
80
81
...
39
40
41
 
42
43
44
 
45
46
47
48
 
49
50
 
51
52
53
54
...
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
...
86
87
88
 
89
90
91
 
92
93
94
95
96
97
98
99
100
101
102
103
104
105
0
@@ -39,16 +39,16 @@ class BlogPost extends CmsObjectRelationalMapping
0
   
0
   function has_more()
0
   {
0
- return $this->summary != '' || count($this->split_content()) > 1;
0
+ return $this->params['summary'] != '' || count($this->split_content()) > 1;
0
   }
0
   
0
- function summary()
0
+ function get_summary_for_frontend()
0
   {
0
     $result = '';
0
 
0
- if ($this->summary != '')
0
+ if ($this->params['summary'] != '')
0
     {
0
- $result = $this->summary;
0
+ $result = $this->params['summary'];
0
     }
0
     else
0
     {
0
@@ -59,6 +59,22 @@ class BlogPost extends CmsObjectRelationalMapping
0
     return $result;
0
   }
0
   
0
+ function get_url()
0
+ {
0
+ $smarty = cms_smarty();
0
+ $module = $smarty->get_template_vars('cms_mapi_module');
0
+ if ($module != null && $module instanceof Blog)
0
+ {
0
+ $id = $smarty->get_template_vars('cms_mapi_id');
0
+ $return_id = $smarty->get_template_vars('cms_mapi_return_id');
0
+ return $module->create_link($id, 'detail', $return_id, '', array('post_id' => $this->id), '', true, false, '', false, 'blog/' . $this->params['url']);
0
+ }
0
+ else
0
+ {
0
+ return $this->params['url'];
0
+ }
0
+ }
0
+
0
   function validate()
0
   {
0
     $this->validate_not_blank('title', lang('nofieldgiven',array(lang('title'))));
0
@@ -70,12 +86,20 @@ class BlogPost extends CmsObjectRelationalMapping
0
   function before_validation()
0
   {
0
     //if this is the first save of this post, generate a decent slug
0
- if ($this->slug == '')
0
+ if ($this->slug == '' || $this->url == '')
0
     {
0
       $this->slug = munge_string_to_url($this->title, true);
0
- $this->url = $this->post_date->format('Y') . '/' . $this->post_date->format('m') . '/' . $this->post_date->format('d') . '/' . $this->slug;
0
+ $this->url = $this->post_date->format('Y/m/d/') . $this->slug;
0
     }
0
   }
0
+
0
+ function before_save()
0
+ {
0
+ //Make sure the date is split out properly
0
+ $this->post_year = $this->post_date->format('Y');
0
+ $this->post_month = $this->post_date->format('m');
0
+ $this->post_day = $this->post_date->format('d');
0
+ }
0
 }
0
 
0
 # vim:ts=4 sw=4 noet
...
18
19
20
 
 
 
21
22
23
...
18
19
20
21
22
23
24
25
26
0
@@ -18,5 +18,8 @@ $lang['cancel'] = 'Cancel';
0
 $lang['writepost'] = 'Write Post';
0
 $lang['manageposts'] = 'Manage Posts';
0
 $lang['slug'] = 'Slug';
0
+$lang['postnotfound'] = 'Post Not Found';
0
+$lang['by'] = 'by';
0
+$lang['hasmore'] = 'Read the rest of this entry';
0
 
0
 ?>
0
\ No newline at end of file
...
5
6
7
 
 
 
8
9
10
...
31
32
33
34
 
35
36
37
...
5
6
7
8
9
10
11
12
13
...
34
35
36
 
37
38
39
40
0
@@ -5,6 +5,9 @@ $this->create_table('blog_posts', "
0
   id I KEY AUTO,
0
   author_id I,
0
   post_date T,
0
+ post_year I,
0
+ post_month I,
0
+ post_day I,
0
   title C(255),
0
   slug C(255),
0
   url C(255),
0
@@ -31,7 +34,7 @@ $this->create_table('blog_post_categories', "
0
 ");
0
 
0
 $this->set_template('summary', 'Default Template', $this->get_default_summary_template());
0
-$this->set_template('detail', 'Default Template', '<p>Placeholder</p>');
0
+$this->set_template('detail', 'Default Template', $this->get_default_detail_template());
0
 
0
 $category = new BlogCategory();
0
 $category->name = 'General';

Comments

    No one has commented yet.