ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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.

References $db, and $ilDB.

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

Member Function Documentation

◆ __appendInvalidLink()

ilLinkChecker::__appendInvalidLink (   $a_link)

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

Referenced by checkLinks(), and checkWebResourceLinks().

346  {
347  $this->invalid_links[] = $a_link;
348  }
+ Here is the caller graph for this function:

◆ __appendLogMessage()

ilLinkChecker::__appendLogMessage (   $a_string)

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

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

352  {
353  $this->log_messages[] = $a_string;
354  }
+ Here is the caller graph for this function:

◆ __checkNotify()

ilLinkChecker::__checkNotify ( )

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

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

Referenced by __saveInDB().

580  {
581  global $ilDB;
582 
583  foreach ($this->getInvalidLinks() as $link) {
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') . " ";
587  $res = $ilDB->query($query);
588 
589  if (!$res->numRows()) {
590  $this->notify[$link["obj_id"]][] = array('page_id' => $link['page_id'],
591  'url' => $link['complete']);
592  }
593  }
594  }
foreach($_POST as $key=> $value) $res
$query
Create styles array
The data for the language used.
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __clearDBData()

ilLinkChecker::__clearDBData ( )

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

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

Referenced by __saveInDB().

598  {
599  global $ilDB;
600 
601  if ($this->getValidateAll()) {
602  $query = "DELETE FROM link_check";
603  } else {
604  $query = "DELETE FROM link_check " .
605  "WHERE obj_id = " . $ilDB->quote($this->getObjId(), 'integer');
606  }
607  $res = $ilDB->manipulate($query);
608 
609  return true;
610  }
foreach($_POST as $key=> $value) $res
$query
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __clearInvalidLinks()

ilLinkChecker::__clearInvalidLinks ( )

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

References array.

Referenced by checkLinks(), and checkWebResourceLinks().

342  {
343  $this->invalid_links = array();
344  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ __clearLogMessages()

ilLinkChecker::__clearLogMessages ( )

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

References array.

Referenced by checkLinks(), and checkWebResourceLinks().

356  {
357  return $this->log_messages = array();
358  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ __fetchUserData()

ilLinkChecker::__fetchUserData (   $a_usr_id)

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

References $data, $ilDB, $r, $row, and ilDBConstants\FETCHMODE_OBJECT.

211  {
212  global $ilDB;
213 
214  $r = $this->db->query("SELECT email FROM usr_data WHERE usr_id = " . $ilDB->quote($a_usr_id));
215 
217 
218  $data['email'] = $row->email;
219 
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"));
223 
224  $row = $ilDB->fetchObject($set);
225 
226  $data['lang'] = $row->value;
227 
228  return $data;
229  }
$r
Definition: example_031.php:79
global $ilDB

◆ __getLinks()

ilLinkChecker::__getLinks (   $a_page)

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

References $i, __getObjIdByPageId(), and array.

Referenced by checkLinks().

361  {
362  $matches = array();
363 
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]);
368  // continue if mailto link
369  if ($url_data['scheme'] == 'mailto') {
370  continue;
371  }
372 
373  // PUH, HTTP_REQUEST needs a beginning http://
374  if (!$url_data['scheme']) {
375  $matches[1][$i] = 'http://' . $matches[1][$i];
376  }
377 
378  $lm_id = $this->__getObjIdByPageId($a_page['page_id']);
379  $link[] = array('page_id' => $a_page['page_id'],
380  'obj_id' => $lm_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']);
385  }
386  }
387 
388  return $link ? $link : array();
389  }
Create styles array
The data for the language used.
__getObjIdByPageId($a_page_id)
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __getNotifyLinks()

ilLinkChecker::__getNotifyLinks ( )

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

References array.

Referenced by __sendMail().

