]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/SubMirror/lib/editmirrorform.php
Merge branch 'statusnetworkapi' into 1.0.x
[quix0rs-gnu-social.git] / plugins / SubMirror / lib / editmirrorform.php
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
25 if (!defined('STATUSNET') && !defined('LACONICA')) {
26     exit(1);
27 }
28
29 class EditMirrorForm extends Form
30 {
31     function __construct($action, $profile)
32     {
33         parent::__construct($action);
34
35         $this->profile = clone($profile);
36         $this->user = common_current_user();
37         $this->mirror = SubMirror::pkeyGet(array('subscriber' => $this->user->id,
38                                                  'subscribed' => $this->profile->id));
39     }
40
41     /**
42      * Name of the form
43      *
44      * Sub-classes should overload this with the name of their form.
45      *
46      * @return void
47      */
48     function formLegend()
49     {
50     }
51
52     /**
53      * Visible or invisible data elements
54      *
55      * Display the form fields that make up the data of the form.
56      * Sub-classes should overload this to show their data.
57      *
58      * @return void
59      */
60     function formData()
61     {
62         $this->out->elementStart('fieldset');
63
64         $this->out->hidden('profile', $this->profile->id);
65
66         $this->out->elementStart('div', array('style' => 'float: left; width: 80px;'));
67         $img = $this->getAvatar($this->profile);
68         $feed = $this->getFeed($this->profile);
69         $this->out->elementStart('a', array('href' => $this->profile->profileurl));
70         $this->out->element('img', array('src' => $img, 'style' => 'float: left'));
71         $this->out->elementEnd('a');
72         $this->out->elementEnd('div');
73
74
75         $this->out->elementStart('div', array('style' => 'margin-left: 80px; margin-right: 20px'));
76         $this->out->elementStart('p');
77         $this->out->elementStart('div');
78         $this->out->element('a', array('href' => $this->profile->profileurl), $this->profile->getBestName());
79         $this->out->elementEnd('div');
80         $this->out->elementStart('div');
81         if ($feed) {
82             // XXX: Why the hard coded space?
83             // TRANS: Field label (URL expectected).
84             $this->out->text(_m('LABEL', 'Remote feed:') . ' ');
85             //$this->out->element('a', array('href' => $feed), $feed);
86             $this->out->element('input', array('value' => $feed, 'readonly' => 'readonly', 'style' => 'width: 100%'));
87         } else {
88             // TRANS: Field label.
89             $this->out->text(_m('LABEL', 'Local user'));
90         }
91         $this->out->elementEnd('div');
92         $this->out->elementEnd('p');
93
94         $this->out->elementStart('fieldset', array('style' => 'margin-top: 20px'));
95         // TRANS: Fieldset legend for feed mirror setting.
96         $this->out->element('legend', false, _m('Mirroring style'));
97
98         // TRANS: Feed mirror style (radio button option).
99         $styles = array('repeat' => _m('Repeat: reference the original user\'s post (sometimes shows as "RT @blah")'),
100                         // TRANS: Feed mirror style (radio button option).
101                         'copy' => _m('Repost the content under my account'));
102         foreach ($styles as $key => $label) {
103             $this->out->elementStart('div');
104             $attribs = array('type' => 'radio',
105                              'value' => $key,
106                              'name' => 'style',
107                              'id' => $this->id() . '-style');
108             if ($key == $this->mirror->style || ($key == 'repeat' && empty($this->mirror->style))) {
109                 $attribs['checked'] = 'checked';
110             }
111             $this->out->element('input', $attribs);
112             $this->out->element('span', false, $label); // @todo FIXME: should be label, but the styles muck it up for now
113             $this->out->elementEnd('div');
114
115         }
116         $this->out->elementEnd('fieldset');
117
118
119         $this->out->elementStart('div');
120         // TRANS: Button text to save feed mirror settings.
121         $this->out->submit($this->id() . '-save', _m('BUTTON','Save'));
122         $this->out->element('input', array('type' => 'submit',
123                                            // TRANS: Button text to stop mirroring a feed.
124                                            'value' => _m('BUTTON','Stop mirroring'),
125                                            'name' => 'delete',
126                                            'class' => 'submit'));
127         $this->out->elementEnd('div');
128
129         $this->out->elementEnd('div');
130         $this->out->elementEnd('fieldset');
131     }
132
133     private function getAvatar($profile)
134     {
135         $avatar = $this->profile->getAvatar(48);
136         if ($avatar) {
137             return $avatar->displayUrl();
138         } else {
139             return Avatar::defaultImage(48);
140         }
141     }
142
143     private function getFeed($profile)
144     {
145         // Ok this is a bit of a hack. ;)
146         if (class_exists('Ostatus_profile')) {
147             $oprofile = Ostatus_profile::staticGet('profile_id', $profile->id);
148             if ($oprofile) {
149                 return $oprofile->feeduri;
150             }
151         }
152         var_dump('wtf');
153         return false;
154     }
155
156     /**
157      * ID of the form
158      *
159      * Should be unique on the page. Sub-classes should overload this
160      * to show their own IDs.
161      *
162      * @return string ID of the form
163      */
164     function id()
165     {
166         return 'edit-mirror-form-' . $this->profile->id;
167     }
168
169     /**
170      * Action of the form.
171      *
172      * URL to post to. Should be overloaded by subclasses to give
173      * somewhere to post to.
174      *
175      * @return string URL to post to
176      */
177     function action()
178     {
179         return common_local_url('editmirror');
180     }
181
182     /**
183      * Class of the form.
184      *
185      * @return string the form's class
186      */
187     function formClass()
188     {
189         return 'form_settings';
190     }
191 }