]> source.dussan.org Git - nextcloud-server.git/commitdiff
Create new mountconfig files in json
authorRobin Appelman <icewind@owncloud.com>
Sat, 16 Feb 2013 00:50:40 +0000 (01:50 +0100)
committerRobin Appelman <icewind@owncloud.com>
Sat, 16 Feb 2013 00:50:40 +0000 (01:50 +0100)
apps/files_external/lib/config.php
lib/files/filesystem.php

index 6ef7f37f58b0ac1ce10bd1999b38d4802b9ed0d6..36ef48462a7b01137353a00ed7741d949a57431e 100755 (executable)
@@ -281,12 +281,19 @@ class OC_Mount_Config {
        private static function readData($isPersonal) {
                $parser = new \OC\ArrayParser();
                if ($isPersonal) {
-                       $file = OC_User::getHome(OCP\User::getUser()).'/mount.php';
+                       $phpFile = OC_User::getHome(OCP\User::getUser()).'/mount.php';
+                       $jsonFile = OC_User::getHome(OCP\User::getUser()).'/mount.json';
                } else {
-                       $file = OC::$SERVERROOT.'/config/mount.php';
+                       $phpFile = OC::$SERVERROOT.'/config/mount.php';
+                       $jsonFile = OC::$SERVERROOT.'/config/mount.json';
                }
-               if (is_file($file)) {
-                       $mountPoints = $parser->parsePHP(file_get_contents($file));
+               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;
                        }
@@ -301,35 +308,11 @@ class OC_Mount_Config {
        */
        private static function writeData($isPersonal, $data) {
                if ($isPersonal) {
-                       $file = OC_User::getHome(OCP\User::getUser()).'/mount.php';
+                       $file = OC_User::getHome(OCP\User::getUser()).'/mount.json';
                } else {
-                       $file = OC::$SERVERROOT.'/config/mount.php';
-               }
-               $content = "<?php return array (\n";
-               if (isset($data[self::MOUNT_TYPE_GROUP])) {
-                       $content .= "\t'group' => array (\n";
-                       foreach ($data[self::MOUNT_TYPE_GROUP] as $group => $mounts) {
-                               $content .= "\t\t'".$group."' => array (\n";
-                               foreach ($mounts as $mountPoint => $mount) {
-                                       $content .= "\t\t\t'".addcslashes($mountPoint, "'")."' => ".str_replace("\n", '', var_export($mount, true)).", \n";
-
-                               }
-                               $content .= "\t\t),\n";
-                       }
-                       $content .= "\t),\n";
-               }
-               if (isset($data[self::MOUNT_TYPE_USER])) {
-                       $content .= "\t'user' => array (\n";
-                       foreach ($data[self::MOUNT_TYPE_USER] as $user => $mounts) {
-                               $content .= "\t\t'".$user."' => array (\n";
-                               foreach ($mounts as $mountPoint => $mount) {
-                                       $content .= "\t\t\t'".addcslashes($mountPoint, "'")."' => ".str_replace("\n", '', var_export($mount, true)).",\n";
-                               }
-                               $content .= "\t\t),\n";
-                       }
-                       $content .= "\t),\n";
+                       $file = OC::$SERVERROOT.'/config/mount.json';
                }
-               $content .= ");\n?>";
+               $content = json_encode($data);
                @file_put_contents($file, $content);
        }
 
index 89a9ab2921208b3b6bab04c1c89d6477b98f2adf..cba469e06c4eda710fec917a165225c72963d291 100644 (file)
@@ -218,8 +218,12 @@ class Filesystem {
                $parser = new \OC\ArrayParser();
 
                // Load system mount points
-               if (is_file(\OC::$SERVERROOT . '/config/mount.php')) {
-                       $mountConfig = $parser->parsePHP(file_get_contents(\OC::$SERVERROOT . '/config/mount.php'));
+               if (is_file(\OC::$SERVERROOT . '/config/mount.php') or is_file(\OC::$SERVERROOT . '/config/mount.json')) {
+                       if(is_file(\OC::$SERVERROOT . '/config/mount.json')){
+                               $mountConfig = json_decode(file_get_contents(\OC::$SERVERROOT . '/config/mount.json'), true);
+                       }elseif(is_file(\OC::$SERVERROOT . '/config/mount.php')){
+                               $mountConfig = $parser->parsePHP(file_get_contents(\OC::$SERVERROOT . '/config/mount.php'));
+                       }
                        if (isset($mountConfig['global'])) {
                                foreach ($mountConfig['global'] as $mountPoint => $options) {
                                        self::mount($options['class'], $options['options'], $mountPoint);
@@ -255,8 +259,12 @@ class Filesystem {
                // Load personal mount points
                $root = \OC_User::getHome($user);
                self::mount('\OC\Files\Storage\Local', array('datadir' => $root), $user);
-               if (is_file($root . '/mount.php')) {
-                       $mountConfig = $parser->parsePHP(file_get_contents($root . '/mount.php'));
+               if (is_file($root . '/mount.php') or is_file($root . '/mount.json')) {
+                       if (is_file($root . '/mount.json')){
+                               $mountConfig = json_decode(file_get_contents($root . '/mount.json'), true);
+                       } elseif (is_file($root . '/mount.php')){
+                               $mountConfig = $parser->parsePHP(file_get_contents($root . '/mount.php'));
+                       }
                        if (isset($mountConfig['user'][$user])) {
                                foreach ($mountConfig['user'][$user] as $mountPoint => $options) {
                                        self::mount($options['class'], $options['options'], $mountPoint);