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