. */ /** * ---------------------------------------------------------------------------------------------------------------------- * Enable & Start WP Session * ---------------------------------------------------------------------------------------------------------------------- */ function cp_admin_init() { if (!session_id()) session_start(); } add_action('init', 'cp_admin_init'); /** * ---------------------------------------------------------------------------------------------------------------------- * Set Global variables * ---------------------------------------------------------------------------------------------------------------------- */ /** wp global vars */ global $wpdb; /** Max Execution Time */ if(!ini_get('safe_mode')) { set_time_limit(0); ini_set('max_execution_time', '3600'); // 3600 seconds = 1 hour } /** unlimited memory limit */ ini_set('memory_limit', '-1'); /** Plugin Version */ define('AEM_PLUGIN_Version', "1.0"); /** Plugin DB Table */ define('AEM_PLUGIN_DB_Table', $wpdb->prefix . "aem_properties"); /** Plugin Folder name */ if (!defined('AEM_PLUGIN_FOLDER')) { define('AEM_PLUGIN_FOLDER', 'agenteasy-properties'); } /** Plugin Title/Name */ if (!defined('AEM_PLUGIN_TITLE')) { #define('AEM_PLUGIN_TITLE', 'AgentEasy Properties'); define('AEM_PLUGIN_TITLE', 'AE Search'); } /** Plugin Full URL */ if (!defined('AEM_PLUGIN_URL')) { define('AEM_PLUGIN_URL', get_option('siteurl').'/wp-content/plugins/'.AEM_PLUGIN_FOLDER); } /** Plugin Full DIR Path */ if (!defined('AEM_PLUGIN_PATH')) { define('AEM_PLUGIN_PATH', 'wp-content/plugins/'.AEM_PLUGIN_FOLDER); } /** Plugin Options */ // set here the url where baycentric-web-service.php file is located $baycentric_web_service = 'http://agenteasy.com/ext/property-search/baycentric-web-service.php'; if (!defined('AEM_PLUGIN_OPTION_XML_PARSER')) { define('AEM_PLUGIN_OPTION_XML_PARSER', $baycentric_web_service.'?xml='); } if (!defined('AEM_PLUGIN_OPTION_API_KEY')) { define('AEM_PLUGIN_OPTION_API_KEY', ''); } if (!defined('AEM_PLUGIN_OPTION_XML_LIMIT')) { define('AEM_PLUGIN_OPTION_XML_LIMIT', 30); } if (!defined('AEM_PLUGIN_OPTION_XML_AGENT')) { define('AEM_PLUGIN_OPTION_XML_AGENT', 0); } if (!defined('AEM_PLUGIN_OPTION_XML_AGENT_ENABLE')) { define('AEM_PLUGIN_OPTION_XML_AGENT_ENABLE', 'No'); } if (!defined('AEM_PLUGIN_OPTION_XML_STATUS')) { define('AEM_PLUGIN_OPTION_XML_STATUS', 'active,pending'); } if (!defined('AEM_PLUGIN_OPTION_XML_NEIGHBORHOODS')) { $plugin_aem_option_xml_neighborhoods = array(); $plugin_aem_option_xml_neighborhoods[1010] = array('enable' => 'Yes', 'id' => 1010, 'district' => 'District 1', 'title' => 'Central Richmond'); $plugin_aem_option_xml_neighborhoods[1020] = array('enable' => 'Yes', 'id' => 1020, 'district' => 'District 1', 'title' => 'Inner Richmond'); $plugin_aem_option_xml_neighborhoods[1030] = array('enable' => 'Yes', 'id' => 1030, 'district' => 'District 1', 'title' => 'Jordan Pk/Laurel'); $plugin_aem_option_xml_neighborhoods[1040] = array('enable' => 'Yes', 'id' => 1040, 'district' => 'District 1', 'title' => 'Lake Street'); $plugin_aem_option_xml_neighborhoods[1050] = array('enable' => 'Yes', 'id' => 1050, 'district' => 'District 1', 'title' => 'Outer Richmond'); $plugin_aem_option_xml_neighborhoods[1060] = array('enable' => 'Yes', 'id' => 1060, 'district' => 'District 1', 'title' => 'Sea Cliff'); $plugin_aem_option_xml_neighborhoods[1070] = array('enable' => 'Yes', 'id' => 1070, 'district' => 'District 1', 'title' => 'Lone Mountain'); $plugin_aem_option_xml_neighborhoods[2010] = array('enable' => 'Yes', 'id' => 2010, 'district' => 'District 2', 'title' => 'Golden Gate Hts'); $plugin_aem_option_xml_neighborhoods[2020] = array('enable' => 'Yes', 'id' => 2020, 'district' => 'District 2', 'title' => 'Outer Parkside'); $plugin_aem_option_xml_neighborhoods[2030] = array('enable' => 'Yes', 'id' => 2030, 'district' => 'District 2', 'title' => 'Outer Sunset'); $plugin_aem_option_xml_neighborhoods[2040] = array('enable' => 'Yes', 'id' => 2040, 'district' => 'District 2', 'title' => 'Parkside'); $plugin_aem_option_xml_neighborhoods[2050] = array('enable' => 'Yes', 'id' => 2050, 'district' => 'District 2', 'title' => 'Central Sunset'); $plugin_aem_option_xml_neighborhoods[2060] = array('enable' => 'Yes', 'id' => 2060, 'district' => 'District 2', 'title' => 'Inner Sunset'); $plugin_aem_option_xml_neighborhoods[2070] = array('enable' => 'Yes', 'id' => 2070, 'district' => 'District 2', 'title' => 'Inner Parkside'); $plugin_aem_option_xml_neighborhoods[3010] = array('enable' => 'Yes', 'id' => 3010, 'district' => 'District 3', 'title' => 'Lake Shore'); $plugin_aem_option_xml_neighborhoods[3020] = array('enable' => 'Yes', 'id' => 3020, 'district' => 'District 3', 'title' => 'Merced Heights'); $plugin_aem_option_xml_neighborhoods[3030] = array('enable' => 'Yes', 'id' => 3030, 'district' => 'District 3', 'title' => 'Pine Lake Park'); $plugin_aem_option_xml_neighborhoods[3040] = array('enable' => 'Yes', 'id' => 3040, 'district' => 'District 3', 'title' => 'Stonestown'); $plugin_aem_option_xml_neighborhoods[3050] = array('enable' => 'Yes', 'id' => 3050, 'district' => 'District 3', 'title' => 'Lakeside'); $plugin_aem_option_xml_neighborhoods[3060] = array('enable' => 'Yes', 'id' => 3060, 'district' => 'District 3', 'title' => 'Merced Manor'); $plugin_aem_option_xml_neighborhoods[3070] = array('enable' => 'Yes', 'id' => 3070, 'district' => 'District 3', 'title' => 'Ingleside Heights'); $plugin_aem_option_xml_neighborhoods[3080] = array('enable' => 'Yes', 'id' => 3080, 'district' => 'District 3', 'title' => 'Ingleside'); $plugin_aem_option_xml_neighborhoods[3090] = array('enable' => 'Yes', 'id' => 3090, 'district' => 'District 3', 'title' => 'Oceanview'); $plugin_aem_option_xml_neighborhoods[4010] = array('enable' => 'Yes', 'id' => 4010, 'district' => 'District 4', 'title' => 'Balboa Terrace'); $plugin_aem_option_xml_neighborhoods[4020] = array('enable' => 'Yes', 'id' => 4020, 'district' => 'District 4', 'title' => 'Diamond Heights'); $plugin_aem_option_xml_neighborhoods[4030] = array('enable' => 'Yes', 'id' => 4030, 'district' => 'District 4', 'title' => 'Forest Hill'); $plugin_aem_option_xml_neighborhoods[4040] = array('enable' => 'Yes', 'id' => 4040, 'district' => 'District 4', 'title' => 'Forest Knolls'); $plugin_aem_option_xml_neighborhoods[4050] = array('enable' => 'Yes', 'id' => 4050, 'district' => 'District 4', 'title' => 'Ingleside Terrace'); $plugin_aem_option_xml_neighborhoods[4060] = array('enable' => 'Yes', 'id' => 4060, 'district' => 'District 4', 'title' => 'Midtown Terrace'); $plugin_aem_option_xml_neighborhoods[4070] = array('enable' => 'Yes', 'id' => 4070, 'district' => 'District 4', 'title' => 'St. Francis Wood'); $plugin_aem_option_xml_neighborhoods[4080] = array('enable' => 'Yes', 'id' => 4080, 'district' => 'District 4', 'title' => 'Miraloma Park'); $plugin_aem_option_xml_neighborhoods[4090] = array('enable' => 'Yes', 'id' => 4090, 'district' => 'District 4', 'title' => 'Forest Hill Ext'); $plugin_aem_option_xml_neighborhoods[4100] = array('enable' => 'Yes', 'id' => 4100, 'district' => 'District 4', 'title' => 'Sherwood Forest'); $plugin_aem_option_xml_neighborhoods[4110] = array('enable' => 'Yes', 'id' => 4110, 'district' => 'District 4', 'title' => 'Monterey Heights'); $plugin_aem_option_xml_neighborhoods[4120] = array('enable' => 'Yes', 'id' => 4120, 'district' => 'District 4', 'title' => 'Mount Davidson Manor'); $plugin_aem_option_xml_neighborhoods[4130] = array('enable' => 'Yes', 'id' => 4130, 'district' => 'District 4', 'title' => 'Westwood Highlands'); $plugin_aem_option_xml_neighborhoods[4140] = array('enable' => 'Yes', 'id' => 4140, 'district' => 'District 4', 'title' => 'Westwood Park'); $plugin_aem_option_xml_neighborhoods[4150] = array('enable' => 'Yes', 'id' => 4150, 'district' => 'District 4', 'title' => 'Sunnyside'); $plugin_aem_option_xml_neighborhoods[4160] = array('enable' => 'Yes', 'id' => 4160, 'district' => 'District 4', 'title' => 'West Portal'); $plugin_aem_option_xml_neighborhoods[5010] = array('enable' => 'Yes', 'id' => 5010, 'district' => 'District 5', 'title' => 'Glen Park'); $plugin_aem_option_xml_neighborhoods[5020] = array('enable' => 'Yes', 'id' => 5020, 'district' => 'District 5', 'title' => 'Haight Ashbury'); $plugin_aem_option_xml_neighborhoods[5030] = array('enable' => 'Yes', 'id' => 5030, 'district' => 'District 5', 'title' => 'Noe Valley'); $plugin_aem_option_xml_neighborhoods[5040] = array('enable' => 'Yes', 'id' => 5040, 'district' => 'District 5', 'title' => 'Twin Peaks'); $plugin_aem_option_xml_neighborhoods[5050] = array('enable' => 'Yes', 'id' => 5050, 'district' => 'District 5', 'title' => 'Cole Valley / Parnassus Hts'); $plugin_aem_option_xml_neighborhoods[5060] = array('enable' => 'Yes', 'id' => 5060, 'district' => 'District 5', 'title' => 'Buena Vista / Ashbury Hts'); $plugin_aem_option_xml_neighborhoods[5070] = array('enable' => 'Yes', 'id' => 5070, 'district' => 'District 5', 'title' => 'Corona Heights'); $plugin_aem_option_xml_neighborhoods[5080] = array('enable' => 'Yes', 'id' => 5080, 'district' => 'District 5', 'title' => 'Clarendon Heights'); $plugin_aem_option_xml_neighborhoods[5090] = array('enable' => 'Yes', 'id' => 5090, 'district' => 'District 5', 'title' => 'Duboce Triangle'); $plugin_aem_option_xml_neighborhoods[5100] = array('enable' => 'Yes', 'id' => 5100, 'district' => 'District 5', 'title' => 'Eureka Valley / Dolores'); $plugin_aem_option_xml_neighborhoods[5110] = array('enable' => 'Yes', 'id' => 5110, 'district' => 'District 5', 'title' => 'Mission Dolores'); $plugin_aem_option_xml_neighborhoods[6010] = array('enable' => 'Yes', 'id' => 6010, 'district' => 'District 6', 'title' => 'Anza Vista'); $plugin_aem_option_xml_neighborhoods[6020] = array('enable' => 'Yes', 'id' => 6020, 'district' => 'District 6', 'title' => 'Hayes Valley'); $plugin_aem_option_xml_neighborhoods[6030] = array('enable' => 'Yes', 'id' => 6030, 'district' => 'District 6', 'title' => 'Lwr Pacific Hts'); $plugin_aem_option_xml_neighborhoods[6040] = array('enable' => 'Yes', 'id' => 6040, 'district' => 'District 6', 'title' => 'Western Addition'); $plugin_aem_option_xml_neighborhoods[6050] = array('enable' => 'Yes', 'id' => 6050, 'district' => 'District 6', 'title' => 'Alamo Square'); $plugin_aem_option_xml_neighborhoods[6060] = array('enable' => 'Yes', 'id' => 6060, 'district' => 'District 6', 'title' => 'North Panhandle'); $plugin_aem_option_xml_neighborhoods[7010] = array('enable' => 'Yes', 'id' => 7010, 'district' => 'District 7', 'title' => 'Marina'); $plugin_aem_option_xml_neighborhoods[7020] = array('enable' => 'Yes', 'id' => 7020, 'district' => 'District 7', 'title' => 'Pacific Heights'); $plugin_aem_option_xml_neighborhoods[7030] = array('enable' => 'Yes', 'id' => 7030, 'district' => 'District 7', 'title' => 'Presidio Heights'); $plugin_aem_option_xml_neighborhoods[7040] = array('enable' => 'Yes', 'id' => 7040, 'district' => 'District 7', 'title' => 'Cow Hollow'); $plugin_aem_option_xml_neighborhoods[8010] = array('enable' => 'Yes', 'id' => 8010, 'district' => 'District 8', 'title' => 'Downtown'); $plugin_aem_option_xml_neighborhoods[8020] = array('enable' => 'Yes', 'id' => 8020, 'district' => 'District 8', 'title' => 'Financial District / Barbary Coast'); $plugin_aem_option_xml_neighborhoods[8030] = array('enable' => 'Yes', 'id' => 8030, 'district' => 'District 8', 'title' => 'Nob Hill'); $plugin_aem_option_xml_neighborhoods[8040] = array('enable' => 'Yes', 'id' => 8040, 'district' => 'District 8', 'title' => 'North Beach'); $plugin_aem_option_xml_neighborhoods[8050] = array('enable' => 'Yes', 'id' => 8050, 'district' => 'District 8', 'title' => 'Russian Hill'); $plugin_aem_option_xml_neighborhoods[8060] = array('enable' => 'Yes', 'id' => 8060, 'district' => 'District 8', 'title' => 'Van Ness/Civ Ctr'); $plugin_aem_option_xml_neighborhoods[8070] = array('enable' => 'Yes', 'id' => 8070, 'district' => 'District 8', 'title' => 'Telegraph Hill'); $plugin_aem_option_xml_neighborhoods[8080] = array('enable' => 'Yes', 'id' => 8080, 'district' => 'District 8', 'title' => 'North Waterfront'); $plugin_aem_option_xml_neighborhoods[8090] = array('enable' => 'Yes', 'id' => 8090, 'district' => 'District 8', 'title' => 'Tenderloin'); $plugin_aem_option_xml_neighborhoods[9010] = array('enable' => 'Yes', 'id' => 9010, 'district' => 'District 9', 'title' => 'Bernal Heights'); $plugin_aem_option_xml_neighborhoods[9020] = array('enable' => 'Yes', 'id' => 9020, 'district' => 'District 9', 'title' => 'Inner Mission'); $plugin_aem_option_xml_neighborhoods[9030] = array('enable' => 'Yes', 'id' => 9030, 'district' => 'District 9', 'title' => 'Mission Bay'); $plugin_aem_option_xml_neighborhoods[9040] = array('enable' => 'Yes', 'id' => 9040, 'district' => 'District 9', 'title' => 'Potrero Hill'); $plugin_aem_option_xml_neighborhoods[9050] = array('enable' => 'Yes', 'id' => 9050, 'district' => 'District 9', 'title' => 'South of Market'); $plugin_aem_option_xml_neighborhoods[9060] = array('enable' => 'Yes', 'id' => 9060, 'district' => 'District 9', 'title' => 'South Beach'); $plugin_aem_option_xml_neighborhoods[9070] = array('enable' => 'Yes', 'id' => 9070, 'district' => 'District 9', 'title' => 'Ctrl Waterfront / Dogpatch'); $plugin_aem_option_xml_neighborhoods[9080] = array('enable' => 'Yes', 'id' => 9080, 'district' => 'District 9', 'title' => 'Yerba Buena'); $plugin_aem_option_xml_neighborhoods[10010] = array('enable' => 'Yes', 'id' => 10010, 'district' => 'District 10', 'title' => 'Bayview'); $plugin_aem_option_xml_neighborhoods[10020] = array('enable' => 'Yes', 'id' => 10020, 'district' => 'District 10', 'title' => 'Crocker Amazon'); $plugin_aem_option_xml_neighborhoods[10030] = array('enable' => 'Yes', 'id' => 10030, 'district' => 'District 10', 'title' => 'Excelsior'); $plugin_aem_option_xml_neighborhoods[10040] = array('enable' => 'Yes', 'id' => 10040, 'district' => 'District 10', 'title' => 'Outer Mission'); $plugin_aem_option_xml_neighborhoods[10050] = array('enable' => 'Yes', 'id' => 10050, 'district' => 'District 10', 'title' => 'Visitacion Valley'); $plugin_aem_option_xml_neighborhoods[10060] = array('enable' => 'Yes', 'id' => 10060, 'district' => 'District 10', 'title' => 'Portola'); $plugin_aem_option_xml_neighborhoods[10070] = array('enable' => 'Yes', 'id' => 10070, 'district' => 'District 10', 'title' => 'Silver Terrace'); $plugin_aem_option_xml_neighborhoods[10080] = array('enable' => 'Yes', 'id' => 10080, 'district' => 'District 10', 'title' => 'Mission Terrace'); $plugin_aem_option_xml_neighborhoods[10090] = array('enable' => 'Yes', 'id' => 10090, 'district' => 'District 10', 'title' => 'Hunters Point'); $plugin_aem_option_xml_neighborhoods[10100] = array('enable' => 'Yes', 'id' => 10100, 'district' => 'District 10', 'title' => 'Bayview Heights'); $plugin_aem_option_xml_neighborhoods[10110] = array('enable' => 'Yes', 'id' => 10110, 'district' => 'District 10', 'title' => 'Candlestick Point'); $plugin_aem_option_xml_neighborhoods[10120] = array('enable' => 'Yes', 'id' => 10120, 'district' => 'District 10', 'title' => 'Little Hollywood'); $plugin_aem_option_xml_neighborhoods[11010] = array('enable' => 'Yes', 'id' => 11010, 'district' => 'District 11', 'title' => 'Original Daly City'); $plugin_aem_option_xml_neighborhoods[11020] = array('enable' => 'Yes', 'id' => 11020, 'district' => 'District 11', 'title' => 'Serramonte'); $plugin_aem_option_xml_neighborhoods[11030] = array('enable' => 'Yes', 'id' => 11030, 'district' => 'District 11', 'title' => 'Southern Hills'); $plugin_aem_option_xml_neighborhoods[11040] = array('enable' => 'Yes', 'id' => 11040, 'district' => 'District 11', 'title' => 'Westlake #1 / Olympic'); $plugin_aem_option_xml_neighborhoods[11050] = array('enable' => 'Yes', 'id' => 11050, 'district' => 'District 11', 'title' => 'Westlake Highlands'); $plugin_aem_option_xml_neighborhoods[11060] = array('enable' => 'Yes', 'id' => 11060, 'district' => 'District 11', 'title' => 'Westlake Knolls'); $plugin_aem_option_xml_neighborhoods[11070] = array('enable' => 'Yes', 'id' => 11070, 'district' => 'District 11', 'title' => 'Broadmoor'); $plugin_aem_option_xml_neighborhoods[11080] = array('enable' => 'Yes', 'id' => 11080, 'district' => 'District 11', 'title' => 'Westlake Terrace'); $plugin_aem_option_xml_neighborhoods[11090] = array('enable' => 'Yes', 'id' => 11090, 'district' => 'District 11', 'title' => 'St. Francis Hts'); $plugin_aem_option_xml_neighborhoods[11100] = array('enable' => 'Yes', 'id' => 11000, 'district' => 'District 11', 'title' => 'Westlake Palisades'); $plugin_aem_option_xml_neighborhoods[11110] = array('enable' => 'Yes', 'id' => 11110, 'district' => 'District 11', 'title' => 'Blossom Valley'); $plugin_aem_option_xml_neighborhoods[11120] = array('enable' => 'Yes', 'id' => 11120, 'district' => 'District 11', 'title' => 'Crown Colony'); $plugin_aem_option_xml_neighborhoods[11130] = array('enable' => 'Yes', 'id' => 11130, 'district' => 'District 11', 'title' => 'Colma'); $plugin_aem_option_xml_neighborhoods[11140] = array('enable' => 'Yes', 'id' => 11140, 'district' => 'District 11', 'title' => 'Brisbane'); $plugin_aem_option_xml_neighborhoods[11150] = array('enable' => 'Yes', 'id' => 11150, 'district' => 'District 11', 'title' => 'Bayridge / Linda Vista'); if(count($plugin_aem_option_xml_neighborhoods) > 0) { $plugin_aem_option_xml_neighborhoods_serialize = serialize($plugin_aem_option_xml_neighborhoods); $plugin_aem_option_xml_neighborhoods_serialize = htmlentities($plugin_aem_option_xml_neighborhoods_serialize,ENT_QUOTES); } else { $plugin_aem_option_xml_neighborhoods_serialize = ""; } define('AEM_PLUGIN_OPTION_XML_NEIGHBORHOODS', $plugin_aem_option_xml_neighborhoods_serialize); } /** Plugin Miscellaneous Settings */ if (!defined('AEM_PLUGIN_TEMPLATE_PAGE_PARENT')) { define('AEM_PLUGIN_TEMPLATE_PAGE_PARENT', 'Properties'); } if (!defined('AEM_THEME_ACTIVE')) { $aem_plugin_template_page_slug = sanitize_title(AEM_PLUGIN_TEMPLATE_PAGE_PARENT); if(plugin_aem_get_ID_by_slug($aem_plugin_template_page_slug) > 0) { define('AEM_THEME_ACTIVE', TRUE); } else { define('AEM_THEME_ACTIVE', FALSE); } } if (!defined('AEM_PLUGIN_TEMPLATE_PAGE_TITLE_PARENT')) { if(AEM_THEME_ACTIVE == true) { define('AEM_PLUGIN_TEMPLATE_PAGE_TITLE_PARENT', AEM_PLUGIN_TEMPLATE_PAGE_PARENT); } else { define('AEM_PLUGIN_TEMPLATE_PAGE_TITLE_PARENT', ''); } } if (!defined('AEM_PLUGIN_TEMPLATE_PAGE_SLUG_PARENT')) { define('AEM_PLUGIN_TEMPLATE_PAGE_SLUG_PARENT', sanitize_title(AEM_PLUGIN_TEMPLATE_PAGE_TITLE_PARENT)); } if (!defined('AEM_PLUGIN_TEMPLATE_PAGE_TITLE_SEARCH')) { define('AEM_PLUGIN_TEMPLATE_PAGE_TITLE_SEARCH', 'Search Property'); } if (!defined('AEM_PLUGIN_TEMPLATE_PAGE_TITLE_RESULTS')) { define('AEM_PLUGIN_TEMPLATE_PAGE_TITLE_RESULTS', 'Search Results'); } if (!defined('AEM_PLUGIN_TEMPLATE_PAGE_TITLE_DETAILS')) { define('AEM_PLUGIN_TEMPLATE_PAGE_TITLE_DETAILS', 'Property Details'); } if (!defined('AEM_PLUGIN_TEMPLATE_PAGE_TITLE_MY_ACTIVE_PROPERTIES')) { define('AEM_PLUGIN_TEMPLATE_PAGE_TITLE_MY_ACTIVE_PROPERTIES', 'My Active Properties'); } if (!defined('AEM_PLUGIN_TEMPLATE_PAGE_TITLE_MY_SOLD_PROPERTIES')) { define('AEM_PLUGIN_TEMPLATE_PAGE_TITLE_MY_SOLD_PROPERTIES', 'My Sold Properties'); } if (!defined('AEM_PLUGIN_SHORTCODE_SEARCH')) { define('AEM_PLUGIN_SHORTCODE_SEARCH', '[plugin_aem_template_search]'); } if (!defined('AEM_PLUGIN_SHORTCODE_RESULTS')) { define('AEM_PLUGIN_SHORTCODE_RESULTS', '[plugin_aem_template_results]'); } if (!defined('AEM_PLUGIN_SHORTCODE_DETAILS')) { define('AEM_PLUGIN_SHORTCODE_DETAILS', '[plugin_aem_template_details]'); } if (!defined('AEM_PLUGIN_SHORTCODE_MY_ACTIVE_PROPERTIES')) { define('AEM_PLUGIN_SHORTCODE_MY_ACTIVE_PROPERTIES', '[plugin_aem_template_my_active_properties]'); } if (!defined('AEM_PLUGIN_SHORTCODE_MY_SOLD_PROPERTIES')) { define('AEM_PLUGIN_SHORTCODE_MY_SOLD_PROPERTIES', '[plugin_aem_template_my_sold_properties]'); } /** * ---------------------------------------------------------------------------------------------------------------------- * Plugin Install/Remove * ---------------------------------------------------------------------------------------------------------------------- */ // Runs when plugin is activated register_activation_hook(__FILE__,'plugin_aem_plugin_install'); // Runs on plugin deactivation register_deactivation_hook( __FILE__, 'plugin_aem_plugin_remove' ); /** * ---------------------------------------------------------------------------------------------------------------------- * Plugin Database: Properties >> Create Database Table if NOT exists * ---------------------------------------------------------------------------------------------------------------------- */ if($wpdb->get_var("SHOW TABLES LIKE '".AEM_PLUGIN_DB_Table."'") != AEM_PLUGIN_DB_Table) { $sql = "CREATE TABLE IF NOT EXISTS `".AEM_PLUGIN_DB_Table."` ( `id` int(100) NOT NULL AUTO_INCREMENT, `Represented` varchar(255) DEFAULT 'Both', `MLS` int(100) DEFAULT 0, `Title` varchar(255) DEFAULT NULL, `URL` varchar(255) DEFAULT NULL, `DefaultImageURL` varchar(255) DEFAULT NULL, `DefaultThumbnailURL` varchar(255) DEFAULT NULL, `PropertyType` varchar(255) DEFAULT NULL, `Address` text, `Bedrooms` varchar(255) DEFAULT 0, `Bathrooms` varchar(255) DEFAULT 0, `ListingPrice` varchar(255) DEFAULT 0, `ListingDate` varchar(255) DEFAULT NULL, `SellingPrice` varchar(255) DEFAULT 0, `SoldDate` varchar(255) DEFAULT NULL, `Description` text, `Status` varchar(255) DEFAULT NULL, `ListingAgent` varchar(255) DEFAULT NULL, `ListingOffice` varchar(255) DEFAULT NULL, `Comment` text, `full_property_details` longtext, `date_added` date DEFAULT NULL, `date_updated` date DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;"; $wpdb->query($sql); if($wpdb->get_var("SHOW TABLES LIKE '".AEM_PLUGIN_DB_Table."'") == AEM_PLUGIN_DB_Table) { $plugin_aem_db_creation[AEM_PLUGIN_DB_Table] = '

DB Table: '.AEM_PLUGIN_DB_Table.' Created Successfully

'; } else { $plugin_aem_db_creation[AEM_PLUGIN_DB_Table] = '

Failed Creating DB Table: '.AEM_PLUGIN_DB_Table.'

'; } #echo $plugin_aem_db_creation[AEM_PLUGIN_DB_Table]; } /** * ---------------------------------------------------------------------------------------------------------------------- * Plugin Install/Active * ---------------------------------------------------------------------------------------------------------------------- */ function plugin_aem_plugin_install() { global $wpdb; // cretae the pages $result_create_page = plugin_aem_create_page(AEM_PLUGIN_TEMPLATE_PAGE_TITLE_SEARCH, AEM_PLUGIN_SHORTCODE_SEARCH); $result_create_page = plugin_aem_create_page(AEM_PLUGIN_TEMPLATE_PAGE_TITLE_RESULTS, AEM_PLUGIN_SHORTCODE_RESULTS); $result_create_page = plugin_aem_create_page(AEM_PLUGIN_TEMPLATE_PAGE_TITLE_DETAILS, AEM_PLUGIN_SHORTCODE_DETAILS); $result_create_page = plugin_aem_create_page(AEM_PLUGIN_TEMPLATE_PAGE_TITLE_MY_ACTIVE_PROPERTIES, "

".AEM_PLUGIN_TEMPLATE_PAGE_TITLE_MY_ACTIVE_PROPERTIES."

".AEM_PLUGIN_SHORTCODE_MY_ACTIVE_PROPERTIES); $result_create_page = plugin_aem_create_page(AEM_PLUGIN_TEMPLATE_PAGE_TITLE_MY_SOLD_PROPERTIES, "

".AEM_PLUGIN_TEMPLATE_PAGE_TITLE_MY_SOLD_PROPERTIES."

".AEM_PLUGIN_SHORTCODE_MY_SOLD_PROPERTIES); // update the permalink of the current blog site update_option('permalink_structure', "/%postname%/"); // Export Properties into Property Listings export_properties_into_propertylistings(); } /** * ---------------------------------------------------------------------------------------------------------------------- * Plugin Uninstall/Deactivate * ---------------------------------------------------------------------------------------------------------------------- */ function plugin_aem_plugin_remove() { global $wpdb; $force_delete = true; $parent_slug = ''; // check if the pages has parent page & get the parent slug/permalink if(AEM_PLUGIN_TEMPLATE_PAGE_SLUG_PARENT != "") { $parent_slug .= AEM_PLUGIN_TEMPLATE_PAGE_SLUG_PARENT.'/'; } // delete database tables created by the plugin if($wpdb->get_var("SHOW TABLES LIKE '".AEM_PLUGIN_DB_Table."'") == AEM_PLUGIN_DB_Table) { #$wpdb->query("DROP TABLE IF EXISTS ".AEM_PLUGIN_DB_Table.";"); if($wpdb->get_var("SHOW TABLES LIKE '".AEM_PLUGIN_DB_Table."'") != AEM_PLUGIN_DB_Table) { #$plugin_aem_db_removed[AEM_PLUGIN_DB_Table] = '

DB Table: '.AEM_PLUGIN_DB_Table.' Removed Successfully

'; } else { #$plugin_aem_db_removed[AEM_PLUGIN_DB_Table] = '

Failed Removing DB Table: '.AEM_PLUGIN_DB_Table.'

'; } #echo $plugin_aem_db_removed[AEM_PLUGIN_DB_Table]; } /* ------------------------------------------------------------------------------ // delete the page from the wp_post database table $delete_thePageIDx = wp_delete_post( plugin_aem_get_ID_by_slug($parent_slug.get_option("plugin_aem_option_template_page_search")), $force_delete ); $delete_thePageIDx = wp_delete_post( plugin_aem_get_ID_by_slug($parent_slug.get_option("plugin_aem_option_template_page_results")), $force_delete ); $delete_thePageIDx = wp_delete_post( plugin_aem_get_ID_by_slug($parent_slug.get_option("plugin_aem_option_template_page_details")), $force_delete ); // delete the page from the wp_post database table $slug_my_active_properties = sanitize_title(AEM_PLUGIN_TEMPLATE_PAGE_TITLE_MY_ACTIVE_PROPERTIES); $slug_my_sold_properties = sanitize_title(AEM_PLUGIN_TEMPLATE_PAGE_TITLE_MY_SOLD_PROPERTIES); $delete_thePageIDx = wp_delete_post( plugin_aem_get_ID_by_slug($parent_slug.$slug_my_active_properties), $force_delete ); $delete_thePageIDx = wp_delete_post( plugin_aem_get_ID_by_slug($parent_slug.$slug_my_sold_properties), $force_delete ); --------------------------------------------------------------------------------- */ // delete the option from the wp_options database table # delete_option("plugin_aem_option_api_key"); # delete_option("plugin_aem_option_limit"); # delete_option("plugin_aem_option_xml_agent"); # delete_option("plugin_aem_option_xml_agent_enable"); delete_option("plugin_aem_option_xml_neighborhoods_serialize"); // code fix: reset the neighborhood arrays # delete_option("plugin_aem_option_template_page_base_search"); # delete_option("plugin_aem_option_template_page_base_results"); # delete_option("plugin_aem_option_template_page_base_details"); # delete_option("plugin_aem_option_template_page_search"); # delete_option("plugin_aem_option_template_page_results"); # delete_option("plugin_aem_option_template_page_details"); } /** * ---------------------------------------------------------------------------------------------------------------------- * Export Properties into Property Listings * ---------------------------------------------------------------------------------------------------------------------- */ function export_properties_into_propertylistings() { global $wpdb; global $current_user; $listing = array(); // Property Details $listing['Represented'] = 'Seller'; $listing['Title'] = ''; $listing['Address'] = ''; $listing['MLS'] = ''; $listing['Bedrooms'] = ''; $listing['Bathrooms'] = ''; $listing['PropertyType'] = ''; $listing['Neighborhood'] = ''; $listing['Description'] = ''; $listing['ListingPrice'] = ''; $listing['SellingPrice'] = ''; $listing['SoldDate'] = ''; $listing['ListingAgent'] = ''; $listing['ListingOffice'] = ''; $listing['Status'] = ''; // PrimaryDetails $listing['CrossStreet'] = ''; $listing['ApproximateSqFt'] = ''; $listing['PricePerSqFt'] = ''; $listing['YearBuilt'] = ''; $listing['TotalRooms'] = ''; $listing['HOADues'] = ''; // AdditionalDetails $listing['Parking'] = ''; $listing['Type'] = ''; $listing['Style'] = ''; $listing['Floors'] = ''; $listing['BathTypeIncludes'] = ''; $listing['Kitchen'] = ''; $listing['DiningRoom'] = ''; $listing['LivingRoom'] = ''; $listing['HeatingCoolingSystem']= ''; $listing['LaundryAppliances'] = ''; $listing['SpecialFeatures'] = ''; $listing['CommonAreas'] = ''; $listing['Transportation'] = ''; $listing['Shopping'] = ''; //$listing['Comment'] = ''; // photos/images $listing['FeaturedImage'] = ''; $listing['Photos'] = ''; $mlsid_listings = array(); $tmp_listings = $wpdb->get_results("SELECT * FROM ".AEM_PLUGIN_DB_Table."", ARRAY_A); if(count($tmp_listings)) { foreach($tmp_listings as $tmp_listing) { // store the details into array $arr["Listing"] = unserialize(base64_decode($tmp_listing['full_property_details'])); $propertylisting = array(); if(is_array($listing)) { foreach($listing as $field_key => $field_value) { if(isset($arr["Listing"]['PrimaryDetails'][$field_key])) { $propertylisting[$field_key] = $arr["Listing"]['PrimaryDetails'][$field_key]['value']; } elseif(isset($arr["Listing"]['AdditionalDetails'][$field_key])) { $propertylisting[$field_key] = $arr["Listing"]['AdditionalDetails'][$field_key]['value']; } else { $propertylisting[$field_key] = $arr["Listing"][$field_key]['value']; } } } if(is_array($arr["Listing"]['Photos']['Photo'])) { if(count($arr["Listing"]['Photos']['Photo']) > 0) { foreach($arr["Listing"]['Photos']['Photo'] as $Photos_photo) { if(!empty($Photos_photo['URL']['value']) && $Photos_photo['URL']['value'] != AEM_PLUGIN_URL."/images/no_image_available.jpg") { $propertylisting['Photos'][] = $Photos_photo['URL']['value']; } } } } if(!isset($propertylisting['Represented']) || empty($propertylisting['Represented'])) { $propertylisting['Represented'] = 'Seller'; } // Create post object $my_post = array( 'post_title' => $propertylisting['Title'], 'post_content' => $propertylisting['Description'], 'post_status' => 'publish', 'post_type' => 'property_listings', 'post_author' => $current_user->ID ); // Insert the post into the database $inserted_post_id = wp_insert_post( $my_post ); if($inserted_post_id > 0) { $mlsid_listings['added'][] = $propertylisting; foreach($listing as $listing_key => $listing_value) { if(!in_array($listing_key, array('Title'))) { update_post_meta($inserted_post_id, $listing_key, $propertylisting[$listing_key]); } } // delete the old record $deleted_property = $wpdb->query("DELETE FROM ".AEM_PLUGIN_DB_Table." WHERE id = '".$tmp_listing['id']."' LIMIT 1"); } } } } /** * ---------------------------------------------------------------------------------------------------------------------- * Get Current User * ---------------------------------------------------------------------------------------------------------------------- */ function plugin_aem_wp_get_current_user() { $current_user = wp_get_current_user(); if ( !($current_user instanceof WP_User) ) { return $current_user; } else { return null; } } /** * ---------------------------------------------------------------------------------------------------------------------- * Get the WordPress Page ID by Slug/Permalink * ---------------------------------------------------------------------------------------------------------------------- */ function plugin_aem_get_ID_by_slug($page_slug) { $page = get_page_by_path($page_slug); if ($page) { return $page->ID; } else { return null; } } /** * ---------------------------------------------------------------------------------------------------------------------- * Plugin Admin Menu * ---------------------------------------------------------------------------------------------------------------------- */ // create custom plugin settings menu add_action('admin_menu', 'plugin_aem_create_menu'); function plugin_aem_create_menu() { /*-------------------------------------------------------- 1. Page title – Title of the page or screen that the menu links to. If you are rendering your own page, then the page title value is stored in the global $title. 2. Menu title – Title of the menu. 3. Capability – Defines what permissions a user must have in order to access this menu. Here are a list of capabilities. (10 = Administrator) 4. Menu ID – Unique id of the menu. 5. Menu display function – Function containing HTML and PHP code on how to display the page or screen that the menu is linked to. 6. Menu icon – (optional) URL of the icon to use for this menu. Here is a tutorial on how to flexibly customize your menu icons. 7. Menu position – (optional) If left unspecified, new menu will appear at the bottom. Otherwise, standard WordPress menus are specified in positions of 5s. For example Dashboard = 0, Post = 5, Media = 10, and so on. Since we want our menu to appear after post, we set its position to 26. If we set it to 25 it will replace the Comments menu. ----------------------------------------------------------*/ add_menu_page(AEM_PLUGIN_TITLE, AEM_PLUGIN_TITLE, 10, 'agenteasy-properties', 'plugin_aem_settings_page', plugins_url('/images/house.gif', __FILE__), 99); add_submenu_page('', 'Properties', 'Properties', 10, 'agenteasy-properties/properties.php'); add_submenu_page('', 'Add Property', 'Add Property', 10, 'agenteasy-properties/add-property.php'); add_submenu_page('', 'Edit Property', 'Edit Property', 10, 'agenteasy-properties/edit-property.php'); } /** * ---------------------------------------------------------------------------------------------------------------------- * Enable WYSIWYG & WP Media Library editor in plugin, * ---------------------------------------------------------------------------------------------------------------------- */ if($_GET['page'] == "agenteasy-properties/add-property.php" || $_GET['page'] == "agenteasy-properties/edit-property.php") { add_action( 'init', 'ae_plugin_init' ); } function ae_plugin_init(){ if (current_user_can('upload_files')) { add_action('admin_print_scripts', 'ae_load_jquery'); add_action('admin_print_styles', 'ae_load_styles' ); //add_action('admin_menu', 'ae_file_uploader_add_metabox'); } } function ae_load_jquery(){ $ae_fileupload_dir = plugins_url('/agenteasy-properties/', dirname(__FILE__)); wp_enqueue_script('jquery'); wp_enqueue_script('ae-fileupload', $ae_fileupload_dir . 'jquery.fileupload.js'); wp_enqueue_script('ae-fileupload-ui', $ae_fileupload_dir . 'jquery.fileupload-ui.js'); } function ae_load_styles(){ $ae_fileupload_dir = plugins_url('/agenteasy-properties/', dirname(__FILE__)); wp_enqueue_style('ae-fileupload-style', $ae_fileupload_dir . 'jquery.fileupload-ui.css'); } // if($_GET['post'] > 0 && $_GET['action'] == "edit" || $_GET['post_type'] == "referrals") { // add_action( 'init', 'agent_plugin_init' ); // } // // function agent_plugin_init() { // // wp_enqueue_script('editor'); // wp_enqueue_script('thickbox'); // wp_enqueue_script('media-upload'); // add_action( 'admin_head', 'wp_tiny_mce' ); // // } /** * ---------------------------------------------------------------------------------------------------------------------- * Create WordPress Page for the Template * ---------------------------------------------------------------------------------------------------------------------- */ function plugin_aem_create_page($plugin_aem_page_title, $plugin_aem_page_content) { global $wpdb; // get the page slug/permalink $plugin_aem_page_slug = sanitize_title($plugin_aem_page_title); if(AEM_PLUGIN_TEMPLATE_PAGE_SLUG_PARENT == "") { // get the page id if exists $plugin_aem_page_id = plugin_aem_get_ID_by_slug($plugin_aem_page_slug); } else { // get the page id if exists $plugin_aem_page_id = plugin_aem_get_ID_by_slug(AEM_PLUGIN_TEMPLATE_PAGE_SLUG_PARENT.'/'.$plugin_aem_page_slug); } // check the page exists & get the parent page id if($plugin_aem_page_id > 0) { $post_info = get_post($plugin_aem_page_id); $plugin_aem_page_parent_id = $post_info->post_parent; $plugin_aem_page_menu_order = $post_info->menu_order; } else { if(AEM_THEME_ACTIVE == TRUE) { $plugin_aem_page_parent_id = plugin_aem_get_ID_by_slug(AEM_PLUGIN_TEMPLATE_PAGE_SLUG_PARENT); } else { $plugin_aem_page_parent_id = 0; } $plugin_aem_page_menu_order = 0; } // get current blog site user info $author_info = plugin_aem_wp_get_current_user(); // Insert the PAGE into the WP database $plugin_aem_page = array(); $plugin_aem_page['ID'] = $plugin_aem_page_id; $plugin_aem_page['post_title'] = $plugin_aem_page_title; $plugin_aem_page['post_type'] = 'page'; $plugin_aem_page['post_author'] = $author_info->ID; $plugin_aem_page['post_content'] = $plugin_aem_page_content; $plugin_aem_page['post_status'] = 'publish'; $plugin_aem_page['comment_status'] = 'closed'; $plugin_aem_page['ping_status'] = 'closed'; $plugin_aem_page['post_parent'] = $plugin_aem_page_parent_id; $plugin_aem_page['menu_order'] = $plugin_aem_page_menu_order; // Insert the post into the database $thePageIDx = 0; $thePageIDx = wp_insert_post( $plugin_aem_page ); if($thePageIDx > 0) { $output = true; } else { $output = false; } return $output; } /** * ---------------------------------------------------------------------------------------------------------------------- * Register Plugin Settings & Set Option default values * ---------------------------------------------------------------------------------------------------------------------- */ //call register settings function add_action( 'admin_init', 'register_plugin_aem_settings' ); //register our settings function register_plugin_aem_settings() { register_setting( 'plugin-ps-settings-group', 'plugin_aem_option_api_key' ); register_setting( 'plugin-ps-settings-group', 'plugin_aem_option_limit' ); register_setting( 'plugin-ps-settings-group', 'plugin_aem_option_xml_agent' ); register_setting( 'plugin-ps-settings-group', 'plugin_aem_option_xml_agent_enable' ); register_setting( 'plugin-ps-settings-group', 'plugin_aem_option_xml_neighborhoods_serialize' ); register_setting( 'plugin-ps-settings-group', 'plugin_aem_option_template_page_base_search' ); register_setting( 'plugin-ps-settings-group', 'plugin_aem_option_template_page_base_results' ); register_setting( 'plugin-ps-settings-group', 'plugin_aem_option_template_page_base_details' ); register_setting( 'plugin-ps-settings-group', 'plugin_aem_option_template_page_search' ); register_setting( 'plugin-ps-settings-group', 'plugin_aem_option_template_page_results' ); register_setting( 'plugin-ps-settings-group', 'plugin_aem_option_template_page_details' ); } if(get_option('plugin_aem_option_template_page_search') == '') { $pageslug = sanitize_title(AEM_PLUGIN_TEMPLATE_PAGE_TITLE_SEARCH); add_option('plugin_aem_option_template_page_search', $pageslug); update_option('plugin_aem_option_template_page_search', $pageslug); } if(get_option('plugin_aem_option_template_page_results') == '') { $pageslug = sanitize_title(AEM_PLUGIN_TEMPLATE_PAGE_TITLE_RESULTS); add_option('plugin_aem_option_template_page_results', $pageslug); update_option('plugin_aem_option_template_page_results', $pageslug); } if(get_option('plugin_aem_option_template_page_details') == '') { $pageslug = sanitize_title(AEM_PLUGIN_TEMPLATE_PAGE_TITLE_DETAILS); add_option('plugin_aem_option_template_page_details', $pageslug); update_option('plugin_aem_option_template_page_details', $pageslug); } if(AEM_PLUGIN_TEMPLATE_PAGE_SLUG_PARENT != "") { $page_parent_slug = '/'.AEM_PLUGIN_TEMPLATE_PAGE_SLUG_PARENT; } else { $page_parent_slug = ''; } if(get_option('plugin_aem_option_template_page_base_search') == '') { add_option('plugin_aem_option_template_page_base_search', get_option( 'siteurl' ).$page_parent_slug); update_option('plugin_aem_option_template_page_base_search', get_option( 'siteurl' ).$page_parent_slug); } if(get_option('plugin_aem_option_template_page_base_results') == '') { add_option('plugin_aem_option_template_page_base_results', get_option( 'siteurl' ).$page_parent_slug); update_option('plugin_aem_option_template_page_base_results', get_option( 'siteurl' ).$page_parent_slug); } if(get_option('plugin_aem_option_template_page_base_details') == '') { add_option('plugin_aem_option_template_page_base_details', get_option( 'siteurl' ).$page_parent_slug); update_option('plugin_aem_option_template_page_base_details', get_option( 'siteurl' ).$page_parent_slug); } if(get_option('plugin_aem_option_api_key') == '') { add_option('plugin_aem_option_api_key', AEM_PLUGIN_OPTION_API_KEY); } if(get_option('plugin_aem_option_limit') == '') { add_option('plugin_aem_option_limit', AEM_PLUGIN_OPTION_XML_LIMIT); } if(get_option('plugin_aem_option_xml_agent') == '') { add_option('plugin_aem_option_xml_agent', AEM_PLUGIN_OPTION_XML_AGENT); } if(get_option('plugin_aem_option_xml_agent_enable') == '') { add_option('plugin_aem_option_xml_agent_enable', AEM_PLUGIN_OPTION_XML_AGENT_ENABLE); } if(get_option('plugin_aem_option_xml_neighborhoods_serialize') == '') { add_option('plugin_aem_option_xml_neighborhoods_serialize', AEM_PLUGIN_OPTION_XML_NEIGHBORHOODS); } /** * ---------------------------------------------------------------------------------------------------------------------- * Set & Get Settings values * ---------------------------------------------------------------------------------------------------------------------- */ function wp_plugin_aem_params(){ $wp_ps = array(); $wp_ps['plugin_aem_option_xml_parser'] = AEM_PLUGIN_OPTION_XML_PARSER; $wp_ps['plugin_aem_option_api_key'] = get_option('plugin_aem_option_api_key'); $wp_ps['plugin_aem_option_limit'] = get_option('plugin_aem_option_limit'); $wp_ps['plugin_aem_option_xml_agent'] = get_option('plugin_aem_option_xml_agent'); $wp_ps['plugin_aem_option_xml_agent_enable'] = get_option('plugin_aem_option_xml_agent_enable'); $wp_ps['plugin_aem_option_xml_status'] = AEM_PLUGIN_OPTION_XML_STATUS; $wp_ps['plugin_aem_option_xml_neighborhoods_serialize'] = get_option('plugin_aem_option_xml_neighborhoods_serialize'); $wp_ps['plugin_aem_option_template_page_base_search'] = get_option('plugin_aem_option_template_page_base_search'); $wp_ps['plugin_aem_option_template_page_base_results'] = get_option('plugin_aem_option_template_page_base_results'); $wp_ps['plugin_aem_option_template_page_base_details'] = get_option('plugin_aem_option_template_page_base_details'); $wp_ps['plugin_aem_option_template_page_search'] = get_option('plugin_aem_option_template_page_search'); $wp_ps['plugin_aem_option_template_page_results'] = get_option('plugin_aem_option_template_page_results'); $wp_ps['plugin_aem_option_template_page_details'] = get_option('plugin_aem_option_template_page_details'); $wp_ps['AEM_PLUGIN_URL'] = AEM_PLUGIN_URL; return $wp_ps; } /** * ---------------------------------------------------------------------------------------------------------------------- * Template Page * ---------------------------------------------------------------------------------------------------------------------- */ function wp_plugin_aem_template($template_page, $wp_plugin_aem_params) { global $wpdb; if($template_page == "template-my-sold-properties.php") { $sold_mlsid_listings = $wpdb->get_results("SELECT * FROM ".AEM_PLUGIN_DB_Table." WHERE Status = 'Sold' ORDER BY MLS ASC", ARRAY_A); if(count($sold_mlsid_listings) > 0) { $db_listings['sold_listings'] = $sold_mlsid_listings; } else { $db_listings['sold_listings'] = array(); } } if($template_page == "template-my-active-properties.php") { $active_mlsid_listings = $wpdb->get_results("SELECT * FROM ".AEM_PLUGIN_DB_Table." WHERE Status LIKE 'Active' OR Status LIKE 'Act. Con.' OR Status LIKE 'Active Contigent' ORDER BY MLS ASC", ARRAY_A); if(count($active_mlsid_listings) > 0) { $db_listings['active_listings'] = $active_mlsid_listings; } else { $db_listings['active_listings'] = array(); } } if($template_page == "template-details.php") { // set default value as null $mlsid = 0; $address = ""; // get the url params on the property details page $aem_property_details = get_query_var('aem_property_details'); $property_vars = explode('/',$aem_property_details); // check if if(is_array($property_vars)) { // get the mlsid on property url (permalink) if(count($property_vars) > 0) { if($property_vars[0] > 0) { $mlsid = $property_vars[0]; } } // get the address on property url (permalink) if(count($property_vars) > 1) { if($property_vars[1] != "") { $address = urldecode($property_vars[1]); } } } $WHERE = " WHERE MLS = '".$mlsid."' "; $WHERE .= " AND address = '".$address."' "; $details_mlsid_listings = $wpdb->get_results("SELECT * FROM ".AEM_PLUGIN_DB_Table." ".$WHERE." LIMIT 1", ARRAY_A); if(count($details_mlsid_listings) > 0) { $db_listings['details_listings'] = $details_mlsid_listings; } else { $db_listings['details_listings'] = array(); } } // turn output buffering On ob_start(); // get the template content require_once($template_page); $output = ob_get_contents(); // silently discard the buffer contents. ob_end_clean(); return $output; } function wp_plugin_aem_template_page($template_page) { $wp_plugin_aem_params = wp_plugin_aem_params(); $output = wp_plugin_aem_template($template_page, $wp_plugin_aem_params); return $output; } /** * ---------------------------------------------------------------------------------------------------------------------- * Template Page: Search * ---------------------------------------------------------------------------------------------------------------------- */ function plugin_aem_property_templates($content) { $content = preg_replace('/

\s*[(.*)]\s*<\/p>/i', "[$1]", $content); if (strpos($content, AEM_PLUGIN_SHORTCODE_SEARCH) !== FALSE) { $content = str_replace(AEM_PLUGIN_SHORTCODE_SEARCH, wp_plugin_aem_template_page('template-search.php'), $content); } if (strpos($content, AEM_PLUGIN_SHORTCODE_RESULTS) !== FALSE){ $content = str_replace(AEM_PLUGIN_SHORTCODE_RESULTS, wp_plugin_aem_template_page('template-results.php'), $content); } if (strpos($content, AEM_PLUGIN_SHORTCODE_DETAILS) !== FALSE) { $content = str_replace(AEM_PLUGIN_SHORTCODE_DETAILS, wp_plugin_aem_template_page('template-details.php'), $content); } if (strpos($content, AEM_PLUGIN_SHORTCODE_MY_ACTIVE_PROPERTIES) !== FALSE) { $content = str_replace(AEM_PLUGIN_SHORTCODE_MY_ACTIVE_PROPERTIES, wp_plugin_aem_template_page('template-my-active-properties.php'), $content); } if (strpos($content, AEM_PLUGIN_SHORTCODE_MY_SOLD_PROPERTIES) !== FALSE) { $content = str_replace(AEM_PLUGIN_SHORTCODE_MY_SOLD_PROPERTIES, wp_plugin_aem_template_page('template-my-sold-properties.php'), $content); } return $content; } add_filter('the_content', 'plugin_aem_property_templates'); /** * ---------------------------------------------------------------------------------------------------------------------- * Custom Rewrite Rule for the "Property" Detail Page (Clean/SEO friendly URL) * ---------------------------------------------------------------------------------------------------------------------- * Example: http://myblogsite.com/detail-page/376072/2450-bush-st-san-francisco-ca-94115/ * * -> Template page : detail-page * -> MLS Listing# : 376072 * -> Property Address : 2450-bush-st-san-francisco-ca-94115 * ---------------------------------------------------------------------------------------------------------------------- */ function property_search_flush_rewrite() { global $wp_rewrite; $wp_rewrite->flush_rules(); } function property_search_vars($public_query_vars) { $public_query_vars[] = 'aem_property_details'; return $public_query_vars; } function property_search_add_rewrite_rules($wp_rewrite) { $template_page = get_option('plugin_aem_option_template_page_base_details').'/'.get_option('plugin_aem_option_template_page_details'); $template_base = get_option( 'siteurl' ).'/'; $template_page_details = str_replace($template_base, "", $template_page); $new_rules = array($template_page_details.'/(.+)' => 'index.php?pagename='.$template_page_details.'&aem_property_details=' . $wp_rewrite->preg_index(1)); $wp_rewrite->rules = $new_rules + $wp_rewrite->rules; } add_action('init', 'property_search_flush_rewrite'); add_filter('query_vars', 'property_search_vars'); add_action('generate_rewrite_rules', 'property_search_add_rewrite_rules'); /** * ---------------------------------------------------------------------------------------------------------------------- * Pagination string * ---------------------------------------------------------------------------------------------------------------------- */ function plugin_aem_getPaginationString($frontText = "", $page = 1, $totalitems, $limit = 10, $adjacents = 1, $targetpage = "/", $pagestring = "?pg=") { //defaults if(!$adjacents) $adjacents = 1; if(!$limit) $limit = 10; if(!$page) $page = 1; if(!$targetpage) $targetpage = "/"; //other vars $prev = $page - 1; //previous page is page - 1 $next = $page + 1; //next page is page + 1 $lastpage = ceil($totalitems / $limit); //lastpage is = total items / items per page, rounded up. $lpm1 = $lastpage - 1; //last page minus 1 // Now we apply our rules and draw the pagination object. We're actually saving the code to a variable in case we want to draw it more than once. $pagination = ""; if($lastpage > 1){ $pagination .= "

"; #$pagination .= "$frontText"; //previous button if ($page > 1) { $pagination .= "  « PREV  "; } else { //$pagination .= "« prev"; } //pages if ($lastpage < 7 + ($adjacents * 2)) { //not enough pages to bother breaking it up for ($counter = 1; $counter <= $lastpage; $counter++) { if ($counter == $page) { $pagination .= "$counter"; } else { $pagination .= "$counter"; } } } elseif($lastpage >= 7 + ($adjacents * 2)) { //enough pages to hide some //close to beginning; only hide later pages if($page < 1 + ($adjacents * 3)) { for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) { if ($counter == $page) { $pagination .= "$counter"; } else { $pagination .= "$counter"; } } $pagination .= "...."; $pagination .= "$lpm1"; $pagination .= "$lastpage"; //in middle; hide some front and some back } elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) { $pagination .= "1"; $pagination .= "2"; $pagination .= "..."; for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) { if ($counter == $page) { $pagination .= "$counter"; } else { $pagination .= "$counter"; } } $pagination .= "..."; $pagination .= "$lpm1"; $pagination .= "$lastpage"; //close to end; only hide early pages } else { $pagination .= "1"; $pagination .= "2"; $pagination .= "...."; for ($counter = $lastpage - (1 + ($adjacents * 3)); $counter <= $lastpage; $counter++) { if ($counter == $page) { $pagination .= "$counter"; } else { $pagination .= "$counter"; } } } } //next button if ($page < $counter - 1) { $pagination .= "  NEXT »"; } else { //$pagination .= "next »"; } $pagination .= "
"; } return $pagination; } /** * ---------------------------------------------------------------------------------------------------------------------- * XML processing * ---------------------------------------------------------------------------------------------------------------------- */ function xml2array($contents, $get_attributes=1) { if(!$contents) return array(); if(!function_exists('xml_parser_create')) { //print "'xml_parser_create()' function not found!"; return array(); } //Get the XML parser of PHP - PHP must have this module for the parser to work $parser = xml_parser_create(); xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 ); xml_parser_set_option( $parser, XML_OPTION_SKIP_WHITE, 1 ); xml_parse_into_struct( $parser, $contents, $xml_values ); xml_parser_free( $parser ); if(!$xml_values) return; //Hmm... //Initializations $xml_array = array(); $parents = array(); $opened_tags = array(); $arr = array(); $current = &$xml_array; //Go through the tags. foreach($xml_values as $data) { unset($attributes,$value); //Remove existing values, or there will be trouble //This command will extract these variables into the foreach scope // tag, type, level(int), attributes(array). extract($data);//We could use the array by itself, but this cooler. $result = ''; if($get_attributes) { //The second argument of the function decides this. $result = array(); if(isset($value)) $result['value'] = $value; //Set the attributes too. if(isset($attributes)) { foreach($attributes as $attr => $val) { if($get_attributes == 1) $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr' /** :TODO: should we change the key name to '_attr'? Someone may use the tagname 'attr'. Same goes for 'value' too */ } } } elseif(isset($value)) { $result = $value; } //See tag status and do the needed. if($type == "open") { //The starting of the tag '' $parent[$level-1] = &$current; if(!is_array($current) or (!in_array($tag, array_keys($current)))) { //Insert New tag $current[$tag] = $result; $current = &$current[$tag]; } else { //There was another element with the same tag name if(isset($current[$tag][0])) { array_push($current[$tag], $result); } else { $current[$tag] = array($current[$tag],$result); } $last = count($current[$tag]) - 1; $current = &$current[$tag][$last]; } } elseif($type == "complete") { //Tags that ends in 1 line '' //See if the key is already taken. if(!isset($current[$tag])) { //New Key $current[$tag] = $result; } else { //If taken, put all things inside a list(array) if((is_array($current[$tag]) and $get_attributes == 0)//If it is already an array... or (isset($current[$tag][0]) and is_array($current[$tag][0]) and $get_attributes == 1)) { // ...push the new element into that array. array_push($current[$tag],$result); } else { //If it is not an array... $current[$tag] = array($current[$tag],$result); //...Make it an array using using the existing value and the new value } } } elseif($type == 'close') { //End of tag '' $current = &$parent[$level-1]; } } return($xml_array); } /** * ---------------------------------------------------------------------------------------------------------------------- * Exclude Pages from the Navigation Menu * ---------------------------------------------------------------------------------------------------------------------- */ function exclude_plugin_aem_pages_from_navmenu($exclude_array) { $results_page_slug = sanitize_title(AEM_PLUGIN_TEMPLATE_PAGE_TITLE_RESULTS); $details_page_slug = sanitize_title(AEM_PLUGIN_TEMPLATE_PAGE_TITLE_DETAILS); // check if the pages has parent page & get the parent slug/permalink if(AEM_PLUGIN_TEMPLATE_PAGE_SLUG_PARENT != "") { $parent_slug = AEM_PLUGIN_TEMPLATE_PAGE_SLUG_PARENT.'/'; } else { $parent_slug = ''; } $results_page_id = plugin_aem_get_ID_by_slug($parent_slug.$results_page_slug); $details_page_id = plugin_aem_get_ID_by_slug($parent_slug.$details_page_slug); return array_merge( $exclude_array, array( $results_page_id, $details_page_id ) ); } add_filter('wp_list_pages_excludes', 'exclude_plugin_aem_pages_from_navmenu'); /** * ---------------------------------------------------------------------------------------------------------------------- * Integrate the Media Library into a Plugin * ---------------------------------------------------------------------------------------------------------------------- */ function wp_gear_manager_admin_scripts() { wp_enqueue_script('media-upload'); wp_enqueue_script('thickbox'); wp_enqueue_script('jquery'); } function wp_gear_manager_admin_styles() { wp_enqueue_style('thickbox'); } add_action('admin_print_scripts', 'wp_gear_manager_admin_scripts'); add_action('admin_print_styles', 'wp_gear_manager_admin_styles'); /** * ---------------------------------------------------------------------------------------------------------------------- * WP Admin Plugin Setting Page * ---------------------------------------------------------------------------------------------------------------------- */ function plugin_aem_settings_page() { ?>

 

'; echo 'Error Saving Agent MLSID setting. MLSID is empty.'; echo '

'; $errcount++; } } else { update_option('plugin_aem_option_xml_agent_enable', 'No'); } if($_POST["plugin_aem_option_limit"] >= 10 && $_POST["plugin_aem_option_limit"] <= 100) { update_option('plugin_aem_option_limit', $_POST["plugin_aem_option_limit"]); } else { echo '

'; echo 'Error Saving LIMIT setting. Value should have a minimum value of 10 and maximum value of 100.'; echo '

'; $errcount++; } if($errcount == 0) { echo '

'; echo 'Settings Saved.'; echo '

'; } } // update the Neighborhoods array if (isset($_POST["update_xml_settings_neighborhoods"])){ if(count($_POST["plugin_aem_option_xml_neighborhoods"]) > 0) { $plugin_aem_option_xml_neighborhoods_serialize = serialize($_POST["plugin_aem_option_xml_neighborhoods"]); $plugin_aem_option_xml_neighborhoods_serialize = htmlentities($plugin_aem_option_xml_neighborhoods_serialize,ENT_QUOTES); delete_option('plugin_aem_option_xml_neighborhoods_serialize'); add_option('plugin_aem_option_xml_neighborhoods_serialize', $plugin_aem_option_xml_neighborhoods_serialize); } echo '

'; echo 'Neighborhoods Updated.'; echo '

'; } // update the Template Pages if (isset($_POST["update_template_pages"])){ update_option('plugin_aem_option_template_page_base_search', $_POST["plugin_aem_option_template_page_base_search"]); update_option('plugin_aem_option_template_page_base_results', $_POST["plugin_aem_option_template_page_base_results"]); update_option('plugin_aem_option_template_page_base_details', $_POST["plugin_aem_option_template_page_base_details"]); update_option('plugin_aem_option_template_page_search', $_POST["plugin_aem_option_template_page_search"]); update_option('plugin_aem_option_template_page_results', $_POST["plugin_aem_option_template_page_results"]); update_option('plugin_aem_option_template_page_details', $_POST["plugin_aem_option_template_page_details"]); echo '

'; echo 'Settings Saved.'; echo '

'; } ?>
Plugin Settings
Agent API Key You'll need an API key to use this plugin.
Agent MLSID Enable: style="border:1px solid #CCCCCC;" />    MLSID: XML agent: Agent MLSID
Limit Number of results/listings to return per page, max is 100


Neighborhoods
0) {?>
style="border:1px solid #CCCCCC;">
No Neighborhood.


Template Page Permalink :  Value should be the same with the Page Permalink where the Shortcode is placed Shortcode
/ /
/ /
/ /

 

Shortcodes Description
When the Agent MLSID is supplied in the Plugin Settings and the Shortcode is on a page, it will display the auto feed of the Agents Active Listings.
When the Agent MLSID is supplied in the Plugin Settings and the Shortcode is on a page, it will display the auto feed of the Agents Sold Listings.

 

Usage: Add the trigger text (Shortcode) to the page content to display the template. By default, the pages with shortcode are created already on plugin activation.

 


 

 

'Contact Info', 'agentMLSID' => '', 'agentImage' => '', 'agentName' => '', 'agentFax' => '', 'agentDRE' => '', 'agentPhone' => '', 'agentMobile' => '', 'agentEmail' => '', 'agentWebsite' => '', 'agentOffice' => '', 'agent1name' => '', 'agent1phone' => '', 'agent2name' => '', 'agent2phone' => '', 'agentAddress' => ''); if ( ! get_option('widget_aem_agent_information')){ add_option('widget_aem_agent_information' , $data); #echo "add widget options"; } else { #update_option('widget_aem_agent_information' , $data); #echo "update widget options"; } } function deactivate(){ #delete_option('widget_aem_agent_information'); #echo "delete widget options"; } function control(){ $data = get_option('widget_aem_agent_information'); ?>

Teams

Agent #1 (left)

Agent #1 (right)

get_var("SELECT ID FROM {$wpdb->posts} WHERE guid = '$image_src' LIMIT 1"); if($attachment_id == null){ $image_src = basename ( $image_src ); $id = $wpdb->get_var("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE '%$image_src%' LIMIT 1"); } if($attachment_id == null){ $attachment_id = 0; } return $attachment_id; } /** * ---------------------------------------------------------------------------------------------------------------------- * Custom Post Type >> Property Listings * ---------------------------------------------------------------------------------------------------------------------- */ /** * ------------------------------------------------------------------------------------------------------------------ * Custom Post Type >> Property Listings >> Enable WYSIWYG & WP Media Library editor in plugin * ------------------------------------------------------------------------------------------------------------------ */ if($_GET['post'] > 0 && $_GET['action'] == "edit" || $_GET['post_type'] == "property_listings") { add_action( 'init', 'ae_property_listings_plugin_init' ); } function ae_property_listings_plugin_init(){ if(current_user_can('upload_files')) { add_action('admin_print_scripts', 'ae_property_listings_load_jquery'); add_action('admin_print_styles', 'ae_property_listings_load_styles' ); add_action( 'admin_head', 'wp_tiny_mce' ); } } function ae_property_listings_load_jquery(){ wp_enqueue_script('editor'); wp_enqueue_script('thickbox'); wp_enqueue_script('media-upload'); $ae_fileupload_dir = plugins_url('/agenteasy-properties/', dirname(__FILE__)); wp_enqueue_script('jquery'); wp_enqueue_script('ae-fileupload', $ae_fileupload_dir . 'jquery.fileupload.js'); wp_enqueue_script('ae-fileupload-ui', $ae_fileupload_dir . 'jquery.fileupload-ui.js'); } function ae_property_listings_load_styles(){ $ae_fileupload_dir = plugins_url('/agenteasy-properties/', dirname(__FILE__)); wp_enqueue_style('ae-fileupload-style', $ae_fileupload_dir . 'jquery.fileupload-ui.css'); } /** * ------------------------------------------------------------------------------------------------------------------ * Custom Post Type >> Property Listings >> Register/Setup Post Type * ------------------------------------------------------------------------------------------------------------------ */ add_action('init', 'ae_register_property_listings'); function ae_register_property_listings() { $labels = array( 'name' => _x('AE Listings', 'post type general name'), 'singular_name' => _x('Property Listing Item', 'post type singular name'), 'add_new' => _x('Add New', 'property_listing item'), 'add_new_item' => __('Add New Property Listing Item'), 'edit_item' => __('Edit Property Listing Item'), 'new_item' => __('New Property Listing Item'), 'view_item' => __('View Property Listing Item'), 'search_items' => __('Search Property Listing'), 'not_found' => __('Nothing found'), 'not_found_in_trash' => __('Nothing found in Trash'), 'parent_item_colon' => '' ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => array('slug' => 'property-listings', 'with_front' => true), 'capability_type' => 'post', 'hierarchical' => false, 'menu_position' => 100, 'supports' => array('title'), #array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes', 'post-formats'), 'has_archive' => false, 'can_export' => true ); register_post_type( 'property_listings' , $args ); flush_rewrite_rules(); } /** * ------------------------------------------------------------------------------------------------------------------ * tells WP to overwrite existing images without changing the filenames * ------------------------------------------------------------------------------------------------------------------ */ add_filter('wp_handle_upload_overrides','noneUniqueFilename'); function noneUniqueFilename($overrides){ $overrides['test_form'] = false; $overrides['unique_filename_callback'] = 'nonUniqueFilenameCallback'; return $overrides; } function nonUniqueFilenameCallback($directory, $name, $extension){ $filename = $name . strtolower($extension); removeOldAttach($filename); return $filename; } function removeOldAttach($filename){ $arguments = array( 'numberposts' => -1, 'meta_key' => '_wp_attached_file', 'meta_value' => $filename, 'post_type' => 'attachment' ); $Attachments_to_remove = get_posts($arguments); foreach($Attachments_to_remove as $a) { wp_delete_attachment($a->ID, true); } } /** * ---------------------------------------------------------------------------------------------------------------------- * Function To Process Image Uploading into WP Media Library * ---------------------------------------------------------------------------------------------------------------------- */ function add_xml_img_to_wp_media_ibrary($image, $post_id, $imgURLname) { require_once(ABSPATH . '/wp-admin/includes/file.php'); require_once(ABSPATH . '/wp-admin/includes/media.php'); require_once(ABSPATH . '/wp-admin/includes/image.php'); $results = array(); $name = basename($image); // name $binary_data = @file_get_contents($image); $getimagesize = @getimagesize($image_url); // type $type = $getimagesize['mime']; $tmp_name = tempnam(dirname(__FILE__)."/tmp", $img_name); // tmp_name $handle = @fopen($tmp_name, "w"); @fwrite($handle, $binary_data); @fclose($handle); $size = @filesize($tmp_name); // size if(isset($name) && !empty($name)) { // nothing to do... } else { $name = $imgURLname; // name } if(isset($name) && !empty($name)) { // nothing to do... } else { $name = time(); //$imgURLname; // name } //array to mimic $_FILES $file_array = array( 'name' => $name, 'type' => $type, 'tmp_name' => $tmp_name, 'error' => 0, 'size' => $size ); //the actual image processing, that is, move to upload directory, generate thumbnails and image sizes and writing into the database happens here #$mhs = media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()); $mhs = media_handle_sideload($file_array, $post_id, $name); // store thr processing result/details into an array $results = array('file' => $file_array, 'id' => $mhs); @unlink($tmp_name); return $results; } /** * ------------------------------------------------------------------------------------------------------------------ * Custom Post Type >> Property Listings >> Save Fields * ------------------------------------------------------------------------------------------------------------------ */ add_action('save_post', 'save_details_property_listings'); function save_details_property_listings() { global $post; // Stop WP from clearing custom fields on autosave, and also during ajax requests (e.g. quick edit) and bulk edits. if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || (defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { return; } // Clean, Validate and Save Custom Fields $listing = array(); // Property Details $listing['Represented'] = 'Seller'; $listing['Address'] = ''; $listing['MLS'] = ''; $listing['Bedrooms'] = ''; $listing['Bathrooms'] = ''; $listing['PropertyType'] = ''; $listing['Neighborhood'] = ''; $listing['Description'] = ''; $listing['ListingPrice'] = ''; $listing['SellingPrice'] = ''; $listing['SoldDate'] = ''; $listing['ListingAgent'] = ''; $listing['ListingOffice'] = ''; $listing['Status'] = ''; // PrimaryDetails $listing['CrossStreet'] = ''; $listing['ApproximateSqFt'] = ''; $listing['PricePerSqFt'] = ''; $listing['YearBuilt'] = ''; $listing['TotalRooms'] = ''; $listing['HOADues'] = ''; // AdditionalDetails $listing['Parking'] = ''; $listing['Type'] = ''; $listing['Style'] = ''; $listing['Floors'] = ''; $listing['BathTypeIncludes'] = ''; $listing['Kitchen'] = ''; $listing['DiningRoom'] = ''; $listing['LivingRoom'] = ''; $listing['HeatingCoolingSystem']= ''; $listing['LaundryAppliances'] = ''; $listing['SpecialFeatures'] = ''; $listing['CommonAreas'] = ''; $listing['Transportation'] = ''; $listing['Shopping'] = ''; //$listing['Comment'] = ''; // photos/images $listing['FeaturedImage'] = ''; $listing['Photos'] = ''; foreach($listing as $listing_key => $listing_value) { if($listing_key == 'Photos') { if(!isset($_POST['Photos'])) { $_POST['Photos'] = array(); } if(count($_POST['Photos']) > 0) { foreach($_POST['Photos'] as $photos_key => $photos_val) { if(isset($_POST['removedPhoto'][$photos_key])) { // don't add photo } else { $ignore_image = false; $image = $_POST['Photos'][$photos_key]; /* // ------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------------- */ if(isset($_POST['MID']) && !empty($_POST['MID'])) { if($image != AEM_PLUGIN_URL."/images/no_image_available.jpg") { #if(@fopen($image,'r') !== false) { // upload into wp media library $imgURLname = basename($image); // name $add_to_wpml_result = add_xml_img_to_wp_media_ibrary($image, $post->ID, $imgURLname); #echo '
'; echo '
'; print_r($add_to_wpml_result); echo '
'; // check if added into wp media library if(is_int($add_to_wpml_result['id'])) { if($add_to_wpml_result['id'] > 0) { // Image added into WP Media Library. // get image @list( $img_src, $width, $height ) = image_downsize($add_to_wpml_result['id'], 'full'); // update the value of the image url $image = $img_src; #if(@fopen($img_src,'r') !== false) { #echo '

Image retrived from WP Media Library. ('.$image.')

'; #} else { #echo '

Failed getting Image URL from WP Media Library.

'; #} } else { $ignore_image = true; // Failed adding image into WP Media Library } } else { $ignore_image = true; // Failed adding image into WP Media Library } #} else { #$ignore_image = true; // Image doesn't exists #} } else { $ignore_image = true; // Image is ignore } } if($ignore_image == false) { $listing['Photos'][] = $image; update_post_meta($post->ID, 'Photos', $listing['Photos']); } } } } } else { update_post_meta($post->ID, $listing_key, $_POST[$listing_key]); } } if(!isset($_POST['Represented']) || empty($_POST['Represented'])) { update_post_meta($post->ID, 'Represented', 'Seller'); } update_post_meta($post->ID, "Description", $_POST["content"]); } /** * ------------------------------------------------------------------------------------------------------------------ * Custom Post Type >> Property Listings >> Main Post Type List Columns * ------------------------------------------------------------------------------------------------------------------ */ // Add to admin_init function add_filter('manage_edit-property_listings_columns', 'add_new_property_listings_columns'); function add_new_property_listings_columns($property_listings_columns) { $new_columns['cb'] = ''; $new_columns['title'] = _x('Title', 'column name'); $new_columns['Address'] = __('Address'); $new_columns['Status'] = __('Status'); $new_columns['Represented'] = __('Represented'); $new_columns['ListingPrice'] = __('ListingPrice'); $new_columns['SellingPrice'] = __('SellingPrice'); $new_columns['FeaturedImage']= __('Featured Image'); $new_columns['ID'] = __('ID'); return $new_columns; } /** * ------------------------------------------------------------------------------------------------------------------ * Custom Post Type >> Property Listings >> Function to echo the selected field * ------------------------------------------------------------------------------------------------------------------ */ add_action("manage_posts_custom_column", "property_listings_custom_columns"); function property_listings_custom_columns($field){ global $post; $wp_plugin_aem_params = wp_plugin_aem_params(); switch ($field){ case "ID": $value = get_the_ID(); echo $value; break; case "title": $value = get_the_title(); echo $value; break; case "description": $value = get_the_content(); echo $value; break; case "excerpt": $value = get_the_excerpt(); echo $value; break; case "FeaturedImage": $value = ''; $fields = get_post_custom($post->ID); if(isset($fields[$field][0]) && !empty($fields[$field][0])) { $FeaturedImage = $fields['FeaturedImage'][0]; if(!empty($FeaturedImage)) { $value = ''; } } echo $value; break; default: $value = ''; if(isset($field) && !empty($field)) { $fields = get_post_custom($post->ID); if(isset($fields[$field][0]) && !empty($fields[$field][0])) { $value = $fields[$field][0]; } } echo $value; break; } } /** * ------------------------------------------------------------------------------------------------------------------ * Custom Post Type >> Property Listings >> Set Fields * ------------------------------------------------------------------------------------------------------------------ */ add_action("admin_init", "ae_admin_init_property_listings"); function ae_admin_init_property_listings(){ add_meta_box("property_listing_details-meta", "Property Details", "property_listing_fields", "property_listings", "normal", "high"); $wp_plugin_aem_params = wp_plugin_aem_params(); if(!empty($wp_plugin_aem_params['plugin_aem_option_api_key'])) { add_meta_box("property_listing_parser-meta", "Property Details XML Parser", "property_listing_parser", "property_listings", "side", "low"); } } function property_listing_parser() { if($_GET['post_type'] == 'property_listings' || $_GET['action'] == 'edit') { ?>
Property MLSID:
Get MLSID Property details from XML and
fills out the 'Property Details' form fields.
ID); $custom_fields_exempt = array('_edit_lock', '_edit_last'); if(is_array($custom_fields)) { foreach($listing as $field_key => $field_value) { if(!in_array($field_key,$custom_fields_exempt)) { $listing[$field_key] = $custom_fields[$field_key][0]; } } } if(isset($listing['Photos']) && !empty($listing['Photos'])) { $listing['Photos'] = unserialize($listing['Photos']); } if(!is_array($listing['Photos'])) { $listing['Photos'] = array(); } /** * ---------------------------------------------------------------------------------------------------------------------- * Process >> Get Property * ---------------------------------------------------------------------------------------------------------------------- */ // check if if(isset($_GET['MID']) && !empty($_GET['MID'])) { // set & parse the xml $xml_query_url = "property?mlsid=".$_GET['MID']; $xml_url = $wp_plugin_aem_params['plugin_aem_option_xml_parser'].urlencode($xml_query_url.'&apikey='.$wp_plugin_aem_params['plugin_aem_option_api_key']); // open the xml url if ($f = @fopen($xml_url, 'r')) { $xml = ''; while (!feof($f)) { $xml .= fgets($f, 4096); } fclose($f); $arr = xml2array($xml); //print_r($arr); if (sizeof($arr) == 1 && $arr["Listing"]){ if(array_key_exists("MLS", $arr["Listing"])) { echo '

'; echo 'Property details successfully retrieved. Click the \'Publish\' or \'Save Draft\' button to save the property details.'; echo '

'; if(is_array($listing)) { $listing_title = $arr["Listing"]['Title']['value']; foreach($listing as $field_key => $field_value) { if(!in_array($field_key,$custom_fields_exempt)) { if(isset($arr["Listing"]['PrimaryDetails'][$field_key])) { $listing[$field_key] = $arr["Listing"]['PrimaryDetails'][$field_key]['value']; } elseif(isset($arr["Listing"]['AdditionalDetails'][$field_key])) { $listing[$field_key] = $arr["Listing"]['AdditionalDetails'][$field_key]['value']; } else { $listing[$field_key] = $arr["Listing"][$field_key]['value']; } } } } if(is_array($arr["Listing"]['Photos']['Photo'])) { if(count($arr["Listing"]['Photos']['Photo']) > 0) { foreach($arr["Listing"]['Photos']['Photo'] as $Photos_photo) { if(!empty($Photos_photo['URL']['value'])) { $listing['Photos'][] = $Photos_photo['URL']['value']; } } } } if(!isset($listing['Represented']) || empty($listing['Represented'])) { $listing['Represented'] = 'Seller'; update_post_meta($post->ID, 'Represented', 'Seller'); } /*echo '
';
							print_r($arr["Listing"]);
							echo '
';*/ } else { echo '
Failed retrieving property details. MLSID doesn\'t exists

'; } } else { echo '

'; echo 'Failed retrieving property details. MLSID doesn\'t exists'; echo '

'; } } } /*if(!isset($listing['Status']) || empty($listing['Status'])) { $listing['Status'] = 'Active'; }*/ ?>
$property_val) { ?>
: />    />    />
:
:
: 0) { ?>
: 0) { ?>
: YYYY-mm-dd

Property Photos:
0) { ?>

/> Featured Image     Remove Image
 
> Property Listings >> Format the Content of the Property Listing Post Type (single page content) * ------------------------------------------------------------------------------------------------------------------ */ function plugin_ae_customposttype_fields_property_listings($content) { global $post; if($post->post_type == "property_listings") { $wp_plugin_aem_params = wp_plugin_aem_params(); $listing = array(); // Property Details $listing['Title'] = get_the_title(); $listing['Address'] = ''; $listing['MLS'] = ''; $listing['Bedrooms'] = ''; $listing['Bathrooms'] = ''; $listing['PropertyType'] = ''; $listing['Neighborhood'] = ''; $listing['Description'] = ''; $listing['ListingPrice'] = ''; $listing['SellingPrice'] = ''; $listing['SoldDate'] = ''; $listing['ListingAgent'] = ''; $listing['ListingOffice'] = ''; $listing['Status'] = ''; // PrimaryDetails $listing['CrossStreet'] = ''; $listing['ApproximateSqFt'] = ''; $listing['PricePerSqFt'] = ''; $listing['YearBuilt'] = ''; $listing['TotalRooms'] = ''; $listing['HOADues'] = ''; // AdditionalDetails $listing['Parking'] = ''; $listing['Type'] = ''; $listing['Style'] = ''; $listing['Floors'] = ''; $listing['BathTypeIncludes'] = ''; $listing['Kitchen'] = ''; $listing['DiningRoom'] = ''; $listing['LivingRoom'] = ''; $listing['HeatingCoolingSystem']= ''; $listing['LaundryAppliances'] = ''; $listing['SpecialFeatures'] = ''; $listing['CommonAreas'] = ''; $listing['Transportation'] = ''; $listing['Shopping'] = ''; //$listing['Comment'] = ''; // photos/images $listing['FeaturedImage'] = ''; $listing['Photos'] = ''; $custom = get_post_custom($post->ID); if(is_array($custom)) { foreach($custom as $field_key => $field_value) { $listing[$field_key] = $field_value[0]; } } if(isset($listing['Photos']) && !empty($listing['Photos'])) { $listing['Photos'] = unserialize($listing['Photos']); } if(!is_array($listing['Photos'])) { $listing['Photos'] = array(); } $listing['Description'] = $content; $listings[0] = $listing; $content = ""; ob_start(); // ------------------------------------------------------------------------------------------------------ ?>
0) { // check listing exists/found ?>

Listing Price: $
Beds, Baths Status:
MLS Listing#:

0) { ?> $ad_val) { ?>
:
0) { ?>
 
1) { ?>

Photos

1) { ?>
1) { ?>
 
 

Location

Loading Map...
" target="_blank" style="text-decoration:none; font-size:11px;">View Larger Map
 
 
This listing courtesy of
 
Property Not Found
> Property Listings >> Admin Sub Page for Shortcodes * ------------------------------------------------------------------------------------------------------------------ */ add_action('admin_menu', 'register_property_listings_custom_submenu_page'); function register_property_listings_custom_submenu_page() { add_submenu_page( 'edit.php?post_type=property_listings', 'Shortcodes', 'Shortcodes', 'manage_options', 'shortcode', 'property_listings_custom_submenu_page_callback' ); } function property_listings_custom_submenu_page_callback() { ?>


Shortcode Usage
[AE_PROPERTY_LISTINGS] Add the trigger text (shortcode) to the page/post content to display the property listings.

Shortcode Options Description Example
num The number of records to display. By default it is set to display All records. [AE_PROPERTY_LISTINGS num="5"]
show_pagination Set this to 'no' if you don't want to display the pagination. By default it is set to 'yes'.
The pagination is automatically hidden if 'num' option is not set and if all records are already displayed.
[AE_PROPERTY_LISTINGS show_pagination="no"]
sort_order The sort order of records ('ASC' or 'DESC'). By default it is set it sort in 'ASC'. [AE_PROPERTY_LISTINGS order_sort="ASC"]
sort_by Sort records by 'post_title', 'Status', 'Address', 'ListingPrice', 'SellingPrice', 'SoldDate'. By default it is sorted by 'post_title'. [AE_PROPERTY_LISTINGS order_by="title"]
id Filter records to display based on ID (comma separated IDs). Display only the records with specific IDs: [AE_PROPERTY_LISTINGS id="1,2,3"]
exclude_id Filter records to display based on ID (comma separated IDs). Display all records but NOT the specified IDs. [AE_PROPERTY_LISTINGS exclude_id="1,2,3"]
status Filter records to display based on status: . [AE_PROPERTY_LISTINGS status="Active"]

Example Shortcode
All Property Listings [AE_PROPERTY_LISTINGS num="10" show_pagination="yes" sort_order="ASC" sort_by="post_title" id="" exclude_id="" status=""]
Active Property Listings [AE_PROPERTY_LISTINGS num="10" show_pagination="yes" sort_order="ASC" sort_by="ListingPrice" id="" exclude_id="" status="Active"]
Sold Property Listings [AE_PROPERTY_LISTINGS num="10" show_pagination="yes" sort_order="DESC" sort_by="SoldDate" id="" exclude_id="" status="Sold"]
0) { $limit = $atts['num']; } else { $limit = 1000; } $loop = new WP_Query( $args ); // cast the posts object into array $property_listings = (array)$loop->posts; if($atts['status'] != 'N/A') { if(count($property_listings) > 0) { foreach($property_listings as $pl_key => $pl_val) { $pl_listing = (array)$property_listings[$pl_key]; $pl_customfields = get_post_custom($pl_listing['ID']); if($pl_customfields['Status'][0] == $atts['status']) { // ignore pl... } else { unset($property_listings[$pl_key]); } } $property_listings = array_values($property_listings); } } // Search Results: Pagination $frontText = ""; $adjacents = 1; $targetpage = "index.php?"; $pagestring = "pg="; $total_listings = count($property_listings); // get current page if($_GET['pg'] > 0) { $pg = $_GET['pg']; // get page from the url parameter ( eg. ?pg=2 ) } else { $pg = 1; // default = page 1 } // check if current page value is greater than 1 (page 2 and above) if($pg > 1) { $offset = (($pg - 1) * $limit);// set the start number of displaying records } else { $offset = 0; // default: page 1 will start displaying records from record 1 } // get listings page numbering $n = $offset; $data = ''; ob_start(); // ------------------------------------------------------------------------------------------------------- ?>

Loading...

Loading Records...