|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Modulebuilder\Files\Classes; |
|
4
|
|
|
|
|
5
|
|
|
use XoopsModules\Modulebuilder; |
|
6
|
|
|
use XoopsModules\Modulebuilder\Files; |
|
7
|
|
|
|
|
8
|
|
|
/* |
|
9
|
|
|
You may not change or alter any portion of this comment or credits |
|
10
|
|
|
of supporting developers from this source code or any supporting source code |
|
11
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
12
|
|
|
|
|
13
|
|
|
This program is distributed in the hope that it will be useful, |
|
14
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
16
|
|
|
*/ |
|
17
|
|
|
/** |
|
18
|
|
|
* tc module. |
|
19
|
|
|
* |
|
20
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
|
21
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
|
22
|
|
|
* |
|
23
|
|
|
* @since 2.5.0 |
|
24
|
|
|
* |
|
25
|
|
|
* @author Txmod Xoops http://www.txmodxoops.org |
|
26
|
|
|
* |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Class ClassSpecialFiles. |
|
31
|
|
|
*/ |
|
32
|
|
|
class ClassSpecialFiles extends Files\CreateFile |
|
33
|
|
|
{ |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* "className" attribute of the files. |
|
37
|
|
|
* |
|
38
|
|
|
* @var mixed |
|
39
|
|
|
*/ |
|
40
|
|
|
public $className = null; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var mixed |
|
44
|
|
|
*/ |
|
45
|
|
|
private $xc = null; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var mixed |
|
49
|
|
|
*/ |
|
50
|
|
|
private $pc = null; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @public function constructor |
|
54
|
|
|
* @param null |
|
55
|
|
|
*/ |
|
56
|
|
|
public function __construct() |
|
57
|
|
|
{ |
|
58
|
|
|
parent::__construct(); |
|
59
|
|
|
$this->xc = Modulebuilder\Files\CreateXoopsCode::getInstance(); |
|
60
|
|
|
$this->pc = Modulebuilder\Files\CreatePhpCode::getInstance(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @static function getInstance |
|
65
|
|
|
* |
|
66
|
|
|
* @return bool|ClassSpecialFiles |
|
67
|
|
|
*/ |
|
68
|
|
|
public static function getInstance() |
|
69
|
|
|
{ |
|
70
|
|
|
static $instance = false; |
|
71
|
|
|
if (!$instance) { |
|
72
|
|
|
$instance = new self(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return $instance; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @public function write |
|
80
|
|
|
* |
|
81
|
|
|
* @param string $module |
|
82
|
|
|
* @param string $table |
|
83
|
|
|
* @param mixed $tables |
|
84
|
|
|
* @param $filename |
|
85
|
|
|
*/ |
|
86
|
|
|
public function write($module, $table, $tables, $filename) |
|
87
|
|
|
{ |
|
88
|
|
|
$this->setModule($module); |
|
89
|
|
|
$this->setTable($table); |
|
90
|
|
|
$this->setTables($tables); |
|
91
|
|
|
$this->setFileName($filename); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @public function render |
|
96
|
|
|
* @param null |
|
97
|
|
|
* |
|
98
|
|
|
* @return bool|string |
|
99
|
|
|
*/ |
|
100
|
|
|
public function renderClass() |
|
101
|
|
|
{ |
|
102
|
|
|
$module = $this->getModule(); |
|
103
|
|
|
$filename = $this->getFileName(); |
|
104
|
|
|
$moduleDirname = $module->getVar('mod_dirname'); |
|
105
|
|
|
$namespace = $this->pc->getPhpCodeNamespace(['XoopsModules', $moduleDirname]); |
|
106
|
|
|
$content = $this->getHeaderFilesComments($module, null, $namespace); |
|
107
|
|
|
$content .= $this->pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname]); |
|
108
|
|
|
$content .= $this->pc->getPhpCodeDefined(); |
|
109
|
|
|
$content .= $this->pc->getPhpCodeCommentMultiLine(['Class Object' => $this->className]); |
|
110
|
|
|
$cCl = $this->pc->getPhpCodeCommentMultiLine(['Constructor' => '', '' => '', '@param' => 'null'], "\t"); |
|
111
|
|
|
$constr = ''; |
|
112
|
|
|
$cCl .= $this->pc->getPhpCodeFunction('__construct', '', $constr, 'public ', false, "\t"); |
|
113
|
|
|
$arrGetInstance = ['@static function' => '&getInstance', '' => '', '@param' => 'null']; |
|
114
|
|
|
$cCl .= $this->pc->getPhpCodeCommentMultiLine($arrGetInstance, "\t"); |
|
115
|
|
|
$getInstance = $this->pc->getPhpCodeVariableClass('static', 'instance', 'false', "\t\t"); |
|
116
|
|
|
$instance = $this->xc->getXcEqualsOperator('$instance', 'new self()', null, "\t\t\t"); |
|
117
|
|
|
$getInstance .= $this->pc->getPhpCodeConditions('!$instance', '', '', $instance, false, "\t\t"); |
|
118
|
|
|
$cCl .= $this->pc->getPhpCodeFunction('getInstance', '', $getInstance, 'public static ', false, "\t"); |
|
119
|
|
|
$content .= $this->pc->getPhpCodeClass($this->className, $cCl, '\XoopsObject'); |
|
120
|
|
|
|
|
121
|
|
|
$this->create($moduleDirname, 'class', $filename, $content, _AM_MODULEBUILDER_FILE_CREATED, _AM_MODULEBUILDER_FILE_NOTCREATED); |
|
122
|
|
|
|
|
123
|
|
|
return $this->renderFile(); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @public function getGlobalPerms |
|
128
|
|
|
* @param null |
|
129
|
|
|
* |
|
130
|
|
|
* @return bool|string |
|
131
|
|
|
*/ |
|
132
|
|
|
public function getGlobalPerms($permId) |
|
133
|
|
|
{ |
|
134
|
|
|
$module = $this->getModule(); |
|
135
|
|
|
$moduleDirname = $module->getVar('mod_dirname'); |
|
136
|
|
|
|
|
137
|
|
|
$returnTrue = $this->getSimpleString("return true;", "\t\t\t"); |
|
138
|
|
|
$right = ''; |
|
139
|
|
|
$cond = ''; |
|
140
|
|
|
$funcname = ''; |
|
141
|
|
|
$comment = ''; |
|
142
|
|
|
switch ($permId) { |
|
143
|
|
|
case 4: |
|
144
|
|
|
$comment .= $this->pc->getPhpCodeCommentMultiLine(['@public' => 'function permGlobalApprove', 'returns' => 'right for global approve', '' => '', '@param' => 'null', '@return' => 'bool'], "\t"); |
|
145
|
|
|
$right .= $this->xc->getXcCheckRight('$grouppermHandler', $moduleDirname . '_ac', 4, '$my_group_ids', '$mid', true, "\t\t\t"); |
|
146
|
|
|
$cond .= $this->pc->getPhpCodeConditions($right, '', '', $returnTrue, false, "\t\t"); |
|
147
|
|
|
$funcname .= 'getPermGlobalApprove'; |
|
148
|
|
|
break; |
|
149
|
|
|
case 8: |
|
150
|
|
|
$comment .= $this->pc->getPhpCodeCommentMultiLine(['@public' => 'function permGlobalSubmit', 'returns' => 'right for global submit', '' => '', '@param' => 'null', '@return' => 'bool'], "\t"); |
|
151
|
|
|
$cond .= $this->pc->getPhpCodeConditions('$this->getGlobalApprove()', '', '', $returnTrue, false, "\t\t"); |
|
152
|
|
|
$right .= $this->xc->getXcCheckRight('$grouppermHandler', $moduleDirname . '_ac', 8, '$my_group_ids', '$mid', true, "\t\t\t"); |
|
153
|
|
|
$cond .= $this->pc->getPhpCodeConditions($right, '', '', $returnTrue, false, "\t\t"); |
|
154
|
|
|
$funcname .= 'getPermGlobalSubmit'; |
|
155
|
|
|
break; |
|
156
|
|
|
case 16: |
|
157
|
|
|
$comment .= $this->pc->getPhpCodeCommentMultiLine(['@public' => 'function permGlobalView', 'returns' => 'right for global view', '' => '', '@param' => 'null', '@return' => 'bool'], "\t"); |
|
158
|
|
|
$cond .= $this->pc->getPhpCodeConditions('$this->getGlobalApprove()', '', '', $returnTrue, false, "\t\t"); |
|
159
|
|
|
$cond .= $this->pc->getPhpCodeConditions('$this->getGlobalSubmit()', '', '', $returnTrue, false, "\t\t"); |
|
160
|
|
|
$right .= $this->xc->getXcCheckRight('$grouppermHandler', $moduleDirname . '_ac', 16, '$my_group_ids', '$mid', true, "\t\t\t"); |
|
161
|
|
|
$cond .= $this->pc->getPhpCodeConditions($right, '', '', $returnTrue, false, "\t\t"); |
|
162
|
|
|
$funcname .= 'getPermGlobalView'; |
|
163
|
|
|
break; |
|
164
|
|
|
case 0: |
|
165
|
|
|
default: |
|
166
|
|
|
break; |
|
167
|
|
|
} |
|
168
|
|
|
$functions = $comment; |
|
169
|
|
|
$globalContent = $this->xc->getXcGetGlobal(['xoopsUser', 'xoopsModule'], "\t\t"); |
|
170
|
|
|
$globalContent .= $this->xc->getXcEqualsOperator('$currentuid', '0', null, "\t\t"); |
|
171
|
|
|
|
|
172
|
|
|
$contIf = $this->pc->getPhpCodeConditions("\$xoopsUser->isAdmin(\$xoopsModule->mid())", '', '', "\t" . $returnTrue, false, "\t\t\t"); |
|
173
|
|
|
$contIf .= $this->xc->getXcEqualsOperator('$currentuid', '$xoopsUser->uid()', null, "\t\t\t"); |
|
174
|
|
|
$globalContent .= $this->pc->getPhpCodeConditions('isset($xoopsUser)', ' && ', 'is_object($xoopsUser)', $contIf, false, "\t\t"); |
|
175
|
|
|
$globalContent .= $this->xc->getXcXoopsHandler('groupperm', "\t\t"); |
|
176
|
|
|
$globalContent .= $this->xc->getXcEqualsOperator('$mid', '$xoopsModule->mid()', null, "\t\t"); |
|
177
|
|
|
$globalContent .= $this->xc->getXcXoopsHandler('member', "\t\t"); |
|
178
|
|
|
|
|
179
|
|
|
$contIfInt = $this->xc->getXcEqualsOperator('$my_group_ids', '[XOOPS_GROUP_ANONYMOUS]', null, "\t\t\t"); |
|
180
|
|
|
$contElseInt = $this->xc->getXcEqualsOperator('$my_group_ids', '$memberHandler->getGroupsByUser($currentuid);', null, "\t\t\t"); |
|
181
|
|
|
$globalContent .= $this->pc->getPhpCodeConditions('$currentuid', ' == ', '0', $contIfInt, $contElseInt, "\t\t"); |
|
182
|
|
|
$globalContent .= $cond; |
|
183
|
|
|
$globalContent .= $this->getSimpleString("return false;", "\t\t"); |
|
184
|
|
|
$functions .= $this->pc->getPhpCodeFunction($funcname, '', $globalContent, 'public ', false, "\t"); |
|
185
|
|
|
|
|
186
|
|
|
return $functions; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* @public function renderPermissionsHandler |
|
191
|
|
|
* @param null |
|
192
|
|
|
* |
|
193
|
|
|
* @return bool|string |
|
194
|
|
|
*/ |
|
195
|
|
|
public function renderPermissionsHandler() |
|
196
|
|
|
{ |
|
197
|
|
|
$module = $this->getModule(); |
|
198
|
|
|
$filename = $this->getFileName(); |
|
199
|
|
|
$moduleDirname = $module->getVar('mod_dirname'); |
|
200
|
|
|
$namespace = $this->pc->getPhpCodeNamespace(['XoopsModules', $moduleDirname]); |
|
201
|
|
|
$content = $this->getHeaderFilesComments($module, null, $namespace); |
|
202
|
|
|
$content .= $this->pc->getPhpCodeUseNamespace(['XoopsModules', $moduleDirname]); |
|
203
|
|
|
$content .= $this->pc->getPhpCodeDefined(); |
|
204
|
|
|
$content .= $this->pc->getPhpCodeCommentMultiLine(['Class Object' => $this->className]); |
|
205
|
|
|
|
|
206
|
|
|
$constr = $this->pc->getPhpCodeCommentMultiLine(['Constructor' => '', '' => '', '@param' => 'null'], "\t"); |
|
207
|
|
|
$constr .= $this->pc->getPhpCodeFunction('__construct', '', '', 'public ', false, "\t"); |
|
208
|
|
|
$functions = $constr; |
|
209
|
|
|
$functions .= $this->getGlobalPerms(4); |
|
210
|
|
|
$functions .= $this->getGlobalPerms(8); |
|
211
|
|
|
$functions .= $this->getGlobalPerms(16); |
|
212
|
|
|
|
|
213
|
|
|
$content .= $this->pc->getPhpCodeClass($this->className, $functions, '\XoopsPersistableObjectHandler'); |
|
214
|
|
|
$this->create($moduleDirname, 'class', $filename, $content, _AM_MODULEBUILDER_FILE_CREATED, _AM_MODULEBUILDER_FILE_NOTCREATED); |
|
215
|
|
|
|
|
216
|
|
|
return $this->renderFile(); |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* @public function renderConstantsInterface |
|
221
|
|
|
* @param null |
|
222
|
|
|
* |
|
223
|
|
|
* @return bool|string |
|
224
|
|
|
*/ |
|
225
|
|
|
public function renderConstantsInterface() |
|
226
|
|
|
{ |
|
227
|
|
|
$module = $this->getModule(); |
|
228
|
|
|
$filename = $this->getFileName(); |
|
229
|
|
|
$tables = $this->getTables(); |
|
230
|
|
|
$tablePermissions = []; |
|
231
|
|
|
$tableRate = []; |
|
232
|
|
|
foreach (array_keys($tables) as $t) { |
|
233
|
|
|
$tablePermissions[] = $tables[$t]->getVar('table_permissions'); |
|
234
|
|
|
$tableRate[] = $tables[$t]->getVar('table_rate'); |
|
235
|
|
|
} |
|
236
|
|
|
$moduleDirname = $module->getVar('mod_dirname'); |
|
237
|
|
|
$namespace = $this->pc->getPhpCodeNamespace(['XoopsModules', $moduleDirname]); |
|
238
|
|
|
$contentFile = $this->getHeaderFilesComments($module, null, $namespace); |
|
239
|
|
|
$contentFile .= $this->pc->getPhpCodeCommentMultiLine(['Interface ' => $this->className]); |
|
240
|
|
|
|
|
241
|
|
|
$contentClass = $this->pc->getPhpCodeBlankLine(); |
|
242
|
|
|
$contentClass .= $this->pc->getPhpCodeCommentLine('Constants for tables', '', "\t"); |
|
243
|
|
|
foreach (array_keys($tables) as $t) { |
|
244
|
|
|
$tablePermissions[] = $tables[$t]->getVar('table_permissions'); |
|
245
|
|
|
$stuTableName = mb_strtoupper($tables[$t]->getVar('table_name')); |
|
246
|
|
|
$contentClass .= $this->pc->getPhpCodeConstant("TABLE_" . $stuTableName, $t, "\t",'const'); |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
$contentClass .= $this->pc->getPhpCodeBlankLine(); |
|
250
|
|
|
$contentClass .= $this->pc->getPhpCodeCommentLine('Constants for status', '', "\t"); |
|
251
|
|
|
$contentClass .= $this->pc->getPhpCodeConstant("STATUS_NONE ", 0, "\t",'const'); |
|
252
|
|
|
$contentClass .= $this->pc->getPhpCodeConstant("STATUS_OFFLINE ", 1, "\t",'const'); |
|
253
|
|
|
$contentClass .= $this->pc->getPhpCodeConstant("STATUS_SUBMITTED", 2, "\t",'const'); |
|
254
|
|
|
$contentClass .= $this->pc->getPhpCodeConstant("STATUS_APPROVED ", 3, "\t",'const'); |
|
255
|
|
|
$contentClass .= $this->pc->getPhpCodeConstant("STATUS_BROKEN ", 4, "\t",'const'); |
|
256
|
|
|
if (in_array(1, $tablePermissions)) { |
|
257
|
|
|
$constPerm = $this->pc->getPhpCodeBlankLine(); |
|
258
|
|
|
$constPerm .= $this->pc->getPhpCodeCommentLine('Constants for permissions', '', "\t"); |
|
259
|
|
|
$constPerm .= $this->pc->getPhpCodeConstant("PERM_GLOBAL_NONE ", 0, "\t",'const'); |
|
260
|
|
|
$constPerm .= $this->pc->getPhpCodeConstant("PERM_GLOBAL_VIEW ", 1, "\t", 'const'); |
|
261
|
|
|
$constPerm .= $this->pc->getPhpCodeConstant("PERM_GLOBAL_SUBMIT ", 2, "\t", 'const'); |
|
262
|
|
|
$constPerm .= $this->pc->getPhpCodeConstant("PERM_GLOBAL_APPROVE", 3, "\t", 'const'); |
|
263
|
|
|
$contentClass .= $constPerm; |
|
264
|
|
|
} |
|
265
|
|
|
if (in_array(1, $tableRate)) { |
|
266
|
|
|
$constRate = $this->pc->getPhpCodeBlankLine(); |
|
267
|
|
|
$constRate .= $this->pc->getPhpCodeCommentLine('Constants for rating', '', "\t"); |
|
268
|
|
|
$constRate .= $this->pc->getPhpCodeConstant("RATING_NONE ", 0, "\t",'const'); |
|
269
|
|
|
$constRate .= $this->pc->getPhpCodeConstant("RATING_5STARS ", 1, "\t", 'const'); |
|
270
|
|
|
$constRate .= $this->pc->getPhpCodeConstant("RATING_10STARS ", 2, "\t", 'const'); |
|
271
|
|
|
$constRate .= $this->pc->getPhpCodeConstant("RATING_LIKES ", 3, "\t", 'const'); |
|
272
|
|
|
$constRate .= $this->pc->getPhpCodeConstant("RATING_10NUM ", 4, "\t", 'const'); |
|
273
|
|
|
$contentClass .= $constRate; |
|
274
|
|
|
} |
|
275
|
|
|
$contentClass .= $this->pc->getPhpCodeBlankLine(); |
|
276
|
|
|
|
|
277
|
|
|
$contentFile .= $this->pc->getPhpCodeInterface($this->className, $contentClass); |
|
278
|
|
|
|
|
279
|
|
|
$this->create($moduleDirname, 'class', $filename, $contentFile, _AM_MODULEBUILDER_FILE_CREATED, _AM_MODULEBUILDER_FILE_NOTCREATED); |
|
280
|
|
|
|
|
281
|
|
|
return $this->renderFile(); |
|
282
|
|
|
} |
|
283
|
|
|
} |
|
284
|
|
|
|