From f7ded5dd5de7abb47d9d5a319677459961930318 Mon Sep 17 00:00:00 2001 From: Ned Zimmerman Date: Thu, 24 Aug 2017 16:52:59 -0300 Subject: [PATCH 01/53] Add activation routine (closes #5, closes #6). --- app/activation.php | 70 +++++++++++++++++++++++++++++++++++++++++ resources/functions.php | 1 + 2 files changed, 71 insertions(+) create mode 100644 app/activation.php diff --git a/app/activation.php b/app/activation.php new file mode 100644 index 0000000..f79784f --- /dev/null +++ b/app/activation.php @@ -0,0 +1,70 @@ + [ + 'post_title' => __('About', 'aldine'), + // @codingStandardsIgnoreStart + 'post_content' => apply_filters('pb_root_about_page_content', __('Pressbooks is simple book production software. You can use Pressbooks to publish textbooks, scholarly monographs, syllabi, fiction and non-fiction books, white papers, and more in multiple formats including: + + + +Pressbooks is used by educational institutions around the world as well as authors and publishers. + +For more information about Pressbooks, see here.', 'aldine')) + // @codingstandardsIgnoreEnd + ], + 'help' => [ + 'post_title' => __('Help', 'aldine'), + // @codingStandardsIgnoreStart + 'post_content' => apply_filters('pb_root_help_page_content', __('The easiest way to get started with Pressbooks is to follow our 4 Step Guide to Making a Book on Pressbooks. Or, you can review our Guide to Using Pressbooks. + +If you require further assistance, please contact your network manager.', 'aldine')) + // @codingstandardsIgnoreEnd + ], + 'catalog' => [ + 'post_title' => __('Catalog', 'aldine'), + 'post_content' => '' + ], + 'home' => [ + 'post_title' => __('Home', 'aldine'), + 'post_content' => '' + ], + ]; + + if (! get_site_option('pb_aldine_activated')) { + // Add our pages + $pages = []; + + foreach ($default_pages as $slug => $page) { + $check = get_page_by_path($slug); + if (empty($check)) { + $pages[$slug] = wp_insert_post(array_merge($page, ['post_type' => 'page', 'post_status' => 'publish'])); + } else { + $pages[$slug] = $check->ID; + } + } + + // Set front page to Home + update_option('show_on_front', 'page'); + update_option('page_on_front', $pages['home']); + + // Remove content generated by wp_install_defaults + if (! wp_delete_post(1, true)) { + return; + } + if (! wp_delete_post(2, true)) { + return; + } + if (! wp_delete_comment(1, true)) { + return; + } + + // Add "pb_aldine_activated" site option to enable check above + add_site_option('pb_aldine_activated', true); + } +}); diff --git a/resources/functions.php b/resources/functions.php index a50262d..4e86ac8 100644 --- a/resources/functions.php +++ b/resources/functions.php @@ -65,6 +65,7 @@ array_map(function ($file) use ($sage_error) { 'helpers', 'setup', 'filters', + 'activation', 'admin', 'widgets', 'widgets/latestbooks', From 633eaa75f0960b5ce9e73f778233b98c508d1e20 Mon Sep 17 00:00:00 2001 From: Ned Zimmerman Date: Tue, 29 Aug 2017 12:48:06 -0300 Subject: [PATCH 02/53] Replace widget areas with content blocks; add custom widget area. --- app/admin.php | 56 +++++++++++++-- app/controllers/FrontPage.php | 37 ++++++---- app/setup.php | 16 +---- resources/views/front-page.blade.php | 69 ++++++++++++------- .../views/partials/front-page-block.blade.php | 11 +++ 5 files changed, 133 insertions(+), 56 deletions(-) create mode 100644 resources/views/partials/front-page-block.blade.php diff --git a/app/admin.php b/app/admin.php index 3e5e48a..545a3e6 100644 --- a/app/admin.php +++ b/app/admin.php @@ -36,23 +36,69 @@ add_action('customize_register', function (\WP_Customize_Manager $wp_customize) 'section' => 'pb_network_social', 'settings' => 'pb_network_twitter', ]); - $wp_customize->add_section('pb_network_catalog', [ - 'title' => __('Catalog', 'aldine'), + $wp_customize->add_section('pb_front_page_content', [ + 'title' => __('Front Page Content', 'aldine'), 'priority' => 20, ]); - $wp_customize->add_setting('pb_front_page_catalog'); + for($i = 1; $i < 5; $i++) { + $wp_customize->add_setting("pb_front_page_block_${i}_title", [ + 'type' => 'option', + 'sanitize_callback' => 'sanitize_text_field', + ]); + $wp_customize->add_control("pb_front_page_block_${i}_title", [ + 'label' => sprintf(__('Block %d Title', 'aldine'), $i), + 'section' => 'pb_front_page_content', + 'settings' => "pb_front_page_block_${i}_title", + ]); + $wp_customize->add_setting("pb_front_page_block_${i}_content", [ + 'type' => 'option', + 'sanitize_callback' => 'sanitize_textarea_field', + ]); + $wp_customize->add_control("pb_front_page_block_${i}_content", [ + 'label' => sprintf(__('Block %d Content', 'aldine'), $i), + 'type' => 'textarea', + 'section' => 'pb_front_page_content', + 'settings' => "pb_front_page_block_${i}_content", + ]); + $wp_customize->add_setting("pb_front_page_block_${i}_button_title", [ + 'type' => 'option', + 'sanitize_callback' => 'sanitize_text_field', + ]); + $wp_customize->add_control("pb_front_page_block_${i}_button_title", [ + 'label' => sprintf(__('Block %d Button Title', 'aldine'), $i), + 'section' => 'pb_front_page_content', + 'settings' => "pb_front_page_block_${i}_button_title", + ]); + $wp_customize->add_setting("pb_front_page_block_${i}_button_url", [ + 'type' => 'option', + 'sanitize_callback' => 'esc_url_raw', + ]); + $wp_customize->add_control("pb_front_page_block_${i}_button_url", [ + 'label' => sprintf(__('Block %d Button URL', 'aldine'), $i), + 'section' => 'pb_front_page_content', + 'settings' => "pb_front_page_block_${i}_button_url", + ]); + } + $wp_customize->add_section('pb_front_page_catalog', [ + 'title' => __('Front Page Catalog', 'aldine'), + 'priority' => 25, + ]); + $wp_customize->add_setting('pb_front_page_catalog', [ + 'type' => 'option', + ]); $wp_customize->add_control('pb_front_page_catalog', [ 'label' => __('Show Front Page Catalog', 'aldine'), - 'section' => 'pb_network_catalog', + 'section' => 'pb_front_page_catalog', 'settings' => 'pb_front_page_catalog', 'type' => 'checkbox' ]); $wp_customize->add_setting('pb_front_page_catalog_title', [ + 'type' => 'option', 'sanitize_callback' => 'sanitize_text_field' ]); $wp_customize->add_control('pb_front_page_catalog_title', [ 'label' => __('Front Page Catalog Title', 'aldine'), - 'section' => 'pb_network_catalog', + 'section' => 'pb_front_page_catalog', 'settings' => 'pb_front_page_catalog_title', ]); }); diff --git a/app/controllers/FrontPage.php b/app/controllers/FrontPage.php index 7b39240..c5d611c 100644 --- a/app/controllers/FrontPage.php +++ b/app/controllers/FrontPage.php @@ -9,13 +9,8 @@ class FrontPage extends Controller public function blockCount() { $c = 0; - foreach ([ - 'home-block-1', - 'home-block-2', - 'home-block-3', - 'home-block-4' - ] as $block) { - if (is_active_sidebar($block)) { + for ($i = 1; $i < 5; $i++) { + if (get_option("pb_front_page_block_${i}_content")) { $c++; } } @@ -25,10 +20,23 @@ class FrontPage extends Controller public function blocks() { $blocks = []; - for ($i = 0; $i < 4; $i++) { - if (is_active_sidebar("home-block-$i")) { - $blocks[] = "home-block-$i"; + for ($i = 1; $i < 5; $i++) { + $block = []; + $title = get_option("pb_front_page_block_${i}_title"); + $content = get_option("pb_front_page_block_${i}_content"); + $button_title = get_option("pb_front_page_block_${i}_button_title"); + $button_url = get_option("pb_front_page_block_${i}_button_url"); + if ($title) { + $block['title'] = $title; } + if ($content) { + $block['content'] = wpautop($content); + } + if ($button_title && $button_url) { + $block['button_title'] = $button_title; + $block['button_url'] = $button_url; + } + $blocks[] = $block; } return $blocks; @@ -57,9 +65,12 @@ class FrontPage extends Controller public function latestBooksTitle() { - return (empty(get_theme_mod('pb_front_page_catalog_title'))) ? - __('Our Latest Titles', 'aldine') : - get_theme_mod('pb_front_page_catalog_title'); + $title = get_option('pb_front_page_catalog_title'); + if ($title) { + return $title; + } + + return __('Our Latest Titles', 'aldine'); } public static function latestBooks($page = 1, $per_page = 3) diff --git a/app/setup.php b/app/setup.php index 8ca684f..f91d295 100644 --- a/app/setup.php +++ b/app/setup.php @@ -108,20 +108,8 @@ add_action('widgets_init', function () { 'after_title' => '' ]; register_sidebar([ - 'name' => __('Home Block 1', 'aldine'), - 'id' => 'home-block-1' - ] + $config); - register_sidebar([ - 'name' => __('Home Block 2', 'aldine'), - 'id' => 'home-block-2' - ] + $config); - register_sidebar([ - 'name' => __('Home Block 3', 'aldine'), - 'id' => 'home-block-3' - ] + $config); - register_sidebar([ - 'name' => __('Home Block 4', 'aldine'), - 'id' => 'home-block-4' + 'name' => __('Front Page Content', 'aldine'), + 'id' => 'front-page-block' ] + $config); register_sidebar([ 'name' => __('Network Footer Block 1', 'aldine'), diff --git a/resources/views/front-page.blade.php b/resources/views/front-page.blade.php index 2e521a3..c309737 100644 --- a/resources/views/front-page.blade.php +++ b/resources/views/front-page.blade.php @@ -2,39 +2,60 @@ @section('content') @if($block_count === 0) -
-
-

{{ __('About Pressbooks', 'aldine') }}

-

{{ __('Pressbooks is easy-to-use book writing software that lets you create a book in all the formats you need to publish.', 'aldine')}}

-
-
+ @component('partials.front-page-block', ['index' => 1]) + @slot('title') + {{ __('About Pressbooks', 'aldine') }} + @endslot +

{{ __('Pressbooks is easy-to-use book writing software that lets you create a book in all the formats you need to publish.', 'aldine')}}

+ @slot('button_title') + {{ __('Learn More', 'aldine') }} + @endslot + @slot('button_url') + {{ network_home_url('/about/') }} + @endslot + {!! $block['content'] !!} + @endcomponent @elseif($block_count < 4) - @for($i = 0; $i < $block_count; $i++) -
-
- @php(dynamic_sidebar($blocks[$i])) -
-
- @endfor + @foreach($blocks as $block) + @component('partials.front-page-block', [ + 'index' => $loop->iteration, + 'title' => (isset($block['title'])) ? $block['title'] : false, + 'button_title' => (isset($block['button_title'])) ? $block['button_title'] : false, + 'button_url' => (isset($block['button_url'])) ? $block['button_url'] : false, + ]) + {!! $block['content'] !!} + @endcomponent + @endforeach @elseif($block_count === 4)
@for($i = 0; $i < 2; $i++) -
-
- @php(dynamic_sidebar($blocks[$i])) -
-
+ @component('partials.front-page-block', [ + 'index' => $i + 1, + 'title' => (isset($blocks[$i]['title'])) ? $blocks[$i]['title'] : false, + 'button_title' => (isset($blocks[$i]['button_title'])) ? $blocks[$i]['button_title'] : false, + 'button_url' => (isset($blocks[$i]['button_url'])) ? $blocks[$i]['button_url'] : false, + ]) + {!! $blocks[$i]['content'] !!} + @endcomponent @endfor
@for($i = 2; $i < $block_count; $i++) -
-
- @php(dynamic_sidebar($blocks[$i])) -
-
+ @component('partials.front-page-block', [ + 'index' => $i + 1, + 'title' => (isset($blocks[$i]['title'])) ? $blocks[$i]['title'] : false, + 'button_title' => (isset($blocks[$i]['button_title'])) ? $blocks[$i]['button_title'] : false, + 'button_url' => (isset($blocks[$i]['button_url'])) ? $blocks[$i]['button_url'] : false, + ]) + {!! $blocks[$i]['content'] !!} + @endcomponent @endfor @endif - @if(get_theme_mod('pb_front_page_catalog')) + @if(is_active_sidebar('front-page-block')) + @component('partials.front-page-block', ['index' => 'custom', 'title' => false, 'button_title' => false, 'button_url' => false]) + @php(dynamic_sidebar('front-page-block')) + @endcomponent + @endif + @if(get_option('pb_front_page_catalog')) @include('partials.front-page-catalog') @endif @endsection diff --git a/resources/views/partials/front-page-block.blade.php b/resources/views/partials/front-page-block.blade.php new file mode 100644 index 0000000..23ba36c --- /dev/null +++ b/resources/views/partials/front-page-block.blade.php @@ -0,0 +1,11 @@ +
+
+ @if($title) +

{{ $title }}

+ @endif + {{ $slot }} + @if($button_url && $button_title) + {{ $button_title }} + @endif +
+
From ad5ab28d2ae543511ba6f989c128b244f71a810d Mon Sep 17 00:00:00 2001 From: Ned Zimmerman Date: Tue, 29 Aug 2017 12:52:23 -0300 Subject: [PATCH 03/53] Fix remnant. --- resources/views/front-page.blade.php | 1 - 1 file changed, 1 deletion(-) diff --git a/resources/views/front-page.blade.php b/resources/views/front-page.blade.php index c309737..c8c9254 100644 --- a/resources/views/front-page.blade.php +++ b/resources/views/front-page.blade.php @@ -13,7 +13,6 @@ @slot('button_url') {{ network_home_url('/about/') }} @endslot - {!! $block['content'] !!} @endcomponent @elseif($block_count < 4) @foreach($blocks as $block) From c24f4ee30b2ac393f6ae736b2f3b456e5259bae9 Mon Sep 17 00:00:00 2001 From: Ned Zimmerman Date: Tue, 29 Aug 2017 12:52:52 -0300 Subject: [PATCH 04/53] Fix PHPCS error. --- app/admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/admin.php b/app/admin.php index 545a3e6..c0fd494 100644 --- a/app/admin.php +++ b/app/admin.php @@ -40,7 +40,7 @@ add_action('customize_register', function (\WP_Customize_Manager $wp_customize) 'title' => __('Front Page Content', 'aldine'), 'priority' => 20, ]); - for($i = 1; $i < 5; $i++) { + for ($i = 1; $i < 5; $i++) { $wp_customize->add_setting("pb_front_page_block_${i}_title", [ 'type' => 'option', 'sanitize_callback' => 'sanitize_text_field', From 3bbe4d0077c7acdf135ae84a686ac9099fc8bb6b Mon Sep 17 00:00:00 2001 From: Ned Zimmerman Date: Tue, 29 Aug 2017 14:09:59 -0300 Subject: [PATCH 05/53] Add custom colours. --- app/admin.php | 31 +++++++++ app/setup.php | 64 +++++++++++++++++++ resources/assets/scripts/routes/home.js | 2 +- resources/assets/styles/common/_global.scss | 24 +++++++ .../assets/styles/components/_buttons.scss | 35 +++++++--- resources/assets/styles/layouts/_footer.scss | 1 - resources/assets/styles/layouts/_pages.scss | 8 +-- resources/views/partials/footer.blade.php | 2 +- .../views/partials/front-page-block.blade.php | 4 +- .../partials/front-page-catalog.blade.php | 8 +-- 10 files changed, 155 insertions(+), 24 deletions(-) diff --git a/app/admin.php b/app/admin.php index c0fd494..7f5a053 100644 --- a/app/admin.php +++ b/app/admin.php @@ -14,6 +14,36 @@ add_action('customize_register', function (\WP_Customize_Manager $wp_customize) bloginfo('name'); } ]); + $wp_customize->add_section('pb_network_colors', [ + 'title' => __('Color Scheme', 'aldine'), + 'priority' => 20, + ]); + $wp_customize->add_setting('pb_network_primary_color', [ + 'type' => 'option', + 'default' => '#b01109', + ]); + $wp_customize->add_control(new \WP_Customize_Color_Control( + $wp_customize, + 'pb_network_primary_color', + [ + 'label' => __('Primary Color', 'aldine'), + 'section' => 'pb_network_colors', + 'settings' => 'pb_network_primary_color', + ] + )); + $wp_customize->add_setting('pb_network_secondary_color', [ + 'type' => 'option', + 'default' => '#015d75', + ]); + $wp_customize->add_control(new \WP_Customize_Color_Control( + $wp_customize, + 'pb_network_secondary_color', + [ + 'label' => __('Secondary Color', 'aldine'), + 'section' => 'pb_network_colors', + 'settings' => 'pb_network_secondary_color', + ] + )); $wp_customize->add_section('pb_network_social', [ 'title' => __('Social Media', 'aldine'), 'priority' => 30, @@ -108,4 +138,5 @@ add_action('customize_register', function (\WP_Customize_Manager $wp_customize) */ add_action('customize_preview_init', function () { wp_enqueue_script('aldine/customizer.js', asset_path('scripts/customizer.js'), ['customize-preview'], null, true); + wp_localize_script('aldine/customizer.js', 'SAGE_DIST_PATH', get_theme_file_uri() . '/dist/'); }); diff --git a/app/setup.php b/app/setup.php index f91d295..32618cc 100644 --- a/app/setup.php +++ b/app/setup.php @@ -159,3 +159,67 @@ add_action('after_setup_theme', function () { return ""; }); }); + +add_action('wp_head', function () { + $primary = get_option('pb_network_primary_color'); + $secondary = get_option('pb_network_secondary_color'); + if ($primary || $secondary) { ?> + + { - books.slick('slickAdd', `
+ books.slick('slickAdd', `

Fiction

${book.metadata.name}

About this book →

diff --git a/resources/assets/styles/common/_global.scss b/resources/assets/styles/common/_global.scss index 9bbf9e1..e1024e4 100644 --- a/resources/assets/styles/common/_global.scss +++ b/resources/assets/styles/common/_global.scss @@ -37,3 +37,27 @@ a { color: $brand-primary; text-decoration: none; } + +.primary { + color: $brand-primary; +} + +.bg-primary { + background-color: $brand-primary; +} + +.secondary { + color: $brand-secondary; +} + +.bg-secondary { + background-color: $brand-secondary; +} + +.b--primary { + border-color: $brand-primary; +} + +.b--secondary { + border-color: $brand-secondary; +} diff --git a/resources/assets/styles/components/_buttons.scss b/resources/assets/styles/components/_buttons.scss index 7724c71..6af6a18 100644 --- a/resources/assets/styles/components/_buttons.scss +++ b/resources/assets/styles/components/_buttons.scss @@ -4,9 +4,9 @@ height: 60px; margin-top: 2em; padding: 1.25em; - border: 2px solid $brand-primary; + border: 2px solid $black; border-radius: 3px; - background: $brand-primary; + background: $black; font-family: $font-family-sans-serif; font-size: em(16); font-weight: 600; @@ -20,7 +20,7 @@ &:hover, &:focus { background: $white; - color: $brand-primary; + color: $black; } &.button-wide { @@ -29,19 +29,38 @@ &.button-outline { background: $white; - color: $brand-primary; + color: $black; &:hover, &:focus { - background: $brand-primary; + background: $black; color: $white; } } + &.button-primary { + border-color: $brand-primary; + background: $brand-primary; + + &:hover, + &:focus { + background: $white; + color: $brand-primary; + } + + &.button-outline { + color: $brand-primary; + + &:hover, + &:focus { + background: $brand-primary; + } + } + } + &.button-secondary { - border: 2px solid $brand-secondary; + border-color: $brand-secondary; background: $brand-secondary; - color: $white; &:hover, &:focus { @@ -50,13 +69,11 @@ } &.button-outline { - background: $white; color: $brand-secondary; &:hover, &:focus { background: $brand-secondary; - color: $white; } } } diff --git a/resources/assets/styles/layouts/_footer.scss b/resources/assets/styles/layouts/_footer.scss index e554381..66156ed 100644 --- a/resources/assets/styles/layouts/_footer.scss +++ b/resources/assets/styles/layouts/_footer.scss @@ -1,6 +1,5 @@ .content-info { .network-footer { - background: $brand-secondary; margin-bottom: 0; padding: 60px 42.5px 40px; font-family: $font-family-sans-serif; diff --git a/resources/assets/styles/layouts/_pages.scss b/resources/assets/styles/layouts/_pages.scss index 9d90115..300115d 100644 --- a/resources/assets/styles/layouts/_pages.scss +++ b/resources/assets/styles/layouts/_pages.scss @@ -8,7 +8,6 @@ font-weight: 600; letter-spacing: 2px; line-height: (36/30); - color: $brand-primary; margin: 0; &::before { @@ -41,8 +40,6 @@ .navigation { a { - color: $brand-secondary; - &.slick-disabled { opacity: 0; } @@ -57,8 +54,7 @@ height: 386px; margin: 45px 0 0; padding: 0 29.5px; - border: solid 2px $brand-secondary; - background-color: $brand-secondary; + border: solid 2px; a { font-family: $font-family-sans-serif; @@ -120,7 +116,7 @@ width: 100vw; height: 600px; z-index: -1; - background: url('../images/banner-two.jpg'); + // background: url('../images/banner-two.jpg'); background-position: center; background-repeat: no-repeat; background-size: cover; diff --git a/resources/views/partials/footer.blade.php b/resources/views/partials/footer.blade.php index a8936b5..2d98041 100644 --- a/resources/views/partials/footer.blade.php +++ b/resources/views/partials/footer.blade.php @@ -1,6 +1,6 @@
From abff9583759af3c73a6bfaa7153028aa68488c8e Mon Sep 17 00:00:00 2001 From: Ned Zimmerman Date: Mon, 11 Sep 2017 14:07:00 -0300 Subject: [PATCH 53/53] Fix catalog. --- resources/views/front-page.blade.php | 24 ++++++++++++++++++- .../partials/front-page-catalog.blade.php | 15 ------------ 2 files changed, 23 insertions(+), 16 deletions(-) delete mode 100644 resources/views/partials/front-page-catalog.blade.php diff --git a/resources/views/front-page.blade.php b/resources/views/front-page.blade.php index 231c5bc..f4090b5 100644 --- a/resources/views/front-page.blade.php +++ b/resources/views/front-page.blade.php @@ -19,7 +19,29 @@ @endcomponent @endif @if(get_option('pb_front_page_catalog')) - @include('partials.front-page-catalog') +
+

{{ $latest_books_title }}

+
+
+ @foreach($catalog_data['books'] as $book) + @include('partials.book', ['book' => $book]) + @endforeach +
+ @if($previous_page) + + @endif + @if($next_page <= $catalog_data['pages']) + + @endif +
+ +
@endif @endsection diff --git a/resources/views/partials/front-page-catalog.blade.php b/resources/views/partials/front-page-catalog.blade.php deleted file mode 100644 index 2643d8f..0000000 --- a/resources/views/partials/front-page-catalog.blade.php +++ /dev/null @@ -1,15 +0,0 @@ -
-

{{ $latest_books_title }}

-
-
- @foreach($catalog_data['books'] as $book) - @include('partials.book', ['book' => $book]) - @endforeach -
- @if($previous_page)@endif - @if($next_page <= $catalog_data['pages'])@endif -
- -