index.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. // This script is part of the Sloodle project
  3. /*
  4. * This script is intended to be shown on the surface of the scoreboard.
  5. *
  6. */
  7. /**
  8. * @package sloodle
  9. * @copyright Copyright (c) 2011 various contributors (see below)
  10. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU GPL v3
  11. *
  12. * @contributor Edmund Edgar
  13. * @contributor Paul Preibisch
  14. *
  15. */
  16. /** Grab the Sloodle/Moodle configuration. */
  17. require_once('../../../init.php');
  18. /** Include the Sloodle PHP API. */
  19. /** Sloodle core library functionality */
  20. require_once(SLOODLE_DIRROOT.'/lib.php');
  21. require_once(SLOODLE_DIRROOT.'/lib/db.php');
  22. /** General Sloodle functions. */
  23. require_once(SLOODLE_LIBROOT.'/general.php');
  24. /** Sloodle course data. */
  25. require_once(SLOODLE_LIBROOT.'/course.php');
  26. require_once(SLOODLE_LIBROOT.'/io.php');
  27. require_once(SLOODLE_LIBROOT.'/object_configs.php');
  28. require_once(SLOODLE_LIBROOT.'/active_object.php');
  29. require_once(SLOODLE_LIBROOT.'/currency.php');
  30. $object_uuid = required_param('sloodleobjuuid', PARAM_RAW);
  31. $ao = new SloodleActiveObject();
  32. // Register the set using URL parameters
  33. if (!$ao->loadByUUID($object_uuid)) {
  34. print "Scoreboard no longer available.";
  35. exit;
  36. }
  37. $configs = $ao->config_name_value_hash();
  38. if ( !isset($configs['sloodleustreamchannel']) || $configs['sloodleustreamchannel'] == '') {
  39. print "Error: ustream channel not set";
  40. exit;
  41. }
  42. $channel = $configs['sloodleustreamchannel'];
  43. if ( !defined('SLOODLE_USTREAM_API_KEY') || (SLOODLE_USTREAM_API_KEY == '') ) {
  44. print "Error: No API key, could not get channel.";
  45. exit;
  46. }
  47. $url = 'http://api.ustream.tv/json/channel/'.urlencode($channel).'/getCustomEmbedTag?key='.SLOODLE_USTREAM_API_KEY.'&params=autoplay:true;mute:false;height:980;width:980';
  48. $ch = curl_init(); // initialize curl handle
  49. curl_setopt($ch, CURLOPT_URL, $url); // set url to post to
  50. curl_setopt($ch, CURLOPT_FAILONERROR,0);
  51. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
  52. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  53. $result = curl_exec($ch); // run the whole process
  54. $info = curl_getinfo($ch);
  55. curl_close($ch);
  56. $json = json_decode($result);
  57. if (!isset($json->results)) {
  58. print "Error: No stream available right now";
  59. exit;
  60. }
  61. $embed = $json->results;
  62. if ($embed == '') {
  63. print "Error: No stream available right now";
  64. exit;
  65. }
  66. print '<html>';
  67. print '<body style="background-color:black; border:0px; margin:0px; text-align:center; vertical-align:middle">';
  68. print '<div style="border:0px; background-color:black; text-align:center; vertical-align:middle; width:98%; height:98%">';
  69. print $embed;
  70. print '</div>';
  71. print '</body>';
  72. print '</html>';
  73. ?>