We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit 3d67fc07 authored by elleo's avatar elleo

Add support for anonymous radio streaming

Make the "listen" link available to non-logged in users
Fix the player on the welcome page
parent deca8122
......@@ -382,4 +382,30 @@ class Server {
return $rv;
}
/**
* Log in to the radio server
*
* @param string $station The station to be played
* @param string $username The user to associate this session with (optional)
* @return A string containing the session key to be used for streaming
*/
static function getRadioSession($station, $username = false) {
global $mdb2;
$session_id = md5(mt_rand() . time());
if($username) {
$sql = "INSERT INTO Radio_Sessions(username, session, url, expires) VALUES ("
. $mdb2->quote($username, "text") . ","
. $mdb2->quote($session_id, "text") . ","
. $mdb2->quote($station, "text") . ","
. $mdb2->quote(time() + 86400) . ")";
} else {
$sql = "INSERT INTO Radio_Sessions(session, url, expires) VALUES ("
. $mdb2->quote($session_id, "text") . ","
. $mdb2->quote($station, "text") . ","
. $mdb2->quote(time() + 86400) . ")";
}
$res = $mdb2->query($sql);
return $session_id;
}
}
......@@ -208,15 +208,7 @@ class User {
* @return A string containing the session key to be used for streaming
*/
function getRadioSession($station) {
global $mdb2;
$session_id = md5(mt_rand() . time());
$sql = "INSERT INTO Radio_Sessions(username, session, url, expires) VALUES ("
. $mdb2->quote($this->name, "text") . ","
. $mdb2->quote($session_id, "text") . ","
. $mdb2->quote($station, "text") . ","
. $mdb2->quote(time() + 86400) . ")";
$mdb2->query($sql);
return $session_id;
return Server::getRadioSession($station, $this->name);
}
/**
......
......@@ -26,6 +26,12 @@ require_once('data/Server.php');
$smarty->assign('welcome', true);
$smarty->assign("station", "rock");
$station = "librefm://globaltags/rock";
if(isset($this_user)) {
$radio_session = $this_user->getRadioSession($station);
} else {
$radio_session = Server::getRadioSession($station);
}
$smarty->assign("radio_session", $radio_session);
$smarty->display('welcome.tpl');
?>
......@@ -30,7 +30,12 @@ if (!PEAR::isError ($aTagCloud)) {
if(isset($_GET['tag'])) {
$station = "librefm://globaltags/" . $_GET['tag'];
$smarty->assign("station", $station);
if(isset($this_user)) {
$radio_session = $this_user->getRadioSession($station);
} else {
$radio_session = Server::getRadioSession($station);
}
$smarty->assign("radio_session", $radio_session);
}
$smarty->display("listen.tpl");
......
......@@ -2,18 +2,16 @@
<h2>Listen</h2><br />
{if isset($station)}
{if isset($this_user)}
{include file='player.tpl'}
{if isset($radio_session)}
{include file='player.tpl'}
<div id='error'></div>
<script type="text/javascript">
{if isset($this_user)}
playerInit(false, "{$this_user->getScrobbleSession()}", "{$this_user->getRadioSession($station)}");
{/if}
</script>
playerInit(false, "{$this_user->getScrobbleSession()}", "{$radio_session}");
{else}
<p>{t}Sorry, you need to <a href='{$base_url}/login.php'>login</a> to be able to listen to radio streams.{/t}</p>
playerInit(false, false, "{$radio_session}");
{/if}
</script>
{else}
<p>{t}To listen to 100% free (libre) music simply enter the type of music you'd like to hear or select one of the common tags below:{/t}</p>
<p><a href="?tag=folk">Folk</a> <a href="?tag=rock">Rock</a> <a href="?tag=metal">Metal</a> <a href="?tag=classical">Classical</a> <a href="?tag=pop">Pop</a> <a href="?tag=blues">Blues</a> <a href="?tag=jazz">Jazz</a> <a href="?tag=punk">Punk</a> <a href="?tag=ambient">Ambient</a></p>
......
<ul>
<ul>
{if ($logged_in)}
<li><a href="{$this_user->getURL()}">{$this_user->name}</a></li>
<li><a href="{$this_user->getURL()}">{$this_user->name}</a></li>
{else}
<li><a href="{$base_url}/register.php">{t}Register{/t}</a></li>
{/if}
{if ($logged_in)}
{if $this_user->userlevel > 0}
<li><a href="/admin.php">{t}Admin{/t}</a></li>
{/if}
{if $this_user->userlevel > 0}
<li><a href="/admin.php">{t}Admin{/t}</a></li>
{/if}
<li><a href="{$base_url}/login.php?action=logout">{t}Logout{/t}</a></li>
<li><a href="{$base_url}/listen.php">{t}Listen{/t}</a></li>
{else}
<li><a href="{$base_url}/login.php?return={$this_page|urlencode|htmlentities}">{t}Login{/t}</a></li>
{/if}
<li><a href="{$base_url}/listen.php">{t}Listen{/t}</a></li>
<li><a href="https://savannah.nongnu.org/bugs/?group=librefm">{t}Bugs{/t}</a></li>
<li><a href="http://ideas.libre.fm/index.php/Using_turtle">{t}Help{/t}</a></li>
</ul>
</ul>
......@@ -2,8 +2,8 @@
<audio id="audio">
{if $track->streamurl}
<object id="fallbackembed" style="width:200px;height:50px;" type="application/ogg" data="{$track->streamurl}"><a type="application/ogg" rel="enclosure" href="{$track->streamurl}">Listen to this track</a></object>
{elseif isset($station)}
<p>P{t}Sorry, you need a browser capable of making use of the HTML 5 &lt;audio&gt; tag to enjoy the streaming service via the JavaScript player.{/t}</p>
{elseif isset($radio_session)}
<p>{t escape=no}Sorry, you need a browser capable of making use of the HTML 5 &lt;audio&gt; tag to enjoy the streaming service via the JavaScript player.{/t}</p>
{/if}
</audio>
<div id="interface">
......
......@@ -25,37 +25,19 @@
</div>
<div class="yui-u">
<div id="radio">
<div id="player">
<div id="interface">
<div id="trackinfo">
<span id="artistname"></span> - <span id="trackname"></span> <span id="showplaylist"><a href="#" onclick="togglePlaylist()"><img src="{$base_url}/themes/librefm/images/player/show-playlist.png" alt="Show playlist" title="Show playlist" /></a></span><span id="hideplaylist"><a href="#" onclick="togglePlaylist()"><img src="{$base_url}/themes/librefm/images/player/hide-playlist.png" alt="Hide playlist" title="Hide playlist" /></a></span>
<div id="playlist">
<hr />
<strong><u>{t}Playlist{/t}</u></strong>
<ul id="songs">
</ul>
</div>
</div>
<div id="progress">
<div id="progressbar"></div>
<span id="currenttime"></span>/<span id="duration"></span>
</div>
<span id="scrobbled">Scrobbled</span>
<div id="buttons">
<a href="#" onclick="skipBack()" id="skipback"><img src="{$base_url}/themes/librefm/images/player/skip-backward.png" alt= "Skip Backwards" /></a>
<a href="#" onclick="seekBack()" id="seekback"><img src="{$base_url}/themes/librefm/images/player/seek-backward.png" alt="Seek Backwards" /></a>
<a href="#" onclick="play()" id="play"><img src="{$base_url}/themes/librefm/images/player/play.png" alt="Play" /></a>
<a href="#" onclick="pause()" id="pause"><img src="{$base_url}/themes/librefm/images/player/pause.png" alt="Pause" /></a>
<a href="#" onclick="seekForward()" id="seekforward"><img src="{$base_url}/themes/librefm/images/player/seek-forward.png" alt="Seek Forwards" /></a>
<a href="#" onclick="skipForward()" id="skipforward"><img src="{$base_url}/themes/librefm/images/player/skip-forward.png" alt="Skip Forwards" /></a>
</div>
</div>
</div>
<div id="radio">
{include file='player.tpl'}
</div>
<script type="text/javascript">
{if isset($this_user)}
playerInit(false, "{$this_user->getScrobbleSession()}", "{$radio_session}");
{else}
playerInit(false, false, "{$radio_session}");
{/if}
</script>
</div>
<div id="downloads">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment