forked from VBog/Bg-Orthodox-Calendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbg_ortcal.php
322 lines (292 loc) · 16.4 KB
/
bg_ortcal.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<?php
/*
Plugin Name: Bg Orthodox Calendar
Plugin URI: http://bogaiskov.ru/plugin-orthodox-calendar/
Description: Плагин выводит на экран православный календарь на год: дата по старому стилю, праздники по типикону (от двунадесятых до вседневных), памятные даты, дни поминовения усопших, дни почитания икон, посты и сплошные седмицы.
Author: Vadim Bogaiskov
Version: 0.8.0
Author URI: http://bogaiskov.ru
*/
/* Copyright 2014 Vadim Bogaiskov (email: [email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*****************************************************************************************
Блок загрузки плагина
******************************************************************************************/
// Запрет прямого запуска скрипта
if ( !defined('ABSPATH') ) {
die( 'Sorry, you are not allowed to access this page directly.' );
}
define('BG_ORTCAL_VERSION', '0.8.0');
// Подключаем дополнительные модули
include_once('includes/settings.php');
include_once('includes/days.php');
// Динамическая Таблица стилей для плагина
function bg_ortcal_frontend_styles () {
wp_enqueue_style( "bg_ortcal_colors", plugins_url( '/css/colors.php', plugin_basename(__FILE__) ), array() , BG_ORTCAL_VERSION );
}
add_action( 'wp_enqueue_scripts' , 'bg_ortcal_frontend_styles' );
add_action( 'admin_enqueue_scripts' , 'bg_ortcal_frontend_styles' );
// JS скрипты
function bg_ortcal_frontend_scripts () {
wp_enqueue_script( 'bg_ortcal_days', plugins_url( 'js/bg_ortcal_days.js' , __FILE__ ), false, BG_ORTCAL_VERSION, true );
wp_enqueue_script( 'bg_ortcal_names', plugins_url( 'js/bg_ortcal_names.js' , __FILE__ ), false, BG_ORTCAL_VERSION, true );
wp_enqueue_script( 'bg_ortcal_year', plugins_url( 'js/bg_ortcal_year.js' , __FILE__ ), false, BG_ORTCAL_VERSION, true );
wp_enqueue_script( 'bg_ortcal_init', plugins_url( 'js/bg_ortcal_init.js' , __FILE__ ), false, BG_ORTCAL_VERSION, true );
}
function bg_ortcal_js_options () {
$customXML_val=get_option( "bg_ortcal_customXML" );
$popmenu1_val = get_option( "bg_ortcal_popmenu1" );
$popmenu2_val = get_option( "bg_ortcal_popmenu2" );
$popmenu3_val = get_option( "bg_ortcal_popmenu3" );
$popmenu101_val = get_option( "bg_ortcal_popmenu101" );
$popmenu1001_val = get_option( "bg_ortcal_popmenu1001" );
$popmenu1002_val = get_option( "bg_ortcal_popmenu1002" );
$dblClick_val = get_option( "bg_ortcal_dblClick" );
?>
<script>
var baseUrl = "<?php echo plugins_url( '/' , __FILE__ ); ?>";
var bg_ortcal_customXML = "<?php if (is_file(ABSPATH."/".$customXML_val)) echo site_url()."/".$customXML_val; ?>";
var popmenu =[];
<?php
$i=0;
if ($popmenu1_val) {echo 'popmenu['.$i.']={name:"'.$popmenu1_val.'", type: 1};'; $i++;}
if ($popmenu2_val) {echo 'popmenu['.$i.']={name: "'.$popmenu2_val.'", type: 2};';$i++;}
if ($popmenu3_val) {echo 'popmenu['.$i.']={name: "'.$popmenu3_val.'", type: 3};';$i++;}
if ($popmenu101_val) {echo 'popmenu['.$i.']={name: "'.$popmenu101_val.'", type: 101};';$i++;}
if ($popmenu1001_val) {echo 'popmenu['.$i.']={name: "'.$popmenu1001_val.'", type: 1001};';$i++;}
if ($popmenu1002_val) {echo 'popmenu['.$i.']={name: "'.$popmenu1002_val.'", type: 1002};';$i++;}
?>
var dblClick = <?php echo get_option( "bg_ortcal_dblClick" ); ?>; // Пункт меню при двойном щелчке по дате (варианты см. выше)
</script>
<?php
}
if ( !is_admin() ) {
bg_ortcal_options_ini (); // Параметры по умолчанию
add_action( 'wp_enqueue_scripts' , 'bg_ortcal_frontend_scripts' );
add_action( 'wp_head' , 'bg_ortcal_js_options' );
}
if ( defined('ABSPATH') && defined('WPINC') ) {
// Регистрируем крючок для добавления меню администратора
add_action('admin_menu', 'bg_ortcal_add_pages');
// Регистрируем крючок на удаление плагина
if (function_exists('register_uninstall_hook')) {
register_uninstall_hook(__FILE__, 'bg_ortcal_deinstall');
}
// Регистрируем шорт-код ortcal_button
add_shortcode( 'ortcal_button', 'bg_ortcal_button' );
add_shortcode( 'DayInfo', 'bg_ortcal_DayInfo' ); // Для совместимости с версией 0.4
add_shortcode( 'OldStyle', 'bg_ortcal_OldStyle' ); // Для совместимости с версией 0.4
add_shortcode( 'Sedmica', 'bg_ortcal_Sedmica' ); // Для совместимости с версией 0.4
add_shortcode( 'dayinfo', 'bg_ortcal_DayInfo' );
add_shortcode( 'monthinfo', 'bg_ortcal_MonthInfo' );
add_shortcode( 'oldstyle', 'bg_ortcal_OldStyle' );
add_shortcode( 'sedmica', 'bg_ortcal_Sedmica' );
add_shortcode( 'readings', 'bg_ortcal_Readings' );
add_shortcode( 'dayinfo_all', 'bg_ortcal_DayInfo_all' );
add_shortcode( 'upcoming_events', 'bg_ortcal_UpcomingEvents' );
}
// Функция действия перед крючком добавления меню
function bg_ortcal_add_pages() {
// Добавим новое подменю в раздел Параметры
add_options_page( 'Православный календарь', 'Православный календарь', 'manage_options', __FILE__, 'bg_ortcal_options_page');
}
/*****************************************************************************************
Функции запуска плагина
******************************************************************************************/
// Функция обработки шорт-кода ortcal_button
function bg_ortcal_button($atts) {
extract( shortcode_atts( array(
'val' => ' Календарь на год '
), $atts ) );
bg_ortcal_load_xml();
global $events;
static $is_loaded = false;
$quote = "<button onClick='bscal.show();'>".$val."</button>";
if (!$is_loaded) {
$quote = "<script>events=".json_encode($events)."</script>".$quote;
$is_loaded = true;
}
return "{$quote}";
}
// Функция обработки шорт-кода DayInfo
function bg_ortcal_DayInfo($atts) {
extract( shortcode_atts( array(
'day' => '', // День (по умолчанию - сегодня)
'month' => '', // Месяц (по умолчанию - сегодня)
'year' => '', // Год (по умолчанию - сегодня)
'date' => 'l, j F Y г. ', // Формат даты по нов. стилю
'old' => '(j F ст.ст.)', // Формат даты по ст. стилю
'sedmica' => 'on', // Седмица
'memory' => 'on', // Памятные дни
'honor' => 'on', // Дни поминовения усопших
'holiday' => 7, // Праздники (уровень значимости)
'img' => 'on', // Значок праздника по Типикону
'saints' => 'off', // Святые
'martyrs' => 'off', // Новомученники и исповедники российские
'icons' => 'off', // Дни почитания икон Богоматери
'posts' => 'off', // Постные дни
'noglans' => 'off', // Дни, в которые браковенчание не совершается
'readings' => 'off', // Чтения Апостола и Евангелие
'links' => 'on', // Ссылки и цитаты
), $atts ) );
return showDayInfo ( $day, $month, $year, $date, $old, $sedmica, $memory, $honor, $holiday, $img, $saints, $martyrs, $icons, $posts, $noglans, $readings, $links );
}
// Функция обработки шорт-кода YearInfo
function bg_ortcal_MonthInfo($atts) {
extract( shortcode_atts( array(
'month' => '', // Месяц (по умолчанию - сегодня)
'year' => '', // Год (по умолчанию - сегодня)
'date' => 'l, j F Y г. ', // Формат даты по нов. стилю
'old' => '(j F ст.ст.)', // Формат даты по ст. стилю
'sedmica' => 'on', // Седмица
'memory' => 'on', // Памятные дни
'honor' => 'on', // Дни поминовения усопших
'holiday' => 7, // Праздники (уровень значимости)
'img' => 'on', // Значок праздника по Типикону
'saints' => 'off', // Святые
'martyrs' => 'off', // Новомученники и исповедники российские
'icons' => 'off', // Дни почитания икон Богоматери
'posts' => 'off', // Постные дни
'noglans' => 'off', // Дни, в которые браковенчание не совершается
'readings' => 'off', // Чтения Апостола и Евангелие
'links' => 'on', // Ссылки и цитаты
), $atts ) );
$quote = "";
if ($year == '') $year = date('Y');
if ($month == '' || ($month < 1 || $month > 12)) $month = date('m');
$days = numDays ($month, $year);
for ( $day = 1; $day <= $days; $day++) {
$quote .= showDayInfo ( $day, $month, $year, $date, $old, $sedmica, $memory, $honor, $holiday, $img, $saints, $martyrs, $icons, $posts, $noglans, $readings, $links )."<hr>";
}
return "{$quote}";
}
// Функция обработки шорт-кода OldStyle
function bg_ortcal_OldStyle($atts) {
extract( shortcode_atts( array(
'day' => '',
'month' => '',
'year' => '',
'old' => 'l, j F Y г. ст.ст.',
), $atts ) );
if ($year == '') $year = date('Y');
if ($month == '' || ($month < 1 || $month > 12)) $month = date('m');
if ($day == '') $day = date('d');
$days = numDays ($month, $year);
if ($day < 1) $day = 1; // если день задан меньше единицы то первое число
if ($day > $days) $day = $days; // а если дата больше количества дней в месяце, последний день месяца
$wd = date('w', mktime(0, 0, 0, $month, $day, $year));
$quote = '<span class="bg_ortcal_OldStyle_old'.(($wd==0)?' bg_ortcal_OldStyle_sunday':'').'">'.oldStyle ($old, $month, $day, $year).'</span>';
return "{$quote}";
}
// Функция обработки шорт-кода Sedmica
function bg_ortcal_Sedmica($atts) {
extract( shortcode_atts( array(
'day' => '',
'month' => '',
'year' => '',
), $atts ) );
if ($year == '') $year = date('Y');
if ($month == '' || ($month < 1 || $month > 12)) $month = date('m');
if ($day == '') $day = date('d');
$days = numDays ($month, $year);
if ($day < 1) $day = 1; // если день задан меньше единицы то первое число
if ($day > $days) $day = $days; // а если дата больше количества дней в месяце, последний день месяца
$wd = date('w', mktime(0, 0, 0, $month, $day, $year));
$quote = '<span class="bg_ortcal_Sedmica_sedmica'.(($wd==0)?' bg_ortcal_Sedmica_sunday':'').'">'.sedmica ($month, $day, $year).'</span>';
return "{$quote}";
}
// Функция обработки шорт-кода Readings
function bg_ortcal_Readings ($atts) {
extract( shortcode_atts( array(
'day' => '', // День (по умолчанию - сегодня)
'month' => '', // Месяц (по умолчанию - сегодня)
'year' => '', // Год (по умолчанию - сегодня)
'readings' => 'G', // Чтения Апостола и Евангелие
'links' => 't_verses', // Ссылки и цитаты
), $atts ) );
return showDayInfo ( $day, $month, $year, 'off', 'off', 'off', 'off', 'off', 'off', 'off', 'off', 'off', 'off', 'off', 'off', $readings, $links );
}
// Функция обработки шорт-кода DayInfo_all
function bg_ortcal_DayInfo_all ($atts) {
extract( shortcode_atts( array(
'day' => '', // День (по умолчанию - сегодня)
'month' => '', // Месяц (по умолчанию - сегодня)
'year' => '', // Год (по умолчанию - сегодня)
), $atts ) );
return showDayInfo ( $day, $month, $year, 'l, j F Y г. ', '(j F ст.ст.)', 'on', 'on', 'on', 'on', 'on', '<b>День памяти святых:</b><br>', '<b>День памяти исповедников и новомучеников российских:</b><br>', '<b>День почитания икон Божией Матери:</b><br>', '<hr />', 'on', '<hr /><b>Чтения дня:</b><br>', 'on' );
// $quote .= showDayInfo ( $day, $month, $year, $date, $old, $sedmica, $memory, $honor, $holiday, $img, $saints, $martyrs, $icons, $posts, $noglans, $readings, $links )."<hr>";
}
// Функция обработки шорт-кода UpcomingEvents
function bg_ortcal_UpcomingEvents($atts) {
extract( shortcode_atts( array(
'numdays' => 14, // Количество дней поиска ближайших событий
'date' => 'j F ', // Формат даты по нов. стилю
'old' => '(j F ст.ст.)', // Формат даты по ст. стилю
'sedmica' => 'off', // Седмица
'memory' => 'off', // Памятные дни
'honor' => 'on', // Дни поминовения усопших
'holiday' => 2, // Праздники (уровень значимости)
'img' => 'on', // Значок праздника по Типикону
'saints' => 'off', // Святые
'martyrs' => 'off', // Новомученники и исповедники российские
'icons' => 'off', // Дни почитания икон Богоматери
'posts' => 'off', // Постные дни
'noglans' => 'off', // Дни, в которые браковенчание не совершается
'readings' => 'off', // Чтения Апостола и Евангелие
'links' => 'off', // Ссылки и цитаты
), $atts ) );
$key='up_'.date("m.d.y").md5(json_encode($atts));
if(false===($t=wp_cache_get($key,'bg-ortho-cal'))) {
$day = ''; // День (по умолчанию - сегодня)
$month = ''; // Месяц (по умолчанию - сегодня)
$year = ''; // Год (по умолчанию - сегодня)
if ($numdays < 1) $numdays = 14;
$t = "";
for ($n = 0; $n < $numdays; $n++) {
$d = "+" . ($n + 1);
$tt = showDayInfo($d, $month, $year, "", "", $sedmica, $memory, $honor, $holiday, $img, $saints, $martyrs, $icons, $posts, $noglans, $readings, $links);
if ($tt) $t .= showDayInfo($d, $month, $year, $date, $old, $sedmica, $memory, $honor, $holiday, $img, $saints, $martyrs, $icons, $posts, $noglans, $readings, $links);
}
wp_cache_set($key,$t,'bg-ortho-cal',12*3600);
}
return $t;
}
// Определить версию плагина
function bg_ortcal_get_plugin_version() {
$plugin_data = get_plugin_data( __FILE__ );
return $plugin_data['Version'];
}
function bg_ortcal_load_xml() {
if(false===($events=wp_cache_get('bg-orthodox-calendar-events','bg-ortho-cal'))) {
// Загружаем в память базу данных событий из XML
$plugins_dir = dirname(__FILE__) . '/MemoryDays.xml';
$xml = getXML($plugins_dir);
if ($xml) $events = $xml["event"];
else $events = false;
if ($events) {
$customXML_val = get_option("bg_ortcal_customXML");
if (is_file(ABSPATH . $customXML_val)) {
$custom_xml = getXML(ABSPATH . $customXML_val);
if ($custom_xml) {
$custom_events = $custom_xml["event"];
if ($custom_events) {
$events = array_merge($custom_events, $events);
}
}
}
}
wp_cache_set('bg-orthodox-calendar-events',$events,'bg-ortho-cal',3600);
}
return $events;
}