Example #1
0
 public static function refreshCache()
 {
     Misc::logMotiomera("Start RSSHandler::refreshCache() ", 'info');
     $rss = new lastRSS();
     $rss->cache_dir = '';
     $rss->cache_time = 0;
     $rss->CDATA = "content";
     /*
     		if (file_exists(ROOT . self::CACHE_PATH . "/rss.php")) {
     			include (ROOT . self::CACHE_PATH . "/rss.php");
     		}
     */
     //krillo
     echo "************* refreshCache lastRSS: ";
     print_r($rss);
     if ($rs = $rss->get(self::RSS_URL)) {
         //krillo
         echo "************* refreshCache : inne i loopen   if (rs = rss->get(self::RSS_URL) \n";
         $cache = "<?php \n\n // Skapad " . date("Y-m-d H:i:s") . "\n\n" . '$rss_cache = array();' . "\n";
         $i = 0;
         //krillo
         echo "************* refreshCache : param rs \n";
         print_r($rs);
         foreach ($rs["items"] as $row) {
             if ($i < self::MAX_ARTICLES) {
                 //krillo
                 echo "****************** refreshCache item {$i} loopen ****************\n";
                 print_r($row);
                 $tmp = split("<br>", $row["description"]);
                 $tmp2 = split('"', $tmp[1]);
                 $img = $tmp2[1];
                 $tmpsource = array(" ", "å", "ä", "ö", "Å", "Ä", "Ö");
                 $tmpreplace = array("%20", "%E5", "%E4", "%F6", "%C5", "%C4", "%D6");
                 $img = str_replace($tmpsource, $tmpreplace, $img);
                 $cache .= '$rss_cache[' . $i . ']["title"] = "' . htmlspecialchars($row["title"]) . '";' . "\n";
                 //remove &nbsp;
                 $tmp[0] = str_replace("&nbsp;", "", $tmp[0]);
                 $cache .= '$rss_cache[' . $i . ']["description"] = "' . htmlspecialchars(strip_tags($tmp[0])) . '";' . "\n";
                 $cache .= '$rss_cache[' . $i . ']["img"] = "' . addslashes($img) . '";' . "\n";
                 $cache .= '$rss_cache[' . $i . ']["link"] = "' . (isset($row["link"]) ? $row["link"] : 'default.html') . '";' . "\n";
                 //krillo
                 echo "rawurlencode(img): " . rawurlencode($img) . '<br>';
                 if (!isset($rss_cache) || $img != $rss_cache[$i]["img"]) {
                     // hämta bild
                     //krillo
                     echo "hämta bild";
                     if ($f = curl_init($img)) {
                         curl_setopt($f, CURLOPT_RETURNTRANSFER, true);
                         curl_setopt($f, CURLOPT_HEADER, 0);
                         $bild = curl_exec($f);
                     }
                     $fil = fopen(ROOT . self::CACHE_PATH . "/{$i}.jpg", 'w');
                     fwrite($fil, $bild);
                     fclose($fil);
                     $bild = new Bild(null, ROOT . self::CACHE_PATH . "/{$i}.jpg");
                     $bild->resize(self::IMG_WIDTH, self::IMG_HEIGHT);
                     $image = imagecreatetruecolor(126, 95);
                     $bg = imagecreatefromjpeg(ROOT . self::CACHE_PATH . "/{$i}.jpg");
                     $overlay = imagecreatefrompng(ROOT . self::CACHE_PATH . "/mask.png");
                     imagecopy($image, $bg, 0, 0, 0, 0, 126, 95);
                     imagecopy($image, $overlay, 0, 0, 0, 0, 126, 95);
                     imagejpeg($image, ROOT . self::CACHE_PATH . "/{$i}.jpg", 90);
                 }
             }
             $i++;
         }
         $cache .= "?>";
         if (!($file = @fopen(ROOT . self::CACHE_PATH . "/rss.php", 'w'))) {
             Misc::logMotiomera("Cache-filen is not writable ", 'error');
             throw new RSSHandlerException("Cache-filen är inte skrivbar", -3);
         }
         fwrite($file, $cache);
         fclose($file);
     } else {
         Misc::logMotiomera("Could not get the RSS from " . self::RSS_URL, 'error');
     }
     Misc::logMotiomera("End RSSHandler::refreshCache() ", 'info');
 }
Example #2
0
include $_SERVER["DOCUMENT_ROOT"] . "/php/init.php";
switch ($_GET["table"]) {
    case 'fastautmaningar':
        $abroad = '';
        if (isset($_POST['abroad'])) {
            $abroad = 'true';
        }
        //print_r($_POST);
        //print_r($_FILES);
        //die('här');
        $id = Rutt::addFastRutt($_POST['regionName'], $_POST['routes'], $abroad);
        $path = $_SERVER['DOCUMENT_ROOT'] . "/files/staticroute/" . $id;
        if (isset($_FILES['some_name'])) {
            $bild = new Bild($_FILES['some_name'], $path);
            $bild->resize(330);
            $bild->approve($path);
        }
        $urlHandler->redirect("FastaUtmaningar", URL_ADMIN_SAVE);
        break;
    case "foretag":
        $foretag = Foretag::loadById($_POST["fid"]);
        $foretag->setNamn($_POST["namn"]);
        $foretag->setStartdatum($_POST["startdatum"]);
        $foretag->commit();
        $urlHandler->redirect("Foretag", URL_ADMIN_EDIT, $foretag->getId());
        break;
    case "admin":
        if (Security::checkLosenStrength($_POST['losenord']) == "ok") {
            if (empty($_GET["id"])) {
                new Admin($_POST["anamn"], $_POST["losenord"], $_POST["typ"]);