/**
  * Handle ajax saving of time intervals
  */
 public function save_interval()
 {
     $interval = array('key' => wp_stream_filter_input(INPUT_GET, 'key', FILTER_SANITIZE_STRING, array('default' => '')), 'start' => wp_stream_filter_input(INPUT_GET, 'start', FILTER_SANITIZE_STRING, array('default' => '')), 'end' => wp_stream_filter_input(INPUT_GET, 'end', FILTER_SANITIZE_STRING, array('default' => '')));
     // Get predefined interval for validation
     $avail_intervals = $this->get_predefined_intervals();
     if ('' !== $interval['key'] && 'custom' !== $interval['key'] && !isset($avail_intervals[$interval['key']])) {
         wp_die(esc_html__('That time interval is not available.', 'stream'));
     }
     // Only store dates if we are dealing with custom dates and no relative preset
     if ('custom' !== $interval['key']) {
         $interval['start'] = '';
         $interval['end'] = '';
     }
     WP_Stream_Reports_Settings::update_user_option_and_redirect('interval', $interval);
 }
Exemplo n.º 2
0
 /**
  * This function will remove the metabox from the current view.
  */
 public function delete_metabox()
 {
     $meta_key = wp_stream_filter_input(INPUT_GET, 'key', FILTER_SANITIZE_NUMBER_INT);
     // Unset the metabox from the array.
     unset(self::$sections[$meta_key]);
     // If there is no more section. We delete the user option.
     if (empty(self::$sections)) {
         delete_user_option(get_current_user_id(), 'meta-box-order_stream_page_' . WP_Stream_Reports::REPORTS_PAGE_SLUG, true);
     } else {
         // Delete the metabox from the page ordering as well
         // There might be a better way on handling this I'm sure (stream_page should not be hardcoded)
         $user_options = get_user_option('meta-box-order_stream_page_' . WP_Stream_Reports::REPORTS_PAGE_SLUG);
     }
     if (!empty($user_options)) {
         // Remove the one we are deleting from the list
         foreach ($user_options as $key => &$string) {
             $order = explode(',', $string);
             if (false !== ($key = array_search(self::META_PREFIX . $meta_key, $order))) {
                 unset($order[$key]);
                 $string = implode(',', $order);
             }
         }
         // Save the ordering again
         update_user_option(get_current_user_id(), 'meta-box-order_stream_page_' . WP_Stream_Reports::REPORTS_PAGE_SLUG, $user_options, true);
     }
     WP_Stream_Reports_Settings::update_user_option_and_redirect('sections', self::$sections);
 }
 public function migrate_settings()
 {
     $sections = self::$sections;
     foreach ($sections as $key => $args) {
         switch ($args['data_group']) {
             case 'action':
                 $sections[$key]['action_id'] = $args['data_type'];
                 break;
             case 'connector':
                 $sections[$key]['connector_id'] = $args['data_type'];
                 break;
             case 'context':
                 $sections[$key]['connector_id'] = $this->find_connector_by_context($args['data_type']);
                 $sections[$key]['context_id'] = $args['data_type'];
                 break;
             case 'other':
                 break;
         }
         if (isset($args['selector_type'])) {
             $sections[$key]['selector_id'] = $args['selector_type'];
         }
         unset($sections[$key]['data_group']);
         unset($sections[$key]['data_type']);
         unset($sections[$key]['selector_type']);
     }
     WP_Stream_Reports_Settings::update_user_option_and_redirect('sections', $sections);
 }