config.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Frank Karlitschek
  6. * @copyright 2012 Frank Karlitschek frank@owncloud.org
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * Public interface of ownCloud for apps to use.
  24. * Config Class
  25. *
  26. */
  27. /**
  28. * @brief use OCP namespace for all classes that are considered public.
  29. *
  30. * Classes that use this namespace are for use by apps, and not for use by internal
  31. * OC classes
  32. */
  33. namespace OCP;
  34. /**
  35. * This class provides functions to read and write configuration data.
  36. * configuration can be on a system, application or user level
  37. */
  38. class Config {
  39. /**
  40. * Gets a value from config.php
  41. * @param string $key key
  42. * @param string $default = null default value
  43. * @return string the value or $default
  44. *
  45. * This function gets the value from config.php. If it does not exist,
  46. * $default will be returned.
  47. */
  48. public static function getSystemValue( $key, $default = null ) {
  49. return \OC_Config::getValue( $key, $default );
  50. }
  51. /**
  52. * Sets a value
  53. * @param string $key key
  54. * @param string $value value
  55. * @return bool
  56. *
  57. * This function sets the value and writes the config.php. If the file can
  58. * not be written, false will be returned.
  59. */
  60. public static function setSystemValue( $key, $value ) {
  61. try {
  62. \OC_Config::setValue( $key, $value );
  63. } catch (Exception $e) {
  64. return false;
  65. }
  66. return true;
  67. }
  68. /**
  69. * Gets the config value
  70. * @param string $app app
  71. * @param string $key key
  72. * @param string $default = null, default value if the key does not exist
  73. * @return string the value or $default
  74. *
  75. * This function gets a value from the appconfig table. If the key does
  76. * not exist the default value will be returned
  77. */
  78. public static function getAppValue( $app, $key, $default = null ) {
  79. return \OC_Appconfig::getValue( $app, $key, $default );
  80. }
  81. /**
  82. * Sets a value in the appconfig
  83. * @param string $app app
  84. * @param string $key key
  85. * @param string $value value
  86. * @return string true/false
  87. *
  88. * Sets a value. If the key did not exist before it will be created.
  89. */
  90. public static function setAppValue( $app, $key, $value ) {
  91. try {
  92. \OC_Appconfig::setValue( $app, $key, $value );
  93. } catch (Exception $e) {
  94. return false;
  95. }
  96. return true;
  97. }
  98. /**
  99. * Gets the preference
  100. * @param string $user user
  101. * @param string $app app
  102. * @param string $key key
  103. * @param string $default = null, default value if the key does not exist
  104. * @return string the value or $default
  105. *
  106. * This function gets a value from the preferences table. If the key does
  107. * not exist the default value will be returned
  108. */
  109. public static function getUserValue( $user, $app, $key, $default = null ) {
  110. return \OC_Preferences::getValue( $user, $app, $key, $default );
  111. }
  112. /**
  113. * Sets a value in the preferences
  114. * @param string $user user
  115. * @param string $app app
  116. * @param string $key key
  117. * @param string $value value
  118. * @return bool
  119. *
  120. * Adds a value to the preferences. If the key did not exist before, it
  121. * will be added automagically.
  122. */
  123. public static function setUserValue( $user, $app, $key, $value ) {
  124. try {
  125. \OC_Preferences::setValue( $user, $app, $key, $value );
  126. } catch (Exception $e) {
  127. return false;
  128. }
  129. return true;
  130. }
  131. }