| 1 |
<?php |
| 2 |
/** |
| 3 |
* HTML for the Add New/Edit Snippet page. |
| 4 |
* |
| 5 |
* @package Code_Snippets |
| 6 |
* @subpackage Views |
| 7 |
* |
| 8 |
* @var Edit_Menu $this |
| 9 |
*/ |
| 10 |
|
| 11 |
namespace Code_Snippets; |
| 12 |
|
| 13 |
/* Bail if accessed directly */ |
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
return; |
| 16 |
} |
| 17 |
|
| 18 |
$snippet = $this->snippet; |
| 19 |
$classes = array(); |
| 20 |
|
| 21 |
if ( ! $snippet->id ) { |
| 22 |
$classes[] = 'new-snippet'; |
| 23 |
} elseif ( 'single-use' === $snippet->scope ) { |
| 24 |
$classes[] = 'single-use-snippet'; |
| 25 |
} elseif ( 'html' !== $snippet->type ) { |
| 26 |
$classes[] = ( $snippet->active ? '' : 'in' ) . 'active-snippet'; |
| 27 |
} |
| 28 |
|
| 29 |
?> |
| 30 |
<div class="wrap"> |
| 31 |
<h1> |
| 32 |
<?php |
| 33 |
|
| 34 |
if ( $snippet->id ) { |
| 35 |
esc_html_e( 'Edit Snippet', 'code-snippets' ); |
| 36 |
printf( |
| 37 |
' <a href="%1$s" class="page-title-action add-new-h2">%2$s</a>', |
| 38 |
esc_url( add_query_arg( 'type', $snippet->type, code_snippets()->get_menu_url( 'add' ) ) ), |
| 39 |
esc_html_x( 'Add New', 'snippet', 'code-snippets' ) |
| 40 |
); |
| 41 |
} else { |
| 42 |
esc_html_e( 'Add New Snippet', 'code-snippets' ); |
| 43 |
} |
| 44 |
|
| 45 |
if ( code_snippets()->is_compact_menu() ) { |
| 46 |
$this->page_title_actions( [ 'manage', 'import', 'settings' ] ); |
| 47 |
} |
| 48 |
|
| 49 |
?> |
| 50 |
</h1> |
| 51 |
|
| 52 |
<?php $this->print_messages(); ?> |
| 53 |
|
| 54 |
<form method="post" id="snippet-form" action="" class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>" |
| 55 |
data-snippet-type="<?php echo esc_attr( $snippet->type ); ?>"> |
| 56 |
<?php |
| 57 |
/* Output the hidden fields */ |
| 58 |
|
| 59 |
if ( 0 !== $snippet->id ) { |
| 60 |
printf( '<input type="hidden" name="snippet_id" value="%d">', esc_attr( $snippet->id ) ); |
| 61 |
} |
| 62 |
|
| 63 |
printf( '<input type="hidden" name="snippet_active" value="%d">', esc_attr( $snippet->active ) ); |
| 64 |
|
| 65 |
printf( '<input type="hidden" name="current_snippet_scope" value="%s">', esc_attr( $snippet->scope ) ); |
| 66 |
|
| 67 |
do_action( 'code_snippets/admin/before_title_input', $snippet ); |
| 68 |
?> |
| 69 |
|
| 70 |
<div id="titlediv"> |
| 71 |
<div id="titlewrap"> |
| 72 |
<label for="title" style="display: none;"><?php esc_html_e( 'Name', 'code-snippets' ); ?></label> |
| 73 |
<input id="title" type="text" autocomplete="off" name="snippet_name" |
| 74 |
value="<?php echo esc_attr( $snippet->name ); ?>" |
| 75 |
placeholder="<?php esc_attr_e( 'Enter title here', 'code-snippets' ); ?>"> |
| 76 |
</div> |
| 77 |
</div> |
| 78 |
|
| 79 |
<?php do_action( 'code_snippets/admin/after_title_input', $snippet ); ?> |
| 80 |
|
| 81 |
<p class="submit-inline"><?php do_action( 'code_snippets/admin/code_editor_toolbar', $snippet ); ?></p> |
| 82 |
|
| 83 |
<h2> |
| 84 |
<label for="snippet_code"> |
| 85 |
<?php |
| 86 |
esc_html_e( 'Code', 'code-snippets' ); |
| 87 |
|
| 88 |
if ( $snippet->id ) { |
| 89 |
printf( ' <span class="snippet-type-badge" data-type="%s">%s</span>', esc_attr( $snippet->type ), esc_html( $snippet->type ) ); |
| 90 |
} |
| 91 |
|
| 92 |
?> |
| 93 |
</label> |
| 94 |
</h2> |
| 95 |
|
| 96 |
<?php if ( ! $snippet->id ) { ?> |
| 97 |
<h2 class="nav-tab-wrapper" id="snippet-type-tabs"> |
| 98 |
<?php |
| 99 |
|
| 100 |
foreach ( code_snippets()->get_types() as $type_name => $label ) { |
| 101 |
|
| 102 |
if ( $snippet->type === $type_name ) { |
| 103 |
echo '<a class="nav-tab nav-tab-active"'; |
| 104 |
} else { |
| 105 |
printf( '<a class="nav-tab" href="%s"', esc_url( add_query_arg( 'type', $type_name ) ) ); |
| 106 |
} |
| 107 |
|
| 108 |
printf( ' data-type="%s">%s <span>%s</span></a>', esc_attr( $type_name ), esc_html( $label ), esc_html( $type_name ) ); |
| 109 |
} ?> |
| 110 |
</h2> |
| 111 |
<?php } ?> |
| 112 |
|
| 113 |
<div class="snippet-editor"> |
| 114 |
<textarea id="snippet_code" name="snippet_code" rows="200" spellcheck="false" |
| 115 |
style="font-family: monospace; width: 100%;"><?php echo esc_textarea( $snippet->code ); ?></textarea> |
| 116 |
|
| 117 |
<?php $this->render_view( 'partials/editor-shortcuts' ); ?> |
| 118 |
</div> |
| 119 |
|
| 120 |
<div class="below-editor"> |
| 121 |
<?php |
| 122 |
$this->render_view( 'partials/edit-scopes' ); |
| 123 |
do_action( 'code_snippets_below_editor', $snippet ); |
| 124 |
?> |
| 125 |
</div> |
| 126 |
|
| 127 |
<?php |
| 128 |
|
| 129 |
/* Allow plugins to add fields and content to this page */ |
| 130 |
do_action( 'code_snippets_edit_snippet', $snippet ); |
| 131 |
|
| 132 |
/* Add a nonce for security */ |
| 133 |
wp_nonce_field( 'save_snippet' ); |
| 134 |
|
| 135 |
?> |
| 136 |
|
| 137 |
<p class="submit"><?php $this->render_submit_buttons( $snippet ); ?></p> |
| 138 |
</form> |
| 139 |
</div> |
| 140 |
|