This repository has been archived by the owner on Oct 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathextension.driver.php
180 lines (150 loc) · 5.56 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
Class extension_tabnavigation extends Extension
{
// About this extension:
public function about() {
return array(
'name' => 'tabnavigation',
'version' => '0.51',
'release-date' => '2013-08-01',
'author' => array(
'name' => 'Martijn Gussekloo',
'website' => 'http://www.stylishmedia.com',
'email' => '[email protected]'),
'description' => 'Back-end navigation with tabs for Symphony CMS'
);
}
public function getSubscribedDelegates() {
return array(
array(
'page' => '/backend/',
'delegate' => 'AdminPagePreGenerate',
'callback' => 'appendAssets'
),
array(
'page' => '/system/preferences/',
'delegate' => 'AddCustomPreferenceFieldsets',
'callback' => 'addPreferences'
),
array(
'page' => '/system/preferences/',
'delegate' => 'Save',
'callback' => 'savePreferences'
)
);
}
public function addPreferences($context) {
if (class_exists('Administration')
&& Administration::instance() instanceof Administration
&& Administration::instance()->Page instanceof HTMLPage) {
$navigation = Administration::instance()->Page->getNavigationArray();
$tabs = self::getTabs();
$groupsPerTab = self::getGroupsPerTab();
$fieldset = new XMLElement('fieldset');
$fieldset->setAttribute('class', 'settings');
$fieldset->appendChild(new XMLElement('legend', 'Plugin: Tab navigation'));
// first the input field
$label = new XMLElement('label', 'Available tabs (comma separated)');
$label->appendChild(Widget::Input('settings[tabnavigation][tabs]', implode(',', $tabs), 'text'));
$fieldset->appendChild($label);
// now the select for each tab
$div = new XMLElement('div');
$div->setAttribute('class', 'four columns');
foreach ($tabs as $tabId=>$tab) {
$options = array();
foreach($navigation as $group) {
if ($group['type'] != 'content') continue;
$selected = (isset($groupsPerTab[$tabId]) && in_array($group['name'], $groupsPerTab[$tabId])) ? true : false;
$options[] = array($group['name'], $selected, $group['name']);
}
$label = new XMLElement('label', 'Groups in <strong>' . $tab . '</strong>');
$label->setAttribute('class', 'column');
$label->appendChild(Widget::Select('settings[tabnavigation][tab' . $tabId . '][]', $options, array('multiple'=>true)));
$div->appendChild($label);
}
$fieldset->appendChild($div);
$context['wrapper']->appendChild($fieldset);
}
}
public function savePreferences($context){
if (class_exists('Administration')
&& Administration::instance() instanceof Administration
&& Administration::instance()->Page instanceof HTMLPage) {
$tabs = explode(',', $_POST['settings']['tabnavigation']['tabs']);
unset($_POST['settings']['tabnavigation']['tabs']);
$groupsPerTab = array();
for ($tabId=0;$tabId<99;$tabId++) {
$postVal = $_POST['settings']['tabnavigation']['tab' . $tabId];
// prevent symphony from storing these values
unset($_POST['settings']['tabnavigation']['tab' . $tabId]);
unset($context['settings']['tabnavigation']['tab' . $tabId]);
if (!isset($postVal) || !is_array($postVal)) break;
// add to the groupspertab array
$groupsPerTab[(string)$tabId] = array();
foreach ($postVal as $groupName) {
if (strlen($groupName) > 0) $groupsPerTab[$tabId][] = $groupName;
}
}
$context['settings']['tabnavigation']['tabs'] = implode(',', $tabs);
$context['settings']['tabnavigation']['groups'] = json_encode($groupsPerTab);
return;
}
}
// ====
public function appendAssets($context) {
if (class_exists('Administration')
&& Administration::instance() instanceof Administration
&& Administration::instance()->Page instanceof HTMLPage) {
$tabs = self::getTabs();
$slugs = array();
foreach ($tabs as $tab) {
$slugs[] = self::slug($tab);
}
$jsConfig = array(
'tabs' => $tabs,
'slugs' => $slugs,
'groups' => array()
);
$groups = array();
$groupsPerTab = self::getGroupsPerTab();
foreach ($groupsPerTab as $tabId => $groupNames) {
foreach ($groupNames as $name) {
if (!isset($groups[$name])) $groups[$name] = array();
$groups[$name][] = 'tabnavigation-' . self::slug($tabs[$tabId]);
}
}
foreach ($groups as $name => $slugs) {
$groups[$name] = implode(' ', $slugs);
}
$jsConfig['groups'] = $groups;
Administration::instance()->Page->addScriptToHead(URL . '/extensions/tabnavigation/assets/tabnavigation.backend.js', 80001, false);
Administration::instance()->Page->addStylesheetToHead(URL . '/extensions/tabnavigation/assets/tabnavigation.backend.css', 'screen', 80001, false);
$container = new XMLElement('script', 'jQuery(function() { var tabnavigationConfiguration=' . json_encode($jsConfig) . '; tabnavigationActivate(tabnavigationConfiguration); });');
$logged_in = Symphony::isLoggedIn();
if ($logged_in) {
Administration::instance()->Page->Body->appendChild($container);
}
}
}
// ====
public static function getTabs() {
$settings = Symphony::Configuration()->get('tabnavigation');
if ($settings['tabs'] == '') return array();
$tabs = explode(',', $settings['tabs']);
$out = array();
foreach ($tabs as $tab) {
$out[] = trim($tab);
}
return $out;
}
public static function getGroupsPerTab() {
$settings = Symphony::Configuration()->get('tabnavigation');
$arr = json_decode($settings['groups'], true);
if (!is_array($arr)) return array();
return $arr;
}
public static function slug($title) {
$replace_arr = array(' ', '"', "'", '?', '!', '/', '\\', '+', '`');
return strtolower(str_replace($replace_arr, '-', $title));
}
}