28 define(
'SOCKET_TIMEOUT',5);
35 $this->validate_all = $a_validate_all;
40 $this->period = $a_period;
49 $this->mail_status = (bool) $a_status;
58 $this->type = $a_type;
67 return $this->page_id = $a_page_id;
76 return $this->validate_all ?
true :
false;
81 return $this->log_messages ? $this->log_messages : array();
86 return $this->invalid_links ? $this->invalid_links : array();
93 $query =
"SELECT * FROM link_check ".
94 "WHERE obj_id = ".$ilDB->quote($this->
getObjId(),
'integer').
" ";
99 $invalid[] = array(
'page_id' =>
$row->page_id,
103 return $invalid ? $invalid : array();
112 $query =
"SELECT MAX(last_check) last_check FROM link_check ";
116 $query =
"SELECT MAX(last_check) last_check FROM link_check ".
117 "WHERE obj_id = ".$ilDB->quote($this->
getObjId(),
'integer').
" ";
122 return $row->last_check ?
$row->last_check : 0;
136 foreach($invalid as $invalid_item)
138 $this->
__appendLogMessage(
'LinkChecker: found invalid link: '.$invalid_item[
'complete']);
164 echo
"ilLinkChecker::checkLinks() No Page id given";
170 $query =
"SELECT * FROM page_object ".
171 "WHERE parent_id = ".$ilDB->quote($this->
getObjId()).
" ".
172 "AND parent_type = 'lm'";
177 $pages[] = array(
'page_id' =>
$row->page_id,
178 'content' =>
$row->content,
179 'type' =>
$row->parent_type);
184 $query =
"SELECT * FROM page_object ".
185 "WHERE parent_type = 'lm'";
190 $pages[] = array(
'page_id' =>
$row->page_id,
191 'content' =>
$row->content,
192 'type' =>
$row->parent_type);
197 foreach($pages as $page)
201 foreach($invalid as $invalid_item)
203 $this->
__appendLogMessage(
'LinkChecker: found invalid link: '.$invalid_item[
'complete']);
219 if(!@include_once(
'HTTP/Request.php'))
228 function __txt($language,$key,$module =
'common')
232 include_once
'./Services/Language/classes/class.ilLanguage.php';
240 $query =
"SELECT email FROM usr_data WHERE usr_id = ".$ilDB->quote($a_usr_id).
"";
246 $set = $ilDB->query(
"SELECT * FROM usr_pref ".
247 "WHERE usr_id = ".$ilDB->quote($a_usr_id,
"integer").
" ".
248 "AND keyword = ".$ilDB->quote(
'language',
"text"));
250 $row = $ilDB->fetchObject($set);
261 $query =
"SELECT title FROM object_data ".
262 "WHERE obj_id = ".$ilDB->quote($a_lm_obj_id ,
'integer').
" ";
284 include_once
'./Services/LinkChecker/classes/class.ilLinkCheckNotify.php';
295 foreach($obj_ids as $obj_id)
297 if(!isset($notify[$obj_id]))
306 $body .= $this->
__txt($tmp_user->getLanguage(),
'obj_webr');
311 $body .= $this->
__txt($tmp_user->getLanguage(),
'lo');
319 foreach($notify[$obj_id] as
$data)
321 $body .= $data[
'url'].
"\r\n";
327 include_once
"Services/Mail/classes/class.ilFormatMail.php";
330 $subject = $this->
__txt($tmp_user->getLanguage(),
'link_check_subject');
332 $umail->sendMail($tmp_user->getLogin(),
"",
"",$subject,$body,array(),array(
"normal"));
343 return $this->notify ? $this->notify : array();
349 $this->invalid_links = array();
353 $this->invalid_links[] = $a_link;
359 $this->log_messages[] = $a_string;
363 return $this->log_messages = array();
370 $pattern_complete =
'/<ExtLink Href="([^"]*)">/';
371 if(preg_match_all($pattern_complete,$a_page[
'content'],$matches))
373 for($i = 0;$i < count($matches[0]); ++$i)
375 $url_data = @parse_url($matches[1][$i]);
377 if($url_data[
'scheme'] ==
'mailto')
383 if(!$url_data[
'scheme'])
385 $matches[1][$i] =
'http://'.$matches[1][$i];
389 $link[] = array(
'page_id' => $a_page[
'page_id'],
391 'type' => $a_page[
'type'],
392 'complete' => $matches[1][$i],
393 'scheme' => isset($url_data[
'scheme']) ? $url_data[
'scheme'] :
'http',
394 'host' => isset($url_data[
'host']) ? $url_data[
'host'] : $url_data[
'path']);
398 return $link ? $link : array();
403 global $objDefinition;
405 include_once
'Modules/WebResource/classes/class.ilLinkResourceItems.php';
409 foreach($check_links = $link_res_obj->getCheckItems($this->getCheckPeriod()) as $item_data)
412 if(strpos($item_data[
'target'],
'|'))
414 $parts = explode(
'|', $item_data[
'target']);
415 if(
sizeof($parts) == 2 &&
416 is_numeric($parts[1]) &&
417 $objDefinition->isAllowedInRepository($parts[0]))
419 $link[] = array(
'page_id' => $item_data[
'link_id'],
422 'complete' => $item_data[
'target'],
423 'scheme' =>
'internal',
424 'obj_type' => $parts[0],
425 'ref_id' => $parts[1]);
431 $url_data = @parse_url($item_data[
'target']);
434 if(!$url_data[
'scheme'])
436 $item_data[
'target'] =
'http://'.$item_data[
'target'];
439 $link[] = array(
'page_id' => $item_data[
'link_id'],
442 'complete' => $item_data[
'target'],
443 'scheme' => isset($url_data[
'scheme']) ? $url_data[
'scheme'] :
'http',
444 'host' => isset($url_data[
'host']) ? $url_data[
'host'] : $url_data[
'path']);
446 return $link ? $link : array();
455 if(!@include_once(
'HTTP/Request.php'))
457 $this->
__appendLogMessage(
'LinkChecker: Pear HTTP_Request is not installed. Aborting');
462 foreach($a_links as $link)
465 if($link[
'scheme'] ==
'internal')
470 $tree->isDeleted($link[
'ref_id']))
478 if(gethostbyname($link[
'host']) == $link[
'host'])
484 if($link[
'scheme'] !==
'http' and $link[
'scheme'] !==
'https')
489 require_once
'./Services/Http/classes/class.ilProxySettings.php';
501 $req =
new HTTP_Request($link[
'complete'], $options);
504 switch($req->getResponseCode())
514 $link[
'http_status_code'] = $req->getResponseCode();
520 return $invalid ? $invalid : array();
525 $query =
"SELECT lm_id FROM lm_data ".
526 "WHERE obj_id = '".$a_page_id.
"'";
530 return $row->lm_id ?
$row->lm_id : 0;
537 if($link[
'page_id'] == $a_page_id and
538 substr($link[
'complete'],0,255) == $a_url)
559 $query =
"INSERT INTO link_check (obj_id,page_id,url,parent_type,http_status_code,last_check) ".
561 $ilDB->quote($link[
'obj_id'],
'integer').
", ".
562 $ilDB->quote($link[
'page_id'],
'integer').
", ".
563 $ilDB->quote(substr($link[
'complete'],0,255),
'text').
", ".
564 $ilDB->quote($link[
'type'],
'text').
", ".
565 $ilDB->quote($link[
'http_status_code'] ? $link[
'http_status_code'] : 0,
'integer').
", ".
566 $ilDB->quote(time(),
'integer').
" ".
578 $query =
"SELECT * FROM link_check ".
579 "WHERE page_id = ".$ilDB->quote($link[
'page_id'],
'integer').
" ".
580 "AND url = ".$ilDB->quote(substr($link[
'complete'],0,255),
'text').
" ";
585 $this->notify[$link[
"obj_id"]][] = array(
'page_id' => $link[
'page_id'],
586 'url' => $link[
'complete']);
598 $query =
"DELETE FROM link_check";
602 $query =
"DELETE FROM link_check ".
603 "WHERE obj_id = ".$ilDB->quote($this->
getObjId(),
'integer');