Commit 4dde1942 by Muhammad Usman

summary page added (static content)

parent f0fbe4f7
...@@ -12,20 +12,40 @@ define('NEWSLETTER_PAGE', 'Newsletter Page'); ...@@ -12,20 +12,40 @@ define('NEWSLETTER_PAGE', 'Newsletter Page');
define('BLOG_PAGE', 'Blog'); define('BLOG_PAGE', 'Blog');
if (isset($_GET['activated']) && is_admin()){ $defaultPagesBanner = [BANNER_PAGE, HOSTING_REVIEW_PAGE, ABOUT_US_PAGE, RECENT_REVIEWS_PAGE, TOP_BLOG_PAGE, NEWSLETTER_PAGE, BLOG_PAGE];
$defaultPagesBanner = [BANNER_PAGE, HOSTING_REVIEW_PAGE, ABOUT_US_PAGE, RECENT_REVIEWS_PAGE, TOP_BLOG_PAGE, NEWSLETTER_PAGE, BLOG_PAGE]; for ($i = 0; $i < count($defaultPagesBanner); $i++) {
for ($i = 0; $i < count($defaultPagesBanner); $i++) { $new_page_title = $defaultPagesBanner[$i];
$new_page_title = $defaultPagesBanner[$i]; $page_check = get_page_by_title($new_page_title);
$page_check = get_page_by_title($new_page_title); $new_page = array(
$new_page = array( 'post_type' => 'page',
'post_type' => 'page', 'post_title' => $new_page_title,
'post_title' => $new_page_title, 'post_content' => '',
'post_content' => '', 'post_status' => 'publish',
'post_status' => 'publish', 'post_author' => 1,
'post_author' => 1, );
); if(!isset($page_check->ID)){
if(!isset($page_check->ID)){ $new_page_id = wp_insert_post($new_page);
$new_page_id = wp_insert_post($new_page); }
}
}
} }
function vq_set_default_data()
{
global $wpdb;
$table_name = $wpdb->prefix . "speed_results";
$sql = "CREATE TABLE $table_name (";
$sql .= "id int(10) unsigned NOT NULL AUTO_INCREMENT,";
$sql .= "domain_addr varchar(255) NOT NULL,";
$sql .= "timestamp varchar(255) NOT NULL,";
$sql .= "video varchar(255) NOT NULL,";
$sql .= "screen_shot varchar(255) DEFAULT NULL,";
$sql .= "server_response_time varchar(255) DEFAULT NULL,";
$sql .= "page_load_time varchar(255) DEFAULT NULL,";
$sql .= "PRIMARY KEY (id)";
$sql .= ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql );
}
add_action("after_switch_theme", "vq_set_default_data");
...@@ -30,7 +30,7 @@ function vq_save_hosting_review($post_id) ...@@ -30,7 +30,7 @@ function vq_save_hosting_review($post_id)
function vq_hosting_company_metabox($post, $metabox) function vq_hosting_company_metabox($post, $metabox)
{ {
$selected = get_post_meta( get_the_ID(), 'vq_review_hosting_company', true ); $selected = get_post_meta( get_the_ID(), 'vq_review_hosting_company', true );
$hosting_companies = json_decode(get_option('vq_hosting_companies')); $hosting_companies = json_decode(get_option('vq_hosting_companies_details'));
if (!isset($hosting_companies)) { if (!isset($hosting_companies)) {
$hosting_companies = []; $hosting_companies = [];
} }
...@@ -58,7 +58,7 @@ function vq_hosting_company_metabox($post, $metabox) ...@@ -58,7 +58,7 @@ function vq_hosting_company_metabox($post, $metabox)
<label>Hosting Company: </label> <label>Hosting Company: </label>
<select name="vq_review_hosting_company" id="voodoo_dropdown"> <select name="vq_review_hosting_company" id="voodoo_dropdown">
<?php foreach ($hosting_companies as $company): ?> <?php foreach ($hosting_companies as $company): ?>
<option value="<?php echo $company->slug;?>" <?php echo $selected === $company->slug ? 'selected' : '' ?> ><?php echo $company->title; ?></option> <option value="<?php echo $company->slug;?>" <?php echo $selected === $company->slug ? 'selected' : '' ?> ><?php echo $company->name; ?></option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
</div> </div>
......
<?php <?php
function vq_theme_settings_page() function vq_theme_settings_page()
{ {
?> ?>
...@@ -11,6 +9,12 @@ function vq_theme_settings_page() ...@@ -11,6 +9,12 @@ function vq_theme_settings_page()
<?php <?php
settings_fields("section"); settings_fields("section");
do_settings_sections("hosting-review-theme-options"); do_settings_sections("hosting-review-theme-options");
settings_fields("server-locations-section");
do_settings_sections("hosting-server-locations");
submit_button(); submit_button();
?> ?>
</form> </form>
...@@ -23,137 +27,82 @@ add_action('admin_menu', 'vq_add_theme_setting_page'); ...@@ -23,137 +27,82 @@ add_action('admin_menu', 'vq_add_theme_setting_page');
function display_hosting_companies_table() function display_hosting_companies_table()
{ {
?> ?>
<input style="display: none;" type="text" name="vq_hosting_companies" id="vq_hosting_companies" value="" />
<style>
.hosting-companies {
border-collapse: collapse;
text-align: center;
}
.hosting-companies th, .hosting-companies td {
padding: 5px;
text-align: center;
}
.hosting-companies tbody tr:nth-child(even) {
background: #fff;
}
.hosting-companies tbody tr:nth-child(odd) {
background: #ddd;
}
.hosting-companies tr.in-edit {
background: #b4b9be !important;
}
#cancel-company-btn {
display: none;
}
</style>
<table>
<tr>
<td>Title: <input type="text" id="new-company-title"></td>
<td>Slug: <input type="text" id="new-company-slug"></td>
<td><button onclick="saveCompany()" type="button" id="add-company-btn">Add</button></td>
<td><button onclick="resetData()" type="button" id="cancel-company-btn">Cancel</button></td>
</tr>
<tr>
</tr>
</table>
<table class="hosting-companies"> <table class="hosting-companies-listing mb-3">
<thead> <thead>
<tr> <tr>
<th>Title</th> <th>Title</th>
<th>Slug</th> <th>Slug</th>
<th>Hosting</th>
<th>Locations</th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
<tbody id="hosting-companies-body"> <tbody id="hosting-companies-body">
</tbody> </tbody>
</table> </table>
<div class="hosting-company-data" id="hosting-data-wrapper">
<div class="row align-items-center">
<div class ="col-md-3"><label>Name</label></div>
<div class="col-md-9"><input type="text" id="hosting-company-name"></div>
</div>
<div class="row mt-2 align-items-center">
<div class ="col-md-3"><label>Organization</label></div>
<div class="col-md-9"><input type="text" id="hosting-company-slug"></div>
</div>
<div>
<h4 class="mb-2">Hosting Packages</h4>
<div id="hosting-packages-wrapper">
</div>
</div>
<a style="cursor: pointer;" onclick="addHostingPackages()">+ Add Package</a>
<div class="mt-3">
<h4 class="mb-2">Server Locations</h4>
<div id="hosting-locations-wrapper">
</div>
</div>
<a style="cursor: pointer;" onclick="addHostingLocation()">+ Add Location</a>
<div class="d-flex justify-content-between mt-4">
<button type="button" class="button button-primary" onclick="saveHostingCompany()">Add</button>
<button type="button" class="button" onclick="resetChanges()">Cancel</button>
</div>
</div>
<input style="display: none;" type="text" name="vq_hosting_companies_details" id="vq_hosting_companies_details" value="" />
<script> <script>
var hostingCompaniesData = <?php echo get_option('vq_hosting_companies'); ?>; var hostingCompaniesDetails = <?php echo get_option('vq_hosting_companies_details') ? get_option('vq_hosting_companies_details') : '[]'; ?>;
if (!hostingCompaniesData) {
hostingCompaniesData = [];
}
var inEditIndex = -1;
var titleEl = document.getElementById('new-company-title');
var slugEl = document.getElementById('new-company-slug');
var cancelEl = document.getElementById('cancel-company-btn');
function saveCompany() {
if (!titleEl.value || !slugEl.value) {
return alert('Please fill all fields');
}
if (inEditIndex > -1) {
hostingCompaniesData[inEditIndex].title = titleEl.value;
hostingCompaniesData[inEditIndex].slug = slugEl.value;
} else {
hostingCompaniesData.push({title: titleEl.value, slug: slugEl.value});
}
populateTable();
resetData();
}
function editCompany(index) {
resetData();
inEditIndex = index;
titleEl.value = hostingCompaniesData[index].title;
slugEl.value = hostingCompaniesData[index].slug;
document.getElementById('add-company-btn').innerText = 'Update';
document.getElementById(`hosting-company-${index}`).classList.add('in-edit');
document.getElementById('cancel-company-btn').style.display = 'block';
}
function deleteCompany(index) {
if (confirm('Are you you want to remove this company?')) {
hostingCompaniesData.splice(index, 1);
populateTable();
resetData();
}
}
function resetData() {
if (inEditIndex > -1) {
document.getElementById(`hosting-company-${inEditIndex}`).classList.remove('in-edit');
}
titleEl.value = '';
slugEl.value = '';
inEditIndex = -1;
document.getElementById('cancel-company-btn').style.display = 'none';
}
function populateTable() {
var tableBody = document.getElementById('hosting-companies-body');
tableBody.innerHTML = '';
hostingCompaniesData.forEach(function(company, index) {
var row = `<tr id="hosting-company-${index}">`;
row += `<td>${company.title}</td>`;
row += `<td>${company.slug}</td>`;
row += `<td><a style="cursor:pointer;" onclick="editCompany(${index})">Edit</a> &nbsp;&nbsp; <a style="cursor:pointer;" onclick="deleteCompany(${index})"> Delete</a></td>`;
row += `</tr>`;
tableBody.innerHTML += row;
});
resetData();
document.getElementById('vq_hosting_companies').value = JSON.stringify(hostingCompaniesData);
}
populateTable();
</script> </script>
<?php <?php
} }
function display_server_locations()
{
?>
<?php
}
function vq_display_theme_panel_fields() function vq_display_theme_panel_fields()
{ {
add_settings_section("section", "Hosting Companies", null, "hosting-review-theme-options"); 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");
register_setting("section", "vq_hosting_companies_details");
add_settings_field("vq_hosting_companies", "Add Hosting Company", "display_hosting_companies_table", "hosting-review-theme-options", "section");
register_setting("section", "vq_hosting_companies"); 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");
} }
......
.hosting-companies-listing {
border-collapse: collapse;
background: #fff;
}
.hosting-companies-listing thead tr {
border-bottom: 2px solid #ccc;
}
.hosting-companies-listing tbody tr {
border-bottom: 1px solid #ccc;
}
.hosting-companies-listing tr:nth-child(even) {
background: #ddd;
}
.hosting-companies-listing th, .hosting-companies-listing td {
text-align: center;
padding: 8px;
}
.hosting-companies-listing a {
cursor: pointer;
}
.hosting-company-data {
display: inline-block;
padding: 30px;
background: #fff;
border-radius: 5px;
min-width: 600px;
}
.hosting-company-data label {
font-weight: 500;
}
.hosting-company-data input.small-fld {
width: 100px;
}
.hosting-company-data input {
font-size: 16px;
padding: 5px;
flex: 1;
width: 100%;
}
var hostingPackageTemplate =
`<div class="d-flex align-items-center mb-1 row hosting-package-details" id="hosting-package-details-%ID%">
<div class="col-md-6">
<input type="text" class="mr-3 hosting-package-name" id="hosting-package-name-%ID%">
</div>
<div class="col-md-3">
<label>Starting from</label>
</div>
<div class="col-md-3">
<input type="text" class="small-fld hosting-package-starting" id="hosting-package-starting-%ID%">
</div>
</div>`;
var hostingLocationTemplate = `
<div class="d-flex align-items-center mb-1 hosting-package-location" id="hosting-location-%ID%">
<input type="text" placeholder="Location Name" class="hosting-package-location-name" id="hosting-location-name-%ID%">
</div>`;
$(document).ready(function () {
var hostingDataWrapper = document.getElementById('hosting-data-wrapper');
var hostingPackagesWrapper = document.getElementById('hosting-packages-wrapper');
var hostingLocationsWrapper = document.getElementById('hosting-locations-wrapper');
var hiddenDataField = document.getElementById('vq_hosting_companies_details');
var hostingCompaniesBody = document.getElementById('hosting-companies-body');
var hostingNameEl = document.getElementById('hosting-company-name');
var hostingSlugEl = document.getElementById('hosting-company-slug');
var hostingInEdit = -1;
resetChanges = function () {
hostingInEdit = -1;
hostingNameEl.value = '';
hostingSlugEl.value = '';
hostingPackagesWrapper.innerHTML = '';
hostingLocationsWrapper.innerHTML = '';
};
addHostingPackages = function () {
const existingPackages = document.getElementsByClassName('hosting-package-details').length;
hostingPackagesWrapper.insertAdjacentHTML('beforeend', hostingPackageTemplate.replace(/%ID%/g, existingPackages.toString()));
};
addHostingLocation = function () {
const existingPackages = document.getElementsByClassName('hosting-package-location').length;
hostingLocationsWrapper.insertAdjacentHTML('beforeend', hostingLocationTemplate.replace(/%ID%/g, existingPackages.toString()));
};
saveHostingCompany = function () {
var hostingInfo = {};
hostingInfo.name = hostingNameEl.value;
hostingInfo.slug = hostingSlugEl.value;
if (!hostingInfo.name || !hostingInfo.slug) {
return alert('Title & Organization is required.');
}
const packages = hostingPackagesWrapper.getElementsByClassName('hosting-package-details');
hostingInfo.packages = [];
for (var i = 0; i < packages.length; i++) {
const name = document.getElementById(`hosting-package-name-${i}`).value;
const price = document.getElementById(`hosting-package-starting-${i}`).value;
hostingInfo.packages.push({title: name, price: price});
}
const locations = hostingLocationsWrapper.getElementsByClassName('hosting-package-location');
hostingInfo.locations = [];
for (var i = 0; i < locations.length; i++) {
const name = locations[i].getElementsByClassName('hosting-package-location-name')[0].value;
hostingInfo.locations.push(name);
}
if (hostingInEdit > -1) {
hostingCompaniesDetails[hostingInEdit] = hostingInfo;
} else {
hostingCompaniesDetails.push(hostingInfo);
}
populateTable();
};
populateTable = function() {
hostingCompaniesBody.innerHTML = '';
hostingCompaniesDetails.forEach(function(company, index) {
var packagesStr = '';
var locationsStr = '';
if (company.packages) {
company.packages.forEach(function (package) {
packagesStr += `<p>${package.title} Starting from $${package.price}</p>`;
})
}
if (company.locations) {
locationsStr = company.locations.join(', ');
}
var row = `<tr>`;
row += `<td>${company.name}</td>`;
row += `<td>${company.slug}</td>`;
row += `<td>${packagesStr}</td>`;
row += `<td>${locationsStr}</td>`;
row += `<td><a onclick="editCompany(${index})">Edit</a> <a class="ml-2 button-link-delete" onclick="removeCompany(${index})">Remove</a></td>`;
row += `</tr>`;
hostingCompaniesBody.innerHTML += row;
});
hiddenDataField.value = JSON.stringify(hostingCompaniesDetails);
resetChanges();
};
removeCompany = function(index) {
if (confirm('Are you sure you want to remove the info of this hosting company?')) {
hostingCompaniesDetails.splice(index, 1);
populateTable();
}
};
editCompany = function(index) {
hostingInEdit = index;
const companyInEdit = hostingCompaniesDetails[hostingInEdit];
hostingNameEl.value = companyInEdit.name;
hostingSlugEl.value = companyInEdit.slug;
hostingPackagesWrapper.innerHTML = '';
if (companyInEdit.packages) {
companyInEdit.packages.forEach(function (pkg, ind) {
hostingPackagesWrapper.insertAdjacentHTML('beforeend', hostingPackageTemplate.replace(/%ID%/g, ind.toString()));
document.getElementById(`hosting-package-name-${ind}`).value = pkg.title;
document.getElementById(`hosting-package-starting-${ind}`).value = pkg.price;
});
}
hostingLocationsWrapper.innerHTML = '';
if (companyInEdit.locations) {
companyInEdit.locations.forEach(function (loc, ind) {
hostingLocationsWrapper.insertAdjacentHTML('beforeend', hostingLocationTemplate.replace(/%ID%/g, ind.toString()));
document.getElementById(`hosting-location-name-${ind}`).value = loc;
});
}
};
populateTable();
});
// document.addEventListener("DOMContentLoaded", function() {
// });
jQuery(document).ready(function($) {
var speedBtn = document.getElementById('homeSpeedButton');
if (speedBtn) {
speedBtn.addEventListener('click', getSpeed);
}
function getSpeed() {
const domainNameEl = document.getElementById('domainNameField');
if (!domainNameEl.value) {
return alert('Please enter a domain');
}
var data = {
'action': 'get_speed_results',
'domain': domainNameEl.value
};
$.post(ajax_url, data, function(response) {
console.log( response );
}, 'json');
}
});
// $(document).ready(function () {
//
// (function ($) {
//
//
// {
// var data = {
// 'action': 'get_speed_results',
// 'post_type': 'POST',
// 'name': 'My First AJAX Request'
// };
//
// jQuery.post("", data, function(response) {
// console.log( response );
// }, 'json');
//
// //
// var xhttp = new XMLHttpRequest();
// xhttp.open("POST", ``, true);
// xhttp.send(JSON.stringify(data));
// // xhttp.onreadystatechange = function() {
// // console.log(this.responseText);
// // // if (this.readyState === 4 && this.status === 200) {
// // // document.getElementById("demo").innerHTML =
// // // this.responseText;
// // // }
// // };
// // // http://176.31.196.92:30001/google.com/2019-12-18T142721+0000/pages/google.com/data/screenshots/1.jpg
//
// // xhttp.setRequestHeader('Content-type', 'application/json');
//
// }
// })(jQuery);
...@@ -22,8 +22,8 @@ echo $page->post_content; ...@@ -22,8 +22,8 @@ echo $page->post_content;
<!-- Top Recent Reviews --> <!-- Top Recent Reviews -->
<?php <?php
$page = get_page_by_title( RECENT_REVIEWS_PAGE); //$page = get_page_by_title( RECENT_REVIEWS_PAGE);
echo do_shortcode($page->post_content); //echo do_shortcode($page->post_content);
?> ?>
<div class="container"> <div class="container">
<div class="hrBorder"></div> <div class="hrBorder"></div>
...@@ -31,8 +31,8 @@ echo do_shortcode($page->post_content); ...@@ -31,8 +31,8 @@ echo do_shortcode($page->post_content);
<!-- Top Blogs Content --> <!-- Top Blogs Content -->
<?php <?php
$page = get_page_by_title( TOP_BLOG_PAGE); //$page = get_page_by_title( TOP_BLOG_PAGE);
echo do_shortcode($page->post_content); //echo do_shortcode($page->post_content);
?> ?>
<?php <?php
......
...@@ -8,10 +8,6 @@ ...@@ -8,10 +8,6 @@
<meta name="author" content=""> <meta name="author" content="">
<title><?php echo get_bloginfo() ?></title> <title><?php echo get_bloginfo() ?></title>
<!-- Custom Css Link Start-->
<link rel="stylesheet" type="text/css" href="assets/css/custom.css"/>
<!-- Custom Css Link End-->
<!-- Bootstrap Link Start--> <!-- Bootstrap Link Start-->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"> integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
...@@ -26,6 +22,10 @@ ...@@ -26,6 +22,10 @@
<link href="https://fonts.googleapis.com/css?family=Exo:300,300i,400,500,700,700i,900,900i&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Exo:300,300i,400,500,700,700i,900,900i&display=swap" rel="stylesheet">
<!-- Font Family --> <!-- Font Family -->
<?php wp_head(); ?> <?php wp_head(); ?>
<script type="">
var ajax_url = "<?= admin_url('admin-ajax.php'); ?>";
</script>
</head> </head>
<!-- Body Code Start--> <!-- Body Code Start-->
......
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