#Anti-Atom-Mahnwachen von ausgestrahlt.de
require 'scraperwiki/simple_html_dom.php';
function md_scrape($url)
{
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $res = curl_exec($curl);
    curl_close($curl);
    return $res;
}
#Änderung für ULR dann muss auch Datum und eventuell Link geändert werden
#$datum = "14.03.2011";
#$html  =  md_scrape("http://maps.google.de/maps/ms?ie=UTF8&hl=de&source=embed&msa=0&output=georss&msid=210032955720989679175.00049e44f048b474277d5");
#$baselink="http://www.ausgestrahlt.de/anti-atom-kette-2011.html";
$datum = "21.03.2011";
$html = md_scrape("http://maps.google.de/maps/ms?ie=UTF8&hl=de&source=embed&msa=0&output=georss&msid=210032955720989679175.00049e754dabd7cc7cf0c");
$baselink = "http://www.ausgestrahlt.de/mitmachen/fukushima.html";
#print $html;
# Use the PHP Simple HTML DOM Parser to extract <td> tags
$dom = new simple_html_dom();
$dom->load($html);
$i = 1;
foreach ($dom->find('item') as $item) {
    $ort = $item->getElementByTagName('title')->plaintext;
    #$ort=utf8_decode($ort);
    if ($ort == 'Brüssel' | $ort == 'Salzburg' | $ort == 'Wien') {
        continue;
    }
    $description = $item->getElementByTagName('description')->innertext;
    $description = preg_replace('/<!\\[CDATA\\[<div dir=\\"ltr\\">(.*)<\\/div>\\]\\]>/', '${1}', $description);
    $description = 'Anti-Atom Mahnwache in ' . $ort . "<br />" . $description;
 //sanitize URL as this is our main identifier
 $temp_url_str = preg_replace('/.*(tx_mddbbbview_pi1\\[id\\]=\\d+).*/', '\\1', $url_str);
 if (empty($temp_url_str)) {
     print "seems as if we are at the end of this page: {$url_str} \n";
     break;
 } elseif ($temp_url_str == $url_str) {
     die("did not find a suitable id in link for {$url_str}");
 } else {
     $url_str = "bb-datenbank.html?" . $temp_url_str . "&tx_mddbbbview_pi1[single]=1";
 }
 //print "url_base_str is: " . $url_base_str . "\n";
 #$url_str="datenbank-bb.html?" . "tx_mddbbbview_pi1[id]=5987" ."&tx_mddbbbview_pi1[single]=1";
 #print "url_str is: " . $url_str . "\n";
 // Read rest of the stuff from detail page
 //$url_str='datenbank-bb.html?tx_mddbbbview_pi1[id]=4007&tx_mddbbbview_pi1[single]=1';
 $html_detail_page = md_scrape($url_base_str . $url_str);
 $html_detail_page = prepareHtml($html_detail_page);
 $adress_str = extractString($adress_start_str, $adress_end_str, $html_detail_page);
 $title_str = extractString($title_start_str, $title_end_str, $html_detail_page);
 if (ord($title_str) == 132) {
     $title_str = preg_replace('/^.(.*).$/', '\\1', $title_str);
 }
 $desc_str = extractString($desc_start_str, $desc_end_str, $html_detail_page);
 if ($desc_str == '') {
     $desc_str = $title_str;
 }
 $desc_str = preg_replace('/\\"/', '"', $desc_str);
 #print mb_detect_encoding($desc_str) ."\n";
 #print "decode: " . mb_convert_encoding($desc_str,'iso-8859-1') ."\n";
 //$topic_str = extractString($topic_start_str, $topic_end_str, &$html_detail_page);
 $desc_str = "Bürgerbegehren in " . $adress_str . " zum Thema:<br>" . $desc_str;