protected function netmount($args)
{
$options = array();
$protocol = $args['protocol'];
if ($protocol === 'netunmount') {
if (!empty($args['user']) && ($volume = $this->volume($args['user']))) {
if ($this->removeNetVolume($args['host'], $volume)) {
return array('removed' => array(array('hash' => $volume->root())));
}
}
return array('sync' => true, 'error' => $this->error(self::ERROR_NETUNMOUNT));
}
$driver = isset(self::$netDrivers[$protocol]) ? self::$netDrivers[$protocol] : '';
$class = 'elFinderVolume' . $driver;
if (!class_exists($class)) {
return array('error' => $this->error(self::ERROR_NETMOUNT, $args['host'], self::ERROR_NETMOUNT_NO_DRIVER));
}
if (!$args['path']) {
$args['path'] = '/';
}
foreach ($args as $k => $v) {
if ($k != 'options' && $k != 'protocol' && $v) {
$options[$k] = $v;
}
}
if (is_array($args['options'])) {
foreach ($args['options'] as $key => $value) {
$options[$key] = $value;
}
}
$volume = new $class();
// pass session handler
$volume->setSession($this->session);
if (method_exists($volume, 'netmountPrepare')) {
$options = $volume->netmountPrepare($options);
if (isset($options['exit'])) {
if ($options['exit'] === 'callback') {
$this->callback($options['out']);
}
return $options;
}
}
$netVolumes = $this->getNetVolumes();
if (!isset($options['id'])) {
// given fixed unique id
if (!($options['id'] = $this->getNetVolumeUniqueId($netVolumes))) {
return array('error' => $this->error(self::ERROR_NETMOUNT, $args['host'], 'Could\'t given volume id.'));
}
}
// load additional volume root options
if (!empty($this->optionsNetVolumes['*'])) {
$options = array_merge($options, $this->optionsNetVolumes['*']);
}
if (!empty($this->optionsNetVolumes[$protocol])) {
$options = array_merge($options, $this->optionsNetVolumes[$protocol]);
}
if (!($key = $volume->netMountKey)) {
$key = md5($protocol . '-' . serialize($options));
}
$options['netkey'] = $key;
if ($volume->mount($options)) {
$options['driver'] = $driver;
$netVolumes[$key] = $options;
$this->saveNetVolumes($netVolumes);
$rootstat = $volume->file($volume->root());
return array('added' => array($rootstat));
} else {
$this->removeNetVolume(null, $volume);
return array('error' => $this->error(self::ERROR_NETMOUNT, $args['host'], implode(' ', $volume->error())));
}
}