Files
vij/src/calend-block.php

133 lines
3.7 KiB
PHP
Raw Normal View History

2021-10-31 13:01:31 +03:00
<?php
2021-11-15 14:22:23 +03:00
//setlocale(LC_ALL, 'ru_RU');
//date_default_timezone_set('Europe/Moscow');
2021-11-01 02:22:21 +03:00
2021-10-31 13:01:31 +03:00
function calend_block($month, $year, $script=false){
2021-11-20 15:24:05 +03:00
if (strlen($month) == 1){
$str_month = "0$month";
}
else{
$str_month = "$month";
}
2021-11-01 02:22:21 +03:00
$find_sql = "
SELECT `post_id`
FROM `wp_postmeta`
2021-11-20 15:24:05 +03:00
WHERE `meta_key` = 'startevent' AND `meta_value` BETWEEN '$year-$str_month-01T00:00:00' AND '$year-$str_month-31T23:59:59'
2021-11-01 02:22:21 +03:00
";
$items = db_get($find_sql);
$ins = str_to_in($items);
if ($ins !== '') {
$posts = db_get("
SELECT ID, post_date, post_title FROM `wp_posts` WHERE ID IN ($ins)
");
}
/** $args = array(
2021-10-31 13:01:31 +03:00
'numberposts' => -1,
'category' => 61, // 61 - мероприятия
2021-11-01 02:22:21 +03:00
'meta_query' => array(
2021-10-31 13:01:31 +03:00
array(
2021-11-01 02:22:21 +03:00
'key' => 'startevent',
'value' => array( "$year-$month-01T00:00:00", "$year-$month-31T23:59:59" ),
'compare' => 'BETWEEN',
'type' => 'DATE'
),
),
2021-10-31 13:01:31 +03:00
'post_type' => 'post',
'suppress_filters' => true, // подавление работы фильтров изменения SQL запроса
2021-11-01 02:22:21 +03:00
);*/
$args = array(
'numberposts' => -1,
'post__in' => $ins
2021-10-31 13:01:31 +03:00
);
2021-11-01 02:22:21 +03:00
//$posts = get_posts($args);
2021-10-31 13:01:31 +03:00
$events = [];
2021-11-01 02:22:21 +03:00
if (is_array($posts)){
2021-10-31 13:01:31 +03:00
2021-11-01 02:22:21 +03:00
foreach ($posts as $post){
$eventdate = get_post_meta($post['ID'], 'startevent', true);
2021-11-20 15:24:05 +03:00
$key = date('d.n.Y', strtotime($eventdate));
2021-11-01 02:22:21 +03:00
$events[$key]['text'] = $post['post_title'];
$events[$key]['link'] = get_permalink($post['ID']);
}
2021-10-31 13:01:31 +03:00
}?>
<div id="event-calendar">
<?=Calendar::getMonth(date($month), date($year), $events);?>
</div>
<?php if ($script){?>
<script>
var calend_link_base = "<?=get_site_url()?>/wp-content/themes/vij/src/eventcalendar.php";
var calend_curr_year = "<?=$year?>";
var calend_curr_month = "<?=$month?>";
function calend_prev_month(){
load_calendar_month(type = 'prev');
}
function calend_next_month(){
load_calendar_month(type = 'next');
}
function load_calendar_month(type = 'next'){
if (type == 'next'){
if (calend_curr_month == 12 ){
calend_curr_month = 1;
calend_curr_year = parseInt(calend_curr_year) + 1;
}
else {
calend_curr_month = parseInt(calend_curr_month) + 1;
}
}
else if (type == 'prev'){
if (calend_curr_month == 1 ){
calend_curr_month = 12;
calend_curr_year = parseInt(calend_curr_year) - 1;
}
else {
calend_curr_month = parseInt(calend_curr_month) - 1;
}
}
$currlink = calend_link_base + '?year=' + calend_curr_year + '&month=' + calend_curr_month;
fetch($currlink).then(function (response) {
return response.text();
}).then(function (html) {
document.getElementById('event-calendar').innerHTML = html;
}).catch(function (err) {
console.warn('Something went wrong.', err);
});
}
</script>
<?}
}