if(extension){
name_span.append($('<span></span>').addClass('extension').text(extension));
}
- //dirs can show the number of uploaded files
+ //dirs can show the number of uploaded files
if (type == 'dir') {
link_elem.append($('<span></span>').attr({
'class': 'uploadtext',
}
td.append(link_elem);
tr.append(td);
-
+
//size column
if(size!=t('files', 'Pending')){
simpleSize=simpleFileSize(size);
"style": 'color:rgb('+sizeColor+','+sizeColor+','+sizeColor+')'
}).text(simpleSize);
tr.append(td);
-
+
// date column
var modifiedColor = Math.round((Math.round((new Date()).getTime() / 1000)-lastModifiedTime)/60/60/24*5);
td = $('<td></td>').attr({ "class": "date" });
lastModified,
$('#permissions').val()
);
-
+
FileList.insertElement(name, 'file', tr.attr('data-file',name));
var row = $('tr').filterAttr('data-file',name);
if(loading){
FileActions.display(row.find('td.filename'));
},
addDir:function(name,size,lastModified,hidden){
-
+
var tr = this.createRow(
'dir',
name,
lastModified,
$('#permissions').val()
);
-
+
FileList.insertElement(name,'dir',tr);
var row = $('tr').filterAttr('data-file',name);
row.find('td.filename').draggable(dragOptions);
var deleteAction = $('tr').filterAttr('data-file',file).children("td.date").children(".move2trash");
deleteAction[0].outerHTML = oldHTML;
});
- }
+ }
});
}
};
$(this).parent().children('#file_upload_start').trigger('click');
return false;
});
-
+
// Show trash bin
$('#trash a').live('click', function() {
window.location=OC.filePath('files_trashbin', '', 'index.php');
//select dragged file
$(event.target).parents('tr').find('td input:first').prop('checked',true);
}
-
+
var selectedFiles = getSelectedFiles();
-
+
if (!isDragSelected && selectedFiles.length == 1) {
//revert the selection
$(event.target).parents('tr').find('td input:first').prop('checked',false);
}
-
+
//also update class when we dragged more than one file
if (selectedFiles.length > 1) {
$(event.target).parents('tr').addClass('selected');
}
-
+
// build dragshadow
var dragshadow = $('<table class="dragshadow"></table>');
var tbody = $('<tbody></tbody>');
dragshadow.append(tbody);
-
+
var dir=$('#dir').val();
-
+
$(selectedFiles).each(function(i,elem){
var newtr = $('<tr data-dir="'+dir+'" data-filename="'+elem.name+'">'
+'<td class="filename">'+elem.name+'</td><td class="size">'+humanFileSize(elem.size)+'</td>'
});
}
});
-
+
return dragshadow;
}
if ($(event.target).parents('tr').find('td input:first').prop('checked') === true) {
return false;
}
-
+
var target=$.trim($(this).find('.nametext').text());
-
+
var files = ui.helper.find('tr');
$(files).each(function(i,row){
var dir = $(row).data('dir');
* @return array
*/
public static function getBackends() {
-
+
$backends['\OC\Files\Storage\Local']=array(
'backend' => 'Local',
'configuration' => array(
'token' => '#token',
'token_secret' => '#token secret'),
'custom' => 'google');
-
+
$backends['\OC\Files\Storage\SWIFT']=array(
'backend' => 'OpenStack Swift',
'configuration' => array(
'token' => '*Token',
'root' => '&Root',
'secure' => '!Secure ftps://'));
-
+
if(OC_Mount_Config::checksmbclient()) $backends['\OC\Files\Storage\SMB']=array(
'backend' => 'SMB / CIFS',
'configuration' => array(
'password' => '*Password',
'share' => 'Share',
'root' => '&Root'));
-
+
$backends['\OC\Files\Storage\DAV']=array(
'backend' => 'ownCloud / WebDAV',
'configuration' => array(
'password' => '*Password',
'root' => '&Root',
'secure' => '!Secure https://'));
-
+
$backends['\OC\Files\Storage\SFTP']=array(
'backend' => 'SFTP',
'configuration' => array(
'host' => 'URL',
- 'user' => 'Username',
- 'password' => '*Password',
+ 'user' => 'Username',
+ 'password' => '*Password',
'root' => '&Root'));
return($backends);
}
/**
- * check if php-ftp is installed
+ * check if php-ftp is installed
*/
public static function checkphpftp() {
if(function_exists('ftp_login')) {
$this->root = isset($params['root']) ? $this->cleanPath($params['root']) : '/';
if ($this->root[0] != '/') $this->root = '/' . $this->root;
if (substr($this->root, -1, 1) != '/') $this->root .= '/';
-
+
$host_keys = $this->read_host_keys();
$this->client = new \Net_SFTP($this->host);
$host_keys[$this->host] = $current_host_key;
$this->write_host_keys($host_keys);
}
-
+
if(!$this->file_exists('')){
$this->mkdir('');
}
}
-
+
public function test() {
if (!isset($params['host']) || !isset($params['user']) || !isset($params['password'])) {
throw new \Exception("Required parameters not set");
- }
+ }
}
-
+
public function getId(){
return 'sftp::' . $this->user . '@' . $this->host . '/' . $this->root;
}
$host_key_arr = explode("::", $line, 2);
if (count($host_key_arr) == 2) {
$hosts[] = $host_key_arr[0];
- $keys[] = $host_key_arr[1];
+ $keys[] = $host_key_arr[1];
}
}
return array_combine($hosts, $keys);
$tmp = \OC_Helper::tmpFile($ext);
$this->getFile($abs_path, $tmp);
return fopen($tmp, $mode);
-
+
case 'w':
case 'wb':
case 'a':
$path = \OC\Files\Filesystem::getPath($linkItem['file_source']);
}
}
-}
+}
if (isset($path)) {
if (!isset($linkItem['item_type'])) {
OCP\Util::writeLog('share', 'No item type set for share id: ' . $linkItem['id'], \OCP\Util::ERROR);
header('HTTP/1.0 404 Not Found');
$tmpl = new OCP\Template('', '404', 'guest');
$tmpl->printPage();
-
$filename = $file;
$timestamp = null;
}
-
+
OCA\Files_Trashbin\Trashbin::delete($filename, $timestamp);
if (!OCA\Files_Trashbin\Trashbin::file_exists($filename, $timestamp)) {
$success[$i]['filename'] = $file;
-<?php
+<?php
OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
$filename = $path_parts['basename'];
$timestamp = null;
}
-
+
if ( !OCA\Files_Trashbin\Trashbin::restore($file, $filename, $timestamp) ) {
$error[] = $filename;
} else {
<?php
-OC::$CLASSPATH['OCA\Files_Trashbin\Hooks'] = 'apps/files_trashbin/lib/hooks.php';\r
-OC::$CLASSPATH['OCA\Files_Trashbin\Trashbin'] = 'apps/files_trashbin/lib/trash.php';\r
+OC::$CLASSPATH['OCA\Files_Trashbin\Hooks'] = 'apps/files_trashbin/lib/hooks.php';
+OC::$CLASSPATH['OCA\Files_Trashbin\Trashbin'] = 'apps/files_trashbin/lib/trash.php';
+
-\r
OCP\Util::connectHook('OC_Filesystem', 'delete', "OCA\Files_Trashbin\Hooks", "remove_hook");
<?php
-// Check if we are a user\r
+// Check if we are a user
OCP\User::checkLoggedIn();
OCP\Util::addScript('files_trashbin', 'trash');
$result = array();
if ($dir) {
$dirlisting = true;
- $view = new \OC_FilesystemView('/'.\OCP\User::getUser().'/files_trashbin');\r
+ $view = new \OC_FilesystemView('/'.\OCP\User::getUser().'/files_trashbin');
$fullpath = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath($dir);
$dirContent = opendir($fullpath);
$i = 0;
'type' => $view->is_dir($dir.'/'.$entryName) ? 'dir' : 'file',
'location' => $dir,
);
- }\r
+ }
}
closedir($dirContent);
-
+
} else {
$dirlisting = false;
$query = \OC_DB::prepare('SELECT id,location,timestamp,type,mime FROM *PREFIX*files_trash WHERE user=?');
$files[] = $i;
}
-// Make breadcrumb\r
+// Make breadcrumb
$pathtohere = '';
-$breadcrumb = array();\r
-foreach (explode('/', $dir) as $i) {\r
+$breadcrumb = array();
+foreach (explode('/', $dir) as $i) {
if ($i != '') {
if ( preg_match('/^(.+)\.d[0-9]+$/', $i, $match) ) {
$name = $match[1];
} else {
$name = $i;
- }\r
- $pathtohere .= '/' . $i;\r
- $breadcrumb[] = array('dir' => $pathtohere, 'name' => $name);\r
- }\r
+ }
+ $pathtohere .= '/' . $i;
+ $breadcrumb[] = array('dir' => $pathtohere, 'name' => $name);
+ }
}
-$breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', '');\r
-$breadcrumbNav->assign('breadcrumb', $breadcrumb, false);\r
+$breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', '');
+$breadcrumbNav->assign('breadcrumb', $breadcrumb, false);
$breadcrumbNav->assign('baseURL', OCP\Util::linkTo('files_trashbin', 'index.php') . '?dir=', false);
$list = new OCP\Template('files_trashbin', 'part.list', '');
$list->assign('files', $files, false);
-$list->assign('baseURL', OCP\Util::linkTo('files_trashbin', 'index.php'). '?dir='.$dir, false);\r
+$list->assign('baseURL', OCP\Util::linkTo('files_trashbin', 'index.php'). '?dir='.$dir, false);
$list->assign('downloadURL', OCP\Util::linkTo('files_trashbin', 'download.php') . '?file='.$dir, false);
$list->assign('disableSharing', true);
$list->assign('dirlisting', $dirlisting);
-/* disable download and sharing actions */\r
-var disableDownloadActions = true;\r
-var disableSharing = true;\r
+/* disable download and sharing actions */
+var disableDownloadActions = true;
+var disableSharing = true;
var trashBinApp = true;
\ No newline at end of file
OC.dialogs.alert(result.data.message, 'Error');
}
});
-
+
});
};
-
+
FileActions.register('all', 'Delete', OC.PERMISSION_READ, function () {
return OC.imagePath('core', 'actions/delete');
}, function (filename) {
$('.tipsy').remove();
-
+
var tr=$('tr').filterAttr('data-file', filename);
var deleteAction = $('tr').filterAttr('data-file',filename).children("td.date").children(".action.delete");
var oldHTML = deleteAction[0].outerHTML;
var newHTML = '<img class="move2trash" data-action="Delete" title="'+t('files', 'delete file permanently')+'" src="'+ OC.imagePath('core', 'loading.gif') +'"></a>';
var files = tr.attr('data-file');
deleteAction[0].outerHTML = newHTML;
-
+
$.post(OC.filePath('files_trashbin','ajax','delete.php'),
{files:JSON.stringify([files]), dirlisting:tr.attr('data-dirlisting') },
function(result){
OC.dialogs.alert(result.data.message, 'Error');
}
});
-
+
});
-
+
// Sets the select_all checkbox behaviour :
$('#select_all').click(function() {
if($(this).attr('checked')){
}
processSelection();
});
-
+
$('.undelete').click('click',function(event) {
var spinner = '<img class="move2trash" title="'+t('files_trashbin', 'perform restore operation')+'" src="'+ OC.imagePath('core', 'loader.gif') +'"></a>';
var files=getSelectedFiles('file');
var fileslist = JSON.stringify(files);
var dirlisting=getSelectedFiles('dirlisting')[0];
-
+
for (var i=0; i<files.length; i++) {
var undeleteAction = $('tr').filterAttr('data-file',files[i]).children("td.date");
undeleteAction[0].innerHTML = undeleteAction[0].innerHTML+spinner;
}
-
+
$.post(OC.filePath('files_trashbin','ajax','undelete.php'),
{files:fileslist, dirlisting:dirlisting},
function(result){
}
});
});
-
+
$('.delete').click('click',function(event) {
console.log("delete selected");
var spinner = '<img class="move2trash" title="'+t('files_trashbin', 'Delete permanently')+'" src="'+ OC.imagePath('core', 'loading.gif') +'"></a>';
var files=getSelectedFiles('file');
var fileslist = JSON.stringify(files);
var dirlisting=getSelectedFiles('dirlisting')[0];
-
+
for (var i=0; i<files.length; i++) {
var deleteAction = $('tr').filterAttr('data-file',files[i]).children("td.date");
deleteAction[0].innerHTML = deleteAction[0].innerHTML+spinner;
}
-
+
$.post(OC.filePath('files_trashbin','ajax','delete.php'),
{files:fileslist, dirlisting:dirlisting},
function(result){
<?php
-/**\r
- * ownCloud - trash bin\r
- *\r
- * @author Bjoern Schiessle\r
- * @copyright 2013 Bjoern Schiessle schiessle@owncloud.com\r
- *\r
- * This library is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE\r
- * License as published by the Free Software Foundation; either\r
- * version 3 of the License, or any later version.\r
- *\r
- * This library is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.\r
- *\r
- * You should have received a copy of the GNU Affero General Public\r
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.\r
- *\r
+/**
+ * ownCloud - trash bin
+ *
+ * @author Bjoern Schiessle
+ * @copyright 2013 Bjoern Schiessle schiessle@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/>.
+ *
*/
/**
* to copy the file to the trash bin
*/
public static function remove_hook($params) {
-
+
if ( \OCP\App::isEnabled('files_trashbin') ) {
$path = $params['path'];
Trashbin::move2trash($path);
<?php
-/**\r
- * ownCloud - trash bin\r
- *\r
- * @author Bjoern Schiessle\r
- * @copyright 2013 Bjoern Schiessle schiessle@owncloud.com\r
- *\r
- * This library is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE\r
- * License as published by the Free Software Foundation; either\r
- * version 3 of the License, or any later version.\r
- *\r
- * This library is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU AFFERO GENERAL PUBLIC LICENSE for more details.\r
- *\r
- * You should have received a copy of the GNU Affero General Public\r
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.\r
- *\r
- */\r
-
-namespace OCA\Files_Trashbin;\r
-\r
+/**
+ * ownCloud - trash bin
+ *
+ * @author Bjoern Schiessle
+ * @copyright 2013 Bjoern Schiessle schiessle@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/>.
+ *
+ */
+
+namespace OCA\Files_Trashbin;
+
class Trashbin {
// how long do we keep files in the trash bin if no other value is defined in the config file (unit: days)
const DEFAULT_RETENTION_OBLIGATION=180;
// unit: percentage; 50% of available disk space/quota
const DEFAULTMAXSIZE=50;
-
+
/**
* move file to the trash bin
- *
+ *
* @param $file_path path to the deleted file/directory relative to the files root directory
*/
public static function move2trash($file_path) {
$user = \OCP\User::getUser();
- $view = new \OC_FilesystemView('/'. $user);\r
- if (!$view->is_dir('files_trashbin')) {\r
- $view->mkdir('files_trashbin');\r
- $view->mkdir("versions_trashbin");\r
- }\r
-\r
- $path_parts = pathinfo($file_path);\r
-\r
- $deleted = $path_parts['basename'];\r
- $location = $path_parts['dirname'];\r
- $timestamp = time();\r
- $mime = $view->getMimeType('files'.$file_path);\r
-\r
- if ( $view->is_dir('files'.$file_path) ) {\r
- $type = 'dir';\r
- } else {\r
- $type = 'file';\r
+ $view = new \OC_FilesystemView('/'. $user);
+ if (!$view->is_dir('files_trashbin')) {
+ $view->mkdir('files_trashbin');
+ $view->mkdir("versions_trashbin");
}
- \r
- if ( ($trashbinSize = \OCP\Config::getAppValue('files_trashbin', 'size')) === null ) {\r
+
+ $path_parts = pathinfo($file_path);
+
+ $deleted = $path_parts['basename'];
+ $location = $path_parts['dirname'];
+ $timestamp = time();
+ $mime = $view->getMimeType('files'.$file_path);
+
+ if ( $view->is_dir('files'.$file_path) ) {
+ $type = 'dir';
+ } else {
+ $type = 'file';
+ }
+
+ if ( ($trashbinSize = \OCP\Config::getAppValue('files_trashbin', 'size')) === null ) {
$trashbinSize = self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_trashbin'));
- $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin'));\r
+ $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin'));
}
$trashbinSize += self::copy_recursive($file_path, 'files_trashbin/'.$deleted.'.d'.$timestamp, $view);
- if ( $view->file_exists('files_trashbin/'.$deleted.'.d'.$timestamp) ) {\r
+ if ( $view->file_exists('files_trashbin/'.$deleted.'.d'.$timestamp) ) {
$query = \OC_DB::prepare("INSERT INTO *PREFIX*files_trash (id,timestamp,location,type,mime,user)"
." VALUES (?,?,?,?,?,?)");
$result = $query->execute(array($deleted, $timestamp, $location, $type, $mime, $user));
$view->deleteAll('files_trashbin/'.$deleted.'.d'.$timestamp);
\OC_Log::write('files_trashbin', 'trash bin database couldn\'t be updated', \OC_log::ERROR);
return;
- }\r
- \r
- if ( \OCP\App::isEnabled('files_versions') ) {\r
+ }
+
+ if ( \OCP\App::isEnabled('files_versions') ) {
if ( $view->is_dir('files_versions'.$file_path) ) {
$trashbinSize += self::calculateSize(
new \OC_FilesystemView('/'. $user.'/files_versions/'.$file_path)
);
- $view->rename('files_versions'.$file_path, 'versions_trashbin/'. $deleted.'.d'.$timestamp);\r
- } else if ( $versions = \OCA\Files_Versions\Storage::getVersions($file_path) ) {\r
+ $view->rename('files_versions'.$file_path, 'versions_trashbin/'. $deleted.'.d'.$timestamp);
+ } else if ( $versions = \OCA\Files_Versions\Storage::getVersions($file_path) ) {
foreach ($versions as $v) {
- $trashbinSize += $view->filesize('files_versions'.$v['path'].'.v'.$v['version']);\r
+ $trashbinSize += $view->filesize('files_versions'.$v['path'].'.v'.$v['version']);
$view->rename('files_versions'.$v['path'].'.v'.$v['version'],
'versions_trashbin/'. $deleted.'.v'.$v['version'].'.d'.$timestamp);
- }\r
- }\r
+ }
+ }
}
} else {
\OC_Log::write('files_trashbin', 'Couldn\'t move '.$file_path.' to the trash bin', \OC_log::ERROR);
}
-
- // get available disk space for user\r
- $quota = \OCP\Util::computerFileSize(\OC_Preferences::getValue($user, 'files', 'quota'));\r
- if ( $quota == null ) {\r
- $quota = \OCP\Util::computerFileSize(\OC_Appconfig::getValue('files', 'default_quota'));\r
- }\r
- if ( $quota == null ) {\r
- $quota = \OC\Files\Filesystem::free_space('/');\r
+
+ // get available disk space for user
+ $quota = \OCP\Util::computerFileSize(\OC_Preferences::getValue($user, 'files', 'quota'));
+ if ( $quota == null ) {
+ $quota = \OCP\Util::computerFileSize(\OC_Appconfig::getValue('files', 'default_quota'));
+ }
+ if ( $quota == null ) {
+ $quota = \OC\Files\Filesystem::free_space('/');
}
-
- // calculate available space for trash bin\r
- $rootInfo = $view->getFileInfo('/files');\r
- $free = $quota-$rootInfo['size']; // remaining free space for user\r
- if ( $free > 0 ) {\r
- $availableSpace = ($free * self::DEFAULTMAXSIZE / 100) - $trashbinSize; // how much space can be used for versions\r
- } else {\r
- $availableSpace = $free-$trashbinSize;\r
+
+ // calculate available space for trash bin
+ $rootInfo = $view->getFileInfo('/files');
+ $free = $quota-$rootInfo['size']; // remaining free space for user
+ if ( $free > 0 ) {
+ $availableSpace = ($free * self::DEFAULTMAXSIZE / 100) - $trashbinSize; // how much space can be used for versions
+ } else {
+ $availableSpace = $free-$trashbinSize;
}
-
+
$trashbinSize -= self::expire($availableSpace);
- \OCP\Config::setAppValue('files_trashbin', 'size', $trashbinSize);\r
+ \OCP\Config::setAppValue('files_trashbin', 'size', $trashbinSize);
}
-
-
+
+
/**
* restore files from trash bin
* @param $file path to the deleted file
public static function restore($file, $filename, $timestamp) {
$user = \OCP\User::getUser();
$view = new \OC_FilesystemView('/'.$user);
-
- if ( ($trashbinSize = \OCP\Config::getAppValue('files_trashbin', 'size')) === null ) {\r
- $trashbinSize = self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_trashbin'));\r
- $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin'));\r
+
+ if ( ($trashbinSize = \OCP\Config::getAppValue('files_trashbin', 'size')) === null ) {
+ $trashbinSize = self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_trashbin'));
+ $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin'));
}
if ( $timestamp ) {
$query = \OC_DB::prepare('SELECT location,type FROM *PREFIX*files_trash'
\OC_Log::write('files_trashbin', 'trash bin database inconsistent!', \OC_Log::ERROR);
return false;
}
-
- // if location no longer exists, restore file in the root directory\r
- $location = $result[0]['location'];\r
- if ( $result[0]['location'] != '/' &&
+
+ // if location no longer exists, restore file in the root directory
+ $location = $result[0]['location'];
+ if ( $result[0]['location'] != '/' &&
(!$view->is_dir('files'.$result[0]['location']) ||
- !$view->isUpdatable('files'.$result[0]['location'])) ) {\r
- $location = '';\r
+ !$view->isUpdatable('files'.$result[0]['location'])) ) {
+ $location = '';
}
} else {
$path_parts = pathinfo($filename);
);
$location = '';
}
-
+
$source = \OC_Filesystem::normalizePath('files_trashbin/'.$file);
$target = \OC_Filesystem::normalizePath('files/'.$location.'/'.$filename);
-
+
// we need a extension in case a file/dir with the same name already exists
$ext = self::getUniqueExtension($location, $filename, $view);
$mtime = $view->filemtime($source);
$versionedFile = $filename;
} else {
$versionedFile = $file;
- }\r
+ }
if ( $result[0]['type'] == 'dir' ) {
$trashbinSize -= self::calculateSize(
new \OC_FilesystemView('/'.$user.'/'.'versions_trashbin/'. $file)
);
$view->rename(\OC_Filesystem::normalizePath('versions_trashbin/'. $file),
\OC_Filesystem::normalizePath('files_versions/'.$location.'/'.$filename.$ext));
- } else if ( $versions = self::getVersionsFromTrash($versionedFile, $timestamp) ) {\r
+ } else if ( $versions = self::getVersionsFromTrash($versionedFile, $timestamp) ) {
foreach ($versions as $v) {
if ($timestamp ) {
$trashbinSize -= $view->filesize('versions_trashbin/'.$versionedFile.'.v'.$v.'.d'.$timestamp);
$trashbinSize -= $view->filesize('versions_trashbin/'.$versionedFile.'.v'.$v);
$view->rename('versions_trashbin/'.$versionedFile.'.v'.$v,
'files_versions/'.$location.'/'.$filename.$ext.'.v'.$v);
- }\r
- }\r
- }\r
+ }
+ }
+ }
}
if ( $timestamp ) {
- $query = \OC_DB::prepare('DELETE FROM *PREFIX*files_trash WHERE user=? AND id=? AND timestamp=?');\r
+ $query = \OC_DB::prepare('DELETE FROM *PREFIX*files_trash WHERE user=? AND id=? AND timestamp=?');
$query->execute(array($user,$filename,$timestamp));
}
return false;
}
-
- /**\r
- * delete file from trash bin permanently\r
+
+ /**
+ * delete file from trash bin permanently
* @param $filename path to the file
- * @param $timestamp of deletion time\r
- * @return size of deleted files\r
- */\r
- public static function delete($filename, $timestamp=null) {\r
- $user = \OCP\User::getUser();\r
+ * @param $timestamp of deletion time
+ * @return size of deleted files
+ */
+ public static function delete($filename, $timestamp=null) {
+ $user = \OCP\User::getUser();
$view = new \OC_FilesystemView('/'.$user);
- $size = 0;\r
-
- if ( ($trashbinSize = \OCP\Config::getAppValue('files_trashbin', 'size')) === null ) {\r
- $trashbinSize = self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_trashbin'));\r
- $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin'));\r
+ $size = 0;
+
+ if ( ($trashbinSize = \OCP\Config::getAppValue('files_trashbin', 'size')) === null ) {
+ $trashbinSize = self::calculateSize(new \OC_FilesystemView('/'. $user.'/files_trashbin'));
+ $trashbinSize += self::calculateSize(new \OC_FilesystemView('/'. $user.'/versions_trashbin'));
}
-\r
- if ( $timestamp ) {\r
- $query = \OC_DB::prepare('DELETE FROM *PREFIX*files_trash WHERE user=? AND id=? AND timestamp=?');\r
- $query->execute(array($user,$filename,$timestamp));\r
+
+ if ( $timestamp ) {
+ $query = \OC_DB::prepare('DELETE FROM *PREFIX*files_trash WHERE user=? AND id=? AND timestamp=?');
+ $query->execute(array($user,$filename,$timestamp));
$file = $filename.'.d'.$timestamp;
} else {
$file = $filename;
}
-
+
if ( \OCP\App::isEnabled('files_versions') ) {
if ($view->is_dir('versions_trashbin/'.$file)) {
$size += self::calculateSize(new \OC_Filesystemview('/'.$user.'/versions_trashbin/'.$file));
}
}
}
- }\r
-
+ }
+
if ($view->is_dir('/files_trashbin/'.$file)) {
$size += self::calculateSize(new \OC_Filesystemview('/'.$user.'/files_trashbin/'.$file));
} else {
$view->unlink('/files_trashbin/'.$file);
$trashbinSize -= $size;
\OCP\Config::setAppValue('files_trashbin', 'size', $trashbinSize);
- \r
- return $size;\r
+
+ return $size;
}
/**
return $view->file_exists($target);
}
- /**\r
+ /**
* clean up the trash bin
- * @param max. available disk space for trashbin\r
- */\r
+ * @param max. available disk space for trashbin
+ */
private static function expire($availableSpace) {
-
+
$user = \OCP\User::getUser();
$view = new \OC_FilesystemView('/'.$user);
$size = 0;
-
- $query = \OC_DB::prepare('SELECT location,type,id,timestamp FROM *PREFIX*files_trash WHERE user=?');\r
+
+ $query = \OC_DB::prepare('SELECT location,type,id,timestamp FROM *PREFIX*files_trash WHERE user=?');
$result = $query->execute(array($user))->fetchAll();
-
+
$retention_obligation = \OC_Config::getValue('trashbin_retention_obligation',
self::DEFAULT_RETENTION_OBLIGATION);
-
+
$limit = time() - ($retention_obligation * 86400);
foreach ( $result as $r ) {
foreach ($versions as $v) {
$size += $view->filesize('versions_trashbin/'.$filename.'.v'.$v.'.d'.$timestamp);
$view->unlink('versions_trashbin/'.$filename.'.v'.$v.'.d'.$timestamp);
- }
+ }
}
}
}
-
- $query = \OC_DB::prepare('DELETE FROM *PREFIX*files_trash WHERE user=? AND timestamp<?');\r
+
+ $query = \OC_DB::prepare('DELETE FROM *PREFIX*files_trash WHERE user=? AND timestamp<?');
$query->execute(array($user,$limit));
-
+
$availableSpace = $availableSpace + $size;
// if size limit for trash bin reached, delete oldest files in trash bin
if ($availableSpace < 0) {
$size += $tmp;
$i++;
}
-
+
}
-
- return $size;\r
+
+ return $size;
}
-
+
/**
* recursive copy to copy a whole directory
- *
+ *
* @param $source source path, relative to the users files directory
* @param $destination destination path relative to the users root directoy
* @param $view file view for the users root directory
}
return $size;
}
-
+
/**
* find all versions which belong to the file we want to restore
* @param $filename name of the file which should be restored
*/
private static function getVersionsFromTrash($filename, $timestamp) {
$view = new \OC_FilesystemView('/'.\OCP\User::getUser().'/versions_trashbin');
- $versionsName = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath($filename);\r
+ $versionsName = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath($filename);
$versions = array();
if ($timestamp ) {
// fetch for old versions
$offset = -strlen($timestamp)-2;
} else {
$matches = glob( $versionsName.'.v*' );
- }\r
- \r
+ }
+
foreach( $matches as $ma ) {
if ( $timestamp ) {
- $parts = explode( '.v', substr($ma, 0, $offset) );\r
+ $parts = explode( '.v', substr($ma, 0, $offset) );
$versions[] = ( end( $parts ) );
} else {
- $parts = explode( '.v', $ma );\r
+ $parts = explode( '.v', $ma );
$versions[] = ( end( $parts ) );
}
}
return $versions;
}
-
+
/**
* find unique extension for restored file if a file with the same name already exists
* @param $location where the file should be restored
* @return string with unique extension
*/
private static function getUniqueExtension($location, $filename, $view) {
- $ext = '';\r
- if ( $view->file_exists('files'.$location.'/'.$filename) ) {\r
- $tmpext = '.restored';\r
- $ext = $tmpext;\r
- $i = 1;\r
- while ( $view->file_exists('files'.$location.'/'.$filename.$ext) ) {\r
- $ext = $tmpext.$i;\r
- $i++;\r
- }\r
+ $ext = '';
+ if ( $view->file_exists('files'.$location.'/'.$filename) ) {
+ $tmpext = '.restored';
+ $ext = $tmpext;
+ $i = 1;
+ while ( $view->file_exists('files'.$location.'/'.$filename.$ext) ) {
+ $ext = $tmpext.$i;
+ $i++;
+ }
}
return $ext;
}
- /**\r
+ /**
* @brief get the size from a given root folder
- * @param $view file view on the root folder\r
- * @return size of the folder\r
- */\r
- private static function calculateSize($view) {\r
- $root = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath('');\r
+ * @param $view file view on the root folder
+ * @return size of the folder
+ */
+ private static function calculateSize($view) {
+ $root = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath('');
if (!file_exists($root)) {
return 0;
}
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($root),
- \RecursiveIteratorIterator::CHILD_FIRST);\r
- $size = 0;\r
- \r
+ \RecursiveIteratorIterator::CHILD_FIRST);
+ $size = 0;
+
foreach ($iterator as $path) {
$relpath = substr($path, strlen($root)-1);
if ( !$view->is_dir($relpath) ) {
$size += $view->filesize($relpath);
- }\r
- }\r
- return $size;\r
+ }
+ }
+ return $size;
}
-
-}\r
+
+}
</td>
</tr>
<?php endforeach;
-
\ No newline at end of file
$l = OC_L10N::get('files_versions');
OCP\JSON::error(array("data" => array( "message" => $l->t("Could not revert: %s", array($file) ))));
}
-
} else {
$(html).appendTo($('thead .share'));
}
-
+
$("#makelink").click(function() {
- goToVersionPage(historyUrl);
+ goToVersionPage(historyUrl);
});
$.ajax({
if($path<>'') {
Storage::delete($path);
}
-
+
}
}
if($oldpath<>'' && $newpath<>'') {
Storage::rename( $oldpath, $newpath );
}
-
+
}
}
-
+
}
const DEFAULTENABLED=true;
const DEFAULTMAXSIZE=50; // unit: percentage; 50% of available disk space/quota
-
+
private static $max_versions_per_interval = array(
//first 10sec, one version every 2sec
1 => array('intervalEndsAfter' => 10, 'step' => 2),
}
return array($uid, $filename);
}
-
+
/**
* store a new version of a file.
*/
public static function store($filename) {
if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
list($uid, $filename) = self::getUidAndFilename($filename);
-
+
$files_view = new \OC\Files\View('/'.$uid .'/files');
$users_view = new \OC\Files\View('/'.$uid);
$versionsSize = self::calculateSize($uid);
}
$versionsSize += $users_view->filesize('files'.$filename);
-
+
// expire old revisions if necessary
$newSize = self::expire($filename, $versionsSize);
-
+
if ( $newSize != $versionsSize ) {
\OCP\Config::setAppValue('files_versions', 'size', $versionsSize);
}
public static function delete($filename) {
list($uid, $filename) = self::getUidAndFilename($filename);
$versions_fileview = new \OC\Files\View('/'.$uid .'/files_versions');
-
+
$abs_path = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath('').$filename.'.v';
if( ($versions = self::getVersions($uid, $filename)) ) {
if ( ($versionsSize = \OCP\Config::getAppValue('files_versions', 'size')) === null ) {
\OCP\Config::setAppValue('files_versions', 'size', $versionsSize);
}
}
-
+
/**
* rename versions of a file
*/
$versions_view = new \OC\Files\View('/'.$uid .'/files_versions');
$files_view = new \OC\Files\View('/'.$uid .'/files');
$abs_newpath = \OCP\Config::getSystemValue('datadirectory').$versions_view->getAbsolutePath('').$newpath;
-
+
if ( $files_view->is_dir($oldpath) && $versions_view->is_dir($oldpath) ) {
$versions_view->rename($oldpath, $newpath);
} else if ( ($versions = Storage::getVersions($uid, $oldpath)) ) {
}
}
}
-
+
/**
* rollback to an old version of a file.
*/
list($uid, $filename) = self::getUidAndFilename($filename);
$users_view = new \OC\Files\View('/'.$uid);
$versionCreated = false;
-
+
//first create a new version
$version = 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename);
if ( !$users_view->file_exists($version)) {
$users_view->copy('files'.$filename, 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename));
$versionCreated = true;
}
-
+
// rollback
if( @$users_view->copy('files_versions'.$filename.'.v'.$revision, 'files'.$filename) ) {
$users_view->touch('files'.$filename, $revision);
$versions = array();
// fetch for old versions
$matches = glob( $versionsName.'.v*' );
-
+
if ( !$matches ) {
return $versions;
}
if( \OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' ) {
$versions_fileview = new \OC\Files\View('/'.$uid.'/files_versions');
$versionsRoot = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath('');
-
+
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($versionsRoot),
\RecursiveIteratorIterator::CHILD_FIRST
);
-
+
$size = 0;
-
+
foreach ($iterator as $path) {
if ( preg_match('/^.+\.v(\d+)$/', $path, $match) ) {
$relpath = substr($path, strlen($versionsRoot)-1);
$size += $versions_fileview->filesize($relpath);
}
}
-
+
return $size;
}
}
-
+
/**
* @brief returns all stored file versions from a given user
* @param $uid id to the user
if( \OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' ) {
$versions_fileview = new \OC\Files\View('/'.$uid.'/files_versions');
$versionsRoot = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath('');
-
+
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($versionsRoot),
\RecursiveIteratorIterator::CHILD_FIRST
);
-
+
$versions = array();
-
+
foreach ($iterator as $path) {
if ( preg_match('/^.+\.v(\d+)$/', $path, $match) ) {
$relpath = substr($path, strlen($versionsRoot)-1);
$versions[$match[1].'#'.$relpath] = array('path' => $relpath, 'timestamp' => $match[1]);
}
}
-
+
ksort($versions);
-
+
$i = 0;
-
+
$result = array();
-
+
foreach( $versions as $key => $value ) {
$i++;
$size = $versions_fileview->filesize($value['path']);
$result['all'][$key]['version'] = $value['timestamp'];
$result['all'][$key]['path'] = $filename;
$result['all'][$key]['size'] = $size;
-
+
$filename = substr($value['path'], 0, -strlen($value['timestamp'])-2);
$result['by_file'][$filename][$key]['version'] = $value['timestamp'];
$result['by_file'][$filename][$key]['path'] = $filename;
$result['by_file'][$filename][$key]['size'] = $size;
-
+
}
-
+
return $result;
}
}
*/
private static function expire($filename, $versionsSize = null) {
if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
- list($uid, $filename) = self::getUidAndFilename($filename);
+ list($uid, $filename) = self::getUidAndFilename($filename);
$versions_fileview = new \OC\Files\View('/'.$uid.'/files_versions');
-
+
// get available disk space for user
$quota = \OCP\Util::computerFileSize(\OC_Preferences::getValue($uid, 'files', 'quota'));
if ( $quota == null ) {
if ( $quota == null ) {
$quota = \OC\Files\Filesystem::free_space('/');
}
-
+
// make sure that we have the current size of the version history
if ( $versionsSize === null ) {
if ( ($versionsSize = \OCP\Config::getAppValue('files_versions', 'size')) === null ) {
$availableSpace = ($free * self::DEFAULTMAXSIZE / 100) - $versionsSize; // how much space can be used for versions
} else {
$availableSpace = $free-$versionsSize;
- }
+ }
- // after every 1000s run reduce the number of all versions not only for the current file
+ // after every 1000s run reduce the number of all versions not only for the current file
$random = rand(0, 1000);
if ($random == 0) {
$result = Storage::getAllVersions($uid);
$all_versions = Storage::getVersions($uid, $filename);
$versions_by_file[$filename] = $all_versions;
}
-
+
$time = time();
-
+
// it is possible to expire versions from more than one file
// iterate through all given files
foreach ($versions_by_file as $filename => $versions) {
$versions = array_reverse($versions); // newest version first
-
+
$interval = 1;
- $step = Storage::$max_versions_per_interval[$interval]['step'];
+ $step = Storage::$max_versions_per_interval[$interval]['step'];
if (Storage::$max_versions_per_interval[$interval]['intervalEndsAfter'] == -1) {
$nextInterval = -1;
} else {
$nextInterval = $time - Storage::$max_versions_per_interval[$interval]['intervalEndsAfter'];
}
-
+
$firstVersion = reset($versions);
$firstKey = key($versions);
$prevTimestamp = $firstVersion['version'];
$nextVersion = $firstVersion['version'] - $step;
$remaining_versions[$firstKey] = $firstVersion;
unset($versions[$firstKey]);
-
+
foreach ($versions as $key => $version) {
$newInterval = true;
while ( $newInterval ) {
$prevTimestamp = $version['version'];
}
}
-
+
// check if enough space is available after versions are rearranged.
// if not we delete the oldest versions until we meet the size limit for versions
$numOfVersions = count($all_versions);
- $i = 0;
+ $i = 0;
while ($availableSpace < 0) {
if ($i = $numOfVersions-2) break; // keep at least the last version
$versions_fileview->unlink($all_versions[$i]['path'].'.v'.$all_versions[$i]['version']);
$availableSpace += $all_versions[$i]['size'];
$i++;
}
-
+
return $versionsSize; // finally return the new size of the version history
}
-
+
return false;
}
}
if($_POST) {
// CSRF check
OCP\JSON::callCheck();
-
+
if(isset($_POST['webdav_url'])) {
OC_CONFIG::setValue('user_webdavauth_url', strip_tags($_POST['webdav_url']));
}
}
} else {
$newPath = $this->path . '/' . $name;
-
+
// mark file as partial while uploading (ignored by the scanner)
$partpath = $newPath . '.part';
-
+
\OC\Files\Filesystem::file_put_contents($partpath, $data);
-
+
//detect aborted upload
if (isset ($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT' ) {
if (isset($_SERVER['CONTENT_LENGTH'])) {
}
}
}
-
+
// rename to correct path
\OC\Files\Filesystem::rename($partpath, $newPath);
-
+
// allow sync clients to send the mtime along in a header
$mtime = OC_Request::hasModificationTime();
if ($mtime !== false) {
header('X-OC-MTime: accepted');
}
}
-
+
return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath);
}
// mark file as partial while uploading (ignored by the scanner)
$partpath = $this->path . '.part';
-
+
\OC\Files\Filesystem::file_put_contents($partpath, $data);
-
+
//detect aborted upload
if (isset ($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT' ) {
if (isset($_SERVER['CONTENT_LENGTH'])) {
}
}
}
-
+
// rename to correct path
\OC\Files\Filesystem::rename($partpath, $this->path);
-
+
//allow sync clients to send the mtime along in a header
$mtime = OC_Request::hasModificationTime();
if ($mtime !== false) {
$this->cacheHasItems = false;
return false;
}
-
+
if ($result === false || property_exists($result, 'error_message_prefix')) {
$this->cacheHasItems = false;
return false;
- }
-
+ }
+
$this->cacheHasItems = (bool)$result->fetchRow();
return $this->cacheHasItems;
}
$root = \OC_User::getHome($user);
self::mount('\OC\Files\Storage\Local', array('datadir' => $root), $user);
-
+
// Load system mount points
if (is_file(\OC::$SERVERROOT . '/config/mount.php') or is_file(\OC::$SERVERROOT . '/config/mount.json')) {
if (is_file(\OC::$SERVERROOT . '/config/mount.json')) {
return uniqid();
}
}
-
+
/**
* clean a path, i.e. remove all redundant '.' and '..'
* making sure that it can't point to higher than '/'
if (strlen($path) == 0 or $path[0] != '/') {
$path = '/' . $path;
}
-
+
$output = array();
foreach (explode('/', $path) as $chunk) {
if ($chunk == '..') {
}
return $users;
}
-
- /**\r
- * @brief get a list of all display names in a group\r
- * @returns array with display names (value) and user ids(key)\r
- */\r
- public static function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) {\r
- $displayNames=array();\r
- foreach(self::$_usedBackends as $backend) {\r
- $displayNames = array_merge($backend->displayNamesInGroup($gid, $search, $limit, $offset), $displayNames);\r
- }\r
- return $displayNames;\r
+
+ /**
+ * @brief get a list of all display names in a group
+ * @returns array with display names (value) and user ids(key)
+ */
+ public static function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) {
+ $displayNames=array();
+ foreach(self::$_usedBackends as $backend) {
+ $displayNames = array_merge($backend->displayNamesInGroup($gid, $search, $limit, $offset), $displayNames);
+ }
+ return $displayNames;
}
-
- /**\r
- * @brief get a list of all display names in several groups\r
- * @param array $gids\r
- * @param string $search\r
- * @param int $limit\r
- * @param int $offset\r
- * @return array with display names (Key) user ids (value)\r
- */\r
- public static function displayNamesInGroups($gids, $search = '', $limit = -1, $offset = 0) {\r
+
+ /**
+ * @brief get a list of all display names in several groups
+ * @param array $gids
+ * @param string $search
+ * @param int $limit
+ * @param int $offset
+ * @return array with display names (Key) user ids (value)
+ */
+ public static function displayNamesInGroups($gids, $search = '', $limit = -1, $offset = 0) {
$displayNames = array();
- foreach ($gids as $gid) {\r
- // TODO Need to apply limits to groups as total\r
+ foreach ($gids as $gid) {
+ // TODO Need to apply limits to groups as total
$diff = array_diff(
self::displayNamesInGroup($gid, $search, $limit, $offset),
$displayNames
if ($diff) {
$displayNames = array_merge($diff, $displayNames);
}
- }\r
- return $displayNames;\r
+ }
+ return $displayNames;
}
}
public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
return array();
}
-
- /**\r
- * @brief get a list of all display names in a group\r
- * @param string $gid\r
- * @param string $search\r
- * @param int $limit\r
- * @param int $offset\r
- * @return array with display names (value) and user ids (key)\r
- */\r
- public function DisplayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) {\r
- $displayNames = '';\r
- $users = $this->usersInGroup($gid, $search, $limit, $offset);\r
- foreach ( $users as $user ) {\r
- $DisplayNames[$user] = $user;\r
- }\r
- \r
- return $DisplayNames;\r
+
+ /**
+ * @brief get a list of all display names in a group
+ * @param string $gid
+ * @param string $search
+ * @param int $limit
+ * @param int $offset
+ * @return array with display names (value) and user ids (key)
+ */
+ public function DisplayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) {
+ $displayNames = '';
+ $users = $this->usersInGroup($gid, $search, $limit, $offset);
+ foreach ( $users as $user ) {
+ $DisplayNames[$user] = $user;
+ }
+
+ return $DisplayNames;
}
}
}
return $users;
}
-
- /**\r
- * @brief get a list of all display names in a group\r
- * @param string $gid\r
- * @param string $search\r
- * @param int $limit\r
- * @param int $offset\r
- * @return array with display names (value) and user ids (key)\r
- */\r
- public function DisplayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) {\r
+
+ /**
+ * @brief get a list of all display names in a group
+ * @param string $gid
+ * @param string $search
+ * @param int $limit
+ * @param int $offset
+ * @return array with display names (value) and user ids (key)
+ */
+ public function DisplayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) {
$displayNames = '';
$stmt = OC_DB::prepare('SELECT `*PREFIX*users`.`uid`, `*PREFIX*users`.`displayname`'
.' WHERE `gid` = ? AND `*PREFIX*group_user`.`uid` LIKE ?',
$limit,
$offset);
- $result = $stmt->execute(array($gid, $search.'%'));\r
- $users = array();\r
+ $result = $stmt->execute(array($gid, $search.'%'));
+ $users = array();
while ($row = $result->fetchRow()) {
- $displayName = trim($row['displayname'], ' ');\r
- $displayNames[$row['uid']] = empty($displayName) ? $row['uid'] : $displayName;\r
- } \r
- return $displayNames;\r
+ $displayName = trim($row['displayname'], ' ');
+ $displayNames[$row['uid']] = empty($displayName) ? $row['uid'] : $displayName;
+ }
+ return $displayNames;
}
}
* TODO: write example
*/
static public function connect( $signalclass, $signalname, $slotclass, $slotname ) {
- // If we're trying to connect to an emitting class that isn't
+ // If we're trying to connect to an emitting class that isn't
// yet registered, register it
if( !array_key_exists( $signalclass, self::$registered )) {
self::$registered[$signalclass] = array();
}
- // If we're trying to connect to an emitting method that isn't
+ // If we're trying to connect to an emitting method that isn't
// yet registered, register it with the emitting class
- if( !array_key_exists( $signalname, self::$registered[$signalclass] )) {
+ if( !array_key_exists( $signalname, self::$registered[$signalclass] )) {
self::$registered[$signalclass][$signalname] = array();
}
-
+
// Connect the hook handler to the requested emitter
self::$registered[$signalclass][$signalname][] = array(
"class" => $slotclass,
"name" => $slotname
);
-
+
// No chance for failure ;-)
return true;
}
* TODO: write example
*/
static public function emit( $signalclass, $signalname, $params = array()) {
-
+
// Return false if no hook handlers are listening to this
// emitting class
if( !array_key_exists( $signalclass, self::$registered )) {
return false;
}
-
+
// Return false if no hook handlers are listening to this
// emitting method
if( !array_key_exists( $signalname, self::$registered[$signalclass] )) {
return false;
}
-
+
// Call all slots
foreach( self::$registered[$signalclass][$signalname] as $i ) {
try {
imagealphablending($process, false);
imagesavealpha($process, true);
}
-
+
imagecopyresampled($process, $this->resource, 0, 0, $x, $y, $targetWidth, $targetHeight, $width, $height);
if ($process == false) {
OC_Log::write('core',
'itemSource' => $itemSource,
'shareType' => $shareType,
'shareWith' => $shareWith,
- ));
+ ));
self::delete($item['id']);
return true;
}
'itemType' => $itemType,
'itemSource' => $itemSource,
'shares' => $shares
- ));
+ ));
foreach ($shares as $share) {
self::delete($share['id']);
}
if ( isset($row['uid_owner']) && $row['uid_owner'] != '') {
$row['displayname_owner'] = \OCP\User::getDisplayName($row['uid_owner']);
}
-
+
$items[$row['id']] = $row;
}
if (!empty($items)) {
public static function getUsers($search = '', $limit = null, $offset = null) {
return \OC_USER::getUsers();
}
-
- /**\r
- * @brief get the user display name of the user currently logged in.\r
- * @return string display name\r
- */\r
- public static function getDisplayName($user=null) {\r
- return \OC_USER::getDisplayName($user);\r
+
+ /**
+ * @brief get the user display name of the user currently logged in.
+ * @return string display name
+ */
+ public static function getDisplayName($user=null) {
+ return \OC_USER::getDisplayName($user);
}
-
- /**\r
- * @brief Get a list of all display names\r
- * @returns array with all display names (value) and the correspondig uids (key)\r
- *\r
- * Get a list of all display names and user ids.\r
- */\r
- public static function getDisplayNames($search = '', $limit = null, $offset = null) {\r
- return \OC_USER::getDisplayNames($search, $limit, $offset);\r
+
+ /**
+ * @brief Get a list of all display names
+ * @returns array with all display names (value) and the correspondig uids (key)
+ *
+ * Get a list of all display names and user ids.
+ */
+ public static function getDisplayNames($search = '', $limit = null, $offset = null) {
+ return \OC_USER::getDisplayNames($search, $limit, $offset);
}
-
+
/**
* @brief Check if the user is logged in
* @returns true/false
return 'gzip';
return false;
}
-
+
/**
* @brief Check if the requester sent along an mtime
* @returns false or an mtime
}
return $results;
}
-
+
/**
* remove an existing search provider
* @param string $provider class name of a OC_Search_Provider
*/
public static function removeProvider($provider) {
self::$registeredProviders = array_filter(
- self::$registeredProviders,
+ self::$registeredProviders,
function ($element) use ($provider) {
return ($element['class'] != $provider);
}
$error[] = array(
'error' => $e->getMessage(),
'hint' => $e->getHint()
- );
+ );
return($error);
} catch (Exception $e) {
$error[] = array(
OC_Appconfig::setValue('core', 'lastupdatedat', microtime(true));
OC_AppConfig::setValue('core', 'remote_core.css', '/core/minimizer.php');
OC_AppConfig::setValue('core', 'remote_core.js', '/core/minimizer.php');
-
+
OC_Group::createGroup('admin');
OC_Group::addToGroup($username, 'admin');
OC_User::login($username, $password);
$query = "CREATE USER '$name'@'%' IDENTIFIED BY '$password'";
$result = mysql_query($query, $connection);
if (!$result) {
- throw new DatabaseSetupException($l->t("MySQL user '%s'@'%%' already exists", array($name)),
+ throw new DatabaseSetupException($l->t("MySQL user '%s'@'%%' already exists", array($name)),
$l->t("Drop this user from MySQL."));
}
}
$result = oci_execute($stmt);
if(!$result) {
$entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />';
- $entry .= $l->t('Offending command was: "%s", name: %s, password: %s',
+ $entry .= $l->t('Offending command was: "%s", name: %s, password: %s',
array($query, $name, $password)) . '<br />';
echo($entry);
}
$result = oci_execute($stmt);
if(!$result) {
$entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />';
- $entry .= $l->t('Offending command was: "%s", name: %s, password: %s',
+ $entry .= $l->t('Offending command was: "%s", name: %s, password: %s',
array($query, $name, $password)) . '<br />';
echo($entry);
}
}
return false;
}
-
+
/**
* @brief Check whether user can change his display name
* @param $uid The username
public function getHome($uid) {
return false;
}
-
+
/**
* @brief get display name of the user
* @param $uid user ID of the user
public function getDisplayName($uid) {
return $uid;
}
-
+
/**
* @brief Get a list of all display names
* @returns array with all displayNames (value) and the corresponding uids (key)
return false;
}
}
-
+
/**
* @brief Set display name
* @param $uid The username
}
}
}
-
+
/**
* @brief Get a list of all display names
* @returns array with all displayNames (value) and the correspondig uids (key)
while ($row = $result->fetchRow()) {
$displayNames[$row['uid']] = $row['displayname'];
}
-
+
// let's see if we can also find some users who don't have a display name yet
$query = OC_DB::prepare('SELECT `uid`, `displayname` FROM `*PREFIX*users`'
.' WHERE LOWER(`uid`) LIKE LOWER(?)', $limit, $offset);
$displayNames[$row['uid']] = $row['uid'];
}
}
-
-
+
+
return $displayNames;
}
-
+
/**
* @brief Check if the password is correct
* @param $uid The username
-<?php\r
-// Check if we are a user\r
-\r
-OCP\JSON::callCheck();\r
-OC_JSON::checkLoggedIn();\r
-\r
-$username = isset($_POST["username"]) ? $_POST["username"] : OC_User::getUser();\r
-$displayName = $_POST["displayName"];\r
-\r
-$userstatus = null;\r
-if(OC_User::isAdminUser(OC_User::getUser())) {\r
- $userstatus = 'admin';\r
-}\r
-if(OC_SubAdmin::isUserAccessible(OC_User::getUser(), $username)) {\r
- $userstatus = 'subadmin';\r
-}\r
-\r
-if ($username == OC_User::getUser() && OC_User::canUserChangeDisplayName($username)) {\r
- $userstatus = 'changeOwnDisplayName';\r
-}\r
-\r
-if(is_null($userstatus)) {\r
- OC_JSON::error( array( "data" => array( "message" => $l->t("Authentication error") )));\r
- exit();\r
-}\r
-\r
-// Return Success story\r
-if( OC_User::setDisplayName( $username, $displayName )) {\r
- OC_JSON::success(array("data" => array( "username" => $username, 'displayName' => $displayName )));\r
-}\r
-else{\r
+<?php
+// Check if we are a user
+
+OCP\JSON::callCheck();
+OC_JSON::checkLoggedIn();
+
+$username = isset($_POST["username"]) ? $_POST["username"] : OC_User::getUser();
+$displayName = $_POST["displayName"];
+
+$userstatus = null;
+if(OC_User::isAdminUser(OC_User::getUser())) {
+ $userstatus = 'admin';
+}
+if(OC_SubAdmin::isUserAccessible(OC_User::getUser(), $username)) {
+ $userstatus = 'subadmin';
+}
+
+if ($username == OC_User::getUser() && OC_User::canUserChangeDisplayName($username)) {
+ $userstatus = 'changeOwnDisplayName';
+}
+
+if(is_null($userstatus)) {
+ OC_JSON::error( array( "data" => array( "message" => $l->t("Authentication error") )));
+ exit();
+}
+
+// Return Success story
+if( OC_User::setDisplayName( $username, $displayName )) {
+ OC_JSON::success(array("data" => array( "username" => $username, 'displayName' => $displayName )));
+}
+else{
OC_JSON::error(array("data" => array( "message" => $l->t("Unable to change display name"), 'displayName' => OC_User::getDisplayName($username) )));
}
->actionInclude('settings/ajax/removegroup.php');
$this->create('settings_ajax_changepassword', '/settings/ajax/changepassword.php')
->actionInclude('settings/ajax/changepassword.php');
-$this->create('settings_ajax_changedisplayname', '/settings/ajax/changedisplayname.php')\r
+$this->create('settings_ajax_changedisplayname', '/settings/ajax/changedisplayname.php')
->actionInclude('settings/ajax/changedisplayname.php');
// personel
$this->create('settings_ajax_lostpassword', '/settings/ajax/lostpassword.php')