| Conditions | 63 |
| Paths | > 20000 |
| Total Lines | 720 |
| Code Lines | 368 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 0 | Features | 2 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 267 | public function index() { |
||
| 268 | |||
| 269 | global $access_level_names; |
||
| 270 | |||
| 271 | $_SESSION["prefs_op_result"] = ""; |
||
| 272 | |||
| 273 | print "<div dojoType='dijit.layout.AccordionContainer' region='center'>"; |
||
| 274 | print "<div dojoType='dijit.layout.AccordionPane' |
||
| 275 | title=\"<i class='material-icons'>person</i> ".__('Personal data / Authentication')."\">"; |
||
| 276 | |||
| 277 | print "<div dojoType='dijit.layout.TabContainer'>"; |
||
| 278 | print "<div dojoType='dijit.layout.ContentPane' title=\"".__('Personal data')."\">"; |
||
| 279 | |||
| 280 | print "<form dojoType='dijit.form.Form' id='changeUserdataForm'>"; |
||
| 281 | |||
| 282 | print "<script type='dojo/method' event='onSubmit' args='evt'> |
||
| 283 | evt.preventDefault(); |
||
| 284 | if (this.validate()) { |
||
| 285 | Notify.progress('Saving data...', true); |
||
| 286 | |||
| 287 | new Ajax.Request('backend.php', { |
||
| 288 | parameters: dojo.objectToQuery(this.getValues()), |
||
| 289 | onComplete: function(transport) { |
||
| 290 | notify_callback2(transport); |
||
| 291 | } }); |
||
| 292 | |||
| 293 | } |
||
| 294 | </script>"; |
||
| 295 | |||
| 296 | $sth = $this->pdo->prepare("SELECT email,full_name,otp_enabled, |
||
| 297 | access_level FROM ttrss_users |
||
| 298 | WHERE id = ?"); |
||
| 299 | $sth->execute([$_SESSION["uid"]]); |
||
| 300 | $row = $sth->fetch(); |
||
| 301 | |||
| 302 | $email = htmlspecialchars($row["email"]); |
||
| 303 | $full_name = htmlspecialchars($row["full_name"]); |
||
| 304 | $otp_enabled = sql_bool_to_bool($row["otp_enabled"]); |
||
| 305 | |||
| 306 | print "<fieldset>"; |
||
| 307 | print "<label>".__('Full name:')."</label>"; |
||
| 308 | print "<input dojoType='dijit.form.ValidationTextBox' name='full_name' required='1' value='$full_name'>"; |
||
| 309 | print "</fieldset>"; |
||
| 310 | |||
| 311 | print "<fieldset>"; |
||
| 312 | print "<label>".__('E-mail:')."</label>"; |
||
| 313 | print "<input dojoType='dijit.form.ValidationTextBox' name='email' required='1' value='$email'>"; |
||
| 314 | print "</fieldset>"; |
||
| 315 | |||
| 316 | if (!SINGLE_USER_MODE && !$_SESSION["hide_hello"]) { |
||
| 317 | |||
| 318 | $access_level = $row["access_level"]; |
||
| 319 | print "<fieldset>"; |
||
| 320 | print "<label>".__('Access level:')."</label>"; |
||
| 321 | print $access_level_names[$access_level]; |
||
| 322 | print "</fieldset>"; |
||
| 323 | } |
||
| 324 | |||
| 325 | print_hidden("op", "pref-prefs"); |
||
| 326 | print_hidden("method", "changeemail"); |
||
| 327 | |||
| 328 | print "<hr/>"; |
||
| 329 | |||
| 330 | print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary'>". |
||
| 331 | __("Save data")."</button>"; |
||
| 332 | |||
| 333 | print "</form>"; |
||
| 334 | |||
| 335 | print "</div>"; # content pane |
||
| 336 | print "<div dojoType='dijit.layout.ContentPane' title=\"".__('Password')."\">"; |
||
| 337 | |||
| 338 | if ($_SESSION["auth_module"]) { |
||
| 339 | $authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]); |
||
| 340 | } else { |
||
| 341 | $authenticator = false; |
||
| 342 | } |
||
| 343 | |||
| 344 | if ($authenticator && method_exists($authenticator, "change_password")) { |
||
| 345 | |||
| 346 | print "<div style='display : none' id='pwd_change_infobox'></div>"; |
||
| 347 | |||
| 348 | print "<form dojoType='dijit.form.Form'>"; |
||
| 349 | |||
| 350 | print "<script type='dojo/method' event='onSubmit' args='evt'> |
||
| 351 | evt.preventDefault(); |
||
| 352 | if (this.validate()) { |
||
| 353 | Notify.progress('Changing password...', true); |
||
| 354 | |||
| 355 | new Ajax.Request('backend.php', { |
||
| 356 | parameters: dojo.objectToQuery(this.getValues()), |
||
| 357 | onComplete: function(transport) { |
||
| 358 | Notify.close(); |
||
| 359 | if (transport.responseText.indexOf('ERROR: ') == 0) { |
||
| 360 | |||
| 361 | $('pwd_change_infobox').innerHTML = |
||
| 362 | transport.responseText.replace('ERROR: ', ''); |
||
| 363 | |||
| 364 | } else { |
||
| 365 | $('pwd_change_infobox').innerHTML = |
||
| 366 | transport.responseText.replace('ERROR: ', ''); |
||
| 367 | |||
| 368 | var warn = $('default_pass_warning'); |
||
| 369 | if (warn) Element.hide(warn); |
||
| 370 | } |
||
| 371 | |||
| 372 | new Effect.Appear('pwd_change_infobox'); |
||
| 373 | |||
| 374 | }}); |
||
| 375 | this.reset(); |
||
| 376 | } |
||
| 377 | </script>"; |
||
| 378 | |||
| 379 | if ($otp_enabled) { |
||
| 380 | print_notice(__("Changing your current password will disable OTP.")); |
||
| 381 | } |
||
| 382 | |||
| 383 | print "<fieldset>"; |
||
| 384 | print "<label>".__("Old password:")."</label>"; |
||
| 385 | print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' name='old_password'>"; |
||
| 386 | print "</fieldset>"; |
||
| 387 | |||
| 388 | print "<fieldset>"; |
||
| 389 | print "<label>".__("New password:")."</label>"; |
||
| 390 | print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' name='new_password'>"; |
||
| 391 | print "</fieldset>"; |
||
| 392 | |||
| 393 | print "<fieldset>"; |
||
| 394 | print "<label>".__("Confirm password:")."</label>"; |
||
| 395 | print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' name='confirm_password'>"; |
||
| 396 | print "</fieldset>"; |
||
| 397 | |||
| 398 | print_hidden("op", "pref-prefs"); |
||
| 399 | print_hidden("method", "changepassword"); |
||
| 400 | |||
| 401 | print "<hr/>"; |
||
| 402 | |||
| 403 | print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary'>". |
||
| 404 | __("Change password")."</button>"; |
||
| 405 | |||
| 406 | print "</form>"; |
||
| 407 | |||
| 408 | print "</div>"; # content pane |
||
| 409 | |||
| 410 | if ($_SESSION["auth_module"] == "auth_internal") { |
||
| 411 | |||
| 412 | print "<div dojoType='dijit.layout.ContentPane' title=\"".__('App passwords')."\">"; |
||
| 413 | |||
| 414 | print_notice("You can create separate passwords for API clients. Using one is required if you enable OTP."); |
||
| 415 | |||
| 416 | print "<div id='app_passwords_holder'>"; |
||
| 417 | $this->appPasswordList(); |
||
| 418 | print "</div>"; |
||
| 419 | |||
| 420 | print "<hr>"; |
||
| 421 | |||
| 422 | print "<button style='float : left' class='alt-primary' dojoType='dijit.form.Button' |
||
| 423 | onclick=\"Helpers.AppPasswords.generate()\">" . |
||
| 424 | __('Generate new password')."</button> "; |
||
| 425 | |||
| 426 | print "<button style='float : left' class='alt-danger' dojoType='dijit.form.Button' |
||
| 427 | onclick=\"Helpers.AppPasswords.removeSelected()\">" . |
||
| 428 | __('Remove selected passwords')."</button>"; |
||
| 429 | |||
| 430 | print "</div>"; # content pane |
||
| 431 | } |
||
| 432 | |||
| 433 | print "<div dojoType='dijit.layout.ContentPane' title=\"".__('One time passwords / Authenticator')."\">"; |
||
| 434 | |||
| 435 | if ($_SESSION["auth_module"] == "auth_internal") { |
||
| 436 | |||
| 437 | if ($otp_enabled) { |
||
| 438 | |||
| 439 | print_warning("One time passwords are currently enabled. Enter your current password below to disable."); |
||
| 440 | |||
| 441 | print "<form dojoType='dijit.form.Form'>"; |
||
| 442 | |||
| 443 | print "<script type='dojo/method' event='onSubmit' args='evt'> |
||
| 444 | evt.preventDefault(); |
||
| 445 | if (this.validate()) { |
||
| 446 | Notify.progress('Disabling OTP', true); |
||
| 447 | |||
| 448 | new Ajax.Request('backend.php', { |
||
| 449 | parameters: dojo.objectToQuery(this.getValues()), |
||
| 450 | onComplete: function(transport) { |
||
| 451 | Notify.close(); |
||
| 452 | if (transport.responseText.indexOf('ERROR: ') == 0) { |
||
| 453 | Notify.error(transport.responseText.replace('ERROR: ', '')); |
||
| 454 | } else { |
||
| 455 | window.location.reload(); |
||
| 456 | } |
||
| 457 | }}); |
||
| 458 | this.reset(); |
||
| 459 | } |
||
| 460 | </script>"; |
||
| 461 | |||
| 462 | print "<fieldset>"; |
||
| 463 | print "<label>".__("Your password:")."</label>"; |
||
| 464 | print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' name='password'>"; |
||
| 465 | print "</fieldset>"; |
||
| 466 | |||
| 467 | print_hidden("op", "pref-prefs"); |
||
| 468 | print_hidden("method", "otpdisable"); |
||
| 469 | |||
| 470 | print "<hr/>"; |
||
| 471 | |||
| 472 | print "<button dojoType='dijit.form.Button' type='submit'>". |
||
| 473 | __("Disable OTP")."</button>"; |
||
| 474 | |||
| 475 | print "</form>"; |
||
| 476 | |||
| 477 | } else { |
||
| 478 | |||
| 479 | print_warning("You will need a compatible Authenticator to use this. Changing your password would automatically disable OTP."); |
||
| 480 | print_notice("You will need to generate app passwords for the API clients if you enable OTP."); |
||
| 481 | |||
| 482 | if (function_exists("imagecreatefromstring")) { |
||
| 483 | print "<h3>".__("Scan the following code by the Authenticator application or copy the key manually")."</h3>"; |
||
| 484 | |||
| 485 | $csrf_token = $_SESSION["csrf_token"]; |
||
| 486 | print "<img alt='otp qr-code' src='backend.php?op=pref-prefs&method=otpqrcode&csrf_token=$csrf_token'>"; |
||
| 487 | } else { |
||
| 488 | print_error("PHP GD functions are required to generate QR codes."); |
||
| 489 | print "<h3>".__("Use the following OTP key with a compatible Authenticator application")."</h3>"; |
||
| 490 | } |
||
| 491 | |||
| 492 | print "<form dojoType='dijit.form.Form' id='changeOtpForm'>"; |
||
| 493 | |||
| 494 | $otp_secret = $this->otpsecret(); |
||
| 495 | |||
| 496 | print "<fieldset>"; |
||
| 497 | print "<label>".__("OTP Key:")."</label>"; |
||
| 498 | print "<input dojoType='dijit.form.ValidationTextBox' disabled='disabled' value='$otp_secret' size='32'>"; |
||
| 499 | print "</fieldset>"; |
||
| 500 | |||
| 501 | print_hidden("op", "pref-prefs"); |
||
| 502 | print_hidden("method", "otpenable"); |
||
| 503 | |||
| 504 | print "<script type='dojo/method' event='onSubmit' args='evt'> |
||
| 505 | evt.preventDefault(); |
||
| 506 | if (this.validate()) { |
||
| 507 | Notify.progress('Saving data...', true); |
||
| 508 | |||
| 509 | new Ajax.Request('backend.php', { |
||
| 510 | parameters: dojo.objectToQuery(this.getValues()), |
||
| 511 | onComplete: function(transport) { |
||
| 512 | Notify.close(); |
||
| 513 | if (transport.responseText.indexOf('ERROR:') == 0) { |
||
| 514 | Notify.error(transport.responseText.replace('ERROR:', '')); |
||
| 515 | } else { |
||
| 516 | window.location.reload(); |
||
| 517 | } |
||
| 518 | } }); |
||
| 519 | |||
| 520 | } |
||
| 521 | </script>"; |
||
| 522 | |||
| 523 | print "<fieldset>"; |
||
| 524 | print "<label>".__("Your password:")."</label>"; |
||
| 525 | print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' |
||
| 526 | name='password'>"; |
||
| 527 | print "</fieldset>"; |
||
| 528 | |||
| 529 | print "<fieldset>"; |
||
| 530 | print "<label>".__("One time password:")."</label>"; |
||
| 531 | print "<input dojoType='dijit.form.ValidationTextBox' autocomplete='off' |
||
| 532 | required='1' name='otp'>"; |
||
| 533 | print "</fieldset>"; |
||
| 534 | |||
| 535 | print "<hr/>"; |
||
| 536 | print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary'>". |
||
| 537 | __("Enable OTP")."</button>"; |
||
| 538 | |||
| 539 | print "</form>"; |
||
| 540 | |||
| 541 | } |
||
| 542 | } |
||
| 543 | |||
| 544 | print "</div>"; # content pane |
||
| 545 | print "</div>"; # tab container |
||
| 546 | |||
| 547 | } |
||
| 548 | |||
| 549 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
||
| 550 | "hook_prefs_tab_section", "prefPrefsAuth"); |
||
| 551 | |||
| 552 | print "</div>"; #pane |
||
| 553 | |||
| 554 | print "<div dojoType='dijit.layout.AccordionPane' selected='true' |
||
| 555 | title=\"<i class='material-icons'>settings</i> ".__('Preferences')."\">"; |
||
| 556 | |||
| 557 | print "<form dojoType='dijit.form.Form' id='changeSettingsForm'>"; |
||
| 558 | |||
| 559 | print "<script type='dojo/method' event='onSubmit' args='evt, quit'> |
||
| 560 | if (evt) evt.preventDefault(); |
||
| 561 | if (this.validate()) { |
||
| 562 | console.log(dojo.objectToQuery(this.getValues())); |
||
| 563 | |||
| 564 | new Ajax.Request('backend.php', { |
||
| 565 | parameters: dojo.objectToQuery(this.getValues()), |
||
| 566 | onComplete: function(transport) { |
||
| 567 | var msg = transport.responseText; |
||
| 568 | if (quit) { |
||
| 569 | document.location.href = 'index.php'; |
||
| 570 | } else { |
||
| 571 | if (msg == 'PREFS_NEED_RELOAD') { |
||
| 572 | window.location.reload(); |
||
| 573 | } else { |
||
| 574 | Notify.info(msg); |
||
| 575 | } |
||
| 576 | } |
||
| 577 | } }); |
||
| 578 | } |
||
| 579 | </script>"; |
||
| 580 | |||
| 581 | print '<div dojoType="dijit.layout.BorderContainer" gutters="false">'; |
||
| 582 | |||
| 583 | print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">'; |
||
| 584 | |||
| 585 | $profile = $_SESSION["profile"]; |
||
| 586 | |||
| 587 | if ($profile) { |
||
| 588 | print_notice(__("Some preferences are only available in default profile.")); |
||
| 589 | |||
| 590 | initialize_user_prefs($_SESSION["uid"], $profile); |
||
| 591 | } else { |
||
| 592 | initialize_user_prefs($_SESSION["uid"]); |
||
| 593 | } |
||
| 594 | |||
| 595 | $prefs_available = []; |
||
| 596 | |||
| 597 | $sth = $this->pdo->prepare("SELECT DISTINCT |
||
| 598 | ttrss_user_prefs.pref_name,value,type_name, |
||
| 599 | ttrss_prefs_sections.order_id, |
||
| 600 | def_value,section_id |
||
| 601 | FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs |
||
| 602 | WHERE type_id = ttrss_prefs_types.id AND |
||
| 603 | (profile = :profile OR (:profile IS NULL AND profile IS NULL)) AND |
||
| 604 | section_id = ttrss_prefs_sections.id AND |
||
| 605 | ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND |
||
| 606 | owner_uid = :uid |
||
| 607 | ORDER BY ttrss_prefs_sections.order_id,pref_name"); |
||
| 608 | $sth->execute([":uid" => $_SESSION['uid'], ":profile" => $profile]); |
||
| 609 | |||
| 610 | $listed_boolean_prefs = []; |
||
| 611 | |||
| 612 | while ($line = $sth->fetch()) { |
||
| 613 | |||
| 614 | if (in_array($line["pref_name"], $this->pref_blacklist)) { |
||
| 615 | continue; |
||
| 616 | } |
||
| 617 | |||
| 618 | if ($profile && in_array($line["pref_name"], $this->profile_blacklist)) { |
||
| 619 | continue; |
||
| 620 | } |
||
| 621 | |||
| 622 | $pref_name = $line["pref_name"]; |
||
| 623 | $short_desc = $this->getShortDesc($pref_name); |
||
| 624 | |||
| 625 | if (!$short_desc) { |
||
| 626 | continue; |
||
| 627 | } |
||
| 628 | |||
| 629 | $prefs_available[$pref_name] = [ |
||
| 630 | 'type_name' => $line["type_name"], |
||
| 631 | 'value' => $line['value'], |
||
| 632 | 'help_text' => $this->getHelpText($pref_name), |
||
| 633 | 'short_desc' => $short_desc |
||
| 634 | ]; |
||
| 635 | } |
||
| 636 | |||
| 637 | foreach (array_keys($this->pref_item_map) as $section) { |
||
| 638 | |||
| 639 | print "<h2>$section</h2>"; |
||
| 640 | |||
| 641 | foreach ($this->pref_item_map[$section] as $pref_name) { |
||
| 642 | |||
| 643 | if ($pref_name == 'BLOCK_SEPARATOR' && !$profile) { |
||
| 644 | print "<hr/>"; |
||
| 645 | continue; |
||
| 646 | } |
||
| 647 | |||
| 648 | if ($pref_name == "DEFAULT_SEARCH_LANGUAGE" && DB_TYPE != "pgsql") { |
||
| 649 | continue; |
||
| 650 | } |
||
| 651 | |||
| 652 | if ($item = $prefs_available[$pref_name]) { |
||
| 653 | |||
| 654 | print "<fieldset class='prefs'>"; |
||
| 655 | |||
| 656 | print "<label for='CB_$pref_name'>"; |
||
| 657 | print $item['short_desc'].":"; |
||
| 658 | print "</label>"; |
||
| 659 | |||
| 660 | $value = $item['value']; |
||
| 661 | $type_name = $item['type_name']; |
||
| 662 | |||
| 663 | if ($pref_name == "USER_LANGUAGE") { |
||
| 664 | print_select_hash($pref_name, $value, get_translations(), |
||
| 665 | "style='width : 220px; margin : 0px' dojoType='fox.form.Select'"); |
||
| 666 | |||
| 667 | } else if ($pref_name == "USER_TIMEZONE") { |
||
| 668 | |||
| 669 | $timezones = explode("\n", file_get_contents("lib/timezones.txt")); |
||
| 670 | |||
| 671 | print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"'); |
||
| 672 | } else if ($pref_name == "USER_CSS_THEME") { |
||
| 673 | |||
| 674 | $themes = array_merge(glob("themes/*.php"), glob("themes/*.css"), glob("themes.local/*.css")); |
||
| 675 | $themes = array_map("basename", $themes); |
||
| 676 | $themes = array_filter($themes, "theme_exists"); |
||
| 677 | asort($themes); |
||
| 678 | |||
| 679 | if (!theme_exists($value)) { |
||
| 680 | $value = "default.php"; |
||
| 681 | } |
||
| 682 | |||
| 683 | print "<select name='$pref_name' id='$pref_name' dojoType='fox.form.Select'>"; |
||
| 684 | |||
| 685 | $issel = $value == "default.php" ? "selected='selected'" : ""; |
||
| 686 | print "<option $issel value='default.php'>".__("default")."</option>"; |
||
| 687 | |||
| 688 | foreach ($themes as $theme) { |
||
| 689 | $issel = $value == $theme ? "selected='selected'" : ""; |
||
| 690 | print "<option $issel value='$theme'>$theme</option>"; |
||
| 691 | } |
||
| 692 | |||
| 693 | print "</select>"; |
||
| 694 | |||
| 695 | print " <button dojoType=\"dijit.form.Button\" class='alt-info' |
||
| 696 | onclick=\"Helpers.customizeCSS()\">" . __('Customize')."</button>"; |
||
| 697 | |||
| 698 | print " <button dojoType='dijit.form.Button' onclick='window.open(\"https://tt-rss.org/wiki/Themes\")'> |
||
| 699 | <i class='material-icons'>open_in_new</i> ".__("More themes...")."</button>"; |
||
| 700 | |||
| 701 | } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") { |
||
| 702 | |||
| 703 | global $update_intervals_nodefault; |
||
| 704 | |||
| 705 | print_select_hash($pref_name, $value, $update_intervals_nodefault, |
||
| 706 | 'dojoType="fox.form.Select"'); |
||
| 707 | } else if ($pref_name == "DEFAULT_SEARCH_LANGUAGE") { |
||
| 708 | |||
| 709 | print_select($pref_name, $value, Pref_Feeds::get_ts_languages(), |
||
| 710 | 'dojoType="fox.form.Select"'); |
||
| 711 | |||
| 712 | } else if ($type_name == "bool") { |
||
| 713 | |||
| 714 | array_push($listed_boolean_prefs, $pref_name); |
||
| 715 | |||
| 716 | $checked = ($value == "true") ? "checked=\"checked\"" : ""; |
||
| 717 | |||
| 718 | if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) { |
||
| 719 | $disabled = "disabled=\"1\""; |
||
| 720 | $checked = "checked=\"checked\""; |
||
| 721 | } else { |
||
| 722 | $disabled = ""; |
||
| 723 | } |
||
| 724 | |||
| 725 | print "<input type='checkbox' name='$pref_name' $checked $disabled |
||
| 726 | dojoType='dijit.form.CheckBox' id='CB_$pref_name' value='1'>"; |
||
| 727 | |||
| 728 | } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', |
||
| 729 | 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) { |
||
| 730 | |||
| 731 | $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; |
||
| 732 | |||
| 733 | if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) { |
||
| 734 | $disabled = "disabled='1'"; |
||
| 735 | $value = FORCE_ARTICLE_PURGE; |
||
| 736 | } else { |
||
| 737 | $disabled = ""; |
||
| 738 | } |
||
| 739 | |||
| 740 | if ($type_name == 'integer') { |
||
| 741 | print "<input dojoType=\"dijit.form.NumberSpinner\" |
||
| 742 | required='1' $disabled |
||
| 743 | name=\"$pref_name\" value=\"$value\">"; |
||
| 744 | } else { |
||
| 745 | print "<input dojoType=\"dijit.form.TextBox\" |
||
| 746 | required='1' $regexp $disabled |
||
| 747 | name=\"$pref_name\" value=\"$value\">"; |
||
| 748 | } |
||
| 749 | |||
| 750 | } else if ($pref_name == "SSL_CERT_SERIAL") { |
||
| 751 | |||
| 752 | print "<input dojoType='dijit.form.ValidationTextBox' |
||
| 753 | id='SSL_CERT_SERIAL' readonly='1' |
||
| 754 | name=\"$pref_name\" value=\"$value\">"; |
||
| 755 | |||
| 756 | $cert_serial = htmlspecialchars(get_ssl_certificate_id()); |
||
| 757 | $has_serial = ($cert_serial) ? "false" : "true"; |
||
| 758 | |||
| 759 | print "<button dojoType='dijit.form.Button' disabled='$has_serial' |
||
| 760 | onclick=\"dijit.byId('SSL_CERT_SERIAL').attr('value', '$cert_serial')\">". |
||
| 761 | __('Register')."</button>"; |
||
| 762 | |||
| 763 | print "<button dojoType='dijit.form.Button' class='alt-danger' |
||
| 764 | onclick=\"dijit.byId('SSL_CERT_SERIAL').attr('value', '')\">" . |
||
| 765 | __('Clear')."</button>"; |
||
| 766 | |||
| 767 | print "<button dojoType='dijit.form.Button' class='alt-info' |
||
| 768 | onclick='window.open(\"https://tt-rss.org/wiki/SSL%20Certificate%20Authentication\")'> |
||
| 769 | <i class='material-icons'>help</i> ".__("More info...")."</button>"; |
||
| 770 | |||
| 771 | } else if ($pref_name == 'DIGEST_PREFERRED_TIME') { |
||
| 772 | print "<input dojoType=\"dijit.form.ValidationTextBox\" |
||
| 773 | id=\"$pref_name\" regexp=\"[012]?\d:\d\d\" placeHolder=\"12:00\" |
||
| 774 | name=\"$pref_name\" value=\"$value\">"; |
||
| 775 | |||
| 776 | $item['help_text'] .= ". ".T_sprintf("Current server time: %s", date("H:i")); |
||
| 777 | } else { |
||
| 778 | $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; |
||
| 779 | |||
| 780 | print "<input dojoType=\"dijit.form.ValidationTextBox\" $regexp name=\"$pref_name\" value=\"$value\">"; |
||
| 781 | } |
||
| 782 | |||
| 783 | if ($item['help_text']) { |
||
| 784 | print "<div class='help-text text-muted'><label for='CB_$pref_name'>".$item['help_text']."</label></div>"; |
||
| 785 | } |
||
| 786 | |||
| 787 | print "</fieldset>"; |
||
| 788 | } |
||
| 789 | } |
||
| 790 | } |
||
| 791 | |||
| 792 | $listed_boolean_prefs = htmlspecialchars(join(",", $listed_boolean_prefs)); |
||
| 793 | |||
| 794 | print_hidden("boolean_prefs", "$listed_boolean_prefs"); |
||
| 795 | |||
| 796 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
||
| 797 | "hook_prefs_tab_section", "prefPrefsPrefsInside"); |
||
| 798 | |||
| 799 | print '</div>'; # inside pane |
||
| 800 | print '<div dojoType="dijit.layout.ContentPane" region="bottom">'; |
||
| 801 | |||
| 802 | print_hidden("op", "pref-prefs"); |
||
| 803 | print_hidden("method", "saveconfig"); |
||
| 804 | |||
| 805 | print "<div dojoType=\"fox.form.ComboButton\" type=\"submit\" class=\"alt-primary\"> |
||
| 806 | <span>".__('Save configuration')."</span> |
||
| 807 | <div dojoType=\"dijit.DropDownMenu\"> |
||
| 808 | <div dojoType=\"dijit.MenuItem\" |
||
| 809 | onclick=\"dijit.byId('changeSettingsForm').onSubmit(null, true)\">". |
||
| 810 | __("Save and exit preferences")."</div> |
||
| 811 | </div> |
||
| 812 | </div>"; |
||
| 813 | |||
| 814 | print "<button dojoType=\"dijit.form.Button\" onclick=\"return Helpers.editProfiles()\">". |
||
| 815 | __('Manage profiles')."</button> "; |
||
| 816 | |||
| 817 | print "<button dojoType=\"dijit.form.Button\" class=\"alt-danger\" onclick=\"return Helpers.confirmReset()\">". |
||
| 818 | __('Reset to defaults')."</button>"; |
||
| 819 | |||
| 820 | print " "; |
||
| 821 | |||
| 822 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, |
||
| 823 | "hook_prefs_tab_section", "prefPrefsPrefsOutside"); |
||
| 824 | |||
| 825 | print "</form>"; |
||
| 826 | print '</div>'; # inner pane |
||
| 827 | print '</div>'; # border container |
||
| 828 | |||
| 829 | print "</div>"; #pane |
||
| 830 | |||
| 831 | print "<div dojoType=\"dijit.layout.AccordionPane\" |
||
| 832 | title=\"<i class='material-icons'>extension</i> ".__('Plugins')."\">"; |
||
| 833 | |||
| 834 | print "<form dojoType=\"dijit.form.Form\" id=\"changePluginsForm\">"; |
||
| 835 | |||
| 836 | print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> |
||
| 837 | evt.preventDefault(); |
||
| 838 | if (this.validate()) { |
||
| 839 | Notify.progress('Saving data...', true); |
||
| 840 | |||
| 841 | new Ajax.Request('backend.php', { |
||
| 842 | parameters: dojo.objectToQuery(this.getValues()), |
||
| 843 | onComplete: function(transport) { |
||
| 844 | Notify.close(); |
||
| 845 | if (confirm(__('Selected plugins have been enabled. Reload?'))) { |
||
| 846 | window.location.reload(); |
||
| 847 | } |
||
| 848 | } }); |
||
| 849 | |||
| 850 | } |
||
| 851 | </script>"; |
||
| 852 | |||
| 853 | print_hidden("op", "pref-prefs"); |
||
| 854 | print_hidden("method", "setplugins"); |
||
| 855 | |||
| 856 | print '<div dojoType="dijit.layout.BorderContainer" gutters="false">'; |
||
| 857 | print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">'; |
||
| 858 | |||
| 859 | if (ini_get("open_basedir") && function_exists("curl_init") && !defined("NO_CURL")) { |
||
| 860 | print_warning("Your PHP configuration has open_basedir restrictions enabled. Some plugins relying on CURL for functionality may not work correctly."); |
||
| 861 | } |
||
| 862 | |||
| 863 | $feed_handler_whitelist = ["Af_Comics"]; |
||
| 864 | |||
| 865 | $feed_handlers = array_merge( |
||
| 866 | PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_FETCHED), |
||
| 867 | PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_PARSED), |
||
| 868 | PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FETCH_FEED)); |
||
| 869 | |||
| 870 | $feed_handlers = array_filter($feed_handlers, function($plugin) use ($feed_handler_whitelist) { |
||
| 871 | return in_array(get_class($plugin), $feed_handler_whitelist) === false; }); |
||
| 872 | |||
| 873 | if (count($feed_handlers) > 0) { |
||
| 874 | print_error( |
||
| 875 | T_sprintf("The following plugins use per-feed content hooks. This may cause excessive data usage and origin server load resulting in a ban of your instance: <b>%s</b>", |
||
| 876 | implode(", ", array_map(function($plugin) { return get_class($plugin); }, $feed_handlers)) |
||
| 877 | )." (<a href='https://tt-rss.org/wiki/FeedHandlerPlugins' target='_blank'>".__("More info...")."</a>)" |
||
| 878 | ); |
||
| 879 | } |
||
| 880 | |||
| 881 | print "<h2>".__("System plugins")."</h2>"; |
||
| 882 | print_notice("System plugins are enabled in <strong>config.php</strong> for all users."); |
||
| 883 | |||
| 884 | $system_enabled = array_map("trim", explode(",", PLUGINS)); |
||
| 885 | $user_enabled = array_map("trim", explode(",", get_pref("_ENABLED_PLUGINS"))); |
||
| 886 | |||
| 887 | $tmppluginhost = new PluginHost(); |
||
| 888 | $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"], true); |
||
| 889 | $tmppluginhost->load_data(); |
||
| 890 | |||
| 891 | foreach ($tmppluginhost->get_plugins() as $name => $plugin) { |
||
| 892 | $about = $plugin->about(); |
||
| 893 | |||
| 894 | if ($about[3]) { |
||
| 895 | if (in_array($name, $system_enabled)) { |
||
| 896 | $checked = "checked='1'"; |
||
| 897 | } else { |
||
| 898 | $checked = ""; |
||
| 899 | } |
||
| 900 | |||
| 901 | print "<fieldset class='prefs plugin'> |
||
| 902 | <label>$name:</label> |
||
| 903 | <label class='checkbox description text-muted' id='PLABEL-$name'> |
||
| 904 | <input disabled='1' |
||
| 905 | dojoType='dijit.form.CheckBox' $checked type='checkbox'> |
||
| 906 | ".htmlspecialchars($about[1])."</label>"; |
||
| 907 | |||
| 908 | if (@$about[4]) { |
||
| 909 | print "<button dojoType='dijit.form.Button' class='alt-info' |
||
| 910 | onclick='window.open(\"".htmlspecialchars($about[4])."\")'> |
||
| 911 | <i class='material-icons'>open_in_new</i> ".__("More info...")."</button>"; |
||
| 912 | } |
||
| 913 | |||
| 914 | print "<div dojoType='dijit.Tooltip' connectId='PLABEL-$name' position='after'>". |
||
| 915 | htmlspecialchars(T_sprintf("v%.2f, by %s", $about[0], $about[2])). |
||
| 916 | "</div>"; |
||
| 917 | |||
| 918 | print "</fieldset>"; |
||
| 919 | |||
| 920 | } |
||
| 921 | } |
||
| 922 | |||
| 923 | print "<h2>".__("User plugins")."</h2>"; |
||
| 924 | |||
| 925 | foreach ($tmppluginhost->get_plugins() as $name => $plugin) { |
||
| 926 | $about = $plugin->about(); |
||
| 927 | |||
| 928 | if (!$about[3]) { |
||
| 929 | |||
| 930 | $checked = ""; |
||
| 931 | $disabled = ""; |
||
| 932 | |||
| 933 | if (in_array($name, $system_enabled)) { |
||
| 934 | $checked = "checked='1'"; |
||
| 935 | $disabled = "disabled='1'"; |
||
| 936 | } else if (in_array($name, $user_enabled)) { |
||
| 937 | $checked = "checked='1'"; |
||
| 938 | } |
||
| 939 | |||
| 940 | print "<fieldset class='prefs plugin'> |
||
| 941 | <label>$name:</label> |
||
| 942 | <label class='checkbox description text-muted' id='PLABEL-$name'> |
||
| 943 | <input name='plugins[]' value='$name' dojoType='dijit.form.CheckBox' $checked $disabled type='checkbox'> |
||
| 944 | ".htmlspecialchars($about[1])."</label>"; |
||
| 945 | |||
| 946 | if (count($tmppluginhost->get_all($plugin)) > 0) { |
||
| 947 | if (in_array($name, $system_enabled) || in_array($name, $user_enabled)) { |
||
| 948 | print " <button dojoType='dijit.form.Button' |
||
| 949 | onclick=\"Helpers.clearPluginData('$name')\"> |
||
| 950 | <i class='material-icons'>clear</i> ".__("Clear data")."</button>"; |
||
| 951 | } |
||
| 952 | } |
||
| 953 | |||
| 954 | if (@$about[4]) { |
||
| 955 | print " <button dojoType='dijit.form.Button' class='alt-info' |
||
| 956 | onclick='window.open(\"".htmlspecialchars($about[4])."\")'> |
||
| 957 | <i class='material-icons'>open_in_new</i> ".__("More info...")."</button>"; |
||
| 958 | } |
||
| 959 | |||
| 960 | print "<div dojoType='dijit.Tooltip' connectId='PLABEL-$name' position='after'>". |
||
| 961 | htmlspecialchars(T_sprintf("v%.2f, by %s", $about[0], $about[2])). |
||
| 962 | "</div>"; |
||
| 963 | |||
| 964 | print "</fieldset>"; |
||
| 965 | } |
||
| 966 | } |
||
| 967 | |||
| 968 | print "</div>"; #content-pane |
||
| 969 | print '<div dojoType="dijit.layout.ContentPane" region="bottom">'; |
||
| 970 | |||
| 971 | print "<button dojoType='dijit.form.Button' style='float : left' class='alt-info' onclick='window.open(\"https://tt-rss.org/wiki/Plugins\")'> |
||
| 972 | <i class='material-icons'>help</i> ".__("More info...")."</button>"; |
||
| 973 | |||
| 974 | print "<button dojoType='dijit.form.Button' class='alt-primary' type='submit'>". |
||
| 975 | __("Enable selected plugins")."</button>"; |
||
| 976 | print "</div>"; #pane |
||
| 977 | |||
| 978 | print "</div>"; #pane |
||
| 979 | print "</div>"; #border-container |
||
| 980 | |||
| 981 | print "</form>"; |
||
| 982 | |||
| 983 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, |
||
| 984 | "hook_prefs_tab", "prefPrefs"); |
||
| 985 | |||
| 986 | print "</div>"; #container |
||
| 987 | |||
| 1359 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.