22 Listopad 2024, 10:42:14

Autor Wątek: Problem z odświeżaniem  (Przeczytany 9129 razy)

Odświeżanie

  • Gość
Problem z odświeżaniem
« dnia: 02 Maj 2013, 14:07:29 »
Witam, czy mógłby ktoś dodać coś do tego skryptu żeby automatycznie się on odświeżał?

<?php// KONFIGURACJE$config[&#39;ip&#39;] = "4stream.pl";		// podajemy ip lub host serwera$config[&#39;port&#39;] = "18032";			// podajemy port serwera$config[&#39;haslo&#39;] = "XXX";		// podajemy haslo do nadawania na serwer shoutcast// KONIEC KONFIGURACJII/*=================================================================================*/header(&#39;Content-type: text/html;charset=iso-8859-2&#39;);$scfp = @fsockopen($config[ip], $config[port], &$errno, &$errstr, 30);if (!$scfp){	echo &#39;<font face="Verdana" size="2" color="#000000"><b>Docelowy serwer SHOUTcast jest wył±czony!</b></font>&#39;;}else{	fputs($scfp,"GET /admin.cgi?pass=$config[haslo]&mode=viewxml HTTP/1.0\r\nUser-Agent: SHOUTcast Song Status (Mozilla Compatible)\r\n\r\n");	while(!feof($scfp))	{		$page .= fgets($scfp, 1000);	}	$loop = array("STREAMSTATUS", "BITRATE");	$y=0;	while($loop[$y]!=&#39;&#39;)	{		$pageed = ereg_replace(".*<$loop[$y]>", "", $page);		$scphp = strtolower($loop[$y]);		$$scphp = ereg_replace("</$loop[$y]>.*", "", $pageed);		if ($loop[$y]==SERVERGENRE || $loop[$y]==SERVERTITLE || $loop[$y]==SONGTITLE)		{			$$scphp = urldecode($$scphp);		}		$y++;	}	$pageed = ereg_replace(".*<SONGHISTORY>", "", $page);	$pageed = ereg_replace("<SONGHISTORY>.*", "", $pageed);	$songatime = explode("<SONG>", $pageed);	$r=1;	while($songatime[$r]!="")	{		$t=$r-1;		$playedat[$t] = ereg_replace(".*<PLAYEDAT>", "", $songatime[$r]);		$playedat[$t] = ereg_replace("</PLAYEDAT>.*", "", $playedat[$t]);		$song[$t] = ereg_replace(".*<TITLE>", "", $songatime[$r]);		$song[$t] = ereg_replace("</TITLE>.*", "", $song[$t]);		$song[$t] = urldecode($song[$t]);		$r++;	}	fclose($scfp);	$skroc = &#39;50&#39;;echo&#39;<table cellspacing="0" cellpadding="0" background="http://eradia.pl/files/user/scsong.jpg" border="0" width="442">  <tr>    <td valign="top" height="0">	<font face="Verdana" size="2" color="#000000">		<br>	<p style="margin-top: 6; margin-bottom: 0">&nbsp;&nbsp; &#39;; if (strlen($song[1])>$skroc) { echo substr($song[1], 0, $skroc).&#39;...&#39;; } else { echo $song[1]; } echo &#39;</p>	<p style="margin-top: 6; margin-bottom: 0">&nbsp;&nbsp; &#39;; if (strlen($song[2])>$skroc) { echo substr($song[2], 0, $skroc).&#39;...&#39;; } else { echo $song[2]; } echo &#39;</p> 	<p style="margin-top: 7; margin-bottom: 0">&nbsp;&nbsp; &#39;; if (strlen($song[3])>$skroc) { echo substr($song[3], 0, $skroc).&#39;...&#39;; } else { echo $song[3]; } echo &#39;</p>	<p style="margin-top: 6; margin-bottom: 0">&nbsp;&nbsp; &#39;; if (strlen($song[4])>$skroc) { echo substr($song[4], 0, $skroc).&#39;...&#39;; } else { echo $song[4]; } echo &#39;</p>	<p style="margin-top: 7; margin-bottom: 0">&nbsp;&nbsp; &#39;; if (strlen($song[5])>$skroc) { echo substr($song[5], 0, $skroc).&#39;...&#39;; } else { echo $song[5]; } echo &#39;</p><p style="margin-top: 7; margin-bottom: 0">&nbsp;&nbsp; &#39;; if (strlen($song[6])>$skroc) { echo substr($song[6], 0, $skroc).&#39;...&#39;; } else { echo $song[6]; } echo &#39;</p>		</font>    </td>  </tr></table>&#39;;}?>


