| 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[] = ( $snippet->active ? '' : 'in' ) . 'active-snippet'; |
| 23 |
} else { |
| 24 |
$classes[] = 'new-snippet'; |
| 25 |
} |
| 26 |
|
| 27 |
?> |
| 28 |
<div class="wrap"> |
| 29 |
<h1><?php |
| 30 |
|
| 31 |
if ( $edit_id ) { |
| 32 |
esc_html_e( 'Edit Snippet', 'code-snippets' ); |
| 33 |
printf( ' <a href="%1$s" class="page-title-action add-new-h2">%2$s</a>', |
| 34 |
code_snippets()->get_menu_url( 'add' ), |
| 35 |
esc_html_x( 'Add New', 'snippet', 'code-snippets' ) |
| 36 |
); |
| 37 |
} else { |
| 38 |
esc_html_e( 'Add New Snippet', 'code-snippets' ); |
| 39 |
} |
| 40 |
|
| 41 |
if ( code_snippets()->admin->is_compact_menu() ) { |
| 42 |
|
| 43 |
printf( '<a href="%2$s" class="page-title-action">%1$s</a>', |
| 44 |
esc_html_x( 'Manage', 'snippets', 'code-snippets' ), |
| 45 |
code_snippets()->get_menu_url() |
| 46 |
); |
| 47 |
|
| 48 |
printf( '<a href="%2$s" class="page-title-action">%1$s</a>', |
| 49 |
esc_html_x( 'Import', 'snippets', 'code-snippets' ), |
| 50 |
code_snippets()->get_menu_url( 'import' ) |
| 51 |
); |
| 52 |
|
| 53 |
if ( isset( $admin->menus['settings'] ) ) { |
| 54 |
|
| 55 |
printf( '<a href="%2$s" class="page-title-action">%1$s</a>', |
| 56 |
esc_html_x( 'Settings', 'snippets', 'code-snippets' ), |
| 57 |
code_snippets()->get_menu_url( 'settings' ) |
| 58 |
); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
?></h1> |
| 63 |
|
| 64 |
<form method="post" id="snippet-form" action="" style="margin-top: 10px;" class="<?php echo implode( ' ', $classes ); ?>"> |
| 65 |
<?php |
| 66 |
/* Output the hidden fields */ |
| 67 |
|
| 68 |
if ( 0 !== $snippet->id ) { |
| 69 |
printf( '<input type="hidden" name="snippet_id" value="%d" />', $snippet->id ); |
| 70 |
} |
| 71 |
|
| 72 |
printf( '<input type="hidden" name="snippet_active" value="%d" />', $snippet->active ); |
| 73 |
|
| 74 |
?> |
| 75 |
<div id="titlediv"> |
| 76 |
<div id="titlewrap"> |
| 77 |
<label for="title" style="display: none;"><?php _e( 'Name', 'code-snippets' ); ?></label> |
| 78 |
<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' ); ?>" /> |
| 79 |
</div> |
| 80 |
</div> |
| 81 |
|
| 82 |
<h2> |
| 83 |
<label for="snippet_code"> |
| 84 |
<?php _e( 'Code', 'code-snippets' ); ?> |
| 85 |
</label> |
| 86 |
</h2> |
| 87 |
|
| 88 |
<textarea id="snippet_code" name="snippet_code" rows="200" spellcheck="false" style="font-family: monospace; width: 100%;"><?php |
| 89 |
echo esc_textarea( $snippet->code ); |
| 90 |
?></textarea> |
| 91 |
|
| 92 |
<?php |
| 93 |
/* Allow plugins to add fields and content to this page */ |
| 94 |
do_action( 'code_snippets/admin/single', $snippet ); |
| 95 |
|
| 96 |
/* Add a nonce for security */ |
| 97 |
wp_nonce_field( 'save_snippet' ); |
| 98 |
|
| 99 |
?> |
| 100 |
|
| 101 |
<p class="submit"> |
| 102 |
<?php |
| 103 |
|
| 104 |
/* Make the 'Save and Activate' button the default if the setting is enabled */ |
| 105 |
|
| 106 |
if ( 'single-use' === $snippet->scope ) { |
| 107 |
|
| 108 |
submit_button( null, 'primary', 'save_snippet', false ); |
| 109 |
|
| 110 |
submit_button( __( 'Save Changes and Execute Once', 'code-snippets' ), 'secondary', 'save_snippet_execute', false ); |
| 111 |
|
| 112 |
} elseif ( $snippet->shared_network && is_network_admin() ) { |
| 113 |
|
| 114 |
submit_button( null, 'primary', 'save_snippet', false ); |
| 115 |
|
| 116 |
} elseif ( ! $snippet->active && code_snippets_get_setting( 'general', 'activate_by_default' ) ) { |
| 117 |
|
| 118 |
submit_button( |
| 119 |
__( 'Save Changes and Activate', 'code-snippets' ), |
| 120 |
'primary', 'save_snippet_activate', false |
| 121 |
); |
| 122 |
|
| 123 |
submit_button( null, 'secondary', 'save_snippet', false ); |
| 124 |
|
| 125 |
} else { |
| 126 |
|
| 127 |
/* Save Snippet button */ |
| 128 |
submit_button( null, 'primary', 'save_snippet', false ); |
| 129 |
|
| 130 |
/* Save Snippet and Activate/Deactivate button */ |
| 131 |
if ( ! $snippet->active ) { |
| 132 |
submit_button( |
| 133 |
__( 'Save Changes and Activate', 'code-snippets' ), |
| 134 |
'secondary', 'save_snippet_activate', false |
| 135 |
); |
| 136 |
|
| 137 |
} else { |
| 138 |
submit_button( |
| 139 |
__( 'Save Changes and Deactivate', 'code-snippets' ), |
| 140 |
'secondary', 'save_snippet_deactivate', false |
| 141 |
); |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
if ( 0 !== $snippet->id ) { |
| 146 |
|
| 147 |
/* Download button */ |
| 148 |
|
| 149 |
if ( apply_filters( 'code_snippets/enable_downloads', true ) ) { |
| 150 |
submit_button( __( 'Download', 'code-snippets' ), 'secondary', 'download_snippet', false ); |
| 151 |
} |
| 152 |
|
| 153 |
/* Export button */ |
| 154 |
|
| 155 |
submit_button( __( 'Export', 'code-snippets' ), 'secondary', 'export_snippet', false ); |
| 156 |
|
| 157 |
/* Delete button */ |
| 158 |
|
| 159 |
$confirm_delete_js = esc_js( |
| 160 |
sprintf( |
| 161 |
'return confirm("%s");', |
| 162 |
__( 'You are about to permanently delete this snippet.', 'code-snippets' ) . "\n" . |
| 163 |
__( "'Cancel' to stop, 'OK' to delete.", 'code-snippets' ) |
| 164 |
) |
| 165 |
); |
| 166 |
|
| 167 |
submit_button( |
| 168 |
__( 'Delete', 'code-snippets' ), |
| 169 |
'secondary', 'delete_snippet', false, |
| 170 |
sprintf( 'onclick="%s"', $confirm_delete_js ) |
| 171 |
); |
| 172 |
} |
| 173 |
|
| 174 |
?> |
| 175 |
</p> |
| 176 |
</form> |
| 177 |
</div> |
| 178 |
|