PluginProbe
RSVP and Event Management / 2.7.5
RSVP and Event Management v2.7.5
trunk 0.5.0 0.6.0 0.7.0 0.8.0 0.9.0 0.9.5 1.0.0 1.1.0 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.5.0 1.6.0 1.6.1 1.6.2 1.6.5 1.7.0 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 All 136 releases
rsvp / wp-rsvp.php

wp-rsvp.php in RSVP and Event Management 2.7.5, at wp-rsvp.php

833 lines 28.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package rsvp
4 * @author WPChill
5 * @version 2.7.5
6 * Plugin Name: RSVP
7 * Text Domain: rsvp-plugin
8 * Plugin URI: http://wordpress.org/extend/plugins/rsvp/
9 * Description: This plugin allows guests to RSVP to an event. It was made initially for weddings but could be used for other things.
10 * Author: WPChill
11 * Version: 2.7.5
12 * Author URI: https://wpchill.com
13 * License: GPLv3
14 * Copyright 2010-2020 Mike de Libero mikede@mde-dev.com
15 * Copyright 2020 MachoThemes office@machothemes.com
16 * Copyright 2020 WPChill heyyy@wpchill.com
17 *
18 * Original Plugin URI: http://www.swimordiesoftware.com
19 * Original Author URI: http://www.swimordiesoftware.com
20 * Original Author: https://profiles.wordpress.org/mdedev/
21 *
22 *
23 * This program is free software; you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License, version 3, as
25 * published by the Free Software Foundation.
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free software
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
35 */
36
37 use Box\Spout\Reader\ReaderFactory;
38 use Box\Spout\Common\Type;
39
40 $my_plugin_file = __FILE__;
41
42 if ( isset( $plugin ) ) {
43 $my_plugin_file = $plugin;
44 } elseif ( isset( $mu_plugin ) ) {
45 $my_plugin_file = $mu_plugin;
46 } elseif ( isset( $network_plugin ) ) {
47 $my_plugin_file = $network_plugin;
48 }
49
50 define( 'RSVP_PLUGIN_FILE', $my_plugin_file );
51 define( 'RSVP_PLUGIN_PATH', WP_PLUGIN_DIR . '/' . basename( dirname( $my_plugin_file ) ) );
52
53 require_once 'includes/rsvp-constants.php';
54
55 require_once 'external-libs/wp-simple-nonce/wp-simple-nonce.php';
56 require_once __DIR__ . '/includes/rsvp_frontend.inc.php';
57
58 if ( is_admin() ) {
59 require_once __DIR__ . '/includes/class-rsvp-review.php';
60 require_once 'includes/class-rsvp-admin.php';
61 require_once 'includes/class-rsvp-list-table.php';
62 require_once 'includes/class-rsvp-events-list-table.php';
63 require_once 'includes/class-rsvp-attendees-list-table.php';
64 require_once 'includes/class-rsvp-questions-list-table.php';
65 require_once 'includes/class-rsvp-helper.php';
66 require_once 'includes/class-rsvp-upsells.php';
67
68 if ( apply_filters( 'rsvp_show_upsells', true ) ) {
69 RSVP_Upsells::get_instance();
70 }
71 }
72
73 /**
74 * Database setup for the rsvp plug-in.
75 */
76 function rsvp_database_setup() {
77 global $wpdb;
78 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
79 require_once __DIR__ . '/includes/rsvp_db_setup.inc.php';
80 }
81
82 /**
83 * Checks to see if the passcode field is installed in the attendees table, if not
84 * it will add the field.
85 */
86 function rsvp_install_passcode_field() {
87 global $wpdb;
88 $table = ATTENDEES_TABLE;
89 $sql = "SHOW COLUMNS FROM `$table` LIKE 'passcode'";
90 if ( ! $wpdb->get_results( $sql ) ) {
91 $sql = "ALTER TABLE `$table` ADD `passcode` VARCHAR(50) NOT NULL DEFAULT '';";
92 $wpdb->query( $sql );
93 }
94 }
95
96 /**
97 * Checks to see if passcode is required for attendees.
98 *
99 * @return bool True if a passcode is required, false otherwise.
100 */
101 function rsvp_require_passcode() {
102 return ( ( get_option( OPTION_RSVP_PASSCODE ) == 'Y' ) || ( get_option( OPTION_RSVP_OPEN_REGISTRATION ) == 'Y' ) || ( get_option( OPTION_RSVP_ONLY_PASSCODE ) == 'Y' ) );
103 }
104
105 /**
106 * Checks to see if only a passcode is required to RSVP.
107 *
108 * @return bool True if only a passcode is needed to RSVP, false otherwise.
109 */
110 function rsvp_require_only_passcode_to_register() {
111 return ( get_option( OPTION_RSVP_ONLY_PASSCODE ) === 'Y' );
112 }
113
114 /**
115 * [rsvp_require_unique_passcode description]
116 *
117 * @return [type] [description]
118 */
119 function rsvp_require_unique_passcode() {
120 return rsvp_require_only_passcode_to_register();
121 }
122
123 /**
124 * [rsvp_is_passcode_unique description]
125 *
126 * @param [type] $passcode [description]
127 * @param [type] $attendee_id [description]
128 *
129 * @return [type] [description]
130 */
131 function rsvp_is_passcode_unique( $passcode, $attendee_id ) {
132 global $wpdb;
133
134 $is_unique = false;
135
136 $sql = $wpdb->prepare( 'SELECT * FROM ' . ATTENDEES_TABLE . ' WHERE id <> %d AND passcode = %s', $attendee_id, $passcode );
137 if ( ! $wpdb->get_results( $sql ) ) {
138 $is_unique = true;
139 }
140
141 return $is_unique;
142 }
143
144 /**
145 * This generates a random 6 character passcode to be used for guests when the option is enabled.
146 */
147 function rsvp_generate_passcode() {
148 $length = 6;
149 $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
150 $passcode = '';
151
152 for ( $p = 0; $p < $length; $p ++ ) {
153 $passcode .= $characters[ mt_rand( 0, strlen( $characters ) ) ];
154 }
155
156 return $passcode;
157 }
158
159
160 /**
161 * Gets the file type based on the users uploaded extension.
162 *
163 * @param string $file_path The file name that the user uploaded for importing.
164 *
165 * @return object Null or the Spout type used for parsing the files.
166 */
167 function rsvp_free_import_get_file_type( $file_path ) {
168 $ext = strtolower( pathinfo( $file_path, PATHINFO_EXTENSION ) );
169
170 if ( 'csv' === $ext ) {
171 return Type::CSV;
172 } elseif ( 'xlsx' === $ext ) {
173 return Type::XLSX;
174 } elseif ( 'ods' === $ext ) {
175 return Type::ODS;
176 }
177
178 return null;
179 }
180
181
182 function rsvp_get_question_with_answer_type_ids() {
183 global $wpdb;
184
185 $ids = array();
186 $sql = 'SELECT id FROM ' . QUESTION_TYPE_TABLE . "
187 WHERE questionType IN ('" . QT_MULTI . "', '" . QT_DROP . "', '" . QT_RADIO . "')";
188 $results = $wpdb->get_results( $sql );
189 foreach ( $results as $r ) {
190 $ids[] = (int) $r->id;
191 }
192
193 return $ids;
194 }
195
196 /**
197 * Populates the custom question types
198 *
199 * @since 2.2.8
200 */
201 function rsvp_populate_custom_question_types() {
202 global $wpdb;
203
204 $question_types = array(
205 array(
206 'questionType' => 'shortAnswer',
207 'friendlyName' => 'Short Answer',
208 ),
209 array(
210 'questionType' => 'multipleChoice',
211 'friendlyName' => 'Multiple Choice',
212 ),
213 array(
214 'questionType' => 'longAnswer',
215 'friendlyName' => 'Long Answer',
216 ),
217 array(
218 'questionType' => 'dropdown',
219 'friendlyName' => 'Drop Down',
220 ),
221 array(
222 'questionType' => 'radio',
223 'friendlyName' => 'Radio',
224 ),
225 );
226
227 foreach ( $question_types as $qt ) {
228 $qType = $wpdb->get_var( $wpdb->prepare( 'SELECT id FROM ' . QUESTION_TYPE_TABLE . ' WHERE questionType = %s ', $qt['questionType'] ) );
229 if ( $qType == null ) {
230 $wpdb->insert(
231 QUESTION_TYPE_TABLE,
232 array(
233 'questionType' => $qt['questionType'],
234 'friendlyName' => $qt['friendlyName'],
235 ),
236 array( '%s', '%s' )
237 );
238 }
239 }
240 }
241
242 function rsvp_admin_custom_question() {
243 global $wpdb;
244 $rsvp_helper = RSVP_Helper::get_instance();
245
246 $answerQuestionTypes = rsvp_get_question_with_answer_type_ids();
247
248 rsvp_populate_custom_question_types();
249
250 if ( ( count( $_POST ) > 0 ) && ! empty( $_POST['question'] ) && is_numeric( $_POST['questionTypeID'] ) ) {
251 check_admin_referer( 'rsvp_add_custom_question' );
252 if ( isset( $_POST['questionId'] ) && is_numeric( $_POST['questionId'] ) && ( $_POST['questionId'] > 0 ) ) {
253 $wpdb->update(
254 QUESTIONS_TABLE,
255 array(
256 'question' => sanitize_text_field( wp_unslash( $_POST['question'] ) ),
257 'questionTypeID' => absint( $_POST['questionTypeID'] ),
258 'permissionLevel' => ( ( sanitize_text_field( wp_unslash( $_POST['permissionLevel'] ) ) == 'private' ) ? 'private' : 'public' ),
259 ),
260 array( 'id' => absint( $_POST['questionId'] ) ),
261 array( '%s', '%d', '%s' ),
262 array( '%d' )
263 );
264 $questionId = absint( $_POST['questionId'] );
265
266 $answers = $wpdb->get_results( $wpdb->prepare( 'SELECT id FROM ' . QUESTION_ANSWERS_TABLE . ' WHERE questionID = %d', absint( $questionId ) ) );
267 if ( count( $answers ) > 0 ) {
268 foreach ( $answers as $a ) {
269 if ( isset( $_POST[ 'deleteAnswer' . $a->id ] ) && ( strToUpper( sanitize_text_field( wp_unslash( $_POST[ 'deleteAnswer' . $a->id ] ) ) ) == 'Y' ) ) {
270 $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . QUESTION_ANSWERS_TABLE . ' WHERE id = %d', $a->id ) );
271 } elseif ( isset( $_POST[ 'answer' . $a->id ] ) && ! empty( $_POST[ 'answer' . $a->id ] ) ) {
272 $wpdb->update(
273 QUESTION_ANSWERS_TABLE,
274 array( 'answer' => sanitize_text_field( wp_unslash( $_POST[ 'answer' . $a->id ] ) ) ),
275 array( 'id' => absint( $a->id ) ),
276 array( '%s' ),
277 array( '%d' )
278 );
279 }
280 }
281 }
282 } else {
283 $wpdb->insert(
284 QUESTIONS_TABLE,
285 array(
286 'question' => sanitize_text_field( wp_unslash( ( $_POST['question'] ) ) ),
287 'questionTypeID' => absint( $_POST['questionTypeID'] ),
288 'permissionLevel' => ( ( sanitize_text_field( wp_unslash( ( $_POST['permissionLevel'] ) ) == 'private' ) ? 'private' : 'public' ) ),
289 ),
290 array( '%s', '%d', '%s' )
291 );
292 $questionId = $wpdb->insert_id;
293 }
294
295 if ( isset( $_POST['numNewAnswers'] ) && is_numeric( $_POST['numNewAnswers'] ) &&
296 in_array( absint( $_POST['questionTypeID'] ), $answerQuestionTypes ) ) {
297 for ( $i = 0; $i < absint( $_POST['numNewAnswers'] ); $i ++ ) {
298 if ( isset( $_POST[ 'newAnswer' . $i ] ) && ! empty( $_POST[ 'newAnswer' . $i ] ) ) {
299 $wpdb->insert(
300 QUESTION_ANSWERS_TABLE,
301 array(
302 'questionID' => absint( $questionId ),
303 'answer' => sanitize_text_field( wp_unslash( $_POST[ 'newAnswer' . $i ] ) ),
304 )
305 );
306 }
307 }
308 }
309
310 if ( strToLower( sanitize_text_field( wp_unslash( $_POST['permissionLevel'] ) ) ) == 'private' ) {
311 $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . QUESTION_ATTENDEES_TABLE . ' WHERE questionID = %d', absint( $questionId ) ) );
312 if ( isset( $_POST['attendees'] ) && is_array( $_POST['attendees'] ) ) {
313 foreach ( array_map( 'sanitize_text_field', array_map( 'wp_unslash', $_POST['attendees'] ) ) as $aid ) {
314 if ( is_numeric( $aid ) && ( $aid > 0 ) ) {
315 $wpdb->insert(
316 QUESTION_ATTENDEES_TABLE,
317 array(
318 'attendeeID' => absint( $aid ),
319 'questionID' => absint( $questionId ),
320 ),
321 array( '%d', '%d' )
322 );
323 }
324 }
325 }
326 }
327 ?>
328 <p><?php echo esc_html__( 'Custom Question saved', 'rsvp' ); ?></p>
329 <p>
330 <a href="<?php echo esc_url( add_query_arg( array( 'page' => 'rsvp-admin-questions' ), admin_url( 'admin.php' ) ) ); ?>"
331 class="button button-secondary"><?php echo esc_html__( 'Continue to Question List', 'rsvp' ); ?></a>
332 <a href="
333 <?php
334 echo esc_url( add_query_arg(
335 array(
336 'page' => 'rsvp-admin-questions',
337 'action' => 'add',
338 ),
339 admin_url( 'admin.php' )
340 ) );
341 ?>
342 "
343 class="button button-primary"><?php echo esc_html__( 'Add another Question', 'rsvp' ); ?></a>
344 </p>
345 <?php
346 } else {
347 $questionTypeId = 0;
348 $question = '';
349 $isNew = true;
350 $questionId = 0;
351 $permissionLevel = 'public';
352 $savedAttendees = array();
353 if ( isset( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) {
354 $qRs = $wpdb->get_results( $wpdb->prepare( 'SELECT id, question, questionTypeID, permissionLevel FROM ' . QUESTIONS_TABLE . ' WHERE id = %d', absint( $_GET['id'] ) ) );
355 if ( count( $qRs ) > 0 ) {
356 $isNew = false;
357 $questionId = absint( $qRs[0]->id );
358 $question = stripslashes( $qRs[0]->question );
359 $permissionLevel = stripslashes( $qRs[0]->permissionLevel );
360 $questionTypeId = absint( $qRs[0]->questionTypeID );
361
362 if ( $permissionLevel == 'private' ) {
363 $aRs = $wpdb->get_results( $wpdb->prepare( 'SELECT attendeeID FROM ' . QUESTION_ATTENDEES_TABLE . ' WHERE questionID = %d', $questionId ) );
364 if ( count( $aRs ) > 0 ) {
365 foreach ( $aRs as $a ) {
366 $savedAttendees[] = $a->attendeeID;
367 }
368 }
369 }
370 }
371 }
372
373 $sql = 'SELECT id, questionType, friendlyName FROM ' . QUESTION_TYPE_TABLE;
374 $questionTypes = $wpdb->get_results( $sql );
375 ?>
376 <script type="text/javascript">
377 var questionTypeId = [
378 <?php
379 foreach ( $answerQuestionTypes as $aqt ) {
380 echo '"' . esc_attr( $aqt ) . '",';
381 }
382 ?>
383 ];
384
385 function addAnswer( counterElement ) {
386 var currAnswer = jQuery( "#numNewAnswers" ).val();
387 if ( isNaN( currAnswer ) ) {
388 currAnswer = 0;
389 }
390
391 var s = "<tr>\r\n" +
392 "<td align=\"right\" width=\"75\"><label for=\"newAnswer" + currAnswer + "\"><?php echo esc_html__( 'Answer', 'rsvp' ); ?>:</label></td>\r\n" +
393 "<td><input type=\"text\" name=\"newAnswer" + currAnswer + "\" id=\"newAnswer" + currAnswer + "\" size=\"40\" /></td>\r\n" +
394 "</tr>\r\n";
395 jQuery( "#answerContainer" ).append( s );
396 currAnswer++;
397 jQuery( "#numNewAnswers" ).val( currAnswer );
398 return false;
399 }
400
401 jQuery( document ).ready( function () {
402
403 <?php
404 if ( $isNew || ! in_array( $questionTypeId, $answerQuestionTypes ) ) {
405 echo 'jQuery("#answerContainer").hide();';
406 }
407
408 if ( $isNew || ( $permissionLevel == 'public' ) ) {
409 ?>
410 jQuery( "#attendeesArea" ).hide();
411 <?php
412 }
413 ?>
414 jQuery( "#questionType" ).change( function () {
415 var selectedValue = jQuery( "#questionType" ).val();
416 if ( questionTypeId.indexOf( selectedValue ) != -1 ) {
417 jQuery( "#answerContainer" ).show();
418 } else {
419 jQuery( "#answerContainer" ).hide();
420 }
421 } )
422
423 jQuery( "#permissionLevel" ).change( function () {
424 if ( jQuery( "#permissionLevel" ).val() != "public" ) {
425 jQuery( "#attendeesArea" ).show();
426 } else {
427 jQuery( "#attendeesArea" ).hide();
428 }
429 } )
430 } );
431 </script>
432 <form name="contact" action="<?php echo esc_url( add_query_arg( 'action', 'add' ) ); ?>" method="post">
433 <input type="hidden" name="numNewAnswers" id="numNewAnswers" value="0"/>
434 <input type="hidden" name="questionId" value="<?php echo absint( $questionId ); ?>"/>
435 <?php wp_nonce_field( 'rsvp_add_custom_question' ); ?>
436 <p class="submit">
437 <a href="<?php echo esc_url( admin_url( 'admin.php?page=rsvp-admin-questions' ) ); ?>"
438 class="button button-secondary"><?php esc_html_e( 'Back to custom question list', 'rsvp' ); ?></a>
439 <input type="submit" class="button-primary" value="<?php esc_attr_e( 'Save', 'rsvp' ); ?>"/>
440 </p>
441 <table id="customQuestions" class="form-table">
442 <tr valign="top">
443 <th scope="row"><label for="questionType"><?php echo esc_html__( 'Question Type', 'rsvp' ); ?>
444 :</label></th>
445 <td align="left"><select name="questionTypeID" id="questionType" size="1">
446 <?php
447 foreach ( $questionTypes as $qt ) {
448 echo '<option value="' . esc_attr( $qt->id ) . '" ' . ( ( $questionTypeId == $qt->id ) ? ' selected="selected"' : '' ) . '>' . esc_html( $qt->friendlyName ) . "</option>\r\n";
449 }
450 ?>
451 </select>
452 </td>
453 </tr>
454 <tr valign="top">
455 <th scope="row"><label for="question"><?php echo esc_html__( 'Question', 'rsvp' ); ?>:</label></th>
456 <td align="left"><input type="text" name="question" id="question" size="40"
457 value="<?php echo esc_attr( $question ); ?>"/></td>
458 </tr>
459 <tr>
460 <th scope="row"><label
461 for="permissionLevel"><?php echo esc_html__( 'Question Permission Level', 'rsvp' ); ?>
462 :</label></th>
463 <td align="left"><select name="permissionLevel" id="permissionLevel" size="1">
464 <option value="public" <?php echo ( $permissionLevel == 'public' ) ? ' selected="selected"' : ''; ?>><?php echo esc_html__( 'Everyone', 'rsvp' ); ?></option>
465 <option value="private" <?php echo ( $permissionLevel == 'private' ) ? ' selected="selected"' : ''; ?>><?php echo esc_html__( 'Select People', 'rsvp' ); ?></option>
466 </select></td>
467 </tr>
468 <?php if ( ! $isNew && ( $permissionLevel == 'private' ) ) : ?>
469 <tr>
470 <th scope="row"><?php echo esc_html__( 'Private Import Key', 'rsvp' ); ?>:</th>
471 <td align="left">pq_<?php echo esc_html( $questionId ); ?></td>
472 </tr>
473 <?php endif; ?>
474 <tr>
475 <td colspan="2">
476 <table cellpadding="0" cellspacing="0" border="0" id="answerContainer">
477 <tr>
478 <th><?php echo esc_html__( 'Answers', 'rsvp' ); ?></th>
479 <th align="right"><a href="#"
480 onclick="return addAnswer();"><?php echo esc_html__( 'Add new Answer', 'rsvp' ); ?></a>
481 </th>
482 </tr>
483 <?php
484 if ( ! $isNew ) {
485 $aRs = $wpdb->get_results( $wpdb->prepare( 'SELECT id, answer FROM ' . QUESTION_ANSWERS_TABLE . ' WHERE questionID = %d', absint( $questionId ) ) );
486 if ( count( $aRs ) > 0 ) {
487 foreach ( $aRs as $answer ) {
488 ?>
489 <tr>
490 <td width="75" align="right"><label
491 for="answer<?php echo esc_attr( $answer->id ); ?>"><?php echo esc_html__( 'Answer', 'rsvp' ); ?>
492 :</label></td>
493 <td><input type="text" name="answer<?php echo esc_attr( $answer->id ); ?>"
494 id="answer<?php echo esc_attr( $answer->id ); ?>" size="40"
495 value="<?php echo esc_attr( stripslashes( $answer->answer ) ); ?>"/>
496 &nbsp; <input type="checkbox"
497 name="deleteAnswer<?php echo esc_attr( $answer->id ); ?>"
498 id="deleteAnswer<?php echo esc_attr( $answer->id ); ?>"
499 value="Y"/><label
500 for="deleteAnswer<?php echo esc_attr( $answer->id ); ?>"><?php echo esc_html__( 'Delete', 'rsvp' ); ?></label>
501 </td>
502 </tr>
503 <?php
504 }
505 }
506 }
507 ?>
508 </table>
509 </td>
510 </tr>
511 <tr id="attendeesArea">
512 <th scope="row"><label
513 for="attendees"><?php echo esc_html__( 'Attendees allowed to answer this question', 'rsvp' ); ?>
514 :</label></th>
515 <td>
516 <p>
517 <span style="margin-left: 30px;"><?php esc_html_e( 'Available people', 'rsvp' ); ?></span>
518 <span style="margin-left: 65px;"><?php esc_html_e( 'People that have access', 'rsvp' ); ?></span>
519 </p>
520 <select name="attendees[]" id="attendeesQuestionSelect" style="height:75px;"
521 multiple="multiple">
522 <?php
523 $attendees = $rsvp_helper->get_attendees();
524 foreach ( $attendees as $a ) {
525 ?>
526 <option value="<?php echo esc_attr( $a->id ); ?>"
527 <?php echo( ( in_array( $a->id, $savedAttendees ) ) ? ' selected="selected"' : '' ); ?>><?php echo esc_html( stripslashes( $a->firstName ) . ' ' . stripslashes( $a->lastName ) ); ?></option>
528 <?php
529 }
530 ?>
531 </select>
532 </td>
533 </tr>
534 </table>
535 </form>
536 <?php
537 }
538 }
539
540 function rsvp_admin_scripts() {
541 wp_enqueue_script( 'jquery' );
542 wp_enqueue_script( 'jquery-ui-datepicker' );
543 wp_enqueue_script( 'jquery-ui-sortable' );
544 wp_enqueue_style( 'jquery-ui' );
545 wp_register_script( 'jquery_multi_select', plugins_url( 'multi-select/js/jquery.multi-select.js', RSVP_PLUGIN_FILE ) );
546 wp_enqueue_script( 'jquery_multi_select' );
547 wp_register_style( 'jquery_multi_select_css', plugins_url( 'multi-select/css/multi-select.css', RSVP_PLUGIN_FILE ) );
548 wp_enqueue_style( 'jquery_multi_select_css' );
549
550 wp_register_style( 'rsvp_jquery-ui', plugins_url( '/assets/admin/css/jquery-ui.css', RSVP_PLUGIN_FILE ) );
551 wp_enqueue_style( 'rsvp_jquery-ui' );
552
553 wp_register_script( 'rsvp_admin', plugins_url( 'assets/admin/js/rsvp_plugin_admin.js', RSVP_PLUGIN_FILE ), array( 'jquery-ui-sortable' ), '', true );
554 wp_enqueue_script( 'rsvp_admin' );
555 }
556
557 /**
558 * Function for loading the needed assets for the plugin.
559 */
560 function rsvp_init() {
561 $result = load_plugin_textdomain( 'rsvp', false, basename( dirname( __FILE__ ) ) . '/languages/' );
562 }
563
564 /**
565 * Handles converting text encodings for characters like umlauts that might be stored in different encodings
566 *
567 * @param string $text The text we wish to handle the encoding against
568 *
569 * @return string The converted text
570 */
571 function rsvp_handle_text_encoding( $text ) {
572 if ( function_exists( 'mb_convert_encoding' ) && function_exists( 'mb_detect_encoding' ) ) {
573 return mb_convert_encoding( $text, 'UTF-8', mb_detect_encoding( $text, 'UTF-8, ISO-8859-1', true ) );
574 }
575
576 return $text;
577 }
578
579 function rsvp_free_is_addslashes_enabled() {
580 return get_magic_quotes_gpc();
581 }
582
583 function rsvp_getCurrentPageURL() {
584 global $wp;
585 global $wp_rewrite;
586
587 $pageURL = home_url( $wp->request );
588 $pageURL = trailingslashit( $pageURL );
589
590 if ( $wp_rewrite->using_index_permalinks() && ( strpos( $pageURL, 'index.php' ) === false ) ) {
591 $parts = parse_url( $pageURL );
592
593 $pageURL = $parts['scheme'] . '://' . $parts['host'];
594
595 if ( isset( $parts['port'] ) ) {
596 $pageURL .= ':' . $parts['port'];
597 }
598
599 $pageURL .= '/index.php' . $parts['path'];
600
601 if ( isset( $parts['query'] ) && ( $parts['query'] != '' ) ) {
602 $pageURL .= '?' . $parts['query'];
603 }
604 } elseif ( empty( $wp_rewrite->permalink_structure ) ) {
605 $pageURL = get_permalink();
606 }
607
608 if ( get_option( OPTION_RSVP_DONT_USE_HASH ) != 'Y' ) {
609 $pageURL .= '#rsvpArea';
610 }
611
612 return $pageURL;
613 }
614 function rsvp_hide_untill_loaded() {
615
616 echo '<style type="text/css">.rsvpArea, .rsvpParagraph, #rsvpPlugin {display:none;} </style>';
617 }
618
619 function rsvp_add_css() {
620 $css = get_option( RSVP_OPTION_CSS_STYLING );
621
622 if ( ! empty( $css ) ) {
623 $output = '<!-- RSVP Free Styling -->';
624 $output .= '<style id="rsvp_plugin-custm-style" type="text/css">' . $css . '</style>';
625
626 echo wp_kses_post( $output );
627 }
628 }
629
630 function rsvp_front_scripts() {
631 wp_register_script( 'jquery_validate', plugins_url( 'assets/js/jquery.validate.min.js', RSVP_PLUGIN_FILE ), array( 'jquery' ) );
632 wp_register_script( 'rsvp_plugin', plugins_url( 'assets/js/rsvp_plugin.js', RSVP_PLUGIN_FILE ), array( 'jquery' ) );
633 wp_localize_script(
634 'rsvp_plugin',
635 'rsvp_plugin_vars',
636 array(
637 'askEmail' => __( 'Please enter an email address that we can use to contact you about the extra guest. We have to keep a pretty close eye on the number of attendees. Thanks!', 'rsvp' ),
638 'customNote' => __( 'If you are adding additional RSVPs please enter your email address in case we have questions', 'rsvp' ),
639 'newAttending1LastName' => __( 'Please enter a last name', 'rsvp' ),
640 'newAttending1FirstName' => __( 'Please enter a first name', 'rsvp' ),
641 'newAttending2LastName' => __( 'Please enter a last name', 'rsvp' ),
642 'newAttending2FirstName' => __( 'Please enter a first name', 'rsvp' ),
643 'newAttending3LastName' => __( 'Please enter a last name', 'rsvp' ),
644 'newAttending3FirstName' => __( 'Please enter a first name', 'rsvp' ),
645 'attendeeFirstName' => __( 'Please enter a first name', 'rsvp' ),
646 'attendeeLastName' => __( 'Please enter a last name', 'rsvp' ),
647 'firstName' => __( 'Please enter your first name', 'rsvp' ),
648 'lastName' => __( 'Please enter your last name', 'rsvp' ),
649 'passcode' => __( 'Please enter your password', 'rsvp' ),
650 )
651 );
652
653 wp_register_style( 'rsvp_css', plugins_url( 'assets/css/rsvp_plugin.css', RSVP_PLUGIN_FILE ) );
654 wp_enqueue_script( 'jquery' );
655 wp_enqueue_script( 'jquery_validate' );
656 wp_enqueue_script( 'rsvp_plugin' );
657 wp_enqueue_style( 'rsvp_css' );
658 }
659
660 function rsvp_add_privacy_policy_content() {
661 if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) {
662 return;
663 }
664
665 $content = __(
666 'All information entered either from an attendee or a WordPress admin for the RSVP
667 plugin is never sent to external sites. The data stays in database tables
668 on the WordPress instance.',
669 'rsvp'
670 );
671
672 wp_add_privacy_policy_content(
673 'RSVP Plugin',
674 wp_kses_post( wpautop( $content, false ) )
675 );
676 }
677
678 /**
679 * Handles the data erasing for a given email address.
680 *
681 * @param string $email_address The email address we want to delete from the attendees table.
682 * @param integer $page The page we are on.
683 *
684 * @return array An array containing how many attendees were deleted.
685 */
686 function rsvp_data_eraser_handler( $email_address, $page = 1 ) {
687 global $wpdb;
688 $rsvp_helper = RSVP_Helper::get_instance();
689
690 $num_deleted = 0;
691 $sql = 'SELECT id FROM ' . ATTENDEES_TABLE . ' WHERE email = %s';
692 $attendees = $wpdb->get_results( $wpdb->prepare( $sql, $email_address ) );
693 foreach ( $attendees as $a ) {
694 $rsvp_helper->delete_attendee( $a->id );
695 $num_deleted ++;
696 }
697
698 return array(
699 'items_removed' => $num_deleted,
700 'items_retained' => false, // We never retain items.
701 'messages' => array( __( 'RSVP Data Erased Successfully', 'rsvp' ) ),
702 'done' => true,
703 );
704 }
705
706 /**
707 * The data eraser registration that lets the core of WP know
708 * we can handle erasing of the RSVP Plugin information
709 * if it is ever requested.
710 *
711 * @param array $erasers The array of erasers already registered with this WP instance.
712 *
713 * @return array The erasers array now with the RSVP eraser added.
714 */
715 function rsvp_register_data_eraser( $erasers ) {
716 $erasers['rsvp-plugin'] = array(
717 'eraser_friendly_name' => __( 'RSVP Plugin', 'rsvp' ),
718 'callback' => 'rsvp_data_eraser_handler',
719 );
720
721 return $erasers;
722 }
723
724 /**
725 * Retrieves and packages up the exporter information for the new WordPress compliance functionality
726 *
727 * @param string $email_address The email address we need to export the information for.
728 * @param integer $page The current page.
729 *
730 * @return array Containing the information and if everything is done being exported.
731 */
732 function rsvp_data_exporter_handler( $email_address, $page = 1 ) {
733 global $wpdb;
734
735 $export_items = array();
736 $sql = 'SELECT a.id, a.firstName, a.lastName, a.rsvpDate,
737 a.rsvpStatus, a.note, a.additionalAttendee, a.kidsMeal,
738 a.veggieMeal, a.personalGreeting
739 FROM ' . ATTENDEES_TABLE . ' a
740 WHERE email = %s';
741 $attendees = $wpdb->get_results( $wpdb->prepare( $sql, $email_address ) );
742 foreach ( $attendees as $a ) {
743 $export_items['firstName'] = stripslashes( $a->firstName );
744 $export_items['lastName'] = stripslashes( $a->lastName );
745 $export_items['rsvpDate'] = $a->rsvpDate;
746 $export_items['rsvpStatus'] = stripslashes( $a->rsvpStatus );
747 $export_items['note'] = stripslashes( $a->note );
748 $export_items['additionalAttendee'] = stripslashes( $a->additionalAttendee );
749 $export_items['personalGreeting'] = stripslashes( $a->personalGreeting );
750 $export_items['veggieMeal'] = stripslashes( $a->veggieMeal );
751 $export_items['kidsMeal'] = stripslashes( $a->kidsMeal );
752
753 // Print out the custom question information for the main event.
754 $export_items = rsvp_data_exporter_custom_questions( $a->id, $export_items );
755 }
756
757 return array(
758 'data' => $export_items,
759 'done' => true,
760 );
761 }
762
763 /**
764 * Retrieves the custom question and answers for export
765 *
766 * @param integer $attendee_id The attendee we want to get the answers for.
767 * @param array $export_items The current exported items that we need to add to.
768 *
769 * @return array The export items with the custom questions added for the event passed in.
770 */
771 function rsvp_data_exporter_custom_questions( $attendee_id, $export_items ) {
772 global $wpdb;
773
774 $sql = 'SELECT answer, question FROM ' . ATTENDEE_ANSWERS . ' aa
775 JOIN ' . QUESTIONS_TABLE . ' q ON q.id = aa.questionID
776 WHERE aa.attendeeID = %d';
777
778 $custom_questions = $wpdb->get_results( $wpdb->prepare( $sql, $attendee_id ) );
779 foreach ( $custom_questions as $cq ) {
780 $export_items[ stripslashes( $cq->question ) ] = stripslashes( $cq->answer );
781 }
782
783 return $export_items;
784 }
785
786 /**
787 * Replace a smart quote with an actual single-quote so that people can
788 * find themselves when they do a search on the front-end.
789 *
790 * @param string $in The string we want to replace smart-quotes with single-quotes.
791 *
792 * @return string The string that has had the values replaced.
793 */
794 function rsvp_smart_quote_replace( $in ) {
795 return str_replace( '', '\'', $in );
796 }
797
798 /**
799 * Registers the RSVP data exporter to WP core
800 *
801 * @param array $exporters The current array of exporters registered with this WP instance.
802 *
803 * @return array The exporters array now with the RSVP exporter added.
804 */
805 function rsvp_register_data_exporter( $exporters ) {
806 $exporters['rsvp-plugin'] = array(
807 'exporter_friendly_name' => __( 'RSVP Plugin', 'rsvp' ),
808 'callback' => 'rsvp_data_exporter_handler',
809 );
810
811 return $exporters;
812 }
813
814 /**
815 * RSVP shortcode handler
816 *
817 * @param array $atts The array of attributes for this shortcode.
818 *
819 * @return string The output of the page.
820 */
821 function rsvpshortcode_func( $atts ) {
822 return rsvp_frontend_handler( 'rsvp-pluginhere ' );
823 }
824
825 add_shortcode( 'rsvp', 'rsvpshortcode_func' );
826 add_action( 'admin_init', 'rsvp_add_privacy_policy_content' );
827 add_filter( 'wp_privacy_personal_data_erasers', 'rsvp_register_data_eraser', 10 );
828 add_filter( 'wp_privacy_personal_data_exporters', 'rsvp_register_data_exporter', 10 );
829 add_action( 'init', 'rsvp_init' );
830 add_action( 'wp_head', 'rsvp_hide_untill_loaded' );
831 add_filter( 'the_content', 'rsvp_frontend_handler' );
832 register_activation_hook( __FILE__, 'rsvp_database_setup' );
833