| Total Complexity | 94 |
| Total Lines | 1169 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like UserXoopsVersion 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 UserXoopsVersion, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 32 | class UserXoopsVersion extends Files\CreateFile |
||
| 33 | { |
||
| 34 | /** |
||
| 35 | * @var array |
||
| 36 | */ |
||
| 37 | private $kw = []; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var mixed |
||
| 41 | */ |
||
| 42 | private $uxc = null; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var mixed |
||
| 46 | */ |
||
| 47 | private $xc = null; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var mixed |
||
| 51 | */ |
||
| 52 | private $pc = null; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @public function constructor |
||
| 56 | * @param null |
||
| 57 | */ |
||
| 58 | public function __construct() |
||
| 59 | { |
||
| 60 | parent::__construct(); |
||
| 61 | $this->xc = Modulebuilder\Files\CreateXoopsCode::getInstance(); |
||
| 62 | $this->pc = Modulebuilder\Files\CreatePhpCode::getInstance(); |
||
| 63 | $this->uxc = Modulebuilder\Files\User\UserXoopsCode::getInstance(); |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @static function getInstance |
||
| 68 | * @param null |
||
| 69 | * @return UserXoopsVersion |
||
| 70 | */ |
||
| 71 | public static function getInstance() |
||
| 72 | { |
||
| 73 | static $instance = false; |
||
| 74 | if (!$instance) { |
||
| 75 | $instance = new self(); |
||
| 76 | } |
||
| 77 | |||
| 78 | return $instance; |
||
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @public function write |
||
| 83 | * @param $module |
||
| 84 | * @param mixed $table |
||
| 85 | * @param mixed $tables |
||
| 86 | * @param $filename |
||
| 87 | */ |
||
| 88 | public function write($module, $table, $tables, $filename) |
||
| 89 | { |
||
| 90 | $this->setModule($module); |
||
| 91 | $this->setTable($table); |
||
| 92 | $this->setTables($tables); |
||
| 93 | $this->setFileName($filename); |
||
| 94 | foreach (array_keys($tables) as $t) { |
||
| 95 | $tableName = $tables[$t]->getVar('table_name'); |
||
| 96 | $this->setKeywords($tableName); |
||
| 97 | } |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @public function setKeywords |
||
| 102 | * @param mixed $keywords |
||
| 103 | */ |
||
| 104 | public function setKeywords($keywords) |
||
| 105 | { |
||
| 106 | if (is_array($keywords)) { |
||
| 107 | $this->kw = $keywords; |
||
| 108 | } else { |
||
| 109 | $this->kw[] = $keywords; |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @public function getKeywords |
||
| 115 | * @param null |
||
| 116 | * @return array |
||
| 117 | */ |
||
| 118 | public function getKeywords() |
||
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @private function getXoopsVersionHeader |
||
| 125 | * @param $module |
||
| 126 | * @param $language |
||
| 127 | * |
||
| 128 | * @return string |
||
| 129 | */ |
||
| 130 | private function getXoopsVersionHeader($module, $language) |
||
| 190 | } |
||
| 191 | |||
| 192 | /** |
||
| 193 | * @private function getXoopsVersionMySQL |
||
| 194 | * @param $moduleDirname |
||
| 195 | * @param $table |
||
| 196 | * @param $tables |
||
| 197 | * @return string |
||
| 198 | */ |
||
| 199 | private function getXoopsVersionMySQL($moduleDirname, $table, $tables) |
||
| 200 | { |
||
| 201 | $tableName = $table->getVar('table_name'); |
||
| 202 | $n = 1; |
||
| 203 | $ret = ''; |
||
| 204 | $items = []; |
||
| 205 | $tableRate = 0; |
||
| 206 | if (!empty($tableName)) { |
||
| 207 | $ret .= $this->getDashComment('Mysql'); |
||
| 208 | $description = "'sql/mysql.sql'"; |
||
| 209 | $ret .= $this->uxc->getUserModVersionText(2, $description, 'sqlfile', "'mysql'"); |
||
| 210 | $ret .= Modulebuilder\Files\CreatePhpCode::getInstance()->getPhpCodeCommentLine('Tables'); |
||
| 211 | |||
| 212 | foreach (array_keys($tables) as $t) { |
||
| 213 | $items[] = "'{$moduleDirname}_{$tables[$t]->getVar('table_name')}'"; |
||
| 214 | if (1 === (int)$tables[$t]->getVar('table_rate')) { |
||
| 215 | $tableRate = 1; |
||
| 216 | } |
||
| 217 | ++$n; |
||
| 218 | } |
||
| 219 | if (1 === $tableRate) { |
||
| 220 | $items[] = "'{$moduleDirname}_ratings'"; |
||
| 221 | ++$n; |
||
| 222 | } |
||
| 223 | $ret .= $this->uxc->getUserModVersionArray(11, $items, 'tables', $n); |
||
| 224 | unset($n); |
||
| 225 | } |
||
| 226 | |||
| 227 | return $ret; |
||
| 228 | } |
||
| 229 | |||
| 230 | /** |
||
| 231 | * @private function getXoopsVersionSearch |
||
| 232 | * @param $moduleDirname |
||
| 233 | * |
||
| 234 | * @return string |
||
| 235 | */ |
||
| 236 | private function getXoopsVersionSearch($moduleDirname) |
||
| 244 | } |
||
| 245 | |||
| 246 | /** |
||
| 247 | * @private function getXoopsVersionComments |
||
| 248 | * @param $moduleDirname |
||
| 249 | * |
||
| 250 | * @param $tables |
||
| 251 | * @return string |
||
| 252 | */ |
||
| 253 | private function getXoopsVersionComments($moduleDirname, $tables) |
||
| 254 | { |
||
| 255 | $tableName = ''; |
||
| 256 | $fieldId = ''; |
||
| 257 | foreach (array_keys($tables) as $t) { |
||
| 258 | if (1 == $tables[$t]->getVar('table_comments')) { |
||
| 259 | $tableName = $tables[$t]->getVar('table_name'); |
||
| 260 | $fields = $this->getTableFields($tables[$t]->getVar('table_mid'), $tables[$t]->getVar('table_id')); |
||
| 261 | foreach (array_keys($fields) as $f) { |
||
| 262 | $fieldName = $fields[$f]->getVar('field_name'); |
||
| 263 | if (0 == $f) { |
||
| 264 | $fieldId = $fieldName; |
||
| 265 | } |
||
| 266 | } |
||
| 267 | } |
||
| 268 | } |
||
| 269 | $ret = $this->getDashComment('Comments'); |
||
| 270 | $ret .= $this->uxc->getUserModVersionText(1, "1", 'hasComments'); |
||
| 271 | $ret .= $this->uxc->getUserModVersionText(2, "'{$tableName}.php'", 'comments', "'pageName'"); |
||
| 272 | $ret .= $this->uxc->getUserModVersionText(2, "'{$fieldId}'", 'comments', "'itemName'"); |
||
| 273 | $ret .= Modulebuilder\Files\CreatePhpCode::getInstance()->getPhpCodeCommentLine('Comment callback functions'); |
||
| 274 | $ret .= $this->uxc->getUserModVersionText(2, "'include/comment_functions.php'", 'comments', "'callbackFile'"); |
||
| 275 | $descriptions = ['approve' => "'{$moduleDirname}CommentsApprove'", 'update' => "'{$moduleDirname}CommentsUpdate'"]; |
||
| 276 | $ret .= $this->uxc->getUserModVersionArray(2, $descriptions, 'comments', "'callback'"); |
||
| 277 | |||
| 278 | return $ret; |
||
| 279 | } |
||
| 280 | |||
| 281 | /** |
||
| 282 | * @private function getXoopsVersionTemplatesAdminUser |
||
| 283 | * @param $moduleDirname |
||
| 284 | * @param $tables |
||
| 285 | * |
||
| 286 | * @param $admin |
||
| 287 | * @param $user |
||
| 288 | * @return string |
||
| 289 | */ |
||
| 290 | private function getXoopsVersionTemplatesAdminUser($moduleDirname, $tables, $admin, $user) |
||
| 291 | { |
||
| 292 | $ret = $this->getDashComment('Templates'); |
||
| 293 | $item = []; |
||
| 294 | if ($admin) { |
||
| 295 | $item[] = $this->pc->getPhpCodeCommentLine('Admin templates'); |
||
| 296 | $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'about', '', true); |
||
| 297 | $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'header', '', true); |
||
| 298 | $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'index', '', true); |
||
| 299 | $tablePermissions = []; |
||
| 300 | $tableBroken = []; |
||
| 301 | foreach (array_keys($tables) as $t) { |
||
| 302 | $tableName = $tables[$t]->getVar('table_name'); |
||
| 303 | $tablePermissions[] = $tables[$t]->getVar('table_permissions'); |
||
| 304 | $tableBroken[] = $tables[$t]->getVar('table_broken'); |
||
| 305 | $item[] .= $this->getXoopsVersionTemplatesLine($moduleDirname, $tableName, '', true); |
||
| 306 | } |
||
| 307 | if (in_array(1, $tableBroken)) { |
||
| 308 | $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'broken', '', true); |
||
| 309 | } |
||
| 310 | if (in_array(1, $tablePermissions)) { |
||
| 311 | $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'permissions', '', true); |
||
| 312 | } |
||
| 313 | $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'footer', '', true); |
||
| 314 | } |
||
| 315 | |||
| 316 | if ($user) { |
||
| 317 | $item[] = $this->pc->getPhpCodeCommentLine('User templates'); |
||
| 318 | $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'header', ''); |
||
| 319 | $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'index', ''); |
||
| 320 | $tableBroken = []; |
||
| 321 | $tablePdf = []; |
||
| 322 | $tablePrint = []; |
||
| 323 | $tableRate = []; |
||
| 324 | $tableRss = []; |
||
| 325 | $tableSearch = []; |
||
| 326 | $tableSingle = []; |
||
| 327 | $tableSubmit = []; |
||
| 328 | foreach (array_keys($tables) as $t) { |
||
| 329 | if (1 == $tables[$t]->getVar('table_user')) { |
||
| 330 | $tableName = $tables[$t]->getVar('table_name'); |
||
| 331 | $tableBroken[] = $tables[$t]->getVar('table_broken'); |
||
| 332 | $tablePdf[] = $tables[$t]->getVar('table_pdf'); |
||
| 333 | $tablePrint[] = $tables[$t]->getVar('table_print'); |
||
| 334 | $tableRate[] = $tables[$t]->getVar('table_rate'); |
||
| 335 | $tableRss[] = $tables[$t]->getVar('table_rss'); |
||
| 336 | $tableSearch[] = $tables[$t]->getVar('table_search'); |
||
| 337 | $tableSingle[] = $tables[$t]->getVar('table_single'); |
||
| 338 | $tableSubmit[] = $tables[$t]->getVar('table_submit'); |
||
| 339 | $tableRate[] = $tables[$t]->getVar('table_rate'); |
||
| 340 | $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, $tableName, ''); |
||
| 341 | $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, $tableName, 'list'); |
||
| 342 | $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, $tableName, 'item'); |
||
| 343 | } |
||
| 344 | } |
||
| 345 | $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'breadcrumbs', ''); |
||
| 346 | if (in_array(1, $tablePdf)) { |
||
| 347 | $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'pdf', ''); |
||
| 348 | } |
||
| 349 | if (in_array(1, $tablePrint)) { |
||
| 350 | $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'print', ''); |
||
| 351 | } |
||
| 352 | if (in_array(1, $tableRate)) { |
||
| 353 | $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'rate', ''); |
||
| 354 | } |
||
| 355 | if (in_array(1, $tableRss)) { |
||
| 356 | $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'rss', ''); |
||
| 357 | } |
||
| 358 | if (in_array(1, $tableSearch)) { |
||
| 359 | $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'search', ''); |
||
| 360 | } |
||
| 361 | if (in_array(1, $tableSingle)) { |
||
| 362 | $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'single', ''); |
||
| 363 | } |
||
| 364 | $item[] = $this->getXoopsVersionTemplatesLine($moduleDirname, 'footer', ''); |
||
| 365 | } |
||
| 366 | |||
| 367 | $ret .= $this->uxc->getUserModVersionArray(11, $item, "templates"); |
||
| 368 | |||
| 369 | return $ret; |
||
| 370 | } |
||
| 371 | |||
| 372 | /** |
||
| 373 | * @private function getXoopsVersionTemplatesLine |
||
| 374 | * @param $moduleDirname |
||
| 375 | * @param $type |
||
| 376 | * @param string $extra |
||
| 377 | * @param bool $isAdmin |
||
| 378 | * @return string |
||
| 379 | */ |
||
| 380 | private function getXoopsVersionTemplatesLine($moduleDirname, $type, $extra = '', $isAdmin = false) |
||
| 381 | { |
||
| 382 | $ret = ''; |
||
| 383 | $desc = "'description' => ''"; |
||
| 384 | $arrayFile = "['file' =>"; |
||
| 385 | if ($isAdmin) { |
||
| 386 | $ret .= "{$arrayFile} '{$moduleDirname}_admin_{$type}.tpl', {$desc}, 'type' => 'admin']"; |
||
| 387 | } else { |
||
| 388 | if ('' !== $extra) { |
||
| 389 | $ret .= "{$arrayFile} '{$moduleDirname}_{$type}_{$extra}.tpl', {$desc}]"; |
||
| 390 | } else { |
||
| 391 | $ret .= "{$arrayFile} '{$moduleDirname}_{$type}.tpl', {$desc}]"; |
||
| 392 | } |
||
| 393 | } |
||
| 394 | |||
| 395 | return $ret; |
||
| 396 | } |
||
| 397 | |||
| 398 | /** |
||
| 399 | * @private function getXoopsVersionSubmenu |
||
| 400 | * @param $language |
||
| 401 | * @param $tables |
||
| 402 | * @return string |
||
| 403 | */ |
||
| 404 | private function getXoopsVersionSubmenu($language, $tables) |
||
| 405 | { |
||
| 406 | $ret = $this->getDashComment('Menu'); |
||
| 407 | $xModule = $this->pc->getPhpCodeGlobals('xoopsModule'); |
||
| 408 | $cond = 'isset(' . $xModule . ') && is_object(' . $xModule . ')'; |
||
| 409 | $one = $this->pc->getPhpCodeGlobals('xoopsModule') . "->getVar('dirname')"; |
||
| 410 | $ret .= $this->pc->getPhpCodeTernaryOperator('currdirname ', $cond, $one, "'system'"); |
||
| 411 | |||
| 412 | $i = 1; |
||
| 413 | $descriptions = [ |
||
| 414 | 'name' => "{$language}SMNAME{$i}", |
||
| 415 | 'url' => "'index.php'", |
||
| 416 | ]; |
||
| 417 | $contentIf = $this->uxc->getUserModVersionArray(2, $descriptions, 'sub', '','', "\t"); |
||
| 418 | |||
| 419 | $tableSearch = []; |
||
| 420 | foreach (array_keys($tables) as $t) { |
||
| 421 | $tableName = $tables[$t]->getVar('table_name'); |
||
| 422 | $tableSearch[] = $tables[$t]->getVar('table_search'); |
||
| 423 | if (1 == $tables[$t]->getVar('table_submenu')) { |
||
| 424 | $contentIf .= $this->pc->getPhpCodeCommentLine('Sub', $tableName, "\t"); |
||
| 425 | $descriptions = [ |
||
| 426 | 'name' => "{$language}SMNAME{$i}", |
||
| 427 | 'url' => "'{$tableName}.php'", |
||
| 428 | ]; |
||
| 429 | $contentIf .= $this->uxc->getUserModVersionArray(2, $descriptions, 'sub', '','', "\t"); |
||
| 430 | unset($item); |
||
|
|
|||
| 431 | } |
||
| 432 | ++$i; |
||
| 433 | if (1 == $tables[$t]->getVar('table_submit')) { |
||
| 434 | $contentIf .= $this->pc->getPhpCodeCommentLine('Sub', 'Submit', "\t"); |
||
| 435 | $descriptions = [ |
||
| 436 | 'name' => "{$language}SMNAME{$i}", |
||
| 437 | 'url' => "'{$tableName}.php?op=new'", |
||
| 438 | ]; |
||
| 439 | $contentIf .= $this->uxc->getUserModVersionArray(2, $descriptions, 'sub', '','', "\t"); |
||
| 440 | ++$i; |
||
| 441 | } |
||
| 442 | } |
||
| 443 | |||
| 444 | //TODO: after finalizing creation of search.php by User/UserSearch.php this sub menu item can be activated |
||
| 445 | /* |
||
| 446 | if (in_array(1, $tableSearch)) { |
||
| 447 | $contentIf .= $cpc->getPhpCodeCommentLine('Sub', 'Search', "\t"); |
||
| 448 | $descriptions = [ |
||
| 449 | 'name' => "{$language}SMNAME{$i}", |
||
| 450 | 'url' => "'search.php'", |
||
| 451 | ]; |
||
| 452 | $contentIf .= $this->uxc->getUserModVersionArray(2, $descriptions, 'sub', '','', "\t"); |
||
| 453 | } |
||
| 454 | */ |
||
| 455 | unset($i); |
||
| 456 | |||
| 457 | $ret .= $this->pc->getPhpCodeConditions('$moduleDirName', ' == ', '$currdirname', $contentIf); |
||
| 458 | |||
| 459 | return $ret; |
||
| 460 | } |
||
| 461 | |||
| 462 | /** |
||
| 463 | * @private function getXoopsVersionBlocks |
||
| 464 | * @param $moduleDirname |
||
| 465 | * @param $tables |
||
| 466 | * @param $language |
||
| 467 | * @return string |
||
| 468 | */ |
||
| 469 | private function getXoopsVersionBlocks($moduleDirname, $tables, $language) |
||
| 470 | { |
||
| 471 | $ret = $this->getDashComment('Blocks'); |
||
| 472 | foreach (array_keys($tables) as $i) { |
||
| 473 | $tableName = $tables[$i]->getVar('table_name'); |
||
| 474 | if (0 == $tables[$i]->getVar('table_category') && 1 == $tables[$i]->getVar('table_blocks')) { |
||
| 475 | $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, 'LAST', $language, 'last'); |
||
| 476 | $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, 'NEW', $language, 'new'); |
||
| 477 | $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, 'HITS', $language, 'hits'); |
||
| 478 | $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, 'TOP', $language, 'top'); |
||
| 479 | $ret .= $this->getXoopsVersionTypeBlocks($moduleDirname, $tableName, 'RANDOM', $language, 'random'); |
||
| 480 | } |
||
| 481 | } |
||
| 482 | |||
| 483 | return $ret; |
||
| 484 | } |
||
| 485 | |||
| 486 | /** |
||
| 487 | * @private function getXoopsVersionTypeBlocks |
||
| 488 | * @param $moduleDirname |
||
| 489 | * @param $tableName |
||
| 490 | * @param $stuTableSoleName |
||
| 491 | * @param $language |
||
| 492 | * @param $type |
||
| 493 | * @return string |
||
| 494 | */ |
||
| 495 | private function getXoopsVersionTypeBlocks($moduleDirname, $tableName, $stuTableSoleName, $language, $type) |
||
| 496 | { |
||
| 497 | $stuTableName = mb_strtoupper($tableName); |
||
| 498 | $ucfTableName = ucfirst($tableName); |
||
| 499 | $ret = $this->pc->getPhpCodeCommentLine($ucfTableName . ' ' . $type); |
||
| 500 | $blocks = [ |
||
| 501 | 'file' => "'{$tableName}.php'", |
||
| 502 | 'name' => "{$language}{$stuTableName}_BLOCK_{$stuTableSoleName}", |
||
| 503 | 'description' => "{$language}{$stuTableName}_BLOCK_{$stuTableSoleName}_DESC", |
||
| 504 | 'show_func' => "'b_{$moduleDirname}_{$tableName}_show'", |
||
| 505 | 'edit_func' => "'b_{$moduleDirname}_{$tableName}_edit'", |
||
| 506 | 'template' => "'{$moduleDirname}_block_{$tableName}.tpl'", |
||
| 507 | 'options' => "'{$type}|5|25|0'", |
||
| 508 | ]; |
||
| 509 | $ret .= $this->uxc->getUserModVersionArray(2, $blocks, 'blocks'); |
||
| 510 | |||
| 511 | return $ret; |
||
| 512 | } |
||
| 513 | |||
| 514 | /** |
||
| 515 | * @private function getXoopsVersionConfig |
||
| 516 | * @param $module |
||
| 517 | * @param $tables |
||
| 518 | * @param $language |
||
| 519 | * |
||
| 520 | * @return string |
||
| 521 | */ |
||
| 522 | private function getXoopsVersionConfig($module, $tables, $language) |
||
| 936 | } |
||
| 937 | |||
| 938 | /** |
||
| 939 | * @private function getXoopsVersionNotifications |
||
| 940 | * @param $module |
||
| 941 | * @param $language |
||
| 942 | * @return string |
||
| 943 | */ |
||
| 944 | private function getXoopsVersionNotifications($module, $language) |
||
| 945 | { |
||
| 946 | $moduleDirname = $module->getVar('mod_dirname'); |
||
| 947 | $ret = $this->getDashComment('Notifications'); |
||
| 948 | $ret .= $this->uxc->getUserModVersionText(1, 1, 'hasNotification'); |
||
| 949 | $notifications = ['lookup_file' => "'include/notification.inc.php'", 'lookup_func' => "'{$moduleDirname}_notify_iteminfo'"]; |
||
| 950 | $ret .= $this->uxc->getUserModVersionArray(1, $notifications, 'notification'); |
||
| 951 | |||
| 952 | $notifyFiles = []; |
||
| 953 | $tables = $this->getTableTables($module->getVar('mod_id'), 'table_order'); |
||
| 954 | $tableCategory = []; |
||
| 955 | $tableBroken = []; |
||
| 956 | $tableComments = []; |
||
| 957 | $tableSubmit = []; |
||
| 958 | $tableId = null; |
||
| 959 | $tableMid = null; |
||
| 960 | $notifyCategory = ''; |
||
| 961 | $notifyEventGlobal = $this->pc->getPhpCodeCommentLine('Global events notification'); |
||
| 962 | $notifyEventTable = $this->pc->getPhpCodeCommentLine('Event notifications for items'); |
||
| 963 | |||
| 964 | //global events |
||
| 965 | $notifyEventGlobal .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'global_new', 'global', 0, 'global_new', 'global_new_notify'); |
||
| 966 | $notifyEventGlobal .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'global_modify', 'global', 0, 'global_modify', 'global_modify_notify'); |
||
| 967 | $notifyEventGlobal .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'global_delete', 'global', 0, 'global_delete', 'global_delete_notify'); |
||
| 968 | $notifyEventGlobal .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'global_approve', 'global', 0, 'global_approve', 'global_approve_notify'); |
||
| 969 | foreach (array_keys($tables) as $t) { |
||
| 970 | $tableBroken[] = $tables[$t]->getVar('table_broken'); |
||
| 971 | $tableComments[] = $tables[$t]->getVar('table_comments'); |
||
| 972 | } |
||
| 973 | if (in_array(1, $tableBroken)) { |
||
| 974 | $notifyEventGlobal .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'global_broken', 'global', 0, 'global_broken', 'global_broken_notify'); |
||
| 975 | } |
||
| 976 | if (in_array(1, $tableComments)) { |
||
| 977 | $notifyEventGlobal .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', 'global_comment', 'global', 0, 'global_comment', 'global_comment_notify'); |
||
| 978 | } |
||
| 979 | |||
| 980 | foreach (array_keys($tables) as $t) { |
||
| 981 | $tableId = $tables[$t]->getVar('table_id'); |
||
| 982 | $tableMid = $tables[$t]->getVar('table_mid'); |
||
| 983 | $tableName = $tables[$t]->getVar('table_name'); |
||
| 984 | $tableSoleName = $tables[$t]->getVar('table_solename'); |
||
| 985 | $tableCategory[] = $tables[$t]->getVar('table_category'); |
||
| 986 | $tableSubmit[] = $tables[$t]->getVar('table_submit'); |
||
| 987 | $fields = $this->getTableFields($tableMid, $tableId); |
||
| 988 | $fieldId = 0; |
||
| 989 | foreach (array_keys($fields) as $f) { |
||
| 990 | $fieldName = $fields[$f]->getVar('field_name'); |
||
| 991 | if (0 == $f) { |
||
| 992 | $fieldId = $fieldName; |
||
| 993 | } |
||
| 994 | } |
||
| 995 | if (1 == $tables[$t]->getVar('table_notifications')) { |
||
| 996 | $notifyFiles[] = $tableName; |
||
| 997 | $notifyCategory .= $this->getXoopsVersionNotificationTableName($language, 'category', $tableName, $tableSoleName, $tableName, $fieldId, 1); |
||
| 998 | //$notifyEvent .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', $tableSoleName . '_new', $tableName, 0, $tableSoleName, $tableSoleName . '_new_notify'); |
||
| 999 | $notifyEventTable .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', $tableSoleName . '_modify', $tableName, 0, $tableSoleName . '_modify', $tableSoleName . '_modify_notify'); |
||
| 1000 | $notifyEventTable .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', $tableSoleName . '_delete', $tableName, 0, $tableSoleName . '_delete', $tableSoleName . '_delete_notify'); |
||
| 1001 | $notifyEventTable .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', $tableSoleName . '_approve', $tableName, 0, $tableSoleName . '_approve', $tableSoleName . '_approve_notify'); |
||
| 1002 | if (1 == $tables[$t]->getVar('table_broken')) { |
||
| 1003 | $notifyEventTable .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', $tableSoleName . '_broken', $tableName, 0, $tableSoleName . '_broken', $tableSoleName . '_broken_notify'); |
||
| 1004 | } |
||
| 1005 | /*event will be added by xoops |
||
| 1006 | if (1 == $tables[$t]->getVar('table_comments')) { |
||
| 1007 | $notifyEventTable .= $this->getXoopsVersionNotificationCodeComplete($language, 'event', $tableSoleName . '_comment', $tableName, 0, $tableSoleName . '_comment', $tableSoleName . '_comment_notify'); |
||
| 1008 | }*/ |
||
| 1009 | } |
||
| 1010 | } |
||
| 1011 | $ret .= $this->pc->getPhpCodeCommentLine('Categories of notification'); |
||
| 1012 | $ret .= $this->getXoopsVersionNotificationGlobal($language, 'category', 'global', 'global', $notifyFiles); |
||
| 1013 | |||
| 1014 | //$ret .= $this->getXoopsVersionNotificationCategory($language, 'category', 'category', 'category', $notifyFiles, $fieldParent, '1'); |
||
| 1015 | |||
| 1016 | $ret .= $notifyCategory . $notifyEventGlobal . $notifyEventTable; |
||
| 1017 | |||
| 1018 | |||
| 1019 | return $ret; |
||
| 1020 | } |
||
| 1021 | |||
| 1022 | /** |
||
| 1023 | * @private function getXoopsVersionNotificationGlobal |
||
| 1024 | * @param $language |
||
| 1025 | * @param $type |
||
| 1026 | * @param $name |
||
| 1027 | * @param $title |
||
| 1028 | * @param $from |
||
| 1029 | * |
||
| 1030 | * @return string |
||
| 1031 | */ |
||
| 1032 | private function getXoopsVersionNotificationGlobal($language, $type, $name, $title, $from) |
||
| 1033 | { |
||
| 1034 | $title = mb_strtoupper($title); |
||
| 1035 | $implodeFrom = implode(".php', '", $from); |
||
| 1036 | $ret = $this->pc->getPhpCodeCommentLine('Global Notify'); |
||
| 1037 | $global = [ |
||
| 1038 | 'name' => "'{$name}'", |
||
| 1039 | 'title' => "{$language}NOTIFY_{$title}", |
||
| 1040 | 'description' => "''", |
||
| 1041 | 'subscribe_from' => "['index.php', '{$implodeFrom}.php']", |
||
| 1042 | ]; |
||
| 1043 | $ret .= $this->uxc->getUserModVersionArray(3, $global, 'notification', "'{$type}'"); |
||
| 1044 | |||
| 1045 | return $ret; |
||
| 1046 | } |
||
| 1047 | |||
| 1048 | |||
| 1049 | /** |
||
| 1050 | * @private function getXoopsVersionNotificationTableName |
||
| 1051 | * @param $language |
||
| 1052 | * @param $type |
||
| 1053 | * @param $name |
||
| 1054 | * @param $title |
||
| 1055 | * @param $file |
||
| 1056 | * @param $item |
||
| 1057 | * @param $allow |
||
| 1058 | * |
||
| 1059 | * @return string |
||
| 1060 | */ |
||
| 1061 | private function getXoopsVersionNotificationTableName($language, $type, $name, $title, $file, $item, $allow) |
||
| 1062 | { |
||
| 1063 | $stuTitle = mb_strtoupper($title); |
||
| 1064 | $ucfTitle = ucfirst($title); |
||
| 1065 | $ret = $this->pc->getPhpCodeCommentLine($ucfTitle . ' Notify'); |
||
| 1066 | $table = [ |
||
| 1067 | 'name' => "'{$name}'", |
||
| 1068 | 'title' => "{$language}NOTIFY_{$stuTitle}", |
||
| 1069 | 'description' => "''", |
||
| 1070 | 'subscribe_from' => "'{$file}.php'", |
||
| 1071 | 'item_name' => "'{$item}'", |
||
| 1072 | 'allow_bookmark' => (string)$allow, |
||
| 1073 | ]; |
||
| 1074 | $ret .= $this->uxc->getUserModVersionArray(3, $table, 'notification', "'{$type}'"); |
||
| 1075 | |||
| 1076 | return $ret; |
||
| 1077 | } |
||
| 1078 | |||
| 1079 | /** |
||
| 1080 | * @private function getXoopsVersionNotifications |
||
| 1081 | * @param $language |
||
| 1082 | * @param $type |
||
| 1083 | * @param $name |
||
| 1084 | * @param $category |
||
| 1085 | * @param $admin |
||
| 1086 | * @param $title |
||
| 1087 | * @param $mail |
||
| 1088 | * |
||
| 1089 | * @return string |
||
| 1090 | */ |
||
| 1091 | private function getXoopsVersionNotificationCodeComplete($language, $type, $name, $category, $admin, $title, $mail) |
||
| 1092 | { |
||
| 1093 | $title = mb_strtoupper($title); |
||
| 1094 | $ucfTitle = ucfirst($title); |
||
| 1095 | $ret = $this->pc->getPhpCodeCommentLine($ucfTitle . ' Notify'); |
||
| 1096 | $event = [ |
||
| 1097 | 'name' => "'{$name}'", |
||
| 1098 | 'category' => "'{$category}'", |
||
| 1099 | 'admin_only' => (string)$admin, |
||
| 1100 | 'title' => "{$language}NOTIFY_{$title}", |
||
| 1101 | 'caption' => "{$language}NOTIFY_{$title}_CAPTION", |
||
| 1102 | 'description' => "''", |
||
| 1103 | 'mail_template' => "'{$mail}'", |
||
| 1104 | 'mail_subject' => "{$language}NOTIFY_{$title}_SUBJECT", |
||
| 1105 | ]; |
||
| 1106 | $ret .= $this->uxc->getUserModVersionArray(3, $event, 'notification', "'{$type}'"); |
||
| 1107 | |||
| 1108 | return $ret; |
||
| 1109 | } |
||
| 1110 | |||
| 1111 | /** |
||
| 1112 | * @private function getXoopsVersionNotifications |
||
| 1113 | * @param $moduleDirname |
||
| 1114 | * @param string $t |
||
| 1115 | * @return string |
||
| 1116 | */ |
||
| 1117 | private function getXoopsVersionSelectSizeMB($moduleDirname, $t = '') |
||
| 1118 | { |
||
| 1119 | $ucModuleDirname = mb_strtoupper($moduleDirname); |
||
| 1120 | |||
| 1121 | $ret = $this->pc->getPhpCodeCommentLine('create increment steps for file size'); |
||
| 1122 | $ret .= $this->pc->getPhpCodeIncludeDir("__DIR__ . '/include/xoops_version.inc.php'", '',true,true); |
||
| 1123 | $ret .= $this->xc->getXcEqualsOperator('$iniPostMaxSize ', "{$moduleDirname}ReturnBytes(ini_get('post_max_size'))"); |
||
| 1124 | $ret .= $this->xc->getXcEqualsOperator('$iniUploadMaxFileSize', "{$moduleDirname}ReturnBytes(ini_get('upload_max_filesize'))"); |
||
| 1125 | $ret .= $this->xc->getXcEqualsOperator('$maxSize ', "min(\$iniPostMaxSize, \$iniUploadMaxFileSize)"); |
||
| 1126 | $cond = $this->xc->getXcEqualsOperator('$increment', '500', null, $t . "\t"); |
||
| 1127 | $ret .= $this->pc->getPhpCodeConditions('$maxSize', ' > ', '10000 * 1048576', $cond, false, $t); |
||
| 1128 | $cond = $this->xc->getXcEqualsOperator('$increment', '200', null, $t . "\t"); |
||
| 1129 | $ret .= $this->pc->getPhpCodeConditions('$maxSize', ' <= ', '10000 * 1048576', $cond, false, $t); |
||
| 1130 | $cond = $this->xc->getXcEqualsOperator('$increment', '100', null, $t . "\t"); |
||
| 1131 | $ret .= $this->pc->getPhpCodeConditions('$maxSize', ' <= ', '5000 * 1048576', $cond, false, $t); |
||
| 1132 | $cond = $this->xc->getXcEqualsOperator('$increment', '50', null, $t . "\t"); |
||
| 1133 | $ret .= $this->pc->getPhpCodeConditions('$maxSize', ' <= ', '2500 * 1048576', $cond, false, $t); |
||
| 1134 | $cond = $this->xc->getXcEqualsOperator('$increment', '10', null, $t . "\t"); |
||
| 1135 | $ret .= $this->pc->getPhpCodeConditions('$maxSize', ' <= ', '1000 * 1048576', $cond, false, $t); |
||
| 1136 | $cond = $this->xc->getXcEqualsOperator('$increment', '5', null, $t . "\t"); |
||
| 1137 | $ret .= $this->pc->getPhpCodeConditions('$maxSize', ' <= ', '500 * 1048576', $cond, false, $t); |
||
| 1138 | $cond = $this->xc->getXcEqualsOperator('$increment', '2', null, $t . "\t"); |
||
| 1139 | $ret .= $this->pc->getPhpCodeConditions('$maxSize', ' <= ', '100 * 1048576', $cond, false, $t); |
||
| 1140 | $cond = $this->xc->getXcEqualsOperator('$increment', '1', null, $t . "\t"); |
||
| 1141 | $ret .= $this->pc->getPhpCodeConditions('$maxSize', ' <= ', '50 * 1048576', $cond, false, $t); |
||
| 1142 | $cond = $this->xc->getXcEqualsOperator('$increment', '0.5', null, $t . "\t"); |
||
| 1143 | $ret .= $this->pc->getPhpCodeConditions('$maxSize', ' <= ', '25 * 1048576', $cond, false, $t); |
||
| 1144 | $ret .= $this->xc->getXcEqualsOperator('$optionMaxsize', '[]'); |
||
| 1145 | $ret .= $this->xc->getXcEqualsOperator('$i', '$increment'); |
||
| 1146 | $while = $this->xc->getXcEqualsOperator("\$optionMaxsize[\$i . ' ' . _MI_{$ucModuleDirname}_SIZE_MB]", '$i * 1048576', null, $t . "\t"); |
||
| 1147 | $while .= $this->xc->getXcEqualsOperator('$i', '$increment', '+',$t . "\t"); |
||
| 1148 | $ret .= $this->pc->getPhpCodeWhile('i * 1048576', $while, '$maxSize', '<='); |
||
| 1149 | |||
| 1150 | return $ret; |
||
| 1151 | } |
||
| 1152 | |||
| 1153 | /** |
||
| 1154 | * @public function render |
||
| 1155 | * @param null |
||
| 1156 | * @return bool|string |
||
| 1157 | */ |
||
| 1158 | public function render() |
||
| 1201 | } |
||
| 1202 | } |
||
| 1203 |