コード例 #1
0
function geodir_claim_listing_information()
{
    global $post, $post_id;
    wp_nonce_field(plugin_basename(__FILE__), 'geodir_post_claim_setting_noncename');
    $is_claimed = geodir_get_post_meta($post_id, 'claimed', true);
    ?>
	
    <div class="geodir-claim-section">
		
        <h4 style="display:inline;"><?php 
    echo CLAIM_IS_CLAIMED;
    ?>
</h4>
				
        <input type="radio" class="gd-checkbox" name="claimed" id="is_claimed_yes" <?php 
    if ($is_claimed == '1') {
        echo 'checked="checked"';
    }
    ?>
  value="1" /> <?php 
    echo CLAIM_YES_TEXT;
    ?>
        <input type="radio" class="gd-checkbox" name="claimed" id="is_claimed_no" <?php 
    if ($is_claimed == '0') {
        echo 'checked="checked"';
    }
    ?>
 value="0" /> <?php 
    echo CLAIM_NO_TEXT;
    ?>
   
    </div><?php 
}
コード例 #2
0
/**
 * Display price package list in claim lisitng form.
 *
 * @since 1.1.4
 *
 * @param  string $field Claim listing field name.
 * @return string Display price package list.
 */
function geodir_claim_after_claim_form_field($field = '')
{
    if ($field == 'geodir_user_comments' && geodir_claim_force_upgrade()) {
        $gd_post_types = geodir_get_posttypes();
        $post_id = isset($_REQUEST['post_id']) ? $_REQUEST['post_id'] : '';
        $post_type = get_post_type($post_id);
        if ($post_type != '' && in_array($post_type, $gd_post_types)) {
            $package_list = geodir_claim_payment_package_list($post_type);
            $payment_methods = geodir_claim_payment_methods();
            if (empty($package_list) || empty($payment_methods)) {
                return;
            }
            $package_id = geodir_get_post_meta('package_id', true);
            if (empty($package_id)) {
                $default_package = geodir_get_default_package($post_type);
                $package_id = $default_package->pid;
            }
            $js_script = '';
            ?>
			<div id="gd_claim_pkgs" class="row clearfix gd-claim-pkgs gd-chosen-outer">
				<label><?php 
            _e('Select Package', GEODIRCLAIM_TEXTDOMAIN);
            ?>
 : <span>*</span></label>
				<select name="geodir_claim_pkg" id="geodir_claim_pkg" field_type="select" class="is_required chosen_select">
				<?php 
            foreach ($package_list as $package) {
                ?>
				<option value="<?php 
                echo $package->pid;
                ?>
"><?php 
                echo stripslashes_deep($package->title_desc);
                ?>
</option>
				<?php 
            }
            ?>
				</select>
				<span class="message_error2" id="geodir_claim_pkgInfo"></span>
			</div>
			<div id="gd_claim_payments" class="row clearfix gd-claim-payments gd-chosen-outer">
				<label><?php 
            _e('Select Payment Method', GEODIRCLAIM_TEXTDOMAIN);
            ?>
 : <span>*</span></label>
				<select name="geodir_claim_payment" id="geodir_claim_payment" field_type="select" class="is_required chosen_select">
				<?php 
            $file_content = '';
            $keys = array();
            foreach ($payment_methods as $payment_method) {
                $keys[] = $payment_method['key'];
                if (file_exists(GEODIR_PAYMENT_MANAGER_PATH . $payment_method['key'] . '/' . $payment_method['key'] . '.php')) {
                    ob_start();
                    include_once GEODIR_PAYMENT_MANAGER_PATH . $payment_method['key'] . '/' . $payment_method['key'] . '.php';
                    $file_content .= ob_get_clean();
                }
                ?>
				<option value="<?php 
                echo $payment_method['key'];
                ?>
"><?php 
                echo stripslashes_deep($payment_method['name']);
                ?>
</option>
				<?php 
            }
            $gd_claim_pmkeys = "['" . implode("', '", $keys) . "']";
            $js_script .= 'jQuery("#geodir_claim_payment").attr("onchange", "javascript:gd_claim_change_pmethod(this, ' . $gd_claim_pmkeys . ');"); jQuery("#geodir_claim_payment").trigger("change");';
            ?>
				</select>
				<span class="message_error2" id="geodir_claim_paymentInfo"></span>
				<?php 
            echo $file_content;
            ?>
				<?php 
            $js_script .= '';
            ?>
			</div>
			<script type="text/javascript"><?php 
            echo $js_script;
            ?>
 jQuery("#geodir_claim_form").addClass('gd-claimfrm-upgrade');jQuery(".chosen_select", "#geodir_claim_form").chosen({"disable_search":true});</script>
			<?php 
        }
    }
}
コード例 #3
0
/**
 * Send enquiry to listing author
 *
 * This function let the user to send Enquiry to listing author. If listing author email not available, then admin email will be used.
 * Email content will be used WP Admin -> Geodirectory -> Notifications -> Other Emails -> Email enquiry
 *
 * @since 1.0.0
 * @package GeoDirectory
 * @global object $wpdb WordPress Database object.
 * @param array $request {
 *    The submitted form fields as an array.
 *
 *    @type string $sendact Enquiry type. Default "send_inqury".
 *    @type string $pid Post ID.
 *    @type string $inq_name Sender name.
 *    @type string $inq_email Sender mail.
 *    @type string $inq_phone Sender phone.
 *    @type string $inq_msg Email message.
 *
 * }
 */
function geodir_send_inquiry($request)
{
    global $wpdb;
    // strip slashes from text
    $request = !empty($request) ? stripslashes_deep($request) : $request;
    $yourname = $request['inq_name'];
    $youremail = $request['inq_email'];
    $inq_phone = $request['inq_phone'];
    $frnd_comments = $request['inq_msg'];
    $pid = $request['pid'];
    $author_id = '';
    $post_title = '';
    if ($request['pid']) {
        $productinfosql = $wpdb->prepare("select ID,post_author,post_title from {$wpdb->posts} where ID =%d", array($request['pid']));
        $productinfo = $wpdb->get_row($productinfosql);
        $author_id = $productinfo->post_author;
        $post_title = $productinfo->post_title;
    }
    $post_title = '<a href="' . get_permalink($pid) . '">' . $post_title . '</a>';
    $user_info = get_userdata($author_id);
    $to_email = geodir_get_post_meta($pid, 'geodir_email', true);
    $to_name = geodir_get_client_name($author_id);
    if ($to_email == '') {
        $to_email = get_option('admin_email');
    }
    /**
     * Called after the send enquiry var have been set but before the email has been sent.
     *
     * @since 1.0.0
     * @param array $request {
     *    The submitted form fields as an array.
     *
     *    @type string $sendact Enquiry type. Default "send_inqury".
     *    @type string $pid Post ID.
     *    @type string $inq_name Sender name.
     *    @type string $inq_email Sender mail.
     *    @type string $inq_phone Sender phone.
     *    @type string $inq_msg Email message.
     *
     * }
     * @param string $type The form type, default: `Enquiry`.
     */
    do_action('geodir_after_send_enquiry', $request, 'Enquiry');
    $client_message = $frnd_comments;
    $client_message .= '<br>' . __('From :', 'geodirectory') . ' ' . $yourname . '<br>' . __('Phone :', 'geodirectory') . ' ' . $inq_phone . '<br>' . __('Email :', 'geodirectory') . ' ' . $youremail . '<br><br>' . __('Sent from', 'geodirectory') . ' - <b><a href="' . trailingslashit(home_url()) . '">' . get_option('blogname') . '</a></b>.';
    /**
     * Filter client message text.
     *
     * @since 1.0.0
     * @param string $client_message Client message text.
     */
    $client_message = apply_filters('geodir_inquiry_email_msg', $client_message);
    /**
     * Called before the send enquiry email is sent.
     *
     * @since 1.0.0
     * @param array $request {
     *    The submitted form fields as an array.
     *
     *    @type string $sendact Enquiry type. Default "send_inqury".
     *    @type string $pid Post ID.
     *    @type string $inq_name Sender name.
     *    @type string $inq_email Sender mail.
     *    @type string $inq_phone Sender phone.
     *    @type string $inq_msg Email message.
     *
     * }
     */
    do_action('geodir_before_send_enquiry_email', $request);
    if ($to_email) {
        // strip slashes message
        $client_message = stripslashes_deep($client_message);
        geodir_sendEmail($youremail, $yourname, $to_email, $to_name, '', $client_message, $extra = '', 'send_enquiry', $request['pid']);
        //To client email
    }
    /**
     * Called after the send enquiry email is sent.
     *
     * @since 1.0.0
     * @param array $request {
     *    The submitted form fields as an array.
     *
     *    @type string $sendact Enquiry type. Default "send_inqury".
     *    @type string $pid Post ID.
     *    @type string $inq_name Sender name.
     *    @type string $inq_email Sender mail.
     *    @type string $inq_phone Sender phone.
     *    @type string $inq_msg Email message.
     *
     * }
     */
    do_action('geodir_after_send_enquiry_email', $request);
    $url = get_permalink($pid);
    if (strstr($url, '?')) {
        $url = $url . "&send_inquiry=success";
    } else {
        $url = $url . "?send_inquiry=success";
    }
    /**
     * Filter redirect url after the send enquiry email is sent.
     *
     * @since 1.0.0
     * @param string $url Redirect url.
     */
    $url = apply_filters('geodir_send_enquiry_after_submit_redirect', $url);
    wp_redirect($url);
    exit;
}
コード例 #4
0
/**
 * Returns permalink structure using post link.
 *
 * @since 1.0.0
 * @package GeoDirectory
 * @global object $wpdb WordPress Database object.
 * @global string $plugin_prefix Geodirectory plugin table prefix.
 * @global object $wp_query WordPress Query object.
 * @global object $post WordPress Post object.
 * @param string $post_link The post link.
 * @param object $post_obj The post object.
 * @param string $leavename Not yet implemented.
 * @param bool $sample Is this a sample post?.
 * @return string The post link.
 */
