siteprofile.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. 'ExtendedProfile' => array(),
  108. 'RegisterThrottle' => array(),
  109. ))
  110. ),
  111. 'discovery' => array('cors' => true) // Allow Cross-Origin Resource Sharing for service discovery (host-meta, XRD, etc.)
  112. );
  113. }
  114. }
  115. /**
  116. * Settings for a 'private' site
  117. *
  118. * // XXX Too business oriented?
  119. */
  120. class PrivateSite extends SiteProfileSettings
  121. {
  122. /**
  123. * Get the settings for this site profile
  124. *
  125. * @return type array an array of settings
  126. */
  127. static function getSettings() {
  128. global $config;
  129. return array(
  130. // We only want to change these values, not replace entire 'site' array
  131. 'site' => array_merge(
  132. $config['site'], array(
  133. 'inviteonly' => true,
  134. 'private' => true,
  135. )
  136. ),
  137. 'plugins' => array(
  138. 'core' => self::corePlugins(),
  139. 'default' => array_merge(self::defaultPlugins(), array(
  140. 'ExtendedProfile' => array(),
  141. 'EmailRegistration' => array(),
  142. 'MobileProfile' => array(),
  143. )),
  144. 'disable-OStatus' => 1,
  145. 'disable-WebFinger' => 1,
  146. ),
  147. 'public' => array('localonly' => true),
  148. 'profile' => array('delete' => 'true'),
  149. 'license' => array('type' => 'private'),
  150. 'attachments' => array(
  151. // Only allow uploads of pictures and MS Office files
  152. 'supported' => array(
  153. 'image/png',
  154. 'image/jpeg',
  155. 'image/gif',
  156. 'image/svg+xml',
  157. 'application/pdf',
  158. 'application/msword',
  159. 'application/vnd.ms-office',
  160. 'application/vnd.ms-excel',
  161. 'application/vnd.ms-powerpoint',
  162. 'application/ogg'
  163. )
  164. ),
  165. 'discovery' => array('cors' => false) // Allow Cross-Origin Resource Sharing for service discovery (host-meta, XRD, etc.)
  166. );
  167. }
  168. }
  169. /**
  170. * Settings for a 'community' site
  171. */
  172. class CommunitySite extends SiteProfileSettings
  173. {
  174. /**
  175. * Get the settings for this site profile
  176. *
  177. * @return type array an array of settings
  178. */
  179. static function getSettings() {
  180. global $config;
  181. return array(
  182. // We only want to change these values, not replace entire 'site' array
  183. 'site' => array_merge(
  184. $config['site'], array(
  185. 'private' => false,
  186. 'inviteonly' => true,
  187. 'closed' => false
  188. )
  189. ),
  190. 'plugins' => array(
  191. 'core' => self::corePlugins(),
  192. 'default' => array_merge(self::defaultPlugins(), array(
  193. ))
  194. ),
  195. 'public' => array('localonly' => true),
  196. 'discovery' => array('cors' => true) // Allow Cross-Origin Resource Sharing for service discovery (host-meta, XRD, etc.)
  197. );
  198. }
  199. }
  200. /**
  201. * Settings for a 'singleuser' site
  202. */
  203. class SingleuserSite extends SiteProfileSettings
  204. {
  205. /**
  206. * Get the settings for this site profile
  207. *
  208. * @return type array an array of settings
  209. */
  210. static function getSettings() {
  211. global $config;
  212. return array(
  213. 'singleuser' => array('enabled' => true),
  214. // We only want to change these values, not replace entire 'site' array
  215. 'site' => array_merge(
  216. $config['site'], array(
  217. 'private' => false,
  218. 'closed' => true,
  219. 'localonly' => true,
  220. )
  221. ),
  222. 'plugins' => array(
  223. 'core' => self::corePlugins(),
  224. 'default' => array_merge(self::defaultPlugins(), array(
  225. 'MobileProfile' => array(),
  226. )),
  227. 'disable-Directory' => 1,
  228. ),
  229. 'public' => array('localonly' => true),
  230. 'discovery' => array('cors' => true) // Allow Cross-Origin Resource Sharing for service discovery (host-meta, XRD, etc.)
  231. );
  232. }
  233. }