home.class.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. require_once dirname(__DIR__) . '/index.class.php';
  3. /**
  4. * The name of the controller is based on the path (home) and the
  5. * namespace (clientconfig). This home controller is the main client view.
  6. */
  7. class ClientConfigHomeManagerController extends ClientConfigManagerController {
  8. public $tabs = array();
  9. /**
  10. * Any specific processing we need on the Home controller.
  11. * In this case, we get all groups and all settings in the group.
  12. * @param array $scriptProperties
  13. */
  14. public function process(array $scriptProperties = array()) {
  15. $tabs = array();
  16. /**
  17. * Get all the Groups
  18. * @var cgGroup $group
  19. * @var cgSetting $setting
  20. */
  21. $c = $this->modx->newQuery('cgGroup');
  22. $c->sortby('sortorder','ASC');
  23. $c->sortby('label','ASC');
  24. $groups = $this->modx->getCollection('cgGroup', $c);
  25. foreach ($groups as $group) {
  26. $grp = $group->toArray();
  27. $grp['items'] = array();
  28. $c = $this->modx->newQuery('cgSetting');
  29. $c->sortby('sortorder','ASC');
  30. $c->sortby('label','ASC');
  31. foreach ($group->getMany('Settings', $c) as $setting) {
  32. $sa = $setting->toArray();
  33. if (in_array($sa['xtype'], array('checkbox','xcheckbox'), true)) {
  34. $sa['value'] = (bool)$sa['value'];
  35. }
  36. if ($sa['xtype'] === 'googlefontlist') {
  37. $googleFontsApiKey = $this->modx->getOption('clientconfig.google_fonts_api_key', null, '');
  38. $sa['xtype'] = empty($googleFontsApiKey) ? 'textfield' : $sa['xtype'];
  39. }
  40. elseif ($sa['xtype'] === 'modx-combo' && $setting->get('process_options')) {
  41. $inputOpts = $setting->get('options');
  42. $this->modx->getParser();
  43. $this->modx->parser->processElementTags('', $inputOpts, true, true);
  44. $sa['options'] = $inputOpts;
  45. }
  46. $grp['items'][] = $sa;
  47. }
  48. $tabs[] = $grp;
  49. }
  50. $this->loadRichTextEditor();
  51. $this->tabs = $tabs;
  52. if (array_key_exists('context', $scriptProperties) && $this->modx->getOption('clientconfig.context_aware')) {
  53. $key = $scriptProperties['context'];
  54. $context = $this->modx->getObject('modContext', ['key' => $key]);
  55. if ($context instanceof modContext) {
  56. $this->addHtml('<script type="text/javascript">
  57. Ext.onReady(function() {
  58. ClientConfig.initialContext = ' . $context->toJSON() . ';
  59. });
  60. </script>');
  61. }
  62. }
  63. }
  64. /**
  65. * The pagetitle to put in the <title> attribute.
  66. * @return null|string
  67. */
  68. public function getPageTitle() {
  69. return $this->modx->lexicon('clientconfig');
  70. }
  71. /**
  72. * Register all the needed javascript files. Using this method, it will automagically
  73. * combine and compress them if enabled in system settings.
  74. */
  75. public function loadCustomCssJs() {
  76. $this->addCss($this->clientconfig->config['jsUrl'] . 'mgr/extras/colorpicker/colorpicker.css');
  77. $mgrUrl = $this->modx->getOption('manager_url',null,MODX_MANAGER_URL);
  78. $this->addJavascript($mgrUrl.'assets/modext/widgets/element/modx.panel.tv.renders.js');
  79. $this->addJavascript($this->clientconfig->config['jsUrl'].'mgr/extras/colorpicker/colorpicker.js');
  80. $this->addJavascript($this->clientconfig->config['jsUrl'].'mgr/extras/colorpicker/colorpickerfield.js');
  81. $this->addJavascript($this->clientconfig->config['jsUrl'].'mgr/widgets/combos.js');
  82. $this->addLastJavascript($this->clientconfig->config['jsUrl'].'mgr/sections/home.js');
  83. $contextAware = $this->modx->getOption('clientconfig.context_aware') ? 'true' : 'false';
  84. $this->addHtml('<script type="text/javascript">
  85. Ext.onReady(function() {
  86. ClientConfig.data = '.$this->modx->toJSON($this->tabs).';
  87. ClientConfig.contextAware = ' . $contextAware . ';
  88. ClientConfig.isAdmin = ' . (($this->clientconfig->hasAdminPermission()) ? '1' : '0') .';
  89. MODx.load({ xtype: "clientconfig-page-home" });
  90. });
  91. </script>');
  92. }
  93. /**
  94. * The name for the template file to load.
  95. * @return string
  96. */
  97. public function getTemplateFile() {
  98. return $this->clientconfig->config['templatesPath'].'home.tpl';
  99. }
  100. }