Public Member Functions | Data Fields

ilLinkChecker Class Reference

Public Member Functions

 ilLinkChecker (&$db, $a_validate_all=true)
 setMailStatus ($a_status)
 getMailStatus ()
 setObjId ($a_page_id)
 getObjId ()
 getValidateAll ()
 getLogMessages ()
 getInvalidLinks ()
 getInvalidLinksFromDB ()
 getLastCheckTimestamp ()
 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)
 __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

Detailed Description

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


Member Function Documentation

ilLinkChecker::__appendInvalidLink ( a_link  ) 

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

Referenced by checkLinks().

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

Here is the caller graph for this function:

ilLinkChecker::__appendLogMessage ( a_string  ) 

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

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

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

Here is the caller graph for this function:

ilLinkChecker::__checkNotify (  ) 

Definition at line 457 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 = '".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 475 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 320 of file class.ilLinkChecker.php.

Referenced by checkLinks().

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

Here is the caller graph for this function:

ilLinkChecker::__clearLogMessages (  ) 

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

Referenced by checkLinks().

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

Here is the caller graph for this function:

ilLinkChecker::__fetchUserData ( a_usr_id  ) 

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

References $data, $query, and $row.

Referenced by __sendMail().

        {
                $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;
        }

Here is the caller graph for this function:

ilLinkChecker::__getLinks ( a_page  ) 

Definition at line 339 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]);
                                
                                // 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 314 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 406 of file class.ilLinkChecker.php.

References $query, and $row.

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 246 of file class.ilLinkChecker.php.

References $query, and $row.

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::__isInvalid ( a_page_id,
a_url 
)

Definition at line 416 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 429 of file class.ilLinkChecker.php.

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

Referenced by checkLinks().

        {
                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 = '".substr($link['complete'],0,255)."', ".
                                "parent_type = '".$link['type']."', ".
                                "http_status_code = '".$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 256 of file class.ilLinkChecker.php.

References $counter, $data, $obj_id, __appendLogMessage(), __fetchUserData(), __getNotifyLinks(), __getTitle(), __txt(), ilLinkCheckNotify::_getAllNotifiers(), and getMailStatus().

Referenced by checkLinks().

        {
                if(!count($notify = $this->__getNotifyLinks()))
                {
                        // Nothing to do
                        return true;
                }
                if($this->getMailStatus())
                {
                        // get all users who want to be notified
                        include_once '../classes/class.ilLinkCheckNotify.php';
                        
                        foreach(ilLinkCheckNotify::_getAllNotifiers($this->db) as $usr_id => $obj_ids)
                        {
                                // Get usr_data (default language, email)
                                $usr_data = $this->__fetchUserData($usr_id);

                                include_once '../classes/class.ilMimeMail.php';
                                
                                $mail =& new ilMimeMail();
                                
                                $mail->From('noreply');
                                $mail->To($usr_data['email']);
                                $mail->Subject($this->__txt($usr_data['lang'],'link_check_subject'));

                                $body = $this->__txt($usr_data['lang'],'link_check_body_top')."\r\n";

                                $counter = 0;
                                foreach($obj_ids as $obj_id)
                                {
                                        if(!isset($notify[$obj_id]))
                                        {
                                                continue;
                                        }
                                        ++$counter;

                                        $body .= $this->__txt($usr_data['lang'],'lo');
                                        $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)
                                {
                                        $mail->Body($body);
                                        $mail->Send();
                                        $this->__appendLogMessage('LinkChecker: Sent mail to '.$usr_data['email']);

                                }
                        }
                }
        }

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 199 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 369 of file class.ilLinkChecker.php.

References __appendLogMessage().

Referenced by checkLinks().

        {
                if(!@include_once('HTTP/Request.php'))
                {
                        $this->__appendLogMessage('LinkChecker: Pear HTTP_Request is not installed. Aborting');

                        return array();
                }

                foreach($a_links as $link)
                {
                        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 125 of file class.ilLinkChecker.php.

References $query, $res, $row, __appendInvalidLink(), __appendLogMessage(), __clearInvalidLinks(), __clearLogMessages(), __getLinks(), __saveInDB(), __sendMail(), __validateLinks(), getInvalidLinks(), getObjId(), and getValidateAll().

        {
                $pages = array();

                $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 188 of file class.ilLinkChecker.php.

        {
                if(!@include_once('HTTP/Request.php'))
                {
                        return false;
                }
                return true;
        }

ilLinkChecker::getInvalidLinks (  ) 

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

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

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

Here is the caller graph for this function:

ilLinkChecker::getInvalidLinksFromDB (  ) 

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

References $query, $res, and $row.

        {
                $query = "SELECT * FROM link_check ".
                        "WHERE obj_id = '".$this->getObjId()."'";

                $res = $this->db->query($query);
                while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
                {
                        $invalid[] = array('page_id' => $row->page_id,
                                                           'url'         => $row->url);
                }

                return $invalid ? $invalid : array();
        }

ilLinkChecker::getLastCheckTimestamp (  ) 

Definition at line 108 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 83 of file class.ilLinkChecker.php.

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

ilLinkChecker::getMailStatus (  ) 

Definition at line 63 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 73 of file class.ilLinkChecker.php.

Referenced by checkLinks().

        {
                return $this->page_id;
        }

Here is the caller graph for this function:

ilLinkChecker::getValidateAll (  ) 

Definition at line 78 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, and $ilDB.

        {
                global $ilDB;

                define('DEBUG',1);
                define('SOCKET_TIMEOUT',5);

                $this->db =& $db;

                // SET GLOBAL DB HANDLER FOR STATIC METHODS OTHER CLASSES
                $ilDB =& $db;

                $this->validate_all = $a_validate_all;
        }

ilLinkChecker::setMailStatus ( a_status  ) 

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

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

ilLinkChecker::setObjId ( a_page_id  ) 

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

        {
                return $this->page_id = $a_page_id;
        }


Field Documentation

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.


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