Browse Source

Merge branch dev into gutenberg

pull/46/head
Ned Zimmerman 8 years ago
parent
commit
64f5a94592
No known key found for this signature in database
GPG Key ID: FF56334A013120CA
  1. 35
      404.php
  2. BIN
      assets/images/header.jpg
  3. 45
      assets/scripts/catalog-admin.js
  4. 7
      assets/styles/aldine.scss
  5. 16
      assets/styles/components/_book.scss
  6. 8
      assets/styles/components/_forms.scss
  7. 3
      assets/styles/editor.scss
  8. 0
      assets/styles/layouts/_footer.scss
  9. 9
      assets/styles/layouts/_header.scss
  10. 0
      assets/styles/layouts/_page-catalog.scss
  11. 0
      assets/styles/layouts/_page-home.scss
  12. 0
      assets/styles/layouts/_page.scss
  13. 13
      assets/styles/layouts/_pages.scss
  14. 3
      assets/styles/layouts/_tinymce.scss
  15. BIN
      dist/images/header.jpg
  16. 11
      dist/mix-manifest.json
  17. 2
      dist/scripts/aldine.js
  18. 2
      dist/scripts/blocks/page-section/block.js
  19. 1
      dist/scripts/catalog-admin.js
  20. 2
      dist/scripts/customizer.js
  21. 2
      dist/styles/aldine.css
  22. 2
      dist/styles/editor.css
  23. 45
      functions.php
  24. 40
      inc/actions/namespace.php
  25. 76
      inc/admin/namespace.php
  26. 116
      inc/helpers/namespace.php
  27. 6333
      package-lock.json
  28. 7
      package.json
  29. 29
      page-catalog.php
  30. 12
      partials/content-front-page.php
  31. 20
      partials/content-page-catalog.php
  32. 1
      webpack.mix.js
  33. 1088
      yarn.lock

35
404.php

@ -12,44 +12,13 @@ get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main">
<section class="error-404 not-found">
<section class="error-404 not-found page-section">
<header class="page-header">
<h1 class="page-title"><?php esc_html_e( 'Oops! That page can&rsquo;t be found.', 'pressbooks-aldine' ); ?></h1>
</header><!-- .page-header -->
<div class="page-content">
<p><?php esc_html_e( 'It looks like nothing was found at this location. Maybe try one of the links below or a search?', 'pressbooks-aldine' ); ?></p>
<?php
get_search_form();
the_widget( 'WP_Widget_Recent_Posts' );
?>
<div class="widget widget_categories">
<h2 class="widget-title"><?php esc_html_e( 'Most Used Categories', 'pressbooks-aldine' ); ?></h2>
<ul>
<?php
wp_list_categories( [
'orderby' => 'count',
'order' => 'DESC',
'show_count' => 1,
'title_li' => '',
'number' => 10,
] );
?>
</ul>
</div><!-- .widget -->
<?php
/* translators: %1$s: smiley */
$archive_content = '<p>' . sprintf( esc_html__( 'Try looking in the monthly archives. %1$s', 'pressbooks-aldine' ), convert_smilies( ':)' ) ) . '</p>';
the_widget( 'WP_Widget_Archives', 'dropdown=1', "after_title=</h2>$archive_content" );
the_widget( 'WP_Widget_Tag_Cloud' );
?>
<p><?php esc_html_e( 'It looks like nothing was found at this location.', 'pressbooks-aldine' ); ?></p>
</div><!-- .page-content -->
</section><!-- .error-404 -->

BIN
assets/images/header.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 176 KiB

After

Width:  |  Height:  |  Size: 240 KiB

45
assets/scripts/catalog-admin.js

