-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtiny_ssi.php
49 lines (33 loc) · 1.21 KB
/
tiny_ssi.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
<?php
namespace Alexxwiz;
class TinySSI {
private $vars = [];
public $config = [
'echomsg' => '[Value Undefined]',
];
private function saveVars($data) {
$output = preg_replace_callback('|<!--#set var="(.*?)" value="(.*?)" -->|', function ($matches) {
if (!isset($this->vars[$matches[1]])) {
$this->vars[$matches[1]] = $matches[2];
}
return '';
}, $data);
return $output;
}
public function parse($filename) {
$filePath = dirname($filename).'/';
$parsed = file_get_contents($filename);
$parsed = $this->saveVars($parsed);
/** #include **/
$parsed = preg_replace_callback('|<!--#include virtual="(.*?)" -->|', function ($matches) use ($filePath) {
$output = $this->parse($filePath.$matches[1]);
$output = $this->saveVars($output);
return $output;
}, $parsed);
/** vars - echo **/
$parsed = preg_replace_callback('|<!--#echo var="(.*?)" -->|', function($matches) {
return isset($this->vars[$matches[1]]) ? $this->vars[$matches[1]] : $this->config['echomsg'];
}, $parsed);
return $parsed;
}
}