function geodir_listing_permalink_structure($post_link, $post_obj, $leavename, $sample)
{
    //echo $post_link."<br />".$sample ;
    global $wpdb, $wp_query, $plugin_prefix, $post, $comment_post_cache, $gd_permalink_cache;
    if (isset($post_obj->ID) && isset($post->ID) && $post_obj->ID == $post->ID) {
    } elseif (isset($post_obj->post_status) && $post_obj->post_status == 'auto-draft') {
        return $post_link;
    } else {
        $orig_post = $post;
        $post = $post_obj;
    }
    if (in_array($post->post_type, geodir_get_posttypes())) {
        $post_types = get_option('geodir_post_types');
        $slug = $post_types[$post->post_type]['rewrite']['slug'];
        // Alter the CPT slug if WPML is set to do so
        if (function_exists('icl_object_id')) {
            if (gd_wpml_slug_translation_turned_on($post->post_type) && ($language_code = gd_wpml_get_lang_from_url($post_link))) {
                $org_slug = $slug;
                $slug = apply_filters('wpml_translate_single_string', $slug, 'WordPress', 'URL slug: ' . $slug, $language_code);
                if (!$slug) {
                    $slug = $org_slug;
                }
            }
        }
        // Fix slug problem when slug matches part of host or base url/ Ex: url -> www.abcxyz.com & slug -> xyz.
        $site_url = trailingslashit(get_bloginfo('url'));
        $fix_url = strpos($post_link, $site_url) === 0 ? true : false;
        if ($fix_url) {
            $post_link = str_replace($site_url, '', $post_link);
        }
        $post_link = trailingslashit(preg_replace("/" . preg_quote($slug, "/") . "/", $slug . "/%gd_taxonomy%", $post_link, 1));
        if ($fix_url) {
            $post_link = $site_url . $post_link;
        }
        if (isset($comment_post_cache[$post->ID])) {
            $post = $comment_post_cache[$post->ID];
        }
        if (isset($gd_permalink_cache[$post->ID]) && $gd_permalink_cache[$post->ID] && !$sample) {
            $post_id = $post->ID;
            if (isset($orig_post)) {
                $post = $orig_post;
            }
            return $gd_permalink_cache[$post_id];
        }
        if (!isset($post->post_locations)) {
            $post_type = $post->post_type;
            $ID = $post->ID;
            $post2 = $wpdb->get_row($wpdb->prepare("SELECT * from " . $plugin_prefix . $post->post_type . "_detail WHERE post_id = %d ", array($post->ID)));
            $post = (object) array_merge((array) $post, (array) $post2);
            $comment_post_cache[$post->ID] = $post;
        }
        if (false !== strpos($post_link, '%gd_taxonomy%')) {
            if (apply_filters("geodir_add_location_url_to_url", get_option('geodir_add_location_url'), $post->post_type, $post)) {
                $location_request = '';
                if (!empty($post->post_locations)) {
                    $geodir_arr_locations = explode(',', $post->post_locations);
                    if (count($geodir_arr_locations) == 3) {
                        $post->city_slug = str_replace('[', '', $geodir_arr_locations[0]);
                        $post->city_slug = str_replace(']', '', $post->city_slug);
                        $post->region_slug = str_replace('[', '', $geodir_arr_locations[1]);
                        $post->region_slug = str_replace(']', '', $post->region_slug);
                        $post->country_slug = str_replace('[', '', $geodir_arr_locations[2]);
                        $post->country_slug = str_replace(']', '', $post->country_slug);
                        $post_location = (object) array('country_slug' => $post->country_slug, 'region_slug' => $post->region_slug, 'city_slug' => $post->city_slug);
                    } else {
                        $post_location = geodir_get_location();
                    }
                } else {
                    $post_location_sql = $wpdb->get_results($wpdb->prepare("SELECT post_locations from " . $plugin_prefix . $post->post_type . "_detail WHERE post_id = %d ", array($post->ID)));
                    if (!empty($post_location_sql) && is_array($post_location_sql) && !empty($post_location_sql[0]->post_locations)) {
                        $geodir_arr_locations = explode(',', $post_location_sql[0]->post_locations);
                        if (count($geodir_arr_locations) == 3) {
                            $post->city_slug = str_replace('[', '', $geodir_arr_locations[0]);
                            $post->city_slug = str_replace(']', '', $post->city_slug);
                            $post->region_slug = str_replace('[', '', $geodir_arr_locations[1]);
                            $post->region_slug = str_replace(']', '', $post->region_slug);
                            $post->country_slug = str_replace('[', '', $geodir_arr_locations[2]);
                            $post->country_slug = str_replace(']', '', $post->country_slug);
                            $post_location = (object) array('country_slug' => $post->country_slug, 'region_slug' => $post->region_slug, 'city_slug' => $post->city_slug);
                        }
                    } else {
                        $post_location = geodir_get_location();
                    }
                }
                if (!empty($post_location)) {
                    $country_slug = isset($post_location->country_slug) ? $post_location->country_slug : '';
                    $region_slug = isset($post_location->region_slug) ? $post_location->region_slug : '';
                    $city_slug = isset($post_location->city_slug) ? $post_location->city_slug : '';
                    $geodir_show_location_url = get_option('geodir_show_location_url');
                    $location_slug = array();
                    if ($geodir_show_location_url == 'all') {
                        $location_slug[] = $country_slug;
                        $location_slug[] = $region_slug;
                    } else {
                        if ($geodir_show_location_url == 'country_city') {
                            $location_slug[] = $country_slug;
                        } else {
                            if ($geodir_show_location_url == 'region_city') {
                                $location_slug[] = $region_slug;
                            }
                        }
                    }
                    $location_slug[] = $city_slug;
                    $location_request .= implode('/', $location_slug) . '/';
                }
            }
            if (get_option('geodir_add_categories_url')) {
                $term_request = '';
                $taxonomies = geodir_get_taxonomies($post->post_type);
                $taxonomies = end($taxonomies);
                if (!empty($post->default_category)) {
                    $post_terms = $post->default_category;
                } else {
                    $post_terms = '';
                    if (isset($post->{$taxonomies})) {
                        $post_terms = explode(",", trim($post->{$taxonomies}, ","));
                        $post_terms = $post_terms[0];
                    }
                    if (!$post_terms) {
                        $post_terms = geodir_get_post_meta($post->ID, 'default_category', true);
                    }
                    if (!$post_terms) {
                        $post_terms = geodir_get_post_meta($post->ID, $taxonomies, true);
                        if ($post_terms) {
                            $post_terms = explode(",", trim($post_terms, ","));
                            $post_terms = $post_terms[0];
                        }
                    }
                }
                $term = get_term_by('id', $post_terms, $taxonomies);
                if (!empty($term)) {
                    $term_request = $term->slug;
                }
                //$term_request = $term->slug.'/';
            }
            $request_term = '';
            $listingurl_separator = '';
            //$detailurl_separator = get_option('geodir_detailurl_separator');
            $detailurl_separator = '';
            if (isset($location_request) && $location_request != '' && isset($term_request) && $term_request != '') {
                $request_term = $location_request;
                //$listingurl_separator = get_option('geodir_listingurl_separator');
                //$request_term .= $listingurl_separator.'/'.$term_request;
                $request_term .= $term_request;
            } else {
                if (isset($location_request) && $location_request != '') {
                    $request_term = $location_request;
                }
                if (isset($term_request) && $term_request != '') {
                    $request_term .= $term_request;
                }
            }
            $request_term = trim($request_term, '/');
            if (!empty($request_term)) {
                $post_link = str_replace('%gd_taxonomy%', $request_term . $detailurl_separator, $post_link);
            } else {
                $post_link = str_replace('/%gd_taxonomy%', $request_term . $detailurl_separator, $post_link);
            }
            //echo $post_link ;
        }
        // temp cache the permalink
        if (!$sample && (!isset($_REQUEST['geodir_ajax']) || isset($_REQUEST['geodir_ajax']) && $_REQUEST['geodir_ajax'] != 'add_listing')) {
            $gd_permalink_cache[$post->ID] = $post_link;
        }
    }
    if (isset($orig_post)) {
        $post = $orig_post;
    }
    //echo $post_link ;
    return $post_link;
}
コード例 #5
0
/**
 * Action to save location related information in post type detail table on add/edit new listing action.
 *
 * @since 1.0.0
 * @package GeoDirectory_Location_Manager
 *
 * @global object $wpdb WordPress Database object.
 *
 * @param int $last_post_id The saved post ID.
 * @param array $request_info The post details in an array.
 */
