<?php
###############################################################
################# Générateur de présentation  #################
###################### Version 1.0 Béta #######################
##################### Auteur : Belzebuth ######################
################### Version du script : 1.0 ###################
############ Mail : fantasygraph@fantasy-graph.net ############
###############################################################

// Fonctions

function getContenuURL($url,$estImg='')
{
	$ch = curl_init();

	curl_setopt ($ch, CURLOPT_URL, $url);
	curl_setopt ($ch, CURLOPT_HEADER, 0);
	ob_start();
	curl_exec ($ch);
	curl_close ($ch);
	$contenuPage = ob_get_contents();

	ob_end_clean();

	return $contenuPage;
}

// Chercher expression
function getEpression($chaine,$expression)
{
	preg_match_all($expression,$chaine, $trouve);

	if( count($trouve[0])!=0 )
	{
		return($trouve[1]);
	}
	else return(false);
}

//-------------------------------------

	function getListMangasNewscom($url)
	{
	global $url_default;
		$erreur = '';
		$mangas = '';

		if( $contenuUrl = getContenuURL($url) )
		{

			if($resultats = getEpression($contenuUrl,'#<h4 class="dvd">Dans les volumes DVD</h4>(.*?)</div> <!--end nom -->#is'))
			{
				$resultats = $resultats[0];

				if(preg_match_all('#<.*?>(.*?)</li>#is',$resultats, $lignesResultats))
				{
					$i = 0;

					foreach($lignesResultats[0] as $unResultat)
					{
						if($estUnManga=getEpression($unResultat,'#<li>(.*?)</li>#is'))
						{
							if( $categorieTmp = getEpression($unResultat,'#<h4 class="manga">(.*?)</h4>#is') )
							{
								$mangas[$i]['categorie'] = '<h4 class="manga">'.$categorieTmp[0].'</h4>';
							}

							if( $titreTmp = getEpression($unResultat,'#<a href=".+" title=".+" >(.*?)</a>#is') )
							{
								$mangas[$i]['titre'] = strip_tags(utf8_decode($titreTmp[0]));
							}

							if( $idTmp = getEpression($unResultat,'#<a href="http://www.manga-news.com/index.php/(.*?)" title=".+" >#is') )
							{
								$mangas[$i]['id'] = strip_tags($idTmp[0]);
							}
							$i++;
						}
					}
				}
			}
		}

	else  $erreur[] = "Impossible de lire la page .";

		return(array($mangas,$erreur));
	}

//-------------------------------------

	function getInfoMangaNewscom($url)
	{
		$erreur = '';

		if( $contenuUrl = getContenuURL($url) )
		{
			list($manga,$erreurs) = scanContenuNewscom($contenuUrl);
			if(!empty($date))
			{
				$manga['date'] = $date;
			}
			if(!empty($erreurs))
			{
				$erreur = array_merge($erreur,$erreurs);
			}
		}
		else $erreur[] = "impossible de lire la page";

		return(array($manga,$erreur));
	}

