//
// ------------------------------------------------------------------------ //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// You may not change or alter any portion of this comment or credits //
// of supporting developers from this source code or any supporting //
// source code which is considered copyrighted (c) material of the //
// original comment or credit authors. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program; if not, write to the Free Software //
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
// ------------------------------------------------------------------------ //
// Author: Kazumi Ono (AKA onokazu) //
// URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
// Project: The XOOPS Project //
// ------------------------------------------------------------------------- //
if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
exit("Access Denied");
} else {
$op = 'list';
if (isset($_POST)) {
foreach ( $_POST as $k => $v ) {
${$k} = $v;
}
}
if (isset($_GET['op'])) {
$op = trim($_GET['op']);
$id = $moddir = $file = $type = $tplset = null;
if (isset($_GET['id'])) {
$id = intval($_GET['id']);
}
if (isset($_GET['moddir'])) {
$moddir = trim($_GET['moddir']);
}
if (isset($_GET['file'])) {
$file = trim($_GET['file']);
}
if (isset($_GET['type'])) {
$type = trim($_GET['type']);
}
if (isset($_GET['tplset'])) {
$tplset = trim($_GET['tplset']);
}
}
if ($op == 'edittpl_go') {
if (isset($previewtpl)) {
$op = 'previewtpl';
}
}
switch ($op) {
case 'list':
$tplset_handler =& xoops_gethandler('tplset');
$tplsets =& $tplset_handler->getObjects();
xoops_cp_header();
echo '
'._MD_TPLMAIN.' ';
$installed = array();
$tpltpl_handler =& xoops_gethandler('tplfile');
$installed_mods = $tpltpl_handler->getModuleTplCount('default');
$tcount = count($tplsets);
echo ''._MD_THMSETNAME.' '._MD_CREATED.' '._MD_TEMPLATES.' '._MD_ACTION.' ';
$class = 'even';
for ($i = 0; $i < $tcount; $i++) {
$tplsetname = $tplsets[$i]->getVar('tplset_name');
$installed_themes[] = $tplsetname;
$class = ($class == 'even') ? 'odd' : 'even';
echo ''.$tplsetname.''.$tplsets[$i]->getVar('tplset_desc').' '.formatTimestamp($tplsets[$i]->getVar('tplset_created'), 's').' ';
$tplstats = $tpltpl_handler->getModuleTplCount($tplsetname);
if (count($tplstats) > 0) {
$module_handler =& xoops_gethandler('module');
echo '';
foreach ($tplstats as $moddir => $filecount) {
$module =& $module_handler->getByDirname($moddir);
if (is_object($module)) {
if ($installed_mods[$moddir] > $filecount) {
$filecount = ''.$filecount.' ';
}
echo ''.$module->getVar('name').' ['._LIST.' ('.$filecount.' )] ';
}
unset($module);
}
$not_installed = array_diff(array_keys($installed_mods), array_keys($tplstats));
} else {
$not_installed =& array_keys($installed_mods);
}
foreach ($not_installed as $ni) {
$module =& $module_handler->getByDirname($ni);
echo ''.$module->getVar('name').' ['._LIST.' (0 )] ['._MD_GENERATE.' ] ';
}
echo ' ';
echo '['._MD_DOWNLOAD.' ] ['._CLONE.' ]';
if ($tplsetname != 'default' && $tplsetname != $xoopsConfig['template_set']) {
echo ' ['._DELETE.' ]';
}
echo ' ';
if ($tplsetname == $xoopsConfig['template_set']) {
echo ' ';
} else {
echo ' ';
}
echo ' ';
}
echo '
';
include_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php';
$form = new XoopsThemeForm(_MD_UPLOADTAR, 'tplupload_form', 'admin.php', 'post', true);
$form->setExtra('enctype="multipart/form-data"');
$form->addElement(new XoopsFormFile(_MD_CHOOSETAR.''._MD_ONLYTAR.' ', 'tpl_upload', 1000000));
$form->addElement(new XoopsFormText(_MD_NTHEMENAME.''._MD_ENTERTH.' ', 'tplset_name', 20, 50));
$form->addElement(new XoopsFormHidden('op', 'uploadtar_go'));
$form->addElement(new XoopsFormHidden('fct', 'tplsets'));
$form->addElement(new XoopsFormButton('', 'upload_button', _MD_UPLOAD, 'submit'));
$form->display();
xoops_cp_footer();
break;
case 'listtpl':
$tplset = trim($_GET['tplset']);
if ($tplset == '') {
redirect_header('admin.php?fct=tplsets',1);
}
if ($moddir == '') {
redirect_header('admin.php?fct=tplsets',1);
}
xoops_cp_header();
$module_handler =& xoops_gethandler('module');
$module =& $module_handler->getByDirname($moddir);
$modname = $module->getVar('name');
echo ''. _MD_TPLMAIN .' »» '.$tplset.' ';
echo ''.$modname.' ';
}
xoops_cp_footer();
break;
case 'edittpl':
if ($id <= 0) {
redirect_header('admin.php?fct=tplsets', 1);
}
$tpltpl_handler =& xoops_gethandler('tplfile');
$tplfile =& $tpltpl_handler->get($id, true);
if (is_object($tplfile)) {
$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' => $tplfile->getVar('tpl_source', 'E'), 'tpl_module' => $tplfile->getVar('tpl_module'));
include_once XOOPS_ROOT_PATH.'/modules/system/admin/tplsets/tplform.php';
xoops_cp_header();
echo ''. _MD_TPLMAIN .' »» '.$tplset.' »» '._MD_EDITTEMPLATE.' ';
$form->display();
xoops_cp_footer();
exit();
} else {
$err[] = 'Selected template (ID: $id) does not exist';
}
xoops_cp_header();
xoops_error($err);
echo ''._MD_AM_BTOTADMIN.' ';
xoops_cp_footer();
break;
case 'edittpl_go':
if ($id <= 0 | !$GLOBALS['xoopsSecurity']->check()) {
redirect_header('admin.php?fct=tplsets', 3, implode(' ', $GLOBALS['xoopsSecurity']->getErrors()));
}
$tpltpl_handler =& xoops_gethandler('tplfile');
$tplfile =& $tpltpl_handler->get($id, true);
$err = array();
if (!is_object($tplfile)) {
$err[] = 'Selected template (ID: $id) does not exist';
} else {
if ($tplfile->getVar('tpl_tplset') != 'default') {
$tplfile->setVar('tpl_source', $html);
$tplfile->setVar('tpl_lastmodified', time());
if (!$tpltpl_handler->insert($tplfile)) {
$err[] = 'Could not insert template file to the database.';
} else {
include_once XOOPS_ROOT_PATH.'/class/template.php';
$xoopsTpl = new XoopsTpl();
if ($xoopsTpl->is_cached('db:'.$tplfile->getVar('tpl_file'))) {
if (!$xoopsTpl->clear_cache('db:'.$tplfile->getVar('tpl_file'))) {
}
}
if ($tplfile->getVar('tpl_tplset') == $xoopsConfig['template_set']) {
xoops_template_touch($id);
}
}
} else {
$err[] = 'Default template files cannot be edited.';
}
}
if (count($err) == 0) {
if (!empty($moddir)) {
redirect_header('admin.php?fct=tplsets&op=edittpl&id='.$tplfile->getVar('tpl_id'), 2, _MD_AM_DBUPDATED);
} elseif (isset($redirect)) {
redirect_header('admin.php?fct=tplsets&tplset='.$tplfile->getVar('tpl_tplset').'&op='.trim($redirect), 2, _MD_AM_DBUPDATED);
} else {
redirect_header('admin.php?fct=tplsets', 2, _MD_AM_DBUPDATED);
}
}
xoops_cp_header();
xoops_error($err);
echo ''._MD_AM_BTOTADMIN.' ';
xoops_cp_footer();
break;
case 'deletetpl':
xoops_cp_header();
xoops_confirm(array('id' => $id, 'op' => 'deletetpl_go', 'fct' => 'tplsets'), 'admin.php', _MD_RUSUREDELTPL, _YES);
xoops_cp_footer();
break;
case 'deletetpl_go':
if ($id <= 0 | !$GLOBALS['xoopsSecurity']->check()) {
redirect_header('admin.php?fct=tplsets', 1, implode(' ', $GLOBALS['xoopsSecurity']->getErrors()));
}
$tpltpl_handler =& xoops_gethandler('tplfile');
$tplfile =& $tpltpl_handler->get($id);
$err = array();
if (!is_object($tplfile)) {
$err[] = 'Selected template (ID: $id) does not exist';
} else {
if ($tplfile->getVar('tpl_tplset') != 'default') {
if (!$tpltpl_handler->delete($tplfile)) {
$err[] = 'Could not delete '.$tplfile->getVar('tpl_file').' from the database.';
} else {
// need to compile default xoops template
if ($tplfile->getVar('tpl_tplset') == $xoopsConfig['template_set']) {
$defaulttpl =& $tpltpl_handler->find('default', $tplfile->getVar('tpl_type'), $tplfile->getVar('tpl_refid'), null, $tplfile->getVar('tpl_file'));
if (count($defaulttpl) > 0) {
include_once XOOPS_ROOT_PATH.'/class/template.php';
xoops_template_touch($defaulttpl[0]->getVar('tpl_id'), true);
}
}
}
} else {
$err[] = 'Default template files cannot be deleted.';
}
}
if (count($err) == 0) {
redirect_header('admin.php?fct=tplsets&op=listtpl&moddir='.$tplfile->getVar('tpl_module').'&tplset='.urlencode($tplfile->getVar('tpl_tplset')), 2, _MD_AM_DBUPDATED);
}
xoops_cp_header();
xoops_error($err);
echo ''._MD_AM_BTOTADMIN.' ';
xoops_cp_footer();
break;
case 'delete':
xoops_cp_header();
xoops_confirm(array('tplset' => $tplset, 'op' => 'delete_go', 'fct' => 'tplsets'), 'admin.php', _MD_RUSUREDELTH, _YES);
xoops_cp_footer();
break;
case 'delete_go':
if (!$GLOBALS['xoopsSecurity']->check()) {
redirect_header('admin.php?fct=tplsets', 1, implode(' ', $GLOBALS['xoopsSecurity']->getErrors()));
}
$msgs = array();
if ($tplset != 'default' && $tplset != $xoopsConfig['template_set']) {
$tpltpl_handler =& xoops_gethandler('tplfile');
$templates =& $tpltpl_handler->getObjects(new Criteria('tpl_tplset', $tplset));
$tcount = count($templates);
if ($tcount > 0) {
$msgs[] = 'Deleting template files...';
for ($i = 0; $i < $tcount; $i++) {
if (!$tpltpl_handler->delete($templates[$i])) {
$msgs[] = ' ERROR: Could not delete template '.$templates[$i]->getVar('tpl_file').' . ID: '.$templates[$i]->getVar('tpl_id').' ';
} else {
$msgs[] = ' Template '.$templates[$i]->getVar('tpl_file').' deleted. ID: '.$templates[$i]->getVar('tpl_id').' ';
}
}
}
/*
$image_handler =& xoops_gethandler('imagesetimg');
$imagefiles =& $image_handler->getObjects(new Criteria('tplset_name', $tplset));
$icount = count($imagefiles);
if ($icount > 0) {
$msgs[] = 'Deleting image files...';
for ($i = 0; $i < $icount; $i++) {
if (!$image_handler->delete($imagefiles[$i])) {
$msgs[] = ' ERROR: Could not remove file '.$imagefiles[$i]->getVar('imgsetimg_file').' from the database (ID: '.$imagefiles[$i]->getVar('imgsetimg_id').' ) ';
} else {
$msgs[] = ' File '.$imagefiles[$i]->getVar('imgsetimg_file').' deleted from the database (ID: '.$imagefiles[$i]->getVar('imgsetimg_id').' )';
}
}
}
$imageset_handler =& xoops_gethandler('imageset');
$imagesets =& $imageset_handler->getObjects(new Criteria('tplset_name', $tplset));
$scount = count($imagesets);
if ($scount > 0) {
$msgs[] = 'Deleting image set data...';
for ($i = 0; $i < $scount; $i++) {
if (!$imageset_handler->unlinktplset($imagesets[$i]->getVar('imgset_id'), $tplset)) {
$msgs[] = ' ERROR: Could not remove link between '.$imagesets[$i]->getVar('imgset_name').' (ID: '.$imagesets[$i]->getVar('imgset_id').' ) and '.$tplset.' from the database. ';
} else {
$msgs[] = ' Link between '.$imagesets[$i]->getVar('imgset_name').' (ID: '.$imagesets[$i]->getVar('imgset_id').' ) and '.$tplset.' removed from the database.';
}
if (!$imageset_handler->delete($imagesets[$i])) {
$msgs[] = ' ERROR: Could not delete image set '.$imagesets[$i]->getVar('imgset_name').' (ID: '.$imagesets[$i]->getVar('imgset_id').' ) from the database. ';
} else {
$msgs[] = ' Image set '.$imagesets[$i]->getVar('imgset_name').' (ID: '.$imagesets[$i]->getVar('imgset_id').' ) removed from the database.';
}
}
}
*/
$tplset_handler =& xoops_gethandler('tplset');
$tplsets =& $tplset_handler->getObjects(new Criteria('tplset_name', $tplset));
if (count($tplsets) > 0 && is_object($tplsets[0])) {
$msgs[] = 'Deleting template set data...';
if (!$tplset_handler->delete($tplsets[0])) {
$msgs[] = ' ERROR: Template set '.$tplset.' could not be deleted. ';
} else {
$msgs[] = ' Template set data removed from the database.';
}
}
} else {
$msgs[] = 'ERROR: Default template files cannot be deleted ';
}
xoops_cp_header();
foreach ($msgs as $msg) {
echo ''.$msg.'
';
}
echo ''._MD_AM_BTOTADMIN.' ';
xoops_cp_footer();
break;
case 'clone':
include_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php';
$form = new XoopsThemeForm(_MD_CLONETHEME, 'template_form', 'admin.php', 'post', true);
$form->addElement(new XoopsFormLabel(_MD_THEMENAME, $tplset));
$form->addElement(new XoopsFormText(_MD_NEWNAME, 'newtheme', 30, 50), true);
$form->addElement(new XoopsFormHidden('tplset', $tplset));
$form->addElement(new XoopsFormHidden('op', 'clone_go'));
$form->addElement(new XoopsFormHidden('fct', 'tplsets'));
$form->addElement(new XoopsFormButton('', 'tpl_button', _SUBMIT, 'submit'));
xoops_cp_header();
echo ''. _MD_TPLMAIN .' »» '._MD_CLONETHEME.' ';
$form->display();
xoops_cp_footer();
break;
case 'clone_go':
if (!$GLOBALS['xoopsSecurity']->check()) {
redirect_header('admin.php?fct=tplsets', 1, implode(' ', $GLOBALS['xoopsSecurity']->getErrors()));
}
$msgs = array();
$tplset = trim($tplset);
$newtheme = trim($newtheme);
$tpltpl_handler =& xoops_gethandler('tplfile');
xoops_cp_header();
if ($tplset == $newtheme) {
xoops_error('Template set name must be a different name.');
} elseif ($tpltpl_handler->getCount(new Criteria('tpl_tplset', $newtheme)) > 0) {
xoops_error('Template set '.$newtheme.' already exists.');
} else {
$tplset_handler =& xoops_gethandler('tplset');
$tplsetobj =& $tplset_handler->create();
$tplsetobj->setVar('tplset_name', $newtheme);
$tplsetobj->setVar('tplset_created', time());
if (!$tplset_handler->insert($tplsetobj)) {
$msgs[] = 'ERROR: Could not create template set '.$newtheme.' . ';
} else {
$tplsetid = $tplsetobj->getVar('tplset_id');
$templates =& $tpltpl_handler->getObjects(new Criteria('tpl_tplset', $tplset), true);
$tcount = count($templates);
if ($tcount > 0) {
$msgs[] = 'Copying template files...';
for ($i = 0; $i < $tcount; $i++) {
$newtpl =& $templates[$i]->xoopsClone();
$newtpl->setVar('tpl_tplset', $newtheme);
$newtpl->setVar('tpl_id', 0);
$newtpl->setVar('tpl_lastimported', 0);
$newtpl->setVar('tpl_lastmodified', time());
if (!$tpltpl_handler->insert($newtpl)) {
$msgs[] = ' ERROR: Failed copying template '.$templates[$i]->getVar('tpl_file').' . ID: '.$templates[$i]->getVar('tpl_id').' ';
} else {
$msgs[] = ' Template '.$templates[$i]->getVar('tpl_file').' copied. ID: '.$newtpl->getVar('tpl_id').' ';
}
unset($newtpl);
}
/*
$imageset_handler =& xoops_gethandler('imageset');
$orig_imgset =& $imageset_handler->getObjects(new Criteria('tplset_name', $tplset));
$msgs[] = 'Copying image files...';
$imgsetcount = count($orig_imgset);
for ($i = 0; $i < $imgsetcount; $i++) {
if ($orig_imgset[$i]->getVar('imgset_refid') == 0) {
$new_imgset =& $orig_imgset[$i]->xoopsClone();
$new_imgset->setVar('imgset_id', 0);
$new_imgset->setVar('imgset_name', $newtheme);
if (!$imageset_handler->insert($new_imgset)) {
$msgs[] = ' ERROR: Failed copying template image set data. ';
} else {
$new_imgsetid = $new_imgset->getVar('imgset_id');
$msgs[] = ' Template image set data copied. (Name: '.$newtheme.' ID: '.$new_imgsetid.' )';
$image_handler = xoops_gethandler('imagesetimg');
$orig_images =& $image_handler->getByImageset($orig_imgset[$i]->getVar('imgset_id'));
$imgcount = count($orig_images);
for ($j = 0; $j < $imgcount; $j++) {
$new_image =& $orig_images[$j]->xoopsClone();
$new_image->setVar('imgsetimg_id', 0);
$new_image->setVar('imgsetimg_imgset', $new_imgsetid);
if (!$image_handler->insert($new_image)) {
$msgs[] = ' ERROR: Failed copying data for image file '.$orig_images[$j]->getVar('imgsetimg_file').' . ';
} else {
$thisimage = $orig_images[$j]->getVar('imgsetimg_file');
$msgs[] = ' Data for image file '.$thisimage.' copied.';
}
}
if (!$imageset_handler->linktplset($new_imgsetid, $newtheme)) {
$msgs[] = ' ERROR: Failed creating link between template image set (ID : '.$new_imgsetid.' ) and template set '.$newtheme.' . ';
} else {
$msgs[] = ' Template image set (ID: '.$new_imgsetid.' ) and template set '.$newtheme.' linked.';
}
}
} else {
// module image set, so just create another link to the new template set
if (!$imageset_handler->linktplset($orig_imgset[$i]->getVar('imgset_id'), $newtheme)) {
$msgs[] = ' ERROR: Failed creating link between module image set '.$orig_imgset[$i]->getVar('imgset_name').' (ID '.$orig_imgset[$i]->getVar('imgset_id').' ) and template set '.$newtheme.' . ';
} else {
$msgs[] = ' Module image set '.$orig_imgset[$i]->getVar('imgset_name').' (ID '.$orig_imgset[$i]->getVar('imgset_id').' ) and template set '.$newtheme.' linked.';
}
}
}
*/
$msgs[] = 'Template set '.htmlspecialchars($newtheme, ENT_QUOTES).' created. (ID: '.$tplsetid.' ) ';
} else {
$msgs[] = 'ERROR: Template files for '.$theme.' do not exist ';
}
}
}
foreach ($msgs as $msg) {
echo ''.$msg.'
';
}
echo ''._MD_AM_BTOTADMIN.' ';
xoops_cp_footer();
break;
/*
case 'editimage':
xoops_cp_header();
echo ''. _MD_TPLMAIN .' »» '._MD_EDITSKINIMG.' ('.$tplset.') ';
include XOOPS_ROOT_PATH.'/modules/system/admin/tplsets/tplimgform.php';
xoops_cp_footer();
break;
case 'updateimage':
$tplset = trim($tplset);
$err = array();
if ($tplset != 'default') {
include_once XOOPS_ROOT_PATH.'/class/uploader.php';
$mimetypes = array('image/gif', "image/pjpeg", "image/jpeg", "image/jpeg", "image/jpeg", "image/png", 'image/x-png', "application/x-shockwave-flash", "image/tiff", "image/tiff", 'image/bmp');
if ($tplset == $xoopsConfig['template_set']) {
//directly upload to cache to reduce one step ;-)
$uploader = new XoopsMediaUploader(XOOPS_CACHE_PATH, $mimetypes, 500000);
} else {
$uploader = new XoopsMediaUploader(XOOPS_UPLOAD_PATH, $mimetypes, 500000);
}
$image_handler =& xoops_gethandler('imagesetimg');
foreach ($imgids as $id) {
if (isset($imgfiles[$id]) && trim($imgfiles[$id]) != '') {
if ($uploader->fetchMedia('imgfiles', $id)) {
$image =& $image_handler->get($id);
$uploader->setTargetFileName($image->getVar('imgsetimg_file'));
if (!$uploader->upload()) {
$err[] = $uploader->getErrors();
} else {
$fp = @fopen($uploader->getSavedDestination(), 'rb');
$image->setVar('imgsetimg_body', @fread($fp, filesize($uploader->getSavedDestination())), true);
@fclose($fp);
if ($tplset != $xoopsConfig['template_set']) {
@unlink($uploader->getSavedDestination());
}
if (!$image_handler->insert($image)) {
$err[] = 'Could not save '.$image->getVar('imgsetimg_file');
}
}
} else {
$err[] = $uploader->getErrors();
}
} elseif (!empty($imgdelete[$id])) {
$image =& $image_handler->get($id);
if (!$image_handler->delete($image)) {
$err[] = 'Could not remove image file '.$image->getVar('imgsetimg_file');
} else {
if ($tplset == $xoopsConfig['template_set']) {
@unlink(XOOPS_CACHE_PATH.'/'.$image->getVar('imgsetimg_file'));
}
}
}
}
} else {
$err[] = 'Cannot change XOOPS system default theme set images';
}
// delete image set if no more images
$current_imgs =& $image_handler->getByImageset($imgset);
if (count($current_imgs) == 0) {
$imageset_handler =& xoops_gethandler('imageset');
$imgset =& $imageset_handler->get($imgset);
if (!$imageset_handler->delete($imgset)) {
$err[] = 'Could not remove image set '.$imgset->getVar('imgset_name');
}
}
if (count($err) > 0) {
xoops_cp_header();
xoops_error($err);
xoops_cp_footer();
} else {
redirect_header('admin.php?fct=tplsets&op=editimage&tplset='.$tplset, 2, _MD_AM_DBUPDATED);
}
break;
case 'addimage':
$tplset = trim($tplset);
$err = array();
if ($tplset != 'default') {
include_once XOOPS_ROOT_PATH.'/class/uploader.php';
$mimetypes = array('image/gif', "image/pjpeg", "image/jpeg", "image/jpeg", "image/jpeg", "image/png", 'image/x-png', "application/x-shockwave-flash", "image/tiff", "image/tiff", 'image/bmp');
if ($tplset == $xoopsConfig['template_set']) {
//directly upload to cache to reduce one step ;-)
$uploader = new XoopsMediaUploader(XOOPS_CACHE_PATH, $mimetypes, 500000);
} else {
$uploader = new XoopsMediaUploader(XOOPS_UPLOAD_PATH, $mimetypes, 500000);
}
$image_handler =& xoops_gethandler('imagesetimg');
if ($uploader->fetchMedia('imgfile')) {
if (!empty($imgset)) {
//check if an image with the same name exists
if ($image_handler->imageExists($uploader->getMediaName(), $imgset)) {
$err[] = 'Image file '.$uploader->getMediaName().' already exists';
}
}
if (empty($err)) {
$image =& $image_handler->create();
if (!$uploader->upload()) {
$err[] = $uploader->getErrors();
} else {
if (!$fp = @fopen($uploader->getSavedDestination(), 'rb')) {
$err[] = 'Could not read '.$uploader->getSavedFileName();
} else {
$image->setVar('imgsetimg_body', @fread($fp, filesize($uploader->getSavedDestination())), true);
@fclose($fp);
if ($tplset != $xoopsConfig['template_set']) {
@unlink($uploader->getSavedDestination());
}
$image->setVar('imgsetimg_file', $uploader->getSavedFileName());
if (!empty($imgset)) {
$image->setVar('imgsetimg_imgset', $imgset);
} else {
$imageset_handler =& xoops_gethandler('imageset');
$imgset =& $imageset_handler->create();
$imgset->setVar('imgset_name', $tplset);
$imgset->setVar('imgset_refid', 0);
if (!$imageset_handler->insert($imgset)) {
$err[] = 'Could not create image set.';
} else {
$newimgsetid = $imgset->getVar('imgset_id');
$image->setVar('imgsetimg_imgset', $newimgsetid);
if (!$imageset_handler->linktplset($newimgsetid, $tplset)) {
$err[] = 'Failed linking image set to template set '.$tplset;
}
}
}
if (count($err) == 0) {
if (!$image_handler->insert($image)) {
$err[] = 'Could not save '.$image->getVar('imgsetimg_file');
}
}
}
}
}
} else {
$err[] = $uploader->getErrors();
}
}
if (count($err) > 0) {
xoops_cp_header();
xoops_error($err);
xoops_cp_footer();
} else {
redirect_header('admin.php?fct=tplsets&op=editimage&tplset='.$tplset, 2, _MD_AM_DBUPDATED);
}
break;
case 'showimage':
$image_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
if (empty($image_id)) {
header('Content-type: image/gif');
readfile(XOOPS_UPLOAD_PATH.'/blank.gif');
exit();
}
$image_handler =& xoops_gethandler('imagesetimg');
$image =& $image_handler->getObjects(new Criteria('imgsetimg_id', $image_id));
if (count($image) > 0) {
$mimetypes = array('gif' => 'image/gif', "jpe"=>"image/jpeg", "jpeg"=>"image/jpeg", "jpg"=>"image/jpeg", "png"=>"image/png", "swf"=>"application/x-shockwave-flash", "tif"=>"image/tiff", "tiff"=>"image/tiff", "bmp" => 'image/bmp');
$ext = substr(strtolower(strrchr($image[0]->getVar('imgsetimg_file'), '.')), 1);
if (in_array($ext, array_keys($mimetypes))) {
header('Content-type: '.$mimetypes[$ext]);
}
header('Cache-control: max-age=31536000');
header('Expires: '.gmdate("D, d M Y H:i:s",time()+31536000).'GMT');
header('Content-disposition: filename='.$image[0]->getVar('imgsetimg_file'));
header('Content-Length: '.strlen($image[0]->getVar('imgsetimg_body')));
header('Last-Modified: '.gmdate("D, d M Y H:i:s", time()).'GMT');
echo $image[0]->getVar('imgsetimg_body');
} else {
header('Content-type: image/gif');
readfile(XOOPS_UPLOAD_PATH.'/blank.gif');
}
break;
*/
case 'viewdefault':
$tpltpl_handler =& xoops_gethandler('tplfile');
$tplfile =& $tpltpl_handler->get($id);
$default =& $tpltpl_handler->find('default', $tplfile->getVar('tpl_type'), $tplfile->getVar('tpl_refid'), null, $tplfile->getVar('tpl_file'));
echo "";
echo '
'.htmlspecialchars($xoopsConfig['sitename']).' Administration
';
if (is_object($default[0])) {
$tpltpl_handler->loadSource($default[0]);
$last_modified = $default[0]->getVar('tpl_lastmodified');
$last_imported = $default[0]->getVar('tpl_lastimported');
if ($default[0]->getVar('tpl_type') == 'block') {
$path = XOOPS_ROOT_PATH.'/modules/'.$default[0]->getVar('tpl_module').'/blocks/'.$default[0]->getVar('tpl_file');
} else {
$path = XOOPS_ROOT_PATH.'/modules/'.$default[0]->getVar('tpl_module').'/'.$default[0]->getVar('tpl_file');
}
$colorchange = '';
if (!file_exists($path)) {
$filemodified_date = _MD_NOFILE;
$lastimported_date = _MD_NOFILE;
} else {
$tpl_modified = filemtime($path);
$filemodified_date = formatTimestamp($tpl_modified, 'l');
if ($tpl_modified > $last_imported) {
$colorchange = ' bgcolor="#ffCC99"';
}
$lastimported_date = formatTimestamp($last_imported, 'l');
}
include_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php';
$form = new XoopsThemeForm(_MD_VIEWDEFAULT, 'template_form', 'admin.php');
$form->addElement(new XoopsFormTextArea(_MD_FILEHTML, 'html', $default[0]->getVar('tpl_source'), 25));
$form->display();
} else {
echo 'Selected file does not exist';
}
echo '';
break;
case 'downloadtpl':
$tpltpl_handler =& xoops_gethandler('tplfile');
$tpl =& $tpltpl_handler->get(intval($id), true);
if (is_object($tpl)) {
$output = $tpl->getVar('tpl_source');
strlen($output);
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
header('Content-Type: application/force-download');
if (preg_match("/MSIE 5.5/", $_SERVER['HTTP_USER_AGENT'])) {
header('Content-Disposition: filename='.$tpl->getVar('tpl_file'));
} else {
header('Content-Disposition: attachment; filename='.$tpl->getVar('tpl_file'));
}
header('Content-length: '.strlen($output));
echo $output;
}
break;
case 'uploadtpl':
$tpltpl_handler =& xoops_gethandler('tplfile');
$id = intval($_GET['id']);
$tpl =& $tpltpl_handler->get($id);
xoops_cp_header();
echo ''. _MD_TPLMAIN .' »» '.$tpl->getVar('tpl_tplset').' »» '._MD_UPLOAD.' ';
if (is_object($tpl)) {
include_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php';
$form = new XoopsThemeForm(_MD_UPLOAD, 'tplupload_form', 'admin.php', 'post', true);
$form->setExtra('enctype="multipart/form-data"');
$form->addElement(new XoopsFormLabel(_MD_FILENAME, $tpl->getVar('tpl_file').' ('.$tpl->getVar('tpl_tplset').')'));
$form->addElement(new XoopsFormFile(_MD_CHOOSEFILE.''._MD_UPWILLREPLACE.' ', 'tpl_upload', 200000), true);
$form->addElement(new XoopsFormHidden('tpl_id', $id));
$form->addElement(new XoopsFormHidden('op', 'uploadtpl_go'));
$form->addElement(new XoopsFormHidden('fct', 'tplsets'));
$form->addElement(new XoopsFormButton('', 'upload_button', _MD_UPLOAD, 'submit'));
$form->display();
xoops_cp_footer();
exit();
} else {
echo 'Selected template does not exist';
}
xoops_cp_footer();
break;
case 'uploadtpl_go':
if (!$GLOBALS['xoopsSecurity']->check()) {
redirect_header('admin.php?fct=tplsets', 1, implode(' ', $GLOBALS['xoopsSecurity']->getErrors()));
}
$tpltpl_handler =& xoops_gethandler('tplfile');
$tpl =& $tpltpl_handler->get($tpl_id);
if (is_object($tpl)) {
include_once XOOPS_ROOT_PATH.'/class/uploader.php';
$uploader = new XoopsMediaUploader(XOOPS_UPLOAD_PATH, array('text/html', 'application/x-cdf', 'text/plain'), 200000);
$uploader->setPrefix('tmp');
if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
if (!$uploader->upload()) {
$err = $uploader->getErrors();
} else {
$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)) {
$err = 'Failed inserting data to database';
} else {
if ($tpl->getVar('tpl_tplset') == $xoopsConfig['template_set']) {
include_once XOOPS_ROOT_PATH.'/class/template.php';
xoops_template_touch($tpl_id, true);
}
}
}
} else {
$err = implode(' ', $uploader->getErrors(false));
}
if (isset($err)) {
xoops_cp_header(false);
xoops_error($err);
xoops_cp_footer();
exit();
}
redirect_header('admin.php?fct=tplsets&op=listtpl&moddir='.$tpl->getVar('tpl_module').'&tplset='.urlencode($tpl->getVar('tpl_tplset')), 2, _MD_AM_DBUPDATED);
}
break;
// upload new file
case 'uploadtpl2':
xoops_cp_header();
$tplset = htmlspecialchars($tplset);
$moddir = htmlspecialchars($moddir);
echo ''. _MD_TPLMAIN .' »» '.$tplset.' »» '._MD_UPLOAD.' ';
include_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php';
$form = new XoopsThemeForm(_MD_UPLOAD, 'tplupload_form', 'admin.php', 'post', true);
$form->setExtra('enctype="multipart/form-data"');
$form->addElement(new XoopsFormLabel(_MD_FILENAME, $file));
$form->addElement(new XoopsFormFile(_MD_CHOOSEFILE.''._MD_UPWILLREPLACE.' ', 'tpl_upload', 200000), true);
$form->addElement(new XoopsFormHidden('moddir', $moddir));
$form->addElement(new XoopsFormHidden('tplset', $tplset));
$form->addElement(new XoopsFormHidden('file', $file));
$form->addElement(new XoopsFormHidden('type', $type));
$form->addElement(new XoopsFormHidden('op', 'uploadtpl2_go'));
$form->addElement(new XoopsFormHidden('fct', 'tplsets'));
$form->addElement(new XoopsFormButton('', 'ploadtarupload_button', _MD_UPLOAD, 'submit'));
$form->display();
xoops_cp_footer();
break;
case 'uploadtpl2_go':
if (!$GLOBALS['xoopsSecurity']->check()) {
redirect_header('admin.php?fct=tplsets', 1, implode(' ', $GLOBALS['xoopsSecurity']->getErrors()));
}
include_once XOOPS_ROOT_PATH.'/class/uploader.php';
$uploader = new XoopsMediaUploader(XOOPS_UPLOAD_PATH, array('text/html', 'application/x-cdf', 'text/plain'), 200000);
$uploader->setPrefix('tmp');
if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
if (!$uploader->upload()) {
$err = $uploader->getErrors();
} else {
$tpltpl_handler =& xoops_gethandler('tplfile');
$tplfile =& $tpltpl_handler->find('default', $type, null, $moddir, $file);
if (is_array($tplfile)) {
$tpl =& $tplfile[0]->xoopsClone();
$tpl->setVar('tpl_id', 0);
$tpl->setVar('tpl_tplset', $tplset);
$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)) {
$err = 'Failed inserting data to database';
} else {
if ($tplset == $xoopsConfig['template_set']) {
include_once XOOPS_ROOT_PATH.'/class/template.php';
xoops_template_touch($tpl->getVar('tpl_id'), true);
}
}
} else {
$err = 'This template file does not need to be installed (PHP files using this template file does not exist)';
}
}
} else {
$err = implode(' ', $uploader->getErrors(false));
}
if (isset($err)) {
xoops_cp_header(false);
xoops_error($err);
xoops_cp_footer();
exit();
}
redirect_header('admin.php?fct=tplsets&op=listtpl&moddir='.$moddir.'&tplset='.urlencode($tplset), 2, _MD_AM_DBUPDATED);
break;
case 'download':
if (isset($tplset)) {
if (false != extension_loaded('zlib')) {
if (isset($_GET['method']) && $_GET['method'] == 'tar') {
if (@function_exists('gzencode')) {
require_once(XOOPS_ROOT_PATH.'/class/tardownloader.php');
$downloader = new XoopsTarDownloader();
}
} else {
if (@function_exists('gzcompress')) {
require_once(XOOPS_ROOT_PATH.'/class/zipdownloader.php');
$downloader = new XoopsZipDownloader();
}
}
$tplset_handler =& xoops_gethandler('tplset');
$tplsetobj =& $tplset_handler->getByName($tplset);
$xml = "<"."?xml version=\"1.0\"?".">\r\n\r\n ".$tplset." \r\n ".$tplsetobj->getVar('tplset_created')." \r\n \r\n".$tplsetobj->getVar('tplset_credits')."\r\n \r\n ".XOOPS_VERSION." \r\n ";
$tpltpl_handler =& xoops_gethandler('tplfile');
$files =& $tpltpl_handler->getObjects(new Criteria('tpl_tplset', $tplset), true);
$fcount = count($files);
if ($fcount > 0) {
for ($i = 0; $i < $fcount; $i++) {
if ($files[$i]->getVar('tpl_type') == 'block') {
$path = $tplset.'/templates/'.$files[$i]->getVar('tpl_module').'/blocks/'.$files[$i]->getVar('tpl_file');
$xml .= "\r\n getVar('tpl_file')."\">\r\n ".$files[$i]->getVar('tpl_module')." \r\n block \r\n ".$files[$i]->getVar('tpl_lastmodified')." \r\n ";
} elseif ($files[$i]->getVar('tpl_type') == 'module') {
$path = $tplset.'/templates/'.$files[$i]->getVar('tpl_module').'/'.$files[$i]->getVar('tpl_file');
$xml .= "\r\n getVar('tpl_file')."\">\r\n ".$files[$i]->getVar('tpl_module')." \r\n module \r\n ".$files[$i]->getVar('tpl_lastmodified')." \r\n ";
}
$downloader->addFileData($files[$i]->getVar('tpl_source'), $path, $files[$i]->getVar('tpl_lastmodified'));
}
$xml .= "\r\n ";
/*
$xml ." "\r\n ";
$image_handler =& xoops_gethandler('imagesetimg');
$criteria = new CriteriaCompo(new Criteria('l.tplset_name', $tplset));
$criteria->add(new Criteria('s.imgset_refid', 0));
$ifiles =& $image_handler->getObjects($criteria);
$fcount = count($ifiles);
for ($i = 0; $i < $fcount; $i++) {
$dummyimage = XOOPS_CACHE_PATH.'/_dummyimage'.$i.time();
$fp = @fopen($dummyimage, 'wb');
@fwrite($fp, $ifiles[$i]->getVar('imgsetimg_body'));
@fclose($fp);
$downloader->addBinaryFile($dummyimage, $tplset.'/images/'.$ifiles[$i]->getVar('imgsetimg_file'));
@unlink($dummyimage);
$xml .= " \r\n getVar('imgsetimg_file')."\"> ";
}
*/
}
//$xml .= "\r\n
$xml .= "\r\n ";
$downloader->addFileData($xml, $tplset.'/tplset.xml', time());
echo $downloader->download($tplset, true);
} else {
xoops_cp_header();
xoops_error(_MD_NOZLIB);
xoops_cp_footer();
}
}
break;
case 'generatetpl':
xoops_cp_header();
xoops_confirm(array('tplset' => $tplset, 'moddir' => $moddir, 'file' => $file, 'type' => $type, 'op' => 'generatetpl_go', 'fct' => 'tplsets'), 'admin.php', _MD_PLZGENERATE, _MD_GENERATE);
xoops_cp_footer();
break;
case 'generatetpl_go':
if (!$GLOBALS['xoopsSecurity']->check()) {
redirect_header('admin.php?fct=tplsets', 3, implode(' ', $GLOBALS['xoopsSecurity']->getErrors()));
}
$tpltpl_handler =& xoops_gethandler('tplfile');
$tplfile =& $tpltpl_handler->find('default', $type, null, $moddir, $file, true);
if (count($tplfile) > 0) {
$newtpl =& $tplfile[0]->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)) {
$err = 'ERROR: Could not insert template '.$tplfile[0]->getVar('tpl_file').' to the database.';
} else {
if ($tplset == $xoopsConfig['template_set']) {
include_once XOOPS_ROOT_PATH.'/class/template.php';
xoops_template_touch($newtpl->getVar('tpl_id'));
}
}
} else {
$err = 'Selected file does not exist)';
}
if (!isset($err)) {
redirect_header('admin.php?fct=tplsets&op=listtpl&moddir='.$newtpl->getVar('tpl_module').'&tplset='.urlencode($newtpl->getVar('tpl_tplset')), 2, _MD_AM_DBUPDATED);
}
xoops_cp_header();
xoops_error($err);
echo ''._MD_AM_BTOTADMIN.' ';
xoops_cp_footer();
break;
case 'generatemod':
xoops_cp_header();
xoops_confirm(array('tplset' => $tplset, 'op' => 'generatemod_go', 'fct' => 'tplsets', 'moddir' => $moddir), 'admin.php', _MD_PLZGENERATE, _MD_GENERATE);
xoops_cp_footer();
break;
case 'generatemod_go':
if (!$GLOBALS['xoopsSecurity']->check()) {
redirect_header('admin.php?fct=tplsets', 3, implode(' ', $GLOBALS['xoopsSecurity']->getErrors()));
}
$tpltpl_handler =& xoops_gethandler('tplfile');
xoops_cp_header();
echo '';
$tplfiles =& $tpltpl_handler->find('default', 'module', null, $moddir, null, true);
$fcount = count($tplfiles);
if ($fcount > 0) {
echo 'Installing module template files for template set '.$tplset.'... ';
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 ' ERROR: Could not insert template '.$file.' to the database. ';
} else {
if ($tplset == $xoopsConfig['template_set']) {
include_once XOOPS_ROOT_PATH.'/class/template.php';
xoops_template_touch($newtpl->getVar('tpl_id'));
}
echo ' Template '.$tplfiles[$i]->getVar('tpl_file').' added to the database. ';
}
}
flush();
unset($newtpl);
}
unset($files);
$tplfiles =& $tpltpl_handler->find('default', 'block', null, $moddir, null, true);
$fcount = count($tplfiles);
if ($fcount > 0) {
echo ' Installing block template files... ';
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 ' ERROR: Could not insert block template '.$tplfiles[$i]->getVar('tpl_file').' to the database. ';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 ' Block template '.$tplfiles[$i]->getVar('tpl_file').' added to the database. ';
}
}
flush();
unset($newtpl);
}
echo ' Module template files for template set '.$tplset.' generated and installed.
'._MD_AM_BTOTADMIN.' ';
xoops_cp_footer();
break;
case 'uploadtar_go':
if (!$GLOBALS['xoopsSecurity']->check()) {
redirect_header('admin.php?fct=tplsets', 3, implode(' ', $GLOBALS['xoopsSecurity']->getErrors()));
}
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 '';
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 'ERROR: Template file not found ';
} elseif (preg_match('/['.preg_quote('\/:*?"<>|','/').']/', $tplset_name)) {
echo 'ERROR: Invalid Template Set Name ';
} else {
$tplset_handler =& xoops_gethandler('tplset');
if ($tplset_handler->getCount(new Criteria('tplset_name', $tplset_name)) > 0) {
echo 'ERROR: Template set '.htmlspecialchars($tplset_name, ENT_QUOTES).' already exists. ';
} else {
$tplset =& $tplset_handler->create();
$tplset->setVar('tplset_name', $tplset_name);
$tplset->setVar('tplset_created', time());
if (!$tplset_handler->insert($tplset)) {
echo 'ERROR: Could not create template set '.htmlspecialchars($tplset_name, ENT_QUOTES).' . ';
} else {
$tplsetid = $tplset->getVar('tplset_id');
echo 'Template set '.htmlspecialchars($tplset_name, ENT_QUOTES).' created. (ID: '.$tplsetid.' ) ';
$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 ' ERROR: Could not insert '.$info['name'].' to the database. ';
} else {
echo ' '.$info['name'].' inserted to the database. ';
}
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 ' ERROR: Could not create image set. ';
} else {
$newimgsetid = $imgset->getVar('imgset_id');
echo ' Image set '.htmlspecialchars($tplset_name, ENT_QUOTES).' created. (ID: '.$newimgsetid.' ) ';
if (!$imageset_handler->linktplset($newimgsetid, $tplset_name)) {
echo ' ERROR: Failed linking image set to template set '.htmlspecialchars($tplset_name, ENT_QUOTES).' ';
}
$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 ' ERROR: Failed storing image file data to database. ';
} else {
echo ' Image file data stored into database. (ID: '.$image->getVar('imgsetimg_id').' ) ';
}
}
}
}
}
}
}
}
}
} else {
$err = implode(' ', $uploader->getErrors(false));
echo $err;
}
echo '
'._MD_AM_BTOTADMIN.' ';
xoops_cp_footer();
break;
case 'previewtpl':
if (!$GLOBALS['xoopsSecurity']->check()) {
redirect_header('admin.php?fct=tplsets', 3, implode(' ', $GLOBALS['xoopsSecurity']->getErrors()));
}
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 = ''.$xoopsConfig['sitename'].' <{$content}>';
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);
$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 ''. _MD_TPLMAIN .' »» '.htmlspecialchars($tplset, ENT_QUOTES).' »» '._MD_EDITTEMPLATE.' ';
$form->display();
xoops_cp_footer();
echo '';
}
break;
case 'update':
if (!$GLOBALS['xoopsSecurity']->check()) {
redirect_header('admin.php?fct=tplsets', 3, implode(' ', $GLOBALS['xoopsSecurity']->getErrors()));
}
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[] = 'Template file '.$upload_file.' does not need to be installed (PHP files using this template file does not exist)';
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[] = 'Failed inserting data for '.$upload_file.' to database';
} else {
$msg[] = 'Template file '.$upload_file.' updated.';
if ($tplset == $xoopsConfig['template_set']) {
include_once XOOPS_ROOT_PATH.'/class/template.php';
if (xoops_template_touch($tpl->getVar('tpl_id'), true)) {
$msg[] = 'Template file '.$upload_file.' compiled.';
}
}
}
}
} else {
if ($uploader->getMediaName() == '') {
continue;
} else {
$msg[] = $uploader->getErrors();
}
}
}
xoops_cp_header();
echo '';
foreach ($msg as $m) {
echo $m.' ';
}
echo '
'._MD_AM_BTOTADMIN.' ';
xoops_cp_footer();
break;
case 'importtpl':
xoops_cp_header();
if (!empty($id)) {
xoops_confirm(array('tplset' => $tplset, 'moddir' => $moddir, 'id' => $id, 'op' => 'importtpl_go', 'fct' => 'tplsets'), 'admin.php', _MD_RUSUREIMPT, _MD_IMPORT);
} elseif (isset($file)) {
xoops_confirm(array('tplset' => $tplset, 'moddir' => $moddir, 'file' => $file, 'op' => 'importtpl_go', 'fct' => 'tplsets'), 'admin.php', _MD_RUSUREIMPT, _MD_IMPORT);
}
xoops_cp_footer();
break;
case 'importtpl_go':
if (!$GLOBALS['xoopsSecurity']->check()) {
redirect_header('admin.php?fct=tplsets', 3, implode(' ', $GLOBALS['xoopsSecurity']->getErrors()));
}
$tpltpl_handler =& xoops_gethandler('tplfile');
$tplfile = '';
if (!empty($id)) {
$tplfile =& $tpltpl_handler->get($id, true);
} else {
$tplfiles =& $tpltpl_handler->find('default', null, null, null, trim($file), true);
$tplfile = (count($tplfiles) > 0) ? $tplfiles[0] : '';
}
$error = true;
if (is_object($tplfile)) {
switch ($tplfile->getVar('tpl_type')) {
case 'module':
$filepath = XOOPS_THEME_PATH.'/'.$tplset.'/templates/'.$tplfile->getVar('tpl_module').'/'.$tplfile->getVar('tpl_file');
break;
case 'block':
$filepath = XOOPS_THEME_PATH.'/'.$tplset.'/templates/'.$tplfile->getVar('tpl_module').'/blocks/'.$tplfile->getVar('tpl_file');
break;
default:
break;
}
if (file_exists($filepath)) {
if (false != $fp = fopen($filepath, 'r')) {
$filesource = fread($fp, filesize($filepath));
fclose($fp);
$tplfile->setVar('tpl_source', $filesource, true);
$tplfile->setVar('tpl_tplset', $tplset);
$tplfile->setVar('tpl_lastmodified', time());
$tplfile->setVar('tpl_lastimported', time());
if (!$tpltpl_handler->insert($tplfile)) {
} else {
$error = false;
}
}
}
}
if (false != $error) {
xoops_cp_header();
xoops_error('Could not import file '.$filepath);
echo ''._MD_AM_BTOTADMIN.' ';
xoops_cp_footer();
exit();
}
redirect_header('admin.php?fct=tplsets&op=listtpl&moddir='.$tplfile->getVar('tpl_module').'&tplset='.urlencode($tplfile->getVar('tpl_tplset')), 2, _MD_AM_DBUPDATED);
break;
default:
break;
}
}
?>