'tiboform_entry', 'posts_per_page' => 99, 'fields' => 'ids', 'meta_key' => '_tiboform_status', 'meta_value' => 'new' ) ) ); // phpcs:ignore WordPress.DB.SlowDBQuery $GLOBALS['tiboform_hook'] = add_menu_page( 'TiboForm', 'TiboForm' . ( $n ? ' ' . $n . '' : '' ), 'edit_pages', 'tiboform', 'tiboform_admin_page', 'dashicons-feedback', 27 ); } ); /** * Yönetim sayfası adresi; sekme/görünüm parametreleri nonce ile imzalanır. * * @param array $args Sorgu parametreleri (tab, edit, form, view, status). * @return string */ function tiboform_admin_url( $args = array() ) { $args = array_merge( array( 'page' => 'tiboform' ), $args ); if ( count( $args ) > 1 ) { $args['_tfnonce'] = wp_create_nonce( 'tiboform_nav' ); } return add_query_arg( $args, admin_url( 'admin.php' ) ); } /** * Sayfa parametresi: yalnız geçerli nonce ve yetki varsa okunur, yoksa boş döner. * * @param string $k Anahtar. * @return string */ function tiboform_query( $k ) { static $ok = null; if ( null === $ok ) { $ok = isset( $_GET['_tfnonce'] ) && current_user_can( 'edit_pages' ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_tfnonce'] ) ), 'tiboform_nav' ); } if ( ! $ok || ! isset( $_GET[ $k ] ) || ! is_scalar( $_GET[ $k ] ) ) { return ''; } return sanitize_text_field( wp_unslash( $_GET[ $k ] ) ); } /** * Bir sonraki sayfa yüklemesinde gösterilecek bilgi mesajı. * * @param string $msg Mesaj. */ function tiboform_flash( $msg ) { set_transient( 'tiboform_msg_' . get_current_user_id(), sanitize_text_field( $msg ), MINUTE_IN_SECONDS ); } /** * Sekmeler. * * @return array */ function tiboform_tabs() { $t = apply_filters( 'tiboform_admin_tabs', array( 'forms' => __( 'Forms', 'tiboform' ), 'entries' => __( 'Submissions', 'tiboform' ), ) ); if ( ! tiboform_is_pro() ) { $t['pro'] = 'Pro'; } return $t; } add_action( 'admin_enqueue_scripts', function ( $hook ) { if ( empty( $GLOBALS['tiboform_hook'] ) || $hook !== $GLOBALS['tiboform_hook'] ) { return; } wp_enqueue_style( 'tiboform-ui', TIBOFORM_URL . 'assets/ui.css', array(), TIBOFORM_VERSION ); wp_enqueue_style( 'tiboform-builder', TIBOFORM_URL . 'assets/builder.css', array( 'tiboform-ui' ), TIBOFORM_VERSION ); $edit = absint( tiboform_query( 'edit' ) ); if ( $edit ) { wp_enqueue_script( 'tiboform-builder', TIBOFORM_URL . 'assets/builder.js', array(), TIBOFORM_VERSION, true ); wp_localize_script( 'tiboform-builder', 'tiboformB', array( 'types' => tiboform_types(), 'layout' => tiboform_layout_types(), 'i18n' => array( 'label' => __( 'Label', 'tiboform' ), 'id' => __( 'Field key (for merge tags)', 'tiboform' ), 'required' => __( 'Required', 'tiboform' ), 'half' => __( 'Half width', 'tiboform' ), 'options' => __( 'Options (one per line)', 'tiboform' ), 'ph' => __( 'Placeholder', 'tiboform' ), 'min' => __( 'Minimum', 'tiboform' ), 'max' => __( 'Maximum', 'tiboform' ), 'value' => __( 'Value (use {get:utm_source} to read from the page address)', 'tiboform' ), 'remove' => __( 'Remove', 'tiboform' ), 'up' => __( 'Move up', 'tiboform' ), 'down' => __( 'Move down', 'tiboform' ), 'empty' => __( 'Add fields from the left. Drag to reorder.', 'tiboform' ), 'newField' => __( 'New field', 'tiboform' ), ), ) ); do_action( 'tiboform_builder_enqueue', $edit ); } } ); /** * Sayfa. */ function tiboform_admin_page() { if ( ! current_user_can( 'edit_pages' ) ) { return; } $tabs = tiboform_tabs(); $tab = sanitize_key( tiboform_query( 'tab' ) ); $tab = isset( $tabs[ $tab ] ) || 'new' === $tab ? $tab : 'forms'; $edit = absint( tiboform_query( 'edit' ) ); echo '
| ' . esc_html__( 'Form', 'tiboform' ) . ' | ' . esc_html__( 'Shortcode', 'tiboform' ) . ' | ' . esc_html__( 'Submissions', 'tiboform' ) . ' | |
|---|---|---|---|
| ' . esc_html( $p->post_title ) . ' | [tiboform id="' . absint( $p->ID ) . '"] | ' . absint( $n ) . ' | ' . esc_html__( 'Edit', 'tiboform' ) . ' · ' . esc_html__( 'Delete', 'tiboform' ) . ' |
' . esc_html__( 'Form not found.', 'tiboform' ) . '
'; return; } $s = $f['settings']; echo ''; } add_action( 'admin_post_tiboform_save', function () { $id = isset( $_POST['id'] ) ? absint( $_POST['id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Verified by check_admin_referer() on the next line; the ID is part of the nonce action. check_admin_referer( 'tiboform_save_' . $id ); if ( ! current_user_can( 'edit_pages' ) || 'tiboform_form' !== get_post_type( $id ) ) { wp_die( esc_html__( 'Not allowed.', 'tiboform' ) ); } $old = tiboform_form( $id ); // JSON metni çözülür çözülmez her değer temizlenir; tiboform_clean_schema() alan bazında ayrıca doğrular. $json = isset( $_POST['schema'] ) && is_string( $_POST['schema'] ) ? wp_unslash( $_POST['schema'] ) : '{}'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- JSON metni; çözüldüğü satırın hemen ardından tiboform_sanitize_deep() ile temizlenir. $raw = json_decode( $json, true ); $raw = is_array( $raw ) ? tiboform_sanitize_deep( $raw, true ) : array(); $raw['settings'] = isset( $_POST['s'] ) && is_array( $_POST['s'] ) ? tiboform_sanitize_deep( wp_unslash( $_POST['s'] ), true ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- tiboform_sanitize_deep() her değeri temizler. $clean = tiboform_clean_schema( $raw ); // Bu ekranda gönderilmeyen ayarlar (ör. Pro kapalıyken Pro ayarları) korunur. foreach ( $old['settings'] as $k => $v ) { if ( ! array_key_exists( $k, $clean['settings'] ) ) { $clean['settings'][ $k ] = $v; } } wp_update_post( array( 'ID' => $id, 'post_title' => sanitize_text_field( wp_unslash( $_POST['title'] ?? '' ) ), 'post_content' => wp_slash( wp_json_encode( $clean ) ) ) ); tiboform_flash( __( 'Form saved.', 'tiboform' ) ); wp_safe_redirect( tiboform_admin_url( array( 'edit' => $id ) ) ); exit; } ); /** * Durum rozeti. * * @param string $st Durum. * @return string */ function tiboform_status_badge( $st ) { $l = tiboform_statuses(); return '' . esc_html( isset( $l[ $st ] ) ? $l[ $st ] : $st ) . ''; } /** * Başvurular. */ function tiboform_tab_entries() { // Parametreler tiboform_query() ile yalnız geçerli nonce + yetkiyle okunur. $form = absint( tiboform_query( 'form' ) ); $view = absint( tiboform_query( 'view' ) ); $status = sanitize_key( tiboform_query( 'status' ) ); $sts = tiboform_statuses(); if ( $view && 'tiboform_entry' === get_post_type( $view ) ) { if ( 'new' === tiboform_entry_status( $view ) && current_user_can( 'edit_pages' ) ) { update_post_meta( $view, '_tiboform_status', 'read' ); } $e = get_post( $view ); $st = tiboform_entry_status( $view ); echo '| ' . esc_html( $d['label'] ) . ' | ' . wp_kses_post( tiboform_value_html( $d, $view, 'admin' ) ) . ' |
|---|---|
| ' . esc_html__( 'Page', 'tiboform' ) . ' | ' . esc_html( (string) get_post_meta( $view, '_tiboform_page', true ) ) . ' |
| ' . esc_html__( 'Date', 'tiboform' ) . ' | ' . esc_html( get_the_date( 'j F Y H:i', $e ) ) . ' |
' . esc_html__( 'No submissions yet.', 'tiboform' ) . '
'; } else { echo '| ' . esc_html__( 'Status', 'tiboform' ) . ' | ' . esc_html__( 'Summary', 'tiboform' ) . ' | ' . esc_html__( 'Form', 'tiboform' ) . ' | ' . esc_html__( 'Date', 'tiboform' ) . ' |
|---|---|---|---|
| ' . wp_kses_post( tiboform_status_badge( $st ) ) . ' | ' . esc_html( wp_trim_words( $sum, 16 ) ) . '' . ( get_post_meta( $e->ID, '_tiboform_note', true ) ? ' ✎' : '' ) . ' | ' . esc_html( get_the_title( $e->post_parent ) ) . ' | ' . esc_html( get_the_date( 'j M Y H:i', $e ) ) . ' |