This advanced topic discusses how the Buying Buddy PHP class file can be used to interact with our API.

The goal of this method is to provide supporting META data capabilities to help with SEO (for example) on a listing, and also provide field value lists to help with custom forms.

This PHP class provides customizable server pre-rendering of pages to make a website SEO index-able in a straightforward way.

The use of this PHP class is optional. It is ONLY required if you wish to extend the function of the Buying Buddy JavaScript plugin to also provide SEO benefits.

Overview

If you have a PHP website, then this PHP method can work in conjunction with the Buying Buddy JavaScript plugin, enabling the additional following SEO features:

  • Indexable Listings: The display widgets (List Widget, Gallery Widget - but not results widget) will output HTML code that includes links to listings that can be followed by Search Engines
  • Long Tail URLs: The structure of the property details page will NOT include a question mark
  • Details Page Optimization: The Title and Meta Description tags on property details pages will be written to include the property address

Once installed, the PHP Class and API executes and presets values before the HTML is output for a page in the browser.
This method therefore allows you to access and use property-specific PHP variables to set SEO options on a property details page such as Meta Tags, OG Tags and so on.

If you implemented this prior to August 2019, you MUST update the call to the Buying Buddy Plugin Script (see instructions).
To use this feature you will need your Buying Buddy API-Authcode, which is available in your Account Settings.
Note:
This PHP class is not supported for use on a WordPress Website. It may be technically possible to use this PHP Class and API rather than the Buying Buddy WordPress Plugin, but currently this is not supported.

Requirements

  1. Curl must be enabled on server.
  2. A special "cache" directory must be made available with "write" access.
  3. You must be using the latest (Aug-2019) multi-line version of the Buying Buddy Plugin script - this is available from the Install Widgets pages in your Buying Buddy dashboard.
  4. Make sure you have the following from your Buying Buddy account:
    1. Your Buying Buddy API-Authcode for Programming APIs
      Navigate to: My Account > Account Settings > Preferences
    2. Your Buying Buddy Account ID (ACID)
      Navigate to: Website & Widgets > Getting Started

Getting Started

1. Download the API Code ZIP FILE

Click here to download the API ZIP file.

This file includes:

  • MBB folder containing the MyBuyingBuddy.php class file and the cache directory

2. Implementation Instructions

2a. Preparation

All pages must load the latest (August 2019) Buying Buddy Plugin Script (see instructions).
This is available from your Buying Buddy account.
Navigate to: Websites & Widgets > Plugin Installation

IMPORTANT
The Buying Buddy Plugin script parameter for "seo : true" must be set. This will then utilize the PHP class, which will also mean that every Widget must use the PHP Object to get the HTML code.

2b. Add PHP on Pages with Widgets

Include the following lines of PHP on each page where you intend to use a Buying Buddy Widget or Buying Buddy functions:

<?php
require 'mbb/MyBuyingBuddy.php';

// Enter the your API-Authcode for Programming APIs, and ACID
$mbbObj = new MyBuyingBuddy( array("api_key" => "[YOUR_API_AUTHCODE]","acid" => "[YOUR_BB_ACID]") );
?>

2b. Add PHP and HTML for specific Widgets on Each page

When using this PHP class you MUST add Widgets using the following modified approach.

For each widget on a page, you must add:

  1. $widgetParams array for the widget
  2. HTML for the Widget that includes a PHP object to load the HTML

Set variables for SEO as desired using the various PHP objects.

See the Code Reference at the bottom of this article for examples.

Using MBB Objects

For SEO benefits, you can set the values of various META tags using PHP objects. These are:

  • $propertyObj->meta_description
  • $propertyObj->meta_keywords
  • $propertyObj->title
  • $propertyObj->h1
  • $propertyObj->property_address
  • $propertyObj->og_tags

For Example

Head

<meta name="keywords" content="<?=$propertyObj->meta_keywords?>" />
<meta name="description" content="<?=$propertyObj->meta_description?>" />

Body

<h1><?=$propertyObj->h1?></h1>
<div id="MBBv3_SearchDetails"><?=$propertyObj->html?></div>

Property Details Example

<?
require_once "mbb/MyBuyingBuddy.php"; /* calls the PHP api */
$mbbObj = new MyBuyingBuddy( array("acid" => "[YOUR_BB_ACID]") ); /* sets up the ACID for the PHP environment */
$loginObj = $mbbObj->getWidget("MBBv3_LoginPanel", array("filter" => "layout:horizontal") );
$propertyObj = $mbbObj->getWidget("MBBv3_SearchDetails", array("property_id" => $mbbObj->getPropertyIdFromURL() ) );
?>

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="description" content="<?=$propertyObj->meta_description?>" />
<script type='text/javascript' src='https://maps.googleapis.com/maps/api/js?key=[YOUR_GOOGLE_MAPS_API_KEY]'></script>
<script type='text/javascript' src='https://www.mbb2.com/version3/css/theme/acid/[YOUR_BB_ACID]'></script>
<script type='text/javascript'>
var MBB = { mbbUrl: 'https://www.mbb2.com/version3', seo : 'true' };
MBB.data = { acid : "[YOUR_BB_ACID]", mbbdomain : "[THIS_DOMAIN_URL]" };
</script>
<script type='text/javascript' src='https://www.mbb2.com/scripts/my-buying-buddy.4.0.js'></script>
<?=$propertyObj->og_tags?>
</head>
<body>
<h1><?=$propertyObj->h1?></h1>
<div id="MBBv3_SearchDetails"><?=$propertyObj->html?></div>
</body>
</html>

HTACCESS

This is an example of HTACCESS for setting up a single property details PHP page for all property details

RewriteEngine on
RewriteRule ^property.*$ property.php [L]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]

Form Field Definitions

