<?php
ob_start
("ob_gzhandler");
//ATOM Feed de vagas no APInfo
$index 'http://apinfo.com/home.htm';
$content file($index);
$content implode(""$content);
$hash md5($content);
$headers getallheaders();
if (
ereg($hash$headers["If-None-Match"])){
    
header("HTTP/1.1 304 Not Modified");
    
ob_end_clean();
    exit();
}
$content iconv("windows-1252""utf-8"$content);
$content str_replace("\r"""$content);
$content str_replace("\n"""$content);
//print $content; exit();
preg_match("/<a href=\"http:\/\/www.apinfo\.com\/(.+)\.htm\" class=\"menu\" target=\"area2\"> *Pesquisar Vagas<\/a><\/font><\/td>/"$content$url_start);
$start 'http://www.apinfo.com/' $url_start[1] . '.htm';
//print $start; exit;
$content file($start);
$content implode(""$content);
$content iconv("windows-1252""utf-8"$content);
$content str_replace("\r"""$content);
$content str_replace("\n"""$content);
//print $content; exit();
preg_match("/<p><a href=\"http:\/\/www.apinfo.com\/(\w+).htm\">Vaga.+<\/a><\/p>/"$content$url_vagas);
$url 'http://www.apinfo.com/' $url_vagas[1] . '.htm';
//print $url; exit();
$content file($url);
$content implode(""$content);
$content iconv("windows-1252""utf-8"$content);
$content str_replace("&""&amp;"$content);
preg_match_all("/<CENTER><P><B><FONT COLOR=\"#\w+\">(.+) - ([A-Z]+) - (\d\d)\/(\d\d)\/(\d\d)<\/FONT><\/B><\/P><\/CENTER>/"$content$titles);
preg_match_all("/<B><FONT SIZE=\+1>(.+)<\/FONT><\/B>/"$content$cargos);
preg_match_all("/Empresa *\.+: *([^<]+)(<br>|<BR>)/"$content$empresas);
preg_match_all("/[Cc]ontato *\.+: *([^<]+)/"$content$contatos);
preg_match_all("/Código *\.+: *(\d+)<\/[Pp]>/"$content$codigos);
$content str_replace("<br>"""$content);
$content str_replace("<BR>"""$content);
$content str_replace("<b>"""$content);
$content str_replace("</b>"""$content);
preg_match_all("/<PRE>([^<]+)<\/PRE>/"$content$descrs);
preg_match_all("/<A HREF=mailto:([^>]+)>[^<]+<\/A>/"$content$emails);

header("Content-type: application/xml; charset=utf-8");

print 
'<?xml version="1.0" encoding="utf-8"?>' "\n";
if (isset(
$_GET['uf'])){
    
$uf strtoupper($_GET['uf']);
    
$pattern $uf;
} else {
    
$pattern '..';
}
?>
<feed version="0.3" xmlns="http://purl.org/atom/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="en">
    <title>Vagas APInfo.com<?php if (isset($uf)) print ' - ' $uf?></title>
    <link rel="alternate" type="text/html" href="<?php print $url?>" />
    <modified><?php print date("Y-m-d\TH:i:s\Z"?></modified>
    <tagline>Vagas APInfo.com - <?php if (isset($uf)) print $uf?></tagline>
    <id>tag:www.apinfo.com,<?php print date("Y-m-d"); ?>:/</id>
<?php
for ($i=0$i<sizeof($titles[0]); $i++){
  if (
ereg($pattern$titles[2][$i])){
  
$date date("Y-m-d\TH:i:s\Z"strtotime('20' $titles[5][$i] . '-' $titles[4][$i] . '-' $titles[3][$i] . ' 23:59:59') - ($i*125));
  
$date_id date("Y-m-d"strtotime('20' $titles[5][$i] . '-' $titles[4][$i] . '-' $titles[3][$i] . ' 23:59:59')  - ($i*125));
?>
    <entry>
        <title><?php print $cargos[1][$i]; ?></title>
        <link rel="alternate" type="text/html" href="<?php print $url "#" $codigos[1][$i]; ?>" />
        <modified><?php print $date?></modified>
        <issued><?php print $date?></issued>
        <id>tag:www.apinfo.com,<?php print $date_id.':' .  $codigos[1][$i]; ?></id>
        <summary type="text/html" mode="escaped" xml:lang="en" xml:base="http://www.apinfo.com/"><![CDATA[<?php print $descrs[1][$i] . "<br />\nEmpresa: <strong>" $empresas[1][$i] . "</strong>" .  "<br />\nContato: " $contatos[1][$i] . "<br />\nEnviar email para: <a href=\"mailto:" $emails[1][$i] . "\">" $emails[1][$i] . "</a>"?>]]></summary>
        <author>
            <name>APinfo</name>
        </author>
        <dc:subject><?php print $titles[1][$i] . ' - ' $titles[2][$i]; ?></dc:subject>
    </entry>
<?php
  
}
}
?>
</feed>
<?php
header
("ETag: \"$hash\"");
ob_end_flush();
?>