|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright 2017 Vladimir Jimenez |
|
5
|
|
|
* @license https://github.com/allejo/stakx/blob/master/LICENSE.md MIT |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace allejo\stakx\Document; |
|
9
|
|
|
|
|
10
|
|
|
use allejo\stakx\Filesystem\File; |
|
11
|
|
|
use allejo\stakx\MarkupEngine\MarkupEngine; |
|
12
|
|
|
use allejo\stakx\MarkupEngine\MarkupEngineManager; |
|
13
|
|
|
use allejo\stakx\Templating\TemplateErrorInterface; |
|
14
|
|
|
|
|
15
|
|
|
class ContentItem extends PermalinkFrontMatterDocument implements CollectableItem, TemplateReadyDocument |
|
16
|
|
|
{ |
|
17
|
|
|
use CollectableItemTrait; |
|
18
|
|
|
use TemplateEngineDependent; |
|
19
|
|
|
|
|
20
|
|
|
/** @var MarkupEngine */ |
|
21
|
|
|
private $markupEngine; |
|
22
|
|
|
|
|
23
|
57 |
|
public function __construct(File $file) |
|
24
|
|
|
{ |
|
25
|
57 |
|
$this->noReadOnConstructor = true; |
|
26
|
|
|
|
|
27
|
57 |
|
parent::__construct($file); |
|
28
|
56 |
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function setMarkupEngine(MarkupEngineManager $manager) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->markupEngine = $manager->getMarkupEngine($this->getExtension()); |
|
33
|
|
|
$this->readContent(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/// |
|
37
|
|
|
// Permalink management |
|
38
|
|
|
/// |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* {@inheritdoc} |
|
42
|
|
|
*/ |
|
43
|
|
|
public function handleSpecialRedirects() |
|
44
|
|
|
{ |
|
45
|
|
|
$fm = $this->getFrontMatter(); |
|
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
if (isset($fm['redirect_from'])) |
|
48
|
|
|
{ |
|
49
|
|
|
$redirects = $fm['redirect_from']; |
|
50
|
|
|
|
|
51
|
|
|
if (!is_array($redirects)) |
|
52
|
|
|
{ |
|
53
|
|
|
$redirects = [$redirects]; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$this->redirects = array_merge($this->redirects, $redirects); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/// |
|
61
|
|
|
// Document body transformation |
|
62
|
|
|
/// |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @throws TemplateErrorInterface |
|
66
|
|
|
* |
|
67
|
|
|
* @return string |
|
68
|
|
|
*/ |
|
69
|
5 |
|
public function getContent() |
|
70
|
|
|
{ |
|
71
|
5 |
|
if (!$this->bodyContentEvaluated) |
|
72
|
|
|
{ |
|
73
|
5 |
|
$this->bodyContent = $this->parseTemplateLanguage($this->bodyContent); |
|
74
|
5 |
|
$this->bodyContent = $this->markupEngine->parse($this->bodyContent); |
|
75
|
|
|
|
|
76
|
|
|
$this->bodyContentEvaluated = true; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
return (string)$this->bodyContent; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* {@inheritdoc} |
|
84
|
|
|
*/ |
|
85
|
6 |
View Code Duplication |
public function createJail() |
|
|
|
|
|
|
86
|
|
|
{ |
|
87
|
6 |
|
$whiteListedFunctions = array_merge(self::$whiteListedFunctions, [ |
|
88
|
6 |
|
]); |
|
89
|
|
|
|
|
90
|
|
|
$jailedFunctions = [ |
|
91
|
6 |
|
'getPageView' => 'getJailedPageView', |
|
92
|
|
|
'getCollection' => 'getNamespace', |
|
93
|
|
|
]; |
|
94
|
|
|
|
|
95
|
6 |
|
return (new JailedDocument($this, $whiteListedFunctions, $jailedFunctions)); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* {@inheritdoc} |
|
100
|
|
|
*/ |
|
101
|
|
View Code Duplication |
public function jsonSerialize() |
|
|
|
|
|
|
102
|
|
|
{ |
|
103
|
|
|
return array_merge($this->getFrontMatter(), [ |
|
104
|
|
|
'content' => $this->getContent(), |
|
105
|
|
|
'permalink' => $this->getPermalink(), |
|
106
|
|
|
'redirects' => $this->getRedirects(), |
|
107
|
|
|
]); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.