时间,渐渐带走了年少轻狂,也慢慢沉淀了冷暖自知。成功的道路上,肯定会有失败;对于失败,我们要正确地看待和对待,不怕失败者,则必成功;怕失败者,则一无是处,会更失败。
最模板主站从dedecms 5.6 升级到5.7, 两周之后百度权重直接消失,还被惩罚了 。找了几天总算是发现到了问题,有个细节地方忘记了,文章内的描文本成全站所有文章都有,部分页还有错误。原来dedecms 升级把 文档关键词换站全站了,害死人!
1. 原本的dedecms是文章内描文本必须是设定的关键词与文档关键词相应对称,两边有才出现描文本。
代码:
/** * 高亮问题修正, 排除alt title <a></a>直接的字符替换 * * @param string $kw * @param string $body * @return string */ function ReplaceKeyword($kw,&$body) { global $cfg_cmspath; $maxkey = 5; $kws = explode(",",trim($kw)); //以分好为间隔符 $i=0; $karr = $kaarr = $GLOBALS['replaced'] = array(); //暂时屏蔽超链接 $body = preg_replace("/(<a(.*))(>)(.*)(<)(\/a>)/isU", '\\1-]-\\4-[-\\6', $body); foreach($kws as $k) { $k = trim($k); if($k!="") { if($i > $maxkey) { break; } $myrow = $this->dsql->GetOne("select * from zuimoban_keywords where keyword='$k' And rpurl<>'' "); if(is_array($myrow)) { $karr[] = $k; $GLOBALS['replaced'][$k] = 0; $kaarr[] = "<a rel="nofollow noopener noreferrer" href='{$myrow['rpurl']}'><u>$k</u></a>"; } $i++; } } $body = preg_replace("/(^|>)([^<]+)(?=<|$)/sUe", "_highlight('\\2', \$karr, \$kaarr, '\\1')", $body); //恢复超链接 $body = preg_replace("/(<a(.*))-\]-(.*)-\[-(\/a>)/isU", '\\1>\\3<\\4', $body); return $body; } |
function ReplaceKeyword($kw,&$body) { global $cfg_cmspath; $maxkey = 5; $kws = explode(",",trim($kw)); //以分好为间隔符 $i=0; $karr = $kaarr = $GLOBALS['replaced'] = array(); //暂时屏蔽超链接 $body = preg_replace("#(<a(.*))(>)(.*)(<)(\/a>)#isU", '\\1-]-\\4-[-\\6', $body); /* foreach($kws as $k) { $k = trim($k); if($k!="") { if($i > $maxkey) { break; } $myrow = $this->dsql->GetOne("SELECT * FROM zuimoban_keywords WHERE keyword='$k' AND rpurl<>'' "); if(is_array($myrow)) { $karr[] = $k; $GLOBALS['replaced'][$k] = 0; $kaarr[] = "<a rel="nofollow noopener noreferrer" href='{$myrow['rpurl']}'><u>$k</u></a>"; } $i++; } } */ $query = "SELECT * FROM zuimoban_keywords WHERE rpurl<>'' ORDER BY rank DESC"; $this->dsql->SetQuery($query); $this->dsql->Execute(); while($row = $this->dsql->GetArray()) { $key = trim($row['keyword']); $key_url=trim($row['rpurl']); $karr[] = $key; $kaarr[] = "<a rel="nofollow noopener noreferrer" href='$key_url' target='_blank'><u>$key</u></a>"; } // 这里可能会有错误 $body = @preg_replace("#(^|>)([^<]+)(?=<|$)#sUe", "_highlight('\\2', \$karr, \$kaarr, '\\1')", $body); //恢复超链接 $body = preg_replace("#(<a(.*))-\]-(.*)-\[-(\/a>)#isU", '\\1>\\3<\\4', $body); return $body; } |
本文升级到dedecms 5.7文档关键词代码部分细节警示到此结束。到不了的就是永远、忘不了的就是曾经。小编再次感谢大家对我们的支持!