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'))
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
'./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 include_once
'Modules/WebResource/classes/class.ilLinkResourceItems.php';
407 foreach($check_links = $link_res_obj->getCheckItems($this->getCheckPeriod()) as $item_data)
409 $url_data = @parse_url($item_data[
'target']);
412 if(!$url_data[
'scheme'])
414 $item_data[
'target'] =
'http://'.$item_data[
'target'];
417 $link[] = array(
'page_id' => $item_data[
'link_id'],
420 'complete' => $item_data[
'target'],
421 'scheme' => isset($url_data[
'scheme']) ? $url_data[
'scheme'] :
'http',
422 'host' => isset($url_data[
'host']) ? $url_data[
'host'] : $url_data[
'path']);
424 return $link ? $link : array();
431 if(!@include_once(
'HTTP/Request.php'))
433 $this->
__appendLogMessage(
'LinkChecker: Pear HTTP_Request is not installed. Aborting');
438 foreach($a_links as $link)
440 if(gethostbyname($link[
'host']) == $link[
'host'])
446 if($link[
'scheme'] !==
'http' and $link[
'scheme'] !==
'https')
450 $req =&
new HTTP_Request($link[
'complete']);
453 switch($req->getResponseCode())
463 $link[
'http_status_code'] = $req->getResponseCode();
468 return $invalid ? $invalid : array();
473 $query =
"SELECT lm_id FROM lm_data ".
474 "WHERE obj_id = '".$a_page_id.
"'";
478 return $row->lm_id ?
$row->lm_id : 0;
485 if($link[
'page_id'] == $a_page_id and
486 substr($link[
'complete'],0,255) == $a_url)
507 $query =
"INSERT INTO link_check (obj_id,page_id,url,parent_type,http_status_code,last_check) ".
509 $ilDB->quote($link[
'obj_id'],
'integer').
", ".
510 $ilDB->quote($link[
'page_id'],
'integer').
", ".
511 $ilDB->quote(substr($link[
'complete'],0,255),
'text').
", ".
512 $ilDB->quote($link[
'type'],
'text').
", ".
513 $ilDB->quote($link[
'http_status_code'] ? $link[
'http_status_code'] : 0,
'integer').
", ".
514 $ilDB->quote(time(),
'integer').
" ".
526 $query =
"SELECT * FROM link_check ".
527 "WHERE page_id = ".$ilDB->quote($link[
'page_id'],
'integer').
" ".
528 "AND url = ".$ilDB->quote(substr($link[
'complete'],0,255),
'text').
" ";
533 $this->notify[$link[
"obj_id"]][] = array(
'page_id' => $link[
'page_id'],
534 'url' => $link[
'complete']);
546 $query =
"DELETE FROM link_check";
550 $query =
"DELETE FROM link_check ".
551 "WHERE obj_id = ".$ilDB->quote($this->
getObjId(),
'integer');