|
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
|
|
|
public function setMarkupEngine(MarkupEngineManager $manager) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->markupEngine = $manager->getEngineByExtension($this->getExtension()); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
1 |
|
/// |
|
29
|
|
|
// Permalink management |
|
30
|
1 |
|
/// |
|
31
|
|
|
|
|
32
|
1 |
|
/** |
|
33
|
|
|
* {@inheritdoc} |
|
34
|
|
|
*/ |
|
35
|
|
|
public function handleSpecialRedirects() |
|
36
|
|
|
{ |
|
37
|
|
|
$fm = $this->getFrontMatter(); |
|
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
if (isset($fm['redirect_from'])) |
|
40
|
|
|
{ |
|
41
|
|
|
$redirects = $fm['redirect_from']; |
|
42
|
|
|
|
|
43
|
1 |
|
if (!is_array($redirects)) |
|
44
|
|
|
{ |
|
45
|
|
|
$redirects = [$redirects]; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$this->redirects = array_merge($this->redirects, $redirects); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/// |
|
53
|
|
|
// Document body transformation |
|
54
|
7 |
|
/// |
|
55
|
|
|
|
|
56
|
7 |
|
/** |
|
57
|
|
|
* @throws TemplateErrorInterface |
|
58
|
7 |
|
* |
|
59
|
7 |
|
* @return string |
|
60
|
|
|
*/ |
|
61
|
7 |
|
public function getContent() |
|
62
|
|
|
{ |
|
63
|
|
|
if (!$this->bodyContentEvaluated) |
|
64
|
7 |
|
{ |
|
65
|
|
|
$this->bodyContent = $this->parseTemplateLanguage($this->bodyContent); |
|
66
|
|
|
|
|
67
|
|
|
if ($this->markupEngine) |
|
68
|
|
|
{ |
|
69
|
|
|
$this->bodyContent = $this->markupEngine->parse($this->bodyContent); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
7 |
|
$this->bodyContentEvaluated = true; |
|
73
|
|
|
} |
|
74
|
7 |
|
|
|
75
|
|
|
return (string)$this->bodyContent; |
|
76
|
7 |
|
} |
|
77
|
6 |
|
|
|
78
|
1 |
|
/** |
|
79
|
1 |
|
* {@inheritdoc} |
|
80
|
|
|
*/ |
|
81
|
6 |
View Code Duplication |
public function createJail() |
|
|
|
|
|
|
82
|
1 |
|
{ |
|
83
|
1 |
|
$whiteListedFunctions = array_merge(self::$whiteListedFunctions, [ |
|
84
|
1 |
|
]); |
|
85
|
|
|
|
|
86
|
|
|
$jailedFunctions = [ |
|
87
|
5 |
|
'getPageView' => 'getJailedPageView', |
|
88
|
5 |
|
'getCollection' => 'getNamespace', |
|
89
|
|
|
]; |
|
90
|
|
|
|
|
91
|
7 |
|
return (new JailedDocument($this, $whiteListedFunctions, $jailedFunctions)); |
|
92
|
7 |
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* {@inheritdoc} |
|
96
|
|
|
*/ |
|
97
|
25 |
View Code Duplication |
public function jsonSerialize() |
|
|
|
|
|
|
98
|
|
|
{ |
|
99
|
25 |
|
return array_merge($this->getFrontMatter(), [ |
|
100
|
25 |
|
'content' => $this->getContent(), |
|
101
|
|
|
'permalink' => $this->getPermalink(), |
|
102
|
|
|
'redirects' => $this->getRedirects(), |
|
103
|
25 |
|
]); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
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.