Plugin Directory

Changeset 3012051


Ignore:
Timestamp:
12/19/2023 03:22:44 PM (2 years ago)
Author:
hexydec
Message:

The name of the app is not title case when Console Logging in app::drawStats()
Used PHP 8.0 property type definitions, and union return types where needed
Updated require calls in autoloaders to be used as a keyword and for the spl_autoload_register() call not to return a value
Fixed issue in csp::recommendations() where if the recommended URL was the base URL of the site, it should use 'self` instead
The minimum supported PHP version is now 8.0
Updated packages to latest versions

Location:
torque/trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • torque/trunk/admin.php

    r2823176 r3012051  
    1010
    1111    /**
    12      * @var $template Stores the name of the cirrently compiling template, see self::compile()
    13      */
    14     protected static $template;
     12     * @var $template Stores the name of the currently compiling template, see self::compile()
     13     */
     14    protected static string $template;
    1515
    1616    /**
  • torque/trunk/app.php

    r2912478 r3012051  
    387387        // render javascript
    388388        $console = [
    389             'console.groupCollapsed("'.self::SLUG.' Stats");',
     389            'console.groupCollapsed("'.\mb_convert_case(self::SLUG, MB_CASE_TITLE).' Stats");',
    390390            'console.table('.\json_encode($table).');',
    391391            'console.table('.\json_encode($sizes).');',
  • torque/trunk/assets.php

    r2939649 r3012051  
    1010
    1111    /**
    12      * @var $pages Caches the result of any page requests
    13      */
    14     protected static $pages = [];
    15 
    16     /**
    17      * @var $assets Caches the result any assets that have been gathered from a page
    18      */
    19     protected static $assets = [];
     12     * @var array $pages Caches the result of any page requests
     13     */
     14    protected static array $pages = [];
     15
     16    /**
     17     * @var array$assets Caches the result any assets that have been gathered from a page
     18     */
     19    protected static array $assets = [];
    2020
    2121    /**
  • torque/trunk/autoload.php

    r2823176 r3012051  
    55 * @package hexydec/torque
    66 */
    7 \spl_autoload_register(function (string $class) : bool {
     7\spl_autoload_register(function (string $class) : void {
    88    $namespace = 'hexydec\\torque\\';
    99    $classes = [
     
    1919    ];
    2020    if (isset($classes[$class]) && \file_exists($classes[$class])) {
    21         return require($classes[$class]);
     21        require $classes[$class];
    2222    }
    23     return false;
    2423});
    2524
  • torque/trunk/config.php

    r2823176 r3012051  
    1212     * @var array $options A list of configuration options for the plugin
    1313     */
    14     protected $options = [];
     14    protected array $options = [];
    1515
    1616    /**
    1717     * @var array $config The plugin configuration
    1818     */
    19     protected $config = [
     19    protected array $config = [
    2020        'output' => null, // can't be set here, see below
    2121        'csplog' => 'csp-reports.json'
     
    2727    public function __construct() {
    2828        $url = \get_home_url().'/?notorque';
    29         $dir = \dirname(\dirname(\dirname(__DIR__))).'/'; // can't use get_home_path() here
     29        // $dir = \dirname(\dirname(\dirname(__DIR__))).'/'; // can't use get_home_path() here
    3030        $this->config['output'] = WP_CONTENT_DIR.'/uploads/torque/';
    3131
     
    6565                        'description' => 'Select which CSS files to combine and minify',
    6666                        'default' => [],
    67                         'datasource' => function () use ($url) {
     67                        'datasource' => function () use ($url) : array|false {
    6868                            if (($assets = assets::getPageAssets($url)) !== false) {
    6969                                $filtered = [];
     
    7777                            return false;
    7878                        },
    79                         'onsave' => function (array $value, array $options) {
     79                        'onsave' => function (array $value, array $options) : bool {
    8080                            if ($value) {
    8181                                $target =  $this->config['output'].\md5(\implode(',', $value)).'.css';
    8282                                if (!assets::buildCss($value, $target, $options['minifystyle'] ? ($options['style'] ?? []) : null)) {
    8383                                    \add_settings_error(self::SLUG, self::SLUG, 'The combined CSS file could not be generated');
     84                                    return false;
    8485                                }
    8586                            }
    86                             return false;
     87                            return true;
    8788                        }
    8889                    ],
     
    9899                        'description' => 'Select which Javascript files to combine and minify. Note that depending on the load order requirements of your inline and included scripts, this can break your Javascript. Check the console for errors after implementing.',
    99100                        'default' => [],
    100                         'datasource' => function () use ($url) {
     101                        'datasource' => function () use ($url) : array|false {
    101102                            if (($assets = assets::getPageAssets($url)) !== false) {
    102103                                $filtered = [];
     
    110111                            return false;
    111112                        },
    112                         'onsave' => function (array $value, array $options) {
     113                        'onsave' => function (array $value, array $options) : bool {
    113114                            if ($value) {
    114115                                $target =  $this->config['output'].\md5(\implode(',', $value)).'.js';
    115116                                if (!assets::buildJavascript($value, $target, $options['minifyscript'] ? ($options['script'] ?? []) : null)) {
    116117                                    \add_settings_error(self::SLUG, self::SLUG, 'The combined Javascript file could not be generated');
     118                                    return false;
    117119                                }
    118120                            }
    119                             return false;
     121                            return true;
    120122                        }
    121123                    ],
     
    620622                        'type' => 'checkbox',
    621623                        'default' => false,
    622                         'onsave' => function (bool $value) {
     624                        'onsave' => function (bool $value) : bool {
    623625                            if ($value) {
    624626                                $report = $this->config['output'].$this->config['csplog'];
     
    642644                        'type' => 'multiselect',
    643645                        'default' => [],
    644                         'datasource' => function () use ($url) {
     646                        'datasource' => function () use ($url) : array|false {
    645647                            if (($assets = assets::getPageAssets($url)) !== false) {
    646648               
     
    751753        $keys = [];
    752754        foreach ($this->options AS $key => $item) {
    753             $tab = $item['tab'];
    754755            if (!\in_array($item['tab'], $tabs)) {
    755756                $tabs[] = $item['tab'];
  • torque/trunk/csp.php

    r2823176 r3012051  
    5555            }
    5656        }
    57         return $key ? $csp[$key] ?? null : $csp;
     57        return $key ? ($csp[$key] ?? null) : $csp;
    5858    }
    5959
    60     public static function recommendations(string $file, string $key) {
     60    public static function recommendations(string $file, string $key) : ?array {
    6161        if (($data = self::violations($file, $key)) !== null) {
    62             $keywords = ["'unsafe-inline'", "'unsafe-eval'", 'data' => 'data:', 'self' => "'self"];
     62
     63            // define kewords
     64            $keywords = ["'unsafe-inline'", "'unsafe-eval'", 'data' => 'data:', "'self'", 'blob:'];
     65
     66            // build recommendations
    6367            $recs = [];
    6468            foreach (\array_keys($data) AS $href) {
     
    99103
    100104                // add keyword
    101                 } elseif (!in_array($href, $recs)) {
     105                } elseif (!\in_array($href, $recs)) {
    102106                    $recs[] = $href;
     107                }
     108            }
     109
     110            // build root URL
     111            $self = (($_SERVER['HTTPS'] ?? 'off') !== 'off' ? 'https' : 'http').'://'.$_SERVER['HTTP_HOST'];
     112            $folder = \str_replace('\\', '/', \mb_substr(\ABSPATH, \mb_strlen($_SERVER['DOCUMENT_ROOT'])));
     113            $base = $self.$folder;
     114
     115            // replace root with 'self'
     116            foreach ($recs AS $key => $item) {
     117                if ($item === $base) {
     118                    $recs[$key] = "'self'";
    103119                }
    104120            }
  • torque/trunk/overview.php

    r2939649 r3012051  
    1212     * @var array $config Stores the configuration for the overview page
    1313     */
    14     protected $config = [];
     14    protected array $config = [];
    1515
    1616    /**
  • torque/trunk/packages.php

    r2939649 r3012051  
    2929     * Note that external dependencies are only installed when install-external.php is available and the packages are not already bundled
    3030     */
    31     protected static $packages = [
     31    protected static array $packages = [
    3232        'htmldoc' => [
    3333            'class' => 'hexydec\\html\\htmldoc',
     
    6262     */
    6363    public static function autoload() : void {
    64         \spl_autoload_register(function (string $class) : bool {
     64        \spl_autoload_register(function (string $class) : void {
    6565            $dir = self::INSTALLDIR;
    6666            foreach (self::$packages AS $item) {
    6767                if ($item['class'] === $class && \file_exists($dir.$item['autoload'])) {
    68                     return require($dir.$item['autoload']);
     68                    require $dir.$item['autoload'];
    6969                }
    7070            }
    71             return false;
    7271        });
    7372    }
  • torque/trunk/packages/cssdoc/config.php

    r2939649 r3012051  
    99     */
    1010    protected array $config = [
    11         'nested' => ['@media', '@supports', '@keyframes', '@-webkit-keyframes', '@-moz-keyframes', '@-o-keyframes', '@document', '@-moz-document', '@container'], // directive that can have nested rules
     11        'nested' => ['@media', '@supports', '@keyframes', '@-webkit-keyframes', '@-moz-keyframes', '@-o-keyframes', '@document', '@-moz-document', '@container', '@layer'], // directive that can have nested rules
    1212        'spaced' => ['calc', 'min', 'max', 'clamp'], // values where spaces between operators must be retained
    1313        'quoted' => ['content', 'format', 'counters', '@charset', 'syntax', 'font-feature-settings', '-webkit-font-feature-settings', '-moz-font-feature-settings', 'quotes', 'text-overflow'], // directives or properties where the contained values must be quoted
  • torque/trunk/packages/cssdoc/tokens/directive.php

    r2912478 r3012051  
    3030     */
    3131    public ?document $document = null;
     32
     33    /**
     34     * @var bool Whether the object has an empty body
     35     */
     36    public bool $empty = false;
    3237
    3338    /**
     
    7782                            if ($item->parse($tokens)) {
    7883                                $this->document = $item;
     84                            } else {
     85                                $this->empty = true;
    7986                            }
    8087                        } else {
     
    130137    public function isEmpty() : bool {
    131138        if (\in_array($this->directive, $this->root->config['nested'], true)) {
    132             return $this->document === null;
     139            return $this->document === null && $this->empty;
    133140        } else {
    134             return !$this->properties && !$this->content;
     141            return empty($this->properties) && empty($this->content);
    135142        }
    136143    }
  • torque/trunk/packages/htmldoc/config.php

    r2615373 r3012051  
    3636            'elements' => [
    3737                'inline' => [
    38                     'b', 'u', 'big', 'i', 'small', 'ttspan', 'em', 'a', 'strong', 'sub', 'sup', 'abbr', 'acronym', 'cite', 'code', 'dfn', 'em', 'kbd', 'strong', 'samp', 'var', 'span'
     38                    'b', 'u', 'big', 'i', 'small', 'ttspan', 'em', 'a', 'strong', 'sub', 'sup', 'abbr', 'acronym', 'cite', 'code', 'dfn', 'em', 'kbd', 'strong', 'samp', 'var', 'span', 's'
    3939                ],
    4040                'singleton' => [
  • torque/trunk/packages/htmldoc/tokens/custom.php

    r2817597 r3012051  
    8181                        $dir = \dirname($file);
    8282                        if (!\is_dir($dir)) {
    83                             \mkdir($dir, 0755);
     83                            \mkdir($dir, 0755, true);
    8484                        }
    8585                        \file_put_contents($file, $content);
  • torque/trunk/packages/htmldoc/tokens/tag.php

    r2912478 r3012051  
    347347    protected function getIndex() : ?int {
    348348        if ($this->parent) {
    349             foreach ($this->parent->children() AS $key => $item) {
     349            foreach ($this->parent->children AS $key => $item) {
    350350                if ($item === $this) {
    351351                    return $key;
     
    431431
    432432                // make folder variables
    433                 if ($folder === null && isset($_SERVER['REQUEST_URI'])) {
    434                     if (($folder = \parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)) !== null) {
     433                if ($folder === null && isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) {
     434                    if (($folder = \parse_url('//'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], PHP_URL_PATH)) !== null) {
    435435                        if (\mb_substr($folder, -1) !== '/') {
    436436                            $folder = \dirname($folder).'/';
  • torque/trunk/readme.txt

    r2939649 r3012051  
    22Contributors: hexydec
    33Tags: minify,minification,performance,security,optimization
    4 Requires at least:
    5 Tested up to: 6.2
     4Requires at least: 6.0
     5Tested up to: 6.4.2
    66Requires PHP: 8.0
    7 Stable tag: 0.7.3
     7Stable tag: 0.7.4
    88License: GPLv3
    99License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
     
    129129== Changelog ==
    130130
     131= Version 0.7.4 =
     132
     133* The name of the app is not title case when Console Logging in app::drawStats()
     134* Used PHP 8.0 property type definitions, and union return types where needed
     135* Updated require calls in autoloaders to be used as a keyword and for the spl_autoload_register() call not to return a value
     136* Fixed issue in csp::recommendations() where if the recommended URL was the base URL of the site, it should use 'self` instead
     137* The minimum supported PHP version is now 8.0
     138* Updated packages to latest versions
     139
    131140= Version 0.7.3 =
    132141
  • torque/trunk/torque.php

    r2939649 r3012051  
    2121
    2222// activate the plugin
    23 \register_activation_hook(__FILE__, function () {
     23\register_activation_hook(__FILE__, function () : void {
    2424
    2525    // from GitHub, download packages
     
    3535
    3636// install the admin menu
    37 \add_action('admin_menu', function () {
     37\add_action('admin_menu', function () : void {
    3838    $obj = new admin();
    3939    $obj->update();
     
    4242
    4343// load the app
    44 \add_action('wp_loaded', function () {
     44\add_action('wp_loaded', function () : void {
    4545    $obj = new app();
    4646    $obj->optimise();
     
    5151
    5252// rebuild files when a plugin is updated
    53 \add_action('upgrader_process_complete', function () {
     53\add_action('upgrader_process_complete', function () : void {
    5454    assets::rebuildAssets();
    5555});
     
    5757// add rebuild command
    5858if (\class_exists('WP_CLI')) {
    59     \WP_CLI::add_command('torque rebuild', function () {
     59    \WP_CLI::add_command('torque rebuild', function () : bool {
    6060        return \hexydec\torque\assets::rebuildAssets();
    6161    }, [
Note: See TracChangeset for help on using the changeset viewer.