/**
  * Check to make sure that the event data is saved properly.
  *
  * @since 2.0.5
  * @author Paul Hughes
  */
 function test_tribe_create_event_API_meta_information()
 {
     $post = get_post(TribeEventsAPI::createEvent($this->postExampleSettings));
     $this->assertEquals(3, $post->post_author);
     $this->assertEquals('This is event content!', $post->post_content);
     $this->assertEquals('', get_post_meta($post->ID, '_EventAllDay', true));
     $this->assertEquals(1, get_post_meta($post->ID, '_EventHideFromUpcoming', true));
     $this->assertEquals(5, get_post_meta($post->ID, '_EventOrganizerID', true));
     $this->assertEquals(8, get_post_meta($post->ID, '_EventVenueID', true));
     $this->assertEquals(1, get_post_meta($post->ID, '_EventShowMapLink', true));
     $this->assertEquals(1, get_post_meta($post->ID, '_EventShowMapLink', true));
     $this->assertEquals(1, get_post_meta($post->ID, '_EventShowMap', true));
     $this->assertEquals('2012-01-01 01:15:00', get_post_meta($post->ID, '_EventStartDate', true));
     $this->assertEquals('2012-01-03 15:25:59', get_post_meta($post->ID, '_EventEndDate', true));
 }
示例#2
0
文件: event.php 项目: donwea/nhap.org
 /**
  * Create an Event
  *
  * $args accepts all the args that can be passed to wp_insert_post(). 
  * In addition to that, the following args can be passed specifically 
  * for the process of creating an Event:
  * 
  * - EventStartDate date string (required) - Start date of the Event.
  * - EventEndDate date string (required) - End date of the Event.
  * - EventAllDay bool - Set to true if event has no start / end time and should run all day.
  * - EventStartHour string - Event start hour (01 - 12).
  * - EventStartMinute string - Event start minute (01 - 60).
  * - EventStartMeridian string - Event start meridian (am or pm).
  * - EventEndHour string - Event end hour (01 - 12).
  * - EventEndMinute string - Event end minute (01 - 60).
  * - EventEndMeridian string - Event end meridian (am or pm).
  * - EventHideFromUpcoming bool - Set to true to hide this Event from the upcoming list view.
  * - EventShowMapLink bool - Set to true to display a link to the map in the Event view.
  * - EventShowMap bool - Set to true to embed the map in the Event view.
  * - EventCost string - Default cost of the Event.
  * - Venue array - Array of data to create or update an Venue to be associated with the Event. {@link tribe_create_venue}.
  * - Organizer array - Array of data to create or update an Organizer to be associated with the Event. {@link tribe_create_organizer}.
  * 
  * Note: If ONLY the 'VenueID'/'OrganizerID' value is set in the 'Venue'/'Organizer' array, 
  * then the specified Venue/Organizer will be associated with this Event without attempting 
  * to edit the Venue/Organizer. If NO 'VenueID'/'OrganizerID' is passed, but other Venue/Organizer
  * data is passed, then a new Venue/Organizer will be created.
  *
  * @param array $args Elements that make up post to insert.
  * @return int ID of the event that was created. False if insert failed.
  * @link http://codex.wordpress.org/Function_Reference/wp_insert_post
  * @see wp_insert_post()
  * @see tribe_create_venue()
  * @see tribe_create_organizer()
  * @category Event Functions
  * @since 2.0.1
  */
 function tribe_create_event($args)
 {
     $postId = TribeEventsAPI::createEvent($args);
     return $postId;
 }
 function import_meetup_events($atts)
 {
     $fetched = 0;
     $found = 0;
     $created = 0;
     $updated = 0;
     $content = '';
     //$content .= '<p>Remote host: ' . $_SERVER["REMOTE_ADDR"] . '</p>';
     $host = $_SERVER["REMOTE_ADDR"];
     $local_ip = getHostByName(getHostName());
     if (!current_user_can('manage_options') && $local_ip != $host) {
         $content .= '<div class="bimbler-alert-box error"><span>Error: </span>You must be an admin user to view this page.</div>';
         error_log('import_meetup_events called by non-admin or not from localhost.');
         return $content;
     }
     $a = shortcode_atts(array('api_key' => 7, 'group_id' => 0, 'create_if_not_found' => 'N', 'update_meta_if_found' => 'N', 'test' => 'Y'), $atts);
     if (!isset($a)) {
         error_log('import_meetup_events called with no parameters set.');
         $content .= '<div class="bimbler-alert-box error"><span>Error: </span>No parameters specified.</div>';
         return $content;
     }
     //error_log ('Post vars: ' . json_encode ($_POST));
     if (isset($_POST['bimbler-run-job'])) {
         error_log('Run job clicked.');
         $a['test'] = 'N';
     }
     // Work around the UTC bug...
     date_default_timezone_set('Australia/Brisbane');
     $date_from = date('Y-m-d', strtotime($a['ahead'] . ' days'));
     $date_to = date('Y-m-d', strtotime($a['ahead'] + 1 . ' days'));
     $content .= '<h5>Input Parameters</h5>';
     $content .= 'Group ID: ' . $a['group_id'] . '<br>';
     $content .= 'API Key: ' . $a['api_key'] . '<br>';
     $content .= 'Test mode: ' . $a['test'] . '<br>';
     $content .= 'Create new: ' . $a['create_if_not_found'] . '<br>';
     $content .= 'Update meta: ' . $a['update_meta_if_found'] . '<br><br>';
     $output = '';
     // What does this app do today?
     $create_if_not_found = false;
     $update_meta_if_found = false;
     if ('Y' == $a['create_if_not_found']) {
         $create_if_not_found = true;
     }
     if ('Y' == $a['update_meta_if_found']) {
         $update_meta_if_found = true;
     }
     $test_mode = false;
     if ('Y' == $a['test']) {
         $test_mode = true;
     }
     $import = $this->fetch_meetup_events($a['group_id'], $a['api_key']);
     // Who are are running as?
     $this_user_id = $this->get_current_user_id();
     //$content .= 'Running as user ID: ' . $this_user_id . '<br><br>';
     $content .= '<h4>Output:</h4>';
     $content .= $import->output;
     $content .= '<br>';
     $fetched = count($import->events);
     $content .= 'Fetched ' . $fetched . ' events.<br>';
     if ($fetched > 0) {
         $i = 1;
         foreach ($import->events as $event) {
             // Create new member, containing parsed date.
             $event->event_date = date('Y-m-d H:i:s', $this->get_event_date($event));
             $content .= $i++ . ': ' . $event->id . ' -> ' . $event->name . ' on ' . $event->event_date;
             // $content .= '<br>';
             // See if this event already exists.
             $get_posts = tribe_get_events(array('eventDisplay' => 'custom', 'posts_per_page' => 1, 'post_status' => array('publish', 'draft'), 'meta_query' => array(array('key' => '_EventStartDate', 'value' => $event->event_date, 'compare' => '=', 'type' => 'datetime')), 'tax_query' => array(array('taxonomy' => TribeEvents::TAXONOMY, 'field' => 'slug', 'terms' => 'mingle'))));
             $content .= '&nbsp;--';
             //error_log (json_encode ($get_posts));
             // Got the same event (or at least, *a* Mingle starting at the same time).
             if (!empty($get_posts)) {
                 $found++;
                 $this_event = $get_posts[0];
                 //$content .= '<pre>' . json_encode ($this_event, true) . '</pre>';
                 // $content .= ' Found: ' . $this_event->post_title . ' on ' . tribe_get_start_date($this_event->ID, false, 'Y-m-d H:i:s') . '.';
                 $content .= ' Found: post ID <a href="' . get_permalink($this_event->ID) . '" target="_external">' . $this_event->ID . '</a>.<br>';
                 // We're updating existing events - backfill data.
                 if ($update_meta_if_found) {
                     // Event found, but not with a Meetup ID.
                     if (!get_post_meta($this_event->ID, 'bimbler_meetup_id', true)) {
                         if (!$test_mode) {
                             // Update with Meetup ID if it's not already set
                             update_post_meta($this_event->ID, 'bimbler_meetup_id', $event->id);
                             $content .= '<font color="orange">&nbsp;-- Updated Meetup ID.</font> ';
                         } else {
                             $content .= '<font color="orange">&nbsp;-- Test mode - Meetup ID not updated. </font>';
                         }
                         $updated++;
                     } else {
                         $content .= '<font color="green">&nbsp;-- Existing event with Meetup ID set - no action to take.</font>';
                         // See if we need to update date / time.
                         // Can't do this, as the query loop is searching by date / time.
                         /*								$curr_start_date = tribe_get_start_date($event->ID, false, 'Y-m-d H:i:s');
                         								$curr_end_date = tribe_get_end_date($event->ID, false, 'Y-m-d H:i:s');
                         								
                         								if ($curr_start_date != $event->event_date) {
                         									$content .= ' Meetup start time not same as here (' . $curr_start_date . ' -> ' . $event->event_date);  
                         								} */
                     }
                 } else {
                     $content .= '<font color="green">&nbsp;-- Not running in "Update Meetup ID if found" mode - no action taken.</font>';
                 }
             } else {
                 // No mingler event found at that time on that day.
                 if ($create_if_not_found) {
                     //$content .= '<pre>' . print_r ($event, true) . '</pre>';
                     //$new_event = new stdClass();
                     $new_event = array();
                     $new_event['EventStartDate'] = date('Y-m-d', strtotime($event->event_date));
                     $new_event['EventStartHour'] = date('h', strtotime($event->event_date));
                     $new_event['EventStartMinute'] = date('i', strtotime($event->event_date));
                     if (isset($event->duration)) {
                         //$content .= ' Adding ' . $event->duration / 1000 . ' seconds ';
                         $new_event['EventEndDate'] = date('Y-m-d', strtotime($event->event_date . ' + ' . $event->duration / 1000 . ' seconds'));
                         $new_event['EventEndHour'] = date('h', strtotime($event->event_date . ' + ' . $event->duration / 1000 . ' seconds'));
                         $new_event['EventEndMinute'] = date('i', strtotime($event->event_date . ' + ' . $event->duration / 1000 . ' seconds'));
                     } else {
                         // Add an abitrary 2 hours to the start time to get the end time.
                         $new_event['EventEndDate'] = date('Y-m-d', strtotime($event->event_date . ' + 2 hours'));
                         $new_event['EventEndHour'] = date('h', strtotime($event->event_date . ' + 2 hours'));
                         $new_event['EventEndMinute'] = date('i', strtotime($event->event_date . ' + 2 hours'));
                     }
                     $content .= '<br><font color="red">&nbsp;-- Creating new event.</font>';
                     //$content .= '<pre>' . print_r ($new_event, true) . '</pre>';
                     $new_event['post_status'] = 'draft';
                     $new_event['author'] = $this_user_id;
                     $new_event['post_title'] = $event->name;
                     $new_event['post_content'] = $event->description;
                     // XXXXX REMOVE SECOND TERM WHEN FINISHED TESTING XXXX
                     //if (!$test_mode && ($created < 1)) {
                     if (!$test_mode) {
                         $new_event_id = TribeEventsAPI::createEvent($new_event);
                         // Copy the taxonomies.
                         $taxonomies = get_object_taxonomies('tribe_events');
                         foreach ($taxonomies as $tax) {
                             $terms = wp_get_object_terms($event_id, $tax);
                             $term = array();
                             foreach ($terms as $t) {
                                 $term[] = $t->slug;
                             }
                             wp_set_object_terms($new_event_id, $term, $tax);
                         }
                         // Update with Meetup ID.
                         update_post_meta($new_event_id, 'bimbler_meetup_id', $event->id);
                         $tribe_ecp = TribeEvents::instance();
                         // Set this to a Mingle.
                         $term_info = get_term_by('slug', 'mingle', $tribe_ecp->get_event_taxonomy());
                         wp_set_object_terms($new_event_id, $term_info->term_id, $term_info->taxonomy);
                         $content .= ' New event ID: <a href="' . get_permalink($new_event_id) . '" target="_external">' . $new_event_id . '</a>';
                     } else {
                         $content .= '<font color="orange">&nbsp;-- Test mode - Event not created. </font>';
                     }
                     $created++;
                 } else {
                     // End create_if_not_found.
                     $content .= '<font color="green"><br>&nbsp;-- Not running in "Create if not found" mode - no action taken.</font>';
                 }
             }
             $content .= '<br>';
         }
     }
     $summary = 'import_meetup_events: fetched: ' . $fetched . ', found: ' . $found . ', created: ' . $created . ', updated: ' . $updated . '.';
     $content .= '<br>' . $summary;
     error_log($summary);
     return $content;
 }
 protected function create_post(array $record)
 {
     $event = $this->build_event_array($record);
     $id = TribeEventsAPI::createEvent($event);
     return $id;
 }
 /**
  * Create an event.
  *
  * @return int The created event's ID.
  * @author Nick Ciske
  * @since 1.0
  */
 public function createEvent()
 {
     $tribe_event_id = TribeEventsAPI::createEvent($_POST);
     $this->save_submitted_attachment($tribe_event_id);
     // TODO: instead of this, we should properly filter current_user_can($taxonomy_obj->cap->assign_terms) in wp_insert_post()
     if (!is_user_logged_in() && isset($_POST['tax_input'])) {
         foreach ((array) $_POST['tax_input'] as $taxonomy => $terms) {
             wp_set_post_terms($tribe_event_id, $terms, $taxonomy, true);
         }
     }
     return $tribe_event_id;
 }
