528 lines
11 KiB
PHP
528 lines
11 KiB
PHP
<?php
|
||
|
||
use PHPMailer\PHPMailer\PHPMailer;
|
||
|
||
//setlocale(LC_ALL, 'ru_RU', 'ru_RU.UTF-8', 'ru', 'russian');
|
||
|
||
define('IMGURL', 'http://img.vetandlife.ru/');
|
||
define("COOK_GOLOS", "_ya_id_76543_w");
|
||
define("COOK_VALUE", "7895");
|
||
define('VIJ_CACHE', ABSPATH.'wp-content/themes/vij/cache/');
|
||
define('BASE_VIJ', ABSPATH.'wp-content/themes/vij/');
|
||
|
||
require ABSPATH.'/vendor/autoload.php';
|
||
|
||
|
||
require get_template_directory().'/src/calend-block.php';
|
||
require get_template_directory().'/src/calendar.php';
|
||
require get_template_directory().'/src/perevod.php';
|
||
require get_template_directory().'/lang.php';
|
||
|
||
//require ABSPATH.'vendor/masterforweb/db_lite/db_lite.php';
|
||
|
||
function vij_send_smtp_email( PHPMailer $phpmailer ) {
|
||
$phpmailer->isSMTP();
|
||
$phpmailer->Host = 'smtp.yandex.ru';
|
||
$phpmailer->SMTPAuth = true;
|
||
$phpmailer->Port = 465;
|
||
$phpmailer->Username = 'info@vetandlife.ru';
|
||
$phpmailer->Password = 'B9c8P6y9';
|
||
$phpmailer->SMTPSecure = 'ssl';
|
||
$phpmailer->From = 'info@vetandlife.ru';
|
||
$phpmailer->FromName = 'Ветеринария и жизнь';
|
||
}
|
||
|
||
add_action( 'phpmailer_init', 'vij_send_smtp_email' );
|
||
|
||
db_config(DB_NAME, 'mysql:host='.DB_HOST.';dbname='.DB_NAME, DB_USER, DB_PASSWORD);
|
||
|
||
# регистрируем меню
|
||
register_nav_menus(array(
|
||
'top' => 'Верхнее меню',
|
||
'bottom' => 'Нижнее меню',
|
||
'left' => 'Левое меню',
|
||
'mobile' => 'Мобильное меню'
|
||
));
|
||
|
||
# поддержка миниматюр
|
||
add_theme_support('post-thumbnails');
|
||
|
||
# регистрируем размеры миниатюр
|
||
add_image_size( 'left-thumb', 95, 84, true ); # для левой колонки
|
||
add_image_size( 'moread', 372, 216, true ); # читайте также
|
||
add_image_size( 'subscripts', 198, 145, true ); # рассылка
|
||
|
||
|
||
#add scripts
|
||
/**
|
||
function tutsplus_burger_menu_scripts() {
|
||
|
||
wp_enqueue_script( 'burger-menu-script', get_stylesheet_directory_uri() . '/scripts/burger-menu.js', array( 'jquery' ) );
|
||
|
||
}
|
||
add_action( 'wp_enqueue_scripts', 'tutsplus_burger_menu_scripts' );
|
||
*/
|
||
|
||
/** add mobile block */
|
||
function mob_block($template){
|
||
|
||
$subclass = " mob-lite";
|
||
include get_template_directory().$template;
|
||
|
||
}
|
||
|
||
|
||
//свой шаблон для категории
|
||
add_filter('category_template', function (){
|
||
|
||
$category = get_queried_object();
|
||
$parent_id = $category->category_parent; // ID родителя
|
||
|
||
$template = array(); //массив для поиска шаблонов
|
||
|
||
$templates[] = "category-{$category->slug}.php";
|
||
$templates[] = "category-{$category->term_id}.php";
|
||
|
||
if ($parent_id > 0){
|
||
|
||
$parent = get_category($parent_id);
|
||
$templates[] = "category-{$parent->slug}.php";
|
||
$templates[] = "category-{$parent->term_id}.php";
|
||
|
||
}
|
||
|
||
$templates[] = 'category.php';
|
||
|
||
return locate_template($templates);
|
||
|
||
|
||
});
|
||
|
||
|
||
//свой шаблон для категории
|
||
add_filter( 'single_template', function ( $single_template ) {
|
||
|
||
$category = (array) get_the_category();
|
||
|
||
foreach( $category as $cat ) {
|
||
|
||
if ( file_exists(TEMPLATEPATH . "/single-{$cat->term_id}.php") ){
|
||
return TEMPLATEPATH . "/single-{$cat->term_id}.php";
|
||
}
|
||
|
||
$parent_id = $cat->parent; // шаблон гл рубрики
|
||
|
||
if ($parent_id > 0){
|
||
$parent = get_category($parent_id);
|
||
if (file_exists(TEMPLATEPATH . "/single-{$parent->term_id}.php") )
|
||
return TEMPLATEPATH . "/single-{$parent->term_id}.php";
|
||
}
|
||
|
||
}
|
||
return $single_template;
|
||
|
||
|
||
}, PHP_INT_MAX, 2 );
|
||
|
||
|
||
|
||
function kuri_set($name = null, $value = null) {
|
||
|
||
static $vars = array();
|
||
|
||
if ($name == null)
|
||
return $vars;
|
||
|
||
if ($value == null){
|
||
if(array_key_exists($name, $vars))
|
||
return $vars[$name];
|
||
}
|
||
else
|
||
$vars[$name] = $value;
|
||
return false;
|
||
|
||
}
|
||
|
||
# время для rss
|
||
function _U2RFC822($date) {
|
||
|
||
$datatime = explode(" ",$date);
|
||
$dater = explode("-",$datatime[0]);
|
||
$timer = explode(":",$datatime[1]);
|
||
|
||
return date('r', mktime($timer[0], $timer[1], $timer[2], $dater[1], $dater[2], $dater[0]));
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* плагин перевода в латиницу
|
||
*/
|
||
|
||
add_action( 'save_post', 'lat_slug' );
|
||
|
||
function lat_slug( $post_id ){
|
||
|
||
if ($post_id < 15789)
|
||
return; // залитое старье не трогаем
|
||
|
||
// только публикованные || get_post($post_id)->post_status != 'publish'
|
||
if ( wp_is_post_revision( $post_id ))
|
||
return;
|
||
|
||
$post = get_posts($post_id);
|
||
$name = urldecode($post[0]->post_name);
|
||
|
||
if (isContainsRussianLetters($name)) { //если есть русские буковки
|
||
$title = express_slug($post[0]->post_title);
|
||
$latname = vij_slug($title);
|
||
remove_action( 'save_post', 'lat_slug' ); // избегаем зацикливания
|
||
wp_update_post( array( 'ID' => $post_id, 'post_name' => $latname ) );
|
||
add_action( 'save_post', 'lat_slug' );
|
||
}
|
||
|
||
|
||
}
|
||
|
||
function vij_slug($slug) {
|
||
$replace = array(
|
||
'А' => 'A', 'а' => 'a',
|
||
'Б' => 'B', 'б' => 'b',
|
||
'В' => 'V', 'в' => 'v',
|
||
'Г' => 'G', 'г' => 'g',
|
||
'Д' => 'D', 'д' => 'd',
|
||
'Е' => 'E', 'е' => 'e',
|
||
'Ё' => 'Jo', 'ё' => 'jo',
|
||
'Ж' => 'Zh', 'ж' => 'zh',
|
||
'З' => 'Z', 'з' => 'z',
|
||
'И' => 'I', 'и' => 'i',
|
||
'Й' => 'J', 'й' => 'j',
|
||
'К' => 'K', 'к' => 'k',
|
||
'Л' => 'L', 'л' => 'l',
|
||
'М' => 'M', 'м' => 'm',
|
||
'Н' => 'N', 'н' => 'n',
|
||
'О' => 'O', 'о' => 'o',
|
||
'П' => 'P', 'п' => 'p',
|
||
'Р' => 'R', 'р' => 'r',
|
||
'С' => 'S', 'с' => 's',
|
||
'Т' => 'T', 'т' => 't',
|
||
'У' => 'U', 'у' => 'u',
|
||
'Ф' => 'F', 'ф' => 'f',
|
||
'Х' => 'H', 'х' => 'h',
|
||
'Ц' => 'C', 'ц' => 'c',
|
||
'Ч' => 'Ch', 'ч' => 'ch',
|
||
'Ш' => 'Sh', 'ш' => 'sh',
|
||
'Щ' => 'Shh', 'щ' => 'shh',
|
||
'Ъ' => '', 'ъ' => '',
|
||
'Ы' => 'Y', 'ы' => 'y',
|
||
'Ь' => '', 'ь' => '',
|
||
'Э' => 'E', 'э' => 'e',
|
||
'Ю' => 'Ju', 'ю' => 'ju',
|
||
'Я' => 'Ya', 'я' => 'ya'
|
||
);
|
||
|
||
|
||
return strtr($slug, $replace);
|
||
|
||
|
||
}
|
||
|
||
|
||
function isContainsRussianLetters($text = false) {
|
||
if ($text !== "") {
|
||
$len = strlen($text)-1;
|
||
for ($i=0;$i<=$len;$i++) {
|
||
if (($i < $len) and (((($ord = ord(substr($text,$i,1))) == 208)
|
||
and (($ord2 = ord(substr($text,($i+1),1))) == 129)
|
||
or (($ord2 >= 144) and ($ord2 <= 191)))
|
||
or ((($ord = ord(substr($text,$i,1))) == 209)
|
||
and ($ord2 == 145) or (($ord2 >= 128)
|
||
and ($ord2 <= 143))))) {
|
||
//Поиск русских букв в UTF-8
|
||
return true;
|
||
} elseif (((($ord = ord(substr($text,$i,1))) >= 192)
|
||
and (($ord <= 255)) or ($ord == 168) or ($ord == 184))) {
|
||
//Поиск русских букв в ANSI
|
||
return true;
|
||
}
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
function eventdate_str($date){
|
||
|
||
|
||
$month = array(
|
||
|
||
"01" => "января",
|
||
"02" => "февраля",
|
||
"03" => "марта",
|
||
"04" => "апреля",
|
||
"05" => "мая",
|
||
"06" => "июня",
|
||
"07" => "июля",
|
||
"08" => "августа",
|
||
"09" => "сентября",
|
||
"10" => "октября",
|
||
"11" => "ноября",
|
||
"12" => "декабря"
|
||
|
||
);
|
||
|
||
|
||
$findT = strpos($date, 'T');
|
||
|
||
if ($findT){
|
||
$currdatetime = substr($date, 0, $findT);
|
||
}
|
||
else {
|
||
$currdatetime = $date;
|
||
}
|
||
|
||
$currdate = explode("-", $currdatetime);
|
||
|
||
|
||
return $currdate[2].' '.$month[$currdate[1]].' '.$currdate[0];
|
||
|
||
|
||
}
|
||
|
||
|
||
function express_slug($value){
|
||
|
||
|
||
$result = mb_strtolower(trim($value));
|
||
|
||
$arr = [
|
||
'$' => '',
|
||
' ' => '-',
|
||
'.' => '',
|
||
'+' => '',
|
||
'!' => '',
|
||
'*' => '',
|
||
'(' => '',
|
||
')' => '',
|
||
',' => '-',
|
||
'{' => '',
|
||
'}' => '',
|
||
'|' => '-',
|
||
'^' => '',
|
||
'~' => '',
|
||
'[' => '-',
|
||
']' => '-',
|
||
'`' => '',
|
||
'<' => '',
|
||
'>' => '',
|
||
'#' => '',
|
||
'%' => '',
|
||
'"' => '',
|
||
';' => '',
|
||
'/' => '',
|
||
'?' => '',
|
||
':' => '',
|
||
'@' => '',
|
||
'&' => '',
|
||
'=' => '',
|
||
'.' => '',
|
||
'«' => '',
|
||
'»' => '',
|
||
"'"=> ''
|
||
];
|
||
|
||
$result = strtr($result, $arr);
|
||
|
||
return $result;
|
||
|
||
}
|
||
|
||
|
||
function eventdate($val){
|
||
$posT = strpos($val, 'T');
|
||
|
||
if ($posT)
|
||
|
||
return $val;
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
*
|
||
*/
|
||
|
||
if (!function_exists('view')){
|
||
function view ($view, $data = array(), $layer = null){
|
||
|
||
ob_start();
|
||
|
||
if (is_array($data))
|
||
extract($data);
|
||
if ($layer !== null){
|
||
$content = view($view, $data);
|
||
require $layer;
|
||
}
|
||
else
|
||
require $view;
|
||
|
||
return trim(ob_get_clean());
|
||
|
||
}
|
||
}
|
||
|
||
|
||
function arr_to_in($items){
|
||
|
||
$in = array();
|
||
|
||
foreach ($items as $item){
|
||
|
||
$in[] = $item['post_id'];
|
||
}
|
||
|
||
return $in;
|
||
|
||
}
|
||
|
||
function str_to_in($items){
|
||
|
||
$in = '';
|
||
|
||
foreach ($items as $item){
|
||
|
||
if ($in !== '') {
|
||
$in .= ',';
|
||
}
|
||
|
||
|
||
$in .= $item['post_id'];
|
||
}
|
||
|
||
return $in;
|
||
|
||
}
|
||
|
||
|
||
add_filter( 'nav_menu_item_title', 'filter_nav_menu_item_title', 10, 4 );
|
||
function filter_nav_menu_item_title( $title, $item, $args, $depth ) {
|
||
|
||
$iconpath = TEMPLATEPATH.'/pub/menu/';
|
||
|
||
$cstart = false;
|
||
$cend = false;
|
||
|
||
$cstart = strpos($title, '<!--');
|
||
if ($cstart !== false){
|
||
$start = $cstart + 4;
|
||
$cend = strpos($title, '-->', $start + 1);
|
||
|
||
if ($cend !== false){
|
||
$svg = substr($title, $start, $cend - $start);
|
||
$svgfile = $iconpath.$svg.'.svg';
|
||
$svgcontent = file_get_contents( $svgfile);
|
||
|
||
if (file_exists( $svgfile )){
|
||
$result = str_replace("<!--$svg-->", $svgcontent , $title);
|
||
return $result;
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
}
|
||
|
||
return $title;
|
||
}
|
||
|
||
|
||
|
||
function lang_version(){
|
||
|
||
|
||
if (is_single()){
|
||
|
||
$current_cat = get_the_category( get_the_ID() )[0];
|
||
|
||
if ($current_cat->parent == 4782 or $current_cat->term_id == 4782 ){
|
||
return 'en';
|
||
}
|
||
|
||
}
|
||
|
||
elseif (is_category()){
|
||
$category = get_queried_object();
|
||
|
||
if ($category->parent == 4782 or $category->term_id == 4782 ){
|
||
return 'en';
|
||
}
|
||
|
||
}
|
||
elseif (is_page([17462, 17463, 17464])){
|
||
|
||
return 'en';
|
||
|
||
}
|
||
|
||
|
||
return 'ru';
|
||
|
||
|
||
}
|
||
|
||
function citata_title($percon){
|
||
|
||
$result = [];
|
||
$pos_zpt = strpos($percon, ',');
|
||
|
||
if ($pos_zpt) {
|
||
|
||
$result['percon'] = substr($percon, 0, $pos_zpt);
|
||
$result['status'] = substr($percon, $pos_zpt + 1);
|
||
|
||
}
|
||
else {
|
||
$result['percon'] = $citata;
|
||
}
|
||
|
||
|
||
return $result;
|
||
|
||
}
|
||
|
||
# helper find perevod author
|
||
function find_perevod($post_id){
|
||
|
||
$author = '';
|
||
|
||
$perevod_name = get_post_meta( $post_id, 'perevod_name', true );
|
||
if ( ! empty ( $perevod_name )){
|
||
$user_info = get_userdata($perevod_name);
|
||
if (isset($user_info->display_name)){
|
||
$author = $user_info->display_name;
|
||
}
|
||
}
|
||
|
||
if ($author !== ''){
|
||
return " / Translated by $author";
|
||
}
|
||
else {
|
||
return '';
|
||
}
|
||
|
||
|
||
}
|
||
|
||
add_action( 'pre_get_posts', function ($query) {
|
||
|
||
if ( ! is_admin() && $query->is_main_query() ) {
|
||
// не админка и основной цикл страницы
|
||
|
||
if ( is_category( 'arkhiv' ) ) {
|
||
$query->set( 'posts_per_page', 9 );
|
||
}
|
||
|
||
}
|
||
|
||
}); |