A
A
Alexey Bespalov2020-01-21 05:09:20
1C-Bitrix
Alexey Bespalov, 2020-01-21 05:09:20

What is this piece of code for $content = str_replace($zzz, str_replace('href', 'rel="nofollow" href', $zzz), $content);?

Found the code in init.php. I know that it was made by some SEOs. But why I can't figure it out. Because of this function, the context menu does not work in the admin panel, in the data export interface.

AddEventHandler("main", "OnEndBufferContent", "AutoCloseLinksHandler");
function AutoCloseLinksHandler(&$content)
{
    $url = $_SERVER['HTTP_HOST'];
    
    preg_match_all("<a[^<>]*href=[\"|'](.*)[\"|'][^<>]*>", $content, $out_url);
    foreach ($out_url[0] as $val => $zzz) {
        if (preg_match('~http(s)?://~', $zzz) && !preg_match('~http(s)?://(www.)?' . $url . '~i', $zzz) && !preg_match('~rel="nofollow"~i', $zzz)) {
            $content = str_replace($zzz, str_replace('href', 'rel="nofollow" href', $zzz), $content);
        }
    }
}

Can you tell me what this code is for? Does he really need it?
And is it possible to exclude the processing of the admin panel in it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question