1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Modulebuilder\Files\User; |
4
|
|
|
|
5
|
|
|
use XoopsModules\Modulebuilder; |
6
|
|
|
|
7
|
|
|
/* |
8
|
|
|
You may not change or alter any portion of this comment or credits |
9
|
|
|
of supporting developers from this source code or any supporting source code |
10
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
11
|
|
|
|
12
|
|
|
This program is distributed in the hope that it will be useful, |
13
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
15
|
|
|
*/ |
16
|
|
|
/** |
17
|
|
|
* modulebuilder module. |
18
|
|
|
* |
19
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
20
|
|
|
* @license GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
21
|
|
|
* |
22
|
|
|
* @since 2.5.0 |
23
|
|
|
* |
24
|
|
|
* @author Txmod Xoops https://xoops.org |
25
|
|
|
* Goffy https://myxoops.org |
26
|
|
|
* |
27
|
|
|
*/ |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Class UserXoopsCode. |
31
|
|
|
*/ |
32
|
|
|
class UserXoopsCode |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @var mixed |
36
|
|
|
*/ |
37
|
|
|
private $xc = null; |
38
|
|
|
/** |
39
|
|
|
* @var mixed |
40
|
|
|
*/ |
41
|
|
|
private $pc = null; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @public function constructor |
45
|
|
|
* @param null |
46
|
|
|
*/ |
47
|
|
|
public function __construct() |
48
|
|
|
{ |
49
|
|
|
$this->xc = Modulebuilder\Files\CreateXoopsCode::getInstance(); |
50
|
|
|
$this->pc = Modulebuilder\Files\CreatePhpCode::getInstance(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/* |
54
|
|
|
* @static function getInstance |
55
|
|
|
* @param null |
56
|
|
|
*/ |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return UserXoopsCode |
60
|
|
|
*/ |
61
|
|
|
public static function getInstance() |
62
|
|
|
{ |
63
|
|
|
static $instance = false; |
64
|
|
|
if (!$instance) { |
65
|
|
|
$instance = new self(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return $instance; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @public function getUserTplMain |
73
|
|
|
* |
74
|
|
|
* @param $moduleDirname |
75
|
|
|
* @param string $tableName |
76
|
|
|
* |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
|
|
public function getUserTplMain($moduleDirname, $tableName = 'index') |
80
|
|
|
{ |
81
|
|
|
return "\$GLOBALS['xoopsOption']['template_main'] = '{$moduleDirname}_{$tableName}.tpl';\n"; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @public function getUserAddMeta |
86
|
|
|
* |
87
|
|
|
* @param string $type |
88
|
|
|
* @param $language |
89
|
|
|
* @param $tableName |
90
|
|
|
* |
91
|
|
|
* @param string $t |
92
|
|
|
* @return string |
93
|
|
|
*/ |
94
|
|
|
public function getUserAddMeta($type, $language, $tableName, $t = '') |
95
|
|
|
{ |
96
|
|
|
$stuTableName = \mb_strtoupper($tableName); |
97
|
|
|
$stripTags = $this->pc->getPhpCodeStripTags('', $language . $stuTableName, true); |
98
|
|
|
|
99
|
|
|
return "{$t}\$GLOBALS['xoTheme']->addMeta('meta', '{$type}', {$stripTags});\n"; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @public function getUserMetaKeywords |
104
|
|
|
* |
105
|
|
|
* @param $moduleDirname |
106
|
|
|
* |
107
|
|
|
* @return string |
108
|
|
|
*/ |
109
|
|
|
public function getUserMetaKeywords($moduleDirname) |
110
|
|
|
{ |
111
|
|
|
$implode = $this->pc->getPhpCodeImplode(',', '$keywords'); |
112
|
|
|
|
113
|
|
|
return "{$moduleDirname}MetaKeywords(\$helper->getConfig('keywords') . ', ' . {$implode});\n"; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @public function getUserMetaDesc |
118
|
|
|
* |
119
|
|
|
* @param $moduleDirname |
120
|
|
|
* @param $language |
121
|
|
|
* @param string $file |
122
|
|
|
* |
123
|
|
|
* @return string |
124
|
|
|
*/ |
125
|
|
|
public function getUserMetaDesc($moduleDirname, $language, $file = 'INDEX') |
126
|
|
|
{ |
127
|
|
|
return "{$moduleDirname}MetaDescription({$language}{$file}_DESC);\n"; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @public function getUserBreadcrumbs |
132
|
|
|
* |
133
|
|
|
* @param $language |
134
|
|
|
* @param string $tableName |
135
|
|
|
* @param string $op |
136
|
|
|
* @param string $link |
137
|
|
|
* @param string $t |
138
|
|
|
* |
139
|
|
|
* @return string |
140
|
|
|
*/ |
141
|
|
|
public function getUserBreadcrumbs($language, $tableName = 'index', $op = '', $link = '', $t = '') |
142
|
|
|
{ |
143
|
|
|
$stuTableName = \mb_strtoupper($tableName); |
144
|
|
|
$stuOp = ''; |
145
|
|
|
$ret = $this->pc->getPhpCodeCommentLine('Breadcrumbs', '', $t); |
146
|
|
|
if ('' !== $op) { |
147
|
|
|
$stuOp = ''; |
148
|
|
|
if ('' !== $tableName) { |
149
|
|
|
$stuOp .= '_'; |
150
|
|
|
} |
151
|
|
|
$stuOp .= \mb_strtoupper($op); |
152
|
|
|
} |
153
|
|
|
if ('' === $link) { |
154
|
|
|
$arrBCrumb = ["'title'" => "{$language}{$stuTableName}{$stuOp}"]; |
155
|
|
|
} else { |
156
|
|
|
$arrBCrumb = ["'title'" => "{$language}{$stuTableName}{$stuOp}", "'link'" => "'{$link}'"]; |
157
|
|
|
} |
158
|
|
|
$ret .= $this->pc->getPhpCodeArray('xoBreadcrumbs[]', $arrBCrumb, false, $t); |
159
|
|
|
|
160
|
|
|
return $ret; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @public function getUserBreadcrumbs |
165
|
|
|
* |
166
|
|
|
* @return string |
167
|
|
|
*/ |
168
|
|
|
public function getUserBreadcrumbsFooterFile() |
169
|
|
|
{ |
170
|
|
|
$cond = $this->xc->getXcXoopsTplAssign('xoBreadcrumbs', '$xoBreadcrumbs'); |
171
|
|
|
$ret = $this->pc->getPhpCodeConditions('\count($xoBreadcrumbs)', ' > ', '1', $cond, false, "\t\t"); |
172
|
|
|
|
173
|
|
|
return $ret; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @public function getUserModVersionArray |
178
|
|
|
* |
179
|
|
|
* @param int $eleArray |
180
|
|
|
* @param $descriptions |
181
|
|
|
* @param null $name |
|
|
|
|
182
|
|
|
* @param null $index |
|
|
|
|
183
|
|
|
* @param bool $num |
184
|
|
|
* @param string $t |
185
|
|
|
* |
186
|
|
|
* @return string |
187
|
|
|
*/ |
188
|
|
|
public function getUserModVersionArray($eleArray, $descriptions, $name = null, $index = null, $num = false, $t = '') |
189
|
|
|
{ |
190
|
|
|
$ret = $t . '$modversion'; |
191
|
|
|
$isArray = false; |
192
|
|
|
$n = ''; |
193
|
|
|
if (!\is_array($descriptions)) { |
194
|
|
|
$descs = [$descriptions]; |
195
|
|
|
} else { |
196
|
|
|
$descs = $descriptions; |
197
|
|
|
$isArray = true; |
198
|
|
|
$n = "\n"; |
199
|
|
|
} |
200
|
|
|
if (0 === $eleArray) { |
201
|
|
|
$ret .= " = "; |
202
|
|
|
} elseif (1 === $eleArray || 11 === $eleArray) { |
203
|
|
|
$ret .= "['{$name}'] = "; |
204
|
|
|
} elseif (2 === $eleArray) { |
205
|
|
|
$ret .= "['{$name}'][{$index}] = "; |
206
|
|
|
} elseif (3 === $eleArray) { |
207
|
|
|
$ret .= "['{$name}'][{$index}][{$num}] = "; |
208
|
|
|
} |
209
|
|
|
if ($isArray) { |
210
|
|
|
$ret .= "["; |
211
|
|
|
} |
212
|
|
|
$ret .= $n; |
213
|
|
|
//search for longest key |
214
|
|
|
$len = 0; |
215
|
|
|
foreach ($descs as $key => $desc) { |
216
|
|
|
$len = \strlen($key) > $len ? \strlen($key) : $len; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
foreach ($descs as $key => $desc) { |
220
|
|
|
$space = str_repeat(' ', $len - \strlen($key)); |
221
|
|
|
if ($eleArray < 4) { |
222
|
|
|
$ret .= $t . "\t'{$key}'{$space} => {$desc},{$n}"; |
223
|
|
|
} elseif (11 === $eleArray) { |
224
|
|
|
if ('/' === \substr($desc, 1, 1)) { |
225
|
|
|
$ret .= $t . "\t{$desc}"; |
226
|
|
|
} else { |
227
|
|
|
$ret .= $t . "\t{$desc},{$n}"; |
228
|
|
|
} |
229
|
|
|
} elseif (12 === $eleArray) { |
230
|
|
|
$ret .= $t . "\t{$desc}{$n}"; |
231
|
|
|
} |
232
|
|
|
} |
233
|
|
|
$ret .= $t; |
234
|
|
|
if ($isArray) { |
235
|
|
|
$ret .= "]"; |
236
|
|
|
} |
237
|
|
|
$ret .= ";\n"; |
238
|
|
|
return $ret; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* @public function getUserModVersionText |
243
|
|
|
* |
244
|
|
|
* @param int $eleArray |
245
|
|
|
* @param $text |
246
|
|
|
* @param null $name |
|
|
|
|
247
|
|
|
* @param null $index |
|
|
|
|
248
|
|
|
* @param bool $num |
249
|
|
|
* @param string $t |
250
|
|
|
* |
251
|
|
|
* @return string |
252
|
|
|
*/ |
253
|
|
|
public function getUserModVersionText($eleArray, $text, $name = null, $index = null, $num = false, $t = '') |
254
|
|
|
{ |
255
|
|
|
$ret = $t . '$modversion'; |
256
|
|
|
|
257
|
|
|
if (0 === $eleArray) { |
258
|
|
|
$ret .= " = "; |
259
|
|
|
} elseif (1 === $eleArray) { |
260
|
|
|
$ret .= "['{$name}'] = "; |
261
|
|
|
} elseif (2 === $eleArray) { |
262
|
|
|
$ret .= "['{$name}'][{$index}] = "; |
263
|
|
|
} elseif (3 === $eleArray) { |
264
|
|
|
$ret .= "['{$name}'][{$index}][{$num}] = "; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
$ret .= $t . "{$text};\n"; |
268
|
|
|
return $ret; |
269
|
|
|
} |
270
|
|
|
} |
271
|
|
|
|