-
Notifications
You must be signed in to change notification settings - Fork 11
/
locallib.php
executable file
·124 lines (107 loc) · 3.91 KB
/
locallib.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
* *************************************************************************
* * OOHOO - Tab Display **
* *************************************************************************
* @package mod **
* @subpackage tab **
* @name tab **
* @copyright oohoo.biz **
* @link http://oohoo.biz **
* @author Patrick Thibaudeau **
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **
* *************************************************************************
* ************************************************************************ */
defined('MOODLE_INTERNAL') || die;
require_once("$CFG->libdir/filelib.php");
require_once("$CFG->libdir/resourcelib.php");
require_once("$CFG->dirroot/mod/tab/lib.php");
/**
* File browsing support class
*/
class tab_content_file_info extends file_info_stored {
/**
* Returns parent file_info instance
* @return file_info|null file_info instance or null for root
*/
public function get_parent() {
if ($this->lf->get_filepath() === '/' and $this->lf->get_filename() === '.') {
return $this->browser->get_file_info($this->context);
}
return parent::get_parent();
}
/**
* Returns localised visible name.
* @return string
*/
public function get_visible_name() {
if ($this->lf->get_filepath() === '/' and $this->lf->get_filename() === '.') {
return $this->topvisiblename;
}
return parent::get_visible_name();
}
}
/**
* Return an array of options for the editor tinyMCE
* @param type $context The context ID
* @return array The array of options for the editor
* @global stdClass $CFG
*/
function tab_get_editor_options($context) {
global $CFG;
return array('subdirs' => 1, 'maxbytes' => $CFG->maxbytes, 'maxfiles' => -1, 'changeformat' => 1, 'context' => $context, 'noclean' => 1, 'trusttext' => 0);
}
/**
* Prepare an URL. Trim, delete useless tags, etc.
* @param string $string The URL to prepare
* @return string
* @global stdClass $CFG
* @global moodle_page $PAGE
*/
function process_urls($string) {
preg_match_all("/<a href=.*?<\/a>/", $string, $matches);
foreach ($matches[0] as $mtch) {
$mtch_bits = explode('"', $mtch);
$string = str_replace($mtch, "{$mtch_bits[1]}", $string);
}
$path = str_replace('<div class="text_to_html">', '', $string);
$path = str_replace('</div>', '', $path);
$path = str_replace('<p>', '', $path);
$path = str_replace('</p>', '', $path);
$string = $path;
return $string;
}
/**
* Returns general link or file embedding html.
* @param string $fullurl
* @param string $title
* @param string $clicktoopen
* @return string html
* @global stdClass $CFG
* @global moodle_page $PAGE
*/
function tab_embed_general($fullurl, $title, $clicktoopen, $mimetype) {
global $PAGE;
$iframe = true;
$id_suffix = md5($fullurl);
if ($iframe) {
$code = <<<EOT
<div class="resourcecontent resourcegeneral">
<iframe id="resourceobject_$id_suffix" src="$fullurl" class="mod-tab-embedded">
$clicktoopen
</iframe>
</div>
EOT;
} else {
$code = <<<EOT
<div class="resourcecontent resourcegeneral">
<object id="resourceobject_$id_suffix" data="$fullurl" type="$mimetype">
<param name="src" value="$fullurl" />
$clicktoopen
</object>
</div>
EOT;
}
$PAGE->requires->js_call_amd('mod_tab/module', 'init', ["resourceobject_$id_suffix"]);
return $code;
}