1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* CMS Pico - Integration of Pico within your files to create websites. |
4
|
|
|
* |
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
6
|
|
|
* later. See the COPYING file. |
7
|
|
|
* |
8
|
|
|
* @author Daniel rudolf <www.daniel-rudolf.de> |
9
|
|
|
* @copyright 2017 |
10
|
|
|
* @license GNU AGPL version 3 or any later version |
11
|
|
|
* |
12
|
|
|
* This program is free software: you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU Affero General Public License as |
14
|
|
|
* published by the Free Software Foundation, either version 3 of the |
15
|
|
|
* License, or (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* This program is distributed in the hope that it will be useful, |
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20
|
|
|
* GNU Affero General Public License for more details. |
21
|
|
|
* |
22
|
|
|
* You should have received a copy of the GNU Affero General Public License |
23
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
namespace OCA\CMSPico; |
27
|
|
|
|
28
|
|
|
use HTMLPurifier; |
29
|
|
|
use HTMLPurifier_Config; |
30
|
|
|
use OCA\CMSPico\AppInfo\Application; |
31
|
|
|
|
32
|
|
|
class Pico extends \Pico { |
33
|
|
|
|
34
|
|
|
/** @var HTMLPurifier */ |
35
|
|
|
protected $htmlPurifier; |
36
|
|
|
|
37
|
|
|
/** @var string */ |
38
|
|
|
protected $requestedUrl; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Loads the config.php from Pico::$configDir. |
42
|
|
|
* |
43
|
|
|
* We force enabled URL rewriting due to the support of Nextcloud's |
44
|
|
|
* `PATH_INFO`-based routing method ({@see self::evaluateRequestUrl()}). |
45
|
|
|
*/ |
46
|
|
|
protected function loadConfig() { |
47
|
|
|
parent::loadConfig(); |
48
|
|
|
|
49
|
|
|
$this->config['rewrite_url'] = true; |
50
|
|
|
|
51
|
|
|
if (empty($this->config['nextcloud_site'])) { |
52
|
|
|
$this->config['nextcloud_site'] = 'default'; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
public function setRequestUrl($requestUrl) { |
58
|
|
|
$this->requestUrl = $requestUrl; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* do not evaluate requested URL. |
64
|
|
|
* |
65
|
|
|
* @see setRequestUrl |
66
|
|
|
*/ |
67
|
|
|
protected function evaluateRequestUrl() { |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Returns the parsed and purified file meta from raw file contents. |
73
|
|
|
* |
74
|
|
|
* @param string $rawContent |
75
|
|
|
* @param string[] $headers |
76
|
|
|
* |
77
|
|
|
* @return array |
78
|
|
|
* @throws \Symfony\Component\Yaml\Exception\ParseException |
79
|
|
|
*/ |
80
|
|
|
public function parseFileMeta($rawContent, array $headers) { |
81
|
|
|
$meta = parent::parseFileMeta($rawContent, $headers); |
82
|
|
|
|
83
|
|
|
return $this->purifyFileMeta($meta); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Purifies file meta. |
89
|
|
|
* |
90
|
|
|
* @param array $meta |
91
|
|
|
* |
92
|
|
|
* @return array |
93
|
|
|
*/ |
94
|
|
|
protected function purifyFileMeta(array $meta) { |
95
|
|
|
$newMeta = []; |
96
|
|
|
foreach ($meta as $key => $value) { |
97
|
|
|
if (is_array($value)) { |
98
|
|
|
$newMeta[$key] = $this->purifyFileMeta($value); |
99
|
|
|
} else { |
100
|
|
|
$newMeta[$key] = $this->getHtmlPurifier() |
101
|
|
|
->purify($value); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
return $newMeta; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Returns the parsed and purified contents of a page. |
111
|
|
|
* |
112
|
|
|
* @param string $markdown |
113
|
|
|
* |
114
|
|
|
* @return string |
115
|
|
|
*/ |
116
|
|
|
public function parseFileContent($markdown) { |
117
|
|
|
$content = parent::parseFileContent($markdown); |
118
|
|
|
|
119
|
|
|
return $this->getHtmlPurifier() |
120
|
|
|
->purify($content); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Returns the variables passed to the template. |
126
|
|
|
* |
127
|
|
|
* Let Pico's `theme_url` point directly to the app's themes directory. |
128
|
|
|
* |
129
|
|
|
* @return array |
130
|
|
|
*/ |
131
|
|
|
protected function getTwigVariables() { |
132
|
|
|
$twigVariables = parent::getTwigVariables(); |
133
|
|
|
$twigVariables['theme_url'] = |
134
|
|
|
\OC_App::getAppWebPath(Application::APP_NAME) . '/Pico/themes/' . $this->getConfig('theme'); |
|
|
|
|
135
|
|
|
|
136
|
|
|
return $twigVariables; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Returns the HTMLPurifier instance. |
142
|
|
|
* |
143
|
|
|
* @return HTMLPurifier |
144
|
|
|
*/ |
145
|
|
|
public function getHtmlPurifier() { |
146
|
|
|
if ($this->htmlPurifier === null) { |
147
|
|
|
$this->htmlPurifier = new HTMLPurifier(HTMLPurifier_Config::createDefault()); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
return $this->htmlPurifier; |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths