add calendar events
This commit is contained in:
134
functions.php
134
functions.php
@@ -1,6 +1,11 @@
|
||||
<?php
|
||||
|
||||
define('IMGURL', 'http://img.vetandlife.ru/');
|
||||
define("COOK_GOLOS", "_ya_id_76543_w");
|
||||
define("COOK_VALUE", "7895");
|
||||
|
||||
require get_template_directory().'/src/calend-block.php';
|
||||
require get_template_directory().'/src/calendar.php';
|
||||
|
||||
# регистрируем меню
|
||||
register_nav_menus(array(
|
||||
@@ -83,29 +88,35 @@ function _U2RFC822($date) {
|
||||
}
|
||||
|
||||
|
||||
add_action( 'save_post', 'prefix_save_post' );
|
||||
|
||||
function prefix_save_post( $post_id ){
|
||||
/**
|
||||
* плагин перевода в латиницу
|
||||
*/
|
||||
|
||||
if ($post_id < 15765)
|
||||
return; // старье не трогаем
|
||||
add_action( 'save_post', 'lat_slug' );
|
||||
|
||||
if ( wp_is_post_revision( $post_id ))
|
||||
return;
|
||||
function lat_slug( $post_id ){
|
||||
|
||||
remove_action( 'save_post_insert', 'prefix_save_post' );
|
||||
if ($post_id < 15789)
|
||||
return; // залитое старье не трогаем
|
||||
|
||||
// только публикованные
|
||||
if ( wp_is_post_revision( $post_id ) || get_post($post_id)->post_status != 'publish' )
|
||||
return;
|
||||
|
||||
$post = get_posts($post_id);
|
||||
$name = $post[0]->post_name;
|
||||
// $newname = vij_slug($name);
|
||||
$name = urldecode($post[0]->post_name);
|
||||
|
||||
file_put_contents("/vhosts/logs/translit.log", "$post_id: $name\n", FILE_APPEND);
|
||||
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(
|
||||
@@ -144,22 +155,100 @@ function vij_slug($slug) {
|
||||
'Я' => 'Ya', 'я' => 'ya'
|
||||
);
|
||||
|
||||
$newslug = strtr($slug, $replace);
|
||||
|
||||
|
||||
|
||||
|
||||
return $newslug;
|
||||
|
||||
//return strtr($slug, $replace);
|
||||
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 view ($view, $data = array(), $layer = null){
|
||||
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();
|
||||
|
||||
@@ -174,4 +263,5 @@ function view ($view, $data = array(), $layer = null){
|
||||
|
||||
return trim(ob_get_clean());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user