/** * Details page tab custom fields. * * @since 1.0.0 * @package GeoDirectory * @global object $post The current post object. * @param array $tabs_arr Tabs array {@see geodir_detail_page_tab_headings_change()}. * @return array Modified tabs array. */ function geodir_detail_page_custom_field_tab($tabs_arr) { global $post; $post_type = geodir_get_current_posttype(); $all_postypes = geodir_get_posttypes(); if (!empty($tabs_arr) && $post_type != '' && in_array($post_type, $all_postypes) && (geodir_is_page('detail') || geodir_is_page('preview'))) { $package_info = array(); $package_info = geodir_post_package_info($package_info, $post); $post_package_id = $package_info->pid; $fields_location = 'detail'; $custom_fields = geodir_post_custom_fields($post_package_id, 'default', $post_type, $fields_location); if (!empty($custom_fields)) { $parse_custom_fields = array(); foreach ($custom_fields as $field) { $field = stripslashes_deep($field); // strip slashes $type = $field; $field_name = $field['htmlvar_name']; if (empty($geodir_post_info) && geodir_is_page('preview') && $field_name != '' && !isset($post->{$field_name}) && isset($_REQUEST[$field_name])) { $post->{$field_name} = $_REQUEST[$field_name]; } if (isset($field['show_as_tab']) && $field['show_as_tab'] == 1 && (isset($post->{$field_name}) && $post->{$field_name} != '' || $field['type'] == 'fieldset') && in_array($field['type'], array('text', 'datepicker', 'textarea', 'time', 'phone', 'email', 'select', 'multiselect', 'url', 'html', 'fieldset', 'radio', 'checkbox', 'file'))) { if ($type['type'] == 'datepicker' && ($post->{$type}['htmlvar_name'] == '' || $post->{$type}['htmlvar_name'] == '0000-00-00')) { continue; } $parse_custom_fields[] = $field; } } $custom_fields = $parse_custom_fields; } if (!empty($custom_fields)) { $field_set_start = 0; $fieldset_count = 0; $fieldset = ''; $total_fields = count($custom_fields); $count_field = 0; $fieldset_arr = array(); $i = 0; $geodir_post_info = isset($post->ID) && !empty($post->ID) ? geodir_get_post_info($post->ID) : NULL; foreach ($custom_fields as $field) { $count_field++; $field_name = $field['htmlvar_name']; if (empty($geodir_post_info) && geodir_is_page('preview') && $field_name != '' && !isset($post->{$field_name}) && isset($_REQUEST[$field_name])) { $post->{$field_name} = $_REQUEST[$field_name]; } if (isset($field['show_as_tab']) && $field['show_as_tab'] == 1 && (isset($post->{$field_name}) && $post->{$field_name} != '' || $field['type'] == 'fieldset') && in_array($field['type'], array('text', 'datepicker', 'textarea', 'time', 'phone', 'email', 'select', 'multiselect', 'url', 'html', 'fieldset', 'radio', 'checkbox', 'file'))) { $label = $field['site_title'] != '' ? $field['site_title'] : $field['admin_title']; $site_title = trim($field['site_title']); $type = $field; $html = ''; $html_var = $field_name; $field_icon = ''; $variables_array = array(); if ($type['type'] == 'datepicker' && ($post->{$type}['htmlvar_name'] == '' || $post->{$type}['htmlvar_name'] == '0000-00-00')) { continue; } if ($type['type'] != 'fieldset') { $i++; $variables_array['post_id'] = $post->ID; $variables_array['label'] = __($type['site_title'], 'geodirectory'); $variables_array['value'] = ''; $variables_array['value'] = $post->{$type}['htmlvar_name']; } if (strpos($type['field_icon'], 'http') !== false) { $field_icon = ' background: url(' . $type['field_icon'] . ') no-repeat left center;background-size:18px 18px;padding-left: 21px;'; } elseif (strpos($type['field_icon'], 'fa fa-') !== false) { $field_icon = '<i class="' . $type['field_icon'] . '"></i>'; } switch ($type['type']) { case 'fieldset': $i = 0; $fieldset_count++; $field_set_start = 1; $fieldset_arr[$fieldset_count]['htmlvar_name'] = 'gd_tab_' . $fieldset_count; $fieldset_arr[$fieldset_count]['label'] = $label; break; case 'url': if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { if ($type['name'] == 'geodir_facebook') { $field_icon_af = '<i class="fa fa-facebook-square"></i>'; } elseif ($type['name'] == 'geodir_twitter') { $field_icon_af = '<i class="fa fa-twitter-square"></i>'; } else { $field_icon_af = '<i class="fa fa-link"></i>'; } } else { $field_icon_af = $field_icon; $field_icon = ''; } if (!strstr($post->{$type}['htmlvar_name'], 'http')) { $website = 'http://' . $post->{$type}['htmlvar_name']; } else { $website = $post->{$type}['htmlvar_name']; } $geodir_odd_even = $field_set_start == 1 && $i % 2 == 0 ? 'geodir_more_info_even' : 'geodir_more_info_odd'; // all search engines that use the nofollow value exclude links that use it from their ranking calculation $rel = strpos($website, get_site_url()) !== false ? '' : 'rel="nofollow"'; $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '"><span class="geodir-i-website" style="' . $field_icon . '">' . $field_icon_af . ' <a href="' . $website . '" target="_blank" ' . $rel . ' ><strong>' . apply_filters('geodir_custom_field_website_name', stripslashes(__($type['site_title'], 'geodirectory')), $website, $post->ID) . '</strong></a></span></div>'; break; case 'phone': if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = '<i class="fa fa-phone"></i>'; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = $field_set_start == 1 && $i % 2 == 0 ? 'geodir_more_info_even' : 'geodir_more_info_odd'; $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-contact" style="' . $field_icon . '">' . $field_icon_af; if ($field_set_start == 1 && $site_title != '') { $html .= ' ' . __($site_title, 'geodirectory') . ': '; } $html .= ' </span>' . stripslashes($post->{$type}['htmlvar_name']) . '</div>'; break; case 'time': $value = ''; if ($post->{$type}['htmlvar_name'] != '') { //$value = date('h:i',strtotime($post->$type['htmlvar_name'])); $value = date(get_option('time_format'), strtotime($post->{$type}['htmlvar_name'])); } if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = '<i class="fa fa-clock-o"></i>'; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = $field_set_start == 1 && $i % 2 == 0 ? 'geodir_more_info_even' : 'geodir_more_info_odd'; $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-time" style="' . $field_icon . '">' . $field_icon_af; if ($field_set_start == 1 && $site_title != '') { $html .= ' ' . __($site_title, 'geodirectory') . ': '; } $html .= ' </span>' . stripslashes($value) . '</div>'; break; case 'datepicker': $date_format = geodir_default_date_format(); if ($type['extra_fields'] != '') { $date_format = unserialize($type['extra_fields']); $date_format = $date_format['date_format']; } $search = array('dd', 'd', 'DD', 'mm', 'm', 'MM', 'yy'); //jQuery UI datepicker format $replace = array('d', 'j', 'l', 'm', 'n', 'F', 'Y'); //PHP date format $date_format = str_replace($search, $replace, $date_format); $post_htmlvar_value = $date_format == 'd/m/Y' ? str_replace('/', '-', $post->{$type}['htmlvar_name']) : $post->{$type}['htmlvar_name']; // PHP doesn't work well with dd/mm/yyyy format $value = ''; if ($post->{$type}['htmlvar_name'] != '') { $value = date($date_format, strtotime($post_htmlvar_value)); } if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = '<i class="fa fa-calendar"></i>'; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = $field_set_start == 1 && $i % 2 == 0 ? 'geodir_more_info_even' : 'geodir_more_info_odd'; $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-datepicker" style="' . $field_icon . '">' . $field_icon_af; if ($field_set_start == 1 && $site_title != '') { $html .= ' ' . __($site_title, 'geodirectory') . ': '; } $html .= ' </span>' . $value . '</div>'; break; case 'text': if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = ''; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = $field_set_start == 1 && $i % 2 == 0 ? 'geodir_more_info_even' : 'geodir_more_info_odd'; $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-text" style="' . $field_icon . '">' . $field_icon_af; if ($field_set_start == 1 && $site_title != '') { $html .= ' ' . __($site_title, 'geodirectory') . ': '; } $html .= ' </span>' . stripslashes($post->{$type}['htmlvar_name']) . '</div>'; break; case 'radio': if ($post->{$type}['htmlvar_name'] != '') { if ($post->{$type}['htmlvar_name'] == 'f' || $post->{$type}['htmlvar_name'] == '0') { $html_val = __('No', 'geodirectory'); } else { if ($post->{$type}['htmlvar_name'] == 't' || $post->{$type}['htmlvar_name'] == '1') { $html_val = __('Yes', 'geodirectory'); } } if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } else { if ($field_icon == '') { $field_icon_af = ''; } else { $field_icon_af = $field_icon; $field_icon = ''; } } $geodir_odd_even = $field_set_start == 1 && $i % 2 == 0 ? 'geodir_more_info_even' : 'geodir_more_info_odd'; $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-radio" style="' . $field_icon . '">' . $field_icon_af; if ($field_set_start == 1 && $site_title != '') { $html .= ' ' . __($site_title, 'geodirectory') . ': '; } $html .= ' </span>' . $html_val . '</div>'; } break; case 'checkbox': $html_var = $type['htmlvar_name']; $html_val = $type['htmlvar_name']; if ((int) $post->{$html_var} == 1) { if ($post->{$type}['htmlvar_name'] == '1') { $html_val = __('Yes', 'geodirectory'); } else { $html_val = __('No', 'geodirectory'); } if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } else { if ($field_icon == '') { $field_icon_af = ''; } else { $field_icon_af = $field_icon; $field_icon = ''; } } $geodir_odd_even = $field_set_start == 1 && $i % 2 == 0 ? 'geodir_more_info_even' : 'geodir_more_info_odd'; $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-checkbox" style="' . $field_icon . '">' . $field_icon_af; if ($field_set_start == 1 && $site_title != '') { $html .= ' ' . __($site_title, 'geodirectory') . ': '; } $html .= ' </span>' . $html_val . '</div>'; } break; case 'select': if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = ''; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = $field_set_start == 1 && $i % 2 == 0 ? 'geodir_more_info_even' : 'geodir_more_info_odd'; $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-select" style="' . $field_icon . '">' . $field_icon_af; if ($field_set_start == 1 && $site_title != '') { $html .= ' ' . __($site_title, 'geodirectory') . ': '; } $html .= ' </span>' . stripslashes($post->{$type}['htmlvar_name']) . '</div>'; break; case 'multiselect': if (is_array($post->{$type}['htmlvar_name'])) { $post->{$type}['htmlvar_name'] = implode(', ', $post->{$type}['htmlvar_name']); } if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = ''; } else { $field_icon_af = $field_icon; $field_icon = ''; } $option_values = explode(',', $post->{$type}['htmlvar_name']); if ($type['option_values']) { if (strstr($type['option_values'], "/")) { $option_values = array(); $field_values = explode(',', $type['option_values']); foreach ($field_values as $data) { $val = explode('/', $data); if (isset($val[1]) && in_array($val[1], explode(',', $post->{$type}['htmlvar_name']))) { $option_values[] = $val[0]; } } } } $geodir_odd_even = $field_set_start == 1 && $i % 2 == 0 ? 'geodir_more_info_even' : 'geodir_more_info_odd'; $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-select" style="' . $field_icon . '">' . $field_icon_af; if ($field_set_start == 1 && $site_title != '') { $html .= ' ' . __($site_title, 'geodirectory') . ': '; } $html .= ' </span>'; if (count($option_values) > 1) { $html .= '<ul>'; foreach ($option_values as $val) { $html .= '<li>' . stripslashes($val) . '</li>'; } $html .= '</ul>'; } else { $html .= stripslashes(trim($post->{$type}['htmlvar_name'], ',')); } $html .= '</div>'; break; case 'email': if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = '<i class="fa fa-envelope"></i>'; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = $field_set_start == 1 && $i % 2 == 0 ? 'geodir_more_info_even' : 'geodir_more_info_odd'; $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-email" style="' . $field_icon . '">' . $field_icon_af; if ($field_set_start == 1 && $site_title != '') { $html .= ' ' . __($site_title, 'geodirectory') . ': '; } $html .= ' </span>' . stripslashes($post->{$type}['htmlvar_name']) . '</div>'; break; case 'textarea': if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = ''; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = $field_set_start == 1 && $i % 2 == 0 ? 'geodir_more_info_even' : 'geodir_more_info_odd'; $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-text" style="' . $field_icon . '">' . $field_icon_af; if ($field_set_start == 1 && $site_title != '') { $html .= ' ' . __($site_title, 'geodirectory') . ': '; } $html .= '</span>' . wpautop(stripslashes($post->{$type}['htmlvar_name'])) . '</div>'; break; case 'html': if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = ''; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = $field_set_start == 1 && $i % 2 == 0 ? 'geodir_more_info_even' : 'geodir_more_info_odd'; $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-text" style="' . $field_icon . '">' . $field_icon_af; if ($field_set_start == 1 && $site_title != '') { $html .= ' ' . __($site_title, 'geodirectory') . ': '; } $html .= ' </span>' . wpautop(stripslashes($post->{$type}['htmlvar_name'])) . '</div>'; break; case 'file': $html_var = $type['htmlvar_name']; if (!empty($post->{$type}['htmlvar_name'])) { $files = explode(",", $post->{$type}['htmlvar_name']); if (!empty($files)) { $extra_fields = !empty($type['extra_fields']) ? maybe_unserialize($type['extra_fields']) : NULL; $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'] : ''; $file_paths = ''; foreach ($files as $file) { if (!empty($file)) { $filetype = wp_check_filetype($file); $image_name_arr = explode('/', $file); $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. } //$allowed_file_types = array('application/pdf', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'text/csv', 'text/plain'); $image_file_types = array('image/jpg', 'image/jpeg', 'image/gif', 'image/png', 'image/bmp', 'image/x-icon'); // If the uploaded file is image if (in_array($uploaded_file_type, $image_file_types)) { $file_paths .= '<div class="geodir-custom-post-gallery" class="clearfix">'; $file_paths .= '<a href="' . $file . '">'; $file_paths .= geodir_show_image(array('src' => $file), 'thumbnail', false, false); $file_paths .= '</a>'; $file_paths .= '</div>'; } else { $ext_path = '_' . $html_var . '_'; $filename = explode($ext_path, $filename); $file_paths .= '<a href="' . $file . '" target="_blank">' . $filename[count($filename) - 1] . '</a>'; } } } if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } else { if ($field_icon == '') { $field_icon_af = ''; } else { $field_icon_af = $field_icon; $field_icon = ''; } } $geodir_odd_even = $field_set_start == 1 && $i % 2 == 0 ? 'geodir_more_info_even' : 'geodir_more_info_odd'; $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . ' geodir-custom-file-box" style="clear:both;"><span class="geodir-i-file" style="display:inline-block;vertical-align:top;padding-right:14px;' . $field_icon . '">' . $field_icon_af; if ($field_set_start == 1 && $site_title != '') { $html .= ' ' . __($site_title, 'geodirectory') . ': '; } $html .= ' </span>' . $file_paths . '</div>'; } } break; } if ($field_set_start == 1) { $add_html = false; if ($type['type'] == 'fieldset' && $fieldset_count > 1) { if ($fieldset != '') { $add_html = true; $label = $fieldset_arr[$fieldset_count - 1]['label']; $htmlvar_name = $fieldset_arr[$fieldset_count - 1]['htmlvar_name']; } $fieldset_html = $fieldset; $fieldset = ''; } else { $fieldset .= $html; if ($total_fields == $count_field && $fieldset != '') { $add_html = true; $label = $fieldset_arr[$fieldset_count]['label']; $htmlvar_name = $fieldset_arr[$fieldset_count]['htmlvar_name']; $fieldset_html = $fieldset; } } if ($add_html) { $tabs_arr[$htmlvar_name] = array('heading_text' => __($label, 'geodirectory'), 'is_active_tab' => false, 'is_display' => apply_filters('geodir_detail_page_tab_is_display', true, $htmlvar_name), 'tab_content' => '<div class="geodir-company_info field-group">' . $fieldset_html . '</html>'); } } else { if ($html != '') { $tabs_arr[$field['htmlvar_name']] = array('heading_text' => __($label, 'geodirectory'), 'is_active_tab' => false, 'is_display' => apply_filters('geodir_detail_page_tab_is_display', true, $field['htmlvar_name']), 'tab_content' => $html); } } } } } } return $tabs_arr; }
/** * Outputs the add listing form HTML content. * * Other things are needed to output a working add listing form, you should use the add listing shortcode if needed. * * @since 1.0.0 * @package GeoDirectory * @global object $current_user Current user object. * @global object $post The current post object. * @global object $post_images Image objects of current post if available. */ function geodir_action_add_listing_form() { global $cat_display, $post_cat, $current_user; $page_id = get_the_ID(); $post = ''; $title = ''; $desc = ''; $kw_tags = ''; $required_msg = ''; $submit_button = ''; if (isset($_REQUEST['ajax_action'])) { $ajax_action = $_REQUEST['ajax_action']; } else { $ajax_action = 'add'; } $thumb_img_arr = array(); $curImages = ''; if (isset($_REQUEST['backandedit'])) { global $post; $post = (object) unserialize($_SESSION['listing']); $listing_type = $post->listing_type; $title = $post->post_title; $desc = $post->post_desc; /*if(is_array($post->post_category) && !empty($post->post_category)) $post_cat = $post->post_category; else*/ $post_cat = $post->post_category; $kw_tags = $post->post_tags; $curImages = isset($post->post_images) ? $post->post_images : ''; } elseif (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') { global $post, $post_images; /*query_posts(array('p'=>$_REQUEST['pid'])); if ( have_posts() ) while ( have_posts() ) the_post(); global $post,$post_images;*/ $post = geodir_get_post_info($_REQUEST['pid']); $thumb_img_arr = geodir_get_images($post->ID); if ($thumb_img_arr) { foreach ($thumb_img_arr as $post_img) { $curImages .= $post_img->src . ','; } } $listing_type = $post->post_type; $title = $post->post_title; $desc = $post->post_content; //$post_cat = $post->categories; $kw_tags = $post->post_tags; $kw_tags = implode(",", wp_get_object_terms($post->ID, $listing_type . '_tags', array('fields' => 'names'))); } else { $listing_type = $_REQUEST['listing_type']; } if ($current_user->ID != '0') { $user_login = true; } ?> <form name="propertyform" id="propertyform" action="<?php echo get_page_link(geodir_preview_page_id()); ?> " method="post" enctype="multipart/form-data"> <input type="hidden" name="preview" value="<?php echo $listing_type; ?> "/> <input type="hidden" name="listing_type" value="<?php echo $listing_type; ?> "/> <?php if ($page_id) { ?> <input type="hidden" name="add_listing_page_id" value="<?php echo $page_id; ?> " /><?php } ?> <?php if (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') { ?> <input type="hidden" name="pid" value="<?php echo $_REQUEST['pid']; ?> "/> <?php } ?> <?php if (isset($_REQUEST['backandedit'])) { ?> <input type="hidden" name="backandedit" value="<?php echo $_REQUEST['backandedit']; ?> "/> <?php } ?> <?php /** * Called at the very top of the add listing page form for frontend. * * This is called just before the "Enter Listing Details" text. * * @since 1.0.0 */ do_action('geodir_before_detail_fields'); ?> <h5><?php echo LISTING_DETAILS_TEXT; ?> </h5> <?php /** * Called at the top of the add listing page form for frontend. * * This is called after the "Enter Listing Details" text. * * @since 1.0.0 */ do_action('geodir_before_main_form_fields'); ?> <div id="geodir_post_title_row" class="required_field geodir_form_row clearfix"> <label><?php echo PLACE_TITLE_TEXT; ?> <span>*</span> </label> <input type="text" field_type="text" name="post_title" id="post_title" class="geodir_textfield" value="<?php echo esc_attr(stripslashes($title)); ?> "/> <span class="geodir_message_error"><?php _e($required_msg, GEODIRECTORY_TEXTDOMAIN); ?> </span> </div> <?php $show_editor = get_option('geodir_tiny_editor_on_add_listing'); $desc = $show_editor ? stripslashes($desc) : esc_attr(stripslashes($desc)); $desc_limit = ''; /** * Filter the add listing description field character limit number. * * @since 1.0.0 * @param int $desc_limit The amount of characters to limit the description to. */ $desc_limit = apply_filters('geodir_description_field_desc_limit', $desc_limit); /** * Filter the add listing description field text. * * @since 1.0.0 * @param string $desc The text for the description field. * @param int $desc_limit The character limit numer if any. */ $desc = apply_filters('geodir_description_field_desc', $desc, $desc_limit); $desc_limit_msg = ''; /** * Filter the add listing description limit message. * * This is the message shown if there is a limit applied to the amount of characters the description can use. * * @since 1.0.0 * @param string $desc_limit_msg The limit message string if any. * @param int $desc_limit The character limit numer if any. */ $desc_limit_msg = apply_filters('geodir_description_field_desc_limit_msg', $desc_limit_msg, $desc_limit); ?> <?php /** * Called on the add listing page form for frontend just before the description field. * * @since 1.0.0 */ do_action('geodir_before_description_field'); ?> <div id="geodir_post_desc_row" class="<?php if ($desc_limit != '0') { echo 'required_field'; } ?> geodir_form_row clearfix"> <label><?php echo PLACE_DESC_TEXT; ?> <span><?php if ($desc_limit != '0') { echo '*'; } ?> </span> </label> <?php if (!empty($show_editor) && in_array($listing_type, $show_editor)) { $editor_settings = array('media_buttons' => false, 'textarea_rows' => 10); ?> <div class="editor" field_id="post_desc" field_type="editor"> <?php wp_editor($desc, "post_desc", $editor_settings); ?> </div> <?php if ($desc_limit != '') { ?> <script type="text/javascript">jQuery('textarea#post_desc').attr('maxlength', "<?php echo $desc_limit; ?> ");</script> <?php } ?> <?php } else { ?> <textarea field_type="textarea" name="post_desc" id="post_desc" class="geodir_textarea" maxlength="<?php echo $desc_limit; ?> "><?php echo $desc; ?> </textarea> <?php } ?> <?php if ($desc_limit_msg != '') { ?> <span class="geodir_message_note"><?php echo $desc_limit_msg; ?> </span> <?php } ?> <span class="geodir_message_error"><?php echo _e($required_msg, GEODIRECTORY_TEXTDOMAIN); ?> </span> </div> <?php /** * Called on the add listing page form for frontend just after the description field. * * @since 1.0.0 */ do_action('geodir_after_description_field'); ?> <?php $kw_tags = esc_attr(stripslashes($kw_tags)); $kw_tags_count = TAGKW_TEXT_COUNT; $kw_tags_msg = TAGKW_MSG; /** * Filter the add listing tags character limit. * * @since 1.0.0 * @param int $kw_tags_count The character count limit if any. */ $kw_tags_count = apply_filters('geodir_listing_tags_field_tags_count', $kw_tags_count); /** * Filter the add listing tags field value. * * You can use the $_REQUEST values to check if this is a go back and edit value etc. * * @since 1.0.0 * @param string $kw_tags The tag field value, usually a comma separated list of tags. * @param int $kw_tags_count The character count limit if any. */ $kw_tags = apply_filters('geodir_listing_tags_field_tags', $kw_tags, $kw_tags_count); /** * Filter the add listing tags field message text. * * @since 1.0.0 * @param string $kw_tags_msg The message shown under the field. * @param int $kw_tags_count The character count limit if any. */ $kw_tags_msg = apply_filters('geodir_listing_tags_field_tags_msg', $kw_tags_msg, $kw_tags_count); ?> <?php /** * Called on the add listing page form for frontend just before the tags field. * * @since 1.0.0 */ do_action('geodir_before_listing_tags_field'); ?> <div id="geodir_post_tags_row" class="geodir_form_row clearfix"> <label><?php echo TAGKW_TEXT; ?> </label> <input name="post_tags" id="post_tags" value="<?php echo $kw_tags; ?> " type="text" class="geodir_textfield" maxlength="<?php echo $kw_tags_count; ?> "/> <span class="geodir_message_note"><?php echo $kw_tags_msg; ?> </span> </div> <?php /** * Called on the add listing page form for frontend just after the tags field. * * @since 1.0.0 */ do_action('geodir_after_listing_tags_field'); ?> <?php $package_info = array(); $package_info = geodir_post_package_info($package_info, $post); geodir_get_custom_fields_html($package_info->pid, 'all', $listing_type); ?> <?php // adjust values here $id = "post_images"; // this will be the name of form field. Image url(s) will be submitted in $_POST using this key. So if $id == �img1� then $_POST[�img1�] will have all the image urls $multiple = true; // allow multiple files upload $width = geodir_media_image_large_width(); // If you want to automatically resize all uploaded images then provide width here (in pixels) $height = geodir_media_image_large_height(); // If you want to automatically resize all uploaded images then provide height here (in pixels) $thumb_img_arr = array(); $totImg = 0; if (isset($_REQUEST['backandedit']) && empty($_REQUEST['pid'])) { $post = (object) unserialize($_SESSION['listing']); if (isset($post->post_images)) { $curImages = trim($post->post_images, ","); } if ($curImages != '') { $curImages_array = explode(',', $curImages); $totImg = count($curImages_array); } $listing_type = $post->listing_type; } elseif (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') { $post = geodir_get_post_info($_REQUEST['pid']); $listing_type = $post->post_type; $thumb_img_arr = geodir_get_images($_REQUEST['pid']); } else { $listing_type = $_REQUEST['listing_type']; } if (!empty($thumb_img_arr)) { foreach ($thumb_img_arr as $img) { //$curImages = $img->src.","; } $totImg = count((array) $thumb_img_arr); } if ($curImages != '') { $svalue = $curImages; } else { $svalue = ''; } $image_limit = $package_info->image_limit; $show_image_input_box = $image_limit != '0'; /** * Filter to be able to show/hide the image upload section of the add listing form. * * @since 1.0.0 * @param bool $show_image_input_box Set true to show. Set false to not show. * @param string $listing_type The custom post type slug. */ $show_image_input_box = apply_filters('geodir_image_uploader_on_add_listing', $show_image_input_box, $listing_type); if ($show_image_input_box) { ?> <h5 id="geodir_form_title_row" class="geodir-form_title"> <?php echo PRO_PHOTO_TEXT; ?> <?php if ($image_limit == 1) { echo '<br /><small>(' . __('You can upload', GEODIRECTORY_TEXTDOMAIN) . ' ' . $image_limit . ' ' . __('image with this package', GEODIRECTORY_TEXTDOMAIN) . ')</small>'; } ?> <?php if ($image_limit > 1) { echo '<br /><small>(' . __('You can upload', GEODIRECTORY_TEXTDOMAIN) . ' ' . $image_limit . ' ' . __('images with this package', GEODIRECTORY_TEXTDOMAIN) . ')</small>'; } ?> <?php if ($image_limit == '') { echo '<br /><small>(' . __('You can upload unlimited images with this package', GEODIRECTORY_TEXTDOMAIN) . ')</small>'; } ?> </h5> <div class="geodir_form_row clearfix" id="<?php echo $id; ?> dropbox" align="center" style="border:1px solid #ccc; min-height:100px; height:auto; padding:10px;"> <input type="hidden" name="<?php echo $id; ?> " id="<?php echo $id; ?> " value="<?php echo $svalue; ?> "/> <input type="hidden" name="<?php echo $id; ?> image_limit" id="<?php echo $id; ?> image_limit" value="<?php echo $image_limit; ?> "/> <input type="hidden" name="<?php echo $id; ?> totImg" id="<?php echo $id; ?> totImg" value="<?php echo $totImg; ?> "/> <div class="plupload-upload-uic hide-if-no-js <?php if ($multiple) { ?> plupload-upload-uic-multiple<?php } ?> " id="<?php echo $id; ?> plupload-upload-ui"> <h4><?php _e('Drop files to upload', GEODIRECTORY_TEXTDOMAIN); ?> </h4><br/> <input id="<?php echo $id; ?> plupload-browse-button" type="button" value="<?php esc_attr_e('Select Files', GEODIRECTORY_TEXTDOMAIN); ?> " class="geodir_button"/> <span class="ajaxnonceplu" id="ajaxnonceplu<?php echo wp_create_nonce($id . 'pluploadan'); ?> "></span> <?php if ($width && $height) { ?> <span class="plupload-resize"></span> <span class="plupload-width" id="plupload-width<?php echo $width; ?> "></span> <span class="plupload-height" id="plupload-height<?php echo $height; ?> "></span> <?php } ?> <div class="filelist"></div> </div> <div class="plupload-thumbs <?php if ($multiple) { ?> plupload-thumbs-multiple<?php } ?> clearfix" id="<?php echo $id; ?> plupload-thumbs" style="border-top:1px solid #ccc; padding-top:10px;"> </div> <span id="upload-msg"><?php _e('Please drag & drop the images to rearrange the order', GEODIRECTORY_TEXTDOMAIN); ?> </span> <span id="<?php echo $id; ?> upload-error" style="display:none"></span> </div> <?php } ?> <?php /** * Called on the add listing page form for frontend just after the image upload field. * * @since 1.0.0 */ do_action('geodir_after_main_form_fields'); ?> <!-- add captcha code --> <script> <!--<script>--> document.write('<inp' + 'ut type="hidden" id="geodir_sp' + 'amblocker_top_form" name="geodir_sp' + 'amblocker" value="64"/>') </script> <noscript> <div> <label><?php _e('Type 64 into this box', GEODIRECTORY_TEXTDOMAIN); ?> </label> <input type="text" id="geodir_spamblocker_top_form" name="geodir_spamblocker" value="" maxlength="10"/> </div> </noscript> <input type="text" id="geodir_filled_by_spam_bot_top_form" name="geodir_filled_by_spam_bot" value=""/> <!-- end captcha code --> <div id="geodir-add-listing-submit" class="geodir_form_row clear_both" align="center" style="padding:2px;"> <input type="submit" value="<?php echo PRO_PREVIEW_BUTTON; ?> " class="geodir_button" <?php echo $submit_button; ?> /> <span class="geodir_message_note" style="padding-left:0px;"> <?php _e('Note: You will be able to see a preview in the next page', GEODIRECTORY_TEXTDOMAIN); ?> </span> </div> </form> <?php wp_reset_query(); }
/** * Imports data from CSV file using ajax. * * @since 1.0.0 * @package GeoDirectory * @global object $wpdb WordPress Database object. * @global string $plugin_prefix Geodirectory plugin table prefix. * @global object $current_user Current user object. */ function geodir_ajax_import_csv() { error_reporting(0); // hide error to get clean json response global $wpdb, $plugin_prefix, $current_user; $uploads = wp_upload_dir(); ini_set('auto_detect_line_endings', true); $wp_post_statuses = get_post_statuses(); // All of the WordPress supported post statuses. $task = isset($_POST['task']) ? $_POST['task'] : ''; $uploadedFile = isset($_POST['gddata']['uploadedFile']) ? $_POST['gddata']['uploadedFile'] : NULL; $filename = $uploadedFile; $uploads = wp_upload_dir(); $uploads_dir = $uploads['path']; $image_name_arr = explode('/', $filename); $filename = end($image_name_arr); $target_path = $uploads_dir . '/temp_' . $current_user->data->ID . '/' . $filename; $return = array(); $return['file'] = $uploadedFile; $return['error'] = __('The uploaded file is not a valid csv file. Please try again.', 'geodirectory'); if (is_file($target_path) && file_exists($target_path) && $uploadedFile) { $wp_filetype = wp_check_filetype_and_ext($target_path, $filename); if (!empty($wp_filetype) && isset($wp_filetype['ext']) && geodir_strtolower($wp_filetype['ext']) == 'csv') { $return['error'] = NULL; $return['rows'] = 0; if (($handle = fopen($target_path, "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { if (is_array($data) && !empty($data)) { $file[] = '"' . implode('","', $data) . '"'; } } fclose($handle); $file = $file; } $return['rows'] = !empty($file) && count($file) > 1 ? count($file) - 1 : 0; if (!$return['rows'] > 0) { $return['error'] = __('No data found in csv file.', 'geodirectory'); } } } if ($task == 'prepare' || !empty($return['error'])) { echo json_encode($return); exit; } $totRecords = isset($_POST['gddata']['totRecords']) ? $_POST['gddata']['totRecords'] : NULL; $importlimit = isset($_POST['gddata']['importlimit']) ? $_POST['gddata']['importlimit'] : 1; $count = $importlimit; $requested_limit = $importlimit; $tmpCnt = isset($_POST['gddata']['tmpcount']) ? $_POST['gddata']['tmpcount'] : 0; if ($count < $totRecords) { $count = $tmpCnt + $count; if ($count > $totRecords) { $count = $totRecords; } } else { $count = $totRecords; } $total_records = 0; $rowcount = 0; $address_invalid = 0; $blank_address = 0; $upload_files = 0; $invalid_post_type = 0; $invalid_title = 0; $customKeyarray = array(); $gd_post_info = array(); $post_location = array(); $countpost = 0; if (!empty($file)) { $columns = isset($file[0]) ? geodir_str_getcsv($file[0]) : NULL; $customKeyarray = $columns; if (empty($columns) || !empty($columns) && $columns[0] == '') { $return['error'] = CSV_INVAILD_FILE; echo json_encode($return); exit; } for ($i = 1; $i <= $importlimit; $i++) { $current_index = $tmpCnt + $i; if (isset($file[$current_index])) { $total_records++; $buffer = geodir_str_getcsv($file[$current_index]); $post_title = addslashes($buffer[0]); $current_post_author = $buffer[1]; $post_desc = addslashes($buffer[2]); $post_cat = array(); $catids_arr = array(); $post_cat = trim($buffer[3]); // comma seperated category name if ($post_cat) { $post_cat_arr = explode(',', $post_cat); for ($c = 0; $c < count($post_cat_arr); $c++) { $catid = wp_kses_normalize_entities(trim($post_cat_arr[$c])); if (!empty($buffer[5])) { if (in_array($buffer[5], geodir_get_posttypes())) { $p_taxonomy = geodir_get_taxonomies(addslashes($buffer[5])); if (get_term_by('name', $catid, $p_taxonomy[0])) { $cat = get_term_by('name', $catid, $p_taxonomy[0]); $catids_arr[] = $cat->slug; } else { if (get_term_by('slug', $catid, $p_taxonomy[0])) { $cat = get_term_by('slug', $catid, $p_taxonomy[0]); $catids_arr[] = $cat->slug; } else { $ret = wp_insert_term($catid, $p_taxonomy[0]); if ($ret && !is_wp_error($ret)) { if (get_term_by('name', $catid, $p_taxonomy[0])) { $cat = get_term_by('name', $catid, $p_taxonomy[0]); $catids_arr[] = $cat->slug; } elseif (get_term_by('slug', $catid, $p_taxonomy[0])) { $cat = get_term_by('slug', $catid, $p_taxonomy[0]); $catids_arr[] = $cat->slug; } } } } } } } } if (!$catids_arr) { $catids_arr[] = 1; } $post_tags = trim($buffer[4]); // comma seperated tags $tag_arr = ''; if ($post_tags) { $tag_arr = explode(',', $post_tags); } $table = $plugin_prefix . $buffer[5] . '_detail'; // check table in database $error = ''; if ($wpdb->get_var("SHOW TABLES LIKE '" . $table . "'") != $table) { $invalid_post_type++; continue; } if ($post_title != '') { $menu_order = 0; $image_folder_name = 'uplaod/'; $image_names = array(); for ($c = 5; $c < count($customKeyarray); $c++) { $gd_post_info[$customKeyarray[$c]] = addslashes($buffer[$c]); if ($customKeyarray[$c] == 'IMAGE') { $buffer[$c] = trim($buffer[$c]); if (!empty($buffer[$c])) { $image_names[] = $buffer[$c]; } } if ($customKeyarray[$c] == 'alive_days') { if ($buffer[$c] != '0' && $buffer[$c] != '') { $submitdata = date('Y-m-d'); $gd_post_info['expire_date'] = date('Y-m-d', strtotime($submitdata . "+" . addslashes($buffer[$c]) . " days")); } else { $gd_post_info['expire_date'] = 'Never'; } } if ($customKeyarray[$c] == 'post_city') { $post_city = addslashes($buffer[$c]); } if ($customKeyarray[$c] == 'post_region') { $post_region = addslashes($buffer[$c]); } if ($customKeyarray[$c] == 'post_country') { $post_country = addslashes($buffer[$c]); } if ($customKeyarray[$c] == 'post_latitude') { $post_latitude = addslashes($buffer[$c]); } if ($customKeyarray[$c] == 'post_longitude') { $post_longitude = addslashes($buffer[$c]); } // Post status if ($customKeyarray[$c] == 'post_status') { $post_status = sanitize_key($buffer[$c]); } } /* ================ before array create ============== */ $location_result = geodir_get_default_location(); if (!isset($gd_post_info['post_city']) || $gd_post_info['post_city'] == '' || (!isset($gd_post_info['post_region']) || $gd_post_info['post_region'] == '') || (!isset($gd_post_info['post_country']) || $gd_post_info['post_country'] == '') || (!isset($gd_post_info['post_address']) || $gd_post_info['post_address'] == '') || (!isset($gd_post_info['post_latitude']) || $gd_post_info['post_latitude'] == '') || (!isset($gd_post_info['post_longitude']) || $gd_post_info['post_longitude'] == '')) { $blank_address++; continue; } else { if ($location_result->location_id == 0) { if (geodir_strtolower($gd_post_info['post_city']) != geodir_strtolower($location_result->city) || geodir_strtolower($gd_post_info['post_region']) != geodir_strtolower($location_result->region) || geodir_strtolower($gd_post_info['post_country']) != geodir_strtolower($location_result->country)) { $address_invalid++; continue; } } } // Default post status $default_status = 'publish'; $post_status = !empty($post_status) ? sanitize_key($post_status) : $default_status; $post_status = !empty($wp_post_statuses) && !isset($wp_post_statuses[$post_status]) ? $default_status : $post_status; $my_post['post_title'] = $post_title; $my_post['post_content'] = $post_desc; $my_post['post_type'] = addslashes($buffer[5]); $my_post['post_author'] = $current_post_author; $my_post['post_status'] = $post_status; $my_post['post_category'] = $catids_arr; $my_post['post_tags'] = $tag_arr; $gd_post_info['post_tags'] = $tag_arr; $gd_post_info['post_title'] = $post_title; $gd_post_info['post_status'] = $post_status; $gd_post_info['submit_time'] = time(); $gd_post_info['submit_ip'] = $_SERVER['REMOTE_ADDR']; $last_postid = wp_insert_post($my_post); $countpost++; // Check if we need to save post location as new location if ($location_result->location_id > 0) { if (isset($post_city) && isset($post_region)) { $request_info['post_location'] = array('city' => $post_city, 'region' => $post_region, 'country' => $post_country, 'geo_lat' => $post_latitude, 'geo_lng' => $post_longitude); $post_location_info = $request_info['post_location']; if ($location_id = geodir_add_new_location($post_location_info)) { $post_location_id = $location_id; } } else { $post_location_id = 0; } } else { $post_location_id = 0; } /* ------- get default package info ----- */ $payment_info = array(); $package_info = array(); $package_info = (array) geodir_post_package_info($package_info, '', $buffer[5]); $package_id = ''; if (isset($gd_post_info['package_id']) && $gd_post_info['package_id'] != '') { $package_id = $gd_post_info['package_id']; } if (!empty($package_info)) { $payment_info['package_id'] = $package_info['pid']; if (isset($package_info['alive_days']) && $package_info['alive_days'] != 0) { $payment_info['expire_date'] = date('Y-m-d', strtotime("+" . $package_info['alive_days'] . " days")); } else { $payment_info['expire_date'] = 'Never'; } $gd_post_info = array_merge($gd_post_info, $payment_info); } $gd_post_info['post_location_id'] = $post_location_id; $post_type = get_post_type($last_postid); $table = $plugin_prefix . $post_type . '_detail'; geodir_save_post_info($last_postid, $gd_post_info); if (!empty($image_names)) { $upload_files++; $menu_order = 1; foreach ($image_names as $image_name) { $img_name_arr = explode('.', $image_name); $uploads = wp_upload_dir(); $sub_dir = $uploads['subdir']; $arr_file_type = wp_check_filetype($image_name); $uploaded_file_type = $arr_file_type['type']; $attachment = array(); $attachment['post_id'] = $last_postid; $attachment['title'] = $img_name_arr[0]; $attachment['content'] = ''; $attachment['file'] = $sub_dir . '/' . $image_name; $attachment['mime_type'] = $uploaded_file_type; $attachment['menu_order'] = $menu_order; $attachment['is_featured'] = 0; $attachment_set = ''; foreach ($attachment as $key => $val) { if ($val != '') { $attachment_set .= $key . " = '" . $val . "', "; } } $attachment_set = trim($attachment_set, ", "); $wpdb->query("INSERT INTO " . GEODIR_ATTACHMENT_TABLE . " SET " . $attachment_set); if ($menu_order == 1) { $post_type = get_post_type($last_postid); $wpdb->query($wpdb->prepare("UPDATE " . $table . " SET featured_image = %s where post_id =%d", array($sub_dir . '/' . $image_name, $last_postid))); } $menu_order++; } } $gd_post_info['package_id'] = $package_id; /** This action is documented in geodirectory-functions/post-functions.php */ do_action('geodir_after_save_listing', $last_postid, $gd_post_info); if (!empty($buffer[5])) { if (in_array($buffer[5], geodir_get_posttypes())) { $taxonomies = geodir_get_posttype_info(addslashes($buffer[5])); wp_set_object_terms($last_postid, $my_post['post_tags'], $taxonomy = $taxonomies['taxonomies'][1]); wp_set_object_terms($last_postid, $my_post['post_category'], $taxonomy = $taxonomies['taxonomies'][0]); $post_default_category = isset($my_post['post_default_category']) ? $my_post['post_default_category'] : ''; $post_category_str = isset($my_post['post_category_str']) ? $my_post['post_category_str'] : ''; geodir_set_postcat_structure($last_postid, $taxonomy, $post_default_category, $post_category_str); } } } else { $invalid_title++; } } } } $return['rowcount'] = $countpost; $return['invalidcount'] = $address_invalid; $return['blank_address'] = $blank_address; $return['upload_files'] = $upload_files; $return['invalid_post_type'] = $invalid_post_type; $return['invalid_title'] = $invalid_title; $return['total_records'] = $total_records; echo json_encode($return); exit; }
/** * Checks to show/hide related listing tab on detail page. * * @since 1.2.3 * * @param array|object $package_info Price package info. * @return bool Returns true on success & false on fail. */ function geodir_payments_hide_related_tab($post) { if (empty($post)) { return false; } $package_info = geodir_post_package_info(array(), $post); if (!empty($package_info) && is_object($package_info) && isset($package_info->hide_related_tab) && (int) $package_info->hide_related_tab == 1) { return true; } else { if (!empty($package_info) && is_array($package_info) && isset($package_info['hide_related_tab']) && (int) $package_info['hide_related_tab'] == 1) { return true; } } return false; }
/** * Saves listing in the database using given information. * * @since 1.0.0 * @package GeoDirectory * @global object $wpdb WordPress Database object. * @global object $post The current post object. * @global object $current_user Current user object. * @param array $request_info { * Array of request info arguments. * * @type string $action Ajax action name. * @type string $geodir_ajax Ajax type. * @type string $ajax_action Ajax action. * @type string $listing_type Listing type. * @type string $pid Default Post ID. * @type string $preview Todo Desc needed. * @type string $add_listing_page_id Add listing page ID. * @type string $post_title Listing title. * @type string $post_desc Listing Description. * @type string $post_tags Listing tags. * @type array $cat_limit Category limit. * @type array $post_category Category IDs. * @type array $post_category_str Category string. * @type string $post_default_category Default category ID. * @type string $post_address Listing address. * @type string $geodir_location_add_listing_country_val Add listing country value. * @type string $post_country Listing country. * @type string $geodir_location_add_listing_region_val Add listing region value. * @type string $post_region Listing region. * @type string $geodir_location_add_listing_city_val Add listing city value. * @type string $post_city Listing city. * @type string $post_zip Listing zip. * @type string $post_latitude Listing latitude. * @type string $post_longitude Listing longitude. * @type string $post_mapview Listing mapview. Default "ROADMAP". * @type string $post_mapzoom Listing mapzoom Default "9". * @type string $geodir_timing Business timing info. * @type string $geodir_contact Contact number. * @type string $geodir_email Business contact email. * @type string $geodir_website Business website. * @type string $geodir_twitter Twitter link. * @type string $geodir_facebook Facebook link. * @type string $geodir_video Video link. * @type string $geodir_special_offers Speacial offers. * @type string $post_images Post image urls. * @type string $post_imagesimage_limit Post images limit. * @type string $post_imagestotImg Todo Desc needed. * @type string $geodir_accept_term_condition Has accepted terms and conditions?. * @type string $geodir_spamblocker Todo Desc needed. * @type string $geodir_filled_by_spam_bot Todo Desc needed. * * } * @param bool $dummy Optional. Is this a dummy listing? Default false. * @return int|string|WP_Error Created post id. */ function geodir_save_listing($request_info = array(), $dummy = false) { global $wpdb, $current_user; $last_post_id = ''; if (isset($_SESSION['listing']) && !$dummy) { $request_info = array(); $request_session = unserialize($_SESSION['listing']); $request_info = array_merge($_REQUEST, $request_session); } else { if (!isset($_SESSION['listing']) && !$dummy) { global $post; $request_info['pid'] = $post->ID; $request_info['post_title'] = $request_info['post_title']; $request_info['listing_type'] = $post->post_type; $request_info['post_desc'] = $request_info['content']; } else { if (!$dummy) { return false; } } } /** * Filter the request_info array. * * You can use this filter to modify request_info array. * * @since 1.0.0 * @package GeoDirectory * @param array $request_info See {@see geodir_save_listing()} for accepted args. */ $request_info = apply_filters('geodir_action_get_request_info', $request_info); // Check if we need to save post location as new location $location_result = geodir_get_default_location(); if ($location_result->location_id > 0) { if (isset($request_info['post_city']) && isset($request_info['post_region'])) { $request_info['post_location'] = array('city' => $request_info['post_city'], 'region' => isset($request_info['post_region']) ? $request_info['post_region'] : '', 'country' => isset($request_info['post_country']) ? $request_info['post_country'] : '', 'geo_lat' => isset($request_info['post_latitude']) ? $request_info['post_latitude'] : '', 'geo_lng' => isset($request_info['post_longitude']) ? $request_info['post_longitude'] : ''); $post_location_info = $request_info['post_location']; if ($location_id = geodir_add_new_location($post_location_info)) { $post_location_id = $location_id; } } else { $post_location_id = $location_result->location_id; } } else { $post_location_id = $location_result->location_id; } if ($dummy) { $post_status = 'publish'; } else { $post_status = geodir_new_post_default_status(); } if (isset($request_info['pid']) && $request_info['pid'] != '') { $post_status = get_post_status($request_info['pid']); } /* fix change of slug on every title edit */ if (!isset($request_info['post_name'])) { $request_info['post_name'] = $request_info['post_title']; if (!empty($request_info['pid'])) { $post_info = get_post($request_info['pid']); if (!empty($post_info) && isset($post_info->post_name)) { $request_info['post_name'] = $post_info->post_name; } } } $post = array('post_content' => $request_info['post_desc'], 'post_status' => $post_status, 'post_title' => $request_info['post_title'], 'post_name' => $request_info['post_name'], 'post_type' => $request_info['listing_type']); /** * Called before a listing is saved to the database. * * @since 1.0.0 * @param object $post The post object. */ do_action_ref_array('geodir_before_save_listing', $post); $send_post_submit_mail = false; // unhook this function so it doesn't loop infinitely remove_action('save_post', 'geodir_post_information_save', 10, 2); if (isset($request_info['pid']) && $request_info['pid'] != '') { $post['ID'] = $request_info['pid']; $last_post_id = wp_update_post($post); } else { $last_post_id = wp_insert_post($post); if (!$dummy && $last_post_id) { $send_post_submit_mail = true; // we move post_submit email from here so the rest of the variables are added to the db first(was breaking permalink in email) //geodir_sendEmail('','',$current_user->user_email,$current_user->display_name,'','',$request_info,'post_submit',$last_post_id,$current_user->ID); } } // re-hook this function add_action('save_post', 'geodir_post_information_save', 10, 2); $post_tags = ''; if (!isset($request_info['post_tags'])) { $post_type = $request_info['listing_type']; $post_tags = implode(",", wp_get_object_terms($last_post_id, $post_type . '_tags', array('fields' => 'names'))); } $gd_post_info = array("post_title" => $request_info['post_title'], "post_tags" => isset($request_info['post_tags']) ? $request_info['post_tags'] : $post_tags, "post_status" => $post_status, "post_location_id" => $post_location_id, "claimed" => isset($request_info['claimed']) ? $request_info['claimed'] : '', "businesses" => isset($request_info['a_businesses']) ? $request_info['a_businesses'] : '', "submit_time" => time(), "submit_ip" => $_SERVER['REMOTE_ADDR']); $payment_info = array(); $package_info = array(); $package_info = (array) geodir_post_package_info($package_info, $post); $post_package_id = geodir_get_post_meta($last_post_id, 'package_id'); if (!empty($package_info) && !$post_package_id) { if (isset($package_info['days']) && $package_info['days'] != 0) { $payment_info['expire_date'] = date('Y-m-d', strtotime("+" . $package_info['days'] . " days")); } else { $payment_info['expire_date'] = 'Never'; } $payment_info['package_id'] = $package_info['pid']; $payment_info['alive_days'] = $package_info['days']; $payment_info['is_featured'] = $package_info['is_featured']; $gd_post_info = array_merge($gd_post_info, $payment_info); } $custom_metaboxes = geodir_post_custom_fields('', 'all', $request_info['listing_type']); foreach ($custom_metaboxes as $key => $val) { $name = $val['name']; $type = $val['type']; $extrafields = $val['extra_fields']; if (trim($type) == 'address') { $prefix = $name . '_'; $address = $prefix . 'address'; if (isset($request_info[$address]) && $request_info[$address] != '') { $gd_post_info[$address] = $request_info[$address]; } if ($extrafields != '') { $extrafields = unserialize($extrafields); if (!isset($request_info[$prefix . 'city']) || $request_info[$prefix . 'city'] == '') { $location_result = geodir_get_default_location(); $gd_post_info[$prefix . 'city'] = $location_result->city; $gd_post_info[$prefix . 'region'] = $location_result->region; $gd_post_info[$prefix . 'country'] = $location_result->country; $gd_post_info['post_locations'] = '[' . $location_result->city_slug . '],[' . $location_result->region_slug . '],[' . $location_result->country_slug . ']'; // set all overall post location } else { $gd_post_info[$prefix . 'city'] = $request_info[$prefix . 'city']; $gd_post_info[$prefix . 'region'] = $request_info[$prefix . 'region']; $gd_post_info[$prefix . 'country'] = $request_info[$prefix . 'country']; //----------set post locations when import dummy data------- $location_result = geodir_get_default_location(); $gd_post_info['post_locations'] = '[' . $location_result->city_slug . '],[' . $location_result->region_slug . '],[' . $location_result->country_slug . ']'; // set all overall post location //----------------------------------------------------------------- } if (isset($extrafields['show_zip']) && $extrafields['show_zip'] && isset($request_info[$prefix . 'zip'])) { $gd_post_info[$prefix . 'zip'] = $request_info[$prefix . 'zip']; } if (isset($extrafields['show_map']) && $extrafields['show_map']) { if (isset($request_info[$prefix . 'latitude']) && $request_info[$prefix . 'latitude'] != '') { $gd_post_info[$prefix . 'latitude'] = $request_info[$prefix . 'latitude']; } if (isset($request_info[$prefix . 'longitude']) && $request_info[$prefix . 'longitude'] != '') { $gd_post_info[$prefix . 'longitude'] = $request_info[$prefix . 'longitude']; } if (isset($request_info[$prefix . 'mapview']) && $request_info[$prefix . 'mapview'] != '') { $gd_post_info[$prefix . 'mapview'] = $request_info[$prefix . 'mapview']; } if (isset($request_info[$prefix . 'mapzoom']) && $request_info[$prefix . 'mapzoom'] != '') { $gd_post_info[$prefix . 'mapzoom'] = $request_info[$prefix . 'mapzoom']; } } // show lat lng if (isset($extrafields['show_latlng']) && $extrafields['show_latlng'] && isset($request_info[$prefix . 'latlng'])) { $gd_post_info[$prefix . 'latlng'] = $request_info[$prefix . 'latlng']; } } } elseif (trim($type) == 'file') { if (isset($request_info[$name])) { $request_files = array(); if ($request_info[$name] != '') { $request_files = explode(",", $request_info[$name]); } $extrafields = $extrafields != '' ? maybe_unserialize($extrafields) : NULL; geodir_save_post_file_fields($last_post_id, $name, $request_files, $extrafields); } } elseif (trim($type) == 'datepicker') { $datetime = ''; if ($request_info[$name] != '') { $date_format = geodir_default_date_format(); if (isset($val['extra_fields']) && $val['extra_fields'] != '') { $extra_fields = unserialize($val['extra_fields']); $date_format = isset($extra_fields['date_format']) && $extra_fields['date_format'] != '' ? $extra_fields['date_format'] : $date_format; } $search = array('dd', 'mm', 'yy'); $replace = array('d', 'm', 'Y'); $date_format = str_replace($search, $replace, $date_format); $post_htmlvar_value = $date_format == 'd/m/Y' ? str_replace('/', '-', $request_info[$name]) : $request_info[$name]; // PHP doesn't work well with dd/mm/yyyy format $datetime = date("Y-m-d", strtotime($post_htmlvar_value)); } $gd_post_info[$name] = $datetime; } else { if ($type == 'multiselect') { if (isset($request_info[$name])) { $gd_post_info[$name] = $request_info[$name]; } else { if (isset($request_info['gd_field_' . $name])) { $gd_post_info[$name] = ''; /* fix de-select for multiselect */ } } } else { if (isset($request_info[$name])) { $gd_post_info[$name] = $request_info[$name]; } } } } if (isset($request_info['post_dummy']) && $request_info['post_dummy'] != '') { $gd_post_info['post_dummy'] = $request_info['post_dummy']; } // Save post detail info in detail table if (!empty($gd_post_info)) { geodir_save_post_info($last_post_id, $gd_post_info); } // Set categories to the listing if (isset($request_info['post_category']) && !empty($request_info['post_category'])) { $post_category = array(); foreach ($request_info['post_category'] as $taxonomy => $cat) { if ($dummy) { $post_category = $cat; } else { if (!is_array($cat) && strstr($cat, ',')) { $cat = explode(',', $cat); } if (!empty($cat) && is_array($cat)) { $post_category = array_map('intval', $cat); } } wp_set_object_terms($last_post_id, $post_category, $taxonomy); } $post_default_category = isset($request_info['post_default_category']) ? $request_info['post_default_category'] : ''; $post_category_str = isset($request_info['post_category_str']) ? $request_info['post_category_str'] : ''; geodir_set_postcat_structure($last_post_id, $taxonomy, $post_default_category, $post_category_str); } $post_tags = ''; // Set tags to the listing if (isset($request_info['post_tags']) && !is_array($request_info['post_tags']) && !empty($request_info['post_tags'])) { $post_tags = explode(",", $request_info['post_tags']); } elseif (isset($request_info['post_tags']) && is_array($request_info['post_tags'])) { if ($dummy) { $post_tags = $request_info['post_tags']; } } else { if ($dummy) { $post_tags = array($request_info['post_title']); } } if (is_array($post_tags)) { $taxonomy = $request_info['listing_type'] . '_tags'; wp_set_object_terms($last_post_id, $post_tags, $taxonomy); } // Insert attechment if (isset($request_info['post_images']) && !is_wp_error($last_post_id)) { if (!$dummy) { $tmpimgArr = trim($request_info['post_images'], ","); $tmpimgArr = explode(",", $tmpimgArr); geodir_save_post_images($last_post_id, $tmpimgArr, $dummy); } else { geodir_save_post_images($last_post_id, $request_info['post_images'], $dummy); } } elseif (!isset($request_info['post_images']) || $request_info['post_images'] == '') { /* Delete Attachments $postcurr_images = geodir_get_images($last_post_id); $wpdb->query( $wpdb->prepare( "DELETE FROM ".GEODIR_ATTACHMENT_TABLE." WHERE `post_id` = %d", array($last_post_id) ) ); geodir_remove_attachments($postcurr_images); $gd_post_featured_img = array(); $gd_post_featured_img['featured_image'] = ''; geodir_save_post_info($last_post_id, $gd_post_featured_img); */ } geodir_remove_temp_images(); geodir_set_wp_featured_image($last_post_id); /** * Called after a listing is saved to the database and before any email have been sent. * * @since 1.0.0 * @param int $last_post_id The saved post ID. * @param array $request_info The post details in an array. * @see 'geodir_after_save_listinginfo' */ do_action('geodir_after_save_listing', $last_post_id, $request_info); //die; if ($send_post_submit_mail) { // if new post send out email $to_name = geodir_get_client_name($current_user->ID); geodir_sendEmail('', '', $current_user->user_email, $to_name, '', '', $request_info, 'post_submit', $last_post_id, $current_user->ID); } /* * Unset the session so we don't loop. */ if (isset($_SESSION['listing'])) { unset($_SESSION['listing']); } return $last_post_id; }
function mhk_geodir_show_listing_info($fields_location = '') { global $post, $preview, $wpdb; $payment_info = array(); $package_info = array(); $package_info = geodir_post_package_info($package_info, $post); $post_package_id = $package_info->pid; ob_start(); $fields_info = geodir_post_custom_fields($post_package_id, 'default', geodir_get_current_posttype(), $fields_location); if (!empty($fields_info)) { //echo '<div class="geodir-company_info field-group">'; $field_set_start = 0; if ($fields_location == 'detail') { $i = 1; } foreach ($fields_info as $type) { $html = ''; $html_var = ''; $field_icon = ''; $variables_array = array(); if ($type['type'] != 'fieldset') { $variables_array['post_id'] = $post->ID; $variables_array['label'] = __($type['site_title'], GEODIRECTORY_TEXTDOMAIN); $variables_array['value'] = ''; if (isset($post->{$type}['htmlvar_name'])) { $variables_array['value'] = $post->{$type}['htmlvar_name']; } } //if($type['field_icon']) if (strpos($type['field_icon'], 'http') !== false) { $field_icon = ' background: url(' . $type['field_icon'] . ') no-repeat left center;background-size:18px 18px;padding-left: 21px;'; } elseif (strpos($type['field_icon'], 'fa fa-') !== false) { $field_icon = '<i class="' . $type['field_icon'] . '"></i>'; } //else{$field_icon = $type['field_icon'];} switch ($type['type']) { case 'fieldset': if ($field_set_start == 1) { echo '</div><div class="geodir-company_info field-group ' . $type['htmlvar_name'] . '"><h2>' . __($type['site_title'], GEODIRECTORY_TEXTDOMAIN) . '</h2>'; } else { echo '<h2>' . __($type['site_title'], GEODIRECTORY_TEXTDOMAIN) . '</h2>'; $field_set_start = 1; } break; case 'url': $html_var = $type['htmlvar_name']; if ($post->{$type}['htmlvar_name']) { if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { if ($type['name'] == 'geodir_facebook') { $field_icon_af = '<i class="fa fa-facebook-square"></i>'; } elseif ($type['name'] == 'geodir_twitter') { $field_icon_af = '<i class="fa fa-twitter-square"></i>'; } else { $field_icon_af = '<i class="fa fa-link"></i>'; } } else { $field_icon_af = $field_icon; $field_icon = ''; } if (!strstr($post->{$type}['htmlvar_name'], 'http')) { $website = 'http://' . $post->{$type}['htmlvar_name']; } else { $website = $post->{$type}['htmlvar_name']; } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html .= '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '"><span class="geodir-i-website" style="' . $field_icon . '">' . $field_icon_af . '<a href="' . $website . '" target="_blank" ><strong>' . stripslashes(__($type['site_title'], GEODIRECTORY_TEXTDOMAIN)) . '</strong></a></span></div>'; } break; case 'time': $html_var = $type['htmlvar_name']; if ($post->{$type}['htmlvar_name']) { $value = ''; if ($post->{$type}['htmlvar_name'] != '') { $value = date('h:i', strtotime($post->{$type}['htmlvar_name'])); } if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = '<i class="fa fa-clock-o"></i>'; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-time" style="' . $field_icon . '">' . $field_icon_af; $html .= trim($type['site_title']) ? __($type['site_title'], GEODIRECTORY_TEXTDOMAIN) . ': ' : ' '; $html .= '</span>' . stripslashes($value) . '</div>'; } break; case 'datepicker': if ($post->{$type}['htmlvar_name']) { $date_format = geodir_default_date_format(); if ($type['extra_fields'] != '') { $date_format = unserialize($type['extra_fields']); $date_format = $date_format['date_format']; } $search = array('dd', 'mm', 'yy'); $replace = array('d', 'm', 'Y'); $date_format = str_replace($search, $replace, $date_format); $value = ''; if ($post->{$type}['htmlvar_name'] != '') { $value = date($date_format, strtotime($post->{$type}['htmlvar_name'])); } if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = '<i class="fa fa-calendar"></i>'; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-datepicker" style="' . $field_icon . '">' . $field_icon_af; $html .= trim($type['site_title']) ? __($type['site_title'], GEODIRECTORY_TEXTDOMAIN) . ': ' : ''; $html .= '</span>' . $value . '</div>'; } break; case 'text': $html_var = $type['htmlvar_name']; if ($post->{$type}['htmlvar_name'] != '' && $type['htmlvar_name'] == 'geodir_timing') { if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = '<i class="fa fa-clock-o"></i>'; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-time" style="' . $field_icon . '">' . $field_icon_af; //$html .= (trim($type['site_title'])) ? __($type['site_title'],GEODIRECTORY_TEXTDOMAIN).': ' : ' '; $html .= '</span>' . stripslashes($post->{$type}['htmlvar_name']) . '</div>'; } elseif ($post->{$type}['htmlvar_name']) { if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = ''; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-text" style="' . $field_icon . '">' . $field_icon_af; $html .= trim($type['site_title']) ? __($type['site_title'], GEODIRECTORY_TEXTDOMAIN) . ': ' : ''; $html .= '</span>' . stripslashes($post->{$type}['htmlvar_name']) . '</div>'; } break; case 'radio': $html_var = $type['htmlvar_name']; $html_val = $post->{$type}['htmlvar_name']; if ($post->{$type}['htmlvar_name'] != '') { if ($post->{$type}['htmlvar_name'] == 'f' || $post->{$type}['htmlvar_name'] == '0') { $html_val = __('No', GEODIRECTORY_TEXTDOMAIN); } elseif ($post->{$type}['htmlvar_name'] == 't' || $post->{$type}['htmlvar_name'] == '1') { $html_val = __('Yes', GEODIRECTORY_TEXTDOMAIN); } if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = ''; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-radio" style="' . $field_icon . '">' . $field_icon_af; $html .= trim($type['site_title']) ? __($type['site_title'], GEODIRECTORY_TEXTDOMAIN) . ': ' : ''; $html .= '</span>' . $html_val . '</div>'; } break; case 'checkbox': $html_var = $type['htmlvar_name']; $html_val = $type['htmlvar_name']; if ($post->{$type}['htmlvar_name'] != '') { if ($post->{$type}['htmlvar_name'] == '1') { $html_val = __('Yes', GEODIRECTORY_TEXTDOMAIN); } else { $html_val = __('No', GEODIRECTORY_TEXTDOMAIN); } if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = ''; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-checkbox" style="' . $field_icon . '">' . $field_icon_af; $html .= trim($type['site_title']) ? __($type['site_title'], GEODIRECTORY_TEXTDOMAIN) . ': ' : ''; $html .= '</span>' . $html_val . '</div>'; } break; case 'select': $html_var = $type['htmlvar_name']; if ($post->{$type}['htmlvar_name']) { if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = ''; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-select" style="' . $field_icon . '">' . $field_icon_af; $html .= trim($type['site_title']) ? __($type['site_title'], GEODIRECTORY_TEXTDOMAIN) . ': ' : ''; $html .= '</span>' . stripslashes($post->{$type}['htmlvar_name']) . '</div>'; } break; case 'multiselect': $html_var = $type['htmlvar_name']; if (!empty($post->{$type}['htmlvar_name'])) { if (is_array($post->{$type}['htmlvar_name'])) { $post->{$type}['htmlvar_name'] = implode(', ', $post->{$type}['htmlvar_name']); } if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = ''; } else { $field_icon_af = $field_icon; $field_icon = ''; } $option_values = explode(',', $post->{$type}['htmlvar_name']); if ($type['option_values']) { if (strstr($type['option_values'], "/")) { $option_values = array(); $field_values = explode(',', $type['option_values']); foreach ($field_values as $data) { $val = explode('/', $data); if (isset($val[1]) && in_array($val[1], explode(',', $post->{$type}['htmlvar_name']))) { $option_values[] = $val[0]; } } } } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-select" style="' . $field_icon . '">' . $field_icon_af; $html .= trim($type['site_title']) ? __($type['site_title'], GEODIRECTORY_TEXTDOMAIN) . ': <br />' : ''; $html .= '</span>'; if (count($option_values) > 1) { $html .= '<ul>'; foreach ($option_values as $val) { $html .= '<li>' . stripslashes($val) . '</li>'; } $html .= '</ul>'; } else { $html .= stripslashes(trim($post->{$type}['htmlvar_name'], ',')); } $html .= '</div>'; } break; case 'textarea': if (!empty($post->{$type}['htmlvar_name'])) { if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = ''; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-text" style="' . $field_icon . '">' . $field_icon_af; //$html .= (trim($type['site_title'])) ? __($type['site_title'],GEODIRECTORY_TEXTDOMAIN).': ' : ''; $html .= '</span>' . stripslashes($post->{$type}['htmlvar_name']) . '</div>'; } break; case 'html': if (!empty($post->{$type}['htmlvar_name'])) { if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = ''; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html = '<div class="geodir_more_info geodir_more_info_html' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-text" style="' . $field_icon . '">' . $field_icon_af; $html .= trim($type['site_title']) ? __($type['site_title'], GEODIRECTORY_TEXTDOMAIN) . ': ' : ''; $html .= '</span>' . stripslashes($post->{$type}['htmlvar_name']) . '</div>'; } break; } if ($html) { do_action('geodir_before_show_' . $html_var); if ($html) { echo apply_filters('geodir_show_' . $html_var, $html, $variables_array); } do_action('geodir_after_show_' . $html_var); } } //echo '</div>'; } return $html = ob_get_clean(); }
_e('Select if you want to show advanced editor.', GEODIRECTORY_TEXTDOMAIN); ?> </span> </td> </tr><?php } ?> <?php $pricearr = array(); if (isset($field_info->packages) && $field_info->packages != '') { $pricearr = explode(',', trim($field_info->packages, ',')); } else { $package_info = array(); $package_info = geodir_post_package_info($package_info, '', $post_type); $pricearr[] = $package_info->pid; } ob_start(); ?> <select style="display:none" name="show_on_pkg[]" id="show_on_pkg" multiple="multiple"> <?php if (!empty($pricearr)) { foreach ($pricearr as $val) { ?> <option selected="selected" value="<?php echo esc_attr($val); ?> " ><?php echo $val;
function geodir_payments_the_content($post_desc) { global $post; if (is_admin() || empty($post)) { return $post_desc; } if (is_object($post) && isset($post->ID) && !empty($post->geodir_video)) { if (strpos($post_desc, $post->geodir_video) !== false) { return $post_desc; } } $package_info = geodir_post_package_info(array(), $post); $desc_limit_enabled = geodir_payments_desc_limit_enabled($package_info); if (is_object($post) && (isset($post->ID) || !isset($post->ID) && isset($post->preview)) && $post_desc != '' && $desc_limit_enabled) { $desc_limit = geodir_payments_get_desc_limit($package_info); $post_desc = geodir_pm_substr($post_desc, (int) $desc_limit); return $post_desc; } return $post_desc; }
/** * Show listing info depending on field location. * * @since 1.0.0 * @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; $payment_info = array(); $package_info = array(); $package_info = geodir_post_package_info($package_info, $post); //return; $post_package_id = $package_info->pid; $p_type = geodir_get_current_posttype() ? geodir_get_current_posttype() : $post->post_type; ob_start(); $fields_info = geodir_post_custom_fields($post_package_id, 'default', $p_type, $fields_location); if (!empty($fields_info)) { //echo '<div class="geodir-company_info field-group">'; $field_set_start = 0; if ($fields_location == 'detail') { $i = 1; } foreach ($fields_info as $type) { $type = stripslashes_deep($type); // strip slashes $html = ''; $html_var = ''; $field_icon = ''; $variables_array = array(); if ($fields_location == 'detail' && isset($type['show_as_tab']) && (int) $type['show_as_tab'] == 1 && in_array($type['type'], array('text', 'datepicker', 'textarea', 'time', 'phone', 'email', 'select', 'multiselect', 'url', 'html', 'fieldset', 'radio', 'checkbox', 'file'))) { continue; } if ($type['type'] != 'fieldset') { $variables_array['post_id'] = $post->ID; $variables_array['label'] = __($type['site_title'], 'geodirectory'); $variables_array['value'] = ''; if (isset($post->{$type}['htmlvar_name'])) { $variables_array['value'] = $post->{$type}['htmlvar_name']; } } //if($type['field_icon']) if (strpos($type['field_icon'], 'http') !== false) { $field_icon = ' background: url(' . $type['field_icon'] . ') no-repeat left center;background-size:18px 18px;padding-left: 21px;'; } elseif (strpos($type['field_icon'], 'fa fa-') !== false) { $field_icon = '<i class="' . $type['field_icon'] . '"></i>'; } //else{$field_icon = $type['field_icon'];} switch ($type['type']) { case 'fieldset': if ($field_set_start == 1) { echo '</div><div class="geodir-company_info field-group ' . $type['htmlvar_name'] . '"><h2>' . __($type['site_title'], 'geodirectory') . '</h2>'; } else { echo '<h2>' . __($type['site_title'], 'geodirectory') . '</h2>'; $field_set_start = 1; } break; case 'address': $html_var = $type['htmlvar_name'] . '_address'; if ($type['extra_fields']) { $extra_fields = unserialize($type['extra_fields']); $addition_fields = ''; if (!empty($extra_fields)) { /** * Filter "show city in address" value. * * @since 1.0.0 */ $show_city_in_address = apply_filters('geodir_show_city_in_address', false); if (isset($extra_fields['show_city']) && $extra_fields['show_city'] && $show_city_in_address) { $field = $type['htmlvar_name'] . '_city'; if ($post->{$field}) { $addition_fields .= ', ' . $post->{$field}; } } if (isset($extra_fields['show_zip']) && $extra_fields['show_zip']) { $field = $type['htmlvar_name'] . '_zip'; if ($post->{$field}) { $addition_fields .= ', ' . $post->{$field}; } } } } /*if($type['extra_fields']) { $extra_fields = unserialize($type['extra_fields']); $addition_fields = ''; if(!empty($extra_fields)) { if($extra_fields['show_city']) { $field = $type['htmlvar_name'].'_city'; if($post->$field) { $addition_fields .= ', '.$post->$field; } } if($extra_fields['show_region']) { $field = $type['htmlvar_name'].'_region'; if($post->$field) { $addition_fields .= ', '.$post->$field; } } if($extra_fields['show_country']) { $field = $type['htmlvar_name'].'_country'; if($post->$field) { $addition_fields .= ', '.$post->$field; } } if($extra_fields['show_zip']) { $field = $type['htmlvar_name'].'_zip'; if($post->$field) { $addition_fields .= ', '.$post->$field; } } } }*/ if ($post->{$html_var}) { if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = '<i class="fa fa-home"></i>'; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;" itemscope itemtype="http://schema.org/PostalAddress">'; $html .= '<span class="geodir-i-location" style="' . $field_icon . '">' . $field_icon_af; $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : ' '; $html .= '</span>'; //print_r($_POST); if ($preview) { $html .= stripslashes($post->{$html_var}) . $addition_fields . '</p>'; } else { if ($post->post_address) { $html .= '<span itemprop="streetAddress">' . $post->post_address . '</span><br>'; } if ($post->post_city) { $html .= '<span itemprop="addressLocality">' . $post->post_city . '</span><br>'; } if ($post->post_region) { $html .= '<span itemprop="addressRegion">' . $post->post_region . '</span><br>'; } if ($post->post_zip) { $html .= '<span itemprop="postalCode">' . $post->post_zip . '</span><br>'; } if ($post->post_country) { $html .= '<span itemprop="addressCountry">' . __($post->post_country, 'geodirectory') . '</span><br>'; } $html .= '</div>'; } } $variables_array['value'] = $post->{$html_var}; break; case 'url': $html_var = $type['htmlvar_name']; if ($post->{$type}['htmlvar_name']) { if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { if ($type['name'] == 'geodir_facebook') { $field_icon_af = '<i class="fa fa-facebook-square"></i>'; } elseif ($type['name'] == 'geodir_twitter') { $field_icon_af = '<i class="fa fa-twitter-square"></i>'; } else { $field_icon_af = '<i class="fa fa-link"></i>'; } } else { $field_icon_af = $field_icon; $field_icon = ''; } if (!strstr($post->{$type}['htmlvar_name'], 'http')) { $website = 'http://' . $post->{$type}['htmlvar_name']; } else { $website = $post->{$type}['htmlvar_name']; } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } // all search engines that use the nofollow value exclude links that use it from their ranking calculation $rel = strpos($website, get_site_url()) !== false ? '' : 'rel="nofollow"'; /** * Filter custom field website name. * * @since 1.0.0 * * @param string $type['site_title'] Website Title. * @param string $website Website URL. * @param int $post->ID Post ID. */ $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '"><span class="geodir-i-website" style="' . $field_icon . '">' . $field_icon_af . '<a href="' . $website . '" target="_blank" ' . $rel . ' ><strong>' . apply_filters('geodir_custom_field_website_name', stripslashes(__($type['site_title'], 'geodirectory')), $website, $post->ID) . '</strong></a></span></div>'; } break; case 'phone': $html_var = $type['htmlvar_name']; if ($post->{$type}['htmlvar_name']) { if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = '<i class="fa fa-phone"></i>'; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-contact" style="' . $field_icon . '">' . $field_icon_af . ($html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : ' '); $html .= '</span><a href="tel:' . stripslashes($post->{$type}['htmlvar_name']) . '">' . stripslashes($post->{$type}['htmlvar_name']) . '</a></div>'; } break; case 'time': $html_var = $type['htmlvar_name']; if ($post->{$type}['htmlvar_name']) { $value = ''; if ($post->{$type}['htmlvar_name'] != '') { //$value = date('h:i',strtotime($post->$type['htmlvar_name'])); $value = date(get_option('time_format'), strtotime($post->{$type}['htmlvar_name'])); } if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = '<i class="fa fa-clock-o"></i>'; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-time" style="' . $field_icon . '">' . $field_icon_af; $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : ' '; $html .= '</span>' . stripslashes($value) . '</div>'; } break; case 'datepicker': if ($post->{$type}['htmlvar_name']) { $date_format = geodir_default_date_format(); if ($type['extra_fields'] != '') { $date_format = unserialize($type['extra_fields']); $date_format = $date_format['date_format']; } $search = array('dd', 'd', 'DD', 'mm', 'm', 'MM', 'yy'); //jQuery UI datepicker format $replace = array('d', 'j', 'l', 'm', 'n', 'F', 'Y'); //PHP date format $date_format = str_replace($search, $replace, $date_format); $post_htmlvar_value = $date_format == 'd/m/Y' ? str_replace('/', '-', $post->{$type}['htmlvar_name']) : $post->{$type}['htmlvar_name']; // PHP doesn't work well with dd/mm/yyyy format $value = ''; if ($post->{$type}['htmlvar_name'] != '' && $post->{$type}['htmlvar_name'] != "0000-00-00") { $value = date($date_format, strtotime($post_htmlvar_value)); } else { continue; } if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = '<i class="fa fa-calendar"></i>'; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-datepicker" style="' . $field_icon . '">' . $field_icon_af; $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : ''; $html .= '</span>' . $value . '</div>'; } break; case 'text': $html_var = $type['htmlvar_name']; if (isset($post->{$type}['htmlvar_name']) && $post->{$type}['htmlvar_name'] != '' && $type['htmlvar_name'] == 'geodir_timing') { if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = '<i class="fa fa-clock-o"></i>'; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-time" style="' . $field_icon . '">' . $field_icon_af; $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : ' '; $html .= '</span>' . stripslashes($post->{$type}['htmlvar_name']) . '</div>'; } elseif (isset($post->{$type}['htmlvar_name']) && $post->{$type}['htmlvar_name']) { if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = ''; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-text" style="' . $field_icon . '">' . $field_icon_af; $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : ''; $html .= '</span>' . stripslashes($post->{$type}['htmlvar_name']) . '</div>'; } break; case 'radio': $html_var = $type['htmlvar_name']; $html_val = $post->{$type}['htmlvar_name']; if ($post->{$type}['htmlvar_name'] != '') { if ($post->{$type}['htmlvar_name'] == 'f' || $post->{$type}['htmlvar_name'] == '0') { $html_val = __('No', 'geodirectory'); } elseif ($post->{$type}['htmlvar_name'] == 't' || $post->{$type}['htmlvar_name'] == '1') { $html_val = __('Yes', 'geodirectory'); } if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = ''; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-radio" style="' . $field_icon . '">' . $field_icon_af; $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : ''; $html .= '</span>' . $html_val . '</div>'; } break; case 'checkbox': $html_var = $type['htmlvar_name']; $html_val = $type['htmlvar_name']; if ((int) $post->{$html_var} == 1) { if ($post->{$type}['htmlvar_name'] == '1') { $html_val = __('Yes', 'geodirectory'); } else { $html_val = __('No', 'geodirectory'); } if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = ''; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-checkbox" style="' . $field_icon . '">' . $field_icon_af; $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : ''; $html .= '</span>' . $html_val . '</div>'; } break; case 'select': $html_var = $type['htmlvar_name']; if ($post->{$type}['htmlvar_name']) { if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = ''; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-select" style="' . $field_icon . '">' . $field_icon_af; $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : ''; $html .= '</span>' . stripslashes($post->{$type}['htmlvar_name']) . '</div>'; } break; case 'multiselect': $html_var = $type['htmlvar_name']; if (!empty($post->{$type}['htmlvar_name'])) { if (is_array($post->{$type}['htmlvar_name'])) { $post->{$type}['htmlvar_name'] = implode(', ', $post->{$type}['htmlvar_name']); } if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = ''; } else { $field_icon_af = $field_icon; $field_icon = ''; } $option_values = explode(',', $post->{$type}['htmlvar_name']); if ($type['option_values']) { if (strstr($type['option_values'], "/")) { $option_values = array(); $field_values = explode(',', $type['option_values']); foreach ($field_values as $data) { $val = explode('/', $data); if (isset($val[1]) && in_array($val[1], explode(',', $post->{$type}['htmlvar_name']))) { $option_values[] = $val[0]; } } } } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-select" style="' . $field_icon . '">' . $field_icon_af; $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : ''; $html .= '</span>'; if (count($option_values) > 1) { $html .= '<ul>'; foreach ($option_values as $val) { $html .= '<li>' . stripslashes($val) . '</li>'; } $html .= '</ul>'; } else { $html .= stripslashes(trim($post->{$type}['htmlvar_name'], ',')); } $html .= '</div>'; } break; case 'email': if ($type['htmlvar_name'] == 'geodir_email' && !(geodir_is_page('detail') || geodir_is_page('preview'))) { continue; // Remove Send Enquiry | Send To Friend from listings page } if ($type['htmlvar_name'] == 'geodir_email' && (isset($package_info->sendtofriend) && $package_info->sendtofriend || $post->{$type}['htmlvar_name'])) { $b_send_inquiry = ''; $b_sendtofriend = ''; $html = ''; if (!$preview) { $b_send_inquiry = 'b_send_inquiry'; $b_sendtofriend = 'b_sendtofriend'; $html = '<input type="hidden" name="geodir_popup_post_id" value="' . $post->ID . '" /><div class="geodir_display_popup_forms"></div>'; } if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = '<i class="fa fa-envelope"></i>'; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html .= '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '"><span class="geodir-i-email" style="' . $field_icon . '">' . $field_icon_af; $seperator = ''; if ($post->{$type}['htmlvar_name']) { $html .= '<a href="javascript:void(0);" class="' . $b_send_inquiry . '" >' . SEND_INQUIRY . '</a>'; $seperator = ' | '; } if (isset($package_info->sendtofriend) && $package_info->sendtofriend) { $html .= $seperator . '<a href="javascript:void(0);" class="' . $b_sendtofriend . '">' . SEND_TO_FRIEND . '</a>'; } $html .= '</span></div>'; if (isset($_REQUEST['send_inquiry']) && $_REQUEST['send_inquiry'] == 'success') { $html .= '<p class="sucess_msg">' . SEND_INQUIRY_SUCCESS . '</p>'; } elseif (isset($_REQUEST['sendtofrnd']) && $_REQUEST['sendtofrnd'] == 'success') { $html .= '<p class="sucess_msg">' . SEND_FRIEND_SUCCESS . '</p>'; } elseif (isset($_REQUEST['emsg']) && $_REQUEST['emsg'] == 'captch') { $html .= '<p class="error_msg_fix">' . WRONG_CAPTCH_MSG . '</p>'; } /*if(!$preview){require_once (geodir_plugin_path().'/geodirectory-templates/popup-forms.php');}*/ } else { if ($post->{$type}['htmlvar_name']) { if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = '<i class="fa fa-envelope"></i>'; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-email" style="' . $field_icon . '">' . $field_icon_af; $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : ''; $html .= '</span>' . stripslashes($post->{$type}['htmlvar_name']) . '</div>'; } } break; case 'file': $html_var = $type['htmlvar_name']; if (!empty($post->{$type}['htmlvar_name'])) { $files = explode(",", $post->{$type}['htmlvar_name']); if (!empty($files)) { $extra_fields = !empty($type['extra_fields']) ? maybe_unserialize($type['extra_fields']) : NULL; $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'] : ''; $file_paths = ''; foreach ($files as $file) { if (!empty($file)) { $filetype = wp_check_filetype($file); $image_name_arr = explode('/', $file); $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. } //$allowed_file_types = array('application/pdf', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'text/csv', 'text/plain'); $image_file_types = array('image/jpg', 'image/jpeg', 'image/gif', 'image/png', 'image/bmp', 'image/x-icon'); // If the uploaded file is image if (in_array($uploaded_file_type, $image_file_types)) { $file_paths .= '<div class="geodir-custom-post-gallery" class="clearfix">'; $file_paths .= '<a href="' . $file . '">'; $file_paths .= geodir_show_image(array('src' => $file), 'thumbnail', false, false); $file_paths .= '</a>'; //$file_paths .= '<img src="'.$file.'" />'; $file_paths .= '</div>'; } else { $ext_path = '_' . $html_var . '_'; $filename = explode($ext_path, $filename); $file_paths .= '<a href="' . $file . '" target="_blank">' . $filename[count($filename) - 1] . '</a>'; } } } if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = ''; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' geodir-custom-file-box ' . $type['htmlvar_name'] . '"><div class="geodir-i-select" style="' . $field_icon . '">' . $field_icon_af; $html .= '<span style="display: inline-block; vertical-align: top; padding-right: 14px;">'; $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : ''; $html .= '</span>'; $html .= $file_paths . '</div></div>'; } } break; case 'textarea': if (!empty($post->{$type}['htmlvar_name'])) { if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = ''; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-text" style="' . $field_icon . '">' . $field_icon_af; $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : ''; $html .= '</span>' . wpautop(stripslashes($post->{$type}['htmlvar_name'])) . '</div>'; } break; case 'html': if (!empty($post->{$type}['htmlvar_name'])) { if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } elseif ($field_icon == '') { $field_icon_af = ''; } else { $field_icon_af = $field_icon; $field_icon = ''; } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-text" style="' . $field_icon . '">' . $field_icon_af; $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : ''; $html .= '</span>' . wpautop(stripslashes($post->{$type}['htmlvar_name'])) . '</div>'; } break; case 'taxonomy': $html_var = $type['htmlvar_name']; if ($html_var == $post->post_type . 'category' && !empty($post->{$html_var})) { $post_taxonomy = $post->post_type . 'category'; $field_value = $post->{$html_var}; $links = array(); $terms = array(); $termsOrdered = array(); if (!is_array($field_value)) { $field_value = explode(",", trim($field_value, ",")); } $field_value = array_unique($field_value); if (!empty($field_value)) { foreach ($field_value as $term) { $term = trim($term); if ($term != '') { $term = get_term_by('id', $term, $html_var); if (is_object($term)) { $links[] = "<a href='" . esc_attr(get_term_link($term, $post_taxonomy)) . "'>" . $term->name . "</a>"; $terms[] = $term; } } } if (!empty($links)) { // order alphabetically asort($links); foreach (array_keys($links) as $key) { $termsOrdered[$key] = $terms[$key]; } $terms = $termsOrdered; } } $html_value = !empty($links) && !empty($terms) ? wp_sprintf('%l', $links, (object) $terms) : ''; if ($html_value != '') { if (strpos($field_icon, 'http') !== false) { $field_icon_af = ''; } else { if ($field_icon == '') { $field_icon_af = ''; } else { $field_icon_af = $field_icon; $field_icon = ''; } } $geodir_odd_even = ''; if ($fields_location == 'detail') { $geodir_odd_even = 'geodir_more_info_odd'; if ($i % 2 == 0) { $geodir_odd_even = 'geodir_more_info_even'; } $i++; } $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $html_var . '" style="clear:both;"><span class="geodir-i-taxonomy geodir-i-category" style="' . $field_icon . '">' . $field_icon_af; $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : ''; $html .= '</span> ' . $html_value . '</div>'; } } break; } 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}"); } } //echo '</div>'; } return $html = ob_get_clean(); }
/** * Handle import/export for categories & listings. * * @since 1.4.6 * @package GeoDirectory * * @global object $wpdb WordPress Database object. * @global string $plugin_prefix Geodirectory plugin table prefix. * @global object $current_user Current user object. * @global null|object $wp_filesystem WP_Filesystem object. * @return string Json data. */ function geodir_ajax_import_export() { global $wpdb, $plugin_prefix, $current_user, $wp_filesystem; // try to set higher limits for import @ini_set('max_input_time', 3000); @ini_set('max_execution_time', 3000); @ini_set('memory_limit', '256M'); error_reporting(0); $json = array(); if (!current_user_can('manage_options')) { wp_send_json($json); } $task = isset($_REQUEST['task']) ? $_REQUEST['task'] : NULL; $nonce = isset($_REQUEST['_nonce']) ? $_REQUEST['_nonce'] : NULL; $stat = isset($_REQUEST['_st']) ? $_REQUEST['_st'] : false; if (!wp_verify_nonce($nonce, 'geodir_import_export_nonce')) { wp_send_json($json); } $post_type = isset($_REQUEST['_pt']) ? $_REQUEST['_pt'] : NULL; /*if( empty( $wp_filesystem ) ) { require_once( ABSPATH . '/wp-admin/includes/file.php' ); WP_Filesystem(); global $wp_filesystem; }*/ $wp_filesystem = geodir_init_filesystem(); if (!$wp_filesystem) { $json['error'] = __('Fail, something wrong to create csv file.', GEODIRECTORY_TEXTDOMAIN); wp_send_json($json); exit; } $csv_file_dir = geodir_path_import_export(false); if (!$wp_filesystem->is_dir($csv_file_dir)) { $wp_filesystem->mkdir($csv_file_dir, FS_CHMOD_DIR); } switch ($task) { case 'export_posts': // WPML $is_wpml = geodir_is_wpml(); if ($is_wpml) { global $sitepress; $active_lang = ICL_LANGUAGE_CODE; $sitepress->switch_lang('all', true); } // WPML if ($post_type == 'gd_event') { //add_filter( 'geodir_imex_count_posts', 'geodir_imex_count_events', 10, 2 ); add_filter('geodir_imex_export_posts_query', 'geodir_imex_get_events_query', 10, 2); } $file_name = $post_type . '_' . date('j_n_y'); $posts_count = geodir_get_posts_count($post_type); $file_url = geodir_path_import_export() . '/' . $file_name . '.csv'; $file_path = $csv_file_dir . '/' . $file_name . '.csv'; $file_path_temp = $csv_file_dir . '/' . $post_type . '_' . $nonce . '.csv'; if (isset($_REQUEST['_st'])) { $line_count = (int) geodir_import_export_line_count($file_path_temp); $percentage = count($posts_count) > 0 && $line_count > 0 ? ceil($line_count / $posts_count) * 100 : 0; $percentage = min($percentage, 100); $json['percentage'] = $percentage; // WPML if ($is_wpml) { $sitepress->switch_lang($active_lang, true); } // WPML wp_send_json($json); } else { if ($wp_filesystem->exists($file_path)) { $wp_filesystem->delete($file_path); } if (!$posts_count > 0) { $json['error'] = __('No records to export.', GEODIRECTORY_TEXTDOMAIN); } else { $args = array('hide_empty' => 0); $posts = geodir_imex_get_posts($post_type); if (!empty($posts)) { $total_posts = count($posts); $per_page = 100; $total_pages = ceil($total_posts / $per_page); for ($i = 0; $i <= $total_pages; $i++) { $save_posts = array_slice($posts, $i * $per_page, $per_page); $clear = $i == 0 ? true : false; geodir_save_csv_data($file_path_temp, $save_posts, $clear); } if ($wp_filesystem->exists($file_path_temp)) { $wp_filesystem->move($file_path_temp, $file_path, true); } if ($wp_filesystem->exists($file_path)) { $json['total'] = $posts_count; $json['csv_file'] = $file_url; } else { $json['error'] = __('Fail, something wrong to create csv file.', GEODIRECTORY_TEXTDOMAIN); } } else { $json['error'] = __('No records to export.', GEODIRECTORY_TEXTDOMAIN); } } // WPML if ($is_wpml) { $sitepress->switch_lang($active_lang, true); } // WPML wp_send_json($json); } break; case 'export_cats': // WPML $is_wpml = geodir_is_wpml(); if ($is_wpml) { global $sitepress; $active_lang = ICL_LANGUAGE_CODE; $sitepress->switch_lang('all', true); } // WPML $file_name = $post_type . 'category_' . date('j_n_y'); $terms_count = geodir_get_terms_count($post_type); $file_url = geodir_path_import_export() . '/' . $file_name . '.csv'; $file_path = $csv_file_dir . '/' . $file_name . '.csv'; $file_path_temp = $csv_file_dir . '/' . $post_type . 'category_' . $nonce . '.csv'; if (isset($_REQUEST['_st'])) { $line_count = (int) geodir_import_export_line_count($file_path_temp); $percentage = count($terms_count) > 0 && $line_count > 0 ? ceil($line_count / $terms_count) * 100 : 0; $percentage = min($percentage, 100); $json['percentage'] = $percentage; // WPML if ($is_wpml) { $sitepress->switch_lang($active_lang, true); } // WPML wp_send_json($json); } else { if ($wp_filesystem->exists($file_path)) { $wp_filesystem->delete($file_path); } if (!$terms_count > 0) { $json['error'] = __('No records to export.', GEODIRECTORY_TEXTDOMAIN); } else { $args = array('hide_empty' => 0); $terms = geodir_imex_get_terms($post_type); if (!empty($terms)) { $total_terms = count($terms); $per_page = 50; $total_pages = ceil($total_terms / $per_page); for ($i = 0; $i <= $total_pages; $i++) { $save_terms = array_slice($terms, $i * $per_page, $per_page); $clear = $i == 0 ? true : false; geodir_save_csv_data($file_path_temp, $save_terms, $clear); } if ($wp_filesystem->exists($file_path_temp)) { $wp_filesystem->move($file_path_temp, $file_path, true); } if ($wp_filesystem->exists($file_path)) { $json['total'] = $terms_count; $json['csv_file'] = $file_url; } else { $json['error'] = __('Fail, something wrong to create csv file.', GEODIRECTORY_TEXTDOMAIN); } } else { $json['error'] = __('No records to export.', GEODIRECTORY_TEXTDOMAIN); } } // WPML if ($is_wpml) { $sitepress->switch_lang($active_lang, true); } // WPML wp_send_json($json); } break; case 'prepare_import': case 'import_cat': case 'import_post': // WPML $is_wpml = geodir_is_wpml(); if ($is_wpml) { global $sitepress; $active_lang = ICL_LANGUAGE_CODE; } // WPML ini_set('auto_detect_line_endings', true); $uploads = wp_upload_dir(); $uploads_dir = $uploads['path']; $uploads_subdir = $uploads['subdir']; $csv_file = isset($_POST['_file']) ? $_POST['_file'] : NULL; $import_choice = isset($_REQUEST['_ch']) ? $_REQUEST['_ch'] : 'skip'; $csv_file_arr = explode('/', $csv_file); $csv_filename = end($csv_file_arr); $target_path = $uploads_dir . '/temp_' . $current_user->data->ID . '/' . $csv_filename; $json['file'] = $csv_file; $json['error'] = __('The uploaded file is not a valid csv file. Please try again.', GEODIRECTORY_TEXTDOMAIN); if ($csv_file && $wp_filesystem->is_file($target_path) && $wp_filesystem->exists($target_path)) { $wp_filetype = wp_check_filetype_and_ext($target_path, $csv_filename); if (!empty($wp_filetype) && isset($wp_filetype['ext']) && strtolower($wp_filetype['ext']) == 'csv') { $json['error'] = NULL; $json['rows'] = 0; if (($handle = fopen($target_path, "r")) !== FALSE) { while (($data = fgetcsv($handle, 100000, ",")) !== FALSE) { if (!empty($data)) { $file[] = $data; } } fclose($handle); } $json['rows'] = !empty($file) && count($file) > 1 ? count($file) - 1 : 0; if (!$json['rows'] > 0) { $json['error'] = __('No data found in csv file.', GEODIRECTORY_TEXTDOMAIN); } } else { wp_send_json($json); } } else { wp_send_json($json); } if ($task == 'prepare_import' || !empty($json['error'])) { wp_send_json($json); } $total = $json['rows']; $limit = isset($_POST['limit']) ? (int) $_POST['limit'] : 1; $processed = isset($_POST['processed']) ? (int) $_POST['processed'] : 0; $count = $limit; $requested_limit = $limit; if ($count < $total) { $count = $processed + $count; if ($count > $total) { $count = $total; } } else { $count = $total; } $created = 0; $updated = 0; $skipped = 0; $invalid = 0; $invalid_addr = 0; $images = 0; $invalid_title = 0; $customKeyarray = array(); $gd_post_info = array(); $post_location = array(); $countpost = 0; $post_types = geodir_get_posttypes(); if ($task == 'import_cat') { if (!empty($file)) { $columns = isset($file[0]) ? $file[0] : NULL; if (empty($columns) || !empty($columns) && $columns[0] == '') { $json['error'] = CSV_INVAILD_FILE; wp_send_json($json); } for ($i = 1; $i <= $limit; $i++) { $index = $processed + $i; if (isset($file[$index])) { $row = $file[$index]; $row = array_map('trim', $row); $row = array_map('utf8_encode', $row); $cat_id = ''; $cat_name = ''; $cat_slug = ''; $cat_posttype = ''; $cat_parent = ''; $cat_description = ''; $cat_top_description = ''; $cat_image = ''; $cat_icon = ''; $cat_language = ''; $c = 0; foreach ($columns as $column) { if ($column == 'cat_id') { $cat_id = (int) $row[$c]; } else { if ($column == 'cat_name') { $cat_name = $row[$c]; } else { if ($column == 'cat_slug') { $cat_slug = $row[$c]; } else { if ($column == 'cat_posttype') { $cat_posttype = $row[$c]; } else { if ($column == 'cat_parent') { $cat_parent = trim($row[$c]); } else { if ($column == 'cat_description') { $cat_description = $row[$c]; } else { if ($column == 'cat_top_description') { $cat_top_description = $row[$c]; } else { if ($column == 'cat_image') { $cat_image = $row[$c]; } else { if ($column == 'cat_icon') { $cat_icon = $row[$c]; } } } } } } } } } // WPML if ($is_wpml && $column == 'cat_language') { $cat_language = strtolower(trim($row[$c])); } // WPML $c++; } if ($cat_name == '' || !in_array($cat_posttype, $post_types)) { $invalid++; continue; } // WPML if ($is_wpml && $cat_language != '') { $sitepress->switch_lang($cat_language, true); } // WPML $term_data = array(); $term_data['name'] = $cat_name; $term_data['slug'] = $cat_slug; $term_data['description'] = $cat_description; $term_data['top_description'] = $cat_top_description; $term_data['image'] = $cat_image != '' ? basename($cat_image) : ''; $term_data['icon'] = $cat_icon != '' ? basename($cat_icon) : ''; $term_data = array_map('utf8_encode', $term_data); $taxonomy = $cat_posttype . 'category'; $term_data['taxonomy'] = $taxonomy; $term_parent_id = 0; if ($cat_parent != "" || (int) $cat_parent > 0) { $term_parent = ''; if ($term_parent = get_term_by('name', $cat_parent, $taxonomy)) { $term_parent = $term_parent; } else { if ($term_parent = get_term_by('slug', $cat_parent, $taxonomy)) { $term_parent = $term_parent; } else { if ($term_parent = get_term_by('id', $cat_parent, $taxonomy)) { $term_parent = $term_parent; } else { $term_parent_data = array(); $term_parent_data['name'] = $cat_parent; $term_parent_data = array_map('utf8_encode', $term_parent_data); $term_parent_data['taxonomy'] = $taxonomy; $term_parent_id = (int) geodir_imex_insert_term($taxonomy, $term_parent_data); } } } if (!empty($term_parent) && !is_wp_error($term_parent)) { $term_parent_id = (int) $term_parent->term_id; } } $term_data['parent'] = (int) $term_parent_id; $term_id = NULL; if ($import_choice == 'update') { if ($cat_id > 0 && ($term = (array) term_exists($cat_id, $taxonomy))) { $term_data['term_id'] = $term['term_id']; if ($term_id = geodir_imex_update_term($taxonomy, $term_data)) { $updated++; } else { $invalid++; } } else { if ($term_data['slug'] != '' && ($term = (array) term_exists($term_data['slug'], $taxonomy))) { $term_data['term_id'] = $term['term_id']; if ($term_id = geodir_imex_update_term($taxonomy, $term_data)) { $updated++; } else { $invalid++; } } else { if ($term_id = geodir_imex_insert_term($taxonomy, $term_data)) { $created++; } else { $invalid++; } } } } else { if ($import_choice == 'skip') { if ($cat_id > 0 && ($term = (array) term_exists($cat_id, $taxonomy))) { $skipped++; } else { if ($term_data['slug'] != '' && ($term = (array) term_exists($term_data['slug'], $taxonomy))) { $skipped++; } else { if ($term_id = geodir_imex_insert_term($taxonomy, $term_data)) { $created++; } else { $invalid++; } } } } else { $invalid++; } } if ($term_id) { if (isset($term_data['top_description'])) { update_tax_meta($term_id, 'ct_cat_top_desc', $term_data['top_description'], $cat_posttype); } $attachment = false; if (isset($term_data['image']) && $term_data['image'] != '') { $cat_image = geodir_get_default_catimage($term_id, $cat_posttype); $cat_image = !empty($cat_image) && isset($cat_image['src']) ? $cat_image['src'] : ''; if (basename($cat_image) != $term_data['image']) { $attachment = true; update_tax_meta($term_id, 'ct_cat_default_img', array('id' => 'image', 'src' => $uploads['url'] . '/' . $term_data['image']), $cat_posttype); } } if (isset($term_data['icon']) && $term_data['icon'] != '') { $cat_icon = get_tax_meta($term_id, 'ct_cat_icon', false, $cat_posttype); $cat_icon = !empty($cat_icon) && isset($cat_icon['src']) ? $cat_icon['src'] : ''; if (basename($cat_icon) != $term_data['icon']) { $attachment = true; update_tax_meta($term_id, 'ct_cat_icon', array('id' => 'icon', 'src' => $uploads['url'] . '/' . $term_data['icon']), $cat_posttype); } } if ($attachment) { $images++; } } // WPML if ($is_wpml && $cat_language != '') { $sitepress->switch_lang($active_lang, true); } // WPML } } } $json = array(); $json['processed'] = $limit; $json['created'] = $created; $json['updated'] = $updated; $json['skipped'] = $skipped; $json['invalid'] = $invalid; $json['images'] = $images; wp_send_json($json); } else { if ($task == 'import_post') { if (!empty($file)) { $wp_post_statuses = get_post_statuses(); // All of the WordPress supported post statuses. $default_status = 'publish'; $current_date = date_i18n('Y-m-d', time()); $columns = isset($file[0]) ? $file[0] : NULL; if (empty($columns) || !empty($columns) && $columns[0] == '') { $json['error'] = CSV_INVAILD_FILE; wp_send_json($json); } for ($i = 1; $i <= $limit; $i++) { $index = $processed + $i; $gd_post = array(); if (isset($file[$index])) { $row = $file[$index]; $row = array_map('trim', $row); $row = array_map('utf8_encode', $row); $row = array_map('addslashes_gpc', $row); $post_id = ''; $post_title = ''; $post_author = ''; $post_content = ''; $post_category_arr = array(); $post_tags = array(); $post_type = ''; $post_status = ''; $geodir_video = ''; $post_address = ''; $post_city = ''; $post_region = ''; $post_country = ''; $post_zip = ''; $post_latitude = ''; $post_longitude = ''; $geodir_timing = ''; $geodir_contact = ''; $geodir_email = ''; $geodir_website = ''; $geodir_twitter = ''; $geodir_facebook = ''; $geodir_twitter = ''; $post_images = array(); $expire_date = 'Never'; $language = ''; $original_post_id = ''; $c = 0; foreach ($columns as $column) { $gd_post[$column] = $row[$c]; if ($column == 'post_id') { $post_id = $row[$c]; } else { if ($column == 'post_title') { $post_title = $row[$c]; } else { if ($column == 'post_author') { $post_author = $row[$c]; } else { if ($column == 'post_content') { $post_content = $row[$c]; } else { if ($column == 'post_category' && $row[$c] != '') { $post_category_arr = explode(',', $row[$c]); } else { if ($column == 'post_tags' && $row[$c] != '') { $post_tags = explode(',', $row[$c]); } else { if ($column == 'post_type') { $post_type = $row[$c]; } else { if ($column == 'post_status') { $post_status = sanitize_key($row[$c]); } else { if ($column == 'is_featured') { $is_featured = (int) $row[$c]; } else { if ($column == 'geodir_video') { $geodir_video = $row[$c]; } else { if ($column == 'post_address') { $post_address = $row[$c]; } else { if ($column == 'post_city') { $post_city = $row[$c]; } else { if ($column == 'post_region') { $post_region = $row[$c]; } else { if ($column == 'post_country') { $post_country = $row[$c]; } else { if ($column == 'post_zip') { $post_zip = $row[$c]; } else { if ($column == 'post_latitude') { $post_latitude = $row[$c]; } else { if ($column == 'post_longitude') { $post_longitude = $row[$c]; } else { if ($column == 'geodir_timing') { $geodir_timing = $row[$c]; } else { if ($column == 'geodir_contact') { $geodir_contact = $row[$c]; } else { if ($column == 'geodir_email') { $geodir_email = $row[$c]; } else { if ($column == 'geodir_website') { $geodir_website = $row[$c]; } else { if ($column == 'geodir_twitter') { $geodir_twitter = $row[$c]; } else { if ($column == 'geodir_facebook') { $geodir_facebook = $row[$c]; } else { if ($column == 'geodir_twitter') { $geodir_twitter = $row[$c]; } else { if ($column == 'IMAGE' && !empty($row[$c]) && $row[$c] != '') { $post_images[] = $row[$c]; } else { if ($column == 'alive_days' && (int) $row[$c] > 0) { $expire_date = date_i18n('Y-m-d', strtotime($current_date . '+' . (int) $row[$c] . ' days')); } else { if ($column == 'expire_date' && $row[$c] != '' && strtolower($row[$c]) != 'never') { $row[$c] = str_replace('/', '-', $row[$c]); $expire_date = date_i18n('Y-m-d', strtotime($row[$c])); } } } } } } } } } } } } } } } } } } } } } } } } } } } // WPML if ($is_wpml) { if ($column == 'language') { $language = strtolower(trim($row[$c])); } else { if ($column == 'original_post_id') { $original_post_id = (int) $row[$c]; } } } // WPML $c++; } // WPML if ($is_wpml && $language != '') { $sitepress->switch_lang($language, true); } // WPML $gd_post['IMAGE'] = $post_images; $post_status = !empty($post_status) ? sanitize_key($post_status) : $default_status; $post_status = !empty($wp_post_statuses) && !isset($wp_post_statuses[$post_status]) ? $default_status : $post_status; $valid = true; if ($post_title == '' || !in_array($post_type, $post_types)) { $invalid++; $valid = false; } $location_allowed = function_exists('geodir_cpt_no_location') && geodir_cpt_no_location($post_type) ? false : true; if ($location_allowed) { $location_result = geodir_get_default_location(); if ($post_address == '' || $post_city == '' || $post_region == '' || $post_country == '' || $post_latitude == '' || $post_longitude == '') { $invalid_addr++; $valid = false; } else { if (!empty($location_result) && $location_result->location_id == 0) { if (strtolower($post_city) != strtolower($location_result->city) || strtolower($post_region) != strtolower($location_result->region) || strtolower($post_country) != strtolower($location_result->country)) { $invalid_addr++; $valid = false; } else { if (!function_exists('geodir_location_plugin_activated')) { $gd_post['post_locations'] = '[' . $location_result->city_slug . '],[' . $location_result->region_slug . '],[' . $location_result->country_slug . ']'; // Set the default location when location manager not activated. } } } } } if (!$valid) { continue; } $cat_taxonomy = $post_type . 'category'; $tags_taxonomy = $post_type . '_tags'; $post_category = array(); if (!empty($post_category_arr)) { foreach ($post_category_arr as $value) { $category_name = wp_kses_normalize_entities(trim($value)); if ($category_name != '') { $term_category = array(); if ($term = get_term_by('name', $category_name, $cat_taxonomy)) { $term_category = $term; } else { if ($term = get_term_by('slug', $category_name, $cat_taxonomy)) { $term_category = $term; } else { $term_data = array(); $term_data['name'] = $category_name; $term_data = array_map('utf8_encode', $term_data); $term_data['taxonomy'] = $cat_taxonomy; $term_id = geodir_imex_insert_term($cat_taxonomy, $term_data); if ($term_id) { $term_category = get_term($term_id, $cat_taxonomy); } } } if (!empty($term_category) && !is_wp_error($term_category)) { //$post_category[] = $term_category->slug; $post_category[] = intval($term_category->term_id); } } } } $save_post = array(); $save_post['post_title'] = $post_title; $save_post['post_content'] = $post_content; $save_post['post_type'] = $post_type; $save_post['post_author'] = $post_author; $save_post['post_status'] = $post_status; $save_post['post_category'] = $post_category; $save_post['post_tags'] = $post_tags; $saved_post_id = NULL; if ($import_choice == 'update') { if ($post_id > 0 && get_post($post_id)) { $save_post['ID'] = $post_id; if (wp_update_post($save_post)) { $saved_post_id = $post_id; $updated++; } } else { if ($saved_post_id = wp_insert_post($save_post)) { $created++; } } if (!$saved_post_id > 0) { $invalid++; } } else { if ($import_choice == 'skip') { if ($post_id > 0 && get_post($post_id)) { $skipped++; } else { if ($saved_post_id = wp_insert_post($save_post)) { $created++; } else { $invalid++; } } } else { $invalid++; } } if ((int) $saved_post_id > 0) { // WPML if ($is_wpml && $original_post_id > 0 && $language != '') { $wpml_post_type = 'post_' . $post_type; $source_language = geodir_get_language_for_element($original_post_id, $wpml_post_type); $source_language = $source_language != '' ? $source_language : $sitepress->get_default_language(); $trid = $sitepress->get_element_trid($original_post_id, $wpml_post_type); $sitepress->set_element_language_details($saved_post_id, $wpml_post_type, $trid, $language, $source_language); } // WPML $gd_post_info = geodir_get_post_info($saved_post_id); $gd_post['post_id'] = $saved_post_id; $gd_post['ID'] = $saved_post_id; $gd_post['post_tags'] = $post_tags; $gd_post['post_title'] = $post_title; $gd_post['post_status'] = $post_status; $gd_post['submit_time'] = time(); $gd_post['submit_ip'] = $_SERVER['REMOTE_ADDR']; // post location $post_location_id = 0; if ($location_allowed && !empty($location_result) && $location_result->location_id > 0) { $post_location_info = array('city' => $post_city, 'region' => $post_region, 'country' => $post_country, 'geo_lat' => $post_latitude, 'geo_lng' => $post_longitude); if ($location_id = (int) geodir_add_new_location($post_location_info)) { $post_location_id = $location_id; } } $gd_post['post_location_id'] = $post_location_id; // post package info $package_id = isset($gd_post['package_id']) && !empty($gd_post['package_id']) ? (int) $gd_post['package_id'] : 0; if (!$package_id && !empty($gd_post_info) && isset($gd_post_info->package_id) && $gd_post_info->package_id) { $package_id = $gd_post_info->package_id; } $package_info = array(); if ($package_id && function_exists('geodir_get_package_info_by_id')) { $package_info = (array) geodir_get_package_info_by_id($package_id); if (!(!empty($package_info) && isset($package_info['post_type']) && $package_info['post_type'] == $post_type)) { $package_info = array(); } } if (empty($package_info)) { $package_info = (array) geodir_post_package_info(array(), '', $post_type); } if (!empty($package_info)) { $package_id = $package_info['pid']; if (isset($gd_post['alive_days']) || isset($gd_post['expire_date'])) { $gd_post['expire_date'] = $expire_date; } else { if (isset($package_info['days']) && (int) $package_info['days'] > 0) { $gd_post['alive_days'] = (int) $package_info['days']; $gd_post['expire_date'] = date_i18n('Y-m-d', strtotime($current_date . '+' . (int) $package_info['days'] . ' days')); } else { $gd_post['expire_date'] = 'Never'; } } $gd_post['package_id'] = $package_id; } $table = $plugin_prefix . $post_type . '_detail'; if ($post_type == 'gd_event') { $gd_post = geodir_imex_process_event_data($gd_post); } if (isset($gd_post['post_id'])) { unset($gd_post['post_id']); } // Export franchise fields $is_franchise_active = is_plugin_active('geodir_franchise/geodir_franchise.php') && geodir_franchise_enabled($post_type) ? true : false; if ($is_franchise_active) { if (isset($gd_post['gd_is_franchise']) && (int) $gd_post['gd_is_franchise'] == 1) { $gd_franchise_lock = array(); if (isset($gd_post['gd_franchise_lock'])) { $gd_franchise_lock = str_replace(" ", "", $gd_post['gd_franchise_lock']); $gd_franchise_lock = trim($gd_franchise_lock); $gd_franchise_lock = explode(",", $gd_franchise_lock); } update_post_meta($saved_post_id, 'gd_is_franchise', 1); update_post_meta($saved_post_id, 'gd_franchise_lock', $gd_franchise_lock); } else { if (isset($gd_post['franchise']) && (int) $gd_post['franchise'] > 0 && geodir_franchise_check((int) $gd_post['franchise'])) { geodir_save_post_meta($saved_post_id, 'franchise', (int) $gd_post['franchise']); } } } if (!empty($save_post['post_category']) && is_array($save_post['post_category'])) { $save_post['post_category'] = array_unique(array_map('intval', $save_post['post_category'])); $gd_post[$cat_taxonomy] = $save_post['post_category']; } // Save post info geodir_save_post_info($saved_post_id, $gd_post); // post taxonomies if (!empty($save_post['post_category'])) { wp_set_object_terms($saved_post_id, $save_post['post_category'], $cat_taxonomy); $post_default_category = isset($save_post['post_default_category']) ? $save_post['post_default_category'] : ''; $post_category_str = isset($save_post['post_category_str']) ? $save_post['post_category_str'] : ''; geodir_set_postcat_structure($saved_post_id, $cat_taxonomy, $post_default_category, $post_category_str); } if (!empty($save_post['post_tags'])) { wp_set_object_terms($saved_post_id, $save_post['post_tags'], $tags_taxonomy); } // Post images if (!empty($post_images)) { $post_images = array_unique($post_images); $old_post_images_arr = array(); $saved_post_images_arr = array(); $order = 1; $old_post_images = geodir_get_images($saved_post_id); if (!empty($old_post_images)) { foreach ($old_post_images as $old_post_image) { if (!empty($old_post_image) && isset($old_post_image->file) && $old_post_image->file != '') { $old_post_images_arr[] = $old_post_image->file; } } } foreach ($post_images as $post_image) { $image_name = basename($post_image); $saved_post_images_arr[] = $image_name; if (!empty($old_post_images_arr) && in_array($image_name, $old_post_images_arr)) { continue; // Skip if image already exists. } $image_name_parts = explode('.', $image_name); array_pop($image_name_parts); $proper_image_name = implode('.', $image_name_parts); $arr_file_type = wp_check_filetype($image_name); if (!empty($arr_file_type)) { $uploaded_file_type = $arr_file_type['type']; $attachment = array(); $attachment['post_id'] = $saved_post_id; $attachment['title'] = $proper_image_name; $attachment['content'] = ''; $attachment['file'] = $uploads_subdir . '/' . $image_name; $attachment['mime_type'] = $uploaded_file_type; $attachment['menu_order'] = $order; $attachment['is_featured'] = 0; $attachment_set = ''; foreach ($attachment as $key => $val) { if ($val != '') { $attachment_set .= $key . " = '" . $val . "', "; } } $attachment_set = trim($attachment_set, ", "); // Add new attachment $wpdb->query("INSERT INTO " . GEODIR_ATTACHMENT_TABLE . " SET " . $attachment_set); $order++; } } $saved_post_images_sql = !empty($saved_post_images_arr) ? " AND ( file NOT LIKE '%/" . implode("' AND file NOT LIKE '%/", $saved_post_images_arr) . "' )" : ''; // Remove previous attachment $wpdb->query("DELETE FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE post_id = " . (int) $saved_post_id . " " . $saved_post_images_sql); if (!empty($saved_post_images_arr)) { $menu_order = 1; foreach ($saved_post_images_arr as $img_name) { $wpdb->query($wpdb->prepare("UPDATE " . GEODIR_ATTACHMENT_TABLE . " SET menu_order = %d WHERE post_id =%d AND file LIKE %s", array($menu_order, $saved_post_id, '%/' . $img_name))); if ($menu_order == 1) { if ($featured_image = $wpdb->get_var($wpdb->prepare("SELECT file FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE post_id =%d AND file LIKE %s", array($saved_post_id, '%/' . $img_name)))) { $wpdb->query($wpdb->prepare("UPDATE " . $table . " SET featured_image = %s WHERE post_id =%d", array($featured_image, $saved_post_id))); } } $menu_order++; } } if ($order > 1) { $images++; } } /** This action is documented in geodirectory-functions/post-functions.php */ do_action('geodir_after_save_listing', $saved_post_id, $gd_post); if (isset($is_featured)) { geodir_save_post_meta($saved_post_id, 'is_featured', $is_featured); } if (isset($gd_post['expire_date'])) { geodir_save_post_meta($saved_post_id, 'expire_date', $gd_post['expire_date']); } } // WPML if ($is_wpml && $language != '') { $sitepress->switch_lang($active_lang, true); } // WPML } } } $json = array(); $json['processed'] = $limit; $json['created'] = $created; $json['updated'] = $updated; $json['skipped'] = $skipped; $json['invalid'] = $invalid; $json['invalid_addr'] = $invalid_addr; $json['images'] = $images; wp_send_json($json); } } break; } echo '0'; wp_die(); }
function geodir_cp_from_submit_handler() { global $plugin_prefix, $wpdb; if (isset($_REQUEST['geodir_save_post_type'])) { $custom_post_type = trim($_REQUEST['geodir_custom_post_type']); $listing_slug = trim($_REQUEST['geodir_listing_slug']); $listing_order = trim($_REQUEST['geodir_listing_order']); $categories = $_REQUEST['geodir_categories']; $tags = isset($_REQUEST['geodir_tags']) ? $_REQUEST['geodir_tags'] : ''; $name = $_REQUEST['geodir_name']; //htmlentities(trim($_REQUEST['geodir_name'])); $singular_name = trim($_REQUEST['geodir_singular_name']); $add_new = trim($_REQUEST['geodir_add_new']); $add_new_item = trim($_REQUEST['geodir_add_new_item']); $edit_item = trim($_REQUEST['geodir_edit_item']); $new_item = trim($_REQUEST['geodir_new_item']); $view_item = trim($_REQUEST['geodir_view_item']); $search_item = trim($_REQUEST['geodir_search_item']); $not_found = trim($_REQUEST['geodir_not_found']); $not_found_trash = trim($_REQUEST['geodir_not_found_trash']); $support = $_REQUEST['geodir_support']; $description = trim($_REQUEST['geodir_description']); $menu_icon = trim($_REQUEST['geodir_menu_icon']); $can_export = $_REQUEST['geodir_can_export']; $geodir_cp_meta_keyword = $_REQUEST['geodir_cp_meta_keyword']; $geodir_cp_meta_description = $_REQUEST['geodir_cp_meta_description']; $label_post_profile = stripslashes_deep(normalize_whitespace($_REQUEST['geodir_label_post_profile'])); $label_post_info = stripslashes_deep(normalize_whitespace($_REQUEST['geodir_label_post_info'])); $label_post_images = stripslashes_deep(normalize_whitespace($_REQUEST['geodir_label_post_images'])); $label_post_map = stripslashes_deep(normalize_whitespace($_REQUEST['geodir_label_post_map'])); $label_reviews = stripslashes_deep(normalize_whitespace($_REQUEST['geodir_label_reviews'])); $label_related_listing = stripslashes_deep(normalize_whitespace($_REQUEST['geodir_label_related_listing'])); $cpt_image = isset($_FILES['geodir_cpt_img']) && !empty($_FILES['geodir_cpt_img']) ? $_FILES['geodir_cpt_img'] : NULL; $cpt_image_remove = isset($_POST['geodir_cpt_img_remove']) ? $_POST['geodir_cpt_img_remove'] : false; if ($can_export == 'true') { $can_export = true; } else { $can_export = false; } $custom_post_type = geodir_clean($custom_post_type); // erase special characters from string $listing_slug = geodir_clean($listing_slug); // erase special characters from string if (isset($_REQUEST['posttype']) && $_REQUEST['posttype'] != '') { $geodir_post_types = get_option('geodir_post_types'); $post_type_array = $geodir_post_types[$_REQUEST['posttype']]; } if ($custom_post_type != '' && $listing_slug != '') { if (empty($post_type_array)) { $is_custom = 1; //check post type create by custom or any other add-once $posttypes_array = get_option('geodir_post_types'); $post_type = $custom_post_type; $custom_post_type = 'gd_' . $custom_post_type; if (array_key_exists($custom_post_type, $posttypes_array)) { $error[] = __('Post Type already exists.', GEODIR_CP_TEXTDOMAIN); } foreach ($posttypes_array as $key => $value) { if ($value['has_archive'] == $listing_slug) { $error[] = __('Listing Slug already exists.', GEODIR_CP_TEXTDOMAIN); break; } } } else { $post_type = preg_replace('/gd_/', '', $_REQUEST['posttype'], 1); $custom_post_type = $_REQUEST['posttype']; $is_custom = isset($post_type_array['is_custom']) ? $post_type_array['is_custom'] : ''; /*check post type create by custom or any other add-once */ //Edit case check duplicate listing slug if ($post_type_array['has_archive'] != $listing_slug) { $posttypes_array = get_option('geodir_post_types'); foreach ($posttypes_array as $key => $value) { if ($value['has_archive'] == $listing_slug) { $error[] = __('Listing Slug already exists.', GEODIR_CP_TEXTDOMAIN); break; } } } } if (empty($error)) { /** * Include any functions needed for upgrades. * * @since 1.1.7 */ require_once ABSPATH . 'wp-admin/includes/upgrade.php'; if (!empty($post_type_array)) { if (!$categories) { $geodir_taxonomies = get_option('geodir_taxonomies'); if (array_key_exists($custom_post_type . 'category', $geodir_taxonomies)) { unset($geodir_taxonomies[$custom_post_type . 'category']); update_option('geodir_taxonomies', $geodir_taxonomies); } } if (!$tags) { $geodir_taxonomies = get_option('geodir_taxonomies'); if (array_key_exists($custom_post_type . '_tags', $geodir_taxonomies)) { unset($geodir_taxonomies[$custom_post_type . '_tags']); update_option('geodir_taxonomies', $geodir_taxonomies); } } } $taxonomies = array(); if ($categories) { $taxonomies[] = $custom_post_type . 'category'; $categories = $custom_post_type . 'category'; } if ($tags) { $taxonomies[] = $custom_post_type . '_tags'; $tags = $custom_post_type . '_tags'; } if ($categories) { $gd_placecategory = array(); $gd_placecategory['object_type'] = $custom_post_type; $gd_placecategory['listing_slug'] = $listing_slug; $gd_placecategory['args'] = array('public' => true, 'hierarchical' => true, 'rewrite' => array('slug' => $listing_slug, 'with_front' => false, 'hierarchical' => true), 'query_var' => true, 'labels' => array('name' => __(ucfirst($post_type) . ' Categories', GEODIR_CP_TEXTDOMAIN), 'singular_name' => __(ucfirst($post_type) . ' Category', GEODIR_CP_TEXTDOMAIN), 'search_items' => __('Search ' . ucfirst($post_type) . ' Categories', GEODIR_CP_TEXTDOMAIN), 'popular_items' => __('Popular ' . ucfirst($post_type) . ' Categories', GEODIR_CP_TEXTDOMAIN), 'all_items' => __('All ' . ucfirst($post_type) . ' Categories', GEODIR_CP_TEXTDOMAIN), 'edit_item' => __('Edit ' . ucfirst($post_type) . ' Category', GEODIR_CP_TEXTDOMAIN), 'update_item' => __('Update ' . ucfirst($post_type) . ' Category', GEODIR_CP_TEXTDOMAIN), 'add_new_item' => __('Add New ' . ucfirst($post_type) . ' Category', GEODIR_CP_TEXTDOMAIN), 'new_item_name' => __('New ' . ucfirst($post_type) . ' Category', GEODIR_CP_TEXTDOMAIN), 'add_or_remove_items' => __('Add or remove ' . ucfirst($post_type) . ' categories', GEODIR_CP_TEXTDOMAIN)), 'show_in_nav_menus' => !empty($_REQUEST['geodir_disable_nav_menus']['cats']) ? 0 : 1); $geodir_taxonomies = get_option('geodir_taxonomies'); $geodir_taxonomies[$categories] = $gd_placecategory; update_option('geodir_taxonomies', $geodir_taxonomies); } if ($tags) { $gd_placetags = array(); $gd_placetags['object_type'] = $custom_post_type; $gd_placetags['listing_slug'] = $listing_slug . '/tags'; $gd_placetags['args'] = array('public' => true, 'hierarchical' => false, 'rewrite' => array('slug' => $listing_slug . '/tags', 'with_front' => false, 'hierarchical' => false), 'query_var' => true, 'labels' => array('name' => __(ucfirst($post_type) . ' Tags', GEODIR_CP_TEXTDOMAIN), 'singular_name' => __(ucfirst($post_type) . ' Tag', GEODIR_CP_TEXTDOMAIN), 'search_items' => __('Search ' . ucfirst($post_type) . ' Tags', GEODIR_CP_TEXTDOMAIN), 'popular_items' => __('Popular ' . ucfirst($post_type) . ' Tags', GEODIR_CP_TEXTDOMAIN), 'all_items' => __('All ' . ucfirst($post_type) . ' Tags', GEODIR_CP_TEXTDOMAIN), 'edit_item' => __('Edit ' . ucfirst($post_type) . ' Tag', GEODIR_CP_TEXTDOMAIN), 'update_item' => __('Update ' . ucfirst($post_type) . ' Tag', GEODIR_CP_TEXTDOMAIN), 'add_new_item' => __('Add New ' . ucfirst($post_type) . ' Tag', GEODIR_CP_TEXTDOMAIN), 'new_item_name' => __('New ' . ucfirst($post_type) . ' Tag Name', GEODIR_CP_TEXTDOMAIN), 'add_or_remove_items' => __('Add or remove ' . ucfirst($post_type) . ' tags', GEODIR_CP_TEXTDOMAIN), 'choose_from_most_used' => __('Choose from the most used ' . ucfirst($post_type) . ' tags', GEODIR_CP_TEXTDOMAIN), 'separate_items_with_commas' => __('Separate ' . ucfirst($post_type) . ' tags with commas', GEODIR_CP_TEXTDOMAIN)), 'show_in_nav_menus' => !empty($_REQUEST['geodir_disable_nav_menus']['tags']) ? 0 : 1); $geodir_taxonomies = get_option('geodir_taxonomies'); $geodir_taxonomies[$tags] = $gd_placetags; update_option('geodir_taxonomies', $geodir_taxonomies); } if (empty($name)) { $name = __(ucfirst($post_type), GEODIR_CP_TEXTDOMAIN); } if (empty($singular_name)) { $singular_name = __(ucfirst($post_type), GEODIR_CP_TEXTDOMAIN); } if (empty($add_new)) { $add_new = __('Add New ' . ucfirst($post_type), GEODIR_CP_TEXTDOMAIN); } if (empty($add_new_item)) { $add_new_item = __('Add New Item', GEODIR_CP_TEXTDOMAIN); } if (empty($edit_item)) { $edit_item = __('Edit Item', GEODIR_CP_TEXTDOMAIN); } if (empty($new_item)) { $new_item = __('New Item', GEODIR_CP_TEXTDOMAIN); } if (empty($view_item)) { $view_item = __('View Item', GEODIR_CP_TEXTDOMAIN); } if (empty($search_item)) { $search_item = __('Search Items', GEODIR_CP_TEXTDOMAIN); } if (empty($not_found)) { $not_found = __('Not Found', GEODIR_CP_TEXTDOMAIN); } if (empty($not_found_trash)) { $not_found_trash = __('Not Found In Trash', GEODIR_CP_TEXTDOMAIN); } $labels = array('name' => ucfirst($name), 'singular_name' => ucfirst($singular_name), 'add_new' => ucfirst($add_new), 'add_new_item' => ucfirst($add_new_item), 'edit_item' => ucfirst($edit_item), 'new_item' => ucfirst($new_item), 'view_item' => ucfirst($view_item), 'search_items' => ucfirst($search_item), 'not_found' => ucfirst($not_found), 'not_found_in_trash' => ucfirst($not_found_trash), 'label_post_profile' => $label_post_profile, 'label_post_info' => $label_post_info, 'label_post_images' => $label_post_images, 'label_post_map' => $label_post_map, 'label_reviews' => $label_reviews, 'label_related_listing' => $label_related_listing); $place_default = array('labels' => $labels, 'can_export' => $can_export, 'capability_type' => 'post', 'description' => $description, 'has_archive' => $listing_slug, 'hierarchical' => false, 'map_meta_cap' => true, 'menu_icon' => apply_filters('geodir_custom_post_type_default_menu_icon', $menu_icon), 'public' => true, 'query_var' => true, 'rewrite' => array('slug' => $listing_slug, 'with_front' => false, 'hierarchical' => true), 'supports' => $support, 'taxonomies' => $taxonomies, 'is_custom' => $is_custom, 'listing_order' => $listing_order, 'seo' => array('meta_keyword' => $geodir_cp_meta_keyword, 'meta_description' => $geodir_cp_meta_description), 'show_in_nav_menus' => !empty($_REQUEST['geodir_disable_nav_menus']['posts']) ? 0 : 1); update_option('temp_post_type', $place_default); $geodir_post_types = get_option('geodir_post_types'); $geodir_post_types[$custom_post_type] = $place_default; update_option('geodir_post_types', $geodir_post_types); //ADD NEW CUSTOM POST TYPE IN SHOW POST TYPE NAVIGATIONS if (!isset($_REQUEST['posttype'])) { $get_posttype_settings_options = array('geodir_add_posttype_in_listing_nav', 'geodir_allow_posttype_frontend', 'geodir_add_listing_link_add_listing_nav', 'geodir_add_listing_link_user_dashboard', 'geodir_listing_link_user_dashboard', 'geodir_favorite_link_user_dashboard'); foreach ($get_posttype_settings_options as $get_posttype_settings_options_obj) { $geodir_post_types_listing = get_option($get_posttype_settings_options_obj); if (empty($geodir_post_types_listing) || is_array($geodir_post_types_listing) && !in_array($custom_post_type, $geodir_post_types_listing)) { $geodir_post_types_listing[] = $custom_post_type; update_option($get_posttype_settings_options_obj, $geodir_post_types_listing); } } } // Save post types in default table if (empty($post_type_array)) { $geodir_custom_post_types = get_option('geodir_custom_post_types'); if (!$geodir_custom_post_types) { $geodir_custom_post_types = array(); } if (!array_key_exists($custom_post_type, $geodir_custom_post_types)) { $geodir_custom_post_types[$custom_post_type] = $custom_post_type; update_option('geodir_custom_post_types', $geodir_custom_post_types); } } // Table for storing custom post type attribute - these are user defined $collate = ''; if ($wpdb->has_cap('collation')) { if (!empty($wpdb->charset)) { $collate = "DEFAULT CHARACTER SET {$wpdb->charset}"; } if (!empty($wpdb->collate)) { $collate .= " COLLATE {$wpdb->collate}"; } } $newtable_name = $plugin_prefix . $custom_post_type . '_detail'; $newposttype_detail = "CREATE TABLE IF NOT EXISTS " . $newtable_name . " (\n\t\t\t\t\t\t\t\t\t\t`post_id` int(11) NOT NULL,\n\t\t\t\t\t\t\t\t\t\t`post_title` text NULL DEFAULT NULL,\n\t\t\t\t\t\t\t\t\t\t`post_status` varchar(20) NULL DEFAULT NULL,\n\t\t\t\t\t\t\t\t\t\t`default_category` INT NULL DEFAULT NULL,\n\t\t\t\t\t\t\t\t\t\t`post_tags` text NULL DEFAULT NULL,\n\t\t\t\t\t\t\t\t\t\t`post_location_id` int(11) NOT NULL,\n\t\t\t\t\t\t\t\t\t\t`marker_json` text NULL DEFAULT NULL,\n\t\t\t\t\t\t\t\t\t\t`claimed` ENUM( '1', '0' ) NULL DEFAULT '0',\n\t\t\t\t\t\t\t\t\t\t`businesses` ENUM( '1', '0' ) NULL DEFAULT '0',\n\t\t\t\t\t\t\t\t\t\t`is_featured` ENUM( '1', '0' ) NULL DEFAULT '0',\n\t\t\t\t\t\t\t\t\t\t`featured_image` VARCHAR( 254 ) NULL DEFAULT NULL,\n\t\t\t\t\t\t\t\t\t\t`paid_amount` DOUBLE NOT NULL DEFAULT '0', \n\t\t\t\t\t\t\t\t\t\t`package_id` INT(11) NOT NULL DEFAULT '0',\n\t\t\t\t\t\t\t\t\t\t`alive_days` INT(11) NOT NULL DEFAULT '0',\n\t\t\t\t\t\t\t\t\t\t`paymentmethod` varchar(30) NULL DEFAULT NULL,\n\t\t\t\t\t\t\t\t\t\t`expire_date` VARCHAR( 100 ) NULL DEFAULT NULL,\n\t\t\t\t\t\t\t\t\t\t`submit_time` varchar(25) NULL DEFAULT NULL,\n\t\t\t\t\t\t\t\t\t\t`submit_ip` varchar(15) NULL DEFAULT NULL,\n\t\t\t\t\t\t\t\t\t\t`overall_rating` float(11) DEFAULT NULL, \n\t\t\t\t\t\t\t\t\t\t`rating_count` INT(11) DEFAULT '0',\n\t\t\t\t\t\t\t\t\t\t`post_locations` VARCHAR( 254 ) NULL DEFAULT NULL,\n\t\t\t\t\t\t\t\t\t\tPRIMARY KEY (`post_id`)) {$collate} "; dbDelta($newposttype_detail); do_action('geodir_after_custom_detail_table_create', $custom_post_type, $newtable_name); $package_info = array(); /*$package_info = apply_filters('geodir_post_package_info' , $package_info , '', $custom_post_type); $package_id = $package_info->pid;*/ $package_info = geodir_post_package_info($package_info, '', $custom_post_type); $package_id = $package_info->pid; if (!$wpdb->get_var($wpdb->prepare("SELECT id FROM " . GEODIR_CUSTOM_FIELDS_TABLE . " WHERE FIND_IN_SET(%s, packages)", array($package_id)))) { $table = $plugin_prefix . $custom_post_type . '_detail'; $wpdb->query($wpdb->prepare("UPDATE " . $table . " SET package_id=%d", array($package_id))); $wpdb->query($wpdb->prepare("UPDATE " . GEODIR_CUSTOM_FIELDS_TABLE . " SET packages=%s WHERE post_type=%s", array($package_id, $custom_post_type))); } geodir_cp_create_default_fields($custom_post_type, $package_id); $msg = __('Post type created successfully.', GEODIR_CP_TEXTDOMAIN); if (isset($_REQUEST['posttype']) && $_REQUEST['posttype'] != '') { $msg = __('Post type updated successfully.', GEODIR_CP_TEXTDOMAIN); } /// call the geodirectory core function to register all posttypes again. geodir_register_post_types(); // call the geodirectory core function to register all taxonomies again. geodir_register_taxonomies(); geodir_flush_rewrite_rules(); geodir_set_user_defined_order(); // Save CPT image $uploads = wp_upload_dir(); // if remove is set then remove the file if ($cpt_image_remove) { if (get_option('geodir_cpt_img_' . $custom_post_type)) { $image_name_arr = explode('/', get_option('geodir_cpt_img_' . $custom_post_type)); $img_path = $uploads['path'] . '/' . end($image_name_arr); if (file_exists($img_path)) { unlink($img_path); } } update_option('geodir_cpt_img_' . $custom_post_type, ''); } if ($cpt_image) { $tmp_name = isset($cpt_image['tmp_name']) ? $cpt_image['tmp_name'] : ''; $filename = isset($cpt_image['name']) ? $cpt_image['name'] : ''; $ext = pathinfo($filename, PATHINFO_EXTENSION); $uplaods = array(); $uplaods[] = $tmp_name; $allowed_file_types = array('jpg' => 'image/jpg', 'jpeg' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png'); $upload_overrides = array('test_form' => false, 'mimes' => $allowed_file_types); $cpt_img = wp_handle_upload($cpt_image, $upload_overrides); if (!empty($cpt_img) && !empty($cpt_img['url'])) { if (get_option('geodir_cpt_img_' . $custom_post_type)) { $image_name_arr = explode('/', get_option('geodir_cpt_img_' . $custom_post_type)); $img_path = $uploads['path'] . '/' . end($image_name_arr); if (file_exists($img_path)) { unlink($img_path); } } // set width and height $w = apply_filters('geodir_cpt_img_width', 300); // get large size width $h = apply_filters('geodir_cpt_img_height', 300); // get large size width // get the uploaded image $cpt_img_file = wp_get_image_editor($cpt_img['file']); // if no error if (!is_wp_error($cpt_img_file)) { // get image width and height $size = getimagesize($cpt_img['file']); // $size[0] = width, $size[1] = height if ($size[0] > $w || $size[1] > $h) { // if the width or height is larger than the large-size $cpt_img_file->resize($w, $h, false); // resize the image $final_image = $cpt_img_file->save($cpt_img['file']); // save the resized image } } update_option('geodir_cpt_img_' . $custom_post_type, $cpt_img['url']); } } $msg = urlencode($msg); $redirect_to = admin_url() . 'admin.php?page=geodirectory&tab=geodir_manage_custom_posts&cp_success=' . $msg; wp_redirect($redirect_to); exit; } else { global $cp_error; foreach ($error as $err) { $cp_error .= '<div id="message" style="color:#FF0000;" class="updated fade"><p><strong>' . $err . '</strong></p></div>'; } } } } if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'cp_delete') { if ($_REQUEST['posttype']) { $geodir_taxonomies = get_option('geodir_taxonomies'); if (array_key_exists($_REQUEST['posttype'] . 'category', $geodir_taxonomies)) { unset($geodir_taxonomies[$_REQUEST['posttype'] . 'category']); update_option('geodir_taxonomies', $geodir_taxonomies); } if (array_key_exists($_REQUEST['posttype'] . '_tags', $geodir_taxonomies)) { unset($geodir_taxonomies[$_REQUEST['posttype'] . '_tags']); update_option('geodir_taxonomies', $geodir_taxonomies); } $geodir_post_types = get_option('geodir_post_types'); if (array_key_exists($_REQUEST['posttype'], $geodir_post_types)) { unset($geodir_post_types[$_REQUEST['posttype']]); update_option('geodir_post_types', $geodir_post_types); } //UPDATE SHOW POST TYPES NAVIGATION OPTIONS $get_posttype_settings_options = array('geodir_add_posttype_in_listing_nav', 'geodir_allow_posttype_frontend', 'geodir_add_listing_link_add_listing_nav', 'geodir_add_listing_link_user_dashboard', 'geodir_listing_link_user_dashboard', 'geodir_favorite_link_user_dashboard'); foreach ($get_posttype_settings_options as $get_posttype_settings_options_obj) { $geodir_post_types_listing = get_option($get_posttype_settings_options_obj); if (in_array($_REQUEST['posttype'], $geodir_post_types_listing)) { $geodir_update_post_type_nav = array_diff($geodir_post_types_listing, array($_REQUEST['posttype'])); update_option($get_posttype_settings_options_obj, $geodir_update_post_type_nav); } } //END CODE OPTIONS geodir_flush_rewrite_rules(); $msg = __('Post type deleted successfully.', GEODIR_CP_TEXTDOMAIN); $msg = urlencode($msg); $redirect_to = admin_url() . 'admin.php?page=geodirectory&tab=geodir_manage_custom_posts&confirm=true&geodir_customposttype=' . $_REQUEST['posttype'] . '&cp_success=' . $msg; wp_redirect($redirect_to); exit; } } }
<?php /** * Template for the details page sidebar for the add listing preview page ONLY. * * You can make most changes via hooks or see the link below for info on how to replace the template in your theme. * * @link http://docs.wpgeodirectory.com/customizing-geodirectory-templates/ * @since 1.0.0 * @package GeoDirectory * @global object $post The current post object. * @global object $post_images Image objects of current post if available. */ global $post, $preview, $post_images; $package_info = array(); $package_info = geodir_post_package_info($package_info, $post); if (isset($package_info->google_analytics)) { $package_info->google_analytics = false; } $html = ''; ?> <div id="gd-sidebar-wrapper"> <div class="geodir-sidebar-main"> <?php ob_start(); ?> <div class="geodir-gd-sidebar"> <?php ob_start(); /** This action is documented in geodirectory_template_actions.php */ do_action('geodir_detail_page_sidebar');