profileactionform.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Superclass for forms that operate on a profile
  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. * @copyright 2009 StatusNet, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  27. * @link http://status.net/
  28. */
  29. if (!defined('STATUSNET')) {
  30. exit(1);
  31. }
  32. /**
  33. * Superclass for forms that operate on a profile
  34. *
  35. * Certain forms (block, silence, userflag, sandbox, delete) work on
  36. * a single profile and work almost the same. So, this form extracts
  37. * a lot of the common code to simplify those forms.
  38. *
  39. * @category Form
  40. * @package StatusNet
  41. * @author Evan Prodromou <evan@status.net>
  42. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  43. * @link http://status.net/
  44. */
  45. class ProfileActionForm extends Form
  46. {
  47. /**
  48. * Profile of user to act on
  49. */
  50. var $profile = null;
  51. /**
  52. * Return-to args
  53. */
  54. var $args = null;
  55. /**
  56. * Constructor
  57. *
  58. * @param HTMLOutputter $out output channel
  59. * @param Profile $profile profile of user to act on
  60. * @param array $args return-to args
  61. */
  62. function __construct($out=null, $profile=null, $args=null)
  63. {
  64. parent::__construct($out);
  65. $this->profile = $profile;
  66. $this->args = $args;
  67. }
  68. /**
  69. * ID of the form
  70. *
  71. * @return int ID of the form
  72. */
  73. function id()
  74. {
  75. return $this->target() . '-' . $this->profile->id;
  76. }
  77. /**
  78. * class of the form
  79. *
  80. * @return string class of the form
  81. */
  82. function formClass()
  83. {
  84. return 'form_user_'.$this->target();
  85. }
  86. /**
  87. * Action of the form
  88. *
  89. * @return string URL of the action
  90. */
  91. function action()
  92. {
  93. return common_local_url($this->target());
  94. }
  95. /**
  96. * Legend of the Form
  97. *
  98. * @return void
  99. */
  100. function formLegend()
  101. {
  102. $this->out->element('legend', null, $this->description());
  103. }
  104. /**
  105. * Data elements of the form
  106. *
  107. * @return void
  108. */
  109. function formData()
  110. {
  111. $action = $this->target();
  112. $this->out->hidden($action.'to-' . $this->profile->id,
  113. $this->profile->id,
  114. 'profileid');
  115. if ($this->args) {
  116. foreach ($this->args as $k => $v) {
  117. $this->out->hidden('returnto-' . $k, $v);
  118. }
  119. }
  120. }
  121. /**
  122. * Action elements
  123. *
  124. * @return void
  125. */
  126. function formActions()
  127. {
  128. $this->out->submit('submit', $this->title(), 'submit',
  129. null, $this->description());
  130. }
  131. /**
  132. * Action this form targets
  133. *
  134. * @return string Name of the action, lowercased.
  135. */
  136. function target()
  137. {
  138. return null;
  139. }
  140. /**
  141. * Title of the form
  142. *
  143. * @return string Title of the form, internationalized
  144. */
  145. function title()
  146. {
  147. return null;
  148. }
  149. /**
  150. * Description of the form
  151. *
  152. * @return string description of the form, internationalized
  153. */
  154. function description()
  155. {
  156. return null;
  157. }
  158. }