function geodir_save_listing_location($last_post_id, $request_info)
{
    global $wpdb;
    $location_info = array();
    if (isset($request_info['post_neighbourhood'])) {
        $location_info['post_neighbourhood'] = $request_info['post_neighbourhood'];
    }
    if (isset($request_info['post_city']) && isset($request_info['post_region'])) {
        $post_location_id = geodir_get_post_meta($last_post_id, 'post_location_id', true);
        $post_location = geodir_get_location_by_id('', $post_location_id);
        $location_info['post_locations'] = '[' . $post_location->city_slug . '],[' . $post_location->region_slug . '],[' . $post_location->country_slug . ']';
        // set all overall post location
    }
    if (!empty($location_info)) {
        geodir_save_post_info($last_post_id, $location_info);
    }
}
コード例 #6
0
ファイル: success.php プロジェクト: poweronio/mbsite
do_action('geodir_before_main_content');
// action called before the main content for setails page, this adds the sidebar top sectiona dn breadcrums
do_action('geodir_success_before_main_content');
###### MAIN CONTENT WRAPPERS OPEN ######
// this adds the opening html tags to the content div, this required the closing tag below :: ($type='',$id='',$class='')
do_action('geodir_wrapper_content_open', 'success-page', 'geodir-wrapper-content', '');
if (isset($_REQUEST['renew'])) {
    $title = RENEW_SUCCESS_TITLE;
} else {
    $title = POSTED_SUCCESS_TITLE;
}
if (isset($postid) && $postid != '') {
    $_REQUEST['pid'] = $postid;
}
$paymentmethod = geodir_get_post_meta($_REQUEST['pid'], 'paymentmethod', true);
$paid_amount = geodir_get_currency_sym() . geodir_get_post_meta($_REQUEST['pid'], 'paid_amount', true);
global $upload_folder_path;
if ($paymentmethod == 'prebanktransfer') {
    $filecontent = stripslashes(get_option('post_pre_bank_trasfer_msg_content'));
    if (!$filecontent) {
        $filecontent = POSTED_SUCCESS_PREBANK_MSG;
    }
} else {
    $filecontent = stripslashes(get_option('post_added_success_msg_content'));
    if (!$filecontent) {
        $filecontent = POSTED_SUCCESS_MSG;
    }
}
if (!$_REQUEST['pid']) {
    $title = PAYMENT_FAIL_TITLE;
    $filecontent = PAYMENT_FAIL_MSG;
コード例 #7
0
    /**
     * Set post Map Marker info html.
     *
     * @since 1.0.0
     * @package GeoDirectory
     * @global array $geodir_addon_list List of active GeoDirectory extensions.
     * @param object $postinfo_obj The post details object.
     * @param string $post_preview Is this a post preview?.
     * @return mixed|string|void
     */
    function geodir_get_infowindow_html($postinfo_obj, $post_preview = '')
    {
        global $preview;
        $srcharr = array("'", "/", "-", '"', '\\');
        $replarr = array("&prime;", "&frasl;", "&ndash;", "&ldquo;", '');
        if (isset($_SESSION['listing']) && isset($post_preview) && $post_preview != '') {
            $ID = '';
            $plink = '';
            if (isset($postinfo_obj->pid)) {
                $ID = $postinfo_obj->pid;
                $plink = get_permalink($ID);
            }
            $title = str_replace($srcharr, $replarr, $postinfo_obj->post_title);
            $lat = $postinfo_obj->post_latitude;
            $lng = $postinfo_obj->post_longitude;
            $address = str_replace($srcharr, $replarr, $postinfo_obj->post_address);
            $contact = str_replace($srcharr, $replarr, $postinfo_obj->geodir_contact);
            $timing = str_replace($srcharr, $replarr, $postinfo_obj->geodir_timing);
        } else {
            $ID = $postinfo_obj->post_id;
            $title = str_replace($srcharr, $replarr, htmlentities($postinfo_obj->post_title, ENT_COMPAT, 'UTF-8'));
            // fix by Stiofan
            $plink = get_permalink($ID);
            $lat = htmlentities(geodir_get_post_meta($ID, 'post_latitude', true));
            $lng = htmlentities(geodir_get_post_meta($ID, 'post_longitude', true));
            $address = str_replace($srcharr, $replarr, htmlentities(geodir_get_post_meta($ID, 'post_address', true), ENT_COMPAT, 'UTF-8'));
            // fix by Stiofan
            $contact = str_replace($srcharr, $replarr, htmlentities(geodir_get_post_meta($ID, 'geodir_contact', true), ENT_COMPAT, 'UTF-8'));
            $timing = str_replace($srcharr, $replarr, geodir_get_post_meta($ID, 'geodir_timing', true));
        }
        // filter field as per price package
        global $geodir_addon_list;
        if (isset($geodir_addon_list['geodir_payment_manager']) && $geodir_addon_list['geodir_payment_manager'] == 'yes') {
            $post_type = get_post_type($ID);
            $package_id = isset($postinfo_obj->package_id) && $postinfo_obj->package_id ? $postinfo_obj->package_id : NULL;
            $field_name = 'geodir_contact';
            if (!check_field_visibility($package_id, $field_name, $post_type)) {
                $contact = '';
            }
            $field_name = 'geodir_timing';
            if (!check_field_visibility($package_id, $field_name, $post_type)) {
                $timing = '';
            }
        }
        if ($lat && $lng) {
            ob_start();
            ?>
            <div class="gd-bubble" style="height: 100px;max-height: 100px;">
                <div class="gd-bubble-inside">
                    <?php 
            $comment_count = '';
            $rating_star = '';
            if ($ID != '') {
                $rating_star = '';
                $comment_count = geodir_get_review_count_total($ID);
                if (!$preview) {
                    $post_avgratings = geodir_get_post_rating($ID);
                    $rating_star = geodir_get_rating_stars($post_avgratings, $ID, false);
                    /**
                     * Filter to change rating stars
                     *
                     * You can use this filter to change Rating stars.
                     *
                     * @since 1.0.0
                     * @package GeoDirectory
                     * @param string $rating_star Rating stars.
                     * @param float $post_avgratings Average ratings of the post.
                     * @param int $ID The post ID.
                     */
                    $rating_star = apply_filters('geodir_review_rating_stars_on_infowindow', $rating_star, $post_avgratings, $ID);
                }
            }
            ?>
                    <div class="geodir-bubble_desc">
                        <h4>
                            <a href="<?php 
            if ($plink != '') {
                echo $plink;
            } else {
                echo 'javascript:void(0);';
            }
            ?>
"><?php 
            echo $title;
            ?>
</a>
                        </h4>
                        <?php 
            if (isset($_SESSION['listing']) && isset($post_preview) && $post_preview != '') {
                $post_images = array();
                if (!empty($postinfo_obj->post_images)) {
                    $post_images = explode(",", $postinfo_obj->post_images);
                }
                if (!empty($post_images)) {
                    ?>
                                <div class="geodir-bubble_image"><a href="<?php 
                    if ($plink != '') {
                        echo $plink;
                    } else {
                        echo 'javascript:void(0);';
                    }
                    ?>
"><img alt="bubble image" style="max-height:50px;"
                                               src="<?php 
                    echo $post_images[0];
                    ?>
"/></a></div>
                            <?php 
                }
            } else {
                if ($image = geodir_show_featured_image($ID, 'widget-thumb', true, false, $postinfo_obj->featured_image)) {
                    ?>
                                <div class="geodir-bubble_image"><a
                                        href="<?php 
                    echo $plink;
                    ?>
"><?php 
                    echo $image;
                    ?>
</a></div>
                            <?php 
                }
            }
            ?>
                        <div class="geodir-bubble-meta-side">
                            <span class="geodir_address"><i class="fa fa-home"></i> <?php 
            echo $address;
            ?>
</span>
                            <?php 
            if ($contact) {
                ?>
<span class="geodir_contact"><i
                                class="fa fa-phone"></i> <?php 
                echo $contact;
                ?>
</span><?php 
            }
            ?>
                            <?php 
            if ($timing) {
                ?>
<span class="geodir_timing"><i
                                class="fa fa-clock-o"></i> <?php 
                echo $timing;
                ?>
</span><?php 
            }
            /**
             * Fires after the meta info in the map info window.
             *
             * This can be used to add more info to the map info window after the normal meta info.
             *
             * @since 1.4.2
             * @param object $postinfo_obj The posts info as an object.
             * @param bool|string $post_preview True if currently in post preview page. Empty string if not.                           *
             */
            do_action('geodir_infowindow_meta_after', $postinfo_obj, $post_preview);
            ?>
                        </div>
                        <?php 
            if (isset($postinfo_obj->recurring_dates)) {
                $recuring_data = unserialize($postinfo_obj->recurring_dates);
                $output = '';
                $output .= '<div class="geodir_event_schedule">';
                $event_recurring_dates = explode(',', $recuring_data['event_recurring_dates']);
                $starttimes = isset($recuring_data['starttime']) ? $recuring_data['starttime'] : '';
                $endtimes = isset($recuring_data['endtime']) ? $recuring_data['endtime'] : '';
                $e = 0;
                foreach ($event_recurring_dates as $key => $date) {
                    if (strtotime($date) < strtotime(date("Y-m-d"))) {
                        continue;
                    }
                    // if the event is old don't show it on the map
                    $e++;
                    if ($e == 2) {
                        break;
                    }
                    // only show 3 event dates
                    $output .= '<p>';
                    //$geodir_num_dates++;
                    if (isset($recuring_data['different_times']) && $recuring_data['different_times'] == '1') {
                        $starttimes = isset($recuring_data['starttimes'][$key]) ? $recuring_data['starttimes'][$key] : '';
                        $endtimes = isset($recuring_data['endtimes'][$key]) ? $recuring_data['endtimes'][$key] : '';
                    }
                    $sdate = strtotime($date . ' ' . $starttimes);
                    $edate = strtotime($date . ' ' . $endtimes);
                    if ($starttimes > $endtimes) {
                        $edate = strtotime($date . ' ' . $endtimes . " +1 day");
                    }
                    global $geodir_date_time_format;
                    $output .= '<i class="fa fa-caret-right"></i>' . date($geodir_date_time_format, $sdate);
                    //$output .=  __(' To', GEODIREVENTS_TEXTDOMAIN).' ';
                    $output .= '<br />';
                    $output .= '<i class="fa fa-caret-left"></i>' . date($geodir_date_time_format, $edate);
                    //.'<br />';
                    $output .= '</p>';
                }
                $output .= '</div>';
                echo $output;
            }
            if ($ID) {
                $post_author = isset($postinfo_obj->post_author) ? $postinfo_obj->post_author : get_post_field('post_author', $ID);
                ?>
                        <div class="geodir-bubble-meta-fade"></div>

                        <div class="geodir-bubble-meta-bottom">
                                <span class="geodir-bubble-rating"><?php 
                echo $rating_star;
                ?>
</span>

                                <span
                                    class="geodir-bubble-fav"><?php 
                echo geodir_favourite_html($post_author, $ID);
                ?>
</span>
                  <span class="geodir-bubble-reviews"><a href="<?php 
                echo get_comments_link($ID);
                ?>
"
                                                         class="geodir-pcomments"><i class="fa fa-comments"></i>
                          <?php 
                echo get_comments_number($ID);
                ?>
                      </a></span>
                            </div>

                        <?php 
            }
            ?>

                    </div>
                </div>
            </div>
            <?php 
            $html = ob_get_clean();
            /**
             * Filter to change infowindow html
             *
             * You can use this filter to change infowindow html.
             *
             * @since 1.0.0
             * @package GeoDirectory
             * @param string $html Infowindow html.
             * @param object $postinfo_obj The Post object.
             * @param bool|string $post_preview Is this a post preview?
             */
            $html = apply_filters('geodir_custom_infowindow_html', $html, $postinfo_obj, $post_preview);
            return $html;
        }
    }
コード例 #8
0
function geodir_payment_after_main_form_fields()
{
    if (!empty($_REQUEST['pid']) && !empty($_REQUEST['package_id'])) {
        $post_type = get_post_type($_REQUEST['pid']);
        $prev_package_id = geodir_get_post_meta($_REQUEST['pid'], 'package_id', true);
        $prev_expire_date = geodir_get_post_meta($_REQUEST['pid'], 'expire_date', true);
        $_SESSION['geodir_prev_package_id'] = $prev_package_id;
        $_SESSION['geodir_prev_expire_date'] = $prev_expire_date;
        if ($post_type != '' && in_array($post_type, geodir_get_posttypes()) && $prev_package_id == $_REQUEST['package_id'] && $prev_expire_date != '' && strtolower($prev_expire_date) != 'never' && strtotime($prev_expire_date) >= strtotime(date('Y-m-d'))) {
            echo '<input type="hidden" id="geodir_prev_package_id" name="geodir_prev_package_id" value="' . $prev_package_id . '" /><input type="hidden" id="geodir_prev_expire_date" name="geodir_prev_expire_date" value="' . $prev_expire_date . '" />';
        }
    }
}
コード例 #9
0
    /**
     * Set post Map Marker info html.
     *
     * @since 1.0.0
     * @since 1.5.4 Modified to add new action "geodir_infowindow_meta_before".
     * @package GeoDirectory
     * @global array $geodir_addon_list List of active GeoDirectory extensions.
     * @param object $postinfo_obj The post details object.
     * @param string $post_preview Is this a post preview?.
     * @return mixed|string|void
     */
    function geodir_get_infowindow_html($postinfo_obj, $post_preview = '')
    {
        global $preview;
        $srcharr = array("'", "/", "-", '"', '\\');
        $replarr = array("&prime;", "&frasl;", "&ndash;", "&ldquo;", '');
        if (isset($_SESSION['listing']) && isset($post_preview) && $post_preview != '') {
            $ID = '';
            $plink = '';
            if (isset($postinfo_obj->pid)) {
                $ID = $postinfo_obj->pid;
                $plink = get_permalink($ID);
            }
            $title = str_replace($srcharr, $replarr, $postinfo_obj->post_title);
            $lat = $postinfo_obj->post_latitude;
            $lng = $postinfo_obj->post_longitude;
            $address = str_replace($srcharr, $replarr, $postinfo_obj->post_address);
            $contact = str_replace($srcharr, $replarr, $postinfo_obj->geodir_contact);
            $timing = str_replace($srcharr, $replarr, $postinfo_obj->geodir_timing);
        } else {
            $ID = $postinfo_obj->post_id;
            $title = str_replace($srcharr, $replarr, htmlentities($postinfo_obj->post_title, ENT_COMPAT, 'UTF-8'));
            // fix by Stiofan
            $plink = get_permalink($ID);
            $lat = htmlentities(geodir_get_post_meta($ID, 'post_latitude', true));
            $lng = htmlentities(geodir_get_post_meta($ID, 'post_longitude', true));
            $address = str_replace($srcharr, $replarr, htmlentities(geodir_get_post_meta($ID, 'post_address', true), ENT_COMPAT, 'UTF-8'));
            // fix by Stiofan
            $contact = str_replace($srcharr, $replarr, htmlentities(geodir_get_post_meta($ID, 'geodir_contact', true), ENT_COMPAT, 'UTF-8'));
            $timing = str_replace($srcharr, $replarr, geodir_get_post_meta($ID, 'geodir_timing', true));
        }
        // filter field as per price package
        global $geodir_addon_list;
        if (isset($geodir_addon_list['geodir_payment_manager']) && $geodir_addon_list['geodir_payment_manager'] == 'yes') {
            $post_type = get_post_type($ID);
            $package_id = isset($postinfo_obj->package_id) && $postinfo_obj->package_id ? $postinfo_obj->package_id : NULL;
            $field_name = 'geodir_contact';
            if (!check_field_visibility($package_id, $field_name, $post_type)) {
                $contact = '';
            }
            $field_name = 'geodir_timing';
            if (!check_field_visibility($package_id, $field_name, $post_type)) {
                $timing = '';
            }
        }
        if ($lat && $lng) {
            ob_start();
            ?>
            <div class="gd-bubble" style="">
                <div class="gd-bubble-inside">
                    <?php 
            $comment_count = '';
            $rating_star = '';
            if ($ID != '') {
                $rating_star = '';
                $comment_count = geodir_get_review_count_total($ID);
                if (!$preview) {
                    $post_avgratings = geodir_get_post_rating($ID);
                    $rating_star = geodir_get_rating_stars($post_avgratings, $ID, false);
                    /**
                     * Filter to change rating stars
                     *
                     * You can use this filter to change Rating stars.
                     *
                     * @since 1.0.0
                     * @package GeoDirectory
                     * @param string $rating_star Rating stars.
                     * @param float $post_avgratings Average ratings of the post.
                     * @param int $ID The post ID.
                     */
                    $rating_star = apply_filters('geodir_review_rating_stars_on_infowindow', $rating_star, $post_avgratings, $ID);
                }
            }
            ?>
                    <div class="geodir-bubble_desc">
                        <h4>
                            <a href="<?php 
            if ($plink != '') {
                echo $plink;
            } else {
                echo 'javascript:void(0);';
            }
            ?>
"><?php 
            echo $title;
            ?>
</a>
                        </h4>
                        <?php 
            if (isset($_SESSION['listing']) && isset($post_preview) && $post_preview != '') {
                $post_images = array();
                if (!empty($postinfo_obj->post_images)) {
                    $post_images = explode(",", $postinfo_obj->post_images);
                }
                if (!empty($post_images)) {
                    ?>
                                <div class="geodir-bubble_image"><a href="<?php 
                    if ($plink != '') {
                        echo $plink;
                    } else {
                        echo 'javascript:void(0);';
                    }
                    ?>
"><img alt="bubble image" style="max-height:50px;"
                                               src="<?php 
                    echo $post_images[0];
                    ?>
"/></a></div>
                            <?php 
                } else {
                    echo '<div class="geodir-bubble_image"></div>';
                }
            } else {
                if ($image = geodir_show_featured_image($ID, 'widget-thumb', true, false, $postinfo_obj->featured_image)) {
                    ?>
                                <div class="geodir-bubble_image"><a href="<?php 
                    echo $plink;
                    ?>
"><?php 
                    echo $image;
                    ?>
</a></div>
                            <?php 
                } else {
                    echo '<div class="geodir-bubble_image"></div>';
                }
            }
            ?>
                        <div class="geodir-bubble-meta-side">
                            <?php 
            /**
             * Fires before the meta info in the map info window.
             *
             * This can be used to add more info to the map info window before the normal meta info.
             *
             * @since 1.5.4
             * @param int $ID The post id.
             * @param object $postinfo_obj The posts info as an object.
             * @param bool|string $post_preview True if currently in post preview page. Empty string if not.                           *
             */
            do_action('geodir_infowindow_meta_before', $ID, $postinfo_obj, $post_preview);
            ?>
                            <span class="geodir_address"><i class="fa fa-home"></i> <?php 
            echo $address;
            ?>
</span>
                            <?php 
            if ($contact) {
                ?>
<span class="geodir_contact"><i
                                class="fa fa-phone"></i> <?php 
                echo $contact;
                ?>
</span><?php 
            }
            ?>
                            <?php 
            if ($timing) {
                ?>
<span class="geodir_timing"><i
                                class="fa fa-clock-o"></i> <?php 
                echo $timing;
                ?>
</span><?php 
            }
            /**
             * Fires after the meta info in the map info window.
             *
             * This can be used to add more info to the map info window after the normal meta info.
             *
             * @since 1.4.2
             * @param object $postinfo_obj The posts info as an object.
             * @param bool|string $post_preview True if currently in post preview page. Empty string if not.                           *
             */
            do_action('geodir_infowindow_meta_after', $postinfo_obj, $post_preview);
            ?>
                        </div>
                        <?php 
            if ($ID) {
                $post_author = isset($postinfo_obj->post_author) ? $postinfo_obj->post_author : get_post_field('post_author', $ID);
                ?>
                            <div class="geodir-bubble-meta-fade"></div>

                            <div class="geodir-bubble-meta-bottom">
                                <span class="geodir-bubble-rating"><?php 
                echo $rating_star;
                ?>
</span>

                                <span
                                    class="geodir-bubble-fav"><?php 
                echo geodir_favourite_html($post_author, $ID);
                ?>
</span>
                  <span class="geodir-bubble-reviews"><a href="<?php 
                echo get_comments_link($ID);
                ?>
"
                                                         class="geodir-pcomments"><i class="fa fa-comments"></i>
                          <?php 
                echo get_comments_number($ID);
                ?>
                      </a></span>
                            </div>

                        <?php 
            }
            ?>

                    </div>
                </div>
            </div>
            <?php 
            $html = ob_get_clean();
            /**
             * Filter to change infowindow html
             *
             * You can use this filter to change infowindow html.
             *
             * @since 1.0.0
             * @package GeoDirectory
             * @param string $html Infowindow html.
             * @param object $postinfo_obj The Post object.
             * @param bool|string $post_preview Is this a post preview?
             */
            $html = apply_filters('geodir_custom_infowindow_html', $html, $postinfo_obj, $post_preview);
            return $html;
        }
    }
コード例 #10
0
/**
 * Append the featured image for the activity excerpt.
 *
 * @since 1.0.5
 * @package GeoDirectory_BuddyPress_Integration
 *
 * @param string $excerpt The appended text for the activity excerpt.
 * @return string The activity excerpt.
 */
function geodir_buddypress_bp_activity_featured_image($excerpt = '')
{
    $activity_name = bp_get_activity_object_name();
    $activity_type = bp_get_activity_type();
    $item_id = bp_get_activity_secondary_item_id();
    if ($activity_name == 'activity' && $item_id > 0 && $activity_type == 'new_' . get_post_type($item_id) && get_option('geodir_buddypress_show_feature_image')) {
        $image = wp_get_attachment_image_src(get_post_thumbnail_id($item_id));
        if (!empty($image) && !empty($image[0])) {
            $listing_title = geodir_get_post_meta($item_id, 'post_title', true);
            $featured_image = '<a class="gdbp-feature-image" href="' . get_permalink($item_id) . '" title="' . esc_attr($listing_title) . '"><img alt="' . esc_attr($listing_title) . '" src="' . $image[0] . '" /></a>';
            /**
             * Filter the new listing featured image in activity.
             *
             * @since 1.0.5
             *
             * @param string $featured_image Featured image content.
             * @param int $item_id Activity item id.
             * @param string $activity_name Current activity name.
             * @param string $activity_type Current activity type.
             */
            $featured_image = apply_filters('geodir_buddypress_bp_activity_featured_image', $featured_image, $item_id, $activity_name, $activity_type);
            echo $featured_image;
        }
    }
    return $excerpt;
}
コード例 #11
0
function geodir_post_package_setting()
{
    global $post, $post_id, $package_id;
    wp_nonce_field(plugin_basename(__FILE__), 'geodir_post_package_setting_noncename');
    $package_price_info = geodir_package_list_info($post->post_type);
    if (isset($_REQUEST['package_id'])) {
        $package_id = $_REQUEST['package_id'];
    } elseif ($post_package_id = geodir_get_post_meta($post_id, 'package_id')) {
        $package_id = $post_package_id;
    } else {
        foreach ($package_price_info as $pck_val) {
            if ($pck_val->is_default) {
                $package_id = $pck_val->pid;
            }
        }
    }
    ?>
		
	<div class="misc-pub-section" >
		<h4 style="display:inline;"><?php 
    echo SELECT_PACKAGE_TEXT;
    ?>
</h4>
		<?php 
    foreach ($package_price_info as $pkg) {
        $checkbox_alive_days = 'unlimited';
        $post_pkg_link = '';
        if ($pkg->days) {
            $checkbox_alive_days = $pkg->days;
        }
        $post_pkg_link = get_edit_post_link($post_id) . '&package_id=' . $pkg->pid;
        ?>
				<div class="gd-package" style="width:100%; margin:5px 0px;">
				<input class="gd-checkbox"  name="package_id" type="radio" value="<?php 
        echo $pkg->pid;
        ?>
"  <?php 
        if ($package_id == $pkg->pid) {
            echo 'checked="checked"';
        }
        ?>
 onclick="window.location.href='<?php 
        echo $post_pkg_link;
        ?>
'">
				<?php 
        _e(stripslashes_deep($pkg->title_desc), GEODIRECTORY_TEXTDOMAIN);
        ?>
				</div>
				
			<?php 
    }
    ?>
	
			
	</div>
	<?php 
    if (geodir_get_post_meta($post_id, 'alive_days', true) != '') {
        $alive_days = geodir_get_post_meta($post_id, 'alive_days', true);
    }
    if (geodir_get_post_meta($post_id, 'is_featured', true) != '') {
        $is_featured = geodir_get_post_meta($post_id, 'is_featured', true);
    }
    if (geodir_get_post_meta($post_id, 'expire_date', true) != '') {
        $expire_date = geodir_get_post_meta($post_id, 'expire_date', true);
    }
    ?>
    
     <div class="misc-pub-section">
        <h4 style="display:inline;"><?php 
    _e('Alive Days:', GEODIRPAYMENT_TEXTDOMAIN);
    ?>
</h4>
        <input type="text" name="alive_days" value="<?php 
    if (isset($alive_days)) {
        echo $alive_days;
    } else {
        echo '0';
    }
    ?>
"  />
		<br />
        <h4 style="display:inline;"><?php 
    _e('Expire Date:', GEODIRPAYMENT_TEXTDOMAIN);
    ?>
(ie: YYYY-MM-DD)</h4>
		<input type="text" name="expire_date" value="<?php 
    if (isset($expire_date)) {
        echo $expire_date;
    } else {
        echo 'Never';
    }
    ?>
" />
        
    </div>
    
   
    
    <div class="misc-pub-section">
        <h4 style="display:inline;"><?php 
    _e('Is Featured:', GEODIRPAYMENT_TEXTDOMAIN);
    ?>
</h4>
        
                <input type="radio" class="gd-checkbox" name="is_featured" id="is_featured_yes" <?php 
    if (isset($is_featured) && $is_featured == '1') {
        echo 'checked="checked"';
    }
    ?>
  value="1"   /> <?php 
    _e('Yes', GEODIRPAYMENT_TEXTDOMAIN);
    ?>
                <input type="radio" class="gd-checkbox" name="is_featured" id="is_featured_no" <?php 
    if (isset($is_featured) && $is_featured == '0' || !isset($is_featured)) {
        echo 'checked="checked"';
    }
    ?>
 value="0"   /> <?php 
    _e('No', GEODIRPAYMENT_TEXTDOMAIN);
    ?>
           
        
    </div><?php 
}
コード例 #12
0
 /**
  * Save post file fields
  *
  * @since 1.0.0
  * @since 1.4.7 Added `$extra_fields` parameter.
  * @package GeoDirectory
  * @global object $wpdb WordPress Database object.
  * @global string $plugin_prefix Geodirectory plugin table prefix.
  * @global object $current_user Current user object.
  * @param int $post_id
  * @param string $field_id
  * @param array $post_image
  * @param array $extra_fields Array of extra fields.
  */
 function geodir_save_post_file_fields($post_id = 0, $field_id = '', $post_image = array(), $extra_fields = array())
 {
     global $wpdb, $plugin_prefix, $current_user;
     $post_type = get_post_type($post_id);
     //echo $field_id; exit;
     $table = $plugin_prefix . $post_type . '_detail';
     $postcurr_images = array();
     $postcurr_images = geodir_get_post_meta($post_id, $field_id, true);
     $file_urls = '';
     if (!empty($post_image)) {
         $invalid_files = array();
         //Get and remove all old images of post from database to set by new order
         $geodir_uploaddir = '';
         $uploads = wp_upload_dir();
         $uploads_dir = $uploads['path'];
         $geodir_uploadpath = $uploads['path'];
         $geodir_uploadurl = $uploads['url'];
         $sub_dir = $uploads['subdir'];
         $allowed_file_types = !empty($extra_fields['gd_file_types']) && is_array($extra_fields['gd_file_types']) && !in_array("*", $extra_fields['gd_file_types']) ? $extra_fields['gd_file_types'] : '';
         for ($m = 0; $m < count($post_image); $m++) {
             /* --------- start ------- */
             if (!($find_image = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM " . $table . " WHERE {$field_id} = %s AND post_id = %d", array($post_image[$m], $post_id))))) {
                 $curr_img_url = $post_image[$m];
                 $image_name_arr = explode('/', $curr_img_url);
                 $curr_img_dir = $image_name_arr[count($image_name_arr) - 2];
                 $filename = end($image_name_arr);
                 $img_name_arr = explode('.', $filename);
                 $arr_file_type = wp_check_filetype($filename);
                 if (empty($arr_file_type['ext']) || empty($arr_file_type['type'])) {
                     continue;
                 }
                 $uploaded_file_type = $arr_file_type['type'];
                 $uploaded_file_ext = $arr_file_type['ext'];
                 if (!empty($allowed_file_types) && !in_array($uploaded_file_ext, $allowed_file_types)) {
                     continue;
                     // Invalid file type.
                 }
                 // Set an array containing a list of acceptable formats
                 //$allowed_file_types = array('image/jpg', 'image/jpeg', 'image/gif', 'image/png', 'application/pdf', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/octet-stream', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'text/csv', 'text/plain');
                 if (!function_exists('wp_handle_upload')) {
                     require_once ABSPATH . 'wp-admin/includes/file.php';
                 }
                 if (!is_dir($geodir_uploadpath)) {
                     mkdir($geodir_uploadpath);
                 }
                 $new_name = $post_id . '_' . $field_id . '_' . $img_name_arr[0] . '.' . $img_name_arr[1];
                 $explode_sub_dir = explode("/", $sub_dir);
                 if ($curr_img_dir == end($explode_sub_dir)) {
                     $img_path = $geodir_uploadpath . '/' . $filename;
                     $img_url = $geodir_uploadurl . '/' . $filename;
                 } else {
                     $img_path = $uploads_dir . '/temp_' . $current_user->data->ID . '/' . $filename;
                     $img_url = $uploads['url'] . '/temp_' . $current_user->data->ID . '/' . $filename;
                 }
                 $uploaded_file = '';
                 if (file_exists($img_path)) {
                     $uploaded_file = copy($img_path, $geodir_uploadpath . '/' . $new_name);
                 }
                 if ($curr_img_dir != $geodir_uploaddir) {
                     if (file_exists($img_path)) {
                         unlink($img_path);
                     }
                 }
                 if (!empty($uploaded_file)) {
                     $file_urls = $geodir_uploadurl . '/' . $new_name;
                 }
             } else {
                 $file_urls = $post_image[$m];
             }
         }
     }
     //Remove all old attachments and temp images
     if (!empty($postcurr_images)) {
         if ($file_urls != $postcurr_images) {
             $invalid_files[] = (object) array('src' => $postcurr_images);
             $invalid_files = (object) $invalid_files;
         }
     }
     geodir_save_post_meta($post_id, $field_id, $file_urls);
     if (!empty($invalid_files)) {
         geodir_remove_attachments($invalid_files);
     }
 }
コード例 #13
0
 /**
  * Adds content to our custom post listing page columns.
  *
  * @since 1.0.0
  * @package GeoDirectory
  * @global object $wpdb WordPress Database object.
  * @global object $post WordPress Post object.
  * @param string $column The column name.
  * @param int $post_id The post ID.
  */
 function geodir_manage_post_columns($column, $post_id)
 {
     global $post, $wpdb;
     switch ($column) {
         /* If displaying the 'city' column. */
         case 'location':
             $location_id = geodir_get_post_meta($post->ID, 'post_location_id', true);
             $location = geodir_get_location($location_id);
             /* If no city is found, output a default message. */
             if (empty($location)) {
                 _e('Unknown', GEODIRECTORY_TEXTDOMAIN);
             } else {
                 /* If there is a city id, append 'city name' to the text string. */
                 $add_location_id = $location_id > 0 ? ' (' . $location_id . ')' : '';
                 echo __($location->country, GEODIRECTORY_TEXTDOMAIN) . '-' . $location->region . '-' . $location->city . $add_location_id;
             }
             break;
             /* If displaying the 'expire' column. */
         /* If displaying the 'expire' column. */
         case 'expire':
             $expire_date = geodir_get_post_meta($post->ID, 'expire_date', true);
             $d1 = $expire_date;
             // get expire_date
             $d2 = date('Y-m-d');
             // get current date
             $state = __('days left', GEODIRECTORY_TEXTDOMAIN);
             $date_diff_text = '';
             $expire_class = 'expire_left';
             if ($expire_date != 'Never') {
                 if (strtotime($d1) < strtotime($d2)) {
                     $state = __('days overdue', GEODIRECTORY_TEXTDOMAIN);
                     $expire_class = 'expire_over';
                 }
                 $date_diff = round(abs(strtotime($d1) - strtotime($d2)) / 86400);
                 // get the differance in days
                 $date_diff_text = '<br /><span class="' . $expire_class . '">(' . $date_diff . ' ' . $state . ')</span>';
             }
             /* If no expire_date is found, output a default message. */
             if (empty($expire_date)) {
                 echo __('Unknown', GEODIRECTORY_TEXTDOMAIN);
             } else {
                 echo $expire_date . $date_diff_text;
             }
             break;
             /* If displaying the 'categorys' column. */
         /* If displaying the 'categorys' column. */
         case 'categorys':
             /* Get the categorys for the post. */
             $terms = wp_get_object_terms($post_id, get_object_taxonomies($post));
             /* If terms were found. */
             if (!empty($terms)) {
                 $out = array();
                 /* Loop through each term, linking to the 'edit posts' page for the specific term. */
                 foreach ($terms as $term) {
                     if (!strstr($term->taxonomy, 'tag')) {
                         $out[] = sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('post_type' => $post->post_type, $term->taxonomy => $term->slug), 'edit.php')), esc_html(sanitize_term_field('name', $term->name, $term->term_id, $term->taxonomy, 'display')));
                     }
                 }
                 /* Join the terms, separating them with a comma. */
                 echo join(', ', $out);
             } else {
                 _e('No Categories', GEODIRECTORY_TEXTDOMAIN);
             }
             break;
     }
 }
