X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fbbcode.php;h=cad7ddc9251df74ca149e7713efcf341c5d541f2;hb=b4d14164bb47a76e62977447816fae5b65ea4da7;hp=749a7c5946729ddb5828ea9d723c5da71ebe9a0c;hpb=af6ca96e66a15b91b3bb276067ec0a33cc8d17e7;p=friendica.git diff --git a/include/bbcode.php b/include/bbcode.php index 749a7c5946..cad7ddc925 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -2,14 +2,15 @@ use Friendica\App; use Friendica\Content\Smilies; +use Friendica\Content\OEmbed; +use Friendica\Core\Addon; use Friendica\Core\Cache; use Friendica\Core\System; use Friendica\Core\Config; use Friendica\Model\Contact; +use Friendica\Util\Map; -require_once 'include/oembed.php'; require_once 'include/event.php'; -require_once 'include/map.php'; require_once 'mod/proxy.php'; require_once 'include/plaintext.php'; @@ -33,76 +34,85 @@ function bb_PictureCache($matches) { function bb_map_coords($match) { // the extra space in the following line is intentional - return str_replace($match[0], '
' . generate_map(str_replace('/', ' ', $match[1])) . '
', $match[0]); + return str_replace($match[0], '
' . Map::byCoordinates(str_replace('/', ' ', $match[1])) . '
', $match[0]); } function bb_map_location($match) { // the extra space in the following line is intentional - return str_replace($match[0], '
' . generate_named_map($match[1]) . '
', $match[0]); + return str_replace($match[0], '
' . Map::byLocation($match[1]) . '
', $match[0]); } -function bb_attachment($Text, $simplehtml = false, $tryoembed = true) { - - $data = get_attachment_data($Text); +/** + * Processes [attachment] tags + * + * Note: Can produce a [bookmark] tag in the returned string + * + * @brief Processes [attachment] tags + * @param string $return + * @param bool|int $simplehtml + * @param bool $tryoembed + * @return string + */ +function bb_attachment($return, $simplehtml = false, $tryoembed = true) +{ + $data = get_attachment_data($return); if (!$data) { - return $Text; + return $return; } if (isset($data["title"])) { $data["title"] = strip_tags($data["title"]); - $data["title"] = str_replace(array("http://", "https://"), "", $data["title"]); + $data["title"] = str_replace(["http://", "https://"], "", $data["title"]); } - if (((strpos($data["text"], "[img=") !== false) - || (strpos($data["text"], "[img]") !== false) - || Config::get('system', 'always_show_preview')) - && ($data["image"] != "")) { + if (((strpos($data["text"], "[img=") !== false) || (strpos($data["text"], "[img]") !== false) || Config::get('system', 'always_show_preview')) && ($data["image"] != "")) { $data["preview"] = $data["image"]; $data["image"] = ""; } + $return = ''; if ($simplehtml == 7) { - $text = style_url_for_mastodon($data["url"]); + $return = style_url_for_mastodon($data["url"]); } elseif (($simplehtml != 4) && ($simplehtml != 0)) { - $text = sprintf('%s
', $data["url"], $data["title"]); + $return = sprintf('%s
', $data["url"], $data["title"]); } else { - if ($simplehtml != 4) { - $text = sprintf('', $data["type"]); - } else { - $span_end = ''; - } - - $bookmark = array(sprintf('[bookmark=%s]%s[/bookmark]', $data["url"], $data["title"]), $data["url"], $data["title"]); - if ($tryoembed) { - $oembed = tryoembed($bookmark); - } else { - $oembed = $bookmark[0]; - } + try { + if ($tryoembed && OEmbed::isAllowedURL($data['url'])) { + $return = OEmbed::getHTML($data['url'], $data['title']); + } else { + throw new Exception('OEmbed is disabled for this attachment.'); + } + } catch (Exception $e) { + if ($simplehtml != 4) { + $return = sprintf('
', $data["type"]); + } - if (strstr(strtolower($oembed), "