Browse Source

Restore catalog, add more helpers.

pull/40/head
Ned Zimmerman 8 years ago
parent
commit
d131fcff97
No known key found for this signature in database
GPG Key ID: FF56334A013120CA
  1. 33
      app/controllers/FrontPage.php
  2. 35
      app/controllers/PageCatalog.php
  3. 28
      inc/helpers/namespace.php
  4. 24
      page-catalog.php
  5. 3
      partials/content-front-page.php
  6. 89
      partials/content-page-catalog.php
  7. 69
      views/page-catalog.blade.php
  8. 3
      views/partials/page-header.blade.php
  9. 4
      webpack.mix.js

33
app/controllers/FrontPage.php

@ -1,33 +0,0 @@
<?php
namespace Aldine;
use Sober\Controller\Controller;
class FrontPage extends Controller
{
public function blockCount()
{
global $_wp_sidebars_widgets;
if (!empty($_wp_sidebars_widgets['front-page-block'])) {
return count($_wp_sidebars_widgets['front-page-block']);
}
return 1;
}
public function latestBooksTitle()
{
$title = get_option('pb_front_page_catalog_title');
if ($title) {
return $title;
}
return __('Our Latest Titles', 'aldine');
}
public function catalogData()
{
$page = (get_query_var('page')) ? get_query_var('page') : 1;
return App::catalogData($page, 3);
}
}

35
app/controllers/PageCatalog.php

@ -1,35 +0,0 @@
<?php
namespace Aldine;
use Sober\Controller\Controller;
class PageCatalog extends Controller
{
public function licenses()
{
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 [];
}
}
public function subjectGroups()
{
return \Pressbooks\Metadata\get_thema_subjects();
}
public function catalogData()
{
$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') : '';
return App::catalogData($page, 9, $orderby, $license, $subject);
}
}

28
inc/helpers/namespace.php

