Browse Source

Add latest books widget.

pull/3/head
Ned Zimmerman 7 years ago
parent
commit
064a1a1e54
No known key found for this signature in database
GPG Key ID: FF56334A013120CA
  1. 5
      app/controllers/Home.php
  2. 22
      app/filters.php
  3. 18
      app/setup.php
  4. 1
      app/widgets.php
  5. 101
      app/widgets/latestbooks.php
  6. 6
      app/widgets/pagebutton.php
  7. 16
      dist/assets.json
  8. BIN
      dist/images/banner-desktop_bcd1d61f.jpg
  9. BIN
      dist/images/banner-mobile_f655d839.jpg
  10. BIN
      dist/images/banner-two_a620635c.jpg
  11. BIN
      dist/images/logo@2x_7d05144c.png
  12. BIN
      dist/images/logo_10675684.png
  13. 1
      dist/scripts/customizer_ec2fc400.js
  14. 1
      dist/scripts/main_ec2fc400.js
  15. 1
      dist/styles/main_ec2fc400.css
  16. 6
      resources/assets/styles/components/_buttons.scss
  17. 60
      resources/assets/styles/layouts/_pages.scss
  18. 11
      resources/functions.php
  19. 6
      resources/views/index.blade.php
  20. 2
      resources/views/partials/header.blade.php

5
app/controllers/Home.php

@ -34,4 +34,9 @@ class Home extends Controller
return $blocks; return $blocks;
} }
public function latestBooksBlock()
{
return is_active_widget(false, false, 'latestbooks');
}
} }

22
app/filters.php

@ -68,3 +68,25 @@ add_filter('comments_template', function ($comments_template) {
); );
return template_path(locate_template(["views/{$comments_template}", $comments_template]) ?: $comments_template); return template_path(locate_template(["views/{$comments_template}", $comments_template]) ?: $comments_template);
}); });
/**
* Remove Admin Bar callback
*/
add_action('admin_bar_init', function () {
remove_action('wp_head', '_admin_bar_bump_cb');
});
/**
* Remove Emoji
* @see https://wordpress.stackexchange.com/questions/185577/disable-emojicons-introduced-with-wp-4-2
*/
add_action('init', function () {
remove_action('admin_print_styles', 'print_emoji_styles');
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('admin_print_scripts', 'print_emoji_detection_script');
remove_action('wp_print_styles', 'print_emoji_styles');
remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
remove_filter('the_content_feed', 'wp_staticize_emoji');
remove_filter('comment_text_rss', 'wp_staticize_emoji');
add_filter( 'emoji_svg_url', '__return_false' );
});

18
app/setup.php

