diff options
author | Georg Ehrke <dev@georgswebsite.de> | 2012-04-15 22:28:11 +0200 |
---|---|---|
committer | Georg Ehrke <dev@georgswebsite.de> | 2012-04-15 22:28:11 +0200 |
commit | 77cefdedb86de65e69f470c8b6a1b03bb001966e (patch) | |
tree | 547b3a111c4d07992b7c528f2db4962ee36f91f9 /lib | |
parent | 77a9e343aae4fc19a1e6fbf71b73e171640ac02a (diff) | |
parent | 12818093007d5bdce5519b5015e2a0748c98e24d (diff) | |
download | nextcloud-server-77cefdedb86de65e69f470c8b6a1b03bb001966e.tar.gz nextcloud-server-77cefdedb86de65e69f470c8b6a1b03bb001966e.zip |
Merge branch 'master' into sabredav_1.6
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/app.php | 67 | ||||
-rw-r--r-- | lib/appconfig.php | 34 | ||||
-rw-r--r-- | lib/connect.php | 40 | ||||
-rw-r--r-- | lib/db.php | 40 | ||||
-rw-r--r-- | lib/filecache.php | 36 | ||||
-rw-r--r-- | lib/files.php | 14 | ||||
-rw-r--r-- | lib/filestorage/common.php | 12 | ||||
-rw-r--r-- | lib/filesystemview.php | 8 | ||||
-rw-r--r-- | lib/group.php | 7 | ||||
-rw-r--r-- | lib/group/backend.php | 12 | ||||
-rwxr-xr-x | lib/helper.php | 82 | ||||
-rw-r--r-- | lib/installer.php | 4 | ||||
-rw-r--r-- | lib/json.php | 6 | ||||
-rw-r--r-- | lib/l10n.php | 33 | ||||
-rw-r--r-- | lib/migrate.php | 331 | ||||
-rw-r--r-- | lib/migration/content.php | 18 | ||||
-rw-r--r-- | lib/migration/provider.php | 8 | ||||
-rw-r--r-- | lib/mimetypes.list.php | 2 | ||||
-rw-r--r-- | lib/remote/cloud.php | 204 | ||||
-rw-r--r-- | lib/search.php | 30 | ||||
-rw-r--r-- | lib/search/provider.php | 6 | ||||
-rw-r--r-- | lib/search/provider/file.php | 4 | ||||
-rw-r--r-- | lib/setup.php | 8 | ||||
-rw-r--r-- | lib/template.php | 6 | ||||
-rw-r--r-- | lib/updater.php | 4 | ||||
-rw-r--r-- | lib/user/database.php | 2 | ||||
-rw-r--r-- | lib/user/dummy.php | 114 | ||||
-rw-r--r-- | lib/util.php | 2 |
28 files changed, 621 insertions, 513 deletions
diff --git a/lib/app.php b/lib/app.php index 1c81fbd4242..bd432109b23 100755 --- a/lib/app.php +++ b/lib/app.php @@ -35,6 +35,7 @@ class OC_App{ static private $adminForms = array(); static private $personalForms = array(); static private $appInfo = array(); + static private $appTypes = array(); /** * @brief loads all apps @@ -85,11 +86,7 @@ class OC_App{ if(is_string($types)){ $types=array($types); } - $appData=self::getAppInfo($app); - if(!isset($appData['types'])){ - return false; - } - $appTypes=$appData['types']; + $appTypes=self::getAppTypes($app); foreach($types as $type){ if(array_search($type,$appTypes)!==false){ return true; @@ -97,6 +94,32 @@ class OC_App{ } return false; } + + /** + * get the types of an app + * @param string $app + * @return array + */ + private static function getAppTypes($app){ + //load the cache + if(count(self::$appTypes)==0){ + self::$appTypes=OC_Appconfig::getValues(false,'types'); + } + + //get it from info.xml if we haven't cached it + if(!isset(self::$appTypes[$app])){ + $appData=self::getAppInfo($app); + if(isset($appData['types'])){ + self::$appTypes[$app]=$appData['types']; + }else{ + self::$appTypes[$app]=array(); + } + + OC_Appconfig::setValue($app,'types',implode(',',self::$appTypes[$app])); + } + + return explode(',',self::$appTypes[$app]); + } /** * get all enabled apps @@ -139,13 +162,18 @@ class OC_App{ if(!is_numeric($app)){ OC_Installer::installShippedApp($app); }else{ - $download=OC_OCSClient::getApplicationDownload($app,1); - if(isset($download['downloadlink']) and $download['downloadlink']<>'') { + $download=OC_OCSClient::getApplicationDownload($app,1); + if(isset($download['downloadlink']) and $download['downloadlink']!='') { $app=OC_Installer::installApp(array('source'=>'http','href'=>$download['downloadlink'])); } } } - OC_Appconfig::setValue( $app, 'enabled', 'yes' ); + if($app!==false){ + OC_Appconfig::setValue( $app, 'enabled', 'yes' ); + return true; + }else{ + return false; + } } /** @@ -249,7 +277,7 @@ class OC_App{ * entries are sorted by the key 'order' ascending. */ public static function getSettingsNavigation(){ - $l=new OC_L10N('core'); + $l=OC_L10N::get('core'); $settings = array(); // by default, settings only contain the help menu @@ -302,6 +330,20 @@ class OC_App{ return $list; } + + /** + * get the last version of the app, either from appinfo/version or from appinfo/info.xml + */ + public static function getAppVersion($appid){ + $file=OC::$APPSROOT.'/apps/'.$appid.'/appinfo/version'; + $version=@file_get_contents($file); + if($version){ + return $version; + }else{ + $appData=self::getAppInfo($appid); + return $appData['version']; + } + } /** * @brief Read app metadata from the info.xml file @@ -436,12 +478,11 @@ class OC_App{ // The rest comes here $versions = self::getAppVersions(); foreach( $versions as $app=>$installedVersion ){ - $appInfo=OC_App::getAppInfo($app); - if (isset($appInfo['version'])) { - $currentVersion=$appInfo['version']; + $currentVersion=OC_App::getAppVersion($app); + if ($currentVersion) { if (version_compare($currentVersion, $installedVersion, '>')) { OC_App::updateApp($app); - OC_Appconfig::setValue($app,'installed_version',$appInfo['version']); + OC_Appconfig::setValue($app,'installed_version',OC_App::getAppVersion($app)); } } } diff --git a/lib/appconfig.php b/lib/appconfig.php index 2b5cef59adc..5aaaadd9c4a 100644 --- a/lib/appconfig.php +++ b/lib/appconfig.php @@ -163,4 +163,38 @@ class OC_Appconfig{ return true; } + + /** + * get multiply values, either the app or key can be used as wildcard by setting it to false + * @param app + * @param key + * @return array + */ + public static function getValues($app,$key){ + if($app!==false and $key!==false){ + return false; + } + $where='WHERE'; + $fields='configvalue'; + $params=array(); + if($app!==false){ + $where.=' appid = ?'; + $fields.=', configkey'; + $params[]=$app; + $key='configkey'; + }else{ + $fields.=', appid'; + $where.=' configkey = ?'; + $params[]=$key; + $key='appid'; + } + $queryString='SELECT '.$fields.' FROM *PREFIX*appconfig '.$where; + $query=OC_DB::prepare($queryString); + $result=$query->execute($params); + $values=array(); + while($row=$result->fetchRow()){ + $values[$row[$key]]=$row['configvalue']; + } + return $values; + } } diff --git a/lib/connect.php b/lib/connect.php deleted file mode 100644 index 22e48750a62..00000000000 --- a/lib/connect.php +++ /dev/null @@ -1,40 +0,0 @@ -<?php - -/** -* ownCloud -* -* @author Frank Karlitschek -* @copyright 2010 Frank Karlitschek karlitschek@kde.org -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ - -/** - * Class for connecting multiply ownCloud installations - * - */ -class OC_Connect{ - static private $clouds=array(); - - static function connect($path,$user,$password){ - $cloud=new OC_REMOTE_CLOUD($path,$user,$password); - if($cloud->connected){ - self::$clouds[$path]=$cloud; - return $cloud; - }else{ - return false; - } - } -} diff --git a/lib/db.php b/lib/db.php index 9364b9e0015..2f74cc6dd95 100644 --- a/lib/db.php +++ b/lib/db.php @@ -36,8 +36,26 @@ class OC_DB { static private $affected=0; static private $result=false; static private $inTransaction=false; + static private $prefix=null; + static private $type=null; /** + * check which backend we should use + * @return BACKEND_MDB2 or BACKEND_PDO + */ + private static function getDBBackend(){ + $backend=self::BACKEND_MDB2; + if(class_exists('PDO') && OC_Config::getValue('installed', false)){//check if we can use PDO, else use MDB2 (instalation always needs to be done my mdb2) + $type = OC_Config::getValue( "dbtype", "sqlite" ); + if($type=='sqlite3') $type='sqlite'; + $drivers=PDO::getAvailableDrivers(); + if(array_search($type,$drivers)!==false){ + $backend=self::BACKEND_PDO; + } + } + } + + /** * @brief connects to the database * @returns true if connection can be established or nothing (die()) * @@ -48,15 +66,7 @@ class OC_DB { return; } if(is_null($backend)){ - $backend=self::BACKEND_MDB2; - if(class_exists('PDO') && OC_Config::getValue('installed', false)){//check if we can use PDO, else use MDB2 (instalation always needs to be done my mdb2) - $type = OC_Config::getValue( "dbtype", "sqlite" ); - if($type=='sqlite3') $type='sqlite'; - $drivers=PDO::getAvailableDrivers(); - if(array_search($type,$drivers)!==false){ - $backend=self::BACKEND_PDO; - } - } + $backend=self::getDBBackend(); } if($backend==self::BACKEND_PDO){ self::connectPDO(); @@ -423,8 +433,14 @@ class OC_DB { private static function processQuery( $query ){ self::connect(); // We need Database type and table prefix - $type = OC_Config::getValue( "dbtype", "sqlite" ); - $prefix = OC_Config::getValue( "dbtableprefix", "oc_" ); + if(is_null(self::$type)){ + self::$type=OC_Config::getValue( "dbtype", "sqlite" ); + } + $type = self::$type; + if(is_null(self::$prefix)){ + self::$prefix=OC_Config::getValue( "dbtableprefix", "oc_" ); + } + $prefix = self::$prefix; // differences in escaping of table names ('`' for mysql) and getting the current timestamp if( $type == 'sqlite' || $type == 'sqlite3' ){ @@ -485,7 +501,7 @@ class OC_DB { } /** - * @breif replaces the owncloud tables with a new set + * @brief replaces the owncloud tables with a new set * @param $file string path to the MDB2 xml db export file */ public static function replaceDB( $file ){ diff --git a/lib/filecache.php b/lib/filecache.php index cdd91dcbfa4..e62fb2189f4 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -281,6 +281,7 @@ class OC_FileCache{ /** * get the file id as used in the cache + * unlike the public getId, full paths are used here (/usename/files/foo instead of /foo) * @param string $path * @return int */ @@ -303,6 +304,39 @@ class OC_FileCache{ return -1; } } + + /** + * get the file id as used in the cache + * @param string path + * @param string root (optional) + * @return int + */ + public static function getId($path,$root=''){ + if(!$root){ + $root=OC_Filesystem::getRoot(); + } + if($root=='/'){ + $root=''; + } + $path=$root.$path; + return self::getFileId($path); + } + + /** + * get the file path from the id, relative to the home folder of the user + * @param int id + * @param string user (optional) + * @return string + */ + public static function getPath($id,$user=''){ + if(!$user){ + $user=OC_User::getUser(); + } + $query=OC_DB::prepare('SELECT path FROM *PREFIX*fscache WHERE id=? AND user=?'); + $result=$query->execute(array($id,$user)); + $row=$result->fetchRow(); + return $row['path']; + } /** * get the file id of the parent folder, taking into account '/' has no parent @@ -441,7 +475,7 @@ class OC_FileCache{ }else{ return; } - $size=OC_Filesystem::filesize($oldPath); + $size=OC_Filesystem::filesize($newPath); self::increaseSize(dirname($fullOldPath),-$oldSize); self::increaseSize(dirname($fullNewPath),$oldSize); self::move($oldPath,$newPath); diff --git a/lib/files.php b/lib/files.php index 051cfd4b81c..a7b83149574 100644 --- a/lib/files.php +++ b/lib/files.php @@ -63,7 +63,7 @@ class OC_Files { $executionTime = intval(ini_get('max_execution_time')); set_time_limit(0); $zip = new ZipArchive(); - $filename = get_temp_dir().'/ownCloud_'.mt_rand(10000,99999).'.zip'; + $filename = OC_Helper::tmpFile('.zip'); if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)!==TRUE) { exit("cannot open <$filename>\n"); } @@ -84,7 +84,7 @@ class OC_Files { $executionTime = intval(ini_get('max_execution_time')); set_time_limit(0); $zip = new ZipArchive(); - $filename = get_temp_dir().'/ownCloud_'.mt_rand(10000,99999).'.zip'; + $filename = OC_Helper::tmpFile('.zip'); if ($zip->open($filename, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)!==TRUE) { exit("cannot open <$filename>\n"); } @@ -104,15 +104,15 @@ 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)); + $fileData=OC_FileCache::get($filename); + header('Content-Type: ' . $fileData['mimetype']); + header('Content-Length: ' . $fileData['size']); } }elseif($zip or !OC_Filesystem::file_exists($filename)){ header("HTTP/1.0 404 Not Found"); $tmpl = new OC_Template( '', '404', 'guest' ); $tmpl->assign('file',$filename); $tmpl->printPage(); -// die('404 Not Found'); }else{ header("HTTP/1.0 403 Forbidden"); die('403 Forbidden'); @@ -225,7 +225,7 @@ class OC_Files { */ static function validateZipDownload($dir, $files) { if(!OC_Config::getValue('allowZipDownload', true)) { - $l = new OC_L10N('files'); + $l = OC_L10N::get('files'); header("HTTP/1.0 409 Conflict"); $tmpl = new OC_Template( '', 'error', 'user' ); $errors = array( @@ -250,7 +250,7 @@ class OC_Files { $totalsize += OC_Filesystem::filesize($dir.'/'.$files); } if($totalsize > $zipLimit) { - $l = new OC_L10N('files'); + $l = OC_L10N::get('files'); header("HTTP/1.0 409 Conflict"); $tmpl = new OC_Template( '', 'error', 'user' ); $errors = array( diff --git a/lib/filestorage/common.php b/lib/filestorage/common.php index f632474df01..f0bfc064cb5 100644 --- a/lib/filestorage/common.php +++ b/lib/filestorage/common.php @@ -100,11 +100,11 @@ abstract class OC_Filestorage_Common extends OC_Filestorage { } $head=fread($source,8192);//8kb should suffice to determine a mimetype if($pos=strrpos($path,'.')){ - $extention=substr($path,$pos); + $extension=substr($path,$pos); }else{ - $extention=''; + $extension=''; } - $tmpFile=OC_Helper::tmpFile($extention); + $tmpFile=OC_Helper::tmpFile($extension); file_put_contents($tmpFile,$head); $mime=OC_Helper::getMimeType($tmpFile); unlink($tmpFile); @@ -129,11 +129,11 @@ abstract class OC_Filestorage_Common extends OC_Filestorage { return false; } if($pos=strrpos($path,'.')){ - $extention=substr($path,$pos); + $extension=substr($path,$pos); }else{ - $extention=''; + $extension=''; } - $tmpFile=OC_Helper::tmpFile($extention); + $tmpFile=OC_Helper::tmpFile($extension); $target=fopen($tmpFile,'w'); $count=OC_Helper::streamCopy($source,$target); return $tmpFile; diff --git a/lib/filesystemview.php b/lib/filesystemview.php index 9d530c7ad63..95873bd87cf 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -283,8 +283,12 @@ class OC_FilesystemView { if(OC_Filesystem::isValidPath($path)){ $source=$this->fopen($path,'r'); if($source){ - $extention=substr($path,strrpos($path,'.')); - $tmpFile=OC_Helper::tmpFile($extention); + $extension=''; + $extOffset=strpos($path,'.'); + if($extOffset !== false) { + $extension=substr($path,strrpos($path,'.')); + } + $tmpFile=OC_Helper::tmpFile($extension); file_put_contents($tmpFile,$source); return $tmpFile; } diff --git a/lib/group.php b/lib/group.php index 4ae9302f78b..9b2959d1f73 100644 --- a/lib/group.php +++ b/lib/group.php @@ -255,7 +255,12 @@ class OC_Group { * @return bool */ public static function groupExists($gid){ - return in_array( $gid, self::getGroups()); + foreach(self::$_usedBackends as $backend){ + if ($backend->groupExists($gid)){ + return true; + } + } + return false; } /** diff --git a/lib/group/backend.php b/lib/group/backend.php index b3fc06ac9a8..d0bc970da73 100644 --- a/lib/group/backend.php +++ b/lib/group/backend.php @@ -82,4 +82,16 @@ abstract class OC_Group_Backend { public function implementsActions($actions){ return (bool)($this->getSupportedActions() & $actions); } + + /** + * check if a group exists + * @param string $gid + * @return bool + */ + public function groupExists($gid){ + if(!$backend->implementsActions(OC_GROUP_BACKEND_GET_GROUPS)){ + return false; + } + return in_array($gid, $this->getGroups()); + } } diff --git a/lib/helper.php b/lib/helper.php index f5626bccaa7..412f0e6b764 100755 --- a/lib/helper.php +++ b/lib/helper.php @@ -27,7 +27,7 @@ class OC_Helper { private static $mimetypes=array(); private static $tmpFiles=array(); - + /** * @brief Creates an url * @param $app app @@ -123,7 +123,7 @@ class OC_Helper { }elseif( file_exists( OC::$SERVERROOT."/core/img/$image" )){ return OC::$WEBROOT."/core/img/$image"; }else{ - echo('image not found: image:'.$image.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); + echo('image not found: image:'.$image.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); die(); } } @@ -188,7 +188,7 @@ class OC_Helper { $bytes = round( $bytes / 1024, 1 ); return "$bytes GB"; } - + /** * @brief Make a computer file size * @param $str file size in a fancy format @@ -224,9 +224,9 @@ class OC_Helper { $bytes = round($bytes, 2); - return $bytes; + return $bytes; } - + /** * @brief Recusive editing of file permissions * @param $path path to file or folder @@ -276,7 +276,7 @@ class OC_Helper { copy($src, $dest); } } - + /** * @brief Recusive deletion of folders * @param string $dir path to the folder @@ -294,6 +294,9 @@ class OC_Helper { }elseif(file_exists($dir)){ unlink($dir); } + if(file_exists($dir)) { + return false; + } } /** @@ -307,9 +310,9 @@ class OC_Helper { $mimeType='application/octet-stream'; if ($mimeType=='application/octet-stream') { self::$mimetypes = include('mimetypes.fixlist.php'); - $extention=strtolower(strrchr(basename($path), ".")); - $extention=substr($extention,1);//remove leading . - $mimeType=(isset(self::$mimetypes[$extention]))?self::$mimetypes[$extention]:'application/octet-stream'; + $extension=strtolower(strrchr(basename($path), ".")); + $extension=substr($extension,1);//remove leading . + $mimeType=(isset(self::$mimetypes[$extension]))?self::$mimetypes[$extension]:'application/octet-stream'; } if (@is_dir($path)) { @@ -343,13 +346,13 @@ class OC_Helper { if(!self::$mimetypes || self::$mimetypes != include('mimetypes.list.php')){ self::$mimetypes=include('mimetypes.list.php'); } - $extention=strtolower(strrchr(basename($path), ".")); - $extention=substr($extention,1);//remove leading . - $mimeType=(isset(self::$mimetypes[$extention]))?self::$mimetypes[$extention]:'application/octet-stream'; + $extension=strtolower(strrchr(basename($path), ".")); + $extension=substr($extension,1);//remove leading . + $mimeType=(isset(self::$mimetypes[$extension]))?self::$mimetypes[$extension]:'application/octet-stream'; } return $mimeType; } - + /** * @brief Checks $_REQUEST contains a var for the $s key. If so, returns the html-escaped value of this var; otherwise returns the default value provided by $d. * @param $s name of the var to escape, if set. @@ -357,16 +360,16 @@ class OC_Helper { * @returns the print-safe value. * */ - + //FIXME: should also check for value validation (i.e. the email is an email). public static function init_var($s, $d="") { $r = $d; if(isset($_REQUEST[$s]) && !empty($_REQUEST[$s])) $r = stripslashes(htmlspecialchars($_REQUEST[$s])); - + return $r; } - + /** * returns "checked"-attribut if request contains selected radio element OR if radio element is the default one -- maybe? * @param string $s Name of radio-button element name @@ -422,7 +425,7 @@ class OC_Helper { } return false; } - + /** * copy the contents of one stream to another * @param resource source @@ -439,7 +442,7 @@ class OC_Helper { } return $count; } - + /** * create a temporary file with an unique filename * @param string postfix @@ -467,15 +470,54 @@ class OC_Helper { self::$tmpFiles[]=$path; return $path.'/'; } - + /** * remove all files created by self::tmpFile */ public static function cleanTmp(){ + $leftoversFile='/tmp/oc-not-deleted'; + if(file_exists($leftoversFile)){ + $leftovers=file($leftoversFile); + foreach($leftovers as $file) { + self::rmdirr($file); + } + unlink($leftoversFile); + } + foreach(self::$tmpFiles as $file){ if(file_exists($file)){ - self::rmdirr($file); + if(!self::rmdirr($file)) { + file_put_contents($leftoversFile, $file."\n", FILE_APPEND); + } } } } + + /** + * Adds a suffix to the name in case the file exists + * + * @param $path + * @param $filename + * @return string + */ + public static function buildNotExistingFileName($path, $filename) + { + if ($pos = strrpos($filename, '.')) { + $name = substr($filename, 0, $pos); + $ext = substr($filename, $pos); + } else { + $name = $filename; + } + + $newpath = $path . '/' . $filename; + $newname = $filename; + $counter = 2; + while (OC_Filesystem::file_exists($newpath)) { + $newname = $name . ' (' . $counter . ')' . $ext; + $newpath = $path . '/' . $newname; + $counter++; + } + + return $newname; + } } diff --git a/lib/installer.php b/lib/installer.php index 38e17130e3c..6edf4ce1b74 100644 --- a/lib/installer.php +++ b/lib/installer.php @@ -175,7 +175,7 @@ class OC_Installer{ } //set the installed version - OC_Appconfig::setValue($info['id'],'installed_version',$info['version']); + OC_Appconfig::setValue($info['id'],'installed_version',OC_App::getAppVersion($info['id'])); OC_Appconfig::setValue($info['id'],'enabled','no'); return $info['id']; } @@ -297,7 +297,7 @@ class OC_Installer{ include(OC::$APPSROOT."/apps/$app/appinfo/install.php"); } $info=OC_App::getAppInfo($app); - OC_Appconfig::setValue($app,'installed_version',$info['version']); + OC_Appconfig::setValue($app,'installed_version',OC_App::getAppVersion($app)); return $info; } } diff --git a/lib/json.php b/lib/json.php index cedf79fd7c3..0d208ce12a2 100644 --- a/lib/json.php +++ b/lib/json.php @@ -24,7 +24,7 @@ class OC_JSON{ */ public static function checkAppEnabled($app){ if( !OC_App::isEnabled($app)){ - $l = new OC_L10N('core'); + $l = OC_L10N::get('core'); self::error(array( 'data' => array( 'message' => $l->t('Application is not enabled') ))); exit(); } @@ -35,7 +35,7 @@ class OC_JSON{ */ public static function checkLoggedIn(){ if( !OC_User::isLoggedIn()){ - $l = new OC_L10N('core'); + $l = OC_L10N::get('core'); self::error(array( 'data' => array( 'message' => $l->t('Authentication error') ))); exit(); } @@ -47,7 +47,7 @@ class OC_JSON{ public static function checkAdminUser(){ self::checkLoggedIn(); if( !OC_Group::inGroup( OC_User::getUser(), 'admin' )){ - $l = new OC_L10N('core'); + $l = OC_L10N::get('core'); self::error(array( 'data' => array( 'message' => $l->t('Authentication error') ))); exit(); } diff --git a/lib/l10n.php b/lib/l10n.php index 636326f9864..c0ecdbd1b70 100644 --- a/lib/l10n.php +++ b/lib/l10n.php @@ -25,6 +25,11 @@ */ class OC_L10N{ /** + * cached instances + */ + protected static $instances=array(); + + /** * cache */ protected static $cache = array(); @@ -46,6 +51,21 @@ class OC_L10N{ 'date' => 'd.m.Y', 'datetime' => 'd.m.Y H:i:s', 'time' => 'H:i:s'); + + /** + * get an L10N instance + * @return OC_L10N + */ + public static function get($app,$lang=null){ + if(is_null($lang)){ + if(!isset(self::$instances[$app])){ + self::$instances[$app]=new OC_L10N($app); + } + return self::$instances[$app]; + }else{ + return new OC_L10N($app,$lang); + } + } /** * @brief The constructor @@ -261,17 +281,14 @@ class OC_L10N{ public static function findAvailableLanguages($app=null){ $available=array('en');//english is always available $dir = self::findI18nDir($app); - if(file_exists($dir)){ - $dh = opendir($dir); - while(($file = readdir($dh)) !== false){ - if(substr($file, -4, 4) == '.php' and (strlen($file) == 6 || strlen($file) == 9)){ + if(is_dir($dir)){ + $files=scandir($dir); + foreach($files as $file){ + if(substr($file, -4, 4) == '.php'){ $i = substr($file, 0, -4); - if($i != ''){ - $available[] = $i; - } + $available[] = $i; } } - closedir($dh); } return $available; } diff --git a/lib/migrate.php b/lib/migrate.php index dff3abe9e93..f46d860e806 100644 --- a/lib/migrate.php +++ b/lib/migrate.php @@ -25,8 +25,8 @@ * provides an interface to migrate users and whole ownclouds */ class OC_Migrate{ - - + + // Array of OC_Migration_Provider objects static private $providers=array(); // User id of the user to import/export @@ -47,7 +47,7 @@ class OC_Migrate{ static private $zippath=false; // Holds the OC_Migration_Content object static private $content=false; - + /** * register a new migration provider * @param OC_Migrate_Provider $provider @@ -55,28 +55,28 @@ class OC_Migrate{ public static function registerProvider($provider){ self::$providers[]=$provider; } - - /** - * @breif finds and loads the providers + + /** + * @brief finds and loads the providers */ static private function findProviders(){ // Find the providers $apps = OC_App::getAllApps(); - + foreach($apps as $app){ $path = OC::$SERVERROOT . '/apps/' . $app . '/appinfo/migrate.php'; if( file_exists( $path ) ){ - include( $path ); - } - } + include( $path ); + } + } } - + /** - * @breif exports a user, or owncloud instance + * @brief exports a user, or owncloud instance * @param optional $uid string user id of user to export if export type is user, defaults to current * @param ootional $type string type of export, defualts to user * @param otional $path string path to zip output folder - * @return false on error, path to zip on success + * @return false on error, path to zip on success */ public static function export( $uid=null, $type='user', $path=null ){ $datadir = OC_Config::getValue( 'datadirectory' ); @@ -84,47 +84,48 @@ class OC_Migrate{ $types = array( 'user', 'instance', 'system', 'userfiles' ); if( !in_array( $type, $types ) ){ OC_Log::write( 'migration', 'Invalid export type', OC_Log::ERROR ); - return json_encode( array( array( 'success' => false ) ) ); + return json_encode( array( array( 'success' => false ) ) ); } self::$exporttype = $type; // Userid? if( self::$exporttype == 'user' ){ // Check user exists - if( !is_null($uid) ){ - if( !OC_User_Database::userExists( $uid ) ){ + if( !is_null($uid) ){ + $db = new OC_User_Database; + if( !$db->userExists( $uid ) ){ OC_Log::write('migration', 'User: '.$uid.' is not in the database and so cannot be exported.', OC_Log::ERROR); - return json_encode( array( 'success' => false ) ); + return json_encode( array( 'success' => false ) ); } self::$uid = $uid; } else { - self::$uid = OC_User::getUser(); - } + self::$uid = OC_User::getUser(); + } } // Calculate zipname if( self::$exporttype == 'user' ){ - $zipname = 'oc_export_' . self::$uid . '_' . date("y-m-d_H-i-s") . '.zip'; + $zipname = 'oc_export_' . self::$uid . '_' . date("y-m-d_H-i-s") . '.zip'; } else { $zipname = 'oc_export_' . self::$exporttype . '_' . date("y-m-d_H-i-s") . '.zip'; } // Calculate path if( self::$exporttype == 'user' ){ - self::$zippath = $datadir . '/' . self::$uid . '/' . $zipname; + self::$zippath = $datadir . '/' . self::$uid . '/' . $zipname; } else { if( !is_null( $path ) ){ // Validate custom path if( !file_exists( $path ) || !is_writeable( $path ) ){ OC_Log::write( 'migration', 'Path supplied is invalid.', OC_Log::ERROR ); - return json_encode( array( 'success' => false ) ); + return json_encode( array( 'success' => false ) ); } - self::$zippath = $path . $zipname; + self::$zippath = $path . $zipname; } else { // Default path - self::$zippath = get_temp_dir() . '/' . $zipname; + self::$zippath = get_temp_dir() . '/' . $zipname; } } // Create the zip object if( !self::createZip() ){ - return json_encode( array( 'success' => false ) ); + return json_encode( array( 'success' => false ) ); } // Do the export self::findProviders(); @@ -134,20 +135,20 @@ class OC_Migrate{ // Connect to the db self::$dbpath = $datadir . '/' . self::$uid . '/migration.db'; if( !self::connectDB() ){ - return json_encode( array( 'success' => false ) ); + return json_encode( array( 'success' => false ) ); } self::$content = new OC_Migration_Content( self::$zip, self::$MDB2 ); // Export the app info - $exportdata = self::exportAppData(); + $exportdata = self::exportAppData(); // Add the data dir to the zip self::$content->addDir( $datadir . '/' . self::$uid, true, '/' ); - break; + break; case 'instance': self::$content = new OC_Migration_Content( self::$zip ); // Creates a zip that is compatable with the import function $dbfile = tempnam( "/tmp", "owncloud_export_data_" ); OC_DB::getDbStructure( $dbfile, 'MDB2_SCHEMA_DUMP_ALL'); - + // Now add in *dbname* and *dbprefix* $dbexport = file_get_contents( $dbfile ); $dbnamestring = "<database>\n\n <name>" . OC_Config::getValue( "dbname", "owncloud" ); @@ -158,14 +159,14 @@ class OC_Migrate{ self::$content->addFromString( $dbexport, "dbexport.xml" ); // Add user data foreach(OC_User::getUsers() as $user){ - self::$content->addDir( $datadir . '/' . $user . '/', true, "/userdata/" ); + self::$content->addDir( $datadir . '/' . $user . '/', true, "/userdata/" ); } break; case 'userfiles': self::$content = new OC_Migration_Content( self::$zip ); // Creates a zip with all of the users files foreach(OC_User::getUsers() as $user){ - self::$content->addDir( $datadir . '/' . $user . '/', true, "/" ); + self::$content->addDir( $datadir . '/' . $user . '/', true, "/" ); } break; case 'system': @@ -178,70 +179,70 @@ class OC_Migrate{ break; } if( !$info = self::getExportInfo( $exportdata ) ){ - return json_encode( array( 'success' => false ) ); + return json_encode( array( 'success' => false ) ); } // Add the export info json to the export zip self::$content->addFromString( $info, 'export_info.json' ); if( !self::$content->finish() ){ - return json_encode( array( 'success' => false ) ); + return json_encode( array( 'success' => false ) ); } - return json_encode( array( 'success' => true, 'data' => self::$zippath ) ); + return json_encode( array( 'success' => true, 'data' => self::$zippath ) ); } - + /** - * @breif imports a user, or owncloud instance + * @brief imports a user, or owncloud instance * @param $path string path to zip * @param optional $type type of import (user or instance) - * @param optional $uid userid of new user + * @param optional $uid userid of new user */ public static function import( $path, $type='user', $uid=null ){ OC_Util::checkAdminUser(); $datadir = OC_Config::getValue( 'datadirectory' ); // Extract the zip if( !$extractpath = self::extractZip( $path ) ){ - return json_encode( array( 'success' => false ) ); + return json_encode( array( 'success' => false ) ); } // Get export_info.json $scan = scandir( $extractpath ); // Check for export_info.json if( !in_array( 'export_info.json', $scan ) ){ OC_Log::write( 'migration', 'Invalid import file, export_info.json note found', OC_Log::ERROR ); - return json_encode( array( 'success' => false ) ); + return json_encode( array( 'success' => false ) ); } $json = json_decode( file_get_contents( $extractpath . 'export_info.json' ) ); if( $json->exporttype != $type ){ OC_Log::write( 'migration', 'Invalid import file', OC_Log::ERROR ); - return json_encode( array( 'success' => false ) ); + return json_encode( array( 'success' => false ) ); } self::$exporttype = $type; - + // Have we got a user if type is user if( self::$exporttype == 'user' ){ if( !$uid ){ self::$uid = $json->exporteduser; - } else { + } else { self::$uid = $uid; } } - + // Handle export types switch( self::$exporttype ){ case 'user': // Check user availability if( OC_User::userExists( self::$uid ) ){ OC_Log::write( 'migration', 'User already exists', OC_Log::ERROR ); - return json_encode( array( 'success' => false ) ); + return json_encode( array( 'success' => false ) ); } $run = true; OC_Hook::emit( "OC_User", "pre_createUser", array( "run" => &$run, "uid" => self::$uid, "password" => $json->hash )); if( !$run ){ // Something stopped the user creation OC_Log::write( 'migration', 'User creation failed', OC_Log::ERROR ); - return json_encode( array( 'success' => false ) ); + return json_encode( array( 'success' => false ) ); } // Create the user if( !self::createUser( self::$uid, $json->hash ) ){ - return json_encode( array( 'success' => false ) ); + return json_encode( array( 'success' => false ) ); } // Emit the post_createUser hook (password is already hashed, will cause problems OC_Hook::emit( "OC_User", "post_createUser", array( "uid" => self::$uid, "password" => $json->hash )); @@ -249,19 +250,19 @@ class OC_Migrate{ $path = $datadir . '/' . self::$uid; if( !mkdir( $path, 0755, true ) ){ OC_Log::write( 'migration', 'Failed to create users data dir: '.$path, OC_Log::ERROR ); - return json_encode( array( 'success' => false ) ); + return json_encode( array( 'success' => false ) ); } // Copy data if( !self::copy_r( $extractpath . $json->exporteduser, $datadir . '/' . self::$uid ) ){ - return json_encode( array( 'success' => false ) ); + return json_encode( array( 'success' => false ) ); } - // Import user app data + // Import user app data if( !$appsimported = self::importAppData( $extractpath . $json->exporteduser . '/migration.db', $json, self::$uid ) ){ - return json_encode( array( 'success' => false ) ); + return json_encode( array( 'success' => false ) ); } // All done! if( !self::unlink_r( $extractpath ) ){ - OC_Log::write( 'migration', 'Failed to delete the extracted zip', OC_Log::ERROR ); + OC_Log::write( 'migration', 'Failed to delete the extracted zip', OC_Log::ERROR ); } return json_encode( array( 'success' => true, 'data' => $appsimported ) ); break; @@ -270,59 +271,59 @@ class OC_Migrate{ * EXPERIMENTAL // Check for new data dir and dbexport before doing anything // TODO - + // Delete current data folder. OC_Log::write( 'migration', "Deleting current data dir", OC_Log::INFO ); if( !self::unlink_r( $datadir, false ) ){ OC_Log::write( 'migration', 'Failed to delete the current data dir', OC_Log::ERROR ); - return json_encode( array( 'success' => false ) ); + return json_encode( array( 'success' => false ) ); } - + // Copy over data if( !self::copy_r( $extractpath . 'userdata', $datadir ) ){ OC_Log::write( 'migration', 'Failed to copy over data directory', OC_Log::ERROR ); - return json_encode( array( 'success' => false ) ); + return json_encode( array( 'success' => false ) ); } - + // Import the db if( !OC_DB::replaceDB( $extractpath . 'dbexport.xml' ) ){ - return json_encode( array( 'success' => false ) ); + return json_encode( array( 'success' => false ) ); } // Done - return json_encode( 'success' => true ); + return json_encode( 'success' => true ); */ - break; + break; } - + } - + /** - * @breif recursively deletes a directory + * @brief recursively deletes a directory * @param $dir string path of dir to delete * $param optional $deleteRootToo bool delete the root directory * @return bool */ - private static function unlink_r( $dir, $deleteRootToo=true ){ - if( !$dh = @opendir( $dir ) ){ - return false; - } + private static function unlink_r( $dir, $deleteRootToo=true ){ + if( !$dh = @opendir( $dir ) ){ + return false; + } while (false !== ($obj = readdir($dh))){ - if($obj == '.' || $obj == '..') { - continue; - } - if (!@unlink($dir . '/' . $obj)){ - self::unlink_r($dir.'/'.$obj, true); - } - } - closedir($dh); - if ( $deleteRootToo ) { - @rmdir($dir); - } - return true; - } - + if($obj == '.' || $obj == '..') { + continue; + } + if (!@unlink($dir . '/' . $obj)){ + self::unlink_r($dir.'/'.$obj, true); + } + } + closedir($dh); + if ( $deleteRootToo ) { + @rmdir($dir); + } + return true; + } + /** - * @breif copies recursively + * @brief copies recursively * @param $path string path to source folder * @param $dest string path to destination * @return bool @@ -349,12 +350,12 @@ class OC_Migrate{ return copy( $path, $dest ); } else { return false; - } + } } - + /** - * @breif tries to extract the import zip - * @param $path string path to the zip + * @brief tries to extract the import zip + * @param $path string path to the zip * @return string path to extract location (with a trailing slash) or false on failure */ static private function extractZip( $path ){ @@ -362,20 +363,20 @@ class OC_Migrate{ // Validate path if( !file_exists( $path ) ){ OC_Log::write( 'migration', 'Zip not found', OC_Log::ERROR ); - return false; + return false; } if ( self::$zip->open( $path ) != TRUE ) { OC_Log::write( 'migration', "Failed to open zip file", OC_Log::ERROR ); return false; } - $to = get_temp_dir() . '/oc_import_' . self::$exporttype . '_' . date("y-m-d_H-i-s") . '/'; + $to = get_temp_dir() . '/oc_import_' . self::$exporttype . '_' . date("y-m-d_H-i-s") . '/'; if( !self::$zip->extractTo( $to ) ){ - return false; + return false; } - self::$zip->close(); + self::$zip->close(); return $to; } - + /** * @brief connects to a MDB2 database scheme * @returns bool @@ -393,16 +394,16 @@ class OC_Migrate{ return true; } - + /** - * @breif creates a migration.db in the users data dir with their app data in + * @brief creates a migration.db in the users data dir with their app data in * @return bool whether operation was successfull */ private static function exportAppData( ){ - + $success = true; $return = array(); - + // Foreach provider foreach( self::$providers as $provider ){ $success = true; @@ -413,37 +414,37 @@ class OC_Migrate{ if( is_array( $tables ) ){ // Save the table names foreach($tables as $table){ - $return['apps'][$provider->getID()]['tables'][] = $table; - } + $return['apps'][$provider->getID()]['tables'][] = $table; + } } else { // It failed to create the tables $success = false; - } + } } - + // Run the export function? if( $success ){ // Set the provider properties $provider->setData( self::$uid, self::$content ); - $return['apps'][$provider->getID()]['success'] = $provider->export(); + $return['apps'][$provider->getID()]['success'] = $provider->export(); } else { - $return['apps'][$provider->getID()]['success'] = false; - $return['apps'][$provider->getID()]['message'] = 'failed to create the app tables'; + $return['apps'][$provider->getID()]['success'] = false; + $return['apps'][$provider->getID()]['message'] = 'failed to create the app tables'; } - + // Now add some app info the the return array $appinfo = OC_App::getAppInfo( $provider->getID() ); - $return['apps'][$provider->getID()]['version'] = $appinfo['version']; - + $return['apps'][$provider->getID()]['version'] = OC_App::getAppVersion($provider->getID()); + } - + return $return; - + } - - + + /** - * @breif generates json containing export info, and merges any data supplied + * @brief generates json containing export info, and merges any data supplied * @param optional $array array of data to include in the returned json * @return bool */ @@ -464,11 +465,11 @@ class OC_Migrate{ OC_Log::write( 'migration', 'Failed to get the users password hash', OC_log::ERROR); return false; } - $info['hash'] = $hash; - $info['exporteduser'] = self::$uid; + $info['hash'] = $hash; + $info['exporteduser'] = self::$uid; } if( !is_array( $array ) ){ - OC_Log::write( 'migration', 'Supplied $array was not an array in getExportInfo()', OC_Log::ERROR ); + OC_Log::write( 'migration', 'Supplied $array was not an array in getExportInfo()', OC_Log::ERROR ); } // Merge in other data $info = array_merge( $info, (array)$array ); @@ -476,9 +477,9 @@ class OC_Migrate{ $json = json_encode( $info ); return $json; } - + /** - * @breif connects to migration.db, or creates if not found + * @brief connects to migration.db, or creates if not found * @param $db optional path to migration.db, defaults to user data dir * @return bool whether the operation was successful */ @@ -487,19 +488,19 @@ class OC_Migrate{ self::$dbpath = !is_null( $path ) ? $path : self::$dbpath; if( !self::$dbpath ){ OC_Log::write( 'migration', 'connectDB() was called without dbpath being set', OC_Log::ERROR ); - return false; + return false; } // Already connected if(!self::$MDB2){ require_once('MDB2.php'); - + $datadir = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ); - + // DB type if( class_exists( 'SQLite3' ) ){ $dbtype = 'sqlite3'; } else if( is_callable( 'sqlite_open' ) ){ - $dbtype = 'sqlite'; + $dbtype = 'sqlite'; } else { OC_Log::write( 'migration', 'SQLite not found', OC_Log::ERROR ); return false; @@ -533,53 +534,53 @@ class OC_Migrate{ self::$MDB2->setFetchMode(MDB2_FETCHMODE_ASSOC); } return true; - + } - + /** - * @breif creates the tables in migration.db from an apps database.xml + * @brief creates the tables in migration.db from an apps database.xml * @param $appid string id of the app * @return bool whether the operation was successful */ static private function createAppTables( $appid ){ - + if( !self::connectScheme() ){ - return false; + return false; } - - // There is a database.xml file + + // There is a database.xml file $content = file_get_contents( OC::$SERVERROOT . '/apps/' . $appid . '/appinfo/database.xml' ); - + $file2 = 'static://db_scheme'; // TODO get the relative path to migration.db from the data dir // For now just cheat $path = pathinfo( self::$dbpath ); $content = str_replace( '*dbname*', self::$uid.'/migration', $content ); $content = str_replace( '*dbprefix*', '', $content ); - + $xml = new SimpleXMLElement($content); foreach($xml->table as $table){ - $tables[] = (string)$table->name; - } - + $tables[] = (string)$table->name; + } + file_put_contents( $file2, $content ); - + // Try to create tables $definition = self::$schema->parseDatabaseDefinitionFile( $file2 ); unlink( $file2 ); - + // Die in case something went wrong if( $definition instanceof MDB2_Schema_Error ){ OC_Log::write( 'migration', 'Failed to parse database.xml for: '.$appid, OC_Log::FATAL ); OC_Log::write( 'migration', $definition->getMessage().': '.$definition->getUserInfo(), OC_Log::FATAL ); return false; } - + $definition['overwrite'] = true; - + $ret = self::$schema->createDatabase( $definition ); - + // Die in case something went wrong if( $ret instanceof MDB2_Error ){ OC_Log::write( 'migration', 'Failed to create tables for: '.$appid, OC_Log::FATAL ); @@ -591,7 +592,7 @@ class OC_Migrate{ } /** - * @breif tries to create the zip + * @brief tries to create the zip * @param $path string path to zip destination * @return bool */ @@ -600,18 +601,18 @@ class OC_Migrate{ // Check if properties are set if( !self::$zippath ){ OC_Log::write('migration', 'createZip() called but $zip and/or $zippath have not been set', OC_Log::ERROR); - return false; + return false; } if ( self::$zip->open( self::$zippath, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE ) !== TRUE ) { OC_Log::write('migration', 'Failed to create the zip with error: '.self::$zip->getStatusString(), OC_Log::ERROR); return false; } else { - return true; - } + return true; + } } - + /** - * @breif returns an array of apps that support migration + * @brief returns an array of apps that support migration * @return array */ static public function getApps(){ @@ -620,13 +621,13 @@ class OC_Migrate{ $path = OC::$SERVERROOT . '/apps/' . $app . '/lib/migrate.php'; if( file_exists( $path ) ){ $supportsmigration[] = $app; - } + } } - return $supportsmigration; + return $supportsmigration; } - + /** - * @breif imports a new user + * @brief imports a new user * @param $db string path to migration.db * @param $info object of migration info * @param $uid optional uid to use @@ -639,76 +640,76 @@ class OC_Migrate{ if(!self::connectDB( $db )){ OC_Log::write('migration','Failed to connect to migration.db',OC_Log::ERROR); return false; - } + } } else { - OC_Log::write('migration','Migration.db not found at: '.$db, OC_Log::FATAL ); + OC_Log::write('migration','Migration.db not found at: '.$db, OC_Log::FATAL ); return false; } - + // Find providers self::findProviders(); // Generate importinfo array - $importinfo = array( + $importinfo = array( 'olduid' => $info->exporteduser, 'newuid' => self::$uid ); - + foreach( self::$providers as $provider){ // Is the app in the export? $id = $provider->getID(); if( isset( $info->apps->$id ) ){ // Is the app installed if( !OC_App::isEnabled( $id ) ){ - OC_Log::write( 'migration', 'App: ' . $id . ' is not installed, can\'t import data.', OC_Log::INFO ); - $appsstatus[$id] = 'notsupported'; + OC_Log::write( 'migration', 'App: ' . $id . ' is not installed, can\'t import data.', OC_Log::INFO ); + $appsstatus[$id] = 'notsupported'; } else { // Did it succeed on export? if( $info->apps->$id->success ){ // Give the provider the content object if( !self::connectDB( $db ) ){ - return false; + return false; } $content = new OC_Migration_Content( self::$zip, self::$MDB2 ); $provider->setData( self::$uid, $content, $info ); // Then do the import if( !$appsstatus[$id] = $provider->import( $info->apps->$id, $importinfo ) ){ // Failed to import app - OC_Log::write( 'migration', 'Failed to import app data for user: ' . self::$uid . ' for app: ' . $id, OC_Log::ERROR ); + OC_Log::write( 'migration', 'Failed to import app data for user: ' . self::$uid . ' for app: ' . $id, OC_Log::ERROR ); } } else { // Add to failed list - $appsstatus[$id] = false; + $appsstatus[$id] = false; } - } - } + } + } } - + return $appsstatus; - + } - + /* - * @breif creates a new user in the database + * @brief creates a new user in the database * @param $uid string user_id of the user to be created * @param $hash string hash of the user to be created * @return bool result of user creation */ public static function createUser( $uid, $hash ){ - + // Check if userid exists if(OC_User::userExists( $uid )){ return false; } - + // Create the user $query = OC_DB::prepare( "INSERT INTO `*PREFIX*users` ( `uid`, `password` ) VALUES( ?, ? )" ); $result = $query->execute( array( $uid, $hash)); if( !$result ){ - OC_Log::write('migration', 'Failed to create the new user "'.$uid.""); + OC_Log::write('migration', 'Failed to create the new user "'.$uid.""); } return $result ? true : false; - + } } diff --git a/lib/migration/content.php b/lib/migration/content.php index d304051f3e6..7ef88f36e43 100644 --- a/lib/migration/content.php +++ b/lib/migration/content.php @@ -33,7 +33,7 @@ class OC_Migration_Content{ private $tmpfiles=false; /** - * @breif sets up the + * @brief sets up the * @param $zip ZipArchive object * @param optional $db a MDB2 database object (required for exporttype user) * @return bool @@ -51,7 +51,7 @@ class OC_Migration_Content{ } - // @breif prepares the db + // @brief prepares the db // @param $query the sql query to prepare public function prepare( $query ){ @@ -74,7 +74,7 @@ class OC_Migration_Content{ } /** - * @breif processes the db query + * @brief processes the db query * @param $query the query to process * @return string of processed query */ @@ -130,7 +130,7 @@ class OC_Migration_Content{ } /** - * @breif saves a sql data set into migration.db + * @brief saves a sql data set into migration.db * @param $data a sql data set returned from self::prepare()->query() * @param $options array of copyRows options * @return void @@ -175,7 +175,7 @@ class OC_Migration_Content{ } /** - * @breif adds a directory to the zip object + * @brief adds a directory to the zip object * @param $dir string path of the directory to add * @param $recursive bool * @param $internaldir string path of folder to add dir to in zip @@ -209,7 +209,7 @@ class OC_Migration_Content{ } /** - * @breif adds a file to the zip from a given string + * @brief adds a file to the zip from a given string * @param $data string of data to add * @param $path the relative path inside of the zip to save the file to * @return bool @@ -228,7 +228,7 @@ class OC_Migration_Content{ } /** - * @breif closes the zip, removes temp files + * @brief closes the zip, removes temp files * @return bool */ public function finish(){ @@ -241,7 +241,7 @@ class OC_Migration_Content{ } /** - * @breif cleans up after the zip + * @brief cleans up after the zip */ private function cleanup(){ // Delete tmp files @@ -249,4 +249,4 @@ class OC_Migration_Content{ unlink( $i ); } } -}
\ No newline at end of file +} diff --git a/lib/migration/provider.php b/lib/migration/provider.php index feae29f1354..91336f3019d 100644 --- a/lib/migration/provider.php +++ b/lib/migration/provider.php @@ -17,19 +17,19 @@ abstract class OC_Migration_Provider{ } /** - * @breif exports data for apps + * @brief exports data for apps * @return array appdata to be exported */ abstract function export( ); /** - * @breif imports data for the app + * @brief imports data for the app * @return void */ abstract function import( ); /** - * @breif sets the OC_Migration_Content object to $this->content + * @brief sets the OC_Migration_Content object to $this->content * @param $content a OC_Migration_Content object */ public function setData( $uid, $content, $info=null ){ @@ -43,7 +43,7 @@ abstract class OC_Migration_Provider{ } /** - * @breif returns the appid of the provider + * @brief returns the appid of the provider * @return string */ public function getID(){ diff --git a/lib/mimetypes.list.php b/lib/mimetypes.list.php index e0570e84ea5..ccf47999b1c 100644 --- a/lib/mimetypes.list.php +++ b/lib/mimetypes.list.php @@ -21,7 +21,7 @@ */ /** - * list of mimetypes by extention + * list of mimetypes by extension */ return array( diff --git a/lib/remote/cloud.php b/lib/remote/cloud.php deleted file mode 100644 index a9c74e8bf5f..00000000000 --- a/lib/remote/cloud.php +++ /dev/null @@ -1,204 +0,0 @@ -<?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=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=get_temp_dir().'/remoteCloudCookie'.uniqid(); - } - $tmpfile=tempnam(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){ - $source=$sourceDir.'/'.$sourceFile; - $tmp=OC_Filesystem::toTmpFile($source); - return $this->sendTmpFile($tmp,$targetDir,$targetFile); - } - - public function sendTmpFile($tmp,$targetDir,$targetFile){ - $token=sha1(uniqid().$tmp); - $file=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'] . OC::$WEBROOT; - }else{ - $url = "http://". $_SERVER['SERVER_NAME'] . OC::$WEBROOT; - } - return $this->apiCall('pull',array('dir'=>$targetDir,'file'=>$targetFile,'token'=>$token,'source'=>$url),true); - } -} - diff --git a/lib/search.php b/lib/search.php index 6b33fa38140..12055418687 100644 --- a/lib/search.php +++ b/lib/search.php @@ -26,13 +26,22 @@ */ class OC_Search{ static private $providers=array(); + static private $registeredProviders=array(); + + /** + * remove all registered search providers + */ + public static function clearProviders(){ + self::$providers=array(); + self::$registeredProviders=array(); + } /** * register a new search provider to be used * @param string $provider class name of a OC_Search_Provider */ - public static function registerProvider($provider){ - self::$providers[]=$provider; + public static function registerProvider($class,$options=array()){ + self::$registeredProviders[]=array('class'=>$class,'options'=>$options); } /** @@ -41,10 +50,25 @@ class OC_Search{ * @return array An array of OC_Search_Result's */ public static function search($query){ + self::initProviders(); $results=array(); foreach(self::$providers as $provider){ - $results=array_merge($results, $provider::search($query)); + $results=array_merge($results, $provider->search($query)); } return $results; } + + /** + * create instances of all the registered search providers + */ + private static function initProviders(){ + if(count(self::$providers)>0){ + return; + } + foreach(self::$registeredProviders as $provider){ + $class=$provider['class']; + $options=$provider['options']; + self::$providers[]=new $class($options); + } + } } diff --git a/lib/search/provider.php b/lib/search/provider.php index 9487ca51f2b..838ab696d04 100644 --- a/lib/search/provider.php +++ b/lib/search/provider.php @@ -2,11 +2,13 @@ /** * provides search functionalty */ -interface OC_Search_Provider { +class OC_Search_Provider { + public function __construct($options){} + /** * search for $query * @param string $query * @return array An array of OC_Search_Result's */ - static function search($query); + public function search($query){} } diff --git a/lib/search/provider/file.php b/lib/search/provider/file.php index 3bdb3bcd2af..a37af495599 100644 --- a/lib/search/provider/file.php +++ b/lib/search/provider/file.php @@ -1,7 +1,7 @@ <?php -class OC_Search_Provider_File implements OC_Search_Provider{ - static function search($query){ +class OC_Search_Provider_File extends OC_Search_Provider{ + function search($query){ $files=OC_FileCache::search($query,true); $results=array(); foreach($files as $fileData){ diff --git a/lib/setup.php b/lib/setup.php index 3e46a3dcc9a..3dca3c50918 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -296,15 +296,21 @@ class OC_Setup { * create .htaccess files for apache hosts */ private static function createHtaccess() { + $content = "ErrorDocument 403 ".OC::$WEBROOT."/core/templates/403.php\n";//custom 403 error page $content = "ErrorDocument 404 ".OC::$WEBROOT."/core/templates/404.php\n";//custom 404 error page $content.= "<IfModule mod_php5.c>\n"; $content.= "php_value upload_max_filesize 512M\n";//upload limit $content.= "php_value post_max_size 512M\n"; - $content.= "SetEnv htaccessWorking true\n"; + $content.= "php_value memory_limit 512M\n"; + $content.= "<IfModule env_module>\n"; + $content.= " SetEnv htaccessWorking true\n"; + $content.= "</IfModule>\n"; $content.= "</IfModule>\n"; $content.= "<IfModule mod_rewrite.c>\n"; $content.= "RewriteEngine on\n"; $content.= "RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization},last]\n"; + $content.= "RewriteRule ^.well-known/carddav /apps/contacts/carddav.php [R]\n"; + $content.= "RewriteRule ^.well-known/caldav /apps/calendar/caldav.php [R]\n"; $content.= "</IfModule>\n"; $content.= "Options -Indexes\n"; @file_put_contents(OC::$SERVERROOT.'/.htaccess', $content); //supress errors in case we don't have permissions for it diff --git a/lib/template.php b/lib/template.php index 5bcf52b9321..eeba2410b68 100644 --- a/lib/template.php +++ b/lib/template.php @@ -76,7 +76,7 @@ function simple_file_size($bytes) { } function relative_modified_date($timestamp) { - $l=new OC_L10N('template'); + $l=OC_L10N::get('template'); $timediff = time() - $timestamp; $diffminutes = round($timediff/60); $diffhours = round($diffminutes/60); @@ -155,13 +155,13 @@ class OC_Template{ $this->renderas = $renderas; $this->application = $app; $this->vars = array(); - $this->l10n = new OC_L10N($app); + $this->l10n = OC_L10N::get($app); $this->findTemplate($name); } /** - * @brief Returns the formfactor extention for current formfactor + * @brief Returns the formfactor extension for current formfactor */ protected function getFormFactorExtension() { diff --git a/lib/updater.php b/lib/updater.php index 196822ac35d..deb0f05945e 100644 --- a/lib/updater.php +++ b/lib/updater.php @@ -59,9 +59,9 @@ class OC_Updater{ public static function ShowUpdatingHint(){ $data=OC_Updater::check(); if(isset($data['version']) and $data['version']<>'') { - $txt='<span style="color:#AA0000; font-weight:bold;">'.$data['versionstring'].' is available. Please click <a href="'.$data['web'].'">here</a> for more information</span>'; + $txt='<span style="color:#AA0000; font-weight:bold;">'.$data['versionstring'].' is available. Get <a href="'.$data['web'].'">more information</a></span>'; }else{ - $txt='Your ownCloud is up to date'; + $txt='up to date'; } return($txt); } diff --git a/lib/user/database.php b/lib/user/database.php index 3eade276dd9..c1bac1bb0b5 100644 --- a/lib/user/database.php +++ b/lib/user/database.php @@ -172,7 +172,7 @@ class OC_User_Database extends OC_User_Backend { * @return boolean */ public function userExists($uid){ - $query = OC_DB::prepare( "SELECT * FROM `*PREFIX*users` WHERE uid = ?" ); + $query = OC_DB::prepare( "SELECT * FROM `*PREFIX*users` WHERE uid LIKE ?" ); $result = $query->execute( array( $uid )); return $result->numRows() > 0; diff --git a/lib/user/dummy.php b/lib/user/dummy.php new file mode 100644 index 00000000000..cfc96c5c52d --- /dev/null +++ b/lib/user/dummy.php @@ -0,0 +1,114 @@ +<?php + +/** +* ownCloud +* +* @author Frank Karlitschek +* @copyright 2010 Frank Karlitschek karlitschek@kde.org +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Affero General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ + +/** + * dummy user backend, does not keep state, only for testing use + */ +class OC_User_Dummy extends OC_User_Backend { + private $users=array(); + /** + * @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 + * itself, not in its subclasses. + */ + public function createUser($uid, $password){ + if(isset($this->users[$uid])){ + return false; + }else{ + $this->users[$uid]=$password; + return true; + } + } + + /** + * @brief delete a user + * @param $uid The username of the user to delete + * @returns true/false + * + * Deletes a user + */ + public function deleteUser( $uid ){ + if(isset($this->users[$uid])){ + unset($this->users[$uid]); + return true; + }else{ + return false; + } + } + + /** + * @brief Set password + * @param $uid The username + * @param $password The new password + * @returns true/false + * + * Change the password of a user + */ + public function setPassword($uid, $password){ + if(isset($this->users[$uid])){ + $this->users[$uid]=$password; + return true; + }else{ + return false; + } + } + + /** + * @brief Check if the password is correct + * @param $uid The username + * @param $password The password + * @returns true/false + * + * Check if the password is correct without logging in the user + */ + public function checkPassword($uid, $password){ + if(isset($this->users[$uid])){ + return ($this->users[$uid]==$password); + }else{ + return false; + } + } + + /** + * @brief Get a list of all users + * @returns array with all uids + * + * Get a list of all users. + */ + public function getUsers(){ + return array_keys($this->users); + } + + /** + * @brief check if a user exists + * @param string $uid the username + * @return boolean + */ + public function userExists($uid){ + return isset($this->users[$uid]); + } +} diff --git a/lib/util.php b/lib/util.php index 34f535d2d5c..2ea392ec31d 100644 --- a/lib/util.php +++ b/lib/util.php @@ -25,7 +25,7 @@ class OC_Util { $success=@mkdir($CONFIG_DATADIRECTORY_ROOT); if(!$success) { $tmpl = new OC_Template( '', 'error', 'guest' ); - $tmpl->assign('errors',array(1=>array('error'=>"Can't create data directory (".$CONFIG_DATADIRECTORY_ROOT.")",'hint'=>"You can usually fix this by giving the webserver write access to the ownCloud directory '".OC::$SERVERROOT."' "))); + $tmpl->assign('errors',array(1=>array('error'=>"Can't create data directory (".$CONFIG_DATADIRECTORY_ROOT.")",'hint'=>"You can usually fix this by giving the webserver write access to the ownCloud directory '".OC::$SERVERROOT."' (in a terminal, use the command 'chown -R www-data:www-data /path/to/your/owncloud/install/data' "))); $tmpl->printPage(); exit; } |