Esempio n. 1
0
 /**
  * Gets the current URL
  *
  * @return current URL
  */
 public static function get_current_url()
 {
     $url = 'http';
     if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
         $url .= "s";
     }
     $url .= "://";
     if ($_SERVER["SERVER_PORT"] != "80") {
         $url .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
     } else {
         $url .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
     }
     return HA_Common::normalize_url($url);
 }
Esempio 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;
 }
 public static function sanitize_url_filters_settings($input)
 {
     // Apply URL filters option
     if (isset($input[HA_Common::APPLY_URL_FILTERS_OPTION]) && $input[HA_Common::APPLY_URL_FILTERS_OPTION] == "true") {
         $input[HA_Common::APPLY_URL_FILTERS_OPTION] = true;
     } else {
         $input[HA_Common::APPLY_URL_FILTERS_OPTION] = false;
     }
     $url_filters_list = preg_split("/[\r\n,]+/", $input[HA_Common::URL_FILTERS_LIST_OPTION], -1, PREG_SPLIT_NO_EMPTY);
     $new_url_filters_list = '';
     foreach ($url_filters_list as $url) {
         $url = HA_Common::normalize_url($url);
         $new_url_filters_list .= $url . '&#13;&#10;';
     }
     $input[HA_Common::URL_FILTERS_LIST_OPTION] = $new_url_filters_list;
     return $input;
 }
    public static function settings_page($tabs)
    {
        $current_tab = isset($_GET['tab']) ? $_GET['tab'] : HA_Common::GENERAL_SETTINGS_TAB;
        ?>
		<div class="wrap">
			<?php 
        HA_Admin_Page_View::page_header('Settings');
        HA_Admin_Page_View::show_page_tabs(HA_Common::SETTINGS_PAGE_SLUG, $tabs, $current_tab);
        if (isset($_GET['updated']) && isset($_GET['page'])) {
            add_settings_error('general', 'settings_updated', __('Settings saved.'), 'updated');
        }
        settings_errors();
        if ($current_tab == HA_Common::GENERAL_SETTINGS_TAB) {
            HA_Admin_Page_View::show_settings_form(HA_Common::GENERAL_SETTINGS_KEY);
        } else {
            if ($current_tab == HA_Common::SCHEDULE_SETTINGS_TAB) {
                HA_Admin_Page_View::show_settings_form(HA_Common::SCHEDULE_SETTINGS_KEY);
            } else {
                if ($current_tab == HA_Common::HEAT_MAP_SETTINGS_TAB) {
                    HA_Admin_Page_View::show_settings_form(HA_Common::HEAT_MAP_SETTINGS_KEY);
                } else {
                    if ($current_tab == HA_Common::URL_FILTERS_SETTINGS_TAB) {
                        HA_Admin_Page_View::show_settings_form(HA_Common::URL_FILTERS_SETTINGS_KEY);
                    } else {
                        if ($current_tab == HA_Common::DATABASE_SETTINGS_TAB) {
                            ?>
				<form method="post" name="<?php 
                            echo HA_Common::DATABASE_SETTINGS_KEY;
                            ?>
" action="options.php" class="hut-settings-form">
					<?php 
                            wp_nonce_field('update-options');
                            settings_fields(HA_Common::DATABASE_SETTINGS_KEY);
                            do_settings_sections(HA_Common::DATABASE_SETTINGS_KEY);
                            ?>
					<p class="submit">
						<?php 
                            submit_button(null, 'primary', 'submit', false, null);
                            submit_button('Clear Database', 'delete', 'clear-database', false, null);
                            ?>
					</p>
					<input type="hidden" name="clear-database-flag" id="clear-database-flag" value="false" />
				</form>
				<?php 
                        } else {
                            if ($current_tab == HA_Common::CUSTOM_EVENTS_SETTINGS_TAB) {
                                echo '<h3>Custom Events</h3>';
                                if (isset($_POST['eventType']) && isset($_POST['customEvent'])) {
                                    $event_type = isset($_POST['eventType']) ? $_POST['eventType'] : '';
                                    $custom_event = isset($_POST['customEvent']) ? $_POST['customEvent'] : '';
                                    $description = isset($_POST['description']) ? $_POST['description'] : '';
                                    $url = isset($_POST['url']) ? trim($_POST['url']) : '';
                                    $url = HA_Common::normalize_url($url);
                                    $url = addslashes($url);
                                    $is_form_submit = isset($_POST['isFormSubmit']) ? true : false;
                                    $is_mouse_click = isset($_POST['isMouseClick']) ? true : false;
                                    $is_touchscreen_tap = isset($_POST['isTouchscreenTap']) ? true : false;
                                    $valid_input = true;
                                    if (strlen(trim($custom_event)) == 0) {
                                        echo '<div class="error"><p>An event type is required.</p></div>';
                                        $valid_input = false;
                                    }
                                    if (strlen(trim($custom_event)) == 0) {
                                        echo '<div class="error"><p>A custom event jQuery selector is required.</p></div>';
                                        $valid_input = false;
                                    }
                                    if ($valid_input == true) {
                                        global $wpdb;
                                        try {
                                            $results = $wpdb->insert($wpdb->prefix . HA_Common::CUSTOM_EVENT_TBL_NAME, array(HA_Common::DESCRIPTION_COLUMN => $description, HA_Common::CUSTOM_EVENT_COLUMN => $custom_event, HA_Common::EVENT_TYPE_COLUMN => $event_type, HA_Common::URL_COLUMN => $url, HA_Common::IS_FORM_SUBMIT_COLUMN => $is_form_submit, HA_Common::IS_MOUSE_CLICK_COLUMN => $is_mouse_click, HA_Common::IS_TOUCHSCREEN_TAP_COLUMN => $is_touchscreen_tap));
                                            echo '<div class="success"><p>Custom event added successfully.</p></div>';
                                        } catch (Exception $e) {
                                            echo '<div class="error"><p>An error occurred. ' . $e->getMessage() . '</p></div>';
                                        }
                                    }
                                }
                                ?>
				<form method="post">
					<table class="form-table">
						<tbody>
							<tr valign="top">
								<th scope="row">Custom Event</th>
								<td>
									<input type="text" name="customEvent" id="customEvent" value="" />
									<p class="description">Enter a jQuery element selector.</p>
								</td>
							</tr>
							<tr valign="top">
								<th scope="row">Event Type</th>
								<td>
									<input type="text" name="eventType" id="eventType" value="" />
									<p class="description">Categorise the event with a named type.</p>
								</td>
							</tr>
							<tr valign="top">
								<th scope="row">Trigger events</th>
								<td>
									<input type="checkbox" name="isMouseClick" id="isMouseClick" value="" checked="checked"/>
									<label for="isMouseClick">Mouse click?</label><br />
									<input type="checkbox" name="isToushcreenTap" id="isToushcreenTap" value="" />
									<label for="isTouchscreenTap">Touchscreen tap?</label><br />
									<input type="checkbox" name="isFormSubmit" id="isFormSubmit" value="" />
									<label for="isTouchscreenTap">Form submit?</label>
									<p class="description">Is the custom event associated with a form submit JavaScript event? If none are checked, mouse click is defaulted.</p>
								</td>
							</tr>
							<tr valign="top">
								<th scope="row">Description</th>
								<td>
									<input type="text" name="description" id="description" value="" />
									<p class="description">Add a description of the event.</p>
								</td>
							</tr>
							
							<tr valign="top">
								<th scope="row">URL</th>
								<td>
									<input class="regular-text" type="text" name="url" id="url" value="" />&nbsp(Optional, leave empty to target all URLs)
									<p class="description">You can enter a URL to target a specific page.</p>
								</td>
							</tr>
						</tbody>
					</table>
					
					<input type="submit" class="button button-secondary" value="Add Custom Event" />
				</form>
		
				<br />
							
				<form method="post">
					<?php 
                                $custom_event_table = new HA_Custom_Event_Table();
                                $custom_event_table->prepare_items();
                                $custom_event_table->display();
                                ?>
				</form>
				<?php 
                            }
                        }
                    }
                }
            }
        }
        ?>
			
		</div>
		<div class="clear" />
		<?php 
    }