| Total Complexity | 146 |
| Total Lines | 1429 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like CreateXoopsCode often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use CreateXoopsCode, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 31 | class CreateXoopsCode |
||
| 32 | { |
||
| 33 | /** |
||
| 34 | * @static function getInstance |
||
| 35 | * @param null |
||
| 36 | */ |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @return Tdmcreate\Files\CreateXoopsCode |
||
| 40 | */ |
||
| 41 | public static function getInstance() |
||
| 42 | { |
||
| 43 | static $instance = false; |
||
| 44 | if (!$instance) { |
||
| 45 | $instance = new self(); |
||
| 46 | } |
||
| 47 | |||
| 48 | return $instance; |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @public function getXcSwitch |
||
| 53 | * @param $op |
||
| 54 | * @param $cases |
||
| 55 | * @param $defaultAfterCase |
||
| 56 | * @param $default |
||
| 57 | * @param $t - Indentation |
||
|
|
|||
| 58 | * |
||
| 59 | * @return string |
||
| 60 | */ |
||
| 61 | public function getXcSwitch($op = '', $cases = [], $defaultAfterCase = false, $default = false, $t = '') |
||
| 62 | { |
||
| 63 | $pc = Tdmcreate\Files\CreatePhpCode::getInstance(); |
||
| 64 | $contentSwitch = $pc->getPhpCodeCaseSwitch($cases, $defaultAfterCase, $default, $t); |
||
| 65 | |||
| 66 | return $pc->getPhpCodeSwitch($op, $contentSwitch, $t); |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @public function getXcEqualsOperator |
||
| 71 | * @param $var |
||
| 72 | * @param $value |
||
| 73 | * @param $interlock |
||
| 74 | * @param $ref |
||
| 75 | * @param $t - Indentation |
||
| 76 | * |
||
| 77 | * @return string |
||
| 78 | */ |
||
| 79 | public function getXcEqualsOperator($var, $value, $interlock = null, $ref = false, $t = '') |
||
| 80 | { |
||
| 81 | if (false === $ref) { |
||
| 82 | $ret = "{$t}{$var} {$interlock}= {$value};\n"; |
||
| 83 | } else { |
||
| 84 | $ret = "{$t}{$var} = {$value};\n"; |
||
| 85 | } |
||
| 86 | |||
| 87 | return $ret; |
||
| 88 | } |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @public function getXcCPHeader |
||
| 92 | * @param null |
||
| 93 | * @return string |
||
| 94 | */ |
||
| 95 | public function getXcCPHeader() |
||
| 96 | { |
||
| 97 | return "xoops_cp_header();\n"; |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @public function getXcCPFooter |
||
| 102 | * @param null |
||
| 103 | * @return string |
||
| 104 | */ |
||
| 105 | public function getXcCPFooter() |
||
| 106 | { |
||
| 107 | return "xoops_cp_footer();\n"; |
||
| 108 | } |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @public function getXcLoad |
||
| 112 | * |
||
| 113 | * @param $var |
||
| 114 | * @param $t |
||
| 115 | * @return string |
||
| 116 | */ |
||
| 117 | public function getXcLoad($var = '', $t = '') |
||
| 118 | { |
||
| 119 | return "{$t}xoops_load('{$var}');\n"; |
||
| 120 | } |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @public function getXcLoadLanguage |
||
| 124 | * |
||
| 125 | * @param $lang |
||
| 126 | * @param $t |
||
| 127 | * @param $domain |
||
| 128 | * |
||
| 129 | * @return string |
||
| 130 | */ |
||
| 131 | public function getXcLoadLanguage($lang, $t = '', $domain = '') |
||
| 132 | { |
||
| 133 | if ('' === $domain) { |
||
| 134 | return "{$t}xoops_loadLanguage('{$lang}');\n"; |
||
| 135 | } |
||
| 136 | |||
| 137 | return "{$t}xoops_loadLanguage('{$lang}', '{$domain}');\n"; |
||
| 138 | } |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @public function getXcAnchorFunction |
||
| 142 | * @param $anchor |
||
| 143 | * @param $name |
||
| 144 | * @param $vars |
||
| 145 | * @param $close |
||
| 146 | * |
||
| 147 | * @return string |
||
| 148 | */ |
||
| 149 | public function getXcAnchorFunction($anchor, $name, $vars, $close = false) |
||
| 150 | { |
||
| 151 | $semicolon = false !== $close ? ';' : ''; |
||
| 152 | |||
| 153 | return "\${$anchor}->{$name}({$vars}){$semicolon}"; |
||
| 154 | } |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @public function getXcSetVar |
||
| 158 | * @param $tableName |
||
| 159 | * @param $fieldName |
||
| 160 | * @param $var |
||
| 161 | * @param $t |
||
| 162 | * @return string |
||
| 163 | */ |
||
| 164 | public function getXcSetVar($tableName, $fieldName, $var, $t = '') |
||
| 165 | { |
||
| 166 | return "{$t}\${$tableName}Obj->setVar('{$fieldName}', {$var});\n"; |
||
| 167 | } |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @public function getXcGetVar |
||
| 171 | * @param $varLeft |
||
| 172 | * @param $handle |
||
| 173 | * @param $var |
||
| 174 | * @param $isParam |
||
| 175 | * @param $t |
||
| 176 | * |
||
| 177 | * @return string |
||
| 178 | */ |
||
| 179 | public function getXcGetVar($varLeft = '', $handle = '', $var = '', $isParam = false, $t = '') |
||
| 180 | { |
||
| 181 | if (!$isParam) { |
||
| 182 | $ret = "{$t}\${$varLeft} = \${$handle}->getVar('{$var}');\n"; |
||
| 183 | } else { |
||
| 184 | $ret = "\${$handle}->getVar('{$var}')"; |
||
| 185 | } |
||
| 186 | |||
| 187 | return $ret; |
||
| 188 | } |
||
| 189 | |||
| 190 | /** |
||
| 191 | * @public function getXcGroupPermForm |
||
| 192 | * @param $varLeft |
||
| 193 | * @param $formTitle |
||
| 194 | * @param $moduleId |
||
| 195 | * @param $permName |
||
| 196 | * @param $permDesc |
||
| 197 | * @param $filename |
||
| 198 | * @param $t |
||
| 199 | * |
||
| 200 | * @return string |
||
| 201 | */ |
||
| 202 | public function getXcGroupPermForm($varLeft = '', $formTitle = '', $moduleId = '', $permName = '', $permDesc = '', $filename = '', $t = '') |
||
| 203 | { |
||
| 204 | return "{$t}\${$varLeft} = new \XoopsGroupPermForm({$formTitle}, {$moduleId}, {$permName}, {$permDesc}, {$filename});\n"; |
||
| 205 | } |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @public function getXcAddItem |
||
| 209 | * @param $varLeft |
||
| 210 | * @param $paramLeft |
||
| 211 | * @param $paramRight |
||
| 212 | * @param $t |
||
| 213 | * |
||
| 214 | * @return string |
||
| 215 | */ |
||
| 216 | public function getXcAddItem($varLeft = '', $paramLeft = '', $paramRight = '', $t = '') |
||
| 217 | { |
||
| 218 | return "{$t}\${$varLeft}->addItem({$paramLeft}, {$paramRight});\n"; |
||
| 219 | } |
||
| 220 | |||
| 221 | /** |
||
| 222 | * @public function getXcGetGroupIds |
||
| 223 | * @param string $var |
||
| 224 | * @param string $anchor |
||
| 225 | * @param $param1 |
||
| 226 | * @param $param2 |
||
| 227 | * @param $param3 |
||
| 228 | * @param string $t |
||
| 229 | * @return string |
||
| 230 | */ |
||
| 231 | public function getXcGetGroupIds($var = '', $anchor = '', $param1 = null, $param2 = null, $param3 = null, $t = '') |
||
| 232 | { |
||
| 233 | return "{$t}\${$var} = \${$anchor}->getGroupIds({$param1}, {$param2}, {$param3});\n"; |
||
| 234 | } |
||
| 235 | |||
| 236 | /** |
||
| 237 | * @public function getXcGetItemIds |
||
| 238 | * @param string $var |
||
| 239 | * @param string $anchor |
||
| 240 | * @param $param1 |
||
| 241 | * @param $param2 |
||
| 242 | * @param $param3 |
||
| 243 | * @param string $t |
||
| 244 | * @return string |
||
| 245 | */ |
||
| 246 | public function getXcGetItemIds($var = '', $anchor = '', $param1 = null, $param2 = null, $param3 = null, $t = '') |
||
| 247 | { |
||
| 248 | return "{$t}\${$var} = \${$anchor}->getItemIds({$param1}, {$param2}, {$param3});\n"; |
||
| 249 | } |
||
| 250 | |||
| 251 | /** |
||
| 252 | * @public function getXcTextDateSelectSetVar |
||
| 253 | * @param $tableName |
||
| 254 | * @param $tableSoleName |
||
| 255 | * @param $fieldName |
||
| 256 | * @param string $t |
||
| 257 | * @return string |
||
| 258 | */ |
||
| 259 | public function getXcTextDateSelectSetVar($tableName, $tableSoleName, $fieldName, $t = '') |
||
| 260 | { |
||
| 261 | $tf = Tdmcreate\Files\CreateFile::getInstance(); |
||
| 262 | $rightField = $tf->getRightString($fieldName); |
||
| 263 | $ucfRightFiled = ucfirst($rightField); |
||
| 264 | $value = "date_create_from_format(_SHORTDATESTRING, \$_POST['{$fieldName}'])"; |
||
| 265 | $ret = $this->getXcEqualsOperator("\${$tableSoleName}{$ucfRightFiled}", $value, null, false, $t); |
||
| 266 | $ret .= $this->getXcSetVar($tableName, $fieldName, "\${$tableSoleName}{$ucfRightFiled}->getTimestamp()", $t); |
||
| 267 | |||
| 268 | return $ret; |
||
| 269 | } |
||
| 270 | |||
| 271 | /** |
||
| 272 | * @public function getXcCheckBoxOrRadioYNSetVar |
||
| 273 | * @param $tableName |
||
| 274 | * @param $fieldName |
||
| 275 | * @param $t |
||
| 276 | * @return string |
||
| 277 | */ |
||
| 278 | public function getXcCheckBoxOrRadioYNSetVar($tableName, $fieldName, $t = '') |
||
| 279 | { |
||
| 280 | return $this->getXcSetVar($tableName, $fieldName, "((1 == \$_REQUEST['{$fieldName}']) ? '1' : '0')", $t); |
||
| 281 | } |
||
| 282 | |||
| 283 | /** |
||
| 284 | * @public function getXcMediaUploader |
||
| 285 | * @param $var |
||
| 286 | * @param $dirPath |
||
| 287 | * @param $moduleDirname |
||
| 288 | * @param $t |
||
| 289 | * @return string |
||
| 290 | */ |
||
| 291 | public function getXcMediaUploader($var, $dirPath, $moduleDirname, $t = '') |
||
| 292 | { |
||
| 293 | $mimetypes = $this->getXcGetConfig($moduleDirname, 'mimetypes'); |
||
| 294 | $maxsize = $this->getXcGetConfig($moduleDirname, 'maxsize'); |
||
| 295 | |||
| 296 | return "{$t}\${$var} = new \XoopsMediaUploader({$dirPath}, |
||
| 297 | {$mimetypes}, |
||
| 298 | {$maxsize}, null, null);\n"; |
||
| 299 | } |
||
| 300 | |||
| 301 | /** |
||
| 302 | * @public function getXcXoopsCaptcha |
||
| 303 | * @param $var |
||
| 304 | * @param $instance |
||
| 305 | * @param $t |
||
| 306 | * |
||
| 307 | * @return string |
||
| 308 | */ |
||
| 309 | public function getXcGetInstance($var = '', $instance = '', $t = '') |
||
| 310 | { |
||
| 311 | return "{$t}\${$var} = {$instance}::getInstance();\n"; |
||
| 312 | } |
||
| 313 | |||
| 314 | /** |
||
| 315 | * @public function getXcXoopsCaptcha |
||
| 316 | * @param $t |
||
| 317 | * @return string |
||
| 318 | */ |
||
| 319 | public function getXcXoopsCaptcha($t = '') |
||
| 320 | { |
||
| 321 | return "{$t}\$xoopsCaptcha = \XoopsCaptcha::getInstance();\n"; |
||
| 322 | } |
||
| 323 | |||
| 324 | /** |
||
| 325 | * @public function getXcXoopsImgListArray |
||
| 326 | * @param $return |
||
| 327 | * @param $var |
||
| 328 | * @param $t |
||
| 329 | * |
||
| 330 | * @return string |
||
| 331 | */ |
||
| 332 | public function getXcXoopsImgListArray($return, $var, $t = '') |
||
| 333 | { |
||
| 334 | return "{$t}\${$return} = \XoopsLists::getImgListAsArray( {$var} );\n"; |
||
| 335 | } |
||
| 336 | |||
| 337 | /** |
||
| 338 | * @public function getXcGetConfig |
||
| 339 | * @param $moduleDirname |
||
| 340 | * @param $name |
||
| 341 | * @return string |
||
| 342 | */ |
||
| 343 | public function getXcGetConfig($moduleDirname, $name) |
||
| 344 | { |
||
| 345 | return "\${$moduleDirname}->getConfig('{$name}')"; |
||
| 346 | } |
||
| 347 | |||
| 348 | /** |
||
| 349 | * @public function getXcIdGetVar |
||
| 350 | * @param $lpFieldName |
||
| 351 | * @param $t |
||
| 352 | * @return string |
||
| 353 | */ |
||
| 354 | public function getXcIdGetVar($lpFieldName, $t = '') |
||
| 355 | { |
||
| 356 | return "{$t}\${$lpFieldName}['id'] = \$i;\n"; |
||
| 357 | } |
||
| 358 | |||
| 359 | /** |
||
| 360 | * @public function getXcGetVarAll |
||
| 361 | * @param $lpFieldName |
||
| 362 | * @param $rpFieldName |
||
| 363 | * @param $tableName |
||
| 364 | * @param $fieldName |
||
| 365 | * @param $t |
||
| 366 | * @return string |
||
| 367 | */ |
||
| 368 | public function getXcGetVarAll($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '') |
||
| 369 | { |
||
| 370 | return "{$t}\${$lpFieldName}['{$rpFieldName}'] = \${$tableName}All[\$i]->getVar('{$fieldName}');\n"; |
||
| 371 | } |
||
| 372 | |||
| 373 | /** |
||
| 374 | * @public function getXoopsHandlerInstance |
||
| 375 | * @param $moduleDirname |
||
| 376 | * |
||
| 377 | * @param string $t |
||
| 378 | * @return string |
||
| 379 | */ |
||
| 380 | public function getXoopsHandlerInstance($moduleDirname, $t = '') |
||
| 381 | { |
||
| 382 | $ucfModuleDirname = ucfirst($moduleDirname); |
||
| 383 | $ret = "{$t}// Get instance of module\n"; |
||
| 384 | $ret .= "{$t}\${$moduleDirname} = {$ucfModuleDirname}Helper::getInstance();\n"; |
||
| 385 | |||
| 386 | return $ret; |
||
| 387 | } |
||
| 388 | |||
| 389 | /** |
||
| 390 | * @public function getXoopsHandlerLine |
||
| 391 | * @param $moduleDirname |
||
| 392 | * @param $tableName |
||
| 393 | * @param $t |
||
| 394 | * @return string |
||
| 395 | */ |
||
| 396 | public function getXoopsHandlerLine($moduleDirname, $tableName, $t = '') |
||
| 397 | { |
||
| 398 | return "{$t}\${$tableName}Handler = \${$moduleDirname}->getHandler('{$tableName}');\n"; |
||
| 399 | } |
||
| 400 | |||
| 401 | /** |
||
| 402 | * @public function getXoopsClearHandler |
||
| 403 | * @param $left |
||
| 404 | * @param $anchor |
||
| 405 | * @param $var |
||
| 406 | * @param $t |
||
| 407 | * |
||
| 408 | * @return string |
||
| 409 | */ |
||
| 410 | public function getXoopsClearHandler($left, $anchor, $var, $t = '') |
||
| 411 | { |
||
| 412 | return "{$t}\${$left}Handler = \${$anchor}->getHandler('{$var}');\n"; |
||
| 413 | } |
||
| 414 | |||
| 415 | /** |
||
| 416 | * @public function getXoopsFormSelectExtraOptions |
||
| 417 | * @param string $varSelect |
||
| 418 | * @param string $caption |
||
| 419 | * @param string $var |
||
| 420 | * @param array $options |
||
| 421 | * @param bool $setExtra |
||
| 422 | * |
||
| 423 | * @param string $t |
||
| 424 | * @return string |
||
| 425 | */ |
||
| 426 | public function getXoopsFormSelectExtraOptions($varSelect = '', $caption = '', $var = '', $options = [], $setExtra = true, $t = '') |
||
| 427 | { |
||
| 428 | $ret = "{$t}\${$varSelect} = new \XoopsFormSelect({$caption}, '{$var}', \${$var});\n"; |
||
| 429 | if (false !== $setExtra) { |
||
| 430 | $ret .= "{$t}\${$varSelect}->setExtra('{$setExtra}');\n"; |
||
| 431 | } |
||
| 432 | foreach ($options as $key => $value) { |
||
| 433 | $ret .= "{$t}\${$varSelect}->addOption('{$key}', {$value});\n"; |
||
| 434 | } |
||
| 435 | |||
| 436 | return $ret; |
||
| 437 | } |
||
| 438 | |||
| 439 | /** |
||
| 440 | * @public function getXcUnameFromId |
||
| 441 | * @param $left |
||
| 442 | * @param $value |
||
| 443 | * @param string $t |
||
| 444 | * |
||
| 445 | * @return string |
||
| 446 | */ |
||
| 447 | public function getXcUnameFromId($left, $value, $t = '') |
||
| 448 | { |
||
| 449 | return "{$t}\${$left} = \XoopsUser::getUnameFromId({$value});\n"; |
||
| 450 | } |
||
| 451 | |||
| 452 | /** |
||
| 453 | * @public function getXcFormatTimeStamp |
||
| 454 | * @param $left |
||
| 455 | * @param $value |
||
| 456 | * @param string $format |
||
| 457 | * @param string $t |
||
| 458 | * @return string |
||
| 459 | */ |
||
| 460 | public function getXcFormatTimeStamp($left, $value, $format = 's', $t = '') |
||
| 461 | { |
||
| 462 | return "{$t}\${$left} = formatTimeStamp({$value}, '{$format}');\n"; |
||
| 463 | } |
||
| 464 | |||
| 465 | /** |
||
| 466 | * @public function getXcTopicGetVar |
||
| 467 | * @param $lpFieldName |
||
| 468 | * @param $rpFieldName |
||
| 469 | * @param $tableName |
||
| 470 | * @param $tableNameTopic |
||
| 471 | * @param $fieldNameParent |
||
| 472 | * @param $fieldNameTopic |
||
| 473 | * @param string $t |
||
| 474 | * @return string |
||
| 475 | */ |
||
| 476 | public function getXcTopicGetVar($lpFieldName, $rpFieldName, $tableName, $tableNameTopic, $fieldNameParent, $fieldNameTopic, $t = '') |
||
| 477 | { |
||
| 478 | $pTopic = Tdmcreate\Files\CreatePhpCode::getInstance(); |
||
| 479 | $ret = $pTopic->getPhpCodeCommentLine('Get Var', $fieldNameParent, $t); |
||
| 480 | $fieldParent = $this->getXcGetVar('', "\${$tableName}All[\$i]", $fieldNameParent, true, ''); |
||
| 481 | $ret .= $this->getXcGet($rpFieldName, $fieldParent, '', $tableNameTopic . 'Handler', false, $t); |
||
| 482 | $ret .= $this->getXcGetVar("\${$lpFieldName}['{$rpFieldName}']", "\${$rpFieldName}", $fieldNameTopic, false, $t); |
||
| 483 | |||
| 484 | return $ret; |
||
| 485 | } |
||
| 486 | |||
| 487 | /** |
||
| 488 | * @public function getXcParentTopicGetVar |
||
| 489 | * @param $moduleDirname |
||
| 490 | * @param $lpFieldName |
||
| 491 | * @param $rpFieldName |
||
| 492 | * @param $tableName |
||
| 493 | * @param $tableSoleNameTopic |
||
| 494 | * @param $tableNameTopic |
||
| 495 | * @param $fieldNameParent |
||
| 496 | * @param string $t |
||
| 497 | * @return string |
||
| 498 | */ |
||
| 499 | public function getXcParentTopicGetVar($moduleDirname, $lpFieldName, $rpFieldName, $tableName, $tableSoleNameTopic, $tableNameTopic, $fieldNameParent, $t = '') |
||
| 500 | { |
||
| 501 | $pParentTopic = Tdmcreate\Files\CreatePhpCode::getInstance(); |
||
| 502 | $parentTopic = $pParentTopic->getPhpCodeCommentLine('Get', $tableNameTopic . ' Handler', $t . "\t"); |
||
| 503 | $parentTopic .= $this->getXoopsHandlerLine($moduleDirname, $tableNameTopic, $t . "\t"); |
||
| 504 | $elseGroups = $this->getXcEqualsOperator('$groups', 'XOOPS_GROUP_ANONYMOUS'); |
||
| 505 | $ret = $pParentTopic->getPhpCodeConditions("!isset(\${$tableNameTopic}Handler", '', '', $parentTopic, $elseGroups); |
||
| 506 | $ret .= $this->getXcGetVarFromID("\${$lpFieldName}['{$rpFieldName}']", $tableNameTopic, $tableSoleNameTopic, $tableName, $fieldNameParent, $t); |
||
| 507 | |||
| 508 | return $ret; |
||
| 509 | } |
||
| 510 | |||
| 511 | /** |
||
| 512 | * @public function getXcGetVarFromID |
||
| 513 | * @param $left |
||
| 514 | * @param $anchor |
||
| 515 | * @param $var |
||
| 516 | * @param $tableName |
||
| 517 | * @param $fieldName |
||
| 518 | * @param string $t |
||
| 519 | * @return string |
||
| 520 | */ |
||
| 521 | public function getXcGetVarFromID($left, $anchor, $var, $tableName, $fieldName, $t = '') |
||
| 522 | { |
||
| 523 | $pVarFromID = Tdmcreate\Files\CreatePhpCode::getInstance(); |
||
| 524 | $ret = $pVarFromID->getPhpCodeCommentLine('Get Var', $fieldName, $t); |
||
| 525 | $getVarFromID = $this->getXcGetVar('', "\${$tableName}All[\$i]", $fieldName, true, ''); |
||
| 526 | $rightGet = $this->getXcAnchorFunction($anchor . 'Handler', 'get' . $var . 'FromId', $getVarFromID); |
||
| 527 | $ret .= $this->getXcEqualsOperator($left, $rightGet, null, false, $t); |
||
| 528 | |||
| 529 | return $ret; |
||
| 530 | } |
||
| 531 | |||
| 532 | /** |
||
| 533 | * @public function getXcUploadImageGetVar |
||
| 534 | * @param $lpFieldName |
||
| 535 | * @param $rpFieldName |
||
| 536 | * @param $tableName |
||
| 537 | * @param $fieldName |
||
| 538 | * @param string $t |
||
| 539 | * @return string |
||
| 540 | */ |
||
| 541 | public function getXcUploadImageGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '') |
||
| 542 | { |
||
| 543 | $pUploadImage = Tdmcreate\Files\CreatePhpCode::getInstance(); |
||
| 544 | $ret = $pUploadImage->getPhpCodeCommentLine('Get Var', $fieldName, $t); |
||
| 545 | $ret .= $this->getXcGetVar($fieldName, "\${$tableName}All[\$i]", $fieldName, false, ''); |
||
| 546 | $ret .= $pUploadImage->getPhpCodeTernaryOperator("{$lpFieldName}['{$rpFieldName}']", "\${$fieldName}", "\${$fieldName}", "'blank.gif'", $t); |
||
| 547 | |||
| 548 | return $ret; |
||
| 549 | } |
||
| 550 | |||
| 551 | /** |
||
| 552 | * @public function getXcUrlFileGetVar |
||
| 553 | * @param $lpFieldName |
||
| 554 | * @param $rpFieldName |
||
| 555 | * @param $tableName |
||
| 556 | * @param $fieldName |
||
| 557 | * @return string |
||
| 558 | */ |
||
| 559 | public function getXcUrlFileGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName) |
||
| 560 | { |
||
| 561 | return $this->getXcGetVarAll($lpFieldName, $rpFieldName, $tableName, $fieldName); |
||
| 562 | } |
||
| 563 | |||
| 564 | /** |
||
| 565 | * @public function getXcTextAreaGetVar |
||
| 566 | * @param $lpFieldName |
||
| 567 | * @param $rpFieldName |
||
| 568 | * @param $tableName |
||
| 569 | * @param $fieldName |
||
| 570 | * @param string $t |
||
| 571 | * @return string |
||
| 572 | */ |
||
| 573 | public function getXcTextAreaGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '') |
||
| 574 | { |
||
| 575 | $phpCodeTextArea = Tdmcreate\Files\CreatePhpCode::getInstance(); |
||
| 576 | $getVar = $this->getXcGetVar('', "\${$tableName}All[\$i]", $fieldName, true, ''); |
||
| 577 | |||
| 578 | return $t . $phpCodeTextArea->getPhpCodeStripTags("{$lpFieldName}['{$rpFieldName}']", $getVar, false, $t); |
||
| 579 | } |
||
| 580 | |||
| 581 | /** |
||
| 582 | * @public function getXcSelectUserGetVar |
||
| 583 | * @param $lpFieldName |
||
| 584 | * @param $rpFieldName |
||
| 585 | * @param $tableName |
||
| 586 | * @param $fieldName |
||
| 587 | * @param string $t |
||
| 588 | * @return string |
||
| 589 | */ |
||
| 590 | public function getXcSelectUserGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '') |
||
| 591 | { |
||
| 592 | return "{$t}\${$lpFieldName}['{$rpFieldName}'] = \XoopsUser::getUnameFromId(\${$tableName}All[\$i]->getVar('{$fieldName}'), 's');\n"; |
||
| 593 | } |
||
| 594 | |||
| 595 | /** |
||
| 596 | * @public function getXcTextDateSelectGetVar |
||
| 597 | * @param $lpFieldName |
||
| 598 | * @param $rpFieldName |
||
| 599 | * @param $tableName |
||
| 600 | * @param $fieldName |
||
| 601 | * @param string $t |
||
| 602 | * @return string |
||
| 603 | */ |
||
| 604 | public function getXcTextDateSelectGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '') |
||
| 605 | { |
||
| 606 | return "{$t}\${$lpFieldName}['{$rpFieldName}'] = formatTimeStamp(\${$tableName}All[\$i]->getVar('{$fieldName}'), 's');\n"; |
||
| 607 | } |
||
| 608 | |||
| 609 | /** |
||
| 610 | * @public function getXcUserHeader |
||
| 611 | * @param $moduleDirname |
||
| 612 | * @param $tableName |
||
| 613 | * @param string $t |
||
| 614 | * @return string |
||
| 615 | */ |
||
| 616 | public function getXcXoopsOptionTemplateMain($moduleDirname, $tableName, $t = '') |
||
| 617 | { |
||
| 618 | return "{$t}\$GLOBALS['xoopsOption']['template_main'] = '{$moduleDirname}_{$tableName}.tpl';\n"; |
||
| 619 | } |
||
| 620 | |||
| 621 | /** |
||
| 622 | * @public function getXcUserHeader |
||
| 623 | * @param $moduleDirname |
||
| 624 | * @param $tableName |
||
| 625 | * @return string |
||
| 626 | */ |
||
| 627 | public function getXcUserHeader($moduleDirname, $tableName) |
||
| 628 | { |
||
| 629 | $phpCodeUserHeader = Tdmcreate\Files\CreatePhpCode::getInstance(); |
||
| 630 | $ret = $phpCodeUserHeader->getPhpCodeIncludeDir('__DIR__', 'header'); |
||
| 631 | $ret .= $this->getXcXoopsOptionTemplateMain($moduleDirname, $tableName); |
||
| 632 | $ret .= $phpCodeUserHeader->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'header', true); |
||
| 633 | |||
| 634 | return $ret; |
||
| 635 | } |
||
| 636 | |||
| 637 | /** |
||
| 638 | * @public function getXcPermissionsHeader |
||
| 639 | * @param null |
||
| 640 | * @return string |
||
| 641 | */ |
||
| 642 | public function getXcPermissionsHeader() |
||
| 643 | { |
||
| 644 | $phpCodePHeader = Tdmcreate\Files\CreatePhpCode::getInstance(); |
||
| 645 | $ret = $phpCodePHeader->getPhpCodeCommentLine('Permission'); |
||
| 646 | $ret .= $phpCodePHeader->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/xoopsform/grouppermform', true); |
||
| 647 | $ret .= $this->getXcEqualsOperator('$gpermHandler', "xoops_getHandler('groupperm')", true); |
||
| 648 | $groups = $this->getXcEqualsOperator('$groups', '$xoopsUser->getGroups()'); |
||
| 649 | $elseGroups = $this->getXcEqualsOperator('$groups', 'XOOPS_GROUP_ANONYMOUS'); |
||
| 650 | $ret .= $phpCodePHeader->getPhpCodeConditions('is_object($xoopsUser)', '', $type = '', $groups, $elseGroups); |
||
| 651 | |||
| 652 | return $ret; |
||
| 653 | } |
||
| 654 | |||
| 655 | /** |
||
| 656 | * @public function getXcGetFieldId |
||
| 657 | * |
||
| 658 | * @param $fields |
||
| 659 | * |
||
| 660 | * @return string |
||
| 661 | */ |
||
| 662 | public function getXcGetFieldId($fields) |
||
| 663 | { |
||
| 664 | $fieldId = 'id'; |
||
| 665 | foreach (array_keys($fields) as $f) { |
||
| 666 | $fieldName = $fields[$f]->getVar('field_name'); |
||
| 667 | if (0 == $f) { |
||
| 668 | $fieldId = $fieldName; |
||
| 669 | } |
||
| 670 | } |
||
| 671 | |||
| 672 | return $fieldId; |
||
| 673 | } |
||
| 674 | |||
| 675 | /** |
||
| 676 | * @public function getXcGetFieldName |
||
| 677 | * |
||
| 678 | * @param $fields |
||
| 679 | * |
||
| 680 | * @return string |
||
| 681 | */ |
||
| 682 | public function getXcGetFieldName($fields) |
||
| 683 | { |
||
| 684 | $fieldName = ''; |
||
| 685 | foreach (array_keys($fields) as $f) { |
||
| 686 | $fieldName = $fields[$f]->getVar('field_name'); |
||
| 687 | } |
||
| 688 | |||
| 689 | return $fieldName; |
||
| 690 | } |
||
| 691 | |||
| 692 | /** |
||
| 693 | * @public function getXcGetFieldParentId |
||
| 694 | * |
||
| 695 | * @param $fields |
||
| 696 | * |
||
| 697 | * @return string |
||
| 698 | */ |
||
| 699 | public function getXcGetFieldParentId($fields) |
||
| 700 | { |
||
| 701 | $fieldPid = 'pid'; |
||
| 702 | foreach (array_keys($fields) as $f) { |
||
| 703 | $fieldName = $fields[$f]->getVar('field_name'); |
||
| 704 | if (1 == $fields[$f]->getVar('field_parent')) { |
||
| 705 | $fieldPid = $fieldName; |
||
| 706 | } |
||
| 707 | } |
||
| 708 | |||
| 709 | return $fieldPid; |
||
| 710 | } |
||
| 711 | |||
| 712 | /** |
||
| 713 | * @public function getXcUserSaveElements |
||
| 714 | * |
||
| 715 | * @param $moduleDirname |
||
| 716 | * @param $tableName |
||
| 717 | * @param $tableSoleName |
||
| 718 | * @param $fields |
||
| 719 | * @return string |
||
| 720 | */ |
||
| 721 | public function getXcUserSaveElements($moduleDirname, $tableName, $tableSoleName, $fields) |
||
| 722 | { |
||
| 723 | $axCodeUserSave = Tdmcreate\Files\Admin\AdminXoopsCode::getInstance(); |
||
| 724 | $ret = ''; |
||
| 725 | $fieldMain = ''; |
||
| 726 | foreach (array_keys($fields) as $f) { |
||
| 727 | $fieldName = $fields[$f]->getVar('field_name'); |
||
| 728 | $fieldElement = $fields[$f]->getVar('field_element'); |
||
| 729 | if (1 == $fields[$f]->getVar('field_main')) { |
||
| 730 | $fieldMain = $fieldName; |
||
| 731 | } |
||
| 732 | if ((5 == $fieldElement) || (6 == $fieldElement)) { |
||
| 733 | $ret .= $this->getXcCheckBoxOrRadioYNSetVar($tableName, $fieldName); |
||
| 734 | } elseif (13 == $fieldElement) { |
||
| 735 | $ret .= $axCodeUserSave->getAxcUploadImageSetVar($moduleDirname, $tableName, $fieldName, $fieldMain); |
||
| 736 | } elseif (14 == $fieldElement) { |
||
| 737 | $ret .= $axCodeUserSave->getXcUploadFileSetVar($moduleDirname, $tableName, $fieldName); |
||
| 738 | } elseif (15 == $fieldElement) { |
||
| 739 | $ret .= $this->getXcTextDateSelectSetVar($tableName, $tableSoleName, $fieldName); |
||
| 740 | } else { |
||
| 741 | $ret .= $this->getXcSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']"); |
||
| 742 | } |
||
| 743 | } |
||
| 744 | |||
| 745 | return $ret; |
||
| 746 | } |
||
| 747 | |||
| 748 | /** |
||
| 749 | * @public function getXcXoopsRequest |
||
| 750 | * @param string $left |
||
| 751 | * @param string $var1 |
||
| 752 | * @param string $var2 |
||
| 753 | * @param string $type |
||
| 754 | * @param bool $metod |
||
| 755 | * @param string $t |
||
| 756 | * @return string |
||
| 757 | */ |
||
| 758 | public function getXcXoopsRequest($left = '', $var1 = '', $var2 = '', $type = 'String', $metod = false, $t = '') |
||
| 759 | { |
||
| 760 | $ret = ''; |
||
| 761 | $intVars = ('' != $var2) ? "'{$var1}', {$var2}" : "'{$var1}'"; |
||
| 762 | if ('String' === $type) { |
||
| 763 | $ret .= "{$t}\${$left} = \Xmf\Request::getString('{$var1}', '{$var2}');\n"; |
||
| 764 | } elseif ('Int' === $type) { |
||
| 765 | $ret .= "{$t}\${$left} = \Xmf\Request::getInt({$intVars});\n"; |
||
| 766 | } elseif ('Int' === $type && false !== $metod) { |
||
| 767 | $ret .= "{$t}\${$left} = \Xmf\Request::getInt({$intVars}, '{$metod}');\n"; |
||
| 768 | } |
||
| 769 | |||
| 770 | return $ret; |
||
| 771 | } |
||
| 772 | |||
| 773 | /** |
||
| 774 | * @public function getXcTplAssign |
||
| 775 | * |
||
| 776 | * @param $tplString |
||
| 777 | * @param $phpRender |
||
| 778 | * @param bool $leftIsString |
||
| 779 | * |
||
| 780 | * @param string $t |
||
| 781 | * @return string |
||
| 782 | */ |
||
| 783 | public function getXcTplAssign($tplString, $phpRender, $leftIsString = true, $t = '') |
||
| 784 | { |
||
| 785 | $assign = "{$t}\$GLOBALS['xoopsTpl']->assign("; |
||
| 786 | if (false === $leftIsString) { |
||
| 787 | $ret = $assign . "{$tplString}, {$phpRender});\n"; |
||
| 788 | } else { |
||
| 789 | $ret = $assign . "'{$tplString}', {$phpRender});\n"; |
||
| 790 | } |
||
| 791 | |||
| 792 | return $ret; |
||
| 793 | } |
||
| 794 | |||
| 795 | /** |
||
| 796 | * @public function getXcXoopsTplAppend |
||
| 797 | * |
||
| 798 | * @param $tplString |
||
| 799 | * @param $phpRender |
||
| 800 | * |
||
| 801 | * @param string $t |
||
| 802 | * @return string |
||
| 803 | */ |
||
| 804 | public function getXcXoopsTplAppend($tplString, $phpRender, $t = '') |
||
| 805 | { |
||
| 806 | return "{$t}\$GLOBALS['xoopsTpl']->append('{$tplString}', {$phpRender});\n"; |
||
| 807 | } |
||
| 808 | |||
| 809 | /** |
||
| 810 | * @public function getXcXoopsTplAppendByRef |
||
| 811 | * |
||
| 812 | * @param $tplString |
||
| 813 | * @param $phpRender |
||
| 814 | * |
||
| 815 | * @param string $t |
||
| 816 | * @return string |
||
| 817 | */ |
||
| 818 | public function getXcXoopsTplAppendByRef($tplString, $phpRender, $t = '') |
||
| 819 | { |
||
| 820 | return "{$t}\$GLOBALS['xoopsTpl']->appendByRef('{$tplString}', {$phpRender});\n"; |
||
| 821 | } |
||
| 822 | |||
| 823 | /** |
||
| 824 | * @public function getXcPath |
||
| 825 | * |
||
| 826 | * @param $directory |
||
| 827 | * @param $filename |
||
| 828 | * @param bool $isParam |
||
| 829 | * |
||
| 830 | * @param string $t |
||
| 831 | * @return string |
||
| 832 | */ |
||
| 833 | public function getXcPath($directory, $filename, $isParam = false, $t = '') |
||
| 834 | { |
||
| 835 | if (!$isParam) { |
||
| 836 | $ret = "{$t}\$GLOBALS['xoops']->path({$directory}.'/{$filename}.php');\n"; |
||
| 837 | } else { |
||
| 838 | $ret = "\$GLOBALS['xoops']->path({$directory}.'/{$filename}.php')"; |
||
| 839 | } |
||
| 840 | |||
| 841 | return $ret; |
||
| 842 | } |
||
| 843 | |||
| 844 | /** |
||
| 845 | * @public function getXcTplDisplay |
||
| 846 | * |
||
| 847 | * @param string $displayTpl |
||
| 848 | * @param string $t |
||
| 849 | * @param bool $usedoublequotes |
||
| 850 | * @return string |
||
| 851 | */ |
||
| 852 | public function getXcTplDisplay($displayTpl = '{$templateMain}', $t = '', $usedoublequotes = true) |
||
| 853 | { |
||
| 854 | if ($usedoublequotes) { |
||
| 855 | return "{$t}\$GLOBALS['xoopsTpl']->display(\"db:{$displayTpl}\");\n"; |
||
| 856 | } |
||
| 857 | |||
| 858 | return "{$t}\$GLOBALS['xoopsTpl']->display('db:" . $displayTpl . "');\n"; |
||
| 859 | } |
||
| 860 | |||
| 861 | /** |
||
| 862 | * @public function getXcGetInfo |
||
| 863 | * |
||
| 864 | * @param $left |
||
| 865 | * @param $string |
||
| 866 | * @param bool $isParam |
||
| 867 | * |
||
| 868 | * @param string $t |
||
| 869 | * @return string |
||
| 870 | */ |
||
| 871 | public function getXcGetInfo($left, $string, $isParam = false, $t = '') |
||
| 872 | { |
||
| 873 | if (!$isParam) { |
||
| 874 | $ret = "{$t}\${$left} = \$GLOBALS['xoopsModule']->getInfo('{$string}');\n"; |
||
| 875 | } else { |
||
| 876 | $ret = "\$GLOBALS['xoopsModule']->getInfo('{$string}')"; |
||
| 877 | } |
||
| 878 | |||
| 879 | return $ret; |
||
| 880 | } |
||
| 881 | |||
| 882 | /** |
||
| 883 | * @public function getXcAddRight |
||
| 884 | * |
||
| 885 | * @param $anchor |
||
| 886 | * @param string $permString |
||
| 887 | * @param string $var |
||
| 888 | * @param string $groups |
||
| 889 | * @param string $mid |
||
| 890 | * @param bool $isParam |
||
| 891 | * |
||
| 892 | * @param string $t |
||
| 893 | * @return string |
||
| 894 | */ |
||
| 895 | public function getXcAddRight($anchor, $permString = '', $var = '', $groups = '', $mid = '', $isParam = false, $t = '') |
||
| 896 | { |
||
| 897 | if (!$isParam) { |
||
| 898 | $ret = "{$t}\${$anchor}->addRight('{$permString}', {$var}, {$groups}, {$mid});\n"; |
||
| 899 | } else { |
||
| 900 | $ret = "\${$anchor}->addRight('{$permString}', {$var}, {$groups}, {$mid})"; |
||
| 901 | } |
||
| 902 | |||
| 903 | return $ret; |
||
| 904 | } |
||
| 905 | |||
| 906 | /** |
||
| 907 | * @public function getXcCheckRight |
||
| 908 | * |
||
| 909 | * @param $anchor |
||
| 910 | * @param string $permString |
||
| 911 | * @param string $var |
||
| 912 | * @param string $groups |
||
| 913 | * @param string $mid |
||
| 914 | * @param bool $isParam |
||
| 915 | * |
||
| 916 | * @param string $t |
||
| 917 | * @return string |
||
| 918 | */ |
||
| 919 | public function getXcCheckRight($anchor, $permString = '', $var = '', $groups = '', $mid = '', $isParam = false, $t = '') |
||
| 920 | { |
||
| 921 | if (!$isParam) { |
||
| 922 | $ret = "{$t}{$anchor}->checkRight('{$permString}', {$var}, {$groups}, {$mid});\n"; |
||
| 923 | } else { |
||
| 924 | $ret = "{$anchor}->checkRight('{$permString}', {$var}, {$groups}, {$mid})"; |
||
| 925 | } |
||
| 926 | |||
| 927 | return $ret; |
||
| 928 | } |
||
| 929 | |||
| 930 | /** |
||
| 931 | * @public function getXcObjHandlerCreate |
||
| 932 | * |
||
| 933 | * @param $tableName |
||
| 934 | * |
||
| 935 | * @param string $t |
||
| 936 | * @return string |
||
| 937 | */ |
||
| 938 | public function getXcObjHandlerCreate($tableName, $t = '') |
||
| 939 | { |
||
| 940 | return "{$t}\${$tableName}Obj = \${$tableName}Handler->create();\n"; |
||
| 941 | } |
||
| 942 | |||
| 943 | /** |
||
| 944 | * @public function getXcObjHandlerCount |
||
| 945 | * |
||
| 946 | * @param $tableName |
||
| 947 | * |
||
| 948 | * @param string $t |
||
| 949 | * @return string |
||
| 950 | */ |
||
| 951 | public function getXcObjHandlerCount($tableName, $t = '') |
||
| 952 | { |
||
| 953 | $ucfTableName = ucfirst($tableName); |
||
| 954 | $ret = "{$t}\${$tableName}Count = \${$tableName}Handler->getCount{$ucfTableName}();\n"; |
||
| 955 | |||
| 956 | return $ret; |
||
| 957 | } |
||
| 958 | |||
| 959 | /** |
||
| 960 | * @public function getXcClearCount |
||
| 961 | * @param $left |
||
| 962 | * @param $anchor |
||
| 963 | * @param $params |
||
| 964 | * @param $t |
||
| 965 | * |
||
| 966 | * @return string |
||
| 967 | */ |
||
| 968 | public function getXcClearHandlerCount($left, $anchor = '', $params = '', $t = '') |
||
| 969 | { |
||
| 970 | $ret = "{$t}\${$left} = \${$anchor}Handler->getCount({$params});\n"; |
||
| 971 | |||
| 972 | return $ret; |
||
| 973 | } |
||
| 974 | |||
| 975 | /** |
||
| 976 | * @public function getXcObjHandlerAll |
||
| 977 | * |
||
| 978 | * @param $tableName |
||
| 979 | * @param string $fieldMain |
||
| 980 | * @param string $start |
||
| 981 | * @param string $limit |
||
| 982 | * |
||
| 983 | * @param string $t |
||
| 984 | * @return string |
||
| 985 | */ |
||
| 986 | public function getXcObjHandlerAll($tableName, $fieldMain = '', $start = '0', $limit = '0', $t = '') |
||
| 987 | { |
||
| 988 | $ucfTableName = ucfirst($tableName); |
||
| 989 | $startLimit = ('0' != $limit) ? "{$start}, {$limit}" : '0'; |
||
| 990 | $params = ('' != $fieldMain) ? "{$startLimit}, '{$fieldMain}'" : $startLimit; |
||
| 991 | $ret = "{$t}\${$tableName}All = \${$tableName}Handler->getAll{$ucfTableName}({$params});\n"; |
||
| 992 | |||
| 993 | return $ret; |
||
| 994 | } |
||
| 995 | |||
| 996 | /** |
||
| 997 | * @public function getXcClearHandlerAll |
||
| 998 | * @param $left |
||
| 999 | * @param string $anchor |
||
| 1000 | * @param string $params |
||
| 1001 | * @param string $t |
||
| 1002 | * @return string |
||
| 1003 | */ |
||
| 1004 | public function getXcClearHandlerAll($left, $anchor = '', $params = '', $t = '') |
||
| 1005 | { |
||
| 1006 | $ret = "{$t}\${$left} = \${$anchor}Handler->getAll({$params});\n"; |
||
| 1007 | |||
| 1008 | return $ret; |
||
| 1009 | } |
||
| 1010 | |||
| 1011 | /** |
||
| 1012 | * @public function getXcGetValues |
||
| 1013 | * |
||
| 1014 | * @param $tableName |
||
| 1015 | * @param $tableSoleName |
||
| 1016 | * |
||
| 1017 | * @param string $index |
||
| 1018 | * @param bool $noArray |
||
| 1019 | * @param string $t |
||
| 1020 | * @return string |
||
| 1021 | */ |
||
| 1022 | public function getXcGetValues($tableName, $tableSoleName, $index = 'i', $noArray = false, $t = '') |
||
| 1023 | { |
||
| 1024 | $index = '' !== $index ? $index : 'i'; |
||
| 1025 | $ucfTableName = ucfirst($tableName); |
||
| 1026 | if (!$noArray) { |
||
| 1027 | $ret = "{$t}\${$tableSoleName} = \${$tableName}All[\${$index}]->getValues{$ucfTableName}();\n"; |
||
| 1028 | } else { |
||
| 1029 | $ret = "{$t}\${$tableSoleName} = \${$tableName}->getValues{$ucfTableName}();\n"; |
||
| 1030 | } |
||
| 1031 | |||
| 1032 | return $ret; |
||
| 1033 | } |
||
| 1034 | |||
| 1035 | /** |
||
| 1036 | * @public function getXcSetVarsObjects |
||
| 1037 | * |
||
| 1038 | * @param $moduleDirname |
||
| 1039 | * @param $tableName |
||
| 1040 | * @param $tableSoleName |
||
| 1041 | * @param $fields |
||
| 1042 | * @return string |
||
| 1043 | */ |
||
| 1044 | public function getXcSetVarsObjects($moduleDirname, $tableName, $tableSoleName, $fields) |
||
| 1045 | { |
||
| 1046 | $axCode = Tdmcreate\Files\Admin\AdminXoopsCode::getInstance(); |
||
| 1047 | $ret = ''; |
||
| 1048 | $fieldMain = ''; |
||
| 1049 | foreach (array_keys($fields) as $f) { |
||
| 1050 | $fieldName = $fields[$f]->getVar('field_name'); |
||
| 1051 | $fieldElement = $fields[$f]->getVar('field_element'); |
||
| 1052 | if (1 == $fields[$f]->getVar('field_main')) { |
||
| 1053 | $fieldMain = $fieldName; |
||
| 1054 | } |
||
| 1055 | if ($f > 0) { // If we want to hide field id |
||
| 1056 | switch ($fieldElement) { |
||
| 1057 | case 5: |
||
| 1058 | case 6: |
||
| 1059 | $ret .= $this->getXcCheckBoxOrRadioYNSetVar($tableName, $fieldName); |
||
| 1060 | break; |
||
| 1061 | case 11: |
||
| 1062 | $ret .= $axCode->getAxcImageListSetVar($moduleDirname, $tableName, $fieldName); |
||
| 1063 | break; |
||
| 1064 | case 12: |
||
| 1065 | $ret .= $axCode->getAxcUploadFileSetVar($moduleDirname, $tableName, $fieldName, true); |
||
| 1066 | break; |
||
| 1067 | case 13: |
||
| 1068 | $ret .= $axCode->getAxcUploadImageSetVar($moduleDirname, $tableName, $fieldName, $fieldMain); |
||
| 1069 | break; |
||
| 1070 | case 14: |
||
| 1071 | $ret .= $axCode->getAxcUploadFileSetVar($moduleDirname, $tableName, $fieldName); |
||
| 1072 | break; |
||
| 1073 | case 15: |
||
| 1074 | $ret .= $this->getXcTextDateSelectSetVar($tableName, $tableSoleName, $fieldName); |
||
| 1075 | break; |
||
| 1076 | default: |
||
| 1077 | $ret .= $this->getXcSetVar($tableName, $fieldName, "\$_POST['{$fieldName}']"); |
||
| 1078 | break; |
||
| 1079 | } |
||
| 1080 | } |
||
| 1081 | } |
||
| 1082 | |||
| 1083 | return $ret; |
||
| 1084 | } |
||
| 1085 | |||
| 1086 | /** |
||
| 1087 | * @public function getXcSecurity |
||
| 1088 | * |
||
| 1089 | * @param $tableName |
||
| 1090 | * |
||
| 1091 | * @param string $t |
||
| 1092 | * @return string |
||
| 1093 | */ |
||
| 1094 | public function getXcSecurity($tableName, $t = '') |
||
| 1095 | { |
||
| 1096 | $phpCodeSecurity = Tdmcreate\Files\CreatePhpCode::getInstance(); |
||
| 1097 | $securityError = $this->getXcSecurityErrors(); |
||
| 1098 | $implode = $phpCodeSecurity->getPhpCodeImplode(',', $securityError); |
||
| 1099 | $content = "{$t}\t" . $this->getXcRedirectHeader($tableName, '', 3, $implode, $t); |
||
| 1100 | $securityCheck = $this->getXcSecurityCheck(); |
||
| 1101 | |||
| 1102 | return $phpCodeSecurity->getPhpCodeConditions('!' . $securityCheck, '', '', $content, $t); |
||
| 1103 | } |
||
| 1104 | |||
| 1105 | /** |
||
| 1106 | * @public function getXcInsertData |
||
| 1107 | * @param $tableName |
||
| 1108 | * @param $language |
||
| 1109 | * @param string $t |
||
| 1110 | * @return string |
||
| 1111 | */ |
||
| 1112 | public function getXcInsertData($tableName, $language, $t = '') |
||
| 1113 | { |
||
| 1114 | $phpCodeInsertData = Tdmcreate\Files\CreatePhpCode::getInstance(); |
||
| 1115 | $content = "{$t}\t" . $this->getXcRedirectHeader($tableName, '?op=list', 2, "{$language}FORM_OK"); |
||
| 1116 | $handlerInsert = $this->getXcHandler($tableName, $tableName, false, true, false, 'Obj'); |
||
| 1117 | |||
| 1118 | return $phpCodeInsertData->getPhpCodeConditions($handlerInsert, '', '', $content, $t); |
||
| 1119 | } |
||
| 1120 | |||
| 1121 | /** |
||
| 1122 | * @public function getXcRedirectHeader |
||
| 1123 | * @param $directory |
||
| 1124 | * @param $options |
||
| 1125 | * @param $numb |
||
| 1126 | * @param $var |
||
| 1127 | * @param bool $isString |
||
| 1128 | * |
||
| 1129 | * @param string $t |
||
| 1130 | * @return string |
||
| 1131 | */ |
||
| 1132 | public function getXcRedirectHeader($directory, $options, $numb, $var, $isString = true, $t = '') |
||
| 1133 | { |
||
| 1134 | $ret = ''; |
||
| 1135 | if (!$isString) { |
||
| 1136 | $ret = "{$t}redirect_header({$directory}, {$numb}, {$var});\n"; |
||
| 1137 | } else { |
||
| 1138 | $ret = "{$t}redirect_header('{$directory}.php{$options}', {$numb}, {$var});\n"; |
||
| 1139 | } |
||
| 1140 | |||
| 1141 | return $ret; |
||
| 1142 | } |
||
| 1143 | |||
| 1144 | /** |
||
| 1145 | * @public function getXcXoopsConfirm |
||
| 1146 | * @param $tableName |
||
| 1147 | * @param $language |
||
| 1148 | * @param $fieldId |
||
| 1149 | * @param $fieldMain |
||
| 1150 | * @param string $options |
||
| 1151 | * |
||
| 1152 | * @param string $t |
||
| 1153 | * @return string |
||
| 1154 | */ |
||
| 1155 | public function getXcXoopsConfirm($tableName, $language, $fieldId, $fieldMain, $options = 'delete', $t = '') |
||
| 1156 | { |
||
| 1157 | $stuOptions = mb_strtoupper($options); |
||
| 1158 | $ccFieldId = Tdmcreate\Files\CreateFile::getInstance()->getCamelCase($fieldId, false, true); |
||
| 1159 | $phpXoopsConfirm = Tdmcreate\Files\CreatePhpCode::getInstance(); |
||
| 1160 | $array = "array('ok' => 1, '{$fieldId}' => \${$ccFieldId}, 'op' => '{$options}')"; |
||
| 1161 | $server = $phpXoopsConfirm->getPhpCodeGlobalsVariables('REQUEST_URI', 'SERVER'); |
||
| 1162 | $getVar = $this->getXcGetVar('', $tableName . 'Obj', $fieldMain, true, ''); |
||
| 1163 | $sprintf = $phpXoopsConfirm->getPhpCodeSprintf($language . 'FORM_SURE_' . $stuOptions, $getVar); |
||
| 1164 | $ret = "{$t}xoops_confirm({$array}, {$server}, {$sprintf});\n"; |
||
| 1165 | |||
| 1166 | return $ret; |
||
| 1167 | } |
||
| 1168 | |||
| 1169 | /** |
||
| 1170 | * @public function getXcAddStylesheet |
||
| 1171 | * @param string $style |
||
| 1172 | * |
||
| 1173 | * @param string $t |
||
| 1174 | * @return string |
||
| 1175 | */ |
||
| 1176 | public function getXcAddStylesheet($style = 'style', $t = '') |
||
| 1177 | { |
||
| 1178 | return "{$t}\$GLOBALS['xoTheme']->addStylesheet( \${$style}, null );\n"; |
||
| 1179 | } |
||
| 1180 | |||
| 1181 | /** |
||
| 1182 | * @public function getXcSecurityCheck |
||
| 1183 | * @param $denial |
||
| 1184 | * @return bool |
||
| 1185 | */ |
||
| 1186 | public function getXcSecurityCheck($denial = '') |
||
| 1187 | { |
||
| 1188 | return "{$denial}\$GLOBALS['xoopsSecurity']->check()"; |
||
| 1189 | } |
||
| 1190 | |||
| 1191 | /** |
||
| 1192 | * @public function getXcSecurityErrors |
||
| 1193 | * @param null |
||
| 1194 | * @return string |
||
| 1195 | */ |
||
| 1196 | public function getXcSecurityErrors() |
||
| 1197 | { |
||
| 1198 | return "\$GLOBALS['xoopsSecurity']->getErrors()"; |
||
| 1199 | } |
||
| 1200 | |||
| 1201 | /** |
||
| 1202 | * @public function getXcHtmlErrors |
||
| 1203 | * |
||
| 1204 | * @param $tableName |
||
| 1205 | * @param bool $isParam |
||
| 1206 | * @param string $obj |
||
| 1207 | * |
||
| 1208 | * @param string $t |
||
| 1209 | * @return string |
||
| 1210 | */ |
||
| 1211 | public function getXcHtmlErrors($tableName, $isParam = false, $obj = 'Obj', $t = '') |
||
| 1212 | { |
||
| 1213 | $ret = ''; |
||
| 1214 | if ($isParam) { |
||
| 1215 | $ret = "\${$tableName}{$obj}->getHtmlErrors()"; |
||
| 1216 | } else { |
||
| 1217 | $ret = "{$t}\${$tableName}{$obj} = \${$tableName}->getHtmlErrors();"; |
||
| 1218 | } |
||
| 1219 | |||
| 1220 | return $ret; |
||
| 1221 | } |
||
| 1222 | |||
| 1223 | /** |
||
| 1224 | * @public function getXcObjHandlerCount |
||
| 1225 | * |
||
| 1226 | * @param $left |
||
| 1227 | * @param $tableName |
||
| 1228 | * @param string $obj |
||
| 1229 | * |
||
| 1230 | * @param string $t |
||
| 1231 | * @return string |
||
| 1232 | */ |
||
| 1233 | public function getXcGetForm($left, $tableName, $obj = '', $t = '') |
||
| 1234 | { |
||
| 1235 | $ucfTableName = ucfirst($tableName); |
||
| 1236 | |||
| 1237 | return "{$t}\${$left} = \${$tableName}{$obj}->getForm{$ucfTableName}();\n"; |
||
| 1238 | } |
||
| 1239 | |||
| 1240 | /** |
||
| 1241 | * @public function getXcGet |
||
| 1242 | * |
||
| 1243 | * @param $left |
||
| 1244 | * @param $var |
||
| 1245 | * @param string $obj |
||
| 1246 | * @param string $handler |
||
| 1247 | * @param bool $isParam |
||
| 1248 | * |
||
| 1249 | * @param string $t |
||
| 1250 | * @return string |
||
| 1251 | */ |
||
| 1252 | public function getXcGet($left, $var, $obj = '', $handler = 'Handler', $isParam = false, $t = '') |
||
| 1253 | { |
||
| 1254 | $ret = ''; |
||
| 1255 | if ($isParam) { |
||
| 1256 | $ret = "\${$left}{$handler}->get(\${$var})"; |
||
| 1257 | } else { |
||
| 1258 | $ret = "{$t}\${$left}{$obj} = \${$handler}->get(\${$var});\n"; |
||
| 1259 | } |
||
| 1260 | |||
| 1261 | return $ret; |
||
| 1262 | } |
||
| 1263 | |||
| 1264 | /** |
||
| 1265 | * @public function getXcHandler |
||
| 1266 | * |
||
| 1267 | * @param $left |
||
| 1268 | * @param $var |
||
| 1269 | * @param $obj |
||
| 1270 | * @param $handler |
||
| 1271 | * |
||
| 1272 | * @return string |
||
| 1273 | */ |
||
| 1274 | public function getXcInsert($left, $var, $obj = '', $handler = 'Handler') |
||
| 1275 | { |
||
| 1276 | return "\${$left}{$handler}->insert(\${$var}{$obj})"; |
||
| 1277 | } |
||
| 1278 | |||
| 1279 | /** |
||
| 1280 | * @public function getXcDelete |
||
| 1281 | * |
||
| 1282 | * @param $left |
||
| 1283 | * @param $var |
||
| 1284 | * @param string $obj |
||
| 1285 | * @param string $handler |
||
| 1286 | * @return string |
||
| 1287 | */ |
||
| 1288 | public function getXcDelete($left, $var, $obj = '', $handler = 'Handler') |
||
| 1289 | { |
||
| 1290 | return "\${$left}{$handler}->delete(\${$var}{$obj})"; |
||
| 1291 | } |
||
| 1292 | |||
| 1293 | /** |
||
| 1294 | * @public function getXcHandler |
||
| 1295 | * |
||
| 1296 | * @param $left |
||
| 1297 | * @param $var |
||
| 1298 | * |
||
| 1299 | * @param bool $get |
||
| 1300 | * @param bool $insert |
||
| 1301 | * @param bool $delete |
||
| 1302 | * @param string $obj |
||
| 1303 | * @param string $t |
||
| 1304 | * @return string |
||
| 1305 | */ |
||
| 1306 | public function getXcHandler($left, $var, $get = false, $insert = false, $delete = false, $obj = '', $t = '') |
||
| 1307 | { |
||
| 1308 | $ret = ''; |
||
| 1309 | if ($get) { |
||
| 1310 | $ret = "{$t}\${$left}Handler->get(\${$var});"; |
||
| 1311 | } elseif ($insert && ('' != $obj)) { |
||
| 1312 | $ret = "{$t}\${$left}Handler->insert(\${$var}{$obj});"; |
||
| 1313 | } elseif ($delete && ('' != $obj)) { |
||
| 1314 | $ret = "{$t}\${$left}Handler->delete(\${$var}{$obj});"; |
||
| 1315 | } |
||
| 1316 | |||
| 1317 | return $ret; |
||
| 1318 | } |
||
| 1319 | |||
| 1320 | /** |
||
| 1321 | * @public function getTopicGetVar |
||
| 1322 | * @param $lpFieldName |
||
| 1323 | * @param $rpFieldName |
||
| 1324 | * @param $tableName |
||
| 1325 | * @param $tableNameTopic |
||
| 1326 | * @param $fieldNameParent |
||
| 1327 | * @param $fieldNameTopic |
||
| 1328 | * @param string $t |
||
| 1329 | * @return string |
||
| 1330 | */ |
||
| 1331 | public function getTopicGetVar($lpFieldName, $rpFieldName, $tableName, $tableNameTopic, $fieldNameParent, $fieldNameTopic, $t = '') |
||
| 1332 | { |
||
| 1333 | $ret = Tdmcreate\Files\CreatePhpCode::getInstance()->getPhpCodeCommentLine('Get Var', $fieldNameParent, $t); |
||
| 1334 | $paramGet = $this->getXcGetVar('', "\${$tableName}All[\$i]", $fieldNameParent, true, ''); |
||
| 1335 | $ret .= $this->getXcGet($rpFieldName, $paramGet, '', $tableNameTopic . 'Handler', false, $t); |
||
| 1336 | $ret .= $this->getXcGetVar("\${$lpFieldName}['{$rpFieldName}']", "\${$rpFieldName}", $fieldNameTopic, false, $t); |
||
| 1337 | |||
| 1338 | return $ret; |
||
| 1339 | } |
||
| 1340 | |||
| 1341 | /** |
||
| 1342 | * @public function getUploadImageGetVar |
||
| 1343 | * @param $lpFieldName |
||
| 1344 | * @param $rpFieldName |
||
| 1345 | * @param $tableName |
||
| 1346 | * @param $fieldName |
||
| 1347 | * @param string $t |
||
| 1348 | * @return string |
||
| 1349 | */ |
||
| 1350 | public function getUploadImageGetVar($lpFieldName, $rpFieldName, $tableName, $fieldName, $t = '') |
||
| 1351 | { |
||
| 1352 | $pImageGetVar = Tdmcreate\Files\CreatePhpCode::getInstance(); |
||
| 1353 | $ret = $pImageGetVar->getPhpCodeCommentLine('Get Var', $fieldName, $t); |
||
| 1354 | $ret .= $this->getXcGetVar($fieldName, "\${$tableName}All[\$i]", $fieldName, false, ''); |
||
| 1355 | $ret .= $pImageGetVar->getPhpCodeTernaryOperator('uploadImage', "\${$fieldName}", "\${$fieldName}", "'blank.gif'", $t); |
||
| 1356 | $ret .= $this->getXcEqualsOperator("${$lpFieldName}['{$rpFieldName}']", '$uploadImage', null, false, $t); |
||
| 1357 | |||
| 1358 | return $ret; |
||
| 1359 | } |
||
| 1360 | |||
| 1361 | /** |
||
| 1362 | * @public function getXcSaveFieldId |
||
| 1363 | * |
||
| 1364 | * @param $fields |
||
| 1365 | * |
||
| 1366 | * @return string |
||
| 1367 | */ |
||
| 1368 | public function getXcSaveFieldId($fields) |
||
| 1378 | } |
||
| 1379 | |||
| 1380 | /** |
||
| 1381 | * @public function getXcSaveFieldMain |
||
| 1382 | * |
||
| 1383 | * @param $fields |
||
| 1384 | * |
||
| 1385 | * @return string |
||
| 1386 | */ |
||
| 1387 | public function getXcSaveFieldMain($fields) |
||
| 1397 | } |
||
| 1398 | |||
| 1399 | /** |
||
| 1400 | * @public function getXcSaveElements |
||
| 1401 | * |
||
| 1402 | * @param $moduleDirname |
||
| 1403 | * @param $tableName |
||
| 1404 | * @param $tableSoleName |
||
| 1405 | * @param $tableAutoincrement |
||
| 1406 | * @param $fields |
||
| 1407 | * |
||
| 1408 | * @param string $t |
||
| 1409 | * @return string |
||
| 1410 | */ |
||
| 1411 | public function getXcSaveElements($moduleDirname, $tableName, $tableSoleName, $tableAutoincrement, $fields, $t = '') |
||
| 1440 | } |
||
| 1441 | |||
| 1442 | /** |
||
| 1443 | * @public function getXcPageNav |
||
| 1444 | * @param $tableName |
||
| 1445 | * |
||
| 1446 | * @param string $t |
||
| 1447 | * @return string |
||
| 1448 | */ |
||
| 1449 | public function getXcPageNav($tableName, $t = '') |
||
| 1450 | { |
||
| 1451 | $phpCodePageNav = Tdmcreate\Files\CreatePhpCode::getInstance(); |
||
| 1452 | $classXCode = Tdmcreate\Files\Classes\ClassXoopsCode::getInstance(); |
||
| 1453 | $ret = $phpCodePageNav->getPhpCodeCommentLine('Display Navigation', null, $t); |
||
| 1454 | $condition = $phpCodePageNav->getPhpCodeIncludeDir('XOOPS_ROOT_PATH', 'class/pagenav', true, false, 'include', $t . "\t"); |
||
| 1455 | $condition .= $classXCode->getClassXoopsPageNav('pagenav', $tableName . 'Count', 'limit', 'start', 'start', "'op=list&limit=' . \$limit", false, $t . "\t"); |
||
| 1456 | $condition .= $this->getXcTplAssign('pagenav', '$pagenav->renderNav(4)', true, $t . "\t"); |
||
| 1457 | $ret .= $phpCodePageNav->getPhpCodeConditions("\${$tableName}Count", ' > ', '$limit', $condition, false, $t); |
||
| 1458 | |||
| 1459 | return $ret; |
||
| 1460 | } |
||
| 1461 | } |
||
| 1462 |