Actual prod
This commit is contained in:
parent
d9beb2597a
commit
63794889e6
@ -62,6 +62,12 @@ function file_force_download_url($url, $name) {
|
|||||||
echo file_get_contents($url);
|
echo file_get_contents($url);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Фолбэк: файла ещё нет в Selectel (окно до офлоада) или Selectel недоступен — отдаём с локального диска.
|
||||||
|
$local = str_replace('https://uf.joywork.ru', $_SERVER['DOCUMENT_ROOT'], $url);
|
||||||
|
if ($local !== $url && file_exists($local)) {
|
||||||
|
file_force_download($local, $name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function doesFileUrlExists($url) {
|
function doesFileUrlExists($url) {
|
||||||
@ -205,6 +211,13 @@ if (isset($_GET['arhive'])) {
|
|||||||
|
|
||||||
if (file_exists($file)) {
|
if (file_exists($file)) {
|
||||||
$zip->addFile($file, $r['name']);
|
$zip->addFile($file, $r['name']);
|
||||||
|
} else {
|
||||||
|
// файл уехал в Selectel — тянем содержимое и кладём в архив из памяти
|
||||||
|
$url = str_replace($_SERVER['DOCUMENT_ROOT'], 'https://uf.joywork.ru', $file);
|
||||||
|
$data = @file_get_contents($url);
|
||||||
|
if ($data !== false) {
|
||||||
|
$zip->addFromString($r['name'], $data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -226,6 +239,13 @@ if (isset($_GET['arhive'])) {
|
|||||||
|
|
||||||
if (file_exists($file)) {
|
if (file_exists($file)) {
|
||||||
$zip->addFile($file, $r['name']);
|
$zip->addFile($file, $r['name']);
|
||||||
|
} else {
|
||||||
|
// файл уехал в Selectel — тянем содержимое и кладём в архив из памяти
|
||||||
|
$url = str_replace($_SERVER['DOCUMENT_ROOT'], 'https://uf.joywork.ru', $file);
|
||||||
|
$data = @file_get_contents($url);
|
||||||
|
if ($data !== false) {
|
||||||
|
$zip->addFromString($r['name'], $data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -287,22 +307,27 @@ if (!isset($_GET['download']) && isset($_GET['preview'])) {
|
|||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
if (strpos($file, "https") !== false) {
|
// Свежий файл (ещё локально, не уехал в Selectel) — отдаём через публичный file_public.php,
|
||||||
|
// чтобы внешний вьюер/браузер увидел его сразу (окно async-офлоада). Иначе — прямой URL.
|
||||||
|
$relForLocal = str_replace('https://uf.joywork.ru', '', $file);
|
||||||
|
if (!empty($r['guid']) && $relForLocal !== $file && file_exists($_SERVER['DOCUMENT_ROOT'] . $relForLocal)) {
|
||||||
|
$path = 'https://' . $_SERVER['HTTP_HOST'] . '/file_public.php?g=' . $r['guid'];
|
||||||
|
} else if (strpos($file, "https") !== false) {
|
||||||
$path = $file;
|
$path = $file;
|
||||||
} else {
|
} else {
|
||||||
$path = 'https://' . $_SERVER["HTTP_HOST"] . $file;
|
$path = 'https://' . $_SERVER["HTTP_HOST"] . $file;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ifrSrc = 'https://docs.google.com/viewer?url=' . $path . '&embedded=true&rm=minimal';
|
$ifrSrc = 'https://docs.google.com/viewer?url=' . urlencode($path) . '&embedded=true&rm=minimal';
|
||||||
|
|
||||||
if (in_array($extension, [
|
if (in_array($extension, [
|
||||||
'doc', 'docx', 'odt', 'pdf', 'xps', 'pages',
|
'doc', 'docx', 'odt', 'pdf', 'xps', 'pages',
|
||||||
'rtf', 'sxw', 'sdw', 'txt',
|
'rtf', 'sxw', 'sdw', 'txt',
|
||||||
'xls', 'xlsx',
|
'xls', 'xlsx',
|
||||||
'sdc',
|
'sdc',
|
||||||
'ppt', 'pptx',
|
'ppt', 'pptx',
|
||||||
'dfx', 'eps', 'psd', 'svg', 'tif', 'ttf',
|
'dfx', 'eps', 'psd', 'svg', 'tif', 'ttf',
|
||||||
'ai', 'PPTX'
|
'ai', 'PPTX'
|
||||||
])) {
|
])) {
|
||||||
?>
|
?>
|
||||||
<div class="holds-the-iframe">
|
<div class="holds-the-iframe">
|
||||||
@ -329,25 +354,17 @@ if (!isset($_GET['download']) && isset($_GET['preview'])) {
|
|||||||
user-select: none;
|
user-select: none;
|
||||||
-webkit-user-select: none;"></iframe>
|
-webkit-user-select: none;"></iframe>
|
||||||
|
|
||||||
<script>
|
<?php // Авто-reload iframe убран: setInterval каждые 2с переустанавливал src вьюера,
|
||||||
function reloadIFrame() {
|
// а обработчик load вешался в $(document).ready и мог не поймать уже случившийся load
|
||||||
document.getElementById("viewer-dc").src=document.getElementById("viewer-dc").src;
|
// → бесконечный reload Google-вьюера → лишние «viewer»-записи в загрузках браузера.
|
||||||
}
|
// Файл доступен сразу (file_public.php для свежих / Selectel для офлоднутых) — вьюер грузится сам. ?>
|
||||||
timerId = setInterval(reloadIFrame, 2000);
|
|
||||||
|
|
||||||
$( document ).ready(function() {
|
|
||||||
$('#viewer-dc').on('load', function() {
|
|
||||||
clearInterval(timerId);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</div>
|
</div>
|
||||||
<?php } elseif (in_array($extension, [
|
<?php } elseif (in_array($extension, [
|
||||||
'jpg', 'jpeg', 'png', 'JPG', 'JPEG', 'PNG'
|
'jpg', 'jpeg', 'png', 'JPG', 'JPEG', 'PNG'
|
||||||
])) { ?>
|
])) { ?>
|
||||||
<img style="overflow-x: auto;" class="hh" src="<?= $path ?>" alt="">
|
<img style="overflow-x: auto;" class="hh" src="<?= $path ?>" alt="">
|
||||||
<?php } elseif (in_array($extension, [
|
<?php } elseif (in_array($extension, [
|
||||||
'avi', 'mp4', '3gp', 'wma', 'MP4', '3GP'
|
'avi', 'mp4', '3gp', 'wma', 'MP4', '3GP'
|
||||||
])) { ?>
|
])) { ?>
|
||||||
<video
|
<video
|
||||||
id="my-video"
|
id="my-video"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user