@ -25,30 +25,12 @@ add_action('wp_enqueue_scripts', function () {
* Theme setup * Theme setup
*/ */
add_action('after_setup_theme', function () { add_action('after_setup_theme', function () {
/**
* Enable features from Soil when plugin is activated
* @link https://roots.io/plugins/soil/
*/
add_theme_support('soil-clean-up');
add_theme_support('soil-jquery-cdn');
add_theme_support('soil-nav-walker');
add_theme_support('soil-nice-search');
add_theme_support('soil-relative-urls');
/** /**
* Enable plugins to manage the document title * Enable plugins to manage the document title
* @link https://developer.wordpress.org/reference/functions/add_theme_support/#title-tag * @link https://developer.wordpress.org/reference/functions/add_theme_support/#title-tag
*/ */
add_theme_support('title-tag'); add_theme_support('title-tag');
/**
* Register navigation menus
* @link https://developer.wordpress.org/reference/functions/register_nav_menus/
*/
register_nav_menus([
'primary_navigation' => __('Primary Navigation', 'aldine')
]);
/** /**
* Enable post thumbnails * Enable post thumbnails
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/ * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/

1
app/widgets.php

@ -18,6 +18,7 @@ add_action('widgets_init', function () {
] as $widget) { ] as $widget) {
unregister_widget($widget); unregister_widget($widget);
} }
register_widget('Aldine\LatestBooks');
register_widget('Aldine\LinkButton'); register_widget('Aldine\LinkButton');
register_widget('Aldine\PageButton'); register_widget('Aldine\PageButton');
}); });

101
app/widgets/latestbooks.php

@ -0,0 +1,101 @@
<?php
namespace Aldine;
class LatestBooks extends \WP_Widget
{
/**
* Constructor.
*
* @see WP_Widget::__construct()
*
*/
public function __construct()
{
parent::__construct('latestbooks', __('Latest Books', 'aldine'), [
'description' => esc_html__('Your network&#8217;s latest books.', 'aldine')
]);
}
/**
* Front-end display of widget.
*
* @see WP_Widget::widget()
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
*/
public function widget($args, $instance)
{
$number = (! empty($instance['number'])) ? absint($instance['number']) : 3;
if (!$number)
$number = 3;
if (empty($instance['title'])) {
$instance['title'] = __('Latest Books', 'aldine');
}
echo $args['before_widget'];
echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title'];
$books = wp_remote_get(home_url('/wp-json/pressbooks/v2/books'));
$books = json_decode($books['body'], true); ?>
<div class="books">
<?php for($i = 0; $i < $number; $i++) {
printf(
'<div class="book"><a class="subject" href="">TK</a><a class="title" href="%1$s">%2$s</a><a class="read-more" href="%1$s">%3$s</a></div>',
$books[$i]['link'],
$books[$i]['metadata']['name'],
__('About this book &rarr;', 'aldine')
);
} ?>
</div>
<?php echo $args['after_widget'];
}
/**
* Back-end widget form.
*
* @see WP_Widget::form()
*
* @param array $instance Previously saved values from database.
*/
public function form($instance)
{
$title = ! empty($instance['title']) ? $instance['title'] : '';
$number = ! empty($instance['number']) ? absint($instance['number']) : 3; ?>
<p><label for="<?= $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
<input
class="widefat"
id="<?= $this->get_field_id( 'title' ); ?>"
name="<?= $this->get_field_name( 'title' ); ?>"
type="text"
value="<?= $title; ?>" /></p>
<p><label for="<?= $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of books to show:' ); ?></label>
<input
class="tiny-text"
id="<?= $this->get_field_id( 'number' ); ?>"
name="<?= $this->get_field_name( 'number' ); ?>"
type="number"
step="1"
min="1"
value="<?= $number; ?>"
size="3" /></p>
<?php
}
/**
* Sanitize widget form values as they are saved.
*
* @see WP_Widget::update()
*
* @param array $new_instance Values just sent to be saved.
* @param array $old_instance Previously saved values from database.
*
* @return array Updated safe values to be saved.
*/
public function update($new_instance, $old_instance)
{
$instance = [];
$instance['title'] = ( ! empty($new_instance['title']) ) ? strip_tags($new_instance['title']) : '';
$instance['number'] = (int) $new_instance['number'];
return $instance;
}
}

6
app/widgets/pagebutton.php

@ -51,7 +51,7 @@ class PageButton extends \WP_Widget
public function form($instance) public function form($instance)
{ {
$title = ! empty($instance['title']) ? $instance['title'] : ''; $title = ! empty($instance['title']) ? $instance['title'] : '';
$url = ! empty($instance['page_id']) ? $instance['page_id'] : ''; ?> $page_id = ! empty($instance['page_id']) ? $instance['page_id'] : ''; ?>
<p><label for="<?= esc_attr($this->get_field_id('title')); ?>"><?php _e('Title:', 'aldine'); ?></label> <p><label for="<?= esc_attr($this->get_field_id('title')); ?>"><?php _e('Title:', 'aldine'); ?></label>
<input <input
class="widefat" class="widefat"
@ -63,11 +63,11 @@ class PageButton extends \WP_Widget
<select <select
id="<?= esc_attr($this->get_field_id('page_id')); ?>" id="<?= esc_attr($this->get_field_id('page_id')); ?>"
name="<?= esc_attr($this->get_field_name('page_id')); ?>"> name="<?= esc_attr($this->get_field_name('page_id')); ?>">
<option value="" <?php selected($instance['page_id'], ''); ?>> -- </a> <option value="" <?php selected($page_id, ''); ?>> -- </a>
<?php $pages = get_pages(); <?php $pages = get_pages();
foreach ($pages as $page) { ?> foreach ($pages as $page) { ?>
<option value="<?= $page->ID; ?>" <option value="<?= $page->ID; ?>"
<?php selected(@$instance['page_id'], $page->ID); ?>> <?php selected($page_id, $page->ID); ?>>
<?= $page->post_title; ?> <?= $page->post_title; ?>
</option> </option>
<?php } ?> <?php } ?>

16
dist/assets.json vendored

@ -1,16 +0,0 @@
{
"images/banner-desktop.jpg": "images/banner-desktop_bcd1d61f.jpg",
"images/banner-mobile.jpg": "images/banner-mobile_f655d839.jpg",
"images/banner-two.jpg": "images/banner-two_a620635c.jpg",
"images/logo.png": "images/logo_10675684.png",
"images/logo@2x.png": "images/logo@2x_7d05144c.png",
"vendor/fontawesome-webfont.eot": "vendor/fontawesome-webfont_674f50d2.eot",
"vendor/fontawesome-webfont.eot?v=4.7.0": "vendor/fontawesome-webfont_674f50d2.eot",
"vendor/fontawesome-webfont.svg?v=4.7.0": "vendor/fontawesome-webfont_912ec66d.svg",
"vendor/fontawesome-webfont.ttf?v=4.7.0": "vendor/fontawesome-webfont_b06871f2.ttf",
"vendor/fontawesome-webfont.woff2?v=4.7.0": "vendor/fontawesome-webfont_af7ae505.woff2",
"vendor/fontawesome-webfont.woff?v=4.7.0": "vendor/fontawesome-webfont_fee66e71.woff",
"scripts/customizer.js": "scripts/customizer_ec2fc400.js",
"styles/main.css": "styles/main_ec2fc400.css",
"scripts/main.js": "scripts/main_ec2fc400.js"
}

BIN
dist/images/banner-desktop_bcd1d61f.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 111 KiB

BIN
dist/images/banner-mobile_f655d839.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

BIN
dist/images/banner-two_a620635c.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 MiB

BIN
dist/images/logo@2x_7d05144c.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

BIN
dist/images/logo_10675684.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

1
dist/scripts/customizer_ec2fc400.js vendored

@ -1 +0,0 @@
!function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="/app/themes/pressbooks-aldine/dist/",t(t.s=9)}({0:function(e,t){e.exports=jQuery},10:function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(0),o=n.n(r);wp.customize("blogname",function(e){e.bind(function(e){return o()(".brand").text(e)})})},9:function(e,t,n){e.exports=n(10)}});

1
dist/scripts/main_ec2fc400.js vendored

@ -1 +0,0 @@
!function(t){function n(i){if(e[i])return e[i].exports;var o=e[i]={i:i,l:!1,exports:{}};return t[i].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var e={};n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:i})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},n.p="/app/themes/pressbooks-aldine/dist/",n(n.s=1)}([function(t,n){t.exports=jQuery},function(t,n,e){e(2),t.exports=e(8)},function(t,n,e){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),function(t){var n=e(0),i=(e.n(n),e(3)),o=e(5),r=e(6),c=e(7),u=new i.a({common:o.a,home:r.a,aboutUs:c.a});t(document).ready(function(){return u.loadEvents()})}.call(n,e(0))},function(t,n,e){"use strict";var i=e(4),o=function(t){this.routes=t};o.prototype.fire=function(t,n,e){void 0===n&&(n="init"),""!==t&&this.routes[t]&&"function"==typeof this.routes[t][n]&&this.routes[t][n](e)},o.prototype.loadEvents=function(){var t=this;this.fire("common"),document.body.className.toLowerCase().replace(/-/g,"_").split(/\s+/).map(i.a).forEach(function(n){t.fire(n),t.fire(n,"finalize")}),this.fire("common","finalize")},n.a=o},function(t,n,e){"use strict";n.a=function(t){return""+t.charAt(0).toLowerCase()+t.replace(/[\W_]/g,"|").split("|").map(function(t){return""+t.charAt(0).toUpperCase()+t.slice(1)}).join("").slice(1)}},function(t,n,e){"use strict";(function(t){n.a={init:function(){t(".toggle-menu").click(function(n){n.preventDefault(),t(n.currentTarget).toggleClass("is-active"),t(".primary-navigation").toggleClass("is-visible")})},finalize:function(){}}}).call(n,e(0))},function(t,n,e){"use strict";n.a={init:function(){},finalize:function(){}}},function(t,n,e){"use strict";n.a={init:function(){}}},function(t,n){}]);

1
dist/styles/main_ec2fc400.css vendored

File diff suppressed because one or more lines are too long

6
resources/assets/styles/components/_buttons.scss

@ -23,3 +23,9 @@
color: $brand-primary; color: $brand-primary;
} }
} }
@media (min-width: $medium) {
.button {
width: 275px;
}
}