示例#6
0
 /**
  * Create an Event
  *
  * $args accepts all the args that can be passed to wp_insert_post().
  * In addition to that, the following args can be passed specifically
  * for the process of creating an Event:
  *
  * - EventStartDate date string (required) - Start date of the Event.
  * - EventEndDate date string (required) - End date of the Event.
  * - EventAllDay bool - Set to true if event has no start / end time and should run all day.
  * - EventStartHour string - Event start hour (01 - 12).
  * - EventStartMinute string - Event start minute (01 - 60).
  * - EventStartMeridian string - Event start meridian (am or pm).
  * - EventEndHour string - Event end hour (01 - 12).
  * - EventEndMinute string - Event end minute (01 - 60).
  * - EventEndMeridian string - Event end meridian (am or pm).
  * - EventHideFromUpcoming bool - Set to true to hide this Event from the upcoming list view.
  * - EventShowMapLink bool - Set to true to display a link to the map in the Event view.
  * - EventShowMap bool - Set to true to embed the map in the Event view.
  * - EventCost string - Default cost of the Event.
  * - Venue array - Array of data to create or update an Venue to be associated with the Event. {@link tribe_create_venue}.
  * - Organizer array - Array of data to create or update an Organizer to be associated with the Event. {@link tribe_create_organizer}.
  *
  * Note: If ONLY the 'VenueID'/'OrganizerID' value is set in the 'Venue'/'Organizer' array,
  * then the specified Venue/Organizer will be associated with this Event without attempting
  * to edit the Venue/Organizer. If NO 'VenueID'/'OrganizerID' is passed, but other Venue/Organizer
  * data is passed, then a new Venue/Organizer will be created.
  *
  * Also note that this function can be used only for the creation of events, supplying
  * a post_type argument therefore is superfluous as it will be reset to the events post
  * type in any case.
  *
  * @param array $args Elements that make up post to insert.
  *
  * @return int ID of the event that was created. False if insert failed.
  * @link     http://codex.wordpress.org/Function_Reference/wp_insert_post
  * @see      wp_insert_post()
  * @see      tribe_create_venue()
  * @see      tribe_create_organizer()
  * @category Event Functions
  */
 function tribe_create_event($args)
 {
     $args['post_type'] = TribeEvents::POSTTYPE;
     $postId = TribeEventsAPI::createEvent($args);
     return $postId;
 }