PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/core/model/modx/processors/browser/directory/chmod.class.php

http://github.com/modxcms/revolution
PHP | 78 lines | 47 code | 7 blank | 24 comment | 6 complexity | aed195ec5cf33e88a2531a8171a0ff2b MD5 | raw file
Possible License(s): GPL-2.0, Apache-2.0, BSD-3-Clause, LGPL-2.1
  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. * Chmod a directory
  12. *
  13. * @param string $mode The mode to chmod to
  14. * @param string $dir The absolute path of the dir
  15. * @param boolean $prependPath (optional) If true, will prepend rb_base_dir to
  16. * the final path
  17. *
  18. * @package modx
  19. * @subpackage processors.browser.directory
  20. */
  21. class modBrowserFolderChmodProcessor extends modProcessor {
  22. /** @var modMediaSource|modFileMediaSource $source */
  23. public $source;
  24. public function checkPermissions() {
  25. return $this->modx->hasPermission('directory_chmod');
  26. }
  27. public function getLanguageTopics() {
  28. return array('file');
  29. }
  30. public function initialize() {
  31. $this->setDefaultProperties(array(
  32. 'mode' => false,
  33. 'dir' => false,
  34. ));
  35. if (!$this->getProperty('mode')) return $this->modx->lexicon('file_err_chmod_ns');
  36. if (!$this->getProperty('dir')) return $this->modx->lexicon('file_folder_err_ns');
  37. return true;
  38. }
  39. public function process() {
  40. if (!$this->getSource()) {
  41. return $this->failure($this->modx->lexicon('permission_denied'));
  42. }
  43. $this->source->setRequestProperties($this->getProperties());
  44. $this->source->initialize();
  45. $dir = $this->getProperty('dir');
  46. $dir = preg_replace('/[\.]{2,}/', '', htmlspecialchars($dir));
  47. $success = $this->source->chmodContainer($dir, $this->getProperty('mode'));
  48. if (empty($success)) {
  49. $msg = '';
  50. $errors = $this->source->getErrors();
  51. foreach ($errors as $k => $msg) {
  52. $this->modx->error->addField($k,$msg);
  53. }
  54. return $this->failure($msg);
  55. }
  56. return $this->success();
  57. }
  58. /**
  59. * Get the active Source
  60. * @return modMediaSource|boolean
  61. */
  62. public function getSource() {
  63. $this->modx->loadClass('sources.modMediaSource');
  64. $this->source = modMediaSource::getDefaultSource($this->modx,$this->getProperty('source'));
  65. if (empty($this->source) || !$this->source->getWorkingContext()) {
  66. return false;
  67. }
  68. return $this->source;
  69. }
  70. }
  71. return 'modBrowserFolderChmodProcessor';