aboutsummaryrefslogtreecommitdiffstats
path: root/include/oembed.php
diff options
context:
space:
mode:
authorredmatrix <git@macgirvin.com>2016-08-11 17:33:28 -0700
committerredmatrix <git@macgirvin.com>2016-08-11 17:33:28 -0700
commitc63deda71a8acc73eaa05fb045f214f93c3aa347 (patch)
treec33e1532d028436407abfc76e0644aa55d91505f /include/oembed.php
parent3ba4b2c1c1ffa8275337857e10c250b338e15170 (diff)
downloadvolse-hubzilla-c63deda71a8acc73eaa05fb045f214f93c3aa347.tar.gz
volse-hubzilla-c63deda71a8acc73eaa05fb045f214f93c3aa347.tar.bz2
volse-hubzilla-c63deda71a8acc73eaa05fb045f214f93c3aa347.zip
embed filter adjustments
Diffstat (limited to 'include/oembed.php')
-rwxr-xr-xinclude/oembed.php30
1 files changed, 17 insertions, 13 deletions
diff --git a/include/oembed.php b/include/oembed.php
index 5c6f6be79..fe6f10d71 100755
--- a/include/oembed.php
+++ b/include/oembed.php
@@ -1,8 +1,10 @@
<?php /** @file */
-
use Zotlabs\Lib as Zlib;
+require_once('include/hubloc.php');
+
+
function oembed_replacecb($matches){
$embedurl=$matches[1];
@@ -130,6 +132,9 @@ function oembed_fetch_url($embedurl){
$txt = null;
+ // we should try to cache this and avoid a lookup on each render
+ $zrl = is_matrix_url($embedurl);
+
if($action !== 'block') {
$txt = Zlib\Cache::get('[' . App::$videowidth . '] ' . $embedurl);
@@ -142,15 +147,11 @@ function oembed_fetch_url($embedurl){
$txt = "";
$furl = $embedurl;
- $zrl = false;
- if(local_channel()) {
- require_once('include/hubloc.php');
- $zrl = is_matrix_url($furl);
- if($zrl)
- $furl = zid($furl);
- }
+ logger('local_channel: ' . local_channel());
+ if(local_channel() && $zrl)
+ $furl = zid($furl);
if ($action !== 'block') {
// try oembed autodiscovery
@@ -216,14 +217,17 @@ function oembed_fetch_url($embedurl){
logger('oembed html was purified. original: ' . $orig . ' purified: ' . $j->html, LOGGER_DEBUG, LOG_INFO);
}
- $orig_len = mb_strlen(trim($orig));
- $new_len = mb_strlen(trim($j->html));
- if(! $new_len)
+ $orig_len = mb_strlen(preg_replace('/\s+/','',$orig));
+ $new_len = mb_strlen(preg_replace('/\s+/','',$j->html));
+
+ if(stripos($orig,'<script') || (! $new_len))
$j->type = 'error';
elseif($orig_len) {
$ratio = $new_len / $orig_len;
- if($ratio < 0.8)
+ if($ratio < 0.5) {
$j->type = 'error';
+ logger('oembed html truncated: ' . $ratio, LOGGER_DEBUG, LOG_INFO);
+ }
}
}
@@ -231,7 +235,7 @@ function oembed_fetch_url($embedurl){
$j->embedurl = $embedurl;
-// logger('fetch return: ' . print_r($j,true));
+ // logger('fetch return: ' . print_r($j,true));
return $j;