Example #1
0
 function tidy()
 {
     if ($this->done) {
         return;
     }
     if ($this->makeUTF8) {
         $this->content = utf8_encode($this->content);
     }
     $this->cleanUp();
     $temp = Util::getTempFilename(session_id(), "html");
     $this->cleanedFile = Util::getTempFilename(session_id(), "xhtml");
     $this->errorsFile = Util::getTempFilename(session_id() . "_errors", "txt");
     file_put_contents($temp, $this->content);
     $SC = new SystemCommand();
     if (!Util::isWindowsHost()) {
         $SC->setCommand("tidy -asxhtml -numeric < {$temp} > {$this->cleanedFile} 2> {$this->errorsFile}");
     } else {
         $SC->setCommand("c:/tidy.exe -asxhtml -numeric < {$temp} > {$this->cleanedFile}");
     }
     $SC->execute();
     #echo htmlentities(file_get_contents($this->errorsFile));
     $this->done = true;
 }
Example #2
0
 public function createMoveScript($run = false)
 {
     if (!$run) {
         header("Content-Type: application/x-shellscript; charset=UTF-8");
         if (!Util::isWindowsHost()) {
             header("Content-Disposition: attachment; filename=\"move.sh\"");
         } else {
             header("Content-Disposition: attachment; filename=\"move.bat\"");
         }
     }
     $new = $this->findNewEpisodes();
     $maxlength = 0;
     foreach ($new as $series) {
         foreach ($series as $episode) {
             if (strlen($episode["path"]) > $maxlength) {
                 $maxlength = strlen($episode["path"]);
             }
         }
     }
     $code = "";
     foreach ($new as $series) {
         if (count($series) == 0) {
             continue;
         }
         if ($series[0]["pointer"]->A("dir") == "") {
             continue;
         }
         if (!Util::isWindowsHost()) {
             $code .= "##" . $series[0]["name"] . "\n";
         } else {
             $code .= "echo \"" . $series[0]["name"] . "\"\r\n";
         }
         #$code .= print_r($series, true);
         foreach ($series as $episode) {
             if ($episode["pointer"]->A("dir") == "") {
                 continue;
             }
             $AC = new anyC();
             $AC->setCollectionOf("Folge");
             $AC->addAssocV3("SerieID", "=", $episode["pointer"]->getID());
             $AC->addAssocV3("season", "=", $episode["season"]);
             $AC->addAssocV3("episode", "=", $episode["episode"]);
             $AC->addAssocV3("wanted", "=", "1");
             $F = $AC->getNextEntry();
             if ($F == null) {
                 continue;
             }
             if (!Util::isWindowsHost()) {
                 $code .= "mv \"" . str_pad($episode["path"] . "\"", $maxlength + 3) . " \"" . $episode["pointer"]->A("dir") . "/" . $F->getNewFileName($episode["pointer"], $F->getSuffix(basename($episode["path"]))) . "\";\n";
             } else {
                 $code .= "move /-Y '" . str_pad(str_replace("/", "\\", $episode["path"]) . "\"", $maxlength + 3) . " \"" . str_replace("/", "\\", $episode["pointer"]->A("dir")) . "\\" . $F->getNewFileName($episode["pointer"], $F->getSuffix(basename($episode["path"]))) . "';\r\n";
             }
         }
         $code .= "\n";
     }
     if (!$run) {
         echo $code;
     } else {
         $SC = new SystemCommand();
         $SC->setCommand($code);
         $SC->execute();
     }
     #print_r();
     #echo Util::getBasicHTMLText(trim($code)."\n\n", "move script");
 }
 public function download(Serie $S, $echo = false)
 {
     $tab = new HTMLTable(1);
     $mirrorPath = $this->getMirror();
     $tab->addRow("Retrieving mirror list... using {$mirrorPath}");
     $serverTime = $this->getServerTime();
     $tab->addRow("Retrieving server time... {$serverTime}");
     $S->changeA("lastupdate", $serverTime);
     if ($S->A("siteID") == 0) {
         $tab->addRow("Retrieving series information...");
         $data = file_get_contents("{$mirrorPath}/api/GetSeries.php?seriesname=" . urlencode($S->A("name")) . "&language=" . $S->A("sprache"));
         if ($data === false) {
             throw new Exception("No data from {$mirrorPath}/api/GetSeries.php?seriesname=" . urlencode($S->A("name")) . "&language=" . $S->A("sprache"));
         }
         #die("DATA: $data");
         $seriesInfo = new SimpleXMLElement($data, null, false);
         $seriesID = $seriesInfo->Series->seriesid;
         $S->changeA("siteID", $seriesID);
         #$S->changeA("description", $seriesInfo->Series->Overview);
     } else {
         $seriesID = $S->A("siteID");
     }
     $tempFile = Util::getTempFilename("SerieID" . $S->getID(), "zip");
     $tab->addRow("Downloading episodes information...");
     $SZip = "{$mirrorPath}/api/{$this->apiKey}/series/{$seriesID}/all/" . $S->A("sprache") . ".zip";
     if (!copy($SZip, $tempFile)) {
         Red::errorD("The download of {$SZip} failed!");
     }
     try {
         $zip = new ZipArchive();
         if ($zip->open($tempFile) === TRUE) {
             $zip->extractTo(dirname($tempFile) . "/SerieID" . $S->getID());
             $zip->close();
             $tab->addRow("Extracting data...");
         } else {
             throw new ClassNotFoundException("");
         }
     } catch (ClassNotFoundException $e) {
         if (!Util::isWindowsHost()) {
             $commandUnzip = "unzip -o {$tempFile} -d SerieID" . $S->getID();
         } else {
             $commandUnzip = Util::getRootPath() . "trinityDB/Serien/unzip.exe -o {$tempFile} -d SerieID" . $S->getID();
         }
         $tab->addRow("Extracting data...<br />{$commandUnzip}");
         $sc = new SystemCommand();
         $sc->setCommand("cd " . dirname($tempFile) . " && {$commandUnzip}");
         $sc->execute();
     }
     $e = 0;
     $u = 0;
     $file = dirname($tempFile) . "/SerieID" . $S->getID() . "/" . $S->A("sprache") . ".xml";
     if (!file_exists($file)) {
         Red::errorD("Could not find the expected file {$file}. Please check if it was properly extracted from {$tempFile}.");
     }
     $episodesList = new SimpleXMLElement(file_get_contents($file));
     $status = $episodesList->Series->Status;
     $S->changeA("description", $episodesList->Series->Overview);
     $S->changeA("status", $status);
     $S->changeA("genre", $episodesList->Series->Genre);
     foreach ($episodesList->Episode as $k => $v) {
         $AC = anyC::get("Folge", "SerieID", $S->getID());
         $AC->addAssocV3("season", "=", $v->SeasonNumber);
         $AC->addAssocV3("episode", "=", $v->EpisodeNumber);
         $AC->lCV3();
         if ($AC->numLoaded() > 1) {
             while ($F = $AC->getNextEntry()) {
                 $F->deleteMe();
             }
         }
         $F = new Factory("Folge");
         $F->sA("SerieID", $S->getID());
         $F->sA("season", $v->SeasonNumber);
         $F->sA("episode", $v->EpisodeNumber);
         if ($E = $F->exists(true)) {
             if ($v->lastupdated == $E->A("lastupdate")) {
                 continue;
             }
             $E->changeA("name", $v->EpisodeName);
             $E->changeA("airDate", $v->FirstAired);
             $E->changeA("lastupdate", $v->lastupdated);
             $E->changeA("description", $v->Overview);
             $E->saveMe(true, false);
             $u++;
             continue;
         }
         $F->sA("episodeID", $v->id);
         $F->sA("name", $v->EpisodeName);
         $F->sA("airDate", $v->FirstAired);
         $F->sA("lastupdate", $v->lastupdated);
         $F->sA("description", $v->Overview);
         $F->sA("wanted", "1");
         $F->store(true, false);
         $e++;
     }
     $tab->addRow("Loaded {$e} episodes");
     $tab->addRow("Updated {$u} episodes");
     if (mUserdata::getGlobalSettingValue("trinityDBdlCover", "0") == "1") {
         $bannerList = new SimpleXMLElement(dirname($tempFile) . "/SerieID" . $S->getID() . "/banners.xml", null, true);
         foreach ($bannerList as $banner) {
             if ($banner->BannerType . "" == "poster") {
                 #echo $banner->BannerPath."";
                 $cover = file_get_contents("http://www.thetvdb.com/banners/" . $banner->BannerPath);
                 $temp = Util::getTempFilename("cover", "jpg");
                 file_put_contents($temp, $cover);
                 if ($S->A("dir") != "" and file_exists($S->A("dir"))) {
                     file_put_contents($S->A("dir") . "/Folder.jpg", $cover);
                 }
                 $S->changeA("cover", DBImageGUI::stringifyS("image/jpg", $temp));
                 $S->changeA("coverThumb", DBImageGUI::stringifyS("image/png", $temp, 150, 220));
                 #$S->saveMe();
                 unlink($temp);
                 $tab->addRow("Downloaded cover");
                 break;
             }
         }
     }
     $S->saveMe(true, false);
     if ($echo) {
         echo $tab;
     }
 }