-
Notifications
You must be signed in to change notification settings - Fork 0
/
print-options.php
288 lines (282 loc) · 11.7 KB
/
print-options.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<?php
/*
* WordPress Plugin: WP-Print
* Copyright (c) 2012 Lester "GaMerZ" Chan
*
* File Written By:
* - Lester "GaMerZ" Chan
* - http://lesterchan.net
*
* File Information:
* - Print Options Page
* - wp-content/plugins/wp-print/print-options.php
*/
### Variables Variables Variables
$base_name = plugin_basename('wp-print/print-options.php');
$base_page = 'admin.php?page='.$base_name;
$id = intval($_GET['id']);
$mode = trim($_GET['mode']);
$print_settings = array('print_options');
### Form Processing
// Update Options
if(!empty($_POST['Submit'])) {
$print_options = array();
$print_options['post_text'] = addslashes(trim(wp_filter_kses($_POST['print_post_text'])));
$print_options['page_text'] = addslashes(trim(wp_filter_kses($_POST['print_page_text'])));
$print_options['print_icon'] = trim($_POST['print_icon']);
$print_options['print_style'] = intval($_POST['print_style']);
$print_options['print_html'] = trim($_POST['print_html']);
$print_options['comments'] = intval($_POST['print_comments']);
$print_options['links'] = intval($_POST['print_links']);
$print_options['images'] = intval($_POST['print_images']);
$print_options['videos'] = intval($_POST['print_videos']);
$print_options['disclaimer'] = trim($_POST['print_disclaimer']);
$update_print_queries = array();
$update_print_text = array();
$update_print_queries[] = update_option('print_options', $print_options);
$update_print_text[] = __('Print Options', 'wp-print');
$i=0;
$text = '';
foreach($update_print_queries as $update_print_query) {
if($update_print_query) {
$text .= '<font color="green">'.$update_print_text[$i].' '.__('Updated', 'wp-print').'</font><br />';
}
$i++;
}
if(empty($text)) {
$text = '<font color="red">'.__('No Print Option Updated', 'wp-print').'</font>';
}
}
// Uninstall WP-Print
if(!empty($_POST['do'])) {
switch($_POST['do']) {
case __('UNINSTALL WP-Print', 'wp-print') :
if(trim($_POST['uninstall_print_yes']) == 'yes') {
echo '<div id="message" class="updated fade">';
echo '<p>';
foreach($print_settings as $setting) {
$delete_setting = delete_option($setting);
if($delete_setting) {
echo '<font color="green">';
printf(__('Setting Key \'%s\' has been deleted.', 'wp-print'), "<strong><em>{$setting}</em></strong>");
echo '</font><br />';
} else {
echo '<font color="red">';
printf(__('Error deleting Setting Key \'%s\'.', 'wp-print'), "<strong><em>{$setting}</em></strong>");
echo '</font><br />';
}
}
echo '</p>';
echo '</div>';
$mode = 'end-UNINSTALL';
}
break;
}
}
### Determines Which Mode It Is
switch($mode) {
// Deactivating WP-Print
case 'end-UNINSTALL':
$deactivate_url = 'plugins.php?action=deactivate&plugin=wp-print/wp-print.php';
if(function_exists('wp_nonce_url')) {
$deactivate_url = wp_nonce_url($deactivate_url, 'deactivate-plugin_wp-print/wp-print.php');
}
echo '<div class="wrap">';
echo '<h2>'.__('Uninstall WP-Print', 'wp-print').'</h2>';
echo '<p><strong>'.sprintf(__('<a href="%s">Click Here</a> To Finish The Uninstallation And WP-Print Will Be Deactivated Automatically.', 'wp-print'), $deactivate_url).'</strong></p>';
echo '</div>';
break;
// Main Page
default:
$print_options = get_option('print_options');
?>
<script type="text/javascript">
/* <![CDATA[*/
function check_print_style() {
if (parseInt(jQuery("#print_style").val()) == 4) {
jQuery("#print_style_custom").show();
} else {
if(jQuery("#print_style_custom").is(":visible")) {
jQuery("#print_style_custom").hide();
}
}
}
function print_default_templates(template) {
var default_template;
switch(template) {
case 'html':
default_template = '<a href="%PRINT_URL%" rel="nofollow" title="%PRINT_TEXT%">%PRINT_TEXT%</a>';
break;
case 'disclaimer':
default_template = '<?php echo js_escape(sprintf(__('Copyright © %s %s. All rights reserved.', 'wp-print'), date('Y'), get_option('blogname'))); ?>';
break;
}
jQuery("#print_template_" + template).val(default_template);
}
/* ]]> */
</script>
<?php if(!empty($text)) { echo '<!-- Last Action --><div id="message" class="updated fade"><p>'.$text.'</p></div>'; } ?>
<form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
<div class="wrap">
<?php screen_icon(); ?>
<h2><?php _e('Print Options', 'wp-print'); ?></h2>
<h3><?php _e('Print Styles', 'wp-print'); ?></h3>
<table class="form-table">
<tr>
<th scope="row" valign="top"><?php _e('Print Text Link For Post', 'wp-print'); ?></th>
<td>
<input type="text" name="print_post_text" value="<?php echo stripslashes($print_options['post_text']); ?>" size="30" />
</td>
</tr>
<tr>
<th scope="row" valign="top"><?php _e('Print Text Link For Page', 'wp-print'); ?></th>
<td>
<input type="text" name="print_page_text" value="<?php echo stripslashes($print_options['page_text']); ?>" size="30" />
</td>
</tr>
<tr>
<th scope="row" valign="top"><?php _e('Print Icon', 'wp-print'); ?></th>
<td>
<?php
$print_icon = $print_options['print_icon'];
$print_icon_url = plugins_url('wp-print/images');
$print_icon_path = WP_PLUGIN_DIR.'/wp-print/images';
if($handle = @opendir($print_icon_path)) {
while (false !== ($filename = readdir($handle))) {
if ($filename != '.' && $filename != '..') {
if(is_file($print_icon_path.'/'.$filename)) {
echo '<p>';
if($print_icon == $filename) {
echo '<input type="radio" name="print_icon" value="'.$filename.'" checked="checked" />'."\n";
} else {
echo '<input type="radio" name="print_icon" value="'.$filename.'" />'."\n";
}
echo ' ';
echo '<img src="'.$print_icon_url.'/'.$filename.'" alt="'.$filename.'" />'."\n";
echo ' ('.$filename.')';
echo '</p>'."\n";
}
}
}
closedir($handle);
}
?>
</td>
</tr>
<tr>
<th scope="row" valign="top"><?php _e('Print Text Link Style', 'wp-print'); ?></th>
<td>
<select name="print_style" id="print_style" size="1" onchange="check_print_style();">
<option value="1"<?php selected('1', $print_options['print_style']); ?>><?php _e('Print Icon With Text Link', 'wp-print'); ?></option>
<option value="2"<?php selected('2', $print_options['print_style']); ?>><?php _e('Print Icon Only', 'wp-print'); ?></option>
<option value="3"<?php selected('3', $print_options['print_style']); ?>><?php _e('Print Text Link Only', 'wp-print'); ?></option>
<option value="4"<?php selected('4', $print_options['print_style']); ?>><?php _e('Custom', 'wp-print'); ?></option>
</select>
<div id="print_style_custom" style="display: <?php if(intval($print_options['print_style']) == 4) { echo 'block'; } else { echo 'none'; } ?>; margin-top: 20px;">
<textarea rows="2" cols="80" name="print_html" id="print_template_html"><?php echo htmlspecialchars(stripslashes($print_options['print_html'])); ?></textarea><br />
<?php _e('HTML is allowed.', 'wp-print'); ?><br />
%PRINT_URL% - <?php _e('URL to the printable post/page.', 'wp-print'); ?><br />
%PRINT_TEXT% - <?php _e('Print text link of the post/page that you have typed in above.', 'wp-print'); ?><br />
%PRINT_ICON_URL% - <?php _e('URL to the print icon you have chosen above.', 'wp-print'); ?><br />
<input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template', 'wp-print'); ?>" onclick="print_default_templates('html');" class="button" />
</div>
</td>
</tr>
</table>
<h3><?php _e('Print Options', 'wp-print'); ?></h3>
<table class="form-table">
<tr>
<th scope="row" valign="top"><?php _e('Print Comments?', 'wp-print'); ?></th>
<td>
<select name="print_comments" size="1">
<option value="1"<?php selected('1', $print_options['comments']); ?>><?php _e('Yes', 'wp-print'); ?></option>
<option value="0"<?php selected('0', $print_options['comments']); ?>><?php _e('No', 'wp-print'); ?></option>
</select>
</td>
</tr>
<tr>
<th scope="row" valign="top"><?php _e('Print Links?', 'wp-print'); ?></th>
<td>
<select name="print_links" size="1">
<option value="1"<?php selected('1', $print_options['links']); ?>><?php _e('Yes', 'wp-print'); ?></option>
<option value="0"<?php selected('0', $print_options['links']); ?>><?php _e('No', 'wp-print'); ?></option>
</select>
</td>
</tr>
<tr>
<th scope="row" valign="top"><?php _e('Print Images?', 'wp-print'); ?></th>
<td>
<select name="print_images" size="1">
<option value="1"<?php selected('1', $print_options['images']); ?>><?php _e('Yes', 'wp-print'); ?></option>
<option value="0"<?php selected('0', $print_options['images']); ?>><?php _e('No', 'wp-print'); ?></option>
</select>
</td>
</tr>
<tr>
<th scope="row" valign="top"><?php _e('Print Videos?', 'wp-print'); ?></th>
<td>
<select name="print_videos" size="1">
<option value="1"<?php selected('1', $print_options['videos']); ?>><?php _e('Yes', 'wp-print'); ?></option>
<option value="0"<?php selected('0', $print_options['videos']); ?>><?php _e('No', 'wp-print'); ?></option>
</select>
</td>
</tr>
<tr>
<th scope="row" valign="top">
<?php _e('Disclaimer/Copyright Text?', 'wp-print'); ?>
<br /><br />
<input type="button" name="RestoreDefault" value="<?php _e('Restore Default Template', 'wp-print'); ?>" onclick="print_default_templates('disclaimer');" class="button" />
</th>
<td>
<textarea rows="2" cols="80" name="print_disclaimer" id="print_template_disclaimer"><?php echo htmlspecialchars(stripslashes($print_options['disclaimer'])); ?></textarea><br /><?php _e('HTML is allowed.', 'wp-print'); ?><br />
</td>
</tr>
</table>
<p class="submit">
<input type="submit" name="Submit" class="button" value="<?php _e('Save Changes', 'wp-print'); ?>" />
</p>
</div>
</form>
<p> </p>
<!-- Uninstall WP-Print -->
<form method="post" action="<?php echo admin_url('admin.php?page='.plugin_basename(__FILE__)); ?>">
<div class="wrap">
<h3><?php _e('Uninstall WP-Print', 'wp-print'); ?></h3>
<p>
<?php _e('Deactivating WP-Print plugin does not remove any data that may have been created, such as the print options. To completely remove this plugin, you can uninstall it here.', 'wp-print'); ?>
</p>
<p style="color: red">
<strong><?php _e('WARNING:', 'wp-print'); ?></strong><br />
<?php _e('Once uninstalled, this cannot be undone. You should use a Database Backup plugin of WordPress to back up all the data first.', 'wp-print'); ?>
</p>
<p style="color: red">
<strong><?php _e('The following WordPress Options will be DELETED:', 'wp-print'); ?></strong><br />
</p>
<table class="widefat">
<thead>
<tr>
<th><?php _e('WordPress Options', 'wp-print'); ?></th>
</tr>
</thead>
<tr>
<td valign="top">
<ol>
<?php
foreach($print_settings as $settings) {
echo '<li>'.$settings.'</li>'."\n";
}
?>
</ol>
</td>
</tr>
</table>
<p> </p>
<p style="text-align: center;">
<input type="checkbox" name="uninstall_print_yes" value="yes" /> <?php _e('Yes', 'wp-print'); ?><br /><br />
<input type="submit" name="do" value="<?php _e('UNINSTALL WP-Print', 'wp-print'); ?>" class="button" onclick="return confirm('<?php _e('You Are About To Uninstall WP-Print From WordPress.\nThis Action Is Not Reversible.\n\n Choose [Cancel] To Stop, [OK] To Uninstall.', 'wp-print'); ?>')" />
</p>
</div>
</form>
<?php
} // End switch($mode)
?>