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',
'settings' => 'pb_network_twitter',
]);
$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_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_front_page_catalog',
'settings' => 'pb_front_page_catalog_title',
]);
if (function_exists('pb_meets_minimum_requirements') && pb_meets_minimum_requirements()) {
$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_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_front_page_catalog',
'settings' => 'pb_front_page_catalog_title',
]);
}
$wp_customize->add_section('pb_network_contact_form', [
'title' => __('Contact Form', 'aldine'),
'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 = '')
{
$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']['keywords'])) ? $book['metadata']['keywords'] : '';
$books[] = $book;
}
if ($orderby === 'latest') {
$books = wp_list_sort($books, $orderby, 'desc');
if (function_exists('pb_meets_minimum_requirements') && pb_meets_minimum_requirements()) {
$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']['keywords'])) ? $book['metadata']['keywords'] : '';
$books[] = $book;
}
if ($orderby === 'latest') {
$books = wp_list_sort($books, $orderby, 'desc');
} else {
$books = wp_list_sort($books, $orderby);
}
return ['pages' => $pages, 'books' => $books];
} 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()
{
$licenses = (new \Pressbooks\Licensing())->getSupportedTypes();
foreach ($licenses as $key => $value) {
$licenses[$key] = preg_replace("/\([^)]+\)/", '', $value['desc']);
if (function_exists('pb_meets_minimum_requirements') && pb_meets_minimum_requirements()) {
$licenses = (new \Pressbooks\Licensing())->getSupportedTypes();
foreach ($licenses as $key => $value) {
$licenses[$key] = preg_replace("/\([^)]+\)/", '', $value['desc']);
}
return $licenses;
} else {
return [];
}
return $licenses;
}
public function subjectGroups()

2
dist/mix-manifest.json vendored

@ -1,5 +1,5 @@
{
"/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"
}

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 {
color: var(--primary, $brand-primary);
}
}
&:nth-child(1) {
margin-right: auto;
}
&--catalog {
margin-right: auto;
}
&:nth-child(2) {
margin: 0 1em 0 auto;
}
&--contact {
margin: 0 1em 0 auto;
}
.sep {
&--sep {
display: inline-block;
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="banner__brand" href="{{ home_url('/') }}"><span class="clip">{{ get_bloginfo('name', 'display') }}</span>{!! $site_logo !!}</a>
<nav class="banner__navigation" id="navigation">
<a href="{{ home_url('/catalog') }}">Catalog</a>
<a href="#contact">Contact</a>
@if(function_exists('pb_meets_minimum_requirements') && pb_meets_minimum_requirements())
<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())
<a href="{{ wp_login_url() }}">{{ __('Sign in', 'aldine') }}</a>
<span class="sep">/</span>
<a href="{{ network_home_url('/wp-signup.php') }}">{{ __('Sign up', 'aldine') }}</a>
<a class="banner__navigation--signin" href="{{ wp_login_url() }}">{{ __('Sign in', 'aldine') }}</a>
<span class="banner__navigation--sep">/</span>
<a class="banner__navigation--signup" href="{{ network_home_url('/wp-signup.php') }}">{{ __('Sign up', 'aldine') }}</a>
@else
<a href="{{ admin_url() }}">{{ __('Admin', 'aldine') }}</a>
<span class="sep">/</span>
<a href="{{ wp_logout_url() }}">{{ __('Sign out', 'aldine') }}</a>
<a class="banner__navigation--admin" href="{{ admin_url() }}">{{ __('Admin', 'aldine') }}</a>
<span class="banner__navigation--sep">/</span>
<a class="banner__navigation--signout" href="{{ wp_logout_url() }}">{{ __('Sign out', 'aldine') }}</a>
@endif
</nav>
<header class="banner__branding">

Loading…
Cancel
Save