diff --git a/app/ACF/CloneGroup.php b/app/ACF/CloneGroup.php
new file mode 100644
index 0000000..04052f0
--- /dev/null
+++ b/app/ACF/CloneGroup.php
@@ -0,0 +1,28 @@
+values();
+
+ $field['choices'] = [];
+
+ foreach($colours as $slug => $hex):
+ $field['choices'][$slug] = ' ' . @$NameThatColour->name($hex)['name'];
+ endforeach;
+
+ return $field;
+
+ }
+
+ public function load_tints( $field )
+ {
+ $colour = new Utilities\Colour;
+ $tints = $colour->tints();
+
+ $field['choices'] = [];
+
+ foreach($tints as $slug => $hex):
+ if($slug):
+ $field['choices'][$slug] = ucfirst($slug);
+
+ else:
+ $field['choices'][0] = 'None';
+ endif;
+ endforeach;
+
+ return $field;
+ }
+
public function load_fontawesome_regular_icons( $field )
{
$field['choices'] = [];
diff --git a/app/ACF/Options.php b/app/ACF/Options.php
new file mode 100644
index 0000000..0ccbdee
--- /dev/null
+++ b/app/ACF/Options.php
@@ -0,0 +1,23 @@
+ __('Global Settings'),
+ 'menu_title' => __('Global Settings'),
+ 'menu_slug' => 'theme-global-settings',
+ 'capability' => 'edit_others_posts',
+ 'redirect' => false,
+ 'icon_url' => 'dashicons-admin-site',
+ ]);
+ }
+}
diff --git a/app/Admin/Blocks.php b/app/Admin/Blocks.php
new file mode 100644
index 0000000..5825412
--- /dev/null
+++ b/app/Admin/Blocks.php
@@ -0,0 +1,135 @@
+get_all_registered() );
+
+ $blacklist = [
+ // Design
+ 'core/button',
+ 'core/comment-template',
+ 'core/home-link',
+ 'core/navigation-link',
+ 'core/navigation-submenu',
+ 'core/buttons',
+ 'core/column',
+ 'core/columns',
+ 'core/group',
+ 'core/more',
+ 'core/nextpage',
+ 'core/separator',
+ 'core/spacer',
+ 'core/text-columns',
+
+ // Embed
+ 'core/embed',
+
+ // Media
+ 'core/cover',
+ 'core/file',
+ 'core/gallery',
+ 'core/image',
+ 'core/media-text',
+ 'core/audio',
+ 'core/video',
+
+ // Reusable
+ 'core/block',
+
+ // Text
+ 'core/footnotes',
+ 'core/heading',
+ 'core/list',
+ 'core/code',
+ 'core/details',
+ 'core/freeform',
+ 'core/list-item',
+ 'core/missing',
+ 'core/paragraph',
+ 'core/preformatted',
+ 'core/pullquote',
+ 'core/quote',
+ 'core/table',
+ 'core/verse',
+
+ // Theme
+ 'core/avatar',
+ 'core/comment-author-name',
+ 'core/comment-content',
+ 'core/comment-date',
+ 'core/comment-edit-link',
+ 'core/comment-reply-link',
+ 'core/comments',
+ 'core/comments-pagination',
+ 'core/comments-pagination-next',
+ 'core/comments-pagination-numbers',
+ 'core/comments-pagination-previous',
+ 'core/comments-title',
+ 'core/loginout',
+ 'core/navigation',
+ 'core/pattern',
+ 'core/post-author',
+ 'core/post-author-biography',
+ 'core/post-author-name',
+ 'core/post-comments-form',
+ 'core/post-content',
+ 'core/post-date',
+ 'core/post-excerpt',
+ 'core/post-featured-image',
+ 'core/post-navigation-link',
+ 'core/post-template',
+ 'core/post-terms',
+ 'core/post-title',
+ 'core/query',
+ 'core/query-no-results',
+ 'core/query-pagination',
+ 'core/query-pagination-next',
+ 'core/query-pagination-numbers',
+ 'core/query-pagination-previous',
+ 'core/query-title',
+ 'core/read-more',
+ 'core/site-logo',
+ 'core/site-tagline',
+ 'core/site-title',
+ 'core/template-part',
+ 'core/term-description',
+ 'core/post-comments',
+
+ // Widgets
+ 'core/legacy-widget',
+ 'core/widget-group',
+ 'core/archives',
+ 'core/calendar',
+ 'core/categories',
+ 'core/latest-comments',
+ 'core/latest-posts',
+ 'core/page-list',
+ 'core/page-list-item',
+ 'core/rss',
+ 'core/search',
+ 'core/shortcode',
+ 'core/social-link',
+ 'core/tag-cloud',
+ 'core/html',
+ 'core/social-links',
+ ];
+
+ return array_values( array_diff( $blocks, $blacklist ) );
+ }
+}
diff --git a/app/Admin/DisablePost.php b/app/Admin/DisablePost.php
new file mode 100644
index 0000000..3738ad0
--- /dev/null
+++ b/app/Admin/DisablePost.php
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+ 'badegg/bad-example',
+ 'title' => __('Bad Example'),
+ 'description' => __('This is an example block'),
+ 'render_callback' => [ $this, 'render'],
+ 'category' => 'layout',
+ 'multiple' => false,
+ 'icon' => [
+ 'src' => 'dismiss',
+ ],
+ 'supports' => [
+ 'align' => false,
+ ],
+ ]);
+ }
+
+ public function render($block)
+ {
+ $CssClasses = new Utilities\CssClasses;
+ $Colour = new Utilities\Colour;
+ $CloneGroup = new ACF\CloneGroup;
+
+ $data = [];
+
+ $fields = [
+ 'heading',
+ 'blurb',
+ ];
+
+ $fields = array_merge($fields, $CloneGroup->background());
+
+ foreach($fields as $field):
+ $data[$field] = get_field($field);
+ endforeach;
+
+ unset($block['data']);
+ $block['name'] = str_replace('acf/', '', $block['name']);
+
+ $data = array_merge($data, $block);
+ $data['section_classes'] = $CssClasses->section($data);
+ $data['block'] = $block;
+
+ $data['knockout'] = ($Colour->is_dark($data['bg_colour'], $data['bg_tint'], $data['contrast'])) ? null : 'knockout';
+
+ echo \Roots\view('blocks.bad-example', [
+ 'data' => $data,
+ 'block' => $block,
+ ])->render();
+ }
+}
diff --git a/app/Utilities/Colour.php b/app/Utilities/Colour.php
new file mode 100644
index 0000000..7072062
--- /dev/null
+++ b/app/Utilities/Colour.php
@@ -0,0 +1,168 @@
+values()[(string)$colour];
+ endif;
+
+ if($tint):
+ $tints = $this->tints();
+ $hex = $this->adjustBrightness($hex, $tints[$tint]);
+ endif;
+
+ return $hex;
+ }
+
+ public function values()
+ {
+ $colours = get_field('badegg_colours', 'option');
+
+ $values = [];
+
+ if($colours):
+ foreach($colours as $index => $props):
+ $index = $index + 1;
+ $hex = @$props['hex'];
+
+ if($hex) $values[$this->latinate($index)] = $hex;
+ endforeach;
+ endif;
+
+ $values['0'] = '#FFFFFF';
+ $values['black'] = '#000000';
+
+ return $values;
+ }
+
+ public function tints()
+ {
+ return [
+ 'lightest' => 100,
+ 'lighter' => 66,
+ 'light' => 33,
+ '0' => 0,
+ 'dark' => -33,
+ 'darker' => -66,
+ 'darkest' => -100,
+ ];
+ }
+
+ public function is_dark($colour = '#FFFFF', $tint = null, $override = null)
+ {
+
+ if($override == 'light') return true;
+ if($override == 'dark') return false;
+
+ // https://css-tricks.com/snippets/php/convert-hex-to-rgb/
+
+ if($tint) $colour = $this->adjustBrightness($colour, $this->tints()[$tint]);
+
+ if ( @$colour[0] == '#' ) {
+ $colour = substr( $colour, 1 );
+ }
+
+ if ( strlen( $colour ) == 6 ) {
+ list( $r, $g, $b ) = [
+ $colour[0] . $colour[1],
+ $colour[2] . $colour[3],
+ $colour[4] . $colour[5],
+ ];
+
+ } elseif ( strlen( $colour ) == 3 ) {
+ list( $r, $g, $b ) = [
+ $colour[0] . $colour[0],
+ $colour[1] . $colour[1],
+ $colour[2] . $colour[2],
+ ];
+
+ } else {
+ return false;
+ }
+
+ $r = hexdec( $r );
+ $g = hexdec( $g );
+ $b = hexdec( $b );
+ // return array( 'red' => $r, 'green' => $g, 'blue' => $b );
+
+ $hsp = sqrt(
+ 0.299 * ($r * $r) +
+ 0.587 * ($g * $g) +
+ 0.114 * ($b * $b)
+ );
+
+ if($hsp > 200) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ public function is_light($colour = '#000000', $tint = null)
+ {
+ if($this->is_dark($colour, $tint)) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ public function adjustBrightness($hex, $steps)
+ {
+ // Steps should be between -255 and 255. Negative = darker, positive = lighter
+ $steps = max(-255, min(255, $steps));
+
+ // Normalize into a six character long hex string
+ $hex = str_replace('#', '', $hex);
+ if (strlen($hex) == 3) {
+ $hex = str_repeat(substr($hex,0,1), 2).str_repeat(substr($hex,1,1), 2).str_repeat(substr($hex,2,1), 2);
+ }
+
+ // Split into three parts: R, G and B
+ $color_parts = str_split($hex, 2);
+ $return = '#';
+
+ foreach ($color_parts as $color) {
+ $color = hexdec($color); // Convert to decimal
+ $color = max(0,min(255,$color + $steps)); // Adjust color
+ $return .= str_pad(dechex($color), 2, '0', STR_PAD_LEFT); // Make two char hex code
+ }
+
+ return $return;
+ }
+
+ public function latinate($x = 0)
+ {
+ $latinate = [
+ 1 => 'primary',
+ 2 => 'secondary',
+ 3 => 'tertiary',
+ 4 => 'quaternary',
+ 5 => 'quinary',
+ 6 => 'senary',
+ 7 => 'septenary',
+ 8 => 'octonary',
+ 9 => 'nonary',
+ 10 => 'denary',
+ 11 => 'undenary',
+ 12 => 'duodenary',
+ ];
+
+ if(array_key_exists($x, $latinate)):
+ return $latinate[$x];
+ else:
+ return 0;
+ endif;
+ }
+}
diff --git a/app/Utilities/CssClasses.php b/app/Utilities/CssClasses.php
new file mode 100644
index 0000000..9f95405
--- /dev/null
+++ b/app/Utilities/CssClasses.php
@@ -0,0 +1,105 @@
+name2hex(@$props['bg_colour'], @$props['bg_tint']);
+
+ $pattern = @$props['pattern'];
+ $pattern_top = @$props['pattern_top'];
+ $pattern_bottom = @$props['pattern_bottom'];
+
+ $classes = [
+ 'section',
+ 'section-' . str_replace('acf/', '', $props['name']),
+ 'bg-' . $this->colourTint([
+ 'colour' => @$props['bg_colour'],
+ 'tint' => @$props['bg_tint'],
+ ]),
+ ];
+
+ if($Colour->is_dark($hex) && $this->is_knockout_block($props['name']))
+ $classes[] = 'knockout';
+
+ if(@$props['padding_top'])
+ $classes[] = 'section-zero-top';
+
+ if(@$props['padding_bottom'])
+ $classes[] = 'section-zero-bottom';
+
+ if($pattern):
+ if($pattern == 'both'):
+ $classes[] = 'pattern-top';
+ $classes[] = 'pattern-bottom';
+
+ else:
+ $classes[] = 'pattern-' . $pattern;
+
+ endif;
+
+ if(in_array($pattern, ['top', 'both']))
+ $classes[] = 'pattern-top-' . $this->colourTint($pattern_top);
+
+ if(in_array($pattern, ['bottom', 'both']))
+ $classes[] = 'pattern-bottom-' . $this->colourTint($pattern_bottom);
+
+ endif;
+
+ if(@$props['bg_image'])
+ $classes[] = "bg-watermarked";
+
+ if(@$props['className']) $args = array_merge($classes, explode(' ', $props['className']));
+
+ return $classes;
+ }
+
+ public function button($args = [])
+ {
+ $default_args = [
+ 'colour' => null,
+ 'style' => null,
+ ];
+
+ $args = wp_parse_args($args, $default_args);
+
+ $classes = [
+ 'button',
+ ];
+
+ if($args['colour']) $classes[] = $args['colour'];
+ if($args['style']) $classes[] = $args['style'];
+
+ return $classes;
+ }
+
+ public function colourTint($props = [])
+ {
+ if(@$props['colour']):
+ $colour = $props['colour'];
+
+ if($props['colour'] != 'black' && @$props['tint']):
+ $colour .= '-' . $props['tint'];
+ endif;
+ else:
+ $colour = 'white';
+ endif;
+
+ return $colour;
+ }
+
+ public function is_knockout_block($name = null)
+ {
+ $blacklist = [
+ 'bad-example',
+ ];
+
+ if(in_array($name, $blacklist)):
+ return false;
+ else:
+ return true;
+ endif;
+ }
+}
diff --git a/app/Utilities/ImageSrcset.php b/app/Utilities/ImageSrcset.php
new file mode 100644
index 0000000..5f69d59
--- /dev/null
+++ b/app/Utilities/ImageSrcset.php
@@ -0,0 +1,124 @@
+default_args());
+ $multipliers = $this->multipliers();
+
+ if(is_null($args['height'])) $args['height'] = $args['width'];
+
+
+ if($args['sizes'] < 5) $multipliers = array_slice($multipliers, 0, $args['sizes']);
+
+ foreach ( $multipliers as $slug => $scale ):
+ add_image_size (
+ $args['name'] . '-' . $slug,
+ round((int)$args['width'] * $scale),
+ round((int)$args['height'] * $scale),
+ $args['crop']
+ );
+ endforeach;
+ }
+
+ public function default_args()
+ {
+ return [
+ 'name' => 'hero',
+ 'width' => 1920,
+ 'height' => null,
+ 'crop' => true,
+ 'sizes' => 5,
+ ];
+ }
+
+ public function multipliers()
+ {
+ return [
+ 'xl' => 1,
+ 'lg' => 0.75,
+ 'md' => 0.52083333,
+ 'sm' => 0.33333333,
+ 'xs' => 0.20833333,
+ ];
+ }
+
+ public function render($args = [])
+ {
+ global $_wp_additional_image_sizes;
+
+ $default_args = [
+ 'name' => 'hero',
+ 'image' => null,
+ 'lazy' => true,
+ 'sizes' => 5,
+ 'class' => null,
+ ];
+
+ $args = wp_parse_args($args, $default_args);
+ $name = $args['name'];
+ $image = ($args['image']) ? $args['image'] : get_post_thumbnail_id();
+
+ if(!$image) return false;
+
+ $properties = @$_wp_additional_image_sizes[$name . '-xl'];
+ $width = @$properties['width'];
+ $height = @$properties['height'];
+
+ $sizes = [
+ 'xl' => 1,
+ 'lg' => 0.75,
+ 'md' => 0.52083333,
+ 'sm' => 0.33333333,
+ 'xs' => 0.20833333,
+ ];
+
+ if($args['sizes'] < 5) $sizes = array_slice($sizes, 0, $args['sizes']);
+
+ $class = $name . '-image';
+ if($args['class']) $class .= ' ' . $args['class'];
+
+ ob_start();
+
+ $full = wp_get_attachment_image_src($image, $name . '-xl');
+ $lazy = wp_get_attachment_image_src($image, 'lazy');
+ $alt = get_post_meta( $image, '_wp_attachment_image_alt', true );
+
+ $srcsets = [];
+ foreach($sizes as $size => $multiplier) {
+ $file = wp_get_attachment_image_src($image, $name . '-' . $size);
+ $srcsets[] = $file[0] . ' ' . $file[1] . 'w';
+ }
+
+ $atts = [
+ 'class' => $class,
+ 'src' => $full[0],
+ 'srcset' => implode(', ', $srcsets),
+ 'width' => $width,
+ 'height' => $height,
+ 'alt' => $alt,
+ ];
+
+ if($args['lazy']):
+ $atts['class'] .= ' lazy';
+ $atts['src'] = $lazy[0];
+ $atts['srcset'] = null;
+ $atts['data-src'] = $full[0];
+ $atts['data-srcset'] = implode(', ', $srcsets);
+ endif;
+
+ ?>
+
+ $value):
+ if($value) echo $att . '="' . $value . '" ';
+ endforeach; ?>
+ />
+
+ $video):
+ if($video):
+ $sizes[$size] = $video['width'];
+ endif;
+ endforeach;
+
+ if(!empty($sizes)):
+ return json_encode($sizes);
+ else:
+ return false;
+ endif;
+ }
+
+ public function smallest($video_srcset = [])
+ {
+ if(empty($video_srcset)) return false;
+
+ $smallest = null;
+
+ foreach($video_srcset as $size => $video):
+ if($smallest) continue;
+ if($video) $smallest = $size;
+ endforeach;
+
+ return $smallest;
+ }
+}
diff --git a/app/View/Composers/App.php b/app/View/Composers/App.php
index 0d870d4..9797355 100644
--- a/app/View/Composers/App.php
+++ b/app/View/Composers/App.php
@@ -3,6 +3,7 @@
namespace App\View\Composers;
use Roots\Acorn\View\Composer;
+use App\Utilities;
class App extends Composer
{
@@ -23,7 +24,14 @@ class App extends Composer
public function with()
{
return [
+ 'Colour' => new Utilities\Colour,
+ 'VideoSrcset' => new Utilities\VideoSrcset,
+ 'ImageSrcset' => new Utilities\ImageSrcset,
'siteName' => $this->siteName(),
+ 'siteLogo' => @file_get_contents(get_template_directory() . '/resources/images/logo-rhythm-road-entertainment.svg'),
+ 'company_legal' => get_field('badegg_company_legal', 'option'),
+ 'company_tel' => get_field('badegg_company_tel', 'option'),
+ 'company_email' => get_field('badegg_company_email', 'option'),
];
}
diff --git a/app/View/Composers/Socials.php b/app/View/Composers/Socials.php
new file mode 100644
index 0000000..47115b7
--- /dev/null
+++ b/app/View/Composers/Socials.php
@@ -0,0 +1,35 @@
+ get_posts([
+ 'post_type' => 'social',
+ 'order' => 'ASC',
+ 'orderby' => 'menu_order name',
+ 'posts_per_page' => -1,
+ 'fields' => 'ids',
+ ]),
+ ];
+ }
+}
diff --git a/app/setup.php b/app/setup.php
index 695a7b3..705c663 100644
--- a/app/setup.php
+++ b/app/setup.php
@@ -122,3 +122,20 @@ add_action('widgets_init', function () {
'id' => 'sidebar-footer',
] + $config);
});
+
+add_filter('admin_post_thumbnail_size', function(){
+ return "medium";
+});
+
+add_action( 'init', __NAMESPACE__ . '\\cors', 15 );
+function cors() {
+
+ if(WP_ENV == 'development'):
+ header( 'Access-Control-Allow-Origin: *' );
+ endif;
+
+}
+
+$image_srcset = new Utilities\ImageSrcset;
+$image_srcset->add(['name' => 'hero', 'width' => 1920, 'height' => 1000]);
+add_image_size('lazy', 50, 50);
diff --git a/composer.json b/composer.json
index 97e64d1..870d4b7 100644
--- a/composer.json
+++ b/composer.json
@@ -39,7 +39,8 @@
}
},
"require": {
- "php": ">=8.1"
+ "php": ">=8.1",
+ "ourcodeworld/name-that-color": "dev-master"
},
"require-dev": {
"laravel/pint": "^1.13"
diff --git a/composer.lock b/composer.lock
index 4d1abeb..ae732c0 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,8 +4,58 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "d8fb7181c59363e264a92e0c7c1c932f",
- "packages": [],
+ "content-hash": "4a53dd50b29d4fb05ac63597d41276d0",
+ "packages": [
+ {
+ "name": "ourcodeworld/name-that-color",
+ "version": "dev-master",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/ourcodeworld/name-that-color.git",
+ "reference": "758b1f9b4b521da63f0ae4226e80cae620b0f648"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/ourcodeworld/name-that-color/zipball/758b1f9b4b521da63f0ae4226e80cae620b0f648",
+ "reference": "758b1f9b4b521da63f0ae4226e80cae620b0f648",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.0"
+ },
+ "default-branch": true,
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "ourcodeworld\\NameThatColor\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "mit"
+ ],
+ "authors": [
+ {
+ "name": "Carlos Delgado",
+ "email": "dev@ourcodeworld.com",
+ "homepage": "https://ourcodeworld.com"
+ }
+ ],
+ "description": "A non-official PHP port of the NTC JS library to find out the name of the closest matching color.",
+ "keywords": [
+ "color converted",
+ "hex",
+ "hsl",
+ "name that color",
+ "rgb"
+ ],
+ "support": {
+ "issues": "https://github.com/ourcodeworld/name-that-color/issues",
+ "source": "https://github.com/ourcodeworld/name-that-color/tree/master"
+ },
+ "time": "2018-08-03T18:14:49+00:00"
+ }
+ ],
"packages-dev": [
{
"name": "laravel/pint",
diff --git a/functions.php b/functions.php
index 1a56319..f5a34ef 100644
--- a/functions.php
+++ b/functions.php
@@ -60,7 +60,10 @@ function autoload_psr4($name) {
autoload_psr4('PostTypes');
autoload_psr4('ACF');
+autoload_psr4('Utilities');
autoload_psr4('Admin');
+autoload_psr4('Blocks');
+autoload_psr4('Ajax');
/*
|--------------------------------------------------------------------------
diff --git a/resources/acf/group_block_bad_example.json b/resources/acf/group_block_bad_example.json
new file mode 100644
index 0000000..46929d9
--- /dev/null
+++ b/resources/acf/group_block_bad_example.json
@@ -0,0 +1,144 @@
+{
+ "key": "group_block_bad_example",
+ "title": "Block: Bad Example",
+ "fields": [
+ {
+ "key": "field_676599038e31d",
+ "label": "",
+ "name": "",
+ "aria-label": "",
+ "type": "message",
+ "instructions": "",
+ "required": 0,
+ "conditional_logic": 0,
+ "wrapper": {
+ "width": "",
+ "class": "",
+ "id": ""
+ },
+ "message": "
{{ @$data['blurb'] }}
+