コード例 #14
0
    function geodir_get_infowindow_html($postinfo_obj, $post_preview = '')
    {
        global $preview;
        $srcharr = array("'", "/", "-", '"', '\\');
        $replarr = array("&prime;", "&frasl;", "&ndash;", "&ldquo;", '');
        if (isset($_SESSION['listing']) && isset($post_preview) && $post_preview != '') {
            $ID = '';
            $plink = '';
            if (isset($postinfo_obj->pid)) {
                $ID = $postinfo_obj->pid;
                $plink = get_permalink($ID);
            }
            $title = str_replace($srcharr, $replarr, $postinfo_obj->post_title);
            $lat = $postinfo_obj->post_latitude;
            $lng = $postinfo_obj->post_longitude;
            $address = str_replace($srcharr, $replarr, $postinfo_obj->post_address);
            $city = str_replace($srcharr, $replarr, $postinfo_obj->post_city);
            $contact = str_replace($srcharr, $replarr, $postinfo_obj->geodir_contact);
            $timing = str_replace($srcharr, $replarr, $postinfo_obj->geodir_timing);
        } else {
            $ID = $postinfo_obj->post_id;
            $title = str_replace($srcharr, $replarr, htmlentities($postinfo_obj->post_title, ENT_COMPAT, 'UTF-8'));
            // fix by Stiofan
            $plink = get_permalink($ID);
            $lat = htmlentities(geodir_get_post_meta($ID, 'post_latitude', true));
            $lng = htmlentities(geodir_get_post_meta($ID, 'post_longitude', true));
            $address = str_replace($srcharr, $replarr, htmlentities(geodir_get_post_meta($ID, 'post_address', true), ENT_COMPAT, 'UTF-8'));
            // fix by Stiofan
            $city = str_replace($srcharr, $replarr, htmlentities(geodir_get_post_meta($ID, 'post_city', true), ENT_COMPAT, 'UTF-8'));
            $contact = str_replace($srcharr, $replarr, htmlentities(geodir_get_post_meta($ID, 'geodir_contact', true), ENT_COMPAT, 'UTF-8'));
            $timing = str_replace($srcharr, $replarr, geodir_get_post_meta($ID, 'geodir_timing', true));
        }
        if ($lat && $lng) {
            ob_start();
            ?>

	<div class="bubble">
		<div style="position: relative;margin:5px 0px; ">
			<?php 
            $comment_count = '';
            $rating_star = '';
            if ($ID != '') {
                $rating_star = '';
                //$comment_count = get_comments_number($ID); // for some reason the filter is not applied here.
                $comment_count = isset($postinfo_obj->rating_count) ? $postinfo_obj->rating_count : 0;
                //$comment_count = geodir_get_comments_number($ID);
                $post_ratings = geodir_get_postoverall($ID);
                // $post_ratings = geodir_get_commentoverall_number($ID);
                if (!$preview) {
                    if ($comment_count > 0) {
                        $post_avgratings = $post_ratings / $comment_count;
                    } else {
                        $post_avgratings = $post_ratings;
                    }
                    //$rating_star = geodir_get_rating_stars($post_avgratings,$ID,true);
                    $rating_star = geodir_get_rating_stars($post_avgratings, $ID, false);
                    $rating_star = apply_filters('geodir_review_rating_stars_on_infowindow', $rating_star, $post_avgratings, $ID);
                }
            }
            ?>
				
			<div class="geodir-bubble_desc">
				<h4>
					<a href="<?php 
            if ($plink != '') {
                echo $plink;
            } else {
                echo 'javascript:void(0);';
            }
            ?>
"><?php 
            echo $title;
            ?>
</a>
				</h4>
               <?php 
            if (isset($_SESSION['listing']) && isset($post_preview) && $post_preview != '') {
                $post_images = array();
                if (!empty($postinfo_obj->post_images)) {
                    $post_images = explode(",", $postinfo_obj->post_images);
                }
                if (!empty($post_images)) {
                    ?>
					
					<div class="geodir-bubble_image" >
					<a href="<?php 
                    if ($plink != '') {
                        echo $plink;
                    } else {
                        echo 'javascript:void(0);';
                    }
                    ?>
">
					<img style="max-height:50px;" src="<?php 
                    echo $post_images[0];
                    ?>
" />
					</a>
					</div> 
				<?php 
                }
            } else {
                if ($image = geodir_show_featured_image($ID, 'widget-thumb', true, false, $postinfo_obj->featured_image)) {
                    ?>
				<div class="geodir-bubble_image" >
					<a href="<?php 
                    echo $plink;
                    ?>
">
					<?php 
                    echo $image;
                    ?>
					</a>
				</div> 
				<?php 
                }
            }
            ?>
                
                
                
				
                
              <div class="geodir-bubble-meta-side">
				<span class="geodir_address"><i class="fa fa-home"></i> <?php 
            echo $address . ', ' . $city;
            ?>
</span>
				<?php 
            if ($contact) {
                ?>
<span class="geodir_contact"><i class="fa fa-phone"></i> <?php 
                echo $contact;
                ?>
</span><?php 
            }
            ?>
				<?php 
            if ($timing) {
                ?>
<span class="geodir_timing"><i class="fa fa-clock-o"></i> <?php 
                echo $timing;
                ?>
</span><?php 
            }
            ?>
              </div>
             
            <?php 
            if (isset($postinfo_obj->recurring_dates)) {
                $recuring_data = unserialize($postinfo_obj->recurring_dates);
                //print_r($recuring_data); echo '###';
                $output = '';
                $output .= '<div class="geodir_event_schedule">';
                $event_recurring_dates = explode(',', $recuring_data['event_recurring_dates']);
                $starttimes = isset($recuring_data['starttime']) ? $recuring_data['starttime'] : '';
                $endtimes = isset($recuring_data['endtime']) ? $recuring_data['endtime'] : '';
                $e = 0;
                foreach ($event_recurring_dates as $key => $date) {
                    if (strtotime($date) < strtotime(date("Y-m-d"))) {
                        continue;
                    }
                    // if the event is old don't show it on the map
                    $e++;
                    if ($e == 2) {
                        break;
                    }
                    // only show 3 event dates
                    $output .= '<p>';
                    //$geodir_num_dates++;
                    if (isset($recuring_data['different_times']) && $recuring_data['different_times'] == '1') {
                        $starttimes = isset($recuring_data['starttimes'][$key]) ? $recuring_data['starttimes'][$key] : '';
                        $endtimes = isset($recuring_data['endtimes'][$key]) ? $recuring_data['endtimes'][$key] : '';
                    }
                    $sdate = strtotime($date . ' ' . $starttimes);
                    $edate = strtotime($date . ' ' . $endtimes);
                    if ($starttimes > $endtimes) {
                        $edate = strtotime($date . ' ' . $endtimes . " +1 day");
                    }
                    global $geodir_date_time_format;
                    $output .= '<i class="fa fa-caret-right"></i>' . date($geodir_date_time_format, $sdate);
                    //$output .=  __(' To', GEODIREVENTS_TEXTDOMAIN).' ';
                    $output .= '<br />';
                    $output .= '<i class="fa fa-caret-left"></i>' . date($geodir_date_time_format, $edate);
                    //.'<br />';
                    $output .= '</p>';
                }
                $output .= '</div>';
                echo $output;
            }
            if ($ID) {
                $post_author = isset($postinfo_obj->post_author) ? $postinfo_obj->post_author : get_post_field('post_author', $ID);
                ?>

              <div class="geodir-bubble-meta-bottom">
                  <span class="geodir-bubble-rating"><?php 
                echo $rating_star;
                ?>
</span>
                  
                  <span class="geodir-bubble-fav"><?php 
                echo geodir_favourite_html($post_author, $ID);
                ?>
</span>
                  <span class="geodir-bubble-reviews"><a href="<?php 
                echo get_comments_link($ID);
                ?>
" class="geodir-pcomments"><i class="fa fa-comments"></i>
                            <?php 
                echo get_comments_number($ID);
                ?>
                                     </a></span>
              </div>
 
       <?php 
            }
            ?>
 
			       
			</div>             					
		</div>
	</div>
	<?php 
            $html = ob_get_clean();
            $html = apply_filters('geodir_custom_infowindow_html', $html, $postinfo_obj, $post_preview);
            return $html;
        }
    }
