From bacd6a1d726143a5e92f068f348d9ee5506cc91c Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 7 May 2021 21:19:14 +0900 Subject: [PATCH] =?UTF-8?q?WP=20PLUGIN=20=E3=82=A2=E3=83=BC=E3=82=AB?= =?UTF-8?q?=E3=82=A4=E3=83=96=E3=83=9A=E3=83=BC=E3=82=B8=E3=81=AE=E6=8A=95?= =?UTF-8?q?=E7=A8=BF=E8=A1=A8=E7=A4=BA=E9=A0=86=E8=A8=AD=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ・検索と通常表示のオプションを追加 ・項目の表示順を修正 ・選択値によって表示/非表示の切り替えやフォームをDisabledにする等修正 ・アンインストーラーを追加 --- class/class.apop.order.php | 110 ++++++++++----- class/class.apop.ui.php | 116 +++++++++++++++- css/apop-style.css | 67 ++++++++- js/apop-style.js | 89 +++++++++--- template/order.php | 261 +++++++++++++++++++----------------- template/setting.php | 203 ++++++++++++++++------------ uninstall.php | 46 +++++++ util/apop-order-setting.php | 76 ++++++++--- 8 files changed, 675 insertions(+), 293 deletions(-) create mode 100644 uninstall.php diff --git a/class/class.apop.order.php b/class/class.apop.order.php index 2d253e1..563a459 100644 --- a/class/class.apop.order.php +++ b/class/class.apop.order.php @@ -29,7 +29,7 @@ if ( ! class_exists( 'APOP' ) ) { add_submenu_page( 'apop_post_sort', // parent_slug 'Sort taxonomy', // page_title - '設定', // menu_title + '表示件数・対象設定', // menu_title 'administrator', // capability 'apop_post_sort', // menu_slug array( $this, 'display_setting_page' ) // function @@ -45,63 +45,108 @@ if ( ! class_exists( 'APOP' ) ) { } public function display_setting_page() { - if ( isset( $_POST['_apop_cat_order'] ) - || isset( $_POST['_apop_tag_order'] ) - || isset( $_POST['_apop_tax_order'] ) ) { - check_admin_referer( 'sh_options' ); + $settings = array( + '_apop_cat_order', //カテゴリー設定 + '_apop_per_page', //1ページ表示件数 + '_apop_tag_order', //タグ設定 + '_apop_tax_order', //カスタムタクソノミー設定 + ); - $settings = array( - '_apop_cat_order', //カテゴリー設定 - '_apop_per_page', //1ページ表示件数 - '_apop_tag_order', //タグ設定 - '_apop_tax_order', //カスタムタクソノミー設定 - ); - foreach ( $settings as $setting ) { - $opt = $_POST[ $setting ]; + foreach ( $settings as $setting ) { + $opt = APOP_UI::input_post_filter( $setting, 'array' ); + if ( $opt ) { + check_admin_referer( 'sh_options' ); update_option( $setting, $opt ); + require_once self::TEMPLATE_DIR . 'success.php'; } - require_once self::TEMPLATE_DIR . 'success.php'; - } require_once self::TEMPLATE_DIR . 'setting.php'; + } public function show_option_page() { + //------------------------------------- + // 通常表示 + // ------------------------------------ + $apop_normal_order = APOP_UI::input_post_filter( '_apop_normal_order', 'str' ); + $apop_normal_order_param = APOP_UI::input_post_filter( '_apop_normal_order_param', 'array' ); + $apop_post_normal = APOP_UI::input_post_filter( '_apop_post_normal', 'array' ); - //検索の投稿表示順設定 - if ( isset( $_POST['_apop_post_search'] ) ) { + if ( $apop_normal_order ) { check_admin_referer( 'sh_options' ); - $this->update_search_sort( 'search' ); + update_option( '_apop_normal_order', $apop_normal_order ); require_once self::TEMPLATE_DIR . 'success.php'; } - if ( isset( $_POST['_apop_search_order'] ) ) { + //表示順設定 + if ( $apop_normal_order_param ) { check_admin_referer( 'sh_options' ); - update_option( '_apop_search_order', $_POST['_apop_search_order'] ); + update_option( '_apop_normal_order_param', $apop_normal_order_param ); require_once self::TEMPLATE_DIR . 'success.php'; } + //カスタム表示順設定 + if ( $apop_post_normal ) { + check_admin_referer( 'sh_options' ); + $this->update_search_normal_sort( $apop_post_normal, 'normal' ); + require_once self::TEMPLATE_DIR . 'success.php'; + } + + //------------------------------------- + // 検索表示 + // ------------------------------------ + $apop_search_order = APOP_UI::input_post_filter( '_apop_search_order', 'str' ); + $apop_search_order_param = APOP_UI::input_post_filter( '_apop_search_order_param', 'array' ); + $apop_post_search = APOP_UI::input_post_filter( '_apop_post_search', 'array' ); + + if ( $apop_search_order ) { + check_admin_referer( 'sh_options' ); + update_option( '_apop_search_order', $apop_search_order ); + require_once self::TEMPLATE_DIR . 'success.php'; + } + + //表示順設定 + if ( $apop_search_order_param ) { + check_admin_referer( 'sh_options' ); + update_option( '_apop_search_order_param', $apop_search_order_param ); + require_once self::TEMPLATE_DIR . 'success.php'; + } + + //カスタム表示順設定 + if ( $apop_post_search ) { + check_admin_referer( 'sh_options' ); + $this->update_search_normal_sort( $apop_post_search, 'search' ); + require_once self::TEMPLATE_DIR . 'success.php'; + } + + //------------------------------------- + // タクソノミー + // ------------------------------------ + $apop_post_category = APOP_UI::input_post_filter( '_apop_post_category', 'array' ); + $apop_post_post_tag = APOP_UI::input_post_filter( '_apop_post_post_tag', 'array' ); + $apop_post_tax = APOP_UI::input_post_filter( '_apop_post_tax', 'array' ); + //カテゴリーの投稿表示順設定 - if ( isset( $_POST['_apop_post_category'] ) ) { + if ( $apop_post_category ) { check_admin_referer( 'sh_options' ); - $this->update_post_sort( 'category' ); + $this->update_post_sort( 'category', $apop_post_category ); require_once self::TEMPLATE_DIR . 'success.php'; } //タグの投稿表示順設定 - if ( isset( $_POST['_apop_post_post_tag'] ) ) { + if ( $apop_post_post_tag ) { check_admin_referer( 'sh_options' ); - $this->update_post_sort( 'post_tag' ); + $this->update_post_sort( 'post_tag', $apop_post_post_tag ); require_once self::TEMPLATE_DIR . 'success.php'; } //カスタム分類の投稿表示順設定 - if ( isset( $_POST['_apop_post_tax'] ) ) { + if ( $apop_post_tax ) { check_admin_referer( 'sh_options' ); - $this->update_post_sort( 'tax' ); + $this->update_post_sort( 'tax', $apop_post_tax ); require_once self::TEMPLATE_DIR . 'success.php'; } @@ -109,21 +154,20 @@ if ( ! class_exists( 'APOP' ) ) { } //投稿表示順の設定 - private function update_post_sort( $target ) { - $target = '_apop_post_' . $target; - $posts_sort = $_POST[ $target ]['post_sort']; + private function update_post_sort( $target, $post_value ) { + $posts_sort = $post_value['post_sort']; foreach ( $posts_sort as $cat_id => $posts ) { - $sort_key = $target . '_' . $cat_id; + $sort_key = '_apop_post_' . $target . '_' . $cat_id; foreach ( $posts as $post_id => $sort ) { update_post_meta( $post_id, $sort_key, $sort ); } } } - private function update_search_sort() { - $posts_sort = $_POST['_apop_post_search']['post_sort']; + private function update_search_normal_sort( $apop_post_search_normal, $key ) { + $posts_sort = $apop_post_search_normal['post_sort']; foreach ( $posts_sort as $post_id => $sort ) { - update_post_meta( $post_id, '_apop_post_search', $sort ); + update_post_meta( $post_id, '_apop_post_' . $key, $sort ); } } diff --git a/class/class.apop.ui.php b/class/class.apop.ui.php index 8af4326..264b91b 100644 --- a/class/class.apop.ui.php +++ b/class/class.apop.ui.php @@ -6,7 +6,16 @@ if ( ! defined( 'ABSPATH' ) ) { if ( ! class_exists( 'APOP_UI' ) ) { class APOP_UI { - public static function get_all_search_posts( $type, $exclude_posts = [] ) { + public static function get_order_type( $type ) { + $type_data = get_option( $type ); + if ( ! $type_data ) { + return 1; + } + + return $type_data; + } + + public static function get_all_search_normal_posts( $type, $key, $exclude_posts = [] ) { $args = [ 'post_status' => array( 'publish', 'draft' ), 'posts_per_page' => - 1, @@ -15,13 +24,14 @@ if ( ! class_exists( 'APOP_UI' ) ) { if ( $type == 'registered' ) { $args['orderby'] = 'meta_value_num'; $args['order'] = 'ASC'; - $args['meta_key'] = '_apop_post_search'; + $args['meta_key'] = '_apop_post_' . $key; } else { $exclude = implode( ',', $exclude_posts ); if ( ! empty( $exclude ) ) { $args['exclude'] = $exclude; } } + return get_posts( $args ); } @@ -156,7 +166,7 @@ value="' . $sort_num . '"> foreach ( $target_posts_no_order as $key => $target_post_no_order ) { $sort_num_no_order = $sort_num + $key + 1; $list[] = ' -
  • +
  • ' . $sort_num_no_order . '' . get_the_title( $target_post_no_order->ID ) . ' public static function create_cat_per_page( $opt_per_page, $type ): array { $cat_per_page = $opt_per_page[ $type ] ?? 'default'; - $set = ''; + $checked = ''; $cat_per_page_num = ''; if ( isset( $opt_per_page[ $type ] ) ) { - if ( $opt_per_page[ $type ] != 'default' && $opt_per_page[ $type ] != '-1' ) { - $set = ' checked="checked"'; + if ( $opt_per_page[ $type ] != 'default' + && $opt_per_page[ $type ] != '-1' + && $opt_per_page[ $type ] != 'all' ) { + $checked = ' checked="checked"'; $cat_per_page_num = $cat_per_page; } } return array( '_per_page' => $cat_per_page, - '_set' => $set, + '_checked' => $checked, '_per_page_num' => $cat_per_page_num, ); } + + public static function create_search_normal_list( $type ): array { + $name_key = 'apop_' . $type . '_order_param'; + $order_param = get_option( '_' . $name_key ); + $target_keys = self::set_search_normal_target_keys( $order_param ); + $target_values = array( + 'date' => '登録日', + 'title' => 'タイトル', + 'ID' => 'ID', + 'modified' => '更新日', + ); + $list = array(); + foreach ( $target_keys as $target_key ) { + $use = $order_param[ $target_key ]['use'] ?? 0; + $sort = $order_param[ $target_key ]['sort'] ?? 2; + $alert = ! $order_param[ $target_key ]['use'] ? '

    並べ替えを登録するには「変更を保存」をクリックしてください。

    ' : ''; + $no_order_class = ! $order_param[ $target_key ]['use'] ? ' no_order' : ''; + $list[] = '
  • + +    + +    + +
  • '; + } + + return array( + implode( PHP_EOL, $list ), + $alert, + ); + } + + private static function set_search_normal_target_keys( $post_apop_search_order_param ) { + if ( $post_apop_search_order_param ) { + return array_keys( $post_apop_search_order_param ); + } + + return array( + 'date', + 'title', + 'ID', + 'modified', + ); + } + + private static function set_search_normal_checked( $param, $default ): string { + if ( $param == $default ) { + return ' checked="checked"'; + } + + return ''; + } + + public static function input_post_filter( $var_name, $type ) { + if ( $type == 'array' ) { + return filter_input( INPUT_POST, $var_name, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); + } + if ( $type == 'str' ) { + return filter_input( INPUT_POST, $var_name ); + } + } + + public static function is_disp_per_page( &$disp, $disp_per_page ) { + if ( $disp_per_page ) { + $disp = true; + } + } + + public static function create_disp_class( $disp ) { + if ( ! $disp ) { + return ' class="hide_list"'; + } + } + + public static function create_none_select_msg( $str ) { + return '

    並べ替えをカスタマイズする' . $str . 'は選択されていません。

    '; + } + + public static function none_registerd_alert_msg() { + return '
    ■の項目は未登録項目です。ドラッグして並び順を変更後に「変更を保存」をクリックしてください。
    '; + } + } } \ No newline at end of file diff --git a/css/apop-style.css b/css/apop-style.css index f6b7bd8..0c83ac0 100644 --- a/css/apop-style.css +++ b/css/apop-style.css @@ -1,5 +1,9 @@ @charset "UTF-8"; +.post-order-nav { + width: 95%; +} + .post-order-nav ul { display: flex; margin-bottom: 0; @@ -61,11 +65,13 @@ h3 { width: calc((100% - 10px) / 2); } +.apop_normal_order_target, .apop_search_order_target { display: flex; } -.apop_search_order_target li:first-child{ +.apop_normal_order_target li:first-child, +.apop_search_order_target li:first-child { margin-right: 2em; } @@ -75,19 +81,20 @@ p.submit.post-order .button-primary { right: 1.5em; } -dl.post_per_page_list { +dl.apop_setting_list { width: 100%; + margin-top: .5em; } -dl.post_per_page_list dt { +dl.apop_setting_list dt { float: left; } -dl.post_per_page_list dd { +dl.apop_setting_list dd { margin-left: 200px; } -dl.post_per_page_list dd:first-of-type { +dl.apop_setting_list dd:first-of-type { margin-bottom: 2em; } @@ -108,6 +115,15 @@ dl.post_per_page_list dd:first-of-type { border: 1px solid #ababab; } +.search_normal_sort .product-list { + padding: 1em .5em; + border-radius: 0px; +} + +.search_normal_sort .product-list label:first-of-type { + width: 100px; +} + .product-list.no_order { background: #ababab; } @@ -124,6 +140,45 @@ dl.post_per_page_list dd:first-of-type { content: "]"; } -.per_page_cat_input { +.hide_list { + display: none; +} +.no_registered_exp { + margin-top: 1em; +} + +@media only screen and (max-width: 964px) { + + .post-order-nav { + width: 98%; + } + + .list-orders-outer { + display: block;; + } + + .list-orders-inner.search_inner { + width: 100%; + } + + .list-orders-inner { + width: 100%; + margin: 1.5em 0 0 0; + } + + dl.apop_setting_list dt { + float: none; + width: 100%; + margin-bottom: 1em; + } + + dl.apop_setting_list dd { + margin-left: 0; + } + + dl.apop_setting_list li label input[type="text"] { + width: 95%; + margin-top: .5em; + } } \ No newline at end of file diff --git a/js/apop-style.js b/js/apop-style.js index 8e20973..bd2e40e 100644 --- a/js/apop-style.js +++ b/js/apop-style.js @@ -1,10 +1,21 @@ jQuery(function ($) { + //tab menu change_tab_menu(); + + //custom orders order_list(); + //order type + change_search_order(); + change_normal_order(); + + en_search_normal_sort_btn() + + //per page + disp_tax_per_page(); + change_normal_per_page(); change_search_per_page(); - change_search_order_options(); change_cat_per_page(); change_tag_per_page(); change_tax_per_page(); @@ -51,6 +62,65 @@ jQuery(function ($) { } } + function change_normal_order() { + let s_radio = $('.apop_normal_order'); + let s_box = $('.normal_sort_box'); + let default_index = $('.apop_normal_order_target').data('normal_order_target') - 1; + + s_box.hide().find('input').each(function () { + $(this).prop('disabled', true); + }); + $('.normal_sort_box:eq(' + default_index + ')').show().find('input').prop('disabled', false); + + s_radio.click(function () { + let target_index = $(this).val() - 1; + s_box.hide().find('input').each(function () { + $(this).prop('disabled', true); + }); + $('.normal_sort_box:eq(' + target_index + ')').show().find('input').prop('disabled', false); + }) + } + + function change_search_order() { + let s_radio = $('.apop_search_order'); + let s_box = $('.search_sort_box'); + let default_index = $('.apop_search_order_target').data('search_order_target') - 1; + + s_box.hide().find('input').each(function () { + $(this).prop('disabled', true); + }); + + $('.search_sort_box:eq(' + default_index + ')').show().find('input').prop('disabled', false); + + s_radio.click(function () { + let target_index = $(this).val() - 1; + s_box.hide().find('input').each(function () { + $(this).prop('disabled', true); + }); + $('.search_sort_box:eq(' + target_index + ')').show().find('input').prop('disabled', false); + }) + } + + function disp_tax_per_page() { + let box_count = $('.order_setting_list').length; + for (let i = 0; i < box_count; i++) { + $('.order_setting_list:eq(' + i + ')').click(function () { + let en_count = $('.order_setting_list:eq(' + i + ') [name^="_apop_"]:checked').length; + if (en_count == 0) { + $(this).parent().next('dt').addClass('hide_list').next('dd').addClass('hide_list'); + } else { + $(this).parent().next('dt').removeClass('hide_list').next('dd').removeClass('hide_list'); + } + }); + } + } + + function change_normal_per_page() { + let per_page_cat = $('.per_page_normal'); + let per_page_input = $('.per_page_normal_input'); + change_per_page(per_page_cat, per_page_input); + } + function change_search_per_page() { let per_page_cat = $('.per_page_search'); let per_page_input = $('.per_page_search_input'); @@ -82,7 +152,7 @@ jQuery(function ($) { per_page_input.prop('disabled', false); } per_page_cat.click(function () { - if ($(this).val() == 'set') { + if ($(this).val() != 'default' && $(this).val() != '-1' && $(this).val() != 'all') { per_page_input.prop('disabled', false); } else { per_page_input.val(''); @@ -91,19 +161,4 @@ jQuery(function ($) { }) } - function change_search_order_options() { - let s_radio = $('.apop_search_order'); - let s_box = $('.search_sort_box'); - let default_index = $('.apop_search_order_target').data('search_order_target') - 1; - - s_box.hide(); - $('.search_sort_box:eq(' + default_index + ')').show(); - - s_radio.click(function () { - let target_index = $(this).val() - 1; - s_box.hide(); - $('.search_sort_box:eq(' + target_index + ')').show(); - }) - } - }); \ No newline at end of file diff --git a/template/order.php b/template/order.php index f922215..db1e578 100644 --- a/template/order.php +++ b/template/order.php @@ -1,15 +1,18 @@ APOP_UI::get_cat_tag_list( 'cat', 'category' ) ); -$tag_lists = array( 'tag_id' => APOP_UI::get_cat_tag_list( 'tag', 'post_tag' ) ); -$taxonomy_lists = array( 'taxonomy' => APOP_UI::get_cat_tag_list( 'tax', 'taxonomy' ) ); -$submit_type = $_POST['submit_type'] ?? '0'; -$apop_search_order = get_option( '_apop_search_order' ) ?? '1'; +$normal_lists = APOP_UI::get_all_search_normal_posts( 'registered', 'normal' ); +$search_lists = APOP_UI::get_all_search_normal_posts( 'registered', 'search' ); +$category_lists = array( 'category' => APOP_UI::get_cat_tag_list( 'cat', 'category' ) ); +$tag_lists = array( 'tag_id' => APOP_UI::get_cat_tag_list( 'tag', 'post_tag' ) ); +$taxonomy_lists = array( 'taxonomy' => APOP_UI::get_cat_tag_list( 'tax', 'taxonomy' ) ); +$submit_type = APOP_UI::input_post_filter( 'submit_type', 'str' ); +$apop_search_order_check = APOP_UI::get_order_type( '_apop_search_order' ); +$apop_normal_check = APOP_UI::get_order_type( '_apop_normal_order' ); ?>

    並べ替え