Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ _ide_helper.php
.php-cs-fixer.cache
.phpunit.result.cache
deploy.php
deploy-old.php
htdocs/wp-content/db.php
htdocs/wp-content/debug.log
htdocs/wp-content/languages
Expand Down
55 changes: 2 additions & 53 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,56 +16,5 @@
->ignoreDotFiles(true)
->ignoreVCS(true);

return (new PhpCsFixer\Config)
->setRules([
'@PSR2' => true,
'indentation_type' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sort_algorithm' => 'alpha',
],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'trailing_comma_in_multiline' => true,
'phpdoc_scalar' => true,
'phpdoc_var_without_name' => true,
'phpdoc_single_line_var_spacing' => true,
'unary_operator_spaces' => true,
'phpdoc_trim' => true,
'phpdoc_trim_consecutive_blank_line_separation' => false,
'align_multiline_comment' => true,
'array_indentation' => true,
'no_superfluous_elseif' => true,
'single_blank_line_before_namespace' => true,
'blank_line_after_opening_tag' => true,
'no_blank_lines_after_phpdoc' => true,
'phpdoc_separation' => false,
'method_chaining_indentation' => true,
'binary_operator_spaces' => [
'default' => 'single_space',
'operators' => [
'=>' => 'single_space',
'|' => 'no_space',
],
],
'return_type_declaration' => [
'space_before' => 'none',
],
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
],
'full_opening_tag' => true,
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
],
'yoda_style' => [
'always_move_variable' => true,
'equal' => true,
'identical' => true,
'less_and_greater' => true,
],
])
// ->setIndent("\t")
->setLineEnding("\n")
->setRiskyAllowed(true)
->setFinder($finder);

return \Yard\PhpCsFixerRules\Config::create($finder);
262 changes: 131 additions & 131 deletions app/Assets/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,135 +6,135 @@

