function save_notice(&$req, &$consumer, &$token) { $version = $req->get_parameter('omb_version'); if ($version != OMB_VERSION_01) { $this->clientError(_('Unsupported OMB version'), 400); return false; } # First, check to see $listenee = $req->get_parameter('omb_listenee'); $remote_profile = Remote_profile::staticGet('uri', $listenee); if (!$remote_profile) { $this->clientError(_('Profile unknown'), 403); return false; } $sub = Subscription::staticGet('token', $token->key); if (!$sub) { $this->clientError(_('No such subscription'), 403); return false; } $content = $req->get_parameter('omb_notice_content'); $content_shortened = common_shorten_links($content); if (mb_strlen($content_shortened) > 140) { $this->clientError(_('Invalid notice content'), 400); return false; } $notice_uri = $req->get_parameter('omb_notice'); if (!Validate::uri($notice_uri) && !common_valid_tag($notice_uri)) { $this->clientError(_('Invalid notice uri'), 400); return false; } $notice_url = $req->get_parameter('omb_notice_url'); if ($notice_url && !common_valid_http_url($notice_url)) { $this->clientError(_('Invalid notice url'), 400); return false; } $notice = Notice::staticGet('uri', $notice_uri); if (!$notice) { $notice = Notice::saveNew($remote_profile->id, $content, 'omb', false, null, $notice_uri); if (is_string($notice)) { common_server_serror($notice, 500); return false; } common_broadcast_notice($notice, true); } return true; }
function add_notice(&$user, &$pl) { $body = trim($pl['body']); $content_shortened = common_shorten_links($body); if (Notice::contentTooLong($content_shortened)) { $from = jabber_normalize_jid($pl['from']); $this->from_site($from, sprintf(_('Message too long - maximum is %1$d characters, you sent %2$d.'), Notice::maxContent(), mb_strlen($content_shortened))); return; } try { $notice = Notice::saveNew($user->id, $content_shortened, 'xmpp'); } catch (Exception $e) { $this->log(LOG_ERR, $e->getMessage()); $this->from_site($user->jabber, $e->getMessage()); return; } common_broadcast_notice($notice); $this->log(LOG_INFO, 'Added notice ' . $notice->id . ' from user ' . $user->nickname); $notice->free(); unset($notice); }
function add_notice(&$user, &$pl) { $body = trim($pl['body']); $content_shortened = $user->shortenLinks($body); if (Notice::contentTooLong($content_shortened)) { $from = jabber_normalize_jid($pl['from']); // TRANS: Response to XMPP source when it sent too long a message. // TRANS: %1$d the maximum number of allowed characters (used for plural), %2$d is the sent number. $this->from_site($from, sprintf(_m('Message too long. Maximum is %1$d character, you sent %2$d.', 'Message too long. Maximum is %1$d characters, you sent %2$d.', Notice::maxContent()), Notice::maxContent(), mb_strlen($content_shortened))); return; } try { $notice = Notice::saveNew($user->id, $content_shortened, 'xmpp'); } catch (Exception $e) { $this->log(LOG_ERR, $e->getMessage()); $this->from_site($user->jabber, $e->getMessage()); return; } common_broadcast_notice($notice); $this->log(LOG_INFO, 'Added notice ' . $notice->id . ' from user ' . $user->nickname); $notice->free(); unset($notice); }
/** * Save a new notice, based on arguments * * If successful, will show the notice, or return an Ajax-y result. * If not, it will show an error message -- possibly Ajax-y. * * Also, if the notice input looks like a command, it will run the * command and show the results -- again, possibly ajaxy. * * @return void */ function saveNewNotice() { $user = common_current_user(); assert($user); // XXX: maybe an error instead... $content = $this->trimmed('status_textarea'); if (!$content) { $this->clientError(_('No content!')); } else { $content_shortened = common_shorten_links($content); if (mb_strlen($content_shortened) > 140) { $this->clientError(_('That\'s too long. ' . 'Max notice size is 140 chars.')); } } $inter = new CommandInterpreter(); $cmd = $inter->handle_command($user, $content_shortened); if ($cmd) { if ($this->boolean('ajax')) { $cmd->execute(new AjaxWebChannel($this)); } else { $cmd->execute(new WebChannel($this)); } return; } $replyto = $this->trimmed('inreplyto'); #If an ID of 0 is wrongly passed here, it will cause a database error, #so override it... if ($replyto == 0) { $replyto = 'false'; } $notice = Notice::saveNew($user->id, $content, 'web', 1, $replyto == 'false' ? null : $replyto); if (is_string($notice)) { $this->clientError($notice); return; } common_broadcast_notice($notice); if ($this->boolean('ajax')) { $this->startHTML('text/xml;charset=utf-8'); $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 add_notice(&$user, &$pl) { $body = trim($pl['body']); $content_shortened = common_shorten_link($body); if (mb_strlen($content_shortened) > 140) { $content = trim(mb_substr($body, 0, 140)); $content_shortened = common_shorten_link($content); } else { $content = $body; } $notice = Notice::saveNew($user->id, $content, 'xmpp'); if (is_string($notice)) { $this->log(LOG_ERR, $notice); return; } common_broadcast_notice($notice); $this->log(LOG_INFO, 'Added notice ' . $notice->id . ' from user ' . $user->nickname); $notice->free(); unset($notice); }
function saveNewNotice() { $user = $this->flink->getUser(); $content = $this->trimmed('status_textarea'); if (!$content) { $this->showPage(_('No notice content!')); return; } else { $content_shortened = common_shorten_links($content); if (mb_strlen($content_shortened) > 140) { $this->showPage(_('That\'s too long. Max notice size is 140 chars.')); return; } } $inter = new CommandInterpreter(); $cmd = $inter->handle_command($user, $content_shortened); if ($cmd) { // XXX fix this $cmd->execute(new WebChannel()); return; } $replyto = $this->trimmed('inreplyto'); $notice = Notice::saveNew($user->id, $content, 'Facebook', 1, $replyto == 'false' ? null : $replyto); if (is_string($notice)) { $this->showPage($notice); return; } common_broadcast_notice($notice); // Also update the user's Facebook status $this->updateFacebookStatus($notice); $this->updateProfileBox($notice); }
function update($args, $apidata) { parent::handle($args); if (!in_array($apidata['content-type'], array('xml', 'json'))) { $this->clientError(_('API method not found!'), $code = 404); return; } if ($_SERVER['REQUEST_METHOD'] != 'POST') { $this->clientError(_('This method requires a POST.'), 400, $apidata['content-type']); return; } $this->auth_user = $apidata['user']; $user = $this->auth_user; $status = $this->trimmed('status'); $source = $this->trimmed('source'); $in_reply_to_status_id = intval($this->trimmed('in_reply_to_status_id')); $reserved_sources = array('web', 'omb', 'mail', 'xmpp', 'api'); if (!$source || in_array($source, $reserved_sources)) { $source = 'api'; } if (!$status) { // XXX: Note: In this case, Twitter simply returns '200 OK' // No error is given, but the status is not posted to the // user's timeline. Seems bad. Shouldn't we throw an // errror? -- Zach return; } else { $status_shortened = common_shorten_links($status); if (mb_strlen($status_shortened) > 140) { // XXX: Twitter truncates anything over 140, flags the status // as "truncated." Sending this error may screw up some clients // that assume Twitter will truncate for them. Should we just // truncate too? -- Zach $this->clientError(_('That\'s too long. Max notice size is 140 chars.'), $code = 406, $apidata['content-type']); return; } } // Check for commands $inter = new CommandInterpreter(); $cmd = $inter->handle_command($user, $status_shortened); if ($cmd) { if ($this->supported($cmd)) { $cmd->execute(new Channel()); } // cmd not supported? Twitter just returns your latest status. // And, it returns your last status whether the cmd was successful // or not! $n = $user->getCurrentNotice(); $apidata['api_arg'] = $n->id; } else { $reply_to = null; if ($in_reply_to_status_id) { // check whether notice actually exists $reply = Notice::staticGet($in_reply_to_status_id); if ($reply) { $reply_to = $in_reply_to_status_id; } else { $this->clientError(_('Not found'), $code = 404, $apidata['content-type']); return; } } $notice = Notice::saveNew($user->id, html_entity_decode($status, ENT_NOQUOTES, 'UTF-8'), $source, 1, $reply_to); if (is_string($notice)) { $this->serverError($notice); return; } common_broadcast_notice($notice); $apidata['api_arg'] = $notice->id; } $this->show($args, $apidata); }
function add_notice($user, $msg) { // should test // $msg_shortened = common_shorten_links($msg); // if (mb_strlen($msg_shortened) > 140) ERROR and STOP $notice = Notice::saveNew($user->id, $msg, 'mail'); if (is_string($notice)) { $this->log(LOG_ERR, $notice); return; } common_broadcast_notice($notice); $this->log(LOG_INFO, 'Added notice ' . $notice->id . ' from user ' . $user->nickname); }