예제 #1
0
 public function do_execute()
 {
     $ai1ec_cat_ids = $this->_params['cat_ids'];
     $ai1ec_tag_ids = $this->_params['tag_ids'];
     $ai1ec_post_ids = $this->_params['post_ids'];
     if (!empty($this->_params['lang'])) {
         $loc_helper = $this->_registry->get('p28n.wpml');
         $loc_helper->set_language($this->_params['lang']);
     }
     $args = array('do_not_export_as_calendar' => false);
     $filter = array();
     if ($ai1ec_cat_ids) {
         $filter['cat_ids'] = Ai1ec_Primitive_Int::convert_to_int_list(',', $ai1ec_cat_ids);
     }
     if ($ai1ec_tag_ids) {
         $filter['tag_ids'] = Ai1ec_Primitive_Int::convert_to_int_list(',', $ai1ec_tag_ids);
     }
     if ($ai1ec_post_ids) {
         $args['do_not_export_as_calendar'] = true;
         $filter['post_ids'] = Ai1ec_Primitive_Int::convert_to_int_list(',', $ai1ec_post_ids);
     }
     $filter = apply_filters('ai1ec_export_filter', $filter);
     // when exporting events by post_id, do not look up the event's start/end date/time
     $start = $ai1ec_post_ids !== false ? $this->_registry->get('date.time', '-3 years') : $this->_registry->get('date.time', time() - 24 * 60 * 60);
     // Include any events ending today
     $end = $this->_registry->get('date.time', '+3 years');
     $search = $this->_registry->get('model.search');
     $params = array('no_html' => $this->_params['no_html'], 'xml' => $this->_params['xml']);
     $export_controller = $this->_registry->get('controller.import-export', array('ics'), $params);
     $args['events'] = $this->unique_events($search->get_events_between($start, $end, $filter));
     $ics = $export_controller->export_events('ics', $args);
     return array('data' => $ics);
 }
예제 #2
0
 /**
  * add_ics_feed function
  *
  * Adds submitted ics feed to the database
  *
  * @return string JSON output
  *
  */
 public function add_ics_feed()
 {
     check_ajax_referer('ai1ec_ics_feed_nonce', 'nonce');
     if (!current_user_can('manage_ai1ec_feeds')) {
         wp_die(Ai1ec_I18n::__('Oh, submission was not accepted.'));
     }
     $db = $this->_registry->get('dbi.dbi');
     $table_name = $db->get_table_name('ai1ec_event_feeds');
     $feed_categories = empty($_REQUEST['feed_category']) ? '' : implode(',', $_REQUEST['feed_category']);
     $entry = array('feed_url' => $_REQUEST['feed_url'], 'feed_name' => $_REQUEST['feed_url'], 'feed_category' => $feed_categories, 'feed_tags' => $_REQUEST['feed_tags'], 'comments_enabled' => Ai1ec_Primitive_Int::db_bool($_REQUEST['comments_enabled']), 'map_display_enabled' => Ai1ec_Primitive_Int::db_bool($_REQUEST['map_display_enabled']), 'keep_tags_categories' => Ai1ec_Primitive_Int::db_bool($_REQUEST['keep_tags_categories']), 'keep_old_events' => Ai1ec_Primitive_Int::db_bool($_REQUEST['keep_old_events']), 'import_timezone' => Ai1ec_Primitive_Int::db_bool($_REQUEST['feed_import_timezone']));
     $entry = apply_filters('ai1ec_ics_feed_entry', $entry);
     $json_strategy = $this->_registry->get('http.response.render.strategy.json');
     if (is_wp_error($entry)) {
         $output = array('error' => true, 'message' => $entry->get_error_message());
         return $json_strategy->render(array('data' => $output));
     }
     $format = array('%s', '%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d');
     if (!empty($_REQUEST['feed_id'])) {
         $feed_id = $_REQUEST['feed_id'];
         $db->update($table_name, $entry, array('feed_id' => $feed_id));
     } else {
         $res = $db->insert($table_name, $entry, $format);
         $feed_id = $db->get_insert_id();
     }
     $categories = array();
     do_action('ai1ec_ics_feed_added', $feed_id, $entry);
     $update = $this->update_ics_feed($feed_id);
     if ($update['data']['error']) {
         $this->delete_ics_feed(false, $feed_id);
         return $json_strategy->render($update);
     }
     $feed_name = $update['data']['name'];
     $db->update($table_name, array('feed_name' => $feed_name), array('feed_id' => $feed_id));
     $cat_ids = '';
     if (!empty($_REQUEST['feed_category'])) {
         foreach ($_REQUEST['feed_category'] as $cat_id) {
             $feed_category = get_term($cat_id, 'events_categories');
             $categories[] = $feed_category->name;
         }
         $cat_ids = implode(',', $_REQUEST['feed_category']);
     }
     $args = array('feed_url' => $_REQUEST['feed_url'], 'feed_name' => $feed_name, 'event_category' => implode(', ', $categories), 'categories_ids' => $cat_ids, 'tags' => str_replace(',', ', ', $_REQUEST['feed_tags']), 'tags_ids' => $_REQUEST['feed_tags'], 'feed_id' => $feed_id, 'comments_enabled' => (bool) intval($_REQUEST['comments_enabled']), 'map_display_enabled' => (bool) intval($_REQUEST['map_display_enabled']), 'events' => 0, 'keep_tags_categories' => (bool) intval($_REQUEST['keep_tags_categories']), 'keep_old_events' => (bool) intval($_REQUEST['keep_old_events']), 'feed_import_timezone' => (bool) intval($_REQUEST['feed_import_timezone']));
     // Display added feed row.
     $loader = $this->_registry->get('theme.loader');
     $file = $loader->get_file('feed_row.php', $args, true);
     $output = $file->get_content();
     $output = array('error' => false, 'message' => stripslashes($output), 'update' => $update);
     return $json_strategy->render(array('data' => $output));
 }
