ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilLinkChecker Class Reference

class for checking external links in page objects Normally used in Cron jobs, but should be extensible for use in learning modules. More...

+ Collaboration diagram for ilLinkChecker:

Public Member Functions

 __construct ($db, $a_validate_all=true)
 
 setCheckPeriod ($a_period)
 
 getCheckPeriod ()
 
 setMailStatus ($a_status)
 
 getMailStatus ()
 
 __setType ($a_type)
 
 __getType ()
 
 setObjId ($a_page_id)
 
 getObjId ()
 
 getValidateAll ()
 
 getLogMessages ()
 
 getInvalidLinks ()
 
 getInvalidLinksFromDB ()
 
 getLastCheckTimestamp ()
 
 checkWebResourceLinks ()
 
 checkLinks ()
 
 __txt ($language, $key, $module='common')
 
 __fetchUserData ($a_usr_id)
 
 __getTitle ($a_lm_obj_id)
 
 __sendMail ()
 
 __getNotifyLinks ()
 
 __clearInvalidLinks ()
 
 __appendInvalidLink ($a_link)
 
 __appendLogMessage ($a_string)
 
 __clearLogMessages ()
 
 __getLinks ($a_page)
 
 __getWebResourceLinks ()
 
 __validateLinks ($a_links)
 $a_links Format: Array ( [1] => Array ( ['scheme'] => intern/http/https, ['ref_id'] => ILIAS ref ID, ['obj_type'] => ILIAS object type, ['complete'] => link to check, ), [2]=> ... ) More...
 
 __getObjIdByPageId ($a_page_id)
 
 __isInvalid ($a_page_id, $a_url)
 
 __saveInDB ()
 
 __checkNotify ()
 
 __clearDBData ()
 

Data Fields

 $db = null
 
 $log_messages = array()
 
 $invalid_links = array()
 
 $validate_all = true
 
 $mail_status = false
 
 $page_id = 0
 

Protected Member Functions

 createPermanentLink ($a_obj_id, $a_usr_id, $a_obj_type)
 creates a permanent link More...
 

Detailed Description

class for checking external links in page objects Normally used in Cron jobs, but should be extensible for use in learning modules.

In this case set second parameter of contructor = false, and use setPageObjectId()

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 12 of file class.ilLinkChecker.php.

Constructor & Destructor Documentation

◆ __construct()

ilLinkChecker::__construct (   $db,
  $a_validate_all = true 
)

Definition at line 23 of file class.ilLinkChecker.php.

24 {
25 global $DIC;
26
27 $ilDB = $DIC['ilDB'];
28
29 define('DEBUG', 1);
30 define('SOCKET_TIMEOUT', 5);
31 define('MAX_REDIRECTS', 5);
32
33 $this->db = $db;
34
35 // SET GLOBAL DB HANDLER FOR STATIC METHODS OTHER CLASSES
36 $ilDB = $db;
37
38 $this->validate_all = $a_validate_all;
39 }
global $ilDB
$DIC
Definition: xapitoken.php:46

References $db, $DIC, and $ilDB.

Member Function Documentation

◆ __appendInvalidLink()

ilLinkChecker::__appendInvalidLink (   $a_link)

Definition at line 359 of file class.ilLinkChecker.php.

360 {
361 $this->invalid_links[] = $a_link;
362 }

Referenced by checkLinks(), and checkWebResourceLinks().

+ Here is the caller graph for this function:

◆ __appendLogMessage()

ilLinkChecker::__appendLogMessage (   $a_string)

Definition at line 365 of file class.ilLinkChecker.php.

366 {
367 $this->log_messages[] = $a_string;
368 }

Referenced by __sendMail(), __validateLinks(), checkLinks(), and checkWebResourceLinks().

+ Here is the caller graph for this function:

◆ __checkNotify()

ilLinkChecker::__checkNotify ( )

Definition at line 594 of file class.ilLinkChecker.php.

