/** * (Web service method) Submit vote for current track * @param mixed[] $args time_utc (YYYY-MM-DD); stream_title; value (-5 .. 5); nick; user_id; is_authed (0|1) * @return mixed[] status; error_message; output (what to announce in IRC chat room) */ private function web_post_vote($args) { $time_utc = $args['time_utc']; // YYYY-MM-DD HH:MM:SS $stream_title = $args['stream_title']; $nick = $args['nick']; $user_id = $args['user_id']; $is_authed = $args['is_authed']; $value_parts = explode(' ', $args['value'], 2); $value = str_replace(['[', ']', '{', '}', '"', '\''], '', $value_parts[0]); if (count($value_parts) == 1) { $comment = ''; } else { $comment = $value_parts[1]; } $opt = Options::get_instance(); if (is_numeric($value)) { $num = (int) $value; if ($num < -5 || $num > 5) { $num = FALSE; } } else { $num = FALSE; } if ($num === FALSE) { $this->fail($nick . ': Invalid vote value. Say "' . explode(' ', $opt->cmd_help)[0] . '" for help.'); } $track_id = Track::create_or_get_id($stream_title); if (!Track::is_recently_played($track_id)) { $this->fail($nick . ': "' . $stream_title . '" wasn\'t played recently!'); } $vote_id = Vote::get_recent_id($track_id, $nick); if ($vote_id) { Vote::delete($vote_id); $txt_vote_response = $opt->txt_revote_response; $priv = $opt->txt_revote_response_switch; } else { $txt_vote_response = $opt->txt_vote_response; $priv = $opt->txt_vote_response_switch; } Vote::new_vote($time_utc, $track_id, $stream_title, $num, $nick, $user_id, $is_authed, $comment); if ($num > 0) { $num_txt = '+' . $num; } else { $num_txt = (string) $num; } $out = str_ireplace('${stream_title}', $args['stream_title'], $txt_vote_response); $out = str_ireplace('${nick}', $nick, $out); $out = str_ireplace('${value}', $num_txt, $out); Track::update_vote($track_id); return array('status' => 'ok', 'error_message' => '', 'output' => $out, 'private' => $priv); }