librefm-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Librefm-commits] [1462] Add support for anonymous radio streaming


From: Michael Sheldon
Subject: [Librefm-commits] [1462] Add support for anonymous radio streaming
Date: Sun, 10 May 2009 13:02:40 +0000

Revision: 1462
          http://svn.sv.gnu.org/viewvc/?view=rev&root=librefm&revision=1462
Author:   elleo
Date:     2009-05-10 13:02:40 +0000 (Sun, 10 May 2009)
Log Message:
-----------
Add support for anonymous radio streaming
Make the "listen" link available to non-logged in users
Fix the player on the welcome page

Modified Paths:
--------------
    trunk/nixtape/data/Server.php
    trunk/nixtape/data/User.php
    trunk/nixtape/index.php
    trunk/nixtape/listen.php
    trunk/nixtape/themes/librefm/templates/listen.tpl
    trunk/nixtape/themes/librefm/templates/menu.tpl
    trunk/nixtape/themes/librefm/templates/player.tpl
    trunk/nixtape/themes/librefm/templates/welcome.tpl

Modified: trunk/nixtape/data/Server.php
===================================================================
--- trunk/nixtape/data/Server.php       2009-05-10 09:54:09 UTC (rev 1461)
+++ trunk/nixtape/data/Server.php       2009-05-10 13:02:40 UTC (rev 1462)
@@ -382,4 +382,30 @@
                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;
+       }
+
 }

Modified: trunk/nixtape/data/User.php
===================================================================
--- trunk/nixtape/data/User.php 2009-05-10 09:54:09 UTC (rev 1461)
+++ trunk/nixtape/data/User.php 2009-05-10 13:02:40 UTC (rev 1462)
@@ -208,15 +208,7 @@
         * @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);
        }
 
        /**

Modified: trunk/nixtape/index.php
===================================================================
--- trunk/nixtape/index.php     2009-05-10 09:54:09 UTC (rev 1461)
+++ trunk/nixtape/index.php     2009-05-10 13:02:40 UTC (rev 1462)
@@ -26,6 +26,12 @@
 
 $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');
 ?>

Modified: trunk/nixtape/listen.php
===================================================================
--- trunk/nixtape/listen.php    2009-05-10 09:54:09 UTC (rev 1461)
+++ trunk/nixtape/listen.php    2009-05-10 13:02:40 UTC (rev 1462)
@@ -30,7 +30,12 @@
 
 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");

Modified: trunk/nixtape/themes/librefm/templates/listen.tpl
===================================================================
--- trunk/nixtape/themes/librefm/templates/listen.tpl   2009-05-10 09:54:09 UTC 
(rev 1461)
+++ trunk/nixtape/themes/librefm/templates/listen.tpl   2009-05-10 13:02:40 UTC 
(rev 1462)
@@ -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>

Modified: trunk/nixtape/themes/librefm/templates/menu.tpl
===================================================================
--- trunk/nixtape/themes/librefm/templates/menu.tpl     2009-05-10 09:54:09 UTC 
(rev 1461)
+++ trunk/nixtape/themes/librefm/templates/menu.tpl     2009-05-10 13:02:40 UTC 
(rev 1462)
@@ -1,19 +1,19 @@
-    <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>

Modified: trunk/nixtape/themes/librefm/templates/player.tpl
===================================================================
--- trunk/nixtape/themes/librefm/templates/player.tpl   2009-05-10 09:54:09 UTC 
(rev 1461)
+++ trunk/nixtape/themes/librefm/templates/player.tpl   2009-05-10 13:02:40 UTC 
(rev 1462)
@@ -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">

Modified: trunk/nixtape/themes/librefm/templates/welcome.tpl
===================================================================
--- trunk/nixtape/themes/librefm/templates/welcome.tpl  2009-05-10 09:54:09 UTC 
(rev 1461)
+++ trunk/nixtape/themes/librefm/templates/welcome.tpl  2009-05-10 13:02:40 UTC 
(rev 1462)
@@ -25,37 +25,19 @@
 </div>
     <div class="yui-u">
 
-    <div id="radio">
+       <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>
+               {include file='player.tpl'}
 
+               <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>
 
     <div id="downloads">
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]