]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/SubMirror/lib/editmirrorform.php
Merge remote branch 'gitorious/1.0.x' 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             $this->out->text(_m('LABEL', 'Remote feed:') . ' ');
84             //$this->out->element('a', array('href' => $feed), $feed);
85             $this->out->element('input', array('value' => $feed, 'readonly' => 'readonly', 'style' => 'width: 100%'));
86         } else {
87             $this->out->text(_m('LABEL', 'Local user'));
88         }
89         $this->out->elementEnd('div');
90         $this->out->elementEnd('p');
91
92         $this->out->elementStart('fieldset', array('style' => 'margin-top: 20px'));
93         $this->out->element('legend', false, _m("Mirroring style"));
94
95         $styles = array('repeat' => _m("Repeat: reference the original user's post (sometimes shows as 'RT @blah')"),
96                         'copy' => _m("Repost the content under my account"));
97         foreach ($styles as $key => $label) {
98             $this->out->elementStart('div');
99             $attribs = array('type' => 'radio',
100                              'value' => $key,
101                              'name' => 'style',
102                              'id' => $this->id() . '-style');
103             if ($key == $this->mirror->style || ($key == 'repeat' && empty($this->mirror->style))) {
104                 $attribs['checked'] = 'checked';
105             }
106             $this->out->element('input', $attribs);
107             $this->out->element('span', false, $label); // @fixme should be label, but the styles muck it up for now
108             $this->out->elementEnd('div');
109
110         }
111         $this->out->elementEnd('fieldset');
112
113
114         $this->out->elementStart('div');
115         $this->out->submit($this->id() . '-save', _m('Save'));
116         $this->out->element('input', array('type' => 'submit',
117                                            'value' => _m('Stop mirroring'),
118                                            'name' => 'delete',
119                                            'class' => 'submit'));
120         $this->out->elementEnd('div');
121
122         $this->out->elementEnd('div');
123         $this->out->elementEnd('fieldset');
124     }
125
126     private function getAvatar($profile)
127     {
128         $avatar = $this->profile->getAvatar(48);
129         if ($avatar) {
130             return $avatar->displayUrl();
131         } else {
132             return Avatar::defaultImage(48);
133         }
134     }
135
136     private function getFeed($profile)
137     {
138         // Ok this is a bit of a hack. ;)
139         if (class_exists('Ostatus_profile')) {
140             $oprofile = Ostatus_profile::staticGet('profile_id', $profile->id);
141             if ($oprofile) {
142                 return $oprofile->feeduri;
143             }
144         }
145         var_dump('wtf');
146         return false;
147     }
148
149     /**
150      * ID of the form
151      *
152      * Should be unique on the page. Sub-classes should overload this
153      * to show their own IDs.
154      *
155      * @return string ID of the form
156      */
157     function id()
158     {
159         return 'edit-mirror-form-' . $this->profile->id;
160     }
161
162     /**
163      * Action of the form.
164      *
165      * URL to post to. Should be overloaded by subclasses to give
166      * somewhere to post to.
167      *
168      * @return string URL to post to
169      */
170     function action()
171     {
172         return common_local_url('editmirror');
173     }
174
175     /**
176      * Class of the form.
177      *
178      * @return string the form's class
179      */
180     function formClass()
181     {
182         return 'form_settings';
183     }
184 }