Use plaintext for names and titles
This commit is contained in:
parent
8bb33dccd1
commit
08dafd6d70
|
@ -142,7 +142,7 @@ class BBCode
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'title':
|
case 'title':
|
||||||
$value = self::convertForUriId(0, html_entity_decode($value, ENT_QUOTES, 'UTF-8'), BBCode::EXTERNAL);
|
$value = self::toPlaintext(html_entity_decode($value, ENT_QUOTES, 'UTF-8'));
|
||||||
$value = html_entity_decode($value, ENT_QUOTES, 'UTF-8');
|
$value = html_entity_decode($value, ENT_QUOTES, 'UTF-8');
|
||||||
$value = str_replace(['[', ']'], ['[', ']'], $value);
|
$value = str_replace(['[', ']'], ['[', ']'], $value);
|
||||||
$data['title'] = $value;
|
$data['title'] = $value;
|
||||||
|
@ -226,7 +226,7 @@ class BBCode
|
||||||
* @param bool $keep_urls Whether to keep URLs in the resulting plaintext
|
* @param bool $keep_urls Whether to keep URLs in the resulting plaintext
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function toPlaintext(string $text, bool $keep_urls = true): string
|
public static function toPlaintext(string $text, bool $keep_urls = true, bool $strip_tags = false): string
|
||||||
{
|
{
|
||||||
DI::profiler()->startRecording('rendering');
|
DI::profiler()->startRecording('rendering');
|
||||||
// Remove pictures in advance to avoid unneeded proxy calls
|
// Remove pictures in advance to avoid unneeded proxy calls
|
||||||
|
@ -238,6 +238,9 @@ class BBCode
|
||||||
|
|
||||||
$naked_text = HTML::toPlaintext(self::convert($text, false, BBCode::EXTERNAL, true), 0, !$keep_urls);
|
$naked_text = HTML::toPlaintext(self::convert($text, false, BBCode::EXTERNAL, true), 0, !$keep_urls);
|
||||||
|
|
||||||
|
if ($strip_tags) {
|
||||||
|
$naked_text = strip_tags($naked_text);
|
||||||
|
}
|
||||||
DI::profiler()->stopRecording();
|
DI::profiler()->stopRecording();
|
||||||
return $naked_text;
|
return $naked_text;
|
||||||
}
|
}
|
||||||
|
|
|
@ -928,7 +928,7 @@ class Event
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format the event location.
|
// Format the event location.
|
||||||
$location = self::locationToArray($item['event-location'], $item['uri-id']);
|
$location = self::locationToArray($item['event-location']);
|
||||||
|
|
||||||
// Construct the profile link (magic-auth).
|
// Construct the profile link (magic-auth).
|
||||||
$author = [
|
$author = [
|
||||||
|
@ -979,7 +979,6 @@ class Event
|
||||||
* handled as location name.
|
* handled as location name.
|
||||||
*
|
*
|
||||||
* @param string $s The string with the bbcode formatted location data.
|
* @param string $s The string with the bbcode formatted location data.
|
||||||
* @param int $uri_id The uri-id of the related post
|
|
||||||
*
|
*
|
||||||
* @return array The array with the location data.
|
* @return array The array with the location data.
|
||||||
* 'name' => The name of the location,<br>
|
* 'name' => The name of the location,<br>
|
||||||
|
@ -987,7 +986,7 @@ class Event
|
||||||
* 'coordinates' => Latitude and longitude (e.g. '48.864716,2.349014').<br>
|
* 'coordinates' => Latitude and longitude (e.g. '48.864716,2.349014').<br>
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
private static function locationToArray(string $s, int $uri_id): array
|
private static function locationToArray(string $s): array
|
||||||
{
|
{
|
||||||
if ($s == '') {
|
if ($s == '') {
|
||||||
return [];
|
return [];
|
||||||
|
@ -1013,7 +1012,7 @@ class Event
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$location['name'] = BBCode::convertForUriId($uri_id, $location['name']);
|
$location['name'] = BBCode::toPlaintext($location['name'], false, true);
|
||||||
|
|
||||||
// Construct the map HTML.
|
// Construct the map HTML.
|
||||||
if (isset($location['address'])) {
|
if (isset($location['address'])) {
|
||||||
|
|
|
@ -640,13 +640,13 @@ class Profile
|
||||||
$istoday = true;
|
$istoday = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$title = strip_tags(html_entity_decode(BBCode::convertForUriId($rr['uri-id'], $rr['summary']), ENT_QUOTES, 'UTF-8'));
|
$title = BBCode::toPlaintext($rr['summary'], false, true);
|
||||||
|
|
||||||
if (strlen($title) > 35) {
|
if (strlen($title) > 35) {
|
||||||
$title = substr($title, 0, 32) . '... ';
|
$title = substr($title, 0, 32) . '... ';
|
||||||
}
|
}
|
||||||
|
|
||||||
$description = substr(strip_tags(BBCode::convertForUriId($rr['uri-id'], $rr['desc'])), 0, 32) . '... ';
|
$description = BBCode::toPlaintext($rr['desc'], false, true) . '... ';
|
||||||
if (!$description) {
|
if (!$description) {
|
||||||
$description = DI::l10n()->t('[No description]');
|
$description = DI::l10n()->t('[No description]');
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,7 +147,7 @@ class Introductions extends BaseNotifications
|
||||||
$knowyou = '';
|
$knowyou = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$convertedName = BBCode::convertForUriId($owner['uri-id'], $Introduction->getName());
|
$convertedName = BBCode::toPlaintext($Introduction->getName(), false, true);
|
||||||
|
|
||||||
$helptext = $this->t('Shall your connection be bidirectional or not?');
|
$helptext = $this->t('Shall your connection be bidirectional or not?');
|
||||||
$helptext2 = $this->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $convertedName, $convertedName);
|
$helptext2 = $this->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $convertedName, $convertedName);
|
||||||
|
|
|
@ -118,7 +118,7 @@ class Notify extends BaseEntity
|
||||||
public function updateMsgFromPreamble($epreamble)
|
public function updateMsgFromPreamble($epreamble)
|
||||||
{
|
{
|
||||||
$this->msg = Renderer::replaceMacros($epreamble, ['$itemlink' => $this->link->__toString()]);
|
$this->msg = Renderer::replaceMacros($epreamble, ['$itemlink' => $this->link->__toString()]);
|
||||||
$this->msg_cache = self::formatMessage($this->name_cache, strip_tags(BBCode::convertForUriId(0, $this->msg, BBCode::EXTERNAL)));
|
$this->msg_cache = self::formatMessage($this->name_cache, BBCode::toPlaintext($this->msg, false, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -134,6 +134,6 @@ class Notify extends BaseEntity
|
||||||
*/
|
*/
|
||||||
public static function formatMessage(string $name, string $message): string
|
public static function formatMessage(string $name, string $message): string
|
||||||
{
|
{
|
||||||
return str_replace('{0}', '<span class="contactname">' . strip_tags(BBCode::convertForUriId(0, $name, BBCode::EXTERNAL)) . '</span>', htmlspecialchars($message));
|
return str_replace('{0}', '<span class="contactname">' . BBCode::toPlaintext($name, false, true) . '</span>', htmlspecialchars($message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,7 +222,7 @@ class FormattedNotify extends BaseFactory
|
||||||
$this->baseUrl . '/notify/' . $Notify->id,
|
$this->baseUrl . '/notify/' . $Notify->id,
|
||||||
Contact::getAvatarUrlForUrl($Notify->url, $Notify->uid, Proxy::SIZE_MICRO),
|
Contact::getAvatarUrlForUrl($Notify->url, $Notify->uid, Proxy::SIZE_MICRO),
|
||||||
$Notify->url,
|
$Notify->url,
|
||||||
strip_tags(BBCode::toPlaintext($Notify->msg ?? '')),
|
BBCode::toPlaintext($Notify->msg ?? '', false, true),
|
||||||
DateTimeFormat::local($Notify->date->format(DateTimeFormat::MYSQL), 'r'),
|
DateTimeFormat::local($Notify->date->format(DateTimeFormat::MYSQL), 'r'),
|
||||||
Temporal::getRelativeDate($Notify->date->format(DateTimeFormat::MYSQL)),
|
Temporal::getRelativeDate($Notify->date->format(DateTimeFormat::MYSQL)),
|
||||||
$Notify->seen
|
$Notify->seen
|
||||||
|
|
|
@ -68,7 +68,7 @@ class Notify extends BaseFactory implements ICanCreateFromTableRow
|
||||||
false,
|
false,
|
||||||
$params['verb'] ?? '',
|
$params['verb'] ?? '',
|
||||||
$params['otype'] ?? '',
|
$params['otype'] ?? '',
|
||||||
substr(strip_tags(BBCode::convertForUriId($uri_id, $params['source_name'])), 0, 255),
|
substr(BBCode::toPlaintext($params['source_name'], false, true), 0, 255),
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
$item_id,
|
$item_id,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user