Skip to content

Commit ed5d4ca

Browse files
committed
Absolute path support for templates
1 parent 4221914 commit ed5d4ca

File tree

1 file changed

+56
-44
lines changed

1 file changed

+56
-44
lines changed

system/core/view.php

+56-44
Original file line numberDiff line numberDiff line change
@@ -184,26 +184,33 @@ function checkNeedRecompile($service = false) {
184184
$templateFile = $templatePath . $template;
185185
$html = DIR_TEMPLATE . $this->tplFile;
186186

187-
if (strpos($this->template, 'plugins' . DS) === 0) {
188-
$templatePath = DIR_PUBLIC . 'plugins' . DS;
189-
//$templatePath = $this->templatePath = DIR_PUBLIC . 'plugins' . DS;
190-
191-
$template = str_replace('plugins' . DS, '', $template);
192-
$p = strpos($template, DS);
193-
$pluginName = substr($template, 0, $p);
194-
$nameSpace = substr($template, $p + 1);
187+
//absolute path
188+
if ($this->template[0] == '/') {
189+
$templatePath = dirname($this->template) . '/';
190+
$template = basename($this->template);
191+
$templateFile = $this->template;
192+
} else {
193+
if (strpos($this->template, 'plugins' . DS) === 0) {
194+
$templatePath = DIR_PUBLIC . 'plugins' . DS;
195+
//$templatePath = $this->templatePath = DIR_PUBLIC . 'plugins' . DS;
196+
197+
$template = str_replace('plugins' . DS, '', $template);
198+
$p = strpos($template, DS);
199+
$pluginName = substr($template, 0, $p);
200+
$nameSpace = substr($template, $p + 1);
201+
202+
if (APP == 'admin') {
203+
$tpl = $pluginName . DS . join(DS, [APP, 'template']) . DS . $nameSpace;
204+
$template = $pluginName . DS . APP . DS . $nameSpace;
205+
} else {
206+
$tpl = $pluginName . DS . join(DS, [APP, 'template']) . DS . $nameSpace;
207+
$template = $pluginName . DS . $nameSpace;
208+
}
195209

196-
if (APP == 'admin') {
197-
$tpl = $pluginName . DS . join(DS, [APP, 'template']) . DS . $nameSpace;
198-
$template = $pluginName . DS . APP . DS . $nameSpace;
199-
} else {
200-
$tpl = $pluginName . DS . join(DS, [APP, 'template']) . DS . $nameSpace;
201-
$template = $pluginName . DS . $nameSpace;
210+
$this->tplFile = str_replace('.html', '.tpl', $tpl);
211+
$html = DIR_PLUGINS . $this->tplFile;
212+
$templateFile = $templatePath . $template;
202213
}
203-
204-
$this->tplFile = str_replace('.html', '.tpl', $tpl);
205-
$html = DIR_PLUGINS . $this->tplFile;
206-
$templateFile = $templatePath . $template;
207214
}
208215

209216
if (! file_exists($templatePath . $template)) {
@@ -255,40 +262,45 @@ private function compile($filename, $file, $service = false) {
255262
}
256263

257264
list($this->template, $filename, $this->tplFile) =
258-
Event :: trigger(__CLASS__,__FUNCTION__, $this->template, $filename, $this->tplFile, $this->templateEngine, $this);
265+
Event :: trigger(__CLASS__,__FUNCTION__, $this->template, $filename, $this->tplFile, $this->templateEngine, $this);
259266
$errors = $this->templateEngine->loadHtmlTemplate($filename);
260267

261268
//if no template defined use the default
262-
if (strpos($this->template, 'plugins' . DS) === 0) {
263-
//$template = str_replace('plugins' . DS, '', $this->template);
264-
$template = $this->tplFile;
265-
$p = strpos($template, DS);
266-
$pluginName = substr($template, 0, $p);
267-
$nameSpace = substr($template, $p + 1);
268-
269-
if (file_exists(DIR_PLUGINS . $this->tplFile)) {
270-
$this->tplFile = DIR_PLUGINS . $this->tplFile;
271-
} else {
272-
$this->tplFile = DIR_TEMPLATE . 'common.tpl';
273-
}
274-
275-
//$this->tplFile = $pluginName . DS . APP . DS . 'template' . DS . $nameSpace;
269+
if ($this->tplFile[0] == '/') {
270+
$this->tplFile = DIR_TEMPLATE . 'common.tpl';
276271
$this->templateEngine->loadTemplateFile($this->tplFile);
277-
/*
278-
if (APP == 'admin') {
279-
$this->tplFile = $pluginName . DS . APP ."/template/$nameSpace";
280-
} else {
281-
$this->tplFile = "$pluginName/admin/template/$nameSpace";
282-
}*/
283272
} else {
284-
if (! file_exists(DIR_TEMPLATE . $this->tplFile)) {
285-
$this->tplFile = 'common.tpl';
273+
if (strpos($this->template, 'plugins' . DS) === 0) {
274+
//$template = str_replace('plugins' . DS, '', $this->template);
275+
$template = $this->tplFile;
276+
$p = strpos($template, DS);
277+
$pluginName = substr($template, 0, $p);
278+
$nameSpace = substr($template, $p + 1);
279+
280+
if (file_exists(DIR_PLUGINS . $this->tplFile)) {
281+
$this->tplFile = DIR_PLUGINS . $this->tplFile;
282+
} else {
283+
$this->tplFile = DIR_TEMPLATE . 'common.tpl';
284+
}
285+
286+
//$this->tplFile = $pluginName . DS . APP . DS . 'template' . DS . $nameSpace;
287+
$this->templateEngine->loadTemplateFile($this->tplFile);
288+
/*
289+
if (APP == 'admin') {
290+
$this->tplFile = $pluginName . DS . APP ."/template/$nameSpace";
291+
} else {
292+
$this->tplFile = "$pluginName/admin/template/$nameSpace";
293+
}*/
294+
} else {
295+
if (! file_exists(DIR_TEMPLATE . $this->tplFile)) {
296+
$this->tplFile = 'common.tpl';
297+
}
298+
$this->templateEngine->loadTemplateFileFromPath($this->tplFile);
286299
}
287-
$this->templateEngine->loadTemplateFileFromPath($this->tplFile);
288300
}
289301

290302
list($this->template, $filename, $this->tplFile) =
291-
Event :: trigger(__CLASS__,__FUNCTION__ . ':after', $this->template, $filename, $this->tplFile, $this->templateEngine, $this);
303+
Event :: trigger(__CLASS__,__FUNCTION__ . ':after', $this->template, $filename, $this->tplFile, $this->templateEngine, $this);
292304
$this->templateEngine->saveCompiledTemplate($file);
293305
}
294306

@@ -333,7 +345,7 @@ function setType($type) {
333345
$this->_type = $type;
334346
}
335347

336-
function getType($type) {
348+
function getType() {
337349
return $this->_type;
338350
}
339351

0 commit comments

Comments
 (0)