2019-05-25 15:46:47 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Shaarli\Formatter;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class BookmarkDefaultFormatter
|
|
|
|
*
|
|
|
|
* Default bookmark formatter.
|
|
|
|
* Escape values for HTML display and automatically add link to URL and hashtags.
|
|
|
|
*
|
|
|
|
* @package Shaarli\Formatter
|
|
|
|
*/
|
|
|
|
class BookmarkDefaultFormatter extends BookmarkFormatter
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public function formatTitle($bookmark)
|
|
|
|
{
|
|
|
|
return escape($bookmark->getTitle());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public function formatDescription($bookmark)
|
|
|
|
{
|
|
|
|
$indexUrl = ! empty($this->contextData['index_url']) ? $this->contextData['index_url'] : '';
|
|
|
|
return format_description(escape($bookmark->getDescription()), $indexUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
protected function formatTagList($bookmark)
|
|
|
|
{
|
2020-01-18 11:33:23 +01:00
|
|
|
return escape(parent::formatTagList($bookmark));
|
2019-05-25 15:46:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public function formatTagString($bookmark)
|
|
|
|
{
|
|
|
|
return implode(' ', $this->formatTagList($bookmark));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
public function formatUrl($bookmark)
|
|
|
|
{
|
2020-07-28 21:09:22 +02:00
|
|
|
if ($bookmark->isNote() && isset($this->contextData['index_url'])) {
|
2020-07-28 20:46:11 +02:00
|
|
|
return rtrim($this->contextData['index_url'], '/') . '/' . escape(ltrim($bookmark->getUrl(), '/'));
|
2019-05-25 15:46:47 +02:00
|
|
|
}
|
2020-07-28 20:46:11 +02:00
|
|
|
|
2019-05-25 15:46:47 +02:00
|
|
|
return escape($bookmark->getUrl());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
protected function formatRealUrl($bookmark)
|
|
|
|
{
|
2020-07-28 20:46:11 +02:00
|
|
|
if ($bookmark->isNote()) {
|
2020-07-28 21:09:22 +02:00
|
|
|
if (isset($this->contextData['index_url'])) {
|
2020-07-28 20:46:11 +02:00
|
|
|
$prefix = rtrim($this->contextData['index_url'], '/') . '/';
|
|
|
|
}
|
|
|
|
|
2020-07-28 21:09:22 +02:00
|
|
|
if (isset($this->contextData['base_path'])) {
|
2020-07-28 20:46:11 +02:00
|
|
|
$prefix = rtrim($this->contextData['base_path'], '/') . '/';
|
|
|
|
}
|
|
|
|
|
|
|
|
return escape($prefix ?? '') . escape(ltrim($bookmark->getUrl(), '/'));
|
2019-05-25 15:46:47 +02:00
|
|
|
}
|
2020-07-28 20:46:11 +02:00
|
|
|
|
2019-05-25 15:46:47 +02:00
|
|
|
return escape($bookmark->getUrl());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
protected function formatThumbnail($bookmark)
|
|
|
|
{
|
|
|
|
return escape($bookmark->getThumbnail());
|
|
|
|
}
|
|
|
|
}
|