-
Notifications
You must be signed in to change notification settings - Fork 3
/
rendez-vous.php
executable file
·383 lines (317 loc) · 10.9 KB
/
rendez-vous.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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
<?php
/**
* @package RendezVous
* @author imath https://twitter.com/imath
* @license GPL-2.0+
* @link http://imathi.eu
* @copyright 2013 imath
*
* @wordpress-plugin
* Plugin Name: Rendez Vous
* Plugin URI: http://imathi.eu/tag/rendez-vous
* Description: Rendez Vous is a BuddyPress plugin to schedule appointments with your buddies
* Version: 1.0.2
* Author: imath
* Author URI: http://imathi.eu
* Text Domain: rendez-vous
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Domain Path: /languages/
* GitHub Plugin URI: https://github.com/imath/rendez-vous
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'Rendez_Vous' ) ) :
/**
* Main RendezVous Class
*
* @since RendezVous (1.0.0)
*/
class Rendez_Vous {
/**
* Instance of this class.
*
* @package Rendez Vous
*
* @since Rendez Vous (1.0.0)
*
* @var object
*/
protected static $instance = null;
/**
* Required BuddyPress version for the plugin.
*
* @package Rendez Vous
*
* @since Rendez Vous (1.0.0)
*
* @var string
*/
public static $required_bp_version = '1.9';
/**
* BuddyPress config.
*
* @package Rendez Vous
*
* @since Rendez Vous (1.0.0)
*
* @var array
*/
public static $bp_config = array();
/**
* Initialize the plugin
*
* @package Rendez Vous
*
* @since Rendez Vous (1.0.0)
*/
private function __construct() {
// First you will set your plugin's globals
$this->setup_globals();
// Then include the needed files
$this->includes();
// Then hook to BuddyPress actions & filters
$this->setup_hooks();
}
/**
* Return an instance of this class.
*
* @package Rendez Vous
*
* @since Rendez Vous (1.0.0)
*
* @return object A single instance of this class.
*/
public static function start() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Sets some globals for the plugin
*
* @package Rendez Vous
*
* @since Rendez Vous (1.0.0)
*/
private function setup_globals() {
// Define a global that will hold the current version number
$this->version = '1.0.2';
// Define a global to get the textdomain of your plugin.
$this->domain = 'rendez-vous';
$this->file = __FILE__;
$this->basename = plugin_basename( $this->file );
// Define a global that we can use to construct file paths throughout the component
$this->plugin_dir = plugin_dir_path( $this->file );
// Define a global that we can use to construct file paths starting from the includes directory
$this->includes_dir = trailingslashit( $this->plugin_dir . 'includes' );
// Define a global that we can use to construct file paths starting from the includes directory
$this->lang_dir = trailingslashit( $this->plugin_dir . 'languages' );
$this->plugin_url = plugin_dir_url( $this->file );
$this->includes_url = trailingslashit( $this->plugin_url . 'includes' );
// Define a global that we can use to construct url to the javascript scripts needed by the component
$this->plugin_js = trailingslashit( $this->includes_url . 'js' );
// Define a global that we can use to construct url to the css needed by the component
$this->plugin_css = trailingslashit( $this->includes_url . 'css' );
}
/**
* Include the component's loader.
*
* @package Rendez Vous
*
* @since Rendez Vous (1.0.0)
*/
private function includes() {
if ( self::bail() )
return;
require( $this->includes_dir . 'rendez-vous-loader.php' );
}
/**
* Sets the key hooks to add an action or a filter to
*
* @package Rendez Vous
*
* @since Rendez Vous (1.0.0)
*/
private function setup_hooks() {
if ( ! self::bail() ) {
// Load the component
add_action( 'bp_loaded', 'rendez_vous_load_component' );
add_filter( 'map_meta_cap', 'rendez_vous_map_meta_caps', 10, 4 );
// Enqueue the needed script and css files
add_action( 'bp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
// loads the languages..
add_action( 'bp_init', array( $this, 'load_textdomain' ), 5 );
// Saves the plugin version in db
add_action( bp_core_admin_hook(), 'rendez_vous_maybe_upgrade' );
} else {
// Display a warning message in network admin or admin
add_action( self::$bp_config['network_active'] ? 'network_admin_notices' : 'admin_notices', array( $this, 'warning' ) );
}
}
/**
* Display a warning message to admin
*
* @package Rendez Vous
*
* @since Rendez Vous (1.0.0)
*/
public function warning() {
$warnings = array();
if( ! self::version_check() ) {
$warnings[] = sprintf( __( 'Rendez Vous requires at least version %s of BuddyPress.', 'rendez-vous' ), self::$required_bp_version );
}
if ( ! empty( self::$bp_config ) ) {
$config = self::$bp_config;
} else {
$config = self::config_check();
}
if ( ! bp_core_do_network_admin() && ! $config['blog_status'] ) {
$warnings[] = __( 'Rendez Vous requires to be activated on the blog where BuddyPress is activated.', 'rendez-vous' );
}
if ( bp_core_do_network_admin() && ! $config['network_status'] ) {
$warnings[] = __( 'Rendez Vous and BuddyPress need to share the same network configuration.', 'rendez-vous' );
}
if ( ! empty( $warnings ) ) :
?>
<div id="message" class="error">
<?php foreach ( $warnings as $warning ) : ?>
<p><?php echo esc_html( $warning ) ; ?></p>
<?php endforeach ; ?>
</div>
<?php
endif;
}
/**
* Enqueue scripts if your component is loaded
*
* @package Rendez Vous
*
* @since Rendez Vous (1.0.0)
*/
public function enqueue_scripts() {
if ( ! bp_is_current_component( 'rendez_vous' ) )
return;
$suffix = SCRIPT_DEBUG ? '' : '.min';
wp_register_script( 'rendez-vous-plupload', includes_url( "js/plupload/wp-plupload$suffix.js" ), array(), $this->version, 1 );
wp_localize_script( 'rendez-vous-plupload', 'pluploadL10n', array() );
wp_register_script( 'rendez-vous-media-views', includes_url( "js/media-views$suffix.js" ), array( 'utils', 'media-models', 'rendez-vous-plupload', 'jquery-ui-sortable' ), $this->version, 1 );
wp_register_script( 'rendez-vous-media-editor', includes_url( "js/media-editor$suffix.js" ), array( 'shortcode', 'rendez-vous-media-views' ), $this->version, 1 );
wp_register_script( 'rendez-vous-modal', $this->plugin_js . "rendez-vous-backbone$suffix.js", array( 'rendez-vous-media-editor', 'jquery-ui-datepicker' ), $this->version, 1 );
// Allow themes to override modal style
$modal_style = apply_filters( 'rendez_vous_modal_css', $this->plugin_css . "rendezvous-editor$suffix.css", $suffix );
wp_register_style ( 'rendez-vous-modal-style', $modal_style, array( 'media-views' ), $this->version );
// Allow themes to override global style
$global_style = apply_filters(
'rendez_vous_global_css',
array(
'style' => $this->plugin_css . "rendezvous$suffix.css",
'deps' => array( 'dashicons' ),
),
$suffix
);
wp_enqueue_style ( 'rendez-vous-style', $global_style['style'], (array) $global_style['deps'], $this->version );
wp_enqueue_script ( 'rendez-vous-script', $this->plugin_js . "rendezvous$suffix.js", array( 'jquery' ), $this->version, 1 );
wp_localize_script( 'rendez-vous-script', 'rendez_vous_vars', array(
'confirm' => esc_html__( 'Are you sure you want to cancel this rendez-vous ?', 'rendez-vous' ),
'noaccess' => esc_html__( 'This rendez-vous is private and you have not been invited to it.', 'rendez-vous' ),
) );
}
/** Utilities *****************************************************************************/
/**
* Checks BuddyPress version
*
* @package Rendez Vous
*
* @since Rendez Vous (1.0.0)
*/
public static function version_check() {
// taking no risk
if ( ! defined( 'BP_VERSION' ) )
return false;
return version_compare( BP_VERSION, self::$required_bp_version, '>=' );
}
/**
* Checks if your plugin's config is similar to BuddyPress
*
* @package Rendez Vous
*
* @since Rendez Vous (1.0.0)
*/
public static function config_check() {
/**
* blog_status : true if your plugin is activated on the same blog
* network_active : true when your plugin is activated on the network
* network_status : BuddyPress & your plugin share the same network status
*/
self::$bp_config = array(
'blog_status' => false,
'network_active' => false,
'network_status' => true
);
if ( get_current_blog_id() == bp_get_root_blog_id() ) {
self::$bp_config['blog_status'] = true;
}
$network_plugins = get_site_option( 'active_sitewide_plugins', array() );
// No Network plugins
if ( empty( $network_plugins ) )
return self::$bp_config;
$rendez_vous_basename = plugin_basename( __FILE__ );
// Looking for BuddyPress and your plugin
$check = array( buddypress()->basename, $rendez_vous_basename );
// Are they active on the network ?
$network_active = array_diff( $check, array_keys( $network_plugins ) );
// If result is 1, your plugin is network activated
// and not BuddyPress or vice & versa. Config is not ok
if ( count( $network_active ) == 1 )
self::$bp_config['network_status'] = false;
// We need to know if the plugin is network activated to choose the right
// notice ( admin or network_admin ) to display the warning message.
self::$bp_config['network_active'] = isset( $network_plugins[ $rendez_vous_basename ] );
return self::$bp_config;
}
/**
* Bail if BuddyPress config is different than this plugin
*
* @package Rendez Vous
*
* @since Rendez Vous (1.0.0)
*/
public static function bail() {
$retval = false;
$config = self::config_check();
if ( ! self::version_check() || ! $config['blog_status'] || ! $config['network_status'] )
$retval = true;
return $retval;
}
/**
* Loads the translation files
*
* @package Rendez Vous
*
* @since Rendez Vous (1.0.0)
*
* @uses get_locale() to get the language of WordPress config
* @uses load_texdomain() to load the translation if any is available for the language
*/
public function load_textdomain() {
// Traditional WordPress plugin locale filter
$locale = apply_filters( 'plugin_locale', get_locale(), $this->domain );
$mofile = sprintf( '%1$s-%2$s.mo', $this->domain, $locale );
// Setup paths to current locale file
$mofile_local = $this->lang_dir . $mofile;
$mofile_global = WP_LANG_DIR . '/rendez-vous/' . $mofile;
// Look in global /wp-content/languages/buddyplug folder
load_textdomain( $this->domain, $mofile_global );
// Look in local /wp-content/plugins/buddyplug/languages/ folder
load_textdomain( $this->domain, $mofile_local );
}
}
endif;
// BuddyPress is loaded and initialized, let's start !
function rendez_vous() {
return Rendez_Vous::start();
}
add_action( 'bp_include', 'rendez_vous' );