Commit 4333791b authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Fixes for blog pagination in html export (bug #617155)


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent a3eb4e93
......@@ -57,6 +57,7 @@ class PluginBlocktypeBlog extends PluginBlocktype {
}
public static function render_instance(BlockInstance $instance, $editing=false) {
global $exporter;
$configdata = $instance->get('configdata');
$result = '';
......@@ -75,19 +76,28 @@ class PluginBlocktypeBlog extends PluginBlocktype {
$limit = isset($configdata['count']) ? intval($configdata['count']) : 5;
$posts = ArtefactTypeBlogpost::get_posts($blog->get('id'), $limit, 0, $configdata);
$template = 'artefact:blog:viewposts.tpl';
if ($exporter) {
$pagination = false;
}
else {
$pagination = array(
'baseurl' => $instance->get_view()->get_url() . '&block=' . $instance->get('id'),
'id' => 'blogpost_pagination_' . $instance->get('id'),
'datatable' => 'postlist_' . $instance->get('id'),
'jsonscript' => 'artefact/blog/posts.json.php',
);
}
ArtefactTypeBlogpost::render_posts($posts, $template, $configdata, $pagination);
$smarty = smarty_core();
if (isset($configdata['viewid'])) {
$smarty->assign('artefacttitle', '<a href="' . get_config('wwwroot') . 'view/artefact.php?artefact='
. $blog->get('id') . '&view=' . $configdata['viewid']
. '">' . hsc($blog->get('title')) . '</a>');
$artefacturl = get_config('wwwroot') . 'view/artefact.php?artefact=' . $blog->get('id') . '&amp;view='
. $configdata['viewid'];
$smarty->assign('artefacttitle', '<a href="' . $artefacturl . '">' . hsc($blog->get('title')) . '</a>');
if ($exporter && $posts['count'] > $limit) {
$posts['pagination'] = '<a href="' . $artefacturl . '">'
. get_string('allposts', 'artefact.blog') . '</a>';
}
}
else {
$smarty->assign('artefacttitle', hsc($blog->get('title')));
......
......@@ -62,8 +62,8 @@ class HtmlExportBlog extends HtmlExportArtefactPlugin {
$postcount = $artefact->count_published_posts();
$perpage = ArtefactTypeBlog::pagination;
if ($postcount > $perpage) {
for ($i = 2; $i <= ceil($postcount / $perpage); $i++) {
$rendered = $artefact->render_self(array('page' => $i));
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');
......
......@@ -35,6 +35,7 @@ $string['addblog'] = 'Create Blog';
$string['addpost'] = 'New Post';
$string['alignment'] = 'Alignment';
$string['allowcommentsonpost'] = 'Allow comments on your post.';
$string['allposts'] = 'All posts';
$string['attach'] = 'Attach';
$string['attachedfilelistloaded'] = 'Attached file list loaded';
$string['attachedfiles'] = 'Attached files';
......
......@@ -219,7 +219,10 @@ class ArtefactTypeBlog extends ArtefactType {
$template = 'artefact:blog:viewposts.tpl';
$baseurl = get_config('wwwroot') . 'view/artefact.php?artefact=' . $this->id . '&view=' . $options['viewid'];
$baseurl = get_config('wwwroot') . 'view/artefact.php?artefact=' . $this->id;
if (!empty($options['viewid'])) {
$baseurl .= '&view=' . $options['viewid'];
}
$pagination = array(
'baseurl' => $baseurl,
'id' => 'blogpost_pagination',
......@@ -670,8 +673,8 @@ class ArtefactTypeBlogPost extends ArtefactType {
$posts['tablerows'] = $smarty->fetch($template);
if ($posts['limit']) {
$pagination = build_pagination(array(
if ($posts['limit'] && $pagination) {
$pagination = build_pagination($foo = array(
'id' => $pagination['id'],
'class' => 'center',
'datatable' => $pagination['datatable'],
......
......@@ -10,10 +10,14 @@
{$posts.tablerows|safe}
</tbody>
</table>
{if $posts.pagination}
<div id="blogpost_page_container_{$blockid}" class="hidden center">{$posts.pagination|safe}</div>
{/if}
{if $posts.pagination_js}
<script>
addLoadEvent(function() {literal}{{/literal}
{$posts.pagination_js|safe}
removeElementClass('blogpost_page_container_{$blockid}', 'hidden');
{literal}}{/literal});
</script>
{/if}
......@@ -56,6 +56,11 @@ class PluginBlocktypeMyfriends extends SystemBlocktype {
$smarty = smarty_core();
$smarty->assign_by_ref('friends', $friendarray);
$friends['tablerows'] = $smarty->fetch('blocktype:myfriends:myfriendrows.tpl');
if ($friends['limit'] === false) {
return;
}
$baseurl = $instance->get_view()->get_url() . '&block=' . $instance->get('id');
$baseurl .= '&user=' . (int) $userid;
$pagination = build_pagination(array(
......@@ -76,14 +81,17 @@ class PluginBlocktypeMyfriends extends SystemBlocktype {
}
public static function render_instance(BlockInstance $instance, $editing=false) {
global $USER;
global $USER, $exporter;
$userid = $instance->get_view()->get('owner');
if (!$userid) {
// 'My Friends' doesn't make sense for group/site views
return '';
}
$friends = get_friends($userid, MAXFRIENDDISPLAY, 0);
$limit = isset($exporter) ? false : MAXFRIENDDISPLAY;
$friends = get_friends($userid, $limit, 0);
if ($friends['count']) {
self::build_myfriends_html($friends, $userid, $instance);
}
......
......@@ -526,7 +526,7 @@ class HtmlExportOutputFilter {
// Links to artefacts
$html = preg_replace_callback(
'#<a[^>]+href="(' . $wwwroot . ')?/?view/artefact\.php\?artefact=(\d+)(&amp;view=\d+)?(&amp;page=\d+)?"[^>]*>([^<]*)</a>#',
'#<a[^>]+href="(' . $wwwroot . ')?/?view/artefact\.php\?artefact=(\d+)(&amp;view=\d+)?(&amp;offset=\d+)?"[^>]*>([^<]*)</a>#',
array($this, 'replace_artefact_link'),
$html
);
......@@ -582,9 +582,9 @@ class HtmlExportOutputFilter {
switch ($artefact->get('artefacttype')) {
case 'blog':
$page = ($matches[4]) ? intval(substr($matches[4], strlen('&amp;page='))) : 1;
$page = ($page == 1) ? 'index' : $page;
return '<a href="' . $this->basepath . '/files/blog/' . PluginExportHtml::text_to_path($artefact->get('title')) . '/' . $page . '.html">' . $matches[5] . '</a>';
$offset = ($matches[4]) ? intval(substr($matches[4], strlen('&amp;offset='))) : 0;
$offset = ($offset == 0) ? 'index' : $offset;
return '<a href="' . $this->basepath . '/files/blog/' . PluginExportHtml::text_to_path($artefact->get('title')) . '/' . $offset . '.html">' . $matches[5] . '</a>';
case 'file':
case 'folder':
case 'image':
......
......@@ -50,6 +50,10 @@ a img {
.r1 {
background-color: #f8f8f8;
}
div.pagination span.selected,
span.pagination {
padding: 5px;
}
/* Headings */
h1 {
......
......@@ -1899,7 +1899,12 @@ function get_friends($userid, $limit=10, $offset=0) {
SELECT f.* ' . $from . "
ORDER BY CASE WHEN NOT f.preferredname IS NULL AND f.preferredname <> '' THEN f.preferredname ELSE f.firstname || f.lastname END";
if ($limit === false) {
$result['data'] = get_records_sql_array($sql, $values);
}
else {
$result['data'] = get_records_sql_array($sql, $values, $offset, $limit);
}
return $result;
}
......
......@@ -2804,7 +2804,7 @@ function build_pagination($params) {
if (isset($params['forceoffset']) && !is_null($params['forceoffset'])) {
$params['offset'] = (int) $params['forceoffset'];
}
else {
else if (!isset($params['offset'])) {
$params['offset'] = param_integer($params['offsetname'], 0);
}
......
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