. *******************************************************************************/ /** * */ class ASException extends Exception { } /** * */ class AgentStorm { /** * */ function init() { wp_register_style('AgentStormDefault', WP_PLUGIN_URL . DIRECTORY_SEPARATOR . array_pop(explode('/', dirname(__FILE__))) . '/static/css/default.css'); wp_register_style('AgentStormJqueryUI', WP_PLUGIN_URL . DIRECTORY_SEPARATOR . array_pop(explode('/', dirname(__FILE__))) . '/static/css/custom.css'); } /** * */ function registerMenu() { $page = add_menu_page('Agent Storm', 'Agent Storm', 'administrator', __FILE__, array(&$this, 'displayAdmin'), WP_PLUGIN_URL . DIRECTORY_SEPARATOR . array_pop(explode('/', dirname(__FILE__))) . '/static/images/icon.png'); add_action('admin_print_styles-' . $page, array($this, 'loadStyles')); } /** * */ function loadStyles() { wp_enqueue_style('AgentStormDefault'); wp_enqueue_style('AgentStormJqueryUI'); wp_enqueue_script("jquery"); wp_enqueue_script("jquery-ui-tabs"); } /** * */ function loadSiteStyles() { if (get_option('as_usestyle')) { wp_register_style('AgentStormSite', WP_PLUGIN_URL . DIRECTORY_SEPARATOR . array_pop(explode('/', dirname(__FILE__))) . '/static/css/site.css'); wp_print_styles('AgentStormSite'); } wp_register_script('GoogleMaps', 'http://maps.google.com/maps/api/js?sensor=false®ion=GB"'); wp_print_scripts('GoogleMaps'); } /** * */ function displayAdmin() { if (!empty($_POST)) { $this->saveAdmin(); } include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'agentstorm_admin.php'; } /** * */ function saveAdmin() { // Save the Settings Variables // if (isset($_POST['as_settings_save'])) { // Save the Options // if (isset($_POST['as_usestyle'])) { update_option('as_usestyle', true); } else { update_option('as_usestyle', false); } if (isset($_POST['as_hostname'])) { update_option('as_hostname', $_POST['as_hostname']); } if (isset($_POST['as_apikey'])) { update_option('as_apikey', $_POST['as_apikey']); } // Force the Hourly Cronjob as it updates caches // agentstorm_hourly(); } // Save the Contact Manager Settings // if (isset($_POST['as_contact_save'])) { if (isset($_POST['as_contact_emailnotification'])) { update_option('as_contact_emailnotification', true); } else { update_option('as_contact_emailnotification', false); } if (isset($_POST['as_contact_tags'])) { update_option('as_contact_tags', $_POST['as_contact_tags']); } if (isset($_POST['as_contact_source'])) { update_option('as_contact_source', $_POST['as_contact_source']); } } // Save the IDX Data Settings // if (isset($_POST['as_idx_save'])) { if (isset($_POST['as_idx_seo'])) { update_option('as_idx_seo', true); } else { update_option('as_idx_seo', false); } if (isset($_POST['as_idx_urlprefix'])) { update_option('as_idx_urlprefix', $_POST['as_idx_urlprefix']); } if (isset($_POST['as_idx_pagelimit'])) { update_option('as_idx_pagelimit', $_POST['as_idx_pagelimit']); } if (isset($_POST['as_idx_gmap'])) { update_option('as_idx_gmap', true); } else { update_option('as_idx_gmap', false); } if (isset($_POST['as_idx_bview'])) { update_option('as_idx_bview', true); } else { update_option('as_idx_bview', false); } if (isset($_POST['as_idx_walkscore'])) { update_option('as_idx_walkscore', $_POST['as_idx_walkscore']); } if (isset($_POST['as_idx_searchtxt'])) { update_option('as_idx_searchtxt', $_POST['as_idx_searchtxt']); } } } } class AgentStormIDX extends stdClass { public $var1 = ''; public $var2 = ''; public $var3 = ''; public $title = ''; /** * */ function init(&$wp) { $path = $wp->request; $groups = array(); if (preg_match("%" . get_option('as_idx_urlprefix') . "/([a-zA-Z0-9-]+)/?([a-zA-Z0-9-+]+)?/?([0-9]+)?/?%", $path, $groups)) { $this->var1 = urldecode($groups[1]); $this->var2 = urldecode($groups[2]); $this->var3 = urldecode($groups[3]); if (!empty($this->var1) || !empty($this->var2) || !empty($this->var3)) { add_filter('the_posts', array(&$this, 'seoFilter')); add_filter('wp_title', array(&$this, 'seoTitle')); add_action('template_redirect', array(&$this, 'seoPage')); } } elseif (preg_match("%" . get_option('as_idx_urlprefix') . "-search/?%", $path, $groups)) { add_filter('the_posts', array(&$this, 'searchFilter')); add_filter('wp_title', array(&$this, 'searchTitle')); add_action('template_redirect', array(&$this, 'searchPage')); } add_shortcode('agentstorm', array(&$this, 'addShortCode')); } function addShortCode($atts) { extract(shortcode_atts(array( 'template' => 'large' ), $atts)); $file = ''; switch ($template) { case 'small': $file = 'agentstorm_searchsmall.php'; break; case 'tabbed': $file = 'agentstorm_searchtabbed.php'; break; default: $file = 'agentstorm_search.php'; break; } ob_start(); include dirname(__FILE__) . DIRECTORY_SEPARATOR . $file; $page_content = ob_get_contents(); ob_end_clean(); return $page_content; } function seoFilter($posts) { $results = null; $as = new AgentStormRequest(trim(get_option('as_hostname')), trim(get_option('as_apikey'))); if (!empty($this->var3) && is_numeric($this->var3)) { $property_result = $as->getProperty($this->var3); } elseif (!empty($this->var1) && !empty($this->var2)) { $property_result = $as->getProperties(array( 'State' => $this->var1, 'City' => $this->var2, 'limit' => get_option('as_idx_pagelimit') )); } elseif (!empty($this->var1) && empty($this->var2)) { $property_result = $as->getProperties(array( 'State' => $this->var1, 'limit' => get_option('as_idx_pagelimit') )); } $results = $property_result->Properties; $state = $this->var1; $city = $this->var2; if (sizeof($results) == 0) { $this->title = 'Properties for Sale in '; $this->title .= (!empty($city)) ? $city . ', ' : ''; $this->title .= $state; ob_start(); include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'agentstorm_noresults.php'; $page_content = ob_get_contents(); ob_end_clean(); } elseif (sizeof($results) == 1) { $result = $results[0]; $this->title = $result->StreetNumber . ' ' . $result->StreetPrefix . ' ' . $result->StreetName . ' ' . $result->StreetSuffix . ', ' . $result->City . ', ' . $result->State . '. ' . $result->Zip; // Get the Walkscore // if (get_option('as_idx_walkscore')) { $walkscore = @json_decode(@file_get_contents('http://api.walkscore.com/score?format=json&address=' . urlencode($result->StreetNumber . ' ' . $result->StreetPrefix . ' ' . $result->StreetName . ' ' . $result->StreetSuffix . ' ' . $result->City . ' ' . $result->State . ' ' . $result->Zip) . '&lat=' . $result->Latitude . '&lon=' . $result->Longitude . '&wsapikey=' . get_option('as_idx_walkscore'))); } ob_start(); include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'agentstorm_result.php'; $page_content = ob_get_contents(); ob_end_clean(); } else { $this->title = 'Properties for Sale in '; $this->title .= (!empty($city)) ? $city . ', ' : ''; $this->title .= $state; ob_start(); include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'agentstorm_results.php'; $page_content = ob_get_contents(); ob_end_clean(); } return array(new AgentStormPage(-1, $this->title, $page_content)); } function seoTitle() { return $this->title . ' - '; } function seoPage() { header("Status: 200",true, 200); include(TEMPLATEPATH . '/page.php'); exit; } function searchFilter($post) { $as = new AgentStormRequest(trim(get_option('as_hostname')), trim(get_option('as_apikey'))); $query = array(); if ($_GET['as_searchwidget_submit']) { // Property Type // if (isset($_GET['as_propertytype']) && !empty($_GET['as_propertytype'])) { $query['Type'] = $_GET['as_propertytype']; } // Zip Code / Suburb // if (isset($_GET['as_suburbzip']) && !empty($_GET['as_suburbzip'])) { if (preg_match("/^[0-9]{5}$/", $_GET['as_suburbzip'])) { $query['Zip'] = $_GET['as_suburbzip']; } else { $query['City'] = $_GET['as_suburbzip']; } } // Price High to Low Handler // if (isset($_GET['as_pricerange_min']) && isset($_GET['as_pricerange_max']) && $_GET['as_pricerange_min'] > 0 && $_GET['as_pricerange_max'] > 0) { $query['ListPrice'] = $_GET['as_pricerange_min'] . ':' . $_GET['as_pricerange_max']; } elseif (isset($_GET['as_pricerange_min']) && $_GET['as_pricerange_min'] > 0) { $query['ListPrice'] = $_GET['as_pricerange_min'] . '+'; } elseif (isset($_GET['as_pricerange_max']) && $_GET['as_pricerange_max'] > 0) { $query['ListPrice'] = $_GET['as_pricerange_max'] . '-'; } // Lot Size Handler // if (isset($_GET['as_lotsize_min']) && isset($_GET['as_lotsize_max']) && $_GET['as_lotsize_min'] > 0 && $_GET['as_lotsize_max'] > 0) { $query['LotSqft'] = $_GET['as_lotsize_min'] . ':' . $_GET['as_lotsize_max']; } elseif (isset($_GET['as_lotsize_min']) && $_GET['as_lotsize_min'] > 0) { $query['LotSqft'] = $_GET['as_lotsize_min'] . '+'; } elseif (isset($_GET['as_lotsize_max']) && $_GET['as_lotsize_max'] > 0) { $query['LotSqft'] = $_GET['as_lotsize_max'] . '-'; } // Size Handler // if (isset($_GET['as_size_min']) && isset($_GET['as_size_max']) && $_GET['as_size_min'] > 0 && $_GET['as_size_max'] > 0) { $query['Sqft'] = $_GET['as_size_min'] . ':' . $_GET['as_size_max']; } elseif (isset($_GET['as_size_min']) && $_GET['as_size_min'] > 0) { $query['Sqft'] = $_GET['as_size_min'] . '+'; } elseif (isset($_GET['as_size_max']) && $_GET['as_size_max'] > 0) { $query['Sqft'] = $_GET['as_size_max'] . '-'; } // Bedrooms // if (isset($_GET['as_bedrooms']) && !empty($_GET['as_bedrooms'])) { $query['Bedrooms'] = $_GET['as_bedrooms']; } // Bathrooms // if (isset($_GET['as_bathrooms']) && !empty($_GET['as_bathrooms'])) { $query['FullBathrooms'] = $_GET['as_bathrooms']; } // City Search if (isset($_GET['idx_city'])) { $query['City'] = $_GET['as_city']; } // Paging // if (isset($_GET['offset'])) { $query['FullBathrooms'] = $_GET['offset']; } // Sort // if (isset($_GET['sort'])) { $query['FullBathrooms'] = $_GET['sort']; } // Limit // $query['limit'] = get_option('as_idx_pagelimit'); $properties = $as->getProperties($query); $this->title = 'Search Results'; $results = $properties->Properties; if (sizeof($results) == 0) { ob_start(); include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'agentstorm_noresults.php'; $page_content = ob_get_contents(); ob_end_clean(); } elseif (sizeof($results) == 1) { $result = $results[0]; ob_start(); include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'agentstorm_result.php'; $page_content = ob_get_contents(); ob_end_clean(); } else { ob_start(); include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'agentstorm_results.php'; $page_content = ob_get_contents(); ob_end_clean(); } } else { $this->title = 'Property Search'; ob_start(); include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'agentstorm_search.php'; $page_content = ob_get_contents(); ob_end_clean(); } return array(new AgentStormPage(-1, $this->title, $page_content)); } function searchTitle() { return $this->title . ' - '; } function searchPage() { header("Status: 200",true, 200); include(TEMPLATEPATH . '/page.php'); exit; } } class AgentStormPage { public $ID = -1; public $post_title = 'This is a Page'; public $post_content = '
Here is the content
'; public $post_author; public $post_status = 'publish'; public $post_type = 'page'; public $ping_status = 'closed'; public $comment_status = 'closed'; public $comment_count = 0; public $post_date = ''; public $post_date_gmt = ''; /** * */ function __construct($id, $title, $content) { $this->post_date = current_time('mysql'); $this->post_date_gmt = current_time('mysql', 1); $this->post_author = 1; $this->ID = $id; $this->post_title = $title; $this->post_content = $content; } /** * */ function toArray() { $return = array(); foreach ($this as $key => $value) { $return[$key] = $value; } return $return; } } class AgentStormWidgetContact { /** * */ function init() { register_sidebar_widget('Agent Storm Contact Manager Widget', array($this, 'display')); register_widget_control('Agent Storm Contact Manager Widget', array($this, 'displayAdmin')); } /** * */ function display($args) { $as_saved = false; if (!empty($_POST)) { if (isset($_POST['as_contactwidget_submit'])) { // Build the basic document to be posted // $xmldoc = new SimpleXMLElement('