Commit b243c5f9 by Muhammad Usman

all app dynamic except page links

parent 7198f028
......@@ -52,6 +52,16 @@ function vq_set_default_data()
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
$table_name = $wpdb->prefix . "review_subscribers";
$sql = "CREATE TABLE $table_name (";
$sql .= "id int(10) unsigned NOT NULL AUTO_INCREMENT,";
$sql .= "name varchar(255) DEFAULT NULL,";
$sql .= "email varchar(255) DEFAULT NULL,";
$sql .= "PRIMARY KEY (id)";
$sql .= ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
dbDelta( $sql );
}
add_action("after_switch_theme", "vq_set_default_data");
......@@ -10,9 +10,6 @@ function vq_theme_settings_page()
settings_fields("section");
do_settings_sections("hosting-review-theme-options");
settings_fields("server-locations-section");
do_settings_sections("hosting-server-locations");
submit_button();
......@@ -33,7 +30,7 @@ function display_hosting_companies_table()
<thead>
<tr>
<th>Title</th>
<th>Slug</th>
<th>Organization</th>
<th>Hosting</th>
<th>Locations</th>
<th></th>
......@@ -132,14 +129,14 @@ function display_server_locations()
function vq_display_theme_panel_fields()
{
add_settings_section("section", "Hosting Companies", null, "hosting-review-theme-options");
add_settings_field("vq_hosting_companies", "", "display_hosting_companies_table", "hosting-review-theme-options", "section");
add_settings_section("section", "Configuration Details", null, "hosting-review-theme-options");
add_settings_field("vq_hosting_companies", "Hosting Companies", "display_hosting_companies_table", "hosting-review-theme-options", "section");
register_setting("section", "vq_hosting_companies_details");
add_settings_field("vq_hosting_locations", "Server Locations", "display_server_locations", "hosting-review-theme-options", "section");
register_setting("section", "vq_hosting_server_locations");
add_settings_section("server-locations-section", "Server Locations", null, "hosting-server-locations");
add_settings_field("vq_hosting_locations", "", "display_server_locations", "hosting-server-locations", "server-locations-section");
register_setting("server-locations-section", "vq_hosting_server_locations");
}
......
......@@ -21,7 +21,7 @@ Template Name: Blog Page
<div class="row">
<?php
$loop = new WP_Query( array( 'post_type' => 'hosting_reviews', 'paged' => true, 'posts_per_page' => 5 ) );
$loop = new WP_Query( array( 'post_type' => 'hosting_reviews', 'paged' => true, 'posts_per_page' => 2 ) );
if ( $loop->have_posts() ) :
while ( $loop->have_posts() ) : $loop->the_post(); ?>
......@@ -59,6 +59,13 @@ Template Name: Blog Page
</div>
<div class="ppage">
<?php
global $wp_query;
paginate_links();
?>
</div>
<div class="d-flex j-content-center">
<nav aria-label="Page navigation example">
<ul class="pagination">
......
......@@ -1775,6 +1775,7 @@ h5
background-color: transparent;
padding: 15px 0 10px 0;
margin: 15px 0 7px 0;
position: relative;
}
.offerHeading
......
......@@ -7,20 +7,56 @@
<h2>Stay up to date with my blogging news</h2>
</div>
</div>
<div class="col-sm-4">
<input type="name" class="form-control SubscribeInput" id="exampleInputName" aria-describedby="emailHelp" placeholder="Name">
</div>
<div class="col-sm-4">
<input type="email" class="form-control SubscribeInput" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Email">
</div>
<div class="col-sm-4">
<button class="btn orange updateButton" type="submit">Stay Update!</button>
<div class="col-md-12" id="footerFormContainer">
<div class="row">
<div class="col-sm-4">
<input type="name" class="form-control SubscribeInput" id="subscriberName" placeholder="Name">
</div>
<div class="col-sm-4">
<input type="email" class="form-control SubscribeInput" id="subscriberEmail" placeholder="Email">
</div>
<div class="col-sm-4">
<button class="btn orange updateButton" type="submit" onclick="subscribeUser()">Stay Update!</button>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
jQuery(document).ready(function ($) {
var subscriberNameEl = document.getElementById('subscriberName');
var subscriberEmailEl = document.getElementById('subscriberEmail');
subscribeUser = function(){
if (subscriberNameEl.value.trim() && validateEmail(subscriberEmailEl.value)) {
var actData = {
'action': 'add_review_subscribers',
'email': subscriberNameEl.value,
'name': subscriberEmailEl.value
};
$.post(ajax_url, actData, function(response) {
if (response === 0) {
return alert('Could not subscribe');
}
document.getElementById('footerFormContainer').innerHTML = '<h4>You have successfully subscribed. We will get in touch.</h4>';
});
} else {
alert('Please enter a valid name & email.');
}
};
validateEmail = function(mail) {
return /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail)
};
});
</script>
<!-- Footer Section Code Start-->
<!-------------------->
<div class="footer light">
......
......@@ -22,8 +22,8 @@ echo $page->post_content;
<!-- Top Recent Reviews -->
<?php
//$page = get_page_by_title( RECENT_REVIEWS_PAGE);
//echo do_shortcode($page->post_content);
$page = get_page_by_title( RECENT_REVIEWS_PAGE);
echo do_shortcode($page->post_content);
?>
<div class="container">
<div class="hrBorder"></div>
......@@ -31,8 +31,8 @@ echo $page->post_content;
<!-- Top Blogs Content -->
<?php
//$page = get_page_by_title( TOP_BLOG_PAGE);
//echo do_shortcode($page->post_content);
$page = get_page_by_title( TOP_BLOG_PAGE);
echo do_shortcode($page->post_content);
?>
<?php
......
......@@ -179,6 +179,8 @@ function vq_get_hosting_speed() {
$requestBatch = generateRandomString(10);
$allResults = [];
global $wpdb;
$speed_table_name = $wpdb->prefix . "speed_results";
for($i = 0; $i < count($servers); $i++) {
$domain = $_POST['domain'];
$curl = curl_init();
......@@ -220,9 +222,6 @@ function vq_get_hosting_speed() {
];
$newData['domain_ip'] = gethostbyname($domain);
global $wpdb;
$speed_table_name = $wpdb->prefix . "speed_results";
$wpdb->insert($speed_table_name, $newData);
// $cmd = "whois {$newData['ip']}";
......@@ -239,7 +238,10 @@ function vq_get_hosting_speed() {
}
}
echo json_encode($allResults);
$oldResutls = $wpdb->get_results("SELECT server_response_time, page_load_time FROM $speed_table_name");
echo json_encode(['oldData' => $oldResutls, 'newData' => $allResults]);
exit;
} catch(Exception $exception) {
print_r(['error' => 'Something went wrong in the server']);
......@@ -247,6 +249,22 @@ function vq_get_hosting_speed() {
}
function vq_add_review_subscribers() {
global $wpdb;
$newSubscripber = [
'name' => $_POST['name'],
'email' => $_POST['email']
];
$subscriber_table = $wpdb->prefix . "review_subscribers";
$wpdb->insert($subscriber_table, $newSubscripber);
print_r($wpdb->insert_id);
exit;
}
// Actions
add_action( 'customize_register', 'vq_theme_customize_register' );
......@@ -255,4 +273,9 @@ add_action( 'init', 'vq_register_theme_supports' );
add_action( 'init', 'vq_add_theme_default_pages' );
add_action( 'wp_ajax_nopriv_get_speed_results', 'vq_get_hosting_speed' );
add_action( 'wp_ajax_get_speed_results', 'vq_get_hosting_speed' );
add_action( 'wp_ajax_nopriv_add_review_subscribers', 'vq_add_review_subscribers' );
add_action( 'wp_ajax_add_review_subscribers', 'vq_add_review_subscribers' );
add_action( 'admin_enqueue_scripts', 'vq_enqueue_custom_admin_style' );
<?php
$path = $_SERVER['DOCUMENT_ROOT'];
include_once $path . '/wp-config.php';
include_once $path . '/wp-load.php';
include_once $path . '/wp-includes/wp-db.php';
include_once $path . '/wp-includes/pluggable.php';
add_action('wp_loaded', 'my_custom_redirect');
if (isset($_POST['submit'])) {
global $wpdb;
$table_name = $wpdb->prefix . 'locations';
$all = $wpdb->get_results('SELECT * FROM ' . $table_name);
if ($all) {
$ART = 0;
$APLT = 0;
$url_tc = parse_url($_POST['url'], PHP_URL_HOST);
$ip = gethostbyname($url_tc);
$HC = '';
$another_table_name = $wpdb->prefix . 'user_requests';
foreach ($all as $record) {
$url = $record->url;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, "url=" . $_POST['url']);
$response = json_decode(curl_exec($curl));
$create_table_name = $wpdb->prefix . 'request_details';
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE $create_table_name (
id int(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
userReqId text,
locationId text NOT NULL,
loadTime text NOT NULL,
resTime text NOT NULL) $charset_collate";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
$reqID = 0;
if ($wpdb->get_results('SELECT * FROM ' . $another_table_name)) {
$reqID = sizeof($wpdb->get_results('SELECT * FROM ' . $another_table_name)) + 1;
} else {
$reqID += 1;
}
if ($response->status == 'success') {
$success = $wpdb->insert($create_table_name, array(
"userReqId" => $reqID,
"loadTime" => $response->pageLoadTime,
"resTime" => $response->reqTime,
"locationId" => $record->id
));
}
$ART += $response->reqTime;
$APLT += $response->pageLoadTime;
$HC = $response->oName;
curl_close($curl);
$hc_table_name = $wpdb->prefix . 'hosting_company_details';
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE $hc_table_name (
id int(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
HCId text,
HCname text,
locationId text NOT NULL,
APLT text NOT NULL,
ART text NOT NULL) $charset_collate";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
$hcd = $wpdb->get_results('SELECT * FROM ' . $hc_table_name . ' WHERE HCname = "' . $response->oName . '" AND locationId = "'.$record->id.'"')[0];
if($hcd) {
$hcd->APLT = ($response->pageLoadTime+$hcd->APLT)/2;
$hcd->ART = ($response->reqTime+$hcd->ART)/2;
$new_hc = array(
'id' => $hcd->id,
'HCId' => $hcd->id,
'HCname' => $hcd->name,
'locationId' => $hcd->locationId,
'APLT' => $hcd->APLT,
'ART' => $hcd->ART
);
$success = $wpdb->update($hc_table_name, $new_hc, array('id' => $new_hc['id']));
}
else{
$hosting_table = $wpdb->prefix . 'hosting_companies';
$hc = $wpdb->get_results('SELECT * FROM ' . $hosting_table . ' WHERE legal_name = "' . $response->oName . '"')[0];
$success = $wpdb->insert($hc_table_name, array(
'HCId' => $hc->id,
'HCname' => $hc->legal_name,
'locationId' => $record->id,
'APLT' => $response->pageLoadTime,
'ART' => $response->reqTime
));
}
}
$ART = $ART / sizeof($all);
$APLT = $APLT / sizeof($all);
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE $another_table_name (
id int(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
userIp text NOT NULL,
URL text NOT NULL,
ART text NOT NULL,
APLT text NOT NULL,
SSC text ,
CLC text ,
HC text ) $charset_collate";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
$success = $wpdb->insert($another_table_name, array(
"userIp" => $ip,
"URL" => $_POST['url'],
"ART" => $ART,
"APLT" => $APLT,
"SSC" => null,
"CLC" => null,
"HC" => $HC
));
$hosting_table = $wpdb->prefix . 'hosting_companies';
$hc = $wpdb->get_results('SELECT * FROM ' . $hosting_table . ' WHERE legal_name = "' . $response->oName . '"')[0];
if($hc){
$hc->APLT = ($hc->APLT+$APLT)/2;
$hc->ART = ($hc->ART+$ART)/2;
$new_hc = array(
'id' => $hc->id,
'name'=> $hc->name,
'legal_name'=> $hc->legal_name,
'APLT' => $hc->APLT,
'ART' => $hc->ART
);
$success = $wpdb->update($hosting_table, $new_hc, array('id' => $new_hc['id']));
}
}
$location = $_SERVER['HTTP_REFERER'];
wp_redirect($location);
exit;
}
<?php
/*
==============================
ADMIN PAGE
==============================
*/
function speedtest_add_admin_page()
{
add_menu_page('Speed Test Theme Options', 'Speed Test', 'manage_options', 'speedtest_options', 'speedtest_theme_create_page', '', 110);
}
add_action('admin_menu', 'speedtest_add_admin_page');
function speedtest_theme_create_page()
{
require_once get_template_directory() . '/inc/admin-page.php';
locations_table_creator();
hosting_table_creator();
}
function locations_table_creator()
{
global $wpdb;
$table_name = $wpdb->prefix . 'locations';
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE $table_name (
id int(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
loc text NOT NULL,
url text NOT NULL) $charset_collate";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
$got = $wpdb->get_results("SELECT * FROM $table_name");
?>
<h2>Locations</h2>
<form method="post" action="<?php echo get_template_directory_uri(); ?>/inc/save-locations.php">
<table id="tab">
<thead>
<tr>
<th></th>
<th>Location</th>
<th>IP Address/URL</th>
<th>Delete</th>
</tr>
</thead>
<script>
var result = <?php echo json_encode($got); ?>;
var index = result?result.length:0;
var tab = document.getElementById('tab');
var deletedArray = [];
var tab = document.getElementById('tab');
for (let i = 0; i < result.length; i++) {
let z = document.createElement('tr');
z.id = result[i].id;
z.innerHTML = '<td><input type="hidden" name="result[' + i + '][id]" value="' + result[i].id + '"></td>\n' +
' <td><input type="text" name="result[' + i + '][loc]" value="' + result[i].loc + '"></td>\n' +
' <td><input type="text" name="result[' + i + '][url]" value="' + result[i].url + '"></td>\n' +
' <td><input type="button" onclick="deleteRow(' + result[i].id + ')" value="Delete"></td>';
tab.appendChild(z);
}
function addNew() {
let thisId = parseInt(result[index - 1]?result[index - 1].id: 0) + 1;
result.push({id: thisId, loc: '', url: ''});
let x = document.createElement('tr');
x.id = thisId;
x.innerHTML = '<td><input type="hidden" name="result[' + index + '][id]" value="' + result[index].id + '"></td>\n' +
' <td><input type="text" name="result[' + index + '][loc]" value="' + result[index].loc + '"></td>\n' +
' <td><input type="text" name="result[' + index + '][url]" value="' + result[index].url + '"></td>\n' +
' <td><input type="button" onclick="deleteRow(' + result[index].id + ')" value="Delete"></td>';
tab.appendChild(x);
index++;
}
function deleteRow(id) {
let deleted = document.getElementById(id);
tab.removeChild(deleted);
result.splice(id, 1);
let newid = parseInt(id);
deletedArray.push(newid);
let del = document.createElement('input');
del.type = 'hidden';
del.name = 'deleted[' + deletedArray.length + ']';
del.value = deletedArray[deletedArray.length - 1];
tab.appendChild(del);
index--;
}
</script>
</table>
<input type='button' value='Add New' onclick="addNew()">
<input name="submit" type="submit" value="Save Changes">
</form>
<?php
}
function hosting_table_creator()
{
global $wpdb;
$table_name = $wpdb->prefix . 'hosting_companies';
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE $table_name (
id int(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
name text NOT NULL,
legal_name text NOT NULL,
APLT text,
ART text) $charset_collate";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
$got = $wpdb->get_results("SELECT * FROM $table_name");
?>
<br>
<h2>Hosting Comapnies</h2>
<form method="post" action="<?php echo get_template_directory_uri(); ?>/inc/save-hosting.php">
<table id="tab-2">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Legal Name</th>
<th>Delete</th>
</tr>
</thead>
<script>
var results_HC = <?php echo json_encode($got); ?>;
var deletedArray_HC = [];
let tab_HC = document.getElementById('tab-2');
for (let i = 0; i < results_HC.length; i++) {
let z = document.createElement('tr');
z.id = 'HC-'+results_HC[i].id;
z.innerHTML = '<td><input type="hidden" name="results_HC[' + i + '][id]" value="' + results_HC[i].id + '"></td>\n' +
' <td><input type="text" name="results_HC[' + i + '][name]" value="' + results_HC[i].name + '"></td>\n' +
' <td><input type="text" name="results_HC[' + i + '][legal_name]" value="' + results_HC[i].legal_name + '"></td>\n' +
' <td><input type="button" onclick="deleteRow2(' + results_HC[i].id + ')" value="Delete"></td>';
tab_HC.appendChild(z);
}
var index2 = results_HC.length;
function addNew2() {
let thisId = parseInt(results_HC[index2 - 1]?results_HC[index2 - 1].id: -1) + 1;
results_HC.push({id: thisId, name: '', legal_name: ''});
let x = document.createElement('tr');
x.id = 'HC-'+thisId;
x.innerHTML = '<td><input type="hidden" name="results_HC[' + index2 + '][id]" value="' + results_HC[index2].id + '"></td>\n' +
' <td><input type="text" name="results_HC[' + index2 + '][name]" value="' + results_HC[index2].name + '"></td>\n' +
' <td><input type="text" name="results_HC[' + index2 + '][legal_name]" value="' + results_HC[index2].legal_name + '"></td>\n' +
' <td><input type="button" onclick="deleteRow2(' + results_HC[index2].id + ')" value="Delete"></td>';
tab_HC.appendChild(x);
index2++;
}
function deleteRow2(id) {
let deleted = document.getElementById('HC-'+ id);
tab_HC.removeChild(deleted);
results_HC.splice(id, 1);
let newid = parseInt(id);
deletedArray_HC.push(newid);
let del = document.createElement('input');
del.type = 'hidden';
del.name = 'deleted_HC[' + deletedArray_HC.length + ']';
del.value = deletedArray_HC[deletedArray_HC.length - 1];
tab_HC.appendChild(del);
index2--;
}
</script>
</table>
<input disabled type="text" name="" id="" value="Other" style="margin-left: 7px;"><br><br>
<input type='button' value='Add New' onclick="addNew2()">
<input name="submit" type="submit" value="Save Changes">
</form>
<?php
}
<?php
$path = $_SERVER['DOCUMENT_ROOT'];
include_once $path . '/wp-config.php';
include_once $path . '/wp-load.php';
include_once $path . '/wp-includes/wp-db.php';
include_once $path . '/wp-includes/pluggable.php';
if (isset($_POST['submit'])) {
global $wpdb;
$table_name = $wpdb->prefix . 'hosting_companies';
$res = $_POST['results_HC'];
$del = $_POST['deleted_HC'];
$ind = 0;
if ($del) {
foreach ($del as $delt) {
if ($wpdb->get_var('SELECT id FROM ' . $table_name . ' WHERE id = ' . $delt)) {
$wpdb->delete($table_name, array('id' => $delt));
}
}
}
if($res){
foreach ($res as $resu) {
$id = $resu['id'];
$item = $wpdb->get_var('SELECT id FROM ' . $table_name . ' WHERE id = ' . $id);
if ($item) {
$success = $wpdb->update($table_name, $resu, array('id' => $resu['id']));
} else {
$success = $wpdb->insert($table_name, array(
"id" => $resu['id'],
"name" => $resu['name'],
"legal_name" => $resu['legal_name'],
"APLT" => 0,
"ART" => 0
));
}
}
}
$location = $_SERVER['HTTP_REFERER'];
wp_safe_redirect($location);
}
<?php
$path = $_SERVER['DOCUMENT_ROOT'];
include_once $path . '/wp-config.php';
include_once $path . '/wp-load.php';
include_once $path . '/wp-includes/wp-db.php';
include_once $path . '/wp-includes/pluggable.php';
if (isset($_POST['submit'])) {
global $wpdb;
$table_name = $wpdb->prefix . 'locations';
$res = $_POST['result'];
$del = $_POST['deleted'];
$ind = 0;
if($del){
foreach ($del as $delt){
if($wpdb->get_var('SELECT id FROM '.$table_name.' WHERE id = '.$delt)){
$wpdb->delete($table_name, array('id' => $delt));
}
}
}
if($res){
foreach ($res as $resu) {
$id = $resu['id'];
$item = $wpdb->get_var('SELECT id FROM '.$table_name.' WHERE id = '.$id);
if ($item) {
$success = $wpdb->update($table_name, $resu, array('id' => $resu['id']));
} else {
$success = $wpdb->insert($table_name, array(
"id" => $resu['id'],
"loc" => $resu['loc'],
"url" => $resu['url'],
));
}
}
}
$location = $_SERVER['HTTP_REFERER'];
wp_safe_redirect($location);
}
......@@ -5,8 +5,8 @@
<h2><?php echo get_theme_mod( "vq-speed-test-heading") ?></h2>
</div>
<div class="col-sm-12">
<form class="form-inline">
<input class="form-control sidebarInput" type="search" placeholder="Enter URL" aria-label="Search">
<form class="form-inline" method="GET" action="/results">
<input class="form-control sidebarInput" type="search" placeholder="Enter URL" name="domain">
<button class="btn btn-outline-success testButton dark" type="submit">Test</button>
</form>
</div>
......@@ -81,69 +81,51 @@
<?php } ?>
</div>
<div class="sideBarBox pb-0">
<div class="recentTitleBox">
<div class="d-flex spaceBetween">
<h4><?php echo get_theme_mod( "vq-top-hosting-heading") ?></h4>
<img src="<?php echo get_template_directory_uri(); ?>/assets/images/hosting-icon.png">
</div>
</div>
<div class="d-flex j-content-center">
<img src="<?php echo get_template_directory_uri(); ?>/assets/images/bottom-style.png">
</div>
<div class="col-sm-12">
<div class="d-flex spaceBetween">
<img class="hostingLogo" src="<?php echo get_template_directory_uri(); ?>/assets/images/hosting-logo.png">
<button class="btn btn-outline-success reviewButton" type="submit"><i class="fas fa-eye"></i> Review</button>
</div>
</div>
<div class="borderBottom"></div>
<div class="col-sm-12">
<div class="d-flex spaceBetween">
<img class="hostingLogo" src="images/hosting-logo.png">
<button class="btn btn-outline-success reviewButton" type="submit"><i class="fas fa-eye"></i> Review</button>
</div>
</div>
<div class="borderBottom"></div>
<div class="col-sm-12">
<div class="d-flex spaceBetween">
<img class="hostingLogo" src="images/hosting-logo.png">
<button class="btn btn-outline-success reviewButton" type="submit"><i class="fas fa-eye"></i> Review</button>
</div>
</div>
<div class="borderBottom"></div>
<div class="col-sm-12">
<div class="d-flex spaceBetween">
<img class="hostingLogo" src="images/hosting-logo.png">
<button class="btn btn-outline-success reviewButton" type="submit"><i class="fas fa-eye"></i> Review</button>
</div>
</div>
<div class="borderBottom"></div>
<div class="col-sm-12">
<div class="d-flex spaceBetween">
<img class="hostingLogo" src="images/hosting-logo.png">
<button class="btn btn-outline-success reviewButton" type="submit"><i class="fas fa-eye"></i> Review</button>
</div>
</div>
<div class="borderBottom"></div>
<div class="col-sm-12">
<div class="d-flex spaceBetween">
<img class="hostingLogo" src="images/hosting-logo.png">
<button class="btn btn-outline-success reviewButton" type="submit"><i class="fas fa-eye"></i> Review</button>
</div>
</div>
</div>
<div class="sideBarBox">
<div class="sideBar newsletterPadding">
<img src="<?php echo get_template_directory_uri(); ?>/assets/images/newsletter-icon.png">
<h2><?php echo get_theme_mod( "vq-newsletter-heading") ?></h2>
</div>
<div class="col-sm-12">
<form class="form-inline">
<input class="form-control sidebarInput w65" type="search" placeholder="Newsletter" aria-label="Search">
<button class="btn btn-outline-success testButton orange " type="submit">Submit</button>
<div class="col-sm-12" id="formContainer">
<form class="form-inline" id="newsLetterForm">
<input class="form-control sidebarInput w65" type="email" placeholder="Newsletter" id="newsLetterEmail">
<button class="btn btn-outline-success testButton orange " type="button" onclick="subscribeUser()">Submit</button>
</form>
</div>
</div>
<script>
jQuery(document).ready(function ($) {
var newsLetterEl = document.getElementById('newsLetterEmail');
subscribeUser = function(){
if (validateEmail(newsLetterEl.value)) {
var actData = {
'action': 'add_review_subscribers',
'email': newsLetterEl.value,
'name': '-'
};
$.post(ajax_url, actData, function(response) {
if (response === 0) {
return alert('Could not subscribe');
}
});
document.getElementById('newsLetterForm').style.display = 'none';
document.getElementById('formContainer').innerHTML = '<h3>You have successfully subscribed. <br>We will get in touch.</h3>';
} else {
alert('Please enter a valid email address');
}
};
validateEmail = function(mail) {
return /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail)
};
});
</script>
</div>
......@@ -120,7 +120,7 @@ if ( isset( $_GET['domain'] ) ) {
</table>
<div class="row m-0">
<div class="col-sm-3 pl-0 summaryPadding">
<img class="boxTopLeftOther top-20 top-7 left-0 "
<img class="boxTopLeftOther top-20 top-7 left-0 " style="left: 5px !important;"
src="<?php echo get_template_directory_uri(); ?>/assets/images/box-top-left.png" alt="">
<div class="summaryAfterBox">
<div class="responseHeading">
......@@ -169,7 +169,7 @@ if ( isset( $_GET['domain'] ) ) {
<h4><strong id="reviewPerformance"></strong> <span>%</span></h4>
</div>
<img class="boxTopRight right-0"
<img class="boxTopRight right-0" style="right: 5px !important;"
src="<?php echo get_template_directory_uri(); ?>/assets/images/box-top-right.png"
alt="">
</div>
......@@ -191,7 +191,7 @@ if ( isset( $_GET['domain'] ) ) {
</div>
</div>
<div class="col-sm-4">
<button type="button" class="hostsButton dark btn btn-primary">Recommended Web Hosts</button>
<a href="#top-hostings" class="hostsButton dark btn btn-primary">Recommended Web Hosts</a>
</div>
<div class="col-sm-8">
<div class="detectedHeading">
......@@ -200,7 +200,7 @@ if ( isset( $_GET['domain'] ) ) {
</div>
</div>
<div class="col-sm-4">
<button type="button" class="hostsButton dark btn btn-primary">Recommended Cache Plugins</button>
<a href="#top-cache-plugins" class="hostsButton dark btn btn-primary">Recommended Cache Plugins</a>
</div>
</div>
</div>
......@@ -305,11 +305,12 @@ if ( isset( $_GET['domain'] ) ) {
reviewTableDetailsBody.innerHTML = '';
reviewData.style.display = 'flex';
resultLoader.style.display = 'none';
const results = JSON.parse(response);
let newResults = JSON.parse(response).newData;
let oldData = JSON.parse(response).oldData;
var respTime = 0;
var loadTime = 0;
results.forEach(res => {
newResults.forEach(res => {
var reviewRowTemplate = `<tr>
<td class="summaryTD">${res.server_location}</td>
<td class="summaryTD">${res.server_response_time} ms</td>
......@@ -320,21 +321,60 @@ if ( isset( $_GET['domain'] ) ) {
loadTime += +res.page_load_time;
});
domainNameEl.innerText = results[0].domain_addr;
domainIPEl.innerText = results[0].domain_ip;
hostingNameEl.innerText = results[0].hosting_name;
domainNameEl.innerText = newResults[0].domain_addr;
domainIPEl.innerText = newResults[0].domain_ip;
hostingNameEl.innerText = newResults[0].hosting_name;
hostingNameEl.innerText = '-';
reviewGradeEl.innerText = 'A';
reviewPerformanceEl.innerText = 'X';
avgResTimeEl.innerText = Math.floor(respTime / results.length).toString();
avgPageLoadTimeEl.innerText = Math.floor(loadTime / results.length).toString();
screenshotImgEl.src = results[0].imgPath;
loadVideoEl.src = results[0].videoPath;
avgResTimeEl.innerText = Math.floor(respTime / newResults.length).toString();
avgPageLoadTimeEl.innerText = Math.floor(loadTime / newResults.length).toString();
screenshotImgEl.src = newResults[0].imgPath;
loadVideoEl.src = newResults[0].videoPath;
var serverResTimes = oldData.map(o => +o.server_response_time + +o.page_load_time).sort((o1, o2) => o1 - o2);
var grade = 'F';
var rank = (100 - (percentRank(serverResTimes, (respTime + loadTime) / newResults.length) * 100));
if (rank > 95) {
grade = 'A'
} else if (rank > 85) {
grade = 'B'
} else if (rank > 75) {
grade = 'C'
} else if (rank > 65) {
grade = 'D'
} else {
grade = 'E'
}
if (grade !== 'A') {
hasProblems.style.display = 'block';
topHostings.style.display = 'block';
topCachePlugins.style.display = 'block';
}
reviewGradeEl.innerText = grade;
reviewPerformanceEl.innerText = Math.floor(rank);
});
}
});
function percentRank(arr, v) {
if (typeof v !== 'number') throw new TypeError('v must be a number');
for (var i = 0, l = arr.length; i < l; i++) {
if (v <= arr[i]) {
while (i < l && v === arr[i]) i++;
if (i === 0) return 0;
if (v !== arr[i-1]) {
i += (v - arr[i-1]) / (arr[i] - arr[i-1]);
}
return i / l;
}
}
return 1;
}
</script>
<?php get_footer(); ?>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment