moodle_page: MDL-12212 reimplement user_is_editing, deprecate isediting
[moodle.git] / blog / blogpage.php
CommitLineData
4a173181 1<?php // $Id$
2
9cfa80b5 3if (!defined('MOODLE_INTERNAL')) {
4 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
5}
6
4a173181 7/**
8* Definition of blog page type.
9 */
10define('PAGE_BLOG_VIEW', 'blog-view');
11
12// Blog class derived from moodle's page class
13class page_blog extends page_base {
14
15 var $editing = false;
e96f2a77 16 var $filtertype = NULL;
17 var $filterselect = NULL;
47b87873 18 var $tagid = NULL;
e96f2a77 19
4a173181 20 // Do any validation of the officially recognized bits of the data and forward to parent.
21 // Do NOT load up "expensive" resouces (e.g. SQL data) here!
22 function init_quick($data) {
23 parent::init_quick($data);
24 if (empty($data->pageid)) {
25 //if no pageid then the user is viewing a collection of blog entries
26 $this->id = 0; //set blog id to 0
27 }
28 }
e96f2a77 29
45df7de3 30 /**
31 * Here you should load up all heavy-duty data for your page. Basically everything that
32 * does not NEED to be loaded for the class to make basic decisions should NOT be loaded
33 * in init_quick() and instead deferred here. Of course this function had better recognize
34 * $this->full_init_done to prevent wasteful multiple-time data retrieval.
35 */
4a173181 36 function init_full() {
45df7de3 37 global $DB;
38
4a173181 39 if ($this->full_init_done) {
40 return;
41 }
42 // I need to determine how best to utilize this function. Most init
43 // is already done before we get here in blogFilter and blogInfo
6524adcf 44
4a173181 45 if ($this->courseid == 0 || $this->courseid == 1 || !is_numeric($this->courseid) ) {
46 $this->courseid = '';
4a173181 47 }
48 $this->full_init_done = true;
e96f2a77 49 }
4a173181 50
51 // For this test page, only admins are going to be allowed editing (for simplicity).
52 function user_allowed_editing() {
25881d1e 53 if (isloggedin() && !isguest()) {
4a173181 54 return true;
55 }
56 return false;
57 }
58
4a173181 59 //over-ride parent method's print_header because blog already passes more than just the title along
60 function print_header($pageTitle='', $pageHeading='', $pageNavigation='', $pageFocus='', $pageMeta='') {
61 global $USER;
e96f2a77 62
4a173181 63 $this->init_full();
64 $extraheader = '';
65 if (!empty($USER) && !empty($USER->id)) {
66 $extraheader = $this->get_extra_header_string();
67 }
68 print_header($pageTitle, $pageHeading, $pageNavigation, $pageFocus, $pageMeta, true, $extraheader );
69 }
e96f2a77 70
4a173181 71 /////////// Blog page specific functions
72 function get_extra_header_string() {
830dd6e9 73 global $CFG, $USER;
d87c9c6e 74
e96f2a77 75 $editformstring = '';
76 if ($this->user_allowed_editing()) {
830dd6e9 77 if ($this->user_is_editing()) {
d87c9c6e 78 $editingString = get_string('turneditingoff');
79 } else {
80 $editingString = get_string('turneditingon');
81 }
e96f2a77 82
ad52c04f 83 $params = $this->url->params();
830dd6e9 84 $params['edit'] = $this->user_is_editing() ? 0 : 1;
e96f2a77 85 $paramstring = '';
86 foreach ($params as $key=>$val) {
87 $paramstring .= '<input type="hidden" name="'.$key.'" value="'.s($val).'" />';
88 }
e25cb710 89
ad52c04f 90 $editformstring = '<form '.$CFG->frametarget.' method="get" action="'.$this->url->out(false).'"><div>'
7a4a9005 91 .$paramstring.'<input type="submit" value="'.$editingString.'" /></div></form>';
4a173181 92 }
d87c9c6e 93
e96f2a77 94 return $editformstring;
95 }
4a173181 96}
3daaa618 97?>