API.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bernhard Posselt <dev@bernhard-posselt.com>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Robin Appelman <robin@icewind.nl>
  9. * @author Robin McCorkell <robin@mccorkell.me.uk>
  10. * @author Thomas Müller <thomas.mueller@tmit.eu>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. namespace OC\AppFramework\Core;
  28. use OCP\AppFramework\IApi;
  29. /**
  30. * This is used to wrap the owncloud static api calls into an object to make the
  31. * code better abstractable for use in the dependency injection container
  32. *
  33. * Should you find yourself in need for more methods, simply inherit from this
  34. * class and add your methods
  35. * @deprecated
  36. */
  37. class API implements IApi{
  38. private $appName;
  39. /**
  40. * constructor
  41. * @param string $appName the name of your application
  42. */
  43. public function __construct($appName){
  44. $this->appName = $appName;
  45. }
  46. /**
  47. * Gets the userid of the current user
  48. * @return string the user id of the current user
  49. * @deprecated Use \OC::$server->getUserSession()->getUser()->getUID()
  50. */
  51. public function getUserId(){
  52. return \OCP\User::getUser();
  53. }
  54. /**
  55. * Adds a new javascript file
  56. * @deprecated include javascript and css in template files
  57. * @param string $scriptName the name of the javascript in js/ without the suffix
  58. * @param string $appName the name of the app, defaults to the current one
  59. */
  60. public function addScript($scriptName, $appName=null){
  61. if($appName === null){
  62. $appName = $this->appName;
  63. }
  64. \OCP\Util::addScript($appName, $scriptName);
  65. }
  66. /**
  67. * Adds a new css file
  68. * @deprecated include javascript and css in template files
  69. * @param string $styleName the name of the css file in css/without the suffix
  70. * @param string $appName the name of the app, defaults to the current one
  71. */
  72. public function addStyle($styleName, $appName=null){
  73. if($appName === null){
  74. $appName = $this->appName;
  75. }
  76. \OCP\Util::addStyle($appName, $styleName);
  77. }
  78. /**
  79. * @deprecated include javascript and css in template files
  80. * shorthand for addScript for files in the 3rdparty directory
  81. * @param string $name the name of the file without the suffix
  82. */
  83. public function add3rdPartyScript($name){
  84. \OCP\Util::addScript($this->appName . '/3rdparty', $name);
  85. }
  86. /**
  87. * @deprecated include javascript and css in template files
  88. * shorthand for addStyle for files in the 3rdparty directory
  89. * @param string $name the name of the file without the suffix
  90. */
  91. public function add3rdPartyStyle($name){
  92. \OCP\Util::addStyle($this->appName . '/3rdparty', $name);
  93. }
  94. /**
  95. * @deprecated communication between apps should happen over built in
  96. * callbacks or interfaces (check the contacts and calendar managers)
  97. * Checks if an app is enabled
  98. * also use \OC::$server->getAppManager()->isEnabledForUser($appName)
  99. * @param string $appName the name of an app
  100. * @return bool true if app is enabled
  101. */
  102. public function isAppEnabled($appName){
  103. return \OCP\App::isEnabled($appName);
  104. }
  105. /**
  106. * used to return and open a new event source
  107. * @return \OCP\IEventSource a new open EventSource class
  108. * @deprecated Use \OC::$server->createEventSource();
  109. */
  110. public function openEventSource(){
  111. return \OC::$server->createEventSource();
  112. }
  113. /**
  114. * @deprecated register hooks directly for class that build in hook interfaces
  115. * connects a function to a hook
  116. * @param string $signalClass class name of emitter
  117. * @param string $signalName name of signal
  118. * @param string $slotClass class name of slot
  119. * @param string $slotName name of slot, in another word, this is the
  120. * name of the method that will be called when registered
  121. * signal is emitted.
  122. * @return bool always true
  123. */
  124. public function connectHook($signalClass, $signalName, $slotClass, $slotName) {
  125. return \OCP\Util::connectHook($signalClass, $signalName, $slotClass, $slotName);
  126. }
  127. /**
  128. * @deprecated implement the emitter interface instead
  129. * Emits a signal. To get data from the slot use references!
  130. * @param string $signalClass class name of emitter
  131. * @param string $signalName name of signal
  132. * @param array $params default: array() array with additional data
  133. * @return bool true if slots exists or false if not
  134. */
  135. public function emitHook($signalClass, $signalName, $params = array()) {
  136. return \OCP\Util::emitHook($signalClass, $signalName, $params);
  137. }
  138. /**
  139. * clear hooks
  140. * @deprecated clear hooks directly for class that build in hook interfaces
  141. * @param string $signalClass
  142. * @param string $signalName
  143. */
  144. public function clearHook($signalClass=false, $signalName=false) {
  145. if ($signalClass) {
  146. \OC_Hook::clear($signalClass, $signalName);
  147. }
  148. }
  149. /**
  150. * Tells ownCloud to include a template in the admin overview
  151. * @param string $mainPath the path to the main php file without the php
  152. * suffix, relative to your apps directory! not the template directory
  153. * @param string $appName the name of the app, defaults to the current one
  154. */
  155. public function registerAdmin($mainPath, $appName=null) {
  156. if($appName === null){
  157. $appName = $this->appName;
  158. }
  159. \OCP\App::registerAdmin($appName, $mainPath);
  160. }
  161. }