When you start to use the PHP API you will be able to use the API to load values in forms.

  • field_label : Label for the form field
  • field_nm : Field name to use when building a form / query
  • field_type : Number support as "_min" and "_max".
    E.g. If field_nm = "price", then this would be "price_min" and "price_max"
  • like : {true or false}. If field queries by like
    E.g. city like %denver% would return Denver and Denver West etc...
  • allow_multiple : {true or false}. If field is true it accepts a comma separated list of values.
    E.g. city = denver, arvada, pueblo
  • look_field : Field uses the lookup code.
    E.g. property features Central Air = ac, Deck = db,  then this would be: "property_features=ac, dc" to get all listings with central air and a deck
  • All fields also support "_not" : which means that field / value should NOT exist.
    E.g. property_features=ac AND city_not=denver would show all properties with Central Air that are not in Denver

There are also some special fields

  • shapesearch : Comma separated list of lat and long as string
    E.g. "1.0333333 -24.0000, 1.0234 -23.40040"
  • create_dt : Number of days on market
    E.g. create_dt=10 show listings new in last 10 days
  • price_drop : Number of days since price dropped
    E.g. price_drop=5 show listings where the price dropped in last 5 days
  • listing_num : When this field is specified all other fields are ignored

PHP Code Reference

The following show examples of how to deploy Widgets when using the PHP class.

Specifically, how to get form field data, field look-ups, get details and photos for a single property and how to perform a search via an Array or filter string.

If a filter is to be applied in the Widget, you should ensure that the  appropriate filter is shown in the widget AND also specified in the $widgetParams array.

List Display Widget

PHP Code:

<?php // List Display Widget
$widgetParams = array(
"filter" => "mls_id:ca64+city:BORREGO SPRINGS,RAMONA",
"limit" => 20, // Defaults to 30 if not set
"order" => "create_dt desc", // Defaults to create_dt desc if not set
"page" => 1 // Defaults to page 1 if not set
);
$listObj = $mbbObj->getWidget("MBBv3_FeaturedList",$widgetParams);
?>

HTML Code

<div id="MBBv3_FeaturedList" filter="mls_id:ca64+city:BORREGO SPRINGS,RAMONA"><?=$listObj->html?></div>

Gallery Display Widget

PHP Code:

<?php // Gallery Display Widget
$widgetParams = array(
"filter" => "mls_id:ca64+price_min:500000+price_max:555000+city:BORREGO SPRINGS,RAMONA",
"limit" => 20, // Defaults to 30 if not set
"order" => "price desc", // Defaults to create_dt desc if not set
"page" => 1 // Defaults to page 1 if not set
);
$galleryObj = $mbbObj->getWidget("MBBv3_FeaturedGallery",$widgetParams);
?>

HTML Code:

<div id="MBBv3_FeaturedGallery" filter="mls_id:ca64+price_min:500000+price_max:555000+city:BORREGO SPRINGS,RAMONA"><?=$galleryObj->html?></div>

Map Widget

PHP Code:

<?php // Interactive Map Widget
$widgetParams = array(
"filter" => "mls_id:ca64+price_min:500000+price_max:555000",
);
$mapObj = $mbbObj->getWidget("MBBv3_InteractiveMap", $widgetParams );
?>

HTML Code:

<div id="MBBv3_InteractiveMap" filter="mls_id:ca64+price_min:500000+price_max:555000" style="height:600px;"><?=$mapObj->html?></div>

Results widget

PHP Code:

<?php // Property results widget
$resultsObj = $mbbObj->getWidget("MBBv3_ListingResults", array("filter" => "login-panel:false") );
?>

HTML Code:

<div id="MBBv3_ListingResults" filter="login-panel:false"><?=$resultsObj->html?></div>

GET the HTML for a Property Details widget

PHP Code:

<?php // GET the HTML for a property details widget
// If you are not using seo friendly URLS replace the getPropertyIdFromUrRL with $_GET["property_id"]
$propertyObj = $mbbObj->getWidget("MBBv3_SearchDetails", array("property_id" => $mbbObj->getPropertyIdFromURL() ) );
?>

HTML Code:

<meta name="keywords" content="<?=$propertyObj->meta_keywords?>" />
<meta name="description" content="<?=$propertyObj->meta_description?>" />
<h1><?=$propertyObj->h1?></h1>
<div id="MBBv3_SearchDetails"><?=$propertyObj->html?></div>

Office Roster Widget

See OfficeRoster Widget with PHP for instructions.

Additional API Calls

PHP Code:

<?php
// ADDITIONAL API CALLS
// These API calls are used to build custom forms etc....

// Get an array of property data based on an array of search parameters
$queryParams = array(
"mls_id" => "ca64", // REQUIRED
"price_min" => 500000,
"price_max" => 555000,
"city" => "BORREGO SPRINGS,RAMONA",
"page" => 1,
"sort" => "price-desc"
);
$resultArray = $mbbObj->getListingDataFromArray( $queryParams );

// Get an array of property data based on filter string of query parameters
$filter = "mls_id:ca64+price_min:500000+price_max:555000+city:BORREGO SPRINGS,RAMONA+sort:price+page:3";
$resultsFilter = $mbbObj->getListingDataFromFilter($filter);

// Get an array of information for a particular property id price => 450000, property_type => res, city => Ramona
$propertyInfo = $mbbObj->getProperty("ca64_110010319");

// Get an array of form fields available for a MLS
$formFields = $mbbObj->getFormFieldList("ca64");

// Get an array of look up fields for a particular MLS
$allLookups = $mbbObj->getAllLookupFields("ca64");

// Get an array of look up key value pairs for a particluar form field (property type will return res => Residential, lnd = Land etc...)
$fieldLookups = $mbbObj->getFieldLookupValues("ca64","property_type");

?>

Admin