siteprofile.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. public $widgetOpts;
  39. public $scoped;
  40. /**
  41. * Returns the config settings for a site profile by name
  42. *
  43. * @param string $name name of a site profile
  44. * @return array config settings
  45. */
  46. static public function getSettings($name)
  47. {
  48. $sprofileClass = ucfirst($name) . "Site";
  49. if (class_exists($sprofileClass)) {
  50. return call_user_func(array($sprofileClass, 'getSettings'));
  51. } else {
  52. common_log(
  53. LOG_ERR,
  54. "Unknown site profile '{$name}' specified in config file.",
  55. __FILE__
  56. );
  57. return array();
  58. }
  59. }
  60. }
  61. /**
  62. * Site profile settings contain the list of the default settings (and
  63. * possibly other information for a particular flavor of StatusNet
  64. * installation). These will overwrite base defaults in $config global.
  65. *
  66. * @category Installation
  67. * @package StatusNet
  68. * @author Zach Copley <zach@status.net>
  69. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  70. * @link http://status.net/
  71. */
  72. abstract class SiteProfileSettings
  73. {
  74. static function getSettings()
  75. {
  76. throw new MethodNotImplementedException(__METHOD__);
  77. }
  78. static function corePlugins() {
  79. return common_config('plugins', 'core');
  80. }
  81. static function defaultPlugins() {
  82. return common_config('plugins', 'default');
  83. }
  84. }
  85. /**
  86. * Settings for a 'public' site
  87. */
  88. class PublicSite extends SiteProfileSettings
  89. {
  90. /**
  91. * Get the settings for this site profile
  92. *
  93. * @return type array an array of settings
  94. */
  95. static function getSettings() {
  96. global $config;
  97. return array(
  98. // We only want to change these values, not replace entire 'site' array
  99. 'site' => array_merge(
  100. $config['site'], array(
  101. 'inviteonly' => false,
  102. 'private' => false,
  103. 'closed' => false
  104. )
  105. ),
  106. 'plugins' => array(
  107. 'core' => self::corePlugins(),
  108. 'default' => array_merge(self::defaultPlugins(), array(
  109. 'RegisterThrottle' => array(),
  110. ))
  111. ),
  112. 'discovery' => array('cors' => true) // Allow Cross-Origin Resource Sharing for service discovery (host-meta, XRD, etc.)
  113. );
  114. }
  115. }
  116. /**
  117. * Settings for a 'private' site
  118. *
  119. * // XXX Too business oriented?
  120. */
  121. class PrivateSite extends SiteProfileSettings
  122. {
  123. /**
  124. * Get the settings for this site profile
  125. *
  126. * @return type array an array of settings
  127. */
  128. static function getSettings() {
  129. global $config;
  130. return array(
  131. // We only want to change these values, not replace entire 'site' array
  132. 'site' => array_merge(
  133. $config['site'], array(
  134. 'inviteonly' => true,
  135. 'private' => true,
  136. )
  137. ),
  138. 'plugins' => array(
  139. 'core' => self::corePlugins(),
  140. 'default' => array_merge(self::defaultPlugins(), array(
  141. 'ExtendedProfile' => array(),
  142. 'EmailRegistration' => array(),
  143. 'MobileProfile' => array(),
  144. )),
  145. 'disable-OStatus' => 1,
  146. 'disable-WebFinger' => 1,
  147. ),
  148. 'public' => array('localonly' => true),
  149. 'profile' => array('delete' => 'true'),
  150. 'license' => array('type' => 'private'),
  151. 'attachments' => array(
  152. // Only allow uploads of pictures and MS Office files
  153. 'supported' => array(
  154. 'image/png',
  155. 'image/jpeg',
  156. 'image/gif',
  157. 'image/svg+xml',
  158. 'application/pdf',
  159. 'application/msword',
  160. 'application/vnd.ms-office',
  161. 'application/vnd.ms-excel',
  162. 'application/vnd.ms-powerpoint',
  163. 'application/ogg'
  164. )
  165. ),
  166. 'discovery' => array('cors' => false) // Allow Cross-Origin Resource Sharing for service discovery (host-meta, XRD, etc.)
  167. );
  168. }
  169. }
  170. /**
  171. * Settings for a 'community' site
  172. */
  173. class CommunitySite extends SiteProfileSettings
  174. {
  175. /**
  176. * Get the settings for this site profile
  177. *
  178. * @return type array an array of settings
  179. */
  180. static function getSettings() {
  181. global $config;
  182. return array(
  183. // We only want to change these values, not replace entire 'site' array
  184. 'site' => array_merge(
  185. $config['site'], array(
  186. 'private' => false,
  187. 'inviteonly' => true,
  188. 'closed' => false
  189. )
  190. ),
  191. 'plugins' => array(
  192. 'core' => self::corePlugins(),
  193. 'default' => array_merge(self::defaultPlugins(), array(
  194. ))
  195. ),
  196. 'public' => array('localonly' => true),
  197. 'discovery' => array('cors' => true) // Allow Cross-Origin Resource Sharing for service discovery (host-meta, XRD, etc.)
  198. );
  199. }
  200. }
  201. /**
  202. * Settings for a 'singleuser' site
  203. */
  204. class SingleuserSite extends SiteProfileSettings
  205. {
  206. /**
  207. * Get the settings for this site profile
  208. *
  209. * @return type array an array of settings
  210. */
  211. static function getSettings() {
  212. global $config;
  213. return array(
  214. 'singleuser' => array('enabled' => true),
  215. // We only want to change these values, not replace entire 'site' array
  216. 'site' => array_merge(
  217. $config['site'], array(
  218. 'private' => false,
  219. 'closed' => true,
  220. 'localonly' => true,
  221. )
  222. ),
  223. 'plugins' => array(
  224. 'core' => self::corePlugins(),
  225. 'default' => array_merge(self::defaultPlugins(), array(
  226. 'MobileProfile' => array(),
  227. )),
  228. 'disable-Directory' => 1,
  229. ),
  230. 'public' => array('localonly' => true),
  231. 'discovery' => array('cors' => true) // Allow Cross-Origin Resource Sharing for service discovery (host-meta, XRD, etc.)
  232. );
  233. }
  234. }