30        define(
'SOCKET_TIMEOUT', 5);
 
   31        define(
'MAX_REDIRECTS', 5);
 
   38        $this->validate_all = $a_validate_all;
 
   43        $this->period = $a_period;
 
   52        $this->mail_status = (bool) $a_status;
 
   61        $this->type = $a_type;
 
   70        return $this->page_id = $a_page_id;
 
   79        return $this->validate_all ? 
true : 
false;
 
   84        return $this->log_messages ? $this->log_messages : array();
 
   89        return $this->invalid_links ? $this->invalid_links : array();
 
   98        $query = 
"SELECT * FROM link_check " .
 
   99            "WHERE obj_id = " . 
$ilDB->quote($this->
getObjId(), 
'integer') . 
" ";
 
  103            $invalid[] = array(
'page_id' => $row->page_id,
 
  107        return $invalid ? $invalid : array();
 
  117            $query = 
"SELECT MAX(last_check) last_check FROM link_check ";
 
  119            $query = 
"SELECT MAX(last_check) last_check FROM link_check " .
 
  120                "WHERE obj_id = " . 
$ilDB->quote($this->
getObjId(), 
'integer') . 
" ";
 
  125        return $row->last_check ? $row->last_check : 0;
 
  138            foreach ($invalid as $invalid_item) {
 
  139                $this->
__appendLogMessage(
'LinkChecker: found invalid link: ' . $invalid_item[
'complete']);
 
  166            echo 
"ilLinkChecker::checkLinks() No Page id given";
 
  170            $query = 
"SELECT * FROM page_object " .
 
  171                "WHERE parent_id = " . 
$ilDB->quote($this->
getObjId()) . 
" " .
 
  172                "AND parent_type = 'lm'";
 
  176                $pages[] = array(
'page_id' => $row->page_id,
 
  177                                 'content' => $row->content,
 
  178                                 'type' => $row->parent_type);
 
  181            $query = 
"SELECT * FROM page_object " .
 
  182                "WHERE parent_type = 'lm'";
 
  186                $pages[] = array(
'page_id' => $row->page_id,
 
  187                                 'content' => $row->content,
 
  188                                 'type' => $row->parent_type);
 
  193        foreach ($pages as $page) {
 
  195                foreach ($invalid as $invalid_item) {
 
  196                    $this->
__appendLogMessage(
'LinkChecker: found invalid link: ' . $invalid_item[
'complete']);
 
  211    public function __txt($language, $key, $module = 
'common')
 
  222        $r = $this->db->query(
"SELECT email FROM usr_data WHERE usr_id = " . 
$ilDB->quote($a_usr_id));
 
  226        $data[
'email'] = $row->email;
 
  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"));
 
  232        $row = 
$ilDB->fetchObject($set);
 
  234        $data[
'lang'] = $row->value;
 
  245        $r = $this->db->query(
"SELECT title FROM object_data " .
 
  246            "WHERE obj_id = " . 
$ilDB->quote($a_lm_obj_id, 
'integer') . 
" ");
 
  279            foreach ($obj_ids as $obj_id) {
 
  280                if (!isset($notify[$obj_id])) {
 
  287                        $obj_name = $this->
__txt($tmp_user->getLanguage(), 
'obj_webr');
 
  291                        $obj_name = $this->
__txt($tmp_user->getLanguage(), 
'lo');
 
  294                $body .= $obj_name . 
': ' . $this->
__getTitle($obj_id) . 
"\r\n";
 
  295                $body .= $this->
__txt($tmp_user->getLanguage(), 
'link_check_perma_link', 
"mail") . 
": " .
 
  297                $body .= $this->
__txt($tmp_user->getLanguage(), 
"link_check_affected_links", 
"mail") . 
":\r\n";
 
  300                foreach ($notify[$obj_id] as 
$data) {
 
  301                    $body .= 
$data[
'url'] . 
"\r\n";
 
  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()));
 
  331        $ilAccess = 
$DIC[
'ilAccess'];
 
  335        foreach ((array) $ref_ids as $id) {
 
  336            if ($ilAccess->checkAccessOfUser($a_usr_id, 
"read", 
"", $id, $a_obj_type, $a_obj_id)) {
 
  341        if ($ref_id === 
null) {
 
  351        return $this->notify ? $this->notify : array();
 
  357        $this->invalid_links = array();
 
  361        $this->invalid_links[] = $a_link;
 
  367        $this->log_messages[] = $a_string;
 
  371        return $this->log_messages = array();
 
  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]);
 
  383                if ($url_data[
'scheme'] == 
'mailto') {
 
  388                if (!$url_data[
'scheme']) {
 
  389                    $matches[1][
$i] = 
'http://' . $matches[1][
$i];
 
  393                $link[] = array(
'page_id' => $a_page[
'page_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']);
 
  402        return $link ? $link : array();
 
  409        $objDefinition = 
$DIC[
'objDefinition'];
 
  415        foreach ($check_links = $link_res_obj->getCheckItems($this->getCheckPeriod()) as $item_data) {
 
  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'],
 
  425                                'complete' => $item_data[
'target'],
 
  426                                'scheme' => 
'internal',
 
  427                                'obj_type' => $parts[0],
 
  428                                'ref_id' => $parts[1]);
 
  434            $url_data = @parse_url($item_data[
'target']);
 
  437            if (!$url_data[
'scheme']) {
 
  438                $item_data[
'target'] = 
'http://' . $item_data[
'target'];
 
  441            $link[] = array(
'page_id' => $item_data[
'link_id'],
 
  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']);
 
  448        return $link ? $link : array();
 
  472        $tree = 
$DIC[
'tree'];
 
  474            $this->
__appendLogMessage(
'LinkChecker: Pear HTTP_Request is not installed. Aborting');
 
  480        foreach ($a_links as $link) {
 
  482            if ($link[
'scheme'] == 
'internal') {
 
  486                    $tree->isDeleted($link[
'ref_id'])) {
 
  494                if ($link[
'scheme'] !== 
'http' and $link[
'scheme'] !== 
'https') {
 
  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);
 
  513                    $headers = $curl->getInfo();
 
  514                    $http_code = $headers[
'http_code'];
 
  516                    $c_error_no = 
$e->getCode();
 
  524                switch ($http_code) {
 
  532                        $link[
'http_status_code'] = $http_code;
 
  533                        if ($http_code == 0 && $c_error_no != 0) {
 
  534                            $link[
'curl_errno'] = $c_error_no;
 
  546        $res = $this->db->query(
"SELECT lm_id FROM lm_data " .
 
  547            "WHERE obj_id = '" . $a_page_id . 
"'");
 
  551        return $row->lm_id ? $row->lm_id : 0;
 
  557            if ($link[
'page_id'] == $a_page_id and
 
  558               substr($link[
'complete'], 0, 255) == $a_url) {
 
  578            $id = 
$ilDB->nextId(
'link_check');
 
  580            $query = 
"INSERT INTO link_check (id, obj_id,page_id,url,parent_type,http_status_code,last_check) " .
 
  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') . 
" " .
 
  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') . 
" ";
 
  606            if (!
$res->numRows()) {
 
  607                $this->notify[$link[
"obj_id"]][] = array(
'page_id' => $link[
'page_id'],
 
  608                                                         'url' => $link[
'complete']);
 
  621            $query = 
"DELETE FROM link_check";
 
  623            $query = 
"DELETE FROM link_check " .
 
  624                "WHERE obj_id = " . 
$ilDB->quote($this->
getObjId(), 
'integer');
 
An exception for terminatinating execution or to throw for unit testing.
return true
Flag indicating whether or not HTTP headers will be sent when outputting captcha image/audio.
static _isCurlExtensionLoaded()
Check if curl extension is loaded.
static _lookupEntry($a_lang_key, $a_mod, $a_id)
static _getAllNotifiers(&$db)
class for checking external links in page objects Normally used in Cron jobs, but should be extensibl...
__fetchUserData($a_usr_id)
setCheckPeriod($a_period)
__txt($language, $key, $module='common')
__getObjIdByPageId($a_page_id)
__isInvalid($a_page_id, $a_url)
createPermanentLink($a_obj_id, $a_usr_id, $a_obj_type)
creates a permanent link
__construct($db, $a_validate_all=true)
__validateLinks($a_links)
$a_links Format: Array ( [1] => Array ( ['scheme'] => intern/http/https, ['ref_id'] => ILIAS ref ID,...
__appendInvalidLink($a_link)
__appendLogMessage($a_string)
Class ilLinkResourceItems.
static _getLink($a_ref_id, $a_type='', $a_params=array(), $append="")
static getLogger($a_component_id)
Get component logger.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupObjId($a_id)
static _getAllReferences($a_id)
get all reference ids of object
static _lookupType($a_id, $a_reference=false)
lookup object type
Wrapper classes for system notifications.
foreach($_POST as $key=> $value) $res