getVolume() public method

Return root - file's owner (public func of volume())
Author: Naoki Sawada
public getVolume ( $hash ) : elFinderStorageDriver
return elFinderStorageDriver
Exemplo n.º 1
0
    /**
     * Create log record
     *
     * @param  string   $cmd       command name
     * @param  array    $result    command result
     * @param  array    $args      command arguments from client
     * @param  elFinder $elfinder  elFinder instance
     * @return void|true
     * @author Dmitry (dio) Levashov
     **/
    public function log($cmd, &$result, $args, $elfinder)
    {
        $log = $cmd . ' [' . date('d.m H:s') . "]\n";
        if ($cmd === 'netmount' && is_object($this->xoopsUser) && (!empty($result['sync']) || !empty($result['added']))) {
            if ($uid = $this->xoopsUser->getVar('uid')) {
                $uid = intval($uid);
                $table = $this->db->prefix($this->mydirname . '_userdat');
                $netVolumes = $this->db->quoteString(serialize($_SESSION[_MD_XELFINDER_NETVOLUME_SESSION_KEY]));
                $sql = 'SELECT `id` FROM `' . $table . '` WHERE `key`=\'netVolumes\' AND `uid`=' . $uid;
                if ($res = $this->db->query($sql)) {
                    if ($this->db->getRowsNum($res) > 0) {
                        $sql = 'UPDATE `' . $table . '` SET `data`=' . $netVolumes . ', `mtime`=' . time() . ' WHERE `key`=\'netVolumes\' AND `uid`=' . $uid;
                    } else {
                        $sql = 'INSERT `' . $table . '` SET `key`=\'netVolumes\', `uid` = ' . $uid . ', `data`=' . $netVolumes . ', `mtime`=' . time();
                    }
                    $this->db->queryF($sql);
                }
            }
        }
        if (!empty($result['error'])) {
            $log .= "\tERROR: " . implode(' ', $result['error']) . "\n";
        }
        if (!empty($result['warning'])) {
            $log .= "\tWARNING: " . implode(' ', $result['warning']) . "\n";
        }
        if (!empty($result['removed'])) {
            foreach ($result['removed'] as $file) {
                // removed file contain additional field "realpath"
                $log .= "\tREMOVED: " . $elfinder->realpath($file['hash']) . "\n";
            }
        }
        if (!empty($result['added'])) {
            foreach ($result['added'] as $file) {
                $log .= "\tADDED: " . $elfinder->realpath($file['hash']) . "\n";
            }
        }
        if (!empty($result['changed'])) {
            foreach ($result['changed'] as $file) {
                $log .= "\tCHANGED: " . $elfinder->realpath($file['hash']) . "\n";
            }
        }
        if (!empty($result['added']) && in_array($cmd, array('mkdir', 'mkfile', 'put', 'upload', 'extract'))) {
            $mail = false;
            if (is_object($this->xoopsUser)) {
                if ($this->isAdmin) {
                    $mail = in_array(XOOPS_GROUP_ADMIN, $this->config['mail_notify_group']);
                } else {
                    $mail = array_intersect($this->config['mail_notify_group'], $this->mygids);
                }
            } else {
                $mail = $this->config['mail_notify_guest'];
            }
            //$log .= "\n\$mail=".($mail? 'On' : 'Off')."\n";
            if ($mail) {
                $config_handler = xoops_gethandler('config');
                $xoopsConfig = $config_handler->getConfigsByCat(XOOPS_CONF);
                $sep = "\n" . str_repeat('-', 40) . "\n";
                $self = XOOPS_MODULE_URL . '/' . $this->mydirname . '/connector.php';
                if (is_object($this->xoopsUser)) {
                    $uname = $this->xoopsUser->uname('n');
                    $uid = $this->xoopsUser->uid();
                } else {
                    $uname = $xoopsConfig['anonymous'];
                    $uid = 0;
                }
                $date = date('c');
                $head = <<<EOD
USER: {$uname}
UID: {$uid}
IP: {$_SERVER['REMOTE_ADDR']}
CMD: {$cmd}
DATE: {$date}
EOD;
                $msg = array();
                foreach ($result['added'] as $file) {
                    $url = 'unknown';
                    if (!empty($file['url'])) {
                        $url = $file['url'] != 1 ? $file['url'] : 'ondemand';
                    } else {
                        $url = $self . '?cmd=file&target=' . $file['hash'];
                    }
                    $dl = $self . '?cmd=file&download=1&target=' . $file['hash'];
                    $hash = $file['hash'];
                    $path = $elfinder->realpath($file['hash']);
                    $name = $file['name'];
                    $manager = XOOPS_MODULE_URL . '/' . $this->mydirname . '/manager.php#elf_' . $file['phash'];
                    $msg[] = <<<EOD
HASH: {$hash}
PATH: {$path}
NAME: {$name}
URL: {$url}
DOWNLOAD: {$dl}
MANAGER: {$manager}
EOD;
                }
                $sitename = $xoopsConfig['sitename'];
                $modname = $this->xoopsModule->getVar('name');
                $subject = '[' . $modname . '] Cmd: "' . $cmd . '" Report';
                $message = join($sep, $msg);
                if (strtoupper(_CHARSET) !== 'UTF-8') {
                    ini_set('default_charset', _CHARSET);
                    if (version_compare(PHP_VERSION, '5.6', '<')) {
                        ini_set('mbstring.internal_encoding', _CHARSET);
                    } else {
                        @ini_set('mbstring.internal_encoding', '');
                    }
                    $message = mb_convert_encoding($message, _CHARSET, 'UTF-8');
                }
                $xoopsMailer = getMailer();
                $xoopsMailer->useMail();
                $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
                $xoopsMailer->setFromName($sitename . ':' . $modname);
                $xoopsMailer->setSubject($subject);
                $xoopsMailer->setBody($head . $sep . $message);
                $xoopsMailer->setToEmails($xoopsConfig['adminmail']);
                $xoopsMailer->send();
                $xoopsMailer->reset();
                if (strtoupper(_CHARSET) !== 'UTF-8') {
                    ini_set('mbstring.internal_encoding', 'UTF-8');
                }
            }
        }
        $this->write($log);
        if (in_array($cmd, array('mkdir', 'mkfile', 'put', 'paste', 'upload', 'extract', 'resize'))) {
            if (!empty($result['changed'])) {
                if (($target = $result['changed'][0]['phash']) && ($volume = $elfinder->getVolume($target))) {
                    if ($parents = $volume->parents($target, true)) {
                        $result['changed'] = array_merge($result['changed'], $parents);
                    }
                }
            }
        }
    }