Skip to content

Commit

Permalink
Merge pull request #269 from UCDavisLibrary/datalab
Browse files Browse the repository at this point in the history
v3.8.0
  • Loading branch information
spelkey-ucd authored Dec 7, 2023
2 parents f0b815d + 79f63da commit 5c845d8
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 71 deletions.
2 changes: 1 addition & 1 deletion dist/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
}
],
"require": {
"timber/timber": "2.0.0-rc.1"
"timber/timber": "2.0.0"
}
}
8 changes: 6 additions & 2 deletions theme/includes/classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
* Sets up custom endpoints for the wordpress api
*/
class UCDThemeAPI {

public $slug;
public $menuSlug;

public function __construct($slug) {
$this->slug = $slug;
$this->menuSlug = 'menu';
Expand Down Expand Up @@ -60,7 +64,7 @@ public function epcb_subnav( $request ){
}

public function epcb_all_menus( $request ){
$menus = get_terms( 'nav_menu', array( 'hide_empty' => true ) );
$menus = get_terms( 'nav_menu', array( 'hide_empty' => true ) );
return rest_ensure_response($menus);
}

Expand Down Expand Up @@ -143,4 +147,4 @@ private function baseMenuItem($item) {
}
return $out;
}
}
}
4 changes: 4 additions & 0 deletions theme/includes/classes/assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
class UCDThemeAssets {
public $scripts;
public $version;
public $directories;
public $isDevEnv;
public $uris;
public $iconsets;

public function __construct($scripts, $version) {
$this->scripts = $scripts;
Expand Down
22 changes: 14 additions & 8 deletions theme/includes/classes/block-renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
// meant to be inheritied by blocks.php classes in theme and plugins
class UCDThemeBlockRenderer {

public static $registry;
public static $transformationClass;

public $iconsUsed;

public function __construct(){
$this->iconsUsed = [];
add_action( 'init', array( $this, 'register_blocks'));
Expand Down Expand Up @@ -33,7 +38,7 @@ public function register_blocks( ) {
}
foreach ($registry as $name => $block) {
$settings = array(
'api_version' => 2,
'api_version' => 2,
'render_callback' => array($this, 'render_callback')
);
if ( array_key_exists('uses_context', $block) ) {
Expand All @@ -43,15 +48,15 @@ public function register_blocks( ) {
$settings['provides_context'] = $block['provides_context'];
};
register_block_type(
$name,
$name,
$settings
);
}
}

/**
* Renders designated Twig and applies attribute transformations for a registered block
*
*
* NOTE:
* We need access to the block name to determine what twig to render.
* Third 'block' arg is not part of documentation:
Expand All @@ -60,10 +65,10 @@ public function register_blocks( ) {
* https://github.com/WordPress/gutenberg/issues/4671
* https://github.com/WordPress/gutenberg/issues/21797
* https://github.com/WordPress/gutenberg/pull/21925
*
*
*/
public function render_callback($block_attributes, $content, $block) {

// Retrieve metadata from registry
$blockName = $block->name;
if ( !$blockName ) return;
Expand All @@ -89,13 +94,14 @@ public function render_callback($block_attributes, $content, $block) {
$block_attributes = call_user_func(static::$transformationClass . "::" . $transformation, $block_attributes);
}
}
if ( !$block_attributes ) $block_attributes = [];

// check for icons (so we can only load the svgs we actually use)
if ( !isset($this->iconsUsed) || !is_array($this->iconsUsed) ){
$this->iconsUsed = [];
}
if (
array_key_exists('icon', $block_attributes) &&
if (
array_key_exists('icon', $block_attributes) &&
!in_array($block_attributes['icon'], $this->iconsUsed)) {
$this->iconsUsed[] = $block_attributes['icon'];
}
Expand All @@ -117,4 +123,4 @@ public function render_callback($block_attributes, $content, $block) {
Timber::render( $meta['twig'], $context );
return ob_get_clean();
}
}
}
6 changes: 4 additions & 2 deletions theme/includes/classes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class UCDThemeBlocks extends UCDThemeBlockRenderer {
public $editor_script_slug;
public $settings;

public $iconsUsed;

public static $transformationClass = 'UCDThemeBlockTransformations';

function __construct($editor_script_slug, $settings=array()) {
parent::__construct();
$this->editor_script_slug = $editor_script_slug;
Expand All @@ -31,8 +35,6 @@ function __construct($editor_script_slug, $settings=array()) {
add_filter('excerpt_allowed_wrapper_blocks', array($this, 'excerpt_allowed_wrapper_blocks'));
}

public static $transformationClass = 'UCDThemeBlockTransformations';

/**
* Meta for each block goes here.
*/
Expand Down
10 changes: 6 additions & 4 deletions theme/includes/classes/html-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
*</html>
*/
class UCDThemeHtmlImport {

public $templateFile='html-import.php';
public $matchingPath='html-import';
public $queryVar='template';

public function __construct() {
$this->templateFile = 'html-import.php';
$this->matchingPath = "html-import";
$this->queryVar = 'template';

add_filter( 'template_include', [$this, 'loadTemplate'], 99 );
add_filter( 'query_vars', [$this, 'registerQueryVar'] );
Expand Down Expand Up @@ -57,4 +59,4 @@ public function updateHeaders($headers){
return $headers;
}

}
}
12 changes: 7 additions & 5 deletions theme/includes/classes/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
class UcdThemeMenu {

public $menuLocations;

public function __construct() {

// slug => label
Expand All @@ -26,12 +28,12 @@ public function add_to_context( $context ) {
$locations = get_nav_menu_locations();
$context['menu'] = array();
foreach ($this->menuLocations as $slug => $label) {

// add to context if location has menu data
if ( array_key_exists($slug, $locations) && $locations[$slug] ) {
$context['menu'][$slug] = Timber::get_menu($slug);
}

}
return $context;
}
Expand Down Expand Up @@ -67,7 +69,7 @@ public static function getDirectHierarchybyId( $menu, $item_id ){
}
return $out;
}

/**
* @method getDirectHierarchyinMenu
* @description Gets all ancestor menu items of a post in a menu (also menu item of the post itself)
Expand All @@ -78,7 +80,7 @@ public static function getDirectHierarchyinMenu($menu, $post_id=0) {
if ( !$menu->items ) return $out;

foreach ($menu->items as $parent) {

// we are finding the currently displayed page in the menu
if ( !$post_id ) {
if ( $parent->current ) {
Expand Down Expand Up @@ -146,4 +148,4 @@ private static function getMenuItemBasics( $menu_item ){
];
}

}
}
12 changes: 8 additions & 4 deletions theme/includes/classes/meta-data.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<?php

/**
* Sets up extra metadata fields.
* Sets up extra metadata fields.
* Will normally be saved in either the 'wp_termmeta', 'wp_postmeta', or 'wp_usermeta' tables
*/
class UCDThemeMetaData {

public $userContactFields;
public $userMetaFields;


function __construct(){
// Assign a UCD theme color to a category
add_action('category_add_form_fields', array($this, 'display_taxonomy_color'), 4, 1);
Expand Down Expand Up @@ -166,7 +170,7 @@ function save_user_meta($user_id){
}

foreach ($this->userMetaFields as $k => $v) {

// upload profile picture
if ( $v['slug'] == 'profile-picture' ){
if( array_key_exists($v['slug'], $_FILES) && $_FILES[$v['slug']]['error'] === UPLOAD_ERR_OK ) {
Expand Down Expand Up @@ -198,7 +202,7 @@ function save_user_meta($user_id){

update_user_meta( $user_id, $v['slug'], $attach_id );
}

}
else if ( isset($_POST['clear_profile_picture']) ){
delete_user_meta( $user_id, $v['slug'] );
Expand Down Expand Up @@ -259,4 +263,4 @@ function api_taxonomy_color($response, $term, $request){
}
}

?>
?>
18 changes: 10 additions & 8 deletions theme/includes/classes/patterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

// Sets up block patterns for this theme
class UCDLibThemePatterns {

public $slug = 'ucdlib-theme-wp';
public $groupIds = [];

public function __construct(){
$this->slug = 'ucdlib-theme-wp';
$this->groupIds = [];

add_action( 'init', [$this, 'register']);
add_filter( 'render_block' , [$this, 'dedupeIds'], 10, 3);
Expand Down Expand Up @@ -48,7 +50,7 @@ public function register(){
'keywords' => ['core', 'text', 'style'],
]
);

register_block_pattern(
"$this->slug/lang-prize-winner",
[
Expand All @@ -59,7 +61,7 @@ public function register(){
'keywords' => ['lang', 'prize', 'winner', 'list'],
]
);

register_block_pattern(
"$this->slug/lang-prize",
[
Expand Down Expand Up @@ -210,8 +212,8 @@ public function markupCoreTextStyles(){
<!-- wp:ucd-theme/heading {\"content\":\"4th Level Headings\",\"level\":5,\"classSuffix\":\"h6\"} /--></div>
<!-- /wp:group -->
";
}
}

// patterns are wrapped in a group with an id attribute
// ensure these ids are unique if more than one is used on a page
public function dedupeIds($block_content, $block, $instance){
Expand All @@ -232,7 +234,7 @@ public function dedupeIds($block_content, $block, $instance){
if ( !in_array($groupId, $this->groupIds) ) {
$this->groupIds[] = $groupId;
break;
}
}
$groupId = explode('--', $groupId);
if ( count($groupId) > 1 && is_numeric(end($groupId)) ) {
$groupId[count($groupId) - 1] = end($groupId) + 1;
Expand All @@ -248,4 +250,4 @@ public function dedupeIds($block_content, $block, $instance){
return $block_content;
}

}
}
6 changes: 6 additions & 0 deletions theme/includes/classes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
* https://timber.github.io/docs/v2/guides/extending-timber/#extending-timber-classes
*/
class UcdThemePost extends Timber\Post {

public $iconsUsed;

public function setup(){
$this->iconsUsed = [];
add_filter( 'ucd-theme/loaded-icons', [$this, 'loadIcons'], 10, 1);
Expand Down Expand Up @@ -393,6 +396,9 @@ public function is_sticky(){
}

class UcdThemePostExcerpt {
public $post;
public $length;

public function __construct( $post, array $options = array() ) {
$this->post = $post;
$this->length = 50;
Expand Down
18 changes: 18 additions & 0 deletions theme/includes/classes/site.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@
*/
class UcdThemeSite extends Timber\Site {

public $version;
public $directories;
public $scripts;
public $buildParams;
public $blockSettings;

public $api;
public $views;
public $metaData;
public $customizer;
public $hideUser;
public $assets;
public $patterns;
public $customBlocks;
public $htmlImport;


public function __construct() {

// Declare class properties
Expand Down Expand Up @@ -151,6 +168,7 @@ public function modify_native_post_types() {

function change_post_labels( $args ) {
foreach( $args as $key => $label ){
if ( !$label ) continue;
$args->{$key} = str_replace( [ __( 'Posts' ), __( 'Post' ) ], __( 'News' ), $label );
}

Expand Down
2 changes: 1 addition & 1 deletion theme/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
* Author: UC Davis Library Online Strategy
* Author URI: https://library.ucdavis.edu
* Description: A Wordpress version of the UC Davis Sitefarm One theme
* Version: 3.5.0
* Version: 3.8.0
*/
Loading

0 comments on commit 5c845d8

Please sign in to comment.