elFinderPlugin.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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) {
  40. if (! $opts['enable']) {
  41. return false;
  42. }
  43. if (isset($opts['onDropWith']) && !is_null($opts['onDropWith'])) {
  44. // plugin disabled by default, enabled only if given key is pressed
  45. if (isset($_REQUEST['dropWith']) && $_REQUEST['dropWith']) {
  46. $onDropWith = $opts['onDropWith'];
  47. $action = (int)$_REQUEST['dropWith'];
  48. if (!is_array($onDropWith)) {
  49. $onDropWith = array($onDropWith);
  50. }
  51. foreach($onDropWith as $key) {
  52. $key = (int)$key;
  53. if (($action & $key) === $key) {
  54. return true;
  55. }
  56. }
  57. }
  58. return false;
  59. }
  60. if (isset($opts['offDropWith']) && ! is_null($opts['offDropWith']) && isset($_REQUEST['dropWith'])) {
  61. // plugin enabled by default, disabled only if given key is pressed
  62. $offDropWith = $opts['offDropWith'];
  63. $action = (int)$_REQUEST['dropWith'];
  64. if (! is_array($offDropWith)) {
  65. $offDropWith = array($offDropWith);
  66. }
  67. $res = true;
  68. foreach($offDropWith as $key) {
  69. $key = (int)$key;
  70. if ($key === 0) {
  71. if ($action === 0) {
  72. $res = false;
  73. break;
  74. }
  75. } else {
  76. if (($action & $key) === $key) {
  77. $res = false;
  78. break;
  79. }
  80. }
  81. }
  82. if (! $res) {
  83. return false;
  84. }
  85. }
  86. return true;
  87. }
  88. }