60
resources/assets/styles/layouts/_pages.scss

@ -37,11 +37,62 @@
.inside { .inside {
width: 100%; width: 100%;
text-align: center;
} }
.widget_linkbutton, &.latest-books {
.widget_pagebutton { box-shadow: unset;
text-align: center; width: 100%;
height: auto;
.inside {
width: 100%;
}
}
.books {
display: flex;
flex-direction: row;
justify-content: center;
.book {
width: 367px;
height: 386px;
margin: 113px 30px 0;
padding: 0 29.5px;
border: solid 2px $brand-secondary;
background-color: $brand-secondary;
// transition: 0.4s all;
a {
font-family: Karla, sans-serif;
color: $white;
text-decoration: none;
}
.subject {
display: block;
height: 91px;
margin-top: 22px;
font-size: 24px;
text-align: center;
}
.title {
display: block;
height: 329px - 115px;
font-size: 30px;
font-weight: 500;
text-align: center;
}
.read-more {
display: block;
height: auto;
font-size: 18px;
text-align: left;
}
}
} }
} }
@ -68,7 +119,7 @@
.one-two + .block { .one-two + .block {
background: transparent; background: transparent;
border: solid 2px $brand-primary; border: solid 2px $brand-primary;
margin-bottom: 401px; // margin-bottom: 401px;
&::after { &::after {
position: absolute; position: absolute;
@ -76,6 +127,7 @@
top: 1840px; top: 1840px;
content: ""; content: "";
display: block; display: block;
display: none;
width: 100vw; width: 100vw;
height: 600px; height: 600px;
z-index: -1; z-index: -1;

11
resources/functions.php

@ -61,7 +61,16 @@ array_map(function ($file) use ($sage_error) {
if (!locate_template($file, true, true)) { if (!locate_template($file, true, true)) {
$sage_error(sprintf(__('Error locating <code>%s</code> for inclusion.', 'aldine'), $file), 'File not found'); $sage_error(sprintf(__('Error locating <code>%s</code> for inclusion.', 'aldine'), $file), 'File not found');
} }
}, ['helpers', 'setup', 'filters', 'admin', 'widgets', 'widgets/linkbutton', 'widgets/pagebutton']); }, [
'helpers',
'setup',
'filters',
'admin',
'widgets',
'widgets/latestbooks',
'widgets/linkbutton',
'widgets/pagebutton'
]);
/** /**
* Here's what's happening with these hooks: * Here's what's happening with these hooks:

6
resources/views/index.blade.php

@ -10,7 +10,7 @@
</div> </div>
@elseif($block_count < 5) @elseif($block_count < 5)
@for($i = 0; $i < $block_count; $i++) @for($i = 0; $i < $block_count; $i++)
<div class="block block-{{ $i + 1 }}"> <div class="block block-{{ $i + 1 }}@if($latest_books_block === $home_blocks[$i]) latest-books @endif">
<div class="inside"> <div class="inside">
@php(dynamic_sidebar($home_blocks[$i])) @php(dynamic_sidebar($home_blocks[$i]))
</div> </div>
@ -19,7 +19,7 @@
@elseif($block_count === 5) @elseif($block_count === 5)
<div class="one-two"> <div class="one-two">
@for($i = 0; $i < 2; $i++) @for($i = 0; $i < 2; $i++)
<div class="block block-{{ $i + 1 }}"> <div class="block block-{{ $i + 1 }}@if($latest_books_block === $home_blocks[$i]) latest-books @endif">
<div class="inside"> <div class="inside">
@php(dynamic_sidebar($home_blocks[$i])) @php(dynamic_sidebar($home_blocks[$i]))
</div> </div>
@ -27,7 +27,7 @@
@endfor @endfor
</div> </div>
@for($i = 2; $i < $block_count; $i++) @for($i = 2; $i < $block_count; $i++)
<div class="block block-{{ $i + 1 }}"> <div class="block block-{{ $i + 1 }}@if($latest_books_block === $home_blocks[$i]) latest-books @endif">
<div class="inside"> <div class="inside">
@php(dynamic_sidebar($home_blocks[$i])) @php(dynamic_sidebar($home_blocks[$i]))
</div> </div>

2
resources/views/partials/header.blade.php

@ -10,6 +10,8 @@
<span class="sep">/</span> <span class="sep">/</span>
<a class="signup" href="{{ network_home_url('/wp-signup.php') }}">{{ __('Sign up', 'aldine') }}</a> <a class="signup" href="{{ network_home_url('/wp-signup.php') }}">{{ __('Sign up', 'aldine') }}</a>
@else @else
<a class="admin" href="{{ admin_url() }}">{{ __('Admin', 'aldine') }}</a>
<span class="sep">/</span>
<a class="signin" href="{{ wp_logout_url() }}">{{ __('Sign out', 'aldine') }}</a> <a class="signin" href="{{ wp_logout_url() }}">{{ __('Sign out', 'aldine') }}</a>
@endif @endif
</nav> </nav>

Loading…
Cancel
Save