forked from symphonists/documenter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.driver.php
More file actions
244 lines (205 loc) · 6.54 KB
/
extension.driver.php
File metadata and controls
244 lines (205 loc) · 6.54 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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<?php
class Extension_Documenter extends Extension {
public function about() {
return array(
'name' => 'Documenter',
'version' => '1.0RC1',
'release-date' => '2011-03-01',
'author' => array(
'name' => 'craig zheng',
'email' => '[email protected]'
),
'description' => 'Document your back end for clients or users.'
);
}
public function fetchNavigation() {
return array(
array(
'location' => 'System',
'name' => __('Documentation'),
'link' => '/',
'limit' => 'developer'
)
);
}
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' => 'AppendElementBelowView',
'callback' => 'appendDocs'
)
);
}
public function loadAssets($context) {
$page = $context['parent']->Page;
$assets_path = '/extensions/documenter/assets/';
$page->addStylesheetToHead(URL . $assets_path . 'documenter.admin.css', 'screen', 120);
$page->addScriptToHead(URL . $assets_path . 'documenter.admin.js', 130);
}
public function appendDocs($context) {
$current_page = str_replace(URL . '/symphony', '', $context['parent']->Page->_Parent->getCurrentPageURL());
if(preg_match('/edit/',$current_page)) {
$pos = strripos($current_page, '/edit/');
$current_page = substr($current_page, 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
Administration::instance()->ExtensionManager->notifyMembers('appendDocsPre',
'/backend/', array(
'pages' => &$pages
)
);
// Fetch documentation items
$items = array();
foreach($pages as $page) {
if(in_array($current_page,$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
Administration::instance()->ExtensionManager->notifyMembers('appendDocsPost',
'/backend/', array(
'doc_item' => &$doc_items
)
);
}
}
}
// Allows a page to have more then one documentation source
if(!empty($items)) {
// Append help item
$help = new XMLElement('a', Symphony::Configuration()->get('button-text', 'documentation'), array('class' => 'documenter button', 'title' => __('View Documentation')));
$context['parent']->Page->Body->appendChild($help);
// Generate documentation panel
$docs = new XMLElement('div', NULL, array('id' => 'documenter-drawer'));
$count = 0;
foreach($items as $item) {
$title = array();
// Add title
if(isset($item['title'])) {
if($count == 0) {
$title = array('id' => 'documenter-title');
}
$docs->appendChild(
new XMLElement('h2', $item['title'], $title)
);
}
// Add formatted help text
$docs->appendChild(
new XMLElement('div', $item['content_formatted'], array('class' => 'documenter-content'))
);
$count++;
}
// Append documentation
$context['parent']->Page->Body->appendChild($docs);
}
}
public function uninstall() {
Symphony::Database()->query("DROP TABLE `tbl_documentation`;");
Symphony::Configuration()->remove('text-formatter', 'documentation');
Symphony::Configuration()->remove('button-text', 'documentation');
Administration::instance()->saveConfig();
}
public function install() {
Symphony::Database()->query(
"CREATE TABLE `tbl_documentation` (
`id` int(11) unsigned NOT NULL auto_increment,
`title` varchar(255),
`pages` varchar(255),
`content` text,
`content_formatted` text,
PRIMARY KEY (`id`)
);");
Symphony::Configuration()->set('text-formatter', 'none', 'documentation');
Symphony::Configuration()->set('button-text', __('Need help?'), 'documentation');
Administration::instance()->saveConfig();
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]',
__($this->_Parent->Configuration->get('button-text', 'documentation')),
'text'
);
$label->appendChild($input);
$div->appendChild($label);
$TFM = new TextformatterManager($this->_Parent);
$formatters = $TFM->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);
}
}