X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Ftext.php;h=9fae74252bd0f0b1c22762e291a64f5413b887da;hb=e74f186b3488dfe2eb607f21f7f3c53e8a392333;hp=05575887a1fa7a020adab19200f2259607197d55;hpb=fa95911fdb2209907572381c62b1fa70088af634;p=friendica.git diff --git a/include/text.php b/include/text.php index 05575887a1..9fae74252b 100644 --- a/include/text.php +++ b/include/text.php @@ -7,18 +7,21 @@ use Friendica\App; use Friendica\Content\ContactSelector; use Friendica\Content\Feature; use Friendica\Content\Smilies; +use Friendica\Content\Text\BBCode; use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\PConfig; use Friendica\Core\System; use Friendica\Database\DBM; +use Friendica\Model\Item; use Friendica\Model\Profile; -use Friendica\Model\Term; +use Friendica\Render\FriendicaSmarty; use Friendica\Util\DateTimeFormat; use Friendica\Util\Map; require_once "mod/proxy.php"; +require_once "include/event.php"; require_once "include/conversation.php"; /** @@ -486,31 +489,6 @@ function item_new_uri($hostname, $uid, $guid = "") { return $uri; } - -/** - * Generate a guaranteed unique photo ID. - * safe from birthday paradox - * - * @return string - */ -function photo_new_resource() { - - do { - $found = false; - $resource = hash('md5',uniqid(mt_rand(),true)); - $r = q("SELECT `id` FROM `photo` WHERE `resource-id` = '%s' LIMIT 1", - dbesc($resource) - ); - - if (DBM::is_result($r)) { - $found = true; - } - } while ($found == true); - - return $resource; -} - - /** * @deprecated * wrapper to load a view template, checking for alternate @@ -1084,7 +1062,7 @@ function linkify($s) { * Load poke verbs * * @return array index is present tense verb - value is array containing past tense verb, translation of present, translation of past + * value is array containing past tense verb, translation of present, translation of past * @hook poke_verbs pokes array */ function get_poke_verbs() { @@ -1191,8 +1169,25 @@ 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"]; + + // Add the content warning + if (!empty($item['content-warning'])) { + $item["body"] = $item['content-warning'] . '[spoiler]' . $item["body"] . '[/spoiler]'; + } + $rendered_hash = defaults($item, 'rendered-hash', ''); if ($rendered_hash == '' @@ -1200,22 +1195,19 @@ function put_item_in_cache(&$item, $update = false) || $rendered_hash != hash("md5", $item["body"]) || Config::get("system", "ignore_cache") ) { - // The function "redir_private_images" changes the body. - // I'm not sure if we should store it permanently, so we save the old value. - $body = $item["body"]; - $a = get_app(); redir_private_images($a, $item); $item["rendered-html"] = prepare_text($item["body"]); $item["rendered-hash"] = hash("md5", $item["body"]); - $item["body"] = $body; if ($update && ($item["id"] > 0)) { dba::update('item', ['rendered-html' => $item["rendered-html"], 'rendered-hash' => $item["rendered-hash"]], ['id' => $item["id"]], false); } } + + $item["body"] = $body; } /** @@ -1303,62 +1295,55 @@ function prepare_body(&$item, $attach = false, $preview = false) { $as = ''; $vhead = false; - $arr = explode('[/attach],', $item['attach']); - if (count($arr)) { - foreach ($arr as $r) { - $matches = false; - $icon = ''; - $cnt = preg_match_all('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|',$r ,$matches, PREG_SET_ORDER); - if ($cnt) { - foreach ($matches as $mtch) { - $mime = $mtch[3]; - - if ((local_user() == $item['uid']) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == NETWORK_DFRN)) { - $the_url = 'redir/' . $item['contact-id'] . '?f=1&url=' . $mtch[1]; - } else { - $the_url = $mtch[1]; - } - - if (strpos($mime, 'video') !== false) { - if (!$vhead) { - $vhead = true; - $a->page['htmlhead'] .= replace_macros(get_markup_template('videos_head.tpl'), [ - '$baseurl' => System::baseUrl(), - ]); - $a->page['end'] .= replace_macros(get_markup_template('videos_end.tpl'), [ - '$baseurl' => System::baseUrl(), - ]); - } - - $id = end(explode('/', $the_url)); - $as .= replace_macros(get_markup_template('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 = ((strlen(trim($mtch[4]))) ? escape_tags(trim($mtch[4])) : escape_tags($mtch[1])); - $title .= ' ' . $mtch[2] . ' ' . L10n::t('bytes'); - - $icon = '
'; - $as .= '' . $icon . ''; - } + $matches = []; + preg_match_all('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\"(?: title=\"(.*?)\")?|', $item['attach'], $matches, PREG_SET_ORDER); + foreach ($matches as $mtch) { + $mime = $mtch[3]; + + if ((local_user() == $item['uid']) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == NETWORK_DFRN)) { + $the_url = 'redir/' . $item['contact-id'] . '?f=1&url=' . $mtch[1]; + } else { + $the_url = $mtch[1]; + } + + if (strpos($mime, 'video') !== false) { + if (!$vhead) { + $vhead = true; + $a->page['htmlhead'] .= replace_macros(get_markup_template('videos_head.tpl'), [ + '$baseurl' => System::baseUrl(), + ]); + $a->page['end'] .= replace_macros(get_markup_template('videos_end.tpl'), [ + '$baseurl' => System::baseUrl(), + ]); } + + $id = end(explode('/', $the_url)); + $as .= replace_macros(get_markup_template('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 = '
'; + $as .= '' . $icon . ''; } + if ($as != '') { $s .= '
'.$as.'
'; } @@ -1421,13 +1406,10 @@ function prepare_body(&$item, $attach = false, $preview = false) { * @return string Formattet HTML. */ function prepare_text($text) { - - require_once 'include/bbcode.php'; - if (stristr($text, '[nosmile]')) { - $s = bbcode($text); + $s = BBCode::convert($text); } else { - $s = Smilies::replace(bbcode($text)); + $s = Smilies::replace(BBCode::convert($text)); } return trim($s); @@ -1897,16 +1879,10 @@ function file_tag_save_file($uid, $item, $file) intval($uid) ); if (DBM::is_result($r)) { - if (! stristr($r[0]['file'],'[' . file_tag_encode($file) . ']')) { - q("UPDATE `item` SET `file` = '%s' WHERE `id` = %d AND `uid` = %d", - dbesc($r[0]['file'] . '[' . file_tag_encode($file) . ']'), - intval($item), - intval($uid) - ); + if (!stristr($r[0]['file'],'[' . file_tag_encode($file) . ']')) { + $fields = ['file' => $r[0]['file'] . '[' . file_tag_encode($file) . ']']; + Item::update($fields, ['id' => $item]); } - - Term::insertFromFileFieldByItemId($item); - $saved = PConfig::get($uid, 'system', 'filetags'); if (!strlen($saved) || !stristr($saved, '[' . file_tag_encode($file) . ']')) { PConfig::set($uid, 'system', 'filetags', $saved . '[' . file_tag_encode($file) . ']'); @@ -1938,13 +1914,8 @@ function file_tag_unsave_file($uid, $item, $file, $cat = false) return false; } - q("UPDATE `item` SET `file` = '%s' WHERE `id` = %d AND `uid` = %d", - dbesc(str_replace($pattern,'',$r[0]['file'])), - intval($item), - intval($uid) - ); - - Term::insertFromFileFieldByItemId($item); + $fields = ['file' => str_replace($pattern,'',$r[0]['file'])]; + Item::update($fields, ['id' => $item]); $r = q("SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d", dbesc($file),