实现v9内容页url规则增加汉字拼音功能

效果如下:
当你的内容标题为  绿色软件  时,链接地址里将带上 lvseruanjian .

实现过程:

修改 modules/content/classes/url.class.php 文件的 public function show()  函数为如下代码:

 
 public function show($id, $page = 0, $catid = 0, $time = 0, $prefix = '',$data = '',$action = 'edit') {
  $page = max($page,1);
  $urls = $catdir = '';
  $category = $this->categorys[$catid];
  $setting = string2array($category['setting']);
  $content_ishtml = $setting['content_ishtml'];
  $show_ruleid = $setting['show_ruleid'];
  $urlrules = $this->urlrules[$show_ruleid];
  if(!$time) $time = SYS_TIME;
  $urlrules_arr = explode('|',$urlrules);
  if($page==1) {
   $urlrule = $urlrules_arr[0];
  } else {
   $urlrule = $urlrules_arr[1];
  }
  if (strpos($category['url'], '://')!==false && strpos($category['url'], '?')===false) {
   if (preg_match('/^((http|https):\/\/)?([^\/]+)/i', $category['url'], $matches)) {
    $url = $matches[0].'/';
   }
   $db = pc_base::load_model('category_model');
   $r = $db->get_one(array('url'=>$url), '`catid`');
   $domain_dir = $this->get_categorydir($r['catid']).$this->categorys[$r['catid']]['catdir'].'/';
  }
  $categorydir = $this->get_categorydir($catid);
  $catdir = $category['catdir'];
  $year = date('Y',$time);
  $month = date('m',$time);
  $day = date('d',$time);
//add 开始
      pc_base::load_sys_func('iconv');
 $modelid = $category['modelid'];
 if(!$modelid) return '';
 $db = pc_base::load_model('content_model');
 $db->set_model($modelid);
      $r = $db->get_one(array('id'=>$id), '`title`');
      $pinyin = gbk_to_pinyin($r['title']);
      if(is_array($pinyin)) {
      $pinyin = implode('', $pinyin);
      }
//end 结束
  $urls = str_replace(array('{$categorydir}','{$catdir}','{$year}','{$month}','{$day}','{$catid}','{$id}','{$page}','{$pinyin}'),array($categorydir,$catdir,$year,$month,$day,$catid,$id,$page,$pinyin),$urlrule);
  $create_to_html_root = $category['create_to_html_root'];
  if(preg_match("/^(http:\/\/)?([^\/]+)/i", $category['url'],$_match)) {
   if($category['parentid'] && $_match[0]) {
    foreach ($this->categorys as $_key=>$_value) {
     if($_value['create_to_html_root'] && $_value['url']==$_match[0].'/') $create_to_html_root = 1;
    }
   }
  }
  
  if($create_to_html_root) {
   $html_root = '';
  } else {
   $html_root = $this->html_root;
  }
  
  if($content_ishtml && $url) {
   if (strpos($urls, $domain_dir)!==false) {
    $url_arr[1] = $html_root.'/'.$urls;
    $url_arr[0] = str_replace($domain_dir, $url, $urls);
   } else {
    $url_arr[1] = $html_root.'/'.$domain_dir.$urls;
    $url_arr[0] = WEB_PATH == '/' ? $url.$urls : substr(WEB_PATH,0,-1).$url.$urls;
   }
  } elseif($content_ishtml) {
   $url_arr[0] = WEB_PATH == '/' ? $html_root.'/'.$urls : substr(WEB_PATH,0,-1).$html_root.'/'.$urls;
   $url_arr[1] = $html_root.'/'.$urls;
  } else {
   $url_arr[0] = $url_arr[1] = APP_PATH.$urls;
  }
  //生成静态 ,在添加文章的时候,同时生成静态,不在批量更新URL处调用
  if($content_ishtml && $data) {
   $html = pc_base::load_app_class('html', 'content');
   $data['id'] = $id;
   $html->show($url_arr[1],$data);
   //在添加和修改内容处定义了 INDEX_HTML
   if(defined('INDEX_HTML')) $html->index();
   if(defined('RELATION_HTML')) $html->create_relation_html($catid);
  }
  
  return $url_arr;
 }


可以自己对比原来函数,只是中间增加了一段代码.

然后就可以在url规则里使用 {$pinyin} 这个url标志了.注意是内容规则(show),不适用栏目url.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值