-
+ 2E195A249E509B946027D0EAFAB56B3C706ADBE329288E5B38084B93D22C4D4C11644DF75DC75D6376A9DB3B2123B6BADC416734638D9BD25F1081C2A2F2E60D
mp-wp/wp-admin/includes/post.php
(0 . 0)(1 . 1349)
38803 <?php
38804 /**
38805 * WordPress Post Administration API.
38806 *
38807 * @package WordPress
38808 * @subpackage Administration
38809 */
38810
38811 /**
38812 * Rename $_POST data from form names to DB post columns.
38813 *
38814 * Manipulates $_POST directly.
38815 *
38816 * @package WordPress
38817 * @since 2.6.0
38818 *
38819 * @param bool $update Are we updating a pre-existing post?
38820 * @param post_data array Array of post data. Defaults to the contents of $_POST.
38821 * @return object|bool WP_Error on failure, true on success.
38822 */
38823 function _wp_translate_postdata( $update = false, $post_data = null ) {
38824
38825 if ( empty($post_data) )
38826 $post_data = &$_POST;
38827
38828 if ( $update )
38829 $post_data['ID'] = (int) $post_data['post_ID'];
38830 $post_data['post_content'] = isset($post_data['content']) ? $post_data['content'] : '';
38831 $post_data['post_excerpt'] = isset($post_data['excerpt']) ? $post_data['excerpt'] : '';
38832 $post_data['post_parent'] = isset($post_data['parent_id'])? $post_data['parent_id'] : '';
38833 if ( isset($post_data['trackback_url']) )
38834 $post_data['to_ping'] = $post_data['trackback_url'];
38835
38836 if (!empty ( $post_data['post_author_override'] ) ) {
38837 $post_data['post_author'] = (int) $post_data['post_author_override'];
38838 } else {
38839 if (!empty ( $post_data['post_author'] ) ) {
38840 $post_data['post_author'] = (int) $post_data['post_author'];
38841 } else {
38842 $post_data['post_author'] = (int) $post_data['user_ID'];
38843 }
38844 }
38845
38846 if ( isset($post_data['user_ID']) && ($post_data['post_author'] != $post_data['user_ID']) ) {
38847 if ( 'page' == $post_data['post_type'] ) {
38848 if ( !current_user_can( 'edit_others_pages' ) ) {
38849 return new WP_Error( 'edit_others_pages', $update ?
38850 __( 'You are not allowed to edit pages as this user.' ) :
38851 __( 'You are not allowed to create pages as this user.' )
38852 );
38853 }
38854 } else {
38855 if ( !current_user_can( 'edit_others_posts' ) ) {
38856 return new WP_Error( 'edit_others_posts', $update ?
38857 __( 'You are not allowed to edit posts as this user.' ) :
38858 __( 'You are not allowed to post as this user.' )
38859 );
38860 }
38861 }
38862 }
38863
38864 // What to do based on which button they pressed
38865 if ( isset($post_data['saveasdraft']) && '' != $post_data['saveasdraft'] )
38866 $post_data['post_status'] = 'draft';
38867 if ( isset($post_data['saveasprivate']) && '' != $post_data['saveasprivate'] )
38868 $post_data['post_status'] = 'private';
38869 if ( isset($post_data['publish']) && ( '' != $post_data['publish'] ) && ( $post_data['post_status'] != 'private' ) )
38870 $post_data['post_status'] = 'publish';
38871 if ( isset($post_data['advanced']) && '' != $post_data['advanced'] )
38872 $post_data['post_status'] = 'draft';
38873 if ( isset($post_data['pending']) && '' != $post_data['pending'] )
38874 $post_data['post_status'] = 'pending';
38875
38876 $previous_status = get_post_field('post_status', isset($post_data['ID']) ? $post_data['ID'] : $post_data['temp_ID']);
38877
38878 // Posts 'submitted for approval' present are submitted to $_POST the same as if they were being published.
38879 // Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts.
38880 if ( 'page' == $post_data['post_type'] ) {
38881 $publish_cap = 'publish_pages';
38882 $edit_cap = 'edit_published_pages';
38883 } else {
38884 $publish_cap = 'publish_posts';
38885 $edit_cap = 'edit_published_posts';
38886 }
38887 if ( isset($post_data['post_status']) && ('publish' == $post_data['post_status'] && !current_user_can( $publish_cap )) )
38888 if ( $previous_status != 'publish' || !current_user_can( $edit_cap ) )
38889 $post_data['post_status'] = 'pending';
38890
38891 if ( ! isset($post_data['post_status']) )
38892 $post_data['post_status'] = $previous_status;
38893
38894 if (!isset( $post_data['comment_status'] ))
38895 $post_data['comment_status'] = 'closed';
38896
38897 if (!isset( $post_data['ping_status'] ))
38898 $post_data['ping_status'] = 'closed';
38899
38900 foreach ( array('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit ) {
38901 if ( !empty( $post_data['hidden_' . $timeunit] ) && $post_data['hidden_' . $timeunit] != $post_data[$timeunit] ) {
38902 $post_data['edit_date'] = '1';
38903 break;
38904 }
38905 }
38906
38907 if ( !empty( $post_data['edit_date'] ) ) {
38908 $aa = $post_data['aa'];
38909 $mm = $post_data['mm'];
38910 $jj = $post_data['jj'];
38911 $hh = $post_data['hh'];
38912 $mn = $post_data['mn'];
38913 $ss = $post_data['ss'];
38914 $aa = ($aa <= 0 ) ? date('Y') : $aa;
38915 $mm = ($mm <= 0 ) ? date('n') : $mm;
38916 $jj = ($jj > 31 ) ? 31 : $jj;
38917 $jj = ($jj <= 0 ) ? date('j') : $jj;
38918 $hh = ($hh > 23 ) ? $hh -24 : $hh;
38919 $mn = ($mn > 59 ) ? $mn -60 : $mn;
38920 $ss = ($ss > 59 ) ? $ss -60 : $ss;
38921 $post_data['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
38922 $post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] );
38923 }
38924
38925 return $post_data;
38926 }
38927
38928 /**
38929 * Update an existing post with values provided in $_POST.
38930 *
38931 * @since unknown
38932 *
38933 * @param array $post_data Optional.
38934 * @return int Post ID.
38935 */
38936 function edit_post( $post_data = null ) {
38937
38938 if ( empty($post_data) )
38939 $post_data = &$_POST;
38940
38941 $post_ID = (int) $post_data['post_ID'];
38942
38943 if ( 'page' == $post_data['post_type'] ) {
38944 if ( !current_user_can( 'edit_page', $post_ID ) )
38945 wp_die( __('You are not allowed to edit this page.' ));
38946 } else {
38947 if ( !current_user_can( 'edit_post', $post_ID ) )
38948 wp_die( __('You are not allowed to edit this post.' ));
38949 }
38950
38951 // Autosave shouldn't save too soon after a real save
38952 if ( 'autosave' == $post_data['action'] ) {
38953 $post =& get_post( $post_ID );
38954 $now = time();
38955 $then = strtotime($post->post_date_gmt . ' +0000');
38956 $delta = AUTOSAVE_INTERVAL / 2;
38957 if ( ($now - $then) < $delta )
38958 return $post_ID;
38959 }
38960
38961 $post_data = _wp_translate_postdata( true, $post_data );
38962 if ( is_wp_error($post_data) )
38963 wp_die( $post_data->get_error_message() );
38964
38965 if ( isset($post_data['visibility']) ) {
38966 switch ( $post_data['visibility'] ) {
38967 case 'public' :
38968 $post_data['post_password'] = '';
38969 break;
38970 case 'password' :
38971 unset( $post_data['sticky'] );
38972 break;
38973 case 'private' :
38974 $post_data['post_status'] = 'private';
38975 $post_data['post_password'] = '';
38976 unset( $post_data['sticky'] );
38977 break;
38978 }
38979 }
38980
38981 // Meta Stuff
38982 if ( isset($post_data['meta']) && $post_data['meta'] ) {
38983 foreach ( $post_data['meta'] as $key => $value )
38984 update_meta( $key, $value['key'], $value['value'] );
38985 }
38986
38987 if ( isset($post_data['deletemeta']) && $post_data['deletemeta'] ) {
38988 foreach ( $post_data['deletemeta'] as $key => $value )
38989 delete_meta( $key );
38990 }
38991
38992 add_meta( $post_ID );
38993
38994 wp_update_post( $post_data );
38995
38996 // Reunite any orphaned attachments with their parent
38997 if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )
38998 $draft_ids = array();
38999 if ( $draft_temp_id = (int) array_search( $post_ID, $draft_ids ) )
39000 _relocate_children( $draft_temp_id, $post_ID );
39001
39002 // Now that we have an ID we can fix any attachment anchor hrefs
39003 _fix_attachment_links( $post_ID );
39004
39005 wp_set_post_lock( $post_ID, $GLOBALS['current_user']->ID );
39006
39007 if ( current_user_can( 'edit_others_posts' ) ) {
39008 if ( !empty($post_data['sticky']) )
39009 stick_post($post_ID);
39010 else
39011 unstick_post($post_ID);
39012 }
39013
39014 return $post_ID;
39015 }
39016
39017 /**
39018 * {@internal Missing Short Description}}
39019 *
39020 * Updates all bulk edited posts/pages, adding (but not removing) tags and
39021 * categories. Skips pages when they would be their own parent or child.
39022 *
39023 * @since unknown
39024 *
39025 * @return array
39026 */
39027 function bulk_edit_posts( $post_data = null ) {
39028 global $wpdb;
39029
39030 if ( empty($post_data) )
39031 $post_data = &$_POST;
39032
39033 if ( 'page' == $post_data['post_type'] ) {
39034 if ( ! current_user_can( 'edit_pages' ) )
39035 wp_die( __('You are not allowed to edit pages.') );
39036 } else {
39037 if ( ! current_user_can( 'edit_posts' ) )
39038 wp_die( __('You are not allowed to edit posts.') );
39039 }
39040
39041 $post_IDs = array_map( intval, (array) $post_data['post'] );
39042
39043 $reset = array( 'post_author', 'post_status', 'post_password', 'post_parent', 'page_template', 'comment_status', 'ping_status', 'keep_private', 'tags_input', 'post_category', 'sticky' );
39044 foreach ( $reset as $field ) {
39045 if ( isset($post_data[$field]) && ( '' == $post_data[$field] || -1 == $post_data[$field] ) )
39046 unset($post_data[$field]);
39047 }
39048
39049 if ( isset($post_data['post_category']) ) {
39050 if ( is_array($post_data['post_category']) && ! empty($post_data['post_category']) )
39051 $new_cats = array_map( absint, $post_data['post_category'] );
39052 else
39053 unset($post_data['post_category']);
39054 }
39055
39056 if ( isset($post_data['tags_input']) ) {
39057 $new_tags = preg_replace( '/\s*,\s*/', ',', rtrim( trim($post_data['tags_input']), ' ,' ) );
39058 $new_tags = explode(',', $new_tags);
39059 }
39060
39061 if ( isset($post_data['post_parent']) && ($parent = (int) $post_data['post_parent']) ) {
39062 $pages = $wpdb->get_results("SELECT ID, post_parent FROM $wpdb->posts WHERE post_type = 'page'");
39063 $children = array();
39064
39065 for ( $i = 0; $i < 50 && $parent > 0; $i++ ) {
39066 $children[] = $parent;
39067
39068 foreach ( $pages as $page ) {
39069 if ( $page->ID == $parent ) {
39070 $parent = $page->post_parent;
39071 break;
39072 }
39073 }
39074 }
39075 }
39076
39077 $updated = $skipped = $locked = array();
39078 foreach ( $post_IDs as $post_ID ) {
39079
39080 if ( isset($children) && in_array($post_ID, $children) ) {
39081 $skipped[] = $post_ID;
39082 continue;
39083 }
39084
39085 if ( wp_check_post_lock( $post_ID ) ) {
39086 $locked[] = $post_ID;
39087 continue;
39088 }
39089
39090 if ( isset($new_cats) ) {
39091 $cats = (array) wp_get_post_categories($post_ID);
39092 $post_data['post_category'] = array_unique( array_merge($cats, $new_cats) );
39093 }
39094
39095 if ( isset($new_tags) ) {
39096 $tags = wp_get_post_tags($post_ID, array('fields' => 'names'));
39097 $post_data['tags_input'] = array_unique( array_merge($tags, $new_tags) );
39098 }
39099
39100 $post_data['ID'] = $post_ID;
39101 $updated[] = wp_update_post( $post_data );
39102
39103 if ( current_user_can( 'edit_others_posts' ) && isset( $post_data['sticky'] ) ) {
39104 if ( 'sticky' == $post_data['sticky'] )
39105 stick_post( $post_ID );
39106 else
39107 unstick_post( $post_ID );
39108 }
39109
39110 }
39111
39112 return array( 'updated' => $updated, 'skipped' => $skipped, 'locked' => $locked );
39113 }
39114
39115 /**
39116 * Default post information to use when populating the "Write Post" form.
39117 *
39118 * @since unknown
39119 *
39120 * @return unknown
39121 */
39122 function get_default_post_to_edit() {
39123 if ( !empty( $_REQUEST['post_title'] ) )
39124 $post_title = wp_specialchars( stripslashes( $_REQUEST['post_title'] ));
39125 else if ( !empty( $_REQUEST['popuptitle'] ) ) {
39126 $post_title = wp_specialchars( stripslashes( $_REQUEST['popuptitle'] ));
39127 $post_title = funky_javascript_fix( $post_title );
39128 } else {
39129 $post_title = '';
39130 }
39131
39132 $post_content = '';
39133 if ( !empty( $_REQUEST['content'] ) )
39134 $post_content = wp_specialchars( stripslashes( $_REQUEST['content'] ));
39135 else if ( !empty( $post_title ) ) {
39136 $text = wp_specialchars( stripslashes( urldecode( $_REQUEST['text'] ) ) );
39137 $text = funky_javascript_fix( $text);
39138 $popupurl = clean_url($_REQUEST['popupurl']);
39139 $post_content = '<a href="'.$popupurl.'">'.$post_title.'</a>'."\n$text";
39140 }
39141
39142 if ( !empty( $_REQUEST['excerpt'] ) )
39143 $post_excerpt = wp_specialchars( stripslashes( $_REQUEST['excerpt'] ));
39144 else
39145 $post_excerpt = '';
39146
39147 $post->ID = 0;
39148 $post->post_name = '';
39149 $post->post_author = '';
39150 $post->post_date = '';
39151 $post->post_password = '';
39152 $post->post_status = 'draft';
39153 $post->post_type = 'post';
39154 $post->to_ping = '';
39155 $post->pinged = '';
39156 $post->comment_status = get_option( 'default_comment_status' );
39157 $post->ping_status = get_option( 'default_ping_status' );
39158 $post->post_pingback = get_option( 'default_pingback_flag' );
39159 $post->post_category = get_option( 'default_category' );
39160 $post->post_content = apply_filters( 'default_content', $post_content);
39161 $post->post_title = apply_filters( 'default_title', $post_title );
39162 $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt);
39163 $post->page_template = 'default';
39164 $post->post_parent = 0;
39165 $post->menu_order = 0;
39166
39167 return $post;
39168 }
39169
39170 /**
39171 * {@internal Missing Short Description}}
39172 *
39173 * @since unknown
39174 *
39175 * @return unknown
39176 */
39177 function get_default_page_to_edit() {
39178 $page = get_default_post_to_edit();
39179 $page->post_type = 'page';
39180 return $page;
39181 }
39182
39183 /**
39184 * Get an existing post and format it for editing.
39185 *
39186 * @since unknown
39187 *
39188 * @param unknown_type $id
39189 * @return unknown
39190 */
39191 function get_post_to_edit( $id ) {
39192
39193 $post = get_post( $id, OBJECT, 'edit' );
39194
39195 if ( $post->post_type == 'page' )
39196 $post->page_template = get_post_meta( $id, '_wp_page_template', true );
39197
39198 return $post;
39199 }
39200
39201 /**
39202 * {@internal Missing Short Description}}
39203 *
39204 * @since unknown
39205 *
39206 * @param unknown_type $title
39207 * @param unknown_type $content
39208 * @param unknown_type $post_date
39209 * @return unknown
39210 */
39211 function post_exists($title, $content = '', $post_date = '') {
39212 global $wpdb;
39213
39214 $title = stripslashes($title);
39215 $content = stripslashes($content);
39216 $post_date = stripslashes($post_date);
39217
39218 if (!empty ($post_date))
39219 $post_date = $wpdb->prepare("AND post_date = %s", $post_date);
39220
39221 if (!empty ($title))
39222 return $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title = %s $post_date", $title) );
39223 else
39224 if (!empty ($content))
39225 return $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_content = %s $post_date", $content) );
39226
39227 return 0;
39228 }
39229
39230 /**
39231 * Creates a new post from the "Write Post" form using $_POST information.
39232 *
39233 * @since unknown
39234 *
39235 * @return unknown
39236 */
39237 function wp_write_post() {
39238 global $user_ID;
39239
39240 if ( 'page' == $_POST['post_type'] ) {
39241 if ( !current_user_can( 'edit_pages' ) )
39242 return new WP_Error( 'edit_pages', __( 'You are not allowed to create pages on this blog.' ) );
39243 } else {
39244 if ( !current_user_can( 'edit_posts' ) )
39245 return new WP_Error( 'edit_posts', __( 'You are not allowed to create posts or drafts on this blog.' ) );
39246 }
39247
39248
39249 // Check for autosave collisions
39250 $temp_id = false;
39251 if ( isset($_POST['temp_ID']) ) {
39252 $temp_id = (int) $_POST['temp_ID'];
39253 if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )
39254 $draft_ids = array();
39255 foreach ( $draft_ids as $temp => $real )
39256 if ( time() + $temp > 86400 ) // 1 day: $temp is equal to -1 * time( then )
39257 unset($draft_ids[$temp]);
39258
39259 if ( isset($draft_ids[$temp_id]) ) { // Edit, don't write
39260 $_POST['post_ID'] = $draft_ids[$temp_id];
39261 unset($_POST['temp_ID']);
39262 update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids );
39263 return edit_post();
39264 }
39265 }
39266
39267 $translated = _wp_translate_postdata( false );
39268 if ( is_wp_error($translated) )
39269 return $translated;
39270
39271 if ( isset($_POST['visibility']) ) {
39272 switch ( $_POST['visibility'] ) {
39273 case 'public' :
39274 $_POST['post_password'] = '';
39275 break;
39276 case 'password' :
39277 unset( $_POST['sticky'] );
39278 break;
39279 case 'private' :
39280 $_POST['post_status'] = 'private';
39281 $_POST['post_password'] = '';
39282 unset( $_POST['sticky'] );
39283 break;
39284 }
39285 }
39286
39287 // Create the post.
39288 $post_ID = wp_insert_post( $_POST );
39289 if ( is_wp_error( $post_ID ) )
39290 return $post_ID;
39291
39292 if ( empty($post_ID) )
39293 return 0;
39294
39295 add_meta( $post_ID );
39296
39297 // Reunite any orphaned attachments with their parent
39298 if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )
39299 $draft_ids = array();
39300 if ( $draft_temp_id = (int) array_search( $post_ID, $draft_ids ) )
39301 _relocate_children( $draft_temp_id, $post_ID );
39302 if ( $temp_id && $temp_id != $draft_temp_id )
39303 _relocate_children( $temp_id, $post_ID );
39304
39305 // Update autosave collision detection
39306 if ( $temp_id ) {
39307 $draft_ids[$temp_id] = $post_ID;
39308 update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids );
39309 }
39310
39311 // Now that we have an ID we can fix any attachment anchor hrefs
39312 _fix_attachment_links( $post_ID );
39313
39314 wp_set_post_lock( $post_ID, $GLOBALS['current_user']->ID );
39315
39316 return $post_ID;
39317 }
39318
39319 /**
39320 * Calls wp_write_post() and handles the errors.
39321 *
39322 * @since unknown
39323 *
39324 * @return unknown
39325 */
39326 function write_post() {
39327 $result = wp_write_post();
39328 if( is_wp_error( $result ) )
39329 wp_die( $result->get_error_message() );
39330 else
39331 return $result;
39332 }
39333
39334 //
39335 // Post Meta
39336 //
39337
39338 /**
39339 * {@internal Missing Short Description}}
39340 *
39341 * @since unknown
39342 *
39343 * @param unknown_type $post_ID
39344 * @return unknown
39345 */
39346 function add_meta( $post_ID ) {
39347 global $wpdb;
39348 $post_ID = (int) $post_ID;
39349
39350 $protected = array( '_wp_attached_file', '_wp_attachment_metadata', '_wp_old_slug', '_wp_page_template' );
39351
39352 $metakeyselect = isset($_POST['metakeyselect']) ? stripslashes( trim( $_POST['metakeyselect'] ) ) : '';
39353 $metakeyinput = isset($_POST['metakeyinput']) ? stripslashes( trim( $_POST['metakeyinput'] ) ) : '';
39354 $metavalue = isset($_POST['metavalue']) ? maybe_serialize( stripslashes( trim( $_POST['metavalue'] ) ) ) : '';
39355
39356 if ( ('0' === $metavalue || !empty ( $metavalue ) ) && ((('#NONE#' != $metakeyselect) && !empty ( $metakeyselect) ) || !empty ( $metakeyinput) ) ) {
39357 // We have a key/value pair. If both the select and the
39358 // input for the key have data, the input takes precedence:
39359
39360 if ('#NONE#' != $metakeyselect)
39361 $metakey = $metakeyselect;
39362
39363 if ( $metakeyinput)
39364 $metakey = $metakeyinput; // default
39365
39366 if ( in_array($metakey, $protected) )
39367 return false;
39368
39369 wp_cache_delete($post_ID, 'post_meta');
39370
39371 $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value ) VALUES (%s, %s, %s)", $post_ID, $metakey, $metavalue) );
39372 return $wpdb->insert_id;
39373 }
39374 return false;
39375 } // add_meta
39376
39377 /**
39378 * {@internal Missing Short Description}}
39379 *
39380 * @since unknown
39381 *
39382 * @param unknown_type $mid
39383 * @return unknown
39384 */
39385 function delete_meta( $mid ) {
39386 global $wpdb;
39387 $mid = (int) $mid;
39388
39389 $post_id = $wpdb->get_var( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_id = %d", $mid) );
39390 wp_cache_delete($post_id, 'post_meta');
39391
39392 return $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id = %d", $mid) );
39393 }
39394
39395 /**
39396 * Get a list of previously defined keys.
39397 *
39398 * @since unknown
39399 *
39400 * @return unknown
39401 */
39402 function get_meta_keys() {
39403 global $wpdb;
39404
39405 $keys = $wpdb->get_col( "
39406 SELECT meta_key
39407 FROM $wpdb->postmeta
39408 GROUP BY meta_key
39409 ORDER BY meta_key" );
39410
39411 return $keys;
39412 }
39413
39414 /**
39415 * {@internal Missing Short Description}}
39416 *
39417 * @since unknown
39418 *
39419 * @param unknown_type $mid
39420 * @return unknown
39421 */
39422 function get_post_meta_by_id( $mid ) {
39423 global $wpdb;
39424 $mid = (int) $mid;
39425
39426 $meta = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE meta_id = %d", $mid) );
39427 if ( is_serialized_string( $meta->meta_value ) )
39428 $meta->meta_value = maybe_unserialize( $meta->meta_value );
39429 return $meta;
39430 }
39431
39432 /**
39433 * {@internal Missing Short Description}}
39434 *
39435 * Some postmeta stuff.
39436 *
39437 * @since unknown
39438 *
39439 * @param unknown_type $postid
39440 * @return unknown
39441 */
39442 function has_meta( $postid ) {
39443 global $wpdb;
39444
39445 return $wpdb->get_results( $wpdb->prepare("SELECT meta_key, meta_value, meta_id, post_id
39446 FROM $wpdb->postmeta WHERE post_id = %d
39447 ORDER BY meta_key,meta_id", $postid), ARRAY_A );
39448
39449 }
39450
39451 /**
39452 * {@internal Missing Short Description}}
39453 *
39454 * @since unknown
39455 *
39456 * @param unknown_type $meta_id
39457 * @param unknown_type $meta_key
39458 * @param unknown_type $meta_value
39459 * @return unknown
39460 */
39461 function update_meta( $meta_id, $meta_key, $meta_value ) {
39462 global $wpdb;
39463
39464 $protected = array( '_wp_attached_file', '_wp_attachment_metadata', '_wp_old_slug', '_wp_page_template' );
39465
39466 if ( in_array($meta_key, $protected) )
39467 return false;
39468
39469 $post_id = $wpdb->get_var( $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_id = %d", $meta_id) );
39470 wp_cache_delete($post_id, 'post_meta');
39471
39472 $meta_value = maybe_serialize( stripslashes( $meta_value ));
39473 $meta_id = (int) $meta_id;
39474
39475 $data = compact( 'meta_key', 'meta_value' );
39476 $where = compact( 'meta_id' );
39477
39478 return $wpdb->update( $wpdb->postmeta, $data, $where );
39479 }
39480
39481 //
39482 // Private
39483 //
39484
39485 /**
39486 * Replace hrefs of attachment anchors with up-to-date permalinks.
39487 *
39488 * @since unknown
39489 * @access private
39490 *
39491 * @param unknown_type $post_ID
39492 * @return unknown
39493 */
39494 function _fix_attachment_links( $post_ID ) {
39495
39496 $post = & get_post( $post_ID, ARRAY_A );
39497
39498 $search = "#<a[^>]+rel=('|\")[^'\"]*attachment[^>]*>#ie";
39499
39500 // See if we have any rel="attachment" links
39501 if ( 0 == preg_match_all( $search, $post['post_content'], $anchor_matches, PREG_PATTERN_ORDER ) )
39502 return;
39503
39504 $i = 0;
39505 $search = "#[\s]+rel=(\"|')(.*?)wp-att-(\d+)\\1#i";
39506 foreach ( $anchor_matches[0] as $anchor ) {
39507 if ( 0 == preg_match( $search, $anchor, $id_matches ) )
39508 continue;
39509
39510 $id = (int) $id_matches[3];
39511
39512 // While we have the attachment ID, let's adopt any orphans.
39513 $attachment = & get_post( $id, ARRAY_A );
39514 if ( ! empty( $attachment) && ! is_object( get_post( $attachment['post_parent'] ) ) ) {
39515 $attachment['post_parent'] = $post_ID;
39516 // Escape data pulled from DB.
39517 $attachment = add_magic_quotes( $attachment);
39518 wp_update_post( $attachment);
39519 }
39520
39521 $post_search[$i] = $anchor;
39522 $post_replace[$i] = preg_replace( "#href=(\"|')[^'\"]*\\1#e", "stripslashes( 'href=\\1' ).get_attachment_link( $id ).stripslashes( '\\1' )", $anchor );
39523 ++$i;
39524 }
39525
39526 $post['post_content'] = str_replace( $post_search, $post_replace, $post['post_content'] );
39527
39528 // Escape data pulled from DB.
39529 $post = add_magic_quotes( $post);
39530
39531 return wp_update_post( $post);
39532 }
39533
39534 /**
39535 * Move child posts to a new parent.
39536 *
39537 * @since unknown
39538 * @access private
39539 *
39540 * @param unknown_type $old_ID
39541 * @param unknown_type $new_ID
39542 * @return unknown
39543 */
39544 function _relocate_children( $old_ID, $new_ID ) {
39545 global $wpdb;
39546 $old_ID = (int) $old_ID;
39547 $new_ID = (int) $new_ID;
39548 return $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_parent = %d WHERE post_parent = %d", $new_ID, $old_ID) );
39549 }
39550
39551 /**
39552 * {@internal Missing Short Description}}
39553 *
39554 * @since unknown
39555 *
39556 * @param unknown_type $type
39557 * @return unknown
39558 */
39559 function get_available_post_statuses($type = 'post') {
39560 $stati = wp_count_posts($type);
39561
39562 return array_keys(get_object_vars($stati));
39563 }
39564
39565 /**
39566 * {@internal Missing Short Description}}
39567 *
39568 * @since unknown
39569 *
39570 * @param unknown_type $q
39571 * @return unknown
39572 */
39573 function wp_edit_posts_query( $q = false ) {
39574 if ( false === $q )
39575 $q = $_GET;
39576 $q['m'] = isset($q['m']) ? (int) $q['m'] : 0;
39577 $q['cat'] = isset($q['cat']) ? (int) $q['cat'] : 0;
39578 $post_stati = array( // array( adj, noun )
39579 'publish' => array(__('Published'), __('Published posts'), __ngettext_noop('Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>')),
39580 'future' => array(__('Scheduled'), __('Scheduled posts'), __ngettext_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>')),
39581 'pending' => array(__('Pending Review'), __('Pending posts'), __ngettext_noop('Pending Review <span class="count">(%s)</span>', 'Pending Review <span class="count">(%s)</span>')),
39582 'draft' => array(__('Draft'), _c('Drafts|manage posts header'), __ngettext_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>')),
39583 'private' => array(__('Private'), __('Private posts'), __ngettext_noop('Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>')),
39584 );
39585
39586 $post_stati = apply_filters('post_stati', $post_stati);
39587
39588 $avail_post_stati = get_available_post_statuses('post');
39589
39590 $post_status_q = '';
39591 if ( isset($q['post_status']) && in_array( $q['post_status'], array_keys($post_stati) ) ) {
39592 $post_status_q = '&post_status=' . $q['post_status'];
39593 $post_status_q .= '&perm=readable';
39594 }
39595
39596 if ( isset($q['post_status']) && 'pending' === $q['post_status'] ) {
39597 $order = 'ASC';
39598 $orderby = 'modified';
39599 } elseif ( isset($q['post_status']) && 'draft' === $q['post_status'] ) {
39600 $order = 'DESC';
39601 $orderby = 'modified';
39602 } else {
39603 $order = 'DESC';
39604 $orderby = 'date';
39605 }
39606
39607 wp("post_type=post&what_to_show=posts$post_status_q&posts_per_page=15&order=$order&orderby=$orderby");
39608
39609 return array($post_stati, $avail_post_stati);
39610 }
39611
39612 /**
39613 * {@internal Missing Short Description}}
39614 *
39615 * @since unknown
39616 *
39617 * @param unknown_type $type
39618 * @return unknown
39619 */
39620 function get_available_post_mime_types($type = 'attachment') {
39621 global $wpdb;
39622
39623 $types = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT post_mime_type FROM $wpdb->posts WHERE post_type = %s", $type));
39624 return $types;
39625 }
39626
39627 /**
39628 * {@internal Missing Short Description}}
39629 *
39630 * @since unknown
39631 *
39632 * @param unknown_type $q
39633 * @return unknown
39634 */
39635 function wp_edit_attachments_query( $q = false ) {
39636 if ( false === $q )
39637 $q = $_GET;
39638
39639 $q['m'] = isset( $q['m'] ) ? (int) $q['m'] : 0;
39640 $q['cat'] = isset( $q['cat'] ) ? (int) $q['cat'] : 0;
39641 $q['post_type'] = 'attachment';
39642 $q['post_status'] = 'any';
39643 $q['posts_per_page'] = 15;
39644 $post_mime_types = array( // array( adj, noun )
39645 'image' => array(__('Images'), __('Manage Images'), __ngettext_noop('Image <span class="count">(%s)</span>', 'Images <span class="count">(%s)</span>')),
39646 'audio' => array(__('Audio'), __('Manage Audio'), __ngettext_noop('Audio <span class="count">(%s)</span>', 'Audio <span class="count">(%s)</span>')),
39647 'video' => array(__('Video'), __('Manage Video'), __ngettext_noop('Video <span class="count">(%s)</span>', 'Video <span class="count">(%s)</span>')),
39648 );
39649 $post_mime_types = apply_filters('post_mime_types', $post_mime_types);
39650
39651 $avail_post_mime_types = get_available_post_mime_types('attachment');
39652
39653 if ( isset($q['post_mime_type']) && !array_intersect( (array) $q['post_mime_type'], array_keys($post_mime_types) ) )
39654 unset($q['post_mime_type']);
39655
39656 wp($q);
39657
39658 return array($post_mime_types, $avail_post_mime_types);
39659 }
39660
39661 /**
39662 * {@internal Missing Short Description}}
39663 *
39664 * @since unknown
39665 *
39666 * @param unknown_type $id
39667 * @param unknown_type $page
39668 * @return unknown
39669 */
39670 function postbox_classes( $id, $page ) {
39671 if ( isset( $_GET['edit'] ) && $_GET['edit'] == $id )
39672 return '';
39673 $current_user = wp_get_current_user();
39674 if ( $closed = get_user_option('closedpostboxes_'.$page, 0, false ) ) {
39675 if ( !is_array( $closed ) ) return '';
39676 return in_array( $id, $closed )? 'if-js-closed' : '';
39677 } else {
39678 return '';
39679 }
39680 }
39681
39682 /**
39683 * {@internal Missing Short Description}}
39684 *
39685 * @since unknown
39686 *
39687 * @param unknown_type $id
39688 * @param unknown_type $title
39689 * @param unknown_type $name
39690 * @return unknown
39691 */
39692 function get_sample_permalink($id, $title=null, $name = null) {
39693 $post = &get_post($id);
39694 if (!$post->ID) {
39695 return array('', '');
39696 }
39697 $original_status = $post->post_status;
39698 $original_date = $post->post_date;
39699 $original_name = $post->post_name;
39700
39701 // Hack: get_permalink would return ugly permalink for
39702 // drafts, so we will fake, that our post is published
39703 if (in_array($post->post_status, array('draft', 'pending'))) {
39704 $post->post_status = 'publish';
39705 $post->post_name = sanitize_title($post->post_name? $post->post_name : $post->post_title, $post->ID);
39706 }
39707
39708 // If the user wants to set a new name -- override the current one
39709 // Note: if empty name is supplied -- use the title instead, see #6072
39710 if (!is_null($name)) {
39711 $post->post_name = sanitize_title($name? $name : $title, $post->ID);
39712 }
39713
39714 $permalink = get_permalink($post, true);
39715
39716 // Handle page hierarchy
39717 if ( 'page' == $post->post_type ) {
39718 $uri = get_page_uri($post->ID);
39719 $uri = untrailingslashit($uri);
39720 $uri = strrev( stristr( strrev( $uri ), '/' ) );
39721 $uri = untrailingslashit($uri);
39722 if ( !empty($uri) )
39723 $uri .='/';
39724 $permalink = str_replace('%pagename%', "${uri}%pagename%", $permalink);
39725 }
39726
39727 $permalink = array($permalink, apply_filters('editable_slug', $post->post_name));
39728 $post->post_status = $original_status;
39729 $post->post_date = $original_date;
39730 $post->post_name = $original_name;
39731 return $permalink;
39732 }
39733
39734 /**
39735 * {@internal Missing Short Description}}
39736 *
39737 * @since unknown
39738 *
39739 * @param unknown_type $id
39740 * @param unknown_type $new_title
39741 * @param unknown_type $new_slug
39742 * @return unknown
39743 */
39744 function get_sample_permalink_html($id, $new_title=null, $new_slug=null) {
39745 $post = &get_post($id);
39746 list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
39747 if (false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%')) {
39748 return '';
39749 }
39750 $title = __('Click to edit this part of the permalink');
39751 if (function_exists('mb_strlen')) {
39752 if (mb_strlen($post_name) > 30) {
39753 $post_name_abridged = mb_substr($post_name, 0, 14). '…' . mb_substr($post_name, -14);
39754 } else {
39755 $post_name_abridged = $post_name;
39756 }
39757 } else {
39758 if (strlen($post_name) > 30) {
39759 $post_name_abridged = substr($post_name, 0, 14). '…' . substr($post_name, -14);
39760 } else {
39761 $post_name_abridged = $post_name;
39762 }
39763 }
39764 $post_name_html = '<span id="editable-post-name" title="'.$title.'">'.$post_name_abridged.'</span><span id="editable-post-name-full">'.$post_name.'</span>';
39765 $display_link = str_replace(array('%pagename%','%postname%'), $post_name_html, $permalink);
39766 $return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink">' . $display_link . "</span>\n";
39767 $return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug button" onclick="edit_permalink(' . $id . '); return false;">' . __('Edit') . "</a></span>\n";
39768 return $return;
39769 }
39770
39771 /**
39772 * {@internal Missing Short Description}}
39773 *
39774 * @since unknown
39775 *
39776 * @param unknown_type $post_id
39777 * @return bool|int False: not locked or locked by current user. Int: user ID of user with lock.
39778 */
39779 function wp_check_post_lock( $post_id ) {
39780 global $current_user;
39781
39782 if ( !$post = get_post( $post_id ) )
39783 return false;
39784
39785 $lock = get_post_meta( $post->ID, '_edit_lock', true );
39786 $last = get_post_meta( $post->ID, '_edit_last', true );
39787
39788 $time_window = apply_filters( 'wp_check_post_lock_window', AUTOSAVE_INTERVAL * 2 );
39789
39790 if ( $lock && $lock > time() - $time_window && $last != $current_user->ID )
39791 return $last;
39792 return false;
39793 }
39794
39795 /**
39796 * {@internal Missing Short Description}}
39797 *
39798 * @since unknown
39799 *
39800 * @param unknown_type $post_id
39801 * @return unknown
39802 */
39803 function wp_set_post_lock( $post_id ) {
39804 global $current_user;
39805 if ( !$post = get_post( $post_id ) )
39806 return false;
39807 if ( !$current_user || !$current_user->ID )
39808 return false;
39809
39810 $now = time();
39811
39812 if ( !add_post_meta( $post->ID, '_edit_lock', $now, true ) )
39813 update_post_meta( $post->ID, '_edit_lock', $now );
39814 if ( !add_post_meta( $post->ID, '_edit_last', $current_user->ID, true ) )
39815 update_post_meta( $post->ID, '_edit_last', $current_user->ID );
39816 }
39817
39818 /**
39819 * Creates autosave data for the specified post from $_POST data.
39820 *
39821 * @package WordPress
39822 * @subpackage Post_Revisions
39823 * @since 2.6.0
39824 *
39825 * @uses _wp_translate_postdata()
39826 * @uses _wp_post_revision_fields()
39827 */
39828 function wp_create_post_autosave( $post_id ) {
39829 $translated = _wp_translate_postdata( true );
39830 if ( is_wp_error( $translated ) )
39831 return $translated;
39832
39833 // Only store one autosave. If there is already an autosave, overwrite it.
39834 if ( $old_autosave = wp_get_post_autosave( $post_id ) ) {
39835 $new_autosave = _wp_post_revision_fields( $_POST, true );
39836 $new_autosave['ID'] = $old_autosave->ID;
39837 return wp_update_post( $new_autosave );
39838 }
39839
39840 // Otherwise create the new autosave as a special post revision
39841 return _wp_put_post_revision( $_POST, true );
39842 }
39843
39844 /**
39845 * Save draft or manually autosave for showing preview.
39846 *
39847 * @package WordPress
39848 * @since 2.7
39849 *
39850 * @uses wp_write_post()
39851 * @uses edit_post()
39852 * @uses get_post()
39853 * @uses current_user_can()
39854 * @uses wp_create_post_autosave()
39855 *
39856 * @return str URL to redirect to show the preview
39857 */
39858 function post_preview() {
39859
39860 $post_ID = (int) $_POST['post_ID'];
39861 if ( $post_ID < 1 )
39862 wp_die( __('Preview not available. Please save as a draft first.') );
39863
39864 if ( isset($_POST['catslist']) )
39865 $_POST['post_category'] = explode(",", $_POST['catslist']);
39866
39867 if ( isset($_POST['tags_input']) )
39868 $_POST['tags_input'] = explode(",", $_POST['tags_input']);
39869
39870 if ( $_POST['post_type'] == 'page' || empty($_POST['post_category']) )
39871 unset($_POST['post_category']);
39872
39873 $_POST['ID'] = $post_ID;
39874 $post = get_post($post_ID);
39875
39876 if ( 'page' == $post->post_type ) {
39877 if ( !current_user_can('edit_page', $post_ID) )
39878 wp_die(__('You are not allowed to edit this page.'));
39879 } else {
39880 if ( !current_user_can('edit_post', $post_ID) )
39881 wp_die(__('You are not allowed to edit this post.'));
39882 }
39883
39884 if ( 'draft' == $post->post_status ) {
39885 $id = edit_post();
39886 } else { // Non drafts are not overwritten. The autosave is stored in a special post revision.
39887 $id = wp_create_post_autosave( $post->ID );
39888 if ( ! is_wp_error($id) )
39889 $id = $post->ID;
39890 }
39891
39892 if ( is_wp_error($id) )
39893 wp_die( $id->get_error_message() );
39894
39895 if ( $_POST['post_status'] == 'draft' ) {
39896 $url = add_query_arg( 'preview', 'true', get_permalink($id) );
39897 } else {
39898 $nonce = wp_create_nonce('post_preview_' . $id);
39899 $url = add_query_arg( array( 'preview' => 'true', 'preview_id' => $id, 'preview_nonce' => $nonce ), get_permalink($id) );
39900 }
39901
39902 return $url;
39903 }
39904
39905 /**
39906 * Adds the TinyMCE editor used on the Write and Edit screens.
39907 *
39908 * Has option to output a trimmed down version used in Press This.
39909 *
39910 * @package WordPress
39911 * @since 2.7
39912 */
39913 function wp_tiny_mce( $teeny = false ) {
39914 if ( ! user_can_richedit() )
39915 return;
39916
39917 $baseurl = includes_url('js/tinymce');
39918
39919 $mce_css = $baseurl . '/wordpress.css';
39920 $mce_css = apply_filters('mce_css', $mce_css);
39921
39922 $mce_locale = ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) ); // only ISO 639-1
39923
39924 /*
39925 The following filter allows localization scripts to change the languages displayed in the spellchecker's drop-down menu.
39926 By default it uses Google's spellchecker API, but can be configured to use PSpell/ASpell if installed on the server.
39927 The + sign marks the default language. More information:
39928 http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/spellchecker
39929 */
39930 $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');
39931
39932 if ( $teeny ) {
39933 $plugins = apply_filters( 'teeny_mce_plugins', array('safari', 'inlinepopups', 'media', 'autosave', 'fullscreen') );
39934 $ext_plugins = '';
39935 } else {
39936 $plugins = array( 'safari', 'inlinepopups', 'autosave', 'spellchecker', 'paste', 'wordpress', 'media', 'fullscreen', 'wpeditimage', 'wpgallery' );
39937
39938 /*
39939 The following filter takes an associative array of external plugins for TinyMCE in the form 'plugin_name' => 'url'.
39940 It adds the plugin's name to TinyMCE's plugins init and the call to PluginManager to load the plugin.
39941 The url should be absolute and should include the js file name to be loaded. Example:
39942 array( 'myplugin' => 'http://my-site.com/wp-content/plugins/myfolder/mce_plugin.js' )
39943 If the plugin uses a button, it should be added with one of the "$mce_buttons" filters.
39944 */
39945 $mce_external_plugins = apply_filters('mce_external_plugins', array());
39946
39947 $ext_plugins = "\n";
39948 if ( ! empty($mce_external_plugins) ) {
39949
39950 /*
39951 The following filter loads external language files for TinyMCE plugins.
39952 It takes an associative array 'plugin_name' => 'path', where path is the
39953 include path to the file. The language file should follow the same format as
39954 /tinymce/langs/wp-langs.php and should define a variable $strings that
39955 holds all translated strings.
39956 When this filter is not used, the function will try to load {mce_locale}.js.
39957 If that is not found, en.js will be tried next.
39958 */
39959 $mce_external_languages = apply_filters('mce_external_languages', array());
39960
39961 $loaded_langs = array();
39962 $strings = '';
39963
39964 if ( ! empty($mce_external_languages) ) {
39965 foreach ( $mce_external_languages as $name => $path ) {
39966 if ( is_file($path) && is_readable($path) ) {
39967 include_once($path);
39968 $ext_plugins .= $strings;
39969 $loaded_langs[] = $name;
39970 }
39971 }
39972 }
39973
39974 foreach ( $mce_external_plugins as $name => $url ) {
39975
39976 if ( is_ssl() ) $url = str_replace('http://', 'https://', $url);
39977
39978 $plugins[] = '-' . $name;
39979
39980 $plugurl = dirname($url);
39981 $strings = $str1 = $str2 = '';
39982 if ( ! in_array($name, $loaded_langs) ) {
39983 $path = str_replace( WP_PLUGIN_URL, '', $plugurl );
39984 $path = WP_PLUGIN_DIR . $path . '/langs/';
39985
39986 if ( function_exists('realpath') )
39987 $path = trailingslashit( realpath($path) );
39988
39989 if ( is_file($path . $mce_locale . '.js') )
39990 $strings .= @file_get_contents($path . $mce_locale . '.js');
39991
39992 if ( is_file($path . $mce_locale . '_dlg.js') )
39993 $strings .= @file_get_contents($path . $mce_locale . '_dlg.js');
39994
39995 if ( 'en' != $mce_locale && empty($strings) ) {
39996 if ( is_file($path . 'en.js') ) {
39997 $str1 = @file_get_contents($path . 'en.js');
39998 $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str1, 1 );
39999 }
40000
40001 if ( is_file($path . 'en_dlg.js') ) {
40002 $str2 = @file_get_contents($path . 'en_dlg.js');
40003 $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str2, 1 );
40004 }
40005 }
40006
40007 if ( ! empty($strings) )
40008 $ext_plugins .= "\n" . $strings . "\n";
40009 }
40010
40011 $ext_plugins .= 'tinyMCEPreInit.load_ext("' . $plugurl . '", "' . $mce_locale . '");' . "\n";
40012 $ext_plugins .= 'tinymce.PluginManager.load("' . $name . '", "' . $url . '");' . "\n";
40013 }
40014 }
40015 }
40016
40017 $plugins = implode($plugins, ',');
40018
40019 if ( $teeny ) {
40020 $mce_buttons = apply_filters( 'teeny_mce_buttons', array('bold, italic, underline, blockquote, separator, strikethrough, bullist, numlist,justifyleft, justifycenter, justifyright, undo, redo, link, unlink, fullscreen') );
40021 $mce_buttons = implode($mce_buttons, ',');
40022 $mce_buttons_2 = $mce_buttons_3 = $mce_buttons_4 = '';
40023 } else {
40024 $mce_buttons = apply_filters('mce_buttons', array('bold', 'italic', 'strikethrough', '|', 'bullist', 'numlist', 'blockquote', '|', 'justifyleft', 'justifycenter', 'justifyright', '|', 'link', 'unlink', 'wp_more', '|', 'spellchecker', 'fullscreen', 'wp_adv' ));
40025 $mce_buttons = implode($mce_buttons, ',');
40026
40027 $mce_buttons_2 = apply_filters('mce_buttons_2', array('formatselect', 'underline', 'justifyfull', 'forecolor', '|', 'pastetext', 'pasteword', 'removeformat', '|', 'media', 'charmap', '|', 'outdent', 'indent', '|', 'undo', 'redo', 'wp_help' ));
40028 $mce_buttons_2 = implode($mce_buttons_2, ',');
40029
40030 $mce_buttons_3 = apply_filters('mce_buttons_3', array());
40031 $mce_buttons_3 = implode($mce_buttons_3, ',');
40032
40033 $mce_buttons_4 = apply_filters('mce_buttons_4', array());
40034 $mce_buttons_4 = implode($mce_buttons_4, ',');
40035 }
40036 $no_captions = ( apply_filters( 'disable_captions', '' ) ) ? true : false;
40037
40038 // TinyMCE init settings
40039 $initArray = array (
40040 'mode' => 'none',
40041 'onpageload' => 'switchEditors.edInit',
40042 'width' => '100%',
40043 'theme' => 'advanced',
40044 'skin' => 'wp_theme',
40045 'theme_advanced_buttons1' => "$mce_buttons",
40046 'theme_advanced_buttons2' => "$mce_buttons_2",
40047 'theme_advanced_buttons3' => "$mce_buttons_3",
40048 'theme_advanced_buttons4' => "$mce_buttons_4",
40049 'language' => "$mce_locale",
40050 'spellchecker_languages' => "$mce_spellchecker_languages",
40051 'theme_advanced_toolbar_location' => 'top',
40052 'theme_advanced_toolbar_align' => 'left',
40053 'theme_advanced_statusbar_location' => 'bottom',
40054 'theme_advanced_resizing' => true,
40055 'theme_advanced_resize_horizontal' => false,
40056 'dialog_type' => 'modal',
40057 'relative_urls' => false,
40058 'remove_script_host' => false,
40059 'convert_urls' => false,
40060 'apply_source_formatting' => false,
40061 'remove_linebreaks' => true,
40062 'paste_convert_middot_lists' => true,
40063 'paste_remove_spans' => true,
40064 'paste_remove_styles' => true,
40065 'gecko_spellcheck' => true,
40066 'entities' => '38,amp,60,lt,62,gt',
40067 'accessibility_focus' => true,
40068 'tab_focus' => ':prev,:next',
40069 'content_css' => "$mce_css",
40070 'save_callback' => 'switchEditors.saveCallback',
40071 'wpeditimage_disable_captions' => $no_captions,
40072 'plugins' => "$plugins"
40073 );
40074
40075 // For people who really REALLY know what they're doing with TinyMCE
40076 // You can modify initArray to add, remove, change elements of the config before tinyMCE.init
40077 // Setting "valid_elements", "invalid_elements" and "extended_valid_elements" can be done through "tiny_mce_before_init".
40078 // Best is to use the default cleanup by not specifying valid_elements, as TinyMCE contains full set of XHTML 1.0.
40079 if ( $teeny ) {
40080 $initArray = apply_filters('teeny_mce_before_init', $initArray);
40081 } else {
40082 $initArray = apply_filters('tiny_mce_before_init', $initArray);
40083 }
40084
40085 $language = $initArray['language'];
40086
40087 $ver = apply_filters('tiny_mce_version', '3101');
40088
40089 if ( 'en' != $language )
40090 include_once(ABSPATH . WPINC . '/js/tinymce/langs/wp-langs.php');
40091
40092 $mce_options = '';
40093 foreach ( $initArray as $k => $v )
40094 $mce_options .= $k . ':"' . $v . '", ';
40095
40096 $mce_options = rtrim( trim($mce_options), '\n\r,' ); ?>
40097
40098 <script type="text/javascript">
40099 /* <![CDATA[ */
40100 tinyMCEPreInit = {
40101 base : "<?php echo $baseurl; ?>",
40102 suffix : "",
40103 query : "ver=<?php echo $ver; ?>",
40104 mceInit : {<?php echo $mce_options; ?>},
40105
40106 go : function() {
40107 var t = this, sl = tinymce.ScriptLoader, ln = t.mceInit.language, th = t.mceInit.theme, pl = t.mceInit.plugins;
40108
40109 sl.markDone(t.base + '/langs/' + ln + '.js');
40110
40111 sl.markDone(t.base + '/themes/' + th + '/langs/' + ln + '.js');
40112 sl.markDone(t.base + '/themes/' + th + '/langs/' + ln + '_dlg.js');
40113
40114 tinymce.each(pl.split(','), function(n) {
40115 if (n && n.charAt(0) != '-') {
40116 sl.markDone(t.base + '/plugins/' + n + '/langs/' + ln + '.js');
40117 sl.markDone(t.base + '/plugins/' + n + '/langs/' + ln + '_dlg.js');
40118 }
40119 });
40120 },
40121
40122 load_ext : function(url,lang) {
40123 var sl = tinymce.ScriptLoader;
40124
40125 sl.markDone(url + '/langs/' + lang + '.js');
40126 sl.markDone(url + '/langs/' + lang + '_dlg.js');
40127 }
40128 };
40129 /* ]]> */
40130 </script>
40131 <script type="text/javascript" src="<?php echo $baseurl; ?>/tiny_mce.js?ver=<?php echo $ver; ?>"></script>
40132 <?php if ( 'en' != $language && isset($lang) ) { ?>
40133 <script type="text/javascript">
40134 <?php echo $lang; ?>
40135 </script>
40136 <?php } else { ?>
40137 <script type="text/javascript" src="<?php echo $baseurl; ?>/langs/wp-langs-en.js?ver=<?php echo $ver; ?>"></script>
40138 <?php } ?>
40139 <script type="text/javascript">
40140 <?php if ( $ext_plugins ) echo $ext_plugins; ?>
40141
40142 // Mark translations as done
40143 tinyMCEPreInit.go();
40144
40145 // Init
40146 tinyMCE.init(tinyMCEPreInit.mceInit);
40147 </script>
40148
40149 <?php
40150 }
40151 ?>