begin process at 2010 03 22 05:20:10
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Divers

 > XO://REMOTE NEWS

XO://REMOTE NEWS


 Information sur la source

Note :
1 / 10 - par 1 personne
1,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Divers Niveau :Débutant Date de création :27/09/2003 Date de mise à jour :27/09/2003 17:52:53 Vu :2 889

Auteur : vbtom

Ecrire un message privé
Site perso
Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note

 Description

Cliquez pour voir la capture en taille normale
Salut,

Bon alors le truc c'est que j'avais un site avec des news ( http://cubelan.euroserv.com) et un autre ( http://rflood.free.fr) ou je voulais afficher les news du premier site, sans pour autant avoir accès a la bdd du premier site.

Donc socket a la rescousse.

A partir du premiere site (sur euroserv) je genere un fichier (http://cubelan.euroserv.com/rcube.php) qui renvoie les 10 dernieres news formattees, si vous affichez la source de ce fichier ca vous donne a peu pres ca:

<<NEWS id="17" postdate="1061935370" title="Quelques améliorations"></NEWS>
<NEWS id="16" postdate="1058392336" title="CL #1: Photos, démos et CyberLeagues"></NEWS>
<NEWS id="15" postdate="1058296051" title="CL #1: Thanks to"></NEWS>
<NEWS id="14" postdate="1058294744" title="CL #1: Bilan rapide"></NEWS>
<NEWS id="13" postdate="1058016380" title="CL #1: Préparatifs"></NEWS>
<NEWS id="12" postdate="1057939897" title="CL #1: Infos des derniers instants ..."></NEWS>
<NEWS id="11" postdate="1057695430" title="CL #1: Tournois Counter-strike,Warcraft3 et CyberLeagues"></NEWS>
<NEWS id="10" postdate="1057695005" title="CL #1: Prépaiement"></NEWS>
<NEWS id="9" postdate="1057236366" title="CL #1: Règlement CS"></NEWS>
<NEWS id="8" postdate="1057143070" title="Inscriptions"></NEWS>

Ca ressemble a du HTML.

Bon a partir de la, je crée un socket sur le 2e site(sur free) qui récupere la source du fichier (http://cubelan.euroserv.com/rcube.php) et qui récupère toutes les news et les affiches.

http://cubelan.euroserv.com > Page qui contient les news non formattées
http://cubelan.euroserv.com/rcube.php > Page qui contient les news formattées
http://rflood.free.fr/rnews.php > Page qui récupère les news et les affiches

Voici la source du fichier rnews.php quil suffit d'inclure dans une page pour afficher les news du site sur euroserv, apres c'est a vous d'adapter ca

Cette source s'appuie sur une autre source que j'avais poste ya pas longtemps:
http://phpcs.com/code.aspx?ID=13455 > XO:// HTML TAG MASTER

Source

  • <?
  • # -- CONFIGURATION - #
  • $conf_host = "cubelan.euroserv.com";
  • $conf_port = 80;
  • $conf_httpquery = "GET http://cubelan.euroserv.com/rcube.php HTTP/1.0\n\n";
  • $conf_limitnews = 5;
  • # -- /CONFIGURATION - #
  • function get_tagint($str_base,$str_tag)
  • {
  • $wprop_name_start = 1;
  • $ftag_end_pos = $wprop_name_end = $wprop_equal = $wprop_value = $wprop_value_start = $wprop_value_end = $prop_value_quote = 0;
  • $thiscar = $tag_int = $cprop_name = $cprop_value = $cprop_name_bu = "";
  • $properties = array();
  • $tag_startpos = strpos($str_base,"<$str_tag");
  • $tag_endpos = strpos($str_base,"</$str_tag>");
  • # - CHERCHE CHAQUE PROPRIETE DU TAG - #
  • for($i=(strlen($str_tag)+2);$i<($tag_endpos-$tag_startpos);$i++)
  • {
  • $thiscar = substr($str_base,$tag_startpos+$i,1);
  • if($wprop_name_start==1 && $thiscar!=" " && $thiscar!="=" && $thiscar!=">")
  • {
  • $cprop_name .= $thiscar;
  • $wprop_name_start = 0;
  • $wprop_name_end = 1;
  • }
  • elseif($wprop_name_start==1 && $thiscar==">")
  • {
  • $wprop_name_start = $wprop_name_end = $wprop_equal = $wprop_value_start = $wprop_value_end = $prop_value_quote = 0;
  • $ftag_end_pos = $tag_startpos+$i;
  • }
  • elseif($wprop_name_end==1 && $thiscar!=" " && $thiscar!="=")
  • {
  • $cprop_name .= $thiscar;
  • }
  • elseif($wprop_name_end==1 && ($thiscar==" " || $thiscar=="="))
  • {
  • $wprop_name_end = 0;
  • if($thiscar=="=") { $wprop_value_start = 1; }
  • $cprop_name_bu = $cprop_name;
  • $properties[$cprop_name_bu] = "tg";
  • $cprop_name = "";
  • }
  • elseif($wprop_value_start==1 && $thiscar!=" ")
  • {
  • if($thiscar == "\"") { $prop_value_quote=1; $wprop_value_start=0; $wprop_value_end=1; }
  • else { $prop_value_quote=0; $wprop_value_start=0; $wprop_value_end=1; $cprop_value.="$thiscar"; }
  • }
  • elseif($wprop_value_end==1)
  • {
  • if(($prop_value_quote==1 && $thiscar=="\"") || ($prop_value_quote==0 && $thiscar==" ")) { $wprop_value_end=0; $prop_value_quote=0; $wprop_name_start=1; $properties[$cprop_name_bu]=$cprop_value; $cprop_value="";}
  • else { $cprop_value.="$thiscar"; }
  • }
  • }
  • # - RECUPERE LE CONTENU DU TAG - #
  • $tag_int = substr($str_base,$ftag_end_pos+1,$tag_endpos-($ftag_end_pos+1));
  • $result = array();
  • $result[0] = $properties;
  • $result[1] = $tag_int;
  • return $result;
  • }
  • $rnws_source = $rnws_txt = $doc_headers = "";
  • $pos_pagestart = $headers_count = $headers_fnsh = 0;
  • $headers = array();
  • $fp = fsockopen($conf_host, $conf_port, &$errno, &$errstr, 30);
  • if(!$fp)
  • {
  • echo "err: $errstr ($errno)<br>\n";
  • }
  • else
  • {
  • fputs($fp,$conf_httpquery);
  • while(!feof($fp))
  • {
  • $rnws_source .= fgets($fp,128);
  • }
  • fclose($fp);
  • }
  • # - RECUPERE LES HEADERS, ET LES STOCK DANS UN ARRAY - #
  • $headers_tempo = "";
  • while($headers_fnsh == 0)
  • {
  • $line_endpos = strpos($rnws_source,"\r\n");
  • if($header_count == 0) { $headers_tempo = substr($rnws_source,0,$line_endpos); }
  • else { $headers_tempo = substr($rnws_source,2,$line_endpos); }
  • if($headers_tempo == "") { $headers_fnsh = 1; }
  • else
  • {
  • $headers[$headers_count] = $headers_tempo;
  • $rnws_source = substr($rnws_source,$line_endpos+2,strlen($rnws_source)-($line_endpos+2));
  • $headers_count += 1;
  • }
  • }
  • $rnws_source = substr($rnws_source,2,strlen($rnws_source)-2);
  • $arr_news = array();
  • $arr_news = split("</NEWS>",$rnws_source);
  • $news_counter = 0;
  • # - PARCOURE TOUTES LES NEWS - #
  • foreach($arr_news as $news_code => $news_rcode)
  • {
  • if($news_counter <= $conf_limitnews && ($news_rcode != "" && $news_rcode != "\n"))
  • {
  • $this_newsrcode = $news_rcode . "</NEWS>";
  • $rcode_props = array();
  • $rcode_props = get_tagint("$this_newsrcode","NEWS");
  • echo "<A style=\"font-family:verdana;font-size:11px;\">" .date("d/m/Y",$rcode_props[0][postdate]) . "</A> : <A style=\"font-family:verdana;font-size:11px;color:#0000aa;\" href=\"http://cubelan.euroserv.com/index.php?newsid=" .$rcode_props[0][id]. "\" target=_blank>" .$rcode_props[0][title] . "<BR>";
  • $news_counter += 1;
  • }
  • }
  • ?>
<?

# -- CONFIGURATION - #
$conf_host 		= "cubelan.euroserv.com";
$conf_port 		= 80;
$conf_httpquery = "GET http://cubelan.euroserv.com/rcube.php HTTP/1.0\n\n";
$conf_limitnews = 5;
# -- /CONFIGURATION - #

function get_tagint($str_base,$str_tag)
{		
	$wprop_name_start	= 1;		
	$ftag_end_pos		= $wprop_name_end = $wprop_equal = $wprop_value = $wprop_value_start = $wprop_value_end = $prop_value_quote = 0;	 
	$thiscar 			= $tag_int = $cprop_name = $cprop_value = $cprop_name_bu = "";			
	$properties			= array();
		
	$tag_startpos 		= strpos($str_base,"<$str_tag");
	$tag_endpos			= strpos($str_base,"</$str_tag>");
	
	# - CHERCHE CHAQUE PROPRIETE DU TAG - #
	for($i=(strlen($str_tag)+2);$i<($tag_endpos-$tag_startpos);$i++)
	{		
		$thiscar = substr($str_base,$tag_startpos+$i,1);		
		if($wprop_name_start==1 && $thiscar!=" " && $thiscar!="=" && $thiscar!=">")
		{			
			$cprop_name			.= $thiscar;	
			$wprop_name_start 	 = 0;	
			$wprop_name_end	 	 = 1;
		}
		elseif($wprop_name_start==1 && $thiscar==">")
		{	
			$wprop_name_start	= $wprop_name_end = $wprop_equal = $wprop_value_start = $wprop_value_end = $prop_value_quote = 0;
			$ftag_end_pos 		= $tag_startpos+$i;					
		}		
		elseif($wprop_name_end==1 && $thiscar!=" " && $thiscar!="=")
		{
			$cprop_name			.= $thiscar;	
		}
		elseif($wprop_name_end==1 && ($thiscar==" " || $thiscar=="="))
		{
			$wprop_name_end = 0;
			if($thiscar=="=") 		{ $wprop_value_start = 1; }
			$cprop_name_bu 					= $cprop_name;
			$properties[$cprop_name_bu] 	= "tg";			
			$cprop_name 					= "";
		}
		elseif($wprop_value_start==1 && $thiscar!=" ")
		{
			if($thiscar == "\"") 	{ $prop_value_quote=1; $wprop_value_start=0; $wprop_value_end=1; }
			else					{ $prop_value_quote=0; $wprop_value_start=0; $wprop_value_end=1; $cprop_value.="$thiscar"; }
		}
		elseif($wprop_value_end==1)
		{			
			if(($prop_value_quote==1 && $thiscar=="\"") || ($prop_value_quote==0 && $thiscar==" ")) 	{ $wprop_value_end=0; $prop_value_quote=0; $wprop_name_start=1; $properties[$cprop_name_bu]=$cprop_value; $cprop_value="";}
			else 																						{ $cprop_value.="$thiscar"; }
		}		
	}
		
	# - RECUPERE LE CONTENU DU TAG - #
	$tag_int 	= substr($str_base,$ftag_end_pos+1,$tag_endpos-($ftag_end_pos+1));	
	$result 	= array();
	$result[0] 	= $properties;
	$result[1] 	= $tag_int;
	
	return $result;
}



$rnws_source	= $rnws_txt 		= $doc_headers 	= "";
$pos_pagestart 	= $headers_count	= $headers_fnsh	= 0;
$headers		= array();


$fp 			= fsockopen($conf_host, $conf_port, &$errno, &$errstr, 30);
if(!$fp) 
{
	echo "err: $errstr ($errno)<br>\n";
} 
else 
{
	fputs($fp,$conf_httpquery);
	while(!feof($fp)) 
	{
		$rnws_source	.= fgets($fp,128);
	}
	fclose($fp);
}

# - RECUPERE LES HEADERS, ET LES STOCK DANS UN ARRAY - #
$headers_tempo = "";
while($headers_fnsh == 0)
{		
	$line_endpos = strpos($rnws_source,"\r\n");
	if($header_count == 0)	{ $headers_tempo = substr($rnws_source,0,$line_endpos); }
	else					{ $headers_tempo = substr($rnws_source,2,$line_endpos); }	
	
	if($headers_tempo == "")	{ $headers_fnsh = 1; }
	else
	{
		$headers[$headers_count] 	 = $headers_tempo;		
		$rnws_source				 = substr($rnws_source,$line_endpos+2,strlen($rnws_source)-($line_endpos+2));	
		
		$headers_count				+= 1;
	}
}

$rnws_source				 = substr($rnws_source,2,strlen($rnws_source)-2);	
$arr_news = array();
$arr_news = split("</NEWS>",$rnws_source);

$news_counter = 0;
# - PARCOURE TOUTES LES NEWS - #
foreach($arr_news as $news_code => $news_rcode)
{	
	if($news_counter <= $conf_limitnews && ($news_rcode != "" && $news_rcode != "\n"))
	{		
		$this_newsrcode  = $news_rcode . "</NEWS>";
		$rcode_props 	 = array();		
		$rcode_props	 = get_tagint("$this_newsrcode","NEWS");
		echo "<A style=\"font-family:verdana;font-size:11px;\">" .date("d/m/Y",$rcode_props[0][postdate]) . "</A> : <A style=\"font-family:verdana;font-size:11px;color:#0000aa;\" href=\"http://cubelan.euroserv.com/index.php?newsid=" .$rcode_props[0][id]. "\" target=_blank>" .$rcode_props[0][title] . "<BR>";
		$news_counter 	+= 1;
	}	
}

?>

 Conclusion

Ca peut etre utile, j'ai fait le plus gros du taff a vous dadapter :)

bisous
ToM.


 Sources du même auteur

Source avec une capture XO :// EASY PAGING
XO:// HTML TAG MASTER
XO://CONNAITRE LE NOMBRE DE JOURS DANS UN MOIS
XO.CALENDAR://V1.0
Source avec Zip Source avec une capture XO.FTP://BROWSER/V0.9.3B

 Sources de la même categorie

CALCUL D'UNE DISTANCE ORTHONORMIQUE par bossfoot
Source avec Zip ESPACE ADMIN SIMPLE par mousaid_88
Source avec Zip IMAGINE-CMS V2.20 par djack69
Source avec Zip AFFICHAGE ET GESTION DE DIAPORAMA EN PHP SANS BASE DE DONNÉE... par mldvb
Source avec Zip Source avec une capture PARSER ALLOCINE par cyrhades

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mars 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728
293031    

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,515 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales