-
Notifications
You must be signed in to change notification settings - Fork 2
/
lib.php
75 lines (71 loc) · 2.62 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
72
73
74
75
<?php
// This file is part of the chatwoot local plugin for Moodle
//
// 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/>.
/**
* Library of interface functions and constants for module chatwoot
*
* All the core Moodle functions, needed to allow the module to work
* integrated in Moodle should be placed here.
*
* All the chatwoot specific functions, needed to implement all the module
* logic, should go to locallib.php. This will help to save some memory when
* Moodle is performing actions across all modules.
*
* @package local_chatwoot
* @copyright 2024 Davor Budimir <[email protected]>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Add extra HTML meta elements according to the Chatwoot widget specification.
*
* Give plugins an opportunity to add any head elements.
* The callback must always return a string containing valid html head content.
*
* Implemented in MDL-53978 (Moodle 3.3).
*
* @return string A string containing the Chatwoot embed code otherwise, an empty string.
*/
function local_chatwoot_before_standard_html_head() {
global $PAGE;
// Trap any catchable error.
try {
$enabled = (bool)get_config('local_chatwoot', 'enabled');
if (!$enabled) {
return '';
}
list($context, $course, $cm) = get_context_info_array($PAGE->context->id);
$ignored_scripts_str = get_config('local_chatwoot', 'ignored_script_names');
$ignored_scripts = explode(",", $ignored_scripts_str);
$ignore = false;
foreach($ignored_scripts as $ignored){
if($_SERVER['SCRIPT_NAME'] == trim($ignored)){
$ignore = true;
}
}
if(!$ignore){
$response = (new \local_chatwoot\helper)->embed_chatwoot($context, $course);
if (!empty($response)) {
return $response;
}
}else{
return '';
}
} catch (Exception $e) {
// Do nothing here.
return '';
}
return '';
}