-
Notifications
You must be signed in to change notification settings - Fork 0
/
templates.php
125 lines (94 loc) · 3.43 KB
/
templates.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( !current_user_can('edit_themes') ) {
wp_die('<p>'.esc_html__('You do not have sufficient permissions to edit templates for this site.', 'codisto-linq' ).'</p>');
}
if ( isset( $_GET['file'] ) ) {
$filename = wp_unslash( $_GET['file'] );
} else {
$filename = 'default.html';
}
$file = WP_CONTENT_DIR . '/ebay/' . $filename;
if( file_exists( $file ) ) {
$content = @file_get_contents($file);
if(!$content) {
$content = '';
}
} else {
$content = '';
}
?>
<?php if ( isset( $_GET['updated'] ) ) : ?>
<div id="message" class="updated notice is-dismissible"><p><?php esc_html_e( 'File edited successfully.', 'codisto-linq' ) ?></p></div>
<?php endif ?>
<div class="wrap">
<h1><?php echo htmlspecialchars( $filename === '_new' ? __( 'New Template File', 'codisto-linq' ) : $filename ); ?>
<span style="font-size: 12px;"><a style="color: #888;" target="codisto!preview" href="codisto/ebaytab/templatepreview">Preview <span style="font-size: inherit; vertical-align: inherit; width: inherit;" class="dashicons dashicons-external"></span></a></span>
</h1>
</div>
<div id="templateside">
<h2>Listing Templates</h2>
<?php
if( is_dir( WP_CONTENT_DIR . '/ebay/' ) ) {
$files = scandir( WP_CONTENT_DIR . '/ebay/' );
} else {
$files = array();
}
?>
<ul class="file-list">
<?php foreach ( $files as $list_file ) {
if ( $list_file[0] === '.' ) {
continue;
}
if( is_dir( WP_CONTENT_DIR . '/ebay/' . $list_file ) ) {
continue;
}
?>
<li><a href="<?php echo htmlspecialchars(admin_url('admin.php?page=codisto-templates&file='.urlencode($list_file))); ?>"><span <?php echo $list_file === $filename ? 'class="highlight"' : ''?>><?php echo htmlspecialchars($list_file) ?></span></a></li>
<?php } ?>
<li><button class="button button-primary new-template"><span class="dashicons dashicons-plus-alt"></span> <?php esc_html_e( 'New Template', 'codisto-linq' ); ?></button></li>
</ul>
</div>
<form name="template" id="template" action="<?php echo htmlspecialchars(admin_url('admin-post.php')); ?>" method="post">
<?php wp_nonce_field( 'edit-ebay-template' ); ?>
<input type="hidden" name="action" value="codisto_update_template" />
<?php if($filename !== '_new') { ?>
<input type="hidden" name="file" value="<?php echo htmlspecialchars($filename); ?>" />
<?php } ?>
<?php if($filename === '_new') { ?>
<br/>
<div>
<label for="filename">New File Name</label> <input id="filename" type="text" name="file" value=""/>
</div><br/>
<?php } ?>
<div>
<textarea cols="70" rows="30" name="newcontent" id="newcontent" aria-describedby="newcontent-description"><?php echo htmlspecialchars($content) ?></textarea>
</div>
<div>
<?php
if ( $filename !== '_new' ) {
if ( is_writeable( $file ) ) {
submit_button( __( 'Update Template', 'codisto-linq' ), 'primary', 'submit', true );
} else {
?>
<p><em><?php echo
wp_kses(
__('You need to make this file writable before you can save your changes. See <a href="https://codex.wordpress.org/Changing_File_Permissions">the Codex</a> for more information.', 'codisto-linq'),
array(
'a' => array(
'class' => array(),
'href' => array()
)
)
); ?></em></p>
<?php
}
} else {
submit_button( __( 'Create New Template', 'codisto-linq' ), 'primary', 'submit', true );
} ?>
</div>
</form>
<?php
include(ABSPATH . 'wp-admin/admin-footer.php' );