Shoutcash Modul mit Bild - auch ohne Sendung

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Shoutcash Modul mit Bild - auch ohne Sendung

    Dann holen wir den Thread mal aus der Versenkung :o)

    Ich bastel nun auch schon eine ganze Weile an einem Script herum, welches das Bild des sendenden DJs ausgibt. Da meine PHP Kentnisse in einer Skala von 0-100 bei ca. 1 liegen dürfte, muss ich auch immer Schnipsel im Netz suchen und diese mühsam zusammen setzen.
    Das Script, welches ich momentan einsetze funktioniert sehr gut, mit einem Nachteil, dass das Bild des zuletzt sendenden DJs auch nach seiner Sendung weiterhin angezeigt wird.
    Die Abfrage geht über den Eintrag AIM.

    Meine Bitte an alle PHP Profis... fügt doch mal bitte einen Schnipsel hinzu, der sicherstellt, dass nach der letzten Sendung (also wenn der Shoutcast Server aus ist) ein Bild xy.jpg angezeigt wird.

    Hier der Code den ich einsetze:

    Quellcode

    1. <body bgcolor="#12447a">
    2. <?php
    3. $host = "IP"; //Host
    4. $port = "Port"; //Port
    5. $password = "Passwort"; //Server Password
    6. //Configuration Finished
    7. //Runs each time an XML element starts
    8. function StartHandler(&$Parser, &$Elem, &$Attr) {
    9. global $Data, $CData;
    10. /* Start with empty CData array. */
    11. $CData = array();
    12. /* Put each attribute into the Data array. */
    13. while ( list($Key, $Val) = each($Attr) ) {
    14. $Data["$Elem:$Key"] = trim($Val);
    15. // debug // echo "$Elem:$Key = " . $Data["$Elem:$Key"] . "\n";
    16. }
    17. }
    18. //Runs each time XML character data is encountered
    19. function CharacterHandler(&$Parser, &$Line) {
    20. global $CData;
    21. /*
    22. * Place lines into an array because elements
    23. * can contain more than one line of data.
    24. */
    25. $CData[] = $Line;
    26. }
    27. //Runs each time an XML element ends
    28. function EndHandler(&$Parser, &$Elem) {
    29. global $Data, $CData, $listeners, $server, $song, $dj, $wee;
    30. //Mush all of the CData lines into a string and put it into the $Data array.
    31. $Data[$Elem] = trim( implode('', $CData) );
    32. //echo "$Elem = " . $Data[$Elem] . "<br>\n";
    33. switch ($Elem){
    34. //for each case, we are putting some data into a variable.
    35. case 'AIM':
    36. $dj['AIM'] = $Data['AIM'];
    37. break;
    38. }
    39. }
    40. //open connection
    41. $fp = fsockopen("$host", $port, &$errno, &$errstr, 30);
    42. if (!$fp) {
    43. echo "Die Verbindung zum Server konnte nicht hergestellt werden! <BR>";
    44. }
    45. else {
    46. //request xml
    47. fputs($fp,"GET /admin.cgi?pass=".$password."&mode=viewxml&page=0 HTTP/1.0\nUser-Agent: Mozilla Compatible\n\n");
    48. while(!feof($fp)) {
    49. //put xml into $Data
    50. $Contents .= fgets($fp, 1000);
    51. }
    52. }
    53. //close connection
    54. fclose($fp);
    55. $Contents = str_replace('HTTP/1.0 200 OK','', $Contents);
    56. $Contents = str_replace('Content-Type:text/xml','', $Contents);
    57. $Contents = str_replace("\n",'', $Contents);
    58. $Contents = str_replace("\r",'', $Contents);
    59. $Contents = preg_replace('/(&amp;|&)/i', '&amp;', $Contents);
    60. $Contents = preg_replace('/[^\x20-\x7E\x09\x0A\x0D]/', "\n", $Contents);
    61. $Data = array();
    62. // Initialize the parser.
    63. $Parser = xml_parser_create('ISO-8859-1');
    64. xml_set_element_handler($Parser, 'StartHandler', 'EndHandler');
    65. xml_set_character_data_handler($Parser, 'CharacterHandler');
    66. //Pass the content string to the parser.
    67. if (!xml_parse($Parser, $Contents)) {
    68. $Probs[] = "$URI$Sym\n Had problem parsing file:\n "
    69. . xml_error_string(xml_get_error_code($Parser));
    70. }
    71. if (isset($Probs)) {
    72. echo implode("\n", $Probs);
    73. }
    74. //Output
    75. $listeners['AVERAGETIME'] = $listeners[AVERAGETIME]/60;
    76. $wee = $wee -1;
    77. $search = array('dj1','dj2','dj3');
    78. $replace = array('<IMG SRC="/images/dj1.jpg" BORDER="0">','<IMG SRC="/images/dj2.jpg" BORDER="0">','<IMG SRC="/images/dj3.jpg" BORDER="0">');
    79. echo str_replace($search, $replace, "
    80. <tr><td></td><td>{$dj[AIM]}</td></tr>\n
    81. ");
    82. ?>
    Alles anzeigen
  • der code ist echt ne plage :P

    Quellcode

    1. if(empty($Contents)) {
    2. echo '<img src="xy.jpg" alt="" />';
    3. } else {
    4. $search = array('dj1','dj2','dj3');
    5. $replace = array('<IMG SRC="/images/dj1.jpg" BORDER="0">','<IMG SRC="/images/dj2.jpg" BORDER="0">','<IMG SRC="/images/dj3.jpg" BORDER="0">');
    6. echo str_replace($search, $replace, "
    7. <tr><td></td><td>{$dj[AIM]}</td></tr>\n
    8. ")
    9. }
  • ...mehr als nur eine Plage :o)

    Aber so ist das. Wenn man keine Ahnung hat, so wie ich, biste aufgeschmissen.
    Erst einmal herzlichen Dank für deine Hilfe.
    Kannst du bitte noch einmal drüber schauen... ich hab eine Fehlermeldung in Zeile 88. Setz ich in Zeile 87 ein ; am Ende, ist zwar die Fehlermeldung weg aber funktionieren tut es dann auch nicht.


    PHP-Quellcode

    1. <body bgcolor="#12447a">
    2. <?php
    3. $host = "IP"; //Host
    4. $port = "Port"; //Port
    5. $password = "Passwort"; //Server Password
    6. //Configuration Finished
    7. //Runs each time an XML element starts
    8. function StartHandler(&$Parser, &$Elem, &$Attr) {
    9. global $Data, $CData;
    10. /* Start with empty CData array. */
    11. $CData = array();
    12. /* Put each attribute into the Data array. */
    13. while ( list($Key, $Val) = each($Attr) ) {
    14. $Data["$Elem:$Key"] = trim($Val);
    15. // debug // echo "$Elem:$Key = " . $Data["$Elem:$Key"] . "\n";
    16. }
    17. }
    18. //Runs each time XML character data is encountered
    19. function CharacterHandler(&$Parser, &$Line) {
    20. global $CData;
    21. /*
    22. * Place lines into an array because elements
    23. * can contain more than one line of data.
    24. */
    25. $CData[] = $Line;
    26. }
    27. //Runs each time an XML element ends
    28. function EndHandler(&$Parser, &$Elem) {
    29. global $Data, $CData, $listeners, $server, $song, $dj, $wee;
    30. //Mush all of the CData lines into a string and put it into the $Data array.
    31. $Data[$Elem] = trim( implode('', $CData) );
    32. //echo "$Elem = " . $Data[$Elem] . "<br>\n";
    33. switch ($Elem){
    34. //for each case, we are putting some data into a variable.
    35. case 'AIM':
    36. $dj['AIM'] = $Data['AIM'];
    37. break;
    38. }
    39. }
    40. //open connection
    41. $fp = fsockopen("$host", $port, &$errno, &$errstr, 30);
    42. if (!$fp) {
    43. echo "Die Verbindung zum Server konnte nicht hergestellt werden! <BR>";
    44. }
    45. else {
    46. //request xml
    47. fputs($fp,"GET /admin.cgi?pass=".$password."&mode=viewxml&page=0 HTTP/1.0\nUser-Agent: Mozilla Compatible\n\n");
    48. while(!feof($fp)) {
    49. //put xml into $Data
    50. $Contents .= fgets($fp, 1000);
    51. }
    52. }
    53. //close connection
    54. fclose($fp);
    55. $Contents = str_replace('HTTP/1.0 200 OK','', $Contents);
    56. $Contents = str_replace('Content-Type:text/xml','', $Contents);
    57. $Contents = str_replace("\n",'', $Contents);
    58. $Contents = str_replace("\r",'', $Contents);
    59. $Contents = preg_replace('/(&amp;|&)/i', '&amp;', $Contents);
    60. $Contents = preg_replace('/[^\x20-\x7E\x09\x0A\x0D]/', "\n", $Contents);
    61. $Data = array();
    62. // Initialize the parser.
    63. $Parser = xml_parser_create('ISO-8859-1');
    64. xml_set_element_handler($Parser, 'StartHandler', 'EndHandler');
    65. xml_set_character_data_handler($Parser, 'CharacterHandler');
    66. //Pass the content string to the parser.
    67. if (!xml_parse($Parser, $Contents)) {
    68. $Probs[] = "$URI$Sym\n Had problem parsing file:\n "
    69. . xml_error_string(xml_get_error_code($Parser));
    70. }
    71. if (isset($Probs)) {
    72. echo implode("\n", $Probs);
    73. }
    74. //Output
    75. $listeners['AVERAGETIME'] = $listeners[AVERAGETIME]/60;
    76. $wee = $wee -1;
    77. if (empty($Contents)) {
    78. echo '<IMG SRC="/images/pause.jpg" BORDER="0">';
    79. } else {
    80. $search = array('dj1','dj2','dj3');
    81. $replace = array('<IMG SRC="/images/dj1.jpg" BORDER="0">','<IMG SRC="/images/dj2.jpg" BORDER="0">','<IMG SRC="/images/dj3.jpg" BORDER="0">');
    82. echo str_replace($search, $replace, "
    83. <tr><td></td><td>{$dj[AIM]}</td></tr>\n
    84. ")
    85. }
    86. ?>
    Alles anzeigen
  • Habs doch noch geschafft.
    Für alle, die es auch interessiert:

    PHP-Quellcode

    1. <body bgcolor="#12447a">
    2. <?php
    3. $host = "IP"; //Host
    4. $port = "Port"; //Port
    5. $password = "Passwort"; //Server Password
    6. //Configuration Finished
    7. //Runs each time an XML element starts
    8. function StartHandler(&$Parser, &$Elem, &$Attr) {
    9. global $Data, $CData;
    10. /* Start with empty CData array. */
    11. $CData = array();
    12. /* Put each attribute into the Data array. */
    13. while ( list($Key, $Val) = each($Attr) ) {
    14. $Data["$Elem:$Key"] = trim($Val);
    15. // debug // echo "$Elem:$Key = " . $Data["$Elem:$Key"] . "\n";
    16. }
    17. }
    18. //Runs each time XML character data is encountered
    19. function CharacterHandler(&$Parser, &$Line) {
    20. global $CData;
    21. /*
    22. * Place lines into an array because elements
    23. * can contain more than one line of data.
    24. */
    25. $CData[] = $Line;
    26. }
    27. //Runs each time an XML element ends
    28. function EndHandler(&$Parser, &$Elem) {
    29. global $Data, $CData, $listeners, $server, $song, $dj, $wee;
    30. //Mush all of the CData lines into a string and put it into the $Data array.
    31. $Data[$Elem] = trim( implode('', $CData) );
    32. //echo "$Elem = " . $Data[$Elem] . "<br>\n";
    33. switch ($Elem){
    34. //for each case, we are putting some data into a variable.
    35. case 'AIM':
    36. $dj['AIM'] = $Data['AIM'];
    37. break;
    38. }
    39. }
    40. ?><!--<?php
    41. $fp = fsockopen("$host", $port, &$errno, &$errstr, 30);
    42. ?>--><?php
    43. if (!$fp) {
    44. ?><tr><td></td><td><IMG SRC="/images/pause.jpg" BORDER="0"></td></tr><?php
    45. }
    46. else {
    47. fputs($fp,"GET /admin.cgi?pass=".$password."&mode=viewxml&page=0 HTTP/1.0\nUser-Agent: Mozilla Compatible\n\n");
    48. while(!feof($fp)) {
    49. $Contents .= fgets($fp, 1000);
    50. }
    51. fclose($fp);
    52. # Daten vom Stream Parsen:
    53. $Contents = str_replace('HTTP/1.0 200 OK','', $Contents);
    54. $Contents = str_replace('Content-Type:text/xml','', $Contents);
    55. $Contents = str_replace("\n",'', $Contents);
    56. $Contents = str_replace("\r",'', $Contents);
    57. $Contents = preg_replace('/(&amp;|&)/i', '&amp;', $Contents);
    58. $Contents = preg_replace('/[^\x20-\x7E\x09\x0A\x0D]/', "\n", $Contents);
    59. $Data = array();
    60. $Parser = xml_parser_create('ISO-8859-1');
    61. xml_set_element_handler($Parser, 'StartHandler', 'EndHandler');
    62. xml_set_character_data_handler($Parser, 'CharacterHandler');
    63. //Pass the content string to the parser.
    64. if (!xml_parse($Parser, $Contents)) {
    65. $Probs[] = "$URI$Sym\n Had problem parsing file:\n " . xml_error_string(xml_get_error_code($Parser));
    66. echo implode("\n", $Probs);
    67. }
    68. //Output
    69. if ($Data['STREAMSTATUS'] == 0) {
    70. ?><tr><td></td><td><IMG SRC="/images/pause.jpg" BORDER="0"></td></tr><?php
    71. }
    72. else {
    73. $search = array('dj1','dj2','dj3');
    74. $replace = array('<IMG SRC="/images/dj1.jpg" BORDER="0">','<IMG SRC="/images/dj2.jpg" BORDER="0">','<IMG SRC="/images/dj3.jpg" BORDER="0">');
    75. echo str_replace($search, $replace, "<tr><td></td><td>{$dj['AIM']}</td></tr>");
    76. }
    77. }
    78. ?>
    Alles anzeigen