See https://www.firebase.com/docs/rest/api/ for methods to access */ session_start(); error_reporting(E_ALL); // Workaround to getting AngularJS post data as $_REQUEST does not work $params = json_decode(file_get_contents('php://input'), true); $room = isset($params['room']) ? $params['room'] : isset($_REQUEST['room']) ? $_REQUEST['room'] : ''; // Connect to webchat to get token $cam4_webchat_url = "http://webchat.cam4.com/requestAccess?roomname=" . $room; try { $obj = curl_it($cam4_webchat_url); if (isset($obj['token'])) { $token = $obj['token']; $import_io_extractor_url = "https://api.import.io/store/connector/d449642d-6969-4df3-92c2-c71324b5548f/_query?input=webpage/url:http%3A%2F%2Fwww.cam4.com%2F" . $room . "&&_apikey=009709b75e614d4799af1403f3acaa884dbbb1c097366f504221fdb3c73b69057368743e61de127ae810cd55c2f92ee0cbd27125a9af044d43323c8f65a6c286f8674935dc940ab67af26c711fc9bbe3"; $obj = curl_it($import_io_extractor_url); if (isset($obj['results'][0])) { $result = (array) $obj['results'][0]; $cam4_firebase_server = $result['cam4firebasehost']; } else { die('{"success": false, "message": "import.io Failure"}'); } $cam4_firebase_url = $cam4_firebase_server . "chatRooms/" . $room . "/chatMessages.json?auth=" . $token; // This is all we need. Javascript can handle the rest! die('{"success": true, "url": "' . $cam4_firebase_url . '"}'); } else { die('{"success": false, "message": "No token generated"}'); } } catch (Exception $e) { // DB Failed die('{"success": false, "message": "' . $e . '"}');
$cam4_auth_url = "http://api.cam4.com/loginnonweb?app=COMMUNICATOR&username="******"&password="******"&deviceId=" . $deviceId; // Step 1 try { $obj = curl_it($cam4_auth_url); if (!isset($obj['details'])) { $token = $obj['accessHash']; } else { if ($obj['details'] == 'IpAddressNotKnown') { if (empty($answer)) { // Redirect to get question $cam4_security_url = 'security.php?username='******'&password='******'&deviceId=' . $deviceId; header('Location: ' . $cam4_security_url); exit; } else { $cam4_security_request = "http://api.cam4.com/loginsecurenonweb?app=COMMUNICATOR&username="******"&questionID=" . $questionid . "&answer=" . $answer . "&deviceId=" . $deviceId . "&token=" . $token; $obj = curl_it($cam4_security_request); if (isset($obj['token'])) { $token = $obj['token']; } else { // Something went wrong, maybe JSON will reveal it? die('{"success": false, "message": "Error fetching token"}'); } } } elseif ($obj['details'] == 'InvalidCredentials') { die('{"success": false, "message": "Login Failed"}'); } else { // Something went wrong die('{"success": false, "message": "' . $obj['details'] . '"}'); } } } catch (Exception $e) {
function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', $instance['title']); $ident = esc_attr($instance['ident']); $ident_type = esc_attr($instance['ident_type']); if ($ident_type == "playlist") { if (substr($ident, 0, 2) == "PL") { $ident = substr($ident, 2); } } $titles = esc_attr($instance['titles']); $num = esc_attr($instance['num_videos']); $autoplay = esc_attr($instance['autoplay']); $fil = esc_attr($instance['filter']); $width = esc_attr($instance['width']); $height = $width * 3 / 4; $key = "AI39si4egIgiaFaxxolUNjk1Iw4ip4GHWJMt44ZpnWXidiFLjlX1_kSwUYUI-bhtK9oW3bvZ7CFe7syG__AtokRmrTMDYHdXvA"; $vidid_url = ssl() . "://gdata.youtube.com/feeds/api/videos/{$ident}?v=2&key={$key}"; $username_url = ssl() . "://gdata.youtube.com/feeds/base/users/{$ident}/uploads?alt=rss&v=2&orderby=published&client=ytapi-youtube-profile&key={$key}"; $playlist_url = ssl() . "://gdata.youtube.com/feeds/api/playlists/{$ident}?v=2&key={$key}"; echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } $output = "<div id='youtube-sidebar-widget' data-url='{$playlist_url}'>\n\r"; $i = 1; if ($ident_type == "username") { $curl_r = curl_it($username_url); if ($simple_xml = simplexml_load_string($curl_r)) { $youtube_is_up = true; } else { $youtube_is_up = false; } /*echo "<pre>"; print_r($simple_xml); echo "</pre>";*/ if ($youtube_is_up) { $output .= "<ul>\n\r"; foreach ($simple_xml->channel->item as $item) { if ($fil) { if (strpos($item->description, $fil)) { if ($i <= $num) { $link = explode("/watch?v=", $item->link); $hash = explode("&", $link[1]); $img = ssl() . "://i2.ytimg.com/vi/{$hash['0']}/0.jpg"; if ($titles == "yes") { $output .= "<li id='{$hash['0']}' data-autoplay='{$autoplay}'><img src='{$img}' alt='{$item->title}' desc='" . strip_tags($item->description) . "' style='width:" . $width . "px;' /><div class='play_arrow' style='width:" . $width . "px; height: " . $height . "px; margin-top: -" . $height . "px;'></div>\n\r<a href='{$item->link}' style='width: " . $width . "px;'>{$item->title}</a>"; } else { $output .= "<li id='{$hash['0']}' data-autoplay='{$autoplay}'><img src='{$img}' alt='{$item->title}' desc='" . strip_tags($item->description) . "' style='width:" . $width . "px;' /><div class='play_arrow' style='width:" . $width . "px; height: " . $height . "px; margin-top: -" . $height . "px;'></div>\n\r"; } $i++; } else { break; } } } else { if ($i <= $num) { $link = explode("/watch?v=", $item->link); $hash = explode("&", $link[1]); $img = ssl() . "://i2.ytimg.com/vi/{$hash['0']}/0.jpg"; if ($titles == "yes") { $output .= "<li id='{$hash['0']}' data-autoplay='{$autoplay}'><img src='{$img}' alt='{$item->title}' desc='" . strip_tags($item->description) . "' style='width:" . $width . "px;' /><div class='play_arrow' style='width:" . $width . "px; height: " . $height . "px; margin-top: -" . $height . "px;'></div>\n\r<a href='{$item->uri}' style='width: " . $width . "px;'>{$item->title}</a>"; } else { $output .= "<li id='{$hash['0']}' data-autoplay='{$autoplay}'><img src='{$img}' alt='{$item->title}' desc='" . strip_tags($item->description) . "' style='width:" . $width . "px;' /><div class='play_arrow' style='width:" . $width . "px; height: " . $height . "px; margin-top: -" . $height . "px;'></div>\n\r"; } $i++; } else { break; } } } $output .= "</ul>\n\r"; } else { $output .= "<p class='ysw-unavailable'>Service Unavailable.</p>"; } } elseif ($ident_type == "vidid") { $curl_r = curl_it($vidid_url); if ($simple_xml = simplexml_load_string($curl_r)) { $youtube_is_up = true; } else { $youtube_is_up = false; } /*echo "<pre>"; print_r($simple_xml); echo "</pre>";*/ if ($youtube_is_up) { $output .= "<ul>\n\r"; $item = $simple_xml; if ($i <= $num) { $link = explode("watch?v=", $item->link['href']); $hash = explode("&", $link[1]); $img = ssl() . "://i2.ytimg.com/vi/{$hash['0']}/0.jpg"; if ($titles == "yes") { $output .= "<li id='{$hash['0']}' data-autoplay='{$autoplay}'><img src='{$img}' alt='{$item->title}' desc='" . strip_tags($item->description) . "' style='width:" . $width . "px;' /><div class='play_arrow' style='width:" . $width . "px; height: " . $height . "px; margin-top: -" . $height . "px;'></div>\n\r<a href='{$item->link}' style='width: " . $width . "px;'>{$item->title}</a>"; } else { $output .= "<li id='{$hash['0']}' data-autoplay='{$autoplay}'><img src='{$img}' alt='{$item->title}' desc='" . strip_tags($item->description) . "' style='width:" . $width . "px;' /><div class='play_arrow' style='width:" . $width . "px; height: " . $height . "px; margin-top: -" . $height . "px;'></div>\n\r"; } $i++; } else { break; } $output .= "</ul>\n\r"; } else { $output .= "<p class='ysw-unavailable'>Service Unavailable.</p>"; } } elseif ($ident_type == "playlist") { $curl_r = curl_it($playlist_url); if ($simple_xml = simplexml_load_string($curl_r)) { $youtube_is_up = true; } else { $youtube_is_up = false; } if ($youtube_is_up) { $output .= "<ul>\n\r"; foreach ($simple_xml->entry as $item) { foreach ($item->link as $link_url) { if ($link_url['type'] == "text/html" && $link_url['rel'] == "alternate") { if ($i <= $num) { $link = explode("/watch?v=", $link_url['href']); $hash = explode("&", $link[1]); $img = ssl() . "://i2.ytimg.com/vi/{$hash['0']}/0.jpg"; if ($titles == "yes") { $output .= "<li id='{$hash['0']}' data-autoplay='{$autoplay}'><img src='{$img}' alt='{$item->title}' desc='{$item->title}' style='width:" . $width . "px;' /><div class='play_arrow' style='width:" . $width . "px; height: " . $height . "px; margin-top: -" . $height . "px;'></div>\n\r<a href='{$item->link}' style='width: " . $width . "px;'>{$item->title}</a>"; } else { $output .= "<li id='{$hash['0']}' data-autoplay='{$autoplay}'><img src='{$img}' alt='{$item->title}' desc='{$item->title}' style='width:" . $width . "px;' /><div class='play_arrow' style='width:" . $width . "px; height: " . $height . "px; margin-top: -" . $height . "px;'></div>\n\r"; } $i++; } else { break; } } } } $output .= "</ul>\n\r"; } else { $output .= "<p class='ysw-unavailable'>Service Unavailable.</p>"; } } $output .= "</div>\n\r"; echo $output; echo $after_widget; }