forked from fex-team/fis-plus-smarty-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compiler.html.php
71 lines (65 loc) · 2.54 KB
/
compiler.html.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* 接管模板页面中的html标签 结束标签时替换页面中的Hook
*
* Copyright (c) 2015 Baidu EXP Team
* @see https://github.com/fex-team/fis-plus-smarty-plugin/blob/master/compiler.html.php
* @example
* {%html id="html" class="html" framework=""%}
* {%head%}
*
* {%/head%}
* {%body%}
*
* {%/body%}
* {%/html%}
* @package fis-plus smarty plugin
* @author Yang,junlong at 2015-07-14 16:10:13 commonts.
* @version $Id$
*/
function smarty_compiler_html($arrParams, $smarty) {
$strResourceApiPath = preg_replace('/[\\/\\\\]+/', '/', dirname(__FILE__) . '/FISResource.class.php');
$strFramework = $arrParams['framework'];
unset($arrParams['framework']);
$strAttr = '';
$strCode = '<?php ';
if (isset($strFramework)) {
$strCode .= 'if(!class_exists(\'FISResource\', false)){require_once(\'' . $strResourceApiPath . '\');}';
$strCode .= 'FISResource::setFramework(FISResource::getUri('.$strFramework.', $_smarty_tpl->smarty));';
}
/********************autopack init********************************/
$strAutoPackPath = preg_replace('/[\\/\\\\]+/', '/', dirname(__FILE__) . '/FISAutoPack.class.php');
$strCode .= 'if(!class_exists(\'FISAutoPack\', false)){require_once(\'' . $strAutoPackPath . '\');}';
$fid = $arrParams['fid'];
$sampleRate = $arrParams['sampleRate'];
unset($arrParams['fid']);
unset($arrParams['sampleRate']);
if (isset($fid)){
$strCode .= 'FISAutoPack::setFid('.$fid.');';
}
if (isset($sampleRate)){
$strCode .= 'FISAutoPack::setSampleRate('.$sampleRate.');';
}
//set page tpl
$template_dir = $smarty->getTemplateDir();
$template_dir = str_replace('\\', '/', $template_dir[0]);
$strCode .= '$tpl=str_replace("\\\\", "/", $_smarty_tpl->template_resource);';
$strCode .= 'FISAutoPack::setPageName(str_replace("' . $template_dir . '", "", $tpl));';
/*********************autopack end*******************************/
$strCode .= ' ?>';
foreach ($arrParams as $_key => $_value) {
if (is_numeric($_key)) {
$strAttr .= ' <?php echo ' . $_value .';?>';
} else {
$strAttr .= ' ' . $_key . '="<?php echo ' . $_value . ';?>"';
}
}
return $strCode . "<html{$strAttr}>";
}
function smarty_compiler_htmlclose($arrParams, $smarty) {
$strCode = '<?php ';
$strCode .= '$_smarty_tpl->registerFilter(\'output\', array(\'FISResource\', \'renderResponse\'));';
$strCode .= '?>';
$strCode .= '</html>';
return $strCode;
}