我的PHP之旅
解决多模板图片样式表的问题
post by:风子 2012-1-30 17:40

用smarty插件,

function smarty_prefilter_chpath($tpl_source,&$smarty)
{
/*这个会将绝对路径也修正,不对
    return preg_replace("/(<(img.*?src|link.*?href|script.*?src)=([\"']))(.*?)(\\3.*?>)/is","$1".SKINTPL."$4$5",$tpl_source);
    */
    /*这个会将js也修正
    return preg_replace("/(<(img.*?src|link.*?href|script.*?src)=([\"']))(([^(http:\/\/)])(.*?))(\\3.*?>)/is","$1".SKINTPL."$5$6$7",$tpl_source);
    */

    /*这个不修正js */
    return preg_replace("/(<(img.*?src|link.*?href)=([\"']))(([^(http:\/\/)])(.*?))(\\3.*?>)/is","$1".SKINTPL."$5$6$7",$tpl_source);
}

文件取名prefilter.chpath.php,放到plugins,用 $smarty->load_filter('pre','chpath');就行了

最新修改此函数如下:

function smarty_prefilter_chpath($tpl_source,&$smarty)
{
/*
    return preg_replace("/(<(img.*?src|link.*?href|script.*?src)=([\"']))(.*?)(\\3.*?>)/is","$1".SKINTPL."$4$5",$tpl_source);
    */
    /*
    return preg_replace("/(<(img.*?src|link.*?href|script.*?src)=([\"']))(([^(http:\/\/)])(.*?))(\\3.*?>)/is","$1".SKINTPL."$5$6$7",$tpl_source);
    */
    /*
    return preg_replace("/(<(img.*?src|link.{1,100}href)=([\"']))(([^(http:\/\/|\{\$imgurl\})])(.*?))(\\3.*?>)/is","$1".SKINTPL."$5$6$7",$tpl_source);
    */
    return preg_replace("/(<(img.*?src|link.{1,100}href)=([\"']))(images|style)(.*?)(\\3.*?>)/is","$1".SKINTPL."$4$5$6",$tpl_source);
}

评论:
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容