+ exit;
+}
+
+function common_save_replies($notice) {
+ # Alternative reply format
+ if (preg_match('/^T ([A-Z0-9]{1,64}) /', $notice->content, $match)) {
+ $tname = $match[1];
+ }
+ # extract all @messages
+ $cnt = preg_match_all('/(?:^|\s)@([a-z0-9]{1,64})/', $notice->content, $match);
+ if (!$cnt && !$tname) {
+ return true;
+ }
+ # XXX: is there another way to make an array copy?
+ $names = ($tname) ? array_unique(array_merge(array(strtolower($tname)), $match[1])) : array_unique($match[1]);
+ $sender = Profile::staticGet($notice->profile_id);
+ # store replied only for first @ (what user/notice what the reply directed,
+ # we assume first @ is it)
+ for ($i=0; $i<count($names); $i++) {
+ $nickname = $names[$i];
+ $recipient = common_relative_profile($sender, $nickname, $notice->created);
+ if (!$recipient) {
+ continue;
+ }
+ if ($i == 0 && ($recipient->id != $sender->id)) { # Don't save reply to self
+ $reply_for = $recipient;
+ $recipient_notice = $reply_for->getCurrentNotice();
+ $orig = clone($notice);
+ $notice->reply_to = $recipient_notice->id;
+ $notice->update($orig);
+ }
+ $reply = new Reply();
+ $reply->notice_id = $notice->id;
+ $reply->profile_id = $recipient->id;
+ $id = $reply->insert();
+ if (!$id) {
+ $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError');
+ common_log(LOG_ERROR, 'DB error inserting reply: ' . $last_error->message);
+ common_server_error(sprintf(_('DB error inserting reply: %s'), $last_error->message));
+ return;
+ }
+ }