Only one lower score could be a glitch in reading the serial port. */ if ($newScore < $prevScore && $lowScoreFound == false) { $lowScoreFound = true; continue 1; } $lowScoreFound = false; // If a new game has started or the scores last changed 2 minutes ago if ($newScore < $prevScore || $lastScoreChange > 0 && time() - $lastScoreChange > 120) { $status = 'Score of ' . number_format($prevScore) . ' posted to ' . $config['machine']['name']; if ($prevScore > $prevHighScore) { $status = 'HIGH ' . $status; file_put_contents('scores.json', json_encode(array('highscore' => $prevScore), JSON_PRETTY_PRINT)); $prevHighScore = $prevScore; } if ($prevScore > $config['machine']['minimumScore']) { logIt('Tweet: ' . $status); $result = postTweet($config['OAuth'], $status); if (empty($result)) { logIt('Tweet not posted'); } } else { logIt('Score: ' . number_format($prevScore)); } $prevScore = 0; $lastScoreChange = 0; } else { $prevScore = $newScore; } } sleep(5); }
} include_once 'includes/functions_events.php'; include_once 'includes/functions_cast.php'; include_once 'includes/functions_twitter.php'; $action = "Failure"; $body = ""; $style = " panel-success"; $nextGameEvent = getNextEvent(false, 3600); $nextCastEvent = getNextEvent(true, 3600); $latestCast = getLatestCast(); $recentTweets = getRecentTweets(); // are we supplying tweet, message via POST? → send tweet if (isset($_POST['tweet']) and isset($_POST['message'])) { $action = "Post Tweet"; // set $body to a success or fail message $reply = postTweet($_POST['message']); // test reply here… if (array_key_exists('errors', $reply)) { $style = "panel-danger"; // TODO, do additional checks in the future. Ask admins to copy/paste the error $body = 'Error code ' . $reply['errors'][0]['code'] . ', with message: ' . $reply['errors'][0]['message'] . '<br>'; $body .= print_r($reply, true); $body .= "<br>Please copy/paste the above error, put it in a gist and share with webmaster."; } else { $body = 'Sent ‘' . $_POST['message'] . "’<br>\n"; $body .= print_r($reply, true); } } // are we supplying delete, key via POST? → delete tweet if (isset($_POST['delete']) and isset($_POST['key'])) { $action = "Delete Tweet";
// Make Requests $options = array(CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $postfields, CURLOPT_HEADER => false, CURLOPT_HTTPHEADER => $header, CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false); $feed = curl_init(); curl_setopt_array($feed, $options); $json = curl_exec($feed); curl_close($feed); return $json; } function buildBaseString($baseURI, $method, $params) { $r = array(); ksort($params); foreach ($params as $key => $value) { $r[] = "{$key}=" . rawurlencode($value); } return $method . "&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $r)); } function buildAuthorizationHeader($oauth) { $r = 'Authorization: OAuth '; $values = array(); foreach ($oauth as $key => $value) { if (substr($key, 0, 5) == "oauth") { $values[] = "{$key}=\"" . rawurlencode($value) . "\""; } } $r .= implode(', ', $values); return $r; } postTweet("V2, tweet avec image posté automatiquement depuis l'API PHP Twitter");