create.class.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * Loads the edit file page
  4. *
  5. * @package modx
  6. * @subpackage manager.controllers
  7. */
  8. class SystemFileCreateManagerController extends modManagerController {
  9. /** @var string The directory to create in */
  10. public $directory = '';
  11. /** @var modMediaSource $source */
  12. public $source = null;
  13. /**
  14. * Check for any permissions or requirements to load page
  15. * @return bool
  16. */
  17. public function checkPermissions() {
  18. return $this->modx->hasPermission('file_create');
  19. }
  20. /**
  21. * Specify the language topics to load
  22. * @return array
  23. */
  24. public function getLanguageTopics() {
  25. return array('file');
  26. }
  27. /**
  28. * Register custom CSS/JS for the page
  29. * @return void
  30. */
  31. public function loadCustomCssJs() {
  32. $this->addJavascript($this->modx->getOption('manager_url').'assets/modext/sections/system/file/create.js');
  33. $this->addHtml('<script type="text/javascript">Ext.onReady(function() {
  34. MODx.load({
  35. xtype: "modx-page-file-create"
  36. ,record: {
  37. directory: "'.$this->directory.'",
  38. source: "'.$this->source->get('id') .'"
  39. }
  40. });
  41. });</script>');
  42. }
  43. /**
  44. * Custom logic code here for setting placeholders, etc
  45. * @param array $scriptProperties
  46. * @return mixed
  47. */
  48. public function process(array $scriptProperties = array()) {
  49. $placeholders = array();
  50. $this->modx->lexicon->load('file');
  51. $this->getSource();
  52. $directory = !empty($scriptProperties['directory']) ? $scriptProperties['directory'] : '';
  53. $this->directory = ltrim(strip_tags(str_replace(array('../','./'),'',$directory)),'/');
  54. $this->directory = htmlspecialchars(strip_tags($this->directory));
  55. $this->loadWorkingContext();
  56. $placeholders['OnFileCreateFormPrerender'] = $this->fireEvents();
  57. return $placeholders;
  58. }
  59. /**
  60. * Get the active source
  61. * @return modMediaSource
  62. */
  63. public function getSource() {
  64. /** @var modMediaSource|modFileMediaSource $source */
  65. if (!$this->source) {
  66. $this->modx->loadClass('sources.modMediaSource');
  67. $source = $this->modx->getOption('source',$this->scriptProperties,false);
  68. if (!empty($source)) {
  69. $source = $this->modx->getObject('source.modMediaSource',$source);
  70. }
  71. if (empty($source)) {
  72. $source = modMediaSource::getDefaultSource($this->modx);
  73. }
  74. if (!$source->getWorkingContext()) {
  75. return $this->failure($this->modx->lexicon('permission_denied'));
  76. }
  77. $source->setRequestProperties($this->scriptProperties);
  78. $source->initialize();
  79. $this->source = $source;
  80. }
  81. return $this->source;
  82. }
  83. /**
  84. * Invoke OnFileEditFormPrerender event
  85. * @return string
  86. */
  87. public function fireEvents() {
  88. $OnFileCreateFormPrerender = $this->modx->invokeEvent('OnFileCreateFormPrerender',array(
  89. 'mode' => modSystemEvent::MODE_NEW,
  90. 'directory' => $this->directory,
  91. ));
  92. if (is_array($OnFileCreateFormPrerender)) $OnFileCreateFormPrerender = implode('',$OnFileCreateFormPrerender);
  93. return $OnFileCreateFormPrerender;
  94. }
  95. /**
  96. * Return the pagetitle
  97. *
  98. * @return string
  99. */
  100. public function getPageTitle() {
  101. return $this->modx->lexicon('file_create');
  102. }
  103. /**
  104. * Return the location of the template file
  105. * @return string
  106. */
  107. public function getTemplateFile() {
  108. return '';
  109. }
  110. }