streams/Zotlabs/Daemon/Thumbnail.php

86 lines
2.5 KiB
PHP
Raw Normal View History

2021-12-03 03:01:39 +00:00
<?php
/** @file */
2017-11-20 00:56:59 +00:00
namespace Zotlabs\Daemon;
2021-12-03 03:01:39 +00:00
class Thumbnail
{
2017-11-20 00:56:59 +00:00
2021-12-03 03:01:39 +00:00
public static function run($argc, $argv)
{
2017-11-20 00:56:59 +00:00
2021-12-03 03:01:39 +00:00
if (! ($argc == 2)) {
return;
}
2017-11-20 00:56:59 +00:00
2021-12-03 03:01:39 +00:00
$c = q(
"select * from attach where hash = '%s' ",
dbesc($argv[1])
);
2017-11-20 00:56:59 +00:00
2021-12-03 03:01:39 +00:00
if (! $c) {
return;
}
2017-11-20 00:56:59 +00:00
2021-12-03 03:01:39 +00:00
$attach = $c[0];
2017-11-20 00:56:59 +00:00
2021-12-03 03:01:39 +00:00
$preview_style = intval(get_config('system', 'thumbnail_security', 0));
$preview_width = intval(get_config('system', 'thumbnail_width', 300));
$preview_height = intval(get_config('system', 'thumbnail_height', 300));
2017-11-22 01:56:23 +00:00
2021-12-03 03:01:39 +00:00
$p = [
'attach' => $attach,
'preview_style' => $preview_style,
'preview_width' => $preview_width,
'preview_height' => $preview_height,
'thumbnail' => null
];
2017-11-20 00:56:59 +00:00
2021-12-03 03:01:39 +00:00
/**
* @hooks thumbnail
* * \e array \b attach
* * \e int \b preview_style
* * \e int \b preview_width
* * \e int \b preview_height
* * \e string \b thumbnail
*/
2017-11-22 01:56:23 +00:00
2021-12-03 03:01:39 +00:00
call_hooks('thumbnail', $p);
if ($p['thumbnail']) {
return;
}
2017-11-22 01:56:23 +00:00
2021-12-03 03:01:39 +00:00
$default_controller = null;
2017-11-22 01:56:23 +00:00
2021-12-03 03:01:39 +00:00
$files = glob('Zotlabs/Thumbs/*.php');
if ($files) {
foreach ($files as $f) {
$clsname = '\\Zotlabs\\Thumbs\\' . ucfirst(basename($f, '.php'));
if (class_exists($clsname)) {
$x = new $clsname();
if (method_exists($x, 'Match')) {
$matched = $x->Match($attach['filetype']);
if ($matched) {
$x->Thumb($attach, $preview_style, $preview_width, $preview_height);
}
}
if (method_exists($x, 'MatchDefault')) {
$default_matched = $x->MatchDefault(substr($attach['filetype'], 0, strpos($attach['filetype'], '/')));
if ($default_matched) {
$default_controller = $x;
}
}
}
}
}
if (
($default_controller)
&& ((! file_exists(dbunescbin($attach['content']) . '.thumb'))
|| (filectime(dbunescbin($attach['content']) . 'thumb') < (time() - 60)))
) {
$default_controller->Thumb($attach, $preview_style, $preview_width, $preview_height);
}
}
}