Merge pull request #129 from fmms/checkstyle01

Checkstyle
This commit is contained in:
Lukas Reschke 2012-10-28 10:36:27 -07:00
commit f3971e659b
4 changed files with 100 additions and 100 deletions

View File

@ -148,21 +148,21 @@ class OC_Filesystem{
* @return string * @return string
*/ */
static public function getMountPoint($path) { static public function getMountPoint($path) {
OC_Hook::emit(self::CLASSNAME,'get_mountpoint', array('path'=>$path)); OC_Hook::emit(self::CLASSNAME, 'get_mountpoint', array('path'=>$path));
if(!$path) { if(!$path) {
$path='/'; $path='/';
} }
if($path[0]!=='/') { if($path[0]!=='/') {
$path='/'.$path; $path='/'.$path;
} }
$path=str_replace('//', '/',$path); $path=str_replace('//', '/', $path);
$foundMountPoint=''; $foundMountPoint='';
$mountPoints=array_keys(OC_Filesystem::$mounts); $mountPoints=array_keys(OC_Filesystem::$mounts);
foreach($mountPoints as $mountpoint) { foreach($mountPoints as $mountpoint) {
if($mountpoint==$path) { if($mountpoint==$path) {
return $mountpoint; return $mountpoint;
} }
if(strpos($path,$mountpoint)===0 and strlen($mountpoint)>strlen($foundMountPoint)) { if(strpos($path, $mountpoint)===0 and strlen($mountpoint)>strlen($foundMountPoint)) {
$foundMountPoint=$mountpoint; $foundMountPoint=$mountpoint;
} }
} }
@ -202,7 +202,7 @@ class OC_Filesystem{
if($mountpoint) { if($mountpoint) {
if(!isset(OC_Filesystem::$storages[$mountpoint])) { if(!isset(OC_Filesystem::$storages[$mountpoint])) {
$mount=OC_Filesystem::$mounts[$mountpoint]; $mount=OC_Filesystem::$mounts[$mountpoint];
OC_Filesystem::$storages[$mountpoint]=OC_Filesystem::createStorage($mount['class'],$mount['arguments']); OC_Filesystem::$storages[$mountpoint]=OC_Filesystem::createStorage($mount['class'], $mount['arguments']);
} }
return OC_Filesystem::$storages[$mountpoint]; return OC_Filesystem::$storages[$mountpoint];
} }
@ -213,19 +213,19 @@ class OC_Filesystem{
$mountConfig=include OC::$SERVERROOT.'/config/mount.php'; $mountConfig=include OC::$SERVERROOT.'/config/mount.php';
if(isset($mountConfig['global'])) { if(isset($mountConfig['global'])) {
foreach($mountConfig['global'] as $mountPoint=>$options) { foreach($mountConfig['global'] as $mountPoint=>$options) {
self::mount($options['class'],$options['options'],$mountPoint); self::mount($options['class'], $options['options'], $mountPoint);
} }
} }
if(isset($mountConfig['group'])) { if(isset($mountConfig['group'])) {
foreach($mountConfig['group'] as $group=>$mounts) { foreach($mountConfig['group'] as $group=>$mounts) {
if(OC_Group::inGroup($user,$group)) { if(OC_Group::inGroup($user, $group)) {
foreach($mounts as $mountPoint=>$options) { foreach($mounts as $mountPoint=>$options) {
$mountPoint=self::setUserVars($mountPoint, $user); $mountPoint=self::setUserVars($mountPoint, $user);
foreach($options as &$option) { foreach($options as &$option) {
$option=self::setUserVars($option, $user); $option=self::setUserVars($option, $user);
} }
self::mount($options['class'],$options['options'],$mountPoint); self::mount($options['class'], $options['options'], $mountPoint);
} }
} }
} }
@ -239,7 +239,7 @@ class OC_Filesystem{
foreach($options as &$option) { foreach($options as &$option) {
$option=self::setUserVars($option, $user); $option=self::setUserVars($option, $user);
} }
self::mount($options['class'],$options['options'],$mountPoint); self::mount($options['class'], $options['options'], $mountPoint);
} }
} }
} }
@ -249,7 +249,7 @@ class OC_Filesystem{
$previousMTime=OC_Appconfig::getValue('files','mountconfigmtime',0); $previousMTime=OC_Appconfig::getValue('files','mountconfigmtime',0);
if($mtime>$previousMTime) {//mount config has changed, filecache needs to be updated if($mtime>$previousMTime) {//mount config has changed, filecache needs to be updated
OC_FileCache::triggerUpdate(); OC_FileCache::triggerUpdate();
OC_Appconfig::setValue('files','mountconfigmtime',$mtime); OC_Appconfig::setValue('files', 'mountconfigmtime', $mtime);
} }
} }
} }
@ -276,9 +276,9 @@ class OC_Filesystem{
*/ */
private static function setUserVars($input, $user) { private static function setUserVars($input, $user) {
if (isset($user)) { if (isset($user)) {
return str_replace('$user', $user,$input); return str_replace('$user', $user, $input);
} else { } else {
return str_replace('$user',OC_User::getUser(),$input); return str_replace('$user', OC_User::getUser(), $input);
} }
} }
@ -353,7 +353,7 @@ class OC_Filesystem{
if($mountpoint[0]!='/') { if($mountpoint[0]!='/') {
$mountpoint='/'.$mountpoint; $mountpoint='/'.$mountpoint;
} }
if(substr($mountpoint,-1)!=='/') { if(substr($mountpoint, -1)!=='/') {
$mountpoint=$mountpoint.'/'; $mountpoint=$mountpoint.'/';
} }
self::$mounts[$mountpoint]=array('class'=>$class,'arguments'=>$arguments); self::$mounts[$mountpoint]=array('class'=>$class,'arguments'=>$arguments);
@ -399,7 +399,7 @@ class OC_Filesystem{
if(!$path || $path[0]!=='/') { if(!$path || $path[0]!=='/') {
$path='/'.$path; $path='/'.$path;
} }
if(strstr($path,'/../') || strrchr($path, '/') === '/..' ) { if(strstr($path, '/../') || strrchr($path, '/') === '/..' ) {
return false; return false;
} }
return true; return true;
@ -501,32 +501,32 @@ class OC_Filesystem{
return self::$defaultInstance->file_get_contents($path); return self::$defaultInstance->file_get_contents($path);
} }
static public function file_put_contents($path,$data) { static public function file_put_contents($path,$data) {
return self::$defaultInstance->file_put_contents($path,$data); return self::$defaultInstance->file_put_contents($path, $data);
} }
static public function unlink($path) { static public function unlink($path) {
return self::$defaultInstance->unlink($path); return self::$defaultInstance->unlink($path);
} }
static public function rename($path1,$path2) { static public function rename($path1,$path2) {
return self::$defaultInstance->rename($path1,$path2); return self::$defaultInstance->rename($path1, $path2);
} }
static public function copy($path1,$path2) { static public function copy($path1,$path2) {
return self::$defaultInstance->copy($path1,$path2); return self::$defaultInstance->copy($path1, $path2);
} }
static public function fopen($path,$mode) { static public function fopen($path,$mode) {
return self::$defaultInstance->fopen($path,$mode); return self::$defaultInstance->fopen($path, $mode);
} }
static public function toTmpFile($path) { static public function toTmpFile($path) {
return self::$defaultInstance->toTmpFile($path); return self::$defaultInstance->toTmpFile($path);
} }
static public function fromTmpFile($tmpFile,$path) { static public function fromTmpFile($tmpFile,$path) {
return self::$defaultInstance->fromTmpFile($tmpFile,$path); return self::$defaultInstance->fromTmpFile($tmpFile, $path);
} }
static public function getMimeType($path) { static public function getMimeType($path) {
return self::$defaultInstance->getMimeType($path); return self::$defaultInstance->getMimeType($path);
} }
static public function hash($type,$path, $raw = false) { static public function hash($type,$path, $raw = false) {
return self::$defaultInstance->hash($type,$path, $raw); return self::$defaultInstance->hash($type, $path, $raw);
} }
static public function free_space($path='/') { static public function free_space($path='/') {
@ -543,7 +543,7 @@ class OC_Filesystem{
* @return bool * @return bool
*/ */
static public function hasUpdated($path,$time) { static public function hasUpdated($path,$time) {
return self::$defaultInstance->hasUpdated($path,$time); return self::$defaultInstance->hasUpdated($path, $time);
} }
static public function removeETagHook($params, $root = false) { static public function removeETagHook($params, $root = false) {
@ -574,18 +574,18 @@ class OC_Filesystem{
return '/'; return '/';
} }
//no windows style slashes //no windows style slashes
$path=str_replace('\\','/',$path); $path=str_replace('\\', '/', $path);
//add leading slash //add leading slash
if($path[0]!=='/') { if($path[0]!=='/') {
$path='/'.$path; $path='/'.$path;
} }
//remove trainling slash //remove trainling slash
if($stripTrailingSlash and strlen($path)>1 and substr($path,-1,1)==='/') { if($stripTrailingSlash and strlen($path)>1 and substr($path, -1, 1)==='/') {
$path=substr($path,0,-1); $path=substr($path, 0, -1);
} }
//remove duplicate slashes //remove duplicate slashes
while(strpos($path,'//')!==false) { while(strpos($path,'//')!==false) {
$path=str_replace('//','/',$path); $path=str_replace('//', '/', $path);
} }
//normalize unicode if possible //normalize unicode if possible
if(class_exists('Normalizer')) { if(class_exists('Normalizer')) {
@ -594,9 +594,9 @@ class OC_Filesystem{
return $path; return $path;
} }
} }
OC_Hook::connect('OC_Filesystem','post_write', 'OC_Filesystem','removeETagHook'); OC_Hook::connect('OC_Filesystem', 'post_write', 'OC_Filesystem', 'removeETagHook');
OC_Hook::connect('OC_Filesystem','post_delete','OC_Filesystem','removeETagHook'); OC_Hook::connect('OC_Filesystem', 'post_delete', 'OC_Filesystem', 'removeETagHook');
OC_Hook::connect('OC_Filesystem','post_rename','OC_Filesystem','removeETagHook'); OC_Hook::connect('OC_Filesystem', 'post_rename', 'OC_Filesystem', 'removeETagHook');
OC_Util::setupFS(); OC_Util::setupFS();
require_once 'filecache.php'; require_once 'filecache.php';

View File

@ -66,7 +66,7 @@ class OC_Image {
public function __construct($imageref = null) { public function __construct($imageref = null) {
//OC_Log::write('core',__METHOD__.'(): start', OC_Log::DEBUG); //OC_Log::write('core',__METHOD__.'(): start', OC_Log::DEBUG);
if(!extension_loaded('gd') || !function_exists('gd_info')) { if(!extension_loaded('gd') || !function_exists('gd_info')) {
OC_Log::write('core',__METHOD__.'(): GD module not installed', OC_Log::ERROR); OC_Log::write('core', __METHOD__.'(): GD module not installed', OC_Log::ERROR);
return false; return false;
} }
if(!is_null($imageref)) { if(!is_null($imageref)) {
@ -112,7 +112,7 @@ class OC_Image {
*/ */
public function widthTopLeft() { public function widthTopLeft() {
$o = $this->getOrientation(); $o = $this->getOrientation();
OC_Log::write('core','OC_Image->widthTopLeft() Orientation: '.$o, OC_Log::DEBUG); OC_Log::write('core', 'OC_Image->widthTopLeft() Orientation: '.$o, OC_Log::DEBUG);
switch($o) { switch($o) {
case -1: case -1:
case 1: case 1:
@ -137,7 +137,7 @@ class OC_Image {
*/ */
public function heightTopLeft() { public function heightTopLeft() {
$o = $this->getOrientation(); $o = $this->getOrientation();
OC_Log::write('core','OC_Image->heightTopLeft() Orientation: '.$o, OC_Log::DEBUG); OC_Log::write('core', 'OC_Image->heightTopLeft() Orientation: '.$o, OC_Log::DEBUG);
switch($o) { switch($o) {
case -1: case -1:
case 1: case 1:
@ -172,7 +172,7 @@ class OC_Image {
public function save($filepath=null) { public function save($filepath=null) {
if($filepath === null && $this->filepath === null) { if($filepath === null && $this->filepath === null) {
OC_Log::write('core',__METHOD__.'(): called with no path.', OC_Log::ERROR); OC_Log::write('core', __METHOD__.'(): called with no path.', OC_Log::ERROR);
return false; return false;
} elseif($filepath === null && $this->filepath !== null) { } elseif($filepath === null && $this->filepath !== null) {
$filepath = $this->filepath; $filepath = $this->filepath;
@ -188,10 +188,10 @@ class OC_Image {
if (!file_exists(dirname($filepath))) if (!file_exists(dirname($filepath)))
mkdir(dirname($filepath), 0777, true); mkdir(dirname($filepath), 0777, true);
if(!is_writable(dirname($filepath))) { if(!is_writable(dirname($filepath))) {
OC_Log::write('core',__METHOD__.'(): Directory \''.dirname($filepath).'\' is not writable.', OC_Log::ERROR); OC_Log::write('core', __METHOD__.'(): Directory \''.dirname($filepath).'\' is not writable.', OC_Log::ERROR);
return false; return false;
} elseif(is_writable(dirname($filepath)) && file_exists($filepath) && !is_writable($filepath)) { } elseif(is_writable(dirname($filepath)) && file_exists($filepath) && !is_writable($filepath)) {
OC_Log::write('core',__METHOD__.'(): File \''.$filepath.'\' is not writable.', OC_Log::ERROR); OC_Log::write('core', __METHOD__.'(): File \''.$filepath.'\' is not writable.', OC_Log::ERROR);
return false; return false;
} }
} }
@ -291,7 +291,7 @@ class OC_Image {
*/ */
public function fixOrientation() { public function fixOrientation() {
$o = $this->getOrientation(); $o = $this->getOrientation();
OC_Log::write('core','OC_Image->fixOrientation() Orientation: '.$o, OC_Log::DEBUG); OC_Log::write('core', 'OC_Image->fixOrientation() Orientation: '.$o, OC_Log::DEBUG);
$rotate = 0; $rotate = 0;
$flip = false; $flip = false;
switch($o) { switch($o) {
@ -341,15 +341,15 @@ class OC_Image {
$this->resource = $res; $this->resource = $res;
return true; return true;
} else { } else {
OC_Log::write('core','OC_Image->fixOrientation() Error during alphasaving.', OC_Log::DEBUG); OC_Log::write('core', 'OC_Image->fixOrientation() Error during alphasaving.', OC_Log::DEBUG);
return false; return false;
} }
} else { } else {
OC_Log::write('core','OC_Image->fixOrientation() Error during alphablending.', OC_Log::DEBUG); OC_Log::write('core', 'OC_Image->fixOrientation() Error during alphablending.', OC_Log::DEBUG);
return false; return false;
} }
} else { } else {
OC_Log::write('core','OC_Image->fixOrientation() Error during oriention fixing.', OC_Log::DEBUG); OC_Log::write('core', 'OC_Image->fixOrientation() Error during oriention fixing.', OC_Log::DEBUG);
return false; return false;
} }
} }
@ -365,7 +365,7 @@ class OC_Image {
if(get_resource_type($imageref) == 'gd') { if(get_resource_type($imageref) == 'gd') {
$this->resource = $imageref; $this->resource = $imageref;
return $this->resource; return $this->resource;
} elseif(in_array(get_resource_type($imageref), array('file','stream'))) { } elseif(in_array(get_resource_type($imageref), array('file', 'stream'))) {
return $this->loadFromFileHandle($imageref); return $this->loadFromFileHandle($imageref);
} }
} elseif($this->loadFromFile($imageref) !== false) { } elseif($this->loadFromFile($imageref) !== false) {
@ -375,7 +375,7 @@ class OC_Image {
} elseif($this->loadFromData($imageref) !== false) { } elseif($this->loadFromData($imageref) !== false) {
return $this->resource; return $this->resource;
} else { } else {
OC_Log::write('core',__METHOD__.'(): couldn\'t load anything. Giving up!', OC_Log::DEBUG); OC_Log::write('core', __METHOD__.'(): couldn\'t load anything. Giving up!', OC_Log::DEBUG);
return false; return false;
} }
} }
@ -387,7 +387,7 @@ class OC_Image {
* @returns An image resource or false on error * @returns An image resource or false on error
*/ */
public function loadFromFileHandle($handle) { public function loadFromFileHandle($handle) {
OC_Log::write('core',__METHOD__.'(): Trying', OC_Log::DEBUG); OC_Log::write('core', __METHOD__.'(): Trying', OC_Log::DEBUG);
$contents = stream_get_contents($handle); $contents = stream_get_contents($handle);
if($this->loadFromData($contents)) { if($this->loadFromData($contents)) {
return $this->resource; return $this->resource;
@ -402,7 +402,7 @@ class OC_Image {
public function loadFromFile($imagepath=false) { public function loadFromFile($imagepath=false) {
if(!is_file($imagepath) || !file_exists($imagepath) || !is_readable($imagepath)) { if(!is_file($imagepath) || !file_exists($imagepath) || !is_readable($imagepath)) {
// Debug output disabled because this method is tried before loadFromBase64? // Debug output disabled because this method is tried before loadFromBase64?
OC_Log::write('core','OC_Image->loadFromFile, couldn\'t load: '.ellipsis($imagepath, 50), OC_Log::DEBUG); OC_Log::write('core', 'OC_Image->loadFromFile, couldn\'t load: '.ellipsis($imagepath, 50), OC_Log::DEBUG);
return false; return false;
} }
$itype = exif_imagetype($imagepath); $itype = exif_imagetype($imagepath);
@ -411,28 +411,28 @@ class OC_Image {
if (imagetypes() & IMG_GIF) { if (imagetypes() & IMG_GIF) {
$this->resource = imagecreatefromgif($imagepath); $this->resource = imagecreatefromgif($imagepath);
} else { } else {
OC_Log::write('core','OC_Image->loadFromFile, GIF images not supported: '.$imagepath, OC_Log::DEBUG); OC_Log::write('core', 'OC_Image->loadFromFile, GIF images not supported: '.$imagepath, OC_Log::DEBUG);
} }
break; break;
case IMAGETYPE_JPEG: case IMAGETYPE_JPEG:
if (imagetypes() & IMG_JPG) { if (imagetypes() & IMG_JPG) {
$this->resource = imagecreatefromjpeg($imagepath); $this->resource = imagecreatefromjpeg($imagepath);
} else { } else {
OC_Log::write('core','OC_Image->loadFromFile, JPG images not supported: '.$imagepath, OC_Log::DEBUG); OC_Log::write('core', 'OC_Image->loadFromFile, JPG images not supported: '.$imagepath, OC_Log::DEBUG);
} }
break; break;
case IMAGETYPE_PNG: case IMAGETYPE_PNG:
if (imagetypes() & IMG_PNG) { if (imagetypes() & IMG_PNG) {
$this->resource = imagecreatefrompng($imagepath); $this->resource = imagecreatefrompng($imagepath);
} else { } else {
OC_Log::write('core','OC_Image->loadFromFile, PNG images not supported: '.$imagepath, OC_Log::DEBUG); OC_Log::write('core', 'OC_Image->loadFromFile, PNG images not supported: '.$imagepath, OC_Log::DEBUG);
} }
break; break;
case IMAGETYPE_XBM: case IMAGETYPE_XBM:
if (imagetypes() & IMG_XPM) { if (imagetypes() & IMG_XPM) {
$this->resource = imagecreatefromxbm($imagepath); $this->resource = imagecreatefromxbm($imagepath);
} else { } else {
OC_Log::write('core','OC_Image->loadFromFile, XBM/XPM images not supported: '.$imagepath, OC_Log::DEBUG); OC_Log::write('core', 'OC_Image->loadFromFile, XBM/XPM images not supported: '.$imagepath, OC_Log::DEBUG);
} }
break; break;
case IMAGETYPE_WBMP: case IMAGETYPE_WBMP:
@ -440,7 +440,7 @@ class OC_Image {
if (imagetypes() & IMG_WBMP) { if (imagetypes() & IMG_WBMP) {
$this->resource = imagecreatefromwbmp($imagepath); $this->resource = imagecreatefromwbmp($imagepath);
} else { } else {
OC_Log::write('core','OC_Image->loadFromFile, (W)BMP images not supported: '.$imagepath, OC_Log::DEBUG); OC_Log::write('core', 'OC_Image->loadFromFile, (W)BMP images not supported: '.$imagepath, OC_Log::DEBUG);
} }
break; break;
/* /*
@ -472,7 +472,7 @@ class OC_Image {
// this is mostly file created from encrypted file // this is mostly file created from encrypted file
$this->resource = imagecreatefromstring(\OC_Filesystem::file_get_contents(\OC_Filesystem::getLocalPath($imagepath))); $this->resource = imagecreatefromstring(\OC_Filesystem::file_get_contents(\OC_Filesystem::getLocalPath($imagepath)));
$itype = IMAGETYPE_PNG; $itype = IMAGETYPE_PNG;
OC_Log::write('core','OC_Image->loadFromFile, Default', OC_Log::DEBUG); OC_Log::write('core', 'OC_Image->loadFromFile, Default', OC_Log::DEBUG);
break; break;
} }
if($this->valid()) { if($this->valid()) {
@ -493,7 +493,7 @@ class OC_Image {
} }
$this->resource = @imagecreatefromstring($str); $this->resource = @imagecreatefromstring($str);
if(!$this->resource) { if(!$this->resource) {
OC_Log::write('core','OC_Image->loadFromData, couldn\'t load', OC_Log::DEBUG); OC_Log::write('core', 'OC_Image->loadFromData, couldn\'t load', OC_Log::DEBUG);
return false; return false;
} }
return $this->resource; return $this->resource;
@ -512,7 +512,7 @@ class OC_Image {
if($data) { // try to load from string data if($data) { // try to load from string data
$this->resource = @imagecreatefromstring($data); $this->resource = @imagecreatefromstring($data);
if(!$this->resource) { if(!$this->resource) {
OC_Log::write('core','OC_Image->loadFromBase64, couldn\'t load', OC_Log::DEBUG); OC_Log::write('core', 'OC_Image->loadFromBase64, couldn\'t load', OC_Log::DEBUG);
return false; return false;
} }
return $this->resource; return $this->resource;
@ -528,7 +528,7 @@ class OC_Image {
*/ */
public function resize($maxsize) { public function resize($maxsize) {
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;
} }
@ -580,7 +580,7 @@ class OC_Image {
*/ */
public function centerCrop($size=0) { public function centerCrop($size=0) {
if(!$this->valid()) { if(!$this->valid()) {
OC_Log::write('core','OC_Image->centerCrop, No image loaded', OC_Log::ERROR); OC_Log::write('core', 'OC_Image->centerCrop, No image loaded', OC_Log::ERROR);
return false; return false;
} }
$width_orig=imageSX($this->resource); $width_orig=imageSX($this->resource);
@ -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;
} }
@ -632,18 +632,18 @@ class OC_Image {
*/ */
public function crop($x, $y, $w, $h) { public function crop($x, $y, $w, $h) {
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;
} }
$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;
} }
@ -660,7 +660,7 @@ class OC_Image {
*/ */
public function fitIn($maxWidth, $maxHeight) { public function fitIn($maxWidth, $maxHeight) {
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);

View File

@ -97,7 +97,7 @@ class OC_Installer{
if($archive=OC_Archive::open($path)) { if($archive=OC_Archive::open($path)) {
$archive->extract($extractDir); $archive->extract($extractDir);
} else { } else {
OC_Log::write('core','Failed to open archive when installing app',OC_Log::ERROR); OC_Log::write('core', 'Failed to open archive when installing app', OC_Log::ERROR);
OC_Helper::rmdirr($extractDir); OC_Helper::rmdirr($extractDir);
if($data['source']=='http') { if($data['source']=='http') {
unlink($path); unlink($path);
@ -118,7 +118,7 @@ class OC_Installer{
} }
} }
if(!is_file($extractDir.'/appinfo/info.xml')) { if(!is_file($extractDir.'/appinfo/info.xml')) {
OC_Log::write('core','App does not provide an info.xml file',OC_Log::ERROR); OC_Log::write('core', 'App does not provide an info.xml file', OC_Log::ERROR);
OC_Helper::rmdirr($extractDir); OC_Helper::rmdirr($extractDir);
if($data['source']=='http') { if($data['source']=='http') {
unlink($path); unlink($path);
@ -127,8 +127,8 @@ class OC_Installer{
} }
$info=OC_App::getAppInfo($extractDir.'/appinfo/info.xml', true); $info=OC_App::getAppInfo($extractDir.'/appinfo/info.xml', true);
// check the code for not allowed calls // check the code for not allowed calls
if(!OC_Installer::checkCode($info['id'],$extractDir)) { if(!OC_Installer::checkCode($info['id'], $extractDir)) {
OC_Log::write('core','App can\'t be installed because of not allowed code in the App',OC_Log::ERROR); OC_Log::write('core', 'App can\'t be installed because of not allowed code in the App', OC_Log::ERROR);
OC_Helper::rmdirr($extractDir); OC_Helper::rmdirr($extractDir);
return false; return false;
} }
@ -136,14 +136,14 @@ class OC_Installer{
// check if the app is compatible with this version of ownCloud // check if the app is compatible with this version of ownCloud
$version=OC_Util::getVersion(); $version=OC_Util::getVersion();
if(!isset($info['require']) or ($version[0]>$info['require'])) { if(!isset($info['require']) or ($version[0]>$info['require'])) {
OC_Log::write('core','App can\'t be installed because it is not compatible with this version of ownCloud',OC_Log::ERROR); OC_Log::write('core', 'App can\'t be installed because it is not compatible with this version of ownCloud', OC_Log::ERROR);
OC_Helper::rmdirr($extractDir); OC_Helper::rmdirr($extractDir);
return false; return false;
} }
//check if an app with the same id is already installed //check if an app with the same id is already installed
if(self::isInstalled( $info['id'] )) { if(self::isInstalled( $info['id'] )) {
OC_Log::write('core','App already installed',OC_Log::WARN); OC_Log::write('core', 'App already installed', OC_Log::WARN);
OC_Helper::rmdirr($extractDir); OC_Helper::rmdirr($extractDir);
if($data['source']=='http') { if($data['source']=='http') {
unlink($path); unlink($path);
@ -154,7 +154,7 @@ class OC_Installer{
$basedir=OC_App::getInstallPath().'/'.$info['id']; $basedir=OC_App::getInstallPath().'/'.$info['id'];
//check if the destination directory already exists //check if the destination directory already exists
if(is_dir($basedir)) { if(is_dir($basedir)) {
OC_Log::write('core','App directory already exists',OC_Log::WARN); OC_Log::write('core', 'App directory already exists', OC_Log::WARN);
OC_Helper::rmdirr($extractDir); OC_Helper::rmdirr($extractDir);
if($data['source']=='http') { if($data['source']=='http') {
unlink($path); unlink($path);
@ -168,14 +168,14 @@ class OC_Installer{
//copy the app to the correct place //copy the app to the correct place
if(@!mkdir($basedir)) { if(@!mkdir($basedir)) {
OC_Log::write('core','Can\'t create app folder. Please fix permissions. ('.$basedir.')',OC_Log::ERROR); OC_Log::write('core', 'Can\'t create app folder. Please fix permissions. ('.$basedir.')', OC_Log::ERROR);
OC_Helper::rmdirr($extractDir); OC_Helper::rmdirr($extractDir);
if($data['source']=='http') { if($data['source']=='http') {
unlink($path); unlink($path);
} }
return false; return false;
} }
OC_Helper::copyr($extractDir,$basedir); OC_Helper::copyr($extractDir, $basedir);
//remove temporary files //remove temporary files
OC_Helper::rmdirr($extractDir); OC_Helper::rmdirr($extractDir);
@ -191,8 +191,8 @@ class OC_Installer{
} }
//set the installed version //set the installed version
OC_Appconfig::setValue($info['id'],'installed_version',OC_App::getAppVersion($info['id'])); OC_Appconfig::setValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id']));
OC_Appconfig::setValue($info['id'],'enabled','no'); OC_Appconfig::setValue($info['id'], 'enabled', 'no');
//set remote/public handelers //set remote/public handelers
foreach($info['remote'] as $name=>$path) { foreach($info['remote'] as $name=>$path) {
@ -296,7 +296,7 @@ class OC_Installer{
$enabled = isset($info['default_enable']); $enabled = isset($info['default_enable']);
if( $enabled ) { if( $enabled ) {
OC_Installer::installShippedApp($filename); OC_Installer::installShippedApp($filename);
OC_Appconfig::setValue($filename,'enabled','yes'); OC_Appconfig::setValue($filename, 'enabled', 'yes');
} }
} }
} }
@ -323,7 +323,7 @@ class OC_Installer{
include OC_App::getAppPath($app)."/appinfo/install.php"; include OC_App::getAppPath($app)."/appinfo/install.php";
} }
$info=OC_App::getAppInfo($app); $info=OC_App::getAppInfo($app);
OC_Appconfig::setValue($app,'installed_version',OC_App::getAppVersion($app)); OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app));
//set remote/public handelers //set remote/public handelers
foreach($info['remote'] as $name=>$path) { foreach($info['remote'] as $name=>$path) {
@ -360,7 +360,7 @@ class OC_Installer{
// check if grep is installed // check if grep is installed
$grep = exec('which grep'); $grep = exec('which grep');
if($grep=='') { if($grep=='') {
OC_Log::write('core','grep not installed. So checking the code of the app "'.$appname.'" was not possible',OC_Log::ERROR); OC_Log::write('core', 'grep not installed. So checking the code of the app "'.$appname.'" was not possible', OC_Log::ERROR);
return true; return true;
} }
@ -370,7 +370,7 @@ class OC_Installer{
$result = exec($cmd); $result = exec($cmd);
// bad pattern found // bad pattern found
if($result<>'') { if($result<>'') {
OC_Log::write('core','App "'.$appname.'" is using a not allowed call "'.$bl.'". Installation refused.',OC_Log::ERROR); OC_Log::write('core', 'App "'.$appname.'" is using a not allowed call "'.$bl.'". Installation refused.', OC_Log::ERROR);
return false; return false;
} }
} }

View File

@ -39,7 +39,7 @@ class OC_Util {
$CONFIG_DATADIRECTORY = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" ); $CONFIG_DATADIRECTORY = OC_Config::getValue( "datadirectory", OC::$SERVERROOT."/data" );
//first set up the local "root" storage //first set up the local "root" storage
if(!self::$rootMounted) { if(!self::$rootMounted) {
OC_Filesystem::mount('OC_Filestorage_Local', array('datadir'=>$CONFIG_DATADIRECTORY),'/'); OC_Filesystem::mount('OC_Filestorage_Local', array('datadir'=>$CONFIG_DATADIRECTORY), '/');
self::$rootMounted=true; self::$rootMounted=true;
} }
@ -81,10 +81,10 @@ class OC_Util {
} }
$mtime=filemtime($user_root.'/mount.php'); $mtime=filemtime($user_root.'/mount.php');
$previousMTime=OC_Preferences::getValue($user,'files','mountconfigmtime',0); $previousMTime=OC_Preferences::getValue($user, 'files', 'mountconfigmtime', 0);
if($mtime>$previousMTime) {//mount config has changed, filecache needs to be updated if($mtime>$previousMTime) {//mount config has changed, filecache needs to be updated
OC_FileCache::triggerUpdate($user); OC_FileCache::triggerUpdate($user);
OC_Preferences::setValue($user,'files','mountconfigmtime',$mtime); OC_Preferences::setValue($user, 'files', 'mountconfigmtime', $mtime);
} }
} }
} }
@ -169,7 +169,7 @@ class OC_Util {
public static function formatDate( $timestamp,$dateOnly=false) { public static function formatDate( $timestamp,$dateOnly=false) {
if(isset($_SESSION['timezone'])) {//adjust to clients timezone if we know it if(isset($_SESSION['timezone'])) {//adjust to clients timezone if we know it
$systemTimeZone = intval(date('O')); $systemTimeZone = intval(date('O'));
$systemTimeZone=(round($systemTimeZone/100,0)*60)+($systemTimeZone%100); $systemTimeZone=(round($systemTimeZone/100, 0)*60)+($systemTimeZone%100);
$clientTimeZone=$_SESSION['timezone']*60; $clientTimeZone=$_SESSION['timezone']*60;
$offset=$clientTimeZone-$systemTimeZone; $offset=$clientTimeZone-$systemTimeZone;
$timestamp=$timestamp+$offset*60; $timestamp=$timestamp+$offset*60;
@ -196,11 +196,11 @@ class OC_Util {
if($pagestop>$pagecount) $pagestop=$pagecount; if($pagestop>$pagecount) $pagestop=$pagecount;
$tmpl = new OC_Template( '', 'part.pagenavi', '' ); $tmpl = new OC_Template( '', 'part.pagenavi', '' );
$tmpl->assign('page',$page); $tmpl->assign('page', $page);
$tmpl->assign('pagecount',$pagecount); $tmpl->assign('pagecount', $pagecount);
$tmpl->assign('pagestart',$pagestart); $tmpl->assign('pagestart', $pagestart);
$tmpl->assign('pagestop',$pagestop); $tmpl->assign('pagestop', $pagestop);
$tmpl->assign('url',$url); $tmpl->assign('url', $url);
return $tmpl; return $tmpl;
} }
} }
@ -241,24 +241,24 @@ class OC_Util {
//check for correct file permissions //check for correct file permissions
if(!stristr(PHP_OS, 'WIN')) { if(!stristr(PHP_OS, 'WIN')) {
$permissionsModHint="Please change the permissions to 0770 so that the directory cannot be listed by other users."; $permissionsModHint="Please change the permissions to 0770 so that the directory cannot be listed by other users.";
$prems=substr(decoct(@fileperms($CONFIG_DATADIRECTORY)),-3); $prems=substr(decoct(@fileperms($CONFIG_DATADIRECTORY)), -3);
if(substr($prems,-1)!='0') { if(substr($prems, -1)!='0') {
OC_Helper::chmodr($CONFIG_DATADIRECTORY,0770); OC_Helper::chmodr($CONFIG_DATADIRECTORY, 0770);
clearstatcache(); clearstatcache();
$prems=substr(decoct(@fileperms($CONFIG_DATADIRECTORY)),-3); $prems=substr(decoct(@fileperms($CONFIG_DATADIRECTORY)), -3);
if(substr($prems,2,1)!='0') { if(substr($prems, 2, 1)!='0') {
$errors[]=array('error'=>'Data directory ('.$CONFIG_DATADIRECTORY.') is readable for other users<br/>','hint'=>$permissionsModHint); $errors[]=array('error'=>'Data directory ('.$CONFIG_DATADIRECTORY.') is readable for other users<br/>', 'hint'=>$permissionsModHint);
} }
} }
if( OC_Config::getValue( "enablebackup", false )) { if( OC_Config::getValue( "enablebackup", false )) {
$CONFIG_BACKUPDIRECTORY = OC_Config::getValue( "backupdirectory", OC::$SERVERROOT."/backup" ); $CONFIG_BACKUPDIRECTORY = OC_Config::getValue( "backupdirectory", OC::$SERVERROOT."/backup" );
$prems=substr(decoct(@fileperms($CONFIG_BACKUPDIRECTORY)),-3); $prems=substr(decoct(@fileperms($CONFIG_BACKUPDIRECTORY)), -3);
if(substr($prems,-1)!='0') { if(substr($prems, -1)!='0') {
OC_Helper::chmodr($CONFIG_BACKUPDIRECTORY,0770); OC_Helper::chmodr($CONFIG_BACKUPDIRECTORY, 0770);
clearstatcache(); clearstatcache();
$prems=substr(decoct(@fileperms($CONFIG_BACKUPDIRECTORY)),-3); $prems=substr(decoct(@fileperms($CONFIG_BACKUPDIRECTORY)), -3);
if(substr($prems,2,1)!='0') { if(substr($prems, 2, 1)!='0') {
$errors[]=array('error'=>'Data directory ('.$CONFIG_BACKUPDIRECTORY.') is readable for other users<br/>','hint'=>$permissionsModHint); $errors[]=array('error'=>'Data directory ('.$CONFIG_BACKUPDIRECTORY.') is readable for other users<br/>', 'hint'=>$permissionsModHint);
} }
} }
} }
@ -391,7 +391,7 @@ class OC_Util {
// Check if we are a user // Check if we are a user
self::checkLoggedIn(); self::checkLoggedIn();
self::verifyUser(); self::verifyUser();
if(OC_Group::inGroup(OC_User::getUser(),'admin')) { if(OC_Group::inGroup(OC_User::getUser(), 'admin')) {
return true; return true;
} }
if(!OC_SubAdmin::isSubAdmin(OC_User::getUser())) { if(!OC_SubAdmin::isSubAdmin(OC_User::getUser())) {
@ -467,7 +467,7 @@ class OC_Util {
$id=OC_Config::getValue('instanceid', null); $id=OC_Config::getValue('instanceid', null);
if(is_null($id)) { if(is_null($id)) {
$id=uniqid(); $id=uniqid();
OC_Config::setValue('instanceid',$id); OC_Config::setValue('instanceid', $id);
} }
return $id; return $id;
} }
@ -504,10 +504,10 @@ class OC_Util {
// cleanup old tokens garbage collector // cleanup old tokens garbage collector
// only run every 20th time so we don't waste cpu cycles // only run every 20th time so we don't waste cpu cycles
if(rand(0,20)==0) { if(rand(0, 20)==0) {
foreach($_SESSION as $key=>$value) { foreach($_SESSION as $key=>$value) {
// search all tokens in the session // search all tokens in the session
if(substr($key,0,12)=='requesttoken') { if(substr($key, 0, 12)=='requesttoken') {
// check if static lifespan has expired // check if static lifespan has expired
if($value+self::$callLifespan<time()) { if($value+self::$callLifespan<time()) {
// remove outdated tokens // remove outdated tokens
@ -571,7 +571,7 @@ class OC_Util {
* @return array with sanitized strings or a single sanitized string, depends on the input parameter. * @return array with sanitized strings or a single sanitized string, depends on the input parameter.
*/ */
public static function sanitizeHTML( &$value ) { public static function sanitizeHTML( &$value ) {
if (is_array($value) || is_object($value)) array_walk_recursive($value,'OC_Util::sanitizeHTML'); if (is_array($value) || is_object($value)) array_walk_recursive($value, 'OC_Util::sanitizeHTML');
else $value = htmlentities($value, ENT_QUOTES, 'UTF-8'); //Specify encoding for PHP<5.4 else $value = htmlentities($value, ENT_QUOTES, 'UTF-8'); //Specify encoding for PHP<5.4
return $value; return $value;
} }