コード例 #1
0
ファイル: FrmProPost.php プロジェクト: swc-dng/swcsandbox
 public static function create_post($entry, $form, $action = false)
 {
     global $wpdb;
     $entry_id = is_object($entry) ? $entry->id : $entry;
     $form_id = is_object($form) ? $form->id : $form;
     if (!$action) {
         $action = FrmFormAction::get_action_for_form($form_id, 'wppost', 1);
         if (!$action) {
             return;
         }
     }
     $post = self::setup_post($action, $entry, $form);
     $post['post_type'] = $action->post_content['post_type'];
     $status = isset($post['post_status']) && !empty($post['post_status']) ? true : false;
     if (!$status && $action && in_array($action->post_content['post_status'], array('pending', 'publish'))) {
         $post['post_status'] = $action->post_content['post_status'];
     }
     if (isset($action->post_content['display_id']) && $action->post_content['display_id']) {
         $post['post_custom']['frm_display_id'] = $action->post_content['display_id'];
     } else {
         if (!is_numeric($action->post_content['post_content'])) {
             // Do not set frm_display_id if the content is mapped to a single field
             //check for auto view and set frm_display_id - for reverse compatibility
             $display = FrmProDisplay::get_auto_custom_display(compact('form_id', 'entry_id'));
             if ($display) {
                 $post['post_custom']['frm_display_id'] = $display->ID;
             }
         }
     }
     $post_id = self::insert_post($entry, $post, array(), $form, $action);
     return $post_id;
 }
コード例 #2
0
 public static function create_post_entry($id = false, $post_id = false)
 {
     if (FrmAppHelper::doing_ajax()) {
         check_ajax_referer('frm_ajax', 'nonce');
     }
     if (!$id) {
         $id = (int) $_POST['id'];
     }
     if (!$post_id) {
         $post_id = (int) $_POST['post_id'];
     }
     if (!is_numeric($id) || !is_numeric($post_id)) {
         return;
     }
     $post = get_post($post_id);
     global $wpdb;
     $values = array('description' => __('Copied from Post', 'formidable'), 'form_id' => $id, 'created_at' => $post->post_date_gmt, 'name' => $post->post_title, 'item_key' => FrmAppHelper::get_unique_key($post->post_name, $wpdb->prefix . 'frm_items', 'item_key'), 'user_id' => $post->post_author, 'post_id' => $post->ID);
     $results = $wpdb->insert($wpdb->prefix . 'frm_items', $values);
     unset($values);
     if (!$results) {
         wp_die();
     }
     $entry_id = $wpdb->insert_id;
     $user_id_field = FrmField::get_all_types_in_form($id, 'user_id', 1);
     if ($user_id_field) {
         $new_values = array('meta_value' => $post->post_author, 'item_id' => $entry_id, 'field_id' => $user_id_field->id, 'created_at' => current_time('mysql', 1));
         $wpdb->insert($wpdb->prefix . 'frm_item_metas', $new_values);
     }
     $display = FrmProDisplay::get_auto_custom_display(array('form_id' => $id, 'entry_id' => $entry_id));
     if ($display) {
         update_post_meta($post->ID, 'frm_display_id', $display->ID);
     }
     wp_die();
 }
コード例 #3
0
ファイル: FrmProDb.php プロジェクト: swc-dng/swcsandbox
 /**
  * Migrate displays table into wp_posts
  */
 private static function migrate_to_16()
 {
     global $wpdb;
     $display_posts = array();
     if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}frm_display'")) {
         //only migrate if table exists
         $dis = FrmDb::get_results('frm_display');
     } else {
         $dis = array();
     }
     foreach ($dis as $d) {
         $post = array('post_title' => $d->name, 'post_content' => $d->content, 'post_date' => $d->created_at, 'post_excerpt' => $d->description, 'post_name' => $d->display_key, 'post_status' => 'publish', 'post_type' => 'frm_display');
         $post_ID = wp_insert_post($post);
         unset($post);
         update_post_meta($post_ID, 'frm_old_id', $d->id);
         if (!isset($d->show_count) || empty($d->show_count)) {
             $d->show_count = 'none';
         }
         foreach (array('dyncontent', 'param', 'form_id', 'post_id', 'entry_id', 'param', 'type', 'show_count', 'insert_loc') as $f) {
             update_post_meta($post_ID, 'frm_' . $f, $d->{$f});
             unset($f);
         }
         $d->options = maybe_unserialize($d->options);
         update_post_meta($post_ID, 'frm_options', $d->options);
         if (isset($d->options['insert_loc']) && $d->options['insert_loc'] != 'none' && is_numeric($d->options['post_id']) && !isset($display_posts[$d->options['post_id']])) {
             $display_posts[$d->options['post_id']] = $post_ID;
         }
         unset($d, $post_ID);
     }
     unset($dis);
     //get all post_ids from frm_entries
     $entry_posts = FrmDb::get_results($wpdb->prefix . 'frm_items', array('post_id >' => 1), 'id, post_id, form_id');
     $form_display = array();
     foreach ($entry_posts as $ep) {
         if (isset($form_display[$ep->form_id])) {
             $display_posts[$ep->post_id] = $form_display[$ep->form_id];
         } else {
             $d = FrmProDisplay::get_auto_custom_display(array('post_id' => $ep->post_id, 'form_id' => $ep->form_id, 'entry_id' => $ep->id));
             $display_posts[$ep->post_id] = $form_display[$ep->form_id] = $d ? $d->ID : 0;
             unset($d);
         }
         unset($ep);
     }
     unset($form_display);
     foreach ($display_posts as $post_ID => $d) {
         if ($d) {
             update_post_meta($post_ID, 'frm_display_id', $d);
         }
         unset($d, $post_ID);
     }
     unset($display_posts);
 }
コード例 #4
0
 public static function before_delete_post($post_id)
 {
     $post = get_post($post_id);
     if ($post->post_type != self::$post_type) {
         return;
     }
     global $wpdb;
     do_action('frm_destroy_display', $post_id);
     $used_by = FrmDb::get_col($wpdb->postmeta, array('meta_key' => 'frm_display_id', 'meta_value' => $post_id), 'post_ID');
     if (!$used_by) {
         return;
     }
     $form_id = get_post_meta($post_id, 'frm_form_id', true);
     $next_display = FrmProDisplay::get_auto_custom_display(compact('form_id'));
     if ($next_display && $next_display->ID) {
         $wpdb->update($wpdb->postmeta, array('meta_value' => $next_display->ID), array('meta_key' => 'frm_display_id', 'meta_value' => $post_id));
     } else {
         $wpdb->delete($wpdb->postmeta, array('meta_key' => 'frm_display_id', 'meta_value' => $post_id));
     }
 }