42
42
function press_it() {
43
43
// define some basic variables
44
44
$quick['post_status'] = 'draft'; // set as draft first
45
$quick['post_category'] = isset($_REQUEST['post_category']) ? $_REQUEST['post_category'] : null;
46
$quick['tax_input'] = isset($_REQUEST['tax_input']) ? $_REQUEST['tax_input'] : '';
47
$quick['post_title'] = isset($_REQUEST['title']) ? $_REQUEST['title'] : '';
48
$quick['post_content'] = '';
45
$quick['post_category'] = isset($_POST['post_category']) ? $_POST['post_category'] : null;
46
$quick['tax_input'] = isset($_POST['tax_input']) ? $_POST['tax_input'] : null;
47
$quick['post_title'] = ( trim($_POST['title']) != '' ) ? $_POST['title'] : ' ';
48
$quick['post_content'] = isset($_POST['post_content']) ? $_POST['post_content'] : '';
50
50
// insert the post with nothing in it, to get an ID
51
51
$post_ID = wp_insert_post($quick, true);
52
$content = isset($_REQUEST['content']) ? $_REQUEST['content'] : '';
52
if ( is_wp_error($post_ID) )
55
$content = isset($_POST['content']) ? $_POST['content'] : '';
55
if( !empty($_REQUEST['photo_src']) && current_user_can('upload_files') )
56
foreach( (array) $_REQUEST['photo_src'] as $key => $image)
58
if( !empty($_POST['photo_src']) && current_user_can('upload_files') ) {
59
foreach( (array) $_POST['photo_src'] as $key => $image) {
57
60
// see if files exist in content - we don't want to upload non-used selected files.
58
if( strpos($_REQUEST['content'], $image) !== false ) {
59
$desc = isset($_REQUEST['photo_description'][$key]) ? $_REQUEST['photo_description'][$key] : '';
61
if ( strpos($_POST['content'], htmlspecialchars($image)) !== false ) {
62
$desc = isset($_POST['photo_description'][$key]) ? $_POST['photo_description'][$key] : '';
60
63
$upload = media_sideload_image($image, $post_ID, $desc);
62
65
// Replace the POSTED content <img> with correct uploaded ones. Regex contains fix for Magic Quotes
63
if( !is_wp_error($upload) ) $content = preg_replace('/<img ([^>]*)src=\\\?(\"|\')'.preg_quote($image, '/').'\\\?(\2)([^>\/]*)\/*>/is', $upload, $content);
66
if( !is_wp_error($upload) )
67
$content = preg_replace('/<img ([^>]*)src=\\\?(\"|\')'.preg_quote(htmlspecialchars($image), '/').'\\\?(\2)([^>\/]*)\/*>/is', $upload, $content);
66
71
// set the post_content and status
67
$quick['post_status'] = isset($_REQUEST['publish']) ? 'publish' : 'draft';
72
$quick['post_status'] = isset($_POST['publish']) ? 'publish' : 'draft';
68
73
$quick['post_content'] = $content;
69
// error handling for $post
70
if ( is_wp_error($post_ID)) {
72
wp_delete_post($post_ID);
73
74
// error handling for media_sideload
74
} elseif ( is_wp_error($upload)) {
75
if ( is_wp_error($upload) ) {
76
wp_delete_post($post_ID);
76
wp_delete_post($post_ID);
78
79
$quick['ID'] = $post_ID;
79
80
wp_update_post($quick);
94
$title = isset($_GET['t']) ? esc_html(aposfix(stripslashes($_GET['t']))) : '';
95
$selection = isset($_GET['s']) ? trim( aposfix( stripslashes($_GET['s']) ) ) : '';
95
$title = isset( $_GET['t'] ) ? trim( strip_tags( aposfix( stripslashes( $_GET['t'] ) ) ) ) : '';
96
$selection = isset( $_GET['s'] ) ? trim( htmlspecialchars( html_entity_decode( aposfix( stripslashes( $_GET['s'] ) ) ) ) ) : '';
96
97
if ( ! empty($selection) ) {
97
98
$selection = preg_replace('/(\r?\n|\r)/', '</p><p>', $selection);
98
99
$selection = '<p>'.str_replace('<p></p>', '', $selection).'</p>';
100
102
$url = isset($_GET['u']) ? esc_url($_GET['u']) : '';
101
103
$image = isset($_GET['i']) ? $_GET['i'] : '';
103
105
if ( !empty($_REQUEST['ajax']) ) {
104
switch ($_REQUEST['ajax']) {
106
<script type="text/javascript" charset="utf-8">
107
jQuery('.select').click(function() {
108
append_editor(jQuery('#embed-code').val());
109
jQuery('#extra_fields').hide();
110
jQuery('#extra_fields').html('');
112
jQuery('.close').click(function() {
113
jQuery('#extra_fields').hide();
114
jQuery('#extra_fields').html('');
117
<div class="postbox">
118
<h2><label for="embed-code"><?php _e('Embed Code') ?></label></h2>
120
<textarea name="embed-code" id="embed-code" rows="8" cols="40"><?php echo format_to_edit($selection, true); ?></textarea>
121
<p id="options"><a href="#" class="select button"><?php _e('Insert Video'); ?></a> <a href="#" class="close button"><?php _e('Cancel'); ?></a></p>
126
case 'photo_thickbox': ?>
127
<script type="text/javascript" charset="utf-8">
128
jQuery('.cancel').click(function() {
131
jQuery('.select').click(function() {
135
<h3 class="tb"><label for="this_photo_description"><?php _e('Description') ?></label></h3>
136
<div class="titlediv">
137
<div class="titlewrap">
138
<input id="this_photo_description" name="photo_description" class="tbtitle text" onkeypress="if(event.keyCode==13) image_selector();" value="<?php echo esc_attr($title);?>"/>
142
<p class="centered"><input type="hidden" name="this_photo" value="<?php echo esc_attr($image); ?>" id="this_photo" />
143
<a href="#" class="select"><img src="<?php echo esc_url($image); ?>" alt="<?php echo esc_attr(__('Click to insert.')); ?>" title="<?php echo esc_attr(__('Click to insert.')); ?>" /></a></p>
145
<p id="options"><a href="#" class="select button"><?php _e('Insert Image'); ?></a> <a href="#" class="cancel button"><?php _e('Cancel'); ?></a></p>
150
case 'photo_thickbox_url': ?>
151
<script type="text/javascript" charset="utf-8">
152
jQuery('.cancel').click(function() {
156
jQuery('.select').click(function() {
160
<h3 class="tb"><label for="this_photo"><?php _e('URL') ?></label></h3>
161
<div class="titlediv">
162
<div class="titlewrap">
163
<input id="this_photo" name="this_photo" class="tbtitle text" onkeypress="if(event.keyCode==13) image_selector();" />
168
<h3 class="tb"><label for="photo_description"><?php _e('Description') ?></label></h3>
170
<div class="titlewrap">
171
<input id="this_photo_description" name="photo_description" class="tbtitle text" onkeypress="if(event.keyCode==13) image_selector();" value="<?php echo esc_attr($title);?>"/>
175
<p id="options"><a href="#" class="select"><?php _e('Insert Image'); ?></a> | <a href="#" class="cancel"><?php _e('Cancel'); ?></a></p>
106
switch ($_REQUEST['ajax']) {
108
<script type="text/javascript" charset="utf-8">
110
jQuery('.select').click(function() {
111
append_editor(jQuery('#embed-code').val());
112
jQuery('#extra-fields').hide();
113
jQuery('#extra-fields').html('');
115
jQuery('.close').click(function() {
116
jQuery('#extra-fields').hide();
117
jQuery('#extra-fields').html('');
121
<div class="postbox">
122
<h2><label for="embed-code"><?php _e('Embed Code') ?></label></h2>
124
<textarea name="embed-code" id="embed-code" rows="8" cols="40"><?php echo wp_htmledit_pre( $selection ); ?></textarea>
125
<p id="options"><a href="#" class="select button"><?php _e('Insert Video'); ?></a> <a href="#" class="close button"><?php _e('Cancel'); ?></a></p>
130
case 'photo_thickbox': ?>
131
<script type="text/javascript" charset="utf-8">
133
jQuery('.cancel').click(function() {
136
jQuery('.select').click(function() {
141
<h3 class="tb"><label for="this_photo_description"><?php _e('Description') ?></label></h3>
142
<div class="titlediv">
143
<div class="titlewrap">
144
<input id="this_photo_description" name="photo_description" class="tbtitle text" onkeypress="if(event.keyCode==13) image_selector();" value="<?php echo esc_attr($title);?>"/>
149
<input type="hidden" name="this_photo" value="<?php echo esc_attr($image); ?>" id="this_photo" />
150
<a href="#" class="select">
151
<img src="<?php echo esc_url($image); ?>" alt="<?php echo esc_attr(__('Click to insert.')); ?>" title="<?php echo esc_attr(__('Click to insert.')); ?>" />
155
<p id="options"><a href="#" class="select button"><?php _e('Insert Image'); ?></a> <a href="#" class="cancel button"><?php _e('Cancel'); ?></a></p>
158
case 'photo_thickbox_url': ?>
159
<script type="text/javascript" charset="utf-8">
161
jQuery('.cancel').click(function() {
165
jQuery('.select').click(function() {
170
<h3 class="tb"><label for="this_photo"><?php _e('URL') ?></label></h3>
171
<div class="titlediv">
172
<div class="titlewrap">
173
<input id="this_photo" name="this_photo" class="tbtitle text" onkeypress="if(event.keyCode==13) image_selector();" />
176
<h3 class="tb"><label for="photo_description"><?php _e('Description') ?></label></h3>
178
<div class="titlewrap">
179
<input id="this_photo_description" name="photo_description" class="tbtitle text" onkeypress="if(event.keyCode==13) image_selector();" value="<?php echo esc_attr($title);?>"/>
183
<p id="options"><a href="#" class="select"><?php _e('Insert Image'); ?></a> | <a href="#" class="cancel"><?php _e('Cancel'); ?></a></p>
177
185
case 'photo_images':
179
187
* Retrieve all image URLs from given URI.
188
196
function get_images_from_uri($uri) {
197
$uri = preg_replace('/\/#.+?$/','', $uri);
189
198
if( preg_match('/\.(jpg|jpe|jpeg|png|gif)$/', $uri) && !strpos($uri,'blogger.com') )
199
return "'" . esc_attr( html_entity_decode($uri) ) . "'";
191
200
$content = wp_remote_fopen($uri);
192
201
if ( false === $content )
194
203
$host = parse_url($uri);
195
$pattern = '/<img ([^>]*)src=(\"|\')([^<>]+?\.(png|jpeg|jpg|jpe|gif))[^<>\'\"]*(\2)([^>\/]*)\/*>/is';
204
$pattern = '/<img ([^>]*)src=(\"|\')([^<>\'\"]+)(\2)([^>]*)\/*>/i';
205
$content = str_replace(array("\n","\t","\r"), '', $content);
196
206
preg_match_all($pattern, $content, $matches);
197
207
if ( empty($matches[0]) )
205
215
$src = 'http://'.str_replace('//','/', $host['host'].'/'.$src);
207
217
$src = 'http://'.str_replace('//','/', $host['host'].'/'.dirname($host['path']).'/'.$src);
208
$sources[] = esc_url($src);
218
$sources[] = esc_attr($src);
210
220
return "'" . implode("','", $sources) . "'";
212
$url = urldecode($url);
213
$url = str_replace(' ', '%20', $url);
222
$url = wp_kses(urldecode($url), null);
214
223
echo 'new Array('.get_images_from_uri($url).')';
218
226
case 'photo_js': ?>
219
227
// gather images and load some default JS
221
229
var img, img_tag, aspect, w, h, skip, i, strtoappend = "";
230
if(photostorage == false) {
234
url: "<?php echo esc_url($_SERVER['PHP_SELF']); ?>",
237
data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
241
if(my_src.length == 0) {
222
242
var my_src = eval(
225
url: "<?php echo esc_url($_SERVER['PHP_SELF']); ?>",
245
url: "<?php echo esc_url($_SERVER['PHP_SELF']); ?>",
228
data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
248
data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
229
249
dataType : "script"
232
252
if(my_src.length == 0) {
236
url: "<?php echo esc_url($_SERVER['PHP_SELF']); ?>",
239
data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
243
if(my_src.length == 0) {
244
strtoappend = '<?php _e('Unable to retrieve images or no images on page.'); ?>';
253
strtoappend = '<?php _e('Unable to retrieve images or no images on page.'); ?>';
248
257
for (i = 0; i < my_src.length; i++) {
249
258
img = new Image();
250
259
img.src = my_src[i];
289
298
desc = jQuery('#this_photo_description').val();
290
299
src = jQuery('#this_photo').val();
292
jQuery('#extra_fields').hide();
293
jQuery('#extra_fields').html('');
301
jQuery('#extra-fields').hide();
302
jQuery('#extra-fields').html('');
297
jQuery(document).ready(function() {
298
jQuery('#extra_fields').html('<div class="postbox"><h2>Photo <small id="photo_directions">(<?php _e("click images to select") ?>)</small></h2><ul id="actions"><li><a href="#" id="photo_add_url" class="thickbox button"><?php _e("Add from URL") ?> +</a></li></ul><div class="inside"><div class="titlewrap"><div id="img_container"></div></div><p id="options"><a href="#" class="close button"><?php _e('Cancel'); ?></a><a href="#" class="refresh button"><?php _e('Refresh'); ?></a></p></div>');
299
jQuery('.close').click(function() {
300
jQuery('#extra_fields').hide();
301
jQuery('#extra_fields').html('');
303
jQuery('.refresh').click(function() {
305
jQuery('#extra-fields').html('<div class="postbox"><h2>Add Photos <small id="photo_directions">(<?php _e("click images to select") ?>)</small></h2><ul class="actions"><li><a href="#" id="photo-add-url" class="thickbox button"><?php _e("Add from URL") ?> +</a></li></ul><div class="inside"><div class="titlewrap"><div id="img_container"></div></div><p id="options"><a href="#" class="close button"><?php _e('Cancel'); ?></a><a href="#" class="refresh button"><?php _e('Refresh'); ?></a></p></div>');
306
306
jQuery('#img_container').html(strtoappend);
307
jQuery('#photo_add_url').attr('href', '?ajax=photo_thickbox_url&height=200&width=500');
308
tb_init('#extra_fields .thickbox');
326
wp_enqueue_style('press-this');
327
wp_enqueue_style('press-this-ie');
321
wp_enqueue_style( 'press-this' );
322
wp_enqueue_style( 'press-this-ie');
328
323
wp_enqueue_style( 'colors' );
329
324
wp_enqueue_script( 'post' );
330
wp_enqueue_script('editor');
325
wp_enqueue_script( 'editor' );
332
327
<script type="text/javascript">
334
329
addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
335
330
var userSettings = {'url':'<?php echo SITECOOKIEPATH; ?>','uid':'<?php if ( ! isset($current_user) ) $current_user = wp_get_current_user(); echo $current_user->ID; ?>','time':'<?php echo time() ?>'};
336
var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
331
var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>', pagenow = 'press-this';
332
var photostorage = false;
400
393
jQuery('#embed-code').prepend('<?php echo htmlentities($content); ?>');
395
jQuery('#extra-fields').show();
405
jQuery('#extra_fields').before('<p id="waiting"><img src="images/wpspin_light.gif" alt="" /> <?php echo esc_js( __( 'Loading...' ) ); ?></p>');
409
url: "<?php echo esc_url($_SERVER['PHP_SELF']); ?>",
410
data: "ajax=photo_js&u=<?php echo urlencode($url)?>",
412
success : function() {
413
jQuery('#waiting').remove();
399
function setup_photo_actions() {
400
jQuery('.close').click(function() {
401
jQuery('#extra-fields').hide();
402
jQuery('#extra-fields').html('');
404
jQuery('.refresh').click(function() {
405
photostorage = false;
408
jQuery('#photo-add-url').attr('href', '?ajax=photo_thickbox_url&height=200&width=500');
409
tb_init('#extra-fields .thickbox');
410
jQuery('#waiting').hide();
411
jQuery('#extra-fields').show();
413
jQuery('#extra-fields').before('<div id="waiting"><img src="images/wpspin_light.gif" alt="" /> <?php echo esc_js( __( 'Loading...' ) ); ?></div>');
415
if(photostorage == false) {
419
url: "<?php echo esc_url($_SERVER['PHP_SELF']); ?>",
420
data: "ajax=photo_js&u=<?php echo urlencode($url)?>",
422
success : function(data) {
424
photostorage = jQuery('#extra-fields').html();
425
setup_photo_actions();
429
jQuery('#extra-fields').html(photostorage);
430
setup_photo_actions();
420
jQuery(document).ready(function() {
436
jQuery(document).ready(function($) {
422
window.resizeTo(720,570);
438
window.resizeTo(720,540);
423
439
// set button actions
424
440
jQuery('#photo_button').click(function() { show('photo'); return false; });
425
441
jQuery('#video_button').click(function() { show('video'); return false; });
434
450
jQuery('#title').unbind();
435
451
jQuery('#publish, #save').click(function() { jQuery('#saving').css('display', 'inline'); });
453
$('#tagsdiv-post_tag, #categorydiv').children('h3, .handlediv').click(function(){
454
$(this).siblings('.inside').toggle();
439
<body class="press-this">
459
<body class="press-this wp-admin">
440
460
<div id="wphead"></div>
441
461
<form action="press-this.php?action=post" method="post">
442
462
<div id="poststuff" class="metabox-holder">
443
463
<div id="side-info-column">
444
464
<div class="sleeve">
445
<h1 id="viewsite"><a class="button" href="<?php echo get_option('home'); ?>/" target="_blank"><?php bloginfo('name'); ?> › <?php _e('Press This') ?></a></span></h1>
465
<h1 id="viewsite"><a href="<?php echo get_option('home'); ?>/" target="_blank"><?php bloginfo('name'); ?> › <?php _e('Press This') ?></a></span></h1>
447
467
<?php wp_nonce_field('press-this') ?>
448
468
<input type="hidden" name="post_type" id="post_type" value="text"/>