editmirror.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. * PHP version 5
  5. *
  6. * LICENCE: This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * @package StatusNet
  20. * @copyright 2010 StatusNet, Inc.
  21. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  22. * @link http://status.net/
  23. */
  24. if (!defined('STATUSNET') && !defined('LACONICA')) {
  25. exit(1);
  26. }
  27. class EditMirrorForm extends Form
  28. {
  29. function __construct($action, $profile)
  30. {
  31. parent::__construct($action);
  32. $this->profile = clone($profile);
  33. $this->user = common_current_user();
  34. $this->mirror = SubMirror::pkeyGet(array('subscriber' => $this->user->id,
  35. 'subscribed' => $this->profile->id));
  36. }
  37. /**
  38. * Name of the form
  39. *
  40. * Sub-classes should overload this with the name of their form.
  41. *
  42. * @return void
  43. */
  44. function formLegend()
  45. {
  46. }
  47. /**
  48. * Visible or invisible data elements
  49. *
  50. * Display the form fields that make up the data of the form.
  51. * Sub-classes should overload this to show their data.
  52. *
  53. * @return void
  54. */
  55. function formData()
  56. {
  57. $this->out->elementStart('fieldset');
  58. $this->out->hidden('profile', $this->profile->id);
  59. $this->out->elementStart('div', array('style' => 'float: left; width: 80px;'));
  60. $img = $this->profile->avatarUrl(AVATAR_STREAM_SIZE);
  61. $feed = $this->getFeed($this->profile);
  62. $this->out->elementStart('a', array('href' => $this->profile->profileurl));
  63. $this->out->element('img', array('src' => $img, 'style' => 'float: left'));
  64. $this->out->elementEnd('a');
  65. $this->out->elementEnd('div');
  66. $this->out->elementStart('div', array('style' => 'margin-left: 80px; margin-right: 20px'));
  67. $this->out->elementStart('p');
  68. $this->out->elementStart('div');
  69. $this->out->element('a', array('href' => $this->profile->profileurl), $this->profile->getBestName());
  70. $this->out->elementEnd('div');
  71. $this->out->elementStart('div');
  72. if ($feed) {
  73. // XXX: Why the hard coded space?
  74. // TRANS: Field label (URL expectected).
  75. $this->out->text(_m('LABEL', 'Remote feed:') . ' ');
  76. //$this->out->element('a', array('href' => $feed), $feed);
  77. $this->out->element('input', array('value' => $feed, 'readonly' => 'readonly', 'style' => 'width: 100%'));
  78. } else {
  79. // TRANS: Field label.
  80. $this->out->text(_m('LABEL', 'Local user'));
  81. }
  82. $this->out->elementEnd('div');
  83. $this->out->elementEnd('p');
  84. $this->out->elementStart('fieldset', array('style' => 'margin-top: 20px'));
  85. // TRANS: Fieldset legend for feed mirror setting.
  86. $this->out->element('legend', false, _m('Mirroring style'));
  87. // TRANS: Feed mirror style (radio button option).
  88. $styles = array('repeat' => _m('Repeat: reference the original user\'s post (sometimes shows as "RT @blah")'),
  89. // TRANS: Feed mirror style (radio button option).
  90. 'copy' => _m('Repost the content under my account'));
  91. foreach ($styles as $key => $label) {
  92. $this->out->elementStart('div');
  93. $attribs = array('type' => 'radio',
  94. 'value' => $key,
  95. 'name' => 'style',
  96. 'id' => $this->id() . '-style');
  97. if ($key == $this->mirror->style || ($key == 'repeat' && empty($this->mirror->style))) {
  98. $attribs['checked'] = 'checked';
  99. }
  100. $this->out->element('input', $attribs);
  101. $this->out->element('span', false, $label); // @todo FIXME: should be label, but the styles muck it up for now
  102. $this->out->elementEnd('div');
  103. }
  104. $this->out->elementEnd('fieldset');
  105. $this->out->elementStart('div');
  106. // TRANS: Button text to save feed mirror settings.
  107. $this->out->submit($this->id() . '-save', _m('BUTTON','Save'));
  108. $this->out->element('input', array('type' => 'submit',
  109. // TRANS: Button text to stop mirroring a feed.
  110. 'value' => _m('BUTTON','Stop mirroring'),
  111. 'name' => 'delete',
  112. 'class' => 'submit'));
  113. $this->out->elementEnd('div');
  114. $this->out->elementEnd('div');
  115. $this->out->elementEnd('fieldset');
  116. }
  117. private function getFeed($profile)
  118. {
  119. // Ok this is a bit of a hack. ;)
  120. if (class_exists('Ostatus_profile')) {
  121. $oprofile = Ostatus_profile::getKV('profile_id', $profile->id);
  122. if ($oprofile) {
  123. return $oprofile->feeduri;
  124. }
  125. }
  126. var_dump('wtf');
  127. return false;
  128. }
  129. /**
  130. * ID of the form
  131. *
  132. * Should be unique on the page. Sub-classes should overload this
  133. * to show their own IDs.
  134. *
  135. * @return string ID of the form
  136. */
  137. function id()
  138. {
  139. return 'edit-mirror-form-' . $this->profile->id;
  140. }
  141. /**
  142. * Action of the form.
  143. *
  144. * URL to post to. Should be overloaded by subclasses to give
  145. * somewhere to post to.
  146. *
  147. * @return string URL to post to
  148. */
  149. function action()
  150. {
  151. return common_local_url('editmirror');
  152. }
  153. /**
  154. * Class of the form.
  155. *
  156. * @return string the form's class
  157. */
  158. function formClass()
  159. {
  160. return 'form_settings';
  161. }
  162. }