2009-11-01 12:00:47 +00:00
|
|
|
<?php
|
2011-04-18 17:31:35 +08:00
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Admin Bookmarks Block page.
|
|
|
|
*
|
2014-02-13 10:55:46 +13:00
|
|
|
* @package block_admin_bookmarks
|
2011-04-18 17:31:35 +08:00
|
|
|
* @copyright 2011 Moodle
|
|
|
|
* @author 2006 vinkmar
|
|
|
|
* 2011 Rossiani Wijaya (updated)
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The admin bookmarks block class
|
|
|
|
*/
|
|
|
|
class block_admin_bookmarks extends block_base {
|
2006-08-18 08:25:02 +00:00
|
|
|
|
2011-04-18 17:31:35 +08:00
|
|
|
/** @var string */
|
|
|
|
public $blockname = null;
|
2006-08-18 08:25:02 +00:00
|
|
|
|
2011-04-18 17:31:35 +08:00
|
|
|
/** @var bool */
|
|
|
|
protected $contentgenerated = false;
|
2006-08-18 08:25:02 +00:00
|
|
|
|
2011-04-18 17:31:35 +08:00
|
|
|
/** @var bool|null */
|
|
|
|
protected $docked = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the initial properties for the block
|
|
|
|
*/
|
2006-08-18 08:25:02 +00:00
|
|
|
function init() {
|
2011-04-18 17:31:35 +08:00
|
|
|
$this->blockname = get_class($this);
|
|
|
|
$this->title = get_string('pluginname', $this->blockname);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* All multiple instances of this block
|
|
|
|
* @return bool Returns false
|
|
|
|
*/
|
|
|
|
function instance_allow_multiple() {
|
|
|
|
return false;
|
2006-09-02 23:55:56 +00:00
|
|
|
}
|
|
|
|
|
2011-04-18 17:31:35 +08:00
|
|
|
/**
|
|
|
|
* Set the applicable formats for this block to all
|
|
|
|
* @return array
|
|
|
|
*/
|
2006-09-02 23:55:56 +00:00
|
|
|
function applicable_formats() {
|
2012-07-23 15:55:09 +08:00
|
|
|
if (has_capability('moodle/site:config', context_system::instance())) {
|
2007-03-30 16:52:38 +00:00
|
|
|
return array('all' => true);
|
|
|
|
} else {
|
2007-03-30 18:04:34 +00:00
|
|
|
return array('site' => true);
|
2007-03-30 16:52:38 +00:00
|
|
|
}
|
2006-08-18 08:25:02 +00:00
|
|
|
}
|
|
|
|
|
2011-04-18 17:31:35 +08:00
|
|
|
/**
|
|
|
|
* Gets the content for this block
|
|
|
|
*/
|
2006-08-18 08:25:02 +00:00
|
|
|
function get_content() {
|
2007-12-19 17:35:20 +00:00
|
|
|
|
2011-04-18 17:31:35 +08:00
|
|
|
global $CFG;
|
2007-12-19 17:35:20 +00:00
|
|
|
|
2011-04-18 17:31:35 +08:00
|
|
|
// First check if we have already generated, don't waste cycles
|
|
|
|
if ($this->contentgenerated === true) {
|
2006-08-18 08:25:02 +00:00
|
|
|
return $this->content;
|
|
|
|
}
|
2012-01-15 13:37:53 +01:00
|
|
|
$this->content = new stdClass();
|
2007-12-19 17:35:20 +00:00
|
|
|
|
2007-03-06 10:45:49 +00:00
|
|
|
if (get_user_preferences('admin_bookmarks')) {
|
2007-10-28 23:06:39 +00:00
|
|
|
require_once($CFG->libdir.'/adminlib.php');
|
2009-01-20 23:53:34 +00:00
|
|
|
$adminroot = admin_get_root(false, false); // settings not required - only pages
|
2007-12-19 17:35:20 +00:00
|
|
|
|
|
|
|
$bookmarks = explode(',', get_user_preferences('admin_bookmarks'));
|
2006-09-22 15:15:48 +00:00
|
|
|
/// Accessibility: markup as a list.
|
2011-04-18 17:31:35 +08:00
|
|
|
$contents = array();
|
2006-08-18 08:25:02 +00:00
|
|
|
foreach($bookmarks as $bookmark) {
|
2006-09-20 20:31:09 +00:00
|
|
|
$temp = $adminroot->locate($bookmark);
|
2009-01-20 23:53:34 +00:00
|
|
|
if ($temp instanceof admin_settingpage) {
|
2011-04-19 10:22:46 +08:00
|
|
|
$contenturl = new moodle_url('/admin/settings.php', array('section'=>$bookmark));
|
2011-04-18 17:31:35 +08:00
|
|
|
$contentlink = html_writer::link($contenturl, $temp->visiblename);
|
|
|
|
$contents[] = html_writer::tag('li', $contentlink);
|
2009-01-20 23:53:34 +00:00
|
|
|
} else if ($temp instanceof admin_externalpage) {
|
2011-04-18 17:31:35 +08:00
|
|
|
$contenturl = new moodle_url($temp->url);
|
|
|
|
$contentlink = html_writer::link($contenturl, $temp->visiblename);
|
|
|
|
$contents[] = html_writer::tag('li', $contentlink);
|
2006-09-26 09:25:37 +00:00
|
|
|
}
|
2006-09-20 20:31:09 +00:00
|
|
|
}
|
2011-04-18 17:31:35 +08:00
|
|
|
$this->content->text = html_writer::tag('ol', implode('', $contents), array('class' => 'list'));
|
2006-09-20 20:31:09 +00:00
|
|
|
} else {
|
|
|
|
$bookmarks = array();
|
|
|
|
}
|
2007-12-19 17:35:20 +00:00
|
|
|
|
2011-04-18 17:31:35 +08:00
|
|
|
$this->content->footer = '';
|
|
|
|
$this->page->settingsnav->initialise();
|
2014-01-03 10:39:50 +08:00
|
|
|
$node = $this->page->settingsnav->get('root', navigation_node::TYPE_SITE_ADMIN);
|
2011-04-18 17:31:35 +08:00
|
|
|
if (!$node || !$node->contains_active_node()) {
|
|
|
|
return $this->content;
|
|
|
|
}
|
|
|
|
$section = $node->find_active_node()->key;
|
|
|
|
|
|
|
|
if ($section == 'search' || empty($section)){
|
2007-03-30 16:52:38 +00:00
|
|
|
// the search page can't be properly bookmarked at present
|
|
|
|
$this->content->footer = '';
|
2011-04-18 17:31:35 +08:00
|
|
|
} else if (in_array($section, $bookmarks)) {
|
|
|
|
$deleteurl = new moodle_url('/blocks/admin_bookmarks/delete.php', array('section'=>$section, 'sesskey'=>sesskey()));
|
|
|
|
$this->content->footer = html_writer::link($deleteurl, get_string('unbookmarkthispage','admin'));
|
2006-09-20 20:31:09 +00:00
|
|
|
} else {
|
2011-04-18 17:31:35 +08:00
|
|
|
$createurl = new moodle_url('/blocks/admin_bookmarks/create.php', array('section'=>$section, 'sesskey'=>sesskey()));
|
|
|
|
$this->content->footer = html_writer::link($createurl, get_string('bookmarkthispage','admin'));
|
2006-09-20 20:31:09 +00:00
|
|
|
}
|
2007-12-19 17:35:20 +00:00
|
|
|
|
2006-09-20 20:31:09 +00:00
|
|
|
return $this->content;
|
2006-08-18 08:25:02 +00:00
|
|
|
}
|
2012-10-10 14:56:28 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the role that best describes the admin bookmarks block.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_aria_role() {
|
|
|
|
return 'navigation';
|
|
|
|
}
|
2006-08-18 08:25:02 +00:00
|
|
|
}
|
|
|
|
|
2009-11-01 12:00:47 +00:00
|
|
|
|