MDL-20523 Script for upgrading sites that use the old bloglevel settings.
[moodle.git] / blog / lib.php
CommitLineData
cae83708 1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18
19/**
20 * Core global functions for Blog.
21 *
22 * @package moodlecore
23 * @subpackage blog
24 * @copyright 2009 Nicolas Connault
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 */
27
28/**
29 * Library of functions and constants for blog
30 */
31require_once($CFG->dirroot .'/blog/rsslib.php');
32require_once($CFG->dirroot.'/tag/lib.php');
33
34/**
35 * Definition of blogcourse page type (blog page with course id present).
36 */
37//not used at the moment, and may not need to be
38define('PAGE_BLOG_COURSE_VIEW', 'blog_course-view');
947eaf57 39define('BLOG_PUBLISHSTATE_DRAFT', 0);
40define('BLOG_PUBLISHSTATE_SITE', 1);
41define('BLOG_PUBLISHSTATE_PUBLIC', 2);
cae83708 42
43/**
44 * Checks to see if user has visited blogpages before, if not, install 2
45 * default blocks (blog_menu and blog_tags).
46 */
47function blog_check_and_install_blocks() {
48 global $USER, $DB;
49
ec7c4f11 50 if (isloggedin() && !isguestuser()) {
cae83708 51 // if this user has not visited this page before
52 if (!get_user_preferences('blogpagesize')) {
53 // find the correct ids for blog_menu and blog_from blocks
54 $menublock = $DB->get_record('block', array('name'=>'blog_menu'));
55 $tagsblock = $DB->get_record('block', array('name'=>'blog_tags'));
56 // add those 2 into block_instance page
8c9814f9 57
f474a4e5 58// Commmented out since the block changes broke it. Hopefully nico will fix it ;-)
59// // add blog_menu block
60// $newblock = new object();
61// $newblock->blockid = $menublock->id;
62// $newblock->pageid = $USER->id;
63// $newblock->pagetype = 'blog-view';
64// $newblock->position = 'r';
65// $newblock->weight = 0;
66// $newblock->visible = 1;
67// $DB->insert_record('block_instances', $newblock);
68//
69// // add blog_tags menu
70// $newblock -> blockid = $tagsblock->id;
71// $newblock -> weight = 1;
72// $DB->insert_record('block_instances', $newblock);
8c9814f9 73
cae83708 74 // finally we set the page size pref
75 set_user_preference('blogpagesize', 10);
8c9814f9 76 }
77 }
cae83708 78}
8c9814f9 79
80
cae83708 81/**
82 * User can edit a blog entry if this is their own blog entry and they have
83 * the capability moodle/blog:create, or if they have the capability
84 * moodle/blog:manageentries.
85 *
86 * This also applies to deleting of entries.
87 */
88function blog_user_can_edit_entry($blog_entry) {
89 global $CFG, $USER, $OUTPUT;
6524adcf 90
cae83708 91 $sitecontext = get_context_instance(CONTEXT_SYSTEM);
4a173181 92
cae83708 93 if (has_capability('moodle/blog:manageentries', $sitecontext)) {
94 return true; // can edit any blog entry
95 }
c2ee4e87 96
cae83708 97 if ($blog_entry->userid == $USER->id
98 and has_capability('moodle/blog:create', $sitecontext)) {
99 return true; // can edit own when having blog:create capability
100 }
4a173181 101
cae83708 102 return false;
103}
d02240f3 104
3bfcfdca 105
cae83708 106/**
107 * Checks to see if a user can view the blogs of another user.
108 * Only blog level is checked here, the capabilities are enforced
109 * in blog/index.php
110 */
111function blog_user_can_view_user_entry($targetuserid, $blog_entry=null) {
112 global $CFG, $USER, $DB;
c2ee4e87 113
cae83708 114 if (empty($CFG->bloglevel)) {
115 return false; // blog system disabled
116 }
117
118 if (!empty($USER->id) and $USER->id == $targetuserid) {
119 return true; // can view own entries in any case
120 }
121
122 $sitecontext = get_context_instance(CONTEXT_SYSTEM);
123 if (has_capability('moodle/blog:manageentries', $sitecontext)) {
124 return true; // can manage all entries
125 }
c2ee4e87 126
cae83708 127 // coming for 1 entry, make sure it's not a draft
128 if ($blog_entry and $blog_entry->publishstate == 'draft') {
129 return false; // can not view draft of others
130 }
131
132 // coming for 1 entry, make sure user is logged in, if not a public blog
133 if ($blog_entry && $blog_entry->publishstate != 'public' && !isloggedin()) {
134 return false;
135 }
d02240f3 136
cae83708 137 switch ($CFG->bloglevel) {
138 case BLOG_GLOBAL_LEVEL:
139 return true;
140 break;
c2ee4e87 141
cae83708 142 case BLOG_SITE_LEVEL:
143 if (!empty($USER->id)) { // not logged in viewers forbidden
144 return true;
c2ee4e87 145 }
cae83708 146 return false;
147 break;
d02240f3 148
cae83708 149 case BLOG_USER_LEVEL:
150 default:
151 $personalcontext = get_context_instance(CONTEXT_USER, $targetuserid);
152 return has_capability('moodle/user:readuserblogs', $personalcontext);
153 break;
4a173181 154
cae83708 155 }
156}
157
158/**
159 * remove all associations for the blog entries of a particular user
160 * @param int userid - id of user whose blog associations will be deleted
161 */
162function blog_remove_associations_for_user($userid) {
163 global $DB;
164 foreach(blog_fetch_entries(array('user' => $userid), 'lasmodified DESC') as $entry) {
165 blog_remove_associations_for_entry($entry->id);
166 }
167 }
168
169/**
170 * generates the url of the page displaying entries matching the search criteria
171 * @param array filters an array of filters (filtername => filtervalue) to narrow down results by
172 * available filters:
173 * entry: id field of a specific entry
174 * course: id of a course that the entries must be associated with
175 * mod: id of a course module that the entries must be associated with
176 * user: id of a user who must be the author of an entry
177 * group: id of a group who the author must be a member of, and whose course must be associated with the entry
178 * tag: id of a tag that must be applied to the entry
179 * site: the entire site is searched
180 * @return string the url of the page displaying entries matching the search criteria
181 */
182function blog_get_blogs_url($filters) {
183 global $CFG;
b0e90a0c 184 $blogsurl = new moodle_url($CFG->wwwroot . '/blog/index.php');
185 if (!empty($filters['course'])) {
186 $blogsurl->param('courseid', $filters['course']);
187 }
188 if (!empty($filters['mod'])) {
189 $blogsurl->param('modid', $filters['mod']);
190 }
191 if (!empty($filters['group'])) {
192 $blogsurl->param('groupid', $filters['group']);
193 }
194 if (!empty($filters['user'])) {
195 $blogsurl->param('userid', $filters['user']);
196 }
197 if (!empty($filters['entry'])) {
198 $blogsurl->param('entryid', $filters['entry']);
199 }
200 if (!empty($filters['tag'])) {
201 $blogsurl->param('tagid', $filters['tag']);
202 }
203 if (!empty($filters['tagtext'])) {
204 $blogsurl->param('tag', $filters['tagtext']);
205 }
206 return $blogsurl;
cae83708 207}
208
209/**
210 * A simple function for checking if a given URL is valid and resolves
211 * to a proper XML data stream.
212 *
213 * @param string $url
214 * @return bool
215 */
216function blog_is_valid_url($url) {
217 $url = @parse_url($url);
218
219 if (!$url) {
220 return false;
221 }
bd70af13 222
cae83708 223 $url = array_map('trim', $url);
4a173181 224
cae83708 225 if (empty($url['port'])) {
226 $url['port'] = 80;
227 } else {
228 $url['port'] = (int)$url['port'];
229 }
4a173181 230
cae83708 231 $path = '';
232 if (!empty($url['path'])) {
233 $path = $url['path'];
234 }
4a173181 235
4a173181 236
cae83708 237 if ($path == '') {
238 $path = '/';
239 }
4a173181 240
cae83708 241 if (!empty($url['query'])) {
242 $path .= "?{$url['query']}";
243 }
d02240f3 244
cae83708 245 if (isset($url['host']) && $url['host'] != gethostbyname($url['host'])) {
246 if (PHP_VERSION >= 5) {
247 $headers = get_headers("{$url['scheme']}://{$url['host']}:{$url['port']}$path");
7d0e5a95 248 } else {
cae83708 249 $fp = fsockopen($url['host'], $url['port'], $errno, $errstr, 30);
4a173181 250
cae83708 251 if (!$fp) {
252 return false;
253 }
4a173181 254
cae83708 255 fputs($fp, "HEAD $path HTTP/1.1\r\nHost: {$url['host']}\r\n\r\n");
256 $headers = fread($fp, 128);
257 fclose($fp);
4a173181 258 }
c2ee4e87 259
cae83708 260 if (is_array($headers)) {
261 $headers = implode("\n", $headers);
18d330b0 262 }
263
cae83708 264 return (bool) preg_match('#^HTTP/.*\s+[(200|301|302)]+\s#i', $headers);
4a173181 265 }
cae83708 266 return false;
267}
268
e96f2a77 269
cae83708 270/**
271 * Given a record in the {blog_external} table, checks the blog's URL
272 * for new entries not yet copied into Moodle.
273 *
274 * @param object $external_blog
275 * @return void
276 */
277function blog_fetch_external_entries($external_blog) {
278 global $CFG, $DB;
e14de6f9 279 require_once($CFG->libdir . '/simplepie/moodle_simplepie.php');
4a173181 280
cae83708 281 if (!blog_is_valid_url($external_blog->url)) {
282 return null;
c2ee4e87 283 }
4a173181 284
e14de6f9 285 $rss = new moodle_simplepie($external_blog->url);
c2ee4e87 286
e14de6f9 287 if (empty($rss->data)) {
cae83708 288 return null;
289 }
b13ee30e 290
e14de6f9 291 foreach ($rss->get_items() as $entry) {
cae83708 292 $params = array('userid' => $external_blog->userid,
293 'module' => 'blog',
e14de6f9 294 'uniquehash' => $entry->get_permalink(),
cae83708 295 'publishstate' => 'site',
296 'format' => FORMAT_HTML);
c2ee4e87 297
947eaf57 298 if (!$DB->record_exists('blog_entries', $params)) {
e14de6f9 299 $params['subject'] = $entry->get_title();
300 $params['summary'] = $entry->get_description();
301 $params['created'] = $entry->get_date('U');
302 $params['lastmodified'] = $entry->get_date('U');
c2ee4e87 303
947eaf57 304 $id = $DB->insert_record('blog_entries', $params);
e96f2a77 305
cae83708 306 // Set tags
307 if ($tags = tag_get_tags_array('blog_external', $external_blog->id)) {
947eaf57 308 tag_set('blog_entries', $id, $tags);
c2ee4e87 309 }
310 }
cae83708 311 }
c2ee4e87 312
cae83708 313 $DB->update_record('blog_external', array('id' => $external_blog->id, 'timefetched' => mktime()));
314}
d02240f3 315
cae83708 316/**
317 * Returns a URL based on the context of the current page.
318 * This URL points to blog/index.php and includes filter parameters appropriate for the current page.
319 *
320 * @param stdclass $context
321 * @return string
322 */
323function blog_get_context_url($context=null) {
324 global $CFG;
c2ee4e87 325
b0e90a0c 326 $viewblogentriesurl = new moodle_url($CFG->wwwroot . '/blog/index.php');
c2ee4e87 327
cae83708 328 if (empty($context)) {
329 global $PAGE;
330 $context = $PAGE->get_context();
331 }
c2ee4e87 332
cae83708 333 // Change contextlevel to SYSTEM if viewing the site course
334 if ($context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID) {
335 $context->contextlevel = CONTEXT_SYSTEM;
336 }
c2ee4e87 337
cae83708 338 $filterparam = '';
339 $strlevel = '';
c2ee4e87 340
cae83708 341 switch ($context->contextlevel) {
342 case CONTEXT_SYSTEM:
343 case CONTEXT_BLOCK:
344 case CONTEXT_COURSECAT:
c2ee4e87 345 break;
cae83708 346 case CONTEXT_COURSE:
347 $filterparam = 'courseid';
348 $strlevel = get_string('course');
c2ee4e87 349 break;
cae83708 350 case CONTEXT_MODULE:
351 $filterparam = 'modid';
352 $strlevel = print_context_name($context);
c2ee4e87 353 break;
cae83708 354 case CONTEXT_USER:
355 $filterparam = 'userid';
356 $strlevel = get_string('user');
c2ee4e87 357 break;
516194d0 358 }
359
cae83708 360 if (!empty($filterparam)) {
b0e90a0c 361 $viewblogentriesurl->param($filterparam, $context->instanceid);
cae83708 362 }
bbbf2d40 363
b0e90a0c 364 return $viewblogentriesurl;
cae83708 365}
366
367/**
368 * This function encapsulates all the logic behind the complex
369 * navigation, titles and headings of the blog listing page, depending
370 * on URL params. It builds and returns an array containing:
371 *
c5dc10ee 372 * 1. The heading displayed above the blog entries
373 * All other variables are set directly in $PAGE
cae83708 374 *
375 * It uses the current URL to build these variables.
376 * A number of mutually exclusive use cases are used to structure this function.
377 *
378 * @return array
379 */
380function blog_get_headers() {
381 global $CFG, $PAGE, $DB, $USER;
382
9366362a 383 $id = optional_param('id', null, PARAM_INT);
cae83708 384 $tag = optional_param('tag', null, PARAM_NOTAGS);
385 $tagid = optional_param('tagid', null, PARAM_INT);
386 $userid = optional_param('userid', null, PARAM_INT);
387 $modid = optional_param('modid', null, PARAM_INT);
388 $entryid = optional_param('entryid', null, PARAM_INT);
389 $groupid = optional_param('groupid', null, PARAM_INT);
390 $courseid = optional_param('courseid', null, PARAM_INT);
391 $search = optional_param('search', null, PARAM_RAW);
392 $action = optional_param('action', null, PARAM_ALPHA);
393 $confirm = optional_param('confirm', false, PARAM_BOOL);
394
e640790e 395 $headers = array('title' => '', 'heading' => '', 'cm' => null);
cae83708 396
397 $blog_url = new moodle_url($CFG->wwwroot . '/blog/index.php');
398 $site = $DB->get_record('course', array('id' => SITEID));
399
400 // Common Lang strings
401 $strparticipants = get_string("participants");
402 $strblogentries = get_string("blogentries", 'blog');
403
404 // Prepare record objects as needed
405 if (!empty($courseid)) {
406 $course = $DB->get_record('course', array('id' => $courseid));
407 }
e96f2a77 408
cae83708 409 if (!empty($userid)) {
410 $user = $DB->get_record('user', array('id' => $userid));
516194d0 411 }
bbbf2d40 412
cae83708 413 if (!empty($groupid)) { // groupid always overrides courseid
414 $group = $DB->get_record('groups', array('id' => $groupid));
415 $course = $DB->get_record('course', array('id' => $group->courseid));
416 }
bbbf2d40 417
cae83708 418 if (!empty($modid)) { // modid always overrides courseid, so the $course object may be reset here
419 // A groupid param may conflict with this coursemod's courseid. Ignore groupid in that case
420 $course_id = $DB->get_field('course_modules', 'course', array('id'=>$modid));
421 $course = $DB->get_record('course', array('id' => $course_id));
422 $cm = $DB->get_record('course_modules', array('id' => $modid));
423 $cm->modname = $DB->get_field('modules', 'name', array('id' => $cm->module));
424 $cm->name = $DB->get_field($cm->modname, 'name', array('id' => $cm->instance));
c5dc10ee 425 $cm->context = get_context_instance(CONTEXT_MODULE, $modid);
426 $PAGE->set_cm($cm, $course);
cae83708 427 }
b73d1ca4 428
4a8b890a 429 // Case 0: No entry, mod, course or user params: all site entries to be shown (filtered by search and tag/tagid)
430 if (empty($entryid) && empty($modid) && empty($courseid) && empty($userid)) {
431 $PAGE->navbar->add($strblogentries, $blog_url);
432 $PAGE->set_title("$site->shortname: " . get_string('blog', 'blog'));
433 $PAGE->set_heading("$site->shortname: " . get_string('blog', 'blog'));
434 $headers['heading'] = get_string('siteblog', 'blog');
435 }
c2ee4e87 436
cae83708 437 // Case 1: only entryid is requested, ignore all other filters. courseid is used to give more contextual information
b73d1ca4 438 // TODO Blog entries link has entryid instead of userid
cae83708 439 if (!empty($entryid)) {
947eaf57 440 $sql = 'SELECT u.* FROM {user} u, {blog_entries} p WHERE p.id = ? AND p.userid = u.id';
cae83708 441 $user = $DB->get_record_sql($sql, array($entryid));
947eaf57 442 $entry = $DB->get_record('blog_entries', array('id' => $entryid));
c2ee4e87 443
cae83708 444 $blog_url->param('userid', $user->id);
c2ee4e87 445
cae83708 446 if (!empty($course)) {
9366362a 447 $mycourseid = $course->id;
448 $blog_url->param('courseid', $mycourseid);
c2ee4e87 449 } else {
9366362a 450 $mycourseid = $site->id;
c2ee4e87 451 }
e14de6f9 452
9366362a 453 $PAGE->navbar->add($strparticipants, "$CFG->wwwroot/user/index.php?id=$mycourseid");
c5dc10ee 454 $PAGE->navbar->add(fullname($user), "$CFG->wwwroot/user/view.php?id=$user->id");
9366362a 455 $PAGE->navbar->add($strblogentries, $blog_url);
456 $blog_url->param('entryid', $entryid);
457 $blog_url->remove_params('userid');
458 $PAGE->navbar->add($entry->subject, $blog_url);
c5dc10ee 459
460 $PAGE->set_title("$site->shortname: " . fullname($user) . ": $entry->subject");
461 $PAGE->set_heading("$site->shortname: " . fullname($user) . ": $entry->subject");
cae83708 462 $headers['heading'] = get_string('blogentrybyuser', 'blog', fullname($user));
463
464 // We ignore tag and search params
9366362a 465 if (empty($action)) {
466 return $headers;
467 }
c2ee4e87 468 }
240075cd 469
cae83708 470 // Case 2: A user's blog entries
9366362a 471 if (!empty($userid) && empty($modid) && empty($courseid) && empty($entryid)) {
cae83708 472 $blog_url->param('userid', $userid);
c5dc10ee 473 $PAGE->navbar->add($strparticipants, "$CFG->wwwroot/user/index.php?id=$site->id");
474 $PAGE->navbar->add(fullname($user), "$CFG->wwwroot/user/view.php?id=$user->id");
9366362a 475 $PAGE->navbar->add($strblogentries, $blog_url);
c5dc10ee 476 $PAGE->set_title("$site->shortname: " . fullname($user) . ": " . get_string('blog', 'blog'));
477 $PAGE->set_heading("$site->shortname: " . fullname($user) . ": " . get_string('blog', 'blog'));
cae83708 478 $headers['heading'] = get_string('userblog', 'blog', fullname($user));
479
480 } else
481
482 // Case 3: Blog entries associated with an activity by a specific user (courseid ignored)
9366362a 483 if (!empty($userid) && !empty($modid) && empty($entryid)) {
cae83708 484 $blog_url->param('userid', $userid);
485 $blog_url->param('modid', $modid);
486
487 // Course module navigation is handled by build_navigation as the second param
488 $headers['cm'] = $cm;
c5dc10ee 489 $PAGE->navbar->add(fullname($user), "$CFG->wwwroot/user/view.php?id=$user->id");
9366362a 490 $PAGE->navbar->add($strblogentries, $blog_url);
cae83708 491
c5dc10ee 492 $PAGE->set_title("$site->shortname: $cm->name: " . fullname($user) . ': ' . get_string('blogentries', 'blog'));
493 $PAGE->set_heading("$site->shortname: $cm->name: " . fullname($user) . ': ' . get_string('blogentries', 'blog'));
cae83708 494
495 $a->user = fullname($user);
496 $a->mod = $cm->name;
497 $headers['heading'] = get_string('blogentriesbyuseraboutmodule', 'blog', $a);
498 } else
499
500 // Case 4: Blog entries associated with a course by a specific user
9366362a 501 if (!empty($userid) && !empty($courseid) && empty($modid) && empty($entryid)) {
cae83708 502 $blog_url->param('userid', $userid);
503 $blog_url->param('courseid', $courseid);
504
c5dc10ee 505 $PAGE->navbar->add($strparticipants, "$CFG->wwwroot/user/index.php?id=$course->id");
506 $PAGE->navbar->add(fullname($user), "$CFG->wwwroot/user/view.php?id=$user->id");
9366362a 507 $PAGE->navbar->add($strblogentries, $blog_url);
cae83708 508
c5dc10ee 509 $PAGE->set_title("$site->shortname: $course->shortname: " . fullname($user) . ': ' . get_string('blogentries', 'blog'));
510 $PAGE->set_heading("$site->shortname: $course->shortname: " . fullname($user) . ': ' . get_string('blogentries', 'blog'));
cae83708 511
512 $a->user = fullname($user);
513 $a->course = $course->fullname;
514 $headers['heading'] = get_string('blogentriesbyuseraboutcourse', 'blog', $a);
515 } else
516
517 // Case 5: Blog entries by members of a group, associated with that group's course
9366362a 518 if (!empty($groupid) && empty($modid) && empty($entryid)) {
cae83708 519 $blog_url->param('courseid', $course->id);
e14de6f9 520
9366362a 521 $PAGE->navbar->add($strblogentries, $blog_url);
cae83708 522 $blog_url->remove_params(array('courseid'));
523 $blog_url->param('groupid', $groupid);
9366362a 524 $PAGE->navbar->add($group->name, $blog_url);
cae83708 525
c5dc10ee 526 $PAGE->set_title("$site->shortname: $course->shortname: " . get_string('blogentries', 'blog') . ": $group->name");
527 $PAGE->set_heading("$site->shortname: $course->shortname: " . get_string('blogentries', 'blog') . ": $group->name");
cae83708 528
529 $a->group = $group->name;
530 $a->course = $course->fullname;
531 $headers['heading'] = get_string('blogentriesbygroupaboutcourse', 'blog', $a);
532 } else
533
534 // Case 6: Blog entries by members of a group, associated with an activity in that course
9366362a 535 if (!empty($groupid) && !empty($modid) && empty($entryid)) {
cae83708 536 $headers['cm'] = $cm;
537 $blog_url->param('modid', $modid);
9366362a 538 $PAGE->navbar->add($strblogentries, $blog_url);
cae83708 539
540 $blog_url->param('groupid', $groupid);
9366362a 541 $PAGE->navbar->add($group->name, $blog_url);
cae83708 542
c5dc10ee 543 $PAGE->set_title("$site->shortname: $course->shortname: $cm->name: " . get_string('blogentries', 'blog') . ": $group->name");
544 $PAGE->set_heading("$site->shortname: $course->shortname: $cm->name: " . get_string('blogentries', 'blog') . ": $group->name");
cae83708 545
546 $a->group = $group->name;
547 $a->mod = $cm->name;
548 $headers['heading'] = get_string('blogentriesbygroupaboutmodule', 'blog', $a);
549
550 } else
551
552 // Case 7: All blog entries associated with an activity
9366362a 553 if (!empty($modid) && empty($userid) && empty($groupid) && empty($entryid)) {
c5dc10ee 554 $PAGE->set_cm($cm, $course);
cae83708 555 $blog_url->param('modid', $modid);
9366362a 556 $PAGE->navbar->add($strblogentries, $blog_url);
c5dc10ee 557 $PAGE->set_title("$site->shortname: $course->shortname: $cm->name: " . get_string('blogentries', 'blog'));
558 $PAGE->set_heading("$site->shortname: $course->shortname: $cm->name: " . get_string('blogentries', 'blog'));
cae83708 559 $headers['heading'] = get_string('blogentriesabout', 'blog', $cm->name);
560 } else
561
562 // Case 8: All blog entries associated with a course
9366362a 563 if (!empty($courseid) && empty($userid) && empty($groupid) && empty($modid) && empty($entryid)) {
cae83708 564 $blog_url->param('courseid', $courseid);
9366362a 565 $PAGE->navbar->add($strblogentries, $blog_url);
c5dc10ee 566 $PAGE->set_title("$site->shortname: $course->shortname: " . get_string('blogentries', 'blog'));
567 $PAGE->set_heading("$site->shortname: $course->shortname: " . get_string('blogentries', 'blog'));
cae83708 568 $headers['heading'] = get_string('blogentriesabout', 'blog', $course->fullname);
569 }
570
571 // Append Tag info
572 if (!empty($tagid)) {
573 $blog_url->param('tagid', $tagid);
574 $tagrec = $DB->get_record('tag', array('id'=>$tagid));
9366362a 575 $PAGE->navbar->add($tagrec->name, $blog_url);
cae83708 576 } elseif (!empty($tag)) {
577 $blog_url->param('tag', $tag);
9366362a 578 $PAGE->navbar->add(get_string('tagparam', 'blog', $tag), $blog_url);
cae83708 579 }
240075cd 580
ee00eb8c 581 // Append Search info
582 if (!empty($search)) {
583 $blog_url->param('search', $search);
584 $PAGE->navbar->add(get_string('searchterm', 'blog', $search), $blog_url->out());
585 }
586
cae83708 587 // Append edit mode info
588 if (!empty($action) && $action == 'add') {
9366362a 589 if (empty($modid) && empty($courseid)) {
590 if (empty($user)) {
591 $user = $USER;
592 }
593 $PAGE->navbar->add($strparticipants, "$CFG->wwwroot/user/index.php?id=$site->id");
594 $PAGE->navbar->add(fullname($user), "$CFG->wwwroot/user/view.php?id=$user->id");
595 }
c5dc10ee 596 $PAGE->navbar->add(get_string('addnewentry', 'blog'));
cae83708 597 } else if (!empty($action) && $action == 'edit') {
c5dc10ee 598 $PAGE->navbar->add(get_string('editentry', 'blog'));
240075cd 599 }
ee00eb8c 600
cae83708 601 return $headers;
602}
23677261 603
604function blog_extend_settings_navigation($settingsnav) {
605 global $USER, $PAGE, $FULLME, $CFG, $DB, $OUTPUT;
606 $blogkey = $settingsnav->add(get_string('blogadministration', 'blog'));
607 $blog = $settingsnav->get($blogkey);
608 $blog->forceopen = true;
b73d1ca4 609
23677261 610 $blog->add(get_string('preferences', 'blog'), new moodle_url('preferences.php'), navigation_node::TYPE_SETTING);
611 if ($CFG->useexternalblogs && $CFG->maxexternalblogsperuser > 0) {
612 $blog->add(get_string('externalblogs', 'blog'), new moodle_url('external.php'), navigation_node::TYPE_SETTING);
613 }
614
615 return $blogkey;
616}