groupeditform.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Form for editing a group
  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 Form
  23. * @package StatusNet
  24. * @author Evan Prodromou <evan@status.net>
  25. * @author Sarven Capadisli <csarven@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://status.net/
  29. */
  30. if (!defined('STATUSNET') && !defined('LACONICA')) {
  31. exit(1);
  32. }
  33. require_once INSTALLDIR.'/lib/form.php';
  34. /**
  35. * Form for editing a group
  36. *
  37. * @category Form
  38. * @package StatusNet
  39. * @author Evan Prodromou <evan@status.net>
  40. * @author Sarven Capadisli <csarven@status.net>
  41. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  42. * @link http://status.net/
  43. *
  44. * @see UnsubscribeForm
  45. */
  46. class GroupEditForm extends Form
  47. {
  48. /**
  49. * group for user to join
  50. */
  51. var $group = null;
  52. /**
  53. * Constructor
  54. *
  55. * @param Action $out output channel
  56. * @param User_group $group group to join
  57. */
  58. function __construct($out=null, $group=null)
  59. {
  60. parent::__construct($out);
  61. $this->group = $group;
  62. }
  63. /**
  64. * ID of the form
  65. *
  66. * @return string ID of the form
  67. */
  68. function id()
  69. {
  70. if ($this->group) {
  71. return 'form_group_edit-' . $this->group->id;
  72. } else {
  73. return 'form_group_add';
  74. }
  75. }
  76. /**
  77. * class of the form
  78. *
  79. * @return string of the form class
  80. */
  81. function formClass()
  82. {
  83. return 'form_settings';
  84. }
  85. /**
  86. * Action of the form
  87. *
  88. * @return string URL of the action
  89. */
  90. function action()
  91. {
  92. if ($this->group) {
  93. return common_local_url('editgroup',
  94. array('nickname' => $this->group->nickname));
  95. } else {
  96. return common_local_url('newgroup');
  97. }
  98. }
  99. /**
  100. * Name of the form
  101. *
  102. * @return void
  103. */
  104. function formLegend()
  105. {
  106. // TRANS: Form legend for group edit form.
  107. $this->out->element('legend', null, _('Create a new group'));
  108. }
  109. /**
  110. * Data elements of the form
  111. *
  112. * @return void
  113. */
  114. function formData()
  115. {
  116. if ($this->group) {
  117. $id = $this->group->id;
  118. $nickname = $this->group->nickname;
  119. $fullname = $this->group->fullname;
  120. $homepage = $this->group->homepage;
  121. $description = $this->group->description;
  122. $location = $this->group->location;
  123. } else {
  124. $id = '';
  125. $nickname = '';
  126. $fullname = '';
  127. $homepage = '';
  128. $description = '';
  129. $location = '';
  130. }
  131. $this->out->elementStart('ul', 'form_data');
  132. if (Event::handle('StartGroupEditFormData', array($this))) {
  133. $this->out->elementStart('li');
  134. $this->out->hidden('groupid', $id);
  135. // TRANS: Field label on group edit form.
  136. $this->out->input('newnickname', _('Nickname'),
  137. ($this->out->arg('newnickname')) ? $this->out->arg('newnickname') : $nickname,
  138. // TRANS: Field title on group edit form.
  139. _('1-64 lowercase letters or numbers, no punctuation or spaces.'),
  140. null, false,
  141. $this->group instanceof User_group && !common_config('profile', 'changenick')
  142. ? array('disabled'=>'disabled') // can't change nickname
  143. : array()); // either we can change nickname, or we're creating a new group.
  144. $this->out->elementEnd('li');
  145. $this->out->elementStart('li');
  146. // TRANS: Field label on group edit form.
  147. $this->out->input('fullname', _('Full name'),
  148. ($this->out->arg('fullname')) ? $this->out->arg('fullname') : $fullname);
  149. $this->out->elementEnd('li');
  150. $this->out->elementStart('li');
  151. // TRANS: Field label on group edit form; points to "more info" for a group.
  152. $this->out->input('homepage', _('Homepage'),
  153. ($this->out->arg('homepage')) ? $this->out->arg('homepage') : $homepage,
  154. // TRANS: Field title on group edit form.
  155. _('URL of the homepage or blog of the group or topic.'));
  156. $this->out->elementEnd('li');
  157. $this->out->elementStart('li');
  158. $desclimit = User_group::maxDescription();
  159. if ($desclimit == 0) {
  160. // TRANS: Text area title for group description when there is no text limit.
  161. $descinstr = _('Describe the group or topic.');
  162. } else {
  163. // TRANS: Text area title for group description.
  164. // TRANS: %d is the number of characters available for the description.
  165. $descinstr = sprintf(_m('Describe the group or topic in %d character or less.',
  166. 'Describe the group or topic in %d characters or less.',
  167. $desclimit),
  168. $desclimit);
  169. }
  170. // TRANS: Text area label on group edit form; contains description of group.
  171. $this->out->textarea('description', _('Description'),
  172. ($this->out->arg('description')) ? $this->out->arg('description') : $description,
  173. $descinstr);
  174. $this->out->elementEnd('li');
  175. $this->out->elementStart('li');
  176. // TRANS: Field label on group edit form.
  177. $this->out->input('location', _('Location'),
  178. ($this->out->arg('location')) ? $this->out->arg('location') : $location,
  179. // TRANS: Field title on group edit form.
  180. _('Location for the group, if any, like "City, State (or Region), Country".'));
  181. $this->out->elementEnd('li');
  182. if (common_config('group', 'maxaliases') > 0) {
  183. $aliases = (empty($this->group)) ? array() : $this->group->getAliases();
  184. $this->out->elementStart('li');
  185. // TRANS: Field label on group edit form.
  186. $this->out->input('aliases', _('Aliases'),
  187. ($this->out->arg('aliases')) ? $this->out->arg('aliases') :
  188. (!empty($aliases)) ? implode(' ', $aliases) : '',
  189. // TRANS: Input field title for group aliases.
  190. // TRANS: %d is the maximum number of group aliases available.
  191. sprintf(_m('Extra nicknames for the group, separated with commas or spaces. Maximum %d alias allowed.',
  192. 'Extra nicknames for the group, separated with commas or spaces. Maximum %d aliases allowed.',
  193. common_config('group', 'maxaliases')),
  194. common_config('group', 'maxaliases')));;
  195. $this->out->elementEnd('li');
  196. }
  197. $this->out->elementStart('li');
  198. // TRANS: Checkbox field label on group edit form to mark a group private.
  199. $this->out->checkbox('private', _m('LABEL','Private'),
  200. ($this->out->arg('private')) ? $this->out->arg('private') :
  201. ((!empty($this->group)) ? $this->group->isPrivate() : false),
  202. // TRANS: Checkbox field title on group edit form to mark a group private.
  203. _('New members must be approved by admin and all posts are forced to be private.'));
  204. $this->out->elementEnd('li');
  205. Event::handle('EndGroupEditFormData', array($this));
  206. }
  207. $this->out->elementEnd('ul');
  208. }
  209. /**
  210. * Action elements
  211. *
  212. * @return void
  213. */
  214. function formActions()
  215. {
  216. // TRANS: Text for save button on group edit form.
  217. $this->out->submit('submit', _m('BUTTON','Save'));
  218. }
  219. }