|
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: admin_index.php 12258 2014-01-02 09:33:29Z timgno $ |
|
23
|
|
|
*/ |
|
24
|
|
|
defined('XOOPS_ROOT_PATH') or die('Restricted access'); |
|
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Class AdminIndex. |
|
28
|
|
|
*/ |
|
29
|
|
|
class AdminIndex extends TDMCreateFile |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
/* |
|
32
|
|
|
* @public function constructor |
|
33
|
|
|
* @param null |
|
34
|
|
|
*/ |
|
35
|
|
|
/** |
|
36
|
|
|
* |
|
37
|
|
|
*/ |
|
38
|
|
View Code Duplication |
public function __construct() |
|
|
|
|
|
|
39
|
|
|
{ |
|
40
|
|
|
parent::__construct(); |
|
41
|
|
|
$this->tdmcfile = TDMCreateFile::getInstance(); |
|
|
|
|
|
|
42
|
|
|
$this->xoopscode = TDMCreateXoopsCode::getInstance(); |
|
|
|
|
|
|
43
|
|
|
$this->phpcode = TDMCreatePhpCode::getInstance(); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/* |
|
47
|
|
|
* @static function &getInstance |
|
48
|
|
|
* @param null |
|
49
|
|
|
*/ |
|
50
|
|
|
/** |
|
51
|
|
|
* @return AdminIndex |
|
52
|
|
|
*/ |
|
53
|
|
|
public static function &getInstance() |
|
54
|
|
|
{ |
|
55
|
|
|
static $instance = false; |
|
56
|
|
|
if (!$instance) { |
|
57
|
|
|
$instance = new self(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return $instance; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/* |
|
64
|
|
|
* @public function write |
|
65
|
|
|
* @param string $module |
|
66
|
|
|
* @param mixed $tables |
|
67
|
|
|
* @param string $filename |
|
68
|
|
|
*/ |
|
69
|
|
|
/** |
|
70
|
|
|
* @param $module |
|
71
|
|
|
* @param $tables |
|
72
|
|
|
* @param $filename |
|
73
|
|
|
*/ |
|
74
|
|
|
public function write($module, $tables, $filename) |
|
75
|
|
|
{ |
|
76
|
|
|
$this->setModule($module); |
|
77
|
|
|
$this->setTables($tables); |
|
78
|
|
|
$this->setFileName($filename); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @private function render |
|
83
|
|
|
* |
|
84
|
|
|
* @param $module |
|
85
|
|
|
* |
|
86
|
|
|
* @return string |
|
87
|
|
|
*/ |
|
88
|
|
|
private function getAdminIndex($module) |
|
89
|
|
|
{ |
|
90
|
|
|
$moduleDirname = $module->getVar('mod_dirname'); |
|
91
|
|
|
$tables = $this->getTableTables($module->getVar('mod_id'), 'table_order'); |
|
92
|
|
|
$language = $this->getLanguage($moduleDirname, 'AM'); |
|
93
|
|
|
$languageThereAre = $this->getLanguage($moduleDirname, 'AM', 'THEREARE_'); |
|
94
|
|
|
$ret = $this->getInclude(); |
|
95
|
|
|
$ret .= $this->getCommentLine('Count elements'); |
|
96
|
|
|
$tableName = null; |
|
97
|
|
View Code Duplication |
foreach (array_keys($tables) as $i) { |
|
|
|
|
|
|
98
|
|
|
$tableName = $tables[$i]->getVar('table_name'); |
|
99
|
|
|
$ucfTableName = ucfirst($tableName); |
|
100
|
|
|
$ret .= $this->xoopscode->getXoopsCodeEqualsOperator("\$count{$ucfTableName}", "\${$tableName}Handler->getCount()"); |
|
101
|
|
|
} |
|
102
|
|
|
$ret .= $this->phpcode->getPhpCodeCommentLine('Template Index'); |
|
103
|
|
|
$ret .= $this->xoopscode->getXoopsCodeTemplateMain("{$moduleDirname}", 'index'); |
|
104
|
|
|
$ret .= $this->phpcode->getPhpCodeCommentLine('InfoBox Statistics'); |
|
105
|
|
|
$ret .= $this->xoopscode->getXoopsCodeAddInfoBox($language.'STATISTICS'); |
|
106
|
|
|
$ret .= $this->phpcode->getPhpCodeCommentLine('Info elements'); |
|
107
|
|
View Code Duplication |
foreach (array_keys($tables) as $i) { |
|
|
|
|
|
|
108
|
|
|
$tableName = $tables[$i]->getVar('table_name'); |
|
109
|
|
|
$tableInstall[] = $tables[$i]->getVar('table_install'); |
|
|
|
|
|
|
110
|
|
|
$stuTableName = $languageThereAre.strtoupper($tableName); |
|
111
|
|
|
$ucfTableName = ucfirst($tableName); |
|
112
|
|
|
$ret .= $this->xoopscode->getXoopsCodeAddInfoBoxLine($language.'STATISTICS', $stuTableName, "\$count{$ucfTableName}", true); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
if ($tableName == null) { |
|
116
|
|
|
$ret .= $this->xoopscode->getXoopsCodeAddInfoBoxLine($language.'STATISTICS', 'No statistics', '0', true); |
|
117
|
|
|
} |
|
118
|
|
|
if (is_array($tables) && in_array(1, $tableInstall)) { |
|
|
|
|
|
|
119
|
|
|
$ret .= $this->phpcode->getPhpCodeCommentLine('Upload Folders'); |
|
120
|
|
|
$ret .= $this->getSimpleString('$folder = array('); |
|
121
|
|
|
$stuModuleDirname = strtoupper($moduleDirname); |
|
122
|
|
View Code Duplication |
foreach (array_keys($tables) as $i) { |
|
|
|
|
|
|
123
|
|
|
$tableName = $tables[$i]->getVar('table_name'); |
|
124
|
|
|
if (1 == $tables[$i]->getVar('table_install')) { |
|
125
|
|
|
$ret .= $this->getSimpleString("\t{$stuModuleDirname}_UPLOAD_PATH . '/{$tableName}/',"); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
$ret .= $this->getSimpleString(');'); |
|
129
|
|
|
$ret .= $this->getCommentLine('Uploads Folders Created'); |
|
130
|
|
|
$boxLine = $this->xoopscode->getXoopsCodeAddInfoBoxLine('$folder[$i]', "'folder'"); |
|
131
|
|
|
$boxLine .= "\t".$this->xoopscode->getXoopsCodeAddInfoBoxLine("array(\$folder[\$i], '777')", "'chmod'"); |
|
132
|
|
|
$ret .= $this->phpcode->getPhpCodeForeach('$folder', $boxLine, '$i', true); |
|
133
|
|
|
} |
|
134
|
|
|
$ret .= $this->getCommentLine('Render Index'); |
|
135
|
|
|
$ret .= $this->xoopscode->getXoopsCodeTplAssign('navigation', "\$adminMenu->addNavigation('index.php')"); |
|
136
|
|
|
$ret .= $this->xoopscode->getXoopsCodeTplAssign('index', '$adminMenu->renderIndex()'); |
|
137
|
|
|
|
|
138
|
|
|
$ret .= $this->getInclude('footer'); |
|
139
|
|
|
|
|
140
|
|
|
return $ret; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/* |
|
144
|
|
|
* @public function render |
|
145
|
|
|
* @param null |
|
146
|
|
|
*/ |
|
147
|
|
|
/** |
|
148
|
|
|
* @return bool|string |
|
149
|
|
|
*/ |
|
150
|
|
|
public function render() |
|
151
|
|
|
{ |
|
152
|
|
|
$module = $this->getModule(); |
|
153
|
|
|
$moduleDirname = $module->getVar('mod_dirname'); |
|
154
|
|
|
$filename = $this->getFileName(); |
|
155
|
|
|
$content = $this->getHeaderFilesComments($module, $filename); |
|
156
|
|
|
$content .= $this->getAdminIndex($module); |
|
157
|
|
|
|
|
158
|
|
|
$this->tdmcfile->create($moduleDirname, 'admin', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED); |
|
|
|
|
|
|
159
|
|
|
|
|
160
|
|
|
return $this->tdmcfile->renderFile(); |
|
|
|
|
|
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
|
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.