Public Member Functions | |
| ilLinkChecker (&$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 () | |
| checkPear () | |
| __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) | |
| __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 | |
Definition at line 33 of file class.ilLinkChecker.php.
| ilLinkChecker::__appendInvalidLink | ( | $ | a_link | ) |
Definition at line 381 of file class.ilLinkChecker.php.
Referenced by checkLinks(), and checkWebResourceLinks().
{
$this->invalid_links[] = $a_link;
}
Here is the caller graph for this function:| ilLinkChecker::__appendLogMessage | ( | $ | a_string | ) |
Definition at line 387 of file class.ilLinkChecker.php.
Referenced by __sendMail(), __validateLinks(), checkLinks(), and checkWebResourceLinks().
{
$this->log_messages[] = $a_string;
}
Here is the caller graph for this function:| ilLinkChecker::__checkNotify | ( | ) |
Definition at line 554 of file class.ilLinkChecker.php.
References $query, $res, and getInvalidLinks().
Referenced by __saveInDB().
{
foreach($this->getInvalidLinks() as $link)
{
$query = "SELECT * FROM link_check ".
"WHERE page_id = '".$link['page_id']."' ".
"AND url = '".addslashes(substr($link['complete'],0,255))."'";
$res = $this->db->query($query);
if(!$res->numRows())
{
$this->notify["$link[obj_id]"][] = array('page_id' => $link['page_id'],
'url' => $link['complete']);
}
}
}
Here is the call graph for this function:
Here is the caller graph for this function:| ilLinkChecker::__clearDBData | ( | ) |
Definition at line 572 of file class.ilLinkChecker.php.
References $query, and getValidateAll().
Referenced by __saveInDB().
{
if($this->getValidateAll())
{
$query = "DELETE FROM link_check";
}
else
{
$query = "DELETE FROM link_check ".
"WHERE obj_id = '".$this->getObjId()."'";
}
$this->db->query($query);
return true;
}
Here is the call graph for this function:
Here is the caller graph for this function:| ilLinkChecker::__clearInvalidLinks | ( | ) |
Definition at line 377 of file class.ilLinkChecker.php.
Referenced by checkLinks(), and checkWebResourceLinks().
{
$this->invalid_links = array();
}
Here is the caller graph for this function:| ilLinkChecker::__clearLogMessages | ( | ) |
Definition at line 391 of file class.ilLinkChecker.php.
Referenced by checkLinks(), and checkWebResourceLinks().
{
return $this->log_messages = array();
}
Here is the caller graph for this function:| ilLinkChecker::__fetchUserData | ( | $ | a_usr_id | ) |
Definition at line 270 of file class.ilLinkChecker.php.
References $data, $query, and $row.
{
$query = "SELECT email FROM usr_data WHERE usr_id = '".$a_usr_id."'";
$row = $this->db->getRow($query,DB_FETCHMODE_OBJECT);
$data['email'] = $row->email;
$query = "SELECT * FROM usr_pref ".
"WHERE usr_id = '".$a_usr_id."' ".
"AND keyword = 'language'";
$row = $this->db->getRow($query,DB_FETCHMODE_OBJECT);
$data['lang'] = $row->value;
return $data;
}
| ilLinkChecker::__getLinks | ( | $ | a_page | ) |
Definition at line 396 of file class.ilLinkChecker.php.
References $lm_id, and __getObjIdByPageId().
Referenced by checkLinks().
{
$matches = array();
$pattern_complete = '/<ExtLink Href="([^"]*)">/';
if(preg_match_all($pattern_complete,$a_page['content'],$matches))
{
for($i = 0;$i < count($matches[0]); ++$i)
{
$url_data = parse_url($matches[1][$i]);
// continue if mailto link
if($url_data['scheme'] == 'mailto')
{
continue;
}
// PUH, HTTP_REQUEST needs a beginning http://
if(!$url_data['scheme'])
{
$matches[1][$i] = 'http://'.$matches[1][$i];
}
$lm_id = $this->__getObjIdByPageId($a_page['page_id']);
$link[] = array('page_id' => $a_page['page_id'],
'obj_id' => $lm_id,
'type' => $a_page['type'],
'complete' => $matches[1][$i],
'scheme' => isset($url_data['scheme']) ? $url_data['scheme'] : 'http',
'host' => isset($url_data['host']) ? $url_data['host'] : $url_data['path']);
}
}
return $link ? $link : array();
}
Here is the call graph for this function:
Here is the caller graph for this function:| ilLinkChecker::__getNotifyLinks | ( | ) |
Definition at line 371 of file class.ilLinkChecker.php.
Referenced by __sendMail().
{
return $this->notify ? $this->notify : array();
}
Here is the caller graph for this function:| ilLinkChecker::__getObjIdByPageId | ( | $ | a_page_id | ) |
Definition at line 503 of file class.ilLinkChecker.php.
Referenced by __getLinks().
{
$query = "SELECT lm_id FROM lm_data ".
"WHERE obj_id = '".$a_page_id."'";
$row = $this->db->getRow($query,DB_FETCHMODE_OBJECT);
return $row->lm_id ? $row->lm_id : 0;
}
Here is the caller graph for this function:| ilLinkChecker::__getTitle | ( | $ | a_lm_obj_id | ) |
Definition at line 289 of file class.ilLinkChecker.php.
Referenced by __sendMail().
{
$query = "SELECT title FROM object_data ".
"WHERE obj_id = '".$a_lm_obj_id."'";
$row = $this->db->getRow($query,DB_FETCHMODE_OBJECT);
return $row->title;
}
Here is the caller graph for this function:| ilLinkChecker::__getType | ( | ) |
Definition at line 81 of file class.ilLinkChecker.php.
Referenced by __sendMail().
{
return $this->type;
}
Here is the caller graph for this function:| ilLinkChecker::__getWebResourceLinks | ( | ) |
Definition at line 432 of file class.ilLinkChecker.php.
References getObjId().
Referenced by checkWebResourceLinks().
{
include_once 'link/classes/class.ilLinkResourceItems.php';
$link_res_obj = new ilLinkResourceItems($this->getObjId());
foreach($check_links = $link_res_obj->getCheckItems($this->getCheckPeriod()) as $item_data)
{
$url_data = parse_url($item_data['target']);
// PUH, HTTP_REQUEST needs a beginning http://
if(!$url_data['scheme'])
{
$item_data['target'] = 'http://'.$item_data['target'];
}
$link[] = array('page_id' => $item_data['link_id'],
'obj_id' => $this->getObjId(),
'type' => 'webr',
'complete' => $item_data['target'],
'scheme' => isset($url_data['scheme']) ? $url_data['scheme'] : 'http',
'host' => isset($url_data['host']) ? $url_data['host'] : $url_data['path']);
}
return $link ? $link : array();
}
Here is the call graph for this function:
Here is the caller graph for this function:| ilLinkChecker::__isInvalid | ( | $ | a_page_id, | |
| $ | a_url | |||
| ) |
Definition at line 513 of file class.ilLinkChecker.php.
References getInvalidLinks().
{
foreach($this->getInvalidLinks() as $link)
{
if($link['page_id'] == $a_page_id and
substr($link['complete'],0,255) == $a_url)
{
return true;
}
}
return false;
}
Here is the call graph for this function:| ilLinkChecker::__saveInDB | ( | ) |
Definition at line 526 of file class.ilLinkChecker.php.
References $query, $res, __checkNotify(), __clearDBData(), getInvalidLinks(), and getMailStatus().
Referenced by checkLinks(), and checkWebResourceLinks().
{
if($this->getMailStatus())
{
$this->__checkNotify();
}
$this->__clearDBData();
foreach($this->getInvalidLinks() as $link)
{
$query = "INSERT INTO link_check ".
"SET page_id = '".$link['page_id']."', ".
"obj_id = '".$link['obj_id']."', ".
"url = '".addslashes(substr($link['complete'],0,255))."', ".
"parent_type = '".addslashes($link['type'])."', ".
"http_status_code = '".addslashes($link['http_status_code'])."', ".
"last_check = '".time()."'";
$res = $this->db->query($query);
}
// delete old values
}
Here is the call graph for this function:
Here is the caller graph for this function:| ilLinkChecker::__sendMail | ( | ) |
Definition at line 299 of file class.ilLinkChecker.php.
References $counter, $data, $ilUser, $obj_id, $tmp_user, $umail, __appendLogMessage(), __getNotifyLinks(), __getTitle(), __getType(), __txt(), ilLinkCheckNotify::_getAllNotifiers(), ilObjectFactory::getInstanceByObjId(), and getMailStatus().
Referenced by checkLinks(), and checkWebResourceLinks().
{
global $ilUser;
if(!count($notify = $this->__getNotifyLinks()))
{
// Nothing to do
return true;
}
if(!$this->getMailStatus())
{
return true;
}
include_once './classes/class.ilLinkCheckNotify.php';
foreach(ilLinkCheckNotify::_getAllNotifiers($this->db) as $usr_id => $obj_ids)
{
if(!is_object($tmp_user =& ilObjectFactory::getInstanceByObjId($usr_id,false)))
{
$this->__appendLogMessage('LinkChecker: Cannot find user with id: '.$usr_id);
continue;
}
$counter = 0;
foreach($obj_ids as $obj_id)
{
if(!isset($notify[$obj_id]))
{
continue;
}
++$counter;
switch($this->__getType())
{
case 'webr':
$body .= $this->__txt($tmp_user->getLanguage(),'obj_webr');
break;
case 'lm':
default:
$body .= $this->__txt($tmp_user->getLanguage(),'lo');
break;
}
$body .= ': ';
$body .= $this->__getTitle($obj_id)."\r\n";
// Print all invalid
foreach($notify[$obj_id] as $data)
{
$body .= $data['url']."\r\n";
}
$body .= "\r\n";
}
if($counter)
{
include_once "classes/class.ilFormatMail.php";
$umail = new ilFormatMail($tmp_user->getId());
$subject = $this->__txt($tmp_user->getLanguage(),'link_check_subject');
$umail->sendMail($tmp_user->getLogin(),"","",$subject,$body,array(),array("normal"));
$this->__appendLogMessage('LinkChecker: Sent mail to '.$tmp_user->getEmail());
}
}
}
Here is the call graph for this function:
Here is the caller graph for this function:| ilLinkChecker::__setType | ( | $ | a_type | ) |
Definition at line 77 of file class.ilLinkChecker.php.
Referenced by checkLinks(), and checkWebResourceLinks().
{
$this->type = $a_type;
}
Here is the caller graph for this function:| ilLinkChecker::__txt | ( | $ | language, | |
| $ | key, | |||
| $ | module = 'common' | |||
| ) |
Definition at line 242 of file class.ilLinkChecker.php.
References $query, $res, and $row.
Referenced by __sendMail().
{
$query = "SELECT value FROM lng_data ".
"WHERE module = '".$module."' ".
"AND identifier = '".$key."' ".
"AND lang_key = '".$language."'";
$res = $this->db->query($query);
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
$value = $row->value;
}
if(!$value)
{
$query = "SELECT value FROM lng_data ".
"WHERE module = '".$module."' ".
"AND identifier = '".$key."' ".
"AND lang_key = 'en'";
$res = $this->db->query($query);
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
$value = $row->value;
}
}
return $value ? $value : '-'.$key.'-';
}
Here is the caller graph for this function:| ilLinkChecker::__validateLinks | ( | $ | a_links | ) |
Definition at line 460 of file class.ilLinkChecker.php.
References __appendLogMessage().
Referenced by checkLinks(), and checkWebResourceLinks().
{
if(!@include_once('HTTP/Request.php'))
{
$this->__appendLogMessage('LinkChecker: Pear HTTP_Request is not installed. Aborting');
return array();
}
foreach($a_links as $link)
{
if(gethostbyname($link['host']) == $link['host'])
{
$invalid[] = $link;
continue;
}
if($link['scheme'] !== 'http' and $link['scheme'] !== 'https')
{
continue;
}
$req =& new HTTP_Request($link['complete']);
$req->sendRequest();
switch($req->getResponseCode())
{
// EVERYTHING OK
case '200':
// In the moment 301 will be handled as ok
case '301':
case '302':
break;
default:
$link['http_status_code'] = $req->getResponseCode();
$invalid[] = $link;
break;
}
}
return $invalid ? $invalid : array();
}
Here is the call graph for this function:
Here is the caller graph for this function:| ilLinkChecker::checkLinks | ( | ) |
Definition at line 167 of file class.ilLinkChecker.php.
References $query, $res, $row, __appendInvalidLink(), __appendLogMessage(), __clearInvalidLinks(), __clearLogMessages(), __getLinks(), __saveInDB(), __sendMail(), __setType(), __validateLinks(), getInvalidLinks(), getObjId(), and getValidateAll().
{
$pages = array();
$this->__setType('lm');
$this->__clearLogMessages();
$this->__clearInvalidLinks();
$this->__appendLogMessage('LinkChecker: Start checkLinks()');
if(!$this->getValidateAll() and !$this->getObjId())
{
echo "ilLinkChecker::checkLinks() No Page id given";
return false;
}
elseif(!$this->getValidateAll() and $this->getObjId())
{
$query = "SELECT * FROM page_object ".
"WHERE parent_id = '".$this->getObjId()."' ".
"AND parent_type = 'lm'";
$res = $this->db->query($query);
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
$pages[] = array('page_id' => $row->page_id,
'content' => $row->content,
'type' => $row->parent_type);
}
}
elseif($this->getValidateAll())
{
$query = "SELECT * FROM page_object ".
"WHERE parent_type = 'lm'";
$res = $this->db->query($query);
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
$pages[] = array('page_id' => $row->page_id,
'content' => $row->content,
'type' => $row->parent_type);
}
}
// VALIDATE
foreach($pages as $page)
{
if(count($invalid = $this->__validateLinks($this->__getLinks($page))))
{
foreach($invalid as $invalid_item)
{
$this->__appendLogMessage('LinkChecker: found invalid link: '.$invalid_item['complete']);
$this->__appendInvalidLink($invalid_item);
}
}
}
$this->__appendLogMessage('LinkChecker: End checkLinks()');
$this->__saveInDB();
$this->__sendMail();
return $this->getInvalidLinks();
}
Here is the call graph for this function:| ilLinkChecker::checkPear | ( | ) |
Definition at line 231 of file class.ilLinkChecker.php.
{
if(!@include_once('HTTP/Request.php'))
{
return false;
}
return true;
}
| ilLinkChecker::checkWebResourceLinks | ( | ) |
Definition at line 141 of file class.ilLinkChecker.php.
References __appendInvalidLink(), __appendLogMessage(), __clearInvalidLinks(), __clearLogMessages(), __getWebResourceLinks(), __saveInDB(), __sendMail(), __setType(), __validateLinks(), and getInvalidLinks().
{
$pages = array();
$this->__setType('webr');
$this->__clearLogMessages();
$this->__clearInvalidLinks();
$this->__appendLogMessage('LinkChecker: Start checkLinks()');
if(count($invalid = $this->__validateLinks($this->__getWebResourceLinks())))
{
foreach($invalid as $invalid_item)
{
$this->__appendLogMessage('LinkChecker: found invalid link: '.$invalid_item['complete']);
$this->__appendInvalidLink($invalid_item);
}
}
$this->__appendLogMessage('LinkChecker: End checkLinks()');
$this->__saveInDB();
$this->__sendMail();
return $this->getInvalidLinks();
}
Here is the call graph for this function:| ilLinkChecker::getCheckPeriod | ( | ) |
Definition at line 63 of file class.ilLinkChecker.php.
{
return $this->period;
}
| ilLinkChecker::getInvalidLinks | ( | ) |
Definition at line 105 of file class.ilLinkChecker.php.
Referenced by __checkNotify(), __isInvalid(), __saveInDB(), checkLinks(), and checkWebResourceLinks().
{
return $this->invalid_links ? $this->invalid_links : array();
}
Here is the caller graph for this function:| ilLinkChecker::getInvalidLinksFromDB | ( | ) |
Definition at line 110 of file class.ilLinkChecker.php.
| ilLinkChecker::getLastCheckTimestamp | ( | ) |
Definition at line 125 of file class.ilLinkChecker.php.
References $query, $row, and getValidateAll().
{
if($this->getValidateAll())
{
$query = "SELECT MAX(last_check) as last_check FROM link_check ";
}
else
{
$query = "SELECT MAX(last_check) as last_check FROM link_check ".
"WHERE obj_id = '".$this->getObjId()."'";
}
$row = $this->db->getRow($query,DB_FETCHMODE_OBJECT);
return $row->last_check ? $row->last_check : 0;
}
Here is the call graph for this function:| ilLinkChecker::getLogMessages | ( | ) |
Definition at line 100 of file class.ilLinkChecker.php.
{
return $this->log_messages ? $this->log_messages : array();
}
| ilLinkChecker::getMailStatus | ( | ) |
Definition at line 72 of file class.ilLinkChecker.php.
Referenced by __saveInDB(), and __sendMail().
{
return (bool) $this->mail_status;
}
Here is the caller graph for this function:| ilLinkChecker::getObjId | ( | ) |
Definition at line 90 of file class.ilLinkChecker.php.
Referenced by __getWebResourceLinks(), and checkLinks().
{
return $this->page_id;
}
Here is the caller graph for this function:| ilLinkChecker::getValidateAll | ( | ) |
Definition at line 95 of file class.ilLinkChecker.php.
Referenced by __clearDBData(), checkLinks(), and getLastCheckTimestamp().
{
return $this->validate_all ? true : false;
}
Here is the caller graph for this function:| ilLinkChecker::ilLinkChecker | ( | &$ | db, | |
| $ | a_validate_all = true | |||
| ) |
Definition at line 44 of file class.ilLinkChecker.php.
References $db.
| ilLinkChecker::setCheckPeriod | ( | $ | a_period | ) |
Definition at line 59 of file class.ilLinkChecker.php.
{
$this->period = $a_period;
}
| ilLinkChecker::setMailStatus | ( | $ | a_status | ) |
Definition at line 68 of file class.ilLinkChecker.php.
{
$this->mail_status = (bool) $a_status;
}
| ilLinkChecker::setObjId | ( | $ | a_page_id | ) |
Definition at line 86 of file class.ilLinkChecker.php.
{
return $this->page_id = $a_page_id;
}
| ilLinkChecker::$db = null |
Definition at line 35 of file class.ilLinkChecker.php.
Referenced by ilLinkChecker().
| ilLinkChecker::$invalid_links = array() |
Definition at line 37 of file class.ilLinkChecker.php.
| ilLinkChecker::$log_messages = array() |
Definition at line 36 of file class.ilLinkChecker.php.
| ilLinkChecker::$mail_status = false |
Definition at line 40 of file class.ilLinkChecker.php.
| ilLinkChecker::$page_id = 0 |
Definition at line 41 of file class.ilLinkChecker.php.
| ilLinkChecker::$validate_all = true |
Definition at line 39 of file class.ilLinkChecker.php.
1.7.1