create.class.php 3.9 KB

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