-
Notifications
You must be signed in to change notification settings - Fork 7
/
extension.driver.php
64 lines (58 loc) · 2.18 KB
/
extension.driver.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
<?php
Class extension_backend_add_script extends Extension
{
/**
* About this extension:
*/
public function about()
{
return array(
'name' => 'Backend add script',
'version' => '1.2',
'release-date' => '2011-12-15',
'author' => array(
'name' => 'Twisted Interactive',
'website' => 'http://www.twisted.nl'),
'description' => 'Adds a hook to the backend so you can easily make JavaScript adjustments on certain pages'
);
}
/**
* Set the delegates
*/
public function getSubscribedDelegates()
{
return array(
array(
'page' => '/backend/',
'delegate' => 'InitaliseAdminPageHead',
'callback' => 'addScriptToHead'
)
);
}
/**
* Add script to the <head>-section of the admin area
*/
public function addScriptToHead($context)
{
// We have to put a lot of javascript here since there are missing some handles:
$javaScript = "\n";
$callback = Administration::instance()->getPageCallback();
// Current callback and action:
$driver = '"'.$callback['driver'].'"';
$action = isset($callback['context']['page']) ? '"'.$callback['context']['page'].'"' : 'false';
$section= isset($callback['context']['section_handle']) ? '"'.$callback['context']['section_handle'].'"' : 'false';
$idEntry= isset($callback['context']['entry_id']) ? '"'.$callback['context']['entry_id'].'"' : 'false';
// User information:
$javaScript.= "var user_id = ".Administration::instance()->Author->get('id').";\n";
$javaScript.= "var user_type = '".Administration::instance()->Author->get('user_type')."';\n";
$javaScript.= "var driver = ".$driver.";\n";
$javaScript.= "var action = ".$action.";\n";
$javaScript.= "var section = ".$section.";\n";
$javaScript.= "var id_entry = ".$idEntry.";\n";
$tag = new XMLElement('script', $javaScript, array('type'=>'text/javascript'));
Administration::instance()->Page->addElementToHead($tag);
Administration::instance()->Page->addScriptToHead(URL.'/extensions/backend_add_script/assets/custom.js');
Administration::instance()->Page->addStylesheetToHead(URL.'/extensions/backend_add_script/assets/custom.css');
}
}
?>