elFinderPlugin.php 3.3 KB

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