profileactionform.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. public $widgetOpts;
  48. public $scoped;
  49. /**
  50. * Profile of user to act on
  51. */
  52. var $profile = null;
  53. /**
  54. * Return-to args
  55. */
  56. var $args = null;
  57. /**
  58. * Constructor
  59. *
  60. * @param HTMLOutputter $out output channel
  61. * @param Profile $profile profile of user to act on
  62. * @param array $args return-to args
  63. */
  64. function __construct($out=null, $profile=null, $args=null)
  65. {
  66. parent::__construct($out);
  67. $this->profile = $profile;
  68. $this->args = $args;
  69. }
  70. /**
  71. * ID of the form
  72. *
  73. * @return int ID of the form
  74. */
  75. function id()
  76. {
  77. return $this->target() . '-' . $this->profile->id;
  78. }
  79. /**
  80. * class of the form
  81. *
  82. * @return string class of the form
  83. */
  84. function formClass()
  85. {
  86. return 'form_user_'.$this->target();
  87. }
  88. /**
  89. * Action of the form
  90. *
  91. * @return string URL of the action
  92. */
  93. function action()
  94. {
  95. return common_local_url($this->target());
  96. }
  97. /**
  98. * Legend of the Form
  99. *
  100. * @return void
  101. */
  102. function formLegend()
  103. {
  104. $this->out->element('legend', null, $this->description());
  105. }
  106. /**
  107. * Data elements of the form
  108. *
  109. * @return void
  110. */
  111. function formData()
  112. {
  113. $action = $this->target();
  114. $this->out->hidden($action.'to-' . $this->profile->id,
  115. $this->profile->id,
  116. 'profileid');
  117. if ($this->args) {
  118. foreach ($this->args as $k => $v) {
  119. $this->out->hidden('returnto-' . $k, $v);
  120. }
  121. }
  122. }
  123. /**
  124. * Action elements
  125. *
  126. * @return void
  127. */
  128. function formActions()
  129. {
  130. $this->out->submit('submit', $this->title(), 'submit',
  131. null, $this->description());
  132. }
  133. /**
  134. * Action this form targets
  135. *
  136. * @return string Name of the action, lowercased.
  137. */
  138. function target()
  139. {
  140. return null;
  141. }
  142. /**
  143. * Title of the form
  144. *
  145. * @return string Title of the form, internationalized
  146. */
  147. function title()
  148. {
  149. return null;
  150. }
  151. /**
  152. * Description of the form
  153. *
  154. * @return string description of the form, internationalized
  155. */
  156. function description()
  157. {
  158. return null;
  159. }
  160. }