|
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: TDMCreateFile.php 12258 2014-01-02 09:33:29Z timgno $ |
|
23
|
|
|
*/ |
|
24
|
|
|
defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
|
25
|
|
|
|
|
26
|
|
|
xoops_load('XoopsFile'); |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Class TDMCreateFile. |
|
30
|
|
|
*/ |
|
31
|
|
|
class TDMCreateFile extends TDMCreateTableFields |
|
|
|
|
|
|
32
|
|
|
{ |
|
33
|
|
|
/* |
|
34
|
|
|
* @var string |
|
35
|
|
|
*/ |
|
36
|
|
|
private $xoopsFile; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* "fileName" attribute of the files. |
|
40
|
|
|
* |
|
41
|
|
|
* @var mixed |
|
42
|
|
|
*/ |
|
43
|
|
|
private $fileName = null; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* "subdir" attribute of the directories. |
|
47
|
|
|
* |
|
48
|
|
|
* @var string |
|
49
|
|
|
*/ |
|
50
|
|
|
private $subdir = null; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* "uploadPath" attribute of the files. |
|
54
|
|
|
* |
|
55
|
|
|
* @var string |
|
56
|
|
|
*/ |
|
57
|
|
|
private $uploadPath; |
|
58
|
|
|
|
|
59
|
|
|
/* |
|
60
|
|
|
* @var string |
|
61
|
|
|
*/ |
|
62
|
|
|
private $content = null; |
|
63
|
|
|
|
|
64
|
|
|
/* |
|
65
|
|
|
* @var mixed |
|
66
|
|
|
*/ |
|
67
|
|
|
private $created = null; |
|
68
|
|
|
|
|
69
|
|
|
/* |
|
70
|
|
|
* @var mixed |
|
71
|
|
|
*/ |
|
72
|
|
|
private $notCreated = null; |
|
73
|
|
|
|
|
74
|
|
|
/* |
|
75
|
|
|
* @var string |
|
76
|
|
|
*/ |
|
77
|
|
|
private $mode = null; |
|
78
|
|
|
|
|
79
|
|
|
/* |
|
80
|
|
|
* @var string |
|
81
|
|
|
*/ |
|
82
|
|
|
protected $tdmcreate; |
|
83
|
|
|
|
|
84
|
|
|
/* |
|
85
|
|
|
* @public function constructor |
|
86
|
|
|
* @param null |
|
87
|
|
|
*/ |
|
88
|
|
|
/** |
|
89
|
|
|
* |
|
90
|
|
|
*/ |
|
91
|
|
|
public function __construct() |
|
92
|
|
|
{ |
|
93
|
|
|
parent::__construct(); |
|
94
|
|
|
$this->xoopsFile = XoopsFile::getHandler(); |
|
95
|
|
|
$this->tdmcreate = TDMCreateHelper::getInstance(); |
|
|
|
|
|
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/* |
|
99
|
|
|
* @public static function &getInstance |
|
100
|
|
|
* @param null |
|
101
|
|
|
*/ |
|
102
|
|
|
/** |
|
103
|
|
|
* @return TDMCreateFile |
|
104
|
|
|
*/ |
|
105
|
|
|
public static function &getInstance() |
|
106
|
|
|
{ |
|
107
|
|
|
static $instance = false; |
|
108
|
|
|
if (!$instance) { |
|
109
|
|
|
$instance = new self(); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
return $instance; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @public function create |
|
117
|
|
|
* |
|
118
|
|
|
* @param $moduleDirname |
|
119
|
|
|
* @param $subdir |
|
120
|
|
|
* @param $fileName |
|
121
|
|
|
* @param $content |
|
122
|
|
|
* @param $created |
|
123
|
|
|
* @param $notCreated |
|
124
|
|
|
* @param $mode |
|
125
|
|
|
*/ |
|
126
|
|
|
public function create($moduleDirname, $subdir = null, $fileName = null, $content = '', $created = null, $notCreated = null, $mode = 'w+') |
|
127
|
|
|
{ |
|
128
|
|
|
$this->setFileName($fileName); |
|
129
|
|
|
$this->created = $created; |
|
130
|
|
|
$this->notCreated = $notCreated; |
|
131
|
|
|
$this->setMode($mode); |
|
132
|
|
|
$this->setRepositoryPath($moduleDirname); |
|
133
|
|
|
if (!empty($content) && is_string($content)) { |
|
134
|
|
|
$this->setContent($content); |
|
135
|
|
|
} |
|
136
|
|
|
if (isset($subdir) && is_string($subdir)) { |
|
137
|
|
|
$this->setSubDir($subdir); |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/* |
|
142
|
|
|
* @public function write |
|
143
|
|
|
* @param string $module |
|
144
|
|
|
* @param string $fileName |
|
145
|
|
|
*/ |
|
146
|
|
|
/** |
|
147
|
|
|
* @param $module |
|
148
|
|
|
* @param $fileName |
|
149
|
|
|
*/ |
|
150
|
|
|
public function write($module, $fileName) |
|
151
|
|
|
{ |
|
152
|
|
|
$this->setModule($module); |
|
153
|
|
|
$this->setFileName($fileName); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/* |
|
157
|
|
|
* @private function setRepositoryPath |
|
158
|
|
|
* @param string $moduleDirname |
|
159
|
|
|
*/ |
|
160
|
|
|
/** |
|
161
|
|
|
* @param $moduleDirname |
|
162
|
|
|
*/ |
|
163
|
|
|
private function setRepositoryPath($moduleDirname) |
|
164
|
|
|
{ |
|
165
|
|
|
$this->uploadPath = TDMC_UPLOAD_REPOSITORY_PATH.'/'.$moduleDirname; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/* |
|
169
|
|
|
* @private function getRepositoryPath |
|
170
|
|
|
* @param null |
|
171
|
|
|
*/ |
|
172
|
|
|
/** |
|
173
|
|
|
* @return string |
|
174
|
|
|
*/ |
|
175
|
|
|
private function getRepositoryPath() |
|
176
|
|
|
{ |
|
177
|
|
|
return $this->uploadPath; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/* |
|
181
|
|
|
* @private function setSubDir |
|
182
|
|
|
* @param string $subdir |
|
183
|
|
|
*/ |
|
184
|
|
|
/** |
|
185
|
|
|
* @param $subdir |
|
186
|
|
|
*/ |
|
187
|
|
|
private function setSubDir($subdir) |
|
188
|
|
|
{ |
|
189
|
|
|
$this->subdir = $subdir; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/* |
|
193
|
|
|
* @private function getSubDir |
|
194
|
|
|
* @param null |
|
195
|
|
|
*/ |
|
196
|
|
|
private function getSubDir() |
|
197
|
|
|
{ |
|
198
|
|
|
return $this->subdir; |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
/** |
|
202
|
|
|
* public function setFileName. |
|
203
|
|
|
* |
|
204
|
|
|
* @param $fileName |
|
205
|
|
|
* |
|
206
|
|
|
* @internal param mixed $file_name |
|
207
|
|
|
*/ |
|
208
|
|
|
public function setFileName($fileName) |
|
209
|
|
|
{ |
|
210
|
|
|
$this->fileName = $fileName; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/* |
|
214
|
|
|
* @public function getFileName |
|
215
|
|
|
* @param null |
|
216
|
|
|
*/ |
|
217
|
|
|
/** |
|
218
|
|
|
* @return mixed |
|
219
|
|
|
*/ |
|
220
|
|
|
public function getFileName() |
|
221
|
|
|
{ |
|
222
|
|
|
return $this->fileName; |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
/* |
|
226
|
|
|
* @private function setContent |
|
227
|
|
|
* @param string $content |
|
228
|
|
|
*/ |
|
229
|
|
|
/** |
|
230
|
|
|
* @param $content |
|
231
|
|
|
*/ |
|
232
|
|
|
private function setContent($content) |
|
233
|
|
|
{ |
|
234
|
|
|
$this->content = $content; |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
/* |
|
238
|
|
|
* @private function setContent |
|
239
|
|
|
* @param null |
|
240
|
|
|
*/ |
|
241
|
|
|
/** |
|
242
|
|
|
*/ |
|
243
|
|
|
private function getContent() |
|
244
|
|
|
{ |
|
245
|
|
|
return $this->content; |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
/* |
|
249
|
|
|
* @private function getFolderName |
|
250
|
|
|
* @param null |
|
251
|
|
|
*/ |
|
252
|
|
|
/** |
|
253
|
|
|
* @return string |
|
254
|
|
|
*/ |
|
255
|
|
|
private function getFolderName() |
|
256
|
|
|
{ |
|
257
|
|
|
$path = $this->getUploadPath(); |
|
258
|
|
|
if (strrpos($path, '\\')) { |
|
259
|
|
|
$str = strrpos($path, '\\'); |
|
260
|
|
|
if ($str !== false) { |
|
261
|
|
|
return substr($path, $str + 1, strlen($path)); |
|
262
|
|
|
} else { |
|
263
|
|
|
return substr($path, $str, strlen($path)); |
|
264
|
|
|
} |
|
265
|
|
|
} |
|
266
|
|
|
//return 'root module'; |
|
267
|
|
|
return; |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
/* |
|
271
|
|
|
* @public function getUploadPath |
|
272
|
|
|
* @param null |
|
273
|
|
|
*/ |
|
274
|
|
|
/** |
|
275
|
|
|
* @return string |
|
276
|
|
|
*/ |
|
277
|
|
|
private function getUploadPath() |
|
278
|
|
|
{ |
|
279
|
|
|
if ($this->getSubDir() != null) { |
|
280
|
|
|
$ret = $this->getRepositoryPath().'/'.$this->getSubDir(); |
|
281
|
|
|
} else { |
|
282
|
|
|
$ret = $this->getRepositoryPath(); |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
return $ret; |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
/* |
|
289
|
|
|
* @private function getCreated |
|
290
|
|
|
* @param null |
|
291
|
|
|
*/ |
|
292
|
|
|
/** |
|
293
|
|
|
* @return bool |
|
294
|
|
|
*/ |
|
295
|
|
|
private function getCreated() |
|
296
|
|
|
{ |
|
297
|
|
|
return $this->created; |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
/* |
|
301
|
|
|
* @private function getNotCreated |
|
302
|
|
|
* @param null |
|
303
|
|
|
*/ |
|
304
|
|
|
/** |
|
305
|
|
|
* @return bool |
|
306
|
|
|
*/ |
|
307
|
|
|
private function getNotCreated() |
|
308
|
|
|
{ |
|
309
|
|
|
return $this->notCreated; |
|
310
|
|
|
} |
|
311
|
|
|
|
|
312
|
|
|
/* |
|
313
|
|
|
* @private function setMode |
|
314
|
|
|
* @param string $mode |
|
315
|
|
|
*/ |
|
316
|
|
|
/** |
|
317
|
|
|
* @param $mode |
|
318
|
|
|
*/ |
|
319
|
|
|
private function setMode($mode) |
|
320
|
|
|
{ |
|
321
|
|
|
$this->mode = $mode; |
|
322
|
|
|
} |
|
323
|
|
|
|
|
324
|
|
|
/* |
|
325
|
|
|
* @private function getMode |
|
326
|
|
|
* @param null |
|
327
|
|
|
*/ |
|
328
|
|
|
/** |
|
329
|
|
|
*/ |
|
330
|
|
|
private function getMode() |
|
331
|
|
|
{ |
|
332
|
|
|
return $this->mode; |
|
333
|
|
|
} |
|
334
|
|
|
|
|
335
|
|
|
/* |
|
336
|
|
|
* @public function getLanguage |
|
337
|
|
|
* @param string $moduleDirname |
|
338
|
|
|
* @param string $prefix |
|
339
|
|
|
* @param string $suffix |
|
340
|
|
|
*/ |
|
341
|
|
|
/** |
|
342
|
|
|
* @param $moduleDirname |
|
343
|
|
|
* @param string $prefix |
|
344
|
|
|
* @param string $suffix |
|
345
|
|
|
* |
|
346
|
|
|
* @return string |
|
347
|
|
|
*/ |
|
348
|
|
|
public function getLanguage($moduleDirname, $prefix = '', $suffix = '') |
|
349
|
|
|
{ |
|
350
|
|
|
$lang = '_'.$prefix.'_'.strtoupper($moduleDirname); |
|
351
|
|
|
$ret = $lang; |
|
352
|
|
|
if (!empty($suffix) || $suffix != '_') { |
|
353
|
|
|
$ret = $lang.'_'.$suffix; |
|
354
|
|
|
} elseif ($suffix == '_') { |
|
355
|
|
|
$ret = $lang.'_'; |
|
356
|
|
|
} |
|
357
|
|
|
|
|
358
|
|
|
return $ret; |
|
359
|
|
|
} |
|
360
|
|
|
|
|
361
|
|
|
/* |
|
362
|
|
|
* @public function getLeftString |
|
363
|
|
|
* @param string $string |
|
364
|
|
|
*/ |
|
365
|
|
|
/** |
|
366
|
|
|
* @param $string |
|
367
|
|
|
* |
|
368
|
|
|
* @return string |
|
369
|
|
|
*/ |
|
370
|
|
|
public function getLeftString($string) |
|
371
|
|
|
{ |
|
372
|
|
|
return substr($string, 0, strpos($string, '_')); |
|
373
|
|
|
} |
|
374
|
|
|
|
|
375
|
|
|
/* |
|
376
|
|
|
* @public function getRightString |
|
377
|
|
|
* @param string $string |
|
378
|
|
|
*/ |
|
379
|
|
|
/** |
|
380
|
|
|
* @param $string |
|
381
|
|
|
* |
|
382
|
|
|
* @return string |
|
383
|
|
|
*/ |
|
384
|
|
|
public function getRightString($string) |
|
385
|
|
|
{ |
|
386
|
|
View Code Duplication |
if (strpos($string, '_')) { |
|
|
|
|
|
|
387
|
|
|
$str = strpos($string, '_'); |
|
388
|
|
|
if ($str !== false) { |
|
389
|
|
|
$ret = substr($string, $str + 1, strlen($string)); |
|
390
|
|
|
|
|
391
|
|
|
return $ret; |
|
392
|
|
|
} |
|
393
|
|
|
} |
|
394
|
|
|
|
|
395
|
|
|
return $string; |
|
396
|
|
|
} |
|
397
|
|
|
|
|
398
|
|
|
/* |
|
399
|
|
|
* @public function getCamelCase |
|
400
|
|
|
* @param $string |
|
401
|
|
|
*/ |
|
402
|
|
|
/** |
|
403
|
|
|
* @param $string |
|
404
|
|
|
* @param $ucfirst |
|
405
|
|
|
* @param $lcfirst |
|
406
|
|
|
* |
|
407
|
|
|
* @return string |
|
408
|
|
|
*/ |
|
409
|
|
|
public function getCamelCase($string, $ucfirst = false, $lcfirst = false) |
|
410
|
|
|
{ |
|
411
|
|
|
$rightString = $this->getRightString($string); |
|
412
|
|
|
$leftString = $this->getLeftString($string); |
|
413
|
|
|
if ($ucfirst) { |
|
414
|
|
|
$ret = $this->getUcfirst($leftString).$this->getUcfirst($rightString); |
|
415
|
|
|
|
|
416
|
|
|
return $ret; |
|
417
|
|
|
} |
|
418
|
|
|
if ($lcfirst) { |
|
419
|
|
|
$ret = $this->getlcfirst($leftString).$this->getUcfirst($rightString); |
|
420
|
|
|
|
|
421
|
|
|
return $ret; |
|
422
|
|
|
} |
|
423
|
|
|
|
|
424
|
|
|
return $string; |
|
425
|
|
|
} |
|
426
|
|
|
|
|
427
|
|
|
/* |
|
428
|
|
|
* @public function getUcfirst |
|
429
|
|
|
* @param $string |
|
430
|
|
|
*/ |
|
431
|
|
|
/** |
|
432
|
|
|
* @param $string |
|
433
|
|
|
* |
|
434
|
|
|
* @return string |
|
435
|
|
|
*/ |
|
436
|
|
|
public function getUcfirst($string) |
|
437
|
|
|
{ |
|
438
|
|
|
return ucfirst($string); |
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
|
|
/* |
|
442
|
|
|
* @public function getLcfirst |
|
443
|
|
|
* @param $string |
|
444
|
|
|
*/ |
|
445
|
|
|
/** |
|
446
|
|
|
* @param $string |
|
447
|
|
|
* |
|
448
|
|
|
* @return string |
|
449
|
|
|
*/ |
|
450
|
|
|
public function getLcfirst($string) |
|
451
|
|
|
{ |
|
452
|
|
|
return lcfirst($string); |
|
453
|
|
|
} |
|
454
|
|
|
|
|
455
|
|
|
/* |
|
456
|
|
|
* @public function getStrToUpper |
|
457
|
|
|
* @param $string |
|
458
|
|
|
*/ |
|
459
|
|
|
/** |
|
460
|
|
|
* @param $string |
|
461
|
|
|
* |
|
462
|
|
|
* @return string |
|
463
|
|
|
*/ |
|
464
|
|
|
public function getStrToUpper($string) |
|
465
|
|
|
{ |
|
466
|
|
|
return strtoupper($string); |
|
467
|
|
|
} |
|
468
|
|
|
|
|
469
|
|
|
/* |
|
470
|
|
|
* @public function getStrToLower |
|
471
|
|
|
* @param $string |
|
472
|
|
|
*/ |
|
473
|
|
|
/** |
|
474
|
|
|
* @param $string |
|
475
|
|
|
* |
|
476
|
|
|
* @return string |
|
477
|
|
|
*/ |
|
478
|
|
|
public function getStrToLower($string) |
|
479
|
|
|
{ |
|
480
|
|
|
return strtolower($string); |
|
481
|
|
|
} |
|
482
|
|
|
|
|
483
|
|
|
/* |
|
484
|
|
|
* @public function getInclude |
|
485
|
|
|
* @param $filename |
|
486
|
|
|
*/ |
|
487
|
|
|
/** |
|
488
|
|
|
* @return string |
|
489
|
|
|
*/ |
|
490
|
|
|
public function getInclude($filename = 'header') |
|
491
|
|
|
{ |
|
492
|
|
|
return "include __DIR__ . '/{$filename}.php';\n"; |
|
493
|
|
|
} |
|
494
|
|
|
|
|
495
|
|
|
/* |
|
496
|
|
|
* @public function getIncludeOnce |
|
497
|
|
|
* @param $filename |
|
498
|
|
|
*/ |
|
499
|
|
|
/** |
|
500
|
|
|
* @return string |
|
501
|
|
|
*/ |
|
502
|
|
|
public function getIncludeOnce($filename = 'header') |
|
503
|
|
|
{ |
|
504
|
|
|
return "include_once __DIR__ . '/{$filename}.php';\n"; |
|
505
|
|
|
} |
|
506
|
|
|
|
|
507
|
|
|
/* |
|
508
|
|
|
* @public function getCommentLine |
|
509
|
|
|
* @param $string |
|
510
|
|
|
* @param $var |
|
511
|
|
|
* |
|
512
|
|
|
* @return string |
|
513
|
|
|
*/ |
|
514
|
|
|
public function getCommentLine($string = '', $var = '') |
|
515
|
|
|
{ |
|
516
|
|
|
$value = !empty($var) ? ' '.$var : ''; |
|
517
|
|
|
$ret = "// {$string}{$value}\n"; |
|
518
|
|
|
|
|
519
|
|
|
return $ret; |
|
520
|
|
|
} |
|
521
|
|
|
|
|
522
|
|
|
/** |
|
523
|
|
|
* @private function getHeaderComment |
|
524
|
|
|
* |
|
525
|
|
|
* @param $comment |
|
526
|
|
|
* |
|
527
|
|
|
* @return string |
|
528
|
|
|
*/ |
|
529
|
|
|
public function getHeaderComment($comment) |
|
530
|
|
|
{ |
|
531
|
|
|
return "// ------------------- {$comment} ------------------- //\n"; |
|
532
|
|
|
} |
|
533
|
|
|
|
|
534
|
|
|
/* |
|
535
|
|
|
* @public function getSimpleString |
|
536
|
|
|
* @param $string |
|
537
|
|
|
* |
|
538
|
|
|
* @return string |
|
539
|
|
|
*/ |
|
540
|
|
|
public function getSimpleString($string) |
|
541
|
|
|
{ |
|
542
|
|
|
return "{$string}\n"; |
|
543
|
|
|
} |
|
544
|
|
|
|
|
545
|
|
|
/* |
|
546
|
|
|
* @public function getHeaderFilesComments |
|
547
|
|
|
* @param string $module |
|
548
|
|
|
* @param string $fileName |
|
549
|
|
|
*/ |
|
550
|
|
|
/** |
|
551
|
|
|
* @param $module |
|
552
|
|
|
* @param $fileName |
|
553
|
|
|
* @param $noPhpFile |
|
554
|
|
|
* |
|
555
|
|
|
* @return string |
|
556
|
|
|
*/ |
|
557
|
|
|
public function getHeaderFilesComments($module, $fileName, $noPhpFile = null) |
|
558
|
|
|
{ |
|
559
|
|
|
$name = $module->getVar('mod_name'); |
|
560
|
|
|
$dirname = $module->getVar('mod_dirname'); |
|
561
|
|
|
$version = $module->getVar('mod_version'); |
|
562
|
|
|
$since = $module->getVar('mod_since'); |
|
563
|
|
|
$minXoops = $module->getVar('mod_min_xoops'); |
|
564
|
|
|
$author = $module->getVar('mod_author'); |
|
565
|
|
|
$credits = $module->getVar('mod_credits'); |
|
566
|
|
|
$authorMail = $module->getVar('mod_author_mail'); |
|
567
|
|
|
$authorWebsiteUrl = $module->getVar('mod_author_website_url'); |
|
568
|
|
|
$license = $module->getVar('mod_license'); |
|
569
|
|
|
$subversion = $module->getVar('mod_subversion'); |
|
570
|
|
|
$date = date('D Y-m-d H:i:s'); |
|
571
|
|
|
if (is_null($noPhpFile)) { |
|
572
|
|
|
$ret = <<<EOT |
|
573
|
|
|
<?php |
|
574
|
|
|
/*\n |
|
575
|
|
|
EOT; |
|
576
|
|
|
} elseif (is_string($noPhpFile)) { |
|
577
|
|
|
$ret = <<<EOT |
|
578
|
|
|
{$noPhpFile} |
|
579
|
|
|
/*\n |
|
580
|
|
|
EOT; |
|
581
|
|
|
} else { |
|
582
|
|
|
$ret = <<<EOT |
|
583
|
|
|
/*\n |
|
584
|
|
|
EOT; |
|
585
|
|
|
} |
|
586
|
|
|
// $ret .= file_get_contents('./docs/top_license_file.txt'); |
|
|
|
|
|
|
587
|
|
|
$ret .= <<<EOT |
|
588
|
|
|
You may not change or alter any portion of this comment or credits |
|
589
|
|
|
of supporting developers from this source code or any supporting source code |
|
590
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
591
|
|
|
|
|
592
|
|
|
This program is distributed in the hope that it will be useful, |
|
593
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
594
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
595
|
|
|
*/ |
|
596
|
|
|
/** |
|
597
|
|
|
* {$name} module for xoops |
|
598
|
|
|
* |
|
599
|
|
|
* @copyright The XOOPS Project (http://xoops.org) |
|
600
|
|
|
* @license {$license} |
|
601
|
|
|
* @package {$dirname} |
|
602
|
|
|
* @since {$since} |
|
603
|
|
|
* @min_xoops {$minXoops} |
|
604
|
|
|
* @author {$author} - Email:<{$authorMail}> - Website:<{$authorWebsiteUrl}> |
|
605
|
|
|
* @version \$Id: {$version} {$fileName} {$subversion} {$date}Z {$credits} \$ |
|
606
|
|
|
*/\n |
|
607
|
|
|
EOT; |
|
608
|
|
|
|
|
609
|
|
|
return $ret; |
|
610
|
|
|
} |
|
611
|
|
|
|
|
612
|
|
|
/* |
|
613
|
|
|
* @public function renderFile |
|
614
|
|
|
* @param null |
|
615
|
|
|
*/ |
|
616
|
|
|
/** |
|
617
|
|
|
* @return string |
|
618
|
|
|
*/ |
|
619
|
|
|
public function renderFile() |
|
|
|
|
|
|
620
|
|
|
{ |
|
621
|
|
|
$fileName = $this->getFileName(); |
|
622
|
|
|
$path = $this->getUploadPath().'/'.$fileName; |
|
623
|
|
|
$created = $this->getCreated(); |
|
624
|
|
|
$notCreated = $this->getNotCreated(); |
|
625
|
|
|
$folderName = $this->getFolderName(); |
|
626
|
|
|
$mode = $this->getMode(); |
|
627
|
|
|
$ret = ''; |
|
628
|
|
|
if (!$this->xoopsFile->__construct($path, true)) { |
|
|
|
|
|
|
629
|
|
|
// Force to create file if not exist |
|
630
|
|
|
if ($this->xoopsFile->open($mode, true)) { |
|
|
|
|
|
|
631
|
|
|
if ($this->xoopsFile->writable()) { |
|
|
|
|
|
|
632
|
|
|
// Integration of the content in the file |
|
633
|
|
|
if (!$this->xoopsFile->write($this->getContent(), $mode, true)) { |
|
|
|
|
|
|
634
|
|
|
$ret .= sprintf($notCreated, $fileName, $folderName); |
|
635
|
|
|
$GLOBALS['xoopsTpl']->assign('created', false); |
|
636
|
|
|
exit(); |
|
|
|
|
|
|
637
|
|
|
} |
|
638
|
|
|
// Created |
|
639
|
|
|
$ret .= sprintf($created, $fileName, $folderName); |
|
640
|
|
|
$GLOBALS['xoopsTpl']->assign('created', true); |
|
641
|
|
|
$this->xoopsFile->close(); |
|
|
|
|
|
|
642
|
|
|
} else { |
|
643
|
|
|
$ret .= sprintf($notCreated, $fileName, $folderName); |
|
644
|
|
|
$GLOBALS['xoopsTpl']->assign('created', false); |
|
645
|
|
|
} |
|
646
|
|
|
} else { |
|
647
|
|
|
$ret .= sprintf($notCreated, $fileName, $folderName); |
|
648
|
|
|
$GLOBALS['xoopsTpl']->assign('created', false); |
|
649
|
|
|
} |
|
650
|
|
|
} |
|
651
|
|
|
|
|
652
|
|
|
return $ret; |
|
653
|
|
|
} |
|
654
|
|
|
} |
|
655
|
|
|
|
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.