336  {
337  return $this->notify ? $this->notify : array();
338  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ __getObjIdByPageId()

ilLinkChecker::__getObjIdByPageId (   $a_page_id)

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

References $res, $row, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by __getLinks().

532  {
533  $res = $this->db->query("SELECT lm_id FROM lm_data " .
534  "WHERE obj_id = '" . $a_page_id . "'");
535 
537 
538  return $row->lm_id ? $row->lm_id : 0;
539  }
foreach($_POST as $key=> $value) $res
+ Here is the caller graph for this function:

◆ __getTitle()

ilLinkChecker::__getTitle (   $a_lm_obj_id)

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

References $ilDB, $r, $row, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by __sendMail().

232  {
233  global $ilDB;
234 
235  $r = $this->db->query("SELECT title FROM object_data " .
236  "WHERE obj_id = " . $ilDB->quote($a_lm_obj_id, 'integer') . " ");
237 
239 
240  return $row->title;
241  }
$r
Definition: example_031.php:79
global $ilDB
+ Here is the caller graph for this function:

◆ __getType()

ilLinkChecker::__getType ( )

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

References $type.

Referenced by __sendMail().

62  {
63  return $this->type;
64  }
$type
+ Here is the caller graph for this function:

◆ __getWebResourceLinks()

ilLinkChecker::__getWebResourceLinks ( )

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

References array, and getObjId().

Referenced by checkWebResourceLinks().

392  {
393  global $objDefinition;
394 
395 
396 
397  $link_res_obj = new ilLinkResourceItems($this->getObjId());
398 
399  foreach ($check_links = $link_res_obj->getCheckItems($this->getCheckPeriod()) as $item_data) {
400  // #10091 - internal
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'],
407  'obj_id' => $this->getObjId(),
408  'type' => 'webr',
409  'complete' => $item_data['target'],
410  'scheme' => 'internal',
411  'obj_type' => $parts[0],
412  'ref_id' => $parts[1]);
413  continue;
414  }
415  }
416 
417  // external
418  $url_data = @parse_url($item_data['target']);
419 
420  // PUH, HTTP_REQUEST needs a beginning http://
421  if (!$url_data['scheme']) {
422  $item_data['target'] = 'http://' . $item_data['target'];
423  }
424 
425  $link[] = array('page_id' => $item_data['link_id'],
426  'obj_id' => $this->getObjId(),
427  'type' => 'webr',
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']);
431  }
432  return $link ? $link : array();
433  }
Create styles array
The data for the language used.
Class ilObjLinkResourceGUI.
+ 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 541 of file class.ilLinkChecker.php.

References getInvalidLinks().

542  {
543  foreach ($this->getInvalidLinks() as $link) {
544  if ($link['page_id'] == $a_page_id and
545  substr($link['complete'], 0, 255) == $a_url) {
546  return true;
547  }
548  }
549  return false;
550  }
+ Here is the call graph for this function:

◆ __saveInDB()

ilLinkChecker::__saveInDB ( )

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

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

Referenced by checkLinks(), and checkWebResourceLinks().

553  {
554  global $ilDB;
555 
556  if ($this->getMailStatus()) {
557  $this->__checkNotify();
558  }
559  $this->__clearDBData();
560 
561 
562  foreach ($this->getInvalidLinks() as $link) {
563  $id = $ilDB->nextId('link_check');
564 
565  $query = "INSERT INTO link_check (id, obj_id,page_id,url,parent_type,http_status_code,last_check) " .
566  "VALUES ( " .
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') . " " .
574  ")";
575  $res = $ilDB->manipulate($query);
576  }
577  }
if(!array_key_exists('StateId', $_REQUEST)) $id
foreach($_POST as $key=> $value) $res
$query
global $ilDB
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __sendMail()

ilLinkChecker::__sendMail ( )

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

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

Referenced by checkLinks(), and checkWebResourceLinks().

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

◆ __setType()

ilLinkChecker::__setType (   $a_type)

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

References $a_type.

Referenced by checkLinks(), and checkWebResourceLinks().

58  {
59  $this->type = $a_type;
60  }
$a_type
Definition: workflow.php:92
+ Here is the caller graph for this function:

◆ __txt()

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

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

References $ilDB, $key, $module, and ilLanguage\_lookupEntry().

Referenced by __sendMail().

204  {
205  global $ilDB;
206 
207  return ilLanguage::_lookupEntry($language, $module, $key);
208  }
static _lookupEntry($a_lang_key, $a_mod, $a_id)
if($modEnd===false) $module
Definition: module.php:59
global $ilDB
$key
Definition: croninfo.php:18
+ 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 452 of file class.ilLinkChecker.php.

References __appendLogMessage(), ilProxySettings\_getInstance(), ilCurlConnection\_isCurlExtensionLoaded(), ilObject\_lookupObjId(), ilObject\_lookupType(), array, and ilLoggerFactory\getLogger().

Referenced by checkLinks(), and checkWebResourceLinks().

