1 | <?php |
||
10 | class ContentItem extends FrontMatterObject implements \JsonSerializable |
||
11 | { |
||
12 | /** |
||
13 | * The collection this Content Item belongs to |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | private $parentCollection; |
||
18 | |||
19 | /** |
||
20 | * The Page View that will be used to render this Content Item |
||
21 | * |
||
22 | * @var PageView |
||
23 | */ |
||
24 | private $parentPageView; |
||
25 | |||
26 | /** |
||
27 | * {@inheritdoc} |
||
28 | */ |
||
29 | 32 | public function createJail () |
|
35 | |||
36 | 1 | public function getCollection () |
|
40 | |||
41 | 30 | public function setCollection ($collection) |
|
45 | |||
46 | /** |
||
47 | * Return the body of the Content Item parsed as markdown |
||
48 | * |
||
49 | * @return string |
||
50 | */ |
||
51 | 7 | public function getContent () |
|
52 | { |
||
53 | 7 | if (!$this->bodyContentEvaluated) |
|
54 | { |
||
55 | 7 | $this->parseTwig(); |
|
56 | 7 | $this->parseEngines(); |
|
57 | |||
58 | 7 | $this->bodyContentEvaluated = true; |
|
59 | } |
||
60 | |||
61 | 7 | return (string)$this->bodyContent; |
|
62 | } |
||
63 | |||
64 | /** |
||
65 | * Parse the Twig that is embedded inside a ContentItem's body |
||
66 | */ |
||
67 | 7 | private function parseTwig () |
|
68 | { |
||
69 | 7 | $twig = TwigManager::getInstance(); |
|
70 | |||
71 | 7 | if ($twig instanceof \Twig_Environment) |
|
72 | { |
||
73 | $template = $twig->createTemplate($this->bodyContent); |
||
74 | $this->bodyContent = $template->render(array()); |
||
75 | } |
||
76 | 7 | } |
|
77 | |||
78 | /** |
||
79 | * Parse the ContentItem's body based on the extension of the file |
||
80 | */ |
||
81 | 7 | private function parseEngines () |
|
82 | { |
||
83 | 7 | switch ($this->getExtension()) |
|
84 | { |
||
85 | 7 | case "md": |
|
86 | 5 | case "markdown": |
|
87 | 2 | $pd = new MarkdownEngine(); |
|
88 | 2 | break; |
|
89 | |||
90 | 5 | case "rst": |
|
91 | 2 | $pd = new RstEngine(); |
|
92 | 2 | $pd->setIncludePolicy(true, getcwd()); |
|
93 | 2 | break; |
|
94 | |||
95 | default: |
||
96 | 3 | $pd = new PlainTextEngine(); |
|
97 | 3 | break; |
|
98 | } |
||
99 | |||
100 | 7 | $this->bodyContent = $pd->parse($this->bodyContent); |
|
101 | 7 | } |
|
102 | |||
103 | /** |
||
104 | * @return PageView |
||
105 | */ |
||
106 | public function &getPageView () |
||
110 | |||
111 | public function getJailedPageView () |
||
115 | |||
116 | /** |
||
117 | * Set the parent Page View that this Content Item will have be assigned to |
||
118 | * |
||
119 | * @param PageView $pageView |
||
120 | */ |
||
121 | public function setPageView (&$pageView) |
||
125 | |||
126 | /** |
||
127 | * {@inheritdoc} |
||
128 | */ |
||
129 | public function jsonSerialize() |
||
137 | } |