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') .
" ";
99 $invalid[] =
array(
'page_id' =>
$row->page_id,
103 return $invalid ? $invalid :
array();
111 $query =
"SELECT MAX(last_check) last_check FROM link_check ";
113 $query =
"SELECT MAX(last_check) last_check FROM link_check " .
114 "WHERE obj_id = " . $ilDB->quote($this->
getObjId(),
'integer') .
" ";
119 return $row->last_check ?
$row->last_check : 0;
132 foreach ($invalid as $invalid_item) {
133 $this->
__appendLogMessage(
'LinkChecker: found invalid link: ' . $invalid_item[
'complete']);
158 echo
"ilLinkChecker::checkLinks() No Page id given";
162 $query =
"SELECT * FROM page_object " .
163 "WHERE parent_id = " . $ilDB->quote($this->
getObjId()) .
" " .
164 "AND parent_type = 'lm'";
168 $pages[] =
array(
'page_id' =>
$row->page_id,
169 'content' =>
$row->content,
170 'type' =>
$row->parent_type);
173 $query =
"SELECT * FROM page_object " .
174 "WHERE parent_type = 'lm'";
178 $pages[] =
array(
'page_id' =>
$row->page_id,
179 'content' =>
$row->content,
180 'type' =>
$row->parent_type);
185 foreach ($pages as $page) {
187 foreach ($invalid as $invalid_item) {
188 $this->
__appendLogMessage(
'LinkChecker: found invalid link: ' . $invalid_item[
'complete']);
214 $r = $this->db->query(
"SELECT email FROM usr_data WHERE usr_id = " . $ilDB->quote($a_usr_id));
220 $set = $ilDB->query(
"SELECT * FROM usr_pref " .
221 "WHERE usr_id = " . $ilDB->quote($a_usr_id,
"integer") .
" " .
222 "AND keyword = " . $ilDB->quote(
'language',
"text"));
224 $row = $ilDB->fetchObject($set);
235 $r = $this->db->query(
"SELECT title FROM object_data " .
236 "WHERE obj_id = " . $ilDB->quote($a_lm_obj_id,
'integer') .
" ");
267 foreach ($obj_ids as $obj_id) {
268 if (!isset($notify[$obj_id])) {
275 $obj_name = $this->
__txt($tmp_user->getLanguage(),
'obj_webr');
279 $obj_name = $this->
__txt($tmp_user->getLanguage(),
'lo');
282 $body .= $obj_name .
': ' . $this->
__getTitle($obj_id) .
"\r\n";
283 $body .= $this->
__txt($tmp_user->getLanguage(),
'link_check_perma_link',
"mail") .
": " .
285 $body .= $this->
__txt($tmp_user->getLanguage(),
"link_check_affected_links",
"mail") .
":\r\n";
288 foreach ($notify[$obj_id] as
$data) {
289 $body .= $data[
'url'] .
"\r\n";
295 $ntf->setLangModules(
array(
"mail",
"common"));
296 $ntf->setSubjectLangId(
"link_check_subject");
297 $ntf->setIntroductionLangId(
"link_check_introduction");
298 $ntf->setReasonLangId(
"link_check_reason");
299 $ntf->addAdditionalInfo(
"additional_info", $body,
true);
300 $ntf->sendMail(
array($tmp_user->getId()));
322 if ($ilAccess->checkAccessOfUser($a_usr_id,
"read",
"", $id, $a_obj_type, $a_obj_id)) {
327 if ($ref_id === null) {
337 return $this->notify ? $this->notify :
array();
343 $this->invalid_links =
array();
347 $this->invalid_links[] = $a_link;
353 $this->log_messages[] = $a_string;
357 return $this->log_messages =
array();
364 $pattern_complete =
'/<ExtLink Href="([^"]*)">/';
365 if (preg_match_all($pattern_complete, $a_page[
'content'], $matches)) {
366 for (
$i = 0;
$i < count($matches[0]); ++
$i) {
367 $url_data = @parse_url($matches[1][
$i]);
369 if ($url_data[
'scheme'] ==
'mailto') {
374 if (!$url_data[
'scheme']) {
375 $matches[1][
$i] =
'http://' . $matches[1][
$i];
379 $link[] =
array(
'page_id' => $a_page[
'page_id'],
381 'type' => $a_page[
'type'],
382 'complete' => $matches[1][$i],
383 'scheme' => isset($url_data[
'scheme']) ? $url_data[
'scheme'] :
'http',
384 'host' => isset($url_data[
'host']) ? $url_data[
'host'] : $url_data[
'path']);
388 return $link ? $link :
array();
393 global $objDefinition;
399 foreach ($check_links = $link_res_obj->getCheckItems($this->getCheckPeriod()) as $item_data) {
401 if (strpos($item_data[
'target'],
'|')) {
402 $parts = explode(
'|', $item_data[
'target']);
403 if (
sizeof($parts) == 2 &&
404 is_numeric($parts[1]) &&
405 $objDefinition->isAllowedInRepository($parts[0])) {
406 $link[] =
array(
'page_id' => $item_data[
'link_id'],
409 'complete' => $item_data[
'target'],
410 'scheme' =>
'internal',
411 'obj_type' => $parts[0],
412 'ref_id' => $parts[1]);
418 $url_data = @parse_url($item_data[
'target']);
421 if (!$url_data[
'scheme']) {
422 $item_data[
'target'] =
'http://' . $item_data[
'target'];
425 $link[] =
array(
'page_id' => $item_data[
'link_id'],
428 'complete' => $item_data[
'target'],
429 'scheme' => isset($url_data[
'scheme']) ? $url_data[
'scheme'] :
'http',
430 'host' => isset($url_data[
'host']) ? $url_data[
'host'] : $url_data[
'path']);
432 return $link ? $link :
array();
456 $this->
__appendLogMessage(
'LinkChecker: Pear HTTP_Request is not installed. Aborting');
462 foreach ($a_links as $link) {
464 if ($link[
'scheme'] ==
'internal') {
468 $tree->isDeleted($link[
'ref_id'])) {
476 if ($link[
'scheme'] !==
'http' and $link[
'scheme'] !==
'https') {
489 $curl->setOpt(CURLOPT_HTTPPROXYTUNNEL,
true);
494 $curl->setOpt(CURLOPT_HEADER, 1);
495 $curl->setOpt(CURLOPT_RETURNTRANSFER, 1);
496 $curl->setOpt(CURLOPT_CONNECTTIMEOUT, SOCKET_TIMEOUT);
497 $curl->setOpt(CURLOPT_FOLLOWLOCATION, 1);
498 $curl->setOpt(CURLOPT_MAXREDIRS, MAX_REDIRECTS);
500 $headers = $curl->getInfo();
501 $http_code = $headers[
'http_code'];
503 $c_error_no = $e->getCode();
504 ilLoggerFactory::getLogger(
'lchk')->error(
'LinkChecker: No valid http code received. Curl error (' . $e->getCode() .
'): ' . $e->getMessage());
511 switch ($http_code) {
519 $link[
'http_status_code'] = $http_code;
520 if ($http_code == 0 && $c_error_no != 0) {
521 $link[
'curl_errno'] = $c_error_no;
533 $res = $this->db->query(
"SELECT lm_id FROM lm_data " .
534 "WHERE obj_id = '" . $a_page_id .
"'");
538 return $row->lm_id ?
$row->lm_id : 0;
544 if ($link[
'page_id'] == $a_page_id and
545 substr($link[
'complete'], 0, 255) == $a_url) {
563 $id = $ilDB->nextId(
'link_check');
565 $query =
"INSERT INTO link_check (id, obj_id,page_id,url,parent_type,http_status_code,last_check) " .
567 $ilDB->quote(
$id,
"integer") .
"," .
568 $ilDB->quote($link[
'obj_id'],
'integer') .
", " .
569 $ilDB->quote($link[
'page_id'],
'integer') .
", " .
570 $ilDB->quote(substr($link[
'complete'], 0, 255),
'text') .
", " .
571 $ilDB->quote($link[
'type'],
'text') .
", " .
572 $ilDB->quote($link[
'http_status_code'] ? $link[
'http_status_code'] : 0,
'integer') .
", " .
573 $ilDB->quote(
time(),
'integer') .
" " .
584 $query =
"SELECT * FROM link_check " .
585 "WHERE page_id = " . $ilDB->quote($link[
'page_id'],
'integer') .
" " .
586 "AND url = " . $ilDB->quote(substr($link[
'complete'], 0, 255),
'text') .
" ";
589 if (!
$res->numRows()) {
590 $this->notify[$link[
"obj_id"]][] =
array(
'page_id' => $link[
'page_id'],
591 'url' => $link[
'complete']);
602 $query =
"DELETE FROM link_check";
604 $query =
"DELETE FROM link_check " .
605 "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
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="")