16 public $mActionForm =
null;
17 public $mErrorMessages = [];
19 public function prepare(&$controller, &$xoopsUser, $moduleConfig)
22 $this->mActionForm->prepare();
25 public function getDefaultView(&$controller, &$xoopsUser)
27 return LEGACYRENDER_FRAME_VIEW_INPUT;
30 public function _addErrorMessage($msg)
32 $this->mErrorMessages[] = $msg;
35 public function execute(&$controller, &$xoopsUser)
37 if (
null != xoops_getrequest(
'_form_control_cancel')) {
38 return LEGACYRENDER_FRAME_VIEW_CANCEL;
41 $this->mActionForm->fetch();
42 $this->mActionForm->validate();
44 if ($this->mActionForm->hasError()) {
45 return $this->getDefaultView($controller, $xoopsUser);
48 require_once XOOPS_ROOT_PATH .
'/class/class.tar.php';
51 $formFile = $this->mActionForm->get(
'upload');
58 $tar->openTar($formFile->_mTmpFileName);
60 if (!is_array($tar->files)) {
61 return LEGACYRENDER_FRAME_VIEW_ERROR;
65 foreach ($tar->files as $id => $info) {
66 $infoArr = explode(
'/', str_replace(
"\\",
'/', $info[
'name']));
67 $tplsetName = $this->mActionForm->get(
'tplset_name');
68 if (
null == $tplsetName) {
69 $tplsetName = trim($infoArr[0]);
72 if (
null != $tplsetName) {
80 if (
null == $tplsetName || preg_match(
'/[' . preg_quote(
'\/:*?"<>|',
'/') .
']/', $tplsetName)) {
81 $this->_addErrorMessage(_AD_LEGACYRENDER_ERROR_TPLSET_NAME_WRONG);
82 return LEGACYRENDER_FRAME_VIEW_ERROR;
85 $handler =& xoops_getmodulehandler(
'tplset');
86 if (0 != $handler->getCount(
new Criteria(
'tplset_name', $tplsetName))) {
88 return LEGACYRENDER_FRAME_VIEW_ERROR;
91 $tplset =& $handler->create();
92 $tplset->set(
'tplset_name', $tplsetName);
93 if (!$handler->insert($tplset)) {
94 $this->_addErrorMessage(_AD_LEGACYRENDER_ERROR_COULD_NOT_SAVE_TPLSET);
95 return LEGACYRENDER_FRAME_VIEW_ERROR;
99 if (!$this->_fetchTemplateFiles($tar, $tplset, $themeimages)) {
100 return LEGACYRENDER_FRAME_VIEW_ERROR;
103 if (!$this->_fetchImageset($tar, $tplset, $themeimages)) {
104 return LEGACYRENDER_FRAME_VIEW_ERROR;
107 return LEGACYRENDER_FRAME_VIEW_SUCCESS;
110 public function _fetchTemplateFiles(&$tar, &$tplset, &$themeimages)
112 $handler =& xoops_getmodulehandler(
'tplfile');
113 foreach ($tar->files as $id => $info) {
114 $infoArr = explode(
'/', str_replace(
"\\",
'/', $info[
'name']));
115 if (isset($infoArr[3]) &&
'blocks' == trim($infoArr[3])) {
116 $default =& $handler->find(
'default',
'block',
null, trim($infoArr[2]), trim($infoArr[4]));
117 } elseif ((!isset($infoArr[4]) ||
'' == trim($infoArr[4])) &&
'templates' == $infoArr[1]) {
118 $default =& $handler->find(
'default',
'module',
null, trim($infoArr[2]), trim($infoArr[3]));
119 } elseif (isset($infoArr[3]) &&
'images' == trim($infoArr[3])) {
120 $infoArr[2] = trim($infoArr[2]);
121 if (preg_match(
"/(.*)\.(gif|jpg|jpeg|png)$/i", $infoArr[2], $match)) {
122 $themeimages[] = [
'name' => $infoArr[2],
'content' => $info[
'file']];
125 if ((is_countable($default) ? count($default) : 0) > 0) {
126 $tplfile =& $default[0]->createClone($tplset->get(
'tplset_name'));
127 $tplfile->Source->set(
'tpl_source', $info[
'file']);
128 $tplfile->set(
'tpl_lastimported', time());
130 if (!$handler->insert($tplfile)) {
131 $this->_addErrorMessage(
XCube_Utils::formatString(_AD_LEGACYRENDER_ERROR_COULD_NOT_SAVE_TPLFILE, $tplfile->get(
'tpl_file')));
141 public function _fetchImageset(&$tar, &$tplset, &$themeimages)
143 if (0 == (is_countable($themeimages) ? count($themeimages) : 0)) {
147 $handler =& xoops_gethandler(
'imageset');
148 $imgset =& $handler->create();
149 $imgset->set(
'imgset_name', $tplset->get(
'tplset_name'));
150 $imgset->set(
'imgset_refid', 0);
152 if (!$handler->insert($imgset)) {
153 $this->_addErrorMessage(
XCube_Utils::formatString(_AD_LEGACYRENDER_ERROR_COULD_NOT_SAVE_IMAGESET, $tplset->get(
'tplset_name')));
157 if (!$handler->linktplset($imgset->get(
'imgset_id'), $tplset->get(
'tplset_name'))) {
158 $this->_addErrorMessage(_AD_LEGACYRENDER_ERROR_COULD_NOT_SAVE_LINKTPLSET);
162 $handler =& xoops_gethandler(
'imagesetimg');
163 for ($i = 0; $i < (is_countable($themeimages) ? count($themeimages) : 0); $i++) {
164 if (isset($themeimages[$i][
'name']) &&
'' != $themeimages[$i][
'name']) {
165 $image =& $handler->create();
166 $image->set(
'imgsetimg_file', $themeimages[$i][
'name']);
167 $image->set(
'imgsetimg_imgset', $imgset->get(
'imgset_id'));
168 $image->set(
'imgsetimg_body', $themeimages[$i][
'content'],
true);
169 if (!$handler->insert($image)) {
170 $this->_addErrorMessage(
XCube_Utils::formatString(_AD_LEGACYRENDER_ERROR_COULD_NOT_SAVE_IMAGE_FILE, $image->get(
'imgsetimg_file')));
179 public function executeViewInput(&$controller, &$xoopsUser, &$render)
181 $render->setTemplateName(
'tplset_upload.html');
182 $render->setAttribute(
'actionForm', $this->mActionForm);
185 public function executeViewSuccess(&$controller, &$xoopsUser, &$render)
187 $controller->executeForward(
'./index.php?action=TplsetList');
190 public function executeViewError(&$controller, &$xoopsUser, &$render)
192 if (0 == count($this->mErrorMessages)) {
193 $controller->executeRedirect(
'./index.php?action=TplsetList', 1, _AD_LEGACYRENDER_ERROR_DBUPDATE_FAILED);
195 $render->setTemplateName(
'tplset_upload_error.html');
196 $render->setAttribute(
'errorMessages', $this->mErrorMessages);
200 public function executeViewCancel(&$controller, &$xoopsUser, &$render)
202 $controller->executeForward(
'./index.php?action=TplsetList');