|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00032 class block_admin_bookmarks extends block_base { 00033 00035 public $blockname = null; 00036 00038 protected $contentgenerated = false; 00039 00041 protected $docked = null; 00042 00046 function init() { 00047 $this->blockname = get_class($this); 00048 $this->title = get_string('pluginname', $this->blockname); 00049 } 00050 00055 function instance_allow_multiple() { 00056 return false; 00057 } 00058 00063 function applicable_formats() { 00064 if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { 00065 return array('all' => true); 00066 } else { 00067 return array('site' => true); 00068 } 00069 } 00070 00074 function get_content() { 00075 00076 global $CFG; 00077 00078 // First check if we have already generated, don't waste cycles 00079 if ($this->contentgenerated === true) { 00080 return $this->content; 00081 } 00082 $this->content = new stdClass(); 00083 00084 if (get_user_preferences('admin_bookmarks')) { 00085 require_once($CFG->libdir.'/adminlib.php'); 00086 $adminroot = admin_get_root(false, false); // settings not required - only pages 00087 00088 $bookmarks = explode(',', get_user_preferences('admin_bookmarks')); 00090 $contents = array(); 00091 foreach($bookmarks as $bookmark) { 00092 $temp = $adminroot->locate($bookmark); 00093 if ($temp instanceof admin_settingpage) { 00094 $contenturl = new moodle_url('/admin/settings.php', array('section'=>$bookmark)); 00095 $contentlink = html_writer::link($contenturl, $temp->visiblename); 00096 $contents[] = html_writer::tag('li', $contentlink); 00097 } else if ($temp instanceof admin_externalpage) { 00098 $contenturl = new moodle_url($temp->url); 00099 $contentlink = html_writer::link($contenturl, $temp->visiblename); 00100 $contents[] = html_writer::tag('li', $contentlink); 00101 } 00102 } 00103 $this->content->text = html_writer::tag('ol', implode('', $contents), array('class' => 'list')); 00104 } else { 00105 $bookmarks = array(); 00106 } 00107 00108 $this->content->footer = ''; 00109 $this->page->settingsnav->initialise(); 00110 $node = $this->page->settingsnav->get('root', navigation_node::TYPE_SETTING); 00111 if (!$node || !$node->contains_active_node()) { 00112 return $this->content; 00113 } 00114 $section = $node->find_active_node()->key; 00115 00116 if ($section == 'search' || empty($section)){ 00117 // the search page can't be properly bookmarked at present 00118 $this->content->footer = ''; 00119 } else if (in_array($section, $bookmarks)) { 00120 $deleteurl = new moodle_url('/blocks/admin_bookmarks/delete.php', array('section'=>$section, 'sesskey'=>sesskey())); 00121 $this->content->footer = html_writer::link($deleteurl, get_string('unbookmarkthispage','admin')); 00122 } else { 00123 $createurl = new moodle_url('/blocks/admin_bookmarks/create.php', array('section'=>$section, 'sesskey'=>sesskey())); 00124 $this->content->footer = html_writer::link($createurl, get_string('bookmarkthispage','admin')); 00125 } 00126 00127 return $this->content; 00128 } 00129 } 00130 00131