"] = ">\n"; // php5 ne détecte pas les encodages XML (bug??) //$trans["iso-8859-15"] = "iso-8859-1"; //$trans["UTF-8"] = "iso-8859-1"; if (isset($convert) && $convert="on") $data = utf8_decode(strtr(implode("",file($root.$filename)),$trans)); else $data = implode("",file($root.$filename)); //$data = html_entity_decode($data); // initialise les compteurs $cpt = 0; $index_item = 0; // parse le fichier et remplit les tableaux $p = xml_parser_create(""); xml_parser_set_option($p, XML_OPTION_TARGET_ENCODING, "iso-8859-1"); xml_parse_into_struct($p,$data,&$vals,&$index); xml_parse_into_struct($p,$data,$vals,$index); xml_parser_free($p); // parcourt et récupère les données foreach($index as $key->$val) { $array = $key->$val; $pos = $array[0]; $tag = $vals[$pos][tag]; $val = $vals[$pos][value]; if ($tag == "ITEM") { while ($index[ITEM][$index_item] != "") { $tag2 = $vals[$index[ITEM][$index_item]+1][tag]; $value2 = $vals[$index[ITEM][$index_item]+1][value]; $index_item++; if ($tag2 == "TITLE") { $items[$cpt]["title"] = $value2; // echo "$value2"; } if ($tag2 == "LINK") $items[$cpt++]["link"] = $value2; } } } return $items; } function parse_rss2($filename) { $root = "/web/website/backends/xml/"; $xml = simplexml_load_file($root.$filename); $cpt = 0; foreach($xml->channel->item as $news) { $items[$cpt]["title"] = utf8_decode((string) $news->title); $items[$cpt++]["link"] = $news->link; //echo '', utf8_decode((string) $news->title), '
'; } return $items; } //************************************************* //* renvoie les données supplémentaires d'un site * //* à partir d'un fichier backend RSS * //************************************************* function get_sitedata($filename) { $root = "/web/website/backends/xml/"; // extrait le nom du fichier if (file_exists($root.$filename)) $data = implode("",file($root.$filename)); // initialise les compteurs $index_textinput = 0; $sitedata["language"] = ""; /*********************** partie parser **********************/ // parse le fichier et remplit les tableaux $p = xml_parser_create(); xml_parse_into_struct($p,$data,&$vals,&$index); xml_parser_free($p); // parcourt et récupère les données foreach($index as $key->$val) { $array = $key->$val; $pos = $array[0]; $tag = $vals[$pos][tag]; $val = htmlspecialchars($vals[$pos][value]); if ($tag == "RSS") { $sitedata["rss_ver"] = $vals[$index[RSS][$pos]][attributes][VERSION]; } else if ($tag == "TITLE") { $sitedata["title_site"] = utf8_decode($val); $index_title++; } else if ($tag == "LINK") { $sitedata["link_site"] = $val; $index_link++; } else if ($tag == "DESCRIPTION") { $sitedata["description"] = $val; } else if ($tag == "LANGUAGE") { $sitedata["language"] = $val; } else if ($tag == "IMAGE") { $sitedata["image_title"] = $vals[$index[TITLE][$index_title]][value]; $index_link++; } else if ($tag == "URL") { $sitedata["image_url"] = $val; } else if ($tag == "WIDTH") { $sitedata["image_width"] = $val; } else if ($tag == "HEIGHT") { $sitedata["image_height"] = $val; } else if ($tag == "TEXTINPUT") { while ($index[TEXTINPUT][$index_textinput] != "") { $tag2 = $vals[$index[TEXTINPUT][$index_textinput]+1][tag]; $value2 = $vals[$index[TEXTINPUT][$index_textinput]+1][value]; $index_textinput++; if ($tag2 == "TITLE") { $sitedata["textinput_title"] = $value2; } else if ($tag2 == "DESCRIPTION") { $sitedata["textinput_description"] = $value2; } else if ($tag2 == "NAME") { $sitedata["textinput_name"] = $value2; } else if ($tag2 == "LINK") { $sitedata["textinput_link"] = $value2; } } } else {} } return $sitedata; } //*********************************************** //* renvoie les titres d'un fichier backend TXT * //*********************************************** //* forme la plus simple: * //*********************************************** //* %% * //* title * //* link * //* %% * //*********************************************** function parse_text_1($filename) { $data = file($filename); while($data[$index] != "") { if (!strchr("%",$data[$index])) { $items[$index]["title"] = $data[$index]; $items[$index]["link"] = $data[$index++]; } else $index++; } return $items; } //************************************** //* renvoie les titres d'une page HTML * //************************************** function parse_html($filename,$regs) { $index=$index_item=0; $data = file($filename); ereg($regs,$data[$index],$result); while($data[$index++] != "") { ereg($regs,$data[$index],$result); if ($result[1] != "") { if (strchr($result[1],"http://")) $item[$index_item]["link"] = strtok(urldecode($result[1]),"\""); else $item[$index_item]["link"] = $url_site.strtok(urldecode($result[1]),"\""); $result[1]=""; } if ($result[2] != "") { $item[$index_item++]["title"] = html2ascii($result[2]); $result[2] = ""; } } return $item; } function parse_html2($data,$regs) { $index=$index_item=0; ereg($regs,$data[$index],$result); while($data[$index++] != "") { ereg($regs,$data[$index],$result); if ($result[1] != "") { $item[$index_item]["link"] = strtok(urldecode($result[1]),"\""); $result[1]=""; } if ($result[2] != "") { $item[$index_item++]["title"] = $result[2]; $result[2] = ""; } } return $item; } ?>