147 lines
6.1 KiB
PHP
147 lines
6.1 KiB
PHP
<?php
|
|
|
|
require_once __DIR__.'/common.inc.php';
|
|
|
|
if (!isset($XOOPS_MODULE_PICO) || empty($XOOPS_MODULE_PICO)) {
|
|
exit('Not configured for pico module'.PHP_EOL);
|
|
}
|
|
|
|
error_reporting(0);
|
|
require_once XOOPS_TRUST_PATH.'/modules/pico/include/main_functions.php';
|
|
require_once XOOPS_TRUST_PATH.'/modules/pico/include/common_functions.php';
|
|
require_once XOOPS_TRUST_PATH.'/modules/pico/class/pico.textsanitizer.php';
|
|
require_once XOOPS_TRUST_PATH.'/modules/pico/class/PicoUriMapper.class.php';
|
|
require_once XOOPS_TRUST_PATH.'/modules/pico/class/PicoPermission.class.php';
|
|
require_once XOOPS_TRUST_PATH.'/modules/pico/class/PicoModelCategory.class.php';
|
|
require_once XOOPS_TRUST_PATH.'/modules/pico/class/PicoModelContent.class.php';
|
|
require_once XOOPS_TRUST_PATH.'/libs/altsys/class/AltsysBreadcrumbs.class.php';
|
|
error_reporting(E_ALL);
|
|
|
|
$config = [];
|
|
foreach ($XOOPS_MODULE_PICO as $pico) {
|
|
dumpPico($pico, $config);
|
|
}
|
|
MyDumpTool::makeDirectory('src/pico');
|
|
MyDumpTool::makeDirectory('src/pico/assets');
|
|
MyDumpTool::saveJson('src/pico/assets/config.json', $config);
|
|
|
|
function dumpPico($pico, &$config)
|
|
{
|
|
global $xoopsDB;
|
|
$prefix = $xoopsDB->prefix();
|
|
$table = $pico.'_contents';
|
|
if (!MyDumpTool::tableExists($table)) {
|
|
exit('pico('.$pico.') module not found'.PHP_EOL);
|
|
}
|
|
MyDumpTool::makeDirectory('public/'.$pico);
|
|
MyDumpTool::makeDirectory('public/'.$pico.'/images');
|
|
$moduleHandler = xoops_gethandler('module');
|
|
$module = $moduleHandler->getByDirname($pico);
|
|
$moduleConfigHandler = xoops_gethandler('config');
|
|
$moduleConfig = $moduleConfigHandler->getConfigsByDirname($pico);
|
|
$permObj = PicoPermission::getInstance();
|
|
$perms = $permObj->getPermissions($pico);
|
|
$categoryHandler = new PicoCategoryHandler($pico, $perms);
|
|
$contentHandler = new PicoContentHandler($pico);
|
|
$cats = $categoryHandler->getAllCategories();
|
|
$confContents = [];
|
|
$confCategories = [];
|
|
foreach ($cats as $cat) {
|
|
$catData = $cat->getData();
|
|
$modConfig = $cat->getOverriddenModConfig();
|
|
$link = pico_common_make_category_link4html($modConfig, $catData, $pico);
|
|
MyDumpTool::decode($catData);
|
|
$confCategories[] = [
|
|
'id' => $catData['id'],
|
|
'title' => $catData['cat_title'],
|
|
'desc' => (string) $catData['cat_desc'],
|
|
'pid' => (int) $catData['pid'],
|
|
'weight' => (int) $catData['cat_weight'],
|
|
'link' => $link,
|
|
];
|
|
$contents = $contentHandler->getCategoryContents($cat);
|
|
foreach ($contents as $content) {
|
|
$data = $content->getData();
|
|
$link = pico_common_make_content_link4html($modConfig , $data);
|
|
MyDumpTool::decode($data);
|
|
$content = MyDumpTool::fixHtml($data['body_cached']);
|
|
$imageId = 1;
|
|
$content = preg_replace_callback('/<img ([^>]*)src="(.*)"([^>]*)\/>/Us', function ($matches) use (&$imageId, $pico, $data, $link) {
|
|
$url = $matches[2];
|
|
if (!preg_match('/^http/', $url)) {
|
|
$xpath = dirname($link);
|
|
$wrap_fpath = XOOPS_TRUST_PATH._MD_PICO_WRAPBASE.'/'.$pico.'/'.$url;
|
|
if (file_exists($wrap_fpath)) {
|
|
$url = $wrap_fpath;
|
|
} else {
|
|
$url = XOOPS_URL.'/modules/'.$pico.'/'.($xpath === '.' ? '' : '/').$url;
|
|
}
|
|
}
|
|
$fname = '/'.$pico.'/images/'.$data['id'].'_'.$imageId.'.dat';
|
|
$fpath = MYDUMPTOOL_OUTPUTDIR.'/public'.$fname;
|
|
if (preg_match('/^\//', $url)) {
|
|
if (!MyDumpTool::fileCopy($url, $fpath)) {
|
|
exit('failed to copy file: '.$url.PHP_EOL);
|
|
}
|
|
} else {
|
|
MyDumpTool::fileDownload($url, $fpath);
|
|
}
|
|
$mime = MyDumpTool::getMimeType($fpath);
|
|
switch ($mime) {
|
|
case 'image/gif':
|
|
$fpath_ = preg_replace('/.dat$/', '.gif', $fpath);
|
|
$fname = preg_replace('/.dat$/', '.gif', $fname);
|
|
rename($fpath, $fpath_);
|
|
$fpath = $fpath_;
|
|
break;
|
|
case 'image/png':
|
|
$fpath_ = preg_replace('/.dat$/', '.png', $fpath);
|
|
$fname = preg_replace('/.dat$/', '.png', $fname);
|
|
rename($fpath, $fpath_);
|
|
$fpath = $fpath_;
|
|
break;
|
|
case 'image/jpeg':
|
|
$fpath = preg_replace('/.dat$/', '.jpeg', $fpath);
|
|
$fname = preg_replace('/.dat$/', '.jpeg', $fname);
|
|
rename($fpath, $fpath_);
|
|
$fpath = $fpath_;
|
|
break;
|
|
default:
|
|
exit('unknown mime type '.$mime.' found: '.$fname.' from '.$url.PHP_EOL);
|
|
}
|
|
++$imageId;
|
|
|
|
return '<img '.$matches[1].'src="'.$fname.'"'.$matches[3].'/>';
|
|
}, $content);
|
|
$item = [
|
|
'id' => $data['id'],
|
|
'title' => $data['subject_raw'],
|
|
'content' => $content,
|
|
];
|
|
MyDumpTool::saveJson('public/'.$pico.'/'.$data['id'].'.json', $item);
|
|
$confContents[] = [
|
|
'id' => $item['id'],
|
|
'title' => $data['subject_raw'],
|
|
'cat_id' => (int) $data['cat_id'],
|
|
'weight' => (int) $data['weight'],
|
|
'link' => $link,
|
|
];
|
|
}
|
|
}
|
|
$moduleinfo = [
|
|
'name' => $module->get('name'),
|
|
'dirname' => $pico,
|
|
'message' => $moduleConfig['top_message'],
|
|
'show_menuinmoduletop' => (int) $moduleConfig['show_menuinmoduletop'],
|
|
'show_listasindex' => (int) $moduleConfig['show_listasindex'],
|
|
'show_breadcrumbs' => (int) $moduleConfig['show_breadcrumbs'],
|
|
'show_pagenavi' => (int) $moduleConfig['show_pagenavi'],
|
|
];
|
|
MyDumpTool::decode($moduleinfo);
|
|
$config[] = [
|
|
'module' => $moduleinfo,
|
|
'categories' => $confCategories,
|
|
'contents' => $confContents,
|
|
];
|
|
}
|