Plugin Directory

Changeset 2817597


Ignore:
Timestamp:
11/14/2022 10:41:38 AM (3 years ago)
Author:
hexydec
Message:

Tested with Wordpress v6.1.
Fixed bug in Content-Security-Policy generator where a directive was not spelt correctly.
Updated dependencies.
Minor syntax improvements.
Bumped version to 0.6.5.

Location:
torque/trunk
Files:
35 edited

Legend:

Unmodified
Added
Removed
  • torque/trunk/app.php

    r2727595 r2817597  
    311311    protected function getContentSecurityPolicy(array $config) : ?string {
    312312        $fields = [
    313             'default' => 'default',
     313            'default' => 'default-src',
    314314            'style' => 'style-src',
    315315            'script' => 'script-src',
  • torque/trunk/assets.php

    r2658195 r2817597  
    256256
    257257            // create the directory if it doesn't exist
    258             $dir =  \dirname($target);
     258            $dir = \dirname($target);
    259259            if (!\is_dir($dir)) {
    260260                \mkdir($dir, 0755);
  • torque/trunk/packages.php

    r2727595 r2817597  
    1717     * @var string VERSION The version number of the application, this is used in the cache key for CSS/Javascript that is minified
    1818     */
    19     public const VERSION = '0.6.3';
     19    public const VERSION = '0.6.4';
    2020
    2121    /**
  • torque/trunk/packages/cssdoc/autoload.php

    r2592945 r2817597  
    11<?php
    2 spl_autoload_register(function (string $class) : bool {
     2declare(strict_types = 1);
     3\spl_autoload_register(function (string $class) : void {
    34    $classes = [
    45        'hexydec\\css\\cssdoc' => __DIR__.'/cssdoc.php',
     
    1112    ];
    1213    if (isset($classes[$class])) {
    13         return (bool) require($classes[$class]);
     14        require($classes[$class]);
    1415    }
    15     return false;
    1616});
  • torque/trunk/packages/cssdoc/cssdoc.php

    r2727595 r2817597  
    77
    88    /**
    9      * @var array $tokens Regexp components keyed by their corresponding codename for tokenising HTML
     9     * @var array<string> $tokens Regexp components keyed by their corresponding codename for tokenising HTML
    1010     */
    1111    protected static array $tokens = [
     
    3131
    3232    /**
    33      * @var array $config Object configuration array
     33     * @var array<array> $config Object configuration array
    3434     */
    3535    protected array $config = [
     
    8383            'mediumvioletred' => '#c71585',
    8484            'palevioletred' => '#db7093',
    85             'lightsalmon' => '#ffa07a',
    8685            'orangered' => '#ff4500',
    8786            'darkorange' => '#ff8c00',
     
    143142            'dodgerblue' => '#1e90ff',
    144143            'cornflowerblue' => '#6495ed',
    145             'mediumslateblue' => '#7b68ee',
    146144            'royalblue' => '#4169e1',
    147145            'mediumblue' => '#0000cd',
     
    202200
    203201    /**
    204      * @var document $document The root document
    205      */
    206     protected document $document;
     202     * @var ?document $document The root document
     203     */
     204    public ?document $document = null;
    207205
    208206    /**
     
    231229    public function __get(string $var) {
    232230        if ($var === 'length') {
    233             return \count($this->children);
     231            return \count($this->document->rules ?? []);
    234232        } elseif ($var === 'config') {
    235233            return $this->config;
     
    244242     */
    245243    public function toArray() : array {
    246         return $this->document->rules;
     244        return $this->document->rules ?? [];
    247245    }
    248246
     
    250248     * Array access method allows you to set the object's configuration as properties
    251249     *
    252      * @param string|integer $i The key to be updated, can be a string or integer
     250     * @param mixed $i The key to be updated, can be a string or integer
    253251     * @param mixed $value The value of the array key in the children array to be updated
    254252     */
     
    304302     * Retrieve the the current pointer position for the object
    305303     *
    306      * @return scalar The current pointer position
    307      */
    308     public function key() : int {
     304     * @return mixed The current pointer position
     305     */
     306    #[\ReturnTypeWillChange]
     307    public function key() : mixed {
    309308        return $this->pointer;
    310309    }
     
    342341     * @param string $url The address of the HTML file to retrieve
    343342     * @param resource $context A resource object made with stream_context_create()
    344      * @param string &$error A reference to any user error that is generated
     343     * @param ?string &$error A reference to any user error that is generated
    345344     * @return mixed The loaded HTML, or false on error
    346345     */
    347     public function open(string $url, mixed $context = null, string &$error = null) {
     346    public function open(string $url, mixed $context = null, ?string &$error = null) {
    348347
    349348        // check resource
     
    387386     * @param string $css A string containing valid CSS
    388387     * @param string $charset The charset of the document
    389      * @param string &$error A reference to any user error that is generated
     388     * @param ?string &$error A reference to any user error that is generated
    390389     * @return bool Whether the input HTML was parsed
    391390     */
    392     public function load(string $css, string $charset = null, &$error = null) : bool {
     391    public function load(string $css, string $charset = null, ?string &$error = null) : bool {
    393392
    394393        // detect the charset
     
    398397
    399398        // reset the document
    400         $this->children = [];
     399        $this->document = null;
    401400        if (($obj = $this->parse($css)) === false) {
    402401            $error = 'Input is not invalid';
     
    413412     * Reads the charset defined in the Content-Type meta tag, or detects the charset from the HTML content
    414413     *
    415      * @param string $html A string containing valid HTML
    416      * @return string The defined or detected charset or null if the charset is not defined
     414     * @param string $css A string containing valid CSS
     415     * @return ?string The defined or detected charset or null if the charset is not defined
    417416     */
    418417    protected function getCharsetFromCss(string $css) : ?string {
  • torque/trunk/packages/cssdoc/tokens/directive.php

    r2693063 r2817597  
    4444     *
    4545     * @param tokenise &$tokens A tokenise object
    46      * @param array $config An array of configuration options
    4746     * @return bool Whether anything was parsed
    4847     */
     
    142141     *
    143142     * @param array $options An array of compilation options
    144      * @return void
     143     * @return string The compiled CSS
    145144     */
    146145    public function compile(array $options) : string {
  • torque/trunk/packages/cssdoc/tokens/document.php

    r2727595 r2817597  
    2323    public function __construct(cssdoc $root, array $rules = []) {
    2424        $this->root = $root;
    25         $this->rules = [];
     25        $this->rules = $rules;
    2626    }
    2727
     
    3030     *
    3131     * @param tokenise &$tokens A tokenise object
    32      * @param array $config An array of configuration options
    3332     * @return bool Whether anything was parsed
    3433     */
     
    9998     * Find rules in the document that match the specified criteria
    10099     *
    101      * @param string $selector A string specifying the selectors to match, comma separate multiple selectors
     100     * @param ?array $selectors A string specifying the selectors to match, comma separate multiple selectors
    102101     * @param array|string $hasProp A string or array specifying the properties that any rules must contain
    103102     * @param array $media An array specifying how any media queries should be match, where the key is the property and the key the value. 'max-width' will match any rules where the value is lower that that specified, 'min-width' the value must be higher. Use 'media' to specify the media type
  • torque/trunk/packages/cssdoc/tokens/property.php

    r2693063 r2817597  
    4949     *
    5050     * @param string $var The name of the property to retrieve
    51      * @return string The value of the requested property, or null if the porperty doesn't exist
     51     * @return ?string The value of the requested property, or null if the porperty doesn't exist
    5252     */
    5353    public function __get(string $var) {
     
    127127     *
    128128     * @param array $options An array of compilation options
    129      * @return void
     129     * @return string The compiled CSS property
    130130     */
    131131    public function compile(array $options) : string {
  • torque/trunk/packages/cssdoc/tokens/rule.php

    r2727595 r2817597  
    3939     *
    4040     * @param tokenise &$tokens A tokenise object
    41      * @param array $config An array of configuration options
    4241     * @return bool Whether anything was parsed
    4342     */
     
    112111     *
    113112     * @param array $options An array of compilation options
    114      * @return void
     113     * @return string The compiled CSS rule
    115114     */
    116115    public function compile(array $options) : string {
  • torque/trunk/packages/cssdoc/tokens/selector.php

    r2727595 r2817597  
    2929     *
    3030     * @param tokenise &$tokens A tokenise object
    31      * @param array $config An array of configuration options
    3231     * @return bool Whether anything was parsed
    3332     */
     
    162161     *
    163162     * @param array $options An array of compilation options
    164      * @return void
     163     * @return string The compiled CSS selector
    165164     */
    166165    public function compile(array $options) : string {
  • torque/trunk/packages/cssdoc/tokens/value.php

    r2727595 r2817597  
    4444     *
    4545     * @param tokenise &$tokens A tokenise object
    46      * @param array $config An array of configuration options
    4746     * @return bool Whether anything was parsed
    4847     */
     
    246245     *
    247246     * @param array $options An array of compilation options
    248      * @return void
     247     * @return string The compiled CSS value
    249248     */
    250249    public function compile(array $options) : string {
  • torque/trunk/packages/htmldoc/autoload.php

    r2711273 r2817597  
    11<?php
    2 spl_autoload_register(function (string $class) : bool {
     2\spl_autoload_register(function (string $class) : void {
    33    $classes = [
    44        'hexydec\\html\\htmldoc' => __DIR__.'/htmldoc.php',
     
    1515    ];
    1616    if (isset($classes[$class])) {
    17         return (bool) require($classes[$class]);
     17        require($classes[$class]);
    1818    }
    19     return false;
    2019});
  • torque/trunk/packages/htmldoc/helpers/selector.php

    r2711273 r2817597  
    77
    88    /**
    9      * @var array $selectors Regexp components keyed by their corresponding codename for tokenising CSS selectors
     9     * @var array<string> $selectors Regexp components keyed by their corresponding codename for tokenising CSS selectors
    1010     */
    1111    protected static array $tokens = [
    1212        'quotes' => '(?<!\\\\)"(?:[^"\\\\]++|\\\\.)*+"',
     13        'comparison' => '[\\^*$<>|~]?=', // comparison operators for media queries or attribute selectors
    1314        'join' => '\\s*[>+~]\\s*',
    14         'comparison' => '[\\^*$<>]?=', // comparison operators for media queries or attribute selectors
    1515        'squareopen' => '\\[',
    1616        'squareclose' => '\\]',
     
    2121        'id' => '#[^ +>\.#{\\[,]++',
    2222        'class' => '\.[^ +>\.#{\\[\\(\\),]++',
    23         'string' => '\\*|[^\\[\\]{}\\(\\):;,>+=~\\^$!" #\\.*]++',
     23        'string' => '\\*|[^\\[\\]{}\\(\\):;,>+=~|\\^$!" #\\.*]++',
    2424        'whitespace' => '\s++',
    2525    ];
    2626
     27    /**
     28     * Get a selector string parsed into an array
     29     *
     30     * @param string $selector The CSS selector string to parse
     31     * @return array|false An array of selector components or false if the selector was not parsable
     32     */
    2733    public function get(string $selector) {
    2834        $tokens = new tokenise(self::$tokens, \trim($selector));
     
    3339     * Parses a CSS selector string
    3440     *
    35      * @param string $selector The CSS selector string to parse
     41     * @param tokenise $tokens A tokenise object loaded with the selector to parse
    3642     * @return array|bool An array of selector components
    3743     */
     
    115121    }
    116122
    117     protected function parseAttributes(tokenise $tokens, ?string $join = null) {
     123    /**
     124     * Parses the attributes of a CSS selector
     125     *
     126     * @param tokenise $tokens A tokenise object loaded with the selector to be parsed
     127     * @param ?string $join The joining command from the last CSS selector component
     128     * @return array An array representing the attribute
     129     */
     130    protected function parseAttributes(tokenise $tokens, ?string $join = null) : array {
    118131        $item = ['join' => $join, 'sensitive' => true];
    119132        while (($token = $tokens->next()) !== null && $token['type'] !== 'squareclose') {
  • torque/trunk/packages/htmldoc/htmldoc.php

    r2727595 r2817597  
    150150     * Retrieve the the current pointer position for the object
    151151     *
    152      * @return scalar The current pointer position
    153      */
    154     public function key() : int {
     152     * @return mixed The current pointer position
     153     */
     154    #[\ReturnTypeWillChange]
     155    public function key() {
    155156        return $this->pointer;
    156157    }
     
    188189     * @param string $url The address of the HTML file to retrieve
    189190     * @param resource $context A resource object made with stream_context_create()
    190      * @param string &$error A reference to any user error that is generated
     191     * @param ?string &$error A reference to any user error that is generated
    191192     * @return string|false The loaded HTML, or false on error
    192193     */
    193     public function open(string $url, $context = null, string &$error = null) {
     194    public function open(string $url, $context = null, ?string &$error = null) {
    194195
    195196        // check resource
     
    231232     * @param string $html A string containing valid HTML
    232233     * @param string $charset The charset of the document
    233      * @param string &$error A reference to any user error that is generated
     234     * @param ?string &$error A reference to any user error that is generated
    234235     * @return bool Whether the input HTML was parsed
    235236     */
    236     public function load(string $html, string $charset = null, &$error = null) : bool {
     237    public function load(string $html, string $charset = null, ?string &$error = null) : bool {
    237238
    238239        // detect the charset
  • torque/trunk/packages/htmldoc/tokens/comment.php

    r2711273 r2817597  
    2121
    2222    /**
    23      * Parses an array of tokens into an HTML documents
     23     * Parses the next HTML component from a tokenise object
    2424     *
    25      * @param array &$tokens An array of tokens generated by tokenise()
    26      * @param array $config An array of configuration options
     25     * @param tokenise $tokens A tokenise object
    2726     * @return void
    2827     */
  • torque/trunk/packages/htmldoc/tokens/custom.php

    r2711273 r2817597  
    2525     *
    2626     * @param htmldoc $root The parent htmldoc object
    27      * @param string $tag The name of the custom tag, note this cannot be null
     27     * @param string $tagName A string specifying the parent tag name
    2828     */
    29     public function __construct(htmldoc $root, string $tagName = null) {
     29    public function __construct(htmldoc $root, ?string $tagName = null) {
    3030        $this->tagName = $tagName = \mb_strtolower($tagName ?? '');
    3131        $this->config = $root->config['custom'][$tagName];
     
    3333
    3434    /**
    35      * Parses an array of tokens into an HTML documents
     35     * Parses the next HTML component from a tokenise object
    3636     *
    37      * @param array &$tokens An array of tokens generated by tokenise()
    38      * @param array $config An array of configuration options
     37     * @param tokenise $tokens A tokenise object
    3938     * @return void
    4039     */
  • torque/trunk/packages/htmldoc/tokens/doctype.php

    r2693063 r2817597  
    2121
    2222    /**
    23      * Parses an array of tokens into an HTML documents
     23     * Parses the next HTML component from a tokenise object
    2424     *
    25      * @param array &$tokens An array of tokens generated by tokenise()
    26      * @param array $config An array of configuration options
     25     * @param tokenise $tokens A tokenise object
    2726     * @return void
    2827     */
  • torque/trunk/packages/htmldoc/tokens/interfaces/token.php

    r2592945 r2817597  
    1717
    1818    /**
    19      * Parses an array of tokens into an HTML documents
     19     * Parses the next HTML component from a tokenise object
    2020     *
    21      * @param array &$tokens An array of tokens generated by tokenise()
    22      * @param array $config An array of configuration options
     21     * @param tokenise $tokens A tokenise object
    2322     * @return void
    2423     */
  • torque/trunk/packages/htmldoc/tokens/tag.php

    r2727628 r2817597  
    103103
    104104    /**
    105      * Parses an array of tokens into an HTML documents
    106      *
    107      * @param tokenise &$tokens An array of tokens generated by tokenise()
    108      * @param array $config An array of configuration options
     105     * Parses the next HTML component from a tokenise object
     106     *
     107     * @param tokenise $tokens A tokenise object
    109108     * @return void
    110109     */
     
    218217     *
    219218     * @param tokenise &$tokens A reference to an array of tokens generated by tokenise(), the reference allows the array pointer to pass between objectsS
    220      * @return bool Whether the parser was able to capture any objects
     219     * @return array An array of child objects
    221220     */
    222221    public function parseChildren(tokenise $tokens) : array {
     
    384383     * Remove the selected child from the object
    385384     *
    386      * @param tag $child The child object to delete
     385     * @param tag $node The child object to delete
    387386     * @return void
    388387     */
     
    630629     *
    631630     * @param array $selector An array of CSS selectors
    632      * @param array $searchChildren Denotes whether to search child tags as well as this tag
     631     * @param bool $searchChildren Denotes whether to search child tags as well as this tag
    633632     * @return array An array of tag objects that match $selector
    634633     */
     
    678677
    679678                // check if attribute exists
    680                 if (empty($this->attributes[$item['attribute']])) {
     679                if (!array_key_exists($item['attribute'], $this->attributes)) {
    681680                    $match = false;
    682681                    break;
    683682                } elseif (!empty($item['value'])) {
    684                     $current = $this->attributes[$item['attribute']];
    685                     switch ($item['comparison']) {
    686 
    687                         // exact match
    688                         case '=':
    689                             if ($item['sensitive']) {
    690                                 if ($current !== $item['value']) {
     683
     684                    // if current value is null, it won't match
     685                    if (($current = $this->attributes[$item['attribute']]) === null) {
     686                        $match = false;
     687                        break;
     688
     689                    // compare
     690                    } else {
     691                        switch ($item['comparison']) {
     692
     693                            // exact match
     694                            case '=':
     695                                if ($item['sensitive']) {
     696                                    if ($current !== $item['value']) {
     697                                        $match = false;
     698                                        break;
     699                                    }
     700                                } elseif (\mb_strtolower($current) !== \mb_strtolower($item['value'])) {
    691701                                    $match = false;
    692702                                    break;
    693703                                }
    694                             } elseif (\mb_strtolower($current) !== \mb_strtolower($item['value'])) {
    695                                 $match = false;
    696704                                break;
    697                             }
    698                             break;
    699 
    700                         // match start
    701                         case '^=':
    702                             if ($item['sensitive']) {
    703                                 if (\mb_strpos($current, $item['value']) !== 0) {
     705
     706                            // match start
     707                            case '^=':
     708                                $pos = $item['sensitive'] ? \mb_strpos($current, $item['value']) : \mb_stripos($current, $item['value']);
     709                                if ($pos !== 0) {
    704710                                    $match = false;
    705711                                    break;
    706712                                }
    707                             } elseif (\mb_stripos($current, $item['value']) !== 0) {
    708                                 $match = false;
    709713                                break;
    710                             }
    711                             break;
    712 
    713                         // match within
    714                         case '*=':
    715                             if ($item['sensitive']) {
    716                                 if (\mb_strpos($current, $item['value']) === false) {
     714
     715                            // match word
     716                            case '~=':
     717                                $current =' '.$current.' ';
     718                                $item['value'] = ' '.$item['value'].' ';
     719
     720                            // match within
     721                            case '*=':
     722                                $pos = $item['sensitive'] ? \mb_strpos($current, $item['value']) : \mb_stripos($current, $item['value']);
     723                                if ($pos === false) {
    717724                                    $match = false;
    718725                                    break;
    719726                                }
    720                             } elseif (\mb_stripos($current, $item['value']) === false) {
    721                                 $match = false;
    722727                                break;
    723                             }
    724                             break;
    725 
    726                         // match end
    727                         case '$=':
    728                             if ($item['sensitive']) {
    729                                 if (\mb_strpos($current, $item['value']) !== \mb_strlen($current) - \mb_strlen($item['value'])) {
     728
     729                            // match end
     730                            case '$=':
     731                                $pos = $item['sensitive'] ? \mb_strrpos($current, $item['value']) : \mb_strripos($current, $item['value']);
     732                                if ($pos !== \mb_strlen($current) - \mb_strlen($item['value'])) {
    730733                                    $match = false;
    731734                                    break;
    732735                                }
    733                             } elseif (\mb_stripos($current, $item['value']) !== \mb_strlen($current) - \mb_strlen($item['value'])) {
    734                                 $match = false;
    735736                                break;
    736                             }
    737                             break;
     737
     738                            // match subcode
     739                            case '|=':
     740                                if ($item['sensitive']) {
     741                                    if ($current !== $item['value'] && \mb_strpos($current, $item['value'].'-') !== 0) {
     742                                        $match = false;
     743                                        break;
     744                                    }
     745                                } elseif (\mb_strtolower($current) !== \mb_strtolower($item['value']) && \mb_stripos($current, $item['value'].'-') !== 0) {
     746                                    $match = false;
     747                                    break;
     748                                }
     749                                break;
     750                        }
    738751                    }
    739752                }
  • torque/trunk/packages/htmldoc/tokens/text.php

    r2711273 r2817597  
    3333
    3434    /**
    35      * Parses an array of tokens into an HTML documents
     35     * Magic method to set protected variables
    3636     *
    37      * @param array &$tokens An array of tokens generated by tokenise()
    38      * @param array $config An array of configuration options
     37     * @param string $name The name of the property to set
     38     * @param mixed $value The value of the property to set
     39     * @return void
     40     */
     41    public function __set(string $name, $value) : void {
     42        if ($name === 'parent' && \get_class($value) === 'hexydec\\html\\tag') {
     43            $this->parent = $value;
     44        }
     45    }
     46
     47    /**
     48     * Parses the next HTML component from a tokenise object
     49     *
     50     * @param tokenise $tokens A tokenise object
    3951     * @return void
    4052     */
  • torque/trunk/packages/jslite/autoload.php

    r2592945 r2817597  
    11<?php
    2 spl_autoload_register(function (string $class) : bool {
     2\spl_autoload_register(function (string $class) : void {
    33    $classes = [
    44        'hexydec\\jslite\\jslite' => __DIR__.'/jslite.php',
     
    1616    ];
    1717    if (isset($classes[$class])) {
    18         return (bool) require($classes[$class]);
     18        require($classes[$class]);
    1919    }
    20     return false;
    2120});
  • torque/trunk/packages/jslite/jslite.php

    r2727595 r2817597  
    2323
    2424        // keywords number and variables
    25         'keyword' => '\\b(?:let|break|case|catch|class|const|continue|debugger|default|delete|do|else|export|extends|finally|for|function|if|import|in|instanceof|new|return|super|switch|this|throw|try|typeof|var|void|while|with|yield|null|async|await|true|false|undefined)\\b',
     25        'keyword' => '\\b(?:let|break|case|catch|class|const|continue|debugger|default|delete|do|else|export|extends|finally|for|function|if|import|in|of|instanceof|new|return|super|switch|this|throw|try|typeof|var|void|while|with|yield|null|async|await|true|false|undefined)\\b',
    2626        'variable' => '[\\p{L}\\p{Nl}$_][\\p{L}\\p{Nl}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}$_]*+',
    2727        'number' => '(?:0[bB][01_]++n?|0[oO][0-7_]++n?|0[xX][a-f0-9_]|[0-9][0-9_]*+(?:\\.[0-9_]++)?+(?:e[+-]?[1-9][0-9]*+)?+)',
    2828
    2929        // consume strings in quotes, check for escaped quotes
    30         'doublequotes' => '"(?:\\\\[^\\n\\r]|[^\\\\"\\n\\r])*+"',
    31         'singlequotes' => "'(?:\\\\[^\\n\\r]|[^\\\\'\\n\\r])*+'",
     30        'doublequotes' => '"(?:\\\\.|[^\\\\"])*+"',
     31        'singlequotes' => "'(?:\\\\.|[^\\\\'])*+'",
    3232        'templateliterals' => '`(?:\\\\.|[^\\\\`])*+`',
    3333
     
    8888     * @param string $url The address of the Javascript file to retrieve
    8989     * @param resource $context A resource object made with stream_context_create()
    90      * @param string &$error A reference to any user error that is generated
     90     * @param ?string &$error A reference to any user error that is generated
    9191     * @return string|false The loaded Javascript, or false on error
    9292     */
    93     public function open(string $url, $context = null, string &$error = null) {
     93    public function open(string $url, $context = null, ?string &$error = null) {
    9494
    9595        // check resource
     
    112112     *
    113113     * @param string $js A string containing valid Javascript
    114      * @param string &$error A reference to any user error that is generated
     114     * @param ?string &$error A reference to any user error that is generated
    115115     * @return bool Whether the input HTML was parsed
    116116     */
    117     public function load(string $js, string &$error = null) : bool {
     117    public function load(string $js, ?string &$error = null) : bool {
    118118
    119119        // reset the document
     
    189189     *
    190190     * @param array $options An array indicating output options
    191      * @return void
     191     * @return string The compiled Javascript
    192192     */
    193193    public function compile(array $options = []) : string {
  • torque/trunk/packages/jslite/tokens/brackets.php

    r2693063 r2817597  
    66class brackets {
    77
     8    /**
     9     * @var bool Denotes whether the class represents significant javascript
     10     */
    811    public const significant = true;
     12
     13    /**
     14     * @var expression The parent expression object
     15     */
    916    protected expression $root;
     17
     18    /**
     19     * @var array An array of child expression objects
     20     */
    1021    protected array $expressions = [];
     22
     23    /**
     24     * @var string The type of bracket this object represents, bracket|square|curly
     25     */
    1126    public string $bracket = 'bracket'; // square or bracket or curly
    1227
     
    1429     * Constructs the comment object
    1530     *
    16      * @param jslite $root The parent jslite object
    17      * @param array $scopes An array of variables that are available in this scope, where the key is the variable name and the value is the scope object
     31     * @param expression $root The parent expression object
    1832     */
    1933    public function __construct(expression $root) {
     
    2438     * Parses an array of tokens
    2539     *
    26      * @param array &$tokens A tokenise object
    27      * @return void
     40     * @param tokenise $tokens A tokenise object
     41     * @return bool Whether any tokens were parsed
    2842     */
    2943    public function parse(tokenise $tokens) : bool {
  • torque/trunk/packages/jslite/tokens/comment.php

    r2693063 r2817597  
    66class comment {
    77
     8    /**
     9     * @var bool Denotes whether the class represents significant javascript
     10     */
    811    public const significant = false;
     12
    913    /**
    1014     * @var string The text content of this object
    1115     */
    1216    protected ?string $content = null;
     17
     18    /**
     19     * @var bool Denotes whether the comment object represents a single or multi-line comment
     20     */
    1321    protected bool $multi = false;
    1422
     
    1624     * Parses an array of tokens
    1725     *
    18      * @param array &$tokens A tokenise object
    19      * @return void
     26     * @param tokenise $tokens A tokenise object
     27     * @return bool Whether there were any tokens to parse
    2028     */
    2129    public function parse(tokenise $tokens) : bool {
  • torque/trunk/packages/jslite/tokens/expression.php

    r2727595 r2817597  
    66class expression {
    77
     8    /**
     9     * @var bool Denotes whether the class represents significant javascript
     10     */
    811    public const significant = true;
     12
     13    /**
     14     * @var array An array of command objects stored within this expression
     15     */
    916    public array $commands = [];
     17
     18    /**
     19     * @var ?string The end of line marker
     20     */
    1021    public ?string $eol = null;
     22
     23    /**
     24     * @var ?string The type of bracket of the parent
     25     */
    1126    public ?string $bracket = null;
    1227
     28    /**
     29     * Constructs the expression object
     30     *
     31     * @param ?string $bracket The type of bracket of the parent
     32     */
    1333    public function __construct(?string $bracket = null) {
    1434        $this->bracket = $bracket;
     
    3151                    case 'commentsingle':
    3252                    case 'commentmulti':
    33                         $obj = new comment($this);
     53                        $obj = new comment();
    3454                        if ($obj->parse($tokens)) {
    3555                            $commands[] = $obj;
     
    3757                        break;
    3858                    case 'operator':
    39                         $obj = new operator($this);
     59                        $obj = new operator();
    4060                        if ($obj->parse($tokens)) {
    4161                            $commands[] = $obj;
     
    4666                        break;
    4767                    case 'increment':
    48                         $obj = new increment($this);
     68                        $obj = new increment();
    4969                        if ($obj->parse($tokens)) {
    5070                            $commands[] = $obj;
     
    5373                    case 'keyword':
    5474                        if ($this->isKeyword($last, $token, $tokens)) {
    55                             $obj = new keyword($this);
     75                            $obj = new keyword();
    5676                            if ($obj->parse($tokens)) {
    5777                                $commands[] = $obj;
     
    6080                        }
    6181                    case 'variable':
    62                         $obj = new variable($this);
     82                        $obj = new variable();
    6383                        if ($obj->parse($tokens)) {
    6484                            $commands[] = $obj;
     
    6686                        break;
    6787                    case 'number':
    68                         $obj = new number($this);
     88                        $obj = new number();
    6989                        if ($obj->parse($tokens)) {
    7090                            $commands[] = $obj;
     
    7494                    case 'singlequotes':
    7595                    case 'templateliterals':
    76                         $obj = new jsstring($this);
     96                        $obj = new jsstring();
    7797                        if ($obj->parse($tokens)) {
    7898                            $commands[] = $obj;
     
    85105
    86106                            // create regexp object
    87                             $obj = new regexp($this);
     107                            $obj = new regexp();
    88108                            if ($obj->parse($tokens)) {
    89109                                $commands[] = $obj;
  • torque/trunk/packages/jslite/tokens/keyword.php

    r2693063 r2817597  
    66class keyword {
    77
     8    /**
     9     * @var bool Denotes whether the class represents significant javascript
     10     */
    811    public const significant = true;
     12
     13    /**
     14     * @var string The captured keyword
     15     */
    916    public string $content = '';
    1017
     
    1219     * Parses an array of tokens
    1320     *
    14      * @param array &$tokens A tokenise object
    15      * @return void
     21     * @param tokenise $tokens A tokenise object
     22     * @return bool Whether any tokens were parsed
    1623     */
    1724    public function parse(tokenise $tokens) : bool {
  • torque/trunk/packages/jslite/tokens/number.php

    r2693063 r2817597  
    66class number {
    77
     8    /**
     9     * @var bool Denotes whether the class represents significant javascript
     10     */
    811    public const significant = true;
     12
     13    /**
     14     * @var string The captured number
     15     */
    916    protected string $content = '';
    1017
     
    1219     * Parses an array of tokens
    1320     *
    14      * @param array &$tokens A tokenise object
    15      * @return void
     21     * @param tokenise $tokens A tokenise object
     22     * @return bool Whether any tokens were parsed
    1623     */
    1724    public function parse(tokenise $tokens) : bool {
  • torque/trunk/packages/jslite/tokens/operator.php

    r2693063 r2817597  
    66class operator {
    77
     8    /**
     9     * @var bool Denotes whether the class represents significant javascript
     10     */
    811    public const significant = true;
     12
    913    /**
    1014     * @var string The text content of this object
     
    1519     * Parses an array of tokens
    1620     *
    17      * @param array &$tokens A tokenise object
    18      * @return void
     21     * @param tokenise $tokens A tokenise object
     22     * @return bool Whether any tokens were parsed
    1923     */
    2024    public function parse(tokenise $tokens) : bool {
  • torque/trunk/packages/jslite/tokens/regexp.php

    r2693063 r2817597  
    66class regexp {
    77
     8    /**
     9     * @var bool Denotes whether the class represents significant javascript
     10     */
    811    public const significant = true;
     12
     13    /**
     14     * @var string The captured regexp pattern
     15     */
    916    protected string $content = '';
    1017
     
    1219     * Parses an array of tokens
    1320     *
    14      * @param array &$tokens A tokenise object
    15      * @return void
     21     * @param tokenise $tokens A tokenise object
     22     * @return bool Whether any tokens were parsed
    1623     */
    1724    public function parse(tokenise $tokens) : bool {
  • torque/trunk/packages/jslite/tokens/string.php

    r2693063 r2817597  
    66class jsstring {
    77
     8    /**
     9     * @var bool Denotes whether the class represents significant javascript
     10     */
    811    public const significant = true;
     12
     13    /**
     14     * @var string The captured string
     15     */
    916    public string $content = '';
     17
     18    /**
     19     * @var string The quote character used to encapsulate the string
     20     */
    1021    protected string $quote = '"';
     22
     23    /**
     24     * @var bool Whether the string has been de-encapsulated and processed
     25     */
    1126    protected bool $process = false;
    1227
     
    1429     * Parses an array of tokens
    1530     *
    16      * @param array &$tokens A tokenise object
    17      * @return void
     31     * @param tokenise $tokens A tokenise object
     32     * @return bool Whether any tokens were parsed
    1833     */
    1934    public function parse(tokenise $tokens) : bool {
  • torque/trunk/packages/jslite/tokens/variable.php

    r2693063 r2817597  
    66class variable {
    77
     8    /**
     9     * @var bool Denotes whether the class represents significant javascript
     10     */
    811    public const significant = true;
     12
     13    /**
     14     * @var string The captured variable name
     15     */
    916    public string $content = '';
    1017
     
    1219     * Parses an array of tokens
    1320     *
    14      * @param array &$tokens A tokenise object
    15      * @return void
     21     * @param tokenise $tokens A tokenise object
     22     * @return bool Whether any tokens were parsed
    1623     */
    1724    public function parse(tokenise $tokens) : bool {
     
    3542     * Compile as Javascript
    3643     *
    37      * @return string The compiled HTML
     44     * @return string The compiled variable name
    3845     */
    3946    public function compile() : string {
  • torque/trunk/packages/jslite/tokens/whitespace.php

    r2693063 r2817597  
    66class whitespace {
    77
     8    /**
     9     * @var bool Denotes whether the class represents significant javascript
     10     */
    811    public const significant = false;
     12
     13    /**
     14     * @var expression The parent expression object
     15     */
    916    protected expression $parent;
     17
     18    /**
     19     * @var string The captured whitespace
     20     */
    1021    protected string $content;
    1122
     
    1425     *
    1526     * @param expression $parent The parent expression object
    16      * @param array $scopes An array of variables that are available in this scope, where the key is the variable name and the value is the scope object
    1727     */
    1828    public function __construct(expression $parent) {
     
    2333     * Parses an array of tokens
    2434     *
    25      * @param array &$tokens A tokenise object
    26      * @return void
     35     * @param tokenise $tokens A tokenise object
     36     * @return bool Whether any tokens were parsed
    2737     */
    2838    public function parse(tokenise $tokens) : bool {
  • torque/trunk/packages/tokenise/autoload.php

    r2592945 r2817597  
    11<?php
    22declare(strict_types = 1);
    3 spl_autoload_register(function (string $class) : bool {
     3\spl_autoload_register(function (string $class) : void {
    44    if ($class === 'hexydec\\tokens\\tokenise') {
    5         return (bool) require(__DIR__.'/tokenise.php');
     5        require(__DIR__.'/tokenise.php');
    66    }
    7     return false;
    87});
  • torque/trunk/readme.txt

    r2744378 r2817597  
    33Tags: minify,minification,performance,security,optimization
    44Requires at least: 5.9
    5 Tested up to: 6.0
     5Tested up to: 6.1
    66Requires PHP: 7.4
    7 Stable tag: 0.6.4
     7Stable tag: 0.6.5
    88License: GPLv3
    99License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
     
    9999Some advanced minification optimisations can cause issues with your website's layout, or break your Javascript depending on how your CSS/Javascript selectors are setup.
    100100
    101 For example, you can strip default attributes from your HTML such as `type="text"` on the `<input>` object. If you have a CSS or Javascript selector that relies on this attribute being there, such as `input[type=input]`, the selecctor will no longer match. See [https://github.com/hexydec/htmldoc/blob/master/docs/mitigating-side-effects.md](HTMLdoc: Mitigating Side Effects of Minification) for solutions.
     101For example, you can strip default attributes from your HTML such as `type="text"` on the `<input>` object. If you have a CSS or Javascript selector that relies on this attribute being there, such as `input[type=input]`, the selector will no longer match. See [HTMLdoc: Mitigating Side Effects of Minification](https://github.com/hexydec/htmldoc/blob/master/docs/mitigating-side-effects.md) for solutions.
    102102
    103103= Why is HTMLdoc best in class? =
     
    136136
    137137== Changelog ==
     138
     139= Version 0.6.5 =
     140
     141* Tested with Wordpress v6.1
     142* Fixed bug in Content-Security-Policy generator where a directive was not spelt correctly
     143* Updated dependencies
     144* Minor syntax improvements
     145
     146= Version 0.6.4 =
     147
     148* Tested with Wordpress v6.0
    138149
    139150= Version 0.6.3 =
  • torque/trunk/torque.php

    r2744378 r2817597  
    1010Plugin URI:     https://github.com/hexydec/torque
    1111Description:    Make your Wordpress website noticably faster by optimising how it is delivered. Analyse your website's performance and security, minify and combine your assets, and configure an array of performance and security settings quickly and easily with this comprehensive plugin. Achieves the best compression of any minification plugin.
    12 Version:        0.6.4
     12Version:        0.6.5
    1313Requires PHP:   7.4
    1414Author:         Hexydec
     
    2525    // from GitHub, download packages
    2626    if (\class_exists('\\hexydec\\torque\\installExternal')) {
    27         $obj = new \hexydec\torque\installExternal();
     27        $obj = new installExternal();
    2828
    2929    // for Wordpress, packages are included
    3030    } else {
    31         $obj = new \hexydec\torque\install();
     31        $obj = new install();
    3232    }
    3333    $obj->install();
     
    3636// install the admin menu
    3737\add_action('admin_menu', function () {
    38     $obj = new \hexydec\torque\admin();
     38    $obj = new admin();
    3939    $obj->update();
    4040    $obj->draw();
     
    4343// load the app
    4444\add_action('wp_loaded', function () {
    45     $obj = new \hexydec\torque\app();
     45    $obj = new app();
    4646    $obj->optimise();
    4747});
     
    5252// rebuild files when a plugin is updated
    5353\add_action('upgrader_process_complete', function () {
    54     \hexydec\torque\assets::rebuildAssets();
     54    assets::rebuildAssets();
    5555});
    5656
Note: See TracChangeset for help on using the changeset viewer.