ID ); $neu = null === $box; $block = function_exists( 'use_block_editor_for_post' ) && use_block_editor_for_post( $post ); if ( $neu ) { $box = ThreeRB_Box::clean( array() )['box'] + array( 'score' => null, 'summary' => '', 'place' => ThreeRB_Box::quick_defaults()['place'], ); $box['item']['name'] = ''; } wp_nonce_field( 'threerb_save_' . $post->ID, 'threerb_nonce' ); echo ''; if ( $block ) { echo ''; } echo '
'; if ( $neu ) { echo '

' . esc_html__( 'Rate what this post reviews: one score is enough, criteria are optional.', '3task-review-box' ) . '

'; } echo '
'; $reiter = array( 'bewertung' => __( 'Rating', '3task-review-box' ), 'inhalt' => __( 'Content', '3task-review-box' ), 'links' => __( 'Links and disclosure', '3task-review-box' ), 'google' => __( 'Google', '3task-review-box' ), ); echo '
'; $erster = true; foreach ( $reiter as $schluessel => $titel ) { printf( '', esc_attr( $schluessel ), $erster ? 'true' : 'false', $erster ? '0' : '-1', esc_html( $titel ) ); $erster = false; } echo '
'; // Reiter Bewertung. echo '
'; echo '

'; if ( current_user_can( 'manage_options' ) ) { echo ' '; } echo '

'; echo '
'; if ( $block ) { echo '

' . esc_html__( 'What is rated?', '3task-review-box' ) . '' . esc_html__( 'Name, score, short verdict and placement are set with the star at the top of the editor.', '3task-review-box' ) . '

'; } else { self::text( 'threerb_q[name]', __( 'What is rated?', '3task-review-box' ), $box['item']['name'], 120 ); } self::auswahl( 'threerb[scale]', __( 'Scale', '3task-review-box' ), $box['scale'], array( 'p10' => __( '0 to 10 points', '3task-review-box' ), 's10' => __( '10 stars', '3task-review-box' ), 's5' => __( '5 stars', '3task-review-box' ), 'pct' => __( '0 to 100 percent', '3task-review-box' ), ) ); self::auswahl( 'threerb[step]', __( 'Steps', '3task-review-box' ), (string) $box['step'], array( '0.1' => '0.1', '0.5' => '0.5', '1' => '1', ) ); echo '
'; if ( ! $block ) { self::text( 'threerb_q[score]', __( 'Score (without criteria)', '3task-review-box' ), null === $box['score'] ? '' : (string) $box['score'], 6 ); } echo ''; $zeilen = $box['criteria']; $anzahl = min( 12, max( 4, count( $zeilen ) + 2 ) ); for ( $i = 0; $i < $anzahl; $i++ ) { $k = isset( $zeilen[ $i ] ) ? $zeilen[ $i ] : array( 'label' => '', 'weight' => '', 'score' => '', 'measure' => '', 'note' => '', ); /* translators: %d: row number. */ $nr = sprintf( __( 'Criterion %d', '3task-review-box' ), $i + 1 ); echo ''; printf( '', (int) $i, esc_attr( $k['label'] ), esc_attr( $nr ) ); printf( '', (int) $i, esc_attr( (string) $k['weight'] ), esc_attr( $nr . ': ' . __( 'weight', '3task-review-box' ) ) ); printf( '', (int) $i, esc_attr( null === $k['score'] ? '' : (string) $k['score'] ), esc_attr( $nr . ': ' . __( 'score', '3task-review-box' ) ) ); printf( '', (int) $i, esc_attr( $k['measure'] ), esc_attr( $nr . ': ' . __( 'measured value', '3task-review-box' ) ) ); printf( '', (int) $i, esc_attr( $k['note'] ), esc_attr( $nr . ': ' . __( 'reason', '3task-review-box' ) ) ); echo ''; } echo '
' . esc_html__( 'Criterion', '3task-review-box' ) . '' . esc_html__( 'Weight %', '3task-review-box' ) . '' . esc_html__( 'Score', '3task-review-box' ) . '' . esc_html__( 'Measured value', '3task-review-box' ) . '' . esc_html__( 'Reason (optional)', '3task-review-box' ) . '

' . esc_html__( 'Weights do not need to add up to 100, they count in proportion. With criteria the score calculates itself.', '3task-review-box' ) . '

'; $gesamt = ThreeRB_Score::total( $box ); if ( null !== $gesamt['value'] ) { /* translators: %s: total score. */ echo '

' . esc_html( sprintf( __( 'Total score: %s', '3task-review-box' ), ThreeRB_Render::zahl( $gesamt['value'], $box ) ) ) . ( '' !== ThreeRB_Render::wort( $gesamt['share'] ) ? ' · ' . esc_html( ThreeRB_Render::wort( $gesamt['share'] ) ) : '' ) . '

