create.class.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /*
  3. * This file is part of MODX Revolution.
  4. *
  5. * Copyright (c) MODX, LLC. All Rights Reserved.
  6. *
  7. * For complete copyright and license information, see the COPYRIGHT and LICENSE
  8. * files found in the top-level directory of this distribution.
  9. */
  10. /**
  11. * Load create plugin page
  12. *
  13. * @package modx
  14. * @subpackage manager.controllers
  15. */
  16. class ElementPluginCreateManagerController extends modManagerController {
  17. public $category;
  18. public $onPluginFormRender = '';
  19. public $onPluginFormPrerender = '';
  20. /**
  21. * Check for any permissions or requirements to load page
  22. * @return bool
  23. */
  24. public function checkPermissions() {
  25. return $this->modx->hasPermission('new_plugin');
  26. }
  27. /**
  28. * Register custom CSS/JS for the page
  29. * @return void
  30. */
  31. public function loadCustomCssJs() {
  32. $mgrUrl = $this->modx->getOption('manager_url',null,MODX_MANAGER_URL);
  33. $this->addJavascript($mgrUrl.'assets/modext/widgets/core/modx.grid.local.property.js');
  34. $this->addJavascript($mgrUrl.'assets/modext/widgets/element/modx.grid.element.properties.js');
  35. $this->addJavascript($mgrUrl.'assets/modext/widgets/element/modx.grid.plugin.event.js');
  36. $this->addJavascript($mgrUrl.'assets/modext/widgets/element/modx.panel.plugin.js');
  37. $this->addJavascript($mgrUrl.'assets/modext/sections/element/plugin/create.js');
  38. $this->addHtml('
  39. <script type="text/javascript">
  40. // <![CDATA[
  41. Ext.onReady(function() {
  42. MODx.load({
  43. xtype: "modx-page-plugin-create"
  44. ,record: {
  45. category: "'.($this->category ? $this->category->get('id') : 0).'"
  46. }
  47. });
  48. });
  49. MODx.onPluginFormRender = "'.$this->onPluginFormRender.'";
  50. MODx.perm.unlock_element_properties = "'.($this->modx->hasPermission('unlock_element_properties') ? 1 : 0).'";
  51. // ]]>
  52. </script>');
  53. }
  54. /**
  55. * Custom logic code here for setting placeholders, etc
  56. * @param array $scriptProperties
  57. * @return mixed
  58. */
  59. public function process(array $scriptProperties = array()) {
  60. $placeholders = array();
  61. /* grab category if preset */
  62. if (isset($scriptProperties['category'])) {
  63. $this->category = $this->modx->getObject('modCategory',$scriptProperties['category']);
  64. if ($this->category != null) {
  65. $placeholders['category'] = $this->category;
  66. }
  67. }
  68. /* invoke OnPluginFormRender event */
  69. $placeholders['onPluginFormRender'] = $this->fireRenderEvent();
  70. return $placeholders;
  71. }
  72. /**
  73. * Invoke OnPluginFormPrerender event
  74. * @return void
  75. */
  76. public function firePreRenderEvents() {
  77. /* PreRender events inject directly into the HTML, as opposed to the JS-based Render event which injects HTML
  78. into the panel */
  79. $this->onPluginFormPrerender = $this->modx->invokeEvent('OnPluginFormPrerender',array(
  80. 'id' => 0,
  81. 'mode' => modSystemEvent::MODE_NEW,
  82. ));
  83. if (is_array($this->onPluginFormPrerender)) $this->onPluginFormPrerender = implode('',$this->onPluginFormPrerender);
  84. $this->setPlaceholder('onPluginFormPrerender', $this->onPluginFormPrerender);
  85. }
  86. /**
  87. * Invoke OnPluginFormRender event
  88. * @return string
  89. */
  90. public function fireRenderEvent() {
  91. $this->onPluginFormRender = $this->modx->invokeEvent('OnPluginFormRender',array(
  92. 'id' => 0,
  93. 'mode' => modSystemEvent::MODE_NEW,
  94. ));
  95. if (is_array($this->onPluginFormRender)) $this->onPluginFormRender = implode('',$this->onPluginFormRender);
  96. $this->onPluginFormRender = str_replace(array('"',"\n","\r"),array('\"','',''),$this->onPluginFormRender);
  97. return $this->onPluginFormRender;
  98. }
  99. /**
  100. * Return the pagetitle
  101. *
  102. * @return string
  103. */
  104. public function getPageTitle() {
  105. return $this->modx->lexicon('plugin_new');
  106. }
  107. /**
  108. * Return the location of the template file
  109. * @return string
  110. */
  111. public function getTemplateFile() {
  112. return 'element/plugin/create.tpl';
  113. }
  114. /**
  115. * Specify the language topics to load
  116. * @return array
  117. */
  118. public function getLanguageTopics() {
  119. return array('plugin','category','system_events','propertyset','element');
  120. }
  121. /**
  122. * Get the Help URL
  123. * @return string
  124. */
  125. public function getHelpUrl() {
  126. return 'Plugins';
  127. }
  128. }