diff --git a/functions.php b/functions.php index 62fd3cf..eb49c93 100644 --- a/functions.php +++ b/functions.php @@ -52,8 +52,10 @@ /** Constants */ define('HOME_PAGE_ID', 2); +define('DEBUG_CURL', FALSE); /** Custom actions */ require_once( 'library/actions.php' ); -require_once( 'getlatestvids.php' ); +require_once( 'getLatestVids.php' ); +require_once( 'getTwitchStream.php' ); diff --git a/getTwitchStream.php b/getTwitchStream.php new file mode 100644 index 0000000..c905dc6 --- /dev/null +++ b/getTwitchStream.php @@ -0,0 +1,34 @@ + 'GET', + 'callback' => 'getTwitchStream', + )); +}); + + +function getTwitchStream($data) { + $twitch_client_id = get_field('twitch-api-key', HOME_PAGE_ID); + $curl = curl_init(); + if (DEBUG_CURL) { + curl_setopt($curl, CURLOPT_VERBOSE, true); + $verbose = fopen('php://temp', 'w+'); + curl_setopt($curl, CURLOPT_STDERR, $verbose); + } + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($curl, CURLOPT_URL, 'https://api.twitch.tv/kraken/streams/accropolis'); + curl_setopt($curl, CURLOPT_HTTPHEADER, array("Client-ID: $twitch_client_id")); + curl_setopt($curl, CURLOPT_RETURNTRANSFER , TRUE); + $res = curl_exec($curl); + if (DEBUG_CURL) { + if ($result === FALSE) { + printf("cUrl error (#%d): %s
\n", curl_errno($curl), + htmlspecialchars(curl_error($curl))); + } + rewind($verbose); + $verboseLog = stream_get_contents($verbose); + echo "Verbose information:\n
", htmlspecialchars($verboseLog), "
\n"; + } + curl_close($curl); + return json_decode($res); +}