link.ajax.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Responses to AJAX calls
  5. */
  6. require_once __DIR__.'/../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. ob_start();
  31. $result = curl_exec($ch);
  32. ob_get_clean();
  33. // close cURL resource, and free up system resources
  34. curl_close($ch);
  35. if ($result) {
  36. echo Display::return_icon(
  37. 'check-circle.png',
  38. get_lang('Ok'),
  39. null,
  40. ICON_SIZE_TINY
  41. );
  42. } else {
  43. echo Display::return_icon(
  44. 'closed-circle.png',
  45. get_lang('Wrong'),
  46. null,
  47. ICON_SIZE_TINY
  48. );
  49. }
  50. }
  51. break;
  52. default:
  53. echo '';
  54. }
  55. exit;