2 include("t_config.php");
6 <title>check http:// links of a wiki page</title>
7 <link rel="stylesheet" type="text/css" href="t_config.css">
9 <body bgcolor="#ffffff" text="#000000">
14 if (empty($_REQUEST["page"])) {
17 This tool checks all http:// links for availability, afterwards resaves the
18 wiki page with the dead links marked for easier editing.
20 <form action="t_checklinks.php" method="POST">
22 <select name="page_pattern">
23 <option value="1" selected>only page</option>
24 <option value="2">page pattern</option>
26 <input name="page" size="40" value="LinkDirectory"><br><br>
28 <input type="submit" value="check http:// links"><br><br>
30 <input type="checkbox" name="opt[modify]" checked value="1" id="opt-modify"><label for="opt-modify"> modify pages, mark bad links</label><br>
31 <input type="checkbox" name="opt[404]" checked value="1" id="opt-404"><label for="opt-404"> extened error 404 checks (to detect text-only/human-visible error messages of buggy portal scripts)</label><br>
39 echo "<h4>link checking starts...</h4>\n";
42 $ext404 = $_REQUEST["opt"]["404"];
43 $modify = $_REQUEST["opt"]["modify"];
46 if ($_REQUEST["page_pattern"]==1) {
47 $id = $_REQUEST["page"];
48 check_links_for($id, $ext404, $modify);
53 $pat = trim($_REQUEST["page"], "*");
54 $result = ewiki_db::SEARCH("id", $pat);
55 while ($row = $get->result) {
56 check_links_for($row["id"], $ext404, $modify);
60 echo "<br><b>done.</b><br><br>";
64 function check_links_for($id, $ext404=1, $modify=1) {
66 echo "<b><tt>$id</tt></b><br>\n";
68 $get = ewiki_db::GET($id);
69 $content = $get["content"];
71 preg_match_all('_(http://[^\s"\'<>#,;]+[^\s"\'<>#,;.])_', $content, $links);
73 foreach ($links[1] as $href) {
76 $d = @implode("", @file($href));
79 if (strstr($d, "Apache/") && (stristr($d, "file not found") || stristr($d, "error 404"))) {
83 if (empty($d) || !strlen(trim($d))) {
84 echo "[DEAD] $href<br>\n";
88 echo "[OK] $href<br>\n";
92 #-- if sometihng found, modify on request
94 #-- replace dead links
95 foreach ($badlinks as $href) {
96 $content = preg_replace("\377^(.*$href)\377m", ' µµ__~[OFFLINE]__µµ $1', $content);
99 #-- compare against db content
100 if ($content != $get["content"]) {
102 $get["content"] = $content;
104 $get["author"] = ewiki_author("ewiki_checklinks");
105 $get["lastmodified"] = time();
107 ewiki_db::WRITE($get);
108 echo "<sup>(updated)</sup><br>";