595 {
596 global $DIC;
597
598 $ilDB = $DIC['ilDB'];
599
600 foreach ($this->getInvalidLinks() as $link) {
601 $query = "SELECT * FROM link_check " .
602 "WHERE page_id = " . $ilDB->quote($link['page_id'], 'integer') . " " .
603 "AND url = " . $ilDB->quote(substr($link['complete'], 0, 255), 'text') . " ";
604 $res = $ilDB->query($query);
605
606 if (!$res->numRows()) {
607 $this->notify[$link["obj_id"]][] = array('page_id' => $link['page_id'],
608 'url' => $link['complete']);
609 }
610 }
611 }
$query
foreach($_POST as $key=> $value) $res

References $DIC, $ilDB, $query, $res, and getInvalidLinks().

Referenced by __saveInDB().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __clearDBData()

ilLinkChecker::__clearDBData ( )

Definition at line 614 of file class.ilLinkChecker.php.

615 {
616 global $DIC;
617
618 $ilDB = $DIC['ilDB'];
619
620 if ($this->getValidateAll()) {
621 $query = "DELETE FROM link_check";
622 } else {
623 $query = "DELETE FROM link_check " .
624 "WHERE obj_id = " . $ilDB->quote($this->getObjId(), 'integer');
625 }
626 $res = $ilDB->manipulate($query);
627
628 return true;
629 }

References $DIC, $ilDB, $query, $res, getObjId(), and getValidateAll().

Referenced by __saveInDB().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __clearInvalidLinks()

ilLinkChecker::__clearInvalidLinks ( )

Definition at line 355 of file class.ilLinkChecker.php.

356 {
357 $this->invalid_links = array();
358 }

Referenced by checkLinks(), and checkWebResourceLinks().

+ Here is the caller graph for this function:

◆ __clearLogMessages()

ilLinkChecker::__clearLogMessages ( )

Definition at line 369 of file class.ilLinkChecker.php.

370 {
371 return $this->log_messages = array();
372 }

Referenced by checkLinks(), and checkWebResourceLinks().

+ Here is the caller graph for this function:

◆ __fetchUserData()

ilLinkChecker::__fetchUserData (   $a_usr_id)

Definition at line 216 of file class.ilLinkChecker.php.

217 {
218 global $DIC;
219
220 $ilDB = $DIC['ilDB'];
221
222 $r = $this->db->query("SELECT email FROM usr_data WHERE usr_id = " . $ilDB->quote($a_usr_id));
223
224 $row = $r->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
225
226 $data['email'] = $row->email;
227
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"));
231
232 $row = $ilDB->fetchObject($set);
233
234 $data['lang'] = $row->value;
235
236 return $data;
237 }
$data
Definition: storeScorm.php:23

References $data, $DIC, $ilDB, and ilDBConstants\FETCHMODE_OBJECT.

◆ __getLinks()

ilLinkChecker::__getLinks (   $a_page)

Definition at line 374 of file class.ilLinkChecker.php.

375 {
376 $matches = array();
377
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]);
382 // continue if mailto link
383 if ($url_data['scheme'] == 'mailto') {
384 continue;
385 }
386
387 // PUH, HTTP_REQUEST needs a beginning http://
388 if (!$url_data['scheme']) {
389 $matches[1][$i] = 'http://' . $matches[1][$i];
390 }
391
392 $lm_id = $this->__getObjIdByPageId($a_page['page_id']);
393 $link[] = array('page_id' => $a_page['page_id'],
394 'obj_id' => $lm_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']);
399 }
400 }
401
402 return $link ? $link : array();
403 }
__getObjIdByPageId($a_page_id)
$i
Definition: metadata.php:24

References $i, and __getObjIdByPageId().

Referenced by checkLinks().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __getNotifyLinks()

ilLinkChecker::__getNotifyLinks ( )

Definition at line 349 of file class.ilLinkChecker.php.

350 {
351 return $this->notify ? $this->notify : array();
352 }

Referenced by __sendMail().

+ Here is the caller graph for this function:

◆ __getObjIdByPageId()

ilLinkChecker::__getObjIdByPageId (   $a_page_id)

Definition at line 544 of file class.ilLinkChecker.php.

545 {
546 $res = $this->db->query("SELECT lm_id FROM lm_data " .
547 "WHERE obj_id = '" . $a_page_id . "'");
548
549 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
550
551 return $row->lm_id ? $row->lm_id : 0;
552 }

References $res, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by __getLinks().

+ Here is the caller graph for this function:

◆ __getTitle()

ilLinkChecker::__getTitle (   $a_lm_obj_id)

