mylocation = $mydir . DIRECTORY_SEPARATOR . basename(__FILE__); $this->base_uri = $site_uri . '/wp-content/plugins/' . $mydir . '/'; $this->interface =& new View_Property($this->base_uri, $this->mylocation); $this->property = new Model_Property($wpdb,$wpdb->prefix); // Set the imagepath for the thumbnails $path = str_replace(ABSPATH, '', trim(get_option('upload_path'))); $url = trailingslashit(trailingslashit($site_uri) . $path); $this->interface->set_imagepath($url); // Add installation and uninstall functions register_activation_hook(__FILE__, array(&$this, 'install')); register_deactivation_hook(__FILE__, array(&$this, 'uninstall')); add_action('init',array(&$this,'create_admin_header')); add_action('init',array(&$this,'handle_ajax')); add_filter('rest_methods', array(&$this,'enable_rest')); // Administration header styles and javascript add_action('admin_head', array(&$this,'add_admin_header')); // Create administration menu add_action('admin_menu', array(&$this,"add_admin_pages")); // Install plugins add_action('clearskys_property_manage', array(&$this,"show_notes_application")); // Google Sitemap plugin integration add_action('sm_buildmap', array(&$this,"build_sitemap")); } function install() { $csp = $this->getpluginoptions(); } function getpluginoptions() { $csp = get_option('clearskys_smallproperty_config'); if(empty($csp)) { // Set up default configuration values $csp['build'] = $this->build; $csp['admin_property_count'] = 12; $csp['admin_property_display'] = 'extended'; $csp['admin_property_spacing'] = 3; update_option("clearskys_smallproperty_config",$csp); } elseif( $csp['build'] < $this->build) { // The build is updated so add any extra bits if(empty($csp['build'])) $csp['build'] = $this->build; if(empty($csp['admin_property_count'])) $csp['admin_property_count'] = 12; if(empty($csp['admin_property_display'])) $csp['admin_property_display'] = 'extended'; if(empty($csp['admin_property_spacing'])) $csp['admin_property_spacing'] = 3; update_option("clearskys_smallproperty_config",$csp); } return $csp; } function uninstall() { } function onpage($page) { $path = $_SERVER['REQUEST_URI']; if((stristr($path,$page."/") || stristr($path,$page."?")) && (stristr($path,get_option('upload_path')) === False)) { return True; } else { return False; } } function create_admin_header() { $site_uri = get_settings('siteurl'); $page = $this->property->xss_clean($_GET['page']); if($page == $this->mylocation && strpos($_SERVER["SCRIPT_FILENAME"],"edit.php")) { // Header details for REST API admin $action = $this->property->xss_clean($_REQUEST['action']); switch($action) { case "_manage": wp_enqueue_script('interface'); $this->interface->queueJs("propertymanage.js"); break; case "_edit": wp_enqueue_script('interface'); $this->interface->queueJs("propertyedit.js"); break; default: wp_enqueue_script('autocomplete', $this->interface->getJsBase() . 'library/jquery.autocomplete.js', array('jquery'), '0.1'); $this->interface->queueJs("property.js"); break; } $this->interface->queueCss("property.css"); //$this->interface->queueJs("library/jquery.js"); } if($page == $this->mylocation && strpos($_SERVER["SCRIPT_FILENAME"],"options-general.php")) { // Header details for the REST API options page } } function add_admin_header() { echo $this->interface->header(); } function add_admin_pages() { if (current_user_can('edit_published_posts') ) { add_management_page("Manage Properties", "Properties", 6, $this->mylocation, array(&$this,'handle_panels')); //if (current_user_can('manage_options') ) { //add_options_page(__('Property options'), __('Properties'), 8, $this->mylocation, array(&$this,'show_options_panel')); //} } } function ajax_nonce_pass($nonce, $action = -1) { $adminurl = strtolower(get_option('siteurl')).'/wp-admin'; $referer = strtolower(wp_get_referer()); if (!(-1 == $action && strpos($referer, $adminurl) !== false)) { return true; // The lines below are skipped for the moment as I need to work out // how to create a nonce in javascript. // So for the moment, only the refering page is checked. /* $user = wp_get_current_user(); $uid = (int) $user->id; $i = ceil(time() / 43200); //Allow for expanding range, but only do one check if we can if( substr(wp_hash($i . $action . $uid), -12, 10) == $nonce || substr(wp_hash(($i - 1) . $action . $uid), -12, 10) == $nonce ) return true; return false; */ } else { return false; } } /* * Handler functions * */ function handle_panels() { // This function handles which page is displayed in the manage tab // It is called AFTER the handle_ajax function so we can be sure that no ajax requests are here $action = $this->property->xss_clean($_REQUEST['action']); switch($action) { case "_manage": $pid = $this->property->xss_clean($_REQUEST['property']); if($pid != "") { $this->show_manage_property($pid); } else { $this->show_manage_propertylist_panel(); } break; case "_edit": $pid = $this->property->xss_clean($_REQUEST['property']); if($pid != "") { $this->show_edit_property($pid); } else { $this->show_manage_propertylist_panel(); } break; case "_delete": case "_add": default: $this->show_manage_propertylist_panel(); break; } } function handle_ajax() { /* * This function checks if the call is an ajax call or a standard web page call */ if($this->onpage('wp-admin/edit.php') && $this->property->xss_clean($_REQUEST['call']) == '_ajax' && function_exists('current_user_can') && current_user_can('edit_published_posts')) { if(function_exists('check_admin_referer') && !$this->ajax_nonce_pass('clearskys_smallproperty_ajax',$_REQUEST['_wpnonce'])) { exit(); } switch($this->property->xss_clean($_REQUEST['action'])) { case "_toolbarclick": $this->handle_toolbar_clicks($this->property->xss_clean($_GET['button'])); break; case "_imageupload": if($_POST['propertyid'] != "") { $this->upload_image($_POST['propertyid']); } break; case "_deleteimage": if($_GET['imageid'] != "") { $imageid = $this->property->xss_clean($_GET['imageid']); $propertyid = $this->property->getpropertyforimage($imageid); if($propertyid) { $propertyid = $propertyid[0]['property_id']; } $this->removeimagefile($imageid); // not interested really if this succeeded or not. $result = $this->property->deleteimage($imageid); if($result == "" || $result == "ok") { $result = $this->property_panel_images($propertyid); } echo $result;//$result; } break; case "_getproperty": $this->show_property_results(); break; case "_search": if($this->property->xss_clean($_GET['q']) != "") { $results = $this->property->getpropertylistforquicksearch($this->property->xss_clean($_GET['q'])); if(!empty($results)) { foreach($results as $result) { echo $result['id'] . "|"; echo $result['reference'] . "|"; echo wordwrap($result['title'],35) . "\n"; } } } break; case "_managepropertylink": if($this->property->xss_clean($_GET['picked']) != "") { $results = $this->property->getpropertyidforref($this->property->xss_clean($_GET['picked'])); if(!empty($results)) { echo rawurldecode($this->interface->link_security("?page=" . $this->mylocation . "&action=_manage&property=" . $results[0]['id'],"clearskys_property_manage")); } } echo ""; break; } exit(); } } function handle_toolbar_clicks($toolbarbutton) { switch($toolbarbutton) { case "toolbarextended": $csp = $this->getpluginoptions(); $csp['admin_property_display'] = "extended"; update_option("clearskys_smallproperty_config",$csp); $this->show_manage_propertylist_resultsdata($csp); break; case "toolbarsummary": $csp = $this->getpluginoptions(); $csp['admin_property_display'] = "summary"; update_option("clearskys_smallproperty_config",$csp); $this->show_manage_propertylist_resultsdata($csp); break; } } function show_manage_propertylist_panel() { // This function will handle the property list panel $csp = $this->getpluginoptions(); $count = $this->property->getpropertycount(); echo '