Merge branch 'dev' of ../hz into dev

This commit is contained in:
zotlabs 2019-04-27 17:22:00 -07:00
commit 13970280d9
3 changed files with 100 additions and 3 deletions

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) {