Skip to content
Snippets Groups Projects
Select Git revision
  • 279cbeb001c9d8e917838ffb6a1b10394f27cf79
  • master default protected
2 results

base.php

Blame
  • util.php 22.40 KiB
    <?php
    /**
     * Class for utility functions
     *
     */
    
    class OC_Util {
    	public static $scripts=array();
    	public static $styles=array();
    	public static $headers=array();
    	private static $rootMounted=false;
    	private static $fsSetup=false;
    	public static $core_styles=array();
    	public static $core_scripts=array();
    
    	// Can be set up
    	public static function setupFS( $user = '' ) {// configure the initial filesystem based on the configuration
    		if(self::$fsSetup) {//setting up the filesystem twice can only lead to trouble
    			return false;
    		}
    
    		// If we are not forced to load a specific user we load the one that is logged in
    		if( $user == "" && OC_User::isLoggedIn()) {
    			$user = OC_User::getUser();
    		}
    
    		// load all filesystem apps before, so no setup-hook gets lost
    		if(!isset($RUNTIME_NOAPPS) || !$RUNTIME_NOAPPS) {
    			OC_App::loadApps(array('filesystem'));
    		}
    
    		// the filesystem will finish when $user is not empty,
    		// mark fs setup here to avoid doing the setup from loading
    		// OC_Filesystem
    		if ($user != '') {
    			self::$fsSetup=true;
    		}
    
    		$CONFIG_DATADIRECTORY = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
    		//first set up the local "root" storage
    		if(!self::$rootMounted) {
    			\OC\Files\Filesystem::mount('\OC\Files\Storage\Local', array('datadir'=>$CONFIG_DATADIRECTORY), '/');
    			self::$rootMounted=true;
    		}
    
    		if( $user != "" ) { //if we aren't logged in, there is no use to set up the filesystem
    			$user_dir = '/'.$user.'/files';
    			$user_root = OC_User::getHome($user);
    			$userdirectory = $user_root . '/files';
    			if( !is_dir( $userdirectory )) {
    				mkdir( $userdirectory, 0755, true );
    			}
    			//jail the user into his "home" directory
    			\OC\Files\Filesystem::init($user_dir);
    
    			$quotaProxy=new OC_FileProxy_Quota();
    			$fileOperationProxy = new OC_FileProxy_FileOperations();
    			OC_FileProxy::register($quotaProxy);
    			OC_FileProxy::register($fileOperationProxy);
    
    			OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $user_dir));
    		}
    		return true;
    	}
    
    	public static function tearDownFS() {
    		\OC\Files\Filesystem::tearDown();
    		self::$fsSetup=false;
    	}