Commit 17ce86eb authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1683582: Don't show the blog owner when viewing anonymously



When viewing the page the blog/post is on and being logged out

behatnotneeded

Change-Id: I8418b37158073d3772d70f20cc696d6ab49d1f13
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 0e29d2fd
......@@ -108,17 +108,22 @@ class PluginBlocktypeRecentposts extends MaharaCoreBlocktype {
}
public static function render_instance(BlockInstance $instance, $editing=false) {
global $USER;
$result = '';
$mostrecent = self::get_blog_posts_in_block($instance);
if ($mostrecent) {
// format the dates
// format the dates and blog title
safe_require('artefact', 'blog');
foreach ($mostrecent as &$data) {
$data->displaydate = format_date($data->ctime);
if ($data->ctime != $data->mtime) {
$data->updateddate = format_date($data->mtime);
}
$blog = new ArtefactTypeBlog($data->parent);
$data->parenttitle = $blog->display_title();
}
$smarty = smarty_core();
$smarty->assign('mostrecent', $mostrecent);
$smarty->assign('view', $instance->get('view'));
......@@ -131,7 +136,6 @@ class PluginBlocktypeRecentposts extends MaharaCoreBlocktype {
$blogs = array();
if ($selectedblogs = get_records_sql_array('SELECT id, title FROM {artefact}'. $wherestm, $recentpostconfigdata['artefactids'])) {
safe_require('artefact', 'blog');
foreach ($selectedblogs as $selectedblog) {
$blog = new ArtefactTypeBlog($selectedblog->id);
if (ArtefactTypeBlog::can_edit_blog($blog, $blog->get('institution'), $blog->get('group'))) {
......
......@@ -213,8 +213,9 @@ class PluginBlocktypeTaggedposts extends MaharaCoreBlocktype {
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));
$result->postedbyon = ArtefactTypeBlog::display_postedby($result->ctime, display_default_name($result->owner));
if ($result->ctime != $result->mtime) {
$result->updateddate= format_date(strtotime($result->mtime));
}
......@@ -246,7 +247,7 @@ class PluginBlocktypeTaggedposts extends MaharaCoreBlocktype {
// check if the user viewing the page is the owner of the selected tag
$owner = $results[0]->owner;
if ($USER->id != $owner) {
if ($USER->is_logged_in() && $USER->id != $owner) {
$viewownerdisplay = get_user_for_display($owner);
}
$smarty->assign('tagsin', $tagsin);
......
......@@ -194,6 +194,41 @@ class ArtefactTypeBlog extends ArtefactType {
return false;
}
public function display_title($maxlen=null) {
global $USER;
$title = $this->get('title');
// Check if we are displaying title to anonymous user
// And the blog we are showing is the default one named
// after the user.
if (!$USER->is_logged_in()) {
$owner = new User;
$owner->find_by_id($this->get('owner'));
if (preg_match('/^' . preg_quote($owner->get('firstname') . ' ' . $owner->get('lastname') . '/'), $title)) {
$title = get_string('Blog', 'artefact.blog');
}
}
if ($maxlen) {
return str_shorten_text($title, $maxlen, true);
}
return $title;
}
public function display_postedby($date, $by) {
global $USER;
if (!is_numeric($date)) {
// convert any formatted dates back to time
$date = strtotime($date);
}
if ($USER->is_logged_in()) {
return get_string('postedbyon', 'artefact.blog', $by, format_date($date));
}
else {
return get_string('postedon', 'artefact.blog') . ' ' . format_date($date);
}
}
/**
* This function updates or inserts the artefact. This involves putting
* some data in the artefact table (handled by parent::commit()), and then
......@@ -877,9 +912,7 @@ class ArtefactTypeBlogPost extends ArtefactType {
}
$smarty->assign('postid', $this->get('id'));
}
$smarty->assign('postedbyon', get_string('postedbyon', 'artefact.blog',
display_name($this->owner),
format_date($this->ctime)));
$smarty->assign('postedbyon', ArtefactTypeBlog::display_postedby($this->ctime, display_name($this->owner)));
if ($this->ctime != $this->mtime) {
$smarty->assign('updatedon', get_string('updatedon', 'artefact.blog') . ' ' . format_date($this->mtime));
}
......@@ -951,6 +984,7 @@ class ArtefactTypeBlogPost extends ArtefactType {
* @param array
*/
public static function get_posts($id, $limit, $offset, $viewoptions=null) {
global $USER;
$results = array(
'limit' => $limit,
......@@ -1025,7 +1059,7 @@ class ArtefactTypeBlogPost extends ArtefactType {
}
else {
$by = $post->author ? display_default_name($post->author) : $post->authorname;
$post->postedby = get_string('postedbyon', 'artefact.blog', $by, format_date($post->ctime));
$post->postedby = ArtefactTypeBlog::display_postedby($post->ctime, $by);
// Get comment counts
if (!empty($viewoptions['countcomments'])) {
safe_require('artefact', 'comment');
......
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