-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScripts.php
More file actions
49 lines (35 loc) · 1.04 KB
/
Scripts.php
File metadata and controls
49 lines (35 loc) · 1.04 KB
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
<?php
namespace MerapiPanel\Module\Panel;
use MerapiPanel\Box\Module\__Fragment;
class Scripts extends __Fragment
{
protected $scripts = [];
protected $module;
function onCreate(\MerapiPanel\Box\Module\Entity\Module $module)
{
$this->module = $module;
}
function add($id, $script)
{
$this->scripts[$id] = $script;
}
function remove($id)
{
unset($this->scripts[$id]);
}
function getScripts()
{
$scripts = "";
foreach ($this->scripts as $id => $script) {
$script = trim($script);
preg_match('/<script.*?src=["\']([^"\']+)["\'].*?><\/script>/im', $script, $matches);
if (isset($matches[1])) {
$script = "<script id='$id' src='$matches[1]' type='text/javascript'></script>\n";
} else {
$script = preg_replace("/<script[^>]*>/", "<script id='$id' type='text/javascript'>", $script) . "\n";
}
$scripts .= $script;
}
return $scripts;
}
}