📄 main.php
字号:
for ($i = 0; $i < $fcount; $i++) {
$newtpl =& $tplfiles[$i]->xoopsClone();
$newtpl->setVar('tpl_id', 0);
$newtpl->setVar('tpl_tplset', $tplset);
$newtpl->setVar('tpl_lastmodified', time());
$newtpl->setVar('tpl_lastimported', 0);
if (!$tpltpl_handler->insert($newtpl)) {
echo ' <span style="color:#ff0000;">错误: 无法插入区块模板<b>'.$tplfiles[$i]->getVar('tpl_file').'</b>到数据库.</span><br />';echo $newtpl->getHtmlErrors();
} else {
if ($tplset == $xoopsConfig['template_set']) {
include_once XOOPS_ROOT_PATH.'/class/template.php';
xoops_template_touch($newtpl->getVar('tpl_id'));
}
echo ' 区块模板<b>'.$tplfiles[$i]->getVar('tpl_file').'</b>已添加到数据库.<br />';
}
}
flush();
unset($newtpl);
}
echo '<br />模板<b>'.$tplset.'</b>的模块模板文件已经生成并安装完毕.<br /></code><br /><a href="admin.php?fct=tplsets">'._MD_AM_BTOTADMIN.'</a>';
xoops_cp_footer();
break;
case 'previewpopup':
$file = XOOPS_CACHE_PATH.'/'.trim($file);
if (file_exists($file)) {
include $file;
@unlink($file);
}
break;
case 'uploadtar_go':
include_once XOOPS_ROOT_PATH.'/class/uploader.php';
$uploader = new XoopsMediaUploader(XOOPS_UPLOAD_PATH, array('application/x-gzip', 'application/gzip', 'application/gzip-compressed', 'application/x-gzip-compressed', 'application/x-tar', 'application/x-tar-compressed', 'application/octet-stream'), 1000000);
$uploader->setPrefix('tmp');
xoops_cp_header();
echo '<code>';
if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
if (!$uploader->upload()) {
xoops_error($uploader->getErrors());
} else {
include_once XOOPS_ROOT_PATH.'/class/class.tar.php';
$tar = new tar();
$tar->openTar($uploader->getSavedDestination());
@unlink($uploader->getSavedDestination());
$themefound = false;
foreach ($tar->files as $id => $info) {
$infoarr = explode('/', str_replace("\\", '/', $info['name']));
if (!isset($tplset_name)) {
$tplset_name = trim($infoarr[0]);
} else {
$tplset_name = trim($tplset_name);
if ($tplset_name == '') {
$tplset_name = trim($infoarr[0]);
}
}
if ($tplset_name != '') {
break;
}
}
if ($tplset_name == '') {
echo '<span style="color:#ff0000;">错误: 模板文件没找到</span><br />';
} else {
$tplset_handler =& xoops_gethandler('tplset');
if ($tplset_handler->getCount(new Criteria('tplset_name', $tplset_name)) > 0) {
echo '<span style="color:#ff0000;">错误: 模板<b>'.$tplset_name.'</b>已存在.</span><br />';
} else {
$tplset =& $tplset_handler->create();
$tplset->setVar('tplset_name', $tplset_name);
$tplset->setVar('tplset_created', time());
if (!$tplset_handler->insert($tplset)) {
echo '<span style="color:#ff0000;">错误: 无法创建模板<b>'.$tplset_name.'</b>.</span><br />';
} else {
$tplsetid = $tplset->getVar('tplset_id');
echo '模板<b>'.$tplset_name.'</b>创建完毕. (ID: <b>'.$tplsetid.'</b>)</span><br />';
$tpltpl_handler = xoops_gethandler('tplfile');
$themeimages = array();
foreach ($tar->files as $id => $info) {
$infoarr = explode('/', str_replace("\\", '/', $info['name']));
if (isset($infoarr[3]) && trim($infoarr[3]) == 'blocks') {
$default =& $tpltpl_handler->find('default', 'block', null, trim($infoarr[2]), trim($infoarr[4]));
} elseif ((!isset($infoarr[4]) || trim($infoarr[4]) == '') && $infoarr[1] == 'templates') {
$default =& $tpltpl_handler->find('default', 'module', null, trim($infoarr[2]), trim($infoarr[3]));
} elseif (isset($infoarr[3]) && trim($infoarr[3]) == 'images') {
$infoarr[2] = trim($infoarr[2]);
if (preg_match("/(.*)\.(gif|jpg|jpeg|png)$/i", $infoarr[2], $match)) {
$themeimages[] = array('name' => $infoarr[2], 'content' => $info['file']);
}
}
if (isset($default) && count($default) > 0) {
$newtpl =& $default[0]->xoopsClone();
$newtpl->setVar('tpl_id', 0);
$newtpl->setVar('tpl_tplset', $tplset_name);
$newtpl->setVar('tpl_source', $info['file'], true);
$newtpl->setVar('tpl_lastmodified', time());
if (!$tpltpl_handler->insert($newtpl)) {
echo ' <span style="color:#ff0000;">错误: 无法插入 <b>'.$info['name'].'</b> 到数据库.</span><br />';
} else {
echo ' <b>'.$info['name'].'</b>已插入到数据库.<br />';
}
unset($default);
}
unset($info);
}
$icount = count($themeimages);
if ($icount > 0) {
$imageset_handler =& xoops_gethandler('imageset');
$imgset =& $imageset_handler->create();
$imgset->setVar('imgset_name', $tplset_name);
$imgset->setVar('imgset_refid', 0);
if (!$imageset_handler->insert($imgset)) {
echo ' <span style="color:#ff0000;">错误: 无法创建图片集.</span><br />';
} else {
$newimgsetid = $imgset->getVar('imgset_id');
echo ' 图片集<b>'.$tplset_name.'</b>创建完毕. (ID: <b>'.$newimgsetid.'</b>)<br />';
if (!$imageset_handler->linktplset($newimgsetid, $tplset_name)) {
echo ' <span style="color:#ff0000;">错误: 将图片集关联到模板<b>'.$tplset_name.'</b>时失败</span><br />';
}
$image_handler =& xoops_gethandler('imagesetimg');
for ($i = 0; $i < $icount; $i++) {
if (isset($themeimages[$i]['name']) && $themeimages[$i]['name'] != '') {
$image =& $image_handler->create();
$image->setVar('imgsetimg_file', $themeimages[$i]['name']);
$image->setVar('imgsetimg_imgset', $newimgsetid);
$image->setVar('imgsetimg_body', $themeimages[$i]['content'], true);
if (!$image_handler->insert($image)) {
echo ' <span style="color:#ff0000;">错误: 将图片文件数据插入数据库时失败.</span><br />';
} else {
echo ' 图片文件数据已保存到数据库. (ID: <b>'.$image->getVar('imgsetimg_id').'</b>)<br />';
}
}
}
}
}
}
}
}
}
} else {
echo '<span style="color:#ff0000;">错误: 文件上传失败</span>';
}
echo '</code><br /><a href="admin.php?fct=tplsets">'._MD_AM_BTOTADMIN.'</a>';
xoops_cp_footer();
break;
case 'previewtpl':
require_once XOOPS_ROOT_PATH.'/class/template.php';
$myts =& MyTextsanitizer::getInstance();
$html = $myts->stripSlashesGPC($html);
$tpltpl_handler =& xoops_gethandler('tplfile');
$tplfile =& $tpltpl_handler->get($id, true);
$xoopsTpl = new XoopsTpl();
if (is_object($tplfile)) {
$dummylayout = '<html><head><meta http-equiv="content-type" content="text/html; charset='._CHARSET.'" /><meta http-equiv="content-language" content="'._LANGCODE.'" /><title>'.$xoopsConfig['sitename'].'</title><style type="text/css" media="all">';
$css =& $tpltpl_handler->find($xoopsConfig['template_set'], 'css', 0, null, null, true);
$csscount = count($css);
for ($i = 0; $i < $csscount; $i++) {
$dummylayout .= "\n".$css[$i]->getVar('tpl_source');
}
$dummylayout .= "\n".'</style></head><body><{$content}></body></html>';
if ($tplfile->getVar('tpl_type') == 'block') {
include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php';
$block = new XoopsBlock($tplfile->getVar('tpl_refid'));
$xoopsTpl->assign('block', $block->buildBlock());
}
$dummytpl = '_dummytpl_'.time().'.html';
$fp = fopen(XOOPS_CACHE_PATH.'/'.$dummytpl, 'w');
fwrite($fp, $html);
fclose($fp);
$xoopsTpl->assign('content', $xoopsTpl->fetch('file:'.XOOPS_CACHE_PATH.'/'.$dummytpl));
$xoopsTpl->clear_compiled_tpl('file:'.XOOPS_CACHE_PATH.'/'.$dummytpl);
unlink(XOOPS_CACHE_PATH.'/'.$dummytpl);
$dummyfile = '_dummy_'.time().'.html';
$fp = fopen(XOOPS_CACHE_PATH.'/'.$dummyfile, 'w');
fwrite($fp, $dummylayout);
fclose($fp);
$dummyfile2 = '_dummy2_'.time().'.html';
$fp = fopen(XOOPS_CACHE_PATH.'/'.$dummyfile2, 'w');
fwrite($fp, $xoopsTpl->fetch('file:'.XOOPS_CACHE_PATH.'/'.$dummyfile));
fclose($fp);
$xoopsTpl->clear_compiled_tpl('file:'.XOOPS_CACHE_PATH.'/'.$dummyfile);
unlink(XOOPS_CACHE_PATH.'/'.$dummyfile);
$tplset= $tplfile->getVar('tpl_tplset');
$tform = array('tpl_tplset' => $tplset, 'tpl_id' => $id, 'tpl_file' => $tplfile->getVar('tpl_file'), 'tpl_desc' => $tplfile->getVar('tpl_desc'), 'tpl_lastmodified' => $tplfile->getVar('tpl_lastmodified'), 'tpl_source' => htmlspecialchars($html, ENT_QUOTES), 'tpl_module' => $moddir);
include_once XOOPS_ROOT_PATH.'/modules/system/admin/tplsets/tplform.php';
xoops_cp_header();
echo '<a href="admin.php?fct=tplsets">'. _MD_TPLMAIN .'</a> <span style="font-weight:bold;">»»</span> <a href="./admin.php?fct=tplsets&op=listtpl&moddir='.$moddir.'&tplset='.$tplset.'">'.$tplset.'</a> <span style="font-weight:bold;">»»</span> '._MD_EDITTEMPLATE.'<br /><br />';
$form->display();
xoops_cp_footer();
echo '<script type="text/javascript">
<!--//
preview_window = openWithSelfMain("'.XOOPS_URL.'/modules/system/admin.php?fct=tplsets&op=previewpopup&file='.$dummyfile2.'", "popup", 680, 450);
//-->
</script>';
}
break;
case 'update':
include_once XOOPS_ROOT_PATH.'/class/uploader.php';
$uploader = new XoopsMediaUploader(XOOPS_UPLOAD_PATH, array('text/html', 'application/x-cdf'), 200000);
$uploader->setPrefix('tmp');
$msg = array();
foreach ($_POST['xoops_upload_file'] as $upload_file) {
// '.' is converted to '_' when upload
$upload_file2 = str_replace('.', '_', $upload_file);
if ($uploader->fetchMedia($upload_file2)) {
if (!$uploader->upload()) {
$msg[] = $uploader->getErrors();
} else {
$tpltpl_handler =& xoops_gethandler('tplfile');
if (!isset($old_template[$upload_file])) {
$tplfile =& $tpltpl_handler->find('default', null, null, $moddir, $upload_file);
if (count($tplfile) > 0) {
$tpl =& $tplfile[0]->xoopsClone();
$tpl->setVar('tpl_id', 0);
$tpl->setVar('tpl_tplset', $tplset);
} else {
$msg[] = '模板文件<b>'.$upload_file.'</b>没有必要安装 (使用该模板的PHP文件不存在)';
continue;
}
} else {
$tpl =& $tpltpl_handler->get($old_template[$upload_file]);
}
$tpl->setVar('tpl_lastmodified', time());
$fp = @fopen($uploader->getSavedDestination(), 'r');
$fsource = @fread($fp, filesize($uploader->getSavedDestination()));
@fclose($fp);
$tpl->setVar('tpl_source', $fsource, true);
@unlink($uploader->getSavedDestination());
if (!$tpltpl_handler->insert($tpl)) {
$msg[] = '将上传的 '.$upload_file.' 数据插入数据库时失败';
} else {
$msg[] = '模板文件<b>'.$upload_file.'</b>更新完成.';
if ($tplset == $xoopsConfig['template_set']) {
include_once XOOPS_ROOT_PATH.'/class/template.php';
if (xoops_template_touch($tpl->getVar('tpl_id'), true)) {
$msg[] = '模板文件<b>'.$upload_file.'</b>编译完成.';
}
}
}
}
} else {
if ($uploader->getMediaName() == '') {
continue;
} else {
$msg[] = $uploader->getErrors();
}
}
}
xoops_cp_header();
echo '<code>';
foreach ($msg as $m) {
echo $m.'<br />';
}
echo '</code><br /><a href="admin.php?fct=tplsets&op=listtpl&tplset='.$tplset.'&moddir='.$moddir.'">'._MD_AM_BTOTADMIN.'</a>';
xoops_cp_footer();
break;
case 'importtpl':
xoops_cp_header();
if (!empty($id)) {
xoops_confirm(array('tplset' => $tplset, 'moddir' => $moddir, 'id' => $id, 'op' => 'impor
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -