|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Engine code |
|
4
|
|
|
* |
|
5
|
|
|
* @package Stencil |
|
6
|
|
|
* @subpackage Smarty3 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Double check to make sure Stencil is loaded |
|
11
|
|
|
*/ |
|
12
|
|
|
if ( class_exists( 'Stencil_Implementation' ) ) : |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Create new instance on init |
|
16
|
|
|
*/ |
|
17
|
|
|
add_action( 'init', create_function( '', 'new Stencil_Smarty_3();' ) ); |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class stencil_smarty3 |
|
21
|
|
|
* |
|
22
|
|
|
* Implementation of the "Smarty 3.x" templating engine |
|
23
|
|
|
*/ |
|
24
|
|
|
class Stencil_Smarty_3 extends Stencil_Implementation { |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Initialize Smarty3 and set defaults |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct() { |
|
30
|
|
|
parent::__construct(); |
|
31
|
|
|
|
|
32
|
|
|
require_once( 'lib/Smarty/Smarty.class.php' ); |
|
33
|
|
|
|
|
34
|
|
|
$this->engine = new Smarty(); |
|
35
|
|
|
$this->engine->setCacheDir( $this->cache_path ); |
|
36
|
|
|
$this->engine->setCompileDir( $this->compile_path ); |
|
37
|
|
|
$this->engine->setTemplateDir( $this->template_path ); |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* For config see: |
|
41
|
|
|
* http://www.smarty.net/docs/en/config.files.tpl |
|
42
|
|
|
*/ |
|
43
|
|
|
|
|
44
|
|
|
/* |
|
45
|
|
|
* $this->engine->setConfigDir( $template_dir . 'configs/'); |
|
46
|
|
|
*/ |
|
47
|
|
|
|
|
48
|
|
|
// Add custom plugins to smarty (per template). |
|
49
|
|
|
$plugin_dir = apply_filters( 'smarty3-template-plugin-dir', 'smarty-plugins' ); |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Add theme plugins & child-theme plugins |
|
53
|
|
|
*/ |
|
54
|
|
|
if ( ! empty( $plugin_dir ) ) { |
|
55
|
|
|
$template_root = get_template_directory(); |
|
56
|
|
|
$plugin_bases = array( $template_root ); |
|
57
|
|
|
|
|
58
|
|
|
$child_root = get_stylesheet_directory(); |
|
59
|
|
|
if ( $child_root !== $template_root ) { |
|
60
|
|
|
$plugin_bases[] = $child_root; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
foreach ( $plugin_bases as $plugin_base ) { |
|
64
|
|
|
$plugin_dir = implode( DIRECTORY_SEPARATOR, array( $plugin_base, $plugin_dir, '' ) ); |
|
65
|
|
|
if ( is_dir( $plugin_dir ) ) { |
|
66
|
|
|
$this->engine->addPluginsDir( $plugin_dir ); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Caching - when and how? |
|
73
|
|
|
* http://www.smarty.net/docsv2/en/caching.tpl |
|
74
|
|
|
*/ |
|
75
|
|
|
$this->engine->caching = 0; |
|
76
|
|
|
|
|
77
|
|
|
$this->ready(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Sets the variable to value |
|
82
|
|
|
* |
|
83
|
|
|
* @param string $variable Variable to set. |
|
84
|
|
|
* @param mixed $value Value to apply. |
|
85
|
|
|
* |
|
86
|
|
|
* @return mixed|void |
|
87
|
|
|
*/ |
|
88
|
|
|
public function set( $variable, $value ) { |
|
89
|
|
|
if ( is_object( $value ) ) { |
|
90
|
|
|
$this->engine->assignByRef( $variable, $value ); |
|
91
|
|
|
} else { |
|
92
|
|
|
$this->engine->assign( $variable, $value ); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
return $this->get( $variable ); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Gets the value of variable |
|
100
|
|
|
* |
|
101
|
|
|
* @param string $variable Variable to read. |
|
102
|
|
|
* |
|
103
|
|
|
* @return mixed|string |
|
104
|
|
|
*/ |
|
105
|
|
|
public function get( $variable ) { |
|
106
|
|
|
return $this->engine->getTemplateVars( $variable ); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Fetches the Smarty compiled template |
|
111
|
|
|
* |
|
112
|
|
|
* @param string $template Template file to get. |
|
113
|
|
|
* |
|
114
|
|
|
* @return string |
|
115
|
|
|
*/ |
|
116
|
|
|
public function fetch( $template ) { |
|
117
|
|
|
return $this->engine->fetch( $template ); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
endif; |
|
122
|
|
|
|
create_functioncan pose a great security vulnerability as it is similar toeval, and could be used for arbitrary code execution. We highly recommend to use a closure instead.