* - versioned
*/
public static function get($path,$root=false) {
- if(OC_FileCache_Update::hasUpdated($path,$root)) {
+ if(OC_FileCache_Update::hasUpdated($path, $root)) {
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{
- OC_FileCache_Update::update($path,$root);
+ OC_FileCache_Update::update($path, $root);
}
}
- return OC_FileCache_Cached::get($path,$root);
+ return OC_FileCache_Cached::get($path, $root);
}
/**
}
$fullpath=$root.$path;
$parent=self::getParentId($fullpath);
- $id=self::getId($fullpath,'');
+ $id=self::getId($fullpath, '');
if(isset(OC_FileCache_Cached::$savedData[$fullpath])) {
- $data=array_merge(OC_FileCache_Cached::$savedData[$fullpath],$data);
+ $data=array_merge(OC_FileCache_Cached::$savedData[$fullpath], $data);
unset(OC_FileCache_Cached::$savedData[$fullpath]);
}
if($id!=-1) {
- self::update($id,$data);
+ self::update($id, $data);
return;
}
$query=OC_DB::prepare('INSERT INTO `*PREFIX*fscache`(`parent`, `name`, `path`, `path_hash`, `size`, `mtime`, `ctime`, `mimetype`, `mimepart`,`user`,`writable`,`encrypted`,`versioned`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)');
$result=$query->execute(array($parent,basename($fullpath),$fullpath,md5($fullpath),$data['size'],$data['mtime'],$data['ctime'],$data['mimetype'],$mimePart,$user,$data['writable'],$data['encrypted'],$data['versioned']));
if(OC_DB::isError($result)) {
- OC_Log::write('files','error while writing file('.$fullpath.') to cache',OC_Log::ERROR);
+ OC_Log::write('files', 'error while writing file('.$fullpath.') to cache', OC_Log::ERROR);
}
if($cache=OC_Cache::getUserCache(true)) {
}
$arguments[]=$id;
- $sql = 'UPDATE `*PREFIX*fscache` SET '.implode(' , ',$queryParts).' WHERE `id`=?';
+ $sql = 'UPDATE `*PREFIX*fscache` SET '.implode(' , ', $queryParts).' WHERE `id`=?';
$query=OC_DB::prepare($sql);
$result=$query->execute($arguments);
if(OC_DB::isError($result)) {
- OC_Log::write('files','error while updating file('.$id.') in cache',OC_Log::ERROR);
+ OC_Log::write('files', 'error while updating file('.$id.') in cache', OC_Log::ERROR);
}
}
$query->execute(array($newParent,basename($newPath),$newPath,md5($newPath),md5($oldPath)));
if(($cache=OC_Cache::getUserCache(true)) && $cache->hasKey('fileid/'.$oldPath)) {
- $cache->set('fileid/'.$newPath,$cache->get('fileid/'.$oldPath));
+ $cache->set('fileid/'.$newPath, $cache->get('fileid/'.$oldPath));
$cache->remove('fileid/'.$oldPath);
}
$updateQuery=OC_DB::prepare('UPDATE `*PREFIX*fscache` SET `path`=?, `path_hash`=? WHERE `path_hash`=?');
while($row= $query->execute(array($oldPath.'/%'))->fetchRow()) {
$old=$row['path'];
- $new=$newPath.substr($old,$oldLength);
+ $new=$newPath.substr($old, $oldLength);
$updateQuery->execute(array($new,md5($new),md5($old)));
if(($cache=OC_Cache::getUserCache(true)) && $cache->hasKey('fileid/'.$old)) {
- $cache->set('fileid/'.$new,$cache->get('fileid/'.$old));
+ $cache->set('fileid/'.$new, $cache->get('fileid/'.$old));
$cache->remove('fileid/'.$old);
}
}
$names=array();
while($row=$result->fetchRow()) {
if(!$returnData) {
- $names[]=substr($row['path'],$rootLen);
+ $names[]=substr($row['path'], $rootLen);
}else{
- $row['path']=substr($row['path'],$rootLen);
+ $row['path']=substr($row['path'], $rootLen);
$names[]=$row;
}
}
* - versioned
*/
public static function getFolderContent($path,$root=false,$mimetype_filter='') {
- if(OC_FileCache_Update::hasUpdated($path,$root,true)) {
- OC_FileCache_Update::updateFolder($path,$root);
+ if(OC_FileCache_Update::hasUpdated($path, $root, true)) {
+ OC_FileCache_Update::updateFolder($path, $root);
}
- return OC_FileCache_Cached::getFolderContent($path,$root,$mimetype_filter);
+ return OC_FileCache_Cached::getFolderContent($path, $root, $mimetype_filter);
}
/**
* @return bool
*/
public static function inCache($path,$root=false) {
- return self::getId($path,$root)!=-1;
+ return self::getId($path, $root)!=-1;
}
/**
$query=OC_DB::prepare('SELECT `id` FROM `*PREFIX*fscache` WHERE `path_hash`=?');
$result=$query->execute(array(md5($fullPath)));
if(OC_DB::isError($result)) {
- OC_Log::write('files','error while getting file id of '.$path,OC_Log::ERROR);
+ OC_Log::write('files', 'error while getting file id of '.$path, OC_Log::ERROR);
return -1;
}
$id=-1;
}
if($cache=OC_Cache::getUserCache(true)) {
- $cache->set('fileid/'.$fullPath,$id);
+ $cache->set('fileid/'.$fullPath, $id);
}
return $id;
$user=OC_User::getUser();
}
$query=OC_DB::prepare('SELECT `path` FROM `*PREFIX*fscache` WHERE `id`=? AND `user`=?');
- $result=$query->execute(array($id,$user));
+ $result=$query->execute(array($id, $user));
$row=$result->fetchRow();
$path=$row['path'];
$root='/'.$user.'/files';
- if(substr($path,0,strlen($root))!=$root) {
+ if(substr($path, 0, strlen($root))!=$root) {
return false;
}
- return substr($path,strlen($root));
+ return substr($path, strlen($root));
}
/**
if($path=='/') {
return -1;
}else{
- return self::getId(dirname($path),'');
+ return self::getId(dirname($path), '');
}
}
*/
public static function increaseSize($path,$sizeDiff, $root=false) {
if($sizeDiff==0) return;
- $id=self::getId($path,$root);
+ $id=self::getId($path, $root);
while($id!=-1) {//walk up the filetree increasing the size of all parent folders
$query=OC_DB::prepare('UPDATE `*PREFIX*fscache` SET `size`=`size`+? WHERE `id`=?');
$query->execute(array($sizeDiff,$id));
*/
public static function scan($path,$eventSource=false,&$count=0,$root=false) {
if($eventSource) {
- $eventSource->send('scanning',array('file'=>$path,'count'=>$count));
+ $eventSource->send('scanning', array('file'=>$path, 'count'=>$count));
}
$lastSend=$count;
// NOTE: Ugly hack to prevent shared files from going into the cache (the source already exists somewhere in the cache)
}else{
$view=new OC_FilesystemView($root);
}
- self::scanFile($path,$root);
+ self::scanFile($path, $root);
$dh=$view->opendir($path.'/');
$totalSize=0;
if($dh) {
if($filename != '.' and $filename != '..') {
$file=$path.'/'.$filename;
if($view->is_dir($file.'/')) {
- self::scan($file,$eventSource,$count,$root);
+ self::scan($file, $eventSource, $count, $root);
}else{
- $totalSize+=self::scanFile($file,$root);
+ $totalSize+=self::scanFile($file, $root);
$count++;
if($count>$lastSend+25 and $eventSource) {
$lastSend=$count;
- $eventSource->send('scanning',array('file'=>$path,'count'=>$count));
+ $eventSource->send('scanning', array('file'=>$path, 'count'=>$count));
}
}
}
if($path=='/') {
$path='';
}
- self::put($path,$stat,$root);
+ self::put($path, $stat, $root);
return $stat['size'];
}
$user=OC_User::getUser();
if(!$part2) {
$query=OC_DB::prepare('SELECT `path` FROM `*PREFIX*fscache` WHERE `mimepart`=? AND `user`=? AND `path` LIKE ?');
- $result=$query->execute(array($part1,$user, $root));
+ $result=$query->execute(array($part1, $user, $root));
}else{
$query=OC_DB::prepare('SELECT `path` FROM `*PREFIX*fscache` WHERE `mimetype`=? AND `user`=? AND `path` LIKE ? ');
- $result=$query->execute(array($part1.'/'.$part2,$user, $root));
+ $result=$query->execute(array($part1.'/'.$part2, $user, $root));
}
$names=array();
while($row=$result->fetchRow()) {
- $names[]=substr($row['path'],$rootLen);
+ $names[]=substr($row['path'], $rootLen);
}
return $names;
}
}
//watch for changes and try to keep the cache up to date
-OC_Hook::connect('OC_Filesystem','post_write','OC_FileCache_Update','fileSystemWatcherWrite');
-OC_Hook::connect('OC_Filesystem','post_delete','OC_FileCache_Update','fileSystemWatcherDelete');
-OC_Hook::connect('OC_Filesystem','post_rename','OC_FileCache_Update','fileSystemWatcherRename');
-OC_Hook::connect('OC_User','post_deleteUser','OC_FileCache_Update','deleteFromUser');
+OC_Hook::connect('OC_Filesystem', 'post_write', 'OC_FileCache_Update', 'fileSystemWatcherWrite');
+OC_Hook::connect('OC_Filesystem', 'post_delete', 'OC_FileCache_Update', 'fileSystemWatcherDelete');
+OC_Hook::connect('OC_Filesystem', 'post_rename', 'OC_FileCache_Update', 'fileSystemWatcherRename');
+OC_Hook::connect('OC_User', 'post_deleteUser', 'OC_FileCache_Update', 'deleteFromUser');
* @param boolean $only_header ; boolean to only send header of the request
*/
public static function get($dir,$files, $only_header = false) {
- if(strpos($files,';')) {
- $files=explode(';',$files);
+ if(strpos($files, ';')) {
+ $files=explode(';', $files);
}
if(is_array($files)) {
- self::validateZipDownload($dir,$files);
+ self::validateZipDownload($dir, $files);
$executionTime = intval(ini_get('max_execution_time'));
set_time_limit(0);
$zip = new ZipArchive();
if(OC_Filesystem::is_file($file)) {
$tmpFile=OC_Filesystem::toTmpFile($file);
self::$tmpFiles[]=$tmpFile;
- $zip->addFile($tmpFile,basename($file));
+ $zip->addFile($tmpFile, basename($file));
}elseif(OC_Filesystem::is_dir($file)) {
- self::zipAddDir($file,$zip);
+ self::zipAddDir($file, $zip);
}
}
$zip->close();
set_time_limit($executionTime);
}elseif(OC_Filesystem::is_dir($dir.'/'.$files)) {
- self::validateZipDownload($dir,$files);
+ self::validateZipDownload($dir, $files);
$executionTime = intval(ini_get('max_execution_time'));
set_time_limit(0);
$zip = new ZipArchive();
exit("cannot open <$filename>\n");
}
$file=$dir.'/'.$files;
- self::zipAddDir($file,$zip);
+ self::zipAddDir($file, $zip);
$zip->close();
set_time_limit($executionTime);
}else{
}elseif($zip or !OC_Filesystem::file_exists($filename)) {
header("HTTP/1.0 404 Not Found");
$tmpl = new OC_Template( '', '404', 'guest' );
- $tmpl->assign('file',$filename);
+ $tmpl->assign('file', $filename);
$tmpl->printPage();
}else{
header("HTTP/1.0 403 Forbidden");
return ;
}
if($zip) {
- $handle=fopen($filename,'r');
+ $handle=fopen($filename, 'r');
if ($handle) {
$chunkSize = 8*1024;// 1 MB chunks
while (!feof($handle)) {
if(OC_Filesystem::is_file($file)) {
$tmpFile=OC_Filesystem::toTmpFile($file);
OC_Files::$tmpFiles[]=$tmpFile;
- $zip->addFile($tmpFile,$internalDir.$filename);
+ $zip->addFile($tmpFile, $internalDir.$filename);
}elseif(OC_Filesystem::is_dir($file)) {
- self::zipAddDir($file,$zip,$internalDir);
+ self::zipAddDir($file, $zip, $internalDir);
}
}
}
if(OC_User::isLoggedIn() && ($sourceDir != '' || $source != 'Shared')) {
$targetFile=self::normalizePath($targetDir.'/'.$target);
$sourceFile=self::normalizePath($sourceDir.'/'.$source);
- return OC_Filesystem::rename($sourceFile,$targetFile);
+ return OC_Filesystem::rename($sourceFile, $targetFile);
} else {
return false;
}
if(OC_User::isLoggedIn()) {
$targetFile=$targetDir.'/'.$target;
$sourceFile=$sourceDir.'/'.$source;
- return OC_Filesystem::copy($sourceFile,$targetFile);
+ return OC_Filesystem::copy($sourceFile, $targetFile);
}
}
* @return string guessed mime type
*/
static function pull($source,$token,$dir,$file) {
- $tmpfile=tempnam(get_temp_dir(),'remoteCloudFile');
+ $tmpfile=tempnam(get_temp_dir(), 'remoteCloudFile');
$fp=fopen($tmpfile,'w+');
$url=$source.="/files/pull.php?token=$token";
$ch=curl_init();
- curl_setopt($ch,CURLOPT_URL,$url);
+ curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch);
fclose($fp);
$httpCode=$info['http_code'];
curl_close($ch);
if($httpCode==200 or $httpCode==0) {
- OC_Filesystem::fromTmpFile($tmpfile,$dir.'/'.$file);
+ OC_Filesystem::fromTmpFile($tmpfile, $dir.'/'.$file);
return true;
}else{
return false;
$size -=1;
} else {
$size=OC_Helper::humanFileSize($size);
- $size=substr($size,0,-1);//strip the B
- $size=str_replace(' ','',$size); //remove the space between the size and the postfix
+ $size=substr($size, 0, -1);//strip the B
+ $size=str_replace(' ', '', $size); //remove the space between the size and the postfix
}
//don't allow user to break his config -- broken or malicious size input
if(is_writable(OC::$SERVERROOT.'/.htaccess')) {
file_put_contents(OC::$SERVERROOT.'/.htaccess', $htaccess);
return OC_Helper::computerFileSize($size);
- } else { OC_Log::write('files','Can\'t write upload limit to '.OC::$SERVERROOT.'/.htaccess. Please check the file permissions',OC_Log::WARN); }
+ } else { OC_Log::write('files', 'Can\'t write upload limit to '.OC::$SERVERROOT.'/.htaccess. Please check the file permissions', OC_Log::WARN); }
return false;
}
$old='';
while($old!=$path) {//replace any multiplicity of slashes with a single one
$old=$path;
- $path=str_replace('//','/',$path);
+ $path=str_replace('//', '/', $path);
}
return $path;
}
}elseif($a['type']!='dir' and $b['type']=='dir') {
return 1;
}else{
- return strnatcasecmp($a['name'],$b['name']);
+ return strnatcasecmp($a['name'], $b['name']);
}
}