453  {
454  global $tree;
456  $this->__appendLogMessage('LinkChecker: Pear HTTP_Request is not installed. Aborting');
457  ilLoggerFactory::getLogger('lchk')->error('LinkChecker: Curl extension is not loeaded. Aborting');
458  return array();
459  }
460  $invalid = array();
461 
462  foreach ($a_links as $link) {
463  // #10091 - internal
464  if ($link['scheme'] == 'internal') {
465  $obj_id = ilObject::_lookupObjId($link['ref_id']);
466  if (!$obj_id ||
467  ilObject::_lookupType($obj_id) != $link['obj_type'] ||
468  $tree->isDeleted($link['ref_id'])) {
469  $invalid[] = $link;
470  }
471  }
472  // external
473  else {
474  //ilLoggerFactory::getLogger('lchk')->debug('Check: '.$link['complete']);
475 
476  if ($link['scheme'] !== 'http' and $link['scheme'] !== 'https') {
477  ilLoggerFactory::getLogger('lchk')->error('LinkChecker: Unkown link sheme "' . $link['scheme'] . '". Continue check');
478  continue;
479  }
480 
481  $curl = null;
482  $http_code = 0;
483  $c_error_no = 0;
484  try {
485  $curl = new ilCurlConnection($link['complete']);
486  $curl->init();
487 
488  if (ilProxySettings::_getInstance()->isActive()) {
489  $curl->setOpt(CURLOPT_HTTPPROXYTUNNEL, true);
490  $curl->setOpt(CURLOPT_PROXY, ilProxySettings::_getInstance()->getHost());
491  $curl->setOpt(CURLOPT_PROXYPORT, ilProxySettings::_getInstance()->getPort());
492  }
493 
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);
499  $curl->exec();
500  $headers = $curl->getInfo();
501  $http_code = $headers['http_code'];
502  } catch (ilCurlConnectionException $e) {
503  $c_error_no = $e->getCode();
504  ilLoggerFactory::getLogger('lchk')->error('LinkChecker: No valid http code received. Curl error (' . $e->getCode() . '): ' . $e->getMessage());
505  } finally {
506  if ($curl != null) {
507  $curl->close();
508  }
509  }
510 
511  switch ($http_code) {
512  // EVERYTHING OK
513  case '200':
514  // In the moment 301 will be handled as ok
515  case '301':
516  case '302':
517  break;
518  default:
519  $link['http_status_code'] = $http_code;
520  if ($http_code == 0 && $c_error_no != 0) {
521  $link['curl_errno'] = $c_error_no;
522  }
523  $invalid[] = $link;
524  break;
525  }
526  }
527  }
528  return $invalid;
529  }
__appendLogMessage($a_string)
static _isCurlExtensionLoaded()
Check if curl extension is loaded.
static _lookupObjId($a_id)
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
static getLogger($a_component_id)
Get component logger.
static _getInstance()
Getter for unique instance.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkLinks()

ilLinkChecker::checkLinks ( )

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

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