예제 #3
0
 /**
  * Update function.
  *
  * Called when a user submits the widget configuration form.
  * The data should be validated and returned.
  *
  * @param  array $new_instance The new data that was submitted.
  * @param  array $old_instance The widget's old data.
  * @return array               The new data to save for this widget instance.
  */
 public function update($new_instance, $old_instance)
 {
     // Save existing data as a base to modify with new data
     $instance = $old_instance;
     $instance['title'] = strip_tags($new_instance['title']);
     $instance['events_per_page'] = Ai1ec_Primitive_Int::index($new_instance['events_per_page'], 1, 1);
     $instance['days_per_page'] = Ai1ec_Primitive_Int::index($new_instance['days_per_page'], 1, 1);
     $instance['events_seek_type'] = $this->_valid_seek_type($new_instance['events_seek_type']);
     $instance['show_subscribe_buttons'] = isset($new_instance['show_subscribe_buttons']) ? true : false;
     $instance['show_calendar_button'] = isset($new_instance['show_calendar_button']) ? true : false;
     $instance['hide_on_calendar_page'] = isset($new_instance['hide_on_calendar_page']) ? true : false;
     // For limits, set the limit to False if no IDs were selected, or set the respective IDs to empty if "limit by" was unchecked
     $instance['limit_by_cat'] = false;
     $instance['cat_ids'] = array();
     if (isset($new_instance['cat_ids']) && $new_instance['cat_ids'] != false) {
         $instance['limit_by_cat'] = true;
     }
     if (isset($new_instance['limit_by_cat']) && $new_instance['limit_by_cat'] != false) {
         $instance['limit_by_cat'] = true;
     }
     if (isset($new_instance['cat_ids']) && $instance['limit_by_cat'] === true) {
         $instance['cat_ids'] = $new_instance['cat_ids'];
     }
     $instance['limit_by_tag'] = false;
     $instance['tag_ids'] = array();
     if (isset($new_instance['tag_ids']) && $new_instance['tag_ids'] != false) {
         $instance['limit_by_tag'] = true;
     }
     if (isset($new_instance['limit_by_tag']) && $new_instance['limit_by_tag'] != false) {
         $instance['limit_by_tag'] = true;
     }
     if (isset($new_instance['tag_ids']) && $instance['limit_by_tag'] === true) {
         $instance['tag_ids'] = $new_instance['tag_ids'];
     }
     return $instance;
 }
 /**
  * add_ics_feed function
  *
  * Adds submitted ics feed to the database
  *
  * @return string JSON output
  *
  */
 public function add_ics_feed()
 {
     check_ajax_referer('ai1ec_ics_feed_nonce', 'nonce');
     $db = $this->_registry->get('dbi.dbi');
     $table_name = $db->get_table_name('ai1ec_event_feeds');
     $feed_categories = empty($_REQUEST['feed_category']) ? '' : implode(',', $_REQUEST['feed_category']);
     $entry = array('feed_url' => $_REQUEST['feed_url'], 'feed_category' => $feed_categories, 'feed_tags' => $_REQUEST['feed_tags'], 'comments_enabled' => Ai1ec_Primitive_Int::db_bool($_REQUEST['comments_enabled']), 'map_display_enabled' => Ai1ec_Primitive_Int::db_bool($_REQUEST['map_display_enabled']), 'keep_tags_categories' => Ai1ec_Primitive_Int::db_bool($_REQUEST['keep_tags_categories']), 'keep_old_events' => Ai1ec_Primitive_Int::db_bool($_REQUEST['keep_old_events']));
     $entry = apply_filters('ai1ec_ics_feed_entry', $entry);
     if (is_wp_error($entry)) {
         $output = array('error' => true, 'message' => $entry->get_error_message());
         $json_strategy = $this->_registry->get('http.response.render.strategy.json');
         return $json_strategy->render(array('data' => $output));
     }
     $format = array('%s', '%s', '%s', '%d', '%d', '%d', '%d');
     $res = $db->insert($table_name, $entry, $format);
     $feed_id = $db->get_insert_id();
     $categories = array();
     if (!empty($_REQUEST['feed_category'])) {
         foreach ($_REQUEST['feed_category'] as $cat_id) {
             $feed_category = get_term($cat_id, 'events_categories');
             $categories[] = $feed_category->name;
         }
     }
     $args = array('feed_url' => $_REQUEST['feed_url'], 'event_category' => implode(', ', $categories), 'tags' => str_replace(',', ', ', $_REQUEST['feed_tags']), 'feed_id' => $feed_id, 'comments_enabled' => (bool) intval($_REQUEST['comments_enabled']), 'map_display_enabled' => (bool) intval($_REQUEST['map_display_enabled']), 'events' => 0, 'keep_tags_categories' => (bool) intval($_REQUEST['keep_tags_categories']), 'keep_old_events' => (bool) intval($_REQUEST['keep_old_events']));
     $loader = $this->_registry->get('theme.loader');
     // display added feed row
     $file = $loader->get_file('feed_row.php', $args, true);
     $output = $file->get_content();
     $output = array('error' => false, 'message' => stripslashes($output));
     $json_strategy = $this->_registry->get('http.response.render.strategy.json');
     return $json_strategy->render(array('data' => $output));
 }