@ -7,6 +7,19 @@
namespace Aldine\Helpers;
/**
* Get block count.
*
* @return int
*/
function get_block_count() {
global $_wp_sidebars_widgets;
if ( ! empty( $_wp_sidebars_widgets['front-page-block'] ) ) {
return count( $_wp_sidebars_widgets['front-page-block'] );
}
return 1;
}
/**
* Get catalog data.
*
@ -48,6 +61,21 @@ function get_catalog_data( $page = 1, $per_page = 10, $orderby = 'title', $licen
}
}
/**
* Get licenses for catalog display.
*
* @return array
*/
function get_catalog_licenses() {
if ( class_exists( '\\Pressbooks\\Licensing' ) ) {
$licenses = ( new \Pressbooks\Licensing() )->getSupportedTypes();
foreach ( $licenses as $key => $value ) {
$licenses[ $key ] = preg_replace( '/\([^)]+\)/', '', $value['desc'] );
}
return $licenses;
}
return [];
}
/**
*

24
page-catalog.php

@ -0,0 +1,24 @@
<?php
/**
* The template for displaying the catalog page
*
* Template Name: Catalog
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
*
* @package Aldine
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main">
<?php get_template_part( 'partials/content', 'page-catalog' ); ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
get_sidebar();
get_footer();

3
partials/content-front-page.php

@ -11,9 +11,10 @@
<?php
use function Aldine\Helpers\get_block_count;
use function Aldine\Helpers\get_catalog_data;
$block_count = 1;
$block_count = get_block_count();
$front_page_catalog = get_option( 'pb_front_page_catalog' );
$latest_books_title = get_option( 'pb_front_page_catalog_title', __( 'Our Latest Titles', 'aldine' ) );
$page = ( get_query_var( 'page' ) ) ? get_query_var( 'page' ) : 1;

89
partials/content-page-catalog.php

@ -0,0 +1,89 @@
<?php
/**
* Template part for displaying the catalog page content
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
*
* @package Aldine
*/
?>
<?php
use function Aldine\Helpers\get_catalog_data;
use function Aldine\Helpers\get_catalog_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();
$subject_groups = ( function_exists( '\\Pressbooks\\Metadata\\get_thema_subjects' ) ) ? \Pressbooks\Metadata\get_thema_subjects() : [];
?>
<?php get_template_part( 'partials/page', 'header' ); ?>
<section class="network-catalog">
<div class="controls">
<div class="search">
<h2><a href="#search"><?php _e( 'Search by titles or keyword', 'aldine' ); ?> <svg class="arrow" width="13" height="8" viewBox="0 0 13 8" xmlns="http://www.w3.org/2000/svg"><path d="M6.255 8L0 0h12.51z" fill="#b01109" fill-rule="evenodd"/></svg></a></h2>
</div>
<div class="filters">
<a href="#filter"><?php _e( 'Filter by', 'aldine' ); ?> <svg class="arrow" width="13" height="8" viewBox="0 0 13 8" xmlns="http://www.w3.org/2000/svg"><path d="M6.255 8L0 0h12.51z" fill="#b01109" fill-rule="evenodd"/></svg></a>
<div id="filter" class="filter-groups">
<?php foreach ( $subject_groups as $key => $val ) : ?>
<div class="<?php echo $key; ?> subjects" id="<?php echo $key; ?>">
<a href="#<?php echo $key; ?>"><?php echo $val['label']; ?> <svg class="arrow" width="13" height="8" viewBox="0 0 13 8" xmlns="http://www.w3.org/2000/svg"><path d="M6.255 8L0 0h12.51z" fill="#b01109" fill-rule="evenodd"/></svg></a>
<ul class="filter-list">
<?php foreach ( $val['children'] as $k => $v ) :
if ( strlen( $k ) === 2 ) : ?>
<li><a data-filter="{{ $k }}"><?php echo $v; ?><span class="close">&times;</span></a></li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</div>
<?php endforeach; ?>
</div>
<div class="licenses" id="licenses">
<a href="#licenses"><?php _e( 'Licenses', 'aldine' ); ?><svg class="arrow" width="13" height="8" viewBox="0 0 13 8" xmlns="http://www.w3.org/2000/svg"><path d="M6.255 8L0 0h12.51z" fill="#b01109" fill-rule="evenodd"/></svg></a>
<ul class="filter-list">
<?php foreach ( $licenses as $key => $value ) : ?>
<li><a data-filter="<?php echo $key; ?>"><?php echo $value; ?><span class="close">&times;</span></a></li>
<?php endforeach; ?>
</ul>
</div>
</div>
<div class="sort">
<a href="#sort"><?php _e( 'Sort by', 'aldine' ); ?> <svg class="arrow" width="13" height="8" viewBox="0 0 13 8" xmlns="http://www.w3.org/2000/svg"><path d="M6.255 8L0 0h12.51z" fill="#b01109" fill-rule="evenodd"/></svg></a>
<ul id="sort" class="sorts">
<li><a data-sort="title" href="<?php echo "/catalog/page/$current_page/?orderby=title"; ?>"><?php _e( 'Title', 'aldine' ); ?></a></li>
<li><a data-sort="subject" href="<?php echo "/catalog/page/$current_page/?orderby=subject"; ?>"><?php _e( 'Subject', 'aldine' ); ?></a></li>
<li><a data-sort="latest" href="<?php echo "/catalog/page/$current_page/?orderby=latest"; ?>"><?php _e( 'Latest', 'aldine' ); ?></a></li>
</ul>
</div>
</div>
<div class="books">
<?php foreach ( $catalog_data['books'] as $book ) :
include( locate_template( 'partials/book.php' ) );
endforeach; ?>
</div>
<?php if ( $catalog_data['pages'] > 1 ) : ?>
<nav class="catalog-navigation">
<?php if ( $previous_page ) : ?><a class="previous" data-page="<?php echo $previous_page; ?>" href="<?php echo network_home_url( "/catalog/page/$previous_page/" ); ?>"><?php _e( 'Previous', 'aldine' ); ?></a><?php endif; ?>
<div class="pages">
<?php for ( $i = 1; $i <= $catalog_data['pages']; $i++ ) :
if ( $i === $current_page ) : ?>
<span class="current"><?php echo $i; ?></span>
<?php else : ?>
<a href="<?php echo network_home_url( "/catalog/page/$i/" ); ?>"><?php echo $i; ?></a>
<?php endif; ?>
<?php endfor; ?>
</div>
<?php if ( $next_page <= $catalog_data['pages'] ) : ?><a class="next" data-page="<?php echo $next_page; ?>" href="<?php echo network_home_url( "/catalog/page/$next_page/" ); ?>"><?php _e( 'Next', 'aldine' ); ?></a><?php endif; ?>
</nav>
<?php endif; ?>
</section>

69
views/page-catalog.blade.php

