コード例 #1
0
 public function Process($message)
 {
     global $config;
     if (preg_match('%(?:youtube(?:-nocookie)?\\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\\.be/)([^"&?/ ]{11})%i', $message['message'], $match)) {
         if (!isset($match[1])) {
             throw new \InvalidArgumentException("Doesn't match youtube url");
         }
         $video_id = $match[1];
     }
     if (!isset($video_id)) {
         throw new \InvalidArgumentException("Doesn't match youtube url");
     }
     $youtubeinfo = $this->parseYoutubeInfo($video_id);
     if ($youtubeinfo['playable'] == false) {
         if ($youtubeinfo['embeddable'] == false) {
             return array("action" => "reply", "data" => array('msg' => 'This video is not added. The video is not embeddable. (traantjes2)', 'color' => 'red'));
         } else {
             if ($youtubeinfo['restriction'] == true) {
                 return array("action" => "reply", "data" => array('msg' => 'This video is not added. Belgium is not allowed. (traantjes2)', 'color' => 'red'));
             }
         }
     }
     // Load file that registers the last 10 video's.
     $fileName = 'data/youtubelinks.txt';
     if (file_exists($fileName)) {
         $fileContents = file_get_contents($fileName);
     } else {
         $fileContents = '';
     }
     // Make an array of the file's contents
     $lines = explode("\n", $fileContents);
     // Make sure the array of video's is only 10 items long
     while (count($lines) > 10) {
         array_shift($lines);
     }
     // Check if the current video id is in the last 10 lines
     if (in_array($video_id, $lines)) {
         return array("action" => "reply", "data" => array('msg' => 'This video was already queued in the last 10 songs. Spamming is bad, mkay.', 'color' => 'red'));
     }
     // Add current video to log
     $lines[] = $video_id;
     // Write file again.
     file_put_contents($fileName, implode("\n", $lines));
     makePost($config['radioUrl'] . 'add', ['link' => $message['message'], 'requestname' => $message['from']['name']]);
     return array("action" => "reply", "data" => array('msg' => 'Added "' . $youtubeinfo['title'] . '" to Radio Wizi', 'color' => 'green'));
 }
コード例 #2
0
ファイル: process.php プロジェクト: sennetorfs/radio-wizi
function getNewToken($id, $secret)
{
    $post = "grant_type=client_credentials&scope=send_notification";
    $ret = makePost("https://api.hipchat.com/v2/oauth/token", $post, $id, $secret);
    LogMe("getNewToken: {$ret}");
    $json = json_decode($ret);
    return $json;
}
コード例 #3
0
ファイル: install.php プロジェクト: sennetorfs/radio-wizi
<?php

require_once 'vendor/autoload.php';
$json = file_get_contents("php://input");
file_put_contents('/tmp/hipchat.txt', $json);
$auth["install"] = json_decode($json);
$arr = json_decode($json, true);
// id
$id = $arr["oauthId"];
$secret = $arr["oauthSecret"];
$url = $arr["capabilitiesUrl"];
// https://api.hipchat.com/v2/oauth/token
$post = "grant_type=client_credentials&scope=send_notification";
$ret = makePost("https://api.hipchat.com/v2/oauth/token", $post, $id, $secret);
file_put_contents('/tmp/hipchat.txt', $ret, FILE_APPEND);
$auth["token"] = json_decode($ret);
$auth["token"]->expires = time() + $auth["token"]->expires_in;
file_put_contents('data/auth/' . $auth["install"]->oauthId, json_encode($auth));
function makePost($url, $postData, $user = "", $pass = "")
{
    //open connection
    $ch = curl_init();
    //set the url, number of POST vars, POST data
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    //    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
    if ($user) {
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt($ch, CURLOPT_USERPWD, "{$user}:{$pass}");