30 define(
'SOCKET_TIMEOUT', 5);
31 define(
'MAX_REDIRECTS', 5);
38 $this->validate_all = $a_validate_all;
43 $this->period = $a_period;
52 $this->mail_status = (bool) $a_status;
70 return $this->page_id = $a_page_id;
79 return $this->validate_all ? true :
false;
84 return $this->log_messages ? $this->log_messages : array();
89 return $this->invalid_links ? $this->invalid_links : array();
98 $query =
"SELECT * FROM link_check " .
99 "WHERE obj_id = " .
$ilDB->quote($this->
getObjId(),
'integer') .
" ";
103 $invalid[] = array(
'page_id' =>
$row->page_id,
107 return $invalid ? $invalid : array();
114 $ilDB = $DIC[
'ilDB'];
117 $query =
"SELECT MAX(last_check) last_check FROM link_check ";
119 $query =
"SELECT MAX(last_check) last_check FROM link_check " .
120 "WHERE obj_id = " .
$ilDB->quote($this->
getObjId(),
'integer') .
" ";
125 return $row->last_check ?
$row->last_check : 0;
138 foreach ($invalid as $invalid_item) {
139 $this->
__appendLogMessage(
'LinkChecker: found invalid link: ' . $invalid_item[
'complete']);
156 $ilDB = $DIC[
'ilDB'];
166 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'";
176 $pages[] = array(
'page_id' =>
$row->page_id,
177 'content' =>
$row->content,
178 'type' =>
$row->parent_type);
181 $query =
"SELECT * FROM page_object " .
182 "WHERE parent_type = 'lm'";
186 $pages[] = array(
'page_id' =>
$row->page_id,
187 'content' =>
$row->content,
188 'type' =>
$row->parent_type);
193 foreach ($pages as $page) {
195 foreach ($invalid as $invalid_item) {
196 $this->
__appendLogMessage(
'LinkChecker: found invalid link: ' . $invalid_item[
'complete']);
220 $ilDB = $DIC[
'ilDB'];
222 $r = $this->db->query(
"SELECT email FROM usr_data WHERE usr_id = " .
$ilDB->quote($a_usr_id));
228 $set =
$ilDB->query(
"SELECT * FROM usr_pref " .
229 "WHERE usr_id = " .
$ilDB->quote($a_usr_id,
"integer") .
" " .
230 "AND keyword = " .
$ilDB->quote(
'language',
"text"));
243 $ilDB = $DIC[
'ilDB'];
245 $r = $this->db->query(
"SELECT title FROM object_data " .
246 "WHERE obj_id = " .
$ilDB->quote($a_lm_obj_id,
'integer') .
" ");
279 foreach ($obj_ids as $obj_id) {
280 if (!isset($notify[$obj_id])) {
287 $obj_name = $this->
__txt($tmp_user->getLanguage(),
'obj_webr');
291 $obj_name = $this->
__txt($tmp_user->getLanguage(),
'lo');
294 $body .= $obj_name .
': ' . $this->
__getTitle($obj_id) .
"\r\n";
295 $body .= $this->
__txt($tmp_user->getLanguage(),
'link_check_perma_link',
"mail") .
": " .
297 $body .= $this->
__txt($tmp_user->getLanguage(),
"link_check_affected_links",
"mail") .
":\r\n";
300 foreach ($notify[$obj_id] as
$data) {
301 $body .= $data[
'url'] .
"\r\n";
307 $ntf->setLangModules(array(
"mail",
"common"));
308 $ntf->setSubjectLangId(
"link_check_subject");
309 $ntf->setIntroductionLangId(
"link_check_introduction");
310 $ntf->setReasonLangId(
"link_check_reason");
311 $ntf->addAdditionalInfo(
"additional_info", $body,
true);
312 $ntf->sendMail(array($tmp_user->getId()));
331 $ilAccess = $DIC[
'ilAccess'];
335 foreach ((array) $ref_ids as
$id) {
336 if ($ilAccess->checkAccessOfUser($a_usr_id,
"read",
"", $id, $a_obj_type, $a_obj_id)) {
341 if ($ref_id === null) {
351 return $this->notify ? $this->notify : array();
357 $this->invalid_links = array();
361 $this->invalid_links[] = $a_link;
367 $this->log_messages[] = $a_string;
371 return $this->log_messages = array();
378 $pattern_complete =
'/<ExtLink Href="([^"]*)">/';
379 if (preg_match_all($pattern_complete, $a_page[
'content'], $matches)) {
380 for (
$i = 0;
$i < count($matches[0]); ++
$i) {
381 $url_data = @parse_url($matches[1][
$i]);
383 if ($url_data[
'scheme'] ==
'mailto') {
388 if (!$url_data[
'scheme']) {
389 $matches[1][
$i] =
'http://' . $matches[1][
$i];
393 $link[] = array(
'page_id' => $a_page[
'page_id'],
395 'type' => $a_page[
'type'],
396 'complete' => $matches[1][$i],
397 'scheme' => isset($url_data[
'scheme']) ? $url_data[
'scheme'] :
'http',
398 'host' => isset($url_data[
'host']) ? $url_data[
'host'] : $url_data[
'path']);
402 return $link ? $link : array();
409 $objDefinition = $DIC[
'objDefinition'];
415 foreach ($check_links = $link_res_obj->getCheckItems($this->getCheckPeriod()) as $item_data) {
417 if (strpos($item_data[
'target'],
'|')) {
418 $parts = explode(
'|', $item_data[
'target']);
419 if (
sizeof($parts) == 2 &&
420 is_numeric($parts[1]) &&
421 $objDefinition->isAllowedInRepository($parts[0])) {
422 $link[] = array(
'page_id' => $item_data[
'link_id'],
425 'complete' => $item_data[
'target'],
426 'scheme' =>
'internal',
427 'obj_type' => $parts[0],
428 'ref_id' => $parts[1]);
434 $url_data = @parse_url($item_data[
'target']);
437 if (!$url_data[
'scheme']) {
438 $item_data[
'target'] =
'http://' . $item_data[
'target'];
441 $link[] = array(
'page_id' => $item_data[
'link_id'],
444 'complete' => $item_data[
'target'],
445 'scheme' => isset($url_data[
'scheme']) ? $url_data[
'scheme'] :
'http',
446 'host' => isset($url_data[
'host']) ? $url_data[
'host'] : $url_data[
'path']);
448 return $link ? $link : array();
472 $tree = $DIC[
'tree'];
474 $this->
__appendLogMessage(
'LinkChecker: Pear HTTP_Request is not installed. Aborting');
480 foreach ($a_links as $link) {
482 if ($link[
'scheme'] ==
'internal') {
486 $tree->isDeleted($link[
'ref_id'])) {
494 if ($link[
'scheme'] !==
'http' and $link[
'scheme'] !==
'https') {
507 $curl->setOpt(CURLOPT_HTTPPROXYTUNNEL,
true);
512 $curl->setOpt(CURLOPT_HEADER, 1);
513 $curl->setOpt(CURLOPT_RETURNTRANSFER, 1);
514 $curl->setOpt(CURLOPT_CONNECTTIMEOUT, SOCKET_TIMEOUT);
515 $curl->setOpt(CURLOPT_FOLLOWLOCATION, 1);
516 $curl->setOpt(CURLOPT_MAXREDIRS, MAX_REDIRECTS);
518 $headers = $curl->getInfo();
519 $http_code = $headers[
'http_code'];
521 $c_error_no = $e->getCode();
522 ilLoggerFactory::getLogger(
'lchk')->error(
'LinkChecker: No valid http code received. Curl error (' . $e->getCode() .
'): ' . $e->getMessage());
529 switch ($http_code) {
537 $link[
'http_status_code'] = $http_code;
538 if ($http_code == 0 && $c_error_no != 0) {
539 $link[
'curl_errno'] = $c_error_no;
551 $res = $this->db->query(
"SELECT lm_id FROM lm_data " .
552 "WHERE obj_id = '" . $a_page_id .
"'");
556 return $row->lm_id ?
$row->lm_id : 0;
562 if ($link[
'page_id'] == $a_page_id
and 563 substr($link[
'complete'], 0, 255) == $a_url) {
574 $ilDB = $DIC[
'ilDB'];
585 $query =
"INSERT INTO link_check (id, obj_id,page_id,url,parent_type,http_status_code,last_check) " .
587 $ilDB->quote(
$id,
"integer") .
"," .
588 $ilDB->quote($link[
'obj_id'],
'integer') .
", " .
589 $ilDB->quote($link[
'page_id'],
'integer') .
", " .
590 $ilDB->quote(substr($link[
'complete'], 0, 255),
'text') .
", " .
591 $ilDB->quote($link[
'type'],
'text') .
", " .
592 $ilDB->quote($link[
'http_status_code'] ? $link[
'http_status_code'] : 0,
'integer') .
", " .
593 $ilDB->quote(time(),
'integer') .
" " .
603 $ilDB = $DIC[
'ilDB'];
606 $query =
"SELECT * FROM link_check " .
607 "WHERE page_id = " .
$ilDB->quote($link[
'page_id'],
'integer') .
" " .
608 "AND url = " .
$ilDB->quote(substr($link[
'complete'], 0, 255),
'text') .
" ";
611 if (!
$res->numRows()) {
612 $this->notify[$link[
"obj_id"]][] = array(
'page_id' => $link[
'page_id'],
613 'url' => $link[
'complete']);
623 $ilDB = $DIC[
'ilDB'];
626 $query =
"DELETE FROM link_check";
628 $query =
"DELETE FROM link_check " .
629 "WHERE obj_id = " .
$ilDB->quote($this->
getObjId(),
'integer');
setCheckPeriod($a_period)
if(!array_key_exists('StateId', $_REQUEST)) $id
class for checking external links in page objects Normally used in Cron jobs, but should be extensibl...
static _lookupEntry($a_lang_key, $a_mod, $a_id)
createPermanentLink($a_obj_id, $a_usr_id, $a_obj_type)
creates a permanent link
static _getAllReferences($a_id)
get all reference ids of object
if($modEnd===false) $module
__appendLogMessage($a_string)
static _getAllNotifiers(&$db)
foreach($_POST as $key=> $value) $res
__isInvalid($a_page_id, $a_url)
__txt($language, $key, $module='common')
static _isCurlExtensionLoaded()
Check if curl extension is loaded.
static _lookupObjId($a_id)
__construct($db, $a_validate_all=true)
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupType($a_id, $a_reference=false)
lookup object type
__getObjIdByPageId($a_page_id)
Class ilObjLinkResourceGUI.
__appendInvalidLink($a_link)
static getLogger($a_component_id)
Get component logger.
__validateLinks($a_links)
$a_links Format: Array ( [1] => Array ( ['scheme'] => intern/http/https, ['ref_id'] => ILIAS ref ID...
static _getInstance()
Getter for unique instance.
Wrapper classes for system notifications.
__fetchUserData($a_usr_id)
static _getLink($a_ref_id, $a_type='', $a_params=array(), $append="")