link.ajax.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Responses to AJAX calls
  5. */
  6. require_once '../global.inc.php';
  7. api_protect_course_script(true);
  8. $action = $_REQUEST['a'];
  9. switch ($action) {
  10. case 'check_url':
  11. if (api_is_allowed_to_edit(null, true)) {
  12. $url = $_REQUEST['url'];
  13. // Check if curl is available.
  14. if (!in_array('curl', get_loaded_extensions())) {
  15. echo '';
  16. exit;
  17. }
  18. // set URL and other appropriate options
  19. $defaults = array(
  20. CURLOPT_URL => $url,
  21. CURLOPT_FOLLOWLOCATION => true, // follow redirects accept youtube.com
  22. CURLOPT_HEADER => 0,
  23. CURLOPT_RETURNTRANSFER => true,
  24. CURLOPT_TIMEOUT => 4
  25. );
  26. //create a new cURL resource
  27. $ch = curl_init();
  28. curl_setopt_array($ch, $defaults);
  29. // grab URL and pass it to the browser
  30. $result = curl_exec($ch);
  31. // close cURL resource, and free up system resources
  32. curl_close($ch);
  33. if ($result) {
  34. echo Display::return_icon('accept.png', get_lang('Ok'));
  35. } else {
  36. echo Display::return_icon('wrong.gif', get_lang('Wrong'));
  37. }
  38. }
  39. break;
  40. default:
  41. echo '';
  42. }
  43. exit;