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