Browse Source

Configure for use without Pressbooks. (#26)

pull/27/head
Ned Zimmerman 7 years ago committed by GitHub
parent
commit
c8c18de008
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 48
      app/admin.php
  2. 46
      app/controllers/App.php
  3. 12
      app/controllers/PageCatalog.php
  4. 2
      dist/mix-manifest.json
  5. 2
      dist/styles/main.css
  6. 14
      resources/assets/styles/layouts/_header.scss
  7. 20
      resources/views/partials/header.blade.php

48
app/admin.php

@ -79,28 +79,32 @@ add_action('customize_register', function (\WP_Customize_Manager $wp_customize)
'section' => 'pb_network_social', 'section' => 'pb_network_social',
'settings' => 'pb_network_twitter', 'settings' => 'pb_network_twitter',
]); ]);
$wp_customize->add_section('pb_front_page_catalog', [
'title' => __('Front Page Catalog', 'aldine'), if (function_exists('pb_meets_minimum_requirements') && pb_meets_minimum_requirements()) {
'priority' => 25, $wp_customize->add_section('pb_front_page_catalog', [
]); 'title' => __('Front Page Catalog', 'aldine'),
$wp_customize->add_setting('pb_front_page_catalog', [ 'priority' => 25,
'type' => 'option', ]);
]); $wp_customize->add_setting('pb_front_page_catalog', [
$wp_customize->add_control('pb_front_page_catalog', [ 'type' => 'option',
'label' => __('Show Front Page Catalog', 'aldine'), ]);
'section' => 'pb_front_page_catalog', $wp_customize->add_control('pb_front_page_catalog', [
'settings' => 'pb_front_page_catalog', 'label' => __('Show Front Page Catalog', 'aldine'),
'type' => 'checkbox' 'section' => 'pb_front_page_catalog',
]); 'settings' => 'pb_front_page_catalog',
$wp_customize->add_setting('pb_front_page_catalog_title', [ 'type' => 'checkbox'
'type' => 'option', ]);
'sanitize_callback' => 'sanitize_text_field' $wp_customize->add_setting('pb_front_page_catalog_title', [
]); 'type' => 'option',
$wp_customize->add_control('pb_front_page_catalog_title', [ 'sanitize_callback' => 'sanitize_text_field'
'label' => __('Front Page Catalog Title', 'aldine'), ]);
'section' => 'pb_front_page_catalog', $wp_customize->add_control('pb_front_page_catalog_title', [
'settings' => 'pb_front_page_catalog_title', 'label' => __('Front Page Catalog Title', 'aldine'),
]); 'section' => 'pb_front_page_catalog',
'settings' => 'pb_front_page_catalog_title',
]);
}
$wp_customize->add_section('pb_network_contact_form', [ $wp_customize->add_section('pb_network_contact_form', [
'title' => __('Contact Form', 'aldine'), 'title' => __('Contact Form', 'aldine'),
'priority' => 25, 'priority' => 25,

46
app/controllers/App.php

@ -126,28 +126,32 @@ class App extends Controller
public static function catalogData($page = 1, $per_page = 10, $orderby = 'title', $license = '', $subject = '') public static function catalogData($page = 1, $per_page = 10, $orderby = 'title', $license = '', $subject = '')
{ {
$request = new \WP_REST_Request('GET', '/pressbooks/v2/books'); if (function_exists('pb_meets_minimum_requirements') && pb_meets_minimum_requirements()) {
$request->set_query_params([ $request = new \WP_REST_Request('GET', '/pressbooks/v2/books');
'page' => $page, $request->set_query_params([
'per_page' => $per_page, 'page' => $page,
]); 'per_page' => $per_page,
$response = rest_do_request($request); ]);
$pages = $response->headers['X-WP-TotalPages']; $response = rest_do_request($request);
$data = rest_get_server()->response_to_data($response, true); $pages = $response->headers['X-WP-TotalPages'];
$books = []; $data = rest_get_server()->response_to_data($response, true);
foreach ($data as $key => $book) { $books = [];
$book['title'] = $book['metadata']['name']; foreach ($data as $key => $book) {
$book['date-published'] = (isset($book['metadata']['datePublished'])) ? $book['title'] = $book['metadata']['name'];
$book['metadata']['datePublished'] : $book['date-published'] = (isset($book['metadata']['datePublished'])) ?
''; $book['metadata']['datePublished'] :
$book['subject'] = (isset($book['metadata']['keywords'])) ? $book['metadata']['keywords'] : ''; '';
$books[] = $book; $book['subject'] = (isset($book['metadata']['keywords'])) ? $book['metadata']['keywords'] : '';
} $books[] = $book;
if ($orderby === 'latest') { }
$books = wp_list_sort($books, $orderby, 'desc'); if ($orderby === 'latest') {
$books = wp_list_sort($books, $orderby, 'desc');
} else {
$books = wp_list_sort($books, $orderby);
}
return ['pages' => $pages, 'books' => $books];
} else { } else {
$books = wp_list_sort($books, $orderby); return ['pages' => 0, 'books' => []];
} }
return ['pages' => $pages, 'books' => $books];
} }
} }

12
app/controllers/PageCatalog.php

@ -8,11 +8,15 @@ class PageCatalog extends Controller
{ {
public function licenses() public function licenses()
{ {
$licenses = (new \Pressbooks\Licensing())->getSupportedTypes(); if (function_exists('pb_meets_minimum_requirements') && pb_meets_minimum_requirements()) {
foreach ($licenses as $key => $value) { $licenses = (new \Pressbooks\Licensing())->getSupportedTypes();
$licenses[$key] = preg_replace("/\([^)]+\)/", '', $value['desc']); foreach ($licenses as $key => $value) {
$licenses[$key] = preg_replace("/\([^)]+\)/", '', $value['desc']);
}
return $licenses;
} else {
return [];
} }
return $licenses;
} }
public function subjectGroups() public function subjectGroups()

2
dist/mix-manifest.json vendored

@ -1,5 +1,5 @@
{ {
"/scripts/main.js": "/scripts/main.js?id=39e1eeb8ed8aa60c4413", "/scripts/main.js": "/scripts/main.js?id=39e1eeb8ed8aa60c4413",
"/styles/main.css": "/styles/main.css?id=c39f8348a65d1cc30ad8", "/styles/main.css": "/styles/main.css?id=be9f897fa23508d206d7",
"/scripts/customizer.js": "/scripts/customizer.js?id=4237643703cf0c22354e" "/scripts/customizer.js": "/scripts/customizer.js?id=4237643703cf0c22354e"
} }

2
dist/styles/main.css vendored

File diff suppressed because one or more lines are too long

14
resources/assets/styles/layouts/_header.scss

@ -178,17 +178,17 @@
&:focus { &:focus {
color: var(--primary, $brand-primary); color: var(--primary, $brand-primary);
} }
}
&:nth-child(1) { &--catalog {
margin-right: auto; margin-right: auto;
} }
&:nth-child(2) { &--contact {
margin: 0 1em 0 auto; margin: 0 1em 0 auto;
}
} }
.sep { &--sep {
display: inline-block; display: inline-block;
margin: 0 0.5em; margin: 0 0.5em;
} }

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

@ -7,16 +7,20 @@
<a class="toggle" href="#navigation">{{ __('Toggle menu', 'aldine') }}<span class="toggle__icon"></span></a> <a class="toggle" href="#navigation">{{ __('Toggle menu', 'aldine') }}<span class="toggle__icon"></span></a>
<a class="banner__brand" href="{{ home_url('/') }}"><span class="clip">{{ get_bloginfo('name', 'display') }}</span>{!! $site_logo !!}</a> <a class="banner__brand" href="{{ home_url('/') }}"><span class="clip">{{ get_bloginfo('name', 'display') }}</span>{!! $site_logo !!}</a>
<nav class="banner__navigation" id="navigation"> <nav class="banner__navigation" id="navigation">
<a href="{{ home_url('/catalog') }}">Catalog</a> @if(function_exists('pb_meets_minimum_requirements') && pb_meets_minimum_requirements())
<a href="#contact">Contact</a> <a class="banner__navigation--catalog" href="{{ home_url('/catalog') }}">Catalog</a>
@endif
@if(get_option('pb_network_contact_form'))
<a class="banner__navigation--contact" href="#contact">Contact</a>
@endif
@if(!is_user_logged_in()) @if(!is_user_logged_in())
<a href="{{ wp_login_url() }}">{{ __('Sign in', 'aldine') }}</a> <a class="banner__navigation--signin" href="{{ wp_login_url() }}">{{ __('Sign in', 'aldine') }}</a>
<span class="sep">/</span> <span class="banner__navigation--sep">/</span>
<a href="{{ network_home_url('/wp-signup.php') }}">{{ __('Sign up', 'aldine') }}</a> <a class="banner__navigation--signup" href="{{ network_home_url('/wp-signup.php') }}">{{ __('Sign up', 'aldine') }}</a>
@else @else
<a href="{{ admin_url() }}">{{ __('Admin', 'aldine') }}</a> <a class="banner__navigation--admin" href="{{ admin_url() }}">{{ __('Admin', 'aldine') }}</a>
<span class="sep">/</span> <span class="banner__navigation--sep">/</span>
<a href="{{ wp_logout_url() }}">{{ __('Sign out', 'aldine') }}</a> <a class="banner__navigation--signout" href="{{ wp_logout_url() }}">{{ __('Sign out', 'aldine') }}</a>
@endif @endif
</nav> </nav>
<header class="banner__branding"> <header class="banner__branding">

Loading…
Cancel
Save