Changeset 3012051
- Timestamp:
- 12/19/2023 03:22:44 PM (2 years ago)
- Location:
- torque/trunk
- Files:
-
- 15 edited
-
admin.php (modified) (1 diff)
-
app.php (modified) (1 diff)
-
assets.php (modified) (1 diff)
-
autoload.php (modified) (2 diffs)
-
config.php (modified) (9 diffs)
-
csp.php (modified) (2 diffs)
-
overview.php (modified) (1 diff)
-
packages.php (modified) (2 diffs)
-
packages/cssdoc/config.php (modified) (1 diff)
-
packages/cssdoc/tokens/directive.php (modified) (3 diffs)
-
packages/htmldoc/config.php (modified) (1 diff)
-
packages/htmldoc/tokens/custom.php (modified) (1 diff)
-
packages/htmldoc/tokens/tag.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
torque.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
torque/trunk/admin.php
r2823176 r3012051 10 10 11 11 /** 12 * @var $template Stores the name of the c irrently 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; 15 15 16 16 /** -
torque/trunk/app.php
r2912478 r3012051 387 387 // render javascript 388 388 $console = [ 389 'console.groupCollapsed("'. self::SLUG.' Stats");',389 'console.groupCollapsed("'.\mb_convert_case(self::SLUG, MB_CASE_TITLE).' Stats");', 390 390 'console.table('.\json_encode($table).');', 391 391 'console.table('.\json_encode($sizes).');', -
torque/trunk/assets.php
r2939649 r3012051 10 10 11 11 /** 12 * @var $pages Caches the result of any page requests13 */ 14 protected static $pages = [];15 16 /** 17 * @var $assets Caches the result any assets that have been gathered from a page18 */ 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 = []; 20 20 21 21 /** -
torque/trunk/autoload.php
r2823176 r3012051 5 5 * @package hexydec/torque 6 6 */ 7 \spl_autoload_register(function (string $class) : bool{7 \spl_autoload_register(function (string $class) : void { 8 8 $namespace = 'hexydec\\torque\\'; 9 9 $classes = [ … … 19 19 ]; 20 20 if (isset($classes[$class]) && \file_exists($classes[$class])) { 21 re turn require($classes[$class]);21 require $classes[$class]; 22 22 } 23 return false;24 23 }); 25 24 -
torque/trunk/config.php
r2823176 r3012051 12 12 * @var array $options A list of configuration options for the plugin 13 13 */ 14 protected $options = [];14 protected array $options = []; 15 15 16 16 /** 17 17 * @var array $config The plugin configuration 18 18 */ 19 protected $config = [19 protected array $config = [ 20 20 'output' => null, // can't be set here, see below 21 21 'csplog' => 'csp-reports.json' … … 27 27 public function __construct() { 28 28 $url = \get_home_url().'/?notorque'; 29 $dir = \dirname(\dirname(\dirname(__DIR__))).'/'; // can't use get_home_path() here29 // $dir = \dirname(\dirname(\dirname(__DIR__))).'/'; // can't use get_home_path() here 30 30 $this->config['output'] = WP_CONTENT_DIR.'/uploads/torque/'; 31 31 … … 65 65 'description' => 'Select which CSS files to combine and minify', 66 66 'default' => [], 67 'datasource' => function () use ($url) {67 'datasource' => function () use ($url) : array|false { 68 68 if (($assets = assets::getPageAssets($url)) !== false) { 69 69 $filtered = []; … … 77 77 return false; 78 78 }, 79 'onsave' => function (array $value, array $options) {79 'onsave' => function (array $value, array $options) : bool { 80 80 if ($value) { 81 81 $target = $this->config['output'].\md5(\implode(',', $value)).'.css'; 82 82 if (!assets::buildCss($value, $target, $options['minifystyle'] ? ($options['style'] ?? []) : null)) { 83 83 \add_settings_error(self::SLUG, self::SLUG, 'The combined CSS file could not be generated'); 84 return false; 84 85 } 85 86 } 86 return false;87 return true; 87 88 } 88 89 ], … … 98 99 '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.', 99 100 'default' => [], 100 'datasource' => function () use ($url) {101 'datasource' => function () use ($url) : array|false { 101 102 if (($assets = assets::getPageAssets($url)) !== false) { 102 103 $filtered = []; … … 110 111 return false; 111 112 }, 112 'onsave' => function (array $value, array $options) {113 'onsave' => function (array $value, array $options) : bool { 113 114 if ($value) { 114 115 $target = $this->config['output'].\md5(\implode(',', $value)).'.js'; 115 116 if (!assets::buildJavascript($value, $target, $options['minifyscript'] ? ($options['script'] ?? []) : null)) { 116 117 \add_settings_error(self::SLUG, self::SLUG, 'The combined Javascript file could not be generated'); 118 return false; 117 119 } 118 120 } 119 return false;121 return true; 120 122 } 121 123 ], … … 620 622 'type' => 'checkbox', 621 623 'default' => false, 622 'onsave' => function (bool $value) {624 'onsave' => function (bool $value) : bool { 623 625 if ($value) { 624 626 $report = $this->config['output'].$this->config['csplog']; … … 642 644 'type' => 'multiselect', 643 645 'default' => [], 644 'datasource' => function () use ($url) {646 'datasource' => function () use ($url) : array|false { 645 647 if (($assets = assets::getPageAssets($url)) !== false) { 646 648 … … 751 753 $keys = []; 752 754 foreach ($this->options AS $key => $item) { 753 $tab = $item['tab'];754 755 if (!\in_array($item['tab'], $tabs)) { 755 756 $tabs[] = $item['tab']; -
torque/trunk/csp.php
r2823176 r3012051 55 55 } 56 56 } 57 return $key ? $csp[$key] ?? null: $csp;57 return $key ? ($csp[$key] ?? null) : $csp; 58 58 } 59 59 60 public static function recommendations(string $file, string $key) {60 public static function recommendations(string $file, string $key) : ?array { 61 61 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 63 67 $recs = []; 64 68 foreach (\array_keys($data) AS $href) { … … 99 103 100 104 // add keyword 101 } elseif (! in_array($href, $recs)) {105 } elseif (!\in_array($href, $recs)) { 102 106 $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'"; 103 119 } 104 120 } -
torque/trunk/overview.php
r2939649 r3012051 12 12 * @var array $config Stores the configuration for the overview page 13 13 */ 14 protected $config = [];14 protected array $config = []; 15 15 16 16 /** -
torque/trunk/packages.php
r2939649 r3012051 29 29 * Note that external dependencies are only installed when install-external.php is available and the packages are not already bundled 30 30 */ 31 protected static $packages = [31 protected static array $packages = [ 32 32 'htmldoc' => [ 33 33 'class' => 'hexydec\\html\\htmldoc', … … 62 62 */ 63 63 public static function autoload() : void { 64 \spl_autoload_register(function (string $class) : bool{64 \spl_autoload_register(function (string $class) : void { 65 65 $dir = self::INSTALLDIR; 66 66 foreach (self::$packages AS $item) { 67 67 if ($item['class'] === $class && \file_exists($dir.$item['autoload'])) { 68 re turn require($dir.$item['autoload']);68 require $dir.$item['autoload']; 69 69 } 70 70 } 71 return false;72 71 }); 73 72 } -
torque/trunk/packages/cssdoc/config.php
r2939649 r3012051 9 9 */ 10 10 protected array $config = [ 11 'nested' => ['@media', '@supports', '@keyframes', '@-webkit-keyframes', '@-moz-keyframes', '@-o-keyframes', '@document', '@-moz-document', '@container' ], // directive that can have nested rules11 'nested' => ['@media', '@supports', '@keyframes', '@-webkit-keyframes', '@-moz-keyframes', '@-o-keyframes', '@document', '@-moz-document', '@container', '@layer'], // directive that can have nested rules 12 12 'spaced' => ['calc', 'min', 'max', 'clamp'], // values where spaces between operators must be retained 13 13 '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 30 30 */ 31 31 public ?document $document = null; 32 33 /** 34 * @var bool Whether the object has an empty body 35 */ 36 public bool $empty = false; 32 37 33 38 /** … … 77 82 if ($item->parse($tokens)) { 78 83 $this->document = $item; 84 } else { 85 $this->empty = true; 79 86 } 80 87 } else { … … 130 137 public function isEmpty() : bool { 131 138 if (\in_array($this->directive, $this->root->config['nested'], true)) { 132 return $this->document === null ;139 return $this->document === null && $this->empty; 133 140 } else { 134 return !$this->properties && !$this->content;141 return empty($this->properties) && empty($this->content); 135 142 } 136 143 } -
torque/trunk/packages/htmldoc/config.php
r2615373 r3012051 36 36 'elements' => [ 37 37 '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' 39 39 ], 40 40 'singleton' => [ -
torque/trunk/packages/htmldoc/tokens/custom.php
r2817597 r3012051 81 81 $dir = \dirname($file); 82 82 if (!\is_dir($dir)) { 83 \mkdir($dir, 0755 );83 \mkdir($dir, 0755, true); 84 84 } 85 85 \file_put_contents($file, $content); -
torque/trunk/packages/htmldoc/tokens/tag.php
r2912478 r3012051 347 347 protected function getIndex() : ?int { 348 348 if ($this->parent) { 349 foreach ($this->parent->children ()AS $key => $item) {349 foreach ($this->parent->children AS $key => $item) { 350 350 if ($item === $this) { 351 351 return $key; … … 431 431 432 432 // 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) { 435 435 if (\mb_substr($folder, -1) !== '/') { 436 436 $folder = \dirname($folder).'/'; -
torque/trunk/readme.txt
r2939649 r3012051 2 2 Contributors: hexydec 3 3 Tags: minify,minification,performance,security,optimization 4 Requires at least: 5 Tested up to: 6. 24 Requires at least: 6.0 5 Tested up to: 6.4.2 6 6 Requires PHP: 8.0 7 Stable tag: 0.7. 37 Stable tag: 0.7.4 8 8 License: GPLv3 9 9 License URI: https://www.gnu.org/licenses/gpl-3.0.en.html … … 129 129 == Changelog == 130 130 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 131 140 = Version 0.7.3 = 132 141 -
torque/trunk/torque.php
r2939649 r3012051 21 21 22 22 // activate the plugin 23 \register_activation_hook(__FILE__, function () {23 \register_activation_hook(__FILE__, function () : void { 24 24 25 25 // from GitHub, download packages … … 35 35 36 36 // install the admin menu 37 \add_action('admin_menu', function () {37 \add_action('admin_menu', function () : void { 38 38 $obj = new admin(); 39 39 $obj->update(); … … 42 42 43 43 // load the app 44 \add_action('wp_loaded', function () {44 \add_action('wp_loaded', function () : void { 45 45 $obj = new app(); 46 46 $obj->optimise(); … … 51 51 52 52 // rebuild files when a plugin is updated 53 \add_action('upgrader_process_complete', function () {53 \add_action('upgrader_process_complete', function () : void { 54 54 assets::rebuildAssets(); 55 55 }); … … 57 57 // add rebuild command 58 58 if (\class_exists('WP_CLI')) { 59 \WP_CLI::add_command('torque rebuild', function () {59 \WP_CLI::add_command('torque rebuild', function () : bool { 60 60 return \hexydec\torque\assets::rebuildAssets(); 61 61 }, [
Note: See TracChangeset
for help on using the changeset viewer.