XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
TplfileListAction.class.php
1<?php
7
8if (!defined('XOOPS_ROOT_PATH')) {
9 exit();
10}
11
12require_once XOOPS_MODULE_PATH . '/legacyRender/class/AbstractListAction.class.php';
13require_once XOOPS_MODULE_PATH . '/legacyRender/admin/forms/TplfileFilterForm.class.php';
14require_once XOOPS_MODULE_PATH . '/legacyRender/admin/forms/TplfileSetFilterForm.class.php';
15require_once XOOPS_MODULE_PATH . '/legacyRender/admin/forms/TplfileUploadForm.class.php';
16
18{
23 public $mActionForm = null;
24
25 public function prepare(&$controller, &$xoopsUser, $moduleConfig)
26 {
27 LegacyRender_AbstractListAction::prepare($controller, $xoopsUser, $moduleConfig);
28 $this->mActionForm =new LegacyRender_TplfileUploadForm();
29 $this->mActionForm->prepare();
30 }
31
32 public function &_getHandler()
33 {
34 $handler =& xoops_getmodulehandler('tplfile');
35 return $handler;
36 }
37
38 public function &_getFilterForm()
39 {
40 $filter = isset($_REQUEST['tpl_tplset']) ? new LegacyRender_TplfileSetFilterForm($this->_getPageNavi(), $this->_getHandler())
41 : new LegacyRender_TplfileFilterForm($this->_getPageNavi(), $this->_getHandler());
42 return $filter;
43 }
44
45 public function _getBaseUrl()
46 {
47 return './index.php?action=TplfileList';
48 }
49
50 public function getDefaultView(&$controller, &$xoopsUser)
51 {
52 $this->mFilter =& $this->_getFilterForm();
53 $this->mFilter->fetch();
54
55 $handler =& $this->_getHandler();
56
57 $criteria = $this->mFilter->getCriteria();
58
59 if (isset($_REQUEST['tpl_tplset'])) {
60 $this->mObjects =& $handler->getObjectsWithOverride($criteria, xoops_getrequest('tpl_tplset'));
61 } else {
62 $this->mObjects =& $handler->getObjects($criteria);
63 }
64
65 return LEGACYRENDER_FRAME_VIEW_INDEX;
66 }
67
74 public function execute(&$controller, &$xoopsUser)
75 {
76 require_once XOOPS_ROOT_PATH . '/class/template.php';
77
78 $this->mActionForm->fetch();
79 $this->mActionForm->validate();
80
81 if ($this->mActionForm->hasError()) {
82 return $this->getDefaultView($controller, $xoopsUser);
83 }
84
85 $formFileArr = $this->mActionForm->get('upload');
86
87 //
88 // Set tpl_module and tpl_tplset of the last object to the following variable for redirect.
89 //
90 $last_tplset = null;
91 $last_module = null;
92
93 $handler =& xoops_getmodulehandler('tplfile');
94
95 $successFlag = true;
96
97 foreach (array_keys($formFileArr) as $key) {
98 $formFile =& $formFileArr[$key];
99
100 $obj =& $handler->get($key);
101 if (null == $obj) {
102 continue;
103 }
104
105 //
106 // If $obj belongs to 'default' template-set, kick!
107 //
108 if ($obj->get('tpl_tplset') == 'default') {
109 continue;
110 }
111
112 $obj->loadSource();
113
114 $last_tplset = $obj->get('tpl_tplset');
115 $last_module = $obj->get('tpl_module');
116
117 //
118 // [Warning] Access to a private property of XCube_FormFile.
119 //
120 if (null != $formFile) {
121 $source = file_get_contents($formFile->_mTmpFileName);
122 $obj->Source->set('tpl_source', $source);
123 $obj->set('tpl_lastmodified', time());
124 $obj->set('tpl_lastimported', time());
125
126 $successFlag &= $handler->insert($obj);
127
128 $xoopsTpl =new XoopsTpl();
129 $xoopsTpl->clear_cache('db:' . $obj->get('tpl_file'));
130 $xoopsTpl->clear_compiled_tpl('db:' . $obj->get('tpl_file'));
131 }
132
133 unset($obj);
134 unset($formFile);
135 }
136
137 $errorMessage = $successFlag ? _AD_LEGACYRENDER_MESSAGE_UPLOAD_TEMPLATE_SUCCESS : _AD_LEGACYRENDER_ERROR_DBUPDATE_FAILED;
138
139 //
140 // Not a good example ;)
141 // Because some local variables are used, jump directly without the return value of view status.
142 //
143 $controller->executeRedirect("index.php?action=TplfileList&tpl_tplset={$last_tplset}&tpl_module={$last_module}", 1, $errorMessage);
144 }
145
146 public function executeViewIndex(&$controller, &$xoopsUser, &$render)
147 {
148 $controller->mRoot->mDelegateManager->add('Legacy.Event.Explaceholder.Get.LegacyRenderPagenaviHidden', 'LegacyRender_TplfileListAction::renderHiddenControl');
149
150 $render->setTemplateName('tplfile_list.html');
151
152 //
153 // Load override file.
154 //
155 if ($this->mFilter->mTplset != null && $this->mFilter->mTplset->get('tplset_name') !='default') {
156 foreach (array_keys($this->mObjects) as $key) {
157 $this->mObjects[$key]->loadOverride($this->mFilter->mTplset->get('tplset_name'));
158 }
159 }
160
161 $render->setAttribute('objects', $this->mObjects);
162 $render->setAttribute('pageNavi', $this->mFilter->mNavi);
163 $render->setAttribute('filterForm', $this->mFilter);
164 $render->setAttribute('actionForm', $this->mActionForm);
165
166 if ($this->mFilter->mTplset != null) {
167 $render->setAttribute('targetTplset', $this->mFilter->mTplset->get('tplset_name'));
168 } else {
169 $render->setAttribute('targetTplset', 'default'); // XCL 2.3.x fix Undefined array key "targetTplset" PHP8
170 }
171
172 $render->setAttribute('targetModule', xoops_getrequest('tpl_module'));
173
174 //
175 // TODO We must to fetch only module objects that have templates.
176 //
177 // fetch module objects, assign to template for pull-down menu.
178 //
179 $moduleHandler =& xoops_gethandler('module');
180 $modules =& $moduleHandler->getObjects();
181 $render->setAttribute('modules', $modules);
182
183 $handler =& xoops_getmodulehandler('tplset');
184 $tplsets =& $handler->getObjects();
185 $render->setAttribute('tplsets', $tplsets);
186 }
187
188 public static function renderHiddenControl(&$buf, $params)
189 {
190 if (isset($params['pagenavi']) && is_object($params['pagenavi'])) {
191 $navi =& $params['pagenavi'];
192 // $mask = isset($params['mask']) ? $params['mask'] : null;
193 $mask = $params['mask'] ?? null;
194
195 foreach ($navi->mExtra as $key => $value) {
196 if ($key != $mask) {
197 $value = htmlspecialchars($value, ENT_QUOTES);
198 $buf .= "<input type=\"hidden\" name=\"{$key}\" value=\"{$value}\" />";
199 }
200 }
201 }
202 }
203}