Exemplo n.º 1
0
// Variables used for verifying the status of the "OAuth dance".
$oauth_token = isset($_GET['oauth_verifier']) ? $_GET['oauth_verifier'] : (isset($_SESSION['oauth_access_token']) ? $_SESSION['oauth_access_token'] : NULL);
$oauth_request_token = isset($_SESSION['oauth_request_token']) ? $_SESSION['oauth_request_token'] : NULL;
$oauth_request_token_secret = isset($_SESSION['oauth_request_token_secret']) ? $_SESSION['oauth_request_token_secret'] : NULL;
if (isset($oauth_token) && isset($oauth_request_token) && isset($oauth_request_token_secret)) {
    // Retreive access tokens if missing.
    if (!isset($_SESSION['oauth_access_token']) && !isset($_SESSION['oauth_access_token_secret'])) {
        $soundcloud = new Soundcloud($consumer_key, $consumer_secret, $_SESSION['oauth_request_token'], $_SESSION['oauth_request_token_secret']);
        $token = $soundcloud->get_access_token($oauth_token);
        $_SESSION['oauth_access_token'] = $token['oauth_token'];
        $_SESSION['oauth_access_token_secret'] = $token['oauth_token_secret'];
    }
    // Construct a fully authicated connection with SoundCloud.
    $soundcloud = new Soundcloud($consumer_key, $consumer_secret, $_SESSION['oauth_access_token'], $_SESSION['oauth_access_token_secret']);
    // Get basic info about the authicated visitor.
    $me = $soundcloud->request('me');
    $me = new SimpleXMLElement($me);
    $me = get_object_vars($me);
    // If a track is submitted.
    if (isset($_POST['submit'])) {
        // We have to make sure it's a valid and supported format by SoundCloud.
        // Note that you also can include artwork for your tracks. Use the same
        // procedure as for the tracks. PNG, JPG, GIF allowed and a max size of 5MB.
        // The artwork field is called track[artwork_data].
        $mimes = array('aac' => 'video/mp4', 'aiff' => 'audio/x-aiff', 'flac' => 'audio/flac', 'mp3' => 'audio/mpeg', 'ogg' => 'audio/ogg', 'wav' => 'audio/x-wav');
        $extension = explode('.', $_FILES['file']['name']);
        $extension = isset($extension[count($extension) - 1]) ? $extension[count($extension) - 1] : NULL;
        $mime = isset($mimes[$extension]) ? $mimes[$extension] : NULL;
        if (isset($mime)) {
            $tmp_file = $tmp_path . $_FILES['file']['name'];
            // Store the track temporary.