解决多模板图片样式表的问题
2012-1-30 17:40 Monday  

分类: PHP 评论(37) 浏览(22445)

用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);
}

+1 13

留下你的看法: