]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/SubMirror/forms/editmirror.php
Removed plugin Google-Analytics as this is free/libre and decentralized
[quix0rs-gnu-social.git] / plugins / SubMirror / forms / editmirror.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->profile->avatarUrl(AVATAR_STREAM_SIZE);
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 getFeed($profile)
134     {
135         // Ok this is a bit of a hack. ;)
136         if (class_exists('Ostatus_profile')) {
137             $oprofile = Ostatus_profile::getKV('profile_id', $profile->id);
138             if ($oprofile) {
139                 return $oprofile->feeduri;
140             }
141         }
142         var_dump('wtf');
143         return false;
144     }
145
146     /**
147      * ID of the form
148      *
149      * Should be unique on the page. Sub-classes should overload this
150      * to show their own IDs.
151      *
152      * @return string ID of the form
153      */
154     function id()
155     {
156         return 'edit-mirror-form-' . $this->profile->id;
157     }
158
159     /**
160      * Action of the form.
161      *
162      * URL to post to. Should be overloaded by subclasses to give
163      * somewhere to post to.
164      *
165      * @return string URL to post to
166      */
167     function action()
168     {
169         return common_local_url('editmirror');
170     }
171
172     /**
173      * Class of the form.
174      *
175      * @return string the form's class
176      */
177     function formClass()
178     {
179         return 'form_settings';
180     }
181 }