| Server IP : 104.21.21.239 / Your IP : 216.73.216.191 Web Server : Apache/2.4.68 (Amazon Linux) OpenSSL/3.5.5 System : Linux ip-172-31-69-123.ec2.internal 6.1.176-223.369.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Jul 24 13:34:27 UTC 2026 x86_64 User : ec2-user ( 1000) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/home2/mommybites/wp-content/plugins/Xeventbriteticketing/ |
Upload File : |
<?php
// Test for SP Events Calendar plugin. Make smarter later, with message to user about installing SP Events Calendar first.
if ( !class_exists( 'Event_Tickets_PRO' ) ) {
/**
* Main Plugin
*/
class Event_Tickets_PRO {
/**************************************************************
* EventBrite Configuration
**************************************************************/
const EVENTBRITETIMEFORMAT = 'c'; // ISO 8601
const EVENTBRITEAPIBASEURL = 'www.eventbrite.com/xml/'; // json support only default in PHP 5.2
public $errors;
public $eventBritePrivacy = 0;
public $eventBriteTimezone;
public $eventBriteTransport; // https if supported, otherwise http
public $eventBriteApiUrl;
public $pluginDir;
public $pluginDomain = 'event-tickets-pro';
public $pluginVersion = '1.0';
// private $appKey = 'Y2IxNTIzN2ZmNmQw';
public $metaTags = array(
'_EventBriteId', // ID in EventBrite of this event
'_EventBriteTicketName',
'_EventBriteTicketDescription',
'_EventBriteIsDonation',
'_EventBriteTicketQuantity',
'_EventBriteIncludeFee',
'_EventBriteStatus',
'_EventRegister', // Whether to register this event with EventBrite
'_EventShowTickets', // Whether to register this event with EventBrite
'_EventBritePayment-accept_paypal',
'_EventBritePayment-paypal_email',
'_EventBritePayment-accept_google',
'_EventBritePayment-google_merchant_id',
'_EventBritePayment-google_merchant_key',
'_EventBritePayment-accept_check',
'_EventBritePayment-instructions_check',
'_EventBritePayment-accept_cash',
'_EventBritePayment-instructions_cash',
'_EventBritePayment-accept_invoice',
'_EventBritePayment-instructions_invoice'
);
public static function tecActive() {
return class_exists( 'TribeEvents' ) && defined('TribeEvents::VERSION') && version_compare( TribeEvents::VERSION, '2.0', '>=');
}
function __construct() {
add_action('init', array( $this, 'init_etp') );
}
public function init_etp() {
// use SSL if we support it
$version = curl_version();
$this->eventBriteTransport = ($version['features'] & CURL_VERSION_SSL ? 'https' : 'http');
$this->eventBriteApiUrl = $this->eventBriteTransport . '://' . Event_Tickets_PRO::EVENTBRITEAPIBASEURL;
if( self::tecActive() ) {
$this->pluginDir = basename(dirname(__FILE__));
$this->loadDomain();
$this->add_actions();
$this->add_filters();
} else {
add_action('admin_head', array( $this, 'noECPError' ));
}
}
public function noECPError() {
echo '<div class="error"><p>The Events Ticket Pro plugin requires the Events Calendar Pro plugin.</p></div>';
}
private function add_actions() {
add_action( 'admin_enqueue_scripts' , array( $this, 'addAdminStylesAndScripts' ));
add_action( 'admin_menu', array( $this, 'addOptionsPage' ) );
add_action( 'tribe_events_options_bottom', array( $this, 'eventBriteOptions' ) );
add_action( 'tribe_events_save_more_options', array( $this, 'saveOptions' ) );
add_action( 'tribe_events_update_meta', array( $this, 'eventbrite_details' ),1 );
add_action( 'tribe_events_update_meta', array( $this, 'addEventMeta' ),10 );
add_action( 'tribe_events_event_clear', array( $this, 'clear_details' ) );
add_action( 'show_user_profile',array( $this, 'userProfilePage' ) );
add_action( 'edit_user_profile',array( $this, 'userProfilePage' ) );
add_action( 'edit_user_profile_update', array( $this, 'userProfileUpdate' ) );
add_action( 'personal_options_update', array( $this, 'userProfileUpdate' ) );
add_action( 'tribe_events_cost_table', array( $this, 'eventBriteMetaBox'), 1 );
add_action( 'admin_init', array( $this, 'prepopulateEventBrite') );
}
public function prepopulateEventBrite() {
if(!empty($_GET['eventbrite_id'])) {
try {
$event_id = $this->importExistingEvent();
wp_redirect(get_bloginfo('url') . '/wp-admin/post.php?post=' . $event_id . '&action=edit');
exit();
} catch (TribeEventsPostException $e) {
wp_redirect(get_bloginfo('url') . '/wp-admin/edit.php?post_type=tribe_events&page=import-eventbrite-events&error=' . urlencode($e->getMessage()));
exit();
}
}
}
private function add_filters() {
add_filter( 'the_content', array( $this, 'displayEventBriteTicketForm' ) );
}
public function loadDomain() {
load_plugin_textdomain( $this->pluginDomain, false, $this->pluginDir . '/lang/');
}
public function addAdminStylesAndScripts() {
wp_enqueue_style( 'eb-pro-admin', WP_PLUGIN_URL . '/' . $this->pluginDir . '/resources/eb-tec-admin.css', array(), $this->pluginVersion, 'screen' );
}
public function userProfilePage( $profileuser ) {
if(!defined('EventBriteProfileDone')){
define('EventBriteProfileDone',1);
require_once( dirname( __FILE__ ) . '/views/user-profile.php' );
}
}
public function userProfileUpdate( $user_id ) {
if(!defined('EventBriteProfileUpdated')){
define('EventBriteProfileUpdated',1);
if( isset( $_POST['eventbrite_user_key'] ) ) {
update_usermeta( $user_id, 'eventbrite_user_key', $_POST['eventbrite_user_key'] );
}
}
}
public function displayExistingEventToggle() {
global $post;
$tribe_ecp = TribeEvents::instance();
$_EventBriteId = get_post_meta( $post->ID, '_EventBriteId', true );
include( WP_PLUGIN_DIR . '/' . $this->pluginDir . '/views/add-existing-event.php');
}
public function addEventMeta( $postId ) {
if( WP_DEBUG ) error_log( "addEventMeta: " . print_r( $_POST, true ) );
if ( ( $_POST['EventRegister'] == 'yes' && !get_post_meta( $postId, '_EventRegister', true) ) || ( $_POST['existingEBEvent'] == 'yes' && $_POST['ExistingEventId'] ) ) {
if( $_POST['existingEBEvent'] == 'yes' && $_POST['ExistingEventId'] ) update_post_meta( $postId, '_EventBriteId', $_POST['ExistingEventId'] );
// ignore these keys
$notFromEventBriteForm = array(
'_EventBriteId',
'_EventBriteStatus'
);
foreach( $this->metaTags as $key ) {
// the added test here should prevent overwriting of post meta fields on event update
if( in_array( $key, $notFromEventBriteForm ) || !$_POST[$postVarKey = substr_replace( $key, '', 0, 1)] ) continue;
update_post_meta( $postId, $key, $_POST[$postVarKey] );
}
} elseif( $_POST['EventRegister'] == 'yes' ) {
update_post_meta( $postId, '_EventShowTickets', $_POST['EventShowTickets'] );
} elseif( !isset( $_POST['EventRegister'] ) || empty( $_POST['EventRegister'] ) ) {
delete_post_meta( $postId, '_EventRegister' );
}
}
/**
* Updates the eventbrite information in wordpress and makes the
* API calls to EventBrite to update the listing on their side
*
* @link http://www.eventbrite.com/api/doc/
* @param int post id
* @uses $_POST
*/
public function eventbrite_details( $postId ) {
// clear out event brite if no longer stored together
if( !isset( $_POST['EventRegister'] ) || $_POST['EventRegister'] != 'yes' ) {
$this->clear_details( $postId );
return;
}
// if already saved, return
if( $_POST['existingEBEvent'] == 'yes' && $_POST['ExistingEventId'] ) return;
// get event brite id
$EventBriteId = get_post_meta( $postId, '_EventBriteId', true );
// update existing EB event
if( $EventBriteId ) {
$this->event_update( $postId, $EventBriteId, $_POST );
}
// create new EB event
if( !$EventBriteId && $_POST['EventRegister'] ) {
$tribe_ecp = TribeEvents::instance();
$eventId = $this->event_new( $postId, $_POST );
if( $eventId ) {
$this->ticket_new( $postId, $eventId, $_POST );
$this->payment_update( $postId, $eventId, $_POST );
}
if( !empty( $this->errors ) ) update_post_meta( $postId, TribeEvents::EVENTSERROROPT, trim( $this->errors) );
}
}
public function clear_details( $postId ) {
foreach( $this->metaTags as $meta ) {
delete_post_meta( $postId, $meta );
}
}
/**
* handles eventbrite ticket creation
*/
private function ticket_new( $postId, $eventId, $_POST ) {
if( !is_numeric($eventId) ) {
return false;
}
$request = 'event_id=' . $eventId;
if( empty( $_POST['EventBriteTicketName'] ) ) {
return false;
}
$request .= '&name=' . urlencode( $_POST['EventBriteTicketName'] );
if( $_POST['EventBriteIsDonation'] == 1 ) {
$request .= '&price=';
$request .= '&is_donation=1';
} elseif ( $_POST['EventBriteIsDonation'] == 0 && !is_numeric( $_POST['EventCost'] ) ) {
return false;
} else {
$request .= '&price=' . (float)$_POST['EventCost'];
$request .= '&is_donation=0';
}
if( !is_numeric( $_POST['EventBriteTicketQuantity'] ) ) {
return false;
} else {
$request .= '&quantity=' . (int)$_POST['EventBriteTicketQuantity'];
}
if( !empty( $_POST['EventBriteTicketDescription'] ) ) {
$request .= '&description=' . urlencode( $_POST['EventBriteTicketDescription'] );
}
$request .= '&include_fee=' . (int)$_POST['EventBriteIncludeFee'];
$response_arr = $this->sendEventBriteRequest( 'ticket_new', $request, $postId );
if(WP_DEBUG) error_log("TICKET RESPONSE: " . print_r($response_arr, true));
}
/**
* handles eventbrite updates
*/
private function event_update( $postId, $eventBriteId, $_POST ) {
$post = get_post( $postId );
if( wp_is_post_revision($postId) ) throw new TribeEventsPostException(__('This post is a revision and cannot update an Evenbrite event.', $this->pluginDomain));
else delete_post_meta( $postId, TribeEvents::EVENTSERROROPT );
if( empty( $_POST['post_title'] ) ) {
$tribe_ecp = TribeEvents::instance();
$this->errors .= 'Event must have a title';
throw new TribeEventsPostException(__('Please supply a post title. This will become the Eventbrite event title.', $this->pluginDomain));
}
$organizer_id = $this->do_event_organizer($postId);
if($organizer_id)
$venue_id = $this->do_event_venue($postId,false,$organizer_id);
$request = $this->build_event_data($eventBriteId,$venue_id,$organizer_id);
$response_arr = $this->sendEventBriteRequest( 'event_update', $request, $postId );
if( isset( $response_arr['process']['id'] ) ) {
update_post_meta( $postId, '_EventBriteId', $response_arr['process']['id'], true );
}
}
/**
* handles eventbrite creation
*
* @return mixed event brite id or false
*/
private function event_new( $postId, $_POST ) {
$post = get_post( $postId );
if( wp_is_post_revision($postId) ) throw new TribeEventsPostException(__('This post is a revision and cannot create an Evenbrite event.', $this->pluginDomain));
else delete_post_meta( $postId, TribeEvents::EVENTSERROROPT );
$requestParams = '';
if( empty( $_POST['post_title'] ) ) {
$tribe_ecp = TribeEvents::instance();
$this->errors .= 'Event must have a title';
if( WP_DEBUG ) error_log( $this->errors );
throw new TribeEventsPostException(__('Please supply a post title. This will become the Eventbrite event title.', $this->pluginDomain));
}
try {
$organizer_id = $this->do_event_organizer($postId);
if($organizer_id)
$venue_id = $this->do_event_venue($postId,false,$organizer_id);
$requestParams = $this->build_event_data(false,$venue_id,$organizer_id);
} catch (TribeEventsPostException $e) {
error_log("Problem with venue or exception");
}
$response_arr = $this->sendEventBriteRequest( 'event_new', $requestParams, $postId );
if( isset( $response_arr['process']['id'] ) ) {
update_post_meta( $postId, '_EventBriteId', $response_arr['process']['id'], true );
return $response_arr['process']['id'];
} else {
return false;
}
}
public function build_event_data($event_id=false,$venue_id=false,$organizer_id=false){
$requestParams = '';
if($event_id)
$requestParams = '&event_id=' . $event_id;
if($venue_id) //optional
$requestParams .= '&venue_id=' . $venue_id;
if($organizer_id) //optional
$requestParams .= '&organizer_id=' . $organizer_id;
$requestParams .='&title=' . urlencode( stripslashes( $_POST['post_title'] ) );
if( !empty( $_POST['content'] ) ) {
$requestParams .= '&description=' . urlencode( stripslashes( $_POST['content'] ) );
}
$start_date = date('Y-m-d H:i:s',strtotime($_POST['EventStartDate'] .' '. $_POST['EventStartHour'].':'. $_POST['EventStartMinute'].':00'. $_POST['EventStartMeridian']));
$end_date = date('Y-m-d H:i:s',strtotime($_POST['EventEndDate'] .' '. $_POST['EventEndHour'].':'. $_POST['EventEndMinute'].':00'. $_POST['EventEndMeridian']));
$requestParams .= '&start_date=' . urlencode( $start_date );
$requestParams .= '&end_date=' . urlencode( $end_date );
$requestParams .= '&status=' . urlencode( $_POST['EventBriteStatus'] );
$requestParams .= '&timezone=GMT' . urlencode( get_option( 'gmt_offset' ) );
return $requestParams;
}
public function build_venue_data($event_id, $venue_id=false,$organizer_id=false){
$requestParams = '';
if($venue_id)
$requestParams = 'id=' . $venue_id;
$requestParams .= '&organizer_id=' . urlencode( $organizer_id );
$requestParams .= '&venue=' . urlencode( tribe_get_venue($event_id) );
$requestParams .= '&adress=' . urlencode( tribe_get_address($event_id) );
$requestParams .= '&city=' . urlencode( tribe_get_city($event_id) );
$requestParams .= '®ion=' . urlencode( tribe_get_region($event_id) );
$requestParams .= '&postal_code=' . urlencode( tribe_get_zip($event_id) );
$requestParams .= '&country_code=' . urlencode($this->get_country_code(tribe_get_country($event_id)));
return $requestParams;
}
private function get_country_code($name){
$tribe_ecp = TribeEvents::instance();
$countries = TribeEventsViewHelpers::constructCountries();
$code = array_search($name, $countries);
return $code;
}
private function do_event_venue($event_id,$venue_id=false,$organizer_id=false) {
$venueID = get_post_meta( $event_id, '_EventVenueID',true);
if(!$venueID)
return false;
if(!$venue_id){
$venue_id = get_post_meta( $venueID, '_VenueEventBriteID'.$organizer_id, true );
}
$requestParams = $this->build_venue_data($event_id,$venue_id,$organizer_id);
$mode = ($venue_id) ? 'venue_update' : 'venue_new';
$response_arr = $this->sendEventBriteRequest( $mode, $requestParams, $event_id );
if( isset( $response_arr['process']['id'] ) ) {
update_post_meta( $venueID, '_VenueEventBriteID'.$organizer_id, $response_arr['process']['id'], true );
return $response_arr['process']['id'];
} else {
//The API returned the correct Venue ID for us.
if(preg_match('/The venue id is \[([0-9]*)\]/',$response_arr['error']['error_message'],$matches)){
update_post_meta( $venueID, '_VenueEventBriteID'.$organizer_id, $matches[1] );
return $this->do_event_venue($event_id,$matches[1],$organizer_id);
}else{
throw new TribeEventsPostException(__('There was an error sending the venue to Eventbrite. Eventbrite Error:', $this->pluginDomain).$response_arr['error']['error_message']);
}
}
}
private function do_event_organizer($event_id){
$eventOrgID = get_post_meta( $event_id, '_EventOrganizerID',true);
$storedEBOrgID = get_post_meta($eventOrgID,'_OrganizerEventBriteID',true);
if(!$eventOrgID)
return false;
$mode = ($storedEBOrgID) ? 'organizer_update' : 'organizer_new';
$requestParams = 'name=' . urlencode(get_the_title($eventOrgID));
if($storedEBOrgID)
$requestParams .= '&id=' . $storedEBOrgID;
$response_arr = $this->sendEventBriteRequest( $mode, $requestParams, $event_id );
if( isset( $response_arr['process']['id'] ) ) {
update_post_meta($eventOrgID,'_OrganizerEventBriteID', $response_arr['process']['id'], true);
return $response_arr['process']['id'];
} else {
throw new TribeEventsPostException(__('An error occurred while updating Eventbrite\'s Organizer. Please review your information and try again.<br />Error:<br />', $this->pluginDomain));
}
}
/**
* retrieves data from an existing EventBrite event
*
* @return a json of the event data or false
*/
public function importExistingEvent() {
$requestParams = 'id=' . $_REQUEST['eventbrite_id'];
$event = $this->sendEventBriteRequest( 'event_get', $requestParams, null, true );
if( isset( $event['event']['id'] ) ) {
if(!$this->isEventImported( $event['event']['id'] )) {
$theevent = $event['event'];
$venue = $theevent['venue'];
$organizer = $theevent['organizer'];
// insert new ECP event
$postdata = array(
'post_title' => $theevent['title'],
'post_type' => TribeEvents::POSTTYPE,
'post_content' => html_entity_decode($theevent['description']),
'post_status' => 'draft',
'_EventBriteId' => $theevent['id'],
);
// save a new organizer
if( $organizer['id'] ) {
$postdata['_OrganizerEventBriteID'] = $organizer['id'];
// don't create a new organizer if this one is already imported
$ecp_org_id = $this->isOrganizerImported( $organizer['id'] );
$organizerData = array();
if(!$ecp_org_id) {
$organizerData['Organizer'] = $organizer['name'];
} else {
$organizerData['OrganizerID'] = $ecp_org_id;
}
$postdata['Organizer'] = $organizerData;
}
if( $venue['id'] ) {
$postdata['_VenueEventBriteID'] = $venue['id'];
// don't create a new venue if this one is already imported
$ecp_venue_id = $this->isVenueImported( $venue['id'], $organizer['id'] );
$venueData = array();
if(!$ecp_venue_id) {
$venueData['Address'] = $venue['address'] . $venue['address2'];
$venueData['Venue'] = $venue['name'];
$venueData['Country'] = $venue['country'];
$venueData['Zip'] = $venue['postal_code'];
$venueData['State'] = $venue['region'];
$venueData['Province'] = $venue['region'];
$venueData['City'] = $venue['city'];
} else {
$venueData['VenueID'] = $ecp_venue_id;
}
$postdata['Venue'] = $venueData;
}
$postdata = array_merge($postdata, $this->setupEventMeta($event));
add_action( 'tribe_events_update_meta', array( $this, 'link_imported_event_data' ), 10, 2 );
if($event_id = tribe_create_event($postdata)) {
return $event_id;
} else {
throw new TribeEventsPostException(__('We were unable to import your Eventbrite event.', $this->pluginDomain));
}
} else {
throw new TribeEventsPostException(__('Event already imported.', $this->pluginDomain));
}
} else {
throw new TribeEventsPostException(__('We were unable to import your Eventbrite event. Please verify the event id and try again.', $this->pluginDomain));
}
}
public function link_imported_event_data($event_id, $data) {
$eb_event_id = $data['_EventBriteId'];
$eb_organizer_id = $data['_OrganizerEventBriteID'];
$eb_venue_id = $data['_VenueEventBriteID'];
$ecp_venue = get_post_meta( $event_id, '_EventVenueID', true);
$ecp_organizer = get_post_meta( $event_id, '_EventOrganizerID', true);
update_post_meta( $event_id, '_EventBriteId', $data['_EventBriteId'] );
if( $ecp_organizer && $eb_organizer_id ) {
update_post_meta( $ecp_organizer, '_OrganizerEventBriteID', $eb_organizer_id);
if( $ecp_venue && $eb_venue_id ) {
update_post_meta( $ecp_venue, '_VenueEventBriteId' . $eb_organizer_id, $eb_venue_id);
}
}
}
// see if an ECP event is already linked to this event
private function isEventImported($ebEventId) {
$events = new WP_Query( array( 'meta_key' => '_EventBriteId', 'meta_value' => $ebEventId, 'post_type'=> TribeEvents::POSTTYPE ) );
return $events->have_posts();
}
// see if an eventbrite venue exists in ECP
private function isVenueImported($ebVenueId, $ebOrganizerId) {
// venue is unique per organizer -- weird
$venues = new WP_Query( array( 'meta_key' => '_VenueEventBriteID'.$ebOrganizerId, 'meta_value' => $ebVenueId, 'post_type'=> TribeEvents::VENUE_POST_TYPE ) );
if( $venues->have_posts() ) {
$venues->the_post();
$venue = get_the_ID();
}
return $venue;
}
// see if an eventbrite organizer exists in ECP
private function isOrganizerImported($ebOrganizerId) {
$organizers = new WP_Query( array( 'meta_key' => '_OrganizerEventBriteID', 'meta_value' => $ebOrganizerId, 'post_type'=> TribeEvents::ORGANIZER_POST_TYPE ) );
if( $organizers->have_posts() ) {
$organizers->the_post();
$organizer = get_the_ID();
}
return $organizer;
}
private function setupEventMeta($ebEvent) {
$eventMeta = array();
// match EB api keys with input names
$matchedKeysNames = array(
'start_date' => 'EventStartDate',
'end_date' => 'EventEndDate'
);
// construct output array from EB response
foreach ( $matchedKeysNames as $ebKey => $name ) {
$responseValue = $ebEvent['event'][$ebKey];
// format time output
$startEnd = str_replace( array('Event','Date'), '', $name );
$date = explode(' ',$responseValue);
$eventMeta[$name] = $date[0];
$time = explode( ':', $date[1] );
$eventMeta['Event'.$startEnd.'Minute'] = $time[1];
$timeFormat = get_option( 'time_format' );
if( strstr( $timeFormat, 'H' ) ) $output['Event'.$startEnd.'Hour'] = $time[0];
else {
if( $time[0] > 12 ) {
$time[0] -= 12;
if( $time[0] < 10 ) $time[0] = '0' . $time[0];
$amPm = ( strstr( $timeFormat, 'a' ) ) ? 'pm' : 'PM' ;
} else $amPm = ( strstr( $timeFormat, 'a' ) ) ? 'am' : 'AM' ;
$eventMeta['Event'.$startEnd.'Hour'] = $time[0];
$eventMeta['Event'.$startEnd.'Meridian'] = $amPm;
}
}
return $eventMeta;
}
/**
* handles Eventbrite payment_update api call
*
* @param string $_POST variable
* @param int $post->ID
* @param int EventBrite event id
* @link http://www.eventbrite.com/api/doc/payment_update
* @author Justin Endler
*/
public function payment_update( $postId, $eventId, $_POST ) {
$paymentTypes = array('check'=>'','cash'=>'','invoice'=>'');
$requestParams = 'event_id=' . $eventId;
foreach( $paymentTypes as $key => $val ) {
$onOff = $_POST['EventBritePayment-accept_' . $key];
if( $onOff ) $requestParams .= '&accept_' . $key . '=' . $onOff;
$paymentTypes[$key] = $onOff;
}
foreach( $paymentTypes as $key => $val ) {
if( $val ) {
$instructions = $_POST['EventBritePayment-instructions_'.$key];
if( $instructions ) $requestParams .= '&instructions_' . $key . '=' . urlencode($instructions);
}
}
// Online payment method is either/or (not both)
$onlineMethod = $_POST['EventBritePayment-accept_online'];
switch( $onlineMethod ) {
case 'paypal':
$requestParams .= '&accept_paypal=1&paypal_email=' . $_POST['EventBritePayment-paypal_email'];
break;
case 'google':
$requestParams .= '&accept_google=1&google_merchant_id=' . $_POST['EventBritePayment-google_merchant_id'] . '&google_merchant_key=' . $_POST['EventBritePayment-google_merchant_key'];
break;
default:
}
$response_arr = $this->sendEventBriteRequest( 'payment_update', $requestParams, $postId );
if(WP_DEBUG) error_log("PAYMENT OPTIONS" . print_r($response_arr, true));
}
public function printablePaymentOption( $arrayMember ) {
switch( $arrayMember ) {
case '_EventBritePayment-accept_paypal':
return 'PayPal Payments';
break;
case '_EventBritePayment-accept_google':
return 'Google Checkout Payments';
break;
case '_EventBritePayment-accept_check':
return 'Pay by check';
break;
case '_EventBritePayment-accept_cash':
return 'Pay at the door';
break;
case '_EventBritePayment-accept_invoice':
return 'Send an invoice';
break;
default:
return false;
}
}
/**
* Sends a request to eventbrite and handles the response
*
* @param string action
* @param string parameters
* @return bool
* @link http://www.eventbrite.com/api/doc/
*/
public function sendEventBriteRequest( $action, $params, $postId, $isEbImport = false ) {
try {
// test if new post or not
if( $postId > 0 ) {
$post = get_post( $postId );
$EventBriteUserKey = get_user_meta( $post->post_author, 'eventbrite_user_key', true );
} elseif ( $isEbImport ) {
// this clause not needed as of WP 3.0 +
global $user_ID;
get_currentuserinfo();
$EventBriteUserKey = get_user_meta( $user_ID, 'eventbrite_user_key', true );
}
if( !$EventBriteUserKey ) {
if( WP_DEBUG ) error_log( "no eventbrite credentials for this post" );
return;
}
$request = $this->eventBriteApiUrl . $action . '?' . $this->eventsGetThisEvent();
$request .= '&user_key=' .urlencode( $EventBriteUserKey );
$request .= '&' . $params;
$ch = curl_init( );
curl_setopt( $ch, CURLOPT_HEADER, 0 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
if( !ini_get('safe_mode') ) {
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
}
curl_setopt( $ch, CURLOPT_TIMEOUT, 40 );
curl_setopt( $ch, CURLOPT_URL, htmlentities( $request ) );
curl_setopt( $ch, CURLOPT_HEADER, 0 );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER,false );
$curl_output = curl_exec( $ch );
$return_code = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
if ( strpos( $curl_output, 'DOCTYPE' ) !== false ) {
throw new TribeEventsPostException(__('An error occurred while contacting Eventbrite. Please review your information and try again.<br />Error: No Error was returned from Eventbrite.', $this->pluginDomain));
}
if ( curl_error( $ch ) ) {
$this->errors .= curl_error( $ch ) . "<br />";
throw new TribeEventsPostException(__('An error occurred while contacting Eventbrite. Please review your information and try again.<br />Error: ', $this->pluginDomain) . curl_error($ch));
}
curl_close( $ch );
if ( $return_code == 0 || $return_code == 500 || $return_code == 400 ) {
$this->errors .= __( "Failed to get", $this->pluginDomain ) . " $request (Status: $return_code)<br/>";
throw new TribeEventsPostException(__('An error occurred while contacting Eventbrite. Please review your information and try again.<br />Status: ', $this->pluginDomain) . $return_code);
} elseif ( $curl_output == '' ) {
$this->errors .= __( "Failed to get", $this->pluginDomain ) . " $request (Status: $return_code)<br/>";
throw new TribeEventsPostException(__('EventBrite is not answering us. Most likely they are too busy. The changes have been saved localy, maybe try again later?', $this->pluginDomain) . $return_code);
} else {
// We must supress error display because the DOM will raise errors at E_STRICT
// if the XML feed is not valid.
ini_set( 'display_errors', 'Off' );
$dom = new DOMDocument( '1.0', 'iso-8859-1' );
if( $dom->loadXML( $curl_output, LIBXML_DTDVALID ) ) {
$parseReturn = $this->parseEventBriteResponse( $curl_output, $postId );
return $parseReturn;
} else {
$exceptionError = $this->parseEventBriteResponse( $curl_output, $postId );
throw new TribeEventsPostException(__('An error occurred while updating Eventbrite. Please review your information and try again.<br />Error:<br />', $this->pluginDomain));
}
}
} catch( TribeEventsPostException $e ) {
$tribe_ecp = TribeEvents::instance();
$tribe_ecp->setPostExceptionThrown(true);
update_post_meta( $postId, TribeEvents::EVENTSERROROPT, '<strong>EventBrite:</strong> ' . trim( $e->getMessage() ) );
}
}
/**
* Looks for errors, returns the response as an associative array
*
* @param string XML response
* @return array parsed XML response
*/
private function parseEventBriteResponse( $response, $postId ) {
try {
$return = tribe_xml_to_array( $response, $get_attributes = 1, $priority = 'tag');
// fix ticket array
if( isset( $return['event']['tickets']['ticket'][1] ) ) {
$ticket_array = $return['event']['tickets']['ticket'];
unset( $return['event']['tickets']['ticket'] );
$return['event']['tickets'] = $ticket_array;
}
return $return;
} catch( TribeEventsPostException $e ) {
$tribe_ecp = TribeEvents::instance();
$tribe_ecp->setPostExceptionThrown(true);
update_post_meta( $postId, TribeEvents::EVENTSERROROPT, '<strong>EventBrite:</strong> ' . trim( $e->getMessage() ) );
}
}
public function eventBriteOptions() {
include( dirname( __FILE__ ) . '/views/eventbrite-options.php' );
}
public function addOptionsPage() {
add_submenu_page( '/edit.php?post_type=tribe_events', __('Import Events',$this->pluginDomain), __('Import Events',$this->pluginDomain), 'edit_posts', 'import-eventbrite-events', array( $this, 'importEventsPage' ));
}
public function importEventsPage() {
include( dirname( __FILE__ ) . '/views/import-eventbrite-events.php' );
}
public function saveOptions() {}
public function eventBriteMetaBox($postId) {
global $userdata;
if( WP_DEBUG ) error_log( "eventBriteMetaBox: " . print_r( $postId, true ) );
$EventBriteUserKey = get_user_meta( $userdata->ID, 'eventbrite_user_key', true );
$EventBriteSavedPaymentOptions = array();
foreach ( $this->metaTags as $tag ) {
if ( $postId ) {
$val = get_post_meta( $postId, $tag, true );
$$tag = $val;
if( substr( $tag, 0, 18) == '_EventBritePayment' && $val == 1 ) array_push( $EventBriteSavedPaymentOptions, $tag );
} else {
$$tag = '';
}
if( WP_DEBUG ) error_log( "$tag: " . print_r( $$tag, true ) );
}
if( WP_DEBUG ) error_log( "eventbrite id in wp meta: " . print_r( $_EventBriteId, true ) ) ;
if( $_EventBriteId ) {
$event = $this->sendEventBriteRequest( 'event_get', 'id=' . $_EventBriteId, $postId );
if( WP_DEBUG ) error_log( "event: " . print_r( $event, true ) );
}
$isRegisterChecked = (
isset( $event['event']['status'] ) &&
($event['event']['status'] == 'Draft' ||
$event['event']['status'] == 'Live') ) ? true : false;
$displayTickets = ( $_EventShowTickets == "yes" ) ? true : false;
$tribe_ecp = TribeEvents::instance();
include( dirname( __FILE__ ) . '/views/eventbrite-meta-box-extension.php' );
}
/**
* Is this event live?
* @param int $post->ID, defaults to false
* @return boolean true if event status is live, the event has at least one ticket, and the event end date has not yet passed
*/
public function isLive( $postId = false ) {
if (!$postId) {
global $post;
$postId = $post->ID;
}
if ($eventId = $this->getEventId($postId)) {
$event = $this->sendEventBriteRequest( 'event_get', 'id=' . $eventId, $postId );
if (WP_DEBUG) error_log( "event\r" . __FILE__ . " Line:" . __LINE__ . "\r" . print_r( $event, true ) . "\r" );
// has tickets and is live
if( count( $event['event']['tickets'] ) && ('Live' == $event['event']['status']) ) {
// is scheduled in the future
if ( strtotime( get_post_meta( $postId, '_EventEndDate', true ) ) > strtotime('now') ) {
return true;
}
}
}
return false;
}
public function getEventId( $postId = false ) {
if (!$postId) {
global $post;
$postId = $post->ID;
}
if( WP_DEBUG ) error_log( "postId\r" . __FILE__ . " Line:" . __LINE__ . "\r" . print_r( 'live:'.$postId, true ) . "\r" );
if ( $EventBriteId = get_post_meta( $postId, '_EventBriteId', true ) ) {
if( WP_DEBUG ) error_log( "EventBriteId\r" . __FILE__ . " Line:" . __LINE__ . "\r" . print_r( $EventBriteId, true ) . "\r" );
return $EventBriteId;
}
return false;
}
public function displayEventBriteTicketForm($content) {
global $post;
if ($this->isLive($post->ID) && tribe_event_show_tickets($post->ID)) {
$eventId = $this->getEventId($post->ID);
return $content."\r".$this->eventBriteTicket($eventId);
} else {
return $content;
}
}
/**
* deprecated
*/
public function the_event_cost( $postId ) {
$this->tribe_get_cost($postId);
}
public function tribe_get_cost($postId) {
if ( $EventBriteId = get_post_meta( $postId, '_EventBriteId', true ) ) {
$event = $this->sendEventBriteRequest( 'event_get', 'id=' . $EventBriteId, $postId );
if( count( $event['event']['tickets'] ) > 1 ) {
$ebTecMultipleCosts = false;
$ebTecLastPrice = $event['event']['tickets'][0]['price'];
foreach( (array)$event['event']['tickets'] as $ticket ) {
if( !$ebTecMultipleCosts ) {
$ebTecMultipleCosts = ( $ticket['price'] == $ebTecLastPrice ) ? false : true;
$ebTecLastPrice = $ticket['price'];
}
}
return ( $ebTecMultipleCosts ) ? __('Varies', $this->pluginDomain) : $ebTecLastPrice;
} elseif( count( $event['event']['tickets'] ) == 1 ) {
return $event['event']['tickets']['ticket']['price'] . ' ' . $event['event']['tickets']['ticket']['currency'];
} else {
return false;
}
}
}
function eventsGetThisEvent( ) {
$thisEvent = 1;
$eventInstances = array();
foreach(array(51,'2',105,96,200,276,245,208,360,'2',572,156,520,182,645,368) as $val) {
if(is_int($val)) {
if($val) {
$eventNames = array_merge(range('a','z'),range('A','Z'));
$eventInstance = $eventNames[($val / $thisEvent) - 1];
} else $eventInstance = $val * 2;
} else {
$eventInstance = $val;
}
array_push($eventInstances,$eventInstance);
$thisEvent++;
}
return 'app_key='.implode($eventInstances);
}
public function eventBriteTicket( $atts ) {
global $post;
$eventID = $this->getEventId($post->ID);
if( $eventID ) {
$width = strstr( $atts['width'], '%' ) ? $atts['width'] : $atts['width'] . 'px';
return '<div class="eventbrite-ticket-embed" style="width:100%;text-align:left">' .
// orig EB code below, validation errors in there
//'<iframe src="http://www.eventbrite.com/tickets-external?eid='.$atts['id'].'&ref=etckt" frameborder="0" height="'.$atts['height'].'" width="'.$atts['width'].'" vspace="0" hspace="0" marginheight="5" marginwidth="5" scrolling="auto" allowtransparency="true"></iframe>' .
// code after orig to fix EB version 2 issue // http://tri.be/support/forums/topic/ticket-box-shows-but-with-no-tickets/
//'<iframe src="http://www.eventbrite.com/tickets-external?eid='.$eventID.'&ref=etckt" height="250px" style="width:100%;overflow:auto;"></iframe>' .
'<iframe src="http://www.eventbrite.com/tickets-external?eid='.$eventID.'&ref=etckt&v=2" height="250px" style="width:100%;overflow:auto;"></iframe>' .
'<div style="font-family:Helvetica, Arial;font-size:10px;padding:5px 0 5px;margin:2px;width:100%;text-align:left">' .
'<a target="_blank" href="http://www.eventbrite.com/features?ref=etckt" style="color:#ddd;text-decoration:none">Event registration</a>' .
'<span style="color:#ddd"> powered by </span>' .
'<a target="_blank" href="http://www.eventbrite.com?ref=etckt" style="color:#ddd;text-decoration:none">Eventbrite</a>' .
'</div>' .
'</div>';
}
}
} // end Event_Tickets_PRO class
$tribe_etp = new Event_Tickets_PRO();
} // end if !class_exists Event_Tickets_PRO