forked from GATEOverflow/mathjax
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqa-formatter-admin.php
144 lines (126 loc) · 4.22 KB
/
qa-formatter-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
<?php
class qa_formatter_admin
{
function allow_template($template)
{
return ($template != 'admin');
}
function option_default($option)
{
switch ($option) {
case 'qa-mathjax-config':
return '
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ [\'$\',\'$\'], ["\\\\(","\\\\)"] ],
config: ["MMLorHTML.js"],
jax: ["input/TeX"],
processEscapes: true
}
});
MathJax.Hub.Config({
"HTML-CSS": {
linebreaks: {
automatic: true
}
}
});';
case 'qa-mathjax-url':
return 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML';
case 'qa-prettify-url':
return 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/highlight.min.js';
case 'qa-formatter-css':
return 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/styles/default.min.css';
case 'qa-mathjax-enable':
return '1';
case 'qa-prettify-enable':
return '1';
case 'qa-ckepreview-enable':
return '1';
default:
return null;
}
}
function admin_form(&$qa_content)
{
// Process form input
$ok = null;
if (qa_clicked('formatter-save-button')) {
foreach ($_POST as $i => $v) {
qa_opt($i, $v);
}
if (!isset($_POST['qa-mathjax-enable']))
qa_opt('qa-mathjax-enable', '0');
if (!isset($_POST['qa-prettify-enable']))
qa_opt('qa-prettify-enable', '0');
if (!isset($_POST['qa-ckepreview-enable']))
qa_opt('qa-ckepreview-enable', '0');
$ok = qa_lang('admin/options_saved');
} else if (qa_clicked('mathjax-reset-button')) {
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' => '<a href="http://docs.mathjax.org/en/latest/configuration.html">MathJax Configuration</a>',
'tags' => 'NAME="qa-mathjax-config"',
'value' => qa_opt('qa-mathjax-config'),
'type' => 'textarea',
'rows' => 20
);
$fields[] = array(
'label' => 'MathJax URL',
'tags' => 'NAME="qa-mathjax-url"',
'value' => qa_opt('qa-mathjax-url'),
'type' => 'text',
);
$fields[] = array(
'label' => 'highlight.js URL',
'tags' => 'NAME="qa-prettify-url"',
'value' => qa_opt('qa-prettify-url'),
'type' => 'text',
);
$fields[] = array(
'label' => 'highlight.js Style URL',
'tags' => 'NAME="qa-formatter-css"',
'value' => qa_opt('qa-formatter-css'),
'type' => 'text',
);
$fields[] = array(
'label' => 'Enable MathJax',
'tags' => 'NAME="qa-mathjax-enable"',
'value' => qa_opt('qa-mathjax-enable'),
'type' => 'checkbox',
);
$fields[] = array(
'label' => 'Enable Prettify',
'tags' => 'NAME="qa-prettify-enable"',
'value' => qa_opt('qa-prettify-enable'),
'type' => 'checkbox',
);
$fields[] = array(
'label' => 'Enable CKEditor Preview',
'tags' => 'NAME="qa-ckepreview-enable"',
'value' => qa_opt('qa-ckepreview-enable'),
'type' => 'checkbox',
);
return array(
'ok' => ($ok && !isset($error)) ? $ok : null,
'fields' => $fields,
'buttons' => array(
array(
'label' => qa_lang_html('main/save_button'),
'tags' => 'NAME="formatter-save-button"',
),
array(
'label' => qa_lang_html('admin/reset_options_button'),
'tags' => 'NAME="formatter-reset-button"',
),
),
);
}
}