]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/SubMirror/lib/addmirrorform.php
SubMirror plugin initial checkin: allows setting up automatic mirroring of posts...
[quix0rs-gnu-social.git] / plugins / SubMirror / lib / addmirrorform.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 AddMirrorForm extends Form
30 {
31
32     /**
33      * Name of the form
34      *
35      * Sub-classes should overload this with the name of their form.
36      *
37      * @return void
38      */
39
40     function formLegend()
41     {
42     }
43
44     /**
45      * Visible or invisible data elements
46      *
47      * Display the form fields that make up the data of the form.
48      * Sub-classes should overload this to show their data.
49      *
50      * @return void
51      */
52
53     function formData()
54     {
55         $this->out->elementStart('fieldset');
56
57         $this->out->elementStart('ul');
58
59         $this->li();
60         $this->out->element('label', array('for' => $this->id() . '-profile'),
61                             _m("Mirror one of your existing subscriptions:"));
62         $this->out->elementStart('select', array('name' => 'profile'));
63
64         $user = common_current_user();
65         $profile = $user->getSubscriptions();
66         while ($profile->fetch()) {
67             $mirror = SubMirror::pkeyGet(array('subscriber' => $user->id,
68                                                'subscribed' => $profile->id));
69             if (!$mirror) {
70                 $this->out->element('option',
71                                     array('value' => $profile->id),
72                                     $profile->getBestName());
73             }
74         }
75         $this->out->elementEnd('select');
76         $this->out->submit($this->id() . '-save', _m('Save'));
77         $this->unli();
78
79
80         $this->li();
81
82         $this->out->elementStart('fieldset', array('style' => 'width: 360px; margin-left: auto; margin-right: auto'));
83         $this->out->element('p', false,
84                             _m("Not already subscribed to the feed you want? " .
85                                "Add a new remote subscription and paste in the URL!"));
86
87         $this->out->elementStart('div', 'entity_actions');
88         $this->out->elementStart('p', array('id' => 'entity_remote_subscribe',
89                                          'class' => 'entity_subscribe'));
90         $this->out->element('a', array('href' => common_local_url('ostatussub'),
91                                     'class' => 'entity_remote_subscribe')
92                             , _m('Remote'));
93         $this->out->elementEnd('p');
94         $this->out->elementEnd('div');
95
96         $this->out->element('div', array('style' => 'clear: both'));
97         $this->out->elementEnd('fieldset');
98         $this->unli();
99         
100         $this->out->elementEnd('ul');
101         $this->out->elementEnd('fieldset');
102     }
103
104     private function doInput($id, $name, $label, $value=null, $instructions=null)
105     {
106         $this->out->element('label', array('for' => $id), $label);
107         $attrs = array('name' => $name,
108                        'type' => 'text',
109                        'id' => $id);
110         if ($value) {
111             $attrs['value'] = $value;
112         }
113         $this->out->element('input', $attrs);
114         if ($instructions) {
115             $this->out->element('p', 'form_guide', $instructions);
116         }
117     }
118
119     /**
120      * Buttons for form actions
121      *
122      * Submit and cancel buttons (or whatever)
123      * Sub-classes should overload this to show their own buttons.
124      *
125      * @return void
126      */
127
128     function formActions()
129     {
130     }
131
132     /**
133      * ID of the form
134      *
135      * Should be unique on the page. Sub-classes should overload this
136      * to show their own IDs.
137      *
138      * @return string ID of the form
139      */
140
141     function id()
142     {
143         return 'add-mirror-form';
144     }
145
146     /**
147      * Action of the form.
148      *
149      * URL to post to. Should be overloaded by subclasses to give
150      * somewhere to post to.
151      *
152      * @return string URL to post to
153      */
154
155     function action()
156     {
157         return common_local_url('addmirror');
158     }
159
160     /**
161      * Class of the form.
162      *
163      * @return string the form's class
164      */
165
166     function formClass()
167     {
168         return 'form_settings';
169     }
170
171 }