* */ define('INTERNAL', 1); define('JSON', 1); define('PUBLIC', 1); require dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php'; safe_require('artefact', 'blog'); json_headers(); $id = param_integer('id'); $limit = param_integer('limit', ArtefactTypeBlog::pagination); $offset = param_integer('offset', 0); $options = json_decode(param_variable('options')); $viewid = isset($options->viewid) ? $options->viewid : null; if ($viewid) { if (!can_view_view($viewid)) { throw new AccessDeniedException(); } } else { if (!$USER->is_logged_in()) { throw new AccessDeniedException(); } if (!$viewid && get_field('artefact', 'owner', 'id', $id) != $USER->get('id')) { throw new AccessDeniedException(); } } list($count, $data) = ArtefactTypeBlogPost::render_posts(FORMAT_ARTEFACT_RENDERFULL, $options, $id, $limit, $offset); if (!$count) { $count = 1; $data = array(array('content' => get_string('noresults', 'artefact.blog'))); } echo json_encode(array('count' => $count, 'limit' => $limit, 'offset' => $offset, 'data' => $data));
if (!empty($blog)) { $blog->check_permission(); } if (!isset($limit)) { $limit = param_integer('limit', 5); } if (!isset($setlimit)) { $setlimit = 0; } if (!isset($offset)) { $offset = param_integer('offset', 0); } $posts = ArtefactTypeBlogPost::get_posts($id, $limit, $offset); $template = 'artefact:blog:posts.tpl'; $pagination = array('baseurl' => get_config('wwwroot') . 'artefact/blog/view/index.php?id=' . $id, 'id' => 'blogpost_pagination', 'jsonscript' => 'artefact/blog/view/index.json.php', 'datatable' => 'postlist', 'setlimit' => $setlimit); ArtefactTypeBlogPost::render_posts($posts, $template, array(), $pagination); $strpublished = json_encode(get_string('published', 'artefact.blog')); $strdraft = json_encode(get_string('draft', 'artefact.blog')); $strchangepoststatuspublish = json_encode(get_string('publish', 'artefact.blog')); $strchangepoststatusunpublish = json_encode(get_string('unpublish', 'artefact.blog')); $js = <<<EOF function changepoststatus_success(form, data) { if (\$('changepoststatus_' + data.id + '_currentpoststatus').value === "0") { removeElementClass(\$('posttitle_' + data.id), 'draft'); addElementClass(\$('posttitle_' + data.id), 'published'); \$('poststatus' + data.id).innerHTML = {$strpublished}; \$('changepoststatus_' + data.id + '_submit').innerHTML = '<span class="prs icon icon-times text-danger"></span> ' + {$strchangepoststatusunpublish}; } else { removeElementClass(\$('posttitle_' + data.id), 'published');