]> git.mxchange.org Git - friendica.git/blobdiff - src/Content/OEmbed.php
Fixes for OEmbed class (#5392)
[friendica.git] / src / Content / OEmbed.php
index 170ee7ba265eb13a40d1e49d1f7cf22abb2c1ea0..390f3ea868435a3c035d9f9f7e9deceab24f5fec 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 /**
  * @file src/Content/OEmbed.php
  */
@@ -6,17 +7,20 @@ namespace Friendica\Content;
 
 use Friendica\Core\Addon;
 use Friendica\Core\Cache;
+use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
-use Friendica\Core\Config;
 use Friendica\Database\DBM;
+use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\ParseUrl;
 use dba;
 use DOMDocument;
-use DOMXPath;
 use DOMNode;
+use DOMText;
+use DOMXPath;
 use Exception;
+use stdClass;
 
 require_once 'include/dba.php';
 require_once 'mod/proxy.php';
@@ -105,12 +109,12 @@ class OEmbed
                                $txt = '{"type":"error"}';
                        } else { //save in cache
                                $j = json_decode($txt);
-                               if ($j->type != "error") {
+                               if (!empty($j->type) && $j->type != "error") {
                                        dba::insert('oembed', [
                                                'url' => normalise_link($embedurl),
                                                'maxwidth' => $a->videowidth,
                                                'content' => $txt,
-                                               'created' => datetime_convert()
+                                               'created' => DateTimeFormat::utcNow()
                                        ], true);
                                }
 
@@ -160,11 +164,12 @@ class OEmbed
                return $j;
        }
 
-       private static function formatObject($j)
+       private static function formatObject(stdClass $j)
        {
                $embedurl = $j->embedurl;
                $jhtml = $j->html;
                $ret = '<div class="oembed ' . $j->type . '">';
+
                switch ($j->type) {
                        case "video":
                                if (isset($j->thumbnail_url)) {
@@ -323,7 +328,7 @@ class OEmbed
 
                $o = self::fetchURL($url, !self::isAllowedURL($url));
 
-               if (!is_object($o) || $o->type == 'error') {
+               if (!is_object($o) || property_exists($o, 'type') && $o->type == 'error') {
                        throw new Exception('OEmbed failed for URL: ' . $url);
                }