@ -0,0 +1,45 @@
/* global ajaxurl, PB_Aldine_Admin */
( function ( $ ) {
$( document ).ready( function () {
$( '.wrap' ).on( 'click', '.notice-dismiss', function () {
$( this ).parent( '#message' ).fadeOut( 500, function () {
$( this ).remove();
} );
} );
$( 'input.in-catalog' ).on( 'change', function () {
let book_id = $( this ).parent( 'td' ).siblings( 'th' ).children( 'input' ).val();
let in_catalog = $( this ).prop( 'checked' );
$.ajax( {
url: ajaxurl,
type: 'POST',
data: {
action: 'pressbooks_aldine_update_catalog',
book_id: book_id,
in_catalog: in_catalog,
_ajax_nonce: PB_Aldine_Admin.aldineAdminNonce,
},
success: function (){
if ( $( '#message' ).length < 1 ) {
$( '<div id="message" class="updated notice is-dismissible">' ).html( '<p><strong>'+PB_Aldine_Admin.catalog_updated+'</strong></p><button type="button" class="notice-dismiss"><span class="screen-reader-text">'+PB_Aldine_Admin.dismiss_notice+'</span></button>' ).hide().insertAfter( '.wrap h1' ).fadeIn( 500 );
} else {
$( '#message' ).fadeOut( 500, function () {
$( this ).remove();
$( '<div id="message" class="updated notice is-dismissible">' ).html( '<p><strong>'+PB_Aldine_Admin.catalog_updated+'</strong></p><button type="button" class="notice-dismiss"><span class="screen-reader-text">'+PB_Aldine_Admin.dismiss_notice+'</span></button>' ).hide().insertAfter( '.wrap h1' ).fadeIn( 500 );
} );
}
},
error: function ( jqXHR, textStatus, errorThrown ) {
if ( $( '#message' ).length < 1 ) {
$( '<div id="message" class="error notice is-dismissible">' ).html( '<p><strong>'+PB_Aldine_Admin.catalog_not_updated+'</strong></p><button type="button" class="notice-dismiss"><span class="screen-reader-text">'+PB_Aldine_Admin.dismiss_notice+'</span></button>' ).hide().insertAfter( '.wrap h1' ).fadeIn( 500 );
} else {
$( '#message' ).fadeOut( 500, function () {
$( this ).remove();
$( '<div id="message" class="error notice is-dismissible">' ).html( '<p><strong>'+PB_Aldine_Admin.catalog_not_updated+'</strong></p><button type="button" class="notice-dismiss"><span class="screen-reader-text">'+PB_Aldine_Admin.dismiss_notice+'</span></button>' ).hide().insertAfter( '.wrap h1' ).fadeIn( 500 );
} );
}
},
} );
} );
} );
} )( jQuery );

7
assets/styles/aldine.scss

@ -12,7 +12,8 @@
@import "common/global";
@import "components/book";
@import "components/forms";
@import "layouts/footer";
@import "layouts/header";
@import "layouts/front-page";
@import "layouts/pages";
@import "layouts/catalog";
@import "layouts/page";
@import "layouts/page-home";
@import "layouts/page-catalog";

16
assets/styles/components/_book.scss

