| 2 | | |
|---|
| 3 | | function write_post() { |
|---|
| 4 | | $result = wp_write_post(); |
|---|
| 5 | | if( is_wp_error( $result ) ) |
|---|
| 6 | | wp_die( $result->get_error_message() ); |
|---|
| 7 | | else |
|---|
| 8 | | return $result; |
|---|
| 9 | | } |
|---|
| 10 | | |
|---|
| 11 | | // Creates a new post from the "Write Post" form using $_POST information. |
|---|
| 12 | | function wp_write_post() { |
|---|
| 13 | | global $user_ID; |
|---|
| 14 | | |
|---|
| 15 | | if ( 'page' == $_POST['post_type'] ) { |
|---|
| 16 | | if ( !current_user_can( 'edit_pages' ) ) |
|---|
| 17 | | return new WP_Error( 'edit_pages', __( 'You are not allowed to create pages on this blog.' ) ); |
|---|
| 18 | | } else { |
|---|
| 19 | | if ( !current_user_can( 'edit_posts' ) ) |
|---|
| 20 | | return new WP_Error( 'edit_posts', __( 'You are not allowed to create posts or drafts on this blog.' ) ); |
|---|
| 21 | | } |
|---|
| 22 | | |
|---|
| 23 | | |
|---|
| 24 | | // Check for autosave collisions |
|---|
| 25 | | $temp_id = false; |
|---|
| 26 | | if ( isset($_POST['temp_ID']) ) { |
|---|
| 27 | | $temp_id = (int) $_POST['temp_ID']; |
|---|
| 28 | | if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) ) |
|---|
| 29 | | $draft_ids = array(); |
|---|
| 30 | | foreach ( $draft_ids as $temp => $real ) |
|---|
| 31 | | if ( time() + $temp > 86400 ) // 1 day: $temp is equal to -1 * time( then ) |
|---|
| 32 | | unset($draft_ids[$temp]); |
|---|
| 33 | | |
|---|
| 34 | | if ( isset($draft_ids[$temp_id]) ) { // Edit, don't write |
|---|
| 35 | | $_POST['post_ID'] = $draft_ids[$temp_id]; |
|---|
| 36 | | unset($_POST['temp_ID']); |
|---|
| 37 | | update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids ); |
|---|
| 38 | | return edit_post(); |
|---|
| 39 | | } |
|---|
| 40 | | } |
|---|
| 41 | | |
|---|
| 42 | | // Rename. |
|---|
| 43 | | $_POST['post_content'] = $_POST['content']; |
|---|
| 44 | | $_POST['post_excerpt'] = $_POST['excerpt']; |
|---|
| 45 | | $_POST['post_parent'] = $_POST['parent_id']; |
|---|
| 46 | | $_POST['to_ping'] = $_POST['trackback_url']; |
|---|
| 47 | | |
|---|
| 48 | | if (!empty ( $_POST['post_author_override'] ) ) { |
|---|
| 49 | | $_POST['post_author'] = (int) $_POST['post_author_override']; |
|---|
| 50 | | } else { |
|---|
| 51 | | if (!empty ( $_POST['post_author'] ) ) { |
|---|
| 52 | | $_POST['post_author'] = (int) $_POST['post_author']; |
|---|
| 53 | | } else { |
|---|
| 54 | | $_POST['post_author'] = (int) $_POST['user_ID']; |
|---|
| 55 | | } |
|---|
| 56 | | |
|---|
| 57 | | } |
|---|
| 58 | | |
|---|
| 59 | | if ( $_POST['post_author'] != $_POST['user_ID'] ) { |
|---|
| 60 | | if ( 'page' == $_POST['post_type'] ) { |
|---|
| 61 | | if ( !current_user_can( 'edit_others_pages' ) ) |
|---|
| 62 | | return new WP_Error( 'edit_others_pages', __( 'You are not allowed to create pages as this user.' ) ); |
|---|
| 63 | | } else { |
|---|
| 64 | | if ( !current_user_can( 'edit_others_posts' ) ) |
|---|
| 65 | | return new WP_Error( 'edit_others_posts', __( 'You are not allowed to post as this user.' ) ); |
|---|
| 66 | | |
|---|
| 67 | | } |
|---|
| 68 | | } |
|---|
| 69 | | |
|---|
| 70 | | // What to do based on which button they pressed |
|---|
| 71 | | if ('' != $_POST['saveasdraft'] ) |
|---|
| 72 | | $_POST['post_status'] = 'draft'; |
|---|
| 73 | | if ('' != $_POST['saveasprivate'] ) |
|---|
| 74 | | $_POST['post_status'] = 'private'; |
|---|
| 75 | | if ('' != $_POST['publish'] ) |
|---|
| 76 | | $_POST['post_status'] = 'publish'; |
|---|
| 77 | | if ('' != $_POST['advanced'] ) |
|---|
| 78 | | $_POST['post_status'] = 'draft'; |
|---|
| 79 | | |
|---|
| 80 | | if ( 'page' == $_POST['post_type'] ) { |
|---|
| 81 | | if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_pages' ) ) |
|---|
| 82 | | $_POST['post_status'] = 'draft'; |
|---|
| 83 | | } else { |
|---|
| 84 | | if ('publish' == $_POST['post_status'] && !current_user_can( 'publish_posts' ) ) |
|---|
| 85 | | $_POST['post_status'] = 'draft'; |
|---|
| 86 | | } |
|---|
| 87 | | |
|---|
| 88 | | if (!isset( $_POST['comment_status'] )) |
|---|
| 89 | | $_POST['comment_status'] = 'closed'; |
|---|
| 90 | | |
|---|
| 91 | | if (!isset( $_POST['ping_status'] )) |
|---|
| 92 | | $_POST['ping_status'] = 'closed'; |
|---|
| 93 | | |
|---|
| 94 | | if (!empty ( $_POST['edit_date'] ) ) { |
|---|
| 95 | | $aa = $_POST['aa']; |
|---|
| 96 | | $mm = $_POST['mm']; |
|---|
| 97 | | $jj = $_POST['jj']; |
|---|
| 98 | | $hh = $_POST['hh']; |
|---|
| 99 | | $mn = $_POST['mn']; |
|---|
| 100 | | $ss = $_POST['ss']; |
|---|
| 101 | | $jj = ($jj > 31 ) ? 31 : $jj; |
|---|
| 102 | | $hh = ($hh > 23 ) ? $hh -24 : $hh; |
|---|
| 103 | | $mn = ($mn > 59 ) ? $mn -60 : $mn; |
|---|
| 104 | | $ss = ($ss > 59 ) ? $ss -60 : $ss; |
|---|
| 105 | | $_POST['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss ); |
|---|
| 106 | | $_POST['post_date_gmt'] = get_gmt_from_date( $_POST['post_date'] ); |
|---|
| 107 | | } |
|---|
| 108 | | |
|---|
| 109 | | unset($_POST['no_filter']); |
|---|
| 110 | | |
|---|
| 111 | | // Create the post. |
|---|
| 112 | | $post_ID = wp_insert_post( $_POST ); |
|---|
| 113 | | |
|---|
| 114 | | add_meta( $post_ID ); |
|---|
| 115 | | |
|---|
| 116 | | // Reunite any orphaned attachments with their parent |
|---|
| 117 | | if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) ) |
|---|
| 118 | | $draft_ids = array(); |
|---|
| 119 | | if ( $draft_temp_id = (int) array_search( $post_ID, $draft_ids ) ) |
|---|
| 120 | | relocate_children( $draft_temp_id, $post_ID ); |
|---|
| 121 | | if ( $temp_id && $temp_id != $draft_temp_id ) |
|---|
| 122 | | relocate_children( $temp_id, $post_ID ); |
|---|
| 123 | | |
|---|
| 124 | | // Update autosave collision detection |
|---|
| 125 | | if ( $temp_id ) { |
|---|
| 126 | | $draft_ids[$temp_id] = $post_ID; |
|---|
| 127 | | update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids ); |
|---|
| 128 | | } |
|---|
| 129 | | |
|---|
| 130 | | // Now that we have an ID we can fix any attachment anchor hrefs |
|---|
| 131 | | fix_attachment_links( $post_ID ); |
|---|
| 132 | | |
|---|
| 133 | | return $post_ID; |
|---|
| 134 | | } |
|---|
| 135 | | |
|---|
| 136 | | // Move child posts to a new parent |
|---|
| 137 | | function relocate_children( $old_ID, $new_ID ) { |
|---|
| 138 | | global $wpdb; |
|---|
| 139 | | $old_ID = (int) $old_ID; |
|---|
| 140 | | $new_ID = (int) $new_ID; |
|---|
| 141 | | return $wpdb->query( "UPDATE $wpdb->posts SET post_parent = $new_ID WHERE post_parent = $old_ID" ); |
|---|
| 142 | | } |
|---|
| 143 | | |
|---|
| 144 | | // Replace hrefs of attachment anchors with up-to-date permalinks. |
|---|
| 145 | | function fix_attachment_links( $post_ID ) { |
|---|
| 146 | | global $wp_rewrite; |
|---|
| 147 | | |
|---|
| 148 | | $post = & get_post( $post_ID, ARRAY_A ); |
|---|
| 149 | | |
|---|
| 150 | | $search = "#<a[^>]+rel=('|\")[^'\"]*attachment[^>]*>#ie"; |
|---|
| 151 | | |
|---|
| 152 | | // See if we have any rel="attachment" links |
|---|
| 153 | | if ( 0 == preg_match_all( $search, $post['post_content'], $anchor_matches, PREG_PATTERN_ORDER ) ) |
|---|
| 154 | | return; |
|---|
| 155 | | |
|---|
| 156 | | $i = 0; |
|---|
| 157 | | $search = "#[\s]+rel=(\"|')(.*?)wp-att-(\d+)\\1#i"; |
|---|
| 158 | | foreach ( $anchor_matches[0] as $anchor ) { |
|---|
| 159 | | if ( 0 == preg_match( $search, $anchor, $id_matches ) ) |
|---|
| 160 | | continue; |
|---|
| 161 | | |
|---|
| 162 | | $id = (int) $id_matches[3]; |
|---|
| 163 | | |
|---|
| 164 | | // While we have the attachment ID, let's adopt any orphans. |
|---|
| 165 | | $attachment = & get_post( $id, ARRAY_A ); |
|---|
| 166 | | if ( ! empty( $attachment) && ! is_object( get_post( $attachment['post_parent'] ) ) ) { |
|---|
| 167 | | $attachment['post_parent'] = $post_ID; |
|---|
| 168 | | // Escape data pulled from DB. |
|---|
| 169 | | $attachment = add_magic_quotes( $attachment); |
|---|
| 170 | | wp_update_post( $attachment); |
|---|
| 171 | | } |
|---|
| 172 | | |
|---|
| 173 | | $post_search[$i] = $anchor; |
|---|
| 174 | | $post_replace[$i] = preg_replace( "#href=(\"|')[^'\"]*\\1#e", "stripslashes( 'href=\\1' ).get_attachment_link( $id ).stripslashes( '\\1' )", $anchor ); |
|---|
| 175 | | ++$i; |
|---|
| 176 | | } |
|---|
| 177 | | |
|---|
| 178 | | $post['post_content'] = str_replace( $post_search, $post_replace, $post['post_content'] ); |
|---|
| 179 | | |
|---|
| 180 | | // Escape data pulled from DB. |
|---|
| 181 | | $post = add_magic_quotes( $post); |
|---|
| 182 | | |
|---|
| 183 | | return wp_update_post( $post); |
|---|
| 184 | | } |
|---|
| 185 | | |
|---|
| 186 | | // Update an existing post with values provided in $_POST. |
|---|
| 187 | | function edit_post() { |
|---|
| 188 | | global $user_ID; |
|---|
| 189 | | |
|---|
| 190 | | $post_ID = (int) $_POST['post_ID']; |
|---|
| 191 | | |
|---|
| 192 | | if ( 'page' == $_POST['post_type'] ) { |
|---|
| 193 | | if ( !current_user_can( 'edit_page', $post_ID ) ) |
|---|
| 194 | | wp_die( __('You are not allowed to edit this page.' )); |
|---|
| 195 | | } else { |
|---|
| 196 | | if ( !current_user_can( 'edit_post', $post_ID ) ) |
|---|
| 197 | | wp_die( __('You are not allowed to edit this post.' )); |
|---|
| 198 | | } |
|---|
| 199 | | |
|---|
| 200 | | // Autosave shouldn't save too soon after a real save |
|---|
| 201 | | if ( 'autosave' == $_POST['action'] ) { |
|---|
| 202 | | $post =& get_post( $post_ID ); |
|---|
| 203 | | $now = time(); |
|---|
| 204 | | $then = strtotime($post->post_date_gmt . ' +0000'); |
|---|
| 205 | | // Keep autosave_interval in sync with autosave-js.php. |
|---|
| 206 | | $delta = apply_filters( 'autosave_interval', 120 ) / 2; |
|---|
| 207 | | if ( ($now - $then) < $delta ) |
|---|
| 208 | | return $post_ID; |
|---|
| 209 | | } |
|---|
| 210 | | |
|---|
| 211 | | // Rename. |
|---|
| 212 | | $_POST['ID'] = (int) $_POST['post_ID']; |
|---|
| 213 | | $_POST['post_content'] = $_POST['content']; |
|---|
| 214 | | $_POST['post_excerpt'] = $_POST['excerpt']; |
|---|
| 215 | | $_POST['post_parent'] = $_POST['parent_id']; |
|---|
| 216 | | $_POST['to_ping'] = $_POST['trackback_url']; |
|---|
| 217 | | |
|---|
| 218 | | if (!empty ( $_POST['post_author_override'] ) ) { |
|---|
| 219 | | $_POST['post_author'] = (int) $_POST['post_author_override']; |
|---|
| 220 | | } else |
|---|
| 221 | | if (!empty ( $_POST['post_author'] ) ) { |
|---|
| 222 | | $_POST['post_author'] = (int) $_POST['post_author']; |
|---|
| 223 | | } else { |
|---|
| 224 | | $_POST['post_author'] = (int) $_POST['user_ID']; |
|---|
| 225 | | } |
|---|
| 226 | | |
|---|
| 227 | | if ( $_POST['post_author'] != $_POST['user_ID'] ) { |
|---|
| 228 | | if ( 'page' == $_POST['post_type'] ) { |
|---|
| 229 | | if ( !current_user_can( 'edit_others_pages' ) ) |
|---|
| 230 | | wp_die( __('You are not allowed to edit pages as this user.' )); |
|---|
| 231 | | } else { |
|---|
| 232 | | if ( !current_user_can( 'edit_others_posts' ) ) |
|---|
| 233 | | wp_die( __('You are not allowed to edit posts as this user.' )); |
|---|
| 234 | | |
|---|
| 235 | | } |
|---|
| 236 | | } |
|---|
| 237 | | |
|---|
| 238 | | // What to do based on which button they pressed |
|---|
| 239 | | if ('' != $_POST['saveasdraft'] ) |
|---|
| 240 | | $_POST['post_status'] = 'draft'; |
|---|
| 241 | | if ('' != $_POST['saveasprivate'] ) |
|---|
| 242 | | $_POST['post_status'] = 'private'; |
|---|
| 243 | | if ('' != $_POST['publish'] ) |
|---|
| 244 | | $_POST['post_status'] = 'publish'; |
|---|
| 245 | | if ('' != $_POST['advanced'] ) |
|---|
| 246 | | $_POST['post_status'] = 'draft'; |
|---|
| 247 | | |
|---|
| 248 | | if ( 'page' == $_POST['post_type'] ) { |
|---|
| 249 | | if ('publish' == $_POST['post_status'] && !current_user_can( 'edit_published_pages' )) |
|---|
| 250 | | $_POST['post_status'] = 'draft'; |
|---|
| 251 | | } else { |
|---|
| 252 | | if ('publish' == $_POST['post_status'] && !current_user_can( 'edit_published_posts' )) |
|---|
| 253 | | $_POST['post_status'] = 'draft'; |
|---|
| 254 | | } |
|---|
| 255 | | |
|---|
| 256 | | if (!isset( $_POST['comment_status'] )) |
|---|
| 257 | | $_POST['comment_status'] = 'closed'; |
|---|
| 258 | | |
|---|
| 259 | | if (!isset( $_POST['ping_status'] )) |
|---|
| 260 | | $_POST['ping_status'] = 'closed'; |
|---|
| 261 | | |
|---|
| 262 | | if (!empty ( $_POST['edit_date'] ) ) { |
|---|
| 263 | | $aa = $_POST['aa']; |
|---|
| 264 | | $mm = $_POST['mm']; |
|---|
| 265 | | $jj = $_POST['jj']; |
|---|
| 266 | | $hh = $_POST['hh']; |
|---|
| 267 | | $mn = $_POST['mn']; |
|---|
| 268 | | $ss = $_POST['ss']; |
|---|
| 269 | | $jj = ($jj > 31 ) ? 31 : $jj; |
|---|
| 270 | | $hh = ($hh > 23 ) ? $hh -24 : $hh; |
|---|
| 271 | | $mn = ($mn > 59 ) ? $mn -60 : $mn; |
|---|
| 272 | | $ss = ($ss > 59 ) ? $ss -60 : $ss; |
|---|
| 273 | | $_POST['post_date'] = "$aa-$mm-$jj $hh:$mn:$ss"; |
|---|
| 274 | | $_POST['post_date_gmt'] = get_gmt_from_date( "$aa-$mm-$jj $hh:$mn:$ss" ); |
|---|
| 275 | | } |
|---|
| 276 | | |
|---|
| 277 | | // Meta Stuff |
|---|
| 278 | | if ( $_POST['meta'] ) { |
|---|
| 279 | | foreach ( $_POST['meta'] as $key => $value ) |
|---|
| 280 | | update_meta( $key, $value['key'], $value['value'] ); |
|---|
| 281 | | } |
|---|
| 282 | | |
|---|
| 283 | | if ( $_POST['deletemeta'] ) { |
|---|
| 284 | | foreach ( $_POST['deletemeta'] as $key => $value ) |
|---|
| 285 | | delete_meta( $key ); |
|---|
| 286 | | } |
|---|
| 287 | | |
|---|
| 288 | | unset($_POST['no_filter']); |
|---|
| 289 | | |
|---|
| 290 | | add_meta( $post_ID ); |
|---|
| 291 | | |
|---|
| 292 | | wp_update_post( $_POST ); |
|---|
| 293 | | |
|---|
| 294 | | // Reunite any orphaned attachments with their parent |
|---|
| 295 | | if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) ) |
|---|
| 296 | | $draft_ids = array(); |
|---|
| 297 | | if ( $draft_temp_id = (int) array_search( $post_ID, $draft_ids ) ) |
|---|
| 298 | | relocate_children( $draft_temp_id, $post_ID ); |
|---|
| 299 | | |
|---|
| 300 | | // Now that we have an ID we can fix any attachment anchor hrefs |
|---|
| 301 | | fix_attachment_links( $post_ID ); |
|---|
| 302 | | |
|---|
| 303 | | return $post_ID; |
|---|
| 304 | | } |
|---|
| 305 | | |
|---|
| 306 | | function edit_comment() { |
|---|
| 307 | | global $user_ID; |
|---|
| 308 | | |
|---|
| 309 | | $comment_ID = (int) $_POST['comment_ID']; |
|---|
| 310 | | $comment_post_ID = (int) $_POST['comment_post_ID']; |
|---|
| 311 | | |
|---|
| 312 | | if (!current_user_can( 'edit_post', $comment_post_ID )) |
|---|
| 313 | | wp_die( __('You are not allowed to edit comments on this post, so you cannot edit this comment.' )); |
|---|
| 314 | | |
|---|
| 315 | | $_POST['comment_author'] = $_POST['newcomment_author']; |
|---|
| 316 | | $_POST['comment_author_email'] = $_POST['newcomment_author_email']; |
|---|
| 317 | | $_POST['comment_author_url'] = $_POST['newcomment_author_url']; |
|---|
| 318 | | $_POST['comment_approved'] = $_POST['comment_status']; |
|---|
| 319 | | $_POST['comment_content'] = $_POST['content']; |
|---|
| 320 | | $_POST['comment_ID'] = (int) $_POST['comment_ID']; |
|---|
| 321 | | |
|---|
| 322 | | if (!empty ( $_POST['edit_date'] ) ) { |
|---|
| 323 | | $aa = $_POST['aa']; |
|---|
| 324 | | $mm = $_POST['mm']; |
|---|
| 325 | | $jj = $_POST['jj']; |
|---|
| 326 | | $hh = $_POST['hh']; |
|---|
| 327 | | $mn = $_POST['mn']; |
|---|
| 328 | | $ss = $_POST['ss']; |
|---|
| 329 | | $jj = ($jj > 31 ) ? 31 : $jj; |
|---|
| 330 | | $hh = ($hh > 23 ) ? $hh -24 : $hh; |
|---|
| 331 | | $mn = ($mn > 59 ) ? $mn -60 : $mn; |
|---|
| 332 | | $ss = ($ss > 59 ) ? $ss -60 : $ss; |
|---|
| 333 | | $_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss"; |
|---|
| 334 | | } |
|---|
| 335 | | |
|---|
| 336 | | wp_update_comment( $_POST); |
|---|
| 337 | | } |
|---|
| 338 | | |
|---|
| 339 | | // Get an existing post and format it for editing. |
|---|
| 340 | | function get_post_to_edit( $id ) { |
|---|
| 341 | | |
|---|
| 342 | | $post = get_post( $id ); |
|---|
| 343 | | |
|---|
| 344 | | $post->post_content = format_to_edit( $post->post_content, user_can_richedit() ); |
|---|
| 345 | | $post->post_content = apply_filters( 'content_edit_pre', $post->post_content); |
|---|
| 346 | | |
|---|
| 347 | | $post->post_excerpt = format_to_edit( $post->post_excerpt); |
|---|
| 348 | | $post->post_excerpt = apply_filters( 'excerpt_edit_pre', $post->post_excerpt); |
|---|
| 349 | | |
|---|
| 350 | | $post->post_title = format_to_edit( $post->post_title ); |
|---|
| 351 | | $post->post_title = apply_filters( 'title_edit_pre', $post->post_title ); |
|---|
| 352 | | |
|---|
| 353 | | $post->post_password = format_to_edit( $post->post_password ); |
|---|
| 354 | | |
|---|
| 355 | | $post->menu_order = (int) $post->menu_order; |
|---|
| 356 | | |
|---|
| 357 | | if ( $post->post_type == 'page' ) |
|---|
| 358 | | $post->page_template = get_post_meta( $id, '_wp_page_template', true ); |
|---|
| 359 | | |
|---|
| 360 | | return $post; |
|---|
| 361 | | } |
|---|
| 362 | | |
|---|
| 363 | | // Default post information to use when populating the "Write Post" form. |
|---|
| 364 | | function get_default_post_to_edit() { |
|---|
| 365 | | if ( !empty( $_REQUEST['post_title'] ) ) |
|---|
| 366 | | $post_title = wp_specialchars( stripslashes( $_REQUEST['post_title'] )); |
|---|
| 367 | | else if ( !empty( $_REQUEST['popuptitle'] ) ) { |
|---|
| 368 | | $post_title = wp_specialchars( stripslashes( $_REQUEST['popuptitle'] )); |
|---|
| 369 | | $post_title = funky_javascript_fix( $post_title ); |
|---|
| 370 | | } else { |
|---|
| 371 | | $post_title = ''; |
|---|
| 372 | | } |
|---|
| 373 | | |
|---|
| 374 | | if ( !empty( $_REQUEST['content'] ) ) |
|---|
| 375 | | $post_content = wp_specialchars( stripslashes( $_REQUEST['content'] )); |
|---|
| 376 | | else if ( !empty( $post_title ) ) { |
|---|
| 377 | | $text = wp_specialchars( stripslashes( urldecode( $_REQUEST['text'] ) ) ); |
|---|
| 378 | | $text = funky_javascript_fix( $text); |
|---|
| 379 | | $popupurl = clean_url($_REQUEST['popupurl']); |
|---|
| 380 | | $post_content = '<a href="'.$popupurl.'">'.$post_title.'</a>'."\n$text"; |
|---|
| 381 | | } |
|---|
| 382 | | |
|---|
| 383 | | if ( !empty( $_REQUEST['excerpt'] ) ) |
|---|
| 384 | | $post_excerpt = wp_specialchars( stripslashes( $_REQUEST['excerpt'] )); |
|---|
| 385 | | else |
|---|
| 386 | | $post_excerpt = ''; |
|---|
| 387 | | |
|---|
| 388 | | $post->post_status = 'draft'; |
|---|
| 389 | | $post->comment_status = get_option( 'default_comment_status' ); |
|---|
| 390 | | $post->ping_status = get_option( 'default_ping_status' ); |
|---|
| 391 | | $post->post_pingback = get_option( 'default_pingback_flag' ); |
|---|
| 392 | | $post->post_category = get_option( 'default_category' ); |
|---|
| 393 | | $post->post_content = apply_filters( 'default_content', $post_content); |
|---|
| 394 | | $post->post_title = apply_filters( 'default_title', $post_title ); |
|---|
| 395 | | $post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt); |
|---|
| 396 | | $post->page_template = 'default'; |
|---|
| 397 | | $post->post_parent = 0; |
|---|
| 398 | | $post->menu_order = 0; |
|---|
| 399 | | |
|---|
| 400 | | return $post; |
|---|
| 401 | | } |
|---|
| 402 | | |
|---|
| 403 | | function get_comment_to_edit( $id ) { |
|---|
| 404 | | $comment = get_comment( $id ); |
|---|
| 405 | | |
|---|
| 406 | | $comment->comment_ID = (int) $comment->comment_ID; |
|---|
| 407 | | $comment->comment_post_ID = (int) $comment->comment_post_ID; |
|---|
| 408 | | |
|---|
| 409 | | $comment->comment_content = format_to_edit( $comment->comment_content ); |
|---|
| 410 | | $comment->comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content); |
|---|
| 411 | | |
|---|
| 412 | | $comment->comment_author = format_to_edit( $comment->comment_author ); |
|---|
| 413 | | $comment->comment_author_email = format_to_edit( $comment->comment_author_email ); |
|---|
| 414 | | $comment->comment_author_url = clean_url($comment->comment_author_url); |
|---|
| 415 | | $comment->comment_author_url = format_to_edit( $comment->comment_author_url ); |
|---|
| 416 | | |
|---|
| 417 | | return $comment; |
|---|
| 418 | | } |
|---|
| 419 | | |
|---|
| 420 | | function get_category_to_edit( $id ) { |
|---|
| 421 | | $category = get_category( $id ); |
|---|
| 422 | | |
|---|
| 423 | | $category->term_id = (int) $category->term_id; |
|---|
| 424 | | $category->parent = (int) $category->parent; |
|---|
| 425 | | |
|---|
| 426 | | return $category; |
|---|
| 427 | | } |
|---|
| 428 | | |
|---|
| 429 | | function wp_dropdown_roles( $default = false ) { |
|---|
| 430 | | global $wp_roles; |
|---|
| 431 | | $r = ''; |
|---|
| 432 | | foreach( $wp_roles->role_names as $role => $name ) |
|---|
| 433 | | if ( $default == $role ) // Make default first in list |
|---|
| 434 | | $p = "\n\t<option selected='selected' value='$role'>$name</option>"; |
|---|
| 435 | | else |
|---|
| 436 | | $r .= "\n\t<option value='$role'>$name</option>"; |
|---|
| 437 | | echo $p . $r; |
|---|
| 438 | | } |
|---|
| 439 | | |
|---|
| 440 | | |
|---|
| 441 | | function get_user_to_edit( $user_id ) { |
|---|
| 442 | | $user = new WP_User( $user_id ); |
|---|
| 443 | | $user->user_login = attribute_escape($user->user_login); |
|---|
| 444 | | $user->user_email = attribute_escape($user->user_email); |
|---|
| 445 | | $user->user_url = clean_url($user->user_url); |
|---|
| 446 | | $user->first_name = attribute_escape($user->first_name); |
|---|
| 447 | | $user->last_name = attribute_escape($user->last_name); |
|---|
| 448 | | $user->display_name = attribute_escape($user->display_name); |
|---|
| 449 | | $user->nickname = attribute_escape($user->nickname); |
|---|
| 450 | | $user->aim = attribute_escape($user->aim); |
|---|
| 451 | | $user->yim = attribute_escape($user->yim); |
|---|
| 452 | | $user->jabber = attribute_escape($user->jabber); |
|---|
| 453 | | $user->description = wp_specialchars($user->description); |
|---|
| 454 | | |
|---|
| 455 | | return $user; |
|---|
| 456 | | } |
|---|
| 457 | | |
|---|
| 458 | | // Creates a new user from the "Users" form using $_POST information. |
|---|
| 459 | | |
|---|
| 460 | | function add_user() { |
|---|
| 461 | | if ( func_num_args() ) { // The hackiest hack that ever did hack |
|---|
| 462 | | global $current_user, $wp_roles; |
|---|
| 463 | | $user_id = (int) func_get_arg( 0 ); |
|---|
| 464 | | |
|---|
| 465 | | if ( isset( $_POST['role'] ) ) { |
|---|
| 466 | | if( $user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap( 'edit_users' ) ) { |
|---|
| 467 | | $user = new WP_User( $user_id ); |
|---|
| 468 | | $user->set_role( $_POST['role'] ); |
|---|
| 469 | | } |
|---|
| 470 | | } |
|---|
| 471 | | } else { |
|---|
| 472 | | add_action( 'user_register', 'add_user' ); // See above |
|---|
| 473 | | return edit_user(); |
|---|
| 474 | | } |
|---|
| 475 | | } |
|---|
| 476 | | |
|---|
| 477 | | function edit_user( $user_id = 0 ) { |
|---|
| 478 | | global $current_user, $wp_roles, $wpdb; |
|---|
| 479 | | if ( $user_id != 0 ) { |
|---|
| 480 | | $update = true; |
|---|
| 481 | | $user->ID = (int) $user_id; |
|---|
| 482 | | $userdata = get_userdata( $user_id ); |
|---|
| 483 | | $user->user_login = $wpdb->escape( $userdata->user_login ); |
|---|
| 484 | | } else { |
|---|
| 485 | | $update = false; |
|---|
| 486 | | $user = ''; |
|---|
| 487 | | } |
|---|
| 488 | | |
|---|
| 489 | | if ( isset( $_POST['user_login'] )) |
|---|
| 490 | | $user->user_login = wp_specialchars( trim( $_POST['user_login'] )); |
|---|
| 491 | | |
|---|
| 492 | | $pass1 = $pass2 = ''; |
|---|
| 493 | | if ( isset( $_POST['pass1'] )) |
|---|
| 494 | | $pass1 = $_POST['pass1']; |
|---|
| 495 | | if ( isset( $_POST['pass2'] )) |
|---|
| 496 | | $pass2 = $_POST['pass2']; |
|---|
| 497 | | |
|---|
| 498 | | if ( isset( $_POST['role'] ) && current_user_can( 'edit_users' ) ) { |
|---|
| 499 | | if( $user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap( 'edit_users' )) |
|---|
| 500 | | $user->role = $_POST['role']; |
|---|
| 501 | | } |
|---|
| 502 | | |
|---|
| 503 | | if ( isset( $_POST['email'] )) |
|---|
| 504 | | $user->user_email = wp_specialchars( trim( $_POST['email'] )); |
|---|
| 505 | | if ( isset( $_POST['url'] ) ) { |
|---|
| 506 | | $user->user_url = clean_url( trim( $_POST['url'] )); |
|---|
| 507 | | $user->user_url = preg_match('/^(https?|ftps?|mailto|news|irc|gopher|nntp|feed|telnet):/is', $user->user_url) ? $user->user_url : 'http://'.$user->user_url; |
|---|
| 508 | | } |
|---|
| 509 | | if ( isset( $_POST['first_name'] )) |
|---|
| 510 | | $user->first_name = wp_specialchars( trim( $_POST['first_name'] )); |
|---|
| 511 | | if ( isset( $_POST['last_name'] )) |
|---|
| 512 | | $user->last_name = wp_specialchars( trim( $_POST['last_name'] )); |
|---|
| 513 | | if ( isset( $_POST['nickname'] )) |
|---|
| 514 | | $user->nickname = wp_specialchars( trim( $_POST['nickname'] )); |
|---|
| 515 | | if ( isset( $_POST['display_name'] )) |
|---|
| 516 | | $user->display_name = wp_specialchars( trim( $_POST['display_name'] )); |
|---|
| 517 | | if ( isset( $_POST['description'] )) |
|---|
| 518 | | $user->description = trim( $_POST['description'] ); |
|---|
| 519 | | if ( isset( $_POST['jabber'] )) |
|---|
| 520 | | $user->jabber = wp_specialchars( trim( $_POST['jabber'] )); |
|---|
| 521 | | if ( isset( $_POST['aim'] )) |
|---|
| 522 | | $user->aim = wp_specialchars( trim( $_POST['aim'] )); |
|---|
| 523 | | if ( isset( $_POST['yim'] )) |
|---|
| 524 | | $user->yim = wp_specialchars( trim( $_POST['yim'] )); |
|---|
| 525 | | if ( !$update ) |
|---|
| 526 | | $user->rich_editing = 'true'; // Default to true for new users. |
|---|
| 527 | | else if ( isset( $_POST['rich_editing'] ) ) |
|---|
| 528 | | $user->rich_editing = $_POST['rich_editing']; |
|---|
| 529 | | else |
|---|
| 530 | | $user->rich_editing = 'false'; |
|---|
| 531 | | |
|---|
| 532 | | $errors = new WP_Error(); |
|---|
| 533 | | |
|---|
| 534 | | /* checking that username has been typed */ |
|---|
| 535 | | if ( $user->user_login == '' ) |
|---|
| 536 | | $errors->add( 'user_login', __( '<strong>ERROR</strong>: Please enter a username.' )); |
|---|
| 537 | | |
|---|
| 538 | | /* checking the password has been typed twice */ |
|---|
| 539 | | do_action_ref_array( 'check_passwords', array ( $user->user_login, & $pass1, & $pass2 )); |
|---|
| 540 | | |
|---|
| 541 | | if (!$update ) { |
|---|
| 542 | | if ( $pass1 == '' || $pass2 == '' ) |
|---|
| 543 | | $errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter your password twice.' )); |
|---|
| 544 | | } else { |
|---|
| 545 | | if ((empty ( $pass1 ) && !empty ( $pass2 ) ) || (empty ( $pass2 ) && !empty ( $pass1 ) ) ) |
|---|
| 546 | | $errors->add( 'pass', __( "<strong>ERROR</strong>: you typed your new password only once." )); |
|---|
| 547 | | } |
|---|
| 548 | | |
|---|
| 549 | | /* Check for "\" in password */ |
|---|
| 550 | | if( strpos( " ".$pass1, "\\" ) ) |
|---|
| 551 | | $errors->add( 'pass', __( '<strong>ERROR</strong>: Passwords may not contain the character "\\".' )); |
|---|
| 552 | | |
|---|
| 553 | | /* checking the password has been typed twice the same */ |
|---|
| 554 | | if ( $pass1 != $pass2 ) |
|---|
| 555 | | $errors->add( 'pass', __( '<strong>ERROR</strong>: Please type the same password in the two password fields.' )); |
|---|
| 556 | | |
|---|
| 557 | | if (!empty ( $pass1 )) |
|---|
| 558 | | $user->user_pass = $pass1; |
|---|
| 559 | | |
|---|
| 560 | | if ( !$update && !validate_username( $user->user_login ) ) |
|---|
| 561 | | $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is invalid. Please enter a valid username.' )); |
|---|
| 562 | | |
|---|
| 563 | | if (!$update && username_exists( $user->user_login )) |
|---|
| 564 | | $errors->add( 'user_login', __( '<strong>ERROR</strong>: This username is already registered, please choose another one.' )); |
|---|
| 565 | | |
|---|
| 566 | | /* checking e-mail address */ |
|---|
| 567 | | if ( empty ( $user->user_email ) ) { |
|---|
| 568 | | $errors->add( 'user_email', __( "<strong>ERROR</strong>: please type an e-mail address" )); |
|---|
| 569 | | } else |
|---|
| 570 | | if (!is_email( $user->user_email ) ) { |
|---|
| 571 | | $errors->add( 'user_email', __( "<strong>ERROR</strong>: the email address isn't correct" )); |
|---|
| 572 | | } |
|---|
| 573 | | |
|---|
| 574 | | if ( $errors->get_error_codes() ) |
|---|
| 575 | | return $errors; |
|---|
| 576 | | |
|---|
| 577 | | if ( $update ) { |
|---|
| 578 | | $user_id = wp_update_user( get_object_vars( $user )); |
|---|
| 579 | | } else { |
|---|
| 580 | | $user_id = wp_insert_user( get_object_vars( $user )); |
|---|
| 581 | | wp_new_user_notification( $user_id ); |
|---|
| 582 | | } |
|---|
| 583 | | return $user_id; |
|---|
| 584 | | } |
|---|
| 585 | | |
|---|
| 586 | | |
|---|
| 587 | | function get_link_to_edit( $link_id ) { |
|---|
| 588 | | $link = get_link( $link_id ); |
|---|
| 589 | | |
|---|
| 590 | | $link->link_url = clean_url($link->link_url); |
|---|
| 591 | | $link->link_name = attribute_escape($link->link_name); |
|---|
| 592 | | $link->link_image = attribute_escape($link->link_image); |
|---|
| 593 | | $link->link_description = attribute_escape($link->link_description); |
|---|
| 594 | | $link->link_rss = clean_url($link->link_rss); |
|---|
| 595 | | $link->link_rel = attribute_escape($link->link_rel); |
|---|
| 596 | | $link->link_notes = wp_specialchars($link->link_notes); |
|---|
| 597 | | $link->post_category = $link->link_category; |
|---|
| 598 | | |
|---|
| 599 | | return $link; |
|---|
| 600 | | } |
|---|
| 601 | | |
|---|
| 602 | | function get_default_link_to_edit() { |
|---|
| 603 | | if ( isset( $_GET['linkurl'] ) ) |
|---|
| 604 | | $link->link_url = clean_url( $_GET['linkurl']); |
|---|
| 605 | | else |
|---|
| 606 | | $link->link_url = ''; |
|---|
| 607 | | |
|---|
| 608 | | if ( isset( $_GET['name'] ) ) |
|---|
| 609 | | $link->link_name = attribute_escape( $_GET['name']); |
|---|
| 610 | | else |
|---|
| 611 | | $link->link_name = ''; |
|---|
| 612 | | |
|---|
| 613 | | $link->link_visible = 'Y'; |
|---|
| 614 | | |
|---|
| 615 | | return $link; |
|---|
| 616 | | } |
|---|
| 617 | | |
|---|
| 618 | | function add_link() { |
|---|
| 619 | | return edit_link(); |
|---|
| 620 | | } |
|---|
| 621 | | |
|---|
| 622 | | function edit_link( $link_id = '' ) { |
|---|
| 623 | | if (!current_user_can( 'manage_links' )) |
|---|
| 624 | | wp_die( __( 'Cheatin’ uh?' )); |
|---|
| 625 | | |
|---|
| 626 | | $_POST['link_url'] = wp_specialchars( $_POST['link_url'] ); |
|---|
| 627 | | $_POST['link_url'] = clean_url($_POST['link_url']); |
|---|
| 628 | | $_POST['link_name'] = wp_specialchars( $_POST['link_name'] ); |
|---|
| 629 | | $_POST['link_image'] = wp_specialchars( $_POST['link_image'] ); |
|---|
| 630 | | $_POST['link_rss'] = clean_url($_POST['link_rss']); |
|---|
| 631 | | $_POST['link_category'] = $_POST['post_category']; |
|---|
| 632 | | |
|---|
| 633 | | if ( !empty( $link_id ) ) { |
|---|
| 634 | | $_POST['link_id'] = $link_id; |
|---|
| 635 | | return wp_update_link( $_POST); |
|---|
| 636 | | } else { |
|---|
| 637 | | return wp_insert_link( $_POST); |
|---|
| 638 | | } |
|---|
| 639 | | } |
|---|
| 640 | | |
|---|
| 641 | | function url_shorten( $url ) { |
|---|
| 642 | | $short_url = str_replace( 'http://', '', stripslashes( $url )); |
|---|
| 643 | | $short_url = str_replace( 'www.', '', $short_url ); |
|---|
| 644 | | if ('/' == substr( $short_url, -1 )) |
|---|
| 645 | | $short_url = substr( $short_url, 0, -1 ); |
|---|
| 646 | | if ( strlen( $short_url ) > 35 ) |
|---|
| 647 | | $short_url = substr( $short_url, 0, 32 ).'...'; |
|---|
| 648 | | return $short_url; |
|---|
| 649 | | } |
|---|
| 650 | | |
|---|
| 651 | | function selected( $selected, $current) { |
|---|
| 652 | | if ( $selected == $current) |
|---|
| 653 | | echo ' selected="selected"'; |
|---|
| 654 | | } |
|---|
| 655 | | |
|---|
| 656 | | function checked( $checked, $current) { |
|---|
| 657 | | if ( $checked == $current) |
|---|
| 658 | | echo ' checked="checked"'; |
|---|
| 659 | | } |
|---|
| 660 | | |
|---|
| 661 | | function return_categories_list( $parent = 0 ) { |
|---|
| 662 | | global $wpdb; |
|---|
| 663 | | return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent AND ( link_count = 0 OR category_count != 0 OR ( link_count = 0 AND category_count = 0 ) ) ORDER BY category_count DESC" ); |
|---|
| 664 | | } |
|---|
| 665 | | |
|---|
| 666 | | function sort_cats( $cat1, $cat2 ) { |
|---|
| 667 | | if ( $cat1['checked'] || $cat2['checked'] ) |
|---|
| 668 | | return ( $cat1['checked'] && !$cat2['checked'] ) ? -1 : 1; |
|---|
| 669 | | else |
|---|
| 670 | | return strcasecmp( $cat1['cat_name'], $cat2['cat_name'] ); |
|---|
| 671 | | } |
|---|
| 672 | | |
|---|
| 673 | | function get_nested_categories( $default = 0, $parent = 0 ) { |
|---|
| 674 | | global $post_ID, $link_id, $mode, $wpdb; |
|---|
| 675 | | |
|---|
| 676 | | if ( $post_ID ) { |
|---|
| 677 | | $checked_categories = $wpdb->get_col( " |
|---|
| 678 | | SELECT category_id |
|---|
| 679 | | FROM $wpdb->categories, $wpdb->post2cat |
|---|
| 680 | | WHERE $wpdb->post2cat.category_id = cat_ID AND $wpdb->post2cat.post_id = '$post_ID' |
|---|
| 681 | | " ); |
|---|
| 682 | | |
|---|
| 683 | | if ( count( $checked_categories ) == 0 ) { |
|---|
| 684 | | // No selected categories, strange |
|---|
| 685 | | $checked_categories[] = $default; |
|---|
| 686 | | } |
|---|
| 687 | | } else if ( $link_id ) { |
|---|
| 688 | | $checked_categories = $wpdb->get_col( " |
|---|
| 689 | | SELECT category_id |
|---|
| 690 | | FROM $wpdb->categories, $wpdb->link2cat |
|---|
| 691 | | WHERE $wpdb->link2cat.category_id = cat_ID AND $wpdb->link2cat.link_id = '$link_id' |
|---|
| 692 | | " ); |
|---|
| 693 | | |
|---|
| 694 | | if ( count( $checked_categories ) == 0 ) { |
|---|
| 695 | | // No selected categories, strange |
|---|
| 696 | | $checked_categories[] = $default; |
|---|
| 697 | | } |
|---|
| 698 | | } else { |
|---|
| 699 | | $checked_categories[] = $default; |
|---|
| 700 | | } |
|---|
| 701 | | |
|---|
| 702 | | $cats = return_categories_list( $parent); |
|---|
| 703 | | $result = array (); |
|---|
| 704 | | |
|---|
| 705 | | if ( is_array( $cats ) ) { |
|---|
| 706 | | foreach ( $cats as $cat) { |
|---|
| 707 | | if ( $cat == 0 ) { // HACK, added 2006-05-13 |
|---|
| 708 | | $wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = 0"); |
|---|
| 709 | | continue; |
|---|
| 710 | | } |
|---|
| 711 | | $result[$cat]['children'] = get_nested_categories( $default, $cat); |
|---|
| 712 | | $result[$cat]['cat_ID'] = $cat; |
|---|
| 713 | | $result[$cat]['checked'] = in_array( $cat, $checked_categories ); |
|---|
| 714 | | $result[$cat]['cat_name'] = get_the_category_by_ID( $cat); |
|---|
| 715 | | } |
|---|
| 716 | | } |
|---|
| 717 | | |
|---|
| 718 | | $result = apply_filters('get_nested_categories', $result); |
|---|
| 719 | | usort( $result, 'sort_cats' ); |
|---|
| 720 | | |
|---|
| 721 | | return $result; |
|---|
| 722 | | } |
|---|
| 723 | | |
|---|
| 724 | | function write_nested_categories( $categories ) { |
|---|
| 725 | | foreach ( $categories as $category ) { |
|---|
| 726 | | echo '<li id="category-', $category['cat_ID'], '"><label for="in-category-', $category['cat_ID'], '" class="selectit"><input value="', $category['cat_ID'], '" type="checkbox" name="post_category[]" id="in-category-', $category['cat_ID'], '"', ($category['checked'] ? ' checked="checked"' : "" ), '/> ', wp_specialchars( apply_filters('the_category', $category['cat_name'] )), "</label></li>"; |
|---|
| 727 | | |
|---|
| 728 | | if ( $category['children'] ) { |
|---|
| 729 | | echo "<ul>\n"; |
|---|
| 730 | | write_nested_categories( $category['children'] ); |
|---|
| 731 | | echo "</ul>\n"; |
|---|
| 732 | | } |
|---|
| 733 | | } |
|---|
| 734 | | } |
|---|
| 735 | | |
|---|
| 736 | | function dropdown_categories( $default = 0 ) { |
|---|
| 737 | | write_nested_categories( get_nested_categories( $default) ); |
|---|
| 738 | | } |
|---|
| 739 | | |
|---|
| 740 | | function return_link_categories_list( $parent = 0 ) { |
|---|
| 741 | | global $wpdb; |
|---|
| 742 | | return $wpdb->get_col( "SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent AND ( category_count = 0 OR link_count != 0 OR ( link_count = 0 AND category_count = 0 ) ) ORDER BY link_count DESC" ); |
|---|
| 743 | | } |
|---|
| 744 | | |
|---|
| 745 | | function get_nested_link_categories( $default = 0, $parent = 0 ) { |
|---|
| 746 | | global $post_ID, $link_id, $mode, $wpdb; |
|---|
| 747 | | |
|---|
| 748 | | if ( $link_id ) { |
|---|
| 749 | | $checked_categories = $wpdb->get_col( " |
|---|
| 750 | | SELECT category_id |
|---|
| 751 | | FROM $wpdb->categories, $wpdb->link2cat |
|---|
| 752 | | WHERE $wpdb->link2cat.category_id = cat_ID AND $wpdb->link2cat.link_id = '$link_id' |
|---|
| 753 | | " ); |
|---|
| 754 | | |
|---|
| 755 | | if ( count( $checked_categories ) == 0 ) { |
|---|
| 756 | | // No selected categories, strange |
|---|
| 757 | | $checked_categories[] = $default; |
|---|
| 758 | | } |
|---|
| 759 | | } else { |
|---|
| 760 | | $checked_categories[] = $default; |
|---|
| 761 | | } |
|---|
| 762 | | |
|---|
| 763 | | $cats = return_link_categories_list( $parent); |
|---|
| 764 | | $result = array (); |
|---|
| 765 | | |
|---|
| 766 | | if ( is_array( $cats ) ) { |
|---|
| 767 | | foreach ( $cats as $cat) { |
|---|
| 768 | | $result[$cat]['children'] = get_nested_link_categories( $default, $cat); |
|---|
| 769 | | $result[$cat]['cat_ID'] = $cat; |
|---|
| 770 | | $result[$cat]['checked'] = in_array( $cat, $checked_categories ); |
|---|
| 771 | | $result[$cat]['cat_name'] = get_the_category_by_ID( $cat); |
|---|
| 772 | | } |
|---|
| 773 | | } |
|---|
| 774 | | |
|---|
| 775 | | usort( $result, 'sort_cats' ); |
|---|
| 776 | | |
|---|
| 777 | | return $result; |
|---|
| 778 | | } |
|---|
| 779 | | |
|---|
| 780 | | function dropdown_link_categories( $default = 0 ) { |
|---|
| 781 | | write_nested_categories( get_nested_link_categories( $default) ); |
|---|
| 782 | | } |
|---|
| 783 | | |
|---|
| 784 | | // Dandy new recursive multiple category stuff. |
|---|
| 785 | | function cat_rows( $parent = 0, $level = 0, $categories = 0 ) { |
|---|
| 786 | | global $wpdb; |
|---|
| 787 | | |
|---|
| 788 | | if (!$categories ) |
|---|
| 789 | | $categories = get_categories( 'hide_empty=0' ); |
|---|
| 790 | | |
|---|
| 791 | | $children = _get_category_hierarchy(); |
|---|
| 792 | | |
|---|
| 793 | | if ( $categories ) { |
|---|
| 794 | | ob_start(); |
|---|
| 795 | | foreach ( $categories as $category ) { |
|---|
| 796 | | if ( $category->cat_ID == 0 ) { // HACK, added 2006-05-13 |
|---|
| 797 | | $wpdb->query("DELETE FROM $wpdb->categories WHERE cat_ID = 0"); |
|---|
| 798 | | continue; |
|---|
| 799 | | } |
|---|
| 800 | | if ( $category->category_parent == $parent) { |
|---|
| 801 | | echo "\t" . _cat_row( $category, $level ); |
|---|
| 802 | | if ( isset($children[$category->cat_ID]) ) |
|---|
| 803 | | cat_rows( $category->cat_ID, $level +1, $categories ); |
|---|
| 804 | | } |
|---|
| 805 | | } |
|---|
| 806 | | $output = ob_get_contents(); |
|---|
| 807 | | ob_end_clean(); |
|---|
| 808 | | |
|---|
| 809 | | $output = apply_filters('cat_rows', $output); |
|---|
| 810 | | |
|---|
| 811 | | echo $output; |
|---|
| 812 | | } else { |
|---|
| 813 | | return false; |
|---|
| 814 | | } |
|---|
| 815 | | } |
|---|
| 816 | | |
|---|
| 817 | | function _cat_row( $category, $level, $name_override = false ) { |
|---|
| 818 | | global $class; |
|---|
| 819 | | |
|---|
| 820 | | $pad = str_repeat( '— ', $level ); |
|---|
| 821 | | if ( current_user_can( 'manage_categories' ) ) { |
|---|
| 822 | | $edit = "<a href='categories.php?action=edit&cat_ID=$category->cat_ID' class='edit'>".__( 'Edit' )."</a></td>"; |
|---|
| 823 | | $default_cat_id = (int) get_option( 'default_category' ); |
|---|
| 824 | | $default_link_cat_id = (int) get_option( 'default_link_category' ); |
|---|
| 825 | | |
|---|
| 826 | | if ( ($category->cat_ID != $default_cat_id ) && ($category->cat_ID != $default_link_cat_id ) ) |
|---|
| 827 | | $edit .= "<td><a href='" . wp_nonce_url( "categories.php?action=delete&cat_ID=$category->cat_ID", 'delete-category_' . $category->cat_ID ) . "' onclick=\"return deleteSomething( 'cat', $category->cat_ID, '" . js_escape(sprintf( __("You are about to delete the category '%s'.\nAll posts that were only assigned to this category will be assigned to the '%s' category.\nAll links that were only assigned to this category will be assigned to the '%s' category.\n'OK' to delete, 'Cancel' to stop." ), $category->cat_name, get_catname( $default_cat_id ), get_catname( $default_link_cat_id ) )) . "' );\" class='delete'>".__( 'Delete' )."</a>"; |
|---|
| 828 | | else |
|---|
| 829 | | $edit .= "<td style='text-align:center'>".__( "Default" ); |
|---|
| 830 | | } else |
|---|
| 831 | | $edit = ''; |
|---|
| 832 | | |
|---|
| 833 | | $class = ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || " class='alternate'" == $class ) ? '' : " class='alternate'"; |
|---|
| 834 | | |
|---|
| 835 | | $category->category_count = number_format( $category->category_count ); |
|---|
| 836 | | $category->link_count = number_format( $category->link_count ); |
|---|
| 837 | | $posts_count = ( $category->category_count > 0 ) ? "<a href='edit.php?cat=$category->cat_ID'>$category->category_count</a>" : $category->category_count; |
|---|
| 838 | | return "<tr id='cat-$category->cat_ID'$class> |
|---|
| 839 | | <th scope='row' style='text-align: center'>$category->cat_ID</th> |
|---|
| 840 | | <td>" . ( $name_override ? $name_override : $pad . ' ' . $category->cat_name ) . "</td> |
|---|
| 841 | | <td>$category->category_description</td> |
|---|
| 842 | | <td align='center'>$posts_count</td> |
|---|
| 843 | | <td align='center'>$category->link_count</td> |
|---|
| 844 | | <td>$edit</td>\n\t</tr>\n"; |
|---|
| 845 | | } |
|---|
| 846 | | |
|---|
| 847 | | function page_rows( $parent = 0, $level = 0, $pages = 0, $hierarchy = true ) { |
|---|
| 848 | | global $wpdb, $class, $post; |
|---|
| 849 | | |
|---|
| 850 | | if (!$pages ) |
|---|
| 851 | | $pages = get_pages( 'sort_column=menu_order' ); |
|---|
| 852 | | |
|---|
| 853 | | if (! $pages ) |
|---|
| 854 | | return false; |
|---|
| 855 | | |
|---|
| 856 | | foreach ( $pages as $post) { |
|---|
| 857 | | setup_postdata( $post); |
|---|
| 858 | | if ( $hierarchy && ($post->post_parent != $parent) ) |
|---|
| 859 | | continue; |
|---|
| 860 | | |
|---|
| 861 | | $post->post_title = wp_specialchars( $post->post_title ); |
|---|
| 862 | | $pad = str_repeat( '— ', $level ); |
|---|
| 863 | | $id = (int) $post->ID; |
|---|
| 864 | | $class = ('alternate' == $class ) ? '' : 'alternate'; |
|---|
| | 2 | // Deprecated. Use includes/admin.php. |
|---|
| | 3 | require_once(ABSPATH . 'wp-admin/includes/admin.php'); |
|---|
| 866 | | <tr id='page-<?php echo $id; ?>' class='<?php echo $class; ?>'> |
|---|
| 867 | | <th scope="row" style="text-align: center"><?php echo $post->ID; ?></th> |
|---|
| 868 | | <td> |
|---|
| 869 | | <?php echo $pad; ?><?php the_title() ?> |
|---|
| 870 | | </td> |
|---|
| 871 | | <td><?php the_author() ?></td> |
|---|
| 872 | | <td><?php if ( '0000-00-00 00:00:00' ==$post->post_modified ) _e('Unpublished'); else echo mysql2date( __('Y-m-d g:i a'), $post->post_modified ); ?></td> |
|---|
| 873 | | <td><a href="<?php the_permalink(); ?>" rel="permalink" class="edit"><?php _e( 'View' ); ?></a></td> |
|---|
| 874 | | <td><?php if ( current_user_can( 'edit_page', $id ) ) { echo "<a href='page.php?action=edit&post=$id' class='edit'>" . __( 'Edit' ) . "</a>"; } ?></td> |
|---|
| 875 | | <td><?php if ( current_user_can( 'delete_page', $id ) ) { echo "<a href='" . wp_nonce_url( "page.php?action=delete&post=$id", 'delete-page_' . $id ) . "' class='delete' onclick=\"return deleteSomething( 'page', " . $id . ", '" . js_escape(sprintf( __("You are about to delete the '%s' page.\n'OK' to delete, 'Cancel' to stop." ), get_the_title() ) ) . "' );\">" . __( 'Delete' ) . "</a>"; } ?></td> |
|---|
| 876 | | </tr> |
|---|
| 877 | | |
|---|
| 878 | | <?php |
|---|
| 879 | | if ( $hierarchy ) page_rows( $id, $level + 1, $pages ); |
|---|
| 880 | | } |
|---|
| 881 | | } |
|---|
| 882 | | |
|---|
| 883 | | function user_row( $user_object, $style = '' ) { |
|---|
| 884 | | global $current_user; |
|---|
| 885 | | |
|---|
| 886 | | if ( !(is_object( $user_object) && is_a( $user_object, 'WP_User' ) ) ) |
|---|
| 887 | | $user_object = new WP_User( (int) $user_object ); |
|---|
| 888 | | $email = $user_object->user_email; |
|---|
| 889 | | $url = $user_object->user_url; |
|---|
| 890 | | $short_url = str_replace( 'http://', '', $url ); |
|---|
| 891 | | $short_url = str_replace( 'www.', '', $short_url ); |
|---|
| 892 | | if ('/' == substr( $short_url, -1 )) |
|---|
| 893 | | $short_url = substr( $short_url, 0, -1 ); |
|---|
| 894 | | if ( strlen( $short_url ) > 35 ) |
|---|
| 895 | | $short_url = substr( $short_url, 0, 32 ).'...'; |
|---|
| 896 | | $numposts = get_usernumposts( $user_object->ID ); |
|---|
| 897 | | $r = "<tr id='user-$user_object->ID'$style> |
|---|
| 898 | | <td><input type='checkbox' name='users[]' id='user_{$user_object->ID}' value='{$user_object->ID}' /> <label for='user_{$user_object->ID}'>{$user_object->ID}</label></td> |
|---|
| 899 | | <td><label for='user_{$user_object->ID}'><strong>$user_object->user_login</strong></label></td> |
|---|
| 900 | | <td><label for='user_{$user_object->ID}'>$user_object->first_name $user_object->last_name</label></td> |
|---|
| 901 | | <td><a href='mailto:$email' title='" . sprintf( __('e-mail: %s' ), $email ) . "'>$email</a></td> |
|---|
| 902 | | <td><a href='$url' title='website: $url'>$short_url</a></td>"; |
|---|
| 903 | | $r .= "\n\t\t<td align='center'>"; |
|---|
| 904 | | if ( $numposts > 0 ) { |
|---|
| 905 | | $r .= "<a href='edit.php?author=$user_object->ID' title='" . __( 'View posts by this author' ) . "' class='edit'>"; |
|---|
| 906 | | $r .= sprintf(__ngettext( 'View %s post', 'View %s posts', $numposts ), $numposts); |
|---|
| 907 | | $r .= '</a>'; |
|---|
| 908 | | } |
|---|
| 909 | | $r .= "</td>\n\t\t<td>"; |
|---|
| 910 | | if ( ( is_site_admin() || $current_user->ID == $user_object->ID ) && current_user_can( 'edit_user', $user_object->ID ) ) { |
|---|
| 911 | | $edit_link = add_query_arg( 'wp_http_referer', urlencode( clean_url( stripslashes( $_SERVER['REQUEST_URI'] ) ) ), "user-edit.php?user_id=$user_object->ID" ); |
|---|
| 912 | | $r .= "<a href='$edit_link' class='edit'>".__( 'Edit' )."</a>"; |
|---|
| 913 | | } |
|---|
| 914 | | $r .= "</td>\n\t</tr>"; |
|---|
| 915 | | return $r; |
|---|
| 916 | | } |
|---|
| 917 | | |
|---|
| 918 | | function _wp_get_comment_list( $s = false, $start, $num ) { |
|---|
| 919 | | global $wpdb; |
|---|
| 920 | | |
|---|
| 921 | | $start = abs( (int) $start ); |
|---|
| 922 | | $num = (int) $num; |
|---|
| 923 | | |
|---|
| 924 | | if ( $s ) { |
|---|
| 925 | | $s = $wpdb->escape($s); |
|---|
| 926 | | $comments = $wpdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE |
|---|
| 927 | | (comment_author LIKE '%$s%' OR |
|---|
| 928 | | comment_author_email LIKE '%$s%' OR |
|---|
| 929 | | comment_author_url LIKE ('%$s%') OR |
|---|
| 930 | | comment_author_IP LIKE ('%$s%') OR |
|---|
| 931 | | comment_content LIKE ('%$s%') ) AND |
|---|
| 932 | | comment_approved != 'spam' |
|---|
| 933 | | ORDER BY comment_date DESC LIMIT $start, $num"); |
|---|
| 934 | | } else { |
|---|
| 935 | | $comments = $wpdb->get_results( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->comments WHERE comment_approved = '0' OR comment_approved = '1' ORDER BY comment_date DESC LIMIT $start, $num" ); |
|---|
| 936 | | } |
|---|
| 937 | | |
|---|
| 938 | | $total = $wpdb->get_var( "SELECT FOUND_ROWS()" ); |
|---|
| 939 | | |
|---|
| 940 | | return array($comments, $total); |
|---|
| 941 | | } |
|---|
| 942 | | |
|---|
| 943 | | function _wp_comment_list_item( $id, $alt = 0 ) { |
|---|
| 944 | | global $authordata, $comment, $wpdb; |
|---|
| 945 | | $id = (int) $id; |
|---|
| 946 | | $comment =& get_comment( $id ); |
|---|
| 947 | | $class = ''; |
|---|
| 948 | | $authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = $comment->comment_post_ID")); |
|---|
| 949 | | $comment_status = wp_get_comment_status($comment->comment_ID); |
|---|
| 950 | | if ( 'unapproved' == $comment_status ) |
|---|
| 951 | | $class .= ' unapproved'; |
|---|
| 952 | | if ( $alt % 2 ) |
|---|
| 953 | | $class .= ' alternate'; |
|---|
| 954 | | echo "<li id='comment-$comment->comment_ID' class='$class'>"; |
|---|
| 955 | | ?> |
|---|
| 956 | | <p><strong><?php comment_author(); ?></strong> <?php if ($comment->comment_author_email) { ?>| <?php comment_author_email_link() ?> <?php } if ($comment->comment_author_url && 'http://' != $comment->comment_author_url) { ?> | <?php comment_author_url_link() ?> <?php } ?>| <?php _e('IP:') ?> <a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP() ?>"><?php comment_author_IP() ?></a></p> |
|---|
| 957 | | |
|---|
| 958 | | <?php comment_text() ?> |
|---|
| 959 | | |
|---|
| 960 | | <p><?php comment_date(__('M j, g:i A')); ?> — [ |
|---|
| 961 | | <?php |
|---|
| 962 | | if ( current_user_can('edit_post', $comment->comment_post_ID) ) { |
|---|
| 963 | | echo " <a href='comment.php?action=editcomment&c=".$comment->comment_ID."'>" . __('Edit') . '</a>'; |
|---|
| 964 | | echo ' | <a href="' . wp_nonce_url('comment.php?action=deletecomment&p=' . $comment->comment_post_ID . '&c=' . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . '" onclick="return deleteSomething( \'comment\', ' . $comment->comment_ID . ', \'' . js_escape(sprintf(__("You are about to delete this comment by '%s'.\n'Cancel' to stop, 'OK' to delete."), $comment->comment_author)) . "', theCommentList );\">" . __('Delete') . '</a> '; |
|---|
| 965 | | if ( ('none' != $comment_status) && ( current_user_can('moderate_comments') ) ) { |
|---|
| 966 | | echo '<span class="unapprove"> | <a href="' . wp_nonce_url('comment.php?action=unapprovecomment&p=' . $comment->comment_post_ID . '&c=' . $comment->comment_ID, 'unapprove-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Unapprove') . '</a> </span>'; |
|---|
| 967 | | echo '<span class="approve"> | <a href="' . wp_nonce_url('comment.php?action=approvecomment&p=' . $comment->comment_post_ID . '&c=' . $comment->comment_ID, 'approve-comment_' . $comment->comment_ID) . '" onclick="return dimSomething( \'comment\', ' . $comment->comment_ID . ', \'unapproved\', theCommentList );">' . __('Approve') . '</a> </span>'; |
|---|
| 968 | | } |
|---|
| 969 | | echo " | <a href=\"" . wp_nonce_url("comment.php?action=deletecomment&dt=spam&p=" . $comment->comment_post_ID . "&c=" . $comment->comment_ID, 'delete-comment_' . $comment->comment_ID) . "\" onclick=\"return deleteSomething( 'comment-as-spam', $comment->comment_ID, '" . js_escape(sprintf(__("You are about to mark as spam this comment by '%s'.\n'Cancel' to stop, 'OK' to mark as spam."), $comment->comment_author)) . "', theCommentList );\">" . __('Spam') . "</a> "; |
|---|
| 970 | | } |
|---|
| 971 | | $post = get_post($comment->comment_post_ID); |
|---|
| 972 | | $post_title = wp_specialchars( $post->post_title, 'double' ); |
|---|
| 973 | | $post_title = ('' == $post_title) ? "# $comment->comment_post_ID" : $post_title; |
|---|
| 974 | | ?> |
|---|
| 975 | | ] — <a href="<?php echo get_permalink($comment->comment_post_ID); ?>"><?php echo $post_title; ?></a></p> |
|---|
| 976 | | </li> |
|---|
| 977 | | <?php |
|---|
| 978 | | } |
|---|
| 979 | | |
|---|
| 980 | | function wp_dropdown_cats( $currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0 ) { |
|---|
| 981 | | global $wpdb; |
|---|
| 982 | | if (!$categories ) |
|---|
| 983 | | $categories = get_categories( 'hide_empty=0' ); |
|---|
| 984 | | |
|---|
| 985 | | if ( $categories ) { |
|---|
| 986 | | foreach ( $categories as $category ) { |
|---|
| 987 | | if ( $currentcat != $category->cat_ID && $parent == $category->category_parent) { |
|---|
| 988 | | $pad = str_repeat( '– ', $level ); |
|---|
| 989 | | $category->cat_name = wp_specialchars( $category->cat_name ); |
|---|
| 990 | | echo "\n\t<option value='$category->cat_ID'"; |
|---|
| 991 | | if ( $currentparent == $category->cat_ID ) |
|---|
| 992 | | echo " selected='selected'"; |
|---|
| 993 | | echo ">$pad$category->cat_name</option>"; |
|---|
| 994 | | wp_dropdown_cats( $currentcat, $currentparent, $category->cat_ID, $level +1, $categories ); |
|---|
| 995 | | } |
|---|
| 996 | | } |
|---|
| 997 | | } else { |
|---|
| 998 | | return false; |
|---|
| 999 | | } |
|---|
| 1000 | | } |
|---|
| 1001 | | |
|---|
| 1002 | | // Some postmeta stuff |
|---|
| 1003 | | function has_meta( $postid ) { |
|---|
| 1004 | | global $wpdb; |
|---|
| 1005 | | |
|---|
| 1006 | | return $wpdb->get_results( " |
|---|
| 1007 | | SELECT meta_key, meta_value, meta_id, post_id |
|---|
| 1008 | | FROM $wpdb->postmeta |
|---|
| 1009 | | WHERE post_id = '$postid' |
|---|
| 1010 | | ORDER BY meta_key,meta_id", ARRAY_A ); |
|---|
| 1011 | | |
|---|
| 1012 | | } |
|---|
| 1013 | | |
|---|
| 1014 | | function list_meta( $meta ) { |
|---|
| 1015 | | global $post_ID; |
|---|
| 1016 | | // Exit if no meta |
|---|
| 1017 | | if (!$meta ) { |
|---|
| 1018 | | echo '<tbody id="the-list"><tr style="display: none;"><td> </td></tr></tbody>'; //TBODY needed for list-manipulation JS |
|---|
| 1019 | | return; |
|---|
| 1020 | | } |
|---|
| 1021 | | $count = 0; |
|---|
| 1022 | | ?> |
|---|
| 1023 | | <thead> |
|---|
| 1024 | | <tr> |
|---|
| 1025 | | <th><?php _e( 'Key' ) ?></th> |
|---|
| 1026 | | <th><?php _e( 'Value' ) ?></th> |
|---|
| 1027 | | <th colspan='2'><?php _e( 'Action' ) ?></th> |
|---|
| 1028 | | </tr> |
|---|
| 1029 | | </thead> |
|---|
| 1030 | | <?php |
|---|
| 1031 | | $r ="\n\t<tbody id='the-list'>"; |
|---|
| 1032 | | foreach ( $meta as $entry ) { |
|---|
| 1033 | | ++ $count; |
|---|
| 1034 | | if ( $count % 2 ) |
|---|
| 1035 | | $style = 'alternate'; |
|---|
| 1036 | | else |
|---|
| 1037 | | $style = ''; |
|---|
| 1038 | | if ('_' == $entry['meta_key'] { 0 } ) |
|---|
| 1039 | | $style .= ' hidden'; |
|---|
| 1040 | | |
|---|
| 1041 | | if ( is_serialized( $entry['meta_value'] ) ) { |
|---|
| 1042 | | if ( is_serialized_string( $entry['meta_value'] ) ) { |
|---|
| 1043 | | // this is a serialized string, so we should display it |
|---|
| 1044 | | $entry['meta_value'] = maybe_unserialize( $entry['meta_value'] ); |
|---|
| 1045 | | } else { |
|---|
| 1046 | | // this is a serialized array/object so we should NOT display it |
|---|
| 1047 | | --$count; |
|---|
| 1048 | | continue; |
|---|
| 1049 | | } |
|---|
| 1050 | | } |
|---|
| 1051 | | |
|---|
| 1052 | | $key_js = js_escape( $entry['meta_key'] ); |
|---|
| 1053 | | $entry['meta_key'] = attribute_escape($entry['meta_key']); |
|---|
| 1054 | | $entry['meta_value'] = attribute_escape($entry['meta_value']); |
|---|
| 1055 | | $entry['meta_id'] = (int) $entry['meta_id']; |
|---|
| 1056 | | $r .= "\n\t<tr id='meta-{$entry['meta_id']}' class='$style'>"; |
|---|
| 1057 | | $r .= "\n\t\t<td valign='top'><input name='meta[{$entry['meta_id']}][key]' tabindex='6' type='text' size='20' value='{$entry['meta_key']}' /></td>"; |
|---|
| 1058 | | $r .= "\n\t\t<td><textarea name='meta[{$entry['meta_id']}][value]' tabindex='6' rows='2' cols='30'>{$entry['meta_value']}</textarea></td>"; |
|---|
| 1059 | | $r .= "\n\t\t<td align='center'><input name='updatemeta' type='submit' class='updatemeta' tabindex='6' value='".attribute_escape(__( 'Update' ))."' /><br />"; |
|---|
| 1060 | | $r .= "\n\t\t<input name='deletemeta[{$entry['meta_id']}]' type='submit' onclick=\"return deleteSomething( 'meta', {$entry['meta_id']}, '"; |
|---|
| 1061 | | $r .= js_escape(sprintf( __("You are about to delete the '%s' custom field on this post.\n'OK' to delete, 'Cancel' to stop." ), $key_js ) ); |
|---|
| 1062 | | $r .= "' );\" class='deletemeta' tabindex='6' value='".attribute_escape(__( 'Delete' ))."' /></td>"; |
|---|
| 1063 | | $r .= "\n\t</tr>"; |
|---|
| 1064 | | } |
|---|
| 1065 | | echo $r; |
|---|
| 1066 | | echo "\n\t</tbody>"; |
|---|
| 1067 | | } |
|---|
| 1068 | | |
|---|
| 1069 | | // Get a list of previously defined keys |
|---|
| 1070 | | function get_meta_keys() { |
|---|
| 1071 | | global $wpdb; |
|---|
| 1072 | | |
|---|
| 1073 | | $keys = $wpdb->get_col( " |
|---|
| 1074 | | SELECT meta_key |
|---|
| 1075 | | FROM $wpdb->postmeta |
|---|
| 1076 | | GROUP BY meta_key |
|---|
| 1077 | | ORDER BY meta_key" ); |
|---|
| 1078 | | |
|---|
| 1079 | | return $keys; |
|---|
| 1080 | | } |
|---|
| 1081 | | |
|---|
| 1082 | | function meta_form() { |
|---|
| 1083 | | global $wpdb; |
|---|
| 1084 | | $limit = (int) apply_filters( 'postmeta_form_limit', 30 ); |
|---|
| 1085 | | $keys = $wpdb->get_col( " |
|---|
| 1086 | | SELECT meta_key |
|---|
| 1087 | | FROM $wpdb->postmeta |
|---|
| 1088 | | GROUP BY meta_key |
|---|
| 1089 | | ORDER BY meta_id DESC |
|---|
| 1090 | | LIMIT $limit" ); |
|---|
| 1091 | | if ( $keys ) |
|---|
| 1092 | | natcasesort($keys); |
|---|
| 1093 | | ?> |
|---|
| 1094 | | <h3><?php _e( 'Add a new custom field:' ) ?></h3> |
|---|
| 1095 | | <table id="newmeta" cellspacing="3" cellpadding="3"> |
|---|
| 1096 | | <tr> |
|---|
| 1097 | | <th colspan="2"><?php _e( 'Key' ) ?></th> |
|---|
| 1098 | | <th><?php _e( 'Value' ) ?></th> |
|---|
| 1099 | | </tr> |
|---|
| 1100 | | <tr valign="top"> |
|---|
| 1101 | | <td align="right" width="18%"> |
|---|
| 1102 | | <?php if ( $keys ) : ?> |
|---|
| 1103 | | <select id="metakeyselect" name="metakeyselect" tabindex="7"> |
|---|
| 1104 | | <option value="#NONE#"><?php _e( '- Select -' ); ?></option> |
|---|
| 1105 | | <?php |
|---|
| 1106 | | |
|---|
| 1107 | | foreach ( $keys as $key ) { |
|---|
| 1108 | | $key = attribute_escape( $key ); |
|---|
| 1109 | | echo "\n\t<option value='$key'>$key</option>"; |
|---|
| 1110 | | } |
|---|
| 1111 | | ?> |
|---|
| 1112 | | </select> <?php _e( 'or' ); ?> |
|---|
| 1113 | | <?php endif; ?> |
|---|
| 1114 | | </td> |
|---|
| 1115 | | <td><input type="text" id="metakeyinput" name="metakeyinput" tabindex="7" /></td> |
|---|
| 1116 | | <td><textarea id="metavalue" name="metavalue" rows="3" cols="25" tabindex="8"></textarea></td> |
|---|
| 1117 | | </tr> |
|---|
| 1118 | | |
|---|
| 1119 | | </table> |
|---|
| 1120 | | <p class="submit"><input type="submit" id="updatemetasub" name="updatemeta" tabindex="9" value="<?php _e( 'Add Custom Field »' ) ?>" /></p> |
|---|
| 1121 | | <?php |
|---|
| 1122 | | |
|---|
| 1123 | | } |
|---|
| 1124 | | |
|---|
| 1125 | | function add_meta( $post_ID ) { |
|---|
| 1126 | | global $wpdb; |
|---|
| 1127 | | $post_ID = (int) $post_ID; |
|---|
| 1128 | | |
|---|
| 1129 | | $protected = array( '_wp_attached_file', '_wp_attachment_metadata', '_wp_old_slug', '_wp_page_template' ); |
|---|
| 1130 | | |
|---|
| 1131 | | $metakeyselect = $wpdb->escape( stripslashes( trim( $_POST['metakeyselect'] ) ) ); |
|---|
| 1132 | | $metakeyinput = $wpdb->escape( stripslashes( trim( $_POST['metakeyinput'] ) ) ); |
|---|
| 1133 | | $metavalue = maybe_serialize( stripslashes( (trim( $_POST['metavalue'] ) ) )); |
|---|
| 1134 | | $metavalue = $wpdb->escape( $metavalue ); |
|---|
| 1135 | | |
|---|
| 1136 | | if ( ('0' === $metavalue || !empty ( $metavalue ) ) && ((('#NONE#' != $metakeyselect) && !empty ( $metakeyselect) ) || !empty ( $metakeyinput) ) ) { |
|---|
| 1137 | | // We have a key/value pair. If both the select and the |
|---|
| 1138 | | // input for the key have data, the input takes precedence: |
|---|
| 1139 | | |
|---|
| 1140 | | if ('#NONE#' != $metakeyselect) |
|---|
| 1141 | | $metakey = $metakeyselect; |
|---|
| 1142 | | |
|---|
| 1143 | | if ( $metakeyinput) |
|---|
| 1144 | | $metakey = $metakeyinput; // default |
|---|
| 1145 | | |
|---|
| 1146 | | if ( in_array($metakey, $protected) ) |
|---|
| 1147 | | return false; |
|---|
| 1148 | | |
|---|
| 1149 | | $result = $wpdb->query( " |
|---|
| 1150 | | INSERT INTO $wpdb->postmeta |
|---|
| 1151 | | (post_id,meta_key,meta_value ) |
|---|
| 1152 | | VALUES ('$post_ID','$metakey','$metavalue' ) |
|---|
| 1153 | | " ); |
|---|
| 1154 | | return $wpdb->insert_id; |
|---|
| 1155 | | } |
|---|
| 1156 | | return false; |
|---|
| 1157 | | } // add_meta |
|---|
| 1158 | | |
|---|
| 1159 | | function delete_meta( $mid ) { |
|---|
| 1160 | | global $wpdb; |
|---|
| 1161 | | $mid = (int) $mid; |
|---|
| 1162 | | |
|---|
| 1163 | | return $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_id = '$mid'" ); |
|---|
| 1164 | | } |
|---|
| 1165 | | |
|---|
| 1166 | | function update_meta( $mid, $mkey, $mvalue ) { |
|---|
| 1167 | | global $wpdb; |
|---|
| 1168 | | |
|---|
| 1169 | | $protected = array( '_wp_attached_file', '_wp_attachment_metadata', '_wp_old_slug', '_wp_page_template' ); |
|---|
| 1170 | | |
|---|
| 1171 | | if ( in_array($mkey, $protected) ) |
|---|
| 1172 | | return false; |
|---|
| 1173 | | |
|---|
| 1174 | | $mvalue = maybe_serialize( stripslashes( $mvalue )); |
|---|
| 1175 | | $mvalue = $wpdb->escape( $mvalue ); |
|---|
| 1176 | | $mid = (int) $mid; |
|---|
| 1177 | | return $wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = '$mkey', meta_value = '$mvalue' WHERE meta_id = '$mid'" ); |
|---|
| 1178 | | } |
|---|
| 1179 | | |
|---|
| 1180 | | function get_post_meta_by_id( $mid ) { |
|---|
| 1181 | | global $wpdb; |
|---|
| 1182 | | $mid = (int) $mid; |
|---|
| 1183 | | |
|---|
| 1184 | | $meta = $wpdb->get_row( "SELECT * FROM $wpdb->postmeta WHERE meta_id = '$mid'" ); |
|---|
| 1185 | | if ( is_serialized_string( $meta->meta_value ) ) |
|---|
| 1186 | | $meta->meta_value = maybe_unserialize( $meta->meta_value ); |
|---|
| 1187 | | return $meta; |
|---|
| 1188 | | } |
|---|
| 1189 | | |
|---|
| 1190 | | function touch_time( $edit = 1, $for_post = 1 ) { |
|---|
| 1191 | | global $wp_locale, $post, $comment; |
|---|
| 1192 | | |
|---|
| 1193 | | if ( $for_post ) |
|---|
| 1194 | | $edit = ( ('draft' == $post->post_status ) && (!$post->post_date || '0000-00-00 00:00:00' == $post->post_date ) ) ? false : true; |
|---|
| 1195 | | |
|---|
| 1196 | | echo '<fieldset><legend><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp" /> <label for="timestamp">'.__( 'Edit timestamp' ).'</label></legend>'; |
|---|
| 1197 | | |
|---|
| 1198 | | $time_adj = time() + (get_option( 'gmt_offset' ) * 3600 ); |
|---|
| 1199 | | $post_date = ($for_post) ? $post->post_date : $comment->comment_date; |
|---|
| 1200 | | $jj = ($edit) ? mysql2date( 'd', $post_date ) : gmdate( 'd', $time_adj ); |
|---|
| 1201 | | $mm = ($edit) ? mysql2date( 'm', $post_date ) : gmdate( 'm', $time_adj ); |
|---|
| 1202 | | $aa = ($edit) ? mysql2date( 'Y', $post_date ) : gmdate( 'Y', $time_adj ); |
|---|
| 1203 | | $hh = ($edit) ? mysql2date( 'H', $post_date ) : gmdate( 'H', $time_adj ); |
|---|
| 1204 | | $mn = ($edit) ? mysql2date( 'i', $post_date ) : gmdate( 'i', $time_adj ); |
|---|
| 1205 | | $ss = ($edit) ? mysql2date( 's', $post_date ) : gmdate( 's', $time_adj ); |
|---|
| 1206 | | |
|---|
| 1207 | | echo "<select name=\"mm\" onchange=\"edit_date.checked=true\">\n"; |
|---|
| 1208 | | for ( $i = 1; $i < 13; $i = $i +1 ) { |
|---|
| 1209 | | echo "\t\t\t<option value=\"$i\""; |
|---|
| 1210 | | if ( $i == $mm ) |
|---|
| 1211 | | echo ' selected="selected"'; |
|---|
| 1212 | | echo '>' . $wp_locale->get_month( $i ) . "</option>\n"; |
|---|
| 1213 | | } |
|---|
| 1214 | | ?> |
|---|
| 1215 | | </select> |
|---|
| 1216 | | <input type="text" id="jj" name="jj" value="<?php echo $jj; ?>" size="2" maxlength="2" onchange="edit_date.checked=true"/> |
|---|
| 1217 | | <input type="text" id="aa" name="aa" value="<?php echo $aa ?>" size="4" maxlength="5" onchange="edit_date.checked=true" /> @ |
|---|
| 1218 | | <input type="text" id="hh" name="hh" value="<?php echo $hh ?>" size="2" maxlength="2" onchange="edit_date.checked=true" /> : |
|---|
| 1219 | | <input type="text" id="mn" name="mn" value="<?php echo $mn ?>" size="2" maxlength="2" onchange="edit_date.checked=true" /> |
|---|
| 1220 | | <input type="hidden" id="ss" name="ss" value="<?php echo $ss ?>" size="2" maxlength="2" onchange="edit_date.checked=true" /> |
|---|
| 1221 | | <?php |
|---|
| 1222 | | if ( $edit ) { |
|---|
| 1223 | | printf( __('Existing timestamp: %1$s %2$s, %3$s @ %4$s:%5$s' ), $wp_locale->get_month( $mm ), $jj, $aa, $hh, $mn ); |
|---|
| 1224 | | } |
|---|
| 1225 | | ?> |
|---|
| 1226 | | </fieldset> |
|---|
| 1227 | | <?php |
|---|
| 1228 | | |
|---|
| 1229 | | } |
|---|
| 1230 | | |
|---|
| 1231 | | // insert_with_markers: Owen Winkler, fixed by Eric Anderson |
|---|
| 1232 | | // Inserts an array of strings into a file (.htaccess ), placing it between |
|---|
| 1233 | | // BEGIN and END markers. Replaces existing marked info. Retains surrounding |
|---|
| 1234 | | // data. Creates file if none exists. |
|---|
| 1235 | | // Returns true on write success, false on failure. |
|---|
| 1236 | | function insert_with_markers( $filename, $marker, $insertion ) { |
|---|
| 1237 | | return true; |
|---|
| 1238 | | if (!file_exists( $filename ) || is_writeable( $filename ) ) { |
|---|
| 1239 | | if (!file_exists( $filename ) ) { |
|---|
| 1240 | | $markerdata = ''; |
|---|
| 1241 | | } else { |
|---|
| 1242 | | $markerdata = explode( "\n", implode( '', file( $filename ) ) ); |
|---|
| 1243 | | } |
|---|
| 1244 | | |
|---|
| 1245 | | $f = fopen( $filename, 'w' ); |
|---|
| 1246 | | $foundit = false; |
|---|
| 1247 | | if ( $markerdata ) { |
|---|
| 1248 | | $state = true; |
|---|
| 1249 | | foreach ( $markerdata as $n => $markerline ) { |
|---|
| 1250 | | if (strpos($markerline, '# BEGIN ' . $marker) !== false) |
|---|
| 1251 | | $state = false; |
|---|
| 1252 | | if ( $state ) { |
|---|
| 1253 | | if ( $n + 1 < count( $markerdata ) ) |
|---|
| 1254 | | fwrite( $f, "{$markerline}\n" ); |
|---|
| 1255 | | else |
|---|
| 1256 | | fwrite( $f, "{$markerline}" ); |
|---|
| 1257 | | } |
|---|
| 1258 | | if (strpos($markerline, '# END ' . $marker) !== false) { |
|---|
| 1259 | | fwrite( $f, "# BEGIN {$marker}\n" ); |
|---|
| 1260 | | if ( is_array( $insertion )) |
|---|
| 1261 | | foreach ( $insertion as $insertline ) |
|---|
| 1262 | | fwrite( $f, "{$insertline}\n" ); |
|---|
| 1263 | | fwrite( $f, "# END {$marker}\n" ); |
|---|
| 1264 | | $state = true; |
|---|
| 1265 | | $foundit = true; |
|---|
| 1266 | | } |
|---|
| 1267 | | } |
|---|
| 1268 | | } |
|---|
| 1269 | | if (!$foundit) { |
|---|
| 1270 | | fwrite( $f, "# BEGIN {$marker}\n" ); |
|---|
| 1271 | | foreach ( $insertion as $insertline ) |
|---|
| 1272 | | fwrite( $f, "{$insertline}\n" ); |
|---|
| 1273 | | fwrite( $f, "# END {$marker}\n" ); |
|---|
| 1274 | | } |
|---|
| 1275 | | fclose( $f ); |
|---|
| 1276 | | return true; |
|---|
| 1277 | | } else { |
|---|
| 1278 | | return false; |
|---|
| 1279 | | } |
|---|
| 1280 | | } |
|---|
| 1281 | | |
|---|
| 1282 | | // extract_from_markers: Owen Winkler |
|---|
| 1283 | | // Returns an array of strings from a file (.htaccess ) from between BEGIN |
|---|
| 1284 | | // and END markers. |
|---|
| 1285 | | function extract_from_markers( $filename, $marker ) { |
|---|
| 1286 | | $result = array (); |
|---|
| 1287 | | |
|---|
| 1288 | | if (!file_exists( $filename ) ) { |
|---|
| 1289 | | return $result; |
|---|
| 1290 | | } |
|---|
| 1291 | | |
|---|
| 1292 | | if ( $markerdata = explode( "\n", implode( '', file( $filename ) ) )); |
|---|
| 1293 | | { |
|---|
| 1294 | | $state = false; |
|---|
| 1295 | | foreach ( $markerdata as $markerline ) { |
|---|
| 1296 | | if (strpos($markerline, '# END ' . $marker) !== false) |
|---|
| 1297 | | $state = false; |
|---|
| 1298 | | if ( $state ) |
|---|
| 1299 | | $result[] = $markerline; |
|---|
| 1300 | | if (strpos($markerline, '# BEGIN ' . $marker) !== false) |
|---|
| 1301 | | $state = true; |
|---|
| 1302 | | } |
|---|
| 1303 | | } |
|---|
| 1304 | | |
|---|
| 1305 | | return $result; |
|---|
| 1306 | | } |
|---|
| 1307 | | |
|---|
| 1308 | | function got_mod_rewrite() { |
|---|
| 1309 | | global $is_apache; |
|---|
| 1310 | | |
|---|
| 1311 | | // take 3 educated guesses as to whether or not mod_rewrite is available |
|---|
| 1312 | | if ( !$is_apache ) |
|---|
| 1313 | | return false; |
|---|
| 1314 | | |
|---|
| 1315 | | if ( function_exists( 'apache_get_modules' ) ) { |
|---|
| 1316 | | if ( !in_array( 'mod_rewrite', apache_get_modules() ) ) |
|---|
| 1317 | | return false; |
|---|
| 1318 | | } |
|---|
| 1319 | | |
|---|
| 1320 | | return true; |
|---|
| 1321 | | } |
|---|
| 1322 | | |
|---|
| 1323 | | function save_mod_rewrite_rules() { |
|---|
| 1324 | | global $is_apache, $wp_rewrite; |
|---|
| 1325 | | $home_path = get_home_path(); |
|---|
| 1326 | | |
|---|
| 1327 | | if (!$wp_rewrite->using_mod_rewrite_permalinks() ) |
|---|
| 1328 | | return false; |
|---|
| 1329 | | |
|---|
| 1330 | | if (!((!file_exists( $home_path.'.htaccess' ) && is_writable( $home_path ) ) || is_writable( $home_path.'.htaccess' ) ) ) |
|---|
| 1331 | | return false; |
|---|
| 1332 | | |
|---|
| 1333 | | if (! got_mod_rewrite() ) |
|---|
| 1334 | | return false; |
|---|
| 1335 | | |
|---|
| 1336 | | $rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() ); |
|---|
| 1337 | | return insert_with_markers( $home_path.'.htaccess', 'WordPress', $rules ); |
|---|
| 1338 | | } |
|---|
| 1339 | | |
|---|
| 1340 | | function get_broken_themes() { |
|---|
| 1341 | | global $wp_broken_themes; |
|---|
| 1342 | | |
|---|
| 1343 | | get_themes(); |
|---|
| 1344 | | return $wp_broken_themes; |
|---|
| 1345 | | } |
|---|
| 1346 | | |
|---|
| 1347 | | function get_page_templates() { |
|---|
| 1348 | | $themes = get_themes(); |
|---|
| 1349 | | $theme = get_current_theme(); |
|---|
| 1350 | | $templates = $themes[$theme]['Template Files']; |
|---|
| 1351 | | $page_templates = array (); |
|---|
| 1352 | | |
|---|
| 1353 | | if ( is_array( $templates ) ) { |
|---|
| 1354 | | foreach ( $templates as $template ) { |
|---|
| 1355 | | $template_data = implode( '', file( ABSPATH.$template )); |
|---|
| 1356 | | preg_match( "|Template Name:(.*)|i", $template_data, $name ); |
|---|
| 1357 | | preg_match( "|Description:(.*)|i", $template_data, $description ); |
|---|
| 1358 | | |
|---|
| 1359 | | $name = $name[1]; |
|---|
| 1360 | | $description = $description[1]; |
|---|
| 1361 | | |
|---|
| 1362 | | if (!empty ( $name ) ) { |
|---|
| 1363 | | $page_templates[trim( $name )] = basename( $template ); |
|---|
| 1364 | | } |
|---|
| 1365 | | } |
|---|
| 1366 | | } |
|---|
| 1367 | | |
|---|
| 1368 | | return $page_templates; |
|---|
| 1369 | | } |
|---|
| 1370 | | |
|---|
| 1371 | | function page_template_dropdown( $default = '' ) { |
|---|
| 1372 | | $templates = get_page_templates(); |
|---|
| 1373 | | foreach (array_keys( $templates ) as $template ) |
|---|
| 1374 | | : if ( $default == $templates[$template] ) |
|---|
| 1375 | | $selected = " selected='selected'"; |
|---|
| 1376 | | else |
|---|
| 1377 | | $selected = ''; |
|---|
| 1378 | | echo "\n\t<option value='".$templates[$template]."' $selected>$template</option>"; |
|---|
| 1379 | | endforeach; |
|---|
| 1380 | | } |
|---|
| 1381 | | |
|---|
| 1382 | | function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) { |
|---|
| 1383 | | global $wpdb, $post_ID; |
|---|
| 1384 | | $items = $wpdb->get_results( "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = $parent AND post_type = 'page' ORDER BY menu_order" ); |
|---|
| 1385 | | |
|---|
| 1386 | | if ( $items ) { |
|---|
| 1387 | | foreach ( $items as $item ) { |
|---|
| 1388 | | // A page cannot be its own parent. |
|---|
| 1389 | | if (!empty ( $post_ID ) ) { |
|---|
| 1390 | | if ( $item->ID == $post_ID ) { |
|---|
| 1391 | | continue; |
|---|
| 1392 | | } |
|---|
| 1393 | | } |
|---|
| 1394 | | $pad = str_repeat( ' ', $level * 3 ); |
|---|
| 1395 | | if ( $item->ID == $default) |
|---|
| 1396 | | $current = ' selected="selected"'; |
|---|
| 1397 | | else |
|---|
| 1398 | | $current = ''; |
|---|
| 1399 | | |
|---|
| 1400 | | echo "\n\t<option value='$item->ID'$current>$pad $item->post_title</option>"; |
|---|
| 1401 | | parent_dropdown( $default, $item->ID, $level +1 ); |
|---|
| 1402 | | } |
|---|
| 1403 | | } else { |
|---|
| 1404 | | return false; |
|---|
| 1405 | | } |
|---|
| 1406 | | } |
|---|
| 1407 | | |
|---|
| 1408 | | function user_can_access_admin_page() { |
|---|
| 1409 | | global $pagenow; |
|---|
| 1410 | | global $menu; |
|---|
| 1411 | | global $submenu; |
|---|
| 1412 | | global $_wp_menu_nopriv; |
|---|
| 1413 | | global $_wp_submenu_nopriv; |
|---|
| 1414 | | global $plugin_page; |
|---|
| 1415 | | |
|---|
| 1416 | | $parent = get_admin_page_parent(); |
|---|
| 1417 | | |
|---|
| 1418 | | if ( isset( $_wp_submenu_nopriv[$parent][$pagenow] ) ) |
|---|
| 1419 | | return false; |
|---|
| 1420 | | |
|---|
| 1421 | | if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$parent][$plugin_page] ) ) |
|---|
| 1422 | | return false; |
|---|
| 1423 | | |
|---|
| 1424 | | if ( empty( $parent) ) { |
|---|
| 1425 | | if ( isset( $_wp_menu_nopriv[$pagenow] ) ) |
|---|
| 1426 | | return false; |
|---|
| 1427 | | if ( isset( $_wp_submenu_nopriv[$pagenow][$pagenow] ) ) |
|---|
| 1428 | | return false; |
|---|
| 1429 | | if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) ) |
|---|
| 1430 | | return false; |
|---|
| 1431 | | foreach (array_keys( $_wp_submenu_nopriv ) as $key ) { |
|---|
| 1432 | | if ( isset( $_wp_submenu_nopriv[$key][$pagenow] ) ) |
|---|
| 1433 | | return false; |
|---|
| 1434 | | if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$key][$plugin_page] ) ) |
|---|
| 1435 | | return false; |
|---|
| 1436 | | } |
|---|
| 1437 | | return true; |
|---|
| 1438 | | } |
|---|
| 1439 | | |
|---|
| 1440 | | if ( isset( $submenu[$parent] ) ) { |
|---|
| 1441 | | foreach ( $submenu[$parent] as $submenu_array ) { |
|---|
| 1442 | | if ( isset( $plugin_page ) && ( $submenu_array[2] == $plugin_page ) ) { |
|---|
| 1443 | | if ( current_user_can( $submenu_array[1] )) |
|---|
| 1444 | | return true; |
|---|
| 1445 | | else |
|---|
| 1446 | | return false; |
|---|
| 1447 | | } else if ( $submenu_array[2] == $pagenow ) { |
|---|
| 1448 | | if ( current_user_can( $submenu_array[1] )) |
|---|
| 1449 | | return true; |
|---|
| 1450 | | else |
|---|
| 1451 | | return false; |
|---|
| 1452 | | } |
|---|
| 1453 | | } |
|---|
| 1454 | | } |
|---|
| 1455 | | |
|---|
| 1456 | | foreach ( $menu as $menu_array ) { |
|---|
| 1457 | | if ( $menu_array[2] == $parent) { |
|---|
| 1458 | | if ( current_user_can( $menu_array[1] )) |
|---|
| 1459 | | return true; |
|---|
| 1460 | | else |
|---|
| 1461 | | return false; |
|---|
| 1462 | | } |
|---|
| 1463 | | } |
|---|
| 1464 | | |
|---|
| 1465 | | return true; |
|---|
| 1466 | | } |
|---|
| 1467 | | |
|---|
| 1468 | | function get_admin_page_title() { |
|---|
| 1469 | | global $title; |
|---|
| 1470 | | global $menu; |
|---|
| 1471 | | global $submenu; |
|---|
| 1472 | | global $pagenow; |
|---|
| 1473 | | global $plugin_page; |
|---|
| 1474 | | |
|---|
| 1475 | | if ( isset( $title ) && !empty ( $title ) ) { |
|---|
| 1476 | | return $title; |
|---|
| 1477 | | } |
|---|
| 1478 | | |
|---|
| 1479 | | $hook = get_plugin_page_hook( $plugin_page, $pagenow ); |
|---|
| 1480 | | |
|---|
| 1481 | | $parent = $parent1 = get_admin_page_parent(); |
|---|
| 1482 | | if ( empty ( $parent) ) { |
|---|
| 1483 | | foreach ( $menu as $menu_array ) { |
|---|
| 1484 | | if ( isset( $menu_array[3] ) ) { |
|---|
| 1485 | | if ( $menu_array[2] == $pagenow ) { |
|---|
| 1486 | | $title = $menu_array[3]; |
|---|
| 1487 | | return $menu_array[3]; |
|---|
| 1488 | | } else |
|---|
| 1489 | | if ( isset( $plugin_page ) && ($plugin_page == $menu_array[2] ) && ($hook == $menu_array[3] ) ) { |
|---|
| 1490 | | $title = $menu_array[3]; |
|---|
| 1491 | | return $menu_array[3]; |
|---|
| 1492 | | } |
|---|
| 1493 | | } else { |
|---|
| 1494 | | $title = $menu_array[0]; |
|---|
| 1495 | | return $title; |
|---|
| 1496 | | } |
|---|
| 1497 | | } |
|---|
| 1498 | | } else { |
|---|
| 1499 | | foreach (array_keys( $submenu ) as $parent) { |
|---|
| 1500 | | foreach ( $submenu[$parent] as $submenu_array ) { |
|---|
| 1501 | | if ( isset( $plugin_page ) && |
|---|
| 1502 | | ($plugin_page == $submenu_array[2] ) && |
|---|
| 1503 | | (($parent == $pagenow ) || ($parent == $plugin_page ) || ($plugin_page == $hook ) || (($pagenow == 'admin.php' ) && ($parent1 != $submenu_array[2] ) ) ) |
|---|
| 1504 | | ) { |
|---|
| 1505 | | $title = $submenu_array[3]; |
|---|
| 1506 | | return $submenu_array[3]; |
|---|
| 1507 | | } |
|---|
| 1508 | | |
|---|
| 1509 | | if ( $submenu_array[2] != $pagenow || isset( $_GET['page'] ) ) // not the current page |
|---|
| 1510 | | continue; |
|---|
| 1511 | | |
|---|
| 1512 | | if ( isset( $submenu_array[3] ) ) { |
|---|
| 1513 | | $title = $submenu_array[3]; |
|---|
| 1514 | | return $submenu_array[3]; |
|---|
| 1515 | | } else { |
|---|
| 1516 | | $title = $submenu_array[0]; |
|---|
| 1517 | | return $title; |
|---|
| 1518 | | } |
|---|
| 1519 | | } |
|---|
| 1520 | | } |
|---|
| 1521 | | } |
|---|
| 1522 | | |
|---|
| 1523 | | return $title; |
|---|
| 1524 | | } |
|---|
| 1525 | | |
|---|
| 1526 | | function get_admin_page_parent() { |
|---|
| 1527 | | global $parent_file; |
|---|
| 1528 | | global $menu; |
|---|
| 1529 | | global $submenu; |
|---|
| 1530 | | global $pagenow; |
|---|
| 1531 | | global $plugin_page; |
|---|
| 1532 | | global $_wp_real_parent_file; |
|---|
| 1533 | | global $_wp_menu_nopriv; |
|---|
| 1534 | | global $_wp_submenu_nopriv; |
|---|
| 1535 | | |
|---|
| 1536 | | if ( !empty ( $parent_file ) ) { |
|---|
| 1537 | | if ( isset( $_wp_real_parent_file[$parent_file] ) ) |
|---|
| 1538 | | $parent_file = $_wp_real_parent_file[$parent_file]; |
|---|
| 1539 | | |
|---|
| 1540 | | return $parent_file; |
|---|
| 1541 | | } |
|---|
| 1542 | | |
|---|
| 1543 | | if ( $pagenow == 'admin.php' && isset( $plugin_page ) ) { |
|---|
| 1544 | | foreach ( $menu as $parent_menu ) { |
|---|
| 1545 | | if ( $parent_menu[2] == $plugin_page ) { |
|---|
| 1546 | | $parent_file = $plugin_page; |
|---|
| 1547 | | if ( isset( $_wp_real_parent_file[$parent_file] ) ) |
|---|
| 1548 | | $parent_file = $_wp_real_parent_file[$parent_file]; |
|---|
| 1549 | | return $parent_file; |
|---|
| 1550 | | } |
|---|
| 1551 | | } |
|---|
| 1552 | | if ( isset( $_wp_menu_nopriv[$plugin_page] ) ) { |
|---|
| 1553 | | $parent_file = $plugin_page; |
|---|
| 1554 | | if ( isset( $_wp_real_parent_file[$parent_file] ) ) |
|---|
| 1555 | | $parent_file = $_wp_real_parent_file[$parent_file]; |
|---|
| 1556 | | return $parent_file; |
|---|
| 1557 | | } |
|---|
| 1558 | | } |
|---|
| 1559 | | |
|---|
| 1560 | | if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) ) { |
|---|
| 1561 | | $parent_file = $pagenow; |
|---|
| 1562 | | if ( isset( $_wp_real_parent_file[$parent_file] ) ) |
|---|
| 1563 | | $parent_file = $_wp_real_parent_file[$parent_file]; |
|---|
| 1564 | | return $parent_file; |
|---|
| 1565 | | } |
|---|
| 1566 | | |
|---|
| 1567 | | foreach (array_keys( $submenu ) as $parent) { |
|---|
| 1568 | | foreach ( $submenu[$parent] as $submenu_array ) { |
|---|
| 1569 | | if ( isset( $_wp_real_parent_file[$parent] ) ) |
|---|
| 1570 | | $parent = $_wp_real_parent_file[$parent]; |
|---|
| 1571 | | if ( $submenu_array[2] == $pagenow ) { |
|---|
| 1572 | | $parent_file = $parent; |
|---|
| 1573 | | return $parent; |
|---|
| 1574 | | } else |
|---|
| 1575 | | if ( isset( $plugin_page ) && ($plugin_page == $submenu_array[2] ) ) { |
|---|
| 1576 | | $parent_file = $parent; |
|---|
| 1577 | | return $parent; |
|---|
| 1578 | | } |
|---|
| 1579 | | } |
|---|
| 1580 | | } |
|---|
| 1581 | | |
|---|
| 1582 | | $parent_file = ''; |
|---|
| 1583 | | return ''; |
|---|
| 1584 | | } |
|---|
| 1585 | | |
|---|
| 1586 | | function add_menu_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { |
|---|
| 1587 | | global $menu, $admin_page_hooks; |
|---|
| 1588 | | |
|---|
| 1589 | | $file = plugin_basename( $file ); |
|---|
| 1590 | | |
|---|
| 1591 | | $menu[] = array ( $menu_title, $access_level, $file, $page_title ); |
|---|
| 1592 | | |
|---|
| 1593 | | $admin_page_hooks[$file] = sanitize_title( $menu_title ); |
|---|
| 1594 | | |
|---|
| 1595 | | $hookname = get_plugin_page_hookname( $file, '' ); |
|---|
| 1596 | | if (!empty ( $function ) && !empty ( $hookname )) |
|---|
| 1597 | | add_action( $hookname, $function ); |
|---|
| 1598 | | |
|---|
| 1599 | | return $hookname; |
|---|
| 1600 | | } |
|---|
| 1601 | | |
|---|
| 1602 | | function add_submenu_page( $parent, $page_title, $menu_title, $access_level, $file, $function = '' ) { |
|---|
| 1603 | | global $submenu; |
|---|
| 1604 | | global $menu; |
|---|
| 1605 | | global $_wp_real_parent_file; |
|---|
| 1606 | | global $_wp_submenu_nopriv; |
|---|
| 1607 | | global $_wp_menu_nopriv; |
|---|
| 1608 | | |
|---|
| 1609 | | $file = plugin_basename( $file ); |
|---|
| 1610 | | |
|---|
| 1611 | | $parent = plugin_basename( $parent); |
|---|
| 1612 | | if ( isset( $_wp_real_parent_file[$parent] ) ) |
|---|
| 1613 | | $parent = $_wp_real_parent_file[$parent]; |
|---|
| 1614 | | |
|---|
| 1615 | | if ( !current_user_can( $access_level ) ) { |
|---|
| 1616 | | $_wp_submenu_nopriv[$parent][$file] = true; |
|---|
| 1617 | | return false; |
|---|
| 1618 | | } |
|---|
| 1619 | | |
|---|
| 1620 | | // If the parent doesn't already have a submenu, add a link to the parent |
|---|
| 1621 | | // as the first item in the submenu. If the submenu file is the same as the |
|---|
| 1622 | | // parent file someone is trying to link back to the parent manually. In |
|---|
| 1623 | | // this case, don't automatically add a link back to avoid duplication. |
|---|
| 1624 | | if (!isset( $submenu[$parent] ) && $file != $parent ) { |
|---|
| 1625 | | foreach ( $menu as $parent_menu ) { |
|---|
| 1626 | | if ( $parent_menu[2] == $parent && current_user_can( $parent_menu[1] ) ) |
|---|
| 1627 | | $submenu[$parent][] = $parent_menu; |
|---|
| 1628 | | } |
|---|
| 1629 | | } |
|---|
| 1630 | | |
|---|
| 1631 | | $submenu[$parent][] = array ( $menu_title, $access_level, $file, $page_title ); |
|---|
| 1632 | | |
|---|
| 1633 | | $hookname = get_plugin_page_hookname( $file, $parent); |
|---|
| 1634 | | if (!empty ( $function ) && !empty ( $hookname )) |
|---|
| 1635 | | add_action( $hookname, $function ); |
|---|
| 1636 | | |
|---|
| 1637 | | return $hookname; |
|---|
| 1638 | | } |
|---|
| 1639 | | |
|---|
| 1640 | | function add_options_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { |
|---|
| 1641 | | return add_submenu_page( 'options-general.php', $page_title, $menu_title, $access_level, $file, $function ); |
|---|
| 1642 | | } |
|---|
| 1643 | | |
|---|
| 1644 | | function add_management_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { |
|---|
| 1645 | | return add_submenu_page( 'edit.php', $page_title, $menu_title, $access_level, $file, $function ); |
|---|
| 1646 | | } |
|---|
| 1647 | | |
|---|
| 1648 | | function add_theme_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { |
|---|
| 1649 | | return add_submenu_page( 'themes.php', $page_title, $menu_title, $access_level, $file, $function ); |
|---|
| 1650 | | } |
|---|
| 1651 | | |
|---|
| 1652 | | function add_users_page( $page_title, $menu_title, $access_level, $file, $function = '' ) { |
|---|
| 1653 | | if ( current_user_can('edit_users') ) |
|---|
| 1654 | | $parent = 'users.php'; |
|---|
| 1655 | | else |
|---|
| 1656 | | $parent = 'profile.php'; |
|---|
| 1657 | | return add_submenu_page( $parent, $page_title, $menu_title, $access_level, $file, $function ); |
|---|
| 1658 | | } |
|---|
| 1659 | | |
|---|
| 1660 | | function validate_file( $file, $allowed_files = '' ) { |
|---|
| 1661 | | if ( false !== strpos( $file, './' )) |
|---|
| 1662 | | return 1; |
|---|
| 1663 | | |
|---|
| 1664 | | if (':' == substr( $file, 1, 1 )) |
|---|
| 1665 | | return 2; |
|---|
| 1666 | | |
|---|
| 1667 | | if (!empty ( $allowed_files ) && (!in_array( $file, $allowed_files ) ) ) |
|---|
| 1668 | | return 3; |
|---|
| 1669 | | |
|---|
| 1670 | | return 0; |
|---|
| 1671 | | } |
|---|
| 1672 | | |
|---|
| 1673 | | function validate_file_to_edit( $file, $allowed_files = '' ) { |
|---|
| 1674 | | $file = stripslashes( $file ); |
|---|
| 1675 | | |
|---|
| 1676 | | $code = validate_file( $file, $allowed_files ); |
|---|
| 1677 | | |
|---|
| 1678 | | if (!$code ) |
|---|
| 1679 | | return $file; |
|---|
| 1680 | | |
|---|
| 1681 | | switch ( $code ) { |
|---|
| 1682 | | case 1 : |
|---|
| 1683 | | wp_die( __('Sorry, can’t edit files with ".." in the name. If you are trying to edit a file in your WordPress home directory, you can just type the name of the file in.' )); |
|---|
| 1684 | | |
|---|
| 1685 | | case 2 : |
|---|
| 1686 | | wp_die( __('Sorry, can’t call files with their real path.' )); |
|---|
| 1687 | | |
|---|
| 1688 | | case 3 : |
|---|
| 1689 | | wp_die( __('Sorry, that file cannot be edited.' )); |
|---|
| 1690 | | } |
|---|
| 1691 | | } |
|---|
| 1692 | | |
|---|
| 1693 | | function get_home_path() { |
|---|
| 1694 | | $home = get_option( 'home' ); |
|---|
| 1695 | | if ( $home != '' && $home != get_option( 'siteurl' ) ) { |
|---|
| 1696 | | $home_path = parse_url( $home ); |
|---|
| 1697 | | $home_path = $home_path['path']; |
|---|
| 1698 | | $root = str_replace( $_SERVER["PHP_SELF"], '', $_SERVER["SCRIPT_FILENAME"] ); |
|---|
| 1699 | | $home_path = trailingslashit( $root.$home_path ); |
|---|
| 1700 | | } else { |
|---|
| 1701 | | $home_path = ABSPATH; |
|---|
| 1702 | | } |
|---|
| 1703 | | |
|---|
| 1704 | | return $home_path; |
|---|
| 1705 | | } |
|---|
| 1706 | | |
|---|
| 1707 | | function get_real_file_to_edit( $file ) { |
|---|
| 1708 | | if ('index.php' == $file || '.htaccess' == $file ) { |
|---|
| 1709 | | $real_file = get_home_path().$file; |
|---|
| 1710 | | } else { |
|---|
| 1711 | | $real_file = ABSPATH.$file; |
|---|
| 1712 | | } |
|---|
| 1713 | | |
|---|
| 1714 | | return $real_file; |
|---|
| 1715 | | } |
|---|
| 1716 | | |
|---|
| 1717 | | $wp_file_descriptions = array ('index.php' => __( 'Main Index Template' ), 'style.css' => __( 'Stylesheet' ), 'comments.php' => __( 'Comments' ), 'comments-popup.php' => __( 'Popup Comments' ), 'footer.php' => __( 'Footer' ), 'header.php' => __( 'Header' ), 'sidebar.php' => __( 'Sidebar' ), 'archive.php' => __( 'Archives' ), 'category.php' => __( 'Category Template' ), 'page.php' => __( 'Page Template' ), 'search.php' => __( 'Search Results' ), 'single.php' => __( 'Single Post' ), '404.php' => __( '404 Template' ), 'my-hacks.php' => __( 'my-hacks.php (legacy hacks support)' ), '.htaccess' => __( '.htaccess (for rewrite rules )' ), |
|---|
| 1718 | | // Deprecated files |
|---|
| 1719 | | 'wp-layout.css' => __( 'Stylesheet' ), 'wp-comments.php' => __( 'Comments Template' ), 'wp-comments-popup.php' => __( 'Popup Comments Template' )); |
|---|
| 1720 | | |
|---|
| 1721 | | function get_file_description( $file ) { |
|---|
| 1722 | | global $wp_file_descriptions; |
|---|
| 1723 | | |
|---|
| 1724 | | if ( isset( $wp_file_descriptions[basename( $file )] ) ) { |
|---|
| 1725 | | return $wp_file_descriptions[basename( $file )]; |
|---|
| 1726 | | } |
|---|
| 1727 | | elseif ( file_exists( ABSPATH . $file ) && is_file( ABSPATH . $file ) ) { |
|---|
| 1728 | | $template_data = implode( '', file( ABSPATH . $file ) ); |
|---|
| 1729 | | if ( preg_match( "|Template Name:(.*)|i", $template_data, $name )) |
|---|
| 1730 | | return $name[1]; |
|---|
| 1731 | | } |
|---|
| 1732 | | |
|---|
| 1733 | | return basename( $file ); |
|---|
| 1734 | | } |
|---|
| 1735 | | |
|---|
| 1736 | | function update_recently_edited( $file ) { |
|---|
| 1737 | | $oldfiles = (array ) get_option( 'recently_edited' ); |
|---|
| 1738 | | if ( $oldfiles ) { |
|---|
| 1739 | | $oldfiles = array_reverse( $oldfiles ); |
|---|
| 1740 | | $oldfiles[] = $file; |
|---|
| 1741 | | $oldfiles = array_reverse( $oldfiles ); |
|---|
| 1742 | | $oldfiles = array_unique( $oldfiles ); |
|---|
| 1743 | | if ( 5 < count( $oldfiles )) |
|---|
| 1744 | | array_pop( $oldfiles ); |
|---|
| 1745 | | } else { |
|---|
| 1746 | | $oldfiles[] = $file; |
|---|
| 1747 | | } |
|---|
| 1748 | | update_option( 'recently_edited', $oldfiles ); |
|---|
| 1749 | | } |
|---|
| 1750 | | |
|---|
| 1751 | | function get_plugin_data( $plugin_file ) { |
|---|
| 1752 | | $plugin_data = implode( '', file( $plugin_file )); |
|---|
| 1753 | | preg_match( "|Plugin Name:(.*)|i", $plugin_data, $plugin_name ); |
|---|
| 1754 | | preg_match( "|Plugin URI:(.*)|i", $plugin_data, $plugin_uri ); |
|---|
| 1755 | | preg_match( "|Description:(.*)|i", $plugin_data, $description ); |
|---|
| 1756 | | preg_match( "|Author:(.*)|i", $plugin_data, $author_name ); |
|---|
| 1757 | | preg_match( "|Author URI:(.*)|i", $plugin_data, $author_uri ); |
|---|
| 1758 | | if ( preg_match( "|Version:(.*)|i", $plugin_data, $version )) |
|---|
| 1759 | | $version = trim( $version[1] ); |
|---|
| 1760 | | else |
|---|
| 1761 | | $version = ''; |
|---|
| 1762 | | |
|---|
| 1763 | | $description = wptexturize( trim( $description[1] )); |
|---|
| 1764 | | |
|---|
| 1765 | | $name = $plugin_name[1]; |
|---|
| 1766 | | $name = trim( $name ); |
|---|
| 1767 | | $plugin = $name; |
|---|
| 1768 | | if ('' != $plugin_uri[1] && '' != $name ) { |
|---|
| 1769 | | $plugin = '<a href="' . trim( $plugin_uri[1] ) . '" title="'.__( 'Visit plugin homepage' ).'">'.$plugin.'</a>'; |
|---|
| 1770 | | } |
|---|
| 1771 | | |
|---|
| 1772 | | if ('' == $author_uri[1] ) { |
|---|
| 1773 | | $author = trim( $author_name[1] ); |
|---|
| 1774 | | } else { |
|---|
| 1775 | | $author = '<a href="' . trim( $author_uri[1] ) . '" title="'.__( 'Visit author homepage' ).'">' . trim( $author_name[1] ) . '</a>'; |
|---|
| 1776 | | } |
|---|
| 1777 | | |
|---|
| 1778 | | return array('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version); |
|---|
| 1779 | | } |
|---|
| 1780 | | |
|---|
| 1781 | | function get_plugins() { |
|---|
| 1782 | | global $wp_plugins; |
|---|
| 1783 | | |
|---|
| 1784 | | if ( isset( $wp_plugins ) ) { |
|---|
| 1785 | | return $wp_plugins; |
|---|
| 1786 | | } |
|---|
| 1787 | | |
|---|
| 1788 | | $wp_plugins = array (); |
|---|
| 1789 | | $plugin_root = ABSPATH . PLUGINDIR; |
|---|
| 1790 | | |
|---|
| 1791 | | // Files in wp-content/plugins directory |
|---|
| 1792 | | $plugins_dir = @ dir( $plugin_root); |
|---|
| 1793 | | if ( $plugins_dir ) { |
|---|
| 1794 | | while (($file = $plugins_dir->read() ) !== false ) { |
|---|
| 1795 | | if ( substr($file, 0, 1) == '.' ) |
|---|
| 1796 | | continue; |
|---|
| 1797 | | if ( is_dir( $plugin_root.'/'.$file ) ) { |
|---|
| 1798 | | $plugins_subdir = @ dir( $plugin_root.'/'.$file ); |
|---|
| 1799 | | if ( $plugins_subdir ) { |
|---|
| 1800 | | while (($subfile = $plugins_subdir->read() ) !== false ) { |
|---|
| 1801 | | if ( substr($subfile, 0, 1) == '.' ) |
|---|
| 1802 | | continue; |
|---|
| 1803 | | if ( substr($subfile, -4) == '.php' ) |
|---|
| 1804 | | $plugin_files[] = "$file/$subfile"; |
|---|
| 1805 | | } |
|---|
| 1806 | | } |
|---|
| 1807 | | } else { |
|---|
| 1808 | | if ( substr($file, -4) == '.php' ) |
|---|
| 1809 | | $plugin_files[] = $file; |
|---|
| 1810 | | } |
|---|
| 1811 | | } |
|---|
| 1812 | | } |
|---|
| 1813 | | |
|---|
| 1814 | | if ( !$plugins_dir || !$plugin_files ) |
|---|
| 1815 | | return $wp_plugins; |
|---|
| 1816 | | |
|---|
| 1817 | | foreach ( $plugin_files as $plugin_file ) { |
|---|
| 1818 | | if ( !is_readable( "$plugin_root/$plugin_file" ) ) |
|---|
| 1819 | | continue; |
|---|
| 1820 | | |
|---|
| 1821 | | $plugin_data = get_plugin_data( "$plugin_root/$plugin_file" ); |
|---|
| 1822 | | |
|---|
| 1823 | | if ( empty ( $plugin_data['Name'] ) ) |
|---|
| 1824 | | continue; |
|---|
| 1825 | | |
|---|
| 1826 | | $wp_plugins[plugin_basename( $plugin_file )] = $plugin_data; |
|---|
| 1827 | | } |
|---|
| 1828 | | |
|---|
| 1829 | | uasort( $wp_plugins, create_function( '$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );' )); |
|---|
| 1830 | | |
|---|
| 1831 | | return $wp_plugins; |
|---|
| 1832 | | } |
|---|
| 1833 | | |
|---|
| 1834 | | function get_plugin_page_hookname( $plugin_page, $parent_page ) { |
|---|
| 1835 | | global $admin_page_hooks; |
|---|
| 1836 | | |
|---|
| 1837 | | $parent = get_admin_page_parent(); |
|---|
| 1838 | | |
|---|
| 1839 | | if ( empty ( $parent_page ) || 'admin.php' == $parent_page ) { |
|---|
| 1840 | | if ( isset( $admin_page_hooks[$plugin_page] )) |
|---|
| 1841 | | $page_type = 'toplevel'; |
|---|
| 1842 | | else |
|---|
| 1843 | | if ( isset( $admin_page_hooks[$parent] )) |
|---|
| 1844 | | $page_type = $admin_page_hooks[$parent]; |
|---|
| 1845 | | } else |
|---|
| 1846 | | if ( isset( $admin_page_hooks[$parent_page] ) ) { |
|---|
| 1847 | | $page_type = $admin_page_hooks[$parent_page]; |
|---|
| 1848 | | } else { |
|---|
| 1849 | | $page_type = 'admin'; |
|---|
| 1850 | | } |
|---|
| 1851 | | |
|---|
| 1852 | | $plugin_name = preg_replace( '!\.php!', '', $plugin_page ); |
|---|
| 1853 | | |
|---|
| 1854 | | return $page_type.'_page_'.$plugin_name; |
|---|
| 1855 | | } |
|---|
| 1856 | | |
|---|
| 1857 | | function get_plugin_page_hook( $plugin_page, $parent_page ) { |
|---|
| 1858 | | global $wp_filter; |
|---|
| 1859 | | |
|---|
| 1860 | | $hook = get_plugin_page_hookname( $plugin_page, $parent_page ); |
|---|
| 1861 | | if ( isset( $wp_filter[$hook] )) |
|---|
| 1862 | | return $hook; |
|---|
| 1863 | | else |
|---|
| 1864 | | return ''; |
|---|
| 1865 | | } |
|---|
| 1866 | | |
|---|
| 1867 | | function browse_happy() { |
|---|
| 1868 | | $getit = __( 'WordPress recommends a better browser' ); |
|---|
| 1869 | | echo ' |
|---|
| 1870 | | <p id="bh" style="text-align: center;"><a href="http://browsehappy.com/" title="'.$getit.'"><img src="images/browse-happy.gif" alt="Browse Happy" /></a></p> |
|---|
| 1871 | | '; |
|---|
| 1872 | | } |
|---|
| 1873 | | |
|---|
| 1874 | | if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) |
|---|
| 1875 | | add_action( 'admin_footer', 'browse_happy' ); |
|---|
| 1876 | | |
|---|
| 1877 | | function documentation_link( $for ) { |
|---|
| 1878 | | return; |
|---|
| 1879 | | } |
|---|
| 1880 | | |
|---|
| 1881 | | function register_importer( $id, $name, $description, $callback ) { |
|---|
| 1882 | | global $wp_importers; |
|---|
| 1883 | | |
|---|
| 1884 | | $wp_importers[$id] = array ( $name, $description, $callback ); |
|---|
| 1885 | | } |
|---|
| 1886 | | |
|---|
| 1887 | | function get_importers() { |
|---|
| 1888 | | global $wp_importers; |
|---|
| 1889 | | uasort($wp_importers, create_function('$a, $b', 'return strcmp($a[0], $b[0]);')); |
|---|
| 1890 | | return $wp_importers; |
|---|
| 1891 | | } |
|---|
| 1892 | | |
|---|
| 1893 | | function current_theme_info() { |
|---|
| 1894 | | $themes = get_themes(); |
|---|
| 1895 | | $current_theme = get_current_theme(); |
|---|
| 1896 | | $ct->name = $current_theme; |
|---|
| 1897 | | $ct->title = $themes[$current_theme]['Title']; |
|---|
| 1898 | | $ct->version = $themes[$current_theme]['Version']; |
|---|
| 1899 | | $ct->parent_theme = $themes[$current_theme]['Parent Theme']; |
|---|
| 1900 | | $ct->template_dir = $themes[$current_theme]['Template Dir']; |
|---|
| 1901 | | $ct->stylesheet_dir = $themes[$current_theme]['Stylesheet Dir']; |
|---|
| 1902 | | $ct->template = $themes[$current_theme]['Template']; |
|---|
| 1903 | | $ct->stylesheet = $themes[$current_theme]['Stylesheet']; |
|---|
| 1904 | | $ct->screenshot = $themes[$current_theme]['Screenshot']; |
|---|
| 1905 | | $ct->description = $themes[$current_theme]['Description']; |
|---|
| 1906 | | $ct->author = $themes[$current_theme]['Author']; |
|---|
| 1907 | | return $ct; |
|---|
| 1908 | | } |
|---|
| 1909 | | |
|---|
| 1910 | | |
|---|
| 1911 | | // array wp_handle_upload ( array &file [, array overrides] ) |
|---|
| 1912 | | // file: reference to a single element of $_FILES. Call the function once for each uploaded file. |
|---|
| 1913 | | // overrides: an associative array of names=>values to override default variables with extract( $overrides, EXTR_OVERWRITE ). |
|---|
| 1914 | | // On success, returns an associative array of file attributes. |
|---|
| 1915 | | // On failure, returns $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ). |
|---|
| 1916 | | function wp_handle_upload( &$file, $overrides = false ) { |
|---|
| 1917 | | // The default error handler. |
|---|
| 1918 | | if (! function_exists( 'wp_handle_upload_error' ) ) { |
|---|
| 1919 | | function wp_handle_upload_error( &$file, $message ) { |
|---|
| 1920 | | return array( 'error'=>$message ); |
|---|
| 1921 | | } |
|---|
| 1922 | | } |
|---|
| 1923 | | |
|---|
| 1924 | | // You may define your own function and pass the name in $overrides['upload_error_handler'] |
|---|
| 1925 | | $upload_error_handler = 'wp_handle_upload_error'; |
|---|
| 1926 | | |
|---|
| 1927 | | // $_POST['action'] must be set and its value must equal $overrides['action'] or this: |
|---|
| 1928 | | $action = 'wp_handle_upload'; |
|---|
| 1929 | | |
|---|
| 1930 | | // Courtesy of php.net, the strings that describe the error indicated in $_FILES[{form field}]['error']. |
|---|
| 1931 | | $upload_error_strings = array( false, |
|---|
| 1932 | | __( "The uploaded file exceeds the <code>upload_max_filesize</code> directive in <code>php.ini</code>." ), |
|---|
| 1933 | | __( "The uploaded file exceeds the <em>MAX_FILE_SIZE</em> directive that was specified in the HTML form." ), |
|---|
| 1934 | | __( "The uploaded file was only partially uploaded." ), |
|---|
| 1935 | | __( "No file was uploaded." ), |
|---|
| 1936 | | __( "Missing a temporary folder." ), |
|---|
| 1937 | | __( "Failed to write file to disk." )); |
|---|
| 1938 | | |
|---|
| 1939 | | // All tests are on by default. Most can be turned off by $override[{test_name}] = false; |
|---|
| 1940 | | $test_form = true; |
|---|
| 1941 | | $test_size = true; |
|---|
| 1942 | | |
|---|
| 1943 | | // If you override this, you must provide $ext and $type!!!! |
|---|
| 1944 | | $test_type = true; |
|---|
| 1945 | | |
|---|
| 1946 | | // Install user overrides. Did we mention that this voids your warranty? |
|---|
| 1947 | | if ( is_array( $overrides ) ) |
|---|
| 1948 | | extract( $overrides, EXTR_OVERWRITE ); |
|---|
| 1949 | | |
|---|
| 1950 | | // A correct form post will pass this test. |
|---|
| 1951 | | if ( $test_form && (!isset( $_POST['action'] ) || ($_POST['action'] != $action ) ) ) |
|---|
| 1952 | | return $upload_error_handler( $file, __( 'Invalid form submission.' )); |
|---|
| 1953 | | |
|---|
| 1954 | | // A successful upload will pass this test. It makes no sense to override this one. |
|---|
| 1955 | | if ( $file['error'] > 0 ) |
|---|
| 1956 | | return $upload_error_handler( $file, $upload_error_strings[$file['error']] ); |
|---|
| 1957 | | |
|---|
| 1958 | | // A non-empty file will pass this test. |
|---|
| 1959 | | if ( $test_size && !($file['size'] > 0 ) ) |
|---|
| 1960 | | return $upload_error_handler( $file, __( 'File is empty. Please upload something more substantial.' )); |
|---|
| 1961 | | |
|---|
| 1962 | | // A properly uploaded file will pass this test. There should be no reason to override this one. |
|---|
| 1963 | | if (! @ is_uploaded_file( $file['tmp_name'] ) ) |
|---|
| 1964 | | return $upload_error_handler( $file, __( 'Specified file failed upload test.' )); |
|---|
| 1965 | | |
|---|
| 1966 | | // A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter. |
|---|
| 1967 | | if ( $test_type ) { |
|---|
| 1968 | | $wp_filetype = wp_check_filetype( $file['name'], $mimes ); |
|---|
| 1969 | | |
|---|
| 1970 | | extract( $wp_filetype ); |
|---|
| 1971 | | |
|---|
| 1972 | | if ( !$type || !$ext ) |
|---|
| 1973 | | return $upload_error_handler( $file, __( 'File type does not meet security guidelines. Try another.' )); |
|---|
| 1974 | | } |
|---|
| 1975 | | |
|---|
| 1976 | | // A writable uploads dir will pass this test. Again, there's no point overriding this one. |
|---|
| 1977 | | if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) ) |
|---|
| 1978 | | return $upload_error_handler( $file, $uploads['error'] ); |
|---|
| 1979 | | |
|---|
| 1980 | | // Increment the file number until we have a unique file to save in $dir. Use $override['unique_filename_callback'] if supplied. |
|---|
| 1981 | | if ( isset( $unique_filename_callback ) && function_exists( $unique_filename_callback ) ) { |
|---|
| 1982 | | $filename = $unique_filename_callback( $uploads['path'], $file['name'] ); |
|---|
| 1983 | | } else { |
|---|
| 1984 | | $number = ''; |
|---|
| 1985 | | $filename = str_replace( '#', '_', $file['name'] ); |
|---|
| 1986 | | $filename = str_replace( array( '\\', "'" ), '', $filename ); |
|---|
| 1987 | | if ( empty( $ext) ) |
|---|
| 1988 | | $ext = ''; |
|---|
| 1989 | | else |
|---|
| 1990 | | $ext = ".$ext"; |
|---|
| 1991 | | while ( file_exists( $uploads['path'] . "/$filename" ) ) { |
|---|
| 1992 | | if ( '' == "$number$ext" ) |
|---|
| 1993 | | $filename = $filename . ++$number . $ext; |
|---|
| 1994 | | else |
|---|
| 1995 | | $filename = str_replace( "$number$ext", ++$number . $ext, $filename ); |
|---|
| 1996 | | } |
|---|
| 1997 | | $filename = str_replace( $ext, '', $filename ); |
|---|
| 1998 | | $filename = sanitize_title_with_dashes( $filename ) . $ext; |
|---|
| 1999 | | } |
|---|
| 2000 | | |
|---|
| 2001 | | // Move the file to the uploads dir |
|---|
| 2002 | | $new_file = $uploads['path'] . "/$filename"; |
|---|
| 2003 | | if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) ) |
|---|
| 2004 | | wp_die( printf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] )); |
|---|
| 2005 | | |
|---|
| 2006 | | // Set correct file permissions |
|---|
| 2007 | | $stat = stat( dirname( $new_file )); |
|---|
| 2008 | | $perms = $stat['mode'] & 0000666; |
|---|
| 2009 | | @ chmod( $new_file, $perms ); |
|---|
| 2010 | | |
|---|
| 2011 | | // Compute the URL |
|---|
| 2012 | | $url = $uploads['url'] . "/$filename"; |
|---|
| 2013 | | |
|---|
| 2014 | | $return = apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type ) ); |
|---|
| 2015 | | |
|---|
| 2016 | | return $return; |
|---|
| 2017 | | } |
|---|
| 2018 | | |
|---|
| 2019 | | function wp_shrink_dimensions( $width, $height, $wmax = 128, $hmax = 96 ) { |
|---|
| 2020 | | if ( $height <= $hmax && $width <= $wmax ) |
|---|
| 2021 | | return array( $width, $height); |
|---|
| 2022 | | elseif ( $width / $height > $wmax / $hmax ) |
|---|
| 2023 | | return array( $wmax, (int) ($height / $width * $wmax )); |
|---|
| 2024 | | else |
|---|
| 2025 | | return array( (int) ($width / $height * $hmax ), $hmax ); |
|---|
| 2026 | | } |
|---|
| 2027 | | |
|---|
| 2028 | | function wp_import_cleanup( $id ) { |
|---|
| 2029 | | wp_delete_attachment( $id ); |
|---|
| 2030 | | } |
|---|
| 2031 | | |
|---|
| 2032 | | function wp_import_upload_form( $action ) { |
|---|
| 2033 | | $size = strtolower( ini_get( 'upload_max_filesize' ) ); |
|---|
| 2034 | | $bytes = 0; |
|---|
| 2035 | | if (strpos($size, 'k') !== false) |
|---|
| 2036 | | $bytes = $size * 1024; |
|---|
| 2037 | | if (strpos($size, 'm') !== false) |
|---|
| 2038 | | $bytes = $size * 1024 * 1024; |
|---|
| 2039 | | if (strpos($size, 'g') !== false) |
|---|
| 2040 | | $bytes = $size * 1024 * 1024 * 1024; |
|---|
| 2041 | | $size = apply_filters( 'import_upload_size_limit', $size ); |
|---|
| 2042 | | ?> |
|---|
| 2043 | | <form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo attribute_escape($action) ?>"> |
|---|
| 2044 | | <p> |
|---|
| 2045 | | <?php wp_nonce_field('import-upload'); ?> |
|---|
| 2046 | | <label for="upload"><?php _e( 'Choose a file from your computer:' ); ?></label> (<?php printf( __('Maximum size: %s' ), $size ); ?> ) |
|---|
| 2047 | | <input type="file" id="upload" name="import" size="25" /> |
|---|
| 2048 | | <input type="hidden" name="action" value="save" /> |
|---|
| 2049 | | <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" /> |
|---|
| 2050 | | </p> |
|---|
| 2051 | | <p class="submit"> |
|---|
| 2052 | | <input type="submit" value="<?php _e( 'Upload file and import' ); ?> »" /> |
|---|
| 2053 | | </p> |
|---|
| 2054 | | </form> |
|---|
| 2055 | | <?php |
|---|
| 2056 | | } |
|---|
| 2057 | | |
|---|
| 2058 | | function wp_import_handle_upload() { |
|---|
| 2059 | | $overrides = array( 'test_form' => false, 'test_type' => false ); |
|---|
| 2060 | | $file = wp_handle_upload( $_FILES['import'], $overrides ); |
|---|
| 2061 | | |
|---|
| 2062 | | if ( isset( $file['error'] ) ) |
|---|
| 2063 | | return $file; |
|---|
| 2064 | | |
|---|
| 2065 | | $url = $file['url']; |
|---|
| 2066 | | $type = $file['type']; |
|---|
| 2067 | | $file = addslashes( $file['file'] ); |
|---|
| 2068 | | $filename = basename( $file ); |
|---|
| 2069 | | |
|---|
| 2070 | | // Construct the object array |
|---|
| 2071 | | $object = array( 'post_title' => $filename, |
|---|
| 2072 | | 'post_content' => $url, |
|---|
| 2073 | | 'post_mime_type' => $type, |
|---|
| 2074 | | 'guid' => $url |
|---|
| 2075 | | ); |
|---|
| 2076 | | |
|---|
| 2077 | | // Save the data |
|---|
| 2078 | | $id = wp_insert_attachment( $object, $file ); |
|---|
| 2079 | | |
|---|
| 2080 | | return array( 'file' => $file, 'id' => $id ); |
|---|
| 2081 | | } |
|---|
| 2082 | | |
|---|
| 2083 | | function the_attachment_links( $id = false ) { |
|---|
| 2084 | | $id = (int) $id; |
|---|
| 2085 | | $post = & get_post( $id ); |
|---|
| 2086 | | |
|---|
| 2087 | | if ( $post->post_type != 'attachment' ) |
|---|
| 2088 | | return false; |
|---|
| 2089 | | |
|---|
| 2090 | | $icon = get_attachment_icon( $post->ID ); |
|---|
| 2091 | | $attachment_data = wp_get_attachment_metadata( $id ); |
|---|
| 2092 | | $thumb = isset( $attachment_data['thumb'] ); |
|---|
| 2093 | | ?> |
|---|
| 2094 | | <form id="the-attachment-links"> |
|---|
| 2095 | | <table> |
|---|
| 2096 | | <col /> |
|---|
| 2097 | | <col class="widefat" /> |
|---|
| 2098 | | <tr> |
|---|
| 2099 | | <th scope="row"><?php _e( 'URL' ) ?></th> |
|---|
| 2100 | | <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><?php echo wp_get_attachment_url(); ?></textarea></td> |
|---|
| 2101 | | </tr> |
|---|
| 2102 | | <?php if ( $icon ) : ?> |
|---|
| 2103 | | <tr> |
|---|
| 2104 | | <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to file' ) : _e( 'Image linked to file' ); ?></th> |
|---|
| 2105 | | <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo wp_get_attachment_url(); ?>"><?php echo $icon ?></a></textarea></td> |
|---|
| 2106 | | </tr> |
|---|
| 2107 | | <tr> |
|---|
| 2108 | | <th scope="row"><?php $thumb ? _e( 'Thumbnail linked to page' ) : _e( 'Image linked to page' ); ?></th> |
|---|
| 2109 | | <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link( $post->ID ) ?>" rel="attachment wp-att-<?php echo $post->ID; ?>"><?php echo $icon ?></a></textarea></td> |
|---|
| 2110 | | </tr> |
|---|
| 2111 | | <?php else : ?> |
|---|
| 2112 | | <tr> |
|---|
| 2113 | | <th scope="row"><?php _e( 'Link to file' ) ?></th> |
|---|
| 2114 | | <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo wp_get_attachment_url(); ?>" class="attachmentlink"><?php echo basename( wp_get_attachment_url() ); ?></a></textarea></td> |
|---|
| 2115 | | </tr> |
|---|
| 2116 | | <tr> |
|---|
| 2117 | | <th scope="row"><?php _e( 'Link to page' ) ?></th> |
|---|
| 2118 | | <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link( $post->ID ) ?>" rel="attachment wp-att-<?php echo $post->ID ?>"><?php the_title(); ?></a></textarea></td> |
|---|
| 2119 | | </tr> |
|---|
| 2120 | | <?php endif; ?> |
|---|
| 2121 | | </table> |
|---|
| 2122 | | </form> |
|---|
| 2123 | | <?php |
|---|
| 2124 | | } |
|---|
| 2125 | | |
|---|
| 2126 | | function get_udims( $width, $height) { |
|---|
| 2127 | | if ( $height <= 96 && $width <= 128 ) |
|---|
| 2128 | | return array( $width, $height); |
|---|
| 2129 | | elseif ( $width / $height > 4 / 3 ) |
|---|
| 2130 | | return array( 128, (int) ($height / $width * 128 )); |
|---|
| 2131 | | else |
|---|
| 2132 | | return array( (int) ($width / $height * 96 ), 96 ); |
|---|
| 2133 | | } |
|---|
| 2134 | | |
|---|
| 2135 | | function wp_reset_vars( $vars ) { |
|---|
| 2136 | | for ( $i=0; $i<count( $vars ); $i += 1 ) { |
|---|
| 2137 | | $var = $vars[$i]; |
|---|
| 2138 | | global $$var; |
|---|
| 2139 | | |
|---|
| 2140 | | if (!isset( $$var ) ) { |
|---|
| 2141 | | if ( empty( $_POST["$var"] ) ) { |
|---|
| 2142 | | if ( empty( $_GET["$var"] ) ) |
|---|
| 2143 | | $$var = ''; |
|---|
| 2144 | | else |
|---|
| 2145 | | $$var = $_GET["$var"]; |
|---|
| 2146 | | } else { |
|---|
| 2147 | | $$var = $_POST["$var"]; |
|---|
| 2148 | | } |
|---|
| 2149 | | } |
|---|
| 2150 | | } |
|---|
| 2151 | | } |
|---|
| 2152 | | |
|---|
| 2153 | | |
|---|
| 2154 | | function wp_remember_old_slug() { |
|---|
| 2155 | | global $post; |
|---|
| 2156 | | $name = attribute_escape($post->post_name); // just in case |
|---|
| 2157 | | if ( strlen($name) ) |
|---|
| 2158 | | echo '<input type="hidden" id="wp-old-slug" name="wp-old-slug" value="' . $name . '" />'; |
|---|
| 2159 | | } |
|---|
| 2160 | | |
|---|
| 2161 | | |
|---|
| 2162 | | // If siteurl or home changed, reset cookies and flush rewrite rules. |
|---|
| 2163 | | function update_home_siteurl( $old_value, $value ) { |
|---|
| 2164 | | global $wp_rewrite, $user_login, $user_pass_md5; |
|---|
| 2165 | | |
|---|
| 2166 | | if ( defined( "WP_INSTALLING" ) ) |
|---|
| 2167 | | return; |
|---|
| 2168 | | |
|---|
| 2169 | | // If home changed, write rewrite rules to new location. |
|---|
| 2170 | | $wp_rewrite->flush_rules(); |
|---|
| 2171 | | // Clear cookies for old paths. |
|---|
| 2172 | | wp_clearcookie(); |
|---|
| 2173 | | // Set cookies for new paths. |
|---|
| 2174 | | wp_setcookie( $user_login, $user_pass_md5, true, get_option( 'home' ), get_option( 'siteurl' )); |
|---|
| 2175 | | } |
|---|
| 2176 | | |
|---|
| 2177 | | add_action( 'update_option_home', 'update_home_siteurl', 10, 2 ); |
|---|
| 2178 | | add_action( 'update_option_siteurl', 'update_home_siteurl', 10, 2 ); |
|---|
| 2179 | | |
|---|
| 2180 | | function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) { |
|---|
| 2181 | | if ( ctype_digit( $src_file ) ) // Handle int as attachment ID |
|---|
| 2182 | | $src_file = get_attached_file( $src_file ); |
|---|
| 2183 | | |
|---|
| 2184 | | $src = wp_load_image( $src_file ); |
|---|
| 2185 | | |
|---|
| 2186 | | if ( !is_resource( $src )) |
|---|
| 2187 | | return $src; |
|---|
| 2188 | | |
|---|
| 2189 | | $dst = imagecreatetruecolor( $dst_w, $dst_h ); |
|---|
| 2190 | | |
|---|
| 2191 | | if ( $src_abs ) { |
|---|
| 2192 | | $src_w -= $src_x; |
|---|
| 2193 | | $src_h -= $src_y; |
|---|
| 2194 | | } |
|---|
| 2195 | | |
|---|
| 2196 | | if (function_exists('imageantialias')) |
|---|
| 2197 | | imageantialias( $dst, true ); |
|---|
| 2198 | | |
|---|
| 2199 | | imagecopyresampled( $dst, $src, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ); |
|---|
| 2200 | | |
|---|
| 2201 | | if ( !$dst_file ) |
|---|
| 2202 | | $dst_file = str_replace( basename( $src_file ), 'cropped-'.basename( $src_file ), $src_file ); |
|---|
| 2203 | | |
|---|
| 2204 | | $dst_file = preg_replace( '/\\.[^\\.]+$/', '.jpg', $dst_file ); |
|---|
| 2205 | | |
|---|
| 2206 | | if ( imagejpeg( $dst, $dst_file ) ) |
|---|
| 2207 | | return $dst_file; |
|---|
| 2208 | | else |
|---|
| 2209 | | return false; |
|---|
| 2210 | | } |
|---|
| 2211 | | |
|---|
| 2212 | | function wp_load_image( $file ) { |
|---|
| 2213 | | if ( ctype_digit( $file ) ) |
|---|
| 2214 | | $file = get_attached_file( $file ); |
|---|
| 2215 | | |
|---|
| 2216 | | if ( !file_exists( $file ) ) |
|---|
| 2217 | | return sprintf(__("File '%s' doesn't exist?"), $file); |
|---|
| 2218 | | |
|---|
| 2219 | | if ( ! function_exists('imagecreatefromstring') ) |
|---|
| 2220 | | return __('The GD image library is not installed.'); |
|---|
| 2221 | | |
|---|
| 2222 | | $contents = file_get_contents( $file ); |
|---|
| 2223 | | |
|---|
| 2224 | | $image = imagecreatefromstring( $contents ); |
|---|
| 2225 | | |
|---|
| 2226 | | if ( !is_resource( $image ) ) |
|---|
| 2227 | | return sprintf(__("File '%s' is not an image."), $file); |
|---|
| 2228 | | |
|---|
| 2229 | | return $image; |
|---|
| 2230 | | } |
|---|
| 2231 | | |
|---|
| 2232 | | function wp_generate_attachment_metadata( $attachment_id, $file ) { |
|---|
| 2233 | | $attachment = get_post( $attachment_id ); |
|---|
| 2234 | | |
|---|
| 2235 | | $metadata = array(); |
|---|
| 2236 | | if ( preg_match('!^image/!', get_post_mime_type( $attachment )) ) { |
|---|
| 2237 | | $imagesize = getimagesize($file); |
|---|
| 2238 | | $metadata['width'] = $imagesize['0']; |
|---|
| 2239 | | $metadata['height'] = $imagesize['1']; |
|---|
| 2240 | | list($uwidth, $uheight) = get_udims($metadata['width'], $metadata['height']); |
|---|
| 2241 | | $metadata['hwstring_small'] = "height='$uheight' width='$uwidth'"; |
|---|
| 2242 | | $metadata['file'] = $file; |
|---|
| 2243 | | |
|---|
| 2244 | | $max = apply_filters( 'wp_thumbnail_creation_size_limit', 3 * 1024 * 1024, $attachment_id, $file ); |
|---|
| 2245 | | |
|---|
| 2246 | | if ( $max < 0 || $metadata['width'] * $metadata['height'] < $max ) { |
|---|
| 2247 | | $max_side = apply_filters( 'wp_thumbnail_max_side_length', 128, $attachment_id, $file ); |
|---|
| 2248 | | $thumb = wp_create_thumbnail( $file, $max_side ); |
|---|
| 2249 | | |
|---|
| 2250 | | if ( @file_exists($thumb) ) |
|---|
| 2251 | | $metadata['thumb'] = basename($thumb); |
|---|
| 2252 | | } |
|---|
| 2253 | | } |
|---|
| 2254 | | return apply_filters( 'wp_generate_attachment_metadata', $metadata ); |
|---|
| 2255 | | } |
|---|
| 2256 | | |
|---|
| 2257 | | function wp_create_thumbnail( $file, $max_side, $effect = '' ) { |
|---|
| 2258 | | |
|---|
| 2259 | | // 1 = GIF, 2 = JPEG, 3 = PNG |
|---|
| 2260 | | |
|---|
| 2261 | | if ( file_exists( $file ) ) { |
|---|
| 2262 | | $type = getimagesize( $file ); |
|---|
| 2263 | | |
|---|
| 2264 | | // if the associated function doesn't exist - then it's not |
|---|
| 2265 | | // handle. duh. i hope. |
|---|
| 2266 | | |
|---|
| 2267 | | if (!function_exists( 'imagegif' ) && $type[2] == 1 ) { |
|---|
| 2268 | | $error = __( 'Filetype not supported. Thumbnail not created.' ); |
|---|
| 2269 | | } |
|---|
| 2270 | | elseif (!function_exists( 'imagejpeg' ) && $type[2] == 2 ) { |
|---|
| 2271 | | $error = __( 'Filetype not supported. Thumbnail not created.' ); |
|---|
| 2272 | | } |
|---|
| 2273 | | elseif (!function_exists( 'imagepng' ) && $type[2] == 3 ) { |
|---|
| 2274 | | $error = __( 'Filetype not supported. Thumbnail not created.' ); |
|---|
| 2275 | | } else { |
|---|
| 2276 | | |
|---|
| 2277 | | // create the initial copy from the original file |
|---|
| 2278 | | if ( $type[2] == 1 ) { |
|---|
| 2279 | | $image = imagecreatefromgif( $file ); |
|---|
| 2280 | | } |
|---|
| 2281 | | elseif ( $type[2] == 2 ) { |
|---|
| 2282 | | $image = imagecreatefromjpeg( $file ); |
|---|
| 2283 | | } |
|---|
| 2284 | | elseif ( $type[2] == 3 ) { |
|---|
| 2285 | | $image = imagecreatefrompng( $file ); |
|---|
| 2286 | | } |
|---|
| 2287 | | |
|---|
| 2288 | | if ( function_exists( 'imageantialias' )) |
|---|
| 2289 | | imageantialias( $image, TRUE ); |
|---|
| 2290 | | |
|---|
| 2291 | | $image_attr = getimagesize( $file ); |
|---|
| 2292 | | |
|---|
| 2293 | | // figure out the longest side |
|---|
| 2294 | | |
|---|
| 2295 | | if ( $image_attr[0] > $image_attr[1] ) { |
|---|
| 2296 | | $image_width = $image_attr[0]; |
|---|
| 2297 | | $image_height = $image_attr[1]; |
|---|
| 2298 | | $image_new_width = $max_side; |
|---|
| 2299 | | |
|---|
| 2300 | | $image_ratio = $image_width / $image_new_width; |
|---|
| 2301 | | $image_new_height = $image_height / $image_ratio; |
|---|
| 2302 | | //width is > height |
|---|
| 2303 | | } else { |
|---|
| 2304 | | $image_width = $image_attr[0]; |
|---|
| 2305 | | $image_height = $image_attr[1]; |
|---|
| 2306 | | $image_new_height = $max_side; |
|---|
| 2307 | | |
|---|
| 2308 | | $image_ratio = $image_height / $image_new_height; |
|---|
| 2309 | | $image_new_width = $image_width / $image_ratio; |
|---|
| 2310 | | //height > width |
|---|
| 2311 | | } |
|---|
| 2312 | | |
|---|
| 2313 | | $thumbnail = imagecreatetruecolor( $image_new_width, $image_new_height); |
|---|
| 2314 | | @ imagecopyresampled( $thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1] ); |
|---|
| 2315 | | |
|---|
| 2316 | | // If no filters change the filename, we'll do a default transformation. |
|---|
| 2317 | | if ( basename( $file ) == $thumb = apply_filters( 'thumbnail_filename', basename( $file ) ) ) |
|---|
| 2318 | | $thumb = preg_replace( '!(\.[^.]+)?$!', '.thumbnail' . '$1', basename( $file ), 1 ); |
|---|
| 2319 | | |
|---|
| 2320 | | $thumbpath = str_replace( basename( $file ), $thumb, $file ); |
|---|
| 2321 | | |
|---|
| 2322 | | // move the thumbnail to its final destination |
|---|
| 2323 | | if ( $type[2] == 1 ) { |
|---|
| 2324 | | if (!imagegif( $thumbnail, $thumbpath ) ) { |
|---|
| 2325 | | $error = __( "Thumbnail path invalid" ); |
|---|
| 2326 | | } |
|---|
| 2327 | | } |
|---|
| 2328 | | elseif ( $type[2] == 2 ) { |
|---|
| 2329 | | if (!imagejpeg( $thumbnail, $thumbpath ) ) { |
|---|
| 2330 | | $error = __( "Thumbnail path invalid" ); |
|---|
| 2331 | | } |
|---|
| 2332 | | } |
|---|
| 2333 | | elseif ( $type[2] == 3 ) { |
|---|
| 2334 | | if (!imagepng( $thumbnail, $thumbpath ) ) { |
|---|
| 2335 | | $error = __( "Thumbnail path invalid" ); |
|---|
| 2336 | | } |
|---|
| 2337 | | } |
|---|
| 2338 | | |
|---|
| 2339 | | } |
|---|
| 2340 | | } else { |
|---|
| 2341 | | $error = __( 'File not found' ); |
|---|
| 2342 | | } |
|---|
| 2343 | | |
|---|
| 2344 | | if (!empty ( $error ) ) { |
|---|
| 2345 | | return $error; |
|---|
| 2346 | | } else { |
|---|
| 2347 | | return apply_filters( 'wp_create_thumbnail', $thumbpath ); |
|---|
| 2348 | | } |
|---|
| 2349 | | } |
|---|
| 2350 | | |
|---|
| 2351 | | function update_blog_public($old_value, $value) { |
|---|
| 2352 | | global $wpdb; |
|---|
| 2353 | | $value = (int) $value; |
|---|
| 2354 | | do_action('update_blog_public'); |
|---|
| 2355 | | update_blog_status( $wpdb->blogid, 'public', $value ); |
|---|
| 2356 | | } |
|---|
| 2357 | | |
|---|
| 2358 | | add_action('update_option_blog_public', 'update_blog_public', 10, 2); |
|---|
| 2359 | | |
|---|
| 2360 | | function update_option_new_admin_email($old_value, $value) { |
|---|
| 2361 | | if ( $value == get_option( 'admin_email' ) || !is_email( $value ) ) |
|---|
| 2362 | | return; |
|---|
| 2363 | | |
|---|
| 2364 | | $hash = md5( $value.time().mt_rand() ); |
|---|
| 2365 | | $newadminemail = array( |
|---|
| 2366 | | "hash" => $hash, |
|---|
| 2367 | | "newemail" => $value |
|---|
| 2368 | | ); |
|---|
| 2369 | | update_option( 'adminhash', $newadminemail ); |
|---|
| 2370 | | |
|---|
| 2371 | | $content = __("Dear user,\n\n |
|---|
| 2372 | | You recently requested to have the administration email address on |
|---|
| 2373 | | your blog changed.\n |
|---|
| 2374 | | If this is correct, please click on the following link to change it:\n |
|---|
| 2375 | | ###ADMIN_URL###\n\n |
|---|
| 2376 | | You can safely ignore and delete this email if you do not want to take this action.\n\n |
|---|
| 2377 | | This email has been sent to ###EMAIL###\n\n |
|---|
| 2378 | | Regards,\n |
|---|
| 2379 | | The Webmaster"); |
|---|
| 2380 | | |
|---|
| 2381 | | $content = str_replace('###ADMIN_URL###', get_option( "siteurl" ).'/wp-admin/options.php?adminhash='.$hash, $content); |
|---|
| 2382 | | $content = str_replace('###EMAIL###', $value, $content); |
|---|
| 2383 | | |
|---|
| 2384 | | wp_mail( $value, sprintf(__('[%s] New Admin Email Address'), get_option('blogname')), $content ); |
|---|
| 2385 | | } |
|---|
| 2386 | | |
|---|
| 2387 | | add_action('update_option_new_admin_email', 'update_option_new_admin_email', 10, 2); |
|---|
| 2388 | | ?> |
|---|