mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 12:40:01 +01:00
Merge branch 'MDL-32344_master' of git://github.com/dmonllao/moodle
This commit is contained in:
commit
060eaca70e
@ -105,6 +105,9 @@ if ($id) {
|
||||
}
|
||||
$returnurl->param('userid', $userid);
|
||||
|
||||
// Blog renderer.
|
||||
$output = $PAGE->get_renderer('blog');
|
||||
|
||||
$strblogs = get_string('blogs','blog');
|
||||
|
||||
if ($action === 'delete'){
|
||||
@ -125,7 +128,11 @@ if ($action === 'delete'){
|
||||
$PAGE->set_title("$SITE->shortname: $strblogs");
|
||||
$PAGE->set_heading($SITE->fullname);
|
||||
echo $OUTPUT->header();
|
||||
$entry->print_html();
|
||||
|
||||
// Output the entry.
|
||||
$entry->prepare_render();
|
||||
echo $output->render($entry);
|
||||
|
||||
echo '<br />';
|
||||
echo $OUTPUT->confirm(get_string('blogdeleteconfirm', 'blog'), new moodle_url('edit.php', $optionsyes),new moodle_url( 'index.php', $optionsno));
|
||||
echo $OUTPUT->footer();
|
||||
|
@ -39,7 +39,7 @@ require_once($CFG->libdir . '/filelib.php');
|
||||
* @copyright 2009 Nicolas Connault
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class blog_entry {
|
||||
class blog_entry implements renderable {
|
||||
// Public Database fields
|
||||
public $id;
|
||||
public $userid;
|
||||
@ -66,6 +66,9 @@ class blog_entry {
|
||||
public $form;
|
||||
public $tags = array();
|
||||
|
||||
/** @var StdClass Data needed to render the entry */
|
||||
public $renderable;
|
||||
|
||||
// Methods
|
||||
/**
|
||||
* Constructor. If given an id, will fetch the corresponding record from the DB.
|
||||
@ -89,242 +92,126 @@ class blog_entry {
|
||||
$this->form = $form;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prints or returns the HTML for this blog entry.
|
||||
*
|
||||
* @param bool $return
|
||||
* @return string
|
||||
* Gets the required data to print the entry
|
||||
*/
|
||||
public function print_html($return=false) {
|
||||
public function prepare_render() {
|
||||
|
||||
global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
|
||||
global $DB, $CFG, $PAGE;
|
||||
|
||||
$user = $DB->get_record('user', array('id'=>$this->userid));
|
||||
$cmttext = '';
|
||||
if (!empty($CFG->usecomments) and $CFG->blogusecomments) {
|
||||
$this->renderable = new StdClass();
|
||||
|
||||
$this->renderable->user = $DB->get_record('user', array('id'=>$this->userid));
|
||||
|
||||
// Entry comments.
|
||||
if (!empty($CFG->usecomments) and $CFG->blogusecomments) {
|
||||
require_once($CFG->dirroot . '/comment/lib.php');
|
||||
// Comments
|
||||
$cmt = new stdClass();
|
||||
$cmt->context = context_user::instance($user->id);
|
||||
$cmt->courseid = $PAGE->course->id;
|
||||
$cmt->area = 'format_blog';
|
||||
$cmt->itemid = $this->id;
|
||||
$cmt->showcount = $CFG->blogshowcommentscount;
|
||||
$cmt->component = 'blog';
|
||||
$comment = new comment($cmt);
|
||||
$cmttext = $comment->output(true);
|
||||
|
||||
$cmt = new stdClass();
|
||||
$cmt->context = context_user::instance($this->userid);
|
||||
$cmt->courseid = $PAGE->course->id;
|
||||
$cmt->area = 'format_blog';
|
||||
$cmt->itemid = $this->id;
|
||||
$cmt->showcount = $CFG->blogshowcommentscount;
|
||||
$cmt->component = 'blog';
|
||||
$this->renderable->comment = new comment($cmt);
|
||||
}
|
||||
$this->summary = file_rewrite_pluginfile_urls($this->summary, 'pluginfile.php', SYSCONTEXTID, 'blog', 'post', $this->id);
|
||||
|
||||
$this->summary = file_rewrite_pluginfile_urls($this->summary, 'pluginfile.php', SYSCONTEXTID, 'blog', 'post', $this->id);
|
||||
|
||||
$options = array('overflowdiv'=>true);
|
||||
$template['body'] = format_text($this->summary, $this->summaryformat, $options);
|
||||
$template['title'] = format_string($this->subject);
|
||||
$template['userid'] = $user->id;
|
||||
$template['author'] = fullname($user);
|
||||
$template['created'] = userdate($this->created);
|
||||
|
||||
if ($this->created != $this->lastmodified) {
|
||||
$template['lastmod'] = userdate($this->lastmodified);
|
||||
// External blog link.
|
||||
if ($this->uniquehash && $this->content) {
|
||||
if ($externalblog = $DB->get_record('blog_external', array('id' => $this->content))) {
|
||||
$urlparts = parse_url($externalblog->url);
|
||||
$this->renderable->externalblogtext = get_string('retrievedfrom', 'blog') . get_string('labelsep', 'langconfig');
|
||||
$this->renderable->externalblogtext .= html_writer::link($urlparts['scheme'] . '://'.$urlparts['host'], $externalblog->name);
|
||||
}
|
||||
}
|
||||
|
||||
$template['publishstate'] = $this->publishstate;
|
||||
|
||||
$stredit = get_string('edit');
|
||||
$strdelete = get_string('delete');
|
||||
|
||||
// Check to see if the entry is unassociated with group/course level access
|
||||
$unassociatedentry = false;
|
||||
if (!empty($CFG->useblogassociations) && ($this->publishstate == 'group' || $this->publishstate == 'course')) {
|
||||
if (!$DB->record_exists('blog_association', array('blogid' => $this->id))) {
|
||||
$unassociatedentry = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Start printing of the blog
|
||||
$table = new html_table();
|
||||
$table->cellspacing = 0;
|
||||
$table->attributes['class'] = 'forumpost blog_entry blog'. ($unassociatedentry ? 'draft' : $template['publishstate']);
|
||||
$table->attributes['id'] = 'b'.$this->id;
|
||||
$table->width = '100%';
|
||||
|
||||
$picturecell = new html_table_cell();
|
||||
$picturecell->attributes['class'] = 'picture left';
|
||||
$picturecell->text = $OUTPUT->user_picture($user);
|
||||
|
||||
$table->head[] = $picturecell;
|
||||
|
||||
$topiccell = new html_table_cell();
|
||||
$topiccell->attributes['class'] = 'topic starter';
|
||||
$titlelink = html_writer::link(new moodle_url('/blog/index.php', array('entryid' => $this->id)), $template['title']);
|
||||
$topiccell->text = $OUTPUT->container($titlelink, 'subject');
|
||||
$topiccell->text .= $OUTPUT->container_start('author');
|
||||
|
||||
$fullname = fullname($user, has_capability('moodle/site:viewfullnames', context_course::instance($PAGE->course->id)));
|
||||
$by = new stdClass();
|
||||
$by->name = html_writer::link(new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $PAGE->course->id)), $fullname);
|
||||
$by->date = $template['created'];
|
||||
|
||||
$topiccell->text .= get_string('bynameondate', 'forum', $by);
|
||||
$topiccell->text .= $OUTPUT->container_end();
|
||||
|
||||
if ($this->uniquehash && $this->content) {
|
||||
if ($externalblog = $DB->get_record('blog_external', array('id' => $this->content))) {
|
||||
$urlparts = parse_url($externalblog->url);
|
||||
$topiccell->text .= $OUTPUT->container(get_string('retrievedfrom', 'blog').get_string('labelsep', 'langconfig').html_writer::link($urlparts['scheme'].'://'.$urlparts['host'], $externalblog->name), 'externalblog');
|
||||
}
|
||||
}
|
||||
|
||||
$topiccell->header = false;
|
||||
$table->head[] = $topiccell;
|
||||
|
||||
// Actual content
|
||||
$mainrow = new html_table_row();
|
||||
|
||||
$leftsidecell = new html_table_cell();
|
||||
$leftsidecell->attributes['class'] = 'left side';
|
||||
$mainrow->cells[] = $leftsidecell;
|
||||
|
||||
$contentcell = new html_table_cell();
|
||||
$contentcell->attributes['class'] = 'content';
|
||||
|
||||
$attachedimages = $OUTPUT->container($this->print_attachments(), 'attachments');
|
||||
|
||||
// retrieve associations in case they're needed early
|
||||
$blogassociations = $DB->get_records('blog_association', array('blogid' => $this->id));
|
||||
|
||||
// determine text for publish state
|
||||
switch ($template['publishstate']) {
|
||||
case 'draft':
|
||||
$blogtype = get_string('publishtonoone', 'blog');
|
||||
break;
|
||||
case 'site':
|
||||
$blogtype = get_string('publishtosite', 'blog');
|
||||
break;
|
||||
case 'public':
|
||||
$blogtype = get_string('publishtoworld', 'blog');
|
||||
break;
|
||||
default:
|
||||
$blogtype = '';
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
$contentcell->text .= $OUTPUT->container($blogtype, 'audience');
|
||||
|
||||
$contentcell->text .= $template['body'];
|
||||
$contentcell->text .= $attachedimages;
|
||||
|
||||
// Uniquehash is used as a link to an external blog
|
||||
if (!empty($this->uniquehash)) {
|
||||
$contentcell->text .= $OUTPUT->container_start('externalblog');
|
||||
$contentcell->text .= html_writer::link($this->uniquehash, get_string('linktooriginalentry', 'blog'));
|
||||
$contentcell->text .= $OUTPUT->container_end();
|
||||
}
|
||||
|
||||
// Links to tags
|
||||
$officialtags = tag_get_tags_csv('post', $this->id, TAG_RETURN_HTML, 'official');
|
||||
$defaulttags = tag_get_tags_csv('post', $this->id, TAG_RETURN_HTML, 'default');
|
||||
|
||||
if (!empty($CFG->usetags) && ($officialtags || $defaulttags) ) {
|
||||
$contentcell->text .= $OUTPUT->container_start('tags');
|
||||
|
||||
if ($officialtags) {
|
||||
$contentcell->text .= get_string('tags', 'tag') .': '. $OUTPUT->container($officialtags, 'officialblogtags');
|
||||
if ($defaulttags) {
|
||||
$contentcell->text .= ', ';
|
||||
// Retrieve associations
|
||||
$this->renderable->unassociatedentry = false;
|
||||
if (!empty($CFG->useblogassociations)) {
|
||||
|
||||
// Adding the entry associations data.
|
||||
if ($associations = $associations = $DB->get_records('blog_association', array('blogid' => $this->id))) {
|
||||
|
||||
// Check to see if the entry is unassociated with group/course level access.
|
||||
if ($this->publishstate == 'group' || $this->publishstate == 'course') {
|
||||
$this->renderable->unassociatedentry = true;
|
||||
}
|
||||
}
|
||||
$contentcell->text .= $defaulttags;
|
||||
$contentcell->text .= $OUTPUT->container_end();
|
||||
}
|
||||
|
||||
foreach ($associations as $key => $assocrec) {
|
||||
|
||||
// Add associations
|
||||
if (!empty($CFG->useblogassociations) && $blogassociations) {
|
||||
$contentcell->text .= $OUTPUT->container_start('tags');
|
||||
$assocstr = '';
|
||||
$hascourseassocs = false;
|
||||
$assoctype = '';
|
||||
|
||||
// First find and show the associated course
|
||||
foreach ($blogassociations as $assocrec) {
|
||||
$context = context::instance_by_id($assocrec->contextid);
|
||||
if ($context->contextlevel == CONTEXT_COURSE) {
|
||||
$assocurl = new moodle_url('/course/view.php', array('id' => $context->instanceid));
|
||||
$text = $DB->get_field('course', 'shortname', array('id' => $context->instanceid)); //TODO: performance!!!!
|
||||
$assocstr .= $OUTPUT->action_icon($assocurl, new pix_icon('i/course', $text), null, array(), true);
|
||||
$hascourseassocs = true;
|
||||
$assoctype = get_string('course');
|
||||
}
|
||||
}
|
||||
|
||||
// Now show mod association
|
||||
foreach ($blogassociations as $assocrec) {
|
||||
$context = context::instance_by_id($assocrec->contextid);
|
||||
|
||||
if ($context->contextlevel == CONTEXT_MODULE) {
|
||||
if ($hascourseassocs) {
|
||||
$assocstr .= ', ';
|
||||
$hascourseassocs = false;
|
||||
if (!$context = context::instance_by_id($assocrec->contextid, IGNORE_MISSING)) {
|
||||
unset($associations[$key]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$modinfo = $DB->get_record('course_modules', array('id' => $context->instanceid));
|
||||
$modname = $DB->get_field('modules', 'name', array('id' => $modinfo->module));
|
||||
// The renderer will need the contextlevel of the association.
|
||||
$associations[$key]->contextlevel = $context->contextlevel;
|
||||
|
||||
// Course associations.
|
||||
if ($context->contextlevel == CONTEXT_COURSE) {
|
||||
$instancename = $DB->get_field('course', 'shortname', array('id' => $context->instanceid)); //TODO: performance!!!!
|
||||
|
||||
$assocurl = new moodle_url('/mod/'.$modname.'/view.php', array('id' => $modinfo->id));
|
||||
$text = $DB->get_field($modname, 'name', array('id' => $modinfo->instance)); //TODO: performance!!!!
|
||||
$assocstr .= $OUTPUT->action_icon($assocurl, new pix_icon('icon', $text, $modname), null, array(), true);
|
||||
$assocstr .= ', ';
|
||||
$assoctype = get_string('modulename', $modname);
|
||||
$associations[$key]->url = $assocurl = new moodle_url('/course/view.php', array('id' => $context->instanceid));
|
||||
$associations[$key]->text = $instancename;
|
||||
$associations[$key]->icon = new pix_icon('i/course', $associations[$key]->text);
|
||||
}
|
||||
|
||||
// Mod associations.
|
||||
if ($context->contextlevel == CONTEXT_MODULE) {
|
||||
|
||||
// Getting the activity type and the activity instance id
|
||||
$sql = 'SELECT cm.instance, m.name FROM {course_modules} cm
|
||||
JOIN {modules} m ON m.id = cm.module
|
||||
WHERE cm.id = :cmid';
|
||||
$modinfo = $DB->get_record_sql($sql, array('cmid' => $context->instanceid));
|
||||
$instancename = $DB->get_field($modinfo->name, 'name', array('id' => $modinfo->instance)); //TODO: performance!!!!
|
||||
|
||||
$associations[$key]->type = get_string('modulename', $modinfo->name);
|
||||
$associations[$key]->url = new moodle_url('/mod/' . $modinfo->name . '/view.php', array('id' => $context->instanceid));
|
||||
$associations[$key]->text = $instancename;
|
||||
$associations[$key]->icon = new pix_icon('icon', $associations[$key]->text, $modinfo->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
$assocstr = substr($assocstr, 0, -2);
|
||||
$contentcell->text .= get_string('associated', 'blog', $assoctype) . ': '. $assocstr;
|
||||
$this->renderable->blogassociations = $associations;
|
||||
}
|
||||
|
||||
$contentcell->text .= $OUTPUT->container_end();
|
||||
}
|
||||
// Entry attachments.
|
||||
$this->renderable->attachments = $this->get_attachments();
|
||||
|
||||
if ($unassociatedentry) {
|
||||
$contentcell->text .= $OUTPUT->container(get_string('associationunviewable', 'blog'), 'noticebox');
|
||||
}
|
||||
$this->renderable->usercanedit = blog_user_can_edit_entry($this);
|
||||
}
|
||||
|
||||
/// Commands
|
||||
|
||||
$contentcell->text .= $OUTPUT->container_start('commands');
|
||||
/**
|
||||
* Gets the entry attachments list
|
||||
* @return array List of blog_entry_attachment instances
|
||||
*/
|
||||
function get_attachments() {
|
||||
|
||||
if (blog_user_can_edit_entry($this)) {
|
||||
if (empty($this->uniquehash)) {
|
||||
//External blog entries should not be edited
|
||||
$contentcell->text .= html_writer::link(new moodle_url('/blog/edit.php',
|
||||
array('action' => 'edit', 'entryid' => $this->id)),
|
||||
$stredit) . ' | ';
|
||||
global $CFG;
|
||||
|
||||
require_once($CFG->libdir.'/filelib.php');
|
||||
|
||||
$syscontext = context_system::instance();
|
||||
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_area_files($syscontext->id, 'blog', 'attachment', $this->id);
|
||||
|
||||
// Adding a blog_entry_attachment for each non-directory file.
|
||||
$attachments = array();
|
||||
foreach ($files as $file) {
|
||||
if ($file->is_directory()) {
|
||||
continue;
|
||||
}
|
||||
$contentcell->text .= html_writer::link(new moodle_url('/blog/edit.php',
|
||||
array('action' => 'delete', 'entryid' => $this->id)),
|
||||
$strdelete) . ' | ';
|
||||
}
|
||||
$attachments[] = new blog_entry_attachment($file, $this->id);
|
||||
}
|
||||
|
||||
$contentcell->text .= html_writer::link(new moodle_url('/blog/index.php', array('entryid' => $this->id)), get_string('permalink', 'blog'));
|
||||
|
||||
$contentcell->text .= $OUTPUT->container_end();
|
||||
|
||||
if (isset($template['lastmod']) ){
|
||||
$contentcell->text .= '<div style="font-size: 55%;">';
|
||||
$contentcell->text .= ' [ '.get_string('modified').': '.$template['lastmod'].' ]';
|
||||
$contentcell->text .= '</div>';
|
||||
}
|
||||
|
||||
//add comments under everything
|
||||
$contentcell->text .= $cmttext;
|
||||
|
||||
$mainrow->cells[] = $contentcell;
|
||||
$table->data = array($mainrow);
|
||||
|
||||
if ($return) {
|
||||
return html_writer::table($table);
|
||||
} else {
|
||||
echo html_writer::table($table);
|
||||
}
|
||||
return $attachments;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -480,66 +367,6 @@ class blog_entry {
|
||||
$fs->delete_area_files(SYSCONTEXTID, 'blog', 'post', $this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* if return=html, then return a html string.
|
||||
* if return=text, then return a text-only string.
|
||||
* otherwise, print HTML for non-images, and return image HTML
|
||||
*
|
||||
* @param bool $return Whether to return or print the generated code
|
||||
* @return void
|
||||
*/
|
||||
public function print_attachments($return=false) {
|
||||
global $CFG, $OUTPUT;
|
||||
|
||||
require_once($CFG->libdir.'/filelib.php');
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$syscontext = context_system::instance();
|
||||
|
||||
$files = $fs->get_area_files($syscontext->id, 'blog', 'attachment', $this->id);
|
||||
|
||||
$imagereturn = "";
|
||||
$output = "";
|
||||
|
||||
$strattachment = get_string("attachment", "forum");
|
||||
|
||||
foreach ($files as $file) {
|
||||
if ($file->is_directory()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$filename = $file->get_filename();
|
||||
$ffurl = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.SYSCONTEXTID.'/blog/attachment/'.$this->id.'/'.$filename);
|
||||
$mimetype = $file->get_mimetype();
|
||||
|
||||
$image = $OUTPUT->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon'));
|
||||
|
||||
if ($return == "html") {
|
||||
$output .= html_writer::link($ffurl, $image);
|
||||
$output .= html_writer::link($ffurl, $filename);
|
||||
|
||||
} else if ($return == "text") {
|
||||
$output .= "$strattachment $filename:\n$ffurl\n";
|
||||
|
||||
} else {
|
||||
if (file_mimetype_in_typegroup($file->get_mimetype(), 'web_image')) { // Image attachments don't get printed as links
|
||||
$imagereturn .= '<br /><img src="'.$ffurl.'" alt="" />';
|
||||
} else {
|
||||
$imagereturn .= html_writer::link($ffurl, $image);
|
||||
$imagereturn .= format_text(html_writer::link($ffurl, $filename), FORMAT_HTML, array('context'=>$syscontext));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($return) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
return $imagereturn;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* function to attach tags into an entry
|
||||
* @return void
|
||||
@ -807,9 +634,12 @@ class blog_listing {
|
||||
* @return void
|
||||
*/
|
||||
public function print_entries() {
|
||||
global $CFG, $USER, $DB, $OUTPUT;
|
||||
global $CFG, $USER, $DB, $OUTPUT, $PAGE;
|
||||
$sitecontext = context_system::instance();
|
||||
|
||||
// Blog renderer
|
||||
$output = $PAGE->get_renderer('blog');
|
||||
|
||||
$page = optional_param('blogpage', 0, PARAM_INT);
|
||||
$limit = optional_param('limit', get_user_preferences('blogpagesize', 10), PARAM_INT);
|
||||
$start = $page * $limit;
|
||||
@ -860,10 +690,13 @@ class blog_listing {
|
||||
|
||||
if ($entries) {
|
||||
$count = 0;
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
$blogentry = new blog_entry(null, $entry);
|
||||
$blogentry->print_html();
|
||||
|
||||
// Get the required blog entry data to render it
|
||||
$blogentry->prepare_render();
|
||||
echo $output->render($blogentry);
|
||||
|
||||
$count++;
|
||||
}
|
||||
|
||||
@ -1161,3 +994,30 @@ class blog_filter_search extends blog_filter {
|
||||
$this->params[] = "%$searchterm%";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Renderable class to represent an entry attachment
|
||||
*/
|
||||
class blog_entry_attachment implements renderable {
|
||||
|
||||
public $filename;
|
||||
public $url;
|
||||
public $file;
|
||||
|
||||
/**
|
||||
* Gets the file data
|
||||
*
|
||||
* @param stored_file $file
|
||||
* @param int $entryid Attachment entry id
|
||||
*/
|
||||
public function __construct($file, $entryid) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$this->file = $file;
|
||||
$this->filename = $file->get_filename();
|
||||
$this->url = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.SYSCONTEXTID.'/blog/attachment/'.$entryid.'/'.$this->filename);
|
||||
}
|
||||
|
||||
}
|
||||
|
252
blog/renderer.php
Normal file
252
blog/renderer.php
Normal file
@ -0,0 +1,252 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Renderers for outputting blog data
|
||||
*
|
||||
* @package core_blog
|
||||
* @subpackage blog
|
||||
* @copyright 2012 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Blog renderer
|
||||
*/
|
||||
class core_blog_renderer extends plugin_renderer_base {
|
||||
|
||||
/**
|
||||
* Renders a blog entry
|
||||
*
|
||||
* @param blog_entry $entry
|
||||
* @return string The table HTML
|
||||
*/
|
||||
public function render_blog_entry(blog_entry $entry) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$syscontext = context_system::instance();
|
||||
|
||||
$stredit = get_string('edit');
|
||||
$strdelete = get_string('delete');
|
||||
|
||||
// Header.
|
||||
$mainclass = 'forumpost blog_entry blog clearfix ';
|
||||
if ($entry->renderable->unassociatedentry) {
|
||||
$mainclass .= 'draft';
|
||||
} else {
|
||||
$mainclass .= $entry->publishstate;
|
||||
}
|
||||
$o = $this->output->container_start($mainclass, 'b' . $entry->id);
|
||||
$o .= $this->output->container_start('row header clearfix');
|
||||
|
||||
// User picture.
|
||||
$o .= $this->output->container_start('left picture header');
|
||||
$o .= $this->output->user_picture($entry->renderable->user);
|
||||
$o .= $this->output->container_end();
|
||||
|
||||
$o .= $this->output->container_start('topic starter header clearfix');
|
||||
|
||||
// Title.
|
||||
$titlelink = html_writer::link(new moodle_url('/blog/index.php', array('entryid' => $entry->id)), format_string($entry->subject));
|
||||
$o .= $this->output->container($titlelink, 'subject');
|
||||
|
||||
// Post by.
|
||||
$by = new stdClass();
|
||||
$fullname = fullname($entry->renderable->user, has_capability('moodle/site:viewfullnames', $syscontext));
|
||||
$userurlparams = array('id' => $entry->renderable->user->id, 'course' => $this->page->course->id);
|
||||
$by->name = html_writer::link(new moodle_url('/user/view.php', $userurlparams), $fullname);
|
||||
|
||||
$by->date = userdate($entry->created);
|
||||
$o .= $this->output->container(get_string('bynameondate', 'forum', $by), 'author');
|
||||
|
||||
// Adding external blog link.
|
||||
if (!empty($entry->renderable->externalblogtext)) {
|
||||
$o .= $this->output->container($entry->renderable->externalblogtext, 'externalblog');
|
||||
}
|
||||
|
||||
// Closing subject tag and header tag.
|
||||
$o .= $this->output->container_end();
|
||||
$o .= $this->output->container_end();
|
||||
|
||||
// Post content.
|
||||
$o .= $this->output->container_start('row maincontent clearfix');
|
||||
|
||||
// Entry.
|
||||
$o .= $this->output->container_start('no-overflow content ');
|
||||
|
||||
// Determine text for publish state.
|
||||
switch ($entry->publishstate) {
|
||||
case 'draft':
|
||||
$blogtype = get_string('publishtonoone', 'blog');
|
||||
break;
|
||||
case 'site':
|
||||
$blogtype = get_string('publishtosite', 'blog');
|
||||
break;
|
||||
case 'public':
|
||||
$blogtype = get_string('publishtoworld', 'blog');
|
||||
break;
|
||||
default:
|
||||
$blogtype = '';
|
||||
break;
|
||||
|
||||
}
|
||||
$o .= $this->output->container($blogtype, 'audience');
|
||||
|
||||
// Attachments.
|
||||
$attachmentsoutputs = array();
|
||||
if ($entry->renderable->attachments) {
|
||||
foreach ($entry->renderable->attachments as $attachment) {
|
||||
$o .= $this->render($attachment, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Body.
|
||||
$o .= format_text($entry->summary, $entry->summaryformat, array('overflowdiv' => true));
|
||||
|
||||
// Uniquehash is used as a link to an external blog.
|
||||
if (!empty($entry->uniquehash)) {
|
||||
$o .= $this->output->container_start('externalblog');
|
||||
$o .= html_writer::link($entry->uniquehash, get_string('linktooriginalentry', 'blog'));
|
||||
$o .= $this->output->container_end();
|
||||
}
|
||||
|
||||
// Links to tags.
|
||||
$officialtags = tag_get_tags_csv('post', $entry->id, TAG_RETURN_HTML, 'official');
|
||||
$defaulttags = tag_get_tags_csv('post', $entry->id, TAG_RETURN_HTML, 'default');
|
||||
|
||||
if (!empty($CFG->usetags) && ($officialtags || $defaulttags) ) {
|
||||
$o .= $this->output->container_start('tags');
|
||||
|
||||
if ($officialtags) {
|
||||
$o .= get_string('tags', 'tag') .': '. $this->output->container($officialtags, 'officialblogtags');
|
||||
if ($defaulttags) {
|
||||
$o .= ', ';
|
||||
}
|
||||
}
|
||||
$o .= $defaulttags;
|
||||
$o .= $this->output->container_end();
|
||||
}
|
||||
|
||||
// Add associations.
|
||||
if (!empty($CFG->useblogassociations) && !empty($entry->renderable->blogassociations)) {
|
||||
|
||||
// First find and show the associated course.
|
||||
$assocstr = '';
|
||||
$coursesarray = array();
|
||||
foreach ($entry->renderable->blogassociations as $assocrec) {
|
||||
if ($assocrec->contextlevel == CONTEXT_COURSE) {
|
||||
$coursesarray[] = $this->output->action_icon($assocrec->url, $assocrec->icon, null, array(), true);
|
||||
}
|
||||
}
|
||||
if (!empty($coursesarray)) {
|
||||
$assocstr .= get_string('associated', 'blog', get_string('course')) . ': ' . implode(', ', $coursesarray);
|
||||
}
|
||||
|
||||
// Now show mod association.
|
||||
$modulesarray = array();
|
||||
foreach ($entry->renderable->blogassociations as $assocrec) {
|
||||
if ($assocrec->contextlevel == CONTEXT_MODULE) {
|
||||
$str = get_string('associated', 'blog', $assocrec->type) . ': ';
|
||||
$str .= $this->output->action_icon($assocrec->url, $assocrec->icon, null, array(), true);
|
||||
$modulesarray[] = $str;
|
||||
}
|
||||
}
|
||||
if (!empty($modulesarray)) {
|
||||
if (!empty($coursesarray)) {
|
||||
$assocstr .= '<br/>';
|
||||
}
|
||||
$assocstr .= implode('<br/>', $modulesarray);
|
||||
}
|
||||
|
||||
// Adding the asociations to the output.
|
||||
$o .= $this->output->container($assocstr, 'tags');
|
||||
}
|
||||
|
||||
if ($entry->renderable->unassociatedentry) {
|
||||
$o .= $this->output->container(get_string('associationunviewable', 'blog'), 'noticebox');
|
||||
}
|
||||
|
||||
// Commands.
|
||||
$o .= $this->output->container_start('commands');
|
||||
if ($entry->renderable->usercanedit) {
|
||||
|
||||
// External blog entries should not be edited.
|
||||
if (empty($entry->uniquehash)) {
|
||||
$o .= html_writer::link(new moodle_url('/blog/edit.php',
|
||||
array('action' => 'edit', 'entryid' => $entry->id)),
|
||||
$stredit) . ' | ';
|
||||
}
|
||||
$o .= html_writer::link(new moodle_url('/blog/edit.php',
|
||||
array('action' => 'delete', 'entryid' => $entry->id)),
|
||||
$strdelete) . ' | ';
|
||||
}
|
||||
|
||||
$entryurl = new moodle_url('/blog/index.php', array('entryid' => $entry->id));
|
||||
$o .= html_writer::link($entryurl, get_string('permalink', 'blog'));
|
||||
|
||||
$o .= $this->output->container_end();
|
||||
|
||||
// Last modification.
|
||||
if ($entry->created != $entry->lastmodified) {
|
||||
$o .= $this->output->container(' [ '.get_string('modified').': '.userdate($entry->lastmodified).' ]');
|
||||
}
|
||||
|
||||
// Comments.
|
||||
if (!empty($entry->renderable->comment)) {
|
||||
$o .= $entry->renderable->comment->output(true);
|
||||
}
|
||||
|
||||
$o .= $this->output->container_end();
|
||||
|
||||
// Closing maincontent div.
|
||||
$o .= $this->output->container(' ', 'side options');
|
||||
$o .= $this->output->container_end();
|
||||
|
||||
$o .= $this->output->container_end();
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders an entry attachment
|
||||
*
|
||||
* Print link for non-images and returns images as HTML
|
||||
*
|
||||
* @param blog_entry_attachment $attachment
|
||||
* @return string List of attachments depending on the $return input
|
||||
*/
|
||||
public function render_blog_entry_attachment(blog_entry_attachment $attachment) {
|
||||
|
||||
$syscontext = context_system::instance();
|
||||
|
||||
// Image attachments don't get printed as links.
|
||||
if (file_mimetype_in_typegroup($attachment->file->get_mimetype(), 'web_image')) {
|
||||
$attrs = array('src' => $attachment->url, 'alt' => '');
|
||||
$o = html_writer::empty_tag('img', $attrs);
|
||||
$class = 'attachedimages';
|
||||
} else {
|
||||
$image = $this->output->pix_icon(file_file_icon($attachment->file), $attachment->filename, 'moodle', array('class'=>'icon'));
|
||||
$o = html_writer::link($attachment->url, $image);
|
||||
$o .= format_text(html_writer::link($attachment->url, $attachment->filename), FORMAT_HTML, array('context' => $syscontext));
|
||||
$class = 'attachments';
|
||||
}
|
||||
|
||||
return $this->output->container($o, $class);
|
||||
}
|
||||
}
|
@ -191,6 +191,10 @@ h2.headingblock {
|
||||
padding: 5px 10px 10px;
|
||||
}
|
||||
|
||||
/* Blogs */
|
||||
|
||||
.blog_entry .content {margin-left: 43px;}
|
||||
|
||||
/* Dock */
|
||||
|
||||
#dock {
|
||||
@ -298,4 +302,4 @@ h2.headingblock {
|
||||
}
|
||||
#custommenu .custom_menu_submenu .custom_menu_submenu .yui3-menu-content {
|
||||
border-top:1px solid #DDD;
|
||||
}
|
||||
}
|
||||
|
@ -252,8 +252,9 @@ input#id_externalurl {direction:ltr;}
|
||||
* Blogs
|
||||
*/
|
||||
.addbloglink {text-align: center;}
|
||||
.blog_entry .audience {text-align: right;}
|
||||
.blog_entry .audience {text-align: right;padding-right: 4px;}
|
||||
.blog_entry .tags {margin-top: 15px;}
|
||||
.blog_entry .content {margin-left: 43px;}
|
||||
|
||||
/**
|
||||
* Group
|
||||
|
Loading…
x
Reference in New Issue
Block a user