Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
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.
8
//
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.
13
//
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/>.
16
 
17
defined('MOODLE_INTERNAL') || die();
18
 
19
// Blog.
20
require_once($CFG->dirroot . "/blog/renderer.php");
21
class theme_universe_core_blog_renderer extends core_blog_renderer {
22
 
23
    /**
24
     * Renders a blog entry
25
     *
26
     * @param blog_entry $entry
27
     * @return string The table HTML
28
     */
29
    public function render_blog_entry(blog_entry $entry) {
30
 
31
        global $CFG;
32
 
33
        $syscontext = context_system::instance();
34
 
35
        $stredit = get_string('edit');
36
        $strdelete = get_string('delete');
37
 
38
        // Header.
39
        $mainclass = 'wrapper-fw blog blog-entry ';
40
        if ($entry->renderable->unassociatedentry) {
41
            $mainclass .= 'draft';
42
        } else {
43
            $mainclass .= $entry->publishstate;
44
        }
45
        $o = $this->output->container_start($mainclass, 'b' . $entry->id);
46
        $o .= $this->output->container_start('blog-entry-author');
47
 
48
        // User picture.
49
        $o .= $this->output->container_start('d-inline-flex align-items-center justify-content-between w-100');
50
 
51
        // Post by.
52
        $by = new stdClass();
53
        $fullname = fullname($entry->renderable->user, has_capability('moodle/site:viewfullnames', $syscontext));
54
        $userurlparams = array('id' => $entry->renderable->user->id, 'course' => $this->page->course->id);
55
        $by->name = html_writer::link(new moodle_url('/user/view.php', $userurlparams), $fullname);
56
 
57
        $postcreated = userdate($entry->created);
58
 
59
        $o .= $this->output->container_start('blog-entry-date-box d-inline-flex align-items-center justify-content-between');
60
 
61
        $o .= html_writer::start_div('blog-entry-date');
62
        $o .= $postcreated;
63
        $o .= html_writer::end_div();
64
 
65
        // Last modification.
66
        if ($entry->created != $entry->lastmodified) {
67
            $o .= $this->output->container(
68
                    get_string('modified') .
69
                    ': ' .
70
                    userdate($entry->lastmodified),
71
                    'blog-entry-date--mod badge badge-light ml-2'
72
                );
73
        }
74
        $o .= $this->output->container_end(); // Blog-entry-date-box end.
75
 
76
        $o .= $this->output->user_picture($entry->renderable->user);
77
        $o .= $this->output->container_end(); // User picture container end.
78
        $o .= $this->output->container_end(); // User picture and date container end.
79
 
80
        // Title.
81
        $titlelink = html_writer::link(
82
            new moodle_url(
83
                '/blog/index.php',
84
                array('entryid' => $entry->id)
85
            ),
86
            format_string($entry->subject)
87
        );
88
        $o .= $this->output->container_start('blog-entry-topic');
89
        $o .= $this->output->container($titlelink, 'subject wrapper-fw m2-4');
90
 
91
        // Attachments.
92
        $attachmentsoutputs = array();
93
        if ($entry->renderable->attachments) {
94
            foreach ($entry->renderable->attachments as $attachment) {
95
                $o .= $this->render($attachment, false);
96
            }
97
        }
98
 
99
        $o .= $this->output->container_end();
100
 
101
        // Post content.
102
        $o .= $this->output->container_start('blog-entry-content-box');
103
 
104
        // Entry.
105
        $o .= $this->output->container_start('blog-entry');
106
 
107
        // Determine text for publish state.
108
        switch ($entry->publishstate) {
109
            case 'draft':
110
                $blogtype = get_string('publishtonoone', 'blog');
111
                break;
112
            case 'site':
113
                $blogtype = get_string('publishtosite', 'blog');
114
                break;
115
            case 'public':
116
                $blogtype = get_string('publishtoworld', 'blog');
117
                break;
118
            default:
119
                $blogtype = '';
120
                break;
121
        }
122
 
123
        // Body.
124
        if (strpos($this->page->url, 'entryid') == true) {
125
            $o .= format_text($entry->summary, $entry->summaryformat, array('overflowdiv' => true));
126
        } else {
127
            $o .= substr(format_string($entry->summary), 0, 300) . '...';
128
        }
129
 
130
        if (!empty($entry->uniquehash)) {
131
            // Uniquehash is used as a link to an external blog.
132
            $url = clean_param($entry->uniquehash, PARAM_URL);
133
            if (!empty($url)) {
134
                $o .= $this->output->container_start('externalblog badge badge-secondary badge-link');
135
                $o .= html_writer::link($url, get_string('linktooriginalentry', 'blog'));
136
                $o .= $this->output->container_end();
137
            }
138
        }
139
 
140
        // Links to tags.
141
        $o .= $this->output->tag_list(core_tag_tag::get_item_tags('core', 'post', $entry->id));
142
 
143
        // Add associations.
144
        if (!empty($CFG->useblogassociations) && !empty($entry->renderable->blogassociations)) {
145
 
146
            // First find and show the associated course.
147
            $assocstr = '';
148
            $coursesarray = array();
149
            foreach ($entry->renderable->blogassociations as $assocrec) {
150
                if ($assocrec->contextlevel == CONTEXT_COURSE) {
151
                    $coursesarray[] = $this->output->action_icon($assocrec->url, $assocrec->icon, null, array(), true);
152
                }
153
            }
154
            if (!empty($coursesarray)) {
155
                $assocstr .= get_string('associated', 'blog', get_string('course')) . ': ' . implode(', ', $coursesarray);
156
            }
157
 
158
            // Now show mod association.
159
            $modulesarray = array();
160
            foreach ($entry->renderable->blogassociations as $assocrec) {
161
                if ($assocrec->contextlevel == CONTEXT_MODULE) {
162
                    $str = get_string('associated', 'blog', $assocrec->type) . ': ';
163
                    $str .= $this->output->action_icon($assocrec->url, $assocrec->icon, null, array(), true);
164
                    $modulesarray[] = $str;
165
                }
166
            }
167
            if (!empty($modulesarray)) {
168
                if (!empty($coursesarray)) {
169
                    $assocstr .= '<br/>';
170
                }
171
                $assocstr .= implode('<br/>', $modulesarray);
172
            }
173
 
174
            // Adding the asociations to the output.
175
            $o .= $this->output->container($assocstr, 'tags');
176
        }
177
 
178
        if ($entry->renderable->unassociatedentry) {
179
            $o .= $this->output->container(get_string('associationunviewable', 'blog'), 'noticebox');
180
        }
181
 
182
        // Commands.
183
        $o .= $this->output->container_start('blog-entry-footer');
184
        if ($entry->renderable->usercanedit) {
185
 
186
            // External blog entries should not be edited.
187
            if (empty($entry->uniquehash)) {
188
                $icon = '
189
                <svg width="18" height="18" fill="none" viewBox="0 0 24 24">
190
                    <path
191
                        stroke="currentColor"
192
                        stroke-linecap="round"
193
                        stroke-linejoin="round"
194
                        stroke-width="1.5"
195
                        d="M4.75 19.25L9 18.25L18.2929 8.95711C18.6834 8.56658 18.6834 7.93342 18.2929
196
                        7.54289L16.4571 5.70711C16.0666 5.31658 15.4334 5.31658 15.0429
197
                        5.70711L5.75 15L4.75 19.25Z"
198
                        ></path>
199
                    <path
200
                        stroke="currentColor"
201
                        stroke-linecap="round"
202
                        stroke-linejoin="round"
203
                        stroke-width="1.5"
204
                        d="M19.25 19.25H13.75"
205
                    >
206
                    </path>
207
                </svg>';
208
                $o .= html_writer::link(
209
                    new moodle_url(
210
                        '/blog/edit.php',
211
                        array('action' => 'edit', 'entryid' => $entry->id)
212
                    ),
213
                    $icon,
214
                    array('class' => 'btn btn-icon btn-secondary')
215
                );
216
            }
217
            $icon = '<svg width="18" height="18" fill="none" viewBox="0 0 24 24">
218
            <path stroke="currentColor"
219
                stroke-linecap="round"
220
                stroke-linejoin="round"
221
                stroke-width="1.5"
222
                d="M6.75 7.75L7.59115 17.4233C7.68102 18.4568 8.54622 19.25 9.58363
223
                19.25H14.4164C15.4538 19.25 16.319 18.4568 16.4088
224
                17.4233L17.25 7.75"></path>
225
            <path stroke="currentColor"
226
                stroke-linecap="round"
227
                stroke-linejoin="round"
228
                stroke-width="1.5"
229
                d="M9.75 7.5V6.75C9.75 5.64543 10.6454 4.75 11.75 4.75H12.25C13.3546
230
                4.75 14.25 5.64543 14.25 6.75V7.5"></path>
231
            <path stroke="currentColor"
232
                stroke-linecap="round"
233
                stroke-linejoin="round"
234
                stroke-width="1.5"
235
                d="M5 7.75H19"></path>
236
            </svg>';
237
            $o .= html_writer::link(
238
                new moodle_url(
239
                    '/blog/edit.php',
240
                    array('action' => 'delete', 'entryid' => $entry->id)
241
                ),
242
                $icon,
243
                array('class' => 'btn btn-icon btn-danger')
244
            );
245
        }
246
 
247
        $entryurl = new moodle_url('/blog/index.php', array('entryid' => $entry->id));
248
        $icon = '
249
        <svg width="18" height="18" fill="none" viewBox="0 0 24 24">
250
            <path stroke="currentColor"
251
                stroke-linecap="round"
252
                stroke-linejoin="round"
253
                stroke-width="1.5"
254
                d="M13.75 6.75L19.25 12L13.75 17.25"
255
            >
256
            </path>
257
            <path
258
                stroke="currentColor"
259
                stroke-linecap="round"
260
                stroke-linejoin="round"
261
                stroke-width="1.5"
262
                d="M19 12H4.75"
263
            >
264
            </path>
265
        </svg>';
266
        $o .= html_writer::link($entryurl, $icon, array('class' => 'btn btn-icon btn-secondary'));
267
 
268
        $o .= $this->output->container_end();
269
 
270
        // Adding external blog link.
271
        if (!empty($entry->renderable->externalblogtext)) {
272
            $o .= $this->output->container($entry->renderable->externalblogtext, 'externalblog badge badge-light badge-link mt-1');
273
        }
274
 
275
        // Determine text for publish state.
276
        switch ($entry->publishstate) {
277
            case 'draft':
278
                $blogtype = get_string('publishtonoone', 'blog');
279
                break;
280
            case 'site':
281
                $blogtype = get_string('publishtosite', 'blog');
282
                break;
283
            case 'public':
284
                $blogtype = get_string('publishtoworld', 'blog');
285
                break;
286
            default:
287
                $blogtype = '';
288
                break;
289
        }
290
        $o .= $this->output->container($blogtype, 'audience badge badge-light mt-2');
291
 
292
        // Comments.
293
        if (strpos($this->page->url, 'entryid') == true) {
294
            if (!empty($entry->renderable->comment)) {
295
                $o .= $entry->renderable->comment->output(true);
296
            }
297
        }
298
 
299
        $o .= $this->output->container_end();
300
 
301
        // Closing maincontent div.
302
        $o .= $this->output->container('', 'side options');
303
        $o .= $this->output->container_end();
304
 
305
        $o .= $this->output->container_end();
306
 
307
        return $o;
308
    }
309
 
310
    /**
311
     * Renders an entry attachment
312
     *
313
     * Print link for non-images and returns images as HTML
314
     *
315
     * @param blog_entry_attachment $attachment
316
     * @return string List of attachments depending on the $return input
317
     */
318
    public function render_blog_entry_attachment(blog_entry_attachment $attachment) {
319
 
320
        $syscontext = context_system::instance();
321
 
322
        // Image attachments don't get printed as links.
323
        if (file_mimetype_in_typegroup($attachment->file->get_mimetype(), 'web_image')) {
324
            $attrs = array('src' => $attachment->url, 'alt' => '');
325
            $o = html_writer::empty_tag('img', $attrs);
326
            $class = 'blog-entry-cover';
327
        } else {
328
            $image = $this->output->pix_icon(
329
                file_file_icon($attachment->file),
330
                $attachment->filename,
331
                'moodle',
332
                array('class' => 'icon')
333
            );
334
            $o = html_writer::link($attachment->url, $image);
335
            $o .= format_text(
336
                html_writer::link($attachment->url, $attachment->filename),
337
                FORMAT_HTML,
338
                array('context' => $syscontext)
339
            );
340
            $class = 'attachments';
341
        }
342
 
343
        return $this->output->container($o, $class);
344
    }
345
}