groupeditform.php 9.0 KB

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