Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
<?php
/**
* Custom fields functions
*
* @since 1.0.0
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
* @global string $table_prefix WordPress Database Table prefix.
*/
global $wpdb, $table_prefix;
if (!function_exists('geodir_column_exist')) {
/**
* Check table column exist or not.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
* @param string $db The table name.
* @param string $column The column name.
* @return bool If column exists returns true. Otherwise false.
*/
function geodir_column_exist($db, $column)
{
global $wpdb;
$exists = false;
$columns = $wpdb->get_col("show columns from $db");
foreach ($columns as $c) {
if ($c == $column) {
$exists = true;
break;
}
}
return $exists;
}
}
if (!function_exists('geodir_add_column_if_not_exist')) {
/**
* Add column if table column not exist.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
* @param string $db The table name.
* @param string $column The column name.
* @param string $column_attr The column attributes.
*/
function geodir_add_column_if_not_exist($db, $column, $column_attr = "VARCHAR( 255 ) NOT NULL")
{
global $wpdb;
$result = 0;// no rows affected
if (!geodir_column_exist($db, $column)) {
if (!empty($db) && !empty($column))
$result = $wpdb->query("ALTER TABLE `$db` ADD `$column` $column_attr");
}
return $result;
}
}
/**
* Returns custom fields based on page type. (detail page, listing page).
*
* @since 1.0.0
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
* @param int|string $package_id The package ID.
* @param string $default Optional. When set to "default" it will display only default fields.
* @param string $post_type Optional. The wordpress post type.
* @param string $fields_location Optional. Where exactly are you going to place this custom fields?.
* @return array|mixed|void Returns custom fields.
*/
function geodir_post_custom_fields($package_id = '', $default = 'all', $post_type = 'gd_place', $fields_location = 'none')
{
global $wpdb, $geodir_post_custom_fields_cache;
$cache_stored = $post_type . '_' . $package_id . '_' . $default . '_' . $fields_location;
if (array_key_exists($cache_stored, $geodir_post_custom_fields_cache)) {
return $geodir_post_custom_fields_cache[$cache_stored];
}
$default_query = '';
if ($default == 'default')
$default_query .= " and is_admin IN ('1') ";
elseif ($default == 'custom')
$default_query .= " and is_admin = '0' ";
if ($fields_location == 'none') {
} else{
$fields_location = esc_sql( $fields_location );
$default_query .= " and show_in LIKE '%%[$fields_location]%%' ";
}
$post_meta_info = $wpdb->get_results(
$wpdb->prepare(
"select * from " . GEODIR_CUSTOM_FIELDS_TABLE . " where is_active = '1' and post_type = %s {$default_query} order by sort_order asc,admin_title asc",
array($post_type)
)
);
$return_arr = array();
if ($post_meta_info) {
foreach ($post_meta_info as $post_meta_info_obj) {
$custom_fields = array(
"name" => $post_meta_info_obj->htmlvar_name,
"label" => $post_meta_info_obj->clabels,
"default" => $post_meta_info_obj->default_value,
"type" => $post_meta_info_obj->field_type,
"desc" => $post_meta_info_obj->admin_desc);
if ($post_meta_info_obj->field_type) {
$options = explode(',', $post_meta_info_obj->option_values);
$custom_fields["options"] = $options;
}
foreach ($post_meta_info_obj as $key => $val) {
$custom_fields[$key] = $val;
}
$pricearr = array();
$pricearr = explode(',', $post_meta_info_obj->packages);
if ($package_id != '' && in_array($package_id, $pricearr)) {
$return_arr[$post_meta_info_obj->sort_order] = $custom_fields;
} elseif ($package_id == '') {
$return_arr[$post_meta_info_obj->sort_order] = $custom_fields;
}
}
}
$geodir_post_custom_fields_cache[$cache_stored] = $return_arr;
if (has_filter('geodir_filter_geodir_post_custom_fields')) {
/**
* Filter the post custom fields array.
*
* @since 1.0.0
*
* @param array $return_arr Post custom fields array.
* @param int|string $package_id The package ID.
* @param string $post_type Optional. The wordpress post type.
* @param string $fields_location Optional. Where exactly are you going to place this custom fields?.
*/
$return_arr = apply_filters('geodir_filter_geodir_post_custom_fields', $return_arr, $package_id, $post_type, $fields_location);
}
return $return_arr;
}
/**
* Adds admin html for custom fields.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
* @param string $field_type The form field type.
* @param object|int $result_str The custom field results object or row id.
* @param string $field_ins_upd When set to "submit" displays form.
* @param string $field_type_key The key of the custom field.
*/
function geodir_custom_field_adminhtml($field_type, $result_str, $field_ins_upd = '', $field_type_key ='')
{
global $wpdb;
$cf = $result_str;
if (!is_object($cf)) {
$field_info = $wpdb->get_row($wpdb->prepare("select * from " . GEODIR_CUSTOM_FIELDS_TABLE . " where id= %d", array($cf)));
} else {
$field_info = $cf;
$result_str = $cf->id;
}
/**
* Contains custom field html.
*
* @since 1.0.0
*/
include('custom_field_html.php');
}
if (!function_exists('geodir_custom_field_delete')) {
/**
* Delete custom field using field id.
*
* @since 1.0.0
* @since 1.5.7 Delete field from sorting fields table when custom field deleted.
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
* @global string $plugin_prefix Geodirectory plugin table prefix.
* @param string $field_id The custom field ID.
* @return int|string If field deleted successfully, returns field id. Otherwise returns 0.
*/
function geodir_custom_field_delete($field_id = '') {
global $wpdb, $plugin_prefix;
if ($field_id != '') {
$cf = trim($field_id, '_');
if ($field = $wpdb->get_row($wpdb->prepare("select htmlvar_name,post_type,field_type from " . GEODIR_CUSTOM_FIELDS_TABLE . " where id= %d", array($cf)))) {
$wpdb->query($wpdb->prepare("delete from " . GEODIR_CUSTOM_FIELDS_TABLE . " where id= %d ", array($cf)));
$post_type = $field->post_type;
$htmlvar_name = $field->htmlvar_name;
if ($post_type != '' && $htmlvar_name != '') {
$wpdb->query($wpdb->prepare("DELETE FROM " . GEODIR_CUSTOM_SORT_FIELDS_TABLE . " WHERE htmlvar_name=%s AND post_type=%s LIMIT 1", array($htmlvar_name, $post_type)));
}
/**
* Called after a custom field is deleted.
*
* @since 1.0.0
* @param string $cf The fields ID.
* @param string $field->htmlvar_name The html variable name for the field.
* @param string $post_type The post type the field belongs to.
*/
do_action('geodir_after_custom_field_deleted', $cf, $field->htmlvar_name, $post_type);
if ($field->field_type == 'address') {
$wpdb->query("ALTER TABLE " . $plugin_prefix . $post_type . "_detail DROP `" . $field->htmlvar_name . "_address`");
$wpdb->query("ALTER TABLE " . $plugin_prefix . $post_type . "_detail DROP `" . $field->htmlvar_name . "_city`");
$wpdb->query("ALTER TABLE " . $plugin_prefix . $post_type . "_detail DROP `" . $field->htmlvar_name . "_region`");
$wpdb->query("ALTER TABLE " . $plugin_prefix . $post_type . "_detail DROP `" . $field->htmlvar_name . "_country`");
$wpdb->query("ALTER TABLE " . $plugin_prefix . $post_type . "_detail DROP `" . $field->htmlvar_name . "_zip`");
$wpdb->query("ALTER TABLE " . $plugin_prefix . $post_type . "_detail DROP `" . $field->htmlvar_name . "_latitude`");
$wpdb->query("ALTER TABLE " . $plugin_prefix . $post_type . "_detail DROP `" . $field->htmlvar_name . "_longitude`");
$wpdb->query("ALTER TABLE " . $plugin_prefix . $post_type . "_detail DROP `" . $field->htmlvar_name . "_mapview`");
$wpdb->query("ALTER TABLE " . $plugin_prefix . $post_type . "_detail DROP `" . $field->htmlvar_name . "_mapzoom`");
} else {
if ($field->field_type != 'fieldset') {
$wpdb->query("ALTER TABLE " . $plugin_prefix . $post_type . "_detail DROP `" . $field->htmlvar_name . "`");
}
}
return $field_id;
} else
return 0;
} else
return 0;
}
}
if (!function_exists('geodir_custom_field_save')) {
/**
* Save or Update custom fields into the database.
*
* @since 1.0.0
* @since 1.5.6 Fix for saving multiselect custom field "Display Type" on first attempt.
* @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 requirement.
* @type string $show_on_listing Want to show this on listing page?.
* @type string $show_in What locations to show the custom field in.
* @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.
* @type array $extra_fields An array of extra fields to store.
*
* }
* @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']) : '';
// some servers fail if a POST value is VARCHAR so we change it.
if(isset($request_field['data_type']) && $request_field['data_type']=='XVARCHAR'){
$request_field['data_type'] = 'VARCHAR';
}
$cf = trim($result_str, '_');
/*-------- check duplicate 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;
}
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'];
$field_type_key = isset($request_field['field_type_key']) ? $request_field['field_type_key'] : $field_type;
$htmlvar_name = isset($request_field['htmlvar_name']) ? $request_field['htmlvar_name'] : '';
$admin_desc = $request_field['admin_desc'];
$clabels = isset($request_field['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_in = isset($request_field['show_in']) ? $request_field['show_in'] : '';
$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) : '';
$validation_pattern = isset($request_field['validation_pattern']) ? $request_field['validation_pattern'] : '';
$validation_msg = isset($request_field['validation_msg']) ? $request_field['validation_msg'] : '';
$for_admin_use = isset($request_field['for_admin_use']) ? $request_field['for_admin_use'] : '';
if(is_array($show_in)){
$show_in = implode(",", $request_field['show_in']);
}
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 = isset($request_field['cat_sort']) ? $request_field['cat_sort'] : '0';
$cat_filter = isset($request_field['cat_filter']) ? $request_field['cat_filter'] : '0';
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 = !empty($package_info->pid) ? $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':
$default_value_add = "ALTER TABLE " . $detail_table . " CHANGE `" . $old_html_variable . "` `" . $htmlvar_name . "` TINYINT(1) NOT NULL";
if ($default_value != '') {
$default_value_add .= " DEFAULT '" . $default_value . "'";
}
$alter_result = $wpdb->query($default_value_add);
if ( $alter_result === false) {
return __('Column change failed, you may have too many columns.', 'geodirectory');
}
break;
case 'multiselect':
case 'select':
case 'taxonomy':
$op_size = '500';
// only make the field as big as it needs to be.
if(isset($option_values) && $option_values && $field_type=='select'){
$option_values_arr = explode(',',$option_values);
if(is_array($option_values_arr)){
$op_max = 0;
foreach($option_values_arr as $op_val){
if(strlen($op_val) && strlen($op_val)>$op_max){$op_max = strlen($op_val);}
}
if($op_max){$op_size =$op_max; }
}
}elseif(isset($option_values) && $option_values && $field_type=='multiselect'){
if(strlen($option_values)){
$op_size = strlen($option_values);
}
}
$meta_field_add = "ALTER TABLE " . $detail_table . " CHANGE `" . $old_html_variable . "` `" . $htmlvar_name . "`VARCHAR( $op_size ) NULL";
if ($default_value != '') {
$meta_field_add .= " DEFAULT '" . $default_value . "'";
}
$alter_result = $wpdb->query($meta_field_add);
if($alter_result===false){
return __('Column change failed, you may have too many columns.','geodirectory');
}
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':
case 'url':
case 'file':
$alter_result = $wpdb->query("ALTER TABLE " . $detail_table . " CHANGE `" . $old_html_variable . "` `" . $htmlvar_name . "` TEXT NULL");
if($alter_result===false){
return __('Column change failed, you may have too many columns.','geodirectory');
}
if (isset($request_field['advanced_editor']))
$extra_fields = $request_field['advanced_editor'];
break;
case 'fieldset':
// Nothing happened 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 . "'";
}
}
$alter_result = $wpdb->query($default_value_add);
if($alter_result===false){
return __('Column change failed, you may have too many columns.','geodirectory');
}
break;
endswitch;
$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
post_type = %s,
admin_title = %s,
site_title = %s,
field_type = %s,
field_type_key = %s,
htmlvar_name = %s,
admin_desc = %s,
clabels = %s,
default_value = %s,
sort_order = %s,
is_active = %s,
is_default = %s,
is_required = %s,
required_msg = %s,
css_class = %s,
field_icon = %s,
field_icon = %s,
show_on_listing = %s,
show_in = %s,
show_on_detail = %s,
show_as_tab = %s,
option_values = %s,
packages = %s,
cat_sort = %d,
cat_filter = %s,
data_type = %s,
extra_fields = %s,
decimal_point = %s,
validation_pattern = %s,
validation_msg = %s,
for_admin_use = %s
where id = %d",
array($post_type, $admin_title, $site_title, $field_type, $field_type_key, $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_in, $show_on_detail, $show_as_tab, $option_values, $price_pkg, $cat_sort, $cat_filter, $data_type, $extra_field_query, $decimal_point,$validation_pattern,$validation_msg, $for_admin_use, $cf)
)
);
$lastid = trim($cf);
$wpdb->query(
$wpdb->prepare(
"update " . GEODIR_CUSTOM_SORT_FIELDS_TABLE . " set
site_title=%s
where 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( 50 ) 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( 50 ) 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 ((int)$default_value === 1) {
$meta_field_add .= " DEFAULT '1'";
}
$add_result = geodir_add_column_if_not_exist($detail_table, $htmlvar_name, $meta_field_add);
if ($add_result === false) {
return __('Column creation failed, you may have too many columns or the default value does not match with field data type.', 'geodirectory');
}
break;
case 'multiselect':
case 'select':
$data_type = 'VARCHAR';
$op_size = '500';
// only make the field as big as it needs to be.
if (isset($option_values) && $option_values && $field_type == 'select') {
$option_values_arr = explode(',', $option_values);
if (is_array($option_values_arr)) {
$op_max = 0;
foreach ($option_values_arr as $op_val) {
if (strlen($op_val) && strlen($op_val) > $op_max) {
$op_max = strlen($op_val);
}
}
if ($op_max) {
$op_size = $op_max;
}
}
} elseif (isset($option_values) && $option_values && $field_type == 'multiselect') {
if (strlen($option_values)) {
$op_size = strlen($option_values);
}
if (isset($request_field['multi_display_type'])) {
$extra_fields = $request_field['multi_display_type'];
}
}
$meta_field_add = $data_type . "( $op_size ) NULL ";
if ($default_value != '') {
$meta_field_add .= " DEFAULT '" . $default_value . "'";
}
$add_result = geodir_add_column_if_not_exist($detail_table, $htmlvar_name, $meta_field_add);
if ($add_result === false) {
return __('Column creation failed, you may have too many columns or the default value does not match with field data type.', 'geodirectory');
}
break;
case 'textarea':
case 'html':
case 'url':
case 'file':
$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."'"; }*/
$add_result = geodir_add_column_if_not_exist($detail_table, $htmlvar_name, $meta_field_add);
if ($add_result === false) {
return __('Column creation failed, you may have too many columns or the default value does not match with field data type.', 'geodirectory');
}
break;
case 'datepicker':
$data_type = 'DATE';
$default_value_add = " `" . $htmlvar_name . "` " . $data_type . " NULL ";
$meta_field_add = $data_type . " NULL ";
$add_result = geodir_add_column_if_not_exist($detail_table, $htmlvar_name, $meta_field_add);
if ($add_result === false) {
return __('Column creation failed, you may have too many columns or the default value might have a invalid date format.', 'geodirectory');
}
break;
case 'time':
$data_type = 'TIME';
$default_value_add = " `" . $htmlvar_name . "` " . $data_type . " NULL ";
$meta_field_add = $data_type . " NULL ";
$add_result = geodir_add_column_if_not_exist($detail_table, $htmlvar_name, $meta_field_add);
if ($add_result === false) {
return __('Column creation failed, you may have too many columns or the default value might have a invalid time format.', 'geodirectory');
}
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 . "'";
}
}
$add_result = geodir_add_column_if_not_exist($detail_table, $htmlvar_name, $meta_field_add);
if ($add_result === false) {
return __('Column creation failed, you may have too many columns or the default value does not match with field data type.', 'geodirectory');
}
break;
endswitch;
$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
post_type = %s,
admin_title = %s,
site_title = %s,
field_type = %s,
field_type_key = %s,
htmlvar_name = %s,
admin_desc = %s,
clabels = %s,
default_value = %s,
sort_order = %d,
is_active = %s,
is_default = %s,
is_admin = %s,
is_required = %s,
required_msg = %s,
css_class = %s,
field_icon = %s,
show_on_listing = %s,
show_in = %s,
show_on_detail = %s,
show_as_tab = %s,
option_values = %s,
packages = %s,
cat_sort = %s,
cat_filter = %s,
data_type = %s,
extra_fields = %s,
decimal_point = %s,
validation_pattern = %s,
validation_msg = %s,
for_admin_use = %s ",
array($post_type, $admin_title, $site_title, $field_type, $field_type_key, $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_in, $show_on_detail, $show_as_tab, $option_values, $price_pkg, $cat_sort, $cat_filter, $data_type, $extra_field_query, $decimal_point,$validation_pattern,$validation_msg, $for_admin_use)
)
);
$lastid = $wpdb->insert_id;
$lastid = trim($lastid);
}
return (int)$lastid;
} else {
return 'HTML Variable Name should be a unique name';
}
}
}
/**
* Set custom field order
*
* @since 1.0.0
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
* @param array $field_ids List of field ids.
* @return array|bool Returns field ids when success, else returns false.
*/
function godir_set_field_order($field_ids = array())
{
global $wpdb;
$count = 0;
if (!empty($field_ids)):
$post_meta_info = false;
foreach ($field_ids as $id) {
$cf = trim($id, '_');
$post_meta_info = $wpdb->query(
$wpdb->prepare(
"update " . GEODIR_CUSTOM_FIELDS_TABLE . " set
sort_order=%d
where id= %d",
array($count, $cf)
)
);
$count++;
}
return $post_meta_info;
else:
return false;
endif;
}
function geodir_get_cf_value($cf) {
global $gd_session;
$value = '';
if (is_admin()) {
global $post;
if (isset($_REQUEST['post'])) {
$_REQUEST['pid'] = (int)$_REQUEST['post'];
}
}
if (isset($_REQUEST['backandedit']) && $_REQUEST['backandedit'] && $gd_ses_listing = $gd_session->get('listing')) {
$post = $gd_ses_listing;
$value = isset($post[$cf['name']]) ? $post[$cf['name']] : '';
} elseif (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') {
$value = geodir_get_post_meta($_REQUEST['pid'], $cf['name'], true);
} else {
if ($value == '') {
$value = $cf['default'];
}
}
/**
* Filter the custom field value.
*
* @since 1.6.20
*
* @param mixed $value Custom field value.
* @param array $cf Custom field info.
*/
return apply_filters( 'geodir_get_cf_value', $value, $cf );
}
/**
* Displays custom fields html.
*
* @since 1.0.0
* @since 1.5.2 Added TERRAIN map type.
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
* @global object $post The current post object.
* @global array $geodir_addon_list List of active GeoDirectory extensions.
* @global object $gd_session GeoDirectory Session object.
*
* @param int|string $package_id The package ID.
* @param string $default Optional. When set to "default" it will display only default fields.
* @param string $post_type Optional. The wordpress post type.
*/
function geodir_get_custom_fields_html($package_id = '', $default = 'custom', $post_type = 'gd_place') {
global $is_default, $mapzoom, $gd_session;
$listing_type = $post_type;
$custom_fields = geodir_post_custom_fields($package_id, $default, $post_type);
foreach ($custom_fields as $key => $val) {
if(isset($val['extra_fields'])){$extra_fields = $val['extra_fields'];}
$val = stripslashes_deep($val); // strip slashes from labels
if(isset($val['extra_fields'])){$val['extra_fields'] = $extra_fields;}
$name = $val['name'];
$type = $val['type'];
$is_default = $val['is_default'];
/* field available to site admin only for edit */
$for_admin_use = isset($val['for_admin_use']) && (int)$val['for_admin_use'] == 1 ? true : false;
if ($for_admin_use && !is_super_admin()) {
continue;
}
if (is_admin()) {
global $post;
if (isset($_REQUEST['post']))
$_REQUEST['pid'] = $_REQUEST['post'];
}
/**
* Called before the custom fields info is output for submitting a post.
*
* Used dynamic hook type geodir_before_custom_form_field_$name.
*
* @since 1.0.0
* @param string $listing_type The post post type.
* @param int $package_id The price package ID for the post.
* @param array $val The settings array for the field. {@see geodir_custom_field_save()}.
* @see 'geodir_after_custom_form_field_$name'
*/
do_action('geodir_before_custom_form_field_' . $name, $listing_type, $package_id, $val);
$custom_field = $val;
$html ='';
/**
* Filter the output for custom fields.
*
* Here we can remove or add new functions depending on the field type.
*
* @param string $html The html to be filtered (blank).
* @param array $custom_field The custom field array values.
*/
echo apply_filters("geodir_custom_field_input_{$type}",$html,$custom_field);
/**
* Called after the custom fields info is output for submitting a post.
*
* Used dynamic hook type geodir_after_custom_form_field_$name.
*
* @since 1.0.0
* @param string $listing_type The post post type.
* @param int $package_id The price package ID for the post.
* @param array $val The settings array for the field. {@see geodir_custom_field_save()}.
* @see 'geodir_before_custom_form_field_$name'
*/
do_action('geodir_after_custom_form_field_' . $name, $listing_type, $package_id, $val);
}
}
if (!function_exists('geodir_get_field_infoby')) {
/**
* Get custom field using key and value.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
* @param string $key The key you want to look for.
* @param string $value The value of the key you want to look for.
* @param string $geodir_post_type The post type.
* @return bool|mixed Returns field info when available. otherwise returns false.
*/
function geodir_get_field_infoby($key = '', $value = '', $geodir_post_type = '')
{
global $wpdb;
$filter = $wpdb->get_row(
$wpdb->prepare(
"SELECT * FROM " . GEODIR_CUSTOM_FIELDS_TABLE . " WHERE post_type=%s AND " . $key . "='" . $value . "'",
array($geodir_post_type)
),ARRAY_A
);
if ($filter) {
return $filter;
} else {
return false;
}
}
}
function geodir_field_icon_proccess($cf){
if (strpos($cf['field_icon'], 'http') !== false) {
$field_icon = ' background: url(' . $cf['field_icon'] . ') no-repeat left center;background-size:18px 18px;padding-left: 21px;';
} elseif (strpos($cf['field_icon'], ' fa-') !== false) {
$field_icon = '<i class="' . $cf['field_icon'] . ' fa-fw"></i>';
}else{
$field_icon = $cf['field_icon'];
}
return $field_icon;
}
if (!function_exists('geodir_show_listing_info')) {
/**
* Show listing info depending on field location.
*
* @since 1.0.0
* @since 1.5.7 Custom fields option values added to db translation.
* Changes to display url fields title.
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
* @global object $post The current post object.
*
* @param string $fields_location In which page you are going to place this custom fields?. Ex: listing, detail etc.
* @return string Returns listing info html.
*/
function geodir_show_listing_info($fields_location = '') {
global $post, $preview, $wpdb;
$package_info = array();
if(!$preview && !isset($post->post_id)){
$post = geodir_get_post_info($post->ID);
}
$package_info = geodir_post_package_info($package_info, $post);
$post_package_id = !empty($package_info->pid) ? $package_info->pid : '';
$p_type = !empty($post->post_type) ? $post->post_type : geodir_get_current_posttype();
ob_start();
$fields_info = geodir_post_custom_fields($post_package_id, 'all', $p_type, $fields_location);
if (!empty($fields_info)) {
$post = stripslashes_deep($post); // strip slashes
//echo '<div class="geodir-company_info field-group">';
global $field_set_start;
$field_set_start = 0;
foreach ($fields_info as $type) {
if(isset($type['extra_fields'])){$extra_fields= $type['extra_fields'];}
$type = stripslashes_deep($type); // strip slashes
if(isset($type['extra_fields'])){$type['extra_fields'] = $extra_fields;}
$html = '';
$field_icon = geodir_field_icon_proccess($type);
$filed_type = $type['type'];
$html_var = isset($type['htmlvar_name']) ? $type['htmlvar_name'] : '';
if($html_var=='post'){$html_var='post_address';}
/**
* Filter the output for custom fields.
*
* Here we can remove or add new functions depending on the field type.
*
* @param string $html The html to be filtered (blank).
* @param string $fields_location The location the field is to be show.
* @param array $type The array of field values.
*/
$html = apply_filters("geodir_custom_field_output_{$filed_type}",$html,$fields_location,$type);
$variables_array = array();
if ($type['type'] != 'fieldset'):
$variables_array['post_id'] = !empty($post->ID) ? $post->ID : (!empty($post->pid) ? $post->pid : NULL);
$variables_array['label'] = __($type['site_title'], 'geodirectory');
$variables_array['value'] = '';
if (isset($post->{$type['htmlvar_name']}))
$variables_array['value'] = $post->{$type['htmlvar_name']};
endif;
if ($html):
/**
* Called before a custom fields is output on the frontend.
*
* @since 1.0.0
* @param string $html_var The HTML variable name for the field.
*/
do_action("geodir_before_show_{$html_var}");
/**
* Filter custom field output.
*
* @since 1.0.0
*
* @param string $html_var The HTML variable name for the field.
* @param string $html Custom field unfiltered HTML.
* @param array $variables_array Custom field variables array.
*/
if ($html) echo apply_filters("geodir_show_{$html_var}", $html, $variables_array);
/**
* Called after a custom fields is output on the frontend.
*
* @since 1.0.0
* @param string $html_var The HTML variable name for the field.
*/
do_action("geodir_after_show_{$html_var}");
endif;
}
//echo '</div>';
}
$html = ob_get_clean();
/**
* Filter the custom fields over all output.
*
* @param string $html The html of the custom fields.
* @param string $fields_location The location the fields are being output.
* @since 1.6.9
*/
return apply_filters('geodir_show_listing_info',$html,$fields_location);
}
}
if (!function_exists('geodir_default_date_format')) {
/**
* Returns default date format.
*
* @since 1.0.0
* @package GeoDirectory
* @return mixed|string|void Returns default date format.
*/
function geodir_default_date_format()
{
if ($format = get_option('date_format'))
return $format;
else
return 'dd-mm-yy';
}
}
if (!function_exists('geodir_get_formated_date')) {
/**
* Returns formatted date.
*
* @since 1.0.0
* @package GeoDirectory
* @param string $date Date string to convert.
* @return bool|int|string Returns formatted date.
*/
function geodir_get_formated_date($date)
{
return mysql2date(get_option('date_format'), $date);
}
}
if (!function_exists('geodir_get_formated_time')) {
/**
* Returns formatted time.
*
* @since 1.0.0
* @package GeoDirectory
* @param string $time Time string to convert.
* @return bool|int|string Returns formatted time.
*/
function geodir_get_formated_time($time)
{
return mysql2date(get_option('time_format'), $time, $translate = true);
}
}
if (!function_exists('geodir_save_post_file_fields')) {
/**
* Save post file fields
*
* @since 1.0.0
* @since 1.4.7 Added `$extra_fields` parameter.
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
* @global string $plugin_prefix Geodirectory plugin table prefix.
* @global object $current_user Current user object.
* @param int $post_id
* @param string $field_id
* @param array $post_image
* @param array $extra_fields Array of extra fields.
*/
function geodir_save_post_file_fields($post_id = 0, $field_id = '', $post_image = array(), $extra_fields = array())
{
global $wpdb, $plugin_prefix, $current_user;
$post_type = get_post_type($post_id);
//echo $field_id; exit;
$table = $plugin_prefix . $post_type . '_detail';
$postcurr_images = array();
$postcurr_images = geodir_get_post_meta($post_id, $field_id, true);
$file_urls = '';
if (!empty($post_image)) {
$invalid_files = array();
//Get and remove all old images of post from database to set by new order
$geodir_uploaddir = '';
$uploads = wp_upload_dir();
$uploads_dir = $uploads['path'];
$geodir_uploadpath = $uploads['path'];
$geodir_uploadurl = $uploads['url'];
$sub_dir = $uploads['subdir'];
$allowed_file_types = !empty($extra_fields['gd_file_types']) && is_array($extra_fields['gd_file_types']) && !in_array("*", $extra_fields['gd_file_types'] ) ? $extra_fields['gd_file_types'] : '';
for ($m = 0; $m < count($post_image); $m++) {
/* --------- start ------- */
if (!$find_image = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM " . $table . " WHERE $field_id = %s AND post_id = %d", array($post_image[$m], $post_id)))) {
$curr_img_url = $post_image[$m];
$image_name_arr = explode('/', $curr_img_url);
$curr_img_dir = $image_name_arr[count($image_name_arr) - 2];
$filename = end($image_name_arr);
$img_name_arr = explode('.', $filename);
$arr_file_type = wp_check_filetype($filename);
if (empty($arr_file_type['ext']) || empty($arr_file_type['type'])) {
continue;
}
$uploaded_file_type = $arr_file_type['type'];
$uploaded_file_ext = $arr_file_type['ext'];
if (!empty($allowed_file_types) && !in_array($uploaded_file_ext, $allowed_file_types)) {
continue; // Invalid file type.
}
// Set an array containing a list of acceptable formats
//$allowed_file_types = array('image/jpg', 'image/jpeg', 'image/gif', 'image/png', 'application/pdf', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/octet-stream', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'text/csv', 'text/plain');
if (!function_exists('wp_handle_upload'))
require_once(ABSPATH . 'wp-admin/includes/file.php');
if (!is_dir($geodir_uploadpath))
mkdir($geodir_uploadpath);
$new_name = $post_id . '_' . $field_id . '_' . $img_name_arr[0] . '.' . $img_name_arr[1];
$explode_sub_dir = explode("/", $sub_dir);
if ($curr_img_dir == end($explode_sub_dir)) {
$img_path = $geodir_uploadpath . '/' . $filename;
$img_url = $geodir_uploadurl . '/' . $filename;
} else {
$img_path = $uploads_dir . '/temp_' . $current_user->data->ID . '/' . $filename;
$img_url = $uploads['url'] . '/temp_' . $current_user->data->ID . '/' . $filename;
}
$uploaded_file = '';
if (file_exists($img_path))
$uploaded_file = copy($img_path, $geodir_uploadpath . '/' . $new_name);
if ($curr_img_dir != $geodir_uploaddir) {
if (file_exists($img_path))
unlink($img_path);
}
if (!empty($uploaded_file))
$file_urls = $geodir_uploadurl . '/' . $new_name;
} else {
$file_urls = $post_image[$m];
}
}
}
//Remove all old attachments and temp images
if (!empty($postcurr_images)) {
if ($file_urls != $postcurr_images) {
$invalid_files[] = (object)array('src' => $postcurr_images);
$invalid_files = (object)$invalid_files;
}
}
geodir_save_post_meta($post_id, $field_id, $file_urls);
if (!empty($invalid_files))
geodir_remove_attachments($invalid_files);
}
}
add_filter('upload_mimes', 'geodir_custom_upload_mimes');
/**
* Returns list of supported mime types for upload handling.
*
* @since 1.0.0
* @package GeoDirectory
* @param array $existing_mimes List of existing mime types.
* @return array Returns list of supported mime types.
*/
function geodir_custom_upload_mimes($existing_mimes = array())
{
$existing_mimes['wif'] = 'text/plain';
$existing_mimes['jpg|jpeg'] = 'image/jpeg';
$existing_mimes['gif'] = 'image/gif';
$existing_mimes['png'] = 'image/png';
$existing_mimes['pdf'] = 'application/pdf';
$existing_mimes['txt'] = 'text/text';
$existing_mimes['csv'] = 'application/octet-stream';
$existing_mimes['doc'] = 'application/msword';
$existing_mimes['xla|xls|xlt|xlw'] = 'application/vnd.ms-excel';
$existing_mimes['docx'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
$existing_mimes['xlsx'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
return $existing_mimes;
}
if (!function_exists('geodir_plupload_action')) {
/**
* Get upload directory path details
*
* @since 1.0.0
* @package GeoDirectory
* @global object $current_user Current user object.
* @param array $upload Array of upload directory data with keys of 'path','url', 'subdir, 'basedir', and 'error'.
* @return mixed Returns upload directory details as an array.
*/
function geodir_upload_dir($upload)
{
global $current_user;
$upload['subdir'] = $upload['subdir'] . '/temp_' . $current_user->data->ID;
$upload['path'] = $upload['basedir'] . $upload['subdir'];
$upload['url'] = $upload['baseurl'] . $upload['subdir'];
return $upload;
}
/**
* Handles place file and image upload.
*
* @since 1.0.0
* @package GeoDirectory
*/
function geodir_plupload_action()
{
// check ajax nonce
$imgid = $_POST["imgid"];
check_ajax_referer($imgid . 'pluploadan');
// handle custom file uploaddir
add_filter('upload_dir', 'geodir_upload_dir');
// change file orientation if needed
$fixed_file = geodir_exif($_FILES[$imgid . 'async-upload']);
// handle file upload
$status = wp_handle_upload($fixed_file, array('test_form' => true, 'action' => 'plupload_action'));
// remove handle custom file uploaddir
remove_filter('upload_dir', 'geodir_upload_dir');
if(!isset($status['url']) && isset($status['error'])){
print_r($status);
}
// send the uploaded file url in response
if (isset($status['url'])) {
echo $status['url'];
} else {
echo 'x';
}
exit;
}
}
/**
* Get video using post ID.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
* @global string $plugin_prefix Geodirectory plugin table prefix.
* @param int $post_id The post ID.
* @return mixed Returns video.
*/
function geodir_get_video($post_id)
{
global $wpdb, $plugin_prefix;
$post_type = get_post_type($post_id);
$table = $plugin_prefix . $post_type . '_detail';
$results = $wpdb->get_results($wpdb->prepare("SELECT geodir_video FROM " . $table . " WHERE post_id=%d", array($post_id)));
if ($results) {
return $results[0]->geodir_video;
}
}
/**
* Get special offers using post ID.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
* @global string $plugin_prefix Geodirectory plugin table prefix.
* @param int $post_id The post ID.
* @return mixed Returns special offers.
*/
function geodir_get_special_offers($post_id)
{
global $wpdb, $plugin_prefix;
$post_type = get_post_type($post_id);
$table = $plugin_prefix . $post_type . '_detail';
$results = $wpdb->get_results($wpdb->prepare("SELECT geodir_special_offers FROM " . $table . " WHERE post_id=%d", array($post_id)));
if ($results) {
return $results[0]->geodir_special_offers;
}
}
if (!function_exists('geodir_max_upload_size')) {
/**
* Get max upload file size
*
* @since 1.0.0
* @package GeoDirectory
* @return mixed|void Returns max upload file size.
*/
function geodir_max_upload_size()
{
$max_filesize = (float)get_option('geodir_upload_max_filesize', 2);
if ($max_filesize > 0 && $max_filesize < 1) {
$max_filesize = (int)($max_filesize * 1024) . 'kb';
} else {
$max_filesize = $max_filesize > 0 ? $max_filesize . 'mb' : '2mb';
}
/** Filter documented in geodirectory-functions/general_functions.php **/
return apply_filters('geodir_default_image_upload_size_limit', $max_filesize);
}
}
add_filter('geodir_add_custom_sort_options', 'geodir_add_custom_sort_options', 0, 2);
/**
* Add custom sort options to the existing fields.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
* @param array $fields The sorting fields array
* @param string $post_type The post type.
* @return array Returns the fields.
*/
function geodir_add_custom_sort_options($fields, $post_type)
{
global $wpdb;
if ($post_type != '') {
$all_postypes = geodir_get_posttypes();
if (in_array($post_type, $all_postypes)) {
$custom_fields = $wpdb->get_results(
$wpdb->prepare(
"select post_type,data_type,field_type,site_title,admin_title,htmlvar_name,field_icon from " . GEODIR_CUSTOM_FIELDS_TABLE . " where post_type = %s and is_active='1' and cat_sort='1' AND field_type != 'address' order by sort_order asc",
array($post_type)
), 'ARRAY_A'
);
if (!empty($custom_fields)) {
foreach ($custom_fields as $val) {
$fields[] = $val;
}
}
}
}
return $fields;
}
/**
* Get sort options based on post type.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
* @param string $post_type The post type.
* @return bool|mixed|void Returns sort options when post type available. Otherwise returns false.
*/
function geodir_get_custom_sort_options($post_type = '')
{
global $wpdb;
if ($post_type != '') {
$all_postypes = geodir_get_posttypes();
if (!in_array($post_type, $all_postypes))
return false;
$fields = array();
$fields[] = array(
'post_type' => $post_type,
'data_type' => '',
'field_type' => 'random',
'site_title' => 'Random',
'htmlvar_name' => 'post_title',
'field_icon' => 'fas fa-random',
'description' => __('Random sort (not recommended for large sites)', 'geodirectory')
);
$fields[] = array(
'post_type' => $post_type,
'data_type' => '',
'field_type' => 'datetime',
'site_title' => __('Add date', 'geodirectory'),
'htmlvar_name' => 'post_date',
'field_icon' => 'fas fa-calendar-alt',
'description' => __('Sort by date added', 'geodirectory')
);
$fields[] = array(
'post_type' => $post_type,
'data_type' => '',
'field_type' => 'bigint',
'site_title' => __('Review', 'geodirectory'),
'htmlvar_name' => 'comment_count',
'field_icon' => 'far fa-comment-dots',
'description' => __('Sort by the number of reviews', 'geodirectory')
);
$fields[] = array(
'post_type' => $post_type,
'data_type' => '',
'field_type' => 'float',
'site_title' => __('Rating', 'geodirectory'),
'htmlvar_name' => 'overall_rating',
'field_icon' => 'far fa-star',
'description' => __('Sort by the overall rating value', 'geodirectory')
);
$fields[] = array(
'post_type' => $post_type,
'data_type' => '',
'field_type' => 'text',
'site_title' => __('Title', 'geodirectory'),
'htmlvar_name' => 'post_title',
'field_icon' => 'fas fa-sort-alpha-up',
'description' => __('Sort alphabetically by title', 'geodirectory')
);
/**
* Hook to add custom sort options.
*
* @since 1.0.0
* @param array $fields Unmodified sort options array.
* @param string $post_type Post type.
*/
return $fields = apply_filters('geodir_add_custom_sort_options', $fields, $post_type);
}
return false;
}
/**
* Set custom sort field order.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
* @param array $field_ids List of field ids.
* @return array|bool Returns field ids. If no field id, returns false.
*/
function godir_set_sort_field_order($field_ids = array())
{
global $wpdb;
$count = 0;
if (!empty($field_ids)):
foreach ($field_ids as $id) {
$cf = trim($id, '_');
$post_meta_info = $wpdb->query(
$wpdb->prepare(
"update " . GEODIR_CUSTOM_SORT_FIELDS_TABLE . " set
sort_order=%d
where id= %d",
array($count, $cf)
)
);
$count++;
}
return $field_ids;
else:
return false;
endif;
}
if (!function_exists('geodir_custom_sort_field_save')) {
/**
* Save or Update custom sort 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.
*
* @type string $action Ajax action name.
* @type string $manage_field_type Manage field type Default "sorting_options".
* @type string $create_field Do you want to create this field?.
* @type string $field_ins_upd Field created or updated?.
* @type string $_wpnonce Nonce value.
* @type string $listing_type The Post type.
* @type string $field_type Field Type.
* @type string $field_id Field ID.
* @type string $data_type Data Type.
* @type string $htmlvar_name HTML variable name.
* @type string $site_title Section title which you wish to display in frontend.
* @type string $is_default Is this default sorting?.
* @type string $is_active If not active then the field will not be displayed anywhere.
* @type string $sort_order Sort Order.
*
* }
* @param bool $default Not yet implemented.
* @return int Returns the last affected db table row id.
*/
function geodir_custom_sort_field_save($request_field = array(), $default = false)
{
global $wpdb, $plugin_prefix;
$result_str = isset($request_field['field_id']) ? trim($request_field['field_id']) : '';
$cf = trim($result_str, '_');
/*-------- check duplicate validation --------*/
$field_type = isset($request_field['field_type']) ? $request_field['field_type'] : '';
$cehhtmlvar_name = isset($request_field['htmlvar_name']) ? $request_field['htmlvar_name'] : '';
$post_type = $request_field['listing_type'];
$data_type = isset($request_field['data_type']) ? $request_field['data_type'] : '';
$field_type = isset($request_field['field_type']) ? $request_field['field_type'] : '';
$site_title = isset($request_field['site_title']) ? $request_field['site_title'] : '';
$htmlvar_name = isset($request_field['htmlvar_name']) ? $request_field['htmlvar_name'] : '';
$sort_order = isset($request_field['sort_order']) ? $request_field['sort_order'] : 0;
$is_active = isset($request_field['is_active']) ? $request_field['is_active'] : 0;
$is_default = isset($request_field['is_default']) ? $request_field['is_default'] : '';
$asc = isset($request_field['asc']) ? $request_field['asc'] : 0;
$desc = isset($request_field['desc']) ? $request_field['desc'] : 0;
$asc_title = isset($request_field['asc_title']) ? $request_field['asc_title'] : '';
$desc_title = isset($request_field['desc_title']) ? $request_field['desc_title'] : '';
$default_order = '';
if ($is_default != '') {
$default_order = $is_default;
$is_default = '1';
}
$check_html_variable = $wpdb->get_var(
$wpdb->prepare(
"select htmlvar_name from " . GEODIR_CUSTOM_SORT_FIELDS_TABLE . " where htmlvar_name = %s and post_type = %s and field_type=%s ",
array($cehhtmlvar_name, $post_type, $field_type)
)
);
if ($is_default == 1) {
$wpdb->query($wpdb->prepare("update " . GEODIR_CUSTOM_SORT_FIELDS_TABLE . " set is_default='0', default_order='' where post_type = %s", array($post_type)));
}
if (!$check_html_variable) {
$wpdb->query(
$wpdb->prepare(
"insert into " . GEODIR_CUSTOM_SORT_FIELDS_TABLE . " set
post_type = %s,
data_type = %s,
field_type = %s,
site_title = %s,
htmlvar_name = %s,
sort_order = %d,
is_active = %d,
is_default = %d,
default_order = %s,
sort_asc = %d,
sort_desc = %d,
asc_title = %s,
desc_title = %s",
array($post_type, $data_type, $field_type, $site_title, $htmlvar_name, $sort_order, $is_active, $is_default, $default_order, $asc, $desc, $asc_title, $desc_title)
)
);
$lastid = $wpdb->insert_id;
$lastid = trim($lastid);
} else {
$wpdb->query(
$wpdb->prepare(
"update " . GEODIR_CUSTOM_SORT_FIELDS_TABLE . " set
post_type = %s,
data_type = %s,
field_type = %s,
site_title = %s,
htmlvar_name = %s,
sort_order = %d,
is_active = %d,
is_default = %d,
default_order = %s,
sort_asc = %d,
sort_desc = %d,
asc_title = %s,
desc_title = %s
where id = %d",
array($post_type, $data_type, $field_type, $site_title, $htmlvar_name, $sort_order, $is_active, $is_default, $default_order, $asc, $desc, $asc_title, $desc_title, $cf)
)
);
$lastid = trim($cf);
}
return (int)$lastid;
}
}
if (!function_exists('geodir_custom_sort_field_delete')) {
/**
* Delete a custom sort field using field id.
* @since 1.0.0
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
* @global string $plugin_prefix Geodirectory plugin table prefix.
* @param string $field_id The field ID.
* @return int|string Returns field id when successful deletion, else returns 0.
*/
function geodir_custom_sort_field_delete($field_id = '')
{
global $wpdb, $plugin_prefix;
if ($field_id != '') {
$cf = trim($field_id, '_');
$wpdb->query($wpdb->prepare("delete from " . GEODIR_CUSTOM_SORT_FIELDS_TABLE . " where id= %d ", array($cf)));
return $field_id;
} else
return 0;
}
}
if (!function_exists('geodir_custom_sort_field_adminhtml')) {
/**
* Custom sort field admin html.
*
* @since 1.0.0
* @package GeoDirectory
* @global object $wpdb WordPress Database object.
* @param string $field_type The form field type.
* @param object|int $result_str The custom field results object or row id.
* @param string $field_ins_upd When set to "submit" displays form.
* @param bool $default when set to true field will be for admin use only.
*/
function geodir_custom_sort_field_adminhtml($field_type, $result_str, $field_ins_upd = '', $field_type_key='')
{
global $wpdb;
$cf = $result_str;
if (!is_object($cf)) {
$field_info = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . GEODIR_CUSTOM_SORT_FIELDS_TABLE . " WHERE id = %d", array($cf)));
} else {
$field_info = $cf;
$result_str = $cf->id;
}
$field_info = stripslashes_deep($field_info); // strip slashes
if (!isset($field_info->post_type)) {
$post_type = sanitize_text_field($_REQUEST['listing_type']);
} else {
$post_type = $field_info->post_type;
}
$htmlvar_name = isset($field_type_key) ? $field_type_key : '';
$site_title = '';
if ($site_title == '')
$site_title = isset($field_info->site_title) ? $field_info->site_title : '';
if ($site_title == '') {
$fields = geodir_get_custom_sort_options($post_type);
foreach ($fields as $val) {
$val = stripslashes_deep($val); // strip slashes
if ($val['field_type'] == $field_type && $val['htmlvar_name'] == $htmlvar_name) {
$site_title = isset($val['site_title']) ? $val['site_title'] : '';
}
}
}
if ($htmlvar_name == '')
$htmlvar_name = isset($field_info->htmlvar_name) ? $field_info->htmlvar_name : '';
$nonce = wp_create_nonce('custom_fields_' . $result_str);
$field_icon = '<i class="fas fa-cog" aria-hidden="true"></i>';
$cso_arr = geodir_get_custom_sort_options($post_type);
$cur_field_type = (isset($cf->field_type)) ? $cf->field_type : esc_html($_REQUEST['field_type']);
foreach($cso_arr as $cso){
if($cur_field_type==$cso['field_type']){
if (isset($cso['field_icon']) && strpos($cso['field_icon'], ' fa-') !== false) {
$field_icon = '<i class="'.$cso['field_icon'].'" aria-hidden="true"></i>';
}elseif(isset($cso['field_icon']) && $cso['field_icon']){
$field_icon = '<b class="gd-cf-icon" style="background-image: url(\''.$cso['field_icon'].'\')"></b>';
}
}
}
$radio_id = (isset($field_info->htmlvar_name)) ? $field_info->htmlvar_name.$field_type : rand(5, 500);
?>
<li class="text" id="licontainer_<?php echo $result_str;?>">
<form><!-- we need to wrap in a form so we can use radio buttons with same name -->
<div class="title title<?php echo $result_str;?> gt-fieldset"
title="<?php _e('Double Click to toggle and drag-drop to sort', 'geodirectory');?>"
ondblclick="show_hide('field_frm<?php echo $result_str;?>')">
<?php
?>
<div title="<?php _e('Click to remove field', 'geodirectory');?>"
onclick="delete_sort_field('<?php echo $result_str;?>', '<?php echo $nonce;?>', this)"
class="handlediv close"><i class="fas fa-times" aria-hidden="true"></i></div>
<?php echo $field_icon;?>
<b style="cursor:pointer;"
onclick="show_hide('field_frm<?php echo $result_str;?>')"><?php echo geodir_ucwords(__('Field:', 'geodirectory') . ' (' . $site_title . ')');?></b>
</div>
<div id="field_frm<?php echo $result_str;?>" class="field_frm"
style="display:<?php if ($field_ins_upd == 'submit') {
echo 'block;';
} else {
echo 'none;';
} ?>">
<input type="hidden" name="_wpnonce" value="<?php echo $nonce; ?>"/>
<input type="hidden" name="listing_type" id="listing_type" value="<?php echo $post_type;?>"/>
<input type="hidden" name="field_type" id="field_type" value="<?php echo $field_type;?>"/>
<input type="hidden" name="field_id" id="field_id" value="<?php echo $result_str;?>"/>
<input type="hidden" name="data_type" id="data_type" value="<?php if (isset($field_info->data_type)) {
echo $field_info->data_type;
}?>"/>
<input type="hidden" name="htmlvar_name" id="htmlvar_name" value="<?php echo $htmlvar_name;?>"/>
<ul class="widefat post fixed" border="0" style="width:100%;">
<?php if ($field_type != 'random') { ?>
<input type="hidden" name="site_title" id="site_title" value="<?php echo esc_attr($site_title); ?>"/>
<li>
<?php $value = (isset($field_info->sort_asc) && $field_info->sort_asc) ? $field_info->sort_asc : 0;?>
<label for="asc" class="gd-cf-tooltip-wrap">
<i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('Show Ascending Sort (low to high)', 'geodirectory'); ?>
<div class="gdcf-tooltip">
<?php _e('Select if you want to show this option in the sort options. (A-Z,0-100 or OFF)', 'geodirectory'); ?>
</div>
</label>
<div class="gd-cf-input-wrap gd-switch">
<input type="radio" id="asc_yes<?php echo $radio_id;?>" name="asc" class="gdri-enabled" value="1"
<?php if ($value == '1') {
echo 'checked';
} ?>/>
<label onclick="show_hide_radio(this,'show','cfs-asc-title');" for="asc_yes<?php echo $radio_id;?>" class="gdcb-enable"><span><?php _e('Yes', 'geodirectory'); ?></span></label>
<input type="radio" id="asc_no<?php echo $radio_id;?>" name="asc" class="gdri-disabled" value="0"
<?php if ($value == '0' || !$value) {
echo 'checked';
} ?>/>
<label onclick="show_hide_radio(this,'hide','cfs-asc-title');" for="asc_no<?php echo $radio_id;?>" class="gdcb-disable"><span><?php _e('No', 'geodirectory'); ?></span></label>
</div>
</li>
<li class="cfs-asc-title" <?php if ((isset($field_info->sort_asc) && $field_info->sort_asc == '0') || !isset($field_info->sort_asc)) {echo "style='display:none;'";}?>>
<?php $value = (isset($field_info->asc_title) && $field_info->asc_title) ? esc_attr($field_info->asc_title) : '';?>
<label for="asc_title" class="gd-cf-tooltip-wrap">
<i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('Ascending title', 'geodirectory'); ?>
<div class="gdcf-tooltip">
<?php _e('This is the text used for the sort option.', 'geodirectory'); ?>
</div>
</label>
<div class="gd-cf-input-wrap">
<input type="text" name="asc_title" id="asc_title" value="<?php echo $value;?>" />
</div>
</li>
<li class="cfs-asc-title" <?php if ((isset($field_info->sort_asc) && $field_info->sort_asc == '0') || !isset($field_info->sort_asc)) {echo "style='display:none;'";}?>>
<label for="is_default" class="gd-cf-tooltip-wrap">
<i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('Default sort?', 'geodirectory'); ?>
<div class="gdcf-tooltip">
<?php _e('This sets the option as the overall default sort value, there can be only one.', 'geodirectory'); ?>
</div>
</label>
<div class="gd-cf-input-wrap">
<input type="radio" name="is_default"
value="<?php echo $htmlvar_name; ?>_asc" <?php if (isset($field_info->default_order) && $field_info->default_order == $htmlvar_name . '_asc') {
echo 'checked="checked"';
} ?>/>
</div>
</li>
<li>
<?php $value = (isset($field_info->sort_desc) && $field_info->sort_desc) ? $field_info->sort_desc : 0;?>
<label for="desc" class="gd-cf-tooltip-wrap">
<i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('Show Descending Sort (high to low)', 'geodirectory'); ?>
<div class="gdcf-tooltip">
<?php _e('Select if you want to show this option in the sort options. (Z-A,100-0 or ON)', 'geodirectory'); ?>
</div>
</label>
<div class="gd-cf-input-wrap gd-switch">
<input type="radio" id="desc_yes<?php echo $radio_id;?>" name="desc" class="gdri-enabled" value="1"
<?php if ($value == '1') {
echo 'checked';
} ?>/>
<label onclick="show_hide_radio(this,'show','cfs-desc-title');" for="desc_yes<?php echo $radio_id;?>" class="gdcb-enable"><span><?php _e('Yes', 'geodirectory'); ?></span></label>
<input type="radio" id="desc_no<?php echo $radio_id;?>" name="desc" class="gdri-disabled" value="0"
<?php if ($value == '0' || !$value) {
echo 'checked';
} ?>/>
<label onclick="show_hide_radio(this,'hide','cfs-desc-title');" for="desc_no<?php echo $radio_id;?>" class="gdcb-disable"><span><?php _e('No', 'geodirectory'); ?></span></label>
</div>
</li>
<li class="cfs-desc-title" <?php if ((isset($field_info->sort_desc) && $field_info->sort_desc == '0') || !isset($field_info->sort_desc)) {echo "style='display:none;'";}?>>
<?php $value = (isset($field_info->desc_title) && $field_info->desc_title) ? esc_attr($field_info->desc_title) : '';?>
<label for="desc_title" class="gd-cf-tooltip-wrap">
<i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('Descending title', 'geodirectory'); ?>
<div class="gdcf-tooltip">
<?php _e('This is the text used for the sort option.', 'geodirectory'); ?>
</div>
</label>
<div class="gd-cf-input-wrap">
<input type="text" name="desc_title" id="desc_title" value="<?php echo $value;?>" />
</div>
</li>
<li class="cfs-desc-title" <?php if ((isset($field_info->sort_desc) && $field_info->sort_desc == '0') || !isset($field_info->sort_desc)) {echo "style='display:none;'";}?>>
<label for="is_default" class="gd-cf-tooltip-wrap">
<i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('Default sort?', 'geodirectory'); ?>
<div class="gdcf-tooltip">
<?php _e('This sets the option as the overall default sort value, there can be only one.', 'geodirectory'); ?>
</div>
</label>
<div class="gd-cf-input-wrap">
<input type="radio" name="is_default"
value="<?php echo $htmlvar_name; ?>_desc" <?php if (isset($field_info->default_order) && $field_info->default_order == $htmlvar_name . '_desc') {
echo 'checked="checked"';
} ?>/>
</div>
</li>
<?php } else { ?>
<li>
<?php $value = esc_attr($site_title)?>
<label for="site_title" class="gd-cf-tooltip-wrap">
<i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('Frontend title', 'geodirectory'); ?>
<div class="gdcf-tooltip">
<?php _e('This is the text used for the sort option.', 'geodirectory'); ?>
</div>
</label>
<div class="gd-cf-input-wrap">
<input type="text" name="site_title" id="site_title" value="<?php echo $value;?>" />
</div>
</li>
<li>
<?php $value = (isset($field_info->is_default) && $field_info->is_default) ? esc_attr($field_info->is_default) : '';?>
<label for="is_default" class="gd-cf-tooltip-wrap">
<i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('Default sort?', 'geodirectory'); ?>
<div class="gdcf-tooltip">
<?php _e('This sets the option as the overall default sort value, there can be only one.', 'geodirectory'); ?>
</div>
</label>
<div class="gd-cf-input-wrap">
<input type="checkbox" name="is_default"
value="<?php echo $field_type; ?>" <?php if (isset($value) && $value == '1') {
echo 'checked="checked"';
} ?>/>
</div>
</li>
<?php } ?>
<li>
<?php $value = (isset($field_info->is_active) && $field_info->is_active) ? $field_info->is_active: 0;?>
<label for="is_active" class="gd-cf-tooltip-wrap">
<i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('Is active', 'geodirectory'); ?>
<div class="gdcf-tooltip">
<?php _e('Set if this sort option is active or not, if not it will not be shown to users.', 'geodirectory'); ?>
</div>
</label>
<div class="gd-cf-input-wrap gd-switch">
<input type="radio" id="is_active_yes<?php echo $radio_id;?>" name="is_active" class="gdri-enabled" value="1"
<?php if ($value == '1') {
echo 'checked';
} ?>/>
<label for="is_active_yes<?php echo $radio_id;?>" class="gdcb-enable"><span><?php _e('Yes', 'geodirectory'); ?></span></label>