create.class.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /**
  3. * Load create chunk page
  4. *
  5. * @package modx
  6. * @subpackage manager.controllers
  7. */
  8. class ElementChunkCreateManagerController extends modManagerController {
  9. public $category;
  10. public $onChunkFormRender;
  11. public $onChunkFormPrerender;
  12. /**
  13. * Check for any permissions or requirements to load page
  14. * @return bool
  15. */
  16. public function checkPermissions() {
  17. return $this->modx->hasPermission('new_chunk');
  18. }
  19. /**
  20. * Register custom CSS/JS for the page
  21. * @return void
  22. */
  23. public function loadCustomCssJs() {
  24. $mgrUrl = $this->modx->getOption('manager_url',null,MODX_MANAGER_URL);
  25. $this->addJavascript($mgrUrl.'assets/modext/widgets/core/modx.grid.local.property.js');
  26. $this->addJavascript($mgrUrl.'assets/modext/widgets/element/modx.grid.element.properties.js');
  27. $this->addJavascript($mgrUrl.'assets/modext/widgets/element/modx.panel.chunk.js');
  28. $this->addJavascript($mgrUrl.'assets/modext/sections/element/chunk/create.js');
  29. $this->addHtml('
  30. <script type="text/javascript">
  31. // <![CDATA[
  32. Ext.onReady(function() {
  33. MODx.load({
  34. xtype: "modx-page-chunk-create"
  35. ,record: {
  36. category: "'.($this->category ? $this->category->get('id') : 0).'"
  37. }
  38. });
  39. });
  40. MODx.onChunkFormRender = "'.$this->onChunkFormRender.'";
  41. MODx.perm.unlock_element_properties = '.($this->modx->hasPermission('unlock_element_properties') ? 1 : 0).';
  42. // ]]>
  43. </script>');
  44. }
  45. /**
  46. * Custom logic code here for setting placeholders, etc
  47. * @param array $scriptProperties
  48. * @return mixed
  49. */
  50. public function process(array $scriptProperties = array()) {
  51. $placeholders = array();
  52. $placeholders['category'] = $this->getCategory($scriptProperties);
  53. /* invoke OnChunkFormRender event */
  54. $placeholders['onChunkFormRender'] = $this->fireRenderEvent();
  55. $placeholders['onRTEInit'] = $this->loadRte();
  56. return $placeholders;
  57. }
  58. /**
  59. * Get the current category
  60. *
  61. * @param array $scriptProperties
  62. * @return void|modCategory
  63. */
  64. public function getCategory(array $scriptProperties = array()) {
  65. /* grab default category if specified */
  66. if (isset($scriptProperties['category'])) {
  67. $this->category = $this->modx->getObject('modCategory',$scriptProperties['category']);
  68. } else { $this->category = null; }
  69. return $this->category;
  70. }
  71. /**
  72. * Invoke OnRichTextEditorInit event, loading the RTE
  73. * @return string
  74. */
  75. public function loadRte() {
  76. $o = '';
  77. if ($this->modx->getOption('use_editor') == 1) {
  78. $onRTEInit = $this->modx->invokeEvent('OnRichTextEditorInit',array(
  79. 'elements' => array('post'),
  80. 'mode' => modSystemEvent::MODE_NEW,
  81. ));
  82. if (is_array($onRTEInit)) {
  83. $onRTEInit = implode('', $onRTEInit);
  84. }
  85. $o = $onRTEInit;
  86. }
  87. return $o;
  88. }
  89. /**
  90. * Fire the OnChunkFormRender event
  91. * @return mixed
  92. */
  93. public function fireRenderEvent() {
  94. $this->onChunkFormRender = $this->modx->invokeEvent('OnChunkFormRender',array(
  95. 'id' => 0,
  96. 'mode' => modSystemEvent::MODE_NEW,
  97. 'chunk' => null,
  98. ));
  99. if (is_array($this->onChunkFormRender)) $this->onChunkFormRender = implode('', $this->onChunkFormRender);
  100. $this->onChunkFormRender = str_replace(array('"',"\n","\r"),array('\"','',''),$this->onChunkFormRender);
  101. return $this->onChunkFormRender;
  102. }
  103. /**
  104. * Fire the OnChunkFormPrerender event
  105. * @return mixed
  106. */
  107. public function firePreRenderEvents() {
  108. /* PreRender events inject directly into the HTML, as opposed to the JS-based Render event which injects HTML
  109. into the panel */
  110. $this->onChunkFormPrerender = $this->modx->invokeEvent('OnChunkFormPrerender',array(
  111. 'id' => 0,
  112. 'mode' => modSystemEvent::MODE_NEW,
  113. 'chunk' => null,
  114. ));
  115. if (is_array($this->onChunkFormPrerender)) { $this->onChunkFormPrerender = implode('',$this->onChunkFormPrerender); }
  116. $this->setPlaceholder('onChunkFormPrerender', $this->onChunkFormPrerender);
  117. }
  118. /**
  119. * Return the pagetitle
  120. *
  121. * @return string
  122. */
  123. public function getPageTitle() {
  124. return $this->modx->lexicon('chunk_new');
  125. }
  126. /**
  127. * Return the location of the template file
  128. * @return string
  129. */
  130. public function getTemplateFile() {
  131. return 'element/chunk/create.tpl';
  132. }
  133. /**
  134. * Specify the language topics to load
  135. * @return array
  136. */
  137. public function getLanguageTopics() {
  138. return array('chunk','category','propertyset','element');
  139. }
  140. /**
  141. * Get the Help URL
  142. * @return string
  143. */
  144. public function getHelpUrl() {
  145. return 'Chunks';
  146. }
  147. }