Merge pull request #133 from fmms/checkstyle02

NoSpaceAfterComma -- checkstyle cleanup
This commit is contained in:
Lukas Reschke 2012-10-29 12:35:12 -07:00
commit 2e1199acb8
7 changed files with 102 additions and 102 deletions

View File

@ -40,7 +40,7 @@ class OC_Crypt {
static private $bf = null; static private $bf = null;
public static function loginListener($params) { public static function loginListener($params) {
self::init($params['uid'],$params['password']); self::init($params['uid'], $params['password']);
} }
public static function init($login,$password) { public static function init($login,$password) {
@ -51,7 +51,7 @@ class OC_Crypt {
OC_FileProxy::$enabled=false; OC_FileProxy::$enabled=false;
if(!$view->file_exists('/'.$login.'/encryption.key')) {// does key exist? if(!$view->file_exists('/'.$login.'/encryption.key')) {// does key exist?
OC_Crypt::createkey($login,$password); OC_Crypt::createkey($login, $password);
} }
$key=$view->file_get_contents('/'.$login.'/encryption.key'); $key=$view->file_get_contents('/'.$login.'/encryption.key');
OC_FileProxy::$enabled=true; OC_FileProxy::$enabled=true;
@ -82,16 +82,16 @@ class OC_Crypt {
public static function createkey($username,$passcode) { public static function createkey($username,$passcode) {
// generate a random key // generate a random key
$key=mt_rand(10000,99999).mt_rand(10000,99999).mt_rand(10000,99999).mt_rand(10000,99999); $key=mt_rand(10000, 99999).mt_rand(10000, 99999).mt_rand(10000, 99999).mt_rand(10000, 99999);
// encrypt the key with the passcode of the user // encrypt the key with the passcode of the user
$enckey=OC_Crypt::encrypt($key,$passcode); $enckey=OC_Crypt::encrypt($key, $passcode);
// Write the file // Write the file
$proxyEnabled=OC_FileProxy::$enabled; $proxyEnabled=OC_FileProxy::$enabled;
OC_FileProxy::$enabled=false; OC_FileProxy::$enabled=false;
$view=new OC_FilesystemView('/'.$username); $view=new OC_FilesystemView('/'.$username);
$view->file_put_contents('/encryption.key',$enckey); $view->file_put_contents('/encryption.key', $enckey);
OC_FileProxy::$enabled=$proxyEnabled; OC_FileProxy::$enabled=$proxyEnabled;
} }
@ -195,8 +195,8 @@ class OC_Crypt {
public static function blockEncrypt($data, $key='') { public static function blockEncrypt($data, $key='') {
$result=''; $result='';
while(strlen($data)) { while(strlen($data)) {
$result.=self::encrypt(substr($data,0,8192),$key); $result.=self::encrypt(substr($data, 0, 8192),$key);
$data=substr($data,8192); $data=substr($data, 8192);
} }
return $result; return $result;
} }
@ -207,11 +207,11 @@ class OC_Crypt {
public static function blockDecrypt($data, $key='',$maxLength=0) { public static function blockDecrypt($data, $key='',$maxLength=0) {
$result=''; $result='';
while(strlen($data)) { while(strlen($data)) {
$result.=self::decrypt(substr($data,0,8192),$key); $result.=self::decrypt(substr($data, 0, 8192),$key);
$data=substr($data,8192); $data=substr($data, 8192);
} }
if($maxLength>0) { if($maxLength>0) {
return substr($result,0,$maxLength); return substr($result, 0, $maxLength);
}else{ }else{
return rtrim($result, "\0"); return rtrim($result, "\0");
} }

View File

@ -40,7 +40,7 @@ class OC_CryptStream{
if(!self::$rootView) { if(!self::$rootView) {
self::$rootView=new OC_FilesystemView(''); self::$rootView=new OC_FilesystemView('');
} }
$path=str_replace('crypt://','',$path); $path=str_replace('crypt://', '', $path);
if(dirname($path)=='streams' and isset(self::$sourceStreams[basename($path)])) { if(dirname($path)=='streams' and isset(self::$sourceStreams[basename($path)])) {
$this->source=self::$sourceStreams[basename($path)]['stream']; $this->source=self::$sourceStreams[basename($path)]['stream'];
$this->path=self::$sourceStreams[basename($path)]['path']; $this->path=self::$sourceStreams[basename($path)]['path'];
@ -50,13 +50,13 @@ class OC_CryptStream{
if($mode=='w' or $mode=='w+' or $mode=='wb' or $mode=='wb+') { if($mode=='w' or $mode=='w+' or $mode=='wb' or $mode=='wb+') {
$this->size=0; $this->size=0;
}else{ }else{
$this->size=self::$rootView->filesize($path,$mode); $this->size=self::$rootView->filesize($path, $mode);
} }
OC_FileProxy::$enabled=false;//disable fileproxies so we can open the source file OC_FileProxy::$enabled=false;//disable fileproxies so we can open the source file
$this->source=self::$rootView->fopen($path,$mode); $this->source=self::$rootView->fopen($path, $mode);
OC_FileProxy::$enabled=true; OC_FileProxy::$enabled=true;
if(!is_resource($this->source)) { if(!is_resource($this->source)) {
OCP\Util::writeLog('files_encryption','failed to open '.$path,OCP\Util::ERROR); OCP\Util::writeLog('files_encryption', 'failed to open '.$path, OCP\Util::ERROR);
} }
} }
if(is_resource($this->source)) { if(is_resource($this->source)) {
@ -67,7 +67,7 @@ class OC_CryptStream{
public function stream_seek($offset, $whence=SEEK_SET) { public function stream_seek($offset, $whence=SEEK_SET) {
$this->flush(); $this->flush();
fseek($this->source,$offset,$whence); fseek($this->source, $offset, $whence);
} }
public function stream_tell() { public function stream_tell() {
@ -79,11 +79,11 @@ class OC_CryptStream{
//This makes this function a lot simpler but will breake everything the moment it's fixed //This makes this function a lot simpler but will breake everything the moment it's fixed
$this->writeCache=''; $this->writeCache='';
if($count!=8192) { if($count!=8192) {
OCP\Util::writeLog('files_encryption','php bug 21641 no longer holds, decryption will not work',OCP\Util::FATAL); OCP\Util::writeLog('files_encryption', 'php bug 21641 no longer holds, decryption will not work', OCP\Util::FATAL);
die(); die();
} }
$pos=ftell($this->source); $pos=ftell($this->source);
$data=fread($this->source,8192); $data=fread($this->source, 8192);
if(strlen($data)) { if(strlen($data)) {
$result=OC_Crypt::decrypt($data); $result=OC_Crypt::decrypt($data);
}else{ }else{
@ -91,7 +91,7 @@ class OC_CryptStream{
} }
$length=$this->size-$pos; $length=$this->size-$pos;
if($length<8192) { if($length<8192) {
$result=substr($result,0,$length); $result=substr($result, 0, $length);
} }
return $result; return $result;
} }
@ -105,12 +105,12 @@ class OC_CryptStream{
} }
if($currentPos%8192!=0) { if($currentPos%8192!=0) {
//make sure we always start on a block start //make sure we always start on a block start
fseek($this->source,-($currentPos%8192),SEEK_CUR); fseek($this->source, -($currentPos%8192), SEEK_CUR);
$encryptedBlock=fread($this->source,8192); $encryptedBlock=fread($this->source,8192);
fseek($this->source,-($currentPos%8192),SEEK_CUR); fseek($this->source, -($currentPos%8192), SEEK_CUR);
$block=OC_Crypt::decrypt($encryptedBlock); $block=OC_Crypt::decrypt($encryptedBlock);
$data=substr($block,0,$currentPos%8192).$data; $data=substr($block, 0, $currentPos%8192).$data;
fseek($this->source,-($currentPos%8192),SEEK_CUR); fseek($this->source, -($currentPos%8192), SEEK_CUR);
} }
$currentPos=ftell($this->source); $currentPos=ftell($this->source);
while($remainingLength=strlen($data)>0) { while($remainingLength=strlen($data)>0) {
@ -118,9 +118,9 @@ class OC_CryptStream{
$this->writeCache=$data; $this->writeCache=$data;
$data=''; $data='';
}else{ }else{
$encrypted=OC_Crypt::encrypt(substr($data,0,8192)); $encrypted=OC_Crypt::encrypt(substr($data, 0, 8192));
fwrite($this->source,$encrypted); fwrite($this->source, $encrypted);
$data=substr($data,8192); $data=substr($data, 8192);
} }
} }
$this->size=max($this->size,$currentPos+$length); $this->size=max($this->size,$currentPos+$length);
@ -130,13 +130,13 @@ class OC_CryptStream{
public function stream_set_option($option,$arg1,$arg2) { public function stream_set_option($option,$arg1,$arg2) {
switch($option) { switch($option) {
case STREAM_OPTION_BLOCKING: case STREAM_OPTION_BLOCKING:
stream_set_blocking($this->source,$arg1); stream_set_blocking($this->source, $arg1);
break; break;
case STREAM_OPTION_READ_TIMEOUT: case STREAM_OPTION_READ_TIMEOUT:
stream_set_timeout($this->source,$arg1,$arg2); stream_set_timeout($this->source, $arg1, $arg2);
break; break;
case STREAM_OPTION_WRITE_BUFFER: case STREAM_OPTION_WRITE_BUFFER:
stream_set_write_buffer($this->source,$arg1,$arg2); stream_set_write_buffer($this->source, $arg1, $arg2);
} }
} }
@ -145,7 +145,7 @@ class OC_CryptStream{
} }
public function stream_lock($mode) { public function stream_lock($mode) {
flock($this->source,$mode); flock($this->source, $mode);
} }
public function stream_flush() { public function stream_flush() {
@ -159,7 +159,7 @@ class OC_CryptStream{
private function flush() { private function flush() {
if($this->writeCache) { if($this->writeCache) {
$encrypted=OC_Crypt::encrypt($this->writeCache); $encrypted=OC_Crypt::encrypt($this->writeCache);
fwrite($this->source,$encrypted); fwrite($this->source, $encrypted);
$this->writeCache=''; $this->writeCache='';
} }
} }
@ -167,7 +167,7 @@ class OC_CryptStream{
public function stream_close() { public function stream_close() {
$this->flush(); $this->flush();
if($this->meta['mode']!='r' and $this->meta['mode']!='rb') { if($this->meta['mode']!='r' and $this->meta['mode']!='rb') {
OC_FileCache::put($this->path, array('encrypted'=>true,'size'=>$this->size),''); OC_FileCache::put($this->path, array('encrypted'=>true, 'size'=>$this->size), '');
} }
return fclose($this->source); return fclose($this->source);
} }

View File

@ -22,8 +22,8 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
public function __construct($params) { public function __construct($params) {
$host = $params['host']; $host = $params['host'];
//remove leading http[s], will be generated in createBaseUri() //remove leading http[s], will be generated in createBaseUri()
if (substr($host,0,8) == "https://") $host = substr($host, 8); if (substr($host, 0, 8) == "https://") $host = substr($host, 8);
else if (substr($host,0,7) == "http://") $host = substr($host, 7); else if (substr($host, 0, 7) == "http://") $host = substr($host, 7);
$this->host=$host; $this->host=$host;
$this->user=$params['user']; $this->user=$params['user'];
$this->password=$params['password']; $this->password=$params['password'];
@ -32,7 +32,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
if(!$this->root || $this->root[0]!='/') { if(!$this->root || $this->root[0]!='/') {
$this->root='/'.$this->root; $this->root='/'.$this->root;
} }
if(substr($this->root,-1,1)!='/') { if(substr($this->root, -1, 1)!='/') {
$this->root.='/'; $this->root.='/';
} }
@ -65,18 +65,18 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
public function mkdir($path) { public function mkdir($path) {
$path=$this->cleanPath($path); $path=$this->cleanPath($path);
return $this->simpleResponse('MKCOL',$path, null,201); return $this->simpleResponse('MKCOL', $path, null, 201);
} }
public function rmdir($path) { public function rmdir($path) {
$path=$this->cleanPath($path); $path=$this->cleanPath($path);
return $this->simpleResponse('DELETE',$path, null,204); return $this->simpleResponse('DELETE', $path, null, 204);
} }
public function opendir($path) { public function opendir($path) {
$path=$this->cleanPath($path); $path=$this->cleanPath($path);
try{ try{
$response=$this->client->propfind($path, array(),1); $response=$this->client->propfind($path, array(), 1);
$id=md5('webdav'.$this->root.$path); $id=md5('webdav'.$this->root.$path);
OC_FakeDirStream::$dirs[$id]=array(); OC_FakeDirStream::$dirs[$id]=array();
$files=array_keys($response); $files=array_keys($response);
@ -123,7 +123,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
} }
public function unlink($path) { public function unlink($path) {
return $this->simpleResponse('DELETE',$path, null,204); return $this->simpleResponse('DELETE', $path, null, 204);
} }
public function fopen($path,$mode) { public function fopen($path,$mode) {
@ -137,7 +137,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
//straight up curl instead of sabredav here, sabredav put's the entire get result in memory //straight up curl instead of sabredav here, sabredav put's the entire get result in memory
$curl = curl_init(); $curl = curl_init();
$fp = fopen('php://temp', 'r+'); $fp = fopen('php://temp', 'r+');
curl_setopt($curl,CURLOPT_USERPWD,$this->user.':'.$this->password); curl_setopt($curl, CURLOPT_USERPWD, $this->user.':'.$this->password);
curl_setopt($curl, CURLOPT_URL, $this->createBaseUri().$path); curl_setopt($curl, CURLOPT_URL, $this->createBaseUri().$path);
curl_setopt($curl, CURLOPT_FILE, $fp); curl_setopt($curl, CURLOPT_FILE, $fp);
@ -158,18 +158,18 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
case 'c': case 'c':
case 'c+': case 'c+':
//emulate these //emulate these
if(strrpos($path,'.')!==false) { if(strrpos($path, '.')!==false) {
$ext=substr($path, strrpos($path,'.')); $ext=substr($path, strrpos($path, '.'));
}else{ }else{
$ext=''; $ext='';
} }
$tmpFile=OCP\Files::tmpFile($ext); $tmpFile=OCP\Files::tmpFile($ext);
OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack'); OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this, 'writeBack');
if($this->file_exists($path)) { if($this->file_exists($path)) {
$this->getFile($path,$tmpFile); $this->getFile($path, $tmpFile);
} }
self::$tempFiles[$tmpFile]=$path; self::$tempFiles[$tmpFile]=$path;
return fopen('close://'.$tmpFile,$mode); return fopen('close://'.$tmpFile, $mode);
} }
} }
@ -203,15 +203,15 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
} }
public function getFile($path,$target) { public function getFile($path,$target) {
$source=$this->fopen($path,'r'); $source=$this->fopen($path, 'r');
file_put_contents($target,$source); file_put_contents($target, $source);
} }
public function uploadFile($path,$target) { public function uploadFile($path,$target) {
$source=fopen($path,'r'); $source=fopen($path, 'r');
$curl = curl_init(); $curl = curl_init();
curl_setopt($curl,CURLOPT_USERPWD,$this->user.':'.$this->password); curl_setopt($curl, CURLOPT_USERPWD, $this->user.':'.$this->password);
curl_setopt($curl, CURLOPT_URL, $this->createBaseUri().$target); curl_setopt($curl, CURLOPT_URL, $this->createBaseUri().$target);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, true); curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
curl_setopt($curl, CURLOPT_INFILE, $source); // file pointer curl_setopt($curl, CURLOPT_INFILE, $source); // file pointer
@ -283,7 +283,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
private function cleanPath($path) { private function cleanPath($path) {
if(!$path || $path[0]=='/') { if(!$path || $path[0]=='/') {
return substr($path,1); return substr($path, 1);
}else{ }else{
return $path; return $path;
} }
@ -292,7 +292,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
private function simpleResponse($method,$path,$body,$expected) { private function simpleResponse($method,$path,$body,$expected) {
$path=$this->cleanPath($path); $path=$this->cleanPath($path);
try{ try{
$response=$this->client->request($method,$path,$body); $response=$this->client->request($method, $path, $body);
return $response['statusCode']==$expected; return $response['statusCode']==$expected;
}catch(Exception $e) { }catch(Exception $e) {
return false; return false;

View File

@ -95,16 +95,16 @@ abstract class OC_Filestorage_Common extends OC_Filestorage {
} }
// abstract public function unlink($path); // abstract public function unlink($path);
public function rename($path1,$path2) { public function rename($path1,$path2) {
if($this->copy($path1,$path2)) { if($this->copy($path1, $path2)) {
return $this->unlink($path1); return $this->unlink($path1);
}else{ }else{
return false; return false;
} }
} }
public function copy($path1,$path2) { public function copy($path1,$path2) {
$source=$this->fopen($path1,'r'); $source=$this->fopen($path1, 'r');
$target=$this->fopen($path2,'w'); $target=$this->fopen($path2, 'w');
$count=OC_Helper::streamCopy($source,$target); $count=OC_Helper::streamCopy($source, $target);
return $count>0; return $count>0;
} }
// abstract public function fopen($path,$mode); // abstract public function fopen($path,$mode);
@ -188,25 +188,25 @@ abstract class OC_Filestorage_Common extends OC_Filestorage {
if($this->is_dir($path)) { if($this->is_dir($path)) {
return 'httpd/unix-directory'; return 'httpd/unix-directory';
} }
$source=$this->fopen($path,'r'); $source=$this->fopen($path, 'r');
if(!$source) { if(!$source) {
return false; return false;
} }
$head=fread($source,8192);//8kb should suffice to determine a mimetype $head=fread($source, 8192);//8kb should suffice to determine a mimetype
if($pos=strrpos($path,'.')) { if($pos=strrpos($path, '.')) {
$extension=substr($path,$pos); $extension=substr($path, $pos);
}else{ }else{
$extension=''; $extension='';
} }
$tmpFile=OC_Helper::tmpFile($extension); $tmpFile=OC_Helper::tmpFile($extension);
file_put_contents($tmpFile,$head); file_put_contents($tmpFile, $head);
$mime=OC_Helper::getMimeType($tmpFile); $mime=OC_Helper::getMimeType($tmpFile);
unlink($tmpFile); unlink($tmpFile);
return $mime; return $mime;
} }
public function hash($type,$path,$raw = false) { public function hash($type,$path,$raw = false) {
$tmpFile=$this->getLocalFile(); $tmpFile=$this->getLocalFile();
$hash=hash($type,$tmpFile,$raw); $hash=hash($type, $tmpFile, $raw);
unlink($tmpFile); unlink($tmpFile);
return $hash; return $hash;
} }
@ -218,23 +218,23 @@ abstract class OC_Filestorage_Common extends OC_Filestorage {
return $this->toTmpFile($path); return $this->toTmpFile($path);
} }
private function toTmpFile($path) {//no longer in the storage api, still usefull here private function toTmpFile($path) {//no longer in the storage api, still usefull here
$source=$this->fopen($path,'r'); $source=$this->fopen($path, 'r');
if(!$source) { if(!$source) {
return false; return false;
} }
if($pos=strrpos($path,'.')) { if($pos=strrpos($path, '.')) {
$extension=substr($path,$pos); $extension=substr($path, $pos);
}else{ }else{
$extension=''; $extension='';
} }
$tmpFile=OC_Helper::tmpFile($extension); $tmpFile=OC_Helper::tmpFile($extension);
$target=fopen($tmpFile,'w'); $target=fopen($tmpFile, 'w');
OC_Helper::streamCopy($source,$target); OC_Helper::streamCopy($source, $target);
return $tmpFile; return $tmpFile;
} }
public function getLocalFolder($path) { public function getLocalFolder($path) {
$baseDir=OC_Helper::tmpFolder(); $baseDir=OC_Helper::tmpFolder();
$this->addLocalFolder($path,$baseDir); $this->addLocalFolder($path, $baseDir);
return $baseDir; return $baseDir;
} }
private function addLocalFolder($path,$target) { private function addLocalFolder($path,$target) {
@ -243,10 +243,10 @@ abstract class OC_Filestorage_Common extends OC_Filestorage {
if($file!=='.' and $file!=='..') { if($file!=='.' and $file!=='..') {
if($this->is_dir($path.'/'.$file)) { if($this->is_dir($path.'/'.$file)) {
mkdir($target.'/'.$file); mkdir($target.'/'.$file);
$this->addLocalFolder($path.'/'.$file,$target.'/'.$file); $this->addLocalFolder($path.'/'.$file, $target.'/'.$file);
}else{ }else{
$tmp=$this->toTmpFile($path.'/'.$file); $tmp=$this->toTmpFile($path.'/'.$file);
rename($tmp,$target.'/'.$file); rename($tmp, $target.'/'.$file);
} }
} }
} }

View File

@ -142,7 +142,7 @@ class OC_FilesystemView {
* @return string * @return string
*/ */
public function getLocalFile($path) { public function getLocalFile($path) {
$parent=substr($path, 0, strrpos($path,'/')); $parent=substr($path, 0, strrpos($path, '/'));
if(OC_Filesystem::isValidPath($parent) and $storage=$this->getStorage($path)) { if(OC_Filesystem::isValidPath($parent) and $storage=$this->getStorage($path)) {
return $storage->getLocalFile($this->getInternalPath($path)); return $storage->getLocalFile($this->getInternalPath($path));
} }
@ -152,7 +152,7 @@ class OC_FilesystemView {
* @return string * @return string
*/ */
public function getLocalFolder($path) { public function getLocalFolder($path) {
$parent=substr($path, 0, strrpos($path,'/')); $parent=substr($path, 0, strrpos($path, '/'));
if(OC_Filesystem::isValidPath($parent) and $storage=$this->getStorage($path)) { if(OC_Filesystem::isValidPath($parent) and $storage=$this->getStorage($path)) {
return $storage->getLocalFolder($this->getInternalPath($path)); return $storage->getLocalFolder($this->getInternalPath($path));
} }
@ -215,13 +215,13 @@ class OC_FilesystemView {
* @deprecated Replaced by isReadable() as part of CRUDS * @deprecated Replaced by isReadable() as part of CRUDS
*/ */
public function is_readable($path) { public function is_readable($path) {
return $this->basicOperation('isReadable',$path); return $this->basicOperation('isReadable', $path);
} }
/** /**
* @deprecated Replaced by isCreatable(), isUpdatable(), isDeletable() as part of CRUDS * @deprecated Replaced by isCreatable(), isUpdatable(), isDeletable() as part of CRUDS
*/ */
public function is_writable($path) { public function is_writable($path) {
return $this->basicOperation('isUpdatable',$path); return $this->basicOperation('isUpdatable', $path);
} }
public function isCreatable($path) { public function isCreatable($path) {
return $this->basicOperation('isCreatable', $path); return $this->basicOperation('isCreatable', $path);
@ -325,8 +325,8 @@ class OC_FilesystemView {
return $this->basicOperation( 'deleteAll', $directory, array('delete'), $empty ); return $this->basicOperation( 'deleteAll', $directory, array('delete'), $empty );
} }
public function rename($path1, $path2) { public function rename($path1, $path2) {
$postFix1=(substr($path1,-1,1)==='/')?'/':''; $postFix1=(substr($path1, -1, 1)==='/')?'/':'';
$postFix2=(substr($path2,-1,1)==='/')?'/':''; $postFix2=(substr($path2, -1, 1)==='/')?'/':'';
$absolutePath1 = OC_Filesystem::normalizePath($this->getAbsolutePath($path1)); $absolutePath1 = OC_Filesystem::normalizePath($this->getAbsolutePath($path1));
$absolutePath2 = OC_Filesystem::normalizePath($this->getAbsolutePath($path2)); $absolutePath2 = OC_Filesystem::normalizePath($this->getAbsolutePath($path2));
if(OC_FileProxy::runPreProxies('rename', $absolutePath1, $absolutePath2) and OC_Filesystem::isValidPath($path2)) { if(OC_FileProxy::runPreProxies('rename', $absolutePath1, $absolutePath2) and OC_Filesystem::isValidPath($path2)) {
@ -377,8 +377,8 @@ class OC_FilesystemView {
} }
} }
public function copy($path1, $path2) { public function copy($path1, $path2) {
$postFix1=(substr($path1,-1,1)==='/')?'/':''; $postFix1=(substr($path1, -1, 1)==='/')?'/':'';
$postFix2=(substr($path2,-1,1)==='/')?'/':''; $postFix2=(substr($path2, -1, 1)==='/')?'/':'';
$absolutePath1 = OC_Filesystem::normalizePath($this->getAbsolutePath($path1)); $absolutePath1 = OC_Filesystem::normalizePath($this->getAbsolutePath($path1));
$absolutePath2 = OC_Filesystem::normalizePath($this->getAbsolutePath($path2)); $absolutePath2 = OC_Filesystem::normalizePath($this->getAbsolutePath($path2));
if(OC_FileProxy::runPreProxies('copy', $absolutePath1, $absolutePath2) and OC_Filesystem::isValidPath($path2)) { if(OC_FileProxy::runPreProxies('copy', $absolutePath1, $absolutePath2) and OC_Filesystem::isValidPath($path2)) {
@ -489,7 +489,7 @@ class OC_FilesystemView {
$hooks[]='write'; $hooks[]='write';
break; break;
default: default:
OC_Log::write('core','invalid mode ('.$mode.') for '.$path,OC_Log::ERROR); OC_Log::write('core', 'invalid mode ('.$mode.') for '.$path,OC_Log::ERROR);
} }
return $this->basicOperation('fopen', $path, $hooks, $mode); return $this->basicOperation('fopen', $path, $hooks, $mode);
@ -501,7 +501,7 @@ class OC_FilesystemView {
$extension=''; $extension='';
$extOffset=strpos($path, '.'); $extOffset=strpos($path, '.');
if($extOffset !== false) { if($extOffset !== false) {
$extension=substr($path, strrpos($path,'.')); $extension=substr($path, strrpos($path, '.'));
} }
$tmpFile = OC_Helper::tmpFile($extension); $tmpFile = OC_Helper::tmpFile($extension);
file_put_contents($tmpFile, $source); file_put_contents($tmpFile, $source);
@ -530,7 +530,7 @@ class OC_FilesystemView {
return $this->basicOperation('getMimeType', $path); return $this->basicOperation('getMimeType', $path);
} }
public function hash($type, $path, $raw = false) { public function hash($type, $path, $raw = false) {
$postFix=(substr($path,-1,1)==='/')?'/':''; $postFix=(substr($path, -1, 1)==='/')?'/':'';
$absolutePath = OC_Filesystem::normalizePath($this->getAbsolutePath($path)); $absolutePath = OC_Filesystem::normalizePath($this->getAbsolutePath($path));
if (OC_FileProxy::runPreProxies('hash', $absolutePath) && OC_Filesystem::isValidPath($path)) { if (OC_FileProxy::runPreProxies('hash', $absolutePath) && OC_Filesystem::isValidPath($path)) {
$path = $this->getRelativePath($absolutePath); $path = $this->getRelativePath($absolutePath);
@ -570,7 +570,7 @@ class OC_FilesystemView {
* OC_Filestorage for delegation to a storage backend for execution * OC_Filestorage for delegation to a storage backend for execution
*/ */
private function basicOperation($operation, $path, $hooks=array(), $extraParam=null) { private function basicOperation($operation, $path, $hooks=array(), $extraParam=null) {
$postFix=(substr($path,-1,1)==='/')?'/':''; $postFix=(substr($path, -1, 1)==='/')?'/':'';
$absolutePath = OC_Filesystem::normalizePath($this->getAbsolutePath($path)); $absolutePath = OC_Filesystem::normalizePath($this->getAbsolutePath($path));
if(OC_FileProxy::runPreProxies($operation, $absolutePath, $extraParam) and OC_Filesystem::isValidPath($path)) { if(OC_FileProxy::runPreProxies($operation, $absolutePath, $extraParam) and OC_Filesystem::isValidPath($path)) {
$path = $this->getRelativePath($absolutePath); $path = $this->getRelativePath($absolutePath);
@ -578,7 +578,7 @@ class OC_FilesystemView {
return false; return false;
} }
$internalPath = $this->getInternalPath($path.$postFix); $internalPath = $this->getInternalPath($path.$postFix);
$run=$this->runHooks($hooks,$path); $run=$this->runHooks($hooks, $path);
if($run and $storage = $this->getStorage($path.$postFix)) { if($run and $storage = $this->getStorage($path.$postFix)) {
if(!is_null($extraParam)) { if(!is_null($extraParam)) {
$result = $storage->$operation($internalPath, $extraParam); $result = $storage->$operation($internalPath, $extraParam);
@ -588,7 +588,7 @@ class OC_FilesystemView {
$result = OC_FileProxy::runPostProxies($operation, $this->getAbsolutePath($path), $result); $result = OC_FileProxy::runPostProxies($operation, $this->getAbsolutePath($path), $result);
if(OC_Filesystem::$loaded and $this->fakeRoot==OC_Filesystem::getRoot()) { if(OC_Filesystem::$loaded and $this->fakeRoot==OC_Filesystem::getRoot()) {
if($operation!='fopen') {//no post hooks for fopen, the file stream is still open if($operation!='fopen') {//no post hooks for fopen, the file stream is still open
$this->runHooks($hooks,$path, true); $this->runHooks($hooks, $path, true);
} }
} }
return $result; return $result;

View File

@ -203,7 +203,7 @@ class OC_Helper {
return OC::$WEBROOT."/core/img/filetypes/$mimetype.png"; return OC::$WEBROOT."/core/img/filetypes/$mimetype.png";
} }
//try only the first part of the filetype //try only the first part of the filetype
$mimetype=substr($mimetype,0, strpos($mimetype,'-')); $mimetype=substr($mimetype, 0, strpos($mimetype, '-'));
if( file_exists( OC::$SERVERROOT."/core/img/filetypes/$mimetype.png" )) { if( file_exists( OC::$SERVERROOT."/core/img/filetypes/$mimetype.png" )) {
return OC::$WEBROOT."/core/img/filetypes/$mimetype.png"; return OC::$WEBROOT."/core/img/filetypes/$mimetype.png";
} }
@ -355,29 +355,29 @@ class OC_Helper {
* does NOT work for ownClouds filesystem, use OC_FileSystem::getMimeType instead * does NOT work for ownClouds filesystem, use OC_FileSystem::getMimeType instead
*/ */
static function getMimeType($path) { static function getMimeType($path) {
$isWrapped=(strpos($path,'://')!==false) and (substr($path,0,7)=='file://'); $isWrapped=(strpos($path, '://')!==false) and (substr($path, 0, 7)=='file://');
if (@is_dir($path)) { if (@is_dir($path)) {
// directories are easy // directories are easy
return "httpd/unix-directory"; return "httpd/unix-directory";
} }
if(strpos($path,'.')) { if(strpos($path, '.')) {
//try to guess the type by the file extension //try to guess the type by the file extension
if(!self::$mimetypes || self::$mimetypes != include 'mimetypes.list.php') { if(!self::$mimetypes || self::$mimetypes != include 'mimetypes.list.php') {
self::$mimetypes=include 'mimetypes.list.php'; self::$mimetypes=include 'mimetypes.list.php';
} }
$extension=strtolower(strrchr(basename($path), ".")); $extension=strtolower(strrchr(basename($path), "."));
$extension=substr($extension,1);//remove leading . $extension=substr($extension, 1);//remove leading .
$mimeType=(isset(self::$mimetypes[$extension]))?self::$mimetypes[$extension]:'application/octet-stream'; $mimeType=(isset(self::$mimetypes[$extension]))?self::$mimetypes[$extension]:'application/octet-stream';
}else{ }else{
$mimeType='application/octet-stream'; $mimeType='application/octet-stream';
} }
if($mimeType=='application/octet-stream' and function_exists('finfo_open') and function_exists('finfo_file') and $finfo=finfo_open(FILEINFO_MIME)) { if($mimeType=='application/octet-stream' and function_exists('finfo_open') and function_exists('finfo_file') and $finfo=finfo_open(FILEINFO_MIME)) {
$info = @strtolower(finfo_file($finfo,$path)); $info = @strtolower(finfo_file($finfo, $path));
if($info) { if($info) {
$mimeType=substr($info,0, strpos($info,';')); $mimeType=substr($info,0, strpos($info, ';'));
} }
finfo_close($finfo); finfo_close($finfo);
} }
@ -412,8 +412,8 @@ class OC_Helper {
return finfo_buffer($finfo, $data); return finfo_buffer($finfo, $data);
}else{ }else{
$tmpFile=OC_Helper::tmpFile(); $tmpFile=OC_Helper::tmpFile();
$fh=fopen($tmpFile,'wb'); $fh=fopen($tmpFile, 'wb');
fwrite($fh,$data,8024); fwrite($fh, $data, 8024);
fclose($fh); fclose($fh);
$mime=self::getMimeType($tmpFile); $mime=self::getMimeType($tmpFile);
unset($tmpFile); unset($tmpFile);
@ -504,7 +504,7 @@ class OC_Helper {
} }
$count=0; $count=0;
while(!feof($source)) { while(!feof($source)) {
$count+=fwrite($target, fread($source,8192)); $count+=fwrite($target, fread($source, 8192));
} }
return $count; return $count;
} }
@ -518,7 +518,7 @@ class OC_Helper {
*/ */
public static function tmpFile($postfix='') { public static function tmpFile($postfix='') {
$file=get_temp_dir().'/'.md5(time().rand()).$postfix; $file=get_temp_dir().'/'.md5(time().rand()).$postfix;
$fh=fopen($file,'w'); $fh=fopen($file, 'w');
fclose($fh); fclose($fh);
self::$tmpFiles[]=$file; self::$tmpFiles[]=$file;
return $file; return $file;

View File

@ -244,7 +244,7 @@ class OC_Image {
ob_start(); ob_start();
$res = imagepng($this->resource); $res = imagepng($this->resource);
if (!$res) { if (!$res) {
OC_Log::write('core','OC_Image->data. Error getting image data.',OC_Log::ERROR); OC_Log::write('core', 'OC_Image->data. Error getting image data.', OC_Log::ERROR);
} }
return ob_get_clean(); return ob_get_clean();
} }
@ -263,11 +263,11 @@ class OC_Image {
*/ */
public function getOrientation() { public function getOrientation() {
if(!is_callable('exif_read_data')) { if(!is_callable('exif_read_data')) {
OC_Log::write('core','OC_Image->fixOrientation() Exif module not enabled.', OC_Log::DEBUG); OC_Log::write('core', 'OC_Image->fixOrientation() Exif module not enabled.', OC_Log::DEBUG);
return -1; return -1;
} }
if(!$this->valid()) { if(!$this->valid()) {
OC_Log::write('core','OC_Image->fixOrientation() No image loaded.', OC_Log::DEBUG); OC_Log::write('core', 'OC_Image->fixOrientation() No image loaded.', OC_Log::DEBUG);
return -1; return -1;
} }
if(is_null($this->filepath) || !is_readable($this->filepath)) { if(is_null($this->filepath) || !is_readable($this->filepath)) {
@ -549,7 +549,7 @@ class OC_Image {
public function preciseResize($width, $height) { public function preciseResize($width, $height) {
if (!$this->valid()) { if (!$this->valid()) {
OC_Log::write('core',__METHOD__.'(): No image loaded', OC_Log::ERROR); OC_Log::write('core', __METHOD__.'(): No image loaded', OC_Log::ERROR);
return false; return false;
} }
$width_orig=imageSX($this->resource); $width_orig=imageSX($this->resource);
@ -557,14 +557,14 @@ class OC_Image {
$process = imagecreatetruecolor($width, $height); $process = imagecreatetruecolor($width, $height);
if ($process == false) { if ($process == false) {
OC_Log::write('core', __METHOD__.'(): Error creating true color image',OC_Log::ERROR); OC_Log::write('core', __METHOD__.'(): Error creating true color image', OC_Log::ERROR);
imagedestroy($process); imagedestroy($process);
return false; return false;
} }
imagecopyresampled($process, $this->resource, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); imagecopyresampled($process, $this->resource, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
if ($process == false) { if ($process == false) {
OC_Log::write('core', __METHOD__.'(): Error resampling process image '.$width.'x'.$height,OC_Log::ERROR); OC_Log::write('core', __METHOD__.'(): Error resampling process image '.$width.'x'.$height, OC_Log::ERROR);
imagedestroy($process); imagedestroy($process);
return false; return false;
} }
@ -607,13 +607,13 @@ class OC_Image {
} }
$process = imagecreatetruecolor($targetWidth, $targetHeight); $process = imagecreatetruecolor($targetWidth, $targetHeight);
if ($process == false) { if ($process == false) {
OC_Log::write('core', 'OC_Image->centerCrop. Error creating true color image',OC_Log::ERROR); OC_Log::write('core', 'OC_Image->centerCrop. Error creating true color image', OC_Log::ERROR);
imagedestroy($process); imagedestroy($process);
return false; return false;
} }
imagecopyresampled($process, $this->resource, 0, 0, $x, $y, $targetWidth, $targetHeight, $width, $height); imagecopyresampled($process, $this->resource, 0, 0, $x, $y, $targetWidth, $targetHeight, $width, $height);
if ($process == false) { if ($process == false) {
OC_Log::write('core', 'OC_Image->centerCrop. Error resampling process image '.$width.'x'.$height,OC_Log::ERROR); OC_Log::write('core', 'OC_Image->centerCrop. Error resampling process image '.$width.'x'.$height, OC_Log::ERROR);
imagedestroy($process); imagedestroy($process);
return false; return false;
} }
@ -637,13 +637,13 @@ class OC_Image {
} }
$process = imagecreatetruecolor($w, $h); $process = imagecreatetruecolor($w, $h);
if ($process == false) { if ($process == false) {
OC_Log::write('core', __METHOD__.'(): Error creating true color image',OC_Log::ERROR); OC_Log::write('core', __METHOD__.'(): Error creating true color image', OC_Log::ERROR);
imagedestroy($process); imagedestroy($process);
return false; return false;
} }
imagecopyresampled($process, $this->resource, 0, 0, $x, $y, $w, $h, $w, $h); imagecopyresampled($process, $this->resource, 0, 0, $x, $y, $w, $h, $w, $h);
if ($process == false) { if ($process == false) {
OC_Log::write('core', __METHOD__.'(): Error resampling process image '.$w.'x'.$h,OC_Log::ERROR); OC_Log::write('core', __METHOD__.'(): Error resampling process image '.$w.'x'.$h, OC_Log::ERROR);
imagedestroy($process); imagedestroy($process);
return false; return false;
} }