[ PHPXref.com ] [ Generated: Sun Jul 20 16:26:46 2008 ] [ Agatha 0.7.3 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/ -> agatha.php (source)

   1  <?php
   2  /*
   3  
   4      Copyright 2001, 2002, 2003, 2004 Jared Watkins <jared at @ watkins dot net>
   5      All rights reserved, All Responsibility Yours
   6      This program is distributed under the terms of the GNU General Public License
   7  
   8      Agatha is free software; you can redistribute it and/or modify
   9      it under the terms of the GNU General Public License as published by
  10      the Free Software Foundation; either version 2 of the License, or
  11      (at your option) any later version.
  12  
  13      This program is distributed in the hope that it will be useful,
  14      but WITHOUT ANY WARRANTY; without even the implied warranty of
  15      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16      GNU General Public License for more details.
  17  
  18      You should have received a copy of the GNU General Public License
  19      along with this program; if not, write to the Free Software
  20      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  21  
  22  */
  23  
  24  $LANG["error_no_config"] = "No Config File Found<br>.
  25                              Copy config.php.dist to config.php and put in your path and language choices";
  26  
  27  if(file_exists("config.php")) require("config.php");
  28    else {
  29       error($LANG["error_no_config"]);
  30       exit;
  31  }
  32  
  33  /* Check Input For Bad Stuff ******************************************/
  34  
  35  #    require_once("paranoia.inc.php");
  36  #    if (isset($_REQUEST)&&!empty($_REQUEST)){
  37  #        $par=new paranoia($_REQUEST);
  38  #        if (!empty($par->wrongParams)) {
  39  #            error("There Were Invalid Characters In Your Request");
  40  #        }
  41  #    }
  42  
  43  /* Build BASE_URL ******************************************************/
  44  
  45      if (!isset($_REQUEST["play"]) || !isset($_REQUEST["selected"])) {
  46          $BASE_URL = $CONFIG["request_method"].$_SERVER["HTTP_HOST"].$_SERVER["SCRIPT_NAME"];
  47      } else {
  48          $BASE_URL = "http://zuricon.com/".$_SERVER["SCRIPT_NAME"];
  49  
  50      }
  51  
  52  
  53  /* Deal With Cookies ***************************************************/
  54  
  55  
  56      if (isset($_GET["mycookie"])) {
  57          header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"');
  58          setcookie("uniqueid", $_GET["mycookie"], time()+157680000); // Plus 5 Years
  59          $uniqueid = $_GET["mycookie"];
  60          echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"2;URL=$BASE_URL\">";
  61          echo $LANG["cookie_is_set"];
  62          exit;
  63      }
  64  
  65      if (isset($_GET["uniqueid"]) && isset($_GET["nextsong"])) {
  66          if (DEBUG) error_log("Inbound playlist req :$uniqueid: ".$_SERVER["HTTP_USER_AGENT"]);
  67      } elseif (!isset($_COOKIE["uniqueid"])) {
  68          header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"');
  69          $token = md5(uniqid(time()));
  70          $better_token = md5(uniqid(rand(),1));
  71          setcookie("uniqueid", $better_token, time()+157680000);
  72          $uniqueid = $better_token;
  73          if(DEBUG) error_log("Setting cookie :$uniqueid: ".$_SERVER["HTTP_USER_AGENT"]);
  74      } else {
  75          $uniqueid = $_COOKIE["uniqueid"];
  76          if(DEBUG) error_log("Using cookie :$uniqueid: ".$_SERVER["HTTP_USER_AGENT"]);
  77      }
  78  
  79  
  80  /* Initialize Vars *****************************************************/
  81  
  82      $LANG = array();
  83      $dir_list = array();
  84      $file_list = array();
  85      $playlist_list = array();
  86      $sharedplaylist_list = array();
  87      $rdirs = array();
  88      $listing = array(); // master list of current dirs and files
  89  
  90      require_once ('id3.class.php');
  91  
  92      // Language selection
  93      if (isset($CONFIG["option_language"])) {
  94          include("lang/".$CONFIG["option_language"]);
  95      }   else include ("lang/agatha-us-en.php");
  96  
  97  
  98  /* Process Incoming GET/POST Requests *******************************************/
  99  
 100  
 101      if (!isset($_REQUEST["pdir"])) {      # If you are hitting the first page there is no parent dir
 102          $pdir = "/";                      # So set it to /
 103          $pdir_64 = $pdir;
 104  
 105      } else if ($_REQUEST["pdir"] != "/") {
 106          $pdir_64 = $_REQUEST["pdir"];
 107          $pdir = stripslashes(base64_decode($_REQUEST["pdir"]));   # Convert from base64 if you do have one..
 108      }
 109  
 110  
 111      if (isset($_GET["cdir"])) {                  # If changing directories LEAVE AS GET!
 112          #if (is_numeric($_REQUEST["cdir"])) {
 113          #    read_dir($pdir);
 114          #    $pdir = $pdir.$dir_list[$_GET["cdir"]];
 115          #    if(DEBUG) error_log("Changing directorys $_GET[cdir]",0);
 116          #
 117          #    unset($file_list); unset($dir_list);
 118          #    $dir_list=array(); $file_list=array();
 119          #
 120          #    read_dir($pdir); # If there are no files and only 1 dir.. change into it without asking
 121          #
 122          #    if ((count($file_list) == 0) && (count($dir_list) == 1)) {
 123          #         $pdir = "$pdir$dir_list[0]";
 124          #    }
 125          #    unset($file_list); unset($dir_list);
 126          #    $dir_list=array(); $file_list=array();
 127          #} else {
 128              $cdir = base64_decode($_REQUEST["cdir"]);
 129  
 130              $mydir = new mydir(BASE_DIR.$pdir.$cdir);
 131              $listing = $mydir->getentries();
 132  
 133              if (($listing["files"]["count"] == 0) && ($listing["directories"]["count"] == 1)) {
 134                  $pdir = $pdir.$cdir.$listing["directories"][0];
 135              } else $pdir = $pdir.$cdir;
 136              if (DEBUG) error_log("pdir :$pdir: cdir :$cdir:", 0);
 137          //}
 138      }
 139  
 140  
 141  
 142  /*****************************************************************************
 143     If you want to embed agatha in another page you have to do two things.    *
 144     First.. on the first line of the page you need to put this in your file:  *
 145     <? include("agatha.php"); ?>                                              *
 146                                                                               *
 147     Second.. where you want agatha to appear in the page (remember the output *
 148     can be quite long) you simply add this:                                   *
 149     <? activate_agatha(); ?>                                                  *
 150                                                                               *
 151     Finally.. you need to set the config item for 'embeded' to equal 1        *
 152                                                                               *
 153     It's that simple...                                                       *
 154                                                                               *
 155     Klingon function calls do not have 'parameters' - they have 'arguments'   *
 156       - and they ALWAYS WIN THEM.                                             *
 157                                                                               *
 158  ******************************************************************************/
 159  
 160  #if($CONFIG["embeded"] != 1) activate_agatha();
 161  
 162  
 163  /**************************************************************************************/
 164  
 165  #function activate_agatha() {
 166  #global $CONFIG;
 167  
 168  #convert_playlists();
 169  
 170  if(isset($_GET["play"])) play_single();
 171  elseif(isset($_REQUEST["playrecursive"])) playrecursive($pdir, $_REQUEST["playrecursive"]);
 172  elseif(isset($_GET["stream"])) stream();
 173  elseif(isset($_GET["pl"])) play_playlist();
 174  elseif(isset($_POST["pladd"])) playlist_add();
 175  elseif(isset($_REQUEST["pledit"])) playlist_edit();
 176  elseif(isset($_REQUEST["selected"])) play_multiple($_REQUEST["selected"]);
 177  else display_listing();
 178  
 179  #}
 180  
 181  /**************************************************************************************/
 182  
 183  
 184  
 185  function playrecursive($pdir, $targetdir) {
 186      global $CONFIG, $rdirs, $listing;
 187      if (DEBUG) error_log("playrecursive= Enter Function", 0);
 188  
 189      $targetdir = base64_decode($targetdir);
 190  
 191      // Writes back to the global rdirs variable
 192      recurse(BASE_DIR . $pdir . $targetdir);
 193      play_multiple($rdirs);
 194  }
 195  
 196  // Pass in the starting directory.. will update the global array called rdirs
 197  function recurse($file_dir) {
 198          global $rdirs;
 199  
 200          if ($handle = @opendir($file_dir))
 201          {
 202                  $i=0;
 203                  while (false !== ($file = @readdir($handle)))
 204                  {
 205                          if ($file != "." && $file != "..")
 206                          {
 207                                  $list[$i] = $file;
 208                                  $i++;
 209                          }
 210                  }
 211                  $dir_length = count($list);
 212                  #echo "<ul>";
 213                  for($i=0;$i<$dir_length;$i++)
 214                  {
 215                          if(strrpos($list[$i], ".") == FALSE)
 216                          {
 217                                  #echo "<li>".$list[$i]."/</li>\n";
 218                                  recurse($file_dir."/".$list[$i]);
 219                          }
 220                          else
 221                          {
 222                                  #echo "<li><a href=\"".$file_dir."/".$list[$i]."\">".$list[$i]."</a></li>\n";
 223                                  $tmp = str_replace('//', '/', $file_dir."/".$list[$i]);
 224                                  $tmp2 = base64_encode(str_replace(BASE_DIR, '', $tmp));
 225                                  array_push($rdirs, $tmp2);
 226  
 227                          }
 228                  }
 229                  #echo "</ul>";
 230                  closedir($handle);
 231          }
 232  
 233  }
 234  
 235  
 236  /*
 237  function convert_playlists() {
 238    global $CONFIG, $LANG, $uniqueid, $DEBUG;
 239  
 240    $c=0;
 241    $d = opendir(PLAYLIST_DIR);
 242      while($raw_list[$c]=readdir($d)) {
 243        if($raw_list[$c] == "." || $raw_list[$c]==".." || $raw_list[$c]=="index.php") continue;
 244        if($_SERVER["REMOTE_ADDR"] == substr($raw_list[$c], 0, -2)) {
 245          copy(PLAYLIST_DIR.$raw_list[$c], PLAYLIST_DIR.$raw_list[$c].".bak");
 246          $pl_number = substr($raw_list[$c], -1);
 247          if(DEBUG) error_log("convert_playlists= uniqueid :$uniqueid:",0);
 248          rename(PLAYLIST_DIR.$raw_list[$c], PLAYLIST_DIR."$uniqueid.$pl_number");
 249          chmod(PLAYLIST_DIR."$uniqueid.$pl_number", 0600);
 250          chmod(PLAYLIST_DIR.$raw_list[$c].".bak", 0600);
 251        }
 252      }
 253  }
 254  */
 255  
 256  /**************************************************************************************/
 257  
 258  
 259  function draw_dirnav_bar() {
 260     global $BASE_URL, $pdir_64, $pdir, $LANG, $CONFIG;
 261  
 262     $path = split("/", $pdir);
 263     echo "<DIV id=layer_dirnav class=dirnav><A href=\"$BASE_URL\">(".$LANG["top"].")</A> / ";
 264     if (count($path) > 2) {
 265         $parent = null;
 266         $max = count($path)-1;
 267  
 268         for ($i=1; $i < count($path)-1; $i++) {
 269  
 270              #if ($i < $max) $parent .= $path[$i-1]."/";
 271              #$parent_enc = base64_encode($parent);
 272              #$dir_enc = base64_encode($path[$i]);
 273              #echo "<A href=\"$BASE_URL?cdir=$dir_enc&pdir=$parent_enc\">$path[$i]</a> / ";
 274              echo "$path[$i] / ";
 275         }
 276     }
 277  
 278     echo "<br><br><A href=\"$BASE_URL?mycookie=".$_COOKIE["uniqueid"]."\"><font size=-2>".$LANG["copy_my_cookie"]."</font></A> <img title=\"".$LANG["help_cookie"]."\" align=middle border=0 src=images/agatha_help_ico.png><br>\n";
 279     echo "</DIV>\n";
 280  }
 281  
 282  
 283  /**************************************************************************************/
 284  
 285  
 286  function display_listing() {
 287  
 288    global $CONFIG, $BASE_URL, $LANG, $pdir, $file_list, $dir_list, $playlist_list;
 289    $pdir_64 = base64_encode($pdir);
 290    read_dir($pdir);
 291    read_playlists(PLAYLIST_DIR, $playlist_list);
 292    $sharedplaylist_list = read_shared_playlists();
 293  
 294    $mydir = new mydir(BASE_DIR . $pdir . $cdir);
 295    $listing = $mydir->getentries();
 296  
 297  
 298    echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
 299    echo "<html>\n";
 300    echo "<head>\n";
 301    echo "<meta http-equiv=\"Content-Type\" content=\"text/html;\" charset=\"utf-8\">";
 302    echo "<SCRIPT Language=\"Javascript\">\n";
 303    echo "  function SelectMost() {\n";
 304    echo "    for(var i=0; i < document.forms.songs.elements.length; i++) {\n";
 305    echo "      if(document.forms.songs.elements[i].type == \"checkbox\"  && document.forms.songs.elements[i].name != document.forms.songs.pladd.name) {\n";
 306    echo "        document.forms.songs.elements[i].checked = true;\n";
 307    echo "      }\n    }\n  }\n</SCRIPT>\n";
 308    echo "<title>$pdir - Agatha</title>\n";
 309    echo "<link href=\"agatha.css\" rel=\"stylesheet\" type=\"text/css\" >\n";
 310    echo "</head><body>\n\n";
 311  
 312  
 313    draw_dirnav_bar();
 314  
 315    echo "<form name=\"songs\" id=\"songs\" method=post action=\"$BASE_URL\">\n";
 316  
 317    if ($listing["directories"]["count"] > 0) {
 318  
 319        echo "<DIV class=\"category\"><A href=\"javascript:history.go(-1)\"><-".$LANG["back"].") </A> ".$LANG["subdirectories"] .":</DIV>\n";
 320        echo "<DIV class=\"directory\">\n";
 321        for ($d=0; $d < $listing["directories"]["count"]; $d++) {
 322             $cdir_64 = base64_encode($listing["directories"][$d]);
 323  
 324             $dir_name_display = ereg_replace("_", " ", substr($listing["directories"][$d],0,-1));
 325             $change_dir_link = "<A href=\"$BASE_URL?cdir=$cdir_64&#38;pdir=$pdir_64\">$dir_name_display</A>";
 326             $recursive_dir_play_link = "<A href=\"$BASE_URL?playrecursive=$cdir_64&#38;pdir=$pdir_64\">\t<img border=\"0\" title=\"$LANG[play_recursive]\" src=\"images/dir.gif\"></A>";
 327             if ($CONFIG["option_local_play"]) $recursive_local_play_link = "<a target=\"localplay\" href=\"mp3daemon.php?pdir=$pdir_64&#38;action=playrecursive&#38;playaction=$cdir_64\"> <img title=\"". $LANG["play_on_server"] ."\" align=\"bottom\" border=\"0\" title=\"". $LANG["local"] ."\" height=\"13\" src=\"images/agatha-localplay.png\"></a>&nbsp;";
 328                 else $recursive_local_play_link = null;
 329  
 330             echo "$recursive_dir_play_link $recursive_local_play_link $change_dir_link<br>\n";
 331        }
 332        echo "</DIV>\n\n";
 333    }
 334  
 335    if (count($sharedplaylist_list) > 0) {
 336  
 337        for ($r=0; $r < sizeof($sharedplaylist_list); $r++) {
 338             $listid = split("\.", $sharedplaylist_list[$r]);  // No need to list your own if they are shared
 339             if ($listid[0] == $_COOKIE["uniqueid"]) {
 340                 continue;
 341             } else $print_header = true;
 342        }
 343  
 344        if ($print_header == true) {
 345            echo "<DIV class=category><A href=\"javascript:history.go(-1)\"><-".$LANG["back"].") </A> Shared ". $LANG["playlists"] .":</DIV>\n";
 346            echo "<DIV class=\"playlist\">\n";
 347        }
 348  
 349        for ($r=0; $r < sizeof($sharedplaylist_list); $r++) {
 350             $listid = split("\.", $sharedplaylist_list[$r]);  // No need to list your own if they are shared
 351             if ($listid[0] == $_COOKIE["uniqueid"]) continue;
 352  
 353             $fp = fopen(SHAREDPLAYLIST_DIR.$sharedplaylist_list[$r], "r");
 354             $list_name = fgets($fp, 1024);
 355             fclose ($fp);
 356             $playlist_entry = substr($sharedplaylist_list[$r], -1);
 357             $playlist64 = base64_encode($sharedplaylist_list[$r]);
 358  
 359  
 360             $play_shared_playlist_link = "<A href=\"$BASE_URL?pl=$r&#38;shared=1\">$list_name</A>";
 361             $play_shared_playlist_shuffle = "<A href=\"$BASE_URL?pl=$r&#38;shuffle=1&#38;shared=1\"><img title=\"". $LANG["shuffle_play"] ."\" border=0 src=\"images/burst.gif\"></A>";
 362             if ($CONFIG["option_local_play"]) $play_local_link = "<A href=\"mp3daemon.php?action=playlist&playaction=$playlist64\" target=\"localplay\"> <img title=\"". $LANG["play_on_server"] ."\" align=\"bottom\" border=\"0\" title=\"". $LANG["local"] ."\" height=\"13\" src=\"images/agatha-localplay.png\"></a>&nbsp;";
 363                 else $play_local_link = null;
 364  
 365             echo "\t$play_shared_playlist_shuffle $play_local_link $play_shared_playlist_link<br>\n";
 366        }
 367        echo "</DIV>\n\n";
 368  
 369    }
 370  
 371    if (count($playlist_list) > 0) {
 372  
 373        echo "<DIV class=category><A href=\"javascript:history.go(-1)\"><-".$LANG["back"].") </A> ". $LANG["playlists"] .":</DIV>\n";
 374        echo "<DIV class=\"playlist\">\n";
 375        for ($r=0; $r < sizeof($playlist_list); $r++) {
 376             $fp = fopen(PLAYLIST_DIR."$playlist_list[$r]", "r");
 377             $list_name=trim(fgets($fp, 1024));
 378             fclose($fp);
 379  
 380             $playlist64 = base64_encode($playlist_list[$r]);
 381             $playlist_entry = substr($playlist_list[$r], -1);
 382  
 383            if (file_exists(SHAREDPLAYLIST_DIR.$playlist_list[$r])) {
 384                $play_playlist_link    = "<A href=\"$BASE_URL?pl=$r\">[$list_name]</A>";
 385            } else $play_playlist_link = "<A href=\"$BASE_URL?pl=$r\">$list_name</A>";
 386  
 387            $play_playlist_shuffle = "<A href=\"$BASE_URL?pl=$r&#38;shuffle=1\"><img title=\"". $LANG["shuffle_play"] ."\" border=0 src=\"images/burst.gif\"></A>";
 388            $edit_playlist_link    = "<A href=$BASE_URL?pledit=$playlist_entry><img title=\"". $LANG["edit_playlist"] ."\" border=0 src=images/image.gif></A>";
 389            if ($CONFIG["option_local_play"]) $play_local_link = "<A href=\"mp3daemon.php?action=playlist&playaction=$playlist64\" target=\"localplay\"> <img title=\"". $LANG["play_on_server"] ."\" align=\"bottom\" border=\"0\" title=\"". $LANG["local"] ."\" height=\"13\" src=\"images/agatha-localplay.png\"></a>&nbsp;";
 390                else $play_local_link = null;
 391  
 392            echo "\t$edit_playlist_link $play_playlist_shuffle $play_local_link $play_playlist_link<br>\n";
 393  
 394        }
 395        echo "</DIV>\n\n";
 396    }
 397  
 398     if ($listing["files"]["count"] > 0) {
 399  
 400        echo "<DIV class=category><A href=\"javascript:history.go(-1)\"><-".$LANG["back"].") </A>".$LANG["songs"] .":</DIV>\n";
 401        echo "<input type=hidden name=pdir value=\"$pdir_64\"></input>\n";
 402        echo "<input type=hidden name=cdir value=\"".$_REQUEST["cdir"]."\"></input>\n";
 403        echo "<DIV class=song>\n";
 404        for ($f=0; $f < $listing["files"]["count"]; $f++) {
 405  
 406             $file_name_dec = $listing["files"][$f];
 407             $file_name_enc = base64_encode($listing["files"][$f]);
 408             $len = strlen($file_name_dec) -4;
 409  
 410             if ($CONFIG["id3"] > 0) {
 411                 $id3 = new id3(BASE_DIR."$pdir$file_name_dec");
 412                 if ($CONFIG["id3"] == 1) { // Only Track Time
 413                     $file_name_display = strtolower($id3->length)." &nbsp; ".ereg_replace("^[0-9]*-", "", ereg_replace("_", " ", substr($file_name_dec,0,$len)));
 414                 } else if ($CONFIG["id3"] == 2) {
 415                     $file_name_display = strtolower($id3->length." &nbsp; ".$id3->artists." ".$id3->name);
 416                     if ($id3->name == "") $file_name_display=$id3->length." &nbsp; ".ereg_replace("^[0-9]*-", "", ereg_replace("_", " ", substr($file_name_dec,0,$len)));
 417                 }
 418             } else {
 419                $file_name_display=ereg_replace("^[0-9]*-", "", ereg_replace("_", " ", substr($file_name_dec,0,$len)));
 420             }
 421  
 422             $direct_64 = base64_encode("$pdir$file_name_dec");
 423  
 424             $play_single_checkbox    = "<input type=checkbox name=\"selected[]\" value=\"$file_name_enc\">";
 425             $play_single_link        = "<A href=\"$BASE_URL?play=$file_name_enc&#38;pdir=$pdir_64\"> $file_name_display</A></input>";
 426             $play_single_local_link  = "<A target=\"localplay\" href=\"mp3daemon.php?action=play&#38;playaction=$direct_64\"> <img title=\"". $LANG["play_on_server"] ."\" align=\"bottom\" border=\"0\" title=\"". $LANG["local"] ."\" height=\"13\" src=\"images/agatha-localplay.png\"></>";
 427  
 428             $play_single_stream_link = "<A href=\"".$CONFIG["shoutcast_base_url"]."content$pdir$file_shoutcast\"> [S] </A></input>";
 429  
 430             echo "\t$play_single_checkbox ";
 431  
 432             if ($CONFIG["option_local_play"] == 1) {
 433                 echo " $play_single_local_link &nbsp";
 434             }
 435             echo "$play_single_link<br>\n";
 436        }
 437        echo "</DIV>\n\n";
 438    }
 439  
 440    if (count($file_list) == 0 && count($playlist_list) == 0 && count($dir_list) == 0) echo "<font size=+1 color=ff0000)<b><i>Empty</b></i></font><br>\n";
 441  
 442        if (DISPLAY_LOGO) echo " <div id=layer_logo class=logo><img src=images/agatha-logo-sm.png></div>\n";
 443        if ($CONFIG["option_local_play"]) $localoption =  "\t<option value=local>$LANG[local]</option>\n";
 444  echo "
 445        <DIV class=category><A href=\"javascript:history.go(-1)\"><-$LANG[back]) </A> <img title=\"$LANG[help_songs]\" align=middle border=0 src=images/agatha_help_ico.png></DIV>\n
 446        <DIV class=control><input type=checkbox name=shuffle> $LANG[shuffle]<br>\n
 447        <br><input type=checkbox name=pladd> $LANG[add_to_playlist]\n
 448        <select name=plfile>\n\t<option value=new>$LANG[new]</option>\n $localoption
 449       ";
 450  
 451  for ($r=0; $r<sizeof($playlist_list); $r++) {
 452       $fp=fopen(PLAYLIST_DIR."$playlist_list[$r]", "r");
 453       $list_name=fgets($fp, 1024);
 454       fclose($fp);
 455       echo "\t<option value=$playlist_list[$r]>$list_name</option>\n";
 456  }
 457  
 458  echo "
 459        </select><br>\n
 460        <br><input type=button value=\"$LANG[select_most]\" onclick=\"SelectMost();\">  <input type=reset><br>\n
 461        <br><input type=submit value=\"$LANG[submit_list]\"></DIV>\n
 462        </form>\n
 463        </html>\n
 464       ";
 465  
 466  }
 467  
 468  
 469  /**************************************************************************************/
 470  
 471  
 472  function playlist_edit() {
 473  global $CONFIG, $LANG, $BASE_URL, $DEBUG;
 474  
 475                   if(DEBUG) error_log("playlist_edit= Enter Function",0);
 476    $song_list=array();
 477    $new_song_list=array();
 478    $del = $_POST["del"];
 479    $listname = $_POST["listname"];
 480  
 481    if(isset($_GET["remove"])) {
 482              if(DEBUG) error_log("playlist_edit= Enter REMOVE",0);
 483  
 484        $filetoremove = SHAREDPLAYLIST_DIR.$_COOKIE["uniqueid"].".".$_GET["pledit"];
 485        if(file_exists($filetoremove)) {
 486           $err = unlink($filetoremove);
 487        }
 488        $filetoremove = PLAYLIST_DIR.$_COOKIE["uniqueid"].".".$_GET["pledit"];
 489        if(file_exists($filetoremove)) {
 490           $err = unlink($filetoremove);
 491        }
 492  
 493        #error($LANG["error_file_delete"]);
 494        #exit;
 495        echo "<html>";
 496        echo "<link href=\"agatha.css\" rel=\"stylesheet\" type=\"text/css\" >\n";
 497        echo "<body>";
 498        if(isset($_POST["cdir"])) echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"2;URL=$BASE_URL?cdir=".$_POST["cdir"]."&pdir=".$_POST["pdir"]."\">";
 499          else echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"2;URL=$BASE_URL\">";
 500        echo "<link href=\"agatha.css\" rel=\"stylesheet\" type=\"text/css\" >\n";
 501        echo "$LANG[playlist_deleted] <br><br>\n";
 502        echo "</body></html>";
 503        exit;
 504  
 505    }
 506  
 507    if(isset($_GET["shuffle_playlist"]) && $_GET["shuffle_playlist"] == 1) {
 508  
 509      if(file_exists(PLAYLIST_DIR.$_COOKIE["uniqueid"].".".$_GET["pledit"])) {
 510        $fp=fopen(PLAYLIST_DIR.$_COOKIE["uniqueid"].".".$_GET["pledit"], "r");   # Write the list back to disk
 511      } else error($LANG["error_open_playlist"]." ".PLAYLIST_DIR.$_COOKIE["uniqueid"].".".$_GET["pledit"].".");
 512  
 513      $song_list = array();
 514  
 515      while(!feof ($fp)) {
 516        array_push($song_list, fgets($fp, 4096));
 517      }
 518      fclose($fp);
 519  
 520      $playlist_name = array_shift($song_list);
 521      my_shuffle($song_list);
 522      array_unshift($song_list, $playlist_name);
 523  
 524      $fp=fopen(PLAYLIST_DIR.$_COOKIE["uniqueid"].".".$_GET["pledit"], "w");   # Write the list back to disk
 525      for($i=0; $i<sizeof($song_list); $i++) {
 526        fputs($fp, "$song_list[$i]");
 527      }
 528      fclose($fp);
 529      $song_list = array();
 530  
 531    }
 532  
 533  
 534  
 535  
 536    /*  Make sure the list name is not unrealisticly long */
 537    // Debugging? Klingons do not debug. Our software does not coddle the weak.
 538    if(isset($_POST["listname"])) {
 539       if(strlen($_POST["listname"]) > 60) $_POST["listname"] = substr($_POST["listname"], 0, 60);
 540    }
 541  
 542    if(isset($_POST["listname"]) || isset($_POST["del"])) {
 543              if(DEBUG) error_log("playlist_edit= Enter MODIFY", 0);
 544  
 545      if(isset($_POST["shareplaylist"])) {
 546         if(!($_POST["shareplaylist"] == "no" || $_POST["shareplaylist"] == "yes")) {
 547            error("Wrong Parameter Supplied ".$_POST["shareplaylist"]);
 548         }
 549  
 550         if($_POST["shareplaylist"] == "yes") {
 551  
 552            if(!file_exists(PLAYLIST_DIR."sharedplaylists/".$_COOKIE["uniqueid"].".".$_REQUEST["pledit"])) {
 553               symlink(PLAYLIST_DIR.$_COOKIE["uniqueid"].".".$_REQUEST["pledit"],
 554                       PLAYLIST_DIR."sharedplaylists/".$_COOKIE["uniqueid"].".".$_REQUEST["pledit"]);
 555            }
 556         } else if($_POST["shareplaylist"] == "no") {
 557            if(file_exists(PLAYLIST_DIR."sharedplaylists/".$_COOKIE["uniqueid"].".".$_REQUEST["pledit"])) {
 558               unlink(PLAYLIST_DIR."sharedplaylists/".$_COOKIE["uniqueid"].".".$_REQUEST["pledit"]);
 559            }
 560         }
 561      }
 562  
 563  
 564      if(file_exists(PLAYLIST_DIR.$_COOKIE["uniqueid"].".".$_POST["pledit"])) {
 565      $fp=fopen(PLAYLIST_DIR.$_COOKIE["uniqueid"].".".$_POST["pledit"], "r");
 566      } else error($LANG["error_open_playlist"]." ".PLAYLIST_DIR.$_COOKIE["uniqueid"].".".$_POST["pledit"].".");
 567  
 568      while(!feof ($fp)) {
 569        array_push($song_list, fgets($fp, 4096));
 570      }
 571      fclose($fp);
 572  
 573      $song_list[0] = $_POST["listname"]."\n";               # Set the list name
 574        if(isset($_POST["del"])) {                           # If selected to delete..
 575                         if(DEBUG) error_log("playlist_edit= Enter DELETE SONG",0);
 576          for($i=0; $i<sizeof($_POST["del"]); $i++) {          # remove from array
 577            for($p=0; $p<sizeof($song_list); $p++) {           #
 578                         if(DEBUG) error_log("del :$del[$i]: song :$p:",0);
 579              if($del[$i] == $p) {
 580                 $i++;
 581                 continue;
 582              }
 583              else array_push($new_song_list, $song_list[$p]);
 584            }                                                  #
 585          }                                                    #
 586          $song_list=$new_song_list;                           # Swap in the adjusted array
 587        }                                                      #
 588  
 589      $fp=fopen(PLAYLIST_DIR.$_COOKIE["uniqueid"].".".$_POST["pledit"], "w");   # Write the list back to disk
 590      for($i=0; $i<sizeof($song_list); $i++) {
 591        fputs($fp, "$song_list[$i]");
 592      }
 593  
 594    header("Content-Type: text/html");
 595    echo "<META HTTP-EQUIV=Refresh Content=2;URL=$BASE_URL?pledit=".$_POST["pledit"].">";
 596    echo "<link href=\"agatha.css\" rel=\"stylesheet\" type=\"text/css\" >\n";
 597    echo $LANG["playlist_modified"];
 598    exit;
 599    }
 600  
 601    /* Prepare to Display the PLEdit Screen - Read in all Required Data *****************/
 602  
 603    $fp=fopen(PLAYLIST_DIR.$_COOKIE["uniqueid"].".".$_GET["pledit"], "r");     # Read the list into an array for display
 604    while(!feof ($fp)) {
 605      array_push($song_list, fgets($fp, 4096));
 606    }
 607    fclose($fp);
 608  
 609    if(file_exists(SHAREDPLAYLIST_DIR.$_COOKIE["uniqueid"].".".$_REQUEST["pledit"])) {
 610       $shareplaylist = "yes";
 611    }
 612  
 613    echo "<html>\n";
 614    echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">";
 615    echo "<head><title>Agatha - Playlist Edit</title></head>\n";
 616    echo "<body>\n<link href=\"agatha.css\" rel=\"stylesheet\" type=\"text/css\" >\n";
 617    draw_dirnav_bar();
 618    echo "<form method=post action=\"$BASE_URL\">\n";
 619    for($p=0; $p<(sizeof($song_list) -1); $p++) {
 620      if($p == 0) {
 621       echo "<input type=hidden name=pledit value=".$_GET["pledit"]."></input>\n";
 622       echo "<input type=text name=listname value=\"$song_list[$p]\"> <img title=\"".$LANG["help_list_edit"]."\" src=images/agatha_help_ico.png align=middle border=0><br><br>\n";
 623       echo "<font size=-2><A href=\"$BASE_URL?pledit=".$_GET["pledit"]."&#38;remove=1\">(". $LANG["delete_list"].")</A></font><br>\n";
 624       echo "<br>\n";
 625       continue;
 626      }
 627      echo "<input type=checkbox name=del[] value=$p> $song_list[$p]</input><br>\n";
 628    }
 629    if($shareplaylist == "yes") {
 630      echo "<br>Share Playlist <input type=radio name=shareplaylist checked value=yes> Yes </input><input type=radio name=shareplaylist value=no> No</input><br></input>\n";
 631      } else {
 632      echo "<br>Share Playlist<input type=radio name=shareplaylist value=yes> Yes </input><input type=radio name=shareplaylist checked value=no> No</input><br></input>\n";
 633    }
 634  
 635    echo "<br><A href=\"$BASE_URL?pledit=".$_GET["pledit"]."&#38;shuffle_playlist=1\">(".$LANG["shuffle"] = "Shuffle".")</A></font><br>\n";
 636  
 637    echo "<br><input type=submit value=". $LANG["modify_list"] ."><br><br><A href=\"javascript:history.go(-1)\"><-".$LANG["back"].") </A><br>\n";
 638    echo "</form></body></html>";
 639  
 640  }
 641  
 642  
 643  /**************************************************************************************/
 644  
 645  
 646  function choose_next_playlist() {
 647    global $CONFIG, $playlist_list, $LANG;
 648     for($i=0; $i<=10; $i++) {
 649       if($i < 10) {
 650         while(!file_exists(PLAYLIST_DIR.$_COOKIE["uniqueid"].".$i")) {
 651           return($i);
 652         }
 653       } else error($LANG["error_too_many_playlists"]);
 654     }
 655  }
 656  
 657  
 658  /**************************************************************************************/
 659  
 660  function playlist_add() {
 661  global $CONFIG, $playlist_list, $pdir, $BASE_URL;
 662  
 663      if(DEBUG) error_log("playlist_add= ".sizeof($_REQUEST["selected"]),0);
 664  
 665      $plfile = $_REQUEST["plfile"];
 666      $selected = $_POST["selected"];
 667  
 668      include_once  "mp3daemon.class.php";
 669  
 670      if ($plfile == "local") {
 671  
 672          $mp3 = new mp3daemon(LOCAL_PLAY_SOCKET);
 673  
 674          foreach ($selected as $item) {
 675                   $args[] = BASE_DIR . $pdir . base64_decode($item);
 676          }
 677  
 678          if ($mp3->command("add", $args) === FALSE) die($mp3->error);
 679          $status = $mp3->status();
 680          if ($status["state"] == "stopped") $mp3->command("play");
 681  
 682          header("Content-Type: text/html");
 683          echo "<body onload=\"history.back(-1)\">";
 684          exit;
 685  
 686      } else if ($plfile == "new") {
 687  
 688          read_playlists(PLAYLIST_DIR, $playlist_list);
 689          if (sizeof($playlist_list) == 0) {
 690              $nextlist=0;
 691          } else {
 692              $nextlist = choose_next_playlist();
 693          }
 694          $fp = fopen(PLAYLIST_DIR.$_COOKIE["uniqueid"].".$nextlist", "a+");
 695          fputs($fp, "Playlist $nextlist\n");
 696          fclose($fp);
 697          $plfile = $_COOKIE["uniqueid"].".$nextlist";
 698      }
 699  
 700          $fp = fopen(PLAYLIST_DIR."$plfile", "a+");
 701          $mydir = new mydir(BASE_DIR . $pdir);
 702          $listing = $mydir->getentries();
 703  
 704          for ($i=0; $i < count($selected); $i++) {
 705               $file_name_dec = base64_decode($selected[$i]);
 706               fputs($fp, "$pdir$file_name_dec\n");
 707               if(DEBUG) error_log("pladd= pdir :$pdir: file_list_index:$file_name_dec:", 0);
 708          }
 709          fclose($fp);
 710  
 711  
 712    header("Content-Type: text/html");
 713    if(isset($_REQUEST["cdir"])) echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"2;URL=$BASE_URL?pdir=".$_REQUEST["pdir"]."\">";
 714      #echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"2;URL=$BASE_URL?cdir=".$_REQUEST["cdir"]."&pdir=".$_REQUEST["pdir"]."\">";
 715      #echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"2;URL=$BASE_URL\">";
 716  
 717  
 718    echo "<link href=\"agatha.css\" rel=\"stylesheet\" type=\"text/css\" >\n";
 719    echo "Added to Playlist";
 720    exit;
 721  
 722  }
 723  
 724  /**************************************************************************************/
 725  
 726  function play_multiple($selected) {
 727      global $BASE_URL, $pdir_64, $DEBUG;
 728  
 729      if(DEBUG) error_log("play_multiple= Selection Size :".sizeof($selected).":", 0);
 730  
 731      if($_POST["shuffle"]) my_shuffle($selected);                         # and you want them shuffled..
 732  
 733      header("Content-Type: audio/mpegurl");
 734      header("Content-Disposition: filename=\"selected.m3u\"");
 735  
 736  
 737      if (is_numeric($selected[0])) {
 738  
 739          #for ($i=0; $i<count($selected); $i++) {
 740          #     if(DEBUG) error_log("play_multiple= echo $BASE_URL?stream=$selected[$i]&pdir=$pdir_64");
 741          #     echo "$BASE_URL?stream=$selected[$i]&pdir=$pdir_64\r\n";
 742          #}
 743  
 744      } else {
 745          for ($i=0; $i<count($selected); $i++) {
 746               if(DEBUG) error_log("play_multiple= echo $BASE_URL?stream=$selected[$i]&pdir=$pdir_64");
 747               echo "$BASE_URL?direct=1&stream=$selected[$i]&pdir=$pdir_64\r\n";
 748          }
 749  
 750  
 751      }
 752  }
 753  
 754  
 755  /**************************************************************************************/
 756  
 757  
 758  function play_playlist() {
 759      global $CONFIG, $pdir, $BASE_URL;
 760      if(DEBUG) error_log("play_playliste= Enter Function", 0);
 761  
 762      $pl = $_REQUEST["pl"];
 763  
 764      if ($_REQUEST["shared"] == 1) {
 765          $sharedplaylist_list = read_shared_playlists();
 766          if(DEBUG) error_log("list :".$sharedplaylist_list[$pl].":",0);
 767          $playlist_to_open = PLAYLIST_DIR.$sharedplaylist_list[$pl];
 768      } else {
 769          $playlist_to_open = PLAYLIST_DIR.$_COOKIE["uniqueid"].".".$_GET["pl"];
 770      }
 771      if(DEBUG) error_log("play_playliste= playlist_to_open :$playlist_to_open:",0);
 772      if (!file_exists($playlist_to_open)) {
 773          error($LANG["error_open_playlist"]);
 774      }
 775  
 776      header("Content-Type: audio/x-mpegurl");
 777      header("Content-Disposition: filename=\"playlist.m3u\"");
 778      $songlist = array();
 779      $fp = fopen($playlist_to_open, "r");
 780  
 781      while (!feof ($fp)) array_push($songlist, fgets($fp, 4096));
 782  
 783      fclose($fp);
 784      array_shift($songlist);
 785  
 786      $nextsong = array();
 787      for ($i=0; $i<(sizeof($songlist)); $i++) $nextsong[$i]=$i;
 788  
 789      if ($_GET["shuffle"] == 1) my_shuffle($nextsong);
 790  
 791      if ($_REQUEST["shared"] == 1) {
 792          for ($s=0; $s<(sizeof($songlist) - 1); $s++) {
 793               echo "$BASE_URL?stream=".$_GET["pl"]."&nextsong=$nextsong[$s]&shared=1\r\n";
 794          }
 795      } else {
 796          for ($s=0; $s<(sizeof($songlist) - 1); $s++) {
 797               echo "$BASE_URL?stream=".$_GET["pl"]."&nextsong=$nextsong[$s]&uniqueid=".$_COOKIE["uniqueid"]."\r\n";
 798          }
 799      }
 800  }
 801  
 802  /**************************************************************************************/
 803  
 804  function stream() {
 805      global $CONFIG, $MIME_TYPES, $pdir, $LANG;
 806  
 807      if ($_REQUEST["shared"] == 1) {
 808          $sharedplaylist_list = read_shared_playlists();
 809          $stream = $_GET["stream"];
 810          $playlisttoopen = SHAREDPLAYLIST_DIR.$sharedplaylist_list[$stream];
 811      } else {
 812          $playlisttoopen = PLAYLIST_DIR .$_REQUEST["uniqueid"] . "." . $_REQUEST["stream"];
 813      }
 814  
 815      if (isset($_REQUEST["nextsong"])) {  // This is from an ondisk playlist
 816          if(DEBUG) error_log("stream= Enter NextSong", 0);
 817          if(DEBUG) error_log("stream= Playlist to open :$playlisttoopen:", 0);
 818  
 819          $songlist = array();
 820  
 821          if (!file_exists($playlisttoopen)) {
 822              error($LANG["error_open_playlist"]);
 823          }
 824  
 825          $fp = fopen($playlisttoopen, "r");  # Open the matching playlist for this requestors IP
 826          while (!feof ($fp)) array_push($songlist, fgets($fp, 4096));    # Read in the list of songs from the playlist
 827          array_shift($songlist);
 828  
 829          $extension = trim(substr(strrchr($songlist[$_REQUEST["nextsong"]], "."),1));
 830  
 831          $file_to_open = BASE_DIR . trim($songlist[$_REQUEST["nextsong"]]);
 832  
 833          $file_size = filesize("$file_to_open");
 834          if(DEBUG) error_log("stream= File to stream :$file_to_open: Size :$file_size:", 0);
 835          $fp = fopen($file_to_open, "r");
 836  
 837      } elseif ($_REQUEST["direct"] == 1) {
 838  
 839          if (strstr(base64_decode($_REQUEST["stream"]), $pdir)) {
 840          
 841              $file_to_open = BASE_DIR . base64_decode($_REQUEST["stream"]);
 842          } else {
 843              $file_to_open = BASE_DIR . $pdir . base64_decode($_REQUEST["stream"]);
 844          }
 845          error_log("FILE:  $file_to_open",0);
 846          if(DEBUG) error_log("stream= Direct File to Open :$file_to_open:", 0);
 847  
 848      } else {
 849  
 850          $file_name_dec = base64_decode($_REQUEST["stream"]);
 851          $file_to_open = BASE_DIR . "$pdir$file_name_dec";
 852      }
 853  
 854      $display_name = substr($file_to_open, strrpos($file_to_open, '/')+1);
 855      $extension = trim(substr(strrchr($file_to_open, "."),1));
 856  
 857      if(DEBUG) error_log("stream= Extension NO list :$extension:", 0);
 858      if(DEBUG) error_log("stream= Header :$MIME_TYPES[$extension]:", 0);
 859  
 860  
 861      $file_size = filesize($file_to_open);
 862      if(DEBUG) error_log("stream= File to stream: $file_to_open", 0);
 863      if (!file_exists($file_to_open)) {
 864          error($LANG["error_open_song"]);
 865      }
 866  
 867      $fp = fopen($file_to_open, "r");
 868  
 869      header("$MIME_TYPES[$extension]");
 870      header("Content-Disposition: filename=$display_name");
 871      header("Content-Length $file_size");
 872  
 873      if(DEBUG) error_log("stream= :Begin Streaming $display_name", 0);
 874  
 875  
 876      if ($CONFIG["use_alternate_streaming"]) {
 877  
 878          $id3 = new id3($file_to_open);
 879          streamfp($fp, $id3->bitrate);
 880  
 881      } else {
 882  
 883          fpassthru($fp);
 884  
 885      }
 886  
 887      fclose($fp);
 888      if(DEBUG) error_log("stream= :End Streaming $display_name", 0);
 889  }
 890  
 891  /**************************************************************************************/
 892  
 893  class MeasureTime {
 894          var $start = 0;
 895          var $alarm = 0;
 896  
 897          function getmicrotime() {
 898              list($usec, $sec) = explode(" ",microtime());
 899              return ((float)$usec + (float)$sec);
 900          }
 901  
 902          function start() {
 903              $this->start = $this->getmicrotime();
 904              usleep(100);
 905          }
 906  
 907          function setalarm($alarm) {
 908              $this->alarm = $alarm;
 909          }
 910  
 911          function alarm() {
 912              if ( ($this->getmicrotime() - $this->start)   >= (float)$this->alarm) return true;
 913              return false;
 914          }
 915  }
 916  
 917  function streamfp($fp, $kbit, $prebuffer=true) {
 918      global $CONFIG;
 919  
 920      $bread = ($kbit * 1000) / 8;
 921      $readbuffer = ($bread / 100) * $CONFIG['buffer'];
 922  
 923      if (DEBUG) error_log("streamfp= kbit :$kbit: readbuffer :$readbuffer:", 0);
 924  
 925      $mt = new MeasureTime();
 926      $mt->setalarm($CONFIG["sleeptime"]);
 927  
 928  
 929      echo fread($fp, $CONFIG["prebuffer"]);
 930      flush();
 931  
 932      $mt->start();
 933      while (!feof($fp)) {
 934             echo fread($fp, $readbuffer);
 935             flush();
 936             while (!$mt->alarm()) usleep($CONFIG["precision"]);
 937             $mt->start();
 938      }
 939  }
 940  
 941  
 942  /**************************************************************************************/
 943  
 944  
 945  function read_dir($dir_parent) {
 946    global $CONFIG, $DEBUG, $dir_list, $file_list, $pdir;
 947  
 948              if(DEBUG) error_log("read_dir= Enter Function", 0);
 949    $c=0;
 950    $d = opendir(BASE_DIR."$pdir");
 951      while($raw_list[$c]=readdir($d)) {
 952        if($raw_list[$c] == "." || $raw_list[$c]==".." || $raw_list[$c]=="sharedplaylists") continue;
 953        if(is_dir(BASE_DIR."$pdir$raw_list[$c]")) {
 954           array_push($dir_list, $raw_list[$c]."/");
 955          # error_log("Raw Dir ".$raw_list[$c], 0);
 956        }
 957          elseif (strtolower(substr($raw_list[$c], -4)) != ".mp3") continue;
 958          else array_push($file_list, $raw_list[$c]);
 959      }
 960    sort($dir_list);
 961    sort($file_list);
 962  
 963  }
 964  
 965  /**************************************************************************************/
 966  
 967  class mydir {
 968  
 969     var $fp;
 970     var $dirs;
 971     var $files;
 972     var $error;
 973  
 974  
 975     function mydir($dir) {
 976  
 977        $this->dir = null;
 978        $this->files = null;
 979        $this->error = null;
 980  
 981  
 982        if (! file_exists($dir)) {
 983            $this->error = "Supplied Path Does Not Exist";
 984            return FALSE;
 985        } else if (! is_readable($dir)) {
 986            $this->error = "Supplied Path Is Not Readable";
 987            clearstatcache();
 988            return FALSE;
 989        } else if (! is_dir($dir)) {
 990            $this->error = "Supplied Path Is Not a Directory";
 991            clearstatcache();
 992            return FALSE;
 993        }
 994        if (! $this->fp = opendir($dir)) {
 995            $this->error = "There was a problem reading $dir.";
 996            return FALSE;
 997        }
 998  
 999        $this->dir = $dir."/";
1000        return TRUE;
1001  
1002     }
1003  
1004     function getentries() {
1005         $this->error = null;
1006         $file_list = array();
1007         $dir_list  = array();
1008  
1009         $c = 0;
1010         while ($raw[$c] = readdir($this->fp)) {
1011                if ($raw[$c] == "." || $raw[$c] == ".." || $raw[$c] == "sharedplaylists" ) continue;
1012                if (is_dir($this->dir.$raw[$c])) array_push($dir_list, $raw[$c]."/");
1013                elseif (stristr(substr($raw[$c], -4), ".mp3") === FALSE) continue;
1014                else array_push($file_list, $raw[$c]);
1015         }
1016         sort($dir_list);
1017         sort($file_list);
1018  
1019         $list["directories"]["count"] = count($dir_list);
1020         $list["files"]["count"] = count($file_list);
1021  
1022         for ($i=0; $i < count($dir_list); $i++) {
1023              $list["directories"][$i] = $dir_list[$i];
1024         }
1025  
1026         for($j=0; $j < count($file_list); $j++) {
1027              $list["files"][$j] = $file_list[$j];
1028         }
1029  
1030         return $list;
1031  
1032     }
1033  
1034  
1035  } // Class
1036  
1037  
1038  /**************************************************************************************/
1039  
1040  
1041  function read_playlists($dir, &$playlist) {
1042    global $CONFIG;
1043    $c = 0;
1044    $d = opendir($dir);
1045      while($raw_list[$c]=readdir($d)) {
1046      if($raw_list[$c] == "." || $raw_list[$c]==".." || $raw_list[$c] == "sharedplaylists") continue;
1047      if($_COOKIE["uniqueid"] == substr($raw_list[$c], 0, -2)) {
1048        array_push($playlist, $raw_list[$c]); }
1049      }
1050    return($playlist);
1051  }
1052  
1053  /**************************************************************************************/
1054  
1055  function read_shared_playlists() {
1056    $sharedplaylist_list = array();
1057    $c = 0;
1058    $d = opendir(SHAREDPLAYLIST_DIR);
1059      while($raw_list[$c] = readdir($d)) {
1060         if($raw_list[$c] == "." || $raw_list[$c]==".." || $raw_list[$c]=="index.php") continue;
1061         #error_log("shared list :$raw_list[$c]:", 0);
1062         array_push($sharedplaylist_list, $raw_list[$c]);
1063      }
1064    return($sharedplaylist_list);
1065  }
1066  
1067  /**************************************************************************************/
1068  
1069  function my_shuffle(&$array) {
1070    global $DEBUG;
1071        if(DEBUG) error_log("my_shuffle= Enter Function", 0);
1072    srand ((double)microtime()*1000000);
1073    for ($j = count($array) - 1; $j > 0; $j--) {
1074      if (($i = rand(0,$j))<$j) {
1075        $swp=$array[$i]; $array[$i]=$array[$j]; $array[$j]=$swp;
1076      }
1077    }
1078  }
1079  
1080  /**************************************************************************************/
1081  
1082  function play_single() {
1083      global $CONFIG, $file_list, $BASE_URL, $pdir_64, $pdir, $play;
1084  
1085      $mydir = new mydir(BASE_DIR . $pdir . $cdir);
1086      $listing = $mydir->getentries();
1087      $play = base64_decode($_REQUEST["play"]);
1088  
1089        $file_to_play = $play.".m3u";
1090        if (DEBUG) error_log("File to play:$file_to_play: pdir :$pdir: cdir :$cdir:", 0);
1091  
1092        header("Content-Type: audio/x-mpegurl");
1093        header("Content-Disposition: filename=\"$file_to_play\"");
1094  
1095        $id3 = new id3(BASE_DIR.$pdir.$play);
1096        echo "#EXTM3U\n";
1097        echo "#EXTINF:$id3->lengths, $id3->name\n";
1098  
1099        echo "$BASE_URL?stream=".$_REQUEST["play"]."&pdir=$pdir_64\n";
1100  
1101  }
1102  
1103  
1104  
1105  
1106  /**************************************************************************************/
1107  // By filing this bug report you have challenged the honor of my family. Prepare to die!
1108  
1109  #function play_local($file, $pdir) {
1110  #    global $CONFIG, $cdir, $playlist_list;
1111  #
1112  #    include "mp3daemon.class.php";
1113  #    $mp3 = new mp3daemon(LOCAL_PLAY_SOCKET);
1114  #
1115  #    $mp3->command("play", array(BASE_DIR.$pdir.$file));
1116  #
1117  #    header("Content-Type: text/html");
1118     # echo "<head>\n
1119     #       <script language=\"JavaScript\" type=\"text/javascript\">\n
1120     #          function reloadlocalplay(url) {\n
1121     #             targetFrame = top.frames.localplay;\n
1122     #             targetFrame.location.href = url;\n
1123     #          }\n
1124     #       </script>\n
1125     #      ";
1126  #    echo "<body onload=\"history.back(-1)\">";
1127  #
1128  #}
1129  
1130  
1131  /**************************************************************************************/
1132  
1133  function pray ($data, $functions=0) {
1134      if($functions!=0) { $sf=1; } else { $sf=0 ;}    // This kluge seemed necessary on one server.
1135      if (isset ($data)) {
1136          if (is_array($data) || is_object($data)) {
1137              if (count ($data)) {
1138                  echo "<OL>\n";
1139                  while (list ($key,$value) = each ($data)) {
1140                         $type=gettype($value);
1141                         if ($type=="array" || $type == "object") {
1142                             printf ("<li>(%s) <b>%s</b>:\n",$type, $key);
1143                             pray ($value,$sf);
1144                         } elseif (eregi ("function", $type)) {
1145                             if ($sf) {
1146                                 printf ("<li>(%s) <b>%s</b> </LI>\n",$type, $key, $value);
1147                                 //   There doesn't seem to be anything traversable inside functions.
1148                             }
1149                         } else {
1150                             if (!$value) { $value="(none)"; }
1151                             printf ("<li>(%s) <b>%s</b> = %s</LI>\n",$type, $key, $value);
1152                         }
1153                  }
1154                  echo "</OL>end.\n";
1155              } else {
1156                  echo "(empty)";
1157              }
1158          }
1159      }
1160  }    // function
1161  
1162  
1163  function error($text) {
1164    echo "<html>\n<head><title>Agatha - Error</title></head>\n";
1165    echo "<body>\n\n";
1166    echo "<link href=\"agatha.css\" rel=\"stylesheet\" type=\"text/css\" >\n";
1167    echo "<DIV class=error>Error: $text<br>\n";
1168    error_log("ERROR: $text", 0);
1169    echo "</body></html>";
1170    exit;
1171  }
1172  
1173  
1174  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]