예제 #1
0
 public function setUp()
 {
     parent::setUp();
     $this->event_ids = array();
     $event_id = $this->factory->event->create(array('start' => new DateTime('2015-03-21 19:30:00', eo_get_blog_timezone()), 'end' => new DateTime('2015-03-21 20:30:00', eo_get_blog_timezone()), 'schedule' => 'daily', 'schedule_last' => new DateTime('2015-03-24 19:30:00', eo_get_blog_timezone())));
     //Now insert another event before the rest, so that the first (chronological) occurrence is
     //not the first in the database for this series.
     eo_update_event($event_id, array('include' => array(new DateTime('2015-03-20 19:30:00', eo_get_blog_timezone()))));
     $this->event_ids[] = $event_id;
     $this->event_ids[] = $this->factory->event->create(array('start' => new DateTime('2015-03-02 14:00:00', eo_get_blog_timezone()), 'end' => new DateTime('2015-03-02 15:00:00', eo_get_blog_timezone()), 'schedule' => 'weekly', 'schedule_last' => new DateTime('2015-03-30 14:00:00', eo_get_blog_timezone())));
     $this->event_ids[] = $this->factory->event->create(array('start' => new DateTime('2015-03-23 09:45:00', eo_get_blog_timezone()), 'end' => new DateTime('2015-03-23 10:00:00', eo_get_blog_timezone()), 'schedule' => 'daily', 'schedule_last' => new DateTime('2015-03-27 09:45:00', eo_get_blog_timezone())));
 }
예제 #2
0
/**
 * For this to work you need to add the following to the custom field exceptions on the ThreeWP settings page:
 *
 * _eventorganiser_event_schedule
 * _eventorganiser_schedule_start_start
 * _eventorganiser_schedule_start_finish
 *_eventorganiser_schedule_last_start
 *_eventorganiser_schedule_last_finish
 *
 * @access private
 * @ignore
 *
*/
function eventorganiser_threeWP($activity)
{
    if (isset($activity['activity_id']) && $activity['activity_id'] == '3broadcast_broadcasted' && 'event' == get_post_type(get_the_ID())) {
        $details = $activity['activity_details'];
        $current_blog_id = get_current_blog_id();
        $original_id = get_the_ID();
        $original_cats = get_the_terms($original_id, 'event-category');
        $original_venue_id = eo_get_venue($original_id);
        //Venue Meta &Thumbnail
        $venue_meta = eo_get_venue_meta($original_venue_id, '', false);
        if ($original_venue_id && ($venue_thumbnail_id = eo_get_venue_meta($original_venue_id, '_eventorganiser_thumbnail_id', true))) {
            $original_upload_dir = wp_upload_dir();
            $metadata = wp_get_attachment_metadata($venue_thumbnail_id);
            $data = get_post($venue_thumbnail_id);
            $file = $metadata['file'];
            $guid = $data->guid;
            $post_title = $data->post_title;
            $menu_order = $data->menu_order;
            $post_excerpt = $data->post_excerpt;
            $filename_base = basename($metadata['file']);
            $filename_path = $original_upload_dir['basedir'] . '/' . $metadata['file'];
            $venue_thumbnail = compact('filename_path', 'file', 'filename_base', 'post_title', 'guid', 'menu_order', 'post_excerpt');
            unset($venue_meta['_eventorganiser_thumbnail_id']);
        }
        foreach ($details as $broadcast) {
            $blog_id = $broadcast['blog_id'];
            $post_id = $broadcast['post_id'];
            switch_to_blog($blog_id);
            $event_data = array('force_regenerate_dates' => true);
            eo_update_event($post_id, $event_data);
            $venue_id = eo_get_venue($post_id);
            //Delete old venue meta
            if ($old_meta = eo_get_venue_meta($venue_id, '', false)) {
                $old_meta_keys = array_keys($old_meta);
                foreach ($old_meta_keys as $key) {
                    eo_delete_venue_meta($venue_id, $key);
                }
            }
            //Add new venue  meta
            foreach ($venue_meta as $key => $values) {
                foreach ($values as $value) {
                    eo_add_venue_meta($venue_id, $key, $value);
                }
            }
            //Sync cat colours
            $cats = get_the_terms($post_id, 'event-category');
            foreach ($cats as $cat) {
                //Find original cat
                foreach ($original_cats as $original_cat) {
                    if ($original_cat->slug == $cat->slug) {
                        $re = update_option("eo-event-category_{$cat->term_id}", array('colour' => $original_cat->color));
                        break;
                    }
                }
            }
            //Sync venue thumbnails
            $upload_dir = wp_upload_dir();
            if (file_exists($venue_thumbnail['filename_path'])) {
                $file_path = $upload_dir['path'] . '/' . $venue_thumbnail['filename_base'];
                // Copy the file to the blog's upload directory
                copy($venue_thumbnail['filename_path'], $file_path);
                if (false == ($attachment_id = eventorganiser_file_to_attachment($venue_thumbnail['file']))) {
                    // And now create the attachment stuff.
                    // This is taken almost directly from http://codex.wordpress.org/Function_Reference/wp_insert_attachment
                    $wp_filetype = wp_check_filetype($venue_thumbnail['filename_base'], null);
                    $attachment = array('guid' => $upload_dir['url'] . '/' . $venue_thumbnail['filename_base'], 'menu_order' => $venue_thumbnail['menu_order'], 'post_excerpt' => $venue_thumbnail['post_excerpt'], 'post_mime_type' => $wp_filetype['type'], 'post_title' => $venue_thumbnail['post_title'], 'post_status' => 'inherit');
                    $attachment_id = wp_insert_attachment($attachment, $file_path, 0);
                    // Now to handle the metadata.
                    require_once ABSPATH . "wp-admin" . '/includes/image.php';
                    $attach_data = wp_generate_attachment_metadata($attachment_id, $file_path);
                    wp_update_attachment_metadata($attachment_id, $attach_data);
                }
                //If attachment post doesn't exist
                eo_update_venue_meta($venue_id, '_eventorganiser_thumbnail_id', $attachment_id);
            }
            //If original file exists
        }
        //Foreach blog
        switch_to_blog($current_blog_id);
    }
    //If broadcasting
}
예제 #3
0
/**
 * Saves the event data posted from the event metabox.
 * Hooked to the 'save_post' action
 * 
 * @since 1.0.0
 *
 * @param int $post_id the event post ID
 * @return int $post_id the event post ID
 */
