-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRender.php
56 lines (51 loc) · 1.32 KB
/
Render.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
<?php
namespace core;
use core\MdMail;
use core\DirtyMarkdown;
use core\Helper;
class Render
{
/** Render(Markdown) $file with $args */
public static function mail($file, array $args = [])
{
$lang = "en";
if (isset($_COOKIE["lang"])) {
$lang = strtolower($_COOKIE["lang"]);
if (! in_array($lang, ["nl", "en"])) {
$lang = "en";
}
}
$txt = file_get_contents(sprintf("%s%s_%s.md", TPL_MAIL, $file, $lang));
foreach ($args as $key => $val) {
$txt = str_replace("{{ $key }}", $val, $txt);
}
$txt = str_replace("{{ site }}", Helper::config("general")["baseurl"], $txt);
$txt = str_replace("{{ company }}", Helper::config("general")["name"], $txt);
$txt = str_replace("{{ support }}", Helper::config("general")["name"], $txt);
$out = [
"text" => $txt,
"html" => file_get_contents(TPL_MAIL . "head.md") .
DirtyMarkdown::parse($txt) .
file_get_contents(TPL_MAIL . "foot.md")
,
"htmlEmbed" => DirtyMarkdown::embeds()
];
if (count($out["htmlEmbed"]) === 0) {
// Force to null against cannot unmarshal array
$out["htmlEmbed"] = null;
}
return $out;
}
// Black magic for dead-simple template rendering
// arg0 = file
// arg1 = args as array
public static function php()
{
ob_start();
{
extract(func_get_arg(1));
include func_get_arg(0);
}
return ob_get_clean();
}
}