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