src/Service/Emailer.php
protected function processLinkGenerate($html, $url, $title, $is_html)
    {
        //  Ensure URLs have a domain
        if (preg_match('/^\//', $url)) {
            $url = $this->getDomain() . $url;
        }

        /**
         * Generate a tracking URL for this link
         * Firstly, check this URL hasn't been processed already (for this email)
         */

        if (isset($this->aTrackLinkCache[md5($url)])) {

            $trackingUrl = $this->aTrackLinkCache[md5($url)];

            //  Replace the URL and return the new tag
            $html = str_replace($url, $trackingUrl, $html);

        } else {

            /**
             * New URL, needs processed. We take the URL and the Title, store it in the
             * database and generate the new tracking link (inc. hashes etc). We'll cache
             * this link so we don't have to process it again.
             *
             * If the email we're sending to hasn't been verified yet we should set the
             * actual URL as the return_to value of the email verifier, that means that
             * every link in this email behaves as a verifying email. Obviously we shouldn't
             * do this for the actual email verifier...
             */

            if ($this->mGenerateTrackingNeedsVerified) {

                //  Make sure we're not applying this to an activation URL
                if (!preg_match('#email/verify/[0-9]*?/(.*?)#', $url)) {

                    $_user_id = $this->mGenerateTrackingNeedsVerified['id'];
                    $_code    = $this->mGenerateTrackingNeedsVerified['code'];
                    $_return  = urlencode($url);

                    $_url = site_url('email/verify/' . $_user_id . '/' . $_code . '?return_to=' . $_return);

                } else {
                    $_url = $url;
                }

            } else {
                $_url = $url;
            }

            $oDb = Factory::service('Database');
            $oDb->set('email_id', $this->iGenerateTrackingEmailId);
            $oDb->set('url', $_url);
            $oDb->set('title', $title);
            $oDb->set('created', 'NOW()', false);
            $oDb->set('is_html', $is_html);
            $oDb->insert(NAILS_DB_PREFIX . 'email_archive_link');

            $_id = $oDb->insert_id();

            if ($_id) {

                $_time       = time();
                $trackingUrl = 'email/tracker/link/' . $this->sGenerateTrackingEmailRef . '/' . $_time . '/';
                $trackingUrl .= $this->generateHash($this->sGenerateTrackingEmailRef, $_time) . '/' . $_id;
                $trackingUrl = site_url($trackingUrl);

                $this->aTrackLinkCache[md5($url)] = $trackingUrl;

                // --------------------------------------------------------------------------

                /**
                 * Replace the URL and return the new tag. $url in quotes so we only replace
                 * hyperlinks and not something else, such as an image's URL
                 */

                $html = str_replace('"' . $url . '"', $trackingUrl, $html);
            }
        }

        return $html;
    }
protected function processLinkGenerate($html, $url, $title, $is_html)
    {
        //  Ensure URLs have a domain
        if (preg_match('/^\//', $url)) {
            $url = $this->getDomain() . $url;
        }

        /**
         * Generate a tracking URL for this link
         * Firstly, check this URL hasn't been processed already (for this email)
         */

        if (isset($this->aTrackLinkCache[md5($url)])) {

            $trackingUrl = $this->aTrackLinkCache[md5($url)];

            //  Replace the URL and return the new tag
            $html = str_replace($url, $trackingUrl, $html);

        } else {

            /**
             * New URL, needs processed. We take the URL and the Title, store it in the
             * database and generate the new tracking link (inc. hashes etc). We'll cache
             * this link so we don't have to process it again.
             *
             * If the email we're sending to hasn't been verified yet we should set the
             * actual URL as the return_to value of the email verifier, that means that
             * every link in this email behaves as a verifying email. Obviously we shouldn't
             * do this for the actual email verifier...
             */

            if ($this->mGenerateTrackingNeedsVerified) {

                //  Make sure we're not applying this to an activation URL
                if (!preg_match('#email/verify/[0-9]*?/(.*?)#', $url)) {

                    $_user_id = $this->mGenerateTrackingNeedsVerified['id'];
                    $_code    = $this->mGenerateTrackingNeedsVerified['code'];
                    $_return  = urlencode($url);

                    $_url = site_url('email/verify/' . $_user_id . '/' . $_code . '?return_to=' . $_return);

                } else {
                    $_url = $url;
                }

            } else {
                $_url = $url;
            }

            $oDb = Factory::service('Database');
            $oDb->set('email_id', $this->iGenerateTrackingEmailId);
            $oDb->set('url', $_url);
            $oDb->set('title', $title);
            $oDb->set('created', 'NOW()', false);
            $oDb->set('is_html', $is_html);
            $oDb->insert(NAILS_DB_PREFIX . 'email_archive_link');

            $_id = $oDb->insert_id();

            if ($_id) {

                $_time       = time();
                $trackingUrl = 'email/tracker/link/' . $this->sGenerateTrackingEmailRef . '/' . $_time . '/';
                $trackingUrl .= $this->generateHash($this->sGenerateTrackingEmailRef, $_time) . '/' . $_id;
                $trackingUrl = site_url($trackingUrl);

                $this->aTrackLinkCache[md5($url)] = $trackingUrl;

                // --------------------------------------------------------------------------

                /**
                 * Replace the URL and return the new tag. $url in quotes so we only replace
                 * hyperlinks and not something else, such as an image's URL
                 */

                $html = str_replace('"' . $url . '"', $trackingUrl, $html);
            }
        }

        return $html;
    }
