/
theme.php
144 lines (101 loc) · 3.68 KB
/
theme.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
/**
* Admin page for smushing all the images in a given WordPress theme.
*
* Expects a `theme` in the query string.
*
* @version 1.3
* @package WP_SmushIt
*/
if ( FALSE == is_admin() ) {
wp_die(__('You are not logged in to the dashboard.', WP_SMUSHIT_DOMAIN));
}
if ( FALSE === current_user_can('edit_themes') ) {
wp_die(__('You don\'t have permission to work with themes.', WP_SMUSHIT_DOMAIN));
}
ob_start();
$theme = null;
$theme_path = null;
$theme_url = null;
if ( isset($_GET['theme']) && !empty($_GET['theme']) ) {
$theme = attribute_escape($_GET['theme']);
$theme_path = get_theme_root() . '/' . $theme;
$theme_url = get_theme_root_uri() . '/' . $theme;
}
?>
<div class="wrap">
<div id="icon-plugins" class="icon32"><br /></div><h2>WP Smush.it: Smush Theme Assets</h2>
<?php
// Smush files
if (isset($_POST['action']) && $_POST['action'] == 'smush_theme' ):
if ( function_exists('check_admin_referer') ) check_admin_referer('wp-smushit_smush-theme' . $theme);
?>
<p>Processing files in the <strong><?php echo $theme; ?></strong> theme.</p>
<?php
foreach($_POST['smushitlink'] as $l) {
// decode and sanitize the file path
$asset_url = base64_decode($l);
$asset_path = str_replace($theme_url, $theme_path, $asset_url);
print "<p>Smushing <span class='code'>$asset_url</span><br/>";
list($processed_path, $msg) = wp_smushit($asset_path);
echo "<em>– $msg</em>.</p>\n";
ob_flush();
}
?>
<p>Finished processing all the files in the <strong><?php echo $theme; ?></strong> theme.</p>
<p><strong>Actions:</strong>
<a href="themes.php?page=<?php echo basename(dirname(__FILE__)) . '/theme.php&theme=' . $theme; ?>" title="<?php _e('Smush other files in this theme', WP_SMUSHIT_DOMAIN); ?>" target="_parent"><?php _e('Smush other files in this theme', WP_SMUSHIT_DOMAIN); ?></a> |
<a href="<?php echo '?page=' . basename(dirname(__FILE__)) . '/theme.php'; ?>" title="<?php _e('Work with a different theme', WP_SMUSHIT_DOMAIN); ?>" target="_parent"><?php _e('Work with a different theme', WP_SMUSHIT_DOMAIN); ?></a>
</p>
<?php
// Select files to smush
elseif( $theme ):
$td = get_theme_data($theme_path . '/style.css');
?>
<form method="post" action="">
<input type="hidden" name="action" value="smush_theme"/>
<?php
if ( function_exists('wp_nonce_field') ) wp_nonce_field('wp-smushit_smush-theme' . $theme);
?>
<table class="widefat fixed" cellspacing="0">
<thead>
<tr>
<th scope="col" id="cb" class="manage-column column-cb check-column" style=""><input type="checkbox" /></th>
<th scope="col" id="name" class="manage-column column-name" style="">File name</th>
</tr>
<tbody>
<?php
$theme_files = list_files($theme_path, 5);
foreach($theme_files as $file) {
if ( preg_match('/\.(jpg|jpeg|png|gif)$/i', $file) < 1 ) {
continue;
}
$file = str_replace(TEMPLATEPATH, '', $file);
$file_url = $theme_url . $file;
?>
<tr valign="middle">
<th scope="row" class="check-column"><input type="checkbox" name="smushitlink[]" value="<?php echo attribute_escape(base64_encode($file_url)); ?>" /></th>
<td class="column-name"><strong><a class='row-title' href='<?php echo $file_url; ?>'><?php echo $file_url; ?></a></strong></td>
</tr>
<?php
}
// closedir($handle);
?>
</table>
<input type="submit">
</form>
<?php else: ?>
<p>Select a theme.</p>
<ul>
<?php
$themes = get_themes();
foreach($themes as $t) {
printf("\t<li><a href=\"?page=%s&theme=%s\">%s</a></li>\n",
basename(dirname(__FILE__)) . '/theme.php',
$t['Template'],
$t['Name']);
}
?>
</ul>
<?php endif; ?>
</div>