aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorredmatrix <git@macgirvin.com>2016-08-11 17:33:28 -0700
committerredmatrix <git@macgirvin.com>2016-08-11 17:34:05 -0700
commit0637a71669d4dcc87c5245a9b226fca7438335dc (patch)
tree4c7481db4ae3480c79e35f170c73b6cec1ee03e3
parent45dc9959678786b05f206f7faee73f042631b2fe (diff)
downloadvolse-hubzilla-0637a71669d4dcc87c5245a9b226fca7438335dc.tar.gz
volse-hubzilla-0637a71669d4dcc87c5245a9b226fca7438335dc.tar.bz2
volse-hubzilla-0637a71669d4dcc87c5245a9b226fca7438335dc.zip
embed filter adjustments
-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;