forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblogpage.php
204 lines (171 loc) · 6.96 KB
/
blogpage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php // $Id$
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
}
/**
* Definition of blog page type.
*/
define('PAGE_BLOG_VIEW', 'blog-view');
// Blog class derived from moodle's page class
class page_blog extends page_base {
var $editing = false;
var $courserecord = NULL;
var $courseid = NULL;
var $filtertype = NULL;
var $filterselect = NULL;
var $tagid = NULL;
// Mandatory; should return our identifier.
function get_type() {
global $CFG;
require_once($CFG->dirroot .'/blog/lib.php');
return PAGE_BLOG_VIEW;
}
// we have no format type, use 'blog'
//I think it's a bug, but if this is left the default NULL value then pages can
//fail to load completely
function get_format_name() {
global $CFG;
require_once($CFG->dirroot .'/blog/lib.php');
return PAGE_BLOG_VIEW;
}
// Do any validation of the officially recognized bits of the data and forward to parent.
// Do NOT load up "expensive" resouces (e.g. SQL data) here!
function init_quick($data) {
parent::init_quick($data);
if (empty($data->pageid)) {
//if no pageid then the user is viewing a collection of blog entries
$this->id = 0; //set blog id to 0
}
}
/**
* Here you should load up all heavy-duty data for your page. Basically everything that
* does not NEED to be loaded for the class to make basic decisions should NOT be loaded
* in init_quick() and instead deferred here. Of course this function had better recognize
* $this->full_init_done to prevent wasteful multiple-time data retrieval.
*/
function init_full() {
global $DB;
if ($this->full_init_done) {
return;
}
// I need to determine how best to utilize this function. Most init
// is already done before we get here in blogFilter and blogInfo
if ($this->courseid == 0 || $this->courseid == 1 || !is_numeric($this->courseid) ) {
$this->courseid = '';
$courserecord = NULL;
} else {
if (! ($courserecord = $DB->get_record('course', array('id'=>$this->courseid))) ) {
print_error('invalidcourseid', 'error', '', $this->courseid);
}
}
$this->full_init_done = true;
}
// For this test page, only admins are going to be allowed editing (for simplicity).
function user_allowed_editing() {
if (isloggedin() && !isguest()) {
return true;
}
return false;
}
// Also, admins are considered to have "always on" editing (I wanted to avoid duplicating
// the code that turns editing on/off here; you can roll your own or copy course/view.php).
function user_is_editing() {
global $SESSION;
if (isloggedin() && !isguest()) {
$this->editing = !empty($SESSION->blog_editing_enabled);
return $this->editing;
}
return false;
}
//over-ride parent method's print_header because blog already passes more than just the title along
function print_header($pageTitle='', $pageHeading='', $pageNavigation='', $pageFocus='', $pageMeta='') {
global $USER;
$this->init_full();
$extraheader = '';
if (!empty($USER) && !empty($USER->id)) {
$extraheader = $this->get_extra_header_string();
}
print_header($pageTitle, $pageHeading, $pageNavigation, $pageFocus, $pageMeta, true, $extraheader );
}
// This should point to the script that displays us
function url_get_path() {
global $CFG;
return $CFG->wwwroot .'/blog/index.php';
}
function url_get_parameters() {
$array = array();
if (!$this->full_init_done) {
$array['userid'] = $this->id;
return $array;
}
if (!empty($this->courseid)) {
$array['courseid'] = $this->courseid;
}
if (!empty($this->filtertype)) {
$array['filtertype'] = $this->filtertype;
}
if (!empty($this->filterselect)) {
$array['filterselect'] = $this->filterselect;
}
if (!empty($this->tagid)) {
$array['tagid'] = $this->tagid;
}
return $array;
}
// Having defined all identifiers we need, here we declare which block positions we are
// going to support.
function blocks_get_positions() {
return array(BLOCK_POS_LEFT, BLOCK_POS_RIGHT);
}
// When a new block is created in this page, which position should it go to?
function blocks_default_position() {
return BLOCK_POS_RIGHT;
}
// When we are creating a new page, use the data at your disposal to provide a textual representation of the
// blocks that are going to get added to this new page. Delimit block names with commas (,) and use double
// colons (:) to delimit between block positions in the page. See blocks_get_positions() for additional info.
function blocks_get_default() {
global $CFG;
$this->init_full();
// It's a normal blog page
if (!empty($CFG->{'defaultblocks_'. $this->get_type()})) {
$blocknames = $CFG->{'defaultblocks_'. $this->get_type()};
} else {
/// Failsafe - in case nothing was defined.
$blocknames = 'admin,calendar_month,online_users,blog_menu';
}
return $blocknames;
}
// And finally, a little block move logic. Given a block's previous position and where
// we want to move it to, return its new position. Pretty self-documenting.
function blocks_move_position(&$instance, $move) {
if ($instance->position == BLOCK_POS_LEFT && $move == BLOCK_MOVE_RIGHT) {
return BLOCK_POS_RIGHT;
} else if ($instance->position == BLOCK_POS_RIGHT && $move == BLOCK_MOVE_LEFT) {
return BLOCK_POS_LEFT;
}
return $instance->position;
}
/////////// Blog page specific functions
function get_extra_header_string() {
global $SESSION, $CFG, $USER;
$editformstring = '';
if ($this->user_allowed_editing()) {
if (!empty($SESSION->blog_editing_enabled)) {
$editingString = get_string('turneditingoff');
} else {
$editingString = get_string('turneditingon');
}
$params = $this->url_get_parameters();
$params['edit'] = empty($SESSION->blog_editing_enabled) ? 1 : 0;
$paramstring = '';
foreach ($params as $key=>$val) {
$paramstring .= '<input type="hidden" name="'.$key.'" value="'.s($val).'" />';
}
$editformstring = '<form '.$CFG->frametarget.' method="get" action="'.$this->url_get_path().'"><div>'
.$paramstring.'<input type="submit" value="'.$editingString.'" /></div></form>';
}
return $editformstring;
}
}
?>