修改后支持设置标签的链接留空,也可以设置标签后缀为/或者.html等
admin/control/setting_control.class.php 搜索
$input['link_tag_end'] = form::get_text('link_tag_end', $cfg['link_tag_end'], '', 'required="required" lay-verify="required"');
修改为
$input['link_tag_end'] = form::get_text('link_tag_end', $cfg['link_tag_end']);
继续搜索
if(empty($link_tag_end)) E(1, lang('link_tag_end_not_empty'));
修改为
//if(empty($link_tag_end)) E(1, lang('link_tag_end_not_empty'));
lecms/control/parseurl_control.class.php 搜索
// 标签URL---------最终统一返回 mid和 name
中间代码是标签路由
// 评论URL
将中间代码替换为
$len = strlen($cfg['link_tag_pre']);
if(substr($uri, 0, $len) == $cfg['link_tag_pre']) {
// 标签后缀为空
if(empty($cfg['link_tag_end'])) {
$newurl = substr($uri, $len);
$_GET['control'] = 'tag';
$_GET['action'] = 'index';
$u_arr = explode('/', $newurl);
$u_arr_count = count($u_arr);
if( $u_arr_count > 2){
core::error404();
}elseif ( $u_arr_count == 2){
preg_match('/^[1-9]\d*$/i', $u_arr[1], $mat);
if(isset($mat[0])){
$_GET['page'] = $u_arr[1];
}else{
core::error404();
}
}
if($cfg['link_tag_type'] == 0){ //标签名
preg_match('/^(\d+)\_(.+)$/i', $newurl, $mat);
if(isset($mat[2])) {
$_GET['mid'] = (int)$mat[1];
$_GET['name'] = $mat['2'];
}else{
$_GET['mid'] = 2;
$_GET['name'] = $u_arr[0];
}
return;
}elseif($cfg['link_tag_type'] == 1){ //标签ID
preg_match("/^(\d+)\_(\d+)$/i", $newurl, $mat);
if(isset($mat[2])) {
$mid = (int)$mat[1];
$tagid = (int)$mat[2];
}else{
$mid = 2;
$tagid = (int)$u_arr[0];
}
empty($tagid) AND core::error404();
$table = isset($cfg['table_arr'][$mid]) ? $cfg['table_arr'][$mid] : '';
if(empty($table) || $mid == 1){
core::error404();
}else{
$tags = $this->cms_content_tag->get_tag_by_table_tagid($table, $tagid);
empty($tags) && core::error404();
$_GET['mid'] = $mid;
$_GET['name'] = $tags['name'];
return;
}
}elseif($cfg['link_tag_type'] == 2){ //加密型标签URL
$newurl = decrypt($u_arr[0]);//解密得到 mid_tagid
preg_match("/^(\d+)\_(\d+)$/i", $newurl, $mat);
if(isset($mat[1]) && isset($mat[2])){
$mid = max(2, $mat[1]);
$table = isset($cfg['table_arr'][$mid]) ? $cfg['table_arr'][$mid] : 'article';
$tagid = (int)$mat[2];
$tags = $this->cms_content_tag->get_tag_by_table_tagid($table, $tagid);
empty($tags) && core::error404();
$_GET['mid'] = $mid;
$_GET['name'] = $tags['name'];
return;
}
}
}else{
// 标签有后缀
$len2 = strlen($cfg['link_tag_end']);
if(substr($uri, -$len2) == $cfg['link_tag_end']) {
$newurl = substr($uri, $len, -$len2);
$_GET['control'] = 'tag';
$_GET['action'] = 'index';
$u_arr = explode('/', $newurl);
$u_arr_count = count($u_arr);
if( $u_arr_count > 2){
core::error404();
}elseif ( $u_arr_count == 2){
preg_match('/^[1-9]\d*$/i', $u_arr[1], $mat);
if(isset($mat[0])){
$_GET['page'] = $u_arr[1];
}else{
core::error404();
}
}
if($cfg['link_tag_type'] == 0){ //标签名
preg_match('/^(\d+)\_(.+)$/i', $newurl, $mat);
if(isset($mat[2])) {
$_GET['mid'] = (int)$mat[1];
$_GET['name'] = $mat['2'];
}else{
$_GET['mid'] = 2;
$_GET['name'] = $u_arr[0];
}
return;
}elseif($cfg['link_tag_type'] == 1){ //标签ID
preg_match("/^(\d+)\_(\d+)$/i", $newurl, $mat);
if(isset($mat[2])) {
$mid = (int)$mat[1];
$tagid = (int)$mat[2];
}else{
$mid = 2;
$tagid = (int)$u_arr[0];
}
empty($tagid) AND core::error404();
$table = isset($cfg['table_arr'][$mid]) ? $cfg['table_arr'][$mid] : '';
if(empty($table) || $mid == 1){
core::error404();
}else{
$tags = $this->cms_content_tag->get_tag_by_table_tagid($table, $tagid);
empty($tags) && core::error404();
$_GET['mid'] = $mid;
$_GET['name'] = $tags['name'];
return;
}
}elseif($cfg['link_tag_type'] == 2){ //加密型标签URL
$newurl = decrypt($u_arr[0]);//解密得到 mid_tagid
preg_match("/^(\d+)\_(\d+)$/i", $newurl, $mat);
if(isset($mat[1]) && isset($mat[2])){
$mid = max(2, $mat[1]);
$table = isset($cfg['table_arr'][$mid]) ? $cfg['table_arr'][$mid] : 'article';
$tagid = (int)$mat[2];
$tags = $this->cms_content_tag->get_tag_by_table_tagid($table, $tagid);
empty($tags) && core::error404();
$_GET['mid'] = $mid;
$_GET['name'] = $tags['name'];
return;
}
}
} else {
//未输入后缀的情况 301重定向到以link_tag_end结尾的URL
header('HTTP/1.1 301 Moved Permanently');
header("Location:".$cfg['webdir'].$uri.$cfg['link_tag_end']);
exit();
}
}
}
修改完成,清理缓存!查看效果。
特别声明:本站所有资源均为学习测试使用,请在下载后48小时之内自主删除,本站以学习为目的不承担任何法律责任!
评论(0)