Skip to content

Commit 5ef2a08

Browse files
committed
Update parser.class.php
SmartyParser update
1 parent aab891a commit 5ef2a08

File tree

1 file changed

+127
-143
lines changed

1 file changed

+127
-143
lines changed

lib/parser.class.php

+127-143
Original file line numberDiff line numberDiff line change
@@ -21,146 +21,130 @@
2121
*/
2222
class parser
2323
{
24-
var $data; // data
25-
var $template; // template-file
26-
var $result; // result
27-
var $owner; // parser's owner object
28-
29-
/**
30-
* Used to parse templates with data provided
31-
* Based on template file extention:
32-
* .xslt - XSLT-parser used
33-
* .tpl - SMARTY-parser used
34-
* all other extensions - jTemplates-parser used
35-
* @param mixed $template Template filename
36-
* @param mixed $data Data
37-
* @param mixed $owner Parser's owner object
38-
*/
39-
public function __construct($template, &$data, $owner = "")
40-
{
41-
// set current directory for template includes
42-
$this->data = &$data;
43-
$this->template = $template;
44-
45-
if (is_object($owner))
46-
{
47-
$this->owner = &$owner;
48-
}
49-
50-
if (strpos($template, ".xslt") == TRUE)
51-
{
52-
// xslt-Templates
53-
$this->result = $this->xslt_parse($template, $this->data);
54-
}
55-
elseif (strpos($template, ".tpl") == TRUE)
56-
{
57-
// smarty-Templates
58-
$this->result = $this->smarty_parse($template, $this->data);
59-
}
60-
else
61-
{
62-
// j-Templates
63-
$this->result = $this->jtemplate_parse($template, $this->data);
64-
}
65-
66-
if (is_object($this->owner))
67-
{
68-
// links parsing for all results (framework support)
69-
$this->result = $this->owner->parseLinks($this->result);
70-
}
71-
}
72-
73-
/**
74-
* jTemplates-parse
75-
* Used to parse jTemplates
76-
* @access private
77-
* @param mixed $template jTemplate filename
78-
* @param mixed $data Data
79-
* @return string
80-
*/
81-
public function jtemplate_parse($template, &$data)
82-
{
83-
/*
84-
if (preg_match('/menu\.html/', $_SERVER['REQUEST_URI'])) {
85-
$compl=new jTemplateCompiler($template, "out", $this->owner);
86-
$out=&$data;
87-
include($compl->compiled_file);
88-
}
89-
*/
90-
91-
startMeasure('Parse template ' . $template);
92-
93-
$jTempl = new jTemplate($template, $data, $this->owner);
94-
$result = $jTempl->result;
95-
96-
endMeasure('Parse template ' . $template);
97-
98-
return $result;
99-
}
100-
101-
/**
102-
* XSLT-parser
103-
* Used to parse xslt-templates
104-
* @access private
105-
* @param mixed $template XSLT-rules
106-
* @param mixed $data Data
107-
* @return mixed
108-
*/
109-
public function xslt_parse($template, &$data)
110-
{
111-
$new_data["ROOT"] = $data;
112-
113-
$xml = new xml_data($new_data);
114-
115-
$arguments = array('/_xml' => $xml->string, '/_xsl' => $template);
116-
117-
$xh = xslt_create();
118-
119-
$result = xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments);
120-
121-
xslt_free($xh);
122-
123-
return $result;
124-
}
125-
126-
/**
127-
* SMARTY-parser
128-
* Used to parse SMARTY templates
129-
* @access private
130-
* @param mixed $template_file Template filename
131-
* @param mixed $data Data
132-
* @return mixed
133-
*/
134-
public function smarty_parse($template_file, &$data)
135-
{
136-
define('SMARTY_DIR',ROOT . '3rdparty/smarty3/');
137-
138-
require_once(SMARTY_DIR . 'Smarty.class.php');
139-
140-
$smarty = new Smarty;
141-
142-
$smarty->compile_dir = SMARTY_DIR . 'templates_c/';
143-
144-
if (isset($this->owner))
145-
{
146-
$smarty->template_dir = DIR_TEMPLATES . $this->owner->name . "/";
147-
}
148-
149-
$data["ROOTHTML"] = ROOTHTML;
150-
151-
foreach ($data as $k => $v)
152-
{
153-
$smarty->assign($k, $data[$k]);
154-
}
155-
156-
if (is_object($this->owner))
157-
{
158-
$smarty->owner = &$this->owner;
159-
}
160-
161-
$result = $smarty->fetch($template_file);
162-
163-
return $result;
164-
}
165-
}
166-
?>
24+
var $data; // data
25+
var $template; // template-file
26+
var $result; // result
27+
var $owner; // parser's owner object
28+
29+
/**
30+
* Used to parse templates with data provided
31+
* Based on template file extention:
32+
* .xslt - XSLT-parser used
33+
* .tpl - SMARTY-parser used
34+
* all other extensions - jTemplates-parser used
35+
* @param mixed $template Template filename
36+
* @param mixed $data Data
37+
* @param mixed $owner Parser's owner object
38+
*/
39+
public function __construct($template, &$data, $owner = "")
40+
{
41+
// set current directory for template includes
42+
$this->data = &$data;
43+
$this->template = $template;
44+
45+
if (is_object($owner)) {
46+
$this->owner = &$owner;
47+
}
48+
49+
if (strpos($template, ".xslt") == TRUE) {
50+
// xslt-Templates
51+
$this->result = $this->xslt_parse($template, $this->data);
52+
} elseif (strpos($template, ".tpl") == TRUE) {
53+
// smarty-Templates
54+
$this->result = $this->smarty_parse($template, $this->data);
55+
} else {
56+
// j-Templates
57+
$this->result = $this->jtemplate_parse($template, $this->data);
58+
}
59+
60+
if (is_object($this->owner)) {
61+
// links parsing for all results (framework support)
62+
$this->result = $this->owner->parseLinks($this->result);
63+
}
64+
}
65+
66+
/**
67+
* jTemplates-parse
68+
* Used to parse jTemplates
69+
* @access private
70+
* @param mixed $template jTemplate filename
71+
* @param mixed $data Data
72+
* @return string
73+
*/
74+
public function jtemplate_parse($template, &$data)
75+
{
76+
/*
77+
if (preg_match('/menu\.html/', $_SERVER['REQUEST_URI'])) {
78+
$compl=new jTemplateCompiler($template, "out", $this->owner);
79+
$out=&$data;
80+
include($compl->compiled_file);
81+
}
82+
*/
83+
84+
startMeasure('Parse template ' . $template);
85+
86+
$jTempl = new jTemplate($template, $data, $this->owner);
87+
$result = $jTempl->result;
88+
89+
endMeasure('Parse template ' . $template);
90+
91+
return $result;
92+
}
93+
94+
/**
95+
* XSLT-parser
96+
* Used to parse xslt-templates
97+
* @access private
98+
* @param mixed $template XSLT-rules
99+
* @param mixed $data Data
100+
* @return mixed
101+
*/
102+
public function xslt_parse($template, &$data)
103+
{
104+
$new_data["ROOT"] = $data;
105+
106+
$xml = new xml_data($new_data);
107+
108+
$arguments = array('/_xml' => $xml->string, '/_xsl' => $template);
109+
110+
$xh = xslt_create();
111+
112+
$result = xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments);
113+
114+
xslt_free($xh);
115+
116+
return $result;
117+
}
118+
119+
/**
120+
* SMARTY-parser
121+
* Used to parse SMARTY templates
122+
* @access private
123+
* @param mixed $template_file Template filename
124+
* @param mixed $data Data
125+
* @return mixed
126+
*/
127+
public function smarty_parse($template_file, &$data)
128+
{
129+
define('SMARTY_DIR', ROOT . '3rdparty/smarty3/');
130+
131+
require_once(SMARTY_DIR . 'Smarty.class.php');
132+
$smarty = new Smarty;
133+
$smarty->compile_dir = ROOT . 'cms/cached/templates_c/';
134+
135+
if (isset($this->owner)) {
136+
$smarty->template_dir = DIR_TEMPLATES . $this->owner->name . "/";
137+
}
138+
$data["ROOTHTML"] = ROOTHTML;
139+
foreach ($data as $k => $v) {
140+
$smarty->assign($k, $data[$k]);
141+
}
142+
if (is_object($this->owner)) {
143+
$smarty->owner = $this->owner;
144+
}
145+
146+
$result = $smarty->fetch($template_file);
147+
148+
return $result;
149+
}
150+
}

0 commit comments

Comments
 (0)