This repository has been archived by the owner on Feb 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwp-plus.php
455 lines (420 loc) · 16.4 KB
/
wp-plus.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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
<?php
/*
Plugin Name: WP-Plus
Plugin URI: https://blog.lwl12.com/read/wp-plus.html
Description: 优化和增强您的博客
Author: liwanglin12
Author URI: https://lwl12.com
Version: 2.1.4
*/
/*Exit if accessed directly:安全第一,如果是直接载入,就退出.*/
defined('ABSPATH') or exit;
define("plus_version", "2.1.4");
/* 插件初始化*/
define('WP_PLUS_URL', plugin_dir_url(__FILE__));
register_activation_hook(__FILE__, 'plus_plugin_activate');
add_action('admin_init', 'plus_plugin_redirect');
function plus_plugin_redirect()
{
if (get_option('do_activation_redirect', false)) {
delete_option('do_activation_redirect');
wp_redirect(admin_url('options-general.php?page=wp_plus'));
}
}
/**
* [register_plugin_settings_link 添加插件控制面板链接]
*/
function plus_register_plugin_settings_link($links)
{
$settings_link = '<a href="options-general.php?page=wp_plus">设置</a>';
array_unshift($links, $settings_link);
return $links;
}
$plugin = plugin_basename(__FILE__);
add_filter("plugin_action_links_{$plugin}", 'plus_register_plugin_settings_link');
/* 注册控制面板*/
if (is_admin()) {
add_action('admin_menu', 'wp_plus_menu');
}
/**
* [wp_plus_menu 注册控制面板]
*/
function wp_plus_menu()
{
add_options_page('WP Plus 插件控制面板', 'WP Plus', 'administrator', 'wp_plus', 'plus_pluginoptions_page');
}
/* 插件设置核心部分*/
function plus_pluginoptions_page()
{
require "option.php";
}
/*加载进度*/
if (get_option('wp_plus_jdt') == 'checked') {
?><?php
function plus_wpn_enqueue()
{
wp_enqueue_style('nprogresss', WP_PLUS_URL . 'css/nprogress.css?ver=' . plus_version);
wp_enqueue_script('nprogress', WP_PLUS_URL . 'js/nprogress.js?ver=' . plus_version, array(
'jquery'
), '0.1.2', true);
wp_enqueue_script('wp-nprogress', WP_PLUS_URL . 'js/global.js?ver=' . plus_version, array(
'jquery',
'nprogress'
), '0.0.1', true);
}
add_action('wp_enqueue_scripts', 'plus_wpn_enqueue'); ?><?php
}
?><?php
if (get_option('wp_plus_glgjt') == 'checked') {
?><?php
show_admin_bar(false); ?><?php
}
?><?php
/*替换头像*/
if (get_option('wp_plus_gravatar') == 'checked') {
?><?php
function plus_sbsb_avatar($avatar)
{
$avatar = str_replace(array(
"www.gravatar.com/avatar/",
"0.gravatar.com/avatar/",
"1.gravatar.com/avatar/",
"2.gravatar.com/avatar/",
"secure.gravatar.com/avatar/"
), "gravatar.loli.net/avatar/", $avatar);
return $avatar;
}
add_filter('get_avatar', 'plus_sbsb_avatar', 10, 3);
add_filter('get_avatar_url', 'plus_sbsb_avatar', 10, 3);
?><?php
}
?><?php
/*微软雅黑*/
if (get_option('wp_plus_wryh') == 'checked') {
?><?php
function plus_admin_fonts()
{
echo '<style type="text/css"> * { font-family: "Microsoft YaHei" !important; } i, .ab-icon, .mce-close, i.mce-i-aligncenter, i.mce-i-alignjustify, i.mce-i-alignleft, i.mce-i-alignright, i.mce-i-blockquote, i.mce-i-bold, i.mce-i-bullist, i.mce-i-charmap, i.mce-i-forecolor, i.mce-i-fullscreen, i.mce-i-help, i.mce-i-hr, i.mce-i-indent, i.mce-i-italic, i.mce-i-link, i.mce-i-ltr, i.mce-i-numlist, i.mce-i-outdent, i.mce-i-pastetext, i.mce-i-pasteword, i.mce-i-redo, i.mce-i-removeformat, i.mce-i-spellchecker, i.mce-i-strikethrough, i.mce-i-underline, i.mce-i-undo, i.mce-i-unlink, i.mce-i-wp-media-library, i.mce-i-wp_adv, i.mce-i-wp_fullscreen, i.mce-i-wp_help, i.mce-i-wp_more, i.mce-i-wp_page, .qt-fullscreen, .star-rating .star { font-family: dashicons !important; } .mce-ico { font-family: tinymce, Arial !important; } .fa { font-family: FontAwesome !important; } .genericon { font-family: "Genericons" !important; } .appearance_page_scte-theme-editor #wpbody *, .ace_editor * { font-family: Monaco, Menlo, "Ubuntu Mono", Consolas, source-code-pro, monospace !important; } .post-type-post #advanced-sortables, .post-type-post #autopaging .description { display: none !important; } .form-field input, .form-field textarea { width: inherit; border-width: 0; } </style>';
}
add_action('admin_head', 'plus_admin_fonts'); ?><?php
}
?><?php
/*积分特效*/
if (get_option('wp_plus_number') == 'checked') {
?><?php
function wp_plus_jifentx()
{
echo '<script> jQuery(document).ready(function($) { $("html,body").click(function(e){ var n=Math.round(Math.random()*100); var $i=$("<b/>").text("+"+n); var x=e.pageX,y=e.pageY; $i.css({ "z-index":99999, "top":y-20, "left":x, "position":"absolute", "color":"#E94F06" }); $("body").append($i); $i.animate( {"top":y-180,"opacity":0}, 1500, function(){$i.remove();}); e.stopPropagation();});}); </script>';
}
add_action('wp_footer', 'wp_plus_jifentx');
}
?><?php
/*中文用户*/
if (get_option('wp_plus_chuser') == 'checked') {
?><?php
add_filter('sanitize_user', 'plus_chinese_user', 3, 3);
function plus_chinese_user($username, $raw_username, $strict)
{
$username = $raw_username;
$username = strip_tags($username);
$username = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '', $username);
$username = preg_replace('/&.+?;/', '', $username);
if ($strict) {
$username = preg_replace('|[^a-z0-9 _.\-@\x80-\xFF]|i', '', $username);
}
$username = preg_replace('|\s+|', ' ', $username);
return $username;
}
}
?><?php
if (get_option('wp_plus_ping') == 'checked') {
?><?php
/* 禁止站内文章PingBack */
function plus_no_self_ping(&$links)
{
$home = get_option('home');
foreach ($links as $l => $link) {
if (0 === strpos($link, $home)) {
unset($links[$l]);
}
}
}
add_action('pre_ping', 'plus_no_self_ping'); ?><?php
}
?><?php
if (get_option('wp_plus_nofollow') == 'checked') {
?><?php
/* 自动为博客内的连接添加nofollow属性并在新窗口打开链接 */
add_filter('the_content', 'plus_cn_nf_url_parse');
function plus_cn_nf_url_parse($content)
{
$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>";
if (preg_match_all("/$regexp/siU", $content, $matches, PREG_SET_ORDER)) {
if (!empty($matches)) {
$srcUrl = get_option('siteurl');
for ($i = 0; $i < count($matches); $i++) {
$tag = $matches[$i][0];
$tag2 = $matches[$i][0];
$url = $matches[$i][0];
$noFollow = '';
$pattern = '/target\s*=\s*"\s*_blank\s*"/';
preg_match($pattern, $tag2, $match, PREG_OFFSET_CAPTURE);
if (count($match) < 1) {
$noFollow .= ' target="_blank" ';
}
$pattern = '/rel\s*=\s*"\s*[n|d]ofollow\s*"/';
preg_match($pattern, $tag2, $match, PREG_OFFSET_CAPTURE);
if (count($match) < 1) {
$noFollow .= ' rel="nofollow" ';
}
$pos = strpos($url, $srcUrl);
if ($pos === false) {
$tag = rtrim($tag, '>');
$tag .= $noFollow . '>';
$content = str_replace($tag2, $tag, $content);
}
}
}
}
$content = str_replace(']]>', ']]>', $content);
return $content;
} ?><?php
}
?><?php
if (get_option('wp_plus_bingbg') == 'checked') {
?><?php
// 调用Bing美图作为登陆界面背景 //
function plus_bingbg()
{
$imgurl = 'https://api.i-meto.com/bing?new&blur';
echo '<style type="text/css">body{background: url(' . $imgurl . ');width:100%;height:100%;background-image:url(' . $imgurl . ');background-size: cover;-moz-border-image: url(' . $imgurl . ') 0;background-repeat:no-repeat\9;background-image:none\9;}</style>';
}
add_action('login_head', 'plus_bingbg'); ?><?php
}
?><?php
if (get_option('wp_plus_simplifyhead') == 'checked') {
?><?php
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'parent_post_rel_link', 10, 0);
remove_action('wp_head', 'start_post_rel_link', 10, 0);
remove_action('wp_head', 'wp_generator'); ?><?php
}
?><?php
if (get_option('wp_plus_replaceurl') == 'checked') {
?><?php
add_action('template_redirect', 'plus_relative_urls');
function plus_relative_urls()
{
if (is_feed() || get_query_var('sitemap')) {
return;
}
$filters = array(
'post_link',
'post_type_link',
'page_link',
'attachment_link',
'get_shortlink',
'post_type_archive_link',
'get_pagenum_link',
'get_comments_pagenum_link',
'term_link',
'search_link',
'day_link',
'month_link',
'year_link'
);
foreach ($filters as $filter) {
add_filter($filter, 'wp_make_link_relative');
}
} ?><?php
}
?><?php
if (get_option('wp_plus_welcomemsg') == 'checked') {
?><?php
require "welcomemsg.php";
function plus_welcomemsg()
{
$msg = welcome_msg();
if ($msg !== false) {
echo "<script>notie('$msg', {type:'info', autoHide:true, timeout: 5000,width:200})</script>";
}
}
add_action('wp_footer', 'plus_welcomemsg'); ?><?php
}
?><?php
if (get_option('wp_plus_ietip') == 'checked') {
?><?php
function plus_ietip()
{
echo '<!--[if lt IE 10]><script src="' . WP_PLUS_URL . 'js/iedie.min.js"></script><![endif]-->';
}
add_action('wp_head', 'plus_ietip'); ?><?php
}
?><?php
if (get_option('wp_plus_linkman') == 'checked') {
?><?php
add_filter('pre_option_link_manager_enabled', '__return_true'); ?><?php
}
?><?php
/*代码高亮*/
if (get_option('wp_plus_codehl') == 'checked') {
?><?php
function plus_add_prismjs()
{
wp_register_script('prismJS', WP_PLUS_URL . 'js/plus_prism.js?ver=' . plus_version);
wp_enqueue_script('prismJS');
}
function plus_add_prismcss()
{
wp_register_style('prismCSS', WP_PLUS_URL . 'css/plus_prism.css?ver=' . plus_version);
wp_enqueue_style('prismCSS');
}
class plusPrism
{
public function __construct()
{
add_filter('clean_url', array(
$this,
'add_async_forscript'
), 11, 1);
}
public function add_async_forscript($url)
{
if (strpos($url, 'plus_prism.js')===false) {
return $url;
} elseif (is_admin()) {
return $url;
} else {
return $url."' async='async";
}
}
}
new plusPrism;
add_action('wp_enqueue_scripts', 'plus_add_prismjs');
add_action('wp_head', 'plus_add_prismcss'); ?><?php
}
?><?php
/*替换JQ*/
if (get_option('wp_plus_jquery') == 'checked') {
?><?php
add_action('init', 'jquery_register');
function jquery_register()
{
if (!is_admin()) {
wp_deregister_script('jquery');
wp_register_script('jquery', 'https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js', false, null, true);
wp_enqueue_script('jquery');
}
} ?><?php
}
?><?php
/*版权提示*/
if (get_option('wp_plus_copyright') == 'checked') {
?><?php
function plus_copyright()
{
echo '<script>function plus_copyright(){document.body.addEventListener("copy", function (e) { if (window.getSelection().toString().length > '. get_option("wp_plus_copyright_num") .') { setClipboardText(e); notie("商业转载请联系作者获得授权,非商业转载请注明出处", {type:"error", autoHide:true, timeout: 5000,width:200}); } }); function setClipboardText(event) { event.preventDefault(); var htmlData = "" + "著作权归作者所有。<br>" + "商业转载请联系作者获得授权,非商业转载请注明出处。<br>" + "作者:' . get_the_author() . '<br>" + "链接:" + window.location.href + "<br>" + "来源:' . get_bloginfo('name') . '<br><br>" + window.getSelection().toString(); var textData = "" + "著作权归作者所有。\n" + "商业转载请联系作者获得授权,非商业转载请注明出处。\n" + "作者:' . get_the_author() . '\n" + "链接:" + window.location.href + "\n" + "来源:' . get_bloginfo('name') . '\n\n" + window.getSelection().toString(); if (event.clipboardData) { event.clipboardData.setData("text/html", htmlData); event.clipboardData.setData("text/plain",textData); } else if (window.clipboardData) { return window.clipboardData.setData("text", textData); } }}</script>';
if (is_single()) {
echo '<script>plus_copyright();</script>';
}
}
add_action('wp_footer', 'plus_copyright'); ?><?php
}
?><?php
/*久远文章提示*/
if (get_option('wp_plus_oldpost') == 'checked') {
?><?php
function plus_oldpost($content)
{
if (is_single()) {
$time = time() - get_the_modified_date('U');
if ($time > get_option("wp_plus_oldpost_num") * 86400) {
return $content . "<script>window.plus_oldpost = function(){notie('此文章最后修订于 ". floor($time / 86400) ." 天前,其中的信息可能已经有所发展或是发生改变', {type:'warning', autoHide:true, timeout: 5000,width:200});};plus_oldpost();</script>";
}
}
return $content;
}
add_filter('the_content', 'plus_oldpost'); ?><?php
}
?><?php
/*禁用emoji*/
if (get_option('wp_plus_disable_emoji') == 'checked') {
?><?php
/**
* 禁用emoji
*/
function disable_emoji()
{
remove_filter('comment_text_rss', 'wp_staticize_emoji');
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_filter('the_content_feed', 'wp_staticize_emoji');
remove_action('admin_print_scripts', 'print_emoji_detection_script');
remove_action('admin_print_styles', 'print_emoji_styles');
remove_action('wp_print_styles', 'print_emoji_styles');
remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
add_filter('tiny_mce_plugins', 'disable_emoji_tinymce');
}
add_action('init', 'disable_emoji');
function disable_emoji_tinymce($plugins)
{
if (is_array($plugins)) {
return array_diff($plugins, array( 'wpemoji' ));
} else {
return array();
}
} ?><?php
}
?><?php
/*版本控制忽略*/
if (get_option('wp_plus_ignore_git') == 'checked') {
?><?php
add_filter('automatic_updates_is_vcs_checkout', '__return_false'); ?><?php
}
?><?php
if (get_option('wp_plus_disable_attachment_page') == 'checked') {
?><?php
function wp_plus_disable_attachment_page() {
if ( is_attachment() ) {
global $wp_query;
$wp_query->set_404();
status_header( 404 );
get_template_part( 404 );
exit;
}
}
add_action( 'template_redirect', 'wp_plus_disable_attachment_page' );
}
?><?php
/**
* Description: 解决 WordPress 简体中文版每次加载后台都会产生好多条非必要 SQL 请求的情况,实质上是在 admin_init 钩子上移除了 wp-content/languages/zh_CN.php 本地化文件中清理旧版选项的函数,改为只在 WordPress 升级数据库时执行。
* Version: 1.0
*
* Author: 斌果
* Author URI: https://www.bgbk.org
*/
if (get_option('wp_plus_remove_zh_cn_legacy_option_clean') == 'checked') {
?><?php
function Bing_remove_zh_cn_legacy_option_clean()
{
if (remove_action('admin_init', 'zh_cn_l10n_legacy_option_cleanup')) {
add_action('wp_upgrade', 'zh_cn_l10n_legacy_option_cleanup');
}
}
add_action('init', 'Bing_remove_zh_cn_legacy_option_clean'); ?><?php
}
?><?php
function plus_add_async_attribute($tag, $handle) {
if ( 'notieJS' !== $handle ) return $tag;
return str_replace( ' src', ' async integrity="sha384-vO46R/Kxmvgbjw4biqvRvhYvWKUgTip1VUIPDKlCIFnuP5aUYvdLQ8aVtS9L3ZO/" crossorigin="anonymous" src', $tag );
}
function plus_loadalert()
{
if (get_option('wp_plus_welcomemsg') == 'checked' || get_option('wp_plus_copyright') == 'checked' || get_option('wp_plus_oldpost') == 'checked') {
wp_register_script('notieJS', 'https://cdn.jsdelivr.net/npm/[email protected]/browser/notie.js');
wp_enqueue_script('notieJS');
add_filter('script_loader_tag', 'plus_add_async_attribute', 10, 2);
}
}
add_action('wp_enqueue_scripts', 'plus_loadalert');