protected function processLinkGenerate ( $ html , $ url , $ title , $ is_html ) { //  Ensure URLs have a domain if ( preg_match ( '/^\//' , $ url ) ) { $ url = $ this -> getDomain ( ) . $ url ; } /**
         * Generate a tracking URL for this link
         * Firstly, check this URL hasn't been processed already (for this email)
         */ if ( isset ( $ this -> aTrackLinkCache [ md5 ( $ url ) ] ) ) { $ trackingUrl = $ this -> aTrackLinkCache [ md5 ( $ url ) ] ; //  Replace the URL and return the new tag $ html = str_replace ( $ url , $ trackingUrl , $ html ) ; } else { /**
             * New URL, needs processed. We take the URL and the Title, store it in the
             * database and generate the new tracking link (inc. hashes etc). We'll cache
             * this link so we don't have to process it again.
             *
             * If the email we're sending to hasn't been verified yet we should set the
             * actual URL as the return_to value of the email verifier, that means that
             * every link in this email behaves as a verifying email. Obviously we shouldn't
             * do this for the actual email verifier...
             */ if ( $ this -> mGenerateTrackingNeedsVerified ) { //  Make sure we're not applying this to an activation URL if ( ! preg_match ( '#email/verify/[0-9]*?/(.*?)#' , $ url ) ) { $ _user_id = $ this -> mGenerateTrackingNeedsVerified [ 'id' ] ; $ _code = $ this -> mGenerateTrackingNeedsVerified [ 'code' ] ; $ _return = urlencode ( $ url ) ; $ _url = site_url ( 'email/verify/' . $ _user_id . '/' . $ _code . '?return_to=' . $ _return ) ; } else { $ _url = $ url ; } } else { $ _url = $ url ; } $ oDb = Factory :: service ( 'Database' ) ; $ oDb -> set ( 'email_id' , $ this -> iGenerateTrackingEmailId ) ; $ oDb -> set ( 'url' , $ _url ) ; $ oDb -> set ( 'title' , $ title ) ; $ oDb -> set ( 'created' , 'NOW()' , false ) ; $ oDb -> set ( 'is_html' , $ is_html ) ; $ oDb -> insert ( NAILS_DB_PREFIX . 'email_archive_link' ) ; $ _id = $ oDb -> insert_id ( ) ; if ( $ _id ) { $ _time = time ( ) ; $ trackingUrl = 'email/tracker/link/' . $ this -> sGenerateTrackingEmailRef . '/' . $ _time . '/' ; $ trackingUrl .= $ this -> generateHash ( $ this -> sGenerateTrackingEmailRef , $ _time ) . '/' . $ _id ; $ trackingUrl = site_url ( $ trackingUrl ) ; $ this -> aTrackLinkCache [ md5 ( $ url ) ] = $ trackingUrl ; // -------------------------------------------------------------------------- /**
                 * Replace the URL and return the new tag. $url in quotes so we only replace
                 * hyperlinks and not something else, such as an image's URL
                 */ $ html = str_replace ( '"' . $ url . '"' , $ trackingUrl , $ html ) ; } } return $ html ; }
Generate a tracking URL

@param  string  $html    The Link HTML
@param  string  $url     The Link's URL
@param  string  $title   The Link's Title
@param  boolean $is_html Whether this is HTML or not

@return string
@throws HostNotKnownException
@throws \Nails\Common\Exception\FactoryException
Generate a tracking URL