'; } echo '
'; self::text( 'threerb[override][value]', __( 'Set total score by hand (optional)', '3task-review-box' ), null === $box['override']['value'] ? '' : (string) $box['override']['value'], 6 ); self::text( 'threerb[override][reason]', __( 'Reason (required, at least 10 characters)', '3task-review-box' ), $box['override']['reason'], 200 ); echo '
'; // Reiter Inhalt. echo ''; // Reiter Links und Hinweise. echo ''; // Reiter Google. echo ''; echo '
'; } /** * Test-Check und Schema-Diagnose. Rot verhindert nie das Speichern. * * @param WP_Post $post Beitrag. * @param array $box Box. * @return array */ public static function checks( $post, array $box ) { $c = array(); foreach ( ThreeRB_Diagnose::checks( $post, $box ) as $p ) { $c[] = array( $p['level'], $p['text'] ); } return $c; } /** * CSS und Skript der Eingabe. * * @param string $hook Admin-Seite. */ public static function admin_assets( $hook ) { if ( ! in_array( $hook, array( 'post.php', 'post-new.php' ), true ) ) { return; } $v = THREERB_VERSION . '.' . (int) filemtime( THREERB_DIR . 'assets/js/metabox.js' ); wp_enqueue_style( 'threerb-metabox', THREERB_URL . 'assets/css/metabox.css', array(), $v ); wp_enqueue_script( 'threerb-metabox', THREERB_URL . 'assets/js/metabox.js', array( 'wp-i18n', 'wp-api-fetch' ), $v, true ); wp_set_script_translations( 'threerb-metabox', '3task-review-box' ); wp_add_inline_script( 'threerb-metabox', 'window.threerbMetabox=' . wp_json_encode( array( 'templates' => array_values( ThreeRB_Templates::all() ) ) ) . ';', 'before' ); } /** * Stern-Seitenleiste im Block-Editor. */ public static function editor_assets() { $typen = array(); foreach ( (array) ThreeRB_Settings::value( 'post_types' ) as $typ ) { $objekt = get_post_type_object( $typ ); $typen[] = array( 'label' => $objekt ? $objekt->labels->name : $typ, 'value' => $typ, ); } if ( function_exists( 'generate_block_asset_handle' ) ) { wp_add_inline_script( generate_block_asset_handle( 'threerb/toplist', 'editorScript' ), 'window.threerbBlocks=' . wp_json_encode( array( 'postTypes' => $typen ) ) . ';', 'before' ); } $post = get_post(); if ( ! $post || ! in_array( $post->post_type, ThreeRB_Settings::value( 'post_types' ), true ) ) { return; } $v = THREERB_VERSION . '.' . (int) filemtime( THREERB_DIR . 'assets/js/editor.js' ); wp_enqueue_style( 'threerb-editor', THREERB_URL . 'assets/css/editor.css', array(), THREERB_VERSION . '.' . (int) filemtime( THREERB_DIR . 'assets/css/editor.css' ) ); wp_enqueue_script( 'threerb-editor', THREERB_URL . 'assets/js/editor.js', array( 'wp-plugins', 'wp-editor', 'wp-edit-post', 'wp-element', 'wp-components', 'wp-data', 'wp-blocks', 'wp-i18n', 'wp-core-data' ), $v, true ); wp_set_script_translations( 'threerb-editor', '3task-review-box' ); } /** * TinyMCE-Plugin für den Stern im klassischen Editor. * * @param array $plugins Plugins. * @return array */ public static function mce_plugin( $plugins ) { $post = get_post(); if ( $post && current_user_can( 'edit_post', $post->ID ) && in_array( $post->post_type, ThreeRB_Settings::value( 'post_types' ), true ) ) { $plugins['threerb'] = THREERB_URL . 'assets/js/tinymce.js?v=' . rawurlencode( THREERB_VERSION ); } return $plugins; } /** * Knopf in der Werkzeugleiste. * * @param array $buttons Knöpfe. * @return array */ public static function mce_button( $buttons ) { $post = get_post(); if ( $post && current_user_can( 'edit_post', $post->ID ) && in_array( $post->post_type, ThreeRB_Settings::value( 'post_types' ), true ) ) { $buttons[] = 'threerb'; } return $buttons; } /** * Textfeld. * * @param string $name Name. * @param string $titel Beschriftung. * @param string $wert Wert. * @param int $max Höchstlänge. */ private static function text( $name, $titel, $wert, $max ) { $id = 'threerb-' . sanitize_key( str_replace( array( '[', ']' ), '-', $name ) ); printf( '

', esc_attr( $id ), esc_html( $titel ), esc_attr( $name ), esc_attr( (string) $wert ), (int) $max ); } /** * Textbereich. * * @param string $name Name. * @param string $titel Beschriftung. * @param string $wert Wert. */ private static function flaeche( $name, $titel, $wert ) { $id = 'threerb-' . sanitize_key( str_replace( array( '[', ']' ), '-', $name ) ); printf( '

', esc_attr( $id ), esc_html( $titel ), esc_attr( $name ), esc_textarea( (string) $wert ) ); } /** * Auswahlfeld. * * @param string $name Name. * @param string $titel Beschriftung. * @param string $wert Aktueller Wert. * @param array $optionen Wert => Text. */ private static function auswahl( $name, $titel, $wert, array $optionen ) { $id = 'threerb-' . sanitize_key( str_replace( array( '[', ']' ), '-', $name ) ); printf( '

'; } }