/** * Processes GeoDirectory ajax url calls. * * @see geodir_get_ajax_url() * @since 1.0.0 * @package GeoDirectory * @global object $wpdb WordPress Database object. * @global object $current_user Current user object. * @todo check if nonce is required here and if so add one. */ function geodir_ajax_handler() { global $wpdb; if (isset($_REQUEST['gd_listing_view']) && $_REQUEST['gd_listing_view'] != '') { $_SESSION['gd_listing_view'] = $_REQUEST['gd_listing_view']; echo '1'; } if (isset($_REQUEST['geodir_ajax']) && $_REQUEST['geodir_ajax'] == 'category_ajax') { if (isset($_REQUEST['main_catid']) && isset($_REQUEST['cat_tax']) && isset($_REQUEST['exclude'])) { geodir_addpost_categories_html($_REQUEST['cat_tax'], $_REQUEST['main_catid'], '', '', '', $_REQUEST['exclude']); } elseif (isset($_REQUEST['catpid']) && isset($_REQUEST['cat_tax'])) { geodir_editpost_categories_html($_REQUEST['cat_tax'], $_REQUEST['catpid']); } } if (isset($_REQUEST['geodir_ajax']) && $_REQUEST['geodir_ajax'] == 'admin_ajax' || isset($_REQUEST['create_field']) || isset($_REQUEST['sort_create_field'])) { if (current_user_can('manage_options')) { /** * Contains admin ajax handling functions. * * @since 1.0.0 * @package GeoDirectory */ include_once geodir_plugin_path() . '/geodirectory-admin/geodir_admin_ajax.php'; } else { wp_redirect(home_url() . '/?geodir_signup=true'); exit; } } if (isset($_REQUEST['geodir_autofill']) && $_REQUEST['geodir_autofill'] != '' && isset($_REQUEST['_wpnonce'])) { if (current_user_can('manage_options')) { switch ($_REQUEST['geodir_autofill']) { case "geodir_dummy_delete": if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'geodir_dummy_posts_delete_noncename')) { return; } if (isset($_REQUEST['posttype'])) { /** * Used to delete the dummy post data per post type. * * Uses dynamic hook, geodir_delete_dummy_posts_$_REQUEST['posttype']. * * @since 1.0.0 */ do_action('geodir_delete_dummy_posts_' . $_REQUEST['posttype']); } break; case "geodir_dummy_insert": if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'geodir_dummy_posts_insert_noncename')) { return; } global $dummy_post_index, $city_bound_lat1, $city_bound_lng1, $city_bound_lat2, $city_bound_lng2; $dummy_post_index = $_REQUEST['insert_dummy_post_index']; $city_bound_lat1 = $_REQUEST['city_bound_lat1']; $city_bound_lng1 = $_REQUEST['city_bound_lng1']; $city_bound_lat2 = $_REQUEST['city_bound_lat2']; $city_bound_lng2 = $_REQUEST['city_bound_lng2']; if (isset($_REQUEST['posttype'])) { /** * Used to insert the dummy post data per post type. * * Uses dynamic hook, geodir_insert_dummy_posts_$_REQUEST['posttype']. * * @since 1.0.0 */ do_action('geodir_insert_dummy_posts_' . $_REQUEST['posttype']); } break; } } else { wp_redirect(home_url() . '/?geodir_signup=true'); exit; } } if (isset($_REQUEST['geodir_import_data']) && $_REQUEST['geodir_import_data'] != '') { if (current_user_can('manage_options')) { geodir_import_data(); } else { wp_redirect(home_url() . '/?geodir_signup=true'); exit; } } if (isset($_REQUEST['popuptype']) && $_REQUEST['popuptype'] != '' && isset($_REQUEST['post_id']) && $_REQUEST['post_id'] != '') { if ($_REQUEST['popuptype'] == 'b_send_inquiry' || $_REQUEST['popuptype'] == 'b_sendtofriend') { require_once geodir_plugin_path() . '/geodirectory-templates/popup-forms.php'; } exit; } /*if(isset($_REQUEST['geodir_ajax']) && $_REQUEST['geodir_ajax'] == 'filter_ajax'){ include_once ( geodir_plugin_path() . '/geodirectory-templates/advance-search-form.php'); }*/ if (isset($_REQUEST['geodir_ajax']) && $_REQUEST['geodir_ajax'] == 'map_ajax') { /** * Contains map marker functions. * * @since 1.0.0 * @package GeoDirectory */ include_once geodir_plugin_path() . '/geodirectory-functions/map-functions/get_markers.php'; } if (isset($_REQUEST['geodir_ajax']) && $_REQUEST['geodir_ajax'] == 'favorite') { if (is_user_logged_in()) { switch ($_REQUEST['ajax_action']) { case "add": geodir_add_to_favorite($_REQUEST['pid']); break; case "remove": geodir_remove_from_favorite($_REQUEST['pid']); break; } } else { wp_redirect(home_url() . '/?geodir_signup=true'); exit; } } if (isset($_REQUEST['geodir_ajax']) && $_REQUEST['geodir_ajax'] == 'add_listing') { $is_current_user_owner = true; if (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') { $is_current_user_owner = geodir_listing_belong_to_current_user($_REQUEST['pid']); } $request = isset($_SESSION['listing']) ? unserialize($_SESSION['listing']) : ''; if (is_user_logged_in() && $is_current_user_owner) { switch ($_REQUEST['ajax_action']) { case "add": case "update": if (isset($request['geodir_spamblocker']) && $request['geodir_spamblocker'] == '64' && isset($request['geodir_filled_by_spam_bot']) && $request['geodir_filled_by_spam_bot'] == '') { $last_id = geodir_save_listing(); if ($last_id) { //$redirect_to = get_permalink( $last_id ); $redirect_to = geodir_getlink(get_permalink(geodir_success_page_id()), array('pid' => $last_id)); } elseif (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') { $redirect_to = get_permalink(geodir_add_listing_page_id()); $redirect_to = geodir_getlink($redirect_to, array('pid' => $post->pid), false); } else { $redirect_to = get_permalink(geodir_add_listing_page_id()); } wp_redirect($redirect_to); } else { if (isset($_SESSION['listing'])) { unset($_SESSION['listing']); } wp_redirect(home_url()); } break; case "cancel": unset($_SESSION['listing']); if (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '' && get_permalink($_REQUEST['pid'])) { wp_redirect(get_permalink($_REQUEST['pid'])); } else { geodir_remove_temp_images(); wp_redirect(geodir_getlink(get_permalink(geodir_add_listing_page_id()), array('listing_type' => $_REQUEST['listing_type']))); } break; case "publish": if (isset($request['geodir_spamblocker']) && $request['geodir_spamblocker'] == '64' && isset($request['geodir_filled_by_spam_bot']) && $request['geodir_filled_by_spam_bot'] == '') { if (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') { $new_post = array(); $new_post['ID'] = $_REQUEST['pid']; //$new_post['post_status'] = 'publish'; $lastid = wp_update_post($new_post); if (isset($_SESSION['listing'])) { unset($_SESSION['listing']); } wp_redirect(get_permalink($lastid)); } else { $last_id = geodir_save_listing(); if ($last_id) { //$redirect_to = get_permalink( $last_id ); $redirect_to = geodir_getlink(get_permalink(geodir_success_page_id()), array('pid' => $last_id)); } elseif (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') { $redirect_to = get_permalink(geodir_add_listing_page_id()); $redirect_to = geodir_getlink($redirect_to, array('pid' => $post->pid), false); } else { $redirect_to = get_permalink(geodir_add_listing_page_id()); } if (isset($_SESSION['listing'])) { unset($_SESSION['listing']); } wp_redirect($redirect_to); } } else { if (isset($_SESSION['listing'])) { unset($_SESSION['listing']); } wp_redirect(home_url()); } break; case "delete": if (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') { global $current_user; get_currentuserinfo(); $post_type = get_post_type($_REQUEST['pid']); $lastid = wp_delete_post($_REQUEST['pid']); if ($lastid && !is_wp_error($lastid)) { wp_redirect($_SERVER['HTTP_REFERER']); } //wp_redirect( geodir_getlink(get_author_posts_url($current_user->ID),array('geodir_dashbord'=>'true','stype'=>$post_type ),false) ); } break; } if (isset($_SESSION['listing'])) { unset($_SESSION['listing']); } } else { if (isset($_SESSION['listing'])) { unset($_SESSION['listing']); } wp_redirect(home_url() . '/?geodir_signup=true'); exit; } } if (isset($_REQUEST['geodir_ajax']) && $_REQUEST['geodir_ajax'] == 'user_login') { /** * Contains registration and login functions. * @todo Fix the file path. * * @since 1.0.0 * @package GeoDirectory */ include_once geodir_plugin_path() . '/geodirectory-functions/geodirectory_reg.php'; } if (isset($_REQUEST['ajax_action']) && $_REQUEST['ajax_action'] == 'geodir_get_term_list') { $terms_o = get_terms(sanitize_text_field($_REQUEST['term'])); // Skip terms which has no listing if (!empty($terms_o)) { $filter_terms = array(); foreach ($terms_o as $term) { if ($term->count > 0) { $filter_terms[] = $term; } } $terms_o = $filter_terms; } $terms = geodir_sort_terms($terms_o, 'count'); geodir_helper_cat_list_output($terms, intval($_REQUEST['limit'])); exit; } die; }
/** * Outputs the edit post link. * * Outputs the edit post link if the current logged in user owns the post. * * @global bool $preview True if the current page is add listing preview page. False if not. * @global WP_Post|null $post The current post, if available. * @since 1.0.0 * @package GeoDirectory */ function geodir_edit_post_link() { global $post, $preview; ob_start(); // Start buffering; /** * This is called before the edit post link html in the function geodir_edit_post_link() * * @since 1.0.0 */ do_action('geodir_before_edit_post_link'); if (!$preview) { //if(is_user_logged_in() && $post->post_author == get_current_user_id()) $is_current_user_owner = geodir_listing_belong_to_current_user(); if ($is_current_user_owner) { $post_id = $post->ID; if (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') { $post_id = esc_attr($_REQUEST['pid']); } $postlink = get_permalink(geodir_add_listing_page_id()); $editlink = geodir_getlink($postlink, array('pid' => $post_id), false); echo ' <p class="edit_link"><i class="fa fa-pencil"></i> <a href="' . $editlink . '">' . __('Edit this Post', 'geodirectory') . '</a></p>'; } } // end of if, if its a preview or not /** * This is called after the edit post link html in the function geodir_edit_post_link() * * @since 1.0.0 */ do_action('geodir_after_edit_post_link'); $content_html = ob_get_clean(); if (trim($content_html) != '') { $content_html = '<div class="geodir-company_info geodir-details-sidebar-user-links">' . $content_html . '</div>'; } if ((int) get_option('geodir_disable_user_links_section') != 1) { /** * Filter the geodir_edit_post_link() function content. * * @param string $content_html The output html of the geodir_edit_post_link() function. */ echo $content_html = apply_filters('geodir_edit_post_link_html', $content_html); } }
/** * Loads template based on the current page. * * @since 1.0.0 * @package GeoDirectory * @global object $wp_query WordPress Query object. * @todo $wp_query declared twice - fix it. * @global object $post The current post object. * @global object $current_user Current user object. * @param string $template The template path. * @return bool|string The template path. */ function geodir_template_loader($template) { global $wp_query; /** * Filter the custom page list. * * @since 1.0.0 */ $geodir_custom_page_list = apply_filters('geodir_set_custom_pages', array('geodir_signup_page' => apply_filters('geodir_set_custom_signup_page', false), 'geodir_add_listing_page' => apply_filters('geodir_set_custom_add_listing_page', false), 'geodir_preview_page' => apply_filters('geodir_set_custom_preview_page', false), 'geodir_listing_success_page' => apply_filters('geodir_set_custom_listing_success_page', false), 'geodir_listing_detail_page' => apply_filters('geodir_set_custom_listing_detail_page', false), 'geodir_listing_page' => apply_filters('geodir_set_custom_listing_page', false), 'geodir_search_page' => apply_filters('geodir_set_custom_search_page', false), 'geodir_author_page' => apply_filters('geodir_set_custom_author_page', false), 'geodir_home_map_page' => apply_filters('geodir_set_custom_home_map_page', false))); if (geodir_is_page('login') || $geodir_custom_page_list['geodir_signup_page']) { $template = geodir_locate_template('signup'); if (!$template) { $template = geodir_plugin_path() . '/geodirectory-templates/geodir-signup.php'; } /** * Filter the signup template path. * * @since 1.0.0 * @param string $template The template path. */ return $template = apply_filters('geodir_template_signup', $template); } if (geodir_is_page('add-listing') || $geodir_custom_page_list['geodir_add_listing_page']) { if (!geodir_is_default_location_set()) { global $information; $information = sprintf(__('Please %sclick here%s to set a default location, this will make the plugin work properly.', 'geodirectory'), '<a href=\'' . admin_url('admin.php?page=geodirectory&tab=default_location_settings') . '\'>', '</a>'); $template = geodir_locate_template('information'); if (!$template) { $template = geodir_plugin_path() . '/geodirectory-templates/geodir-information.php'; } /** * Filter the information template path. * * @since 1.0.0 * @param string $template The template path. */ return $template = apply_filters('geodir_template_information', $template); } // check if pid exists in the record if yes then check if this post belongs to the user who is logged in. if (isset($_REQUEST['pid']) && $_REQUEST['pid'] != '') { global $information; $information = __('This listing does not belong to your account, please check the listing id carefully.', 'geodirectory'); $is_current_user_owner = geodir_listing_belong_to_current_user(); if (!$is_current_user_owner) { $template = geodir_locate_template('information'); if (!$template) { $template = geodir_plugin_path() . '/geodirectory-templates/geodir-information.php'; } /** * Filter the information template path. * * @since 1.0.0 * @param string $template The template path. */ return $template = apply_filters('geodir_template_information', $template); } } //geodir_is_login(true); global $current_user; if (!$current_user->ID) { wp_redirect(geodir_login_url(array('redirect_add_listing' => urlencode(geodir_curPageURL()))), 302); exit; } $template = geodir_locate_template('add-listing'); if (!$template) { $template = geodir_plugin_path() . '/geodirectory-templates/add-listing.php'; } /** * Filter the add listing template path. * * @since 1.0.0 * @param string $template The template path. */ return $template = apply_filters('geodir_template_add_listing', $template); } if (geodir_is_page('preview') || $geodir_custom_page_list['geodir_preview_page']) { global $preview; $preview = true; $template = geodir_locate_template('preview'); if (!$template) { $template = geodir_plugin_path() . '/geodirectory-templates/listing-detail.php'; } /** * Filter the preview template path. * * @since 1.0.0 * @param string $template The template path. */ return $template = apply_filters('geodir_template_preview', $template); } if (geodir_is_page('listing-success') || $geodir_custom_page_list['geodir_listing_success_page']) { $template = geodir_locate_template('success'); if (!$template) { $template = geodir_plugin_path() . '/geodirectory-templates/listing-success.php'; } /** * Filter the success template path. * * @since 1.0.0 * @param string $template The template path. */ return $template = apply_filters('geodir_template_success', $template); } if (geodir_is_page('detail') || $geodir_custom_page_list['geodir_listing_detail_page']) { $template = geodir_locate_template('detail'); if (!$template) { $template = geodir_plugin_path() . '/geodirectory-templates/listing-detail.php'; } /** * Filter the detail template path. * * @since 1.0.0 * @param string $template The template path. */ return $template = apply_filters('geodir_template_detail', $template); } if (geodir_is_page('listing') || $geodir_custom_page_list['geodir_listing_page']) { $template = geodir_locate_template('listing'); if (!$template) { $template = geodir_plugin_path() . '/geodirectory-templates/geodir-listing.php'; } /** * Filter the listing template path. * * @since 1.0.0 * @param string $template The template path. */ return $template = apply_filters('geodir_template_listing', $template); } if (geodir_is_page('search') || $geodir_custom_page_list['geodir_search_page']) { $template = geodir_locate_template('search'); if (!$template) { $template = geodir_plugin_path() . '/geodirectory-templates/geodir-search.php'; } /** * Filter the search template path. * * @since 1.0.0 * @param string $template The template path. */ return $template = apply_filters('geodir_template_search', $template); } if (geodir_is_page('author') || $geodir_custom_page_list['geodir_author_page']) { $template = geodir_locate_template('author'); if (!$template) { $template = geodir_plugin_path() . '/geodirectory-templates/geodir-author.php'; } /** * Filter the author template path. * * @since 1.0.0 * @param string $template The template path. */ return $template = apply_filters('geodir_template_author', $template); } if (get_option('geodir_set_as_home') || geodir_is_page('home') || geodir_is_page('location')) { global $post, $wp_query; if (geodir_is_page('home') || 'page' == get_option('show_on_front') && isset($post->ID) && $post->ID == get_option('page_on_front') || is_home() && !$wp_query->is_posts_page) { $template = geodir_locate_template('geodir-home'); if (!$template) { $template = geodir_plugin_path() . '/geodirectory-templates/geodir-home.php'; } /** * Filter the home page template path. * * @since 1.0.0 * @param string $template The template path. */ return $template = apply_filters('geodir_template_homepage', $template); } elseif (geodir_is_page('location')) { $template = geodir_locate_template('location'); if (!$template) { $template = geodir_plugin_path() . '/geodirectory-templates/geodir-location.php'; } /** * Filter the location template path. * * @since 1.0.0 * @param string $template The template path. */ return $template = apply_filters('geodir_template_location', $template); } else { return $template; } } return $template; }