function eventorganiser_details_save($post_id)
{
    //make sure data came from our meta box
    if (!isset($_POST['_eononce']) || !wp_verify_nonce($_POST['_eononce'], 'eventorganiser_event_update_' . $post_id . '_' . get_current_blog_id())) {
        return;
    }
    //verify this is not an auto save routine.
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    //authentication checks
    if (!current_user_can('edit_event', $post_id)) {
        return;
    }
    //Collect raw data
    $raw_data = isset($_POST['eo_input']) ? $_POST['eo_input'] : array();
    $raw_data = wp_parse_args($raw_data, array('StartDate' => '', 'EndDate' => '', 'StartTime' => '00:00', 'FinishTime' => '23:59', 'schedule' => 'once', 'event_frequency' => 1, 'schedule_end' => '', 'allday' => 0, 'schedule_meta' => '', 'days' => array(), 'include' => '', 'exclude' => ''));
    //Update venue
    $venue_id = !empty($raw_data['event-venue']) ? intval($raw_data['event-venue']) : null;
    //Maybe create a new venue
    if (empty($venue_id) && !empty($_POST['eo_venue']) && current_user_can('manage_venues')) {
        $venue = $_POST['eo_venue'];
        if (!empty($venue['name'])) {
            $new_venue = eo_insert_venue($venue['name'], $venue);
            if (!is_wp_error($new_venue)) {
                $venue_id = $new_venue['term_id'];
            } else {
                if ($new_venue->get_error_code() == 'term_exists') {
                    $venue_id = eo_get_venue($event_id);
                }
            }
        }
    }
    //Set venue
    $r = wp_set_post_terms($post_id, array($venue_id), 'event-venue', false);
    //If reocurring, but not editing occurrences, can abort here, but trigger hook.
    if (eo_reoccurs($post_id) && (!isset($raw_data['AlterRe']) || 'yes' != $raw_data['AlterRe'])) {
        /**
         * Triggered after an event has been updated.
         *
         * @param int $post_id The ID of the event
         */
        do_action('eventorganiser_save_event', $post_id);
        //Need this to update cache
        return;
    }
    //Check dates
    $date_format = eventorganiser_get_option('dateformat');
    $is24 = eventorganiser_blog_is_24();
    $time_format = $is24 ? 'H:i' : 'g:ia';
    $datetime_format = $date_format . ' ' . $time_format;
    //Set times for all day events
    $all_day = intval($raw_data['allday']);
    if ($all_day) {
        $raw_data['StartTime'] = $is24 ? '00:00' : '12:00am';
        $raw_data['FinishTime'] = $is24 ? '23:59' : '11:59pm';
    }
    $start = eo_check_datetime($datetime_format, trim($raw_data['StartDate']) . ' ' . trim($raw_data['StartTime']));
    $end = eo_check_datetime($datetime_format, trim($raw_data['EndDate']) . ' ' . trim($raw_data['FinishTime']));
    $until = eo_check_datetime($datetime_format, trim($raw_data['schedule_end']) . ' ' . trim($raw_data['StartTime']));
    //Collect schedule meta
    $schedule = $raw_data['schedule'];
    if ('weekly' == $schedule) {
        $schedule_meta = $raw_data['days'];
        $occurs_by = '';
    } elseif ('monthly' == $schedule) {
        $schedule_meta = $raw_data['schedule_meta'];
        $occurs_by = trim($schedule_meta, '=');
    } else {
        $schedule_meta = '';
        $occurs_by = '';
    }
    //Collect include/exclude
    $in_ex = array();
    $orig_schedule = eo_get_event_schedule($post_id);
    foreach (array('include', 'exclude') as $key) {
        $in_ex[$key] = array();
        $arr = explode(',', sanitize_text_field($raw_data[$key]));
        if (!empty($arr)) {
            foreach ($arr as $date) {
                if ($date_obj = eo_check_datetime('Y-m-d', trim($date))) {
                    $date_obj->setTime($start->format('H'), $start->format('i'));
                    $in_ex[$key][] = $date_obj;
                }
            }
            /* see https://github.com/stephenharris/Event-Organiser/issues/260
            			if( $orig = array_uintersect( $orig_schedule[$key], $in_ex[$key], '_eventorganiser_compare_dates' ) ){
            				$in_ex[$key] = array_merge( $orig, $in_ex[$key] );
            				$in_ex[$key] = _eventorganiser_remove_duplicates( $in_ex[$key] );
            			}*/
        }
    }
    $event_data = array('start' => $start, 'end' => $end, 'all_day' => $all_day, 'schedule' => $schedule, 'frequency' => (int) $raw_data['event_frequency'], 'until' => $until, 'schedule_meta' => $schedule_meta, 'occurs_by' => $occurs_by, 'include' => $in_ex['include'], 'exclude' => $in_ex['exclude']);
    $response = eo_update_event($post_id, $event_data);
    if (is_wp_error($response)) {
        global $EO_Errors;
        $code = $response->get_error_code();
        $message = $response->get_error_message($code);
        $errors[$post_id][] = __('Event dates were not saved.', 'eventorganiser');
        $errors[$post_id][] = $message;
        $EO_Errors->add('eo_error', $message);
        update_option('eo_notice', $errors);
    }
    return;
}
예제 #4
0
 /**
  * @see https://github.com/stephenharris/Event-Organiser/issues/242 
  */
 function testDuplicatePostCompatability()
 {
     $tz = eo_get_blog_timezone();
     $start = new DateTime('2015-02-12 14:45:00', $tz);
     $end = new DateTime('2015-02-12 15:45:00', $tz);
     $event = array('start' => $start, 'end' => $end, 'frequency' => 1, 'schedule' => 'weekly', 'schedule_meta' => array('TH'), 'schedule_last' => new DateTime('2015-02-26 14:45:00', $tz));
     $event_id = $this->factory->event->create($event);
     $event_post = get_post($event_id);
     $duplicated_event_id = $this->duplicate($event_post);
     $this->duplicate_metadata($duplicated_event_id, $event_post);
     eo_update_event($duplicated_event_id);
     //Check occurrences of duplicate event exist
     $expected = array(new DateTime('2015-02-12 14:45:00', $tz), new DateTime('2015-02-19 14:45:00', $tz), new DateTime('2015-02-26 14:45:00', $tz));
     $actual = eo_get_the_occurrences($duplicated_event_id);
     $actual = array_values($actual);
     $this->assertEquals($expected, $actual);
 }
