-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfullcalendar.php
More file actions
151 lines (137 loc) · 6.56 KB
/
fullcalendar.php
File metadata and controls
151 lines (137 loc) · 6.56 KB
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
<?php
/*
Plugin Name: fullcalendar
Plugin URI: https://ircf.fr
Description: Display and customize one or many Google calendars. This is just a Wordpress wrapper for the fullcalendar Open Source project
Version: 3.4.0
Author: IRCF
Author URI: https://ircf.fr/
*/
/* Copyright 2017 IRCF
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;
*/
// Default plugin options, may be modified in the Settings menu
$fullcalendar_default_options = array(
"head" => '',
"body" => '<div id="loading" style="display:none">Chargement en cours...</div>
<div id="calendar"></div>
<script type="text/javascript">
$(document).ready(function() {
$("#calendar").fullCalendar({
googleCalendarApiKey: "YOUR API KEY",
eventSources: [
{
googleCalendarId: "abcd1234@group.calendar.google.com",
className: "nice-event"
}
]
});
});
</script>'
);
// Admin menu
add_action('admin_menu', 'fullcalendar_menu');
function fullcalendar_menu() {
add_options_page('FullCalendar', 'FullCalendar', 'activate_plugins', 'fullcalendar', 'fullcalendar_options');
}
function fullcalendar_get_options($field=null){
global $fullcalendar_default_options;
$options = get_option('fullcalendar_options');
if (!is_array($options)) $options = array();
$options = array_merge($fullcalendar_default_options,$options);
if (isset($field)){
return $options[$field];
}else{
return $options;
}
}
function fullcalendar_options() {
global $fullcalendar_default_options;
$options = fullcalendar_get_options();
if (!is_admin()){
?><div class="error notice"><p><?=__('Sorry, only admin can edit fullcalendar options', 'fullcalendar_textdomain' )?></p></div><?php
return;
}
if(isset($_POST['Submit']) && check_admin_referer('fullcalendar_options')){
if ($_POST["Submit"] == __('Update', 'fullcalendar_textdomain' )){
foreach($_POST as $key => $value){
if (substr($key,0,13) == "fullcalendar_"){
$options[str_replace("fullcalendar_", "", sanitize_key($key))] = stripslashes($value); // value can be any HTML code
}
}
update_option('fullcalendar_options', $options);
echo '<div class="updated notice"><p><strong>'.__('Options saved', 'fullcalendar_textdomain' ).'</strong></p></div>';
}elseif ($_POST["Submit"] == __('Reset', 'fullcalendar_textdomain' )){
update_option('fullcalendar_options', $fullcalendar_default_options);
echo '<div class="updated notice"><p><strong>'.__('Options resetted', 'fullcalendar_textdomain' ).'</strong></p></div>';
}
}
?>
<div class="wrap">
<form method="post" name="options" target="_self">
<?php wp_nonce_field( 'fullcalendar_options' ); ?>
<h2><?=__('Configure FullCalendar', 'fullcalendar_textdomain' )?></h2>
<p><?=__('For the FullCalendar API documentation, please visit <a href="https://fullcalendar.io" target="_blank">fullcalendar.io</a>', 'fullcalendar_textdomain' )?></p>
<h3><?=__('Head template', 'fullcalendar_textdomain' )?></h3>
<p><?=__('<strong>WARNING : </strong> Setting the head template will remove the default FullCalendar JS+CSS loading.', 'fullcalendar_textdomain' )?></p>
<textarea name="fullcalendar_head" cols="100" rows="10"><?php echo $options['head']?></textarea>
<h3><?=__('Body template', 'fullcalendar_textdomain' )?></h3>
<p><?=__('Short code parameters [fullcalendar param1=valeur1 param2=valeur2] can be used with : %param1%, %param2% . These expressions will be replaced by their respective values in the HTML code.', 'fullcalendar_textdomain' )?></p>
<textarea name="fullcalendar_body" cols="100" rows="30"><?php echo $options['body']?></textarea>
<p class="submit">
<input type="submit" name="Submit" value="<?=__('Update', 'fullcalendar_textdomain' )?>" class="button-primary" />
<input type="submit" name="Submit" value="<?=__('Reset', 'fullcalendar_textdomain' )?>" class="button" />
</p>
</form>
</div>
<?php
}
// Replace placeholders "%whatever%" in a text
function fullcalendar_placeholders($text,$placeholders){
foreach($placeholders as $key=>$value){
$text = str_replace('%'.$key.'%',$value,$text);
}
return $text;
}
// Short code
// TODO Add TinyMCE shortcode button
function fullcalendar_body($atts) {
$options = fullcalendar_get_options();
$output = fullcalendar_placeholders($options['body'],$atts);
return $output;
}
add_shortcode('fullcalendar', 'fullcalendar_body');
// Enqueue scripts and styles
function fullcalendar_enqueue_scripts() {
// From CDN
//wp_enqueue_script('moment', '//cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment-with-locales.min.js', array('jquery'));
//wp_enqueue_script('fullcalendar', '//cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.4.0/fullcalendar.min.js', array('jquery','moment'));
//wp_enqueue_script('fullcalendar_gcal', '//cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.4.0/gcal.js', array('fullcalendar'));
//wp_enqueue_style('fullcalendar', '//cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.4.0/fullcalendar.min.css');
//wp_enqueue_style('fullcalendar_print', '//cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.4.0/fullcalendar.print.min.css', array(), null, 'print');
// From local
wp_enqueue_script('moment', plugin_dir_url( __FILE__ ) . 'lib/moment-with-locales.min.js', array('jquery'));
wp_enqueue_script('fullcalendar', plugin_dir_url( __FILE__ ) . 'lib/fullcalendar.min.js', array('jquery','moment'));
wp_enqueue_script('fullcalendar_gcal', plugin_dir_url( __FILE__ ) . 'lib/gcal.js', array('fullcalendar'));
wp_enqueue_style('fullcalendar', plugin_dir_url( __FILE__ ) . 'lib/fullcalendar.min.css');
wp_enqueue_style('fullcalendar_print', plugin_dir_url( __FILE__ ) . 'lib/fullcalendar.print.min.css', array(), null, 'print');
}
// Custom head template
function fullcalendar_head(){
$options = fullcalendar_get_options();
echo $options['head'];
}
if (fullcalendar_get_options('head') != ''){
add_action('wp_head', 'fullcalendar_head');
}else{
add_action('wp_enqueue_scripts', 'fullcalendar_enqueue_scripts');
}