forked from moodlehq/moodle-local_dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.php
71 lines (61 loc) · 2.64 KB
/
lib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
// 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/>.
/**
* The plugin's external API is defined here
*
* @package local_dev
* @copyright 2012 David Mudrak <david@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Custom URL handling class that supports the plugin appearing outside its real location
*/
class local_dev_url extends moodle_url {
/**
* Given the real location if the script like '/local/dev/file.php' this method
* actually creates URL to '/dev/file.php'
*/
public function __construct($url, array $params = null) {
if (is_string($url) and preg_match("~^/local/dev(/?)(.*)$~", $url, $matches)) {
$url = '/dev/'.$matches[2];
}
parent::__construct($url, $params);
}
}
/**
* Puts AMOS into the global navigation tree.
*
* @param global_navigation $navigation the navigation tree instance
* @category navigation
*/
function local_dev_extend_navigation(global_navigation $navigation) {
global $CFG;
if (!empty($CFG->hidelocaldevfromnavigation)) {
return;
}
if (!defined('LOCAL_DEV_LOCALLIB_LOADED')) {
return;
}
$devnode = $navigation->add(get_string('pluginname', 'local_dev'), null, navigation_node::TYPE_CUSTOM, null, 'local_dev-root');
$devnode->add(get_string('developers', 'local_dev'), new local_dev_url('/local/dev/index.php'), navigation_node::TYPE_CUSTOM, null, 'local_dev-developers');
$devnode->add(get_string('contributions', 'local_dev'), new local_dev_url('/local/dev/contributions.php'), navigation_node::TYPE_CUSTOM, null, 'local_dev-contributions');
if (has_capability('local/dev:manage', context_system::instance())) {
$admin = $devnode->add(get_string('administration'));
$admin->add(get_string('adminoverview', 'local_dev'), new local_dev_url('/local/dev/admin/index.php'));
$admin->add(get_string('gitaliases', 'local_dev'), new local_dev_url('/local/dev/admin/git-aliases.php'));
}
}