コード例 #15
0
/**
 * Handle import/export for categories & listings.
 *
 * @since 1.4.6
 * @since 1.5.4 Modified to add default category via csv import.
 * @since 1.5.7 Modified to fix 504 Gateway Time-out for very large data.
 * @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
    $max_input_time = ini_get('max_input_time');
    $max_execution_time = ini_get('max_execution_time');
    $memory_limit = ini_get('memory_limit');
    if (!$max_input_time || $max_input_time < 3000) {
        @ini_set('max_input_time', 3000);
    }
    if (!$max_execution_time || $max_execution_time < 3000) {
        @ini_set('max_execution_time', 3000);
    }
    if ($memory_limit && str_replace('M', '', $memory_limit)) {
        if (str_replace('M', '', $memory_limit) < 256) {
            @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;
    $chunk_per_page = isset($_REQUEST['_n']) ? absint($_REQUEST['_n']) : NULL;
    $chunk_per_page = $chunk_per_page < 50 || $chunk_per_page > 100000 ? 5000 : $chunk_per_page;
    $chunk_page_no = isset($_REQUEST['_p']) ? absint($_REQUEST['_p']) : 1;
    /*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');
        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('dmyHi');
            $posts_count = geodir_get_posts_count($post_type);
            $file_url_base = geodir_path_import_export() . '/';
            $file_url = $file_url_base . $file_name . '.csv';
            $file_path = $csv_file_dir . '/' . $file_name . '.csv';
            $file_path_temp = $csv_file_dir . '/' . $post_type . '_' . $nonce . '.csv';
            $chunk_file_paths = array();
            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);
                exit;
            } else {
                if (!$posts_count > 0) {
                    $json['error'] = __('No records to export.', 'geodirectory');
                } else {
                    $total_posts = $posts_count;
                    if ($chunk_per_page > $total_posts) {
                        $chunk_per_page = $total_posts;
                    }
                    $chunk_total_pages = ceil($total_posts / $chunk_per_page);
                    $j = $chunk_page_no;
                    $chunk_save_posts = geodir_imex_get_posts($post_type, $chunk_per_page, $j);
                    $per_page = 500;
                    if ($per_page > $chunk_per_page) {
                        $per_page = $chunk_per_page;
                    }
                    $total_pages = ceil($chunk_per_page / $per_page);
                    for ($i = 0; $i <= $total_pages; $i++) {
                        $save_posts = array_slice($chunk_save_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)) {
                        $chunk_page_no = $chunk_total_pages > 1 ? '-' . $j : '';
                        $chunk_file_name = $file_name . $chunk_page_no . '.csv';
                        $file_path = $csv_file_dir . '/' . $chunk_file_name;
                        $wp_filesystem->move($file_path_temp, $file_path, true);
                        $file_url = $file_url_base . $chunk_file_name;
                        $chunk_file_paths[] = array('i' => $j . '.', 'u' => $file_url, 's' => size_format(filesize($file_path), 2));
                    }
                    if (!empty($chunk_file_paths)) {
                        $json['total'] = $posts_count;
                        $json['files'] = $chunk_file_paths;
                    } else {
                        $json['error'] = __('Fail, something wrong to create csv file.', 'geodirectory');
                    }
                }
                // WPML
                if ($is_wpml) {
                    $sitepress->switch_lang($active_lang, true);
                }
                // WPML
                wp_send_json($json);
                exit;
            }
            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('dmyHi');
            $terms_count = geodir_get_terms_count($post_type);
            $file_url_base = geodir_path_import_export() . '/';
            $file_url = $file_url_base . $file_name . '.csv';
            $file_path = $csv_file_dir . '/' . $file_name . '.csv';
            $file_path_temp = $csv_file_dir . '/' . $post_type . 'category_' . $nonce . '.csv';
            $chunk_file_paths = array();
            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);
                exit;
            } else {
                if (!$terms_count > 0) {
                    $json['error'] = __('No records to export.', 'geodirectory');
                } else {
                    $total_terms = $terms_count;
                    if ($chunk_per_page > $terms_count) {
                        $chunk_per_page = $terms_count;
                    }
                    $chunk_total_pages = ceil($total_terms / $chunk_per_page);
                    $j = $chunk_page_no;
                    $chunk_save_terms = geodir_imex_get_terms($post_type, $chunk_per_page, $j);
                    $per_page = 500;
                    if ($per_page > $chunk_per_page) {
                        $per_page = $chunk_per_page;
                    }
                    $total_pages = ceil($chunk_per_page / $per_page);
                    for ($i = 0; $i <= $total_pages; $i++) {
                        $save_terms = array_slice($chunk_save_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)) {
                        $chunk_page_no = $chunk_total_pages > 1 ? '-' . $j : '';
                        $chunk_file_name = $file_name . $chunk_page_no . '.csv';
                        $file_path = $csv_file_dir . '/' . $chunk_file_name;
                        $wp_filesystem->move($file_path_temp, $file_path, true);
                        $file_url = $file_url_base . $chunk_file_name;
                        $chunk_file_paths[] = array('i' => $j . '.', 'u' => $file_url, 's' => size_format(filesize($file_path), 2));
                    }
                    if (!empty($chunk_file_paths)) {
                        $json['total'] = $terms_count;
                        $json['files'] = $chunk_file_paths;
                    } else {
                        $json['error'] = __('Fail, something wrong to create csv file.', 'geodirectory');
                    }
                }
                // WPML
                if ($is_wpml) {
                    $sitepress->switch_lang($active_lang, true);
                }
                // WPML
                wp_send_json($json);
                exit;
            }
            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');
            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']) && geodir_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');
                    }
                } 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_schema = '';
                            $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_schema' && $row[$c] != '') {
                                                        $cat_schema = $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 = geodir_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['cat_schema'] = $cat_schema;
                            $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);
                                }
                                if (isset($term_data['cat_schema'])) {
                                    update_tax_meta($term_id, 'ct_cat_schema', $term_data['cat_schema'], $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') {
                    //run some stuff to make the import quicker
                    wp_defer_term_counting(true);
                    wp_defer_comment_counting(true);
                    $wpdb->query('SET autocommit = 0;');
                    //remove_all_actions('publish_post');
                    //remove_all_actions('transition_post_status');
                    //remove_all_actions('publish_future_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);
                        }
                        $processed_actual = 0;
                        for ($i = 1; $i <= $limit; $i++) {
                            $index = $processed + $i;
                            $gd_post = array();
                            if (isset($file[$index])) {
                                $processed_actual++;
                                $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();
                                $default_category = '';
                                $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 == 'default_category') {
                                                            $default_category = wp_kses_normalize_entities($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] != '' && geodir_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 = geodir_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 (geodir_strtolower($post_city) != geodir_strtolower($location_result->city) || geodir_strtolower($post_region) != geodir_strtolower($location_result->region) || geodir_strtolower($post_country) != geodir_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';
                                if ($default_category != '' && !in_array($default_category, $post_category_arr)) {
                                    $post_category_arr = array_merge(array($default_category), $post_category_arr);
                                }
                                $post_category = array();
                                $default_category_id = NULL;
                                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);
                                                if ($category_name == $default_category) {
                                                    $default_category_id = 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']));
                                        if ($default_category_id) {
                                            $save_post['post_default_category'] = $default_category_id;
                                            $gd_post['default_category'] = $default_category_id;
                                        }
                                        $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'] : '';
                                        if ($default_category_id) {
                                            $post_default_category = $default_category_id;
                                        }
                                        $post_cat_ids = geodir_get_post_meta($saved_post_id, $cat_taxonomy);
                                        $save_post['post_category'] = !empty($post_cat_ids) ? explode(",", trim($post_cat_ids, ",")) : $save_post['post_category'];
                                        $post_category_str = !empty($save_post['post_category']) ? implode(",y:#", $save_post['post_category']) . ',y:' : '';
                                        if ($post_category_str != '' && $post_default_category) {
                                            $post_category_str = str_replace($post_default_category . ',y:', $post_default_category . ',y,d:', $post_category_str);
                                        }
                                        $post_category_str = $post_category_str != '' ? array($cat_taxonomy => $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
                            }
                        }
                    }
                    //undo some stuff to make the import quicker
                    wp_defer_term_counting(false);
                    wp_defer_comment_counting(false);
                    $wpdb->query('COMMIT;');
                    $wpdb->query('SET autocommit = 1;');
                    $json = array();
                    $json['processed'] = $processed_actual;
                    $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;
        case 'import_finish':
            /**
             * Run an action when an import finishes.
             *
             * This action can be used to fire functions after an import ends.
             *
             * @since 1.5.3
             * @package GeoDirectory
             */
            do_action('geodir_import_finished');
            break;
    }
    echo '0';
    wp_die();
}
コード例 #16
0
/**
 * Update review count for each location.
 *
 * @since 1.0.0
 * @package GeoDirectory_Location_Manager
 *
 * @param int $post_id The post ID.
 */
function geodir_term_review_count_update($post_id)
{
    $geodir_posttypes = geodir_get_posttypes();
    $post = get_post($post_id);
    if (isset($post->post_type) && in_array($post->post_type, $geodir_posttypes)) {
        $locations = geodir_get_post_meta($post_id, 'post_locations');
        if ($locations) {
            $array = explode(',', $locations);
            $loc = array();
            $loc['gd_city'] = str_replace(array('[', ']'), '', $array[0]);
            $loc['gd_region'] = str_replace(array('[', ']'), '', $array[1]);
            $loc['gd_country'] = str_replace(array('[', ']'), '', $array[2]);
            foreach ($loc as $key => $value) {
                if ($value != '') {
                    geodir_get_loc_term_count('review_count', $value, $key, true, $loc);
                }
            }
        }
    }
    return;
}