From 2736e2926783e139c4a35b6cf7840339f1cfbdb9 Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Wed, 16 Oct 2019 09:12:53 -0400 Subject: [PATCH] Various visual and user interface improvements Separated admin edit of Selected Site and Global paramters into two forms Added ability to set maximum cookie pop-up width Updated default cookie pop-up text Various fixes and updates to interaction with licensing and update server Responsive layout improved for medium widths Now using popup border color for button border color --- defines.php | 2 +- index.php | 4 +- .../opentools-update-checker.php | 11 +- lib/plugin-update-checker/github-checker.php | 2 +- .../plugin-update-checker.php | 23 +- models/adminServerStats.php | 42 ++- models/frontCookiePopUp.php | 16 +- readme.txt | 8 + views/adminServerStats.html | 302 ++++++++++++------ views/ui/f6/form-edit-start.html | 1 + views/ui/f6/form-summary-start.html | 14 +- 11 files changed, 291 insertions(+), 134 deletions(-) diff --git a/defines.php b/defines.php index 450b3fd..c76d4ef 100755 --- a/defines.php +++ b/defines.php @@ -110,7 +110,7 @@ define('GLM_SERVERSTATS_PLUGIN_MODEL_PATH', GLM_SERVERSTATS_PLUGIN_PATH.'/models define('GLM_SERVERSTATS_PLUGIN_VIEW_PATH', GLM_SERVERSTATS_PLUGIN_PATH.'/views'); // Update Server -define('GLM_SERVERSTATS_PLUGIN_UPDATE_SERVER', 'http://www.gaslightmedia.com/update_server'); +define('GLM_SERVERSTATS_PLUGIN_UPDATE_SERVER', 'https://www.gaslightmedia.com/update_server'); // define('GLM_SERVERSTATS_PLUGIN_UPDATE_SERVER', 'https://192.168.44.82/update_server'); // Other diff --git a/index.php b/index.php index 79335e8..ff62f01 100755 --- a/index.php +++ b/index.php @@ -174,9 +174,9 @@ if ( ( !empty( $_REQUEST['force_cookie'] ) || $websiteSettings['show_cookie_popu // Have WordPress include the cookie pop-up code just before the footer. function doCookiePopUp() { - include GLM_SERVERSTATS_PLUGIN_MODEL_PATH . '/frontCookiePopUp.php'; + include GLM_SERVERSTATS_PLUGIN_MODEL_PATH.'/frontCookiePopUp.php'; } - add_action( 'get_footer', '\GlmServerStats\doCookiePopUp' ); + add_action( 'wp_footer', '\GlmServerStats\doCookiePopUp' ); } diff --git a/lib/opentools-update-checker/opentools-update-checker.php b/lib/opentools-update-checker/opentools-update-checker.php index 2cee653..7ae92f2 100644 --- a/lib/opentools-update-checker/opentools-update-checker.php +++ b/lib/opentools-update-checker/opentools-update-checker.php @@ -30,7 +30,6 @@ class OpenToolsPluginUpdateChecker extends PluginUpdateChecker_3_1 { $this->credvars = $credential_def; // Append the update credentials to the update server link $this->addQueryArgFilter(array($this, 'appendQueryArgsCredentials')); - } protected function installOTHooks() @@ -221,11 +220,19 @@ class OpenToolsPluginUpdateChecker extends PluginUpdateChecker_3_1 { $this->setCredentials($this->slug, $credentials); $success = FALSE; $updateinfo = $this->requestInfo(array()); - if ($updateinfo && isset($updateinfo->download_url)) { $downloadurl = $updateinfo->download_url; $downloadurl = apply_filters('puc_check_download_query_args-'.$this->slug, $downloadurl); + if (GLM_SERVERSTATS_PLUGIN_HOST == 'DEVELOPMENT') { + stream_context_set_default( [ + 'ssl' => [ + 'verify_peer' => false, + 'verify_peer_name' => false, + ], + ]); + } + $headers = get_headers($downloadurl); list($version, $status_code, $msg) = explode(' ',$headers[0], 3); diff --git a/lib/plugin-update-checker/github-checker.php b/lib/plugin-update-checker/github-checker.php index c2d506f..a65b625 100644 --- a/lib/plugin-update-checker/github-checker.php +++ b/lib/plugin-update-checker/github-checker.php @@ -282,7 +282,7 @@ class PucGitHubChecker_3_1 extends PluginUpdateChecker_3_1 { return $document; } - return new WP_Error( + return new \WP_Error( 'puc-github-http-error', 'GitHub API error. HTTP status: ' . $code ); diff --git a/lib/plugin-update-checker/plugin-update-checker.php b/lib/plugin-update-checker/plugin-update-checker.php index b9a9852..f321fe0 100644 --- a/lib/plugin-update-checker/plugin-update-checker.php +++ b/lib/plugin-update-checker/plugin-update-checker.php @@ -169,6 +169,7 @@ class PluginUpdateChecker_3_1 { * @return PluginInfo_3_1 */ public function requestInfo($queryArgs = array()){ + //Query args to append to the URL. Plugins can add their own by using a filter callback (see addQueryArgFilter()). $installedVersion = $this->getInstalledVersion(); $queryArgs['installed_version'] = ($installedVersion !== null) ? $installedVersion : ''; @@ -180,7 +181,9 @@ class PluginUpdateChecker_3_1 { 'headers' => array( 'Accept' => 'application/json' ), + 'sslverify' => (!GLM_SERVERSTATS_PLUGIN_HOST=='DEVELOPMENT') // *** Added to permit testing with development server that uses a self-signed cert ); + $options = apply_filters('puc_request_info_options-'.$this->slug, $options); //The plugin info should be at 'http://your-api.com/url/here/$slug/info.json' @@ -188,7 +191,6 @@ class PluginUpdateChecker_3_1 { if ( !empty($queryArgs) ){ $url = add_query_arg($queryArgs, $url); } - $result = wp_remote_get( $url, $options @@ -205,6 +207,7 @@ class PluginUpdateChecker_3_1 { } } else { + return false; /* Not generating error at this time as this could simply be a bad or missing key submitted $this->triggerError( @@ -222,28 +225,28 @@ class PluginUpdateChecker_3_1 { /** * Check if $result is a successful update API response. * - * @param array|WP_Error $result - * @return true|WP_Error + * @param array WP_Error $result + * @return true WP_Error */ private function validateApiResponse($result) { if ( is_wp_error($result) ) { /** @var WP_Error $result */ - return new WP_Error($result->get_error_code(), 'WP HTTP Error: ' . $result->get_error_message()); + return new \WP_Error($result->get_error_code(), 'WP HTTP Error: ' . $result->get_error_message()); } if ( !isset($result['response']['code']) ) { - return new WP_Error('puc_no_response_code', 'wp_remote_get() returned an unexpected result.'); + return new \WP_Error('puc_no_response_code', 'wp_remote_get() returned an unexpected result.'); } if ( $result['response']['code'] !== 200 ) { - return new WP_Error( + return new \WP_Error( 'puc_unexpected_response_code', 'HTTP response code is ' . $result['response']['code'] . ' (expected: 200)' ); } if ( empty($result['body']) ) { - return new WP_Error('puc_empty_response', 'The metadata file appears to be empty.'); + return new \WP_Error('puc_empty_response', 'The metadata file appears to be empty.'); } return true; @@ -621,7 +624,7 @@ class PluginUpdateChecker_3_1 { //WordPress will try to copy the entire working directory ($source == $remoteSource). We can't rename //$remoteSource because that would break WordPress code that cleans up temporary files after update. if ( $this->isBadDirectoryStructure($remoteSource) ) { - return new WP_Error( + return new \WP_Error( 'puc-incorrect-directory-structure', sprintf( 'The directory structure of the update is incorrect. All plugin files should be inside ' . @@ -642,7 +645,7 @@ class PluginUpdateChecker_3_1 { $upgrader->skin->feedback('Plugin directory successfully renamed.'); return $correctedSource; } else { - return new WP_Error( + return new \WP_Error( 'puc-rename-failed', 'Unable to rename the update to match the existing plugin directory.' ); @@ -1043,7 +1046,7 @@ class PluginInfo_3_1 { || empty($apiResponse->name) || empty($apiResponse->version) ) { - return new WP_Error( + return new \WP_Error( 'puc-invalid-metadata', "The plugin metadata file does not contain the required 'name' and/or 'version' keys." ); diff --git a/models/adminServerStats.php b/models/adminServerStats.php index 2151675..9ad24d3 100755 --- a/models/adminServerStats.php +++ b/models/adminServerStats.php @@ -128,7 +128,7 @@ class adminServerStats extends glmServerStatsBandwidthSupport } - if ($option == 'update_site') { + if ( $option == 'update_site' ) { // Update the website table with certain values $vals = filter_input_array( INPUT_POST, @@ -154,7 +154,8 @@ class adminServerStats extends glmServerStatsBandwidthSupport 'color_text' => FILTER_SANITIZE_STRING, 'color_buttontext' => FILTER_SANITIZE_STRING, 'popup_border' => FILTER_SANITIZE_STRING, - 'popup_position' => FILTER_SANITIZE_STRING + 'popup_position' => FILTER_SANITIZE_STRING, + 'popup_width' => FILTER_VALIDATE_INT, ),true ); @@ -184,13 +185,17 @@ class adminServerStats extends glmServerStatsBandwidthSupport color_text = '".$vals['color_text']."', color_buttontext = '".$vals['color_buttontext']."', popup_border = '".$vals['popup_border']."', - popup_position = '".$vals['popup_position']."' + popup_position = '".$vals['popup_position']."', + popup_width = ".$vals['popup_width']." WHERE name = '".$currentSiteName."' "; if (!$bwdb->query($sql)) { printf("Error: %s\n", $bwdb->error); } + } + if ( $option == 'update_settings' ) { + // Update Reporting From Contact and Title (GLM) $glmFromContact = [ 'name' => filter_input( INPUT_POST, 'report_contact_name', FILTER_SANITIZE_STRING), @@ -224,11 +229,17 @@ class adminServerStats extends glmServerStatsBandwidthSupport // Get list of sites in the bandwidth database $websites = $this->bandwidthLastMonthAllSites($sortBy); - } else { - // Get the settings for the currently selected site - $currentSite = bandwidthGetWebsiteSettingsFromName($currentSiteName); } + // Get the settings for the currently selected site + $currentSite = bandwidthGetWebsiteSettingsFromName($currentSiteName); + + // Fix old positioning option + if ( $currentSite['popup_position'] == 'Top' ) { + $currentSite['popup_position'] = 'Top Left'; + } + + // Get bandwidth stats for the current site $stats = $this->getStatsAndCheckTargetExceeded($currentSite); @@ -250,12 +261,19 @@ class adminServerStats extends glmServerStatsBandwidthSupport // Default text to use if the Cookie Message text is not supplied if (trim($currentSite['cookie_message']) == '') { $currentSite['cookie_message'] = - '

This site uses temporary "Cookies" to store limited information that\'s ' - .'required to provide you with a consistent user experience. We don\'t store ' - .'personally identifying or other sensitive information in these Cookies and ' - .'these Cookies are erased when you close your Web Browser unless otherwise ' - .'stated when you click "Show more".

If you\'re on a public computer, ' - .'be sure to close all Web Browsers when you\'re done!

'; + '

This site uses "Cookies" to store limited information ' + .'required to provide you with a consistent user experience. ' + .'Click "Show more" for additional information.

'; + + $sql = " + UPDATE website + SET cookie_message = '".$currentSite['cookie_message']."' + WHERE name = '".$currentSiteName."' + "; + if (!$bwdb->query($sql)) { + printf("Error: %s\n", $bwdb->error); + } + } // Default text to use if reporting E-Mail content is not supplied diff --git a/models/frontCookiePopUp.php b/models/frontCookiePopUp.php index ee80f5c..1fb9640 100755 --- a/models/frontCookiePopUp.php +++ b/models/frontCookiePopUp.php @@ -5,20 +5,24 @@ namespace GLMServerStats; $bwdb = mysqli_init(); $settings = bandwidthDataConnect(GLM_SERVERSTATS_PLUGIN_HOSTNAME); -if ( $settings['popup_position'] == 'Top' ) { - $position = 'position: absolute; top: 0px;'; -} else { - $position = 'position: fixed; bottom: 0;'; +if ( $settings['popup_position'] == 'Top Left' || $settings['popup_position'] == 'Top') { // Top left in for backward compatibiltiy with settings + $position = 'position: absolute; top: 0px; left: 0;'; +} elseif ( $settings['popup_position'] == 'Top Right' ) { + $position = 'position: absolute; top: 0px; right: 0;'; +} elseif ( $settings['popup_position'] == 'Bottom Right' ) { + $position = 'position: fixed; bottom: 0; right: 0;'; +} else { // Bottom left + $position = 'position: fixed; bottom: 0; left: 0;'; } ?>