예제 #5
0
 public function testScheduleLastUpdate()
 {
     $event_data = array('start' => new DateTime('2013-10-22 19:19:00', eo_get_blog_timezone()), 'end' => new DateTime('2013-10-22 20:19:00', eo_get_blog_timezone()), 'schedule' => 'daily', 'frequency' => 2, 'until' => new DateTime('2013-10-26 19:19:00', eo_get_blog_timezone()));
     $event = eo_insert_event($event_data);
     eo_update_event($event, array('include' => array(new DateTime('2013-10-25 19:19:00', eo_get_blog_timezone()))));
     $schedule = eo_get_event_schedule($event);
     $this->assertEquals(new DateTime('2013-10-26 19:19:00', eo_get_blog_timezone()), $schedule['until']);
 }
예제 #6
0
 function update_object($post_id, $fields)
 {
     $fields['ID'] = $post_id;
     return eo_update_event($fields);
 }
예제 #7
0
/**
 * Updates a specific occurrence, and preserves the occurrence ID. 
 * 
 * Currently two occurrences cannot occupy the same date.
 * 
 * @ignore
 * @access private
 * @since 2.12.0
 * 
 * @param int $event_id      ID of the event whose occurrence we're moving
 * @param int $occurrence_id ID of the occurrence we're moving
 * @param DateTime $start    New start DateTime of the occurrence
 * @param DateTime $end      New end DateTime of the occurrence
 * @return bool|WP_Error True on success. WP_Error on failure.
 */
