function filter_search_widget($args)
 {
     $data = get_option('filter_search_widget');
     $data["echo_this"] = true;
     echo $args['before_widget'];
     echo $args['before_title'] . __("Filter Listings", "bepro-listings") . $args['after_title'];
     echo Bepro_listings::search_filter_options($data);
     echo $args['after_widget'];
 }
function load_constants()
{
    // The main slug
    if (!defined('BEPRO_LISTINGS_SLUG')) {
        define('BEPRO_LISTINGS_SLUG', 'Listings');
    }
    // The slug used when editing a doc
    if (!defined('BEPRO_LISTINGS_LIST_SLUG')) {
        define('BEPRO_LISTINGS_LIST_SLUG', 'List');
    }
    // The slug used when editing a doc
    if (!defined('BEPRO_LISTINGS_EDIT_SLUG')) {
        define('BEPRO_LISTINGS_EDIT_SLUG', 'edit');
    }
    // The slug used when creating a new doc
    if (!defined('BEPRO_LISTINGS_CREATE_SLUG')) {
        define('BEPRO_LISTINGS_CREATE_SLUG', 'Create');
    }
    // The slug used when saving new docs
    if (!defined('BEPRO_LISTINGSS_SAVE_SLUG')) {
        define('BEPRO_UPLOADS_SAVE_SLUG', 'save');
    }
    // The slug used when deleting a doc
    if (!defined('BEPRO_LISTINGS_DELETE_SLUG')) {
        define('BEPRO_LISTINGS_DELETE_SLUG', 'delete');
    }
    // The slug used when deleting a doc
    if (!defined('BEPRO_LISTINGS_SEARCH_SLUG')) {
        define('BEPRO_LISTINGS_SEARCH_SLUG', 'listings');
    }
    // The plugin path
    if (!defined('BEPRO_LISTINGS_PLUGIN_PATH')) {
        define('BEPRO_LISTINGS_PLUGIN_PATH', plugins_url("", __FILE__));
    }
    // Plugin Slug
    if (!defined('BEPRO_LISTINGS_CATEGORY')) {
        define('BEPRO_LISTINGS_CATEGORY', "bepro_listing_types");
    }
    // Category Slug
    if (!defined('BEPRO_LISTINGS_CATEGORY')) {
        define('BEPRO_LISTINGS_CATEGORY', "bepro_listing_types");
    }
    // The Main table name (check if multisite)
    if (function_exists('is_multisite') && is_multisite()) {
        global $wpdb;
        $cur_blog_id = $wpdb->blogid == 1 ? "" : $wpdb->blogid . '_';
        define('BEPRO_LISTINGS_TABLE_NAME', $cur_blog_id . 'bepro_listings');
    } else {
        if (!defined('BEPRO_LISTINGS_TABLE_NAME')) {
            define('BEPRO_LISTINGS_TABLE_NAME', 'bepro_listings');
        }
    }
    // Base Table Name
    if (!defined('BEPRO_LISTINGS_TABLE_BASE')) {
        define('BEPRO_LISTINGS_TABLE_BASE', 'bepro_listings');
    }
    // Current version
    if (!defined('BEPRO_LISTINGS_VERSION')) {
        define('BEPRO_LISTINGS_VERSION', '2.1.28');
    }
    $data = get_option("bepro_listings");
    if (empty($data)) {
        Bepro_listings::bepro_listings_activate();
    }
    //Load Languages
    load_plugin_textdomain('bepro-listings', false, dirname(plugin_basename(__FILE__)) . '/languages/');
    //load default options if they dont already exist
    if (empty($data["bepro_listings_list_template_1"])) {
        //general
        $data["show_cost"] = "on";
        $data["show_con"] = "on";
        $data["show_geo"] = "on";
        $data["num_images"] = 3;
        $data["cat_heading"] = "Categories";
        $data["cat_empty"] = "No Categories";
        $data["cat_singular"] = "Category";
        //forms
        $data["validate_form"] = "on";
        $data["success_message"] = 'Listing Created and pending admin approval.';
        $data["default_status"] = 'pending';
        $data["default_user_id"] = get_current_user_id();
        $data["fail_message"] = "Issue saving listing. Try again or contact the Admin";
        $data["bepro_listings_cat_required"] = "";
        $data["bepro_listings_cat_exclude"] = "";
        //search listings
        $data["default_image"] = plugins_url("images/no_img.jpg", __FILE__);
        $data["link_new_page"] = 1;
        $data["ajax_on"] = "on";
        $data["num_listings"] = 3;
        $data["distance"] = 150;
        $data["details_link"] = "Item";
        $data["show_web_link"] = "";
        $data["currency_sign"] = "\$";
        $data["show_date"] = 1;
        //Page/post
        $data["gallery_size"] = "thumbnail";
        $data["gallery_cols"] = 3;
        $data["show_details"] = "on";
        $data["add_detail_links"] = "on";
        $data["show_content"] = "on";
        //map
        $data["map_query_type"] = "curl";
        //buddypress
        $data["buddypress"] = 0;
        //Support
        $data["footer_link"] = 0;
        //item page template
        $data['bepro_listings_item_title_template'] = 'bepro_listings_item_title';
        $data['bepro_listings_item_gallery_template'] = "bepro_listings_item_gallery";
        $data['bepro_listings_item_after_gallery_template'] = "bepro_listings_item_after_gallery";
        $data['bepro_listings_item_details_template'] = 'bepro_listings_item_details';
        $data['bepro_listings_item_content_template'] = 'bepro_listings_item_content_info';
        //item list template
        $data['bepro_listings_list_template_1'] = array("bepro_listings_list_title" => "bepro_listings_list_title_template", "bepro_listings_list_above_image" => "bepro_listings_list_featured_template", "bepro_listings_list_below_title" => "bepro_listings_list_category_template", "bepro_listings_list_image" => "bepro_listings_list_image_template", "bepro_listings_list_content" => "bepro_listings_list_content_template", "bepro_listings_list_end" => "bepro_listings_list_cost_template", "bepro_listings_list_end" => "bepro_listings_list_links_template", "style" => plugins_url("css/generic_listings_1.css", __FILE__), "template_file" => plugin_dir_path(__FILE__) . '/templates/listings/generic_1.php');
        $data['bepro_listings_list_template_2'] = array("bepro_listings_list_title" => "bepro_listings_list_title_template", "bepro_listings_list_above_image" => "bepro_listings_list_featured_template", "bepro_listings_list_below_title" => "bepro_listings_list_category_template", "bepro_listings_list_above_title" => "bepro_listings_list_image_template", "bepro_listings_list_image" => "bepro_listings_list_geo_template", "bepro_listings_list_content" => "bepro_listings_list_content_template", "bepro_listings_list_end" => "bepro_listings_list_cost_template", "bepro_listings_list_end" => "bepro_listings_list_links_template", "style" => plugins_url("css/generic_listings_2.css", __FILE__), "template_file" => plugin_dir_path(__FILE__) . '/templates/listings/generic_2.php');
        //save
        update_option("bepro_listings", $data);
    }
    //Things that need to change only if there is an upgrade
    $bepro_listings_version = get_option("bepro_listings_version");
    if ($bepro_listings_version != BEPRO_LISTINGS_VERSION) {
        $bepro_listings_version = get_option("bepro_listings_version");
        $data["cat_heading"] = "Categories";
        $data["cat_empty"] = "No Categories";
        $data["cat_singular"] = "Category";
        update_option("bepro_listings", $data);
    }
}
function process_listings_results($show_paging = false, $num_results = false, $l_type = false, $l_ids = false, $order_by = 1, $order_dir = 1)
{
    global $wpdb;
    if (!empty($_REQUEST["filter_search"]) || !empty($l_type)) {
        if (is_array($l_type) && @isset($l_type[0]) && $l_type[0] == 0) {
            $l_type = "";
        }
        $returncaluse = Bepro_listings::listitems(array('l_type' => $l_type));
        $filter_cat = true;
    }
    if (!empty($l_ids)) {
        $returncaluse .= " AND posts.ID IN ({$l_ids})";
    }
    if ($order_by == 1) {
        $order_by = "posts.post_title";
    } else {
        if ($order_by == 2) {
            $order_by = "RAND()";
        } else {
            if ($order_by == 3) {
                $order_by = "geo.last_name";
            } else {
                $order_by = "posts.post_date";
            }
        }
    }
    $order_dir = $order_dir == 1 || empty($order_dir) ? "ASC" : "DESC";
    //Handle Paging selection calculations and process listings
    $page = empty($_REQUEST["lpage"]) ? 1 : $_REQUEST["lpage"];
    $page = ($page - 1) * $num_results;
    $limit_clause = " ORDER BY {$order_by} {$order_dir} LIMIT {$page} , {$num_results}";
    $resvs = bepro_get_listings($returncaluse, $filter_cat);
    $pages = ceil(count($resvs) / $num_results);
    $findings[1] = $pages;
    $raw_results = bepro_get_listings($returncaluse, $filter_cat, $limit_clause);
    $findings[0] = $raw_results;
    return $findings;
}
function bepro_listings_status()
{
    global $wpdb;
    $data = get_option("bepro_listings");
    //setup google api check
    $_POST["address_line1"] = "220 e university blvd";
    $_POST["postcode"] = "32901";
    $lat_lon = @get_bepro_lat_lon();
    //setup database table checks
    $table_name = $wpdb->prefix . BEPRO_LISTINGS_TABLE_BASE;
    //setup filepath check
    $plugin_url = @Bepro_listings::get_bpl_plugin_url();
    echo "\n\t\t\t<h1>" . __("BePro Listings Status", "bepro-listings") . "</h1>\n\t\t\t<p>" . __("This page shows how the plugin is performing. This is the first place to look when trying to diagnose issues.", "bepro-listings") . "</p>\n\t\t\t<table class='bpl_status_display_table'>\n\t\t\t\t<thead><tr><td colspan='2'>" . __("BePro Listings", "bepro-listings") . "</td></tr></thead>\n\t\t\t\t<tr><td>" . __("Database Tables", "bepro-listings") . "</td><td>" . ($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") != $table_name ? "<span class='bpl_error'>" . __("ERROR", "bepro-listings") . "</span>" : "OK") . "</td></tr>\n\t\t\t\t<tr><td>" . __("File Path", "bepro-listings") . "</td><td>" . $plugin_url . "</td></tr>\n\t\t\t\t<tr><td>" . __("Google API", "bepro-listings") . "</td><td>" . $lat_lon["status"] . "</td></tr>\n\t\t\t\t<tr><td>" . __("Result Templates", "bepro-listings") . "</td><td>" . (empty($data["bepro_listings_list_template_1"]) ? "<span class='bpl_error'>" . __("ERROR", "bepro-listings") . "</span>" : "OK") . "</td></tr>\n\t\t\t</table>\n\t\t\t<table class='bpl_status_display_table'>\n\t\t\t\t<thead><tr><td colspan='2'>" . __("PHP", "bepro-listings") . "</td></tr></thead>\n\t\t\t\t<tr><td>" . __("CURL", "bepro-listings") . "</td><td>" . (function_exists('curl_version') ? "OK" : "<span class='bpl_error'>" . __("ERROR", "bepro-listings") . "</span>") . "</td></tr>\n\t\t\t\t<tr><td>" . __("File Get Contents", "bepro-listings") . "</td><td>" . (function_exists('file_get_contents') ? "OK" : "<span class='bpl_error'>" . __("ERROR", "bepro-listings") . "</span>") . "</td></tr>\n\t\t\t\t<tr><td>" . __("Memory Limit", "bepro-listings") . "</td><td>" . ini_get("memory_limit") . "</td></tr>\n\t\t\t\t<tr><td>" . __("Max Upload Size", "bepro-listings") . "</td><td>" . ini_get("upload_max_filesize") . "</td></tr>\n\t\t\t\t<tr><td>" . __("PHP Time Limit", "bepro-listings") . "</td><td>" . ini_get("max_execution_time") . "</td></tr>\n\t\t\t\t<tr><td>" . __("ASP Tags", "bepro-listings") . "</td><td>" . (ini_get("asp_tags") ? "ON" : "OFF") . "</td></tr>\n\t\t\t</table>\n\t\t\t<table class='bpl_status_display_table'>\n\t\t\t\t<thead><tr><td colspan='2'>" . __("SERVER", "bepro-listings") . "</td></tr></thead>\n\t\t\t\t<tr><td>" . __("Type", "bepro-listings") . "</td><td>" . $_SERVER["SERVER_SOFTWARE"] . "</td></tr>\n\t\t\t\t<tr><td>" . __("IP Address", "bepro-listings") . "</td><td>" . $_SERVER["SERVER_ADDR"] . "</td></tr>\n\t\t\t\t<tr><td>" . __("Protocol", "bepro-listings") . "</td><td>" . (empty($_SERVER["HTTPS"]) ? "HTTP" : "HTTPS") . "</td></tr>\n\t\t\t</table>\n\t\t";
    do_action("bpl_admin_status_page");
}
function bl_complete_startup()
{
    global $wpdb;
    $data = get_option("bepro_listings");
    if (empty($data)) {
        Bepro_listings::bepro_listings_activate();
    }
    //Load Languages
    load_plugin_textdomain('bepro-listings', false, dirname(plugin_basename(__FILE__)) . '/languages/');
    //load default options if they dont already exist
    if (empty($data["bepro_listings_list_template_1"])) {
        //general
        $data["show_cost"] = 1;
        $data["show_con"] = 1;
        $data["show_geo"] = 1;
        $data["show_imgs"] = 1;
        $data["num_images"] = 3;
        $data["cat_heading"] = __("Categories", "bepro-listings");
        $data["cat_empty"] = __("No Sub Categories", "bepro-listings");
        $data["cat_singular"] = __("Category", "bepro-listings");
        $data["permalink"] = "/" . BEPRO_LISTINGS_SEARCH_SLUG;
        $data["cat_permalink"] = "/" . BEPRO_LISTINGS_CATEGORY_SLUG;
        //forms
        $data["validate_form"] = "on";
        $data["success_message"] = __('Listing Created and pending admin approval.', "bepro-listings");
        $data["use_tiny_mce"] = "";
        $data["default_status"] = 'pending';
        $data["default_user_id"] = get_current_user_id();
        $data["fail_message"] = __("Issue saving listing. Try again or contact the Admin", "bepro-listings");
        $data["form_cat_style"] = 2;
        $data["bepro_listings_cat_required"] = "";
        $data["bepro_listings_cat_exclude"] = "";
        //search listings
        $data["default_image"] = plugins_url("images/no_img.jpg", __FILE__);
        $data["link_new_page"] = 1;
        $data["ajax_on"] = "on";
        $data["num_listings"] = 8;
        $data["distance"] = 150;
        $data["dist_measurement"] = 1;
        $data["search_names"] = 1;
        $data["title_length"] = 18;
        $data["desc_length"] = 80;
        $data["details_link"] = __("Item", "bepro-listings");
        $data["show_web_link"] = "";
        $data["currency_sign"] = "\$";
        $data["show_date"] = 1;
        //Page/post
        $data["gallery_size"] = "thumbnail";
        $data["gallery_cols"] = 3;
        $data["gallery_cols"] = 1;
        $data["show_details"] = 2;
        $data["add_detail_links"] = "on";
        $data["protect_contact"] = "";
        $data["show_content"] = 1;
        $data["tabs_type"] = 1;
        //map
        $data["map_query_type"] = "curl";
        $data["map_use_api"] = 1;
        $data["map_zoom"] = "10";
        //3rd party
        $data["buddypress"] = 0;
        //Payment
        $data["require_payment"] = "";
        $data["publish_after_payment"] = "";
        $data["redirect_need_funds"] = 1;
        $data["charge_amount"] = 1;
        //Support
        $data["footer_link"] = 0;
        //item page template
        $data['bepro_listings_item_title_template'] = 'bepro_listings_item_title';
        $data['bepro_listings_item_gallery_template'] = "bepro_listings_item_gallery";
        $data['bepro_listings_item_after_gallery_template'] = "bepro_listings_item_after_gallery";
        $data['bepro_listings_item_details_template'] = 'bepro_listings_item_details';
        $data['bepro_listings_item_content_template'] = 'bepro_listings_item_content_info';
        //item list template
        $data = create_result_listing_templates($data);
        //save
        update_option("bepro_listings", $data);
    }
    //Things that need to change only if there is an upgrade
    $bepro_listings_version = get_option("bepro_listings_version");
    if (version_compare($bepro_listings_version, '2.1.5', '<')) {
        //upgrade tables to utf8
        if (is_numeric(substr($wpdb->prefix, -2, 1)) && is_multisite()) {
            $blogids = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs}");
            foreach ($blogids as $blogid_x) {
                $wpdb->query("ALTER TABLE " . $wpdb->base_prefix . $blogid_x . "_" . BEPRO_LISTINGS_TABLE_BASE . " CONVERT TO CHARACTER SET utf8;");
            }
        } else {
            $wpdb->query("ALTER TABLE " . $wpdb->base_prefix . BEPRO_LISTINGS_TABLE_BASE . " CONVERT TO CHARACTER SET utf8;");
        }
    }
    if (version_compare($bepro_listings_version, '2.1.90', '<')) {
        $data["map_use_api"] = 1;
        $data["map_zoom"] = "10";
        $data["show_imgs"] = 1;
    }
    if (version_compare($bepro_listings_version, '2.1.992', '<')) {
        //support for BePro Cart
        if (is_numeric(substr($wpdb->prefix, -2, 1)) && is_multisite()) {
            $blogids = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs}");
            foreach ($blogids as $blogid_x) {
                if ($blogid_x == 1) {
                    $blogid_x = "";
                } else {
                    $blogid_x = $blogid_x . "_";
                }
                $wpdb->query("ALTER TABLE " . $wpdb->base_prefix . $blogid_x . BEPRO_LISTINGS_TABLE_BASE . " ADD COLUMN bl_order_id int(9) DEFAULT NULL AFTER lon, DROP COLUMN bepro_cart_id;");
                //install new payments table
                create_bl_order_table($wpdb->base_prefix . $blogid_x . BEPRO_LISTINGS_ORDERS_TABLE_BASE);
            }
        } else {
            $wpdb->query("ALTER TABLE " . $wpdb->base_prefix . BEPRO_LISTINGS_TABLE_BASE . " ADD COLUMN bl_order_id int(9) DEFAULT NULL AFTER lon, DROP COLUMN bepro_cart_id;");
            //install new payments table
            create_bl_order_table($wpdb->base_prefix . BEPRO_LISTINGS_ORDERS_TABLE_BASE);
        }
        //flat fee now works differently
        if ($data["flat_fee"]) {
            unset($data["flat_fee"]);
        }
    }
    if (version_compare($bepro_listings_version, '2.1.999', '<')) {
        if (is_numeric(substr($wpdb->prefix, -2, 1)) && is_multisite()) {
            $blogids = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs}");
            foreach ($blogids as $blogid_x) {
                if ($blogid_x == 1) {
                    $blogid_x = "";
                } else {
                    $blogid_x = $blogid_x . "_";
                }
                $tbl_1 = $wpdb->base_prefix . $blogid_x . BEPRO_LISTINGS_ORDERS_TABLE_BASE;
                $tbl_2 = $wpdb->base_prefix . $blogid_x . BEPRO_LISTINGS_TABLE_BASE;
                $wpdb->query("ALTER TABLE " . $tbl_1 . " ADD COLUMN expires DATETIME DEFAULT NULL AFTER date_paid;");
                $orders = $wpdb->get_results("SELECT * FROM " . $tbl_1);
                foreach ($orders as $order) {
                    $record = $wpdb->get_row("SELECT * FROM " . $tbl_2 . " WHERE bl_order_id = " . $order->bl_order_id . " LIMIT 1");
                    if ($record) {
                        $wpdb->query("UPDATE " . $tbl_1 . " SET expires = '" . $record->expires . "' WHERE bl_order_id = " . $record->bl_order_id);
                    }
                }
                $wpdb->query("ALTER TABLE " . $tbl_2 . " DROP COLUMN expires;");
            }
        } else {
            $tbl_1 = $wpdb->prefix . BEPRO_LISTINGS_ORDERS_TABLE_BASE;
            $tbl_2 = $wpdb->prefix . BEPRO_LISTINGS_TABLE_BASE;
            $wpdb->query("ALTER TABLE " . $tbl_1 . " ADD COLUMN expires DATETIME DEFAULT NULL AFTER date_paid;");
            $orders = $wpdb->get_results("SELECT * FROM " . $tbl_1);
            foreach ($orders as $order) {
                $record = $wpdb->get_row("SELECT * FROM " . $tbl_2 . " WHERE bl_order_id = " . $order->bl_order_id . " LIMIT 1");
                if (@$record) {
                    $wpdb->query("UPDATE " . $tbl_1 . " SET expires = '" . $record->expires . "' WHERE bl_order_id = " . $record->bl_order_id);
                }
            }
            $wpdb->query("ALTER TABLE " . $tbl_2 . " DROP COLUMN expires;");
        }
    }
    if (version_compare($bepro_listings_version, '2.1.9994', '<')) {
        if (!empty($data["show_cost"])) {
            $data["show_cost"] = 1;
        }
        if (!empty($data["show_con"])) {
            $data["show_con"] = 1;
        }
        if (!empty($data["show_geo"])) {
            $data["show_geo"] = 1;
        }
        if (!empty($data["show_imgs"])) {
            $data["show_imgs"] = 1;
        }
        $data["show_details"] = 2;
        $data["show_content"] = 1;
    }
    if (version_compare($bepro_listings_version, '2.1.99995', '<')) {
        if ($data["show_details"] == "on") {
            $data["show_details"] = 2;
        }
        if ($data["show_content"] == "on") {
            $data["show_content"] = 1;
        }
        if ($data["show_geo"] == "on") {
            $data["show_geo"] = 1;
        }
        if ($data["show_con"] == "on") {
            $data["show_con"] = 1;
        }
    }
    if (version_compare($bepro_listings_version, '2.2.0004', '<')) {
        if (empty($data["desc_length"])) {
            $data["desc_length"] = 80;
        }
    }
    if ($bepro_listings_version != BEPRO_LISTINGS_VERSION) {
        $bepro_listings_version = BEPRO_LISTINGS_VERSION;
        //new features
        //show welcome screen to users who are updating
        set_transient('_bepro_listings_activation_redirect', 1, HOUR_IN_SECONDS);
        //set version
        update_option('bepro_listings_version', $bepro_listings_version);
    }
}
 function bepro_listings_activate()
 {
     global $wpdb;
     Bepro_listings::flush_permalinks();
     if (function_exists('is_multisite') && is_multisite()) {
         $blogids = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM {$wpdb->blogs}"));
         foreach ($blogids as $blogid_x) {
             bepro_listings_install_table($blogid_x);
         }
     } else {
         bepro_listings_install_table();
     }
 }