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('pluginname', 'block_admin_bookmarks');
13 function applicable_formats() {
14 if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM
))) {
15 return array('all' => true);
17 return array('site' => true);
21 function preferred_width() {
25 function create_item($visiblename,$link,$icon) {
26 $this->tempcontent
.= '<a href="' . $link . '"><img src="' . $icon . '" alt="" /> ' . $visiblename . '</a><br />' . "\n";
29 function get_content() {
33 if ($this->content
!== NULL) {
34 return $this->content
;
37 $this->content
= new stdClass
;
38 $this->content
->text
= '';
39 if (get_user_preferences('admin_bookmarks')) {
40 // this is expensive! Only require when bookmakrs exist..
41 require_once($CFG->libdir
.'/adminlib.php');
42 $adminroot = admin_get_root(false, false); // settings not required - only pages
44 $bookmarks = explode(',', get_user_preferences('admin_bookmarks'));
45 // hmm... just a liiitle (potentially) processor-intensive
46 // (recall that $adminroot->locate is a huge recursive call... and we're calling it repeatedly here
48 /// Accessibility: markup as a list.
49 $this->content
->text
.= '<ol class="list">'."\n";
51 foreach($bookmarks as $bookmark) {
52 $temp = $adminroot->locate($bookmark);
53 if ($temp instanceof admin_settingpage
) {
54 $this->content
->text
.= '<li><a href="' . $CFG->wwwroot
. '/' . $CFG->admin
. '/settings.php?section=' . $bookmark . '">' . $temp->visiblename
. "</a></li>\n";
55 } else if ($temp instanceof admin_externalpage
) {
56 $this->content
->text
.= '<li><a href="' . $temp->url
. '">' . $temp->visiblename
. "</a></li>\n";
59 $this->content
->text
.= "</ol>\n";
64 if (isset($this->page
->section
) and $this->page
->section
== 'search'){
65 // the search page can't be properly bookmarked at present
66 $this->content
->footer
= '';
67 } else if (($section = (isset($this->page
->section
) ?
$this->page
->section
: '')) && (in_array($section, $bookmarks))) {
68 $this->content
->footer
= '<a href="' . $CFG->wwwroot
. '/blocks/admin_bookmarks/delete.php?section=' . $section . '&sesskey='.sesskey().'">' . get_string('unbookmarkthispage','admin') . '</a>';
69 } else if ($section = (isset($this->page
->section
) ?
$this->page
->section
: '')) {
70 $this->content
->footer
= '<a href="' . $CFG->wwwroot
. '/blocks/admin_bookmarks/create.php?section=' . $section . '&sesskey='.sesskey().'">' . get_string('bookmarkthispage','admin') . '</a>';
72 $this->content
->footer
= '';
75 return $this->content
;