From 398b52e4f01fe6402ca8c0b9502940acbb676c2d Mon Sep 17 00:00:00 2001 From: Sam Tuke Date: Tue, 11 Dec 2012 17:24:25 +0000 Subject: [PATCH] Improved formatting of getPublicKeys() --- apps/files_encryption/lib/keymanager.php | 43 ++++++++++++++++++++---- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php index 35adf9b67d1..d3be166add2 100755 --- a/apps/files_encryption/lib/keymanager.php +++ b/apps/files_encryption/lib/keymanager.php @@ -82,19 +82,37 @@ class Keymanager { * @param string path to file * @return array of public keys for the given file */ - public static function getPublicKeys($path) { + public static function getPublicKeys( $path ) { + $userId = \OCP\User::getUser(); + $path = ltrim( $path, '/' ); + $filepath = '/'.$userId.'/files/'.$path; // Check if sharing is enabled if ( OC_App::isEnabled( 'files_sharing' ) ) { // // Check if file was shared with other users -// $query = \OC_DB::prepare( "SELECT uid_owner, source, target, uid_shared_with FROM `*PREFIX*sharing` WHERE ( target = ? AND uid_shared_with = ? ) OR source = ? " ); -// $result = $query->execute( array ($filepath, $userId, $filepath)); +// $query = \OC_DB::prepare( " +// SELECT +// uid_owner +// , source +// , target +// , uid_shared_with +// FROM +// `*PREFIX*sharing` +// WHERE +// ( target = ? AND uid_shared_with = ? ) +// OR source = ? +// " ); +// +// $result = $query->execute( array ( $filepath, $userId, $filepath ) ); +// // $users = array(); -// if ($row = $result->fetchRow()){ +// +// if ( $row = $result->fetchRow() ) +// { // $source = $row['source']; // $owner = $row['uid_owner']; // $users[] = $owner; @@ -103,23 +121,34 @@ class Keymanager { // $result = $query->execute( array ($source)); // while ( ($row = $result->fetchRow()) ) { // $users[] = $row['uid_shared_with']; +// // } +// // } } else { + // check if it is a file owned by the user and not shared at all $userview = new \OC_FilesystemView( '/'.$userId.'/files/' ); - if ($userview->file_exists($path)) { + + if ( $userview->file_exists( $path ) ) { + $users[] = $userId; + } + } $view = new \OC_FilesystemView( '/public-keys/' ); $keylist = array(); + $count = 0; - foreach ($users as $user) { - $keylist['key'.++$count] = $view->file_get_contents($user.'.public.key'); + + foreach ( $users as $user ) { + + $keylist['key'.++$count] = $view->file_get_contents( $user.'.public.key' ); + } return $keylist;