summaryrefslogtreecommitdiff
path: root/plugins/SocialObject/NewSocialObjectAction.php
blob: dd58cacbf2bf23be36aa4e4aa775b00c5787e808 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
/**
 * StatusNet - the distributed open-source microblogging tool
 * Copyright (C) 2009, 2010, StatusNet, Inc.
 * Copyright (C) 2010, Free Software Foundation, Inc.
 *
 * Base class for handling new social-objects
 *
 * PHP version 5
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category  GNUSocial
 * @package   StatusNet
 * @author    Shashi Gowda <connect2shashi@gmail.com>
 * @copyright 2009, 2010, StatusNet, Inc.
 * @copyright 2010, Free Software Foundation, Inc.
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
 * @link      http://daisycha.in
 */


if (!defined('STATUSNET')) {
    exit(1);
}

class NewSocialObjectAction extends NewnoticeAction
{
    private $slug=null;
    private $dbclass=null;

    function saveNewNotice($metadata=array())
    {
        $this->validate();

        # summarize social-object data to be put in as notice content
        # should be usable in xmpp, email etc.
        $content = $this->getSummary();
        $replyto = $this->getReplyTo();

        $metadata['replies'] = $this->getMentions();
        $metadata['urls'] = $this->getUrls();
        $metadata['groups'] = $this->getGroups();
        $metadata['tags'] = $this->getTags();

        # this is largely copied from parent::saveNewNotice

        $user = common_current_user();
        assert($user); // XXX: maybe an error instead...

        #If an ID of 0 is wrongly passed here, it will cause a database error,
        #so override it...
        if ($replyto == 0) {
            $replyto = 'false';
        }

        $upload = null;
        $upload = MediaFile::fromUpload('attach');

        if (isset($upload)) {

            $content_shortened .= ' ' . $upload->shortUrl();

            if (Notice::contentTooLong($content_shortened)) {
                $upload->delete();
                $this->clientError(
                    sprintf(
                        _('Max notice size is %d chars, including attachment URL.'),
                          Notice::maxContent()
                    )
                );
            }
        }

        $options = array('reply_to' => ($replyto == 'false') ? null : $replyto);

        if ($user->shareLocation()) {
            // use browser data if checked; otherwise profile data
            if ($this->arg('notice_data-geo')) {
                $locOptions = Notice::locationOptions($this->trimmed('lat'),
                                                      $this->trimmed('lon'),
                                                      $this->trimmed('location_id'),
                                                      $this->trimmed('location_ns'),
                                                      $user->getProfile());
            } else {
                $locOptions = Notice::locationOptions(null,
                                                      null,
                                                      null,
                                                      null,
                                                      $user->getProfile());
            }

            $options = array_merge($options, $locOptions, $metadata); ### $metadata too.
        }

        $notice = Notice::saveNew($user->id, $content_shortened, 'web', $options);
        $this->saveNew($notice); ### <-- save me.

        if (isset($upload)) {
            $upload->attachToNotice($notice);
        }

        if ($this->boolean('ajax')) {
            header('Content-Type: text/xml;charset=utf-8');
            $this->xw->startDocument('1.0', 'UTF-8');
            $this->elementStart('html');
            $this->elementStart('head');
            $this->element('title', null, _('Notice posted'));
            $this->elementEnd('head');
            $this->elementStart('body');
            $this->showNotice($notice);
            $this->elementEnd('body');
            $this->elementEnd('html');
        } else {
            $returnto = $this->trimmed('returnto');

            if ($returnto) {
                $url = common_local_url($returnto,
                                        array('nickname' => $user->nickname));
            } else {
                $url = common_local_url('shownotice',
                                        array('notice' => $notice->id));
            }
            common_redirect($url, 303);
        }
    }

    function validate()
    {
        return true;
    }

    function getSummary()
    {
        # have this function in the DB class,
        # respect Notice::MaxContent()
    }

    function getReplyTo()
    {
        return $this->trimmed('inreplyto');
    }

    function getMentions()
    {
    }

    function getUrls()
    {
    }

    function getTags()
    {
    }

    function getGroups()
    {
    }

    function save()
    {
        # save your custom data, video, event or whatever.
    }

    function saveNew()
    {
        # save new social-object to its table.
    }

    function showPage()
    {
        if ($this->boolean('ajax')) {
            header('Content-Type: text/xml;charset=utf-8');
            $this->xw->startDocument('1.0', 'UTF-8');
            $this->elementStart('html');
            $this->elementStart('head');
            $this->elementEnd('head');
            $this->elementStart('body');
            $this->showSocialObjectForm();
            $this->elementEnd('body');
            $this->elementEnd('html');
            return false;
        }
        else {
            parent::showPage();
        }
    }

    function showNoticeForm()
    {
        $this->showSocialObjectForm();
    }

    # when user choses to post a social object,
    # the existing notice box will be replaced
    # with this.
    # abstracted out in SocialLayout plugin
    # has autocomplete for replies and groupnames
    function showSocialObjectForm()
    {
        # show some awesome variation of SocialObjectForm
    }
}