From 846eb9c270a5f94462ca8f465283535d15c8a058 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Thu, 5 Mar 2015 11:20:47 +1300 Subject: [PATCH] Break out templates and expand --- code/model/Blog.php | 8 +- code/model/BlogPost.php | 8 +- css/blog.css | 43 +++++++++++ lang/en.yml | 90 ++++++++++++++-------- templates/Includes/BlogSideBar.ss | 5 ++ templates/Includes/EntryMeta.ss | 25 ++++++ templates/Includes/Pagination.ss | 25 ++++++ templates/Layout/Blog.ss | 72 +++++++++++++++++ templates/Layout/BlogPost.ss | 20 +++++ templates/WidgetHolder.ss | 4 + templates/widgets/BlogArchiveWidget.ss | 13 +++- templates/widgets/BlogCategoriesWidget.ss | 11 ++- templates/widgets/BlogRecentPostsWidget.ss | 11 ++- templates/widgets/BlogTagsWidget.ss | 11 ++- 14 files changed, 296 insertions(+), 50 deletions(-) create mode 100755 css/blog.css create mode 100644 templates/Includes/BlogSideBar.ss create mode 100644 templates/Includes/EntryMeta.ss create mode 100644 templates/Includes/Pagination.ss create mode 100644 templates/Layout/Blog.ss create mode 100644 templates/Layout/BlogPost.ss create mode 100644 templates/WidgetHolder.ss mode change 100755 => 100644 templates/widgets/BlogArchiveWidget.ss mode change 100755 => 100644 templates/widgets/BlogCategoriesWidget.ss mode change 100755 => 100644 templates/widgets/BlogRecentPostsWidget.ss mode change 100755 => 100644 templates/widgets/BlogTagsWidget.ss diff --git a/code/model/Blog.php b/code/model/Blog.php index 7b98869..7dbfd46 100644 --- a/code/model/Blog.php +++ b/code/model/Blog.php @@ -274,8 +274,12 @@ class Blog_Controller extends Page_Controller { $posts = new PaginatedList($this->blogPosts); // If pagination is set to '0' then no pagination will be shown. - if($this->PostsPerPage > 0) $posts->setPageLength($this->PostsPerPage); - else $posts->setPageLength($this->getBlogPosts()->count()); + if($this->PostsPerPage > 0) { + $posts->setPageLength($this->PostsPerPage); + } else { + $pageSize = $this->getBlogPosts()->count() ?: 99999; + $posts->setPageLength($pageSize); + } $start = $this->request->getVar($posts->getPaginationGetVar()); $posts->setPageStart($start); diff --git a/code/model/BlogPost.php b/code/model/BlogPost.php index e4b0cb9..1c9ade1 100644 --- a/code/model/BlogPost.php +++ b/code/model/BlogPost.php @@ -41,6 +41,10 @@ class BlogPost extends Page { "Title", ); + private static $casting = array( + 'Excerpt' => 'Text' + ); + private static $allowed_children = array(); private static $default_sort = "PublishDate DESC"; @@ -75,7 +79,7 @@ class BlogPost extends Page { // We're going to add the url segment to sidebar so we're making it a little lighter $urlSegment = $fields->dataFieldByName('URLSegment'); - $urlSegment->setURLPrefix('/' . Director::makeRelative($self->Parent()->Link())); + $urlSegment->setURLPrefix($self->Parent()->RelativeLink()); // Remove the MenuTitle and URLSegment from the main tab $fields->removeFieldsFromTab('Root.Main', array( @@ -117,7 +121,7 @@ class BlogPost extends Page { /** * If no publish date is set, set the date to now. **/ - public function onBeforeWrite() { + protected function onBeforeWrite() { parent::onBeforeWrite(); if(!$this->PublishDate) $this->setCastedField("PublishDate", time()); } diff --git a/css/blog.css b/css/blog.css new file mode 100755 index 0000000..ed5df79 --- /dev/null +++ b/css/blog.css @@ -0,0 +1,43 @@ +.no-sidebar .content-container.size3of4 { + width: 75%; +} + +.blog-entry .post-image img { + width: 98.75%; +} + +.blog-sidebar .WidgetHolder ul { + margin-left: 0; +} + .blog-sidebar .WidgetHolder ul li { + list-style-type: none; + } + +#Form_CommentsForm + h4 { + clear: both; + padding-top: 35px; + display: block; +} + +.typography ul.comments-list { + margin: 0; +} + +.typography ul.comments-list > li { + list-style: none; + border-bottom: 1px solid #e5e5e5; + padding: 10px 0; +} + +.typography ul.comments-list > li .action-links { + margin: 0; +} + +.typography ul.comments-list > li .action-links li { + list-style: none; + margin-right: 10px; +} + +.commenting-rss-feed { + clear: both; +} diff --git a/lang/en.yml b/lang/en.yml index fa656fa..4b94e0e 100755 --- a/lang/en.yml +++ b/lang/en.yml @@ -1,38 +1,62 @@ en: + Blog: + Archive: Archive + Categories: Categories + Category: Category + Comments: Comments + DESCRIPTION: 'Adds a blog to your website.' + LumberjackTitle: 'Blog Posts' + NoPosts: 'There are no posts' + PLURALNAME: Blogs + Posted: Posted + PostedIn: 'Posted in' + PostsPerPage: 'Posts Per Page' + ReadMoreAbout: 'Read more about ''{title}''...' + SINGULARNAME: Blog + Tag: Tag + Tagged: Tagged + Tags: Tags + BlogArchiveWidget: + Blog: Blog + NumberToDisplay: 'No. to Display' + PLURALNAME: 'Blog Archive Widgets' + SINGULARNAME: 'Blog Archive Widget' + Type: Type + BlogCategoriesWidget: + Blog: Blog + PLURALNAME: 'Blog Categories Widgets' + SINGULARNAME: 'Blog Categories Widget' + BlogCategory: + PLURALNAME: 'Blog Categories' + SINGULARNAME: 'Blog Category' + Title: Title + BlogPost: + Categories: Categories + DESCRIPTION: 'Generic content page' + FeaturedImage: 'Featured Image' + PLURALNAME: 'Blog Posts' + PageTitleLabel: 'Post Title' + PublishDate: 'Publish Date' + SINGULARNAME: 'Blog Post' + Tags: Tags + BlogRecentPostsWidget: + Blog: Blog + NumberOfPosts: 'Number of Posts' + PLURALNAME: 'Blog Recent Posts Widgets' + SINGULARNAME: 'Blog Recent Posts Widget' + BlogTag: + PLURALNAME: 'Blog Tags' + SINGULARNAME: 'Blog Tag' + Title: Title + BlogTagsWidget: + Blog: Blog + PLURALNAME: 'Blog Tags Widgets' + SINGULARNAME: 'Blog Tags Widget' GridFieldAddByDBField: + Add: 'Add {name}' AddFail: 'Unable to save {class} to the database.' PermissionFail: 'You don''t have permission to create a {class}.' - Add: 'Add {name}' GridFieldBlogPostState: - StateTitle: 'State' - Draft: ' Saved as Draft on {date}' - Published: ' Published on {date}' - Timer: ' Publish at {date}' - Modified: 'Modified' - BlogPost: - PublishDate: 'Publish Date' - Categories: 'Categories' - Tags: 'Tags' - FeaturedImage: 'Featured Image' - PageTitleLabel: 'Post Title' - Blog: - BlogPosts: 'Blog Posts' - Categories: 'Categories' - Tags: 'Tags' - PostsPerPage: 'Posts Per Page' - BlogTag: - Title: 'Title' - BlogCategory: - Title: 'Title' - BlogRecentPostsWidget: - Blog: 'Blog' - NumberOfPosts: 'Number of Posts' - BlogCategoriesWidget: - Blog: 'Blog' - BlogArchiveWidget: - Blog: 'Blog' - Monthly: 'Monthly' - Yearly: 'Yearly' - NumberToDisplay: 'Number to Display' - BlogTagsWidget: - Blog: 'Blog' \ No newline at end of file + Draft: ' Saved as Draft on {date}' + Published: ' Published on {date}' + Timer: ' Publish at {date}' diff --git a/templates/Includes/BlogSideBar.ss b/templates/Includes/BlogSideBar.ss new file mode 100644 index 0000000..840df55 --- /dev/null +++ b/templates/Includes/BlogSideBar.ss @@ -0,0 +1,5 @@ +<% if $SideBarView %> +
+ $SideBarView +
+<% end_if %> diff --git a/templates/Includes/EntryMeta.ss b/templates/Includes/EntryMeta.ss new file mode 100644 index 0000000..b2467aa --- /dev/null +++ b/templates/Includes/EntryMeta.ss @@ -0,0 +1,25 @@ +

+ <% if $Categories.exists %> + <%t Blog.PostedIn "Posted in" %> + <% loop $Categories %> + $Title<% if not Last %>, <% else %>;<% end_if %> + <% end_loop %> + <% end_if %> + + <% if $Tags.exists %> + <%t Blog.Tagged "Tagged" %> + <% loop $Tags %> + $Title<% if not Last %>, <% else %>;<% end_if %> + <% end_loop %> + <% end_if %> + + <% if $Comments.exists %> + + <%t Blog.Comments "Comments" %> + $Comments.count + ; + <% end_if %> + + <%t Blog.Posted "Posted" %> + $PublishDate.ago +

diff --git a/templates/Includes/Pagination.ss b/templates/Includes/Pagination.ss new file mode 100644 index 0000000..1a20c7e --- /dev/null +++ b/templates/Includes/Pagination.ss @@ -0,0 +1,25 @@ +<%-- NOTE: Before including this, you will need to wrap the include in a with block --%> + +<% if $MoreThanOnePage %> +

+ <% if $NotFirstPage %> + + <% end_if %> + + <% loop $Pages %> + <% if $CurrentBool %> + $PageNum + <% else %> + <% if $Link %> + $PageNum + <% else %> + ... + <% end_if %> + <% end_if %> + <% end_loop %> + + <% if $NotLastPage %> + + <% end_if %> +

+<% end_if %> diff --git a/templates/Layout/Blog.ss b/templates/Layout/Blog.ss new file mode 100644 index 0000000..a736f39 --- /dev/null +++ b/templates/Layout/Blog.ss @@ -0,0 +1,72 @@ +<% require themedCSS('blog', 'blog') %> + +
+ +
+

+ <% if $ArchiveYear %> + <%t Blog.Archive "Archive" %>: + <% if $ArchiveDay %> + $ArchiveDate.Nice + <% else_if $ArchiveMonth %> + $ArchiveDate.format("F, Y") + <% else %> + $ArchiveDate.format("Y") + <% end_if %> + <% else_if $CurrentTag %> + <%t Blog.Tag "Tag" %>: $CurrentTag.Title + <% else_if $CurrentCategory %> + <%t Blog.Category "Category" %>: $CurrentCategory.Title + <% else %> + $Title + <% end_if %> +

+ +
$Content
+ + <% if $PaginatedList.Exists %> + <% loop $PaginatedList %> +
+

+ "> + <% if $MenuTitle %>$MenuTitle + <% else %>$Title<% end_if %> + +

+ +

+ > + $FeaturedImage.setWidth(795) + +

+ + <% if $Excerpt %> +

+ $Excerpt + + <%t Blog.ReadMoreAbout "Read more about '{title}'..." title=$Title %> + +

+ <% else %> +

+ <%t Blog.ReadMoreAbout "Read more about '{title}'..." title=$Title %> +

+ <% end_if %> + + <% include EntryMeta %> +
+ <% end_loop %> + <% else %> +

<%t Blog.NoPosts "There are no posts" %>

+ <% end_if %> +
+ + $Form + $PageComments + + <% with $PaginatedList %> + <% include Pagination %> + <% end_with %> +
+ +<% include BlogSideBar %> diff --git a/templates/Layout/BlogPost.ss b/templates/Layout/BlogPost.ss new file mode 100644 index 0000000..3a34c6e --- /dev/null +++ b/templates/Layout/BlogPost.ss @@ -0,0 +1,20 @@ +<% require themedCSS('blog', 'blog') %> + +
+
+

$Title

+ + <% if $FeaturedImage %> +

$FeaturedImage.setWidth(795)

+ <% end_if %> + +
$Content
+ + <% include EntryMeta %> +
+ + $Form + $PageComments +
+ +<% include BlogSideBar %> diff --git a/templates/WidgetHolder.ss b/templates/WidgetHolder.ss new file mode 100644 index 0000000..f73142e --- /dev/null +++ b/templates/WidgetHolder.ss @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/templates/widgets/BlogArchiveWidget.ss b/templates/widgets/BlogArchiveWidget.ss old mode 100755 new mode 100644 index 5a30f2b..bba3265 --- a/templates/widgets/BlogArchiveWidget.ss +++ b/templates/widgets/BlogArchiveWidget.ss @@ -1,7 +1,12 @@ -<% if Archive %> +<% if $Archive %> -<% end_if %> \ No newline at end of file +<% end_if %> diff --git a/templates/widgets/BlogCategoriesWidget.ss b/templates/widgets/BlogCategoriesWidget.ss old mode 100755 new mode 100644 index 395a87c..558f09f --- a/templates/widgets/BlogCategoriesWidget.ss +++ b/templates/widgets/BlogCategoriesWidget.ss @@ -1,7 +1,12 @@ -<% if Categories %> +<% if $Categories %> <% end_if %> \ No newline at end of file diff --git a/templates/widgets/BlogRecentPostsWidget.ss b/templates/widgets/BlogRecentPostsWidget.ss old mode 100755 new mode 100644 index c1905e4..0dfc2a2 --- a/templates/widgets/BlogRecentPostsWidget.ss +++ b/templates/widgets/BlogRecentPostsWidget.ss @@ -1,7 +1,12 @@ -<% if Posts %> +<% if $Posts %> <% end_if %> \ No newline at end of file diff --git a/templates/widgets/BlogTagsWidget.ss b/templates/widgets/BlogTagsWidget.ss old mode 100755 new mode 100644 index faa10a0..4fcb1dc --- a/templates/widgets/BlogTagsWidget.ss +++ b/templates/widgets/BlogTagsWidget.ss @@ -1,7 +1,12 @@ -<% if Tags %> +<% if $Tags %> <% end_if %> \ No newline at end of file