Skip to content

Commit

Permalink
0.3.3 (#1)
Browse files Browse the repository at this point in the history
* Fix: remove commas from address

* Fix: README.md heading

* Fix: + allowed in query params

* Fix: timezone correction for ModificationTimestamp

* Change: allow > 1200px wide grid

* Update README

* Bump version

* Update CHANGELOG
  • Loading branch information
justinh-rahb authored Oct 4, 2024
1 parent 0d6096b commit 0210ed1
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 19 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## [0.3.3]

### Added

- **Readme.txt Compliance**: Updated the `readme.txt` file to comply with WordPress Plugin Directory requirements. Added missing sections including `Requires PHP` field, `Frequently Asked Questions`, and `Changelog`.

### Fixed

- **API Client URL Encoding**: Ensured proper URL encoding of query parameter values in the `API_Client` class. This fix allows spaces and dashes in advanced query parameters, resolving issues where certain valid characters were not being correctly encoded when making API requests.

- **Settings Sanitization**: Updated the `Settings_Page` class to allow spaces and dashes in the advanced query parameters. Modified the `sanitize_query` method to permit valid special characters, ensuring that user input is not unnecessarily stripped.


## [0.3.2]

### Fixed
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Bridge API Directory
# Bridge Interactive API Directory for WordPress

[![License](https://img.shields.io/badge/license-GPLv2-green.svg)](LICENSE)

> [!IMPORTANT]
> This project is not affiliated with Bridge Interactive or Zillow. Please do not contact them for support related to issues with this plugin.
A WordPress plugin that displays a comprehensive, searchable directory of office locations using the Bridge Interactive API.
A WordPress plugin that displays a comprehensive, searchable directory of office locations using the [Bridge Interactive API](https://bridgedataoutput.com/docs/explorer/mls-data#listOffices).

## Table of Contents

Expand All @@ -22,7 +22,7 @@ A WordPress plugin that displays a comprehensive, searchable directory of office
- **Responsive Office Directory**: Displays offices in a grid of interactive cards, each showing essential information such as name, address, phone, email, and website.
- **Advanced Search**: Users can search for offices by name, address, phone number, or email with instant feedback thanks to client-side filtering and debounce optimization.
- **Infinite Scroll**: Offices are loaded automatically as users scroll, enhancing the user experience without traditional pagination.
- **Automated Data Sync**: Full and incremental synchronization with the Bridge Interactive API to keep office data current, including handling of inactive records.
- **Automated Data Sync**: Full and incremental synchronization with the [Bridge Interactive API](https://bridgedataoutput.com/docs/explorer/mls-data#listOffices) to keep office data current, including handling of inactive records.
- **Custom Database Storage**: Utilizes a custom WordPress database table for efficient storage and retrieval, optimized for large datasets.
- **User-Friendly Admin Interface**: Intuitive settings page for configuring API access, synchronization intervals, and managing data directly from the WordPress admin dashboard.

Expand Down Expand Up @@ -77,6 +77,7 @@ If you chose Option B and are setting up the plugin for development purposes, fr
### API Access

- **Access Token**: Required. Obtain this from your Bridge Data Output API account.
- Refer to the [Bridge API Explorer and Documentation](https://bridgedataoutput.com/docs/explorer/mls-data#listOffices) for more information on obtaining an access token and available datasets.
- **Dataset Name**: Required. The dataset you want to query (e.g., `itso`).

### Sync Settings
Expand Down
98 changes: 94 additions & 4 deletions bridge-directory/README.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,100 @@
=== Bridge Directory ===
Contributors: justinhrahb
Tags: real estate, bridge, brokerage, api
Requires at least: 5.0
Tags: real estate, bridge, api, directory, listings
Requires at least: 6.0
Tested up to: 6.6.2
Stable tag: 0.3.2
Requires PHP: 8.0
Stable tag: 0.3.3
License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Displays a searchable directory of offices using the Bridge Interactive API.
Displays a comprehensive, searchable directory of office locations using the Bridge Interactive API.

== Description ==

**Bridge Directory** is a WordPress plugin that displays a comprehensive, searchable directory of office locations using the [Bridge Interactive API](https://bridgedataoutput.com/docs/explorer/mls-data#listOffices).

### Features

– **Responsive Office Directory**: Displays offices in a grid of interactive cards, showing essential information such as name, address, phone, email, and website.
– **Advanced Search**: Users can search for offices by name, address, phone number, or email with instant feedback thanks to client-side filtering and debounce optimization.
– **Infinite Scroll**: Offices are loaded automatically as users scroll, enhancing the user experience without traditional pagination.
– **Automated Data Sync**: Full and incremental synchronization with the [Bridge Interactive API](https://bridgedataoutput.com/docs/explorer/mls-data#listOffices) to keep office data current, including handling of inactive records.
– **Custom Database Storage**: Utilizes a custom WordPress database table for efficient storage and retrieval, optimized for large datasets.
– **User-Friendly Admin Interface**: Intuitive settings page for configuring API access, synchronization intervals, and managing data directly from the WordPress admin dashboard.

### Benefits

**For Website Visitors**

– **Enhanced User Experience**: Easily find and contact the nearest office with an intuitive and responsive interface.
– **Quick Access to Information**: Advanced search functionality reduces the time needed to locate specific offices.

**For Administrators**

– **Operational Efficiency**: Automates the updating of office information, reducing manual workload and minimizing errors.
– **Accurate Data**: Ensures the directory reflects the most current office statuses and details.
– **Scalable Solution**: Designed to handle growth as more offices are added without significant redevelopment.

== Installation ==

1. **Upload the Plugin**:
– Upload the `bridge-directory` folder to the `/wp-content/plugins/` directory, or install the plugin through the WordPress plugins screen directly.
2. **Activate the Plugin**:
– Activate the plugin through the 'Plugins' screen in WordPress.
3. **Configure Plugin Settings**:
– Navigate to `Settings` -> `Bridge Directory` in the WordPress admin dashboard.
– **Access Token**: Enter your Bridge Data Output API access token.
– **Dataset Name**: Specify the dataset name to query (e.g., `test`).
– **Sync Interval**: Set how often (in hours) to perform incremental syncs. Default is every 24 hours.
– **Advanced Query Filter**: (Optional) Add additional query parameters for API requests. Do not include `OfficeStatus` or `ModificationTimestamp.gt` in this field.
4. **Data Synchronization**:
– Click the **Full Sync** button to initiate the initial data synchronization.
5. **Add Office Directory to Pages or Posts**:
– In the WordPress block editor, add the **Office List** block to your page or post.

== Frequently Asked Questions ==

= How do I obtain an API access token? =

You can obtain an API access token by signing up on the Bridge Interactive website and requesting API access.

= How often does the plugin synchronize data? =

By default, the plugin synchronizes data every 24 hours. You can change the synchronization interval in the plugin settings.

= Can I customize the displayed fields? =

Currently, the plugin displays predefined fields. Future updates may include customization options.

= How do I add the office directory to my site? =

You can add the **Office List** block in the WordPress block editor.

= What is the Advanced Query Filter? =

The Advanced Query Filter allows you to add custom query parameters to refine the data fetched from the API. Do not include `OfficeStatus` or `ModificationTimestamp.gt` in this field.

== Changelog ==

= 0.3.3 =
* Updated `readme.txt` to comply with WordPress Plugin Directory requirements.
* Fixed URL encoding in API requests to handle spaces and dashes in advanced query parameters.
* Improved settings sanitization to allow valid special characters in advanced queries.

= 0.3.2 =
* Fixed version numbering to match the actual plugin version.

= 0.3.1 =
* Updated the plugin name to "Bridge Directory" for consistency.

= 0.3.0 =
* Fixed linting errors for code consistency and maintainability.

== License ==

This plugin is licensed under the GPLv2 or later.

== Additional Notes ==

For support and additional information, please visit the [GitHub repo](https://github.com/RAHB-REALTORS-Association/Bridge-Directory-WP).
2 changes: 1 addition & 1 deletion bridge-directory/assets/css/bridge-directory.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.bridge-directory-grid {
max-width: 1200px;
/* max-width: 1200px; */
margin: 0 auto;
padding: 20px;
}
Expand Down
2 changes: 1 addition & 1 deletion bridge-directory/assets/js/bridge-directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
cityStateZip.push(office.OfficePostalCode);
}
if (cityStateZip.length > 0) {
addressParts.push(cityStateZip.join(", "));
addressParts.push(cityStateZip.join(" "));
}
if (addressParts.length > 0) {
parts.push(`<p>${addressParts.join("<br>")}</p>`);
Expand Down
2 changes: 1 addition & 1 deletion bridge-directory/bridge-directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Bridge Directory
* Plugin URI: https://github.com/RAHB-REALTORS-Association/Bridge-Directory-WP
* Description: Displays a searchable directory of offices using the Bridge Interactive API.
* Version: 0.3.2
* Version: 0.3.3
* Author: Cornerstone Association of REALTORS
* Author URI: https://www.cornerstone.inc
* License: GPL-2.0
Expand Down
4 changes: 2 additions & 2 deletions bridge-directory/includes/API_Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ private function fetch_offices( $args = [] ) {
$advanced_query_string = $this->advanced_query;
if ( ! empty( $advanced_query_string ) ) {
// Remove OfficeStatus and ModificationTimestamp.gt from advanced query string
// Build an array of parameters to remove
$params_to_remove = ['OfficeStatus', 'ModificationTimestamp.gt'];

// Split advanced query string into parameters
Expand All @@ -149,7 +148,8 @@ private function fetch_offices( $args = [] ) {
$kv = explode('=', $pair, 2);
$key = urldecode($kv[0]);
if ( in_array( $key, $params_to_remove ) ) continue;
$filtered_pairs[] = $pair;
$value = isset($kv[1]) ? str_replace(' ', '+', urldecode($kv[1])) : '';
$filtered_pairs[] = urlencode($key) . '=' . urlencode($value);
}
// Rebuild advanced query string
$advanced_query_string = implode('&', $filtered_pairs);
Expand Down
22 changes: 18 additions & 4 deletions bridge-directory/includes/Data_Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,23 @@ public function full_sync() {
*/
public function incremental_sync() {
error_log( 'Bridge Directory: Starting incremental sync.' );
// Retrieve the last sync time, defaulting to Unix epoch if not set
$last_sync = get_option( 'bridge_directory_last_sync', '1970-01-01T00:00:00Z' );

// Ensure the timestamp is in the correct format and in UTC
$last_sync_formatted = gmdate( 'Y-m-d\TH:i:s\Z', strtotime( $last_sync ) );
// Parse the last sync time as a DateTime object in UTC
try {
$date = new \DateTime( $last_sync, new \DateTimeZone( 'UTC' ) );
} catch ( \Exception $e ) {
// Handle parsing error
error_log( 'Bridge Directory: Failed to parse last sync time. Defaulting to Unix epoch.' );
$date = new \DateTime( '1970-01-01T00:00:00Z', new \DateTimeZone( 'UTC' ) );
}
// Format the date for use in the API request
$last_sync_formatted = $date->format( 'Y-m-d\TH:i:s\Z' );
// Log the formatted timestamp for debugging
error_log( 'Bridge Directory: Last sync timestamp for API request: ' . $last_sync_formatted );

// Use $last_sync_formatted in your API requests
$updated_offices = $this->api_client->fetch_updated_offices( $last_sync_formatted );
$inactive_offices = $this->api_client->fetch_inactive_offices( $last_sync_formatted );

Expand All @@ -140,7 +152,9 @@ public function incremental_sync() {
error_log( 'Bridge Directory Incremental Sync Error (Inactive Offices): ' . $inactive_offices->get_error_message() );
}

update_option( 'bridge_directory_last_sync', gmdate( 'Y-m-d\TH:i:s\Z' ) );
error_log( 'Bridge Directory: Incremental sync completed.' );
// Update the last sync time to the current time in UTC
$current_time_utc = gmdate( 'Y-m-d\TH:i:s\Z' );
update_option( 'bridge_directory_last_sync', $current_time_utc );
error_log( 'Bridge Directory: Incremental sync completed. Updated last sync time to ' . $current_time_utc );
}
}
4 changes: 2 additions & 2 deletions bridge-directory/includes/Settings_Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function validate_input( $input ) {
}

public function sanitize_query( $input ) {
// Allow specific characters for query parameters
return preg_replace( '/[^a-zA-Z0-9=&._-]/', '', $input );
// Allow characters commonly used in URLs and query parameters
return preg_replace( '/[^a-zA-Z0-9=&._\-+]/', '', $input );
}
}
2 changes: 1 addition & 1 deletion bridge-directory/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bridge-directory",
"version": "0.3.2",
"version": "0.3.3",
"description": "A WordPress plugin that displays a searchable directory of offices using the Bridge Interactive API.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 0210ed1

Please sign in to comment.