mirror of
https://github.com/yunluo/gdk.git
synced 2024-06-16 12:35:08 +02:00
持续丰富内容
This commit is contained in:
parent
7f462f8791
commit
47257c804c
0
class/cache/index.html
vendored
Normal file
0
class/cache/index.html
vendored
Normal file
0
class/cache/timthumb_cacheLastCleanTime.touch
vendored
Normal file
0
class/cache/timthumb_cacheLastCleanTime.touch
vendored
Normal file
|
@ -1,14 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
/*本文件是主题缩略图产生文件*/
|
/*本文件是主题缩略图产生文件*/
|
||||||
define ('VERSION', '2.8.13');
|
define ('TIM_VERSION', '2.8.13');
|
||||||
if( file_exists(dirname(__FILE__) . '/timthumb-config.php')) require_once('timthumb-config.php');
|
if( file_exists(dirname(__FILE__) . '/timthumb-config.php')) require_once('timthumb-config.php');
|
||||||
|
if( file_exists(dirname(__FILE__) . '/../../../timthumb-config.php')) require_once('../../../timthumb-config.php');//timthumb-config.php文件被定义在wp-content 目录下
|
||||||
if(! defined('DEBUG_ON') ) define ('DEBUG_ON', false);
|
if(! defined('DEBUG_ON') ) define ('DEBUG_ON', false);
|
||||||
if(! defined('DEBUG_LEVEL') ) define ('DEBUG_LEVEL', 1);
|
if(! defined('DEBUG_LEVEL') ) define ('DEBUG_LEVEL', 1);
|
||||||
if(! defined('MEMORY_LIMIT') ) define ('MEMORY_LIMIT', '30M');
|
if(! defined('MEMORY_LIMIT') ) define ('MEMORY_LIMIT', '30M');
|
||||||
if(! defined('BLOCK_EXTERNAL_LEECHERS') ) define ('BLOCK_EXTERNAL_LEECHERS', false);
|
if(! defined('BLOCK_EXTERNAL_LEECHERS') ) define ('BLOCK_EXTERNAL_LEECHERS', false);
|
||||||
if(! defined('DISPLAY_ERROR_MESSAGES') ) define ('DISPLAY_ERROR_MESSAGES', true);
|
if(! defined('DISPLAY_ERROR_MESSAGES') ) define ('DISPLAY_ERROR_MESSAGES', true);
|
||||||
if(! defined('ALLOW_EXTERNAL') ) define ('ALLOW_EXTERNAL', TRUE);
|
if(! defined('ALLOW_EXTERNAL') ) define ('ALLOW_EXTERNAL', TRUE);
|
||||||
if(! defined('ALLOW_ALL_EXTERNAL_SITES') ) define ('ALLOW_ALL_EXTERNAL_SITES', true);
|
if(! defined('ALLOW_ALL_EXTERNAL_SITES') ) define ('ALLOW_ALL_EXTERNAL_SITES', false);
|
||||||
//上面这行,改成true则是允许所有外链,为了解决缩略图问题,默认为开启,如果你懂这个,你也可以关闭
|
//上面这行,改成true则是允许所有外链,为了解决缩略图问题,默认为开启,如果你懂这个,你也可以关闭
|
||||||
if(! defined('FILE_CACHE_ENABLED') ) define ('FILE_CACHE_ENABLED', TRUE);
|
if(! defined('FILE_CACHE_ENABLED') ) define ('FILE_CACHE_ENABLED', TRUE);
|
||||||
if(! defined('FILE_CACHE_TIME_BETWEEN_CLEANS')) define ('FILE_CACHE_TIME_BETWEEN_CLEANS', 86400);
|
if(! defined('FILE_CACHE_TIME_BETWEEN_CLEANS')) define ('FILE_CACHE_TIME_BETWEEN_CLEANS', 86400);
|
||||||
|
@ -19,8 +20,7 @@ if(! defined('FILE_CACHE_DIRECTORY') ) define ('FILE_CACHE_DIRECTORY', './cach
|
||||||
if(! defined('MAX_FILE_SIZE') ) define ('MAX_FILE_SIZE', 10485760);
|
if(! defined('MAX_FILE_SIZE') ) define ('MAX_FILE_SIZE', 10485760);
|
||||||
if(! defined('CURL_TIMEOUT') ) define ('CURL_TIMEOUT', 20);
|
if(! defined('CURL_TIMEOUT') ) define ('CURL_TIMEOUT', 20);
|
||||||
if(! defined('WAIT_BETWEEN_FETCH_ERRORS') ) define ('WAIT_BETWEEN_FETCH_ERRORS', 3600);
|
if(! defined('WAIT_BETWEEN_FETCH_ERRORS') ) define ('WAIT_BETWEEN_FETCH_ERRORS', 3600);
|
||||||
//Browser caching
|
if(! defined('BROWSER_CACHE_MAX_AGE') ) define ('BROWSER_CACHE_MAX_AGE', 864000);//Browser caching
|
||||||
if(! defined('BROWSER_CACHE_MAX_AGE') ) define ('BROWSER_CACHE_MAX_AGE', 864000);
|
|
||||||
if(! defined('BROWSER_CACHE_DISABLE') ) define ('BROWSER_CACHE_DISABLE', false);
|
if(! defined('BROWSER_CACHE_DISABLE') ) define ('BROWSER_CACHE_DISABLE', false);
|
||||||
if(! defined('MAX_WIDTH') ) define ('MAX_WIDTH', 1500);
|
if(! defined('MAX_WIDTH') ) define ('MAX_WIDTH', 1500);
|
||||||
if(! defined('MAX_HEIGHT') ) define ('MAX_HEIGHT', 1500);
|
if(! defined('MAX_HEIGHT') ) define ('MAX_HEIGHT', 1500);
|
||||||
|
@ -34,40 +34,29 @@ if(! defined('DEFAULT_S') ) define ('DEFAULT_S', 0);
|
||||||
if(! defined('DEFAULT_CC') ) define ('DEFAULT_CC', 'ffffff');
|
if(! defined('DEFAULT_CC') ) define ('DEFAULT_CC', 'ffffff');
|
||||||
if(! defined('DEFAULT_WIDTH') ) define ('DEFAULT_WIDTH', 100);
|
if(! defined('DEFAULT_WIDTH') ) define ('DEFAULT_WIDTH', 100);
|
||||||
if(! defined('DEFAULT_HEIGHT') ) define ('DEFAULT_HEIGHT', 100);
|
if(! defined('DEFAULT_HEIGHT') ) define ('DEFAULT_HEIGHT', 100);
|
||||||
if(! defined('OPTIPNG_ENABLED') ) define ('OPTIPNG_ENABLED', false);
|
if(! defined('OPTIPNG_ENABLED') ) define ('OPTIPNG_ENABLED', false);
|
||||||
if(! defined('OPTIPNG_PATH') ) define ('OPTIPNG_PATH', '/usr/bin/optipng');
|
if(! defined('OPTIPNG_PATH') ) define ('OPTIPNG_PATH', '/usr/bin/optipng');
|
||||||
if(! defined('PNGCRUSH_ENABLED') ) define ('PNGCRUSH_ENABLED', false);
|
if(! defined('PNGCRUSH_ENABLED') ) define ('PNGCRUSH_ENABLED', false);
|
||||||
if(! defined('PNGCRUSH_PATH') ) define ('PNGCRUSH_PATH', '/usr/bin/pngcrush');
|
if(! defined('PNGCRUSH_PATH') ) define ('PNGCRUSH_PATH', '/usr/bin/pngcrush');
|
||||||
if(! defined('WEBSHOT_ENABLED') ) define ('WEBSHOT_ENABLED', false);
|
if(! defined('WEBSHOT_ENABLED') ) define ('WEBSHOT_ENABLED', false);
|
||||||
if(! defined('WEBSHOT_CUTYCAPT') ) define ('WEBSHOT_CUTYCAPT', '/usr/local/bin/CutyCapt');
|
if(! defined('WEBSHOT_CUTYCAPT') ) define ('WEBSHOT_CUTYCAPT', '/usr/local/bin/CutyCapt');
|
||||||
if(! defined('WEBSHOT_XVFB') ) define ('WEBSHOT_XVFB', '/usr/bin/xvfb-run');
|
if(! defined('WEBSHOT_XVFB') ) define ('WEBSHOT_XVFB', '/usr/bin/xvfb-run');
|
||||||
if(! defined('WEBSHOT_SCREEN_X') ) define ('WEBSHOT_SCREEN_X', '1024'); //1024 works ok
|
if(! defined('WEBSHOT_SCREEN_X') ) define ('WEBSHOT_SCREEN_X', '1024'); //1024 works ok
|
||||||
if(! defined('WEBSHOT_SCREEN_Y') ) define ('WEBSHOT_SCREEN_Y', '768'); //768 works ok
|
if(! defined('WEBSHOT_SCREEN_Y') ) define ('WEBSHOT_SCREEN_Y', '768'); //768 works ok
|
||||||
if(! defined('WEBSHOT_COLOR_DEPTH') ) define ('WEBSHOT_COLOR_DEPTH', '24');
|
if(! defined('WEBSHOT_COLOR_DEPTH') ) define ('WEBSHOT_COLOR_DEPTH', '24');
|
||||||
if(! defined('WEBSHOT_IMAGE_FORMAT') ) define ('WEBSHOT_IMAGE_FORMAT', 'png');
|
if(! defined('WEBSHOT_IMAGE_FORMAT') ) define ('WEBSHOT_IMAGE_FORMAT', 'png');
|
||||||
if(! defined('WEBSHOT_TIMEOUT') ) define ('WEBSHOT_TIMEOUT', '20');
|
if(! defined('WEBSHOT_TIMEOUT') ) define ('WEBSHOT_TIMEOUT', '20');
|
||||||
if(! defined('WEBSHOT_USER_AGENT') ) define ('WEBSHOT_USER_AGENT', "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.18) Gecko/20110614 Firefox/3.6.18");
|
if(! defined('WEBSHOT_USER_AGENT') ) define ('WEBSHOT_USER_AGENT', "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.18) Gecko/20110614 Firefox/64.6.18");
|
||||||
if(! defined('WEBSHOT_JAVASCRIPT_ON') ) define ('WEBSHOT_JAVASCRIPT_ON', true);
|
if(! defined('WEBSHOT_JAVASCRIPT_ON') ) define ('WEBSHOT_JAVASCRIPT_ON', true);
|
||||||
if(! defined('WEBSHOT_JAVA_ON') ) define ('WEBSHOT_JAVA_ON', false);
|
if(! defined('WEBSHOT_JAVA_ON') ) define ('WEBSHOT_JAVA_ON', false);
|
||||||
if(! defined('WEBSHOT_PLUGINS_ON') ) define ('WEBSHOT_PLUGINS_ON', true);
|
if(! defined('WEBSHOT_PLUGINS_ON') ) define ('WEBSHOT_PLUGINS_ON', true);
|
||||||
if(! defined('WEBSHOT_PROXY') ) define ('WEBSHOT_PROXY', '');
|
if(! defined('WEBSHOT_PROXY') ) define ('WEBSHOT_PROXY', '');
|
||||||
if(! defined('WEBSHOT_XVFB_RUNNING') ) define ('WEBSHOT_XVFB_RUNNING', false);
|
if(! defined('WEBSHOT_XVFB_RUNNING') ) define ('WEBSHOT_XVFB_RUNNING', false);
|
||||||
if(! isset($ALLOWED_SITES)){
|
if(! isset($ALLOWED_SITES)){
|
||||||
//下面输入您的外链图片域名
|
//下面输入您的外链图片域名
|
||||||
$ALLOWED_SITES = array (
|
$ALLOWED_SITES = array (
|
||||||
'image.baidu.com',
|
'image.baidu.com',
|
||||||
'images.yusi123.com',
|
'clouddn.com'
|
||||||
'clouddn.com',
|
|
||||||
'tietuku.com',
|
|
||||||
'qiniudn.com',
|
|
||||||
'tinypic.com',
|
|
||||||
'neowing.co.jp',
|
|
||||||
'img.moe-acg.us',
|
|
||||||
'img.kan300.com',
|
|
||||||
'sinaimg.cn',
|
|
||||||
'wal8.com',
|
|
||||||
'poco.cn',
|
|
||||||
'upyun.com'
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
/*后面止步*/
|
/*后面止步*/
|
||||||
|
@ -355,7 +344,8 @@ class timthumb {
|
||||||
$html .= '</ul>';
|
$html .= '</ul>';
|
||||||
echo '<h1>A TimThumb error has occured</h1>The following error(s) occured:<br />' . $html . '<br />';
|
echo '<h1>A TimThumb error has occured</h1>The following error(s) occured:<br />' . $html . '<br />';
|
||||||
echo '<br />Query String : ' . htmlentities( $_SERVER['QUERY_STRING'], ENT_QUOTES );
|
echo '<br />Query String : ' . htmlentities( $_SERVER['QUERY_STRING'], ENT_QUOTES );
|
||||||
echo '<br />TimThumb version : ' . VERSION . '</pre>';
|
echo '<br />TimThumb version : ' . TIM_VERSION . '</pre>';
|
||||||
|
|
||||||
}
|
}
|
||||||
protected function serveInternalImage(){
|
protected function serveInternalImage(){
|
||||||
$this->debug(3, "Local image path is $this->localImage");
|
$this->debug(3, "Local image path is $this->localImage");
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -17,9 +17,9 @@ function gdk_update_options() {
|
||||||
global $gdk_default_options, $gdk_options, $gdk_current_options;
|
global $gdk_default_options, $gdk_options, $gdk_current_options;
|
||||||
foreach ($gdk_options as $panel) {
|
foreach ($gdk_options as $panel) {
|
||||||
foreach ($panel as $option) {
|
foreach ($panel as $option) {
|
||||||
$id = isset( $option['id'] ) ? $option['id'] : '';
|
$id = $option['id'] ?? '';
|
||||||
$type = isset( $option['type'] ) ? $option['type'] : '';
|
$type = $option['type'] ?? '';
|
||||||
$std = isset( $option['std'] ) ? $option['std'] : '';
|
$std = $option['std'] ?? '';
|
||||||
if ( !$id ) continue;
|
if ( !$id ) continue;
|
||||||
$gdk_default_options[$id] = $std;
|
$gdk_default_options[$id] = $std;
|
||||||
if ( isset($gdk_current_options[$id]) ) continue;
|
if ( isset($gdk_current_options[$id]) ) continue;
|
||||||
|
@ -67,7 +67,7 @@ foreach ( array_keys($gdk_options) as $i => $name ) {
|
||||||
<?php
|
<?php
|
||||||
$index = 0;
|
$index = 0;
|
||||||
foreach ( $gdk_options as $panel ) {
|
foreach ( $gdk_options as $panel ) {
|
||||||
echo '<div class="panel" id="panel_' . $index . '" ' . ( $index == $activePanelIdx ? ' style="display:block"' : '' ) . '><table class="form-table">';
|
echo '<div class="panel gdk_option" id="panel_' . $index . '" ' . ( $index == $activePanelIdx ? ' style="display:block"' : '' ) . '><table class="form-table">';
|
||||||
foreach ( $panel as $option ) {
|
foreach ( $panel as $option ) {
|
||||||
$type = $option['type'];
|
$type = $option['type'];
|
||||||
if ( $type == 'title' ) {
|
if ( $type == 'title' ) {
|
||||||
|
@ -248,6 +248,13 @@ switch ( $type ) {
|
||||||
border-bottom: 4px solid #6b48ff;
|
border-bottom: 4px solid #6b48ff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.gdk_option input[type=radio]:checked::before {
|
||||||
|
background-color: #6b48ff;
|
||||||
|
}
|
||||||
|
.gdk_option input[type=radio]:focus {
|
||||||
|
box-shadow: 0 0 0 1px #6b48ff;
|
||||||
|
}
|
||||||
|
|
||||||
.wp-filter .drawer-toggle:before {
|
.wp-filter .drawer-toggle:before {
|
||||||
content: "\f463";
|
content: "\f463";
|
||||||
color: #fff!important;
|
color: #fff!important;
|
||||||
|
|
|
@ -28,9 +28,9 @@ add_action( 'wp', 'gdk_prevent_script_injection' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(gdk_get_option('gdk_lock_login')){
|
||||||
if ( ! class_exists( 'Gdk_Limit_Login_Attempts' ) ) {
|
if ( ! class_exists( 'GDK_Limit_Login_Attempts' ) ) {
|
||||||
class Gdk_Limit_Login_Attempts {
|
class GDK_Limit_Login_Attempts {
|
||||||
var $failed_login_limit = 3;
|
var $failed_login_limit = 3;
|
||||||
//登录失败的次数限制
|
//登录失败的次数限制
|
||||||
var $lockout_duration = 60;
|
var $lockout_duration = 60;
|
||||||
|
@ -44,8 +44,8 @@ add_action( 'wp', 'gdk_prevent_script_injection' );
|
||||||
add_action( 'wp_login_failed', array( $this, 'login_failed' ), 10, 1 );
|
add_action( 'wp_login_failed', array( $this, 'login_failed' ), 10, 1 );
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Lock login attempts of failed login limit is reached
|
* Lock login attempts of failed login limit is reached
|
||||||
*/
|
*/
|
||||||
public function check_attempted_login( $user, $username, $password ) {
|
public function check_attempted_login( $user, $username, $password ) {
|
||||||
if ( get_transient( $this->transient_name ) ) {
|
if ( get_transient( $this->transient_name ) ) {
|
||||||
$datas = get_transient( $this->transient_name );
|
$datas = get_transient( $this->transient_name );
|
||||||
|
@ -53,35 +53,33 @@ add_action( 'wp', 'gdk_prevent_script_injection' );
|
||||||
$until = get_option( '_transient_timeout_' . $this->transient_name );
|
$until = get_option( '_transient_timeout_' . $this->transient_name );
|
||||||
$time = $this->when( $until );
|
$time = $this->when( $until );
|
||||||
//Display error message to the user when limit is reached
|
//Display error message to the user when limit is reached
|
||||||
return new WP_Error( 'too_many_tried', sprintf( esc_attr( 'ERROR: 您已达到登陆错误次数,请在 %1$s 后再次尝试登陆.' ) , $time ) );
|
return new WP_Error( 'too_many_tried', sprintf( esc_attr( 'ERROR:您已触发登陆安全保护,请在 %1$s 后再次尝试.' ) , $time ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Add transient
|
* Add transient
|
||||||
*/
|
*/
|
||||||
public function login_failed( $username ) {
|
public function login_failed( $username ) {
|
||||||
if ( get_transient( $this->transient_name ) ) {
|
if ( get_transient( $this->transient_name ) ) {
|
||||||
$datas = get_transient( $this->transient_name );
|
$datas = get_transient( $this->transient_name );
|
||||||
$datas['tried']++;
|
$datas['tried']++;
|
||||||
if ( $datas['tried'] <= $this->failed_login_limit )
|
if ( $datas['tried'] <= $this->failed_login_limit )
|
||||||
set_transient( $this->transient_name, $datas , $this->lockout_duration );
|
set_transient( $this->transient_name, $datas , $this->lockout_duration );
|
||||||
} else {
|
} else {
|
||||||
$datas = array(
|
$datas = array('tried' => 1 );
|
||||||
'tried' => 1
|
|
||||||
);
|
|
||||||
set_transient( $this->transient_name, $datas , $this->lockout_duration );
|
set_transient( $this->transient_name, $datas , $this->lockout_duration );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Return difference between 2 given dates
|
* Return difference between 2 given dates
|
||||||
* @param int $time Date as Unix timestamp
|
* @param int $time Date as Unix timestamp
|
||||||
* @return string Return string
|
* @return string Return string
|
||||||
*/
|
*/
|
||||||
private function when( $time ) {
|
private function when( $time ) {
|
||||||
if ( ! $time )
|
if ( ! $time )
|
||||||
return;
|
return;
|
||||||
$right_now = time();
|
$right_now = time();
|
||||||
$diff = abs( $right_now - $time );
|
$diff = abs( $right_now - $time );
|
||||||
$second = 1;
|
$second = 1;
|
||||||
|
@ -89,20 +87,20 @@ add_action( 'wp', 'gdk_prevent_script_injection' );
|
||||||
$hour = $minute * 60;
|
$hour = $minute * 60;
|
||||||
$day = $hour * 24;
|
$day = $hour * 24;
|
||||||
if ( $diff < $minute )
|
if ( $diff < $minute )
|
||||||
return floor( $diff / $second ) . ' ' . esc_attr( '秒' );
|
return floor( $diff / $second ) . ' ' . esc_attr( '秒' );
|
||||||
if ( $diff < $minute * 2 )
|
if ( $diff < $minute * 2 )
|
||||||
return esc_attr( 'about 1 minute ago' );
|
return esc_attr( 'about 1 minute ago' );
|
||||||
if ( $diff < $hour )
|
if ( $diff < $hour )
|
||||||
return floor( $diff / $minute ) . ' ' . esc_attr( '分' );
|
return floor( $diff / $minute ) . ' ' . esc_attr( '分' );
|
||||||
if ( $diff < $hour * 2 )
|
if ( $diff < $hour * 2 )
|
||||||
return esc_attr( 'about 1 hour');
|
return esc_attr( 'about 1 hour');
|
||||||
return floor( $diff / $hour ) . ' ' . esc_attr( '小时' );
|
return floor( $diff / $hour ) . ' ' . esc_attr( '小时' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Enable it:
|
//Enable it:
|
||||||
new Gdk_Limit_Login_Attempts();
|
new GDK_Limit_Login_Attempts();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//禁用登陆错误信息
|
//禁用登陆错误信息
|
||||||
|
@ -119,36 +117,7 @@ add_filter( 'login_errors', 'gdk_disable_login_errors' );
|
||||||
|
|
||||||
|
|
||||||
//禁用找回密码
|
//禁用找回密码
|
||||||
class Gdk_Password_Reset_Removed
|
add_filter('allow_password_reset', '__return_false' );
|
||||||
{
|
|
||||||
function __construct() {
|
|
||||||
add_filter( 'show_password_fields', array( $this, 'disable' ) );
|
|
||||||
add_filter( 'allow_password_reset', array( $this, 'disable' ) );
|
|
||||||
add_filter( 'gettext', array( $this, 'remove' ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
function disable() {
|
|
||||||
if ( is_admin() ) {
|
|
||||||
$user_id = get_current_user_id();
|
|
||||||
$user = get_user_by('id' , $user_id );
|
|
||||||
if ( !empty( $user->roles ) && is_array( $user->roles ) && $user->roles[0] == 'administrator' )
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function remove( $translated_text, $untranslated_text ) {
|
|
||||||
if ( is_login() && in_string($untranslated_text,'Lost your password?') ){
|
|
||||||
return str_replace('Lost your password?','',$untranslated_text);
|
|
||||||
}else{
|
|
||||||
return $translated_text;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
new Gdk_Password_Reset_Removed();
|
|
||||||
|
|
||||||
//拦截无来路的评论
|
//拦截无来路的评论
|
||||||
add_action('check_comment_flood', 'gdk_comment_check_referrer');
|
add_action('check_comment_flood', 'gdk_comment_check_referrer');
|
||||||
|
@ -157,3 +126,25 @@ add_action('check_comment_flood', 'gdk_comment_check_referrer');
|
||||||
wp_die( esc_attr( 'Please enable referrers in your browser!' ) );
|
wp_die( esc_attr( 'Please enable referrers in your browser!' ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//拦截垃圾评论
|
||||||
|
function gdk_url_spamcheck($approved, $commentdata) {
|
||||||
|
return (strlen($commentdata['comment_author_url']) > 50) ? 'spam' : $approved;
|
||||||
|
}
|
||||||
|
add_filter('pre_comment_approved', 'gdk_url_spamcheck', 99, 2);
|
||||||
|
|
||||||
|
function gdk_comment_lang($incoming_comment) {
|
||||||
|
$pattern = '/[一-龥]/u';
|
||||||
|
// 禁止全英文评论
|
||||||
|
if (!preg_match($pattern, $incoming_comment['comment_content'])) {
|
||||||
|
wp_die("您的评论中必须包含汉字!");
|
||||||
|
}
|
||||||
|
$pattern = '/[あ-んア-ン]/u';
|
||||||
|
// 禁止日文评论
|
||||||
|
if (preg_match($pattern, $incoming_comment['comment_content'])) {
|
||||||
|
wp_die("评论禁止包含日文!");
|
||||||
|
}
|
||||||
|
return($incoming_comment);
|
||||||
|
}
|
||||||
|
add_filter('preprocess_comment', 'gdk_comment_lang');
|
|
@ -1,128 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
//新文章同步到新浪微博
|
|
||||||
function post_to_sina_weibo($post_ID) {
|
|
||||||
if (get_post_meta($post_ID, 'git_weibo_sync', true) == 1) return;
|
|
||||||
$get_post_info = get_post($post_ID);
|
|
||||||
$get_post_centent = get_post($post_ID)->post_content;
|
|
||||||
$get_post_title = get_post($post_ID)->post_title;
|
|
||||||
if ($get_post_info->post_status == 'publish' && $_POST['original_post_status'] != 'publish') {
|
|
||||||
$appkey = git_get_option('git_wbapky_b');
|
|
||||||
$username = git_get_option('git_wbuser_b');
|
|
||||||
$userpassword = git_get_option('git_wbpasd_b');
|
|
||||||
$request = new WP_Http;
|
|
||||||
$keywords = "";
|
|
||||||
$tags = wp_get_post_tags($post_ID);
|
|
||||||
foreach ($tags as $tag) {
|
|
||||||
$keywords = $keywords . '#' . $tag->name . "#";
|
|
||||||
}
|
|
||||||
$string1 = '【' . strip_tags($get_post_title) . '】:';
|
|
||||||
$string2 = $keywords . ' [阅读全文]:' . get_permalink($post_ID);
|
|
||||||
/* 微博字数控制,避免超标同步失败 */
|
|
||||||
$wb_num = (138 - WeiboLength($string1 . $string2)) * 2;
|
|
||||||
$status = $string1 . mb_strimwidth(strip_tags(apply_filters('the_content', $get_post_centent)) , 0, $wb_num, '...') . $string2;
|
|
||||||
$api_url = 'https://api.weibo.com/2/statuses/update.json';
|
|
||||||
$body = array(
|
|
||||||
'status' => $status,
|
|
||||||
'source' => $appkey
|
|
||||||
);
|
|
||||||
$headers = array(
|
|
||||||
'Authorization' => 'Basic ' . base64_encode("$username:$userpassword")
|
|
||||||
);
|
|
||||||
$result = $request->post($api_url, array(
|
|
||||||
'body' => $body,
|
|
||||||
'headers' => $headers
|
|
||||||
));
|
|
||||||
/* 若同步成功,则给新增自定义栏目git_weibo_sync,避免以后更新文章重复同步 */
|
|
||||||
add_post_meta($post_ID, 'git_weibo_sync', 1, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (git_get_option('git_sinasync_b')) {
|
|
||||||
add_action('publish_post', 'post_to_sina_weibo', 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
//获取微博字符长度函数
|
|
||||||
*/
|
|
||||||
function WeiboLength($str) {
|
|
||||||
$arr = arr_split_zh($str); //先将字符串分割到数组中
|
|
||||||
foreach ($arr as $v) {
|
|
||||||
$temp = ord($v); //转换为ASCII码
|
|
||||||
if ($temp > 0 && $temp < 127) {
|
|
||||||
$len = $len + 0.5;
|
|
||||||
} else {
|
|
||||||
$len++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ceil($len); //加一取整
|
|
||||||
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
//拆分字符串函数,只支持 gb2312编码
|
|
||||||
//参考:http://u-czh.iteye.com/blog/1565858
|
|
||||||
*/
|
|
||||||
function arr_split_zh($tempaddtext) {
|
|
||||||
$tempaddtext = iconv("UTF-8", "GBK//IGNORE", $tempaddtext);
|
|
||||||
$cind = 0;
|
|
||||||
$arr_cont = array();
|
|
||||||
for ($i = 0; $i < strlen($tempaddtext); $i++) {
|
|
||||||
if (strlen(substr($tempaddtext, $cind, 1)) > 0) {
|
|
||||||
if (ord(substr($tempaddtext, $cind, 1)) < 0xA1) { //如果为英文则取1个字节
|
|
||||||
array_push($arr_cont, substr($tempaddtext, $cind, 1));
|
|
||||||
$cind++;
|
|
||||||
} else {
|
|
||||||
array_push($arr_cont, substr($tempaddtext, $cind, 2));
|
|
||||||
$cind+= 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach ($arr_cont as & $row) {
|
|
||||||
$row = iconv("gb2312", "UTF-8", $row);
|
|
||||||
}
|
|
||||||
return $arr_cont;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//百度收录提示
|
|
||||||
if (git_get_option('git_baidurecord_b') && function_exists('curl_init')) {
|
|
||||||
function baidu_check($url, $post_id){
|
|
||||||
$baidu_record = get_post_meta($post_id, 'baidu_record', true);
|
|
||||||
if ($baidu_record != 1) {
|
|
||||||
$url = 'http://www.baidu.com/s?wd=' . $url;
|
|
||||||
$curl = curl_init();
|
|
||||||
curl_setopt($curl, CURLOPT_URL, $url);
|
|
||||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
||||||
$rs = curl_exec($curl);
|
|
||||||
curl_close($curl);
|
|
||||||
if (!strpos($rs, '没有找到该URL,您可以直接访问') && !strpos($rs, '很抱歉,没有找到与')) {
|
|
||||||
update_post_meta($post_id, 'baidu_record', 1) || add_post_meta($post_id, 'baidu_record', 1, true);
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function baidu_record(){
|
|
||||||
global $wpdb;
|
|
||||||
$post_id = null === $post_id ? get_the_ID() : $post_id;
|
|
||||||
if (baidu_check(get_permalink($post_id), $post_id) == 1) {
|
|
||||||
echo '<a target="_blank" title="点击查看" rel="external nofollow" href="http://www.baidu.com/s?wd=' . get_the_title() . '">已收录</a>';
|
|
||||||
} else {
|
|
||||||
echo '<a style="color:red;" rel="external nofollow" title="点击提交,谢谢您!" target="_blank" href="http://zhanzhang.baidu.com/sitesubmit/index?sitename=' . get_permalink() . '">未收录</a>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//七牛CDN
|
//七牛CDN
|
||||||
if (!is_admin() && git_get_option('git_qncdn_b')) {
|
if (!is_admin() && git_get_option('git_qncdn_b')) {
|
||||||
add_action('wp_loaded', 'Googlo_ob_start');
|
add_action('wp_loaded', 'gdk_cdn_start');
|
||||||
function Googlo_ob_start() {
|
function gdk_cdn_start() {
|
||||||
ob_start('Googlo_qiniu_cdn_replace');
|
ob_start('gdk_cdn_replace');
|
||||||
}
|
}
|
||||||
function Googlo_qiniu_cdn_replace($html) {
|
function gdk_cdn_replace($html) {
|
||||||
$local_host = home_url(); //博客域名
|
$local_host = home_url(); //博客域名
|
||||||
$qiniu_host = git_get_option('git_cdnurl_b'); //七牛域名
|
$qiniu_host = git_get_option('git_cdnurl_b'); //七牛域名
|
||||||
$cdn_exts = git_get_option('git_cdnurl_format'); //扩展名(使用|分隔)
|
$cdn_exts = git_get_option('git_cdnurl_format'); //扩展名(使用|分隔)
|
||||||
|
@ -164,6 +50,44 @@ if (is_admin() && git_get_option('git_cdnurl_b') && git_get_option('git_adminqn_
|
||||||
add_filter('wp_get_attachment_url', 'attachment_replace');
|
add_filter('wp_get_attachment_url', 'attachment_replace');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//百度收录提示
|
||||||
|
if (git_get_option('git_baidurecord_b') && function_exists('curl_init')) {
|
||||||
|
function baidu_check($url, $post_id){
|
||||||
|
$baidu_record = get_post_meta($post_id, 'baidu_record', true);
|
||||||
|
if ($baidu_record != 1) {
|
||||||
|
$url = 'http://www.baidu.com/s?wd=' . $url;
|
||||||
|
$curl = curl_init();
|
||||||
|
curl_setopt($curl, CURLOPT_URL, $url);
|
||||||
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
$rs = curl_exec($curl);
|
||||||
|
curl_close($curl);
|
||||||
|
if (!strpos($rs, '没有找到该URL,您可以直接访问') && !strpos($rs, '很抱歉,没有找到与')) {
|
||||||
|
update_post_meta($post_id, 'baidu_record', 1) || add_post_meta($post_id, 'baidu_record', 1, true);
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function baidu_record(){
|
||||||
|
global $wpdb;
|
||||||
|
$post_id = null === $post_id ? get_the_ID() : $post_id;
|
||||||
|
if (baidu_check(get_permalink($post_id), $post_id) == 1) {
|
||||||
|
echo '<a target="_blank" title="点击查看" rel="external nofollow" href="http://www.baidu.com/s?wd=' . get_the_title() . '">已收录</a>';
|
||||||
|
} else {
|
||||||
|
echo '<a style="color:red;" rel="external nofollow" title="点击提交,谢谢您!" target="_blank" href="http://zhanzhang.baidu.com/sitesubmit/index?sitename=' . get_permalink() . '">未收录</a>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//百度主动推送
|
//百度主动推送
|
||||||
if (git_get_option('git_sitemap_api')) {
|
if (git_get_option('git_sitemap_api')) {
|
||||||
function Git_Baidu_Submit($post_ID) {
|
function Git_Baidu_Submit($post_ID) {
|
||||||
|
|
|
@ -335,10 +335,11 @@ function nc_the_meta($key, $placeholder = '') {
|
||||||
}
|
}
|
||||||
|
|
||||||
function gdk_is_mobile() {
|
function gdk_is_mobile() {
|
||||||
if (empty($_SERVER['HTTP_USER_AGENT'])) {
|
$ua = $_SERVER['HTTP_USER_AGENT'];
|
||||||
|
if (empty($ua)) {
|
||||||
return false;
|
return false;
|
||||||
} elseif ((strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'iPad') === false) // many mobile devices (all iPh, etc.)
|
} elseif ((in_string($ua, 'Mobile') && strpos($ua, 'iPad') === false) // many mobile devices (all iPh, etc.)
|
||||||
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'NetType/') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'MQQBrowser') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'HUAWEI') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'TBS/') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Mi') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== false) {
|
|| in_string($ua, 'Android') || in_string($ua, 'NetType/') || in_string($ua, 'Kindle') || in_string($ua, 'MQQBrowser') || in_string($ua, 'Opera Mini') || in_string($ua, 'Opera Mobi') || in_string($ua, 'HUAWEI') || in_string($ua, 'TBS/') || in_string($ua, 'Mi') || in_string($ua, 'iPhone')) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -397,3 +398,156 @@ function in_string($text,$find) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getBrowser() {
|
||||||
|
$u_agent = $_SERVER['HTTP_USER_AGENT'];
|
||||||
|
$bname = $u_agent;
|
||||||
|
$platform = '';
|
||||||
|
$version= '';
|
||||||
|
|
||||||
|
//First get the platform?
|
||||||
|
if ( preg_match( '/linux/i', $u_agent ) ) {
|
||||||
|
$platform = 'Linux';
|
||||||
|
}
|
||||||
|
elseif ( preg_match( '/macintosh|mac os x/i', $u_agent ) ) {
|
||||||
|
$platform = 'Mac';
|
||||||
|
}
|
||||||
|
elseif ( preg_match( '/windows|win32/i', $u_agent ) ) {
|
||||||
|
$platform = 'Windows';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next get the name of the useragent yes seperately and for good reason
|
||||||
|
if ( preg_match( '/MSIE/i',$u_agent) && ! preg_match( '/Opera/i',$u_agent ) ) {
|
||||||
|
$bname = 'Internet Explorer';
|
||||||
|
$ub = "MSIE";
|
||||||
|
} elseif( preg_match( '/Firefox/i',$u_agent ) ) {
|
||||||
|
$bname = 'Mozilla Firefox';
|
||||||
|
$ub = "Firefox";
|
||||||
|
} elseif( preg_match( '/Chrome/i',$u_agent ) ) {
|
||||||
|
$bname = 'Google Chrome';
|
||||||
|
$ub = "Chrome";
|
||||||
|
} elseif( preg_match( '/Safari/i',$u_agent ) ) {
|
||||||
|
$bname = 'Apple Safari';
|
||||||
|
$ub = "Safari";
|
||||||
|
} elseif( preg_match( '/Opera/i',$u_agent ) ) {
|
||||||
|
$bname = 'Opera';
|
||||||
|
$ub = "Opera";
|
||||||
|
} elseif( preg_match( '/Netscape/i',$u_agent ) ) {
|
||||||
|
$bname = 'Netscape';
|
||||||
|
$ub = "Netscape";
|
||||||
|
}
|
||||||
|
|
||||||
|
// finally get the correct version number
|
||||||
|
$known = array( 'Version', $ub, 'other');
|
||||||
|
$pattern = '#( ?<browser>' . join( '|', $known) .
|
||||||
|
')[/ ]+( ?<version>[0-9.|a-zA-Z.]*)#';
|
||||||
|
|
||||||
|
if ( ! preg_match_all( $pattern, $u_agent, $matches ) ) {
|
||||||
|
// we have no matching number just continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( isset( $matches['browser'] ) && is_array($matches['browser']) ) {
|
||||||
|
// see how many we have
|
||||||
|
$i = count( $matches['browser'] );
|
||||||
|
|
||||||
|
if ( $i != 1) {
|
||||||
|
|
||||||
|
//we will have two since we are not using 'other' argument yet
|
||||||
|
//see if version is before or after the name
|
||||||
|
if ( strripos( $u_agent,"Version") < strripos( $u_agent,$ub ) ){
|
||||||
|
$version = $matches['version'][0];
|
||||||
|
} else {
|
||||||
|
$version = $matches['version'][1];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$version = $matches['version'][0];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$version="?";
|
||||||
|
}
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'userAgent' => $u_agent,
|
||||||
|
'name' => $bname,
|
||||||
|
'version' => $version,
|
||||||
|
'platform' => $platform,
|
||||||
|
'pattern' => $pattern
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function get_ip_address( ) {
|
||||||
|
// check for shared internet/ISP IP
|
||||||
|
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) && validate_ip( $_SERVER['HTTP_CLIENT_IP'] ) ) {
|
||||||
|
return $_SERVER['HTTP_CLIENT_IP'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// check for IPs passing through proxies
|
||||||
|
if ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
|
||||||
|
|
||||||
|
// check if multiple ips exist in var
|
||||||
|
if ( in_string( $_SERVER['HTTP_X_FORWARDED_FOR'], ',')) {
|
||||||
|
$iplist = explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR']);
|
||||||
|
foreach ( $iplist as $ip) {
|
||||||
|
if ( validate_ip( $ip ) )
|
||||||
|
return $ip;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ( validate_ip( $_SERVER['HTTP_X_FORWARDED_FOR'] ) )
|
||||||
|
return $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( ! empty( $_SERVER['HTTP_X_FORWARDED']) && validate_ip( $_SERVER['HTTP_X_FORWARDED'] ) ) {
|
||||||
|
return $_SERVER['HTTP_X_FORWARDED'];
|
||||||
|
}
|
||||||
|
if ( ! empty( $_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && validate_ip( $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'] ) ) {
|
||||||
|
return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
|
||||||
|
}
|
||||||
|
if ( ! empty( $_SERVER['HTTP_FORWARDED_FOR']) && validate_ip( $_SERVER['HTTP_FORWARDED_FOR'] ) ) {
|
||||||
|
return $_SERVER['HTTP_FORWARDED_FOR'];
|
||||||
|
}
|
||||||
|
if ( ! empty( $_SERVER['HTTP_FORWARDED']) && validate_ip( $_SERVER['HTTP_FORWARDED'] ) ) {
|
||||||
|
return $_SERVER['HTTP_FORWARDED'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// return unreliable ip since all else failed
|
||||||
|
return $_SERVER['REMOTE_ADDR'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensures an ip address is both a valid IP and does not fall within
|
||||||
|
* a private network range.
|
||||||
|
*/
|
||||||
|
function validate_ip( $ip) {
|
||||||
|
if ( strtolower( $ip) === 'unknown') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// generate ipv4 network address
|
||||||
|
$ip = ip2long( $ip);
|
||||||
|
|
||||||
|
// if the ip is set and not equivalent to 255.255.255.255
|
||||||
|
if ( $ip !== false && $ip !== -1) {
|
||||||
|
// make sure to get unsigned long representation of ip
|
||||||
|
// due to discrepancies between 32 and 64 bit OSes and
|
||||||
|
// signed numbers ( ints default to signed in PHP)
|
||||||
|
$ip = sprintf( '%u', $ip);
|
||||||
|
// do private network range checking
|
||||||
|
if ( $ip >= 0 && $ip <= 50331647) return false;
|
||||||
|
if ( $ip >= 167772160 && $ip <= 184549375) return false;
|
||||||
|
if ( $ip >= 2130706432 && $ip <= 2147483647) return false;
|
||||||
|
if ( $ip >= 2851995648 && $ip <= 2852061183) return false;
|
||||||
|
if ( $ip >= 2886729728 && $ip <= 2887778303) return false;
|
||||||
|
if ( $ip >= 3221225984 && $ip <= 3221226239) return false;
|
||||||
|
if ( $ip >= 3232235520 && $ip <= 3232301055) return false;
|
||||||
|
if ( $ip >= 4294967040) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Ajax报错方式
|
||||||
|
function gdk_die($ErrMsg) {
|
||||||
|
header('HTTP/1.1 405 Method Not Allowed');
|
||||||
|
echo $ErrMsg;
|
||||||
|
exit;
|
||||||
|
}
|
|
@ -1,22 +1,2 @@
|
||||||
<?php
|
<?php
|
||||||
function nc_url_spamcheck($approved, $commentdata)
|
|
||||||
{
|
|
||||||
return (strlen($commentdata['comment_author_url']) > 50) ? 'spam' : $approved;
|
|
||||||
}
|
|
||||||
add_filter('pre_comment_approved', 'nc_url_spamcheck', 99, 2);
|
|
||||||
|
|
||||||
function nc_comment_post($incoming_comment)
|
|
||||||
{
|
|
||||||
$pattern = '/[一-龥]/u';
|
|
||||||
// 禁止全英文评论
|
|
||||||
if (!preg_match($pattern, $incoming_comment['comment_content'])) {
|
|
||||||
wp_die("您的评论中必须包含汉字!");
|
|
||||||
}
|
|
||||||
$pattern = '/[あ-んア-ン]/u';
|
|
||||||
// 禁止日文评论
|
|
||||||
if (preg_match($pattern, $incoming_comment['comment_content'])) {
|
|
||||||
wp_die("评论禁止包含日文!");
|
|
||||||
}
|
|
||||||
return($incoming_comment);
|
|
||||||
}
|
|
||||||
add_filter('preprocess_comment', 'nc_comment_post');
|
|
||||||
|
|
Loading…
Reference in a new issue