| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* HTML code for the Add New/Edit Snippet page |
| 5 |
* |
| 6 |
* @package Code_Snippets |
| 7 |
* @subpackage Views |
| 8 |
*/ |
| 9 |
|
| 10 |
/* Bail if accessed directly */ |
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
return; |
| 13 |
} |
| 14 |
|
| 15 |
$table = code_snippets()->db->get_table_name(); |
| 16 |
$edit_id = isset( $_REQUEST['id'] ) && intval( $_REQUEST['id'] ) ? absint( $_REQUEST['id'] ) : 0; |
| 17 |
$snippet = get_snippet( $edit_id ); |
| 18 |
|
| 19 |
$classes = array(); |
| 20 |
|
| 21 |
if ( ! $edit_id ) { |
| 22 |
$classes[] = 'new-snippet'; |
| 23 |
} elseif ( 'single-use' === $snippet->scope ) { |
| 24 |
$classes[] = 'single-use-snippet'; |
| 25 |
} else { |
| 26 |
$classes[] = ( $snippet->active ? '' : 'in' ) . 'active-snippet'; |
| 27 |
} |
| 28 |
|
| 29 |
?> |
| 30 |
<div class="wrap"> |
| 31 |
<h1><?php |
| 32 |
|
| 33 |
if ( $edit_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 |
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 |
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 |
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 |
code_snippets()->get_menu_url( 'settings' ) |
| 62 |
); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
?></h1> |
| 67 |
|
| 68 |
<form method="post" id="snippet-form" action="" style="margin-top: 10px;" class="<?php echo implode( ' ', $classes ); ?>"> |
| 69 |
<?php |
| 70 |
/* Output the hidden fields */ |
| 71 |
|
| 72 |
if ( 0 !== $snippet->id ) { |
| 73 |
printf( '<input type="hidden" name="snippet_id" value="%d" />', $snippet->id ); |
| 74 |
} |
| 75 |
|
| 76 |
printf( '<input type="hidden" name="snippet_active" value="%d" />', $snippet->active ); |
| 77 |
|
| 78 |
?> |
| 79 |
<div id="titlediv"> |
| 80 |
<div id="titlewrap"> |
| 81 |
<label for="title" style="display: none;"><?php _e( 'Name', 'code-snippets' ); ?></label> |
| 82 |
<input id="title" type="text" autocomplete="off" name="snippet_name" value="<?php echo esc_attr( $snippet->name ); ?>" placeholder="<?php _e( 'Enter title here', 'code-snippets' ); ?>" /> |
| 83 |
</div> |
| 84 |
</div> |
| 85 |
|
| 86 |
<h2> |
| 87 |
<label for="snippet_code"> |
| 88 |
<?php _e( 'Code', 'code-snippets' ); ?> |
| 89 |
</label> |
| 90 |
</h2> |
| 91 |
|
| 92 |
<div class="snippet-editor"> |
| 93 |
<textarea id="snippet_code" name="snippet_code" rows="200" spellcheck="false" style="font-family: monospace; width: 100%;"><?php |
| 94 |
echo esc_textarea( $snippet->code ); |
| 95 |
?></textarea> |
| 96 |
|
| 97 |
<div class="snippet-editor-help"> |
| 98 |
|
| 99 |
<div class="editor-help-tooltip cm-s-<?php |
| 100 |
echo esc_attr( code_snippets_get_setting( 'editor', 'theme' ) ); ?>"><?php |
| 101 |
echo esc_html_x( '?', 'help tooltip', 'code-snippets' ); ?></div> |
| 102 |
|
| 103 |
<?php |
| 104 |
|
| 105 |
$keys = array( |
| 106 |
'Cmd' => esc_html_x( 'Cmd', 'keyboard key', 'code-snippets' ), |
| 107 |
'Ctrl' => esc_html_x( 'Ctrl', 'keyboard key', 'code-snippets' ), |
| 108 |
'Shift' => esc_html_x( 'Shift', 'keyboard key', 'code-snippets' ), |
| 109 |
'Option' => esc_html_x( 'Option', 'keyboard key', 'code-snippets' ), |
| 110 |
'Alt' => esc_html_x( 'Alt', 'keyboard key', 'code-snippets' ), |
| 111 |
'F' => esc_html_x( 'F', 'keyboard key', 'code-snippets' ), |
| 112 |
'G' => esc_html_x( 'G', 'keyboard key', 'code-snippets' ), |
| 113 |
'R' => esc_html_x( 'R', 'keyboard key', 'code-snippets' ), |
| 114 |
); |
| 115 |
?> |
| 116 |
|
| 117 |
<div class="editor-help-text"> |
| 118 |
<table> |
| 119 |
<tr> |
| 120 |
<td><?php esc_html_e( 'Begin searching', 'code-snippets' ); ?></td> |
| 121 |
<td><kbd class="pc-key"><?php echo $keys['Ctrl']; ?></kbd><kbd class="mac-key"><?php |
| 122 |
echo $keys['Cmd']; ?></kbd>‐<kbd><?php echo $keys['F']; ?></kbd></td> |
| 123 |
</tr> |
| 124 |
<tr> |
| 125 |
<td><?php esc_html_e( 'Find next', 'code-snippets' ); ?></td> |
| 126 |
<td><kbd class="pc-key"><?php echo $keys['Ctrl']; ?></kbd><kbd class="mac-key"><?php echo $keys['Cmd']; ?></kbd>‐<kbd><?php echo $keys['G']; ?></kbd></td> |
| 127 |
</tr> |
| 128 |
<tr> |
| 129 |
<td><?php esc_html_e( 'Find previous', 'code-snippets' ); ?></td> |
| 130 |
<td><kbd><?php echo $keys['Shift']; ?></kbd>-<kbd class="pc-key"><?php echo $keys['Ctrl']; ?></kbd><kbd class="mac-key"><?php echo $keys['Cmd']; ?></kbd>‐<kbd><?php echo $keys['G']; ?></kbd></td> |
| 131 |
</tr> |
| 132 |
<tr> |
| 133 |
<td><?php esc_html_e( 'Replace', 'code-snippets' ); ?></td> |
| 134 |
<td><kbd><?php echo $keys['Shift']; ?></kbd>‐<kbd class="pc-key"><?php echo $keys['Ctrl']; ?></kbd><kbd class="mac-key"><?php echo $keys['Cmd']; ?></kbd>‐<kbd><?php echo $keys['F']; ?></kbd></td> |
| 135 |
</tr> |
| 136 |
<tr> |
| 137 |
<td><?php esc_html_e( 'Replace all', 'code-snippets' ); ?></td> |
| 138 |
<td> |
| 139 |
<kbd><?php echo $keys['Shift']; ?></kbd>‐<kbd class="pc-key"><?php echo $keys['Ctrl']; ?></kbd><kbd class="mac-key"><?php echo $keys['Cmd']; ?></kbd><span class="mac-key">‐</span><kbd class="mac-key"><?php echo $keys['Option']; ?></kbd>‐<kbd><?php echo $keys['R']; ?></kbd> |
| 140 |
</td> |
| 141 |
</tr> |
| 142 |
<tr> |
| 143 |
<td><?php esc_html_e( 'Persistent search', 'code-snippets' ); ?></td> |
| 144 |
<td><kbd><?php echo $keys['Alt']; ?></kbd>‐<kbd><?php echo $keys['F']; ?></kbd></td> |
| 145 |
</tr> |
| 146 |
</table> |
| 147 |
</div> |
| 148 |
</div> |
| 149 |
</div> |
| 150 |
|
| 151 |
<?php |
| 152 |
/* Allow plugins to add fields and content to this page */ |
| 153 |
do_action( 'code_snippets/admin/single', $snippet ); |
| 154 |
|
| 155 |
/* Add a nonce for security */ |
| 156 |
wp_nonce_field( 'save_snippet' ); |
| 157 |
|
| 158 |
?> |
| 159 |
|
| 160 |
<p class="submit"> |
| 161 |
<?php |
| 162 |
|
| 163 |
/* Make the 'Save and Activate' button the default if the setting is enabled */ |
| 164 |
|
| 165 |
if ( $snippet->shared_network && is_network_admin() ) { |
| 166 |
|
| 167 |
submit_button( null, 'primary', 'save_snippet', false ); |
| 168 |
|
| 169 |
} elseif ( 'single-use' === $snippet->scope ) { |
| 170 |
|
| 171 |
submit_button( null, 'primary', 'save_snippet', false ); |
| 172 |
|
| 173 |
submit_button( __( 'Save Changes and Execute Once', 'code-snippets' ), 'secondary', 'save_snippet_execute', false ); |
| 174 |
|
| 175 |
} elseif ( ! $snippet->active && code_snippets_get_setting( 'general', 'activate_by_default' ) ) { |
| 176 |
|
| 177 |
submit_button( |
| 178 |
__( 'Save Changes and Activate', 'code-snippets' ), |
| 179 |
'primary', 'save_snippet_activate', false |
| 180 |
); |
| 181 |
|
| 182 |
submit_button( null, 'secondary', 'save_snippet', false ); |
| 183 |
|
| 184 |
} else { |
| 185 |
|
| 186 |
/* Save Snippet button */ |
| 187 |
submit_button( null, 'primary', 'save_snippet', false ); |
| 188 |
|
| 189 |
/* Save Snippet and Activate/Deactivate button */ |
| 190 |
if ( ! $snippet->active ) { |
| 191 |
submit_button( |
| 192 |
__( 'Save Changes and Activate', 'code-snippets' ), |
| 193 |
'secondary', 'save_snippet_activate', false |
| 194 |
); |
| 195 |
|
| 196 |
} else { |
| 197 |
submit_button( |
| 198 |
__( 'Save Changes and Deactivate', 'code-snippets' ), |
| 199 |
'secondary', 'save_snippet_deactivate', false |
| 200 |
); |
| 201 |
} |
| 202 |
} |
| 203 |
|
| 204 |
if ( 0 !== $snippet->id ) { |
| 205 |
|
| 206 |
/* Download button */ |
| 207 |
|
| 208 |
if ( apply_filters( 'code_snippets/enable_downloads', true ) ) { |
| 209 |
submit_button( __( 'Download', 'code-snippets' ), 'secondary', 'download_snippet', false ); |
| 210 |
} |
| 211 |
|
| 212 |
/* Export button */ |
| 213 |
|
| 214 |
submit_button( __( 'Export', 'code-snippets' ), 'secondary', 'export_snippet', false ); |
| 215 |
|
| 216 |
/* Delete button */ |
| 217 |
|
| 218 |
$confirm_delete_js = esc_js( |
| 219 |
sprintf( |
| 220 |
'return confirm("%s");', |
| 221 |
__( 'You are about to permanently delete this snippet.', 'code-snippets' ) . "\n" . |
| 222 |
__( "'Cancel' to stop, 'OK' to delete.", 'code-snippets' ) |
| 223 |
) |
| 224 |
); |
| 225 |
|
| 226 |
submit_button( |
| 227 |
__( 'Delete', 'code-snippets' ), |
| 228 |
'secondary', 'delete_snippet', false, |
| 229 |
sprintf( 'onclick="%s"', $confirm_delete_js ) |
| 230 |
); |
| 231 |
} |
| 232 |
|
| 233 |
?> |
| 234 |
</p> |
| 235 |
</form> |
| 236 |
</div> |
| 237 |
|