91 lines
3.8 KiB
PHP
91 lines
3.8 KiB
PHP
<?php
|
|
|
|
require_once __DIR__.'/common.inc.php';
|
|
|
|
if (!isset($XOOPS_MODULE_XELFINDER) || empty($XOOPS_MODULE_XELFINDER)) {
|
|
exit('Not configured for xelfinder module'.PHP_EOL);
|
|
}
|
|
|
|
foreach ($XOOPS_MODULE_XELFINDER as $mydirname) {
|
|
dumpXelfinder($mydirname);
|
|
}
|
|
|
|
function dumpXelfinder($mydirname)
|
|
{
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
$table = $mydirname.'_file';
|
|
if (!MyDumpTool::tableExists($table)) {
|
|
exit($mydirname.' module not found'.PHP_EOL);
|
|
}
|
|
$hostname = rawurlencode(substr(XOOPS_URL, strpos(XOOPS_URL, '://') + 3));
|
|
// all registered files
|
|
$sql = <<< SQL
|
|
SELECT
|
|
*
|
|
FROM `${prefix}_${table}`
|
|
WHERE `mime` != 'directory'
|
|
SQL;
|
|
if (!($res = $xoopsDB->query($sql))) {
|
|
var_dump($xoopsDB);
|
|
exit();
|
|
}
|
|
while ($row = $xoopsDB->fetchArray($res)) {
|
|
MyDumpTool::decode($row);
|
|
MyDumpTool::convertToInt($row, ['file_id', 'parent_id', 'size', 'ctime', 'mtime', 'uid', 'gid', 'width', 'height']);
|
|
$row['gids'] = array_map('intval', explode(',', $row['gids']));
|
|
$operm = intval(hexdec(substr($row['perm'], 2, 1)));
|
|
if ($operm & 0x04) {
|
|
// bit:0100 - read permission
|
|
$src = XOOPS_TRUST_PATH.'/uploads/xelfinder/'.$hostname.'_'.$mydirname.'_'.$row['file_id'];
|
|
$basedir = '/modules/'.$mydirname.'/index.php/view/'.$row['file_id'];
|
|
MyDumpTool::makeDirectory('public'.$basedir);
|
|
$dest = MYDUMPTOOL_OUTPUTDIR.'/public'.$basedir.'/'.$row['name'];
|
|
if (!MyDumpTool::fileCopy($src, $dest)) {
|
|
exit('Failed to copy file : '.$src.PHP_EOL);
|
|
}
|
|
$htaccess = MYDUMPTOOL_OUTPUTDIR.'/public'.$basedir.'/.htaccess';
|
|
if (!file_exists($htaccess)) {
|
|
$htfname = str_replace(' ', '\\ ', $row['name']);
|
|
$data = "RewriteEngine On\nRewriteBase $basedir\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteRule .* $htfname [R=301,L]\n";
|
|
file_put_contents($htaccess, $data);
|
|
}
|
|
$thumbs = glob($src.'_*.tmb');
|
|
if (false !== $thumbs && !empty($thumbs)) {
|
|
foreach ($thumbs as $thumb) {
|
|
list($twidth, $theight) = getimagesize($thumb);
|
|
$tsize = max((int) $twidth, (int) $theight);
|
|
$tsrc = $thumb;
|
|
$tbasedir = '/modules/'.$mydirname.'/index.php/tmb/'.$tsize.'/'.$row['file_id'];
|
|
MyDumpTool::makeDirectory('public'.$tbasedir);
|
|
$tdest = MYDUMPTOOL_OUTPUTDIR.'/public'.$tbasedir.'/'.$row['name'];
|
|
if (!MyDumpTool::fileCopy($tsrc, $tdest)) {
|
|
exit('Failed to copy file : '.$tsrc.PHP_EOL);
|
|
}
|
|
$htaccess = MYDUMPTOOL_OUTPUTDIR.'/public'.$tbasedir.'/.htaccess';
|
|
if (!file_exists($htaccess)) {
|
|
$htfname = str_replace(' ', '\\ ', $row['name']);
|
|
$data = "RewriteEngine On\nRewriteBase $tbasedir\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteRule .* $htfname [R=301,L]\n";
|
|
file_put_contents($htaccess, $data);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$xoopsDB->freeRecordSet($res);
|
|
// cache files
|
|
$src = XOOPS_ROOT_PATH.'/modules/'.$mydirname.'/cache/tmb/*.png';
|
|
$thumbs = glob($src);
|
|
if (false !== $thumbs && !empty($thumbs)) {
|
|
$tbasedir = '/modules/'.$mydirname.'/cache/tmb';
|
|
MyDumpTool::makeDirectory('public'.$tbasedir);
|
|
foreach ($thumbs as $thumb) {
|
|
$tsrc = $thumb;
|
|
$tdest = MYDUMPTOOL_OUTPUTDIR.'/public'.$tbasedir.'/'.basename($tsrc);
|
|
if (!MyDumpTool::fileCopy($tsrc, $tdest)) {
|
|
exit('Failed to copy file : '.$tsrc.PHP_EOL);
|
|
}
|
|
}
|
|
}
|
|
}
|