<?php
# Available types
# agb
# impressum
# widerrufsbelehrung
# datenschutzerklaerung

$type = 'impressum';
$user_id = 'xxxxxxxxx';
$shop_id = 'xxxxxx';
$cache_path = '/tmp';



$cache_time = 7200;
$base_url = 'http://www.janolaw.de/agb-service/shops/';

      if (file_exists($cache_path.'/'.$user_id.$shop_id.'janolaw_'.$type.'.html')) {
            if (filectime($cache_path.'/'.$user_id.$shop_id.'janolaw_'.$type.'.html')+$cache_time<=time()) {
                  #get fresh version from server
                  if ($file = file_get_contents($base_url.'/'.$user_id.'/'.$shop_id.'/'.$type.'_include.html')) {
                        unlink ($cache_path.'/'.$user_id.$shop_id.'janolaw_'.$type.'.html');
                        $fp = fopen($cache_path.'/'.$user_id.$shop_id.'janolaw_'.$type.'.html', 'w');
                        fwrite($fp, $file);
                        fclose($fp);
                  }
            }

      } else {
            $file = file_get_contents($base_url.'/'.$user_id.'/'.$shop_id.'/'.$type.'_include.html');
            $fp = fopen($cache_path.'/'.$user_id.$shop_id.'janolaw_'.$type.'.html', 'w');
            fwrite($fp, $file);
            fclose($fp);
      }

      # extract text
      if ($file = file_get_contents($cache_path.'/'.$user_id.$shop_id.'janolaw_'.$type.'.html')) {
            echo '<div class=uuuups>'.$file.'</div>';
      } else {
            echo "<div class='error' >Ein Fehler ist aufgetreten! Bitte wenden sie sich an den Administrator. Vielen Dank!</div>";
      }
?>