$Ndays[$month-1])
{
$month ++;
if ($month > 12) { $month = 01; $year ++; }
$day = 01;
}
if (strlen($day) == 1) $day = '0'.$day;
if (strlen($month) == 1) $month = '0'.$month;
return($year.'-'.$month.'-'.$day);
}
function check_tags($data, $allowed)
{
$data = preg_replace("/<(.*?)>/e",
"process_tag(StripSlashes('\\1'), \$allowed)",
$data);
$data = str_replace('javascript:','#',$data);
return $data;
}
function process_tag($data, $allowed)
{
# ending tags
if (preg_match("/^\/([a-z0-9]+)/i", $data, $matches)){
$name = StrToLower($matches[1]);
if (in_array($name, array_keys($allowed)))
{
return ''.$name.'>';
}else
return '';
}
# starting tags
if (preg_match("/^([a-z0-9]+)(.*?)(\/?)$/i", $data, $matches)){
$name = StrToLower($matches[1]);
$body = $matches[2];
$ending = $matches[3];
if (in_array($name, array_keys($allowed)))
{
$params = "";
preg_match_all("/([a-z0-9]+)=\"(.*?)\"/i", $body,$matches_2, PREG_SET_ORDER);
preg_match_all("/([a-z0-9]+)=([^\"\s]+)/i", $body,$matches_1, PREG_SET_ORDER);
$matches = array_merge($matches_1, $matches_2);
if ($name <>"img")
{
foreach($matches as $match)
{
$pname = StrToLower($match[1]);
if (in_array($pname, $allowed[$name]))
{
$params .= " $pname=\"$match[2]\"";
}
}
return '<'.$name/*.$params.$ending*/.'>';
}
else return '';
}
else
return '';
}
# garbage, ignore it
return '';
}
if ($submit)
{
global $HTTP_SERVER_VARS;
$tbl = array();
$DC = 0;
while(list($name,$value)=each($HTTP_POST_VARS))
{
if (!strncmp($name,"day",3))
{
$num = (int)$value;
$tbl[$num]=(int)$value;
$DC ++;
}
}
$errmsg = "";
$err = 0;
$startdt = clear_date_EN($startdt);
$enddt = clear_date_EN($enddt);
if (!$startdt) $startdt = $enddt;
if (!$enddt) $enddt = $startdt;
$rundt = $startdt;
while(1)
{
print '
Boat Itineraries for '.DescDayOfWeek($rundt).' '.EN_dayformat($rundt).'';
list($year,$month,$day) = explode('-',$rundt);
$src = 'http://www.openseas.gr/OPENSEAS/searchOutwardRoute.do?lang=el&from=RAF&to=AND&date='.$day.'%2F'.$month.'%2F'.$year.'&Submit.x=18&Submit.y=3';
$fp =@fopen ($src, "r")
or die ("
Ooops - No Data found , Maybe server is offline ".$src."
Please try later
Thank you
");
while (!feof ($fp))
{
$text .= fgets($fp,65000);
}
fclose($fp);
$num = 0;
// echo "file is ".$src."
";
while ($num < 10)
{
$text = substr($text, 7);
$pos1 = strpos($text, "
"."num ".$num." at ".$pos1." ".substr($text,1,60);
}
$pos2 = strpos($text, "
pos1 ".$pos1 ." pos2 " . $pos2."\n";
if (!is_integer($pos1))
print "not found STARTING TEXT
";
$text = substr($text, 0, $pos2);
$html_array = preg_split ('/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/', trim ($text), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$allowed = array(
'table'=> array('align','border','cellpadding','cellspacing','width','background'),
'tr'=> array('align','bgcolor','width','valign','align'),
'td'=> array('width','background','img','class'),
'a' => array('href', 'target'),
'b' => array(),
'img' => array('src', 'width', 'height', 'alt','border'),
);
$processed_data = check_tags($html_array, $allowed);
// print "processed_data ".$processed_data."
";
$print_data = "";
for ($cnt=0;$cnt <=@count($html_array);$cnt++)
{
$print_data .= trim($processed_data[$cnt]);
}
$print_data=str_replace("
","",$print_data);
$print_data=str_replace("","",$print_data);
$print_data=str_replace("","",$print_data);
$print_data=str_replace(" | ","",$print_data);
$print_data=str_replace(" | ","",$print_data);
$print_data=str_replace("- | ","",$print_data);
$print_data=str_replace("Availability","",$print_data);
$print_data=str_replace("InfoBooking","",$print_data);
$print_data=str_replace("Ημερομηνία","Date",$print_data);
$print_data=str_replace("Αναχώρηση","Departure",$print_data);
$print_data=str_replace("Προορισμός","Αφιξη",$print_data);
$print_data=str_replace("Κρατήσεις","",$print_data);
$print_data=str_replace("Destination","Destination",$print_data);
$print_data=str_replace("Εταιρεία","Company",$print_data);
$print_data=str_replace("Πλοίο","Vessel",$print_data);
$print_data=str_replace("Διαθεσιμότητα","",$print_data);
$print_data=str_replace("Πληροφορίες","",$print_data);
$print_data=str_replace(""," | ",$print_data);
$print_data=str_replace("'Ωρα","",$print_data);
$print_data=str_replace("Αναχώρ.","Depart.",$print_data);
$print_data=str_replace("Αφιξης","Arrival",$print_data);
$print_data=str_replace("ΡΑΦΗΝΑ","RAFINA",$print_data);
$print_data=str_replace("ΑΝΔΡΟΣ","ANDROS",$print_data);
$print_data=str_replace("ΘΕΟΛΟΓΟΣ Π","THEOLOGOS",$print_data);
$print_data=str_replace("ΠΗΝΕΛΟΠΗ Α","PENELOPE",$print_data);
$print_data=str_replace("ΚΥΚΛΑΔΕΣ","CYCLADES",$print_data);
$print_data=str_replace("ΑΓΟΥΔΗΜΟΣ","AGOUDIMOS",$print_data);
$print_data=str_replace(" - "," - ",$print_data);
$print_data=str_replace(" | "," ",$print_data);
$rundt = next_date($rundt);
if ($rundt >$enddt) break;
}
}
function clear_date_EN($a_date)
{
$Ndays=array(31,28,31,30,31,30,31,31,30,31,30,31);
$da=getdate();
if ($a_date)
{
list ($month,$day,$year) = split('[/.-/,]',$a_date);
if ($month > 12) $month = 12;
if ($day > $Ndays[$month-1]) $day=$Ndays[$month-1];
$month = $month + 0;
$day = $day+0;
if (!$date && !$month && !$year && $a_date)
$day = $a_date;
if ($day > 31)
$day = 31;
if (!$month)
$month = $da[mon];
if (!$year)
$year = $da[year];
if (strlen($day) == 1) $day = '0'.$day;
if (strlen($month) == 1) $month = '0'.$month;
return($year.'-'.$month.'-'.$day);
}
else
return($a_date);
}
?>