api.php 887 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. require_once "misc/search_engine.php";
  3. require_once "locale/localization.php";
  4. $opts = load_opts();
  5. if ($opts->disable_api) {
  6. echo "<p>" . TEXTS["api_unavailable"] . "</p>";
  7. die();
  8. }
  9. require_once "misc/tools.php";
  10. if (!$opts->query) {
  11. echo "<p>Example API request: <a href=\"./api.php?q=gentoo&p=2&t=0\">./api.php?q=gentoo&p=2&t=0</a></p>
  12. <br/>
  13. <p>\"q\" is the keyword</p>
  14. <p>\"p\" is the result page (the first page is 0)</p>
  15. <p>\"t\" is the search type (0=text, 1=image, 2=video, 3=torrent, 4=tor)</p>
  16. <br/>
  17. <p>The results are going to be in JSON format.</p>
  18. <p>The API supports both POST and GET requests.</p>";
  19. die();
  20. }
  21. $results = fetch_search_results($opts, false);
  22. header("Content-Type: application/json");
  23. echo json_encode($results);
  24. ?>