Skip to content

Commit

Permalink
Update from vk-filter-search-pro
Browse files Browse the repository at this point in the history
  • Loading branch information
vektorinc committed Sep 18, 2024
1 parent 1024476 commit dbad5b4
Show file tree
Hide file tree
Showing 20 changed files with 1,390 additions and 872 deletions.
12 changes: 12 additions & 0 deletions inc/filter-search/package/class-vk-filter-search-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,17 @@ public static function register_blocks() {
VKFS_FREE_MODULE_VERSION
);

// WordPress 6.5 以下の対策
if ( ! wp_script_is( 'react-jsx-runtime', 'registered' ) ) {
wp_register_script(
'react-jsx-runtime',
plugins_url( '/build/react-jsx-runtime.js', __FILE__ ),
array( 'react' ),
'18.3.1',
true
);
}

wp_register_script(
'vk-filter-search-block',
plugins_url( '/build/block.js', __FILE__ ),
Expand All @@ -241,6 +252,7 @@ public static function register_blocks() {
'keyword-search',
'post-type-search',
'taxonomy-search',
'search-result-count',
'search-result-form',
'search-result-title',
'call-filter-search',
Expand Down
40 changes: 23 additions & 17 deletions inc/filter-search/package/class-vk-filter-search-title.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public static function get_taxonomy_search_title( $search_title_args ) {
} elseif ( ! empty( get_query_var( 'category__in' ) ) ) {
$taxnomy_value = get_query_var( 'category__in' );
$operator = $search_title_args['query_element_or'];
} elseif ( ! empty( get_query_var( 'category_name' ) ) ) {
} elseif ( ! empty( get_query_var( 'category_name' ) ) && ! empty( get_category_by_slug( get_query_var( 'category_name' ) ) ) ) {
$taxnomy_value = array( get_category_by_slug( get_query_var( 'category_name' ) )->term_id );
$operator = $search_title_args['query_element_or'];
}
Expand All @@ -169,11 +169,13 @@ public static function get_taxonomy_search_title( $search_title_args ) {

$count = 0;
foreach ( $taxnomy_value as $category_id ) {
$search_title .= $search_title_args['query_element_before'];
$search_title .= get_term_by( 'id', $category_id, 'category' )->name;
$search_title .= $search_title_args['query_element_after'];
if ( $count < count( $taxnomy_value ) - 1 ) {
$search_title .= $operator;
if ( ! empty( get_term_by( 'id', $category_id, 'category' ) ) ) {
$search_title .= $search_title_args['query_element_before'];
$search_title .= get_term_by( 'id', $category_id, 'category' )->name;
$search_title .= $search_title_args['query_element_after'];
if ( $count < count( $taxnomy_value ) - 1 ) {
$search_title .= $operator;
}
}
++$count;
}
Expand Down Expand Up @@ -203,16 +205,18 @@ public static function get_taxonomy_search_title( $search_title_args ) {

// query_title_display が true の場合はクエリタイトルを表示
if ( $search_title_args['query_title_display'] ) {
$search_title .= get_taxonomy('post_tag')->label . $search_title_args['query_title_after'];
$search_title .= get_taxonomy( 'post_tag' )->label . $search_title_args['query_title_after'];
}

$count = 0;
foreach ( $taxnomy_value as $tag ) {
$search_title .= $search_title_args['query_element_before'];
$search_title .= get_term_by( 'slug', $tag, 'post_tag' )->name;
$search_title .= $search_title_args['query_element_after'];
if ( $count < count( $taxnomy_value ) - 1 ) {
$search_title .= $operator;
if ( ! empty( get_term_by( 'slug', $tag, 'post_tag' ) ) ) {
$search_title .= $search_title_args['query_element_before'];
$search_title .= get_term_by( 'slug', $tag, 'post_tag' )->name;
$search_title .= $search_title_args['query_element_after'];
if ( $count < count( $taxnomy_value ) - 1 ) {
$search_title .= $operator;
}
}
++$count;
}
Expand Down Expand Up @@ -250,11 +254,13 @@ public static function get_taxonomy_search_title( $search_title_args ) {

$count = 0;
foreach ( $taxnomy_value as $term_slug ) {
$search_title .= $search_title_args['query_element_before'];
$search_title .= get_term_by( 'slug', $term_slug, $taxonomy )->name;
$search_title .= $search_title_args['query_element_after'];
if ( $count < count( $taxnomy_value ) - 1 ) {
$search_title .= $operator;
if ( ! empty( get_term_by( 'slug', $term_slug, $taxonomy ) ) ) {
$search_title .= $search_title_args['query_element_before'];
$search_title .= get_term_by( 'slug', $term_slug, $taxonomy )->name;
$search_title .= $search_title_args['query_element_after'];
if ( $count < count( $taxnomy_value ) - 1 ) {
$search_title .= $operator;
}
}
++$count;
}
Expand Down
73 changes: 73 additions & 0 deletions inc/filter-search/package/class-vk-filter-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,20 @@ public static function get_column_dynamic_style( $options = array() ) {
return $column_dynamic_style;
}

/**
* is hex color
*
* @param string color color
*/
public static function is_hex_color( $color ) {
$is_hex = false;
if ( $color && preg_match( '/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/', $color ) ) {
$is_hex = true;
}
return $is_hex;
}


/**
* Get Keyword Filter Form HTML
*
Expand Down Expand Up @@ -703,6 +717,65 @@ public static function get_taxonomy_design_html( $taxonomy, $options = array() )
return apply_filters( 'vk_search_filter_taxonomy_design_html', $taxonomy_design_html, $taxonomy, $options );
}

public static function get_search_count_html( $options ) {
$default = array(
'outer' => true,
'before_text' => __( 'Search Results:', 'vk-filter-search' ),
'after_text' => __( 'articles found.', 'vk-filter-search' ),
'number_color' => '',
'number_font_size' => '',
);
$options = wp_parse_args( $options, $default );

global $wp_query;

$content = '';

if ( is_search() ) {

$number_style = '';
$number_class = '';

// 数字の色の処理
if ( ! empty( $options['number_color'] ) ) {
if ( self::is_hex_color( $options['number_color'] ) ) {
$number_style .= 'color: ' . $options['number_color'] . ';';
} else {
$number_class .= 'has-text-color has-' . $options['number_color'] . '-color';
}
}

// 数字のフォントサイズ
if ( ! empty( $options['number_font_size'] ) ) {
$number_style .= 'font-size: ' . $options['number_font_size'] . ';';
}

// スタイルの処理
if ( ! empty( $number_style ) ) {
$number_style = ' style="' . $number_style . '"';
}

// クラスの処理
if ( ! empty( $number_class ) ) {
$number_class = ' class="' . $number_class . '"';
}

if ( ! empty( $options['outer'] ) ) {
$content .= '<div class="vkfs__search-result-count">';
}

$content .= $options['before_text'];
$content .= ' <span' . $number_style . $number_class . '>' . $wp_query->found_posts . '</span> ';
$content .= $options['after_text'];

if ( ! empty( $options['outer'] ) ) {
$content .= '</div>';
}
}

return $content;
}

/**
* Pre Get Posts
*
Expand Down
2 changes: 2 additions & 0 deletions inc/filter-search/package/src/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { vkfsCategoryIcon } from './block-category';
import * as callFilterSearch from './call-filter-search';
import * as filterSearch from './filter-search';
import * as keywordSearch from './keyword-search';
import * as searchResultCount from './search-result-count';
import * as searchResultForm from './search-result-form';
import * as searchResultTitle from './search-result-title';
import * as postTypeSearch from './post-type-search';
Expand All @@ -27,6 +28,7 @@ import * as taxonomySearch from './taxonomy-search';
export const __getVKFilterSearchBlocks = () => [
callFilterSearch,
filterSearch,
searchResultCount,
searchResultForm,
searchResultTitle,
keywordSearch,
Expand Down
14 changes: 13 additions & 1 deletion inc/filter-search/package/src/call-filter-search/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import { PanelBody, BaseControl, SelectControl } from '@wordpress/components';
import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
import ServerSideRender from '@wordpress/server-side-render';

export default function CallFilterSearchEdit( { attributes, setAttributes } ) {
export default function CallFilterSearchEdit( props ) {
const { attributes, setAttributes } = props;
const { TargetPost } = attributes;

// eslint-disable-next-line no-undef
const adminURL = callFilterSearch.adminURL;
// eslint-disable-next-line no-undef
const hasFilterSearchPosts = callFilterSearch.hasFilterSearchPosts;
// eslint-disable-next-line no-undef
const filterSearchPostIDs = callFilterSearch.filterSearchPostIDs;
// eslint-disable-next-line no-undef
const pagesSelect = callFilterSearch.targetPosts;

let editContent;
Expand Down Expand Up @@ -56,6 +59,15 @@ export default function CallFilterSearchEdit( { attributes, setAttributes } ) {
) }
</div>
);
} else if ( ! filterSearchPostIDs.includes( TargetPost ) ) {
editContent = (
<div className="vkfs__alert alert text-center">
{ __(
'The selected form is deleted. Please select another form.',
'vk-filter-search'
) }
</div>
);
} else {
editContent = (
<ServerSideRender
Expand Down
8 changes: 7 additions & 1 deletion inc/filter-search/package/src/call-filter-search/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ function vkfs_set_call_filteer_search_data() {
)
);

$post_ids = array();

if ( ! empty( $posts ) ) {
$has_filter_search_posts = true;
foreach ( $posts as $post ) {
$post_ids[] = $post->ID;
}
} else {
$has_filter_search_posts = false;
}
Expand All @@ -59,6 +64,7 @@ function vkfs_set_call_filteer_search_data() {
array(
'adminURL' => admin_url(),
'hasFilterSearchPosts' => $has_filter_search_posts,
'filterSearchPostIDs' => $post_ids,
'targetPosts' => $post_selection,
)
);
Expand All @@ -75,7 +81,7 @@ function vkfs_call_filteer_search_render_callback( $attributes ) {
// 投稿タイプ VK Filter Search で作った投稿のID
$target_id = ! empty( $attributes['TargetPost'] ) ? $attributes['TargetPost'] : -1;
// 投稿タイプ VK Filter Search で作成した投稿(フォーム)コンテンツを取得
$target_content = -1 !== $target_id ? get_post( $target_id )->post_content : '';
$target_content = -1 !== $target_id && ! empty( get_post( $target_id ) ) ? get_post( $target_id )->post_content : '';
// 検索結果ページに表示するかどうか
$display_result = get_post_meta( $target_id, 'vkfs_display_result', true );

Expand Down
79 changes: 79 additions & 0 deletions inc/filter-search/package/src/common/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@

import { CheckboxControl } from '@wordpress/components';
import { useState } from '@wordpress/element';
import { select } from '@wordpress/data';

// @wordpress/block-editor から必要なものをインポート
import {
ColorPalette,
getColorObjectByColorValue,
getColorObjectByAttributeValues,
} from '@wordpress/block-editor';

export const destructiveDeleteFromArray = ( array, value ) => {
const index = array.indexOf( value );
Expand Down Expand Up @@ -48,3 +56,74 @@ export const AdvancedCheckboxControl = ( props ) => {
} );
return checkBoxComponents;
};

export const isParentReusableBlock = ( clientId ) => {
const parentReusableBlock = select(
'core/block-editor'
).getBlockParentsByBlockName( clientId, [ 'core/block' ] );
return parentReusableBlock.length ? true : false;
};

export const isHexColor = ( color ) => {
let isHex = false;
if (
color &&
color.match( /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/ ) !== null
) {
isHex = true;
}
return isHex;
};

export const colorSlugToColorCode = ( color ) => {
let colorCode;
if ( color ) {
// カラーパレットの色名・スラッグ・カラーコードを取得
const colorSet = select( 'core/block-editor' ).getSettings().colors;

// titleColor の色コードを colorSet から探して色データを取得
const ColorValue = getColorObjectByAttributeValues( colorSet, color );

if ( ColorValue.color !== undefined ) {
colorCode = ColorValue.color;
} else {
colorCode = color;
}
}
return colorCode;
};

export const AdvancedColorPalette = ( props ) => {
const { schema, setAttributes, attributes } = props;
const hexColor = colorSlugToColorCode( attributes[ schema ] );

return (
<ColorPalette
value={ hexColor }
onChange={ ( value ) => {
// カラーパレットの色名・スラッグ・カラーコードを取得
const colorSet =
select( 'core/block-editor' ).getSettings().colors;

// 色コードを colorSet から探して色データを取得
// カスタムカラーの場合 undefined が返る
// パレットのあるカラーの場合 オブジェクトで color / name / slug が返る( console.dir(ColorValue) )
const ColorValue = getColorObjectByColorValue(
colorSet,
value
);

if ( ColorValue !== undefined ) {
setAttributes( { [ schema ]: ColorValue.slug } );
} else {
setAttributes( { [ schema ]: value } );
}
} }
/>
);
};

export const isBlockDuplicate = ( blockName, clientId ) => {
const blockids = select( 'core/block-editor' ).getBlocksByName( blockName );
return blockids[ 0 ] !== clientId;
};
33 changes: 30 additions & 3 deletions inc/filter-search/package/src/filter-search/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,36 @@
"supports": {
"className": true,
"spacing": {
"margin": {
"top": true,
"bottom": true
"margin": true,
"padding": true
},
"background": {
"backgroundImage": true,
"backgroundSize": true,
"__experimentalDefaultControls": {
"backgroundImage": true
}
},
"color": {
"gradients": true,
"heading": false,
"button": false,
"link": false,
"__experimentalDefaultControls": {
"background": true,
"text": false
}
},
"__experimentalBorder": {
"color": true,
"radius": true,
"style": true,
"width": true,
"__experimentalDefaultControls": {
"color": true,
"radius": true,
"style": true,
"width": true
}
}
}
Expand Down
Loading

0 comments on commit dbad5b4

Please sign in to comment.