diff options
author | Robin Appelman <icewind@owncloud.com> | 2014-02-07 13:42:18 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2014-02-07 13:45:59 +0100 |
commit | b537d90e58913be203fd96f31b624559be00abeb (patch) | |
tree | 9af6c432b3b503303f1315f82f602844664f837d /lib/public | |
parent | b35b22977cfc9412278ae70b49c402a95efca19e (diff) | |
parent | b9e724d4ae7635435b3cc7793237c3ab9fe2a1c0 (diff) | |
download | nextcloud-server-b537d90e58913be203fd96f31b624559be00abeb.tar.gz nextcloud-server-b537d90e58913be203fd96f31b624559be00abeb.zip |
use the 'new' server container for appconfig
Diffstat (limited to 'lib/public')
60 files changed, 2709 insertions, 1128 deletions
diff --git a/lib/public/activity/iconsumer.php b/lib/public/activity/iconsumer.php new file mode 100644 index 00000000000..9afacf4e745 --- /dev/null +++ b/lib/public/activity/iconsumer.php @@ -0,0 +1,48 @@ +<?php +/** + * ownCloud + * + * @author Thomas Müller + * @copyright 2013 Thomas Müller deepdiver@owncloud.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Activity/IConsumer interface + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Activity; + +interface IConsumer { + /** + * @param $app + * @param $subject + * @param $subjectParams + * @param $message + * @param $messageParams + * @param $file + * @param $link + * @param $affectedUser + * @param $type + * @param $priority + * @return mixed + */ + function receive($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority ); +} + diff --git a/lib/public/activity/imanager.php b/lib/public/activity/imanager.php new file mode 100644 index 00000000000..086e430d677 --- /dev/null +++ b/lib/public/activity/imanager.php @@ -0,0 +1,59 @@ +<?php +/** + * ownCloud + * + * @author Thomas Müller + * @copyright 2013 Thomas Müller deepdiver@owncloud.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Activity/IManager interface + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Activity; + +interface IManager { + + /** + * @param $app + * @param $subject + * @param $subjectParams + * @param $message + * @param $messageParams + * @param $file + * @param $link + * @param $affectedUser + * @param $type + * @param $priority + * @return mixed + */ + function publishActivity($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority); + + /** + * In order to improve lazy loading a closure can be registered which will be called in case + * activity consumers are actually requested + * + * $callable has to return an instance of OCA\Activity\IConsumer + * + * @param \Closure $callable + */ + function registerConsumer(\Closure $callable); + +} diff --git a/lib/public/api.php b/lib/public/api.php index d94b68e908a..f53188d2721 100644 --- a/lib/public/api.php +++ b/lib/public/api.php @@ -1,25 +1,33 @@ <?php /** -* ownCloud -* -* @author Tom Needham -* @copyright 2012 Tom Needham tom@owncloud.com -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ + * ownCloud + * + * @author Tom Needham + * @copyright 2012 Tom Needham tom@owncloud.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/** + * Public interface of ownCloud for apps to use. + * API Class + * + */ +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; /** diff --git a/lib/public/app.php b/lib/public/app.php index 0a5721b334e..e0b5682242b 100644 --- a/lib/public/app.php +++ b/lib/public/app.php @@ -1,28 +1,28 @@ <?php /** -* ownCloud -* -* @author Frank Karlitschek -* @copyright 2012 Frank Karlitschek frank@owncloud.org -* -* 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/>. -* -*/ + * ownCloud + * + * @author Frank Karlitschek + * @copyright 2012 Frank Karlitschek frank@owncloud.org + * + * 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/>. + * + */ /** * Public interface of ownCloud for apps to use. - * App Class. + * App Class * */ @@ -35,14 +35,12 @@ namespace OCP; */ class App { /** - * @brief Makes ownCloud aware of this app - * @brief This call is deprecated and not necessary to use. - * @param $data array with all information - * @returns boolean + * Makes ownCloud aware of this app + * @param array with all information + * @return boolean * - * @deprecated this method is deprecated - * Do not call it anymore - * It'll remain in our public API for compatibility reasons + * @deprecated This method is deprecated. Do not call it anymore. + * It'll remain in our public API for compatibility reasons. * */ public static function register( $data ) { @@ -50,9 +48,9 @@ class App { } /** - * @brief adds an entry to the navigation - * @param $data array containing the data - * @returns boolean + * Adds an entry to the navigation + * @param array containing the data + * @return boolean * * This function adds a new entry to the navigation visible to users. $data * is an associative array. @@ -71,9 +69,9 @@ class App { } /** - * @brief marks a navigation entry as active - * @param $id string id of the entry - * @returns boolean + * Marks a navigation entry as active + * @param string id of the entry + * @return boolean * * This function sets a navigation entry as active and removes the 'active' * property from all other entries. The templates can use this for @@ -84,7 +82,7 @@ class App { } /** - * @brief Register a Configuration Screen that should appear in the personal settings section. + * Register a Configuration Screen that should appear in the personal settings section. * @param $app string appid * @param $page string page to be included */ @@ -93,7 +91,7 @@ class App { } /** - * @brief Register a Configuration Screen that should appear in the Admin section. + * Register a Configuration Screen that should appear in the Admin section. * @param $app string appid * @param $page string page to be included */ @@ -102,19 +100,19 @@ class App { } /** - * @brief Read app metadata from the info.xml file + * Read app metadata from the info.xml file * @param string $app id of the app or the path of the info.xml file * @param boolean $path (optional) - * @returns array + * @return array */ public static function getAppInfo( $app, $path=false ) { return \OC_App::getAppInfo( $app, $path); } /** - * @brief checks whether or not an app is enabled - * @param $app app - * @returns boolean + * checks whether or not an app is enabled + * @param string + * @return boolean * * This function checks whether or not an app is enabled. */ @@ -123,17 +121,17 @@ class App { } /** - * @brief Check if the app is enabled, redirects to home if not - * @param $app app + * Check if the app is enabled, redirects to home if not + * @param string */ public static function checkAppEnabled( $app ) { \OC_Util::checkAppEnabled( $app ); } /** - * @brief Get the last version of the app, either from appinfo/version or from appinfo/info.xml - * @param $app app - * @returns boolean + * Get the last version of the app, either from appinfo/version or from appinfo/info.xml + * @param string + * @return boolean */ public static function getAppVersion( $app ) { return \OC_App::getAppVersion( $app ); diff --git a/lib/public/appframework/app.php b/lib/public/appframework/app.php index d97c5c81848..90150245c41 100644 --- a/lib/public/appframework/app.php +++ b/lib/public/appframework/app.php @@ -20,7 +20,13 @@ * */ +/** + * Public interface of ownCloud for apps to use. + * AppFramework/App class + */ + namespace OCP\AppFramework; +use OC\AppFramework\routing\RouteConfig; /** @@ -31,8 +37,11 @@ namespace OCP\AppFramework; * to be registered using IContainer::registerService */ class App { - public function __construct($appName) { - $this->container = new \OC\AppFramework\DependencyInjection\DIContainer($appName); + /** + * @param array $urlParams an array with variables extracted from the routes + */ + public function __construct($appName, $urlParams = array()) { + $this->container = new \OC\AppFramework\DependencyInjection\DIContainer($appName, $urlParams); } private $container; @@ -45,13 +54,35 @@ class App { } /** + * This function is to be called to create single routes and restful routes based on the given $routes array. + * + * Example code in routes.php of tasks app (it will register two restful resources): + * $routes = array( + * 'resources' => array( + * 'lists' => array('url' => '/tasklists'), + * 'tasks' => array('url' => '/tasklists/{listId}/tasks') + * ) + * ); + * + * $a = new TasksApp(); + * $a->registerRoutes($this, $routes); + * + * @param \OC_Router $router + * @param array $routes + */ + public function registerRoutes($router, $routes) { + $routeConfig = new RouteConfig($this->container, $router, $routes); + $routeConfig->register(); + } + + /** * This function is called by the routing component to fire up the frameworks dispatch mechanism. * * Example code in routes.php of the task app: * $this->create('tasks_index', '/')->get()->action( * function($params){ - * $app = new TaskApp(); - * $app->dispatch('PageController', 'index', $params); + * $app = new TaskApp($params); + * $app->dispatch('PageController', 'index'); * } * ); * @@ -59,8 +90,8 @@ class App { * Example for for TaskApp implementation: * class TaskApp extends \OCP\AppFramework\App { * - * public function __construct(){ - * parent::__construct('tasks'); + * public function __construct($params){ + * parent::__construct('tasks', $params); * * $this->getContainer()->registerService('PageController', function(IAppContainer $c){ * $a = $c->query('API'); @@ -73,9 +104,8 @@ class App { * @param string $controllerName the name of the controller under which it is * stored in the DI container * @param string $methodName the method that you want to call - * @param array $urlParams an array with variables extracted from the routes */ - public function dispatch($controllerName, $methodName, array $urlParams) { - \OC\AppFramework\App::main($controllerName, $methodName, $urlParams, $this->container); + public function dispatch($controllerName, $methodName) { + \OC\AppFramework\App::main($controllerName, $methodName, $this->container); } } diff --git a/lib/public/appframework/controller.php b/lib/public/appframework/controller.php new file mode 100644 index 00000000000..dc8da967871 --- /dev/null +++ b/lib/public/appframework/controller.php @@ -0,0 +1,151 @@ +<?php +/** + * ownCloud - App Framework + * + * @author Bernhard Posselt + * @copyright 2012 Bernhard Posselt nukeawhale@gmail.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/>. + * + */ + +/** + * Public interface of ownCloud for apps to use. + * AppFramework\Controller class + */ + +namespace OCP\AppFramework; + +use OCP\AppFramework\Http\TemplateResponse; +use OCP\AppFramework\IAppContainer; +use OCP\IRequest; + + +/** + * Base class to inherit your controllers from + */ +abstract class Controller { + + /** + * app container for dependency injection + * @var \OCP\AppFramework\IAppContainer + */ + protected $app; + + /** + * current request + * @var \OCP\IRequest + */ + protected $request; + + /** + * constructor of the controller + * @param IAppContainer $app interface to the app + * @param IRequest $request an instance of the request + */ + public function __construct(IAppContainer $app, IRequest $request){ + $this->app = $app; + $this->request = $request; + } + + + /** + * Lets you access post and get parameters by the index + * @param string $key the key which you want to access in the URL Parameter + * placeholder, $_POST or $_GET array. + * The priority how they're returned is the following: + * 1. URL parameters + * 2. POST parameters + * 3. GET parameters + * @param mixed $default If the key is not found, this value will be returned + * @return mixed the content of the array + */ + public function params($key, $default=null){ + return $this->request->getParam($key, $default); + } + + + /** + * Returns all params that were received, be it from the request + * (as GET or POST) or throuh the URL by the route + * @return array the array with all parameters + */ + public function getParams() { + return $this->request->getParams(); + } + + + /** + * Returns the method of the request + * @return string the method of the request (POST, GET, etc) + */ + public function method() { + return $this->request->getMethod(); + } + + + /** + * Shortcut for accessing an uploaded file through the $_FILES array + * @param string $key the key that will be taken from the $_FILES array + * @return array the file in the $_FILES element + */ + public function getUploadedFile($key) { + return $this->request->getUploadedFile($key); + } + + + /** + * Shortcut for getting env variables + * @param string $key the key that will be taken from the $_ENV array + * @return array the value in the $_ENV element + */ + public function env($key) { + return $this->request->getEnv($key); + } + + + /** + * Shortcut for getting cookie variables + * @param string $key the key that will be taken from the $_COOKIE array + * @return array the value in the $_COOKIE element + */ + public function cookie($key) { + return $this->request->getCookie($key); + } + + + /** + * Shortcut for rendering a template + * @param string $templateName the name of the template + * @param array $params the template parameters in key => value structure + * @param string $renderAs user renders a full page, blank only your template + * admin an entry in the admin settings + * @param array $headers set additional headers in name/value pairs + * @return \OCP\AppFramework\Http\TemplateResponse containing the page + */ + public function render($templateName, array $params=array(), + $renderAs='user', array $headers=array()){ + $response = new TemplateResponse($this->app->getAppName(), $templateName); + $response->setParams($params); + $response->renderAs($renderAs); + + foreach($headers as $name => $value){ + $response->addHeader($name, $value); + } + + return $response; + } + + +} diff --git a/lib/public/appframework/http/http.php b/lib/public/appframework/http.php index 9eafe782726..60f314202cc 100644 --- a/lib/public/appframework/http/http.php +++ b/lib/public/appframework/http.php @@ -1,5 +1,4 @@ <?php - /** * ownCloud - App Framework * @@ -21,10 +20,16 @@ * */ +/** + * Public interface of ownCloud for apps to use. + * AppFramework\HTTP class + */ -namespace OCP\AppFramework\Http; - +namespace OCP\AppFramework; +/** + * Base class which contains constants for HTTP status codes + */ class Http { const STATUS_CONTINUE = 100; diff --git a/lib/public/appframework/http/jsonresponse.php b/lib/public/appframework/http/jsonresponse.php index 085fdbed2f9..b54b23a34e6 100644 --- a/lib/public/appframework/http/jsonresponse.php +++ b/lib/public/appframework/http/jsonresponse.php @@ -1,5 +1,4 @@ <?php - /** * ownCloud - App Framework * @@ -21,19 +20,29 @@ * */ +/** + * Public interface of ownCloud for apps to use. + * AppFramework\HTTP\JSONResponse class + */ namespace OCP\AppFramework\Http; +use OCP\AppFramework\Http; /** * A renderer for JSON calls */ class JSONResponse extends Response { + /** + * response data + * @var array|object + */ protected $data; /** + * constructor of JSONResponse * @param array|object $data the object or array that should be transformed * @param int $statusCode the Http status code, defaults to 200 */ @@ -55,7 +64,7 @@ class JSONResponse extends Response { /** * Sets values in the data json array - * @param array|object $params an array or object which will be transformed + * @param array|object $data an array or object which will be transformed * to JSON */ public function setData($data){ diff --git a/lib/public/appframework/http/response.php b/lib/public/appframework/http/response.php index 64477258948..0f5a18ca4fe 100644 --- a/lib/public/appframework/http/response.php +++ b/lib/public/appframework/http/response.php @@ -1,5 +1,4 @@ <?php - /** * ownCloud - App Framework * @@ -21,17 +20,25 @@ * */ +/** + * Public interface of ownCloud for apps to use. + * AppFramework\HTTP\Response class + */ namespace OCP\AppFramework\Http; +use OCP\AppFramework\Http; /** - * Base class for responses. Also used to just send headers + * Base class for responses. Also used to just send headers. + * + * It handles headers, HTTP status code, last modified and ETag. */ class Response { /** - * @var array default headers + * Headers - defaults to ['Cache-Control' => 'no-cache, must-revalidate'] + * @var array */ private $headers = array( 'Cache-Control' => 'no-cache, must-revalidate' @@ -39,18 +46,21 @@ class Response { /** + * HTTP status code - defaults to STATUS OK * @var string */ private $status = Http::STATUS_OK; /** + * Last modified date * @var \DateTime */ private $lastModified; /** + * ETag * @var string */ private $ETag; @@ -64,7 +74,7 @@ class Response { public function cacheFor($cacheSeconds) { if($cacheSeconds > 0) { - $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . + $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate'); } else { $this->addHeader('Cache-Control', 'no-cache, must-revalidate'); @@ -94,16 +104,16 @@ class Response { */ public function getHeaders() { $mergeWith = array(); - + if($this->lastModified) { - $mergeWith['Last-Modified'] = + $mergeWith['Last-Modified'] = $this->lastModified->format(\DateTime::RFC2822); } if($this->ETag) { $mergeWith['ETag'] = '"' . $this->ETag . '"'; } - + return array_merge($mergeWith, $this->headers); } @@ -135,6 +145,7 @@ class Response { /** + * Get the ETag * @return string the etag */ public function getETag() { @@ -143,6 +154,7 @@ class Response { /** + * Get "last modified" date * @return string RFC2822 formatted last modified date */ public function getLastModified() { @@ -151,6 +163,7 @@ class Response { /** + * Set the ETag * @param string $ETag */ public function setETag($ETag) { @@ -159,6 +172,7 @@ class Response { /** + * Set "last modified" date * @param \DateTime $lastModified */ public function setLastModified($lastModified) { diff --git a/lib/public/appframework/http/templateresponse.php b/lib/public/appframework/http/templateresponse.php index 97678c96cba..2200a38beca 100644 --- a/lib/public/appframework/http/templateresponse.php +++ b/lib/public/appframework/http/templateresponse.php @@ -1,5 +1,4 @@ <?php - /** * ownCloud - App Framework * @@ -21,33 +20,51 @@ * */ +/** + * Public interface of ownCloud for apps to use. + * AppFramework\HTTP\TemplateResponse class + */ namespace OCP\AppFramework\Http; -use OC\AppFramework\Core\API; - /** * Response for a normal template */ class TemplateResponse extends Response { + /** + * name of the template + * @var string + */ protected $templateName; + + /** + * parameters + * @var array + */ protected $params; - protected $api; + + /** + * rendering type (admin, user, blank) + * @var string + */ protected $renderAs; + + /** + * app name + * @var string + */ protected $appName; /** - * @param API $api an API instance + * constructor of TemplateResponse + * @param string $appName the name of the app to load the template from * @param string $templateName the name of the template - * @param string $appName optional if you want to include a template from - * a different app */ - public function __construct(API $api, $templateName, $appName=null) { + public function __construct($appName, $templateName) { $this->templateName = $templateName; $this->appName = $appName; - $this->api = $api; $this->params = array(); $this->renderAs = 'user'; } @@ -108,13 +125,7 @@ class TemplateResponse extends Response { */ public function render(){ - if($this->appName !== null){ - $appName = $this->appName; - } else { - $appName = $this->api->getAppName(); - } - - $template = $this->api->getTemplate($this->templateName, $this->renderAs, $appName); + $template = new \OCP\Template($this->appName, $this->templateName, $this->renderAs); foreach($this->params as $key => $value){ $template->assign($key, $value); diff --git a/lib/public/appframework/iapi.php b/lib/public/appframework/iapi.php index fa6af5f5965..963e870f79b 100644 --- a/lib/public/appframework/iapi.php +++ b/lib/public/appframework/iapi.php @@ -1,5 +1,4 @@ <?php - /** * ownCloud - App Framework * @@ -21,6 +20,10 @@ * */ +/** + * Public interface of ownCloud for apps to use. + * AppFramework/IApi interface + */ namespace OCP\AppFramework; @@ -67,59 +70,6 @@ interface IApi { */ function add3rdPartyStyle($name); - /** - * Returns the translation object - * @return \OC_L10N the translation object - * - * FIXME: returns private object / should be retrieved from teh ServerContainer - */ - function getTrans(); - - - /** - * Returns the URL for a route - * @param string $routeName the name of the route - * @param array $arguments an array with arguments which will be filled into the url - * @return string the url - */ - function linkToRoute($routeName, $arguments=array()); - - - /** - * Returns an URL for an image or file - * @param string $file the name of the file - * @param string $appName the name of the app, defaults to the current one - */ - function linkTo($file, $appName=null); - - - /** - * Returns the link to an image, like link to but only with prepending img/ - * @param string $file the name of the file - * @param string $appName the name of the app, defaults to the current one - */ - function imagePath($file, $appName = null); - - - /** - * Makes an URL absolute - * @param string $url the url - * @return string the absolute url - * - * FIXME: function should live in Request / Response - */ - function getAbsoluteURL($url); - - - /** - * links to a file - * @param string $file the name of the file - * @param string $appName the name of the app, defaults to the current one - * @deprecated replaced with linkToRoute() - * @return string the url - */ - function linkToAbsolute($file, $appName = null); - /** * Checks if an app is enabled @@ -128,24 +78,4 @@ interface IApi { */ public function isAppEnabled($appName); - - /** - * Writes a function into the error log - * @param string $msg the error message to be logged - * @param int $level the error level - * - * FIXME: add logger instance to ServerContainer - */ - function log($msg, $level = null); - - - /** - * Returns a template - * @param string $templateName the name of the template - * @param string $renderAs how it should be rendered - * @param string $appName the name of the app - * @return \OCP\Template a new template - */ - function getTemplate($templateName, $renderAs='user', $appName=null); - } diff --git a/lib/public/appframework/iappcontainer.php b/lib/public/appframework/iappcontainer.php index 7d3b4b3bac7..7e6ec6016b7 100644 --- a/lib/public/appframework/iappcontainer.php +++ b/lib/public/appframework/iappcontainer.php @@ -50,8 +50,26 @@ interface IAppContainer extends IContainer{ function getServer(); /** - * @param IMiddleWare $middleWare + * @param Middleware $middleWare * @return boolean */ - function registerMiddleWare(IMiddleWare $middleWare); + function registerMiddleWare(Middleware $middleWare); + + /** + * @return boolean + */ + function isLoggedIn(); + + /** + * @return boolean + */ + function isAdminUser(); + + /** + * @param $message + * @param $level + * @return mixed + */ + function log($message, $level); + } diff --git a/lib/public/appframework/imiddleware.php b/lib/public/appframework/middleware.php index 1e76d3bbe49..24f31939935 100644 --- a/lib/public/appframework/imiddleware.php +++ b/lib/public/appframework/middleware.php @@ -1,5 +1,4 @@ <?php - /** * ownCloud - App Framework * @@ -21,8 +20,14 @@ * */ +/** + * Public interface of ownCloud for apps to use. + * AppFramework\Middleware class + */ namespace OCP\AppFramework; + +use OCP\AppFramework\Controller; use OCP\AppFramework\Http\Response; @@ -32,7 +37,7 @@ use OCP\AppFramework\Http\Response; * They're modeled after Django's middleware system: * https://docs.djangoproject.com/en/dev/topics/http/middleware/ */ -interface IMiddleWare { +abstract class Middleware { /** @@ -43,7 +48,9 @@ interface IMiddleWare { * @param string $methodName the name of the method that will be called on * the controller */ - function beforeController($controller, $methodName); + public function beforeController($controller, $methodName){ + + } /** @@ -60,10 +67,13 @@ interface IMiddleWare { * @throws \Exception the passed in exception if it cant handle it * @return Response a Response object in case that the exception was handled */ - function afterException($controller, $methodName, \Exception $exception); + public function afterException($controller, $methodName, \Exception $exception){ + throw $exception; + } + /** - * This is being run after a successful controller method call and allows + * 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 @@ -72,7 +82,10 @@ interface IMiddleWare { * @param Response $response the generated response from the controller * @return Response a Response object */ - function afterController($controller, $methodName, Response $response); + public function afterController($controller, $methodName, Response $response){ + return $response; + } + /** * This is being run after the response object has been rendered and @@ -84,5 +97,8 @@ interface IMiddleWare { * @param string $output the generated output from a response * @return string the output that should be printed */ - function beforeOutput($controller, $methodName, $output); + public function beforeOutput($controller, $methodName, $output){ + return $output; + } + } diff --git a/lib/public/authentication/iapachebackend.php b/lib/public/authentication/iapachebackend.php new file mode 100644 index 00000000000..3979a14302e --- /dev/null +++ b/lib/public/authentication/iapachebackend.php @@ -0,0 +1,55 @@ +<?php +/** + * ownCloud - Apache backend + * + * @author Karl Beecher + * @copyright 2013 Karl Beecher - karl@endocode.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/>. + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Authentication/IApacheBackend interface + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Authentication; + +interface IApacheBackend { + + /** + * In case the user has been authenticated by Apache true is returned. + * + * @return boolean whether Apache reports a user as currently logged in. + */ + public function isSessionActive(); + + /** + * Creates an attribute which is added to the logout hyperlink. It can + * supply any attribute(s) which are valid for <a>. + * + * @return string with one or more HTML attributes. + */ + public function getLogoutAttribute(); + + /** + * Return the id of the current user + * @return string + */ + public function getCurrentUserId(); + +} diff --git a/lib/public/backgroundjob.php b/lib/public/backgroundjob.php index cc076a3a845..a7f54491dfa 100644 --- a/lib/public/backgroundjob.php +++ b/lib/public/backgroundjob.php @@ -44,7 +44,8 @@ use \OC\BackgroundJob\JobList; */ class BackgroundJob { /** - * @brief get the execution type of background jobs + * get the execution type of background jobs + * * @return string * * This method returns the type how background jobs are executed. If the user @@ -55,7 +56,8 @@ class BackgroundJob { } /** - * @brief sets the background jobs execution type + * sets the background jobs execution type + * * @param string $type execution type * @return boolean * @@ -77,19 +79,21 @@ class BackgroundJob { /** * @deprecated - * @brief creates a regular task + * creates a regular task * @param string $klass class name * @param string $method method name * @return true */ public static function addRegularTask($klass, $method) { - self::registerJob('OC\BackgroundJob\Legacy\RegularJob', array($klass, $method)); - return true; + if (!\OC::needUpgrade()) { + self::registerJob('OC\BackgroundJob\Legacy\RegularJob', array($klass, $method)); + return true; + } } /** * @deprecated - * @brief gets all regular tasks + * gets all regular tasks * @return associative array * * key is string "$klass-$method", value is array( $klass, $method ) @@ -109,7 +113,7 @@ class BackgroundJob { /** * @deprecated - * @brief Gets one queued task + * Gets one queued task * @param int $id ID of the task * @return associative array */ @@ -120,7 +124,7 @@ class BackgroundJob { /** * @deprecated - * @brief Gets all queued tasks + * Gets all queued tasks * @return array with associative arrays */ public static function allQueuedTasks() { @@ -139,7 +143,7 @@ class BackgroundJob { /** * @deprecated - * @brief Gets all queued tasks of a specific app + * Gets all queued tasks of a specific app * @param string $app app name * @return array with associative arrays */ @@ -161,7 +165,7 @@ class BackgroundJob { /** * @deprecated - * @brief queues a task + * queues a task * @param string $app app name * @param string $class class name * @param string $method method name @@ -175,7 +179,7 @@ class BackgroundJob { /** * @deprecated - * @brief deletes a queued task + * deletes a queued task * @param int $id id of task * @return bool * diff --git a/lib/public/config.php b/lib/public/config.php index 73476d7551d..d9355a0605f 100644 --- a/lib/public/config.php +++ b/lib/public/config.php @@ -1,24 +1,24 @@ <?php /** -* ownCloud -* -* @author Frank Karlitschek -* @copyright 2012 Frank Karlitschek frank@owncloud.org -* -* 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/>. -* -*/ + * ownCloud + * + * @author Frank Karlitschek + * @copyright 2012 Frank Karlitschek frank@owncloud.org + * + * 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/>. + * + */ /** * Public interface of ownCloud for apps to use. @@ -27,7 +27,7 @@ */ /** - * @brief use OCP namespace for all classes that are considered public. + * Use OCP namespace for all classes that are considered public. * * Classes that use this namespace are for use by apps, and not for use by internal * OC classes @@ -40,7 +40,7 @@ namespace OCP; */ class Config { /** - * @brief Gets a value from config.php + * Gets a value from config.php * @param string $key key * @param string $default = null default value * @return string the value or $default @@ -53,7 +53,7 @@ class Config { } /** - * @brief Sets a value + * Sets a value * @param string $key key * @param string $value value * @return bool @@ -71,7 +71,7 @@ class Config { } /** - * @brief Gets the config value + * Gets the config value * @param string $app app * @param string $key key * @param string $default = null, default value if the key does not exist @@ -85,7 +85,7 @@ class Config { } /** - * @brief sets a value in the appconfig + * Sets a value in the appconfig * @param string $app app * @param string $key key * @param string $value value @@ -103,7 +103,7 @@ class Config { } /** - * @brief Gets the preference + * Gets the preference * @param string $user user * @param string $app app * @param string $key key @@ -118,12 +118,12 @@ class Config { } /** - * @brief sets a value in the preferences + * Sets a value in the preferences * @param string $user user * @param string $app app * @param string $key key * @param string $value value - * @returns bool + * @return bool * * Adds a value to the preferences. If the key did not exist before, it * will be added automagically. diff --git a/lib/public/contacts/imanager.php b/lib/public/contacts/imanager.php index 3bfbca7be50..973d48be5ec 100644 --- a/lib/public/contacts/imanager.php +++ b/lib/public/contacts/imanager.php @@ -119,11 +119,15 @@ namespace OCP\Contacts { function isEnabled(); /** + * Registers an address book + * * @param \OCP\IAddressBook $address_book */ function registerAddressBook(\OCP\IAddressBook $address_book); /** + * Unregisters an address book + * * @param \OCP\IAddressBook $address_book */ function unregisterAddressBook(\OCP\IAddressBook $address_book); diff --git a/lib/public/db.php b/lib/public/db.php index 9512cca2d19..4a19d78d444 100644 --- a/lib/public/db.php +++ b/lib/public/db.php @@ -1,24 +1,24 @@ <?php /** -* ownCloud -* -* @author Frank Karlitschek -* @copyright 2012 Frank Karlitschek frank@owncloud.org -* -* 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/>. -* -*/ + * ownCloud + * + * @author Frank Karlitschek + * @copyright 2012 Frank Karlitschek frank@owncloud.org + * + * 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/>. + * + */ /** * Public interface of ownCloud for apps to use. @@ -35,18 +35,20 @@ namespace OCP; */ class DB { /** - * @brief Prepare a SQL query + * Prepare a SQL query * @param string $query Query string - * @return \MDB2_Statement_Common prepared SQL query + * @param int $limit Limit of the SQL statement + * @param int $offset Offset of the SQL statement + * @return \Doctrine\DBAL\Statement prepared SQL query * - * SQL query via MDB2 prepare(), needs to be execute()'d! + * SQL query via Doctrine prepare(), needs to be execute()'d! */ static public function prepare( $query, $limit=null, $offset=null ) { return(\OC_DB::prepare($query, $limit, $offset)); } /** - * @brief Insert a row if a matching row doesn't exists. + * Insert a row if a matching row doesn't exists. * @param $table string The table name (will replace *PREFIX*) to perform the replace on. * @param $input array * @@ -67,11 +69,11 @@ class DB { } /** - * @brief gets last value of autoincrement + * Gets last value of autoincrement * @param $table string The optional table name (will replace *PREFIX*) and add sequence suffix * @return int * - * MDB2 lastInsertID() + * \Doctrine\DBAL\Connection lastInsertID() * * Call this method right after the insert command or other functions may * cause trouble! @@ -81,21 +83,21 @@ class DB { } /** - * @brief Start a transaction + * Start a transaction */ public static function beginTransaction() { - return(\OC_DB::beginTransaction()); + \OC_DB::beginTransaction(); } /** - * @brief Commit the database changes done during a transaction that is in progress + * Commit the database changes done during a transaction that is in progress */ public static function commit() { - return(\OC_DB::commit()); + \OC_DB::commit(); } /** - * @brief check if a result is an error, works with MDB2 and PDOException + * Check if a result is an error, works with Doctrine * @param mixed $result * @return bool */ diff --git a/lib/public/defaults.php b/lib/public/defaults.php index 147f23e341f..34b68903ee8 100644 --- a/lib/public/defaults.php +++ b/lib/public/defaults.php @@ -1,41 +1,56 @@ <?php /** -* ownCloud -* -* @author Björn Schießle -* @copyright 2013 Björn Schießle schiessle@owncloud.com -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ + * ownCloud + * + * @author Björn Schießle + * @copyright 2013 Björn Schießle schiessle@owncloud.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Defaults Class + * + */ +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; -/* +/** * public api to access default strings and urls for your templates */ - class Defaults { + /** + * \OC_Defaults instance to retrieve the defaults + * @return string + */ private $defaults; + /** + * creates a \OC_Defaults instance which is used in all methods to retrieve the + * actual defaults + */ function __construct() { $this->defaults = new \OC_Defaults(); } /** - * @breif get base URL for the organisation behind your ownCloud instance + * get base URL for the organisation behind your ownCloud instance * @return string */ public function getBaseUrl() { @@ -43,7 +58,7 @@ class Defaults { } /** - * @breif link to the desktop sync client + * link to the desktop sync client * @return string */ public function getSyncClientUrl() { @@ -51,7 +66,7 @@ class Defaults { } /** - * @breif base URL to the documentation of your ownCloud instance + * base URL to the documentation of your ownCloud instance * @return string */ public function getDocBaseUrl() { @@ -59,7 +74,7 @@ class Defaults { } /** - * @breif name of your ownCloud instance + * name of your ownCloud instance * @return string */ public function getName() { @@ -67,7 +82,7 @@ class Defaults { } /** - * @breif Entity behind your onwCloud instance + * Entity behind your onwCloud instance * @return string */ public function getEntity() { @@ -75,7 +90,7 @@ class Defaults { } /** - * @breif ownCloud slogan + * ownCloud slogan * @return string */ public function getSlogan() { @@ -83,7 +98,7 @@ class Defaults { } /** - * @breif logo claim + * logo claim * @return string */ public function getLogoClaim() { @@ -91,7 +106,7 @@ class Defaults { } /** - * @breif footer, short version + * footer, short version * @return string */ public function getShortFooter() { @@ -99,7 +114,7 @@ class Defaults { } /** - * @breif footer, long version + * footer, long version * @return string */ public function getLongFooter() { diff --git a/lib/public/files.php b/lib/public/files.php index 852b041eefb..d36d74fdf77 100644 --- a/lib/public/files.php +++ b/lib/public/files.php @@ -1,24 +1,24 @@ <?php /** -* ownCloud -* -* @author Frank Karlitschek -* @copyright 2012 Frank Karlitschek frank@owncloud.org -* -* 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/>. -* -*/ + * ownCloud + * + * @author Frank Karlitschek + * @copyright 2012 Frank Karlitschek frank@owncloud.org + * + * 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/>. + * + */ /** * Public interface of ownCloud for apps to use. @@ -36,9 +36,8 @@ namespace OCP; */ class Files { /** - * @brief Recusive deletion of folders - * @param string $dir path to the folder - * + * Recusive deletion of folders + * @param string path to the folder * @return bool */ static function rmdirr( $dir ) { @@ -46,7 +45,7 @@ class Files { } /** - * get the mimetype form a local file + * Get the mimetype form a local file * @param string path * @return string * does NOT work for ownClouds filesystem, use OC_FileSystem::getMimeType instead @@ -56,17 +55,16 @@ class Files { } /** - * search for files by mimetype - * - * @param string $query + * Search for files by mimetype + * @param string mimetype * @return array */ - static public function searchByMime($mimetype) { + static public function searchByMime( $mimetype ) { return(\OC\Files\Filesystem::searchByMime( $mimetype )); } /** - * copy the contents of one stream to another + * Copy the contents of one stream to another * @param resource source * @param resource target * @return int the number of bytes copied @@ -77,7 +75,7 @@ class Files { } /** - * create a temporary file with an unique filename + * Create a temporary file with an unique filename * @param string postfix * @return string * @@ -88,7 +86,7 @@ class Files { } /** - * create a temporary folder with an unique filename + * Create a temporary folder with an unique filename * @return string * * temporary files are automatically cleaned up after the script is finished @@ -99,9 +97,8 @@ class Files { /** * 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 ) { @@ -109,8 +106,9 @@ class Files { } /** + * Gets the Storage for an app - creates the needed folder if they are not + * existant * @param string appid - * @param $app app * @return \OC\Files\View */ public static function getStorage( $app ) { diff --git a/lib/public/files/alreadyexistsexception.php b/lib/public/files/alreadyexistsexception.php index 32947c7a5c3..7bea947aef0 100644 --- a/lib/public/files/alreadyexistsexception.php +++ b/lib/public/files/alreadyexistsexception.php @@ -1,11 +1,35 @@ <?php /** - * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com> - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. + * ownCloud + * + * @author Robin Appelman + * @copyright 2013 Robin Appelman icewind@owncloud.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * */ +/** + * Public interface of ownCloud for apps to use. + * Files/AlreadyExistsException class + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP\Files; +/** + * Exception for already existing files/folders + */ class AlreadyExistsException extends \Exception {} diff --git a/lib/public/files/entitytoolargeexception.php b/lib/public/files/entitytoolargeexception.php new file mode 100644 index 00000000000..eaa68a548b9 --- /dev/null +++ b/lib/public/files/entitytoolargeexception.php @@ -0,0 +1,35 @@ +<?php +/** + * ownCloud + * + * @author Thomas Müller + * @copyright 2013 Thomas Müller deepdiver@owncloud.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Files/EntityTooLargeException class + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +/** + * Exception for too large entity + */ +class EntityTooLargeException extends \Exception {} diff --git a/lib/public/files/file.php b/lib/public/files/file.php index 916b2edd6c4..c6cda59f9b0 100644 --- a/lib/public/files/file.php +++ b/lib/public/files/file.php @@ -1,11 +1,32 @@ <?php /** - * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com> - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. + * ownCloud + * + * @author Robin Appelman + * @copyright 2013 Robin Appelman icewind@owncloud.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * */ +/** + * Public interface of ownCloud for apps to use. + * Files/File interface + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP\Files; interface File extends Node { diff --git a/lib/public/files/folder.php b/lib/public/files/folder.php index da7f20fd366..7fec1c529a5 100644 --- a/lib/public/files/folder.php +++ b/lib/public/files/folder.php @@ -1,11 +1,32 @@ <?php /** - * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com> - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. + * ownCloud + * + * @author Robin Appelman + * @copyright 2013 Robin Appelman icewind@owncloud.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * */ +/** + * Public interface of ownCloud for apps to use. + * Files/Folder interface + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP\Files; interface Folder extends Node { diff --git a/lib/public/files/invalidcontentexception.php b/lib/public/files/invalidcontentexception.php new file mode 100644 index 00000000000..3dfe7378c4d --- /dev/null +++ b/lib/public/files/invalidcontentexception.php @@ -0,0 +1,35 @@ +<?php +/** + * ownCloud + * + * @author Thomas Müller + * @copyright 2013 Thomas Müller deepdiver@owncloud.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Files/InvalidContentException class + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +/** + * Exception for invalid content + */ +class InvalidContentException extends \Exception {} diff --git a/lib/public/files/invalidpathexception.php b/lib/public/files/invalidpathexception.php new file mode 100644 index 00000000000..8ecfa7d89ad --- /dev/null +++ b/lib/public/files/invalidpathexception.php @@ -0,0 +1,35 @@ +<?php +/** + * ownCloud + * + * @author Thomas Müller + * @copyright 2013 Thomas Müller deepdiver@owncloud.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Files/InvalidPathException class + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +/** + * Exception for invalid path + */ +class InvalidPathException extends \Exception {} diff --git a/lib/public/files/node.php b/lib/public/files/node.php index b3ddf6de621..972b1cfa492 100644 --- a/lib/public/files/node.php +++ b/lib/public/files/node.php @@ -1,11 +1,32 @@ <?php /** - * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com> - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. + * ownCloud + * + * @author Robin Appelman + * @copyright 2013 Robin Appelman icewind@owncloud.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * */ +/** + * Public interface of ownCloud for apps to use. + * Files/Node interface + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP\Files; interface Node { diff --git a/lib/public/files/notenoughspaceexception.php b/lib/public/files/notenoughspaceexception.php index e51806666ad..17f91b31bfc 100644 --- a/lib/public/files/notenoughspaceexception.php +++ b/lib/public/files/notenoughspaceexception.php @@ -1,11 +1,35 @@ <?php /** - * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com> - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. + * ownCloud + * + * @author Robin Appelman + * @copyright 2013 Robin Appelman icewind@owncloud.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * */ +/** + * Public interface of ownCloud for apps to use. + * Files/NotEnoughSpaceException class + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP\Files; +/** + * Exception for not enough space + */ class NotEnoughSpaceException extends \Exception {} diff --git a/lib/public/files/notfoundexception.php b/lib/public/files/notfoundexception.php index 1ff426a40c6..cb35199220b 100644 --- a/lib/public/files/notfoundexception.php +++ b/lib/public/files/notfoundexception.php @@ -1,11 +1,35 @@ <?php /** - * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com> - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. + * ownCloud + * + * @author Robin Appelman + * @copyright 2013 Robin Appelman icewind@owncloud.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * */ +/** + * Public interface of ownCloud for apps to use. + * Files/NotFoundException class + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP\Files; +/** + * Exception for not found entity + */ class NotFoundException extends \Exception {} diff --git a/lib/public/files/notpermittedexception.php b/lib/public/files/notpermittedexception.php index 0509de7e829..e37bd6fad3c 100644 --- a/lib/public/files/notpermittedexception.php +++ b/lib/public/files/notpermittedexception.php @@ -1,11 +1,35 @@ <?php /** - * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com> - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. + * ownCloud + * + * @author Robin Appelman + * @copyright 2013 Robin Appelman icewind@owncloud.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * */ +/** + * Public interface of ownCloud for apps to use. + * Files/NotPermittedException class + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP\Files; +/** + * Exception for not permitted action + */ class NotPermittedException extends \Exception {} diff --git a/lib/public/files/storage.php b/lib/public/files/storage.php index f32f2073483..194b42a6481 100644 --- a/lib/public/files/storage.php +++ b/lib/public/files/storage.php @@ -1,11 +1,32 @@ <?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. + * ownCloud + * + * @author Robin Appelman + * @copyright 2012 Robin Appelman icewind@owncloud.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Files/Storage interface */ +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP\Files; /** diff --git a/lib/public/groupinterface.php b/lib/public/groupinterface.php index 5603faa8265..625e0b12a87 100644 --- a/lib/public/groupinterface.php +++ b/lib/public/groupinterface.php @@ -1,24 +1,24 @@ <?php /** -* ownCloud -* -* @author Arthur Schiwon -* @copyright 2012 Arthur Schiwon blizzz@owncloud.org -* -* 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/>. -* -*/ + * ownCloud + * + * @author Arthur Schiwon + * @copyright 2012 Arthur Schiwon blizzz@owncloud.org + * + * 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/>. + * + */ /** * Public interface of ownCloud for apps to use. @@ -26,6 +26,8 @@ * */ +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; interface GroupInterface extends \OC_Group_Interface {} diff --git a/lib/public/iaddressbook.php b/lib/public/iaddressbook.php index 77e8750d9da..dcfe08012e6 100644 --- a/lib/public/iaddressbook.php +++ b/lib/public/iaddressbook.php @@ -20,6 +20,11 @@ * */ +/** + * Public interface of ownCloud for apps to use. + * IAddressBook interface + */ + // use OCP namespace for all classes that are considered public. // This means that they should be used by apps instead of the internal ownCloud classes namespace OCP { diff --git a/lib/public/iappconfig.php b/lib/public/iappconfig.php new file mode 100644 index 00000000000..3b6484c09d5 --- /dev/null +++ b/lib/public/iappconfig.php @@ -0,0 +1,91 @@ +<?php +/** + * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +namespace OCP; + +/** + * This class provides an easy way for apps to store config values in the + * database. + */ +interface IAppConfig { + /** + * @brief check if a key is set in the appconfig + * @param string $app + * @param string $key + * @return bool + */ + public function hasKey($app, $key); + + /** + * @brief Gets the config value + * @param string $app app + * @param string $key key + * @param string $default = null, default value if the key does not exist + * @return string the value or $default + * + * This function gets a value from the appconfig table. If the key does + * not exist the default value will be returned + */ + public function getValue($app, $key, $default = null); + + /** + * @brief Deletes a key + * @param string $app app + * @param string $key key + * @return bool + * + * Deletes a key. + */ + public function deleteKey($app, $key); + + /** + * @brief Get the available keys for an app + * @param string $app the app we are looking for + * @return array with key names + * + * This function gets all keys of an app. Please note that the values are + * not returned. + */ + public function getKeys($app); + + /** + * get multiply values, either the app or key can be used as wildcard by setting it to false + * + * @param app + * @param key + * @return array + */ + public function getValues($app, $key); + + /** + * @brief sets a value in the appconfig + * @param string $app app + * @param string $key key + * @param string $value value + * + * Sets a value. If the key did not exist before it will be created. + */ + public function setValue($app, $key, $value); + + /** + * @brief Get all apps using the config + * @return array with app ids + * + * This function returns a list of all apps that have at least one + * entry in the appconfig table. + */ + public function getApps(); + + /** + * @brief Remove app from appconfig + * @param string $app app + * @return bool + * + * Removes all keys in appconfig belonging to the app. + */ + public function deleteApp($app); +} diff --git a/lib/public/iavatar.php b/lib/public/iavatar.php new file mode 100644 index 00000000000..2cbec0d45c3 --- /dev/null +++ b/lib/public/iavatar.php @@ -0,0 +1,38 @@ +<?php +/** + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCP; + +/** + * This class provides avatar functionality + */ + +interface IAvatar { + + /** + * @brief get the users avatar + * @param $size integer 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 + */ + function get($size = 64); + + /** + * @brief sets the users avatar + * @param $data mixed 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 \OCP\NotSquareException if the image is not square + * @return void + */ + function set($data); + + /** + * @brief remove the users avatar + * @return void + */ + function remove(); +} diff --git a/lib/public/iavatarmanager.php b/lib/public/iavatarmanager.php new file mode 100644 index 00000000000..9b185ae0467 --- /dev/null +++ b/lib/public/iavatarmanager.php @@ -0,0 +1,23 @@ +<?php +/** + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCP; + +/** + * This class provides avatar functionality + */ + +interface IAvatarManager { + + /** + * @brief return a user specific instance of \OCP\IAvatar + * @see \OCP\IAvatar + * @param $user string the ownCloud user id + * @return \OCP\IAvatar + */ + function getAvatar($user); +} diff --git a/lib/public/icache.php b/lib/public/icache.php index 436ee71b2b9..0da994eadb3 100644 --- a/lib/public/icache.php +++ b/lib/public/icache.php @@ -1,10 +1,33 @@ <?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. + * ownCloud + * + * @author Thomas Tanghus + * @copyright 2013 Thomas Tanghus thomas@tanghus.net + * + * 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/>. + * */ + +/** + * Public interface of ownCloud for apps to use. + * Cache interface + * + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; /** @@ -14,7 +37,6 @@ interface ICache { /** * Get a value from the user cache - * * @param string $key * @return mixed */ @@ -22,7 +44,6 @@ interface ICache { /** * Set a value in the user cache - * * @param string $key * @param mixed $value * @param int $ttl Time To Live in seconds. Defaults to 60*60*24 @@ -32,7 +53,6 @@ interface ICache { /** * Check if a value is set in the user cache - * * @param string $key * @return bool */ @@ -40,14 +60,13 @@ interface ICache { /** * Remove an item from the user cache - * * @param string $key * @return bool */ public function remove($key); /** - * clear the user cache of all entries starting with a prefix + * Clear the user cache of all entries starting with a prefix * @param string $prefix (optional) * @return bool */ diff --git a/lib/public/icachefactory.php b/lib/public/icachefactory.php new file mode 100644 index 00000000000..874f1ec0a59 --- /dev/null +++ b/lib/public/icachefactory.php @@ -0,0 +1,28 @@ +<?php +/** + * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OCP; + +interface ICacheFactory{ + /** + * Get a memory cache instance + * + * All entries added trough the cache instance will be namespaced by $prefix to prevent collisions between apps + * + * @param string $prefix + * @return \OCP\ICache + */ + public function create($prefix = ''); + + /** + * Check if any memory cache backend is available + * + * @return bool + */ + public function isAvailable(); +} diff --git a/lib/public/iconfig.php b/lib/public/iconfig.php index 850bddf6935..1d0f8e0015c 100644 --- a/lib/public/iconfig.php +++ b/lib/public/iconfig.php @@ -1,12 +1,33 @@ <?php /** - * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl> - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - * + * ownCloud + * + * @author Bart Visscher + * @copyright 2013 Bart Visscher bartv@thisnet.nl + * + * 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/>. + * */ +/** + * Public interface of ownCloud for apps to use. + * Config interface + * + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; /** @@ -15,6 +36,7 @@ namespace OCP; interface IConfig { /** * Sets a new system wide value + * * @param string $key the key of the value, under which will be saved * @param string $value the value that should be stored * @todo need a use case for this @@ -23,14 +45,17 @@ interface IConfig { /** * Looks up a system wide defined value + * * @param string $key the key of the value, under which it was saved + * @param string $default the default value to be returned if the value isn't set * @return string the saved value */ - public function getSystemValue($key); + public function getSystemValue($key, $default = ''); /** * Writes a new app wide value + * * @param string $appName the appName that we want to store the value under * @param string $key the key of the value, under which will be saved * @param string $value the value that should be stored @@ -39,15 +64,18 @@ interface IConfig { /** * Looks up an app wide defined value + * * @param string $appName the appName that we stored the value under * @param string $key the key of the value, under which it was saved + * @param string $default the default value to be returned if the value isn't set * @return string the saved value */ - public function getAppValue($appName, $key); + public function getAppValue($appName, $key, $default = ''); /** * Set a user defined value + * * @param string $userId the userId of the user that we want to store the value under * @param string $appName the appName that we want to store the value under * @param string $key the key under which the value is being stored @@ -57,9 +85,11 @@ interface IConfig { /** * Shortcut for getting a user defined value + * * @param string $userId the userId of the user that we want to store the value under * @param string $appName the appName that we stored the value under * @param string $key the key under which the value is being stored + * @param string $default the default value to be returned if the value isn't set */ - public function getUserValue($userId, $appName, $key); + public function getUserValue($userId, $appName, $key, $default = ''); } diff --git a/lib/public/icontainer.php b/lib/public/icontainer.php index d43c1c90f11..eaffa5d5a06 100644 --- a/lib/public/icontainer.php +++ b/lib/public/icontainer.php @@ -20,6 +20,14 @@ * */ +/** + * Public interface of ownCloud for apps to use. + * Container interface + * + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; /** @@ -56,7 +64,7 @@ interface IContainer { * In case the parameter is false the service will be recreated on every call. * * @param string $name - * @param callable $closure + * @param \Closure $closure * @param bool $shared * @return void */ diff --git a/lib/public/idbconnection.php b/lib/public/idbconnection.php index c741a0f061a..656b5e7e5b2 100644 --- a/lib/public/idbconnection.php +++ b/lib/public/idbconnection.php @@ -1,12 +1,33 @@ <?php /** - * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl> - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - * + * ownCloud + * + * @author Bart Visscher + * @copyright 2013 Bart Visscher bartv@thisnet.nl + * + * 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/>. + * */ +/** + * Public interface of ownCloud for apps to use. + * DBConnection interface + * + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; /** @@ -24,15 +45,15 @@ interface IDBConnection { /** * Used to get the id of the just inserted element - * @param string $tableName the name of the table where we inserted the item + * @param string $table the name of the table where we inserted the item * @return int the id of the inserted element */ public function lastInsertId($table = null); /** - * @brief Insert a row if a matching row doesn't exists. - * @param $table string The table name (will replace *PREFIX*) to perform the replace on. - * @param $input array + * 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 * * The input array if in the form: * @@ -49,25 +70,25 @@ interface IDBConnection { public function insertIfNotExist($table, $input); /** - * @brief Start a transaction + * Start a transaction * @return bool TRUE on success or FALSE on failure */ public function beginTransaction(); /** - * @brief Commit the database changes done during a transaction that is in progress + * Commit the database changes done during a transaction that is in progress * @return bool TRUE on success or FALSE on failure */ public function commit(); /** - * @brief Rollback the database changes done during a transaction that is in progress + * Rollback the database changes done during a transaction that is in progress * @return bool TRUE on success or FALSE on failure */ public function rollBack(); /** - * returns the error code and message as a string for logging + * Gets the error code and message as a string for logging * @return string */ public function getError(); diff --git a/lib/public/ihelper.php b/lib/public/ihelper.php new file mode 100644 index 00000000000..c0723b8edc7 --- /dev/null +++ b/lib/public/ihelper.php @@ -0,0 +1,44 @@ +<?php +/** + * ownCloud + * + * @author Bart Visscher + * @copyright 2013 Bart Visscher bartv@thisnet.nl + * + * 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/>. + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Helper interface + * + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP; + +/** + * Functions that don't have any specific interface to place + */ +interface IHelper { + /** + * Gets the content of an URL by using CURL or a fallback if it is not + * installed + * @param string $url the url that should be fetched + * @return string the content of the webpage + */ + public function getUrlContent($url); +} diff --git a/lib/public/il10n.php b/lib/public/il10n.php new file mode 100644 index 00000000000..817b299b0b7 --- /dev/null +++ b/lib/public/il10n.php @@ -0,0 +1,75 @@ +<?php +/** + * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + * + */ + +/** + * Public interface of ownCloud for apps to use. + * L10n interface + * + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP; + +/** + * TODO: Description + */ +interface IL10N { + /** + * Translating + * @param $text String The text we need a translation for + * @param array $parameters default:array() Parameters for sprintf + * @return \OC_L10N_String|string Translation or the same text + * + * Returns the translation. If no translation is found, $text will be + * returned. + */ + public function t($text, $parameters = array()); + + /** + * Translating + * @param $text_singular String the string to translate for exactly one object + * @param $text_plural String the string to translate for n objects + * @param $count Integer Number of objects + * @param array $parameters default:array() Parameters for sprintf + * @return \OC_L10N_String|string Translation or the same text + * + * Returns the translation. If no translation is found, $text will be + * returned. %n will be replaced with the number of objects. + * + * The correct plural is determined by the plural_forms-function + * provided by the po file. + * + */ + public function n($text_singular, $text_plural, $count, $parameters = array()); + + /** + * Localization + * @param $type Type of localization + * @param $params parameters for this localization + * @return String or false + * + * Returns the localized data. + * + * Implemented types: + * - date + * - Creates a date + * - l10n-field: date + * - params: timestamp (int/string) + * - datetime + * - Creates date and time + * - l10n-field: datetime + * - params: timestamp (int/string) + * - time + * - Creates a time + * - l10n-field: time + * - params: timestamp (int/string) + */ + public function l($type, $data); +} diff --git a/lib/public/image.php b/lib/public/image.php index c6dd9a113ab..a9e2bfa724e 100644 --- a/lib/public/image.php +++ b/lib/public/image.php @@ -1,25 +1,33 @@ <?php /** -* ownCloud -* -* @author Bart Visscher -* @copyright 2013 Bart Visscher <bartv@thisnet.nl> -* -* 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/>. -* -*/ + * ownCloud + * + * @author Bart Visscher + * @copyright 2013 Bart Visscher <bartv@thisnet.nl> + * + * 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/>. + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Image class + * + */ +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; /** diff --git a/lib/public/inavigationmanager.php b/lib/public/inavigationmanager.php index f89e790c1d0..73e85d03761 100644 --- a/lib/public/inavigationmanager.php +++ b/lib/public/inavigationmanager.php @@ -1,12 +1,33 @@ <?php /** - * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl> - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - * + * ownCloud + * + * @author Bart Visscher + * @copyright 2013 Bart Visscher bartv@thisnet.nl + * + * 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/>. + * */ +/** + * Public interface of ownCloud for apps to use. + * Navigation manager interface + * + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; /** diff --git a/lib/public/ipreview.php b/lib/public/ipreview.php index b01e7f5b539..f74472ad368 100644 --- a/lib/public/ipreview.php +++ b/lib/public/ipreview.php @@ -1,11 +1,36 @@ <?php + /** - * Copyright (c) 2013 Frank Karlitschek frank@owncloud.org - * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. + * ownCloud + * + * @author Frank Karlitschek + * @author Georg Ehrke + * @copyright 2013 Frank Karlitschek frank@owncloud.org + * @copyright 2013 Georg Ehrke georg@owncloud.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * */ + +/** + * Public interface of ownCloud for apps to use. + * Preview interface + * + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; /** @@ -15,7 +40,7 @@ interface IPreview { /** - * @brief return a preview of a file + * Return a preview of a file * @param string $file The path to the file where you want a thumbnail from * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image @@ -26,7 +51,7 @@ interface IPreview /** - * @brief returns true if the passed mime type is supported + * Returns true if the passed mime type is supported * @param string $mimeType * @return boolean */ diff --git a/lib/public/irequest.php b/lib/public/irequest.php index 9f335b06f2a..ca23e12b7f5 100644 --- a/lib/public/irequest.php +++ b/lib/public/irequest.php @@ -20,8 +20,38 @@ * */ +/** + * Public interface of ownCloud for apps to use. + * Request interface + * + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; +/** + * This interface provides an immutable object with with accessors to + * request variables and headers. + * + * Access request variables by method and name. + * + * Examples: + * + * $request->post['myvar']; // Only look for POST variables + * $request->myvar; or $request->{'myvar'}; or $request->{$myvar} + * Looks in the combined GET, POST and urlParams array. + * + * If you access e.g. ->post but the current HTTP request method + * is GET a \LogicException will be thrown. + * + * NOTE: + * - When accessing ->put a stream resource is returned and the accessor + * will return false on subsequent access to ->put or ->patch. + * - When accessing ->patch and the Content-Type is either application/json + * or application/x-www-form-urlencoded (most cases) it will act like ->get + * and ->post and return an array. Otherwise the raw data will be returned. + */ interface IRequest { @@ -86,11 +116,8 @@ interface IRequest { /** - * Returns the request body content. - * - * @param Boolean $asResource If true, a resource will be returned - * @return string|resource The request body content or a resource to read the body stream. - * @throws \LogicException + * Checks if the CSRF check was correct + * @return bool true if CSRF check passed */ - function getContent($asResource = false); + public function passesCSRFCheck(); } diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index f4045faefef..dcb00caf496 100644 --- a/lib/public/iservercontainer.php +++ b/lib/public/iservercontainer.php @@ -20,6 +20,14 @@ * */ +/** + * Public interface of ownCloud for apps to use. + * Server container interface + * + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; @@ -92,16 +100,48 @@ interface IServerContainer { function getUserSession(); /** + * Returns the navigation manager + * * @return \OCP\INavigationManager */ function getNavigationManager(); /** + * Returns the config manager + * * @return \OCP\IConfig */ function getConfig(); /** + * Returns the app config manager + * + * @return \OCP\IAppConfig + */ + function getAppConfig(); + + /** + * get an L10N instance + * @param $app string appid + * @return \OCP\IL10N + */ + function getL10N($app); + + /** + * Returns the URL generator + * + * @return \OCP\IURLGenerator + */ + function getURLGenerator(); + + /** + * Returns the Helper + * + * @return \OCP\IHelper + */ + function getHelper(); + + /** * Returns an ICache instance * * @return \OCP\ICache @@ -109,6 +149,13 @@ interface IServerContainer { function getCache(); /** + * Returns an \OCP\CacheFactory instance + * + * @return \OCP\ICacheFactory + */ + function getMemCacheFactory(); + + /** * Returns the current session * * @return \OCP\ISession @@ -116,10 +163,24 @@ interface IServerContainer { function getSession(); /** + * Returns the activity manager + * + * @return \OCP\Activity\IManager + */ + function getActivityManager(); + + /** * Returns the current session * * @return \OCP\IDBConnection */ function getDatabaseConnection(); + /** + * Returns an avatar manager, used for avatar functionality + * + * @return \OCP\IAvatarManager + */ + function getAvatarManager(); + } diff --git a/lib/public/isession.php b/lib/public/isession.php index 0a77b0c823b..20da712cda3 100644 --- a/lib/public/isession.php +++ b/lib/public/isession.php @@ -1,13 +1,35 @@ <?php /** - * Copyright (c) 2013 Thomas Tanghus (thomas@tanghus.net) + * ownCloud + * * @author Thomas Tanghus * @author Robin Appelman - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. + * @copyright 2013 Thomas Tanghus thomas@tanghus.net + * @copyright 2013 Robin Appelman icewind@owncloud.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Session interface + * */ +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; /** diff --git a/lib/public/itagmanager.php b/lib/public/itagmanager.php index 07e1d12fc0f..40487de42b4 100644 --- a/lib/public/itagmanager.php +++ b/lib/public/itagmanager.php @@ -1,24 +1,34 @@ <?php /** -* ownCloud -* -* @author Thomas Tanghus -* @copyright 2013 Thomas Tanghus <thomas@tanghus.net> -* -* 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/>. -* -*/ + * ownCloud + * + * @author Thomas Tanghus + * @copyright 2013 Thomas Tanghus <thomas@tanghus.net> + * + * 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/>. + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Tag manager interface + * + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP; /** * Factory class creating instances of \OCP\ITags @@ -30,9 +40,6 @@ * are entered in. If a user already has a tag 'family' for a type, and * tries to add a tag named 'Family' it will be silently ignored. */ - -namespace OCP; - interface ITagManager { /** diff --git a/lib/public/itags.php b/lib/public/itags.php index 5b1ebd189da..ea62fb38ecb 100644 --- a/lib/public/itags.php +++ b/lib/public/itags.php @@ -1,25 +1,33 @@ <?php /** -* ownCloud -* -* @author Thomas Tanghus -* @copyright 2013 Thomas Tanghus <thomas@tanghus.net> -* -* 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/>. -* -*/ + * ownCloud + * + * @author Thomas Tanghus + * @copyright 2013 Thomas Tanghus <thomas@tanghus.net> + * + * 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/>. + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Tags interface + * + */ +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; // FIXME: Where should I put this? Or should it be implemented as a Listener? diff --git a/lib/public/iurlgenerator.php b/lib/public/iurlgenerator.php new file mode 100644 index 00000000000..afdf1b6f299 --- /dev/null +++ b/lib/public/iurlgenerator.php @@ -0,0 +1,68 @@ +<?php +/** + * ownCloud + * + * @author Bart Visscher + * @copyright 2013 Bart Visscher bartv@thisnet.nl + * + * 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/>. + * + */ + +/** + * Public interface of ownCloud for apps to use. + * URL generator interface + * + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP; + +/** + * Class to generate URLs + */ +interface IURLGenerator { + /** + * Returns the URL for a route + * @param string $routeName the name of the route + * @param array $arguments an array with arguments which will be filled into the url + * @return string the url + */ + public function linkToRoute($routeName, $arguments = array()); + + /** + * Returns an URL for an image or file + * @param string $appName the name of the app + * @param string $file the name of the file + * @return string the url + */ + public function linkTo($appName, $file); + + /** + * Returns the link to an image, like linkTo but only with prepending img/ + * @param string $appName the name of the app + * @param string $file the name of the file + * @return string the url + */ + public function imagePath($appName, $file); + + + /** + * Makes an URL absolute + * @param string $url the url in the owncloud host + * @return string the absolute version of the url + */ + public function getAbsoluteURL($url); +} diff --git a/lib/public/iusersession.php b/lib/public/iusersession.php index 5dc1ecf71e6..131b326ab90 100644 --- a/lib/public/iusersession.php +++ b/lib/public/iusersession.php @@ -1,12 +1,33 @@ <?php /** - * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl> - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - * + * ownCloud + * + * @author Bart Visscher + * @copyright 2013 Bart Visscher bartv@thisnet.nl + * + * 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/>. + * */ +/** + * Public interface of ownCloud for apps to use. + * User session interface + * + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; /** @@ -22,7 +43,7 @@ interface IUserSession { public function login($user, $password); /** - * @brief Logs the user out including all the session data + * Logs the user out including all the session data * Logout, destroys session */ public function logout(); diff --git a/lib/public/json.php b/lib/public/json.php index 2186dd8ee49..cd5d233ef90 100644 --- a/lib/public/json.php +++ b/lib/public/json.php @@ -1,24 +1,24 @@ <?php /** -* ownCloud -* -* @author Frank Karlitschek -* @copyright 2012 Frank Karlitschek frank@owncloud.org -* -* 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/>. -* -*/ + * ownCloud + * + * @author Frank Karlitschek + * @copyright 2012 Frank Karlitschek frank@owncloud.org + * + * 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/>. + * + */ /** * Public interface of ownCloud for apps to use. @@ -35,7 +35,7 @@ namespace OCP; */ class JSON { /** - * @brief Encode and print $data in JSON format + * Encode and print $data in JSON format * @param array $data The data to use * @param string $setContentType the optional content type * @return string json formatted string. @@ -123,7 +123,7 @@ class JSON { } /** - * @brief set Content-Type header to jsonrequest + * Set Content-Type header to jsonrequest * @param array $type The contwnt type header * @return string json formatted string. */ @@ -167,6 +167,22 @@ class JSON { * @return string json formatted string if not admin user. */ public static function checkAdminUser() { - return(\OC_JSON::checkAdminUser()); + \OC_JSON::checkAdminUser(); + } + + /** + * Encode JSON + * @param array $data + */ + public static function encode($data) { + return(\OC_JSON::encode($data)); + } + + /** + * Check is a given user exists - send json error msg if not + * @param string $user + */ + public static function checkUserExists($user) { + \OC_JSON::checkUserExists($user); } } diff --git a/lib/public/response.php b/lib/public/response.php index de0c3f25347..24d3c81d628 100644 --- a/lib/public/response.php +++ b/lib/public/response.php @@ -1,24 +1,24 @@ <?php /** -* ownCloud -* -* @author Frank Karlitschek -* @copyright 2012 Frank Karlitschek frank@owncloud.org -* -* 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/>. -* -*/ + * ownCloud + * + * @author Frank Karlitschek + * @copyright 2012 Frank Karlitschek frank@owncloud.org + * + * 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/>. + * + */ /** * Public interface of ownCloud for apps to use. @@ -35,64 +35,73 @@ namespace OCP; */ class Response { /** - * @brief Enable response caching by sending correct HTTP headers - * @param int $cache_time time to cache the response - * >0 cache time in seconds - * 0 and <0 enable default browser caching - * null cache indefinitly - */ + * Enable response caching by sending correct HTTP headers + * @param int $cache_time time to cache the response + * >0 cache time in seconds + * 0 and <0 enable default browser caching + * null cache indefinitly + */ static public function enableCaching( $cache_time = null ) { \OC_Response::enableCaching( $cache_time ); } /** - * Checks and set Last-Modified header, when the request matches sends a - * 'not modified' response - * @param string $lastModified time when the reponse was last modified - */ + * Checks and set Last-Modified header, when the request matches sends a + * 'not modified' response + * @param string $lastModified time when the reponse was last modified + */ static public function setLastModifiedHeader( $lastModified ) { \OC_Response::setLastModifiedHeader( $lastModified ); } /** - * @brief disable browser caching - * @see enableCaching with cache_time = 0 - */ + * Sets the content disposition header (with possible workarounds) + * @param string $filename file name + * @param string $type disposition type, either 'attachment' or 'inline' + */ + static public function setContentDispositionHeader( $filename, $type = 'attachment' ) { + \OC_Response::setContentDispositionHeader( $filename, $type ); + } + + /** + * Disable browser caching + * @see enableCaching with cache_time = 0 + */ static public function disableCaching() { \OC_Response::disableCaching(); } /** - * Checks and set ETag header, when the request matches sends a - * 'not modified' response - * @param string $etag token to use for modification check - */ + * Checks and set ETag header, when the request matches sends a + * 'not modified' response + * @param string $etag token to use for modification check + */ static public function setETagHeader( $etag ) { \OC_Response::setETagHeader( $etag ); } /** - * @brief Send file as response, checking and setting caching headers - * @param string $filepath of file to send - */ + * Send file as response, checking and setting caching headers + * @param string $filepath of file to send + */ static public function sendFile( $filepath ) { \OC_Response::sendFile( $filepath ); } /** - * @brief Set response expire time - * @param string|\DateTime $expires date-time when the response expires - * string for DateInterval from now - * DateTime object when to expire response - */ + * Set response expire time + * @param string|\DateTime $expires date-time when the response expires + * string for DateInterval from now + * DateTime object when to expire response + */ static public function setExpiresHeader( $expires ) { \OC_Response::setExpiresHeader( $expires ); } /** - * @brief Send redirect response - * @param string $location to redirect to - */ + * Send redirect response + * @param string $location to redirect to + */ static public function redirect( $location ) { \OC_Response::redirect( $location ); } diff --git a/lib/public/share.php b/lib/public/share.php index 6c5783f1179..f832d04a70f 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -1,32 +1,41 @@ <?php /** -* ownCloud -* -* @author Michael Gapczynski -* @copyright 2012 Michael Gapczynski mtgap@owncloud.com -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -*/ + * ownCloud + * + * @author Michael Gapczynski + * @copyright 2012 Michael Gapczynski mtgap@owncloud.com + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * Public interface of ownCloud for apps to use. + * Share Class + * + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; /** -* This class provides the ability for apps to share their content between users. -* Apps must create a backend class that implements OCP\Share_Backend and register it with this class. -* -* It provides the following hooks: -* - post_shared -*/ + * This class provides the ability for apps to share their content between users. + * Apps must create a backend class that implements OCP\Share_Backend and register it with this class. + * + * It provides the following hooks: + * - post_shared + */ class Share { const SHARE_TYPE_USER = 0; @@ -37,19 +46,19 @@ class Share { const SHARE_TYPE_REMOTE = 6; /** CRUDS permissions (Create, Read, Update, Delete, Share) using a bitmask - * Construct permissions for share() and setPermissions with Or (|) e.g. - * Give user read and update permissions: PERMISSION_READ | PERMISSION_UPDATE - * - * Check if permission is granted with And (&) e.g. Check if delete is - * granted: if ($permissions & PERMISSION_DELETE) - * - * Remove permissions with And (&) and Not (~) e.g. Remove the update - * permission: $permissions &= ~PERMISSION_UPDATE - * - * Apps are required to handle permissions on their own, this class only - * stores and manages the permissions of shares - * @see lib/public/constants.php - */ + * Construct permissions for share() and setPermissions with Or (|) e.g. + * Give user read and update permissions: PERMISSION_READ | PERMISSION_UPDATE + * + * Check if permission is granted with And (&) e.g. Check if delete is + * granted: if ($permissions & PERMISSION_DELETE) + * + * Remove permissions with And (&) and Not (~) e.g. Remove the update + * permission: $permissions &= ~PERMISSION_UPDATE + * + * Apps are required to handle permissions on their own, this class only + * stores and manages the permissions of shares + * @see lib/public/constants.php + */ const FORMAT_NONE = -1; const FORMAT_STATUSES = -2; @@ -64,13 +73,13 @@ class Share { private static $isResharingAllowed; /** - * @brief 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 - */ + * 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 + */ public static function registerBackend($itemType, $class, $collectionOf = null, $supportedFileExtensions = null) { if (self::isEnabled()) { if (!isset(self::$backendTypes[$itemType])) { @@ -94,12 +103,11 @@ class Share { } /** - * @brief Check if the Share API is enabled - * @return Returns true if enabled or false - * - * The Share API is enabled by default if not configured - * - */ + * Check if the Share API is enabled + * @return Returns true if enabled or false + * + * The Share API is enabled by default if not configured + */ public static function isEnabled() { if (\OC_Appconfig::getValue('core', 'shareapi_enabled', 'yes') == 'yes') { return true; @@ -108,9 +116,10 @@ class Share { } /** - * @brief Prepare a path to be passed to DB as file_target - * @return string Prepared path - */ + * Prepare a path to be passed to DB as file_target + * @param string $path path + * @return string Prepared path + */ public static function prepFileTarget( $path ) { // Paths in DB are stored with leading slashes, so add one if necessary @@ -125,14 +134,14 @@ class Share { } /** - * @brief Find which users can access a shared item - * @param $path to the file - * @param $user owner of the file - * @param include owner to the list of users with access to the file - * @return array - * @note $path needs to be relative to user data dir, e.g. 'file.txt' - * not '/admin/data/file.txt' - */ + * Find which users can access a shared item + * @param $path to the file + * @param $user owner of the file + * @param include owner to the list of users with access to the file + * @return array + * @note $path needs to be relative to user data dir, e.g. 'file.txt' + * not '/admin/data/file.txt' + */ public static function getUsersSharingFile($path, $user, $includeOwner = false) { $shares = array(); @@ -155,13 +164,13 @@ class Share { while ($source !== -1) { - // Fetch all shares of this file path from DB + // Fetch all shares with another user $query = \OC_DB::prepare( 'SELECT `share_with` FROM `*PREFIX*share` WHERE - `item_source` = ? AND `share_type` = ?' + `item_source` = ? AND `share_type` = ? AND `item_type` IN (\'file\', \'folder\')' ); $result = $query->execute(array($source, self::SHARE_TYPE_USER)); @@ -180,7 +189,7 @@ class Share { FROM `*PREFIX*share` WHERE - `item_source` = ? AND `share_type` = ?' + `item_source` = ? AND `share_type` = ? AND `item_type` IN (\'file\', \'folder\')' ); $result = $query->execute(array($source, self::SHARE_TYPE_GROUP)); @@ -201,7 +210,7 @@ class Share { FROM `*PREFIX*share` WHERE - `item_source` = ? AND `share_type` = ?' + `item_source` = ? AND `share_type` = ? AND `item_type` IN (\'file\', \'folder\')' ); $result = $query->execute(array($source, self::SHARE_TYPE_LINK)); @@ -232,12 +241,14 @@ class Share { } /** - * @brief 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 int Number of items to return (optional) Returns all by default - * @return Return depends on format - */ + * 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 + */ public static function getItemsSharedWith($itemType, $format = self::FORMAT_NONE, $parameters = null, $limit = -1, $includeCollections = false) { return self::getItems($itemType, null, self::$shareTypeUserAndGroups, \OC_User::getUser(), null, $format, @@ -245,12 +256,14 @@ class Share { } /** - * @brief Get the item of item type shared with the current user - * @param string Item type - * @param string Item target - * @param int Format (optional) Format type must be defined by the backend - * @return Return depends on format - */ + * Get the item of item type shared with the current user + * @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 + */ public static function getItemSharedWith($itemType, $itemTarget, $format = self::FORMAT_NONE, $parameters = null, $includeCollections = false) { return self::getItems($itemType, $itemTarget, self::$shareTypeUserAndGroups, \OC_User::getUser(), null, $format, @@ -258,12 +271,63 @@ class Share { } /** - * @brief 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 - * @return Return depends on format - */ + * Get the item of item type shared with a given user by source + * @param string $itemType + * @param string $itemSource + * @param string $user User user to whom the item was shared + * @return array Return list of items with file_target, permissions and expiration + */ + public static function getItemSharedWithUser($itemType, $itemSource, $user) { + + $shares = array(); + + // first check if there is a db entry for the specific user + $query = \OC_DB::prepare( + 'SELECT `file_target`, `permissions`, `expiration` + FROM + `*PREFIX*share` + WHERE + `item_source` = ? AND `item_type` = ? AND `share_with` = ?' + ); + + $result = \OC_DB::executeAudited($query, array($itemSource, $itemType, $user)); + + while ($row = $result->fetchRow()) { + $shares[] = $row; + } + + //if didn't found a result than let's look for a group share. + if(empty($shares)) { + $groups = \OC_Group::getUserGroups($user); + + $query = \OC_DB::prepare( + 'SELECT `file_target`, `permissions`, `expiration` + FROM + `*PREFIX*share` + WHERE + `item_source` = ? AND `item_type` = ? AND `share_with` in (?)' + ); + + $result = \OC_DB::executeAudited($query, array($itemSource, $itemType, implode(',', $groups))); + + while ($row = $result->fetchRow()) { + $shares[] = $row; + } + } + + return $shares; + + } + + /** + * 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 + */ public static function getItemSharedWithBySource($itemType, $itemSource, $format = self::FORMAT_NONE, $parameters = null, $includeCollections = false) { return self::getItems($itemType, $itemSource, self::$shareTypeUserAndGroups, \OC_User::getUser(), null, $format, @@ -271,44 +335,46 @@ class Share { } /** - * @brief 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 - */ + * 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 + */ public static function getItemSharedWithByLink($itemType, $itemSource, $uidOwner) { return self::getItems($itemType, $itemSource, self::SHARE_TYPE_LINK, null, $uidOwner, self::FORMAT_NONE, null, 1); } /** - * @brief Get the item shared by a token - * @param string token - * @return Item + * 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 */ - public static function getShareByToken($token) { + public static function getShareByToken($token, $checkPasswordProtection = true) { $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share` WHERE `token` = ?', 1); $result = $query->execute(array($token)); if (\OC_DB::isError($result)) { \OC_Log::write('OCP\Share', \OC_DB::getErrorMessage($result) . ', token=' . $token, \OC_Log::ERROR); } $row = $result->fetchRow(); + if ($row === false) { + return false; + } + if (is_array($row) and self::expireItem($row)) { + return false; + } - if (!empty($row['expiration'])) { - $now = new \DateTime(); - $expirationDate = new \DateTime($row['expiration'], new \DateTimeZone('UTC')); - if ($now > $expirationDate) { - self::delete($row['id']); - return false; - } + // password protected shares need to be authenticated + if ($checkPasswordProtection && !\OCP\Share::checkPasswordProtectedShare($row)) { + return false; } return $row; } /** - * @brief resolves reshares down to the last real share + * resolves reshares down to the last real share * @param $linkItem * @return $fileOwner */ @@ -331,12 +397,14 @@ class Share { /** - * @brief 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 int Number of items to return (optional) Returns all by default - * @return Return depends on format - */ + * 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 + */ public static function getItemsShared($itemType, $format = self::FORMAT_NONE, $parameters = null, $limit = -1, $includeCollections = false) { return self::getItems($itemType, null, null, null, \OC_User::getUser(), $format, @@ -344,12 +412,14 @@ class Share { } /** - * @brief 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 - * @return Return depends on format - */ + * 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 + */ public static function getItemShared($itemType, $itemSource, $format = self::FORMAT_NONE, $parameters = null, $includeCollections = false) { return self::getItems($itemType, $itemSource, null, null, \OC_User::getUser(), $format, @@ -357,16 +427,18 @@ class Share { } /** - * Get all users an item is shared with - * @param string Item type - * @param string Item source - * @param string Owner - * @param bool Include collections - * @return Return array of users - */ - public static function getUsersItemShared($itemType, $itemSource, $uidOwner, $includeCollections = false) { + * 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 + */ + public static function getUsersItemShared($itemType, $itemSource, $uidOwner, $includeCollections = false, $checkExpireDate = true) { + $users = array(); - $items = self::getItems($itemType, $itemSource, null, null, $uidOwner, self::FORMAT_NONE, null, -1, $includeCollections); + $items = self::getItems($itemType, $itemSource, null, null, $uidOwner, self::FORMAT_NONE, null, -1, $includeCollections, false, $checkExpireDate); if ($items) { foreach ($items as $item) { if ((int)$item['share_type'] === self::SHARE_TYPE_USER) { @@ -380,33 +452,45 @@ class Share { } /** - * @brief Share an item with a user, group, or via 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 - * @param int CRUDS 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) { + * Share an item with a user, group, or via private link + * @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 + * @param null $itemSourceName + * @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) { $uidOwner = \OC_User::getUser(); $sharingPolicy = \OC_Appconfig::getValue('core', 'shareapi_share_policy', 'global'); + + if (is_null($itemSourceName)) { + $itemSourceName = $itemSource; + } + // Verify share type and sharing conditions are met if ($shareType === self::SHARE_TYPE_USER) { if ($shareWith == $uidOwner) { - $message = 'Sharing '.$itemSource.' failed, because the user '.$shareWith.' is the item owner'; + $message = 'Sharing '.$itemSourceName.' failed, because the user '.$shareWith.' is the item owner'; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } if (!\OC_User::userExists($shareWith)) { - $message = 'Sharing '.$itemSource.' failed, because the user '.$shareWith.' does not exist'; + $message = 'Sharing '.$itemSourceName.' failed, because the user '.$shareWith.' does not exist'; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } if ($sharingPolicy == 'groups_only') { $inGroup = array_intersect(\OC_Group::getUserGroups($uidOwner), \OC_Group::getUserGroups($shareWith)); if (empty($inGroup)) { - $message = 'Sharing '.$itemSource.' failed, because the user ' + $message = 'Sharing '.$itemSourceName.' failed, because the user ' .$shareWith.' is not a member of any groups that '.$uidOwner.' is a member of'; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); @@ -419,19 +503,19 @@ class Share { // owner and is not a user share, this use case is for increasing // permissions for a specific user if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) { - $message = 'Sharing '.$itemSource.' failed, because this item is already shared with '.$shareWith; + $message = 'Sharing '.$itemSourceName.' failed, because this item is already shared with '.$shareWith; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } } } else if ($shareType === self::SHARE_TYPE_GROUP) { if (!\OC_Group::groupExists($shareWith)) { - $message = 'Sharing '.$itemSource.' failed, because the group '.$shareWith.' does not exist'; + $message = 'Sharing '.$itemSourceName.' failed, because the group '.$shareWith.' does not exist'; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } if ($sharingPolicy == 'groups_only' && !\OC_Group::inGroup($uidOwner, $shareWith)) { - $message = 'Sharing '.$itemSource.' failed, because ' + $message = 'Sharing '.$itemSourceName.' failed, because ' .$uidOwner.' is not a member of the group '.$shareWith; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); @@ -444,7 +528,7 @@ class Share { // owner and is not a group share, this use case is for increasing // permissions for a specific user if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) { - $message = 'Sharing '.$itemSource.' failed, because this item is already shared with '.$shareWith; + $message = 'Sharing '.$itemSourceName.' failed, because this item is already shared with '.$shareWith; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } @@ -486,14 +570,14 @@ class Share { $token = \OC_Util::generateRandomBytes(self::TOKEN_LENGTH); } $result = self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, - null, $token); + null, $token, $itemSourceName); if ($result) { return $token; } else { return false; } } - $message = 'Sharing '.$itemSource.' failed, because sharing with links is not allowed'; + $message = 'Sharing '.$itemSourceName.' failed, because sharing with links is not allowed'; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); return false; @@ -552,79 +636,67 @@ class Share { // return false; // } else { // Put the item into the database - return self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions); + return self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, null, null, $itemSourceName); // } } /** - * @brief 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 - */ + * 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 + */ public static function unshare($itemType, $itemSource, $shareType, $shareWith) { if ($item = self::getItems($itemType, $itemSource, $shareType, $shareWith, \OC_User::getUser(), self::FORMAT_NONE, null, 1)) { - // Pass all the vars we have for now, they may be useful - \OC_Hook::emit('OCP\Share', 'pre_unshare', array( - 'itemType' => $itemType, - 'itemSource' => $itemSource, - 'fileSource' => $item['file_source'], - 'shareType' => $shareType, - 'shareWith' => $shareWith, - 'itemParent' => $item['parent'], - )); - self::delete($item['id']); - \OC_Hook::emit('OCP\Share', 'post_unshare', array( - 'itemType' => $itemType, - 'itemSource' => $itemSource, - 'shareType' => $shareType, - 'shareWith' => $shareWith, - 'itemParent' => $item['parent'], - )); + self::unshareItem($item); return true; } return false; } /** - * @brief 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 - */ + * 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 + */ public static function unshareAll($itemType, $itemSource) { - if ($shares = self::getItemShared($itemType, $itemSource)) { + // Get all of the owners of shares of this item. + $query = \OC_DB::prepare( 'SELECT `uid_owner` from `*PREFIX*share` WHERE `item_type`=? AND `item_source`=?' ); + $result = $query->execute(array($itemType, $itemSource)); + $shares = array(); + // Add each owner's shares to the array of all shares for this item. + while ($row = $result->fetchRow()) { + $shares = array_merge($shares, self::getItems($itemType, $itemSource, null, null, $row['uid_owner'])); + } + if (!empty($shares)) { // Pass all the vars we have for now, they may be useful - \OC_Hook::emit('OCP\Share', 'pre_unshareAll', array( + $hookParams = array( 'itemType' => $itemType, 'itemSource' => $itemSource, - 'shares' => $shares - )); + 'shares' => $shares, + ); + \OC_Hook::emit('OCP\Share', 'pre_unshareAll', $hookParams); foreach ($shares as $share) { - self::delete($share['id']); + self::unshareItem($share); } - \OC_Hook::emit('OCP\Share', 'post_unshareAll', array( - 'itemType' => $itemType, - 'itemSource' => $itemSource, - 'shares' => $shares - )); + \OC_Hook::emit('OCP\Share', 'post_unshareAll', $hookParams); return true; } return false; } /** - * @brief 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 - * - * Unsharing from self is not allowed for items inside collections - * - */ + * 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 + * + * Unsharing from self is not allowed for items inside collections + */ public static function unshareFromSelf($itemType, $itemTarget) { if ($item = self::getItemSharedWith($itemType, $itemTarget)) { if ((int)$item['share_type'] === self::SHARE_TYPE_GROUP) { @@ -653,16 +725,37 @@ class Share { } 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 + */ + public static function setSendMailStatus($itemType, $itemSource, $shareType, $status) { + $status = $status ? 1 : 0; + + $query = \OC_DB::prepare( + 'UPDATE `*PREFIX*share` + SET `mail_send` = ? + WHERE `item_type` = ? AND `item_source` = ? AND `share_type` = ?'); + + $result = $query->execute(array($status, $itemType, $itemSource, $shareType)); + + if($result === false) { + \OC_Log::write('OCP\Share', 'Couldn\'t set send mail status', \OC_Log::ERROR); + } + } /** - * @brief 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 - */ + * 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 + */ public static function setPermissions($itemType, $itemSource, $shareType, $shareWith, $permissions) { if ($item = self::getItems($itemType, $itemSource, $shareType, $shareWith, \OC_User::getUser(), self::FORMAT_NONE, null, 1, false)) { @@ -738,6 +831,13 @@ class Share { throw new \Exception($message); } + /** + * Set expiration date for a share + * @param string $itemType + * @param string $itemSource + * @param string $date expiration date + * @return Share_Backend + */ public static function setExpirationDate($itemType, $itemSource, $date) { if ($items = self::getItems($itemType, $itemSource, null, null, \OC_User::getUser(), self::FORMAT_NONE, null, -1, false)) { @@ -746,11 +846,12 @@ class Share { $date = null; } else { $date = new \DateTime($date); - $date = date('Y-m-d H:i', $date->format('U') - $date->getOffset()); } $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `expiration` = ? WHERE `id` = ?'); + $query->bindValue(1, $date, 'datetime'); foreach ($items as $item) { - $query->execute(array($date, $item['id'])); + $query->bindValue(2, (int) $item['id']); + $query->execute(); } return true; } @@ -759,10 +860,50 @@ class Share { } /** - * @brief Get the backend class for the specified item type - * @param string $itemType - * @return Share_Backend - */ + * 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. + */ + protected static function expireItem(array $item) { + if (!empty($item['expiration'])) { + $now = new \DateTime(); + $expires = new \DateTime($item['expiration']); + if ($now > $expires) { + self::unshareItem($item); + return true; + } + } + return false; + } + + /** + * Unshares a share given a share data array + * @param array $item Share data (usually database row) + * @return null + */ + protected static function unshareItem(array $item) { + // Pass all the vars we have for now, they may be useful + $hookParams = array( + 'itemType' => $item['item_type'], + 'itemSource' => $item['item_source'], + 'shareType' => $item['share_type'], + 'shareWith' => $item['share_with'], + 'itemParent' => $item['parent'], + 'uidOwner' => $item['uid_owner'], + ); + + \OC_Hook::emit('OCP\Share', 'pre_unshare', $hookParams + array( + 'fileSource' => $item['file_source'], + )); + self::delete($item['id']); + \OC_Hook::emit('OCP\Share', 'post_unshare', $hookParams); + } + + /** + * Get the backend class for the specified item type + * @param string $itemType + * @return Share_Backend + */ public static function getBackend($itemType) { if (isset(self::$backends[$itemType])) { return self::$backends[$itemType]; @@ -788,12 +929,11 @@ class Share { } /** - * @brief Check if resharing is allowed - * @return Returns true if allowed or false - * - * Resharing is allowed by default if not configured - * - */ + * Check if resharing is allowed + * @return Returns true if allowed or false + * + * Resharing is allowed by default if not configured + */ private static function isResharingAllowed() { if (!isset(self::$isResharingAllowed)) { if (\OC_Appconfig::getValue('core', 'shareapi_allow_resharing', 'yes') == 'yes') { @@ -806,10 +946,10 @@ class Share { } /** - * @brief Get a list of collection item types for the specified item type - * @param string Item type - * @return array - */ + * Get a list of collection item types for the specified item type + * @param string Item type + * @return array + */ private static function getCollectionItemTypes($itemType) { $collectionTypes = array($itemType); foreach (self::$backendTypes as $type => $backend) { @@ -830,24 +970,26 @@ class Share { } /** - * @brief 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) - * @return mixed - * - * See public functions getItem(s)... for parameter usage - * - */ + * 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 + * @return mixed + * + * See public functions getItem(s)... for parameter usage + * + */ private static function getItems($itemType, $item = null, $shareType = null, $shareWith = null, $uidOwner = null, $format = self::FORMAT_NONE, $parameters = null, $limit = -1, - $includeCollections = false, $itemShareWithBySource = false) { + $includeCollections = false, $itemShareWithBySource = false, $checkExpireDate = true) { if (!self::isEnabled()) { if ($limit == 1 || (isset($uidOwner) && isset($item))) { return false; @@ -889,6 +1031,10 @@ class Share { $queryArgs = array($itemType); } } + if (\OC_Appconfig::getValue('core', 'shareapi_allow_links', 'yes') !== 'yes') { + $where .= ' AND `share_type` != ?'; + $queryArgs[] = self::SHARE_TYPE_LINK; + } if (isset($shareType)) { // Include all user and group items if ($shareType == self::$shareTypeUserAndGroups && isset($shareWith)) { @@ -982,20 +1128,20 @@ class Share { // TODO Optimize selects if ($format == self::FORMAT_STATUSES) { if ($itemType == 'file' || $itemType == 'folder') { - $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`,' - .' `share_type`, `file_source`, `path`, `expiration`, `storage`'; + $select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `*PREFIX*share`.`parent`,' + .' `share_type`, `file_source`, `path`, `expiration`, `storage`, `share_with`, `mail_send`, `uid_owner`'; } else { - $select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `expiration`'; + $select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `share_with`, `expiration`, `mail_send`, `uid_owner`'; } } else { if (isset($uidOwner)) { if ($itemType == 'file' || $itemType == 'folder') { - $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`,' + $select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `*PREFIX*share`.`parent`,' .' `share_type`, `share_with`, `file_source`, `path`, `permissions`, `stime`,' - .' `expiration`, `token`, `storage`'; + .' `expiration`, `token`, `storage`, `mail_send`, `uid_owner`'; } else { $select = '`id`, `item_type`, `item_source`, `parent`, `share_type`, `share_with`, `permissions`,' - .' `stime`, `file_source`, `expiration`, `token`'; + .' `stime`, `file_source`, `expiration`, `token`, `mail_send`, `uid_owner`'; } } else { if ($fileDependent) { @@ -1003,14 +1149,14 @@ class Share { && $format == \OC_Share_Backend_File::FORMAT_GET_FOLDER_CONTENTS || $format == \OC_Share_Backend_File::FORMAT_FILE_APP_ROOT ) { - $select = '`*PREFIX*share`.`id`, `item_type`, `*PREFIX*share`.`parent`, `uid_owner`, ' + $select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `*PREFIX*share`.`parent`, `uid_owner`, ' .'`share_type`, `share_with`, `file_source`, `path`, `file_target`, ' .'`permissions`, `expiration`, `storage`, `*PREFIX*filecache`.`parent` as `file_parent`, ' - .'`name`, `mtime`, `mimetype`, `mimepart`, `size`, `encrypted`, `etag`'; + .'`name`, `mtime`, `mimetype`, `mimepart`, `size`, `encrypted`, `etag`, `mail_send`'; } else { $select = '`*PREFIX*share`.`id`, `item_type`, `item_source`, `item_target`, `*PREFIX*share`.`parent`, `share_type`, `share_with`, `uid_owner`, - `file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`, `token`, `storage`'; + `file_source`, `path`, `file_target`, `permissions`, `stime`, `expiration`, `token`, `storage`, `mail_send`'; } } else { $select = '*'; @@ -1109,10 +1255,8 @@ class Share { } } } - if (isset($row['expiration'])) { - $time = new \DateTime(); - if ($row['expiration'] < date('Y-m-d H:i', $time->format('U') - $time->getOffset())) { - self::delete($row['id']); + if($checkExpireDate) { + if (self::expireItem($row)) { continue; } } @@ -1235,30 +1379,35 @@ class Share { } /** - * @brief 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 int CRUDS permissions - * @param bool|array Parent folder target (optional) - * @return bool Returns true on success or false on failure - */ + * 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 + */ private static function put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, - $permissions, $parentFolder = null, $token = null) { + $permissions, $parentFolder = null, $token = null, $itemSourceName = null) { $backend = self::getBackend($itemType); + // Check if this is a reshare if ($checkReshare = self::getItemSharedWithBySource($itemType, $itemSource, self::FORMAT_NONE, null, true)) { + // Check if attempting to share back to owner if ($checkReshare['uid_owner'] == $shareWith && $shareType == self::SHARE_TYPE_USER) { - $message = 'Sharing '.$itemSource.' failed, because the user '.$shareWith.' is the original sharer'; + $message = 'Sharing '.$itemSourceName.' failed, because the user '.$shareWith.' is the original sharer'; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } // Check if share permissions is granted if (self::isResharingAllowed() && (int)$checkReshare['permissions'] & PERMISSION_SHARE) { if (~(int)$checkReshare['permissions'] & $permissions) { - $message = 'Sharing '.$itemSource + $message = 'Sharing '.$itemSourceName .' failed, because the permissions exceed permissions granted to '.$uidOwner; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); @@ -1272,7 +1421,7 @@ class Share { $filePath = $checkReshare['file_target']; } } else { - $message = 'Sharing '.$itemSource.' failed, because resharing is not allowed'; + $message = 'Sharing '.$itemSourceName.' failed, because resharing is not allowed'; \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR); throw new \Exception($message); } @@ -1400,6 +1549,7 @@ class Share { 'id' => $parent, 'token' => $token )); + if ($parentFolder === true) { // Return parent folders to preserve file target paths for potential children return $parentFolders; @@ -1471,15 +1621,16 @@ class Share { } /** - * @brief 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 The suggested target originating from a reshare (optional) - * @param int The id of the parent group share (optional) - * @return string Item target - */ + * 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) + * @return string Item target + */ private static function generateTarget($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $suggestedTarget = null, $groupParent = null) { $backend = self::getBackend($itemType); @@ -1587,11 +1738,11 @@ class Share { } /** - * @brief 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) - */ + * 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) + */ private static function delete($parent, $excludeParent = false, $uidOwner = null) { $ids = array($parent); $parents = array($parent); @@ -1647,9 +1798,25 @@ class Share { } /** - * Hook Listeners - */ + * Delete all shares with type SHARE_TYPE_LINK + */ + public static function removeAllLinkShares() { + // Delete any link shares + $query = \OC_DB::prepare('SELECT `id` FROM `*PREFIX*share` WHERE `share_type` = ?'); + $result = $query->execute(array(self::SHARE_TYPE_LINK)); + while ($item = $result->fetchRow()) { + self::delete($item['id']); + } + } + + /** + * Hook Listeners + */ + /** + * Function that is called after a user is deleted. Cleans up the shares of that user. + * @param array arguments + */ public static function post_deleteUser($arguments) { // Delete any items shared with the deleted user $query = \OC_DB::prepare('DELETE FROM `*PREFIX*share`' @@ -1663,6 +1830,11 @@ class Share { } } + /** + * Function that is called after a user is added to a group. + * TODO what does it do? + * @param array arguments + */ public static function post_addToGroup($arguments) { // Find the group shares and check if the user needs a unique target $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share` WHERE `share_type` = ? AND `share_with` = ?'); @@ -1693,6 +1865,10 @@ class Share { } } + /** + * Function that is called after a user is removed from a group. Shares are cleaned up. + * @param array arguments + */ public static function post_removeFromGroup($arguments) { // TODO Don't call if user deleted? $sql = 'SELECT `id`, `share_type` FROM `*PREFIX*share`' @@ -1709,6 +1885,10 @@ class Share { } } + /** + * Function that is called after a group is removed. Cleans up the shares to that group. + * @param array arguments + */ public static function post_deleteGroup($arguments) { $sql = 'SELECT `id` FROM `*PREFIX*share` WHERE `share_type` = ? AND `share_with` = ?'; $result = \OC_DB::executeAudited($sql, array(self::SHARE_TYPE_GROUP, $arguments['gid'])); @@ -1717,90 +1897,117 @@ class Share { } } + /** + * In case a password protected link is not yet authenticated this function will return false + * + * @param array $linkItem + * @return bool + */ + public static function checkPasswordProtectedShare(array $linkItem) { + if (!isset($linkItem['share_with'])) { + return true; + } + if (!isset($linkItem['share_type'])) { + return true; + } + if (!isset($linkItem['id'])) { + return true; + } + + if ($linkItem['share_type'] != \OCP\Share::SHARE_TYPE_LINK) { + return true; + } + + if ( \OC::$session->exists('public_link_authenticated') + && \OC::$session->get('public_link_authenticated') === $linkItem['id'] ) { + return true; + } + + return false; + } } /** -* Interface that apps must implement to share content. -*/ + * Interface that apps must implement to share content. + */ interface Share_Backend { /** - * @brief Get the source of the item to be stored in the database - * @param string Item source - * @param string Owner of the item - * @return mixed|array|false Source - * - * Return an array if the item is file dependent, the array needs two keys: 'item' and 'file' - * Return false if the item does not exist for the user - * - * The formatItems() function will translate the source returned back into the item - */ + * Get the source of the item to be stored in the database + * @param string Item source + * @param string Owner of the item + * @return mixed|array|false Source + * + * Return an array if the item is file dependent, the array needs two keys: 'item' and 'file' + * Return false if the item does not exist for the user + * + * The formatItems() function will translate the source returned back into the item + */ public function isValidSource($itemSource, $uidOwner); /** - * @brief Get a unique name of the item for the specified user - * @param string Item source - * @param string|false User the item is being shared with - * @param array|null List of similar item names already existing as shared items - * @return string Target name - * - * This function needs to verify that the user does not already have an item with this name. - * If it does generate a new name e.g. name_# - */ + * Get a unique name of the item for the specified user + * @param string Item source + * @param string|false User the item is being shared with + * @param array|null List of similar item names already existing as shared items + * @return string Target name + * + * This function needs to verify that the user does not already have an item with this name. + * If it does generate a new name e.g. name_# + */ public function generateTarget($itemSource, $shareWith, $exclude = null); /** - * @brief Converts the shared item sources back into the item in the specified format - * @param array Shared items - * @param int Format - * @return ? - * - * The items array is a 3-dimensional array with the item_source as the - * first key and the share id as the second key to an array with the share - * info. - * - * The key/value pairs included in the share info depend on the function originally called: - * If called by getItem(s)Shared: id, item_type, item, item_source, - * share_type, share_with, permissions, stime, file_source - * - * If called by getItem(s)SharedWith: id, item_type, item, item_source, - * item_target, share_type, share_with, permissions, stime, file_source, - * file_target - * - * This function allows the backend to control the output of shared items with custom formats. - * It is only called through calls to the public getItem(s)Shared(With) functions. - */ + * Converts the shared item sources back into the item in the specified format + * @param array Shared items + * @param int Format + * @return TODO + * + * The items array is a 3-dimensional array with the item_source as the + * first key and the share id as the second key to an array with the share + * info. + * + * The key/value pairs included in the share info depend on the function originally called: + * If called by getItem(s)Shared: id, item_type, item, item_source, + * share_type, share_with, permissions, stime, file_source + * + * If called by getItem(s)SharedWith: id, item_type, item, item_source, + * item_target, share_type, share_with, permissions, stime, file_source, + * file_target + * + * This function allows the backend to control the output of shared items with custom formats. + * It is only called through calls to the public getItem(s)Shared(With) functions. + */ public function formatItems($items, $format, $parameters = null); } /** -* Interface for share backends that share content that is dependent on files. -* Extends the Share_Backend interface. -*/ + * Interface for share backends that share content that is dependent on files. + * Extends the Share_Backend interface. + */ interface Share_Backend_File_Dependent extends Share_Backend { /** - * @brief Get the file path of the item - * @param - * @param - * @return - */ + * Get the file path of the item + * @param string Item source + * @param string User that is the owner of shared item + */ public function getFilePath($itemSource, $uidOwner); } /** -* Interface for collections of of items implemented by another share backend. -* Extends the Share_Backend interface. -*/ + * Interface for collections of of items implemented by another share backend. + * Extends the Share_Backend interface. + */ interface Share_Backend_Collection extends Share_Backend { /** - * @brief Get the sources of the children of the item - * @param string Item source - * @return array Returns an array of children each inside an array with the keys: source, target, and file_path if applicable - */ + * Get the sources of the children of the item + * @param string Item source + * @return array Returns an array of children each inside an array with the keys: source, target, and file_path if applicable + */ public function getChildren($itemSource); } diff --git a/lib/public/template.php b/lib/public/template.php index 3b1a4ed4906..320b7c6393f 100644 --- a/lib/public/template.php +++ b/lib/public/template.php @@ -1,24 +1,24 @@ <?php /** -* ownCloud -* -* @author Frank Karlitschek -* @copyright 2012 Frank Karlitschek frank@owncloud.org -* -* 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/>. -* -*/ + * ownCloud + * + * @author Frank Karlitschek + * @copyright 2012 Frank Karlitschek frank@owncloud.org + * + * 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/>. + * + */ /** * Public interface of ownCloud for apps to use. @@ -32,12 +32,12 @@ namespace OCP; /** - * @brief make OC_Helper::imagePath available as a simple function - * @param $app app - * @param $image image - * @returns link to the image + * Make OC_Helper::imagePath available as a simple function + * @param string app + * @param string image + * @return link to the image * - * For further information have a look at OC_Helper::imagePath + * @see OC_Helper::imagePath */ function image_path( $app, $image ) { return(\image_path( $app, $image )); @@ -45,40 +45,39 @@ function image_path( $app, $image ) { /** - * @brief make OC_Helper::mimetypeIcon available as a simple function - * Returns the path to the image of this file type. - * @param $mimetype mimetype - * @returns link to the image + * Make OC_Helper::mimetypeIcon available as a simple function + * @param string mimetype + * @return path to the image of this file type. */ function mimetype_icon( $mimetype ) { return(\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 + * Make preview_icon available as a simple function + * @param string path of file + * @return path to the preview of the image */ function preview_icon( $path ) { return(\preview_icon( $path )); } /** - * @brief make publicpreview_icon available as a simple function + * Make publicpreview_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 of file + * @param string token + * @return link to the preview */ function publicPreview_icon ( $path, $token ) { return(\publicPreview_icon( $path, $token )); } /** - * @brief make OC_Helper::humanFileSize available as a simple function - * Makes 2048 to 2 kB. - * @param $bytes size in bytes - * @returns size as string + * Make OC_Helper::humanFileSize available as a simple function + * Example: 2048 to 2 kB. + * @param int size in bytes + * @return size as string */ function human_file_size( $bytes ) { return(\human_file_size( $bytes )); @@ -86,20 +85,21 @@ function human_file_size( $bytes ) { /** - * @brief Return the relative date in relation to today. Returns something like "last hour" or "two month ago" - * @param $timestamp unix timestamp - * @returns human readable interpretation of the timestamp + * Return the relative date in relation to today. Returns something like "last hour" or "two month ago" + * @param int unix timestamp + * @param boolean date only + * @return human readable interpretation of the timestamp */ -function relative_modified_date($timestamp) { - return(\relative_modified_date($timestamp)); +function relative_modified_date( $timestamp, $dateOnly = false ) { + return(\relative_modified_date($timestamp, null, $dateOnly)); } /** - * @brief DEPRECATED Return a human readable outout for a file size. + * Return a human readable outout for a file size. * @deprecated human_file_size() instead - * @param $byte size of a file in byte - * @returns human readable interpretation of a file size + * @param integer size of a file in byte + * @return human readable interpretation of a file size */ function simple_file_size($bytes) { return(\human_file_size($bytes)); @@ -107,11 +107,11 @@ function simple_file_size($bytes) { /** - * @brief Generate html code for an options block. + * Generate html code for an options block. * @param $options the options * @param $selected which one is selected? - * @param $params the parameters - * @returns html options + * @param array the parameters + * @return html options */ function html_select_options($options, $selected, $params=array()) { return(\html_select_options($options, $selected, $params)); diff --git a/lib/public/user.php b/lib/public/user.php index 576a64d7048..acc0e3b737b 100644 --- a/lib/public/user.php +++ b/lib/public/user.php @@ -1,28 +1,28 @@ <?php /** -* ownCloud -* -* @author Frank Karlitschek -* @copyright 2012 Frank Karlitschek frank@owncloud.org -* -* 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/>. -* -*/ + * ownCloud + * + * @author Frank Karlitschek + * @copyright 2012 Frank Karlitschek frank@owncloud.org + * + * 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/>. + * + */ /** * Public interface of ownCloud for apps to use. - * User Class. + * User Class * */ @@ -36,7 +36,7 @@ namespace OCP; */ class User { /** - * @brief get the user id of the user currently logged in. + * Get the user id of the user currently logged in. * @return string uid or false */ public static function getUser() { @@ -44,45 +44,46 @@ class User { } /** - * @brief Get a list of all users - * @returns array with all uids - * - * Get a list of all users. + * Get a list of all users + * @param string search pattern + * @param int limit + * @param int offset + * @return array with all uids */ - public static function getUsers($search = '', $limit = null, $offset = null) { - return \OC_User::getUsers($search, $limit, $offset); + public static function getUsers( $search = '', $limit = null, $offset = null ) { + return \OC_User::getUsers( $search, $limit, $offset ); } /** - * @brief get the user display name of the user currently logged in. + * Get the user display name of the user currently logged in. + * @param string user id or null for current user * @return string display name */ - public static function getDisplayName($user=null) { - return \OC_User::getDisplayName($user); + public static function getDisplayName( $user = null ) { + return \OC_User::getDisplayName( $user ); } /** - * @brief Get a list of all display names - * @returns array with all display names (value) and the correspondig uids (key) - * * Get a list of all display names and user ids. + * @param string search pattern + * @param int limit + * @param int offset + * @return array with all display names (value) and the correspondig uids (key) */ - public static function getDisplayNames($search = '', $limit = null, $offset = null) { - return \OC_User::getDisplayNames($search, $limit, $offset); + public static function getDisplayNames( $search = '', $limit = null, $offset = null ) { + return \OC_User::getDisplayNames( $search, $limit, $offset ); } /** - * @brief Check if the user is logged in - * @returns true/false - * - * Checks if the user is logged in + * Check if the user is logged in + * @return boolean */ public static function isLoggedIn() { return \OC_User::isLoggedIn(); } /** - * @brief check if a user exists + * Check if a user exists * @param string $uid the username * @param string $excludingBackend (default none) * @return boolean @@ -91,7 +92,7 @@ class User { return \OC_User::userExists( $uid, $excludingBackend ); } /** - * @brief Loggs the user out including all the session data + * Logs the user out including all the session data * Logout, destroys session */ public static function logout() { @@ -99,10 +100,10 @@ class User { } /** - * @brief Check if the password is correct - * @param $uid The username - * @param $password The password - * @returns mixed username on success, false otherwise + * Check if the password is correct + * @param string The username + * @param string The password + * @return mixed username on success, false otherwise * * Check if the password is correct without logging in the user */ diff --git a/lib/public/userinterface.php b/lib/public/userinterface.php index 53d9faf7a5e..1f6c2f7292b 100644 --- a/lib/public/userinterface.php +++ b/lib/public/userinterface.php @@ -1,31 +1,33 @@ <?php /** -* ownCloud -* -* @author Arthur Schiwon -* @copyright 2012 Arthur Schiwon blizzz@owncloud.org -* -* 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/>. -* -*/ + * ownCloud + * + * @author Arthur Schiwon + * @copyright 2012 Arthur Schiwon blizzz@owncloud.org + * + * 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/>. + * + */ /** * Public interface of ownCloud for apps to use. - * User Class. + * User Interface * */ +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes namespace OCP; interface UserInterface extends \OC_User_Interface {} diff --git a/lib/public/util.php b/lib/public/util.php index b33f07b55e6..d8497e29cfc 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -1,24 +1,24 @@ <?php /** -* ownCloud -* -* @author Frank Karlitschek -* @copyright 2012 Frank Karlitschek frank@owncloud.org -* -* 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/>. -* -*/ + * ownCloud + * + * @author Frank Karlitschek + * @copyright 2012 Frank Karlitschek frank@owncloud.org + * + * 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/>. + * + */ /** * Public interface of ownCloud for apps to use. @@ -42,7 +42,7 @@ class Util { const FATAL=4; /** - * @brief get the current installed version of ownCloud + * get the current installed version of ownCloud * @return array */ public static function getVersion() { @@ -50,7 +50,7 @@ class Util { } /** - * @brief send an email + * send an email * @param string $toaddress * @param string $toname * @param string $subject @@ -58,6 +58,10 @@ class Util { * @param string $fromaddress * @param string $fromname * @param bool $html + * @param string $altbody + * @param string $ccaddress + * @param string $ccname + * @param string $bcc */ public static function sendMail( $toaddress, $toname, $subject, $mailtext, $fromaddress, $fromname, $html = 0, $altbody = '', $ccaddress = '', $ccname = '', $bcc = '') { @@ -67,7 +71,7 @@ class Util { } /** - * @brief write a message in the log + * write a message in the log * @param string $app * @param string $message * @param int $level @@ -78,8 +82,45 @@ class Util { } /** - * @brief get l10n object - * @param string $app + * write exception into the log. Include the stack trace + * if DEBUG mode is enabled + * @param string $app app name + * @param Exception $ex exception to log + */ + public static function logException( $app, \Exception $ex ) { + $class = get_class($ex); + if ($class !== 'Exception') { + $message = $class . ': '; + } + $message .= $ex->getMessage(); + if ($ex->getCode()) { + $message .= ' [' . $ex->getCode() . ']'; + } + \OCP\Util::writeLog($app, 'Exception: ' . $message, \OCP\Util::FATAL); + if (defined('DEBUG') and DEBUG) { + // also log stack trace + $stack = explode("\n", $ex->getTraceAsString()); + // first element is empty + array_shift($stack); + foreach ($stack as $s) { + \OCP\Util::writeLog($app, 'Exception: ' . $s, \OCP\Util::FATAL); + } + + // include cause + while (method_exists($ex, 'getPrevious') && $ex = $ex->getPrevious()) { + $message .= ' - Caused by:' . ' '; + $message .= $ex->getMessage(); + if ($ex->getCode()) { + $message .= '[' . $ex->getCode() . '] '; + } + \OCP\Util::writeLog($app, 'Exception: ' . $message, \OCP\Util::FATAL); + } + } + } + + /** + * get l10n object + * @param string $application * @return OC_L10N */ public static function getL10N( $application ) { @@ -87,24 +128,25 @@ class Util { } /** - * @brief add a css file - * @param string $url + * add a css file + * @param string $application + * @param string $file */ public static function addStyle( $application, $file = null ) { \OC_Util::addStyle( $application, $file ); } /** - * @brief add a javascript file + * add a javascript file * @param string $application - * @param string $file + * @param string $file */ public static function addScript( $application, $file = null ) { \OC_Util::addScript( $application, $file ); } /** - * @brief Add a custom element to the header + * Add a custom element to the header * @param string $tag tag name of the element * @param array $attributes array of attributes for the element * @param string $text the text content for the element @@ -114,7 +156,7 @@ class Util { } /** - * @brief formats a timestamp in the "right" way + * formats a timestamp in the "right" way * @param int $timestamp $timestamp * @param bool $dateOnly option to omit time from the result */ @@ -123,93 +165,78 @@ class Util { } /** - * @brief check if some encrypted files are stored + * check if some encrypted files are stored * @return bool */ public static function encryptedFiles() { return \OC_Util::encryptedFiles(); } - + /** - * @brief Creates an absolute url + * Creates an absolute url to the given app and file. * @param string $app app * @param string $file file * @param array $args array with param=>value, will be appended to the returned url * The value of $args will be urlencoded - * @returns string the url - * - * Returns a absolute url to the given app and file. + * @return string the url */ public static function linkToAbsolute( $app, $file, $args = array() ) { return(\OC_Helper::linkToAbsolute( $app, $file, $args )); } /** - * @brief Creates an absolute url for remote use + * Creates an absolute url for remote use. * @param string $service id - * @returns string the url - * - * Returns a absolute url to the given app and file. + * @return string the url */ public static function linkToRemote( $service ) { return(\OC_Helper::linkToRemote( $service )); } /** - * @brief Creates an absolute url for public use + * Creates an absolute url for public use * @param string $service id - * @returns string the url - * - * Returns a absolute url to the given app and file. + * @return string the url */ public static function linkToPublic($service) { return \OC_Helper::linkToPublic($service); } /** - * @brief Creates an url using a defined route + * Creates an url using a defined route * @param $route * @param array $parameters * @return * @internal param array $args with param=>value, will be appended to the returned url - * @returns the url - * - * Returns a url to the given app and file. + * @return the url */ public static function linkToRoute( $route, $parameters = array() ) { return \OC_Helper::linkToRoute($route, $parameters); } /** - * @brief Creates an url + * Creates an url to the given app and file * @param string $app app * @param string $file file * @param array $args array with param=>value, will be appended to the returned url * The value of $args will be urlencoded - * @returns string the url - * - * Returns a url to the given app and file. + * @return string the url */ public static function linkTo( $app, $file, $args = array() ) { return(\OC_Helper::linkTo( $app, $file, $args )); } /** - * @brief Returns the server host - * @returns string the server host - * - * Returns the server host, even if the website uses one or more - * reverse proxies + * Returns the server host, even if the website uses one or more reverse proxy + * @return string the server host */ public static function getServerHost() { return(\OC_Request::serverHost()); } /** - * @brief returns the server hostname - * @returns string the server hostname - * * Returns the server host name without an eventual port number + * @return string the server hostname */ public static function getServerHostName() { $host_name = self::getServerHost(); @@ -222,17 +249,22 @@ class Util { } /** - * @brief Returns the default email address + * Returns the default email address * @param string $user_part the user part of the address - * @returns string the default email address + * @return string the default email address * * Assembles a default email address (using the server hostname * and the given user part, and returns it * Example: when given lostpassword-noreply as $user_part param, * and is currently accessed via http(s)://example.com/, * it would return 'lostpassword-noreply@example.com' + * + * If the configuration value 'mail_from_address' is set in + * config.php, this value will override the $user_part that + * is passed to this function */ public static function getDefaultEmailAddress($user_part) { + $user_part = \OC_Config::getValue('mail_from_address', $user_part); $host_name = self::getServerHostName(); $host_name = \OC_Config::getValue('mail_domain', $host_name); $defaultEmailAddress = $user_part.'@'.$host_name; @@ -246,66 +278,54 @@ class Util { } /** - * @brief Returns the server protocol - * @returns string the server protocol - * * Returns the server protocol. It respects reverse proxy servers and load balancers + * @return string the server protocol */ public static function getServerProtocol() { return(\OC_Request::serverProtocol()); } /** - * @brief Returns the request uri - * @returns the request uri + * Returns the request uri, even if the website uses one or more reverse proxies * - * Returns the request uri, even if the website uses one or more - * reverse proxies + * @return the request uri */ public static function getRequestUri() { return(\OC_Request::requestUri()); } /** - * @brief Returns the script name - * @returns the script name + * Returns the script name, even if the website uses one or more reverse proxies * - * Returns the script name, even if the website uses one or more - * reverse proxies + * @return the script name */ public static function getScriptName() { return(\OC_Request::scriptName()); } /** - * @brief Creates path to an image + * Creates path to an image * @param string $app app * @param string $image image name - * @returns string the url - * - * Returns the path to the image. + * @return string the url */ public static function imagePath( $app, $image ) { return(\OC_Helper::imagePath( $app, $image )); } /** - * @brief Make a human file size + * Make a human file size (2048 to 2 kB) * @param int $bytes file size in bytes - * @returns string a human readable file size - * - * Makes 2048 to 2 kB. + * @return string a human readable file size */ public static function humanFileSize( $bytes ) { return(\OC_Helper::humanFileSize( $bytes )); } /** - * @brief Make a computer file size + * Make a computer file size (2 kB to 2048) * @param string $str file size in a fancy format - * @returns int a file size in bytes - * - * Makes 2kB to 2048. + * @return int a file size in bytes * * Inspired by: http://www.php.net/manual/en/function.filesize.php#92418 */ @@ -314,12 +334,12 @@ class Util { } /** - * @brief connects a function to a hook + * connects a function to a hook * @param string $signalclass class name of emitter * @param string $signalname name of signal * @param string $slotclass class name of slot * @param string $slotname name of slot - * @returns bool + * @return bool * * This function makes it very easy to connect to use hooks. * @@ -330,13 +350,11 @@ class Util { } /** - * @brief emitts a signal + * 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 string $params defautl: array() array with additional data - * @returns bool true if slots exists or false if not - * - * Emits a signal. To get data from the slot use references! + * @return bool true if slots exists or false if not * * TODO: write example */ @@ -361,7 +379,7 @@ class Util { } /** - * @brief Used to sanitize HTML + * Used to sanitize HTML * * 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. @@ -372,78 +390,75 @@ class Util { public static function sanitizeHTML( $value ) { return(\OC_Util::sanitizeHTML($value)); } - + /** - * @brief Public function to encode url parameters + * Public function to encode url parameters * * This function is used to encode path to file before output. * Encoding is done according to RFC 3986 with one exception: - * Character '/' is preserved as is. + * Character '/' is preserved as is. * * @param string $component part of URI to encode - * @return string + * @return string */ public static function encodePath($component) { return(\OC_Util::encodePath($component)); } /** - * @brief Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is. - * - * @param array $input The array to work on - * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default) - * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 - * @return array - * - * - */ + * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is. + * + * @param array $input The array to work on + * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default) + * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 + * @return array + */ public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') { return(\OC_Helper::mb_array_change_key_case($input, $case, $encoding)); } /** - * @brief replaces a copy of string delimited by the start and (optionally) length parameters with the string given in replacement. - * - * @param string $input The input string. .Opposite to the PHP build-in function does not accept an array. - * @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 - * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 - * @return string - * - */ + * replaces a copy of string delimited by the start and (optionally) length parameters with the string given in replacement. + * + * @param string $string The input string. Opposite to the PHP build-in function does not accept an array. + * @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 + * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 + * @return string + */ public static function mb_substr_replace($string, $replacement, $start, $length = null, $encoding = 'UTF-8') { return(\OC_Helper::mb_substr_replace($string, $replacement, $start, $length, $encoding)); } /** - * @brief Replace all occurrences of the search string with the replacement string - * - * @param string $search The value being searched for, otherwise known as the needle. String. - * @param string $replace The replacement string. - * @param string $subject The string or array being searched and replaced on, otherwise known as the haystack. - * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 - * @param int $count If passed, this will be set to the number of replacements performed. - * @return string - * - */ + * Replace all occurrences of the search string with the replacement string + * + * @param string $search The value being searched for, otherwise known as the needle. String. + * @param string $replace The replacement string. + * @param string $subject The string or array being searched and replaced on, otherwise known as the haystack. + * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 + * @param int $count If passed, this will be set to the number of replacements performed. + * @return string + */ public static function mb_str_replace($search, $replace, $subject, $encoding = 'UTF-8', &$count = null) { return(\OC_Helper::mb_str_replace($search, $replace, $subject, $encoding, $count)); } /** - * @brief performs a search in a nested array - * @param array $haystack the array to be searched - * @param string $needle the search string - * @param int $index optional, only search this key name - * @return mixed the key of the matching field, otherwise false - */ + * performs a search in a nested array + * + * @param array $haystack the array to be searched + * @param string $needle the search string + * @param int $index optional, only search this key name + * @return mixed the key of the matching field, otherwise false + */ public static function recursiveArraySearch($haystack, $needle, $index = null) { return(\OC_Helper::recursiveArraySearch($haystack, $needle, $index)); } /** - * @brief calculates the maximum upload size respecting system settings, free space and user quota + * calculates the maximum upload size respecting system settings, free space and user quota * * @param $dir the current folder where the user currently operates * @return number of bytes representing @@ -451,4 +466,23 @@ class Util { public static function maxUploadFilesize($dir) { return \OC_Helper::maxUploadFilesize($dir); } + + /** + * Calculate free space left within user quota + * + * @param $dir the current folder where the user currently operates + * @return number of bytes representing + */ + public static function freeSpace($dir) { + return \OC_Helper::freeSpace($dir); + } + + /** + * Calculate PHP upload limit + * + * @return number of bytes representing + */ + public static function uploadLimit() { + return \OC_Helper::uploadLimit(); + } } |