@ -1,20 +1,20 @@
.book {
display: flex;
flex-direction: column;
justify-content: space-between;
justify-content: flex-start;
width: 100%;
max-width: 22.9375rem;
height: 24.125rem;
margin: 0 0 2rem;
padding: 1.5rem 1rem 2rem;
@media #{$breakpoint-not-small} { padding: 1.5rem 1.85rem 2.1875rem; }
border: solid 2px var(--accent, $brand-accent);
background: var(--accent, $brand-accent);
border: solid 2px var(--accent);
background: var(--accent);
a {
margin: 0;
font-family: $font-family-sans-serif;
color: var(--accent-fg, #fff);
color: var(--accent-fg);
text-decoration: none;
text-align: center;
}
@ -30,13 +30,15 @@
&__subject {
margin: 0;
font-size: 0.8rem;
@media #{$breakpoint-not-small} { font-size: 1.25rem; }
font-size: 0.75rem;
@media #{$breakpoint-not-small} {
font-size: 1rem;
}
text-align: left;
}
&__read-more {
margin: 0;
margin: auto 0 0;
font-size: 1rem;
@media #{$breakpoint-not-small} { font-size: 1.125rem; }
text-align: left;

8
assets/styles/components/_forms.scss

@ -16,7 +16,7 @@ textarea {
border-top: 0;
border-right: 0;
border-left: 0;
border-bottom: solid 2px var(--black, #000);
border-bottom: solid 2px var(--black);
border-radius: 0;
padding: 0 0 1.5em;
font-size: 1rem;
@ -40,7 +40,7 @@ input[type="submit"] {
width: rem(354);
::placeholder {
color: #000;
color: var(--black);
}
&__notice {
@ -52,11 +52,11 @@ input[type="submit"] {
text-align: center;
&--error {
color: #c00;
color: var(--error, #c00);
}
&--success {
color: #070;
color: var(--success, #070);
}
}

3
assets/styles/editor.scss

@ -1,7 +1,8 @@
@import '~aetna/assets/styles/common/_variables.scss';
@import '~aetna/assets/styles/common/_global.scss';
#tinymce.wp-editor {
body#tinymce {
margin: 12px !important;
@import '~aetna/assets/styles/components/_buttons.scss';
@import '~aetna/assets/styles/layouts/_page-sections.scss';
}

0
assets/styles/layouts/_posts.scss → assets/styles/layouts/_footer.scss

9
assets/styles/layouts/_header.scss

@ -12,6 +12,10 @@
@media #{$breakpoint-large} {
height: 880px;
.header__inside {
position: relative;
z-index: 99;
}
}
}
@ -31,8 +35,8 @@
height: 540px;
@media #{$breakpoint-large} {
height: 300px;
margin: 120px 0;
height: 160px;
margin: 80px 0 0;
}
.entry-title {
@ -49,6 +53,7 @@
.entry-description {
font-family: $font-family-sans-serif;
font-size: 1.125rem;
margin-top: 0;
margin-bottom: 0;
text-align: center;
max-width: 100%;

0
assets/styles/layouts/_catalog.scss → assets/styles/layouts/_page-catalog.scss

0
assets/styles/layouts/_front-page.scss → assets/styles/layouts/_page-home.scss

0
assets/styles/layouts/_sidebar.scss → assets/styles/layouts/_page.scss

13
assets/styles/layouts/_pages.scss

@ -1,13 +0,0 @@
// .page:not(.home) article {
// .entry-header h1 {
// @extend .h2;
// }
// @extend .page-section;
// text-align: left;
// width: 100%;
// max-width: rem(800);
// margin-top: calc(-80%);
// margin-left: auto;
// margin-right: auto;
// }

3
assets/styles/layouts/_tinymce.scss

@ -1,3 +0,0 @@
body#tinymce {
margin: 12px !important;
}

BIN
dist/images/header.jpg vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 176 KiB

After

Width:  |  Height:  |  Size: 240 KiB

11
dist/mix-manifest.json vendored

@ -1,8 +1,9 @@
{
"/scripts/aldine.js": "/scripts/aldine.js?id=23474d19014434f02b3f",
"/styles/aldine.css": "/styles/aldine.css?id=00b0c10d93f464c01cc5",
"/styles/editor.css": "/styles/editor.css?id=10e3f4b144847aa8d75e",
"/scripts/aldine.js": "/scripts/aldine.js?id=ba190765ddbe404a6d2d",
"/styles/aldine.css": "/styles/aldine.css?id=fa7bbb302e39b92990db",
"/styles/editor.css": "/styles/editor.css?id=d96762ab5918cde0c2e1",
"/styles/blocks/page-section/editor.css": "/styles/blocks/page-section/editor.css?id=d41d8cd98f00b204e980",
"/scripts/customizer.js": "/scripts/customizer.js?id=decf119933e3b2d4b210",
"/scripts/blocks/page-section/block.js": "/scripts/blocks/page-section/block.js?id=28da8f65e0922aad6041"
"/scripts/customizer.js": "/scripts/customizer.js?id=1b0d3cfc1d85f460af53",
"/scripts/catalog-admin.js": "/scripts/catalog-admin.js?id=d25f1240496bd3607338",
"/scripts/blocks/page-section/block.js": "/scripts/blocks/page-section/block.js?id=0d61a9b8d8de8775309e"
}

2
dist/scripts/aldine.js vendored

File diff suppressed because one or more lines are too long

2
dist/scripts/blocks/page-section/block.js vendored

@ -1 +1 @@
!function(e){var t={};function a(o){if(t[o])return t[o].exports;var n=t[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,a),n.l=!0,n.exports}a.m=e,a.c=t,a.d=function(e,t,o){a.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:o})},a.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(t,"a",t),t},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.p="",a(a.s=2)}({2:function(e,t,a){e.exports=a("plbo")},plbo:function(e,t){var a,o,n,c,l;a=window.wp.blocks,o=window.wp.i18n,n=window.wp.element,c=window._,l=n.createElement,wp.blocks.registerBlockType("aldine/page-section",{title:o.__("Page Section","pressbooks-aldine"),icon:"flag",category:"layout",attributes:{title:{type:"array",source:"children",selector:"h2"},content:{type:"array",source:"children",selector:"p"}},edit:function(e){var t=e.focus?e.focus.editable||"title":null,n=e.attributes;return l("div",{className:e.className},l(a.Editable,{tagName:"h2",className:"page-section__title",inline:!1,placeholder:o.__("About Pressbooks","pressbooks-aldine"),value:n.title,onChange:function(t){e.setAttributes({title:t})},focus:"title"===t?focus:null,onFocus:function(t){e.setFocus(c.extend({},t,{editable:"title"}))}}),l(a.Editable,{tagName:"p",className:"page-section__content",inline:!1,placeholder:o.__("Kogi ennui ugh plaid, hella neutra kitsch cloud bread next level twee taiyaki. Live-edge paleo fixie whatever farm-to-table snackwave, meditation fam man braid next level viral. Four loko waistcoat mustache cloud bread activated charcoal food truck pabst roof party ugh kitsch raw denim edison bulb man braid 8-bit try-hard. Activated charcoal put a bird on it tilde meggings farm-to-table coloring book. Before they sold out four dollar toast stumptown actually.","pressbooks-gutenberg"),value:n.content,onChange:function(t){e.setAttributes({content:t})},focus:"content"===t?focus:null,onFocus:function(t){e.setFocus(c.extend({},t,{editable:"content"}))}}),l("p",{classname:"page-section__cta"},l(a.Editable,{tagName:"a",className:"call-to-action",inline:!1,placeholder:o.__("Learn More","pressbooks-aldine"),value:n.cta,onChange:function(t){e.setAttributes({cta:t})},focus:"cta"===t?focus:null,onFocus:function(t){e.setFocus(c.extend({},t,{editable:"cta"}))}})))},save:function(e){var t=e.attributes;return l("div",{className:e.className},l("h2",{className:"page-section__title"},t.title),l("p",{className:"page-section__content"},t.content),l("p",{classname:"page-section__cta"},l("a",{classname:"call-to-action"},t.cta)))}})}});
!function(e){var t={};function a(o){if(t[o])return t[o].exports;var n=t[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,a),n.l=!0,n.exports}a.m=e,a.c=t,a.d=function(e,t,o){a.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:o})},a.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(t,"a",t),t},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.p="",a(a.s=3)}({3:function(e,t,a){e.exports=a("plbo")},plbo:function(e,t){var a,o,n,c,l;a=window.wp.blocks,o=window.wp.i18n,n=window.wp.element,c=window._,l=n.createElement,wp.blocks.registerBlockType("aldine/page-section",{title:o.__("Page Section","pressbooks-aldine"),icon:"flag",category:"layout",attributes:{title:{type:"array",source:"children",selector:"h2"},content:{type:"array",source:"children",selector:"p"}},edit:function(e){var t=e.focus?e.focus.editable||"title":null,n=e.attributes;return l("div",{className:e.className},l(a.Editable,{tagName:"h2",className:"page-section__title",inline:!1,placeholder:o.__("About Pressbooks","pressbooks-aldine"),value:n.title,onChange:function(t){e.setAttributes({title:t})},focus:"title"===t?focus:null,onFocus:function(t){e.setFocus(c.extend({},t,{editable:"title"}))}}),l(a.Editable,{tagName:"p",className:"page-section__content",inline:!1,placeholder:o.__("Kogi ennui ugh plaid, hella neutra kitsch cloud bread next level twee taiyaki. Live-edge paleo fixie whatever farm-to-table snackwave, meditation fam man braid next level viral. Four loko waistcoat mustache cloud bread activated charcoal food truck pabst roof party ugh kitsch raw denim edison bulb man braid 8-bit try-hard. Activated charcoal put a bird on it tilde meggings farm-to-table coloring book. Before they sold out four dollar toast stumptown actually.","pressbooks-gutenberg"),value:n.content,onChange:function(t){e.setAttributes({content:t})},focus:"content"===t?focus:null,onFocus:function(t){e.setFocus(c.extend({},t,{editable:"content"}))}}),l("p",{classname:"page-section__cta"},l(a.Editable,{tagName:"a",className:"call-to-action",inline:!1,placeholder:o.__("Learn More","pressbooks-aldine"),value:n.cta,onChange:function(t){e.setAttributes({cta:t})},focus:"cta"===t?focus:null,onFocus:function(t){e.setFocus(c.extend({},t,{editable:"cta"}))}})))},save:function(e){var t=e.attributes;return l("div",{className:e.className},l("h2",{className:"page-section__title"},t.title),l("p",{className:"page-section__content"},t.content),l("p",{classname:"page-section__cta"},l("a",{classname:"call-to-action"},t.cta)))}})}});

