-
Notifications
You must be signed in to change notification settings - Fork 1
/
PluginInclude.php
64 lines (55 loc) · 1.36 KB
/
PluginInclude.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
<?php
class PluginInclude extends WikiPlugin
{
public function executePhaseOne()
{
$parent = end($this->parents);
$data = $this->parser->getData();
$path = $this->parameters['path'];
if (!preg_match('#^(/|[a-z]:\\\\|https?://)#i', $path)) {
$path = $data['__dir__'] . $path;
}
$markup = file_get_contents($path);
$is_html = preg_match('#\.html?$#i', $path);
$vars = array();
foreach ($this->parameters as $key => $value) {
if ($key == 'path') {
continue;
}
if ($is_html) {
$markup = str_replace(
'{{ ' . $key . ' }}',
$this->parser->encode($value),
$markup
);
} else {
$vars['var:' . $key] = $value;
}
}
$vars = array_merge($this->parser->getData(), $vars);
$tag = $this->tag;
if ($is_html) {
// Cleanup unused replacements
$markup = preg_replace('#(?<!\{)\{\{\s+\w+\s+\}\}(?!\})#', '', $markup);
$this->parser->changeTag(
$parent,
$tag,
'raw',
NULL,
array(0 => $markup)
);
} else {
$parser = new FlourishWikiParser($markup, $vars);
$parser->parse();
// Graft the include's children under the current parent
$tree = $parser->getTree();
$last_child = $tag;
foreach ($tree->children as $child) {
$this->parser->injectTag($parent, $last_child, $child);
$last_child = $child;
}
$this->parser->removeTag($parent, $tag);
}
return TRUE;
}
}