XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
TplsetDownloadAction.class.php
1<?php
6
7if (!defined('XOOPS_ROOT_PATH')) {
8 exit();
9}
10
11require_once XOOPS_MODULE_PATH . '/legacyRender/admin/forms/TplfileEditForm.class.php';
12
14{
15 public $mPreparedFlag = false;
16
17 public $mTplset = null;
18
19 public $mDownloader = null;
20
21 public function &_createDownloader($method)
22 {
23 $ret = null;
24
25 switch ($method) {
26 case 'tar':
27 if (@function_exists('gzencode')) {
28 require_once XOOPS_ROOT_PATH . '/class/tardownloader.php';
29 $ret =new XoopsTarDownloader();
30 }
31 break;
32 case 'zip':
33 if (@function_exists('gzcompress')) {
34 require_once XOOPS_ROOT_PATH . '/class/zipdownloader.php';
35 $ret =new XoopsZipDownloader();
36 }
37 break;
38 }
39
40 return $ret;
41 }
42
43
44 public function getDefaultView(&$controller, &$xoopsUser)
45 {
46 $path = null;
47 $method = 'tar' == xoops_getrequest('method') ? 'tar' : 'zip';
48 $this->mDownloader =& $this->_createDownloader($method);
49
50 if (null == $this->mDownloader) {
51 return LEGACYRENDER_FRAME_VIEW_ERROR;
52 }
53
54 $id = xoops_getrequest('tplset_id');
55
56 $handler =& xoops_getmodulehandler('tplset');
57 $this->mTplset =& $handler->get($id);
58
59 if (null == $this->mTplset) {
60 return LEGACYRENDER_FRAME_VIEW_ERROR;
61 }
62
63 $xml = '<?xml version="1.0"?>'
64 . "\n" . '<tplset>'
65 . "\n" . ' <name>'
66 . $this->mTplset->getShow('tplset_name') . '</name>'
67 . "\n" . ' <dateCreated>'
68 . $this->mTplset->getShow('tplset_created') . '</dateCreated>'
69 . "\n" . ' <credits>'
70 . $this->mTplset->getShow('tplset_credits') . '</credits>'
71 . "\n" . ' <generator>'
72 . XOOPS_VERSION . '</generator>'
73 . "\n";
74
75 $handler =& xoops_getmodulehandler('tplfile');
76 $files =& $handler->getObjects(new Criteria('tpl_tplset', $this->mTplset->get('tplset_name')));
77
78 $count = is_countable($files) ? count($files) : 0;
79
80 if ($count > 0) {
81 $xml .= ' <templates>' . "\n";
82 for ($i = 0; $i < $count; $i++) {
83 $files[$i]->loadSource();
84 if (null != $files[$i]->Source) {
85 $type = null;
86 if ('block' == $files[$i]->get('tpl_type')) {
87 $path = $this->mTplset->getShow('tplset_name') . '/templates/' . $files[$i]->getShow('tpl_module') . '/blocks/' . $files[$i]->getShow('tpl_file');
88 $type = 'block';
89 } elseif ('module' == $files[$i]->get('tpl_type')) {
90 $path = $this->mTplset->getShow('tplset_name') . '/templates/' . $files[$i]->getShow('tpl_module') . '/' . $files[$i]->getShow('tpl_file');
91 $type = 'module';
92 }
93 $xml .= ' <template name="' . $files[$i]->getShow('tpl_file') . '">' . "\n" . ' <module>'
94 . $files[$i]->getShow('tpl_module') . '</module>'
95 . "\n" . ' <type>module</type>'
96 . "\n" . ' <lastModified>'
97 . $files[$i]->getShow('tpl_lastmodified') . '</lastModified>'
98 . "\n" . ' </template>'
99 . "\n";
100
101 $this->mDownloader->addFileData($files[$i]->Source->get('tpl_source'), $path, $files[$i]->getShow('tpl_lastmodified'));
102 }
103 }
104
105 $xml .= ' </templates>' . "\n";
106 }
107
108 $xml .= '</tplset>';
109
110 $this->mDownloader->addFileData($xml, $this->mTplset->getShow('tplset_name') . '/tplset.xml', time());
111
112 return LEGACYRENDER_FRAME_VIEW_SUCCESS;
113 }
114
115 public function executeViewSuccess(&$controller, &$xoopsUser, &$render)
116 {
117 print $this->mDownloader->download($this->mTplset->getShow('tplset_name'), true);
118 exit(0);
119 }
120
121 public function executeViewError(&$controller, &$xoopsUser, &$render)
122 {
123 $controller->executeRedirect('./index.php?action=TplsetList', 1, _AD_LEGACYRENDER_ERROR_DBUPDATE_FAILED);
124 }
125}