| 1 |
<?php |
| 2 |
/** |
| 3 |
* Code Embed Search |
| 4 |
* |
| 5 |
* Allow the user to change the default options |
| 6 |
* |
| 7 |
* @package Artiss-Code-Embed |
| 8 |
* @since 1.6 |
| 9 |
* |
| 10 |
* @uses ace_get_embed_paras Get the options |
| 11 |
*/ |
| 12 |
?> |
| 13 |
<div class="wrap"> |
| 14 |
<?php |
| 15 |
global $wp_version; |
| 16 |
if ( ( float ) $wp_version >= 4.3 ) { $heading = '1'; } else { $heading = '2'; } |
| 17 |
?> |
| 18 |
<h<?php echo $heading; ?>><?php _e( 'Code Embed Search', 'simple-embed-code' ); ?></h<?php echo $heading; ?>> |
| 19 |
|
| 20 |
<?php |
| 21 |
echo '<p>' . __( '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>'; |
| 22 |
?> |
| 23 |
|
| 24 |
<?php |
| 25 |
// Get the suffix - either from the submitted field or via the URL line |
| 26 |
if ( isset ( $_GET[ 'suffix' ] ) ) { |
| 27 |
$suffix = htmlspecialchars( $_GET[ 'suffix' ] ); |
| 28 |
} else { |
| 29 |
if ( ( !empty( $_POST ) ) && ( check_admin_referer( 'code-embed-search' , 'code_embed_search_nonce' ) ) ) { |
| 30 |
$suffix = htmlspecialchars( $_POST[ 'ace_suffix' ] ); |
| 31 |
} else { |
| 32 |
$suffix = ''; |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
// Fetch options into an array |
| 37 |
$options = ace_get_embed_paras(); |
| 38 |
?> |
| 39 |
|
| 40 |
<form method="post" action="<?php echo get_bloginfo( 'wpurl' ) . '/wp-admin/admin.php?page=ace-search&updated=true'; ?>"> |
| 41 |
|
| 42 |
<?php echo $options[ 'opening_ident' ] . $options[ 'keyword_ident' ]; ?> |
| 43 |
|
| 44 |
<input type="text" size="6" name="ace_suffix" value="<?php echo $suffix; ?>"/> |
| 45 |
|
| 46 |
<?php echo $options[ 'closing_ident' ]; ?> |
| 47 |
|
| 48 |
<?php wp_nonce_field( 'code-embed-search', 'code_embed_search_nonce', true, true ); ?> |
| 49 |
|
| 50 |
<input type="submit" name="Submit" class="button-primary" value="<?php _e( 'Search', 'simple-embed-code' ); ?>"/> |
| 51 |
|
| 52 |
</form> |
| 53 |
|
| 54 |
<?php |
| 55 |
if ( $suffix != '' ) { |
| 56 |
|
| 57 |
global $wpdb; |
| 58 |
$meta = $wpdb -> get_results( "SELECT meta_value, post_title, ID FROM $wpdb->postmeta, $wpdb->posts WHERE meta_key = '" . $options[ 'keyword_ident' ] . $suffix . "' AND post_id = ID ORDER BY meta_value" ); |
| 59 |
$records = $wpdb -> num_rows; |
| 60 |
|
| 61 |
if ( $records > 0 ) { |
| 62 |
|
| 63 |
echo '<table class="form-table">'; |
| 64 |
$color1 = 'dfdfdf'; |
| 65 |
$color2 = 'ececec'; |
| 66 |
$color = $color1; |
| 67 |
$prev_html = ''; |
| 68 |
|
| 69 |
foreach ( $meta as $meta_data ) { |
| 70 |
$html = $meta_data -> meta_value; |
| 71 |
$post_title = $meta_data -> post_title; |
| 72 |
$post_id = $meta_data -> ID; |
| 73 |
|
| 74 |
// Switch background colours as the code changes |
| 75 |
|
| 76 |
if ( $html != $prev_html ) { if ( $color == $color1 ) { $color = $color2; } else { $color = $color1; } } |
| 77 |
|
| 78 |
echo "<tr style=\"background-color: #" . $color . "\">\n"; |
| 79 |
echo '<td><a href="' . home_url() . '/wp-admin/post.php?post=' . $post_id . '&action=edit" style="color: #f00;">'.$post_title."</td>\n"; |
| 80 |
echo '<td><textarea readonly="readonly" rows="3" cols="80">' . htmlspecialchars( $html ) . "</textarea></td>\n"; |
| 81 |
echo "</tr>\n"; |
| 82 |
|
| 83 |
$prev_html = $html; |
| 84 |
} |
| 85 |
|
| 86 |
echo "</table>\n"; |
| 87 |
|
| 88 |
} else { |
| 89 |
|
| 90 |
echo "<p style=\"color: #f00\">" . __( 'No posts were found containing that embed code.', 'simple-embed-code' ) . "</p>\n"; |
| 91 |
|
| 92 |
} |
| 93 |
} |
| 94 |
?> |
| 95 |
|
| 96 |
</div> |