| 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><?php |
| 31 |
|
| 32 |
if ( $snippet->id ) { |
| 33 |
esc_html_e( 'Edit Snippet', 'code-snippets' ); |
| 34 |
printf( ' <a href="%1$s" class="page-title-action add-new-h2">%2$s</a>', |
| 35 |
code_snippets()->get_menu_url( 'add' ), |
| 36 |
esc_html_x( 'Add New', 'snippet', 'code-snippets' ) |
| 37 |
); |
| 38 |
} else { |
| 39 |
esc_html_e( 'Add New Snippet', 'code-snippets' ); |
| 40 |
} |
| 41 |
|
| 42 |
$admin = code_snippets()->admin; |
| 43 |
|
| 44 |
if ( code_snippets()->admin->is_compact_menu() ) { |
| 45 |
|
| 46 |
printf( '<a href="%2$s" class="page-title-action">%1$s</a>', |
| 47 |
esc_html_x( 'Manage', 'snippets', 'code-snippets' ), |
| 48 |
code_snippets()->get_menu_url() |
| 49 |
); |
| 50 |
|
| 51 |
printf( '<a href="%2$s" class="page-title-action">%1$s</a>', |
| 52 |
esc_html_x( 'Import', 'snippets', 'code-snippets' ), |
| 53 |
code_snippets()->get_menu_url( 'import' ) |
| 54 |
); |
| 55 |
|
| 56 |
if ( isset( $admin->menus['settings'] ) ) { |
| 57 |
|
| 58 |
printf( '<a href="%2$s" class="page-title-action">%1$s</a>', |
| 59 |
esc_html_x( 'Settings', 'snippets', 'code-snippets' ), |
| 60 |
code_snippets()->get_menu_url( 'settings' ) |
| 61 |
); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
?></h1> |
| 66 |
|
| 67 |
<form method="post" id="snippet-form" action="" style="margin-top: 10px;" class="<?php echo implode( ' ', $classes ); ?>"> |
| 68 |
<?php |
| 69 |
/* Output the hidden fields */ |
| 70 |
|
| 71 |
if ( 0 !== $snippet->id ) { |
| 72 |
printf( '<input type="hidden" name="snippet_id" value="%d" />', $snippet->id ); |
| 73 |
} |
| 74 |
|
| 75 |
printf( '<input type="hidden" name="snippet_active" value="%d" />', $snippet->active ); |
| 76 |
|
| 77 |
?> |
| 78 |
<div id="titlediv"> |
| 79 |
<div id="titlewrap"> |
| 80 |
<label for="title" style="display: none;"><?php _e( 'Name', 'code-snippets' ); ?></label> |
| 81 |
<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' ); ?>" /> |
| 82 |
</div> |
| 83 |
</div> |
| 84 |
|
| 85 |
<?php if ( apply_filters( 'code_snippets/extra_save_buttons', true ) ) { ?> |
| 86 |
<p class="submit-inline"> |
| 87 |
<?php |
| 88 |
|
| 89 |
$actions['save_snippet'] = array( |
| 90 |
__( 'Save Changes', 'code-snippets' ), |
| 91 |
__( 'Save Snippet', 'code-snippets' ), |
| 92 |
); |
| 93 |
|
| 94 |
if ( 'single-use' === $snippet->scope ) { |
| 95 |
$actions['save_snippet_execute'] = array( |
| 96 |
__( 'Execute Once', 'code-snippets' ), |
| 97 |
__( 'Save Snippet and Execute Once', 'code-snippets' ), |
| 98 |
); |
| 99 |
|
| 100 |
} elseif ( ! $snippet->shared_network || ! is_network_admin() ) { |
| 101 |
|
| 102 |
if ( $snippet->active ) { |
| 103 |
$actions['save_snippet_deactivate'] = array( |
| 104 |
__( 'Deactivate', 'code-snippets' ), |
| 105 |
__( 'Save Snippet and Deactivate', 'code-snippets' ), |
| 106 |
); |
| 107 |
|
| 108 |
} else { |
| 109 |
$actions['save_snippet_activate'] = array( |
| 110 |
__( 'Activate', 'code-snippets' ), |
| 111 |
__( 'Save Snippet and Activate', 'code-snippets' ), |
| 112 |
); |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
foreach ( $actions as $action => $labels ) { |
| 117 |
$other_attributes = array( 'title' => $labels[1], 'id' => $action . '_extra' ); |
| 118 |
submit_button( $labels[0], 'secondary small', $action, false, $other_attributes ); |
| 119 |
} |
| 120 |
|
| 121 |
?> |
| 122 |
</p> |
| 123 |
<?php } ?> |
| 124 |
|
| 125 |
<h2> |
| 126 |
<label for="snippet_code"> |
| 127 |
<?php _e( 'Code', 'code-snippets' ); ?> |
| 128 |
</label> |
| 129 |
</h2> |
| 130 |
|
| 131 |
<div class="snippet-editor"> |
| 132 |
<textarea id="snippet_code" name="snippet_code" rows="200" spellcheck="false" style="font-family: monospace; width: 100%;"><?php |
| 133 |
echo esc_textarea( $snippet->code ); |
| 134 |
?></textarea> |
| 135 |
|
| 136 |
<div class="snippet-editor-help"> |
| 137 |
|
| 138 |
<div class="editor-help-tooltip cm-s-<?php |
| 139 |
echo esc_attr( code_snippets_get_setting( 'editor', 'theme' ) ); ?>"><?php |
| 140 |
echo esc_html_x( '?', 'help tooltip', 'code-snippets' ); ?></div> |
| 141 |
|
| 142 |
<?php |
| 143 |
|
| 144 |
$keys = array( |
| 145 |
'Cmd' => esc_html_x( 'Cmd', 'keyboard key', 'code-snippets' ), |
| 146 |
'Ctrl' => esc_html_x( 'Ctrl', 'keyboard key', 'code-snippets' ), |
| 147 |
'Shift' => esc_html_x( 'Shift', 'keyboard key', 'code-snippets' ), |
| 148 |
'Option' => esc_html_x( 'Option', 'keyboard key', 'code-snippets' ), |
| 149 |
'Alt' => esc_html_x( 'Alt', 'keyboard key', 'code-snippets' ), |
| 150 |
'F' => esc_html_x( 'F', 'keyboard key', 'code-snippets' ), |
| 151 |
'G' => esc_html_x( 'G', 'keyboard key', 'code-snippets' ), |
| 152 |
'R' => esc_html_x( 'R', 'keyboard key', 'code-snippets' ), |
| 153 |
'S' => esc_html_x( 'S', 'keyboard key', 'code-snippets' ), |
| 154 |
); |
| 155 |
|
| 156 |
?> |
| 157 |
|
| 158 |
<div class="editor-help-text"> |
| 159 |
<table> |
| 160 |
<tr> |
| 161 |
<td><?php esc_html_e( 'Save changes', 'code-snippets' ); ?></td> |
| 162 |
<td> |
| 163 |
<kbd class="pc-key"><?php echo $keys['Ctrl']; ?></kbd><kbd class="mac-key"><?php |
| 164 |
echo $keys['Cmd']; ?></kbd>‐<kbd><?php echo $keys['S']; ?></kbd> |
| 165 |
</td> |
| 166 |
</tr> |
| 167 |
<tr> |
| 168 |
<td><?php esc_html_e( 'Begin searching', 'code-snippets' ); ?></td> |
| 169 |
<td> |
| 170 |
<kbd class="pc-key"><?php echo $keys['Ctrl']; ?></kbd><kbd class="mac-key"><?php |
| 171 |
echo $keys['Cmd']; ?></kbd>‐<kbd><?php echo $keys['F']; ?></kbd> |
| 172 |
</td> |
| 173 |
</tr> |
| 174 |
<tr> |
| 175 |
<td><?php esc_html_e( 'Find next', 'code-snippets' ); ?></td> |
| 176 |
<td> |
| 177 |
<kbd class="pc-key"><?php echo $keys['Ctrl']; ?></kbd><kbd class="mac-key"><?php echo $keys['Cmd']; ?></kbd>‐<kbd><?php echo $keys['G']; ?></kbd> |
| 178 |
</td> |
| 179 |
</tr> |
| 180 |
<tr> |
| 181 |
<td><?php esc_html_e( 'Find previous', 'code-snippets' ); ?></td> |
| 182 |
<td> |
| 183 |
<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> |
| 184 |
</td> |
| 185 |
</tr> |
| 186 |
<tr> |
| 187 |
<td><?php esc_html_e( 'Replace', 'code-snippets' ); ?></td> |
| 188 |
<td> |
| 189 |
<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> |
| 190 |
</td> |
| 191 |
</tr> |
| 192 |
<tr> |
| 193 |
<td><?php esc_html_e( 'Replace all', 'code-snippets' ); ?></td> |
| 194 |
<td> |
| 195 |
<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> |
| 196 |
</td> |
| 197 |
</tr> |
| 198 |
<tr> |
| 199 |
<td><?php esc_html_e( 'Persistent search', 'code-snippets' ); ?></td> |
| 200 |
<td> |
| 201 |
<kbd><?php echo $keys['Alt']; ?></kbd>‐<kbd><?php echo $keys['F']; ?></kbd> |
| 202 |
</td> |
| 203 |
</tr> |
| 204 |
</table> |
| 205 |
</div> |
| 206 |
</div> |
| 207 |
</div> |
| 208 |
|
| 209 |
<?php |
| 210 |
/* Allow plugins to add fields and content to this page */ |
| 211 |
do_action( 'code_snippets/admin/single', $snippet ); |
| 212 |
|
| 213 |
/* Add a nonce for security */ |
| 214 |
wp_nonce_field( 'save_snippet' ); |
| 215 |
|
| 216 |
?> |
| 217 |
|
| 218 |
<p class="submit"><?php $this->render_submit_buttons( $snippet ); ?></p> |
| 219 |
</form> |
| 220 |
</div> |
| 221 |
|