]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Bookmark/actions/newbookmark.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / plugins / Bookmark / actions / newbookmark.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2010, StatusNet, Inc.
5  *
6  * Add a new bookmark
7  *
8  * PHP version 5
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Affero General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Affero General Public License for more details.
19  *
20  * You should have received a copy of the GNU Affero General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  * @category  Bookmark
24  * @package   StatusNet
25  * @author    Evan Prodromou <evan@status.net>
26  * @copyright 2010 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28  * @link      http://status.net/
29  */
30 if (!defined('STATUSNET')) {
31     // This check helps protect against security problems;
32     // your code file can't be executed directly from the web.
33     exit(1);
34 }
35
36 /**
37  * Add a new bookmark
38  *
39  * @category  Bookmark
40  * @package   StatusNet
41  * @author    Evan Prodromou <evan@status.net>
42  * @copyright 2010 StatusNet, Inc.
43  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
44  * @link      http://status.net/
45  */
46 class NewbookmarkAction extends FormAction
47 {
48     protected $complete    = null;
49     protected $title       = null;
50     protected $url         = null;
51     protected $tags        = null;
52     protected $description = null;
53
54     function title()
55     {
56         // TRANS: Title for action to create a new bookmark.
57         return _m('New bookmark');
58     }
59
60     protected function doPreparation()
61     {
62         $this->title       = $this->trimmed('title');
63         $this->url         = $this->trimmed('url');
64         $this->tags        = preg_split('/[\s,]+/', $this->trimmed('tags'), null,  PREG_SPLIT_NO_EMPTY);
65         $this->description = $this->trimmed('description');
66
67         return true;
68     }
69
70     /**
71      * Add a new bookmark
72      *
73      * @return void
74      */
75     function handlePost()
76     {
77         if (empty($this->title)) {
78             // TRANS: Client exception thrown when trying to create a new bookmark without a title.
79             throw new ClientException(_m('Bookmark must have a title.'));
80         }
81
82         if (empty($this->url)) {
83             // TRANS: Client exception thrown when trying to create a new bookmark without a URL.
84             throw new ClientException(_m('Bookmark must have an URL.'));
85         }
86
87         $options = array();
88
89         ToSelector::fillOptions($this, $options);
90
91         $saved = Bookmark::addNew($this->scoped,
92                                    $this->title,
93                                    $this->url,
94                                    $this->tags,
95                                    $this->description,
96                                    $options);
97     }
98
99     /**
100      * Output a notice
101      *
102      * Used to generate the notice code for Ajax results.
103      *
104      * @param Notice $notice Notice that was saved
105      *
106      * @return void
107      */
108     function showNotice(Notice $notice)
109     {
110         class_exists('NoticeList'); // @fixme hack for autoloader
111         $nli = new NoticeListItem($notice, $this);
112         $nli->show();
113     }
114
115     /**
116      * Show the bookmark form
117      *
118      * @return void
119      */
120     function showContent()
121     {
122         if (!empty($this->error)) {
123             $this->element('p', 'error', $this->error);
124         }
125
126         $form = new BookmarkForm($this,
127                                  $this->title,
128                                  $this->url,
129                                  $this->tags,
130                                  $this->description);
131
132         $form->show();
133
134         return;
135     }
136
137     /**
138      * Return true if read only.
139      *
140      * MAY override
141      *
142      * @param array $args other arguments
143      *
144      * @return boolean is read only action?
145      */
146     function isReadOnly($args)
147     {
148         if ($_SERVER['REQUEST_METHOD'] == 'GET' ||
149             $_SERVER['REQUEST_METHOD'] == 'HEAD') {
150             return true;
151         } else {
152             return false;
153         }
154     }
155 }