public static function render_instance(BlockInstance $instance, $editing = false) { global $exporter; $configdata = $instance->get('configdata'); $result = ''; if (!empty($configdata['artefactid'])) { require_once get_config('docroot') . 'artefact/lib.php'; $blog = $instance->get_artefact_instance($configdata['artefactid']); $configdata['hidetitle'] = true; $configdata['countcomments'] = true; $configdata['viewid'] = $instance->get('view'); if ($instance->get_view()->is_submitted()) { // Don't display posts added after the submitted date. if ($submittedtime = $instance->get_view()->get('submittedtime')) { $configdata['before'] = $submittedtime; } } $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 { $baseurl = $instance->get_view()->get_url(); $baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'block=' . $instance->get('id'); $pagination = array('baseurl' => $baseurl, 'id' => 'blogpost_pagination_' . $instance->get('id'), 'datatable' => 'postlist_' . $instance->get('id'), 'jsonscript' => 'artefact/blog/posts.json.php'); } $configdata['blockid'] = $instance->get('id'); $configdata['editing'] = $editing; ArtefactTypeBlogpost::render_posts($posts, $template, $configdata, $pagination); $smarty = smarty_core(); if (isset($configdata['viewid'])) { $artefacturl = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $blog->get('id') . '&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'))); } // Only show the 'New entry' link for blogs that you can add an entry to $canaddpost = false; $institution = $blog->get('institution'); $group = $blog->get('group'); if (ArtefactTypeBlog::can_edit_blog($blog, $institution, $group)) { $canaddpost = true; } $smarty->assign('options', $configdata); $smarty->assign('description', $blog->get('description')); $smarty->assign('owner', $blog->get('owner')); $smarty->assign('tags', $blog->get('tags')); $smarty->assign('blockid', $instance->get('id')); $smarty->assign('editing', $editing); $smarty->assign('canaddpost', $canaddpost); $smarty->assign('blogid', $blog->get('id')); $smarty->assign('posts', $posts); $result = $smarty->fetch('artefact:blog:blog.tpl'); } return $result; }
if ($institution != 'mahara') { $s = institution_selector_for_page($institution, get_config('wwwroot') . 'artefact/blog/view/index.php'); } } } PluginArtefactBlog::set_blog_nav($institution, $institutionname); if ($institutionname === false) { $smarty = smarty(); $smarty->display('admin/users/noinstitutions.tpl'); exit; } if ($changepoststatus = param_integer('changepoststatus', null)) { ArtefactTypeBlogpost::changepoststatus_form($changepoststatus); } if ($delete = param_integer('delete', null)) { ArtefactTypeBlogpost::delete_form($delete); } if (is_null($id)) { if ($institutionname) { $records = get_records_select_array('artefact', "artefacttype = 'blog' AND \"institution\" = ?", array($institutionname), 'id ASC'); if (!$records || count($records) > 1) { // There are either no blogs for this institution or more than one so we need to send them to journal list page // so they can add one or chose a particular blog by id. redirect("/artefact/blog/index.php?institution={$institutionname}"); exit; } } else { if (!($records = get_records_select_array('artefact', "artefacttype = 'blog' AND \"owner\" = ?", array($USER->get('id')), 'id ASC'))) { die_info(get_string('nodefaultblogfound', 'artefact.blog', get_config('wwwroot'))); } }
public static function render_instance(BlockInstance $instance, $editing = false) { global $USER; $configdata = $instance->get('configdata'); $view = $instance->get('view'); $full = isset($configdata['full']) ? $configdata['full'] : false; $results = array(); $smarty = smarty_core(); $smarty->assign('view', $view); $viewownerdisplay = null; // Display all posts, from all blogs, owned by this user $tagsin = $tagsout = array(); $results = self::get_blog_posts_in_block($instance, $tagsin, $tagsout); if ($tagsin || $tagsout) { $smarty->assign('blockid', $instance->get('id')); $smarty->assign('editing', $editing); if ($editing) { // Get list of blogs owned by this user to create the "Add new post" shortcut while editing $viewowner = $instance->get_view()->get('owner'); if (!$viewowner || !($blogs = get_records_select_array('artefact', 'artefacttype = \'blog\' AND owner = ?', array($viewowner), 'title ASC', 'id, title'))) { $blogs = array(); } $smarty->assign('tagselect', implode(', ', $tagsin)); $smarty->assign('blogs', $blogs); } // if posts are not found with the selected tag, notify the user if (!$results) { $smarty->assign('badtag', implode(', ', $tagsin)); $smarty->assign('badnotag', implode(', ', $tagsout)); return $smarty->fetch('blocktype:taggedposts:taggedposts.tpl'); } // update the view_artefact table so journal entries are accessible when this is the only block on the page // referencing this journal $dataobject = array('view' => $view, 'block' => $instance->get('id')); require_once get_config('docroot') . 'lib/view.php'; $viewobj = new View($view); require_once get_config('docroot') . 'artefact/lib.php'; safe_require('artefact', 'blog'); safe_require('artefact', 'comment'); foreach ($results as $result) { $dataobject["artefact"] = $result->parent; $result->postedbyon = get_string('postedbyon', 'artefact.blog', display_default_name($result->owner), format_date(strtotime($result->ctime))); $result->displaydate = format_date(strtotime($result->ctime)); $artefact = new ArtefactTypeBlogpost($result->id); // get comments for this post $result->commentcount = count_records_select('artefact_comment_comment', "onartefact = {$result->id} AND private = 0 AND deletedby IS NULL"); $allowcomments = $artefact->get('allowcomments'); if (empty($result->commentcount) && empty($allowcomments)) { $result->commentcount = null; } list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $viewobj, null, false); $result->comments = $comments; // get all tags for this post $taglist = get_records_array('artefact_tag', 'artefact', $result->id, "tag DESC"); foreach ($taglist as $t) { $result->taglist[] = $t->tag; } if ($full) { $rendered = $artefact->render_self(array('viewid' => $view, 'details' => true, 'blockid' => $instance->get('id'))); $result->html = $rendered['html']; if (!empty($rendered['javascript'])) { $result->html .= '<script type="application/javascript">' . $rendered['javascript'] . '</script>'; } } } // check if the user viewing the page is the owner of the selected tag $owner = $results[0]->owner; if ($USER->id != $owner) { $viewownerdisplay = get_user_for_display($owner); } $smarty->assign('tagsin', $tagsin); $smarty->assign('tagsout', $tagsout); } else { if (!self::get_chooseable_tags()) { // error if block configuration fails $smarty->assign('configerror', get_string('notagsavailableerror', 'blocktype.blog/taggedposts')); return $smarty->fetch('blocktype:taggedposts:taggedposts.tpl'); } else { // error if block configuration fails $smarty->assign('configerror', get_string('configerror', 'blocktype.blog/taggedposts')); return $smarty->fetch('blocktype:taggedposts:taggedposts.tpl'); } } // add any needed links to the tags $tagstr = $tagomitstr = ''; foreach ($tagsin as $key => $tag) { if ($key > 0) { $tagstr .= ', '; } $tagstr .= $viewownerdisplay ? '"' . $tag . '"' : '"<a href="' . get_config('wwwroot') . 'tags.php?tag=' . $tag . '&sort=name&type=text">' . $tag . '</a>"'; } if (!empty($tagsout)) { foreach ($tagsout as $key => $tag) { if ($key > 0) { $tagomitstr .= ', '; } $tagomitstr .= $viewownerdisplay ? '"' . $tag . '"' : '"<a href="' . get_config('wwwroot') . 'tags.php?tag=' . $tag . '&sort=name&type=text">' . $tag . '</a>"'; } } $blockheading = get_string('blockheadingtags', 'blocktype.blog/taggedposts', count($tagsin), $tagstr); $blockheading .= !empty($tagomitstr) ? get_string('blockheadingtagsomit', 'blocktype.blog/taggedposts', count($tagsout), $tagomitstr) : ''; $blockheading .= $viewownerdisplay ? ' ' . get_string('by', 'artefact.blog') . ' <a href="' . profile_url($viewownerdisplay) . '">' . display_name($viewownerdisplay) . '</a>' : ''; $smarty->assign('full', $full); $smarty->assign('results', $results); $smarty->assign('blockheading', $blockheading); return $smarty->fetch('blocktype:taggedposts:taggedposts.tpl'); }
if ($blockid = param_integer('block', null)) { $bi = new BlockInstance($blockid); if (!can_view_view($bi->get('view'))) { json_reply(true, get_string('accessdenied', 'error')); } $configdata = $bi->get('configdata'); $limit = isset($configdata['count']) ? $configdata['count'] : 5; $configdata['countcomments'] = true; $configdata['viewid'] = $bi->get('view'); $posts = ArtefactTypeBlogpost::get_posts($configdata['artefactid'], $limit, $offset, $configdata); $template = 'artefact:blog:viewposts.tpl'; $baseurl = $bi->get_view()->get_url(); $baseurl .= (strpos($baseurl, '?') === false ? '?' : '&') . 'block=' . $blockid; $pagination = array('baseurl' => $baseurl, 'id' => 'blogpost_pagination_' . $blockid, 'datatable' => 'postlist_' . $blockid, 'jsonscript' => 'artefact/blog/posts.json.php'); ArtefactTypeBlogpost::render_posts($posts, $template, $configdata, $pagination); } else { // No block, we're just rendering the blog by itself. $limit = param_integer('limit', ArtefactTypeBlog::pagination); $blogid = param_integer('artefact'); $viewid = param_integer('view'); if (!can_view_view($viewid)) { json_reply(true, get_string('accessdenied', 'error')); } $options = array('viewid' => $viewid, 'countcomments' => true); $posts = ArtefactTypeBlogpost::get_posts($blogid, $limit, $offset, $options); $template = 'artefact:blog:viewposts.tpl'; $baseurl = get_config('wwwroot') . 'artefact/artefact.php?artefact=' . $blogid . '&view=' . $viewid; $pagination = array('baseurl' => $baseurl, 'id' => 'blogpost_pagination', 'datatable' => 'postlist', 'jsonscript' => 'artefact/blog/posts.json.php'); ArtefactTypeBlogpost::render_posts($posts, $template, $options, $pagination); } json_reply(false, array('data' => $posts));
foreach (get_my_tags(null, false, $tagsort) as $tag) { $tags_arr[] = array("id" => $tag->tag, "tag" => $tag->tag); } if (count($tags_arr) > 0) { $json['tags'] = $tags_arr; } // OK - let's add journals (and journal posts) $blogs_arr = array(); $blogs = (object) array('offset' => param_integer('offset', 0), 'limit' => param_integer('limit', 10)); $blogposts_arr = array(); $blogposts = array(); list($blogs->count, $blogs->data) = ArtefactTypeBlog::get_blog_list($blogs->limit, $blogs->offset); foreach ($blogs->data as $blog) { if (!$blog->locked) { $blogs_arr[] = array("id" => $blog->id, "blog" => $blog->title); $blogposts = ArtefactTypeBlogpost::get_posts($blog->id, $blogs->limit, $blogs->offset, null); foreach ($blogposts['data'] as $blogpost) { if (!$blogpost->locked) { $blogposts_arr[] = array("id" => $blogpost->id, "blogpost" => $blogpost->title); } } } } if (count($blogs_arr) > 0) { $json['blogs'] = $blogs_arr; } if (count($blogposts_arr) > 0) { $json['blogposts'] = $blogposts_arr; } // OK - let's add folders $folders_arr = array();
/** * This function returns a list of posts in a given blog. * * @param integer * @param integer * @param integer * @param array */ public static function get_posts($id, $limit, $offset, $viewoptions = null) { $results = array('limit' => $limit, 'offset' => $offset); // If viewoptions is null, we're getting posts for the my blogs area, // and we should get all posts & show drafts first. Otherwise it's a // blog in a view, and we should only get published posts. $from = "\n FROM {artefact} a LEFT JOIN {artefact_blog_blogpost} bp ON a.id = bp.blogpost\n WHERE a.artefacttype = 'blogpost' AND a.parent = ?"; if (!is_null($viewoptions)) { if (isset($viewoptions['before'])) { $from .= " AND a.ctime < '{$viewoptions['before']}'"; } $from .= ' AND bp.published = 1'; } $results['count'] = count_records_sql('SELECT COUNT(*) ' . $from, array($id)); $data = get_records_sql_assoc(' SELECT a.id, a.title, a.description, a.author, a.authorname, ' . db_format_tsfield('a.ctime', 'ctime') . ', ' . db_format_tsfield('a.mtime', 'mtime') . ', a.locked, bp.published, a.allowcomments ' . $from . ' ORDER BY bp.published ASC, a.ctime DESC, a.id DESC', array($id), $offset, $limit); if (!$data) { $results['data'] = array(); return $results; } // Get the attached files. $postids = array_map(create_function('$a', 'return $a->id;'), $data); $files = ArtefactType::attachments_from_id_list($postids); if ($files) { safe_require('artefact', 'file'); foreach ($files as &$file) { $params = array('id' => $file->attachment); if (!empty($viewoptions['viewid'])) { $params['viewid'] = $viewoptions['viewid']; } $file->icon = call_static_method(generate_artefact_class_name($file->artefacttype), 'get_icon', $params); $data[$file->artefact]->files[] = $file; } } if ($tags = ArtefactType::tags_from_id_list($postids)) { foreach ($tags as &$at) { $data[$at->artefact]->tags[] = $at->tag; } } foreach ($data as &$post) { // Format dates properly if (is_null($viewoptions)) { // My Blogs area: create forms for changing post status & deleting posts. $post->changepoststatus = ArtefactTypeBlogpost::changepoststatus_form($post->id, $post->published); $post->delete = ArtefactTypeBlogpost::delete_form($post->id, $post->title); } else { $by = $post->author ? display_default_name($post->author) : $post->authorname; $post->postedby = get_string('postedbyon', 'artefact.blog', $by, format_date($post->ctime)); // Get comment counts if (!empty($viewoptions['countcomments'])) { safe_require('artefact', 'comment'); require_once get_config('docroot') . 'lib/view.php'; $view = new View($viewoptions['viewid']); $artefact = artefact_instance_from_id($post->id); list($commentcount, $comments) = ArtefactTypeComment::get_artefact_comments_for_view($artefact, $view, null, false); $post->commentcount = $commentcount; $post->comments = $comments; } } $post->ctime = format_date($post->ctime, 'strftimedaydatetime'); $post->mtime = format_date($post->mtime); // Ensure images in the post have the right viewid associated with them if (!empty($viewoptions['viewid'])) { safe_require('artefact', 'file'); $post->description = ArtefactTypeFolder::append_view_url($post->description, $viewoptions['viewid']); } } $results['data'] = array_values($data); return $results; }