elFinderPlugin.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * elFinder Plugin Abstract
  4. *
  5. * @package elfinder
  6. * @author Naoki Sawada
  7. * @license New BSD
  8. */
  9. class elFinderPlugin {
  10. /**
  11. * This plugin's options
  12. *
  13. * @var array
  14. */
  15. protected $opts = array();
  16. /**
  17. * Get current volume's options
  18. *
  19. * @param object $volume
  20. * @return array options
  21. */
  22. protected function getCurrentOpts($volume) {
  23. $name = substr(get_class($this), 14); // remove "elFinderPlugin"
  24. $opts = $this->opts;
  25. if (is_object($volume)) {
  26. $volOpts = $volume->getOptionsPlugin($name);
  27. if (is_array($volOpts)) {
  28. $opts = array_merge($opts, $volOpts);
  29. }
  30. }
  31. return $opts;
  32. }
  33. /**
  34. * Is enabled with options
  35. *
  36. * @param array $opts
  37. * @return boolean
  38. */
  39. protected function iaEnabled($opts, $elfinder = null) {
  40. if (! $opts['enable']) {
  41. return false;
  42. }
  43. // check post var 'contentSaveId' to disable this plugin
  44. if ($elfinder && !empty($opts['disableWithContentSaveId'])) {
  45. $session = $elfinder->getSession();
  46. $urlContentSaveIds = $session->get('urlContentSaveIds', array());
  47. if (!empty(elFinder::$currentArgs['contentSaveId']) && ($contentSaveId = elFinder::$currentArgs['contentSaveId'])) {
  48. if (!empty($urlContentSaveIds[$contentSaveId])) {
  49. $elfinder->removeUrlContentSaveId($contentSaveId);
  50. return false;
  51. }
  52. }
  53. }
  54. if (isset($opts['onDropWith']) && !is_null($opts['onDropWith'])) {
  55. // plugin disabled by default, enabled only if given key is pressed
  56. if (isset($_REQUEST['dropWith']) && $_REQUEST['dropWith']) {
  57. $onDropWith = $opts['onDropWith'];
  58. $action = (int)$_REQUEST['dropWith'];
  59. if (!is_array($onDropWith)) {
  60. $onDropWith = array($onDropWith);
  61. }
  62. foreach($onDropWith as $key) {
  63. $key = (int)$key;
  64. if (($action & $key) === $key) {
  65. return true;
  66. }
  67. }
  68. }
  69. return false;
  70. }
  71. if (isset($opts['offDropWith']) && ! is_null($opts['offDropWith']) && isset($_REQUEST['dropWith'])) {
  72. // plugin enabled by default, disabled only if given key is pressed
  73. $offDropWith = $opts['offDropWith'];
  74. $action = (int)$_REQUEST['dropWith'];
  75. if (! is_array($offDropWith)) {
  76. $offDropWith = array($offDropWith);
  77. }
  78. $res = true;
  79. foreach($offDropWith as $key) {
  80. $key = (int)$key;
  81. if ($key === 0) {
  82. if ($action === 0) {
  83. $res = false;
  84. break;
  85. }
  86. } else {
  87. if (($action & $key) === $key) {
  88. $res = false;
  89. break;
  90. }
  91. }
  92. }
  93. if (! $res) {
  94. return false;
  95. }
  96. }
  97. return true;
  98. }
  99. }