. *******************************************************************************/ define('AGENTSTORM_PLUGIN_URL', WP_PLUGIN_URL . DIRECTORY_SEPARATOR . 'agentstorm'); 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; } /** * */ class ASException extends Exception { } /** * */ class AgentStorm { /** * */ function init() { wp_register_style('AgentStormDefault', AGENTSTORM_PLUGIN_URL . '/static/css/default.css'); wp_register_style('AgentStormJqueryUI', AGENTSTORM_PLUGIN_URL . '/static/css/custom.css'); } /** * */ function registerMenu() { $page = add_menu_page('Agent Storm', 'Agent Storm', 'administrator', __FILE__, array(&$this, 'displayAdmin'), AGENTSTORM_PLUGIN_URL . '/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("%property/([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, 'filterPost')); add_filter('wp_title', array(&$this, 'templateTitle')); add_action('template_redirect', array(&$this, 'templateRenderer')); } } } function filterPost($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) { 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(); } if (!empty($this->var1) && !empty($this->var2) && empty($this->var3)) { $this->title = 'Properties For Sale in ' . $this->var2 . ', ' . $this->var1 . '.'; } elseif (!empty($this->var1) && empty($this->var2) && empty($this->var3)) { $this->title = 'Properties For Sale in ' . $this->var1 . '.'; } return array(new AgentStormPage(-1, '', $page_content)); } function templateTitle() { return $this->title; } function templateRenderer() { 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 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_activate() { wp_schedule_event(time(), 'hourly', 'agentstorm_hourly'); } /** * */ 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')); // // $agentstorm_idx = new AgentStormIDX(); add_action('parse_request', array(&$agentstorm_idx, 'init')); // Testing //