1 | <?php |
||
16 | class ContentItem extends FrontMatterDocument implements \JsonSerializable, RepeatableItem |
||
17 | { |
||
18 | /** |
||
19 | * The collection this Content Item belongs to. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | private $parentCollection; |
||
24 | |||
25 | /** |
||
26 | * The Page View that will be used to render this Content Item. |
||
27 | * |
||
28 | * @var PageView |
||
29 | */ |
||
30 | private $parentPageView; |
||
31 | |||
32 | /** |
||
33 | * {@inheritdoc} |
||
34 | */ |
||
35 | 27 | public function createJail() |
|
41 | |||
42 | 21 | public function getNamespace() |
|
46 | |||
47 | 37 | public function setNamespace($collection) |
|
51 | |||
52 | 3 | public function handleSpecialRedirects() |
|
53 | { |
||
54 | 3 | $fm = $this->getFrontMatter(); |
|
|
|||
55 | |||
56 | 3 | if (isset($fm['redirect_from'])) |
|
57 | 3 | { |
|
58 | $redirects = $fm['redirect_from']; |
||
59 | |||
60 | if (!is_array($redirects)) |
||
61 | { |
||
62 | $redirects = array($redirects); |
||
63 | } |
||
64 | |||
65 | $this->redirects = array_merge($this->redirects, $redirects); |
||
66 | } |
||
67 | 3 | } |
|
68 | |||
69 | /** |
||
70 | * Return the body of the Content Item parsed as markdown. |
||
71 | * |
||
72 | * @return string |
||
73 | */ |
||
74 | 7 | public function getContent() |
|
75 | { |
||
76 | 7 | if (!$this->bodyContentEvaluated) |
|
77 | 7 | { |
|
78 | 7 | $this->parseTwig(); |
|
79 | 7 | $this->parseEngines(); |
|
80 | |||
81 | 7 | $this->bodyContentEvaluated = true; |
|
82 | 7 | } |
|
83 | |||
84 | 7 | return (string)$this->bodyContent; |
|
85 | } |
||
86 | |||
87 | /** |
||
88 | * Parse the Twig that is embedded inside a ContentItem's body. |
||
89 | */ |
||
90 | 7 | private function parseTwig() |
|
91 | { |
||
92 | 7 | $twig = TwigManager::getInstance(); |
|
93 | |||
94 | 7 | if ($twig instanceof \Twig_Environment) |
|
95 | 7 | { |
|
96 | 7 | $template = $twig->createTemplate($this->bodyContent); |
|
97 | 7 | $this->bodyContent = $template->render(array()); |
|
98 | 7 | } |
|
99 | 7 | } |
|
100 | |||
101 | /** |
||
102 | * Parse the ContentItem's body based on the extension of the file. |
||
103 | */ |
||
104 | 7 | private function parseEngines() |
|
105 | { |
||
106 | 7 | switch ($this->getExtension()) |
|
107 | { |
||
108 | 7 | case 'md': |
|
109 | 7 | case 'markdown': |
|
110 | 2 | $pd = new MarkdownEngine(); |
|
111 | 2 | break; |
|
112 | |||
113 | 5 | case 'rst': |
|
114 | 2 | $pd = new RstEngine(); |
|
115 | 2 | $pd->setIncludePolicy(true, getcwd()); |
|
116 | 2 | break; |
|
117 | |||
118 | 3 | default: |
|
119 | 3 | $pd = new PlainTextEngine(); |
|
120 | 3 | break; |
|
121 | 7 | } |
|
122 | |||
123 | 7 | $this->bodyContent = $pd->parse($this->bodyContent); |
|
124 | 7 | } |
|
125 | |||
126 | /** |
||
127 | * @return PageView |
||
128 | */ |
||
129 | public function &getPageView() |
||
133 | |||
134 | public function getJailedPageView() |
||
138 | |||
139 | /** |
||
140 | * Set the parent Page View that this Content Item will have be assigned to. |
||
141 | * |
||
142 | * @param PageView $pageView |
||
143 | */ |
||
144 | 5 | public function setParentPageView(PageView &$pageView) |
|
148 | |||
149 | /** |
||
150 | * {@inheritdoc} |
||
151 | */ |
||
152 | public function jsonSerialize() |
||
160 | } |
||
161 |
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.