create.class.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * Load create plugin page
  4. *
  5. * @package modx
  6. * @subpackage manager.controllers
  7. */
  8. class ElementPluginCreateManagerController extends modManagerController {
  9. public $category;
  10. public $onPluginFormRender = '';
  11. public $onPluginFormPrerender = '';
  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_plugin');
  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.grid.plugin.event.js');
  28. $this->addJavascript($mgrUrl.'assets/modext/widgets/element/modx.panel.plugin.js');
  29. $this->addJavascript($mgrUrl.'assets/modext/sections/element/plugin/create.js');
  30. $this->addHtml('
  31. <script type="text/javascript">
  32. // <![CDATA[
  33. Ext.onReady(function() {
  34. MODx.load({
  35. xtype: "modx-page-plugin-create"
  36. ,record: {
  37. category: "'.($this->category ? $this->category->get('id') : 0).'"
  38. }
  39. });
  40. });
  41. MODx.onPluginFormRender = "'.$this->onPluginFormRender.'";
  42. MODx.perm.unlock_element_properties = "'.($this->modx->hasPermission('unlock_element_properties') ? 1 : 0).'";
  43. // ]]>
  44. </script>');
  45. }
  46. /**
  47. * Custom logic code here for setting placeholders, etc
  48. * @param array $scriptProperties
  49. * @return mixed
  50. */
  51. public function process(array $scriptProperties = array()) {
  52. $placeholders = array();
  53. /* grab category if preset */
  54. if (isset($scriptProperties['category'])) {
  55. $this->category = $this->modx->getObject('modCategory',$scriptProperties['category']);
  56. if ($this->category != null) {
  57. $placeholders['category'] = $this->category;
  58. }
  59. }
  60. /* invoke OnPluginFormRender event */
  61. $placeholders['onPluginFormRender'] = $this->fireRenderEvent();
  62. return $placeholders;
  63. }
  64. /**
  65. * Invoke OnPluginFormPrerender event
  66. * @return void
  67. */
  68. public function firePreRenderEvents() {
  69. /* PreRender events inject directly into the HTML, as opposed to the JS-based Render event which injects HTML
  70. into the panel */
  71. $this->onPluginFormPrerender = $this->modx->invokeEvent('OnPluginFormPrerender',array(
  72. 'id' => 0,
  73. 'mode' => modSystemEvent::MODE_NEW,
  74. ));
  75. if (is_array($this->onPluginFormPrerender)) $this->onPluginFormPrerender = implode('',$this->onPluginFormPrerender);
  76. $this->setPlaceholder('onPluginFormPrerender', $this->onPluginFormPrerender);
  77. }
  78. /**
  79. * Invoke OnPluginFormRender event
  80. * @return string
  81. */
  82. public function fireRenderEvent() {
  83. $this->onPluginFormRender = $this->modx->invokeEvent('OnPluginFormRender',array(
  84. 'id' => 0,
  85. 'mode' => modSystemEvent::MODE_NEW,
  86. ));
  87. if (is_array($this->onPluginFormRender)) $this->onPluginFormRender = implode('',$this->onPluginFormRender);
  88. $this->onPluginFormRender = str_replace(array('"',"\n","\r"),array('\"','',''),$this->onPluginFormRender);
  89. return $this->onPluginFormRender;
  90. }
  91. /**
  92. * Return the pagetitle
  93. *
  94. * @return string
  95. */
  96. public function getPageTitle() {
  97. return $this->modx->lexicon('plugin_new');
  98. }
  99. /**
  100. * Return the location of the template file
  101. * @return string
  102. */
  103. public function getTemplateFile() {
  104. return 'element/plugin/create.tpl';
  105. }
  106. /**
  107. * Specify the language topics to load
  108. * @return array
  109. */
  110. public function getLanguageTopics() {
  111. return array('plugin','category','system_events','propertyset','element');
  112. }
  113. /**
  114. * Get the Help URL
  115. * @return string
  116. */
  117. public function getHelpUrl() {
  118. return 'Plugins';
  119. }
  120. }