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 // Uniquehash is used as a link to an external blog.
123 if (!empty($entry->uniquehash
)) {
124 $o .= $this->output
->container_start('externalblog');
125 $o .= html_writer
::link($entry->uniquehash
, get_string('linktooriginalentry', 'blog'));
126 $o .= $this->output
->container_end();
130 $officialtags = tag_get_tags_csv('post', $entry->id
, TAG_RETURN_HTML
, 'official');
131 $defaulttags = tag_get_tags_csv('post', $entry->id
, TAG_RETURN_HTML
, 'default');
133 if (!empty($CFG->usetags
) && ($officialtags ||
$defaulttags) ) {
134 $o .= $this->output
->container_start('tags');
137 $o .= get_string('tags', 'tag') .': '. $this->output
->container($officialtags, 'officialblogtags');
143 $o .= $this->output
->container_end();
147 if (!empty($CFG->useblogassociations
) && !empty($entry->renderable
->blogassociations
)) {
149 // First find and show the associated course.
151 $coursesarray = array();
152 foreach ($entry->renderable
->blogassociations
as $assocrec) {
153 if ($assocrec->contextlevel
== CONTEXT_COURSE
) {
154 $coursesarray[] = $this->output
->action_icon($assocrec->url
, $assocrec->icon
, null, array(), true);
157 if (!empty($coursesarray)) {
158 $assocstr .= get_string('associated', 'blog', get_string('course')) . ': ' . implode(', ', $coursesarray);
161 // Now show mod association.
162 $modulesarray = array();
163 foreach ($entry->renderable
->blogassociations
as $assocrec) {
164 if ($assocrec->contextlevel
== CONTEXT_MODULE
) {
165 $str = get_string('associated', 'blog', $assocrec->type
) . ': ';
166 $str .= $this->output
->action_icon($assocrec->url
, $assocrec->icon
, null, array(), true);
167 $modulesarray[] = $str;
170 if (!empty($modulesarray)) {
171 if (!empty($coursesarray)) {
172 $assocstr .= '<br/>';
174 $assocstr .= implode('<br/>', $modulesarray);
177 // Adding the asociations to the output.
178 $o .= $this->output
->container($assocstr, 'tags');
181 if ($entry->renderable
->unassociatedentry
) {
182 $o .= $this->output
->container(get_string('associationunviewable', 'blog'), 'noticebox');
186 $o .= $this->output
->container_start('commands');
187 if ($entry->renderable
->usercanedit
) {
189 // External blog entries should not be edited.
190 if (empty($entry->uniquehash
)) {
191 $o .= html_writer
::link(new moodle_url('/blog/edit.php',
192 array('action' => 'edit', 'entryid' => $entry->id
)),
195 $o .= html_writer
::link(new moodle_url('/blog/edit.php',
196 array('action' => 'delete', 'entryid' => $entry->id
)),
200 $entryurl = new moodle_url('/blog/index.php', array('entryid' => $entry->id
));
201 $o .= html_writer
::link($entryurl, get_string('permalink', 'blog'));
203 $o .= $this->output
->container_end();
205 // Last modification.
206 if ($entry->created
!= $entry->lastmodified
) {
207 $o .= $this->output
->container(' [ '.get_string('modified').': '.userdate($entry->lastmodified
).' ]');
211 if (!empty($entry->renderable
->comment
)) {
212 $o .= $entry->renderable
->comment
->output(true);
215 $o .= $this->output
->container_end();
217 // Closing maincontent div.
218 $o .= $this->output
->container(' ', 'side options');
219 $o .= $this->output
->container_end();
221 $o .= $this->output
->container_end();
227 * Renders an entry attachment
229 * Print link for non-images and returns images as HTML
231 * @param blog_entry_attachment $attachment
232 * @return string List of attachments depending on the $return input
234 public function render_blog_entry_attachment(blog_entry_attachment
$attachment) {
236 $syscontext = context_system
::instance();
238 // Image attachments don't get printed as links.
239 if (file_mimetype_in_typegroup($attachment->file
->get_mimetype(), 'web_image')) {
240 $attrs = array('src' => $attachment->url
, 'alt' => '');
241 $o = html_writer
::empty_tag('img', $attrs);
242 $class = 'attachedimages';
244 $image = $this->output
->pix_icon(file_file_icon($attachment->file
), $attachment->filename
, 'moodle', array('class'=>'icon'));
245 $o = html_writer
::link($attachment->url
, $image);
246 $o .= format_text(html_writer
::link($attachment->url
, $attachment->filename
), FORMAT_HTML
, array('context' => $syscontext));
247 $class = 'attachments';
250 return $this->output
->container($o, $class);