HEX
Server: Apache/2.4.59 (Debian)
System: Linux skycube.cz 4.19.0-25-amd64 #1 SMP Debian 4.19.289-2 (2023-08-08) x86_64
User: ilya (534)
PHP: 7.3.31-1~deb10u7
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,
Upload Files
File: /var/www/ilya/data/www/korunka.ru/includes/typograph.php
<?php

define("TAG1","\xAC");  
define("TAG2","\xAD");  
define("LAQUO","\xAB");  
define("RAQUO","\xBB");  
define("LDQUO","\x84");  
define("RDQUO","\x93");  
define("MDASH","\x97");  
define("NDASH","\x96");  
define("APOS","\xB4");  
define("HELLIP","\x85");  

$Refs = array(); // буфер для хранения тегов  
$RefsCntr = 0;   // счётчик буфера 

function yyyTypo($x)  
{  
    global $Refs, $RefsCntr; 
    $Refs[] = StripSlashes($x[0]); 
    return TAG1.($RefsCntr++).TAG2;  
}  
function zzzTypo($x)  
{  
    global $Refs; 
    return $Refs[$x[1]];  
}  

function TypoAll($text, $isHTML = true) {
    global $Refs,$RefsCntr; 
    if($isHTML) {  
        $Refs = array(); // сбрасываем буфер  
        $RefsCntr = 0;   // счётчик буфера 

        // комментарии  
        $text = preg_replace_callback('{<!--.*?-->}s', 'yyyTypo', $text);  

        $PrivateTags = "title|script|style|pre|textarea"; 
        $text = preg_replace_callback('{<\s*('.$PrivateTags.')[\s>].*?<\s*/\s*\1\s*>}is', 'yyyTypo', $text);  

        // обычные теги  
        $text = preg_replace_callback('{<(?:[^\'"\>]+|".*?"|\'.*?\')+>}s','yyyTypo',$text);  
    }  

    // ОК. Теперь займёмся кавычками  

    $prequote = '\s\(\[\{";-';  
    $text = preg_replace('{^"}', LAQUO, $text);  
    $text = preg_replace('{(?<=['.$prequote.'])"}', LAQUO, $text);  

    // а это для тех, кто нарушает ВЕЛИКОЕ ПРАВИЛО  
    $text = preg_replace('{^((?:'.TAG1.'\d+'.TAG2.')+)"}', '\1'.LAQUO, $text);  
    $text = preg_replace('{(?<=['.$prequote.'])((?:'.TAG1.'\d+'.TAG2.')+)"}', '\1'.LAQUO, $text);  

    $text = str_replace('"', RAQUO, $text);  

    // исправляем ошибки в расстановке кавычек типа ""... и ...""  
    // (предполагаем, что не более двух-трёх кавык подряд)  
    $text = preg_replace('{'.LAQUO.RAQUO.'}', LAQUO.LAQUO, $text);  
    $text = preg_replace('{'.RAQUO.LAQUO.'}', RAQUO.RAQUO, $text);  

    //    вложенные кавыки  
    $i=0; // - это защита от зацикливания (оно возможно в случае неправильно расставленных кавычек)  
    while (($i++<10) && preg_match('{'.LAQUO.'(?:[^'.RAQUO.']*?)'.LAQUO.'}', $text))  
        $text = preg_replace(  
            '{'.LAQUO.'([^'.RAQUO.']*?)'.LAQUO.'(.*?)'.RAQUO.'}s',  
            LAQUO.'\1'.LDQUO.'\2'.RDQUO, $text);  

    $i=0;  
    while (($i++<10) && preg_match('{'.RAQUO.'(?:[^'.LAQUO.']*?)'.RAQUO.'}', $text))  
        $text = preg_replace(  
            '{'.RAQUO.'([^'.LAQUO.']*?)'.RAQUO.'}',  
            RDQUO.'\1'.RAQUO, $text);  

    // с кавычками закончили, займёмся мелкой типографикой  
    // тире:  
    $text = preg_replace('{^-+(?=\s)}',MDASH,$text);  
    $text = preg_replace('{(?<=[\s'.TAG2.'])-+(?=\s)}',MDASH,$text);  
    //$text = str_replace(' '.MDASH,'&nbsp;'.MDASH,$text);  
    // ndash:  
    //$text = preg_replace('{(?<=\d)-(?=\d)}',MDASH,$text);  
    // ...:  
    $text = str_replace('...',HELLIP,$text);  
    // апостроф:  
    $text = preg_replace('{(?<=\S)\'}',APOS,$text);  


    if($isHTML)  
    {  
        // возвращаем взятое обратно  
        while (preg_match('{'.TAG1.'.+?'.TAG2.'}', $text))  
            $text = preg_replace_callback('{'.TAG1.'(.+?)'.TAG2.'}', 'zzzTypo', $text);  
    }     
    
    // заменяем коды символов на HTML-entities.  
    /*$text = str_replace(  
        array(LAQUO,RAQUO,LDQUO,RDQUO,MDASH,NDASH,HELLIP,APOS),  
        array('&laquo;','&raquo;','&bdquo;','&ldquo;','&#8212;','&#8211;','&hellip;','&#8217;'),  
        $text  
    );  */

    return $text; 

}

?>