//-------------------------------------

	function scanContenuNewscom($contenuUrl)
	{
	global $url_default;
		$erreur = "";

			if( $titreTmp = getEpression($contenuUrl,'#<h2 class="entryTitle">(.*?)</h2>#is') )
			{
				$manga['titre'] = strip_tags(utf8_decode($titreTmp[0]));
			}
			else
			{
				$manga['titre'] = 'Aucune Information ...';
			}

			if( $auteurTmp = getEpression($contenuUrl,'# <li><strong>Auteur</strong>:(.*?)</li>#is') )
			{
				$manga['auteur'] = strip_tags(trim(utf8_decode($auteurTmp[0])));
				$manga['auteur'] = str_replace(array("\n","\r"),array("",""),$manga['auteur']);
				$manga['auteur'] = preg_replace("#\s\s#is","",$manga['auteur']);
			}
			else
			{
				$manga['auteur'] = 'Aucune Information ...';
			}

			if( $imageTmp = getEpression($contenuUrl,'#<a href="http://www.manga-news.com/public/images/dvd_volumes/(.*?)" class="cpModal" rel="[^"]+" title="[^"]+">#is') )
			{
				$manga['image'] = 'http://www.manga-news.com/public/images/dvd_volumes/' .$imageTmp[0];
			}
			elseif( $imageTmp = getEpression($contenuUrl,'#<img class="[^"]+" src="http://www.manga-news.com/public/images/dvd_volumes/(.*?)"
           alt="[^"]+" />#is') )
			{
				$manga['image'] = 'http://www.manga-news.com/public/images/dvd_volumes/' .$imageTmp[0];
			}
			elseif( $imageTmp = getEpression($contenuUrl,'#<a href="http://www.manga-news.com/public/images/vols/(.*?)" rel="[^"]+" title="[^"]+">#is') )
			{
				$manga['image'] = 'http://www.manga-news.com/public/images/vols/' .$imageTmp[0];
			}
			elseif( $imageTmp = getEpression($contenuUrl,'#<img class="[^"]+" src="http://www.manga-news.com/public/images/vols/(.*?)"
           alt="[^"]+" />#is') )
			{
				$manga['image'] = 'http://www.manga-news.com/public/images/dvd_volumes/' .$imageTmp[0];
			}
			else
			{
				$manga['image'] = $url_default.'images/no_image.png';
			}

			if( $studioTmp = getEpression($contenuUrl,'#<strong>Studios</strong>:(.*?)</li>#is') )
			{
				$manga['studio'] = strip_tags(trim(utf8_decode($studioTmp[0])));
				$manga['studio'] = str_replace(array("\n","\r"),array("",""),$manga['studio']);
				$manga['studio'] = preg_replace("#\s\s#is","",$manga['studio']);
			}
			else
			{
				$manga['studio'] = 'Aucune Information ...';
			}

			if( $typeTmp = getEpression($contenuUrl,'#<strong>Type</strong>:(.*?)</li>#is') )
			{
				$manga['type'] = strip_tags(utf8_decode(trim($typeTmp[0])));
				$manga['type'] = str_replace(array("\n","\r"),array("",""),$manga['type']);
				$manga['type'] = preg_replace("#\s\s#is","",$manga['type']);
			}
			else
			{
				$manga['type'] = 'Aucune Information ...';
			}

			if( $genreTmp = getEpression($contenuUrl,'#<strong>Genre</strong>:(.*?)</li>#is') )
			{
				$manga['genre'] = strip_tags(trim(utf8_decode($genreTmp[0])));
				$manga['genre'] = str_replace(array("\n","\r"),array("",""),$manga['genre']);
				$manga['genre'] = preg_replace("#\s\s#is","",$manga['genre']);
			}
			else
			{
				$manga['genre'] = 'Aucune Information ...';
			}

			if( $collectionTmp = getEpression($contenuUrl,'#<strong>Collection</strong>:(.*?)</li>#is') )
			{
				$manga['collectiona'] = strip_tags(trim(utf8_decode($collectionTmp[0])));
				$manga['collection'] = '<b>Collection :</b> ' . $manga['collectiona'] . '<br />';
				$manga['collectionb'] = '[b][u]Collection[/u] : [/b] [i]' . $manga['collectiona'] . '[/i]' ."\n";
			}

			if( $editeurTmp = getEpression($contenuUrl,'#<strong>Editeur</strong>:(.*?)</li>#is') )
			{
				$manga['editeura'] = strip_tags(trim(utf8_decode($editeurTmp[0])));
				$manga['editeura'] = str_replace(array("\n","\r"),array("",""),$manga['editeura']);
				$manga['editeura'] = preg_replace("#\s\s#is","",$manga['editeura']);
				$manga['editeur'] = '<b>Éditeur :</b> ' . $manga['editeura'] . '<br />';
				$manga['editeurb'] = '[b][u]Editeur[/u] : [/b] [i]' . $manga['editeura'] . '[/i]' ."\n";
			}
			elseif( $editeurTmp = getEpression($contenuUrl,'#<strong>Editeur VO</strong>:(.*?)</li>#is') )
			{
				$manga['editeura'] = strip_tags(trim(utf8_decode($editeurTmp[0])));
				$manga['editeura'] = str_replace(array("\n","\r"),array("",""),$manga['editeura']);
				$manga['editeura'] = preg_replace("#\s\s#is","",$manga['editeura']);
				$manga['editeur'] = '<b>Éditeur VO:</b> ' . $manga['editeura'] . '<br />';
				$manga['editeurb'] = '[b][u]Editeur VO[/u] : [/b] [i]' . $manga['editeura'] . '[/i]' ."\n";
			}
			else
			{
				$manga['editeur'] = '<b>Éditeur :</b>Aucune Information ...<br />';
				$manga['editeurb'] = '[b][u]Editeur[/u] : [/b] [i]Aucune Information ...[/i]' ."\n";
			}

			if( $prepubTmp = getEpression($contenuUrl,'#<strong>PrÃ©publication</strong>:(.*?)</li>#is') )
			{
				$manga['prepuba'] = strip_tags(trim(utf8_decode($prepubTmp[0])));
				$manga['prepuba'] = str_replace(array("\n","\r"),array("",""),$manga['prepuba']);
				$manga['prepuba'] = preg_replace("#\s\s#is","",$manga['prepuba']);
				$manga['prepub'] = '<b>Prépublication :</b> ' . $manga['prepuba'] . '<br />';
				$manga['prepubb'] = '[b][u]Prépublication[/u] : [/b] [i]' . $manga['prepuba'] . '[/i]' ."\n";
			}

			if( $datepubTmp = getEpression($contenuUrl,'#<strong>Date de publication</strong>:(.*?)</li>#is') )
			{
				$manga['datepuba'] = strip_tags(trim(utf8_decode($datepubTmp[0])));
				$manga['datepub'] = '<b>Date de publication :</b> ' . $manga['datepuba'] . '<br />';
				$manga['datepubb'] = '[b][u]Date de publication[/u] : [/b] [i]' . $manga['datepuba'] . '[/i]' ."\n";
			}

			if( $nbvolTmp = getEpression($contenuUrl,'#<strong>Nbr de volume\(s\) VO</strong>:(.*?)</li>#is') )
			{
				$manga['nbvola'] = strip_tags(trim(utf8_decode($nbvolTmp[0])));
				$manga['nbvola'] = str_replace(array("\n","\r"),array("",""),$manga['nbvola']);
				$manga['nbvola'] = preg_replace("#\s\s#is","",$manga['nbvola']);
				$manga['nbvol'] = '<b>Nbr de volume(s) VO :</b> ' . $manga['nbvola'] . '<br />';
				$manga['nbvolb'] = '[b][u]Nbr de volume(s) VO[/u] : [/b] [i]' . $manga['nbvola'] . '[/i]' ."\n";
			}

			if( $EANTmp = getEpression($contenuUrl,'#<strong>Code EAN</strong>:(.*?)</li>#is') )
			{
				$manga['EANa'] = strip_tags(trim(utf8_decode($EANTmp[0])));
				$manga['EAN'] = '<b>Code EAN :</b> ' . $manga['EANa'] . '<br />';
				$manga['EANb'] = '[b][u]Code EAN[/u] : [/b] [i]' . $manga['EANa'] . '[/i]' ."\n";
			}

			if( $dateTmp = getEpression($contenuUrl,'#<strong>Date de sortie</strong>:(.*?)</li>#is') )
			{
				$manga['datea'] = strip_tags(trim(utf8_decode($dateTmp[0])));
				$manga['date'] = '<b>Date de sortie :</b> ' . $manga['datea'] . '<br />';
				$manga['dateb'] = '[b][u]Date de sortie[/u] : [/b] [i]' . $manga['datea'] . '[/i]' ."\n";
			}

			if( $anprodTmp = getEpression($contenuUrl,'#<strong>AnnÃ©e de production</strong>:(.*?)</li>#is') )
			{
				$manga['anproda'] = strip_tags(trim(utf8_decode($anprodTmp[0])));
				$manga['anprod'] = '<b>Année de production :</b> ' . $manga['anproda'] . '<br />';
				$manga['anprodb'] = '[b][u]Année de production[/u] : [/b] [i]' . $manga['anproda'] . '[/i]' ."\n";
			}

			if( $languageTmp = getEpression($contenuUrl,'#<strong>Langue</strong>:(.*?)</li>#is') )
			{
				$manga['languagea'] = strip_tags(trim(utf8_decode($languageTmp[0])));
				$manga['language'] = '<b>Langue :</b> ' . $manga['languagea'] . '<br />';
				$manga['languageb'] = '[b][u]Langue[/u] : [/b] [i]' . $manga['languagea'] . '[/i]' ."\n";
			}

			if( $episodeTmp = getEpression($contenuUrl,'#<strong>Nbr d\'Ã©pisode\(s\)</strong>:(.*?)</li>#is') )
			{
				$manga['episodea'] = strip_tags(trim(utf8_decode($episodeTmp[0])));
				$manga['episode'] = '<b>Nbr d\'épisode(s) :</b> ' . $manga['episodea'] . '<br />';
				$manga['episodeb'] = '[b][u]Nbr d\'épisode(s)[/u] : [/b] [i]' . $manga['episodea'] . '[/i]' ."\n";
			}

			if( $publicTmp = getEpression($contenuUrl,'#<strong>Pour public averti</strong>:(.*?)</li>#is') )
			{
				$manga['publica'] = strip_tags(trim(utf8_decode($publicTmp[0])));
				$manga['public'] = '<b>Pour public averti :</b> ' . $manga['publica'] . '<br />';
				$manga['publicb'] = '[b][u]Pour public averti[/u] : [/b] [i]' . $manga['publica'] . '[/i]' ."\n";
			}

			if( $ageTmp = getEpression($contenuUrl,'#<strong>Age conseillÃ©</strong>:(.*?)</li>#is') )
			{
				$manga['agea'] = strip_tags(trim(utf8_decode($ageTmp[0])));
				$manga['age'] = '<b>Age conseillé :</b> ' . $manga['agea'] . '<br />';
				$manga['ageb'] = '[b][u]Age conseillé[/u] : [/b] [i]' . $manga['agea'] . '[/i]' ."\n";
			}

			if( $commerceTmp = getEpression($contenuUrl,'#<strong>Commercialisation</strong>:(.*?)</li>#is') )
			{
				$manga['commercea'] = strip_tags(trim(utf8_decode($commerceTmp[0])));
				$manga['commerce'] = '<b>Commercialisation :</b> ' . $manga['commercea'] . '<br />';
				$manga['commerceb'] = '[b][u]Commercialisation[/u] : [/b] [i]' . $manga['commercea'] . '[/i]' ."\n";
			}

			if( $synopsisTmp = getEpression($contenuUrl,'#<div id="summary">(.*?)</div>#is') )
			{
				$synopsis = str_replace(array("’","…","œ","\n\n\n"),array("'","...","oe","\n"),$synopsisTmp[0]);
				$synopsis = str_replace(array('<div id="bonus">',"<h3>","</h3>","<pre>","</pre>"),array("","<br /><font color=red><b><u>","</u></b></font><br /><br />","",""),$synopsisTmp[0]);
				$manga['synopsis'] = trim(utf8_decode($synopsis));
				$manga['synopsis'] = str_replace(array("<p>","</p>","?","	","    ","N/C"),array("","","'","","","Aucune Synopsis de la part de Mangas-news.com"),$manga['synopsis']);
				$manga['synopsisb'] = str_replace("<br />","",$manga['synopsis']);
				$manga['synopsisb'] = str_replace(array("\n\n","   "),array("\n"," "),$manga['synopsisb']);
				$manga['synopsisb'] = str_replace(array("?","<br /><br />","<br />","<font color=red><b><u>","</u></b></font>","<div style=\"font-size: 8pt;\">-","N/C"),array(" ","\n","\n","[color=red][b][u]","[/u][/b][/color]\n"," ","Aucune Synopsis de la part de Mangas-news.com"),$manga['synopsis']);
			}
			else
			{
				$manga['synopsis'] = 'Aucune Synopsis de la part de Mangas-news.com ...<br /><img src="images/manga-news.png" alt="" />';
				$manga['synopsisb'] = 'Aucune Synopsis de la part de Mangas-news.com ...';
			}
			return(array($manga,$erreur));
	}

?>