web/wp-admin/includes/post.php
branchwordpress
changeset 132 4d4862461b8d
parent 109 03b0d1493584
equal deleted inserted replaced
131:a4642baaf829 132:4d4862461b8d
   234 	} else {
   234 	} else {
   235 		if ( ! current_user_can( 'edit_posts' ) )
   235 		if ( ! current_user_can( 'edit_posts' ) )
   236 			wp_die( __('You are not allowed to edit posts.') );
   236 			wp_die( __('You are not allowed to edit posts.') );
   237 	}
   237 	}
   238 
   238 
       
   239 	if ( -1 == $post_data['_status'] ) {
       
   240 		$post_data['post_status'] = null;
       
   241 		unset($post_data['post_status']);
       
   242 	} else {
       
   243 		$post_data['post_status'] = $post_data['_status'];
       
   244 	}
       
   245 	unset($post_data['_status']);
       
   246 
   239 	$post_IDs = array_map( 'intval', (array) $post_data['post'] );
   247 	$post_IDs = array_map( 'intval', (array) $post_data['post'] );
   240 
   248 
   241 	$reset = array( 'post_author', 'post_status', 'post_password', 'post_parent', 'page_template', 'comment_status', 'ping_status', 'keep_private', 'tags_input', 'post_category', 'sticky' );
   249 	$reset = array( 'post_author', 'post_status', 'post_password', 'post_parent', 'page_template', 'comment_status', 'ping_status', 'keep_private', 'tags_input', 'post_category', 'sticky' );
   242 	foreach ( $reset as $field ) {
   250 	foreach ( $reset as $field ) {
   243 		if ( isset($post_data[$field]) && ( '' == $post_data[$field] || -1 == $post_data[$field] ) )
   251 		if ( isset($post_data[$field]) && ( '' == $post_data[$field] || -1 == $post_data[$field] ) )
   296 		}
   304 		}
   297 
   305 
   298 		$post_data['ID'] = $post_ID;
   306 		$post_data['ID'] = $post_ID;
   299 		$updated[] = wp_update_post( $post_data );
   307 		$updated[] = wp_update_post( $post_data );
   300 
   308 
   301 		if ( current_user_can( 'edit_others_posts' ) && isset( $post_data['sticky'] ) ) {
   309 		if ( isset( $post_data['sticky'] ) && current_user_can( 'edit_others_posts' ) ) {
   302 			if ( 'sticky' == $post_data['sticky'] )
   310 			if ( 'sticky' == $post_data['sticky'] )
   303 				stick_post( $post_ID );
   311 				stick_post( $post_ID );
   304 			else
   312 			else
   305 				unstick_post( $post_ID );
   313 				unstick_post( $post_ID );
   306 		}
   314 		}
   316  * @since unknown
   324  * @since unknown
   317  *
   325  *
   318  * @return unknown
   326  * @return unknown
   319  */
   327  */
   320 function get_default_post_to_edit() {
   328 function get_default_post_to_edit() {
       
   329 
       
   330 	$post_title = '';
   321 	if ( !empty( $_REQUEST['post_title'] ) )
   331 	if ( !empty( $_REQUEST['post_title'] ) )
   322 		$post_title = esc_html( stripslashes( $_REQUEST['post_title'] ));
   332 		$post_title = esc_html( stripslashes( $_REQUEST['post_title'] ));
   323 	else if ( !empty( $_REQUEST['popuptitle'] ) ) {
       
   324 		$post_title = esc_html( stripslashes( $_REQUEST['popuptitle'] ));
       
   325 		$post_title = funky_javascript_fix( $post_title );
       
   326 	} else {
       
   327 		$post_title = '';
       
   328 	}
       
   329 
   333 
   330 	$post_content = '';
   334 	$post_content = '';
   331 	if ( !empty( $_REQUEST['content'] ) )
   335 	if ( !empty( $_REQUEST['content'] ) )
   332 		$post_content = esc_html( stripslashes( $_REQUEST['content'] ));
   336 		$post_content = esc_html( stripslashes( $_REQUEST['content'] ));
   333 	else if ( !empty( $post_title ) ) {
   337 
   334 		$text       = esc_html( stripslashes( urldecode( $_REQUEST['text'] ) ) );
   338 	$post_excerpt = '';
   335 		$text       = funky_javascript_fix( $text);
       
   336 		$popupurl   = esc_url($_REQUEST['popupurl']);
       
   337 		$post_content = '<a href="'.$popupurl.'">'.$post_title.'</a>'."\n$text";
       
   338 	}
       
   339 
       
   340 	if ( !empty( $_REQUEST['excerpt'] ) )
   339 	if ( !empty( $_REQUEST['excerpt'] ) )
   341 		$post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] ));
   340 		$post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] ));
   342 	else
       
   343 		$post_excerpt = '';
       
   344 
   341 
   345 	$post->ID = 0;
   342 	$post->ID = 0;
   346 	$post->post_name = '';
   343 	$post->post_name = '';
   347 	$post->post_author = '';
   344 	$post->post_author = '';
   348 	$post->post_date = '';
   345 	$post->post_date = '';
   560 
   557 
   561 	$protected = array( '_wp_attached_file', '_wp_attachment_metadata', '_wp_old_slug', '_wp_page_template' );
   558 	$protected = array( '_wp_attached_file', '_wp_attachment_metadata', '_wp_old_slug', '_wp_page_template' );
   562 
   559 
   563 	$metakeyselect = isset($_POST['metakeyselect']) ? stripslashes( trim( $_POST['metakeyselect'] ) ) : '';
   560 	$metakeyselect = isset($_POST['metakeyselect']) ? stripslashes( trim( $_POST['metakeyselect'] ) ) : '';
   564 	$metakeyinput = isset($_POST['metakeyinput']) ? stripslashes( trim( $_POST['metakeyinput'] ) ) : '';
   561 	$metakeyinput = isset($_POST['metakeyinput']) ? stripslashes( trim( $_POST['metakeyinput'] ) ) : '';
   565 	$metavalue = isset($_POST['metavalue']) ? maybe_serialize( stripslashes( trim( $_POST['metavalue'] ) ) ) : '';
   562 	$metavalue = isset($_POST['metavalue']) ? maybe_serialize( stripslashes_deep( $_POST['metavalue'] ) ) : '';
       
   563 	if ( is_string($metavalue) )
       
   564 		$metavalue = trim( $metavalue );
   566 
   565 
   567 	if ( ('0' === $metavalue || !empty ( $metavalue ) ) && ((('#NONE#' != $metakeyselect) && !empty ( $metakeyselect) ) || !empty ( $metakeyinput) ) ) {
   566 	if ( ('0' === $metavalue || !empty ( $metavalue ) ) && ((('#NONE#' != $metakeyselect) && !empty ( $metakeyselect) ) || !empty ( $metakeyinput) ) ) {
   568 		// We have a key/value pair. If both the select and the
   567 		// We have a key/value pair. If both the select and the
   569 		// input for the key have data, the input takes precedence:
   568 		// input for the key have data, the input takes precedence:
   570 
   569 
   578 			return false;
   577 			return false;
   579 
   578 
   580 		wp_cache_delete($post_ID, 'post_meta');
   579 		wp_cache_delete($post_ID, 'post_meta');
   581 
   580 
   582 		$wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value ) VALUES (%s, %s, %s)", $post_ID, $metakey, $metavalue) );
   581 		$wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value ) VALUES (%s, %s, %s)", $post_ID, $metakey, $metavalue) );
       
   582 		do_action( 'added_postmeta', $wpdb->insert_id, $post_ID, $metakey, $metavalue );
       
   583 
   583 		return $wpdb->insert_id;
   584 		return $wpdb->insert_id;
   584 	}
   585 	}
   585 	return false;
   586 	return false;
   586 } // add_meta
   587 } // add_meta
   587 
   588 
   596 function delete_meta( $mid ) {
   597 function delete_meta( $mid ) {
   597 	global $wpdb;
   598 	global $wpdb;
   598 	$mid = (int) $mid;
   599 	$mid = (int) $mid;
   599 
   600 
   600 	$post_id = $wpdb->get_var( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_id = %d", $mid) );
   601 	$post_id = $wpdb->get_var( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_id = %d", $mid) );
       
   602 
       
   603 	do_action( 'delete_postmeta', $mid );
   601 	wp_cache_delete($post_id, 'post_meta');
   604 	wp_cache_delete($post_id, 'post_meta');
   602 
   605 	$rval = $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id = %d", $mid) );
   603 	return $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id = %d", $mid) );
   606 	do_action( 'deleted_postmeta', $mid );
       
   607 
       
   608 	return $rval;
   604 }
   609 }
   605 
   610 
   606 /**
   611 /**
   607  * Get a list of previously defined keys.
   612  * Get a list of previously defined keys.
   608  *
   613  *
   679 
   684 
   680 	if ( '' === trim( $meta_value ) )
   685 	if ( '' === trim( $meta_value ) )
   681 		return false;
   686 		return false;
   682 
   687 
   683 	$post_id = $wpdb->get_var( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_id = %d", $meta_id) );
   688 	$post_id = $wpdb->get_var( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_id = %d", $meta_id) );
   684 	wp_cache_delete($post_id, 'post_meta');
   689 
   685 
   690 	$meta_value = maybe_serialize( stripslashes_deep( $meta_value ) );
   686 	$meta_value = maybe_serialize( stripslashes( $meta_value ) );
       
   687 	$meta_id = (int) $meta_id;
   691 	$meta_id = (int) $meta_id;
   688 
   692 
   689 	$data  = compact( 'meta_key', 'meta_value' );
   693 	$data  = compact( 'meta_key', 'meta_value' );
   690 	$where = compact( 'meta_id' );
   694 	$where = compact( 'meta_id' );
   691 
   695 
   692 	return $wpdb->update( $wpdb->postmeta, $data, $where );
   696 	do_action( 'update_postmeta', $meta_id, $post_id, $meta_key, $meta_value );
       
   697 	$rval = $wpdb->update( $wpdb->postmeta, $data, $where );
       
   698 	wp_cache_delete($post_id, 'post_meta');
       
   699 	do_action( 'updated_postmeta', $meta_id, $post_id, $meta_key, $meta_value );
       
   700 
       
   701 	return $rval;
   693 }
   702 }
   694 
   703 
   695 //
   704 //
   696 // Private
   705 // Private
   697 //
   706 //
   704  *
   713  *
   705  * @param unknown_type $post_ID
   714  * @param unknown_type $post_ID
   706  * @return unknown
   715  * @return unknown
   707  */
   716  */
   708 function _fix_attachment_links( $post_ID ) {
   717 function _fix_attachment_links( $post_ID ) {
       
   718 	global $_fix_attachment_link_id;
   709 
   719 
   710 	$post = & get_post( $post_ID, ARRAY_A );
   720 	$post = & get_post( $post_ID, ARRAY_A );
   711 
   721 
   712 	$search = "#<a[^>]+rel=('|\")[^'\"]*attachment[^>]*>#ie";
   722 	$search = "#<a[^>]+rel=('|\")[^'\"]*attachment[^>]*>#ie";
   713 
   723 
   731 			$attachment = add_magic_quotes( $attachment);
   741 			$attachment = add_magic_quotes( $attachment);
   732 			wp_update_post( $attachment);
   742 			wp_update_post( $attachment);
   733 		}
   743 		}
   734 
   744 
   735 		$post_search[$i] = $anchor;
   745 		$post_search[$i] = $anchor;
   736 		$post_replace[$i] = preg_replace( "#href=(\"|')[^'\"]*\\1#e", "stripslashes( 'href=\\1' ).get_attachment_link( $id ).stripslashes( '\\1' )", $anchor );
   746 		 $_fix_attachment_link_id = $id;
       
   747 		$post_replace[$i] = preg_replace_callback( "#href=(\"|')[^'\"]*\\1#", '_fix_attachment_links_replace_cb', $anchor );
   737 		++$i;
   748 		++$i;
   738 	}
   749 	}
   739 
   750 
   740 	$post['post_content'] = str_replace( $post_search, $post_replace, $post['post_content'] );
   751 	$post['post_content'] = str_replace( $post_search, $post_replace, $post['post_content'] );
   741 
   752 
   742 	// Escape data pulled from DB.
   753 	// Escape data pulled from DB.
   743 	$post = add_magic_quotes( $post);
   754 	$post = add_magic_quotes( $post);
   744 
   755 
   745 	return wp_update_post( $post);
   756 	return wp_update_post( $post);
       
   757 }
       
   758 
       
   759 function _fix_attachment_links_replace_cb($match) {
       
   760         global $_fix_attachment_link_id;
       
   761         return stripslashes( 'href='.$match[1] ).get_attachment_link( $_fix_attachment_link_id ).stripslashes( $match[1] );
   746 }
   762 }
   747 
   763 
   748 /**
   764 /**
   749  * Move child posts to a new parent.
   765  * Move child posts to a new parent.
   750  *
   766  *
   757  */
   773  */
   758 function _relocate_children( $old_ID, $new_ID ) {
   774 function _relocate_children( $old_ID, $new_ID ) {
   759 	global $wpdb;
   775 	global $wpdb;
   760 	$old_ID = (int) $old_ID;
   776 	$old_ID = (int) $old_ID;
   761 	$new_ID = (int) $new_ID;
   777 	$new_ID = (int) $new_ID;
   762 	return $wpdb->update($wpdb->posts, array('post_parent' => $new_ID), array('post_parent' => $old_ID) );
   778 
       
   779 	$children = $wpdb->get_col( $wpdb->prepare("
       
   780 		SELECT post_id
       
   781 		FROM $wpdb->postmeta
       
   782 		WHERE meta_key = '_wp_attachment_temp_parent'
       
   783 		AND meta_value = %d", $old_ID) );
       
   784 
       
   785 	foreach ( $children as $child_id ) {
       
   786 		$wpdb->update($wpdb->posts, array('post_parent' => $new_ID), array('ID' => $child_id) );
       
   787 		delete_post_meta($child_id, '_wp_attachment_temp_parent');
       
   788 	}
   763 }
   789 }
   764 
   790 
   765 /**
   791 /**
   766  * {@internal Missing Short Description}}
   792  * {@internal Missing Short Description}}
   767  *
   793  *
   793 				'publish' => array(_x('Published', 'post'), __('Published posts'), _n_noop('Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>')),
   819 				'publish' => array(_x('Published', 'post'), __('Published posts'), _n_noop('Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>')),
   794 				'future' => array(_x('Scheduled', 'post'), __('Scheduled posts'), _n_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>')),
   820 				'future' => array(_x('Scheduled', 'post'), __('Scheduled posts'), _n_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>')),
   795 				'pending' => array(_x('Pending Review', 'post'), __('Pending posts'), _n_noop('Pending Review <span class="count">(%s)</span>', 'Pending Review <span class="count">(%s)</span>')),
   821 				'pending' => array(_x('Pending Review', 'post'), __('Pending posts'), _n_noop('Pending Review <span class="count">(%s)</span>', 'Pending Review <span class="count">(%s)</span>')),
   796 				'draft' => array(_x('Draft', 'post'), _x('Drafts', 'manage posts header'), _n_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>')),
   822 				'draft' => array(_x('Draft', 'post'), _x('Drafts', 'manage posts header'), _n_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>')),
   797 				'private' => array(_x('Private', 'post'), __('Private posts'), _n_noop('Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>')),
   823 				'private' => array(_x('Private', 'post'), __('Private posts'), _n_noop('Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>')),
       
   824 				'trash' => array(_x('Trash', 'post'), __('Trash posts'), _n_noop('Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>')),
   798 			);
   825 			);
   799 
   826 
   800 	$post_stati = apply_filters('post_stati', $post_stati);
   827 	$post_stati = apply_filters('post_stati', $post_stati);
   801 
   828 
   802 	$avail_post_stati = get_available_post_statuses('post');
   829 	$avail_post_stati = get_available_post_statuses('post');
   816 	} else {
   843 	} else {
   817 		$order = 'DESC';
   844 		$order = 'DESC';
   818 		$orderby = 'date';
   845 		$orderby = 'date';
   819 	}
   846 	}
   820 
   847 
   821 	$posts_per_page = get_user_option('edit_per_page');
   848 	$posts_per_page = (int) get_user_option( 'edit_per_page', 0, false );
   822 	if ( empty($posts_per_page) )
   849 	if ( empty( $posts_per_page ) || $posts_per_page < 1 )
   823 		$posts_per_page = 15;
   850 		$posts_per_page = 15;
   824 	$posts_per_page = apply_filters('edit_posts_per_page', $posts_per_page);
   851 	$posts_per_page = apply_filters( 'edit_posts_per_page', $posts_per_page );
   825 
   852 
   826 	wp("post_type=post&$post_status_q&posts_per_page=$posts_per_page&order=$order&orderby=$orderby");
   853 	wp("post_type=post&$post_status_q&posts_per_page=$posts_per_page&order=$order&orderby=$orderby");
   827 
   854 
   828 	return array($post_stati, $avail_post_stati);
   855 	return array($post_stati, $avail_post_stati);
       
   856 }
       
   857 
       
   858 /**
       
   859  * Get default post mime types
       
   860  *
       
   861  * @since 2.9.0
       
   862  *
       
   863  * @return array
       
   864  */
       
   865 function get_post_mime_types() {
       
   866 	$post_mime_types = array(	//	array( adj, noun )
       
   867 		'image' => array(__('Images'), __('Manage Images'), _n_noop('Image <span class="count">(%s)</span>', 'Images <span class="count">(%s)</span>')),
       
   868 		'audio' => array(__('Audio'), __('Manage Audio'), _n_noop('Audio <span class="count">(%s)</span>', 'Audio <span class="count">(%s)</span>')),
       
   869 		'video' => array(__('Video'), __('Manage Video'), _n_noop('Video <span class="count">(%s)</span>', 'Video <span class="count">(%s)</span>')),
       
   870 	);
       
   871 
       
   872 	return apply_filters('post_mime_types', $post_mime_types);
   829 }
   873 }
   830 
   874 
   831 /**
   875 /**
   832  * {@internal Missing Short Description}}
   876  * {@internal Missing Short Description}}
   833  *
   877  *
   856 		$q = $_GET;
   900 		$q = $_GET;
   857 
   901 
   858 	$q['m']   = isset( $q['m'] ) ? (int) $q['m'] : 0;
   902 	$q['m']   = isset( $q['m'] ) ? (int) $q['m'] : 0;
   859 	$q['cat'] = isset( $q['cat'] ) ? (int) $q['cat'] : 0;
   903 	$q['cat'] = isset( $q['cat'] ) ? (int) $q['cat'] : 0;
   860 	$q['post_type'] = 'attachment';
   904 	$q['post_type'] = 'attachment';
   861 	$q['post_status'] = 'any';
   905 	$q['post_status'] = isset( $q['status'] ) && 'trash' == $q['status'] ? 'trash' : 'inherit';
   862 	$media_per_page = get_user_option('upload_per_page');
   906 	$media_per_page = (int) get_user_option( 'upload_per_page', 0, false );
   863 	if ( empty($media_per_page) )
   907 	if ( empty( $media_per_page ) || $media_per_page < 1 )
   864 		$media_per_page = 20;
   908 		$media_per_page = 20;
   865 	$q['posts_per_page'] = $media_per_page;
   909 	$q['posts_per_page'] = apply_filters( 'upload_per_page', $media_per_page );
   866 	$post_mime_types = array(	//	array( adj, noun )
   910 
   867 				'image' => array(__('Images'), __('Manage Images'), _n_noop('Image <span class="count">(%s)</span>', 'Images <span class="count">(%s)</span>')),
   911 	$post_mime_types = get_post_mime_types();
   868 				'audio' => array(__('Audio'), __('Manage Audio'), _n_noop('Audio <span class="count">(%s)</span>', 'Audio <span class="count">(%s)</span>')),
       
   869 				'video' => array(__('Video'), __('Manage Video'), _n_noop('Video <span class="count">(%s)</span>', 'Video <span class="count">(%s)</span>')),
       
   870 			);
       
   871 	$post_mime_types = apply_filters('post_mime_types', $post_mime_types);
       
   872 
       
   873 	$avail_post_mime_types = get_available_post_mime_types('attachment');
   912 	$avail_post_mime_types = get_available_post_mime_types('attachment');
   874 
   913 
   875 	if ( isset($q['post_mime_type']) && !array_intersect( (array) $q['post_mime_type'], array_keys($post_mime_types) ) )
   914 	if ( isset($q['post_mime_type']) && !array_intersect( (array) $q['post_mime_type'], array_keys($post_mime_types) ) )
   876 		unset($q['post_mime_type']);
   915 		unset($q['post_mime_type']);
   877 
   916 
   904 /**
   943 /**
   905  * {@internal Missing Short Description}}
   944  * {@internal Missing Short Description}}
   906  *
   945  *
   907  * @since unknown
   946  * @since unknown
   908  *
   947  *
   909  * @param unknown_type $id
   948  * @param int|object $id    Post ID or post object. 
   910  * @param unknown_type $title
   949  * @param string $title (optional) Title 
   911  * @param unknown_type $name
   950  * @param string $name (optional) Name 
   912  * @return unknown
   951  * @return array With two entries of type string 
   913  */
   952  */
   914 function get_sample_permalink($id, $title=null, $name = null) {
   953 function get_sample_permalink($id, $title = null, $name = null) {
   915 	$post = &get_post($id);
   954 	$post = &get_post($id);
   916 	if (!$post->ID) {
   955 	if (!$post->ID) {
   917 		return array('', '');
   956 		return array('', '');
   918 	}
   957 	}
   919 	$original_status = $post->post_status;
   958 	$original_status = $post->post_status;
   922 
   961 
   923 	// Hack: get_permalink would return ugly permalink for
   962 	// Hack: get_permalink would return ugly permalink for
   924 	// drafts, so we will fake, that our post is published
   963 	// drafts, so we will fake, that our post is published
   925 	if (in_array($post->post_status, array('draft', 'pending'))) {
   964 	if (in_array($post->post_status, array('draft', 'pending'))) {
   926 		$post->post_status = 'publish';
   965 		$post->post_status = 'publish';
   927 		$post->post_name = sanitize_title($post->post_name? $post->post_name : $post->post_title, $post->ID);
   966 		$post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID);
   928 	}
   967 	}
   929 
   968 
   930 	$post->post_name = wp_unique_post_slug($post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent);
   969 	$post->post_name = wp_unique_post_slug($post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent);
   931 
   970 
   932 	// If the user wants to set a new name -- override the current one
   971 	// If the user wants to set a new name -- override the current one
   933 	// Note: if empty name is supplied -- use the title instead, see #6072
   972 	// Note: if empty name is supplied -- use the title instead, see #6072
   934 	if (!is_null($name)) {
   973 	if (!is_null($name)) {
   935 		$post->post_name = sanitize_title($name? $name : $title, $post->ID);
   974 		$post->post_name = sanitize_title($name ? $name : $title, $post->ID);
   936 	}
   975 	}
   937 
   976 
   938 	$post->filter = 'sample';
   977 	$post->filter = 'sample';
   939 
   978 
   940 	$permalink = get_permalink($post, true);
   979 	$permalink = get_permalink($post, true);
   958 
   997 
   959 	return $permalink;
   998 	return $permalink;
   960 }
   999 }
   961 
  1000 
   962 /**
  1001 /**
   963  * {@internal Missing Short Description}}
  1002  * sample permalink html
   964  *
  1003  *
   965  * @since unknown
  1004  * intended to be used for the inplace editor of the permalink post slug on in the post (and page?) editor.
   966  *
  1005  * 
   967  * @param unknown_type $id
  1006  * @since unknown
   968  * @param unknown_type $new_title
  1007  *
   969  * @param unknown_type $new_slug
  1008  * @param int|object $id Post ID or post object. 
   970  * @return unknown
  1009  * @param string $new_title (optional) New title  
       
  1010  * @param string $new_slug (optional) New slug 
       
  1011  * @return string intended to be used for the inplace editor of the permalink post slug on in the post (and page?) editor. 
   971  */
  1012  */
   972 function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
  1013 function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
   973 	$post = &get_post($id);
  1014 	$post = &get_post($id);
   974 	list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
  1015 	list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
   975 	if ( 'publish' == $post->post_status )
  1016 
       
  1017 	if ( 'publish' == $post->post_status ) {
   976 		$view_post = 'post' == $post->post_type ? __('View Post') : __('View Page');
  1018 		$view_post = 'post' == $post->post_type ? __('View Post') : __('View Page');
       
  1019 		$title = __('Click to edit this part of the permalink');
       
  1020 	} else {
       
  1021 		$title = __('Temporary permalink. Click to edit this part.');
       
  1022 	}
   977 
  1023 
   978 	if ( false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%') ) {
  1024 	if ( false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%') ) {
   979 		$return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink">' . $permalink . "</span>\n";
  1025 		$return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink">' . $permalink . "</span>\n";
   980 		if ( current_user_can( 'manage_options' ) )
  1026 		if ( current_user_can( 'manage_options' ) && !( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) )
   981 			$return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button" target="_blank">' . __('Change Permalinks') . "</a></span>\n";
  1027 			$return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button" target="_blank">' . __('Change Permalinks') . "</a></span>\n";
   982 		if ( isset($view_post) )
  1028 		if ( isset($view_post) )
   983 			$return .= "<span id='view-post-btn'><a href='$permalink' class='button' target='_blank'>$view_post</a></span>\n";
  1029 			$return .= "<span id='view-post-btn'><a href='$permalink' class='button' target='_blank'>$view_post</a></span>\n";
   984 
  1030 
       
  1031 		$return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug);
       
  1032 
   985 		return $return;
  1033 		return $return;
   986 	}
  1034 	}
   987 
  1035 
   988 	$title = __('Click to edit this part of the permalink');
  1036 	if ( function_exists('mb_strlen') ) {
   989 	if (function_exists('mb_strlen')) {
  1037 		if ( mb_strlen($post_name) > 30 ) {
   990 		if (mb_strlen($post_name) > 30) {
       
   991 			$post_name_abridged = mb_substr($post_name, 0, 14). '&hellip;' . mb_substr($post_name, -14);
  1038 			$post_name_abridged = mb_substr($post_name, 0, 14). '&hellip;' . mb_substr($post_name, -14);
   992 		} else {
  1039 		} else {
   993 			$post_name_abridged = $post_name;
  1040 			$post_name_abridged = $post_name;
   994 		}
  1041 		}
   995 	} else {
  1042 	} else {
   996 		if (strlen($post_name) > 30) {
  1043 		if ( strlen($post_name) > 30 ) {
   997 			$post_name_abridged = substr($post_name, 0, 14). '&hellip;' . substr($post_name, -14);
  1044 			$post_name_abridged = substr($post_name, 0, 14). '&hellip;' . substr($post_name, -14);
   998 		} else {
  1045 		} else {
   999 			$post_name_abridged = $post_name;
  1046 			$post_name_abridged = $post_name;
  1000 		}
  1047 		}
  1001 	}
  1048 	}
  1002 
  1049 
  1003 	$post_name_html = '<span id="editable-post-name" title="' . $title . '">' . $post_name_abridged . '</span>';
  1050 	$post_name_html = '<span id="editable-post-name" title="' . $title . '">' . $post_name_abridged . '</span>';
  1004 	$display_link = str_replace(array('%pagename%','%postname%'), $post_name_html, $permalink);
  1051 	$display_link = str_replace(array('%pagename%','%postname%'), $post_name_html, $permalink);
  1005 	$view_link = str_replace(array('%pagename%','%postname%'), $post_name, $permalink);
  1052 	$view_link = str_replace(array('%pagename%','%postname%'), $post_name, $permalink);
  1006 	$return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink">' . $display_link . "</span>\n";
  1053 	$return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink">' . $display_link . "</span>\n";
  1007 	$return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug button hide-if-no-js" onclick="edit_permalink(' . $id . '); return false;">' . __('Edit') . "</a></span>\n";
  1054 	$return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug button hide-if-no-js" onclick="editPermalink(' . $id . '); return false;">' . __('Edit') . "</a></span>\n";
  1008 	$return .= '<span id="editable-post-name-full">' . $post_name . "</span>\n";
  1055 	$return .= '<span id="editable-post-name-full">' . $post_name . "</span>\n";
  1009 	if ( isset($view_post) )
  1056 	if ( isset($view_post) )
  1010 		$return .= "<span id='view-post-btn'><a href='$view_link' class='button' target='_blank'>$view_post</a></span>\n";
  1057 		$return .= "<span id='view-post-btn'><a href='$view_link' class='button' target='_blank'>$view_post</a></span>\n";
  1011 
  1058 
       
  1059 	$return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug);
       
  1060 
  1012 	return $return;
  1061 	return $return;
  1013 }
  1062 }
  1014 
  1063 
  1015 /**
  1064 /**
  1016  * {@internal Missing Short Description}}
  1065  * Output HTML for the post thumbnail meta-box.
  1017  *
  1066  *
  1018  * @since unknown
  1067  * @since 2.9.0
  1019  *
  1068  *
  1020  * @param unknown_type $post_id
  1069  * @param int $thumbnail_id ID of the attachment used for thumbnail
       
  1070  * @return string html
       
  1071  */
       
  1072 function _wp_post_thumbnail_html( $thumbnail_id = NULL ) {
       
  1073 	global $content_width, $_wp_additional_image_sizes;
       
  1074 	$content = '<p class="hide-if-no-js"><a href="#" id="set-post-thumbnail" onclick="jQuery(\'#add_image\').click();return false;">' . esc_html__( 'Set thumbnail' ) . '</a></p>';
       
  1075 
       
  1076 	if ( $thumbnail_id && get_post( $thumbnail_id ) ) {
       
  1077 		$old_content_width = $content_width;
       
  1078 		$content_width = 266;
       
  1079 		if ( !isset( $_wp_additional_image_sizes['post-thumbnail'] ) )
       
  1080 			$thumbnail_html = wp_get_attachment_image( $thumbnail_id, array( $content_width, $content_width ) );
       
  1081 		else
       
  1082 			$thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'post-thumbnail' );
       
  1083 		if ( !empty( $thumbnail_html ) ) {
       
  1084 			$content = '<a href="#" id="set-post-thumbnail" onclick="jQuery(\'#add_image\').click();return false;">' . $thumbnail_html . '</a>';
       
  1085 			$content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail" onclick="WPRemoveThumbnail();return false;">' . esc_html__( 'Remove thumbnail' ) . '</a></p>';
       
  1086 		}
       
  1087 		$content_width = $old_content_width;
       
  1088 	}
       
  1089 
       
  1090 	return apply_filters( 'admin_post_thumbnail_html', $content );
       
  1091 }
       
  1092 
       
  1093 /**
       
  1094  * Check to see if the post is currently being edited by another user.
       
  1095  *
       
  1096  * @since 2.5.0
       
  1097  *
       
  1098  * @param int $post_id ID of the post to check for editing
  1021  * @return bool|int False: not locked or locked by current user. Int: user ID of user with lock.
  1099  * @return bool|int False: not locked or locked by current user. Int: user ID of user with lock.
  1022  */
  1100  */
  1023 function wp_check_post_lock( $post_id ) {
  1101 function wp_check_post_lock( $post_id ) {
  1024 	global $current_user;
  1102 	global $current_user;
  1025 
  1103 
  1035 		return $last;
  1113 		return $last;
  1036 	return false;
  1114 	return false;
  1037 }
  1115 }
  1038 
  1116 
  1039 /**
  1117 /**
  1040  * {@internal Missing Short Description}}
  1118  * Mark the post as currently being edited by the current user
  1041  *
  1119  *
  1042  * @since unknown
  1120  * @since 2.5.0
  1043  *
  1121  *
  1044  * @param unknown_type $post_id
  1122  * @param int $post_id ID of the post to being edited
  1045  * @return unknown
  1123  * @return bool Returns false if the post doesn't exist of there is no current user
  1046  */
  1124  */
  1047 function wp_set_post_lock( $post_id ) {
  1125 function wp_set_post_lock( $post_id ) {
  1048 	global $current_user;
  1126 	global $current_user;
  1049 	if ( !$post = get_post( $post_id ) )
  1127 	if ( !$post = get_post( $post_id ) )
  1050 		return false;
  1128 		return false;
  1059 		update_post_meta( $post->ID, '_edit_last', $current_user->ID );
  1137 		update_post_meta( $post->ID, '_edit_last', $current_user->ID );
  1060 }
  1138 }
  1061 
  1139 
  1062 /**
  1140 /**
  1063  * Outputs the notice message to say that someone else is editing this post at the moment.
  1141  * Outputs the notice message to say that someone else is editing this post at the moment.
  1064  * 
  1142  *
  1065  * @since 2.8.5
  1143  * @since 2.8.5
  1066  * @return none
  1144  * @return none
  1067  */
  1145  */
  1068 function _admin_notice_post_locked() {
  1146 function _admin_notice_post_locked() {
  1069 	global $post;
  1147 	global $post;
  1070 	$last_user = get_userdata( get_post_meta( $post->ID, '_edit_last', true ) );
  1148 	$last_user = get_userdata( get_post_meta( $post->ID, '_edit_last', true ) );
  1071 	$last_user_name = $last_user ? $last_user->display_name : __('Somebody');
  1149 	$last_user_name = $last_user ? $last_user->display_name : __('Somebody');
  1072 	
  1150 
  1073 	switch ($post->post_type) {
  1151 	switch ($post->post_type) {
  1074 		case 'post':
  1152 		case 'post':
  1075 			$message = __( 'Warning: %s is currently editing this post' );
  1153 			$message = __( 'Warning: %s is currently editing this post' );
  1076 			break;
  1154 			break;
  1077 		case 'page':
  1155 		case 'page':
  1078 			$message = __( 'Warning: %s is currently editing this page' );
  1156 			$message = __( 'Warning: %s is currently editing this page' );
  1079 			break;
  1157 			break;
  1080 		default:
  1158 		default:
  1081 			$message = __( 'Warning: %s is currently editing this.' );
  1159 			$message = __( 'Warning: %s is currently editing this.' );
  1082 	}
  1160 	}
  1083 	
  1161 
  1084 	$message = sprintf( $message, esc_html( $last_user_name ) );
  1162 	$message = sprintf( $message, esc_html( $last_user_name ) );
  1085 	echo "<div class='error'><p>$message</p></div>";	
  1163 	echo "<div class='error'><p>$message</p></div>";
  1086 }
  1164 }
  1087 
  1165 
  1088 /**
  1166 /**
  1089  * Creates autosave data for the specified post from $_POST data.
  1167  * Creates autosave data for the specified post from $_POST data.
  1090  *
  1168  *
  1102 
  1180 
  1103 	// Only store one autosave.  If there is already an autosave, overwrite it.
  1181 	// Only store one autosave.  If there is already an autosave, overwrite it.
  1104 	if ( $old_autosave = wp_get_post_autosave( $post_id ) ) {
  1182 	if ( $old_autosave = wp_get_post_autosave( $post_id ) ) {
  1105 		$new_autosave = _wp_post_revision_fields( $_POST, true );
  1183 		$new_autosave = _wp_post_revision_fields( $_POST, true );
  1106 		$new_autosave['ID'] = $old_autosave->ID;
  1184 		$new_autosave['ID'] = $old_autosave->ID;
       
  1185 		$current_user = wp_get_current_user();
       
  1186 		$new_autosave['post_author'] = $current_user->ID;
  1107 		return wp_update_post( $new_autosave );
  1187 		return wp_update_post( $new_autosave );
  1108 	}
  1188 	}
  1109 
  1189 
  1110 	// _wp_put_post_revision() expects unescaped.
  1190 	// _wp_put_post_revision() expects unescaped.
  1111 	$_POST = stripslashes_deep($_POST);
  1191 	$_POST = stripslashes_deep($_POST);
  1185  * and optionaly pre-compressed version of the core and all default plugins. Additional plugins are loaded
  1265  * and optionaly pre-compressed version of the core and all default plugins. Additional plugins are loaded
  1186  * directly by TinyMCE using non-blocking method. Custom plugins can be refreshed by adding a query string
  1266  * directly by TinyMCE using non-blocking method. Custom plugins can be refreshed by adding a query string
  1187  * to the URL when queueing them with the mce_external_plugins filter.
  1267  * to the URL when queueing them with the mce_external_plugins filter.
  1188  *
  1268  *
  1189  * @param bool $teeny optional Output a trimmed down version used in Press This.
  1269  * @param bool $teeny optional Output a trimmed down version used in Press This.
  1190  */
  1270  * @param mixed $settings optional An array that can add to or overwrite the default TinyMCE settings.
  1191 function wp_tiny_mce( $teeny = false ) {
  1271  */
       
  1272 function wp_tiny_mce( $teeny = false, $settings = false ) {
  1192 	global $concatenate_scripts, $compress_scripts, $tinymce_version;
  1273 	global $concatenate_scripts, $compress_scripts, $tinymce_version;
  1193 
  1274 
  1194 	if ( ! user_can_richedit() )
  1275 	if ( ! user_can_richedit() )
  1195 		return;
  1276 		return;
  1196 
  1277 
  1205 	http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/spellchecker
  1286 	http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/spellchecker
  1206 	*/
  1287 	*/
  1207 	$mce_spellchecker_languages = apply_filters('mce_spellchecker_languages', '+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv');
  1288 	$mce_spellchecker_languages = apply_filters('mce_spellchecker_languages', '+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv');
  1208 
  1289 
  1209 	if ( $teeny ) {
  1290 	if ( $teeny ) {
  1210 		$plugins = apply_filters( 'teeny_mce_plugins', array('safari', 'inlinepopups', 'media', 'autosave', 'fullscreen') );
  1291 		$plugins = apply_filters( 'teeny_mce_plugins', array('safari', 'inlinepopups', 'media', 'fullscreen', 'wordpress') );
  1211 		$ext_plugins = '';
  1292 		$ext_plugins = '';
  1212 	} else {
  1293 	} else {
  1213 		$plugins = array( 'safari', 'inlinepopups', 'spellchecker', 'paste', 'wordpress', 'media', 'fullscreen', 'wpeditimage', 'wpgallery', 'tabfocus' );
  1294 		$plugins = array( 'safari', 'inlinepopups', 'spellchecker', 'paste', 'wordpress', 'media', 'fullscreen', 'wpeditimage', 'wpgallery', 'tabfocus' );
  1214 
  1295 
  1215 		/*
  1296 		/*
  1339 		'gecko_spellcheck' => true,
  1420 		'gecko_spellcheck' => true,
  1340 		'entities' => '38,amp,60,lt,62,gt',
  1421 		'entities' => '38,amp,60,lt,62,gt',
  1341 		'accessibility_focus' => true,
  1422 		'accessibility_focus' => true,
  1342 		'tabfocus_elements' => 'major-publishing-actions',
  1423 		'tabfocus_elements' => 'major-publishing-actions',
  1343 		'media_strict' => false,
  1424 		'media_strict' => false,
  1344 		'save_callback' => 'switchEditors.saveCallback',
  1425 		'paste_remove_styles' => true,
       
  1426 		'paste_remove_spans' => true,
       
  1427 		'paste_strip_class_attributes' => 'all',
  1345 		'wpeditimage_disable_captions' => $no_captions,
  1428 		'wpeditimage_disable_captions' => $no_captions,
  1346 		'plugins' => "$plugins"
  1429 		'plugins' => "$plugins"
  1347 	);
  1430 	);
  1348 
  1431 
  1349 	$mce_css = trim(apply_filters('mce_css', ''), ' ,');
  1432 	$mce_css = trim(apply_filters('mce_css', ''), ' ,');
  1350 
  1433 
  1351 	if ( ! empty($mce_css) )
  1434 	if ( ! empty($mce_css) )
  1352 		$initArray['content_css'] = "$mce_css";
  1435 		$initArray['content_css'] = "$mce_css";
       
  1436 
       
  1437 	if ( is_array($settings) )
       
  1438 		$initArray = array_merge($initArray, $settings);
  1353 
  1439 
  1354 	// For people who really REALLY know what they're doing with TinyMCE
  1440 	// For people who really REALLY know what they're doing with TinyMCE
  1355 	// You can modify initArray to add, remove, change elements of the config before tinyMCE.init
  1441 	// You can modify initArray to add, remove, change elements of the config before tinyMCE.init
  1356 	// Setting "valid_elements", "invalid_elements" and "extended_valid_elements" can be done through "tiny_mce_before_init".
  1442 	// Setting "valid_elements", "invalid_elements" and "extended_valid_elements" can be done through "tiny_mce_before_init".
  1357 	// Best is to use the default cleanup by not specifying valid_elements, as TinyMCE contains full set of XHTML 1.0.
  1443 	// Best is to use the default cleanup by not specifying valid_elements, as TinyMCE contains full set of XHTML 1.0.