|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Quantum PHP Framework |
|
5
|
|
|
* |
|
6
|
|
|
* An open source software development framework for PHP |
|
7
|
|
|
* |
|
8
|
|
|
* @package Quantum |
|
9
|
|
|
* @author Arman Ag. <[email protected]> |
|
10
|
|
|
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) |
|
11
|
|
|
* @link http://quantum.softberg.org/ |
|
12
|
|
|
* @since 2.9.8 |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
use Quantum\Config\Exceptions\ConfigException; |
|
16
|
|
|
use Quantum\View\Exceptions\ViewException; |
|
17
|
|
|
use League\CommonMark\CommonMarkConverter; |
|
18
|
|
|
use Quantum\App\Exceptions\BaseException; |
|
19
|
|
|
use Quantum\View\Factories\ViewFactory; |
|
20
|
|
|
use Quantum\Di\Exceptions\DiException; |
|
21
|
|
|
use DebugBar\DebugBarException; |
|
22
|
|
|
use Quantum\Debugger\Debugger; |
|
23
|
|
|
use Quantum\View\RawParam; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Rendered view |
|
27
|
|
|
* @return string|null |
|
28
|
|
|
* @throws BaseException |
|
29
|
|
|
* @throws ConfigException |
|
30
|
|
|
* @throws DebugBarException |
|
31
|
|
|
* @throws DiException |
|
32
|
|
|
* @throws ReflectionException |
|
33
|
|
|
* @throws ViewException |
|
34
|
|
|
*/ |
|
35
|
|
|
function view(): ?string |
|
36
|
|
|
{ |
|
37
|
|
|
return ViewFactory::get()->getView(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Rendered partial |
|
42
|
|
|
* @param string $partial |
|
43
|
|
|
* @param array $args |
|
44
|
|
|
* @return string|null |
|
45
|
|
|
* @throws BaseException |
|
46
|
|
|
* @throws ConfigException |
|
47
|
|
|
* @throws DebugBarException |
|
48
|
|
|
* @throws DiException |
|
49
|
|
|
* @throws ReflectionException |
|
50
|
|
|
*/ |
|
51
|
|
|
function partial(string $partial, array $args = []): ?string |
|
52
|
|
|
{ |
|
53
|
|
|
return ViewFactory::get()->renderPartial($partial, $args); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Gets the param passed to view |
|
58
|
|
|
* @param string $key |
|
59
|
|
|
* @return mixed|null |
|
60
|
|
|
* @throws BaseException |
|
61
|
|
|
* @throws ConfigException |
|
62
|
|
|
* @throws DebugBarException |
|
63
|
|
|
* @throws DiException |
|
64
|
|
|
* @throws ReflectionException |
|
65
|
|
|
*/ |
|
66
|
|
|
function view_param(string $key) |
|
67
|
|
|
{ |
|
68
|
|
|
return ViewFactory::get()->getParam($key); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Creates a raw param |
|
73
|
|
|
* @param $value |
|
74
|
|
|
* @return RawParam |
|
75
|
|
|
*/ |
|
76
|
|
|
function raw_param($value): RawParam |
|
77
|
|
|
{ |
|
78
|
|
|
return new RawParam($value); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Rendered debug bar |
|
83
|
|
|
* @return string|null |
|
84
|
|
|
* @throws DebugBarException |
|
85
|
|
|
*/ |
|
86
|
|
|
function debugbar(): ?string |
|
87
|
|
|
{ |
|
88
|
|
|
$debugger = Debugger::getInstance(); |
|
89
|
|
|
|
|
90
|
|
|
if ($debugger->isEnabled()) { |
|
91
|
|
|
return $debugger->render(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
return null; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param string $content |
|
99
|
|
|
* @param bool $sanitize |
|
100
|
|
|
* @return string |
|
101
|
|
|
*/ |
|
102
|
|
|
function markdown_to_html(string $content, bool $sanitize = false): string |
|
103
|
|
|
{ |
|
104
|
|
|
$converter = new CommonMarkConverter(); |
|
105
|
|
|
$purifier = null; |
|
106
|
|
|
|
|
107
|
|
|
if ($sanitize) { |
|
108
|
|
|
$config = HTMLPurifier_Config::createDefault(); |
|
109
|
|
|
$purifier = new HTMLPurifier($config); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
$html = $converter->convertToHtml($content); |
|
113
|
|
|
|
|
114
|
|
|
if ($purifier) { |
|
115
|
|
|
return $purifier->purify($html); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
return $html; |
|
119
|
|
|
} |