Discuz教程网

☆小BUG(002)——必须重视DZ关于搜索引擎优化的一个BUG

[复制链接]
authicon zxaDFEp 发表于 2013-6-6 16:34:28 | 显示全部楼层 |阅读模式
主要分析DZ底层关于获取后台设置的模块关键字和描述,对于搜索引擎优化非常重要。

154522jx0900odod0tnxr0.jpg




如图所示,在helper_seo类的获取seo设置方法get_seosetting里面。或者看下面代码颜色标注段。
蓝色的是获取title,只要不为空就可以获取。

if($titletext) {
$seotitle = helper_seo::strreplace_strip_split($searchs, $replaces, $titletext);
}

if($descriptiontext && (CURSCRIPT == 'forum' || IS_ROBOT || $_G['adminid'] == 1)) {
$seodescription = helper_seo::strreplace_strip_split($searchs, $replaces, $descriptiontext);
}
if($keywordstext && (CURSCRIPT == 'forum' || IS_ROBOT || $_G['adminid'] == 1)) {
$seokeywords = helper_seo::strreplace_strip_split($searchs, $replaces, $keywordstext);
}

红色的是获取keyword和description,为什么在获取title时,可以直接获取,而在获取keyword和description时就需要其他的判断条件呢?

CURSCRIPT == 'forum' || IS_ROBOT || $_G['adminid'] == 1

多出的这一句判断条件到底有什么作用?如果当前脚本模块是forum或者是爬虫或者是管理员,就可以获取keyword和description,爬虫还好理解。但是,如果当前脚本模块是forum之外的同时不是爬虫或者管理员就不能正常获取后台设置的keyword和description了。

我的问题:能不能把这一句去掉呢,就是所有页面都可以获取keyword和description,有没有什么坏处呢?
  1. public static function get_seosetting($page, $data = array(), $defset = array()) {
  2. global $_G;
  3. $searchs = array('{bbname}');
  4. $replaces = array($_G['setting']['bbname']);
  5. $seotitle = $seodescription = $seokeywords = '';
  6. $titletext = $defset['seotitle'] ? $defset['seotitle'] : $_G['setting']['seotitle'][$page];
  7. $descriptiontext = $defset['seodescription'] ? $defset['seodescription'] : $_G['setting']['seodescription'][$page];
  8. $keywordstext = $defset['seokeywords'] ? $defset['seokeywords'] : $_G['setting']['seokeywords'][$page];
  9. preg_match_all("/{([a-z0-9_-]+?)}/", $titletext.$descriptiontext.$keywordstext, $pageparams);
  10. if($pageparams) {
  11. foreach($pageparams[1] as $var) {
  12. $searchs[] = '{'.$var.'}';
  13. if($var == 'page') {
  14. $data['page'] = $data['page'] > 1 ? lang('core', 'page', array('page' => $data['page'])) : '';
  15. }
  16. $replaces[] = $data[$var] ? strip_tags($data[$var]) : '';
  17. }
  18. if($titletext) {
  19. $seotitle = helper_seo::strreplace_strip_split($searchs, $replaces, $titletext);
  20. }
  21. if($descriptiontext && (CURSCRIPT == 'forum' || IS_ROBOT || $_G['adminid'] == 1)) {
  22. $seodescription = helper_seo::strreplace_strip_split($searchs, $replaces, $descriptiontext);
  23. }
  24. if($keywordstext && (CURSCRIPT == 'forum' || IS_ROBOT || $_G['adminid'] == 1)) {
  25. $seokeywords = helper_seo::strreplace_strip_split($searchs, $replaces, $keywordstext);
  26. }
  27. }
  28. return array($seotitle, $seodescription, $seokeywords);
  29. }
  30. [code]<blockquote>
复制代码



上一篇:(已解决 )3.0伪静态设置不成功。
下一篇:刚刚修改了一个文件后保存了 打开网站全站乱码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-15 15:03

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

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