-
Notifications
You must be signed in to change notification settings - Fork 12
/
extension.driver.php
225 lines (188 loc) · 6.11 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<?php
class Extension_Documenter extends Extension {
public function fetchNavigation() {
return array(
array(
'location' => __('System'),
'name' => __('Documentation'),
'link' => '/',
'limit' => 'manager',
)
);
}
public function getSubscribedDelegates() {
return array(
array(
'page' => '/system/preferences/',
'delegate' => 'AddCustomPreferenceFieldsets',
'callback' => 'appendPreferences'
),
array(
'page' => '/system/preferences/',
'delegate' => 'Save',
'callback' => 'savePreferences'
),
array(
'page' => '/backend/',
'delegate' => 'InitaliseAdminPageHead',
'callback' => 'loadAssets'
),
array(
'page' => '/backend/',
'delegate' => 'InitaliseAdminPageHead',
'callback' => 'appendDocs'
)
);
}
public function loadAssets($context) {
Administration::instance()->Page->addStylesheetToHead(URL . '/extensions/documenter/assets/documenter.admin.css', 'screen', 100);
Administration::instance()->Page->addScriptToHead(URL . '/extensions/documenter/assets/documenter.admin.js', 101, false);
}
public function appendDocs($context) {
$current_page_url = str_replace(SYMPHONY_URL, '', Administration::instance()->getCurrentPageURL());
if(preg_match('/edit/',$current_page_url)) {
$pos = strripos($current_page_url, '/edit/');
$current_page_url = substr($current_page_url, 0, $pos + 6);
}
$pages = Symphony::Database()->fetch("
SELECT
d.pages, d.id
FROM
`tbl_documentation` AS d
ORDER BY
d.pages ASC
");
foreach($pages as $key => $value) {
if(strstr($value['pages'],',')) {
$list = explode(',',$value['pages']);
foreach($list as $item){
$pages[] = array('id' => $value['id'], 'page' => $item);
}
unset($pages[$key]);
}
}
###
# Delegate: appendDocsPre
# Description: Allow other extensions to add their own documentation page
Symphony::ExtensionManager()->notifyMembers('appendDocsPre',
'/backend/', array(
'pages' => &$pages
)
);
// Fetch documentation items
$items = array();
foreach($pages as $page) {
if(in_array($current_page_url, $page)) {
if(isset($page['id'])) {
$items[] = Symphony::Database()->fetchRow(0, "
SELECT
d.title, d.content_formatted
FROM
`tbl_documentation` AS d
WHERE
d.id = '{$page['id']}'
LIMIT 1
");
}
else {
###
# Delegate: appendDocsPost
# Description: Allows other extensions to insert documentation for the $current_page_url
Administration::instance()->ExtensionManager->notifyMembers('appendDocsPost',
'/backend/', array(
'doc_item' => &$doc_items
)
);
}
}
}
// Allows a page to have more then one documentation source
if(!empty($items)) {
// Generate documentation panel
$docs = new XMLElement('div', NULL, array('id' => 'documenter-drawer'));
foreach($items as $item) {
// Add title
if(isset($item['title'])) {
$docs->appendChild(
new XMLElement('h2', $item['title'])
);
}
// Add formatted help text
$docs->appendChild(
new XMLElement('div', $item['content_formatted'], array('class' => 'documenter-content'))
);
}
$button = General::sanitize(Symphony::Configuration()->get('button-text', 'Documentation'));
$drawer = Widget::Drawer(
'documenter',
($button != '' ? $button : __('Documentation')),
$docs,
'closed'
);
Administration::instance()->Page->insertDrawer($drawer, 'vertical-right');
}
}
public function uninstall() {
Symphony::Database()->query("DROP TABLE `tbl_documentation`;");
Symphony::Configuration()->remove('text-formatter', 'documentation');
Symphony::Configuration()->remove('button-text', 'documentation');
Symphony::Configuration()->write();
}
public function install() {
Symphony::Database()->query(
"CREATE TABLE `tbl_documentation` (
`id` int(11) unsigned NOT NULL auto_increment,
`title` varchar(255),
`pages` text,
`content` text,
`content_formatted` text,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"
);
Symphony::Configuration()->set('text-formatter', 'none', 'documentation');
Symphony::Configuration()->set('button-text', __('Documentation'), 'documentation');
Symphony::Configuration()->write();
return;
}
public function savePreferences($context) {
if(!is_array($context['settings'])) $context['settings'] = array('documentation' => array('text-formatter' => 'none'));
elseif(!isset($context['settings']['documentation'])) {
$context['settings']['documentation'] = array('text-formatter' => 'none');
}
}
public function appendPreferences($context) {
include_once(TOOLKIT . '/class.textformattermanager.php');
$group = new XMLElement('fieldset');
$group->setAttribute('class', 'settings');
$group->appendChild(new XMLElement('legend', __('Documentation')));
$div = new XMLElement('div');
$div->setAttribute('class', 'group');
// Input for button text
$label = Widget::Label(__('Button Text'));
$input = Widget::Input(
'settings[documentation][button-text]',
General::sanitize(Symphony::Configuration()->get('button-text', 'documentation')),
'text'
);
$label->appendChild($input);
$div->appendChild($label);
$formatters = TextformatterManager::listAll();
// Text formatter select
$label = Widget::Label(__('Text Formatter'));
$options = array();
$options[] = array('none', false, __('None'));
if(!empty($formatters) && is_array($formatters)) {
foreach($formatters as $handle => $about) {
$options[] = array(
$handle,
(Symphony::Configuration()->get('text-formatter', 'documentation') == $handle),
$about['name']);
}
}
$input = Widget::Select('settings[documentation][text-formatter]', $options);
$label->appendChild($input);
$div->appendChild($label);
$group->appendChild($div);
$context['wrapper']->appendChild($group);
}
}