Commit f5b4f099 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Remove second template from blog index page & rewrite my blogs url in menu instead


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 7bfde9ff
......@@ -29,10 +29,13 @@ define('INTERNAL', 1);
define('MENUITEM', 'myportfolio/blogs');
define('SECTION_PLUGINTYPE', 'artefact');
define('SECTION_PLUGINNAME', 'blog');
define('SECTION_PAGE', 'index');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('artefact', 'blog');
define('TITLE', get_string('myblogs','artefact.blog'));
if ($delete = param_integer('delete', 0)) {
$blog = artefact_instance_from_id($delete);
if ($blog instanceof ArtefactTypeBlog) {
......@@ -49,34 +52,6 @@ $blogs = (object) array(
list($blogs->count, $blogs->data) = ArtefactTypeBlog::get_blog_list($blogs->limit, $blogs->offset);
// If the user has exactly one blog, and has not enabled multiple blogs, skip the blog listing and display it
if (!$delete && $blogs->offset == 0 && !empty($blogs->data) && count($blogs->data) == 1 && !$USER->get_account_preference('multipleblogs')) {
define('TITLE', get_string('viewblog','artefact.blog'));
define('SECTION_PAGE', 'view');
$record = end($blogs->data);
$id = $record->id;
$blog = new ArtefactTypeBlog($id, $record);
// This javascript is used to generate a list of blog posts.
$js = '';
if ($blog->count_children()) {
$js = require(get_config('docroot') . 'artefact/blog/view/index.js.php');
}
$smarty = smarty(array('tablerenderer'));
$smarty->assign_by_ref('blog', $blog);
$smarty->assign_by_ref('INLINEJAVASCRIPT', $js);
$smarty->assign('PAGEHEADING', hsc($blog->get('title')));
$smarty->assign('strnopostsaddone',
get_string('nopostsaddone', 'artefact.blog',
'<a href="' . get_config('wwwroot') . 'artefact/blog/post.php?blog=' . $blog->get('id') . '">', '</a>'));
$smarty->display('artefact:blog:view.tpl');
exit;
}
define('TITLE', get_string('myblogs','artefact.blog'));
define('SECTION_PAGE', 'index');
ArtefactTypeBlog::build_blog_list_html($blogs);
$smarty = smarty(array('paginator'));
......
......@@ -49,14 +49,19 @@ class PluginArtefactBlog extends PluginArtefact {
public static function menu_items() {
global $USER;
return array(
array(
'path' => 'myportfolio/blogs',
'url' => 'artefact/blog/',
'title' => $USER->get_account_preference('multipleblogs') ? get_string('myblogs', 'artefact.blog') : get_string('myblog', 'artefact.blog'),
'weight' => 30,
),
$tab = array(
'path' => 'myportfolio/blogs',
'weight' => 30,
);
if ($USER->get_account_preference('multipleblogs')) {
$tab['url'] = 'artefact/blog/';
$tab['title'] = get_string('myblogs', 'artefact.blog');
}
else {
$tab['url'] = 'artefact/blog/view/';
$tab['title'] = get_string('myblog', 'artefact.blog');
}
return array($tab);
}
public static function get_cron() {
......
......@@ -35,8 +35,21 @@ require(dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php');
define('TITLE', get_string('viewblog','artefact.blog'));
safe_require('artefact', 'blog');
$id = param_integer('id');
$blog = new ArtefactTypeBlog($id);
$id = param_integer('id', null);
if (is_null($id)) {
if (!$records = get_records_select_array(
'artefact',
"artefacttype = 'blog' AND owner = ?",
array($USER->get('id')),
'id ASC'
)) {
throw new ParameterException();
}
$blog = new ArtefactTypeBlog($records[0]->id, $records[0]);
}
else {
$blog = new ArtefactTypeBlog($id);
}
$blog->check_permission();
// This javascript is used to generate a list of blog posts.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment