主要分析DZ底层关于获取后台设置的模块关键字和描述,对于搜索引擎优化非常重要。
如图所示,在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,有没有什么坏处呢?- public static function get_seosetting($page, $data = array(), $defset = array()) {
-
- global $_G;
- $searchs = array('{bbname}');
- $replaces = array($_G['setting']['bbname']);
- $seotitle = $seodescription = $seokeywords = '';
- $titletext = $defset['seotitle'] ? $defset['seotitle'] : $_G['setting']['seotitle'][$page];
- $descriptiontext = $defset['seodescription'] ? $defset['seodescription'] : $_G['setting']['seodescription'][$page];
- $keywordstext = $defset['seokeywords'] ? $defset['seokeywords'] : $_G['setting']['seokeywords'][$page];
- preg_match_all("/{([a-z0-9_-]+?)}/", $titletext.$descriptiontext.$keywordstext, $pageparams);
- if($pageparams) {
- foreach($pageparams[1] as $var) {
- $searchs[] = '{'.$var.'}';
- if($var == 'page') {
- $data['page'] = $data['page'] > 1 ? lang('core', 'page', array('page' => $data['page'])) : '';
- }
- $replaces[] = $data[$var] ? strip_tags($data[$var]) : '';
- }
- 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);
- }
- }
- return array($seotitle, $seodescription, $seokeywords);
- }
- [code]<blockquote>
复制代码 |