PluginProbe
Code Embed / 2.4
Code Embed v2.4
2.6.4 2.6.3 2.6.2 2.6.1 trunk 1.0 1.1 1.2 1.3 1.4.1 1.5.1 1.6.1 2.0.2 2.1.2 2.2.2 2.3.9 2.4 2.5.1 2.5.2 2.6
simple-embed-code / includes / search-screen.php

search-screen.php in Code Embed 2.4, at includes/search-screen.php

95 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Code Embed Search
4 *
5 * Allow the user to change the default options
6 *
7 * @package simple-embed-code
8 */
9
10 ?>
11 <div class="wrap">
12 <h1><?php echo esc_html( ucwords( __( 'Code Embed search', 'simple-embed-code' ) ) ); ?></h1>
13
14 <?php
15 echo '<p>' . esc_html__( 'Enter the suffix to search for below and press the \'Search\' button to view the results. Further help can be found by clicking on the Help tab at the top right-hand of the screen.', 'simple-embed-code' ) . '</p>';
16 ?>
17
18 <?php
19
20 // Get the suffix from the submitted field.
21
22 if ( ! empty( $_POST['ce_suffix'] ) && check_admin_referer( 'code-embed-search', 'code_embed_search_nonce' ) ) { // Input var okay.
23 $suffix = htmlspecialchars( sanitize_title( wp_unslash( $_POST['ce_suffix'] ) ) ); // Input var okay.
24 } else {
25 $suffix = '';
26 }
27
28 // Fetch options into an array.
29
30 $options = get_option( 'artiss_code_embed' );
31 ?>
32
33 <form method="post" action="<?php echo esc_url( get_bloginfo( 'wpurl' ) ) . '/wp-admin/tools.php?page=ce-search'; ?>">
34
35 <?php echo esc_html( $options['opening_ident'] ) . esc_html( $options['keyword_ident'] ); ?>
36
37 <input type="text" size="6" name="ce_suffix" value="<?php echo esc_attr( $suffix ); ?>"/>
38
39 <?php echo esc_html( $options['closing_ident'] ); ?>
40
41 <?php wp_nonce_field( 'code-embed-search', 'code_embed_search_nonce', true, true ); ?>
42
43 <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e( 'Search', 'simple-embed-code' ); ?>"/>
44
45 </form>
46
47 <?php
48 if ( '' !== $suffix ) {
49
50 global $wpdb;
51 $meta = $wpdb->get_results( $wpdb->prepare( "SELECT meta_value, post_title, ID FROM $wpdb->postmeta, $wpdb->posts WHERE meta_key = %s AND post_id = ID ORDER BY meta_value", esc_html( $options['keyword_ident'] ) . esc_html( $suffix ) ) ); // @codingStandardsIgnoreLine -- being used for a simple, ad-hoc search feature in admin. Unlikely to be used much and caching on this is overkill
52 $records = $wpdb->num_rows;
53
54 if ( 0 < $records ) {
55
56 echo '<table class="form-table">';
57 $color1 = 'dfdfdf';
58 $color2 = 'ececec';
59 $color = $color1;
60 $prev_html = '';
61
62 foreach ( $meta as $meta_data ) {
63 $html = $meta_data->meta_value;
64 $post_title = $meta_data->post_title;
65 $post_ident = $meta_data->ID;
66
67 // Switch background colours as the code changes.
68
69 if ( $html !== $prev_html ) {
70 if ( $color === $color1 ) {
71 $color = $color2;
72 } else {
73 $color = $color1; }
74 }
75
76 echo '<tr style="background-color: #' . esc_html( $color ) . "\">\n";
77 echo '<td><a href="' . esc_url( home_url() ) . '/wp-admin/post.php?post=' . esc_attr( $post_ident ) . '&action=edit" style="color: #f00;">' . esc_html( $post_title ) . "</td>\n";
78 echo '<td><textarea readonly="readonly" rows="3" cols="80">' . esc_html( $html ) . "</textarea></td>\n";
79 echo "</tr>\n";
80
81 $prev_html = $html;
82 }
83
84 echo "</table>\n";
85
86 } else {
87
88 echo '<p style="color: #f00">' . esc_html__( 'No posts were found containing that embed code.', 'simple-embed-code' ) . "</p>\n";
89
90 }
91 }
92 ?>
93
94 </div>
95