class Assets
{
private static array $defaultScripts = [
'jquery-ui-core' => [
'url' => 'https://code.jquery.com/ui/1.14.1/jquery-ui.min.js',
'integrity' => 'sha384-SStJQoPipVtHHnIgUfDI+jTAbSyU+HMbhwt2XRRNpLIRFg9VguopT6Y4+cdOlkqg',
'deps' => ['jquery'],
],
'jquery-migrate' => [
'url' => 'https://code.jquery.com/jquery-migrate-3.5.2.min.js',
'integrity' => 'sha384-q8xaSZ1piumPohq/TeRG7Teq801W0tUq/00Kt0PcnM9d4hb3w9+vMocDmnPq72ts',
],
];

/**
* Enqueues scripts and styles for the frontend.
*/
public static function enqueueScripts(): void
{
$assetDetails = self::getAssetDetails('frontend.asset.php');

wp_register_script(
'theme',
$assetDetails['baseUrl'] . 'frontend.js',
$assetDetails['scriptAsset']['dependencies'],
$assetDetails['scriptAsset']['version'],
);

wp_enqueue_script('theme');

wp_enqueue_style('theme', $assetDetails['baseUrl'] . 'frontend.css', [], $assetDetails['scriptAsset']['version']);

$sitesWithRS = [
env('GGD_SITE_ID', 5) => '13499',
env('HW_SITE_ID', 4) => '8150',
];

wp_localize_script('theme', 'theme', [
'rsID' => $sitesWithRS[get_current_blog_id()] ?? '0',
]);
}

/**
* Enqueues scripts for the block editor.
*/
public static function enqueueBlockEditorScripts(): void
{
$assetDetails = self::getAssetDetails('editor.asset.php');

wp_register_script(
'theme-block-editor',
$assetDetails['baseUrl'] . 'editor.js',
$assetDetails['scriptAsset']['dependencies'],
$assetDetails['scriptAsset']['version'],
true
);

wp_enqueue_script('theme-block-editor');
wp_enqueue_style('theme-block-editor', $assetDetails['baseUrl'] . 'editor.css', [], $assetDetails['scriptAsset']['version']);
}

/**
* Retrieve common asset details.
*
* @param string $assetFileName The name of the php asset file.
*/
private static function getAssetDetails($assetFileName): array
{
$baseUrl = get_stylesheet_directory_uri() . '/assets/dist/';
$basePath = get_stylesheet_directory() . '/assets/dist/';

$scriptAssetPath = $basePath . $assetFileName;
$scriptAsset = file_exists($scriptAssetPath) ? require($scriptAssetPath) : ['dependencies' => [], 'version' => round(microtime(true))];

return [
'baseUrl' => $baseUrl,
'basePath' => $basePath,
'scriptAssetPath' => $scriptAssetPath,
'scriptAsset' => $scriptAsset,
];
}

/**
* Replace defaultscripts with latest version
*/
public static function replaceDefaultScripts(\WP_Scripts $scripts): void
{
if (is_admin()) {
return;
}

foreach (self::$defaultScripts as $handle => $props) {
$props = wp_parse_args(
$props,
[
'url' => null,
'integrity' => null,
'deps' => [],
'ver' => null,
]
);

$scripts->remove($handle);
$scripts->add($handle, $props['url'], $props['deps'], $props['ver'], true);
$scripts->enqueue($handle);
}
}

/**
* Add script attributes for external scripts
* - integrity
* - crossorigin
*/
public static function addScriptAttributes(array $attributes): array
{
if (is_admin()) {
return $attributes;
}

foreach (self::$defaultScripts as $handle => $props) {
if ($props['url'] !== $attributes['src']) {
continue;
}
if (! empty($props['integrity'])) {
$attributes['integrity'] = $props['integrity'];
$attributes['crossorigin'] = 'anonymous';
}

break;
}

return $attributes;
}
private static array $defaultScripts = [
'jquery-ui-core' => [
'url' => 'https://code.jquery.com/ui/1.14.1/jquery-ui.min.js',
'integrity' => 'sha384-SStJQoPipVtHHnIgUfDI+jTAbSyU+HMbhwt2XRRNpLIRFg9VguopT6Y4+cdOlkqg',
'deps' => ['jquery'],
],
'jquery-migrate' => [
'url' => 'https://code.jquery.com/jquery-migrate-3.5.2.min.js',
'integrity' => 'sha384-q8xaSZ1piumPohq/TeRG7Teq801W0tUq/00Kt0PcnM9d4hb3w9+vMocDmnPq72ts',
],
];

/**
* Enqueues scripts and styles for the frontend.
*/
public static function enqueueScripts(): void
{
$assetDetails = self::getAssetDetails('frontend.asset.php');

wp_register_script(
'theme',
$assetDetails['baseUrl'] . 'frontend.js',
$assetDetails['scriptAsset']['dependencies'],
$assetDetails['scriptAsset']['version'],
);

wp_enqueue_script('theme');

wp_enqueue_style('theme', $assetDetails['baseUrl'] . 'frontend.css', [], $assetDetails['scriptAsset']['version']);

$sitesWithRS = [
env('GGD_SITE_ID', 5) => '13499',
env('HW_SITE_ID', 4) => '8150',
];

wp_localize_script('theme', 'theme', [
'rsID' => $sitesWithRS[get_current_blog_id()] ?? '0',
]);
}

/**
* Enqueues scripts for the block editor.
*/
public static function enqueueBlockEditorScripts(): void
{
$assetDetails = self::getAssetDetails('editor.asset.php');

wp_register_script(
'theme-block-editor',
$assetDetails['baseUrl'] . 'editor.js',
$assetDetails['scriptAsset']['dependencies'],
$assetDetails['scriptAsset']['version'],
true
);

wp_enqueue_script('theme-block-editor');
wp_enqueue_style('theme-block-editor', $assetDetails['baseUrl'] . 'editor.css', [], $assetDetails['scriptAsset']['version']);
}

/**
* Retrieve common asset details.
*
* @param string $assetFileName The name of the php asset file.
*/
private static function getAssetDetails($assetFileName): array
{
$baseUrl = get_stylesheet_directory_uri() . '/assets/dist/';
$basePath = get_stylesheet_directory() . '/assets/dist/';

$scriptAssetPath = $basePath . $assetFileName;
$scriptAsset = file_exists($scriptAssetPath) ? require($scriptAssetPath) : ['dependencies' => [], 'version' => round(microtime(true))];

return [
'baseUrl' => $baseUrl,
'basePath' => $basePath,
'scriptAssetPath' => $scriptAssetPath,
'scriptAsset' => $scriptAsset,
];
}

/**
* Replace defaultscripts with latest version
*/
public static function replaceDefaultScripts(\WP_Scripts $scripts): void
{
if (is_admin()) {
return;
}

foreach (self::$defaultScripts as $handle => $props) {
$props = wp_parse_args(
$props,
[
'url' => null,
'integrity' => null,
'deps' => [],
'ver' => null,
]
);

$scripts->remove($handle);
$scripts->add($handle, $props['url'], $props['deps'], $props['ver'], true);
$scripts->enqueue($handle);
}
}

/**
* Add script attributes for external scripts
* - integrity
* - crossorigin
*/
public static function addScriptAttributes(array $attributes): array
{
if (is_admin()) {
return $attributes;
}

foreach (self::$defaultScripts as $handle => $props) {
if ($props['url'] !== $attributes['src']) {
continue;
}
if (! empty($props['integrity'])) {
$attributes['integrity'] = $props['integrity'];
$attributes['crossorigin'] = 'anonymous';
}

break;
}

return $attributes;
}
}
Loading