Merge branch 'dev' into 'dev'

Add jot videos inline and with poster if possible

See merge request hubzilla/core!1613
This commit is contained in:
Mario 2019-04-29 11:58:59 +02:00
commit 674215e9e6
4 changed files with 109 additions and 5 deletions

View File

@ -195,6 +195,13 @@ class Activity {
if(! $ev['nofinish']) {
$y['endTime'] = (($ev['adjust']) ? datetime_convert('UTC','UTC',$ev['dtend'], ATOM_TIME) : datetime_convert('UTC','UTC',$ev['dtend'],'Y-m-d\\TH:i:s-00:00'));
}
// copy attachments from the passed object - these are already formatted for ActivityStreams
if($x['attachment']) {
$y['attachment'] = $x['attachment'];
}
if($actor) {
return $y;
}
@ -404,7 +411,7 @@ class Activity {
$ret = [];
if($item['attach']) {
$atts = json_decode($item['attach'],true);
$atts = ((is_array($item['attach'])) ? $item['attach'] : json_decode($item['attach'],true));
if($atts) {
foreach($atts as $att) {
if(strpos($att['type'],'image')) {
@ -416,7 +423,7 @@ class Activity {
}
}
}
return $ret;
}

View File

@ -69,6 +69,14 @@ class Linkinfo extends \Zotlabs\Web\Controller {
killme();
}
if(stripos($type,'video/') !== false) {
$thumb = self::get_video_poster($url);
if($thumb) {
if ($zrl)
echo $br . '[zvideo poster=\'' . $thumb . '\']' . $url . '[/zvideo]' . $br;
else
echo $br . '[video poster=\'' . $thumb . '\']' . $url . '[/video]' . $br;
killme();
}
if($zrl)
echo $br . '[zvideo]' . $url . '[/zvideo]' . $br;
else
@ -216,7 +224,42 @@ class Linkinfo extends \Zotlabs\Web\Controller {
return($complete);
}
public static function get_video_poster($url) {
if(strpos($url,z_root() . '/cloud/') === false) {
return EMPTY_STR;
}
$m = parse_url($url,PHP_URL_PATH);
if($m) {
// strip leading '/cloud/'
$m = substr($m,7);
}
$nick = substr($m,0,strpos($m,'/'));
$p = substr($m,strpos($m,'/')+1);
// get the channel to check permissions
$u = channelx_by_nick($nick);
if($u && $p) {
$sql_extra = permissions_sql(intval($u['channel_id']));
$r = q("select hash, content from attach where display_path = '%s' and uid = %d and os_storage = 1 $sql_extra limit 1",
dbesc($p),
intval($u['channel_id'])
);
if($r) {
$path = dbunescbin($r[0]['content']);
if($path && @file_exists($path . '.thumb')) {
return z_root() . '/poster/' . $nick . '/' . $r[0]['hash'];
}
}
}
return EMPTY_STR;
}
public static function parseurl_getsiteinfo($url) {
$siteinfo = array();

37
Zotlabs/Module/Poster.php Normal file
View File

@ -0,0 +1,37 @@
<?php
namespace Zotlabs\Module;
use Zotlabs\Web\Controller;
require_once('include/security.php');
class Poster extends Controller {
function init() {
$nick = argv(1);
$hash = argv(2);
if(! ($nick && $hash)) {
return;
}
$u = channelx_by_nick($nick);
$sql_extra = permissions_sql(intval($u['channel_id']));
$r = q("select content from attach where hash = '%s' and uid = %d and os_storage = 1 $sql_extra limit 1",
dbesc($hash),
intval($u['channel_id'])
);
if($r) {
$path = dbunescbin($r[0]['content']);
if($path && @file_exists($path . '.thumb')) {
header('Content-Type: image/jpeg');
echo file_get_contents($path . '.thumb');
killme();
}
}
}
}

View File

@ -96,9 +96,26 @@ class Wall_attach extends \Zotlabs\Web\Controller {
$s = "\n\n" . $r['body'] . "\n\n";
}
else {
$s = "\n\n" . '[attachment]' . $r['data']['hash'] . ',' . $r['data']['revision'] . '[/attachment]' . "\n";
if(strpos($r['data']['filetype'],'video') === 0) {
// give a wee bit of time for the background thumbnail processor to do its thing
// or else we'll never see a video poster
sleep(3);
$url = z_root() . '/cloud/' . $channel['channel_address'] . '/' . $r['data']['display_path'];
$thumb = Linkinfo::get_video_poster($url);
if($thumb) {
$s = "\n\n" . '[zvideo poster=\'' . $thumb . '\']' . $url . '[/zvideo]' . "\n\n";
}
else {
$s = "\n\n" . '[zvideo]' . $url . '[/zvideo]' . "\n\n";
}
}
if(strpos($r['data']['filetype'],'audio') === 0) {
$url = z_root() . '/cloud/' . $channel['channel_address'] . '/' . $r['data']['display_path'];
echo "\n\n" . '[zaudio]' . $url . '[/zaudio]' . "\n\n";
}
$s .= "\n\n" . '[attachment]' . $r['data']['hash'] . ',' . $r['data']['revision'] . '[/attachment]' . "\n";
}
$sync = attach_export_data($channel,$r['data']['hash']);
if($sync) {