Definition at line 239 of file class.ilLinkChecker.php.

240 {
241 global $DIC;
242
243 $ilDB = $DIC['ilDB'];
244
245 $r = $this->db->query("SELECT title FROM object_data " .
246 "WHERE obj_id = " . $ilDB->quote($a_lm_obj_id, 'integer') . " ");
247
248 $row = $r->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
249
250 return $row->title;
251 }

References $DIC, $ilDB, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by __sendMail().

+ Here is the caller graph for this function:

◆ __getType()

ilLinkChecker::__getType ( )

Definition at line 63 of file class.ilLinkChecker.php.

64 {
65 return $this->type;
66 }
$type

References $type.

Referenced by __sendMail().

+ Here is the caller graph for this function:

◆ __getWebResourceLinks()

ilLinkChecker::__getWebResourceLinks ( )

Definition at line 405 of file class.ilLinkChecker.php.

406 {
407 global $DIC;
408
409 $objDefinition = $DIC['objDefinition'];
410
411
412
413 $link_res_obj = new ilLinkResourceItems($this->getObjId());
414
415 foreach ($check_links = $link_res_obj->getCheckItems($this->getCheckPeriod()) as $item_data) {
416 // #10091 - internal
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'],
423 'obj_id' => $this->getObjId(),
424 'type' => 'webr',
425 'complete' => $item_data['target'],
426 'scheme' => 'internal',
427 'obj_type' => $parts[0],
428 'ref_id' => $parts[1]);
429 continue;
430 }
431 }
432
433 // external
434 $url_data = @parse_url($item_data['target']);
435
436 // PUH, HTTP_REQUEST needs a beginning http://
437 if (!$url_data['scheme']) {
438 $item_data['target'] = 'http://' . $item_data['target'];
439 }
440
441 $link[] = array('page_id' => $item_data['link_id'],
442 'obj_id' => $this->getObjId(),
443 'type' => 'webr',
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']);
447 }
448 return $link ? $link : array();
449 }
Class ilObjLinkResourceGUI.

References $DIC, and getObjId().

Referenced by checkWebResourceLinks().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __isInvalid()

ilLinkChecker::__isInvalid (   $a_page_id,
  $a_url 
)

Definition at line 554 of file class.ilLinkChecker.php.

555 {
556 foreach ($this->getInvalidLinks() as $link) {
557 if ($link['page_id'] == $a_page_id and
558 substr($link['complete'], 0, 255) == $a_url) {
559 return true;
560 }
561 }
562 return false;
563 }

References getInvalidLinks().

+ Here is the call graph for this function:

◆ __saveInDB()

ilLinkChecker::__saveInDB ( )

Definition at line 565 of file class.ilLinkChecker.php.

566 {
567 global $DIC;
568
569 $ilDB = $DIC['ilDB'];
570
571 if ($this->getMailStatus()) {
572 $this->__checkNotify();
573 }
574 $this->__clearDBData();
575
576
577 foreach ($this->getInvalidLinks() as $link) {
578 $id = $ilDB->nextId('link_check');
579
580 $query = "INSERT INTO link_check (id, obj_id,page_id,url,parent_type,http_status_code,last_check) " .
581 "VALUES ( " .
582 $ilDB->quote($id, "integer") . "," .
583 $ilDB->quote($link['obj_id'], 'integer') . ", " .
584 $ilDB->quote($link['page_id'], 'integer') . ", " .
585 $ilDB->quote(substr($link['complete'], 0, 255), 'text') . ", " .
586 $ilDB->quote($link['type'], 'text') . ", " .
587 $ilDB->quote($link['http_status_code'] ? $link['http_status_code'] : 0, 'integer') . ", " .
588 $ilDB->quote(time(), 'integer') . " " .
589 ")";
590 $res = $ilDB->manipulate($query);
591 }
592 }

References $DIC, $ilDB, $query, $res, __checkNotify(), __clearDBData(), getInvalidLinks(), and getMailStatus().

Referenced by checkLinks(), and checkWebResourceLinks().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __sendMail()

ilLinkChecker::__sendMail ( )

Definition at line 253 of file class.ilLinkChecker.php.

