]>
Commit | Line | Data |
---|---|---|
336a28fa A |
1 | <?php |
2 | ||
3 | namespace Shaarli\Formatter; | |
4 | ||
5 | /** | |
6 | * Class BookmarkDefaultFormatter | |
7 | * | |
8 | * Default bookmark formatter. | |
9 | * Escape values for HTML display and automatically add link to URL and hashtags. | |
10 | * | |
11 | * @package Shaarli\Formatter | |
12 | */ | |
13 | class BookmarkDefaultFormatter extends BookmarkFormatter | |
14 | { | |
15 | /** | |
16 | * @inheritdoc | |
17 | */ | |
18 | public function formatTitle($bookmark) | |
19 | { | |
20 | return escape($bookmark->getTitle()); | |
21 | } | |
22 | ||
23 | /** | |
24 | * @inheritdoc | |
25 | */ | |
26 | public function formatDescription($bookmark) | |
27 | { | |
28 | $indexUrl = ! empty($this->contextData['index_url']) ? $this->contextData['index_url'] : ''; | |
29 | return format_description(escape($bookmark->getDescription()), $indexUrl); | |
30 | } | |
31 | ||
32 | /** | |
33 | * @inheritdoc | |
34 | */ | |
35 | protected function formatTagList($bookmark) | |
36 | { | |
a39acb25 | 37 | return escape(parent::formatTagList($bookmark)); |
336a28fa A |
38 | } |
39 | ||
40 | /** | |
41 | * @inheritdoc | |
42 | */ | |
43 | public function formatTagString($bookmark) | |
44 | { | |
45 | return implode(' ', $this->formatTagList($bookmark)); | |
46 | } | |
47 | ||
48 | /** | |
49 | * @inheritdoc | |
50 | */ | |
51 | public function formatUrl($bookmark) | |
52 | { | |
62412317 | 53 | if ($bookmark->isNote() && isset($this->contextData['index_url'])) { |
301c7ab1 | 54 | return rtrim($this->contextData['index_url'], '/') . '/' . escape(ltrim($bookmark->getUrl(), '/')); |
336a28fa | 55 | } |
301c7ab1 | 56 | |
336a28fa A |
57 | return escape($bookmark->getUrl()); |
58 | } | |
59 | ||
60 | /** | |
61 | * @inheritdoc | |
62 | */ | |
63 | protected function formatRealUrl($bookmark) | |
64 | { | |
301c7ab1 | 65 | if ($bookmark->isNote()) { |
62412317 | 66 | if (isset($this->contextData['index_url'])) { |
301c7ab1 A |
67 | $prefix = rtrim($this->contextData['index_url'], '/') . '/'; |
68 | } | |
69 | ||
62412317 | 70 | if (isset($this->contextData['base_path'])) { |
301c7ab1 A |
71 | $prefix = rtrim($this->contextData['base_path'], '/') . '/'; |
72 | } | |
73 | ||
74 | return escape($prefix ?? '') . escape(ltrim($bookmark->getUrl(), '/')); | |
336a28fa | 75 | } |
301c7ab1 | 76 | |
336a28fa A |
77 | return escape($bookmark->getUrl()); |
78 | } | |
79 | ||
80 | /** | |
81 | * @inheritdoc | |
82 | */ | |
83 | protected function formatThumbnail($bookmark) | |
84 | { | |
85 | return escape($bookmark->getThumbnail()); | |
86 | } | |
87 | } |