Skip to content

Commit

Permalink
Merge branch 'master' of github.com:vektor-inc/vk-filter-search
Browse files Browse the repository at this point in the history
  • Loading branch information
drill-lancer committed Jun 10, 2024
2 parents 2c44a4d + ae6f764 commit 6a32da8
Show file tree
Hide file tree
Showing 32 changed files with 2,649 additions and 2,257 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php_unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
php-versions: ['7.4', '8.0', '8.1']
wp-versions: ['6.2', '6.3', '6.4']
wp-versions: ['6.3', '6.4', '6.5']
name: PHP Unit Test on PHP ${{ matrix.php-versions }} / WP ${{ matrix.wp-versions }} Test
services:
mysql:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/wp-plugin-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Deploy to WordPress.org
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
- '[0-9]+.[0-9]+.[0-9]+.[0-9]'
env:
plugin_name: vk-filter-search
jobs:
Expand All @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
php-versions: ['7.4', '8.0', '8.1']
wp-versions: ['6.2', '6.3', '6.4']
wp-versions: ['6.3', '6.4', '6.5']
name: PHP Unit Test on PHP ${{ matrix.php-versions }} / WP ${{ matrix.wp-versions }} Test
services:
mysql:
Expand Down
7 changes: 4 additions & 3 deletions inc/dropdown-categories/class-vk-walker-catrgory-dropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ public function start_el( &$output, $data_object, $depth = 0, $args = array(), $
// タクソノミーに応じて適切なクエリのキーに変換
$count_name = $data_object->taxonomy;
// 該当フォームの値
$count_value = esc_attr( urldecode( $data_object->{$value_field} ) );
$post_type = $args['post_type'];
$count_value = esc_attr( urldecode( $data_object->{$value_field} ) );
$multi_select = false;
$post_type = $args['post_type'];
// 上記に基づいた投稿数を取得して表示
$output .= '  (' . number_format_i18n( vkfs_auto_count( $count_name, $count_value, $post_type ) ) . ')';
$output .= '  (' . number_format_i18n( vkfs_auto_count( $count_name, $count_value, $multi_select, $post_type ) ) . ')';
} else {
$output .= '  (' . number_format_i18n( $data_object->count ) . ')';
}
Expand Down
24 changes: 14 additions & 10 deletions inc/filter-search/package/class-vk-filter-search-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ class VK_Filter_Search_Block {
* Constructor
*/
public function __construct() {
// ver5.8.0 block_categories_all
if ( function_exists( 'get_default_block_categories' ) && function_exists( 'get_block_editor_settings' ) ) {
add_filter( 'block_categories_all', array( __CLASS__, 'register_block_category' ), 10, 2 );
} else {
add_filter( 'block_categories', array( __CLASS__, 'register_block_category' ), 10, 2 );
}

/*
Priority
10 - Exunit
11 - Video Block
12 - VK Filter Search
13 - VK Blocks
*/
add_filter( 'block_categories_all', array( __CLASS__, 'register_block_category' ), 12, 2 );
add_action( 'init', array( __CLASS__, 'register_blocks' ), 11 );
add_action( 'enqueue_block_editor_assets', array( __CLASS__, 'set_block_data' ) );
}
Expand Down Expand Up @@ -188,16 +191,16 @@ public static function register_block_category( $categories, $post ) {
$keys[] = $value['slug'];
}

if ( ! in_array( 'vk-blocks-cat', $keys, true ) ) {
if ( ! in_array( 'vk-filter-search', $keys, true ) ) {
$categories = array_merge(
$categories,
array(
array(
'slug' => 'vk-blocks-cat',
'title' => __( 'VK Blocks', 'vk-filter-search' ),
'slug' => 'vk-filter-search',
'title' => __( 'VK Filter Search', 'vk-filter-search' ),
'icon' => '',
),
)
),
);
}

Expand Down Expand Up @@ -239,6 +242,7 @@ public static function register_blocks() {
'post-type-search',
'taxonomy-search',
'search-result-form',
'search-result-title',
'call-filter-search',
);

Expand Down
35 changes: 25 additions & 10 deletions inc/filter-search/package/class-vk-filter-search-title.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public static function get_search_title_args( $search_title_args = array() ) {
*/
public static function get_post_type_search_title( $search_title_args ) {

// タイトルを初期化
$search_title = '';
// 投稿タイプを取得
$post_type_value = get_query_var( 'post_type' );
if ( ! empty( $post_type_value ) && $post_type_value !== 'any' ) {

Expand All @@ -78,11 +81,12 @@ public static function get_post_type_search_title( $search_title_args ) {
}

$count = 0;

// query_title_display が true の場合はクエリタイトルを表示
if ( $search_title_args['query_title_display'] ) {
$search_title = __( 'Post Type', 'vk-filter-search' ) . $search_title_args['query_title_after'];
} else {
$search_title = '';
$search_title .= __( 'Post Type', 'vk-filter-search' ) . $search_title_args['query_title_after'];
}

foreach ( $post_type_value as $post_type ) {
$search_title .= $search_title_args['query_element_before'];
$search_title .= $post_type_labels[ $post_type ];
Expand All @@ -93,8 +97,9 @@ public static function get_post_type_search_title( $search_title_args ) {
++$count;
}
$search_title .= $search_title_args['query_elements_after'];
return $search_title;

}
return $search_title;
}

/**
Expand All @@ -105,6 +110,9 @@ public static function get_post_type_search_title( $search_title_args ) {
*/
public static function get_taxonomy_search_title( $search_title_args ) {

// タイトルを初期化
$search_title = '';

// 追加されたタクソノミーの取得
$tax_args = array(
'public' => true,
Expand All @@ -128,8 +136,7 @@ public static function get_taxonomy_search_title( $search_title_args ) {
$taxonomy_label_array[ $taxonomy ] = get_taxonomy( $taxonomy )->labels->singular_name;
}

// タイトルを初期化
$search_title = '';


foreach ( $taxonomy_array as $taxonomy ) {
if ( 'category_name' === $taxonomy ) {
Expand All @@ -154,11 +161,12 @@ public static function get_taxonomy_search_title( $search_title_args ) {

// カテゴリのタイトルを作成
if ( ! empty( $taxnomy_value ) ) {

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

$count = 0;
foreach ( $taxnomy_value as $category_id ) {
$search_title .= $search_title_args['query_element_before'];
Expand Down Expand Up @@ -192,6 +200,8 @@ public static function get_taxonomy_search_title( $search_title_args ) {

// タグのタイトルを作成
if ( ! empty( $taxnomy_value ) ) {

// query_title_display が true の場合はクエリタイトルを表示
if ( $search_title_args['query_title_display'] ) {
$search_title .= get_taxonomy('post_tag')->label . $search_title_args['query_title_after'];
}
Expand Down Expand Up @@ -232,7 +242,12 @@ public static function get_taxonomy_search_title( $search_title_args ) {

// タクソノミーのタイトルを作成
if ( ! empty( $taxnomy_value ) ) {
$search_title .= $taxonomy_label_array[ $taxonomy ] . $search_title_args['query_title_after'];

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

$count = 0;
foreach ( $taxnomy_value as $term_slug ) {
$search_title .= $search_title_args['query_element_before'];
Expand Down
89 changes: 60 additions & 29 deletions inc/filter-search/package/class-vk-filter-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static function register_post_type() {
'label' => __( 'VK Filter Search', 'vk-filter-search-addon' ),
'public' => false,
'has_archive' => false,
'menu_icon' => 'dashicons-filter',
'menu_icon' => 'dashicons-filter',
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 20,
Expand Down Expand Up @@ -135,9 +135,11 @@ public static function kses_allowed() {
'action' => array(),
),
'div' => array(
'id' => array(),
'class' => array(),
'style' => array(),
'id' => array(),
'class' => array(),
'style' => array(),
'data-vkfs-dropdown-options' => array(),
'data-vkfs-taxonomy-accordion' => array(),
),
'h1' => array(
'id' => array(),
Expand Down Expand Up @@ -505,17 +507,19 @@ public static function get_taxonomy_form_html( $taxonomy, $options = array() ) {

// オプションの値を調整
$default = array(
'class_name' => '',
'label' => $taxonomy_object->labels->singular_name,
'form_design' => 'select',
'non_selected_label' => '',
'post_type' => '',
'operator' => 'or',
'show_count' => false,
'auto_count' => false,
'hide_empty' => true,
'outer_columns' => array(),
'inner_columns' => array(),
'class_name' => '',
'label' => $taxonomy_object->labels->singular_name,
'form_design' => 'select',
'non_selected_label' => '',
'post_type' => '',
'operator' => 'or',
'enable_child_dropdown' => false,
'show_count' => false,
'auto_count' => false,
'hide_empty' => true,
'outer_columns' => array(),
'inner_columns' => array(),
'accordion_type' => 'none',
);
$options = wp_parse_args( $options, $default );

Expand All @@ -531,13 +535,38 @@ public static function get_taxonomy_form_html( $taxonomy, $options = array() ) {
// 追加クラスの調整.
$outer_classes .= ! empty( $options['class_name'] ) ? ' ' . $options['class_name'] : '';

$dropdown_options = array();
$data_dropdown_options = '';
if ( ! empty( $options['enable_child_dropdown'] ) ) {
$outer_classes .= ' vkfs__child-dropdown';
$dropdown_options = array(
'post_type' => $options['post_type'],
'operator' => $options['operator'],
'show_count' => $options['show_count'],
'auto_count' => $options['auto_count'],
'hide_empty' => $options['hide_empty'],
);
$data_dropdown_options = ' data-vkfs-dropdown-options="' . esc_html( wp_json_encode( $dropdown_options, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT ) ) . '"';
}

// 変数を初期化.
$taxonomy_form_html = '';
$taxonomy_design_html = '';

$accordion_data = array();
$data_vkfs_taxonomy_accordion = '';

if ( $options['accordion_type'] !== 'none' ) {
$accordion_data = array(
'AccordionType' => $options['accordion_type'],
);
$data_vkfs_taxonomy_accordion = ' data-vkfs-taxonomy-accordion="' . esc_html( wp_json_encode( $accordion_data, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT ) ) . '"';
}

// 描画開始.
if ( ! empty( $taxonomy_object ) && ! empty( $taxonomy_terms ) ) {
$taxonomy_form_html .= '<div class="vkfs__outer-wrap vkfs__taxonomy' . $outer_classes . '">';
$taxonomy_form_html .= '<div class="vkfs__outer-wrap vkfs__taxonomy' . $outer_classes . '"' . $data_vkfs_taxonomy_accordion . $data_dropdown_options . '>';

$taxonomy_form_html .= '<div class="vkfs__label-name">';
if ( 'user' !== $options['operator'] ) {
$taxonomy_form_html .= $options['label'];
Expand Down Expand Up @@ -922,11 +951,11 @@ public static function form_edit_content( $post_id, $old_flag ) {
$edit_content .= '<div class="vkfs_old-form-alert" data-nosnippet">';
$edit_content .= '<div class="vkfs_old-form-alert--icon"><i class="fa-solid fa-circle-info"></i></div>';
$edit_content .= '<div class="vkfs_old-form-alert--text">';
$edit_content .= __( 'This form is obsolete and may eventually become obsolete.', 'vk-filter-search' );
$edit_content .= __( 'This form is obsolete and may eventually be deleted.', 'vk-filter-search' );
$edit_content .= '<br>';
$edit_content .= __( 'We recommend creating a form with the post type "Filteer Search".', 'vk-filter-search' );
$edit_content .= __( 'We recommend creating a form with the post type "VK Filteer Search".', 'vk-filter-search' );
$edit_content .= '<br>';
$edit_content .= __( 'The post of "Filteer Search" can be called by the "Call Filter Search" block.', 'vk-filter-search' );
$edit_content .= __( 'The post of "VK Filter Search" can be called by the "Call Filter Search" block.', 'vk-filter-search' );
$edit_content .= '</div>';
$edit_content .= '</div>';
}
Expand All @@ -939,8 +968,10 @@ public static function form_edit_content( $post_id, $old_flag ) {

/**
* Search Form on Loop
*
* @param bool $force_display_result 検索結果を強制表示するかどうか
*/
public static function search_result_form_content() {
public static function search_result_form_content( $force_display_result = false ) {
$content = '';
$old_flag = false;
$options = self::get_options();
Expand All @@ -953,10 +984,11 @@ public static function search_result_form_content() {
// 表示するフォームの ID を取得
$target_id = sanitize_text_field( wp_unslash( $_GET['vkfs_form_id'] ) );

// フォームの ID が数値型なら該当の投稿を取得
// フォームのIDは 投稿タイプ VK Filter Search : 数値 / 直配置の場合 : 16進数と - の文字列
// フォームの ID が数値型なら該当の投稿(VK Filter Search)を取得
$target_post = is_numeric( $target_id ) ? get_post( $target_id ) : array();

// Filter Search の投稿がある場合はそちらを優先する
// 投稿タイプ VK Filter Search のフォームがある場合はそちらを優先する
if ( ! empty( $target_post ) && ( 'publish' === $target_post->post_status || 'private' === $target_post->post_status ) ) {
// 新しいのでフラグを消す

Expand All @@ -968,15 +1000,14 @@ public static function search_result_form_content() {
// 上記カスタムフィールドを処理
$display_result = ! empty( $display_result ) ? true : false;

// 上記フィールドが true ならその投稿を表示
if ( ! empty( $display_result ) ) {
$content = str_replace( '[filter_search_result_input]', '<input type="hidden" name="vkfs_form_id" value="' . $target_id . '" />', $target_post->post_content );
$content = apply_filters( 'filter_search_content', $content );
// 上記フィールドが true か強制表示フラグが true ならその投稿を表示
if ( ! empty( $display_result ) || ! empty( $force_display_result ) ) {
$content = str_replace( '[filter_search_result_input]', '<input type="hidden" name="vkfs_form_id" value="' . $target_id . '" />', $target_post->post_content );
$content = apply_filters( 'filter_search_content', $content );
$content .= self::form_edit_content( $target_post->ID, $old_flag );
} else {
$content = str_replace( '[filter_search_result_input]', '', $target_post->post_content );
$content = apply_filters( 'filter_search_content', $target_post->post_content );
$content = '';
}
$content .= self::form_edit_content( $target_post->ID, $old_flag );
}

// 旧版のフォームを表示
Expand Down
23 changes: 23 additions & 0 deletions inc/filter-search/package/src/block-category/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { updateCategory } from '@wordpress/blocks';

export const vkfsCategoryIcon = () => {
const blockCategoryIcon = (
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
fill="none"
>
<path
fill="#000"
d="m19.84 6.586-4.751.011a.161.161 0 0 0-.15.11l-.363 1.05c-.032.111.043.222.15.222h1.847c.138 0 .213.176.117.276l-2.947 3.172h.011l1.516 4.94c.032.11-.043.21-.15.21h-1.483a.151.151 0 0 1-.15-.11l-.758-2.531c-.042-.155-.245-.155-.299-.012l-.619 1.78a.16.16 0 0 0 0 .1l.566 2.154c.021.067.085.122.15.122h4.782c.107 0 .182-.11.15-.21l-1.933-6.222c-.021-.056 0-.122.043-.166l4.388-4.62c.096-.1.021-.276-.118-.276Z"
/>
<path
fill="#D8141C"
d="m14.213 4-2.893.011a.161.161 0 0 0-.15.11l-.373 1.05a.163.163 0 0 0 .15.222h1.217c.106 0 .181.11.149.22l-3.448 9.77a.158.158 0 0 1-.3 0L6.09 8.333a.163.163 0 0 1 .15-.222h1.249c.064 0 .128.044.15.11l.896 2.543a.158.158 0 0 0 .299 0l1.388-3.957a.163.163 0 0 0-.15-.22H4.157c-.107 0-.182.11-.15.22l4.548 13.085a.158.158 0 0 0 .3 0l5.508-15.671c.032-.11-.043-.221-.15-.221Z"
/>
</svg>
);

updateCategory( 'vk-filter-search', { icon: blockCategoryIcon } );
};
Loading

0 comments on commit 6a32da8

Please sign in to comment.