update.class.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. /**
  3. * Loads the view context preview page.
  4. *
  5. * @package modx
  6. * @subpackage manager.controllers
  7. */
  8. class ContextUpdateManagerController extends modManagerController {
  9. /**
  10. * The key of the current context
  11. * @var string $contextKey
  12. */
  13. public $contextKey;
  14. /**
  15. * The return value from the OnContextFormRender event
  16. * @var string $onContextFormRender
  17. */
  18. public $onContextFormRender;
  19. /**
  20. * The context to update.
  21. * @var modContext $context
  22. */
  23. public $context;
  24. /**
  25. * Check for any permissions or requirements to load page
  26. * @return bool
  27. */
  28. public function checkPermissions() {
  29. return $this->modx->hasPermission('edit_context');
  30. }
  31. /**
  32. * Get the context to update
  33. * @return void
  34. */
  35. public function initialize() {
  36. $this->context= $this->modx->getObjectGraph('modContext', '{"ContextSettings":{}}', array('key' => $this->scriptProperties['key']));
  37. if ($this->context) {
  38. $this->contextKey = $this->context->get('key');
  39. }
  40. }
  41. /**
  42. * Register custom CSS/JS for the page
  43. * @return void
  44. */
  45. public function loadCustomCssJs() {
  46. $mgrUrl = $this->modx->getOption('manager_url',null,MODX_MANAGER_URL);
  47. $perm = (bool)$this->modx->hasPermission('new_context');
  48. $this->addHtml("<script>
  49. // <![CDATA[
  50. MODx.onContextFormRender = '".$this->onContextFormRender."';
  51. MODx.ctx = '".$this->contextKey."';
  52. MODx.perm.new_context = {$perm};
  53. Ext.onReady(function() {
  54. MODx.add('modx-page-context-update');
  55. });
  56. // ]]>
  57. </script>");
  58. $this->addJavascript($mgrUrl.'assets/modext/widgets/security/modx.grid.access.context.js');
  59. $this->addJavascript($mgrUrl.'assets/modext/widgets/core/modx.grid.settings.js');
  60. $this->addJavascript($mgrUrl.'assets/modext/widgets/system/modx.grid.context.settings.js');
  61. $this->addJavascript($mgrUrl.'assets/modext/widgets/system/modx.panel.context.js');
  62. $this->addJavascript($mgrUrl.'assets/modext/sections/context/update.js');
  63. }
  64. /**
  65. * Custom logic code here for setting placeholders, etc
  66. * @param array $scriptProperties
  67. * @return mixed
  68. */
  69. public function process(array $scriptProperties = array()) {
  70. if (empty($this->context)) {
  71. return $this->failure(sprintf($this->modx->lexicon('context_with_key_not_found'), $this->scriptProperties['key']));
  72. }
  73. if (!$this->context->checkPolicy(array('view' => true, 'save' => true))) {
  74. return $this->failure($this->modx->lexicon('permission_denied'));
  75. }
  76. /* prepare context data for display */
  77. if (!$this->context->prepare()) {
  78. return $this->failure($this->modx->lexicon('context_err_load_data'), $this->context->toArray());
  79. }
  80. /* invoke OnContextFormPrerender event */
  81. $this->setPlaceholder('OnContextFormPrerender',$this->onPreRender());
  82. /* invoke OnContextFormRender event */
  83. $this->setPlaceholder('OnContextFormRender',$this->onRender());
  84. /* assign context to smarty and display */
  85. $this->setPlaceholder('context',$this->context);
  86. $this->setPlaceholder('_ctx',$this->context->get('key'));
  87. return null;
  88. }
  89. /**
  90. * @return mixed
  91. */
  92. public function onPreRender() {
  93. $onContextFormPrerender = $this->modx->invokeEvent('OnContextFormPrerender',array(
  94. 'key' => $this->context->get('key'),
  95. 'context' => &$this->context,
  96. 'mode' => modSystemEvent::MODE_UPD,
  97. ));
  98. if (is_array($onContextFormPrerender)) $onContextFormPrerender = implode('',$onContextFormPrerender);
  99. return $onContextFormPrerender;
  100. }
  101. /**
  102. * @return mixed
  103. */
  104. public function onRender() {
  105. $this->onContextFormRender = $this->modx->invokeEvent('OnContextFormRender',array(
  106. 'key' => $this->context->get('key'),
  107. 'context' => &$this->context,
  108. 'mode' => modSystemEvent::MODE_UPD,
  109. ));
  110. if (is_array($this->onContextFormRender)) $this->onContextFormRender = implode('',$this->onContextFormRender);
  111. $this->onContextFormRender = str_replace(array('"',"\n","\r"),array('\"','',''),$this->onContextFormRender);
  112. return $this->onContextFormRender;
  113. }
  114. /**
  115. * Return the pagetitle
  116. *
  117. * @return string
  118. */
  119. public function getPageTitle() {
  120. return $this->modx->lexicon('context').': '.$this->contextKey;
  121. }
  122. /**
  123. * Return the location of the template file
  124. * @return string
  125. */
  126. public function getTemplateFile() {
  127. return '';
  128. }
  129. /**
  130. * Specify the language topics to load
  131. * @return array
  132. */
  133. public function getLanguageTopics() {
  134. return array('context','setting','access','policy','user');
  135. }
  136. /**
  137. * Get the Help URL
  138. * @return string
  139. */
  140. public function getHelpUrl() {
  141. return 'Contexts';
  142. }
  143. }