diff options
author | Michael Gapczynski <GapczynskiM@gmail.com> | 2011-07-30 19:40:19 -0400 |
---|---|---|
committer | Michael Gapczynski <GapczynskiM@gmail.com> | 2011-07-30 19:40:19 -0400 |
commit | 11d162751381963e0c8a86cf15c811cc99003654 (patch) | |
tree | 276b5b1e67a66491ef553346087b2959f35b3bc7 /lib | |
parent | d13ba0ee2d93080ba56776442b9d39a53e2b6321 (diff) | |
parent | d6faa89ed720da7319923cba33a83d0210216d57 (diff) | |
download | nextcloud-server-11d162751381963e0c8a86cf15c811cc99003654.tar.gz nextcloud-server-11d162751381963e0c8a86cf15c811cc99003654.zip |
Merge branch 'master' into sharing. Integrate with changes in master, rename classes
Conflicts:
lib/base.php
Diffstat (limited to 'lib')
-rw-r--r-- | lib/MDB2/Driver/Manager/sqlite3.php | 2 | ||||
-rw-r--r-- | lib/MDB2/Driver/sqlite3.php | 2 | ||||
-rw-r--r-- | lib/app.php | 21 | ||||
-rw-r--r-- | lib/appconfig.php | 3 | ||||
-rw-r--r-- | lib/base.php | 445 | ||||
-rw-r--r-- | lib/config.php | 3 | ||||
-rw-r--r-- | lib/connect.php | 262 | ||||
-rw-r--r-- | lib/connector/sabre/auth.php (renamed from lib/Connector/Sabre/auth.php) | 5 | ||||
-rw-r--r-- | lib/connector/sabre/directory.php (renamed from lib/Connector/Sabre/directory.php) | 23 | ||||
-rw-r--r-- | lib/connector/sabre/file.php (renamed from lib/Connector/Sabre/file.php) | 12 | ||||
-rw-r--r-- | lib/connector/sabre/locks.php (renamed from lib/Connector/Sabre/locks.php) | 11 | ||||
-rw-r--r-- | lib/connector/sabre/node.php (renamed from lib/Connector/Sabre/node.php) | 18 | ||||
-rw-r--r-- | lib/db.php (renamed from lib/database.php) | 27 | ||||
-rw-r--r-- | lib/fakedirstream.php | 45 | ||||
-rw-r--r-- | lib/files.php | 153 | ||||
-rw-r--r-- | lib/filestorage.php | 362 | ||||
-rw-r--r-- | lib/filestorage/local.php | 357 | ||||
-rw-r--r-- | lib/filestorage/remote.php (renamed from lib/remotestorage.php) | 7 | ||||
-rw-r--r-- | lib/filesystem.php | 93 | ||||
-rw-r--r-- | lib/group.php | 23 | ||||
-rw-r--r-- | lib/group/backend.php (renamed from lib/Group/backend.php) | 2 | ||||
-rw-r--r-- | lib/group/database.php (renamed from lib/Group/database.php) | 4 | ||||
-rwxr-xr-x | lib/helper.php | 4 | ||||
-rw-r--r-- | lib/hook.php | 69 | ||||
-rw-r--r-- | lib/installer.php | 36 | ||||
-rw-r--r-- | lib/l10n.php | 4 | ||||
-rw-r--r-- | lib/log.php | 8 | ||||
-rw-r--r-- | lib/mimetypes.list.php | 1 | ||||
-rw-r--r-- | lib/ocs.php | 18 | ||||
-rw-r--r-- | lib/ocsclient.php | 3 | ||||
-rw-r--r-- | lib/preferences.php | 3 | ||||
-rw-r--r-- | lib/remote/cloud.php | 206 | ||||
-rw-r--r-- | lib/search.php | 77 | ||||
-rw-r--r-- | lib/search/provider.php | 16 | ||||
-rw-r--r-- | lib/search/provider/file.php | 16 | ||||
-rw-r--r-- | lib/search/result.php | 24 | ||||
-rw-r--r-- | lib/setup.php | 46 | ||||
-rw-r--r-- | lib/template.php | 68 | ||||
-rw-r--r-- | lib/user.php | 37 | ||||
-rw-r--r-- | lib/user/backend.php (renamed from lib/User/backend.php) | 4 | ||||
-rw-r--r-- | lib/user/database.php (renamed from lib/User/database.php) | 6 | ||||
-rw-r--r-- | lib/user/example.php (renamed from lib/User/example.php) | 6 | ||||
-rw-r--r-- | lib/util.php | 248 |
43 files changed, 1356 insertions, 1424 deletions
diff --git a/lib/MDB2/Driver/Manager/sqlite3.php b/lib/MDB2/Driver/Manager/sqlite3.php index 7096126a523..4e420b5d0b2 100644 --- a/lib/MDB2/Driver/Manager/sqlite3.php +++ b/lib/MDB2/Driver/Manager/sqlite3.php @@ -70,7 +70,7 @@ class MDB2_Driver_Manager_sqlite3 extends MDB2_Driver_Manager_Common function createDatabase($name, $options = array()) { global $SERVERROOT; - $datadir=OC_CONFIG::getValue( "datadirectory", "$SERVERROOT/data" ); + $datadir=OC_Config::getValue( "datadirectory", "$SERVERROOT/data" ); $db =$this->getDBInstance(); if (PEAR::isError($db)) { return $db; diff --git a/lib/MDB2/Driver/sqlite3.php b/lib/MDB2/Driver/sqlite3.php index 3b74afed146..ccf6bb53688 100644 --- a/lib/MDB2/Driver/sqlite3.php +++ b/lib/MDB2/Driver/sqlite3.php @@ -352,7 +352,7 @@ class MDB2_Driver_sqlite3 extends MDB2_Driver_Common return MDB2_OK; } global $SERVERROOT; - $datadir=OC_CONFIG::getValue( "datadirectory", "$SERVERROOT/data" ); + $datadir=OC_Config::getValue( "datadirectory", "$SERVERROOT/data" ); $database_file = $this->_getDatabaseFile($this->database_name); if (is_resource($this->connection)) { //if (count(array_diff($this->connected_dsn, $this->dsn)) == 0 diff --git a/lib/app.php b/lib/app.php index b6c2512e79a..9e81ed8184e 100644 --- a/lib/app.php +++ b/lib/app.php @@ -26,7 +26,7 @@ * owncloud ecosystem. Furthermore, this class is responsible for installing, * upgrading and removing apps. */ -class OC_APP{ +class OC_App{ static private $init = false; static private $apps = array(); static private $activeapp = ''; @@ -57,7 +57,7 @@ class OC_APP{ } // The rest comes here - $apps = OC_APPCONFIG::getApps(); + $apps = OC_Appconfig::getApps(); foreach( $apps as $app ){ if( self::isEnabled( $app )){ if(is_file($SERVERROOT.'/apps/'.$app.'/appinfo/app.php')){ @@ -80,7 +80,7 @@ class OC_APP{ * This function checks whether or not an app is enabled. */ public static function isEnabled( $app ){ - if( 'yes' == OC_APPCONFIG::getValue( $app, 'enabled' )){ + if( 'yes' == OC_Appconfig::getValue( $app, 'enabled' )){ return true; } @@ -95,7 +95,7 @@ class OC_APP{ * This function set an app as enabled in appconfig. */ public static function enable( $app ){ - OC_APPCONFIG::setValue( $app, 'enabled', 'yes' ); + OC_Appconfig::setValue( $app, 'enabled', 'yes' ); } /** @@ -106,7 +106,7 @@ class OC_APP{ * This function set an app as enabled in appconfig. */ public static function disable( $app ){ - OC_APPCONFIG::setValue( $app, 'enabled', 'no' ); + OC_Appconfig::setValue( $app, 'enabled', 'no' ); } /** @@ -126,7 +126,7 @@ class OC_APP{ * */ public static function register( $data ){ - OC_APP::$apps[] = $data; + OC_App::$apps[] = $data; } /** @@ -137,7 +137,7 @@ class OC_APP{ */ public static function get(){ // TODO: write function - return OC_APP::$apps; + return OC_App::$apps; } /** @@ -162,7 +162,7 @@ class OC_APP{ if(!isset($data['icon'])){ $data['icon']=''; } - OC_APP::$navigation[] = $data; + OC_App::$navigation[] = $data; return true; } @@ -241,7 +241,7 @@ class OC_APP{ */ public static function addAdminPage( $data = array()){ // TODO: write function - OC_APP::$adminpages[] = $data; + OC_App::$adminpages[] = $data; return true; } @@ -266,7 +266,7 @@ class OC_APP{ */ public static function addSettingsPage( $data = array()){ // TODO: write function - OC_APP::$settingspages[] = $data; + OC_App::$settingspages[] = $data; return true; } @@ -408,4 +408,3 @@ class OC_APP{ } } } -?>
\ No newline at end of file diff --git a/lib/appconfig.php b/lib/appconfig.php index 4fef7542f40..06281d38585 100644 --- a/lib/appconfig.php +++ b/lib/appconfig.php @@ -37,7 +37,7 @@ * This class provides an easy way for apps to store config values in the * database. */ -class OC_APPCONFIG{ +class OC_Appconfig{ /** * @brief Get all apps using the config * @returns array with app ids @@ -158,4 +158,3 @@ class OC_APPCONFIG{ return true; } } -?> diff --git a/lib/base.php b/lib/base.php index d81479e5a28..324713de61c 100644 --- a/lib/base.php +++ b/lib/base.php @@ -20,6 +20,13 @@ * */ +// Get rid of this stupid require_once OC_... +function OC_autoload($className) { + if(strpos($className,'OC_')===0) { + require_once strtolower(str_replace('_','/',substr($className,3)) . '.php'); + } +} +spl_autoload_register('OC_autoload'); // set some stuff //ob_start(); @@ -36,8 +43,8 @@ $DOCUMENTROOT=realpath($_SERVER['DOCUMENT_ROOT']); $SERVERROOT=str_replace("\\",'/',$SERVERROOT); $SUBURI=substr(realpath($_SERVER["SCRIPT_FILENAME"]),strlen($SERVERROOT)); $scriptName=$_SERVER["SCRIPT_NAME"]; -if(substr($scriptName,-1)=='/'){//if the script isn't a file assume index.php - $scriptName.='index.php'; +if(substr($scriptName,-1)=='/'){ + $scriptName.='index.php'; } $WEBROOT=substr($scriptName,0,strlen($scriptName)-strlen($SUBURI)); @@ -58,17 +65,14 @@ if( !isset( $RUNTIME_NOAPPS )){ $RUNTIME_NOAPPS = false; } -// Doing the config stuff first -require_once('config.php'); - // TODO: we should get rid of this one, too // WARNING: to make everything even more confusing, DATADIRECTORY is a var that // changes and DATATIRECTORY_ROOT stays the same, but is set by // "datadirectory". Any questions? -$CONFIG_DATADIRECTORY = OC_CONFIG::getValue( "datadirectory", "$SERVERROOT/data" ); +$CONFIG_DATADIRECTORY = OC_Config::getValue( "datadirectory", "$SERVERROOT/data" ); // redirect to https site if configured -if( OC_CONFIG::getValue( "forcessl", false )){ +if( OC_Config::getValue( "forcessl", false )){ if(!isset($_SERVER['HTTPS']) or $_SERVER['HTTPS'] != 'on') { $url = "https://". $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; header("Location: $url"); @@ -76,359 +80,124 @@ if( OC_CONFIG::getValue( "forcessl", false )){ } } -// load core libs -require_once('helper.php'); -require_once('database.php'); -require_once('app.php'); -require_once('appconfig.php'); -require_once('files.php'); -require_once('filesystem.php'); -require_once('filestorage.php'); -require_once('apps/files_sharing/sharedstorage.php'); -require_once('l10n.php'); -require_once('preferences.php'); -require_once('log.php'); -require_once('user.php'); -require_once('group.php'); -require_once('ocs.php'); -require_once('ocsclient.php'); -require_once('connect.php'); -require_once('remotestorage.php'); -require_once('search.php'); +$error=(count(OC_Util::checkServer())>0); + +// User and Groups +if( !OC_Config::getValue( "installed", false )){ + $_SESSION['user_id'] = ''; +} -$error=(count(OC_UTIL::checkServer())>0); +OC_User::useBackend( OC_Config::getValue( "userbackend", "database" )); +OC_Group::setBackend( OC_Config::getValue( "groupbackend", "database" )); -OC_USER::useBackend( OC_CONFIG::getValue( "userbackend", "database" )); -OC_GROUP::setBackend( OC_CONFIG::getValue( "groupbackend", "database" )); +// Was in required file ... put it here +OC_Filesystem::registerStorageType('local','OC_Filestorage_Local',array('datadir'=>'string')); +require_once('apps/files_sharing/sharedstorage.php'); +OC_Filesystem::registerStorageType('shared','OC_Filestorage_Shared',array('datadir'=>'string')); // Set up file system unless forbidden if(!$error and !$RUNTIME_NOSETUPFS ){ - OC_UTIL::setupFS(); + OC_Util::setupFS(); } // Add the stuff we need always -OC_UTIL::addScript( "jquery-1.6.2.min" ); -OC_UTIL::addScript( "jquery-ui-1.8.14.custom.min" ); -OC_UTIL::addScript( "js" ); -OC_UTIL::addStyle( "jquery-ui-1.8.14.custom" ); -OC_UTIL::addStyle( "styles" ); +OC_Util::addScript( "jquery-1.6.2.min" ); +OC_Util::addScript( "jquery-ui-1.8.14.custom.min" ); +OC_Util::addScript( "js" ); +OC_Util::addStyle( "jquery-ui-1.8.14.custom" ); +OC_Util::addStyle( "styles" ); // Load Apps if(!$error and !$RUNTIME_NOAPPS ){ - OC_APP::loadApps(); + OC_App::loadApps(); } -/** - * Class for utility functions - * - */ -class OC_UTIL { - public static $scripts=array(); - public static $styles=array(); - public static $headers=array(); - private static $fsSetup=false; - - // Can be set up - public static function setupFS( $user = "", $root = "files" ){// configure the initial filesystem based on the configuration - if(self::$fsSetup){//setting up the filesystem twice can only lead to trouble - return false; - } - - // Global Variables - global $SERVERROOT; - global $CONFIG_DATADIRECTORY; - - $CONFIG_DATADIRECTORY_ROOT = OC_CONFIG::getValue( "datadirectory", "$SERVERROOT/data" ); - $CONFIG_BACKUPDIRECTORY = OC_CONFIG::getValue( "backupdirectory", "$SERVERROOT/backup" ); - - // Create root dir - if(!is_dir($CONFIG_DATADIRECTORY_ROOT)){ - @mkdir($CONFIG_DATADIRECTORY_ROOT) or die("Can't create data directory ($CONFIG_DATADIRECTORY_ROOT), you can usually fix this by setting the owner of '$SERVERROOT' to the user that the web server uses (www-data for debian/ubuntu)"); - } - - // 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(); - } - - if( $user != "" ){ //if we aren't logged in, there is no use to set up the filesystem - //first set up the local "root" storage and the backupstorage if needed - $rootStorage=OC_FILESYSTEM::createStorage('local',array('datadir'=>$CONFIG_DATADIRECTORY_ROOT)); -// if( OC_CONFIG::getValue( "enablebackup", false )){ -// // This creates the Directorys recursively -// if(!is_dir( "$CONFIG_BACKUPDIRECTORY/$user/$root" )){ -// mkdir( "$CONFIG_BACKUPDIRECTORY/$user/$root", 0755, true ); -// } -// $backupStorage=OC_FILESYSTEM::createStorage('local',array('datadir'=>$CONFIG_BACKUPDIRECTORY)); -// $backup=new OC_FILEOBSERVER_BACKUP(array('storage'=>$backupStorage)); -// $rootStorage->addObserver($backup); -// } - OC_FILESYSTEM::mount($rootStorage,'/'); - - // TODO add this storage provider in a proper way - $sharedStorage = OC_FILESYSTEM::createStorage('shared',array('datadir'=>'/'.OC_USER::getUser().'/files/Share/')); - OC_FILESYSTEM::mount($sharedStorage,'/'.OC_USER::getUser().'/files/Share/'); - - $CONFIG_DATADIRECTORY = "$CONFIG_DATADIRECTORY_ROOT/$user/$root"; - if( !is_dir( $CONFIG_DATADIRECTORY )){ - mkdir( $CONFIG_DATADIRECTORY, 0755, true ); - } - -// TODO: find a cool way for doing this -// //set up the other storages according to the system settings -// foreach($CONFIG_FILESYSTEM as $storageConfig){ -// if(OC_FILESYSTEM::hasStorageType($storageConfig['type'])){ -// $arguments=$storageConfig; -// unset($arguments['type']); -// unset($arguments['mountpoint']); -// $storage=OC_FILESYSTEM::createStorage($storageConfig['type'],$arguments); -// if($storage){ -// OC_FILESYSTEM::mount($storage,$storageConfig['mountpoint']); -// } -// } -// } - - //jail the user into his "home" directory - OC_FILESYSTEM::chroot("/$user/$root"); - self::$fsSetup=true; - } - } - - public static function tearDownFS(){ - OC_FILESYSTEM::tearDown(); - self::$fsSetup=false; - } - - /** - * get the current installed version of ownCloud - * @return array - */ - public static function getVersion(){ - return array(1,90,0); - } - - /** - * add a javascript file - * - * @param url $url - */ - public static function addScript( $application, $file = null ){ - if( is_null( $file )){ - $file = $application; - $application = ""; - } - if( !empty( $application )){ - self::$scripts[] = "$application/js/$file"; - }else{ - self::$scripts[] = "js/$file"; - } - } - - /** - * add a css file - * - * @param url $url - */ - public static function addStyle( $application, $file = null ){ - if( is_null( $file )){ - $file = $application; - $application = ""; - } - if( !empty( $application )){ - self::$styles[] = "$application/css/$file"; - }else{ - self::$styles[] = "css/$file"; - } - } - - /** - * @brief Add a custom element to the header - * @param string tag tag name of the element - * @param array $attributes array of attrobutes for the element - * @param string $text the text content for the element - */ - public static function addHeader( $tag, $attributes, $text=''){ - self::$headers[]=array('tag'=>$tag,'attributes'=>$attributes,'text'=>$text); - } - - /** - * formats a timestamp in the "right" way - * - * @param int timestamp $timestamp - * @param bool dateOnly option to ommit time from the result - */ - public static function formatDate( $timestamp,$dateOnly=false){ - if(isset($_SESSION['timezone'])){//adjust to clients timezone if we know it - $systemTimeZone = intval(exec('date +%z')); - $systemTimeZone=(round($systemTimeZone/100,0)*60)+($systemTimeZone%100); - $clientTimeZone=$_SESSION['timezone']*60; - $offset=$clientTimeZone-$systemTimeZone; - $timestamp=$timestamp+$offset*60; - } - $timeformat=$dateOnly?'F j, Y':'F j, Y, H:i'; - return date($timeformat,$timestamp); - } - - /** - * Shows a pagenavi widget where you can jump to different pages. - * - * @param int $pagecount - * @param int $page - * @param string $url - * @return OC_TEMPLATE - */ - public static function getPageNavi($pagecount,$page,$url) { - - $pagelinkcount=8; - if ($pagecount>1) { - $pagestart=$page-$pagelinkcount; - if($pagestart<0) $pagestart=0; - $pagestop=$page+$pagelinkcount; - if($pagestop>$pagecount) $pagestop=$pagecount; - - $tmpl = new OC_TEMPLATE( '', 'part.pagenavi', '' ); - $tmpl->assign('page',$page); - $tmpl->assign('pagecount',$pagecount); - $tmpl->assign('pagestart',$pagestart); - $tmpl->assign('pagestop',$pagestop); - $tmpl->assign('url',$url); - return $tmpl; - } - } - - - - /** - * check if the current server configuration is suitable for ownCloud - * @return array arrays with error messages and hints - */ - public static function checkServer(){ - global $SERVERROOT; - global $CONFIG_DATADIRECTORY; - - $CONFIG_DATADIRECTORY_ROOT = OC_CONFIG::getValue( "datadirectory", "$SERVERROOT/data" );; - $CONFIG_BACKUPDIRECTORY = OC_CONFIG::getValue( "backupdirectory", "$SERVERROOT/backup" ); - $CONFIG_INSTALLED = OC_CONFIG::getValue( "installed", false ); - $errors=array(); - - //check for database drivers - if(!is_callable('sqlite_open') and !is_callable('mysql_connect')){ - $errors[]=array('error'=>'No database drivers (sqlite or mysql) installed.<br/>','hint'=>'');//TODO: sane hint - } - $CONFIG_DBTYPE = OC_CONFIG::getValue( "dbtype", "sqlite" ); - $CONFIG_DBNAME = OC_CONFIG::getValue( "dbname", "owncloud" ); - - //try to get the username the httpd server runs on, used in hints - $stat=stat($_SERVER['DOCUMENT_ROOT']); - if(is_callable('posix_getpwuid')){ - $serverUser=posix_getpwuid($stat['uid']); - $serverUser='\''.$serverUser['name'].'\''; - }else{ - $serverUser='\'www-data\' for ubuntu/debian';//TODO: try to detect the distro and give a guess based on that - } - - //common hint for all file permissons error messages - $permissionsHint="Permissions can usually be fixed by setting the owner of the file or directory to the user the web server runs as ($serverUser)"; - - //check for correct file permissions - if(!stristr(PHP_OS, 'WIN')){ - $prems=substr(decoct(fileperms($CONFIG_DATADIRECTORY_ROOT)),-3); - if(substr($prems,-1)!='0'){ - OC_HELPER::chmodr($CONFIG_DATADIRECTORY_ROOT,0770); - clearstatcache(); - $prems=substr(decoct(fileperms($CONFIG_DATADIRECTORY_ROOT)),-3); - if(substr($prems,2,1)!='0'){ - $errors[]=array('error'=>'Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') is readable from the web<br/>','hint'=>$permissionsHint); +// FROM Connect.php +function OC_CONNECT_TEST($path,$user,$password){ + echo 'connecting...'; + $remote=OC_Connect::connect($path,$user,$password); + if($remote->connected){ + echo 'done<br/>'; + if($remote->isLoggedIn()){ + echo 'logged in, session working<br/>'; + echo 'trying to get remote files...'; + $files=$remote->getFiles(''); + if($files){ + echo count($files).' files found:<br/>'; + foreach($files as $file){ + echo "{$file['type']} {$file['name']}: {$file['size']} bytes<br/>"; } - } - if( OC_CONFIG::getValue( "enablebackup", false )){ - $prems=substr(decoct(fileperms($CONFIG_BACKUPDIRECTORY)),-3); - if(substr($prems,-1)!='0'){ - OC_HELPER::chmodr($CONFIG_BACKUPDIRECTORY,0770); - clearstatcache(); - $prems=substr(decoct(fileperms($CONFIG_BACKUPDIRECTORY)),-3); - if(substr($prems,2,1)!='0'){ - $errors[]=array('error'=>'Data directory ('.$CONFIG_BACKUPDIRECTORY.') is readable from the web<br/>','hint'=>$permissionsHint); + echo 'getting file "'.$file['name'].'"...'; + $size=$file['size']; + $file=$remote->getFile('',$file['name']); + if(file_exists($file)){ + $newSize=filesize($file); + if($size!=$newSize){ + echo "fail<br/>Error: $newSize bytes received, $size expected."; + echo '<br/><br/>Recieved file:<br/>'; + readfile($file); + unlink($file); + return; } + OC_Filesystem::fromTmpFile($file,'/remoteFile'); + echo 'done<br/>'; + echo 'sending file "burning_avatar.png"...'; + $res=$remote->sendFile('','burning_avatar.png','','burning_avatar.png'); + if($res){ + echo 'done<br/>'; + }else{ + echo 'fail<br/>'; + } + }else{ + echo 'fail<br/>'; } + }else{ + echo 'fail<br/>'; } }else{ - //TODO: premisions checks for windows hosts - } - if(is_dir($CONFIG_DATADIRECTORY_ROOT) and !is_writable($CONFIG_DATADIRECTORY_ROOT)){ - $errors[]=array('error'=>'Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') not writable by ownCloud<br/>','hint'=>$permissionsHint); + echo 'no longer logged in, session fail<br/>'; } - - //TODO: check for php modules - - return $errors; + }else{ + echo 'fail<br/>'; } + $remote->disconnect(); + die(); } -/** - * This class manages the hooks. It basically provides two functions: adding - * slots and emitting signals. - */ -class OC_HOOK{ - static private $registered = array(); - - /** - * @brief connects a function to a hook - * @param $signalclass class name of emitter - * @param $signalname name of signal - * @param $slotclass class name of slot - * @param $slotname name of slot - * @returns true/false - * - * This function makes it very easy to connect to use hooks. - * - * TODO: write example - */ - static public function connect( $signalclass, $signalname, $slotclass, $slotname ){ - // Cerate the data structure - if( !array_key_exists( $signalclass, self::$registered )){ - self::$registered[$signalclass] = array(); - } - if( !array_key_exists( $signalname, self::$registered[$signalclass] )){ - self::$registered[$signalclass][$signalname] = array(); - } - - // register hook - self::$registered[$signalclass][$signalname][] = array( - "class" => $slotclass, - "name" => $slotname ); - - // No chance for failure ;-) - return true; - } +// From files.php +function zipAddDir($dir,$zip,$internalDir=''){ + $dirname=basename($dir); + $zip->addEmptyDir($internalDir.$dirname); + $internalDir.=$dirname.='/'; + $files=OC_Files::getdirectorycontent($dir); + foreach($files as $file){ + $filename=$file['name']; + $file=$dir.'/'.$filename; + if(OC_Filesystem::is_file($file)){ + $tmpFile=OC_Filesystem::toTmpFile($file); + OC_Files::$tmpFiles[]=$tmpFile; + $zip->addFile($tmpFile,$internalDir.$filename); + }elseif(OC_Filesystem::is_dir($file)){ + zipAddDir($file,$zip,$internalDir); + } + } +} - /** - * @brief emitts a signal - * @param $signalclass class name of emitter - * @param $signalname name of signal - * @param $params defautl: array() array with additional data - * @returns true if slots exists or false if not - * - * Emits a signal. To get data from the slot use references! - * - * TODO: write example - */ - static public function emit( $signalclass, $signalname, $params = array()){ - // Return false if there are no slots - if( !array_key_exists( $signalclass, self::$registered )){ - return false; - } - if( !array_key_exists( $signalname, self::$registered[$signalclass] )){ - return false; - } +if(!function_exists('sys_get_temp_dir')) { + function sys_get_temp_dir() { + if( $temp=getenv('TMP') ) return $temp; + if( $temp=getenv('TEMP') ) return $temp; + if( $temp=getenv('TMPDIR') ) return $temp; + $temp=tempnam(__FILE__,''); + if (file_exists($temp)) { + unlink($temp); + return dirname($temp); + } + return null; + } +} - // Call all slots - foreach( self::$registered[$signalclass][$signalname] as $i ){ - call_user_func( array( $i["class"], $i["name"] ), $params ); - } +require_once('fakedirstream.php'); - // return true - return true; - } -} -?> +// FROM search.php +new OC_Search_Provider_File();
\ No newline at end of file diff --git a/lib/config.php b/lib/config.php index cd18ddd499c..16e9ea441d5 100644 --- a/lib/config.php +++ b/lib/config.php @@ -38,7 +38,7 @@ * This class is responsible for reading and writing config.php, the very basic * configuration file of owncloud. */ -class OC_CONFIG{ +class OC_Config{ // associative array key => value private static $cache = array(); @@ -182,4 +182,3 @@ class OC_CONFIG{ return true; } } -?> diff --git a/lib/connect.php b/lib/connect.php index 6fc8f2165cf..22e48750a62 100644 --- a/lib/connect.php +++ b/lib/connect.php @@ -25,7 +25,7 @@ * Class for connecting multiply ownCloud installations * */ -class OC_CONNECT{ +class OC_Connect{ static private $clouds=array(); static function connect($path,$user,$password){ @@ -38,263 +38,3 @@ class OC_CONNECT{ } } } - - -/** - * Class for connection to a remote owncloud installation - * - */ -class OC_REMOTE_CLOUD{ - private $path; - private $connected=false; - private $cookiefile=false; - - /** - * make an api call to the remote cloud - * @param string $action - * @param array parameters - * @param bool assoc when set to true, the result will be parsed as associative array - * - */ - private function apiCall($action,$parameters=false,$assoc=false){ - if(!$this->cookiefile){ - $this->cookiefile=sys_get_temp_dir().'/remoteCloudCookie'.uniqid(); - } - $url=$this->path.='/files/api.php'; - $fields_string="action=$action&"; - if(is_array($parameters)){ - foreach($parameters as $key=>$value){ - $fields_string.=$key.'='.$value.'&'; - } - rtrim($fields_string,'&'); - } - $ch=curl_init(); - curl_setopt($ch,CURLOPT_URL,$url); - curl_setopt($ch,CURLOPT_POST,count($parameters)); - curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); - curl_setopt($ch, CURLOPT_COOKIEFILE,$this->cookiefile); - curl_setopt($ch, CURLOPT_COOKIEJAR,$this->cookiefile); - curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); - $result=curl_exec($ch); - $result=trim($result); - $info=curl_getinfo($ch); - $httpCode=$info['http_code']; - curl_close($ch); - if($httpCode==200 or $httpCode==0){ - return json_decode($result,$assoc); - }else{ - return false; - } - } - - public function __construct($path,$user,$password){ - $this->path=$path; - $this->connected=$this->apiCall('login',array('username'=>$user,'password'=>$password)); - } - - /** - * check if we are stull logged in on the remote cloud - * - */ - public function isLoggedIn(){ - if(!$this->connected){ - return false; - } - return $this->apiCall('checklogin'); - } - - public function __get($name){ - switch($name){ - case 'connected': - return $this->connected; - } - } - - /** - * disconnect from the remote cloud - * - */ - public function disconnect(){ - $this->connected=false; - if(is_file($this->cookiefile)){ - unlink($this->cookiefile); - } - $this->cookiefile=false; - } - - /** - * create a new file or directory - * @param string $dir - * @param string $name - * @param string $type - */ - public function newFile($dir,$name,$type){ - if(!$this->connected){ - return false; - } - return $this->apiCall('new',array('dir'=>$dir,'name'=>$name,'type'=>$type),true); - } - - /** - * deletes a file or directory - * @param string $dir - * @param string $file - */ - public function delete($dir,$name){ - if(!$this->connected){ - return false; - } - return $this->apiCall('delete',array('dir'=>$dir,'file'=>$name),true); - } - - /** - * moves a file or directory - * @param string $sorceDir - * @param string $sorceFile - * @param string $targetDir - * @param string $targetFile - */ - public function move($sourceDir,$sourceFile,$targetDir,$targetFile){ - if(!$this->connected){ - return false; - } - return $this->apiCall('move',array('sourcedir'=>$sourceDir,'source'=>$sourceFile,'targetdir'=>$targetDir,'target'=>$targetFile),true); - } - - /** - * copies a file or directory - * @param string $sorceDir - * @param string $sorceFile - * @param string $targetDir - * @param string $targetFile - */ - public function copy($sourceDir,$sourceFile,$targetDir,$targetFile){ - if(!$this->connected){ - return false; - } - return $this->apiCall('copy',array('sourcedir'=>$sourceDir,'source'=>$sourceFile,'targetdir'=>$targetDir,'target'=>$targetFile),true); - } - - /** - * get a file tree - * @param string $dir - */ - public function getTree($dir){ - if(!$this->connected){ - return false; - } - return $this->apiCall('gettree',array('dir'=>$dir),true); - } - - /** - * get the files inside a directory of the remote cloud - * @param string $dir - */ - public function getFiles($dir){ - if(!$this->connected){ - return false; - } - return $this->apiCall('getfiles',array('dir'=>$dir),true); - } - - /** - * get a remove file and save it in a temporary file and return the path of the temporary file - * @param string $dir - * @param string $file - * @return string - */ - public function getFile($dir, $file){ - if(!$this->connected){ - return false; - } - $ch=curl_init(); - if(!$this->cookiefile){ - $this->cookiefile=sys_get_temp_dir().'/remoteCloudCookie'.uniqid(); - } - $tmpfile=tempnam(sys_get_temp_dir(),'remoteCloudFile'); - $fp=fopen($tmpfile,'w+'); - $url=$this->path.="/files/api.php?action=get&dir=$dir&file=$file"; - curl_setopt($ch,CURLOPT_URL,$url); - curl_setopt($ch, CURLOPT_COOKIEFILE,$this->cookiefile); - curl_setopt($ch, CURLOPT_COOKIEJAR,$this->cookiefile); - curl_setopt($ch, CURLOPT_FILE, $fp); - curl_exec($ch); - fclose($fp); - curl_close($ch); - return $tmpfile; - } - - public function sendFile($sourceDir,$sourceFile,$targetDir,$targetFile){ - global $WEBROOT; - $source=$sourceDir.'/'.$sourceFile; - $tmp=OC_FILESYSTEM::toTmpFile($source); - return $this->sendTmpFile($tmp,$targetDir,$targetFile); - } - - public function sendTmpFile($tmp,$targetDir,$targetFile){ - $token=sha1(uniqid().$tmp); - global $WEBROOT; - $file=sys_get_temp_dir().'/'.'remoteCloudFile'.$token; - rename($tmp,$file); - if( OC_CONFIG::getValue( "forcessl", false ) or isset($_SERVER['HTTPS']) and $_SERVER['HTTPS'] == 'on') { - $url = "https://". $_SERVER['SERVER_NAME'] . $WEBROOT; - }else{ - $url = "http://". $_SERVER['SERVER_NAME'] . $WEBROOT; - } - return $this->apiCall('pull',array('dir'=>$targetDir,'file'=>$targetFile,'token'=>$token,'source'=>$url),true); - } -} - -function OC_CONNECT_TEST($path,$user,$password){ - echo 'connecting...'; - $remote=OC_CONNECT::connect($path,$user,$password); - if($remote->connected){ - echo 'done<br/>'; - if($remote->isLoggedIn()){ - echo 'logged in, session working<br/>'; - echo 'trying to get remote files...'; - $files=$remote->getFiles(''); - if($files){ - echo count($files).' files found:<br/>'; - foreach($files as $file){ - echo "{$file['type']} {$file['name']}: {$file['size']} bytes<br/>"; - } - echo 'getting file "'.$file['name'].'"...'; - $size=$file['size']; - $file=$remote->getFile('',$file['name']); - if(file_exists($file)){ - $newSize=filesize($file); - if($size!=$newSize){ - echo "fail<br/>Error: $newSize bytes received, $size expected."; - echo '<br/><br/>Recieved file:<br/>'; - readfile($file); - unlink($file); - return; - } - OC_FILESYSTEM::fromTmpFile($file,'/remoteFile'); - echo 'done<br/>'; - echo 'sending file "burning_avatar.png"...'; - $res=$remote->sendFile('','burning_avatar.png','','burning_avatar.png'); - if($res){ - echo 'done<br/>'; - }else{ - echo 'fail<br/>'; - } - }else{ - echo 'fail<br/>'; - } - }else{ - echo 'fail<br/>'; - } - }else{ - echo 'no longer logged in, session fail<br/>'; - } - }else{ - echo 'fail<br/>'; - } - $remote->disconnect(); - die(); -} - - -?> diff --git a/lib/Connector/Sabre/auth.php b/lib/connector/sabre/auth.php index cfe7723e761..1e87c7cee08 100644 --- a/lib/Connector/Sabre/auth.php +++ b/lib/connector/sabre/auth.php @@ -1,5 +1,4 @@ <?php -require_once("lib/base.php"); /** * HTTP Basic authentication backend class * @@ -24,8 +23,8 @@ class OC_Connector_Sabre_Auth extends Sabre_DAV_Auth_Backend_AbstractBasic { * @return bool */ protected function validateUserPass($username, $password){ - if(OC_USER::login($username,$password)){ - OC_UTIL::setUpFS(); + if(OC_User::login($username,$password)){ + OC_Util::setUpFS(); return true; } else{ diff --git a/lib/Connector/Sabre/directory.php b/lib/connector/sabre/directory.php index d0ff87f9b1a..139c6b784b1 100644 --- a/lib/Connector/Sabre/directory.php +++ b/lib/connector/sabre/directory.php @@ -1,7 +1,4 @@ <?php - -require_once("lib/base.php"); - /** * Directory class * @@ -25,7 +22,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa public function createFile($name, $data = null) { $newPath = $this->path . '/' . $name; - OC_FILESYSTEM::file_put_contents($newPath,$data); + OC_Filesystem::file_put_contents($newPath,$data); } @@ -38,7 +35,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa public function createDirectory($name) { $newPath = $this->path . '/' . $name; - OC_FILESYSTEM::mkdir($newPath); + OC_Filesystem::mkdir($newPath); } @@ -53,9 +50,9 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa $path = $this->path . '/' . $name; - if (!OC_FILESYSTEM::file_exists($path)) throw new Sabre_DAV_Exception_FileNotFound('File with name ' . $path . ' could not be located'); + if (!OC_Filesystem::file_exists($path)) throw new Sabre_DAV_Exception_FileNotFound('File with name ' . $path . ' could not be located'); - if (OC_FILESYSTEM::is_dir($path)) { + if (OC_Filesystem::is_dir($path)) { return new OC_Connector_Sabre_Directory($path); @@ -76,8 +73,8 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa $nodes = array(); // foreach(scandir($this->path) as $node) if($node!='.' && $node!='..') $nodes[] = $this->getChild($node); - if( OC_FILESYSTEM::is_dir($this->path)){ - $dh = OC_FILESYSTEM::opendir($this->path); + if( OC_Filesystem::is_dir($this->path)){ + $dh = OC_Filesystem::opendir($this->path); while(( $node = readdir($dh)) !== false ){ if($node!='.' && $node!='..'){ $nodes[] = $this->getChild($node); @@ -97,7 +94,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa public function childExists($name) { $path = $this->path . '/' . $name; - return OC_FILESYSTEM::file_exists($path); + return OC_Filesystem::file_exists($path); } @@ -109,7 +106,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa public function delete() { foreach($this->getChildren() as $child) $child->delete(); - OC_FILESYSTEM::rmdir($this->path); + OC_Filesystem::rmdir($this->path); } @@ -121,8 +118,8 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa public function getQuotaInfo() { return array( - OC_FILESYSTEM::filesize('/'), - OC_FILESYSTEM::free_space() + OC_Filesystem::filesize('/'), + OC_Filesystem::free_space() ); } diff --git a/lib/Connector/Sabre/file.php b/lib/connector/sabre/file.php index bb5ab738430..b049f39c171 100644 --- a/lib/Connector/Sabre/file.php +++ b/lib/connector/sabre/file.php @@ -1,6 +1,4 @@ <?php - -require_once("lib/base.php"); /** * File class * @@ -20,7 +18,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D */ public function put($data) { - OC_FILESYSTEM::file_put_contents($this->path,$data); + OC_Filesystem::file_put_contents($this->path,$data); } @@ -31,7 +29,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D */ public function get() { - return OC_FILESYSTEM::file_get_contents($this->path); + return OC_Filesystem::file_get_contents($this->path); } @@ -42,7 +40,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D */ public function delete() { - OC_FILESYSTEM::unlink($this->path); + OC_Filesystem::unlink($this->path); } @@ -53,7 +51,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D */ public function getSize() { - return OC_FILESYSTEM::filesize($this->path); + return OC_Filesystem::filesize($this->path); } @@ -82,7 +80,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D */ public function getContentType() { - return OC_FILESYSTEM::getMimeType($this->path); + return OC_Filesystem::getMimeType($this->path); } } diff --git a/lib/Connector/Sabre/locks.php b/lib/connector/sabre/locks.php index 4f3eb7bbf52..7164d9a09c1 100644 --- a/lib/Connector/Sabre/locks.php +++ b/lib/connector/sabre/locks.php @@ -1,6 +1,4 @@ <?php -require_once("lib/base.php"); - /** * The Lock manager allows you to handle all file-locks centrally. * @@ -52,7 +50,7 @@ class OC_Connector_Sabre_Locks extends Sabre_DAV_Locks_Backend_Abstract { // pure sql. MySQL's non-standard string concatination prevents us // from doing this though. $query = 'SELECT * FROM *PREFIX*locks WHERE userid = ? AND (created + timeout) > ? AND ((uri = ?)'; - $params = array(OC_USER::getUser(),time(),$uri); + $params = array(OC_User::getUser(),time(),$uri); // We need to check locks for every part in the uri. $uriParts = explode('/',$uri); @@ -124,10 +122,10 @@ class OC_Connector_Sabre_Locks extends Sabre_DAV_Locks_Backend_Abstract { if ($exists) { $query = OC_DB::prepare( 'UPDATE *PREFIX*locks SET owner = ?, timeout = ?, scope = ?, depth = ?, uri = ?, created = ? WHERE userid = ? AND token = ?' ); - $result = $query->execute( array($lockInfo->owner,$lockInfo->timeout,$lockInfo->scope,$lockInfo->depth,$uri,$lockInfo->created,OC_USER::getUser(),$lockInfo->token)); + $result = $query->execute( array($lockInfo->owner,$lockInfo->timeout,$lockInfo->scope,$lockInfo->depth,$uri,$lockInfo->created,OC_User::getUser(),$lockInfo->token)); } else { $query = OC_DB::prepare( 'INSERT INTO *PREFIX*locks (userid,owner,timeout,scope,depth,uri,created,token) VALUES (?,?,?,?,?,?,?,?)' ); - $result = $query->execute( array(OC_USER::getUser(),$lockInfo->owner,$lockInfo->timeout,$lockInfo->scope,$lockInfo->depth,$uri,$lockInfo->created,$lockInfo->token)); + $result = $query->execute( array(OC_User::getUser(),$lockInfo->owner,$lockInfo->timeout,$lockInfo->scope,$lockInfo->depth,$uri,$lockInfo->created,$lockInfo->token)); } return true; @@ -144,11 +142,10 @@ class OC_Connector_Sabre_Locks extends Sabre_DAV_Locks_Backend_Abstract { public function unlock($uri,Sabre_DAV_Locks_LockInfo $lockInfo) { $query = OC_DB::prepare( 'DELETE FROM *PREFIX*locks WHERE userid = ? AND uri=? AND token=?' ); - $result = $query->execute( array(OC_USER::getUser(),$uri,$lockInfo->token)); + $result = $query->execute( array(OC_User::getUser(),$uri,$lockInfo->token)); return $result->numRows() === 1; } } - diff --git a/lib/Connector/Sabre/node.php b/lib/connector/sabre/node.php index dc1013dc524..ace572a1ee3 100644 --- a/lib/Connector/Sabre/node.php +++ b/lib/connector/sabre/node.php @@ -1,7 +1,4 @@ <?php - -require_once("lib/base.php"); - /** * Base node-class * @@ -73,12 +70,12 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr $newPath = $parentPath . '/' . $newName; $oldPath = $this->path; - OC_FILESYSTEM::rename($this->path,$newPath); + OC_Filesystem::rename($this->path,$newPath); $this->path = $newPath; $query = OC_DB::prepare( 'UPDATE *PREFIX*properties SET propertypath = ? WHERE userid = ? AND propertypath = ?' ); - $query->execute( array( $newPath,OC_USER::getUser(), $oldPath )); + $query->execute( array( $newPath,OC_User::getUser(), $oldPath )); } @@ -91,7 +88,7 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr */ public function getLastModified() { - return OC_FILESYSTEM::filemtime($this->path); + return OC_Filesystem::filemtime($this->path); } @@ -109,17 +106,17 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr if (is_null($propertyValue)) { if(array_key_exists( $propertyName, $existing )){ $query = OC_DB::prepare( 'DELETE FROM *PREFIX*properties WHERE userid = ? AND propertypath = ? AND propertyname = ?' ); - $query->execute( array( OC_USER::getUser(), $this->path, $propertyName )); + $query->execute( array( OC_User::getUser(), $this->path, $propertyName )); } } else { if(!array_key_exists( $propertyName, $existing )){ $query = OC_DB::prepare( 'INSERT INTO *PREFIX*properties (userid,propertypath,propertyname,propertyvalue) VALUES(?,?,?,?)' ); - $query->execute( array( OC_USER::getUser(), $this->path, $propertyName,$propertyValue )); + $query->execute( array( OC_User::getUser(), $this->path, $propertyName,$propertyValue )); } else{ $query = OC_DB::prepare( 'UPDATE *PREFIX*properties SET propertyvalue = ? WHERE userid = ? AND propertypath = ? AND propertyname = ?' ); - $query->execute( array( $propertyValue,OC_USER::getUser(), $this->path, $propertyName )); + $query->execute( array( $propertyValue,OC_User::getUser(), $this->path, $propertyName )); } } @@ -139,7 +136,7 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr function getProperties($properties) { // At least some magic in here :-) $query = OC_DB::prepare( 'SELECT * FROM *PREFIX*properties WHERE userid = ? AND propertypath = ?' ); - $result = $query->execute( array( OC_USER::getUser(), $this->path )); + $result = $query->execute( array( OC_User::getUser(), $this->path )); $existing = array(); while( $row = $result->fetchRow()){ @@ -158,4 +155,3 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr return $props; } } - diff --git a/lib/database.php b/lib/db.php index 8d7c76756c1..858db09b764 100644 --- a/lib/database.php +++ b/lib/db.php @@ -38,13 +38,13 @@ class OC_DB { */ static public function connect(){ // The global data we need - $CONFIG_DBNAME = OC_CONFIG::getValue( "dbname", "owncloud" );; - $CONFIG_DBHOST = OC_CONFIG::getValue( "dbhost", "" );; - $CONFIG_DBUSER = OC_CONFIG::getValue( "dbuser", "" );; - $CONFIG_DBPASSWORD = OC_CONFIG::getValue( "dbpassword", "" );; - $CONFIG_DBTYPE = OC_CONFIG::getValue( "dbtype", "sqlite" );; + $CONFIG_DBNAME = OC_Config::getValue( "dbname", "owncloud" );; + $CONFIG_DBHOST = OC_Config::getValue( "dbhost", "" );; + $CONFIG_DBUSER = OC_Config::getValue( "dbuser", "" );; + $CONFIG_DBPASSWORD = OC_Config::getValue( "dbpassword", "" );; + $CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" );; global $SERVERROOT; - $datadir=OC_CONFIG::getValue( "datadirectory", "$SERVERROOT/data" ); + $datadir=OC_Config::getValue( "datadirectory", "$SERVERROOT/data" ); // do nothing if the connection already has been established if(!self::$DBConnection){ @@ -235,8 +235,8 @@ class OC_DB { * TODO: write more documentation */ public static function createDbFromStructure( $file ){ - $CONFIG_DBNAME = OC_CONFIG::getValue( "dbname", "owncloud" ); - $CONFIG_DBTABLEPREFIX = OC_CONFIG::getValue( "dbtableprefix", "oc_" ); + $CONFIG_DBNAME = OC_Config::getValue( "dbname", "owncloud" ); + $CONFIG_DBTABLEPREFIX = OC_Config::getValue( "dbtableprefix", "oc_" ); self::connectScheme(); @@ -259,7 +259,7 @@ class OC_DB { if( $definition instanceof MDB2_Schema_Error ){ die( $definition->getMessage().': '.$definition->getUserInfo()); } -// if(OC_CONFIG::getValue('dbtype','sqlite')=='sqlite'){ +// if(OC_Config::getValue('dbtype','sqlite')=='sqlite'){ // $definition['overwrite']=true;//always overwrite for sqlite // } $ret=self::$schema->createDatabase( $definition ); @@ -302,8 +302,8 @@ class OC_DB { private static function processQuery( $query ){ self::connect(); // We need Database type and table prefix - $CONFIG_DBTYPE = OC_CONFIG::getValue( "dbtype", "sqlite" ); - $CONFIG_DBTABLEPREFIX = OC_CONFIG::getValue( "dbtableprefix", "oc_" ); + $CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" ); + $CONFIG_DBTABLEPREFIX = OC_Config::getValue( "dbtableprefix", "oc_" ); // differences is getting the current timestamp $query = str_replace( 'NOW()', self::$DBConnection->now(), $query ); @@ -339,8 +339,8 @@ class OC_DB { * @param string $file the xml file describing the tables */ public static function removeDBStructure($file){ - $CONFIG_DBNAME = OC_CONFIG::getValue( "dbname", "owncloud" ); - $CONFIG_DBTABLEPREFIX = OC_CONFIG::getValue( "dbtableprefix", "oc_" ); + $CONFIG_DBNAME = OC_Config::getValue( "dbname", "owncloud" ); + $CONFIG_DBTABLEPREFIX = OC_Config::getValue( "dbtableprefix", "oc_" ); self::connectScheme(); // read file @@ -362,4 +362,3 @@ class OC_DB { } } } -?>
\ No newline at end of file diff --git a/lib/fakedirstream.php b/lib/fakedirstream.php new file mode 100644 index 00000000000..fa3e64da62c --- /dev/null +++ b/lib/fakedirstream.php @@ -0,0 +1,45 @@ +<?php +global $FAKEDIRS; +$FAKEDIRS=array(); + +class fakeDirStream{ + private $name; + private $data; + private $index; + + public function dir_opendir($path,$options){ + global $FAKEDIRS; + $url=parse_url($path); + $this->name=substr($path,strlen('fakedir://')); + $this->index=0; + if(isset($FAKEDIRS[$this->name])){ + $this->data=$FAKEDIRS[$this->name]; + }else{ + $this->data=array(); + } + return true; + } + + public function dir_readdir(){ + if($this->index>=count($this->data)){ + return false; + } + $filename=$this->data[$this->index]; + $this->index++; + return $filename; + } + + public function dir_closedir() { + $this->data=false; + $this->name=''; + return true; + } + + public function dir_rewinddir() { + $this->index=0; + return true; + } +} + +stream_wrapper_register("fakedir", "fakeDirStream"); + diff --git a/lib/files.php b/lib/files.php index d8133667954..d189a96fd89 100644 --- a/lib/files.php +++ b/lib/files.php @@ -21,14 +21,11 @@ * */ -require_once("log.php"); - - /** * Class for fileserver access * */ -class OC_FILES { +class OC_Files { static $tmpFiles=array(); /** @@ -45,21 +42,21 @@ class OC_FILES { $dirs=array(); $file=array(); $files=array(); - if(OC_FILESYSTEM::is_dir($directory)) { - if ($dh = OC_FILESYSTEM::opendir($directory)) { + if(OC_Filesystem::is_dir($directory)) { + if ($dh = OC_Filesystem::opendir($directory)) { while (($filename = readdir($dh)) !== false) { if($filename<>'.' and $filename<>'..' and substr($filename,0,1)!='.'){ $file=array(); $filesfound=true; $file['name']=$filename; $file['directory']=$directory; - $stat=OC_FILESYSTEM::stat($directory.'/'.$filename); + $stat=OC_Filesystem::stat($directory.'/'.$filename); $file=array_merge($file,$stat); - $file['size']=OC_FILESYSTEM::filesize($directory.'/'.$filename); - $file['mime']=OC_FILES::getMimeType($directory .'/'. $filename); - $file['readable']=OC_FILESYSTEM::is_readable($directory .'/'. $filename); - $file['writeable']=OC_FILESYSTEM::is_writeable($directory .'/'. $filename); - $file['type']=OC_FILESYSTEM::filetype($directory .'/'. $filename); + $file['size']=OC_Filesystem::filesize($directory.'/'.$filename); + $file['mime']=OC_Files::getMimeType($directory .'/'. $filename); + $file['readable']=OC_Filesystem::is_readable($directory .'/'. $filename); + $file['writeable']=OC_Filesystem::is_writeable($directory .'/'. $filename); + $file['type']=OC_Filesystem::filetype($directory .'/'. $filename); if($file['type']=='dir'){ $dirs[$file['name']]=$file; }else{ @@ -101,16 +98,16 @@ class OC_FILES { } foreach($files as $file){ $file=$dir.'/'.$file; - if(OC_FILESYSTEM::is_file($file)){ - $tmpFile=OC_FILESYSTEM::toTmpFile($file); + if(OC_Filesystem::is_file($file)){ + $tmpFile=OC_Filesystem::toTmpFile($file); self::$tmpFiles[]=$tmpFile; $zip->addFile($tmpFile,basename($file)); - }elseif(OC_FILESYSTEM::is_dir($file)){ + }elseif(OC_Filesystem::is_dir($file)){ zipAddDir($file,$zip); } } $zip->close(); - }elseif(OC_FILESYSTEM::is_dir($dir.'/'.$files)){ + }elseif(OC_Filesystem::is_dir($dir.'/'.$files)){ $zip = new ZipArchive(); $filename = sys_get_temp_dir()."/ownCloud.zip"; if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) { @@ -123,7 +120,7 @@ class OC_FILES { $zip=false; $filename=$dir.'/'.$files; } - if($zip or OC_FILESYSTEM::is_readable($filename)){ + if($zip or OC_Filesystem::is_readable($filename)){ header('Content-Disposition: attachment; filename='.basename($filename)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); @@ -133,12 +130,12 @@ class OC_FILES { header('Content-Type: application/zip'); header('Content-Length: ' . filesize($filename)); }else{ - header('Content-Type: ' . OC_FILESYSTEM::getMimeType($filename)); - header('Content-Length: ' . OC_FILESYSTEM::filesize($filename)); + header('Content-Type: ' . OC_Filesystem::getMimeType($filename)); + header('Content-Length: ' . OC_Filesystem::filesize($filename)); } - }elseif($zip or !OC_FILESYSTEM::file_exists($filename)){ + }elseif($zip or !OC_Filesystem::file_exists($filename)){ header("HTTP/1.0 404 Not Found"); - $tmpl = new OC_TEMPLATE( '', '404', 'guest' ); + $tmpl = new OC_Template( '', '404', 'guest' ); $tmpl->assign('file',$filename); $tmpl->printPage(); // die('404 Not Found'); @@ -147,12 +144,12 @@ class OC_FILES { die('403 Forbidden'); } ob_end_clean(); -// OC_LOG::event($_SESSION['username'],3,"$dir/$files"); +// OC_Log::event($_SESSION['username'],3,"$dir/$files"); if($zip){ readfile($filename); unlink($filename); }else{ - OC_FILESYSTEM::readfile($filename); + OC_Filesystem::readfile($filename); } foreach(self::$tmpFiles as $tmpFile){ if(file_exists($tmpFile) and is_file($tmpFile)){ @@ -170,10 +167,10 @@ class OC_FILES { * @param file $target */ public static function move($sourceDir,$source,$targetDir,$target){ - if(OC_USER::isLoggedIn()){ + if(OC_User::isLoggedIn()){ $targetFile=$targetDir.'/'.$target; $sourceFile=$sourceDir.'/'.$source; - return OC_FILESYSTEM::rename($sourceFile,$targetFile); + return OC_Filesystem::rename($sourceFile,$targetFile); } } @@ -186,10 +183,10 @@ class OC_FILES { * @param file $target */ public static function copy($sourceDir,$source,$targetDir,$target){ - if(OC_USER::isLoggedIn()){ + if(OC_User::isLoggedIn()){ $targetFile=$targetDir.'/'.$target; $sourceFile=$sourceDir.'/'.$source; - return OC_FILESYSTEM::copy($sourceFile,$targetFile); + return OC_Filesystem::copy($sourceFile,$targetFile); } } @@ -201,15 +198,15 @@ class OC_FILES { * @param type $type */ public static function newFile($dir,$name,$type){ - if(OC_USER::isLoggedIn()){ + if(OC_User::isLoggedIn()){ $file=$dir.'/'.$name; if($type=='dir'){ - return OC_FILESYSTEM::mkdir($file); + return OC_Filesystem::mkdir($file); }elseif($type=='file'){ - $fileHandle=OC_FILESYSTEM::fopen($file, 'w'); + $fileHandle=OC_Filesystem::fopen($file, 'w'); if($fileHandle){ fclose($fileHandle); -// OC_LOG::event($_SESSION['username'],4,"$dir/$name"); +// OC_Log::event($_SESSION['username'],4,"$dir/$name"); return true; }else{ return false; @@ -225,12 +222,12 @@ class OC_FILES { * @param file $name */ public static function delete($dir,$file){ - if(OC_USER::isLoggedIn()){ + if(OC_User::isLoggedIn()){ $file=$dir.'/'.$file; - if(OC_FILESYSTEM::is_file($file)){ - return OC_FILESYSTEM::unlink($file); - }elseif(OC_FILESYSTEM::is_dir($file)){ - return OC_FILESYSTEM::delTree($file); + if(OC_Filesystem::is_file($file)){ + return OC_Filesystem::unlink($file); + }elseif(OC_Filesystem::is_dir($file)){ + return OC_Filesystem::delTree($file); } } } @@ -242,7 +239,7 @@ class OC_FILES { * @return string guessed mime type */ static function getMimeType($path){ - return OC_FILESYSTEM::getMimeType($path); + return OC_Filesystem::getMimeType($path); } /** @@ -252,7 +249,7 @@ class OC_FILES { * @return array */ static function getTree($path){ - return OC_FILESYSTEM::getTree($path); + return OC_Filesystem::getTree($path); } /** @@ -276,7 +273,7 @@ class OC_FILES { $httpCode=$info['http_code']; curl_close($ch); if($httpCode==200 or $httpCode==0){ - OC_FILESYSTEM::fromTmpFile($tmpfile,$dir.'/'.$file); + OC_Filesystem::fromTmpFile($tmpfile,$dir.'/'.$file); return true; }else{ return false; @@ -290,7 +287,7 @@ class OC_FILES { static function setUploadLimit($size){ global $SERVERROOT; global $WEBROOT; - $size=OC_HELPER::humanFileSize($size); + $size=OC_Helper::humanFileSize($size); $size=substr($size,0,-1);//strip the B $size=str_replace(' ','',$size); //remove the space between the size and the postfix $content = "ErrorDocument 404 /$WEBROOT/core/templates/404.php\n";//custom 404 error page @@ -301,79 +298,3 @@ class OC_FILES { @file_put_contents($SERVERROOT.'/.htaccess', $content); //supress errors in case we don't have permissions for it } } - -function zipAddDir($dir,$zip,$internalDir=''){ - $dirname=basename($dir); - $zip->addEmptyDir($internalDir.$dirname); - $internalDir.=$dirname.='/'; - $files=OC_FILES::getdirectorycontent($dir); - foreach($files as $file){ - $filename=$file['name']; - $file=$dir.'/'.$filename; - if(OC_FILESYSTEM::is_file($file)){ - $tmpFile=OC_FILESYSTEM::toTmpFile($file); - OC_FILES::$tmpFiles[]=$tmpFile; - $zip->addFile($tmpFile,$internalDir.$filename); - }elseif(OC_FILESYSTEM::is_dir($file)){ - zipAddDir($file,$zip,$internalDir); - } - } -} - -if(!function_exists('sys_get_temp_dir')) { - function sys_get_temp_dir() { - if( $temp=getenv('TMP') ) return $temp; - if( $temp=getenv('TEMP') ) return $temp; - if( $temp=getenv('TMPDIR') ) return $temp; - $temp=tempnam(__FILE__,''); - if (file_exists($temp)) { - unlink($temp); - return dirname($temp); - } - return null; - } -} - -global $FAKEDIRS; -$FAKEDIRS=array(); - -class fakeDirStream{ - private $name; - private $data; - private $index; - - public function dir_opendir($path,$options){ - global $FAKEDIRS; - $url=parse_url($path); - $this->name=substr($path,strlen('fakedir://')); - $this->index=0; - if(isset($FAKEDIRS[$this->name])){ - $this->data=$FAKEDIRS[$this->name]; - }else{ - $this->data=array(); - } - return true; - } - - public function dir_readdir(){ - if($this->index>=count($this->data)){ - return false; - } - $filename=$this->data[$this->index]; - $this->index++; - return $filename; - } - - public function dir_closedir() { - $this->data=false; - $this->name=''; - return true; - } - - public function dir_rewinddir() { - $this->index=0; - return true; - } -} -stream_wrapper_register("fakedir", "fakeDirStream"); -?> diff --git a/lib/filestorage.php b/lib/filestorage.php index 601cf6f37fe..b398285d340 100644 --- a/lib/filestorage.php +++ b/lib/filestorage.php @@ -23,7 +23,7 @@ /** * Privde a common interface to all different storage options */ -class OC_FILESTORAGE{ +class OC_Filestorage{ public function __construct($parameters){} public function mkdir($path){} public function rmdir($path){} @@ -58,363 +58,3 @@ class OC_FILESTORAGE{ public function search($query){} public function getLocalFile($path){}// get a path to a local version of the file, whether the original file is local or remote } - - -OC_FILESYSTEM::registerStorageType('local','OC_FILESTORAGE_LOCAL',array('datadir'=>'string')); -/** - * for local filestore, we only have to map the paths - */ -class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ - private $datadir; - private static $mimetypes=null; - public function __construct($arguments){ - $this->datadir=$arguments['datadir']; - if(substr($this->datadir,-1)!=='/'){ - $this->datadir.='/'; - } - } - public function mkdir($path){ - if($return=mkdir($this->datadir.$path)){ - $this->clearFolderSizeCache($path); - } - return $return; - } - public function rmdir($path){ - if($return=rmdir($this->datadir.$path)){ - $this->clearFolderSizeCache($path); - } - return $return; - } - public function opendir($path){ - return opendir($this->datadir.$path); - } - public function is_dir($path){ - return (is_dir($this->datadir.$path) or substr($path,-1)=='/'); - } - public function is_file($path){ - return is_file($this->datadir.$path); - } - public function stat($path){ - return stat($this->datadir.$path); - } - public function filetype($path){ - $filetype=filetype($this->datadir.$path); - if($filetype=='link'){ - $filetype=filetype(readlink($this->datadir.$path)); - } - return $filetype; - } - public function filesize($path){ - if($this->is_dir($path)){ - return $this->getFolderSize($path); - }else{ - return filesize($this->datadir.$path); - } - } - public function is_readable($path){ - return is_readable($this->datadir.$path); - } - public function is_writeable($path){ - return is_writeable($this->datadir.$path); - } - public function file_exists($path){ - return file_exists($this->datadir.$path); - } - public function readfile($path){ - return readfile($this->datadir.$path); - } - public function filectime($path){ - return filectime($this->datadir.$path); - } - public function filemtime($path){ - return filemtime($this->datadir.$path); - } - public function fileatime($path){ - return fileatime($this->datadir.$path); - } - public function file_get_contents($path){ - return file_get_contents($this->datadir.$path); - } - public function file_put_contents($path,$data){ - if($return=file_put_contents($this->datadir.$path,$data)){ - $this->clearFolderSizeCache($path); - } - } - public function unlink($path){ - if($return=unlink($this->datadir.$path)){ - $this->clearFolderSizeCache($path); - } - return $return; - } - public function rename($path1,$path2){ - if($return=rename($this->datadir.$path1,$this->datadir.$path2)){ - $this->clearFolderSizeCache($path1); - $this->clearFolderSizeCache($path2); - } - return $return; - } - public function copy($path1,$path2){ - if($this->is_dir($path2)){ - if(!$this->file_exists($path2)){ - $this->mkdir($path2); - } - $source=substr($path1,strrpos($path1,'/')+1); - $path2.=$source; - } - if($return=copy($this->datadir.$path1,$this->datadir.$path2)){ - $this->clearFolderSizeCache($path2); - } - return $return; - } - public function fopen($path,$mode){ - if($return=fopen($this->datadir.$path,$mode)){ - switch($mode){ - case 'r': - break; - case 'r+': - case 'w+': - case 'x+': - case 'a+': - $this->clearFolderSizeCache($path); - break; - case 'w': - case 'x': - case 'a': - $this->clearFolderSizeCache($path); - break; - } - } - return $return; - } - - public function getMimeType($fspath){ - if($this->is_readable($fspath)){ - if (@is_dir($this->datadir.$fspath)) { - // directories are easy - return "httpd/unix-directory"; - }elseif (function_exists('finfo_open') and function_exists('finfo_file') and $finfo=finfo_open(FILEINFO_MIME)){ - $mimeType =strtolower(finfo_file($finfo,$this->datadir.$fspath)); - $mimeType=substr($mimeType,0,strpos($mimeType,';')); - finfo_close($finfo); - return $mimeType; - } else if (function_exists("mime_content_type")) { - // use mime magic extension if available - $mime_type = mime_content_type($this->datadir.$fspath); - } else if (OC_HELPER::canExecute("file")) { - // it looks like we have a 'file' command, - // lets see it it does have mime support - $fp = popen("file -i -b '{$this->datadir}$fspath' 2>/dev/null", "r"); - $reply = fgets($fp); - pclose($fp); - - //trim the character set from the end of the response - $mime_type=substr($reply,0,strrpos($reply,' ')); - } - if (empty($mime_type)) { - // Fallback solution: (try to guess the type by the file extension - if(!self::$mimetypes){ - self::$mimetypes=include('mimetypes.list.php'); - } - $extention=strtolower(strrchr(basename($fspath), ".")); - $extention=substr($extention,1);//remove leading . - $mime_type=(isset(self::$mimetypes[$extention]))?self::$mimetypes[$extention]:'application/octet-stream'; - } - return $mime_type; - } - } - - public function toTmpFile($path){ - $tmpFolder=sys_get_temp_dir(); - $filename=tempnam($tmpFolder,'OC_TEMP_FILE_'.substr($path,strrpos($path,'.'))); - $fileStats = stat($this->datadir.$path); - if(copy($this->datadir.$path,$filename)){ - touch($filename, $fileStats['mtime'], $fileStats['atime']); - return $filename; - }else{ - return false; - } - } - - public function fromTmpFile($tmpFile,$path){ - $fileStats = stat($tmpFile); - if(rename($tmpFile,$this->datadir.$path)){ - touch($this->datadir.$path, $fileStats['mtime'], $fileStats['atime']); - $this->clearFolderSizeCache($path); - return true; - }else{ - return false; - } - } - - public function fromUploadedFile($tmpFile,$path){ - $fileStats = stat($tmpFile); - if(move_uploaded_file($tmpFile,$this->datadir.$path)){ - touch($this->datadir.$path, $fileStats['mtime'], $fileStats['atime']); - $this->clearFolderSizeCache($path); - return true; - }else{ - return false; - } - } - - public function delTree($dir) { - $dirRelative=$dir; - $dir=$this->datadir.$dir; - if (!file_exists($dir)) return true; - if (!is_dir($dir) || is_link($dir)) return unlink($dir); - foreach (scandir($dir) as $item) { - if ($item == '.' || $item == '..') continue; - if(is_file($dir.'/'.$item)){ - if(unlink($dir.'/'.$item)){ - $this->clearFolderSizeCache($dir); - } - }elseif(is_dir($dir.'/'.$item)){ - if (!$this->delTree($dirRelative. "/" . $item)){ - return false; - }; - } - } - if($return=rmdir($dir)){ - $this->clearFolderSizeCache($dir); - } - return $return; - } - - public function find($path){ - $return=System::find($this->datadir.$path); - foreach($return as &$file){ - $file=str_replace($file,$this->datadir,''); - } - return $return; - } - - public function getTree($dir) { - if(substr($dir,-1,1)=='/'){ - $dir=substr($dir,0,-1); - } - $tree=array(); - $tree[]=$dir; - $dirRelative=$dir; - $dir=$this->datadir.$dir; - if (!file_exists($dir)) return true; - foreach (scandir($dir) as $item) { - if ($item == '.' || $item == '..') continue; - if(is_file($dir.'/'.$item)){ - $tree[]=$dirRelative.'/'.$item; - }elseif(is_dir($dir.'/'.$item)){ - if ($subTree=$this->getTree($dirRelative. "/" . $item)){ - $tree=array_merge($tree,$subTree); - } - } - } - return $tree; - } - - public function hash($type,$path,$raw){ - return hash_file($type,$this->datadir.$path,$raw); - } - - public function free_space($path){ - return disk_free_space($this->datadir.$path); - } - - public function search($query){ - return $this->searchInDir($query); - } - public function getLocalFile($path){ - return $this->datadir.$path; - } - - private function searchInDir($query,$dir=''){ - $files=array(); - foreach (scandir($this->datadir.$dir) as $item) { - if ($item == '.' || $item == '..') continue; - if(strstr(strtolower($item),strtolower($query))!==false){ - $files[]=$dir.'/'.$item; - } - if(is_dir($this->datadir.$dir.'/'.$item)){ - $files=array_merge($files,$this->searchInDir($query,$dir.'/'.$item)); - } - } - return $files; - } - - /** - * @brief get the size of folder and it's content - * @param string $path file path - * @return int size of folder and it's content - */ - public function getFolderSize($path){ - $path=str_replace('//','/',$path); - if($this->is_dir($path) and substr($path,-1)!='/'){ - $path.='/'; - } - $query=OC_DB::prepare("SELECT size FROM *PREFIX*foldersize WHERE path=?"); - $size=$query->execute(array($path))->fetchAll(); - if(count($size)>0){// we already the size, just return it - return $size[0]['size']; - }else{//the size of the folder isn't know, calulate it - return $this->calculateFolderSize($path); - } - } - - /** - * @brief calulate the size of folder and it's content and cache it - * @param string $path file path - * @return int size of folder and it's content - */ - public function calculateFolderSize($path){ - if($this->is_file($path)){ - $path=dirname($path); - } - $path=str_replace('//','/',$path); - if($this->is_dir($path) and substr($path,-1)!='/'){ - $path.='/'; - } - $size=0; - if ($dh = $this->opendir($path)) { - while (($filename = readdir($dh)) !== false) { - if($filename!='.' and $filename!='..'){ - $subFile=$path.'/'.$filename; - if($this->is_file($subFile)){ - $size+=$this->filesize($subFile); - }else{ - $size+=$this->getFolderSize($subFile); - } - } - } - if($size>0){ - $query=OC_DB::prepare("INSERT INTO *PREFIX*foldersize VALUES(?,?)"); - $result=$query->execute(array($path,$size)); - } - } - return $size; - } - - /** - * @brief clear the folder size cache of folders containing a file - * @param string $path - */ - public function clearFolderSizeCache($path){ - if($this->is_file($path)){ - $path=dirname($path); - } - $path=str_replace('//','/',$path); - if($this->is_dir($path) and substr($path,-1)!='/'){ - $path.='/'; - } - $query=OC_DB::prepare("DELETE FROM *PREFIX*foldersize WHERE path = ?"); - $result=$query->execute(array($path)); - if($path!='/' and $path!=''){ - $parts=explode('/',$path); - //pop empty part - $part=array_pop($parts); - if(empty($part)){ - array_pop($parts); - } - $parent=implode('/',$parts); - $this->clearFolderSizeCache($parent); - } - } -} -?>
\ No newline at end of file diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php new file mode 100644 index 00000000000..3bbdd6b4137 --- /dev/null +++ b/lib/filestorage/local.php @@ -0,0 +1,357 @@ +<?php +/** + * for local filestore, we only have to map the paths + */ +class OC_Filestorage_Local extends OC_Filestorage{ + private $datadir; + private static $mimetypes=null; + public function __construct($arguments){ + $this->datadir=$arguments['datadir']; + if(substr($this->datadir,-1)!=='/'){ + $this->datadir.='/'; + } + } + public function mkdir($path){ + if($return=mkdir($this->datadir.$path)){ + $this->clearFolderSizeCache($path); + } + return $return; + } + public function rmdir($path){ + if($return=rmdir($this->datadir.$path)){ + $this->clearFolderSizeCache($path); + } + return $return; + } + public function opendir($path){ + return opendir($this->datadir.$path); + } + public function is_dir($path){ + return (is_dir($this->datadir.$path) or substr($path,-1)=='/'); + } + public function is_file($path){ + return is_file($this->datadir.$path); + } + public function stat($path){ + return stat($this->datadir.$path); + } + public function filetype($path){ + $filetype=filetype($this->datadir.$path); + if($filetype=='link'){ + $filetype=filetype(readlink($this->datadir.$path)); + } + return $filetype; + } + public function filesize($path){ + if($this->is_dir($path)){ + return $this->getFolderSize($path); + }else{ + return filesize($this->datadir.$path); + } + } + public function is_readable($path){ + return is_readable($this->datadir.$path); + } + public function is_writeable($path){ + return is_writeable($this->datadir.$path); + } + public function file_exists($path){ + return file_exists($this->datadir.$path); + } + public function readfile($path){ + return readfile($this->datadir.$path); + } + public function filectime($path){ + return filectime($this->datadir.$path); + } + public function filemtime($path){ + return filemtime($this->datadir.$path); + } + public function fileatime($path){ + return fileatime($this->datadir.$path); + } + public function file_get_contents($path){ + return file_get_contents($this->datadir.$path); + } + public function file_put_contents($path,$data){ + if($return=file_put_contents($this->datadir.$path,$data)){ + $this->clearFolderSizeCache($path); + } + } + public function unlink($path){ + if($return=unlink($this->datadir.$path)){ + $this->clearFolderSizeCache($path); + } + return $return; + } + public function rename($path1,$path2){ + if($return=rename($this->datadir.$path1,$this->datadir.$path2)){ + $this->clearFolderSizeCache($path1); + $this->clearFolderSizeCache($path2); + } + return $return; + } + public function copy($path1,$path2){ + if($this->is_dir($path2)){ + if(!$this->file_exists($path2)){ + $this->mkdir($path2); + } + $source=substr($path1,strrpos($path1,'/')+1); + $path2.=$source; + } + if($return=copy($this->datadir.$path1,$this->datadir.$path2)){ + $this->clearFolderSizeCache($path2); + } + return $return; + } + public function fopen($path,$mode){ + if($return=fopen($this->datadir.$path,$mode)){ + switch($mode){ + case 'r': + break; + case 'r+': + case 'w+': + case 'x+': + case 'a+': + $this->clearFolderSizeCache($path); + break; + case 'w': + case 'x': + case 'a': + $this->clearFolderSizeCache($path); + break; + } + } + return $return; + } + + public function getMimeType($fspath){ + if($this->is_readable($fspath)){ + if (@is_dir($this->datadir.$fspath)) { + // directories are easy + return "httpd/unix-directory"; + }elseif (function_exists('finfo_open') and function_exists('finfo_file') and $finfo=finfo_open(FILEINFO_MIME)){ + $mimeType =strtolower(finfo_file($finfo,$this->datadir.$fspath)); + $mimeType=substr($mimeType,0,strpos($mimeType,';')); + finfo_close($finfo); + return $mimeType; + } else if (function_exists("mime_content_type")) { + // use mime magic extension if available + $mime_type = mime_content_type($this->datadir.$fspath); + } else if (OC_Helper::canExecute("file")) { + // it looks like we have a 'file' command, + // lets see it it does have mime support + $fp = popen("file -i -b '{$this->datadir}$fspath' 2>/dev/null", "r"); + $reply = fgets($fp); + pclose($fp); + + //trim the character set from the end of the response + $mime_type=substr($reply,0,strrpos($reply,' ')); + } + if (empty($mime_type)) { + // Fallback solution: (try to guess the type by the file extension + if(!self::$mimetypes){ + self::$mimetypes=include('mimetypes.list.php'); + } + $extention=strtolower(strrchr(basename($fspath), ".")); + $extention=substr($extention,1);//remove leading . + $mime_type=(isset(self::$mimetypes[$extention]))?self::$mimetypes[$extention]:'application/octet-stream'; + } + return $mime_type; + } + } + + public function toTmpFile($path){ + $tmpFolder=sys_get_temp_dir(); + $filename=tempnam($tmpFolder,'OC_TEMP_FILE_'.substr($path,strrpos($path,'.'))); + $fileStats = stat($this->datadir.$path); + if(copy($this->datadir.$path,$filename)){ + touch($filename, $fileStats['mtime'], $fileStats['atime']); + return $filename; + }else{ + return false; + } + } + + public function fromTmpFile($tmpFile,$path){ + $fileStats = stat($tmpFile); + if(rename($tmpFile,$this->datadir.$path)){ + touch($this->datadir.$path, $fileStats['mtime'], $fileStats['atime']); + $this->clearFolderSizeCache($path); + return true; + }else{ + return false; + } + } + + public function fromUploadedFile($tmpFile,$path){ + $fileStats = stat($tmpFile); + if(move_uploaded_file($tmpFile,$this->datadir.$path)){ + touch($this->datadir.$path, $fileStats['mtime'], $fileStats['atime']); + $this->clearFolderSizeCache($path); + return true; + }else{ + return false; + } + } + + public function delTree($dir) { + $dirRelative=$dir; + $dir=$this->datadir.$dir; + if (!file_exists($dir)) return true; + if (!is_dir($dir) || is_link($dir)) return unlink($dir); + foreach (scandir($dir) as $item) { + if ($item == '.' || $item == '..') continue; + if(is_file($dir.'/'.$item)){ + if(unlink($dir.'/'.$item)){ + $this->clearFolderSizeCache($dir); + } + }elseif(is_dir($dir.'/'.$item)){ + if (!$this->delTree($dirRelative. "/" . $item)){ + return false; + }; + } + } + if($return=rmdir($dir)){ + $this->clearFolderSizeCache($dir); + } + return $return; + } + + public function find($path){ + $return=System::find($this->datadir.$path); + foreach($return as &$file){ + $file=str_replace($file,$this->datadir,''); + } + return $return; + } + + public function getTree($dir) { + if(substr($dir,-1,1)=='/'){ + $dir=substr($dir,0,-1); + } + $tree=array(); + $tree[]=$dir; + $dirRelative=$dir; + $dir=$this->datadir.$dir; + if (!file_exists($dir)) return true; + foreach (scandir($dir) as $item) { + if ($item == '.' || $item == '..') continue; + if(is_file($dir.'/'.$item)){ + $tree[]=$dirRelative.'/'.$item; + }elseif(is_dir($dir.'/'.$item)){ + if ($subTree=$this->getTree($dirRelative. "/" . $item)){ + $tree=array_merge($tree,$subTree); + } + } + } + return $tree; + } + + public function hash($type,$path,$raw){ + return hash_file($type,$this->datadir.$path,$raw); + } + + public function free_space($path){ + return disk_free_space($this->datadir.$path); + } + + public function search($query){ + return $this->searchInDir($query); + } + public function getLocalFile($path){ + return $this->datadir.$path; + } + + private function searchInDir($query,$dir=''){ + $files=array(); + foreach (scandir($this->datadir.$dir) as $item) { + if ($item == '.' || $item == '..') continue; + if(strstr(strtolower($item),strtolower($query))!==false){ + $files[]=$dir.'/'.$item; + } + if(is_dir($this->datadir.$dir.'/'.$item)){ + $files=array_merge($files,$this->searchInDir($query,$dir.'/'.$item)); + } + } + return $files; + } + + /** + * @brief get the size of folder and it's content + * @param string $path file path + * @return int size of folder and it's content + */ + public function getFolderSize($path){ + $path=str_replace('//','/',$path); + if($this->is_dir($path) and substr($path,-1)!='/'){ + $path.='/'; + } + $query=OC_DB::prepare("SELECT size FROM *PREFIX*foldersize WHERE path=?"); + $size=$query->execute(array($path))->fetchAll(); + if(count($size)>0){// we already the size, just return it + return $size[0]['size']; + }else{//the size of the folder isn't know, calulate it + return $this->calculateFolderSize($path); + } + } + + /** + * @brief calulate the size of folder and it's content and cache it + * @param string $path file path + * @return int size of folder and it's content + */ + public function calculateFolderSize($path){ + if($this->is_file($path)){ + $path=dirname($path); + } + $path=str_replace('//','/',$path); + if($this->is_dir($path) and substr($path,-1)!='/'){ + $path.='/'; + } + $size=0; + if ($dh = $this->opendir($path)) { + while (($filename = readdir($dh)) !== false) { + if($filename!='.' and $filename!='..'){ + $subFile=$path.'/'.$filename; + if($this->is_file($subFile)){ + $size+=$this->filesize($subFile); + }else{ + $size+=$this->getFolderSize($subFile); + } + } + } + if($size>0){ + $query=OC_DB::prepare("INSERT INTO *PREFIX*foldersize VALUES(?,?)"); + $result=$query->execute(array($path,$size)); + } + } + return $size; + } + + /** + * @brief clear the folder size cache of folders containing a file + * @param string $path + */ + public function clearFolderSizeCache($path){ + if($this->is_file($path)){ + $path=dirname($path); + } + $path=str_replace('//','/',$path); + if($this->is_dir($path) and substr($path,-1)!='/'){ + $path.='/'; + } + $query=OC_DB::prepare("DELETE FROM *PREFIX*foldersize WHERE path = ?"); + $result=$query->execute(array($path)); + if($path!='/' and $path!=''){ + $parts=explode('/',$path); + //pop empty part + $part=array_pop($parts); + if(empty($part)){ + array_pop($parts); + } + $parent=implode('/',$parts); + $this->clearFolderSizeCache($parent); + } + } +} diff --git a/lib/remotestorage.php b/lib/filestorage/remote.php index ed90cf1fdaf..fb14c4121a2 100644 --- a/lib/remotestorage.php +++ b/lib/filestorage/remote.php @@ -21,8 +21,7 @@ * */ - -class OC_FILESTORAGE_REMOTE extends OC_FILESTORAGE{ +class OC_Filestorage_Remote extends OC_Filestorage{ private $url; private $username; private $password; @@ -46,7 +45,7 @@ class OC_FILESTORAGE_REMOTE extends OC_FILESTORAGE{ } private function connect(){ if($this->remote===false){ - $this->remote=OC_CONNECT::connect($this->url,$this->username,$this->password); + $this->remote=OC_Connect::connect($this->url,$this->username,$this->password); } } public function mkdir($path){ @@ -349,5 +348,3 @@ class OC_FILESTORAGE_REMOTE extends OC_FILESTORAGE{ } } } - -?> diff --git a/lib/filesystem.php b/lib/filesystem.php index 2c26667bbee..c2153520650 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -24,7 +24,7 @@ /** * Class for abstraction of filesystem functions - * This class won't call any filesystem functions for itself but but will pass them to the correct OC_FILESTORAGE object + * This class won't call any filesystem functions for itself but but will pass them to the correct OC_Filestorage object * this class should also handle all the file premission related stuff * * Hooks provided: @@ -42,7 +42,7 @@ * * the &run parameter can be set to false to prevent the operation from occuring */ -class OC_FILESYSTEM{ +class OC_Filesystem{ static private $storages=array(); static private $fakeRoot=''; static private $storageTypes=array(); @@ -89,7 +89,7 @@ class OC_FILESYSTEM{ * create a new storage of a specific type * @param string type * @param array arguments - * @return OC_FILESTORAGE + * @return OC_Filestorage */ static public function createStorage($type,$arguments){ if(!self::hasStorageType($type)){ @@ -159,8 +159,8 @@ class OC_FILESYSTEM{ } /** - * mount an OC_FILESTORAGE in our virtual filesystem - * @param OC_FILESTORAGE storage + * mount an OC_Filestorage in our virtual filesystem + * @param OC_Filestorage storage * @param string mountpoint */ static public function mount($storage,$mountpoint){ @@ -173,7 +173,7 @@ class OC_FILESYSTEM{ /** * get the storage object for a path * @param string path - * @return OC_FILESTORAGE + * @return OC_Filestorage */ static public function getStorage($path){ $mountpoint=self::getMountPoint($path); @@ -232,14 +232,14 @@ class OC_FILESYSTEM{ $parent=substr($path,0,strrpos($path,'/')); if(self::canWrite($parent) and $storage=self::getStorage($path)){ $run=true; - OC_HOOK::emit( 'OC_FILESYSTEM', 'create', array( 'path' => $path, 'run' => &$run)); + OC_Hook::emit( 'OC_Filesystem', 'create', array( 'path' => $path, 'run' => &$run)); if($run){ - OC_HOOK::emit( 'OC_FILESYSTEM', 'write', array( 'path' => $path, 'run' => &$run)); + OC_Hook::emit( 'OC_Filesystem', 'write', array( 'path' => $path, 'run' => &$run)); } if($run){ $result=$storage->mkdir(self::getInternalPath($path)); - OC_HOOK::emit( 'OC_FILESYSTEM', 'post_create', array( 'path' => $path)); - OC_HOOK::emit( 'OC_FILESYSTEM', 'post_write', array( 'path' => $path)); + OC_Hook::emit( 'OC_Filesystem', 'post_create', array( 'path' => $path)); + OC_Hook::emit( 'OC_Filesystem', 'post_write', array( 'path' => $path)); return $result; } } @@ -247,17 +247,17 @@ class OC_FILESYSTEM{ static public function rmdir($path){ if(self::canWrite($path) and $storage=self::getStorage($path)){ $run=true; - OC_HOOK::emit( 'OC_FILESYSTEM', 'delete', array( 'path' => $path, 'run' => &$run)); + OC_Hook::emit( 'OC_Filesystem', 'delete', array( 'path' => $path, 'run' => &$run)); if($run){ $result=$storage->rmdir(self::getInternalPath($path)); - OC_HOOK::emit( 'OC_FILESYSTEM', 'post_delete', array( 'path' => $path)); + OC_Hook::emit( 'OC_Filesystem', 'post_delete', array( 'path' => $path)); return $result; } } } static public function opendir($path){ if(self::canRead($path) and $storage=self::getStorage($path)){ - OC_HOOK::emit( 'OC_FILESYSTEM', 'read', array( 'path' => $path)); + OC_Hook::emit( 'OC_Filesystem', 'read', array( 'path' => $path)); return $storage->opendir(self::getInternalPath($path)); } } @@ -294,7 +294,7 @@ class OC_FILESYSTEM{ } static public function readfile($path){ if(self::canRead($path) and $storage=self::getStorage($path)){ - OC_HOOK::emit( 'OC_FILESYSTEM', 'read', array( 'path' => $path)); + OC_Hook::emit( 'OC_Filesystem', 'read', array( 'path' => $path)); return $storage->readfile(self::getInternalPath($path)); } } @@ -336,7 +336,7 @@ class OC_FILESYSTEM{ } static public function file_get_contents($path){ if(self::canRead($path) and $storage=self::getStorage($path)){ - OC_HOOK::emit( 'OC_FILESYSTEM', 'read', array( 'path' => $path)); + OC_Hook::emit( 'OC_Filesystem', 'read', array( 'path' => $path)); return $storage->file_get_contents(self::getInternalPath($path)); } } @@ -345,17 +345,17 @@ class OC_FILESYSTEM{ $run=true; $exists=self::file_exists($path); if(!$exists){ - OC_HOOK::emit( 'OC_FILESYSTEM', 'create', array( 'path' => $path, 'run' => &$run)); + OC_Hook::emit( 'OC_Filesystem', 'create', array( 'path' => $path, 'run' => &$run)); } if($run){ - OC_HOOK::emit( 'OC_FILESYSTEM', 'write', array( 'path' => $path, 'run' => &$run)); + OC_Hook::emit( 'OC_Filesystem', 'write', array( 'path' => $path, 'run' => &$run)); } if($run){ $result=$storage->file_put_contents(self::getInternalPath($path),$data); if(!$exists){ - OC_HOOK::emit( 'OC_FILESYSTEM', 'post_create', array( 'path' => $path)); + OC_Hook::emit( 'OC_Filesystem', 'post_create', array( 'path' => $path)); } - OC_HOOK::emit( 'OC_FILESYSTEM', 'post_write', array( 'path' => $path)); + OC_Hook::emit( 'OC_Filesystem', 'post_write', array( 'path' => $path)); return $result; } } @@ -363,10 +363,10 @@ class OC_FILESYSTEM{ static public function unlink($path){ if(self::canWrite($path) and $storage=self::getStorage($path)){ $run=true; - OC_HOOK::emit( 'OC_FILESYSTEM', 'delete', array( 'path' => $path, 'run' => &$run)); + OC_Hook::emit( 'OC_Filesystem', 'delete', array( 'path' => $path, 'run' => &$run)); if($run){ $result=$storage->unlink(self::getInternalPath($path)); - OC_HOOK::emit( 'OC_FILESYSTEM', 'post_delete', array( 'path' => $path)); + OC_Hook::emit( 'OC_Filesystem', 'post_delete', array( 'path' => $path)); return $result; } } @@ -374,7 +374,7 @@ class OC_FILESYSTEM{ static public function rename($path1,$path2){ if(self::canWrite($path1) and self::canWrite($path2)){ $run=true; - OC_HOOK::emit( 'OC_FILESYSTEM', 'rename', array( 'oldpath' => $path1 ,'newpath'=>$path2, 'run' => &$run)); + OC_Hook::emit( 'OC_Filesystem', 'rename', array( 'oldpath' => $path1 ,'newpath'=>$path2, 'run' => &$run)); if($run){ $mp1=self::getMountPoint($path1); $mp2=self::getMountPoint($path2); @@ -387,7 +387,7 @@ class OC_FILESYSTEM{ $result=$storage2->fromTmpFile($tmpFile,self::getInternalPath($path2)); $storage1->unlink(self::getInternalPath($path1)); } - OC_HOOK::emit( 'OC_FILESYSTEM', 'post_rename', array( 'oldpath' => $path1, 'newpath'=>$path2)); + OC_Hook::emit( 'OC_Filesystem', 'post_rename', array( 'oldpath' => $path1, 'newpath'=>$path2)); return $result; } } @@ -395,13 +395,13 @@ class OC_FILESYSTEM{ static public function copy($path1,$path2){ if(self::canRead($path1) and self::canWrite($path2)){ $run=true; - OC_HOOK::emit( 'OC_FILESYSTEM', 'copy', array( 'oldpath' => $path1 ,'newpath'=>$path2, 'run' => &$run)); + OC_Hook::emit( 'OC_Filesystem', 'copy', array( 'oldpath' => $path1 ,'newpath'=>$path2, 'run' => &$run)); $exists=self::file_exists($path2); if($run and !$exists){ - OC_HOOK::emit( 'OC_FILESYSTEM', 'create', array( 'path' => $path2, 'run' => &$run)); + OC_Hook::emit( 'OC_Filesystem', 'create', array( 'path' => $path2, 'run' => &$run)); } if($run){ - OC_HOOK::emit( 'OC_FILESYSTEM', 'write', array( 'path' => $path2, 'run' => &$run)); + OC_Hook::emit( 'OC_Filesystem', 'write', array( 'path' => $path2, 'run' => &$run)); } if($run){ $mp1=self::getMountPoint($path1); @@ -414,11 +414,11 @@ class OC_FILESYSTEM{ $tmpFile=$storage1->toTmpFile(self::getInternalPath($path1)); $result=$storage2->fromTmpFile($tmpFile,self::getInternalPath($path2)); } - OC_HOOK::emit( 'OC_FILESYSTEM', 'post_copy', array( 'oldpath' => $path1 ,'newpath'=>$path2)); + OC_Hook::emit( 'OC_Filesystem', 'post_copy', array( 'oldpath' => $path1 ,'newpath'=>$path2)); if(!$exists){ - OC_HOOK::emit( 'OC_FILESYSTEM', 'post_create', array( 'path' => $path2)); + OC_Hook::emit( 'OC_Filesystem', 'post_create', array( 'path' => $path2)); } - OC_HOOK::emit( 'OC_FILESYSTEM', 'post_write', array( 'path' => $path2)); + OC_Hook::emit( 'OC_Filesystem', 'post_write', array( 'path' => $path2)); return $result; } } @@ -432,13 +432,13 @@ class OC_FILESYSTEM{ $write=false; switch($mode){ case 'r': - OC_HOOK::emit( 'OC_FILESYSTEM', 'read', array( 'path' => $path)); + OC_Hook::emit( 'OC_Filesystem', 'read', array( 'path' => $path)); break; case 'r+': case 'w+': case 'x+': case 'a+': - OC_HOOK::emit( 'OC_FILESYSTEM', 'read', array( 'path' => $path)); + OC_Hook::emit( 'OC_Filesystem', 'read', array( 'path' => $path)); $write=true; break; case 'w': @@ -449,20 +449,20 @@ class OC_FILESYSTEM{ } if($write){ if(!$exists){ - OC_HOOK::emit( 'OC_FILESYSTEM', 'create', array( 'path' => $path)); + OC_Hook::emit( 'OC_Filesystem', 'create', array( 'path' => $path)); } if($run){ - OC_HOOK::emit( 'OC_FILESYSTEM', 'write', array( 'path' => $path, 'run' => &$run)); + OC_Hook::emit( 'OC_Filesystem', 'write', array( 'path' => $path, 'run' => &$run)); } } if($run){ $result=$storage->fopen(self::getInternalPath($path),$mode); if($write){ if(!$exists){ - OC_HOOK::emit( 'OC_FILESYSTEM', 'post_create', array( 'path' => $path)); + OC_Hook::emit( 'OC_Filesystem', 'post_create', array( 'path' => $path)); } if($run){ - OC_HOOK::emit( 'OC_FILESYSTEM', 'post_write', array( 'path' => $path)); + OC_Hook::emit( 'OC_Filesystem', 'post_write', array( 'path' => $path)); } } return $result; @@ -472,7 +472,7 @@ class OC_FILESYSTEM{ } static public function toTmpFile($path){ if(self::canRead($path) and $storage=self::getStorage($path)){ - OC_HOOK::emit( 'OC_FILESYSTEM', 'read', array( 'path' => $path)); + OC_Hook::emit( 'OC_Filesystem', 'read', array( 'path' => $path)); return $storage->toTmpFile(self::getInternalPath($path)); } } @@ -481,17 +481,17 @@ class OC_FILESYSTEM{ $run=true; $exists=self::file_exists($path); if(!$exists){ - OC_HOOK::emit( 'OC_FILESYSTEM', 'create', array( 'path' => $path, 'run' => &$run)); + OC_Hook::emit( 'OC_Filesystem', 'create', array( 'path' => $path, 'run' => &$run)); } if($run){ - OC_HOOK::emit( 'OC_FILESYSTEM', 'write', array( 'path' => $path, 'run' => &$run)); + OC_Hook::emit( 'OC_Filesystem', 'write', array( 'path' => $path, 'run' => &$run)); } if($run){ $result=$storage->fromTmpFile($tmpFile,self::getInternalPath($path)); if(!$exists){ - OC_HOOK::emit( 'OC_FILESYSTEM', 'post_create', array( 'path' => $path)); + OC_Hook::emit( 'OC_Filesystem', 'post_create', array( 'path' => $path)); } - OC_HOOK::emit( 'OC_FILESYSTEM', 'post_write', array( 'path' => $path)); + OC_Hook::emit( 'OC_Filesystem', 'post_write', array( 'path' => $path)); return $result; } } @@ -502,18 +502,18 @@ class OC_FILESYSTEM{ $run=true; $exists=self::file_exists($path); if(!$exists){ - OC_HOOK::emit( 'OC_FILESYSTEM', 'create', array( 'path' => $path, 'run' => &$run)); + OC_Hook::emit( 'OC_Filesystem', 'create', array( 'path' => $path, 'run' => &$run)); } if($run){ - OC_HOOK::emit( 'OC_FILESYSTEM', 'write', array( 'path' => $path, 'run' => &$run)); + OC_Hook::emit( 'OC_Filesystem', 'write', array( 'path' => $path, 'run' => &$run)); } error_log('upload2'); if($run){ $result=$storage->fromUploadedFile($tmpFile,self::getInternalPath($path)); if(!$exists){ - OC_HOOK::emit( 'OC_FILESYSTEM', 'post_create', array( 'path' => $path)); + OC_Hook::emit( 'OC_Filesystem', 'post_create', array( 'path' => $path)); } - OC_HOOK::emit( 'OC_FILESYSTEM', 'post_write', array( 'path' => $path)); + OC_Hook::emit( 'OC_Filesystem', 'post_write', array( 'path' => $path)); return $result; } } @@ -526,7 +526,7 @@ class OC_FILESYSTEM{ static public function delTree($path){ if(self::canWrite($path) and $storage=self::getStorage($path)){ $run=true; - OC_HOOK::emit( 'OC_FILESYSTEM', 'delete', array( 'path' => $path, 'run' => &$run)); + OC_Hook::emit( 'OC_Filesystem', 'delete', array( 'path' => $path, 'run' => &$run)); if($run){ return $storage->delTree(self::getInternalPath($path)); } @@ -561,7 +561,7 @@ class OC_FILESYSTEM{ } static public function hash($type,$path,$raw=false){ if(self::canRead($path) and $storage=self::getStorage($path)){ - OC_HOOK::emit( 'OC_FILESYSTEM', 'read', array( 'path' => $path)); + OC_Hook::emit( 'OC_Filesystem', 'read', array( 'path' => $path)); return $storage->hash($type,self::getInternalPath($path),$raw); } } @@ -589,4 +589,3 @@ class OC_FILESYSTEM{ } } -?> diff --git a/lib/group.php b/lib/group.php index 6510838ccfc..1161b9035fa 100644 --- a/lib/group.php +++ b/lib/group.php @@ -33,7 +33,7 @@ * pre_removeFromGroup(&run, uid, gid) * post_removeFromGroup(uid, gid) */ -class OC_GROUP { +class OC_Group { // The backend used for user management private static $_backend; @@ -78,8 +78,7 @@ class OC_GROUP { case 'database': case 'mysql': case 'sqlite': - require_once('Group/database.php'); - self::$_backend = new OC_GROUP_DATABASE(); + self::$_backend = new OC_Group_Database(); break; default: $className = 'OC_GROUP_' . strToUpper($backend); @@ -114,10 +113,10 @@ class OC_GROUP { } $run = true; - OC_HOOK::emit( "OC_GROUP", "pre_createGroup", array( "run" => &$run, "gid" => $gid )); + OC_Hook::emit( "OC_Group", "pre_createGroup", array( "run" => &$run, "gid" => $gid )); if( $run && self::$_backend->createGroup( $gid )){ - OC_HOOK::emit( "OC_GROUP", "post_createGroup", array( "gid" => $gid )); + OC_Hook::emit( "OC_Group", "post_createGroup", array( "gid" => $gid )); return true; } else{ @@ -139,10 +138,10 @@ class OC_GROUP { } $run = true; - OC_HOOK::emit( "OC_GROUP", "pre_deleteGroup", array( "run" => &$run, "gid" => $gid )); + OC_Hook::emit( "OC_Group", "pre_deleteGroup", array( "run" => &$run, "gid" => $gid )); if( $run && self::$_backend->deleteGroup( $gid )){ - OC_HOOK::emit( "OC_GROUP", "post_deleteGroup", array( "gid" => $gid )); + OC_Hook::emit( "OC_Group", "post_deleteGroup", array( "gid" => $gid )); return true; } else{ @@ -172,7 +171,7 @@ class OC_GROUP { */ public static function addToGroup( $uid, $gid ){ // Does the user exist? - if( !in_array( $uid, OC_USER::getUsers())){ + if( !in_array( $uid, OC_User::getUsers())){ return false; } // Does the group exist? @@ -182,10 +181,10 @@ class OC_GROUP { // Go go go $run = true; - OC_HOOK::emit( "OC_GROUP", "pre_addToGroup", array( "run" => &$run, "uid" => $uid, "gid" => $gid )); + OC_Hook::emit( "OC_Group", "pre_addToGroup", array( "run" => &$run, "uid" => $uid, "gid" => $gid )); if( $run && self::$_backend->addToGroup( $uid, $gid )){ - OC_HOOK::emit( "OC_GROUP", "post_addToGroup", array( "uid" => $uid, "gid" => $gid )); + OC_Hook::emit( "OC_Group", "post_addToGroup", array( "uid" => $uid, "gid" => $gid )); return true; } else{ @@ -203,10 +202,10 @@ class OC_GROUP { */ public static function removeFromGroup( $uid, $gid ){ $run = true; - OC_HOOK::emit( "OC_GROUP", "pre_removeFromGroup", array( "run" => &$run, "uid" => $uid, "gid" => $gid )); + OC_Hook::emit( "OC_Group", "pre_removeFromGroup", array( "run" => &$run, "uid" => $uid, "gid" => $gid )); if( $run && self::$_backend->removeFromGroup( $uid, $gid )){ - OC_HOOK::emit( "OC_GROUP", "post_removeFromGroup", array( "uid" => $uid, "gid" => $gid )); + OC_Hook::emit( "OC_Group", "post_removeFromGroup", array( "uid" => $uid, "gid" => $gid )); return true; } else{ diff --git a/lib/Group/backend.php b/lib/group/backend.php index 298cced7ff5..ebee8aacb91 100644 --- a/lib/Group/backend.php +++ b/lib/group/backend.php @@ -26,7 +26,7 @@ /** * Abstract base class for user management */ -abstract class OC_GROUP_BACKEND { +abstract class OC_Group_Backend { /** * @brief Try to create a new group * @param $gid The name of the group to create diff --git a/lib/Group/database.php b/lib/group/database.php index 6e508a4d47c..6ca80b93985 100644 --- a/lib/Group/database.php +++ b/lib/group/database.php @@ -37,12 +37,10 @@ * */ -require_once( 'Group/backend.php' ); - /** * Class for group management in a SQL Database (e.g. MySQL, SQLite) */ -class OC_GROUP_DATABASE extends OC_GROUP_BACKEND { +class OC_Group_Database extends OC_Group_Backend { static private $userGroupCache=array(); /** diff --git a/lib/helper.php b/lib/helper.php index ffb25877433..5dc3dd44a15 100755 --- a/lib/helper.php +++ b/lib/helper.php @@ -24,7 +24,7 @@ /** * Collection of useful functions */ -class OC_HELPER { +class OC_Helper { /** * @brief Creates an url * @param $app app @@ -318,5 +318,3 @@ class OC_HELPER { return false; } } - -?> diff --git a/lib/hook.php b/lib/hook.php new file mode 100644 index 00000000000..b069a7da6c0 --- /dev/null +++ b/lib/hook.php @@ -0,0 +1,69 @@ +<?php + +/** + * This class manages the hooks. It basically provides two functions: adding + * slots and emitting signals. + */ +class OC_Hook{ + static private $registered = array(); + + /** + * @brief connects a function to a hook + * @param $signalclass class name of emitter + * @param $signalname name of signal + * @param $slotclass class name of slot + * @param $slotname name of slot + * @returns true/false + * + * This function makes it very easy to connect to use hooks. + * + * TODO: write example + */ + static public function connect( $signalclass, $signalname, $slotclass, $slotname ){ + // Cerate the data structure + if( !array_key_exists( $signalclass, self::$registered )){ + self::$registered[$signalclass] = array(); + } + if( !array_key_exists( $signalname, self::$registered[$signalclass] )){ + self::$registered[$signalclass][$signalname] = array(); + } + + // register hook + self::$registered[$signalclass][$signalname][] = array( + "class" => $slotclass, + "name" => $slotname ); + + // No chance for failure ;-) + return true; + } + + /** + * @brief emitts a signal + * @param $signalclass class name of emitter + * @param $signalname name of signal + * @param $params defautl: array() array with additional data + * @returns true if slots exists or false if not + * + * Emits a signal. To get data from the slot use references! + * + * TODO: write example + */ + static public function emit( $signalclass, $signalname, $params = array()){ + // Return false if there are no slots + if( !array_key_exists( $signalclass, self::$registered )){ + return false; + } + if( !array_key_exists( $signalname, self::$registered[$signalclass] )){ + return false; + } + + // Call all slots + foreach( self::$registered[$signalclass][$signalname] as $i ){ + call_user_func( array( $i["class"], $i["name"] ), $params ); + } + + // return true + return true; + } +} + diff --git a/lib/installer.php b/lib/installer.php index a237caa0983..e25f9d9c4ce 100644 --- a/lib/installer.php +++ b/lib/installer.php @@ -23,7 +23,7 @@ /** * This class provides the functionality needed to install, update and remove plugins/apps */ -class OC_INSTALLER{ +class OC_Installer{ /** * @brief Installs an app * @param $data array with all information @@ -88,7 +88,7 @@ class OC_INSTALLER{ $zip->close(); } else { error_log("Failed to open archive when installing app"); - OC_HELPER::rmdirr($extractDir); + OC_Helper::rmdirr($extractDir); if($data['source']=='http'){ unlink($path); } @@ -98,19 +98,19 @@ class OC_INSTALLER{ //load the info.xml file of the app if(!is_file($extractDir.'/appinfo/info.xml')){ error_log("App does not provide an info.xml file"); - OC_HELPER::rmdirr($extractDir); + OC_Helper::rmdirr($extractDir); if($data['source']=='http'){ unlink($path); } return false; } - $info=OC_APP::getAppInfo($extractDir.'/appinfo/info.xml'); + $info=OC_App::getAppInfo($extractDir.'/appinfo/info.xml'); $basedir=$SERVERROOT.'/apps/'.$info['id']; //check if an app with the same id is already installed if(self::isInstalled( $info['id'] )){ error_log("App already installed"); - OC_HELPER::rmdirr($extractDir); + OC_Helper::rmdirr($extractDir); if($data['source']=='http'){ unlink($path); } @@ -120,7 +120,7 @@ class OC_INSTALLER{ //check if the destination directory already exists if(is_dir($basedir)){ error_log("App's directory already exists"); - OC_HELPER::rmdirr($extractDir); + OC_Helper::rmdirr($extractDir); if($data['source']=='http'){ unlink($path); } @@ -134,16 +134,16 @@ class OC_INSTALLER{ //copy the app to the correct place if(!mkdir($basedir)){ error_log('Can\'t create app folder ('.$basedir.')'); - OC_HELPER::rmdirr($extractDir); + OC_Helper::rmdirr($extractDir); if($data['source']=='http'){ unlink($path); } return false; } - OC_HELPER::copyr($extractDir,$basedir); + OC_Helper::copyr($extractDir,$basedir); //remove temporary files - OC_HELPER::rmdirr($extractDir); + OC_Helper::rmdirr($extractDir); if($data['source']=='http'){ unlink($path); } @@ -159,8 +159,8 @@ class OC_INSTALLER{ } //set the installed version - OC_APPCONFIG::setValue($info['id'],'installed_version',$info['version']); - OC_APPCONFIG::setValue($info['id'],'enabled','no'); + OC_Appconfig::setValue($info['id'],'installed_version',$info['version']); + OC_Appconfig::setValue($info['id'],'enabled','no'); return true; } @@ -173,7 +173,7 @@ class OC_INSTALLER{ */ public static function isInstalled( $app ){ - if( null == OC_APPCONFIG::getValue( $app, "installed_version" )){ + if( null == OC_Appconfig::getValue( $app, "installed_version" )){ return false; } @@ -205,7 +205,7 @@ class OC_INSTALLER{ * -# including appinfo/upgrade.php * -# setting the installed version * - * upgrade.php can determine the current installed version of the app using "OC_APPCONFIG::getValue($appid,'installed_version')" + * upgrade.php can determine the current installed version of the app using "OC_Appconfig::getValue($appid,'installed_version')" */ public static function upgradeApp( $data = array()){ // TODO: write function @@ -251,7 +251,7 @@ class OC_INSTALLER{ while( false !== ( $filename = readdir( $dir ))){ if( substr( $filename, 0, 1 ) != '.' and is_dir("$SERVERROOT/apps/$filename") ){ if( file_exists( "$SERVERROOT/apps/$filename/appinfo/app.php" )){ - if(!OC_INSTALLER::isInstalled($filename)){ + if(!OC_Installer::isInstalled($filename)){ //install the database if(is_file("$SERVERROOT/apps/$filename/appinfo/database.xml")){ OC_DB::createDbFromStructure("$SERVERROOT/apps/$filename/appinfo/database.xml"); @@ -261,12 +261,12 @@ class OC_INSTALLER{ if(is_file("$SERVERROOT/apps/$filename/appinfo/install.php")){ include("$SERVERROOT/apps/$filename/appinfo/install.php"); } - $info=OC_APP::getAppInfo("$SERVERROOT/apps/$filename/appinfo/info.xml"); - OC_APPCONFIG::setValue($filename,'installed_version',$info['version']); + $info=OC_App::getAppInfo("$SERVERROOT/apps/$filename/appinfo/info.xml"); + OC_Appconfig::setValue($filename,'installed_version',$info['version']); if( $enabled ){ - OC_APPCONFIG::setValue($filename,'enabled','yes'); + OC_Appconfig::setValue($filename,'enabled','yes'); }else{ - OC_APPCONFIG::setValue($filename,'enabled','no'); + OC_Appconfig::setValue($filename,'enabled','no'); } } } diff --git a/lib/l10n.php b/lib/l10n.php index 053c6fbc10e..4e65af66c4f 100644 --- a/lib/l10n.php +++ b/lib/l10n.php @@ -200,8 +200,8 @@ class OC_L10N{ else{ $available=self::findAvailableLanguages( $app ); } - if( OC_USER::getUser() && OC_PREFERENCES::getValue( OC_USER::getUser(), 'core', 'lang' )){ - $lang = OC_PREFERENCES::getValue( OC_USER::getUser(), 'core', 'lang' ); + if( OC_User::getUser() && OC_Preferences::getValue( OC_User::getUser(), 'core', 'lang' )){ + $lang = OC_Preferences::getValue( OC_User::getUser(), 'core', 'lang' ); self::$language = $lang; if( array_search( $lang, $available ) !== false ){ return $lang; diff --git a/lib/log.php b/lib/log.php index 764c094c919..d51b2ef0785 100644 --- a/lib/log.php +++ b/lib/log.php @@ -39,7 +39,7 @@ /** * This class is for logging */ -class OC_LOG { +class OC_Log { /** * @brief adds an entry to the log * @param $appid id of the app @@ -101,7 +101,7 @@ class OC_LOG { $result=$query->execute($params)->fetchAll(); if(count($result)>0 and is_numeric($result[0]['moment'])){ foreach($result as &$row){ - $row['moment']=OC_UTIL::formatDate($row['moment']); + $row['moment']=OC_Util::formatDate($row['moment']); } } return $result; @@ -149,7 +149,3 @@ class OC_LOG { return $filteredLogs; } } - - - -?> diff --git a/lib/mimetypes.list.php b/lib/mimetypes.list.php index 6d8b3b9abce..24679257199 100644 --- a/lib/mimetypes.list.php +++ b/lib/mimetypes.list.php @@ -78,4 +78,3 @@ return array( 'webm'=>'video/webm', 'wmv'=>'video/x-ms-asf' ); -?>
\ No newline at end of file diff --git a/lib/ocs.php b/lib/ocs.php index b1be2cb11cf..8c7556a173b 100644 --- a/lib/ocs.php +++ b/lib/ocs.php @@ -207,7 +207,7 @@ class OC_OCS { $identifieduser=''; } }else{ - if(!OC_USER::login($authuser,$authpw)){ + if(!OC_User::login($authuser,$authpw)){ if($forceuser){ header('WWW-Authenticate: Basic realm="your valid user account or api key"'); header('HTTP/1.0 401 Unauthorized'); @@ -377,7 +377,7 @@ class OC_OCS { */ private static function personCheck($format,$login,$passwd) { if($login<>''){ - if(OC_USER::login($login,$passwd)){ + if(OC_User::login($login,$passwd)){ $xml['person']['personid']=$login; echo(OC_OCS::generatexml($format,'ok',100,'',$xml,'person','check',2)); }else{ @@ -426,7 +426,7 @@ class OC_OCS { $xml[$i]['timestamp']=date('c',$log['timestamp']); $xml[$i]['type']=1; - $xml[$i]['message']=OC_LOG::$TYPE[$log['type']].' '.strip_tags($log['message']); + $xml[$i]['message']=OC_Log::$TYPE[$log['type']].' '.strip_tags($log['message']); $xml[$i]['link']=$url; } @@ -514,19 +514,19 @@ class OC_OCS { if($app){ $apps=array($app); }else{ - $apps=OC_PREFERENCES::getApps($user); + $apps=OC_Preferences::getApps($user); } if($key){ $keys=array($key); }else{ foreach($apps as $app){ - $keys=OC_PREFERENCES::getKeys($user,$app); + $keys=OC_Preferences::getKeys($user,$app); } } $result=array(); foreach($apps as $app){ foreach($keys as $key){ - $value=OC_PREFERENCES::getValue($user,$app,$key); + $value=OC_Preferences::getValue($user,$app,$key); $result[]=array('app'=>$app,'key'=>$key,'value'=>$value); } } @@ -542,7 +542,7 @@ class OC_OCS { * @return bool */ public static function setData($user, $app, $key, $value) { - return OC_PREFERENCES::setValue($user,$app,$key,$value); + return OC_Preferences::setValue($user,$app,$key,$value); } /** @@ -553,8 +553,6 @@ class OC_OCS { * @return string xml/json */ public static function deleteData($user, $app, $key) { - return OC_PREFERENCES::deleteKey($user,$app,$key); + return OC_Preferences::deleteKey($user,$app,$key); } } - -?> diff --git a/lib/ocsclient.php b/lib/ocsclient.php index cfd529b2ec4..2d85e715090 100644 --- a/lib/ocsclient.php +++ b/lib/ocsclient.php @@ -26,7 +26,7 @@ * database. */ -class OC_OCSCLIENT{ +class OC_OCSClient{ /** * @brief Get all the categories from the OCS server @@ -160,4 +160,3 @@ class OC_OCSCLIENT{ } -?> diff --git a/lib/preferences.php b/lib/preferences.php index 0f4636f6832..d53cdd538e0 100644 --- a/lib/preferences.php +++ b/lib/preferences.php @@ -37,7 +37,7 @@ /** * This class provides an easy way for storing user preferences. */ -class OC_PREFERENCES{ +class OC_Preferences{ /** * @brief Get all users using the preferences * @returns array with user ids @@ -217,4 +217,3 @@ class OC_PREFERENCES{ return true; } } -?> diff --git a/lib/remote/cloud.php b/lib/remote/cloud.php new file mode 100644 index 00000000000..2d3dee47b1c --- /dev/null +++ b/lib/remote/cloud.php @@ -0,0 +1,206 @@ +<?php +/** + * Class for connection to a remote owncloud installation + * + */ +class OC_REMOTE_CLOUD{ + private $path; + private $connected=false; + private $cookiefile=false; + + /** + * make an api call to the remote cloud + * @param string $action + * @param array parameters + * @param bool assoc when set to true, the result will be parsed as associative array + * + */ + private function apiCall($action,$parameters=false,$assoc=false){ + if(!$this->cookiefile){ + $this->cookiefile=sys_get_temp_dir().'/remoteCloudCookie'.uniqid(); + } + $url=$this->path.='/files/api.php'; + $fields_string="action=$action&"; + if(is_array($parameters)){ + foreach($parameters as $key=>$value){ + $fields_string.=$key.'='.$value.'&'; + } + rtrim($fields_string,'&'); + } + $ch=curl_init(); + curl_setopt($ch,CURLOPT_URL,$url); + curl_setopt($ch,CURLOPT_POST,count($parameters)); + curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); + curl_setopt($ch, CURLOPT_COOKIEFILE,$this->cookiefile); + curl_setopt($ch, CURLOPT_COOKIEJAR,$this->cookiefile); + curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); + $result=curl_exec($ch); + $result=trim($result); + $info=curl_getinfo($ch); + $httpCode=$info['http_code']; + curl_close($ch); + if($httpCode==200 or $httpCode==0){ + return json_decode($result,$assoc); + }else{ + return false; + } + } + + public function __construct($path,$user,$password){ + $this->path=$path; + $this->connected=$this->apiCall('login',array('username'=>$user,'password'=>$password)); + } + + /** + * check if we are stull logged in on the remote cloud + * + */ + public function isLoggedIn(){ + if(!$this->connected){ + return false; + } + return $this->apiCall('checklogin'); + } + + public function __get($name){ + switch($name){ + case 'connected': + return $this->connected; + } + } + + /** + * disconnect from the remote cloud + * + */ + public function disconnect(){ + $this->connected=false; + if(is_file($this->cookiefile)){ + unlink($this->cookiefile); + } + $this->cookiefile=false; + } + + /** + * create a new file or directory + * @param string $dir + * @param string $name + * @param string $type + */ + public function newFile($dir,$name,$type){ + if(!$this->connected){ + return false; + } + return $this->apiCall('new',array('dir'=>$dir,'name'=>$name,'type'=>$type),true); + } + + /** + * deletes a file or directory + * @param string $dir + * @param string $file + */ + public function delete($dir,$name){ + if(!$this->connected){ + return false; + } + return $this->apiCall('delete',array('dir'=>$dir,'file'=>$name),true); + } + + /** + * moves a file or directory + * @param string $sorceDir + * @param string $sorceFile + * @param string $targetDir + * @param string $targetFile + */ + public function move($sourceDir,$sourceFile,$targetDir,$targetFile){ + if(!$this->connected){ + return false; + } + return $this->apiCall('move',array('sourcedir'=>$sourceDir,'source'=>$sourceFile,'targetdir'=>$targetDir,'target'=>$targetFile),true); + } + + /** + * copies a file or directory + * @param string $sorceDir + * @param string $sorceFile + * @param string $targetDir + * @param string $targetFile + */ + public function copy($sourceDir,$sourceFile,$targetDir,$targetFile){ + if(!$this->connected){ + return false; + } + return $this->apiCall('copy',array('sourcedir'=>$sourceDir,'source'=>$sourceFile,'targetdir'=>$targetDir,'target'=>$targetFile),true); + } + + /** + * get a file tree + * @param string $dir + */ + public function getTree($dir){ + if(!$this->connected){ + return false; + } + return $this->apiCall('gettree',array('dir'=>$dir),true); + } + + /** + * get the files inside a directory of the remote cloud + * @param string $dir + */ + public function getFiles($dir){ + if(!$this->connected){ + return false; + } + return $this->apiCall('getfiles',array('dir'=>$dir),true); + } + + /** + * get a remove file and save it in a temporary file and return the path of the temporary file + * @param string $dir + * @param string $file + * @return string + */ + public function getFile($dir, $file){ + if(!$this->connected){ + return false; + } + $ch=curl_init(); + if(!$this->cookiefile){ + $this->cookiefile=sys_get_temp_dir().'/remoteCloudCookie'.uniqid(); + } + $tmpfile=tempnam(sys_get_temp_dir(),'remoteCloudFile'); + $fp=fopen($tmpfile,'w+'); + $url=$this->path.="/files/api.php?action=get&dir=$dir&file=$file"; + curl_setopt($ch,CURLOPT_URL,$url); + curl_setopt($ch, CURLOPT_COOKIEFILE,$this->cookiefile); + curl_setopt($ch, CURLOPT_COOKIEJAR,$this->cookiefile); + curl_setopt($ch, CURLOPT_FILE, $fp); + curl_exec($ch); + fclose($fp); + curl_close($ch); + return $tmpfile; + } + + public function sendFile($sourceDir,$sourceFile,$targetDir,$targetFile){ + global $WEBROOT; + $source=$sourceDir.'/'.$sourceFile; + $tmp=OC_Filesystem::toTmpFile($source); + return $this->sendTmpFile($tmp,$targetDir,$targetFile); + } + + public function sendTmpFile($tmp,$targetDir,$targetFile){ + $token=sha1(uniqid().$tmp); + global $WEBROOT; + $file=sys_get_temp_dir().'/'.'remoteCloudFile'.$token; + rename($tmp,$file); + if( OC_Config::getValue( "forcessl", false ) or isset($_SERVER['HTTPS']) and $_SERVER['HTTPS'] == 'on') { + $url = "https://". $_SERVER['SERVER_NAME'] . $WEBROOT; + }else{ + $url = "http://". $_SERVER['SERVER_NAME'] . $WEBROOT; + } + return $this->apiCall('pull',array('dir'=>$targetDir,'file'=>$targetFile,'token'=>$token,'source'=>$url),true); + } +} +
\ No newline at end of file diff --git a/lib/search.php b/lib/search.php index ef82e225f3d..f6f805bfe65 100644 --- a/lib/search.php +++ b/lib/search.php @@ -24,12 +24,12 @@ /** * provides an interface to all search providers */ -class OC_SEARCH{ +class OC_Search{ static private $providers=array(); /** * register a new search provider to be used - * @param OC_SearchProvider $provider + * @param OC_Search_Provider $provider */ public static function registerProvider($provider){ self::$providers[]=$provider; @@ -38,7 +38,7 @@ class OC_SEARCH{ /** * search all provider for $query * @param string query - * @return array An array of OC_SearchResult's + * @return array An array of OC_Search_Result's */ public static function search($query){ $results=array(); @@ -48,74 +48,3 @@ class OC_SEARCH{ return $results; } } - -/** - * provides search functionalty - */ -abstract class OC_SearchProvider{ - public function __construct(){ - OC_SEARCH::registerProvider($this); - } - - /** - * search for $query - * @param string $query - * @return array An array of OC_SearchResult's - */ - abstract function search($query); -} - -/** - * a result of a search - */ -class OC_SearchResult{ - private $name; - private $text; - private $link; - private $type; - - /** - * create a new search result - * @param string $name short name for the result - * @param string $text some more information about the result - * @param string $link link for the result - * @param string $type the type of result as human readable string ('File', 'Music', etc) - */ - public function __construct($name,$text,$link,$type){ - $this->name=$name; - $this->text=$text; - $this->link=$link; - $this->type=$type; - } - - public function __get($name){ - switch($name){ - case 'name': - return $this->name; - case 'text': - return $this->text; - case 'link': - return $this->link; - case 'type': - return $this->type; - } - } -} - -class OC_FileSearchProvider extends OC_SearchProvider{ - function search($query){ - $files=OC_FILESYSTEM::search($query); - $results=array(); - foreach($files as $file){ - if(OC_FILESYSTEM::is_dir($file)){ - $results[]=new OC_SearchResult(basename($file),$file,OC_HELPER::linkTo( 'files', 'index.php?dir='.$file ),'Files'); - }else{ - $results[]=new OC_SearchResult(basename($file),$file,OC_HELPER::linkTo( 'files', 'download.php?file='.$file ),'Files'); - } - } - return $results; - } -} - -new OC_FileSearchProvider(); -?>
\ No newline at end of file diff --git a/lib/search/provider.php b/lib/search/provider.php new file mode 100644 index 00000000000..cceed8b04a3 --- /dev/null +++ b/lib/search/provider.php @@ -0,0 +1,16 @@ +<?php +/** + * provides search functionalty + */ +abstract class OC_Search_Provider{ + public function __construct(){ + OC_Search::registerProvider($this); + } + + /** + * search for $query + * @param string $query + * @return array An array of OC_Search_Result's + */ + abstract function search($query); +} diff --git a/lib/search/provider/file.php b/lib/search/provider/file.php new file mode 100644 index 00000000000..e257b82a694 --- /dev/null +++ b/lib/search/provider/file.php @@ -0,0 +1,16 @@ +<?php + +class OC_Search_Provider_File extends OC_Search_Provider{ + function search($query){ + $files=OC_Filesystem::search($query); + $results=array(); + foreach($files as $file){ + if(OC_Filesystem::is_dir($file)){ + $results[]=new OC_Search_Result(basename($file),$file,OC_Helper::linkTo( 'files', 'index.php?dir='.$file ),'Files'); + }else{ + $results[]=new OC_Search_Result(basename($file),$file,OC_Helper::linkTo( 'files', 'download.php?file='.$file ),'Files'); + } + } + return $results; + } +} diff --git a/lib/search/result.php b/lib/search/result.php new file mode 100644 index 00000000000..cd78a5cf253 --- /dev/null +++ b/lib/search/result.php @@ -0,0 +1,24 @@ +<?php +/** + * a result of a search + */ +class OC_Search_Result{ + public $name; + public $text; + public $link; + public $type; + + /** + * create a new search result + * @param string $name short name for the result + * @param string $text some more information about the result + * @param string $link link for the result + * @param string $type the type of result as human readable string ('File', 'Music', etc) + */ + public function __construct($name,$text,$link,$type){ + $this->name=$name; + $this->text=$text; + $this->link=$link; + $this->type=$type; + } +} diff --git a/lib/setup.php b/lib/setup.php index f9bc6fd1bdd..41cfa1750ab 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -1,10 +1,8 @@ <?php -include_once( 'installer.php' ); - $hasSQLite = (is_callable('sqlite_open') or class_exists('SQLite3')); $hasMySQL = is_callable('mysql_connect'); -$datadir = OC_CONFIG::getValue('datadir', $SERVERROOT.'/data'); +$datadir = OC_Config::getValue('datadir', $SERVERROOT.'/data'); $opts = array( 'hasSQLite' => $hasSQLite, 'hasMySQL' => $hasMySQL, @@ -14,13 +12,13 @@ $opts = array( if(isset($_POST['install']) AND $_POST['install']=='true') { // We have to launch the installation process : - $e = OC_SETUP::install($_POST); + $e = OC_Setup::install($_POST); $errors = array('errors' => $e); if(count($e) > 0) { - //OC_TEMPLATE::printGuestPage("", "error", array("errors" => $errors)); + //OC_Template::printGuestPage("", "error", array("errors" => $errors)); $options = array_merge($_POST, $opts, $errors); - OC_TEMPLATE::printGuestPage("", "installation", $options); + OC_Template::printGuestPage("", "installation", $options); } else { header("Location: ".$WEBROOT.'/'); @@ -28,10 +26,10 @@ if(isset($_POST['install']) AND $_POST['install']=='true') { } } else { - OC_TEMPLATE::printGuestPage("", "installation", $opts); + OC_Template::printGuestPage("", "installation", $opts); } -class OC_SETUP { +class OC_Setup { public static function install($options) { $error = array(); $dbtype = $options['dbtype']; @@ -74,18 +72,18 @@ class OC_SETUP { } //write the config file - OC_CONFIG::setValue('datadirectory', $datadir); - OC_CONFIG::setValue('dbtype', $dbtype); - OC_CONFIG::setValue('version',implode('.',OC_UTIL::getVersion())); + OC_Config::setValue('datadirectory', $datadir); + OC_Config::setValue('dbtype', $dbtype); + OC_Config::setValue('version',implode('.',OC_Util::getVersion())); if($dbtype == 'mysql') { $dbuser = $options['dbuser']; $dbpass = $options['dbpass']; $dbname = $options['dbname']; $dbhost = $options['dbhost']; $dbtableprefix = $options['dbtableprefix']; - OC_CONFIG::setValue('dbname', $dbname); - OC_CONFIG::setValue('dbhost', $dbhost); - OC_CONFIG::setValue('dbtableprefix', $dbtableprefix); + OC_Config::setValue('dbname', $dbname); + OC_Config::setValue('dbhost', $dbhost); + OC_Config::setValue('dbtableprefix', $dbtableprefix); //check if the database user has admin right $connection = @mysql_connect($dbhost, $dbuser, $dbpass); @@ -107,15 +105,15 @@ class OC_SETUP { self::createDBUser($dbusername, $dbpassword, $connection); - OC_CONFIG::setValue('dbuser', $dbusername); - OC_CONFIG::setValue('dbpassword', $dbpassword); + OC_Config::setValue('dbuser', $dbusername); + OC_Config::setValue('dbpassword', $dbpassword); //create the database self::createDatabase($dbname, $dbusername, $connection); } else { - OC_CONFIG::setValue('dbuser', $dbuser); - OC_CONFIG::setValue('dbpassword', $dbpass); + OC_Config::setValue('dbuser', $dbuser); + OC_Config::setValue('dbpassword', $dbpass); //create the database self::createDatabase($dbname, $dbuser, $connection); @@ -141,18 +139,18 @@ class OC_SETUP { if(count($error) == 0) { //create the user and group - OC_USER::createUser($username, $password); - OC_GROUP::createGroup('admin'); - OC_GROUP::addToGroup($username, 'admin'); + OC_User::createUser($username, $password); + OC_Group::createGroup('admin'); + OC_Group::addToGroup($username, 'admin'); //guess what this does - OC_INSTALLER::installShippedApps(true); + OC_Installer::installShippedApps(true); //create htaccess files for apache hosts self::createHtaccess(); //TODO detect if apache is used //and we are done - OC_CONFIG::setValue('installed', true); + OC_Config::setValue('installed', true); } } @@ -195,7 +193,7 @@ class OC_SETUP { @file_put_contents($SERVERROOT.'/.htaccess', $content); //supress errors in case we don't have permissions for it $content = "deny from all"; - file_put_contents(OC_CONFIG::getValue('datadirectory', $SERVERROOT.'/data').'/.htaccess', $content); + file_put_contents(OC_Config::getValue('datadirectory', $SERVERROOT.'/data').'/.htaccess', $content); } } diff --git a/lib/template.php b/lib/template.php index 99099d49d0f..fe173f609b2 100644 --- a/lib/template.php +++ b/lib/template.php @@ -22,49 +22,49 @@ */ /** - * @brief make OC_HELPER::linkTo available as a simple function + * @brief make OC_Helper::linkTo available as a simple function * @param $app app * @param $file file * @returns link to the file * - * For further information have a look at OC_HELPER::linkTo + * For further information have a look at OC_Helper::linkTo */ function link_to( $app, $file ){ - return OC_HELPER::linkTo( $app, $file ); + return OC_Helper::linkTo( $app, $file ); } /** - * @brief make OC_HELPER::imagePath available as a simple function + * @brief make OC_Helper::imagePath available as a simple function * @param $app app * @param $image image * @returns link to the image * - * For further information have a look at OC_HELPER::imagePath + * For further information have a look at OC_Helper::imagePath */ function image_path( $app, $image ){ - return OC_HELPER::imagePath( $app, $image ); + return OC_Helper::imagePath( $app, $image ); } /** - * @brief make OC_HELPER::mimetypeIcon available as a simple function + * @brief make OC_Helper::mimetypeIcon available as a simple function * @param $mimetype mimetype * @returns link to the image * - * For further information have a look at OC_HELPER::mimetypeIcon + * For further information have a look at OC_Helper::mimetypeIcon */ function mimetype_icon( $mimetype ){ - return OC_HELPER::mimetypeIcon( $mimetype ); + return OC_Helper::mimetypeIcon( $mimetype ); } /** - * @brief make OC_HELPER::humanFileSize available as a simple function + * @brief make OC_Helper::humanFileSize available as a simple function * @param $bytes size in bytes * @returns size as string * - * For further information have a look at OC_HELPER::humanFileSize + * For further information have a look at OC_Helper::humanFileSize */ function human_file_size( $bytes ){ - return OC_HELPER::humanFileSize( $bytes ); + return OC_Helper::humanFileSize( $bytes ); } function simple_file_size($bytes) { @@ -101,7 +101,7 @@ function relative_modified_date($timestamp) { /** * This class provides the templates for owncloud. */ -class OC_TEMPLATE{ +class OC_Template{ private $renderas; // Create a full page? private $application; // template Application private $vars; // Vars @@ -114,11 +114,11 @@ class OC_TEMPLATE{ * @param $app app providing the template * @param $file name of the tempalte file (without suffix) * @param $renderas = ""; produce a full page - * @returns OC_TEMPLATE object + * @returns OC_Template object * - * This function creates an OC_TEMPLATE object. + * This function creates an OC_Template object. * - * If $renderas is set, OC_TEMPLATE will try to produce a full page in the + * If $renderas is set, OC_Template will try to produce a full page in the * according layout. For now, renderas can be set to "guest", "user" or * "admin". */ @@ -233,34 +233,34 @@ class OC_TEMPLATE{ // Decide which page we show if( $this->renderas == "user" ) { - $page = new OC_TEMPLATE( "core", "layout.user" ); - $search=new OC_TEMPLATE( 'core', 'part.searchbox'); - $search->assign('searchurl',OC_HELPER::linkTo( 'search', 'index.php' )); + $page = new OC_Template( "core", "layout.user" ); + $search=new OC_Template( 'core', 'part.searchbox'); + $search->assign('searchurl',OC_Helper::linkTo( 'search', 'index.php' )); $page->assign('searchbox', $search->fetchPage()); // Add navigation entry - $page->assign( "navigation", OC_APP::getNavigation()); + $page->assign( "navigation", OC_App::getNavigation()); } elseif( $this->renderas == "admin" ) { - $page = new OC_TEMPLATE( "core", "layout.admin" ); - $search=new OC_TEMPLATE( 'core', 'part.searchbox'); - $search->assign('searchurl',OC_HELPER::linkTo( 'search', 'index.php' )); + $page = new OC_Template( "core", "layout.admin" ); + $search=new OC_Template( 'core', 'part.searchbox'); + $search->assign('searchurl',OC_Helper::linkTo( 'search', 'index.php' )); $page->assign('searchbox', $search->fetchPage()); // Add menu data - if( OC_GROUP::inGroup( $_SESSION["user_id"], "admin" )){ - $page->assign( "adminnavigation", OC_APP::getAdminNavigation()); + if( OC_Group::inGroup( $_SESSION["user_id"], "admin" )){ + $page->assign( "adminnavigation", OC_App::getAdminNavigation()); } - $page->assign( "settingsnavigation", OC_APP::getSettingsNavigation()); + $page->assign( "settingsnavigation", OC_App::getSettingsNavigation()); } else { - $page = new OC_TEMPLATE( "core", "layout.guest" ); + $page = new OC_Template( "core", "layout.guest" ); } // Add the css and js files - foreach(OC_UTIL::$scripts as $script){ + foreach(OC_Util::$scripts as $script){ if(is_file("$SERVERROOT/apps/$script.js" )){ $page->append( "jsfiles", "$WEBROOT/apps/$script.js" ); } @@ -271,7 +271,7 @@ class OC_TEMPLATE{ $page->append( "jsfiles", "$WEBROOT/core/$script.js" ); } } - foreach(OC_UTIL::$styles as $style){ + foreach(OC_Util::$styles as $style){ if(is_file("$SERVERROOT/apps/$style.css" )){ $page->append( "cssfiles", "$WEBROOT/apps/$style.css" ); } @@ -285,7 +285,7 @@ class OC_TEMPLATE{ // Add custom headers $page->assign('headers',$this->headers); - foreach(OC_UTIL::$headers as $header){ + foreach(OC_Util::$headers as $header){ $page->append('headers',$header); } @@ -328,7 +328,7 @@ class OC_TEMPLATE{ * @returns true/false */ public static function printUserPage( $application, $name, $parameters = array() ){ - $content = new OC_TEMPLATE( $application, $name, "user" ); + $content = new OC_Template( $application, $name, "user" ); foreach( $parameters as $key => $value ){ $content->assign( $key, $value ); } @@ -343,7 +343,7 @@ class OC_TEMPLATE{ * @returns true/false */ public static function printAdminPage( $application, $name, $parameters = array() ){ - $content = new OC_TEMPLATE( $application, $name, "admin" ); + $content = new OC_Template( $application, $name, "admin" ); foreach( $parameters as $key => $value ){ $content->assign( $key, $value ); } @@ -358,12 +358,10 @@ class OC_TEMPLATE{ * @returns true/false */ public static function printGuestPage( $application, $name, $parameters = array() ){ - $content = new OC_TEMPLATE( $application, $name, "guest" ); + $content = new OC_Template( $application, $name, "guest" ); foreach( $parameters as $key => $value ){ $content->assign( $key, $value ); } return $content->printPage(); } } - -?> diff --git a/lib/user.php b/lib/user.php index a64ce05f2c9..9b8f5fb13e7 100644 --- a/lib/user.php +++ b/lib/user.php @@ -20,10 +20,6 @@ * */ -if( !OC_CONFIG::getValue( "installed", false )){ - $_SESSION['user_id'] = ''; -} - /** * This class provides all methods for user management. * @@ -38,7 +34,7 @@ if( !OC_CONFIG::getValue( "installed", false )){ * post_login(uid) * logout() */ -class OC_USER { +class OC_User { // The backend used for user management private static $_usedBackends = array(); @@ -95,8 +91,7 @@ class OC_USER { case 'database': case 'mysql': case 'sqlite': - require_once('User/database.php'); - self::$_usedBackends[$backend] = new OC_USER_DATABASE(); + self::$_usedBackends[$backend] = new OC_User_Database(); break; default: $className = 'OC_USER_' . strToUpper($backend); @@ -113,7 +108,7 @@ class OC_USER { * @param $password The password of the new user * @returns true/false * - * Creates a new user. Basic checking of username is done in OC_USER + * Creates a new user. Basic checking of username is done in OC_User * itself, not in its subclasses. * * Allowed characters in the username are: "a-z", "A-Z", "0-9" and "_.@-" @@ -135,7 +130,7 @@ class OC_USER { $run = true; - OC_HOOK::emit( "OC_USER", "pre_createUser", array( "run" => &$run, "uid" => $uid, "password" => $password )); + OC_Hook::emit( "OC_User", "pre_createUser", array( "run" => &$run, "uid" => $uid, "password" => $password )); if( $run ){ //create the user in the first backend that supports creating users @@ -144,7 +139,7 @@ class OC_USER { continue; $backend->createUser($uid,$password); - OC_HOOK::emit( "OC_USER", "post_createUser", array( "uid" => $uid, "password" => $password )); + OC_Hook::emit( "OC_User", "post_createUser", array( "uid" => $uid, "password" => $password )); return true; } @@ -161,7 +156,7 @@ class OC_USER { */ public static function deleteUser( $uid ){ $run = true; - OC_HOOK::emit( "OC_USER", "pre_deleteUser", array( "run" => &$run, "uid" => $uid )); + OC_Hook::emit( "OC_User", "pre_deleteUser", array( "run" => &$run, "uid" => $uid )); if( $run ){ //delete the user from all backends @@ -171,12 +166,12 @@ class OC_USER { } } // We have to delete the user from all groups - foreach( OC_GROUP::getUserGroups( $uid ) as $i ){ - OC_GROUP::removeFromGroup( $uid, $i ); + foreach( OC_Group::getUserGroups( $uid ) as $i ){ + OC_Group::removeFromGroup( $uid, $i ); } // Emit and exit - OC_HOOK::emit( "OC_USER", "post_deleteUser", array( "uid" => $uid )); + OC_Hook::emit( "OC_User", "post_deleteUser", array( "uid" => $uid )); return true; } else{ @@ -194,12 +189,12 @@ class OC_USER { */ public static function login( $uid, $password ){ $run = true; - OC_HOOK::emit( "OC_USER", "pre_login", array( "run" => &$run, "uid" => $uid )); + OC_Hook::emit( "OC_User", "pre_login", array( "run" => &$run, "uid" => $uid )); if( $run && self::checkPassword( $uid, $password )){ $_SESSION['user_id'] = $uid; - OC_LOG::add( "core", $_SESSION['user_id'], "login" ); - OC_HOOK::emit( "OC_USER", "post_login", array( "uid" => $uid )); + OC_Log::add( "core", $_SESSION['user_id'], "login" ); + OC_Hook::emit( "OC_User", "post_login", array( "uid" => $uid )); return true; } else{ @@ -214,8 +209,8 @@ class OC_USER { * Logout, destroys session */ public static function logout(){ - OC_HOOK::emit( "OC_USER", "logout", array()); - OC_LOG::add( "core", $_SESSION['user_id'], "logout" ); + OC_Hook::emit( "OC_User", "logout", array()); + OC_Log::add( "core", $_SESSION['user_id'], "logout" ); $_SESSION['user_id'] = false; return true; } @@ -268,7 +263,7 @@ class OC_USER { */ public static function setPassword( $uid, $password ){ $run = true; - OC_HOOK::emit( "OC_USER", "pre_setPassword", array( "run" => &$run, "uid" => $uid, "password" => $password )); + OC_Hook::emit( "OC_User", "pre_setPassword", array( "run" => &$run, "uid" => $uid, "password" => $password )); if( $run ){ foreach(self::$_usedBackends as $backend){ @@ -278,7 +273,7 @@ class OC_USER { } } } - OC_HOOK::emit( "OC_USER", "post_setPassword", array( "uid" => $uid, "password" => $password )); + OC_Hook::emit( "OC_User", "post_setPassword", array( "uid" => $uid, "password" => $password )); return true; } else{ diff --git a/lib/User/backend.php b/lib/user/backend.php index 1797d0c475a..4afdf152150 100644 --- a/lib/User/backend.php +++ b/lib/user/backend.php @@ -41,9 +41,9 @@ define('OC_USER_BACKEND_USER_EXISTS', 0x100000); /** * abstract base class for user management - * subclass this for your own backends and see OC_USER_EXAMPLE for descriptions + * subclass this for your own backends and see OC_User_Example for descriptions */ -abstract class OC_USER_BACKEND { +abstract class OC_User_Backend { protected $possibleActions = array( OC_USER_BACKEND_CREATE_USER => 'createUser', diff --git a/lib/User/database.php b/lib/user/database.php index 0396ac30958..4992c2aa164 100644 --- a/lib/User/database.php +++ b/lib/user/database.php @@ -33,12 +33,10 @@ * */ -require_once('User/backend.php'); - /** * Class for user management in a SQL Database (e.g. MySQL, SQLite) */ -class OC_USER_DATABASE extends OC_USER_BACKEND { +class OC_User_Database extends OC_User_Backend { static private $userGroupCache=array(); /** @@ -47,7 +45,7 @@ class OC_USER_DATABASE extends OC_USER_BACKEND { * @param $password The password of the new user * @returns true/false * - * Creates a new user. Basic checking of username is done in OC_USER + * Creates a new user. Basic checking of username is done in OC_User * itself, not in its subclasses. */ public function createUser( $uid, $password ){ diff --git a/lib/User/example.php b/lib/user/example.php index 4abc1b3d49c..7481014de77 100644 --- a/lib/User/example.php +++ b/lib/user/example.php @@ -21,20 +21,18 @@ * */ -require_once('User/backend.php'); - /** * abstract reference class for user management * this class should only be used as a reference for method signatures and their descriptions */ -abstract class OC_USER_EXAMPLE extends OC_USER_BACKEND { +abstract class OC_User_Example extends OC_User_Backend { /** * @brief Create a new user * @param $uid The username of the user to create * @param $password The password of the new user * @returns true/false * - * Creates a new user. Basic checking of username is done in OC_USER + * Creates a new user. Basic checking of username is done in OC_User * itself, not in its subclasses. */ public function createUser($uid, $password){ diff --git a/lib/util.php b/lib/util.php new file mode 100644 index 00000000000..3e2e4fa34e4 --- /dev/null +++ b/lib/util.php @@ -0,0 +1,248 @@ +<?php + +/** + * Class for utility functions + * + */ +class OC_Util { + public static $scripts=array(); + public static $styles=array(); + public static $headers=array(); + private static $fsSetup=false; + + // Can be set up + public static function setupFS( $user = "", $root = "files" ){// configure the initial filesystem based on the configuration + if(self::$fsSetup){//setting up the filesystem twice can only lead to trouble + return false; + } + + // Global Variables + global $SERVERROOT; + global $CONFIG_DATADIRECTORY; + + $CONFIG_DATADIRECTORY_ROOT = OC_Config::getValue( "datadirectory", "$SERVERROOT/data" ); + $CONFIG_BACKUPDIRECTORY = OC_Config::getValue( "backupdirectory", "$SERVERROOT/backup" ); + + // Create root dir + if(!is_dir($CONFIG_DATADIRECTORY_ROOT)){ + @mkdir($CONFIG_DATADIRECTORY_ROOT) or die("Can't create data directory ($CONFIG_DATADIRECTORY_ROOT), you can usually fix this by setting the owner of '$SERVERROOT' to the user that the web server uses (www-data for debian/ubuntu)"); + } + + // 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(); + } + + if( $user != "" ){ //if we aren't logged in, there is no use to set up the filesystem + //first set up the local "root" storage and the backupstorage if needed + $rootStorage=OC_Filesystem::createStorage('local',array('datadir'=>$CONFIG_DATADIRECTORY_ROOT)); +// if( OC_Config::getValue( "enablebackup", false )){ +// // This creates the Directorys recursively +// if(!is_dir( "$CONFIG_BACKUPDIRECTORY/$user/$root" )){ +// mkdir( "$CONFIG_BACKUPDIRECTORY/$user/$root", 0755, true ); +// } +// $backupStorage=OC_Filesystem::createStorage('local',array('datadir'=>$CONFIG_BACKUPDIRECTORY)); +// $backup=new OC_FILEOBSERVER_BACKUP(array('storage'=>$backupStorage)); +// $rootStorage->addObserver($backup); +// } + OC_Filesystem::mount($rootStorage,'/'); + + // TODO add this storage provider in a proper way + $sharedStorage = OC_Filesystem::createStorage('shared',array('datadir'=>'/'.OC_User::getUser().'/files/Share/')); + OC_Filesystem::mount($sharedStorage,'/'.OC_User::getUser().'/files/Share/'); + + $CONFIG_DATADIRECTORY = "$CONFIG_DATADIRECTORY_ROOT/$user/$root"; + if( !is_dir( $CONFIG_DATADIRECTORY )){ + mkdir( $CONFIG_DATADIRECTORY, 0755, true ); + } + +// TODO: find a cool way for doing this +// //set up the other storages according to the system settings +// foreach($CONFIG_FILESYSTEM as $storageConfig){ +// if(OC_Filesystem::hasStorageType($storageConfig['type'])){ +// $arguments=$storageConfig; +// unset($arguments['type']); +// unset($arguments['mountpoint']); +// $storage=OC_Filesystem::createStorage($storageConfig['type'],$arguments); +// if($storage){ +// OC_Filesystem::mount($storage,$storageConfig['mountpoint']); +// } +// } +// } + + //jail the user into his "home" directory + OC_Filesystem::chroot("/$user/$root"); + self::$fsSetup=true; + } + } + + public static function tearDownFS(){ + OC_Filesystem::tearDown(); + self::$fsSetup=false; + } + + /** + * get the current installed version of ownCloud + * @return array + */ + public static function getVersion(){ + return array(1,90,0); + } + + /** + * add a javascript file + * + * @param url $url + */ + public static function addScript( $application, $file = null ){ + if( is_null( $file )){ + $file = $application; + $application = ""; + } + if( !empty( $application )){ + self::$scripts[] = "$application/js/$file"; + }else{ + self::$scripts[] = "js/$file"; + } + } + + /** + * add a css file + * + * @param url $url + */ + public static function addStyle( $application, $file = null ){ + if( is_null( $file )){ + $file = $application; + $application = ""; + } + if( !empty( $application )){ + self::$styles[] = "$application/css/$file"; + }else{ + self::$styles[] = "css/$file"; + } + } + + /** + * @brief Add a custom element to the header + * @param string tag tag name of the element + * @param array $attributes array of attrobutes for the element + * @param string $text the text content for the element + */ + public static function addHeader( $tag, $attributes, $text=''){ + self::$headers[]=array('tag'=>$tag,'attributes'=>$attributes,'text'=>$text); + } + + /** + * formats a timestamp in the "right" way + * + * @param int timestamp $timestamp + * @param bool dateOnly option to ommit time from the result + */ + public static function formatDate( $timestamp,$dateOnly=false){ + if(isset($_SESSION['timezone'])){//adjust to clients timezone if we know it + $systemTimeZone = intval(exec('date +%z')); + $systemTimeZone=(round($systemTimeZone/100,0)*60)+($systemTimeZone%100); + $clientTimeZone=$_SESSION['timezone']*60; + $offset=$clientTimeZone-$systemTimeZone; + $timestamp=$timestamp+$offset*60; + } + $timeformat=$dateOnly?'F j, Y':'F j, Y, H:i'; + return date($timeformat,$timestamp); + } + + /** + * Shows a pagenavi widget where you can jump to different pages. + * + * @param int $pagecount + * @param int $page + * @param string $url + * @return OC_Template + */ + public static function getPageNavi($pagecount,$page,$url) { + + $pagelinkcount=8; + if ($pagecount>1) { + $pagestart=$page-$pagelinkcount; + if($pagestart<0) $pagestart=0; + $pagestop=$page+$pagelinkcount; + if($pagestop>$pagecount) $pagestop=$pagecount; + + $tmpl = new OC_Template( '', 'part.pagenavi', '' ); + $tmpl->assign('page',$page); + $tmpl->assign('pagecount',$pagecount); + $tmpl->assign('pagestart',$pagestart); + $tmpl->assign('pagestop',$pagestop); + $tmpl->assign('url',$url); + return $tmpl; + } + } + + + + /** + * check if the current server configuration is suitable for ownCloud + * @return array arrays with error messages and hints + */ + public static function checkServer(){ + global $SERVERROOT; + global $CONFIG_DATADIRECTORY; + + $CONFIG_DATADIRECTORY_ROOT = OC_Config::getValue( "datadirectory", "$SERVERROOT/data" );; + $CONFIG_BACKUPDIRECTORY = OC_Config::getValue( "backupdirectory", "$SERVERROOT/backup" ); + $CONFIG_INSTALLED = OC_Config::getValue( "installed", false ); + $errors=array(); + + //check for database drivers + if(!is_callable('sqlite_open') and !is_callable('mysql_connect')){ + $errors[]=array('error'=>'No database drivers (sqlite or mysql) installed.<br/>','hint'=>'');//TODO: sane hint + } + $CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" ); + $CONFIG_DBNAME = OC_Config::getValue( "dbname", "owncloud" ); + + //try to get the username the httpd server runs on, used in hints + $stat=stat($_SERVER['DOCUMENT_ROOT']); + if(is_callable('posix_getpwuid')){ + $serverUser=posix_getpwuid($stat['uid']); + $serverUser='\''.$serverUser['name'].'\''; + }else{ + $serverUser='\'www-data\' for ubuntu/debian';//TODO: try to detect the distro and give a guess based on that + } + + //common hint for all file permissons error messages + $permissionsHint="Permissions can usually be fixed by setting the owner of the file or directory to the user the web server runs as ($serverUser)"; + + //check for correct file permissions + if(!stristr(PHP_OS, 'WIN')){ + $prems=substr(decoct(fileperms($CONFIG_DATADIRECTORY_ROOT)),-3); + if(substr($prems,-1)!='0'){ + OC_Helper::chmodr($CONFIG_DATADIRECTORY_ROOT,0770); + clearstatcache(); + $prems=substr(decoct(fileperms($CONFIG_DATADIRECTORY_ROOT)),-3); + if(substr($prems,2,1)!='0'){ + $errors[]=array('error'=>'Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') is readable from the web<br/>','hint'=>$permissionsHint); + } + } + if( OC_Config::getValue( "enablebackup", false )){ + $prems=substr(decoct(fileperms($CONFIG_BACKUPDIRECTORY)),-3); + if(substr($prems,-1)!='0'){ + OC_Helper::chmodr($CONFIG_BACKUPDIRECTORY,0770); + clearstatcache(); + $prems=substr(decoct(fileperms($CONFIG_BACKUPDIRECTORY)),-3); + if(substr($prems,2,1)!='0'){ + $errors[]=array('error'=>'Data directory ('.$CONFIG_BACKUPDIRECTORY.') is readable from the web<br/>','hint'=>$permissionsHint); + } + } + } + }else{ + //TODO: premisions checks for windows hosts + } + if(is_dir($CONFIG_DATADIRECTORY_ROOT) and !is_writable($CONFIG_DATADIRECTORY_ROOT)){ + $errors[]=array('error'=>'Data directory ('.$CONFIG_DATADIRECTORY_ROOT.') not writable by ownCloud<br/>','hint'=>$permissionsHint); + } + + //TODO: check for php modules + + return $errors; + } +} |