hSearch.php

The hSearch.php helper in Osclass is designed to facilitate all aspects of search functionality on your classifieds website. It provides functions to retrieve the search object, obtain search criteria (such as selected region, city, price range, and category), generate dynamic search URLs with updated parameters, and manage the presentation of search results. In addition, the helper offers functions for listing locations on the sidebar and for handling the latest searches performed by users.

Functions Description

osc_search() – Gets the search object.

osc_list_orders() – Retrieves the available search orders.

osc_search_page() – Gets the current search page number.

osc_search_total_pages() – Gets the total number of pages for the current search.

osc_search_has_pic() – Returns true if the “has pic” option is enabled in the search; otherwise, false.

osc_search_order() – Gets the current search order.

osc_search_order_type() – Gets the current search order type.

osc_search_pattern() – Gets the current search pattern.

osc_search_region() – Gets the current search region.

osc_search_city() – Gets the current search city.

osc_search_price_max() – Gets the current search maximum price.

osc_search_price_min() – Gets the current search minimum price.

osc_search_total_items() – Gets the total number of items matching the current search criteria.

osc_search_show_as() – Gets the current “show as” setting for search results (e.g., list or gallery view).

osc_search_start() – Gets the starting record number for the current search results.

osc_search_end() – Gets the ending record number for the current search results.

osc_search_category() – Gets the current search category.

osc_search_category_id() – Gets the current search category ID.

osc_update_search_url($params, $delimiter = '&') – Updates the search URL with new options.

osc_alert_form() – Loads the form for alert subscription.

osc_search_alert() – Retrieves the alert for the current search.

osc_search_show_all_url() – Gets the URL for a default search (all categories, with no additional options).

osc_search_url($params = null) – Generates a search URL based on the provided parameters.

Location Listing Helpers (Sidebar)

osc_list_country() – Gets the list of countries with items.

osc_list_region() – Gets the list of regions with items.

osc_list_city() – Gets the list of cities with items.

osc_has_list_countries() – Retrieves the next country from the list of countries.

osc_has_list_regions($country = '%%%%') – Retrieves the next region from the list of regions for a given country.

osc_has_list_cities($region = '%%%%') – Retrieves the next city from the list of cities for a given region.

osc_count_list_countries() – Gets the total number of countries in the list.

osc_count_list_regions($country = '%%%%') – Gets the total number of regions for the given country.

osc_count_list_cities($region = '%%%%') – Gets the total number of cities for the given region.

osc_list_region_name() – Gets the name of the current list region.

osc_list_region_items() – Gets the number of items in the current list region.

osc_list_city_name() – Gets the name of the current list city.

osc_list_city_items() – Gets the number of items in the current list city.

osc_list_country_url() – Gets the URL for the current list country.

osc_list_region_url() – Gets the URL for the current list region.

osc_list_city_url() – Gets the URL for the current list city.

Latest Searches

osc_get_latest_searches($limit = 20) – Retrieves the latest searches performed on the website.

osc_count_latest_searches() – Gets the total number of latest searches performed on the website.

osc_has_latest_searches() – Retrieves the next latest search; returns null if there are no more.

osc_latest_search() – Gets the current latest search.

osc_latest_search_text() – Gets the search pattern of the current latest search.

osc_latest_search_date() – Gets the date of the current latest search.

osc_latest_search_total() – Gets the total number of results for the current latest search.

The hSearch.php helper in Osclass provides a rich set of functions to manage and customize search operations on your classifieds website. This document offers a detailed explanation of each function, including its parameters and return values, along with usage examples.

Advanced Information

osc_search()

osc_search() – Gets the search object.

This function checks if a search object exists in the view. If it does, it returns that object; otherwise, it creates a new instance of the Search class, exports it to the view, and returns the new object.

  • Parameters: None
  • Returns: Search object

osc_list_orders()

osc_list_orders() – Retrieves available search orders.

Depending on whether the price option is enabled for items, it returns an array of search orders. When prices are enabled, the options include "Newly listed", "Lower price first", and "Higher price first". Otherwise, it returns only "Newly listed".

  • Parameters: None
  • Returns: Array (keys: order description; values: arrays with sOrder and iOrderType).

osc_search_alert_subscribed()

osc_search_alert_subscribed() – Checks if the search alert is subscribed.

  • Parameters: None
  • Returns: Boolean indicating if the search alert subscription is active.

osc_search_page()

osc_search_page() – Gets the current search page number.

  • Parameters: None
  • Returns: Integer (current page number, defaults to 0 if not set).

osc_search_total_pages()

osc_search_total_pages() – Gets the total number of pages for the current search results.

  • Parameters: None
  • Returns: Integer (total pages).

osc_search_has_pic()

osc_search_has_pic() – Checks if the "has pic" option is enabled in the search.

  • Parameters: None
  • Returns: Boolean

osc_search_only_premium()

osc_search_only_premium() – Checks if the search is limited to premium items.

  • Parameters: None
  • Returns: Boolean

osc_search_order()

