找回密码
 立即注册

只需一扫,快速开始

QQ登录

只需一步,快速开始

搜索
查看: 18371|回复: 0

[技术经验] Discuz! X3.1 3.2 3.0门户关键词keyword与描述description查看源码不显示的解决方案

[复制链接]

8万

主题

431

回帖

9万

积分

管理员

积分
94388
QQ
发表于 2015-10-22 10:57:22 | 显示全部楼层 |阅读模式
原因是逻辑有bug

修改文件路径:
  1. source/class/helper/helper_seo.php
复制代码


查找:
  1. if($descriptiontext && (isset($_G['makehtml']) || CURSCRIPT == 'forum' || IS_ROBOT || $_G['adminid'] == 1)) {
复制代码
修改为:
  1. if($descriptiontext && (isset($_G['makehtml']) || CURSCRIPT == 'forum' || CURSCRIPT == 'portal' || IS_ROBOT || $_G['adminid'] == 1)){
复制代码


查找:
  1. if($keywordstext && (isset($_G['makehtml']) || CURSCRIPT == 'forum' || IS_ROBOT || $_G['adminid'] == 1)) {
复制代码


修改为:
  1. if($keywordstext && (isset($_G['makehtml']) || CURSCRIPT == 'forum' || CURSCRIPT == 'portal' || IS_ROBOT || $_G['adminid'] == 1)) {
复制代码


实际上就是增加了  IS_ROBOT  的常量,判断是否只蜘蛛。






修改后的代码是(适合3.2版本):
  1. <?php

  2. /**
  3. *      [Discuz!] (C)2001-2099 Comsenz Inc.
  4. *      This is NOT a freeware, use is subject to license terms
  5. *
  6. *      $Id: helper_seo.php 32836 2013-03-14 08:10:02Z zhangguosheng $
  7. */

  8. if(!defined('IN_DISCUZ')) {
  9.         exit('Access Denied');
  10. }

  11. class helper_seo {


  12.         public static function get_seosetting($page, $data = array(), $defset = array()) {
  13.                 global $_G;
  14.                 $searchs = array('{bbname}');
  15.                 $replaces = array($_G['setting']['bbname']);

  16.                 $seotitle = $seodescription = $seokeywords = '';
  17.                 $titletext = $defset['seotitle'] ? $defset['seotitle'] : $_G['setting']['seotitle'][$page];
  18.                 $descriptiontext = $defset['seodescription'] ? $defset['seodescription'] : $_G['setting']['seodescription'][$page];
  19.                 $keywordstext = $defset['seokeywords'] ? $defset['seokeywords'] : $_G['setting']['seokeywords'][$page];
  20.                 preg_match_all("/\{([a-z0-9_-]+?)\}/", $titletext.$descriptiontext.$keywordstext, $pageparams);
  21.                 if($pageparams) {
  22.                         foreach($pageparams[1] as $var) {
  23.                                 $searchs[] = '{'.$var.'}';
  24.                                 if($var == 'page') {
  25.                                         $data['page'] = $data['page'] > 1 ? lang('core', 'page', array('page' => $data['page'])) : '';
  26.                                 }
  27.                                 $replaces[] = $data[$var] ? strip_tags($data[$var]) : '';
  28.                         }
  29.                         if($titletext) {
  30.                                 $seotitle = helper_seo::strreplace_strip_split($searchs, $replaces, $titletext);
  31.                         }
  32.                          //if($descriptiontext && (isset($_G['makehtml']) || CURSCRIPT == 'forum' || IS_ROBOT || $_G['adminid'] == 1)) {
  33.                           if($descriptiontext && (isset($_G['makehtml']) || CURSCRIPT == 'forum' || CURSCRIPT == 'portal' || IS_ROBOT || $_G['adminid'] == 1)){
  34.                                 $seodescription = helper_seo::strreplace_strip_split($searchs, $replaces, $descriptiontext);
  35.                         }
  36.                          //if($keywordstext && (isset($_G['makehtml']) || CURSCRIPT == 'forum' || IS_ROBOT || $_G['adminid'] == 1)) {
  37.                           if($keywordstext && (isset($_G['makehtml']) || CURSCRIPT == 'forum' || CURSCRIPT == 'portal' || IS_ROBOT || $_G['adminid'] == 1)) {
  38.                                 $seokeywords = helper_seo::strreplace_strip_split($searchs, $replaces, $keywordstext);
  39.                         }
  40.                 }
  41.                 return array($seotitle, $seodescription, $seokeywords);
  42.         }


  43.         public static function strreplace_strip_split($searchs, $replaces, $str) {
  44.                 $searchspace = array('((\s*\-\s*)+)', '((\s*\,\s*)+)', '((\s*\|\s*)+)', '((\s*\t\s*)+)', '((\s*_\s*)+)');
  45.                 $replacespace = array('-', ',', '|', ' ', '_');
  46.                 return trim(preg_replace($searchspace, $replacespace, str_replace($searchs, $replaces, $str)), ' ,-|_');
  47.         }

  48.         public static function get_title_page($navtitle, $page){
  49.                 if($page > 1) {
  50.                         $navtitle .= ' - '.lang('core', 'page', array('page' => $page));
  51.                 }
  52.                 return $navtitle;
  53.         }

  54.         public static function get_related_link($extent) {
  55.                 global $_G;
  56.                 loadcache('relatedlink');
  57.                 $allextent = array('article' => 0, 'forum' => 1, 'group' => 2, 'blog' => 3);
  58.                 $links = array();
  59.                 if($_G['cache']['relatedlink'] && isset($allextent[$extent])) {
  60.                         foreach($_G['cache']['relatedlink'] as $link) {
  61.                                 $link['extent'] = sprintf('%04b', $link['extent']);
  62.                                 if($link['extent'][$allextent[$extent]] && $link['name'] && $link['url']) {
  63.                                         $links[] = daddslashes($link);
  64.                                 }
  65.                         }
  66.                 }
  67.                 rsort($links);
  68.                 return $links;
  69.         }

  70.         public static function parse_related_link($content, $extent) {
  71.                 global $_G;
  72.                 loadcache('relatedlink');
  73.                 $allextent = array('article' => 0, 'forum' => 1, 'group' => 2, 'blog' => 3);
  74.                 if($_G['cache']['relatedlink'] && isset($allextent[$extent])) {
  75.                         $searcharray = $replacearray = array();
  76.                         foreach($_G['cache']['relatedlink'] as $link) {
  77.                                 $link['extent'] = sprintf('%04b', $link['extent']);
  78.                                 if($link['extent'][$allextent[$extent]] && $link['name'] && $link['url']) {
  79.                                         $searcharray[$link[name]] = '/('.preg_quote($link['name']).')/i';
  80.                                         $replacearray[$link[name]] = "<a href="$link[url]" target="_blank" class="relatedlink">$link[name]</a>";
  81.                                 }
  82.                         }
  83.                         if($searcharray && $replacearray) {
  84.                                 $_G['trunsform_tmp'] = array();
  85.                                
  86.                                
  87.                                 $content = preg_replace("/(<script\s+.*?>.*?<\/script>)|(<a\s+.*?>.*?<\/a>)|(<img\s+.*?[\/]?>)|(\[attach\](\d+)\[\/attach\])/ies", "helper_seo::base64_transform('encode', '<relatedlink>', '\\1\\2\\3\\4', '</relatedlink>')", $content);
  88.                                 $content = preg_replace($searcharray, $replacearray, $content, 1);
  89.                                 $content = preg_replace("/<relatedlink>(.*?)<\/relatedlink>/ies", "helper_seo::base64_transform('decode', '', '\\1', '')", $content);
  90.                         }
  91.                 }
  92.                 return $content;
  93.         }


  94.         public static function base64_transform($type, $prefix, $string, $suffix) {
  95.                 global $_G;
  96.                 if($type == 'encode') {
  97.                         $_G['trunsform_tmp'][] = base64_encode(str_replace("\\"", """, $string));
  98.                         return $prefix.(count($_G['trunsform_tmp']) - 1).$suffix;
  99.                 } elseif($type == 'decode') {
  100.                         return $prefix.base64_decode($_G['trunsform_tmp'][$string]).$suffix;
  101.                 }
  102.         }
  103. }

  104. ?>
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册   

本版积分规则

QQ|Archiver|手机版|小黑屋|站秘书 ( 蜀ICP备15034504号-3 )

GMT+8, 2024-5-3 16:04 , Processed in 0.082705 second(s), 40 queries .

Powered by Discuz! X3.5

Copyright © 2001-2024 Tencent Cloud.

快速回复 返回顶部 返回列表