convert oembed tools to use json arrays rather than json objects
This commit is contained in:
parent
4650458157
commit
dca4db9d4d
@ -25,7 +25,7 @@ class Oembed extends \Zotlabs\Web\Controller {
|
|||||||
echo "<html><head><base target=\"_blank\" /></head><body>";
|
echo "<html><head><base target=\"_blank\" /></head><body>";
|
||||||
$src = base64url_decode(argv(1));
|
$src = base64url_decode(argv(1));
|
||||||
$j = oembed_fetch_url($src);
|
$j = oembed_fetch_url($src);
|
||||||
echo $j->html;
|
echo $j['html'];
|
||||||
// logger('mod-oembed ' . $h, LOGGER_ALL);
|
// logger('mod-oembed ' . $h, LOGGER_ALL);
|
||||||
echo "</body></html>";
|
echo "</body></html>";
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ function tryoembed($match) {
|
|||||||
|
|
||||||
$o = oembed_fetch_url($url);
|
$o = oembed_fetch_url($url);
|
||||||
|
|
||||||
if ($o->type == 'error')
|
if ($o['type'] == 'error')
|
||||||
return $match[0];
|
return $match[0];
|
||||||
|
|
||||||
$html = oembed_format_object($o);
|
$html = oembed_format_object($o);
|
||||||
|
@ -105,7 +105,7 @@ function oembed_action($embedurl) {
|
|||||||
function oembed_process($url) {
|
function oembed_process($url) {
|
||||||
$j = oembed_fetch_url($url);
|
$j = oembed_fetch_url($url);
|
||||||
logger('oembed_process: ' . print_r($j,true));
|
logger('oembed_process: ' . print_r($j,true));
|
||||||
if($j && $j->type !== 'error')
|
if($j && $j['type'] !== 'error')
|
||||||
return '[embed]' . $url . '[/embed]';
|
return '[embed]' . $url . '[/embed]';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -215,26 +215,29 @@ function oembed_fetch_url($embedurl){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$j = json_decode($txt);
|
$j = json_decode($txt,true);
|
||||||
|
|
||||||
|
if(! $j)
|
||||||
|
$j = [];
|
||||||
|
|
||||||
if($action === 'filter') {
|
if($action === 'filter') {
|
||||||
if($j->html) {
|
if($j['html']) {
|
||||||
$orig = $j->html;
|
$orig = $j['html'];
|
||||||
$allow_position = (($zrl) ? true : false);
|
$allow_position = (($zrl) ? true : false);
|
||||||
$j->html = purify_html($j->html,$allow_position);
|
$j['html'] = purify_html($j['html'],$allow_position);
|
||||||
if($j->html != $orig) {
|
if($j['html'] != $orig) {
|
||||||
logger('oembed html was purified. original: ' . $orig . ' purified: ' . $j->html, LOGGER_DEBUG, LOG_INFO);
|
logger('oembed html was purified. original: ' . $orig . ' purified: ' . $j['html'], LOGGER_DEBUG, LOG_INFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
$orig_len = mb_strlen(preg_replace('/\s+/','',$orig));
|
$orig_len = mb_strlen(preg_replace('/\s+/','',$orig));
|
||||||
$new_len = mb_strlen(preg_replace('/\s+/','',$j->html));
|
$new_len = mb_strlen(preg_replace('/\s+/','',$j['html']));
|
||||||
|
|
||||||
if(stripos($orig,'<script') || (! $new_len))
|
if(stripos($orig,'<script') || (! $new_len))
|
||||||
$j->type = 'error';
|
$j['type'] = 'error';
|
||||||
elseif($orig_len) {
|
elseif($orig_len) {
|
||||||
$ratio = $new_len / $orig_len;
|
$ratio = $new_len / $orig_len;
|
||||||
if($ratio < 0.5) {
|
if($ratio < 0.5) {
|
||||||
$j->type = 'error';
|
$j['type'] = 'error';
|
||||||
logger('oembed html truncated: ' . $ratio, LOGGER_DEBUG, LOG_INFO);
|
logger('oembed html truncated: ' . $ratio, LOGGER_DEBUG, LOG_INFO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -242,7 +245,7 @@ function oembed_fetch_url($embedurl){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$j->embedurl = $embedurl;
|
$j['embedurl'] = $embedurl;
|
||||||
|
|
||||||
// logger('fetch return: ' . print_r($j,true));
|
// logger('fetch return: ' . print_r($j,true));
|
||||||
|
|
||||||
@ -253,27 +256,27 @@ function oembed_fetch_url($embedurl){
|
|||||||
|
|
||||||
function oembed_format_object($j){
|
function oembed_format_object($j){
|
||||||
|
|
||||||
$embedurl = $j->embedurl;
|
$embedurl = $j['embedurl'];
|
||||||
|
|
||||||
// logger('format: ' . print_r($j,true));
|
// logger('format: ' . print_r($j,true));
|
||||||
|
|
||||||
$jhtml = oembed_iframe($j->embedurl,(isset($j->width) ? $j->width : null), (isset($j->height) ? $j->height : null));
|
$jhtml = oembed_iframe($j['embedurl'],(isset($j['width']) ? $j['width'] : null), (isset($j['height']) ? $j['height'] : null));
|
||||||
|
|
||||||
$ret="<span class='oembed ".$j->type."'>";
|
$ret="<span class='oembed " . $j['type'] . "'>";
|
||||||
switch ($j->type) {
|
switch ($j['type']) {
|
||||||
case "video": {
|
case "video": {
|
||||||
if (isset($j->thumbnail_url)) {
|
if (isset($j['thumbnail_url'])) {
|
||||||
$tw = (isset($j->thumbnail_width)) ? $j->thumbnail_width:200;
|
$tw = (isset($j['thumbnail_width'])) ? $j['thumbnail_width'] : 200;
|
||||||
$th = (isset($j->thumbnail_height)) ? $j->thumbnail_height:180;
|
$th = (isset($j['thumbnail_height'])) ? $j['thumbnail_height'] : 180;
|
||||||
$tr = $tw/$th;
|
$tr = $tw/$th;
|
||||||
|
|
||||||
$th=120; $tw = $th*$tr;
|
$th=120; $tw = $th*$tr;
|
||||||
$tpl=get_markup_template('oembed_video.tpl');
|
$tpl=get_markup_template('oembed_video.tpl');
|
||||||
if(strstr($embedurl,'youtu') && strstr(z_root(),'https:')) {
|
if(strstr($embedurl,'youtu') && strstr(z_root(),'https:')) {
|
||||||
$embedurl = str_replace('http:','https:',$embedurl);
|
$embedurl = str_replace('http:','https:',$embedurl);
|
||||||
$j->thumbnail_url = str_replace('http:','https:', $j->thumbnail_url);
|
$j['thumbnail_url'] = str_replace('http:','https:', $j['thumbnail_url']);
|
||||||
$jhtml = str_replace('http:','https:', $jhtml);
|
$jhtml = str_replace('http:','https:', $jhtml);
|
||||||
$j->html = str_replace('http:','https:', $j->html);
|
$j['html'] = str_replace('http:','https:', $j['html']);
|
||||||
|
|
||||||
}
|
}
|
||||||
$ret.=replace_macros($tpl, array(
|
$ret.=replace_macros($tpl, array(
|
||||||
@ -282,7 +285,7 @@ function oembed_format_object($j){
|
|||||||
'$escapedhtml'=>base64_encode($jhtml),
|
'$escapedhtml'=>base64_encode($jhtml),
|
||||||
'$tw'=>$tw,
|
'$tw'=>$tw,
|
||||||
'$th'=>$th,
|
'$th'=>$th,
|
||||||
'$turl'=>$j->thumbnail_url,
|
'$turl'=> $j['thumbnail_url'],
|
||||||
));
|
));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -291,19 +294,19 @@ function oembed_format_object($j){
|
|||||||
$ret.="<br>";
|
$ret.="<br>";
|
||||||
}; break;
|
}; break;
|
||||||
case "photo": {
|
case "photo": {
|
||||||
$ret.= "<img width='".$j->width."' src='".$j->url."'>";
|
$ret.= "<img width='".$j['width']."' src='".$j['url']."'>";
|
||||||
$ret.="<br>";
|
$ret.="<br>";
|
||||||
}; break;
|
}; break;
|
||||||
case "link": {
|
case "link": {
|
||||||
if($j->thumbnail_url) {
|
if($j['thumbnail_url']) {
|
||||||
if(is_matrix_url($embedurl)) {
|
if(is_matrix_url($embedurl)) {
|
||||||
$embedurl = zid($embedurl);
|
$embedurl = zid($embedurl);
|
||||||
$j->thumbnail_url = zid($j->thumbnail_url);
|
$j['thumbnail_url'] = zid($j['thumbnail_url']);
|
||||||
}
|
}
|
||||||
$ret = '<a href="' . $embedurl . '" ><img src="' . $j->thumbnail_url . '" alt="thumbnail" /></a><br /><br />';
|
$ret = '<a href="' . $embedurl . '" ><img src="' . $j['thumbnail_url'] . '" alt="thumbnail" /></a><br /><br />';
|
||||||
}
|
}
|
||||||
|
|
||||||
//$ret = "<a href='".$embedurl."'>".$j->title."</a>";
|
//$ret = "<a href='".$embedurl."'>".$j['title']."</a>";
|
||||||
}; break;
|
}; break;
|
||||||
case "rich": {
|
case "rich": {
|
||||||
// not so safe..
|
// not so safe..
|
||||||
@ -312,12 +315,12 @@ function oembed_format_object($j){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add link to source if not present in "rich" type
|
// add link to source if not present in "rich" type
|
||||||
if ( $j->type!='rich' || !strpos($j->html,$embedurl) ){
|
if ( $j['type'] != 'rich' || !strpos($j['html'],$embedurl) ){
|
||||||
$embedlink = (isset($j->title))?$j->title:$embedurl;
|
$embedlink = (isset($j['title']))?$j['title'] : $embedurl;
|
||||||
$ret .= '<br />' . "<a href='$embedurl' rel='oembed'>$embedlink</a>";
|
$ret .= '<br />' . "<a href='$embedurl' rel='oembed'>$embedlink</a>";
|
||||||
$ret .= "<br />";
|
$ret .= "<br />";
|
||||||
if (isset($j->author_name)) $ret.=" by ".$j->author_name;
|
if (isset($j['author_name'])) $ret .= t(' by ') . $j['author_name'];
|
||||||
if (isset($j->provider_name)) $ret.=" on ".$j->provider_name;
|
if (isset($j['provider_name'])) $ret .= t(' on ') . $j['provider_name'];
|
||||||
} else {
|
} else {
|
||||||
// add <a> for html2bbcode conversion
|
// add <a> for html2bbcode conversion
|
||||||
$ret .= "<br /><a href='$embedurl' rel='oembed'>$embedurl</a>";
|
$ret .= "<br /><a href='$embedurl' rel='oembed'>$embedurl</a>";
|
||||||
|
Reference in New Issue
Block a user