Subversion Repositories oidplus

Rev

Rev 1050 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4. * MIT License
  5. *
  6. * Copyright (c) 2022 Simon Tushev
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in all
  16. * copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  24. * SOFTWARE.
  25. */
  26.  
  27. namespace TushevOrg\OIDplus;
  28.  
  29. use ViaThinkSoft\OIDplus\OIDplus;
  30. use ViaThinkSoft\OIDplus\OIDplusConfig;
  31. use ViaThinkSoft\OIDplus\OIDplusException;
  32. use ViaThinkSoft\OIDplus\OIDplusPagePluginPublic;
  33.  
  34. // phpcs:disable PSR1.Files.SideEffects
  35. \defined('INSIDE_OIDPLUS') or die;
  36. // phpcs:enable PSR1.Files.SideEffects
  37.  
  38. class OIDplusPagePublicUITweaks extends OIDplusPagePluginPublic {
  39.  
  40.         public function init($html=true) {
  41.                 OIDplus::config()->prepareConfigKey('uitweaks_expand_objects_tree', 'UITweaks plugin: 1=Fully expand objects tree on page reload, 0=Default behavior', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
  42.                         if (!is_numeric($value) || ($value < 0) || ($value > 1)) {
  43.                                 throw new OIDplusException(_L('Please enter a valid value.'));
  44.                         }
  45.                 });
  46.                 OIDplus::config()->prepareConfigKey('uitweaks_collapse_login_tree', 'UITweaks plugin: 1=Collapse login tree on page reload, 0=Default behavior', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
  47.                         if (!is_numeric($value) || ($value < 0) || ($value > 1)) {
  48.                                 throw new OIDplusException(_L('Please enter a valid value.'));
  49.                         }
  50.                 });
  51.                 OIDplus::config()->prepareConfigKey('uitweaks_collapse_res_tree', 'UITweaks plugin: 1=Collapse Documents&Resources tree on page reload, 0=Default behavior', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
  52.                         if (!is_numeric($value) || ($value < 0) || ($value > 1)) {
  53.                                 throw new OIDplusException(_L('Please enter a valid value.'));
  54.                         }
  55.                 });
  56.                 OIDplus::config()->prepareConfigKey('uitweaks_prefer_admin_login_tab', 'UITweaks plugin: 1=Prefer `Login as administrator` tab at login, 0=Default behavior', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
  57.                         if (!is_numeric($value) || ($value < 0) || ($value > 1)) {
  58.                                 throw new OIDplusException(_L('Please enter a valid value.'));
  59.                         }
  60.                 });
  61.  
  62.                 OIDplus::config()->prepareConfigKey('uitweaks_menu_width', 'UITweaks plugin: default width of tree pane (in px)', '450', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
  63.                         if (!is_numeric($value) || ($value < 0)) {
  64.                                 throw new OIDplusException(_L('Please enter a valid value.'));
  65.                         }
  66.                 });
  67.                 OIDplus::config()->prepareConfigKey('uitweaks_menu_remember_width', 'UITweaks plugin: 1=Remember menu width (save to browser.localStorage), 0=Default behavior', '1', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
  68.                         if (!is_numeric($value) || ($value < 0) || ($value > 1)) {
  69.                                 throw new OIDplusException(_L('Please enter a valid value.'));
  70.                         }
  71.                 });
  72.         }
  73.  
  74.         public function htmlHeaderUpdate(&$head_elems) {
  75.                 $w  = js_escape(OIDplus::config()->getValue('uitweaks_menu_width'));
  76.                 $rw = OIDplus::config()->getValue('uitweaks_menu_remember_width')               == 1 ? 'true' : 'false';
  77.                 $o  = OIDplus::config()->getValue('uitweaks_expand_objects_tree')               == 1 ? 'true' : 'false';
  78.                 $l  = OIDplus::config()->getValue('uitweaks_collapse_login_tree')               == 1 ? 'true' : 'false';
  79.                 $r  = OIDplus::config()->getValue('uitweaks_collapse_res_tree')                 == 1 ? 'true' : 'false';
  80.                 $r  = OIDplus::config()->getValue('uitweaks_prefer_admin_login_tab')    == 1 ? 'true' : 'false';
  81.  
  82.                 $s  = "<script>\n";
  83.                 $s .= "  oidplus_menu_width = $w;\n";
  84.                 $s .= "  let uitweaks = {\n";
  85.                 $s .= "    \"menu_remember_width\":     $rw,\n";
  86.                 $s .= "    \"expand_objects_tree\":     $o,\n";
  87.                 $s .= "    \"collapse_login_tree\":     $l,\n";
  88.                 $s .= "    \"collapse_res_tree\":       $r,\n";
  89.                 $s .= "    \"prefer_admin_login_tab\":  $r,\n";
  90.                 $s .= "  };\n";
  91.                 $s .= "</script>";
  92.  
  93.                 $head_elems[] = $s;
  94.         }
  95.  
  96.  
  97.  
  98. }
  99.