Skip to content

Commit

Permalink
Merge pull request #400 from Lvshujun0918/master
Browse files Browse the repository at this point in the history
一些小优化,详见commit
  • Loading branch information
Licoy authored Apr 26, 2024
2 parents 15395f0 + 3b00b99 commit decf6ac
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 40 deletions.
81 changes: 81 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,87 @@ function pk_breadcrumbs()
return $out;
}

/**
* 返回图标信息
*
* @return string
* @author lvshujun
* @date 2024-03-19
*/
function pk_icon_mate() {
//获取icon地址
$pk_icon = pk_get_option('favicon');
//未设置返回空
if ($pk_icon === '') return '';

//连接字符串
$str = '<link rel="shortcut icon" href="' . $pk_icon . '">
<link rel="apple-touch-icon" href="' . $pk_icon . '"/>';

return $str;
}

/**
* 输出SEO标题
*
* @return string SEO标题
* @author lvshujun
* @date 2024-03-19
*/
function pk_get_seo_title() {
// 未启用SEO返回空
if (!pk_is_checked('seo_open',true)) {
return '';
}
// 用户定义的连接符
$pk_title_conn = ' ' . pk_get_option("title_conn") . ' ';
// 网站名称
$pk_blog_name = pk_get_web_title();
// 分页情况
$pk_paged_title = '';
if (get_query_var('paged')) {
$pk_paged_title = $pk_title_conn . '' . get_query_var('paged') . '';
}
// 获取SEO设置
$pk_custom_seo_title = pk_get_custom_seo()['title'] ?? '';
// 输出内容
$pk_title = '';
// 通用结尾
$pk_common_end = $pk_paged_title . $pk_title_conn . $pk_blog_name;
// 已经自定义标题
if (!empty($pk_custom_seo_title)) {
$pk_title .= $pk_custom_seo_title . $pk_common_end;
} else if (is_home()) {
$pk_description = pk_get_option('web_title_2');
if (!empty($pk_description)) {
$pk_title .= $pk_blog_name . $pk_paged_title . $pk_title_conn . $pk_description;
} else {
$pk_title .= $pk_blog_name . $pk_paged_title;
}
} else if (is_search()) {
$pk_title .= '搜索“' . $_REQUEST['s'] . '”的结果' . $pk_common_end;
} else if (is_single() || is_page()) {
$pk_title .= single_post_title('', false) . $pk_common_end;
} else if (is_year()) {
$pk_title .= get_the_time('Y年') . '的所有文章' . $pk_common_end;
} else if (is_month()) {
$pk_title .= get_the_time('m') . '的所有文章' . $pk_common_end;
} else if (is_day()) {
$pk_title .= get_the_time('Y年m月d日') . '的所有文章' . $pk_common_end;
} else if (is_author()) {
$pk_title .= '作者:' . get_the_author() . $pk_common_end;
} else if (is_category()) {
$pk_title .= single_cat_title('', false) . $pk_common_end;
} else if (is_tag()) {
$pk_title .= single_tag_title('', false) . $pk_common_end;
} else if (is_404()) {
$pk_title .= '你访问的资源不存在' . $pk_common_end;
} else {
$pk_title .= $pk_blog_name . $pk_paged_title;
}
return '<title>'.$pk_title.'</title>';
}

//获取阅读数量
function pk_get_post_views()
{
Expand Down
4 changes: 2 additions & 2 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta http-equiv='content-language' content='<?php echo get_locale() ?>'>
<link rel="shortcut icon" href="<?php echo pk_get_option('favicon') ?>">
<link rel="apple-touch-icon" href="<?php echo pk_get_option('favicon') ?>"/>
<?php echo pk_icon_mate(); ?>
<?php echo pk_get_seo_title(); ?>
<?php if(pk_is_checked('seo_open',true)) get_template_part('inc/seo') ?>
<?php wp_head(); ?>
<?php if (!empty(pk_get_option('tj_code_header', ''))): ?>
Expand Down
29 changes: 28 additions & 1 deletion inc/fun/opt.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,37 @@ function pk_go_link($url, $name = '')
return $url;
}

//开启了内页链接跳转
if (pk_is_checked('link_go_page')) {
/**
* 内页跳转链接
*
* @param string $content 修改前的内容
* @return string 修改后的内容
* @author lvshujun
* @date 2024-03-19
*/
function pk_content_addlink($content) {
//匹配链接
preg_match_all('/<a(.*?)href="(.*?)"(.*?)>/',$content,$matches);
if ($matches) {
foreach ($matches[2] as $val) {
if (strpos($val,'://') !== false
&& pk_is_cur_site($val) === false
&& !preg_match('/\.(jpg|jepg|png|ico|bmp|gif|tiff)/i',$val)) {
$content = str_replace('href="'.$val.'"', 'href="'.pk_go_link($val).'"', $content);
}
}
}
return $content;
}
add_filter('the_content', 'pk_content_addlink');
}