function eventorganiser_move_occurrence($event_id, $occurrence_id, $start, $end)
{
    global $wpdb;
    $old_start = eo_get_the_start(DATETIMEOBJ, $event_id, null, $occurrence_id);
    $schedule = eo_get_event_schedule($event_id);
    if ($start == $old_start) {
        return true;
    }
    $current_occurrences = eo_get_the_occurrences($event_id);
    unset($current_occurrences[$occurrence_id]);
    $current_occurrences = array_map('eo_format_datetime', $current_occurrences);
    if (in_array($start->format('d-m-Y'), $current_occurrences)) {
        return new WP_Error('events-cannot-share-date', __('There is already an occurrence on this date', 'eventorganiser'));
    }
    //We update the date directly in the DB first so the occurrence is not deleted and recreated,
    //but simply updated.
    $wpdb->update($wpdb->eo_events, array('StartDate' => $start->format('Y-m-d'), 'StartTime' => $start->format('H:i:s'), 'EndDate' => $end->format('Y-m-d'), 'FinishTime' => $end->format('H:i:s')), array('event_id' => $occurrence_id));
    wp_cache_delete('eventorganiser_occurrences_' . $event_id);
    //Important: update DB clear cache
    //Now update event schedule...
    //If date being removed was manually included remove it,
    //otherwise add it to exclude. Then add new date as include.
    if (false === ($index = array_search($old_start, $schedule['include']))) {
        $schedule['exclude'][] = $old_start;
    } else {
        unset($schedule['include'][$index]);
    }
    $schedule['include'][] = $start;
    $re = eo_update_event($event_id, $schedule);
    if ($re && !is_wp_error($re)) {
        return true;
    }
    return $re;
}
 /**
  * Update and EO event, given a CiviEvent. If no EO event exists
  * then create one. This will NOT create sequences and is intended for the
  * initial migration of CiviEvents to WordPress
  *
  * @since 0.1
  *
  * @param array $civi_event An array of data for the CiviEvent
  * @return int $event_id The numeric ID of the event
  */
 public function update_event($civi_event)
 {
     /*
     error_log( print_r( array(
     	'method' => __METHOD__,
     	'civi_event' => $civi_event,
     ), true ) );
     */
     // define schedule
     $event_data = array('start' => new DateTime($civi_event['start_date'], eo_get_blog_timezone()), 'end' => new DateTime($civi_event['end_date'], eo_get_blog_timezone()), 'schedule_last' => new DateTime($civi_event['end_date'], eo_get_blog_timezone()), 'frequency' => 1, 'all_day' => 0, 'schedule' => 'once');
     // define post
     $post_data = array('post_title' => $civi_event['title'], 'post_content' => isset($civi_event['description']) ? $civi_event['description'] : '', 'post_excerpt' => isset($civi_event['summary']) ? $civi_event['summary'] : '', 'to_ping' => '', 'pinged' => '', 'post_content_filtered' => '');
     // test for created date, which may be absent
     if (isset($civi_event['created_date']) and !empty($civi_event['created_date'])) {
         // create DateTime object
         $datetime = new DateTime($civi_event['created_date'], eo_get_blog_timezone());
         // add it, but format it first since Civi seems to send data in the form 20150916135435
         $post_data['post_date'] = $datetime->format('Y-m-d H:i:s');
     }
     // assume the CiviEvent is live
     $post_data['post_status'] = 'publish';
     // is the event active?
     if ($civi_event['is_active'] == 0) {
         // make the CiviEvent unpublished
         $post_data['post_status'] = 'draft';
     }
     // init venue as undefined
     $venue_id = 0;
     // get location ID
     if (isset($civi_event['loc_block_id'])) {
         // we have a location...
         // get location data
         $location = $this->plugin->civi->get_location_by_id($civi_event['loc_block_id']);
         // get corresponding EO venue ID
         $venue_id = $this->plugin->eo_venue->get_venue_id($location);
         // did we get one?
         if ($venue_id === false) {
             // no, let's create one
             $venue_id = $this->plugin->eo_venue->create_venue($location);
         } else {
             // yes, update it
             $venue_id = $this->plugin->eo_venue->update_venue($location);
         }
     }
     // init category as undefined
     $terms = array();
     // get location ID
     if (isset($civi_event['event_type_id'])) {
         // we have a category...
         //print_r( $this->plugin->civi->get_event_types() ); die();
         // get event type data for this pseudo-ID (actually "value")
         $type = $this->plugin->civi->get_event_type_by_value($civi_event['event_type_id']);
         // does this type have an existing term?
         $term_id = $this->get_term_id($type);
         // if not...
         if ($term_id === false) {
             // create one
             $term = $this->create_term($type);
             // assign term ID
             $term_id = $term['term_id'];
         }
         // define as array
         $terms = array(absint($term_id));
     }
     // add to post data
     $post_data['tax_input'] = array('event-venue' => array(absint($venue_id)), 'event-category' => $terms);
     /*
     error_log( print_r( array(
     	'method' => __METHOD__,
     	'post_data' => $post_data,
     	'type' => isset( $type ) ? $type : 'NOT SET',
     ) ); die();
     */
     // do we have a post ID for this event?
     $eo_post_id = $this->plugin->db->get_eo_event_id_by_civi_event_id($civi_event['id']);
     // remove hooks
     remove_action('wp_insert_post', array($this, 'insert_post'), 10);
     remove_action('eventorganiser_save_event', array($this, 'intercept_save_event'), 10);
     // did we get a post ID?
     if ($eo_post_id === false) {
         // use EO's API to create event
         $event_id = eo_insert_event($post_data, $event_data);
     } else {
         // use EO's API to update event
         $event_id = eo_update_event($eo_post_id, $post_data, $event_data);
     }
     // re-add hooks
     add_action('wp_insert_post', array($this, 'insert_post'), 10, 2);
     add_action('eventorganiser_save_event', array($this, 'intercept_save_event'), 10, 1);
     // --<
     return $event_id;
 }
