1
0
Fork 0
mirror of https://github.com/yunluo/gdk.git synced 2024-06-20 06:25:13 +02:00

优化问题

This commit is contained in:
云落 2020-02-06 19:53:07 +08:00
parent f3a8f8f61c
commit bd3e9cb1a1
3 changed files with 122 additions and 277 deletions

View file

@ -63,6 +63,7 @@ function check_data(a,b){/**1=数字,2=邮箱,3=网址,4= 到时候再写 */
}
/**点击提交充值开始 */
$("#submit_pay").click(function() {
var money = $("#money").val(),
@ -72,7 +73,7 @@ var money = $("#money").val(),
/**检查服务器是否有订单 */
function checkpayjs(a, b) { //ID订单号
function check_pay_points(a, b) { //ID订单号
var ajax_data = {
check_pay_points: ajax.check_pay_points,
action: 'check_pay_points',
@ -81,6 +82,8 @@ var money = $("#money").val(),
};
$.post(ajax.url, ajax_data,
function(c) {
console.log(c);
c = $.trim(c);
if (c == '200') {
swal("支付成功!", "为了方便您后续再次查看,建议您输入您的常用邮箱作为提取码", "info", {
dangerMode: true,
@ -88,6 +91,7 @@ var money = $("#money").val(),
content: "input",
})
.then((d) => {
console.log(d);
gdk_getcontent(a);
addcode(a, `${d}`);
}); //ok
@ -121,7 +125,7 @@ var money = $("#money").val(),
button: ""+e[2]+"支付已完成",
})
.then((value) => {
checkpayjs(c, e[1]);/**用户id,订单号 */
check_pay_points(c, e[1]);/**用户id,订单号 */
});
new QRious({
element: document.getElementById("pqrious"),

View file

@ -904,9 +904,9 @@ function gdk_category(){
*/
function gdk_term_meta($term,$meta,$id) {
if($term == 'cat') {
$term_meta = gdk_str2arr(category_description($id),'<br />');
$term_meta = gdk_str2arr(category_description($id),'@@');
} elseif($term == 'tag') {
$term_meta = gdk_str2arr(tag_description($id),'<br />');
$term_meta = gdk_str2arr(tag_description($id),'@@');
} else {
return false;
}
@ -1081,9 +1081,7 @@ function payjs_notify() {
//充值按钮
function buy_points(){
if(is_user_logged_in()) {//logined
$result = '
<a data-fancybox="pay_fancybox" data-src="#pay_fancybox" href="javascript:;" class="button">点击充值</a>
<form id="pay_fancybox" name="pay_form" style="display: none; width: 100%; max-width: 500px;" class="pure-form">

View file

@ -1,180 +1,32 @@
<?php
if (!function_exists('nc_filter_document_title_separator')):
add_filter('document_title_separator', 'nc_filter_document_title_separator', 10, 1);
add_filter('document_title_parts', 'nc_filter_document_title_parts', 10, 1);
add_action('wp_head', 'nc_seo_meta_action', 1);
function nc_filter_document_title_separator($var)
{
$nc_option = get_option('nc_option');
$option_sep = $nc_option['seo_divider'];
$var = isset($option_sep) ? $option_sep : $var;
return trim($var);
};
function nc_filter_document_title_parts($title)
{
$nc_option = get_option('nc_option');
global $paged, $page, $post;
$taxonomy_seo = $nc_option['taxonomy_seo'];
$seo_index_inner = $nc_option['seo_index_inner'];
if (is_home() || is_front_page()) {
$title_home = $seo_index_inner['seo_index_title'];
$title['title'] = (isset($title_home) && !empty($title_home)) ? $title_home : get_bloginfo('name');
} elseif (is_single() || is_page()) {
$post_title = get_post_meta($post->ID, 'seo_title', true);
$title['title'] = (isset($post_title) && !empty($post_title)) ? $post_title : get_the_title($post->ID);
} elseif ($taxonomy_seo && is_category()) {
$term = get_queried_object();
$title_category = get_term_meta($term->term_id, 'taxonomy_title', true);
$title['title'] = (isset($title_category) && !empty($title_category)) ? $title_category : get_cat_name($term->term_id);
} elseif ($taxonomy_seo && is_tag()) {
$term = get_queried_object();
$title_tag = get_term_meta($term->term_id, 'taxonomy_title', true);
$title['title'] = (isset($title_tag) && !empty($title_tag)) ? $title_tag : single_tag_title('', false);
} elseif ($taxonomy_seo && is_tax()) {
$term = get_queried_object();
$title_tag = get_term_meta($term->term_id, 'taxonomy_title', true);
$title['title'] = (isset($title_tag) && !empty($title_tag)) ? $title_tag : single_tag_title('', false);
} elseif (is_author() && ! is_post_type_archive()) {
$author = get_queried_object();
if ($author) {
$title['title'] = $author->display_name;
}
} elseif (is_search()) {
$title['title'] = "搜索结果:".get_query_var('s');
} elseif (is_404()) {
$title['title'] = __('Page not found');
}
return $title;
};
function nc_seo_meta_action()
{
$nc_option = get_option('nc_option');
$pages = get_query_var('page');
$taxonomy_seo = $nc_option['taxonomy_seo'];
$seo_index_inner = $nc_option['seo_index_inner'];
if ((is_single() || is_page()) && $pages < 2) {
global $post;
$post_keywords = get_post_meta($post->ID, 'seo_keywords', true);
$post_desc = get_post_meta($post->ID, 'seo_description', true);
if (empty($single_description_range) || is_numeric($single_description_range)) {
$post_desc_num = 140;
} else {
$post_desc_num = $single_description_range;
}
$seo_manual_des = get_post_meta($post->ID, 'seo_manual_des', true);
$seo_manual_keywords = get_post_meta($post->ID, 'seo_manual_keywords', true);
$tag = '';
$tags = get_the_tags();
if ($tags) {
foreach ($tags as $val) {
$tag.=','.$val->name;
}
}
$tag = ltrim($tag, ',');
$key_meta = isset($post_keywords) ? $post_keywords : '';
$des_meta = isset($post_desc) ? $post_desc : '';
$pt = $post->post_excerpt ? $post->post_excerpt : preg_replace('/\s+/', '', strip_tags(apply_filters('the_content', $post->post_content)));
$excerpt = mb_strimwidth($pt, 0, $post_desc_num, '', get_bloginfo('charset'));
if ((empty($key_meta) || !$seo_manual_keywords) && isset($tag)) {
$keywords = $tag;
} else {
$keywords = $key_meta;
}
if (empty($des_meta) || !$seo_manual_des) {
$description = $excerpt;
} else {
$description = $des_meta;
}
if ($keywords) {
echo '<meta name="keywords" content="'.$keywords.'" />';
echo "\n";
}
if ($description) {
echo '<meta name="description" content="'.esc_attr($description).'" />';
echo "\n";
}
}
if ((is_home() || is_front_page()) && !is_paged()) {
$keywords = $seo_index_inner['seo_index_keywords'];
$description = $seo_index_inner['seo_index_description'];
if ($keywords) {
echo '<meta name="keywords" content="'.$keywords.'" />';
echo "\n";
}
if ($description) {
echo '<meta name="description" content="'.esc_attr(stripslashes($description)).'" />';
echo "\n";
}
}
if ($taxonomy_seo && ((is_category() || is_tag() || is_tax('special')) && !is_paged())) {
$term = get_queried_object();
$keywords = get_term_meta($term->term_id, 'taxonomy_keywords', true);
$description = get_term_meta($term->term_id, 'taxonomy_desc', true);
if ($keywords) {
echo '<meta name="keywords" content="'.$keywords.'" />';
echo "\n";
}
if ($description) {
echo '<meta name="description" content="'.esc_attr(stripslashes($description)).'" />';
echo "\n";
}
}
}
endif;
//加载网站地图xml
if(gdk_option('gdk_sitemap_xml')){
include('sitemap-xml.php');
}
// 屏蔽蜘蛛爬取作者页面
if(gdk_option('gdk_no_author_page')){
function gdk_no_author_page()
{
if (is_author()) {
wp_no_robots();
}
}
add_action('wp_head', 'gdk_no_author_page');
if(gdk_option('gdk_no_author_page')) {
function gdk_no_author_page() {
if (is_author()) {
wp_no_robots();
}
}
add_action('wp_head', 'gdk_no_author_page');
}
//robots.txt优化功能
if(gdk_option('gdk_robots')){
add_filter('robots_txt', 'gdk_robots_txt', 10, 2);
function gdk_robots_txt($robotext)
{
if(gdk_option('gdk_sitemap_xml')){
$sitemap = 'Sitemap: ' . home_url('/sitemap.xml');
} else {
$sitemap = '';
}
$robotext = "User-agent: *
if(gdk_option('gdk_robots')) {
add_filter('robots_txt', 'gdk_robots_txt', 10, 2);
function gdk_robots_txt($robotext) {
if(gdk_option('gdk_sitemap_xml')) {
$sitemap = 'Sitemap: ' . home_url('/sitemap.xml');
} else {
$sitemap = '';
}
$robotext = "User-agent: *
Disallow: /wp-admin/
Disallow: /wp-content/plugins/
Disallow: /wp-includes/
@ -184,29 +36,27 @@ Disallow: /*/feed
Disallow: /attachment/
Disallow: /wp-content/themes/
{$sitemap}";
return $robotext;
}
return $robotext;
}
}
//文章自动内链
if(gdk_option('gdk_tag_link')){
function gdk_tag_link($content)
{
$post_tags = get_the_tags();
if ($post_tags) {
foreach ($post_tags as $tag) {
$link = get_tag_link($tag->term_id);
$keyword = $tag->name;
$cleankeyword = stripslashes($keyword);
$url = '<a target="_blank" href="'.$link.'" title="'.str_replace('%s', addcslashes($cleankeyword, '$'), '查看更多关于%s的文章').'">'.addcslashes($cleankeyword, '$').'</a>';
$regEx = '\'(?!((<.*?)|(<a.*?)))('. $cleankeyword . ')(?!(([^<>]*?)>)|([^>]*?</a>))\'s';
$content = preg_replace($regEx, $url, $content, gdk_option('gdk_tag_num') ?? 5);
}
}
return $content;
}
add_filter('the_content', 'gdk_tag_link', 1);
if(gdk_option('gdk_tag_link')) {
function gdk_tag_link($content) {
$post_tags = get_the_tags();
if ($post_tags) {
foreach ($post_tags as $tag) {
$link = get_tag_link($tag->term_id);
$keyword = $tag->name;
$cleankeyword = stripslashes($keyword);
$url = '<a target="_blank" href="'.$link.'" title="'.str_replace('%s', addcslashes($cleankeyword, '$'), '查看更多关于%s的文章').'">'.addcslashes($cleankeyword, '$').'</a>';
$regEx = '\'(?!((<.*?)|(<a.*?)))('. $cleankeyword . ')(?!(([^<>]*?)>)|([^>]*?</a>))\'s';
$content = preg_replace($regEx, $url, $content, gdk_option('gdk_tag_num') ?? 5);
}
}
return $content;
}
add_filter('the_content', 'gdk_tag_link', 1);
}
// 自动添加nofloow
@ -282,15 +132,15 @@ function gdk_baidu_auto_push() {
if(gdk_option('gdk_seo_img')) {
//给文章图片自动添加alt和title信息
function nc_imagesalt($content) {
function gdk_imagesalt($content) {
global $post;
$pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
$replacement = '<a$1href=$2$3.$4$5 alt="'.strip_tags($post->post_title).'" title="'.strip_tags($post->post_title).'"$6>';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
add_filter('the_content', 'nc_imagesalt');
function nc_image_alt_tag($content) {
add_filter('the_content', 'gdk_imagesalt');
function gdk_image_alt_tag($content) {
global $post;
preg_match_all('/<img (.*?)\/>/', $content, $images);
if(!is_null($images)) {
@ -301,85 +151,96 @@ if(gdk_option('gdk_seo_img')) {
}
return $content;
}
add_filter('the_content', 'nc_image_alt_tag', 99999);
add_filter('the_content', 'gdk_image_alt_tag', 99999);
}
//关键字
function gdk_keywords() {
global $s, $post;
$keywords = '';
if (is_single()) {
if (get_the_tags($post->ID)) {
foreach (get_the_tags($post->ID) as $tag) $keywords.= $tag->name . ', ';
}
foreach (get_the_category($post->ID) as $category) $keywords.= $category->cat_name . ', ';
$keywords = substr_replace($keywords, '', -2);
} elseif (is_home()||is_front_page()) {
$keywords = gdk_option('gdk_keywords');
} elseif (is_tag()) {
$keywords = single_tag_title('', false);
} elseif (is_category()) {
$keywords = single_cat_title('', false);
} elseif (is_search()) {
$keywords = esc_html($s, 1);
} else {
$keywords = trim(wp_title('', false));
}
if ($keywords) {
echo "<meta name=\"keywords\" content=\"$keywords\">\n";
}
global $s, $post;
$keywords = '';
if (is_single()) {
if (get_the_tags($post->ID)) {
foreach (get_the_tags($post->ID) as $tag) $keywords.= $tag->name . ', ';
}
foreach (get_the_category($post->ID) as $category) $keywords.= $category->cat_name . ', ';
$keywords = substr_replace($keywords, '', -2);
} elseif (is_home()||is_front_page()) {
$keywords = gdk_option('gdk_keywords');
} elseif (is_tag()) {
if(in_string(tag_description(),'@@')) {
$keywords = gdk_term_meta('tag','keyword');
} else {
$keywords = single_tag_title('', false);
}
} elseif (is_category()) {
if(in_string(category_description(),'@@')) {
$keywords = gdk_term_meta('cat','keyword');
} else {
$keywords = single_cat_title('', false);
}
} elseif (is_search()) {
$keywords = esc_html($s, 1);
} else {
$keywords = trim(wp_title('', false));
}
if ($keywords) {
echo "<meta name=\"keywords\" content=\"$keywords\">\n";
}
}
add_action('wp_head', 'gdk_keywords');
add_action('wp_head', 'gdk_keywords');
//网站描述
function gdk_description() {
global $s, $post;
$description = '';
$blog_name = get_bloginfo('name');
$excerpt = $post->post_excerpt;
if (is_singular()) {
if (!empty($excerpt)) {
$text = $excerpt;
} else {
$text = strip_shortcodes($post->post_content);
}
$description = trim(str_replace(array(
"\r\n",
"\r",
"\n",
" ",
" "
) , " ", str_replace("\"", "'", strip_tags($text))));
if (!($description)) $description = $blog_name . "-" . trim(wp_title('', false));
} elseif (is_home()||is_front_page()) {
$description = gdk_option('gdk_description'); // 首頁要自己加
} elseif (is_tag()) {
$description = $blog_name . "'" . gdk_term_meta('tag','des') . "'";
} elseif (is_category()) {
$description = trim(strip_tags(gdk_term_meta('cat','des')));
} elseif (is_archive()) {
$description = $blog_name . "'" . trim(wp_title('', false)) . "'";
} elseif (is_search()) {
$description = $blog_name . ": '" . esc_html($s, 1) . "' 的搜索結果";
} else {
$description = $blog_name . "'" . trim(wp_title('', false)) . "'";
}
$description = mb_substr($description, 0, 220, 'utf-8');
echo "<meta name=\"description\" content=\"$description\">\n";
global $s, $post;
$description = '';
$blog_name = get_bloginfo('name');
$excerpt = $post->post_excerpt;
if (is_singular()) {
if (!empty($excerpt)) {
$text = $excerpt;
} else {
$text = strip_shortcodes($post->post_content);
}
$description = trim(str_replace(array(
"\r\n",
"\r",
"\n",
" ",
" "
) , " ", str_replace("\"", "'", strip_tags($text))));
if (!($description)) $description = $blog_name . "-" . trim(wp_title('', false));
} elseif (is_home()||is_front_page()) {
$description = gdk_option('gdk_description');// 首頁要自己加
} elseif (is_tag()) {
if(in_string(tag_description(),'@@')) {
$description = $blog_name . "'" . gdk_term_meta('tag','des') . "'";
} else {
$description = $blog_name . "'" . single_tag_title('', false) . "'";
}
} elseif (is_category()) {
if(in_string(category_description(),'@@')) {
$description = $blog_name . "'" . trim(strip_tags(gdk_term_meta('tag','des')));
} else {
$description = $blog_name . "'" . trim(strip_tags(category_description()));
}
} elseif (is_archive()) {
$description = $blog_name . "'" . trim(wp_title('', false)) . "'";
} elseif (is_search()) {
$description = $blog_name . ": '" . esc_html($s, 1) . "' 的搜索結果";
} else {
$description = $blog_name . "'" . trim(wp_title('', false)) . "'";
}
$description = mb_substr($description, 0, 220, 'utf-8');
echo "<meta name=\"description\" content=\"$description\">\n";
}
add_action('wp_head', 'gdk_description');
add_action('wp_head', 'gdk_description');
//添加Open Graph Meta
function meta_og() {
global $post;
if ( is_single() ) {
if( has_post_thumbnail( $post->ID ) ) {
$img_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail' );
$img_src = gdk_thumbnail_src();
}
$excerpt = strip_tags( $post->post_content );
$excerpt_more = '';
@ -399,8 +260,8 @@ function meta_og() {
<meta property="og:description" content="<?php echo $excerpt; ?>">
<meta property="og:type" content="article">
<meta property="og:url" content="<?php echo the_permalink(); ?>">
<meta property="og:site_name" content="Your Site Name">
<meta property="og:image" content="<?php echo $img_src[0]; ?>">
<meta property="og:site_name" content="<?php echo get_bloginfo('name');?>">
<meta property="og:image" content="<?php $img_src; ?>">
<?php
} else {
return;
@ -409,24 +270,6 @@ function meta_og() {
add_action('wp_head', 'meta_og', 5);
//图片img标签添加alttitle属性
function imagesalt($content){
global $post;
$pattern = "/<img(.*?)src=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
$replacement = '<img$1src=$2$3.$4$5 alt="' . $post->post_title . '" title="' . $post->post_title . '"$6>';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
add_filter('the_content', 'imagesalt');
//图片A标签添加title属性
function aimagesalt($content){
global $post;
$pattern = "/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
$replacement = '<a$1href=$2$3.$4$5 title="' . $post->post_title . '"$6>';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
add_filter('the_content', 'aimagesalt');
//评论分页的seo处理
function gdk_canonical(){