1
0
Fork 0
mirror of https://github.com/yunluo/gdk.git synced 2024-05-18 06:06:40 +02:00

更新优化了路由重写规则

This commit is contained in:
云落 2020-02-11 23:41:23 +08:00
parent e5ea0abab5
commit c975b5a1f8
11 changed files with 72 additions and 231 deletions

BIN
assets/img/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

View file

@ -134,14 +134,7 @@ function gdk_link_go($content) {
return $content;
}
//微信登陆重写
function weauth_rewrite_rules($wp_rewrite){
if (get_option('permalink_structure')) {
$new_rules['^weauth'] = 'index.php?user=$matches[1]&sk=$matches[2]';
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
}
add_action('generate_rewrite_rules', 'weauth_rewrite_rules');
//邮箱SMTP设置
function gdk_smtp( $phpmailer ) {

View file

@ -1,99 +0,0 @@
<?php
//SMTP邮箱设置
/*
if (gdk_option('gdk_mailsmtp_b')) {
function googlo_mail_smtp($phpmailer) {
$phpmailer->From = gdk_option('gdk_maildizhi_b'); //发件人地址
$phpmailer->FromName = gdk_option('gdk_mailnichen_b'); //发件人昵称
$phpmailer->Host = gdk_option('gdk_mailsmtp_b'); //SMTP服务器地址
$phpmailer->Port = gdk_option('gdk_mailport_b'); //SMTP邮件发送端口
if (gdk_option('gdk_smtpssl_b')) {
$phpmailer->SMTPSecure = 'ssl';
} else {
$phpmailer->SMTPSecure = '';
} //SMTP加密方式(SSL/TLS)没有为空即可
$phpmailer->Username = gdk_option('gdk_mailuser_b'); //邮箱帐号
$phpmailer->Password = gdk_option('gdk_mailpass_b'); //邮箱密码
$phpmailer->IsSMTP();
$phpmailer->SMTPAuth = true; //启用SMTPAuth服务
}
add_action('phpmailer_init', 'googlo_mail_smtp');
}
*/
//修改默认发信地址
function deel_res_from_email($email) {
$wp_from_email = get_option('admin_email');
return $wp_from_email;
}
function deel_res_from_name($email) {
$wp_from_name = get_option('blogname');
return $wp_from_name;
}
add_filter('wp_mail_from', 'deel_res_from_email');
add_filter('wp_mail_from_name', 'deel_res_from_name');
//评论回应邮件通知
function comment_mail_notify($comment_id) {
$admin_notify = '0'; // admin 要不要收回复通知 ( '1'=要 ; '0'=不要 )
$admin_email = get_bloginfo('admin_email'); // $admin_email 可改为你指定的 e-mail.
$comment = get_comment($comment_id);
$comment_author_email = trim($comment->comment_author_email);
$parent_id = $comment->comment_parent ? $comment->comment_parent : '';
$blogname = get_option("blogname");
global $wpdb;
if ($wpdb->query("Describe {$wpdb->comments} comment_mail_notify") == '') $wpdb->query("ALTER TABLE {$wpdb->comments} ADD COLUMN comment_mail_notify TINYINT NOT NULL DEFAULT 0;");
if (($comment_author_email != $admin_email && isset($_POST['comment_mail_notify'])) || ($comment_author_email == $admin_email && $admin_notify == '1')) $wpdb->query("UPDATE {$wpdb->comments} SET comment_mail_notify='1' WHERE comment_ID='$comment_id'");
$notify = $parent_id ? get_comment($parent_id)->comment_mail_notify : '0';
$spam_confirmed = $comment->comment_approved;
if ($parent_id != '' && $spam_confirmed != 'spam' && $notify == '1') {
$wp_email = 'no-reply@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])); // e-mail 发出点, no-reply 可改为可用的 e-mail.
$to = trim(get_comment($parent_id)->comment_author_email);
$subject = 'Hi您在 [' . get_option("blogname") . '] 的留言有人回复啦!';
$message = '<div style="color:#555;font:12px/1.5 微软雅黑,Tahoma,Helvetica,Arial,sans-serif;width:650px;margin:50px auto;border-top: none;box-shadow:0 0px 3px #aaaaaa;" ><table border="0" cellspacing="0" cellpadding="0"><tbody><tr valign="top" height="2"><td valign="top"><div style="background-color:white;border-top:2px solid #12ADDB;line-padding:0 15px 12px;width:650px;color:#555555;font-family:微软雅黑, Arial;;font-size:12px;"><h2 style="border-bottom:1px solid #DDD;font-size:14px;font-weight:normal;padding:8px 0 10px 8px;"><span style="color: #12ADDB;font-weight: bold;">&gt; </span>您在 <a style="text-decoration:none; color:#58B5F5;font-weight:600;" target="_blank" href="' . home_url() . '">' . $blogname . '</a> 网站上的留言有回复啦!</h2><div style="padding:0 12px 0 12px;margin-top:18px"><p>您好, ' . trim(get_comment($parent_id)->comment_author) . '! 您发表在文章 <a style="text-decoration:none;" target="_blank" href="' . get_the_permalink($comment->comment_post_ID) . '">《' . get_the_title($comment->comment_post_ID) . '》</a> 的评论:</p><p style="background-color: #EEE;border: 1px solid #DDD;padding: 20px;margin: 15px 0;">' . nl2br(strip_tags(get_comment($parent_id)->comment_content)) . '</p><p>' . trim($comment->comment_author) . ' 给您的回复如下:</p><p style="background-color: #EEE;border: 1px solid #DDD;padding: 20px;margin: 15px 0;">' . nl2br(strip_tags($comment->comment_content)) . '</p><p>您可以点击 <a style="text-decoration:none; color:#5692BC" target="_blank" href="' . htmlspecialchars(get_comment_link($parent_id)) . '">这里查看回复的完整內容</a>,也欢迎再次光临 <a style="text-decoration:none; color:#5692BC" target="_blank" href="' . home_url() . '">' . $blogname . '</a>。祝您天天开心,欢迎下次访问 <a style="text-decoration:none; color:#5692BC" target="_blank" href="' . home_url() . '">' . $blogname . '</a>!谢谢。</p><p style="float:right;">(此邮件由系统自动发出, 请勿回复)</p></div></div></td></tr></tbody></table><div style="color:#fff;background-color: #12ADDB;text-align : center;height:35px;padding-top:15px">Copyright © 2013-2018 ' . $blogname . '</div></div>';
$from = "From: \"" . get_option('blogname') . "\" <$wp_email>";
$headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
wp_mail($to, $subject, $message, $headers);
}
}
add_action('comment_post', 'comment_mail_notify');
//站长评论邮件添加评论链接
function gdk_notify_postauthor($notify_message,$comment_ID) {
$notify = $notify_message;
$notify.= '快速回复此评论: ' . admin_url("edit-comments.php").'#comment-'.$comment_ID;
return $notify;
}
add_filter('comment_notification_text', 'gdk_notify_postauthor', 10, 2);
//欢迎新用户邮件
function gdk_register_mail($user_id) {
$user = get_user_by('id', $user_id);
$user_pass = $_POST['password'];
$blogname = get_option('blogname');
$message = '<div class="emailcontent" style="width:100%;max-width:720px;text-align:left;margin:0 auto;padding-top:80px;padding-bottom:20px"><div class="emailtitle"><h1 style="color:#fff;background:#51a0e3;line-height:70px;font-size:24px;font-weight:400;padding-left:40px;margin:0">注册成功通知</h1><div class="emailtext" style="background:#fff;padding:20px 32px 20px"><div style="padding:0;font-weight:700;color:#6e6e6e;font-size:16px">尊敬的' . $user->user_login . ',您好!</div><p style="color:#6e6e6e;font-size:13px;line-height:24px">欢迎您注册[' . $blogname . '],下面是您的账号信息,请妥善保管!</p><table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-top:1px solid #eee;border-left:1px solid #eee;color:#6e6e6e;font-size:16px;font-weight:normal"><thead><tr><th colspan="2" style="padding:10px 0;border-right:1px solid #eee;border-bottom:1px solid #eee;text-align:center;background:#f8f8f8">您的详细注册信息</th></tr></thead><tbody><tr><td style="padding:10px 0;border-right:1px solid #eee;border-bottom:1px solid #eee;text-align:center;width:100px">登录邮箱</td><td style="padding:10px 20px 10px 30px;border-right:1px solid #eee;border-bottom:1px solid #eee;line-height:30px">' . $user->user_email . '</td></tr><tr><td style="padding:10px 0;border-right:1px solid #eee;border-bottom:1px solid #eee;text-align:center">登录密码</td><td style="padding:10px 20px 10px 30px;border-right:1px solid #eee;border-bottom:1px solid #eee;line-height:30px">' . $user_pass . '</td></tr></tbody></table><p style="color:#6e6e6e;font-size:13px;line-height:24px">如果您的账号有异常,请您在第一时间和我们取得联系哦,联系邮箱:' . get_bloginfo('admin_email') . '</p></div><div class="emailad" style="margin-top:4px"><a href="' . home_url() . '"><img src="http://reg.163.com/images/secmail/adv.png" alt="" style="margin:auto;width:100%;max-width:700px;height:auto"></a></div></div></div>';
$headers = "Content-Type:text/html;charset=UTF-8\n";
wp_mail($user->user_email, '[' . $blogname . ']欢迎注册' . $blogname, $message, $headers);
}
add_action('user_register', 'gdk_register_mail');
//登录失败提醒
function gdk_login_failed_notify() {
date_default_timezone_set('PRC');
$admin_email = get_bloginfo('admin_email');
$to = $admin_email;
$subject = '您的网站登录错误警告';
$message = '<p>您好!您的网站(' . get_option("blogname") . ')有登录错误!</p>' . '<p>请确定是您自己的登录失误,以防别人攻击!登录信息如下:</p>' . '<p>登录名:' . $_POST['log'] . '</p>' . '<p>登录密码:' . $_POST['pwd'] . '</p>' . '<p>登录时间:' . date("Y-m-d H:i:s") . '</p>' . '<p>登录IP' . $_SERVER['REMOTE_ADDR'] . '</p>' . '<p style="float:right">————本邮件由系统发送,无需回复</p>';
$wp_email = 'no-reply@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
$from = "From: \"" . get_option('blogname') . "\" <$wp_email>";
$headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
wp_mail($to, $subject, $message, $headers);
}
add_action('wp_login_failed', 'gdk_login_failed_notify');

View file

@ -1,4 +1,5 @@
<?php
include( 'rewrite.php' );//路由重写
include( 'Common.php' );//通用代码
include( 'Ajax.php' );//Ajax服务
@ -6,13 +7,9 @@ include( 'optimization.php');//优化措施
include( 'advanced.php' );//高级功能
include( 'security.php' );//安全功能
include( 'shortcode.php' );//短代码
include( 'seo.php' );//seo功能
include(GDK_ROOT_PATH.'public/download.php');//单页下载
include(GDK_ROOT_PATH.'public/go.php');//跳转中间页
include(GDK_ROOT_PATH.'public/daohang.php');//跳转中间页

View file

@ -323,14 +323,7 @@ if (gdk_option('gdk_porxy_update') && !gdk_option('gdk_diasble_wp_update')) {
);
}
//页面伪静态
function gdk_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', 'gdk_page_permalink', -1);
//文件自动重命名
if(gdk_option('gdk_upload_rename')) {

56
functions/rewrite.php Normal file
View file

@ -0,0 +1,56 @@
<?php
/**
* 各页面重写规则
*/
//页面伪静态规则
function gdk_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', 'gdk_page_permalink', -1);
// 更新重写规则
function gdk_rewrite_flush_rules(){
$rules = get_option( 'rewrite_rules' );
if ( !isset( $rules['^sitemap(.*?)\.xml$'] , $rules['^sitemap(.*?)\.html$'], $rules['^daohang(.*?)\.html$'] ) ) {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
}
add_action( 'wp_loaded', 'gdk_rewrite_flush_rules' );
// 添加自定义URL重写
function gdk_add_custom_rewrite_rule() {
add_rewrite_rule('^sitemap(.*?)\.xml$','index.php?sitemap=gdk$matches[1]','top');//xml地图规则
add_rewrite_rule('^sitemap(.*?)\.html$','index.php?sitemap=gdkk$matches[1]','top');//html地图规则
add_rewrite_rule('^daohang(.*?)\.html$','index.php?daohang=gdkk$matches[1]','top');//导航页面规则
add_rewrite_rule('^weauth','index.php?user=$matches[1]&sk=$matches[2]','top');//微信登陆二维码规则
}
add_action( 'init', 'gdk_add_custom_rewrite_rule' , 10, 0);
//自定义链接跳转
function gdk_custom_cancel_redirect( $redirect_url ) {
$api_sitemap = get_query_var('sitemap');
$api_daohang = get_query_var('daohang');
if ( !empty($api_sitemap) || !empty($api_daohang) ){
return false;
}else{
return $redirect_url;
}
}
add_filter( 'redirect_canonical', 'gdk_custom_cancel_redirect' );
//自定义路由参数,GO跳转和dl下载
function gdk_public_query_vars($public_query_vars){
array_push($public_query_vars, 'go','dl','sitemap','daohang');
return $public_query_vars;
}
add_action('query_vars', 'gdk_public_query_vars');

File diff suppressed because one or more lines are too long

View file

@ -1,13 +1,10 @@
<?php
add_action('query_vars', 'gdk_edl_add_query_vars');
add_action('template_redirect', 'gdk_edl_redirect');
function gdk_edl_add_query_vars($public_query_vars){
$public_query_vars[] = 'dl';
return $public_query_vars;
}
function gdk_edl_redirect(){
global $wp,$wp_query;
@ -125,7 +122,3 @@ if(empty($download_link)) wp_die('不填写文件下载链接是不可以的哦'
</body>
</html>
<?php }
//页脚

View file

@ -1,13 +1,10 @@
<?php
add_action('query_vars', 'gdk_go_add_query_vars');
add_action('template_redirect', 'gdk_go_redirect');
function gdk_go_add_query_vars($public_query_vars){
$public_query_vars[] = 'go';
return $public_query_vars;
}
function gdk_go_redirect(){
global $wp,$wp_query;

View file

@ -1,32 +1,5 @@
<?php
// ----------------------
// 开一个api的统一URL
function gdk_sitemap_xml_flush_rules(){
$rules = get_option( 'rewrite_rules' );
if ( !isset( $rules['^sitemap(.*?)\.xml$'] ) ) {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
}
// 添加自定义URL重写
function gdk_sitemap_xml_custom_rewrite_rule() {
add_rewrite_rule('^sitemap(.*?)\.xml$','index.php?sitemap=gdk$matches[1]','top');
}
function gdk_sitemap_xml_insert_query_vars( $vars ){
array_push($vars, 'sitemap');
return $vars;
}
function gdk_sitemap_xml_cancel_redirect( $redirect_url ) {
$api_type = get_query_var('sitemap');
if ( !empty($api_type) ){
return false;
}else{
return $redirect_url;
}
}
function gdk_sitemap_xml_api_handlers( $template ){
@ -57,10 +30,8 @@ function gdk_sitemap_xml_api_handlers( $template ){
return $template;
}
add_action( 'init', 'gdk_sitemap_xml_custom_rewrite_rule' , 10, 0);
add_filter( 'query_vars', 'gdk_sitemap_xml_insert_query_vars' );
add_filter( 'redirect_canonical', 'gdk_sitemap_xml_cancel_redirect' );
add_action( 'wp_loaded', 'gdk_sitemap_xml_flush_rules' );
add_filter( 'template_include', 'gdk_sitemap_xml_api_handlers', 99 );
function gdk_create_sitemap() {

View file

@ -2,34 +2,7 @@
/**
* SiteMap HTML
*/
// ----------------------
// 开一个api的统一URL
function gdk_sitemap_html_flush_rules(){
$rules = get_option( 'rewrite_rules' );
if ( !isset( $rules['^sitemap(.*?)\.html$'] ) ) {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
}
// 添加自定义URL重写
function gdk_sitemap_html_custom_rewrite_rule() {
add_rewrite_rule('^sitemap(.*?)\.html$','index.php?sitemap=gdkk$matches[1]','top');
}
function gdk_sitemap_html_insert_query_vars( $vars ){
array_push($vars, 'sitemap');
return $vars;
}
function gdk_sitemap_html_cancel_redirect( $redirect_url ) {
$api_type = get_query_var('sitemap');
if ( !empty($api_type) ){
return false;
}else{
return $redirect_url;
}
}
function gdk_sitemap_html_api_handlers( $template ){
@ -59,10 +32,7 @@ function gdk_sitemap_html_api_handlers( $template ){
return $template;
}
add_action( 'init', 'gdk_sitemap_html_custom_rewrite_rule' , 10, 0);
add_filter( 'query_vars', 'gdk_sitemap_html_insert_query_vars' );
add_filter( 'redirect_canonical', 'gdk_sitemap_html_cancel_redirect' );
add_action( 'wp_loaded', 'gdk_sitemap_html_flush_rules' );
add_filter( 'template_include', 'gdk_sitemap_html_api_handlers', 99 );
function gdk_create_html_sitemap() {