2006-03-10 06:53:01 +00:00
|
|
|
<?php // $Id$
|
|
|
|
|
2008-06-27 03:35:22 +00:00
|
|
|
if (!defined('MOODLE_INTERNAL')) {
|
|
|
|
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
|
|
|
|
}
|
|
|
|
|
2006-03-10 06:53:01 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
2006-10-06 10:11:52 +00:00
|
|
|
var $filtertype = NULL;
|
|
|
|
var $filterselect = NULL;
|
2006-10-31 08:50:55 +00:00
|
|
|
var $tagid = NULL;
|
2006-10-06 10:11:52 +00:00
|
|
|
|
2006-03-10 06:53:01 +00:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
}
|
2006-10-06 10:11:52 +00:00
|
|
|
|
2008-06-01 13:48:12 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2006-03-10 06:53:01 +00:00
|
|
|
function init_full() {
|
2008-06-01 13:48:12 +00:00
|
|
|
global $DB;
|
|
|
|
|
2006-03-10 06:53:01 +00:00
|
|
|
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
|
2006-04-12 08:58:49 +00:00
|
|
|
|
2006-03-10 06:53:01 +00:00
|
|
|
if ($this->courseid == 0 || $this->courseid == 1 || !is_numeric($this->courseid) ) {
|
|
|
|
$this->courseid = '';
|
|
|
|
}
|
|
|
|
$this->full_init_done = true;
|
2006-10-06 10:11:52 +00:00
|
|
|
}
|
2006-03-10 06:53:01 +00:00
|
|
|
|
|
|
|
// For this test page, only admins are going to be allowed editing (for simplicity).
|
|
|
|
function user_allowed_editing() {
|
2006-04-12 02:27:14 +00:00
|
|
|
if (isloggedin() && !isguest()) {
|
2006-03-10 06:53:01 +00:00
|
|
|
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() {
|
2006-10-06 10:11:52 +00:00
|
|
|
global $SESSION;
|
2006-04-12 02:27:14 +00:00
|
|
|
|
2006-10-06 10:11:52 +00:00
|
|
|
if (isloggedin() && !isguest()) {
|
|
|
|
$this->editing = !empty($SESSION->blog_editing_enabled);
|
2006-03-10 06:53:01 +00:00
|
|
|
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;
|
2006-10-06 10:11:52 +00:00
|
|
|
|
2006-03-10 06:53:01 +00:00
|
|
|
$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 );
|
|
|
|
}
|
2006-10-06 10:11:52 +00:00
|
|
|
|
2006-03-10 06:53:01 +00:00
|
|
|
/////////// Blog page specific functions
|
|
|
|
function get_extra_header_string() {
|
|
|
|
global $SESSION, $CFG, $USER;
|
2006-03-16 08:45:39 +00:00
|
|
|
|
2006-10-06 10:11:52 +00:00
|
|
|
$editformstring = '';
|
|
|
|
if ($this->user_allowed_editing()) {
|
|
|
|
if (!empty($SESSION->blog_editing_enabled)) {
|
2006-03-16 08:45:39 +00:00
|
|
|
$editingString = get_string('turneditingoff');
|
|
|
|
} else {
|
|
|
|
$editingString = get_string('turneditingon');
|
|
|
|
}
|
2006-10-06 10:11:52 +00:00
|
|
|
|
2009-05-06 08:55:53 +00:00
|
|
|
$params = $this->url->params();
|
2006-10-06 10:11:52 +00:00
|
|
|
$params['edit'] = empty($SESSION->blog_editing_enabled) ? 1 : 0;
|
|
|
|
$paramstring = '';
|
|
|
|
foreach ($params as $key=>$val) {
|
|
|
|
$paramstring .= '<input type="hidden" name="'.$key.'" value="'.s($val).'" />';
|
|
|
|
}
|
2007-01-03 19:24:48 +00:00
|
|
|
|
2009-05-06 08:55:53 +00:00
|
|
|
$editformstring = '<form '.$CFG->frametarget.' method="get" action="'.$this->url->out(false).'"><div>'
|
2007-03-01 05:03:06 +00:00
|
|
|
.$paramstring.'<input type="submit" value="'.$editingString.'" /></div></form>';
|
2006-03-10 06:53:01 +00:00
|
|
|
}
|
2006-03-16 08:45:39 +00:00
|
|
|
|
2006-10-06 10:11:52 +00:00
|
|
|
return $editformstring;
|
|
|
|
}
|
2006-03-10 06:53:01 +00:00
|
|
|
}
|
2006-03-16 06:16:54 +00:00
|
|
|
?>
|