28 define(
'SOCKET_TIMEOUT',5);
29 define(
'MAX_REDIRECTS',5);
36 $this->validate_all = $a_validate_all;
41 $this->period = $a_period;
50 $this->mail_status = (bool) $a_status;
68 return $this->page_id = $a_page_id;
77 return $this->validate_all ? true :
false;
82 return $this->log_messages ? $this->log_messages :
array();
87 return $this->invalid_links ? $this->invalid_links :
array();
94 $query =
"SELECT * FROM link_check ".
95 "WHERE obj_id = ".$ilDB->quote($this->
getObjId(),
'integer').
" ";
100 $invalid[] =
array(
'page_id' =>
$row->page_id,
104 return $invalid ? $invalid :
array();
113 $query =
"SELECT MAX(last_check) last_check FROM link_check ";
117 $query =
"SELECT MAX(last_check) last_check FROM link_check ".
118 "WHERE obj_id = ".$ilDB->quote($this->
getObjId(),
'integer').
" ";
123 return $row->last_check ?
$row->last_check : 0;
137 foreach($invalid as $invalid_item)
139 $this->
__appendLogMessage(
'LinkChecker: found invalid link: '.$invalid_item[
'complete']);
165 echo "ilLinkChecker::checkLinks() No Page id given";
171 $query =
"SELECT * FROM page_object ".
172 "WHERE parent_id = ".$ilDB->quote($this->
getObjId()).
" ".
173 "AND parent_type = 'lm'";
178 $pages[] =
array(
'page_id' =>
$row->page_id,
179 'content' =>
$row->content,
180 'type' =>
$row->parent_type);
185 $query =
"SELECT * FROM page_object ".
186 "WHERE parent_type = 'lm'";
191 $pages[] =
array(
'page_id' =>
$row->page_id,
192 'content' =>
$row->content,
193 'type' =>
$row->parent_type);
198 foreach($pages as $page)
202 foreach($invalid as $invalid_item)
204 $this->
__appendLogMessage(
'LinkChecker: found invalid link: '.$invalid_item[
'complete']);
219 function __txt($language,$key,$module =
'common')
223 include_once
'./Services/Language/classes/class.ilLanguage.php';
231 $r = $this->db->query(
"SELECT email FROM usr_data WHERE usr_id = ".$ilDB->quote($a_usr_id));
237 $set = $ilDB->query(
"SELECT * FROM usr_pref ".
238 "WHERE usr_id = ".$ilDB->quote($a_usr_id,
"integer").
" ".
239 "AND keyword = ".$ilDB->quote(
'language',
"text"));
241 $row = $ilDB->fetchObject($set);
252 $r = $this->db->query(
"SELECT title FROM object_data ".
253 "WHERE obj_id = ".$ilDB->quote($a_lm_obj_id ,
'integer').
" ");
275 include_once
'./Services/LinkChecker/classes/class.ilLinkCheckNotify.php';
288 foreach($obj_ids as $obj_id)
290 if(!isset($notify[$obj_id]))
299 $obj_name = $this->
__txt($tmp_user->getLanguage(),
'obj_webr');
303 $obj_name = $this->
__txt($tmp_user->getLanguage(),
'lo');
306 $body .= $obj_name.
': '.$this->
__getTitle($obj_id).
"\r\n";
307 $body .= $this->
__txt($tmp_user->getLanguage(),
'link_check_perma_link',
"mail").
": " .
309 $body .= $this->
__txt($tmp_user->getLanguage(),
"link_check_affected_links",
"mail").
":\r\n";
312 foreach($notify[$obj_id] as
$data)
314 $body .= $data[
'url'].
"\r\n";
320 include_once
"./Services/Notification/classes/class.ilSystemNotification.php";
322 $ntf->setLangModules(
array(
"mail",
"common"));
323 $ntf->setSubjectLangId(
"link_check_subject");
324 $ntf->setIntroductionLangId(
"link_check_introduction");
325 $ntf->setReasonLangId(
"link_check_reason");
326 $ntf->addAdditionalInfo(
"additional_info", $body,
true);
327 $ntf->sendMail(
array($tmp_user->getId()));
348 foreach((
array) $ref_ids as $id)
350 if($ilAccess->checkAccessOfUser($a_usr_id,
"read",
"", $id, $a_obj_type, $a_obj_id))
361 include_once
'./Services/Link/classes/class.ilLink.php';
367 return $this->notify ? $this->notify :
array();
373 $this->invalid_links =
array();
377 $this->invalid_links[] = $a_link;
383 $this->log_messages[] = $a_string;
387 return $this->log_messages =
array();
394 $pattern_complete =
'/<ExtLink Href="([^"]*)">/';
395 if(preg_match_all($pattern_complete,$a_page[
'content'],$matches))
397 for($i = 0;$i < count($matches[0]); ++$i)
399 $url_data = @parse_url($matches[1][$i]);
401 if($url_data[
'scheme'] ==
'mailto')
407 if(!$url_data[
'scheme'])
409 $matches[1][$i] =
'http://'.$matches[1][$i];
413 $link[] =
array(
'page_id' => $a_page[
'page_id'],
415 'type' => $a_page[
'type'],
416 'complete' => $matches[1][$i],
417 'scheme' => isset($url_data[
'scheme']) ? $url_data[
'scheme'] :
'http',
418 'host' => isset($url_data[
'host']) ? $url_data[
'host'] : $url_data[
'path']);
422 return $link ? $link :
array();
427 global $objDefinition;
429 include_once
'Modules/WebResource/classes/class.ilLinkResourceItems.php';
433 foreach($check_links = $link_res_obj->getCheckItems($this->getCheckPeriod()) as $item_data)
436 if(strpos($item_data[
'target'],
'|'))
438 $parts = explode(
'|', $item_data[
'target']);
439 if(
sizeof($parts) == 2 &&
440 is_numeric($parts[1]) &&
441 $objDefinition->isAllowedInRepository($parts[0]))
443 $link[] =
array(
'page_id' => $item_data[
'link_id'],
446 'complete' => $item_data[
'target'],
447 'scheme' =>
'internal',
448 'obj_type' => $parts[0],
449 'ref_id' => $parts[1]);
455 $url_data = @parse_url($item_data[
'target']);
458 if(!$url_data[
'scheme'])
460 $item_data[
'target'] =
'http://'.$item_data[
'target'];
463 $link[] =
array(
'page_id' => $item_data[
'link_id'],
466 'complete' => $item_data[
'target'],
467 'scheme' => isset($url_data[
'scheme']) ? $url_data[
'scheme'] :
'http',
468 'host' => isset($url_data[
'host']) ? $url_data[
'host'] : $url_data[
'path']);
470 return $link ? $link :
array();
493 include_once(
'./Services/Logging/classes/public/class.ilLoggerFactory.php');
494 include_once(
'./Services/WebServices/Curl/classes/class.ilCurlConnection.php');
497 $this->
__appendLogMessage(
'LinkChecker: Pear HTTP_Request is not installed. Aborting');
503 foreach($a_links as $link)
506 if($link[
'scheme'] ==
'internal')
511 $tree->isDeleted($link[
'ref_id']))
519 if($link[
'scheme'] !==
'http' and $link[
'scheme'] !==
'https')
525 require_once
'./Services/Http/classes/class.ilProxySettings.php';
535 $curl->setOpt(CURLOPT_HTTPPROXYTUNNEL,
true );
540 $curl->setOpt( CURLOPT_HEADER, 1);
541 $curl->setOpt(CURLOPT_RETURNTRANSFER, 1);
542 $curl->setOpt(CURLOPT_CONNECTTIMEOUT ,SOCKET_TIMEOUT);
543 $curl->setOpt(CURLOPT_FOLLOWLOCATION, 1);
544 $curl->setOpt(CURLOPT_MAXREDIRS ,MAX_REDIRECTS);
546 $headers = $curl->getInfo();
547 $http_code = $headers[
'http_code'];
551 $c_error_no = $e->getCode();
552 ilLoggerFactory::getLogger(
'lchk')->error(
'LinkChecker: No valid http code received. Curl error ('.$e->getCode().
'): ' . $e->getMessage());
564 $link[
'http_status_code'] = $http_code;
565 if($http_code == 0 && $c_error_no != 0)
567 $link[
'curl_errno'] = $c_error_no;
579 $res = $this->db->query(
"SELECT lm_id FROM lm_data ".
580 "WHERE obj_id = '".$a_page_id.
"'");
584 return $row->lm_id ?
$row->lm_id : 0;
591 if($link[
'page_id'] == $a_page_id
and 592 substr($link[
'complete'],0,255) == $a_url)
613 $id = $ilDB->nextId(
'link_check');
615 $query =
"INSERT INTO link_check (id, obj_id,page_id,url,parent_type,http_status_code,last_check) ".
617 $ilDB->quote($id,
"integer").
",".
618 $ilDB->quote($link[
'obj_id'],
'integer').
", ".
619 $ilDB->quote($link[
'page_id'],
'integer').
", ".
620 $ilDB->quote(substr($link[
'complete'],0,255),
'text').
", ".
621 $ilDB->quote($link[
'type'],
'text').
", ".
622 $ilDB->quote($link[
'http_status_code'] ? $link[
'http_status_code'] : 0,
'integer').
", ".
623 $ilDB->quote(
time(),
'integer').
" ".
635 $query =
"SELECT * FROM link_check ".
636 "WHERE page_id = ".$ilDB->quote($link[
'page_id'],
'integer').
" ".
637 "AND url = ".$ilDB->quote(substr($link[
'complete'],0,255),
'text').
" ";
642 $this->notify[$link[
"obj_id"]][] =
array(
'page_id' => $link[
'page_id'],
643 'url' => $link[
'complete']);
655 $query =
"DELETE FROM link_check";
659 $query =
"DELETE FROM link_check ".
660 "WHERE obj_id = ".$ilDB->quote($this->
getObjId(),
'integer');
setCheckPeriod($a_period)
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
__appendLogMessage($a_string)
static _getAllNotifiers(&$db)
__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
Create styles array
The data for the language used.
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.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
__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="")