147  {
148  global $ilDB;
149 
150  $pages = array();
151 
152  $this->__setType('lm');
153  $this->__clearLogMessages();
154  $this->__clearInvalidLinks();
155  $this->__appendLogMessage('LinkChecker: Start checkLinks()');
156 
157  if (!$this->getValidateAll() and !$this->getObjId()) {
158  echo "ilLinkChecker::checkLinks() No Page id given";
159 
160  return false;
161  } elseif (!$this->getValidateAll() and $this->getObjId()) {
162  $query = "SELECT * FROM page_object " .
163  "WHERE parent_id = " . $ilDB->quote($this->getObjId()) . " " .
164  "AND parent_type = 'lm'";
165 
166  $res = $this->db->query($query);
167  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
168  $pages[] = array('page_id' => $row->page_id,
169  'content' => $row->content,
170  'type' => $row->parent_type);
171  }
172  } elseif ($this->getValidateAll()) {
173  $query = "SELECT * FROM page_object " .
174  "WHERE parent_type = 'lm'";
175 
176  $res = $this->db->query($query);
177  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
178  $pages[] = array('page_id' => $row->page_id,
179  'content' => $row->content,
180  'type' => $row->parent_type);
181  }
182  }
183 
184  // VALIDATE
185  foreach ($pages as $page) {
186  if (count($invalid = $this->__validateLinks($this->__getLinks($page)))) {
187  foreach ($invalid as $invalid_item) {
188  $this->__appendLogMessage('LinkChecker: found invalid link: ' . $invalid_item['complete']);
189  $this->__appendInvalidLink($invalid_item);
190  }
191  }
192  }
193 
194  $this->__appendLogMessage('LinkChecker: End checkLinks()');
195  $this->__saveInDB();
196 
197  $this->__sendMail();
198 
199  return $this->getInvalidLinks();
200  }
__appendLogMessage($a_string)
foreach($_POST as $key=> $value) $res
$query
Create styles array
The data for the language used.
global $ilDB
__appendInvalidLink($a_link)
__validateLinks($a_links)
$a_links Format: Array ( [1] => Array ( [&#39;scheme&#39;] => intern/http/https, [&#39;ref_id&#39;] => ILIAS ref ID...
+ Here is the call graph for this function:

◆ checkWebResourceLinks()

ilLinkChecker::checkWebResourceLinks ( )

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

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

123  {
124  $pages = array();
125 
126  $this->__setType('webr');
127  $this->__clearLogMessages();
128  $this->__clearInvalidLinks();
129  $this->__appendLogMessage('LinkChecker: Start checkLinks()');
130 
131  if (count($invalid = $this->__validateLinks($this->__getWebResourceLinks()))) {
132  foreach ($invalid as $invalid_item) {
133  $this->__appendLogMessage('LinkChecker: found invalid link: ' . $invalid_item['complete']);
134  $this->__appendInvalidLink($invalid_item);
135  }
136  }
137 
138  $this->__appendLogMessage('LinkChecker: End checkLinks()');
139  $this->__saveInDB();
140 
141  $this->__sendMail();
142 
143  return $this->getInvalidLinks();
144  }
__appendLogMessage($a_string)
Create styles array
The data for the language used.
__appendInvalidLink($a_link)
__validateLinks($a_links)
$a_links Format: Array ( [1] => Array ( [&#39;scheme&#39;] => intern/http/https, [&#39;ref_id&#39;] => ILIAS ref ID...
+ 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 315 of file class.ilLinkChecker.php.

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

Referenced by __sendMail().

316  {
317  global $ilAccess;
318  $ref_ids = ilObject::_getAllReferences($a_obj_id);
319  $ref_id = null;
320 
321  foreach ((array) $ref_ids as $id) {
322  if ($ilAccess->checkAccessOfUser($a_usr_id, "read", "", $id, $a_obj_type, $a_obj_id)) {
323  $ref_id = $id;
324  }
325  }
326 
327  if ($ref_id === null) {
328  return false;
329  }
330 
331 
332  return ilLink::_getLink($ref_id, $a_obj_type);
333  }
if(!array_key_exists('StateId', $_REQUEST)) $id
static _getAllReferences($a_id)
get all reference ids of object
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCheckPeriod()

ilLinkChecker::getCheckPeriod ( )

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

44  {
45  return $this->period;
46  }

◆ getInvalidLinks()

ilLinkChecker::getInvalidLinks ( )

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

References array.

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

86  {
87  return $this->invalid_links ? $this->invalid_links : array();
88  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ getInvalidLinksFromDB()

ilLinkChecker::getInvalidLinksFromDB ( )

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

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

91  {
92  global $ilDB;
93 
94  $query = "SELECT * FROM link_check " .
95  "WHERE obj_id = " . $ilDB->quote($this->getObjId(), 'integer') . " ";
96 
97  $res = $this->db->query($query);
98  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
99  $invalid[] = array('page_id' => $row->page_id,
100  'url' => $row->url);
101  }
102 
103  return $invalid ? $invalid : array();
104  }
foreach($_POST as $key=> $value) $res
$query
Create styles array
The data for the language used.
global $ilDB
+ Here is the call graph for this function:

◆ getLastCheckTimestamp()

ilLinkChecker::getLastCheckTimestamp ( )

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

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

107  {
108  global $ilDB;
109 
110  if ($this->getValidateAll()) {
111  $query = "SELECT MAX(last_check) last_check FROM link_check ";
112  } else {
113  $query = "SELECT MAX(last_check) last_check FROM link_check " .
114  "WHERE obj_id = " . $ilDB->quote($this->getObjId(), 'integer') . " ";
115  }
116  $res = $ilDB->query($query);
117  $row = $ilDB->fetchObject($res);
118 
119  return $row->last_check ? $row->last_check : 0;
120  }
foreach($_POST as $key=> $value) $res
$query
global $ilDB
+ Here is the call graph for this function:

◆ getLogMessages()

ilLinkChecker::getLogMessages ( )

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

References array.

81  {
82  return $this->log_messages ? $this->log_messages : array();
83  }
Create styles array
The data for the language used.

◆ getMailStatus()

ilLinkChecker::getMailStatus ( )

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

References $mail_status.

Referenced by __saveInDB(), and __sendMail().

53  {
54  return (bool) $this->mail_status;
55  }
+ Here is the caller graph for this function:

◆ getObjId()

ilLinkChecker::getObjId ( )

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

References $page_id.

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

71  {
72  return $this->page_id;
73  }
+ Here is the caller graph for this function:

◆ getValidateAll()

ilLinkChecker::getValidateAll ( )

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

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

76  {
77  return $this->validate_all ? true : false;
78  }
+ Here is the caller graph for this function:

◆ setCheckPeriod()

ilLinkChecker::setCheckPeriod (   $a_period)

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

40  {
41  $this->period = $a_period;
42  }

◆ setMailStatus()

ilLinkChecker::setMailStatus (   $a_status)

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

49  {
50  $this->mail_status = (bool) $a_status;
51  }

◆ setObjId()

ilLinkChecker::setObjId (   $a_page_id)

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

67  {
68  return $this->page_id = $a_page_id;
69  }

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: