/** * Read the mount points in the config file into an array * * @param string|null $user If not null, personal for $user, otherwise system * @return array */ private static function readData($user = null) { // $parser = new \OC\ArrayParser(); // if (isset($user)) { // $phpFile = OC_User::getHome($user) . '/mount.php'; // $jsonFile = OC_User::getHome($user) . '/mount.json'; // } else { // $phpFile = OC::$SERVERROOT . '/config/mount.php'; // $datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data/'); // $jsonFile = \OC_Config::getValue('mount_file', $datadir . '/mount.json'); // } // if (is_file($jsonFile)) { // $mountPoints = json_decode(file_get_contents($jsonFile), true); // if (is_array($mountPoints)) { // return $mountPoints; // } // } elseif (is_file($phpFile)) { // $mountPoints = $parser->parsePHP(file_get_contents($phpFile)); // if (is_array($mountPoints)) { // return $mountPoints; // } // } // return array(); //修改从json文件中获取变为从数据库中获取mount信息 //根据用户获取数据 if (isset($user)) { $mountdatabase = new \OC\Files\Mount\MountDatabase(); $result = $mountdatabase->getMountPointByUser($user); if (!empty($result)) { $options = json_decode($result['options'], true); $mountpoints = array('user' => array($result['name'] => array($result['storage_name'] => array('class' => $result['class'], 'options' => $options, 'priority' => $result['priority'], 'storage_id' => $result['storage_id'])))); return $mountpoints; } else { return array(); } } else { //如果没有用户则获取所有数据 $mountdatabase = new \OC\Files\Mount\MountDatabase(); $result = $mountdatabase->getAllMountPoints(); if (!empty($result)) { $users = array(); foreach ($result as $res) { $options = json_decode($res['options'], true); $arr = array($res['name'] => array($res['storage_name'] => array('class' => $res['class'], 'options' => $options, 'priority' => $res['priority'], 'storage_id' => $res['storage_id']))); $users = $users + $arr; } $mountpoints = array('user' => $users); return $mountpoints; } else { return array(); } } }
<?php /** * Created by PhpStorm. * User: admin * Date: 2015/9/17 * Time: 12:24 */ $mount = new \OC\Files\Mount\MountDatabase(); $result = $mount->getAllMountPoints(); //$result=$mount->getMountPointByUserAndStorage('sunny','/$user/files/FTP'); $users = array(); foreach ($result as $res) { $options = json_decode($res['options'], true); $arr = array($res['name'] => array($res['storage_name'] => array('class' => $res['class'], 'options' => $options, 'priority' => $res['priority'], 'storage_id' => $res['storage_id']))); $users = array_merge($users, $arr); } $mountpoints = array('user' => $users); print_r($mountpoints); //$str='{ // "admin": { // "\/$user\/files\/FTP": { // "class": "\\OC\\Files\\Storage\\FTP", // "options": { // "host": "192.168.200.122", // "user": "******", // "password": "", // "root": "1100000002", // "secure": "false", // "password_encrypted": "bng1Z3JqZHR5cHluZHUxa+YC\/PQLE9ksmn3TPM1MDiw=" // },