254 {
255 global $DIC;
256
257 $ilUser = $DIC['ilUser'];
258
259
260 if (!count($notify = $this->__getNotifyLinks())) {
261 // Nothing to do
262 return true;
263 }
264 if (!$this->getMailStatus()) {
265 return true;
266 }
267
268
269 $body = "";
270 $obj_name = "";
271
272 foreach (ilLinkCheckNotify::_getAllNotifiers($this->db) as $usr_id => $obj_ids) {
273 if (!is_object($tmp_user = &ilObjectFactory::getInstanceByObjId($usr_id, false))) {
274 $this->__appendLogMessage('LinkChecker: Cannot find user with id: ' . $usr_id);
275 continue;
276 }
277
278 $counter = 0;
279 foreach ($obj_ids as $obj_id) {
280 if (!isset($notify[$obj_id])) {
281 continue;
282 }
283 ++$counter;
284
285 switch ($this->__getType()) {
286 case 'webr':
287 $obj_name = $this->__txt($tmp_user->getLanguage(), 'obj_webr');
288 break;
289 case 'lm':
290 default:
291 $obj_name = $this->__txt($tmp_user->getLanguage(), 'lo');
292 break;
293 }
294 $body .= $obj_name . ': ' . $this->__getTitle($obj_id) . "\r\n";
295 $body .= $this->__txt($tmp_user->getLanguage(), 'link_check_perma_link', "mail") . ": " .
296 $this->createPermanentLink($obj_id, $usr_id, $this->__getType()) . " \r\n";
297 $body .= $this->__txt($tmp_user->getLanguage(), "link_check_affected_links", "mail") . ":\r\n";
298
299 // Print all invalid
300 foreach ($notify[$obj_id] as $data) {
301 $body .= $data['url'] . "\r\n";
302 }
303 $body .= "\r\n";
304 }
305 if ($counter) {
306 $ntf = new ilSystemNotification();
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()));
313
314 $this->__appendLogMessage('LinkChecker: Sent mail to ' . $tmp_user->getEmail());
315 }
316 $body = "";
317 }
318 }
__txt($language, $key, $module='common')
createPermanentLink($a_obj_id, $a_usr_id, $a_obj_type)
creates a permanent link
__getTitle($a_lm_obj_id)
__appendLogMessage($a_string)
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Wrapper classes for system notifications.
$ilUser
Definition: imgupload.php:18

References $data, $DIC, $ilUser, __appendLogMessage(), __getNotifyLinks(), __getTitle(), __getType(), __txt(), ilLinkCheckNotify\_getAllNotifiers(), createPermanentLink(), ilObjectFactory\getInstanceByObjId(), and getMailStatus().

Referenced by checkLinks(), and checkWebResourceLinks().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __setType()

ilLinkChecker::__setType (   $a_type)

Definition at line 59 of file class.ilLinkChecker.php.

60 {
61 $this->type = $a_type;
62 }
$a_type
Definition: workflow.php:92

References $a_type.

Referenced by checkLinks(), and checkWebResourceLinks().

+ Here is the caller graph for this function:

◆ __txt()

ilLinkChecker::__txt (   $language,
  $key,
  $module = 'common' 
)

Definition at line 211 of file class.ilLinkChecker.php.

212 {
213 return ilLanguage::_lookupEntry($language, $module, $key);
214 }
static _lookupEntry($a_lang_key, $a_mod, $a_id)

References ilLanguage\_lookupEntry().

Referenced by __sendMail().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __validateLinks()

ilLinkChecker::__validateLinks (   $a_links)

$a_links Format: Array ( [1] => Array ( ['scheme'] => intern/http/https, ['ref_id'] => ILIAS ref ID, ['obj_type'] => ILIAS object type, ['complete'] => link to check, ), [2]=> ... )

Parameters
array$a_linksFormat:
Returns
array Returns all invalid links! Format like $a_links with additional error information ['http_status_code'] and ['curl_errno']

Definition at line 468 of file class.ilLinkChecker.php.

