/** * Add nightbourhood column in custom post detail table. * * @since 1.0.0 * @package GeoDirectory_Location_Manager * * @global object $wpdb WordPress Database object. * @global string $plugin_prefix Geodirectory plugin table prefix. * * @param string $post_type The post type. * @param string $detail_table The deatil table name. */ function geodir_after_custom_detail_table_create($post_type, $detail_table = '') { global $wpdb, $plugin_prefix; $post_types = geodir_get_posttypes(); if ($detail_table == '') { $detail_table = $plugin_prefix . $post_type . '_detail'; } if (in_array($post_type, $post_types)) { $meta_field_add = "VARCHAR( 30 ) NULL"; geodir_add_column_if_not_exist($detail_table, "post_neighbourhood", $meta_field_add); } }
function geodir_claim_add_field_in_table() { if (!get_option('geodir_claim_fields_upgrade')) { geodir_add_column_if_not_exist(GEODIR_CLAIM_TABLE, 'upgrade_pkg_id', 'INT( 11 ) NOT NULL'); geodir_add_column_if_not_exist(GEODIR_CLAIM_TABLE, 'upgrade_pkg_data', 'TINYTEXT NOT NULL'); update_option('geodir_claim_fields_upgrade', '1'); } }
function geodir_payment_after_custom_detail_table_create($post_type, $detail_table) { $post_types = geodir_get_posttypes(); if (in_array($post_type, $post_types)) { $meta_field_add = " ENUM( 'false', 'true' ) NOT NULL "; geodir_add_column_if_not_exist($detail_table, "expire_notification", $meta_field_add); } }
function dt_geodir_add_cpt_dummy_column($post_type) { global $plugin_prefix; $detail_table = $plugin_prefix . $post_type . '_detail'; geodir_add_column_if_not_exist($detail_table, 'post_dummy', "enum( '1', '0' ) NULL DEFAULT '0'"); }
/** * Save or Update custom fields into the database. * * @since 1.0.0 * @package GeoDirectory * @global object $wpdb WordPress Database object. * @global string $plugin_prefix Geodirectory plugin table prefix. * @param array $request_field { * Attributes of the request field array. * * @type string $action Ajax Action name. Default "geodir_ajax_action". * @type string $manage_field_type Field type Default "custom_fields". * @type string $create_field Create field Default "true". * @type string $field_ins_upd Field ins upd Default "submit". * @type string $_wpnonce WP nonce value. * @type string $listing_type Listing type Example "gd_place". * @type string $field_type Field type Example "radio". * @type string $field_id Field id Example "12". * @type string $data_type Data type Example "VARCHAR". * @type string $is_active Either "1" or "0". If "0" is used then the field will not be displayed anywhere. * @type array $show_on_pkg Package list to display this field. * @type string $admin_title Personal comment, it would not be displayed anywhere except in custom field settings. * @type string $site_title Section title which you wish to display in frontend. * @type string $admin_desc Section description which will appear in frontend. * @type string $htmlvar_name Html variable name. This should be a unique name. * @type string $clabels Section Title which will appear in backend. * @type string $default_value The default value (for "link" this will be used as the link text). * @type string $sort_order The display order of this field in backend. e.g. 5. * @type string $is_default Either "1" or "0". If "0" is used then the field will be displayed as main form field or additional field. * @type string $for_admin_use Either "1" or "0". If "0" is used then only site admin can edit this field. * @type string $is_required Use "1" to set field as required. * @type string $required_msg Enter text for error message if field required and have not full fill requirment. * @type string $show_on_listing Want to show this on listing page?. * @type string $show_on_detail Want to show this in More Info tab on detail page?. * @type string $show_as_tab Want to display this as a tab on detail page? If "1" then "Show on detail page?" must be Yes. * @type string $option_values Option Values should be separated by comma. * @type string $field_icon Upload icon using media and enter its url path, or enter font awesome class. * @type string $css_class Enter custom css class for field custom style. * * } * @param bool $default Not yet implemented. * @return int|string If field is unique returns inserted row id. Otherwise returns error string. */ function geodir_custom_field_save($request_field = array(), $default = false) { global $wpdb, $plugin_prefix; $old_html_variable = ''; $data_type = trim($request_field['data_type']); $result_str = isset($request_field['field_id']) ? trim($request_field['field_id']) : ''; //geodir_add_column_if_not_exist(GEODIR_CUSTOM_FIELDS_TABLE, 'cat_sort', 'text NOT NULL'); //geodir_add_column_if_not_exist(GEODIR_CUSTOM_FIELDS_TABLE, 'cat_filter', 'text NOT NULL'); // add column to store decimal point //geodir_add_column_if_not_exist( GEODIR_CUSTOM_FIELDS_TABLE, 'decimal_point', 'VARCHAR( 10 ) NOT NULL'); $cf = trim($result_str, '_'); /*-------- check dublicate validation --------*/ $cehhtmlvar_name = isset($request_field['htmlvar_name']) ? $request_field['htmlvar_name'] : ''; $post_type = $request_field['listing_type']; if ($request_field['field_type'] != 'address' && $request_field['field_type'] != 'taxonomy' && $request_field['field_type'] != 'fieldset') { $cehhtmlvar_name = 'geodir_' . $cehhtmlvar_name; } $check_html_variable = $wpdb->get_var($wpdb->prepare("select htmlvar_name from " . GEODIR_CUSTOM_FIELDS_TABLE . " where id <> %d and htmlvar_name = %s and post_type = %s ", array($cf, $cehhtmlvar_name, $post_type))); if (!$check_html_variable || $request_field['field_type'] == 'fieldset') { if ($cf != '') { $post_meta_info = $wpdb->get_row($wpdb->prepare("select * from " . GEODIR_CUSTOM_FIELDS_TABLE . " where id = %d", array($cf))); } if (!empty($post_meta_info)) { $post_val = $post_meta_info; $old_html_variable = $post_val->htmlvar_name; } /*else{ $post_val->sort_order = $wpdb->get_var("select max(sort_order)+1 from ".GEODIR_CUSTOM_FIELDS_TABLE); }*/ if ($post_type == '') { $post_type = 'gd_place'; } $detail_table = $plugin_prefix . $post_type . '_detail'; $admin_title = $request_field['admin_title']; $site_title = $request_field['site_title']; $data_type = $request_field['data_type']; $field_type = $request_field['field_type']; $htmlvar_name = isset($request_field['htmlvar_name']) ? $request_field['htmlvar_name'] : ''; $admin_desc = $request_field['admin_desc']; $clabels = $request_field['clabels']; $default_value = isset($request_field['default_value']) ? $request_field['default_value'] : ''; $sort_order = isset($request_field['sort_order']) ? $request_field['sort_order'] : ''; $is_active = isset($request_field['is_active']) ? $request_field['is_active'] : ''; $is_required = isset($request_field['is_required']) ? $request_field['is_required'] : ''; $required_msg = isset($request_field['required_msg']) ? $request_field['required_msg'] : ''; $css_class = isset($request_field['css_class']) ? $request_field['css_class'] : ''; $field_icon = isset($request_field['field_icon']) ? $request_field['field_icon'] : ''; $show_on_listing = isset($request_field['show_on_listing']) ? $request_field['show_on_listing'] : ''; $show_on_detail = isset($request_field['show_on_detail']) ? $request_field['show_on_detail'] : ''; $show_as_tab = isset($request_field['show_as_tab']) ? $request_field['show_as_tab'] : ''; $decimal_point = isset($request_field['decimal_point']) ? trim($request_field['decimal_point']) : ''; // decimal point for DECIMAL data type $decimal_point = $decimal_point > 0 ? $decimal_point > 10 ? 10 : $decimal_point : ''; $for_admin_use = isset($request_field['for_admin_use']) ? $request_field['for_admin_use'] : ''; if ($field_type != 'address' && $field_type != 'taxonomy' && $field_type != 'fieldset') { $htmlvar_name = 'geodir_' . $htmlvar_name; } $option_values = ''; if (isset($request_field['option_values'])) { $option_values = $request_field['option_values']; } $cat_sort = ''; if (isset($request_field['cat_sort']) && !empty($request_field['cat_sort'])) { $cat_sort = implode(",", $request_field['cat_sort']); } $cat_filter = ''; if (isset($request_field['cat_filter']) && !empty($request_field['cat_filter'])) { $cat_filter = implode(",", $request_field['cat_filter']); } if (isset($request_field['show_on_pkg']) && !empty($request_field['show_on_pkg'])) { $price_pkg = implode(",", $request_field['show_on_pkg']); } else { $package_info = array(); $package_info = geodir_post_package_info($package_info, '', $post_type); $price_pkg = $package_info->pid; } if (isset($request_field['extra']) && !empty($request_field['extra'])) { $extra_fields = $request_field['extra']; } if (isset($request_field['is_default']) && $request_field['is_default'] != '') { $is_default = $request_field['is_default']; } else { $is_default = '0'; } if (isset($request_field['is_admin']) && $request_field['is_admin'] != '') { $is_admin = $request_field['is_admin']; } else { $is_admin = '0'; } if ($is_active == '') { $is_active = 1; } if ($is_required == '') { $is_required = 0; } if ($sort_order == '') { $last_order = $wpdb->get_var("SELECT MAX(sort_order) as last_order FROM " . GEODIR_CUSTOM_FIELDS_TABLE); $sort_order = (int) $last_order + 1; } $default_value_add = ''; if (!empty($post_meta_info)) { switch ($field_type) { case 'address': if ($htmlvar_name != '') { $prefix = $htmlvar_name . '_'; } $old_prefix = $old_html_variable . '_'; $meta_field_add = "ALTER TABLE " . $detail_table . " CHANGE `" . $old_prefix . "address` `" . $prefix . "address` VARCHAR( 254 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } $wpdb->query($meta_field_add); if ($extra_fields != '') { if (isset($extra_fields['show_city']) && $extra_fields['show_city']) { $is_column = $wpdb->get_var("SHOW COLUMNS FROM " . $detail_table . " where field='" . $old_prefix . "city'"); if ($is_column) { $meta_field_add = "ALTER TABLE " . $detail_table . " CHANGE `" . $old_prefix . "city` `" . $prefix . "city` VARCHAR( 50 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } $wpdb->query($meta_field_add); } else { $meta_field_add = "VARCHAR( 50 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } geodir_add_column_if_not_exist($detail_table, $prefix . "city", $meta_field_add); } } if (isset($extra_fields['show_region']) && $extra_fields['show_region']) { $is_column = $wpdb->get_var("SHOW COLUMNS FROM " . $detail_table . " where field='" . $old_prefix . "region'"); if ($is_column) { $meta_field_add = "ALTER TABLE " . $detail_table . " CHANGE `" . $old_prefix . "region` `" . $prefix . "region` VARCHAR( 50 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } $wpdb->query($meta_field_add); } else { $meta_field_add = "VARCHAR( 50 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } geodir_add_column_if_not_exist($detail_table, $prefix . "region", $meta_field_add); } } if (isset($extra_fields['show_country']) && $extra_fields['show_country']) { $is_column = $wpdb->get_var("SHOW COLUMNS FROM " . $detail_table . " where field='" . $old_prefix . "country'"); if ($is_column) { $meta_field_add = "ALTER TABLE " . $detail_table . " CHANGE `" . $old_prefix . "country` `" . $prefix . "country` VARCHAR( 50 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } $wpdb->query($meta_field_add); } else { $meta_field_add = "VARCHAR( 50 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } geodir_add_column_if_not_exist($detail_table, $prefix . "country", $meta_field_add); } } if (isset($extra_fields['show_zip']) && $extra_fields['show_zip']) { $is_column = $wpdb->get_var("SHOW COLUMNS FROM " . $detail_table . " where field='" . $old_prefix . "zip'"); if ($is_column) { $meta_field_add = "ALTER TABLE " . $detail_table . " CHANGE `" . $old_prefix . "zip` `" . $prefix . "zip` VARCHAR( 50 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } $wpdb->query($meta_field_add); } else { $meta_field_add = "VARCHAR( 50 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } geodir_add_column_if_not_exist($detail_table, $prefix . "zip", $meta_field_add); } } if (isset($extra_fields['show_map']) && $extra_fields['show_map']) { $is_column = $wpdb->get_var("SHOW COLUMNS FROM " . $detail_table . " where field='" . $old_prefix . "latitude'"); if ($is_column) { $meta_field_add = "ALTER TABLE " . $detail_table . " CHANGE `" . $old_prefix . "latitude` `" . $prefix . "latitude` VARCHAR( 20 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } $wpdb->query($meta_field_add); } else { $meta_field_add = "ALTER TABLE " . $detail_table . " ADD `" . $prefix . "latitude` VARCHAR( 20 ) NULL"; $meta_field_add = "VARCHAR( 20 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } geodir_add_column_if_not_exist($detail_table, $prefix . "latitude", $meta_field_add); } $is_column = $wpdb->get_var("SHOW COLUMNS FROM " . $detail_table . " where field='" . $old_prefix . "longitude'"); if ($is_column) { $meta_field_add = "ALTER TABLE " . $detail_table . " CHANGE `" . $old_prefix . "longitude` `" . $prefix . "longitude` VARCHAR( 20 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } $wpdb->query($meta_field_add); } else { $meta_field_add = "ALTER TABLE " . $detail_table . " ADD `" . $prefix . "longitude` VARCHAR( 20 ) NULL"; $meta_field_add = "VARCHAR( 20 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } geodir_add_column_if_not_exist($detail_table, $prefix . "longitude", $meta_field_add); } } if (isset($extra_fields['show_mapview']) && $extra_fields['show_mapview']) { $is_column = $wpdb->get_var("SHOW COLUMNS FROM " . $detail_table . " where field='" . $old_prefix . "mapview'"); if ($is_column) { $meta_field_add = "ALTER TABLE " . $detail_table . " CHANGE `" . $old_prefix . "mapview` `" . $prefix . "mapview` VARCHAR( 15 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } $wpdb->query($meta_field_add); } else { $meta_field_add = "ALTER TABLE " . $detail_table . " ADD `" . $prefix . "mapview` VARCHAR( 15 ) NULL"; $meta_field_add = "VARCHAR( 15 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } geodir_add_column_if_not_exist($detail_table, $prefix . "mapview", $meta_field_add); } } if (isset($extra_fields['show_mapzoom']) && $extra_fields['show_mapzoom']) { $is_column = $wpdb->get_var("SHOW COLUMNS FROM " . $detail_table . " where field='" . $old_prefix . "mapzoom'"); if ($is_column) { $meta_field_add = "ALTER TABLE " . $detail_table . " CHANGE `" . $old_prefix . "mapzoom` `" . $prefix . "mapzoom` VARCHAR( 3 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } $wpdb->query($meta_field_add); } else { $meta_field_add = "ALTER TABLE " . $detail_table . " ADD `" . $prefix . "mapzoom` VARCHAR( 3 ) NULL"; $meta_field_add = "VARCHAR( 3 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } geodir_add_column_if_not_exist($detail_table, $prefix . "mapzoom", $meta_field_add); } } // show lat lng if (isset($extra_fields['show_latlng']) && $extra_fields['show_latlng']) { $is_column = $wpdb->get_var("SHOW COLUMNS FROM " . $detail_table . " where field='" . $old_prefix . "latlng'"); if ($is_column) { $meta_field_add = "ALTER TABLE " . $detail_table . " CHANGE `" . $old_prefix . "latlng` `" . $prefix . "latlng` VARCHAR( 3 ) NULL"; $meta_field_add .= " DEFAULT '1'"; $wpdb->query($meta_field_add); } else { $meta_field_add = "ALTER TABLE " . $detail_table . " ADD `" . $prefix . "latlng` VARCHAR( 3 ) NULL"; $meta_field_add = "VARCHAR( 3 ) NULL"; $meta_field_add .= " DEFAULT '1'"; geodir_add_column_if_not_exist($detail_table, $prefix . "latlng", $meta_field_add); } } } // end extra break; case 'checkbox': case 'multiselect': case 'taxonomy': $meta_field_add = "ALTER TABLE " . $detail_table . " CHANGE `" . $old_html_variable . "` `" . $htmlvar_name . "`VARCHAR( 500 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } $wpdb->query($meta_field_add); if (isset($request_field['cat_display_type'])) { $extra_fields = $request_field['cat_display_type']; } if (isset($request_field['multi_display_type'])) { $extra_fields = $request_field['multi_display_type']; } break; case 'textarea': case 'html': $wpdb->query("ALTER TABLE " . $detail_table . " CHANGE `" . $old_html_variable . "` `" . $htmlvar_name . "` TEXT NULL"); if (isset($request_field['advanced_editor'])) { $extra_fields = $request_field['advanced_editor']; } break; case 'fieldset': // Nothig happend for fieldset break; default: if ($data_type != 'VARCHAR' && $data_type != '') { if ($data_type == 'FLOAT' && $decimal_point > 0) { $default_value_add = "ALTER TABLE " . $detail_table . " CHANGE `" . $old_html_variable . "` `" . $htmlvar_name . "` DECIMAL(11, " . (int) $decimal_point . ") NULL"; } else { $default_value_add = "ALTER TABLE " . $detail_table . " CHANGE `" . $old_html_variable . "` `" . $htmlvar_name . "` " . $data_type . " NULL"; } if (is_numeric($default_value) && $default_value != '') { $default_value_add .= " DEFAULT '" . $default_value . "'"; } } else { $default_value_add = "ALTER TABLE " . $detail_table . " CHANGE `" . $old_html_variable . "` `" . $htmlvar_name . "` VARCHAR( 254 ) NULL"; if ($default_value != '') { $default_value_add .= " DEFAULT '" . $default_value . "'"; } } $wpdb->query($default_value_add); break; } $extra_field_query = ''; if (!empty($extra_fields)) { $extra_field_query = serialize($extra_fields); } $decimal_point = $field_type == 'text' && $data_type == 'FLOAT' ? $decimal_point : ''; $wpdb->query($wpdb->prepare("update " . GEODIR_CUSTOM_FIELDS_TABLE . " set \n\t\t\t\t\tpost_type = %s,\n\t\t\t\t\tadmin_title = %s,\n\t\t\t\t\tsite_title = %s,\n\t\t\t\t\tfield_type = %s,\n\t\t\t\t\thtmlvar_name = %s,\n\t\t\t\t\tadmin_desc = %s,\n\t\t\t\t\tclabels = %s,\n\t\t\t\t\tdefault_value = %s,\n\t\t\t\t\tsort_order = %s,\n\t\t\t\t\tis_active = %s,\n\t\t\t\t\tis_default = %s,\n\t\t\t\t\tis_required = %s,\n\t\t\t\t\trequired_msg = %s,\n\t\t\t\t\tcss_class = %s,\n\t\t\t\t\tfield_icon = %s,\n\t\t\t\t\tfield_icon = %s,\n\t\t\t\t\tshow_on_listing = %s,\n\t\t\t\t\tshow_on_detail = %s, \n\t\t\t\t\tshow_as_tab = %s, \n\t\t\t\t\toption_values = %s, \n\t\t\t\t\tpackages = %s, \n\t\t\t\t\tcat_sort = %d, \n\t\t\t\t\tcat_filter = %s, \n\t\t\t\t\tdata_type = %s,\n\t\t\t\t\textra_fields = %s,\n\t\t\t\t\tdecimal_point = %s,\n\t\t\t\t\tfor_admin_use = %s \n\t\t\t\t\twhere id = %d", array($post_type, $admin_title, $site_title, $field_type, $htmlvar_name, $admin_desc, $clabels, $default_value, $sort_order, $is_active, $is_default, $is_required, $required_msg, $css_class, $field_icon, $field_icon, $show_on_listing, $show_on_detail, $show_as_tab, $option_values, $price_pkg, $cat_sort, $cat_filter, $data_type, $extra_field_query, $decimal_point, $for_admin_use, $cf))); $lastid = trim($cf); $wpdb->query($wpdb->prepare("update " . GEODIR_CUSTOM_SORT_FIELDS_TABLE . " set \n\t\t\t\t\t \tsite_title=%s\n\t\t\t\t\twhere post_type = %s and htmlvar_name = %s", array($site_title, $post_type, $htmlvar_name))); if ($cat_sort == '') { $wpdb->query($wpdb->prepare("delete from " . GEODIR_CUSTOM_SORT_FIELDS_TABLE . " where post_type = %s and htmlvar_name = %s", array($post_type, $htmlvar_name))); } /** * Called after all custom fields are saved for a post. * * @since 1.0.0 * @param int $lastid The post ID. */ do_action('geodir_after_custom_fields_updated', $lastid); } else { switch ($field_type) { case 'address': $data_type = ''; if ($htmlvar_name != '') { $prefix = $htmlvar_name . '_'; } $old_prefix = $old_html_variable; //$meta_field_add = "ALTER TABLE ".$detail_table." ADD `".$prefix."address` VARCHAR( 254 ) NULL"; $meta_field_add = "VARCHAR( 254 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } geodir_add_column_if_not_exist($detail_table, $prefix . "address", $meta_field_add); //$wpdb->query($meta_field_add); if (!empty($extra_fields)) { if (isset($extra_fields['show_city']) && $extra_fields['show_city']) { $meta_field_add = "ALTER TABLE " . $detail_table . " ADD `" . $prefix . "city` VARCHAR( 30 ) NULL"; $meta_field_add = "VARCHAR( 30 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } geodir_add_column_if_not_exist($detail_table, $prefix . "city", $meta_field_add); //$wpdb->query($meta_field_add); } if (isset($extra_fields['show_region']) && $extra_fields['show_region']) { $meta_field_add = "ALTER TABLE " . $detail_table . " ADD `" . $prefix . "region` VARCHAR( 30 ) NULL"; $meta_field_add = "VARCHAR( 30 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } geodir_add_column_if_not_exist($detail_table, $prefix . "region", $meta_field_add); //$wpdb->query($meta_field_add); } if (isset($extra_fields['show_country']) && $extra_fields['show_country']) { $meta_field_add = "ALTER TABLE " . $detail_table . " ADD `" . $prefix . "country` VARCHAR( 30 ) NULL"; $meta_field_add = "VARCHAR( 30 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } geodir_add_column_if_not_exist($detail_table, $prefix . "country", $meta_field_add); //$wpdb->query($meta_field_add); } if (isset($extra_fields['show_zip']) && $extra_fields['show_zip']) { $meta_field_add = "ALTER TABLE " . $detail_table . " ADD `" . $prefix . "zip` VARCHAR( 15 ) NULL"; $meta_field_add = "VARCHAR( 15 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } geodir_add_column_if_not_exist($detail_table, $prefix . "zip", $meta_field_add); //$wpdb->query($meta_field_add); } if (isset($extra_fields['show_map']) && $extra_fields['show_map']) { $meta_field_add = "ALTER TABLE " . $detail_table . " ADD `" . $prefix . "latitude` VARCHAR( 20 ) NULL"; $meta_field_add = "VARCHAR( 20 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } geodir_add_column_if_not_exist($detail_table, $prefix . "latitude", $meta_field_add); //$wpdb->query($meta_field_add); $meta_field_add = "ALTER TABLE " . $detail_table . " ADD `" . $prefix . "longitude` VARCHAR( 20 ) NULL"; $meta_field_add = "VARCHAR( 20 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } geodir_add_column_if_not_exist($detail_table, $prefix . "longitude", $meta_field_add); //$wpdb->query($meta_field_add); } if (isset($extra_fields['show_mapview']) && $extra_fields['show_mapview']) { $meta_field_add = "ALTER TABLE " . $detail_table . " ADD `" . $prefix . "mapview` VARCHAR( 15 ) NULL"; $meta_field_add = "VARCHAR( 15 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } geodir_add_column_if_not_exist($detail_table, $prefix . "mapview", $meta_field_add); //$wpdb->query($meta_field_add); } if (isset($extra_fields['show_mapzoom']) && $extra_fields['show_mapzoom']) { $meta_field_add = "ALTER TABLE " . $detail_table . " ADD `" . $prefix . "mapzoom` VARCHAR( 3 ) NULL"; $meta_field_add = "VARCHAR( 3 ) NULL"; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } geodir_add_column_if_not_exist($detail_table, $prefix . "mapzoom", $meta_field_add); //$wpdb->query($meta_field_add); } // show lat lng if (isset($extra_fields['show_latlng']) && $extra_fields['show_latlng']) { $meta_field_add = "ALTER TABLE " . $detail_table . " ADD `" . $prefix . "latlng` VARCHAR( 3 ) NULL"; $meta_field_add = "VARCHAR( 3 ) NULL"; $meta_field_add .= " DEFAULT '1'"; geodir_add_column_if_not_exist($detail_table, $prefix . "latlng", $meta_field_add); //$wpdb->query($meta_field_add); } } break; case 'checkbox': $data_type = 'TINYINT'; $meta_field_add = $data_type . "( 1 ) NOT NULL "; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } geodir_add_column_if_not_exist($detail_table, $htmlvar_name, $meta_field_add); break; case 'multiselect': $data_type = 'VARCHAR'; $meta_field_add = $data_type . "( 500 ) NULL "; if ($default_value != '') { $meta_field_add .= " DEFAULT '" . $default_value . "'"; } geodir_add_column_if_not_exist($detail_table, $htmlvar_name, $meta_field_add); break; case 'textarea': case 'html': $data_type = 'TEXT'; $default_value_add = " `" . $htmlvar_name . "` " . $data_type . " NULL "; $meta_field_add = $data_type . " NULL "; /*if($default_value != '') { $meta_field_add .= " DEFAULT '".$default_value."'"; }*/ geodir_add_column_if_not_exist($detail_table, $htmlvar_name, $meta_field_add); break; case 'datepicker': $data_type = 'DATE'; $default_value_add = " `" . $htmlvar_name . "` " . $data_type . " NULL "; $meta_field_add = $data_type . " NULL "; geodir_add_column_if_not_exist($detail_table, $htmlvar_name, $meta_field_add); break; case 'time': $data_type = 'TIME'; $default_value_add = " `" . $htmlvar_name . "` " . $data_type . " NULL "; $meta_field_add = $data_type . " NULL "; geodir_add_column_if_not_exist($detail_table, $htmlvar_name, $meta_field_add); break; default: if ($data_type != 'VARCHAR' && $data_type != '') { $meta_field_add = $data_type . " NULL "; if ($data_type == 'FLOAT' && $decimal_point > 0) { $meta_field_add = "DECIMAL(11, " . (int) $decimal_point . ") NULL "; } if (is_numeric($default_value) && $default_value != '') { $default_value_add .= " DEFAULT '" . $default_value . "'"; $meta_field_add .= " DEFAULT '" . $default_value . "'"; } } else { $meta_field_add = " VARCHAR( 254 ) NULL "; if ($default_value != '') { $default_value_add .= " DEFAULT '" . $default_value . "'"; $meta_field_add .= " DEFAULT '" . $default_value . "'"; } } geodir_add_column_if_not_exist($detail_table, $htmlvar_name, $meta_field_add); break; } $extra_field_query = ''; if (!empty($extra_fields)) { $extra_field_query = serialize($extra_fields); } $decimal_point = $field_type == 'text' && $data_type == 'FLOAT' ? $decimal_point : ''; $wpdb->query($wpdb->prepare("insert into " . GEODIR_CUSTOM_FIELDS_TABLE . " set \n\t\t\t\t\tpost_type = %s,\n\t\t\t\t\tadmin_title = %s,\n\t\t\t\t\tsite_title = %s,\n\t\t\t\t\tfield_type = %s,\n\t\t\t\t\thtmlvar_name = %s,\n\t\t\t\t\tadmin_desc = %s,\n\t\t\t\t\tclabels = %s,\n\t\t\t\t\tdefault_value = %s,\n\t\t\t\t\tsort_order = %d,\n\t\t\t\t\tis_active = %s,\n\t\t\t\t\tis_default = %s,\n\t\t\t\t\tis_admin = %s,\n\t\t\t\t\tis_required = %s,\n\t\t\t\t\trequired_msg = %s,\n\t\t\t\t\tcss_class = %s,\n\t\t\t\t\tfield_icon = %s,\n\t\t\t\t\tshow_on_listing = %s,\n\t\t\t\t\tshow_on_detail = %s, \n\t\t\t\t\tshow_as_tab = %s, \n\t\t\t\t\toption_values = %s, \n\t\t\t\t\tpackages = %s, \n\t\t\t\t\tcat_sort = %s, \n\t\t\t\t\tcat_filter = %s, \n\t\t\t\t\tdata_type = %s,\n\t\t\t\t\textra_fields = %s,\n\t\t\t\t\tdecimal_point = %s,\n\t\t\t\t\tfor_admin_use = %s ", array($post_type, $admin_title, $site_title, $field_type, $htmlvar_name, $admin_desc, $clabels, $default_value, $sort_order, $is_active, $is_default, $is_admin, $is_required, $required_msg, $css_class, $field_icon, $show_on_listing, $show_on_detail, $show_as_tab, $option_values, $price_pkg, $cat_sort, $cat_filter, $data_type, $extra_field_query, $decimal_point, $for_admin_use))); $lastid = $wpdb->insert_id; $lastid = trim($lastid); } return (int) $lastid; } else { return 'HTML Variable Name should be a unique name'; } }
/** * Add ratings column to the detail table when a new post type get created. * * @since 1.0.0 * @package GeoDirectory_Review_Rating_Manager * * @param string $post_type The post type. * @return bool */ function geodir_reviewrating_create_new_post_type($post_type = '') { global $wpdb, $plugin_prefix; if ($post_type != '') { $all_postypes = geodir_get_posttypes(); if (!in_array($post_type, $all_postypes)) { return false; } $detail_table = $plugin_prefix . $post_type . '_detail'; geodir_add_column_if_not_exist($detail_table, 'ratings', 'TEXT NULL DEFAULT NULL'); } }
/** * Handles upgrade for review table. * * @since 1.0.0 * @package GeoDirectory * @global object $wpdb WordPress Database object. * @global string $plugin_prefix Geodirectory plugin table prefix. */ function geodir_update_review_db() { global $wpdb, $plugin_prefix; // Add columns to review table geodir_add_column_if_not_exist(GEODIR_REVIEW_TABLE, 'post_status', 'INT(11) DEFAULT NULL'); geodir_add_column_if_not_exist(GEODIR_REVIEW_TABLE, 'post_date', 'DATETIME NOT NULL'); geodir_add_column_if_not_exist(GEODIR_REVIEW_TABLE, 'post_city', 'varchar(30) NULL DEFAULT NULL'); geodir_add_column_if_not_exist(GEODIR_REVIEW_TABLE, 'post_region', 'varchar(30) NULL DEFAULT NULL'); geodir_add_column_if_not_exist(GEODIR_REVIEW_TABLE, 'post_country', 'varchar(30) NULL DEFAULT NULL'); geodir_add_column_if_not_exist(GEODIR_REVIEW_TABLE, 'post_latitude', 'varchar(20) NULL DEFAULT NULL'); geodir_add_column_if_not_exist(GEODIR_REVIEW_TABLE, 'post_longitude', 'varchar(20) NULL DEFAULT NULL'); geodir_add_column_if_not_exist(GEODIR_REVIEW_TABLE, 'comment_content', 'TEXT NULL DEFAULT NULL'); // this should not be needed anymore becasue of geodir_fix_review_location() /*$reviews = $wpdb->get_results("SELECT * FROM ".GEODIR_REVIEW_TABLE." WHERE post_city='' OR post_city IS NULL OR post_latitude='' OR post_latitude IS NULL"); foreach($reviews as $review){ $location = $wpdb->get_row("SELECT * FROM ".$plugin_prefix.$review->post_type."_detail WHERE post_id=".$review->post_id); $wpdb->query($wpdb->prepare("UPDATE ".GEODIR_REVIEW_TABLE." gdr SET gdr.post_city=%s, gdr.post_region=%s , gdr.post_country=%s , gdr.post_latitude=%s, gdr.post_longitude=%s WHERE gdr.id=%d",$location->post_city,$location->post_region,$location->post_country,$review->id,$location->post_latitude,$location->post_longitude)); }*/ geodir_fix_review_date(); geodir_fix_review_post_status(); geodir_fix_review_content(); geodir_fix_review_location(); }