4 // maybe I should add some pretty icons?
5 // or possibly add the ability to custom-name things?
7 class block_admin_bookmarks
extends block_base
{
10 $this->title
= get_string('adminbookmarks');
11 $this->version
= 2007101509;
14 function applicable_formats() {
15 if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM
))) {
16 return array('all' => true);
18 return array('site' => true);
22 function preferred_width() {
26 function create_item($visiblename,$link,$icon) {
27 $this->tempcontent
.= '<a href="' . $link . '"><img src="' . $icon . '" alt="" /> ' . $visiblename . '</a><br />' . "\n";
30 function get_content() {
32 global $CFG, $USER, $PAGE;
34 if ($this->content
!== NULL) {
35 return $this->content
;
38 $this->content
= new stdClass
;
39 $this->content
->text
= '';
40 if (get_user_preferences('admin_bookmarks')) {
41 // this is expensive! Only require when bookmakrs exist..
42 require_once($CFG->libdir
.'/adminlib.php');
43 $adminroot =& admin_get_root(false, false); // settings not required - only pages
45 $bookmarks = explode(',', get_user_preferences('admin_bookmarks'));
46 // hmm... just a liiitle (potentially) processor-intensive
47 // (recall that $adminroot->locate is a huge recursive call... and we're calling it repeatedly here
49 /// Accessibility: markup as a list.
50 $this->content
->text
.= '<ol class="list">'."\n";
52 foreach($bookmarks as $bookmark) {
53 $temp = $adminroot->locate($bookmark);
54 if (is_a($temp, 'admin_settingpage')) {
55 $this->content
->text
.= '<li><a href="' . $CFG->wwwroot
. '/' . $CFG->admin
. '/settings.php?section=' . $bookmark . '">' . $temp->visiblename
. "</a></li>\n";
56 } else if (is_a($temp, 'admin_externalpage')) {
57 $this->content
->text
.= '<li><a href="' . $temp->url
. '">' . $temp->visiblename
. "</a></li>\n";
60 $this->content
->text
.= "</ol>\n";
65 if (isset($PAGE->section
) and $PAGE->section
== 'search'){
66 // the search page can't be properly bookmarked at present
67 $this->content
->footer
= '';
68 } else if (($section = (isset($PAGE->section
) ?
$PAGE->section
: '')) && (in_array($section, $bookmarks))) {
69 $this->content
->footer
= '<a href="' . $CFG->wwwroot
. '/blocks/admin_bookmarks/delete.php?section=' . $section . '&sesskey='.sesskey().'">' . get_string('unbookmarkthispage','admin') . '</a>';
70 } else if ($section = (isset($PAGE->section
) ?
$PAGE->section
: '')) {
71 $this->content
->footer
= '<a href="' . $CFG->wwwroot
. '/blocks/admin_bookmarks/create.php?section=' . $section . '&sesskey='.sesskey().'">' . get_string('bookmarkthispage','admin') . '</a>';
73 $this->content
->footer
= '';
76 return $this->content
;