/**
  * Constructs the frontend config array
  * @return config array
  */
 function construct_config_array()
 {
     $current_url = HA_Common::get_current_url();
     $config_array = array('ajax_url' => admin_url('admin-ajax.php'), 'ajax_nonce' => wp_create_nonce(HA_Common::PLUGIN_ID . '-nonce'), 'ignore_ajax_actions' => $this->ignore_ajax_actions, 'plugin_version' => HA_Common::PLUGIN_VERSION);
     $ip_address = HA_Common::get_ip_address();
     $session_id = session_id();
     // get or create user details and user environment details
     $user_details = HA_Common::get_user_details($ip_address, $session_id, false, null);
     $user_environment_details = HA_Common::get_user_environment_details($user_details['user_id'], false, null);
     $config_array = array_merge($config_array, $user_environment_details);
     $config_array = array_merge($config_array, $user_details);
     $config_array = array_merge($config_array, $this->get_custom_events($current_url));
     $config_array = array_merge($config_array, $this->get_schedule_check());
     $config_array = array_merge($config_array, $this->get_url_excluded($current_url));
     $config_array = array_merge($config_array, $this->get_general_settings());
     $config_array = array_merge($config_array, $this->get_heat_map_settings());
     $config_array = array_merge($config_array, $this->get_url_db_limit_check($current_url));
     $config_array = array_merge($config_array, $this->get_url_filters_settings());
     return $config_array;
 }
Ejemplo n.º 2
0
 /**
  * Saves mouse click or touchscreen tap information database
  *
  * @since 2.0
  */
 public function save_user_event()
 {
     $ajaxNonce = $_POST['nonce'];
     $response = array();
     if (wp_verify_nonce($ajaxNonce, HA_Common::PLUGIN_ID . '-nonce')) {
         $response = array('status' => 'OK', 'message' => '');
         // POST parameters
         $x_coord = isset($_POST['xCoord']) && is_numeric($_POST['xCoord']) ? intval($_POST['xCoord']) : -1;
         $y_coord = isset($_POST['yCoord']) && is_numeric($_POST['yCoord']) ? intval($_POST['yCoord']) : -1;
         $url = isset($_POST['url']) ? HA_Common::normalize_url(urldecode($_POST['url'])) : null;
         $page_width = isset($_POST['pageWidth']) && is_numeric($_POST['pageWidth']) ? intval($_POST['pageWidth']) : null;
         $ip_address = isset($_POST['ipAddress']) ? $_POST['ipAddress'] : null;
         $user_id = isset($_POST['userId']) ? $_POST['userId'] : null;
         $user_environment_id = isset($_POST['userEnvironmentId']) ? $_POST['userEnvironmentId'] : null;
         $event_type = isset($_POST['eventType']) ? $_POST['eventType'] : null;
         $description = isset($_POST['description']) ? urldecode($_POST['description']) : '';
         $data = isset($_POST['data']) ? urldecode($_POST['data']) : '';
         // validate data
         if (!$url || !$page_width || !$ip_address || !$event_type) {
             $response['status'] = 'Error';
             $response['message'] = 'Required data missing from request';
             echo json_encode($response);
             return;
         }
         $ip_address = HA_Common::get_IP_address();
         // if user_id is null, create it
         if ($user_id == null) {
             $user_details = HA_Common::get_user_details(HA_Common::get_ip_address(), session_id(), true, $this->data_services);
             $user_id = $user_details['user_id'];
         }
         // if user_environment_id is null, create it
         if ($user_environment_id == null) {
             $user_environment_details = HA_Common::get_user_environment_details($user_id, true, $this->data_services);
             $user_environment_id = $user_environment_details['user_environment_id'];
         }
         // insert data into database
         $user_event_id = '';
         try {
             global $wpdb;
             $rowsAffected = $wpdb->insert($wpdb->prefix . HA_Common::USER_EVENT_TBL_NAME, array(HA_Common::USER_ID_COLUMN => $user_id, HA_Common::USER_ENV_ID_COLUMN => $user_environment_id, HA_Common::X_COORD_COLUMN => $x_coord, HA_Common::Y_COORD_COLUMN => $y_coord, HA_Common::URL_COLUMN => $url, HA_Common::PAGE_WIDTH_COLUMN => $page_width, HA_Common::LAST_UPDT_DATE_COLUMN => current_time('mysql'), HA_Common::RECORD_DATE_COLUMN => current_time('mysql'), HA_Common::DESCRIPTION_COLUMN => $description, HA_Common::DATA_COLUMN => $data, HA_Common::EVENT_TYPE_COLUMN => $event_type));
             $user_event_id = $wpdb->insert_id;
         } catch (Exception $e) {
             $response['status'] = 'Error';
             $response['message'] = 'An unexpected error occured';
             echo json_encode($response);
             return;
         }
         $debug = isset($_POST['debug']) && $_POST['debug'] == 'true' ? true : false;
         $draw_heat_map_enabled = isset($_POST['drawHeatMapEnabled']) && $_POST['drawHeatMapEnabled'] == 'true' ? true : false;
         $width_allowance = isset($_POST['widthAllowance']) && is_numeric($_POST['widthAllowance']) ? intval($_POST['widthAllowance']) : null;
         $spot_radius = isset($_POST['spotRadius']) && is_numeric($_POST['spotRadius']) ? intval($_POST['spotRadius']) : null;
         // debug
         if ($event_type !== null && ($event_type == HA_Common::MOUSE_CLICK_EVENT_TYPE || $event_type == HA_Common::TOUCHSCREEN_TAP_EVENT_TYPE) && $debug && $draw_heat_map_enabled && $width_allowance && $spot_radius) {
             // retrieve all clicks and taps and calculate heat value
             $query = 'SELECT ' . HA_Common::ID_COLUMN . ', ' . HA_Common::X_COORD_COLUMN . ', ' . HA_Common::Y_COORD_COLUMN . ', ' . HA_Common::URL_COLUMN . ', ' . HA_Common::PAGE_WIDTH_COLUMN . ' FROM ' . $wpdb->prefix . HA_Common::USER_EVENT_TBL_NAME . ' WHERE ' . HA_Common::URL_COLUMN . ' = "' . $url . '" AND (' . HA_Common::EVENT_TYPE_COLUMN . ' = "' . HA_Common::MOUSE_CLICK_EVENT_TYPE . '" OR ' . HA_Common::EVENT_TYPE_COLUMN . ' = "' . HA_Common::TOUCHSCREEN_TAP_EVENT_TYPE . '")';
             // allow a range either side to be the same
             $diff_left = $page_width - $width_allowance;
             $diff_right = $page_width + $width_allowance;
             $query .= ' AND ' . HA_Common::PAGE_WIDTH_COLUMN . ' >= ' . $diff_left . ' AND ' . HA_Common::PAGE_WIDTH_COLUMN . ' <= ' . $diff_right;
             $rows = $wpdb->get_results($query);
             $heat_value = HA_Common::calculate_heat_value($x_coord, $y_coord, $user_event_id, $rows, $spot_radius);
             $response = array_merge($response, array('user_event_id' => $user_event_id, 'heat_value' => $heat_value));
         } else {
             $response = array_merge($response, array('user_event_id' => $user_event_id));
         }
         echo json_encode($response);
     }
     die;
 }