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| \\;)*)?(\\d?(\\s| \\;)*[А-яA-z]{2,8})((\\.|\\s| \\;)*)(\\d+((\\s| \\;)*[\\:\\,\\-—–](\\s| \\;)*\\d+)*)(\\s| \\;)*[\\]\\)]/ui"; // $template = "/(\\s| \\;)?\\(?\\[?((\\s| \\;)*см\\.?\\:?(\\s| \\;)*)?(\\d?(\\s| \\;)*[А-яA-z]{2,8})((\\.|\\s| \\;)*)(\\d+((\\s| \\;)*[\\:\\,\\-—–](\\s| \\;)*\\d+)*)(\\s| \\;)*[\\]\\)\\.]?/ui"; // $template = "/(\\s| \\;)?\\(?\\[?((\\s| \\;)*см\\.?\\:?(\\s| \\;)*)?(\\d?(\\s| \\;)*[А-яA-z]{2,8})((\\.|\\s| \\;)*)(\\d+((\\s| \\;)*[\\:\\;\\,\\.\\-—–](\\s| \\;)*\\d+)*)(\\s| \\;)*[\\]\\)\\.]?/ui"; // $template = "/(\\s| \\;)?\\(?\\[?((\\s| \\;)*см\\.?\\:?(\\s| \\;)*)?(\\d?(\\s| \\;)*[А-яA-z]{2,8})((\\.|\\s| \\;)*)(\\d+((\\s| \\;)*[\\:\\,\\.\\-—–](\\s| \\;)*\\d+)*)(\\s| \\;)*[\\]\\)(\\;|\\.)]?/ui"; // $template = "/(\\s| \\;)?\\(?\\[?((\\s| \\;)*см\\.?\\:?(\\s| \\;)*)?(\\d?(\\s| \\;)*[А-яA-z]{2,8})((\\.|\\s| \\;)*)(\\d+((\\s| \\;)*[\\:\\,\\.\\-—–](\\s| \\;)*\\d+)*)[(\\s| \\;)\\]\\)(\\;|\\.)]?/ui"; // $template = "/(\\s| \\;)?\\(?\\[?((\\s| \\;)*см\\.?\\:?(\\s| \\;)*)?([1-4]?(\\s| \\;)*[А-яёіїєґўЁІЇЄҐЎA-z\']{2,8})((\\.|\\s| \\;)*)(\\d+((\\s| \\;)*[\\:\\,\\.\\-‐‑‒–——―](\\s| \\;)*\\d+)*)[(\\s| \\;)\\]\\)(\\;|\\.)]?/uxi"; $sps = "(?:\\s|\\x{00A0}|\\x{00C2}|(?: ))"; $dashes = "(?:[\\x{2010}-\\x{2015}]|(̴[8-9];)|(̵[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]); // и другие юникодные пробельные символы, а также неразрывные пробелы $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; }
function bg_bibrefs_callback() { $title = $_GET["title"]; $chapter = $_GET["chapter"]; if (!$chapter) { $chapter = '1-999'; } $type = $_GET["type"]; $lang = $_GET["lang"]; if (!$type) { $type = 'verses'; } $expand_button = '<img src="' . plugins_url('/js/expand.png', __FILE__) . '" style="cursor:pointer; margin-right: 8px;" align="left" width=16 height=16 title1="' . __('Expand', 'bg_bibfers') . '" title2="' . __('Hide', 'bg_bibfers') . '" />'; echo $expand_button . bg_bibfers_getQuotes($title, $chapter, $type, $lang); die; }
$chapter = $_GET["chapter"]; if (!$chapter) { $chapter = '1-99'; } $type = $_GET["type"]; if (!$type) { $type = 'verses'; } // Подключаем WP и данные плагина include_once realpath(substr(__FILE__, 0, strpos(__FILE__, 'wp-content')) . 'wp-blog-header.php'); include_once '../../includes/quotes.php'; $class_val = get_option('bg_bibfers_class'); if ($class_val == "") { $class_val = 'bg_bibfers'; } // Формируем страницу get_header(); // Заголовок ?> <div id="content"> <span class='<?php echo $class_val; ?> '><?php echo bg_bibfers_getQuotes($title, $chapter, $type); ?> </span> </div> <?php get_footer(); // Подвал