src/Kunstmaan/NodeBundle/Helper/URLHelper.php
public function replaceUrl($text)
    {
        if ($this->isEmailAddress($text)) {
            $text = sprintf('%s:%s', 'mailto', $text);
        }

        if ($this->isInternalLink($text)) {
            preg_match_all("/\[(([a-z_A-Z\.]+):)?NT([0-9]+)\]/", $text, $matches, PREG_SET_ORDER);

            if (count($matches) > 0) {
                $map = $this->getNodeTranslationMap();
                foreach ($matches as $match) {
                    $nodeTranslationFound = false;
                    $fullTag = $match[0];
                    $hostId = $match[2];
                    $hostConfig = $this->domainConfiguration->getFullHostById($hostId);
                    $hostBaseUrl = $this->domainConfiguration->getHostBaseUrl($hostConfig['host']);

                    $nodeTranslationId = $match[3];

                    foreach ($map as $nodeTranslation) {
                        if ($nodeTranslation['id'] == $nodeTranslationId) {
                            $urlParams = ['url' => $nodeTranslation['url']];
                            $nodeTranslationFound = true;
                            // Only add locale if multilingual site
                            if ($this->domainConfiguration->isMultiLanguage($hostConfig['host'])) {
                                $urlParams['_locale'] = $nodeTranslation['lang'];
                            }

                            // Only add other site, when having this.
                            if ($hostId) {
                                $urlParams['otherSite'] = $hostId;
                            }

                            $url = $this->router->generate('_slug', $urlParams);

                            $text = str_replace($fullTag, $hostId ? $hostBaseUrl . $url : $url, $text);
                        }
                    }

                    if (!$nodeTranslationFound) {
                        $this->logger->error('No NodeTranslation found in the database when replacing url tag ' . $fullTag);
                    }
                }
            }
        }

        if ($this->isInternalMediaLink($text)) {
            preg_match_all("/\[(([a-z_A-Z]+):)?M([0-9]+)\]/", $text, $matches, PREG_SET_ORDER);

            if (count($matches) > 0) {
                $map = $this->getMediaMap();
                foreach ($matches as $match) {
                    $mediaFound = false;
                    $fullTag = $match[0];
                    $mediaId = $match[3];

                    foreach ($map as $mediaItem) {
                        if ($mediaItem['id'] == $mediaId) {
                            $mediaFound = true;
                            $text = str_replace($fullTag, $mediaItem['url'], $text);
                        }
                    }

                    if (!$mediaFound) {
                        $this->logger->error('No Media found in the database when replacing url tag ' . $fullTag);
                    }
                }
            }
        }

        return $text;
    }
public function replaceUrl($text)
    {
        if ($this->isEmailAddress($text)) {
            $text = sprintf('%s:%s', 'mailto', $text);
        }

        if ($this->isInternalLink($text)) {
            preg_match_all("/\[(([a-z_A-Z\.]+):)?NT([0-9]+)\]/", $text, $matches, PREG_SET_ORDER);

            if (count($matches) > 0) {
                $map = $this->getNodeTranslationMap();
                foreach ($matches as $match) {
                    $nodeTranslationFound = false;
                    $fullTag = $match[0];
                    $hostId = $match[2];
                    $hostConfig = $this->domainConfiguration->getFullHostById($hostId);
                    $hostBaseUrl = $this->domainConfiguration->getHostBaseUrl($hostConfig['host']);

                    $nodeTranslationId = $match[3];

                    foreach ($map as $nodeTranslation) {
                        if ($nodeTranslation['id'] == $nodeTranslationId) {
                            $urlParams = ['url' => $nodeTranslation['url']];
                            $nodeTranslationFound = true;
                            // Only add locale if multilingual site
                            if ($this->domainConfiguration->isMultiLanguage($hostConfig['host'])) {
                                $urlParams['_locale'] = $nodeTranslation['lang'];
                            }

                            // Only add other site, when having this.
                            if ($hostId) {
                                $urlParams['otherSite'] = $hostId;
                            }

                            $url = $this->router->generate('_slug', $urlParams);

                            $text = str_replace($fullTag, $hostId ? $hostBaseUrl . $url : $url, $text);
                        }
                    }

                    if (!$nodeTranslationFound) {
                        $this->logger->error('No NodeTranslation found in the database when replacing url tag ' . $fullTag);
                    }
                }
            }
        }

        if ($this->isInternalMediaLink($text)) {
            preg_match_all("/\[(([a-z_A-Z]+):)?M([0-9]+)\]/", $text, $matches, PREG_SET_ORDER);

            if (count($matches) > 0) {
                $map = $this->getMediaMap();
                foreach ($matches as $match) {
                    $mediaFound = false;
                    $fullTag = $match[0];
                    $mediaId = $match[3];

                    foreach ($map as $mediaItem) {
                        if ($mediaItem['id'] == $mediaId) {
                            $mediaFound = true;
                            $text = str_replace($fullTag, $mediaItem['url'], $text);
                        }
                    }

                    if (!$mediaFound) {
                        $this->logger->error('No Media found in the database when replacing url tag ' . $fullTag);
                    }
                }
            }
        }

        return $text;
    }
