mirror of
https://github.com/friendica/friendica
synced 2024-12-23 08:00:16 +00:00
Merge pull request #6093 from zeroadam/TextToItem
Split text.php to Item class
This commit is contained in:
commit
5d03232dc7
8 changed files with 310 additions and 299 deletions
|
@ -638,7 +638,7 @@ function conversation(App $a, array $items, Pager $pager, $mode, $update, $previ
|
|||
$lock = false;
|
||||
$likebuttons = false;
|
||||
|
||||
$body = prepare_body($item, true, $preview);
|
||||
$body = Item::prepareBody($item, true, $preview);
|
||||
|
||||
list($categories, $folders) = get_cats_and_terms($item);
|
||||
|
||||
|
@ -689,7 +689,7 @@ function conversation(App $a, array $items, Pager $pager, $mode, $update, $previ
|
|||
'owner_name' => $owner_name_e,
|
||||
'owner_url' => $owner_url,
|
||||
'owner_photo' => System::removedBaseUrl(ProxyUtils::proxifyUrl($item['owner-avatar'], false, ProxyUtils::SIZE_THUMB)),
|
||||
'plink' => get_plink($item),
|
||||
'plink' => Item::getPlink($item),
|
||||
'edpost' => false,
|
||||
'isstarred' => $isstarred,
|
||||
'star' => $star,
|
||||
|
|
|
@ -157,7 +157,7 @@ function notification($params)
|
|||
$item = Item::selectFirstForUser($params['uid'], Item::ITEM_FIELDLIST, ['id' => $parent_id]);
|
||||
}
|
||||
|
||||
$item_post_type = item_post_type($item);
|
||||
$item_post_type = Item::postType($item);
|
||||
$itemlink = $item['plink'];
|
||||
|
||||
// "a post"
|
||||
|
|
286
include/text.php
286
include/text.php
|
@ -400,236 +400,6 @@ function redir_private_images($a, &$item)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the "rendered-html" field of the provided item
|
||||
*
|
||||
* Body is preserved to avoid side-effects as we modify it just-in-time for spoilers and private image links
|
||||
*
|
||||
* @param array $item
|
||||
* @param bool $update
|
||||
*
|
||||
* @todo Remove reference, simply return "rendered-html" and "rendered-hash"
|
||||
*/
|
||||
function put_item_in_cache(&$item, $update = false)
|
||||
{
|
||||
$body = $item["body"];
|
||||
|
||||
$rendered_hash = defaults($item, 'rendered-hash', '');
|
||||
$rendered_html = defaults($item, 'rendered-html', '');
|
||||
|
||||
if ($rendered_hash == ''
|
||||
|| $rendered_html == ""
|
||||
|| $rendered_hash != hash("md5", $item["body"])
|
||||
|| Config::get("system", "ignore_cache")
|
||||
) {
|
||||
$a = get_app();
|
||||
redir_private_images($a, $item);
|
||||
|
||||
$item["rendered-html"] = prepare_text($item["body"]);
|
||||
$item["rendered-hash"] = hash("md5", $item["body"]);
|
||||
|
||||
$hook_data = ['item' => $item, 'rendered-html' => $item['rendered-html'], 'rendered-hash' => $item['rendered-hash']];
|
||||
Addon::callHooks('put_item_in_cache', $hook_data);
|
||||
$item['rendered-html'] = $hook_data['rendered-html'];
|
||||
$item['rendered-hash'] = $hook_data['rendered-hash'];
|
||||
unset($hook_data);
|
||||
|
||||
// Force an update if the generated values differ from the existing ones
|
||||
if ($rendered_hash != $item["rendered-hash"]) {
|
||||
$update = true;
|
||||
}
|
||||
|
||||
// Only compare the HTML when we forcefully ignore the cache
|
||||
if (Config::get("system", "ignore_cache") && ($rendered_html != $item["rendered-html"])) {
|
||||
$update = true;
|
||||
}
|
||||
|
||||
if ($update && !empty($item["id"])) {
|
||||
Item::update(['rendered-html' => $item["rendered-html"], 'rendered-hash' => $item["rendered-hash"]],
|
||||
['id' => $item["id"]]);
|
||||
}
|
||||
}
|
||||
|
||||
$item["body"] = $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Given an item array, convert the body element from bbcode to html and add smilie icons.
|
||||
* If attach is true, also add icons for item attachments.
|
||||
*
|
||||
* @param array $item
|
||||
* @param boolean $attach
|
||||
* @param boolean $is_preview
|
||||
* @return string item body html
|
||||
* @hook prepare_body_init item array before any work
|
||||
* @hook prepare_body_content_filter ('item'=>item array, 'filter_reasons'=>string array) before first bbcode to html
|
||||
* @hook prepare_body ('item'=>item array, 'html'=>body string, 'is_preview'=>boolean, 'filter_reasons'=>string array) after first bbcode to html
|
||||
* @hook prepare_body_final ('item'=>item array, 'html'=>body string) after attach icons and blockquote special case handling (spoiler, author)
|
||||
*/
|
||||
function prepare_body(array &$item, $attach = false, $is_preview = false)
|
||||
{
|
||||
$a = get_app();
|
||||
Addon::callHooks('prepare_body_init', $item);
|
||||
|
||||
// In order to provide theme developers more possibilities, event items
|
||||
// are treated differently.
|
||||
if ($item['object-type'] === ACTIVITY_OBJ_EVENT && isset($item['event-id'])) {
|
||||
$ev = Event::getItemHTML($item);
|
||||
return $ev;
|
||||
}
|
||||
|
||||
$tags = \Friendica\Model\Term::populateTagsFromItem($item);
|
||||
|
||||
$item['tags'] = $tags['tags'];
|
||||
$item['hashtags'] = $tags['hashtags'];
|
||||
$item['mentions'] = $tags['mentions'];
|
||||
|
||||
// Compile eventual content filter reasons
|
||||
$filter_reasons = [];
|
||||
if (!$is_preview && public_contact() != $item['author-id']) {
|
||||
if (!empty($item['content-warning']) && (!local_user() || !PConfig::get(local_user(), 'system', 'disable_cw', false))) {
|
||||
$filter_reasons[] = L10n::t('Content warning: %s', $item['content-warning']);
|
||||
}
|
||||
|
||||
$hook_data = [
|
||||
'item' => $item,
|
||||
'filter_reasons' => $filter_reasons
|
||||
];
|
||||
Addon::callHooks('prepare_body_content_filter', $hook_data);
|
||||
$filter_reasons = $hook_data['filter_reasons'];
|
||||
unset($hook_data);
|
||||
}
|
||||
|
||||
// Update the cached values if there is no "zrl=..." on the links.
|
||||
$update = (!local_user() && !remote_user() && ($item["uid"] == 0));
|
||||
|
||||
// Or update it if the current viewer is the intented viewer.
|
||||
if (($item["uid"] == local_user()) && ($item["uid"] != 0)) {
|
||||
$update = true;
|
||||
}
|
||||
|
||||
put_item_in_cache($item, $update);
|
||||
$s = $item["rendered-html"];
|
||||
|
||||
$hook_data = [
|
||||
'item' => $item,
|
||||
'html' => $s,
|
||||
'preview' => $is_preview,
|
||||
'filter_reasons' => $filter_reasons
|
||||
];
|
||||
Addon::callHooks('prepare_body', $hook_data);
|
||||
$s = $hook_data['html'];
|
||||
unset($hook_data);
|
||||
|
||||
if (!$attach) {
|
||||
// Replace the blockquotes with quotes that are used in mails.
|
||||
$mailquote = '<blockquote type="cite" class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">';
|
||||
$s = str_replace(['<blockquote>', '<blockquote class="spoiler">', '<blockquote class="author">'], [$mailquote, $mailquote, $mailquote], $s);
|
||||
return $s;
|
||||
}
|
||||
|
||||
$as = '';
|
||||
$vhead = false;
|
||||
$matches = [];
|
||||
preg_match_all('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\"(?: title=\"(.*?)\")?|', $item['attach'], $matches, PREG_SET_ORDER);
|
||||
foreach ($matches as $mtch) {
|
||||
$mime = $mtch[3];
|
||||
|
||||
$the_url = Contact::magicLinkById($item['author-id'], $mtch[1]);
|
||||
|
||||
if (strpos($mime, 'video') !== false) {
|
||||
if (!$vhead) {
|
||||
$vhead = true;
|
||||
$a->page['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('videos_head.tpl'), [
|
||||
'$baseurl' => System::baseUrl(),
|
||||
]);
|
||||
}
|
||||
|
||||
$url_parts = explode('/', $the_url);
|
||||
$id = end($url_parts);
|
||||
$as .= Renderer::replaceMacros(Renderer::getMarkupTemplate('video_top.tpl'), [
|
||||
'$video' => [
|
||||
'id' => $id,
|
||||
'title' => L10n::t('View Video'),
|
||||
'src' => $the_url,
|
||||
'mime' => $mime,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
$filetype = strtolower(substr($mime, 0, strpos($mime, '/')));
|
||||
if ($filetype) {
|
||||
$filesubtype = strtolower(substr($mime, strpos($mime, '/') + 1));
|
||||
$filesubtype = str_replace('.', '-', $filesubtype);
|
||||
} else {
|
||||
$filetype = 'unkn';
|
||||
$filesubtype = 'unkn';
|
||||
}
|
||||
|
||||
$title = escape_tags(trim(!empty($mtch[4]) ? $mtch[4] : $mtch[1]));
|
||||
$title .= ' ' . $mtch[2] . ' ' . L10n::t('bytes');
|
||||
|
||||
$icon = '<div class="attachtype icon s22 type-' . $filetype . ' subtype-' . $filesubtype . '"></div>';
|
||||
$as .= '<a href="' . strip_tags($the_url) . '" title="' . $title . '" class="attachlink" target="_blank" >' . $icon . '</a>';
|
||||
}
|
||||
|
||||
if ($as != '') {
|
||||
$s .= '<div class="body-attach">'.$as.'<div class="clear"></div></div>';
|
||||
}
|
||||
|
||||
// Map.
|
||||
if (strpos($s, '<div class="map">') !== false && x($item, 'coord')) {
|
||||
$x = Map::byCoordinates(trim($item['coord']));
|
||||
if ($x) {
|
||||
$s = preg_replace('/\<div class\=\"map\"\>/', '$0' . $x, $s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Look for spoiler.
|
||||
$spoilersearch = '<blockquote class="spoiler">';
|
||||
|
||||
// Remove line breaks before the spoiler.
|
||||
while ((strpos($s, "\n" . $spoilersearch) !== false)) {
|
||||
$s = str_replace("\n" . $spoilersearch, $spoilersearch, $s);
|
||||
}
|
||||
while ((strpos($s, "<br />" . $spoilersearch) !== false)) {
|
||||
$s = str_replace("<br />" . $spoilersearch, $spoilersearch, $s);
|
||||
}
|
||||
|
||||
while ((strpos($s, $spoilersearch) !== false)) {
|
||||
$pos = strpos($s, $spoilersearch);
|
||||
$rnd = random_string(8);
|
||||
$spoilerreplace = '<br /> <span id="spoiler-wrap-' . $rnd . '" class="spoiler-wrap fakelink" onclick="openClose(\'spoiler-' . $rnd . '\');">' . L10n::t('Click to open/close') . '</span>'.
|
||||
'<blockquote class="spoiler" id="spoiler-' . $rnd . '" style="display: none;">';
|
||||
$s = substr($s, 0, $pos) . $spoilerreplace . substr($s, $pos + strlen($spoilersearch));
|
||||
}
|
||||
|
||||
// Look for quote with author.
|
||||
$authorsearch = '<blockquote class="author">';
|
||||
|
||||
while ((strpos($s, $authorsearch) !== false)) {
|
||||
$pos = strpos($s, $authorsearch);
|
||||
$rnd = random_string(8);
|
||||
$authorreplace = '<br /> <span id="author-wrap-' . $rnd . '" class="author-wrap fakelink" onclick="openClose(\'author-' . $rnd . '\');">' . L10n::t('Click to open/close') . '</span>'.
|
||||
'<blockquote class="author" id="author-' . $rnd . '" style="display: block;">';
|
||||
$s = substr($s, 0, $pos) . $authorreplace . substr($s, $pos + strlen($authorsearch));
|
||||
}
|
||||
|
||||
// Replace friendica image url size with theme preference.
|
||||
if (x($a->theme_info, 'item_image_size')){
|
||||
$ps = $a->theme_info['item_image_size'];
|
||||
$s = preg_replace('|(<img[^>]+src="[^"]+/photo/[0-9a-f]+)-[0-9]|', "$1-" . $ps, $s);
|
||||
}
|
||||
|
||||
$s = HTML::applyContentFilter($s, $filter_reasons);
|
||||
|
||||
$hook_data = ['item' => $item, 'html' => $s];
|
||||
Addon::callHooks('prepare_body_final', $hook_data);
|
||||
|
||||
return $hook_data['html'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Given a text string, convert from bbcode to html and add smilie icons.
|
||||
*
|
||||
|
@ -723,42 +493,6 @@ function get_cats_and_terms($item)
|
|||
return [$categories, $folders];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get private link for item
|
||||
* @param array $item
|
||||
* @return boolean|array False if item has not plink, otherwise array('href'=>plink url, 'title'=>translated title)
|
||||
*/
|
||||
function get_plink($item) {
|
||||
$a = get_app();
|
||||
|
||||
if ($a->user['nickname'] != "") {
|
||||
$ret = [
|
||||
//'href' => "display/" . $a->user['nickname'] . "/" . $item['id'],
|
||||
'href' => "display/" . $item['guid'],
|
||||
'orig' => "display/" . $item['guid'],
|
||||
'title' => L10n::t('View on separate page'),
|
||||
'orig_title' => L10n::t('view on separate page'),
|
||||
];
|
||||
|
||||
if (x($item, 'plink')) {
|
||||
$ret["href"] = $a->removeBaseURL($item['plink']);
|
||||
$ret["title"] = L10n::t('link to source');
|
||||
}
|
||||
|
||||
} elseif (x($item, 'plink') && ($item['private'] != 1)) {
|
||||
$ret = [
|
||||
'href' => $item['plink'],
|
||||
'orig' => $item['plink'],
|
||||
'title' => L10n::t('link to source'),
|
||||
];
|
||||
} else {
|
||||
$ret = [];
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* return number of bytes in size (K, M, G)
|
||||
* @param string $size_str
|
||||
|
@ -836,26 +570,6 @@ function bb_translate_video($s) {
|
|||
return $s;
|
||||
}
|
||||
|
||||
/**
|
||||
* get translated item type
|
||||
*
|
||||
* @param array $itme
|
||||
* @return string
|
||||
*/
|
||||
function item_post_type($item) {
|
||||
if (!empty($item['event-id'])) {
|
||||
return L10n::t('event');
|
||||
} elseif (!empty($item['resource-id'])) {
|
||||
return L10n::t('photo');
|
||||
} elseif (!empty($item['verb']) && $item['verb'] !== ACTIVITY_POST) {
|
||||
return L10n::t('activity');
|
||||
} elseif ($item['id'] != $item['parent']) {
|
||||
return L10n::t('comment');
|
||||
}
|
||||
|
||||
return L10n::t('post');
|
||||
}
|
||||
|
||||
function normalise_openid($s) {
|
||||
return trim(str_replace(['http://', 'https://'], ['', ''], $s), '/');
|
||||
}
|
||||
|
|
|
@ -697,11 +697,10 @@ function item_post(App $a) {
|
|||
killme();
|
||||
}
|
||||
|
||||
if ($orig_post) {
|
||||
|
||||
if ($orig_post) {
|
||||
// Fill the cache field
|
||||
// This could be done in Item::update as well - but we have to check for the existance of some fields.
|
||||
put_item_in_cache($datarray);
|
||||
Item::putInCache($datarray);
|
||||
|
||||
$fields = [
|
||||
'title' => $datarray['title'],
|
||||
|
@ -817,7 +816,7 @@ function item_post(App $a) {
|
|||
$subject = Email::encodeHeader('[Friendica]' . ' ' . L10n::t('%s posted an update.', $a->user['username']), 'UTF-8');
|
||||
}
|
||||
$link = '<a href="' . System::baseUrl() . '/profile/' . $a->user['nickname'] . '"><img src="' . $author['thumb'] . '" alt="' . $a->user['username'] . '" /></a><br /><br />';
|
||||
$html = prepare_body($datarray);
|
||||
$html = Item::prepareBody($datarray);
|
||||
$message = '<html><body>' . $link . $html . $disclaimer . '</body></html>';
|
||||
$params = [
|
||||
'fromName' => $a->user['username'],
|
||||
|
|
|
@ -1363,7 +1363,7 @@ class BBCode extends BaseObject
|
|||
$text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.*?)\[\/mail\]/", '<a href="mailto:$1">$2</a>', $text);
|
||||
|
||||
// leave open the posibility of [map=something]
|
||||
// this is replaced in prepare_body() which has knowledge of the item location
|
||||
// this is replaced in Item::prepareBody() which has knowledge of the item location
|
||||
|
||||
if (strpos($text, '[/map]') !== false) {
|
||||
$text = preg_replace_callback(
|
||||
|
@ -1474,7 +1474,7 @@ class BBCode extends BaseObject
|
|||
|
||||
$text = str_replace('[hr]', '<hr />', $text);
|
||||
|
||||
// This is actually executed in prepare_body()
|
||||
// This is actually executed in Item::prepareBody()
|
||||
|
||||
$text = str_replace('[nosmile]', '', $text);
|
||||
|
||||
|
|
|
@ -8,23 +8,29 @@ namespace Friendica\Model;
|
|||
|
||||
use Friendica\BaseObject;
|
||||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Content\Text\HTML;
|
||||
use Friendica\Core\Addon;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Core\Lock;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\PConfig;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\Event;
|
||||
use Friendica\Model\FileTag;
|
||||
use Friendica\Model\PermissionSet;
|
||||
use Friendica\Model\Term;
|
||||
use Friendica\Model\ItemURI;
|
||||
use Friendica\Object\Image;
|
||||
use Friendica\Protocol\Diaspora;
|
||||
use Friendica\Protocol\OStatus;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Map;
|
||||
use Friendica\Util\XML;
|
||||
use Friendica\Util\Security;
|
||||
use Text_LanguageDetect;
|
||||
|
@ -1607,7 +1613,7 @@ class Item extends BaseObject
|
|||
$item["deleted"] = $parent_deleted;
|
||||
|
||||
// Fill the cache field
|
||||
put_item_in_cache($item);
|
||||
self::putInCache($item);
|
||||
|
||||
if ($notify) {
|
||||
$item['edit'] = false;
|
||||
|
@ -3247,4 +3253,295 @@ class Item extends BaseObject
|
|||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* get translated item type
|
||||
*
|
||||
* @param array $itme
|
||||
* @return string
|
||||
*/
|
||||
public static function postType($item)
|
||||
{
|
||||
if (!empty($item['event-id'])) {
|
||||
return L10n::t('event');
|
||||
} elseif (!empty($item['resource-id'])) {
|
||||
return L10n::t('photo');
|
||||
} elseif (!empty($item['verb']) && $item['verb'] !== ACTIVITY_POST) {
|
||||
return L10n::t('activity');
|
||||
} elseif ($item['id'] != $item['parent']) {
|
||||
return L10n::t('comment');
|
||||
}
|
||||
|
||||
return L10n::t('post');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the "rendered-html" field of the provided item
|
||||
*
|
||||
* Body is preserved to avoid side-effects as we modify it just-in-time for spoilers and private image links
|
||||
*
|
||||
* @param array $item
|
||||
* @param bool $update
|
||||
*
|
||||
* @todo Remove reference, simply return "rendered-html" and "rendered-hash"
|
||||
*/
|
||||
public static function putInCache(&$item, $update = false)
|
||||
{
|
||||
$body = $item["body"];
|
||||
|
||||
$rendered_hash = defaults($item, 'rendered-hash', '');
|
||||
$rendered_html = defaults($item, 'rendered-html', '');
|
||||
|
||||
if ($rendered_hash == ''
|
||||
|| $rendered_html == ""
|
||||
|| $rendered_hash != hash("md5", $item["body"])
|
||||
|| Config::get("system", "ignore_cache")
|
||||
) {
|
||||
$a = self::getApp();
|
||||
redir_private_images($a, $item);
|
||||
|
||||
$item["rendered-html"] = prepare_text($item["body"]);
|
||||
$item["rendered-hash"] = hash("md5", $item["body"]);
|
||||
|
||||
$hook_data = ['item' => $item, 'rendered-html' => $item['rendered-html'], 'rendered-hash' => $item['rendered-hash']];
|
||||
Addon::callHooks('put_item_in_cache', $hook_data);
|
||||
$item['rendered-html'] = $hook_data['rendered-html'];
|
||||
$item['rendered-hash'] = $hook_data['rendered-hash'];
|
||||
unset($hook_data);
|
||||
|
||||
// Force an update if the generated values differ from the existing ones
|
||||
if ($rendered_hash != $item["rendered-hash"]) {
|
||||
$update = true;
|
||||
}
|
||||
|
||||
// Only compare the HTML when we forcefully ignore the cache
|
||||
if (Config::get("system", "ignore_cache") && ($rendered_html != $item["rendered-html"])) {
|
||||
$update = true;
|
||||
}
|
||||
|
||||
if ($update && !empty($item["id"])) {
|
||||
self::update(
|
||||
[
|
||||
'rendered-html' => $item["rendered-html"],
|
||||
'rendered-hash' => $item["rendered-hash"]
|
||||
],
|
||||
['id' => $item["id"]]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$item["body"] = $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Given an item array, convert the body element from bbcode to html and add smilie icons.
|
||||
* If attach is true, also add icons for item attachments.
|
||||
*
|
||||
* @param array $item
|
||||
* @param boolean $attach
|
||||
* @param boolean $is_preview
|
||||
* @return string item body html
|
||||
* @hook prepare_body_init item array before any work
|
||||
* @hook prepare_body_content_filter ('item'=>item array, 'filter_reasons'=>string array) before first bbcode to html
|
||||
* @hook prepare_body ('item'=>item array, 'html'=>body string, 'is_preview'=>boolean, 'filter_reasons'=>string array) after first bbcode to html
|
||||
* @hook prepare_body_final ('item'=>item array, 'html'=>body string) after attach icons and blockquote special case handling (spoiler, author)
|
||||
*/
|
||||
public static function prepareBody(array &$item, $attach = false, $is_preview = false)
|
||||
{
|
||||
$a = self::getApp();
|
||||
Addon::callHooks('prepare_body_init', $item);
|
||||
|
||||
// In order to provide theme developers more possibilities, event items
|
||||
// are treated differently.
|
||||
if ($item['object-type'] === ACTIVITY_OBJ_EVENT && isset($item['event-id'])) {
|
||||
$ev = Event::getItemHTML($item);
|
||||
return $ev;
|
||||
}
|
||||
|
||||
$tags = Term::populateTagsFromItem($item);
|
||||
|
||||
$item['tags'] = $tags['tags'];
|
||||
$item['hashtags'] = $tags['hashtags'];
|
||||
$item['mentions'] = $tags['mentions'];
|
||||
|
||||
// Compile eventual content filter reasons
|
||||
$filter_reasons = [];
|
||||
if (!$is_preview && public_contact() != $item['author-id']) {
|
||||
if (!empty($item['content-warning']) && (!local_user() || !PConfig::get(local_user(), 'system', 'disable_cw', false))) {
|
||||
$filter_reasons[] = L10n::t('Content warning: %s', $item['content-warning']);
|
||||
}
|
||||
|
||||
$hook_data = [
|
||||
'item' => $item,
|
||||
'filter_reasons' => $filter_reasons
|
||||
];
|
||||
Addon::callHooks('prepare_body_content_filter', $hook_data);
|
||||
$filter_reasons = $hook_data['filter_reasons'];
|
||||
unset($hook_data);
|
||||
}
|
||||
|
||||
// Update the cached values if there is no "zrl=..." on the links.
|
||||
$update = (!local_user() && !remote_user() && ($item["uid"] == 0));
|
||||
|
||||
// Or update it if the current viewer is the intented viewer.
|
||||
if (($item["uid"] == local_user()) && ($item["uid"] != 0)) {
|
||||
$update = true;
|
||||
}
|
||||
|
||||
self::putInCache($item, $update);
|
||||
$s = $item["rendered-html"];
|
||||
|
||||
$hook_data = [
|
||||
'item' => $item,
|
||||
'html' => $s,
|
||||
'preview' => $is_preview,
|
||||
'filter_reasons' => $filter_reasons
|
||||
];
|
||||
Addon::callHooks('prepare_body', $hook_data);
|
||||
$s = $hook_data['html'];
|
||||
unset($hook_data);
|
||||
|
||||
if (!$attach) {
|
||||
// Replace the blockquotes with quotes that are used in mails.
|
||||
$mailquote = '<blockquote type="cite" class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">';
|
||||
$s = str_replace(['<blockquote>', '<blockquote class="spoiler">', '<blockquote class="author">'], [$mailquote, $mailquote, $mailquote], $s);
|
||||
return $s;
|
||||
}
|
||||
|
||||
$as = '';
|
||||
$vhead = false;
|
||||
$matches = [];
|
||||
preg_match_all('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\"(?: title=\"(.*?)\")?|', $item['attach'], $matches, PREG_SET_ORDER);
|
||||
foreach ($matches as $mtch) {
|
||||
$mime = $mtch[3];
|
||||
|
||||
$the_url = Contact::magicLinkById($item['author-id'], $mtch[1]);
|
||||
|
||||
if (strpos($mime, 'video') !== false) {
|
||||
if (!$vhead) {
|
||||
$vhead = true;
|
||||
$a->page['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('videos_head.tpl'), [
|
||||
'$baseurl' => System::baseUrl(),
|
||||
]);
|
||||
}
|
||||
|
||||
$url_parts = explode('/', $the_url);
|
||||
$id = end($url_parts);
|
||||
$as .= Renderer::replaceMacros(Renderer::getMarkupTemplate('video_top.tpl'), [
|
||||
'$video' => [
|
||||
'id' => $id,
|
||||
'title' => L10n::t('View Video'),
|
||||
'src' => $the_url,
|
||||
'mime' => $mime,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
$filetype = strtolower(substr($mime, 0, strpos($mime, '/')));
|
||||
if ($filetype) {
|
||||
$filesubtype = strtolower(substr($mime, strpos($mime, '/') + 1));
|
||||
$filesubtype = str_replace('.', '-', $filesubtype);
|
||||
} else {
|
||||
$filetype = 'unkn';
|
||||
$filesubtype = 'unkn';
|
||||
}
|
||||
|
||||
$title = escape_tags(trim(!empty($mtch[4]) ? $mtch[4] : $mtch[1]));
|
||||
$title .= ' ' . $mtch[2] . ' ' . L10n::t('bytes');
|
||||
|
||||
$icon = '<div class="attachtype icon s22 type-' . $filetype . ' subtype-' . $filesubtype . '"></div>';
|
||||
$as .= '<a href="' . strip_tags($the_url) . '" title="' . $title . '" class="attachlink" target="_blank" >' . $icon . '</a>';
|
||||
}
|
||||
|
||||
if ($as != '') {
|
||||
$s .= '<div class="body-attach">'.$as.'<div class="clear"></div></div>';
|
||||
}
|
||||
|
||||
// Map.
|
||||
if (strpos($s, '<div class="map">') !== false && x($item, 'coord')) {
|
||||
$x = Map::byCoordinates(trim($item['coord']));
|
||||
if ($x) {
|
||||
$s = preg_replace('/\<div class\=\"map\"\>/', '$0' . $x, $s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Look for spoiler.
|
||||
$spoilersearch = '<blockquote class="spoiler">';
|
||||
|
||||
// Remove line breaks before the spoiler.
|
||||
while ((strpos($s, "\n" . $spoilersearch) !== false)) {
|
||||
$s = str_replace("\n" . $spoilersearch, $spoilersearch, $s);
|
||||
}
|
||||
while ((strpos($s, "<br />" . $spoilersearch) !== false)) {
|
||||
$s = str_replace("<br />" . $spoilersearch, $spoilersearch, $s);
|
||||
}
|
||||
|
||||
while ((strpos($s, $spoilersearch) !== false)) {
|
||||
$pos = strpos($s, $spoilersearch);
|
||||
$rnd = random_string(8);
|
||||
$spoilerreplace = '<br /> <span id="spoiler-wrap-' . $rnd . '" class="spoiler-wrap fakelink" onclick="openClose(\'spoiler-' . $rnd . '\');">' . L10n::t('Click to open/close') . '</span>'.
|
||||
'<blockquote class="spoiler" id="spoiler-' . $rnd . '" style="display: none;">';
|
||||
$s = substr($s, 0, $pos) . $spoilerreplace . substr($s, $pos + strlen($spoilersearch));
|
||||
}
|
||||
|
||||
// Look for quote with author.
|
||||
$authorsearch = '<blockquote class="author">';
|
||||
|
||||
while ((strpos($s, $authorsearch) !== false)) {
|
||||
$pos = strpos($s, $authorsearch);
|
||||
$rnd = random_string(8);
|
||||
$authorreplace = '<br /> <span id="author-wrap-' . $rnd . '" class="author-wrap fakelink" onclick="openClose(\'author-' . $rnd . '\');">' . L10n::t('Click to open/close') . '</span>'.
|
||||
'<blockquote class="author" id="author-' . $rnd . '" style="display: block;">';
|
||||
$s = substr($s, 0, $pos) . $authorreplace . substr($s, $pos + strlen($authorsearch));
|
||||
}
|
||||
|
||||
// Replace friendica image url size with theme preference.
|
||||
if (!empty($a->theme_info['item_image_size'])) {
|
||||
$ps = $a->theme_info['item_image_size'];
|
||||
$s = preg_replace('|(<img[^>]+src="[^"]+/photo/[0-9a-f]+)-[0-9]|', "$1-" . $ps, $s);
|
||||
}
|
||||
|
||||
$s = HTML::applyContentFilter($s, $filter_reasons);
|
||||
|
||||
$hook_data = ['item' => $item, 'html' => $s];
|
||||
Addon::callHooks('prepare_body_final', $hook_data);
|
||||
|
||||
return $hook_data['html'];
|
||||
}
|
||||
|
||||
/**
|
||||
* get private link for item
|
||||
* @param array $item
|
||||
* @return boolean|array False if item has not plink, otherwise array('href'=>plink url, 'title'=>translated title)
|
||||
*/
|
||||
public static function getPlink($item)
|
||||
{
|
||||
$a = self::getApp();
|
||||
|
||||
if ($a->user['nickname'] != "") {
|
||||
$ret = [
|
||||
'href' => "display/" . $item['guid'],
|
||||
'orig' => "display/" . $item['guid'],
|
||||
'title' => L10n::t('View on separate page'),
|
||||
'orig_title' => L10n::t('view on separate page'),
|
||||
];
|
||||
|
||||
if (!empty($item['plink'])) {
|
||||
$ret["href"] = $a->removeBaseURL($item['plink']);
|
||||
$ret["title"] = L10n::t('link to source');
|
||||
}
|
||||
|
||||
} elseif (!empty($item['plink']) && ($item['private'] != 1)) {
|
||||
$ret = [
|
||||
'href' => $item['plink'],
|
||||
'orig' => $item['plink'],
|
||||
'title' => L10n::t('link to source'),
|
||||
];
|
||||
} else {
|
||||
$ret = [];
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -315,7 +315,7 @@ class Post extends BaseObject
|
|||
|
||||
localize_item($item);
|
||||
|
||||
$body = prepare_body($item, true);
|
||||
$body = Item::prepareBody($item, true);
|
||||
|
||||
list($categories, $folders) = get_cats_and_terms($item);
|
||||
|
||||
|
@ -392,7 +392,7 @@ class Post extends BaseObject
|
|||
'owner_url' => $this->getOwnerUrl(),
|
||||
'owner_photo' => $a->removeBaseURL(ProxyUtils::proxifyUrl($item['owner-avatar'], false, ProxyUtils::SIZE_THUMB)),
|
||||
'owner_name' => htmlentities($owner_name_e),
|
||||
'plink' => get_plink($item),
|
||||
'plink' => Item::getPlink($item),
|
||||
'edpost' => Feature::isEnabled($conv->getProfileOwner(), 'edit_posts') ? $edpost : '',
|
||||
'isstarred' => $isstarred,
|
||||
'star' => Feature::isEnabled($conv->getProfileOwner(), 'star_posts') ? $star : '',
|
||||
|
|
|
@ -7,6 +7,7 @@ namespace Friendica\Protocol;
|
|||
use Friendica\Core\Logger;
|
||||
use Friendica\Content\Text\HTML;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Model\Item;
|
||||
|
||||
/**
|
||||
* @brief Email class
|
||||
|
@ -331,7 +332,7 @@ class Email
|
|||
|
||||
$part = uniqid("", true);
|
||||
|
||||
$html = prepare_body($item);
|
||||
$html = Item::prepareBody($item);
|
||||
|
||||
$headers .= "Mime-Version: 1.0\n";
|
||||
$headers .= 'Content-Type: multipart/alternative; boundary="=_'.$part.'"'."\n\n";
|
||||
|
|
Loading…
Reference in a new issue