This repository has been archived by the owner on Aug 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
events-calendar.php
278 lines (243 loc) · 10.2 KB
/
events-calendar.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
<?php
/*
Plugin Name: WP Events Calendar
Plugin URI: http://www.ugoku.nl/
Description: There are options under the widget options to specify the view of the calendar in the sidebar. The widget can be a list for upcoming events or a calendar. If you do not have a widget ready theme then you can place `<?php SidebarEventsCalendar();?>`, or `<?php SidebarEventsList();?>` for an event list, in the sidebar.php file of your theme. If you want to display a large calendar in a post or a page, simply place `[events-calendar-large]` in the html of the post or page. Make sure to leave off the quotes.
Version: 7.0
Author: Ugoku, based on code by Luke Howell
Author URI: http://www.ugoku.nl/
Licence: GPLv3 {@link http://www.gnu.org/licenses/gpl}
*/
/** Set timezone **/
if (function_exists ('date_default_timezone_set'))
date_default_timezone_set(get_option('timezone_string'));
/** Events-Calendar version */
define('EVENTSCALENDARVERS', 'Version: 7.0');
// Paths
define('EVENTSCALENDARPATH', ABSPATH . 'wp-content/plugins/events-calendar');
define('EVENTSCALENDARCLASSPATH', EVENTSCALENDARPATH);
define('ABSWPINCLUDE', ABSPATH.WPINC);
// URLS
define('EVENTSCALENDARURL', get_option('siteurl') . '/wp-content/plugins/events-calendar');
define('EVENTSCALENDARJSURL', EVENTSCALENDARURL.'/js');
define('EVENTSCALENDARCSSURL', EVENTSCALENDARURL.'/css');
define('EVENTSCALENDARIMAGESURL', EVENTSCALENDARURL.'/images');
require_once(EVENTSCALENDARCLASSPATH . '/ec_day.class.php');
require_once(EVENTSCALENDARCLASSPATH . '/ec_calendar.class.php');
require_once(EVENTSCALENDARCLASSPATH . '/ec_db.class.php');
require_once(EVENTSCALENDARCLASSPATH . '/ec_widget.class.php');
require_once(EVENTSCALENDARCLASSPATH . '/ec_management.class.php');
require_once(ABSPATH.'wp-includes/pluggable.php');
/** Init Localisation */
load_default_textdomain();
load_plugin_textdomain('events-calendar', PLUGINDIR . '/' . dirname(plugin_basename(__FILE__)) . '/lang');
/** DatePicker localisation */
$locale = get_locale();
$loc_lang = explode("_",$locale);
$loc_lang = $loc_lang[0];
if (!in_array ($loc_lang, array('ar','bg','ca','cs','da','de','es','fi','fr','he','hu','hy','id','is','it','ja','ko','lt','lv','nl','no','pl','ro','ru','sk','sv','th','tr','uk')))
{
$loc_lang='en';
}
if (isset ($_GET['EC_view']) && $_GET['EC_view'] == 'day')
{
EC_send_headers();
$EC_date = date('Y-m-d', mktime(0, 0, 0, $_GET['EC_month'], $_GET['EC_day'], $_GET['EC_year']));
$day = new EC_Day();
$day->display($EC_date);
exit;
}
// Called from the large calendar through AJAX.
// We need to send a header to make sure we respect the blog charset.
if (isset ($_GET['EC_action']) && $_GET['EC_action'] == 'switchMonth')
{
EC_send_headers();
$calendar = new EC_Calendar();
$calendar->displayWidget($_GET['EC_year'], $_GET['EC_month']);
exit;
}
// Called from the large calendar through AJAX.
// We need to send a header to make sure we respect the blog charset.
if (isset ($_GET['EC_action']) && $_GET['EC_action'] == 'switchMonthLarge')
{
EC_send_headers();
$calendar = new EC_Calendar();
$calendar->displayLarge($_GET['EC_year'], $_GET['EC_month']);
exit;
}
if (isset ($_GET['EC_action']) && $_GET['EC_action'] == 'ajaxDelete')
{
$db = new EC_DB();
$db->deleteEvent($_GET['EC_id']);
exit;
}
// Sends headers needed when AJAX is used.
function EC_send_headers()
{
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Pragma: no-cache"); // HTTP/1.0
header("Content-Type: text/html; charset=" . get_option('blog_charset'));
}
/**
* Initializes the Events Calendar plugin.
*
* The function first check to see if we are in the admin panel.
* If we're not, it enqueues the jQuery plugins needed by WPEC: tooltip and thickbox.
* Then it registers the widget and the widget control with WordPress.
* @uses EC_Widget
* @uses EC_Management
*/
/* updated INIT function for EC6.6.1 patch by Byron Rode */
function EventsCalendarINIT()
{
$options = get_option('optionsEventsCalendar');
$inadmin = is_admin();
if (!$inadmin)
{
if($options['disableTooltips'] !== 'yes')
{
wp_enqueue_script('jquerytooltip', plugin_dir_url(__FILE__) . 'js/jquery.tooltip.min.js', array('jquery'), '1.3');
}
wp_enqueue_script('thickbox');
}
// Always register both the widget and widget control objects
// in case there are dependencies between the two.
$widget = new EC_Widget();
$management = new EC_Management();
wp_register_sidebar_widget('wpec_display', __('Events Calendar','events-calendar'), array(&$widget, 'display'));
wp_register_widget_control('wpec_control', __('Events Calendar','events-calendar'), array(&$management, 'widgetControl'));
}
/**
* Initializes the Events Calendar admin panel.
* The function creates a new menu and enqueues a few jquery plugins:
* tooltip, ui.core, ui.datepicker and its language file, clockpicker,
*
* @uses EC_Management
*/
function EventsCalendarManagementINIT()
{
$options = get_option ('optionsEventsCalendar');
$EC_userLevel = isset ($options['accessLevel']) && !empty ($options['accessLevel']) ? $options['accessLevel'] : 'level_10';
$management = new EC_Management();
add_menu_page(__('Events Calendar','events-calendar'), __('Events Calendar','events-calendar'), $EC_userLevel, 'events-calendar', array(&$management, 'display'), 'dashicons-calendar');
if(isset($_GET['page']) && strstr($_GET['page'], 'events-calendar'))
{
global $loc_lang;
wp_enqueue_script('jquerytooltip', '/wp-content/plugins/events-calendar/js/jquery.tooltip.min.js', array('jquery'), '1.3');
wp_enqueue_script('jqueryuicore', '/wp-content/plugins/events-calendar/js/ui.core.min.js', array('jquery'), '1.5.2');
wp_enqueue_script('jqueryuidatepicker', '/wp-content/plugins/events-calendar/js/ui.datepicker.js', array('jquery'), '1.5.2');
if ($loc_lang !== 'en')
wp_enqueue_script('jqueryuidatepickerlang', '/wp-content/plugins/events-calendar/js/i18n/ui.datepicker-' . $loc_lang . '.js', array('jquery'), '1.5.2');
wp_enqueue_script('jqueryclockpicker', '/wp-content/plugins/events-calendar/js/jquery.clockpick.min.js', array('jquery'), '1.2.6');
add_submenu_page('events-calendar', __('Events Calendar','events-calendar'), __('Calendar','events-calendar'), $EC_userLevel, 'events-calendar', '');
add_submenu_page('events-calendar', __('Events Calendar','events-calendar'), __('Add Event','events-calendar'), $EC_userLevel, '#addEventform', '');
add_submenu_page('events-calendar', __('Events Calendar Options','events-calendar'), __('Options','events-calendar'), $EC_userLevel, 'events-calendar-options', array(&$management, 'calendarOptions'));
}
}
/**
* Loads the stylesheets and the jQuery library.
* The function generates a call to jQuery,noConflict() and passes it the jQuery
* Extreme Flag that can be set/unset in the admin panel.
* The jQuery object is stored in ecd.jq which will then be used by the plugin.
*/
function EventsCalendarHeaderScript()
{
?>
<!-- Start of script generated by Events Calendar -->
<link type="text/css" rel="stylesheet" href="<?php bloginfo('wpurl'); ?>/wp-includes/js/thickbox/thickbox.css">
<link type="text/css" rel="stylesheet" href="<?php echo EVENTSCALENDARCSSURL; ?>/events-calendar.css">
<?php
require_once(ABSPATH . 'wp-admin/includes/admin.php');
// jQuery DOM extreme protection management
$options = get_option('optionsEventsCalendar');
echo '<script>';
echo 'var ecd = {};';
echo 'ecd.jq = jQuery.noConflict(' . $options['jqueryextremstatus'] . ');';
echo '</script>';
echo "<!-- End of script generated by Events Calendar -->";
}
/**
* Loads the needed stylesheets for the admin panel.
*/
function EventsCalendarAdminHeaderScript()
{
if (isset($_GET['page']) && $_GET['page'] == 'events-calendar')
{
?>
<link type="text/css" rel="stylesheet" href="<?php echo EVENTSCALENDARCSSURL; ?>/events-calendar-management.css">
<link type="text/css" rel="stylesheet" href="<?php echo EVENTSCALENDARCSSURL; ?>/ui.datepicker.css">
<link type="text/css" rel="stylesheet" href="<?php echo EVENTSCALENDARCSSURL; ?>/clockpick.css">
<?php
}
}
/**
* Installs or upgrade the plugin on activation.
* This is why it is important to de-activate the plugin before
* upgrading it.
* @uses EC_DB
*/
function EventsCalendarActivated()
{
$db = new EC_DB();
$db->createTable();
$db->initOptions();
}
/**
* Either returns needle or the data before needle.
*
* This is used by the filterEventsCalendarLarge() function to get
* the content of a page before and after the short tag [[EventsCalendarLarge]]
*
* @param string $haystack page or post swhere the shrt tag lives
* @param string $needle the short tag
* @param bool $before_needle do we want the data before the short tag?
* @return string
*/
function ec_strstr($haystack, $needle, $before_needle=FALSE)
{
if (FALSE === ($pos = strpos($haystack, $needle)))
return FALSE;
if ($before_needle)
return substr($haystack, 0, $pos);
else
return substr($haystack, $pos + strlen($needle));
}
/* New function with updated function argument at the end of the function.
* @bool(true) - echo's out content1
* @bool(false) - returns content, works better for use in WP Shortcode
*/
function filterEventsCalendarLarge()
{
$calendar = new EC_Calendar();
return $calendar->displayLarge(date('Y'), date('m'), "", array(), 7, false);
}
/**
* Will display the small calendar in sidebar.
*
* This can be used by themes that are not widget ready.
*/
function SidebarEventsCalendar()
{
$calendar = new EC_Calendar();
$calendar->displayWidget(date('Y'), date('m'));
}
/**
* Will display an events list in sidebar.
*
* This can be used by themes that are not widget ready.
*
* @param int $num number of events to display. defaults to 5.
*/
function SidebarEventsList($num = 5)
{
$calendar = new EC_Calendar();
$calendar->displayEventList($num);
}
add_action('activate_events-calendar/events-calendar.php', 'EventsCalendarActivated');
add_action('init', 'EventsCalendarINIT');
add_action('admin_menu', 'EventsCalendarManagementINIT');
add_action('wp_head', 'EventsCalendarHeaderScript');
add_action('admin_head', 'EventsCalendarAdminHeaderScript');
add_shortcode('events-calendar-large', 'filterEventsCalendarLarge');