php 开发的内容管理系统
源代码在线查看: keywords.php
/**
* Article management
*
* @copyright The XOOPS project http://www.xoops.org/
* @license http://www.fsf.org/copyleft/gpl.html GNU public license
* @author Taiwen Jiang (phppp or D.J.)
* @since 1.00
* @version $Id$
* @package module::article
*/
// The solution is not ready for HTML yet.
// Another trial: http://aidan.dotgeek.org/lib/?file=function.str_highlight.php
// -- D.J.
/*
* Adapted from
* ------------
* @description Advanced keyword highlighter, keep HTML tags safe.
* @author(s) Bojidar Naydenov a.k.a Bojo (bojo2000@mail.bg) & Antony Raijekov a.k.a Zeos (dev@strategma.bg)
* @country Bulgaria
* @version 2.1
* @copyright GPL
* @access public
*/
if (!defined("XOOPS_ROOT_PATH")) {
exit();
}
include_once dirname(dirname(__FILE__))."/include/vars.php";
mod_loadFunctions("parse", $GLOBALS["artdirname"]);
art_parse_class('
class [CLASS_PREFIX]KeywordsHandler /*extends XoopsObjectHandler*/
{
var $keywords;
var $skip_tags = array("A", "IMG", "PRE", "QUOTE", "CODE",
"H1", "H2", "H3", "H4", "H5", "H6"
); //add here more, if you want to filter them
function init()
{
$this->getKeywords();
if(count($this->keywords)==0) return false;
else return true;
}
function getKeywords()
{
global $xoopsModuleConfig;
static $keywords=array();
if(count($keywords)>0) return $keywords;
$_keywords = art_parseLinks($xoopsModuleConfig["keywords"]);
foreach($_keywords as $_keyword){
$this->keywords[strtolower($_keyword["title"])] = $_keyword["url"];
}
}
function highlighter($matches)
{
if (!in_array(strtoupper($matches[2]),$this->skip_tags))
{
$replace = "keywords[strtolower($matches[3])]."\">".$matches[3]."";
$proceed = preg_replace("#\b(".$matches[3].")\b#si",$replace,$matches[0]);
}
else
{
$proceed = $matches[0];
}
return stripslashes($proceed);
}
function &process(&$text)
{
foreach($this->keywords as $keyword => $rep){
$text = preg_replace_callback("#(]*[\>]*)*\s(".$keyword.")\s(.*?)()*#si",array(&$this, "highlighter"), $text);
}
return $text;
}
}
');
?>