Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Merge develop. Fixes from feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
miina committed Apr 12, 2018
2 parents 62760e5 + c361a86 commit 551cfbe
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 76 deletions.
4 changes: 2 additions & 2 deletions assets/js/editor-blocks.js

Large diffs are not rendered by default.

22 changes: 3 additions & 19 deletions blocks/activity-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,11 @@ export default registerBlockType(
__( 'Travel' )
],

attributes: {
heading: {
source: 'children',
type: 'array',
selector: '.travel-activities h3'
}
},

edit: withAPIData( () => {
return {
activityResults: '/wp/v2/activities'
};
} )( ( { activityResults, attributes, setAttributes } ) => {
} )( ( { activityResults } ) => {
const hasActivities = Array.isArray( activityResults.data ) && activityResults.data.length;
if ( ! hasActivities ) {
return (
Expand All @@ -49,25 +41,17 @@ export default registerBlockType(
}

const activities = activityResults.data;
const { heading } = attributes;

return (
<section className='travel-activities pb4 pt3 relative'>
<div className='max-width-3 mx-auto px1 md-px2'>
<RichText
key='editable'
className='bold h1 line-height-2'
tagName='h3'
value={ heading }
onChange={ ( value ) => setAttributes( { heading: value } ) }
placeholder={ __( 'Browse by activity' ) }
/>
<h3 className='bold h1 line-height-2'>{ __( 'Browse by activity' ) }</h3>
</div>
<div className='overflow-scroll'>
<div className='travel-overflow-container'>
<div className='flex p1 md-px1 mxn1'>
{ activities.map( ( activity, i ) =>
<a key='activity' href={ activity.link } className='travel-activities-activity travel-type-active mx1' target="_blank">
<a key='activity' href={ activity.link } className={ 'travel-activities-activity mx1 travel-type-' + activity.slug } target="_blank">
<div className='travel-shadow circle inline-block'>
<div className='travel-activities-activity-icon'>
<RawHTML key='html'>{ decodeEntities( activity.svg ) }</RawHTML>
Expand Down
2 changes: 1 addition & 1 deletion blocks/travel-angles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default registerBlockType(
// Copy from Travel HTML template.
edit() {

// Don't display the travel angels since that will hide the block configure buttons behind an image.
// Don't display the travel angles since that will hide the block configure buttons behind an image.
return (
<div className='travel-angles max-width-3 mx-auto'>
--- Placeholder for Travel angles ---
Expand Down
37 changes: 6 additions & 31 deletions functions.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,13 @@
<?php
/**
* Theme functions file.
* AMP Travel Theme.
*
* @package WPAMPTheme
*/

// Include required classes.
require_once get_template_directory() . '/includes/class-amp-travel-blocks.php';
require_once get_template_directory() . '/includes/class-amp-travel-taxonomies.php';
// Load theme.
require_once get_template_directory() . '/includes/functions.php';
require_once get_template_directory() . '/includes/class-amp-travel-theme.php';

if ( ! function_exists( 'travel_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function travel_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on WPAMPTheme, use a find and replace
* to change 'travel' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'travel', get_template_directory() . '/languages' );

add_theme_support( 'amp', array() );

// Init blocks.
new AMP_Travel_Blocks();
new AMP_Travel_Taxonomies();
}
endif;

// Hook into theme after setup.
add_action( 'after_setup_theme', 'travel_setup' );
// Initialize theme.
amp_travel_theme()->init();
6 changes: 3 additions & 3 deletions includes/class-amp-travel-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
class AMP_Travel_Blocks {

/**
* AMP_Travel_Blocks constructor.
* Init Travel Blocks.
*/
public function __construct() {
public function init() {
if ( function_exists( 'gutenberg_init' ) ) {
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_editor_scripts' ) );
add_filter( 'the_content', array( $this, 'filter_the_content_amp_atts' ), 10, 1 );
Expand Down Expand Up @@ -73,7 +73,7 @@ public function render_block_activity_list( $attributes ) {
<div class='flex justify-center p1 md-px1 mxn1'>";

foreach ( $activities as $activity ) {
$output .= "<a href='" . get_term_link( $activity ) . "' class='travel-activities-activity travel-type-active mx1'>
$output .= "<a href='" . get_term_link( $activity ) . "' class='travel-activities-activity travel-type-" . $activity->slug . " mx1'>
<div class='travel-shadow circle inline-block'>
<div class='travel-activities-activity-icon'>";
$output .= get_term_meta( $activity->term_id, 'amp_travel_activity_svg', true );
Expand Down
60 changes: 40 additions & 20 deletions includes/class-amp-travel-taxonomies.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
class AMP_Travel_Taxonomies {

/**
* AMP_Travel_Taxonomies constructor.
* Init AMP_Travel_Taxonomies.
*/
public function __construct() {
public function init() {
add_action( 'init', array( $this, 'register_taxonomies' ) );
add_action( 'init', array( $this, 'register_activity_meta' ) );
add_action( 'activity_add_form_fields', array( $this, 'add_activity_meta_fields' ) );
add_action( 'activity_edit_form_fields', array( $this, 'edit_activity_meta_fields' ) );
add_action( 'edit_activity', array( $this, 'save_activity_svg' ) );
add_action( 'create_activity', array( $this, 'save_activity_svg' ) );
add_action( 'edit_activity', array( $this, 'save_activity_meta' ) );
add_action( 'create_activity', array( $this, 'save_activity_meta' ) );
}

/**
Expand All @@ -46,7 +46,7 @@ public function add_activity_meta_fields() {
<label for='travel-activity-svg'>SVG</label>
<?php wp_nonce_field( basename( __FILE__ ), 'travel_activity_svg_nonce' ); ?>
<textarea aria-required='true' name='travel-activity-svg' id='travel-activity-svg'></textarea>
<p class="description"><?php esc_attr_e( 'This is for the background icon of the activity term.', 'travel' ); ?></p>
<p class="description"><?php esc_html_e( 'This is for the background icon of the activity term. Only <path>, <svg>, <g>, and <circle> elements are allowed', 'travel' ); ?></p>
</div>
<?php
}
Expand All @@ -59,13 +59,32 @@ public function add_activity_meta_fields() {
*/
public function sanitize_activity_svg( $text ) {
$allowed_html = array(
'path' => array(
'fill' => true,
'd' => true,
'path' => array(
'fill' => true,
'd' => true,
'id' => true,
'stroke' => true,
'stroke-width' => true,
),
'svg' => array(
'svg' => array(
'class' => true,
'viewbox' => true,
'height' => true,
'width' => true,
),
'g' => array(
'fill' => true,
'fillRule' => true,
'fill-rule' => true,
'stroke' => true,
'stroke-width' => true,
),
'circle' => array(
'cx' => true,
'cy' => true,
'r' => true,
'stroke' => true,
'stroke-width' => true,
),
);

Expand All @@ -90,12 +109,9 @@ public function edit_activity_meta_fields( $term ) {
<td>
<?php wp_nonce_field( basename( __FILE__ ), 'travel_activity_svg_nonce' ); ?>
<textarea aria-required="true" name="travel-activity-svg" id="travel-activity-svg">
<?php
// @codingStandardsIgnoreLine
echo $this->sanitize_activity_svg( $value );
?>
<?php echo $this->sanitize_activity_svg( $value ); // WPCS: XSS ok. ?>
</textarea>
<p class="description"><?php esc_attr_e( 'This is for the background icon of the activity term.', 'travel' ); ?></p>
<p class="description"><?php esc_html_e( 'This is for the background icon of the activity term. Only <path>, <svg>, <g>, and <circle> elements are allowed', 'travel' ); ?></p>
</td>
</tr>
<?php
Expand All @@ -106,15 +122,22 @@ public function edit_activity_meta_fields( $term ) {
*
* @param integer $term_id Term ID.
*/
public function save_activity_svg( $term_id ) {
public function save_activity_meta( $term_id ) {

if ( ! wp_verify_nonce( $_POST['travel_activity_svg_nonce'], basename( __FILE__ ) ) ) {
return;
}

$old_value = get_term_meta( $term_id, 'amp_travel_activity_svg', true );
$new_value = isset( $_POST['travel-activity-svg'] ) ? $this->sanitize_activity_svg( $_POST['travel-activity-svg'] ) : '';
$old_value = get_term_meta( $term_id, 'amp_travel_activity_svg', true );
$original_value = isset( $_POST['travel-activity-svg'] ) ? trim( $_POST['travel-activity-svg'] ) : '';
$new_value = isset( $_POST['travel-activity-svg'] ) ? $this->sanitize_activity_svg( $_POST['travel-activity-svg'] ) : '';

if ( $old_value !== $new_value ) {

// If the stripped new value is completely empty but the intended value was not, don't save it.
if ( '' === $new_value && '' !== $original_value ) {
return;
}
update_term_meta( $term_id, 'amp_travel_activity_svg', $new_value );
}
}
Expand All @@ -124,10 +147,7 @@ public function save_activity_svg( $term_id ) {
*/
public function register_taxonomies() {
register_taxonomy( 'activity', array( 'adventure', 'post' ), array(
'hierarchical' => false,
'query_var' => 'activity',
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_rest' => true,
'rest_base' => 'activities',
Expand Down
85 changes: 85 additions & 0 deletions includes/class-amp-travel-theme.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
/**
* AMP Travel Theme class.
*
* @package WPAMPTheme
*/

/**
* Class AMP_Travel_Theme.
*
* @package WPAMPTheme
*/
class AMP_Travel_Theme {

/**
* AMP_Travel_Theme constructor.
*/
protected function __construct() {
$this->includes();
$this->instantiate_classes();
}

/**
* Init classes.
*/
protected function instantiate_classes() {

// Init blocks.
$travel_blocks = new AMP_Travel_Blocks();
$travel_blocks->init();

// Init taxonomies.
$travel_taxonomies = new AMP_Travel_Taxonomies();
$travel_taxonomies->init();
}

/**
* Init.
*/
public function init() {

// Hook into theme after setup.
add_action( 'after_setup_theme', array( $this, 'setup' ) );
}

/**
* Get theme instance.
*
* @return object $instance Theme instance.
*/
public static function get_instance() {
static $instance;

if ( ! $instance instanceof AMP_Travel_Theme ) {
$instance = new AMP_Travel_Theme();
}

return $instance;
}

/**
* Setup.
*/
public function setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on WPAMPTheme, use a find and replace
* to change 'travel' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'travel', get_template_directory() . '/languages' );

add_theme_support( 'amp', array() );
}

/**
* Theme includes.
*/
protected function includes() {
$dir = get_template_directory();

require_once $dir . '/includes/class-amp-travel-taxonomies.php';
require_once $dir . '/includes/class-amp-travel-blocks.php';
}
}
15 changes: 15 additions & 0 deletions includes/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* Theme functions file.
*
* @package WPAMPTheme
*/

/**
* Init theme.
*
* @return object Theme object
*/
function amp_travel_theme() {
return AMP_Travel_Theme::get_instance();
}

0 comments on commit 551cfbe

Please sign in to comment.