-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathqa-book-admin.php
375 lines (328 loc) · 14 KB
/
qa-book-admin.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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
<?php
class qa_book_admin {
function option_default($option) {
switch($option) {
case 'book_plugin_sort_q':
return 0;
case 'book_plugin_inc':
return 0;
case 'book_plugin_req_qv_no':
return 5;
case 'book_plugin_req_av_no':
return 5;
case 'book_plugin_refresh_last':
return time();
case 'book_plugin_refresh_hours':
return 24;
case 'book_plugin_loc':
return dirname(__FILE__).'/book.html';
case 'book_plugin_loc_pdf':
return dirname(__FILE__).'/book.pdf';
case 'book_plugin_request':
return 'book';
case 'book_plugin_request_pdf':
return 'book.pdf';
case 'book_plugin_css':
return file_get_contents(dirname(__FILE__).'/book.css');
case 'book_plugin_template':
return file_get_contents(dirname(__FILE__).'/template.html');
case 'book_plugin_template_front':
return file_get_contents(dirname(__FILE__).'/front.html');
case 'book_plugin_template_toc':
return file_get_contents(dirname(__FILE__).'/toc.html');
case 'book_plugin_template_back':
return file_get_contents(dirname(__FILE__).'/back.html');
case 'book_plugin_template_category':
return file_get_contents(dirname(__FILE__).'/category.html');
case 'book_plugin_template_questions':
return file_get_contents(dirname(__FILE__).'/questions.html');
case 'book_plugin_template_question':
return file_get_contents(dirname(__FILE__).'/question.html');
case 'book_plugin_template_answer':
return file_get_contents(dirname(__FILE__).'/answer.html');
default:
return null;
}
}
function allow_template($template)
{
return ($template!='admin');
}
function admin_form(&$qa_content)
{
// Process form input
$ok = null;
if (qa_clicked('book_plugin_process') || qa_clicked('book_plugin_save')) {
qa_opt('book_plugin_active',(bool)qa_post_text('book_plugin_active'));
qa_opt('book_plugin_cats',(bool)qa_post_text('book_plugin_cats'));
qa_opt('book_plugin_catex',qa_post_text('book_plugin_catex'));
qa_opt('book_plugin_sort_q',(int)qa_post_text('book_plugin_sort_q'));
qa_opt('book_plugin_req_sel',(bool)qa_post_text('book_plugin_req_sel'));
qa_opt('book_plugin_req_abest',(bool)qa_post_text('book_plugin_req_abest'));
qa_opt('book_plugin_req_abest_max',(int)qa_post_text('book_plugin_req_abest_max'));
qa_opt('book_plugin_req_qv',(bool)qa_post_text('book_plugin_req_qv'));
qa_opt('book_plugin_req_av',(bool)qa_post_text('book_plugin_req_av'));
qa_opt('book_plugin_req_qv_no',(int)qa_post_text('book_plugin_req_qv_no'));
qa_opt('book_plugin_req_av_no',(int)qa_post_text('book_plugin_req_av_no'));
qa_opt('book_plugin_static',(bool)qa_post_text('book_plugin_static'));
qa_opt('book_plugin_pdf',(bool)qa_post_text('book_plugin_pdf'));
qa_opt('book_plugin_loc',qa_post_text('book_plugin_loc'));
qa_opt('book_plugin_loc_pdf',qa_post_text('book_plugin_loc_pdf'));
qa_opt('book_plugin_refresh',(bool)qa_post_text('book_plugin_refresh'));
qa_opt('book_plugin_refresh_time',(bool)qa_post_text('book_plugin_refresh_time'));
qa_opt('book_plugin_refresh_cron',(bool)qa_post_text('book_plugin_refresh_cron'));
qa_opt('book_plugin_refresh_hours',(int)qa_post_text('book_plugin_refresh_hours'));
qa_opt('book_plugin_request',qa_post_text('book_plugin_request'));
qa_opt('book_plugin_request_pdf',qa_post_text('book_plugin_request_pdf'));
qa_opt('book_plugin_css',qa_post_text('book_plugin_css'));
qa_opt('book_plugin_template',qa_post_text('book_plugin_template'));
qa_opt('book_plugin_template_front',qa_post_text('book_plugin_template_front'));
qa_opt('book_plugin_template_back',qa_post_text('book_plugin_template_back'));
qa_opt('book_plugin_template_toc',qa_post_text('book_plugin_template_toc'));
qa_opt('book_plugin_template_category',qa_post_text('book_plugin_template_category'));
qa_opt('book_plugin_template_questions',qa_post_text('book_plugin_template_questions'));
qa_opt('book_plugin_template_question',qa_post_text('book_plugin_template_question'));
qa_opt('book_plugin_template_answer',qa_post_text('book_plugin_template_answer'));
if(qa_clicked('book_plugin_process') && qa_opt('book_plugin_static'))
$ok = qa_book_plugin_createBook();
else
$ok = qa_lang('admin/options_saved');
}
else if (qa_clicked('book_plugin_reset')) {
foreach($_POST as $i => $v) {
$def = $this->option_default($i);
if($def !== null) qa_opt($i,$def);
}
$ok = qa_lang('admin/options_reset');
}
// Create the form for display
$fields = array();
$fields[] = array(
'label' => 'Activate Plugin',
'tags' => 'NAME="book_plugin_active"',
'value' => qa_opt('book_plugin_active'),
'type' => 'checkbox',
);
$fields[] = array(
'type' => 'blank',
);
$fields[] = array(
'label' => 'Sort By Categories',
'tags' => 'onchange="if(this.checked) $(\'#book_plugin_cat_div\').show(); else $(\'#book_plugin_cat_div\').hide();" NAME="book_plugin_cats"',
'value' => qa_opt('book_plugin_cats'),
'type' => 'checkbox',
);
$fields[] = array(
'value' => '<span style="display:'.(qa_opt('book_plugin_cats')?'block':'none').'" id="book_plugin_cat_div"><i>Categories to exclude (comma seperated categoryid list):</i><br/><input name="book_plugin_catex" id="book_plugin_catex" value="'.qa_opt('book_plugin_catex').'"></span>',
'type' => 'static',
);
$sort = array(
'votes',
'date',
);
$fields[] = array(
'id' => 'book_plugin_sort_q',
'label' => 'Sort questions by',
'tags' => 'NAME="book_plugin_sort_q" ID="book_plugin_sort_q"',
'type' => 'select',
'options' => $sort,
'value' => @$sort[qa_opt('book_plugin_sort_q')],
);
$fields[] = array(
'type' => 'blank',
);
$fields[] = array(
'value' => '<b>Restrict inclusion to:</b>',
'type' => 'static',
);
$fields[] = array(
'label' => 'Selected answers',
'tags' => 'NAME="book_plugin_req_sel"',
'value' => qa_opt('book_plugin_req_sel'),
'type' => 'checkbox',
);
$fields[] = array(
'label' => 'Highest voted answers',
'tags' => 'onclick="if(this.checked) $(\'#book_plugin_req_abest_max_div\').show(); else $(\'#book_plugin_req_abest_max_div\').hide();" NAME="book_plugin_req_abest"',
'value' => qa_opt('book_plugin_req_abest'),
'type' => 'checkbox',
);
$fields[] = array(
'value' => '<span id="book_plugin_req_abest_max_div" style="display:'.(qa_opt('book_plugin_req_abest')?'block':'none').'">max number of answers to include: <input name="book_plugin_req_abest_max" size="3" value="'.(qa_opt('book_plugin_req_abest_max')?qa_opt('book_plugin_req_abest_max'):'').'"></span>',
'type' => 'static',
);
$fields[] = array(
'label' => 'Questions with minimum votes',
'tags' => 'onclick="if(this.checked) $(\'#book_plugin_req_qv_div\').show(); else $(\'#book_plugin_req_qv_div\').hide();" NAME="book_plugin_req_qv"',
'value' => qa_opt('book_plugin_req_qv'),
'type' => 'checkbox',
);
$fields[] = array(
'value' => '<span id="book_plugin_req_qv_div" style="display:'.(qa_opt('book_plugin_req_qv')?'block':'none').'">min. votes for inclusion: <input name="book_plugin_req_qv_no" size="3" value="'.qa_opt('book_plugin_req_qv_no').'"></span>',
'type' => 'static',
);
$fields[] = array(
'label' => 'Answers with minimum votes',
'tags' => 'onclick="if(this.checked) $(\'#book_plugin_req_av_div\').show(); else $(\'#book_plugin_req_av_div\').hide();" NAME="book_plugin_req_av"',
'value' => qa_opt('book_plugin_req_av'),
'type' => 'checkbox',
);
$fields[] = array(
'value' => '<span id="book_plugin_req_av_div" style="display:'.(qa_opt('book_plugin_req_av')?'block':'none').'">min. votes for inclusion: <input name="book_plugin_req_av_no" size="3" value="'.qa_opt('book_plugin_req_av_no').'"></span>',
'type' => 'static',
);
$fields[] = array(
'type' => 'blank',
);
$fields[] = array(
'label' => 'Create Static Book',
'note' => '<i>if this is unchecked, accessing the book page will recreate the book on every view</i>',
'tags' => 'onclick="if(this.checked) $(\'#book_plugin_loc\').show(); else $(\'#book_plugin_loc\').hide();" NAME="book_plugin_static"',
'value' => qa_opt('book_plugin_static'),
'type' => 'checkbox',
);
$fields[] = array(
'value' => '<span id="book_plugin_loc" style="display:'.(qa_opt('book_plugin_static')?'block':'none').'">Location (must be writable): <input name="book_plugin_loc" value="'.qa_opt('book_plugin_loc').'"></span>',
'type' => 'static',
);
$fields[] = array(
'type' => 'blank',
);
$fields[] = array(
'label' => 'Create Static PDF',
'note' => '<i>requires wkhtmltopdf - see README.rst</i>',
'tags' => 'onclick="if(this.checked) $(\'#book_plugin_loc_pdf\').show(); else $(\'#book_plugin_loc_pdf\').hide();" NAME="book_plugin_pdf"',
'value' => qa_opt('book_plugin_pdf'),
'type' => 'checkbox',
);
$fields[] = array(
'value' => '<span id="book_plugin_loc_pdf" style="display:'.(qa_opt('book_plugin_pdf')?'block':'none').'">Location (must be writable): <input name="book_plugin_loc_pdf" value="'.qa_opt('book_plugin_loc_pdf').'"></span>',
'type' => 'static',
);
$fields[] = array(
'type' => 'blank',
);
$fields[] = array(
'label' => 'Recreate Static Book',
'tags' => 'onclick="if(this.checked) $(\'#book_plugin_refresh_hours\').show(); else $(\'#book_plugin_refresh_hours\').hide();" NAME="book_plugin_refresh"',
'value' => qa_opt('book_plugin_refresh'),
'type' => 'checkbox',
);
$cron_url = qa_opt('site_url').qa_opt('book_plugin_request').'?cron=true';
$fields[] = array(
'value' => '<div id="book_plugin_refresh_hours" style="display:'.(qa_opt('book_plugin_refresh')?'block':'none').'">minimum time to recreate: <input name="book_plugin_refresh_hours" value="'.qa_opt('book_plugin_refresh_hours').'" size="3"> hours<br/><i>if this is set to zero, the auto-recreate will not run, and the cron url may be called at any time.<br/><br/><input type="checkbox" name="book_plugin_refresh_time" '.(qa_opt('book_plugin_refresh_time')?'checked':'').'> recreate on next access after above interval<br/><br/><input type="checkbox" name="book_plugin_refresh_cron" '.(qa_opt('book_plugin_refresh_cron')?'checked':'').'>recreate via cron url below<br/><span style="font-style:italic;">url is currently <a href="'.$cron_url.'">'.$cron_url.'</a></span></div>',
'type' => 'static',
);
$fields[] = array(
'type' => 'blank',
);
$fields[] = array(
'label' => 'Book Permalink',
'note' => '<i>the url used to access the book, either via static file, or on the fly</i>',
'tags' => 'NAME="book_plugin_request"',
'value' => qa_opt('book_plugin_request'),
);
$fields[] = array(
'label' => 'Book PDF Permalink',
'note' => '<i>the url used to access the PDF file; should correspond with static PDF location above</i>',
'tags' => 'NAME="book_plugin_request_pdf"',
'value' => qa_opt('book_plugin_request_pdf'),
);
$fields[] = array(
'type' => 'blank',
);
$fields[] = array(
'label' => 'Book CSS',
'note' => '<i>book.css</i>',
'tags' => 'NAME="book_plugin_css"',
'value' => qa_opt('book_plugin_css'),
'type' => 'textarea',
'rows' => '10',
);
$fields[] = array(
'type' => 'blank',
);
$fields[] = array(
'label' => 'Book Template',
'note' => '<i>template.html</i>',
'tags' => 'NAME="book_plugin_template"',
'value' => qa_opt('book_plugin_template'),
'type' => 'textarea',
'rows' => '10',
);
$fields[] = array(
'label' => 'Front Cover Template',
'note' => '<i>front.html</i>',
'tags' => 'NAME="book_plugin_template_front"',
'value' => qa_opt('book_plugin_template_front'),
'type' => 'textarea',
'rows' => '10',
);
$fields[] = array(
'label' => 'Back Cover Template',
'note' => '<i>back.html</i>',
'tags' => 'NAME="book_plugin_template_back"',
'value' => qa_opt('book_plugin_template_back'),
'type' => 'textarea',
'rows' => '10',
);
$fields[] = array(
'label' => 'Table of Contents Template',
'note' => '<i>toc.html</i>',
'tags' => 'NAME="book_plugin_template_toc"',
'value' => qa_opt('book_plugin_template_toc'),
'type' => 'textarea',
'rows' => '10',
);
$fields[] = array(
'label' => 'Category Template',
'note' => '<i>category.html - used when sorting by categories</i>',
'tags' => 'NAME="book_plugin_template_category"',
'value' => qa_opt('book_plugin_template_category'),
'type' => 'textarea',
'rows' => '10',
);
$fields[] = array(
'label' => 'Questions Template',
'note' => '<i>questions.html - used when not sorting by categories</i>',
'tags' => 'NAME="book_plugin_template_questions"',
'value' => qa_opt('book_plugin_template_questions'),
'type' => 'textarea',
'rows' => '10',
);
$fields[] = array(
'label' => 'Question Template',
'note' => '<i>question.html</i>',
'tags' => 'NAME="book_plugin_template_question"',
'value' => qa_opt('book_plugin_template_question'),
'type' => 'textarea',
'rows' => '10',
);
$fields[] = array(
'label' => 'Answer Template',
'note' => '<i>answer.html</i>',
'tags' => 'NAME="book_plugin_template_answer"',
'value' => qa_opt('book_plugin_template_answer'),
'type' => 'textarea',
'rows' => '10',
);
return array(
'ok' => ($ok && !isset($error)) ? $ok : null,
'fields' => $fields,
'buttons' => array(
array(
'label' => qa_lang_html('admin/save_options_button'),
'tags' => 'NAME="book_plugin_save"',
),
array(
'label' => 'Process',
'tags' => 'NAME="book_plugin_process"',
),
array(
'label' => qa_lang_html('admin/reset_options_button'),
'tags' => 'NAME="book_plugin_reset"',
),
),
);
}
}