Merge pull request 'Use "convertForUriId" whenever possible' (#1404) from heluecht/friendica-addons:more-privacy into develop

Reviewed-on: friendica/friendica-addons#1404
This commit is contained in:
Hypolite Petovan 2023-07-17 14:05:14 +02:00
commit 5d666fbd1e
8 changed files with 21 additions and 19 deletions

View file

@ -14,7 +14,7 @@ use Friendica\Core\Logger;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Core\Config\Util\ConfigFileManager;
use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Model\User;
function impressum_install()
{
@ -45,7 +45,7 @@ function obfuscate_email (string $s): string
function impressum_footer(string &$body)
{
$text = ProxyUtils::proxifyHtml(BBCode::convert(DI::config()->get('impressum', 'footer_text')));
$text = BBCode::convertForUriId(User::getSystemUriId(), DI::config()->get('impressum', 'footer_text'));
if ($text != '') {
DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . DI::baseUrl() . '/addon/impressum/impressum.css" media="all" />';
@ -64,8 +64,8 @@ function impressum_show(string &$body)
$body .= '<h3>' . DI::l10n()->t('Impressum') . '</h3>';
$owner = DI::config()->get('impressum', 'owner');
$owner_profile = DI::config()->get('impressum', 'ownerprofile');
$postal = ProxyUtils::proxifyHtml(BBCode::convert(DI::config()->get('impressum', 'postal')));
$notes = ProxyUtils::proxifyHtml(BBCode::convert(DI::config()->get('impressum', 'notes')));
$postal = BBCode::convertForUriId(User::getSystemUriId(), DI::config()->get('impressum', 'postal'));
$notes = BBCode::convertForUriId(User::getSystemUriId(), DI::config()->get('impressum', 'notes'));
if ($owner) {
if ($owner_profile) {

View file

@ -122,7 +122,7 @@ function langfilter_prepare_body_content_filter(&$hook_data)
$naked_body = strip_tags(
$hook_data['item']['rendered-html']
??''?: // Equivalent of !empty()
BBCode::convert($hook_data['item']['body'], false, BBCode::ACTIVITYPUB, true)
BBCode::convertForUriId($hook_data['item']['uri-id'], $hook_data['item']['body'], BBCode::ACTIVITYPUB)
);
$naked_body = preg_replace('#\s+#', ' ', trim($naked_body));

View file

@ -258,12 +258,13 @@ function mailstream_sender(array $item): string
* Converts a bbcode-encoded subject line into a plaintext version suitable for the subject line of an email
*
* @param string $subject bbcode-encoded subject line
* @param int $uri_id
*
* @return string plaintext subject line
*/
function mailstream_decode_subject(string $subject): string
function mailstream_decode_subject(string $subject, int $uri_id): string
{
$html = BBCode::convert($subject);
$html = BBCode::convertForUriId($uri_id, $subject);
if (!$html) {
return $subject;
}
@ -298,7 +299,7 @@ function mailstream_decode_subject(string $subject): string
function mailstream_subject(array $item): string
{
if ($item['title']) {
return mailstream_decode_subject($item['title']);
return mailstream_decode_subject($item['title'], $item['uri-id']);
}
$parent = $item['thr-parent'];
// Don't look more than 100 levels deep for a subject, in case of loops
@ -311,7 +312,7 @@ function mailstream_subject(array $item): string
break;
}
if ($parent_item['title']) {
return DI::l10n()->t('Re:') . ' ' . mailstream_decode_subject($parent_item['title']);
return DI::l10n()->t('Re:') . ' ' . mailstream_decode_subject($parent_item['title'], $item['uri-id']);
}
$parent = $parent_item['thr-parent'];
}
@ -333,7 +334,7 @@ function mailstream_subject(array $item): string
return DI::l10n()->t("Diaspora post");
}
if ($contact['network'] === 'face') {
$text = mailstream_decode_subject($item['body']);
$text = mailstream_decode_subject($item['body'], $item['uri-id']);
// For some reason these do show up in Facebook
$text = preg_replace('/\xA0$/', '', $text);
$subject = (strlen($text) > 150) ? (substr($text, 0, 140) . '...') : $text;

View file

@ -12,6 +12,7 @@ use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Model\User;
function newmemberwidget_install()
{
@ -39,7 +40,7 @@ function newmemberwidget_network_mod_init ($b)
$ft = DI::config()->get('newmemberwidget','freetext', '');
if (!empty($ft)) {
$t .= '<p>'.BBCode::convert(trim($ft)).'</p>';
$t .= '<p>'.BBCode::convertForUriId(User::getSystemUriId(), trim($ft)).'</p>';
}
$t .= '</div><div class="clear"></div>';

View file

@ -25,6 +25,7 @@ use Friendica\App\BaseURL;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\L10n;
use Friendica\Model\User;
use Friendica\Object\Email;
/**
@ -50,9 +51,9 @@ class NotifyAllEmail extends Email
$subject = $_REQUEST['subject'];
$textversion = strip_tags(html_entity_decode(BBCode::convert(stripslashes(str_replace(["\\r", "\\n"], ["", "\n"], $text))), ENT_QUOTES, 'UTF-8'));
$textversion = strip_tags(html_entity_decode(BBCode::convertForUriId(User::getSystemUriId(), stripslashes(str_replace(["\\r", "\\n"], ["", "\n"], $text))), ENT_QUOTES, 'UTF-8'));
$htmlversion = BBCode::convert(stripslashes(str_replace(["\\r", "\\n"], ["", "<br />\n"], $text)));
$htmlversion = BBCode::convertForUriId(User::getSystemUriId(), stripslashes(str_replace(["\\r", "\\n"], ["", "<br />\n"], $text)));
parent::__construct($sender_name, $sender_email, $sender_email, '', $subject, $htmlversion, $textversion);
}

View file

@ -6,7 +6,6 @@
* Author: Ryan <https://friendica.verya.pe/profile/ryan>
*/
use Friendica\App;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
@ -14,7 +13,6 @@ use Friendica\Core\Renderer;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\User;
use Friendica\Util\Strings;
use OneLogin\Saml2\Utils;
require_once(__DIR__ . '/vendor/autoload.php');
@ -84,7 +82,7 @@ function saml_head(string &$body)
function saml_footer(string &$body)
{
$fragment = addslashes(BBCode::convert(DI::config()->get('saml', 'settings_statement')));
$fragment = addslashes(BBCode::convertForUriId(User::getSystemUriId(), DI::config()->get('saml', 'settings_statement')));
$body .= <<<EOL
<script>
var target=$("#settings-nickname-desc");
@ -163,7 +161,7 @@ function saml_sso_reply()
}
if (!empty($user['uid'])) {
DI::auth()->setForUser($user);
DI::auth()->setForUser(DI::app(), $user);
}
if (isset($_POST['RelayState']) && Utils::getSelfURL() != $_POST['RelayState']) {

View file

@ -1267,7 +1267,7 @@ function tumblr_get_contact_by_url(string $url): ?array
return null;
}
if (is_array($data->response->blog)) {
if (is_array($data->response->blog) || empty($data->response->blog)) {
Logger::warning('Unexpected blog format', ['blog' => $blog, 'data' => $data]);
return null;
}

View file

@ -15,6 +15,7 @@ use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Model\User;
use Friendica\Util\XML;
function wppost_install()
@ -92,7 +93,7 @@ function wppost_settings_post(array &$b)
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'wppost', 'wp_blog', trim($_POST['wp_blog']));
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'wppost', 'backlink', intval($_POST['wp_backlink']));
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'wppost', 'shortcheck', intval($_POST['wp_shortcheck']));
$wp_backlink_text = BBCode::convert(trim($_POST['wp_backlink_text']), false, BBCode::BACKLINK);
$wp_backlink_text = BBCode::convertForUriId(User::getSystemUriId(), trim($_POST['wp_backlink_text']), BBCode::BACKLINK);
$wp_backlink_text = HTML::toPlaintext($wp_backlink_text, 0, true);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'wppost', 'wp_backlink_text', $wp_backlink_text);
}