469 {
470 global $DIC;
471
472 $tree = $DIC['tree'];
474 $this->__appendLogMessage('LinkChecker: Pear HTTP_Request is not installed. Aborting');
475 ilLoggerFactory::getLogger('lchk')->error('LinkChecker: Curl extension is not loeaded. Aborting');
476 return array();
477 }
478 $invalid = array();
479
480 foreach ($a_links as $link) {
481 // #10091 - internal
482 if ($link['scheme'] == 'internal') {
483 $obj_id = ilObject::_lookupObjId($link['ref_id']);
484 if (!$obj_id ||
485 ilObject::_lookupType($obj_id) != $link['obj_type'] ||
486 $tree->isDeleted($link['ref_id'])) {
487 $invalid[] = $link;
488 }
489 }
490 // external
491 else {
492 //ilLoggerFactory::getLogger('lchk')->debug('Check: '.$link['complete']);
493
494 if ($link['scheme'] !== 'http' and $link['scheme'] !== 'https') {
495 ilLoggerFactory::getLogger('lchk')->error('LinkChecker: Unkown link sheme "' . $link['scheme'] . '". Continue check');
496 continue;
497 }
498
499 $curl = null;
500 $http_code = 0;
501 $c_error_no = 0;
502
503 try {
504 $curl = new ilCurlConnection($link['complete']);
505 $curl->init();
506
507 $curl->setOpt(CURLOPT_HEADER, 1);
508 $curl->setOpt(CURLOPT_RETURNTRANSFER, 1);
509 $curl->setOpt(CURLOPT_CONNECTTIMEOUT, SOCKET_TIMEOUT);
510 $curl->setOpt(CURLOPT_FOLLOWLOCATION, 1);
511 $curl->setOpt(CURLOPT_MAXREDIRS, MAX_REDIRECTS);
512 $curl->exec();
513 $headers = $curl->getInfo();
514 $http_code = $headers['http_code'];
515 } catch (ilCurlConnectionException $e) {
516 $c_error_no = $e->getCode();
517 ilLoggerFactory::getLogger('lchk')->error('LinkChecker: No valid http code received. Curl error (' . $e->getCode() . '): ' . $e->getMessage());
518 } finally {
519 if ($curl != null) {
520 $curl->close();
521 }
522 }
523
524 switch ($http_code) {
525 // EVERYTHING OK
526 case '200':
527 // In the moment 301 will be handled as ok
528 case '301':
529 case '302':
530 break;
531 default:
532 $link['http_status_code'] = $http_code;
533 if ($http_code == 0 && $c_error_no != 0) {
534 $link['curl_errno'] = $c_error_no;
535 }
536 $invalid[] = $link;
537 break;
538 }
539 }
540 }
541 return $invalid;
542 }
static _isCurlExtensionLoaded()
Check if curl extension is loaded.
static getLogger($a_component_id)
Get component logger.
static _lookupObjId($a_id)
static _lookupType($a_id, $a_reference=false)
lookup object type

References $DIC, Vendor\Package\$e, __appendLogMessage(), ilCurlConnection\_isCurlExtensionLoaded(), ilObject\_lookupObjId(), ilObject\_lookupType(), and ilLoggerFactory\getLogger().

Referenced by checkLinks(), and checkWebResourceLinks().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkLinks()

ilLinkChecker::checkLinks ( )

Definition at line 152 of file class.ilLinkChecker.php.