예제 #5
0
파일: ics.php 프로젝트: newmight2015/psmpsm
 /**
  * add_ics_feed function
  *
  * Adds submitted ics feed to the database
  *
  * @return string JSON output
  *
  */
 public function add_ics_feed()
 {
     $db = $this->_registry->get('dbi.dbi');
     $table_name = $db->get_table_name('ai1ec_event_feeds');
     $feed_categories = empty($_REQUEST['feed_category']) ? '' : implode(',', $_REQUEST['feed_category']);
     $entry = array('feed_url' => $_REQUEST['feed_url'], 'feed_category' => $feed_categories, 'feed_tags' => $_REQUEST['feed_tags'], 'comments_enabled' => Ai1ec_Primitive_Int::db_bool($_REQUEST['comments_enabled']), 'map_display_enabled' => Ai1ec_Primitive_Int::db_bool($_REQUEST['map_display_enabled']), 'keep_tags_categories' => Ai1ec_Primitive_Int::db_bool($_REQUEST['keep_tags_categories']));
     $format = array('%s', '%s', '%s', '%d', '%d', '%d');
     $res = $db->insert($table_name, $entry, $format);
     $feed_id = $db->get_insert_id();
     $categories = array();
     if (!empty($_REQUEST['feed_category'])) {
         foreach ($_REQUEST['feed_category'] as $cat_id) {
             $feed_category = get_term($cat_id, 'events_categories');
             $categories[] = $feed_category->name;
         }
     }
     $args = array('feed_url' => $_REQUEST['feed_url'], 'event_category' => implode(', ', $categories), 'tags' => str_replace(',', ', ', $_REQUEST['feed_tags']), 'feed_id' => $feed_id, 'comments_enabled' => (bool) intval($_REQUEST['comments_enabled']), 'map_display_enabled' => (bool) intval($_REQUEST['map_display_enabled']), 'events' => 0, 'keep_tags_categories' => (bool) intval($_REQUEST['keep_tags_categories']));
     $loader = $this->_registry->get('theme.loader');
     // display added feed row
     $file = $loader->get_file('feed_row.php', $args, true);
     $output = $file->get_content();
     $output = array("error" => 0, "message" => stripslashes($output));
     echo json_encode($output);
     exit;
 }