forked from aidistan-archives/wp-scibloger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscibloger.php
245 lines (210 loc) · 8.01 KB
/
scibloger.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
<?php
/*
*******************************************************************************
Plugin Name: Science Blog Helper
Plugin URI: http://wordpress.org/plugins/scibloger/
Description: Intended to help people build blogs and write posts on science.
Version: 0.2.5
Author: aidistan
Author URI: http://aidi.no-ip.org
*******************************************************************************
*/
class ScienceBlogHelper {
// Constants
const MENU_SLUG = 'scibloger_page';
const OPTION_GROUP = 'scibloger_options';
const OPTION_MODE = 'scibloger_mode';
const OPTION_MATHJAX = 'scibloger_mathjax';
const OPTION_OUTLINE = 'scibloger_outline';
// Member
var $mDetect;
var $mMathJax;
var $mOutline;
function __construct() {
// Init options
$this -> init_options();
// Load modules
define('BASE_PATH', dirname(__FILE__));
require BASE_PATH . '/libs/Mobile_Detect.php';
require BASE_PATH . '/mathjax.php';
require BASE_PATH . '/outline.php';
// Admin actions
if ( is_admin() ){
// Add settings link on plugin page
add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'add_plugin_settings_link') );
// Add settings menu and page
add_action( 'admin_menu', array($this, 'add_plugin_settings_page') );
add_action( 'admin_init', array($this, 'init_plugin_settings_page') );
}
// Init modules
$this -> mDetect = new Mobile_Detect(); // Usage: $ScienceBlogHelper->mDetect->isMobile()
$this -> mMathJax = new SciBloger_MathJax();
$this -> mOutline = new SciBloger_Outline();
}
function init_options() {
if(!get_option(self::OPTION_MODE)) add_option( self::OPTION_MODE, 'minimal' );
if(!get_option(self::OPTION_MATHJAX)) add_option( self::OPTION_MATHJAX, 'on' );
if(!get_option(self::OPTION_OUTLINE)) add_option( self::OPTION_OUTLINE, 'off' );
}
function add_plugin_settings_link($links) {
if(get_option( self::OPTION_MODE, 'minimal' ) == 'minimal')
$settings_link = '<a href="options-general.php?page=' . self::MENU_SLUG . '">Settings</a>';
else
$settings_link = '<a href="admin.php?page=' . self::MENU_SLUG . '">Settings</a>';
array_unshift($links, $settings_link);
return $links;
}
function add_plugin_settings_page() {
if(get_option( self::OPTION_MODE, 'minimal' ) == 'minimal') {
// Minimal
add_options_page(
'Science Blog Helper',
'SciBloger',
'manage_options',
self::MENU_SLUG,
array( $this, 'create_plugin_settings_page' )
);
} else {
// Maximal
add_utility_page(
'Science Blog Helper',
'SciBloger',
'manage_options',
self::MENU_SLUG,
array( $this, 'create_plugin_settings_page' ),
plugin_dir_url( __FILE__ ) . '/images/menu-icon.png'
);
}
}
function create_plugin_settings_page() {
?>
<div class="wrap">
<h2><b>Sci</b>ence <b>Blog</b> Help<b>er</b></h2>
<form method="post" action="options.php">
<?php
settings_fields( self::OPTION_GROUP );
do_settings_sections( self::MENU_SLUG );
submit_button('Save', 'primary', 'submit', false);
?>
<input type="reset" name="reset" id="reset" class="button button-primary" value="Reset" style="margin:10px 0 0 10px;"/>
</form>
</div>
<?php
}
function init_plugin_settings_page() {
add_settings_section(
'option_section_main',
'',
array($this, 'section_callback_main'),
self::MENU_SLUG
);
add_settings_field(
self::OPTION_MODE,
'Configuration mode',
array( $this, 'setting_callback_mode'),
self::MENU_SLUG,
'option_section_main'
);
add_settings_section(
'option_section_mathjax',
'LaTeX Support',
array($this, 'section_callback_mathjax'),
self::MENU_SLUG
);
add_settings_field(
self::OPTION_MODE,
'MathJax engine',
array( $this, 'setting_callback_mathjax'),
self::MENU_SLUG,
'option_section_mathjax'
);
add_settings_section(
'option_section_outline',
'Outline Generation',
array($this, 'section_callback_outline'),
self::MENU_SLUG
);
add_settings_field(
self::OPTION_OUTLINE,
'Generate by default',
array( $this, 'setting_callback_outline'),
self::MENU_SLUG,
'option_section_outline'
);
register_setting( self::OPTION_GROUP, self::OPTION_MODE );
register_setting( self::OPTION_GROUP, self::OPTION_MATHJAX);
register_setting( self::OPTION_GROUP, self::OPTION_OUTLINE);
}
function section_callback_main() {
?>
<p>Intended to help people build blogs and write posts on science.</p>
<?php
}
function setting_callback_mode() {
?>
<input name="<?php echo self::OPTION_MODE ?>" type="radio" value="minimal"
<?php if(get_option( self::OPTION_MODE ) =='minimal') echo 'checked'; ?>
> Minimal</input><br />
<input name="<?php echo self::OPTION_MODE ?>" type="radio" value="maximal"
<?php if(get_option( self::OPTION_MODE ) =='maximal') echo 'checked'; ?>
> Maximal</input><br />
<p>For the greatest convenience, SciBloger follows "Convention over Configuration".
Least configs to make things rock are shown in "Minimal" mode.
To view and modify all settings, change to "Maximal" mode please.</p>
<p><b>Notice</b>: Setting modified in maximal mode will still have effects in minimal mode.</p>
<?php
}
function section_callback_mathjax() {
$this -> mMathJax -> insert_js_script();
?>
<p>This function is realised by importing copy of **MathJax**, an open source JavaScript display engine for mathematics that works in all browsers, from their CDN Service.
Following are two simple use cases:</p>
<ol>
<li><b>\<b></b>(...\<b></b>)</b> for in-line math: \( E = mc^2 \) and \( e^{\pi i} + 1 = 0 \)</li>
<li><b>\<b></b>[...\<b></b>]</b> or <b>$<b></b>$...$<b></b>$</b> for equations:
$$\mathbf{X} \sim \mathcal{N} (\boldsymbol\mu, \mathbf\Sigma) :
f_{\mathbf{X}}\left(x_1,...,x_k\right) =
\frac{1}{\sqrt{(2\pi)^k |\mathbf\Sigma|}} \:
\exp^{-\frac{1}{2}(\mathbf{x}-\boldsymbol\mu)^T \mathbf\Sigma^{-1} (\mathbf{x}-\boldsymbol\mu)}$$
</li>
</ol>
<p>For more help, please visit
MathJax <a href="http://www.mathjax.org/" target="_blank">Homepage</a>
or <a href="http://docs.mathjax.org/en/latest/" target="_blank">Documents</a>.</p>
<?php
}
function setting_callback_mathjax() {
?>
<input name="<?php echo self::OPTION_MATHJAX ?>" type="radio" value="on"
<?php if(get_option( self::OPTION_MATHJAX ) =='on') echo 'checked'; ?>
> On</input><br />
<input name="<?php echo self::OPTION_MATHJAX ?>" type="radio" value="off"
<?php if(get_option( self::OPTION_MATHJAX ) =='off') echo 'checked'; ?>
> Off</input><br />
<?php
}
function section_callback_outline() {
?>
<p>Posts on science usually are long works. SciBloger will help you generate a useful outline as long as headers were set properly: making h3 the top level in your post; h4s, h5s, h6s follows by order.
Shortcodes are also supported to use Outline more flexible by overwritting the defaults:</p>
<p style="text-align:center;">[scibloger_outline show="(yes/no, depends on your choose here)" right="10px" top="20%"]</p>
<?php
}
function setting_callback_outline() {
?>
<input name="<?php echo self::OPTION_OUTLINE ?>" type="radio" value="yes"
<?php if(get_option( self::OPTION_OUTLINE ) =='yes') echo 'checked'; ?>
> Yes</input><br />
<input name="<?php echo self::OPTION_OUTLINE ?>" type="radio" value="no"
<?php if(get_option( self::OPTION_OUTLINE ) =='no') echo 'checked'; ?>
> No</input><br />
<?php
}
}
// Start this plugin once all other plugins are fully loaded
add_action( 'init', 'ScienceBlogHelper');
function ScienceBlogHelper() {
global $ScienceBlogHelper;
$ScienceBlogHelper = new ScienceBlogHelper();
}
?>