. *******************************************************************************/ /** * */ 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 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_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']); } } // 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']); } } } } 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')); } } 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)) { $results = $as->getProperty($this->var3); } elseif (!empty($this->var1) && !empty($this->var2)) { $results = $as->getProperties(array( 'State' => $this->var1, 'City' => $this->var2 )); } elseif (!empty($this->var1) && empty($this->var2)) { $results = $as->getProperties(array( 'State' => $this->var1 )); } $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; 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() { include(TEMPLATEPATH . '/page.php'); exit; } function searchFilter($post) { $as = new AgentStormRequest(trim(get_option('as_hostname')), trim(get_option('as_apikey'))); $query = array(); // 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'] . '-'; } // 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']; } $results = $as->getProperties($query); 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(); } $this->title = 'Search Results'; return array(new AgentStormPage(-1, $this->title, $page_content)); } function searchTitle() { return $this->title . ' - '; } function searchPage() { 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'])) { //if () { //} $as_saved = true; } } extract($args); echo $before_widget; echo $before_title . get_option('as_contactwidget_title') . $after_title; include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'agentstorm_widget_contact.php'; echo $after_widget; } /** * */ function displayAdmin() { if (!empty($_POST)) { $this->saveAdmin(); } include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'agentstorm_widget_contactoptions.php'; } /** * */ function saveAdmin() { if (isset($_POST['as_contactwidget_save'])) { update_option('as_contactwidget_title', $_POST['as_contactwidget_title']); update_option('as_contactwidget_desc', $_POST['as_contactwidget_desc']); update_option('as_contactwidget_success', $_POST['as_contactwidget_success']); update_option('as_contactwidget_button', $_POST['as_contactwidget_button']); } } } class AgentStormWidgetNavigation { /** * */ function init() { register_sidebar_widget('Agent Storm Navigation Widget', array($this, 'display')); register_widget_control('Agent Storm Navigation Widget', array($this, 'displayAdmin')); } /** * */ function display($args) { $as = new AgentStormRequest(get_option('as_hostname'), get_option('as_apikey')); $cities = get_option('as_cities'); extract($args); echo $before_widget; echo $before_title . get_option('as_navigationwidget_title') . $after_title; include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'agentstorm_widget_navigation.php'; echo $after_widget; } /** * */ function displayAdmin() { if (!empty($_POST)) { $this->saveAdmin(); } include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'agentstorm_widget_navigationoptions.php'; } /** * */ function saveAdmin() { if (isset($_POST['as_navigationwidget_save'])) { update_option('as_navigationwidget_title', $_POST['as_navigationwidget_title']); update_option('as_navigationwidget_desc', $_POST['as_navigationwidget_desc']); } } } class AgentStormWidgetSearch { /** * */ function init() { register_sidebar_widget('Agent Storm Search Widget', array($this, 'display')); register_widget_control('Agent Storm Search Widget', array($this, 'displayAdmin')); } /** * */ function display($args) { $as = new AgentStormRequest(get_option('as_hostname'), get_option('as_apikey')); $cities = get_option('as_cities'); extract($args); echo $before_widget; echo $before_title . get_option('as_searchwidget_title') . $after_title; include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'agentstorm_widget_search.php'; echo $after_widget; } /** * */ function displayAdmin() { if (!empty($_POST)) { $this->saveAdmin(); } include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'agentstorm_widget_searchoptions.php'; } /** * */ function saveAdmin() { if (isset($_POST['as_searchwidget_save'])) { update_option('as_searchwidget_title', $_POST['as_searchwidget_title']); update_option('as_searchwidget_desc', $_POST['as_searchwidget_desc']); } } } class AgentStormRequest { /** * */ public $hostname = ''; /** * */ public $apikey = ''; /** * */ public $format = 'json'; /** * */ function __construct($hostname, $apikey) { $this->hostname = $hostname; $this->apikey = $apikey; } private function buildParams($params) { $return = '?'; foreach ($params as $key => $value) { $return .= $key . '=' . urlencode($value) . '&'; } return trim($return, '&'); } /** * */ function getRemote($path, $params = array()) { $params['apikey'] = $this->apikey; $param_string = $this->buildParams($params); switch ($this->format) { case 'json': $ret = json_decode(file_get_contents($this->hostname . $path . '.' . $this->format . $param_string)); break; case 'xml': if (!$ret=@simplexml_load_file($this->hostname . $path . '.' . $this->format . '?apikey=' . $this->apikey)) { throw new ASException('An Error occurred while retrieving the results'); } break; } return $ret; } /** * */ function getContacts() { return $this->getRemote('contacts'); } /** * */ function getContact($contact_id) { return $this->getRemote('contacts/' . $contact_id); } /** * */ function getProperties($search = array()) { return $this->getRemote('properties', $search); } /** * */ function getProperty($property_id) { return $this->getRemote('properties/' . $property_id); } /** * */ function getCities() { return $this->getRemote('cities'); } } /** * */ function agentstorm_slugify($text) { $text = preg_replace('~[^\\pL\d]+~u', '-', $text); $text = trim($text, '-'); if (function_exists('iconv')) { $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); } $text = strtolower($text); $text = preg_replace('~[^-\w]+~', '', $text); if (empty($text)) { return 'n-a'; } return $text; } /** * */ function agentstorm_activate() { wp_schedule_event(time(), 'hourly', 'agentstorm_hourly'); update_option('as_idx_urlprefix', 'property'); } /** * */ function agentstorm_deactivate() { wp_clear_scheduled_hook('agentstorm_hourly'); } /** * */ function agentstorm_hourly() { if (get_option('as_hostname') && get_option('as_apikey')) { $as = new AgentStormRequest(get_option('as_hostname'), get_option('as_apikey')); update_option('as_cities', $as->getCities()); } } // Initialize the Agent Storm Plugin // $agentstorm = new AgentStorm(); add_action('admin_init', array(&$agentstorm, 'init')); add_action('admin_menu', array(&$agentstorm, 'registerMenu')); register_activation_hook(__FILE__, 'agentstorm_activate'); register_deactivation_hook(__FILE__, 'agentstorm_deactivate'); // Initialize the Contact Manager Sidebar Widget // $agentstorm_contact_widget = new AgentStormWidgetContact(); add_action('plugins_loaded', array(&$agentstorm_contact_widget, 'init')); // Initialize the Navigation Widget // $agentstorm_navigation_widget = new AgentStormWidgetNavigation(); add_action('plugins_loaded', array(&$agentstorm_navigation_widget, 'init')); // Initialize the Search Widget // $agentstorm_search_widget = new AgentStormWidgetSearch(); add_action('plugins_loaded', array(&$agentstorm_search_widget, 'init')); // // $agentstorm_idx = new AgentStormIDX(); add_action('parse_request', array(&$agentstorm_idx, 'init'));