function do_purge_tweets(array $querybin, $dt_start, $dt_end) { // Purge tweets $num_del = tweet_purge($querybin, $dt_start, $dt_end); // Show result $response_mediatype = choose_mediatype(['application/json', 'text/html']); switch ($response_mediatype) { case 'application/json': respond_with_json(['purge-tweets' => $num_del]); break; case 'text/html': $script_url = $_SERVER['SCRIPT_URL']; $components = explode('/', $script_url); array_pop($components); $query_bin_info = implode('/', $components); array_pop($components); $query_bin_list = implode('/', $components); html_begin("Query bin tweets: {$querybin['bin']}: purge", [["Query Bins", $query_bin_list], [$querybin['bin'], $query_bin_info], ["Purge"]]); $hB = isset($dt_end) ? dt_format_html($dt_end) : ""; if (isset($dt_start)) { $hA = dt_format_html($dt_start); if (isset($dt_end)) { $dt_desc_html = "tweets from {$hA} to {$hB}"; } else { $dt_desc_html = "tweets from {$hA} to last tweet"; } } else { if (isset($dt_end)) { $dt_desc_html = "tweets from first tweet to {$hB}"; } else { $dt_desc_html = "all tweets"; } } echo <<<END <p>Purged {$dt_desc_html}.</p> <p>Number of tweets deleted: {$num_del['tweets']}</p> END; html_end(); break; default: print "{$num_del['tweets']} tweets purged from {$querybin['bin']}\n"; foreach ($num_del as $name => $num) { print " Table {$name}: {$num} rows deleted\n"; } break; } }
<?php require_once __DIR__ . '/lib/common.php'; require_once __DIR__ . '/lib/http_util.php'; switch (choose_mediatype(['text/html'])) { case 'text/html': html_begin("API", []); echo <<<END <ul> <li><a href="querybin.php">List query bins</a></li> </ul> END; echo "<p>Version: ", API_VERSION, "</p>\n"; html_end(); break; default: echo "DMI-TCAT API (version: ", API_VERSION, ")\n"; echo " Running this script from the command line does nothing useful!\n"; echo " Run \"php querybin.php --help\" instead.\n"; exit(1); break; }