Ale w taki sposób żeby odświeżała się tylko ta część strony a nie cała strona.
« Ostatnia zmiana: 06 Maj 2013, 08:53:48 wysłana przez Karol »

Odświeżanie

  • Gość
Odp: Problem z odświeżaniem
« Odpowiedź #1 dnia: 05 Maj 2013, 15:19:35 »
Tak.

Grott

  • Webmaster
  • Radiowiec
  • *****
  • Wiadomości: 43
    • Status GG
    • Mazury Woda Wiatr Zagle Szanty
Odp: Problem z odświeżaniem
« Odpowiedź #2 dnia: 05 Maj 2013, 17:39:53 »
Wynika z tego, że jest to skrypcik ukazujący historię granych utworków. Podrzucam Tobie dwa, świetnie ze sobą współpracujace skrypty. Pierwszy to cast.php, drugi to shoutcast_class.php i tak je nazwij. Oba wyślij na serwer do głównego katalogu lub lub utworz katalog o nazwie np. cast, wazne aby oba pliki były w tym samym katalogu. W skrypcie cast.php musisz podać dokładną ścieżke dostępu do plików. Skrypt cast.php najlepiej wyświetlać za pomoca <iframe src="http://twoj.serwer.pl/cast.php" allowTransparency="false" align="center" width="320" height="100" scrolling="no" frameborder="0"></iframe> Wysokość i szerokość ramki dostosujesz do swoich potrzeb. W linii <body text="#FFFF00" bgcolor="#483848" > kolor tekstu oraz kolor tła można dowolnie ustawiać.
<?phpinclude "shoutcast_class.php";$ip	= "4stream.pl";$port	= "18032";?>

<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<META HTTP-EQUIV="REFRESH" CONTENT="30;URL=http://twoj.serwer.pl/cast.php">
 <title></title>
<body text="#FFFF00" bgcolor="#483848" >
 <style type="text/css">
.songOverview {
width:100%;
border:0px solid black;
background-color: #483848;
font-family:Tahoma;
font-size:12;
}
 </style>
</head>
<?php$radio = new Radio($ip.":".$port);echo $radio->getHistoryTable("/played.html", "", "", "songOverview");?>

