| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* HTML code for the Add New/Edit Snippet page |
| 5 |
* |
| 6 |
* @package Code_Snippets |
| 7 |
* @subpackage Views |
| 8 |
* |
| 9 |
* @var Code_Snippets_Edit_Menu $this |
| 10 |
*/ |
| 11 |
|
| 12 |
/* Bail if accessed directly */ |
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
return; |
| 15 |
} |
| 16 |
|
| 17 |
$snippet = $this->snippet; |
| 18 |
$classes = array(); |
| 19 |
|
| 20 |
if ( ! $snippet->id ) { |
| 21 |
$classes[] = 'new-snippet'; |
| 22 |
} elseif ( 'single-use' === $snippet->scope ) { |
| 23 |
$classes[] = 'single-use-snippet'; |
| 24 |
} else { |
| 25 |
$classes[] = ( $snippet->active ? '' : 'in' ) . 'active-snippet'; |
| 26 |
} |
| 27 |
|
| 28 |
?> |
| 29 |
<div class="wrap"> |
| 30 |
<h1> |
| 31 |
<?php |
| 32 |
|
| 33 |
if ( $snippet->id ) { |
| 34 |
esc_html_e( 'Edit Snippet', 'code-snippets' ); |
| 35 |
printf( ' <a href="%1$s" class="page-title-action add-new-h2">%2$s</a>', |
| 36 |
esc_url( code_snippets()->get_menu_url( 'add' ) ), |
| 37 |
esc_html_x( 'Add New', 'snippet', 'code-snippets' ) |
| 38 |
); |
| 39 |
} else { |
| 40 |
esc_html_e( 'Add New Snippet', 'code-snippets' ); |
| 41 |
} |
| 42 |
|
| 43 |
$admin = code_snippets()->admin; |
| 44 |
|
| 45 |
if ( code_snippets()->admin->is_compact_menu() ) { |
| 46 |
|
| 47 |
printf( '<a href="%2$s" class="page-title-action">%1$s</a>', |
| 48 |
esc_html_x( 'Manage', 'snippets', 'code-snippets' ), |
| 49 |
esc_url( code_snippets()->get_menu_url() ) |
| 50 |
); |
| 51 |
|
| 52 |
printf( '<a href="%2$s" class="page-title-action">%1$s</a>', |
| 53 |
esc_html_x( 'Import', 'snippets', 'code-snippets' ), |
| 54 |
esc_url( code_snippets()->get_menu_url( 'import' ) ) |
| 55 |
); |
| 56 |
|
| 57 |
if ( isset( $admin->menus['settings'] ) ) { |
| 58 |
|
| 59 |
printf( '<a href="%2$s" class="page-title-action">%1$s</a>', |
| 60 |
esc_html_x( 'Settings', 'snippets', 'code-snippets' ), |
| 61 |
esc_url( code_snippets()->get_menu_url( 'settings' ) ) |
| 62 |
); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
?> |
| 67 |
</h1> |
| 68 |
|
| 69 |
<form method="post" id="snippet-form" action="" style="margin-top: 10px;" |
| 70 |
class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>"> |
| 71 |
<?php |
| 72 |
/* Output the hidden fields */ |
| 73 |
|
| 74 |
if ( 0 !== $snippet->id ) { |
| 75 |
printf( '<input type="hidden" name="snippet_id" value="%d">', esc_attr( $snippet->id ) ); |
| 76 |
} |
| 77 |
|
| 78 |
printf( '<input type="hidden" name="snippet_active" value="%d">', esc_attr( $snippet->active ) ); |
| 79 |
|
| 80 |
do_action( 'code_snippets/admin/before_title_input', $snippet ); |
| 81 |
?> |
| 82 |
|
| 83 |
<div id="titlediv"> |
| 84 |
<div id="titlewrap"> |
| 85 |
<label for="title" style="display: none;"><?php esc_html_e( 'Name', 'code-snippets' ); ?></label> |
| 86 |
<input id="title" type="text" autocomplete="off" name="snippet_name" |
| 87 |
value="<?php echo esc_attr( $snippet->name ); ?>" |
| 88 |
placeholder="<?php esc_html_e( 'Enter title here', 'code-snippets' ); ?>"> |
| 89 |
</div> |
| 90 |
</div> |
| 91 |
|
| 92 |
<?php do_action( 'code_snippets/admin/after_title_input', $snippet ); ?> |
| 93 |
|
| 94 |
<p class="submit-inline"><?php do_action( 'code_snippets/admin/code_editor_toolbar', $snippet ); ?></p> |
| 95 |
|
| 96 |
<h2><label for="snippet_code"><?php esc_html_e( 'Code', 'code-snippets' ); ?></label></h2> |
| 97 |
|
| 98 |
<div class="snippet-editor"> |
| 99 |
<textarea id="snippet_code" name="snippet_code" rows="200" spellcheck="false" |
| 100 |
style="font-family: monospace; width: 100%;"><?php echo esc_textarea( $snippet->code ); ?></textarea> |
| 101 |
|
| 102 |
<div class="snippet-editor-help"> |
| 103 |
|
| 104 |
<div class="editor-help-tooltip cm-s-<?php |
| 105 |
echo esc_attr( code_snippets_get_setting( 'editor', 'theme' ) ); ?>"><?php |
| 106 |
echo esc_html_x( '?', 'help tooltip', 'code-snippets' ); ?></div> |
| 107 |
|
| 108 |
<div class="editor-help-text"> |
| 109 |
<table> |
| 110 |
<tr> |
| 111 |
<td><?php esc_html_e( 'Save changes', 'code-snippets' ); ?></td> |
| 112 |
<td><?php $this->render_keyboard_shortcut( 'Cmd', 'S' ); ?></td> |
| 113 |
</tr> |
| 114 |
<tr> |
| 115 |
<td><?php esc_html_e( 'Begin searching', 'code-snippets' ); ?></td> |
| 116 |
<td><?php $this->render_keyboard_shortcut( 'Cmd', 'F' ); ?></td> |
| 117 |
</tr> |
| 118 |
<tr> |
| 119 |
<td><?php esc_html_e( 'Find next', 'code-snippets' ); ?></td> |
| 120 |
<td><?php $this->render_keyboard_shortcut( 'Cmd', 'G' ); ?></td> |
| 121 |
</tr> |
| 122 |
<tr> |
| 123 |
<td><?php esc_html_e( 'Find previous', 'code-snippets' ); ?></td> |
| 124 |
<td><?php $this->render_keyboard_shortcut( array( 'Shift', 'Cmd' ), 'G' ); ?></td> |
| 125 |
</tr> |
| 126 |
<tr> |
| 127 |
<td><?php esc_html_e( 'Replace', 'code-snippets' ); ?></td> |
| 128 |
<td><?php $this->render_keyboard_shortcut( array( 'Shift', 'Cmd' ), 'F' ); ?></td> |
| 129 |
</tr> |
| 130 |
<tr> |
| 131 |
<td><?php esc_html_e( 'Replace all', 'code-snippets' ); ?></td> |
| 132 |
<td><?php $this->render_keyboard_shortcut( array( 'Shift', 'Cmd', 'Option' ), 'R' ); ?></td> |
| 133 |
</tr> |
| 134 |
<tr> |
| 135 |
<td><?php esc_html_e( 'Persistent search', 'code-snippets' ); ?></td> |
| 136 |
<td><?php $this->render_keyboard_shortcut( 'Alt', 'F' ); ?></td> |
| 137 |
</tr> |
| 138 |
</table> |
| 139 |
</div> |
| 140 |
</div> |
| 141 |
</div> |
| 142 |
|
| 143 |
<?php |
| 144 |
/* Allow plugins to add fields and content to this page */ |
| 145 |
do_action( 'code_snippets/admin/single', $snippet ); |
| 146 |
|
| 147 |
/* Add a nonce for security */ |
| 148 |
wp_nonce_field( 'save_snippet' ); |
| 149 |
|
| 150 |
?> |
| 151 |
|
| 152 |
<p class="submit"><?php $this->render_submit_buttons( $snippet ); ?></p> |
| 153 |
</form> |
| 154 |
</div> |
| 155 |
|