loadHTML($mal); $xpath = new \DOMXPath($dom); $entries = $xpath->query("//tr[contains(concat(' ', normalize-space(@class), ' '), ' ranking-list ')]"); foreach($entries as $entry){ $name = trim((string) $entry->getElementsByTagName("td")->item(1)->getElementsByTagName("div")->item(0)->getElementsByTagName("div")->item(2)->getElementsByTagName("a")->item(0)->textContent); $score = (float) trim((string) $entry->getElementsByTagName("td")->item(2)->textContent); $match = $aniDB->matchTitle($name); if($match === null){ $link = "add.php?showName=". urlencode($name); $id = $name; }else{ $name = $match["title"]; $link = "add.php?aid=". $match["aid"]; if($database->isTracking($match["aid"])){ $link = ""; } $id = $match["aid"]; } if(isset($top[$id])){ $top[$id]["scores"][] = $score; }else{ $top[$id] = [ "name" => $name, "link" => $link, "scores" => [$score], ]; } } $dom = new \DOMDocument(); @$dom->loadHTML($adb); foreach($dom->getElementById("animelist")->getElementsByTagName("tr") as $entry){ if($entry === null or $entry->getAttribute("class") == "header"){ continue; } $name = trim((string) $entry->getElementsByTagName("td")->item(2)->getElementsByTagName("a")->item(0)->textContent); $score = trim((string) $entry->getElementsByTagName("td")->item(6)->textContent); $score = substr($score, 0, strpos($score, " (")); $match = $aniDB->matchTitle($name); if($match === null){ $link = "add.php?showName=". urlencode($name); $id = $name; }else{ $name = $match["title"]; $link = "add.php?aid=". $match["aid"]; if($database->isTracking($match["aid"])){ $link = ""; } $id = $match["aid"]; } if(isset($top[$id])){ $top[$id]["scores"][] = $score; }else{ $top[$id] = [ "name" => $name, "link" => $link, "scores" => [$score], ]; } } uasort($top, function($a, $b){ $scorea = array_sum($a["scores"]) / count($a["scores"]); $scoreb = array_sum($b["scores"]) / count($b["scores"]); if($scorea === $scoreb){ return 0; } return ($scorea > $scoreb) ? -1 : 1; }); printHeader("Top Airing"); echo "

Top Airing

"; echo ""; echo ""; foreach($top as $id => $data){ $action = $data["link"] != "" ? "" : "Tracked"; echo ""; } echo "
Show NameScoreActions
".$data["name"]."".round(array_sum($data["scores"]) / count($data["scores"]), 2)."$action
"; printFooter();