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