.
*/
/**
* ----------------------------------------------------------------------------------------------------------------------
* 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', 'Property 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' => 9010, 'district' => 'District 9', 'title' => 'Inner Mission');
$plugin_aem_option_xml_neighborhoods[9030] = array('enable' => 'Yes', 'id' => 9010, 'district' => 'District 9', 'title' => 'Mission Bay');
$plugin_aem_option_xml_neighborhoods[9040] = array('enable' => 'Yes', 'id' => 9010, 'district' => 'District 9', 'title' => 'Potrero Hill');
$plugin_aem_option_xml_neighborhoods[9050] = array('enable' => 'Yes', 'id' => 9010, 'district' => 'District 9', 'title' => 'South of Market');
$plugin_aem_option_xml_neighborhoods[9060] = array('enable' => 'Yes', 'id' => 9010, 'district' => 'District 9', 'title' => 'South Beach');
$plugin_aem_option_xml_neighborhoods[9070] = array('enable' => 'Yes', 'id' => 9010, 'district' => 'District 9', 'title' => 'Ctrl Waterfront / Dogpatch');
$plugin_aem_option_xml_neighborhoods[9080] = array('enable' => 'Yes', 'id' => 9010, '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%/");
}
/**
* ----------------------------------------------------------------------------------------------------------------------
* 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");
# 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");
}
/**
* ----------------------------------------------------------------------------------------------------------------------
* 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__), 26);
add_submenu_page('agenteasy-properties', 'Properties', 'Properties', 10, 'agenteasy-properties/properties.php');
add_submenu_page('agenteasy-properties', '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' );
}
/**
* ----------------------------------------------------------------------------------------------------------------------
* Additional Plugin
* ----------------------------------------------------------------------------------------------------------------------
* Note: Plugin is integrated to AgentEasy Properties Plugin to enable multiple image select & upload
* ----------------------------------------------------------------------------------------------------------------------
* Plugin Name: Faster Image Insert
* Plugin URI: http://blog.ticktag.org/2009/02/19/2765/
* Description: Fully integrates media manager into editing interface, avoid having to reload it separately in thickbox pop-up; comes with enhanced features, suitable for precise image control.
* Version: 2.1.0
* Author: David Frank
* Author URI: http://blog.ticktag.org/
* License: GPL2
* ----------------------------------------------------------------------------------------------------------------------
*/
//notice in editing panel when wp_version < 3.0
function fast_insert_form_notice() {
?>
3.0
function fast_insert_form() {
global $post_ID, $temp_ID;
$id = (int) (0 == $post_ID ? $temp_ID : $post_ID);
$upload_form = 'faster_insert_upload_form';
$noflash = get_option( $upload_form );
?>
=')) {
$compat = true;
} else {
$compat = false;
}
//upload supported custom post type
$customtype = 'faster_insert_post_type';
$ptype = get_option( $customtype );
//integrates manager into post/page edit inferface.
if($compat) {
add_meta_box('fastinsert', 'Faster Insert', 'fast_insert_form', 'post', 'normal', 'high');
add_meta_box('fastinsert', 'Faster Insert', 'fast_insert_form', 'page', 'normal', 'high');
$ptypes = explode(",",$ptype);
foreach ($ptypes as $type) add_meta_box('fastinsert', 'Faster Insert', 'fast_insert_form', $type, 'normal', 'high');
} else {
add_meta_box('fastinsert', 'Faster Insert', 'fast_insert_form_notice', 'post', 'normal', 'high');
add_meta_box('fastinsert', 'Faster Insert', 'fast_insert_form_notice', 'page', 'normal', 'high');
}
}
// various javascript / css goodies for:
// 1. selected insert
// 2. mass-editing
// 3. styling for iframe and mass-edit table
function faster_insert_local() {
?>
$attachment ) {
$attachment = stripslashes_deep( $attachment );
if (!empty($attachment['selected'])) {
$html = $attachment['post_title'];
if ( !empty($attachment['url']) ) {
if ( strpos($attachment['url'], 'attachment_id') || false !== strpos($attachment['url'], get_permalink($post_id)) )
$rel = " rel='attachment wp-att-".attribute_escape($attachment_id)."'";
$html = "$html ";
}
$html = apply_filters('media_send_to_editor', $html, $attachment_id, $attachment);
//since 1.5.0: is the same as a blank space, but can be passed onto TinyMCE
if(!$oneline) $result .= $html.str_repeat("\\n".$cstring."\\n",$number);
else $result .= $html.str_repeat($cstring,$number);
}
}
return fast_insert_to_editor($result);
}
return $errors;
}
//filter for media_upload_gallery, recognize insertall request.
function faster_insert_media_upload_gallery() {
if ( isset($_POST['insertall']) ) {
$return = faster_insert_form_handler();
if ( is_string($return) )
return $return;
if ( is_array($return) )
$errors = $return;
}
}
//filter for media_upload_image, recognize insertall request.
function faster_insert_media_upload_image() {
if ( isset($_POST['insertall']) ) {
$return = faster_insert_form_handler();
if ( is_string($return) )
return $return;
if ( is_array($return) )
$errors = $return;
}
}
//filter for media_upload_library, recognize insertall request.
function faster_insert_media_upload_library() {
if ( isset($_POST['insertall']) ) {
$return = faster_insert_form_handler();
if ( is_string($return) )
return $return;
if ( is_array($return) )
$errors = $return;
}
}
//for disabling captions
function caption_off() {
$no_caption = 'faster_insert_no_caption';
$nocaption = get_option( $no_caption );
if($nocaption)
return true;
}
//adds a new submenu for options
function faster_insert_option() {
add_options_page(__('Faster Image Insert - User Options','faster-image-insert'), 'Faster Image Insert', 8, __FILE__, 'faster_insert_option_detail');
}
//display the actual content of option page.
function faster_insert_option_detail() {
$faster_insert_update = 'faster_insert_update';
$faster_insert_delete = 'faster_insert_delete';
$faster_insert_valid = 'faster_insert_valid';
//all the options
$upload_form = 'faster_insert_upload_form';
$image_line = 'faster_insert_image_line';
$line_number = 'faster_insert_line_number';
$no_caption = 'faster_insert_no_caption';
$customstring = 'faster_insert_plugin_custom';
$customtype = 'faster_insert_post_type';
//add options
add_option( $upload_form, false );
add_option( $image_line, false );
add_option( $line_number, 1 );
add_option( $no_caption, false );
add_option( $customstring, "
" );
add_option( $customtype, "" );
//update options
if( !empty($_POST[ $faster_insert_update ]) && check_admin_referer($faster_insert_valid,'check-form') ) {
$_POST[ $upload_form ] == 'selected' ? $flash = true : $flash = false;
$_POST[ $image_line ] == 'selected' ? $image = true : $image = false;
if(is_numeric($_POST[ $line_number ])) $number = $_POST[ $line_number ]; else $number = 1;
$_POST[ $no_caption ] == 'selected' ? $caption = true : $caption = false;
if(is_string($_POST[ $customstring ]) && !empty($_POST[ $customstring ])) $cstring = $_POST[ $customstring ]; else $cstring = "
";
if(is_string($_POST[ $customtype ]) && !empty($_POST[ $customtype ])) $ptype = $_POST[ $customtype ]; else $ptype = "";
update_option( $upload_form, $flash );
update_option( $image_line, $image );
update_option( $line_number, $number );
update_option( $no_caption, $caption );
update_option( $customstring, $cstring );
update_option( $customtype, $ptype );
echo ''.__('Settings saved.', 'faster-image-insert').'
';
}
//delete options
if( isset($_POST[ $faster_insert_delete ]) && $_POST[ $faster_insert_valid ] == 'V' ) {
//compatible with version older than FII 2.0
delete_option( $load_iframe );
delete_option( $upload_form );
delete_option( $image_line );
delete_option( $line_number );
delete_option( $mass_edit );
delete_option( $no_caption );
delete_option( $backcompat );
delete_option( $plugindebug );
delete_option( $customstring );
delete_option( $customtype );
echo ''.__('Settings deleted.', 'faster-image-insert').'
';
}
//current value
$flash = get_option( $upload_form );
$image = get_option( $image_line );
$number = get_option( $line_number );
$caption = get_option( $no_caption );
$cstring = get_option( $customstring );
$ptype = get_option( $customtype );
echo ''."\n".
'
'."\n".
'
'.__('Faster Image Insert - User Options','faster-image-insert').' '."\n".
'
'.__('Updates your settings here', 'faster-image-insert').' ';
?>
'."\n";
}
//load languages file for i18n
function faster_insert_textdomain() {
if (function_exists('load_plugin_textdomain')) {
if ( !defined('WP_PLUGIN_DIR') ) {
load_plugin_textdomain('faster-image-insert', str_replace( ABSPATH, '', dirname(__FILE__) ) . '/languages');
} else {
load_plugin_textdomain('faster-image-insert', false, dirname( plugin_basename(__FILE__) ) . '/languages');
}
}
}
//hook it up
add_action('init', 'faster_insert_textdomain');
add_action('admin_menu', 'faster_insert_option');
add_action('admin_menu', 'fast_image_insert', 20);
add_action('admin_head', 'faster_insert_local');
add_filter('media_upload_gallery', 'faster_insert_media_upload_gallery');
add_filter('media_upload_library', 'faster_insert_media_upload_library');
add_filter('media_upload_image', 'faster_insert_media_upload_image');
add_filter('disable_captions', 'caption_off');
// end of -> Additional Plugin >> Plugin Name: Faster Image Insert -----------------------------------------------------
/**
* ----------------------------------------------------------------------------------------------------------------------
* 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 .= "
";
}
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 '
';
}
?>
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');
?>
Title:
Agent MLSID:
Agent Name:
Image URL:
DRE#:
Mobile#:
Phone#:
Fax#:
Email:
Website:
Office/Company Name:
Address:
Teams
Agent #1 (left)
Name:
Phone:
Agent #1 (right)
Name:
Phone:
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;
}
?>