siteprofile.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * A site profile is a set of default settings for a particular style of
  6. * StatusNet site: public, private, community, etc.
  7. *
  8. * PHP version 5
  9. *
  10. * LICENCE: This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. * @category Installation
  24. * @package StatusNet
  25. * @author Zach Copley <zach@status.net>
  26. * @copyright 2011 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://status.net/
  29. */
  30. if (!defined('GNUSOCIAL')) {
  31. exit(1);
  32. }
  33. /**
  34. * Helper class for getting the settings for a particular site profile
  35. */
  36. class SiteProfile
  37. {
  38. /**
  39. * Returns the config settings for a site profile by name
  40. *
  41. * @param string $name name of a site profile
  42. * @return array config settings
  43. */
  44. static public function getSettings($name)
  45. {
  46. $sprofileClass = ucfirst($name) . "Site";
  47. if (class_exists($sprofileClass)) {
  48. return call_user_func(array($sprofileClass, 'getSettings'));
  49. } else {
  50. common_log(
  51. LOG_ERR,
  52. "Unknown site profile '{$name}' specified in config file.",
  53. __FILE__
  54. );
  55. return array();
  56. }
  57. }
  58. }
  59. /**
  60. * Site profile settings contain the list of the default settings (and
  61. * possibly other information for a particular flavor of StatusNet
  62. * installation). These will overwrite base defaults in $config global.
  63. *
  64. * @category Installation
  65. * @package StatusNet
  66. * @author Zach Copley <zach@status.net>
  67. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  68. * @link http://status.net/
  69. */
  70. abstract class SiteProfileSettings
  71. {
  72. static function getSettings()
  73. {
  74. throw new MethodNotImplementedException(__METHOD__);
  75. }
  76. static function corePlugins() {
  77. return common_config('plugins', 'core');
  78. }
  79. static function defaultPlugins() {
  80. return common_config('plugins', 'default');
  81. }
  82. }
  83. /**
  84. * Settings for a 'public' site
  85. */
  86. class PublicSite extends SiteProfileSettings
  87. {
  88. /**
  89. * Get the settings for this site profile
  90. *
  91. * @return type array an array of settings
  92. */
  93. static function getSettings() {
  94. global $config;
  95. return array(
  96. // We only want to change these values, not replace entire 'site' array
  97. 'site' => array_merge(
  98. $config['site'], array(
  99. 'inviteonly' => false,
  100. 'private' => false,
  101. 'closed' => false
  102. )
  103. ),
  104. 'plugins' => array(
  105. 'core' => self::corePlugins(),
  106. 'default' => array_merge(self::defaultPlugins(), array(
  107. 'RegisterThrottle' => array(),
  108. ))
  109. ),
  110. 'discovery' => array('cors' => true) // Allow Cross-Origin Resource Sharing for service discovery (host-meta, XRD, etc.)
  111. );
  112. }
  113. }
  114. /**
  115. * Settings for a 'private' site
  116. *
  117. * // XXX Too business oriented?
  118. */
  119. class PrivateSite extends SiteProfileSettings
  120. {
  121. /**
  122. * Get the settings for this site profile
  123. *
  124. * @return type array an array of settings
  125. */
  126. static function getSettings() {
  127. global $config;
  128. return array(
  129. // We only want to change these values, not replace entire 'site' array
  130. 'site' => array_merge(
  131. $config['site'], array(
  132. 'inviteonly' => true,
  133. 'private' => true,
  134. )
  135. ),
  136. 'plugins' => array(
  137. 'core' => self::corePlugins(),
  138. 'default' => array_merge(self::defaultPlugins(), array(
  139. 'ExtendedProfile' => array(),
  140. 'EmailRegistration' => array(),
  141. 'MobileProfile' => array(),
  142. )),
  143. 'disable-OStatus' => 1,
  144. 'disable-WebFinger' => 1,
  145. ),
  146. 'public' => array('localonly' => true),
  147. 'profile' => array('delete' => 'true'),
  148. 'license' => array('type' => 'private'),
  149. 'attachments' => array(
  150. // Only allow uploads of pictures and MS Office files
  151. 'supported' => array(
  152. 'image/png',
  153. 'image/jpeg',
  154. 'image/gif',
  155. 'image/svg+xml',
  156. 'application/pdf',
  157. 'application/msword',
  158. 'application/vnd.ms-office',
  159. 'application/vnd.ms-excel',
  160. 'application/vnd.ms-powerpoint',
  161. 'application/ogg'
  162. )
  163. ),
  164. 'discovery' => array('cors' => false) // Allow Cross-Origin Resource Sharing for service discovery (host-meta, XRD, etc.)
  165. );
  166. }
  167. }
  168. /**
  169. * Settings for a 'community' site
  170. */
  171. class CommunitySite extends SiteProfileSettings
  172. {
  173. /**
  174. * Get the settings for this site profile
  175. *
  176. * @return type array an array of settings
  177. */
  178. static function getSettings() {
  179. global $config;
  180. return array(
  181. // We only want to change these values, not replace entire 'site' array
  182. 'site' => array_merge(
  183. $config['site'], array(
  184. 'private' => false,
  185. 'inviteonly' => true,
  186. 'closed' => false
  187. )
  188. ),
  189. 'plugins' => array(
  190. 'core' => self::corePlugins(),
  191. 'default' => array_merge(self::defaultPlugins(), array(
  192. ))
  193. ),
  194. 'public' => array('localonly' => true),
  195. 'discovery' => array('cors' => true) // Allow Cross-Origin Resource Sharing for service discovery (host-meta, XRD, etc.)
  196. );
  197. }
  198. }
  199. /**
  200. * Settings for a 'singleuser' site
  201. */
  202. class SingleuserSite extends SiteProfileSettings
  203. {
  204. /**
  205. * Get the settings for this site profile
  206. *
  207. * @return type array an array of settings
  208. */
  209. static function getSettings() {
  210. global $config;
  211. return array(
  212. 'singleuser' => array('enabled' => true),
  213. // We only want to change these values, not replace entire 'site' array
  214. 'site' => array_merge(
  215. $config['site'], array(
  216. 'private' => false,
  217. 'closed' => true,
  218. 'localonly' => true,
  219. )
  220. ),
  221. 'plugins' => array(
  222. 'core' => self::corePlugins(),
  223. 'default' => array_merge(self::defaultPlugins(), array(
  224. 'MobileProfile' => array(),
  225. )),
  226. 'disable-Directory' => 1,
  227. ),
  228. 'public' => array('localonly' => true),
  229. 'discovery' => array('cors' => true) // Allow Cross-Origin Resource Sharing for service discovery (host-meta, XRD, etc.)
  230. );
  231. }
  232. }