$file = stripslashes($_GET["file"]);
$newname = stripslashes($_GET["newname"]);
- if (($dir != '' || $file != 'Shared')) {
-// Delete
-if( $newname !== '.' and OC_Files::move( $dir, $file, $dir, $newname )) {
- OCP\JSON::success(array("data" => array( "dir" => $dir, "file" => $file, "newname" => $newname )));
-}
-else{
++if (($dir != '' || $file != 'Shared') and $newname !== '.') {
+ $targetFile = \OC\Files\Filesystem::normalizePath($dir . '/' . $newname);
+ $sourceFile = \OC\Files\Filesystem::normalizePath($dir . '/' . $file);
+ if(\OC\Files\Filesystem::rename($sourceFile, $targetFile)) {
+ OCP\JSON::success(array("data" => array( "dir" => $dir, "file" => $file, "newname" => $newname )));
+ } else {
+ OCP\JSON::error(array("data" => array( "message" => "Unable to rename file" )));
+ }
+}else{
OCP\JSON::error(array("data" => array( "message" => "Unable to rename file" )));
}
for($i=0;$i<$fileCount;$i++) {
$target = OCP\Files::buildNotExistingFileName(stripslashes($dir), $files['name'][$i]);
// $path needs to be normalized - this failed within drag'n'drop upload to a sub-folder
-- $target = OC_Filesystem::normalizePath($target);
-- if(is_uploaded_file($files['tmp_name'][$i]) and OC_Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) {
- $meta = OC_FileCache::get($target);
- $id = OC_FileCache::getId($target);
++ $target = \OC\Files\Filesystem::normalizePath($target);
++ if(is_uploaded_file($files['tmp_name'][$i]) and \OC\Files\Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) {
+ $meta = \OC\Files\Filesystem::getFileInfo($target);
$result[]=array( 'status' => 'success',
'mime'=>$meta['mimetype'],
'size'=>$meta['size'],
if (isset($_GET['path'])) {
$path .= $_GET['path'];
}
- if (!$path || !\OC\Files\Filesystem::isValidPath($path) || !OC_Filesystem::file_exists($path)) {
- if (!$path || !OC_Filesystem::isValidPath($path) || !OC_Filesystem::file_exists($path)) {
- OCP\Util::writeLog('share', 'Invalid path '.$path.' for share id '.$linkItem['id'], \OCP\Util::ERROR);
++ if (!$path || !\OC\Files\Filesystem::isValidPath($path) || !\OC\Files\Filesystem::file_exists($path)) {
+ OCP\Util::writeLog('share', 'Invalid path ' . $path . ' for share id ' . $linkItem['id'], \OCP\Util::ERROR);
header('HTTP/1.0 404 Not Found');
$tmpl = new OCP\Template('', '404', 'guest');
$tmpl->printPage();
$tmpl->assign('uidOwner', $shareOwner);
$tmpl->assign('dir', $dir);
$tmpl->assign('filename', $file);
-- $tmpl->assign('mimetype', OC_Filesystem::getMimeType($path));
++ $tmpl->assign('mimetype', \OC\Files\Filesystem::getMimeType($path));
if (isset($_GET['path'])) {
$getPath = $_GET['path'];
} else {
$getPath = '';
}
//
- $urlLinkIdentifiers= (isset($token)?'&t='.$token:'').(isset($_GET['dir'])?'&dir='.$_GET['dir']:'').(isset($_GET['file'])?'&file='.$_GET['file']:'');
+ $urlLinkIdentifiers = (isset($token) ? '&t=' . $token : '') . (isset($_GET['dir']) ? '&dir=' . $_GET['dir'] : '') . (isset($_GET['file']) ? '&file=' . $_GET['file'] : '');
// Show file list
-- if (OC_Filesystem::is_dir($path)) {
++ if (\OC\Files\Filesystem::is_dir($path)) {
OCP\Util::addStyle('files', 'files');
OCP\Util::addScript('files', 'files');
OCP\Util::addScript('files', 'filelist');
//add subdir breadcrumbs
foreach (explode('/', urldecode($getPath)) as $i) {
if ($i != '') {
- $pathtohere .= '/'.$i;
+ $pathtohere .= '/' . $i;
$breadcrumb[] = array('dir' => $pathtohere, 'name' => $i);
- if (OC_Filesystem::is_dir($path)) {
+ $path = $linkItem['path'];
+ if (isset($_GET['path'])) {
+ $path .= $_GET['path'];
+ $dir .= $_GET['path'];
+ if (!\OC\Files\Filesystem::file_exists($path)) {
+ header('HTTP/1.0 404 Not Found');
+ $tmpl = new OCP\Template('', '404', 'guest');
+ $tmpl->printPage();
+ exit();
+ }
+ }
+
+ $list = new OCP\Template('files', 'part.list', '');
+ $list->assign('files', $files, false);
+ $list->assign('publicListView', true);
+ $list->assign('baseURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&path=', false);
+ $list->assign('downloadURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download&path=', false);
+ $breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', '');
+ $breadcrumbNav->assign('breadcrumb', $breadcrumb, false);
+ $breadcrumbNav->assign('baseURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&path=', false);
+ $folder = new OCP\Template('files', 'index', '');
+ $folder->assign('fileList', $list->fetchPage(), false);
+ $folder->assign('breadcrumb', $breadcrumbNav->fetchPage(), false);
+ $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('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true)));
+ $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download&path=' . urlencode($getPath));
+ } else {
+ // Show file preview if viewer is available
+ if ($type == 'file') {
+ $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download');
+ } 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
- $tmpl->assign('mimetype', OC_Filesystem::getMimeType($path));
++ if (\OC\Files\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\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('mimetype', \OC\Files\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\Files\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();
+ }
}
+ $tmpl->printPage();
}
$list = new OCP\Template('files', 'part.list', '');
$uri='/'.$uri;
}
list($parentUri, $newName) = Sabre_DAV_URLUtil::splitPath($uri);
-- if ($length > OC_Filesystem::free_space($parentUri)) {
++ if ($length > \OC\Files\Filesystem::free_space($parentUri)) {
throw new Sabre_DAV_Exception_InsufficientStorage();
}
}
--- /dev/null
- return stat($this->datadir.$path);
+<?php
+/**
+ * Copyright (c) 2012 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Files\Storage;
+
+/**
+ * for local filestore, we only have to map the paths
+ */
+class Local extends \OC\Files\Storage\Common{
+ protected $datadir;
+ public function __construct($arguments) {
+ $this->datadir=$arguments['datadir'];
+ if(substr($this->datadir, -1)!=='/') {
+ $this->datadir.='/';
+ }
+ }
+ public function getId(){
+ return 'local::'.$this->datadir;
+ }
+ public function mkdir($path) {
+ return @mkdir($this->datadir.$path);
+ }
+ public function rmdir($path) {
+ return @rmdir($this->datadir.$path);
+ }
+ public function opendir($path) {
+ return opendir($this->datadir.$path);
+ }
+ public function is_dir($path) {
+ if(substr($path,-1)=='/') {
+ $path=substr($path, 0, -1);
+ }
+ return is_dir($this->datadir.$path);
+ }
+ public function is_file($path) {
+ return is_file($this->datadir.$path);
+ }
+ public function stat($path) {
- return filesize($this->datadir.$path);
++ $fullPath = $this->datadir . $path;
++ $statResult = stat($fullPath);
++
++ if ($statResult['size'] < 0) {
++ $size = self::getFileSizeFromOS($fullPath);
++ $statResult['size'] = $size;
++ $statResult[7] = $size;
++ }
++ return $statResult;
+ }
+ public function filetype($path) {
+ $filetype=filetype($this->datadir.$path);
+ if($filetype=='link') {
+ $filetype=filetype(realpath($this->datadir.$path));
+ }
+ return $filetype;
+ }
+ public function filesize($path) {
+ if($this->is_dir($path)) {
+ return 0;
+ }else{
++ $fullPath = $this->datadir . $path;
++ $fileSize = filesize($fullPath);
++ if ($fileSize < 0) {
++ return self::getFileSizeFromOS($fullPath);
++ }
++
++ return $fileSize;
+ }
+ }
+ public function isReadable($path) {
+ return is_readable($this->datadir.$path);
+ }
+ public function isUpdatable($path) {
+ return is_writable($this->datadir.$path);
+ }
+ public function file_exists($path) {
+ return file_exists($this->datadir.$path);
+ }
+ public function filemtime($path) {
+ return filemtime($this->datadir.$path);
+ }
+ public function touch($path, $mtime=null) {
+ // sets the modification time of the file to the given value.
+ // If mtime is nil the current time is set.
+ // note that the access time of the file always changes to the current time.
+ if(!is_null($mtime)) {
+ $result=touch( $this->datadir.$path, $mtime );
+ }else{
+ $result=touch( $this->datadir.$path);
+ }
+ if( $result ) {
+ clearstatcache( true, $this->datadir.$path );
+ }
+
+ return $result;
+ }
+ public function file_get_contents($path) {
+ return file_get_contents($this->datadir.$path);
+ }
+ public function file_put_contents($path, $data) {
+ return file_put_contents($this->datadir.$path, $data);
+ }
+ public function unlink($path) {
+ return $this->delTree($path);
+ }
+ public function rename($path1, $path2) {
+ if (!$this->isUpdatable($path1)) {
+ \OC_Log::write('core','unable to rename, file is not writable : '.$path1,\OC_Log::ERROR);
+ return false;
+ }
+ if(! $this->file_exists($path1)) {
+ \OC_Log::write('core','unable to rename, file does not exists : '.$path1,\OC_Log::ERROR);
+ return false;
+ }
+
+ if($return=rename($this->datadir.$path1, $this->datadir.$path2)) {
+ }
+ return $return;
+ }
+ public function copy($path1, $path2) {
+ if($this->is_dir($path2)) {
+ if(!$this->file_exists($path2)) {
+ $this->mkdir($path2);
+ }
+ $source=substr($path1, strrpos($path1, '/')+1);
+ $path2.=$source;
+ }
+ return copy($this->datadir.$path1, $this->datadir.$path2);
+ }
+ public function fopen($path, $mode) {
+ if($return=fopen($this->datadir.$path, $mode)) {
+ switch($mode) {
+ case 'r':
+ break;
+ case 'r+':
+ case 'w+':
+ case 'x+':
+ case 'a+':
+ break;
+ case 'w':
+ case 'x':
+ case 'a':
+ break;
+ }
+ }
+ return $return;
+ }
+
+ public function getMimeType($path) {
+ if($this->isReadable($path)) {
+ return \OC_Helper::getMimeType($this->datadir . $path);
+ }else{
+ return false;
+ }
+ }
+
+ private function delTree($dir) {
+ $dirRelative=$dir;
+ $dir=$this->datadir.$dir;
+ if (!file_exists($dir)) return true;
+ if (!is_dir($dir) || is_link($dir)) return unlink($dir);
+ foreach (scandir($dir) as $item) {
+ if ($item == '.' || $item == '..') continue;
+ if(is_file($dir.'/'.$item)) {
+ if(unlink($dir.'/'.$item)) {
+ }
+ }elseif(is_dir($dir.'/'.$item)) {
+ if (!$this->delTree($dirRelative. "/" . $item)) {
+ return false;
+ };
+ }
+ }
+ if($return=rmdir($dir)) {
+ }
+ return $return;
+ }
+
++ private static function getFileSizeFromOS($fullPath) {
++ $name = strtolower(php_uname('s'));
++ // Windows OS: we use COM to access the filesystem
++ if (strpos($name, 'win') !== false) {
++ if (class_exists('COM')) {
++ $fsobj = new COM("Scripting.FileSystemObject");
++ $f = $fsobj->GetFile($fullPath);
++ return $f->Size;
++ }
++ } else if (strpos($name, 'bsd') !== false) {
++ if (\OC_Helper::is_function_enabled('exec')) {
++ return (float)exec('stat -f %z ' . escapeshellarg($fullPath));
++ }
++ } else if (strpos($name, 'linux') !== false) {
++ if (\OC_Helper::is_function_enabled('exec')) {
++ return (float)exec('stat -c %s ' . escapeshellarg($fullPath));
++ }
++ } else {
++ OC_Log::write('core', 'Unable to determine file size of "'.$fullPath.'". Unknown OS: '.$name, OC_Log::ERROR);
++ }
++
++ return 0;
++ }
++
+ public function hash($path, $type, $raw=false) {
+ return hash_file($type, $this->datadir.$path, $raw);
+ }
+
+ public function free_space($path) {
+ return @disk_free_space($this->datadir.$path);
+ }
+
+ public function search($query) {
+ return $this->searchInDir($query);
+ }
+ public function getLocalFile($path) {
+ return $this->datadir.$path;
+ }
+ public function getLocalFolder($path) {
+ return $this->datadir.$path;
+ }
+
+ protected function searchInDir($query, $dir='') {
+ $files=array();
+ foreach (scandir($this->datadir.$dir) as $item) {
+ if ($item == '.' || $item == '..') continue;
+ if(strstr(strtolower($item), strtolower($query))!==false) {
+ $files[]=$dir.'/'.$item;
+ }
+ if(is_dir($this->datadir.$dir.'/'.$item)) {
+ $files=array_merge($files, $this->searchInDir($query, $dir.'/'.$item));
+ }
+ }
+ return $files;
+ }
+
+ /**
+ * check if a file or folder has been updated since $time
++ * @param string $path
+ * @param int $time
+ * @return bool
+ */
+ public function hasUpdated($path, $time) {
+ return $this->filemtime($path)>$time;
+ }
+}
self::copyr("$src/$file", "$dest/$file");
}
}
-- }elseif(file_exists($src) && !OC_Filesystem::isFileBlacklisted($src)) {
++ }elseif(file_exists($src) && !\OC\Files\Filesystem::isFileBlacklisted($src)) {
copy($src, $dest);
}
}
--- /dev/null
- OC_Filesystem::init($useDir);
- $rootInfo = OC_FileCache::get('');
- $sharedInfo = OC_FileCache::get('/Shared');
+ <?php
+ /**
+ * ownCloud
+ *
+ * @author Frank Karlitschek
+ * @author Tom Needham
+ * @copyright 2012 Frank Karlitschek frank@owncloud.org
+ * @copyright 2012 Tom Needham tom@owncloud.com
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * 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
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+ class OC_OCS_Cloud {
+
+ public static function getSystemWebApps($parameters) {
+ OC_Util::checkLoggedIn();
+ $apps = OC_App::getEnabledApps();
+ $values = array();
+ foreach($apps as $app) {
+ $info = OC_App::getAppInfo($app);
+ if(isset($info['standalone'])) {
+ $newValue = array('name'=>$info['name'],'url'=>OC_Helper::linkToAbsolute($app,''),'icon'=>'');
+ $values[] = $newValue;
+ }
+ }
+ return new OC_OCS_Result($values);
+ }
+
+ public static function getUserQuota($parameters) {
+ $user = OC_User::getUser();
+ if(OC_Group::inGroup($user, 'admin') or ($user==$parameters['user'])) {
+
+ if(OC_User::userExists($parameters['user'])) {
+ // calculate the disc space
+ $userDir = '/'.$parameters['user'].'/files';
- $free = OC_Filesystem::free_space();
++ \OC\Files\Filesystem::init($useDir);
++ $rootInfo = \OC\Files\Filesystem::getFileInfo('');
++ $sharedInfo = \OC\Files\Filesystem::getFileInfo('/Shared');
+ $used = $rootInfo['size'] - $sharedInfo['size'];
++ $free = \OC\Files\Filesystem::free_space();
+ $total = $free + $used;
+ if($total===0) $total = 1; // prevent division by zero
+ $relative = round(($used/$total)*10000)/100;
+
+ $xml = array();
+ $xml['quota'] = $total;
+ $xml['free'] = $free;
+ $xml['used'] = $used;
+ $xml['relative'] = $relative;
+
+ return new OC_OCS_Result($xml);
+ } else {
+ return new OC_OCS_Result(null, 300);
+ }
+ } else {
+ return new OC_OCS_Result(null, 300);
+ }
+ }
+
+ public static function getUserPublickey($parameters) {
+
+ if(OC_User::userExists($parameters['user'])) {
+ // calculate the disc space
+ // TODO
+ return new OC_OCS_Result(array());
+ } else {
+ return new OC_OCS_Result(null, 300);
+ }
+ }
+
+ public static function getUserPrivatekey($parameters) {
+ $user = OC_User::getUser();
+ if(OC_Group::inGroup($user, 'admin') or ($user==$parameters['user'])) {
+
+ if(OC_User::userExists($user)) {
+ // calculate the disc space
+ $txt = 'this is the private key of '.$parameters['user'];
+ echo($txt);
+ } else {
+ return new OC_OCS_Result(null, 300, 'User does not exist');
+ }
+ } else {
+ return new OC_OCS_Result('null', 300, 'You donĀ“t have permission to access this ressource.');
+ }
+ }
+ }