profilefields.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. /**
  3. * GNU Social
  4. * Copyright (C) 2010, Free Software Foundation, Inc.
  5. *
  6. * PHP version 5
  7. *
  8. * LICENCE:
  9. * 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 Widget
  23. * @package GNU Social
  24. * @author Max Shinn <trombonechamp@gmail.com>
  25. * @copyright 2010 Free Software Foundation, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  27. */
  28. if (!defined('STATUSNET')) {
  29. exit(1);
  30. }
  31. require_once INSTALLDIR . '/lib/adminpanelaction.php';
  32. class ProfilefieldsAdminPanelAction extends AdminPanelAction
  33. {
  34. function title()
  35. {
  36. return _('Profile fields');
  37. }
  38. function getInstructions()
  39. {
  40. return _('GNU Social custom profile fields');
  41. }
  42. function showForm()
  43. {
  44. $form = new ProfilefieldsAdminForm($this);
  45. $form->show();
  46. return;
  47. }
  48. function saveSettings()
  49. {
  50. $field = GNUsocialProfileExtensionField::getKV('id', $this->trimmed('id'));
  51. if (!$field)
  52. $field = new GNUsocialProfileExtensionField();
  53. $field->title = $this->trimmed('title');
  54. $field->description = $this->trimmed('description');
  55. $field->type = $this->trimmed('type');
  56. $field->systemname = $this->trimmed('systemname');
  57. if (!gnusocial_field_systemname_validate($field->systemname)) {
  58. $this->clientError(_('Internal system name must be unique and consist of only alphanumeric characters!'));
  59. }
  60. if ($field->id) {
  61. if ($field->validate())
  62. $field->update();
  63. else {
  64. $this->clientError(_('There was an error with the field data.'));
  65. }
  66. }
  67. else {
  68. $field->insert();
  69. }
  70. return;
  71. }
  72. }
  73. class ProfilefieldsAdminForm extends AdminForm
  74. {
  75. function id()
  76. {
  77. return 'form_profilefields_admin_panel';
  78. }
  79. function formClass()
  80. {
  81. return 'form_settings';
  82. }
  83. function action()
  84. {
  85. return '/admin/profilefields';
  86. }
  87. function formData()
  88. {
  89. $title = null;
  90. $description = null;
  91. $type = null;
  92. $systemname = null;
  93. $id = null;
  94. $fieldsettitle = _("New Profile Field");
  95. //Edit a field
  96. if ($this->out->trimmed('edit')) {
  97. $field = GNUsocialProfileExtensionField::getKV('id', $this->out->trimmed('edit'));
  98. $title = $field->title;
  99. $description = $field->description;
  100. $type = $field->type;
  101. $systemname = $field->systemname;
  102. $this->out->hidden('id', $field->id, 'id');
  103. $fieldsettitle = _("Edit Profile Field");
  104. }
  105. //Don't show the list of all fields when editing one
  106. else {
  107. $this->out->elementStart('fieldset');
  108. $this->out->element('legend', null, _('Existing Custom Profile Fields'));
  109. $this->out->elementStart('ul', 'form_data');
  110. $fields = GNUsocialProfileExtensionField::allFields();
  111. foreach ($fields as $field) {
  112. $this->li();
  113. $content =
  114. $this->out->elementStart('div');
  115. $this->out->element('a', array('href' => '/admin/profilefields?edit=' . $field->id),
  116. $field->title);
  117. $this->out->text(' (' . $field->type . '): ' . $field->description);
  118. $this->out->elementEnd('div');
  119. $this->unli();
  120. }
  121. $this->out->elementEnd('ul');
  122. $this->out->elementEnd('fieldset');
  123. }
  124. //New fields
  125. $this->out->elementStart('fieldset');
  126. $this->out->element('legend', null, $fieldsettitle);
  127. $this->out->elementStart('ul', 'form_data');
  128. $this->li();
  129. $this->out->input('title', _('Title'), $title,
  130. _('The title of the field'));
  131. $this->unli();
  132. $this->li();
  133. $this->out->input('systemname', _('Internal name'), $systemname,
  134. _('The alphanumeric name used internally for this field. Also the key used in OStatus user info. (optional)'));
  135. $this->unli();
  136. $this->li();
  137. $this->out->input('description', _('Description'), $description,
  138. _('An optional more detailed description of the field'));
  139. $this->unli();
  140. $this->li();
  141. $this->out->dropdown('type', _('Type'), array('text' => _("Text"),
  142. 'str' => _("String")),
  143. _('The type of the datafield'), false, $type);
  144. $this->unli();
  145. $this->out->elementEnd('ul');
  146. $this->out->elementEnd('fieldset');
  147. }
  148. /**
  149. * Action elements
  150. *
  151. * @return void
  152. */
  153. function formActions()
  154. {
  155. $this->out->submit('submit', _('Save'), 'submit', null, _('Save new field'));
  156. }
  157. }