Commit 659664be authored by Son Nguyen's avatar Son Nguyen Committed by Robert Lyon
Browse files

Make sure draft post not visible. Bug 1387858



- Filter out draft posts when editing the blogpost block
- Don't display the post's content if it is unpublished

Change-Id: Iaaf92f29383e2f3997e214b052dd116005a971dd
Signed-off-by: default avatarSon Nguyen <son.nguyen@catalyst.net.nz>
parent 259550c9
......@@ -15,3 +15,5 @@ $string['title'] = 'Journal entry';
$string['description'] = 'A single entry from your journal (see Content -> Journal)';
$string['defaulttitledescription'] = 'If you leave this blank, the title of the journal entry will be used';
$string['choosepublishedblogpostsdescription'] = 'Select one of your published journal entries.';
......@@ -109,7 +109,12 @@ class PluginBlocktypeBlogpost extends PluginBlocktype {
// Note: the owner check will have to change when we do group/site
// blogs
if (empty($configdata['artefactid']) || $blog->get('owner') == $USER->get('id')) {
$elements[] = self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null);
$publishedposts = get_column_sql('
SELECT a.id
FROM {artefact} a
INNER JOIN {artefact_blog_blogpost} p ON p.blogpost = a.id
WHERE p.published = 1 AND a.owner= ?', array($USER->get('id')));
$elements[] = self::artefactchooser_element((isset($configdata['artefactid'])) ? $configdata['artefactid'] : null, $publishedposts);
$elements[] = PluginArtefactBlog::block_advanced_options_element($configdata, 'blogpost');
}
else {
......@@ -122,17 +127,19 @@ class PluginBlocktypeBlogpost extends PluginBlocktype {
return $elements;
}
public static function artefactchooser_element($default=null) {
public static function artefactchooser_element($default=null, $publishedposts=array()) {
$element = array(
'name' => 'artefactid',
'type' => 'artefactchooser',
'title' => get_string('blogpost', 'artefact.blog'),
'description' => get_string('choosepublishedblogpostsdescription', 'blocktype.blog/blogpost'),
'defaultvalue' => $default,
'blocktype' => 'blogpost',
'limit' => 10,
'selectone' => true,
'artefacttypes' => array('blogpost'),
'template' => 'artefact:blog:artefactchooser-element.tpl',
'extraselect' => !empty($publishedposts) ? array(array('fieldname' => 'id', 'type' => 'int', 'values' => $publishedposts)) : null,
);
return $element;
}
......
......@@ -94,6 +94,7 @@ $string['nposts'] = array(
);
$string['publish'] = 'Publish';
$string['publishit'] = 'Publish it.';
$string['unpublish'] = 'Unpublish';
$string['publishfailed'] = 'An error occurred. Your entry was not published.';
$string['publishblogpost?'] = 'Are you sure you want to publish this entry?';
......@@ -158,3 +159,4 @@ $string['progress_blogpost'] = array(
'Add 1 entry to a journal',
'Add %s entries to a journal',
);
$string['notpublishedblogpost'] = 'This journal entry has not been published yet.';
......@@ -621,7 +621,17 @@ class ArtefactTypeBlogPost extends ArtefactType {
}
public function render_self($options) {
global $USER;
$smarty = smarty_core();
$smarty->assign('published', $this->get('published'));
if (!$this->get('published')) {
$notpublishedblogpoststr = get_string('notpublishedblogpost', 'artefact.blog');
if ($this->get('owner') == $USER->get('id')) {
$notpublishedblogpoststr .= ' <a href="' . get_config('wwwroot') . 'artefact/blog/post.php?id=' . $this->get('id') . '">' . get_string('publishit', 'artefact.blog') . '</a>';
}
$smarty->assign('notpublishedblogpost', $notpublishedblogpoststr);
}
$artefacturl = get_config('wwwroot') . 'view/artefact.php?artefact=' . $this->get('id');
if (isset($options['viewid'])) {
$artefacturl .= '&view=' . $options['viewid'];
......
{**
* This template displays a blog post.
*}
{if $published}
<div id="blogpost">
{if $artefacttitle}<h3 class="title">{$artefacttitle|safe}</h3>{/if}
<div class="postdetails">{$postedbyon}</div>
......@@ -39,3 +40,8 @@
{/if}
{if isset($commentcount) && $artefact->get('allowcomments')}<div class="postdetails"><a href="{$artefacturl}">{str tag=Comments section=artefact.comment} ({$commentcount})</a></div>{/if}
</div>
{else}
<div>
{$notpublishedblogpost|safe}
</div>
{/if}
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