|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
You may not change or alter any portion of this comment or credits |
|
5
|
|
|
of supporting developers from this source code or any supporting source code |
|
6
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
7
|
|
|
|
|
8
|
|
|
This program is distributed in the hope that it will be useful, |
|
9
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
11
|
|
|
*/ |
|
12
|
|
|
/** |
|
13
|
|
|
* tdmcreate module. |
|
14
|
|
|
* |
|
15
|
|
|
* @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ |
|
16
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
|
17
|
|
|
* |
|
18
|
|
|
* @since 2.5.0 |
|
19
|
|
|
* |
|
20
|
|
|
* @author Txmod Xoops http://www.txmodxoops.org |
|
21
|
|
|
* |
|
22
|
|
|
* @version $Id: AdminXoopsCode.php 12258 2014-01-02 09:33:29Z timgno $ |
|
23
|
|
|
*/ |
|
24
|
|
|
defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
|
25
|
|
|
/** |
|
26
|
|
|
* Class AdminXoopsCode. |
|
27
|
|
|
*/ |
|
28
|
|
|
class AdminXoopsCode |
|
|
|
|
|
|
29
|
|
|
{ |
|
30
|
|
|
/* |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
private $xoopscode; |
|
34
|
|
|
|
|
35
|
|
|
/* |
|
36
|
|
|
* @public function constructor |
|
37
|
|
|
* @param null |
|
38
|
|
|
*/ |
|
39
|
|
|
/** |
|
40
|
|
|
* |
|
41
|
|
|
*/ |
|
42
|
|
|
public function __construct() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->phpcode = TDMCreatePhpCode::getInstance(); |
|
|
|
|
|
|
45
|
|
|
$this->xoopscode = TDMCreateXoopsCode::getInstance(); |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/* |
|
49
|
|
|
* @static function &getInstance |
|
50
|
|
|
* @param null |
|
51
|
|
|
*/ |
|
52
|
|
|
/** |
|
53
|
|
|
* @return AdminXoopsCode |
|
54
|
|
|
*/ |
|
55
|
|
|
public static function &getInstance() |
|
56
|
|
|
{ |
|
57
|
|
|
static $instance = false; |
|
58
|
|
|
if (!$instance) { |
|
59
|
|
|
$instance = new self(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return $instance; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/* |
|
66
|
|
|
* @public function getAdminTemplateMain |
|
67
|
|
|
* @param $moduleDirname |
|
68
|
|
|
* @param $tableName |
|
69
|
|
|
* |
|
70
|
|
|
* @return string |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getAdminTemplateMain($moduleDirname, $tableName) |
|
73
|
|
|
{ |
|
74
|
|
|
return "\$templateMain = '{$moduleDirname}_admin_{$tableName}.tpl';\n"; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/* |
|
78
|
|
|
* @public function getAdminTemplateMain |
|
79
|
|
|
* @param $language |
|
80
|
|
|
* @param $tableName |
|
81
|
|
|
* @param $stuTableSoleName |
|
82
|
|
|
* @param $type |
|
83
|
|
|
* |
|
84
|
|
|
* @return string |
|
85
|
|
|
*/ |
|
86
|
|
|
public function getAdminItemButton($language, $tableName, $stuTableSoleName, $op = '?op=new', $type = 'add') |
|
87
|
|
|
{ |
|
88
|
|
|
$stuType = strtoupper($type); |
|
89
|
|
|
$adminMenu = '$adminMenu->addItemButton('; |
|
90
|
|
|
if ($type === 'add') { |
|
91
|
|
|
$ret = $adminMenu."{$language}ADD_{$stuTableSoleName}, '{$tableName}.php{$op}', '{$type}');\n"; |
|
92
|
|
|
} else { |
|
93
|
|
|
$ret = $adminMenu."{$language}{$stuTableSoleName}_{$stuType}, '{$tableName}.php{$op}', '{$type}');\n"; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
return $ret; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @public function getAdminAddNavigation |
|
101
|
|
|
* |
|
102
|
|
|
* @param $tableName |
|
103
|
|
|
* |
|
104
|
|
|
* @return string |
|
105
|
|
|
*/ |
|
106
|
|
|
public function getAdminAddNavigation($tableName) |
|
107
|
|
|
{ |
|
108
|
|
|
return "\$adminMenu->addNavigation('{$tableName}.php')"; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/* |
|
112
|
|
|
* @public function getAdminXoopsCodeAddInfoBox |
|
113
|
|
|
* @param $language |
|
114
|
|
|
* |
|
115
|
|
|
* @return string |
|
116
|
|
|
*/ |
|
117
|
|
|
public function getAdminXoopsCodeAddInfoBox($language) |
|
118
|
|
|
{ |
|
119
|
|
|
return "\$adminMenu->addInfoBox({$language});\n"; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/* |
|
123
|
|
|
* @public function getAdminXoopsCodeAddInfoBoxLine |
|
124
|
|
|
* @param $language |
|
125
|
|
|
* @param $label |
|
126
|
|
|
* @param $var |
|
127
|
|
|
* |
|
128
|
|
|
* @return string |
|
129
|
|
|
*/ |
|
130
|
|
View Code Duplication |
public function getAdminXoopsCodeAddInfoBoxLine($language, $label = '', $var = '') |
|
|
|
|
|
|
131
|
|
|
{ |
|
132
|
|
|
$aMenu = '$adminMenu->addInfoBoxLine('; |
|
133
|
|
|
if ($var != '') { |
|
134
|
|
|
$ret = $aMenu."{$language}, '<label>'.{$label}.'</label>', {$var});\n"; |
|
135
|
|
|
} else { |
|
136
|
|
|
$ret = $aMenu."{$language}, '<label>'.{$label}.'</label>');\n"; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
return $ret; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/* |
|
143
|
|
|
* @public function getAdminXoopsCodeAddConfigBoxLine |
|
144
|
|
|
* @param $language |
|
145
|
|
|
* @param $label |
|
146
|
|
|
* @param $var |
|
147
|
|
|
* |
|
148
|
|
|
* @return string |
|
149
|
|
|
*/ |
|
150
|
|
View Code Duplication |
public function getAdminXoopsCodeAddConfigBoxLine($language, $label = '', $var = '') |
|
|
|
|
|
|
151
|
|
|
{ |
|
152
|
|
|
$aMenu = '$adminMenu->addConfigBoxLine('; |
|
153
|
|
|
if ($var != '') { |
|
154
|
|
|
$ret = $aMenu."{$language}, '{$label}', {$var});\n"; |
|
155
|
|
|
} else { |
|
156
|
|
|
$ret = $aMenu."{$language}, '{$label}');\n"; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
return $ret; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/* |
|
163
|
|
|
* @public function getAdminXoopsCodeImageListSetVar |
|
164
|
|
|
* @param string $moduleDirname |
|
165
|
|
|
* @param string $tableName |
|
166
|
|
|
* @param string $fieldName |
|
167
|
|
|
* @return string |
|
168
|
|
|
*/ |
|
169
|
|
|
public function getAdminXoopsCodeImageListSetVar($moduleDirname, $tableName, $fieldName) |
|
170
|
|
|
{ |
|
171
|
|
|
$ret = $this->phpcode->getPhpCodeCommentLine('Set Var', $fieldName); |
|
172
|
|
|
$ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/uploader', true); |
|
173
|
|
|
$ret .= $this->xoopscode->getAdminXoopsCodeMediaUploader('uploader', "XOOPS_ROOT_PATH . '/Frameworks/moduleclasses/icons/32'", $tableName, $moduleDirname); |
|
|
|
|
|
|
174
|
|
|
$fetchMedia = "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])"; |
|
175
|
|
|
$ifelse = "//\$uploader->setPrefix('{$fieldName}_');\n"; |
|
176
|
|
|
$ifelse .= "//\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])\n"; |
|
177
|
|
|
$contentElseInt = "\${$tableName}Obj->setVar('{$fieldName}', \$uploader->getSavedFileName());"; |
|
178
|
|
|
$contentIf = "\$errors = \$uploader->getErrors();\n"; |
|
179
|
|
|
$contentIf .= "redirect_header('javascript:history.go(-1)', 3, \$errors);\n"; |
|
180
|
|
|
$ifelse .= $this->phpcode->getPhpCodeConditions('!$uploader->upload()', '', '', $contentIf, $contentElseInt); |
|
181
|
|
|
$contentElseExt = "\${$tableName}Obj->setVar('{$fieldName}', \$_POST['{$fieldName}']);\n"; |
|
182
|
|
|
|
|
183
|
|
|
$ret .= $this->phpcode->getPhpCodeConditions($fetchMedia, '', '', $ifelse, $contentElseExt); |
|
184
|
|
|
|
|
185
|
|
|
return $ret; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/* |
|
189
|
|
|
* @public function getAdminXoopsCodeUploadImageSetVar |
|
190
|
|
|
* @param string $moduleDirname |
|
191
|
|
|
* @param string $tableName |
|
192
|
|
|
* @param string $fieldName |
|
193
|
|
|
* @return string |
|
194
|
|
|
*/ |
|
195
|
|
|
public function getAdminXoopsCodeUploadImageSetVar($moduleDirname, $tableName, $fieldName, $fieldMain) |
|
196
|
|
|
{ |
|
197
|
|
|
$stuModuleDirname = strtoupper($moduleDirname); |
|
198
|
|
|
$ret = $this->phpcode->getPhpCodeCommentLine('Set Var', $fieldName); |
|
199
|
|
|
$ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/uploader', true); |
|
200
|
|
|
$ret .= $this->getAdminXoopsCodeMediaUploader('uploader', "{$stuModuleDirname}_UPLOAD_IMAGE_PATH", $tableName, $moduleDirname); |
|
|
|
|
|
|
201
|
|
|
|
|
202
|
|
|
$fetchMedia = "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])"; |
|
203
|
|
|
$ifelse = "\$extension = preg_replace( '/^.+\.([^.]+)$/sU' , '' , \$_FILES['attachedfile']['name']);\n"; |
|
204
|
|
|
$ifelse .= "\$imgName = str_replace(' ', '', \$_POST['{$fieldMain}']).'.'.\$extension;\n"; |
|
205
|
|
|
$ifelse .= "\$uploader->setPrefix(\$imgName);\n"; |
|
206
|
|
|
$ifelse .= "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0]);\n"; |
|
207
|
|
|
$contentElseInt = "\${$tableName}Obj->setVar('{$fieldName}', \$uploader->getSavedFileName());"; |
|
208
|
|
|
$contentIf = "\$errors = \$uploader->getErrors();\n"; |
|
209
|
|
|
$contentIf .= "redirect_header('javascript:history.go(-1)', 3, \$errors);\n"; |
|
210
|
|
|
$ifelse .= $this->phpcode->getPhpCodeConditions('!$uploader->upload()', '', '', $contentIf, $contentElseInt); |
|
211
|
|
|
$contentElseExt = "\${$tableName}Obj->setVar('{$fieldName}', \$_POST['{$fieldName}']);\n"; |
|
212
|
|
|
|
|
213
|
|
|
$ret .= $this->phpcode->getPhpCodeConditions($fetchMedia, '', '', $ifelse, $contentElseExt); |
|
214
|
|
|
|
|
215
|
|
|
return $ret; |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/* |
|
219
|
|
|
* @public function getAdminXoopsCodeFileSetVar |
|
220
|
|
|
* @param $moduleDirname |
|
221
|
|
|
* @param $tableName |
|
222
|
|
|
* @param $fieldName |
|
223
|
|
|
* @param $formatUrl |
|
224
|
|
|
* @return string |
|
225
|
|
|
*/ |
|
226
|
|
|
public function getAdminXoopsCodeFileSetVar($moduleDirname, $tableName, $fieldName, $formatUrl = false) |
|
227
|
|
|
{ |
|
228
|
|
|
$stuModuleDirname = strtoupper($moduleDirname); |
|
229
|
|
|
if ($formatUrl) { |
|
230
|
|
|
$ret = $this->getAdminXoopsCodeSetVar($tableName, $fieldName, "formatUrl(\$_REQUEST['{$fieldName}'])"); |
|
|
|
|
|
|
231
|
|
|
$ret .= $this->phpcode->getPhpCodeCommentLine('Set Var', $fieldName); |
|
232
|
|
|
} else { |
|
233
|
|
|
$ret = $this->phpcode->getPhpCodeCommentLine('Set Var', $fieldName); |
|
234
|
|
|
} |
|
235
|
|
|
$ret .= $this->phpcode->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/uploader', true); |
|
236
|
|
|
$ret .= $this->getAdminXoopsCodeMediaUploader('uploader', "{$stuModuleDirname}_UPLOAD_FILES_PATH", $tableName, $moduleDirname); |
|
|
|
|
|
|
237
|
|
|
$fetchMedia = "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])"; |
|
238
|
|
|
if ($formatUrl) { |
|
239
|
|
|
$ifelse = "\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])\n"; |
|
240
|
|
|
} else { |
|
241
|
|
|
$ifelse = "//\$uploader->setPrefix('{$fieldName}_');\n"; |
|
242
|
|
|
$ifelse .= "//\$uploader->fetchMedia(\$_POST['xoops_upload_file'][0])\n"; |
|
243
|
|
|
} |
|
244
|
|
|
$contentElse = "\${$tableName}Obj->setVar('{$fieldName}', \$uploader->getSavedFileName());"; |
|
245
|
|
|
$contentIf = "\$errors = \$uploader->getErrors();\n"; |
|
246
|
|
|
$contentIf .= "redirect_header('javascript:history.go(-1)', 3, \$errors);\n"; |
|
247
|
|
|
$ifelse .= $this->phpcode->getPhpCodeConditions('!$uploader->upload()', '', '', $contentIf, $contentElse); |
|
248
|
|
|
|
|
249
|
|
|
$ret .= $this->phpcode->getPhpCodeConditions($fetchMedia, '', '', $ifelse); |
|
250
|
|
|
|
|
251
|
|
|
return $ret; |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
/** |
|
255
|
|
|
* @public function getAdminXoopsCodeSetVarsObjects |
|
256
|
|
|
* |
|
257
|
|
|
* @param $moduleDirname |
|
258
|
|
|
* @param $tableName |
|
259
|
|
|
* @param $fields |
|
260
|
|
|
* |
|
261
|
|
|
* @return string |
|
262
|
|
|
*/ |
|
263
|
|
|
public function getAdminXoopsCodeSetVarsObjects($moduleDirname, $tableName, $fields) |
|
264
|
|
|
{ |
|
265
|
|
|
$ret = $this->phpcode->getPhpCodeCommentLine($comment = 'Set Vars', $var = ''); |
|
266
|
|
|
foreach (array_keys($fields) as $f) { |
|
267
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
268
|
|
|
$fieldElement = $fields[$f]->getVar('field_element'); |
|
269
|
|
|
if ($f > 0) { // If we want to hide field id |
|
270
|
|
|
switch ($fieldElement) { |
|
271
|
|
|
case 5: |
|
272
|
|
|
case 6: |
|
273
|
|
|
$ret .= $this->xoopscode->getXoopsCodeCheckBoxOrRadioYNSetVar($tableName, $fieldName); |
|
|
|
|
|
|
274
|
|
|
break; |
|
275
|
|
|
case 11: |
|
276
|
|
|
$ret .= $this->xoopscode->getXoopsCodeImageListSetVar($moduleDirname, $tableName, $fieldName); |
|
|
|
|
|
|
277
|
|
|
break; |
|
278
|
|
|
case 12: |
|
279
|
|
|
$ret .= $this->xoopscode->getXoopsCodeUrlFileSetVar($moduleDirname, $tableName, $fieldName); |
|
|
|
|
|
|
280
|
|
|
break; |
|
281
|
|
|
case 13: |
|
282
|
|
|
if (1 == $fields[$f]->getVar('field_main')) { |
|
283
|
|
|
$fieldMain = $fieldName; |
|
284
|
|
|
} |
|
285
|
|
|
$ret .= $this->xoopscode->getXoopsCodeUploadImageSetVar($moduleDirname, $tableName, $fieldName, $fieldMain); |
|
|
|
|
|
|
286
|
|
|
break; |
|
287
|
|
|
case 14: |
|
288
|
|
|
$ret .= $this->xoopscode->getXoopsCodeUploadFileSetVar($moduleDirname, $tableName, $fieldName); |
|
|
|
|
|
|
289
|
|
|
break; |
|
290
|
|
|
case 15: |
|
291
|
|
|
$ret .= $this->xoopscode->getXoopsCodeTextDateSelectSetVar($tableName, $fieldName); |
|
|
|
|
|
|
292
|
|
|
break; |
|
293
|
|
|
default: |
|
294
|
|
|
$ret .= $this->xoopscode->getXoopsCodeSimpleSetVar($tableName, $fieldName); |
|
|
|
|
|
|
295
|
|
|
break; |
|
296
|
|
|
} |
|
297
|
|
|
} |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
return $ret; |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
/** |
|
304
|
|
|
* @public function getAdminXoopsCodeGetObjHandlerId |
|
305
|
|
|
* |
|
306
|
|
|
* @param string $tableName |
|
307
|
|
|
* @param string $fieldId |
|
308
|
|
|
* |
|
309
|
|
|
* @return string |
|
310
|
|
|
*/ |
|
311
|
|
|
public function getAdminXoopsCodeGetObjHandlerId($tableName, $fieldId) |
|
312
|
|
|
{ |
|
313
|
|
|
$ret = <<<EOT |
|
314
|
|
|
\${$tableName}Obj =& \${$tableName}Handler->get(\${$fieldId});\n |
|
315
|
|
|
EOT; |
|
316
|
|
|
|
|
317
|
|
|
return $ret; |
|
318
|
|
|
} |
|
319
|
|
|
} |
|
320
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.