//检测链接是否属于本站
function pk_is_cur_site($url)
{
if (strpos($url, home_url()) === 0) {
if (str_starts_with($url, home_url()) === 0) {
return true;
}
return false;
Expand Down
10 changes: 4 additions & 6 deletions inc/go.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

include '../../../../wp-blog-header.php';
pk_set_custom_seo("链接跳转");
$url = @$_GET['to'];
$name = @$_GET['name'];
$url = $_GET['to'] ?? '';
$name = $_GET['name'] ?? '';
if (!empty($name)) {
$name = base64_decode(str_replace(' ','+',$name));
}
Expand All @@ -15,7 +15,7 @@
if (strpos($url, "https://") !== 0 && strpos($url, "http://") !== 0) {
$error = "跳转链接协议有误";
} else {
if (strpos($url, home_url()) === 0) {
if (pk_is_cur_site($url)) {
header("Location:" . $url);
exit();
}
Expand All @@ -37,9 +37,7 @@
<p class="mt20"><?php echo $error ?></p>
<?php else: ?>
<p class="mt20">
<span>您即将离开<?php echo get_bloginfo('name') ?>跳转至</span>
<a class="a-link text-line" rel="nofollow"
href="<?php echo $url ?>"><?php echo empty($name) ? $url : $name; ?></a><span> ,确定进入吗?</span>
<span>您即将离开<?php echo get_bloginfo('name') ?>跳转至</span><?php echo empty($name) ? $url : $name; ?><span> ,确定进入吗?</span>
</p>
<?php endif; ?>
<div class="text-center mt20">
Expand Down
31 changes: 0 additions & 31 deletions inc/seo.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,3 @@
<?php $titleConn = " " . pk_get_option("title_conn") . " " ?>
<?php $blog_name = pk_get_web_title();
$pkSeoPageInfo = ''; ?>
<?php
$custom_seo = pk_get_custom_seo();
$custom_seo_title = $custom_seo['title'] ?? '';
if (get_query_var('paged')) {
$pkSeoPageInfo = $titleConn . '' . get_query_var('paged') . '';
}
if (!empty($custom_seo_title)) { ?>
<title><?php echo $custom_seo['title'] . $pkSeoPageInfo . $titleConn . $blog_name; ?></title>
<?php } else if (is_home()) { ?>
<title><?php echo $blog_name . $pkSeoPageInfo . (pk_get_option('web_title_2') ? $titleConn . pk_get_option('web_title_2') : ''); ?></title>
<?php } else if (is_search()) { ?><title>搜索"<?php echo $_REQUEST['s'] ?>
"的结果<?php echo $titleConn . $pkSeoPageInfo . $blog_name ?></title>
<?php } else if (is_single() || is_page()) { ?>
<title><?php echo trim(wp_title('', 0)); ?><?php echo $titleConn . $blog_name; ?></title>
<?php } else if (is_year()) { ?><title><?php the_time('Y年'); ?>
的所有文章 <?php echo $pkSeoPageInfo . $titleConn . $blog_name ?></title>
<?php } else if (is_month()) { ?><title><?php the_time('m'); ?>
份的所有文章 <?php echo $pkSeoPageInfo . $titleConn . $blog_name ?></title>
<?php } else if (is_day()) { ?><title><?php the_time('Y年m月d日'); ?>
的所有文章 <?php echo $pkSeoPageInfo . $titleConn . $blog_name ?></title>
<?php } else if (is_author()) { ?><title><?php the_author(); ?>
<?php echo $pkSeoPageInfo . $titleConn . $blog_name ?></title>
<?php } else if (is_category()) { ?>
<title><?php single_cat_title(); ?><?php echo $pkSeoPageInfo . $titleConn . $blog_name ?> </title>
<?php } else if (is_tag()) { ?>
<title><?php single_tag_title("", true); ?><?php echo $pkSeoPageInfo . $titleConn . $blog_name; ?></title>
<?php } else if (is_404()) { ?> <title>你访问的资源不存在<?php echo $pkSeoPageInfo . $titleConn . $blog_name; ?></title>
<?php } else { ?> <title><?php echo $blog_name . $pkSeoPageInfo . $titleConn . $blog_name; ?></title><?php } ?>
<?php if (is_home()) : ?>
<meta name="keywords" content="<?php echo pk_get_option('keyword') ?>"/>
<meta name="description" content="<?php echo pk_get_option('description') ?>"/>
Expand Down
6 changes: 6 additions & 0 deletions inc/setting/options/OptionBasic.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ function get_fields(): array
'type' => 'switch',
'sdt' => 'false',
],
[
'id' => 'link_go_page',
'label' => __('正文内容链接加跳转', PUOCK),
'type' => 'switch',
'sdt' => 'false',
],
[
'id' => 'use_post_menu',
'label' => __('正文内容侧边目录菜单生成', PUOCK),
Expand Down

0 comments on commit decf6ac

Please sign in to comment.