PageRenderTime 75ms CodeModel.GetById 43ms RepoModel.GetById 0ms app.codeStats 0ms

/main_body.php

https://github.com/sdubois/phpMp
PHP | 133 lines | 112 code | 8 blank | 13 comment | 23 complexity | 87d948ef27c1097ba5993ab415e80ee5 MD5 | raw file
  1. <?php
  2. include "info.php";
  3. include "utils.php";
  4. include "info2html.php";
  5. $arg = "";
  6. $dir = "";
  7. $sort = $default_sort;
  8. EXTRACT($_GET);
  9. $sort_array = split(",",$sort);
  10. $fp = fsockopen($host,$port,$errno,$errstr,10);
  11. if(!$fp) {
  12. echo "$errstr ($errno)<br>\n";
  13. }
  14. else {
  15. while(!feof($fp)) {
  16. $got = fgets($fp,1024);
  17. if(strncmp("OK",$got,strlen("OK"))==0)
  18. break;
  19. print "$got<br>";
  20. if(strncmp("ACK",$got,strlen("ACK"))==0)
  21. break;
  22. }
  23. if(isset($password)) {
  24. fputs($fp,"password \"$password\"\n");
  25. while(!feof($fp)) {
  26. $got = fgets($fp,1024);
  27. if(strncmp("OK",$got,strlen("OK"))==0)
  28. break;
  29. print "$got<br>";
  30. if(strncmp("ACK",$got,strlen("ACK"))==0)
  31. break;
  32. }
  33. }
  34. if(isset($command)) {
  35. if(strlen($arg)>0) $command.=" \"$arg\"";
  36. fputs($fp,"$command\n");
  37. while(!feof($fp)) {
  38. $got = fgets($fp,1024);
  39. if(strncmp("OK",$got,strlen("OK"))==0)
  40. break;
  41. preg_replace("/\n/","\n<br>",$got);
  42. print "$got<br>";
  43. if(strncmp("ACK",$got,strlen("ACK"))==0)
  44. break;
  45. }
  46. }
  47. $dir_url = sanitizeForURL($dir);
  48. if(strlen($dir)>0) $lsinfo = getLsInfo($fp,"lsinfo \"$dir\"\n");
  49. else $lsinfo = getLsInfo($fp,"lsinfo\n");
  50. # lsinfo2musicTable should start here
  51. $dcount = count($lsinfo["dir"]);
  52. if($dcount) usort($lsinfo["dir"],"strcasecmp");
  53. $dic = 0;
  54. for($i=0;$i<$dcount;$i++) {
  55. $dirent = $lsinfo["dir"][$i];
  56. $dirstr = $dirent;
  57. $dirss = split("/",$dirstr);
  58. if(count($dirss)==0)
  59. $dirss[0] = $dirstr;
  60. $dirss[0] = $dirss[count($dirss)-1];
  61. $dirstr = sanitizeForURL($dirstr);
  62. $dcol = $colors["directories"]["body"][$i%2];
  63. $dprint[$i] = "<tr bgcolor=\"$dcol\"><td>";
  64. $fc = strtoupper(mbFirstChar($dirss[0]));
  65. if($dic==0 || $dindex[$dic-1]!=$fc) {
  66. $dindex[$dic] = $fc;
  67. $foo = $dindex[$dic];
  68. $dic++;
  69. $dprint[$i].="<a name=d$foo>";
  70. }
  71. $dprint[$i].="[<a href=\"playlist.php?add_dir=$dirstr\" target=playlist>add</a>] <a href=\"main.php?sort=$sort&dir=$dirstr\">$dirss[0]</a></td></tr>\n";
  72. # $dprint[$i].="[<a href=\"main.php?sort=$sort&dir=$dirstr\">dir</a>] [<a href=\"playlist.php?add_dir=$dirstr\" target=playlist>add</a>] $dirss[0]</td></tr>\n";
  73. }
  74. if(!isset($dindex)) $dindex = array();
  75. # end of lsinfo2directoryTable
  76. list($pprint,$pindex) = lsinfo2playlistTable($lsinfo,$sort);
  77. list($mprint,$mindex,$add_all) = lsinfo2musicTable($lsinfo,$sort,$dir_url);
  78. displayDirectory($dir,$sort,"Current Directory",count($mprint),count($pprint));
  79. if(isset($save) && $save) {
  80. print "<br><form style=\"padding:0;margin:0;\" action=main.php? method=get>\n";
  81. print "<table border=0 cellspacing=1 bgcolor=\"";
  82. print $colors["playlist"]["title"];
  83. print "\" width=\"100%\">\n";
  84. print "<tr><td><b>Save Playlist</b></td></tr>\n";
  85. print "<tr bgcolor=\"";
  86. print $colors["playlist"]["body"];
  87. print "\"><td>\n";
  88. print "<input name=arg size=40>\n";
  89. print "<input type=hidden value=save name=command>\n";
  90. print "<input type=submit value=save name=foo>\n";
  91. print "</td></tr></table>\n";
  92. print "</form>\n";
  93. $dir = "";
  94. }
  95. # begin printDirectoryTable
  96. # dcount -> is the number of directories
  97. # dprint -> array, has dcount elements, just do print $dprint[$i]
  98. # to print output for that directory, it was formatted
  99. # in lsinfo2directoryTable (this parses input from
  100. # lsinfo and make the $dprint's for output)
  101. # dindex -> these are the links etc for the index elements point too
  102. # printIndex -> function that takes $dinex and prints all the links
  103. # for the indexes
  104. if($dcount) {
  105. print "<br>\n";
  106. print "<table border=0 cellspacing=1 bgcolor=\"";
  107. print $colors["directories"]["title"];
  108. print "\" width=\"100%\">\n";
  109. print "<tr><td nowrap><b>Directories</b>\n";
  110. printIndex($dindex,"","d");
  111. print "</td></tr>\n";
  112. print "<tr><td><table border=0 cellspacing=1 bgcolor=\"";
  113. print $colors["directories"]["body"][1];
  114. print "\" width=\"100%\">\n";
  115. for($i=0;$i<$dcount;$i++) print $dprint[$i];
  116. print "</table></td></tr></table>\n";
  117. }
  118. # end of printDirectoryTable
  119. printMusicTable($mprint,"main.php?dir=$dir_url",$add_all,$mindex);
  120. printPlaylistTable($pprint,$pindex);
  121. fclose($fp);
  122. displayStats($dir,$sort);
  123. displayUpdate($dir,$sort);
  124. }
  125. ?>