public function save_image_db() { global $wpdb; $gal_id = isset($_POST['current_id']) ? (int) $_POST['current_id'] : 0; $image_ids = isset($_POST['ids_string']) ? esc_html(stripslashes($_POST['ids_string'])) : ''; $image_id_array = explode(',', $image_ids); foreach ($image_id_array as $image_id) { if ($image_id) { $filename = isset($_POST['input_filename_' . $image_id]) ? esc_html(stripslashes($_POST['input_filename_' . $image_id])) : ''; $image_url = isset($_POST['image_url_' . $image_id]) ? esc_html(stripslashes($_POST['image_url_' . $image_id])) : ''; $thumb_url = isset($_POST['thumb_url_' . $image_id]) ? esc_html(stripslashes($_POST['thumb_url_' . $image_id])) : ''; $description = isset($_POST['image_description_' . $image_id]) ? esc_html(stripslashes($_POST['image_description_' . $image_id])) : ''; $alt = isset($_POST['image_alt_text_' . $image_id]) ? esc_html(stripslashes($_POST['image_alt_text_' . $image_id])) : ''; $date = isset($_POST['input_date_modified_' . $image_id]) ? esc_html(stripslashes($_POST['input_date_modified_' . $image_id])) : ''; $size = isset($_POST['input_size_' . $image_id]) ? esc_html(stripslashes($_POST['input_size_' . $image_id])) : ''; $filetype = isset($_POST['input_filetype_' . $image_id]) ? esc_html(stripslashes($_POST['input_filetype_' . $image_id])) : ''; $resolution = isset($_POST['input_resolution_' . $image_id]) ? esc_html(stripslashes($_POST['input_resolution_' . $image_id])) : ''; $order = isset($_POST['order_input_' . $image_id]) ? esc_html(stripslashes($_POST['order_input_' . $image_id])) : ''; $redirect_url = isset($_POST['redirect_url_' . $image_id]) ? esc_html(stripslashes($_POST['redirect_url_' . $image_id])) : ''; $author = get_current_user_id(); $tags_ids = isset($_POST['tags_' . $image_id]) ? esc_html(stripslashes($_POST['tags_' . $image_id])) : ''; if (strpos($image_id, 'pr_') !== FALSE) { $save = $wpdb->insert($wpdb->prefix . 'bwg_image', array('gallery_id' => $gal_id, 'slug' => WDWLibrary::spider_replace4byte($alt), 'filename' => $filename, 'image_url' => $image_url, 'thumb_url' => $thumb_url, 'description' => WDWLibrary::spider_replace4byte($description), 'alt' => WDWLibrary::spider_replace4byte($alt), 'date' => $date, 'size' => $size, 'filetype' => $filetype, 'resolution' => $resolution, 'author' => $author, 'order' => $order, 'published' => 1, 'comment_count' => 0, 'avg_rating' => 0, 'rate_count' => 0, 'hit_count' => 0, 'redirect_url' => $redirect_url), array('%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%s')); $new_image_id = (int) $wpdb->get_var('SELECT MAX(`id`) FROM ' . $wpdb->prefix . 'bwg_image'); if (isset($_POST['check_' . $image_id])) { $_POST['check_' . $new_image_id] = 'on'; } if (isset($_POST['image_current_id']) && esc_html($_POST['image_current_id']) == $image_id) { $_POST['image_current_id'] = $new_image_id; } $image_id = $new_image_id; } else { $save = $wpdb->update($wpdb->prefix . 'bwg_image', array('gallery_id' => $gal_id, 'slug' => WDWLibrary::spider_replace4byte($alt), 'filename' => $filename, 'image_url' => $image_url, 'thumb_url' => $thumb_url, 'description' => WDWLibrary::spider_replace4byte($description), 'alt' => WDWLibrary::spider_replace4byte($alt), 'date' => $date, 'size' => $size, 'filetype' => $filetype, 'resolution' => $resolution, 'author' => $author, 'order' => $order, 'redirect_url' => $redirect_url), array('id' => $image_id)); } $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->prefix . 'bwg_image_tag WHERE image_id="%d" AND gallery_id="%d"', $image_id, $gal_id)); if ($save !== FALSE) { $tag_id_array = explode(',', $tags_ids); foreach ($tag_id_array as $tag_id) { if ($tag_id) { if (strpos($tag_id, 'pr_') !== FALSE) { $tag_id = substr($tag_id, 3); } $save = $wpdb->insert($wpdb->prefix . 'bwg_image_tag', array('tag_id' => $tag_id, 'image_id' => $image_id, 'gallery_id' => $gal_id), array('%d', '%d', '%d')); // Increase tag count in term_taxonomy table. $wpdb->query($wpdb->prepare('UPDATE ' . $wpdb->prefix . 'term_taxonomy SET count="%d" WHERE term_id="%d"', $wpdb->get_var($wpdb->prepare('SELECT COUNT(image_id) FROM ' . $wpdb->prefix . 'bwg_image_tag WHERE tag_id="%d"', $tag_id)), $tag_id)); } } } } } }