Permalink
Browse files

Added the summary view for the front end

git-svn-id: http://svn.cmsmadesimple.org/svn/blog/trunk@4 b11ec80d-081b-0410-a2d1-923984365dec
  • Loading branch information...
wishy
wishy committed Feb 19, 2008
1 parent 90258d6 commit 46afb499fee73856100384973ccaaf91440e7beb
Showing with 66 additions and 1 deletion.
  1. +24 −0 Blog.module.php
  2. +9 −0 action.default.php
  3. +32 −0 class.blog_post.php
  4. +1 −1 method.install.php
View
@@ -59,6 +59,8 @@ function setup()
{
$this->register_data_object('BlogPost');
$this->register_data_object('BlogCategory');
+
+ $this->register_module_plugin('blog');
}
public function get_categories($add_any = false)
@@ -90,6 +92,28 @@ public function get_statuses($add_any = false)
$result['publish'] = $this->lang('published');
return $result;
}
+
+ public function get_default_summary_template()
+ {
+ return "{foreach from=$posts item=entry}
+ <h3>{$entry->title}</h3>
+ <small>
+ {$entry->post_date}
+ {if $entry->author ne null}
+ by {$entry->author->full_name()}
+ {/if}
+ </small>
+
+ <div>
+ {$entry->summary()}
+ </div>
+
+ {if $entry->has_more() eq true}
+ <a href="{$entry->detailurl}">{tr}hasmore{/tr} &gt;&gt;</a>
+ {/if}
+
+ {/foreach}";
+ }
}
# vim:ts=4 sw=4 noet
View
@@ -0,0 +1,9 @@
+<?php
+if (!isset($gCms)) die("Can't call actions directly!");
+
+$smarty->assign('posts', cms_orm('BlogPost')->find_all(array('order' => 'id desc', 'conditions' => array('status = ?', 'publish'))));
+
+echo $this->process_template_from_database($id, $return_id, 'summary');
+
+# vim:ts=4 sw=4 noet
+?>
View
@@ -27,6 +27,38 @@ function __construct()
parent::__construct();
}
+ function setup()
+ {
+ $this->create_belongs_to_association('author', 'CmsUser', 'author_id');
+ }
+
+ function split_content()
+ {
+ return preg_split("/<!--\ ?more\ ?-->/i", $this->content);
+ }
+
+ function has_more()
+ {
+ return $this->summary != '' || count($this->split_content()) > 1;
+ }
+
+ function summary()
+ {
+ $result = '';
+
+ if ($this->summary != '')
+ {
+ $result = $this->summary;
+ }
+ else
+ {
+ $parts = $this->split_content();
+ $result = $parts[0];
+ }
+
+ return $result;
+ }
+
function validate()
{
$this->validate_not_blank('title', lang('nofieldgiven',array(lang('title'))));
View
@@ -29,7 +29,7 @@
modified_date T
");
-$this->set_template('summary', 'Default Template', '<p>Placeholder</p>');
+$this->set_template('summary', 'Default Template', $this->get_default_summary_template());
$this->set_template('detail', 'Default Template', '<p>Placeholder</p>');
$category = new BlogCategory();

0 comments on commit 46afb49

Please sign in to comment.