</body>
</html>
i drugi skrypcik, tu nic nie zmieniaj, odświeżanie ustawione jest na 30 s. Powodzenia!
<?phpclass Radio{	var $fields = array();	var $fieldsDefaults = array(					"Server Status",					"Stream Status",					"Listener Peak",					"Average Listen Time",					"Stream Title",					"Content Type",					"Current Listeners",					"Stream Genre",					"Stream Description",					"Stream URL",					"Stream AIM"	,					"Stream IRC"	,					"Current Song",					"Current Listeners",					"Bitrate"	);	var $usingDefaults;	var $very_first_str;	var $domain, $port, $path;	var $errno, $errstr;	var $trackLists = array();	var $isShoutcast, $isIcecast;	var $nonShoutcastData = array(					"Server Status"		=> "n/a",					"Server Type"		=> "n/a",					"Stream Status"		=> "n/a",					"Listener Peak"		=> "n/a",					"Average Listen Time"	=> "n/a",					"Stream Title"		=> "n/a",					"Content Type"		=> "n/a",					"Stream Genre"		=> "n/a",					"Stream Description"	=> "n/a",					"Stream URL"		=> "n/a",					"Stream AIM"		=> "n/a",					"Stream IRC"		=> "n/a",					"Current Song"		=> "n/a",					"Current Listeners"	=> "n/a",					"Bitrate"		=> "n/a"					);	var $altServer = False;	function Radio($url)	{		$parsed_url = parse_url($url);		$this->domain	= isset($parsed_url[&#39;host&#39;]) ? $parsed_url[&#39;host&#39;] : "";		$this->port	= !isset($parsed_url[&#39;port&#39;]) || empty($parsed_url[&#39;port&#39;]) ? "80" : $parsed_url[&#39;port&#39;];		$this->path	= empty($parsed_url[&#39;path&#39;]) ? "/" : $parsed_url[&#39;path&#39;];		if (empty($this->domain))		{			$this->domain = $this->path;			$this->path = "";		}		$this->setOffset("Current Stream Information");		$this->setFields();		// setting default fields		$this->setTableStart("<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">");		$this->setTableEnd("</table>");	}	function setFields($array=False)	{		if (!$array)		{			$this->fields = $this->fieldsDefaults;			$this->usingDefaults = true;		}		else		{			$this->fields = $array;		}	}	function setOffset($string)	{		$this->very_first_str = $string;	}	function setTableStart($string)	{		$this->tableStart = $string;	}	function setTableEnd($string)	{		$this->tableEnd = $string;	}	function getHTML($page=False)	{		if (!$page)			$page = $this->path;		$contents = "";		$domain = (substr($this->domain, 0, 7) == "http://") ? substr($this->domain, 7) : $this->domain;		if (@$fp = fsockopen($domain, $this->port, $this->errno, $this->errstr, 2))		{			fputs($fp, "GET ".$page." HTTP/1.1\r\n".				"User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)\r\n".				"Accept: */*\r\n".				"Host: ".$domain."\r\n\r\n");			$c = 0;			while (!feof($fp) && $c <= 20)			{				$contents .= fgets($fp, 4096);				$c++;			}			fclose ($fp);			$this->isShoutcast = False;			$this->isIcecast = False;			preg_match("/(Content-Type:)(.*)/i", $contents, $matches);			if (count($matches) > 0)			{				$contentType = trim($matches[2]);				if ($contentType == "text/html")				{					$this->isShoutcast = True;					return $contents;				}				else				{					$htmlContent = substr($contents, 0, strpos($contents, "\r\n\r\n"));					$dataStr = str_replace("\r", "\n", str_replace("\r\n", "\n", $contents));					$lines = explode("\n", $dataStr);					foreach ($lines AS $line)					{						if ($dp = strpos($line, ":"))						{							$key = substr($line, 0, $dp);							$value = trim(substr($line, ($dp+1)));							if (preg_match("/genre/i", $key))								$this->nonShoutcastData[&#39;Stream Genre&#39;] = $value;							elseif (preg_match("/name/i", $key))								$this->nonShoutcastData[&#39;Stream Title&#39;] = $value;							elseif (preg_match("/server/i", $key))								$this->nonShoutcastData[&#39;Stream Type&#39;] = $value;							elseif (preg_match("/description/i", $key))								$this->nonShoutcastData[&#39;Stream Description&#39;] = $value;							elseif (preg_match("/content-type/i", $key))								$this->nonShoutcastData[&#39;Content Type&#39;] = $value;							elseif (preg_match("/icy-br/i", $key))							{								$this->nonShoutcastData[&#39;Stream Status&#39;] = "Stream is up at ".$value."kbps";								$this->nonShoutcastData[&#39;Bitrate&#39;] = $value;								$this->isIcecast = True;							}							elseif (preg_match("/icy-notice2/i", $key))							{								$this->nonShoutcastData[&#39;Server Status&#39;] = "This is <span style=\"color: red;\">not</span> a Shoutcast server!";								if (preg_match("/ultravox/i", $value))									$this->nonShoutcastData[&#39;Server Status&#39;] .= " But an <a href=\"http://ultravox.aol.com/\" target=\"_blank\">Ultravox</a> Server";								$this->altServer = $value;							}							elseif (preg_match("/url/i", $key))								$this->nonShoutcastData[&#39;Stream URL&#39;] = $value;						}					}					if ($this->isIcecast)					{						$this->nonShoutcastData[&#39;Server Type&#39;] = "Icecast";						$this->getIcecastStatusHtml();					}					return nl2br($htmlContent);				}			}			else				return $contents;		}		else		{			return False;		}	}	function getIcecastStatusHtml($page = "/status.xsl")	{		$contents = "";		$domain = (substr($this->domain, 0, 7) == "http://") ? substr($this->domain, 7) : $this->domain;		if (@$fp = fsockopen($domain, $this->port, $this->errno, $this->errstr, 2))		{			fputs($fp, "GET ".$page." HTTP/1.1\r\n".				"User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)\r\n".				"Accept: */*\r\n".				"Host: ".$domain."\r\n\r\n");			$c = 0;			while (!feof($fp))			{				$contents .= fgets($fp, 4096);				$c++;			}			fclose ($fp);			$tables = explode("<table", $contents);			foreach ($tables AS $table)			{				if (preg_match("/(<td(.*)>".$this->nonShoutcastData[&#39;Stream Title&#39;]."<\/td>)/", $table))				{					$rows = explode("<tr>", $table);					foreach ($rows AS $row)					{						if (preg_match_all("/<td.*>(.*)<\/td>/siU", $row, $matches))						{							$type = trim(str_replace(":", "", $matches[1][0]));							$value = $matches[1][1];							if ($type == "Current Song")								$this->nonShoutcastData[&#39;Current Song&#39;] = $value;							elseif ($type == "Current Listeners")								$this->nonShoutcastData[&#39;Current Listeners&#39;] = $value;							elseif ($type == "Peak Listeners")								$this->nonShoutcastData[&#39;Listener Peak&#39;] = $value;						}					}				}			}		}	}	function getServerInfo($display_array=null, $very_first_str=null)	{		if (!isset($display_array))		{			if ($this->isShoutcast)			{				$display_array = $this->fields;			}			else			{				$display_array = array_keys($this->nonShoutcastData);			}		}		if (!isset($very_first_str))			$very_first_str = $this->very_first_str;		if ($html = $this->getHTML())		{			 // parsing the contents			$data = array();			foreach ($display_array AS $key => $item)			{				if ($this->isShoutcast)				{					$very_first_pos	= stripos($html, $very_first_str);					$first_pos	= stripos($html, $item, $very_first_pos);					$line_start	= strpos($html, "<td>", $first_pos);					$line_end	= strpos($html, "</td>", $line_start) + 4;					$difference	= $line_end - $line_start;					$line		= substr($html, $line_start, $difference);					$data[$key]	= strip_tags($line);				}				else				{					$data[$item]	= $this->nonShoutcastData[$item];				}			}			return $data;		}		else		{			return $this->errstr." (".$this->errno.")";		}	}	function createHistoryArray($page)	{		if (!in_array($page, $this->trackLists))		{			$this->trackLists[] = $page;			if ($html = $this->getHTML($page))			{				$fromPos	= stripos($html, $this->tableStart);				if (!$fromPos)				{					$fromPos	= stripos($html, str_replace("\"", "", $this->tableStart));				}				$toPos		= stripos($html, $this->tableEnd, $fromPos);				$tableData	= substr($html, $fromPos, ($toPos-$fromPos));				$lines		= explode("</tr><tr>", $tableData);				$tracks = array();				$c = 0;				foreach ($lines AS $line)				{					$info = explode ("</td><td>", $line);					$time = trim(strip_tags($info[0]));					if (substr($time, 0, 9) != "Copyright" && !preg_match("/Tag Loomis, Tom Pepper and Justin Frankel/i", $info[1]))					{						$this->tracks[$c][&#39;time&#39;] = $time;						$this->tracks[$c++][&#39;track&#39;] = trim(strip_tags($info[1]));					}				}				if (count($this->tracks) > 0)				{					unset($this->tracks[0]);					if (isset($this->tracks[1]))						$this->tracks[1][&#39;track&#39;] = str_replace("Current Song", "", $this->tracks[1][&#39;track&#39;]);				}			}			else			{				$this->tracks[0] = array("time"=>$this->errno, "track"=>$this->errstr);			}		}	}	function getHistoryArray($page="/played.html")	{		if (!in_array($page, $this->trackLists))			$this->createHistoryArray($page);		return $this->tracks;	}	function getHistoryTable($page="/played.html", $timeColText=False, $trackColText=False, $class=False)	{		if (!in_array($page, $this->trackLists))			$this->createHistoryArray($page);		$output = "<table".($class ? " class=\"".$class."\"" : "").">";		if ($timeColText && $trackColText)			$output .= "<tr><td>".$timeColText."</td><td>".$trackColText."</td></tr>";		foreach ($this->tracks AS $trackArr)			$output .= "<tr><td>".$trackArr[&#39;time&#39;]."</td><td>".$trackArr[&#39;track&#39;]."</td></tr>";		$output .= "</table>\n";		return $output;	}} // this is needed for those with a php version < 5 // the function is copied from the user comments @ php.net (http://nl3.php.net/stripos)if (!function_exists("stripos")){	function stripos($haystack, $needle, $offset=0)	{		return strpos(strtoupper($haystack), strtoupper($needle), $offset);	}}?>
navigare necesse est...
http://mwwzs.mazury.pl

Grott

  • Webmaster
  • Radiowiec
  • *****
  • Wiadomości: 43
    • Status GG
    • Mazury Woda Wiatr Zagle Szanty
Odp: Problem z odświeżaniem
« Odpowiedź #3 dnia: 05 Maj 2013, 17:55:54 »
Sprawdzałem na Twoim radyjku, pięknie śmiga. Zobacz obrazek!
navigare necesse est...
http://mwwzs.mazury.pl

Odświeżanie

  • Gość
Odp: Problem z odświeżaniem
« Odpowiedź #4 dnia: 05 Maj 2013, 19:32:25 »
Hej Grott, dziękuję ale czy to zadziała z wordpressem? :)