osc_search_order() – Retrieves the current search order field.

  • Parameters: None
  • Returns: String (e.g., dt_pub_date or i_price).

osc_search_order_type()

osc_search_order_type() – Retrieves the current search order type.

  • Parameters: None
  • Returns: String (typically asc or desc).

osc_search_pattern()

osc_search_pattern() – Retrieves the search pattern input by the user.

  • Parameters: None
  • Returns: String (returns an empty string if not set).

osc_search_country()

osc_search_country() – Retrieves the search country parameter.

  • Parameters: None
  • Returns: String (country code or name).

osc_search_region()

osc_search_region() – Retrieves the search region parameter.

  • Parameters: None
  • Returns: String (region identifier).

osc_search_city()

osc_search_city() – Retrieves the search city parameter.

  • Parameters: None
  • Returns: String (city identifier).

osc_search_user()

osc_search_user() – Retrieves an array of users involved in the search criteria.

  • Parameters: None
  • Returns: Array (empty array if not set).

osc_search_price_max()

osc_search_price_max() – Retrieves the maximum price filter from the search criteria.

  • Parameters: None
  • Returns: Float

osc_search_price_min()

osc_search_price_min() – Retrieves the minimum price filter from the search criteria.

  • Parameters: None
  • Returns: Float

osc_search_total_items()

osc_search_total_items() – Retrieves the total number of items matching the search criteria.

  • Parameters: None
  • Returns: Integer

osc_search_show_as()

osc_search_show_as() – Retrieves the display mode for search results (e.g., list or gallery).

  • Parameters: None
  • Returns: String

osc_search_start()

osc_search_start() – Retrieves the starting index for search results on the current page.

  • Parameters: None
  • Returns: Integer

osc_search_end()

osc_search_end() – Retrieves the ending index for search results on the current page.

  • Parameters: None
  • Returns: Integer

osc_search_category()

osc_search_category() – Retrieves the current search category or categories.

  • Parameters: None
  • Returns: Array (empty array if not defined).

osc_search_category_id()

osc_search_category_id() – Retrieves the ID(s) of the current search category.

  • Parameters: None
  • Returns: Integer or Array of integers

osc_update_search_url($params, $forced = false)

osc_update_search_url($params, $forced = false) – Updates the search URL by merging new parameters with the current request.

  • $params (array): An associative array of search parameters to update (e.g., sCategory, sRegion, sCity, iPage, etc.).
  • $forced (boolean, default: false): If true, bypasses subdomain restrictions when updating the URL.
  • Returns: String (the updated search URL).

osc_alert_form()

osc_alert_form() – Loads the alert subscription form.

  • Parameters: None
  • This function includes the alert form view from the current web theme.

osc_search_alert()

osc_search_alert() – Retrieves the alert message for the current search.

  • Parameters: None
  • Returns: String (the alert message, if any).

osc_search_show_all_url($params = array())

osc_search_show_all_url($params = array()) – Generates a URL for a default search (all categories, no extra options).

  • $params (array, default: empty array): Additional parameters to include in the URL.
  • Returns: String (the default search URL).

osc_search_url($params = null)

osc_search_url($params = null) – Generates the search URL based on the provided parameters.

  • $params (array, default: null): An associative array of search parameters. If not provided, defaults to a basic search URL.
  • Returns: String (the complete search URL).

Comprehensive Guide

The hSearch.php helper is a critical component for building and customizing search functionality in Osclass. It enables you to:

  • Retrieve and manage the search object using osc_search().
  • Define and modify search orders with osc_list_orders(), which adjusts based on whether pricing is enabled.
  • Control pagination and determine the current page and total pages via osc_search_page() and osc_search_total_pages().
  • Filter search results by various criteria, such as the presence of images (osc_search_has_pic()), premium status (osc_search_only_premium()), and search keywords (osc_search_pattern()).
  • Extract location-related search parameters using functions like osc_search_country(), osc_search_region(), and osc_search_city().
  • Generate dynamic and SEO-friendly search URLs by merging current parameters with new ones using osc_update_search_url() and osc_search_url().
  • Provide a user-friendly alert system for search queries through osc_alert_form() and osc_search_alert().

Parameter Options:

  • $params:
    • sCategory – Category slug or ID.
    • sRegion – Region identifier.
    • sCity – City identifier.
    • iPage – Page number for pagination.
    • sPattern – Search keyword or pattern.
    • Additional keys for filters such as sCountry, sUser, etc.
  • Subdomain Handling:
    • Depending on your subdomain configuration, certain parameters (e.g., sCategory or sCountry) may be automatically removed or adjusted.
  • Return Values:
    • Functions return strings, arrays, or objects. For example, osc_search() returns a Search object, while osc_list_orders() returns an array of order options.
  • Error Handling:
    • These functions assume that necessary view variables and configurations are set up by the Osclass framework. Missing parameters may lead to default values being used.

By leveraging the hSearch.php helper, you can create a robust, customizable search experience that enhances both usability and SEO for your classifieds website.