/** * filter_by_terms function * * Returns a subset of post IDs from the given set of post IDs that have any * of the given taxonomy term IDs. This is actually useful for all posts and * taxonomies in general, not just event posts and event-specific taxonomies. * * @param array|string $post_ids Post IDs as an array of ints or * comma-separated string * @param array|string $term_ids Term IDs as an array of ints or * comma-separated string * * @return array Filtered post IDs as an array of ints */ public function filter_by_terms($post_ids, $term_ids) { global $wpdb; // =============================================== // = Sanitize provided IDs against SQL injection = // =============================================== $post_ids = implode(',', Ai1ec_Number_Utility::convert_to_int_list(',', $post_ids)); $term_ids = implode(',', Ai1ec_Number_Utility::convert_to_int_list(',', $term_ids)); $query = 'SELECT DISTINCT p.ID ' . 'FROM ' . $wpdb->posts . ' p ' . 'INNER JOIN ' . $wpdb->term_relationships . ' tr ON p.ID = tr.object_id ' . 'INNER JOIN ' . $wpdb->term_taxonomy . ' tt ON tr.term_taxonomy_id = tt.term_taxonomy_id ' . 'WHERE p.ID IN ( ' . $post_ids . ' ) ' . 'AND tt.term_id IN ( ' . $term_ids . ' )'; return $wpdb->get_col($query); }
/** * export_events function * * Export events * * @return void **/ function export_events() { global $ai1ec_events_helper, $ai1ec_exporter_helper, $ai1ec_localization_helper; $ai1ec_cat_ids = !empty($_REQUEST['ai1ec_cat_ids']) ? $_REQUEST['ai1ec_cat_ids'] : false; $ai1ec_tag_ids = !empty($_REQUEST['ai1ec_tag_ids']) ? $_REQUEST['ai1ec_tag_ids'] : false; $ai1ec_post_ids = !empty($_REQUEST['ai1ec_post_ids']) ? $_REQUEST['ai1ec_post_ids'] : false; if (!empty($_REQUEST['lang'])) { $ai1ec_localization_helper->set_language($_REQUEST['lang']); } $filter = array(); if ($ai1ec_cat_ids) { $filter['cat_ids'] = Ai1ec_Number_Utility::convert_to_int_list(',', $ai1ec_cat_ids); } if ($ai1ec_tag_ids) { $filter['tag_ids'] = Ai1ec_Number_Utility::convert_to_int_list(',', $ai1ec_tag_ids); } if ($ai1ec_post_ids) { $filter['post_ids'] = Ai1ec_Number_Utility::convert_to_int_list(',', $ai1ec_post_ids); } // when exporting events by post_id, do not look up the event's start/end date/time $start = $ai1ec_post_ids !== false ? false : Ai1ec_Time_Utility::current_time(true) - 24 * 60 * 60; // Include any events ending today $end = false; $c = new vcalendar(); $c->setProperty('calscale', 'GREGORIAN'); $c->setProperty('method', 'PUBLISH'); // if no post id are specified do not export those properties // as they would create a new calendar in outlook. // a user reported this in AIOEC-982 and said this would fix it if (false === $ai1ec_post_ids) { $c->setProperty('X-WR-CALNAME', get_bloginfo('name')); $c->setProperty('X-WR-CALDESC', get_bloginfo('description')); } $c->setProperty('X-FROM-URL', home_url()); // Timezone setup $tz = Ai1ec_Meta::get_option('timezone_string'); if ($tz) { $c->setProperty('X-WR-TIMEZONE', $tz); $tz_xprops = array('X-LIC-LOCATION' => $tz); iCalUtilityFunctions::createTimezone($c, $tz, $tz_xprops); } $events = $ai1ec_events_helper->get_matching_events($start, $end, $filter); foreach ($events as $event) { $ai1ec_exporter_helper->insert_event_in_calendar($event, $c, $export = true); } $str = ltrim($c->createCalendar()); header('Content-type: text/calendar; charset=utf-8'); echo $str; exit; }