X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Foembed.php;h=b7c1616feeab0e1f2f550b2ac41081f37d9d759a;hb=e848e376b89a6aaf35054c178c1662d4a23035fa;hp=2490e5ecaa34f20c156ef7845437b37191f0f21c;hpb=41a36606c6ee92c914acbb7f6d9ea79c0a149088;p=friendica.git diff --git a/include/oembed.php b/include/oembed.php old mode 100755 new mode 100644 index 2490e5ecaa..b7c1616fee --- a/include/oembed.php +++ b/include/oembed.php @@ -4,8 +4,12 @@ * @file include/oembed.php */ -use \Friendica\ParseUrl; -use \Friendica\Core\Config; +use Friendica\App; +use Friendica\Core\Cache; +use Friendica\Core\System; +use Friendica\ParseUrl; +use Friendica\Core\Config; +use Friendica\Database\DBM; function oembed_replacecb($matches){ $embedurl=$matches[1]; @@ -17,32 +21,32 @@ function oembed_replacecb($matches){ /** * @brief Get data from an URL to embed its content. - * + * * @param string $embedurl The URL from which the data should be fetched. * @param bool $no_rich_type If set to true rich type content won't be fetched. - * + * * @return bool|object Returns object with embed content or false if no embedable * content exists */ -function oembed_fetch_url($embedurl, $no_rich_type = false){ +function oembed_fetch_url($embedurl, $no_rich_type = false) { $embedurl = trim($embedurl, "'"); $embedurl = trim($embedurl, '"'); $a = get_app(); - $r = q("SELECT * FROM `oembed` WHERE `url` = '%s'", - dbesc(normalise_link($embedurl))); + $condition = array('url' => normalise_link($embedurl)); + $r = dba::select('oembed', array('content'), $condition, array('limit' => 1)); - if (dbm::is_result($r)) { - $txt = $r[0]["content"]; + if (DBM::is_result($r)) { + $txt = $r["content"]; } else { $txt = Cache::get($a->videowidth . $embedurl); } // These media files should now be caught in bbcode.php // left here as a fallback in case this is called from another source - $noexts = array("mp3","mp4","ogg","ogv","oga","ogm","webm"); - $ext = pathinfo(strtolower($embedurl),PATHINFO_EXTENSION); + $noexts = array("mp3", "mp4", "ogg", "ogv", "oga", "ogm", "webm"); + $ext = pathinfo(strtolower($embedurl), PATHINFO_EXTENSION); if (is_null($txt)) { @@ -74,29 +78,15 @@ function oembed_fetch_url($embedurl, $no_rich_type = false){ } } - if ($txt==false || $txt=="") { - $embedly = Config::get("system", "embedly"); - if ($embedly != "") { - // try embedly service - $ourl = "https://api.embed.ly/1/oembed?key=".$embedly."&url=".urlencode($embedurl); - $txt = fetch_url($ourl); - - logger("oembed_fetch_url: ".$txt, LOGGER_DEBUG); - } - } - - $txt=trim($txt); + $txt = trim($txt); - if ($txt[0]!="{") { - $txt='{"type":"error"}'; + if ($txt[0] != "{") { + $txt = '{"type":"error"}'; } else { //save in cache $j = json_decode($txt); if ($j->type != "error") { - q("INSERT INTO `oembed` (`url`, `content`, `created`) VALUES ('%s', '%s', '%s') - ON DUPLICATE KEY UPDATE `content` = '%s', `created` = '%s'", - dbesc(normalise_link($embedurl)), - dbesc($txt), dbesc(datetime_convert()), - dbesc($txt), dbesc(datetime_convert())); + dba::insert('oembed', array('url' => normalise_link($embedurl), + 'content' => $txt, 'created' => datetime_convert()), true); } Cache::set($a->videowidth.$embedurl, $txt, CACHE_DAY); @@ -118,7 +108,7 @@ function oembed_fetch_url($embedurl, $no_rich_type = false){ $j->embedurl = $embedurl; // If fetching information doesn't work, then improve via internal functions - if (($j->type == "error") OR ($no_rich_type AND ($j->type == "rich"))) { + if (($j->type == "error") || ($no_rich_type && ($j->type == "rich"))) { $data = ParseUrl::getSiteinfoCached($embedurl, true, false); $j->type = $data["type"]; @@ -165,7 +155,7 @@ function oembed_format_object($j){ $th=120; $tw = $th*$tr; $tpl=get_markup_template('oembed_video.tpl'); $ret.=replace_macros($tpl, array( - '$baseurl' => App::get_baseurl(), + '$baseurl' => System::baseUrl(), '$embedurl' => $embedurl, '$escapedhtml' => base64_encode($jhtml), '$tw' => $tw, @@ -204,7 +194,7 @@ function oembed_format_object($j){ if (isset($j->author_name)) { $ret.=" (".$j->author_name.")"; } - } elseif (isset($j->provider_name) OR isset($j->author_name)) { + } elseif (isset($j->provider_name) || isset($j->author_name)) { $embedlink = ""; if (isset($j->provider_name)) { $embedlink .= $j->provider_name; @@ -262,7 +252,7 @@ function oembed_iframe($src, $width, $height) { } $width = '100%'; - $s = App::get_baseurl() . '/oembed/' . base64url_encode($src); + $s = System::baseUrl() . '/oembed/' . base64url_encode($src); return ''; } @@ -314,7 +304,7 @@ function oembed_html2bbcode($text) { $entries = $xpath->query("//span[$xattr]"); $xattr = "@rel='oembed'";//oe_build_xpath("rel","oembed"); - foreach($entries as $e) { + foreach ($entries as $e) { $href = $xpath->evaluate("a[$xattr]/@href", $e)->item(0)->nodeValue; if (!is_null($href)) { $e->parentNode->replaceChild(new DOMText("[embed]".$href."[/embed]"), $e);