aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/formatter
diff options
context:
space:
mode:
Diffstat (limited to 'application/formatter')
-rw-r--r--application/formatter/BookmarkDefaultFormatter.php18
-rw-r--r--application/formatter/BookmarkFormatter.php3
-rw-r--r--application/formatter/BookmarkMarkdownFormatter.php14
-rw-r--r--application/formatter/BookmarkRawFormatter.php4
-rw-r--r--application/formatter/FormatterFactory.php2
5 files changed, 25 insertions, 16 deletions
diff --git a/application/formatter/BookmarkDefaultFormatter.php b/application/formatter/BookmarkDefaultFormatter.php
index d58a5e39..7e0afafc 100644
--- a/application/formatter/BookmarkDefaultFormatter.php
+++ b/application/formatter/BookmarkDefaultFormatter.php
@@ -12,8 +12,8 @@ namespace Shaarli\Formatter;
12 */ 12 */
13class BookmarkDefaultFormatter extends BookmarkFormatter 13class BookmarkDefaultFormatter extends BookmarkFormatter
14{ 14{
15 const SEARCH_HIGHLIGHT_OPEN = '|@@HIGHLIGHT'; 15 protected const SEARCH_HIGHLIGHT_OPEN = '|@@HIGHLIGHT';
16 const SEARCH_HIGHLIGHT_CLOSE = 'HIGHLIGHT@@|'; 16 protected const SEARCH_HIGHLIGHT_CLOSE = 'HIGHLIGHT@@|';
17 17
18 /** 18 /**
19 * @inheritdoc 19 * @inheritdoc
@@ -46,8 +46,13 @@ class BookmarkDefaultFormatter extends BookmarkFormatter
46 $bookmark->getDescription() ?? '', 46 $bookmark->getDescription() ?? '',
47 $bookmark->getAdditionalContentEntry('search_highlight')['description'] ?? [] 47 $bookmark->getAdditionalContentEntry('search_highlight')['description'] ?? []
48 ); 48 );
49 $description = format_description(
50 escape($description),
51 $indexUrl,
52 $this->conf->get('formatter_settings.autolink', true)
53 );
49 54
50 return $this->replaceTokens(format_description(escape($description), $indexUrl)); 55 return $this->replaceTokens($description);
51 } 56 }
52 57
53 /** 58 /**
@@ -63,15 +68,16 @@ class BookmarkDefaultFormatter extends BookmarkFormatter
63 */ 68 */
64 protected function formatTagListHtml($bookmark) 69 protected function formatTagListHtml($bookmark)
65 { 70 {
71 $tagsSeparator = $this->conf->get('general.tags_separator', ' ');
66 if (empty($bookmark->getAdditionalContentEntry('search_highlight')['tags'])) { 72 if (empty($bookmark->getAdditionalContentEntry('search_highlight')['tags'])) {
67 return $this->formatTagList($bookmark); 73 return $this->formatTagList($bookmark);
68 } 74 }
69 75
70 $tags = $this->tokenizeSearchHighlightField( 76 $tags = $this->tokenizeSearchHighlightField(
71 $bookmark->getTagsString(), 77 $bookmark->getTagsString($tagsSeparator),
72 $bookmark->getAdditionalContentEntry('search_highlight')['tags'] 78 $bookmark->getAdditionalContentEntry('search_highlight')['tags']
73 ); 79 );
74 $tags = $this->filterTagList(explode(' ', $tags)); 80 $tags = $this->filterTagList(tags_str2array($tags, $tagsSeparator));
75 $tags = escape($tags); 81 $tags = escape($tags);
76 $tags = $this->replaceTokensArray($tags); 82 $tags = $this->replaceTokensArray($tags);
77 83
@@ -83,7 +89,7 @@ class BookmarkDefaultFormatter extends BookmarkFormatter
83 */ 89 */
84 protected function formatTagString($bookmark) 90 protected function formatTagString($bookmark)
85 { 91 {
86 return implode(' ', $this->formatTagList($bookmark)); 92 return implode($this->conf->get('general.tags_separator'), $this->formatTagList($bookmark));
87 } 93 }
88 94
89 /** 95 /**
diff --git a/application/formatter/BookmarkFormatter.php b/application/formatter/BookmarkFormatter.php
index e1b7f705..124ce78b 100644
--- a/application/formatter/BookmarkFormatter.php
+++ b/application/formatter/BookmarkFormatter.php
@@ -267,7 +267,7 @@ abstract class BookmarkFormatter
267 */ 267 */
268 protected function formatTagString($bookmark) 268 protected function formatTagString($bookmark)
269 { 269 {
270 return implode(' ', $this->formatTagList($bookmark)); 270 return implode($this->conf->get('general.tags_separator', ' '), $this->formatTagList($bookmark));
271 } 271 }
272 272
273 /** 273 /**
@@ -351,6 +351,7 @@ abstract class BookmarkFormatter
351 351
352 /** 352 /**
353 * Format tag list, e.g. remove private tags if the user is not logged in. 353 * Format tag list, e.g. remove private tags if the user is not logged in.
354 * TODO: this method is called multiple time to format tags, the result should be cached.
354 * 355 *
355 * @param array $tags 356 * @param array $tags
356 * 357 *
diff --git a/application/formatter/BookmarkMarkdownFormatter.php b/application/formatter/BookmarkMarkdownFormatter.php
index f7714be9..ee4e8dca 100644
--- a/application/formatter/BookmarkMarkdownFormatter.php
+++ b/application/formatter/BookmarkMarkdownFormatter.php
@@ -16,7 +16,7 @@ class BookmarkMarkdownFormatter extends BookmarkDefaultFormatter
16 /** 16 /**
17 * When this tag is present in a bookmark, its description should not be processed with Markdown 17 * When this tag is present in a bookmark, its description should not be processed with Markdown
18 */ 18 */
19 const NO_MD_TAG = 'nomarkdown'; 19 public const NO_MD_TAG = 'nomarkdown';
20 20
21 /** @var \Parsedown instance */ 21 /** @var \Parsedown instance */
22 protected $parsedown; 22 protected $parsedown;
@@ -71,7 +71,7 @@ class BookmarkMarkdownFormatter extends BookmarkDefaultFormatter
71 $processedDescription = $this->replaceTokens($processedDescription); 71 $processedDescription = $this->replaceTokens($processedDescription);
72 72
73 if (!empty($processedDescription)) { 73 if (!empty($processedDescription)) {
74 $processedDescription = '<div class="markdown">'. $processedDescription . '</div>'; 74 $processedDescription = '<div class="markdown">' . $processedDescription . '</div>';
75 } 75 }
76 76
77 return $processedDescription; 77 return $processedDescription;
@@ -110,7 +110,7 @@ class BookmarkMarkdownFormatter extends BookmarkDefaultFormatter
110 function ($match) use ($allowedProtocols, $indexUrl) { 110 function ($match) use ($allowedProtocols, $indexUrl) {
111 $link = startsWith($match[1], '?') || startsWith($match[1], '/') ? $indexUrl : ''; 111 $link = startsWith($match[1], '?') || startsWith($match[1], '/') ? $indexUrl : '';
112 $link .= whitelist_protocols($match[1], $allowedProtocols); 112 $link .= whitelist_protocols($match[1], $allowedProtocols);
113 return ']('. $link.')'; 113 return '](' . $link . ')';
114 }, 114 },
115 $description 115 $description
116 ); 116 );
@@ -137,7 +137,7 @@ class BookmarkMarkdownFormatter extends BookmarkDefaultFormatter
137 * \p{Mn} - any non marking space (accents, umlauts, etc) 137 * \p{Mn} - any non marking space (accents, umlauts, etc)
138 */ 138 */
139 $regex = '/(^|\s)#([\p{Pc}\p{N}\p{L}\p{Mn}]+)/mui'; 139 $regex = '/(^|\s)#([\p{Pc}\p{N}\p{L}\p{Mn}]+)/mui';
140 $replacement = '$1[#$2]('. $indexUrl .'./add-tag/$2)'; 140 $replacement = '$1[#$2](' . $indexUrl . './add-tag/$2)';
141 141
142 $descriptionLines = explode(PHP_EOL, $description); 142 $descriptionLines = explode(PHP_EOL, $description);
143 $descriptionOut = ''; 143 $descriptionOut = '';
@@ -178,17 +178,17 @@ class BookmarkMarkdownFormatter extends BookmarkDefaultFormatter
178 */ 178 */
179 protected function sanitizeHtml($description) 179 protected function sanitizeHtml($description)
180 { 180 {
181 $escapeTags = array( 181 $escapeTags = [
182 'script', 182 'script',
183 'style', 183 'style',
184 'link', 184 'link',
185 'iframe', 185 'iframe',
186 'frameset', 186 'frameset',
187 'frame', 187 'frame',
188 ); 188 ];
189 foreach ($escapeTags as $tag) { 189 foreach ($escapeTags as $tag) {
190 $description = preg_replace_callback( 190 $description = preg_replace_callback(
191 '#<\s*'. $tag .'[^>]*>(.*</\s*'. $tag .'[^>]*>)?#is', 191 '#<\s*' . $tag . '[^>]*>(.*</\s*' . $tag . '[^>]*>)?#is',
192 function ($match) { 192 function ($match) {
193 return escape($match[0]); 193 return escape($match[0]);
194 }, 194 },
diff --git a/application/formatter/BookmarkRawFormatter.php b/application/formatter/BookmarkRawFormatter.php
index bc372273..4ff07cdf 100644
--- a/application/formatter/BookmarkRawFormatter.php
+++ b/application/formatter/BookmarkRawFormatter.php
@@ -10,4 +10,6 @@ namespace Shaarli\Formatter;
10 * 10 *
11 * @package Shaarli\Formatter 11 * @package Shaarli\Formatter
12 */ 12 */
13class BookmarkRawFormatter extends BookmarkFormatter {} 13class BookmarkRawFormatter extends BookmarkFormatter
14{
15}
diff --git a/application/formatter/FormatterFactory.php b/application/formatter/FormatterFactory.php
index a029579f..bb865aed 100644
--- a/application/formatter/FormatterFactory.php
+++ b/application/formatter/FormatterFactory.php
@@ -41,7 +41,7 @@ class FormatterFactory
41 public function getFormatter(string $type = null): BookmarkFormatter 41 public function getFormatter(string $type = null): BookmarkFormatter
42 { 42 {
43 $type = $type ? $type : $this->conf->get('formatter', 'default'); 43 $type = $type ? $type : $this->conf->get('formatter', 'default');
44 $className = '\\Shaarli\\Formatter\\Bookmark'. ucfirst($type) .'Formatter'; 44 $className = '\\Shaarli\\Formatter\\Bookmark' . ucfirst($type) . 'Formatter';
45 if (!class_exists($className)) { 45 if (!class_exists($className)) {
46 $className = '\\Shaarli\\Formatter\\BookmarkDefaultFormatter'; 46 $className = '\\Shaarli\\Formatter\\BookmarkDefaultFormatter';
47 } 47 }