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