public function replaceUrl ( $ text ) { if ( $ this -> isEmailAddress ( $ text ) ) { $ text = sprintf ( '%s:%s' , 'mailto' , $ text ) ; } if ( $ this -> isInternalLink ( $ text ) ) { preg_match_all ( "/\[(([a-z_A-Z\.]+):)?NT([0-9]+)\]/" , $ text , $ matches , PREG_SET_ORDER ) ; if ( count ( $ matches ) > 0 ) { $ map = $ this -> getNodeTranslationMap ( ) ; foreach ( $ matches as $ match ) { $ nodeTranslationFound = false ; $ fullTag = $ match [ 0 ] ; $ hostId = $ match [ 2 ] ; $ hostConfig = $ this -> domainConfiguration -> getFullHostById ( $ hostId ) ; $ hostBaseUrl = $ this -> domainConfiguration -> getHostBaseUrl ( $ hostConfig [ 'host' ] ) ; $ nodeTranslationId = $ match [ 3 ] ; foreach ( $ map as $ nodeTranslation ) { if ( $ nodeTranslation [ 'id' ] == $ nodeTranslationId ) { $ urlParams = [ 'url' => $ nodeTranslation [ 'url' ] ] ; $ nodeTranslationFound = true ; // Only add locale if multilingual site if ( $ this -> domainConfiguration -> isMultiLanguage ( $ hostConfig [ 'host' ] ) ) { $ urlParams [ '_locale' ] = $ nodeTranslation [ 'lang' ] ; } // Only add other site, when having this. if ( $ hostId ) { $ urlParams [ 'otherSite' ] = $ hostId ; } $ url = $ this -> router -> generate ( '_slug' , $ urlParams ) ; $ text = str_replace ( $ fullTag , $ hostId ? $ hostBaseUrl . $ url : $ url , $ text ) ; } } if ( ! $ nodeTranslationFound ) { $ this -> logger -> error ( 'No NodeTranslation found in the database when replacing url tag ' . $ fullTag ) ; } } } } if ( $ this -> isInternalMediaLink ( $ text ) ) { preg_match_all ( "/\[(([a-z_A-Z]+):)?M([0-9]+)\]/" , $ text , $ matches , PREG_SET_ORDER ) ; if ( count ( $ matches ) > 0 ) { $ map = $ this -> getMediaMap ( ) ; foreach ( $ matches as $ match ) { $ mediaFound = false ; $ fullTag = $ match [ 0 ] ; $ mediaId = $ match [ 3 ] ; foreach ( $ map as $ mediaItem ) { if ( $ mediaItem [ 'id' ] == $ mediaId ) { $ mediaFound = true ; $ text = str_replace ( $ fullTag , $ mediaItem [ 'url' ] , $ text ) ; } } if ( ! $ mediaFound ) { $ this -> logger -> error ( 'No Media found in the database when replacing url tag ' . $ fullTag ) ; } } } } return $ text ; }
Replace a given text, according to the node translation id and the multidomain site id.

@param $text

@return mixed
Replace a given text according to the node translation id and the multidomain site id .