Browse files

changes to blog that generates a preview url and loads in new tab/window

  • Loading branch information...
1 parent 9314486 commit 36fc0fb50f013d1d51d4c03f1568bbf55b47f7b9 @mfrost503 committed Apr 28, 2012
Showing with 63 additions and 39 deletions.
  1. +62 −38 system/cms/modules/blog/controllers/blog.php
  2. +1 −1 system/cms/modules/blog/views/admin/tables/posts.php
View
100 system/cms/modules/blog/controllers/blog.php
@@ -142,46 +142,28 @@ public function view($slug = '')
redirect('blog');
}
- // if it uses markdown then display the parsed version
- if ($post->type == 'markdown')
- {
- $post->body = $post->parsed;
- }
-
- // IF this post uses a category, grab it
- if ($post->category_id && ($category = $this->blog_categories_m->get($post->category_id)))
- {
- $post->category = $category;
- }
-
- // Set some defaults
- else
- {
- $post->category->id = 0;
- $post->category->slug = '';
- $post->category->title = '';
- }
-
- $this->session->set_flashdata(array('referrer' => $this->uri->uri_string));
-
- $this->template->title($post->title, lang('blog_blog_title'))
- ->set_metadata('description', $post->intro)
- ->set_metadata('keywords', implode(', ', Keywords::get_array($post->keywords)))
- ->set_breadcrumb(lang('blog_blog_title'), 'blog');
-
- if ($post->category->id > 0)
- {
- $this->template->set_breadcrumb($post->category->title, 'blog/category/'.$post->category->slug);
- }
-
- $post->keywords = Keywords::get_links($post->keywords, 'blog/tagged');
-
- $this->template
- ->set_breadcrumb($post->title)
- ->set('post', $post)
- ->build('view');
+ $this->_singleView($post);
}
+ /**
+ * View a post
+ *
+ * @param string $slug The slug of the blog post.
+ */
+ public function preview($slug = '')
+ {
+ if ( ! $slug or ! $post = $this->blog_m->get_by('slug', $slug))
+ {
+ redirect('blog');
+ }
+
+ if ($post->status != 'draft')
+ {
+ redirect('blog/' . date('Y/m',$post->created_on) . '/' . $post->slug);
+ }
+
+ $this->_singleView($post);
+ }
/**
* @todo Document this.
*
@@ -253,4 +235,46 @@ private function _posts_metadata(&$posts = array())
'description' => implode(', ', $description)
);
}
+
+ private function _singleView($post,$build='view') {
+
+ // if it uses markdown then display the parsed version
+ if ($post->type == 'markdown')
+ {
+ $post->body = $post->parsed;
+ }
+
+ // IF this post uses a category, grab it
+ if ($post->category_id && ($category = $this->blog_categories_m->get($post->category_id)))
+ {
+ $post->category = $category;
+ }
+
+ // Set some defaults
+ else
+ {
+ $post->category->id = 0;
+ $post->category->slug = '';
+ $post->category->title = '';
+ }
+
+ $this->session->set_flashdata(array('referrer' => $this->uri->uri_string));
+
+ $this->template->title($post->title, lang('blog_blog_title'))
+ ->set_metadata('description', $post->intro)
+ ->set_metadata('keywords', implode(', ', Keywords::get_array($post->keywords)))
+ ->set_breadcrumb(lang('blog_blog_title'), 'blog');
+
+ if ($post->category->id > 0)
+ {
+ $this->template->set_breadcrumb($post->category->title, 'blog/category/'.$post->category->slug);
+ }
+
+ $post->keywords = Keywords::get_links($post->keywords, 'blog/tagged');
+
+ $this->template
+ ->set_breadcrumb($post->title)
+ ->set('post', $post)
+ ->build($build);
+ }
}
View
2 system/cms/modules/blog/views/admin/tables/posts.php
@@ -33,7 +33,7 @@
</td>
<td><?php echo lang('blog_'.$post->status.'_label'); ?></td>
<td>
- <?php echo anchor('admin/blog/preview/' . $post->id, lang($post->status == 'live' ? 'global:view' : 'global:preview'), 'rel="modal-large" class="iframe btn green" target="_blank"'); ?>
+ <?php echo anchor('blog/preview/' . $post->slug, lang($post->status == 'live' ? 'global:view' : 'global:preview'), 'class="btn green" target="_blank"'); ?>
<?php echo anchor('admin/blog/edit/' . $post->id, lang('global:edit'), 'class="btn orange edit"'); ?>
<?php echo anchor('admin/blog/delete/' . $post->id, lang('global:delete'), array('class'=>'confirm btn red delete')); ?>
</td>

0 comments on commit 36fc0fb

Please sign in to comment.