apignusocialconfig.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Dump of configuration variables
  6. *
  7. * PHP version 5
  8. *
  9. * LICENCE: This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category API
  23. * @package GNUsocial
  24. * @author Evan Prodromou <evan@status.net>
  25. * @author Zach Copley <zach@status.net>
  26. * @copyright 2009 StatusNet, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  28. * @link http://www.gnu.org/software/social/
  29. */
  30. if (!defined('GNUSOCIAL')) { exit(1); }
  31. /**
  32. * Gives a full dump of configuration variables for this instance
  33. * of GNU social, minus variables that may be security-sensitive (like
  34. * passwords).
  35. * URL: https://example.com/api/gnusocial/config.(xml|json)
  36. * Formats: xml, json
  37. *
  38. * @category API
  39. * @package GNUsocial
  40. * @author Evan Prodromou <evan@status.net>
  41. * @author Zach Copley <zach@status.net>
  42. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  43. * @link http://www.gnu.org/software/social/
  44. */
  45. class ApiGNUsocialConfigAction extends ApiAction
  46. {
  47. var $keys = array(
  48. 'site' => array('name', 'server', 'theme', 'path', 'logo', 'fancy', 'language',
  49. 'email', 'broughtby', 'broughtbyurl', 'timezone', 'closed',
  50. 'inviteonly', 'private', 'textlimit', 'ssl', 'sslserver'),
  51. 'license' => array('type', 'owner', 'url', 'title', 'image'),
  52. 'nickname' => array('featured'),
  53. 'profile' => array('biolimit'),
  54. 'group' => array('desclimit'),
  55. 'notice' => array('contentlimit'),
  56. 'throttle' => array('enabled', 'count', 'timespan'),
  57. 'xmpp' => array('enabled', 'server', 'port', 'user'),
  58. 'integration' => array('source'),
  59. 'attachments' => array('uploads', 'file_quota'),
  60. 'url' => array('maxurllength', 'maxnoticelength'),
  61. );
  62. protected function handle()
  63. {
  64. parent::handle();
  65. switch ($this->format) {
  66. case 'xml':
  67. $this->initDocument('xml');
  68. $this->elementStart('config');
  69. // XXX: check that all sections and settings are legal XML elements
  70. foreach ($this->keys as $section => $settings) {
  71. $this->elementStart($section);
  72. foreach ($settings as $setting) {
  73. $value = $this->setting($section, $setting);
  74. if (is_array($value)) {
  75. $value = implode(',', $value);
  76. } else if ($value === false || $value == '0') {
  77. $value = 'false';
  78. } else if ($value === true || $value == '1') {
  79. $value = 'true';
  80. }
  81. // return theme logo if there's no site specific one
  82. if (empty($value)) {
  83. if ($section == 'site' && $setting == 'logo') {
  84. $value = Theme::path('logo.png');
  85. }
  86. }
  87. $this->element($setting, null, $value);
  88. }
  89. $this->elementEnd($section);
  90. }
  91. $this->elementEnd('config');
  92. $this->endDocument('xml');
  93. break;
  94. case 'json':
  95. $result = array();
  96. foreach ($this->keys as $section => $settings) {
  97. $result[$section] = array();
  98. foreach ($settings as $setting) {
  99. $result[$section][$setting]
  100. = $this->setting($section, $setting);
  101. }
  102. }
  103. $this->initDocument('json');
  104. $this->showJsonObjects($result);
  105. $this->endDocument('json');
  106. break;
  107. default:
  108. // TRANS: Client error displayed when coming across a non-supported API method.
  109. $this->clientError(_('API method not found.'), 404);
  110. }
  111. }
  112. function setting($section, $key) {
  113. $result = common_config($section, $key);
  114. if ($key == 'file_quota') {
  115. // hack: adjust for the live upload limit
  116. if (common_config($section, 'uploads')) {
  117. $max = ImageFile::maxFileSizeInt();
  118. } else {
  119. $max = 0;
  120. }
  121. return min($result, $max);
  122. }
  123. return $result;
  124. }
  125. /**
  126. * Return true if read only.
  127. *
  128. * MAY override
  129. *
  130. * @param array $args other arguments
  131. *
  132. * @return boolean is read only action?
  133. */
  134. function isReadOnly($args)
  135. {
  136. return true;
  137. }
  138. }