1: <?php
2: 3: 4: 5:
6:
7: if (!defined('XOOPS_ROOT_PATH')) exit();
8:
9: require_once XOOPS_MODULE_PATH . "/legacyRender/class/AbstractListAction.class.php";
10: require_once XOOPS_MODULE_PATH . "/legacyRender/admin/forms/TplfileFilterForm.class.php";
11: require_once XOOPS_MODULE_PATH . "/legacyRender/admin/forms/TplfileSetFilterForm.class.php";
12: require_once XOOPS_MODULE_PATH . "/legacyRender/admin/forms/TplfileUploadForm.class.php";
13:
14: class LegacyRender_TplfileListAction extends LegacyRender_AbstractListAction
15: {
16: 17: 18: 19:
20: var $mActionForm = null;
21:
22: function prepare(&$controller, &$xoopsUser, $moduleConfig)
23: {
24: LegacyRender_AbstractListAction::prepare($controller, $xoopsUser, $moduleConfig);
25: $this->mActionForm =new LegacyRender_TplfileUploadForm();
26: $this->mActionForm->prepare();
27: }
28:
29: function &_getHandler()
30: {
31: $handler =& xoops_getmodulehandler('tplfile');
32: return $handler;
33: }
34:
35: function &_getFilterForm()
36: {
37: $filter = isset($_REQUEST['tpl_tplset']) ? new LegacyRender_TplfileSetFilterForm($this->_getPageNavi(), $this->_getHandler())
38: : new LegacyRender_TplfileFilterForm($this->_getPageNavi(), $this->_getHandler());
39: return $filter;
40: }
41:
42: function _getBaseUrl()
43: {
44: return "./index.php?action=TplfileList";
45: }
46:
47: function getDefaultView(&$controller, &$xoopsUser)
48: {
49: $this->mFilter =& $this->_getFilterForm();
50: $this->mFilter->fetch();
51:
52: $handler =& $this->_getHandler();
53:
54: $criteria = $this->mFilter->getCriteria();
55:
56: if (isset($_REQUEST['tpl_tplset'])) {
57: $this->mObjects =& $handler->getObjectsWithOverride($criteria, xoops_getrequest('tpl_tplset'));
58: }
59: else {
60: $this->mObjects =& $handler->getObjects($criteria);
61: }
62:
63: return LEGACYRENDER_FRAME_VIEW_INDEX;
64: }
65:
66: 67: 68:
69: function execute(&$controller, &$xoopsUser)
70: {
71: require_once XOOPS_ROOT_PATH . "/class/template.php";
72:
73: $this->mActionForm->fetch();
74: $this->mActionForm->validate();
75:
76: if ($this->mActionForm->hasError()) {
77: return $this->getDefaultView($controller, $xoopsUser);
78: }
79:
80: $formFileArr = $this->mActionForm->get('upload');
81:
82:
83:
84:
85: $last_tplset = null;
86: $last_module = null;
87:
88: $handler =& xoops_getmodulehandler('tplfile');
89:
90: $successFlag = true;
91:
92: foreach (array_keys($formFileArr) as $key) {
93: $formFile =& $formFileArr[$key];
94:
95: $obj =& $handler->get($key);
96: if ($obj == null) {
97: continue;
98: }
99:
100:
101:
102:
103: if ($obj->get('tpl_tplset') == 'default') {
104: continue;
105: }
106:
107: $obj->loadSource();
108:
109: $last_tplset = $obj->get('tpl_tplset');
110: $last_module = $obj->get('tpl_module');
111:
112:
113:
114:
115: if ($formFile != null) {
116: $source = file_get_contents($formFile->_mTmpFileName);
117: $obj->Source->set('tpl_source', $source);
118: $obj->set('tpl_lastmodified', time());
119: $obj->set('tpl_lastimported', time());
120:
121: $successFlag &= $handler->insert($obj);
122:
123: $xoopsTpl =new XoopsTpl();
124: $xoopsTpl->clear_cache('db:' . $obj->get('tpl_file'));
125: $xoopsTpl->clear_compiled_tpl('db:' . $obj->get('tpl_file'));
126: }
127:
128: unset($obj);
129: unset($formFile);
130: }
131:
132: $errorMessage = $successFlag ? _AD_LEGACYRENDER_MESSAGE_UPLOAD_TEMPLATE_SUCCESS : _AD_LEGACYRENDER_ERROR_DBUPDATE_FAILED;
133:
134:
135:
136:
137:
138: $controller->executeRedirect("index.php?action=TplfileList&tpl_tplset=${last_tplset}&tpl_module=${last_module}", 1, $errorMessage);
139: }
140:
141: function executeViewIndex(&$controller, &$xoopsUser, &$render)
142: {
143: $controller->mRoot->mDelegateManager->add('Legacy.Event.Explaceholder.Get.LegacyRenderPagenaviHidden', 'LegacyRender_TplfileListAction::renderHiddenControl');
144:
145: $render->setTemplateName("tplfile_list.html");
146:
147:
148:
149:
150: if ($this->mFilter->mTplset != null && $this->mFilter->mTplset->get('tplset_name') != 'default') {
151: foreach (array_keys($this->mObjects) as $key) {
152: $this->mObjects[$key]->loadOverride($this->mFilter->mTplset->get('tplset_name'));
153: }
154: }
155:
156: $render->setAttribute('objects', $this->mObjects);
157: $render->setAttribute('pageNavi', $this->mFilter->mNavi);
158: $render->setAttribute('filterForm', $this->mFilter);
159: $render->setAttribute('actionForm', $this->mActionForm);
160:
161: if ($this->mFilter->mTplset != null) {
162: $render->setAttribute('targetTplset', $this->mFilter->mTplset->get('tplset_name'));
163: }
164:
165: $render->setAttribute('targetModule', xoops_getrequest('tpl_module'));
166:
167:
168:
169:
170:
171:
172: $moduleHandler =& xoops_gethandler('module');
173: $modules =& $moduleHandler->getObjects();
174: $render->setAttribute('modules', $modules);
175:
176: $handler =& xoops_getmodulehandler('tplset');
177: $tplsets =& $handler->getObjects();
178: $render->setAttribute('tplsets', $tplsets);
179: }
180:
181: function renderHiddenControl(&$buf, $params)
182: {
183: if (isset($params['pagenavi']) && is_object($params['pagenavi'])) {
184: $navi =& $params['pagenavi'];
185: $mask = isset($params['mask']) ? $params['mask'] : null;
186:
187: foreach ($navi->mExtra as $key => $value) {
188: if ($key != $mask) {
189: $value = htmlspecialchars($value, ENT_QUOTES);
190: $buf .= "<input type=\"hidden\" name=\"${key}\" value=\"${value}\" />";
191: }
192: }
193: }
194: }
195: }
196:
197: ?>
198: