2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Renderers for outputting blog data
22 * @copyright 2012 David MonllaĆ³
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') ||
die();
31 class core_blog_renderer
extends plugin_renderer_base
{
34 * Renders a blog entry
36 * @param blog_entry $entry
37 * @return string The table HTML
39 public function render_blog_entry(blog_entry
$entry) {
43 $syscontext = context_system
::instance();
45 $stredit = get_string('edit');
46 $strdelete = get_string('delete');
49 $mainclass = 'forumpost blog_entry blog clearfix ';
50 if ($entry->renderable
->unassociatedentry
) {
51 $mainclass .= 'draft';
53 $mainclass .= $entry->publishstate
;
55 $o = $this->output
->container_start($mainclass, 'b' . $entry->id
);
56 $o .= $this->output
->container_start('row header clearfix');
59 $o .= $this->output
->container_start('left picture header');
60 $o .= $this->output
->user_picture($entry->renderable
->user
);
61 $o .= $this->output
->container_end();
63 $o .= $this->output
->container_start('topic starter header clearfix');
66 $titlelink = html_writer
::link(new moodle_url('/blog/index.php', array('entryid' => $entry->id
)), format_string($entry->subject
));
67 $o .= $this->output
->container($titlelink, 'subject');
71 $fullname = fullname($entry->renderable
->user
, has_capability('moodle/site:viewfullnames', $syscontext));
72 $userurlparams = array('id' => $entry->renderable
->user
->id
, 'course' => $this->page
->course
->id
);
73 $by->name
= html_writer
::link(new moodle_url('/user/view.php', $userurlparams), $fullname);
75 $by->date
= userdate($entry->created
);
76 $o .= $this->output
->container(get_string('bynameondate', 'forum', $by), 'author');
78 // Adding external blog link.
79 if (!empty($entry->renderable
->externalblogtext
)) {
80 $o .= $this->output
->container($entry->renderable
->externalblogtext
, 'externalblog');
83 // Closing subject tag and header tag.
84 $o .= $this->output
->container_end();
85 $o .= $this->output
->container_end();
88 $o .= $this->output
->container_start('row maincontent clearfix');
91 $o .= $this->output
->container_start('no-overflow content ');
93 // Determine text for publish state.
94 switch ($entry->publishstate
) {
96 $blogtype = get_string('publishtonoone', 'blog');
99 $blogtype = get_string('publishtosite', 'blog');
102 $blogtype = get_string('publishtoworld', 'blog');
109 $o .= $this->output
->container($blogtype, 'audience');
112 $attachmentsoutputs = array();
113 if ($entry->renderable
->attachments
) {
114 foreach ($entry->renderable
->attachments
as $attachment) {
115 $o .= $this->render($attachment, false);
120 $o .= format_text($entry->summary
, $entry->summaryformat
, array('overflowdiv' => true));
122 if (!empty($entry->uniquehash
)) {
123 // Uniquehash is used as a link to an external blog.
124 $url = clean_param($entry->uniquehash
, PARAM_URL
);
126 $o .= $this->output
->container_start('externalblog');
127 $o .= html_writer
::link($url, get_string('linktooriginalentry', 'blog'));
128 $o .= $this->output
->container_end();
133 $officialtags = tag_get_tags_csv('post', $entry->id
, TAG_RETURN_HTML
, 'official');
134 $defaulttags = tag_get_tags_csv('post', $entry->id
, TAG_RETURN_HTML
, 'default');
136 if (!empty($CFG->usetags
) && ($officialtags ||
$defaulttags) ) {
137 $o .= $this->output
->container_start('tags');
140 $o .= get_string('tags', 'tag') .': '. $this->output
->container($officialtags, 'officialblogtags');
146 $o .= $this->output
->container_end();
150 if (!empty($CFG->useblogassociations
) && !empty($entry->renderable
->blogassociations
)) {
152 // First find and show the associated course.
154 $coursesarray = array();
155 foreach ($entry->renderable
->blogassociations
as $assocrec) {
156 if ($assocrec->contextlevel
== CONTEXT_COURSE
) {
157 $coursesarray[] = $this->output
->action_icon($assocrec->url
, $assocrec->icon
, null, array(), true);
160 if (!empty($coursesarray)) {
161 $assocstr .= get_string('associated', 'blog', get_string('course')) . ': ' . implode(', ', $coursesarray);
164 // Now show mod association.
165 $modulesarray = array();
166 foreach ($entry->renderable
->blogassociations
as $assocrec) {
167 if ($assocrec->contextlevel
== CONTEXT_MODULE
) {
168 $str = get_string('associated', 'blog', $assocrec->type
) . ': ';
169 $str .= $this->output
->action_icon($assocrec->url
, $assocrec->icon
, null, array(), true);
170 $modulesarray[] = $str;
173 if (!empty($modulesarray)) {
174 if (!empty($coursesarray)) {
175 $assocstr .= '<br/>';
177 $assocstr .= implode('<br/>', $modulesarray);
180 // Adding the asociations to the output.
181 $o .= $this->output
->container($assocstr, 'tags');
184 if ($entry->renderable
->unassociatedentry
) {
185 $o .= $this->output
->container(get_string('associationunviewable', 'blog'), 'noticebox');
189 $o .= $this->output
->container_start('commands');
190 if ($entry->renderable
->usercanedit
) {
192 // External blog entries should not be edited.
193 if (empty($entry->uniquehash
)) {
194 $o .= html_writer
::link(new moodle_url('/blog/edit.php',
195 array('action' => 'edit', 'entryid' => $entry->id
)),
198 $o .= html_writer
::link(new moodle_url('/blog/edit.php',
199 array('action' => 'delete', 'entryid' => $entry->id
)),
203 $entryurl = new moodle_url('/blog/index.php', array('entryid' => $entry->id
));
204 $o .= html_writer
::link($entryurl, get_string('permalink', 'blog'));
206 $o .= $this->output
->container_end();
208 // Last modification.
209 if ($entry->created
!= $entry->lastmodified
) {
210 $o .= $this->output
->container(' [ '.get_string('modified').': '.userdate($entry->lastmodified
).' ]');
214 if (!empty($entry->renderable
->comment
)) {
215 $o .= $entry->renderable
->comment
->output(true);
218 $o .= $this->output
->container_end();
220 // Closing maincontent div.
221 $o .= $this->output
->container(' ', 'side options');
222 $o .= $this->output
->container_end();
224 $o .= $this->output
->container_end();
230 * Renders an entry attachment
232 * Print link for non-images and returns images as HTML
234 * @param blog_entry_attachment $attachment
235 * @return string List of attachments depending on the $return input
237 public function render_blog_entry_attachment(blog_entry_attachment
$attachment) {
239 $syscontext = context_system
::instance();
241 // Image attachments don't get printed as links.
242 if (file_mimetype_in_typegroup($attachment->file
->get_mimetype(), 'web_image')) {
243 $attrs = array('src' => $attachment->url
, 'alt' => '');
244 $o = html_writer
::empty_tag('img', $attrs);
245 $class = 'attachedimages';
247 $image = $this->output
->pix_icon(file_file_icon($attachment->file
), $attachment->filename
, 'moodle', array('class'=>'icon'));
248 $o = html_writer
::link($attachment->url
, $image);
249 $o .= format_text(html_writer
::link($attachment->url
, $attachment->filename
), FORMAT_HTML
, array('context' => $syscontext));
250 $class = 'attachments';
253 return $this->output
->container($o, $class);