This repository has been archived by the owner on May 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter.php
130 lines (100 loc) · 4.15 KB
/
filter.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
125
126
127
128
129
130
<?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/>.
/* __________________________________________________________________________
*
* Jecho filter for Moodle 2.x
*
* This filter will replace any links to a Jecho file (jecho.json)
* with a execho.html file that presents that exercise.
*
* @package filter
* @subpackage jecho
* @copyright 2015 Patrick Cardona
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* __________________________________________________________________________
*/
/* __________________________________________________________________________
*
*
* Jecho 3 License
*
* Copyright (c) 2012-2015 Patrick Cardona
*
* __________________________________________________________________________
*/
// Jecho 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.
//
// Jecho 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/>.
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/filelib.php');
class filter_jecho extends moodle_text_filter {
function filter($text, array $options = array()) {
global $CFG, $PAGE;
if (!is_string($text)) {
// non string data can not be filtered anyway
return $text;
}
// Set the language of the exercise UI
if (isset($this->localconfig['lang'])) {
$lang = $this->localconfig['lang'];
}
else {
$lang = $CFG->filter_jecho_lang;
}
$newtext = $text; // fullclone is slow and not needed here
$search = '/<a.*?href="([^<]+jecho\.json)"[^>]*>.*?<\/a>/is';
$url = preg_replace_callback($search, 'filter_jecho_callback', $newtext);
if (is_null($url) or $url === $text) {
// error or not filtered
return $text;
}
$execho = rip_tags($CFG->wwwroot . '/filter/jecho/jecho/view.html?urljson=' . $url . '&lang=' . $lang);
$html = '<iframe width="900" height="500" src="'.$execho.'">'.get_string('iframeloaderror','filter_jecho').'</iframe>';
return $html;
}
}
/* ************************************************** */
/* @Function : return the href string */
/* @param : $link is got from the search expression */
/* ************************************************** */
function filter_jecho_callback($link) {
$url = $link[1];
return $url;
}
/* ************************************************** */
/* @Function : remove HTML tags */
/* @param : $string */
/* ************************************************** */
function rip_tags($string) {
// ----- remove HTML TAGs -----
$string = preg_replace ('/<[^>]*>/', '', $string);
// ----- remove control characters -----
$string = str_replace("\r", '', $string); // --- replace with empty space
$string = str_replace("\n", '', $string); // --- replace with empty space
$string = str_replace("\t", '', $string); // --- replace with empty space
return $string;
}
?>