diff --git a/apps/contacts/ajax/uploadphoto.php b/apps/contacts/ajax/uploadphoto.php index 09c4e55d4a..32abc6c285 100644 --- a/apps/contacts/ajax/uploadphoto.php +++ b/apps/contacts/ajax/uploadphoto.php @@ -59,7 +59,7 @@ if ($fn) { bailOut(OC_Contacts_App::$l10n->t('Couldn\'t save temporary image: ').$tmpkey); } } else { - bailOut(OC_Contacts_App::$l10n->t('Couldn\'t load temporary image: ').$tmpkey.$data); + bailOut(OC_Contacts_App::$l10n->t('Couldn\'t load temporary image: ').$tmpkey); } } diff --git a/apps/files_archive/lib/storage.php b/apps/files_archive/lib/storage.php index b8f7d46838..8676166361 100644 --- a/apps/files_archive/lib/storage.php +++ b/apps/files_archive/lib/storage.php @@ -18,7 +18,7 @@ class OC_Filestorage_Archive extends OC_Filestorage_Common{ private static $rootView; private function stripPath($path){//files should never start with / - if(substr($path,0,1)=='/'){ + if(!$path || $path[0]=='/'){ $path=substr($path,1); } return $path; diff --git a/apps/files_external/lib/ftp.php b/apps/files_external/lib/ftp.php index e9655ebf3a..4d5ae670de 100644 --- a/apps/files_external/lib/ftp.php +++ b/apps/files_external/lib/ftp.php @@ -21,7 +21,7 @@ class OC_FileStorage_FTP extends OC_FileStorage_StreamWrapper{ $this->password=$params['password']; $this->secure=isset($params['secure'])?(bool)$params['secure']:false; $this->root=isset($params['root'])?$params['root']:'/'; - if(substr($this->root,0,1)!='/'){ + if(!$this->root || $this->root[0]!='/'){ $this->root='/'.$this->root; } diff --git a/apps/files_external/lib/smb.php b/apps/files_external/lib/smb.php index f594fbb880..9112655194 100644 --- a/apps/files_external/lib/smb.php +++ b/apps/files_external/lib/smb.php @@ -23,13 +23,13 @@ class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{ $this->password=$params['password']; $this->share=$params['share']; $this->root=isset($params['root'])?$params['root']:'/'; + if(!$this->root || $this->root[0]!='/'){ + $this->root='/'.$this->root; + } if(substr($this->root,-1,1)!='/'){ $this->root.='/'; } - if(substr($this->root,0,1)!='/'){ - $this->root='/'.$this->root; - } - if(substr($this->share,0,1)!='/'){ + if(!$this->share || $this->share[0]!='/'){ $this->share='/'.$this->share; } if(substr($this->share,-1,1)=='/'){ diff --git a/apps/files_external/lib/swift.php b/apps/files_external/lib/swift.php index e3ba9c240c..58b95a6ae0 100644 --- a/apps/files_external/lib/swift.php +++ b/apps/files_external/lib/swift.php @@ -269,7 +269,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{ $this->user=$params['user']; $this->root=isset($params['root'])?$params['root']:'/'; $this->secure=isset($params['secure'])?(bool)$params['secure']:true; - if(substr($this->root,0,1)!='/'){ + if(!$this->root || $this->root[0]!='/'){ $this->root='/'.$this->root; } $this->auth = new CF_Authentication($this->user, $this->token, null, $this->host); diff --git a/apps/files_external/lib/webdav.php b/apps/files_external/lib/webdav.php index 07c90d4878..d136f04f3e 100644 --- a/apps/files_external/lib/webdav.php +++ b/apps/files_external/lib/webdav.php @@ -25,7 +25,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{ $this->password=$params['password']; $this->secure=isset($params['secure'])?(bool)$params['secure']:false; $this->root=isset($params['root'])?$params['root']:'/'; - if(substr($this->root,0,1)!='/'){ + if(!$this->root || $this->root[0]!='/'){ $this->root='/'.$this->root; } if(substr($this->root,-1,1)!='/'){ @@ -273,7 +273,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{ } private function cleanPath($path){ - if(substr($path,0,1)=='/'){ + if(!$path || $path[0]=='/'){ return substr($path,1); }else{ return $path; diff --git a/apps/gallery/appinfo/app.php b/apps/gallery/appinfo/app.php index e1db33eb31..2aa6a9e8f9 100644 --- a/apps/gallery/appinfo/app.php +++ b/apps/gallery/appinfo/app.php @@ -26,6 +26,8 @@ OC::$CLASSPATH['OC_Gallery_Photo'] = 'apps/gallery/lib/photo.php'; OC::$CLASSPATH['OC_Gallery_Scanner'] = 'apps/gallery/lib/scanner.php'; OC::$CLASSPATH['OC_Gallery_Sharing'] = 'apps/gallery/lib/sharing.php'; OC::$CLASSPATH['OC_Gallery_Hooks_Handlers'] = 'apps/gallery/lib/hooks_handlers.php'; +OC::$CLASSPATH['Pictures_Managers'] = 'apps/gallery/lib/managers.php'; +OC::$CLASSPATH['Pictures_Tiles'] = 'apps/gallery/lib/tiles.php'; $l = OC_L10N::get('gallery'); diff --git a/apps/gallery/css/styles.css b/apps/gallery/css/styles.css index fbf54e43db..98d3651549 100644 --- a/apps/gallery/css/styles.css +++ b/apps/gallery/css/styles.css @@ -1,20 +1,6 @@ -div#gallery_list { margin: 4.5em 2em 0 2em; } -div#gallery_list.leftcontent { padding-top: 15pt; margin: 0; position: absolute; bottom:0px; text-align: center; overflow: auto; } -div.gallery_box { width: 200px; position:relative; text-align: center; border: 0; display: inline-block; margin: 5pt; vertical-align: top; padding: 5px 5px 5px 5px; position: relative; -webkit-transition: color 0.5s ease-in-out; -o-transition: color 0.5s ease-in-out; -moz-transition: color 0.5s ease-in-out;color: #BBB;} -div.album {border: 1px solid #e0e0e0; border-radius: 7px;} -div.gallery_box h1 { font-size: 9pt; font-family: Verdana; } -div.gallery_album_decoration { width: 200px; position: absolute; border: 0; height: 20px; top: 5px; text-align:right; vertical-align:middle; background-color: #eee; opacity: 0; -webkit-transition: opacity 0.5s ease-in-out; -moz-transition: opacity 0.5s ease-in-out; -o-transition: opacity 0.5s ease-in-out; } -div.gallery_box:hover { color: black; } -div.gallery_box:hover div.gallery_album_decoration { opacity: 0.7;} -div.gallery_album_decoration a {padding: 0 4pt; cursor: pointer;} -div.gallery_album_cover { width: 200px; height: 200px; border: 0; padding: 0; position:relative;} -div.gallery_box:hover div.gallery_control_overlay { opacity:0.5 } -div.gallery_control_overlay a { color:white; } -#gallery_images.rightcontent { padding:10px 5px; bottom: 0px; overflow: auto; right:0px} -#scan { position:absolute; right:13.5em; top:0em; } -#scan #scanprogressbar { position:relative; display:inline-block; width:10em; height:1.5em; top:.4em; } +#gallerycontent { margin-top: 2.8em; overflow: visible; } #g-settings {position: absolute; left 13.5em; top: 0;} -input[type=button] { -webkit-transition: opacity 0.5s ease-in-out; -moz-transition: opacity 0.5s ease-in-out; -o-transition: opacity 0.5s ease-in-out; opacity: 1} +div#controls input[type=button] { -webkit-transition: opacity 0.5s ease-in-out; -moz-transition: opacity 0.5s ease-in-out; -o-transition: opacity 0.5s ease-in-out; opacity: 1; position:absolute; right:13.5em; top:0em; } input[type=button]:disabled { opacity: 0.5 } .ui-dialog tr {background-color: #eee;} .ui-dialog input {width: 90%;} diff --git a/apps/gallery/index.php b/apps/gallery/index.php index 9d4654a7cc..b87d99bb6c 100644 --- a/apps/gallery/index.php +++ b/apps/gallery/index.php @@ -27,6 +27,10 @@ OCP\User::checkLoggedIn(); OCP\App::checkAppEnabled('gallery'); OCP\App::setActiveNavigationEntry( 'gallery_index' ); +OCP\Util::addStyle('files', 'files'); +OCP\Util::addStyle('gallery', 'styles'); +OCP\Util::addScript('gallery', 'pictures'); + $tmpl = new OCP\Template( 'gallery', 'index', 'user' ); $tmpl->printPage(); ?> diff --git a/apps/gallery/js/album_cover.js b/apps/gallery/js/album_cover.js deleted file mode 100644 index 905034f6fd..0000000000 --- a/apps/gallery/js/album_cover.js +++ /dev/null @@ -1,138 +0,0 @@ -var actual_cover; -var paths = []; -var crumbCount = 0; -$(document).ready(returnToElement(0)); - -function returnToElement(num) { - while (crumbCount != num) { - $('#g-album-navigation .last').remove(); - $('#g-album-navigation .crumb :last').parent().addClass('last'); - crumbCount--; - paths.pop(); - } - var p=''; - for (var i in paths) p += paths[i]+'/'; - $('#g-album-loading').show(); - $.getJSON(OC.filePath('gallery','ajax','galleryOp.php'), {operation: 'get_gallery', path: p }, albumClickHandler); -} - -function albumClick(title) { - paths.push(title); - crumbCount++; - var p = ''; - for (var i in paths) p += paths[i]+'/'; - $('#g-album-loading').show(); - $.getJSON(OC.filePath('gallery','ajax','galleryOp.php'), {operation: 'get_gallery', path: p }, function(r) { - albumClickHandler(r); - if ($('#g-album-navigation :last-child')) - $('#g-album-navigation :last-child').removeClass('last'); - $('#g-album-navigation').append('
'+decodeURIComponent(escape(title))+'
'); - }); -} - -function constructSharingPath() { - return document.location.protocol + '//' + document.location.host + OC.linkTo('', 'public.php') + '?service=gallery&token=' + Albums.token; -} - -function shareGallery() { - var existing_token = ''; - if (Albums.token) - existing_token = constructSharingPath(); - var form_fields = [{text: 'Share', name: 'share', type: 'checkbox', value: Albums.shared}, - {text: 'Share recursive', name: 'recursive', type: 'checkbox', value: Albums.recursive}, - {text: 'Shared gallery address', name: 'address', type: 'text', value: existing_token}]; - OC.dialogs.form(form_fields, t('gallery', 'Share gallery'), function(values){ - var p = ''; - for (var i in paths) p += paths[i]+'/'; - if (p == '') p = '/'; - alert(p); - $.getJSON(OC.filePath('gallery', 'ajax', 'galleryOp.php'), {operation: 'share', path: p, share: values[0].value, recursive: values[1].value}, function(r) { - if (r.status == 'success') { - Albums.shared = r.sharing; - if (Albums.shared) { - Albums.token = r.token; - Albums.recursive = r.recursive; - } else { - Albums.token = ''; - Albums.recursive = false; - } - var actual_addr = ''; - if (Albums.token) - actual_addr = constructSharingPath(); - $('input[name="address"]').val(actual_addr); - } else { - OC.dialogs.alert(t('gallery', 'Error: ') + r.cause, t('gallery', 'Internal error')); - } - }); - }); -} - -function albumClickHandler(r) { - Albums.photos = []; - Albums.albums = []; - if (r.status == 'success') { - for (var i in r.albums) { - var a = r.albums[i]; - Albums.add(a.name, a.numOfItems, a.path, a.shared, a.recursive, a.token); - } - for (var i in r.photos) { - Albums.photos.push(r.photos[i]); - } - Albums.shared = r.shared; - if (Albums.shared) { - Albums.recursive = r.recursive; - Albums.token = r.token; - } else { - Albums.recursive = false; - Albums.token = ''; - } - $(document).ready(function(){ - var targetDiv = $('#gallery_list'); - targetDiv.html(''); - Albums.display(targetDiv); - //$('#gallery_list').sortable({revert:true}); - $('.album').each(function(i, el) { - $(el).click(albumClick.bind(null,$(el).attr('title'))); - //$(el).draggable({connectToSortable: '#gallery_list', handle: '.dummy'}); - }); - }); - } else { - OC.dialogs.alert(t('gallery', 'Error: ') + r.cause, t('gallery', 'Internal error')); - } - $('#g-album-loading').hide(); -} - -var albumCounter = 0; -var totalAlbums = 0; - -function scanForAlbums(cleanup) { - Scanner.scanAlbums(); - return; -} - -function settings() { - OC.dialogs.form([{text: t('gallery', 'Scanning root'), name: 'root', type:'text', value:gallery_scanning_root}, - {text: t('gallery', 'Default order'), name: 'order', type:'select', value:gallery_default_order, options:[ - {text:t('gallery', 'Ascending'), value:'ASC'}, {text: t('gallery', 'Descending'), value:'DESC'} ]}], - t('gallery', 'Settings'), - function(values) { - var scanning_root = values[0].value; - var disp_order = values[1].value; - if (scanning_root == '') { - OC.dialogs.alert(t('gallery', 'Scanning root cannot be empty'), t('gallery', 'Error')); - return; - } - $.getJSON(OC.filePath('gallery','ajax','galleryOp.php'), {operation: 'store_settings', root: scanning_root, order: disp_order}, function(r) { - if (r.status == 'success') { - if (r.rescan == 'yes') { - Albums.clear(document.getElementById('gallery_list')); - scanForAlbums(true); - } - gallery_scanning_root = scanning_root; - } else { - OC.dialogs.alert(t('gallery', 'Error: ') + r.cause, t('gallery', 'Error')); - return; - } - }); - }); -} diff --git a/apps/gallery/js/pictures.js b/apps/gallery/js/pictures.js new file mode 100644 index 0000000000..678c9bcbf5 --- /dev/null +++ b/apps/gallery/js/pictures.js @@ -0,0 +1,37 @@ + +function constructSharingPath() { + return document.location.protocol + '//' + document.location.host + OC.linkTo('', 'public.php') + '?service=gallery&token=' + Albums.token; +} + +function shareGallery() { + var existing_token = ''; + //if (Albums.token) + // existing_token = constructSharingPath(); + var form_fields = [{text: 'Share', name: 'share', type: 'checkbox', value: false}, + {text: 'Share recursive', name: 'recursive', type: 'checkbox', value: false}, + {text: 'Shared gallery address', name: 'address', type: 'text', value: ''}]; + OC.dialogs.form(form_fields, t('gallery', 'Share gallery'), function(values){ + var p = ''; + for (var i in paths) p += paths[i]+'/'; + if (p == '') p = '/'; + alert(p); + $.getJSON(OC.filePath('gallery', 'ajax', 'galleryOp.php'), {operation: 'share', path: p, share: values[0].value, recursive: values[1].value}, function(r) { + if (r.status == 'success') { + Albums.shared = r.sharing; + if (Albums.shared) { + Albums.token = r.token; + Albums.recursive = r.recursive; + } else { + Albums.token = ''; + Albums.recursive = false; + } + var actual_addr = ''; + if (Albums.token) + actual_addr = constructSharingPath(); + $('input[name="address"]').val(actual_addr); + } else { + OC.dialogs.alert(t('gallery', 'Error: ') + r.cause, t('gallery', 'Internal error')); + } + }); + }); +} diff --git a/apps/gallery/lib/hooks_handlers.php b/apps/gallery/lib/hooks_handlers.php index 6391e9f4e5..a9f4dc6aff 100644 --- a/apps/gallery/lib/hooks_handlers.php +++ b/apps/gallery/lib/hooks_handlers.php @@ -13,136 +13,30 @@ * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* +* * You should have received a copy of the GNU Lesser General Public -* License along with this library. If not, see . +* License along with this library. If not, see . * */ -OCP\Util::connectHook(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_write, "OC_Gallery_Hooks_Handlers", "addPhotoFromPath"); OCP\Util::connectHook(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_delete, "OC_Gallery_Hooks_Handlers", "removePhoto"); //OCP\Util::connectHook(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_rename, "OC_Gallery_Hooks_Handlers", "renamePhoto"); -require_once(OC::$CLASSPATH['OC_Gallery_Album']); -require_once(OC::$CLASSPATH['OC_Gallery_Photo']); +require_once(OC::$CLASSPATH['Pictures_Managers']); class OC_Gallery_Hooks_Handlers { - private static $APP_TAG = "Gallery"; - private static function isPhoto($filename) { - $ext = strtolower(substr($filename, strrpos($filename, '.')+1)); - return $ext=='png' || $ext=='jpeg' || $ext=='jpg' || $ext=='gif'; - } + public static function removePhoto($params) { + \OC\Pictures\ThumbnailsManager::getInstance()->delete($params[OC_Filesystem::signal_param_path]); + } - private static function directoryContainsPhotos($dirpath) { - $dirhandle = OC_Filesystem::opendir($dirpath.'/'); - if ($dirhandle != FALSE) { - while (($filename = readdir($dirhandle)) != FALSE) { - if ($filename[0] == '.') continue; - if (self::isPhoto($dirpath.'/'.$filename)) return true; - } - } - return false; - } - - private static function createAlbum($path) { - $new_album_name = trim(str_replace('/', '.', $path), '.'); - if ($new_album_name == '') - $new_album_name = 'main'; - - OCP\Util::writeLog(self::$APP_TAG, 'Creating new album '.$new_album_name, OCP\Util::DEBUG); - OC_Gallery_Album::create(OCP\USER::getUser(), $new_album_name, $path); - - return OC_Gallery_Album::find(OCP\USER::getUser(), null, $path); - } - - public static function pathInRoot($path) { - $root = OCP\Config::getUserValue(OCP\USER::getUser(), 'gallery', 'root', '/'); - return substr($path, 0, strlen($path)>strlen($root)?strlen($root):strlen($path)) == $root; - } - - public static function addPhotoFromPath($params) { - $fullpath = $params[OC_Filesystem::signal_param_path]; - $fullpath = rtrim(dirname($fullpath),'/').'/'.basename($fullpath); - - if (!self::isPhoto($fullpath)) return; - - $a = OC_Gallery_Album::find(OCP\USER::getUser(), null, dirname($fullpath)); - if (!($r = $a->fetchRow())) { - OC_Gallery_Album::create(OCP\USER::getUser(), basename(dirname($fullpath)), dirname($fullpath)); - $a = OC_Gallery_Album::find(OCP\USER::getUser(), null, dirname($fullpath)); - $r = $a->fetchRow(); - } - $albumId = $r['album_id']; - $p = OC_Gallery_Album::find($albumId, $fullpath); - if (!($p->fetchRow())) - OC_Gallery_Photo::create($albumId, $fullpath); - } - - public static function removePhoto($params) { - $fullpath = $params[OC_Filesystem::signal_param_path]; - $fullpath = rtrim(dirname($fullpath),'/').'/'.basename($fullpath); - - if (OC_Filesystem::is_dir($fullpath)) { - OC_Gallery_Album::remove(OCP\USER::getUser(), null, $fullpath); - } elseif (self::isPhoto($fullpath)) { - $a = OC_Gallery_Album::find(OCP\USER::getUser(), null, rtrim(dirname($fullpath),'/')); - if (($r = $a->fetchRow())) { - OC_Gallery_Photo::removeByPath($fullpath, $r['album_id']); - $p = OC_Gallery_Photo::findForAlbum(OCP\USER::getUser(), $r['album_name']); - if (!($p->fetchRow())) { - OC_Gallery_Album::remove(OCP\USER::getUser(), null, dirname($fullpath)); - } - } - } - } - - public static function renamePhoto($params) { - $oldpath = $params[OC_Filesystem::signal_param_oldpath]; - $newpath = $params[OC_Filesystem::signal_param_newpath]; - if (OC_Filesystem::is_dir($newpath.'/') && self::directoryContainsPhotos($newpath)) { - OC_Gallery_Album::changePath($oldpath, $newpath, OCP\USER::getUser()); - } elseif (self::isPhoto($newpath)) { - $olddir = dirname($oldpath); - $newdir = dirname($newpath); - if ($olddir == '') $olddir = '/'; - if ($newdir == '') $newdir = '/'; - if (!self::isPhoto($newpath)) return; - OCP\Util::writeLog(self::$APP_TAG, 'Moving photo from '.$oldpath.' to '.$newpath, OCP\Util::DEBUG); - $album; - $newAlbumId; - $oldAlbumId; - if ($olddir == $newdir) { - // album changing is not needed - $albums = OC_Gallery_Album::find(OCP\USER::getUser(), null, $olddir); - $album = $albums->fetchRow(); - if (!$album) { - $albums = self::createAlbum($newdir); - $album = $albums->fetchRow(); - } - $newAlbumId = $oldAlbumId = $album['album_id']; - } else { - $newalbum = OC_Gallery_Album::find(OCP\USER::getUser(), null, $newdir); - $oldalbum = OC_Gallery_Album::find(OCP\USER::getUser(), null, $olddir); - - if (!($newalbum = $newalbum->fetchRow())) { - $newalbum = self::createAlbum($newdir); - $newalbum = $newalbum->fetchRow(); - } - $oldalbum = $oldalbum->fetchRow(); - if (!$oldalbum) { - OC_Gallery_Photo::create($newalbum['album_id'], $newpath); - return; - } - $newAlbumId = $newalbum['album_id']; - $oldAlbumId = $oldalbum['album_id']; - - } - OC_Gallery_Photo::changePath($oldAlbumId, $newAlbumId, $oldpath, $newpath); - } - } + public static function renamePhoto($params) { + $oldpath = $params[OC_Filesystem::signal_param_oldpath]; + $newpath = $params[OC_Filesystem::signal_param_newpath]; + //TODO: implement this + } } ?> diff --git a/apps/gallery/lib/managers.php b/apps/gallery/lib/managers.php index 2444659d0a..4130005893 100644 --- a/apps/gallery/lib/managers.php +++ b/apps/gallery/lib/managers.php @@ -33,9 +33,9 @@ class DatabaseManager { $stmt = \OCP\DB::prepare('INSERT INTO *PREFIX*pictures_images_cache (uid_owner, path, width, height) VALUES (?, ?, ?, ?)'); $stmt->execute(array(\OCP\USER::getUser(), $path, $image->width(), $image->height())); \OCP\DB::commit(); - $ret = array('filepath' => $path, 'width' => $image->width(), 'height' => $image->height()); + $ret = array('path' => $path, 'width' => $image->width(), 'height' => $image->height()); unset($image); - return $ret; + return $ret; } private function __construct() {} @@ -82,13 +82,13 @@ class ThumbnailsManager { public function getThumbnailInfo($path) { $arr = DatabaseManager::getInstance()->getFileData($path); $ret = array('filepath' => $arr['path'], - 'width' => $arr['width'], - 'height' => $arr['height']); + 'width' => $arr['width'], + 'height' => $arr['height']); return $ret; } public function delete($path) { - unlink(\OC::$CONFIG_DATADIRECTORY_ROOT.'/'.\OC_User::getUser()."/gallery".$path); + unlink(\OCP\Config::getSystemValue('datadirectory').'/'.\OC_User::getUser()."/gallery".$path); } private function __construct() {} diff --git a/apps/gallery/lib/tiles.php b/apps/gallery/lib/tiles.php index ff9519142a..f1961cb72e 100644 --- a/apps/gallery/lib/tiles.php +++ b/apps/gallery/lib/tiles.php @@ -156,11 +156,11 @@ class TileStack extends TileBase { } public function getOnHoverAction() { - return 'javascript:t(this);return false;'; + return 'javascript:explode(this);return false;'; } public function getOnOutAction() { - return 'javascript:o(this);return false;'; + return 'javascript:deplode(this);return false;'; } public function getCount() { diff --git a/apps/gallery/templates/index.php b/apps/gallery/templates/index.php index 39e3bbf47b..e761cb5472 100644 --- a/apps/gallery/templates/index.php +++ b/apps/gallery/templates/index.php @@ -1,21 +1,22 @@ +'; + } + } + +?>
+ +
getCount() != 0) { echo $tl->get(); ?> +
diff --git a/apps/user_ldap/lib_ldap.php b/apps/user_ldap/lib_ldap.php index 22d464b65a..befdf267bc 100644 --- a/apps/user_ldap/lib_ldap.php +++ b/apps/user_ldap/lib_ldap.php @@ -576,7 +576,7 @@ class OC_LDAP { static private function combineFilter($filters, $operator) { $combinedFilter = '('.$operator; foreach($filters as $filter) { - if(substr($filter,0,1) != '(') { + if($filter[0] != '(') { $filter = '('.$filter.')'; } $combinedFilter.=$filter; @@ -692,4 +692,4 @@ class OC_LDAP { return false; } - } \ No newline at end of file + } diff --git a/lib/app.php b/lib/app.php index e8a5a1291d..0c51e3c553 100755 --- a/lib/app.php +++ b/lib/app.php @@ -469,7 +469,7 @@ class OC_App{ $apps=array(); $dh=opendir(OC::$APPSROOT.'/apps'); while($file=readdir($dh)){ - if(substr($file,0,1)!='.' and is_file(OC::$APPSROOT.'/apps/'.$file.'/appinfo/app.php')){ + if($file[0]!='.' and is_file(OC::$APPSROOT.'/apps/'.$file.'/appinfo/app.php')){ $apps[]=$file; } } diff --git a/lib/archive/tar.php b/lib/archive/tar.php index 4ff7877983..944a0ac4ba 100644 --- a/lib/archive/tar.php +++ b/lib/archive/tar.php @@ -150,7 +150,7 @@ class OC_Archive_TAR extends OC_Archive{ $folderContent=array(); $pathLength=strlen($path); foreach($files as $file){ - if(substr($file,0,1)=='/'){ + if($file[0]=='/'){ $file=substr($file,1); } if(substr($file,0,$pathLength)==$path and $file!=$path){ @@ -241,7 +241,7 @@ class OC_Archive_TAR extends OC_Archive{ } } } - if(substr($path,0,1)!='/'){//not all programs agree on the use of a leading / + if($path[0]!='/'){//not all programs agree on the use of a leading / return $this->fileExists('/'.$path); }else{ return false; diff --git a/lib/archive/zip.php b/lib/archive/zip.php index 22ab48937e..6631a649b1 100644 --- a/lib/archive/zip.php +++ b/lib/archive/zip.php @@ -191,7 +191,7 @@ class OC_Archive_ZIP extends OC_Archive{ } private function stripPath($path){ - if(substr($path,0,1)=='/'){ + if(!$path || $path[0]=='/'){ return substr($path,1); }else{ return $path; diff --git a/lib/base.php b/lib/base.php index 4bd165862b..d86a39966e 100644 --- a/lib/base.php +++ b/lib/base.php @@ -427,7 +427,7 @@ class OC{ register_shutdown_function(array('OC_Helper','cleanTmp')); //parse the given parameters - self::$REQUESTEDAPP = (isset($_GET['app'])?str_replace(array('\0', '/', '\\', '..'), '', strip_tags($_GET['app'])):OC_Config::getValue('defaultapp', 'files')); + self::$REQUESTEDAPP = (isset($_GET['app']) && trim($_GET['app']) != '' && !is_null($_GET['app'])?str_replace(array('\0', '/', '\\', '..'), '', strip_tags($_GET['app'])):OC_Config::getValue('defaultapp', 'files')); if(substr_count(self::$REQUESTEDAPP, '?') != 0){ $app = substr(self::$REQUESTEDAPP, 0, strpos(self::$REQUESTEDAPP, '?')); $param = substr(self::$REQUESTEDAPP, strpos(self::$REQUESTEDAPP, '?') + 1); diff --git a/lib/connector/sabre/file.php b/lib/connector/sabre/file.php index f2efe0a5ac..3ba1b3355f 100644 --- a/lib/connector/sabre/file.php +++ b/lib/connector/sabre/file.php @@ -63,8 +63,8 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D * @return int */ public function getSize() { - - return OC_Filesystem::filesize($this->path); + $this->stat(); + return $this->stat_cache['size']; } diff --git a/lib/connector/sabre/node.php b/lib/connector/sabre/node.php index a7d1de8b95..e7bcea3171 100644 --- a/lib/connector/sabre/node.php +++ b/lib/connector/sabre/node.php @@ -29,6 +29,11 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr * @var string */ protected $path; + /** + * file stat cache + * @var array + */ + protected $stat_cache; /** * Sets up the node, expects a full path name @@ -77,7 +82,14 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr } - + /** + * Set the stat cache + */ + protected function stat() { + if (!isset($this->stat_cache)) { + $this->stat_cache = OC_Filesystem::stat($this->path); + } + } /** * Returns the last modification time, as a unix timestamp @@ -85,8 +97,8 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr * @return int */ public function getLastModified() { - - return OC_Filesystem::filemtime($this->path); + $this->stat(); + return $this->stat_cache['mtime']; } @@ -137,7 +149,9 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr /** * Returns a list of properties for this nodes.; * - * The properties list is a list of propertynames the client requested, encoded as xmlnamespace#tagName, for example: http://www.example.org/namespace#author + * The properties list is a list of propertynames the client requested, + * encoded as xmlnamespace#tagName, for example: + * http://www.example.org/namespace#author * If the array is empty, all properties should be returned * * @param array $properties @@ -153,11 +167,11 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr $existing[$row['propertyname']] = $row['propertyvalue']; } + // if the array was empty, we need to return everything if(count($properties) == 0){ return $existing; } - // if the array was empty, we need to return everything $props = array(); foreach($properties as $property) { if (isset($existing[$property])) $props[$property] = $existing[$property]; diff --git a/lib/fileproxy.php b/lib/fileproxy.php index 70db9cca23..82c9298788 100644 --- a/lib/fileproxy.php +++ b/lib/fileproxy.php @@ -27,14 +27,17 @@ * Manipulation happens by using 2 kind of proxy operations, pre and post proxies * that manipulate the filesystem call and the result of the call respectively * - * A pre-proxy recieves the filepath as arugments (or 2 filespaths in case of operations like copy or move) and return a boolean - * If a pre-proxy returnes false the file operation will be canceled + * A pre-proxy recieves the filepath as arugments (or 2 filespaths in case of + * operations like copy or move) and return a boolean + * If a pre-proxy returns false the file operation will be canceled * All filesystem operations have a pre-proxy * * A post-proxy recieves 2 arguments, the filepath and the result of the operation. - * The return calue of the post-proxy will be used as the new result of the operation - * The operations that have a post-proxy are - * file_get_contents, is_file, is_dir, file_exists, stat, is_readable, is_writable, fileatime, filemtime, filectime, file_get_contents, getMimeType, hash, fopen, free_space and search + * The return value of the post-proxy will be used as the new result of the operation + * The operations that have a post-proxy are: + * file_get_contents, is_file, is_dir, file_exists, stat, is_readable, + * is_writable, fileatime, filemtime, filectime, file_get_contents, + * getMimeType, hash, fopen, free_space and search */ class OC_FileProxy{ @@ -42,16 +45,7 @@ class OC_FileProxy{ public static $enabled=true; /** - * check if this proxy implments a specific proxy operation - * @param string #proxy name of the proxy operation - * @return bool - */ - public function provides($operation){ - return method_exists($this,$operation); - } - - /** - * fallback function when a proxy operation is not implement + * fallback function when a proxy operation is not implemented * @param string $function the name of the proxy operation * @param mixed * @@ -73,11 +67,10 @@ class OC_FileProxy{ self::$proxies[]=$proxy; } - public static function getProxies($operation,$post){ - $operation=(($post)?'post':'pre').$operation; + public static function getProxies($operation){ $proxies=array(); foreach(self::$proxies as $proxy){ - if($proxy->provides($operation)){ + if(method_exists($proxy,$operation)){ $proxies[]=$proxy; } } @@ -88,8 +81,8 @@ class OC_FileProxy{ if(!self::$enabled){ return true; } - $proxies=self::getProxies($operation,false); $operation='pre'.$operation; + $proxies=self::getProxies($operation); foreach($proxies as $proxy){ if(!is_null($filepath2)){ if($proxy->$operation($filepath,$filepath2)===false){ @@ -108,8 +101,8 @@ class OC_FileProxy{ if(!self::$enabled){ return $result; } - $proxies=self::getProxies($operation,true); $operation='post'.$operation; + $proxies=self::getProxies($operation); foreach($proxies as $proxy){ $result=$proxy->$operation($path,$result); } diff --git a/lib/filesystem.php b/lib/filesystem.php index 84d45f5f24..337b0f1464 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -150,7 +150,7 @@ class OC_Filesystem{ if(!$path){ $path='/'; } - if(substr($path,0,1)!=='/'){ + if($path[0]!=='/'){ $path='/'.$path; } $foundMountPoint=''; @@ -281,7 +281,7 @@ class OC_Filesystem{ } /** - * change the root to a fake toor + * change the root to a fake root * @param string fakeRoot * @return bool */ @@ -313,12 +313,12 @@ class OC_Filesystem{ * @param string mountpoint */ static public function mount($class,$arguments,$mountpoint){ + if($mountpoint[0]!='/'){ + $mountpoint='/'.$mountpoint; + } if(substr($mountpoint,-1)!=='/'){ $mountpoint=$mountpoint.'/'; } - if(substr($mountpoint,0,1)!=='/'){ - $mountpoint='/'.$mountpoint; - } self::$mounts[$mountpoint]=array('class'=>$class,'arguments'=>$arguments); } @@ -349,7 +349,7 @@ class OC_Filesystem{ * @return bool */ static public function isValidPath($path){ - if(substr($path,0,1)!=='/'){ + if(!$path || $path[0]!=='/'){ $path='/'.$path; } if(strstr($path,'/../') || strrchr($path, '/') === '/..' ){ diff --git a/lib/filesystemview.php b/lib/filesystemview.php index c8df59cf82..6e34257a46 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -40,6 +40,8 @@ class OC_FilesystemView { private $fakeRoot=''; + private $internal_path_cache=array(); + private $storage_cache=array(); public function __construct($root){ $this->fakeRoot=$root; @@ -49,7 +51,7 @@ class OC_FilesystemView { if(!$path){ $path='/'; } - if(substr($path,0,1)!=='/'){ + if($path[0]!=='/'){ $path='/'.$path; } return $this->fakeRoot.$path; @@ -84,7 +86,10 @@ class OC_FilesystemView { * @return bool */ public function getInternalPath($path){ - return OC_Filesystem::getInternalPath($this->getAbsolutePath($path)); + if (!isset($this->internal_path_cache[$path])) { + $this->internal_path_cache[$path] = OC_Filesystem::getInternalPath($this->getAbsolutePath($path)); + } + return $this->internal_path_cache[$path]; } /** * get the storage object for a path @@ -92,7 +97,10 @@ class OC_FilesystemView { * @return OC_Filestorage */ public function getStorage($path){ - return OC_Filesystem::getStorage($this->getAbsolutePath($path)); + if (!isset($this->storage_cache[$path])) { + $this->storage_cache[$path] = OC_Filesystem::getStorage($this->getAbsolutePath($path)); + } + return $this->storage_cache[$path]; } /** diff --git a/lib/installer.php b/lib/installer.php index 5c030d2917..34c6f8c7bb 100644 --- a/lib/installer.php +++ b/lib/installer.php @@ -110,7 +110,7 @@ class OC_Installer{ //try to find it in a subdir $dh=opendir($extractDir); while($folder=readdir($dh)){ - if(substr($folder,0,1)!='.' and is_dir($extractDir.'/'.$folder)){ + if($folder[0]!='.' and is_dir($extractDir.'/'.$folder)){ if(is_file($extractDir.'/'.$folder.'/appinfo/info.xml')){ $extractDir.='/'.$folder; } diff --git a/lib/user/database.php b/lib/user/database.php index bb077c8364..a48b8357d6 100644 --- a/lib/user/database.php +++ b/lib/user/database.php @@ -129,7 +129,7 @@ class OC_User_Database extends OC_User_Backend { $row=$result->fetchRow(); if($row){ $storedHash=$row['password']; - if (substr($storedHash,0,1)=='$'){//the new phpass based hashing + if ($storedHash[0]=='$'){//the new phpass based hashing $hasher=$this->getHasher(); if($hasher->CheckPassword($password.OC_Config::getValue('passwordsalt', ''), $storedHash)){ return $row['uid']; diff --git a/tests/index.php b/tests/index.php index 9c5178f81a..691bf2a5d4 100644 --- a/tests/index.php +++ b/tests/index.php @@ -47,7 +47,7 @@ function loadTests($dir=''){ } if($dh=opendir($dir)){ while($name=readdir($dh)){ - if(substr($name,0,1)!='.'){//no hidden files, '.' or '..' + if($name[0]!='.'){//no hidden files, '.' or '..' $file=$dir.'/'.$name; if(is_dir($file)){ loadTests($file);