예제 #9
0
/**
 * Saves the event data posted from the event metabox.
 * Hooked to the 'save_post' action
 * 
 * @since 1.0.0
 *
 * @param int $post_id the event post ID
 * @return int $post_id the event post ID
 */
function eventorganiser_details_save($post_id)
{
    //make sure data came from our meta box
    if (!isset($_POST['_eononce']) || !wp_verify_nonce($_POST['_eononce'], 'eventorganiser_event_update_' . $post_id)) {
        return;
    }
    // verify this is not an auto save routine.
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    //authentication checks
    if (!current_user_can('edit_event', $post_id)) {
        return;
    }
    //Collect raw data
    $raw_data = isset($_POST['eo_input']) ? $_POST['eo_input'] : array();
    $raw_data = wp_parse_args($raw_data, array('StartDate' => '', 'EndDate' => '', 'StartTime' => '00:00', 'FinishTime' => '23:59', 'schedule' => 'once', 'event_frequency' => 1, 'schedule_end' => '', 'allday' => 0, 'schedule_meta' => '', 'days' => array(), 'include' => '', 'exclude' => ''));
    //Update venue
    $venue_id = !empty($raw_data['event-venue']) ? intval($raw_data['event-venue']) : null;
    //Maybe create a new venue
    if (empty($venue_id) && !empty($_POST['eo_venue']) && current_user_can('manage_venues')) {
        $venue = $_POST['eo_venue'];
        if (!empty($venue['name'])) {
            $new_venue = eo_insert_venue($venue['name'], $venue);
            if (!is_wp_error($new_venue)) {
                $venue_id = $new_venue['term_id'];
            }
        }
    }
    //Set venue
    $r = wp_set_post_terms($post_id, array($venue_id), 'event-venue', false);
    //If reocurring, but not editing occurrences, can abort here, but trigger hook.
    if (eo_reoccurs($post_id) && (!isset($raw_data['AlterRe']) || 'yes' != $raw_data['AlterRe'])) {
        do_action('eventorganiser_save_event', $post_id);
        //Need this to update cache
        return;
    }
    //Set times for all day events
    $all_day = intval($raw_data['allday']);
    if ($all_day) {
        $raw_data['StartTime'] = '00:00';
        $raw_data['FinishTime'] = '23:59';
    } elseif (!eventorganiser_blog_is_24()) {
        //Potentially need to parse 24
        //TODO incorproate into _eventorganiser_check_datetime
        $raw_data['StartTime'] = date("H:i", strtotime($raw_data['StartTime']));
        $raw_data['FinishTime'] = date("H:i", strtotime($raw_data['FinishTime']));
    }
    //Check dates
    $start = _eventorganiser_check_datetime(trim($raw_data['StartDate']) . ' ' . trim($raw_data['StartTime']));
    $end = _eventorganiser_check_datetime(trim($raw_data['EndDate']) . ' ' . trim($raw_data['FinishTime']));
    $schedule_last = _eventorganiser_check_datetime(trim($raw_data['schedule_end']) . ' ' . trim($raw_data['StartTime']));
    //Collect schedule meta
    $schedule = $raw_data['schedule'];
    if ('weekly' == $schedule) {
        $schedule_meta = $raw_data['days'];
        $occurs_by = '';
    } elseif ('monthly' == $schedule) {
        $schedule_meta = $raw_data['schedule_meta'];
        $occurs_by = trim($schedule_meta, '=');
    } else {
        $schedule_meta = '';
        $occurs_by = '';
    }
    //Collect include/exclude
    $in_ex = array();
    foreach (array('include', 'exclude') as $key) {
        $in_ex[$key] = array();
        $arr = explode(',', sanitize_text_field($raw_data[$key]));
        if (!empty($arr)) {
            foreach ($arr as $date) {
                $date_obj = _eventorganiser_check_datetime($date . ' ' . $raw_data['StartTime'], 'Y-m-d');
                if ($date_obj) {
                    $in_ex[$key][] = $date_obj;
                }
            }
        }
    }
    $event_data = array('start' => $start, 'end' => $end, 'all_day' => $all_day, 'schedule' => $schedule, 'frequency' => (int) $raw_data['event_frequency'], 'schedule_last' => $schedule_last, 'schedule_meta' => $schedule_meta, 'occurs_by' => $occurs_by, 'include' => $in_ex['include'], 'exclude' => $in_ex['exclude']);
    $response = eo_update_event($post_id, $event_data);
    if (is_wp_error($response)) {
        global $EO_Errors;
        $code = $response->get_error_code();
        $message = $response->get_error_message($code);
        $errors[$post_id][] = __('Event dates were not saved.', 'eventorganiser');
        $errors[$post_id][] = $message;
        $EO_Errors->add('eo_error', $message);
        update_option('eo_notice', $errors);
    }
    return;
}