Tip: Click lines to highlight, hold ctrl/cmd to multi-select
Fresherplay Soundcloud Authentication (import.php) (13-Jan @ 18:43)
Syntax Highlighted Code
- <?php
- require_once 'oauth.php';
- require_once 'soundcloud.php';
- // Clear the session i.e delete all stored tokens.
- }
- // Change these four variables, note the that temporary path must be writable by the server.
- $consumer_key = '6Sg4X3oTeaq5U6qJGJehw';
- $consumer_secret = '6JBq9Qz2UHBMfSWS26tYx7jP6YUlW6DZqQxSMXENc2c';
- $callback_url = 'http://fresherplay.tk/';
- $tmp_path = 'temp/';
- // Variables used for verifying the status of the "OAuth dance".
- ? $_GET['oauth_verifier']
- ? $_SESSION['oauth_request_token']
- : NULL;
- ? $_SESSION['oauth_request_token_secret']
- : NULL;
- // Retreive access tokens if missing.
- $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);
- $mytracks = $soundcloud->request('me/tracks/');
- $mytracks = new SimpleXMLElement($mytracks);
- $x1 = $soundcloud->request('me/tracks/');
- $x1 = new SimpleXMLElement($x1);
- $x2 = $soundcloud->request('me/tracks/');
- $x2 = new SimpleXMLElement($x2);
- // If a track is submitted.
- // 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].
- 'aac' => 'video/mp4',
- 'aiff' => 'audio/x-aiff',
- 'flac' => 'audio/flac',
- 'mp3' => 'audio/mpeg',
- 'ogg' => 'audio/ogg',
- 'wav' => 'audio/x-wav'
- );
- : NULL;
- $tmp_file = $tmp_path . $_FILES['file']['name'];
- // Store the track temporary.
- 'track[sharing]' => 'private'
- );
- if ($response = $soundcloud->upload_track($post_data, $mime)) {
- $response = new SimpleXMLElement($response);
- $message = 'Success! <a href="' . $response['permalink-url'] . '">Your track</a> has been uploaded!';
- // Delete the temporary file.
- } else {
- $message = 'Something went wrong while talking to SoundCloud, please try again.';
- }
- } else {
- $message = 'Couldn\'t move file, make sure the temporary path is writable by the server.';
- }
- } else {
- $message = 'SoundCloud support .mp3, .aiff, .wav, .flac, .aac, and .ogg files. Please select a different file.';
- }
- }
- } else {
- // This is the first step in the "OAuth dance" where we ask the visitior to authicate himself.
- $soundcloud = new Soundcloud($consumer_key, $consumer_secret);
- $token = $soundcloud->get_request_token($callback_url)
- or die (" <h1>Could not connect to soundcloud via the api</h1> <br>Email fresherplay about this error <br>Use the back button to go back")
- ;
- $_SESSION['oauth_request_token'] = $token['oauth_token'];
- $_SESSION['oauth_request_token_secret'] = $token['oauth_token_secret'];
- $login = $soundcloud->get_authorize_url($token['oauth_token']);
- }
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <title>Fresherplay</title>
- <script type="text/javascript" src="jquery.js"></script>
- <script type="text/javascript" src="ui-core.js"></script>
- <script type="text/javascript" src="flash.js"></script>
- <script type="text/javascript" src="localscroll.js"></script>
- <script type="text/javascript" src="hide.js"></script>
- <script type='text/javascript' src='swfobject.js'></script>
- <SCRIPT LANGUAGE="JavaScript">
- <!-- Idea by: Nic Wolfe -->
- <!-- This script and many more are available free online at -->
- <!-- The JavaScript Source!! http://javascript.internet.com -->
- <!-- Begin
- function popUp(URL) {
- id = day.getTime();
- eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=528,height=158');");
- }
- // End -->
- </script>
- <script type="text/javascript">
- // Array variable to hold a list of all player IDs on the page
- var mediaPlayer = ['s1', 's2', 's3', 's4'];
- // Add a listener to trigger function stopOtherPlayers whenever an item is played
- function playerReady(obj) {
- document.getElementById(obj.id).addControllerListener('ITEM', 'stopOtherPlayers');
- }
- // Loop through all player IDs and, unless the player ID is the currently selected player ID, tell them to stop
- function stopOtherPlayers(obj) {
- for ( var id in mediaPlayer ) {
- if ( obj.id != mediaPlayer[id] ) document.getElementById(mediaPlayer[id]).sendEvent('STOP');
- }
- }
- </script>
- <link rel="stylesheet" type="text/css" href="stylesheet.css">
- </head>
- <body>
- <div class="headerpane" id="thetop">
- <img src="header.png" align="left" style="z-index: 3">
- </div>
- <div class="leftpane">
- <div class="menuhere"><div id="navcontainer">
- <ul id="navlist">
- <li id="active"><a>Import Music</a></li>
- <!-- <li id="sel4"><a>Email Fresherplay</a></li> -->
- </ul>
- </div>
- </div></div>
- </div>
- <div class="rightpane">
- <div class="content5" id="thechart">
- <div id="rev1">
- <font class="headline">Import Music from Soundcloud</font>
- <a class="button" href="<?php echo $login; ?>"><img src="sc-connect.png"></a>
- <img src="<?php echo $me['avatar-url']; ?>" width="75" height="75" alt="" align="left"/>
- <br>
- <br><a class="logout" href="?logout=true">logout from soundcloud</a><br>
- <?php endif; ?>
- <br>
- <?php
- echo "<table cellspacing=\"5\" cellpadding=\"5\">";
- foreach($x2 as $user){
- echo "<tr><td>";
- $numbera = $numbera +1;
- <!-- Address: '.$user->address.' -->
- <br />
- ';
- $stream2 = $user->xpath('stream-url');
- $perma2 = $user->xpath('permalink');
- //print_r($perma2);
- //echo "<b> $perma2[0] </b>";
- $stream3 = $stream2[0];
- $perma3 = $perma2[0];
- echo "
- <div id=\"YouTubeReloadedPlayer$numbera\">
- To play music on this website you need the Adobe Flash Plugin.
- <br><a href=\"http://www.adobe.com/go/EN_US-H-GET-FLASH\"><img src=\"getflash.png\"></a>
- </div>
- <script type='text/javascript'>
- var so = new SWFObject('player2/player.swf','mpl','470','55','9');
- so.addParam('allowfullscreen','true');
- so.addParam('allowscriptaccess','always');
- so.addParam('wmode','opaque');
- so.addVariable('file','$stream3');
- so.addVariable('provider','sound');
- so.write('YouTubeReloadedPlayer$numbera');
- </script>
- ";
- echo "
- </td>
- <td>
- <img src=\"upload.png\" height=\"60\" width=\"60\">
- <br><font size=\"-2\"><a href=\"import2.php?url=$stream4&permalink=$perma4\">Add to Fresherplay</a></font>
- </td>
- </tr>
- ";
- //print_r($x2->tracks->track);
- //print $x2->tracks->track->permalink-XXurl . "\n";
- /*
- foreach($x1->story as $story) {
- print("<h2>" . $story->headline . "</h2><br />");
- print($story->description . "<br />_________________________<br />");
- print($story->headline["date"] . "<br /><br />");
- }
- */
- //print_r($x1);
- //echo "<hr size=\"30\" color=\"#6633ff\">";
- //echo $x1->getName() . "<br />";
- //echo "<hr size=\"30\" color=\"#336633\">";
- foreach($x1->children() as $child)
- {
- //print_r($child);
- //echo $child->getName() . ": " . $child . "<br />";
- //echo "$child[title]";
- foreach($child->children() as $childx)
- {
- //echo ("$childx[0]" );
- /*
- */
- //echo $childx->getName() . ": " . $childx . "<br />";
- }
- //echo $child->getName() . ": " . $child . "<br />";
- //echo "<hr size=\"30\" bgcolor=\"#cc0000\" color=\"#cc0000\">";
- }
- //$myvar = $mytracks->[track]->uri;
- //print_r($);
- ?> <!-- <h2>Upload a new track</h2>
- <form action="" method="post" enctype="multipart/form-data">
- <p>
- <label for="title">Track title</label>
- <input class="text" type="text" name="title" id="title" />
- </p>
- <p>
- <label for="file">File</label>
- <input class="file" type="file" name="file" value="" id="file" />
- </p>
- <p class="center">
- <input class="submit" type="submit" name="submit" value="Upload" id="submit" />
- </p>
- </form>
- -->
- <div id="message">
- <p><?php echo $message; ?></p>
- </div>
- <?php endif; ?>
- <?php endif; ?>
- </div>
- </div>
- </div>
- </div> <!-- CLOSE content5 -->
- </div> <!-- CLOSE rightside -->
- <script type="text/javascript" src="//counter.goingup.com/js/tracker.js?st=bc4gyw7&b=5"></script>
- <noscript><a href="http://www.goingup.com" title=""><img src="//counter.goingup.com/default.php?st=bc4gyw7&b=5" border="0" /></a></noscript>
- </body>
- </html>
Plain Code
<?php
error_reporting(E_ALL);
require_once 'oauth.php';
require_once 'soundcloud.php';
session_start();
// Clear the session i.e delete all stored tokens.
if (isset($_GET['logout'])) {
session_destroy();
}
// Change these four variables, note the that temporary path must be writable by the server.
$consumer_key = '6Sg4X3oTeaq5U6qJGJehw';
$consumer_secret = '6JBq9Qz2UHBMfSWS26tYx7jP6YUlW6DZqQxSMXENc2c';
$callback_url = 'http://fresherplay.tk/';
$tmp_path = 'temp/';
// 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);
$mytracks = $soundcloud->request('me/tracks/');
$mytracks = new SimpleXMLElement($mytracks);
$mytracks = get_object_vars($mytracks);
$x1 = $soundcloud->request('me/tracks/');
$x1 = new SimpleXMLElement($x1);
$x2 = $soundcloud->request('me/tracks/');
$x2 = new SimpleXMLElement($x2);
// 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.
if (move_uploaded_file($_FILES['file']['tmp_name'], $tmp_file)) {
$post_data = array(
'track[title]' => stripslashes($_POST['title']),
'track[asset_data]' => realpath($tmp_file),
'track[sharing]' => 'private'
);
if ($response = $soundcloud->upload_track($post_data, $mime)) {
$response = new SimpleXMLElement($response);
$response = get_object_vars($response);
$message = 'Success! <a href="' . $response['permalink-url'] . '">Your track</a> has been uploaded!';
// Delete the temporary file.
unlink(realpath($tmp_file));
} else {
$message = 'Something went wrong while talking to SoundCloud, please try again.';
}
} else {
$message = 'Couldn\'t move file, make sure the temporary path is writable by the server.';
}
} else {
$message = 'SoundCloud support .mp3, .aiff, .wav, .flac, .aac, and .ogg files. Please select a different file.';
}
}
} else {
// This is the first step in the "OAuth dance" where we ask the visitior to authicate himself.
$soundcloud = new Soundcloud($consumer_key, $consumer_secret);
$token = $soundcloud->get_request_token($callback_url)
or die (" <h1>Could not connect to soundcloud via the api</h1> <br>Email fresherplay about this error <br>Use the back button to go back")
;
$_SESSION['oauth_request_token'] = $token['oauth_token'];
$_SESSION['oauth_request_token_secret'] = $token['oauth_token_secret'];
$login = $soundcloud->get_authorize_url($token['oauth_token']);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Fresherplay</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="ui-core.js"></script>
<script type="text/javascript" src="flash.js"></script>
<script type="text/javascript" src="localscroll.js"></script>
<script type="text/javascript" src="hide.js"></script>
<script type='text/javascript' src='swfobject.js'></script>
<SCRIPT LANGUAGE="JavaScript">
<!-- Idea by: Nic Wolfe -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=528,height=158');");
}
// End -->
</script>
<script type="text/javascript">
// Array variable to hold a list of all player IDs on the page
var mediaPlayer = ['s1', 's2', 's3', 's4'];
// Add a listener to trigger function stopOtherPlayers whenever an item is played
function playerReady(obj) {
document.getElementById(obj.id).addControllerListener('ITEM', 'stopOtherPlayers');
}
// Loop through all player IDs and, unless the player ID is the currently selected player ID, tell them to stop
function stopOtherPlayers(obj) {
for ( var id in mediaPlayer ) {
if ( obj.id != mediaPlayer[id] ) document.getElementById(mediaPlayer[id]).sendEvent('STOP');
}
}
</script>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
<div class="headerpane" id="thetop">
<img src="header.png" align="left" style="z-index: 3">
</div>
<div class="leftpane">
<div class="menuhere"><div id="navcontainer">
<ul id="navlist">
<li id="active"><a>Import Music</a></li>
<!-- <li id="sel4"><a>Email Fresherplay</a></li> -->
</ul>
</div>
</div></div>
</div>
<div class="rightpane">
<div class="content5" id="thechart">
<div id="rev1">
<font class="headline">Import Music from Soundcloud</font>
<?php if (isset($login)): ?>
<a class="button" href="<?php echo $login; ?>"><img src="sc-connect.png"></a>
<?php elseif (isset($me)): ?>
<img src="<?php echo $me['avatar-url']; ?>" width="75" height="75" alt="" align="left"/>
<a href="<?php echo $me['permalink-url']; ?>"><?php echo $me['permalink']; ?></a>
<br><?php echo $me['full-name'] ?>, <?php echo $me['city']; ?>, <?php echo $me['country']; ?></p>
<br>
<?php if (isset($me)): ?>
<br><a class="logout" href="?logout=true">logout from soundcloud</a><br>
<?php endif; ?>
<br>You have <?php echo $me['track-count']; ?> <?php echo ($me['track-count'] == 1) ? 'track' : 'tracks'; ?>.</p>
<br>
<?php
echo "<table cellspacing=\"5\" cellpadding=\"5\">";
foreach($x2 as $user){
echo "<tr><td>";
if (!isset($numbera)) {$number = "0";}
$numbera = $numbera +1;
echo '<img src="arrow.png" align="left">'.$user->title.'
<!-- Address: '.$user->address.' -->
<br />
';
$stream2 = $user->xpath('stream-url');
$perma2 = $user->xpath('permalink');
//print_r($perma2);
//echo "<b> $perma2[0] </b>";
$stream3 = $stream2[0];
$perma3 = $perma2[0];
$stream4 = urlencode($stream3);
$perma4 = urlencode($perma3);
echo "
<div id=\"YouTubeReloadedPlayer$numbera\">
To play music on this website you need the Adobe Flash Plugin.
<br><a href=\"http://www.adobe.com/go/EN_US-H-GET-FLASH\"><img src=\"getflash.png\"></a>
</div>
<script type='text/javascript'>
var so = new SWFObject('player2/player.swf','mpl','470','55','9');
so.addParam('allowfullscreen','true');
so.addParam('allowscriptaccess','always');
so.addParam('wmode','opaque');
so.addVariable('file','$stream3');
so.addVariable('provider','sound');
so.write('YouTubeReloadedPlayer$numbera');
</script>
";
echo "
</td>
<td>
<img src=\"upload.png\" height=\"60\" width=\"60\">
<br><font size=\"-2\"><a href=\"import2.php?url=$stream4&permalink=$perma4\">Add to Fresherplay</a></font>
</td>
</tr>
";
} echo "</table>";
//print_r($x2->tracks->track);
//print $x2->tracks->track->permalink-XXurl . "\n";
/*
foreach($x1->story as $story) {
print("<h2>" . $story->headline . "</h2><br />");
print($story->description . "<br />_________________________<br />");
print($story->headline["date"] . "<br /><br />");
}
*/
//print_r($x1);
//echo "<hr size=\"30\" color=\"#6633ff\">";
//echo $x1->getName() . "<br />";
//echo "<hr size=\"30\" color=\"#336633\">";
foreach($x1->children() as $child)
{
//print_r($child);
//echo $child->getName() . ": " . $child . "<br />";
//echo "$child[title]";
foreach($child->children() as $childx)
{
//echo ("$childx[0]" );
/*
*/
//echo $childx->getName() . ": " . $childx . "<br />";
}
print($child[tracks][track]);
//echo $child->getName() . ": " . $child . "<br />";
//echo "<hr size=\"30\" bgcolor=\"#cc0000\" color=\"#cc0000\">";
}
//$myvar = $mytracks->[track]->uri;
//print_r($);
?> <!-- <h2>Upload a new track</h2>
<form action="" method="post" enctype="multipart/form-data">
<p>
<label for="title">Track title</label>
<input class="text" type="text" name="title" id="title" />
</p>
<p>
<label for="file">File</label>
<input class="file" type="file" name="file" value="" id="file" />
</p>
<p class="center">
<input class="submit" type="submit" name="submit" value="Upload" id="submit" />
</p>
</form>
-->
<?php if (isset($message)): ?>
<div id="message">
<p><?php echo $message; ?></p>
</div>
<?php endif; ?>
<?php endif; ?>
</div>
</div>
</div>
</div> <!-- CLOSE content5 -->
</div> <!-- CLOSE rightside -->
<script type="text/javascript" src="//counter.goingup.com/js/tracker.js?st=bc4gyw7&b=5"></script>
<noscript><a href="http://www.goingup.com" title=""><img src="//counter.goingup.com/default.php?st=bc4gyw7&b=5" border="0" /></a></noscript>
</body>
</html>