mirror of
https://github.com/friendica/friendica
synced 2025-04-25 07:50:10 +00:00
Merge branch 'develop' into merge-2024.09-rc-branch
This commit is contained in:
commit
eb04f3b079
25 changed files with 340 additions and 205 deletions
|
@ -157,10 +157,6 @@ class Search extends BaseApi
|
|||
$condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $max_id]);
|
||||
}
|
||||
|
||||
if (!empty($since_id)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $since_id]);
|
||||
}
|
||||
|
||||
if (!empty($min_id)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $min_id]);
|
||||
|
||||
|
|
|
@ -23,12 +23,12 @@ class ActivityPubConversion extends BaseModule
|
|||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
function visible_whitespace($s)
|
||||
{
|
||||
return '<pre>' . htmlspecialchars($s) . '</pre>';
|
||||
}
|
||||
|
||||
$results = [];
|
||||
|
||||
$visible_whitespace = function (string $s): string {
|
||||
return '<pre>' . htmlspecialchars($s) . '</pre>';
|
||||
};
|
||||
|
||||
if (!empty($_REQUEST['source'])) {
|
||||
try {
|
||||
$source = json_decode($_REQUEST['source'], true);
|
||||
|
@ -43,11 +43,11 @@ class ActivityPubConversion extends BaseModule
|
|||
$formatted = json_encode($source, JSON_PRETTY_PRINT);
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('Formatted'),
|
||||
'content' => visible_whitespace(trim(var_export($formatted, true), "'")),
|
||||
'content' => $visible_whitespace(trim(var_export($formatted, true), "'")),
|
||||
];
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('Source'),
|
||||
'content' => visible_whitespace(var_export($source, true))
|
||||
'content' => $visible_whitespace(var_export($source, true))
|
||||
];
|
||||
$activity = JsonLD::compact($source);
|
||||
if (!$activity) {
|
||||
|
@ -55,7 +55,7 @@ class ActivityPubConversion extends BaseModule
|
|||
}
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('Activity'),
|
||||
'content' => visible_whitespace(var_export($activity, true))
|
||||
'content' => $visible_whitespace(var_export($activity, true))
|
||||
];
|
||||
|
||||
$type = JsonLD::fetchElement($activity, '@type');
|
||||
|
@ -92,10 +92,6 @@ class ActivityPubConversion extends BaseModule
|
|||
throw new \Exception('No trust for activity type "' . $type . '", so we quit now.');
|
||||
}
|
||||
|
||||
if (!empty($body) && empty($object_data['raw'])) {
|
||||
$object_data['raw'] = $body;
|
||||
}
|
||||
|
||||
// Internal flag for thread completion. See Processor.php
|
||||
if (!empty($activity['thread-completion'])) {
|
||||
$object_data['thread-completion'] = $activity['thread-completion'];
|
||||
|
@ -107,14 +103,14 @@ class ActivityPubConversion extends BaseModule
|
|||
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('Object data'),
|
||||
'content' => visible_whitespace(var_export($object_data, true))
|
||||
'content' => $visible_whitespace(var_export($object_data, true))
|
||||
];
|
||||
|
||||
$item = ActivityPub\Processor::createItem($object_data, true);
|
||||
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('Result Item'),
|
||||
'content' => visible_whitespace(var_export($item, true))
|
||||
'content' => $visible_whitespace(var_export($item, true))
|
||||
];
|
||||
} catch (\Throwable $e) {
|
||||
$results[] = [
|
||||
|
|
|
@ -29,12 +29,12 @@ class Babel extends BaseModule
|
|||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
function visible_whitespace($s)
|
||||
{
|
||||
return '<pre>' . htmlspecialchars($s) . '</pre>';
|
||||
}
|
||||
|
||||
$results = [];
|
||||
|
||||
$visible_whitespace = function (string $s): string {
|
||||
return '<pre>' . htmlspecialchars($s) . '</pre>';
|
||||
};
|
||||
|
||||
if (!empty($request['text'])) {
|
||||
self::checkFormSecurityTokenForbiddenOnError('babel');
|
||||
switch (($request['type'] ?? '') ?: 'bbcode') {
|
||||
|
@ -42,24 +42,24 @@ class Babel extends BaseModule
|
|||
$bbcode = $request['text'];
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('Source input'),
|
||||
'content' => visible_whitespace($bbcode)
|
||||
'content' => $visible_whitespace($bbcode)
|
||||
];
|
||||
|
||||
$plain = Text\BBCode::toPlaintext($bbcode, false);
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('BBCode::toPlaintext'),
|
||||
'content' => visible_whitespace($plain)
|
||||
'content' => $visible_whitespace($plain)
|
||||
];
|
||||
|
||||
$html = Text\BBCode::convertForUriId(0, $bbcode);
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('BBCode::convert (raw HTML)'),
|
||||
'content' => visible_whitespace($html)
|
||||
'content' => $visible_whitespace($html)
|
||||
];
|
||||
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('BBCode::convert (hex)'),
|
||||
'content' => visible_whitespace(bin2hex($html)),
|
||||
'content' => $visible_whitespace(bin2hex($html)),
|
||||
];
|
||||
|
||||
$results[] = [
|
||||
|
@ -70,19 +70,19 @@ class Babel extends BaseModule
|
|||
$bbcode2 = Text\HTML::toBBCode($html);
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('BBCode::convert => HTML::toBBCode'),
|
||||
'content' => visible_whitespace($bbcode2)
|
||||
'content' => $visible_whitespace($bbcode2)
|
||||
];
|
||||
|
||||
$markdown = Text\BBCode::toMarkdown($bbcode);
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('BBCode::toMarkdown'),
|
||||
'content' => visible_whitespace($markdown)
|
||||
'content' => $visible_whitespace($markdown)
|
||||
];
|
||||
|
||||
$html2 = Text\Markdown::convert($markdown);
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('BBCode::toMarkdown => Markdown::convert (raw HTML)'),
|
||||
'content' => visible_whitespace($html2)
|
||||
'content' => $visible_whitespace($html2)
|
||||
];
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('BBCode::toMarkdown => Markdown::convert'),
|
||||
|
@ -92,13 +92,13 @@ class Babel extends BaseModule
|
|||
$bbcode3 = Text\Markdown::toBBCode($markdown);
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('BBCode::toMarkdown => Markdown::toBBCode'),
|
||||
'content' => visible_whitespace($bbcode3)
|
||||
'content' => $visible_whitespace($bbcode3)
|
||||
];
|
||||
|
||||
$bbcode4 = Text\HTML::toBBCode($html2);
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('BBCode::toMarkdown => Markdown::convert => HTML::toBBCode'),
|
||||
'content' => visible_whitespace($bbcode4)
|
||||
'content' => $visible_whitespace($bbcode4)
|
||||
];
|
||||
|
||||
$tags = Text\BBCode::getTags($bbcode);
|
||||
|
@ -106,22 +106,22 @@ class Babel extends BaseModule
|
|||
$body = Item::setHashtags($bbcode);
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('Item Body'),
|
||||
'content' => visible_whitespace($body)
|
||||
'content' => $visible_whitespace($body)
|
||||
];
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('Item Tags'),
|
||||
'content' => visible_whitespace(var_export($tags, true)),
|
||||
'content' => $visible_whitespace(var_export($tags, true)),
|
||||
];
|
||||
|
||||
$body2 = PageInfo::searchAndAppendToBody($bbcode, true);
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('PageInfo::appendToBody'),
|
||||
'content' => visible_whitespace($body2)
|
||||
'content' => $visible_whitespace($body2)
|
||||
];
|
||||
$html3 = Text\BBCode::convertForUriId(0, $body2);
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('PageInfo::appendToBody => BBCode::convert (raw HTML)'),
|
||||
'content' => visible_whitespace($html3)
|
||||
'content' => $visible_whitespace($html3)
|
||||
];
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('PageInfo::appendToBody => BBCode::convert'),
|
||||
|
@ -132,7 +132,7 @@ class Babel extends BaseModule
|
|||
$diaspora = trim($request['text']);
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('Source input (Diaspora format)'),
|
||||
'content' => visible_whitespace($diaspora),
|
||||
'content' => $visible_whitespace($diaspora),
|
||||
];
|
||||
|
||||
$markdown = XML::unescape($diaspora);
|
||||
|
@ -141,13 +141,13 @@ class Babel extends BaseModule
|
|||
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('Source input (Markdown)'),
|
||||
'content' => visible_whitespace($markdown),
|
||||
'content' => $visible_whitespace($markdown),
|
||||
];
|
||||
|
||||
$html = Text\Markdown::convert($markdown);
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('Markdown::convert (raw HTML)'),
|
||||
'content' => visible_whitespace($html),
|
||||
'content' => $visible_whitespace($html),
|
||||
];
|
||||
|
||||
$results[] = [
|
||||
|
@ -158,14 +158,14 @@ class Babel extends BaseModule
|
|||
$bbcode = Text\Markdown::toBBCode($markdown);
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('Markdown::toBBCode'),
|
||||
'content' => visible_whitespace($bbcode),
|
||||
'content' => $visible_whitespace($bbcode),
|
||||
];
|
||||
break;
|
||||
case 'html' :
|
||||
$html = trim($request['text']);
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('Raw HTML input'),
|
||||
'content' => visible_whitespace($html),
|
||||
'content' => $visible_whitespace($html),
|
||||
];
|
||||
|
||||
$results[] = [
|
||||
|
@ -177,12 +177,12 @@ class Babel extends BaseModule
|
|||
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('HTML Purified (raw)'),
|
||||
'content' => visible_whitespace($purified),
|
||||
'content' => $visible_whitespace($purified),
|
||||
];
|
||||
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('HTML Purified (hex)'),
|
||||
'content' => visible_whitespace(bin2hex($purified)),
|
||||
'content' => $visible_whitespace(bin2hex($purified)),
|
||||
];
|
||||
|
||||
$results[] = [
|
||||
|
@ -193,7 +193,7 @@ class Babel extends BaseModule
|
|||
$bbcode = Text\HTML::toBBCode($html);
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('HTML::toBBCode'),
|
||||
'content' => visible_whitespace($bbcode)
|
||||
'content' => $visible_whitespace($bbcode)
|
||||
];
|
||||
|
||||
$html2 = Text\BBCode::convertForUriId(0, $bbcode);
|
||||
|
@ -210,25 +210,25 @@ class Babel extends BaseModule
|
|||
$bbcode2plain = Text\BBCode::toPlaintext($bbcode);
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('HTML::toBBCode => BBCode::toPlaintext'),
|
||||
'content' => visible_whitespace($bbcode2plain),
|
||||
'content' => $visible_whitespace($bbcode2plain),
|
||||
];
|
||||
|
||||
$markdown = Text\HTML::toMarkdown($html);
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('HTML::toMarkdown'),
|
||||
'content' => visible_whitespace($markdown)
|
||||
'content' => $visible_whitespace($markdown)
|
||||
];
|
||||
|
||||
$text = Text\HTML::toPlaintext($html, 0);
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('HTML::toPlaintext'),
|
||||
'content' => visible_whitespace($text),
|
||||
'content' => $visible_whitespace($text),
|
||||
];
|
||||
|
||||
$text = Text\HTML::toPlaintext($html, 0, true);
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('HTML::toPlaintext (compact)'),
|
||||
'content' => visible_whitespace($text),
|
||||
'content' => $visible_whitespace($text),
|
||||
];
|
||||
break;
|
||||
case 'twitter':
|
||||
|
@ -237,16 +237,11 @@ class Babel extends BaseModule
|
|||
if (file_exists('addon/twitter/twitter.php')) {
|
||||
require_once 'addon/twitter/twitter.php';
|
||||
|
||||
if (parse_url($json) !== false) {
|
||||
preg_match('#^https?://(?:mobile\.|www\.)?twitter.com/[^/]+/status/(\d+).*#', $json, $matches);
|
||||
$status = twitter_statuses_show($matches[1]);
|
||||
} else {
|
||||
$status = json_decode($json);
|
||||
}
|
||||
$status = json_decode($json);
|
||||
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('Decoded post'),
|
||||
'content' => visible_whitespace(var_export($status, true)),
|
||||
'content' => $visible_whitespace(var_export($status, true)),
|
||||
];
|
||||
|
||||
$postarray = [];
|
||||
|
@ -263,23 +258,9 @@ class Babel extends BaseModule
|
|||
$postarray['object-type'] = Activity\ObjectType::BOOKMARK;
|
||||
}
|
||||
|
||||
$picture = \twitter_media_entities($status, $postarray);
|
||||
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('Post array before expand entities'),
|
||||
'content' => visible_whitespace(var_export($postarray, true)),
|
||||
];
|
||||
|
||||
$converted = \twitter_expand_entities($postarray['body'], $status, $picture);
|
||||
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('Post converted'),
|
||||
'content' => visible_whitespace(var_export($converted, true)),
|
||||
];
|
||||
|
||||
$results[] = [
|
||||
'title' => DI::l10n()->t('Converted body'),
|
||||
'content' => visible_whitespace($converted['body']),
|
||||
'content' => $visible_whitespace(var_export($postarray, true)),
|
||||
];
|
||||
} else {
|
||||
$results[] = [
|
||||
|
|
|
@ -11,36 +11,43 @@ use Friendica\BaseModule;
|
|||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Network\HTTPException\NotFoundException;
|
||||
use Friendica\Network\HTTPException\UnauthorizedException;
|
||||
|
||||
/**
|
||||
* Print the body of an Item
|
||||
*/
|
||||
class ItemBody extends BaseModule
|
||||
{
|
||||
/**
|
||||
* @throws NotFoundException|UnauthorizedException
|
||||
*
|
||||
* @return string|never
|
||||
*/
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
if (!DI::userSession()->getLocalUserId()) {
|
||||
throw new HTTPException\UnauthorizedException(DI::l10n()->t('Access denied.'));
|
||||
throw new UnauthorizedException(DI::l10n()->t('Access denied.'));
|
||||
}
|
||||
|
||||
if (empty($this->parameters['item'])) {
|
||||
throw new HTTPException\NotFoundException(DI::l10n()->t('Item not found.'));
|
||||
throw new NotFoundException(DI::l10n()->t('Item not found.'));
|
||||
}
|
||||
|
||||
$itemId = intval($this->parameters['item']);
|
||||
|
||||
$item = Post::selectFirst(['body'], ['uid' => [0, DI::userSession()->getLocalUserId()], 'uri-id' => $itemId]);
|
||||
|
||||
if (!empty($item)) {
|
||||
if (DI::mode()->isAjax()) {
|
||||
echo str_replace("\n", '<br />', $item['body']);
|
||||
System::exit();
|
||||
} else {
|
||||
return str_replace("\n", '<br />', $item['body']);
|
||||
}
|
||||
} else {
|
||||
throw new HTTPException\NotFoundException(DI::l10n()->t('Item not found.'));
|
||||
if (empty($item)) {
|
||||
throw new NotFoundException(DI::l10n()->t('Item not found.'));
|
||||
}
|
||||
|
||||
// TODO: Extract this code into controller
|
||||
if (DI::mode()->isAjax()) {
|
||||
echo str_replace("\n", '<br />', $item['body']);
|
||||
System::exit();
|
||||
}
|
||||
|
||||
return str_replace("\n", '<br />', $item['body']);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue