forked from vfremaux/moodle-local_vmoodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.php
71 lines (62 loc) · 2.59 KB
/
renderer.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/>.
class local_vmoodle_renderer extends plugin_renderer_base {
public function pix_url($image, $subplugin = null) {
global $CFG, $OUTPUT;
if (!$subplugin) {
return $OUTPUT->pix_url($image, 'local_vmoodle');
}
list($type, $plugin) = explode('_', $subplugin);
$parts = pathinfo($image);
$filepath = $CFG->dirroot.'/local/vmoodle/plugins/'.$plugin.'/pix/'.$parts['filename'];
// We do not support SVG.
$realpath = local_vmoodle_renderer::image_exists($filepath, false);
$parts = pathinfo($realpath);
return $CFG->wwwroot.'/local/vmoodle/plugins/'.$plugin.'/pix/'.$parts['filename'].'.'.$parts['extension'];
}
/**
* Checks if file with any image extension exists.
*
* The order to these images was adjusted prior to the release of 2.4
* At that point the were the following image counts in Moodle core:
*
* - png = 667 in pix dirs (1499 total)
* - gif = 385 in pix dirs (606 total)
* - jpg = 62 in pix dirs (74 total)
* - jpeg = 0 in pix dirs (1 total)
*
* There is work in progress to move towards SVG presently hence that has been prioritiesed.
*
* @param string $filepath
* @param bool $svg If set to true SVG images will also be looked for.
* @return string image name with extension
*/
private static function image_exists($filepath, $svg = false) {
if ($svg && file_exists("$filepath.svg")) {
return "$filepath.svg";
} else if (file_exists("$filepath.png")) {
return "$filepath.png";
} else if (file_exists("$filepath.gif")) {
return "$filepath.gif";
} else if (file_exists("$filepath.jpg")) {
return "$filepath.jpg";
} else if (file_exists("$filepath.jpeg")) {
return "$filepath.jpeg";
} else {
return false;
}
}
}