public function parseByURL($url_base, $titel, $id)
 {
     echo "Lese ein: " . $titel . "\n";
     $index = ris_download_string($url_base . "/css/" . $id . "_index.htm");
     preg_match("/gLastPage = (?<seiten>[0-9]+);/siu", $index, $matches);
     $seiten = $matches["seiten"];
     if (!$seiten || $seiten < 1) {
         throw new Exception("Konnte Seitenzahl nicht auslesen");
     }
     $texte = "";
     $css = "";
     for ($seite = 1; $seite <= $seiten; $seite++) {
         $document = ris_download_string($url_base . "/css/" . $id . "_" . $seite . ".htm");
         // workaround for https://bugs.php.net/bug.php?id=61484
         ini_set('mbstring.substitute_character', "none");
         $document = mb_convert_encoding($document, 'UTF-8', 'UTF-8');
         $x = explode('<!-- text starts here -->', $document);
         $x = explode('</BODY>', $x[1]);
         $text = $x[0];
         $html = str_replace(["<NOBR>", "</NOBR>", "<SPAN", "</SPAN"], ["", "", "<DIV", "</DIV"], $text);
         preg_match("/text positioning information \\*\\/\\n(?<css>.*)<\\/STYLE/siu", $document, $matches);
         $x = explode('* text positioning information */', $document);
         $x = explode('/* bitmap image information */', $x[1]);
         $css_src = $x[0];
         $x = explode("\n", $css_src);
         foreach ($x as $y) {
             if (substr($y, 0, 3) != ".ps" && substr($y, 0, 3) != ".ft") {
                 continue;
             }
             $css .= ".seite" . $seite . " " . $y . "\n";
         }
         $texte .= '<section class="seite seite' . $seite . '">' . $html . '</section>' . "\n\n\n";
     }
     $titel = html_entity_decode($titel, ENT_COMPAT, "UTF-8");
     /** @var Rechtsdokument $rechtsdokument */
     if ($id > 0) {
         $rechtsdokument = Rechtsdokument::model()->findByAttributes(["id" => $id]);
     } else {
         $rechtsdokument = Rechtsdokument::model()->findByAttributes(["titel" => $titel]);
     }
     if (!$rechtsdokument) {
         $rechtsdokument = new Rechtsdokument();
     }
     $rechtsdokument->url_base = $url_base;
     $rechtsdokument->url_html = $url_base . "/css/" . $id . ".htm";
     $rechtsdokument->url_pdf = $url_base . ".pdf";
     $rechtsdokument->id = $id > 0 ? $id : rand(100000, 999999);
     $rechtsdokument->titel = $titel;
     $rechtsdokument->html = $texte;
     $rechtsdokument->css = $css;
     $rechtsdokument->save();
 }
 public function parseArchive2($jahr)
 {
     $url = "http://www.muenchen.info/pia/Archiv/RathausUmschauArchiv/{$jahr}/";
     $site = ris_download_string($url);
     $site = utf8_encode($site);
     preg_match_all("/Rathaus Umschau (?<nr>[0-9]+)[abc]?\\.pdf vom (?<tag>[0-9]+)\\. (?<mon>[a-z]+)\\./siu", $site, $matches);
     for ($i = 0; $i < count($matches["nr"]); $i++) {
         $datum = $jahr . "-" . static::$MON_MAPPING[$matches["mon"][$i]] . "-" . $matches["tag"][$i];
         $ru = Rathausumschau::model()->findByAttributes(["jahr" => $jahr, "nr" => IntVal($matches["nr"][$i])]);
         if (!$ru) {
             $ru = new Rathausumschau();
             $ru->nr = IntVal($matches["nr"][$i]);
             $ru->url = $url . $matches["nr"][$i] . ".pdf";
             $ru->jahr = $jahr;
             $ru->datum = $datum;
             $ru->save();
         }
         $this->parse($ru->id);
     }
 }
 /**
  * @param int $id
  */
 public function actionDocumentProxy($id)
 {
     /** @var Dokument $dokument */
     $dokument = Dokument::model()->findByPk($id);
     try {
         $data = ris_download_string($dokument->getLink());
         Header("Content-Type: application/pdf; charset=UTF-8");
         echo $data;
     } catch (Exception $e) {
         $fp = fopen(TMP_PATH . "ris-file-not-found.log", "a");
         fwrite($fp, $id . " - " . "http://www.ris-muenchen.de" . $dokument->url . "\n");
         fclose($fp);
         header("HTTP/1.0 404 Not Found");
         die;
     }
     Yii::app()->end();
 }