]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - application/formatter/BookmarkDefaultFormatter.php
Better support for notes permalink
[github/shaarli/Shaarli.git] / application / formatter / BookmarkDefaultFormatter.php
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() && !empty($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 (!empty($this->contextData['index_url'])) {
67 $prefix = rtrim($this->contextData['index_url'], '/') . '/';
68 }
69
70 if (!empty($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 }