-
Notifications
You must be signed in to change notification settings - Fork 1
/
customcode.php
98 lines (71 loc) · 3.1 KB
/
customcode.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
<?php
require_once('polyfill.php');
require_once(INCLUDE_DIR . 'class.plugin.php');
require_once(INCLUDE_DIR . 'class.osticket.php');
require_once('config.php');
class CustomCodePlugin extends Plugin {
var $config_class = "CustomCodePluginConfig";
function bootstrap() {
$filepath = INCLUDE_DIR . "client/header.inc.php";
$contents = file_get_contents($filepath);
$tag_start = "<!-- start custom code -->";
if (!str_contains($contents, $tag_start)){
//Add custom code. It's been removed for some reason, maybe an upgrade?
$this->InsertCustomCode();
}
// staff side
$filepath = INCLUDE_DIR . "staff/header.inc.php";
$contents = file_get_contents($filepath);
$tag_start = "<!-- start custom code -->";
if (!str_contains($contents, $tag_start)){
//Add custom code. It's been removed for some reason, maybe an upgrade?
$this->InsertCustomStaffCode();
}
}
function InsertCustomCode() {
try {
$config = $this->getConfig();
$filepath = INCLUDE_DIR . "client/header.inc.php";
//Place it all just before the </head>, its just a reference point
$find = "</head>";
$tag_start = "<!-- start custom code -->";
$tag_end = "<!-- end custom code-->";
$contents = file_get_contents($filepath);
$css = $config->get('custom-code-css');
$js = $config->get('custom-code-js');
$replace = $tag_start;
$replace .= "<style>" . $css . "</style>";
$replace .= "<script>" . $js . "</script>";
$replace .= $tag_end;
$replace .= "</head>"; //don't forget to put it back
$contents = str_replace($find, $replace, $contents);
file_put_contents($filepath, $contents);
} catch(Exception $e) {
//maybe log this?
error_log($e->getMessage(), 0);
}
}
function InsertCustomStaffCode() {
try {
$config = $this->getConfig();
$filepath = INCLUDE_DIR . "staff/header.inc.php";
//Place it all just before the </head>, its just a reference point
$find = "</head>";
$tag_start = "<!-- start custom code -->";
$tag_end = "<!-- end custom code-->";
$contents = file_get_contents($filepath);
$css = $config->get('custom-staff-code-css');
$js = $config->get('custom-staff-code-js');
$replace = $tag_start;
$replace .= "<style>" . $css . "</style>";
$replace .= "<script>" . $js . "</script>";
$replace .= $tag_end;
$replace .= "</head>"; //don't forget to put it back
$contents = str_replace($find, $replace, $contents);
file_put_contents($filepath, $contents);
} catch(Exception $e) {
//maybe log this?
error_log($e->getMessage(), 0);
}
}
}