1
dist/scripts/catalog-admin.js vendored

File diff suppressed because one or more lines are too long

2
dist/scripts/customizer.js vendored

File diff suppressed because one or more lines are too long

2
dist/styles/aldine.css vendored

File diff suppressed because one or more lines are too long

2
dist/styles/editor.css vendored

File diff suppressed because one or more lines are too long

45
functions.php

@ -25,6 +25,7 @@ if ( ! class_exists( 'PressbooksMix\\Assets' ) ) {
$includes = [
'actions',
'activation',
'admin',
'customizer',
'filters',
'helpers',
@ -36,21 +37,29 @@ foreach ( $includes as $include ) {
}
require get_template_directory() . '/inc/intervention.php';
add_action( 'after_switch_theme', '\\Aldine\\Activation\\create_default_content', 10 );
add_action( 'after_switch_theme', '\\Aldine\\Activation\\create_menus', 11 );
add_action( 'after_switch_theme', '\\Aldine\\Activation\\assign_menus', 12 );
add_action( 'admin_bar_init', '\\Aldine\\Actions\\remove_admin_bar_callback' );
add_action( 'after_setup_theme', '\\Aldine\\Actions\\setup' );
add_action( 'after_setup_theme', '\\Aldine\\Actions\\content_width', 0 );
add_action( 'wp_head', '\\Aldine\\Actions\\output_custom_colors' );
add_action( 'init', '\\Aldine\\Actions\\add_editor_styles' );
add_filter( 'mce_buttons', '\\Aldine\\Filters\\add_style_select' );
add_filter( 'tiny_mce_before_init', '\\Aldine\\Filters\\add_blocks' );
add_filter( 'body_class', '\\Aldine\\Filters\\body_classes' );
add_filter( 'excerpt_more', '\\Aldine\\Filters\\excerpt_more' );
add_filter( 'query_vars', '\\Aldine\\Filters\\register_query_vars' );
add_filter( 'wp_nav_menu_items', '\\Aldine\\Filters\\adjust_menu', 10, 2 );
add_action( 'widgets_init', '\\Aldine\\Actions\\widgets_init' );
add_action( 'wp_enqueue_scripts', '\\Aldine\\Actions\\enqueue_assets' );
add_action( 'customize_register', '\\Aldine\\Customizer\\customize_register' );
add_action( 'customize_preview_init', '\\Aldine\\Customizer\\customize_preview_js' );
add_action( 'after_switch_theme', '\Aldine\Activation\create_default_content', 10 );
add_action( 'after_switch_theme', '\Aldine\Activation\create_menus', 11 );
add_action( 'after_switch_theme', '\Aldine\Activation\assign_menus', 12 );
add_action( 'admin_bar_init', '\Aldine\Actions\remove_admin_bar_callback' );
add_action( 'after_setup_theme', '\Aldine\Actions\setup' );
add_action( 'after_setup_theme', '\Aldine\Actions\content_width', 0 );
add_action( 'wp_head', '\Aldine\Actions\output_custom_colors' );
add_action( 'init', '\Aldine\Actions\add_editor_styles' );
add_action( 'admin_init', '\Aldine\Actions\hide_catalog_content_editor' );
add_filter( 'mce_buttons', '\Aldine\Filters\add_style_select' );
add_filter( 'tiny_mce_before_init', '\Aldine\Filters\add_blocks' );
add_filter( 'body_class', '\Aldine\Filters\body_classes' );
add_filter( 'excerpt_more', '\Aldine\Filters\excerpt_more' );
add_filter( 'query_vars', '\Aldine\Filters\register_query_vars' );
add_filter( 'wp_nav_menu_items', '\Aldine\Filters\adjust_menu', 10, 2 );
add_action( 'widgets_init', '\Aldine\Actions\widgets_init' );
add_action( 'wp_enqueue_scripts', '\Aldine\Actions\enqueue_assets' );
add_action( 'customize_register', '\Aldine\Customizer\customize_register' );
add_action( 'customize_preview_init', '\Aldine\Customizer\customize_preview_js' );
// Catalog page: Network admin controls
add_action( 'admin_enqueue_scripts', '\Aldine\Admin\admin_scripts' );
add_action( 'wp_ajax_pressbooks_aldine_update_catalog', '\Aldine\Admin\update_catalog' );
add_filter( 'wpmu_blogs_columns', '\Aldine\Admin\catalog_columns' );
add_action( 'manage_blogs_custom_column', '\Aldine\Admin\catalog_column', 1, 3 );
add_action( 'manage_sites_custom_column', '\Aldine\Admin\catalog_column', 1, 3 );

40
inc/actions/namespace.php

@ -204,18 +204,36 @@ function remove_admin_bar_callback() {
}
/**
* Hide content editor for Catalog page.
*/
function hide_catalog_content_editor() {
$post_id = $_GET['post'] ?? null ;
if ( ! isset( $post_id ) ) {
return;
}
$pagename = get_the_title( $post_id );
if ( $pagename === 'Catalog' ) {
add_action( 'edit_form_after_title', function() {
printf( '<p>%s</p>', __( 'This page displays your network catalog, so there is no content to edit.', 'pressbooks-aldine' ) );
} );
remove_post_type_support( 'page', 'editor' );
remove_post_type_support( 'page', 'thumbnail' );
}
}
/*
* Enqueue block editor assets.
*/
function enqueue_block_editor_assets() {
$assets = new Assets( 'pressbooks-aldine', 'theme' );
$assets->setSrcDirectory( 'assets' )->setDistDirectory( 'dist' );
wp_enqueue_script( 'aldine/page-section-block', $assets->getPath( 'scripts/blocks/page-section/block.js' ), [
'wp-blocks',
'wp-i18n',
'wp-element',
], null );
wp_enqueue_style( 'aldine/page-section-block', $assets->getPath( 'scripts/blocks/page-section/block.css' ), [
'wp-blocks',
], null );
$assets = new Assets( 'pressbooks-aldine', 'theme' );
$assets->setSrcDirectory( 'assets' )->setDistDirectory( 'dist' );
wp_enqueue_script( 'aldine/page-section-block', $assets->getPath( 'scripts/blocks/page-section/block.js' ), [
'wp-blocks',
'wp-i18n',
'wp-element',
], null );
wp_enqueue_style( 'aldine/page-section-block', $assets->getPath( 'scripts/blocks/page-section/block.css' ), [
'wp-blocks',
], null );
}

76
inc/admin/namespace.php

@ -0,0 +1,76 @@
<?php
/**
* @package Aldine
*/
namespace Aldine\Admin;
use PressbooksMix\Assets;
/**
* Uses old option to provide a simpler upgrade path from pressbooks-publisher theme
*/
const BLOG_OPTION = 'pressbooks_publisher_in_catalog';
/**
* @param string $hook
*/
function admin_scripts( $hook ) {
if ( 'sites.php' !== $hook ) {
return;
}
$assets = new Assets( 'pressbooks-aldine', 'theme' );
$assets->setSrcDirectory( 'assets' )->setDistDirectory( 'dist' );
wp_enqueue_script( 'pressbooks-aldine-admin', $assets->getPath( 'scripts/catalog-admin.js' ), [ 'jquery' ] );
wp_localize_script(
'pressbooks-aldine-admin', 'PB_Aldine_Admin', [
'aldineAdminNonce' => wp_create_nonce( 'pressbooks-aldine-admin' ),
'catalog_updated' => __( 'Catalog updated.', 'pressbooks-aldine' ),
'catalog_not_updated' => __( 'Sorry, but your catalog was not updated. Please try again.', 'pressbooks-aldine' ),
'dismiss_notice' => __( 'Dismiss this notice.', 'pressbooks-aldine' ),
]
);
}
/**
*
*/
function update_catalog() {
if ( ! current_user_can( 'manage_network' ) || ! check_ajax_referer( 'pressbooks-aldine-admin' ) ) {
return;
}
$blog_id = absint( $_POST['book_id'] );
$in_catalog = $_POST['in_catalog'];
if ( $in_catalog === 'true' ) {
update_blog_option( $blog_id, \Aldine\Admin\BLOG_OPTION, 1 );
} else {
delete_blog_option( $blog_id, \Aldine\Admin\BLOG_OPTION );
}
}
/**
* @param array $columns
*
* @return array
*/
function catalog_columns( $columns ) {
$columns['in_catalog'] = __( 'In Catalog', 'pressbooks-aldine' );
return $columns;
}
/**
* @param string $column
* @param int $blog_id
*/
function catalog_column( $column, $blog_id ) {
if ( 'in_catalog' === $column && ! is_main_site( $blog_id ) ) { ?>
<input class="in-catalog" type="checkbox" name="in_catalog" value="1" aria-label="<?php echo esc_attr_x( 'Show in Catalog', 'pressbooks-aldine' ); ?>" <?php checked( get_blog_option( $blog_id, \Aldine\Admin\BLOG_OPTION ), 1 ); ?> <?php
if ( ! get_blog_option( $blog_id, 'blog_public' ) ) { ?>disabled="disabled" title="<?php echo esc_attr_x( 'This book is private, so you can&rsquo;t display it in your catalog.', 'pressbooks-aldine' ); ?>"<?php } ?> />
<?php }
}

116
inc/helpers/namespace.php

@ -7,49 +7,87 @@
namespace Aldine\Helpers;
use Pressbooks\Licensing;
use Pressbooks\Book;
use function \Pressbooks\Metadata\book_information_to_schema;
/**
* Get catalog data.
*
* @param int $page
* @param int $per_page
* @param string $orderby
* @param string $license
* @param string $subject
*
* @return array
*/
function get_catalog_data( $page = 1, $per_page = 10, $orderby = 'title', $license = '', $subject = '' ) {
if ( defined( 'PB_PLUGIN_VERSION' ) ) {
$request = new \WP_REST_Request( 'GET', '/pressbooks/v2/books' );
$request->set_query_params([
'page' => $page,
'per_page' => $per_page,
]);
$response = rest_do_request( $request );
$pages = $response->headers['X-WP-TotalPages'];
$data = rest_get_server()->response_to_data( $response, true );
$books = [];
foreach ( $data as $key => $book ) {
$book['title'] = $book['metadata']['name'];
$book['date-published'] = ( isset( $book['metadata']['datePublished'] ) ) ?
$book['metadata']['datePublished'] :
'';
$book['subject'] = ( isset( $book['metadata']['about'][0] ) )
? $book['metadata']['about'][0]['identifier']
: '';
$books[] = $book;
}
if ( $orderby === 'latest' ) {
$books = wp_list_sort( $books, $orderby, 'desc' );
} else {
$books = wp_list_sort( $books, $orderby );
if ( ! defined( 'PB_PLUGIN_VERSION' ) ) {
return [ 'pages' => 0, 'books' => [] ]; // Bail
}
/**
* Filter the WP_Site_Query args for the catalog display.
*
* @since 5.0.0
*/
$args = apply_filters(
'pb_aldine_catalog_query_args',
/** @deprecated */
apply_filters(
'pb_publisher_catalog_query_args',
[
'public' => '1',
'network_id' => get_network()->site_id,
]
)
);
/** @var \WP_Site $site */
$sites_in_catalog = [];
$sites = new \WP_Site_Query( $args );
foreach ( $sites->sites as $site ) {
// TODO: Using switch_to_blog() is a performance problem. Use [ https://core.trac.wordpress.org/ticket/37923 ] when available.
switch_to_blog( $site->blog_id );
if ( get_option( \Aldine\Admin\BLOG_OPTION ) ) {
$site->pb_title = get_bloginfo( 'name' ); // Cool hack! :face_with_rolling_eyes:
$sites_in_catalog[] = $site;
}
return [ 'pages' => $pages, 'books' => $books ];
restore_current_blog();
}
if ( $orderby === 'latest' ) {
$sites_in_catalog = wp_list_sort( $sites_in_catalog, 'last_updated', 'DESC' );
} else {
return [ 'pages' => 0, 'books' => [] ];
$sites_in_catalog = wp_list_sort( $sites_in_catalog, 'pb_title', 'ASC' );
}
$total_pages = ceil( count( $sites_in_catalog ) / $per_page );
$offset = ( $page - 1 ) * $per_page;
$books = [];
foreach ( $sites_in_catalog as $i => $site ) {
if ( $i < $offset ) {
continue;
}
switch_to_blog( $site->blog_id );
$schema = book_information_to_schema( Book::getBookInformation() );
$book['title'] = $schema['name'];
$book['date-published'] = $schema['datePublished'] ?? '';
$book['subject'] = $schema['about'][0]['identifier'] ?? '';
$book['link'] = get_blogaddress_by_id( $site->blog_id );
$book['metadata'] = $schema;
$books[] = $book;
restore_current_blog();
if ( count( $books ) >= $per_page ) {
break;
}
}
return [ 'pages' => $total_pages, 'books' => $books ];
}
/**
* Get licenses for catalog display.
*
@ -70,6 +108,7 @@ function get_catalog_licenses() {
* Get licenses currently in use.
*
* @param array $catalog_data
*
* @return array
*/
function get_available_licenses( $catalog_data ) {
@ -90,6 +129,7 @@ function get_available_licenses( $catalog_data ) {
* Get subjects currently in use.
*
* @param array $catalog_data
*
* @return array
*/
function get_available_subjects( $catalog_data ) {
@ -107,6 +147,7 @@ function get_available_subjects( $catalog_data ) {
* Return the default (non-page) menu items.
*
* @param string $items
*
* @return string $items
*/
function get_default_menu( $items = '' ) {
@ -151,9 +192,10 @@ function get_default_menu( $items = '' ) {
);
}
/* @codingStandardsIgnoreStart $items .= sprintf(
'<li class="header__search js-search"><div class="header__search__form">%s</div></li>',
get_search_form( false )
); @codingStandardsIgnoreEnd */
* '<li class="header__search js-search"><div class="header__search__form">%s</div></li>',
* get_search_form( false )
* ); @codingStandardsIgnoreEnd
*/
return $items;
}
@ -162,13 +204,18 @@ function get_default_menu( $items = '' ) {
* Echo the default menu.
*
* @param string $items
* @return null
*/
function default_menu( $args = [], $items = '' ) {
printf(
"<{$args['container']} id='{$args['container_id']}' class='{$args['container_class']}'><ul id='{$args['menu_id']}' class='{$args['menu_class']}'>%s</ul></{$args['container']}>",
get_default_menu( $items )
);
if ( class_exists( '\PressbooksOAuth\OAuth' ) ) {
add_filter( 'pb_oauth_output_button', function( $bool ) {
return false;
} );
do_action( 'pressbooks_oauth_connect' );
}
}
/**
@ -179,7 +226,7 @@ function default_menu( $args = [], $items = '' ) {
*/
function handle_contact_form_submission() {
if ( ! isset( $_POST['pb_root_contact_form_nonce'] ) || ! wp_verify_nonce( $_POST['pb_root_contact_form_nonce'], 'pb_root_contact_form' ) ) {
return; // Security check failed.
return false; // Security check failed.
}
if ( isset( $_POST['submitted'] ) ) {
$output = [];
@ -243,6 +290,7 @@ function handle_contact_form_submission() {
* Does a page have page sections?
*
* @param int $post_id The page.
*
* @return bool
*/
function has_sections( $post_id ) {

6333
package-lock.json generated

File diff suppressed because it is too large Load Diff

7
package.json

@ -41,8 +41,7 @@
"cross-env NODE_ENV=development webpack --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"rmdist": "rimraf dist",
"lint": "npm run -s lint:scripts && npm run -s lint:styles",
"lint:scripts":
"node_modules/eslint/bin/eslint.js \"assets/scripts/**/*.js\"",
"lint:scripts": "node_modules/eslint/bin/eslint.js \"assets/scripts/*.js\"",
"lint:styles":
"node_modules/stylelint/bin/stylelint.js \"assets/styles/**/*.scss\" --syntax scss",
"test": "npm run -s lint"
@ -51,10 +50,10 @@
"node": ">= 6.9.4"
},
"devDependencies": {
"pressbooks-build-tools": "^0.9.0"
"pressbooks-build-tools": "^0.10.0"
},
"dependencies": {
"aetna": "^1.0.0-alpha",
"aetna": "^1.0.0-alpha.1",
"isotope-layout": "^3.0.5",
"jquery-bridget": "^2.0.1",
"js-cookie": "^2.2.0",

29
page-catalog.php

@ -9,12 +9,31 @@
* @package Aldine
*/
use function Aldine\Helpers\get_catalog_data;
use function Aldine\Helpers\get_catalog_licenses;
use function Aldine\Helpers\get_available_subjects;
use function Aldine\Helpers\get_available_licenses;
$current_page = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$orderby = ( get_query_var( 'orderby' ) ) ? get_query_var( 'orderby' ) : 'title';
$subject = ( get_query_var( 'subject' ) ) ? get_query_var( 'subject' ) : '';
$license = ( get_query_var( 'license' ) ) ? get_query_var( 'license' ) : '';
$catalog_data = get_catalog_data( $current_page, 9, $orderby, $license, $subject );
$previous_page = ( $current_page > 1 ) ? $current_page - 1 : 0;
$next_page = $current_page + 1;
$licenses = get_catalog_licenses();
$available_licenses = get_available_licenses( $catalog_data );
$subjects = ( defined( 'PB_PLUGIN_VERSION' ) ) ? \Pressbooks\Metadata\get_thema_subjects() : [];
$available_subjects = get_available_subjects( $catalog_data );
if ( ! empty( $catalog_data['books'] ) ) : ?>
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main">
<?php get_template_part( 'partials/content', 'page-catalog' ); ?>
<?php include( locate_template( 'partials/content-page-catalog.php' ) ); ?>
</main><!-- #main -->
</div><!-- #primary -->
@ -22,3 +41,11 @@ get_header(); ?>
<?php
get_sidebar();
get_footer();
else :
global $wp_query;
$wp_query->set_404();
status_header( 404 );
get_template_part( 404 );
exit();
endif;

12
partials/content-front-page.php

@ -15,10 +15,12 @@ use function Aldine\Helpers\get_catalog_data;
$front_page_catalog = get_option( 'pb_front_page_catalog' );
$latest_books_title = get_option( 'pb_front_page_catalog_title', __( 'Our Latest Titles', 'pressbooks-aldine' ) );
$page = ( get_query_var( 'page' ) ) ? get_query_var( 'page' ) : 1;
$catalog_data = get_catalog_data( $page, 3 );
$previous_page = ( $page > 1 ) ? $page - 1 : 0;
$next_page = $page + 1;
if ( get_option( 'pb_front_page_catalog' ) ) {
$page = ( get_query_var( 'page' ) ) ? get_query_var( 'page' ) : 1;
$catalog_data = get_catalog_data( $page, 3, 'latest' );
$previous_page = ( $page > 1 ) ? $page - 1 : 0;
$next_page = $page + 1;
}
?>
@ -35,7 +37,7 @@ $next_page = $page + 1;
</div><!-- .entry-content -->
</article><!-- #post-<?php the_ID(); ?> -->
<?php if ( get_option( 'pb_front_page_catalog' ) ) : ?>
<?php if ( get_option( 'pb_front_page_catalog' ) && ! empty( $catalog_data['books'] ) ) : ?>
<div id="latest-books" class="latest-books">
<h2 id="latest-books-title"><?php echo $latest_books_title; ?></h2>
<div class="slider" role="region" aria-labelledby="latest-books-title" data-total-pages="<?php echo $catalog_data['pages']; ?>" <?php if ( $next_page <= $catalog_data['pages'] ) : ?>data-next-page="<?php echo $next_page; ?>"<?php endif; ?>>

20
partials/content-page-catalog.php

@ -9,26 +9,6 @@
?>
<?php
use function Aldine\Helpers\get_catalog_data;
use function Aldine\Helpers\get_catalog_licenses;
use function Aldine\Helpers\get_available_subjects;
use function Aldine\Helpers\get_available_licenses;
$current_page = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$orderby = ( get_query_var( 'orderby' ) ) ? get_query_var( 'orderby' ) : 'title';
$subject = ( get_query_var( 'subject' ) ) ? get_query_var( 'subject' ) : '';
$license = ( get_query_var( 'license' ) ) ? get_query_var( 'license' ) : '';
$catalog_data = get_catalog_data( $current_page, 9, $orderby, $license, $subject );
$previous_page = ( $current_page > 1 ) ? $current_page - 1 : 0;
$next_page = $current_page + 1;
$licenses = get_catalog_licenses();
$available_licenses = get_available_licenses( $catalog_data );
$subjects = ( defined( 'PB_PLUGIN_VERSION' ) ) ? \Pressbooks\Metadata\get_thema_subjects() : [];
$available_subjects = get_available_subjects( $catalog_data );
?>
<?php get_template_part( 'partials/page', 'header' ); ?>
<section class="network-catalog">
<form role="form" class="filter-sort" method="get">

1
webpack.mix.js

@ -46,6 +46,7 @@ mix.autoload( { jquery: [ '$', 'window.jQuery', 'jQuery' ] } );
mix
.js( `${assets}/scripts/aldine.js`, `${dist}/scripts` )
.js( `${assets}/scripts/catalog-admin.js`, `${dist}/scripts` )
.js( `${assets}/scripts/customizer.js`, `${dist}/scripts` )
.js(
`${assets}/scripts/blocks/page-section/block.js`,

1088
yarn.lock

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save