MDL-30386 blog : saved a function call
[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
cae83708 18/**
19 * Core global functions for Blog.
20 *
21 * @package moodlecore
22 * @subpackage blog
23 * @copyright 2009 Nicolas Connault
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 */
26
35716b86
PS
27defined('MOODLE_INTERNAL') || die();
28
cae83708 29/**
30 * Library of functions and constants for blog
31 */
32require_once($CFG->dirroot .'/blog/rsslib.php');
33require_once($CFG->dirroot.'/tag/lib.php');
34
cae83708 35/**
36 * User can edit a blog entry if this is their own blog entry and they have
37 * the capability moodle/blog:create, or if they have the capability
38 * moodle/blog:manageentries.
39 *
40 * This also applies to deleting of entries.
41 */
1c7b8b93
NC
42function blog_user_can_edit_entry($blogentry) {
43 global $USER;
6524adcf 44
cae83708 45 $sitecontext = get_context_instance(CONTEXT_SYSTEM);
4a173181 46
cae83708 47 if (has_capability('moodle/blog:manageentries', $sitecontext)) {
48 return true; // can edit any blog entry
49 }
c2ee4e87 50
1c7b8b93 51 if ($blogentry->userid == $USER->id && has_capability('moodle/blog:create', $sitecontext)) {
cae83708 52 return true; // can edit own when having blog:create capability
53 }
4a173181 54
cae83708 55 return false;
56}
d02240f3 57
3bfcfdca 58
cae83708 59/**
60 * Checks to see if a user can view the blogs of another user.
61 * Only blog level is checked here, the capabilities are enforced
62 * in blog/index.php
63 */
1c7b8b93 64function blog_user_can_view_user_entry($targetuserid, $blogentry=null) {
cae83708 65 global $CFG, $USER, $DB;
c2ee4e87 66
cae83708 67 if (empty($CFG->bloglevel)) {
68 return false; // blog system disabled
69 }
70
2c27b6ae 71 if (isloggedin() && $USER->id == $targetuserid) {
cae83708 72 return true; // can view own entries in any case
73 }
74
75 $sitecontext = get_context_instance(CONTEXT_SYSTEM);
76 if (has_capability('moodle/blog:manageentries', $sitecontext)) {
77 return true; // can manage all entries
78 }
c2ee4e87 79
cae83708 80 // coming for 1 entry, make sure it's not a draft
1c7b8b93 81 if ($blogentry && $blogentry->publishstate == 'draft' && !has_capability('moodle/blog:viewdrafts', $sitecontext)) {
cae83708 82 return false; // can not view draft of others
83 }
84
bb8a75e7 85 // coming for 0 entry, make sure user is logged in, if not a public blog
1c7b8b93 86 if ($blogentry && $blogentry->publishstate != 'public' && !isloggedin()) {
cae83708 87 return false;
88 }
d02240f3 89
cae83708 90 switch ($CFG->bloglevel) {
91 case BLOG_GLOBAL_LEVEL:
92 return true;
93 break;
c2ee4e87 94
cae83708 95 case BLOG_SITE_LEVEL:
4f0c2d00 96 if (isloggedin()) { // not logged in viewers forbidden
cae83708 97 return true;
c2ee4e87 98 }
cae83708 99 return false;
100 break;
d02240f3 101
cae83708 102 case BLOG_USER_LEVEL:
103 default:
104 $personalcontext = get_context_instance(CONTEXT_USER, $targetuserid);
105 return has_capability('moodle/user:readuserblogs', $personalcontext);
106 break;
4a173181 107
cae83708 108 }
109}
110
111/**
112 * remove all associations for the blog entries of a particular user
113 * @param int userid - id of user whose blog associations will be deleted
114 */
115function blog_remove_associations_for_user($userid) {
1c7b8b93 116 global $DB;
d91181dc
PS
117 throw new coding_exception('function blog_remove_associations_for_user() is not finished');
118 /*
1c7b8b93
NC
119 $blogentries = blog_fetch_entries(array('user' => $userid), 'lasmodified DESC');
120 foreach ($blogentries as $entry) {
121 if (blog_user_can_edit_entry($entry)) {
122 blog_remove_associations_for_entry($entry->id);
123 }
b0e90a0c 124 }
d91181dc 125 */
cae83708 126}
127
128/**
1c7b8b93
NC
129 * remove all associations for the blog entries of a particular course
130 * @param int courseid - id of user whose blog associations will be deleted
cae83708 131 */
1c7b8b93
NC
132function blog_remove_associations_for_course($courseid) {
133 global $DB;
134 $context = get_context_instance(CONTEXT_COURSE, $courseid);
135 $DB->delete_records('blog_association', array('contextid' => $context->id));
cae83708 136}
137
cae83708 138/**
139 * Given a record in the {blog_external} table, checks the blog's URL
b7c1da93 140 * for new entries not yet copied into Moodle.
50ff50da 141 * Also attempts to identify and remove deleted blog entries
cae83708 142 *
1c7b8b93
NC
143 * @param object $externalblog
144 * @return boolean False if the Feed is invalid
cae83708 145 */
1c7b8b93 146function blog_sync_external_entries($externalblog) {
cae83708 147 global $CFG, $DB;
e14de6f9 148 require_once($CFG->libdir . '/simplepie/moodle_simplepie.php');
4a173181 149
1c7b8b93
NC
150 $rssfile = new moodle_simplepie_file($externalblog->url);
151 $filetest = new SimplePie_Locator($rssfile);
152
a537e507
EL
153 $textlib = textlib_get_instance(); // Going to use textlib services
154
1c7b8b93
NC
155 if (!$filetest->is_feed($rssfile)) {
156 $externalblog->failedlastsync = 1;
157 $DB->update_record('blog_external', $externalblog);
158 return false;
8397492b 159 } else if (!empty($externalblog->failedlastsync)) {
1c7b8b93
NC
160 $externalblog->failedlastsync = 0;
161 $DB->update_record('blog_external', $externalblog);
c2ee4e87 162 }
4a173181 163
1c7b8b93 164 $rss = new moodle_simplepie($externalblog->url);
c2ee4e87 165
e14de6f9 166 if (empty($rss->data)) {
cae83708 167 return null;
168 }
50ff50da 169 //used to identify blog posts that have been deleted from the source feed
cc52e53d 170 $oldesttimestamp = null;
50ff50da 171 $uniquehashes = array();
b13ee30e 172
e14de6f9 173 foreach ($rss->get_items() as $entry) {
1c7b8b93
NC
174 // If filtertags are defined, use them to filter the entries by RSS category
175 if (!empty($externalblog->filtertags)) {
176 $containsfiltertag = false;
177 $categories = $entry->get_categories();
178 $filtertags = explode(',', $externalblog->filtertags);
179 $filtertags = array_map('trim', $filtertags);
180 $filtertags = array_map('strtolower', $filtertags);
181
182 foreach ($categories as $category) {
183 if (in_array(trim(strtolower($category->term)), $filtertags)) {
184 $containsfiltertag = true;
185 }
186 }
187
188 if (!$containsfiltertag) {
189 continue;
c2ee4e87 190 }
191 }
c484c852 192
50ff50da 193 $uniquehashes[] = $entry->get_permalink();
1c7b8b93 194
e463f508 195 $newentry = new stdClass();
1c7b8b93
NC
196 $newentry->userid = $externalblog->userid;
197 $newentry->module = 'blog_external';
198 $newentry->content = $externalblog->id;
199 $newentry->uniquehash = $entry->get_permalink();
200 $newentry->publishstate = 'site';
201 $newentry->format = FORMAT_HTML;
a537e507
EL
202 // Clean subject of html, just in case
203 $newentry->subject = clean_param($entry->get_title(), PARAM_TEXT);
204 // Observe 128 max chars in DB
205 // TODO: +1 to raise this to 255
206 if ($textlib->strlen($newentry->subject) > 128) {
207 $newentry->subject = $textlib->substr($newentry->subject, 0, 125) . '...';
208 }
1c7b8b93 209 $newentry->summary = $entry->get_description();
c484c852 210
9829e3d8 211 //used to decide whether to insert or update
212 //uses enty permalink plus creation date if available
bb8a75e7 213 $existingpostconditions = array('uniquehash' => $entry->get_permalink());
99cd408f 214
9829e3d8 215 //our DB doesnt allow null creation or modified timestamps so check the external blog supplied one
99cd408f 216 $entrydate = $entry->get_date('U');
afce96f0 217 if (!empty($entrydate)) {
218 $existingpostconditions['created'] = $entrydate;
219 }
c484c852 220
e5137f24 221 //the post ID or false if post not found in DB
afce96f0 222 $postid = $DB->get_field('post', 'id', $existingpostconditions);
c484c852 223
afce96f0 224 $timestamp = null;
99cd408f 225 if (empty($entrydate)) {
afce96f0 226 $timestamp = time();
99cd408f 227 } else {
afce96f0 228 $timestamp = $entrydate;
99cd408f 229 }
c484c852 230
afce96f0 231 //only set created if its a new post so we retain the original creation timestamp if the post is edited
bb8a75e7 232 if ($postid === false) {
afce96f0 233 $newentry->created = $timestamp;
234 }
235 $newentry->lastmodified = $timestamp;
694fb770 236
bb8a75e7 237 if (empty($oldesttimestamp) || $timestamp < $oldesttimestamp) {
cc52e53d 238 //found an older post
239 $oldesttimestamp = $timestamp;
240 }
1c7b8b93 241
3b59524d 242 $textlib = textlib_get_instance();
ca824b38 243 if ($textlib->strlen($newentry->uniquehash) > 255) {
3b59524d
SH
244 // The URL for this item is too long for the field. Rather than add
245 // the entry without the link we will skip straight over it.
246 // RSS spec says recommended length 500, we use 255.
247 debugging('External blog entry skipped because of oversized URL', DEBUG_DEVELOPER);
248 continue;
249 }
250
bb8a75e7 251 if ($postid === false) {
9829e3d8 252 $id = $DB->insert_record('post', $newentry);
1c7b8b93 253
9829e3d8 254 // Set tags
255 if ($tags = tag_get_tags_array('blog_external', $externalblog->id)) {
256 tag_set('post', $id, $tags);
257 }
258 } else {
259 $newentry->id = $postid;
afce96f0 260 $DB->update_record('post', $newentry);
1c7b8b93 261 }
cae83708 262 }
c484c852 263
ed79b89b
DM
264 // Look at the posts we have in the database to check if any of them have been deleted from the feed.
265 // Only checking posts within the time frame returned by the rss feed. Older items may have been deleted or
266 // may just not be returned anymore. We can't tell the difference so we leave older posts alone.
267 $sql = "SELECT id, uniquehash
268 FROM {post}
269 WHERE module = 'blog_external'
270 AND " . $DB->sql_compare_text('content') . " = " . $DB->sql_compare_text(':blogid') . "
271 AND created > :ts";
42291c61
AD
272 $dbposts = $DB->get_records_sql($sql, array('blogid' => $externalblog->id, 'ts' => $oldesttimestamp));
273
50ff50da 274 $todelete = array();
275 foreach($dbposts as $dbpost) {
29487578 276 if ( !in_array($dbpost->uniquehash, $uniquehashes) ) {
50ff50da 277 $todelete[] = $dbpost->id;
278 }
279 }
280 $DB->delete_records_list('post', 'id', $todelete);
c2ee4e87 281
e5137f24 282 $DB->update_record('blog_external', array('id' => $externalblog->id, 'timefetched' => time()));
1c7b8b93
NC
283}
284
285/**
286 * Given an external blog object, deletes all related blog entries from the post table.
287 * NOTE: The external blog's id is saved as post.content, a field that is not oterhwise used by blog entries.
288 * @param object $externablog
289 */
290function blog_delete_external_entries($externalblog) {
291 global $DB;
292 require_capability('moodle/blog:manageexternal', get_context_instance(CONTEXT_SYSTEM));
a742eb1f
EL
293 $DB->delete_records_select('post',
294 "module='blog_external' AND " . $DB->sql_compare_text('content') . " = ?",
295 array($externalblog->id));
cae83708 296}
d02240f3 297
cae83708 298/**
299 * Returns a URL based on the context of the current page.
300 * This URL points to blog/index.php and includes filter parameters appropriate for the current page.
301 *
302 * @param stdclass $context
303 * @return string
304 */
305function blog_get_context_url($context=null) {
306 global $CFG;
c2ee4e87 307
a6855934 308 $viewblogentriesurl = new moodle_url('/blog/index.php');
c2ee4e87 309
cae83708 310 if (empty($context)) {
311 global $PAGE;
5515b536 312 $context = $PAGE->context;
cae83708 313 }
c2ee4e87 314
cae83708 315 // Change contextlevel to SYSTEM if viewing the site course
316 if ($context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID) {
317 $context->contextlevel = CONTEXT_SYSTEM;
318 }
c2ee4e87 319
cae83708 320 $filterparam = '';
321 $strlevel = '';
c2ee4e87 322
cae83708 323 switch ($context->contextlevel) {
324 case CONTEXT_SYSTEM:
325 case CONTEXT_BLOCK:
326 case CONTEXT_COURSECAT:
c2ee4e87 327 break;
cae83708 328 case CONTEXT_COURSE:
329 $filterparam = 'courseid';
330 $strlevel = get_string('course');
c2ee4e87 331 break;
cae83708 332 case CONTEXT_MODULE:
333 $filterparam = 'modid';
334 $strlevel = print_context_name($context);
c2ee4e87 335 break;
cae83708 336 case CONTEXT_USER:
337 $filterparam = 'userid';
338 $strlevel = get_string('user');
c2ee4e87 339 break;
516194d0 340 }
341
cae83708 342 if (!empty($filterparam)) {
b0e90a0c 343 $viewblogentriesurl->param($filterparam, $context->instanceid);
cae83708 344 }
bbbf2d40 345
b0e90a0c 346 return $viewblogentriesurl;
cae83708 347}
348
27bad0a6 349/**
593270c6 350 * This function checks that blogs are enabled, and that the user can see blogs at all
27bad0a6
SH
351 * @return bool
352 */
353function blog_is_enabled_for_user() {
354 global $CFG;
593270c6
MD
355 //return (!empty($CFG->bloglevel) && $CFG->bloglevel <= BLOG_GLOBAL_LEVEL && isloggedin() && !isguestuser());
356 return (!empty($CFG->bloglevel) && (isloggedin() || ($CFG->bloglevel == BLOG_GLOBAL_LEVEL)));
27bad0a6
SH
357}
358
359/**
360 * This function gets all of the options available for the current user in respect
361 * to blogs.
897aa80c 362 *
27bad0a6
SH
363 * It loads the following if applicable:
364 * - Module options {@see blog_get_options_for_module}
365 * - Course options {@see blog_get_options_for_course}
366 * - User specific options {@see blog_get_options_for_user}
367 * - General options (BLOG_LEVEL_GLOBAL)
368 *
369 * @param moodle_page $page The page to load for (normally $PAGE)
370 * @param stdClass $userid Load for a specific user
371 * @return array An array of options organised by type.
372 */
373function blog_get_all_options(moodle_page $page, stdClass $userid = null) {
374 global $CFG, $DB, $USER;
375
376 $options = array();
377
378 // If blogs are enabled and the user is logged in and not a guest
379 if (blog_is_enabled_for_user()) {
380 // If the context is the user then assume we want to load for the users context
381 if (is_null($userid) && $page->context->contextlevel == CONTEXT_USER) {
382 $userid = $page->context->instanceid;
383 }
384 // Check the userid var
385 if (!is_null($userid) && $userid!==$USER->id) {
386 // Load the user from the userid... it MUST EXIST throw a wobbly if it doesn't!
387 $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
388 } else {
389 $user = null;
390 }
391
392 if ($CFG->useblogassociations && $page->cm !== null) {
393 // Load for the module associated with the page
394 $options[CONTEXT_MODULE] = blog_get_options_for_module($page->cm, $user);
395 } else if ($CFG->useblogassociations && $page->course->id != SITEID) {
396 // Load the options for the course associated with the page
397 $options[CONTEXT_COURSE] = blog_get_options_for_course($page->course, $user);
398 }
399
400 // Get the options for the user
5b183f51 401 if ($user !== null and !isguestuser($user)) {
27bad0a6
SH
402 // Load for the requested user
403 $options[CONTEXT_USER+1] = blog_get_options_for_user($user);
404 }
405 // Load for the current user
5b183f51
PS
406 if (isloggedin() and !isguestuser()) {
407 $options[CONTEXT_USER] = blog_get_options_for_user();
408 }
27bad0a6
SH
409 }
410
411 // If blog level is global then display a link to view all site entries
412 if (!empty($CFG->bloglevel) && $CFG->bloglevel >= BLOG_GLOBAL_LEVEL && has_capability('moodle/blog:view', get_context_instance(CONTEXT_SYSTEM))) {
413 $options[CONTEXT_SYSTEM] = array('viewsite' => array(
414 'string' => get_string('viewsiteentries', 'blog'),
415 'link' => new moodle_url('/blog/index.php')
416 ));
417 }
418
419 // Return the options
420 return $options;
421}
422
423/**
424 * Get all of the blog options that relate to the passed user.
425 *
426 * If no user is passed the current user is assumed.
427 *
428 * @staticvar array $useroptions Cache so we don't have to regenerate multiple times
429 * @param stdClass $user
430 * @return array The array of options for the requested user
431 */
432function blog_get_options_for_user(stdClass $user=null) {
433 global $CFG, $USER;
434 // Cache
435 static $useroptions = array();
436
437 $options = array();
438 // Blogs must be enabled and the user must be logged in
439 if (!blog_is_enabled_for_user()) {
440 return $options;
441 }
442
443 // Sort out the user var
444 if ($user === null || $user->id == $USER->id) {
445 $user = $USER;
446 $iscurrentuser = true;
447 } else {
448 $iscurrentuser = false;
449 }
450
451 // If we've already generated serve from the cache
452 if (array_key_exists($user->id, $useroptions)) {
453 return $useroptions[$user->id];
454 }
455
456 $sitecontext = get_context_instance(CONTEXT_SYSTEM);
457 $canview = has_capability('moodle/blog:view', $sitecontext);
458
459 if (!$iscurrentuser && $canview && ($CFG->bloglevel >= BLOG_SITE_LEVEL)) {
460 // Not the current user, but we can view and its blogs are enabled for SITE or GLOBAL
461 $options['userentries'] = array(
462 'string' => get_string('viewuserentries', 'blog', fullname($user)),
463 'link' => new moodle_url('/blog/index.php', array('userid'=>$user->id))
464 );
465 } else {
466 // It's the current user
467 if ($canview) {
468 // We can view our own blogs .... BIG surprise
469 $options['view'] = array(
470 'string' => get_string('viewallmyentries', 'blog'),
471 'link' => new moodle_url('/blog/index.php', array('userid'=>$USER->id))
472 );
473 }
474 if (has_capability('moodle/blog:create', $sitecontext)) {
475 // We can add to our own blog
476 $options['add'] = array(
477 'string' => get_string('addnewentry', 'blog'),
478 'link' => new moodle_url('/blog/edit.php', array('action'=>'add'))
479 );
480 }
481 }
0f4c6067 482 if ($canview && $CFG->enablerssfeeds) {
c000545d
JF
483 $options['rss'] = array(
484 'string' => get_string('rssfeed', 'blog'),
485 'link' => new moodle_url(rss_get_url($sitecontext->id, $USER->id, 'blog', 'user/'.$user->id))
486 );
487 }
488
27bad0a6
SH
489 // Cache the options
490 $useroptions[$user->id] = $options;
491 // Return the options
492 return $options;
493}
494
495/**
496 * Get the blog options that relate to the given course for the given user.
497 *
498 * @staticvar array $courseoptions A cache so we can save regenerating multiple times
499 * @param stdClass $course The course to load options for
500 * @param stdClass $user The user to load options for null == current user
501 * @return array The array of options
502 */
503function blog_get_options_for_course(stdClass $course, stdClass $user=null) {
504 global $CFG, $USER;
505 // Cache
506 static $courseoptions = array();
897aa80c 507
27bad0a6
SH
508 $options = array();
509
510 // User must be logged in and blogs must be enabled
511 if (!blog_is_enabled_for_user()) {
512 return $options;
513 }
514
515 // Check that the user can associate with the course
516 $sitecontext = get_context_instance(CONTEXT_SYSTEM);
517 if (!has_capability('moodle/blog:associatecourse', $sitecontext)) {
518 return $options;
519 }
520 // Generate the cache key
521 $key = $course->id.':';
522 if (!empty($user)) {
523 $key .= $user->id;
524 } else {
525 $key .= $USER->id;
526 }
527 // Serve from the cache if we've already generated for this course
528 if (array_key_exists($key, $courseoptions)) {
af8fe217 529 return $courseoptions[$key];
27bad0a6 530 }
897aa80c 531
27bad0a6
SH
532 if (has_capability('moodle/blog:view', get_context_instance(CONTEXT_COURSE, $course->id))) {
533 // We can view!
534 if ($CFG->bloglevel >= BLOG_SITE_LEVEL) {
535 // View entries about this course
536 $options['courseview'] = array(
537 'string' => get_string('viewcourseblogs', 'blog'),
538 'link' => new moodle_url('/blog/index.php', array('courseid'=>$course->id))
539 );
540 }
541 // View MY entries about this course
542 $options['courseviewmine'] = array(
543 'string' => get_string('viewmyentriesaboutcourse', 'blog'),
544 'link' => new moodle_url('/blog/index.php', array('courseid'=>$course->id, 'userid'=>$USER->id))
545 );
546 if (!empty($user) && ($CFG->bloglevel >= BLOG_SITE_LEVEL)) {
547 // View the provided users entries about this course
548 $options['courseviewuser'] = array(
549 'string' => get_string('viewentriesbyuseraboutcourse', 'blog', fullname($user)),
550 'link' => new moodle_url('/blog/index.php', array('courseid'=>$course->id, 'userid'=>$user->id))
551 );
552 }
553 }
554
555 if (has_capability('moodle/blog:create', $sitecontext)) {
556 // We can blog about this course
557 $options['courseadd'] = array(
cfa11fd6 558 'string' => get_string('blogaboutthiscourse', 'blog'),
27bad0a6
SH
559 'link' => new moodle_url('/blog/edit.php', array('action'=>'add', 'courseid'=>$course->id))
560 );
561 }
562
563
564 // Cache the options for this course
565 $courseoptions[$key] = $options;
566 // Return the options
567 return $options;
568}
569
570/**
571 * Get the blog options relating to the given module for the given user
572 *
573 * @staticvar array $moduleoptions Cache
78f0f64d 574 * @param stdClass|cm_info $module The module to get options for
27bad0a6
SH
575 * @param stdClass $user The user to get options for null == currentuser
576 * @return array
577 */
78f0f64d 578function blog_get_options_for_module($module, $user=null) {
27bad0a6
SH
579 global $CFG, $USER;
580 // Cache
581 static $moduleoptions = array();
582
583 $options = array();
584 // User must be logged in, blogs must be enabled
585 if (!blog_is_enabled_for_user()) {
586 return $options;
587 }
588
589 // Check the user can associate with the module
590 $sitecontext = get_context_instance(CONTEXT_SYSTEM);
591 if (!has_capability('moodle/blog:associatemodule', $sitecontext)) {
592 return $options;
593 }
594
595 // Generate the cache key
596 $key = $module->id.':';
597 if (!empty($user)) {
598 $key .= $user->id;
599 } else {
600 $key .= $USER->id;
601 }
602 if (array_key_exists($key, $moduleoptions)) {
603 // Serve from the cache so we don't have to regenerate
604 return $moduleoptions[$module->id];
605 }
606
607 if (has_capability('moodle/blog:view', get_context_instance(CONTEXT_MODULE, $module->id))) {
608 // We can view!
609 if ($CFG->bloglevel >= BLOG_SITE_LEVEL) {
610 // View all entries about this module
611 $a = new stdClass;
612 $a->type = $module->modname;
613 $options['moduleview'] = array(
614 'string' => get_string('viewallmodentries', 'blog', $a),
615 'link' => new moodle_url('/blog/index.php', array('modid'=>$module->id))
616 );
617 }
618 // View MY entries about this module
619 $options['moduleviewmine'] = array(
620 'string' => get_string('viewmyentriesaboutmodule', 'blog', $module->modname),
621 'link' => new moodle_url('/blog/index.php', array('modid'=>$module->id, 'userid'=>$USER->id))
622 );
623 if (!empty($user) && ($CFG->bloglevel >= BLOG_SITE_LEVEL)) {
624 // View the given users entries about this module
625 $a = new stdClass;
626 $a->mod = $module->modname;
627 $a->user = fullname($user);
628 $options['moduleviewuser'] = array(
629 'string' => get_string('blogentriesbyuseraboutmodule', 'blog', $a),
630 'link' => new moodle_url('/blog/index.php', array('modid'=>$module->id, 'userid'=>$user->id))
631 );
632 }
633 }
634
635 if (has_capability('moodle/blog:create', $sitecontext)) {
636 // The user can blog about this module
637 $options['moduleadd'] = array(
638 'string' => get_string('blogaboutthismodule', 'blog', $module->modname),
639 'link' => new moodle_url('/blog/edit.php', array('action'=>'add', 'modid'=>$module->id))
640 );
641 }
642 // Cache the options
643 $moduleoptions[$key] = $options;
644 // Return the options
645 return $options;
646}
647
cae83708 648/**
649 * This function encapsulates all the logic behind the complex
650 * navigation, titles and headings of the blog listing page, depending
1c7b8b93
NC
651 * on URL params. It looks at URL params and at the current context level.
652 * It builds and returns an array containing:
653 *
654 * 1. heading: The heading displayed above the blog entries
655 * 2. stradd: The text to be used as the "Add entry" link
656 * 3. strview: The text to be used as the "View entries" link
657 * 4. url: The moodle_url object used as the base for add and view links
658 * 5. filters: An array of parameters used to filter blog listings. Used by index.php and the Recent blogs block
cae83708 659 *
c5dc10ee 660 * All other variables are set directly in $PAGE
cae83708 661 *
662 * It uses the current URL to build these variables.
663 * A number of mutually exclusive use cases are used to structure this function.
664 *
665 * @return array
666 */
451f1e38 667function blog_get_headers($courseid=null, $groupid=null, $userid=null, $tagid=null) {
cae83708 668 global $CFG, $PAGE, $DB, $USER;
669
9366362a 670 $id = optional_param('id', null, PARAM_INT);
cae83708 671 $tag = optional_param('tag', null, PARAM_NOTAGS);
451f1e38
AD
672 $tagid = optional_param('tagid', $tagid, PARAM_INT);
673 $userid = optional_param('userid', $userid, PARAM_INT);
cae83708 674 $modid = optional_param('modid', null, PARAM_INT);
675 $entryid = optional_param('entryid', null, PARAM_INT);
451f1e38
AD
676 $groupid = optional_param('groupid', $groupid, PARAM_INT);
677 $courseid = optional_param('courseid', $courseid, PARAM_INT);
cae83708 678 $search = optional_param('search', null, PARAM_RAW);
679 $action = optional_param('action', null, PARAM_ALPHA);
680 $confirm = optional_param('confirm', false, PARAM_BOOL);
681
1c7b8b93
NC
682 // Ignore userid when action == add
683 if ($action == 'add' && $userid) {
684 unset($userid);
685 $PAGE->url->remove_params(array('userid'));
686 } else if ($action == 'add' && $entryid) {
687 unset($entryid);
688 $PAGE->url->remove_params(array('entryid'));
689 }
690
691 $headers = array('title' => '', 'heading' => '', 'cm' => null, 'filters' => array());
cae83708 692
a6855934 693 $blogurl = new moodle_url('/blog/index.php');
1c7b8b93
NC
694
695 // If the title is not yet set, it's likely that the context isn't set either, so skip this part
6f5e0852 696 $pagetitle = $PAGE->title;
1c7b8b93
NC
697 if (!empty($pagetitle)) {
698 $contexturl = blog_get_context_url();
699
700 // Look at the context URL, it may have additional params that are not in the current URL
701 if (!$blogurl->compare($contexturl)) {
702 $blogurl = $contexturl;
703 if (empty($courseid)) {
704 $courseid = $blogurl->param('courseid');
705 }
706 if (empty($modid)) {
707 $modid = $blogurl->param('modid');
708 }
709 }
710 }
711
712 $headers['stradd'] = get_string('addnewentry', 'blog');
713 $headers['strview'] = null;
cae83708 714
1c7b8b93
NC
715 $site = $DB->get_record('course', array('id' => SITEID));
716 $sitecontext = get_context_instance(CONTEXT_SYSTEM);
cae83708 717 // Common Lang strings
718 $strparticipants = get_string("participants");
719 $strblogentries = get_string("blogentries", 'blog');
720
721 // Prepare record objects as needed
722 if (!empty($courseid)) {
1c7b8b93 723 $headers['filters']['course'] = $courseid;
cae83708 724 $course = $DB->get_record('course', array('id' => $courseid));
725 }
e96f2a77 726
cae83708 727 if (!empty($userid)) {
1c7b8b93 728 $headers['filters']['user'] = $userid;
cae83708 729 $user = $DB->get_record('user', array('id' => $userid));
516194d0 730 }
bbbf2d40 731
cae83708 732 if (!empty($groupid)) { // groupid always overrides courseid
1c7b8b93 733 $headers['filters']['group'] = $groupid;
cae83708 734 $group = $DB->get_record('groups', array('id' => $groupid));
735 $course = $DB->get_record('course', array('id' => $group->courseid));
736 }
bbbf2d40 737
897aa80c 738 $PAGE->set_pagelayout('standard');
27bad0a6 739
1c7b8b93
NC
740 if (!empty($modid) && $CFG->useblogassociations && has_capability('moodle/blog:associatemodule', $sitecontext)) { // modid always overrides courseid, so the $course object may be reset here
741 $headers['filters']['module'] = $modid;
cae83708 742 // A groupid param may conflict with this coursemod's courseid. Ignore groupid in that case
1c7b8b93
NC
743 $courseid = $DB->get_field('course_modules', 'course', array('id'=>$modid));
744 $course = $DB->get_record('course', array('id' => $courseid));
cae83708 745 $cm = $DB->get_record('course_modules', array('id' => $modid));
746 $cm->modname = $DB->get_field('modules', 'name', array('id' => $cm->module));
747 $cm->name = $DB->get_field($cm->modname, 'name', array('id' => $cm->instance));
e463f508 748 $a = new stdClass();
1c7b8b93 749 $a->type = get_string('modulename', $cm->modname);
c5dc10ee 750 $PAGE->set_cm($cm, $course);
1c7b8b93
NC
751 $headers['stradd'] = get_string('blogaboutthis', 'blog', $a);
752 $headers['strview'] = get_string('viewallmodentries', 'blog', $a);
cae83708 753 }
b73d1ca4 754
1c7b8b93
NC
755 // Case 1: No entry, mod, course or user params: all site entries to be shown (filtered by search and tag/tagid)
756 // Note: if action is set to 'add' or 'edit', we do this at the end
757 if (empty($entryid) && empty($modid) && empty($courseid) && empty($userid) && !in_array($action, array('edit', 'add'))) {
8ebbb06a 758 $shortname = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
1c7b8b93 759 $PAGE->navbar->add($strblogentries, $blogurl);
8ebbb06a
SH
760 $PAGE->set_title("$shortname: " . get_string('blog', 'blog'));
761 $PAGE->set_heading("$shortname: " . get_string('blog', 'blog'));
762 $headers['heading'] = get_string('siteblog', 'blog', $shortname);
1c7b8b93 763 // $headers['strview'] = get_string('viewsiteentries', 'blog');
4a8b890a 764 }
c2ee4e87 765
1c7b8b93 766 // Case 2: only entryid is requested, ignore all other filters. courseid is used to give more contextual information
cae83708 767 if (!empty($entryid)) {
1c7b8b93
NC
768 $headers['filters']['entry'] = $entryid;
769 $sql = 'SELECT u.* FROM {user} u, {post} p WHERE p.id = ? AND p.userid = u.id';
cae83708 770 $user = $DB->get_record_sql($sql, array($entryid));
1c7b8b93 771 $entry = $DB->get_record('post', array('id' => $entryid));
c2ee4e87 772
1c7b8b93 773 $blogurl->param('userid', $user->id);
c2ee4e87 774
cae83708 775 if (!empty($course)) {
9366362a 776 $mycourseid = $course->id;
1c7b8b93 777 $blogurl->param('courseid', $mycourseid);
c2ee4e87 778 } else {
9366362a 779 $mycourseid = $site->id;
c2ee4e87 780 }
8ebbb06a 781 $shortname = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
e14de6f9 782
1c7b8b93
NC
783 $PAGE->navbar->add($strblogentries, $blogurl);
784
785 $blogurl->remove_params('userid');
786 $PAGE->navbar->add($entry->subject, $blogurl);
8ebbb06a
SH
787 $PAGE->set_title("$shortname: " . fullname($user) . ": $entry->subject");
788 $PAGE->set_heading("$shortname: " . fullname($user) . ": $entry->subject");
cae83708 789 $headers['heading'] = get_string('blogentrybyuser', 'blog', fullname($user));
790
791 // We ignore tag and search params
1c7b8b93
NC
792 if (empty($action) || !$CFG->useblogassociations) {
793 $headers['url'] = $blogurl;
9366362a 794 return $headers;
795 }
c2ee4e87 796 }
240075cd 797
1c7b8b93
NC
798 // Case 3: A user's blog entries
799 if (!empty($userid) && empty($entryid) && ((empty($courseid) && empty($modid)) || !$CFG->useblogassociations)) {
8ebbb06a 800 $shortname = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
1c7b8b93 801 $blogurl->param('userid', $userid);
8ebbb06a
SH
802 $PAGE->set_title("$shortname: " . fullname($user) . ": " . get_string('blog', 'blog'));
803 $PAGE->set_heading("$shortname: " . fullname($user) . ": " . get_string('blog', 'blog'));
cae83708 804 $headers['heading'] = get_string('userblog', 'blog', fullname($user));
27bad0a6 805 $headers['strview'] = get_string('viewuserentries', 'blog', fullname($user));
1c7b8b93
NC
806
807 } else
cae83708 808
1c7b8b93
NC
809 // Case 4: No blog associations, no userid
810 if (!$CFG->useblogassociations && empty($userid) && !in_array($action, array('edit', 'add'))) {
8ebbb06a
SH
811 $shortname = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
812 $PAGE->set_title("$shortname: " . get_string('blog', 'blog'));
813 $PAGE->set_heading("$shortname: " . get_string('blog', 'blog'));
814 $headers['heading'] = get_string('siteblog', 'blog', $shortname);
cae83708 815 } else
816
1c7b8b93 817 // Case 5: Blog entries associated with an activity by a specific user (courseid ignored)
9366362a 818 if (!empty($userid) && !empty($modid) && empty($entryid)) {
8ebbb06a 819 $shortname = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
1c7b8b93
NC
820 $blogurl->param('userid', $userid);
821 $blogurl->param('modid', $modid);
cae83708 822
823 // Course module navigation is handled by build_navigation as the second param
824 $headers['cm'] = $cm;
c5dc10ee 825 $PAGE->navbar->add(fullname($user), "$CFG->wwwroot/user/view.php?id=$user->id");
1c7b8b93 826 $PAGE->navbar->add($strblogentries, $blogurl);
cae83708 827
8ebbb06a
SH
828 $PAGE->set_title("$shortname: $cm->name: " . fullname($user) . ': ' . get_string('blogentries', 'blog'));
829 $PAGE->set_heading("$shortname: $cm->name: " . fullname($user) . ': ' . get_string('blogentries', 'blog'));
cae83708 830
e463f508 831 $a = new stdClass();
cae83708 832 $a->user = fullname($user);
833 $a->mod = $cm->name;
1c7b8b93 834 $a->type = get_string('modulename', $cm->modname);
cae83708 835 $headers['heading'] = get_string('blogentriesbyuseraboutmodule', 'blog', $a);
1c7b8b93
NC
836 $headers['stradd'] = get_string('blogaboutthis', 'blog', $a);
837 $headers['strview'] = get_string('viewallmodentries', 'blog', $a);
cae83708 838 } else
839
1c7b8b93 840 // Case 6: Blog entries associated with a course by a specific user
9366362a 841 if (!empty($userid) && !empty($courseid) && empty($modid) && empty($entryid)) {
8ebbb06a
SH
842 $siteshortname = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
843 $courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
1c7b8b93
NC
844 $blogurl->param('userid', $userid);
845 $blogurl->param('courseid', $courseid);
2c27b6ae 846
1c7b8b93 847 $PAGE->navbar->add($strblogentries, $blogurl);
cae83708 848
8ebbb06a
SH
849 $PAGE->set_title("$siteshortname: $courseshortname: " . fullname($user) . ': ' . get_string('blogentries', 'blog'));
850 $PAGE->set_heading("$siteshortname: $courseshortname: " . fullname($user) . ': ' . get_string('blogentries', 'blog'));
cae83708 851
e463f508 852 $a = new stdClass();
cae83708 853 $a->user = fullname($user);
635c65bb 854 $a->course = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
1c7b8b93 855 $a->type = get_string('course');
cae83708 856 $headers['heading'] = get_string('blogentriesbyuseraboutcourse', 'blog', $a);
1c7b8b93
NC
857 $headers['stradd'] = get_string('blogaboutthis', 'blog', $a);
858 $headers['strview'] = get_string('viewblogentries', 'blog', $a);
859
860 // Remove the userid from the URL to inform the blog_menu block correctly
861 $blogurl->remove_params(array('userid'));
cae83708 862 } else
863
1c7b8b93 864 // Case 7: Blog entries by members of a group, associated with that group's course
9366362a 865 if (!empty($groupid) && empty($modid) && empty($entryid)) {
8ebbb06a
SH
866 $siteshortname = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
867 $courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
1c7b8b93 868 $blogurl->param('courseid', $course->id);
e14de6f9 869
1c7b8b93
NC
870 $PAGE->navbar->add($strblogentries, $blogurl);
871 $blogurl->remove_params(array('courseid'));
872 $blogurl->param('groupid', $groupid);
873 $PAGE->navbar->add($group->name, $blogurl);
cae83708 874
8ebbb06a
SH
875 $PAGE->set_title("$siteshortname: $courseshortname: " . get_string('blogentries', 'blog') . ": $group->name");
876 $PAGE->set_heading("$siteshortname: $courseshortname: " . get_string('blogentries', 'blog') . ": $group->name");
cae83708 877
e463f508 878 $a = new stdClass();
cae83708 879 $a->group = $group->name;
635c65bb 880 $a->course = format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
1c7b8b93 881 $a->type = get_string('course');
cae83708 882 $headers['heading'] = get_string('blogentriesbygroupaboutcourse', 'blog', $a);
1c7b8b93
NC
883 $headers['stradd'] = get_string('blogaboutthis', 'blog', $a);
884 $headers['strview'] = get_string('viewblogentries', 'blog', $a);
cae83708 885 } else
886
1c7b8b93 887 // Case 8: Blog entries by members of a group, associated with an activity in that course
9366362a 888 if (!empty($groupid) && !empty($modid) && empty($entryid)) {
8ebbb06a
SH
889 $siteshortname = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
890 $courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
cae83708 891 $headers['cm'] = $cm;
1c7b8b93
NC
892 $blogurl->param('modid', $modid);
893 $PAGE->navbar->add($strblogentries, $blogurl);
cae83708 894
1c7b8b93
NC
895 $blogurl->param('groupid', $groupid);
896 $PAGE->navbar->add($group->name, $blogurl);
cae83708 897
8ebbb06a
SH
898 $PAGE->set_title("$siteshortname: $courseshortname: $cm->name: " . get_string('blogentries', 'blog') . ": $group->name");
899 $PAGE->set_heading("$siteshortname: $courseshortname: $cm->name: " . get_string('blogentries', 'blog') . ": $group->name");
cae83708 900
e463f508 901 $a = new stdClass();
cae83708 902 $a->group = $group->name;
903 $a->mod = $cm->name;
1c7b8b93 904 $a->type = get_string('modulename', $cm->modname);
cae83708 905 $headers['heading'] = get_string('blogentriesbygroupaboutmodule', 'blog', $a);
1c7b8b93
NC
906 $headers['stradd'] = get_string('blogaboutthis', 'blog', $a);
907 $headers['strview'] = get_string('viewallmodentries', 'blog', $a);
cae83708 908
909 } else
910
1c7b8b93 911 // Case 9: All blog entries associated with an activity
9366362a 912 if (!empty($modid) && empty($userid) && empty($groupid) && empty($entryid)) {
8ebbb06a
SH
913 $siteshortname = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
914 $courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
c5dc10ee 915 $PAGE->set_cm($cm, $course);
1c7b8b93
NC
916 $blogurl->param('modid', $modid);
917 $PAGE->navbar->add($strblogentries, $blogurl);
8ebbb06a
SH
918 $PAGE->set_title("$siteshortname: $courseshortname: $cm->name: " . get_string('blogentries', 'blog'));
919 $PAGE->set_heading("$siteshortname: $courseshortname: $cm->name: " . get_string('blogentries', 'blog'));
cae83708 920 $headers['heading'] = get_string('blogentriesabout', 'blog', $cm->name);
e463f508 921 $a = new stdClass();
1c7b8b93
NC
922 $a->type = get_string('modulename', $cm->modname);
923 $headers['stradd'] = get_string('blogaboutthis', 'blog', $a);
924 $headers['strview'] = get_string('viewallmodentries', 'blog', $a);
cae83708 925 } else
926
1c7b8b93 927 // Case 10: All blog entries associated with a course
9366362a 928 if (!empty($courseid) && empty($userid) && empty($groupid) && empty($modid) && empty($entryid)) {
8ebbb06a
SH
929 $siteshortname = format_string($site->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, SITEID)));
930 $courseshortname = format_string($course->shortname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id)));
1c7b8b93
NC
931 $blogurl->param('courseid', $courseid);
932 $PAGE->navbar->add($strblogentries, $blogurl);
8ebbb06a
SH
933 $PAGE->set_title("$siteshortname: $courseshortname: " . get_string('blogentries', 'blog'));
934 $PAGE->set_heading("$siteshortname: $courseshortname: " . get_string('blogentries', 'blog'));
e463f508 935 $a = new stdClass();
1c7b8b93 936 $a->type = get_string('course');
635c65bb 937 $headers['heading'] = get_string('blogentriesabout', 'blog', format_string($course->fullname, true, array('context' => get_context_instance(CONTEXT_COURSE, $course->id))));
1c7b8b93
NC
938 $headers['stradd'] = get_string('blogaboutthis', 'blog', $a);
939 $headers['strview'] = get_string('viewblogentries', 'blog', $a);
940 $blogurl->remove_params(array('userid'));
941 }
942
943 if (!in_array($action, array('edit', 'add'))) {
944 // Append Tag info
945 if (!empty($tagid)) {
946 $headers['filters']['tag'] = $tagid;
947 $blogurl->param('tagid', $tagid);
948 $tagrec = $DB->get_record('tag', array('id'=>$tagid));
949 $PAGE->navbar->add($tagrec->name, $blogurl);
950 } elseif (!empty($tag)) {
951 $blogurl->param('tag', $tag);
952 $PAGE->navbar->add(get_string('tagparam', 'blog', $tag), $blogurl);
953 }
240075cd 954
1c7b8b93
NC
955 // Append Search info
956 if (!empty($search)) {
957 $headers['filters']['search'] = $search;
958 $blogurl->param('search', $search);
959 $PAGE->navbar->add(get_string('searchterm', 'blog', $search), $blogurl->out());
960 }
ee00eb8c 961 }
962
cae83708 963 // Append edit mode info
964 if (!empty($action) && $action == 'add') {
f36b47ef 965
cae83708 966 } else if (!empty($action) && $action == 'edit') {
c5dc10ee 967 $PAGE->navbar->add(get_string('editentry', 'blog'));
240075cd 968 }
ee00eb8c 969
1c7b8b93
NC
970 if (empty($headers['url'])) {
971 $headers['url'] = $blogurl;
972 }
cae83708 973 return $headers;
974}
23677261 975
1c7b8b93
NC
976/**
977 * Shortcut function for getting a count of blog entries associated with a course or a module
978 * @param int $courseid The ID of the course
979 * @param int $cmid The ID of the course_modules
980 * @return string The number of associated entries
981 */
982function blog_get_associated_count($courseid, $cmid=null) {
983 global $DB;
984 $context = get_context_instance(CONTEXT_COURSE, $courseid);
985 if ($cmid) {
986 $context = get_context_instance(CONTEXT_MODULE, $cmid);
987 }
988 return $DB->count_records('blog_association', array('contextid' => $context->id));
593270c6 989}
c1951ea9
DC
990
991/**
992 * Running addtional permission check on plugin, for example, plugins
993 * may have switch to turn on/off comments option, this callback will
994 * affect UI display, not like pluginname_comment_validate only throw
995 * exceptions.
996 * Capability check has been done in comment->check_permissions(), we
997 * don't need to do it again here.
998 *
999 * @param stdClass $comment_param {
1000 * context => context the context object
1001 * courseid => int course id
1002 * cm => stdClass course module object
1003 * commentarea => string comment area
1004 * itemid => int itemid
1005 * }
1006 * @return array
1007 */
1008function blog_comment_permissions($comment_param) {
1009 return array('post'=>true, 'view'=>true);
1010}
1011
1012/**
1013 * Validate comment parameter before perform other comments actions
1014 *
1015 * @param stdClass $comment {
1016 * context => context the context object
1017 * courseid => int course id
1018 * cm => stdClass course module object
1019 * commentarea => string comment area
1020 * itemid => int itemid
1021 * }
1022 * @return boolean
1023 */
1024function blog_comment_validate($comment_param) {
1025 global $DB;
1026 // validate comment itemid
1027 if (!$entry = $DB->get_record('post', array('id'=>$comment_param->itemid))) {
1028 throw new comment_exception('invalidcommentitemid');
1029 }
1030 // validate comment area
1031 if ($comment_param->commentarea != 'format_blog') {
1032 throw new comment_exception('invalidcommentarea');
1033 }
1034 // validation for comment deletion
1035 if (!empty($comment_param->commentid)) {
1036 if ($record = $DB->get_record('comments', array('id'=>$comment_param->commentid))) {
1037 if ($record->commentarea != 'format_blog') {
1038 throw new comment_exception('invalidcommentarea');
1039 }
1040 if ($record->contextid != $comment_param->context->id) {
1041 throw new comment_exception('invalidcontext');
1042 }
1043 if ($record->itemid != $comment_param->itemid) {
1044 throw new comment_exception('invalidcommentitemid');
1045 }
1046 } else {
1047 throw new comment_exception('invalidcommentid');
1048 }
1049 }
1050 return true;
1051}
b1627a92
DC
1052
1053/**
1054 * Return a list of page types
1055 * @param string $pagetype current page type
1056 * @param stdClass $parentcontext Block's parent context
1057 * @param stdClass $currentcontext Current context of block
1058 */
b38e2e28 1059function blog_page_type_list($pagetype, $parentcontext, $currentcontext) {
b1627a92
DC
1060 return array(
1061 '*'=>get_string('page-x', 'pagetype'),
1062 'blog-*'=>get_string('page-blog-x', 'blog'),
1063 'blog-index'=>get_string('page-blog-index', 'blog'),
1064 'blog-edit'=>get_string('page-blog-edit', 'blog')
1065 );
1066}