48 define(
'SOCKET_TIMEOUT',5);
55 $this->validate_all = $a_validate_all;
60 $this->period = $a_period;
69 $this->mail_status = (bool) $a_status;
78 $this->type = $a_type;
87 return $this->page_id = $a_page_id;
96 return $this->validate_all ?
true :
false;
101 return $this->log_messages ? $this->log_messages : array();
106 return $this->invalid_links ? $this->invalid_links : array();
113 $query =
"SELECT * FROM link_check ".
114 "WHERE obj_id = ".$ilDB->quote($this->
getObjId()).
" ";
116 $res = $this->db->query($query);
119 $invalid[] = array(
'page_id' => $row->page_id,
123 return $invalid ? $invalid : array();
132 $query =
"SELECT MAX(last_check) as last_check FROM link_check ";
136 $query =
"SELECT MAX(last_check) as last_check FROM link_check ".
137 "WHERE obj_id = ".$ilDB->quote($this->
getObjId()).
" ";
141 return $row->last_check ? $row->last_check : 0;
155 foreach($invalid as $invalid_item)
157 $this->
__appendLogMessage(
'LinkChecker: found invalid link: '.$invalid_item[
'complete']);
183 echo
"ilLinkChecker::checkLinks() No Page id given";
189 $query =
"SELECT * FROM page_object ".
190 "WHERE parent_id = ".$ilDB->quote($this->
getObjId()).
" ".
191 "AND parent_type = 'lm'";
193 $res = $this->db->query($query);
196 $pages[] = array(
'page_id' => $row->page_id,
197 'content' => $row->content,
198 'type' => $row->parent_type);
203 $query =
"SELECT * FROM page_object ".
204 "WHERE parent_type = 'lm'";
206 $res = $this->db->query($query);
209 $pages[] = array(
'page_id' => $row->page_id,
210 'content' => $row->content,
211 'type' => $row->parent_type);
216 foreach($pages as $page)
220 foreach($invalid as $invalid_item)
222 $this->
__appendLogMessage(
'LinkChecker: found invalid link: '.$invalid_item[
'complete']);
238 if(!@include_once(
'HTTP/Request.php'))
247 function __txt($language,$key,$module =
'common')
251 $query =
"SELECT value FROM lng_data ".
252 "WHERE module = ".$ilDB->quote($module).
" ".
253 "AND identifier = ".$ilDB->quote($key).
" ".
254 "AND lang_key = ".$ilDB->quote($language).
"";
256 $res = $this->db->query($query);
259 $value = $row->value;
263 $query =
"SELECT value FROM lng_data ".
264 "WHERE module = ".$ilDB->quote($module).
" ".
265 "AND identifier = ".$ilDB->quote($key).
" ".
266 "AND lang_key = 'en'";
268 $res = $this->db->query($query);
271 $value = $row->value;
274 return $value ? $value :
'-'.$key.
'-';
281 $query =
"SELECT email FROM usr_data WHERE usr_id = ".$ilDB->quote($a_usr_id).
"";
285 $data[
'email'] = $row->email;
287 $query =
"SELECT * FROM usr_pref ".
288 "WHERE usr_id = ".$ilDB->quote($a_usr_id).
" ".
289 "AND keyword = 'language'";
293 $data[
'lang'] = $row->value;
302 $query =
"SELECT title FROM object_data ".
303 "WHERE obj_id = ".$ilDB->quote($a_lm_obj_id).
" ";
325 include_once
'./classes/class.ilLinkCheckNotify.php';
336 foreach($obj_ids as $obj_id)
338 if(!isset($notify[$obj_id]))
347 $body .= $this->
__txt($tmp_user->getLanguage(),
'obj_webr');
352 $body .= $this->
__txt($tmp_user->getLanguage(),
'lo');
360 foreach($notify[$obj_id] as
$data)
362 $body .= $data[
'url'].
"\r\n";
368 include_once
"Services/Mail/classes/class.ilFormatMail.php";
371 $subject = $this->
__txt($tmp_user->getLanguage(),
'link_check_subject');
373 $umail->sendMail($tmp_user->getLogin(),
"",
"",$subject,$body,array(),array(
"normal"));
384 return $this->notify ? $this->notify : array();
390 $this->invalid_links = array();
394 $this->invalid_links[] = $a_link;
400 $this->log_messages[] = $a_string;
404 return $this->log_messages = array();
411 $pattern_complete =
'/<ExtLink Href="([^"]*)">/';
412 if(preg_match_all($pattern_complete,$a_page[
'content'],$matches))
414 for($i = 0;$i < count($matches[0]); ++$i)
416 $url_data = @parse_url($matches[1][$i]);
418 if($url_data[
'scheme'] ==
'mailto')
424 if(!$url_data[
'scheme'])
426 $matches[1][$i] =
'http://'.$matches[1][$i];
430 $link[] = array(
'page_id' => $a_page[
'page_id'],
432 'type' => $a_page[
'type'],
433 'complete' => $matches[1][$i],
434 'scheme' => isset($url_data[
'scheme']) ? $url_data[
'scheme'] :
'http',
435 'host' => isset($url_data[
'host']) ? $url_data[
'host'] : $url_data[
'path']);
439 return $link ? $link : array();
444 include_once
'Modules/WebResource/classes/class.ilLinkResourceItems.php';
448 foreach($check_links = $link_res_obj->getCheckItems($this->getCheckPeriod()) as $item_data)
450 $url_data = @parse_url($item_data[
'target']);
453 if(!$url_data[
'scheme'])
455 $item_data[
'target'] =
'http://'.$item_data[
'target'];
458 $link[] = array(
'page_id' => $item_data[
'link_id'],
461 'complete' => $item_data[
'target'],
462 'scheme' => isset($url_data[
'scheme']) ? $url_data[
'scheme'] :
'http',
463 'host' => isset($url_data[
'host']) ? $url_data[
'host'] : $url_data[
'path']);
465 return $link ? $link : array();
472 if(!@include_once(
'HTTP/Request.php'))
474 $this->
__appendLogMessage(
'LinkChecker: Pear HTTP_Request is not installed. Aborting');
479 foreach($a_links as $link)
481 if(gethostbyname($link[
'host']) == $link[
'host'])
487 if($link[
'scheme'] !==
'http' and $link[
'scheme'] !==
'https')
491 $req =&
new HTTP_Request($link[
'complete']);
494 switch($req->getResponseCode())
504 $link[
'http_status_code'] = $req->getResponseCode();
509 return $invalid ? $invalid : array();
514 $query =
"SELECT lm_id FROM lm_data ".
515 "WHERE obj_id = '".$a_page_id.
"'";
519 return $row->lm_id ? $row->lm_id : 0;
526 if($link[
'page_id'] == $a_page_id and
527 substr($link[
'complete'],0,255) == $a_url)
549 $query =
"INSERT INTO link_check ".
550 "SET page_id = ".$ilDB->quote($link[
'page_id']).
", ".
551 "obj_id = ".$ilDB->quote($link[
'obj_id']).
", ".
552 "url = ".$ilDB->quote((substr($link[
'complete'],0,255))).
", ".
553 "parent_type = ".$ilDB->quote(($link[
'type'])).
", ".
554 "http_status_code = ".$ilDB->quote(($link[
'http_status_code'])).
", ".
555 "last_check = '".time().
"'";
558 $res = $this->db->query($query);
571 $query =
"SELECT * FROM link_check ".
572 "WHERE page_id = ".$ilDB->quote($link[
'page_id']).
" ".
573 "AND url = ".$ilDB->quote((substr($link[
'complete'],0,255))).
" ";
574 $res = $this->db->query($query);
578 $this->notify[
"$link[obj_id]"][] = array(
'page_id' => $link[
'page_id'],
579 'url' => $link[
'complete']);
591 $query =
"DELETE FROM link_check";
595 $query =
"DELETE FROM link_check ".
596 "WHERE obj_id = ".$ilDB->quote($this->
getObjId()).
" ";
599 $this->db->query($query);