153 {
154 global $DIC;
155
156 $ilDB = $DIC['ilDB'];
157
158 $pages = array();
159
160 $this->__setType('lm');
161 $this->__clearLogMessages();
162 $this->__clearInvalidLinks();
163 $this->__appendLogMessage('LinkChecker: Start checkLinks()');
164
165 if (!$this->getValidateAll() and !$this->getObjId()) {
166 echo "ilLinkChecker::checkLinks() No Page id given";
167
168 return false;
169 } elseif (!$this->getValidateAll() and $this->getObjId()) {
170 $query = "SELECT * FROM page_object " .
171 "WHERE parent_id = " . $ilDB->quote($this->getObjId()) . " " .
172 "AND parent_type = 'lm'";
173
174 $res = $this->db->query($query);
175 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
176 $pages[] = array('page_id' => $row->page_id,
177 'content' => $row->content,
178 'type' => $row->parent_type);
179 }
180 } elseif ($this->getValidateAll()) {
181 $query = "SELECT * FROM page_object " .
182 "WHERE parent_type = 'lm'";
183
184 $res = $this->db->query($query);
185 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
186 $pages[] = array('page_id' => $row->page_id,
187 'content' => $row->content,
188 'type' => $row->parent_type);
189 }
190 }
191
192 // VALIDATE
193 foreach ($pages as $page) {
194 if (count($invalid = $this->__validateLinks($this->__getLinks($page)))) {
195 foreach ($invalid as $invalid_item) {
196 $this->__appendLogMessage('LinkChecker: found invalid link: ' . $invalid_item['complete']);
197 $this->__appendInvalidLink($invalid_item);
198 }
199 }
200 }
201
202 $this->__appendLogMessage('LinkChecker: End checkLinks()');
203 $this->__saveInDB();
204
205 $this->__sendMail();
206
207 return $this->getInvalidLinks();
208 }
__validateLinks($a_links)
$a_links Format: Array ( [1] => Array ( ['scheme'] => intern/http/https, ['ref_id'] => ILIAS ref ID,...
__appendInvalidLink($a_link)

References $DIC, $ilDB, $query, $res, __appendInvalidLink(), __appendLogMessage(), __clearInvalidLinks(), __clearLogMessages(), __getLinks(), __saveInDB(), __sendMail(), __setType(), __validateLinks(), ilDBConstants\FETCHMODE_OBJECT, getInvalidLinks(), getObjId(), and getValidateAll().

+ Here is the call graph for this function:

◆ checkWebResourceLinks()

ilLinkChecker::checkWebResourceLinks ( )

Definition at line 128 of file class.ilLinkChecker.php.

129 {
130 $pages = array();
131
132 $this->__setType('webr');
133 $this->__clearLogMessages();
134 $this->__clearInvalidLinks();
135 $this->__appendLogMessage('LinkChecker: Start checkLinks()');
136
137 if (count($invalid = $this->__validateLinks($this->__getWebResourceLinks()))) {
138 foreach ($invalid as $invalid_item) {
139 $this->__appendLogMessage('LinkChecker: found invalid link: ' . $invalid_item['complete']);
140 $this->__appendInvalidLink($invalid_item);
141 }
142 }
143
144 $this->__appendLogMessage('LinkChecker: End checkLinks()');
145 $this->__saveInDB();
146
147 $this->__sendMail();
148
149 return $this->getInvalidLinks();
150 }

References __appendInvalidLink(), __appendLogMessage(), __clearInvalidLinks(), __clearLogMessages(), __getWebResourceLinks(), __saveInDB(), __sendMail(), __setType(), __validateLinks(), and getInvalidLinks().

+ Here is the call graph for this function:

◆ createPermanentLink()

ilLinkChecker::createPermanentLink (   $a_obj_id,
  $a_usr_id,
  $a_obj_type 
)
protected

creates a permanent link

Parameters
$a_obj_id
$a_usr_id
$a_obj_type
Returns
string goto link

Definition at line 327 of file class.ilLinkChecker.php.

328 {
329 global $DIC;
330
331 $ilAccess = $DIC['ilAccess'];
332 $ref_ids = ilObject::_getAllReferences($a_obj_id);
333 $ref_id = null;
334
335 foreach ((array) $ref_ids as $id) {
336 if ($ilAccess->checkAccessOfUser($a_usr_id, "read", "", $id, $a_obj_type, $a_obj_id)) {
337 $ref_id = $id;
338 }
339 }
340
341 if ($ref_id === null) {
342 return false;
343 }
344
345
346 return ilLink::_getLink($ref_id, $a_obj_type);
347 }
static _getAllReferences($a_id)
get all reference ids of object

References $DIC, ilObject\_getAllReferences(), and ilLink\_getLink().

Referenced by __sendMail().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCheckPeriod()

ilLinkChecker::getCheckPeriod ( )

Definition at line 45 of file class.ilLinkChecker.php.

46 {
47 return $this->period;
48 }

◆ getInvalidLinks()

ilLinkChecker::getInvalidLinks ( )

Definition at line 87 of file class.ilLinkChecker.php.

88 {
89 return $this->invalid_links ? $this->invalid_links : array();
90 }

Referenced by __checkNotify(), __isInvalid(), __saveInDB(), checkLinks(), and checkWebResourceLinks().

+ Here is the caller graph for this function:

◆ getInvalidLinksFromDB()

ilLinkChecker::getInvalidLinksFromDB ( )

Definition at line 92 of file class.ilLinkChecker.php.

93 {
94 global $DIC;
95
96 $ilDB = $DIC['ilDB'];
97
98 $query = "SELECT * FROM link_check " .
99 "WHERE obj_id = " . $ilDB->quote($this->getObjId(), 'integer') . " ";
100
101 $res = $this->db->query($query);
102 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
103 $invalid[] = array('page_id' => $row->page_id,
104 'url' => $row->url);
105 }
106
107 return $invalid ? $invalid : array();
108 }

References $DIC, $ilDB, $query, $res, ilDBConstants\FETCHMODE_OBJECT, and getObjId().

+ Here is the call graph for this function:

◆ getLastCheckTimestamp()

ilLinkChecker::getLastCheckTimestamp ( )

Definition at line 110 of file class.ilLinkChecker.php.

111 {
112 global $DIC;
113
114 $ilDB = $DIC['ilDB'];
115
116 if ($this->getValidateAll()) {
117 $query = "SELECT MAX(last_check) last_check FROM link_check ";
118 } else {
119 $query = "SELECT MAX(last_check) last_check FROM link_check " .
120 "WHERE obj_id = " . $ilDB->quote($this->getObjId(), 'integer') . " ";
121 }
122 $res = $ilDB->query($query);
123 $row = $ilDB->fetchObject($res);
124
125 return $row->last_check ? $row->last_check : 0;
126 }

References $DIC, $ilDB, $query, $res, getObjId(), and getValidateAll().

+ Here is the call graph for this function:

◆ getLogMessages()

ilLinkChecker::getLogMessages ( )

Definition at line 82 of file class.ilLinkChecker.php.

83 {
84 return $this->log_messages ? $this->log_messages : array();
85 }

◆ getMailStatus()

ilLinkChecker::getMailStatus ( )

Definition at line 54 of file class.ilLinkChecker.php.

55 {
56 return (bool) $this->mail_status;
57 }

References $mail_status.

Referenced by __saveInDB(), and __sendMail().

+ Here is the caller graph for this function:

◆ getObjId()

ilLinkChecker::getObjId ( )

Definition at line 72 of file class.ilLinkChecker.php.

73 {
74 return $this->page_id;
75 }

References $page_id.

Referenced by __clearDBData(), __getWebResourceLinks(), checkLinks(), getInvalidLinksFromDB(), and getLastCheckTimestamp().

+ Here is the caller graph for this function:

◆ getValidateAll()

ilLinkChecker::getValidateAll ( )

Definition at line 77 of file class.ilLinkChecker.php.

78 {
79 return $this->validate_all ? true : false;
80 }

Referenced by __clearDBData(), checkLinks(), and getLastCheckTimestamp().

+ Here is the caller graph for this function:

◆ setCheckPeriod()

ilLinkChecker::setCheckPeriod (   $a_period)

Definition at line 41 of file class.ilLinkChecker.php.

42 {
43 $this->period = $a_period;
44 }

◆ setMailStatus()

ilLinkChecker::setMailStatus (   $a_status)

Definition at line 50 of file class.ilLinkChecker.php.

51 {
52 $this->mail_status = (bool) $a_status;
53 }

◆ setObjId()

ilLinkChecker::setObjId (   $a_page_id)

Definition at line 68 of file class.ilLinkChecker.php.

69 {
70 return $this->page_id = $a_page_id;
71 }

Field Documentation

◆ $db

ilLinkChecker::$db = null

Definition at line 14 of file class.ilLinkChecker.php.

Referenced by __construct().

◆ $invalid_links

ilLinkChecker::$invalid_links = array()

Definition at line 16 of file class.ilLinkChecker.php.

◆ $log_messages

ilLinkChecker::$log_messages = array()

Definition at line 15 of file class.ilLinkChecker.php.

◆ $mail_status

ilLinkChecker::$mail_status = false

Definition at line 19 of file class.ilLinkChecker.php.

Referenced by getMailStatus().

◆ $page_id

ilLinkChecker::$page_id = 0

Definition at line 20 of file class.ilLinkChecker.php.

Referenced by getObjId().

◆ $validate_all

ilLinkChecker::$validate_all = true

Definition at line 18 of file class.ilLinkChecker.php.


The documentation for this class was generated from the following file: