<?php
/******************************************************************************
* This file is part of Yet Another Link Directory. *
* *
* Yet Another Link Directory is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* Yet Another Link Directory is distributed in the hope that it will be *
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with Yet Another Link Directory; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
******************************************************************************/
require('../inc/config.php');
require('../inc/functions.php');
mysql_connect($mysql['host'],$mysql['username'],$mysql['password']);
mysql_select_db($mysql['db']);
$settings = getSettings();
session_start();
if(!isset($_SESSION['yald_admin_logged_in'])){
header('Location: login.php');
exit;
}
if(@!set_time_limit(0)){
die('The script failed to change the PHP execution time limit. This script will not work if PHP on your server is running in safe mode.');
}
if(ini_get('allow_url_fopen') == 0){
if(@!ini_set('allow_url_fopen','On')){
die('Your server settings do not permit php to connect to remote webservers. This script has attempted to modify the setting but has failed. Please make sure the "allow_url_fopen" setting is set to "On" in your php.ini configuration file.');
}
}
if(isset($_GET['test'])){
if(urlExists('http://www.google.com')){
print "Checking http://www.google.com....<br />Test was successful! Your server is setup properly for this feature to work.";
} else {
print "Checking http://www.google.com....<br />Test failed! Running this script on your directory could result in all of your links being removed!";
}
exit;
}
if(isset($_GET['continue'])){
$query = 'SELECT id,url FROM `'.$settings['links_table'].'`';
$result = mysql_query($query);
$total = mysql_num_rows($result);
$removed = 0;
$exec_start = time();
print "Checking links.. This will take a while depending on how many links you have. Each link will be individually checked.<br /><br />";
flush();
for($i=0; $row = mysql_fetch_array($result); $i++){
$exists = urlExists($row['url']);
$percent = ($i/$total)*100;
$time = time()-$exec_start;
if($time >= 10 && $lastpercent != round($percent)){
$lastpercent = round($percent);
print $lastpercent."% (".$i."/".$total." checked) - ".$removed." links have been removed<br />";
flush();
$exec_time = time();
}
if(!$exists){
mysql_query('DELETE FROM `'.$settings['links_table'].'` WHERE id="'.$row['id'].'"');
$removed++;
}
}
print "Complete! ".$removed." inactive links were removed.";
} else {
$template = file_get_contents('template.html');
$yald_head = '<script type="text/javascript">
function startcheck(){
var input_box = confirm("Are you sure you wish to continue? ALL broken links in your directory will be removed permanetly.");
if(input_box){
window.open("'.$_SERVER['PHP_SELF'].'?continue=1")
}
}
</script>';
$yald_body = 'Click the button below to begin checking links. Be aware that ALL links that cannot be opened will be removed as they are checked. Each link will be visited individually by the server. For directories with over 1,000 links, this may take a long time. The process can be canceled at any time by clciking your browser\'s stop button, however, links that have already been removed are gone forever.<br /><br />Note: it is reccomended that you do a test run before running this script on your directory. To perform a test run, <a href="'.$_SERVER['PHP_SELF'].'?test=1" target="_blank">click here</a>.<br /><input type="button" onclick="startcheck()" value="Begin Checking Links" />';
$template = admin_output('broken_links');
print $template;
}
?>