@ -1,69 +0,0 @@
{{--
Template Name: Catalog
--}}
@extends('layouts.app')
@section('content')
@include('partials.page-header')
<section class="network-catalog">
<div class="controls">
<div class="search">
<h2><a href="#search">{{ __('Search by titles or keyword', 'aldine') }} <svg class="arrow" width="13" height="8" viewBox="0 0 13 8" xmlns="http://www.w3.org/2000/svg"><path d="M6.255 8L0 0h12.51z" fill="#b01109" fill-rule="evenodd"/></svg></a></h2>
</div>
<div class="filters">
<a href="#filter">{{ __('Filter by', 'aldine') }} <svg class="arrow" width="13" height="8" viewBox="0 0 13 8" xmlns="http://www.w3.org/2000/svg"><path d="M6.255 8L0 0h12.51z" fill="#b01109" fill-rule="evenodd"/></svg></a>
<div id="filter" class="filter-groups">
@foreach($subject_groups as $key => $val)
<div class="{{ $key }} subjects" id="{{ $key }}">
<a href="#{{ $key }}">{{ $val['label'] }} <svg class="arrow" width="13" height="8" viewBox="0 0 13 8" xmlns="http://www.w3.org/2000/svg"><path d="M6.255 8L0 0h12.51z" fill="#b01109" fill-rule="evenodd"/></svg></a>
<ul class="filter-list">
@foreach($val['children'] as $k => $v)
@if(strlen($k) === 2)
<li><a data-filter="{{ $k }}">{{ $v }}<span class="close">&times;</span></a></li>
@endif
@endforeach
</ul>
</div>
@endforeach
</div>
<div class="licenses" id="licenses">
<a href="#licenses">{{ __('Licenses', 'aldine' ) }}<svg class="arrow" width="13" height="8" viewBox="0 0 13 8" xmlns="http://www.w3.org/2000/svg"><path d="M6.255 8L0 0h12.51z" fill="#b01109" fill-rule="evenodd"/></svg></a>
<ul class="filter-list">
@foreach($licenses as $key => $value)
<li><a data-filter="{{ $key }}">{{ $value }}<span class="close">&times;</span></a></li>
@endforeach
</ul>
</div>
</div>
<div class="sort">
<a href="#sort">{{ __('Sort by', 'aldine') }} <svg class="arrow" width="13" height="8" viewBox="0 0 13 8" xmlns="http://www.w3.org/2000/svg"><path d="M6.255 8L0 0h12.51z" fill="#b01109" fill-rule="evenodd"/></svg></a>
<ul id="sort" class="sorts">
<li><a data-sort="title" href="{{ "/catalog/page/$current_page/?orderby=title" }}">{{ __('Title', 'aldine') }}</a></li>
<li><a data-sort="subject" href="{{ "/catalog/page/$current_page/?orderby=subject" }}">{{ __('Subject', 'aldine') }}</a></li>
<li><a data-sort="latest" href="{{ "/catalog/page/$current_page/?orderby=latest" }}">{{ __('Latest', 'aldine') }}</a></li>
</ul>
</div>
</div>
<div class="books">
@foreach($catalog_data['books'] as $book)
@include('partials.book', ['book' => $book])
@endforeach
</div>
@if($catalog_data['pages'] > 1)
<nav class="catalog-navigation">
@if($previous_page)<a class="previous" data-page="{{ $previous_page }}" href="{{ network_home_url("/catalog/page/$previous_page/") }}">@php(include get_theme_file_path() . '/dist/' . Aldine\asset_dir('images/left-arrow.svg')) {{ __('Previous', 'aldine') }}</a>@endif
<div class="pages">
@for($i = 1; $i <= $catalog_data['pages']; $i++)
@if($i === $current_page)
<span class="current">{{ $i }}</span>
@else
<a href="{{ network_home_url("/catalog/page/$i/") }}">{{ $i }}</a>
@endif
@endfor
</div>
@if($next_page <= $catalog_data['pages'])<a class="next" data-page="{{ $next_page }}" href="{{ network_home_url("/catalog/page/$next_page/") }}">{{ __('Next', 'aldine') }} @php(include get_theme_file_path() . '/dist/' . Aldine\asset_dir('images/right-arrow.svg'))</a>@endif
</nav>
@endif
</section>
@endsection

3
views/partials/page-header.blade.php

@ -1,3 +0,0 @@
<div class="page-header">
<h1>{!! App::title() !!}</h1>
</div>

4
webpack.mix.js

@ -12,7 +12,7 @@ let mix = require( 'laravel-mix' );
*/
const inc = 'inc';
const views = 'views';
const partials = 'partials';
const assets = 'assets';
const dist = 'dist';
@ -27,7 +27,7 @@ mix.browserSync( {
files: [
'*.php',
`${inc}/**/*.php`,
`${views}/**/*.php`,
`${partials}/**/*.php`,
`${dist}/**/*.css`,
`${dist}/**/*.js`,
],

Loading…
Cancel
Save