|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PiedWeb\CMSBundle\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use Michelf\Markdown; |
|
6
|
|
|
|
|
7
|
|
|
trait PageExtendedMainContentTrait |
|
8
|
|
|
{ |
|
9
|
|
|
protected $chapeau; |
|
10
|
|
|
|
|
11
|
|
|
protected $readableContent; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @ORM\Column(type="boolean", nullable=true) |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $mainContentIsMarkdown; |
|
17
|
|
|
|
|
18
|
|
|
public static function removeHtmlComments(string $content) |
|
19
|
|
|
{ |
|
20
|
|
|
return preg_replace('/<!--(.|\s)*?-->/', '', $content); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
protected function manageMainContent() |
|
24
|
|
|
{ |
|
25
|
|
|
$content = (string) $this->mainContentIsMarkdown ? Markdown::defaultTransform($this->getMainContent()) : $this->getMainContent(); |
|
|
|
|
|
|
26
|
|
|
$content = explode('<!--break-->', $content); |
|
27
|
|
|
|
|
28
|
|
|
$this->chapeau = isset($content[1]) ? self::removeHtmlComments($content[0]) : null; |
|
29
|
|
|
$this->readableContent = self::removeHtmlComments(isset($content[1]) ? $content[1] : $content[0]); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function getReadableContent() |
|
33
|
|
|
{ |
|
34
|
|
|
if (null === $this->readableContent) { |
|
35
|
|
|
$this->manageMainContent(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
return $this->readableContent; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function getChapeau() |
|
42
|
|
|
{ |
|
43
|
|
|
if (null === $this->readableContent) { |
|
44
|
|
|
$this->manageMainContent(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
return $this->chapeau; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Shortcut, will be destroy soon. |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getSubtitle() |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->getEmc('subtitle'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function getEmc($name) |
|
|
|
|
|
|
59
|
|
|
{ |
|
60
|
|
|
if (preg_match('/<!--"subtitle"--(.*)--\/-->/s', $this->getMainContent(), $match)) { |
|
61
|
|
|
return $match[1]; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function mainContentIsMarkdown(): bool |
|
66
|
|
|
{ |
|
67
|
|
|
return null === $this->mainContentIsMarkdown ? false : $this->mainContentIsMarkdown; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function setMainContentIsMarkdown(bool $mainContentIsMarkdown): self |
|
71
|
|
|
{ |
|
72
|
|
|
$this->mainContentIsMarkdown = $mainContentIsMarkdown; |
|
73
|
|
|
|
|
74
|
|
|
return $this; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|