Пример #1
0
function bg_bibfers_bible_proc($txt, $type = '', $lang = '', $prll = '')
{
    global $post;
    global $bg_bibfers_option;
    global $bg_bibfers_all_refs;
    global $bg_bibfers_chapter, $bg_bibfers_ch;
    global $bg_bibfers_url, $bg_bibfers_bookTitle, $bg_bibfers_shortTitle, $bg_bibfers_bookFile;
    bg_bibfers_get_options();
    /****************** ОТЛАДКА ****************************************/
    if ($bg_bibfers_option['debug']) {
        $debug_file = dirname(dirname(__FILE__)) . "/debug.log";
        if (file_exists($debug_file)) {
            $size = filesize($debug_file);
            $lasttime = filectime($debug_file);
            if ($lasttime + 30 * 60 < time() || $size > 2 * 1024 * 1024) {
                unlink($debug_file);
            }
        }
        $start_time = microtime(true) * 1000;
        $s_time = $start_time;
        error_log(date('d.m.Y h:i:s') . ": " . get_permalink() . "\n", 3, $debug_file);
    }
    /*******************************************************************/
    if (!$lang) {
        $lang = set_bible_lang();
    }
    $lang = include_books($lang);
    $norefs_posts_val = get_post_meta($post->ID, 'norefs', true);
    if ($norefs_posts_val || in_category('norefs') || has_tag('norefs')) {
        return $txt;
    }
    // Ищем все вхождения ссылок <a ...</a>, заголовков <h. ... </h.> и шорт-кодов [norefs]...[/norefs] и [bible]...[/bible]
    preg_match_all("/<a\\s.*?<\\/a>/sui", $txt, $hdr_a, PREG_OFFSET_CAPTURE);
    preg_match_all("/<h([1-6])(.*?)<\\/h\\1>/sui", $txt, $hdr_h, PREG_OFFSET_CAPTURE);
    preg_match_all("/\\[norefs.*?\\[\\/norefs\\]/sui", $txt, $hdr_norefs, PREG_OFFSET_CAPTURE);
    preg_match_all("/\\[bible.*?\\[\\/bible\\]/sui", $txt, $hdr_bible, PREG_OFFSET_CAPTURE);
    // Ищем все вхождения ссылок на Библию
    //	$template = "/[\\(\\[](см\\.?\\:?(\\s|&nbsp\\;)*)?(\\d?(\\s|&nbsp\\;)*[А-яA-z]{2,8})((\\.|\\s|&nbsp\\;)*)(\\d+((\\s|&nbsp\\;)*[\\:\\,\\-—–](\\s|&nbsp\\;)*\\d+)*)(\\s|&nbsp\\;)*[\\]\\)]/ui";
    //	$template = "/(\\s|&nbsp\\;)?\\(?\\[?((\\s|&nbsp\\;)*см\\.?\\:?(\\s|&nbsp\\;)*)?(\\d?(\\s|&nbsp\\;)*[А-яA-z]{2,8})((\\.|\\s|&nbsp\\;)*)(\\d+((\\s|&nbsp\\;)*[\\:\\,\\-—–](\\s|&nbsp\\;)*\\d+)*)(\\s|&nbsp\\;)*[\\]\\)\\.]?/ui";
    //	$template = "/(\\s|&nbsp\\;)?\\(?\\[?((\\s|&nbsp\\;)*см\\.?\\:?(\\s|&nbsp\\;)*)?(\\d?(\\s|&nbsp\\;)*[А-яA-z]{2,8})((\\.|\\s|&nbsp\\;)*)(\\d+((\\s|&nbsp\\;)*[\\:\\;\\,\\.\\-—–](\\s|&nbsp\\;)*\\d+)*)(\\s|&nbsp\\;)*[\\]\\)\\.]?/ui";
    //	$template = "/(\\s|&nbsp\\;)?\\(?\\[?((\\s|&nbsp\\;)*см\\.?\\:?(\\s|&nbsp\\;)*)?(\\d?(\\s|&nbsp\\;)*[А-яA-z]{2,8})((\\.|\\s|&nbsp\\;)*)(\\d+((\\s|&nbsp\\;)*[\\:\\,\\.\\-—–](\\s|&nbsp\\;)*\\d+)*)(\\s|&nbsp\\;)*[\\]\\)(\\;|\\.)]?/ui";
    //	$template = "/(\\s|&nbsp\\;)?\\(?\\[?((\\s|&nbsp\\;)*см\\.?\\:?(\\s|&nbsp\\;)*)?(\\d?(\\s|&nbsp\\;)*[А-яA-z]{2,8})((\\.|\\s|&nbsp\\;)*)(\\d+((\\s|&nbsp\\;)*[\\:\\,\\.\\-—–](\\s|&nbsp\\;)*\\d+)*)[(\\s|&nbsp\\;)\\]\\)(\\;|\\.)]?/ui";
    //	$template = "/(\\s|&nbsp\\;)?\\(?\\[?((\\s|&nbsp\\;)*см\\.?\\:?(\\s|&nbsp\\;)*)?([1-4]?(\\s|&nbsp\\;)*[А-яёіїєґўЁІЇЄҐЎA-z\']{2,8})((\\.|\\s|&nbsp\\;)*)(\\d+((\\s|&nbsp\\;)*[\\:\\,\\.\\-‐‑‒–——―](\\s|&nbsp\\;)*\\d+)*)[(\\s|&nbsp\\;)\\]\\)(\\;|\\.)]?/uxi";
    $sps = "(?:\\s|\\x{00A0}|\\x{00C2}|(?:&nbsp;))";
    $dashes = "(?:[\\x{2010}-\\x{2015}]|(&#820[8-9];)|(&#821[0-3];))";
    $template = "/(?<!\\w)((?:[1-4]|I{1,3}|IV)?" . $sps . "*['A-Za-zА-Яа-яёіїєґўЁІЇЄҐЎ]{2,8})" . $sps . "*\\.?" . $sps . "*((\\d+|[IVXLC]+)(" . $sps . "*([\\.;:,-]|" . $dashes . ")" . $sps . "*(\\d+|[IVXLC]+))*)(?!\\w)/u";
    preg_match_all($template, $txt, $matches, PREG_OFFSET_CAPTURE);
    $cnt = count($matches[0]);
    $text = "";
    $start = 0;
    $j = 0;
    /****************** ОТЛАДКА ****************************************/
    if ($bg_bibfers_option['debug']) {
        $this_time = microtime(true) * 1000;
        $time = $this_time - $start_time;
        error_log("  Начальная обработка: " . round($time, 2) . " мсек.\n", 3, $debug_file);
        $start_time = $this_time;
    }
    /*******************************************************************/
    for ($i = 0; $i < $cnt; $i++) {
        // Проверим по каждому паттерну.
        preg_match($template, $matches[0][$i][0], $mt);
        /****************** ОПЕРАТИВНАЯ ОТЛАДКА ****************************	
        		echo "<b>". $matches[0][$i][0]."</b> => ";
        		$mcnt = count ($mt);
        		for ($k=1; $k < $mcnt; $k++) {
        			echo " <sup>|".$k."|</sup> ".$mt[$k];
        		}	
        		echo "<br>";
        /*******************************************************************/
        $cn = count($mt);
        if ($cn > 0) {
            $title = preg_replace("/" . $sps . "/u", '', $mt[1]);
            // Убираем пробельные символы, включая пробел, табуляцию, переводы строки
            $chapter = preg_replace("/" . $sps . "/u", '', $mt[2]);
            // и другие юникодные пробельные символы, а также неразрывные пробелы &nbsp;
            $chapter = preg_replace("/" . $dashes . "/u", '-', $chapter);
            // Замена разных вариантов тире на обычный
            $chapter = preg_replace("/;/u", ',', $chapter);
            // Замена точки с запятой на запятую
            $chapter = preg_replace("/(?<=[IVXLC]),\\./u", ":", $chapter);
            // Римскими цифрами обозначаются только главы (после них должно идти ":", а не "," или ".")
            // Замена римских цифр на арабские
            preg_match("/(I{1,3}|IV)(?=" . $sps . "*['A-Za-zА-Яа-яёіїєґўЁІЇЄҐЎ]{2,8})/u", $title, $rome);
            if ($rome) {
                $title = preg_replace("/" . $rome[0] . "/u", rome_to_arab($rome[0]), $title, 1);
            }
            preg_match_all("/[IVXLC]+/u", $chapter, $rome, PREG_OFFSET_CAPTURE);
            $crome = count($rome[0]);
            for ($r = 0; $r < $crome; $r++) {
                $chapter = preg_replace("/" . $rome[0][$r][0] . "/u", rome_to_arab($rome[0][$r][0]), $chapter, 1);
            }
            preg_match("/[\\:\\,\\.\\-]/u", $chapter, $mtchs);
            if ($mtchs) {
                if (strcasecmp($mtchs[0], ',') == 0 || strcasecmp($mtchs[0], '.') == 0) {
                    $chapter = preg_replace("/\\,/u", ':', $chapter, 1);
                    // Первое число всегда номер главы. Если глава отделена запятой, заменяем ее на двоеточие.
                    $chapter = preg_replace("/\\./u", ':', $chapter, 1);
                    // Первое число всегда номер главы. Если глава отделена точкой, заменяем ее на двоеточие.
                }
            }
            $title = bg_bibfers_getBook($title);
            if (strcasecmp($title, "") != 0 && bg_bibfers_check_tag($hdr_a, $matches[0][$i][1]) && ($bg_bibfers_option['headers'] == 'on' || bg_bibfers_check_tag($hdr_h, $matches[0][$i][1])) && bg_bibfers_check_tag($hdr_norefs, $matches[0][$i][1]) && bg_bibfers_check_tag($hdr_bible, $matches[0][$i][1])) {
                $ref = $matches[0][$i][0];
                $ref = trim($ref, " \f\t\v\n\r��");
                $book = bg_bibfers_getBook($title);
                // Обозначение книги
                if ($type == '' || $type == 'link') {
                    $book = bg_bibfers_getshortTitle($book);
                    // Короткое наименование книги
                    if ($bg_bibfers_option['norm_refs']) {
                        // Преобразовать ссылку к нормализованному виду
                        $newmt = bg_bibfers_get_url($title, $chapter, $book . ' ' . $chapter, $lang);
                    } else {
                        $newmt = bg_bibfers_get_url($title, $chapter, $ref, $lang);
                    }
                    $listmt = bg_bibfers_get_url($title, $chapter, $book . ' ' . $chapter, $lang);
                    $double = false;
                    for ($k = 0; $k < $j; $k++) {
                        // Проверяем не совпадают ли ссылки?
                        if ($bg_bibfers_all_refs[$k] == $listmt) {
                            $double = true;
                            break;
                        }
                    }
                    if (!$double) {
                        // Дубликат не найден
                        $bg_bibfers_all_refs[$j] = $listmt;
                        $j++;
                    }
                } else {
                    $newmt = bg_bibfers_getQuotes($book, $chapter, $type, $lang, $prll);
                }
                $text = $text . substr($txt, $start, $matches[0][$i][1] - $start) . str_replace($ref, $newmt, $matches[0][$i][0]);
                $start = $matches[0][$i][1] + strlen($matches[0][$i][0]);
            }
        }
    }
    $txt = $text . substr($txt, $start);
    /****************** ОТЛАДКА ****************************************/
    if ($bg_bibfers_option['debug']) {
        error_log(" Всего патернов : " . $i . "\n", 3, $debug_file);
        $this_time = microtime(true) * 1000;
        $time = $this_time - $start_time;
        error_log("  * Обработка патернов: " . round($time, 2) . " мсек.\n", 3, $debug_file);
        $time = $this_time - $s_time;
        error_log(" Полное время : " . round($time, 2) . " мсек.\n\n", 3, $debug_file);
        $start_time = $this_time;
    }
    /*******************************************************************/
    return $txt;
}
Пример #2
0
function bg_bibfers_bible_search($atts)
{
    extract(shortcode_atts(array('context' => 'get', 'book' => '', 'ch' => '1-999', 'type' => 'b_verses', 'lang' => '', 'prll' => ''), $atts));
    // Если $context задано значение "get", то получаем $context из ссылки
    if ($context == "get") {
        $context = $_GET["bs"];
        $book = $_GET["book"];
        $ch = $_GET["ch"];
        if ($ch == "") {
            $ch = "1-999";
        }
        $l = $_GET["lang"];
        if ($l != "") {
            $lang = $l;
        }
        $prll = $_GET["prll"];
        if (!isset($_GET["bs"]) && !isset($_GET["book"])) {
            $keys = array_keys($_GET);
            $context = $keys[0];
            $context = str_replace('_', ' ', $context);
            $context = trim($context);
            if ($context == "ch" || $context == "type" || $context == "lang" || $context == "prll") {
                $context = '';
            }
        }
    }
    if ($book) {
        $book = bg_bibfers_getBook($book);
        $context = $book . $ch;
    }
    $context = trim($context);
    if (!$context) {
        return "";
    }
    $quote = bg_bibfers_bible_proc($context, $type, $lang, $prll);
    if (!$quote || $quote == $context) {
        $quote = bg_bibfers_search_result($context, $type, $lang, $prll);
    }
    if ($quote != "") {
        $class_val = get_option('bg_bibfers_class');
        if ($class_val == "") {
            $class_val = 'bg_bibfers';
        }
        $quote = "<span class='" . $class_val . "'>" . $quote . "</span>";
    }
    return "{$quote}";
}
Пример #3
0
function bg_bibfers_linksKey($linksKey, $lang)
{
    global $bg_bibfers_option;
    global $bg_bibfers_chapter, $bg_bibfers_ch;
    global $bg_bibfers_url, $bg_bibfers_bookTitle, $bg_bibfers_shortTitle, $bg_bibfers_bookFile;
    $quote = $linksKey;
    $template = "/(\\d?\\s*[А-яA-z]{2,8})(\\.*|\\s*)(\\d+\\,\\s*\\d+)/ui";
    preg_match($template, $linksKey, $mt);
    $cn = count($mt);
    if ($cn > 0) {
        $title = preg_replace("/\\s/u", '', $mt[1]);
        // Убираем пробельные символы, включая пробел, табуляцию, переводы строки
        $title = bg_bibfers_getBook($title);
        // Стандартное обозначение книги
        $chapter = preg_replace("/\\s/u", '', $mt[3]);
        // и другие юникодные пробельные символы
        $chapter = preg_replace("/\\,/u", ':', $chapter);
        // Если глава отделена запятой, заменяем ее на двоеточие.
        if ($title != "") {
            if (!$lang) {
                $lang = set_bible_lang();
            }
            $quote = bg_bibfers_get_url($title, $chapter, '&#128279;' . $bg_bibfers_shortTitle[$title] . '&nbsp;' . $chapter . ' ', $lang);
        }
    }
    return $quote;
}