-
Notifications
You must be signed in to change notification settings - Fork 6
/
extension.driver.php
executable file
·86 lines (76 loc) · 2.27 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* Backend language switcher
*
* @author John J. Camilleri
* @version 1.2.1
*/
Class extension_backend_language_switcher extends Extension{
public function getSubscribedDelegates(){
return array(
array(
'page' => '/backend/',
'delegate' => 'InitialiseAdminPageHead',
'callback' => 'initializeAdmin',
),
);
}
private $LOAD_NUMBER = 955935299;
public function initializeAdmin($context) {
$assets_path = URL . '/extensions/backend_language_switcher/assets';
$page = Administration::instance()->Page;
$author = null;
if (is_callable(array('Symphony', 'Author'))) {
$author = Symphony::Author();
} else {
$author = Administration::instance()->Author;
}
//frontend localization
$codes = Symphony::Configuration()->get('langs', 'frontend_localisation');
//language redirect cases
if ($codes == '' || $codes == null) $codes = Symphony::Configuration()->get('language_codes', 'language_redirect');
if ($codes == '' || $codes == null) $codes = Symphony::Configuration()->get('languages', 'language_redirect');
$languages = array_filter(array_map('trim',explode(',', $codes )));
// CSS & JS for all admin
$page->addStylesheetToHead($assets_path . '/language_switcher.css', 'all', $LOAD_NUMBER++);
$script = new XMLElement('script');
$script->setAttributeArray(array('type' => 'text/javascript'));
$script->setValue(sprintf(
"
Symphony.Languages = %s;
Symphony.Author = {
id : %d,
default_section : %d,
email : '%s',
first_name : '%s',
last_name : '%s',
username : '%s',
language : '%s'
};
",
empty($languages) ? '[]' : "['" . implode("','", $languages) . "']",
$author->get('id'),
$author->get('default_section'),
$author->get('email'),
addslashes($author->get('first_name')),
addslashes($author->get('last_name')),
$author->get('username'),
$author->get('language')
));
$script->setSelfClosingTag(false);
$page->addElementToHead($script, $this->LOAD_NUMBER++);
$page->addScriptToHead($assets_path . '/language_switcher.js', $this->LOAD_NUMBER++);
}
public function enable() {
return $this->install();
}
public function disable() {
return true;
}
public function install() {
return true;
}
public function uninstall() {
return true;
}
}