forked from ProThoughts/q2apro-popular-questions-widget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
q2apro-popular-questions-admin.php
113 lines (99 loc) · 3.83 KB
/
q2apro-popular-questions-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
<?php
/*
Plugin Name: q2apro Popular questions widget
Plugin Author: q2apro
*/
class q2apro_popular_questions_admin
{
function option_default($option)
{
switch ($option) {
case 'q2apro_popularqu_enabled':
return 1;
case 'q2apro_popularqu_maxqu':
return 7;
case 'q2apro_popularqu_lastdays':
return 3;
case 'q2apro_popularqu_checkhours':
return 24;
case 'q2apro_popularqu_answercount':
return true;
case 'q2apro_popularqu_checktime':
return false;
default:
return null;
}
}
function allow_template($template)
{
return ($template != 'admin');
}
function admin_form(&$qa_content)
{
// process the admin form if admin hits Save-Changes-button
$ok = null;
if (qa_clicked('q2apro_popularqu_save')) {
qa_opt('q2apro_popularqu_enabled', (bool)qa_post_text('q2apro_popularqu_enabled')); // empty or 1
qa_opt('q2apro_popularqu_maxqu', (int)qa_post_text('q2apro_popularqu_maxqu'));
qa_opt('q2apro_popularqu_lastdays', (int)qa_post_text('q2apro_popularqu_lastdays'));
qa_opt('q2apro_popularqu_checkhours', (int)qa_post_text('q2apro_popularqu_checkhours'));
qa_opt('q2apro_popularqu_answercount', (bool)qa_post_text('q2apro_popularqu_answercount'));
$ok = qa_lang('admin/options_saved');
// in case the options have been changed, update the widget
q2apro_save_most_viewed_questions();
}
// form fields to display frontend for admin
$fields = array();
$fields[] = array(
'type' => 'checkbox',
'label' => qa_lang('q2apro_popularqu_lang/enable_plugin'),
'tags' => 'name="q2apro_popularqu_enabled"',
'value' => qa_opt('q2apro_popularqu_enabled'),
);
$fields[] = array(
'type' => 'input',
'label' => qa_lang('q2apro_popularqu_lang/admin_maxqu'),
'tags' => 'name="q2apro_popularqu_maxqu"',
'value' => qa_opt('q2apro_popularqu_maxqu'),
);
$fields[] = array(
'type' => 'checkbox',
'label' => qa_lang('q2apro_popularqu_lang/admin_answercount'),
'tags' => 'name="q2apro_popularqu_answercount"',
'value' => qa_opt('q2apro_popularqu_answercount'),
);
$fields[] = array(
'type' => 'input',
'label' => qa_lang('q2apro_popularqu_lang/admin_lastdays'),
'tags' => 'name="q2apro_popularqu_lastdays"',
'value' => qa_opt('q2apro_popularqu_lastdays'),
);
$fields[] = array(
'type' => 'input',
'label' => qa_lang('q2apro_popularqu_lang/admin_checkhours'),
'tags' => 'name="q2apro_popularqu_checkhours"',
'value' => qa_opt('q2apro_popularqu_checkhours'),
);
$fields[] = array(
'type' => 'static',
'note' => qa_lang('q2apro_popularqu_lang/admin_lastcache') . ' ' . date('Y-m-d H:i:s', (float)qa_opt('q2apro_popularqu_checktime')),
);
$fields[] = array(
'type' => 'static',
'note' => '<span style="color:red;">' . qa_lang('q2apro_popularqu_lang/admin_remember') . ' <a href="' . qa_path('admin/layout') . '">/admin/layout</a></span>',
);
return array(
'ok' => ($ok && !isset($error)) ? $ok : null,
'fields' => $fields,
'buttons' => array(
array(
'label' => qa_lang('main/save_button'),
'tags' => 'name="q2apro_popularqu_save"',
),
),
);
}
}
/*
Omit PHP closing tag to help avoid accidental output
*/