Exemplo n.º 1
0
 function smarty_prefilter_preCompile($source)
 {
     $file_type = strtolower(strrchr($this->_current_file, '.'));
     $tmp_dir = 'themes/' . $GLOBALS['_CFG']['template'] . '/';
     // 模板所在路径
     /**
      * 处理模板文件
      */
     if ($file_type == '.dwt') {
         /* 将模板中所有library替换为链接 */
         $pattern = '/<!--\\s#BeginLibraryItem\\s\\"\\/(.*?)\\"\\s-->.*?<!--\\s#EndLibraryItem\\s-->/s';
         $replacement = "'{include file='.strtolower('\\1'). '}'";
         $source = preg_replace_callback($pattern, create_function('$math', ' 
             $temp = strtolower($math[1]);
             return "{include file={$temp}}";
          '), $source);
         //$source      = preg_replace($pattern, $replacement, $source);
         /* 检查有无动态库文件,如果有为其赋值 */
         $dyna_libs = get_dyna_libs($GLOBALS['_CFG']['template'], $this->_current_file);
         if ($dyna_libs) {
             foreach ($dyna_libs as $region => $libs) {
                 $pattern = '/<!--\\s*TemplateBeginEditable\\sname="' . $region . '"\\s*-->(.*?)<!--\\s*TemplateEndEditable\\s*-->/s';
                 if (preg_match($pattern, $source, $reg_match)) {
                     $reg_content = $reg_match[1];
                     /* 生成匹配字串 */
                     $keys = array_keys($libs);
                     $lib_pattern = '';
                     foreach ($keys as $lib) {
                         $lib_pattern .= '|' . str_replace('/', '\\/', substr($lib, 1));
                     }
                     $lib_pattern = '/{include\\sfile=(' . substr($lib_pattern, 1) . ')}/';
                     /* 修改$reg_content中的内容 */
                     $GLOBALS['libs'] = $libs;
                     $reg_content = preg_replace_callback($lib_pattern, 'dyna_libs_replace', $reg_content);
                     /* 用修改过的内容替换原来当前区域中内容 */
                     $source = preg_replace($pattern, $reg_content, $source);
                 }
             }
         }
         /* 在头部加入版本信息 */
         $source = preg_replace('/<head>/i', "<head>\r\n<meta name=\"Generator\" content=\"" . APPNAME . ' ' . VERSION . "\" />", $source);
         /* 修正css路径 */
         $source = preg_replace('/(<link\\shref=["|\'])(?:\\.\\/|\\.\\.\\/)?(css\\/)?([a-z0-9A-Z_]+\\.css["|\']\\srel=["|\']stylesheet["|\']\\stype=["|\']text\\/css["|\'])/i', '\\1' . $tmp_dir . '\\2\\3', $source);
         /* 修正js目录下js的路径 */
         $source = preg_replace('/(<script\\s(?:type|language)=["|\']text\\/javascript["|\']\\ssrc=["|\'])(?:\\.\\/|\\.\\.\\/)?(js\\/[a-z0-9A-Z_\\-\\.]+\\.(?:js|vbs)["|\']><\\/script>)/', '\\1' . $tmp_dir . '\\2', $source);
         /* 更换编译模板的编码类型 */
         $source = preg_replace('/<meta\\shttp-equiv=["|\']Content-Type["|\']\\scontent=["|\']text\\/html;\\scharset=(?:.*?)["|\'][^>]*?>\\r?\\n?/i', '<meta http-equiv="Content-Type" content="text/html; charset=' . EC_CHARSET . '" />' . "\n", $source);
     } elseif ($file_type == '.lbi') {
         /* 去除meta */
         $source = preg_replace('/<meta\\shttp-equiv=["|\']Content-Type["|\']\\scontent=["|\']text\\/html;\\scharset=(?:.*?)["|\']>\\r?\\n?/i', '', $source);
     }
     /* 替换文件编码头部 */
     if (strpos($source, "") !== FALSE) {
         $source = str_replace("", '', $source);
     }
     $pattern = array('/<!--[^>|\\n]*?({.+?})[^<|{|\\n]*?-->/', '/<!--[^<|>|{|\\n]*?-->/', '/(href=["|\'])\\.\\.\\/(.*?)(["|\'])/i', '/((?:background|src)\\s*=\\s*["|\'])(?:\\.\\/|\\.\\.\\/)?(images\\/.*?["|\'])/is', '/((?:background|background-image):\\s*?url\\()(?:\\.\\/|\\.\\.\\/)?(images\\/)/is', '/([\'|"])\\.\\.\\//is');
     $replace = array('\\1', '', '\\1\\2\\3', '\\1' . $tmp_dir . '\\2', '\\1' . $tmp_dir . '\\2', '\\1');
     return preg_replace($pattern, $replace, $source);
 }
Exemplo n.º 2
0
 function smarty_prefilter_preCompile($source)
 {
     $file_type = strtolower(strrchr($this->_current_file, '.'));
     $tmp_dir = 'themes/' . $GLOBALS['_CFG']['template'] . '/';
     // 模板所在路径
     /**
      * 处理模板文件
      */
     if ($file_type == '.dwt') {
         /* 将模板中所有library替换为链接 */
         $pattern = '/<!--\\s#BeginLibraryItem\\s\\"\\/(.*?)\\"\\s-->.*?<!--\\s#EndLibraryItem\\s-->/se';
         $replacement = "'{include file='.strtolower('\\1'). '}'";
         $source = preg_replace($pattern, $replacement, $source);
         /* 检查有无动态库文件,如果有为其赋值 */
         $dyna_libs = get_dyna_libs($GLOBALS['_CFG']['template'], $this->_current_file);
         if ($dyna_libs) {
             foreach ($dyna_libs as $region => $libs) {
                 $pattern = '/<!--\\s*TemplateBeginEditable\\sname="' . $region . '"\\s*-->(.*?)<!--\\s*TemplateEndEditable\\s*-->/s';
                 if (preg_match($pattern, $source, $reg_match)) {
                     $reg_content = $reg_match[1];
                     /* 生成匹配字串 */
                     $keys = array_keys($libs);
                     $lib_pattern = '';
                     foreach ($keys as $lib) {
                         $lib_pattern .= '|' . str_replace('/', '\\/', substr($lib, 1));
                     }
                     $lib_pattern = '/{include\\sfile=(' . substr($lib_pattern, 1) . ')}/';
                     /* 修改$reg_content中的内容 */
                     $GLOBALS['libs'] = $libs;
                     $reg_content = preg_replace_callback($lib_pattern, 'dyna_libs_replace', $reg_content);
                     /* 用修改过的内容替换原来当前区域中内容 */
                     $source = preg_replace($pattern, $reg_content, $source);
                 }
             }
         }
         /* 在头部加入版本信息 */
         $source = preg_replace('/<head>/i', "<head>\r\n<meta name=\"Generator\" content=\"" . APPNAME . ' ' . VERSION . "\" />", $source);
         /* 修正css路径 */
         $source = preg_replace('/(<link\\shref=["|\'])(?:\\.\\/|\\.\\.\\/)?(css\\/)?([a-z0-9A-Z_]+\\.css["|\']\\srel=["|\']stylesheet["|\']\\stype=["|\']text\\/css["|\'])/i', '\\1' . $tmp_dir . '\\2\\3', $source);
         /* 修正js目录下js的路径 */
         $source = preg_replace('/(<script\\s(?:type|language)=["|\']text\\/javascript["|\']\\ssrc=["|\'])(?:\\.\\/|\\.\\.\\/)?(js\\/[a-z0-9A-Z_\\-\\.]+\\.(?:js|vbs)["|\']><\\/script>)/', '\\1' . $tmp_dir . '\\2', $source);
         /* 更换编译模板的编码类型 */
         $source = preg_replace('/<meta\\shttp-equiv=["|\']Content-Type["|\']\\scontent=["|\']text\\/html;\\scharset=(?:.*?)["|\'][^>]*?>\\r?\\n?/i', '<meta http-equiv="Content-Type" content="text/html; charset=' . EC_CHARSET . '" />' . "\n", $source);
     } elseif ($file_type == '.lbi') {
         /* 去除meta */
         $source = preg_replace('/<meta\\shttp-equiv=["|\']Content-Type["|\']\\scontent=["|\']text\\/html;\\scharset=(?:.*?)["|\']>\\r?\\n?/i', '', $source);
     }
     /* 替换文件编码头部 */
     if (strpos($source, "") !== FALSE) {
         $source = str_replace("", '', $source);
     }
     $pattern = array('/<!--[^>|\\n]*?({.+?})[^<|{|\\n]*?-->/', '/<!--[^<|>|{|\\n]*?-->/', '/(href=["|\'])\\.\\.\\/(.*?)(["|\'])/i', '/((?:background|src)\\s*=\\s*["|\'])(?:\\.\\/|\\.\\.\\/)?(images\\/.*?["|\'])/is', '/((?:background|background-image):\\s*?url\\()(?:\\.\\/|\\.\\.\\/)?(images\\/)/is', '/([\'|"])\\.\\.\\//is');
     $replace = array('\\1', '', '\\1\\2\\3', '\\1' . $tmp_dir . '\\2', '\\1' . $tmp_dir . '\\2', '\\1');
     return preg_replace($pattern, $replace, $source);
 }
Exemplo n.º 3
0
 function smarty_prefilter_preCompile($source)
 {
     $file_type = strtolower(strrchr($this->_current_file, '.'));
     $tmp_dir = 'themes/' . $GLOBALS['_CFG']['template'] . '/';
     // Ä£°åËùÔÚ·¾¶
     /**
      * ´¦ÀíÄ£°åÎļþ
      */
     if ($file_type == '.dwt') {
         /* ½«Ä£°åÖÐËùÓÐlibraryÌ滻ΪÁ´½Ó */
         $pattern = '/<!--\\s#BeginLibraryItem\\s\\"\\/(.*?)\\"\\s-->.*?<!--\\s#EndLibraryItem\\s-->/se';
         $replacement = "'{include file='.strtolower('\\1'). '}'";
         $source = preg_replace($pattern, $replacement, $source);
         /* ¼ì²éÓÐÎÞ¶¯Ì¬¿âÎļþ£¬Èç¹ûÓÐΪÆ丳ֵ */
         $dyna_libs = get_dyna_libs($GLOBALS['_CFG']['template'], $this->_current_file);
         if ($dyna_libs) {
             foreach ($dyna_libs as $region => $libs) {
                 $pattern = '/<!--\\s*TemplateBeginEditable\\sname="' . $region . '"\\s*-->(.*?)<!--\\s*TemplateEndEditable\\s*-->/s';
                 if (preg_match($pattern, $source, $reg_match)) {
                     $reg_content = $reg_match[1];
                     /* Éú³ÉÆ¥Åä×Ö´® */
                     $keys = array_keys($libs);
                     $lib_pattern = '';
                     foreach ($keys as $lib) {
                         $lib_pattern .= '|' . str_replace('/', '\\/', substr($lib, 1));
                     }
                     $lib_pattern = '/{include\\sfile=(' . substr($lib_pattern, 1) . ')}/';
                     /* ÐÞ¸Ä$reg_contentÖеÄÄÚÈÝ */
                     $GLOBALS['libs'] = $libs;
                     $reg_content = preg_replace_callback($lib_pattern, 'dyna_libs_replace', $reg_content);
                     /* ÓÃÐ޸ĹýµÄÄÚÈÝÌæ»»Ô­À´µ±Ç°ÇøÓòÖÐÄÚÈÝ */
                     $source = preg_replace($pattern, $reg_content, $source);
                 }
             }
         }
         /* ÔÚÍ·²¿¼ÓÈë°æ±¾ÐÅÏ¢ */
         $source = preg_replace('/<head>/i', "<head>\r\n<meta name=\"Generator\" content=\"" . APPNAME . ' ' . VERSION . "\" />", $source);
         /* ÐÞÕýcss·¾¶ */
         $source = preg_replace('/(<link\\shref=["|\'])(?:\\.\\/|\\.\\.\\/)?(css\\/)?([a-z0-9A-Z_]+\\.css["|\']\\srel=["|\']stylesheet["|\']\\stype=["|\']text\\/css["|\'])/i', '\\1' . $tmp_dir . '\\2\\3', $source);
         /* ÐÞÕýjsĿ¼ÏÂjsµÄ·¾¶ */
         $source = preg_replace('/(<script\\s(?:type|language)=["|\']text\\/javascript["|\']\\ssrc=["|\'])(?:\\.\\/|\\.\\.\\/)?(js\\/[a-z0-9A-Z_\\-\\.]+\\.(?:js|vbs)["|\']><\\/script>)/', '\\1' . $tmp_dir . '\\2', $source);
         /* ¸ü»»±àÒëÄ£°åµÄ±àÂëÀàÐÍ */
         $source = preg_replace('/<meta\\shttp-equiv=["|\']Content-Type["|\']\\scontent=["|\']text\\/html;\\scharset=(?:.*?)["|\'][^>]*?>\\r?\\n?/i', '<meta http-equiv="Content-Type" content="text/html; charset=' . EC_CHARSET . '" />' . "\n", $source);
     } elseif ($file_type == '.lbi') {
         /* È¥³ýmeta */
         $source = preg_replace('/<meta\\shttp-equiv=["|\']Content-Type["|\']\\scontent=["|\']text\\/html;\\scharset=(?:.*?)["|\']>\\r?\\n?/i', '', $source);
     }
     /* Ìæ»»Îļþ±àÂëÍ·²¿ */
     if (strpos($source, "") !== FALSE) {
         $source = str_replace("", '', $source);
     }
     $pattern = array('/<!--[^>|\\n]*?({.+?})[^<|{|\\n]*?-->/', '/<!--[^<|>|{|\\n]*?-->/', '/(href=["|\'])\\.\\.\\/(.*?)(["|\'])/i', '/((?:background|src)\\s*=\\s*["|\'])(?:\\.\\/|\\.\\.\\/)?(images\\/.*?["|\'])/is', '/((?:background|background-image):\\s*?url\\()(?:\\.\\/|\\.\\.\\/)?(images\\/)/is', '/([\'|"])\\.\\.\\//is');
     $replace = array('\\1', '', '\\1\\2\\3', '\\1' . $tmp_dir . '\\2', '\\1' . $tmp_dir . '\\2', '\\1');
     return preg_replace($pattern, $replace, $source);
 }