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

Move pagination part of blog html export into parent class (bug #619597)


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent d91b3aa8
......@@ -32,46 +32,20 @@ defined('INTERNAL') || die();
*/
class HtmlExportBlog extends HtmlExportArtefactPlugin {
public function pagination_data($artefact) {
if ($artefact instanceof ArtefactTypeBlog) {
return array(
'perpage' => ArtefactTypeBlog::pagination,
'childcount' => $artefact->count_published_posts(),
'plural' => get_string('blogs', 'artefact.blog'),
);
}
}
public function dump_export_data() {
foreach ($this->exporter->get('artefacts') as $artefact) {
if ($artefact->get('artefacttype') == 'blog') {
// Create directory for storing the blog
$dirname = PluginExportHtml::text_to_path($artefact->get('title'));
if (!check_dir_exists($this->fileroot . $dirname)) {
throw new SystemException("Couldn't create blog directory {$this->fileroot}{$dirname}");
}
// Render the first page of the blog (the only one if there's
// not many posts)
$smarty = $this->exporter->get_smarty('../../../', 'blog');
$smarty->assign('page_heading', $artefact->get('title'));
$smarty->assign('breadcrumbs', array(
array('text' => get_string('blogs', 'artefact.blog')),
array('text' => $artefact->get('title'), 'path' => 'index.html'),
));
$rendered = $artefact->render_self(array('hidetitle' => true));
$outputfilter = new HtmlExportOutputFilter('../../../', $this->exporter);
$smarty->assign('rendered_blog', $outputfilter->filter($rendered['html']));
$content = $smarty->fetch('export:html/blog:index.tpl');
if (false === file_put_contents($this->fileroot . $dirname . '/index.html', $content)) {
throw new SystemException("Unable to create index.html for blog $blogid");
}
// If the blog has many posts, we'll need to write out archive pages
$postcount = $artefact->count_published_posts();
$perpage = ArtefactTypeBlog::pagination;
if ($postcount > $perpage) {
for ($i = $perpage; $i <= $postcount; $i += $perpage) {
$rendered = $artefact->render_self(array('limit' => $perpage, 'offset' => $i));
$smarty->assign('rendered_blog', $outputfilter->filter($rendered['html']));
$content = $smarty->fetch('export:html/blog:index.tpl');
if (false === file_put_contents($this->fileroot . $dirname . "/{$i}.html", $content)) {
throw new SystemException("Unable to create {$i}.html for blog {$artefact->get('id')}");
}
}
}
if ($artefact instanceof ArtefactTypeBlog) {
$this->paginate($artefact);
}
}
}
......
......@@ -446,6 +446,46 @@ abstract class HtmlExportArtefactPlugin {
abstract public function get_summary_weight();
public function paginate($artefact) {
// Create directory for storing the artefact
$dirname = PluginExportHtml::text_to_path($artefact->get('title'));
if (!check_dir_exists($this->fileroot . $dirname)) {
throw new SystemException("Couldn't create artefact directory {$this->fileroot}{$dirname}");
}
// Get artefact-specific pagination options
$options = $this->pagination_data($artefact);
// Render the first page of the artefact (the only one if there aren't many children)
$smarty = $this->exporter->get_smarty('../../../', $artefact->get('artefacttype'));
$smarty->assign('page_heading', $artefact->get('title'));
$smarty->assign('breadcrumbs', array(
array('text' => $options['plural']),
array('text' => $artefact->get('title'), 'path' => 'index.html'),
));
$rendered = $artefact->render_self(array('hidetitle' => true));
$outputfilter = new HtmlExportOutputFilter('../../../', $this->exporter);
$smarty->assign('rendered', $outputfilter->filter($rendered['html']));
$content = $smarty->fetch('export:html:page.tpl');
if (false === file_put_contents($this->fileroot . $dirname . '/index.html', $content)) {
throw new SystemException("Unable to create index.html for artefact " . $artefact->get('id'));
}
// If the artefact has many children, we'll need to write out archive pages
if ($options['childcount'] > $options['perpage']) {
for ($i = $options['perpage']; $i <= $options['childcount']; $i += $options['perpage']) {
$rendered = $artefact->render_self(array('limit' => $options['perpage'], 'offset' => $i));
$smarty->assign('rendered', $outputfilter->filter($rendered['html']));
$content = $smarty->fetch('export:html:page.tpl');
if (false === file_put_contents($this->fileroot . $dirname . "/{$i}.html", $content)) {
throw new SystemException("Unable to create {$i}.html for artefact {$artefact->get('id')}");
}
}
}
}
}
/**
......
{include file="export:html:header.tpl"}
{$rendered|safe}
{include file="export:html:footer.tpl"}
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