';
// build compatibility test result
$html .= '' . apply_filters( 'aiwp_no_browser_support', 'It appears your browser is not capable of displaying this content. Try connecting with Chrome, Firefox, or Opera.' ) . '';
// include appearin iframe populated by API
$html .= '';
return $html;
} // end display_shortcode
/**
* Build an invitation form
*
* @since 1.0
*
* @return string HTML content for invite form.
*/
public function invite_form( $invites = 0, $room_type = '' ) {
// if invites enabled for room type, then build a hidden form
// otherwise, include hidden content to trigger room launch
if ( $invites > 0 ) {
$html = '
';
// include replacement button for invite submission and room entrance
$html .= '';
// inform of optional invites (delay hide with js)
$html .= 'Optionally Invite';
// include input for users name & email
$html .= '';
$html .= '';
// include some number of inputs for invitation emails (defined by custom settings)
for ( $i=1; $i<($invites+1); $i++ ) {
$html .= '1 ? ' style="display:none;"' : ''; // ensure the first field is displayed
$html .= ' value="" tabindex="' . ( 4 + $i ) . '">';
}
$html .= '
';
} else {
$html = '';
} // end if
return $html;
}
/**
* Callback for ajax send email invites
*
* @since 1.0
*/
public function email_invites() {
if ( check_ajax_referer( 'aiwp-action-on_' . get_option( 'aiwp_public_room' ), 'aiwp_security' ) ) {
// get the submitted parameters
$aiwp_username = $_POST['aiwp_username'];
$aiwp_email = $_POST['aiwp_email'];
$aiwp_room_url = $_POST['aiwp_room_url'];
$aiwp_room = $_POST['aiwp_room'];
$aiwp_room_type = $_POST['aiwp_room_type'];
$aiwp_invites = array();
// get the submitted emails and fill array
for( $i=1; $i<8; $i++ ) {
( isset( $_POST[ 'aiwp_invite_' . $i ] ) && '' != $_POST[ 'aiwp_invite_' . $i ] ) ? $aiwp_invites[] = $_POST[ 'aiwp_invite_' . $i ] : FALSE;
}
// if no invite emails set, then return true to enter room
// otherwise, process email invites
if ( empty( $aiwp_invites ) ) {
echo TRUE;
} else {
// validate invite email addresses
foreach ( $aiwp_invites as $email ) {
// if any fail, then return false triggering error message
if ( ! is_email( $email ) ) {
echo FALSE;
die();
}
}
// if from email set and valid, build header
// otherwise, set empty header
if ( '' != $aiwp_email && is_email( $aiwp_email ) ) {
$header = 'From: ';
$header .= '' != $aiwp_username ? $aiwp_username : '';
$header .= '<' . $aiwp_email . '>';
} else {
$header = '';
}
// build the message content
$message = 'You have been invited';
$message .= '' != $aiwp_username ? ' by ' . $aiwp_username : '';
$message .= ' to join a videochat happening now at ' . $aiwp_room_url . '?appearin=' . $aiwp_room;
// send each message separately
foreach ( $aiwp_invites as $email ) {
// send the message
$email_sent = wp_mail( $email, apply_filters( 'aiwp_invitation_subject', 'Invitation to Appear In' ), apply_filters( 'aiwp_invitation_message', $message ), $header );
// if send fails, return false triggering error message
// otherwise, add 1 to invite count stats
if ( ! $email_sent ) {
echo FALSE;
die();
} else {
$aiwp_stats = get_option( 'aiwp_stats' );
$aiwp_stats[ $aiwp_room_type ]['invites_sent'] ++;
update_option( 'aiwp_stats', $aiwp_stats );
}
}
// return success to enter room
echo TRUE;
}
} else {
echo FALSE;
}
die();
}
/**
* Callback for ajax counting rooms triggered
*
* @since 1.0
*/
public function count_session() {
if ( check_ajax_referer( 'aiwp-action-on_' . get_option( 'aiwp_public_room' ), 'aiwp_security' ) ) {
$aiwp_room_type = $_POST['aiwp_room_type'];
$aiwp_stats = get_option( 'aiwp_stats' );
$aiwp_stats[ $aiwp_room_type ]['rooms_triggered'] ++;
update_option( 'aiwp_stats', $aiwp_stats );
echo TRUE;
} else {
echo FALSE;
}
die();
}
/**
* Callback for ajax counting accepted invites
*
* @since 1.0
*/
public function count_accepted_invite() {
if ( check_ajax_referer( 'aiwp-action-on_' . get_option( 'aiwp_public_room' ), 'aiwp_security' ) ) {
$aiwp_room = $_POST['aiwp_room'];
$aiwp_room_type = strpos( ' ' . $aiwp_room, 'private-' ) > 0 ? 'private' : 'public';
$aiwp_stats = get_option( 'aiwp_stats' );
$aiwp_stats[ $aiwp_room_type ]['invites_accepted'] ++;
update_option( 'aiwp_stats', $aiwp_stats );
echo TRUE;
} else {
echo FALSE;
}
die();
}
} // end class
/**
* Create a random room code
*/
function aiwp_random_room() {
// predefine the alphabet used
$aiwp_alphabet = 'qwertyuiopasdfghjklzxcvbnm1234567890';
// set the length of the string
$aiwp_stringLength = 30;
// initialize the room name as an empty string
$aiwp_randomString = '';
// select and add 30 random character to the string
for ( $i=0; $i<$aiwp_stringLength; $i++) {
$aiwp_character = $aiwp_alphabet[ round( ( rand(0,100)/100 )*(strlen($aiwp_alphabet)-1) ) ];
$aiwp_randomString .= $aiwp_character;
} // end for
// return the result
return $aiwp_randomString;
}
/**
* Creates a new room code and saves to db
*/
function aiwp_expire_room() {
$aiwp_room = aiwp_random_room();
update_option( 'aiwp_public_room', $aiwp_room );
}
// Hook function to expireroom cron event (found in admin class)
add_action( 'expireroom', 'aiwp_expire_room' );
?>