diff --git a/class/simple_local_avatars.php b/class/simple_local_avatars.php new file mode 100644 index 0000000..92a4519 --- /dev/null +++ b/class/simple_local_avatars.php @@ -0,0 +1,177 @@ + + + ID; + elseif (is_object($id_or_email) && !empty($id_or_email->user_id)) $user_id = (int)$id_or_email->user_id; + if (empty($user_id)) return $avatar; + $local_avatars = get_user_meta($user_id, 'simple_local_avatar', true); + if (empty($local_avatars) || empty($local_avatars['full'])) return $avatar; + $size = (int)$size; + if (empty($alt)) $alt = get_the_author_meta('display_name', $user_id); + if (empty($local_avatars[$size])) { + $upload_path = wp_upload_dir(); + $avatar_full_path = str_replace($upload_path['baseurl'], $upload_path['basedir'], $local_avatars['full']); + $image = wp_get_image_editor($avatar_full_path); + if (!is_wp_error($image)) { + $image->resize($size, $size, true); + $image_sized = $image->save(); + } + $local_avatars[$size] = is_wp_error($image_sized) ? $local_avatars[$size] = $local_avatars['full'] : str_replace($upload_path['basedir'], $upload_path['baseurl'], $image_sized['path']); + update_user_meta($user_id, 'simple_local_avatar', $local_avatars); + } elseif (substr($local_avatars[$size], 0, 4) != 'http') { + $local_avatars[$size] = home_url($local_avatars[$size]); + } + $author_class = is_author($user_id) ? ' current-author' : ''; + $avatar = "" . esc_attr($alt) . ""; + return apply_filters('simple_local_avatar', $avatar); + } + public function edit_user_profile($profileuser) { +?> +

头像

+ + + + + + +
+ ID); ?> + +
'; + if (empty($profileuser->simple_local_avatar)) { + echo '尚未设置本地头像,请点击“浏览”按钮上传本地头像'; + } else { + echo '移除本地头像
'; + echo '如需要修改本地头像,请重新上传新头像。如需要移除本地头像,请选中上方的“移除本地头像”复选框并更新个人资料即可。
移除本地头像后,将恢复使用 Gravatar 头像
'; + } + } else { + if (empty($profileuser->simple_local_avatar)) { + echo '尚未设置本地头像,请在 Gravatar.com 网站设置头像'; + } else { + echo '你没有头像上传权限,如需要修改本地头像,请联系站点管理员'; + } + } +?> +
+ + 'image/jpeg', + 'gif' => 'image/gif', + 'png' => 'image/png', + ); + if (!function_exists('wp_handle_upload')) require_once ABSPATH . 'wp-admin/includes/file.php'; + $this->avatar_delete($user_id); + if (strstr($_FILES['basic-user-avatar']['name'], '.php')) wp_die('基于安全考虑 ".php" 格式文件禁止上传'); + $this->user_id_being_edited = $user_id; + $avatar = wp_handle_upload($_FILES['basic-user-avatar'], array( + 'mimes' => $mimes, + 'test_form' => false, + 'unique_filename_callback' => array( + $this, + 'unique_filename_callback' + ) + )); + update_user_meta($user_id, 'simple_local_avatar', array( + 'full' => $avatar['url'] + )); + } elseif (!empty($_POST['basic-user-avatar-erase'])) { + $this->avatar_delete($user_id); + } + } + public function avatar_defaults($avatar_defaults) { + remove_action('get_avatar', array( + $this, + 'get_avatar' + )); + return $avatar_defaults; + } + public function avatar_delete($user_id) { + $old_avatars = get_user_meta($user_id, 'simple_local_avatar', true); + $upload_path = wp_upload_dir(); + if (is_array($old_avatars)) { + foreach ($old_avatars as $old_avatar) { + $old_avatar_path = str_replace($upload_path['baseurl'], $upload_path['basedir'], $old_avatar); + @unlink($old_avatar_path); + } + } + delete_user_meta($user_id, 'simple_local_avatar'); + } + public function unique_filename_callback($dir, $name, $ext) { + $user = get_user_by('id', (int)$this->user_id_being_edited); + $name = $base_name = sanitize_file_name($user->ID . '_avatar'); + $number = 1; + while (file_exists($dir . "/$name$ext")) { + $name = $base_name . '_' . $number; + $number++; + } + return $name . $ext; + } +} +$gdk_local_avatars = new gdk_local_avatars; \ No newline at end of file diff --git a/framework/load.php b/framework/load.php deleted file mode 100644 index 81aee17..0000000 --- a/framework/load.php +++ /dev/null @@ -1,14 +0,0 @@ - array( - array( - 'name' => '滚动内容来源', - 'desc' => '选择一个内容调用显示在顶部的滚动', - 'id' => 'git_gun_b', + '优化选项' => array( + array( + 'name' => '新版编辑器开关', + 'desc' => '新版编辑器尚不成熟,很多主题不兼容,建议禁用', + 'id' => 'gdk_diasble_gutenberg', 'type' => 'radio', 'options' => array( - 'git_gun_shuo' => '调用说说标题', - 'git_gun_tui' => '调用下方公告' + '1' => '禁用', + '0' => '开启' ), - 'std' => 'git_gun_tui' + 'std' => '1' ), array( - 'name' => '滚动公告栏', - 'desc' => '最新消息显示在全站导航条下方,非常给力的推广位置', - 'id' => 'git_tui', - 'type' => 'textarea', - 'std' => '
  • 欢迎访问极客公园网站,WordPress信息,WordPress教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入极客公园 QQ群
  • Git主题现已支持滚动公告栏功能,兼容其他浏览器,看到的就是咯,在后台最新消息那里用li标签添加即可。
  • 最新版Git主题已支持说说碎语功能,可像添加文章一样直接添加说说,新建说说页面即可,最后重新保存固定连接,演示地址
  • 百度口碑求点赞啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊http://koubei.baidu.com/s/gitcafe.net
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏极客公园吧
  • ' - ), - array( - 'name' => '友情链接页面', - 'desc' => '只显示输入分类的链接,id之间用英文逗号隔开,建议只显示友情链接即可。', - 'id' => 'git_linkpage_cat', - 'type' => 'number' - ), - array( - 'name' => '列表Ajax下拉加载', - 'desc' => '开启本选项之后网站会采用ajax方式下拉自动加载,默认只在传统blog列表页面生效,如果使用卡片式或者CMS,请关闭', - 'id' => 'git_ajaxpager_b', - 'type' => 'checkbox' - ), - array( - 'title' => '热门排行', - 'type' => 'title' - ), - array( - 'name' => '开启', - 'desc' => '【注意,在开启3D幻灯片的时候是默认打开的,无法关闭】', - 'id' => 'hot_list_check', - 'type' => 'checkbox' - ), - array( - 'name' => '排序根据', - 'desc' => '选择一个参数作为排序的根据,可以选择评论数目,文章置顶,置顶文章最多10篇', - 'id' => 'git_hot_b', + 'name' => '清理冗余头部代码开关', + 'desc' => 'wordpress头部自带很多无用代码,不安全且浪费,建议禁用', + 'id' => 'gdk_diasble_head_useless', 'type' => 'radio', 'options' => array( - 'git_hot_comment' => '评论数目', - 'git_hot_zd' => '文章置顶' + '1' => '禁用', + '0' => '开启' ), - 'std' => 'git_hot_comment' + 'std' => '1' ), array( - 'name' => '排行名称', - 'desc' => '这里是显示在网站首页热门排行那里', - 'id' => 'hot_list_title', - 'type' => 'text', - 'std' => '本周热门' + 'name' => '禁用wordpress更新', + 'desc' => 'wordpress更新会不时发送请求数据,所以可以关闭wordpress更新,包括主题,插件和内核更新', + 'id' => 'gdk_diasble_wp_update', + 'type' => 'radio', + 'options' => array( + '1' => '禁用', + '0' => '开启' + ), + 'std' => '1' ), array( - 'name' => '用户登录信息', - 'desc' => '开启', - 'id' => 'git_sign_b', - 'type' => 'checkbox' + 'name' => '禁用emojis功能', + 'desc' => 'wordpress的emojis功能会加载国外资源,那是网站速度,所以建议禁用', + 'id' => 'gdk_disable_emojis', + 'type' => 'radio', + 'options' => array( + '1' => '禁用', + '0' => '开启' + ), + 'std' => '1' ), array( - 'name' => '百度分享', - 'desc' => '开启并且同时开启打赏功能,支持https', - 'id' => 'git_bdshare_b', - 'type' => 'checkbox' + 'name' => '禁用XML-RPC功能', + 'desc' => '该功能有安全风险,如果不使用wordpress的手机客户端或者第三方编辑器软件,那么建议禁用', + 'id' => 'gdk_disable_xmlrpc', + 'type' => 'radio', + 'options' => array( + '1' => '禁用', + '0' => '开启' + ), + 'std' => '1' ), array( - 'title' => '占位文本', - 'type' => 'title' + 'name' => '禁用文章版本功能', + 'desc' => '该功能有会造成数据库体量暴增为了你的数据库考虑,建议禁用', + 'id' => 'gdk_disable_revision', + 'type' => 'radio', + 'options' => array( + '1' => '禁用', + '0' => '开启' + ), + 'std' => '1' ), array( - 'name' => '搜索框', - 'desc' => '占位文本', - 'id' => 'git_search_placeholder', - 'type' => 'text', - 'std' => '输入内容并回车' + 'name' => '禁用pingback功能', + 'desc' => '该功能会增加垃圾评论的几率,建议禁用', + 'id' => 'gdk_disable_trackbacks', + 'type' => 'radio', + 'options' => array( + '1' => '禁用', + '0' => '开启' + ), + 'std' => '1' + ), + array( + 'name' => 'wordpress更新中国加速', + 'desc' => '该功能会帮助顺利更新wordpress,突破429,注意:如果上面的wordpress禁用更新了,此处设置无效,建议开启', + 'id' => 'gdk_porxy_update', + 'type' => 'radio', + 'options' => array( + '0' => '禁用', + '1' => '开启' + ), + 'std' => '1' + ), + array( + 'name' => '头像加速功能', + 'desc' => '该功能会增加头像加载速度,有随机头像,V2EX头像镜像和七牛头像镜像,默认选择随机头像', + 'id' => 'gdk_switch_get_avatar', + 'type' => 'radio', + 'options' => array( + '1' => '随机头像', + '2' => 'V2EX头像镜像', + '3' => '七牛头像镜像', + ), + 'std' => '1' ), array( 'name' => '评论', diff --git a/framework/plugin-options.php b/framework/plugin-options.php index 64b30b2..585874c 100644 --- a/framework/plugin-options.php +++ b/framework/plugin-options.php @@ -11,18 +11,19 @@ $current_theme = wp_get_theme(); $gdk_default_options = []; $gdk_options = []; include('options-config.php'); -$gdk_current_options = get_option('gdk_options_setup', []); +$gdk_current_options = get_option('gdk_options_setup'); function gdk_update_options() { global $gdk_default_options, $gdk_options, $gdk_current_options; foreach ($gdk_options as $panel) { foreach ($panel as $option) { - $id = $option['id']; - $type = $option['type']; + $id = isset( $option['id'] ) ? $option['id'] : ''; + $type = isset( $option['type'] ) ? $option['type'] : ''; + $std = isset( $option['std'] ) ? $option['std'] : ''; if ( !$id ) continue; - $gdk_default_options[$id] = $option['std']; + $gdk_default_options[$id] = $std; if ( isset($gdk_current_options[$id]) ) continue; - $gdk_current_options[$id] = isset( $option['std'] ) ? $option['std'] : ''; + $gdk_current_options[$id] = $std; } } } @@ -44,9 +45,9 @@ function gdk_options_page() {

    设置已保存。

    '; - if ($_GET['reset']) echo '

    设置已重置。

    '; - if ($_GET['test']) echo '

    如果您的邮箱收到测试邮件,则证明您的SMTP设置是没问题的。

    '; + if (isset($_GET['update'])) echo '

    设置已保存。

    '; + if (isset($_GET['reset'])) echo '

    设置已重置。

    '; + if (isset($_GET['test'])) echo '

    如果您的邮箱收到测试邮件,则证明您的SMTP设置是没问题的。

    '; ?>
    @@ -98,7 +99,6 @@ switch ( $type ) { case 'number': ?> diff --git a/functions/advanced.php b/functions/advanced.php new file mode 100644 index 0000000..26675fd --- /dev/null +++ b/functions/advanced.php @@ -0,0 +1,29 @@ +"; + break; + case 2: + $avatar = preg_replace("/http[s]{0,1}:\/\/(secure|www|\d).gravatar.com\/avatar\//","//cdn.v2ex.com/gravatar/",$avatar); + break; + default: + $avatar = preg_replace("/http[s]{0,1}:\/\/(secure|www|\d).gravatar.com\/avatar\//","//dn-qiniu-avatar.qbox.me/avatar/",$avatar); + } + return $avatar; +} +add_filter('get_avatar', 'gdk_switch_get_avatar'); + +//fancybox图片灯箱效果 +function fancybox($content) { + $pattern = "/]*).(bmp|gif|jpeg|jpg|png|swf)('|\")(.*?)>(.*?)<\\/a>/i"; + $replacement = '$7'; + $content = preg_replace($pattern, $replacement, $content); + return $content; +} +add_filter('the_content', 'fancybox'); + + diff --git a/functions/avatar.php b/functions/avatar.php index 80daa6f..872cbf6 100644 --- a/functions/avatar.php +++ b/functions/avatar.php @@ -2,196 +2,7 @@ //头像镜像 -function get_ssl_avatar($avatar) { - $avatar = preg_replace('/.*\/avatar\/(.*)\?s=([\d]+)&.*/','',$avatar); - return $avatar; -} - -add_filter('get_avatar', 'get_ssl_avatar', 10, 3); -//随机头像 -function local_random_avatar($avatar) { - $avatarsrc = 'https://cdn.jsdelivr.net/gh/yunluo/GitCafeApi/avatar/' . mt_rand(1, 1999) . '.jpg'; - $avatar = ""; - return $avatar; -} - - add_filter('get_avatar', 'local_random_avatar', 1, 5); -//本地头像 -class simple_local_avatars { - private $user_id_being_edited; - public function __construct() { - add_action('admin_init', array( - $this, - 'admin_init' - )); - add_action('show_user_profile', array( - $this, - 'edit_user_profile' - )); - add_action('edit_user_profile', array( - $this, - 'edit_user_profile' - )); - add_action('personal_options_update', array( - $this, - 'edit_user_profile_update' - )); - add_action('edit_user_profile_update', array( - $this, - 'edit_user_profile_update' - )); - add_filter('get_avatar', array( - $this, - 'get_avatar' - ) , 10, 5); - add_filter('avatar_defaults', array( - $this, - 'avatar_defaults' - )); - } - public function admin_init() { - register_setting('discussion', 'simple_local_avatars_caps', array( - $this, - 'sanitize_options' - )); - add_settings_field('basic-user-avatars-caps', '本地上传头像权限管理', array( - $this, - 'avatar_settings_field' - ) , 'discussion', 'avatars'); - } - public function avatar_settings_field($args) { - $options = get_option('simple_local_avatars_caps'); -?> - - ID; - elseif (is_object($id_or_email) && !empty($id_or_email->user_id)) $user_id = (int)$id_or_email->user_id; - if (empty($user_id)) return $avatar; - $local_avatars = get_user_meta($user_id, 'simple_local_avatar', true); - if (empty($local_avatars) || empty($local_avatars['full'])) return $avatar; - $size = (int)$size; - if (empty($alt)) $alt = get_the_author_meta('display_name', $user_id); - if (empty($local_avatars[$size])) { - $upload_path = wp_upload_dir(); - $avatar_full_path = str_replace($upload_path['baseurl'], $upload_path['basedir'], $local_avatars['full']); - $image = wp_get_image_editor($avatar_full_path); - if (!is_wp_error($image)) { - $image->resize($size, $size, true); - $image_sized = $image->save(); - } - $local_avatars[$size] = is_wp_error($image_sized) ? $local_avatars[$size] = $local_avatars['full'] : str_replace($upload_path['basedir'], $upload_path['baseurl'], $image_sized['path']); - update_user_meta($user_id, 'simple_local_avatar', $local_avatars); - } elseif (substr($local_avatars[$size], 0, 4) != 'http') { - $local_avatars[$size] = home_url($local_avatars[$size]); - } - $author_class = is_author($user_id) ? ' current-author' : ''; - $avatar = "" . esc_attr($alt) . ""; - return apply_filters('simple_local_avatar', $avatar); - } - public function edit_user_profile($profileuser) { -?> -

    头像

    - - - - - - -
    - ID); ?> - -
    '; - if (empty($profileuser->simple_local_avatar)) { - echo '尚未设置本地头像,请点击“浏览”按钮上传本地头像'; - } else { - echo '移除本地头像
    '; - echo '如需要修改本地头像,请重新上传新头像。如需要移除本地头像,请选中上方的“移除本地头像”复选框并更新个人资料即可。
    移除本地头像后,将恢复使用 Gravatar 头像
    '; - } - } else { - if (empty($profileuser->simple_local_avatar)) { - echo '尚未设置本地头像,请在 Gravatar.com 网站设置头像'; - } else { - echo '你没有头像上传权限,如需要修改本地头像,请联系站点管理员'; - } - } -?> -
    - - 'image/jpeg', - 'gif' => 'image/gif', - 'png' => 'image/png', - ); - if (!function_exists('wp_handle_upload')) require_once ABSPATH . 'wp-admin/includes/file.php'; - $this->avatar_delete($user_id); - if (strstr($_FILES['basic-user-avatar']['name'], '.php')) wp_die('基于安全考虑 ".php" 格式文件禁止上传'); - $this->user_id_being_edited = $user_id; - $avatar = wp_handle_upload($_FILES['basic-user-avatar'], array( - 'mimes' => $mimes, - 'test_form' => false, - 'unique_filename_callback' => array( - $this, - 'unique_filename_callback' - ) - )); - update_user_meta($user_id, 'simple_local_avatar', array( - 'full' => $avatar['url'] - )); - } elseif (!empty($_POST['basic-user-avatar-erase'])) { - $this->avatar_delete($user_id); - } - } - public function avatar_defaults($avatar_defaults) { - remove_action('get_avatar', array( - $this, - 'get_avatar' - )); - return $avatar_defaults; - } - public function avatar_delete($user_id) { - $old_avatars = get_user_meta($user_id, 'simple_local_avatar', true); - $upload_path = wp_upload_dir(); - if (is_array($old_avatars)) { - foreach ($old_avatars as $old_avatar) { - $old_avatar_path = str_replace($upload_path['baseurl'], $upload_path['basedir'], $old_avatar); - @unlink($old_avatar_path); - } - } - delete_user_meta($user_id, 'simple_local_avatar'); - } - public function unique_filename_callback($dir, $name, $ext) { - $user = get_user_by('id', (int)$this->user_id_being_edited); - $name = $base_name = sanitize_file_name($user->ID . '_avatar'); - $number = 1; - while (file_exists($dir . "/$name$ext")) { - $name = $base_name . '_' . $number; - $number++; - } - return $name . $ext; - } -} -$simple_local_avatars = new simple_local_avatars; diff --git a/functions/func_load.php b/functions/func_load.php index e15143c..06f206a 100644 --- a/functions/func_load.php +++ b/functions/func_load.php @@ -3,7 +3,7 @@ //require ( 'shortcode.php' );//短代码 include('optimization.php');//优化措施 -//require ( 'avatar.php' );//头像功能 +include( 'advanced.php' );//头像功能 //require ( 'server.php' );//第三方服务 diff --git a/functions/optimization.php b/functions/optimization.php index 44dba74..a95ab15 100644 --- a/functions/optimization.php +++ b/functions/optimization.php @@ -3,9 +3,146 @@ //禁用新版编辑器 +if(gdk_get_option('gdk_diasble_gutenberg')){ add_filter('use_block_editor_for_post', '__return_false'); remove_action( 'wp_enqueue_scripts', 'wp_common_block_scripts_and_styles' ); - +} // 友情链接扩展 -add_filter('pre_option_link_manager_enabled', '__return_true'); \ No newline at end of file +add_filter('pre_option_link_manager_enabled', '__return_true'); + +//移除 WP_Head 无关紧要的代码 +if(gdk_get_option('gdk_diasble_head_useless')){ + remove_action('wp_head', 'wp_generator'); //删除 head 中的 WP 版本号 + foreach (array('rss2_head', 'commentsrss2_head', 'rss_head', 'rdf_header', 'atom_head', 'comments_atom_head', 'opml_head', 'app_head') as $action) { + remove_action($action, 'the_generator'); + } + + remove_action('wp_head', 'rsd_link'); //删除 head 中的 RSD LINK + remove_action('wp_head', 'wlwmanifest_link'); //删除 head 中的 Windows Live Writer 的适配器? + + remove_action('wp_head', 'feed_links_extra', 3); //删除 head 中的 Feed 相关的link + //remove_action( 'wp_head', 'feed_links', 2 ); + + remove_action('wp_head', 'index_rel_link'); //删除 head 中首页,上级,开始,相连的日志链接 + remove_action('wp_head', 'parent_post_rel_link', 10); + remove_action('wp_head', 'start_post_rel_link', 10); + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10); + + remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0); //删除 head 中的 shortlink + + remove_action('wp_head', 'rest_output_link_wp_head', 10); // 删除头部输出 WP RSET API 地址 + + remove_action('template_redirect', 'wp_shortlink_header', 11); //禁止短链接 Header 标签。 + remove_action('template_redirect', 'rest_output_link_header', 11); // 禁止输出 Header Link 标签。 +} + + +/** 开始关闭WordPress更新 **/ +if (gdk_get_option('gdk_diasble_wp_update')) { + add_filter('automatic_updater_disabled', '__return_true'); + remove_action('init', 'wp_schedule_update_checks'); + wp_clear_scheduled_hook('wp_version_check'); + wp_clear_scheduled_hook('wp_maybe_auto_update'); + remove_action( 'admin_init', '_maybe_update_core' ); + //禁用主题更新 + wp_clear_scheduled_hook('wp_update_themes'); + remove_action( 'load-themes.php', 'wp_update_themes' ); + remove_action( 'load-update.php', 'wp_update_themes' ); + remove_action( 'load-update-core.php', 'wp_update_themes' ); + remove_action( 'admin_init', '_maybe_update_themes' ); + // 禁用插件更新 + wp_clear_scheduled_hook('wp_update_plugins'); + remove_action( 'load-plugins.php', 'wp_update_plugins' ); + remove_action( 'load-update.php', 'wp_update_plugins' ); + remove_action( 'load-update-core.php', 'wp_update_plugins' ); + remove_action( 'admin_init', '_maybe_update_plugins' ); +} + +//禁用自带p标签的 +remove_filter( 'the_content', 'wpautop' ); +add_filter( 'the_content', 'wpautop' , 12); + +//禁用emoji功能 +if (gdk_get_option('gdk_disable_emojis')) { + function gdk_disable_emojis_link() { + remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); + remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); + remove_action( 'wp_print_styles', 'print_emoji_styles' ); + remove_action( 'admin_print_styles', 'print_emoji_styles' ); + remove_filter( 'the_content_feed', 'wp_staticize_emoji' ); + remove_filter( 'comment_text_rss', 'wp_staticize_emoji' ); + remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ); + add_filter( 'tiny_mce_plugins', 'gdk_disable_emojis_tinymce' ); + } + add_action( 'init', 'gdk_disable_emojis_link' ); + + function gdk_disable_emojis_tinymce( $plugins ) { + if ( is_array( $plugins ) ) return array_diff( $plugins, array( 'wpemoji' ) ); + return array(); + } +} + + +//禁用 XML-RPC 接口 +if (gdk_get_option('gdk_disable_xmlrpc')) { + add_filter('xmlrpc_enabled', '__return_false'); + remove_action('xmlrpc_rsd_apis', 'rest_output_rsd'); +} + + +//禁用日志修订功能 +if (gdk_get_option('gdk_disable_revision')) { + function gdk_disable_post_revisions() { + foreach ( get_post_types() as $post_type ) { + remove_post_type_support( $post_type, 'revisions' ); + } + } + add_action( 'init', 'gdk_disable_post_revisions', 999 ); +} + +//彻底关闭 pingback +if (gdk_get_option('gdk_disable_trackbacks')) { + add_filter('xmlrpc_methods', 'gdk_xmlrpc_methods'); + function gdk_xmlrpc_methods($methods) { + $methods['pingback.ping'] = '__return_false'; + $methods['pingback.extensions.getPingbacks'] = '__return_false'; + return $methods; + } + //禁用 pingbacks, enclosures, trackbacks + remove_action('do_pings', 'do_all_pings', 10); + //去掉 _encloseme 和 do_ping 操作。 + remove_action('publish_post', '_publish_post_hook', 5); +} + +//国内更新word press加速 +if (gdk_get_option('gdk_porxy_update') && !gdk_get_option('gdk_diasble_wp_update')) { + add_filter('site_transient_update_core',function($value) { + foreach($value->updates as &$update) { + if($update->locale == 'zh_CN') { + $update->download = 'http://cn.wp101.net/latest-zh_CN.zip'; + $update->packages->full = 'http://cn.wp101.net/latest-zh_CN.zip'; + } + } + return $value; + } + ); +} + + +function html_page_permalink() { + global $wp_rewrite; + if (!strpos($wp_rewrite->get_page_permastruct(), '.html')) { + $wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html'; + } +} +add_action('init', 'html_page_permalink', -1); + + +//中文文件重命名 +function gdk_upload_rename($file) { + $time = date("YmdHis"); + $file['name'] = $time . "" . mt_rand(1, 100) . "." . pathinfo($file['name'], PATHINFO_EXTENSION); + return $file; +} +add_filter('wp_handle_upload_prefilter', 'gdk_upload_rename'); \ No newline at end of file diff --git a/functions/utils.php b/functions/utils.php index 608f328..b0ce41d 100644 --- a/functions/utils.php +++ b/functions/utils.php @@ -332,4 +332,54 @@ function nc_get_meta($key, $single = true) { function nc_the_meta($key, $placeholder = '') { echo nc_get_meta($key, true) ?: $placeholder; +} + +function gdk_is_mobile() { + if (empty($_SERVER['HTTP_USER_AGENT'])) { + return false; + } elseif ((strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false && strpos($_SERVER['HTTP_USER_AGENT'], '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) { + return true; + } else { + return false; + } +} + +if (function_exists('curl_init')) { + function curl_post($url, $postfields = '', $headers = '', $timeout = 20, $file = 0) { + $ch = curl_init(); + $options = array( + CURLOPT_URL => $url, + CURLOPT_HEADER => false, + CURLOPT_NOBODY => false, + CURLOPT_POST => true, + CURLOPT_MAXREDIRS => 20, + CURLOPT_USERAGENT => 'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36', + CURLOPT_TIMEOUT => $timeout, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_SSL_VERIFYHOST => 0, + CURLOPT_SSL_VERIFYPEER => 0 + ); + if (is_array($postfields) && $file == 0) { + $options[CURLOPT_POSTFIELDS] = http_build_query($postfields); + } else { + $options[CURLOPT_POSTFIELDS] = $postfields; + } + curl_setopt_array($ch, $options); + if (is_array($headers)) { + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + } + $result = curl_exec($ch); + $code = curl_errno($ch); + $msg = curl_error($ch); + $info = curl_getinfo($ch); + curl_close($ch); + return array( + 'data' => $result, + 'code' => $code, + 'msg' => $msg, + 'info' => $info + ); + } } \ No newline at end of file diff --git a/modules/base/functions/rocket.php b/modules/base/functions/rocket.php index cb5e4ef..e39dd55 100644 --- a/modules/base/functions/rocket.php +++ b/modules/base/functions/rocket.php @@ -20,81 +20,16 @@ if (!function_exists('nc_admin_logo')): add_action('login_head', 'nc_admin_logo'); endif; -//移除 WP_Head 无关紧要的代码 -if ($general_options['remove_wp_head_useless']) { - remove_action('wp_head', 'wp_generator'); //删除 head 中的 WP 版本号 - foreach (array('rss2_head', 'commentsrss2_head', 'rss_head', 'rdf_header', 'atom_head', 'comments_atom_head', 'opml_head', 'app_head') as $action) { - remove_action($action, 'the_generator'); - } - - remove_action('wp_head', 'rsd_link'); //删除 head 中的 RSD LINK - remove_action('wp_head', 'wlwmanifest_link'); //删除 head 中的 Windows Live Writer 的适配器? - - remove_action('wp_head', 'feed_links_extra', 3); //删除 head 中的 Feed 相关的link - //remove_action( 'wp_head', 'feed_links', 2 ); - - remove_action('wp_head', 'index_rel_link'); //删除 head 中首页,上级,开始,相连的日志链接 - remove_action('wp_head', 'parent_post_rel_link', 10); - remove_action('wp_head', 'start_post_rel_link', 10); - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10); - - remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0); //删除 head 中的 shortlink - - remove_action('wp_head', 'rest_output_link_wp_head', 10); // 删除头部输出 WP RSET API 地址 - - remove_action('template_redirect', 'wp_shortlink_header', 11); //禁止短链接 Header 标签。 - remove_action('template_redirect', 'rest_output_link_header', 11); // 禁止输出 Header Link 标签。 -} - -//禁用日志修订功能 -if ($general_options['post_revision']) { - if (!function_exists('nc_disable_post_revisions')): - function nc_disable_post_revisions() { - foreach ( get_post_types() as $post_type ) { - remove_post_type_support( $post_type, 'revisions' ); - } - } - add_action( 'init', 'nc_disable_post_revisions', 999 ); - endif; -} - -if (isset($general_options['core_update']) && $general_options['core_update']) { - add_filter('site_transient_update_core', 'nc_core_update_cdn'); - function nc_core_update_cdn($value) { - foreach ($value->updates as &$update) { - $update->download = str_replace('downloads.wordpress.org', 'downloads.wordpress.org.nicetheme.xyz', $update->download); - $update->packages->full = str_replace('downloads.wordpress.org', 'downloads.wordpress.org.nicetheme.xyz', $update->packages->full); - } - - return $value; - } -} - -if ($general_options['disable_trackbacks']) { - //彻底关闭 pingback - if (!function_exists('nc_xmlrpc_methods')): - add_filter('xmlrpc_methods', 'nc_xmlrpc_methods'); - function nc_xmlrpc_methods($methods) - { - $methods['pingback.ping'] = '__return_false'; - $methods['pingback.extensions.getPingbacks'] = '__return_false'; - - return $methods; - } - endif; - //禁用 pingbacks, enclosures, trackbacks - remove_action('do_pings', 'do_all_pings', 10); - - //去掉 _encloseme 和 do_ping 操作。 - remove_action('publish_post', '_publish_post_hook', 5); -} -//禁用 XML-RPC 接口 -if ($general_options['disable_xmlrpc']) { - add_filter('xmlrpc_enabled', '__return_false'); - remove_action('xmlrpc_rsd_apis', 'rest_output_rsd'); -} + + + + + + + + //禁用 Auto OEmbed // if ($general_options['disable_auto_embeds']) { @@ -139,81 +74,5 @@ if ($general_options['gravatar_speedup']) { endif; } -if ($general_options['disable_emoji']) { - if (!function_exists('nc_disable_emojis')): - function nc_disable_emojis() { - remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); - remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); - remove_action( 'wp_print_styles', 'print_emoji_styles' ); - remove_action( 'admin_print_styles', 'print_emoji_styles' ); - remove_filter( 'the_content_feed', 'wp_staticize_emoji' ); - remove_filter( 'comment_text_rss', 'wp_staticize_emoji' ); - remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ); - add_filter( 'tiny_mce_plugins', 'nc_disable_emojis_tinymce' ); - } - add_action( 'init', 'nc_disable_emojis' ); - endif; - if (!function_exists('nc_disable_emojis_tinymce')): - function nc_disable_emojis_tinymce( $plugins ) { - if ( is_array( $plugins ) ) return array_diff( $plugins, array( 'wpemoji' ) ); - return array(); - } - endif; -} -if ($general_options['emoji_cdn']) { - if (!function_exists('nc_change_wp_emoji_baseurl')): - function nc_change_wp_emoji_baseurl() { - return set_url_scheme('//twemoji.maxcdn.com/2/72x72/'); - } - add_action( 'emoji_url', 'nc_change_wp_emoji_baseurl' ); - endif; - if (!function_exists('nc_change_wp_emoji_baseurl')): - function nc_change_wp_emoji_svgurl($url) { - return set_url_scheme('//twemoji.maxcdn.com/svg/'); - } - add_filter('emoji_svg_url', 'nc_change_wp_emoji_svgurl'); - endif; -} -if ($general_options['disable_wp_widgets']) { - if (!function_exists('nc_unregister_rss_widget')): - function nc_unregister_rss_widget(){ - unregister_widget('WP_Widget_Pages'); - unregister_widget('WP_Nav_Menu_Widget'); - unregister_widget('WP_Widget_Categories'); - unregister_widget('WP_Widget_Meta'); - unregister_widget('WP_Widget_RSS'); - unregister_widget('WP_Widget_Calendar'); - unregister_widget('WP_Widget_Links'); - unregister_widget('WP_Widget_Recent_Comments'); - } - add_action('widgets_init', 'nc_unregister_rss_widget'); - endif; -} - -if ($general_options['disable_core_update']) { - add_filter('automatic_updater_disabled', '__return_true'); - - remove_action('init', 'wp_schedule_update_checks'); - wp_clear_scheduled_hook('wp_version_check'); - wp_clear_scheduled_hook('wp_maybe_auto_update'); - - remove_action( 'admin_init', '_maybe_update_core' ); -} - -if ($general_options['disable_theme_update']) { - wp_clear_scheduled_hook('wp_update_themes'); - remove_action( 'load-themes.php', 'wp_update_themes' ); - remove_action( 'load-update.php', 'wp_update_themes' ); - remove_action( 'load-update-core.php', 'wp_update_themes' ); - remove_action( 'admin_init', '_maybe_update_themes' ); -} - -if ($general_options['disable_plugin_update']) { - wp_clear_scheduled_hook('wp_update_plugins'); - remove_action( 'load-plugins.php', 'wp_update_plugins' ); - remove_action( 'load-update.php', 'wp_update_plugins' ); - remove_action( 'load-update-core.php', 'wp_update_plugins' ); - remove_action( 'admin_init', '_maybe_update_plugins' ); -} \ No newline at end of file diff --git a/route.php b/route.php index 3384efd..a95f4c9 100644 --- a/route.php +++ b/route.php @@ -26,20 +26,20 @@ define('NC_STORE_VER', '0.3.5'); define('NC_STORE_FILE', __FILE__);//插件入口文件 define('NC_BASE_URL', plugin_dir_url( __FILE__ ) );//插件目录url define('NC_STORE_ROOT_PATH', plugin_dir_path( __FILE__ ) );//插件目录路径 -include('library/nc-base/kernel/kernel.php'); -include('library/nc-base/static-load.php'); -include('library/nc-base/add-menu-page.php'); +//include('library/nc-base/kernel/kernel.php'); +//include('library/nc-base/static-load.php'); +//include('library/nc-base/add-menu-page.php'); if (version_compare(PHP_VERSION, '7.2.26', '>=')) { - include('modules/field-group/Field_Group_Values.php'); - include('modules/field-group/get_all_custom_field_meta.php'); + //include('modules/field-group/Field_Group_Values.php'); + //include('modules/field-group/get_all_custom_field_meta.php'); } -include('modules/base/main.php'); - +//include('modules/base/main.php'); +include('framework/plugin-options.php'); include('functions/func_load.php'); -include('framework/load.php'); + function nc_store_pluggable_include() { include( 'modules/pluggable/load.php' );