From facf3625d0cf6be7c5b454a3dad33c9faf713755 Mon Sep 17 00:00:00 2001 From: ivanviduka Date: Fri, 3 May 2024 14:25:07 +0200 Subject: [PATCH 1/5] Fixed errors from plugin checker, additional check for actions which should be done only by admin --- purgely.php | 19 +- readme.txt | 8 +- src/classes/api.php | 2 +- src/classes/edgemodules.php | 116 ++++++----- src/classes/purge-request.php | 3 - src/classes/related-surrogate-keys.php | 1 - src/classes/vcl-handler.php | 6 +- src/settings-page.php | 272 ++++++++++++++----------- src/utils.php | 29 +-- src/wp-cli.php | 18 +- 10 files changed, 267 insertions(+), 207 deletions(-) diff --git a/purgely.php b/purgely.php index 9be6cef..a1a2d8a 100644 --- a/purgely.php +++ b/purgely.php @@ -4,7 +4,7 @@ Plugin URI: http://fastly.com/ Description: Configuration and cache purging for the Fastly CDN. Authors: Zack Tollman (github.com/tollmanz), WIRED Tech Team (github.com/CondeNast) & Fastly -Version: 1.2.25 +Version: 1.2.26 Author URI: http://fastly.com/ */ @@ -62,7 +62,7 @@ class Purgely * * @var string Plugin version. */ - var $version = '1.2.25'; + var $version = '1.2.26'; /** * Currently installed plugin version. @@ -190,10 +190,6 @@ public function __construct() } } - if (is_admin()) { - include $this->src_dir . '/settings-page.php'; - } - // First install DB schema changes $upgrades = new Upgrades($this); $upgrades->check_and_run_upgrades(); @@ -248,6 +244,7 @@ public function __construct() // Load the textdomain. add_action('plugins_loaded', array($this, 'load_plugin_textdomain')); + add_action('plugins_loaded', array($this, 'load_admin_settings')); // Load custom JS for EdgeModules add_action( 'admin_enqueue_scripts', array($this, 'enqueue_admin_script_edgemodules')); @@ -370,6 +367,13 @@ public function load_plugin_textdomain() load_plugin_textdomain('purgely', false, basename(dirname(__FILE__)) . '/languages/'); } + public function load_admin_settings() + { + if (is_admin()) { + include $this->src_dir . '/settings-page.php'; + } + } + /** * Initialize Fastly custom cache tags taxonomy */ @@ -561,8 +565,7 @@ function fastly_io_pixel_ratios_the_content_filter($content) { function fastly_edge_modules() { $result = []; foreach ( glob( $this->edge_modules_dir . "/*.json" ) as $file ) { - if (is_file($file) && $contents = file_get_contents($file)) { - $json = json_decode($contents); + if (is_file($file) && $json = wp_json_file_decode($file)) { $result[$json->id] = $json; } } diff --git a/readme.txt b/readme.txt index d12409c..f62dbf3 100644 --- a/readme.txt +++ b/readme.txt @@ -2,8 +2,8 @@ Contributors: Fastly, Inchoo, CondeNast Tags: fastly, cdn, performance, speed, spike, spike-protection, caching, dynamic, comments, ddos Requires at least: 4.6.2 -Tested up to: 6.4.2 -Stable tag: trunk +Tested up to: 6.5.2 +Stable tag: 1.2.26 License: GPLv2 Integrates Fastly with WordPress publishing tools. @@ -118,6 +118,10 @@ Note: you may have to disable other caching plugins like W3TotalCache to avoid g == Changelog == += 1.2.26 + +* Code cleanup, improvements in data sanitization and escaping input + = 1.2.25 * Assignment fix for constants https://github.com/fastly/WordPress-Plugin/pull/99 diff --git a/src/classes/api.php b/src/classes/api.php index 289f6f2..b81cb30 100644 --- a/src/classes/api.php +++ b/src/classes/api.php @@ -204,7 +204,7 @@ public function error_notice() { ?>
-

error_message); ?>

+

error_message ); ?>

- fastly
- version: + fastly
+ version:

Fastly Edge Modules is a framework that allows you to enable specific functionality on Fastly without needing to write any VCL code. @@ -50,19 +50,20 @@ public function renderSettings() - name; ?>
+ name ); ?>

- description; ?> + description ); ?>

- enabled) && $module->enabled) ? __('Enabled') : __('Disabled'); ?>
- Uploaded: data['uploaded_at']) ? date ( 'Y/m/d' , strtotime($module->data['uploaded_at'])) : __('never'); ?> + enabled) && $module->enabled) ? esc_html__('Enabled', 'purgely') : esc_html__('Disabled', 'purgely'); ?>
+ Uploaded: data['uploaded_at']) ? esc_html( gmdate('Y/m/d' , strtotime($module->data['uploaded_at'] ) ) ) : esc_html__('never', 'purgely'); ?>
- Manage + Manage @@ -71,15 +72,15 @@ public function renderSettings() -