diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-10-13 12:05:08 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-10-13 12:05:08 +0200 |
commit | b6f678a5a1d15acf284ebcec16c905e976671ce1 (patch) | |
tree | 33c7da831482ed79c44896ef19c73c72ada84f2e /application/formatter/BookmarkDefaultFormatter.php | |
parent | b14687036b9b800681197f51fdc47e62f0c88e2e (diff) | |
parent | 1c1520b6b98ab20201bfe15577782a52320339df (diff) | |
download | Shaarli-b6f678a5a1d15acf284ebcec16c905e976671ce1.tar.gz Shaarli-b6f678a5a1d15acf284ebcec16c905e976671ce1.tar.zst Shaarli-b6f678a5a1d15acf284ebcec16c905e976671ce1.zip |
Merge branch 'v0.12' into latest
Diffstat (limited to 'application/formatter/BookmarkDefaultFormatter.php')
-rw-r--r-- | application/formatter/BookmarkDefaultFormatter.php | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/application/formatter/BookmarkDefaultFormatter.php b/application/formatter/BookmarkDefaultFormatter.php new file mode 100644 index 00000000..9d4a0fa0 --- /dev/null +++ b/application/formatter/BookmarkDefaultFormatter.php | |||
@@ -0,0 +1,87 @@ | |||
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 | { | ||
37 | return escape(parent::formatTagList($bookmark)); | ||
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 | { | ||
53 | if ($bookmark->isNote() && isset($this->contextData['index_url'])) { | ||
54 | return rtrim($this->contextData['index_url'], '/') . '/' . escape(ltrim($bookmark->getUrl(), '/')); | ||
55 | } | ||
56 | |||
57 | return escape($bookmark->getUrl()); | ||
58 | } | ||
59 | |||
60 | /** | ||
61 | * @inheritdoc | ||
62 | */ | ||
63 | protected function formatRealUrl($bookmark) | ||
64 | { | ||
65 | if ($bookmark->isNote()) { | ||
66 | if (isset($this->contextData['index_url'])) { | ||
67 | $prefix = rtrim($this->contextData['index_url'], '/') . '/'; | ||
68 | } | ||
69 | |||
70 | if (isset($this->contextData['base_path'])) { | ||
71 | $prefix = rtrim($this->contextData['base_path'], '/') . '/'; | ||
72 | } | ||
73 | |||
74 | return escape($prefix ?? '') . escape(ltrim($bookmark->getUrl(), '/')); | ||
75 | } | ||
76 | |||
77 | return escape($bookmark->getUrl()); | ||
78 | } | ||
79 | |||
80 | /** | ||
81 | * @inheritdoc | ||
82 | */ | ||
83 | protected function formatThumbnail($bookmark) | ||
84 | { | ||
85 | return escape($bookmark->getThumbnail()); | ||
86 | } | ||
87 | } | ||