diff options
author | Robin Appelman <icewind@owncloud.com> | 2012-09-22 14:28:14 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2012-09-22 14:28:14 +0200 |
commit | 93292516d9a44bb16a19093f38d3fbd562d27133 (patch) | |
tree | 3b3c5059eb27ccfd08d5fb47a68dac497f84ecc0 /lib | |
parent | 954596c251cb3132878d8d5eafcc37c47b3f520e (diff) | |
parent | b4de89e6b4c05ddb99010e0dee071c919d338d5e (diff) | |
download | nextcloud-server-93292516d9a44bb16a19093f38d3fbd562d27133.tar.gz nextcloud-server-93292516d9a44bb16a19093f38d3fbd562d27133.zip |
Merge branch 'master' into filesystem
Diffstat (limited to 'lib')
56 files changed, 1263 insertions, 824 deletions
diff --git a/lib/app.php b/lib/app.php index 28f1f16ebaf..288f82d054b 100755 --- a/lib/app.php +++ b/lib/app.php @@ -397,10 +397,11 @@ class OC_App{ } /** - * @brief Read app metadata from the info.xml file + * @brief Read all app metadata from the info.xml file * @param string $appid id of the app or the path of the info.xml file * @param boolean path (optional) * @returns array + * @note all data is read from info.xml, not just pre-defined fields */ public static function getAppInfo($appid,$path=false) { if($path) { @@ -442,6 +443,7 @@ class OC_App{ } } self::$appInfo[$appid]=$data; + return $data; } @@ -521,20 +523,90 @@ class OC_App{ } /** - * get a list of all apps in the apps folder + * @brief: get a list of all apps in the apps folder + * @return array or app names (string IDs) + * @todo: change the name of this method to getInstalledApps, which is more accurate */ public static function getAllApps() { + $apps=array(); - foreach(OC::$APPSROOTS as $apps_dir) { - $dh=opendir($apps_dir['path']); - while($file=readdir($dh)) { - if($file[0]!='.' and is_file($apps_dir['path'].'/'.$file.'/appinfo/app.php')) { - $apps[]=$file; + + foreach ( OC::$APPSROOTS as $apps_dir ) { + if(! is_readable($apps_dir['path'])) { + OC_Log::write('core', 'unable to read app folder : ' .$apps_dir['path'] , OC_Log::WARN); + continue; + } + $dh = opendir( $apps_dir['path'] ); + + while( $file = readdir( $dh ) ) { + + if ( + $file[0] != '.' + and is_file($apps_dir['path'].'/'.$file.'/appinfo/app.php' ) + ) { + + $apps[] = $file; + } + } + } + return $apps; } + + /** + * @brief: get a list of all apps on apps.owncloud.com + * @return multi-dimensional array of apps. Keys: id, name, type, typename, personid, license, detailpage, preview, changed, description + */ + public static function getAppstoreApps( $filter = 'approved' ) { + + $catagoryNames = OC_OCSClient::getCategories(); + + if ( is_array( $catagoryNames ) ) { + + // Check that categories of apps were retrieved correctly + if ( ! $categories = array_keys( $catagoryNames ) ) { + + return false; + + } + + $page = 0; + + $remoteApps = OC_OCSClient::getApplications( $categories, $page, $filter ); + + $app1 = array(); + + $i = 0; + + foreach ( $remoteApps as $app ) { + + $app1[$i] = $app; + + $app1[$i]['author'] = $app['personid']; + + $app1[$i]['ocs_id'] = $app['id']; + + $app1[$i]['internal'] = $app1[$i]['active'] = 0; + + $i++; + + } + + } + + if ( empty( $app1 ) ) { + + return false; + + } else { + + return $app1; + + } + } /** * check if the app need updating and update when needed @@ -550,7 +622,13 @@ class OC_App{ $installedVersion = $versions[$app]; if (version_compare($currentVersion, $installedVersion, '>')) { OC_Log::write($app, 'starting app upgrade from '.$installedVersion.' to '.$currentVersion, OC_Log::DEBUG); - OC_App::updateApp($app); + try { + OC_App::updateApp($app); + } + catch (Exception $e) { + echo 'Failed to upgrade "'.$app.'". Exception="'.$e->getMessage().'"'; + die; + } OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app)); } } @@ -640,7 +718,7 @@ class OC_App{ } }else{ OC_Log::write('core', 'Can\'t get app storage, app '.$appid.' not enabled', OC_Log::ERROR); - false; + return false; } } } diff --git a/lib/archive/tar.php b/lib/archive/tar.php index ebd581fc162..639d2392b63 100644 --- a/lib/archive/tar.php +++ b/lib/archive/tar.php @@ -6,7 +6,7 @@ * See the COPYING-README file. */ -require_once '3rdparty/Archive/Tar.php'; +require_once 'Archive/Tar.php'; class OC_Archive_TAR extends OC_Archive{ const PLAIN=0; @@ -24,7 +24,7 @@ class OC_Archive_TAR extends OC_Archive{ function __construct($source) { $types=array(null,'gz','bz'); $this->path=$source; - $this->tar=new Archive_Tar($source,$types[self::getTarType($source)]); + $this->tar=new Archive_Tar($source, $types[self::getTarType($source)]); } /** @@ -33,8 +33,8 @@ class OC_Archive_TAR extends OC_Archive{ * @return str */ static public function getTarType($file) { - if(strpos($file,'.')) { - $extension=substr($file,strrpos($file,'.')); + if(strpos($file, '.')) { + $extension=substr($file, strrpos($file, '.')); switch($extension) { case 'gz': case 'tgz': @@ -57,13 +57,13 @@ class OC_Archive_TAR extends OC_Archive{ */ function addFolder($path) { $tmpBase=OC_Helper::tmpFolder(); - if(substr($path,-1,1)!='/') { + if(substr($path, -1, 1)!='/') { $path.='/'; } if($this->fileExists($path)) { return false; } - $parts=explode('/',$path); + $parts=explode('/', $path); $folder=$tmpBase; foreach($parts as $part) { $folder.='/'.$part; @@ -71,7 +71,7 @@ class OC_Archive_TAR extends OC_Archive{ mkdir($folder); } } - $result=$this->tar->addModify(array($tmpBase.$path),'',$tmpBase); + $result=$this->tar->addModify(array($tmpBase.$path), '', $tmpBase); rmdir($tmpBase.$path); $this->fileList=false; return $result; @@ -90,9 +90,9 @@ class OC_Archive_TAR extends OC_Archive{ $header=array(); $dummy=''; $this->tar->_openAppend(); - $result=$this->tar->_addfile($source,$header,$dummy,$dummy,$path); + $result=$this->tar->_addfile($source, $header, $dummy, $dummy, $path); }else{ - $result=$this->tar->addString($path,$source); + $result=$this->tar->addString($path, $source); } $this->fileList=false; return $result; @@ -108,12 +108,12 @@ class OC_Archive_TAR extends OC_Archive{ //no proper way to delete, rename entire archive, rename file and remake archive $tmp=OCP\Files::tmpFolder(); $this->tar->extract($tmp); - rename($tmp.$source,$tmp.$dest); + rename($tmp.$source, $tmp.$dest); $this->tar=null; unlink($this->path); - $types=array(null,'gz','bz'); - $this->tar=new Archive_Tar($this->path,$types[self::getTarType($this->path)]); - $this->tar->createModify(array($tmp),'',$tmp.'/'); + $types=array(null, 'gz', 'bz'); + $this->tar=new Archive_Tar($this->path, $types[self::getTarType($this->path)]); + $this->tar->createModify(array($tmp), '', $tmp.'/'); $this->fileList=false; return true; } @@ -158,14 +158,14 @@ class OC_Archive_TAR extends OC_Archive{ $pathLength=strlen($path); foreach($files as $file) { if($file[0]=='/') { - $file=substr($file,1); + $file=substr($file, 1); } - if(substr($file,0,$pathLength)==$path and $file!=$path) { - $result=substr($file,$pathLength); - if($pos=strpos($result,'/')) { - $result=substr($result,0,$pos+1); + if(substr($file, 0, $pathLength)==$path and $file!=$path) { + $result=substr($file, $pathLength); + if($pos=strpos($result, '/')) { + $result=substr($result, 0, $pos+1); } - if(array_search($result,$folderContent)===false) { + if(array_search($result, $folderContent)===false) { $folderContent[]=$result; } } @@ -208,12 +208,12 @@ class OC_Archive_TAR extends OC_Archive{ return false; } if($this->fileExists('/'.$path)) { - $success=$this->tar->extractList(array('/'.$path),$tmp); + $success=$this->tar->extractList(array('/'.$path), $tmp); }else{ - $success=$this->tar->extractList(array($path),$tmp); + $success=$this->tar->extractList(array($path), $tmp); } if($success) { - rename($tmp.$path,$dest); + rename($tmp.$path, $dest); } OCP\Files::rmdirr($tmp); return $success; @@ -234,16 +234,16 @@ class OC_Archive_TAR extends OC_Archive{ */ function fileExists($path) { $files=$this->getFiles(); - if((array_search($path,$files)!==false) or (array_search($path.'/',$files)!==false)) { + if((array_search($path, $files)!==false) or (array_search($path.'/', $files)!==false)) { return true; }else{ $folderPath=$path; - if(substr($folderPath,-1,1)!='/') { + if(substr($folderPath, -1, 1)!='/') { $folderPath.='/'; } $pathLength=strlen($folderPath); foreach($files as $file) { - if(strlen($file)>$pathLength and substr($file,0,$pathLength)==$folderPath) { + if(strlen($file)>$pathLength and substr($file, 0, $pathLength)==$folderPath) { return true; } } @@ -272,7 +272,7 @@ class OC_Archive_TAR extends OC_Archive{ $this->tar=null; unlink($this->path); $this->reopen(); - $this->tar->createModify(array($tmp),'',$tmp); + $this->tar->createModify(array($tmp), '', $tmp); return true; } /** @@ -282,23 +282,23 @@ class OC_Archive_TAR extends OC_Archive{ * @return resource */ function getStream($path,$mode) { - if(strrpos($path,'.')!==false) { - $ext=substr($path,strrpos($path,'.')); + if(strrpos($path, '.')!==false) { + $ext=substr($path, strrpos($path, '.')); }else{ $ext=''; } $tmpFile=OCP\Files::tmpFile($ext); if($this->fileExists($path)) { - $this->extractFile($path,$tmpFile); + $this->extractFile($path, $tmpFile); }elseif($mode=='r' or $mode=='rb') { return false; } if($mode=='r' or $mode=='rb') { - return fopen($tmpFile,$mode); + return fopen($tmpFile, $mode); }else{ OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack'); self::$tempFiles[$tmpFile]=$path; - return fopen('close://'.$tmpFile,$mode); + return fopen('close://'.$tmpFile, $mode); } } @@ -308,7 +308,7 @@ class OC_Archive_TAR extends OC_Archive{ */ function writeBack($tmpFile) { if(isset(self::$tempFiles[$tmpFile])) { - $this->addFile(self::$tempFiles[$tmpFile],$tmpFile); + $this->addFile(self::$tempFiles[$tmpFile], $tmpFile); unlink($tmpFile); } } @@ -322,6 +322,6 @@ class OC_Archive_TAR extends OC_Archive{ $this->tar=null; } $types=array(null,'gz','bz'); - $this->tar=new Archive_Tar($this->path,$types[self::getTarType($this->path)]); + $this->tar=new Archive_Tar($this->path, $types[self::getTarType($this->path)]); } } diff --git a/lib/archive/zip.php b/lib/archive/zip.php index 45992ee3d89..a2b07f1a35d 100644 --- a/lib/archive/zip.php +++ b/lib/archive/zip.php @@ -16,9 +16,9 @@ class OC_Archive_ZIP extends OC_Archive{ function __construct($source) { $this->path=$source; $this->zip=new ZipArchive(); - if($this->zip->open($source,ZipArchive::CREATE)) { + if($this->zip->open($source, ZipArchive::CREATE)) { }else{ - OCP\Util::writeLog('files_archive','Error while opening archive '.$source,OCP\Util::WARN); + OCP\Util::writeLog('files_archive', 'Error while opening archive '.$source, OCP\Util::WARN); } } /** @@ -37,9 +37,9 @@ class OC_Archive_ZIP extends OC_Archive{ */ function addFile($path,$source='') { if($source and $source[0]=='/' and file_exists($source)) { - $result=$this->zip->addFile($source,$path); + $result=$this->zip->addFile($source, $path); }else{ - $result=$this->zip->addFromString($path,$source); + $result=$this->zip->addFromString($path, $source); } if($result) { $this->zip->close();//close and reopen to save the zip @@ -56,7 +56,7 @@ class OC_Archive_ZIP extends OC_Archive{ function rename($source,$dest) { $source=$this->stripPath($source); $dest=$this->stripPath($dest); - $this->zip->renameName($source,$dest); + $this->zip->renameName($source, $dest); } /** * get the uncompressed size of a file in the archive @@ -85,9 +85,9 @@ class OC_Archive_ZIP extends OC_Archive{ $folderContent=array(); $pathLength=strlen($path); foreach($files as $file) { - if(substr($file,0,$pathLength)==$path and $file!=$path) { - if(strrpos(substr($file,0,-1),'/')<=$pathLength) { - $folderContent[]=substr($file,$pathLength); + if(substr($file, 0, $pathLength)==$path and $file!=$path) { + if(strrpos(substr($file, 0, -1),'/')<=$pathLength) { + $folderContent[]=substr($file, $pathLength); } } } @@ -121,7 +121,7 @@ class OC_Archive_ZIP extends OC_Archive{ */ function extractFile($path,$dest) { $fp = $this->zip->getStream($path); - file_put_contents($dest,$fp); + file_put_contents($dest, $fp); } /** * extract the archive @@ -162,18 +162,18 @@ class OC_Archive_ZIP extends OC_Archive{ if($mode=='r' or $mode=='rb') { return $this->zip->getStream($path); }else{//since we cant directly get a writable stream, make a temp copy of the file and put it back in the archive when the stream is closed - if(strrpos($path,'.')!==false) { - $ext=substr($path,strrpos($path,'.')); + if(strrpos($path, '.')!==false) { + $ext=substr($path, strrpos($path, '.')); }else{ $ext=''; } $tmpFile=OCP\Files::tmpFile($ext); OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack'); if($this->fileExists($path)) { - $this->extractFile($path,$tmpFile); + $this->extractFile($path, $tmpFile); } self::$tempFiles[$tmpFile]=$path; - return fopen('close://'.$tmpFile,$mode); + return fopen('close://'.$tmpFile, $mode); } } @@ -183,14 +183,14 @@ class OC_Archive_ZIP extends OC_Archive{ */ function writeBack($tmpFile) { if(isset(self::$tempFiles[$tmpFile])) { - $this->addFile(self::$tempFiles[$tmpFile],$tmpFile); + $this->addFile(self::$tempFiles[$tmpFile], $tmpFile); unlink($tmpFile); } } private function stripPath($path) { if(!$path || $path[0]=='/') { - return substr($path,1); + return substr($path, 1); }else{ return $path; } diff --git a/lib/base.php b/lib/base.php index 3b2ab8d5ebe..7a09946b9db 100644 --- a/lib/base.php +++ b/lib/base.php @@ -75,7 +75,7 @@ class OC{ /** @TODO: Remove this when necessary Remove "apps/" from inclusion path for smooth migration to mutli app dir */ - $path = preg_replace('/apps\//', '', OC::$CLASSPATH[$className]); + $path = str_replace('apps/', '', OC::$CLASSPATH[$className]); require_once $path; } elseif(strpos($className, 'OC_')===0) { @@ -222,8 +222,10 @@ class OC{ $tmpl->printPage(); exit; } - OC_Minimizer::clearCache(); - + $minimizerCSS = new OC_Minimizer_CSS(); + $minimizerCSS->clearCache(); + $minimizerJS = new OC_Minimizer_JS(); + $minimizerJS->clearCache(); OC_Config::setValue('version', implode('.', OC_Util::getVersion())); OC_App::checkAppsRequirements(); // load all apps to also upgrade enabled apps diff --git a/lib/cache/file.php b/lib/cache/file.php index a4f83f76c94..27d8b19f36e 100644 --- a/lib/cache/file.php +++ b/lib/cache/file.php @@ -22,7 +22,7 @@ class OC_Cache_File{ $this->storage = new OC_FilesystemView('/'.OC_User::getUser().'/'.$subdir); return $this->storage; }else{ - OC_Log::write('core','Can\'t get cache storage, user not logged in', OC_Log::ERROR); + OC_Log::write('core', 'Can\'t get cache storage, user not logged in', OC_Log::ERROR); return false; } } diff --git a/lib/cache/xcache.php b/lib/cache/xcache.php index 0739e4a2fa2..cecdf46351c 100644 --- a/lib/cache/xcache.php +++ b/lib/cache/xcache.php @@ -29,9 +29,9 @@ class OC_Cache_XCache { public function set($key, $value, $ttl=0) { if($ttl>0) { - return xcache_set($this->getNamespace().$key,$value,$ttl); + return xcache_set($this->getNamespace().$key, $value, $ttl); }else{ - return xcache_set($this->getNamespace().$key,$value); + return xcache_set($this->getNamespace().$key, $value); } } diff --git a/lib/connector/sabre/auth.php b/lib/connector/sabre/auth.php index 34fc5fee50c..0c34c7ea29f 100644 --- a/lib/connector/sabre/auth.php +++ b/lib/connector/sabre/auth.php @@ -36,7 +36,7 @@ class OC_Connector_Sabre_Auth extends Sabre_DAV_Auth_Backend_AbstractBasic { return true; } else { OC_Util::setUpFS();//login hooks may need early access to the filesystem - if(OC_User::login($username,$password)) { + if(OC_User::login($username, $password)) { OC_Util::setUpFS($username); return true; } diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php index 8fff77ac749..413efef73b7 100644 --- a/lib/connector/sabre/directory.php +++ b/lib/connector/sabre/directory.php @@ -50,17 +50,19 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa public function createFile($name, $data = null) { if (isset($_SERVER['HTTP_OC_CHUNKED'])) { $info = OC_FileChunking::decodeName($name); + if (empty($info)) { + throw new Sabre_DAV_Exception_NotImplemented(); + } $chunk_handler = new OC_FileChunking($info); $chunk_handler->store($info['index'], $data); if ($chunk_handler->isComplete()) { $newPath = $this->path . '/' . $info['name']; - $f = OC_Filesystem::fopen($newPath, 'w'); - $chunk_handler->assemble($f); + $chunk_handler->file_assemble($newPath); return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath); } } else { $newPath = $this->path . '/' . $name; - OC_Filesystem::file_put_contents($newPath,$data); + OC_Filesystem::file_put_contents($newPath, $data); return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath); } @@ -91,10 +93,12 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa $path = $this->path . '/' . $name; if (is_null($info)) { - $info = OC_FileCache::get($path); + $info = OC_Files::getFileInfo($path); } - if (!$info) throw new Sabre_DAV_Exception_NotFound('File with name ' . $path . ' could not be located'); + if (!$info) { + throw new Sabre_DAV_Exception_NotFound('File with name ' . $path . ' could not be located'); + } if ($info['mimetype'] == 'httpd/unix-directory') { $node = new OC_Connector_Sabre_Directory($path); @@ -113,7 +117,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa */ public function getChildren() { - $folder_content = OC_FileCache::getFolderContent($this->path); + $folder_content = OC_Files::getDirectoryContent($this->path); $paths = array(); foreach($folder_content as $info) { $paths[] = $this->path.'/'.$info['name']; @@ -195,10 +199,9 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa */ public function getProperties($properties) { $props = parent::getProperties($properties); - if (in_array(self::GETETAG_PROPERTYNAME, $properties) - && !isset($props[self::GETETAG_PROPERTYNAME])) { - $props[self::GETETAG_PROPERTYNAME] = - OC_Connector_Sabre_Node::getETagPropertyForPath($this->path); + if (in_array(self::GETETAG_PROPERTYNAME, $properties) && !isset($props[self::GETETAG_PROPERTYNAME])) { + $props[self::GETETAG_PROPERTYNAME] + = OC_Connector_Sabre_Node::getETagPropertyForPath($this->path); } return $props; } diff --git a/lib/connector/sabre/node.php b/lib/connector/sabre/node.php index 2916575e2d5..ecbbef81292 100644 --- a/lib/connector/sabre/node.php +++ b/lib/connector/sabre/node.php @@ -235,7 +235,7 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr static public function removeETagPropertyForPath($path) { // remove tags from this and parent paths $paths = array(); - while ($path != '/' && $path != '') { + while ($path != '/' && $path != '.' && $path != '') { $paths[] = $path; $path = dirname($path); } diff --git a/lib/connector/sabre/principal.php b/lib/connector/sabre/principal.php index cfc72eda9f9..ee95ae63306 100644 --- a/lib/connector/sabre/principal.php +++ b/lib/connector/sabre/principal.php @@ -66,7 +66,7 @@ class OC_Connector_Sabre_Principal implements Sabre_DAVACL_IPrincipalBackend { */ public function getGroupMemberSet($principal) { // TODO: for now the group principal has only one member, the user itself - list($prefix,$name) = Sabre_DAV_URLUtil::splitPath($principal); + list($prefix, $name) = Sabre_DAV_URLUtil::splitPath($principal); $principal = $this->getPrincipalByPath($prefix); if (!$principal) throw new Sabre_DAV_Exception('Principal not found'); @@ -115,6 +115,12 @@ class OC_Connector_Sabre_Principal implements Sabre_DAVACL_IPrincipalBackend { public function setGroupMemberSet($principal, array $members) { throw new Sabre_DAV_Exception('Setting members of the group is not supported yet'); } - function updatePrincipal($path, $mutations) {return 0;} - function searchPrincipals($prefixPath, array $searchProperties) {return 0;} + + function updatePrincipal($path, $mutations) { + return 0; + } + + function searchPrincipals($prefixPath, array $searchProperties) { + return 0; + } } diff --git a/lib/db.php b/lib/db.php index ee69e5f8299..42bd04e9880 100644 --- a/lib/db.php +++ b/lib/db.php @@ -187,7 +187,7 @@ class OC_DB { // Prepare options array $options = array( - 'portability' => MDB2_PORTABILITY_ALL & (!MDB2_PORTABILITY_FIX_CASE), + 'portability' => MDB2_PORTABILITY_ALL - MDB2_PORTABILITY_FIX_CASE, 'log_line_break' => '<br>', 'idxname_format' => '%s', 'debug' => true, @@ -226,12 +226,14 @@ class OC_DB { 'phptype' => 'oci8', 'username' => $user, 'password' => $pass, + 'charset' => 'AL32UTF8', ); if ($host != '') { $dsn['hostspec'] = $host; $dsn['database'] = $name; } else { // use dbname for hostspec $dsn['hostspec'] = $name; + $dsn['database'] = $user; } break; } @@ -297,7 +299,7 @@ class OC_DB { // Die if we have an error (error means: bad query, not 0 results!) if( PEAR::isError($result)) { $entry = 'DB Error: "'.$result->getMessage().'"<br />'; - $entry .= 'Offending command was: '.$query.'<br />'; + $entry .= 'Offending command was: '.htmlentities($query).'<br />'; OC_Log::write('core', $entry,OC_Log::FATAL); error_log('DB error: '.$entry); die( $entry ); @@ -307,7 +309,7 @@ class OC_DB { $result=self::$connection->prepare($query); }catch(PDOException $e) { $entry = 'DB Error: "'.$e->getMessage().'"<br />'; - $entry .= 'Offending command was: '.$query.'<br />'; + $entry .= 'Offending command was: '.htmlentities($query).'<br />'; OC_Log::write('core', $entry,OC_Log::FATAL); error_log('DB error: '.$entry); die( $entry ); @@ -457,7 +459,8 @@ class OC_DB { $previousSchema = self::$schema->getDefinitionFromDatabase(); if (PEAR::isError($previousSchema)) { $error = $previousSchema->getMessage(); - OC_Log::write('core', 'Failed to get existing database structure for upgrading ('.$error.')', OC_Log::FATAL); + $detail = $previousSchema->getDebugInfo(); + OC_Log::write('core', 'Failed to get existing database structure for upgrading ('.$error.', '.$detail.')', OC_Log::FATAL); return false; } @@ -649,6 +652,30 @@ class OC_DB { return false; } } + + /** + * returns the error code and message as a string for logging + * works with MDB2 and PDOException + * @param mixed $error + * @return string + */ + public static function getErrorMessage($error) { + if ( self::$backend==self::BACKEND_MDB2 and PEAR::isError($error) ) { + $msg = $error->getCode() . ': ' . $error->getMessage(); + if (defined('DEBUG') && DEBUG) { + $msg .= '(' . $error->getDebugInfo() . ')'; + } + } elseif (self::$backend==self::BACKEND_PDO and self::$PDO) { + $msg = self::$PDO->errorCode() . ': '; + $errorInfo = self::$PDO->errorInfo(); + if (is_array($errorInfo)) { + $msg .= 'SQLSTATE = '.$errorInfo[0] . ', '; + $msg .= 'Driver Code = '.$errorInfo[1] . ', '; + $msg .= 'Driver Message = '.$errorInfo[2]; + } + } + return $msg; + } } /** diff --git a/lib/filecache.php b/lib/filecache.php index adcf97753ed..07099bcccd5 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -481,7 +481,7 @@ class OC_FileCache{ */ public static function clear($user='') { if($user) { - $query=OC_DB::prepare('DELETE FROM `*PREFIX*fscache` WHERE user=?'); + $query=OC_DB::prepare('DELETE FROM `*PREFIX*fscache` WHERE `user`=?'); $query->execute(array($user)); }else{ $query=OC_DB::prepare('DELETE FROM `*PREFIX*fscache`'); diff --git a/lib/filecache/cached.php b/lib/filecache/cached.php index 261bd2f572b..9b1eb4f7803 100644 --- a/lib/filecache/cached.php +++ b/lib/filecache/cached.php @@ -18,11 +18,22 @@ class OC_FileCache_Cached{ $root=OC_Filesystem::getRoot(); } $path=$root.$path; - $query=OC_DB::prepare('SELECT `path`,`ctime`,`mtime`,`mimetype`,`size`,`encrypted`,`versioned`,`writable` FROM `*PREFIX*fscache` WHERE `path_hash`=?'); - $result=$query->execute(array(md5($path)))->fetchRow(); + $stmt=OC_DB::prepare('SELECT `path`,`ctime`,`mtime`,`mimetype`,`size`,`encrypted`,`versioned`,`writable` FROM `*PREFIX*fscache` WHERE `path_hash`=?'); + if ( ! OC_DB::isError($stmt) ) { + $result=$stmt->execute(array(md5($path))); + if ( ! OC_DB::isError($result) ) { + $result = $result->fetchRow(); + } else { + OC:Log::write('OC_FileCache_Cached', 'could not execute get: '. OC_DB::getErrorMessage($result), OC_Log::ERROR); + $result = false; + } + } else { + OC_Log::write('OC_FileCache_Cached', 'could not prepare get: '. OC_DB::getErrorMessage($stmt), OC_Log::ERROR); + $result = false; + } if(is_array($result)) { if(isset(self::$savedData[$path])) { - $result=array_merge($result,self::$savedData[$path]); + $result=array_merge($result, self::$savedData[$path]); } return $result; }else{ @@ -54,7 +65,7 @@ class OC_FileCache_Cached{ if($root===false) { $root=OC_Filesystem::getRoot(); } - $parent=OC_FileCache::getId($path,$root); + $parent=OC_FileCache::getId($path, $root); if($parent==-1) { return array(); } @@ -63,7 +74,7 @@ class OC_FileCache_Cached{ if(is_array($result)) { return $result; }else{ - OC_Log::write('files','getFolderContent(): file not found in cache ('.$path.')',OC_Log::DEBUG); + OC_Log::write('files', 'getFolderContent(): file not found in cache ('.$path.')', OC_Log::DEBUG); return false; } } diff --git a/lib/filecache/update.php b/lib/filecache/update.php index 3d10f5ea7b6..2b64a2a90ff 100644 --- a/lib/filecache/update.php +++ b/lib/filecache/update.php @@ -27,13 +27,13 @@ class OC_FileCache_Update{ if(!$view->file_exists($path)) { return false; } - $cachedData=OC_FileCache_Cached::get($path,$root); + $cachedData=OC_FileCache_Cached::get($path, $root); if(isset($cachedData['mtime'])) { $cachedMTime=$cachedData['mtime']; if($folder) { - return $view->hasUpdated($path.'/',$cachedMTime); + return $view->hasUpdated($path.'/', $cachedMTime); }else{ - return $view->hasUpdated($path,$cachedMTime); + return $view->hasUpdated($path, $cachedMTime); } }else{//file not in cache, so it has to be updated if(($path=='/' or $path=='') and $root===false) {//dont auto update the home folder, it will be scanned @@ -59,9 +59,9 @@ class OC_FileCache_Update{ $file=$view->getRelativePath($path); if(!$view->file_exists($file)) { if($root===false) {//filesystem hooks are only valid for the default root - OC_Hook::emit('OC_Filesystem','post_delete',array('path'=>$file)); + OC_Hook::emit('OC_Filesystem', 'post_delete', array('path'=>$file)); }else{ - self::delete($file,$root); + self::delete($file, $root); } } } @@ -83,24 +83,24 @@ class OC_FileCache_Update{ while (($filename = readdir($dh)) !== false) { if($filename != '.' and $filename != '..') { $file=$path.'/'.$filename; - if(self::hasUpdated($file,$root)) { + if(self::hasUpdated($file, $root)) { if($root===false) {//filesystem hooks are only valid for the default root - OC_Hook::emit('OC_Filesystem','post_write',array('path'=>$file)); + OC_Hook::emit('OC_Filesystem', 'post_write', array('path'=>$file)); }else{ - self::update($file,$root); + self::update($file, $root); } } } } } - self::cleanFolder($path,$root); + self::cleanFolder($path, $root); //update the folder last, so we can calculate the size correctly if($root===false) {//filesystem hooks are only valid for the default root - OC_Hook::emit('OC_Filesystem','post_write',array('path'=>$path)); + OC_Hook::emit('OC_Filesystem', 'post_write', array('path'=>$path)); }else{ - self::update($path,$root); + self::update($path, $root); } } @@ -132,7 +132,7 @@ class OC_FileCache_Update{ public static function fileSystemWatcherRename($params) { $oldPath=$params['oldpath']; $newPath=$params['newpath']; - self::rename($oldPath,$newPath); + self::rename($oldPath, $newPath); } /** @@ -154,24 +154,24 @@ class OC_FileCache_Update{ $cachedSize=isset($cached['size'])?$cached['size']:0; if($view->is_dir($path.'/')) { - if(OC_FileCache::inCache($path,$root)) { - $cachedContent=OC_FileCache_Cached::getFolderContent($path,$root); + if(OC_FileCache::inCache($path, $root)) { + $cachedContent=OC_FileCache_Cached::getFolderContent($path, $root); foreach($cachedContent as $file) { $size+=$file['size']; } $mtime=$view->filemtime($path.'/'); $ctime=$view->filectime($path.'/'); $writable=$view->is_writable($path.'/'); - OC_FileCache::put($path,array('size'=>$size,'mtime'=>$mtime,'ctime'=>$ctime,'mimetype'=>$mimetype,'writable'=>$writable)); + OC_FileCache::put($path, array('size'=>$size,'mtime'=>$mtime,'ctime'=>$ctime,'mimetype'=>$mimetype,'writable'=>$writable)); }else{ $count=0; - OC_FileCache::scan($path,null,$count,$root); + OC_FileCache::scan($path, null, $count, $root); return; //increaseSize is already called inside scan } }else{ - $size=OC_FileCache::scanFile($path,$root); + $size=OC_FileCache::scanFile($path, $root); } - OC_FileCache::increaseSize(dirname($path),$size-$cachedSize,$root); + OC_FileCache::increaseSize(dirname($path), $size-$cachedSize, $root); } /** @@ -180,13 +180,13 @@ class OC_FileCache_Update{ * @param string root (optional) */ public static function delete($path,$root=false) { - $cached=OC_FileCache_Cached::get($path,$root); + $cached=OC_FileCache_Cached::get($path, $root); if(!isset($cached['size'])) { return; } $size=$cached['size']; - OC_FileCache::increaseSize(dirname($path),-$size,$root); - OC_FileCache::delete($path,$root); + OC_FileCache::increaseSize(dirname($path), -$size, $root); + OC_FileCache::delete($path, $root); } /** @@ -196,7 +196,7 @@ class OC_FileCache_Update{ * @param string root (optional) */ public static function rename($oldPath,$newPath,$root=false) { - if(!OC_FileCache::inCache($oldPath,$root)) { + if(!OC_FileCache::inCache($oldPath, $root)) { return; } if($root===false) { @@ -205,10 +205,10 @@ class OC_FileCache_Update{ $view=new OC_FilesystemView($root); } - $cached=OC_FileCache_Cached::get($oldPath,$root); + $cached=OC_FileCache_Cached::get($oldPath, $root); $oldSize=$cached['size']; - OC_FileCache::increaseSize(dirname($oldPath),-$oldSize,$root); - OC_FileCache::increaseSize(dirname($newPath),$oldSize,$root); - OC_FileCache::move($oldPath,$newPath); + OC_FileCache::increaseSize(dirname($oldPath), -$oldSize, $root); + OC_FileCache::increaseSize(dirname($newPath), $oldSize, $root); + OC_FileCache::move($oldPath, $newPath); } }
\ No newline at end of file diff --git a/lib/filechunking.php b/lib/filechunking.php index d03af226d8b..5ab33c77ad7 100644 --- a/lib/filechunking.php +++ b/lib/filechunking.php @@ -55,12 +55,13 @@ class OC_FileChunking { public function assemble($f) { $cache = $this->getCache(); $prefix = $this->getPrefix(); + $count = 0; for($i=0; $i < $this->info['chunkcount']; $i++) { $chunk = $cache->get($prefix.$i); $cache->remove($prefix.$i); - fwrite($f,$chunk); + $count += fwrite($f,$chunk); } - fclose($f); + return $count; } public function signature_split($orgfile, $input) { @@ -91,4 +92,57 @@ class OC_FileChunking { 'count' => $count, ); } + + public function file_assemble($path) { + $absolutePath = OC_Filesystem::normalizePath(OC_Filesystem::getView()->getAbsolutePath($path)); + $data = ''; + // use file_put_contents as method because that best matches what this function does + if (OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data) && OC_Filesystem::isValidPath($path)) { + $path = OC_Filesystem::getView()->getRelativePath($absolutePath); + $exists = OC_Filesystem::file_exists($path); + $run = true; + if(!$exists) { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_create, + array( + OC_Filesystem::signal_param_path => $path, + OC_Filesystem::signal_param_run => &$run + ) + ); + } + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_write, + array( + OC_Filesystem::signal_param_path => $path, + OC_Filesystem::signal_param_run => &$run + ) + ); + if(!$run) { + return false; + } + $target = OC_Filesystem::fopen($path, 'w'); + if($target) { + $count = $this->assemble($target); + fclose($target); + if(!$exists) { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_post_create, + array( OC_Filesystem::signal_param_path => $path) + ); + } + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_post_write, + array( OC_Filesystem::signal_param_path => $path) + ); + OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count); + return $count > 0; + }else{ + return false; + } + } + } } diff --git a/lib/fileproxy/quota.php b/lib/fileproxy/quota.php index adbff3d301a..5a0dbdb6fe2 100644 --- a/lib/fileproxy/quota.php +++ b/lib/fileproxy/quota.php @@ -26,6 +26,7 @@ */ class OC_FileProxy_Quota extends OC_FileProxy{ + static $rootView; private $userQuota=-1; /** @@ -86,7 +87,10 @@ class OC_FileProxy_Quota extends OC_FileProxy{ } public function preCopy($path1,$path2) { - return (OC_Filesystem::filesize($path1)<$this->getFreeSpace() or $this->getFreeSpace()==0); + if(!self::$rootView){ + self::$rootView = new OC_FilesystemView(''); + } + return (self::$rootView->filesize($path1)<$this->getFreeSpace() or $this->getFreeSpace()==0); } public function preFromTmpFile($tmpfile,$path) { @@ -96,4 +100,4 @@ class OC_FileProxy_Quota extends OC_FileProxy{ public function preFromUploadedFile($tmpfile,$path) { return (filesize($tmpfile)<$this->getFreeSpace() or $this->getFreeSpace()==0); } -}
\ No newline at end of file +} diff --git a/lib/files.php b/lib/files.php index 63dd96b9509..360614caec9 100644 --- a/lib/files.php +++ b/lib/files.php @@ -29,6 +29,35 @@ class OC_Files { static $tmpFiles=array(); /** + * get the filesystem info + * @param string path + * @return array + * + * returns an associative array with the following keys: + * - size + * - mtime + * - ctime + * - mimetype + * - encrypted + * - versioned + */ + public static function getFileInfo($path) { + if (($path == '/Shared' || substr($path, 0, 8) == '/Shared/') && OC_App::isEnabled('files_sharing')) { + if ($path == '/Shared') { + $info = OCP\Share::getItemsSharedWith('file', OC_Share_Backend_File::FORMAT_FILE_APP_ROOT); + } + else { + $info = OCP\Share::getItemSharedWith('file', '/'.$name, OC_Share_Backend_File::FORMAT_FILE_APP); + } + $info = $info[0]; + } + else { + $info = OC_FileCache::get($path); + } + return $info; + } + + /** * get the content of a directory * @param dir $directory path under datadirectory */ diff --git a/lib/files/storage/local.php b/lib/files/storage/local.php index 78e4877a005..66ae5542e36 100644 --- a/lib/files/storage/local.php +++ b/lib/files/storage/local.php @@ -173,7 +173,7 @@ class Local extends \OC\Files\Storage\Common{ } public function free_space($path) { - return disk_free_space($this->datadir.$path); + return @disk_free_space($this->datadir.$path); } public function search($query) { diff --git a/lib/filesystem.php b/lib/filesystem.php index ef8b3fef5bb..e936dfcce26 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -375,7 +375,7 @@ class OC_Filesystem{ * @return string */ static public function getLocalPath($path) { - $datadir = OC_User::getHome($user).'/files'; + $datadir = OC_User::getHome(OC_User::getUser()).'/files'; $newpath = $path; if (strncmp($newpath, $datadir, strlen($datadir)) == 0) { $newpath = substr($path, strlen($datadir)); @@ -545,6 +545,7 @@ class OC_Filesystem{ } else { $path=$params['oldpath']; } + $path = self::normalizePath($path); OC_Connector_Sabre_Node::removeETagPropertyForPath($path); } diff --git a/lib/filesystemview.php b/lib/filesystemview.php index 36fef485513..678e6703cf0 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -263,24 +263,26 @@ class OC_FilesystemView { $path = $this->getRelativePath($absolutePath); $exists = $this->file_exists($path); $run = true; - if(!$exists) { + if( $this->fakeRoot==OC_Filesystem::getRoot() ){ + if(!$exists) { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_create, + array( + OC_Filesystem::signal_param_path => $path, + OC_Filesystem::signal_param_run => &$run + ) + ); + } OC_Hook::emit( OC_Filesystem::CLASSNAME, - OC_Filesystem::signal_create, + OC_Filesystem::signal_write, array( OC_Filesystem::signal_param_path => $path, OC_Filesystem::signal_param_run => &$run ) ); } - OC_Hook::emit( - OC_Filesystem::CLASSNAME, - OC_Filesystem::signal_write, - array( - OC_Filesystem::signal_param_path => $path, - OC_Filesystem::signal_param_run => &$run - ) - ); if(!$run) { return false; } @@ -289,18 +291,20 @@ class OC_FilesystemView { $count=OC_Helper::streamCopy($data, $target); fclose($target); fclose($data); - if(!$exists) { + if( $this->fakeRoot==OC_Filesystem::getRoot() ){ + if(!$exists) { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_post_create, + array( OC_Filesystem::signal_param_path => $path) + ); + } OC_Hook::emit( OC_Filesystem::CLASSNAME, - OC_Filesystem::signal_post_create, + OC_Filesystem::signal_post_write, array( OC_Filesystem::signal_param_path => $path) ); } - OC_Hook::emit( - OC_Filesystem::CLASSNAME, - OC_Filesystem::signal_post_write, - array( OC_Filesystem::signal_param_path => $path) - ); OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count); return $count > 0; }else{ @@ -330,14 +334,16 @@ class OC_FilesystemView { return false; } $run=true; - OC_Hook::emit( - OC_Filesystem::CLASSNAME, OC_Filesystem::signal_rename, - array( - OC_Filesystem::signal_param_oldpath => $path1, - OC_Filesystem::signal_param_newpath => $path2, - OC_Filesystem::signal_param_run => &$run - ) - ); + if( $this->fakeRoot==OC_Filesystem::getRoot() ){ + OC_Hook::emit( + OC_Filesystem::CLASSNAME, OC_Filesystem::signal_rename, + array( + OC_Filesystem::signal_param_oldpath => $path1, + OC_Filesystem::signal_param_newpath => $path2, + OC_Filesystem::signal_param_run => &$run + ) + ); + } if($run) { $mp1 = $this->getMountPoint($path1.$postFix1); $mp2 = $this->getMountPoint($path2.$postFix2); @@ -353,14 +359,16 @@ class OC_FilesystemView { $storage1->unlink($this->getInternalPath($path1.$postFix1)); $result = $count>0; } - OC_Hook::emit( - OC_Filesystem::CLASSNAME, - OC_Filesystem::signal_post_rename, - array( - OC_Filesystem::signal_param_oldpath => $path1, - OC_Filesystem::signal_param_newpath => $path2 - ) - ); + if( $this->fakeRoot==OC_Filesystem::getRoot() ){ + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_post_rename, + array( + OC_Filesystem::signal_param_oldpath => $path1, + OC_Filesystem::signal_param_newpath => $path2 + ) + ); + } return $result; } } @@ -378,35 +386,37 @@ class OC_FilesystemView { return false; } $run=true; - OC_Hook::emit( - OC_Filesystem::CLASSNAME, - OC_Filesystem::signal_copy, - array( - OC_Filesystem::signal_param_oldpath => $path1, - OC_Filesystem::signal_param_newpath=>$path2, - OC_Filesystem::signal_param_run => &$run - ) - ); - $exists=$this->file_exists($path2); - if($run and !$exists) { + if( $this->fakeRoot==OC_Filesystem::getRoot() ){ OC_Hook::emit( OC_Filesystem::CLASSNAME, - OC_Filesystem::signal_create, + OC_Filesystem::signal_copy, array( - OC_Filesystem::signal_param_path => $path2, - OC_Filesystem::signal_param_run => &$run - ) - ); - } - if($run) { - OC_Hook::emit( - OC_Filesystem::CLASSNAME, - OC_Filesystem::signal_write, - array( - OC_Filesystem::signal_param_path => $path2, + OC_Filesystem::signal_param_oldpath => $path1, + OC_Filesystem::signal_param_newpath=>$path2, OC_Filesystem::signal_param_run => &$run ) ); + $exists=$this->file_exists($path2); + if($run and !$exists) { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_create, + array( + OC_Filesystem::signal_param_path => $path2, + OC_Filesystem::signal_param_run => &$run + ) + ); + } + if($run) { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_write, + array( + OC_Filesystem::signal_param_path => $path2, + OC_Filesystem::signal_param_run => &$run + ) + ); + } } if($run) { $mp1=$this->getMountPoint($path1.$postFix1); @@ -420,26 +430,28 @@ class OC_FilesystemView { $target = $this->fopen($path2.$postFix2, 'w'); $result = OC_Helper::streamCopy($source, $target); } - OC_Hook::emit( - OC_Filesystem::CLASSNAME, - OC_Filesystem::signal_post_copy, - array( - OC_Filesystem::signal_param_oldpath => $path1, - OC_Filesystem::signal_param_newpath=>$path2 - ) - ); - if(!$exists) { + if( $this->fakeRoot==OC_Filesystem::getRoot() ){ OC_Hook::emit( OC_Filesystem::CLASSNAME, - OC_Filesystem::signal_post_create, - array(OC_Filesystem::signal_param_path => $path2) + OC_Filesystem::signal_post_copy, + array( + OC_Filesystem::signal_param_oldpath => $path1, + OC_Filesystem::signal_param_newpath=>$path2 + ) + ); + if(!$exists) { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_post_create, + array(OC_Filesystem::signal_param_path => $path2) + ); + } + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_post_write, + array( OC_Filesystem::signal_param_path => $path2) ); } - OC_Hook::emit( - OC_Filesystem::CLASSNAME, - OC_Filesystem::signal_post_write, - array( OC_Filesystem::signal_param_path => $path2) - ); return $result; } } diff --git a/lib/helper.php b/lib/helper.php index 70b2f78862b..e70379d1731 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -62,8 +62,11 @@ class OC_Helper { } } - foreach($args as $k => $v) { - $urlLinkTo .= '&'.$k.'='.$v; + if (!empty($args)) { + $urlLinkTo .= '?'; + foreach($args as $k => $v) { + $urlLinkTo .= '&'.$k.'='.$v; + } } return $urlLinkTo; @@ -654,7 +657,7 @@ class OC_Helper { public static function mb_str_replace($search, $replace, $subject, $encoding = 'UTF-8', &$count = null) { $offset = -1; $length = mb_strlen($search, $encoding); - while(($i = mb_strrpos($subject, $search, $offset, $encoding))) { + while(($i = mb_strrpos($subject, $search, $offset, $encoding)) !== false ) { $subject = OC_Helper::mb_substr_replace($subject, $replace, $i, $length); $offset = $i - mb_strlen($subject, $encoding) - 1; $count++; diff --git a/lib/image.php b/lib/image.php index f4b3c2cc071..861353e039d 100644 --- a/lib/image.php +++ b/lib/image.php @@ -543,21 +543,7 @@ class OC_Image { $new_height = $maxsize; } - $process = imagecreatetruecolor(round($new_width), round($new_height)); - if ($process == false) { - OC_Log::write('core',__METHOD__.'(): Error creating true color image',OC_Log::ERROR); - imagedestroy($process); - return false; - } - - imagecopyresampled($process, $this->resource, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig); - if ($process == false) { - OC_Log::write('core',__METHOD__.'(): Error resampling process image '.$new_width.'x'.$new_height,OC_Log::ERROR); - imagedestroy($process); - return false; - } - imagedestroy($this->resource); - $this->resource = $process; + $this->preciseResize(round($new_width), round($new_height)); return true; } @@ -666,6 +652,28 @@ class OC_Image { return true; } + /** + * @brief Resizes the image to fit within a boundry while preserving ratio. + * @param $maxWidth + * @param $maxHeight + * @returns bool + */ + public function fitIn($maxWidth, $maxHeight) { + if(!$this->valid()) { + OC_Log::write('core',__METHOD__.'(): No image loaded', OC_Log::ERROR); + return false; + } + $width_orig=imageSX($this->resource); + $height_orig=imageSY($this->resource); + $ratio = $width_orig/$height_orig; + + $newWidth = min($maxWidth, $ratio*$maxHeight); + $newHeight = min($maxHeight, $maxWidth/$ratio); + + $this->preciseResize(round($newWidth), round($newHeight)); + return true; + } + public function destroy() { if($this->valid()) { imagedestroy($this->resource); diff --git a/lib/l10n/da.php b/lib/l10n/da.php index 7a9ee26b477..5c68174fa07 100644 --- a/lib/l10n/da.php +++ b/lib/l10n/da.php @@ -21,5 +21,7 @@ "last month" => "Sidste måned", "months ago" => "måneder siden", "last year" => "Sidste år", -"years ago" => "år siden" +"years ago" => "år siden", +"%s is available. Get <a href=\"%s\">more information</a>" => "%s er tilgængelig. Få <a href=\"%s\">mere information</a>", +"up to date" => "opdateret" ); diff --git a/lib/l10n/de.php b/lib/l10n/de.php index 4a567003de2..aea631aba28 100644 --- a/lib/l10n/de.php +++ b/lib/l10n/de.php @@ -14,10 +14,10 @@ "Token expired. Please reload page." => "Token abgelaufen. Bitte laden Sie die Seite neu.", "seconds ago" => "Vor wenigen Sekunden", "1 minute ago" => "Vor einer Minute", -"%d minutes ago" => "Vor %d Minuten", +"%d minutes ago" => "Vor %d Minute(n)", "today" => "Heute", "yesterday" => "Gestern", -"%d days ago" => "Vor %d Tagen", +"%d days ago" => "Vor %d Tag(en)", "last month" => "Letzten Monat", "months ago" => "Vor Monaten", "last year" => "Letztes Jahr", diff --git a/lib/l10n/el.php b/lib/l10n/el.php index d9f272258e1..e4e12490711 100644 --- a/lib/l10n/el.php +++ b/lib/l10n/el.php @@ -11,7 +11,7 @@ "Selected files too large to generate zip file." => "Τα επιλεγμένα αρχεία είναι μεγάλα ώστε να δημιουργηθεί αρχείο zip.", "Application is not enabled" => "Δεν ενεργοποιήθηκε η εφαρμογή", "Authentication error" => "Σφάλμα πιστοποίησης", -"Token expired. Please reload page." => "Το αναγνωριστικό έληξε. Παρακαλώ επανα-φορτώστε την σελίδα.", +"Token expired. Please reload page." => "Το αναγνωριστικό έληξε. Παρακαλώ φορτώστε ξανά την σελίδα.", "seconds ago" => "δευτερόλεπτα πριν", "1 minute ago" => "1 λεπτό πριν", "%d minutes ago" => "%d λεπτά πριν", @@ -21,5 +21,8 @@ "last month" => "τον προηγούμενο μήνα", "months ago" => "μήνες πριν", "last year" => "τον προηγούμενο χρόνο", -"years ago" => "χρόνια πριν" +"years ago" => "χρόνια πριν", +"%s is available. Get <a href=\"%s\">more information</a>" => "%s είναι διαθέσιμα. Δείτε <a href=\"%s\">περισσότερες πληροφορίες</a>", +"up to date" => "ενημερωμένο", +"updates check is disabled" => "ο έλεγχος ενημερώσεων είναι απενεργοποιημένος" ); diff --git a/lib/l10n/eo.php b/lib/l10n/eo.php index 3f89e2eca73..b3c1c52ecee 100644 --- a/lib/l10n/eo.php +++ b/lib/l10n/eo.php @@ -21,5 +21,8 @@ "last month" => "lasta monato", "months ago" => "monatojn antaŭe", "last year" => "lasta jaro", -"years ago" => "jarojn antaŭe" +"years ago" => "jarojn antaŭe", +"%s is available. Get <a href=\"%s\">more information</a>" => "%s haveblas. Ekhavu <a href=\"%s\">pli da informo</a>", +"up to date" => "ĝisdata", +"updates check is disabled" => "ĝisdateckontrolo estas malkapabligita" ); diff --git a/lib/l10n/et_EE.php b/lib/l10n/et_EE.php index d8da90a3cbf..87f222af838 100644 --- a/lib/l10n/et_EE.php +++ b/lib/l10n/et_EE.php @@ -21,5 +21,8 @@ "last month" => "eelmisel kuul", "months ago" => "kuud tagasi", "last year" => "eelmisel aastal", -"years ago" => "aastat tagasi" +"years ago" => "aastat tagasi", +"%s is available. Get <a href=\"%s\">more information</a>" => "%s on saadaval. Vaata <a href=\"%s\">lisainfot</a>", +"up to date" => "ajakohane", +"updates check is disabled" => "uuenduste kontrollimine on välja lülitatud" ); diff --git a/lib/l10n/gl.php b/lib/l10n/gl.php new file mode 100644 index 00000000000..7a9de627c2d --- /dev/null +++ b/lib/l10n/gl.php @@ -0,0 +1,28 @@ +<?php $TRANSLATIONS = array( +"Help" => "Axuda", +"Personal" => "Personal", +"Settings" => "Preferencias", +"Users" => "Usuarios", +"Apps" => "Apps", +"Admin" => "Administración", +"ZIP download is turned off." => "Descargas ZIP está deshabilitadas", +"Files need to be downloaded one by one." => "Os ficheiros necesitan ser descargados de un en un", +"Back to Files" => "Voltar a ficheiros", +"Selected files too large to generate zip file." => "Os ficheiros seleccionados son demasiado grandes para xerar un ficheiro ZIP", +"Application is not enabled" => "O aplicativo non está habilitado", +"Authentication error" => "Erro na autenticación", +"Token expired. Please reload page." => "Testemuño caducado. Por favor recargue a páxina.", +"seconds ago" => "hai segundos", +"1 minute ago" => "hai 1 minuto", +"%d minutes ago" => "hai %d minutos", +"today" => "hoxe", +"yesterday" => "onte", +"%d days ago" => "hai %d días", +"last month" => "último mes", +"months ago" => "meses atrás", +"last year" => "último ano", +"years ago" => "anos atrás", +"%s is available. Get <a href=\"%s\">more information</a>" => "%s está dispoñible. Obteña <a href=\"%s\">máis información</a>", +"up to date" => "ao día", +"updates check is disabled" => "comprobación de actualizacións está deshabilitada" +); diff --git a/lib/l10n/ro.php b/lib/l10n/ro.php new file mode 100644 index 00000000000..5fffeec2335 --- /dev/null +++ b/lib/l10n/ro.php @@ -0,0 +1,28 @@ +<?php $TRANSLATIONS = array( +"Help" => "Ajutor", +"Personal" => "Personal", +"Settings" => "Setări", +"Users" => "Utilizatori", +"Apps" => "Aplicații", +"Admin" => "Admin", +"ZIP download is turned off." => "Descărcarea ZIP este dezactivată.", +"Files need to be downloaded one by one." => "Fișierele trebuie descărcate unul câte unul.", +"Back to Files" => "Înapoi la fișiere", +"Selected files too large to generate zip file." => "Fișierele selectate sunt prea mari pentru a genera un fișier zip.", +"Application is not enabled" => "Aplicația nu este activată", +"Authentication error" => "Eroare la autentificare", +"Token expired. Please reload page." => "Token expirat. Te rugăm să reîncarci pagina.", +"seconds ago" => "secunde în urmă", +"1 minute ago" => "1 minut în urmă", +"%d minutes ago" => "%d minute în urmă", +"today" => "astăzi", +"yesterday" => "ieri", +"%d days ago" => "%d zile în urmă", +"last month" => "ultima lună", +"months ago" => "luni în urmă", +"last year" => "ultimul an", +"years ago" => "ani în urmă", +"%s is available. Get <a href=\"%s\">more information</a>" => "%s este disponibil. Vezi <a href=\"%s\">mai multe informații</a>", +"up to date" => "la zi", +"updates check is disabled" => "verificarea după actualizări este dezactivată" +); diff --git a/lib/l10n/ru.php b/lib/l10n/ru.php index 3b2681ba8d1..74425f0e134 100644 --- a/lib/l10n/ru.php +++ b/lib/l10n/ru.php @@ -22,5 +22,7 @@ "months ago" => "месяцы назад", "last year" => "в прошлом году", "years ago" => "годы назад", +"%s is available. Get <a href=\"%s\">more information</a>" => "Возможно обновление до %s. <a href=\"%s\">Подробнее</a>", +"up to date" => "актуальная версия", "updates check is disabled" => "проверка обновлений отключена" ); diff --git a/lib/l10n/ru_RU.php b/lib/l10n/ru_RU.php new file mode 100644 index 00000000000..1e691993014 --- /dev/null +++ b/lib/l10n/ru_RU.php @@ -0,0 +1,27 @@ +<?php $TRANSLATIONS = array( +"Help" => "Помощь", +"Personal" => "Персональный", +"Settings" => "Настройки", +"Users" => "Пользователи", +"Apps" => "Приложения", +"Admin" => "Админ", +"Files need to be downloaded one by one." => "Файлы должны быть загружены один за другим.", +"Back to Files" => "Обратно к файлам", +"Selected files too large to generate zip file." => "Выбранные файлы слишком велики для генерации zip-архива.", +"Application is not enabled" => "Приложение не запущено", +"Authentication error" => "Ошибка аутентификации", +"Token expired. Please reload page." => "Маркер истек. Пожалуйста, перезагрузите страницу.", +"seconds ago" => "секунд назад", +"1 minute ago" => "1 минуту назад", +"%d minutes ago" => "%d минут назад", +"today" => "сегодня", +"yesterday" => "вчера", +"%d days ago" => "%d дней назад", +"last month" => "в прошлом месяце", +"months ago" => "месяц назад", +"last year" => "в прошлом году", +"years ago" => "год назад", +"%s is available. Get <a href=\"%s\">more information</a>" => "%s доступно. Получите <a href=\"%s\">more information</a>", +"up to date" => "до настоящего времени", +"updates check is disabled" => "Проверка обновлений отключена" +); diff --git a/lib/l10n/sk_SK.php b/lib/l10n/sk_SK.php new file mode 100644 index 00000000000..33b329c30bb --- /dev/null +++ b/lib/l10n/sk_SK.php @@ -0,0 +1,25 @@ +<?php $TRANSLATIONS = array( +"Help" => "Pomoc", +"Personal" => "Osobné", +"Settings" => "Nastavenia", +"Users" => "Užívatelia", +"Apps" => "Aplikácie", +"Admin" => "Správca", +"ZIP download is turned off." => "Sťahovanie súborov ZIP je vypnuté.", +"Files need to be downloaded one by one." => "Súbory musia byť nahrávané jeden za druhým.", +"Back to Files" => "Späť na súbory", +"Selected files too large to generate zip file." => "Zvolené súbory sú príliž veľké na vygenerovanie zip súboru.", +"Application is not enabled" => "Aplikácia nie je zapnutá", +"Authentication error" => "Chyba autentifikácie", +"1 minute ago" => "pred 1 minútou", +"%d minutes ago" => "pred %d minútami", +"today" => "dnes", +"yesterday" => "včera", +"%d days ago" => "pred %d dňami", +"last month" => "minulý mesiac", +"months ago" => "pred mesiacmi", +"last year" => "minulý rok", +"years ago" => "pred rokmi", +"up to date" => "aktuálny", +"updates check is disabled" => "sledovanie aktualizácií je vypnuté" +); diff --git a/lib/l10n/sl.php b/lib/l10n/sl.php index 273773f2f7b..eac839e78f3 100644 --- a/lib/l10n/sl.php +++ b/lib/l10n/sl.php @@ -12,16 +12,16 @@ "Application is not enabled" => "Aplikacija ni omogočena", "Authentication error" => "Napaka overitve", "Token expired. Please reload page." => "Žeton je potekel. Prosimo, če spletno stran znova naložite.", -"seconds ago" => "sekund nazaj", +"seconds ago" => "pred nekaj sekundami", "1 minute ago" => "pred minuto", "%d minutes ago" => "pred %d minutami", "today" => "danes", "yesterday" => "včeraj", "%d days ago" => "pred %d dnevi", "last month" => "prejšnji mesec", -"months ago" => "mesecev nazaj", +"months ago" => "pred nekaj meseci", "last year" => "lani", -"years ago" => "let nazaj", +"years ago" => "pred nekaj leti", "%s is available. Get <a href=\"%s\">more information</a>" => "%s je na voljo. <a href=\"%s\">Več informacij.</a>", "up to date" => "ažuren", "updates check is disabled" => "preverjanje za posodobitve je onemogočeno" diff --git a/lib/l10n/uk.php b/lib/l10n/uk.php index 18f6a4a623d..423aa12b2d7 100644 --- a/lib/l10n/uk.php +++ b/lib/l10n/uk.php @@ -20,5 +20,6 @@ "last month" => "минулого місяця", "months ago" => "місяці тому", "last year" => "минулого року", -"years ago" => "роки тому" +"years ago" => "роки тому", +"updates check is disabled" => "перевірка оновлень відключена" ); diff --git a/lib/l10n/vi.php b/lib/l10n/vi.php new file mode 100644 index 00000000000..fc41d69819a --- /dev/null +++ b/lib/l10n/vi.php @@ -0,0 +1,28 @@ +<?php $TRANSLATIONS = array( +"Help" => "Giúp đỡ", +"Personal" => "Cá nhân", +"Settings" => "Cài đặt", +"Users" => "Người dùng", +"Apps" => "Ứng dụng", +"Admin" => "Quản trị", +"ZIP download is turned off." => "Tải về ZIP đã bị tắt.", +"Files need to be downloaded one by one." => "Tập tin cần phải được tải về từng người một.", +"Back to Files" => "Trở lại tập tin", +"Selected files too large to generate zip file." => "Tập tin được chọn quá lớn để tạo tập tin ZIP.", +"Application is not enabled" => "Ứng dụng không được BẬT", +"Authentication error" => "Lỗi xác thực", +"Token expired. Please reload page." => "Mã Token đã hết hạn. Hãy tải lại trang.", +"seconds ago" => "1 giây trước", +"1 minute ago" => "1 phút trước", +"%d minutes ago" => "%d phút trước", +"today" => "hôm nay", +"yesterday" => "hôm qua", +"%d days ago" => "%d ngày trước", +"last month" => "tháng trước", +"months ago" => "tháng trước", +"last year" => "năm trước", +"years ago" => "năm trước", +"%s is available. Get <a href=\"%s\">more information</a>" => "%s có sẵn. <a href=\"%s\">xem thêm ở đây</a>", +"up to date" => "đến ngày", +"updates check is disabled" => "đã TĂT chức năng cập nhật " +); diff --git a/lib/l10n/zh_CN.GB2312.php b/lib/l10n/zh_CN.GB2312.php new file mode 100644 index 00000000000..4b0a5e9f4d2 --- /dev/null +++ b/lib/l10n/zh_CN.GB2312.php @@ -0,0 +1,28 @@ +<?php $TRANSLATIONS = array( +"Help" => "帮助", +"Personal" => "私人", +"Settings" => "设置", +"Users" => "用户", +"Apps" => "程序", +"Admin" => "管理员", +"ZIP download is turned off." => "ZIP 下载已关闭", +"Files need to be downloaded one by one." => "需要逐个下载文件。", +"Back to Files" => "返回到文件", +"Selected files too large to generate zip file." => "选择的文件太大而不能生成 zip 文件。", +"Application is not enabled" => "应用未启用", +"Authentication error" => "验证错误", +"Token expired. Please reload page." => "会话过期。请刷新页面。", +"seconds ago" => "秒前", +"1 minute ago" => "1 分钟前", +"%d minutes ago" => "%d 分钟前", +"today" => "今天", +"yesterday" => "昨天", +"%d days ago" => "%d 天前", +"last month" => "上个月", +"months ago" => "月前", +"last year" => "去年", +"years ago" => "年前", +"%s is available. Get <a href=\"%s\">more information</a>" => "%s 不可用。获知 <a href=\"%s\">详情</a>", +"up to date" => "最新", +"updates check is disabled" => "更新检测已禁用" +); diff --git a/lib/migrate.php b/lib/migrate.php index 823b3574f16..611a935ee5d 100644 --- a/lib/migrate.php +++ b/lib/migrate.php @@ -84,21 +84,15 @@ 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( 'success' => false ) ); } self::$exporttype = $type; // Userid? if( self::$exporttype == 'user' ) { // Check user exists - 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 ) ); - } - self::$uid = $uid; - } else { - self::$uid = OC_User::getUser(); + self::$uid = is_null($uid) ? OC_User::getUser() : $uid; + if(!OC_User::userExists(self::$uid)){ + return json_encode( array( 'success' => false) ); } } // Calculate zipname diff --git a/lib/migration/content.php b/lib/migration/content.php index 64b8168cd98..89b1e782d86 100644 --- a/lib/migration/content.php +++ b/lib/migration/content.php @@ -30,7 +30,7 @@ class OC_Migration_Content{ // Holds the MDB2 object private $db=null; // Holds an array of tmpfiles to delete after zip creation - private $tmpfiles=false; + private $tmpfiles=array(); /** * @brief sets up the @@ -43,18 +43,21 @@ class OC_Migration_Content{ $this->zip = $zip; $this->db = $db; - if( !is_null( $db ) ) { - // Get db path - $db = $this->db->getDatabase(); - $this->tmpfiles[] = $db; - } - } // @brief prepares the db // @param $query the sql query to prepare public function prepare( $query ) { - + + // Only add database to tmpfiles if actually used + if( !is_null( $this->db ) ) { + // Get db path + $db = $this->db->getDatabase(); + if(!in_array($db, $this->tmpfiles)){ + $this->tmpfiles[] = $db; + } + } + // Optimize the query $query = $this->processQuery( $query ); diff --git a/lib/ocs.php b/lib/ocs.php index 3a9be4cf09d..7350c3c8821 100644 --- a/lib/ocs.php +++ b/lib/ocs.php @@ -84,7 +84,7 @@ class OC_OCS { $method='get'; }elseif($_SERVER['REQUEST_METHOD'] == 'PUT') { $method='put'; - parse_str(file_get_contents("php://input"),$put_vars); + parse_str(file_get_contents("php://input"), $put_vars); }elseif($_SERVER['REQUEST_METHOD'] == 'POST') { $method='post'; }else{ @@ -94,8 +94,8 @@ class OC_OCS { // preprocess url $url = strtolower($_SERVER['REQUEST_URI']); - if(substr($url,(strlen($url)-1))<>'/') $url.='/'; - $ex=explode('/',$url); + if(substr($url, (strlen($url)-1))<>'/') $url.='/'; + $ex=explode('/', $url); $paracount=count($ex); $format = self::readData($method, 'format', 'text', ''); @@ -107,23 +107,23 @@ class OC_OCS { // PERSON // personcheck - POST - PERSON/CHECK - }elseif(($method=='post') and ($ex[$paracount-4] == 'v1.php') and ($ex[$paracount-3]=='person') and ($ex[$paracount-2] == 'check')) { + } elseif(($method=='post') and ($ex[$paracount-4] == 'v1.php') and ($ex[$paracount-3]=='person') and ($ex[$paracount-2] == 'check')) { $login = self::readData($method, 'login', 'text'); $passwd = self::readData($method, 'password', 'text'); - OC_OCS::personcheck($format,$login,$passwd); + OC_OCS::personcheck($format, $login, $passwd); // ACTIVITY // activityget - GET ACTIVITY page,pagesize als urlparameter }elseif(($method=='get') and ($ex[$paracount-3] == 'v1.php') and ($ex[$paracount-2] == 'activity')) { $page = self::readData($method, 'page', 'int', 0); - $pagesize = self::readData($method, 'pagesize','int', 10); + $pagesize = self::readData($method, 'pagesize', 'int', 10); if($pagesize<1 or $pagesize>100) $pagesize=10; - OC_OCS::activityget($format,$page,$pagesize); + OC_OCS::activityget($format, $page, $pagesize); // activityput - POST ACTIVITY }elseif(($method=='post') and ($ex[$paracount-3] == 'v1.php') and ($ex[$paracount-2] == 'activity')) { $message = self::readData($method, 'message', 'text'); - OC_OCS::activityput($format,$message); + OC_OCS::activityput($format, $message); // PRIVATEDATA @@ -138,7 +138,7 @@ class OC_OCS { $key=$ex[$paracount-2]; $app=$ex[$paracount-3]; - OC_OCS::privateDataGet($format, $app,$key); + OC_OCS::privateDataGet($format, $app, $key); // set - POST DATA }elseif(($method=='post') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-4] == 'setattribute')) { @@ -160,23 +160,23 @@ class OC_OCS { // quotaget }elseif(($method=='get') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-5]=='cloud') and ($ex[$paracount-4] == 'user') and ($ex[$paracount-2] == 'quota')) { $user=$ex[$paracount-3]; - OC_OCS::quotaget($format,$user); + OC_OCS::quotaget($format, $user); // quotaset }elseif(($method=='post') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-5]=='cloud') and ($ex[$paracount-4] == 'user') and ($ex[$paracount-2] == 'quota')) { $user=$ex[$paracount-3]; $quota = self::readData('post', 'quota', 'int'); - OC_OCS::quotaset($format,$user,$quota); + OC_OCS::quotaset($format, $user, $quota); // keygetpublic }elseif(($method=='get') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-5]=='cloud') and ($ex[$paracount-4] == 'user') and ($ex[$paracount-2] == 'publickey')) { $user=$ex[$paracount-3]; - OC_OCS::publicKeyGet($format,$user); + OC_OCS::publicKeyGet($format, $user); // keygetprivate }elseif(($method=='get') and ($ex[$paracount-6] == 'v1.php') and ($ex[$paracount-5]=='cloud') and ($ex[$paracount-4] == 'user') and ($ex[$paracount-2] == 'privatekey')) { $user=$ex[$paracount-3]; - OC_OCS::privateKeyGet($format,$user); + OC_OCS::privateKeyGet($format, $user); // add more calls here @@ -196,7 +196,7 @@ class OC_OCS { }else{ $txt='Invalid query, please check the syntax. API specifications are here: http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:'."\n"; $txt.=OC_OCS::getdebugoutput(); - echo(OC_OCS::generatexml($format,'failed',999,$txt)); + echo(OC_OCS::generatexml($format, 'failed', 999, $txt)); } exit(); } @@ -237,7 +237,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'); @@ -283,69 +283,69 @@ class OC_OCS { $writer = xmlwriter_open_memory(); xmlwriter_set_indent( $writer, 2 ); xmlwriter_start_document($writer ); - xmlwriter_start_element($writer,'ocs'); - xmlwriter_start_element($writer,'meta'); - xmlwriter_write_element($writer,'status',$status); - xmlwriter_write_element($writer,'statuscode',$statuscode); - xmlwriter_write_element($writer,'message',$message); + xmlwriter_start_element($writer, 'ocs'); + xmlwriter_start_element($writer, 'meta'); + xmlwriter_write_element($writer, 'status', $status); + xmlwriter_write_element($writer, 'statuscode', $statuscode); + xmlwriter_write_element($writer, 'message', $message); if($itemscount<>'') xmlwriter_write_element($writer,'totalitems',$itemscount); - if(!empty($itemsperpage)) xmlwriter_write_element($writer,'itemsperpage',$itemsperpage); + if(!empty($itemsperpage)) xmlwriter_write_element($writer, 'itemsperpage', $itemsperpage); xmlwriter_end_element($writer); if($dimension=='0') { // 0 dimensions - xmlwriter_write_element($writer,'data',$data); + xmlwriter_write_element($writer, 'data', $data); }elseif($dimension=='1') { - xmlwriter_start_element($writer,'data'); + xmlwriter_start_element($writer, 'data'); foreach($data as $key=>$entry) { - xmlwriter_write_element($writer,$key,$entry); + xmlwriter_write_element($writer, $key, $entry); } xmlwriter_end_element($writer); }elseif($dimension=='2') { xmlwriter_start_element($writer,'data'); foreach($data as $entry) { - xmlwriter_start_element($writer,$tag); - if(!empty($tagattribute)) { - xmlwriter_write_attribute($writer,'details',$tagattribute); - } - foreach($entry as $key=>$value) { - if(is_array($value)) { - foreach($value as $k=>$v) { - xmlwriter_write_element($writer,$k,$v); - } - } else { - xmlwriter_write_element($writer,$key,$value); - } - } - xmlwriter_end_element($writer); - } + xmlwriter_start_element($writer, $tag); + if(!empty($tagattribute)) { + xmlwriter_write_attribute($writer, 'details', $tagattribute); + } + foreach($entry as $key=>$value) { + if(is_array($value)) { + foreach($value as $k=>$v) { + xmlwriter_write_element($writer, $k, $v); + } + } else { + xmlwriter_write_element($writer, $key, $value); + } + } + xmlwriter_end_element($writer); + } xmlwriter_end_element($writer); }elseif($dimension=='3') { - xmlwriter_start_element($writer,'data'); + xmlwriter_start_element($writer, 'data'); foreach($data as $entrykey=>$entry) { - xmlwriter_start_element($writer,$tag); - if(!empty($tagattribute)) { - xmlwriter_write_attribute($writer,'details',$tagattribute); - } - foreach($entry as $key=>$value) { - if(is_array($value)) { - xmlwriter_start_element($writer,$entrykey); - foreach($value as $k=>$v) { - xmlwriter_write_element($writer,$k,$v); - } - xmlwriter_end_element($writer); - } else { - xmlwriter_write_element($writer,$key,$value); - } - } - xmlwriter_end_element($writer); + xmlwriter_start_element($writer, $tag); + if(!empty($tagattribute)) { + xmlwriter_write_attribute($writer, 'details', $tagattribute); + } + foreach($entry as $key=>$value) { + if(is_array($value)) { + xmlwriter_start_element($writer, $entrykey); + foreach($value as $k=>$v) { + xmlwriter_write_element($writer, $k, $v); + } + xmlwriter_end_element($writer); + } else { + xmlwriter_write_element($writer, $key, $value); + } + } + xmlwriter_end_element($writer); } xmlwriter_end_element($writer); }elseif($dimension=='dynamic') { - xmlwriter_start_element($writer,'data'); - OC_OCS::toxml($writer,$data,'comment'); + xmlwriter_start_element($writer, 'data'); + OC_OCS::toxml($writer, $data, 'comment'); xmlwriter_end_element($writer); } @@ -364,18 +364,15 @@ class OC_OCS { $key = $node; } if (is_array($value)) { - xmlwriter_start_element($writer,$key); - OC_OCS::toxml($writer,$value,$node); + xmlwriter_start_element($writer, $key); + OC_OCS::toxml($writer,$value, $node); xmlwriter_end_element($writer); }else{ - xmlwriter_write_element($writer,$key,$value); + xmlwriter_write_element($writer, $key, $value); } } } - - - /** * return the config data of this server * @param string $format @@ -383,17 +380,16 @@ class OC_OCS { */ private static function apiConfig($format) { $user=OC_OCS::checkpassword(false); - $url=substr(OCP\Util::getServerHost().$_SERVER['SCRIPT_NAME'],0,-11).''; + $url=substr(OCP\Util::getServerHost().$_SERVER['SCRIPT_NAME'], 0, -11).''; $xml['version']='1.7'; $xml['website']='ownCloud'; $xml['host']=OCP\Util::getServerHost(); $xml['contact']=''; $xml['ssl']='false'; - echo(OC_OCS::generatexml($format,'ok',100,'',$xml,'config','',1)); + echo(OC_OCS::generatexml($format, 'ok', 100, '', $xml, 'config', '', 1)); } - /** * check if the provided login/apikey/password is valid * @param string $format @@ -403,19 +399,17 @@ 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)); + echo(OC_OCS::generatexml($format, 'ok', 100, '', $xml, 'person', 'check', 2)); }else{ - echo(OC_OCS::generatexml($format,'failed',102,'login not valid')); + echo(OC_OCS::generatexml($format, 'failed', 102, 'login not valid')); } }else{ - echo(OC_OCS::generatexml($format,'failed',101,'please specify all mandatory fields')); + echo(OC_OCS::generatexml($format, 'failed', 101, 'please specify all mandatory fields')); } } - - // ACTIVITY API ############################################# /** @@ -425,12 +419,12 @@ class OC_OCS { * @param string $pagesize * @return string xml/json */ - private static function activityGet($format,$page,$pagesize) { + private static function activityGet($format, $page, $pagesize) { $user=OC_OCS::checkpassword(); //TODO - $txt=OC_OCS::generatexml($format,'ok',100,'',$xml,'activity','full',2,$totalcount,$pagesize); + $txt=OC_OCS::generatexml($format, 'ok', 100, '', $xml, 'activity', 'full', 2, $totalcount,$pagesize); echo($txt); } @@ -443,7 +437,7 @@ class OC_OCS { private static function activityPut($format,$message) { // not implemented in ownCloud $user=OC_OCS::checkpassword(); - echo(OC_OCS::generatexml($format,'ok',100,'')); + echo(OC_OCS::generatexml($format, 'ok', 100, '')); } // PRIVATEDATA API ############################################# @@ -455,9 +449,9 @@ class OC_OCS { * @param string $key * @return string xml/json */ - private static function privateDataGet($format,$app="",$key="") { + private static function privateDataGet($format, $app="", $key="") { $user=OC_OCS::checkpassword(); - $result=OC_OCS::getData($user,$app,$key); + $result=OC_OCS::getData($user, $app, $key); $xml=array(); foreach($result as $i=>$log) { $xml[$i]['key']=$log['key']; @@ -480,8 +474,8 @@ class OC_OCS { */ private static function privateDataSet($format, $app, $key, $value) { $user=OC_OCS::checkpassword(); - if(OC_OCS::setData($user,$app,$key,$value)) { - echo(OC_OCS::generatexml($format,'ok',100,'')); + if(OC_OCS::setData($user, $app, $key, $value)) { + echo(OC_OCS::generatexml($format, 'ok', 100, '')); } } @@ -497,8 +491,8 @@ class OC_OCS { return; //key and app are NOT optional here } $user=OC_OCS::checkpassword(); - if(OC_OCS::deleteData($user,$app,$key)) { - echo(OC_OCS::generatexml($format,'ok',100,'')); + if(OC_OCS::deleteData($user, $app, $key)) { + echo(OC_OCS::generatexml($format, 'ok', 100, '')); } } @@ -510,7 +504,7 @@ class OC_OCS { * @param bool $like use LIKE instead of = when comparing keys * @return array */ - public static function getData($user,$app="",$key="") { + public static function getData($user, $app="", $key="") { if($app) { $apps=array($app); }else{ @@ -520,14 +514,14 @@ class OC_OCS { $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); - $result[]=array('app'=>$app,'key'=>$key,'value'=>$value); + $value=OC_Preferences::getValue($user, $app, $key); + $result[]=array('app'=>$app, 'key'=>$key, 'value'=>$value); } } return $result; @@ -542,7 +536,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,7 +547,7 @@ 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 8596ea0b3c7..6428a883679 100644 --- a/lib/ocsclient.php +++ b/lib/ocsclient.php @@ -53,7 +53,7 @@ class OC_OCSClient{ /** * @brief Get all the categories from the OCS server * @returns array with category ids - * + * @note returns NULL if config value appstoreenabled is set to false * This function returns a list of all the application categories on the OCS server */ public static function getCategories() { diff --git a/lib/public/app.php b/lib/public/app.php index eb824f043e9..809a656f17f 100644 --- a/lib/public/app.php +++ b/lib/public/app.php @@ -34,120 +34,109 @@ namespace OCP; * This class provides functions to manage apps in ownCloud */ class App { - /** - * @brief Makes owncloud aware of this app - * @brief This call is deprecated and not necessary to use. - * @param $data array with all information - * @returns true/false - * - * @deprecated this method is deprecated - * Do not call it anymore - * It'll remain in our public API for compatibility reasons - * - */ - public static function register( $data ) { + /** + * @brief Makes owncloud aware of this app + * @brief This call is deprecated and not necessary to use. + * @param $data array with all information + * @returns true/false + * + * @deprecated this method is deprecated + * Do not call it anymore + * It'll remain in our public API for compatibility reasons + * + */ + public static function register( $data ) { return true; // don't do anything - } + } - /** - * @brief adds an entry to the navigation - * @param $data array containing the data - * @returns true/false - * - * This function adds a new entry to the navigation visible to users. $data - * is an associative array. - * The following keys are required: - * - id: unique id for this entry ('addressbook_index') - * - href: link to the page - * - name: Human readable name ('Addressbook') - * - * The following keys are optional: - * - icon: path to the icon of the app - * - order: integer, that influences the position of your application in - * the navigation. Lower values come first. - */ - public static function addNavigationEntry( $data ) { + /** + * @brief adds an entry to the navigation + * @param $data array containing the data + * @returns true/false + * + * This function adds a new entry to the navigation visible to users. $data + * is an associative array. + * The following keys are required: + * - id: unique id for this entry ('addressbook_index') + * - href: link to the page + * - name: Human readable name ('Addressbook') + * + * The following keys are optional: + * - icon: path to the icon of the app + * - order: integer, that influences the position of your application in + * the navigation. Lower values come first. + */ + public static function addNavigationEntry( $data ) { return \OC_App::addNavigationEntry( $data ); } - - /** - * @brief marks a navigation entry as active - * @param $id id of the entry - * @returns true/false - * - * This function sets a navigation entry as active and removes the 'active' - * property from all other entries. The templates can use this for - * highlighting the current position of the user. - */ - public static function setActiveNavigationEntry( $id ) { + /** + * @brief marks a navigation entry as active + * @param $id id of the entry + * @returns true/false + * + * This function sets a navigation entry as active and removes the 'active' + * property from all other entries. The templates can use this for + * highlighting the current position of the user. + */ + public static function setActiveNavigationEntry( $id ) { return \OC_App::setActiveNavigationEntry( $id ); } - - /** - * @brief Register a Configuration Screen that should appear in the personal settings section. - * @param $app string appid - * @param $page string page to be included - */ - public static function registerPersonal( $app, $page ) { + /** + * @brief Register a Configuration Screen that should appear in the personal settings section. + * @param $app string appid + * @param $page string page to be included + */ + public static function registerPersonal( $app, $page ) { return \OC_App::registerPersonal( $app, $page ); } - /** - * @brief Register a Configuration Screen that should appear in the Admin section. - * @param $app string appid - * @param $page string page to be included + * @brief Register a Configuration Screen that should appear in the Admin section. + * @param $app string appid + * @param $page string page to be included */ public static function registerAdmin( $app, $page ) { return \OC_App::registerAdmin( $app, $page ); } - - /** - * @brief Read app metadata from the info.xml file - * @param string $app id of the app or the path of the info.xml file - * @param boolean path (optional) - * @returns array - */ - public static function getAppInfo( $app, $path=false ) { + /** + * @brief Read app metadata from the info.xml file + * @param string $app id of the app or the path of the info.xml file + * @param boolean path (optional) + * @returns array + */ + public static function getAppInfo( $app, $path=false ) { return \OC_App::getAppInfo( $app, $path); } - - - /** - * @brief checks whether or not an app is enabled - * @param $app app - * @returns true/false - * - * This function checks whether or not an app is enabled. - */ - public static function isEnabled( $app ) { + /** + * @brief checks whether or not an app is enabled + * @param $app app + * @returns true/false + * + * This function checks whether or not an app is enabled. + */ + public static function isEnabled( $app ) { return \OC_App::isEnabled( $app ); } + /** + * @brief Check if the app is enabled, redirects to home if not + * @param $app app + * @returns true/false + */ + public static function checkAppEnabled( $app ) { + return \OC_Util::checkAppEnabled( $app ); + } - /** - * @brief Check if the app is enabled, redirects to home if not - * @param $app app - * @returns true/false - */ - public static function checkAppEnabled( $app ) { - return \OC_Util::checkAppEnabled( $app ); - } - - - /** - * @brief Get the last version of the app, either from appinfo/version or from appinfo/info.xml - * @param $app app - * @returns true/false - */ - public static function getAppVersion( $app ) { + /** + * @brief Get the last version of the app, either from appinfo/version or from appinfo/info.xml + * @param $app app + * @returns true/false + */ + public static function getAppVersion( $app ) { return \OC_App::getAppVersion( $app ); } - - - } diff --git a/lib/public/config.php b/lib/public/config.php index fa9658e7288..377150115ff 100644 --- a/lib/public/config.php +++ b/lib/public/config.php @@ -38,8 +38,6 @@ namespace OCP; * This class provides functions to read and write configuration data. configuration can be on a system, application or user level */ class Config { - - /** * @brief Gets a value from config.php * @param $key key @@ -53,7 +51,6 @@ class Config { return(\OC_Config::getValue( $key, $default )); } - /** * @brief Sets a value * @param $key key @@ -67,70 +64,60 @@ class Config { return(\OC_Config::setValue( $key, $value )); } - - /** - * @brief Gets the config value - * @param $app app - * @param $key key - * @param $default = null, default value if the key does not exist - * @returns the value or $default - * - * This function gets a value from the appconfig table. If the key does - * not exist the default value will be returnes - */ - public static function getAppValue( $app, $key, $default = null ) { + /** + * @brief Gets the config value + * @param $app app + * @param $key key + * @param $default = null, default value if the key does not exist + * @returns the value or $default + * + * This function gets a value from the appconfig table. If the key does + * not exist the default value will be returnes + */ + public static function getAppValue( $app, $key, $default = null ) { return(\OC_Appconfig::getValue( $app, $key, $default )); } - - /** - * @brief sets a value in the appconfig - * @param $app app - * @param $key key - * @param $value value - * @returns true/false - * - * Sets a value. If the key did not exist before it will be created. - */ - public static function setAppValue( $app, $key, $value ) { + /** + * @brief sets a value in the appconfig + * @param $app app + * @param $key key + * @param $value value + * @returns true/false + * + * Sets a value. If the key did not exist before it will be created. + */ + public static function setAppValue( $app, $key, $value ) { return(\OC_Appconfig::setValue( $app, $key, $value )); } - - /** - * @brief Gets the preference - * @param $user user - * @param $app app - * @param $key key - * @param $default = null, default value if the key does not exist - * @returns the value or $default - * - * This function gets a value from the prefernces table. If the key does - * not exist the default value will be returnes - */ - public static function getUserValue( $user, $app, $key, $default = null ) { + /** + * @brief Gets the preference + * @param $user user + * @param $app app + * @param $key key + * @param $default = null, default value if the key does not exist + * @returns the value or $default + * + * This function gets a value from the prefernces table. If the key does + * not exist the default value will be returnes + */ + public static function getUserValue( $user, $app, $key, $default = null ) { return(\OC_Preferences::getValue( $user, $app, $key, $default )); } - - /** - * @brief sets a value in the preferences - * @param $user user - * @param $app app - * @param $key key - * @param $value value - * @returns true/false - * - * Adds a value to the preferences. If the key did not exist before, it - * will be added automagically. - */ - public static function setUserValue( $user, $app, $key, $value ) { + /** + * @brief sets a value in the preferences + * @param $user user + * @param $app app + * @param $key key + * @param $value value + * @returns true/false + * + * Adds a value to the preferences. If the key did not exist before, it + * will be added automagically. + */ + public static function setUserValue( $user, $app, $key, $value ) { return(\OC_Preferences::setValue( $user, $app, $key, $value )); } - - - - - - } diff --git a/lib/public/db.php b/lib/public/db.php index 5ac356bb475..6ce62b27ca2 100644 --- a/lib/public/db.php +++ b/lib/public/db.php @@ -34,8 +34,6 @@ namespace OCP; * This class provides access to the internal database system. Use this class exlusively if you want to access databases */ class DB { - - /** * @brief Prepare a SQL query * @param $query Query string @@ -47,7 +45,6 @@ class DB { return(\OC_DB::prepare($query,$limit,$offset)); } - /** * @brief gets last value of autoincrement * @param $table string The optional table name (will replace *PREFIX*) and add sequence suffix @@ -62,7 +59,6 @@ class DB { return(\OC_DB::insertid($table)); } - /** * @brief Start a transaction */ @@ -70,7 +66,6 @@ class DB { return(\OC_DB::beginTransaction()); } - /** * @brief Commit the database changes done during a transaction that is in progress */ @@ -78,7 +73,6 @@ class DB { return(\OC_DB::commit()); } - /** * @brief check if a result is an error, works with MDB2 and PDOException * @param mixed $result @@ -87,7 +81,4 @@ class DB { public static function isError($result) { return(\OC_DB::isError($result)); } - - - } diff --git a/lib/public/files.php b/lib/public/files.php index 2f4f459bd91..90889c59ad8 100644 --- a/lib/public/files.php +++ b/lib/public/files.php @@ -34,8 +34,6 @@ namespace OCP; * This class provides access to the internal filesystem abstraction layer. Use this class exlusively if you want to access files */ class Files { - - /** * @brief Recusive deletion of folders * @param string $dir path to the folder @@ -45,7 +43,6 @@ class Files { \OC_Helper::rmdirr( $dir ); } - /** * get the mimetype form a local file * @param string path @@ -56,7 +53,6 @@ class Files { return(\OC_Helper::getMimeType( $path )); } - /** * copy the contents of one stream to another * @param resource source @@ -67,7 +63,6 @@ class Files { return(\OC_Helper::streamCopy( $source, $target )); } - /** * create a temporary file with an unique filename * @param string postfix @@ -79,7 +74,6 @@ class Files { return(\OC_Helper::tmpFile( $postfix )); } - /** * create a temporary folder with an unique filename * @return string @@ -90,7 +84,6 @@ class Files { return(\OC_Helper::tmpFolder()); } - /** * Adds a suffix to the name in case the file exists * @@ -102,16 +95,12 @@ class Files { return(\OC_Helper::buildNotExistingFileName( $path, $filename )); } - /** - * @param string appid - * @param $app app - * @return OC_FilesystemView - */ - public static function getStorage( $app ) { + /** + * @param string appid + * @param $app app + * @return OC_FilesystemView + */ + public static function getStorage( $app ) { return \OC_App::getStorage( $app ); } - - - - } diff --git a/lib/public/json.php b/lib/public/json.php index 93be920c6d7..2186dd8ee49 100644 --- a/lib/public/json.php +++ b/lib/public/json.php @@ -34,7 +34,6 @@ namespace OCP; * This class provides convinient functions to generate and send JSON data. Usefull for Ajax calls */ class JSON { - /** * @brief Encode and print $data in JSON format * @param array $data The data to use @@ -170,5 +169,4 @@ class JSON { public static function checkAdminUser() { return(\OC_JSON::checkAdminUser()); } - } diff --git a/lib/public/response.php b/lib/public/response.php index febb3f14361..95e67a85720 100644 --- a/lib/public/response.php +++ b/lib/public/response.php @@ -34,8 +34,6 @@ namespace OCP; * This class provides convinient functions to send the correct http response headers */ class Response { - - /** * @brief Enable response caching by sending correct HTTP headers * @param $cache_time time to cache the response @@ -47,7 +45,6 @@ class Response { return(\OC_Response::enableCaching( $cache_time )); } - /** * Checks and set Last-Modified header, when the request matches sends a * 'not modified' response @@ -57,7 +54,6 @@ class Response { return(\OC_Response::setLastModifiedHeader( $lastModified )); } - /** * @brief disable browser caching * @see enableCaching with cache_time = 0 @@ -66,7 +62,6 @@ class Response { return(\OC_Response::disableCaching()); } - /** * Checks and set ETag header, when the request matches sends a * 'not modified' response @@ -76,7 +71,6 @@ class Response { return(\OC_Response::setETagHeader( $etag )); } - /** * @brief Send file as response, checking and setting caching headers * @param $filepath of file to send @@ -102,6 +96,4 @@ class Response { static public function redirect( $location ) { return(\OC_Response::redirect( $location )); } - - -} +}
\ No newline at end of file diff --git a/lib/public/share.php b/lib/public/share.php index cf61681424f..b215d7f9389 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -252,26 +252,26 @@ class Share { \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); return false; - } else if ($shareType === self::SHARE_TYPE_CONTACT) { - if (!\OC_App::isEnabled('contacts')) { - $message = 'Sharing '.$itemSource.' failed, because the contacts app is not enabled'; - \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); - return false; - } - $vcard = \OC_Contacts_App::getContactVCard($shareWith); - if (!isset($vcard)) { - $message = 'Sharing '.$itemSource.' failed, because the contact does not exist'; - \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); - throw new \Exception($message); - } - $details = \OC_Contacts_VCard::structureContact($vcard); - // TODO Add ownCloud user to contacts vcard - if (!isset($details['EMAIL'])) { - $message = 'Sharing '.$itemSource.' failed, because no email address is associated with the contact'; - \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); - throw new \Exception($message); - } - return self::shareItem($itemType, $itemSource, self::SHARE_TYPE_EMAIL, $details['EMAIL'], $permissions); +// } else if ($shareType === self::SHARE_TYPE_CONTACT) { +// if (!\OC_App::isEnabled('contacts')) { +// $message = 'Sharing '.$itemSource.' failed, because the contacts app is not enabled'; +// \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); +// return false; +// } +// $vcard = \OC_Contacts_App::getContactVCard($shareWith); +// if (!isset($vcard)) { +// $message = 'Sharing '.$itemSource.' failed, because the contact does not exist'; +// \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); +// throw new \Exception($message); +// } +// $details = \OC_Contacts_VCard::structureContact($vcard); +// // TODO Add ownCloud user to contacts vcard +// if (!isset($details['EMAIL'])) { +// $message = 'Sharing '.$itemSource.' failed, because no email address is associated with the contact'; +// \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); +// throw new \Exception($message); +// } +// return self::shareItem($itemType, $itemSource, self::SHARE_TYPE_EMAIL, $details['EMAIL'], $permissions); } else { // Future share types need to include their own conditions $message = 'Share type '.$shareType.' is not valid for '.$itemSource; @@ -337,10 +337,21 @@ class Share { public static function unshareFromSelf($itemType, $itemTarget) { if ($item = self::getItemSharedWith($itemType, $itemTarget)) { if ((int)$item['share_type'] === self::SHARE_TYPE_GROUP) { - // TODO + // Insert an extra row for the group share and set permission to 0 to prevent it from showing up for the user + $query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (`item_type`, `item_source`, `item_target`, `parent`, `share_type`, `share_with`, `uid_owner`, `permissions`, `stime`, `file_source`, `file_target`) VALUES (?,?,?,?,?,?,?,?,?,?,?)'); + $query->execute(array($item['item_type'], $item['item_source'], $item['item_target'], $item['id'], self::$shareTypeGroupUserUnique, \OC_User::getUser(), $item['uid_owner'], 0, $item['stime'], $item['file_source'], $item['file_target'])); + \OC_DB::insertid('*PREFIX*share'); + // Delete all reshares by this user of the group share + self::delete($item['id'], true, \OC_User::getUser()); + } else if ((int)$item['share_type'] === self::$shareTypeGroupUserUnique) { + // Set permission to 0 to prevent it from showing up for the user + $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `permissions` = ? WHERE `id` = ?'); + $query->execute(array(0, $item['id'])); + self::delete($item['id'], true); + } else { + self::delete($item['id']); } - // Delete - return self::delete($item['id']); + return true; } return false; } @@ -406,6 +417,16 @@ class Share { throw new \Exception($message); } + public static function setExpirationDate($itemType, $itemSource, $date) { + if ($item = self::getItems($itemType, $itemSource, null, null, \OC_User::getUser(), self::FORMAT_NONE, null, 1, false)) { + error_log('setting'); + $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `expiration` = ? WHERE `id` = ?'); + $query->execute(array($date, $item['id'])); + return true; + } + return false; + } + /** * @brief Get the backend class for the specified item type * @param string Item type @@ -447,8 +468,11 @@ class Share { $collectionTypes[] = $type; } } - if (count($collectionTypes) > 1) { + if (!self::getBackend($itemType) instanceof Share_Backend_Collection) { unset($collectionTypes[0]); + } + // Return array if collections were found or the item type is a collection itself - collections can be inside collections + if (count($collectionTypes) > 0) { return $collectionTypes; } return false; @@ -493,9 +517,13 @@ class Share { $root = ''; if ($includeCollections && !isset($item) && ($collectionTypes = self::getCollectionItemTypes($itemType))) { // If includeCollections is true, find collections of this item type, e.g. a music album contains songs - $itemTypes = array_merge(array($itemType), $collectionTypes); + if (!in_array($itemType, $collectionTypes)) { + $itemTypes = array_merge(array($itemType), $collectionTypes); + } else { + $itemTypes = $collectionTypes; + } $placeholders = join(',', array_fill(0, count($itemTypes), '?')); - $where = ' WHERE `item_type` IN ('.$placeholders.')'; + $where .= ' WHERE item_type IN ('.$placeholders.'))'; $queryArgs = $itemTypes; } else { $where = ' WHERE `item_type` = ?'; @@ -570,7 +598,7 @@ class Share { } } $queryArgs[] = $item; - if ($includeCollections && $collectionTypes = self::getCollectionItemTypes($itemType)) { + if ($includeCollections && $collectionTypes) { $placeholders = join(',', array_fill(0, count($collectionTypes), '?')); $where .= ' OR item_type IN ('.$placeholders.'))'; $queryArgs = array_merge($queryArgs, $collectionTypes); @@ -594,23 +622,23 @@ class Share { // TODO Optimize selects if ($format == self::FORMAT_STATUSES) { if ($itemType == 'file' || $itemType == 'folder') { - $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `share_type`, `file_source`, `path`'; + $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `share_type`, `file_source`, `path`, `expiration`'; } else { - $select = '`id`, `item_type`, `item_source`, `parent`, `share_type`'; + $select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `expiration`'; } } else { if (isset($uidOwner)) { if ($itemType == 'file' || $itemType == 'folder') { - $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `file_source`, `path`, `permissions`, `stime`'; + $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `file_source`, `path`, `permissions`, `stime`, `expiration`'; } else { - $select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `share_with`, `permissions`, `stime`, `file_source`'; + $select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `share_with`, `permissions`, `stime`, `file_source`, `expiration`'; } } else { if ($fileDependent) { if (($itemType == 'file' || $itemType == 'folder') && $format == \OC_Share_Backend_File::FORMAT_FILE_APP || $format == \OC_Share_Backend_File::FORMAT_FILE_APP_ROOT) { - $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `file_source`, `path`, `file_target`, `permissions`, `name`, `ctime`, `mtime`, `mimetype`, `size`, `encrypted`, `versioned`, `writable`'; + $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `file_source`, `path`, `file_target`, `permissions`, `expiration`, `name`, `ctime`, `mtime`, `mimetype`, `size`, `encrypted`, `versioned`, `writable`'; } else { - $select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `item_target`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `uid_owner`, `file_source`, `path`, `file_target`, `permissions`, `stime`'; + $select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `item_target`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `uid_owner`, `file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`'; } } else { $select = '*'; @@ -629,6 +657,9 @@ class Share { $row['share_with'] = $items[$row['parent']]['share_with']; // Remove the parent group share unset($items[$row['parent']]); + if ($row['permissions'] == 0) { + continue; + } } else if (!isset($uidOwner)) { // Check if the same target already exists if (isset($targets[$row[$column]])) { @@ -662,6 +693,13 @@ class Share { $row['path'] = substr($row['path'], $root); } } + if (isset($row['expiration'])) { + $time = new \DateTime(); + if ($row['expiration'] < date('Y-m-d H:i', $time->format('U') - $time->getOffset())) { + self::delete($row['id']); + continue; + } + } $items[$row['id']] = $row; } if (!empty($items)) { @@ -676,29 +714,54 @@ class Share { } } // Check if this is a collection of the requested item type - if ($includeCollections && $row['item_type'] != $itemType) { + if ($includeCollections && $collectionTypes && in_array($row['item_type'], $collectionTypes)) { if (($collectionBackend = self::getBackend($row['item_type'])) && $collectionBackend instanceof Share_Backend_Collection) { - $row['collection'] = array('item_type' => $itemType, $column => $row[$column]); - // Fetch all of the children sources - $children = $collectionBackend->getChildren($row[$column]); - foreach ($children as $child) { - $childItem = $row; - $childItem['item_source'] = $child; - // $childItem['item_target'] = $child['target']; TODO - if (isset($item)) { - if ($childItem[$column] == $item) { - // Return only the item instead of a 2-dimensional array - if ($limit == 1 && $format == self::FORMAT_NONE) { - return $childItem; + // Collections can be inside collections, check if the item is a collection + if (isset($item) && $row['item_type'] == $itemType && $row[$column] == $item) { + $collectionItems[] = $row; + } else { + $collection = array(); + $collection['item_type'] = $row['item_type']; + if ($row['item_type'] == 'file' || $row['item_type'] == 'folder') { + $collection['path'] = basename($row['path']); + } + $row['collection'] = $collection; + // Fetch all of the children sources + $children = $collectionBackend->getChildren($row[$column]); + foreach ($children as $child) { + $childItem = $row; + $childItem['item_type'] = $itemType; + if ($row['item_type'] != 'file' && $row['item_type'] != 'folder') { + $childItem['item_source'] = $child['source']; + $childItem['item_target'] = $child['target']; + } + if ($backend instanceof Share_Backend_File_Dependent) { + if ($row['item_type'] == 'file' || $row['item_type'] == 'folder') { + $childItem['file_source'] = $child['source']; } else { - // Unset the items array and break out of both loops - $items = array(); - $items[] = $childItem; - break 2; + $childItem['file_source'] = \OC_FileCache::getId($child['file_path']); } + $childItem['file_target'] = \OC_Filesystem::normalizePath($child['file_path']); + } + if (isset($item)) { + if ($childItem[$column] == $item) { + // Return only the item instead of a 2-dimensional array + if ($limit == 1) { + if ($format == self::FORMAT_NONE) { + return $childItem; + } else { + // Unset the items array and break out of both loops + $items = array(); + $items[] = $childItem; + break 2; + } + } else { + $collectionItems[] = $childItem; + } + } + } else { + $collectionItems[] = $childItem; } - } else { - $collectionItems[] = $childItem; } } } @@ -848,6 +911,7 @@ class Share { // Insert an extra row for the group share if the item or file target is unique for this user if ($itemTarget != $groupItemTarget || (isset($fileSource) && $fileTarget != $groupFileTarget)) { $query->execute(array($itemType, $itemSource, $itemTarget, $parent, self::$shareTypeGroupUserUnique, $uid, $uidOwner, $permissions, time(), $fileSource, $fileTarget)); + \OC_DB::insertid('*PREFIX*share'); } } if ($parentFolder === true) { @@ -1153,7 +1217,7 @@ interface Share_Backend_Collection extends Share_Backend { /** * @brief Get the sources of the children of the item * @param string Item source - * @return array Returns an array of sources + * @return array Returns an array of children each inside an array with the keys: source, target, and file_path if applicable */ public function getChildren($itemSource); diff --git a/lib/public/user.php b/lib/public/user.php index b530321f21d..b320ce8ea0c 100644 --- a/lib/public/user.php +++ b/lib/public/user.php @@ -34,8 +34,6 @@ namespace OCP; * This class provides access to the user management. You can get information about the currently logged in user and the permissions for example */ class User { - - /** * @brief get the user id of the user currently logged in. * @return string uid or false @@ -44,7 +42,6 @@ class User { return \OC_USER::getUser(); } - /** * @brief Get a list of all users * @returns array with all uids @@ -55,7 +52,6 @@ class User { return \OC_USER::getUsers(); } - /** * @brief Check if the user is logged in * @returns true/false @@ -66,7 +62,6 @@ class User { return \OC_USER::isLoggedIn(); } - /** * @brief check if a user exists * @param string $uid the username @@ -76,7 +71,6 @@ class User { return \OC_USER::userExists( $uid ); } - /** * @brief Loggs the user out including all the session data * @returns true @@ -87,7 +81,6 @@ class User { return \OC_USER::logout(); } - /** * @brief Check if the password is correct * @param $uid The username @@ -100,23 +93,18 @@ class User { return \OC_USER::checkPassword( $uid, $password ); } + /** + * Check if the user is a admin, redirects to home if not + */ + public static function checkAdminUser() { + \OC_Util::checkAdminUser(); + } - /** - * Check if the user is a admin, redirects to home if not - */ - public static function checkAdminUser() { - \OC_Util::checkAdminUser(); - } - - - /** - * Check if the user is logged in, redirects to home if not. With - * redirect URL parameter to the request URI. - */ - public static function checkLoggedIn() { - \OC_Util::checkLoggedIn(); - } - - - + /** + * Check if the user is logged in, redirects to home if not. With + * redirect URL parameter to the request URI. + */ + public static function checkLoggedIn() { + \OC_Util::checkLoggedIn(); + } } diff --git a/lib/public/util.php b/lib/public/util.php index ed23521b040..747448e62eb 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -34,8 +34,6 @@ namespace OCP; * This class provides different helper functions to make the life of a developer easier */ class Util { - - // consts for Logging const DEBUG=0; const INFO=1; @@ -43,7 +41,6 @@ class Util { const ERROR=3; const FATAL=4; - /** * @brief get the current installed version of ownCloud * @return array @@ -52,7 +49,6 @@ class Util { return(\OC_Util::getVersion()); } - /** * @brief send an email * @param string $toaddress @@ -68,18 +64,16 @@ class Util { \OC_MAIL::send( $toaddress, $toname, $subject, $mailtext, $fromaddress, $fromname, $html=0, $altbody='', $ccaddress='', $ccname='', $bcc=''); } - - /** + /** * @brief write a message in the log * @param string $app * @param string $message * @param int level - */ - public static function writeLog( $app, $message, $level ) { - // call the internal log class - \OC_LOG::write( $app, $message, $level ); - } - + */ + public static function writeLog( $app, $message, $level ) { + // call the internal log class + \OC_LOG::write( $app, $message, $level ); + } /** * @brief add a css file @@ -87,8 +81,7 @@ class Util { */ public static function addStyle( $application, $file = null ) { \OC_Util::addStyle( $application, $file ); - } - + } /** * @brief add a javascript file @@ -97,7 +90,7 @@ class Util { */ public static function addScript( $application, $file = null ) { \OC_Util::addScript( $application, $file ); - } + } /** * @brief Add a custom element to the header @@ -118,8 +111,6 @@ class Util { return(\OC_Util::formatDate( $timestamp,$dateOnly )); } - - /** * @brief Creates an absolute url * @param $app app @@ -133,7 +124,6 @@ class Util { return(\OC_Helper::linkToAbsolute( $app, $file, $args )); } - /** * @brief Creates an absolute url for remote use * @param $service id @@ -156,7 +146,6 @@ class Util { return \OC_Helper::linkToPublic($service); } - /** * @brief Creates an url * @param $app app @@ -199,11 +188,10 @@ class Util { * * Returns the path to the image. */ - public static function imagePath( $app, $image ) { + public static function imagePath( $app, $image ) { return(\OC_Helper::imagePath( $app, $image )); } - /** * @brief Make a human file size * @param $bytes file size in bytes @@ -244,7 +232,6 @@ class Util { return(\OC_Hook::connect( $signalclass, $signalname, $slotclass, $slotname )); } - /** * @brief emitts a signal * @param $signalclass class name of emitter @@ -260,7 +247,6 @@ class Util { return(\OC_Hook::emit( $signalclass, $signalname, $params )); } - /** * Register an get/post call. This is important to prevent CSRF attacks * TODO: write example @@ -269,7 +255,6 @@ class Util { return(\OC_Util::callRegister()); } - /** * Check an ajax get/post call if the request token is valid. exit if not. * Todo: Write howto diff --git a/lib/setup.php b/lib/setup.php index f27254a42a4..c21c8be3957 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -9,7 +9,7 @@ $opts = array( 'hasSQLite' => $hasSQLite, 'hasMySQL' => $hasMySQL, 'hasPostgreSQL' => $hasPostgreSQL, - 'hasOracle' => $hasOracle, + 'hasOracle' => $hasOracle, 'directory' => $datadir, 'errors' => array(), ); @@ -51,10 +51,10 @@ class OC_Setup { if($dbtype=='mysql' or $dbtype == 'pgsql' or $dbtype == 'oci') { //mysql and postgresql needs more config options if($dbtype=='mysql') $dbprettyname = 'MySQL'; - else if($dbtype=='pgsql') - $dbprettyname = 'PostgreSQL'; - else - $dbprettyname = 'Oracle'; + else if($dbtype=='pgsql') + $dbprettyname = 'PostgreSQL'; + else + $dbprettyname = 'Oracle'; if(empty($options['dbuser'])) { @@ -63,7 +63,7 @@ class OC_Setup { if(empty($options['dbname'])) { $error[] = "$dbprettyname enter the database name."; } - if(empty($options['dbhost'])) { + if($dbtype != 'oci' && empty($options['dbhost'])) { $error[] = "$dbprettyname set the database host."; } } @@ -232,117 +232,125 @@ class OC_Setup { } } } - elseif($dbtype == 'oci') { - $dbuser = $options['dbuser']; - $dbpass = $options['dbpass']; - $dbname = $options['dbname']; - $dbtablespace = $options['dbtablespace']; - $dbhost = $options['dbhost']; - $dbtableprefix = isset($options['dbtableprefix']) ? $options['dbtableprefix'] : 'oc_'; - OC_CONFIG::setValue('dbname', $dbname); - OC_CONFIG::setValue('dbtablespace', $dbtablespace); - OC_CONFIG::setValue('dbhost', $dbhost); - OC_CONFIG::setValue('dbtableprefix', $dbtableprefix); - - $e_host = addslashes($dbhost); - $e_dbname = addslashes($dbname); - //check if the database user has admin right - $connection_string = '//'.$e_host.'/'.$e_dbname; - $connection = @oci_connect($dbuser, $dbpass, $connection_string); - if(!$connection) { - $e = oci_error(); - $error[] = array( - 'error' => 'Oracle username and/or password not valid', - 'hint' => 'You need to enter either an existing account or the administrator.' - ); - return $error; - } else { - //check for roles creation rights in oracle - - $query="SELECT count(*) FROM user_role_privs, role_sys_privs WHERE user_role_privs.granted_role = role_sys_privs.role AND privilege = 'CREATE ROLE'"; - $stmt = oci_parse($connection, $query); - if (!$stmt) { - $entry='DB Error: "'.oci_last_error($connection).'"<br />'; - $entry.='Offending command was: '.$query.'<br />'; - echo($entry); - } - $result = oci_execute($stmt); - if($result) { - $row = oci_fetch_row($stmt); - } - if($result and $row[0] > 0) { - //use the admin login data for the new database user - - //add prefix to the oracle user name to prevent collisions - $dbusername='oc_'.$username; - //create a new password so we don't need to store the admin config in the config file - $dbpassword=md5(time().$dbpass); - - //oracle passwords are treated as identifiers: - // must start with aphanumeric char - // needs to be shortened to 30 bytes, as the two " needed to escape the identifier count towards the identifier length. - $dbpassword=substr($dbpassword, 0, 30); - - self::oci_createDBUser($dbusername, $dbpassword, $dbtablespace, $connection); - - OC_CONFIG::setValue('dbuser', $dbusername); - OC_CONFIG::setValue('dbname', $dbusername); - OC_CONFIG::setValue('dbpassword', $dbpassword); - - //create the database not neccessary, oracle implies user = schema - //self::oci_createDatabase($dbname, $dbusername, $connection); - } else { - - OC_CONFIG::setValue('dbuser', $dbuser); - OC_CONFIG::setValue('dbname', $dbname); - OC_CONFIG::setValue('dbpassword', $dbpass); - - //create the database not neccessary, oracle implies user = schema - //self::oci_createDatabase($dbname, $dbuser, $connection); - } - - //FIXME check tablespace exists: select * from user_tablespaces - - // the connection to dbname=oracle is not needed anymore - oci_close($connection); - - // connect to the oracle database (schema=$dbuser) an check if the schema needs to be filled - $dbuser = OC_CONFIG::getValue('dbuser'); - //$dbname = OC_CONFIG::getValue('dbname'); - $dbpass = OC_CONFIG::getValue('dbpassword'); - - $e_host = addslashes($dbhost); - $e_dbname = addslashes($dbname); - - $connection_string = '//'.$e_host.'/'.$e_dbname; - $connection = @oci_connect($dbuser, $dbpass, $connection_string); - if(!$connection) { - $error[] = array( - 'error' => 'Oracle username and/or password not valid', - 'hint' => 'You need to enter either an existing account or the administrator.' - ); - return $error; - } else { - $query = "SELECT count(*) FROM user_tables WHERE table_name = :un"; - $stmt = oci_parse($connection, $query); - $un = $dbtableprefix.'users'; - oci_bind_by_name($stmt, ':un', $un); - if (!$stmt) { - $entry='DB Error: "'.oci_last_error($connection).'"<br />'; - $entry.='Offending command was: '.$query.'<br />'; - echo($entry); - } - $result = oci_execute($stmt); - - if($result) { - $row = oci_fetch_row($stmt); - } - if(!$result or $row[0]==0) { - OC_DB::createDbFromStructure('db_structure.xml'); - } - } - } - } + elseif($dbtype == 'oci') { + $dbuser = $options['dbuser']; + $dbpass = $options['dbpass']; + $dbname = $options['dbname']; + $dbtablespace = $options['dbtablespace']; + $dbhost = isset($options['dbhost'])?$options['dbhost']:''; + $dbtableprefix = isset($options['dbtableprefix']) ? $options['dbtableprefix'] : 'oc_'; + OC_CONFIG::setValue('dbname', $dbname); + OC_CONFIG::setValue('dbtablespace', $dbtablespace); + OC_CONFIG::setValue('dbhost', $dbhost); + OC_CONFIG::setValue('dbtableprefix', $dbtableprefix); + + $e_host = addslashes($dbhost); + $e_dbname = addslashes($dbname); + //check if the database user has admin right + if ($e_host == '') { + $easy_connect_string = $e_dbname; // use dbname as easy connect name + } else { + $easy_connect_string = '//'.$e_host.'/'.$e_dbname; + } + $connection = @oci_connect($dbuser, $dbpass, $easy_connect_string); + if(!$connection) { + $e = oci_error(); + $error[] = array( + 'error' => 'Oracle username and/or password not valid', + 'hint' => 'You need to enter either an existing account or the administrator.' + ); + return $error; + } else { + //check for roles creation rights in oracle + + $query="SELECT count(*) FROM user_role_privs, role_sys_privs WHERE user_role_privs.granted_role = role_sys_privs.role AND privilege = 'CREATE ROLE'"; + $stmt = oci_parse($connection, $query); + if (!$stmt) { + $entry='DB Error: "'.oci_last_error($connection).'"<br />'; + $entry.='Offending command was: '.$query.'<br />'; + echo($entry); + } + $result = oci_execute($stmt); + if($result) { + $row = oci_fetch_row($stmt); + } + if($result and $row[0] > 0) { + //use the admin login data for the new database user + + //add prefix to the oracle user name to prevent collisions + $dbusername='oc_'.$username; + //create a new password so we don't need to store the admin config in the config file + $dbpassword=md5(time().$dbpass); + + //oracle passwords are treated as identifiers: + // must start with aphanumeric char + // needs to be shortened to 30 bytes, as the two " needed to escape the identifier count towards the identifier length. + $dbpassword=substr($dbpassword, 0, 30); + + self::oci_createDBUser($dbusername, $dbpassword, $dbtablespace, $connection); + + OC_CONFIG::setValue('dbuser', $dbusername); + OC_CONFIG::setValue('dbname', $dbusername); + OC_CONFIG::setValue('dbpassword', $dbpassword); + + //create the database not neccessary, oracle implies user = schema + //self::oci_createDatabase($dbname, $dbusername, $connection); + } else { + + OC_CONFIG::setValue('dbuser', $dbuser); + OC_CONFIG::setValue('dbname', $dbname); + OC_CONFIG::setValue('dbpassword', $dbpass); + + //create the database not neccessary, oracle implies user = schema + //self::oci_createDatabase($dbname, $dbuser, $connection); + } + + //FIXME check tablespace exists: select * from user_tablespaces + + // the connection to dbname=oracle is not needed anymore + oci_close($connection); + + // connect to the oracle database (schema=$dbuser) an check if the schema needs to be filled + $dbuser = OC_CONFIG::getValue('dbuser'); + //$dbname = OC_CONFIG::getValue('dbname'); + $dbpass = OC_CONFIG::getValue('dbpassword'); + + $e_host = addslashes($dbhost); + $e_dbname = addslashes($dbname); + + if ($e_host == '') { + $easy_connect_string = $e_dbname; // use dbname as easy connect name + } else { + $easy_connect_string = '//'.$e_host.'/'.$e_dbname; + } + $connection = @oci_connect($dbuser, $dbpass, $easy_connect_string); + if(!$connection) { + $error[] = array( + 'error' => 'Oracle username and/or password not valid', + 'hint' => 'You need to enter either an existing account or the administrator.' + ); + return $error; + } else { + $query = "SELECT count(*) FROM user_tables WHERE table_name = :un"; + $stmt = oci_parse($connection, $query); + $un = $dbtableprefix.'users'; + oci_bind_by_name($stmt, ':un', $un); + if (!$stmt) { + $entry='DB Error: "'.oci_last_error($connection).'"<br />'; + $entry.='Offending command was: '.$query.'<br />'; + echo($entry); + } + $result = oci_execute($stmt); + + if($result) { + $row = oci_fetch_row($stmt); + } + if(!$result or $row[0]==0) { + OC_DB::createDbFromStructure('db_structure.xml'); + } + } + } + } else { //delete the old sqlite database first, might cause infinte loops otherwise if(file_exists("$datadir/owncloud.db")) { @@ -462,79 +470,79 @@ class OC_Setup { } } } - /** - * - * @param String $name - * @param String $password - * @param String $tablespace - * @param resource $connection - */ - private static function oci_createDBUser($name, $password, $tablespace, $connection) { - - $query = "SELECT * FROM all_users WHERE USERNAME = :un"; - $stmt = oci_parse($connection, $query); - if (!$stmt) { - $entry='DB Error: "'.oci_error($connection).'"<br />'; - $entry.='Offending command was: '.$query.'<br />'; - echo($entry); - } - oci_bind_by_name($stmt, ':un', $name); - $result = oci_execute($stmt); - if(!$result) { - $entry='DB Error: "'.oci_error($connection).'"<br />'; - $entry.='Offending command was: '.$query.'<br />'; - echo($entry); - } - - if(! oci_fetch_row($stmt)) { - //user does not exists let's create it :) - //password must start with alphabetic character in oracle - $query = 'CREATE USER '.$name.' IDENTIFIED BY "'.$password.'" DEFAULT TABLESPACE '.$tablespace; //TODO set default tablespace - $stmt = oci_parse($connection, $query); - if (!$stmt) { - $entry='DB Error: "'.oci_error($connection).'"<br />'; - $entry.='Offending command was: '.$query.'<br />'; - echo($entry); - } - //oci_bind_by_name($stmt, ':un', $name); - $result = oci_execute($stmt); - if(!$result) { - $entry='DB Error: "'.oci_error($connection).'"<br />'; - $entry.='Offending command was: '.$query.', name:'.$name.', password:'.$password.'<br />'; - echo($entry); - } - } else { // change password of the existing role - $query = "ALTER USER :un IDENTIFIED BY :pw"; - $stmt = oci_parse($connection, $query); - if (!$stmt) { - $entry='DB Error: "'.oci_error($connection).'"<br />'; - $entry.='Offending command was: '.$query.'<br />'; - echo($entry); - } - oci_bind_by_name($stmt, ':un', $name); - oci_bind_by_name($stmt, ':pw', $password); - $result = oci_execute($stmt); - if(!$result) { - $entry='DB Error: "'.oci_error($connection).'"<br />'; - $entry.='Offending command was: '.$query.'<br />'; - echo($entry); - } - } - // grant neccessary roles - $query = 'GRANT CREATE SESSION, CREATE TABLE, CREATE SEQUENCE, CREATE TRIGGER, UNLIMITED TABLESPACE TO '.$name; - $stmt = oci_parse($connection, $query); - if (!$stmt) { - $entry='DB Error: "'.oci_error($connection).'"<br />'; - $entry.='Offending command was: '.$query.'<br />'; - echo($entry); - } - $result = oci_execute($stmt); - if(!$result) { - $entry='DB Error: "'.oci_error($connection).'"<br />'; - $entry.='Offending command was: '.$query.', name:'.$name.', password:'.$password.'<br />'; - echo($entry); - } - } + /** + * + * @param String $name + * @param String $password + * @param String $tablespace + * @param resource $connection + */ + private static function oci_createDBUser($name, $password, $tablespace, $connection) { + + $query = "SELECT * FROM all_users WHERE USERNAME = :un"; + $stmt = oci_parse($connection, $query); + if (!$stmt) { + $entry='DB Error: "'.oci_error($connection).'"<br />'; + $entry.='Offending command was: '.$query.'<br />'; + echo($entry); + } + oci_bind_by_name($stmt, ':un', $name); + $result = oci_execute($stmt); + if(!$result) { + $entry='DB Error: "'.oci_error($connection).'"<br />'; + $entry.='Offending command was: '.$query.'<br />'; + echo($entry); + } + + if(! oci_fetch_row($stmt)) { + //user does not exists let's create it :) + //password must start with alphabetic character in oracle + $query = 'CREATE USER '.$name.' IDENTIFIED BY "'.$password.'" DEFAULT TABLESPACE '.$tablespace; //TODO set default tablespace + $stmt = oci_parse($connection, $query); + if (!$stmt) { + $entry='DB Error: "'.oci_error($connection).'"<br />'; + $entry.='Offending command was: '.$query.'<br />'; + echo($entry); + } + //oci_bind_by_name($stmt, ':un', $name); + $result = oci_execute($stmt); + if(!$result) { + $entry='DB Error: "'.oci_error($connection).'"<br />'; + $entry.='Offending command was: '.$query.', name:'.$name.', password:'.$password.'<br />'; + echo($entry); + } + } else { // change password of the existing role + $query = "ALTER USER :un IDENTIFIED BY :pw"; + $stmt = oci_parse($connection, $query); + if (!$stmt) { + $entry='DB Error: "'.oci_error($connection).'"<br />'; + $entry.='Offending command was: '.$query.'<br />'; + echo($entry); + } + oci_bind_by_name($stmt, ':un', $name); + oci_bind_by_name($stmt, ':pw', $password); + $result = oci_execute($stmt); + if(!$result) { + $entry='DB Error: "'.oci_error($connection).'"<br />'; + $entry.='Offending command was: '.$query.'<br />'; + echo($entry); + } + } + // grant neccessary roles + $query = 'GRANT CREATE SESSION, CREATE TABLE, CREATE SEQUENCE, CREATE TRIGGER, UNLIMITED TABLESPACE TO '.$name; + $stmt = oci_parse($connection, $query); + if (!$stmt) { + $entry='DB Error: "'.oci_error($connection).'"<br />'; + $entry.='Offending command was: '.$query.'<br />'; + echo($entry); + } + $result = oci_execute($stmt); + if(!$result) { + $entry='DB Error: "'.oci_error($connection).'"<br />'; + $entry.='Offending command was: '.$query.', name:'.$name.', password:'.$password.'<br />'; + echo($entry); + } + } /** * create .htaccess files for apache hosts diff --git a/lib/template.php b/lib/template.php index 8c872a2059b..76a0b372b3c 100644 --- a/lib/template.php +++ b/lib/template.php @@ -158,7 +158,8 @@ class OC_Template{ if($renderas == 'user') { $this->vars['requesttoken'] = OC_Util::callRegister(); } - $this->l10n = OC_L10N::get($app); + $parts = explode('/', $app); // fix translation when app is something like core/lostpassword + $this->l10n = OC_L10N::get($parts[0]); header('X-Frame-Options: Sameorigin'); header('X-XSS-Protection: 1; mode=block'); header('X-Content-Type-Options: nosniff'); diff --git a/lib/templatelayout.php b/lib/templatelayout.php index d72f5552fde..c898628bcdf 100644 --- a/lib/templatelayout.php +++ b/lib/templatelayout.php @@ -41,7 +41,7 @@ class OC_TemplateLayout extends OC_Template { } $this->assign( 'apps_paths', str_replace('\\/', '/',json_encode($apps_paths)),false ); // Ugly unescape slashes waiting for better solution - if (!OC_AppConfig::getValue('core', 'remote_core.css', false)) { + if (OC_Config::getValue('installed', false) && !OC_AppConfig::getValue('core', 'remote_core.css', false)) { OC_AppConfig::setValue('core', 'remote_core.css', '/core/minimizer.php'); OC_AppConfig::setValue('core', 'remote_core.js', '/core/minimizer.php'); } diff --git a/lib/user.php b/lib/user.php index 89dab9f9647..7de2a4b7fe6 100644 --- a/lib/user.php +++ b/lib/user.php @@ -416,9 +416,16 @@ class OC_User { * @param string $userid the user to disable */ public static function disableUser($userid) { - $query = "INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, `configkey`, `configvalue`) VALUES(?, ?, ?, ?)"; - $query = OC_DB::prepare($query); - $query->execute(array($userid, 'core', 'enabled', 'false')); + $sql = "INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, `configkey`, `configvalue`) VALUES(?, ?, ?, ?)"; + $stmt = OC_DB::prepare($sql); + if ( ! OC_DB::isError($stmt) ) { + $result = $stmt->execute(array($userid, 'core', 'enabled', 'false')); + if ( OC_DB::isError($result) ) { + OC_Log::write('OC_User', 'could not enable user: '. OC_DB::getErrorMessage($result), OC_Log::ERROR); + } + } else { + OC_Log::write('OC_User', 'could not disable user: '. OC_DB::getErrorMessage($stmt), OC_Log::ERROR); + } } /** @@ -426,9 +433,16 @@ class OC_User { * @param string $userid */ public static function enableUser($userid) { - $query = "DELETE FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ? AND `configvalue` = ?"; - $query = OC_DB::prepare($query); - $query->execute(array($userid, 'core', 'enabled', 'false')); + $sql = "DELETE FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ? AND `configvalue` = ?"; + $stmt = OC_DB::prepare($sql); + if ( ! OC_DB::isError($stmt) ) { + $result = $stmt->execute(array($userid, 'core', 'enabled', 'false')); + if ( OC_DB::isError($result) ) { + OC_Log::write('OC_User', 'could not enable user: '. OC_DB::getErrorMessage($result), OC_Log::ERROR); + } + } else { + OC_Log::write('OC_User', 'could not enable user: '. OC_DB::getErrorMessage($stmt), OC_Log::ERROR); + } } /** @@ -437,10 +451,19 @@ class OC_User { * @return bool */ public static function isEnabled($userid) { - $query = "SELECT `userid` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ? AND `configvalue` = ?"; - $query = OC_DB::prepare($query); - $results = $query->execute(array($userid, 'core', 'enabled', 'false')); - return $results->numRows() ? false : true; + $sql = "SELECT `userid` FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ? AND `configvalue` = ?"; + $stmt = OC_DB::prepare($sql); + if ( ! OC_DB::isError($stmt) ) { + $result = $stmt->execute(array($userid, 'core', 'enabled', 'false')); + if ( ! OC_DB::isError($result) ) { + return $result->numRows() ? false : true; + } else { + OC_Log::write('OC_User', 'could not check if enabled: '. OC_DB::getErrorMessage($result), OC_Log::ERROR); + } + } else { + OC_Log::write('OC_User', 'could not check if enabled: '. OC_DB::getErrorMessage($stmt), OC_Log::ERROR); + } + return false; } /** diff --git a/lib/user/database.php b/lib/user/database.php index 76b44a2f6ca..25e24fcf7e4 100644 --- a/lib/user/database.php +++ b/lib/user/database.php @@ -155,7 +155,7 @@ class OC_User_Database extends OC_User_Backend { * Get a list of all users. */ public function getUsers($search = '', $limit = null, $offset = null) { - $query = OC_DB::prepare('SELECT `uid` FROM `*PREFIX*users` WHERE `uid` LIKE ?',$limit,$offset); + $query = OC_DB::prepare('SELECT `uid` FROM `*PREFIX*users` WHERE LOWER(`uid`) LIKE LOWER(?)',$limit,$offset); $result = $query->execute(array($search.'%')); $users = array(); while ($row = $result->fetchRow()) { diff --git a/lib/util.php b/lib/util.php index 78976c96606..a8d2fcedd20 100755 --- a/lib/util.php +++ b/lib/util.php @@ -81,7 +81,7 @@ class OC_Util { */ public static function getVersion() { // hint: We only can count up. So the internal version number of ownCloud 4.5 will be 4,9,0. This is not visible to the user - return array(4,83,6); + return array(4,84,10); } /** @@ -89,7 +89,7 @@ class OC_Util { * @return string */ public static function getVersionString() { - return '4.5 beta 2'; + return '4.5 beta 4'; } /** @@ -200,22 +200,24 @@ class OC_Util { public static function checkServer() { $errors=array(); + $web_server_restart= false; //check for database drivers if(!(is_callable('sqlite_open') or class_exists('SQLite3')) and !is_callable('mysql_connect') and !is_callable('pg_connect')) { $errors[]=array('error'=>'No database drivers (sqlite, mysql, or postgresql) installed.<br/>','hint'=>'');//TODO: sane hint + $web_server_restart= true; } //common hint for all file permissons error messages $permissionsHint="Permissions can usually be fixed by giving the webserver write access to the ownCloud directory"; // Check if config folder is writable. - if(!is_writable(OC::$SERVERROOT."/config/")) { + if(!is_writable(OC::$SERVERROOT."/config/") or !is_readable(OC::$SERVERROOT."/config/")) { $errors[]=array('error'=>"Can't write into config directory 'config'",'hint'=>"You can usually fix this by giving the webserver user write access to the config directory in owncloud"); } // Check if there is a writable install folder. if(OC_Config::getValue('appstoreenabled', true)) { - if( OC_App::getInstallPath() === null || !is_writable(OC_App::getInstallPath())) { + if( OC_App::getInstallPath() === null || !is_writable(OC_App::getInstallPath()) || !is_readable(OC_App::getInstallPath()) ) { $errors[]=array('error'=>"Can't write into apps directory",'hint'=>"You can usually fix this by giving the webserver user write access to the apps directory in owncloud or disabling the appstore in the config file."); } @@ -255,35 +257,47 @@ class OC_Util { if(!$success) { $errors[]=array('error'=>"Can't create data directory (".$CONFIG_DATADIRECTORY.")",'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' "); } - } else if(!is_writable($CONFIG_DATADIRECTORY)) { + } else if(!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) { $errors[]=array('error'=>'Data directory ('.$CONFIG_DATADIRECTORY.') not writable by ownCloud<br/>','hint'=>$permissionsHint); } // check if all required php modules are present if(!class_exists('ZipArchive')) { $errors[]=array('error'=>'PHP module zip not installed.<br/>','hint'=>'Please ask your server administrator to install the module.'); + $web_server_restart= false; } if(!function_exists('mb_detect_encoding')) { $errors[]=array('error'=>'PHP module mb multibyte not installed.<br/>','hint'=>'Please ask your server administrator to install the module.'); + $web_server_restart= false; } if(!function_exists('ctype_digit')) { $errors[]=array('error'=>'PHP module ctype is not installed.<br/>','hint'=>'Please ask your server administrator to install the module.'); + $web_server_restart= false; } if(!function_exists('json_encode')) { $errors[]=array('error'=>'PHP module JSON is not installed.<br/>','hint'=>'Please ask your server administrator to install the module.'); + $web_server_restart= false; } if(!function_exists('imagepng')) { $errors[]=array('error'=>'PHP module GD is not installed.<br/>','hint'=>'Please ask your server administrator to install the module.'); + $web_server_restart= false; } if(!function_exists('gzencode')) { $errors[]=array('error'=>'PHP module zlib is not installed.<br/>','hint'=>'Please ask your server administrator to install the module.'); + $web_server_restart= false; } if(floatval(phpversion())<5.3) { $errors[]=array('error'=>'PHP 5.3 is required.<br/>','hint'=>'Please ask your server administrator to update PHP to version 5.3 or higher. PHP 5.2 is no longer supported by ownCloud and the PHP community.'); + $web_server_restart= false; } if(!defined('PDO::ATTR_DRIVER_NAME')) { $errors[]=array('error'=>'PHP PDO module is not installed.<br/>','hint'=>'Please ask your server administrator to install the module.'); + $web_server_restart= false; + } + + if($web_server_restart) { + $errors[]=array('error'=>'PHP modules have been installed, but they are still listed as missing?<br/>','hint'=>'Please ask your server administrator to restart the web server.'); } return $errors; diff --git a/lib/vcategories.php b/lib/vcategories.php index f5123adeeb6..6b1d6a316f1 100644 --- a/lib/vcategories.php +++ b/lib/vcategories.php @@ -55,7 +55,10 @@ class OC_VCategories { $this->app = $app; $this->user = is_null($user) ? OC_User::getUser() : $user; $categories = trim(OC_Preferences::getValue($this->user, $app, self::PREF_CATEGORIES_LABEL, '')); - $this->categories = $categories != '' ? @unserialize($categories) : $defcategories; + if ($categories) { + $categories = @unserialize($categories); + } + $this->categories = is_array($categories) ? $categories : $defcategories; } /** |