HEX
Server: Apache/2.4.46 (Ubuntu)
System: Linux localhost 5.11.0-49-generic #55-Ubuntu SMP Wed Jan 12 17:36:34 UTC 2022 x86_64
User: root (0)
PHP: 7.4.16
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/html/sarvodayahospital/app/PageInterlink.php
<?php
namespace App;

use App\Models\Interlink;

class PageInterlink {
    static function interlink_filter($content, $firstrun=true)
    {
        global $protectblocks;

        $content = preg_replace_callback('!(\<a[^>]*\>([^>]*)\>)!ims',function ($blocks){
            global $protectblocks;
            $protectblocks[] = $blocks[1];
            return '[block]'.(count($protectblocks)-1).'[/block]';
        }, $content);

        if($firstrun)
        {
            $content = preg_replace_callback('!(\<code\>[\S\s]*?\<\/code\>)!ims', function ($blocks){
                global $protectblocks;
                $protectblocks[] = $blocks[1];
                return '[block]'.(count($protectblocks)-1).'[/block]';
            }, $content);


            $content = preg_replace_callback('!(\[tags*\][\S\s]*?\[\/tags*\])!ims', function ($blocks){
                global $protectblocks;
                $protectblocks[] = $blocks[1];
                return '[block]'.(count($protectblocks)-1).'[/block]';
            }, $content);


            $content = preg_replace_callback('!(\<img[^>]*\>)!ims', function ($blocks){
                global $protectblocks;
                $protectblocks[] = $blocks[1];
                return '[block]'.(count($protectblocks)-1).'[/block]';
            }, $content);

            $content = preg_replace_callback('!(\<h1[^>]*\>([^>]*)\>)!ims', function ($blocks){
                global $protectblocks;
                $protectblocks[] = $blocks[1];
                return '[block]'.(count($protectblocks)-1).'[/block]';
            }, $content);

            $content = preg_replace_callback('!(\<h2[^>]*\>([^>]*)\>)!ims', function ($blocks){
                global $protectblocks;
                $protectblocks[] = $blocks[1];
                return '[block]'.(count($protectblocks)-1).'[/block]';
            }, $content);


            $content = preg_replace_callback('!(\<h3[^>]*\>([^>]*)\>)!ims', function ($blocks){
                global $protectblocks;
                $protectblocks[] = $blocks[1];
                return '[block]'.(count($protectblocks)-1).'[/block]';
            }, $content);


            $content = preg_replace_callback('!(\<h4[^>]*\>([^>]*)\>)!ims', function ($blocks){
                global $protectblocks;
                $protectblocks[] = $blocks[1];
                return '[block]'.(count($protectblocks)-1).'[/block]';
            }, $content);


            $content = preg_replace_callback('!(\<h5[^>]*\>([^>]*)\>)!ims', function ($blocks){
                global $protectblocks;
                $protectblocks[] = $blocks[1];
                return '[block]'.(count($protectblocks)-1).'[/block]';
            }, $content);


            $content = preg_replace_callback('!(\<h6[^>]*\>([^>]*)\>)!ims', function ($blocks){
                global $protectblocks;
                $protectblocks[] = $blocks[1];
                return '[block]'.(count($protectblocks)-1).'[/block]';
            }, $content);
        }


        $keywords = Interlink::orderBy('Priority','ASC')->get();

            foreach($keywords as $keyR){

                if ($keyR->OpenInNewWindow) {
                    $openExternalWindow = 'target="_blank" rel="noopener"';
                } else {
                    $openExternalWindow = '';
                }

                $ankerTag = '<a href="'.$keyR->Link.'" '.$openExternalWindow.'>'.$keyR->Keyword.'</a>';
                //$changedText = preg_replace('/('.preg_quote($keyR->keyword, '/').')/i', $ankerTag, $changedText,$keyR->count);  // change by character
                $content = preg_replace(sprintf('/\b%s\b/',preg_quote($keyR->Keyword)), $ankerTag, $content,$keyR->Count); //change by word
            }

            $content = preg_replace_callback('!(\[block\]([0-9]*?)\[\/block\])!', function ($blocks){
            global $protectblocks;
            $protectblocks[] = $blocks[1];
            return $protectblocks[$blocks[2]];
        }, $content);


        return $content;
    }

    public static function interlink_formatter(string $html = null)
    {
        return static::interlink_filter($html);
    }
}