Merge pull request #11647 from Quix0r/fixes/type-error-exception
Followup PR for bad #11624 PR
This commit is contained in:
commit
341d8860d1
3 changed files with 27 additions and 17 deletions
|
@ -143,6 +143,14 @@ class HTML
|
||||||
*/
|
*/
|
||||||
public static function toBBCode(string $message, string $basepath = ''): string
|
public static function toBBCode(string $message, string $basepath = ''): string
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* Check if message is empty to prevent a lot code below being executed
|
||||||
|
* for just an empty message.
|
||||||
|
*/
|
||||||
|
if (empty($message)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
DI::profiler()->startRecording('rendering');
|
DI::profiler()->startRecording('rendering');
|
||||||
$message = str_replace("\r", "", $message);
|
$message = str_replace("\r", "", $message);
|
||||||
|
|
||||||
|
|
|
@ -241,9 +241,10 @@ class APContact
|
||||||
$apcontact['name'] = $apcontact['nick'];
|
$apcontact['name'] = $apcontact['nick'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$apcontact['about'] = HTML::toBBCode(JsonLD::fetchElement($compacted, 'as:summary', '@value'));
|
$apcontact['about'] = HTML::toBBCode(JsonLD::fetchElement($compacted, 'as:summary', '@value') ?? '');
|
||||||
|
|
||||||
$ims = JsonLD::fetchElementArray($compacted, 'vcard:hasInstantMessage');
|
$ims = JsonLD::fetchElementArray($compacted, 'vcard:hasInstantMessage');
|
||||||
|
|
||||||
if (!empty($ims)) {
|
if (!empty($ims)) {
|
||||||
foreach ($ims as $link) {
|
foreach ($ims as $link) {
|
||||||
if (substr($link, 0, 5) == 'xmpp:') {
|
if (substr($link, 0, 5) == 'xmpp:') {
|
||||||
|
|
|
@ -71,7 +71,7 @@ class Processor
|
||||||
* @param array $languages
|
* @param array $languages
|
||||||
* @return string language JSON
|
* @return string language JSON
|
||||||
*/
|
*/
|
||||||
private static function processLanguages(array $languages)
|
private static function processLanguages(array $languages): string
|
||||||
{
|
{
|
||||||
$codes = array_keys($languages);
|
$codes = array_keys($languages);
|
||||||
$lang = [];
|
$lang = [];
|
||||||
|
@ -88,12 +88,13 @@ class Processor
|
||||||
/**
|
/**
|
||||||
* Replaces emojis in the body
|
* Replaces emojis in the body
|
||||||
*
|
*
|
||||||
* @param array $emojis
|
* @param int $uri_id
|
||||||
* @param string $body
|
* @param string $body
|
||||||
|
* @param array $emojis
|
||||||
*
|
*
|
||||||
* @return string with replaced emojis
|
* @return string with replaced emojis
|
||||||
*/
|
*/
|
||||||
private static function replaceEmojis(int $uri_id, $body, array $emojis)
|
private static function replaceEmojis(int $uri_id, string $body, array $emojis)
|
||||||
{
|
{
|
||||||
$body = strtr($body,
|
$body = strtr($body,
|
||||||
array_combine(
|
array_combine(
|
||||||
|
@ -143,7 +144,7 @@ class Processor
|
||||||
* @param array $activity
|
* @param array $activity
|
||||||
* @param array $item
|
* @param array $item
|
||||||
*/
|
*/
|
||||||
private static function storeAttachments($activity, $item)
|
private static function storeAttachments(array $activity, array $item)
|
||||||
{
|
{
|
||||||
if (empty($activity['attachments'])) {
|
if (empty($activity['attachments'])) {
|
||||||
return;
|
return;
|
||||||
|
@ -160,7 +161,7 @@ class Processor
|
||||||
* @param array $activity
|
* @param array $activity
|
||||||
* @param array $item
|
* @param array $item
|
||||||
*/
|
*/
|
||||||
private static function storeQuestion($activity, $item)
|
private static function storeQuestion(array $activity, array $item)
|
||||||
{
|
{
|
||||||
if (empty($activity['question'])) {
|
if (empty($activity['question'])) {
|
||||||
return;
|
return;
|
||||||
|
@ -191,7 +192,7 @@ class Processor
|
||||||
* @param array $activity Activity array
|
* @param array $activity Activity array
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
public static function updateItem($activity)
|
public static function updateItem(array $activity)
|
||||||
{
|
{
|
||||||
$item = Post::selectFirst(['uri', 'uri-id', 'thr-parent', 'gravity', 'post-type'], ['uri' => $activity['id']]);
|
$item = Post::selectFirst(['uri', 'uri-id', 'thr-parent', 'gravity', 'post-type'], ['uri' => $activity['id']]);
|
||||||
if (!DBA::isResult($item)) {
|
if (!DBA::isResult($item)) {
|
||||||
|
@ -262,7 +263,7 @@ class Processor
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws \ImagickException
|
||||||
*/
|
*/
|
||||||
public static function createItem($activity)
|
public static function createItem(array $activity): array
|
||||||
{
|
{
|
||||||
$item = [];
|
$item = [];
|
||||||
$item['verb'] = Activity::POST;
|
$item['verb'] = Activity::POST;
|
||||||
|
@ -411,7 +412,7 @@ class Processor
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws \ImagickException
|
||||||
*/
|
*/
|
||||||
public static function deleteItem($activity)
|
public static function deleteItem(array $activity)
|
||||||
{
|
{
|
||||||
$owner = Contact::getIdForURL($activity['actor']);
|
$owner = Contact::getIdForURL($activity['actor']);
|
||||||
|
|
||||||
|
@ -426,7 +427,7 @@ class Processor
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws \ImagickException
|
||||||
*/
|
*/
|
||||||
public static function addTag($activity)
|
public static function addTag(array $activity)
|
||||||
{
|
{
|
||||||
if (empty($activity['object_content']) || empty($activity['object_id'])) {
|
if (empty($activity['object_content']) || empty($activity['object_id'])) {
|
||||||
return;
|
return;
|
||||||
|
@ -457,7 +458,7 @@ class Processor
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws \ImagickException
|
||||||
*/
|
*/
|
||||||
public static function createActivity($activity, $verb)
|
public static function createActivity(array $activity, string $verb)
|
||||||
{
|
{
|
||||||
$item = self::createItem($activity);
|
$item = self::createItem($activity);
|
||||||
if (empty($item)) {
|
if (empty($item)) {
|
||||||
|
@ -561,7 +562,7 @@ class Processor
|
||||||
* @return int event id
|
* @return int event id
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public static function createEvent($activity, $item)
|
public static function createEvent(array $activity, array $item): int
|
||||||
{
|
{
|
||||||
$event['summary'] = HTML::toBBCode($activity['name'] ?: $activity['summary']);
|
$event['summary'] = HTML::toBBCode($activity['name'] ?: $activity['summary']);
|
||||||
$event['desc'] = HTML::toBBCode($activity['content']);
|
$event['desc'] = HTML::toBBCode($activity['content']);
|
||||||
|
@ -605,7 +606,7 @@ class Processor
|
||||||
* @return array|bool Returns the item array or false if there was an unexpected occurrence
|
* @return array|bool Returns the item array or false if there was an unexpected occurrence
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
private static function processContent($activity, $item)
|
private static function processContent(array $activity, array $item)
|
||||||
{
|
{
|
||||||
if (!empty($activity['mediatype']) && ($activity['mediatype'] == 'text/markdown')) {
|
if (!empty($activity['mediatype']) && ($activity['mediatype'] == 'text/markdown')) {
|
||||||
$item['title'] = strip_tags($activity['name']);
|
$item['title'] = strip_tags($activity['name']);
|
||||||
|
@ -615,8 +616,8 @@ class Processor
|
||||||
$content = $activity['content'];
|
$content = $activity['content'];
|
||||||
} else {
|
} else {
|
||||||
// By default assume "text/html"
|
// By default assume "text/html"
|
||||||
$item['title'] = HTML::toBBCode($activity['name']);
|
$item['title'] = HTML::toBBCode($activity['name'] ?? '');
|
||||||
$content = HTML::toBBCode($activity['content']);
|
$content = HTML::toBBCode($activity['content'] ?? '');
|
||||||
}
|
}
|
||||||
|
|
||||||
$item['title'] = trim(BBCode::toPlaintext($item['title']));
|
$item['title'] = trim(BBCode::toPlaintext($item['title']));
|
||||||
|
@ -650,7 +651,7 @@ class Processor
|
||||||
|
|
||||||
$content = self::removeImplicitMentionsFromBody($content, $parent);
|
$content = self::removeImplicitMentionsFromBody($content, $parent);
|
||||||
}
|
}
|
||||||
$item['content-warning'] = HTML::toBBCode($activity['summary']);
|
$item['content-warning'] = HTML::toBBCode($activity['summary'] ?? '');
|
||||||
$item['raw-body'] = $item['body'] = $content;
|
$item['raw-body'] = $item['body'] = $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1224,7 +1225,7 @@ class Processor
|
||||||
$attributed_to = JsonLD::fetchElement($activity['as:object'], 'as:attributedTo', '@id');
|
$attributed_to = JsonLD::fetchElement($activity['as:object'], 'as:attributedTo', '@id');
|
||||||
$authorid = Contact::getIdForURL($attributed_to);
|
$authorid = Contact::getIdForURL($attributed_to);
|
||||||
|
|
||||||
$body = HTML::toBBCode(JsonLD::fetchElement($activity['as:object'], 'as:content', '@value'));
|
$body = HTML::toBBCode(JsonLD::fetchElement($activity['as:object'], 'as:content', '@value') ?? '');
|
||||||
|
|
||||||
$messageTags = [];
|
$messageTags = [];
|
||||||
$tags = Receiver::processTags(JsonLD::fetchElementArray($activity['as:object'], 'as:tag') ?? []);
|
$tags = Receiver::processTags(JsonLD::fetchElementArray($activity['as:object'], 'as:tag') ?? []);
|
||||||
|
|
Loading…
Reference in a new issue