Ranq_Forms_Post_Type::POST_TYPE, 'post_status' => array( 'publish', 'draft' ), 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC', 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, ) ); if ( ! $form_id && $forms ) { $form_id = (int) $forms[0]->ID; } // The entry count per form. The same figure serves the picker, the empty screen // and the pointer to a form that already has entries, so it is counted once, in // one query for all the forms rather than one query per form. $counts = Ranq_Forms_Entries::counts_by_form(); $total = isset( $counts[ $form_id ] ) ? $counts[ $form_id ] : 0; $entries = $form_id ? Ranq_Forms_Entries::get_for_form( $form_id, self::PER_PAGE, ( $paged - 1 ) * self::PER_PAGE ) : array(); $fields = array(); // Only fields that really take input are shown. A heading, a divider and a // page break have no value, so they have nothing to show either. if ( $form_id ) { foreach ( Ranq_Forms_Fields::get_form_fields( $form_id ) as $one ) { $object = isset( $one['type'] ) ? Ranq_Forms_Fields::get( $one['type'] ) : null; if ( $object instanceof Ranq_Forms_Field && $object->is_input() ) { $fields[] = $one; } } } $open = null; $index = 0; foreach ( $entries as $i => $one ) { if ( $open_id && (int) $one['id'] === $open_id ) { $open = $one; $index = (int) $i; break; } } if ( ! $open && $entries ) { $open = $entries[0]; } // A form that already has entries, so the empty screen has something to offer. $other = 0; $other_n = 0; // Only a form that still exists is offered. The counts come from the entries // table, which keeps the entries of a form that has since been deleted. foreach ( $forms as $one ) { $id = (int) $one->ID; $n = isset( $counts[ $id ] ) ? (int) $counts[ $id ] : 0; if ( $id !== (int) $form_id && $n > $other_n ) { $other = $id; $other_n = $n; } } $base = admin_url( 'admin.php?page=' . Ranq_Forms_Admin::PAGE_ENTRIES . '&form_id=' . (int) $form_id ); $table = Ranq_Forms_Install::entries_table(); $code = '[2ranq_form id="' . (int) $form_id . '"]'; $notify = (string) get_option( 'ranq_forms_notify_email', get_option( 'admin_email' ) ); $name = $form_id ? get_the_title( $form_id ) : ''; $day = ''; ?>

0 ? $entries[ $index - 1 ] : null; $next = isset( $entries[ $index + 1 ] ) ? $entries[ $index + 1 ] : null; ?>
'', 'topic' => '', 'snip' => '', 'mail' => '', 'file' => false, ); foreach ( $fields as $field ) { $type = isset( $field['type'] ) ? $field['type'] : ''; $key = isset( $field['id'] ) ? $field['id'] : ''; $raw = isset( $values[ $key ] ) ? $values[ $key ] : ''; if ( 'file' === $type ) { if ( is_array( $raw ) && ! empty( $raw['files'] ) ) { $out['file'] = true; } continue; } $value = trim( (string) self::value( $raw, $field ) ); if ( '' === $value ) { continue; } if ( 'email' === $type && '' === $out['mail'] ) { $out['mail'] = $value; } if ( '' === $out['who'] && in_array( $type, array( 'name', 'text', 'email' ), true ) ) { $out['who'] = $value; continue; } if ( '' === $out['topic'] && in_array( $type, array( 'select', 'radio' ), true ) ) { $out['topic'] = $value; continue; } if ( '' === $out['snip'] && 'textarea' === $type ) { $out['snip'] = $value; } } if ( '' === $out['who'] ) { $out['who'] = sprintf( /* translators: %d: entry number. */ __( 'Entry #%d', '2ranq-forms' ), (int) $entry['id'] ); } return $out; } /** * The value of one field, the way that field itself says it. * * @param mixed $raw The raw value. * @param array $field The field description. * * @return string */ private static function value( $raw, $field ) { $object = isset( $field['type'] ) ? Ranq_Forms_Fields::get( $field['type'] ) : null; if ( $object instanceof Ranq_Forms_Field ) { return (string) $object->format_value( $raw, $field ); } return is_array( $raw ) ? implode( ', ', array_map( 'strval', $raw ) ) : (string) $raw; } /** * The day only, for a group heading in the list. * * @param string $gmt The time in GMT. * * @return string */ private static function day( $gmt ) { $stamp = strtotime( $gmt . ' UTC' ); return $stamp ? wp_date( get_option( 'date_format' ), $stamp ) : (string) $gmt; } /** * The hour only, for a row in the list. * * @param string $gmt The time in GMT. * * @return string */ private static function clock( $gmt ) { $stamp = strtotime( $gmt . ' UTC' ); return $stamp ? wp_date( get_option( 'time_format' ), $stamp ) : ''; } /** * When the entry arrived, in the site's local time. * * @param string $gmt The time in GMT. * * @return string */ private static function when( $gmt ) { $stamp = strtotime( $gmt . ' UTC' ); if ( ! $stamp ) { return $gmt; } return wp_date( get_option( 'date_format' ) . ', ' . get_option( 'time_format' ), $stamp ); } /** * Moving on to the next page. * * @param int $total The total number of entries. * @param int $paged The current page. * @param int $form_id The form id. * * @return void */ private static function pagination( $total, $paged, $form_id ) { $pages = (int) ceil( $total / self::PER_PAGE ); if ( $pages < 2 ) { return; } $links = paginate_links( array( 'base' => admin_url( 'admin.php?page=' . Ranq_Forms_Admin::PAGE_ENTRIES . '&form_id=' . $form_id . '&paged=%#%' ), 'format' => '', 'current' => $paged, 'total' => $pages, 'prev_text' => '«', 'next_text' => '»', ) ); if ( ! $links ) { return; } echo '
' . wp_kses_post( $links ) . '
'; } }