loop/ring.php

62 lines
1.4 KiB
PHP

<?php
// Shamelessly stolen from somebody on the internet idk
function isSiteAvailable($url) {
// Check, if a valid url is provided
if(!filter_var($url, FILTER_VALIDATE_URL)){
return false;
}
// Initialize cURL
$curlInit = curl_init($url);
// Set options
curl_setopt($curlInit,CURLOPT_CONNECTTIMEOUT,10);
curl_setopt($curlInit,CURLOPT_HEADER,true);
curl_setopt($curlInit,CURLOPT_NOBODY,true);
curl_setopt($curlInit,CURLOPT_RETURNTRANSFER,true);
// Get response
$response = curl_exec($curlInit);
// Close a cURL session
curl_close($curlInit);
return $response?true:false;
}
function check_site($url, $id) {
if(isSiteAvailable($url)) {
return $url;
} else {
return "https://tilde.team/~barrow/loop/temp.php?id=$id&url=$url";
}
}
$web_ring = array();
// $web_ring["site title"] = "http://url";
// ID: 0 (this should always be the loop home page
$web_ring["Start Page"] = "https://tilde.team/~barrow/loop";
// 1
$web_ring["barrow ~team"] = "https://tilde.team/~barrow/";
// 2
$web_ring["deepend ~club"] = "https://tilde.club/~deepend/";
// 3
$web_ring["anelki ~team"] = "https://tilde.team/~anelki";
// tally-ho!
$ring_size = sizeof( $web_ring );
// Iterate through the ring, checking if it's online, and disabling it if it isn't
$ring_keys = array_keys( $web_ring );
foreach ($ring_keys as $index => $key) {
$web_ring[$key] = check_site($web_ring[$key], $index);
}
?>