web/wp-admin/press-this.php
branchwordpress
changeset 132 4d4862461b8d
parent 109 03b0d1493584
equal deleted inserted replaced
131:a4642baaf829 132:4d4862461b8d
    40  * @return int Post ID
    40  * @return int Post ID
    41  */
    41  */
    42 function press_it() {
    42 function press_it() {
    43 	// define some basic variables
    43 	// define some basic variables
    44 	$quick['post_status'] = 'draft'; // set as draft first
    44 	$quick['post_status'] = 'draft'; // set as draft first
    45 	$quick['post_category'] = isset($_REQUEST['post_category']) ? $_REQUEST['post_category'] : null;
    45 	$quick['post_category'] = isset($_POST['post_category']) ? $_POST['post_category'] : null;
    46 	$quick['tax_input'] = isset($_REQUEST['tax_input']) ? $_REQUEST['tax_input'] : '';
    46 	$quick['tax_input'] = isset($_POST['tax_input']) ? $_POST['tax_input'] : null;
    47 	$quick['post_title'] = isset($_REQUEST['title']) ? $_REQUEST['title'] : '';
    47 	$quick['post_title'] = ( trim($_POST['title']) != '' ) ? $_POST['title'] : '  ';
    48 	$quick['post_content'] = '';
    48 	$quick['post_content'] = isset($_POST['post_content']) ? $_POST['post_content'] : ''; 
    49 
    49 
    50 	// insert the post with nothing in it, to get an ID
    50 	// insert the post with nothing in it, to get an ID
    51 	$post_ID = wp_insert_post($quick, true);
    51 	$post_ID = wp_insert_post($quick, true);
    52 	$content = isset($_REQUEST['content']) ? $_REQUEST['content'] : '';
    52 	if ( is_wp_error($post_ID) )
       
    53 		wp_die($post_ID);
       
    54 
       
    55 	$content = isset($_POST['content']) ? $_POST['content'] : '';
    53 
    56 
    54 	$upload = false;
    57 	$upload = false;
    55 	if( !empty($_REQUEST['photo_src']) && current_user_can('upload_files') )
    58 	if( !empty($_POST['photo_src']) && current_user_can('upload_files') ) {
    56 		foreach( (array) $_REQUEST['photo_src'] as $key => $image)
    59 		foreach( (array) $_POST['photo_src'] as $key => $image) {
    57 			// see if files exist in content - we don't want to upload non-used selected files.
    60 			// see if files exist in content - we don't want to upload non-used selected files.
    58 			if( strpos($_REQUEST['content'], $image) !== false ) {
    61 			if ( strpos($_POST['content'], htmlspecialchars($image)) !== false ) {
    59 				$desc = isset($_REQUEST['photo_description'][$key]) ? $_REQUEST['photo_description'][$key] : '';
    62 				$desc = isset($_POST['photo_description'][$key]) ? $_POST['photo_description'][$key] : '';
    60 				$upload = media_sideload_image($image, $post_ID, $desc);
    63 				$upload = media_sideload_image($image, $post_ID, $desc);
    61 
    64 
    62 				// Replace the POSTED content <img> with correct uploaded ones. Regex contains fix for Magic Quotes
    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);
    64 			}
    68 			}
    65 
    69 		}
       
    70 	}
    66 	// set the post_content and status
    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 	$quick['post_content'] = $content;
    73 	$quick['post_content'] = $content;
    69 	// error handling for $post
    74 	// error handling for media_sideload
    70 	if ( is_wp_error($post_ID)) {
    75 	if ( is_wp_error($upload) ) {
    71 		wp_die($id);
       
    72 		wp_delete_post($post_ID);
    76 		wp_delete_post($post_ID);
    73 	// error handling for media_sideload
       
    74 	} elseif ( is_wp_error($upload)) {
       
    75 		wp_die($upload);
    77 		wp_die($upload);
    76 		wp_delete_post($post_ID);
       
    77 	} else {
    78 	} else {
    78 		$quick['ID'] = $post_ID;
    79 		$quick['ID'] = $post_ID;
    79 		wp_update_post($quick);
    80 		wp_update_post($quick);
    80 	}
    81 	}
    81 	return $post_ID;
    82 	return $post_ID;
    95 $selection = isset( $_GET['s'] ) ? trim( htmlspecialchars( html_entity_decode( aposfix( stripslashes( $_GET['s'] ) ) ) ) ) : '';
    96 $selection = isset( $_GET['s'] ) ? trim( htmlspecialchars( html_entity_decode( aposfix( stripslashes( $_GET['s'] ) ) ) ) ) : '';
    96 if ( ! empty($selection) ) {
    97 if ( ! empty($selection) ) {
    97 	$selection = preg_replace('/(\r?\n|\r)/', '</p><p>', $selection);
    98 	$selection = preg_replace('/(\r?\n|\r)/', '</p><p>', $selection);
    98 	$selection = '<p>'.str_replace('<p></p>', '', $selection).'</p>';
    99 	$selection = '<p>'.str_replace('<p></p>', '', $selection).'</p>';
    99 }
   100 }
       
   101 
   100 $url = isset($_GET['u']) ? esc_url($_GET['u']) : '';
   102 $url = isset($_GET['u']) ? esc_url($_GET['u']) : '';
   101 $image = isset($_GET['i']) ? $_GET['i'] : '';
   103 $image = isset($_GET['i']) ? $_GET['i'] : '';
   102 
   104 
   103 if ( !empty($_REQUEST['ajax']) ) {
   105 if ( !empty($_REQUEST['ajax']) ) {
   104 switch ($_REQUEST['ajax']) {
   106 	switch ($_REQUEST['ajax']) {
   105 	case 'video': ?>
   107 		case 'video': ?>
   106 		<script type="text/javascript" charset="utf-8">
   108 			<script type="text/javascript" charset="utf-8">
   107 			jQuery('.select').click(function() {
   109 			/* <![CDATA[ */
   108 				append_editor(jQuery('#embed-code').val());
   110 				jQuery('.select').click(function() {
   109 				jQuery('#extra_fields').hide();
   111 					append_editor(jQuery('#embed-code').val());
   110 				jQuery('#extra_fields').html('');
   112 					jQuery('#extra-fields').hide();
   111 			});
   113 					jQuery('#extra-fields').html('');
   112 			jQuery('.close').click(function() {
   114 				});
   113 				jQuery('#extra_fields').hide();
   115 				jQuery('.close').click(function() {
   114 				jQuery('#extra_fields').html('');
   116 					jQuery('#extra-fields').hide();
   115 			});
   117 					jQuery('#extra-fields').html('');
   116 		</script>
   118 				});
   117 		<div class="postbox">
   119 			/* ]]> */
   118 		<h2><label for="embed-code"><?php _e('Embed Code') ?></label></h2>
   120 			</script>
   119 		<div class="inside">
   121 			<div class="postbox">
   120 			<textarea name="embed-code" id="embed-code" rows="8" cols="40"><?php echo wp_htmledit_pre( $selection ); ?></textarea>
   122 				<h2><label for="embed-code"><?php _e('Embed Code') ?></label></h2>
   121 			<p id="options"><a href="#" class="select button"><?php _e('Insert Video'); ?></a> <a href="#" class="close button"><?php _e('Cancel'); ?></a></p>
   123 				<div class="inside">
   122 		</div>
   124 					<textarea name="embed-code" id="embed-code" rows="8" cols="40"><?php echo wp_htmledit_pre( $selection ); ?></textarea>
   123 		</div>
   125 					<p id="options"><a href="#" class="select button"><?php _e('Insert Video'); ?></a> <a href="#" class="close button"><?php _e('Cancel'); ?></a></p>
   124 		<?php break;
   126 				</div>
   125 
   127 			</div>
   126 	case 'photo_thickbox': ?>
   128 			<?php break;
   127 		<script type="text/javascript" charset="utf-8">
   129 
   128 			jQuery('.cancel').click(function() {
   130 		case 'photo_thickbox': ?>
   129 				tb_remove();
   131 			<script type="text/javascript" charset="utf-8">
   130 			});
   132 				/* <![CDATA[ */
   131 			jQuery('.select').click(function() {
   133 				jQuery('.cancel').click(function() {
   132 				image_selector();
   134 					tb_remove();
   133 			});
   135 				});
   134 		</script>
   136 				jQuery('.select').click(function() {
   135 		<h3 class="tb"><label for="this_photo_description"><?php _e('Description') ?></label></h3>
   137 					image_selector();
   136 		<div class="titlediv">
   138 				});
   137 		<div class="titlewrap">
   139 				/* ]]> */
   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);?>"/>
   140 			</script>
   139 		</div>
   141 			<h3 class="tb"><label for="this_photo_description"><?php _e('Description') ?></label></h3>
   140 		</div>
   142 			<div class="titlediv">
   141 
   143 				<div class="titlewrap">
   142 		<p class="centered"><input type="hidden" name="this_photo" value="<?php echo esc_attr($image); ?>" id="this_photo" />
   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);?>"/>
   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 				</div>
   144 
   146 			</div>
   145 		<p id="options"><a href="#" class="select button"><?php _e('Insert Image'); ?></a> <a href="#" class="cancel button"><?php _e('Cancel'); ?></a></p>
   147 
   146 
   148 			<p class="centered">
   147 
   149 				<input type="hidden" name="this_photo" value="<?php echo esc_attr($image); ?>" id="this_photo" />
   148 		<?php break;
   150 				<a href="#" class="select">
   149 
   151 					<img src="<?php echo esc_url($image); ?>" alt="<?php echo esc_attr(__('Click to insert.')); ?>" title="<?php echo esc_attr(__('Click to insert.')); ?>" />
   150 	case 'photo_thickbox_url': ?>
   152 				</a>
   151 		<script type="text/javascript" charset="utf-8">
   153 			</p>
   152 			jQuery('.cancel').click(function() {
   154 
   153 				tb_remove();
   155 			<p id="options"><a href="#" class="select button"><?php _e('Insert Image'); ?></a> <a href="#" class="cancel button"><?php _e('Cancel'); ?></a></p>
   154 			});
   156 			<?php break;
   155 
   157 
   156 			jQuery('.select').click(function() {
   158 		case 'photo_thickbox_url': ?>
   157 				image_selector();
   159 			<script type="text/javascript" charset="utf-8">
   158 			});
   160 				/* <![CDATA[ */
   159 		</script>
   161 				jQuery('.cancel').click(function() {
   160 		<h3 class="tb"><label for="this_photo"><?php _e('URL') ?></label></h3>
   162 					tb_remove();
   161 		<div class="titlediv">
   163 				});
   162 			<div class="titlewrap">
   164 
   163 			<input id="this_photo" name="this_photo" class="tbtitle text" onkeypress="if(event.keyCode==13) image_selector();" />
   165 				jQuery('.select').click(function() {
   164 			</div>
   166 					image_selector();
   165 		</div>
   167 				});
   166 
   168 				/* ]]> */
   167 
   169 			</script>
   168 		<h3 class="tb"><label for="photo_description"><?php _e('Description') ?></label></h3>
   170 			<h3 class="tb"><label for="this_photo"><?php _e('URL') ?></label></h3>
   169 		<div id="titlediv">
   171 			<div class="titlediv">
   170 			<div class="titlewrap">
   172 				<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);?>"/>
   173 					<input id="this_photo" name="this_photo" class="tbtitle text" onkeypress="if(event.keyCode==13) image_selector();" />
   172 			</div>
   174 				</div>
   173 		</div>
   175 			</div>
   174 
   176 			<h3 class="tb"><label for="photo_description"><?php _e('Description') ?></label></h3>
   175 		<p id="options"><a href="#" class="select"><?php _e('Insert Image'); ?></a> | <a href="#" class="cancel"><?php _e('Cancel'); ?></a></p>
   177 			<div id="titlediv">
   176 		<?php break;
   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);?>"/>
       
   180 				</div>
       
   181 			</div>
       
   182 
       
   183 			<p id="options"><a href="#" class="select"><?php _e('Insert Image'); ?></a> | <a href="#" class="cancel"><?php _e('Cancel'); ?></a></p>
       
   184 			<?php break;
   177 	case 'photo_images':
   185 	case 'photo_images':
   178 		/**
   186 		/**
   179 		 * Retrieve all image URLs from given URI.
   187 		 * Retrieve all image URLs from given URI.
   180 		 *
   188 		 *
   181 		 * @package WordPress
   189 		 * @package WordPress
   184 		 *
   192 		 *
   185 		 * @param string $uri
   193 		 * @param string $uri
   186 		 * @return string
   194 		 * @return string
   187 		 */
   195 		 */
   188 		function get_images_from_uri($uri) {
   196 		function get_images_from_uri($uri) {
       
   197 			$uri = preg_replace('/\/#.+?$/','', $uri);
   189 			if( preg_match('/\.(jpg|jpe|jpeg|png|gif)$/', $uri) && !strpos($uri,'blogger.com') )
   198 			if( preg_match('/\.(jpg|jpe|jpeg|png|gif)$/', $uri) && !strpos($uri,'blogger.com') )
   190 				return "'".$uri."'";
   199 				return "'" . esc_attr( html_entity_decode($uri) ) . "'";
   191 			$content = wp_remote_fopen($uri);
   200 			$content = wp_remote_fopen($uri);
   192 			if ( false === $content )
   201 			if ( false === $content )
   193 				return '';
   202 				return '';
   194 			$host = parse_url($uri);
   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 			preg_match_all($pattern, $content, $matches);
   206 			preg_match_all($pattern, $content, $matches);
   197 			if ( empty($matches[0]) )
   207 			if ( empty($matches[0]) )
   198 				return '';
   208 				return '';
   199 			$sources = array();
   209 			$sources = array();
   200 			foreach ($matches[3] as $src) {
   210 			foreach ($matches[3] as $src) {
   203 					// if it doesn't have a relative uri
   213 					// if it doesn't have a relative uri
   204 					if( strpos($src, '../') === false && strpos($src, './') === false && strpos($src, '/') === 0)
   214 					if( strpos($src, '../') === false && strpos($src, './') === false && strpos($src, '/') === 0)
   205 						$src = 'http://'.str_replace('//','/', $host['host'].'/'.$src);
   215 						$src = 'http://'.str_replace('//','/', $host['host'].'/'.$src);
   206 					else
   216 					else
   207 						$src = 'http://'.str_replace('//','/', $host['host'].'/'.dirname($host['path']).'/'.$src);
   217 						$src = 'http://'.str_replace('//','/', $host['host'].'/'.dirname($host['path']).'/'.$src);
   208 				$sources[] = esc_url($src);
   218 				$sources[] = esc_attr($src);
   209 			}
   219 			}
   210 			return "'" . implode("','", $sources) . "'";
   220 			return "'" . implode("','", $sources) . "'";
   211 		}
   221 		}
   212 		$url = urldecode($url);
   222 		$url = wp_kses(urldecode($url), null);
   213 		$url = str_replace(' ', '%20', $url);
       
   214 		echo 'new Array('.get_images_from_uri($url).')';
   223 		echo 'new Array('.get_images_from_uri($url).')';
   215 
       
   216 		break;
   224 		break;
   217 
   225 
   218 	case 'photo_js': ?>
   226 	case 'photo_js': ?>
   219 		// gather images and load some default JS
   227 		// gather images and load some default JS
   220 		var last = null
   228 		var last = null
   221 		var img, img_tag, aspect, w, h, skip, i, strtoappend = "";
   229 		var img, img_tag, aspect, w, h, skip, i, strtoappend = "";
       
   230 		if(photostorage == false) {
       
   231 		var my_src = eval(
       
   232 			jQuery.ajax({
       
   233 		   		type: "GET",
       
   234 		   		url: "<?php echo esc_url($_SERVER['PHP_SELF']); ?>",
       
   235 				cache : false,
       
   236 				async : false,
       
   237 		   		data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
       
   238 				dataType : "script"
       
   239 			}).responseText
       
   240 		);
       
   241 		if(my_src.length == 0) {
   222 			var my_src = eval(
   242 			var my_src = eval(
   223 				jQuery.ajax({
   243 				jQuery.ajax({
   224 			   		type: "GET",
   244 		   			type: "GET",
   225 			   		url: "<?php echo esc_url($_SERVER['PHP_SELF']); ?>",
   245 		   			url: "<?php echo esc_url($_SERVER['PHP_SELF']); ?>",
   226 					cache : false,
   246 					cache : false,
   227 					async : false,
   247 					async : false,
   228 			   		data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
   248 		   			data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
   229 					dataType : "script"
   249 					dataType : "script"
   230 				}).responseText
   250 				}).responseText
   231 			);
   251 			);
   232 			if(my_src.length == 0) {
   252 			if(my_src.length == 0) {
   233 				var my_src = eval(
   253 				strtoappend = '<?php _e('Unable to retrieve images or no images on page.'); ?>';
   234 				jQuery.ajax({
       
   235 			   		type: "GET",
       
   236 			   		url: "<?php echo esc_url($_SERVER['PHP_SELF']); ?>",
       
   237 					cache : false,
       
   238 					async : false,
       
   239 			   		data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
       
   240 					dataType : "script"
       
   241 				}).responseText
       
   242 				);
       
   243 				if(my_src.length == 0) {
       
   244 					strtoappend = '<?php _e('Unable to retrieve images or no images on page.'); ?>';
       
   245 				}
       
   246 			}
   254 			}
   247 
   255 		}
       
   256 		}
   248 		for (i = 0; i < my_src.length; i++) {
   257 		for (i = 0; i < my_src.length; i++) {
   249 			img = new Image();
   258 			img = new Image();
   250 			img.src = my_src[i];
   259 			img.src = my_src[i];
   251 			img_attr = 'id="img' + i + '"';
   260 			img_attr = 'id="img' + i + '"';
   252 			skip = false;
   261 			skip = false;
   287 		function image_selector() {
   296 		function image_selector() {
   288 			tb_remove();
   297 			tb_remove();
   289 			desc = jQuery('#this_photo_description').val();
   298 			desc = jQuery('#this_photo_description').val();
   290 			src = jQuery('#this_photo').val();
   299 			src = jQuery('#this_photo').val();
   291 			pick(src, desc);
   300 			pick(src, desc);
   292 			jQuery('#extra_fields').hide();
   301 			jQuery('#extra-fields').hide();
   293 			jQuery('#extra_fields').html('');
   302 			jQuery('#extra-fields').html('');
   294 			return false;
   303 			return false;
   295 		}
   304 		}
   296 
   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>');
   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('');
       
   302 			});
       
   303 			jQuery('.refresh').click(function() {
       
   304 						show('photo');
       
   305 					});
       
   306 			jQuery('#img_container').html(strtoappend);
   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');
       
   309 
       
   310 
       
   311 		});
       
   312 		<?php break;
   307 		<?php break;
   313 }
   308 }
   314 die;
   309 die;
   315 }
   310 }
   316 
   311 
   321 	<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
   316 	<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
   322 	<title><?php _e('Press This') ?></title>
   317 	<title><?php _e('Press This') ?></title>
   323 
   318 
   324 <?php
   319 <?php
   325 	add_thickbox();
   320 	add_thickbox();
   326 	wp_enqueue_style('press-this');
   321 	wp_enqueue_style( 'press-this' );
   327 	wp_enqueue_style('press-this-ie');
   322 	wp_enqueue_style( 'press-this-ie');
   328 	wp_enqueue_style( 'colors' );
   323 	wp_enqueue_style( 'colors' );
   329 	wp_enqueue_script( 'post' );
   324 	wp_enqueue_script( 'post' );
   330 	wp_enqueue_script('editor');
   325 	wp_enqueue_script( 'editor' );
   331 ?>
   326 ?>
   332 <script type="text/javascript">
   327 <script type="text/javascript">
   333 //<![CDATA[
   328 //<![CDATA[
   334 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();}}};
   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 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() ?>'};
   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;
   337 //]]>
   333 //]]>
   338 </script>
   334 </script>
   339 
   335 
   340 <?php
   336 <?php
   341 	do_action('admin_print_styles');
   337 	do_action('admin_print_styles');
   342 	do_action('admin_print_scripts');
   338 	do_action('admin_print_scripts');
   343 	do_action('admin_head');
   339 	do_action('admin_head');
   344 
   340 
   345 	if ( user_can_richedit() ) {
   341 	if ( user_can_richedit() )
   346 		add_filter( 'teeny_mce_before_init', create_function( '$a', '$a["height"] = "400"; $a["onpageload"] = ""; $a["mode"] = "textareas"; $a["editor_selector"] = "mceEditor"; return $a;' ) );
   342 		wp_tiny_mce( true, array( 'height' => '370' ) );
   347 		wp_tiny_mce( true );
       
   348 	}
       
   349 ?>
   343 ?>
   350 	<script type="text/javascript">
   344 	<script type="text/javascript">
   351 	function insert_plain_editor(text) {
   345 	function insert_plain_editor(text) {
   352 		edCanvas = document.getElementById('content');
   346 		edCanvas = document.getElementById('content');
   353 		edInsertContent(edCanvas, text);
   347 		edInsertContent(edCanvas, text);
   371 			insert_plain_editor(text);
   365 			insert_plain_editor(text);
   372 		}
   366 		}
   373 	}
   367 	}
   374 
   368 
   375 	function show(tab_name) {
   369 	function show(tab_name) {
   376 		jQuery('#extra_fields').html('');
   370 		jQuery('#extra-fields').html('');
   377 		jQuery('#extra_fields').show();
       
   378 		switch(tab_name) {
   371 		switch(tab_name) {
   379 			case 'video' :
   372 			case 'video' :
   380 				jQuery('#extra_fields').load('<?php echo esc_url($_SERVER['PHP_SELF']); ?>', { ajax: 'video', s: '<?php echo esc_attr($selection); ?>'}, function() {
   373 				jQuery('#extra-fields').load('<?php echo esc_url($_SERVER['PHP_SELF']); ?>', { ajax: 'video', s: '<?php echo esc_attr($selection); ?>'}, function() {
   381 					<?php
   374 					<?php
   382 					$content = '';
   375 					$content = '';
   383 					if ( preg_match("/youtube\.com\/watch/i", $url) ) {
   376 					if ( preg_match("/youtube\.com\/watch/i", $url) ) {
   384 						list($domain, $video_id) = split("v=", $url);
   377 						list($domain, $video_id) = split("v=", $url);
   385 						$video_id = esc_attr($video_id);
   378 						$video_id = esc_attr($video_id);
   397 						$content = $selection;
   390 						$content = $selection;
   398 					}
   391 					}
   399 					?>
   392 					?>
   400 					jQuery('#embed-code').prepend('<?php echo htmlentities($content); ?>');
   393 					jQuery('#embed-code').prepend('<?php echo htmlentities($content); ?>');
   401 				});
   394 				});
       
   395 				jQuery('#extra-fields').show();
   402 				return false;
   396 				return false;
   403 				break;
   397 				break;
   404 			case 'photo' :
   398 			case 'photo' :
   405 				jQuery('#extra_fields').before('<p id="waiting"><img src="images/wpspin_light.gif" alt="" /> <?php echo esc_js( __( 'Loading...' ) ); ?></p>');
   399 				function setup_photo_actions() {
   406 				jQuery.ajax({
   400 					jQuery('.close').click(function() {
   407 					type: "GET",
   401 						jQuery('#extra-fields').hide();
   408 					cache : false,
   402 						jQuery('#extra-fields').html('');
   409 					url: "<?php echo esc_url($_SERVER['PHP_SELF']); ?>",
   403 					});
   410 					data: "ajax=photo_js&u=<?php echo urlencode($url)?>",
   404 					jQuery('.refresh').click(function() {
   411 					dataType : "script",
   405 						photostorage = false;
   412 					success : function() {
   406 						show('photo');
   413 						jQuery('#waiting').remove();
   407 					});
   414 					}
   408 					jQuery('#photo-add-url').attr('href', '?ajax=photo_thickbox_url&height=200&width=500');
   415 				});
   409 					tb_init('#extra-fields .thickbox');
       
   410 					jQuery('#waiting').hide();
       
   411 					jQuery('#extra-fields').show();
       
   412 				}
       
   413 				jQuery('#extra-fields').before('<div id="waiting"><img src="images/wpspin_light.gif" alt="" /> <?php echo esc_js( __( 'Loading...' ) ); ?></div>');
       
   414 				
       
   415 				if(photostorage == false) {
       
   416 					jQuery.ajax({
       
   417 						type: "GET",
       
   418 						cache : false,
       
   419 						url: "<?php echo esc_url($_SERVER['PHP_SELF']); ?>",
       
   420 						data: "ajax=photo_js&u=<?php echo urlencode($url)?>",
       
   421 						dataType : "script",
       
   422 						success : function(data) {
       
   423 							eval(data);
       
   424 							photostorage = jQuery('#extra-fields').html();
       
   425 							setup_photo_actions();
       
   426 						}
       
   427 					});
       
   428 				} else {
       
   429 					jQuery('#extra-fields').html(photostorage);
       
   430 					setup_photo_actions();
       
   431 				}
   416 				return false;
   432 				return false;
   417 				break;
   433 				break;
   418 		}
   434 		}
   419 	}
   435 	}
   420 	jQuery(document).ready(function() {
   436 	jQuery(document).ready(function($) {
   421 		//resize screen
   437 		//resize screen
   422 		window.resizeTo(720,570);
   438 		window.resizeTo(720,540);
   423 		// set button actions
   439 		// set button actions
   424     	jQuery('#photo_button').click(function() { show('photo'); return false; });
   440     	jQuery('#photo_button').click(function() { show('photo'); return false; });
   425 		jQuery('#video_button').click(function() { show('video'); return false; });
   441 		jQuery('#video_button').click(function() { show('video'); return false; });
   426 		// auto select
   442 		// auto select
   427 		<?php if ( preg_match("/youtube\.com\/watch/i", $url) ) { ?>
   443 		<?php if ( preg_match("/youtube\.com\/watch/i", $url) ) { ?>
   431 		<?php  } elseif ( preg_match("/flickr\.com/i", $url) ) { ?>
   447 		<?php  } elseif ( preg_match("/flickr\.com/i", $url) ) { ?>
   432 			show('photo');
   448 			show('photo');
   433 		<?php } ?>
   449 		<?php } ?>
   434 		jQuery('#title').unbind();
   450 		jQuery('#title').unbind();
   435 		jQuery('#publish, #save').click(function() { jQuery('#saving').css('display', 'inline'); });
   451 		jQuery('#publish, #save').click(function() { jQuery('#saving').css('display', 'inline'); });
       
   452 
       
   453 		$('#tagsdiv-post_tag, #categorydiv').children('h3, .handlediv').click(function(){
       
   454 			$(this).siblings('.inside').toggle();
       
   455 		});
   436 	});
   456 	});
   437 </script>
   457 </script>
   438 </head>
   458 </head>
   439 <body class="press-this">
   459 <body class="press-this wp-admin">
   440 <div id="wphead"></div>
   460 <div id="wphead"></div>
   441 <form action="press-this.php?action=post" method="post">
   461 <form action="press-this.php?action=post" method="post">
   442 <div id="poststuff" class="metabox-holder">
   462 <div id="poststuff" class="metabox-holder">
   443 	<div id="side-info-column">
   463 	<div id="side-info-column">
   444 		<div class="sleeve">
   464 		<div class="sleeve">
   445 			<h1 id="viewsite"><a class="button" href="<?php echo get_option('home'); ?>/" target="_blank"><?php bloginfo('name'); ?> &rsaquo; <?php _e('Press This') ?></a></span></h1>
   465 			<h1 id="viewsite"><a href="<?php echo get_option('home'); ?>/" target="_blank"><?php bloginfo('name'); ?> &rsaquo; <?php _e('Press This') ?></a></span></h1>
   446 
   466 
   447 			<?php wp_nonce_field('press-this') ?>
   467 			<?php wp_nonce_field('press-this') ?>
   448 			<input type="hidden" name="post_type" id="post_type" value="text"/>
   468 			<input type="hidden" name="post_type" id="post_type" value="text"/>
   449 			<input type="hidden" name="autosave" id="autosave" />
   469 			<input type="hidden" name="autosave" id="autosave" />
   450 			<input type="hidden" id="original_post_status" name="original_post_status" value="draft" />
   470 			<input type="hidden" id="original_post_status" name="original_post_status" value="draft" />
   452 
   472 
   453 			<!-- This div holds the photo metadata -->
   473 			<!-- This div holds the photo metadata -->
   454 			<div class="photolist"></div>
   474 			<div class="photolist"></div>
   455 
   475 
   456 			<div id="submitdiv" class="stuffbox">
   476 			<div id="submitdiv" class="stuffbox">
       
   477 				<div class="handlediv" title="<?php _e( 'Click to toggle' ); ?>">
       
   478 					<br/>
       
   479 				</div>
   457 				<h3><?php _e('Publish') ?></h3>
   480 				<h3><?php _e('Publish') ?></h3>
   458 				<div class="inside">
   481 				<div class="inside">
   459 					<p>
   482 					<p>
   460 						<input class="button" type="submit" name="draft" value="<?php esc_attr_e('Save Draft') ?>" id="save" />
   483 						<input class="button" type="submit" name="draft" value="<?php esc_attr_e('Save Draft') ?>" id="save" />
   461 						<?php if ( current_user_can('publish_posts') ) { ?>
   484 						<?php if ( current_user_can('publish_posts') ) { ?>
   467 					</p>
   490 					</p>
   468 				</div>
   491 				</div>
   469 			</div>
   492 			</div>
   470 
   493 
   471 			<div id="categorydiv" class="stuffbox">
   494 			<div id="categorydiv" class="stuffbox">
       
   495 				<div class="handlediv" title="<?php _e( 'Click to toggle' ); ?>">
       
   496 					<br/>
       
   497 				</div>
   472 				<h3><?php _e('Categories') ?></h3>
   498 				<h3><?php _e('Categories') ?></h3>
   473 				<div class="inside">
   499 				<div class="inside">
   474 
   500 
   475 					<div id="categories-all" class="tabs-panel">
   501 					<div id="categories-all" class="tabs-panel">
       
   502 
   476 						<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
   503 						<ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
   477 							<?php wp_category_checklist($post_ID, false) ?>
   504 							<?php wp_category_checklist($post_ID, false) ?>
   478 						</ul>
   505 						</ul>
   479 					</div>
   506 					</div>
   480 
   507 
   490 					</div>
   517 					</div>
   491 				</div>
   518 				</div>
   492 			</div>
   519 			</div>
   493 
   520 
   494 			<div id="tagsdiv-post_tag" class="stuffbox" >
   521 			<div id="tagsdiv-post_tag" class="stuffbox" >
       
   522 				<div class="handlediv" title="<?php _e( 'Click to toggle' ); ?>">
       
   523 					<br/>
       
   524 				</div>
   495 				<h3><span><?php _e('Post Tags'); ?></span></h3>
   525 				<h3><span><?php _e('Post Tags'); ?></span></h3>
   496 				<div class="inside">
   526 				<div class="inside">
   497 					<div class="tagsdiv" id="post_tag">
   527 					<div class="tagsdiv" id="post_tag">
   498 						<p class="jaxtag">
   528 						<p class="jaxtag">
   499 							<label class="screen-reader-text" for="newtag"><?php _e('Post Tags'); ?></label>
   529 							<label class="screen-reader-text" for="newtag"><?php _e('Post Tags'); ?></label>
   500 							<input type="hidden" name="tax_input[post_tag]" class="the-tags" id="tax-input[post_tag]" value="" />
   530 							<input type="hidden" name="tax_input[post_tag]" class="the-tags" id="tax-input[post_tag]" value="" />
   501 							<span class="ajaxtag" style="display:none;">
   531 							<div class="ajaxtag">
   502 								<input type="text" name="newtag[post_tag]" class="newtag form-input-tip" size="16" autocomplete="off" value="<?php esc_attr_e('Add new tag'); ?>" />
   532 								<input type="text" name="newtag[post_tag]" class="newtag form-input-tip" size="16" autocomplete="off" value="" />
   503 								<input type="button" class="button tagadd" value="<?php esc_attr_e('Add'); ?>" tabindex="3" />
   533 								<input type="button" class="button tagadd" value="<?php esc_attr_e('Add'); ?>" tabindex="3" />
   504 							</span>
   534 							</div>
   505 						</p>
   535 						</p>
   506 						<div class="tagchecklist"></div>
   536 						<div class="tagchecklist"></div>
   507 					</div>
   537 					</div>
   508 					<p class="tagcloud-link"><a href="#titlediv" class="tagcloud-link" id="link-post_tag"><?php _e('Choose from the most used tags in Post Tags'); ?></a></p>
   538 					<p class="tagcloud-link"><a href="#titlediv" class="tagcloud-link" id="link-post_tag"><?php _e('Choose from the most used tags in Post Tags'); ?></a></p>
   509 				</div>
   539 				</div>
   510 			</div>
   540 			</div>
   511 		</div>
   541 		</div>
   512 	</div>
   542 	</div>
   513 
       
   514 	<div class="posting">
   543 	<div class="posting">
   515 		<?php if ( isset($posted) && intval($posted) ) { $post_ID = intval($posted); ?>
   544 		<?php if ( isset($posted) && intval($posted) ) { $post_ID = intval($posted); ?>
   516 		<div id="message" class="updated fade"><p><strong><?php _e('Your post has been saved.'); ?></strong> <a onclick="window.opener.location.replace(this.href); window.close();" href="<?php echo get_permalink( $post_ID); ?>"><?php _e('View post'); ?></a> | <a href="<?php echo get_edit_post_link( $post_ID ); ?>" onclick="window.opener.location.replace(this.href); window.close();"><?php _e('Edit post'); ?></a> | <a href="#" onclick="window.close();"><?php _e('Close Window'); ?></a></p></div>
   545 		<div id="message" class="updated fade"><p><strong><?php _e('Your post has been saved.'); ?></strong> <a onclick="window.opener.location.replace(this.href); window.close();" href="<?php echo get_permalink( $post_ID); ?>"><?php _e('View post'); ?></a> | <a href="<?php echo get_edit_post_link( $post_ID ); ?>" onclick="window.opener.location.replace(this.href); window.close();"><?php _e('Edit post'); ?></a> | <a href="#" onclick="window.close();"><?php _e('Close Window'); ?></a></p></div>
   517 		<?php } ?>
   546 		<?php } ?>
   518 
   547 
   520 			<div class="titlewrap">
   549 			<div class="titlewrap">
   521 				<input name="title" id="title" class="text" value="<?php echo esc_attr($title);?>"/>
   550 				<input name="title" id="title" class="text" value="<?php echo esc_attr($title);?>"/>
   522 			</div>
   551 			</div>
   523 		</div>
   552 		</div>
   524 
   553 
   525 		<div id="extra_fields" style="display: none"></div>
   554 		<div id="extra-fields" style="display: none"></div>
   526 
   555 
   527 		<div class="postdivrich">
   556 		<div class="postdivrich">
   528 			<ul id="actions">
   557 			<ul id="actions" class="actions">
   529 
   558 
   530 				<li id="photo_button">
   559 				<li id="photo_button">
   531 					Add: <?php if ( current_user_can('upload_files') ) { ?><a title="<?php _e('Insert an Image'); ?>" href="#">
   560 					Add: <?php if ( current_user_can('upload_files') ) { ?><a title="<?php _e('Insert an Image'); ?>" href="#">
   532 <img alt="<?php _e('Insert an Image'); ?>" src="images/media-button-image.gif"/></a>
   561 <img alt="<?php _e('Insert an Image'); ?>" src="images/media-button-image.gif"/></a>
   533 					<?php } ?>
   562 					<?php } ?>
   545 				</li>
   574 				</li>
   546 				<?php } ?>
   575 				<?php } ?>
   547 			</ul>
   576 			</ul>
   548 			<div id="quicktags"></div>
   577 			<div id="quicktags"></div>
   549 			<div class="editor-container">
   578 			<div class="editor-container">
   550 				<textarea name="content" id="content" style="width:100%;" class="mceEditor" rows="15">
   579 				<textarea name="content" id="content" style="width:100%;" class="theEditor" rows="15"><?php
   551 					<?php if ($selection) echo wp_richedit_pre( $selection ); ?>
   580 					if ( $selection )
   552 					<?php if ($url) { echo '<p>'; if($selection) _e('via '); printf( "<a href='%s'>%s</a>.", esc_url( $url ), esc_html( $title ) ); echo '</p>'; } ?>
   581 						echo wp_richedit_pre($selection);
   553 				</textarea>
   582 					if ( $url ) {
       
   583 						echo '<p>';
       
   584 						if ( $selection )
       
   585 							_e('via ');
       
   586 						printf( "<a href='%s'>%s</a>.</p>", esc_url( $url ), esc_html( $title ) );
       
   587 					}
       
   588 				?></textarea>
   554 			</div>
   589 			</div>
   555 		</div>
   590 		</div>
   556 	</div>
   591 	</div>
   557 </div>
   592 </div>
   558 </form>
   593 </form>