3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
6 * 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.
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.
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/>.
20 if (!defined('LACONICA')) { exit(1); }
22 require_once(INSTALLDIR.'/lib/omb.php');
24 class PostnoticeAction extends Action {
25 function handle($args)
27 parent::handle($args);
29 common_remove_magic_from_request();
30 $req = OAuthRequest::from_request();
31 # Note: server-to-server function!
32 $server = omb_oauth_server();
33 list($consumer, $token) = $server->verify_request($req);
34 if ($this->save_notice($req, $consumer, $token)) {
35 print "omb_version=".OMB_VERSION_01;
37 } catch (OAuthException $e) {
38 common_server_error($e->getMessage());
43 function save_notice(&$req, &$consumer, &$token)
45 $version = $req->get_parameter('omb_version');
46 if ($version != OMB_VERSION_01) {
47 common_user_error(_('Unsupported OMB version'), 400);
51 $listenee = $req->get_parameter('omb_listenee');
52 $remote_profile = Remote_profile::staticGet('uri', $listenee);
53 if (!$remote_profile) {
54 common_user_error(_('Profile unknown'), 403);
57 $sub = Subscription::staticGet('token', $token->key);
59 common_user_error(_('No such subscription'), 403);
62 $content = $req->get_parameter('omb_notice_content');
63 $content_shortened = common_shorten_links($content);
64 if (mb_strlen($content_shortened) > 140) {
65 common_user_error(_('Invalid notice content'), 400);
68 $notice_uri = $req->get_parameter('omb_notice');
69 if (!Validate::uri($notice_uri) &&
70 !common_valid_tag($notice_uri)) {
71 common_user_error(_('Invalid notice uri'), 400);
74 $notice_url = $req->get_parameter('omb_notice_url');
75 if ($notice_url && !common_valid_http_url($notice_url)) {
76 common_user_error(_('Invalid notice url'), 400);
79 $notice = Notice::staticGet('uri', $notice_uri);
81 $notice = Notice::saveNew($remote_profile->id, $content, 'omb', false, 0, $notice_uri);
82 if (is_string($notice)) {
83 common_server_serror($notice, 500);
86 common_broadcast_notice($notice, true);