aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/app.php4
-rw-r--r--lib/private/appconfig.php4
-rw-r--r--lib/private/appframework/app.php2
-rw-r--r--lib/private/appframework/core/api.php4
-rw-r--r--lib/private/appframework/db/db.php57
-rw-r--r--lib/private/appframework/dependencyinjection/dicontainer.php32
-rw-r--r--lib/private/appframework/http.php4
-rw-r--r--lib/private/appframework/http/dispatcher.php89
-rw-r--r--lib/private/appframework/http/request.php2
-rw-r--r--lib/private/appframework/middleware/middlewaredispatcher.php2
-rw-r--r--lib/private/appframework/middleware/security/corsmiddleware.php75
-rw-r--r--lib/private/appframework/middleware/security/securityexception.php2
-rw-r--r--lib/private/appframework/middleware/security/securitymiddleware.php23
-rw-r--r--lib/private/appframework/routing/routeconfig.php12
-rw-r--r--lib/private/appframework/utility/controllermethodreflector.php (renamed from lib/private/appframework/utility/methodannotationreader.php)57
-rw-r--r--lib/private/appframework/utility/simplecontainer.php3
-rw-r--r--lib/private/appframework/utility/timefactory.php2
-rw-r--r--lib/private/archive/tar.php2
-rw-r--r--lib/private/avatar.php6
-rw-r--r--lib/private/avatarmanager.php2
-rw-r--r--lib/private/backgroundjob/joblist.php8
-rw-r--r--lib/private/cache/file.php2
-rw-r--r--lib/private/config.php8
-rw-r--r--lib/private/connector/sabre/auth.php2
-rw-r--r--lib/private/connector/sabre/exceptionloggerplugin.php17
-rw-r--r--lib/private/connector/sabre/file.php2
-rw-r--r--lib/private/connector/sabre/filesplugin.php2
-rw-r--r--lib/private/connector/sabre/quotaplugin.php2
-rw-r--r--lib/private/contactsmanager.php4
-rw-r--r--lib/private/db.php2
-rw-r--r--lib/private/db/connectionwrapper.php4
-rw-r--r--lib/private/db/mdb2schemamanager.php2
-rw-r--r--lib/private/db/mdb2schemareader.php4
-rw-r--r--lib/private/db/statementwrapper.php2
-rw-r--r--lib/private/defaults.php2
-rw-r--r--lib/private/fileproxy.php2
-rw-r--r--lib/private/files.php11
-rw-r--r--lib/private/files/cache/cache.php12
-rw-r--r--lib/private/files/cache/scanner.php8
-rw-r--r--lib/private/files/cache/updater.php2
-rw-r--r--lib/private/files/cache/watcher.php2
-rw-r--r--lib/private/files/fileinfo.php2
-rw-r--r--lib/private/files/filesystem.php6
-rw-r--r--lib/private/files/mapper.php4
-rw-r--r--lib/private/files/mount/manager.php6
-rw-r--r--lib/private/files/mount/mount.php2
-rw-r--r--lib/private/files/node/folder.php2
-rw-r--r--lib/private/files/storage/common.php4
-rw-r--r--lib/private/files/storage/local.php11
-rw-r--r--lib/private/files/storage/mappedlocal.php11
-rw-r--r--lib/private/files/storage/wrapper/quota.php2
-rw-r--r--lib/private/files/stream/oc.php8
-rw-r--r--lib/private/files/type/templatemanager.php2
-rw-r--r--lib/private/files/view.php19
-rw-r--r--lib/private/geo.php4
-rw-r--r--lib/private/group.php26
-rw-r--r--lib/private/group/backend.php30
-rw-r--r--lib/private/group/database.php36
-rw-r--r--lib/private/group/dummy.php53
-rw-r--r--lib/private/group/example.php48
-rw-r--r--lib/private/group/group.php10
-rw-r--r--lib/private/group/interface.php6
-rw-r--r--lib/private/group/manager.php76
-rw-r--r--lib/private/helper.php76
-rw-r--r--lib/private/hook.php2
-rw-r--r--lib/private/image.php2
-rw-r--r--lib/private/installer.php4
-rw-r--r--lib/private/l10n.php49
-rw-r--r--lib/private/l10n/factory.php4
-rw-r--r--lib/private/legacy/appconfig.php4
-rw-r--r--lib/private/legacy/cache.php10
-rw-r--r--lib/private/legacy/cache/fileglobalgc.php4
-rw-r--r--lib/private/legacy/config.php2
-rw-r--r--lib/private/legacy/filesystem.php415
-rw-r--r--lib/private/legacy/filesystemview.php9
-rw-r--r--lib/private/legacy/preferences.php4
-rw-r--r--lib/private/log.php39
-rw-r--r--lib/private/memcache/memcached.php2
-rw-r--r--lib/private/migrate.php6
-rw-r--r--lib/private/migration/content.php16
-rw-r--r--lib/private/navigationmanager.php2
-rw-r--r--lib/private/ocs.php4
-rw-r--r--lib/private/ocs/cloud.php4
-rw-r--r--lib/private/ocs/result.php6
-rw-r--r--lib/private/ocsclient.php14
-rw-r--r--lib/private/preferences.php4
-rwxr-xr-xlib/private/preview.php72
-rw-r--r--lib/private/preview/image.php12
-rw-r--r--lib/private/preview/mp3.php2
-rw-r--r--lib/private/preview/pdf.php1
-rw-r--r--lib/private/preview/provider.php1
-rw-r--r--lib/private/preview/svg.php3
-rwxr-xr-xlib/private/request.php10
-rw-r--r--lib/private/response.php38
-rw-r--r--lib/private/route/route.php2
-rw-r--r--lib/private/route/router.php4
-rw-r--r--lib/private/server.php52
-rw-r--r--lib/private/share/helper.php27
-rw-r--r--lib/private/share/hooks.php10
-rw-r--r--lib/private/share/mailnotifications.php29
-rw-r--r--lib/private/share/searchresultsorter.php4
-rw-r--r--lib/private/share/share.php362
-rw-r--r--lib/private/subadmin.php4
-rw-r--r--lib/private/tags.php55
-rw-r--r--lib/private/template.php4
-rw-r--r--lib/private/template/functions.php4
-rw-r--r--lib/private/template/resourcelocator.php10
-rw-r--r--lib/private/templatelayout.php10
-rw-r--r--lib/private/updater.php2
-rw-r--r--lib/private/urlgenerator.php2
-rw-r--r--lib/private/user.php10
-rw-r--r--lib/private/user/backend.php4
-rw-r--r--lib/private/user/database.php42
-rw-r--r--lib/private/user/dummy.php2
-rw-r--r--lib/private/user/example.php22
-rw-r--r--lib/private/user/http.php10
-rw-r--r--lib/private/user/interface.php18
-rw-r--r--lib/private/user/manager.php16
-rw-r--r--lib/private/user/session.php6
-rw-r--r--lib/private/user/user.php18
-rwxr-xr-xlib/private/util.php72
-rw-r--r--lib/private/vobject.php70
122 files changed, 1387 insertions, 1157 deletions
diff --git a/lib/private/app.php b/lib/private/app.php
index 2f55b54b328..a35248f2552 100644
--- a/lib/private/app.php
+++ b/lib/private/app.php
@@ -307,7 +307,7 @@ class OC_App{
/**
* @brief Get the navigation entries for the $app
* @param string $app app
- * @return array of the $data added with addNavigationEntry
+ * @return array an array of the $data added with addNavigationEntry
*
* Warning: destroys the existing entries
*/
@@ -660,7 +660,7 @@ class OC_App{
/**
* @brief: get a list of all apps in the apps folder
- * @return array or app names (string IDs)
+ * @return array an array of app names (string IDs)
* @todo: change the name of this method to getInstalledApps, which is more accurate
*/
public static function getAllApps() {
diff --git a/lib/private/appconfig.php b/lib/private/appconfig.php
index 0cd6b3bc35b..5fba7514de0 100644
--- a/lib/private/appconfig.php
+++ b/lib/private/appconfig.php
@@ -90,7 +90,7 @@ class AppConfig implements \OCP\IAppConfig {
/**
* @brief Get all apps using the config
- * @return array with app ids
+ * @return array an array of app ids
*
* This function returns a list of all apps that have at least one
* entry in the appconfig table.
@@ -109,7 +109,7 @@ class AppConfig implements \OCP\IAppConfig {
/**
* @brief Get the available keys for an app
* @param string $app the app we are looking for
- * @return array with key names
+ * @return array an array of key names
*
* This function gets all keys of an app. Please note that the values are
* not returned.
diff --git a/lib/private/appframework/app.php b/lib/private/appframework/app.php
index 3b13194862d..baf52d02054 100644
--- a/lib/private/appframework/app.php
+++ b/lib/private/appframework/app.php
@@ -4,7 +4,7 @@
* ownCloud - App Framework
*
* @author Bernhard Posselt
- * @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+ * @copyright 2012 Bernhard Posselt <dev@bernhard-posselt.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
diff --git a/lib/private/appframework/core/api.php b/lib/private/appframework/core/api.php
index e7269373bb0..5f2035389b7 100644
--- a/lib/private/appframework/core/api.php
+++ b/lib/private/appframework/core/api.php
@@ -4,7 +4,7 @@
* ownCloud - App Framework
*
* @author Bernhard Posselt
- * @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+ * @copyright 2012 Bernhard Posselt <dev@bernhard-posselt.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@@ -136,7 +136,7 @@ class API implements IApi{
* @brief Emits a signal. To get data from the slot use references!
* @param string $signalClass class name of emitter
* @param string $signalName name of signal
- * @param array $params defautl: array() array with additional data
+ * @param array $params default: array() array with additional data
* @return bool, true if slots exists or false if not
*/
public function emitHook($signalClass, $signalName, $params = array()) {
diff --git a/lib/private/appframework/db/db.php b/lib/private/appframework/db/db.php
new file mode 100644
index 00000000000..fc77a38f814
--- /dev/null
+++ b/lib/private/appframework/db/db.php
@@ -0,0 +1,57 @@
+<?php
+
+/**
+ * ownCloud - App Framework
+ *
+ * @author Bernhard Posselt
+ * @copyright 2012 Bernhard Posselt dev@bernhard-posselt.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 OC\AppFramework\Db;
+
+use \OCP\IDb;
+
+
+/**
+ * Small Facade for being able to inject the database connection for tests
+ */
+class Db implements IDb {
+
+
+ /**
+ * Used to abstract the owncloud database access away
+ * @param string $sql the sql query with ? placeholder for params
+ * @param int $limit the maximum number of rows
+ * @param int $offset from which row we want to start
+ * @return \OC_DB_StatementWrapper prepared SQL query
+ */
+ public function prepareQuery($sql, $limit=null, $offset=null){
+ return \OCP\DB::prepare($sql, $limit, $offset);
+ }
+
+
+ /**
+ * Used to get the id of the just inserted element
+ * @param string $tableName the name of the table where we inserted the item
+ * @return int the id of the inserted element
+ */
+ public function getInsertId($tableName){
+ return \OCP\DB::insertid($tableName);
+ }
+
+
+}
diff --git a/lib/private/appframework/dependencyinjection/dicontainer.php b/lib/private/appframework/dependencyinjection/dicontainer.php
index e478225a53d..ee492b8a9e5 100644
--- a/lib/private/appframework/dependencyinjection/dicontainer.php
+++ b/lib/private/appframework/dependencyinjection/dicontainer.php
@@ -4,7 +4,7 @@
* ownCloud - App Framework
*
* @author Bernhard Posselt
- * @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+ * @copyright 2012 Bernhard Posselt <dev@bernhard-posselt.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@@ -30,8 +30,10 @@ use OC\AppFramework\Http\Dispatcher;
use OC\AppFramework\Core\API;
use OC\AppFramework\Middleware\MiddlewareDispatcher;
use OC\AppFramework\Middleware\Security\SecurityMiddleware;
+use OC\AppFramework\Middleware\Security\CORSMiddleware;
use OC\AppFramework\Utility\SimpleContainer;
use OC\AppFramework\Utility\TimeFactory;
+use OC\AppFramework\Utility\ControllerMethodReflector;
use OCP\AppFramework\IApi;
use OCP\AppFramework\IAppContainer;
use OCP\AppFramework\Middleware;
@@ -80,7 +82,12 @@ class DIContainer extends SimpleContainer implements IAppContainer{
});
$this['Dispatcher'] = $this->share(function($c) {
- return new Dispatcher($c['Protocol'], $c['MiddlewareDispatcher']);
+ return new Dispatcher(
+ $c['Protocol'],
+ $c['MiddlewareDispatcher'],
+ $c['ControllerMethodReflector'],
+ $c['Request']
+ );
});
@@ -89,13 +96,25 @@ class DIContainer extends SimpleContainer implements IAppContainer{
*/
$app = $this;
$this['SecurityMiddleware'] = $this->share(function($c) use ($app){
- return new SecurityMiddleware($app, $c['Request']);
+ return new SecurityMiddleware(
+ $app,
+ $c['Request'],
+ $c['ControllerMethodReflector']
+ );
+ });
+
+ $this['CORSMiddleware'] = $this->share(function($c) {
+ return new CORSMiddleware(
+ $c['Request'],
+ $c['ControllerMethodReflector']
+ );
});
$middleWares = &$this->middleWares;
$this['MiddlewareDispatcher'] = $this->share(function($c) use (&$middleWares) {
$dispatcher = new MiddlewareDispatcher();
$dispatcher->registerMiddleware($c['SecurityMiddleware']);
+ $dispatcher->registerMiddleware($c['CORSMiddleware']);
foreach($middleWares as $middleWare) {
$dispatcher->registerMiddleware($c[$middleWare]);
@@ -112,6 +131,9 @@ class DIContainer extends SimpleContainer implements IAppContainer{
return new TimeFactory();
});
+ $this['ControllerMethodReflector'] = $this->share(function($c) {
+ return new ControllerMethodReflector();
+ });
}
@@ -168,8 +190,8 @@ class DIContainer extends SimpleContainer implements IAppContainer{
}
/**
- * @param $message
- * @param $level
+ * @param string $message
+ * @param string $level
* @return mixed
*/
function log($message, $level) {
diff --git a/lib/private/appframework/http.php b/lib/private/appframework/http.php
index 65d926105f1..2b1387af715 100644
--- a/lib/private/appframework/http.php
+++ b/lib/private/appframework/http.php
@@ -4,7 +4,7 @@
* ownCloud - App Framework
*
* @author Bernhard Posselt, Thomas Tanghus, Bart Visscher
- * @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+ * @copyright 2012 Bernhard Posselt <dev@bernhard-posselt.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@@ -33,7 +33,7 @@ class Http extends BaseHttp {
protected $headers;
/**
- * @param $_SERVER $server
+ * @param array $server $_SERVER
* @param string $protocolVersion the http version to use defaults to HTTP/1.1
*/
public function __construct($server, $protocolVersion='HTTP/1.1') {
diff --git a/lib/private/appframework/http/dispatcher.php b/lib/private/appframework/http/dispatcher.php
index a2afb53f0fa..442e33ee726 100644
--- a/lib/private/appframework/http/dispatcher.php
+++ b/lib/private/appframework/http/dispatcher.php
@@ -4,7 +4,7 @@
* ownCloud - App Framework
*
* @author Bernhard Posselt, Thomas Tanghus, Bart Visscher
- * @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+ * @copyright 2012 Bernhard Posselt <dev@bernhard-posselt.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@@ -26,7 +26,11 @@ namespace OC\AppFramework\Http;
use \OC\AppFramework\Middleware\MiddlewareDispatcher;
use \OC\AppFramework\Http;
+use \OC\AppFramework\Utility\ControllerMethodReflector;
+
use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http\Response;
+use OCP\IRequest;
/**
@@ -36,17 +40,25 @@ class Dispatcher {
private $middlewareDispatcher;
private $protocol;
-
+ private $reflector;
+ private $request;
/**
* @param Http $protocol the http protocol with contains all status headers
* @param MiddlewareDispatcher $middlewareDispatcher the dispatcher which
* runs the middleware
+ * @param ControllerMethodReflector the reflector that is used to inject
+ * the arguments for the controller
+ * @param IRequest $request the incoming request
*/
public function __construct(Http $protocol,
- MiddlewareDispatcher $middlewareDispatcher) {
+ MiddlewareDispatcher $middlewareDispatcher,
+ ControllerMethodReflector $reflector,
+ IRequest $request) {
$this->protocol = $protocol;
$this->middlewareDispatcher = $middlewareDispatcher;
+ $this->reflector = $reflector;
+ $this->request = $request;
}
@@ -63,10 +75,13 @@ class Dispatcher {
$out = array(null, array(), null);
try {
+ // prefill reflector with everything thats needed for the
+ // middlewares
+ $this->reflector->reflect($controller, $methodName);
$this->middlewareDispatcher->beforeController($controller,
$methodName);
- $response = $controller->$methodName();
+ $response = $this->executeController($controller, $methodName);
// if an exception appears, the middleware checks if it can handle the
// exception and creates a response. If no response is created, it is
@@ -98,4 +113,70 @@ class Dispatcher {
}
+ /**
+ * Uses the reflected parameters, types and request parameters to execute
+ * the controller
+ * @param Controller $controller the controller to be executed
+ * @param string $methodName the method on the controller that should be executed
+ * @return Response
+ */
+ private function executeController($controller, $methodName) {
+ $arguments = array();
+
+ // valid types that will be casted
+ $types = array('int', 'integer', 'bool', 'boolean', 'float');
+
+ foreach($this->reflector->getParameters() as $param => $default) {
+
+ // try to get the parameter from the request object and cast
+ // it to the type annotated in the @param annotation
+ $value = $this->request->getParam($param, $default);
+ $type = $this->reflector->getType($param);
+
+ // if this is submitted using GET or a POST form, 'false' should be
+ // converted to false
+ if(($type === 'bool' || $type === 'boolean') &&
+ $value === 'false' &&
+ (
+ $this->request->method === 'GET' ||
+ strpos($this->request->getHeader('Content-Type'),
+ 'application/x-www-form-urlencoded') !== false
+ )
+ ) {
+ $value = false;
+
+ } elseif(in_array($type, $types)) {
+ settype($value, $type);
+ }
+
+ $arguments[] = $value;
+ }
+
+ $response = call_user_func_array(array($controller, $methodName), $arguments);
+
+ // format response if not of type response
+ if(!($response instanceof Response)) {
+
+ // get format from the url format or request format parameter
+ $format = $this->request->getParam('format');
+
+ // if none is given try the first Accept header
+ if($format === null) {
+ $header = $this->request->getHeader('Accept');
+ $formats = explode(',', $header);
+
+ if($header !== null && count($formats) > 0) {
+ $accept = strtolower(trim($formats[0]));
+ $format = str_replace('application/', '', $accept);
+ } else {
+ $format = 'json';
+ }
+ }
+
+ $response = $controller->buildResponse($response, $format);
+ }
+
+ return $response;
+ }
+
}
diff --git a/lib/private/appframework/http/request.php b/lib/private/appframework/http/request.php
index 643fa685adc..8b68ca486ff 100644
--- a/lib/private/appframework/http/request.php
+++ b/lib/private/appframework/http/request.php
@@ -3,7 +3,9 @@
* ownCloud - Request
*
* @author Thomas Tanghus
+ * @author Bernhard Posselt
* @copyright 2013 Thomas Tanghus (thomas@tanghus.net)
+ * @copyright 2014 Bernhard Posselt <dev@bernhard-posselt.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
diff --git a/lib/private/appframework/middleware/middlewaredispatcher.php b/lib/private/appframework/middleware/middlewaredispatcher.php
index 598743e523f..dcb63a8e552 100644
--- a/lib/private/appframework/middleware/middlewaredispatcher.php
+++ b/lib/private/appframework/middleware/middlewaredispatcher.php
@@ -4,7 +4,7 @@
* ownCloud - App Framework
*
* @author Bernhard Posselt
- * @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+ * @copyright 2012 Bernhard Posselt <dev@bernhard-posselt.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
diff --git a/lib/private/appframework/middleware/security/corsmiddleware.php b/lib/private/appframework/middleware/security/corsmiddleware.php
new file mode 100644
index 00000000000..dca3996ea2e
--- /dev/null
+++ b/lib/private/appframework/middleware/security/corsmiddleware.php
@@ -0,0 +1,75 @@
+<?php
+/**
+ * ownCloud - App Framework
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright Bernhard Posselt 2014
+ */
+
+namespace OC\AppFramework\Middleware\Security;
+
+use OC\AppFramework\Utility\ControllerMethodReflector;
+use OCP\IRequest;
+use OCP\AppFramework\Http\Response;
+use OCP\AppFramework\Middleware;
+
+/**
+ * This middleware sets the correct CORS headers on a response if the
+ * controller has the @CORS annotation. This is needed for webapps that want
+ * to access an API and dont run on the same domain, see
+ * https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
+ */
+class CORSMiddleware extends Middleware {
+
+ private $request;
+ private $reflector;
+
+ /**
+ * @param IRequest $request
+ * @param ControllerMethodReflector $reflector
+ */
+ public function __construct(IRequest $request,
+ ControllerMethodReflector $reflector) {
+ $this->request = $request;
+ $this->reflector = $reflector;
+ }
+
+
+ /**
+ * This is being run after a successful controllermethod call and allows
+ * the manipulation of a Response object. The middleware is run in reverse order
+ *
+ * @param Controller $controller the controller that is being called
+ * @param string $methodName the name of the method that will be called on
+ * the controller
+ * @param Response $response the generated response from the controller
+ * @return Response a Response object
+ */
+ public function afterController($controller, $methodName, Response $response){
+ // only react if its a CORS request and if the request sends origin and
+
+ if(isset($this->request->server['HTTP_ORIGIN']) &&
+ $this->reflector->hasAnnotation('CORS')) {
+
+ // allow credentials headers must not be true or CSRF is possible
+ // otherwise
+ foreach($response->getHeaders() as $header => $value ) {
+ if(strtolower($header) === 'access-control-allow-credentials' &&
+ strtolower(trim($value)) === 'true') {
+ $msg = 'Access-Control-Allow-Credentials must not be '.
+ 'set to true in order to prevent CSRF';
+ throw new SecurityException($msg);
+ }
+ }
+
+ $origin = $this->request->server['HTTP_ORIGIN'];
+ $response->addHeader('Access-Control-Allow-Origin', $origin);
+ }
+ return $response;
+ }
+
+
+}
diff --git a/lib/private/appframework/middleware/security/securityexception.php b/lib/private/appframework/middleware/security/securityexception.php
index e551675acdf..df37d5e3275 100644
--- a/lib/private/appframework/middleware/security/securityexception.php
+++ b/lib/private/appframework/middleware/security/securityexception.php
@@ -4,7 +4,7 @@
* ownCloud - App Framework
*
* @author Bernhard Posselt
- * @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+ * @copyright 2012 Bernhard Posselt <dev@bernhard-posselt.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
diff --git a/lib/private/appframework/middleware/security/securitymiddleware.php b/lib/private/appframework/middleware/security/securitymiddleware.php
index 0f160d224ad..d7e398fe445 100644
--- a/lib/private/appframework/middleware/security/securitymiddleware.php
+++ b/lib/private/appframework/middleware/security/securitymiddleware.php
@@ -4,7 +4,7 @@
* ownCloud - App Framework
*
* @author Bernhard Posselt
- * @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+ * @copyright 2012 Bernhard Posselt <dev@bernhard-posselt.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@@ -25,7 +25,7 @@
namespace OC\AppFramework\Middleware\Security;
use OC\AppFramework\Http;
-use OC\AppFramework\Utility\MethodAnnotationReader;
+use OC\AppFramework\Utility\ControllerMethodReflector;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Middleware;
use OCP\AppFramework\Http\Response;
@@ -53,12 +53,20 @@ class SecurityMiddleware extends Middleware {
private $request;
/**
+ * @var OC\AppFramework\Utility\ControllerMethodReflector
+ */
+ private $reflector;
+
+ /**
* @param IAppContainer $app
* @param IRequest $request
+ * @param ControllerMethodReflector $reflector
*/
- public function __construct(IAppContainer $app, IRequest $request){
+ public function __construct(IAppContainer $app, IRequest $request,
+ ControllerMethodReflector $reflector){
$this->app = $app;
$this->request = $request;
+ $this->reflector = $reflector;
}
@@ -72,28 +80,25 @@ class SecurityMiddleware extends Middleware {
*/
public function beforeController($controller, $methodName){
- // get annotations from comments
- $annotationReader = new MethodAnnotationReader($controller, $methodName);
-
// this will set the current navigation entry of the app, use this only
// for normal HTML requests and not for AJAX requests
$this->app->getServer()->getNavigationManager()->setActiveEntry($this->app->getAppName());
// security checks
- $isPublicPage = $annotationReader->hasAnnotation('PublicPage');
+ $isPublicPage = $this->reflector->hasAnnotation('PublicPage');
if(!$isPublicPage) {
if(!$this->app->isLoggedIn()) {
throw new SecurityException('Current user is not logged in', Http::STATUS_UNAUTHORIZED);
}
- if(!$annotationReader->hasAnnotation('NoAdminRequired')) {
+ if(!$this->reflector->hasAnnotation('NoAdminRequired')) {
if(!$this->app->isAdminUser()) {
throw new SecurityException('Logged in user must be an admin', Http::STATUS_FORBIDDEN);
}
}
}
- if(!$annotationReader->hasAnnotation('NoCSRFRequired')) {
+ if(!$this->reflector->hasAnnotation('NoCSRFRequired')) {
if(!$this->request->passesCSRFCheck()) {
throw new SecurityException('CSRF check failed', Http::STATUS_PRECONDITION_FAILED);
}
diff --git a/lib/private/appframework/routing/routeconfig.php b/lib/private/appframework/routing/routeconfig.php
index a3bbde6af53..91ea7778d08 100644
--- a/lib/private/appframework/routing/routeconfig.php
+++ b/lib/private/appframework/routing/routeconfig.php
@@ -61,7 +61,7 @@ class RouteConfig {
/**
* Creates one route base on the give configuration
- * @param $routes
+ * @param array $routes
* @throws \UnexpectedValueException
*/
private function processSimpleRoutes($routes)
@@ -105,7 +105,7 @@ class RouteConfig {
* - update
* - destroy
*
- * @param $routes
+ * @param array $routes
*/
private function processResources($routes)
{
@@ -151,7 +151,7 @@ class RouteConfig {
/**
* Based on a given route name the controller name is generated
- * @param $controller
+ * @param string $controller
* @return string
*/
private function buildControllerName($controller)
@@ -161,7 +161,7 @@ class RouteConfig {
/**
* Based on the action part of the route name the controller method name is generated
- * @param $action
+ * @param string $action
* @return string
*/
private function buildActionName($action) {
@@ -170,7 +170,7 @@ class RouteConfig {
/**
* Generates the id used in the url part o the route url
- * @param $resource
+ * @param string $resource
* @return string
*/
private function buildResourceId($resource) {
@@ -179,7 +179,7 @@ class RouteConfig {
/**
* Underscored strings are converted to camel case strings
- * @param $str string
+ * @param string $str
* @return string
*/
private function underScoreToCamelCase($str) {
diff --git a/lib/private/appframework/utility/methodannotationreader.php b/lib/private/appframework/utility/controllermethodreflector.php
index 42060a08529..a1519c72809 100644
--- a/lib/private/appframework/utility/methodannotationreader.php
+++ b/lib/private/appframework/utility/controllermethodreflector.php
@@ -4,7 +4,7 @@
* ownCloud - App Framework
*
* @author Bernhard Posselt
- * @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+ * @copyright 2014 Bernhard Posselt <dev@bernhard-posselt.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@@ -28,23 +28,68 @@ namespace OC\AppFramework\Utility;
/**
* Reads and parses annotations from doc comments
*/
-class MethodAnnotationReader {
+class ControllerMethodReflector {
private $annotations;
+ private $types;
+ private $parameters;
+
+ public function __construct() {
+ $this->types = array();
+ $this->parameters = array();
+ $this->annotations = array();
+ }
+
/**
* @param object $object an object or classname
- * @param string $method the method which we want to inspect for annotations
+ * @param string $method the method which we want to inspect
*/
- public function __construct($object, $method){
- $this->annotations = array();
-
+ public function reflect($object, $method){
$reflection = new \ReflectionMethod($object, $method);
$docs = $reflection->getDocComment();
// extract everything prefixed by @ and first letter uppercase
preg_match_all('/@([A-Z]\w+)/', $docs, $matches);
$this->annotations = $matches[1];
+
+ // extract type parameter information
+ preg_match_all('/@param (?<type>\w+) \$(?<var>\w+)/', $docs, $matches);
+ $this->types = array_combine($matches['var'], $matches['type']);
+
+ // get method parameters
+ foreach ($reflection->getParameters() as $param) {
+ if($param->isOptional()) {
+ $default = $param->getDefaultValue();
+ } else {
+ $default = null;
+ }
+ $this->parameters[$param->name] = $default;
+ }
+ }
+
+
+ /**
+ * Inspects the PHPDoc parameters for types
+ * @param string $parameter the parameter whose type comments should be
+ * parsed
+ * @return string|null type in the type parameters (@param int $something)
+ * would return int or null if not existing
+ */
+ public function getType($parameter) {
+ if(array_key_exists($parameter, $this->types)) {
+ return $this->types[$parameter];
+ } else {
+ return null;
+ }
+ }
+
+
+ /**
+ * @return array the arguments of the method with key => default value
+ */
+ public function getParameters() {
+ return $this->parameters;
}
diff --git a/lib/private/appframework/utility/simplecontainer.php b/lib/private/appframework/utility/simplecontainer.php
index d08a4879e34..1ad06b9ab23 100644
--- a/lib/private/appframework/utility/simplecontainer.php
+++ b/lib/private/appframework/utility/simplecontainer.php
@@ -2,9 +2,6 @@
namespace OC\AppFramework\Utility;
-// register 3rdparty autoloaders
-require_once 'Pimple/Pimple.php';
-
/**
* Class SimpleContainer
*
diff --git a/lib/private/appframework/utility/timefactory.php b/lib/private/appframework/utility/timefactory.php
index 2c3dd6cf5e3..a9b07a356e3 100644
--- a/lib/private/appframework/utility/timefactory.php
+++ b/lib/private/appframework/utility/timefactory.php
@@ -4,7 +4,7 @@
* ownCloud - App Framework
*
* @author Bernhard Posselt
- * @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+ * @copyright 2012 Bernhard Posselt <dev@bernhard-posselt.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
diff --git a/lib/private/archive/tar.php b/lib/private/archive/tar.php
index cbdb565ba35..21a995d9e50 100644
--- a/lib/private/archive/tar.php
+++ b/lib/private/archive/tar.php
@@ -154,7 +154,7 @@ class OC_Archive_TAR extends OC_Archive{
}
/**
* get the last modified time of a file in the archive
- * @param string path
+ * @param string $path
* @return int
*/
function mtime($path) {
diff --git a/lib/private/avatar.php b/lib/private/avatar.php
index e97f55eecaf..45959798476 100644
--- a/lib/private/avatar.php
+++ b/lib/private/avatar.php
@@ -16,7 +16,7 @@ class OC_Avatar implements \OCP\IAvatar {
/**
* @brief constructor
- * @param $user string user to do avatar-management with
+ * @param string $user user to do avatar-management with
*/
public function __construct ($user) {
$this->view = new \OC\Files\View('/'.$user);
@@ -24,7 +24,7 @@ class OC_Avatar implements \OCP\IAvatar {
/**
* @brief get the users avatar
- * @param $size integer size in px of the avatar, avatars are square, defaults to 64
+ * @param int $size size in px of the avatar, avatars are square, defaults to 64
* @return boolean|\OC_Image containing the avatar or false if there's no image
*/
public function get ($size = 64) {
@@ -44,7 +44,7 @@ class OC_Avatar implements \OCP\IAvatar {
/**
* @brief sets the users avatar
- * @param $data mixed OC_Image, imagedata or path to set a new avatar
+ * @param \OC_Image|resource|string $data OC_Image, imagedata or path to set a new avatar
* @throws Exception if the provided file is not a jpg or png image
* @throws Exception if the provided image is not valid
* @throws \OC\NotSquareException if the image is not square
diff --git a/lib/private/avatarmanager.php b/lib/private/avatarmanager.php
index 3ca46868ea6..f462e6ac5fd 100644
--- a/lib/private/avatarmanager.php
+++ b/lib/private/avatarmanager.php
@@ -17,7 +17,7 @@ class AvatarManager implements IAvatarManager {
/**
* @brief return a user specific instance of \OCP\IAvatar
* @see \OCP\IAvatar
- * @param $user string the ownCloud user id
+ * @param string $user the ownCloud user id
* @return \OCP\IAvatar
*/
function getAvatar($user) {
diff --git a/lib/private/backgroundjob/joblist.php b/lib/private/backgroundjob/joblist.php
index 26c90269349..9fa13c25851 100644
--- a/lib/private/backgroundjob/joblist.php
+++ b/lib/private/backgroundjob/joblist.php
@@ -31,7 +31,7 @@ class JobList implements IJobList {
}
/**
- * @param \Test\BackgroundJob\TestJob $job
+ * @param Job|string $job
* @param mixed $argument
*/
public function add($job, $argument = null) {
@@ -48,7 +48,7 @@ class JobList implements IJobList {
}
/**
- * @param Job $job
+ * @param Job|string $job
* @param mixed $argument
*/
public function remove($job, $argument = null) {
@@ -70,7 +70,7 @@ class JobList implements IJobList {
/**
* check if a job is in the list
*
- * @param $job
+ * @param Job|string $job
* @param mixed $argument
* @return bool
*/
@@ -126,7 +126,7 @@ class JobList implements IJobList {
/**
* @param int $id
- * @return Job
+ * @return Job|null
*/
public function getById($id) {
$query = $this->conn->prepare('SELECT `id`, `class`, `last_run`, `argument` FROM `*PREFIX*jobs` WHERE `id` = ?');
diff --git a/lib/private/cache/file.php b/lib/private/cache/file.php
index feee9cc32b6..4e7c065678e 100644
--- a/lib/private/cache/file.php
+++ b/lib/private/cache/file.php
@@ -48,7 +48,7 @@ class File {
/**
* Returns the size of the stored/cached data
*
- * @param $key
+ * @param string $key
* @return int
*/
public function size($key) {
diff --git a/lib/private/config.php b/lib/private/config.php
index 6701ca0532b..4242682af3d 100644
--- a/lib/private/config.php
+++ b/lib/private/config.php
@@ -65,7 +65,7 @@ class Config {
/**
* @brief Lists all available config keys
- * @return array with key names
+ * @return array an array of key names
*
* This function returns all keys saved in config.php. Please note that it
* does not return the values.
@@ -77,8 +77,8 @@ class Config {
/**
* @brief Gets a value from config.php
* @param string $key key
- * @param array|bool|string|null $default = null default value
- * @return string the value or $default
+ * @param mixed $default = null default value
+ * @return mixed the value or $default
*
* This function gets the value from config.php. If it does not exist,
* $default will be returned.
@@ -94,7 +94,7 @@ class Config {
/**
* @brief Sets a value
* @param string $key key
- * @param string $value value
+ * @param mixed $value value
*
* This function sets the value and writes the config.php.
*
diff --git a/lib/private/connector/sabre/auth.php b/lib/private/connector/sabre/auth.php
index 5577273df8c..9ebf5fc05cf 100644
--- a/lib/private/connector/sabre/auth.php
+++ b/lib/private/connector/sabre/auth.php
@@ -69,6 +69,8 @@ class OC_Connector_Sabre_Auth extends Sabre_DAV_Auth_Backend_AbstractBasic {
* even if there are no HTTP Basic Auth headers.
* In other case, just fallback to the parent implementation.
*
+ * @param Sabre_DAV_Server $server
+ * @param $realm
* @return bool
*/
public function authenticate(Sabre_DAV_Server $server, $realm) {
diff --git a/lib/private/connector/sabre/exceptionloggerplugin.php b/lib/private/connector/sabre/exceptionloggerplugin.php
index 8e77afaf207..5eaf1e87621 100644
--- a/lib/private/connector/sabre/exceptionloggerplugin.php
+++ b/lib/private/connector/sabre/exceptionloggerplugin.php
@@ -11,6 +11,17 @@
class OC_Connector_Sabre_ExceptionLoggerPlugin extends Sabre_DAV_ServerPlugin
{
+ private $nonFatalExceptions = array(
+ 'Sabre_DAV_Exception_NotAuthenticated' => true,
+ // the sync client uses this to find out whether files exist,
+ // so it is not always an error, log it as debug
+ 'Sabre_DAV_Exception_NotFound' => true,
+ // this one mostly happens when the same file is uploaded at
+ // exactly the same time from two clients, only one client
+ // wins, the second one gets "Precondition failed"
+ 'Sabre_DAV_Exception_PreconditionFailed' => true,
+ );
+
private $appName;
/**
@@ -43,8 +54,10 @@ class OC_Connector_Sabre_ExceptionLoggerPlugin extends Sabre_DAV_ServerPlugin
*/
public function logException($e) {
$exceptionClass = get_class($e);
- if ($exceptionClass !== 'Sabre_DAV_Exception_NotAuthenticated') {
- \OCP\Util::logException($this->appName, $e);
+ $level = \OCP\Util::FATAL;
+ if (isset($this->nonFatalExceptions[$exceptionClass])) {
+ $level = \OCP\Util::DEBUG;
}
+ \OCP\Util::logException($this->appName, $e, $level);
}
}
diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php
index 66b50a87552..ab9d3e47d0e 100644
--- a/lib/private/connector/sabre/file.php
+++ b/lib/private/connector/sabre/file.php
@@ -123,7 +123,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
/**
* Returns the data
*
- * @return string | resource
+ * @return string|resource
*/
public function get() {
diff --git a/lib/private/connector/sabre/filesplugin.php b/lib/private/connector/sabre/filesplugin.php
index 1d8f28008b3..25d7fd53343 100644
--- a/lib/private/connector/sabre/filesplugin.php
+++ b/lib/private/connector/sabre/filesplugin.php
@@ -83,7 +83,7 @@ class OC_Connector_Sabre_FilesPlugin extends Sabre_DAV_ServerPlugin
}
/**
- * @param $filePath
+ * @param string $filePath
* @param Sabre_DAV_INode $node
* @throws Sabre_DAV_Exception_BadRequest
*/
diff --git a/lib/private/connector/sabre/quotaplugin.php b/lib/private/connector/sabre/quotaplugin.php
index 1e73e1645c3..c9b8336b57b 100644
--- a/lib/private/connector/sabre/quotaplugin.php
+++ b/lib/private/connector/sabre/quotaplugin.php
@@ -97,7 +97,7 @@ class OC_Connector_Sabre_QuotaPlugin extends Sabre_DAV_ServerPlugin {
}
/**
- * @param $parentUri
+ * @param string $parentUri
* @return mixed
*/
public function getFreeSpace($parentUri) {
diff --git a/lib/private/contactsmanager.php b/lib/private/contactsmanager.php
index 4299d88017a..26264d4e988 100644
--- a/lib/private/contactsmanager.php
+++ b/lib/private/contactsmanager.php
@@ -31,7 +31,7 @@ namespace OC {
* @param string $pattern which should match within the $searchProperties
* @param array $searchProperties defines the properties within the query pattern should match
* @param array $options - for future use. One should always have options!
- * @return array of contacts which are arrays of key-value-pairs
+ * @return array an array of contacts which are arrays of key-value-pairs
*/
public function search($pattern, $searchProperties = array(), $options = array()) {
$result = array();
@@ -72,7 +72,7 @@ namespace OC {
*
* @param array $properties this array if key-value-pairs defines a contact
* @param string $address_book_key identifier of the address book in which the contact shall be created or updated
- * @return array representing the contact just created or updated
+ * @return array an array representing the contact just created or updated
*/
public function createOrUpdate($properties, $address_book_key) {
diff --git a/lib/private/db.php b/lib/private/db.php
index 322a13642ae..52bf570d1d0 100644
--- a/lib/private/db.php
+++ b/lib/private/db.php
@@ -401,7 +401,7 @@ class OC_DB {
/**
* @brief replaces the ownCloud tables with a new set
- * @param $file string path to the MDB2 xml db export file
+ * @param string $file path to the MDB2 xml db export file
*/
public static function replaceDB( $file ) {
$schemaManager = self::getMDB2SchemaManager();
diff --git a/lib/private/db/connectionwrapper.php b/lib/private/db/connectionwrapper.php
index c2cfc21d204..132e76666ab 100644
--- a/lib/private/db/connectionwrapper.php
+++ b/lib/private/db/connectionwrapper.php
@@ -41,8 +41,8 @@ class ConnectionWrapper implements \OCP\IDBConnection {
/**
* Insert a row if a matching row doesn't exists.
- * @param string The table name (will replace *PREFIX*) to perform the replace on.
- * @param array
+ * @param string $table The table name (will replace *PREFIX*) to perform the replace on.
+ * @param array $input
*
* The input array if in the form:
*
diff --git a/lib/private/db/mdb2schemamanager.php b/lib/private/db/mdb2schemamanager.php
index aaf2ea543b9..d98197445e9 100644
--- a/lib/private/db/mdb2schemamanager.php
+++ b/lib/private/db/mdb2schemamanager.php
@@ -126,7 +126,7 @@ class MDB2SchemaManager {
/**
* @brief replaces the ownCloud tables with a new set
- * @param $file string path to the MDB2 xml db export file
+ * @param string $file path to the MDB2 xml db export file
*/
public function replaceDB( $file ) {
$apps = \OC_App::getAllApps();
diff --git a/lib/private/db/mdb2schemareader.php b/lib/private/db/mdb2schemareader.php
index 1c16d03eab2..597650985fa 100644
--- a/lib/private/db/mdb2schemareader.php
+++ b/lib/private/db/mdb2schemareader.php
@@ -66,7 +66,7 @@ class MDB2SchemaReader {
}
/**
- * @param\Doctrine\DBAL\Schema\Schema $schema
+ * @param \Doctrine\DBAL\Schema\Schema $schema
* @param \SimpleXMLElement $xml
* @throws \DomainException
*/
@@ -303,7 +303,7 @@ class MDB2SchemaReader {
}
/**
- * @param \SimpleXMLElement | string $xml
+ * @param \SimpleXMLElement|string $xml
* @return bool
*/
private function asBool($xml) {
diff --git a/lib/private/db/statementwrapper.php b/lib/private/db/statementwrapper.php
index 492209b883b..70d1f985a41 100644
--- a/lib/private/db/statementwrapper.php
+++ b/lib/private/db/statementwrapper.php
@@ -41,7 +41,7 @@ class OC_DB_StatementWrapper {
* make execute return the result instead of a bool
*
* @param array $input
- * @return \OC_DB_StatementWrapper | int
+ * @return \OC_DB_StatementWrapper|int
*/
public function execute($input=array()) {
if(OC_Config::getValue( "log_query", false)) {
diff --git a/lib/private/defaults.php b/lib/private/defaults.php
index fca798568c5..663c327a3b0 100644
--- a/lib/private/defaults.php
+++ b/lib/private/defaults.php
@@ -185,7 +185,7 @@ class OC_Defaults {
/**
* Returns mail header color
- * @return mail header color
+ * @return string
*/
public function getMailHeaderColor() {
if ($this->themeExist('getMailHeaderColor')) {
diff --git a/lib/private/fileproxy.php b/lib/private/fileproxy.php
index 88976c1b8e5..2835e974642 100644
--- a/lib/private/fileproxy.php
+++ b/lib/private/fileproxy.php
@@ -47,7 +47,7 @@ class OC_FileProxy{
/**
* fallback function when a proxy operation is not implemented
* @param string $function the name of the proxy operation
- * @param mixed
+ * @param mixed $arguments
*
* this implements a dummy proxy for all operations
*/
diff --git a/lib/private/files.php b/lib/private/files.php
index 152595ba697..7c437a16a98 100644
--- a/lib/private/files.php
+++ b/lib/private/files.php
@@ -152,7 +152,7 @@ class OC_Files {
/** @var $storage \OC\Files\Storage\Storage */
list($storage) = $view->resolvePath($filename);
if ($storage->isLocal()) {
- self::addSendfileHeader(\OC\Files\Filesystem::getLocalFile($filename));
+ self::addSendfileHeader($filename);
} else {
\OC\Files\Filesystem::readfile($filename);
}
@@ -167,9 +167,11 @@ class OC_Files {
*/
private static function addSendfileHeader($filename) {
if (isset($_SERVER['MOD_X_SENDFILE_ENABLED'])) {
+ $filename = \OC\Files\Filesystem::getLocalFile($filename);
header("X-Sendfile: " . $filename);
}
if (isset($_SERVER['MOD_X_SENDFILE2_ENABLED'])) {
+ $filename = \OC\Files\Filesystem::getLocalFile($filename);
if (isset($_SERVER['HTTP_RANGE']) &&
preg_match("/^bytes=([0-9]+)-([0-9]*)$/", $_SERVER['HTTP_RANGE'], $range)) {
$filelength = filesize($filename);
@@ -185,6 +187,7 @@ class OC_Files {
}
if (isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])) {
+ $filename = \OC::$WEBROOT . '/data' . \OC\Files\Filesystem::getRoot() . $filename;
header("X-Accel-Redirect: " . $filename);
}
}
@@ -222,7 +225,7 @@ class OC_Files {
* checks if the selected files are within the size constraint. If not, outputs an error page.
*
* @param string $dir
- * @param array | string $files
+ * @param array|string $files
*/
static function validateZipDownload($dir, $files) {
if (!OC_Config::getValue('allowZipDownload', true)) {
@@ -279,9 +282,7 @@ class OC_Files {
return false;
$size -= 1;
} else {
- $size = OC_Helper::humanFileSize($size);
- $size = substr($size, 0, -1); //strip the B
- $size = str_replace(' ', '', $size); //remove the space between the size and the postfix
+ $size = OC_Helper::phpFileSize($size);
}
//don't allow user to break his config -- broken or malicious size input
diff --git a/lib/private/files/cache/cache.php b/lib/private/files/cache/cache.php
index 1c9de56f8c5..3e4f6dfb132 100644
--- a/lib/private/files/cache/cache.php
+++ b/lib/private/files/cache/cache.php
@@ -109,7 +109,7 @@ class Cache {
* get the stored metadata of a file or folder
*
* @param string/int $file
- * @return array | false
+ * @return array|false
*/
public function get($file) {
if (is_string($file) or $file == '') {
@@ -450,7 +450,7 @@ class Cache {
* search for files matching $pattern
*
* @param string $pattern
- * @return array of file data
+ * @return array an array of file data
*/
public function search($pattern) {
@@ -597,12 +597,16 @@ class Cache {
* get the path of a file on this storage by it's id
*
* @param int $id
- * @return string | null
+ * @return string|null
*/
public function getPathById($id) {
$sql = 'SELECT `path` FROM `*PREFIX*filecache` WHERE `fileid` = ? AND `storage` = ?';
$result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId()));
if ($row = $result->fetchRow()) {
+ // Oracle stores empty strings as null...
+ if ($row['path'] === null) {
+ return '';
+ }
return $row['path'];
} else {
return null;
@@ -636,7 +640,7 @@ class Cache {
/**
* normalize the given path
- * @param $path
+ * @param string $path
* @return string
*/
public function normalize($path) {
diff --git a/lib/private/files/cache/scanner.php b/lib/private/files/cache/scanner.php
index c0bdde06a75..51454a71458 100644
--- a/lib/private/files/cache/scanner.php
+++ b/lib/private/files/cache/scanner.php
@@ -61,7 +61,7 @@ class Scanner extends BasicEmitter {
* *
*
* @param string $path
- * @return array with metadata of the file
+ * @return array an array of metadata of the file
*/
public function getData($path) {
if (!$this->storage->isReadable($path)) {
@@ -88,7 +88,7 @@ class Scanner extends BasicEmitter {
* @param string $file
* @param int $reuseExisting
* @param bool $parentExistsInCache
- * @return array with metadata of the scanned file
+ * @return array an array of metadata of the scanned file
*/
public function scanFile($file, $reuseExisting = 0, $parentExistsInCache = false) {
if (!self::isPartialFile($file)
@@ -174,7 +174,7 @@ class Scanner extends BasicEmitter {
* @param string $path
* @param bool $recursive
* @param int $reuse
- * @return array with the meta data of the scanned file or folder
+ * @return array an array of the meta data of the scanned file or folder
*/
public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1) {
if ($reuse === -1) {
@@ -273,7 +273,7 @@ class Scanner extends BasicEmitter {
* @brief check if the file should be ignored when scanning
* NOTE: files with a '.part' extension are ignored as well!
* prevents unfinished put requests to be scanned
- * @param String $file
+ * @param string $file
* @return boolean
*/
public static function isPartialFile($file) {
diff --git a/lib/private/files/cache/updater.php b/lib/private/files/cache/updater.php
index 199ce5dee78..95f77a81fa2 100644
--- a/lib/private/files/cache/updater.php
+++ b/lib/private/files/cache/updater.php
@@ -17,7 +17,7 @@ class Updater {
* resolve a path to a storage and internal path
*
* @param string $path the relative path
- * @return array consisting of the storage and the internal path
+ * @return array an array consisting of the storage and the internal path
*/
static public function resolvePath($path) {
$view = \OC\Files\Filesystem::getView();
diff --git a/lib/private/files/cache/watcher.php b/lib/private/files/cache/watcher.php
index 48aa6f853ce..599752a6eff 100644
--- a/lib/private/files/cache/watcher.php
+++ b/lib/private/files/cache/watcher.php
@@ -55,7 +55,7 @@ class Watcher {
* check $path for updates
*
* @param string $path
- * @return boolean | array true if path was updated, otherwise the cached data is returned
+ * @return boolean|array true if path was updated, otherwise the cached data is returned
*/
public function checkUpdate($path) {
if ($this->watchPolicy === self::CHECK_ALWAYS or ($this->watchPolicy === self::CHECK_ONCE and array_search($path, $this->checkedPaths) === false)) {
diff --git a/lib/private/files/fileinfo.php b/lib/private/files/fileinfo.php
index 357364415fb..e7afeb4ccce 100644
--- a/lib/private/files/fileinfo.php
+++ b/lib/private/files/fileinfo.php
@@ -147,7 +147,7 @@ class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
}
/**
- * @return \OCP\Files\FileInfo::TYPE_FILE | \OCP\Files\FileInfo::TYPE_FOLDER
+ * @return \OCP\Files\FileInfo::TYPE_FILE|\OCP\Files\FileInfo::TYPE_FOLDER
*/
public function getType() {
if (isset($this->data['type'])) {
diff --git a/lib/private/files/filesystem.php b/lib/private/files/filesystem.php
index 52df1bec611..22d15840c32 100644
--- a/lib/private/files/filesystem.php
+++ b/lib/private/files/filesystem.php
@@ -245,7 +245,7 @@ class Filesystem {
}
/**
- * @param $id
+ * @param string $id
* @return Mount\Mount[]
*/
public static function getMountByStorageId($id) {
@@ -256,7 +256,7 @@ class Filesystem {
}
/**
- * @param $id
+ * @param int $id
* @return Mount\Mount[]
*/
public static function getMountByNumericId($id) {
@@ -270,7 +270,7 @@ class Filesystem {
* resolve a path to a storage and internal path
*
* @param string $path
- * @return array consisting of the storage and the internal path
+ * @return array an array consisting of the storage and the internal path
*/
static public function resolvePath($path) {
if (!self::$mounts) {
diff --git a/lib/private/files/mapper.php b/lib/private/files/mapper.php
index 833d4bd8d1c..666719da12d 100644
--- a/lib/private/files/mapper.php
+++ b/lib/private/files/mapper.php
@@ -97,8 +97,8 @@ class Mapper
}
/**
- * @param $path
- * @param $root
+ * @param string $path
+ * @param string $root
* @return false|string
*/
public function stripRootFolder($path, $root) {
diff --git a/lib/private/files/mount/manager.php b/lib/private/files/mount/manager.php
index 91460b72730..db1f4600c74 100644
--- a/lib/private/files/mount/manager.php
+++ b/lib/private/files/mount/manager.php
@@ -33,7 +33,7 @@ class Manager {
/**
* Find the mount for $path
*
- * @param $path
+ * @param string $path
* @return Mount
*/
public function find($path) {
@@ -61,7 +61,7 @@ class Manager {
/**
* Find all mounts in $path
*
- * @param $path
+ * @param string $path
* @return Mount[]
*/
public function findIn($path) {
@@ -112,7 +112,7 @@ class Manager {
/**
* Find mounts by numeric storage id
*
- * @param string $id
+ * @param int $id
* @return Mount[]
*/
public function findByNumericId($id) {
diff --git a/lib/private/files/mount/mount.php b/lib/private/files/mount/mount.php
index 08d5ddf348b..256630726d2 100644
--- a/lib/private/files/mount/mount.php
+++ b/lib/private/files/mount/mount.php
@@ -28,7 +28,7 @@ class Mount {
private $loader;
/**
- * @param string | \OC\Files\Storage\Storage $storage
+ * @param string|\OC\Files\Storage\Storage $storage
* @param string $mountpoint
* @param array $arguments (optional)\
* @param \OC\Files\Storage\Loader $loader
diff --git a/lib/private/files/node/folder.php b/lib/private/files/node/folder.php
index d9e0ddc2d61..1af34fc2be6 100644
--- a/lib/private/files/node/folder.php
+++ b/lib/private/files/node/folder.php
@@ -296,7 +296,7 @@ class Folder extends Node implements \OCP\Files\Folder {
}
/**
- * @param $id
+ * @param int $id
* @return \OC\Files\Node\Node[]
*/
public function getById($id) {
diff --git a/lib/private/files/storage/common.php b/lib/private/files/storage/common.php
index 8a263d4ce1e..fef33cabd87 100644
--- a/lib/private/files/storage/common.php
+++ b/lib/private/files/storage/common.php
@@ -317,7 +317,7 @@ abstract class Common implements \OC\Files\Storage\Storage {
* clean a path, i.e. remove all redundant '.' and '..'
* making sure that it can't point to higher than '/'
*
- * @param $path The path to clean
+ * @param string $path The path to clean
* @return string cleaned path
*/
public function cleanPath($path) {
@@ -347,7 +347,7 @@ abstract class Common implements \OC\Files\Storage\Storage {
/**
* get the free space in the storage
*
- * @param $path
+ * @param string $path
* @return int
*/
public function free_space($path) {
diff --git a/lib/private/files/storage/local.php b/lib/private/files/storage/local.php
index ff2949d33b6..de940fc7cdb 100644
--- a/lib/private/files/storage/local.php
+++ b/lib/private/files/storage/local.php
@@ -44,17 +44,26 @@ if (\OC_Util::runningOnWindows()) {
new \RecursiveDirectoryIterator($this->datadir . $path),
\RecursiveIteratorIterator::CHILD_FIRST
);
- foreach ($it as $file) {
+ /**
+ * RecursiveDirectoryIterator on an NFS path isn't iterable with foreach
+ * This bug is fixed in PHP 5.5.9 or before
+ * See #8376
+ */
+ $it->rewind();
+ while ($it->valid()) {
/**
* @var \SplFileInfo $file
*/
+ $file = $it->current();
if (in_array($file->getBasename(), array('.', '..'))) {
+ $it->next();
continue;
} elseif ($file->isDir()) {
rmdir($file->getPathname());
} elseif ($file->isFile() || $file->isLink()) {
unlink($file->getPathname());
}
+ $it->next();
}
return rmdir($this->datadir . $path);
} catch (\UnexpectedValueException $e) {
diff --git a/lib/private/files/storage/mappedlocal.php b/lib/private/files/storage/mappedlocal.php
index 75582fd6c83..07691661644 100644
--- a/lib/private/files/storage/mappedlocal.php
+++ b/lib/private/files/storage/mappedlocal.php
@@ -39,17 +39,26 @@ class MappedLocal extends \OC\Files\Storage\Common{
new \RecursiveDirectoryIterator($this->buildPath($path)),
\RecursiveIteratorIterator::CHILD_FIRST
);
- foreach ($it as $file) {
+ /**
+ * RecursiveDirectoryIterator on an NFS path isn't iterable with foreach
+ * This bug is fixed in PHP 5.5.9 or before
+ * See #8376
+ */
+ $it->rewind();
+ while ($it->valid()) {
/**
* @var \SplFileInfo $file
*/
+ $file = $it->current();
if (in_array($file->getBasename(), array('.', '..'))) {
+ $it->next();
continue;
} elseif ($file->isDir()) {
rmdir($file->getPathname());
} elseif ($file->isFile() || $file->isLink()) {
unlink($file->getPathname());
}
+ $it->next();
}
if ($result = @rmdir($this->buildPath($path))) {
$this->cleanMapper($path);
diff --git a/lib/private/files/storage/wrapper/quota.php b/lib/private/files/storage/wrapper/quota.php
index a878b2c5cf6..c57c797f87a 100644
--- a/lib/private/files/storage/wrapper/quota.php
+++ b/lib/private/files/storage/wrapper/quota.php
@@ -30,7 +30,7 @@ class Quota extends Wrapper {
}
/**
- * @return quota value
+ * @return int quota value
*/
public function getQuota() {
return $this->quota;
diff --git a/lib/private/files/stream/oc.php b/lib/private/files/stream/oc.php
index 88e7e062df9..c206b41f55e 100644
--- a/lib/private/files/stream/oc.php
+++ b/lib/private/files/stream/oc.php
@@ -18,7 +18,15 @@ class OC {
static private $rootView;
private $path;
+
+ /**
+ * @var resource
+ */
private $dirSource;
+
+ /**
+ * @var resource
+ */
private $fileSource;
private $meta;
diff --git a/lib/private/files/type/templatemanager.php b/lib/private/files/type/templatemanager.php
index cd1536d2732..e693e7079a5 100644
--- a/lib/private/files/type/templatemanager.php
+++ b/lib/private/files/type/templatemanager.php
@@ -19,7 +19,7 @@ class TemplateManager {
* get the path of the template for a mimetype
*
* @param string $mimetype
- * @return string | null
+ * @return string|null
*/
public function getTemplatePath($mimetype) {
if (isset($this->templates[$mimetype])) {
diff --git a/lib/private/files/view.php b/lib/private/files/view.php
index 47fc04c937d..3b99bd12b8a 100644
--- a/lib/private/files/view.php
+++ b/lib/private/files/view.php
@@ -11,7 +11,7 @@
* working with files within that view (e.g. read, write, delete, etc.). Each
* view is restricted to a set of directories via a virtual root. The default view
* uses the currently logged in user's data directory as root (parts of
- * OC_Filesystem are merely a wrapper for OC_FilesystemView).
+ * OC_Filesystem are merely a wrapper for OC\Files\View).
*
* Apps that need to access files outside of the user data folders (to modify files
* belonging to a user other than the one currently logged in, for example) should
@@ -37,7 +37,7 @@ class View {
}
public function getAbsolutePath($path = '/') {
- if (!$path) {
+ if ($path === '') {
$path = '/';
}
if ($path[0] !== '/') {
@@ -109,7 +109,7 @@ class View {
* resolve a path to a storage and internal path
*
* @param string $path
- * @return array consisting of the storage and the internal path
+ * @return array an array consisting of the storage and the internal path
*/
public function resolvePath($path) {
$a = $this->getAbsolutePath($path);
@@ -168,6 +168,10 @@ class View {
}
}
+ /**
+ * @param string $path
+ * @return resource
+ */
public function opendir($path) {
return $this->basicOperation('opendir', $path, array('read'));
}
@@ -552,6 +556,11 @@ class View {
}
}
+ /**
+ * @param string $path
+ * @param string $mode
+ * @return resource
+ */
public function fopen($path, $mode) {
$hooks = array();
switch ($mode) {
@@ -796,7 +805,7 @@ class View {
* @param string $path
* @param boolean $includeMountPoints whether to add mountpoint sizes,
* defaults to true
- * @return \OC\Files\FileInfo | false
+ * @return \OC\Files\FileInfo|false
*/
public function getFileInfo($path, $includeMountPoints = true) {
$data = array();
@@ -991,7 +1000,7 @@ class View {
* change file metadata
*
* @param string $path
- * @param array | \OCP\Files\FileInfo $data
+ * @param array|\OCP\Files\FileInfo $data
* @return int
*
* returns the fileid of the updated file
diff --git a/lib/private/geo.php b/lib/private/geo.php
index cd62511f0c1..a0ad2b799ab 100644
--- a/lib/private/geo.php
+++ b/lib/private/geo.php
@@ -8,8 +8,8 @@
class OC_Geo{
/**
* @brief returns the closest timezone to coordinates
- * @param $latitude
- * @param $longitude
+ * @param float $latitude
+ * @param float $longitude
* @return mixed Closest timezone
*/
public static function timezone($latitude, $longitude) {
diff --git a/lib/private/group.php b/lib/private/group.php
index d9f430f833b..845b3655bab 100644
--- a/lib/private/group.php
+++ b/lib/private/group.php
@@ -58,7 +58,7 @@ class OC_Group {
/**
* @brief set the group backend
- * @param \OC_Group_Backend $backend The backend to use for user managment
+ * @param \OC_Group_Backend $backend The backend to use for user managment
* @return bool
*/
public static function useBackend($backend) {
@@ -179,7 +179,7 @@ class OC_Group {
/**
* @brief Get all groups a user belongs to
* @param string $uid Name of the user
- * @return array with group names
+ * @return array an array of group names
*
* This function fetches all groups a user belongs to. It does not check
* if the user exists at all.
@@ -203,7 +203,7 @@ class OC_Group {
* @param string $search
* @param int|null $limit
* @param int|null $offset
- * @returns array with group names
+ * @return array an array of group names
*
* Returns a list with all groups
*/
@@ -232,7 +232,7 @@ class OC_Group {
* @param string $search
* @param int $limit
* @param int $offset
- * @returns array with user ids
+ * @return array an array of user ids
*/
public static function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
$group = self::getManager()->get($gid);
@@ -254,7 +254,7 @@ class OC_Group {
* @param string $search
* @param int $limit
* @param int $offset
- * @return array with user ids
+ * @return array an array of user ids
*/
public static function usersInGroups($gids, $search = '', $limit = -1, $offset = 0) {
$users = array();
@@ -271,20 +271,10 @@ class OC_Group {
* @param string $search
* @param int $limit
* @param int $offset
- * @returns array with display names (value) and user ids(key)
+ * @return array an array of display names (value) and user ids(key)
*/
public static function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) {
- $group = self::getManager()->get($gid);
- if ($group) {
- $users = $group->searchDisplayName($search, $limit, $offset);
- $displayNames = array();
- foreach ($users as $user) {
- $displayNames[$user->getUID()] = $user->getDisplayName();
- }
- return $displayNames;
- } else {
- return array();
- }
+ return self::getManager()->displayNamesInGroup($gid, $search, $limit, $offset);
}
/**
@@ -293,7 +283,7 @@ class OC_Group {
* @param string $search
* @param int $limit
* @param int $offset
- * @return array with display names (Key) user ids (value)
+ * @return array an array of display names (Key) user ids (value)
*/
public static function displayNamesInGroups($gids, $search = '', $limit = -1, $offset = 0) {
$displayNames = array();
diff --git a/lib/private/group/backend.php b/lib/private/group/backend.php
index b0ed0d90d76..38522d0c43c 100644
--- a/lib/private/group/backend.php
+++ b/lib/private/group/backend.php
@@ -33,7 +33,7 @@ define('OC_GROUP_BACKEND_CREATE_GROUP', 0x00000001);
define('OC_GROUP_BACKEND_DELETE_GROUP', 0x00000010);
define('OC_GROUP_BACKEND_ADD_TO_GROUP', 0x00000100);
define('OC_GROUP_BACKEND_REMOVE_FROM_GOUP', 0x00001000);
-define('OC_GROUP_BACKEND_GET_DISPLAYNAME', 0x00010000);
+define('OC_GROUP_BACKEND_GET_DISPLAYNAME', 0x00010000); //OBSOLETE
define('OC_GROUP_BACKEND_COUNT_USERS', 0x00100000);
/**
@@ -45,7 +45,6 @@ abstract class OC_Group_Backend implements OC_Group_Interface {
OC_GROUP_BACKEND_DELETE_GROUP => 'deleteGroup',
OC_GROUP_BACKEND_ADD_TO_GROUP => 'addToGroup',
OC_GROUP_BACKEND_REMOVE_FROM_GOUP => 'removeFromGroup',
- OC_GROUP_BACKEND_GET_DISPLAYNAME => 'displayNamesInGroup',
OC_GROUP_BACKEND_COUNT_USERS => 'countUsersInGroup',
);
@@ -70,7 +69,7 @@ abstract class OC_Group_Backend implements OC_Group_Interface {
/**
* @brief Check if backend implements actions
* @param int $actions bitwise-or'ed actions
- * @return boolean
+ * @return bool
*
* Returns the supported actions as int to be
* compared with OC_GROUP_BACKEND_CREATE_GROUP etc.
@@ -94,7 +93,7 @@ abstract class OC_Group_Backend implements OC_Group_Interface {
/**
* @brief Get all groups a user belongs to
* @param string $uid Name of the user
- * @return array with group names
+ * @return array an array of group names
*
* This function fetches all groups a user belongs to. It does not check
* if the user exists at all.
@@ -108,7 +107,7 @@ abstract class OC_Group_Backend implements OC_Group_Interface {
* @param string $search
* @param int $limit
* @param int $offset
- * @return array with group names
+ * @return array an array of group names
*
* Returns a list with all groups
*/
@@ -132,28 +131,9 @@ abstract class OC_Group_Backend implements OC_Group_Interface {
* @param string $search
* @param int $limit
* @param int $offset
- * @return array with user ids
+ * @return array an array of user ids
*/
public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
return array();
}
-
- /**
- * @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 = array();
- $users = $this->usersInGroup($gid, $search, $limit, $offset);
- foreach ($users as $user) {
- $displayNames[$user] = $user;
- }
-
- return $displayNames;
- }
-
}
diff --git a/lib/private/group/database.php b/lib/private/group/database.php
index 3815dcff2e5..91baa3140cc 100644
--- a/lib/private/group/database.php
+++ b/lib/private/group/database.php
@@ -140,7 +140,7 @@ class OC_Group_Database extends OC_Group_Backend {
/**
* @brief Get all groups a user belongs to
* @param string $uid Name of the user
- * @return array with group names
+ * @return array an array of group names
*
* This function fetches all groups a user belongs to. It does not check
* if the user exists at all.
@@ -163,7 +163,7 @@ class OC_Group_Database extends OC_Group_Backend {
* @param string $search
* @param int $limit
* @param int $offset
- * @return array with group names
+ * @return array an array of group names
*
* Returns a list with all groups
*/
@@ -197,7 +197,7 @@ class OC_Group_Database extends OC_Group_Backend {
* @param string $search
* @param int $limit
* @param int $offset
- * @return array with user ids
+ * @return array an array of user ids
*/
public function usersInGroup($gid, $search = '', $limit = null, $offset = null) {
$stmt = OC_DB::prepare('SELECT `uid` FROM `*PREFIX*group_user` WHERE `gid` = ? AND `uid` LIKE ?',
@@ -215,9 +215,8 @@ class OC_Group_Database extends OC_Group_Backend {
* @brief get the number of all users matching the search string in a group
* @param string $gid
* @param string $search
- * @param int $limit
- * @param int $offset
- * @return int | false
+ * @return int|false
+ * @throws DatabaseException
*/
public function countUsersInGroup($gid, $search = '') {
$stmt = OC_DB::prepare('SELECT COUNT(`uid`) AS `count` FROM `*PREFIX*group_user` WHERE `gid` = ? AND `uid` LIKE ?');
@@ -225,29 +224,4 @@ class OC_Group_Database extends OC_Group_Backend {
return $result->fetchOne();
}
- /**
- * @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 = array();
-
- $stmt = OC_DB::prepare('SELECT `*PREFIX*users`.`uid`, `*PREFIX*users`.`displayname`'
- .' FROM `*PREFIX*users`'
- .' INNER JOIN `*PREFIX*group_user` ON `*PREFIX*group_user`.`uid` = `*PREFIX*users`.`uid`'
- .' WHERE `gid` = ? AND `*PREFIX*group_user`.`uid` LIKE ?',
- $limit,
- $offset);
- $result = $stmt->execute(array($gid, $search.'%'));
- $users = array();
- while ($row = $result->fetchRow()) {
- $displayName = trim($row['displayname'], ' ');
- $displayNames[$row['uid']] = empty($displayName) ? $row['uid'] : $displayName;
- }
- return $displayNames;
- }
}
diff --git a/lib/private/group/dummy.php b/lib/private/group/dummy.php
index 94cbb607ad1..75bab31a337 100644
--- a/lib/private/group/dummy.php
+++ b/lib/private/group/dummy.php
@@ -29,9 +29,9 @@ class OC_Group_Dummy extends OC_Group_Backend {
/**
* @brief Try to create a new group
* @param string $gid The name of the group to create
- * @returns true/false
+ * @return bool
*
- * Trys to create a new group. If the group name already exists, false will
+ * Tries to create a new group. If the group name already exists, false will
* be returned.
*/
public function createGroup($gid) {
@@ -45,8 +45,8 @@ class OC_Group_Dummy extends OC_Group_Backend {
/**
* @brief delete a group
- * @param $gid gid of the group to delete
- * @returns true/false
+ * @param string $gid gid of the group to delete
+ * @return bool
*
* Deletes a group and removes it from the group_user-table
*/
@@ -61,9 +61,9 @@ class OC_Group_Dummy extends OC_Group_Backend {
/**
* @brief is user in group?
- * @param $uid uid of the user
- * @param $gid gid of the group
- * @returns true/false
+ * @param string $uid uid of the user
+ * @param string $gid gid of the group
+ * @return bool
*
* Checks whether the user is member of a group or not.
*/
@@ -77,9 +77,9 @@ class OC_Group_Dummy extends OC_Group_Backend {
/**
* @brief Add a user to a group
- * @param $uid Name of the user to add to group
- * @param $gid Name of the group in which add the user
- * @returns true/false
+ * @param string $uid Name of the user to add to group
+ * @param string $gid Name of the group in which add the user
+ * @return bool
*
* Adds a user to a group.
*/
@@ -98,9 +98,9 @@ class OC_Group_Dummy extends OC_Group_Backend {
/**
* @brief Removes a user from a group
- * @param $uid NameUSER of the user to remove from group
- * @param $gid Name of the group from which remove the user
- * @returns true/false
+ * @param string $uid Name of the user to remove from group
+ * @param string $gid Name of the group from which remove the user
+ * @return bool
*
* removes the user from a group.
*/
@@ -118,8 +118,8 @@ class OC_Group_Dummy extends OC_Group_Backend {
/**
* @brief Get all groups a user belongs to
- * @param $uid Name of the user
- * @returns array with group names
+ * @param string $uid Name of the user
+ * @return array an array of group names
*
* This function fetches all groups a user belongs to. It does not check
* if the user exists at all.
@@ -136,18 +136,23 @@ class OC_Group_Dummy extends OC_Group_Backend {
}
/**
- * @brief get a list of all groups
- * @returns array with group names
- *
- * Returns a list with all groups
+ * @brief Get a list of all groups
+ * @param string $search
+ * @param int $limit
+ * @param int $offset
+ * @return array an array of group names
*/
public function getGroups($search = '', $limit = -1, $offset = 0) {
return array_keys($this->groups);
}
/**
- * @brief get a list of all users in a group
- * @returns array with user ids
+ * @brief Get a list of all users in a group
+ * @param string $gid
+ * @param string $search
+ * @param int $limit
+ * @param int $offset
+ * @return array an array of user IDs
*/
public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
if(isset($this->groups[$gid])) {
@@ -159,7 +164,11 @@ class OC_Group_Dummy extends OC_Group_Backend {
/**
* @brief get the number of all users in a group
- * @returns int | bool
+ * @param string $gid
+ * @param string $search
+ * @param int $limit
+ * @param int $offset
+ * @return int
*/
public function countUsersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
if(isset($this->groups[$gid])) {
diff --git a/lib/private/group/example.php b/lib/private/group/example.php
index 3519b9ed92f..76c9ce2433d 100644
--- a/lib/private/group/example.php
+++ b/lib/private/group/example.php
@@ -28,18 +28,18 @@
abstract class OC_Group_Example {
/**
* @brief Try to create a new group
- * @param $gid The name of the group to create
- * @returns true/false
+ * @param string $gid The name of the group to create
+ * @return bool
*
- * Trys to create a new group. If the group name already exists, false will
+ * Tries to create a new group. If the group name already exists, false will
* be returned.
*/
abstract public static function createGroup($gid);
/**
* @brief delete a group
- * @param $gid gid of the group to delete
- * @returns true/false
+ * @param string $gid gid of the group to delete
+ * @return bool
*
* Deletes a group and removes it from the group_user-table
*/
@@ -47,9 +47,9 @@ abstract class OC_Group_Example {
/**
* @brief is user in group?
- * @param $uid uid of the user
- * @param $gid gid of the group
- * @returns true/false
+ * @param string $uid uid of the user
+ * @param string $gid gid of the group
+ * @return bool
*
* Checks whether the user is member of a group or not.
*/
@@ -57,9 +57,9 @@ abstract class OC_Group_Example {
/**
* @brief Add a user to a group
- * @param $uid Name of the user to add to group
- * @param $gid Name of the group in which add the user
- * @returns true/false
+ * @param string $uid Name of the user to add to group
+ * @param string $gid Name of the group in which add the user
+ * @return bool
*
* Adds a user to a group.
*/
@@ -67,9 +67,9 @@ abstract class OC_Group_Example {
/**
* @brief Removes a user from a group
- * @param $uid NameUSER of the user to remove from group
- * @param $gid Name of the group from which remove the user
- * @returns true/false
+ * @param string $uid Name of the user to remove from group
+ * @param string $gid Name of the group from which remove the user
+ * @return bool
*
* removes the user from a group.
*/
@@ -77,8 +77,8 @@ abstract class OC_Group_Example {
/**
* @brief Get all groups a user belongs to
- * @param $uid Name of the user
- * @returns array with group names
+ * @param string $uid Name of the user
+ * @return array an array of group names
*
* This function fetches all groups a user belongs to. It does not check
* if the user exists at all.
@@ -87,14 +87,15 @@ abstract class OC_Group_Example {
/**
* @brief get a list of all groups
- * @returns array with group names
- *
- * Returns a list with all groups
+ * @param string $search
+ * @param int $limit
+ * @param int $offset
+ * @return array an array of group names
*/
abstract public static function getGroups($search = '', $limit = -1, $offset = 0);
/**
- * check if a group exists
+ * @brief Check if a group exists
* @param string $gid
* @return bool
*/
@@ -102,8 +103,11 @@ abstract class OC_Group_Example {
/**
* @brief get a list of all users in a group
- * @returns array with user ids
+ * @param string $gid
+ * @param string $search
+ * @param int $limit
+ * @param int $offset
+ * @return array an array of user ids
*/
abstract public static function usersInGroup($gid, $search = '', $limit = -1, $offset = 0);
-
}
diff --git a/lib/private/group/group.php b/lib/private/group/group.php
index 3efbb6e7023..69641854dc5 100644
--- a/lib/private/group/group.php
+++ b/lib/private/group/group.php
@@ -26,7 +26,7 @@ class Group {
private $usersLoaded;
/**
- * @var \OC_Group_Backend[] | \OC_Group_Database[] $backend
+ * @var \OC_Group_Backend[]|\OC_Group_Database[] $backend
*/
private $backends;
@@ -184,7 +184,7 @@ class Group {
* returns the number of users matching the search string
*
* @param string $search
- * @return int | bool
+ * @return int|bool
*/
public function count($search) {
$users = false;
@@ -212,11 +212,7 @@ class Group {
public function searchDisplayName($search, $limit = null, $offset = null) {
$users = array();
foreach ($this->backends as $backend) {
- if ($backend->implementsActions(OC_GROUP_BACKEND_GET_DISPLAYNAME)) {
- $userIds = array_keys($backend->displayNamesInGroup($this->gid, $search, $limit, $offset));
- } else {
- $userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset);
- }
+ $userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset);
$users = $this->getVerifiedUsers($userIds);
if (!is_null($limit) and $limit <= 0) {
return array_values($users);
diff --git a/lib/private/group/interface.php b/lib/private/group/interface.php
index 4ef3663837f..74d288d42c0 100644
--- a/lib/private/group/interface.php
+++ b/lib/private/group/interface.php
@@ -45,7 +45,7 @@ interface OC_Group_Interface {
/**
* @brief Get all groups a user belongs to
* @param string $uid Name of the user
- * @return array with group names
+ * @return array an array of group names
*
* This function fetches all groups a user belongs to. It does not check
* if the user exists at all.
@@ -57,7 +57,7 @@ interface OC_Group_Interface {
* @param string $search
* @param int $limit
* @param int $offset
- * @return array with group names
+ * @return array an array of group names
*
* Returns a list with all groups
*/
@@ -76,7 +76,7 @@ interface OC_Group_Interface {
* @param string $search
* @param int $limit
* @param int $offset
- * @return array with user ids
+ * @return array an array of user ids
*/
public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0);
diff --git a/lib/private/group/manager.php b/lib/private/group/manager.php
index f591bd32aba..707009fb3d4 100644
--- a/lib/private/group/manager.php
+++ b/lib/private/group/manager.php
@@ -28,7 +28,7 @@ use OC\Hooks\PublicEmitter;
*/
class Manager extends PublicEmitter {
/**
- * @var \OC_Group_Backend[] | \OC_Group_Database[] $backends
+ * @var \OC_Group_Backend[]|\OC_Group_Database[] $backends
*/
private $backends = array();
@@ -40,19 +40,38 @@ class Manager extends PublicEmitter {
/**
* @var \OC\Group\Group[]
*/
- private $cachedGroups;
+ private $cachedGroups = array();
+
+ /**
+ * @var \OC\Group\Group[]
+ */
+ private $cachedUserGroups = array();
/**
* @param \OC\User\Manager $userManager
*/
public function __construct($userManager) {
$this->userManager = $userManager;
- $cache = & $this->cachedGroups;
- $this->listen('\OC\Group', 'postDelete', function ($group) use (&$cache) {
+ $cachedGroups = & $this->cachedGroups;
+ $cachedUserGroups = & $this->cachedUserGroups;
+ $this->listen('\OC\Group', 'postDelete', function ($group) use (&$cachedGroups, &$cachedUserGroups) {
+ /**
+ * @var \OC\Group\Group $group
+ */
+ unset($cachedGroups[$group->getGID()]);
+ $cachedUserGroups = array();
+ });
+ $this->listen('\OC\Group', 'postAddUser', function ($group) use (&$cachedUserGroups) {
/**
* @var \OC\Group\Group $group
*/
- unset($cache[$group->getGID()]);
+ $cachedUserGroups = array();
+ });
+ $this->listen('\OC\Group', 'postRemoveUser', function ($group) use (&$cachedUserGroups) {
+ /**
+ * @var \OC\Group\Group $group
+ */
+ $cachedUserGroups = array();
});
}
@@ -135,7 +154,7 @@ class Manager extends PublicEmitter {
foreach ($this->backends as $backend) {
$groupIds = $backend->getGroups($search, $limit, $offset);
foreach ($groupIds as $groupId) {
- $groups[$groupId] = $this->getGroupObject($groupId);
+ $groups[$groupId] = $this->get($groupId);
}
if (!is_null($limit) and $limit <= 0) {
return array_values($groups);
@@ -149,13 +168,52 @@ class Manager extends PublicEmitter {
* @return \OC\Group\Group[]
*/
public function getUserGroups($user) {
+ $uid = $user->getUID();
+ if (isset($this->cachedUserGroups[$uid])) {
+ return $this->cachedUserGroups[$uid];
+ }
$groups = array();
foreach ($this->backends as $backend) {
- $groupIds = $backend->getUserGroups($user->getUID());
+ $groupIds = $backend->getUserGroups($uid);
foreach ($groupIds as $groupId) {
- $groups[$groupId] = $this->getGroupObject($groupId);
+ $groups[$groupId] = $this->get($groupId);
}
}
- return array_values($groups);
+ $this->cachedUserGroups[$uid] = array_values($groups);
+ return $this->cachedUserGroups[$uid];
+ }
+
+ /**
+ * @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 an array of display names (value) and user ids (key)
+ */
+ public function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) {
+ $group = $this->get($gid);
+ if(is_null($group)) {
+ return array();
+ }
+ // only user backends have the capability to do a complex search for users
+ $groupUsers = $group->searchUsers('', $limit, $offset);
+ $search = trim($search);
+ if(!empty($search)) {
+ //TODO: for OC 7 earliest: user backend should get a method to check selected users against a pattern
+ $filteredUsers = $this->userManager->search($search);
+ $testUsers = true;
+ } else {
+ $filteredUsers = array();
+ $testUsers = false;
+ }
+
+ $matchingUsers = array();
+ foreach($groupUsers as $user) {
+ if(!$testUsers || isset($filteredUsers[$user->getUID()])) {
+ $matchingUsers[$user->getUID()] = $user->getDisplayName();
+ }
+ }
+ return $matchingUsers;
}
}
diff --git a/lib/private/helper.php b/lib/private/helper.php
index ab1e0d38924..12d82f6fb45 100644
--- a/lib/private/helper.php
+++ b/lib/private/helper.php
@@ -32,11 +32,11 @@ class OC_Helper {
/**
* @brief Creates an url using a defined route
- * @param $route
+ * @param string $route
* @param array $parameters
* @return
* @internal param array $args with param=>value, will be appended to the returned url
- * @returns string the url
+ * @return string the url
*
* Returns a url to the given app and file.
*/
@@ -78,7 +78,9 @@ class OC_Helper {
* Returns a absolute url to the given app and file.
*/
public static function linkToAbsolute($app, $file, $args = array()) {
- return self::linkTo($app, $file, $args);
+ return OC::$server->getURLGenerator()->getAbsoluteURL(
+ self::linkTo($app, $file, $args)
+ );
}
/**
@@ -112,8 +114,10 @@ class OC_Helper {
* Returns a absolute url to the given service.
*/
public static function linkToRemote($service, $add_slash = true) {
- return self::makeURLAbsolute(self::linkToRemoteBase($service))
- . (($add_slash && $service[strlen($service) - 1] != '/') ? '/' : '');
+ return OC::$server->getURLGenerator()->getAbsoluteURL(
+ self::linkToRemoteBase($service)
+ . (($add_slash && $service[strlen($service) - 1] != '/') ? '/' : '')
+ );
}
/**
@@ -125,8 +129,12 @@ class OC_Helper {
* Returns a absolute url to the given service.
*/
public static function linkToPublic($service, $add_slash = false) {
- return self::linkToAbsolute('', 'public.php') . '?service=' . $service
- . (($add_slash && $service[strlen($service) - 1] != '/') ? '/' : '');
+ return OC::$server->getURLGenerator()->getAbsoluteURL(
+ self::linkTo(
+ '', 'public.php') . '?service=' . $service
+ . (($add_slash && $service[strlen($service) - 1] != '/') ? '/' : ''
+ )
+ );
}
/**
@@ -306,6 +314,32 @@ class OC_Helper {
}
/**
+ * @brief Make a php file size
+ * @param int $bytes file size in bytes
+ * @return string a php parseable file size
+ *
+ * Makes 2048 to 2k and 2^41 to 2048G
+ */
+ public static function phpFileSize($bytes) {
+ if ($bytes < 0) {
+ return "?";
+ }
+ if ($bytes < 1024) {
+ return $bytes . "B";
+ }
+ $bytes = round($bytes / 1024, 1);
+ if ($bytes < 1024) {
+ return $bytes . "K";
+ }
+ $bytes = round($bytes / 1024, 1);
+ if ($bytes < 1024) {
+ return $bytes . "M";
+ }
+ $bytes = round($bytes / 1024, 1);
+ return $bytes . "G";
+ }
+
+ /**
* @brief Make a computer file size
* @param string $str file size in human readable format
* @return int a file size in bytes
@@ -461,7 +495,7 @@ class OC_Helper {
/**
* detect if a given program is found in the search PATH
*
- * @param $name
+ * @param string $name
* @param bool $path
* @internal param string $program name
* @internal param string $optional search path, defaults to $PATH
@@ -636,8 +670,8 @@ class OC_Helper {
/**
* Adds a suffix to the name in case the file exists
*
- * @param $path
- * @param $filename
+ * @param string $path
+ * @param string $filename
* @return string
*/
public static function buildNotExistingFileName($path, $filename) {
@@ -648,8 +682,8 @@ class OC_Helper {
/**
* Adds a suffix to the name in case the file exists
*
- * @param $path
- * @param $filename
+ * @param string $path
+ * @param string $filename
* @return string
*/
public static function buildNotExistingFileNameForView($path, $filename, \OC\Files\View $view) {
@@ -698,10 +732,22 @@ class OC_Helper {
* @param string $parent
* @return bool
*/
- public static function issubdirectory($sub, $parent) {
- if (strpos(realpath($sub), realpath($parent)) === 0) {
+ public static function isSubDirectory($sub, $parent) {
+ $realpathSub = realpath($sub);
+ $realpathParent = realpath($parent);
+
+ // realpath() may return false in case the directory does not exist
+ // since we can not be sure how different PHP versions may behave here
+ // we do an additional check whether realpath returned false
+ if($realpathSub === false || $realpathParent === false) {
+ return false;
+ }
+
+ // Check whether $sub is a subdirectory of $parent
+ if (strpos($realpathSub, $realpathParent) === 0) {
return true;
}
+
return false;
}
@@ -729,7 +775,7 @@ class OC_Helper {
/**
* @brief replaces a copy of string delimited by the start and (optionally) length parameters with the string given in replacement.
*
- * @param $string
+ * @param string $string
* @param string $replacement The replacement string.
* @param int $start If start is positive, the replacing will begin at the start'th offset into string. If start is negative, the replacing will begin at the start'th character from the end of string.
* @param int $length Length of the part to be replaced
diff --git a/lib/private/hook.php b/lib/private/hook.php
index b63b442c31b..b715db2d16c 100644
--- a/lib/private/hook.php
+++ b/lib/private/hook.php
@@ -45,7 +45,7 @@ class OC_Hook{
* @brief emits a signal
* @param string $signalclass class name of emitter
* @param string $signalname name of signal
- * @param array $params defautl: array() array with additional data
+ * @param mixed $params default: array() array with additional data
* @return bool, true if slots exists or false if not
*
* Emits a signal. To get data from the slot use references!
diff --git a/lib/private/image.php b/lib/private/image.php
index 14aa64d12da..341bfaaf818 100644
--- a/lib/private/image.php
+++ b/lib/private/image.php
@@ -424,7 +424,7 @@ class OC_Image {
* @brief Loads an image from an open file handle.
* It is the responsibility of the caller to position the pointer at the correct place and to close the handle again.
* @param resource $handle
- * @return An image resource or false on error
+ * @return resource|false An image resource or false on error
*/
public function loadFromFileHandle($handle) {
OC_Log::write('core', __METHOD__.'(): Trying', OC_Log::DEBUG);
diff --git a/lib/private/installer.php b/lib/private/installer.php
index 64e8e3a5e7a..9417c32bc89 100644
--- a/lib/private/installer.php
+++ b/lib/private/installer.php
@@ -221,7 +221,7 @@ class OC_Installer{
/**
* @brief checks whether or not an app is installed
* @param string $app app
- * @returns true/false
+ * @return bool
*
* Checks whether or not an app is installed, i.e. registered in apps table.
*/
@@ -313,7 +313,7 @@ class OC_Installer{
/**
* @brief Removes an app
* @param string $name name of the application to remove
- * @param $options array with options
+ * @param array $options options
* @return boolean|null
*
* This function removes an app. $options is an associative array. The
diff --git a/lib/private/l10n.php b/lib/private/l10n.php
index c7e4328161e..40eeb98d6bb 100644
--- a/lib/private/l10n.php
+++ b/lib/private/l10n.php
@@ -134,10 +134,10 @@ class OC_L10N implements \OCP\IL10N {
$i18ndir = self::findI18nDir($app);
// Localization is in /l10n, Texts are in $i18ndir
// (Just no need to define date/time format etc. twice)
- if((OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC::$SERVERROOT.'/core/l10n/')
- || OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC::$SERVERROOT.'/lib/l10n/')
- || OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC::$SERVERROOT.'/settings')
- || OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC_App::getAppPath($app).'/l10n/')
+ if((OC_Helper::isSubDirectory($i18ndir.$lang.'.php', OC::$SERVERROOT.'/core/l10n/')
+ || OC_Helper::isSubDirectory($i18ndir.$lang.'.php', OC::$SERVERROOT.'/lib/l10n/')
+ || OC_Helper::isSubDirectory($i18ndir.$lang.'.php', OC::$SERVERROOT.'/settings')
+ || OC_Helper::isSubDirectory($i18ndir.$lang.'.php', OC_App::getAppPath($app).'/l10n/')
)
&& file_exists($i18ndir.$lang.'.php')) {
// Include the file, save the data from $CONFIG
@@ -162,7 +162,7 @@ class OC_L10N implements \OCP\IL10N {
}
}
- if(file_exists(OC::$SERVERROOT.'/core/l10n/l10n-'.$lang.'.php') && OC_Helper::issubdirectory(OC::$SERVERROOT.'/core/l10n/l10n-'.$lang.'.php', OC::$SERVERROOT.'/core/l10n/')) {
+ if(file_exists(OC::$SERVERROOT.'/core/l10n/l10n-'.$lang.'.php') && OC_Helper::isSubDirectory(OC::$SERVERROOT.'/core/l10n/l10n-'.$lang.'.php', OC::$SERVERROOT.'/core/l10n/')) {
// Include the file, save the data from $CONFIG
include OC::$SERVERROOT.'/core/l10n/l10n-'.$lang.'.php';
if(isset($LOCALIZATIONS) && is_array($LOCALIZATIONS)) {
@@ -183,7 +183,7 @@ class OC_L10N implements \OCP\IL10N {
*
* Parts of the code is copied from Habari:
* https://github.com/habari/system/blob/master/classes/locale.php
- * @param $string string
+ * @param string $string
* @return string
*/
protected function createPluralFormFunction($string){
@@ -278,7 +278,7 @@ class OC_L10N implements \OCP\IL10N {
/**
* @brief getTranslations
- * @returns array Fetch all translations
+ * @return array Fetch all translations
*
* Returns an associative array with all translations
*/
@@ -289,7 +289,7 @@ class OC_L10N implements \OCP\IL10N {
/**
* @brief getPluralFormString
- * @returns string containing the gettext "Plural-Forms"-string
+ * @return string containing the gettext "Plural-Forms"-string
*
* Returns a string like "nplurals=2; plural=(n != 1);"
*/
@@ -300,7 +300,7 @@ class OC_L10N implements \OCP\IL10N {
/**
* @brief getPluralFormFunction
- * @returns string the plural form function
+ * @return string the plural form function
*
* returned function accepts the argument $n
*/
@@ -314,7 +314,7 @@ class OC_L10N implements \OCP\IL10N {
/**
* @brief get localizations
- * @returns array Fetch all localizations
+ * @return array Fetch all localizations
*
* Returns an associative array with all localizations
*/
@@ -326,8 +326,8 @@ class OC_L10N implements \OCP\IL10N {
/**
* @brief Localization
* @param string $type Type of localization
- * @param array $data parameters for this localization
- * @returns String or false
+ * @param array|int|string $data parameters for this localization
+ * @return String or false
*
* Returns the localized data.
*
@@ -381,7 +381,7 @@ class OC_L10N implements \OCP\IL10N {
/**
* @brief Choose a language
* @param array $text Associative Array with possible strings
- * @returns String
+ * @return String
*
* $text is an array 'de' => 'hallo welt', 'en' => 'hello world', ...
*
@@ -401,6 +401,7 @@ class OC_L10N implements \OCP\IL10N {
self::$language = $lang;
}
+
/**
* @brief find the best language
* @param array|string $app details below
@@ -412,6 +413,22 @@ class OC_L10N implements \OCP\IL10N {
*
* If nothing works it returns 'en'
*/
+ public function getLanguageCode($app=null) {
+ return self::findLanguage($app);
+ }
+
+
+ /**
+ * @brief find the best language
+ * @param array|string $app details below
+ * @return string language
+ *
+ * If $app is an array, ownCloud assumes that these are the available
+ * languages. Otherwise ownCloud tries to find the files in the l10n
+ * folder.
+ *
+ * If nothing works it returns 'en'
+ */
public static function findLanguage($app = null) {
if(!is_array($app) && self::$language != '') {
return self::$language;
@@ -477,7 +494,7 @@ class OC_L10N implements \OCP\IL10N {
/**
* @brief find the l10n directory
* @param string $app App that needs to be translated
- * @returns directory
+ * @return directory
*/
protected static function findI18nDir($app) {
// find the i18n dir
@@ -497,7 +514,7 @@ class OC_L10N implements \OCP\IL10N {
/**
* @brief find all available languages for an app
* @param string $app App that needs to be translated
- * @returns array an array of available languages
+ * @return array an array of available languages
*/
public static function findAvailableLanguages($app=null) {
$available=array('en');//english is always available
@@ -517,7 +534,7 @@ class OC_L10N implements \OCP\IL10N {
/**
* @param string $app
* @param string $lang
- * @returns bool
+ * @return bool
*/
public static function languageExists($app, $lang) {
if ($lang == 'en') {//english is always available
diff --git a/lib/private/l10n/factory.php b/lib/private/l10n/factory.php
index 8c65f368171..d0c3799b9c2 100644
--- a/lib/private/l10n/factory.php
+++ b/lib/private/l10n/factory.php
@@ -20,8 +20,8 @@ class Factory {
/**
* get an L10N instance
- * @param $app string
- * @param $lang string|null
+ * @param string $app
+ * @param string|null $lang
* @return \OC_L10N
*/
public function get($app) {
diff --git a/lib/private/legacy/appconfig.php b/lib/private/legacy/appconfig.php
index cb5cef7e350..209f42ffe38 100644
--- a/lib/private/legacy/appconfig.php
+++ b/lib/private/legacy/appconfig.php
@@ -35,7 +35,7 @@ class OC_Appconfig {
/**
* @brief Get all apps using the config
- * @return array with app ids
+ * @return array an array of app ids
*
* This function returns a list of all apps that have at least one
* entry in the appconfig table.
@@ -47,7 +47,7 @@ class OC_Appconfig {
/**
* @brief Get the available keys for an app
* @param string $app the app we are looking for
- * @return array with key names
+ * @return array an array of key names
*
* This function gets all keys of an app. Please note that the values are
* not returned.
diff --git a/lib/private/legacy/cache.php b/lib/private/legacy/cache.php
deleted file mode 100644
index f915eb516b1..00000000000
--- a/lib/private/legacy/cache.php
+++ /dev/null
@@ -1,10 +0,0 @@
-<?php
-/**
- * Copyright (c) 2013 Thomas Tanghus (thomas@tanghus.net)
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-class OC_Cache extends \OC\Cache {
-} \ No newline at end of file
diff --git a/lib/private/legacy/cache/fileglobalgc.php b/lib/private/legacy/cache/fileglobalgc.php
deleted file mode 100644
index 385f6406673..00000000000
--- a/lib/private/legacy/cache/fileglobalgc.php
+++ /dev/null
@@ -1,4 +0,0 @@
-<?php
-
-class OC_Cache_FileGlobalGC extends OC\Cache\FileGlobalGC{
-}
diff --git a/lib/private/legacy/config.php b/lib/private/legacy/config.php
index 6c2103179ab..76a53d3f627 100644
--- a/lib/private/legacy/config.php
+++ b/lib/private/legacy/config.php
@@ -51,7 +51,7 @@ class OC_Config {
/**
* @brief Lists all available config keys
- * @return array with key names
+ * @return array an array of key names
*
* This function returns all keys saved in config.php. Please note that it
* does not return the values.
diff --git a/lib/private/legacy/filesystem.php b/lib/private/legacy/filesystem.php
deleted file mode 100644
index 34f92b357ca..00000000000
--- a/lib/private/legacy/filesystem.php
+++ /dev/null
@@ -1,415 +0,0 @@
-<?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.
- */
-
-/**
- * Class for abstraction of filesystem functions
- * This class won't call any filesystem functions for itself but but will pass them to the correct OC_Filestorage object
- * this class should also handle all the file permission related stuff
- *
- * Hooks provided:
- * read(path)
- * write(path, &run)
- * post_write(path)
- * create(path, &run) (when a file is created, both create and write will be emitted in that order)
- * post_create(path)
- * delete(path, &run)
- * post_delete(path)
- * rename(oldpath,newpath, &run)
- * post_rename(oldpath,newpath)
- * copy(oldpath,newpath, &run) (if the newpath doesn't exists yes, copy, create and write will be emitted in that order)
- * post_rename(oldpath,newpath)
- *
- * the &run parameter can be set to false to prevent the operation from occurring
- */
-
-/**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
-class OC_Filesystem {
- /**
- * get the mountpoint of the storage object for a path
- * ( note: because a storage is not always mounted inside the fakeroot, the
- * returned mountpoint is relative to the absolute root of the filesystem
- * and doesn't take the chroot into account )
- *
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- * @param string $path
- * @return string
- */
- static public function getMountPoint($path) {
- return \OC\Files\Filesystem::getMountPoint($path);
- }
-
- /**
- * resolve a path to a storage and internal path
- *
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- * @param string $path
- * @return array consisting of the storage and the internal path
- */
- static public function resolvePath($path) {
- return \OC\Files\Filesystem::resolvePath($path);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function init($user, $root) {
- return \OC\Files\Filesystem::init($user, $root);
- }
-
- /**
- * get the default filesystem view
- *
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- * @return \OC\Files\View
- */
- static public function getView() {
- return \OC\Files\Filesystem::getView();
- }
-
- /**
- * tear down the filesystem, removing all storage providers
- *
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function tearDown() {
- \OC\Files\Filesystem::tearDown();
- }
-
- /**
- * @brief get the relative path of the root data directory for the current user
- * @return string
- *
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- * Returns path like /admin/files
- */
- static public function getRoot() {
- return \OC\Files\Filesystem::getRoot();
- }
-
- /**
- * clear all mounts and storage backends
- *
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- public static function clearMounts() {
- \OC\Files\Filesystem::clearMounts();
- }
-
- /**
- * mount an \OC\Files\Storage\Storage in our virtual filesystem
- *
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- * @param \OC\Files\Storage\Storage $class
- * @param array $arguments
- * @param string $mountpoint
- */
- static public function mount($class, $arguments, $mountpoint) {
- \OC\Files\Filesystem::mount($class, $arguments, $mountpoint);
- }
-
- /**
- * return the path to a local version of the file
- * we need this because we can't know if a file is stored local or not from
- * outside the filestorage and for some purposes a local file is needed
- *
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- * @param string $path
- * @return string
- */
- static public function getLocalFile($path) {
- return \OC\Files\Filesystem::getLocalFile($path);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- * @param string $path
- * @return string
- */
- static public function getLocalFolder($path) {
- return \OC\Files\Filesystem::getLocalFolder($path);
- }
-
- /**
- * return path to file which reflects one visible in browser
- *
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- * @param string $path
- * @return string
- */
- static public function getLocalPath($path) {
- return \OC\Files\Filesystem::getLocalPath($path);
- }
-
- /**
- * check if the requested path is valid
- *
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- * @param string $path
- * @return bool
- */
- static public function isValidPath($path) {
- return \OC\Files\Filesystem::isValidPath($path);
- }
-
- /**
- * checks if a file is blacklisted for storage in the filesystem
- * Listens to write and rename hooks
- *
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- * @param array $data from hook
- */
- static public function isBlacklisted($data) {
- \OC\Files\Filesystem::isBlacklisted($data);
- }
-
- /**
- * following functions are equivalent to their php builtin equivalents for arguments/return values.
- *
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function mkdir($path) {
- return \OC\Files\Filesystem::mkdir($path);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function rmdir($path) {
- return \OC\Files\Filesystem::rmdir($path);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function opendir($path) {
- return \OC\Files\Filesystem::opendir($path);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function readdir($path) {
- return \OC\Files\Filesystem::readdir($path);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function is_dir($path) {
- return \OC\Files\Filesystem::is_dir($path);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function is_file($path) {
- return \OC\Files\Filesystem::is_file($path);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function stat($path) {
- return \OC\Files\Filesystem::stat($path);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function filetype($path) {
- return \OC\Files\Filesystem::filetype($path);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function filesize($path) {
- return \OC\Files\Filesystem::filesize($path);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function readfile($path) {
- return \OC\Files\Filesystem::readfile($path);
- }
-
- /**
- * @deprecated Replaced by isReadable() as part of CRUDS
- */
- static public function is_readable($path) {
- return \OC\Files\Filesystem::isReadable($path);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function isCreatable($path) {
- return \OC\Files\Filesystem::isCreatable($path);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function isReadable($path) {
- return \OC\Files\Filesystem::isReadable($path);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function isUpdatable($path) {
- return \OC\Files\Filesystem::isUpdatable($path);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function isDeletable($path) {
- return \OC\Files\Filesystem::isDeletable($path);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function isSharable($path) {
- return \OC\Files\Filesystem::isSharable($path);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function file_exists($path) {
- return \OC\Files\Filesystem::file_exists($path);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function filemtime($path) {
- return \OC\Files\Filesystem::filemtime($path);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function touch($path, $mtime = null) {
- return \OC\Files\Filesystem::touch($path, $mtime);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function file_get_contents($path) {
- return \OC\Files\Filesystem::file_get_contents($path);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function file_put_contents($path, $data) {
- return \OC\Files\Filesystem::file_put_contents($path, $data);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function unlink($path) {
- return \OC\Files\Filesystem::unlink($path);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function rename($path1, $path2) {
- return \OC\Files\Filesystem::rename($path1, $path2);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function copy($path1, $path2) {
- return \OC\Files\Filesystem::copy($path1, $path2);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function fopen($path, $mode) {
- return \OC\Files\Filesystem::fopen($path, $mode);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function toTmpFile($path) {
- return \OC\Files\Filesystem::toTmpFile($path);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function fromTmpFile($tmpFile, $path) {
- return \OC\Files\Filesystem::fromTmpFile($tmpFile, $path);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function getMimeType($path) {
- return \OC\Files\Filesystem::getMimeType($path);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function hash($type, $path, $raw = false) {
- return \OC\Files\Filesystem::hash($type, $path, $raw);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function free_space($path = '/') {
- return \OC\Files\Filesystem::free_space($path);
- }
-
- /**
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- */
- static public function search($query) {
- return \OC\Files\Filesystem::search($query);
- }
-
- /**
- * check if a file or folder has been updated since $time
- *
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- * @param string $path
- * @param int $time
- * @return bool
- */
- static public function hasUpdated($path, $time) {
- return \OC\Files\Filesystem::hasUpdated($path, $time);
- }
-
- /**
- * normalize a path
- *
- * @deprecated OC_Filesystem is replaced by \OC\Files\Filesystem
- * @param string $path
- * @param bool $stripTrailingSlash
- * @return string
- */
- public static function normalizePath($path, $stripTrailingSlash = true) {
- return \OC\Files\Filesystem::normalizePath($path, $stripTrailingSlash);
- }
-}
diff --git a/lib/private/legacy/filesystemview.php b/lib/private/legacy/filesystemview.php
deleted file mode 100644
index d6bca62e06a..00000000000
--- a/lib/private/legacy/filesystemview.php
+++ /dev/null
@@ -1,9 +0,0 @@
-<?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. */
-
-class OC_FilesystemView extends \OC\Files\View {}
diff --git a/lib/private/legacy/preferences.php b/lib/private/legacy/preferences.php
index fcde12796ca..eed6730a529 100644
--- a/lib/private/legacy/preferences.php
+++ b/lib/private/legacy/preferences.php
@@ -29,7 +29,7 @@ class OC_Preferences{
public static $object;
/**
* @brief Get all users using the preferences
- * @return array with user ids
+ * @return array an array of user ids
*
* This function returns a list of all users that have at least one entry
* in the preferences table.
@@ -54,7 +54,7 @@ class OC_Preferences{
* @brief Get the available keys for an app
* @param string $user user
* @param string $app the app we are looking for
- * @return array with key names
+ * @return array an array of key names
*
* This function gets all keys of an app of an user. Please note that the
* values are not returned.
diff --git a/lib/private/log.php b/lib/private/log.php
index e0b9fe3c696..98465ec40ea 100644
--- a/lib/private/log.php
+++ b/lib/private/log.php
@@ -8,6 +8,8 @@
namespace OC;
+use \OCP\ILogger;
+
/**
* logging utilities
*
@@ -18,8 +20,24 @@ namespace OC;
* MonoLog is an example implementing this interface.
*/
-class Log {
- private $logClass;
+class Log implements ILogger {
+
+ private $logger;
+
+ /**
+ * @param string $logger The logger that should be used
+ */
+ public function __construct($logger=null) {
+ // FIXME: Add this for backwards compatibility, should be fixed at some point probably
+ if($logger === null) {
+ $this->logger = 'OC_Log_'.ucfirst(\OC_Config::getValue('log_type', 'owncloud'));
+ call_user_func(array($this->logger, 'init'));
+ } else {
+ $this->logger = $logger;
+ }
+
+ }
+
/**
* System is unusable.
@@ -112,10 +130,6 @@ class Log {
$this->log(\OC_Log::DEBUG, $message, $context);
}
- public function __construct() {
- $this->logClass = 'OC_Log_'.ucfirst(\OC_Config::getValue('log_type', 'owncloud'));
- call_user_func(array($this->logClass, 'init'));
- }
/**
* Logs with an arbitrary level.
@@ -130,7 +144,16 @@ class Log {
} else {
$app = 'no app in context';
}
- $logClass=$this->logClass;
- $logClass::write($app, $message, $level);
+ // interpolate $message as defined in PSR-3
+ $replace = array();
+ foreach ($context as $key => $val) {
+ $replace['{' . $key . '}'] = $val;
+ }
+
+ // interpolate replacement values into the message and return
+ $message = strtr($message, $replace);
+
+ $logger = $this->logger;
+ $logger::write($app, $message, $level);
}
}
diff --git a/lib/private/memcache/memcached.php b/lib/private/memcache/memcached.php
index 075828eebad..cd8e2e8d0b6 100644
--- a/lib/private/memcache/memcached.php
+++ b/lib/private/memcache/memcached.php
@@ -57,7 +57,7 @@ class Memcached extends Cache {
public function hasKey($key) {
self::$cache->get($this->getNamespace() . $key);
- return self::$cache->getResultCode() !== \Memcached::RES_NOTFOUND;
+ return self::$cache->getResultCode() === \Memcached::RES_SUCCESS;
}
public function remove($key) {
diff --git a/lib/private/migrate.php b/lib/private/migrate.php
index 5bcc11b061b..98c825aafd8 100644
--- a/lib/private/migrate.php
+++ b/lib/private/migrate.php
@@ -333,7 +333,7 @@ class OC_Migrate{
/**
* @brief tries to extract the import zip
- * @param $path string path to the zip
+ * @param string $path path to the zip
* @return string path to extract location (with a trailing slash) or false on failure
*/
static private function extractZip( $path ) {
@@ -536,9 +536,9 @@ class OC_Migrate{
/**
* @brief imports a new user
* @param string $db string path to migration.db
- * @param $info object of migration info
+ * @param object $info object of migration info
* @param string|null|int $uid uid to use
- * @return array of apps with import statuses, or false on failure.
+ * @return array an array of apps with import statuses, or false on failure.
*/
public static function importAppData( $db, $info, $uid=null ) {
// Check if the db exists
diff --git a/lib/private/migration/content.php b/lib/private/migration/content.php
index b0e7a4e9528..d3b2fe836a4 100644
--- a/lib/private/migration/content.php
+++ b/lib/private/migration/content.php
@@ -35,7 +35,7 @@ class OC_Migration_Content{
/**
* @brief sets up the
* @param ZipArchive $zip ZipArchive object
- * @param $db a database object (required for exporttype user)
+ * @param object $db a database object (required for exporttype user)
* @return bool|null
*/
public function __construct( $zip, $db=null ) {
@@ -45,11 +45,9 @@ class OC_Migration_Content{
}
- // @brief prepares the db
- // @param $query the sql query to prepare
-
/**
- * @param string $query
+ * @brief prepares the db
+ * @param string $query the sql query to prepare
*/
public function prepare( $query ) {
@@ -88,7 +86,7 @@ class OC_Migration_Content{
/**
* @brief copys rows to migration.db from the main database
- * @param $options array of options.
+ * @param array $options array of options.
* @return bool
*/
public function copyRows( $options ) {
@@ -131,7 +129,7 @@ class OC_Migration_Content{
/**
* @brief saves a sql data set into migration.db
* @param OC_DB_StatementWrapper $data a sql data set returned from self::prepare()->query()
- * @param $options array of copyRows options
+ * @param array $options array of copyRows options
* @return void
*/
private function insertData( $data, $options ) {
@@ -170,8 +168,8 @@ class OC_Migration_Content{
/**
* @brief adds a directory to the zip object
* @param boolean|string $dir string path of the directory to add
- * @param $recursive bool
- * @param $internaldir string path of folder to add dir to in zip
+ * @param bool $recursive
+ * @param string $internaldir path of folder to add dir to in zip
* @return bool
*/
public function addDir( $dir, $recursive=true, $internaldir='' ) {
diff --git a/lib/private/navigationmanager.php b/lib/private/navigationmanager.php
index 1f657b9ad80..d7111af03cf 100644
--- a/lib/private/navigationmanager.php
+++ b/lib/private/navigationmanager.php
@@ -30,7 +30,7 @@ class NavigationManager implements \OCP\INavigationManager {
/**
* @brief returns all the added Menu entries
- * @return array of the added entries
+ * @return array an array of the added entries
*/
public function getAll() {
return $this->entries;
diff --git a/lib/private/ocs.php b/lib/private/ocs.php
index 211e8222145..aeb3d259b30 100644
--- a/lib/private/ocs.php
+++ b/lib/private/ocs.php
@@ -213,8 +213,8 @@ class OC_OCS {
}
/**
- * @param $writer
- * @param $data
+ * @param resource $writer
+ * @param array $data
* @param string $node
*/
public static function toXml($writer, $data, $node) {
diff --git a/lib/private/ocs/cloud.php b/lib/private/ocs/cloud.php
index c8bb9425f1a..3ced0af8ee1 100644
--- a/lib/private/ocs/cloud.php
+++ b/lib/private/ocs/cloud.php
@@ -57,8 +57,8 @@ class OC_OCS_Cloud {
* </quota>
* </data>
*
- * @param $parameters object should contain parameter 'userid' which identifies
- * the user from whom the information will be returned
+ * @param array $parameters should contain parameter 'userid' which identifies
+ * the user from whom the information will be returned
*/
public static function getUser($parameters) {
$return = array();
diff --git a/lib/private/ocs/result.php b/lib/private/ocs/result.php
index 0e3b85d5905..567fe7f87fe 100644
--- a/lib/private/ocs/result.php
+++ b/lib/private/ocs/result.php
@@ -26,7 +26,7 @@ class OC_OCS_Result{
/**
* create the OCS_Result object
- * @param $data mixed the data to return
+ * @param mixed $data the data to return
*/
public function __construct($data=null, $code=100, $message=null) {
if ($data === null) {
@@ -42,7 +42,7 @@ class OC_OCS_Result{
/**
* optionally set the total number of items available
- * @param $items int
+ * @param int $items
*/
public function setTotalItems(int $items) {
$this->items = $items;
@@ -50,7 +50,7 @@ class OC_OCS_Result{
/**
* optionally set the the number of items per page
- * @param $items int
+ * @param int $items
*/
public function setItemsPerPage(int $items) {
$this->perPage = $items;
diff --git a/lib/private/ocsclient.php b/lib/private/ocsclient.php
index b0480caf028..fb8282747eb 100644
--- a/lib/private/ocsclient.php
+++ b/lib/private/ocsclient.php
@@ -30,7 +30,7 @@ class OC_OCSClient{
/**
* @brief Get the url of the OCS AppStore server.
- * @returns string of the AppStore server
+ * @return string of the AppStore server
*
* This function returns the url of the OCS AppStore server. It´s possible
* to set it in the config file or it will fallback to the default
@@ -48,7 +48,7 @@ class OC_OCSClient{
/**
* @brief Get the content of an OCS url call.
- * @returns string of the response
+ * @return string of the response
* This function calls an OCS server and returns the response. It also sets a sane timeout
* @param string $url
*/
@@ -59,7 +59,7 @@ class OC_OCSClient{
/**
* @brief Get all the categories from the OCS server
- * @returns array with category ids
+ * @return array an array of category ids
* @note returns NULL if config value appstoreenabled is set to false
* This function returns a list of all the application categories on the OCS server
*/
@@ -92,10 +92,10 @@ class OC_OCSClient{
/**
* @brief Get all the applications from the OCS server
- * @returns array with application data
+ * @return array an array of application data
*
* This function returns a list of all the applications on the OCS server
- * @param $categories
+ * @param array|string $categories
* @param int $page
* @param string $filter
*/
@@ -150,7 +150,7 @@ class OC_OCSClient{
/**
* @brief Get an the applications from the OCS server
* @param string $id
- * @returns array with application data
+ * @return array an array of application data
*
* This function returns an applications from the OCS server
*/
@@ -192,7 +192,7 @@ class OC_OCSClient{
/**
* @brief Get the download url for an application from the OCS server
- * @returns array with application data
+ * @return array an array of application data
*
* This function returns an download url for an applications from the OCS server
* @param string $id
diff --git a/lib/private/preferences.php b/lib/private/preferences.php
index d45e6e77089..3cadb6a2e97 100644
--- a/lib/private/preferences.php
+++ b/lib/private/preferences.php
@@ -69,7 +69,7 @@ class Preferences {
/**
* @brief Get all users using the preferences
- * @return array with user ids
+ * @return array an array of user ids
*
* This function returns a list of all users that have at least one entry
* in the preferences table.
@@ -125,7 +125,7 @@ class Preferences {
* @brief Get the available keys for an app
* @param string $user user
* @param string $app the app we are looking for
- * @return array with key names
+ * @return array an array of key names
*
* This function gets all keys of an app of an user. Please note that the
* values are not returned.
diff --git a/lib/private/preview.php b/lib/private/preview.php
index cdf22240382..eb932470a47 100755
--- a/lib/private/preview.php
+++ b/lib/private/preview.php
@@ -43,6 +43,7 @@ class Preview {
private $maxY;
private $scalingUp;
private $mimeType;
+ private $keepAspect = false;
//filemapper used for deleting previews
// index is path, value is fileinfo
@@ -190,7 +191,7 @@ class Preview {
/**
* @brief set the path of the file you want a thumbnail from
* @param string $file
- * @return $this
+ * @return \OC\Preview $this
*/
public function setFile($file) {
$this->file = $file;
@@ -216,7 +217,7 @@ class Preview {
* @brief set the the max width of the preview
* @param int $maxX
* @throws \Exception
- * @return $this
+ * @return \OC\Preview $this
*/
public function setMaxX($maxX = 1) {
if ($maxX <= 0) {
@@ -237,7 +238,7 @@ class Preview {
* @brief set the the max height of the preview
* @param int $maxY
* @throws \Exception
- * @return $this
+ * @return \OC\Preview $this
*/
public function setMaxY($maxY = 1) {
if ($maxY <= 0) {
@@ -257,7 +258,7 @@ class Preview {
/**
* @brief set whether or not scalingup is enabled
* @param bool $scalingUp
- * @return $this
+ * @return \OC\Preview $this
*/
public function setScalingup($scalingUp) {
if ($this->getMaxScaleFactor() === 1) {
@@ -267,6 +268,11 @@ class Preview {
return $this;
}
+ public function setKeepAspect($keepAspect) {
+ $this->keepAspect = $keepAspect;
+ return $this;
+ }
+
/**
* @brief check if all parameters are valid
* @return bool
@@ -297,7 +303,7 @@ class Preview {
if($fileInfo !== null && $fileInfo !== false) {
$fileId = $fileInfo->getId();
- $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/' . $this->getMaxX() . '-' . $this->getMaxY() . '.png';
+ $previewPath = $this->buildCachePath($fileId);
return $this->userView->unlink($previewPath);
}
return false;
@@ -330,15 +336,12 @@ class Preview {
if (is_null($fileId)) {
return false;
}
-
- $maxX = $this->getMaxX();
- $maxY = $this->getMaxY();
- $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/';
+ $preview = $this->buildCachePath($fileId);
//does a preview with the wanted height and width already exist?
- if ($this->userView->file_exists($previewPath . $maxX . '-' . $maxY . '.png')) {
- return $previewPath . $maxX . '-' . $maxY . '.png';
+ if ($this->userView->file_exists($preview)) {
+ return $preview;
}
return $this->isCachedBigger($fileId);
@@ -355,6 +358,11 @@ class Preview {
return false;
}
+ // in order to not loose quality we better generate aspect preserving previews from the original file
+ if ($this->keepAspect) {
+ return false;
+ }
+
$maxX = $this->getMaxX();
//array for usable cached thumbnails
@@ -374,7 +382,7 @@ class Preview {
/**
* @brief get possible bigger thumbnails of the given image
* @param int $fileId fileId of the original image
- * @return array of paths to bigger thumbnails
+ * @return array an array of paths to bigger thumbnails
*/
private function getPossibleThumbnails($fileId) {
@@ -466,12 +474,12 @@ class Preview {
$fileId = $fileInfo->getId();
$cached = $this->isCached($fileId);
-
if ($cached) {
$stream = $this->userView->fopen($cached, 'r');
$image = new \OC_Image();
$image->loadFromFileHandle($stream);
$this->preview = $image->valid() ? $image : null;
+
$this->resizeAndCrop();
fclose($stream);
}
@@ -497,7 +505,7 @@ class Preview {
$this->resizeAndCrop();
$previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/';
- $cachePath = $previewPath . $maxX . '-' . $maxY . '.png';
+ $cachePath = $this->buildCachePath($fileId);
if ($this->userView->is_dir($this->getThumbnailsFolder() . '/') === false) {
$this->userView->mkdir($this->getThumbnailsFolder() . '/');
@@ -524,20 +532,12 @@ class Preview {
* @brief show preview
* @return void
*/
- public function showPreview() {
+ public function showPreview($mimeType = null) {
\OCP\Response::enableCaching(3600 * 24); // 24 hours
if (is_null($this->preview)) {
$this->getPreview();
}
- $this->preview->show('image/png');
- }
-
- /**
- * @brief show preview
- * @return void
- */
- public function show() {
- $this->showPreview();
+ $this->preview->show($mimeType);
}
/**
@@ -561,6 +561,11 @@ class Preview {
$realX = (int)$image->width();
$realY = (int)$image->height();
+ // compute $maxY using the aspect of the generated preview
+ if ($this->keepAspect) {
+ $y = $x / ($realX / $realY);
+ }
+
if ($x === $realX && $y === $realY) {
$this->preview = $image;
return;
@@ -610,7 +615,7 @@ class Preview {
return;
}
- if ($newXSize < $x || $newYSize < $y) {
+ if (($newXSize < $x || $newYSize < $y) && $scalingUp) {
if ($newXSize > $x) {
$cropX = floor(($newXSize - $x) * 0.5);
$image->crop($cropX, 0, $x, $newYSize);
@@ -743,4 +748,21 @@ class Preview {
}
return false;
}
+
+ /**
+ * @param int $fileId
+ * @return string
+ */
+ private function buildCachePath($fileId) {
+ $maxX = $this->getMaxX();
+ $maxY = $this->getMaxY();
+
+ $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/';
+ $preview = $previewPath . $maxX . '-' . $maxY . '.png';
+ if ($this->keepAspect) {
+ $preview = $previewPath . $maxX . '-with-aspect.png';
+ return $preview;
+ }
+ return $preview;
+ }
}
diff --git a/lib/private/preview/image.php b/lib/private/preview/image.php
index 84343df2608..cec5d7c0170 100644
--- a/lib/private/preview/image.php
+++ b/lib/private/preview/image.php
@@ -22,15 +22,17 @@ class Image extends Provider {
}
$image = new \OC_Image();
- //check if file is encrypted
+
if($fileInfo['encrypted'] === true) {
- $image->loadFromData(stream_get_contents($fileview->fopen($path, 'r')));
- }else{
- $image->loadFromFile($fileview->getLocalFile($path));
+ $fileName = $fileview->toTmpFile($path);
+ } else {
+ $fileName = $fileview->getLocalFile($path);
}
+ $image->loadFromFile($fileName);
return $image->valid() ? $image : false;
}
+
}
-\OC\Preview::registerProvider('OC\Preview\Image'); \ No newline at end of file
+\OC\Preview::registerProvider('OC\Preview\Image');
diff --git a/lib/private/preview/mp3.php b/lib/private/preview/mp3.php
index 3fc0ab0490c..21f160fd50f 100644
--- a/lib/private/preview/mp3.php
+++ b/lib/private/preview/mp3.php
@@ -47,4 +47,4 @@ class MP3 extends Provider {
}
-\OC\Preview::registerProvider('OC\Preview\MP3'); \ No newline at end of file
+\OC\Preview::registerProvider('OC\Preview\MP3');
diff --git a/lib/private/preview/pdf.php b/lib/private/preview/pdf.php
index 064a5a3b3d1..4b88b1a31e2 100644
--- a/lib/private/preview/pdf.php
+++ b/lib/private/preview/pdf.php
@@ -40,6 +40,7 @@ if (extension_loaded('imagick')) {
//check if image object is valid
return $image->valid() ? $image : false;
}
+
}
\OC\Preview::registerProvider('OC\Preview\PDF');
diff --git a/lib/private/preview/provider.php b/lib/private/preview/provider.php
index 88337d64e4b..f769823f6e6 100644
--- a/lib/private/preview/provider.php
+++ b/lib/private/preview/provider.php
@@ -22,4 +22,5 @@ abstract class Provider {
* OC_Image object of the preview
*/
abstract public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview);
+
}
diff --git a/lib/private/preview/svg.php b/lib/private/preview/svg.php
index 505122fddbf..82ef3cdebf6 100644
--- a/lib/private/preview/svg.php
+++ b/lib/private/preview/svg.php
@@ -45,8 +45,9 @@ if (extension_loaded('imagick')) {
//check if image object is valid
return $image->valid() ? $image : false;
}
+
}
\OC\Preview::registerProvider('OC\Preview\SVG');
}
-} \ No newline at end of file
+}
diff --git a/lib/private/request.php b/lib/private/request.php
index 90f7488eea5..cf9a316b851 100755
--- a/lib/private/request.php
+++ b/lib/private/request.php
@@ -18,7 +18,7 @@ class OC_Request {
/**
* @brief Check overwrite condition
* @param string $type
- * @returns bool
+ * @return bool
*/
private static function isOverwriteCondition($type = '') {
$regex = '/' . OC_Config::getValue('overwritecondaddr', '') . '/';
@@ -49,7 +49,7 @@ class OC_Request {
/**
* @brief Returns the unverified server host from the headers without checking
* whether it is a trusted domain
- * @returns string the server host
+ * @return string the server host
*
* Returns the server host, even if the website uses one or more
* reverse proxies
@@ -89,7 +89,7 @@ class OC_Request {
/**
* @brief Returns the server host from the headers, or the first configured
* trusted domain if the host isn't in the trusted list
- * @returns string the server host
+ * @return string the server host
*
* Returns the server host, even if the website uses one or more
* reverse proxies
@@ -121,7 +121,7 @@ class OC_Request {
/**
* @brief Returns the server protocol
- * @returns string the server protocol
+ * @return string the server protocol
*
* Returns the server protocol. It respects reverse proxy servers and load balancers
*/
@@ -143,7 +143,7 @@ class OC_Request {
/**
* @brief Returns the request uri
- * @returns string the request uri
+ * @return string the request uri
*
* Returns the request uri, even if the website uses one or more
* reverse proxies
diff --git a/lib/private/response.php b/lib/private/response.php
index 1aa5e629b8b..f976925fb2e 100644
--- a/lib/private/response.php
+++ b/lib/private/response.php
@@ -93,7 +93,7 @@ class OC_Response {
/**
* @brief Set reponse expire time
- * @param $expires date-time when the response expires
+ * @param string|DateTime $expires date-time when the response expires
* string for DateInterval from now
* DateTime object when to expire response
*/
@@ -113,7 +113,7 @@ class OC_Response {
/**
* Checks and set ETag header, when the request matches sends a
* 'not modified' response
- * @param $etag token to use for modification check
+ * @param string $etag token to use for modification check
*/
static public function setETagHeader($etag) {
if (empty($etag)) {
@@ -131,7 +131,7 @@ class OC_Response {
/**
* Checks and set Last-Modified header, when the request matches sends a
* 'not modified' response
- * @param $lastModified time when the reponse was last modified
+ * @param int|DateTime|string $lastModified time when the reponse was last modified
*/
static public function setLastModifiedHeader($lastModified) {
if (empty($lastModified)) {
@@ -186,4 +186,36 @@ class OC_Response {
self::setStatus(self::STATUS_NOT_FOUND);
}
}
+
+ /*
+ * This function adds some security related headers to all requests served via base.php
+ * The implementation of this function has to happen here to ensure that all third-party
+ * components (e.g. SabreDAV) also benefit from this headers.
+ */
+ public static function addSecurityHeaders() {
+ header('X-XSS-Protection: 1; mode=block'); // Enforce browser based XSS filters
+ header('X-Content-Type-Options: nosniff'); // Disable sniffing the content type for IE
+
+ // iFrame Restriction Policy
+ $xFramePolicy = OC_Config::getValue('xframe_restriction', true);
+ if ($xFramePolicy) {
+ header('X-Frame-Options: Sameorigin'); // Disallow iFraming from other domains
+ }
+
+ // Content Security Policy
+ // If you change the standard policy, please also change it in config.sample.php
+ $policy = OC_Config::getValue('custom_csp_policy',
+ 'default-src \'self\'; '
+ . 'script-src \'self\' \'unsafe-eval\'; '
+ . 'style-src \'self\' \'unsafe-inline\'; '
+ . 'frame-src *; '
+ . 'img-src *; '
+ . 'font-src \'self\' data:; '
+ . 'media-src *');
+ header('Content-Security-Policy:' . $policy);
+
+ // https://developers.google.com/webmasters/control-crawl-index/docs/robots_meta_tag
+ header('X-Robots-Tag: none');
+ }
+
}
diff --git a/lib/private/route/route.php b/lib/private/route/route.php
index df80facf9c1..87030ad7853 100644
--- a/lib/private/route/route.php
+++ b/lib/private/route/route.php
@@ -124,7 +124,7 @@ class Route extends SymfonyRoute implements IRoute {
/**
* The action to execute when this route matches, includes a file like
* it is called directly
- * @param $file
+ * @param string $file
* @return void
*/
public function actionInclude($file) {
diff --git a/lib/private/route/router.php b/lib/private/route/router.php
index f7900362bec..a72ac2bb3f1 100644
--- a/lib/private/route/router.php
+++ b/lib/private/route/router.php
@@ -90,7 +90,7 @@ class Router implements IRouter {
$files[] = 'settings/routes.php';
$files[] = 'core/routes.php';
$files[] = 'ocs/routes.php';
- $this->cacheKey = \OC_Cache::generateCacheKeyFromFiles($files);
+ $this->cacheKey = \OC\Cache::generateCacheKeyFromFiles($files);
}
return $this->cacheKey;
}
@@ -239,7 +239,7 @@ class Router implements IRouter {
/**
* To isolate the variable scope used inside the $file it is required in it's own method
- * @param $file
+ * @param string $file
*/
private function requireRouteFile($file) {
require_once $file;
diff --git a/lib/private/server.php b/lib/private/server.php
index 5d90a0b19fc..47bdee4b0f8 100644
--- a/lib/private/server.php
+++ b/lib/private/server.php
@@ -3,6 +3,7 @@
namespace OC;
use OC\AppFramework\Http\Request;
+use OC\AppFramework\Db\Db;
use OC\AppFramework\Utility\SimpleContainer;
use OC\Cache\UserCache;
use OC\DB\ConnectionWrapper;
@@ -30,9 +31,9 @@ class Server extends SimpleContainer implements IServerContainer {
}
if (\OC::$session->exists('requesttoken')) {
- $requesttoken = \OC::$session->get('requesttoken');
+ $requestToken = \OC::$session->get('requesttoken');
} else {
- $requesttoken = false;
+ $requestToken = false;
}
if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
@@ -54,7 +55,7 @@ class Server extends SimpleContainer implements IServerContainer {
? $_SERVER['REQUEST_METHOD']
: null,
'urlParams' => $urlParams,
- 'requesttoken' => $requesttoken,
+ 'requesttoken' => $requestToken,
), $stream
);
});
@@ -158,6 +159,14 @@ class Server extends SimpleContainer implements IServerContainer {
$this->registerService('AvatarManager', function($c) {
return new AvatarManager();
});
+ $this->registerService('Logger', function($c) {
+ /** @var $c SimpleContainer */
+ $logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud');
+ $logger = 'OC_Log_' . ucfirst($logClass);
+ call_user_func(array($logger, 'init'));
+
+ return new Log($logger);
+ });
$this->registerService('JobList', function ($c) {
/**
* @var Server $c
@@ -177,6 +186,9 @@ class Server extends SimpleContainer implements IServerContainer {
}
return $router;
});
+ $this->registerService('Db', function($c){
+ return new Db();
+ });
}
/**
@@ -240,15 +252,23 @@ class Server extends SimpleContainer implements IServerContainer {
* @return \OCP\Files\Folder
*/
function getUserFolder() {
-
- $dir = '/files';
+ $dir = '/' . \OCP\User::getUser();
$root = $this->getRootFolder();
$folder = null;
+
if(!$root->nodeExists($dir)) {
$folder = $root->newFolder($dir);
} else {
$folder = $root->get($dir);
}
+
+ $dir = '/files';
+ if(!$folder->nodeExists($dir)) {
+ $folder = $folder->newFolder($dir);
+ } else {
+ $folder = $folder->get($dir);
+ }
+
return $folder;
}
@@ -317,14 +337,14 @@ class Server extends SimpleContainer implements IServerContainer {
}
/**
- * @return \OC\URLGenerator
+ * @return \OCP\IURLGenerator
*/
function getURLGenerator() {
return $this->query('URLGenerator');
}
/**
- * @return \OC\Helper
+ * @return \OCP\IHelper
*/
function getHelper() {
return $this->query('AppHelper');
@@ -385,6 +405,15 @@ class Server extends SimpleContainer implements IServerContainer {
}
/**
+ * Returns a logger instance
+ *
+ * @return \OCP\ILogger
+ */
+ function getLogger() {
+ return $this->query('Logger');
+ }
+
+ /**
* Returns a router for generating and matching urls
*
* @return \OCP\Route\IRouter
@@ -392,4 +421,13 @@ class Server extends SimpleContainer implements IServerContainer {
function getRouter(){
return $this->query('Router');
}
+
+
+ /**
+ * Returns an instance of the db facade
+ * @return \OCP\IDb
+ */
+ function getDb() {
+ return $this->query('Db');
+ }
}
diff --git a/lib/private/share/helper.php b/lib/private/share/helper.php
index 515ec85909a..e04180e00e4 100644
--- a/lib/private/share/helper.php
+++ b/lib/private/share/helper.php
@@ -25,13 +25,14 @@ class Helper extends \OC\Share\Constants {
/**
* Generate a unique target for the item
- * @param string Item type
- * @param string Item source
- * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
- * @param string User or group the item is being shared with
- * @param string User that is the owner of shared item
- * @param string The suggested target originating from a reshare (optional)
- * @param int The id of the parent group share (optional)
+ * @param string $itemType
+ * @param string $itemSource
+ * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
+ * @param string $shareWith User or group the item is being shared with
+ * @param string $uidOwner User that is the owner of shared item
+ * @param string $suggestedTarget The suggested target originating from a reshare (optional)
+ * @param int $groupParent The id of the parent group share (optional)
+ * @throws \Exception
* @return string Item target
*/
public static function generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner,
@@ -142,9 +143,9 @@ class Helper extends \OC\Share\Constants {
/**
* Delete all reshares of an item
- * @param int Id of item to delete
- * @param bool If true, exclude the parent from the delete (optional)
- * @param string The user that the parent was shared with (optinal)
+ * @param int $parent Id of item to delete
+ * @param bool $excludeParent If true, exclude the parent from the delete (optional)
+ * @param string $uidOwner The user that the parent was shared with (optional)
*/
public static function delete($parent, $excludeParent = false, $uidOwner = null) {
$ids = array($parent);
@@ -231,7 +232,7 @@ class Helper extends \OC\Share\Constants {
$expires = false;
- if (isset($defaultExpireSettings['defaultExpireDateSet']) && $defaultExpireSettings['defaultExpireDateSet']) {
+ if (!empty($defaultExpireSettings['defaultExpireDateSet'])) {
$expires = $creationTime + $defaultExpireSettings['expireAfterDays'] * 86400;
}
@@ -239,8 +240,8 @@ class Helper extends \OC\Share\Constants {
if (isset($userExpireDate)) {
// if the admin decided to enforce the default expire date then we only take
// the user defined expire date of it is before the default expire date
- if ($expires && isset($defaultExpireSettings['enforceExpireDate']) && $defaultExpireSettings['enforceExpireDate']) {
- $expires = ($userExpireDate < $expires) ? $userExpireDate : $expires;
+ if ($expires && !empty($defaultExpireSettings['enforceExpireDate'])) {
+ $expires = min($userExpireDate, $expires);
} else {
$expires = $userExpireDate;
}
diff --git a/lib/private/share/hooks.php b/lib/private/share/hooks.php
index a33c71eedd2..9ac64d888ea 100644
--- a/lib/private/share/hooks.php
+++ b/lib/private/share/hooks.php
@@ -22,9 +22,9 @@
namespace OC\Share;
class Hooks extends \OC\Share\Constants {
- /**
+ /**
* Function that is called after a user is deleted. Cleans up the shares of that user.
- * @param array arguments
+ * @param array $arguments
*/
public static function post_deleteUser($arguments) {
// Delete any items shared with the deleted user
@@ -42,7 +42,7 @@ class Hooks extends \OC\Share\Constants {
/**
* Function that is called after a user is added to a group.
* TODO what does it do?
- * @param array arguments
+ * @param array $arguments
*/
public static function post_addToGroup($arguments) {
// Find the group shares and check if the user needs a unique target
@@ -76,7 +76,7 @@ class Hooks extends \OC\Share\Constants {
/**
* Function that is called after a user is removed from a group. Shares are cleaned up.
- * @param array arguments
+ * @param array $arguments
*/
public static function post_removeFromGroup($arguments) {
$sql = 'SELECT `id`, `share_type` FROM `*PREFIX*share`'
@@ -95,7 +95,7 @@ class Hooks extends \OC\Share\Constants {
/**
* Function that is called after a group is removed. Cleans up the shares to that group.
- * @param array arguments
+ * @param array $arguments
*/
public static function post_deleteGroup($arguments) {
$sql = 'SELECT `id` FROM `*PREFIX*share` WHERE `share_type` = ? AND `share_with` = ?';
diff --git a/lib/private/share/mailnotifications.php b/lib/private/share/mailnotifications.php
index 4799db52330..ca0dff6562d 100644
--- a/lib/private/share/mailnotifications.php
+++ b/lib/private/share/mailnotifications.php
@@ -21,11 +21,30 @@
namespace OC\Share;
+use DateTime;
+
class MailNotifications {
- private $senderId; // sender userId
- private $from; // sender email address
+ /**
+ * sender userId
+ * @var null|string
+ */
+ private $senderId;
+
+ /**
+ * sender email address
+ * @var string
+ */
+ private $from;
+
+ /**
+ * @var string
+ */
private $senderDisplayName;
+
+ /**
+ * @var \OC_L10N
+ */
private $l;
/**
@@ -50,8 +69,8 @@ class MailNotifications {
* @brief inform users if a file was shared with them
*
* @param array $recipientList list of recipients
- * @param type $itemSource shared item source
- * @param type $itemType shared item type
+ * @param string $itemSource shared item source
+ * @param string $itemType shared item type
* @return array list of user to whom the mail send operation failed
*/
public function sendInternalShareMail($recipientList, $itemSource, $itemType) {
@@ -136,7 +155,7 @@ class MailNotifications {
* @param string $filename the shared file
* @param string $link link to the shared file
* @param int $expiration expiration date (timestamp)
- * @return array with the html mail body and the plain text mail body
+ * @return array an array of the html mail body and the plain text mail body
*/
private function createMailBody($filename, $link, $expiration) {
diff --git a/lib/private/share/searchresultsorter.php b/lib/private/share/searchresultsorter.php
index 76abbf30846..91709902fff 100644
--- a/lib/private/share/searchresultsorter.php
+++ b/lib/private/share/searchresultsorter.php
@@ -18,8 +18,8 @@ class SearchResultSorter {
* @param string $search the search term as was given by the user
* @param string $key the array key containing the value that should be compared
* against
- * @param $encoding optional, encoding to use, defaults to UTF-8
- * @param $log optional, an \OC\Log instance
+ * @param string $encoding optional, encoding to use, defaults to UTF-8
+ * @param \OC\Log $log optional
*/
public function __construct($search, $key, \OC\Log $log = null, $encoding = 'UTF-8') {
$this->encoding = $encoding;
diff --git a/lib/private/share/share.php b/lib/private/share/share.php
index b12d62e8439..2846631a693 100644
--- a/lib/private/share/share.php
+++ b/lib/private/share/share.php
@@ -48,11 +48,11 @@ class Share extends \OC\Share\Constants {
/**
* Register a sharing backend class that implements OCP\Share_Backend for an item type
- * @param string Item type
- * @param string Backend class
- * @param string (optional) Depends on item type
- * @param array (optional) List of supported file extensions if this item type depends on files
- * @return Returns true if backend is registered or false if error
+ * @param string $itemType Item type
+ * @param string $class Backend class
+ * @param string $collectionOf (optional) Depends on item type
+ * @param array $supportedFileExtensions (optional) List of supported file extensions if this item type depends on files
+ * @return boolean true if backend is registered or false if error
*/
public static function registerBackend($itemType, $class, $collectionOf = null, $supportedFileExtensions = null) {
if (self::isEnabled()) {
@@ -78,7 +78,7 @@ class Share extends \OC\Share\Constants {
/**
* Check if the Share API is enabled
- * @return Returns true if enabled or false
+ * @return boolean true if enabled or false
*
* The Share API is enabled by default if not configured
*/
@@ -93,8 +93,8 @@ class Share extends \OC\Share\Constants {
* Find which users can access a shared item
* @param string $path to the file
* @param string $ownerUser owner of the file
- * @param bool $includeOwner include owner to the list of users with access to the file
- * @param bool $returnUserPaths Return an array with the user => path map
+ * @param boolean $includeOwner include owner to the list of users with access to the file
+ * @param boolean $returnUserPaths Return an array with the user => path map
* @return array
* @note $path needs to be relative to user data dir, e.g. 'file.txt'
* not '/admin/data/file.txt'
@@ -239,12 +239,12 @@ class Share extends \OC\Share\Constants {
/**
* Get the items of item type shared with the current user
- * @param string Item type
- * @param int Format (optional) Format type must be defined by the backend
- * @param mixed Parameters (optional)
- * @param int Number of items to return (optional) Returns all by default
- * @param bool include collections (optional)
- * @return Return depends on format
+ * @param string $itemType
+ * @param int $format (optional) Format type must be defined by the backend
+ * @param mixed $parameters (optional)
+ * @param int $limit Number of items to return (optional) Returns all by default
+ * @param boolean $includeCollections (optional)
+ * @return mixed Return depends on format
*/
public static function getItemsSharedWith($itemType, $format = self::FORMAT_NONE,
$parameters = null, $limit = -1, $includeCollections = false) {
@@ -254,13 +254,13 @@ class Share extends \OC\Share\Constants {
/**
* Get the items of item type shared with a user
- * @param string Item type
- * @param sting user id for which user we want the shares
- * @param int Format (optional) Format type must be defined by the backend
- * @param mixed Parameters (optional)
- * @param int Number of items to return (optional) Returns all by default
- * @param bool include collections (optional)
- * @return Return depends on format
+ * @param string $itemType
+ * @param string $user id for which user we want the shares
+ * @param int $format (optional) Format type must be defined by the backend
+ * @param mixed $parameters (optional)
+ * @param int $limit Number of items to return (optional) Returns all by default
+ * @param boolean $includeCollections (optional)
+ * @return mixed Return depends on format
*/
public static function getItemsSharedWithUser($itemType, $user, $format = self::FORMAT_NONE,
$parameters = null, $limit = -1, $includeCollections = false) {
@@ -273,9 +273,9 @@ class Share extends \OC\Share\Constants {
* @param string $itemType
* @param string $itemTarget
* @param int $format (optional) Format type must be defined by the backend
- * @param mixed Parameters (optional)
- * @param bool include collections (optional)
- * @return Return depends on format
+ * @param mixed $parameters (optional)
+ * @param boolean $includeCollections (optional)
+ * @return mixed Return depends on format
*/
public static function getItemSharedWith($itemType, $itemTarget, $format = self::FORMAT_NONE,
$parameters = null, $includeCollections = false) {
@@ -334,12 +334,12 @@ class Share extends \OC\Share\Constants {
/**
* Get the item of item type shared with the current user by source
- * @param string Item type
- * @param string Item source
- * @param int Format (optional) Format type must be defined by the backend
- * @param mixed Parameters
- * @param bool include collections
- * @return Return depends on format
+ * @param string $itemType
+ * @param string $itemSource
+ * @param int $format (optional) Format type must be defined by the backend
+ * @param mixed $parameters
+ * @param boolean $includeCollections
+ * @return mixed Return depends on format
*/
public static function getItemSharedWithBySource($itemType, $itemSource, $format = self::FORMAT_NONE,
$parameters = null, $includeCollections = false) {
@@ -349,10 +349,10 @@ class Share extends \OC\Share\Constants {
/**
* Get the item of item type shared by a link
- * @param string Item type
- * @param string Item source
- * @param string Owner of link
- * @return Item
+ * @param string $itemType
+ * @param string $itemSource
+ * @param string $uidOwner Owner of link
+ * @return array
*/
public static function getItemSharedWithByLink($itemType, $itemSource, $uidOwner) {
return self::getItems($itemType, $itemSource, self::SHARE_TYPE_LINK, null, $uidOwner, self::FORMAT_NONE,
@@ -362,7 +362,7 @@ class Share extends \OC\Share\Constants {
/**
* Based on the given token the share information will be returned - password protected shares will be verified
* @param string $token
- * @return array | bool false will be returned in case the token is unknown or unauthorized
+ * @return array|boolean false will be returned in case the token is unknown or unauthorized
*/
public static function getShareByToken($token, $checkPasswordProtection = true) {
$query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share` WHERE `token` = ?', 1);
@@ -388,8 +388,8 @@ class Share extends \OC\Share\Constants {
/**
* resolves reshares down to the last real share
- * @param $linkItem
- * @return $fileOwner
+ * @param array $linkItem
+ * @return array file owner
*/
public static function resolveReShare($linkItem)
{
@@ -411,12 +411,12 @@ class Share extends \OC\Share\Constants {
/**
* Get the shared items of item type owned by the current user
- * @param string Item type
- * @param int Format (optional) Format type must be defined by the backend
- * @param mixed Parameters
- * @param int Number of items to return (optional) Returns all by default
- * @param bool include collections
- * @return Return depends on format
+ * @param string $itemType
+ * @param int $format (optional) Format type must be defined by the backend
+ * @param mixed $parameters
+ * @param int $limit Number of items to return (optional) Returns all by default
+ * @param boolean $includeCollections
+ * @return mixed Return depends on format
*/
public static function getItemsShared($itemType, $format = self::FORMAT_NONE, $parameters = null,
$limit = -1, $includeCollections = false) {
@@ -426,12 +426,12 @@ class Share extends \OC\Share\Constants {
/**
* Get the shared item of item type owned by the current user
- * @param string Item type
- * @param string Item source
- * @param int Format (optional) Format type must be defined by the backend
- * @param mixed Parameters
- * @param bool include collections
- * @return Return depends on format
+ * @param string $itemType
+ * @param string $itemSource
+ * @param int $format (optional) Format type must be defined by the backend
+ * @param mixed $parameters
+ * @param boolean $includeCollections
+ * @return mixed Return depends on format
*/
public static function getItemShared($itemType, $itemSource, $format = self::FORMAT_NONE,
$parameters = null, $includeCollections = false) {
@@ -441,12 +441,12 @@ class Share extends \OC\Share\Constants {
/**
* Get all users an item is shared with
- * @param string Item type
- * @param string Item source
- * @param string Owner
- * @param bool Include collections
- * @praram bool check expire date
- * @return Return array of users
+ * @param string $itemType
+ * @param string $itemSource
+ * @param string $uidOwner
+ * @param boolean $includeCollections
+ * @param boolean $checkExpireDate
+ * @return array Return array of users
*/
public static function getUsersItemShared($itemType, $itemSource, $uidOwner, $includeCollections = false, $checkExpireDate = true) {
@@ -471,16 +471,12 @@ class Share extends \OC\Share\Constants {
* @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
* @param string $shareWith User or group the item is being shared with
* @param int $permissions CRUDS
- * @param null $itemSourceName
+ * @param string $itemSourceName
+ * @param \DateTime $expirationDate
+ * @return boolean|string Returns true on success or false on failure, Returns token on success for links
* @throws \Exception
- * @internal param \OCP\Item $string type
- * @internal param \OCP\Item $string source
- * @internal param \OCP\SHARE_TYPE_USER $int , SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
- * @internal param \OCP\User $string or group the item is being shared with
- * @internal param \OCP\CRUDS $int permissions
- * @return bool|string Returns true on success or false on failure, Returns token on success for links
*/
- public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName = null) {
+ public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName = null, \DateTime $expirationDate = null) {
$uidOwner = \OC_User::getUser();
$sharingPolicy = \OC_Appconfig::getValue('core', 'shareapi_share_policy', 'global');
$l = \OC_L10N::get('lib');
@@ -489,7 +485,6 @@ class Share extends \OC\Share\Constants {
$itemSourceName = $itemSource;
}
-
// verify that the file exists before we try to share it
if ($itemType === 'file' or $itemType === 'folder') {
$path = \OC\Files\Filesystem::getPath($itemSource);
@@ -588,7 +583,9 @@ class Share extends \OC\Share\Constants {
$shareWith['users'] = array_diff(\OC_Group::usersInGroup($group), array($uidOwner));
} else if ($shareType === self::SHARE_TYPE_LINK) {
if (\OC_Appconfig::getValue('core', 'shareapi_allow_links', 'yes') == 'yes') {
+
// when updating a link share
+ // FIXME Don't delete link if we update it
if ($checkExists = self::getItems($itemType, $itemSource, self::SHARE_TYPE_LINK, null,
$uidOwner, self::FORMAT_NONE, null, 1)) {
// remember old token
@@ -599,7 +596,7 @@ class Share extends \OC\Share\Constants {
}
// Generate hash of password - same method as user passwords
- if (isset($shareWith)) {
+ if (!empty($shareWith)) {
$forcePortable = (CRYPT_BLOWFISH != 1);
$hasher = new \PasswordHash(8, $forcePortable);
$shareWith = $hasher->HashPassword($shareWith.\OC_Config::getValue('passwordsalt', ''));
@@ -611,6 +608,13 @@ class Share extends \OC\Share\Constants {
}
}
+ if (\OCP\Util::isPublicLinkPasswordRequired() && empty($shareWith)) {
+ $message = 'You need to provide a password to create a public link, only protected links are allowed';
+ $message_t = $l->t('You need to provide a password to create a public link, only protected links are allowed');
+ \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
+ throw new \Exception($message_t);
+ }
+
// Generate token
if (isset($oldToken)) {
$token = $oldToken;
@@ -618,7 +622,7 @@ class Share extends \OC\Share\Constants {
$token = \OC_Util::generateRandomBytes(self::TOKEN_LENGTH);
}
$result = self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions,
- null, $token, $itemSourceName);
+ null, $token, $itemSourceName, $expirationDate);
if ($result) {
return $token;
} else {
@@ -637,17 +641,18 @@ class Share extends \OC\Share\Constants {
\OC_Log::write('OCP\Share', sprintf($message, $shareType, $itemSource), \OC_Log::ERROR);
throw new \Exception($message_t);
}
- // Put the item into the database
- return self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, null, null, $itemSourceName);
+
+ // Put the item into the database
+ return self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, null, null, $itemSourceName, $expirationDate);
}
/**
* Unshare an item from a user, group, or delete a private link
- * @param string Item type
- * @param string Item source
- * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
- * @param string User or group the item is being shared with
- * @return Returns true on success or false on failure
+ * @param string $itemType
+ * @param string $itemSource
+ * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
+ * @param string $shareWith User or group the item is being shared with
+ * @return boolean true on success or false on failure
*/
public static function unshare($itemType, $itemSource, $shareType, $shareWith) {
$item = self::getItems($itemType, $itemSource, $shareType, $shareWith, \OC_User::getUser(),self::FORMAT_NONE, null, 1);
@@ -660,9 +665,9 @@ class Share extends \OC\Share\Constants {
/**
* Unshare an item from all users, groups, and remove all links
- * @param string Item type
- * @param string Item source
- * @return Returns true on success or false on failure
+ * @param string $itemType
+ * @param string $itemSource
+ * @return boolean true on success or false on failure
*/
public static function unshareAll($itemType, $itemSource) {
// Get all of the owners of shares of this item.
@@ -692,9 +697,9 @@ class Share extends \OC\Share\Constants {
/**
* Unshare an item shared with the current user
- * @param string Item type
- * @param string Item target
- * @return Returns true on success or false on failure
+ * @param string $itemType
+ * @param string $itemTarget
+ * @return boolean true on success or false on failure
*
* Unsharing from self is not allowed for items inside collections
*/
@@ -727,12 +732,13 @@ class Share extends \OC\Share\Constants {
}
return false;
}
+
/**
* sent status if users got informed by mail about share
* @param string $itemType
* @param string $itemSource
* @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
- * @param bool $status
+ * @param boolean $status
*/
public static function setSendMailStatus($itemType, $itemSource, $shareType, $status) {
$status = $status ? 1 : 0;
@@ -751,12 +757,12 @@ class Share extends \OC\Share\Constants {
/**
* Set the permissions of an item for a specific user or group
- * @param string Item type
- * @param string Item source
- * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
- * @param string User or group the item is being shared with
- * @param int CRUDS permissions
- * @return Returns true on success or false on failure
+ * @param string $itemType
+ * @param string $itemSource
+ * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
+ * @param string $shareWith User or group the item is being shared with
+ * @param int $permissions CRUDS permissions
+ * @return boolean true on success or false on failure
*/
public static function setPermissions($itemType, $itemSource, $shareType, $shareWith, $permissions) {
$l = \OC_L10N::get('lib');
@@ -842,7 +848,7 @@ class Share extends \OC\Share\Constants {
* @param string $itemType
* @param string $itemSource
* @param string $date expiration date
- * @return \OCP\Share_Backend
+ * @return boolean
*/
public static function setExpirationDate($itemType, $itemSource, $date) {
$user = \OC_User::getUser();
@@ -873,20 +879,24 @@ class Share extends \OC\Share\Constants {
/**
* Checks whether a share has expired, calls unshareItem() if yes.
* @param array $item Share data (usually database row)
- * @return bool True if item was expired, false otherwise.
+ * @return boolean True if item was expired, false otherwise.
*/
protected static function expireItem(array $item) {
- // get default expire settings
- $defaultSettings = Helper::getDefaultExpireSetting();
// calculate expire date
if (!empty($item['expiration'])) {
$userDefinedExpire = new \DateTime($item['expiration']);
- $userDefinedExpireTimestamp = $userDefinedExpire->getTimestamp();
+ $expires = $userDefinedExpire->getTimestamp();
} else {
- $userDefinedExpireTimestamp = null;
+ $expires = null;
+ }
+
+ // only use default expire date for link shares
+ if((int)$item['share_type'] === self::SHARE_TYPE_LINK) {
+ // get default expire settings
+ $defaultSettings = Helper::getDefaultExpireSetting();
+ $expires = Helper::calculateExpireDate($defaultSettings, $item['stime'], $expires);
}
- $expires = Helper::calculateExpireDate($defaultSettings, $item['stime'], $userDefinedExpireTimestamp);
if (is_int($expires)) {
$now = time();
@@ -925,6 +935,7 @@ class Share extends \OC\Share\Constants {
/**
* Get the backend class for the specified item type
* @param string $itemType
+ * @throws \Exception
* @return \OCP\Share_Backend
*/
public static function getBackend($itemType) {
@@ -957,7 +968,7 @@ class Share extends \OC\Share\Constants {
/**
* Check if resharing is allowed
- * @return Returns true if allowed or false
+ * @return boolean true if allowed or false
*
* Resharing is allowed by default if not configured
*/
@@ -974,7 +985,7 @@ class Share extends \OC\Share\Constants {
/**
* Get a list of collection item types for the specified item type
- * @param string Item type
+ * @param string $itemType
* @return array
*/
private static function getCollectionItemTypes($itemType) {
@@ -998,17 +1009,17 @@ class Share extends \OC\Share\Constants {
/**
* Get shared items from the database
- * @param string Item type
- * @param string Item source or target (optional)
- * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, SHARE_TYPE_LINK, $shareTypeUserAndGroups, or $shareTypeGroupUserUnique
- * @param string User or group the item is being shared with
- * @param string User that is the owner of shared items (optional)
- * @param int Format to convert items to with formatItems()
- * @param mixed Parameters to pass to formatItems()
- * @param int Number of items to return, -1 to return all matches (optional)
- * @param bool Include collection item types (optional)
- * @param bool TODO (optional)
- * @prams bool check expire date
+ * @param string $itemType
+ * @param string $item Item source or target (optional)
+ * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, SHARE_TYPE_LINK, $shareTypeUserAndGroups, or $shareTypeGroupUserUnique
+ * @param string $shareWith User or group the item is being shared with
+ * @param string $uidOwner User that is the owner of shared items (optional)
+ * @param int $format Format to convert items to with formatItems() (optional)
+ * @param mixed $parameters to pass to formatItems() (optional)
+ * @param int $limit Number of items to return, -1 to return all matches (optional)
+ * @param boolean $includeCollections Include collection item types (optional)
+ * @param boolean $itemShareWithBySource (optional)
+ * @param boolean $checkExpireDate
* @return array
*
* See public functions getItem(s)... for parameter usage
@@ -1343,19 +1354,21 @@ class Share extends \OC\Share\Constants {
/**
* Put shared item into the database
- * @param string Item type
- * @param string Item source
- * @param int SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
- * @param string User or group the item is being shared with
- * @param string User that is the owner of shared item
- * @param int CRUDS permissions
- * @param bool|array Parent folder target (optional)
- * @param string token (optional)
- * @param string name of the source item (optional)
- * @return bool Returns true on success or false on failure
+ * @param string $itemType Item type
+ * @param string $itemSource Item source
+ * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
+ * @param string $shareWith User or group the item is being shared with
+ * @param string $uidOwner User that is the owner of shared item
+ * @param int $permissions CRUDS permissions
+ * @param boolean|array $parentFolder Parent folder target (optional)
+ * @param string $token (optional)
+ * @param string $itemSourceName name of the source item (optional)
+ * @param \DateTime $expirationDate (optional)
+ * @throws \Exception
+ * @return boolean Returns true on success or false on failure
*/
private static function put($itemType, $itemSource, $shareType, $shareWith, $uidOwner,
- $permissions, $parentFolder = null, $token = null, $itemSourceName = null) {
+ $permissions, $parentFolder = null, $token = null, $itemSourceName = null, \DateTime $expirationDate = null) {
$backend = self::getBackend($itemType);
$l = \OC_L10N::get('lib');
// Check if this is a reshare
@@ -1385,6 +1398,7 @@ class Share extends \OC\Share\Constants {
$suggestedItemTarget = $checkReshare['item_target'];
$suggestedFileTarget = $checkReshare['file_target'];
$filePath = $checkReshare['file_target'];
+ $expirationDate = min($expirationDate, $checkReshare['expiration']);
}
} else {
$message = 'Sharing %s failed, because resharing is not allowed';
@@ -1424,9 +1438,7 @@ class Share extends \OC\Share\Constants {
$fileSource = null;
}
}
- $query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (`item_type`, `item_source`, `item_target`,'
- .' `share_type`, `share_with`, `uid_owner`, `permissions`, `stime`, `file_source`,'
- .' `file_target`, `token`, `parent`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)');
+
// Share with a group
if ($shareType == self::SHARE_TYPE_GROUP) {
$groupItemTarget = Helper::generateTarget($itemType, $itemSource, $shareType, $shareWith['group'],
@@ -1442,6 +1454,7 @@ class Share extends \OC\Share\Constants {
'uidOwner' => $uidOwner,
'permissions' => $permissions,
'fileSource' => $fileSource,
+ 'expiration' => $expirationDate,
'token' => $token,
'run' => &$run,
'error' => &$error
@@ -1471,8 +1484,21 @@ class Share extends \OC\Share\Constants {
$groupFileTarget = null;
}
$queriesToExecute = array();
- $queriesToExecute['groupShare'] = array($itemType, $itemSource, $groupItemTarget, $shareType,
- $shareWith['group'], $uidOwner, $permissions, time(), $fileSource, $groupFileTarget, $token, $parent);
+ $queriesToExecute['groupShare'] = array(
+ 'itemType' => $itemType,
+ 'itemSource' => $itemSource,
+ 'itemTarget' => $groupItemTarget,
+ 'shareType' => $shareType,
+ 'shareWith' => $shareWith['group'],
+ 'uidOwner' => $uidOwner,
+ 'permissions' => $permissions,
+ 'shareTime' => time(),
+ 'fileSource' => $fileSource,
+ 'fileTarget' => $groupFileTarget,
+ 'token' => $token,
+ 'parent' => $parent,
+ 'expiration' => $expirationDate,
+ );
// Loop through all users of this group in case we need to add an extra row
foreach ($shareWith['users'] as $uid) {
$itemTarget = Helper::generateTarget($itemType, $itemSource, self::SHARE_TYPE_USER, $uid,
@@ -1498,19 +1524,32 @@ class Share extends \OC\Share\Constants {
}
// Insert an extra row for the group share if the item or file target is unique for this user
if ($itemTarget != $groupItemTarget || (isset($fileSource) && $fileTarget != $groupFileTarget)) {
- $queriesToExecute[] = array($itemType, $itemSource, $itemTarget,
- self::$shareTypeGroupUserUnique, $uid, $uidOwner, $permissions, time(),
- $fileSource, $fileTarget, $token);
- $id = \OC_DB::insertid('*PREFIX*share');
+ $queriesToExecute[] = array(
+ 'itemType' => $itemType,
+ 'itemSource' => $itemSource,
+ 'itemTarget' => $itemTarget,
+ 'shareType' => self::$shareTypeGroupUserUnique,
+ 'shareWith' => $uid,
+ 'uidOwner' => $uidOwner,
+ 'permissions' => $permissions,
+ 'shareTime' => time(),
+ 'fileSource' => $fileSource,
+ 'fileTarget' => $fileTarget,
+ 'token' => $token,
+ //'parent' => $parent,
+ 'expiration' => $expirationDate,
+ );
}
}
- $query->execute($queriesToExecute['groupShare']);
+
+ self::insertShare($queriesToExecute['groupShare']);
// Save this id, any extra rows for this group share will need to reference it
$parent = \OC_DB::insertid('*PREFIX*share');
unset($queriesToExecute['groupShare']);
- foreach ($queriesToExecute as $qe) {
- $qe[] = $parent;
- $query->execute($qe);
+
+ foreach ($queriesToExecute as $shareQuery) {
+ $shareQuery['parent'] = $parent;
+ self::insertShare($shareQuery);
}
\OC_Hook::emit('OCP\Share', 'post_shared', array(
@@ -1525,7 +1564,8 @@ class Share extends \OC\Share\Constants {
'fileSource' => $fileSource,
'fileTarget' => $groupFileTarget,
'id' => $parent,
- 'token' => $token
+ 'token' => $token,
+ 'expirationDate' => $expirationDate,
));
if ($parentFolder === true) {
@@ -1547,8 +1587,9 @@ class Share extends \OC\Share\Constants {
'permissions' => $permissions,
'fileSource' => $fileSource,
'token' => $token,
+ 'expirationDate' => $expirationDate,
'run' => &$run,
- 'error' => &$error
+ 'error' => &$error,
));
if ($run === false) {
@@ -1572,8 +1613,23 @@ class Share extends \OC\Share\Constants {
} else {
$fileTarget = null;
}
- $query->execute(array($itemType, $itemSource, $itemTarget, $shareType, $shareWith, $uidOwner,
- $permissions, time(), $fileSource, $fileTarget, $token, $parent));
+
+ self::insertShare(array(
+ 'itemType' => $itemType,
+ 'itemSource' => $itemSource,
+ 'itemTarget' => $itemTarget,
+ 'shareType' => $shareType,
+ 'shareWith' => $shareWith,
+ 'uidOwner' => $uidOwner,
+ 'permissions' => $permissions,
+ 'shareTime' => time(),
+ 'fileSource' => $fileSource,
+ 'fileTarget' => $fileTarget,
+ 'token' => $token,
+ 'parent' => $parent,
+ 'expiration' => $expirationDate,
+ ));
+
$id = \OC_DB::insertid('*PREFIX*share');
\OC_Hook::emit('OCP\Share', 'post_shared', array(
'itemType' => $itemType,
@@ -1587,7 +1643,8 @@ class Share extends \OC\Share\Constants {
'fileSource' => $fileSource,
'fileTarget' => $fileTarget,
'id' => $id,
- 'token' => $token
+ 'token' => $token,
+ 'expirationDate' => $expirationDate,
));
if ($parentFolder === true) {
$parentFolders['id'] = $id;
@@ -1598,6 +1655,27 @@ class Share extends \OC\Share\Constants {
return true;
}
+ private static function insertShare(array $shareData)
+ {
+ $query = \OC_DB::prepare('INSERT INTO `*PREFIX*share` ('
+ .' `item_type`, `item_source`, `item_target`, `share_type`,'
+ .' `share_with`, `uid_owner`, `permissions`, `stime`, `file_source`,'
+ .' `file_target`, `token`, `parent`, `expiration`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)');
+ $query->bindValue(1, $shareData['itemType']);
+ $query->bindValue(2, $shareData['itemSource']);
+ $query->bindValue(3, $shareData['itemTarget']);
+ $query->bindValue(4, $shareData['shareType']);
+ $query->bindValue(5, $shareData['shareWith']);
+ $query->bindValue(6, $shareData['uidOwner']);
+ $query->bindValue(7, $shareData['permissions']);
+ $query->bindValue(8, $shareData['shareTime']);
+ $query->bindValue(9, $shareData['fileSource']);
+ $query->bindValue(10, $shareData['fileTarget']);
+ $query->bindValue(11, $shareData['token']);
+ $query->bindValue(12, $shareData['parent']);
+ $query->bindValue(13, $shareData['expiration'], 'datetime');
+ $query->execute();
+ }
/**
* Delete all shares with type SHARE_TYPE_LINK
*/
@@ -1614,7 +1692,7 @@ class Share extends \OC\Share\Constants {
* In case a password protected link is not yet authenticated this function will return false
*
* @param array $linkItem
- * @return bool
+ * @return boolean
*/
public static function checkPasswordProtectedShare(array $linkItem) {
if (!isset($linkItem['share_with'])) {
@@ -1640,9 +1718,9 @@ class Share extends \OC\Share\Constants {
}
/**
- * @breif construct select statement
+ * @brief construct select statement
* @param int $format
- * @param bool $fileDependent ist it a file/folder share or a generla share
+ * @param boolean $fileDependent ist it a file/folder share or a generla share
* @param string $uidOwner
* @return string select statement
*/
@@ -1717,11 +1795,11 @@ class Share extends \OC\Share\Constants {
/**
* @brief format result
* @param array $items result
- * @prams string $column is it a file share or a general share ('file_target' or 'item_target')
- * @params \OCP\Share_Backend $backend sharing backend
+ * @param string $column is it a file share or a general share ('file_target' or 'item_target')
+ * @param \OCP\Share_Backend $backend sharing backend
* @param int $format
- * @param array additional format parameters
- * @return array formate result
+ * @param array $parameters additional format parameters
+ * @return array format result
*/
private static function formatResult($items, $column, $backend, $format = self::FORMAT_NONE , $parameters = null) {
if ($format === self::FORMAT_NONE) {
diff --git a/lib/private/subadmin.php b/lib/private/subadmin.php
index 5b6072987ad..3e8b73d55b0 100644
--- a/lib/private/subadmin.php
+++ b/lib/private/subadmin.php
@@ -167,7 +167,7 @@ class OC_SubAdmin{
/**
* @brief delete all SubAdmins by uid
- * @param $parameters
+ * @param array $parameters
* @return boolean
*/
public static function post_deleteUser($parameters) {
@@ -178,7 +178,7 @@ class OC_SubAdmin{
/**
* @brief delete all SubAdmins by gid
- * @param $parameters
+ * @param array $parameters
* @return boolean
*/
public static function post_deleteGroup($parameters) {
diff --git a/lib/private/tags.php b/lib/private/tags.php
index 06550068f76..0b62caf2dd8 100644
--- a/lib/private/tags.php
+++ b/lib/private/tags.php
@@ -121,21 +121,7 @@ class Tags implements \OCP\ITags {
* @return boolean.
*/
public function isEmpty() {
- $sql = 'SELECT COUNT(*) FROM `' . self::TAG_TABLE . '` '
- . 'WHERE `uid` = ? AND `type` = ?';
- try {
- $stmt = \OCP\DB::prepare($sql);
- $result = $stmt->execute(array($this->user, $this->type));
- if (\OCP\DB::isError($result)) {
- \OCP\Util::writeLog('core', __METHOD__. ', DB error: ' . \OCP\DB::getErrorMessage($result), \OCP\Util::ERROR);
- return false;
- }
- return ((int)$result->fetchOne() === 0);
- } catch(\Exception $e) {
- \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
- \OCP\Util::ERROR);
- return false;
- }
+ return count($this->tags) === 0;
}
/**
@@ -184,6 +170,10 @@ class Tags implements \OCP\ITags {
$tagId = $tag;
} elseif(is_string($tag)) {
$tag = trim($tag);
+ if($tag === '') {
+ \OCP\Util::writeLog('core', __METHOD__.', Cannot use empty tag names', \OCP\Util::DEBUG);
+ return false;
+ }
$tagId = $this->array_searchi($tag, $this->tags);
}
@@ -234,11 +224,15 @@ class Tags implements \OCP\ITags {
* Add a new tag.
*
* @param string $name A string with a name of the tag
- * @return false|string the id of the added tag or false if it already exists.
+ * @return false|string the id of the added tag or false on error.
*/
public function add($name) {
$name = trim($name);
+ if($name === '') {
+ \OCP\Util::writeLog('core', __METHOD__.', Cannot add an empty tag', \OCP\Util::DEBUG);
+ return false;
+ }
if($this->hasTag($name)) {
\OCP\Util::writeLog('core', __METHOD__.', name: ' . $name. ' exists already', \OCP\Util::DEBUG);
return false;
@@ -280,6 +274,12 @@ class Tags implements \OCP\ITags {
public function rename($from, $to) {
$from = trim($from);
$to = trim($to);
+
+ if($to === '' || $from === '') {
+ \OCP\Util::writeLog('core', __METHOD__.', Cannot use empty tag names', \OCP\Util::DEBUG);
+ return false;
+ }
+
$id = $this->array_searchi($from, $this->tags);
if($id === false) {
\OCP\Util::writeLog('core', __METHOD__.', tag: ' . $from. ' does not exist', \OCP\Util::DEBUG);
@@ -318,6 +318,8 @@ class Tags implements \OCP\ITags {
$names = array($names);
}
$names = array_map('trim', $names);
+ array_filter($names);
+
$newones = array();
foreach($names as $name) {
if(($this->in_arrayi(
@@ -391,7 +393,7 @@ class Tags implements \OCP\ITags {
*
* For hooking up on post_deleteUser
*
- * @param array
+ * @param array $arguments
*/
public static function post_deleteUser($arguments) {
// Find all objectid/tagId pairs.
@@ -492,9 +494,9 @@ class Tags implements \OCP\ITags {
*/
public function addToFavorites($objid) {
if(!$this->hasTag(self::TAG_FAVORITE)) {
- $this->add(self::TAG_FAVORITE, true);
+ $this->add(self::TAG_FAVORITE);
}
- return $this->tagAs($objid, self::TAG_FAVORITE, $this->type);
+ return $this->tagAs($objid, self::TAG_FAVORITE);
}
/**
@@ -504,7 +506,7 @@ class Tags implements \OCP\ITags {
* @return boolean
*/
public function removeFromFavorites($objid) {
- return $this->unTag($objid, self::TAG_FAVORITE, $this->type);
+ return $this->unTag($objid, self::TAG_FAVORITE);
}
/**
@@ -512,13 +514,17 @@ class Tags implements \OCP\ITags {
*
* @param int $objid The id of the object
* @param string $tag The id or name of the tag
- * @return boolean Returns false on database error.
+ * @return boolean Returns false on error.
*/
public function tagAs($objid, $tag) {
if(is_string($tag) && !is_numeric($tag)) {
$tag = trim($tag);
+ if($tag === '') {
+ \OCP\Util::writeLog('core', __METHOD__.', Cannot add an empty tag', \OCP\Util::DEBUG);
+ return false;
+ }
if(!$this->hasTag($tag)) {
- $this->add($tag, true);
+ $this->add($tag);
}
$tagId = $this->array_searchi($tag, $this->tags);
} else {
@@ -549,6 +555,10 @@ class Tags implements \OCP\ITags {
public function unTag($objid, $tag) {
if(is_string($tag) && !is_numeric($tag)) {
$tag = trim($tag);
+ if($tag === '') {
+ \OCP\Util::writeLog('core', __METHOD__.', Tag name is empty', \OCP\Util::DEBUG);
+ return false;
+ }
$tagId = $this->array_searchi($tag, $this->tags);
} else {
$tagId = $tag;
@@ -579,6 +589,7 @@ class Tags implements \OCP\ITags {
}
$names = array_map('trim', $names);
+ array_filter($names);
\OCP\Util::writeLog('core', __METHOD__ . ', before: '
. print_r($this->tags, true), \OCP\Util::DEBUG);
diff --git a/lib/private/template.php b/lib/private/template.php
index 3d18b52bac9..dfeb5d14b08 100644
--- a/lib/private/template.php
+++ b/lib/private/template.php
@@ -30,6 +30,7 @@ class OC_Template extends \OC\Template\Base {
private $renderas; // Create a full page?
private $path; // The path to the template
private $headers=array(); //custom headers
+ protected $app; // app id
/**
* @brief Constructor
@@ -62,6 +63,7 @@ class OC_Template extends \OC\Template\Base {
// Set the private data
$this->renderas = $renderas;
$this->path = $path;
+ $this->app = $app;
parent::__construct($template, $requesttoken, $l10n, $themeDefaults);
}
@@ -172,7 +174,7 @@ class OC_Template extends \OC\Template\Base {
$data = parent::fetchPage();
if( $this->renderas ) {
- $page = new OC_TemplateLayout($this->renderas);
+ $page = new OC_TemplateLayout($this->renderas, $this->app);
// Add custom headers
$page->assign('headers', $this->headers, false);
diff --git a/lib/private/template/functions.php b/lib/private/template/functions.php
index 3c42d441efa..3f5312c0a7b 100644
--- a/lib/private/template/functions.php
+++ b/lib/private/template/functions.php
@@ -70,8 +70,8 @@ function mimetype_icon( $mimetype ) {
/**
* @brief make preview_icon available as a simple function
* Returns the path to the preview of the image.
- * @param $path path of file
- * @returns link to the preview
+ * @param string $path path of file
+ * @return link to the preview
*
* For further information have a look at OC_Helper::previewIcon
*/
diff --git a/lib/private/template/resourcelocator.php b/lib/private/template/resourcelocator.php
index 8a3dd5e7fa9..900aa6a8f08 100644
--- a/lib/private/template/resourcelocator.php
+++ b/lib/private/template/resourcelocator.php
@@ -53,13 +53,9 @@ abstract class ResourceLocator {
/*
* @brief append the $file resource if exist at $root
- * @param $root path to check
- * @param $file the filename
- * @param $web base for path, default map $root to $webroot
- */
- /**
- * @param string $file
- * @param string|false $webroot
+ * @param string $root path to check
+ * @param string $file the filename
+ * @param string|null $webroot base for path, default map $root to $webroot
*/
protected function appendIfExist($root, $file, $webroot = null) {
if (is_file($root.'/'.$file)) {
diff --git a/lib/private/templatelayout.php b/lib/private/templatelayout.php
index b7ac02a753d..a5dd9a0c614 100644
--- a/lib/private/templatelayout.php
+++ b/lib/private/templatelayout.php
@@ -15,8 +15,9 @@ class OC_TemplateLayout extends OC_Template {
/**
* @param string $renderas
+ * @param string $appid application id
*/
- public function __construct( $renderas ) {
+ public function __construct( $renderas, $appid = '' ) {
// Decide which page we show
if( $renderas == 'user' ) {
@@ -43,6 +44,7 @@ class OC_TemplateLayout extends OC_Template {
// Add navigation entry
$this->assign( 'application', '', false );
+ $this->assign( 'appid', $appid );
$navigation = OC_App::getNavigation();
$this->assign( 'navigation', $navigation);
$this->assign( 'settingsnavigation', OC_App::getSettingsNavigation());
@@ -98,7 +100,7 @@ class OC_TemplateLayout extends OC_Template {
}
/**
- * @param $styles
+ * @param array $styles
* @return array
*/
static public function findStylesheetFiles($styles) {
@@ -116,7 +118,7 @@ class OC_TemplateLayout extends OC_Template {
}
/**
- * @param $scripts
+ * @param array $scripts
* @return array
*/
static public function findJavascriptFiles($scripts) {
@@ -175,7 +177,7 @@ class OC_TemplateLayout extends OC_Template {
}
/**
- * @param $files
+ * @param array $files
* @return string
*/
private static function hashScriptNames($files)
diff --git a/lib/private/updater.php b/lib/private/updater.php
index 7b09f580176..d8694ac6ed5 100644
--- a/lib/private/updater.php
+++ b/lib/private/updater.php
@@ -35,7 +35,7 @@ class Updater extends BasicEmitter {
/**
* Check if a new version is available
* @param string $updaterUrl the url to check, i.e. 'http://apps.owncloud.com/updater.php'
- * @return array | bool
+ * @return array|bool
*/
public function check($updaterUrl) {
diff --git a/lib/private/urlgenerator.php b/lib/private/urlgenerator.php
index a56b0fe3378..b37ef89d40d 100644
--- a/lib/private/urlgenerator.php
+++ b/lib/private/urlgenerator.php
@@ -30,7 +30,7 @@ class URLGenerator implements IURLGenerator {
/**
* @brief Creates an url using a defined route
- * @param $route
+ * @param string $route
* @param array $parameters
* @internal param array $args with param=>value, will be appended to the returned url
* @return string the url
diff --git a/lib/private/user.php b/lib/private/user.php
index 7106d664aca..90aac88cdc8 100644
--- a/lib/private/user.php
+++ b/lib/private/user.php
@@ -77,7 +77,7 @@ class OC_User {
/**
* @brief gets available backends
* @deprecated
- * @returns array of backends
+ * @return array an array of backends
*
* Returns the names of all backends.
*/
@@ -88,7 +88,7 @@ class OC_User {
/**
* @brief gets used backends
* @deprecated
- * @returns array of backends
+ * @return array an array of backends
*
* Returns the names of all used backends.
*/
@@ -98,7 +98,7 @@ class OC_User {
/**
* @brief Adds the backend to the list of used backends
- * @param string | OC_User_Backend $backend default: database The backend to use for user management
+ * @param string|OC_User_Interface $backend default: database The backend to use for user management
* @return bool
*
* Set the User Authentication Module
@@ -321,7 +321,7 @@ class OC_User {
/**
* @brief Check if the user is logged in
- * @returns bool
+ * @return bool
*
* Checks if the user is logged in
*/
@@ -517,7 +517,7 @@ class OC_User {
/**
* @brief Get a list of all users
- * @returns array with all uids
+ * @return array an array of all uids
*
* Get a list of all users.
* @param string $search
diff --git a/lib/private/user/backend.php b/lib/private/user/backend.php
index f4e5618e04a..8d2f0e935de 100644
--- a/lib/private/user/backend.php
+++ b/lib/private/user/backend.php
@@ -103,7 +103,7 @@ abstract class OC_User_Backend implements OC_User_Interface {
/**
* @brief Get a list of all users
- * @returns array with all uids
+ * @return array an array of all uids
*
* Get a list of all users.
*/
@@ -140,7 +140,7 @@ abstract class OC_User_Backend implements OC_User_Interface {
/**
* @brief Get a list of all display names
- * @returns array with all displayNames (value) and the corresponding uids (key)
+ * @return array an array of all displayNames (value) and the corresponding uids (key)
*
* Get a list of all display names and user ids.
*/
diff --git a/lib/private/user/database.php b/lib/private/user/database.php
index 681f03981f5..747895a8a95 100644
--- a/lib/private/user/database.php
+++ b/lib/private/user/database.php
@@ -57,9 +57,9 @@ class OC_User_Database extends OC_User_Backend {
/**
* @brief Create a new user
- * @param $uid The username of the user to create
- * @param $password The password of the new user
- * @returns true/false
+ * @param string $uid The username of the user to create
+ * @param string $password The password of the new user
+ * @return bool
*
* Creates a new user. Basic checking of username is done in OC_User
* itself, not in its subclasses.
@@ -79,8 +79,8 @@ class OC_User_Database extends OC_User_Backend {
/**
* @brief delete a user
- * @param $uid The username of the user to delete
- * @returns true/false
+ * @param string $uid The username of the user to delete
+ * @return bool
*
* Deletes a user
*/
@@ -98,9 +98,9 @@ class OC_User_Database extends OC_User_Backend {
/**
* @brief Set password
- * @param $uid The username
- * @param $password The new password
- * @returns true/false
+ * @param string $uid The username
+ * @param string $password The new password
+ * @return bool
*
* Change the password of a user
*/
@@ -119,9 +119,9 @@ class OC_User_Database extends OC_User_Backend {
/**
* @brief Set display name
- * @param $uid The username
- * @param $displayName The new display name
- * @returns true/false
+ * @param string $uid The username
+ * @param string $displayName The new display name
+ * @return bool
*
* Change the display name of a user
*/
@@ -139,7 +139,7 @@ class OC_User_Database extends OC_User_Backend {
/**
* @brief get display name of the user
- * @param $uid user ID of the user
+ * @param string $uid user ID of the user
* @return string display name
*/
public function getDisplayName($uid) {
@@ -149,7 +149,7 @@ class OC_User_Database extends OC_User_Backend {
/**
* @brief Get a list of all display names
- * @returns array with all displayNames (value) and the correspondig uids (key)
+ * @return array an array of all displayNames (value) and the correspondig uids (key)
*
* Get a list of all display names and user ids.
*/
@@ -169,9 +169,9 @@ class OC_User_Database extends OC_User_Backend {
/**
* @brief Check if the password is correct
- * @param $uid The username
- * @param $password The password
- * @returns string
+ * @param string $uid The username
+ * @param string $password The password
+ * @return string
*
* Check if the password is correct without logging in the user
* returns the user id or false
@@ -183,14 +183,14 @@ class OC_User_Database extends OC_User_Backend {
$row = $result->fetchRow();
if ($row) {
$storedHash = $row['password'];
- if ($storedHash[0] == '$') { //the new phpass based hashing
+ if ($storedHash[0] === '$') { //the new phpass based hashing
$hasher = $this->getHasher();
if ($hasher->CheckPassword($password . OC_Config::getValue('passwordsalt', ''), $storedHash)) {
return $row['uid'];
}
//old sha1 based hashing
- } elseif (sha1($password) == $storedHash) {
+ } elseif (sha1($password) === $storedHash) {
//upgrade to new hashing
$this->setPassword($row['uid'], $password);
return $row['uid'];
@@ -203,7 +203,7 @@ class OC_User_Database extends OC_User_Backend {
/**
* @brief Load an user in the cache
* @param string $uid the username
- * @returns boolean
+ * @return boolean
*/
private function loadUser($uid) {
if (empty($this->cache[$uid])) {
@@ -226,7 +226,7 @@ class OC_User_Database extends OC_User_Backend {
/**
* @brief Get a list of all users
- * @returns array with all uids
+ * @return array an array of all uids
*
* Get a list of all users.
*/
@@ -273,7 +273,7 @@ class OC_User_Database extends OC_User_Backend {
/**
* counts the users in the database
*
- * @return int | bool
+ * @return int|bool
*/
public function countUsers() {
$query = OC_DB::prepare('SELECT COUNT(*) FROM `*PREFIX*users`');
diff --git a/lib/private/user/dummy.php b/lib/private/user/dummy.php
index 2fb51d02de3..d2ada37c80f 100644
--- a/lib/private/user/dummy.php
+++ b/lib/private/user/dummy.php
@@ -127,7 +127,7 @@ class OC_User_Dummy extends OC_User_Backend {
/**
* counts the users in the database
*
- * @return int | bool
+ * @return int|bool
*/
public function countUsers() {
return 0;
diff --git a/lib/private/user/example.php b/lib/private/user/example.php
index b2d0dc25410..4bf3652330e 100644
--- a/lib/private/user/example.php
+++ b/lib/private/user/example.php
@@ -28,9 +28,9 @@
abstract class OC_User_Example extends OC_User_Backend {
/**
* @brief Create a new user
- * @param $uid The username of the user to create
- * @param $password The password of the new user
- * @returns true/false
+ * @param string $uid The username of the user to create
+ * @param string $password The password of the new user
+ * @return bool
*
* Creates a new user. Basic checking of username is done in OC_User
* itself, not in its subclasses.
@@ -39,9 +39,9 @@ abstract class OC_User_Example extends OC_User_Backend {
/**
* @brief Set password
- * @param $uid The username
- * @param $password The new password
- * @returns true/false
+ * @param string $uid The username
+ * @param string $password The new password
+ * @return bool
*
* Change the password of a user
*/
@@ -49,9 +49,9 @@ abstract class OC_User_Example extends OC_User_Backend {
/**
* @brief Check if the password is correct
- * @param $uid The username
- * @param $password The password
- * @returns string
+ * @param string $uid The username
+ * @param string $password The password
+ * @return string
*
* Check if the password is correct without logging in the user
* returns the user id or false
@@ -60,8 +60,8 @@ abstract class OC_User_Example extends OC_User_Backend {
/**
* @brief get the user's home directory
- * @param $uid The username
- * @returns string
+ * @param string $uid The username
+ * @return string
*
* get the user's home directory
* returns the path or false
diff --git a/lib/private/user/http.php b/lib/private/user/http.php
index a0394521012..67f7156b498 100644
--- a/lib/private/user/http.php
+++ b/lib/private/user/http.php
@@ -27,7 +27,7 @@
class OC_User_HTTP extends OC_User_Backend {
/**
* split http://user@host/path into a user and url part
- * @param string path
+ * @param string $url
* @return array
*/
private function parseUrl($url) {
@@ -46,7 +46,7 @@ class OC_User_HTTP extends OC_User_Backend {
/**
* check if an url is a valid login
- * @param string url
+ * @param string $url
* @return boolean
*/
private function matchUrl($url) {
@@ -55,9 +55,9 @@ class OC_User_HTTP extends OC_User_Backend {
/**
* @brief Check if the password is correct
- * @param $uid The username
- * @param $password The password
- * @returns string
+ * @param string $uid The username
+ * @param string $password The password
+ * @return string
*
* Check if the password is correct without logging in the user
* returns the user id or false
diff --git a/lib/private/user/interface.php b/lib/private/user/interface.php
index cdcab3e5d00..e130e5b569c 100644
--- a/lib/private/user/interface.php
+++ b/lib/private/user/interface.php
@@ -26,27 +26,23 @@ interface OC_User_Interface {
/**
* @brief Check if backend implements actions
* @param $actions bitwise-or'ed actions
- * @returns boolean
+ * @return boolean
*
* Returns the supported actions as int to be
* compared with OC_USER_BACKEND_CREATE_USER etc.
- * @return boolean
*/
public function implementsActions($actions);
/**
* @brief delete a user
- * @param $uid The username of the user to delete
- * @returns true/false
- *
- * Deletes a user
- * @return boolean
+ * @param string $uid The username of the user to delete
+ * @return bool
*/
public function deleteUser($uid);
/**
* @brief Get a list of all users
- * @returns array with all uids
+ * @return array an array of all uids
*
* Get a list of all users.
*/
@@ -61,14 +57,14 @@ interface OC_User_Interface {
/**
* @brief get display name of the user
- * @param $uid user ID of the user
- * @return display name
+ * @param string $uid user ID of the user
+ * @return string display name
*/
public function getDisplayName($uid);
/**
* @brief Get a list of all display names
- * @returns array with all displayNames (value) and the corresponding uids (key)
+ * @return array an array of all displayNames (value) and the corresponding uids (key)
*
* Get a list of all display names and user ids.
*/
diff --git a/lib/private/user/manager.php b/lib/private/user/manager.php
index 14698452e88..0fcf1ceb6ab 100644
--- a/lib/private/user/manager.php
+++ b/lib/private/user/manager.php
@@ -26,7 +26,7 @@ use OC\Hooks\PublicEmitter;
*/
class Manager extends PublicEmitter {
/**
- * @var \OC_User_Backend[] $backends
+ * @var \OC_User_Interface[] $backends
*/
private $backends = array();
@@ -57,7 +57,7 @@ class Manager extends PublicEmitter {
/**
* register a user backend
*
- * @param \OC_User_Backend $backend
+ * @param \OC_User_Interface $backend
*/
public function registerBackend($backend) {
$this->backends[] = $backend;
@@ -66,7 +66,7 @@ class Manager extends PublicEmitter {
/**
* remove a user backend
*
- * @param \OC_User_Backend $backend
+ * @param \OC_User_Interface $backend
*/
public function removeBackend($backend) {
$this->cachedUsers = array();
@@ -105,7 +105,7 @@ class Manager extends PublicEmitter {
* get or construct the user object
*
* @param string $uid
- * @param \OC_User_Backend $backend
+ * @param \OC_User_Interface $backend
* @return \OC\User\User
*/
protected function getUserObject($uid, $backend) {
@@ -174,12 +174,12 @@ class Manager extends PublicEmitter {
$backendUsers = $backend->getUsers($pattern, $limit, $offset);
if (is_array($backendUsers)) {
foreach ($backendUsers as $uid) {
- $users[] = $this->getUserObject($uid, $backend);
+ $users[$uid] = $this->getUserObject($uid, $backend);
}
}
}
- usort($users, function ($a, $b) {
+ uasort($users, function ($a, $b) {
/**
* @var \OC\User\User $a
* @var \OC\User\User $b
@@ -222,7 +222,7 @@ class Manager extends PublicEmitter {
* @param string $uid
* @param string $password
* @throws \Exception
- * @return bool | \OC\User\User the created user of false
+ * @return bool|\OC\User\User the created user of false
*/
public function createUser($uid, $password) {
$l = \OC_L10N::get('lib');
@@ -261,7 +261,7 @@ class Manager extends PublicEmitter {
/**
* returns how many users per backend exist (if supported by backend)
*
- * @return array with backend class as key and count number as value
+ * @return array an array of backend class as key and count number as value
*/
public function countUsers() {
$userCountStatistics = array();
diff --git a/lib/private/user/session.php b/lib/private/user/session.php
index 1740bad5abe..3d10b134b83 100644
--- a/lib/private/user/session.php
+++ b/lib/private/user/session.php
@@ -82,7 +82,7 @@ class Session implements Emitter, \OCP\IUserSession {
/**
* set the currently active user
*
- * @param \OC\User\User $user
+ * @param \OC\User\User|null $user
*/
public function setUser($user) {
if (is_null($user)) {
@@ -115,7 +115,7 @@ class Session implements Emitter, \OCP\IUserSession {
/**
* set the login name
*
- * @param string $loginName for the logged in user
+ * @param string|null $loginName for the logged in user
*/
public function setLoginName($loginName) {
if (is_null($loginName)) {
@@ -191,7 +191,7 @@ class Session implements Emitter, \OCP\IUserSession {
$expires = time() + \OC_Config::getValue('remember_login_cookie_lifetime', 60 * 60 * 24 * 15);
setcookie("oc_username", $username, $expires, \OC::$WEBROOT, '', $secure_cookie);
setcookie("oc_token", $token, $expires, \OC::$WEBROOT, '', $secure_cookie, true);
- setcookie("oc_remember_login", true, $expires, \OC::$WEBROOT, '', $secure_cookie);
+ setcookie("oc_remember_login", "1", $expires, \OC::$WEBROOT, '', $secure_cookie);
}
/**
diff --git a/lib/private/user/user.php b/lib/private/user/user.php
index ef5364cbf7b..bc5c541e521 100644
--- a/lib/private/user/user.php
+++ b/lib/private/user/user.php
@@ -23,7 +23,7 @@ class User {
private $displayName;
/**
- * @var \OC_User_Backend $backend
+ * @var \OC_User_Interface $backend
*/
private $backend;
@@ -33,7 +33,7 @@ class User {
private $enabled;
/**
- * @var Emitter | Manager $emitter
+ * @var Emitter|Manager $emitter
*/
private $emitter;
@@ -49,17 +49,12 @@ class User {
/**
* @param string $uid
- * @param \OC_User_Backend $backend
+ * @param \OC_User_Interface $backend
* @param \OC\Hooks\Emitter $emitter
* @param \OC\AllConfig $config
*/
public function __construct($uid, $backend, $emitter = null, $config = null) {
$this->uid = $uid;
- if ($backend and $backend->implementsActions(OC_USER_BACKEND_GET_DISPLAYNAME)) {
- $this->displayName = $backend->getDisplayName($uid);
- } else {
- $this->displayName = $uid;
- }
$this->backend = $backend;
$this->emitter = $emitter;
$this->config = $config;
@@ -86,6 +81,13 @@ class User {
* @return string
*/
public function getDisplayName() {
+ if (!isset($this->displayName)) {
+ if ($this->backend and $this->backend->implementsActions(OC_USER_BACKEND_GET_DISPLAYNAME)) {
+ $this->displayName = $this->backend->getDisplayName($this->uid);
+ } else {
+ $this->displayName = $this->uid;
+ }
+ }
return $this->displayName;
}
diff --git a/lib/private/util.php b/lib/private/util.php
index e6aa7b061b5..107dc6b9a9f 100755
--- a/lib/private/util.php
+++ b/lib/private/util.php
@@ -87,6 +87,16 @@ class OC_Util {
}
/**
+ * @brief check if a password is required for each public link
+ * @return boolean
+ */
+ public static function isPublicLinkPasswordRequired() {
+ $appConfig = \OC::$server->getAppConfig();
+ $enforcePassword = $appConfig->getValue('core', 'shareapi_enforce_links_password', 'no');
+ return ($enforcePassword === 'yes') ? true : false;
+ }
+
+ /**
* Get the quota of a user
* @param string $user
* @return int Quota bytes
@@ -299,7 +309,7 @@ class OC_Util {
}
// Assume that if checkServer() succeeded before in this session, then all is fine.
- if(\OC::$session->exists('checkServer_suceeded') && \OC::$session->get('checkServer_suceeded')) {
+ if(\OC::$session->exists('checkServer_succeeded') && \OC::$session->get('checkServer_succeeded')) {
return $errors;
}
@@ -491,7 +501,7 @@ class OC_Util {
$errors = array_merge($errors, self::checkDatabaseVersion());
// Cache the result of this function
- \OC::$session->set('checkServer_suceeded', count($errors) == 0);
+ \OC::$session->set('checkServer_succeeded', count($errors) == 0);
return $errors;
}
@@ -551,6 +561,27 @@ class OC_Util {
}
/**
+ * @brief check if a backup from the encryption keys exists
+ * @return boolean
+ */
+ public static function backupKeysExists() {
+ //check if encryption was enabled in the past
+ $backupExists = false;
+ if (OC_App::isEnabled('files_encryption') === false) {
+ $view = new OC\Files\View('/' . OCP\User::getUser());
+ $backupPath = '/files_encryption/keyfiles.backup';
+ if ($view->is_dir($backupPath)) {
+ $dircontent = $view->getDirectoryContent($backupPath);
+ if (!empty($dircontent)) {
+ $backupExists = true;
+ }
+ }
+ }
+
+ return $backupExists;
+ }
+
+ /**
* @brief Check for correct file permissions of data directory
* @param string $dataDirectory
* @return array arrays with error messages and hints
@@ -748,7 +779,7 @@ class OC_Util {
/**
* @brief Register an get/post call. Important to prevent CSRF attacks.
* @todo Write howto: CSRF protection guide
- * @return $token Generated token.
+ * @return string Generated token.
* @description
* Creates a 'request token' (random) and stores it inside the session.
* Ever subsequent (ajax) request must use such a valid token to succeed,
@@ -781,7 +812,7 @@ class OC_Util {
}
/**
- * @brief Check an ajax get/post call if the request token is valid. exit if not.
+ * @brief Check an ajax get/post call if the request token is valid. Exit if not.
* @todo Write howto
* @return void
*/
@@ -797,8 +828,8 @@ class OC_Util {
* This function is used to sanitize HTML and should be applied on any
* string or array of strings before displaying it on a web page.
*
- * @param string|array of strings
- * @return array with sanitized strings or a single sanitized string, depends on the input parameter.
+ * @param string|array &$value
+ * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter.
*/
public static function sanitizeHTML( &$value ) {
if (is_array($value)) {
@@ -837,7 +868,7 @@ class OC_Util {
if (!\OC_Config::getValue("check_for_working_htaccess", true)) {
return true;
}
-
+
// testdata
$fileName = '/htaccesstest.txt';
$testContent = 'testcontent';
@@ -1007,8 +1038,8 @@ class OC_Util {
/**
* @brief Generates a cryptographic secure pseudo-random string
- * @param Int $length of the random string
- * @return String
+ * @param int $length of the random string
+ * @return string
* Please also update secureRNGAvailable if you change something here
*/
public static function generateRandomBytes($length = 30) {
@@ -1082,7 +1113,7 @@ class OC_Util {
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curl, CURLOPT_URL, $url);
-
+
curl_setopt($curl, CURLOPT_USERAGENT, "ownCloud Server Crawler");
if(OC_Config::getValue('proxy', '') != '') {
@@ -1091,24 +1122,23 @@ class OC_Util {
if(OC_Config::getValue('proxyuserpwd', '') != '') {
curl_setopt($curl, CURLOPT_PROXYUSERPWD, OC_Config::getValue('proxyuserpwd'));
}
-
- if (ini_get('open_basedir') === '' && ini_get('safe_mode' === 'Off')) {
+
+ if (ini_get('open_basedir') === '' && ini_get('safe_mode') === 'Off') {
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_MAXREDIRS, $max_redirects);
$data = curl_exec($curl);
} else {
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
$mr = $max_redirects;
- if ($mr > 0) {
- $newurl = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);
-
+ if ($mr > 0) {
+ $newURL = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);
$rcurl = curl_copy_handle($curl);
curl_setopt($rcurl, CURLOPT_HEADER, true);
curl_setopt($rcurl, CURLOPT_NOBODY, true);
curl_setopt($rcurl, CURLOPT_FORBID_REUSE, false);
curl_setopt($rcurl, CURLOPT_RETURNTRANSFER, true);
do {
- curl_setopt($rcurl, CURLOPT_URL, $newurl);
+ curl_setopt($rcurl, CURLOPT_URL, $newURL);
$header = curl_exec($rcurl);
if (curl_errno($rcurl)) {
$code = 0;
@@ -1116,7 +1146,7 @@ class OC_Util {
$code = curl_getinfo($rcurl, CURLINFO_HTTP_CODE);
if ($code == 301 || $code == 302) {
preg_match('/Location:(.*?)\n/', $header, $matches);
- $newurl = trim(array_pop($matches));
+ $newURL = trim(array_pop($matches));
} else {
$code = 0;
}
@@ -1124,10 +1154,10 @@ class OC_Util {
} while ($code && --$mr);
curl_close($rcurl);
if ($mr > 0) {
- curl_setopt($curl, CURLOPT_URL, $newurl);
- }
+ curl_setopt($curl, CURLOPT_URL, $newURL);
+ }
}
-
+
if($mr == 0 && $max_redirects > 0) {
$data = false;
} else {
@@ -1267,7 +1297,7 @@ class OC_Util {
/**
* Returns whether the given file name is valid
- * @param $file string file name to check
+ * @param string $file file name to check
* @return bool true if the file name is valid, false otherwise
*/
public static function isValidFileName($file) {
diff --git a/lib/private/vobject.php b/lib/private/vobject.php
index a3e9f7ef790..e472429b23e 100644
--- a/lib/private/vobject.php
+++ b/lib/private/vobject.php
@@ -25,28 +25,28 @@
*/
class OC_VObject{
/** @var Sabre\VObject\Component */
- protected $vobject;
+ protected $vObject;
/**
- * @returns Sabre\VObject\Component
+ * @return Sabre\VObject\Component
*/
public function getVObject() {
- return $this->vobject;
+ return $this->vObject;
}
/**
* @brief Parses the VObject
* @param string $data VObject as string
- * @returns Sabre\VObject\Reader|null
+ * @return Sabre\VObject\Reader|null
*/
public static function parse($data) {
try {
Sabre\VObject\Property::$classMap['LAST-MODIFIED'] = 'Sabre\VObject\Property\DateTime';
- $vobject = Sabre\VObject\Reader::read($data);
- if ($vobject instanceof Sabre\VObject\Component) {
- $vobject = new OC_VObject($vobject);
+ $vObject = Sabre\VObject\Reader::read($data);
+ if ($vObject instanceof Sabre\VObject\Component) {
+ $vObject = new OC_VObject($vObject);
}
- return $vobject;
+ return $vObject;
} catch (Exception $e) {
OC_Log::write('vobject', $e->getMessage(), OC_Log::ERROR);
return null;
@@ -89,26 +89,26 @@ class OC_VObject{
/**
* Constructor
- * @param Sabre\VObject\Component or string
+ * @param Sabre\VObject\Component|string $vobject_or_name
*/
public function __construct($vobject_or_name) {
if (is_object($vobject_or_name)) {
- $this->vobject = $vobject_or_name;
+ $this->vObject = $vobject_or_name;
} else {
- $this->vobject = new Sabre\VObject\Component($vobject_or_name);
+ $this->vObject = new Sabre\VObject\Component($vobject_or_name);
}
}
/**
* @todo Write documentation
- * @param $item
+ * @param \OC_VObject|\Sabre\VObject\Component $item
* @param null $itemValue
*/
public function add($item, $itemValue = null) {
if ($item instanceof OC_VObject) {
$item = $item->getVObject();
}
- $this->vobject->add($item, $itemValue);
+ $this->vObject->add($item, $itemValue);
}
/**
@@ -116,7 +116,7 @@ class OC_VObject{
* @param object $name of property
* @param object $value of property
* @param array|object $parameters of property
- * @returns Sabre\VObject\Property newly created
+ * @return Sabre\VObject\Property newly created
*/
public function addProperty($name, $value, $parameters=array()) {
if(is_array($value)) {
@@ -127,26 +127,26 @@ class OC_VObject{
$property->parameters[] = new Sabre\VObject\Parameter($name, $value);
}
- $this->vobject->add($property);
+ $this->vObject->add($property);
return $property;
}
public function setUID() {
$uid = substr(md5(rand().time()), 0, 10);
- $this->vobject->add('UID', $uid);
+ $this->vObject->add('UID', $uid);
}
/**
* @todo Write documentation
- * @param mixed $name
+ * @param mixed $name
* @param string $string
*/
public function setString($name, $string) {
if ($string != '') {
$string = strtr($string, array("\r\n"=>"\n"));
- $this->vobject->__set($name, $string);
+ $this->vObject->__set($name, $string);
}else{
- $this->vobject->__unset($name);
+ $this->vObject->__unset($name);
}
}
@@ -167,31 +167,31 @@ class OC_VObject{
if ($datetime instanceof DateTime) {
$datetime_element = new Sabre\VObject\Property\DateTime($name);
$datetime_element->setDateTime($datetime, $dateType);
- $this->vobject->__set($name, $datetime_element);
+ $this->vObject->__set($name, $datetime_element);
}else{
- $this->vobject->__unset($name);
+ $this->vObject->__unset($name);
}
}
/**
* @todo Write documentation
- * @param $name
+ * @param string $name
* @return string
*/
public function getAsString($name) {
- return $this->vobject->__isset($name) ?
- $this->vobject->__get($name)->value :
+ return $this->vObject->__isset($name) ?
+ $this->vObject->__get($name)->value :
'';
}
/**
* @todo Write documentation
- * @param $name
+ * @param string $name
* @return array
*/
public function getAsArray($name) {
$values = array();
- if ($this->vobject->__isset($name)) {
+ if ($this->vObject->__isset($name)) {
$values = explode(',', $this->getAsString($name));
$values = array_map('trim', $values);
}
@@ -200,14 +200,14 @@ class OC_VObject{
/**
* @todo Write documentation
- * @param $name
+ * @param string $name
* @return array|OC_VObject|\Sabre\VObject\Property
*/
public function &__get($name) {
if ($name == 'children') {
- return $this->vobject->children;
+ return $this->vObject->children;
}
- $return = $this->vobject->__get($name);
+ $return = $this->vObject->__get($name);
if ($return instanceof Sabre\VObject\Component) {
$return = new OC_VObject($return);
}
@@ -220,7 +220,7 @@ class OC_VObject{
* @param string $value
*/
public function __set($name, $value) {
- return $this->vobject->__set($name, $value);
+ return $this->vObject->__set($name, $value);
}
/**
@@ -228,7 +228,7 @@ class OC_VObject{
* @param string $name
*/
public function __unset($name) {
- return $this->vobject->__unset($name);
+ return $this->vObject->__unset($name);
}
/**
@@ -237,16 +237,16 @@ class OC_VObject{
* @return bool
*/
public function __isset($name) {
- return $this->vobject->__isset($name);
+ return $this->vObject->__isset($name);
}
/**
* @todo Write documentation
- * @param $function
- * @param $arguments
+ * @param callable $function
+ * @param array $arguments
* @return mixed
*/
public function __call($function, $arguments) {
- return call_user_func_array(array($this->vobject, $function), $arguments);
+ return call_user_func_array(array($this->vObject, $function), $arguments);
}
}