| 1 |
<?php |
| 2 |
/** |
| 3 |
* Code Embed Search |
| 4 |
* |
| 5 |
* Search for specific code embeds across site content. |
| 6 |
* |
| 7 |
* @package simple-embed-code |
| 8 |
*/ |
| 9 |
|
| 10 |
// Exit if accessed directly. |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; |
| 14 |
} |
| 15 |
?> |
| 16 |
<div class="wrap"> |
| 17 |
<h1><?php echo esc_html( __( 'Code Embed search', 'simple-embed-code' ) ); ?></h1> |
| 18 |
|
| 19 |
<?php |
| 20 |
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>'; |
| 21 |
?> |
| 22 |
|
| 23 |
<?php |
| 24 |
|
| 25 |
// Get the suffix from the submitted field. |
| 26 |
|
| 27 |
if ( ! empty( $_POST['ce_suffix'] || '0' === $_POST['ce_suffix'] ) && check_admin_referer( 'code-embed-search', 'code_embed_search_nonce' ) ) { |
| 28 |
$suffix = sanitize_text_field( wp_unslash( $_POST['ce_suffix'] ) ); |
| 29 |
} else { |
| 30 |
$suffix = ''; |
| 31 |
} |
| 32 |
|
| 33 |
// Fetch options into an array. |
| 34 |
|
| 35 |
$options = get_option( 'artiss_code_embed' ); |
| 36 |
?> |
| 37 |
|
| 38 |
<form method="post" action="<?php echo esc_url( admin_url( 'tools.php?page=ce-search' ) ); ?>"> |
| 39 |
|
| 40 |
<?php echo esc_html( $options['opening_ident'] ) . esc_html( $options['keyword_ident'] ); ?> |
| 41 |
|
| 42 |
<input type="text" size="6" name="ce_suffix" aria-label="<?php esc_attr_e( 'Code suffix', 'simple-embed-code' ); ?>" value="<?php echo esc_attr( $suffix ); ?>"/> |
| 43 |
|
| 44 |
<?php echo esc_html( $options['closing_ident'] ); ?> |
| 45 |
|
| 46 |
<?php wp_nonce_field( 'code-embed-search', 'code_embed_search_nonce', true, true ); ?> |
| 47 |
|
| 48 |
<input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e( 'Search', 'simple-embed-code' ); ?>"/> |
| 49 |
|
| 50 |
</form> |
| 51 |
|
| 52 |
<?php |
| 53 |
if ( '' !== $suffix ) { |
| 54 |
|
| 55 |
global $wpdb; |
| 56 |
$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 AND post_status NOT IN ('trash', 'auto-draft', 'inherit') AND post_type IN ('post', 'page') ORDER BY meta_value", $options['keyword_ident'] . $suffix ) ); // @codingStandardsIgnoreLine -- being used for a simple, ad-hoc search feature in admin. Unlikely to be used much and caching on this is overkill |
| 57 |
$records = $wpdb->num_rows; |
| 58 |
|
| 59 |
if ( 0 < $records ) { |
| 60 |
|
| 61 |
echo '<table class="widefat striped">'; |
| 62 |
$prev_html = ''; |
| 63 |
|
| 64 |
foreach ( $meta as $meta_data ) { |
| 65 |
$html = $meta_data->meta_value; |
| 66 |
$post_title = $meta_data->post_title; |
| 67 |
$post_ident = $meta_data->ID; |
| 68 |
|
| 69 |
echo '<tr style="border-bottom-style: dotted; border-top-style: dotted;">' . "\n"; |
| 70 |
echo '<td><a href="' . esc_url( get_edit_post_link( esc_attr( $post_ident ) ) ) . '" >' . esc_html( $post_title ) . "</a></td>\n"; |
| 71 |
|
| 72 |
echo '<td><textarea aria-label="' . esc_attr__( 'Embed code', 'simple-embed-code' ) . '" readonly="readonly" rows="3" cols="80">' . esc_html( $html ) . "</textarea></td>\n"; |
| 73 |
echo "</tr>\n"; |
| 74 |
|
| 75 |
$prev_html = $html; |
| 76 |
} |
| 77 |
|
| 78 |
echo "</table>\n"; |
| 79 |
|
| 80 |
} else { |
| 81 |
|
| 82 |
ce_report_error( esc_html__( 'No posts were found containing that embed code.', 'simple-embed-code' ), 'Code Embed', true ); |
| 83 |
|
| 84 |
} |
| 85 |
} |
| 86 |
?> |
| 87 |
|
| 88 |
</div> |
| 89 |
|