]> source.dussan.org Git - nextcloud-server.git/commitdiff
Checkstyle: Fix the last two InvalidEOLChar
authorFelix Moeller <mail@felixmoeller.de>
Sun, 4 Nov 2012 17:42:18 +0000 (18:42 +0100)
committerFelix Moeller <mail@felixmoeller.de>
Sun, 4 Nov 2012 17:42:18 +0000 (18:42 +0100)
apps/files_sharing/public.php
apps/files_versions/lib/versions.php

index 105e94f1140631044bd8b7940796262fe21e63e5..dca87cd68762a536367cadd7f2b8295ad21f4ed5 100644 (file)
-<?php\r
-// Load other apps for file previews\r
-OC_App::loadApps();\r
-\r
-// Compatibility with shared-by-link items from ownCloud 4.0\r
-// requires old Sharing table !\r
-// support will be removed in OC 5.0,a\r
-if (isset($_GET['token'])) {\r
-       unset($_GET['file']);\r
-       $qry = \OC_DB::prepare('SELECT `source` FROM `*PREFIX*sharing` WHERE `target` = ? LIMIT 1');\r
-       $filepath = $qry->execute(array($_GET['token']))->fetchOne();\r
-       if(isset($filepath)) {\r
-               $info = OC_FileCache_Cached::get($filepath, '');\r
-               if(strtolower($info['mimetype']) == 'httpd/unix-directory') {\r
-                       $_GET['dir'] = $filepath;\r
-               } else {\r
-                       $_GET['file'] = $filepath;\r
-               }\r
-               \OCP\Util::writeLog('files_sharing', 'You have files that are shared by link originating from ownCloud 4.0. Redistribute the new links, because backwards compatibility will be removed in ownCloud 5.', \OCP\Util::WARN);\r
-       }\r
-}\r
-// Enf of backward compatibility\r
-\r
-function getID($path) {\r
-       // use the share table from the db to find the item source if the file was reshared because shared files \r
-       //are not stored in the file cache.\r
-       if (substr(OC_Filesystem::getMountPoint($path), -7, 6) == "Shared") {\r
-               $path_parts = explode('/', $path, 5);\r
-               $user = $path_parts[1];\r
-               $intPath = '/'.$path_parts[4];\r
-               $query = \OC_DB::prepare('SELECT item_source FROM *PREFIX*share WHERE uid_owner = ? AND file_target = ? ');\r
-               $result = $query->execute(array($user, $intPath));\r
-               $row = $result->fetchRow();\r
-               $fileSource = $row['item_source'];\r
-       } else {\r
-               $fileSource = OC_Filecache::getId($path, '');\r
-       }\r
-\r
-       return $fileSource;\r
-}\r
-\r
-if (isset($_GET['file']) || isset($_GET['dir'])) {\r
-       if (isset($_GET['dir'])) {\r
-               $type = 'folder';\r
-               $path = $_GET['dir'];\r
-               if(strlen($path)>1 and substr($path, -1, 1)==='/') {\r
-                       $path=substr($path, 0, -1);\r
-               }\r
-               $baseDir = $path;\r
-               $dir = $baseDir;\r
-       } else {\r
-               $type = 'file';\r
-               $path = $_GET['file'];\r
-               if(strlen($path)>1 and substr($path, -1, 1)==='/') {\r
-                       $path=substr($path, 0, -1);\r
-               }\r
-       }\r
-       $uidOwner = substr($path, 1, strpos($path, '/', 1) - 1);\r
-       if (OCP\User::userExists($uidOwner)) {\r
-               OC_Util::setupFS($uidOwner);\r
-               $fileSource = getId($path);\r
-               if ($fileSource != -1 && ($linkItem = OCP\Share::getItemSharedWithByLink($type, $fileSource, $uidOwner))) {\r
-                       // TODO Fix in the getItems\r
-                       if (!isset($linkItem['item_type']) || $linkItem['item_type'] != $type) {\r
-                               header('HTTP/1.0 404 Not Found');\r
-                               $tmpl = new OCP\Template('', '404', 'guest');\r
-                               $tmpl->printPage();\r
-                               exit();\r
-                       }\r
-                       if (isset($linkItem['share_with'])) {\r
-                               // Check password\r
-                               if (isset($_GET['file'])) {\r
-                                       $url = OCP\Util::linkToPublic('files').'&file='.$_GET['file'];\r
-                               } else {\r
-                                       $url = OCP\Util::linkToPublic('files').'&dir='.$_GET['dir'];\r
-                               }\r
-                               if (isset($_POST['password'])) {\r
-                                       $password = $_POST['password'];\r
-                                       $storedHash = $linkItem['share_with'];\r
-                                       $forcePortable = (CRYPT_BLOWFISH != 1);\r
-                                       $hasher = new PasswordHash(8, $forcePortable);\r
-                                       if (!($hasher->CheckPassword($password.OC_Config::getValue('passwordsalt', ''), $storedHash))) {\r
-                                               $tmpl = new OCP\Template('files_sharing', 'authenticate', 'guest');\r
-                                               $tmpl->assign('URL', $url);\r
-                                               $tmpl->assign('error', true);\r
-                                               $tmpl->printPage();\r
-                                               exit();\r
-                                       } else {\r
-                                               // Save item id in session for future requests\r
-                                               $_SESSION['public_link_authenticated'] = $linkItem['id'];\r
-                                       }\r
-                               // Check if item id is set in session\r
-                               } else if (!isset($_SESSION['public_link_authenticated']) || $_SESSION['public_link_authenticated'] !== $linkItem['id']) {\r
-                                       // Prompt for password\r
-                                       $tmpl = new OCP\Template('files_sharing', 'authenticate', 'guest');\r
-                                       $tmpl->assign('URL', $url);\r
-                                       $tmpl->printPage();\r
-                                       exit();\r
-                               }\r
-                       }\r
-                       $path = $linkItem['path'];\r
-                       if (isset($_GET['path'])) {\r
-                               $path .= $_GET['path'];\r
-                               $dir .= $_GET['path'];\r
-                               if (!OC_Filesystem::file_exists($path)) {\r
-                                       header('HTTP/1.0 404 Not Found');\r
-                                       $tmpl = new OCP\Template('', '404', 'guest');\r
-                                       $tmpl->printPage();\r
-                                       exit();\r
-                               }\r
-                       }\r
-                       // Download the file\r
-                       if (isset($_GET['download'])) {\r
-                               if (isset($_GET['dir'])) {\r
-                                       if ( isset($_GET['files']) ) { // download selected files\r
-                                               OC_Files::get($path, $_GET['files'], $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false);\r
-                                       } else  if (isset($_GET['path']) &&  $_GET['path'] != '' ) { // download a file from a shared directory\r
-                                               OC_Files::get('', $path, $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false);\r
-                                       } else { // download the whole shared directory\r
-                                               OC_Files::get($path, '', $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false);\r
-                                       }\r
-                               } else { // download a single shared file\r
-                                       OC_Files::get("", $path, $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false);\r
-                               }\r
-\r
-                       } else {\r
-                               OCP\Util::addStyle('files_sharing', 'public');\r
-                               OCP\Util::addScript('files_sharing', 'public');\r
-                               OCP\Util::addScript('files', 'fileactions');\r
-                               $tmpl = new OCP\Template('files_sharing', 'public', 'base');\r
-                               $tmpl->assign('owner', $uidOwner);\r
-                               // Show file list\r
-                               if (OC_Filesystem::is_dir($path)) {\r
-                                       OCP\Util::addStyle('files', 'files');\r
-                                       OCP\Util::addScript('files', 'files');\r
-                                       OCP\Util::addScript('files', 'filelist');\r
-                                       $files = array();\r
-                                       $rootLength = strlen($baseDir) + 1;\r
-                                       foreach (OC_Files::getDirectoryContent($path) as $i) {\r
-                                               $i['date'] = OCP\Util::formatDate($i['mtime']);\r
-                                               if ($i['type'] == 'file') {\r
-                                                       $fileinfo = pathinfo($i['name']);\r
-                                                       $i['basename'] = $fileinfo['filename'];\r
-                                                       $i['extension'] = isset($fileinfo['extension']) ? ('.'.$fileinfo['extension']) : '';\r
-                                               }\r
-                                               $i['directory'] = '/'.substr('/'.$uidOwner.'/files'.$i['directory'], $rootLength);\r
-                                               if ($i['directory'] == '/') {\r
-                                                       $i['directory'] = '';\r
-                                               }\r
-                                               $i['permissions'] = OCP\Share::PERMISSION_READ;\r
-                                               $files[] = $i;\r
-                                       }\r
-                                       // Make breadcrumb\r
-                                       $breadcrumb = array();\r
-                                       $pathtohere = '';\r
-                                       $count = 1;\r
-                                       foreach (explode('/', $dir) as $i) {\r
-                                               if ($i != '') {\r
-                                                       if ($i != $baseDir) {\r
-                                                               $pathtohere .= '/'.$i;\r
-                                                       }\r
-                                                       if ( strlen($pathtohere) <  strlen($_GET['dir'])) {\r
-                                                               continue;\r
-                                                       }\r
-                                                       $breadcrumb[] = array('dir' => str_replace($_GET['dir'], "", $pathtohere, $count), 'name' => $i);\r
-                                               }\r
-                                       }\r
-                                       $list = new OCP\Template('files', 'part.list', '');\r
-                                       $list->assign('files', $files, false);\r
-                                       $list->assign('publicListView', true);\r
-                                       $list->assign('baseURL', OCP\Util::linkToPublic('files').'&dir='.urlencode($_GET['dir']).'&path=', false);\r
-                                       $list->assign('downloadURL', OCP\Util::linkToPublic('files').'&download&dir='.urlencode($_GET['dir']).'&path=', false);\r
-                                       $breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', '' );\r
-                                       $breadcrumbNav->assign('breadcrumb', $breadcrumb, false);\r
-                                       $breadcrumbNav->assign('baseURL', OCP\Util::linkToPublic('files').'&dir='.urlencode($_GET['dir']).'&path=', false);\r
-                                       $folder = new OCP\Template('files', 'index', '');\r
-                                       $folder->assign('fileList', $list->fetchPage(), false);\r
-                                       $folder->assign('breadcrumb', $breadcrumbNav->fetchPage(), false);\r
-                                       $folder->assign('dir', basename($dir));\r
-                                       $folder->assign('isCreatable', false);\r
-                                       $folder->assign('permissions', 0);\r
-                                       $folder->assign('files', $files);\r
-                                       $folder->assign('uploadMaxFilesize', 0);\r
-                                       $folder->assign('uploadMaxHumanFilesize', 0);\r
-                                       $folder->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));\r
-                                       $tmpl->assign('folder', $folder->fetchPage(), false);\r
-                                       $tmpl->assign('uidOwner', $uidOwner);\r
-                                       $tmpl->assign('dir', basename($dir));\r
-                                       $tmpl->assign('filename', basename($path));\r
-                                       $tmpl->assign('mimetype', OC_Filesystem::getMimeType($path));\r
-                                       $tmpl->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));\r
-                                       if (isset($_GET['path'])) {\r
-                                               $getPath = $_GET['path'];\r
-                                       } else {\r
-                                               $getPath = '';\r
-                                       }\r
-                                       $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files').'&download&dir='.urlencode($_GET['dir']).'&path='.urlencode($getPath), false);\r
-                               } else {\r
-                                       // Show file preview if viewer is available\r
-                                       $tmpl->assign('uidOwner', $uidOwner);\r
-                                       $tmpl->assign('dir', dirname($path));\r
-                                       $tmpl->assign('filename', basename($path));\r
-                                       $tmpl->assign('mimetype', OC_Filesystem::getMimeType($path));\r
-                                       if ($type == 'file') {\r
-                                               $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files').'&file='.urlencode($_GET['file']).'&download', false);\r
-                                       } else {\r
-                                               if (isset($_GET['path'])) {\r
-                                                       $getPath = $_GET['path'];\r
-                                               } else {\r
-                                                       $getPath = '';\r
-                                               }\r
-                                               $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files').'&download&dir='.urlencode($_GET['dir']).'&path='.urlencode($getPath), false);\r
-                                       }\r
-                               }\r
-                               $tmpl->printPage();\r
-                       }\r
-                       exit();\r
-               }\r
-       }\r
-}\r
-header('HTTP/1.0 404 Not Found');\r
-$tmpl = new OCP\Template('', '404', 'guest');\r
-$tmpl->printPage();\r
+<?php
+// Load other apps for file previews
+OC_App::loadApps();
+
+// Compatibility with shared-by-link items from ownCloud 4.0
+// requires old Sharing table !
+// support will be removed in OC 5.0,a
+if (isset($_GET['token'])) {
+       unset($_GET['file']);
+       $qry = \OC_DB::prepare('SELECT `source` FROM `*PREFIX*sharing` WHERE `target` = ? LIMIT 1');
+       $filepath = $qry->execute(array($_GET['token']))->fetchOne();
+       if(isset($filepath)) {
+               $info = OC_FileCache_Cached::get($filepath, '');
+               if(strtolower($info['mimetype']) == 'httpd/unix-directory') {
+                       $_GET['dir'] = $filepath;
+               } else {
+                       $_GET['file'] = $filepath;
+               }
+               \OCP\Util::writeLog('files_sharing', 'You have files that are shared by link originating from ownCloud 4.0. Redistribute the new links, because backwards compatibility will be removed in ownCloud 5.', \OCP\Util::WARN);
+       }
+}
+// Enf of backward compatibility
+
+function getID($path) {
+       // use the share table from the db to find the item source if the file was reshared because shared files 
+       //are not stored in the file cache.
+       if (substr(OC_Filesystem::getMountPoint($path), -7, 6) == "Shared") {
+               $path_parts = explode('/', $path, 5);
+               $user = $path_parts[1];
+               $intPath = '/'.$path_parts[4];
+               $query = \OC_DB::prepare('SELECT item_source FROM *PREFIX*share WHERE uid_owner = ? AND file_target = ? ');
+               $result = $query->execute(array($user, $intPath));
+               $row = $result->fetchRow();
+               $fileSource = $row['item_source'];
+       } else {
+               $fileSource = OC_Filecache::getId($path, '');
+       }
+
+       return $fileSource;
+}
+
+if (isset($_GET['file']) || isset($_GET['dir'])) {
+       if (isset($_GET['dir'])) {
+               $type = 'folder';
+               $path = $_GET['dir'];
+               if(strlen($path)>1 and substr($path, -1, 1)==='/') {
+                       $path=substr($path, 0, -1);
+               }
+               $baseDir = $path;
+               $dir = $baseDir;
+       } else {
+               $type = 'file';
+               $path = $_GET['file'];
+               if(strlen($path)>1 and substr($path, -1, 1)==='/') {
+                       $path=substr($path, 0, -1);
+               }
+       }
+       $uidOwner = substr($path, 1, strpos($path, '/', 1) - 1);
+       if (OCP\User::userExists($uidOwner)) {
+               OC_Util::setupFS($uidOwner);
+               $fileSource = getId($path);
+               if ($fileSource != -1 && ($linkItem = OCP\Share::getItemSharedWithByLink($type, $fileSource, $uidOwner))) {
+                       // TODO Fix in the getItems
+                       if (!isset($linkItem['item_type']) || $linkItem['item_type'] != $type) {
+                               header('HTTP/1.0 404 Not Found');
+                               $tmpl = new OCP\Template('', '404', 'guest');
+                               $tmpl->printPage();
+                               exit();
+                       }
+                       if (isset($linkItem['share_with'])) {
+                               // Check password
+                               if (isset($_GET['file'])) {
+                                       $url = OCP\Util::linkToPublic('files').'&file='.$_GET['file'];
+                               } else {
+                                       $url = OCP\Util::linkToPublic('files').'&dir='.$_GET['dir'];
+                               }
+                               if (isset($_POST['password'])) {
+                                       $password = $_POST['password'];
+                                       $storedHash = $linkItem['share_with'];
+                                       $forcePortable = (CRYPT_BLOWFISH != 1);
+                                       $hasher = new PasswordHash(8, $forcePortable);
+                                       if (!($hasher->CheckPassword($password.OC_Config::getValue('passwordsalt', ''), $storedHash))) {
+                                               $tmpl = new OCP\Template('files_sharing', 'authenticate', 'guest');
+                                               $tmpl->assign('URL', $url);
+                                               $tmpl->assign('error', true);
+                                               $tmpl->printPage();
+                                               exit();
+                                       } else {
+                                               // Save item id in session for future requests
+                                               $_SESSION['public_link_authenticated'] = $linkItem['id'];
+                                       }
+                               // Check if item id is set in session
+                               } else if (!isset($_SESSION['public_link_authenticated']) || $_SESSION['public_link_authenticated'] !== $linkItem['id']) {
+                                       // Prompt for password
+                                       $tmpl = new OCP\Template('files_sharing', 'authenticate', 'guest');
+                                       $tmpl->assign('URL', $url);
+                                       $tmpl->printPage();
+                                       exit();
+                               }
+                       }
+                       $path = $linkItem['path'];
+                       if (isset($_GET['path'])) {
+                               $path .= $_GET['path'];
+                               $dir .= $_GET['path'];
+                               if (!OC_Filesystem::file_exists($path)) {
+                                       header('HTTP/1.0 404 Not Found');
+                                       $tmpl = new OCP\Template('', '404', 'guest');
+                                       $tmpl->printPage();
+                                       exit();
+                               }
+                       }
+                       // Download the file
+                       if (isset($_GET['download'])) {
+                               if (isset($_GET['dir'])) {
+                                       if ( isset($_GET['files']) ) { // download selected files
+                                               OC_Files::get($path, $_GET['files'], $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false);
+                                       } else  if (isset($_GET['path']) &&  $_GET['path'] != '' ) { // download a file from a shared directory
+                                               OC_Files::get('', $path, $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false);
+                                       } else { // download the whole shared directory
+                                               OC_Files::get($path, '', $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false);
+                                       }
+                               } else { // download a single shared file
+                                       OC_Files::get("", $path, $_SERVER['REQUEST_METHOD'] == 'HEAD' ? true : false);
+                               }
+
+                       } else {
+                               OCP\Util::addStyle('files_sharing', 'public');
+                               OCP\Util::addScript('files_sharing', 'public');
+                               OCP\Util::addScript('files', 'fileactions');
+                               $tmpl = new OCP\Template('files_sharing', 'public', 'base');
+                               $tmpl->assign('owner', $uidOwner);
+                               // Show file list
+                               if (OC_Filesystem::is_dir($path)) {
+                                       OCP\Util::addStyle('files', 'files');
+                                       OCP\Util::addScript('files', 'files');
+                                       OCP\Util::addScript('files', 'filelist');
+                                       $files = array();
+                                       $rootLength = strlen($baseDir) + 1;
+                                       foreach (OC_Files::getDirectoryContent($path) as $i) {
+                                               $i['date'] = OCP\Util::formatDate($i['mtime']);
+                                               if ($i['type'] == 'file') {
+                                                       $fileinfo = pathinfo($i['name']);
+                                                       $i['basename'] = $fileinfo['filename'];
+                                                       $i['extension'] = isset($fileinfo['extension']) ? ('.'.$fileinfo['extension']) : '';
+                                               }
+                                               $i['directory'] = '/'.substr('/'.$uidOwner.'/files'.$i['directory'], $rootLength);
+                                               if ($i['directory'] == '/') {
+                                                       $i['directory'] = '';
+                                               }
+                                               $i['permissions'] = OCP\Share::PERMISSION_READ;
+                                               $files[] = $i;
+                                       }
+                                       // Make breadcrumb
+                                       $breadcrumb = array();
+                                       $pathtohere = '';
+                                       $count = 1;
+                                       foreach (explode('/', $dir) as $i) {
+                                               if ($i != '') {
+                                                       if ($i != $baseDir) {
+                                                               $pathtohere .= '/'.$i;
+                                                       }
+                                                       if ( strlen($pathtohere) <  strlen($_GET['dir'])) {
+                                                               continue;
+                                                       }
+                                                       $breadcrumb[] = array('dir' => str_replace($_GET['dir'], "", $pathtohere, $count), 'name' => $i);
+                                               }
+                                       }
+                                       $list = new OCP\Template('files', 'part.list', '');
+                                       $list->assign('files', $files, false);
+                                       $list->assign('publicListView', true);
+                                       $list->assign('baseURL', OCP\Util::linkToPublic('files').'&dir='.urlencode($_GET['dir']).'&path=', false);
+                                       $list->assign('downloadURL', OCP\Util::linkToPublic('files').'&download&dir='.urlencode($_GET['dir']).'&path=', false);
+                                       $breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', '' );
+                                       $breadcrumbNav->assign('breadcrumb', $breadcrumb, false);
+                                       $breadcrumbNav->assign('baseURL', OCP\Util::linkToPublic('files').'&dir='.urlencode($_GET['dir']).'&path=', false);
+                                       $folder = new OCP\Template('files', 'index', '');
+                                       $folder->assign('fileList', $list->fetchPage(), false);
+                                       $folder->assign('breadcrumb', $breadcrumbNav->fetchPage(), false);
+                                       $folder->assign('dir', basename($dir));
+                                       $folder->assign('isCreatable', false);
+                                       $folder->assign('permissions', 0);
+                                       $folder->assign('files', $files);
+                                       $folder->assign('uploadMaxFilesize', 0);
+                                       $folder->assign('uploadMaxHumanFilesize', 0);
+                                       $folder->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));
+                                       $tmpl->assign('folder', $folder->fetchPage(), false);
+                                       $tmpl->assign('uidOwner', $uidOwner);
+                                       $tmpl->assign('dir', basename($dir));
+                                       $tmpl->assign('filename', basename($path));
+                                       $tmpl->assign('mimetype', OC_Filesystem::getMimeType($path));
+                                       $tmpl->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));
+                                       if (isset($_GET['path'])) {
+                                               $getPath = $_GET['path'];
+                                       } else {
+                                               $getPath = '';
+                                       }
+                                       $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files').'&download&dir='.urlencode($_GET['dir']).'&path='.urlencode($getPath), false);
+                               } else {
+                                       // Show file preview if viewer is available
+                                       $tmpl->assign('uidOwner', $uidOwner);
+                                       $tmpl->assign('dir', dirname($path));
+                                       $tmpl->assign('filename', basename($path));
+                                       $tmpl->assign('mimetype', OC_Filesystem::getMimeType($path));
+                                       if ($type == 'file') {
+                                               $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files').'&file='.urlencode($_GET['file']).'&download', false);
+                                       } else {
+                                               if (isset($_GET['path'])) {
+                                                       $getPath = $_GET['path'];
+                                               } else {
+                                                       $getPath = '';
+                                               }
+                                               $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files').'&download&dir='.urlencode($_GET['dir']).'&path='.urlencode($getPath), false);
+                                       }
+                               }
+                               $tmpl->printPage();
+                       }
+                       exit();
+               }
+       }
+}
+header('HTTP/1.0 404 Not Found');
+$tmpl = new OCP\Template('', '404', 'guest');
+$tmpl->printPage();
index 8f807187467e0d3b26312ad3ad9a122a5e067124..dc83ab12af0f3081dacbd0e2c3459e24e826dc54 100644 (file)
-<?php\r
-/**\r
- * Copyright (c) 2012 Frank Karlitschek <frank@owncloud.org>\r
- * This file is licensed under the Affero General Public License version 3 or\r
- * later.\r
- * See the COPYING-README file.\r
- */\r
-\r
-/**\r
- * Versions\r
- *\r
- * A class to handle the versioning of files.\r
- */\r
-\r
-namespace OCA_Versions;\r
-\r
-class Storage {\r
-\r
-\r
-       // config.php configuration:\r
-       //   - files_versions\r
-       //   - files_versionsfolder\r
-       //   - files_versionsblacklist\r
-       //   - files_versionsmaxfilesize\r
-       //   - files_versionsinterval\r
-       //   - files_versionmaxversions\r
-       //\r
-       // todo:\r
-       //   - finish porting to OC_FilesystemView to enable network transparency\r
-       //   - add transparent compression. first test if it´s worth it.\r
-\r
-       const DEFAULTENABLED=true;\r
-       const DEFAULTBLACKLIST='avi mp3 mpg mp4 ctmp';\r
-       const DEFAULTMAXFILESIZE=1048576; // 10MB\r
-       const DEFAULTMININTERVAL=60; // 1 min\r
-       const DEFAULTMAXVERSIONS=50;\r
-\r
-       private static function getUidAndFilename($filename)\r
-       {\r
-               if (\OCP\App::isEnabled('files_sharing')\r
-                   && substr($filename, 0, 7) == '/Shared'\r
-                   && $source = \OCP\Share::getItemSharedWith('file',\r
-                                       substr($filename, 7),\r
-                                       \OC_Share_Backend_File::FORMAT_SHARED_STORAGE)) {\r
-                       $filename = $source['path'];\r
-                       $pos = strpos($filename, '/files', 1);\r
-                       $uid = substr($filename, 1, $pos - 1);\r
-                       $filename = substr($filename, $pos + 6);\r
-               } else {\r
-                       $uid = \OCP\User::getUser();\r
-               }\r
-               return array($uid, $filename);\r
-       }\r
-\r
-       /**\r
-        * store a new version of a file.\r
-        */\r
-       public function store($filename) {\r
-               if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {\r
-                       list($uid, $filename) = self::getUidAndFilename($filename);\r
-                       $files_view = new \OC_FilesystemView('/'.\OCP\User::getUser() .'/files');\r
-                       $users_view = new \OC_FilesystemView('/'.\OCP\User::getUser());\r
-\r
-                       //check if source file already exist as version to avoid recursions.\r
-                       // todo does this check work?\r
-                       if ($users_view->file_exists($filename)) {\r
-                               return false;\r
-                       }\r
-\r
-                       // check if filename is a directory\r
-                       if($files_view->is_dir($filename)) {\r
-                               return false;\r
-                       }\r
-\r
-                       // check filetype blacklist\r
-                       $blacklist=explode(' ', \OCP\Config::getSystemValue('files_versionsblacklist', Storage::DEFAULTBLACKLIST));\r
-                       foreach($blacklist as $bl) {\r
-                               $parts=explode('.', $filename);\r
-                               $ext=end($parts);\r
-                               if(strtolower($ext)==$bl) {\r
-                                       return false;\r
-                               }\r
-                       }\r
-                       // we should have a source file to work with\r
-                       if (!$files_view->file_exists($filename)) {\r
-                               return false;\r
-                       }\r
-\r
-                       // check filesize\r
-                       if($files_view->filesize($filename)>\OCP\Config::getSystemValue('files_versionsmaxfilesize', Storage::DEFAULTMAXFILESIZE)) {\r
-                               return false;\r
-                       }\r
-\r
-\r
-                       // check mininterval if the file is being modified by the owner (all shared files should be versioned despite mininterval)\r
-                       if ($uid == \OCP\User::getUser()) {\r
-                               $versions_fileview = new \OC_FilesystemView('/'.\OCP\User::getUser().'/files_versions');\r
-                               $versionsName=\OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath($filename);\r
-                               $versionsFolderName=\OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath('');\r
-                               $matches=glob($versionsName.'.v*');\r
-                               sort($matches);\r
-                               $parts=explode('.v', end($matches));\r
-                               if((end($parts)+Storage::DEFAULTMININTERVAL)>time()) {\r
-                                       return false;\r
-                               }\r
-                       }\r
-\r
-\r
-                       // create all parent folders\r
-                       $info=pathinfo($filename);\r
-                       if(!file_exists($versionsFolderName.'/'.$info['dirname'])) {\r
-                               mkdir($versionsFolderName.'/'.$info['dirname'], 0750, true);\r
-                       }\r
-\r
-                       // store a new version of a file\r
-                       $users_view->copy('files'.$filename, 'files_versions'.$filename.'.v'.time());\r
-\r
-                       // expire old revisions if necessary\r
-                       Storage::expire($filename);\r
-               }\r
-       }\r
-\r
-\r
-       /**\r
-        * rollback to an old version of a file.\r
-        */\r
-       public static function rollback($filename, $revision) {\r
-\r
-               if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {\r
-                       list($uid, $filename) = self::getUidAndFilename($filename);\r
-                       $users_view = new \OC_FilesystemView('/'.\OCP\User::getUser());\r
-\r
-                       // rollback\r
-                       if( @$users_view->copy('files_versions'.$filename.'.v'.$revision, 'files'.$filename) ) {\r
-\r
-                               return true;\r
-\r
-                       }else{\r
-\r
-                               return false;\r
-\r
-                       }\r
-\r
-               }\r
-\r
-       }\r
-\r
-       /**\r
-        * check if old versions of a file exist.\r
-        */\r
-       public static function isversioned($filename) {\r
-               if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {\r
-                       list($uid, $filename) = self::getUidAndFilename($filename);\r
-                       $versions_fileview = new \OC_FilesystemView('/'.\OCP\User::getUser().'/files_versions');\r
-\r
-                       $versionsName=\OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath($filename);\r
-\r
-                       // check for old versions\r
-                       $matches=glob($versionsName.'.v*');\r
-                       if(count($matches)>0) {\r
-                               return true;\r
-                       }else{\r
-                               return false;\r
-                       }\r
-               }else{\r
-                       return(false);\r
-               }\r
-       }\r
-\r
-\r
-\r
-       /**\r
-        * @brief get a list of all available versions of a file in descending chronological order\r
-        * @param $filename file to find versions of, relative to the user files dir\r
-        * @param $count number of versions to return\r
-        * @returns array\r
-        */\r
-       public static function getVersions( $filename, $count = 0 ) {\r
-               if( \OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' ) {\r
-                       list($uid, $filename) = self::getUidAndFilename($filename);\r
-                       $versions_fileview = new \OC_FilesystemView('/'.\OCP\User::getUser().'/files_versions');\r
-\r
-                       $versionsName = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath($filename);\r
-                       $versions = array();\r
-                       // fetch for old versions\r
-                       $matches = glob( $versionsName.'.v*' );\r
-\r
-                       sort( $matches );\r
-\r
-                       $i = 0;\r
-\r
-                       $files_view = new \OC_FilesystemView('/'.\OCP\User::getUser().'/files');\r
-                       $local_file = $files_view->getLocalFile($filename);\r
-                       foreach( $matches as $ma ) {\r
-\r
-                               $i++;\r
-                               $versions[$i]['cur'] = 0;\r
-                               $parts = explode( '.v', $ma );\r
-                               $versions[$i]['version'] = ( end( $parts ) );\r
-\r
-                               // if file with modified date exists, flag it in array as currently enabled version\r
-                               ( \md5_file( $ma ) == \md5_file( $local_file ) ? $versions[$i]['fileMatch'] = 1 : $versions[$i]['fileMatch'] = 0 );\r
-\r
-                       }\r
-\r
-                       $versions = array_reverse( $versions );\r
-\r
-                       foreach( $versions as $key => $value ) {\r
-\r
-                               // flag the first matched file in array (which will have latest modification date) as current version\r
-                               if ( $value['fileMatch'] ) {\r
-\r
-                                       $value['cur'] = 1;\r
-                                       break;\r
-\r
-                               }\r
-\r
-                       }\r
-\r
-                       $versions = array_reverse( $versions );\r
-\r
-                       // only show the newest commits\r
-                       if( $count != 0 and ( count( $versions )>$count ) ) {\r
-\r
-                               $versions = array_slice( $versions, count( $versions ) - $count );\r
-\r
-                       }\r
-\r
-                       return( $versions );\r
-\r
-\r
-               } else {\r
-\r
-                       // if versioning isn't enabled then return an empty array\r
-                       return( array() );\r
-\r
-               }\r
-\r
-       }\r
-\r
-       /**\r
-        * @brief Erase a file's versions which exceed the set quota\r
-        */\r
-       public static function expire($filename) {\r
-               if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {\r
-                       list($uid, $filename) = self::getUidAndFilename($filename);\r
-                       $versions_fileview = new \OC_FilesystemView('/'.$uid.'/files_versions');\r
-\r
-                       $versionsName=\OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath($filename);\r
-\r
-                       // check for old versions\r
-                       $matches = glob( $versionsName.'.v*' );\r
-\r
-                       if( count( $matches ) > \OCP\Config::getSystemValue( 'files_versionmaxversions', Storage::DEFAULTMAXVERSIONS ) ) {\r
-\r
-                               $numberToDelete = count($matches) - \OCP\Config::getSystemValue( 'files_versionmaxversions', Storage::DEFAULTMAXVERSIONS );\r
-\r
-                               // delete old versions of a file\r
-                               $deleteItems = array_slice( $matches, 0, $numberToDelete );\r
-\r
-                               foreach( $deleteItems as $de ) {\r
-\r
-                                       unlink( $versionsName.'.v'.$de );\r
-\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-\r
-       /**\r
-        * @brief Erase all old versions of all user files\r
-        * @return true/false\r
-        */\r
-       public function expireAll() {\r
-               $view = \OCP\Files::getStorage('files_versions');\r
-               return $view->deleteAll('', true);\r
-       }\r
+<?php
+/**
+ * Copyright (c) 2012 Frank Karlitschek <frank@owncloud.org>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+/**
+ * Versions
+ *
+ * A class to handle the versioning of files.
+ */
+
+namespace OCA_Versions;
+
+class Storage {
+
+
+       // config.php configuration:
+       //   - files_versions
+       //   - files_versionsfolder
+       //   - files_versionsblacklist
+       //   - files_versionsmaxfilesize
+       //   - files_versionsinterval
+       //   - files_versionmaxversions
+       //
+       // todo:
+       //   - finish porting to OC_FilesystemView to enable network transparency
+       //   - add transparent compression. first test if it´s worth it.
+
+       const DEFAULTENABLED=true;
+       const DEFAULTBLACKLIST='avi mp3 mpg mp4 ctmp';
+       const DEFAULTMAXFILESIZE=1048576; // 10MB
+       const DEFAULTMININTERVAL=60; // 1 min
+       const DEFAULTMAXVERSIONS=50;
+
+       private static function getUidAndFilename($filename)
+       {
+               if (\OCP\App::isEnabled('files_sharing')
+                   && substr($filename, 0, 7) == '/Shared'
+                   && $source = \OCP\Share::getItemSharedWith('file',
+                                       substr($filename, 7),
+                                       \OC_Share_Backend_File::FORMAT_SHARED_STORAGE)) {
+                       $filename = $source['path'];
+                       $pos = strpos($filename, '/files', 1);
+                       $uid = substr($filename, 1, $pos - 1);
+                       $filename = substr($filename, $pos + 6);
+               } else {
+                       $uid = \OCP\User::getUser();
+               }
+               return array($uid, $filename);
+       }
+
+       /**
+        * store a new version of a file.
+        */
+       public function store($filename) {
+               if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
+                       list($uid, $filename) = self::getUidAndFilename($filename);
+                       $files_view = new \OC_FilesystemView('/'.\OCP\User::getUser() .'/files');
+                       $users_view = new \OC_FilesystemView('/'.\OCP\User::getUser());
+
+                       //check if source file already exist as version to avoid recursions.
+                       // todo does this check work?
+                       if ($users_view->file_exists($filename)) {
+                               return false;
+                       }
+
+                       // check if filename is a directory
+                       if($files_view->is_dir($filename)) {
+                               return false;
+                       }
+
+                       // check filetype blacklist
+                       $blacklist=explode(' ', \OCP\Config::getSystemValue('files_versionsblacklist', Storage::DEFAULTBLACKLIST));
+                       foreach($blacklist as $bl) {
+                               $parts=explode('.', $filename);
+                               $ext=end($parts);
+                               if(strtolower($ext)==$bl) {
+                                       return false;
+                               }
+                       }
+                       // we should have a source file to work with
+                       if (!$files_view->file_exists($filename)) {
+                               return false;
+                       }
+
+                       // check filesize
+                       if($files_view->filesize($filename)>\OCP\Config::getSystemValue('files_versionsmaxfilesize', Storage::DEFAULTMAXFILESIZE)) {
+                               return false;
+                       }
+
+
+                       // check mininterval if the file is being modified by the owner (all shared files should be versioned despite mininterval)
+                       if ($uid == \OCP\User::getUser()) {
+                               $versions_fileview = new \OC_FilesystemView('/'.\OCP\User::getUser().'/files_versions');
+                               $versionsName=\OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath($filename);
+                               $versionsFolderName=\OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath('');
+                               $matches=glob($versionsName.'.v*');
+                               sort($matches);
+                               $parts=explode('.v', end($matches));
+                               if((end($parts)+Storage::DEFAULTMININTERVAL)>time()) {
+                                       return false;
+                               }
+                       }
+
+
+                       // create all parent folders
+                       $info=pathinfo($filename);
+                       if(!file_exists($versionsFolderName.'/'.$info['dirname'])) {
+                               mkdir($versionsFolderName.'/'.$info['dirname'], 0750, true);
+                       }
+
+                       // store a new version of a file
+                       $users_view->copy('files'.$filename, 'files_versions'.$filename.'.v'.time());
+
+                       // expire old revisions if necessary
+                       Storage::expire($filename);
+               }
+       }
+
+
+       /**
+        * rollback to an old version of a file.
+        */
+       public static function rollback($filename, $revision) {
+
+               if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
+                       list($uid, $filename) = self::getUidAndFilename($filename);
+                       $users_view = new \OC_FilesystemView('/'.\OCP\User::getUser());
+
+                       // rollback
+                       if( @$users_view->copy('files_versions'.$filename.'.v'.$revision, 'files'.$filename) ) {
+
+                               return true;
+
+                       }else{
+
+                               return false;
+
+                       }
+
+               }
+
+       }
+
+       /**
+        * check if old versions of a file exist.
+        */
+       public static function isversioned($filename) {
+               if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
+                       list($uid, $filename) = self::getUidAndFilename($filename);
+                       $versions_fileview = new \OC_FilesystemView('/'.\OCP\User::getUser().'/files_versions');
+
+                       $versionsName=\OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath($filename);
+
+                       // check for old versions
+                       $matches=glob($versionsName.'.v*');
+                       if(count($matches)>0) {
+                               return true;
+                       }else{
+                               return false;
+                       }
+               }else{
+                       return(false);
+               }
+       }
+
+
+
+       /**
+        * @brief get a list of all available versions of a file in descending chronological order
+        * @param $filename file to find versions of, relative to the user files dir
+        * @param $count number of versions to return
+        * @returns array
+        */
+       public static function getVersions( $filename, $count = 0 ) {
+               if( \OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' ) {
+                       list($uid, $filename) = self::getUidAndFilename($filename);
+                       $versions_fileview = new \OC_FilesystemView('/'.\OCP\User::getUser().'/files_versions');
+
+                       $versionsName = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath($filename);
+                       $versions = array();
+                       // fetch for old versions
+                       $matches = glob( $versionsName.'.v*' );
+
+                       sort( $matches );
+
+                       $i = 0;
+
+                       $files_view = new \OC_FilesystemView('/'.\OCP\User::getUser().'/files');
+                       $local_file = $files_view->getLocalFile($filename);
+                       foreach( $matches as $ma ) {
+
+                               $i++;
+                               $versions[$i]['cur'] = 0;
+                               $parts = explode( '.v', $ma );
+                               $versions[$i]['version'] = ( end( $parts ) );
+
+                               // if file with modified date exists, flag it in array as currently enabled version
+                               ( \md5_file( $ma ) == \md5_file( $local_file ) ? $versions[$i]['fileMatch'] = 1 : $versions[$i]['fileMatch'] = 0 );
+
+                       }
+
+                       $versions = array_reverse( $versions );
+
+                       foreach( $versions as $key => $value ) {
+
+                               // flag the first matched file in array (which will have latest modification date) as current version
+                               if ( $value['fileMatch'] ) {
+
+                                       $value['cur'] = 1;
+                                       break;
+
+                               }
+
+                       }
+
+                       $versions = array_reverse( $versions );
+
+                       // only show the newest commits
+                       if( $count != 0 and ( count( $versions )>$count ) ) {
+
+                               $versions = array_slice( $versions, count( $versions ) - $count );
+
+                       }
+
+                       return( $versions );
+
+
+               } else {
+
+                       // if versioning isn't enabled then return an empty array
+                       return( array() );
+
+               }
+
+       }
+
+       /**
+        * @brief Erase a file's versions which exceed the set quota
+        */
+       public static function expire($filename) {
+               if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
+                       list($uid, $filename) = self::getUidAndFilename($filename);
+                       $versions_fileview = new \OC_FilesystemView('/'.$uid.'/files_versions');
+
+                       $versionsName=\OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath($filename);
+
+                       // check for old versions
+                       $matches = glob( $versionsName.'.v*' );
+
+                       if( count( $matches ) > \OCP\Config::getSystemValue( 'files_versionmaxversions', Storage::DEFAULTMAXVERSIONS ) ) {
+
+                               $numberToDelete = count($matches) - \OCP\Config::getSystemValue( 'files_versionmaxversions', Storage::DEFAULTMAXVERSIONS );
+
+                               // delete old versions of a file
+                               $deleteItems = array_slice( $matches, 0, $numberToDelete );
+
+                               foreach( $deleteItems as $de ) {
+
+                                       unlink( $versionsName.'.v'.$de );
+
+                               }
+                       }
+               }
+       }
+
+       /**
+        * @brief Erase all old versions of all user files
+        * @return true/false
+        */
+       public function expireAll() {
+               $view = \OCP\Files::getStorage('files_versions');
+               return $view->deleteAll('', true);
+       }
 }