Projects : mp-wp : mp-wp_svg-screenshots-and-errorreporting-r2
1 | <?php |
2 | /** |
3 | * WordPress Administration Media API. |
4 | * |
5 | * @package WordPress |
6 | * @subpackage Administration |
7 | */ |
8 | |
9 | /** |
10 | * {@internal Missing Short Description}} |
11 | * |
12 | * @since unknown |
13 | * |
14 | * @return unknown |
15 | */ |
16 | function media_upload_tabs() { |
17 | $_default_tabs = array( |
18 | 'type' => __('From Computer'), // handler action suffix => tab text |
19 | 'type_url' => __('From URL'), |
20 | 'gallery' => __('Gallery'), |
21 | 'library' => __('Media Library') |
22 | ); |
23 | |
24 | return apply_filters('media_upload_tabs', $_default_tabs); |
25 | } |
26 | |
27 | /** |
28 | * {@internal Missing Short Description}} |
29 | * |
30 | * @since unknown |
31 | * |
32 | * @param unknown_type $tabs |
33 | * @return unknown |
34 | */ |
35 | function update_gallery_tab($tabs) { |
36 | global $wpdb; |
37 | |
38 | if ( !isset($_REQUEST['post_id']) ) { |
39 | unset($tabs['gallery']); |
40 | return $tabs; |
41 | } |
42 | |
43 | if ( intval($_REQUEST['post_id']) ) |
44 | $attachments = intval($wpdb->get_var($wpdb->prepare("SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $_REQUEST['post_id']))); |
45 | |
46 | if ( empty($attachments) ) { |
47 | unset($tabs['gallery']); |
48 | return $tabs; |
49 | } |
50 | |
51 | $tabs['gallery'] = sprintf(__('Gallery (%s)'), "<span id='attachments-count'>$attachments</span>"); |
52 | |
53 | return $tabs; |
54 | } |
55 | add_filter('media_upload_tabs', 'update_gallery_tab'); |
56 | |
57 | /** |
58 | * {@internal Missing Short Description}} |
59 | * |
60 | * @since unknown |
61 | */ |
62 | function the_media_upload_tabs() { |
63 | global $redir_tab; |
64 | $tabs = media_upload_tabs(); |
65 | |
66 | if ( !empty($tabs) ) { |
67 | echo "<ul id='sidemenu'>\n"; |
68 | if ( isset($redir_tab) && array_key_exists($redir_tab, $tabs) ) |
69 | $current = $redir_tab; |
70 | elseif ( isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) ) |
71 | $current = $_GET['tab']; |
72 | else { |
73 | $keys = array_keys($tabs); |
74 | $current = array_shift($keys); |
75 | } |
76 | foreach ( $tabs as $callback => $text ) { |
77 | $class = ''; |
78 | if ( $current == $callback ) |
79 | $class = " class='current'"; |
80 | $href = add_query_arg(array('tab'=>$callback, 's'=>false, 'paged'=>false, 'post_mime_type'=>false, 'm'=>false)); |
81 | $link = "<a href='" . clean_url($href) . "'$class>$text</a>"; |
82 | echo "\t<li id='" . attribute_escape("tab-$callback") . "'>$link</li>\n"; |
83 | } |
84 | echo "</ul>\n"; |
85 | } |
86 | } |
87 | |
88 | /** |
89 | * {@internal Missing Short Description}} |
90 | * |
91 | * @since unknown |
92 | * |
93 | * @param unknown_type $id |
94 | * @param unknown_type $alt |
95 | * @param unknown_type $title |
96 | * @param unknown_type $align |
97 | * @param unknown_type $url |
98 | * @param unknown_type $rel |
99 | * @param unknown_type $size |
100 | * @return unknown |
101 | */ |
102 | function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = false, $size='medium') { |
103 | |
104 | $htmlalt = ( empty($alt) ) ? $title : $alt; |
105 | |
106 | $html = get_image_tag($id, $htmlalt, $title, $align, $size); |
107 | |
108 | $rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : ''; |
109 | |
110 | if ( $url ) |
111 | $html = '<a href="' . clean_url($url) . "\"$rel>$html</a>"; |
112 | |
113 | $html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url, $size ); |
114 | |
115 | return $html; |
116 | } |
117 | |
118 | /** |
119 | * {@internal Missing Short Description}} |
120 | * |
121 | * @since unknown |
122 | * |
123 | * @param unknown_type $html |
124 | * @param unknown_type $id |
125 | * @param unknown_type $alt |
126 | * @param unknown_type $title |
127 | * @param unknown_type $align |
128 | * @param unknown_type $url |
129 | * @param unknown_type $size |
130 | * @return unknown |
131 | */ |
132 | function image_add_caption( $html, $id, $alt, $title, $align, $url, $size ) { |
133 | |
134 | if ( empty($alt) || apply_filters( 'disable_captions', '' ) ) return $html; |
135 | $id = ( 0 < (int) $id ) ? 'attachment_' . $id : ''; |
136 | |
137 | preg_match( '/width="([0-9]+)/', $html, $matches ); |
138 | if ( ! isset($matches[1]) ) return $html; |
139 | $width = $matches[1]; |
140 | |
141 | $html = preg_replace( '/align[^\s\'"]+\s?/', '', $html ); |
142 | if ( empty($align) ) $align = 'none'; |
143 | |
144 | $alt = ! empty($alt) ? addslashes($alt) : ''; |
145 | |
146 | $shcode = '[caption id="' . $id . '" align="align' . $align |
147 | . '" width="' . $width . '" caption="' . $alt . '"]' . $html . '[/caption]'; |
148 | |
149 | return apply_filters( 'image_add_caption_shortcode', $shcode, $html ); |
150 | } |
151 | add_filter( 'image_send_to_editor', 'image_add_caption', 20, 7 ); |
152 | |
153 | /** |
154 | * {@internal Missing Short Description}} |
155 | * |
156 | * @since unknown |
157 | * |
158 | * @param unknown_type $html |
159 | */ |
160 | function media_send_to_editor($html) { |
161 | ?> |
162 | <script type="text/javascript"> |
163 | /* <![CDATA[ */ |
164 | var win = window.dialogArguments || opener || parent || top; |
165 | win.send_to_editor('<?php echo addslashes($html); ?>'); |
166 | /* ]]> */ |
167 | </script> |
168 | <?php |
169 | exit; |
170 | } |
171 | |
172 | /** |
173 | * {@internal Missing Short Description}} |
174 | * |
175 | * This handles the file upload POST itself, creating the attachment post. |
176 | * |
177 | * @since unknown |
178 | * |
179 | * @param unknown_type $file_id |
180 | * @param unknown_type $post_id |
181 | * @param unknown_type $post_data |
182 | * @return unknown |
183 | */ |
184 | function media_handle_upload($file_id, $post_id, $post_data = array()) { |
185 | $overrides = array('test_form'=>false); |
186 | |
187 | $time = current_time('mysql'); |
188 | if ( $post = get_post($post_id) ) { |
189 | if ( substr( $post->post_date, 0, 4 ) > 0 ) |
190 | $time = $post->post_date; |
191 | } |
192 | |
193 | $file = wp_handle_upload($_FILES[$file_id], $overrides, $time); |
194 | |
195 | if ( isset($file['error']) ) |
196 | return new WP_Error( 'upload_error', $file['error'] ); |
197 | |
198 | $url = $file['url']; |
199 | $type = $file['type']; |
200 | $file = $file['file']; |
201 | $title = preg_replace('/\.[^.]+$/', '', basename($file)); |
202 | $content = ''; |
203 | |
204 | // use image exif/iptc data for title and caption defaults if possible |
205 | if ( $image_meta = @wp_read_image_metadata($file) ) { |
206 | if ( trim($image_meta['title']) ) |
207 | $title = $image_meta['title']; |
208 | if ( trim($image_meta['caption']) ) |
209 | $content = $image_meta['caption']; |
210 | } |
211 | |
212 | // Construct the attachment array |
213 | $attachment = array_merge( array( |
214 | 'post_mime_type' => $type, |
215 | 'guid' => $url, |
216 | 'post_parent' => $post_id, |
217 | 'post_title' => $title, |
218 | 'post_content' => $content, |
219 | ), $post_data ); |
220 | |
221 | // Save the data |
222 | $id = wp_insert_attachment($attachment, $file, $post_id); |
223 | if ( !is_wp_error($id) ) { |
224 | wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); |
225 | } |
226 | |
227 | return $id; |
228 | |
229 | } |
230 | |
231 | /** |
232 | * {@internal Missing Short Description}} |
233 | * |
234 | * @since unknown |
235 | * |
236 | * @param unknown_type $file_array |
237 | * @param unknown_type $post_id |
238 | * @param unknown_type $desc |
239 | * @param unknown_type $post_data |
240 | * @return unknown |
241 | */ |
242 | function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) { |
243 | $overrides = array('test_form'=>false); |
244 | $file = wp_handle_sideload($file_array, $overrides); |
245 | |
246 | if ( isset($file['error']) ) |
247 | return new WP_Error( 'upload_error', $file['error'] ); |
248 | |
249 | $url = $file['url']; |
250 | $type = $file['type']; |
251 | $file = $file['file']; |
252 | $title = preg_replace('/\.[^.]+$/', '', basename($file)); |
253 | $content = ''; |
254 | |
255 | // use image exif/iptc data for title and caption defaults if possible |
256 | if ( $image_meta = @wp_read_image_metadata($file) ) { |
257 | if ( trim($image_meta['title']) ) |
258 | $title = $image_meta['title']; |
259 | if ( trim($image_meta['caption']) ) |
260 | $content = $image_meta['caption']; |
261 | } |
262 | |
263 | $title = @$desc; |
264 | |
265 | // Construct the attachment array |
266 | $attachment = array_merge( array( |
267 | 'post_mime_type' => $type, |
268 | 'guid' => $url, |
269 | 'post_parent' => $post_id, |
270 | 'post_title' => $title, |
271 | 'post_content' => $content, |
272 | ), $post_data ); |
273 | |
274 | // Save the data |
275 | $id = wp_insert_attachment($attachment, $file, $post_id); |
276 | if ( !is_wp_error($id) ) { |
277 | wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); |
278 | return $url; |
279 | } |
280 | return $id; |
281 | } |
282 | |
283 | /** |
284 | * {@internal Missing Short Description}} |
285 | * |
286 | * Wrap iframe content (produced by $content_func) in a doctype, html head/body |
287 | * etc any additional function args will be passed to content_func. |
288 | * |
289 | * @since unknown |
290 | * |
291 | * @param unknown_type $content_func |
292 | */ |
293 | function wp_iframe($content_func /* ... */) { |
294 | ?> |
295 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
296 | <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>> |
297 | <head> |
298 | <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" /> |
299 | <title><?php bloginfo('name') ?> › <?php _e('Uploads'); ?> — <?php _e('WordPress'); ?></title> |
300 | <?php |
301 | wp_enqueue_style( 'global' ); |
302 | wp_enqueue_style( 'wp-admin' ); |
303 | wp_enqueue_style( 'colors' ); |
304 | if ( 0 === strpos( $content_func, 'media' ) ) |
305 | wp_enqueue_style( 'media' ); |
306 | |
307 | ?> |
308 | <script type="text/javascript"> |
309 | //<![CDATA[ |
310 | function addLoadEvent(func) {if ( typeof wpOnload!='function'){wpOnload=func;}else{ var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}} |
311 | //]]> |
312 | </script> |
313 | <?php |
314 | do_action('admin_print_styles'); |
315 | do_action('admin_print_scripts'); |
316 | do_action('admin_head'); |
317 | if ( is_string($content_func) ) |
318 | do_action( "admin_head_{$content_func}" ); |
319 | ?> |
320 | </head> |
321 | <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?>> |
322 | <?php |
323 | $args = func_get_args(); |
324 | $args = array_slice($args, 1); |
325 | call_user_func_array($content_func, $args); |
326 | ?> |
327 | </body> |
328 | </html> |
329 | <?php |
330 | } |
331 | |
332 | /** |
333 | * {@internal Missing Short Description}} |
334 | * |
335 | * @since unknown |
336 | */ |
337 | function media_buttons() { |
338 | global $post_ID, $temp_ID; |
339 | $uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID); |
340 | $context = apply_filters('media_buttons_context', __('Upload/Insert %s')); |
341 | $media_upload_iframe_src = "media-upload.php?post_id=$uploading_iframe_ID"; |
342 | $media_title = __('Add Media'); |
343 | $image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src&type=image"); |
344 | $image_title = __('Add an Image'); |
345 | $video_upload_iframe_src = apply_filters('video_upload_iframe_src', "$media_upload_iframe_src&type=video"); |
346 | $video_title = __('Add Video'); |
347 | $audio_upload_iframe_src = apply_filters('audio_upload_iframe_src', "$media_upload_iframe_src&type=audio"); |
348 | $audio_title = __('Add Audio'); |
349 | $out = <<<EOF |
350 | |
351 | <a href="{$image_upload_iframe_src}&TB_iframe=true" id="add_image" class="thickbox" title='$image_title'><img src='images/media-button-image.svg' alt='$image_title' /></a> |
352 | <a href="{$video_upload_iframe_src}&TB_iframe=true" id="add_video" class="thickbox" title='$video_title'><img src='images/media-button-video.svg' alt='$video_title' /></a> |
353 | <a href="{$audio_upload_iframe_src}&TB_iframe=true" id="add_audio" class="thickbox" title='$audio_title'><img src='images/media-button-music.svg' alt='$audio_title' /></a> |
354 | <a href="{$media_upload_iframe_src}&TB_iframe=true" id="add_media" class="thickbox" title='$media_title'><img src='images/media-button-other.svg' alt='$media_title' /></a> |
355 | |
356 | EOF; |
357 | printf($context, $out); |
358 | } |
359 | add_action( 'media_buttons', 'media_buttons' ); |
360 | add_action('media_upload_media', 'media_upload_handler'); |
361 | |
362 | /** |
363 | * {@internal Missing Short Description}} |
364 | * |
365 | * @since unknown |
366 | * |
367 | * @return unknown |
368 | */ |
369 | function media_upload_form_handler() { |
370 | check_admin_referer('media-form'); |
371 | |
372 | if ( !empty($_POST['attachments']) ) foreach ( $_POST['attachments'] as $attachment_id => $attachment ) { |
373 | $post = $_post = get_post($attachment_id, ARRAY_A); |
374 | if ( isset($attachment['post_content']) ) |
375 | $post['post_content'] = $attachment['post_content']; |
376 | if ( isset($attachment['post_title']) ) |
377 | $post['post_title'] = $attachment['post_title']; |
378 | if ( isset($attachment['post_excerpt']) ) |
379 | $post['post_excerpt'] = $attachment['post_excerpt']; |
380 | if ( isset($attachment['menu_order']) ) |
381 | $post['menu_order'] = $attachment['menu_order']; |
382 | if ( isset($attachment['post_parent']) ) |
383 | $post['post_parent'] = $attachment['post_parent']; |
384 | |
385 | $post = apply_filters('attachment_fields_to_save', $post, $attachment); |
386 | |
387 | if ( isset($post['errors']) ) { |
388 | $errors[$attachment_id] = $post['errors']; |
389 | unset($post['errors']); |
390 | } |
391 | |
392 | if ( $post != $_post ) |
393 | wp_update_post($post); |
394 | |
395 | foreach ( get_attachment_taxonomies($post) as $t ) |
396 | if ( isset($attachment[$t]) ) |
397 | wp_set_object_terms($attachment_id, array_map('trim', preg_split('/,+/', $attachment[$t])), $t, false); |
398 | } |
399 | |
400 | if ( isset($_POST['insert-gallery']) || isset($_POST['update-gallery']) ) { ?> |
401 | <script type="text/javascript"> |
402 | /* <![CDATA[ */ |
403 | var win = window.dialogArguments || opener || parent || top; |
404 | win.tb_remove(); |
405 | /* ]]> */ |
406 | </script> |
407 | <?php |
408 | exit; |
409 | } |
410 | |
411 | if ( isset($_POST['send']) ) { |
412 | $keys = array_keys($_POST['send']); |
413 | $send_id = (int) array_shift($keys); |
414 | $attachment = stripslashes_deep( $_POST['attachments'][$send_id] ); |
415 | $html = $attachment['post_title']; |
416 | if ( !empty($attachment['url']) ) { |
417 | if ( strpos($attachment['url'], 'attachment_id') || false !== strpos($attachment['url'], get_permalink($_POST['post_id'])) ) |
418 | $rel = " rel='attachment wp-att-".attribute_escape($send_id)."'"; |
419 | $html = "<a href='{$attachment['url']}'$rel>$html</a>"; |
420 | } |
421 | $html = apply_filters('media_send_to_editor', $html, $send_id, $attachment); |
422 | return media_send_to_editor($html); |
423 | } |
424 | |
425 | return $errors; |
426 | } |
427 | |
428 | /** |
429 | * {@internal Missing Short Description}} |
430 | * |
431 | * @since unknown |
432 | * |
433 | * @return unknown |
434 | */ |
435 | function media_upload_image() { |
436 | $errors = array(); |
437 | $id = 0; |
438 | |
439 | if ( isset($_POST['html-upload']) && !empty($_FILES) ) { |
440 | // Upload File button was clicked |
441 | $id = media_handle_upload('async-upload', $_REQUEST['post_id']); |
442 | unset($_FILES); |
443 | if ( is_wp_error($id) ) { |
444 | $errors['upload_error'] = $id; |
445 | $id = false; |
446 | } |
447 | } |
448 | |
449 | if ( !empty($_POST['insertonlybutton']) ) { |
450 | $src = $_POST['insertonly']['src']; |
451 | if ( !empty($src) && !strpos($src, '://') ) |
452 | $src = "http://$src"; |
453 | $alt = attribute_escape($_POST['insertonly']['alt']); |
454 | if ( isset($_POST['insertonly']['align']) ) { |
455 | $align = attribute_escape($_POST['insertonly']['align']); |
456 | $class = " class='align$align'"; |
457 | } |
458 | if ( !empty($src) ) |
459 | $html = "<img src='$src' alt='$alt'$class />"; |
460 | return media_send_to_editor($html); |
461 | } |
462 | |
463 | if ( !empty($_POST) ) { |
464 | $return = media_upload_form_handler(); |
465 | |
466 | if ( is_string($return) ) |
467 | return $return; |
468 | if ( is_array($return) ) |
469 | $errors = $return; |
470 | } |
471 | |
472 | if ( isset($_POST['save']) ) { |
473 | $errors['upload_notice'] = __('Saved.'); |
474 | return media_upload_gallery(); |
475 | } |
476 | |
477 | if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' ) |
478 | return wp_iframe( 'media_upload_type_url_form', 'image', $errors, $id ); |
479 | |
480 | return wp_iframe( 'media_upload_type_form', 'image', $errors, $id ); |
481 | } |
482 | |
483 | /** |
484 | * {@internal Missing Short Description}} |
485 | * |
486 | * @since unknown |
487 | * |
488 | * @param unknown_type $file |
489 | * @param unknown_type $post_id |
490 | * @param unknown_type $desc |
491 | * @return unknown |
492 | */ |
493 | function media_sideload_image($file, $post_id, $desc = null) { |
494 | if (!empty($file) ) { |
495 | $file_array['name'] = basename($file); |
496 | $tmp = download_url($file); |
497 | $file_array['tmp_name'] = $tmp; |
498 | $desc = @$desc; |
499 | |
500 | if ( is_wp_error($tmp) ) { |
501 | @unlink($file_array['tmp_name']); |
502 | $file_array['tmp_name'] = ''; |
503 | } |
504 | |
505 | $id = media_handle_sideload($file_array, $post_id, $desc); |
506 | $src = $id; |
507 | |
508 | if ( is_wp_error($id) ) { |
509 | @unlink($file_array['tmp_name']); |
510 | return $id; |
511 | } |
512 | } |
513 | |
514 | if ( !empty($src) ) { |
515 | $alt = @$desc; |
516 | $html = "<img src='$src' alt='$alt' />"; |
517 | return $html; |
518 | } |
519 | } |
520 | |
521 | /** |
522 | * {@internal Missing Short Description}} |
523 | * |
524 | * @since unknown |
525 | * |
526 | * @return unknown |
527 | */ |
528 | function media_upload_audio() { |
529 | $errors = array(); |
530 | $id = 0; |
531 | |
532 | if ( isset($_POST['html-upload']) && !empty($_FILES) ) { |
533 | // Upload File button was clicked |
534 | $id = media_handle_upload('async-upload', $_REQUEST['post_id']); |
535 | unset($_FILES); |
536 | if ( is_wp_error($id) ) { |
537 | $errors['upload_error'] = $id; |
538 | $id = false; |
539 | } |
540 | } |
541 | |
542 | if ( !empty($_POST['insertonlybutton']) ) { |
543 | $href = $_POST['insertonly']['href']; |
544 | if ( !empty($href) && !strpos($href, '://') ) |
545 | $href = "http://$href"; |
546 | $title = attribute_escape($_POST['insertonly']['title']); |
547 | if ( empty($title) ) |
548 | $title = basename($href); |
549 | if ( !empty($title) && !empty($href) ) |
550 | $html = "<a href='$href' >$title</a>"; |
551 | return media_send_to_editor($html); |
552 | } |
553 | |
554 | if ( !empty($_POST) ) { |
555 | $return = media_upload_form_handler(); |
556 | |
557 | if ( is_string($return) ) |
558 | return $return; |
559 | if ( is_array($return) ) |
560 | $errors = $return; |
561 | } |
562 | |
563 | if ( isset($_POST['save']) ) { |
564 | $errors['upload_notice'] = __('Saved.'); |
565 | return media_upload_gallery(); |
566 | } |
567 | |
568 | if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' ) |
569 | return wp_iframe( 'media_upload_type_url_form', 'audio', $errors, $id ); |
570 | |
571 | return wp_iframe( 'media_upload_type_form', 'audio', $errors, $id ); |
572 | } |
573 | |
574 | /** |
575 | * {@internal Missing Short Description}} |
576 | * |
577 | * @since unknown |
578 | * |
579 | * @return unknown |
580 | */ |
581 | function media_upload_video() { |
582 | $errors = array(); |
583 | $id = 0; |
584 | |
585 | if ( isset($_POST['html-upload']) && !empty($_FILES) ) { |
586 | // Upload File button was clicked |
587 | $id = media_handle_upload('async-upload', $_REQUEST['post_id']); |
588 | unset($_FILES); |
589 | if ( is_wp_error($id) ) { |
590 | $errors['upload_error'] = $id; |
591 | $id = false; |
592 | } |
593 | } |
594 | |
595 | if ( !empty($_POST['insertonlybutton']) ) { |
596 | $href = $_POST['insertonly']['href']; |
597 | if ( !empty($href) && !strpos($href, '://') ) |
598 | $href = "http://$href"; |
599 | $title = attribute_escape($_POST['insertonly']['title']); |
600 | if ( empty($title) ) |
601 | $title = basename($href); |
602 | if ( !empty($title) && !empty($href) ) |
603 | $html = "<a href='$href' >$title</a>"; |
604 | return media_send_to_editor($html); |
605 | } |
606 | |
607 | if ( !empty($_POST) ) { |
608 | $return = media_upload_form_handler(); |
609 | |
610 | if ( is_string($return) ) |
611 | return $return; |
612 | if ( is_array($return) ) |
613 | $errors = $return; |
614 | } |
615 | |
616 | if ( isset($_POST['save']) ) { |
617 | $errors['upload_notice'] = __('Saved.'); |
618 | return media_upload_gallery(); |
619 | } |
620 | |
621 | if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' ) |
622 | return wp_iframe( 'media_upload_type_url_form', 'video', $errors, $id ); |
623 | |
624 | return wp_iframe( 'media_upload_type_form', 'video', $errors, $id ); |
625 | } |
626 | |
627 | /** |
628 | * {@internal Missing Short Description}} |
629 | * |
630 | * @since unknown |
631 | * |
632 | * @return unknown |
633 | */ |
634 | function media_upload_file() { |
635 | $errors = array(); |
636 | $id = 0; |
637 | |
638 | if ( isset($_POST['html-upload']) && !empty($_FILES) ) { |
639 | // Upload File button was clicked |
640 | $id = media_handle_upload('async-upload', $_REQUEST['post_id']); |
641 | unset($_FILES); |
642 | if ( is_wp_error($id) ) { |
643 | $errors['upload_error'] = $id; |
644 | $id = false; |
645 | } |
646 | } |
647 | |
648 | if ( !empty($_POST['insertonlybutton']) ) { |
649 | $href = $_POST['insertonly']['href']; |
650 | if ( !empty($href) && !strpos($href, '://') ) |
651 | $href = "http://$href"; |
652 | $title = attribute_escape($_POST['insertonly']['title']); |
653 | if ( empty($title) ) |
654 | $title = basename($href); |
655 | if ( !empty($title) && !empty($href) ) |
656 | $html = "<a href='$href' >$title</a>"; |
657 | return media_send_to_editor($html); |
658 | } |
659 | |
660 | if ( !empty($_POST) ) { |
661 | $return = media_upload_form_handler(); |
662 | |
663 | if ( is_string($return) ) |
664 | return $return; |
665 | if ( is_array($return) ) |
666 | $errors = $return; |
667 | } |
668 | |
669 | if ( isset($_POST['save']) ) { |
670 | $errors['upload_notice'] = __('Saved.'); |
671 | return media_upload_gallery(); |
672 | } |
673 | |
674 | if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' ) |
675 | return wp_iframe( 'media_upload_type_url_form', 'file', $errors, $id ); |
676 | |
677 | return wp_iframe( 'media_upload_type_form', 'file', $errors, $id ); |
678 | } |
679 | |
680 | /** |
681 | * {@internal Missing Short Description}} |
682 | * |
683 | * @since unknown |
684 | * |
685 | * @return unknown |
686 | */ |
687 | function media_upload_gallery() { |
688 | $errors = array(); |
689 | |
690 | if ( !empty($_POST) ) { |
691 | $return = media_upload_form_handler(); |
692 | |
693 | if ( is_string($return) ) |
694 | return $return; |
695 | if ( is_array($return) ) |
696 | $errors = $return; |
697 | } |
698 | |
699 | wp_enqueue_script('admin-gallery'); |
700 | return wp_iframe( 'media_upload_gallery_form', $errors ); |
701 | } |
702 | |
703 | /** |
704 | * {@internal Missing Short Description}} |
705 | * |
706 | * @since unknown |
707 | * |
708 | * @return unknown |
709 | */ |
710 | function media_upload_library() { |
711 | $errors = array(); |
712 | if ( !empty($_POST) ) { |
713 | $return = media_upload_form_handler(); |
714 | |
715 | if ( is_string($return) ) |
716 | return $return; |
717 | if ( is_array($return) ) |
718 | $errors = $return; |
719 | } |
720 | |
721 | return wp_iframe( 'media_upload_library_form', $errors ); |
722 | } |
723 | |
724 | /** |
725 | * Retrieve HTML for the image alignment radio buttons with the specified one checked. |
726 | * |
727 | * @since unknown |
728 | * |
729 | * @param unknown_type $post |
730 | * @param unknown_type $checked |
731 | * @return unknown |
732 | */ |
733 | function image_align_input_fields($post, $checked='') { |
734 | |
735 | $alignments = array('none' => 'None', 'left' => 'Left', 'center' => 'Center', 'right' => 'Right'); |
736 | if ( !array_key_exists($checked, $alignments) ) |
737 | $checked = 'none'; |
738 | |
739 | $out = array(); |
740 | foreach ($alignments as $name => $label) { |
741 | |
742 | $out[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='$name'". |
743 | ( $checked == $name ? " checked='checked'" : "" ) . |
744 | " /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>" . __($label) . "</label>"; |
745 | } |
746 | return join("\n", $out); |
747 | } |
748 | |
749 | /** |
750 | * Retrieve HTML for the size radio buttons with the specified one checked. |
751 | * |
752 | * @since unknown |
753 | * |
754 | * @param unknown_type $post |
755 | * @param unknown_type $checked |
756 | * @return unknown |
757 | */ |
758 | function image_size_input_fields($post, $checked='') { |
759 | |
760 | // get a list of the actual pixel dimensions of each possible intermediate version of this image |
761 | $size_names = array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full size')); |
762 | |
763 | foreach ( $size_names as $size => $name) { |
764 | $downsize = image_downsize($post->ID, $size); |
765 | |
766 | // is this size selectable? |
767 | $enabled = ( $downsize[3] || 'full' == $size ); |
768 | $css_id = "image-size-{$size}-{$post->ID}"; |
769 | // if this size is the default but that's not available, don't select it |
770 | if ( $checked && !$enabled ) |
771 | $checked = ''; |
772 | // if $checked was not specified, default to the first available size that's bigger than a thumbnail |
773 | if ( !$checked && $enabled && 'thumbnail' != $size ) |
774 | $checked = $size; |
775 | |
776 | $html = "<div class='image-size-item'><input type='radio' ".( $enabled ? '' : "disabled='disabled'")."name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'".( $checked == $size ? " checked='checked'" : '') ." />"; |
777 | |
778 | $html .= "<label for='{$css_id}'>" . __($name). "</label>"; |
779 | // only show the dimensions if that choice is available |
780 | if ( $enabled ) |
781 | $html .= " <label for='{$css_id}' class='help'>" . sprintf( __("(%d × %d)"), $downsize[1], $downsize[2] ). "</label>"; |
782 | |
783 | $html .= '</div>'; |
784 | |
785 | $out[] = $html; |
786 | } |
787 | |
788 | return array( |
789 | 'label' => __('Size'), |
790 | 'input' => 'html', |
791 | 'html' => join("\n", $out), |
792 | ); |
793 | } |
794 | |
795 | /** |
796 | * Retrieve HTML for the Link URL buttons with the default link type as specified. |
797 | * |
798 | * @since unknown |
799 | * |
800 | * @param unknown_type $post |
801 | * @param unknown_type $url_type |
802 | * @return unknown |
803 | */ |
804 | function image_link_input_fields($post, $url_type='') { |
805 | |
806 | $file = wp_get_attachment_url($post->ID); |
807 | $link = get_attachment_link($post->ID); |
808 | |
809 | $url = ''; |
810 | if ( $url_type == 'file' ) |
811 | $url = $file; |
812 | elseif ( $url_type == 'post' ) |
813 | $url = $link; |
814 | |
815 | return "<input type='text' class='urlfield' name='attachments[$post->ID][url]' value='" . attribute_escape($url) . "' /><br /> |
816 | <button type='button' class='button urlnone' title=''>" . __('None') . "</button> |
817 | <button type='button' class='button urlfile' title='" . attribute_escape($file) . "'>" . __('File URL') . "</button> |
818 | <button type='button' class='button urlpost' title='" . attribute_escape($link) . "'>" . __('Post URL') . "</button> |
819 | "; |
820 | } |
821 | |
822 | /** |
823 | * {@internal Missing Short Description}} |
824 | * |
825 | * @since unknown |
826 | * |
827 | * @param unknown_type $form_fields |
828 | * @param unknown_type $post |
829 | * @return unknown |
830 | */ |
831 | function image_attachment_fields_to_edit($form_fields, $post) { |
832 | if ( substr($post->post_mime_type, 0, 5) == 'image' ) { |
833 | $form_fields['post_title']['required'] = true; |
834 | |
835 | $form_fields['post_excerpt']['label'] = __('Caption'); |
836 | $form_fields['post_excerpt']['helps'][] = __('Also used as alternate text for the image'); |
837 | |
838 | $form_fields['post_content']['label'] = __('Description'); |
839 | |
840 | $form_fields['align'] = array( |
841 | 'label' => __('Alignment'), |
842 | 'input' => 'html', |
843 | 'html' => image_align_input_fields($post, get_option('image_default_align')), |
844 | ); |
845 | |
846 | $form_fields['image-size'] = image_size_input_fields($post, get_option('image_default_size')); |
847 | } |
848 | return $form_fields; |
849 | } |
850 | |
851 | add_filter('attachment_fields_to_edit', 'image_attachment_fields_to_edit', 10, 2); |
852 | |
853 | /** |
854 | * {@internal Missing Short Description}} |
855 | * |
856 | * @since unknown |
857 | * |
858 | * @param unknown_type $form_fields |
859 | * @param unknown_type $post |
860 | * @return unknown |
861 | */ |
862 | function media_single_attachment_fields_to_edit( $form_fields, $post ) { |
863 | unset($form_fields['url'], $form_fields['align'], $form_fields['image-size']); |
864 | return $form_fields; |
865 | } |
866 | |
867 | /** |
868 | * {@internal Missing Short Description}} |
869 | * |
870 | * @since unknown |
871 | * |
872 | * @param unknown_type $post |
873 | * @param unknown_type $attachment |
874 | * @return unknown |
875 | */ |
876 | function image_attachment_fields_to_save($post, $attachment) { |
877 | if ( substr($post['post_mime_type'], 0, 5) == 'image' ) { |
878 | if ( strlen(trim($post['post_title'])) == 0 ) { |
879 | $post['post_title'] = preg_replace('/\.\w+$/', '', basename($post['guid'])); |
880 | $post['errors']['post_title']['errors'][] = __('Empty Title filled from filename.'); |
881 | } |
882 | } |
883 | |
884 | return $post; |
885 | } |
886 | |
887 | add_filter('attachment_fields_to_save', 'image_attachment_fields_to_save', 10, 2); |
888 | |
889 | /** |
890 | * {@internal Missing Short Description}} |
891 | * |
892 | * @since unknown |
893 | * |
894 | * @param unknown_type $html |
895 | * @param unknown_type $attachment_id |
896 | * @param unknown_type $attachment |
897 | * @return unknown |
898 | */ |
899 | function image_media_send_to_editor($html, $attachment_id, $attachment) { |
900 | $post =& get_post($attachment_id); |
901 | if ( substr($post->post_mime_type, 0, 5) == 'image' ) { |
902 | $url = $attachment['url']; |
903 | |
904 | if ( isset($attachment['align']) ) |
905 | $align = $attachment['align']; |
906 | else |
907 | $align = 'none'; |
908 | |
909 | if ( !empty($attachment['image-size']) ) |
910 | $size = $attachment['image-size']; |
911 | else |
912 | $size = 'medium'; |
913 | |
914 | $rel = ( $url == get_attachment_link($attachment_id) ); |
915 | |
916 | return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size); |
917 | } |
918 | |
919 | return $html; |
920 | } |
921 | |
922 | add_filter('media_send_to_editor', 'image_media_send_to_editor', 10, 3); |
923 | |
924 | /** |
925 | * {@internal Missing Short Description}} |
926 | * |
927 | * @since unknown |
928 | * |
929 | * @param unknown_type $post |
930 | * @param unknown_type $errors |
931 | * @return unknown |
932 | */ |
933 | function get_attachment_fields_to_edit($post, $errors = null) { |
934 | if ( is_int($post) ) |
935 | $post =& get_post($post); |
936 | if ( is_array($post) ) |
937 | $post = (object) $post; |
938 | |
939 | $edit_post = sanitize_post($post, 'edit'); |
940 | |
941 | $form_fields = array( |
942 | 'post_title' => array( |
943 | 'label' => __('Title'), |
944 | 'value' => $edit_post->post_title, |
945 | ), |
946 | 'post_excerpt' => array( |
947 | 'label' => __('Caption'), |
948 | 'value' => $edit_post->post_excerpt, |
949 | ), |
950 | 'post_content' => array( |
951 | 'label' => __('Description'), |
952 | 'value' => $edit_post->post_content, |
953 | 'input' => 'textarea', |
954 | ), |
955 | 'url' => array( |
956 | 'label' => __('Link URL'), |
957 | 'input' => 'html', |
958 | 'html' => image_link_input_fields($post, get_option('image_default_link_type')), |
959 | 'helps' => __('Enter a link URL or click above for presets.'), |
960 | ), |
961 | 'menu_order' => array( |
962 | 'label' => __('Order'), |
963 | 'value' => $edit_post->menu_order |
964 | ), |
965 | ); |
966 | |
967 | foreach ( get_attachment_taxonomies($post) as $taxonomy ) { |
968 | $t = (array) get_taxonomy($taxonomy); |
969 | if ( empty($t['label']) ) |
970 | $t['label'] = $taxonomy; |
971 | if ( empty($t['args']) ) |
972 | $t['args'] = array(); |
973 | |
974 | $terms = get_object_term_cache($post->ID, $taxonomy); |
975 | if ( empty($terms) ) |
976 | $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']); |
977 | |
978 | $values = array(); |
979 | |
980 | foreach ( $terms as $term ) |
981 | $values[] = $term->name; |
982 | $t['value'] = join(', ', $values); |
983 | |
984 | $form_fields[$taxonomy] = $t; |
985 | } |
986 | |
987 | // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default |
988 | // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing ) |
989 | $form_fields = array_merge_recursive($form_fields, (array) $errors); |
990 | |
991 | $form_fields = apply_filters('attachment_fields_to_edit', $form_fields, $post); |
992 | |
993 | return $form_fields; |
994 | } |
995 | |
996 | /** |
997 | * Retrieve HTML for media items of post gallery. |
998 | * |
999 | * The HTML markup retrieved will be created for the progress of SWF Upload |
1000 | * component. Will also create link for showing and hiding the form to modify |
1001 | * the image attachment. |
1002 | * |
1003 | * @since unknown |
1004 | * |
1005 | * @param int $post_id Optional. Post ID. |
1006 | * @param array $errors Errors for attachment, if any. |
1007 | * @return string |
1008 | */ |
1009 | function get_media_items( $post_id, $errors ) { |
1010 | if ( $post_id ) { |
1011 | $post = get_post($post_id); |
1012 | if ( $post && $post->post_type == 'attachment' ) |
1013 | $attachments = array($post->ID => $post); |
1014 | else |
1015 | $attachments = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') ); |
1016 | } else { |
1017 | if ( is_array($GLOBALS['wp_the_query']->posts) ) |
1018 | foreach ( $GLOBALS['wp_the_query']->posts as $attachment ) |
1019 | $attachments[$attachment->ID] = $attachment; |
1020 | } |
1021 | |
1022 | $output = ''; |
1023 | foreach ( (array) $attachments as $id => $attachment ) |
1024 | if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) ) |
1025 | $output .= "\n<div id='media-item-$id' class='media-item child-of-$attachment->post_parent preloaded'><div class='progress'><div class='bar'></div></div><div id='media-upload-error-$id'></div><div class='filename'></div>$item\n</div>"; |
1026 | |
1027 | return $output; |
1028 | } |
1029 | |
1030 | /** |
1031 | * Retrieve HTML form for modifying the image attachment. |
1032 | * |
1033 | * @since unknown |
1034 | * |
1035 | * @param int $attachment_id Attachment ID for modification. |
1036 | * @param string|array $args Optional. Override defaults. |
1037 | * @return string HTML form for attachment. |
1038 | */ |
1039 | function get_media_item( $attachment_id, $args = null ) { |
1040 | global $redir_tab; |
1041 | |
1042 | $default_args = array( 'errors' => null, 'send' => true, 'delete' => true, 'toggle' => true, 'show_title' => true ); |
1043 | $args = wp_parse_args( $args, $default_args ); |
1044 | extract( $args, EXTR_SKIP ); |
1045 | |
1046 | global $post_mime_types; |
1047 | if ( ( $attachment_id = intval($attachment_id) ) && $thumb_url = get_attachment_icon_src( $attachment_id ) ) |
1048 | $thumb_url = $thumb_url[0]; |
1049 | else |
1050 | return false; |
1051 | |
1052 | $toggle_on = __('Show'); |
1053 | $toggle_off = __('Hide'); |
1054 | |
1055 | $post = get_post($attachment_id); |
1056 | |
1057 | $filename = basename($post->guid); |
1058 | $title = attribute_escape($post->post_title); |
1059 | |
1060 | if ( $_tags = get_the_tags($attachment_id) ) { |
1061 | foreach ( $_tags as $tag ) |
1062 | $tags[] = $tag->name; |
1063 | $tags = attribute_escape(join(', ', $tags)); |
1064 | } |
1065 | |
1066 | $type = ''; |
1067 | if ( isset($post_mime_types) ) { |
1068 | $keys = array_keys(wp_match_mime_types(array_keys($post_mime_types), $post->post_mime_type)); |
1069 | $type = array_shift($keys); |
1070 | $type = "<input type='hidden' id='type-of-$attachment_id' value='" . attribute_escape( $type ) . "' />"; |
1071 | } |
1072 | |
1073 | $form_fields = get_attachment_fields_to_edit($post, $errors); |
1074 | |
1075 | if ( $toggle ) { |
1076 | $class = empty($errors) ? 'startclosed' : 'startopen'; |
1077 | $toggle_links = " |
1078 | <a class='toggle describe-toggle-on' href='#'>$toggle_on</a> |
1079 | <a class='toggle describe-toggle-off' href='#'>$toggle_off</a>"; |
1080 | } else { |
1081 | $class = 'form-table'; |
1082 | $toggle_links = ''; |
1083 | } |
1084 | |
1085 | $display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case |
1086 | $display_title = $show_title ? "<div class='filename new'>" . wp_html_excerpt($display_title, 60) . "</div>" : ''; |
1087 | |
1088 | $gallery = ( (isset($_REQUEST['tab']) && 'gallery' == $_REQUEST['tab']) || (isset($redir_tab) && 'gallery' == $redir_tab) ) ? true : false; |
1089 | $order = ''; |
1090 | |
1091 | foreach ( $form_fields as $key => $val ) { |
1092 | if ( 'menu_order' == $key ) { |
1093 | if ( $gallery ) |
1094 | $order = '<div class="menu_order"> <input class="menu_order_input" type="text" id="attachments['.$attachment_id.'][menu_order]" name="attachments['.$attachment_id.'][menu_order]" value="'.$val['value'].'" /></div>'; |
1095 | else |
1096 | $order = '<input type="hidden" name="attachments['.$attachment_id.'][menu_order]" value="'.$val['value'].'" />'; |
1097 | |
1098 | unset($form_fields['menu_order']); |
1099 | break; |
1100 | } |
1101 | } |
1102 | |
1103 | $item = " |
1104 | $type |
1105 | $toggle_links |
1106 | $order |
1107 | $display_title |
1108 | <table class='slidetoggle describe $class'> |
1109 | <thead class='media-item-info'> |
1110 | <tr> |
1111 | <td class='A1B1' rowspan='4'><img class='thumbnail' src='$thumb_url' alt='' /></td> |
1112 | <td>$filename</td> |
1113 | </tr> |
1114 | <tr><td>$post->post_mime_type</td></tr> |
1115 | <tr><td>" . mysql2date($post->post_date, get_option('time_format')) . "</td></tr> |
1116 | <tr><td>" . apply_filters('media_meta', '', $post) . "</td></tr> |
1117 | </thead> |
1118 | <tbody>\n"; |
1119 | |
1120 | $defaults = array( |
1121 | 'input' => 'text', |
1122 | 'required' => false, |
1123 | 'value' => '', |
1124 | 'extra_rows' => array(), |
1125 | ); |
1126 | |
1127 | $delete_href = wp_nonce_url("post.php?action=delete-post&post=$attachment_id", 'delete-post_' . $attachment_id); |
1128 | if ( $send ) |
1129 | $send = "<input type='submit' class='button' name='send[$attachment_id]' value='" . attribute_escape( __( 'Insert into Post' ) ) . "' />"; |
1130 | if ( $delete ) |
1131 | $delete = "<a href=\"#\" class=\"del-link\" onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __('Delete') . "</a>"; |
1132 | if ( ( $send || $delete ) && !isset($form_fields['buttons']) ) |
1133 | $form_fields['buttons'] = array('tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>$send $delete |
1134 | <div id=\"del_attachment_$attachment_id\" class=\"del-attachment\" style=\"display:none;\">" . sprintf(__("You are about to delete <strong>%s</strong>."), $filename) . " <a href=\"$delete_href\" id=\"del[$attachment_id]\" class=\"delete\">" . __('Continue') . "</a> |
1135 | <a href=\"#\" class=\"del-link\" onclick=\"this.parentNode.style.display='none';return false;\">" . __('Cancel') . "</a></div></td></tr>\n"); |
1136 | |
1137 | $hidden_fields = array(); |
1138 | |
1139 | foreach ( $form_fields as $id => $field ) { |
1140 | if ( $id{0} == '_' ) |
1141 | continue; |
1142 | |
1143 | if ( !empty($field['tr']) ) { |
1144 | $item .= $field['tr']; |
1145 | continue; |
1146 | } |
1147 | |
1148 | $field = array_merge($defaults, $field); |
1149 | $name = "attachments[$attachment_id][$id]"; |
1150 | |
1151 | if ( $field['input'] == 'hidden' ) { |
1152 | $hidden_fields[$name] = $field['value']; |
1153 | continue; |
1154 | } |
1155 | |
1156 | $required = $field['required'] ? '<abbr title="required" class="required">*</abbr>' : ''; |
1157 | $aria_required = $field['required'] ? " aria-required='true' " : ''; |
1158 | $class = $id; |
1159 | $class .= $field['required'] ? ' form-required' : ''; |
1160 | |
1161 | $item .= "\t\t<tr class='$class'>\n\t\t\t<th valign='top' scope='row' class='label'><label for='$name'><span class='alignleft'>{$field['label']}</span><span class='alignright'>$required</span><br class='clear' /></label></th>\n\t\t\t<td class='field'>"; |
1162 | if ( !empty($field[$field['input']]) ) |
1163 | $item .= $field[$field['input']]; |
1164 | elseif ( $field['input'] == 'textarea' ) { |
1165 | $item .= "<textarea type='text' id='$name' name='$name'" . $aria_required . ">" . htmlspecialchars( $field['value'] ) . "</textarea>"; |
1166 | } else { |
1167 | $item .= "<input type='text' id='$name' name='$name' value='" . attribute_escape( $field['value'] ) . "'" . $aria_required . "/>"; |
1168 | } |
1169 | if ( !empty($field['helps']) ) |
1170 | $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique((array) $field['helps']) ) . '</p>'; |
1171 | $item .= "</td>\n\t\t</tr>\n"; |
1172 | |
1173 | $extra_rows = array(); |
1174 | |
1175 | if ( !empty($field['errors']) ) |
1176 | foreach ( array_unique((array) $field['errors']) as $error ) |
1177 | $extra_rows['error'][] = $error; |
1178 | |
1179 | if ( !empty($field['extra_rows']) ) |
1180 | foreach ( $field['extra_rows'] as $class => $rows ) |
1181 | foreach ( (array) $rows as $html ) |
1182 | $extra_rows[$class][] = $html; |
1183 | |
1184 | foreach ( $extra_rows as $class => $rows ) |
1185 | foreach ( $rows as $html ) |
1186 | $item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n"; |
1187 | } |
1188 | |
1189 | if ( !empty($form_fields['_final']) ) |
1190 | $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n"; |
1191 | $item .= "\t</tbody>\n"; |
1192 | $item .= "\t</table>\n"; |
1193 | |
1194 | foreach ( $hidden_fields as $name => $value ) |
1195 | $item .= "\t<input type='hidden' name='$name' id='$name' value='" . attribute_escape( $value ) . "' />\n"; |
1196 | |
1197 | if ( $post->post_parent < 1 && (int) $_REQUEST['post_id'] ) { |
1198 | $parent = (int) $_REQUEST['post_id']; |
1199 | $parent_name = "attachments[$attachment_id][post_parent]"; |
1200 | |
1201 | $item .= "\t<input type='hidden' name='$parent_name' id='$parent_name' value='" . $parent . "' />\n"; |
1202 | } |
1203 | |
1204 | return $item; |
1205 | } |
1206 | |
1207 | /** |
1208 | * {@internal Missing Short Description}} |
1209 | * |
1210 | * @since unknown |
1211 | */ |
1212 | function media_upload_header() { |
1213 | ?> |
1214 | <script type="text/javascript">post_id = <?php echo intval($_REQUEST['post_id']); ?>;</script> |
1215 | <div id="media-upload-header"> |
1216 | <?php the_media_upload_tabs(); ?> |
1217 | </div> |
1218 | <?php |
1219 | } |
1220 | |
1221 | /** |
1222 | * {@internal Missing Short Description}} |
1223 | * |
1224 | * @since unknown |
1225 | * |
1226 | * @param unknown_type $errors |
1227 | */ |
1228 | function media_upload_form( $errors = null ) { |
1229 | global $type, $tab; |
1230 | |
1231 | $flash_action_url = admin_url('async-upload.php'); |
1232 | |
1233 | // If Mac and mod_security, no Flash. :( |
1234 | $flash = true; |
1235 | if ( false !== strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'mac') && apache_mod_loaded('mod_security') ) |
1236 | $flash = false; |
1237 | |
1238 | $flash = apply_filters('flash_uploader', $flash); |
1239 | $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0; |
1240 | |
1241 | ?> |
1242 | <div id="media-upload-notice"> |
1243 | <?php if (isset($errors['upload_notice']) ) { ?> |
1244 | <?php echo $errors['upload_notice']; ?> |
1245 | <?php } ?> |
1246 | </div> |
1247 | <div id="media-upload-error"> |
1248 | <?php if (isset($errors['upload_error']) && is_wp_error($errors['upload_error'])) { ?> |
1249 | <?php echo $errors['upload_error']->get_error_message(); ?> |
1250 | <?php } ?> |
1251 | </div> |
1252 | |
1253 | <?php do_action('pre-upload-ui'); ?> |
1254 | |
1255 | <?php if ( $flash ) : ?> |
1256 | <script type="text/javascript"> |
1257 | <!-- |
1258 | SWFUpload.onload = function() { |
1259 | swfu = new SWFUpload({ |
1260 | button_text: '<span class="button"><?php _e('Select Files'); ?></span>', |
1261 | button_text_style: '.button { text-align: center; font-weight: bold; font-family:"Lucida Grande","Lucida Sans Unicode",Tahoma,Verdana,sans-serif; }', |
1262 | button_height: "24", |
1263 | button_width: "132", |
1264 | button_image_url: '<?php echo includes_url('images/upload.svg'); ?>', |
1265 | button_placeholder_id: "flash-browse-button", |
1266 | upload_url : "<?php echo attribute_escape( $flash_action_url ); ?>", |
1267 | flash_url : "<?php echo includes_url('js/swfupload/swfupload.swf'); ?>", |
1268 | file_post_name: "async-upload", |
1269 | file_types: "<?php echo apply_filters('upload_file_glob', '*.*'); ?>", |
1270 | post_params : { |
1271 | "post_id" : "<?php echo $post_id; ?>", |
1272 | "auth_cookie" : "<?php if ( is_ssl() ) echo $_COOKIE[SECURE_AUTH_COOKIE]; else echo $_COOKIE[AUTH_COOKIE]; ?>", |
1273 | "_wpnonce" : "<?php echo wp_create_nonce('media-form'); ?>", |
1274 | "type" : "<?php echo $type; ?>", |
1275 | "tab" : "<?php echo $tab; ?>", |
1276 | "short" : "1" |
1277 | }, |
1278 | file_size_limit : "<?php echo wp_max_upload_size(); ?>b", |
1279 | file_dialog_start_handler : fileDialogStart, |
1280 | file_queued_handler : fileQueued, |
1281 | upload_start_handler : uploadStart, |
1282 | upload_progress_handler : uploadProgress, |
1283 | upload_error_handler : uploadError, |
1284 | upload_success_handler : uploadSuccess, |
1285 | upload_complete_handler : uploadComplete, |
1286 | file_queue_error_handler : fileQueueError, |
1287 | file_dialog_complete_handler : fileDialogComplete, |
1288 | swfupload_pre_load_handler: swfuploadPreLoad, |
1289 | swfupload_load_failed_handler: swfuploadLoadFailed, |
1290 | custom_settings : { |
1291 | degraded_element_id : "html-upload-ui", // id of the element displayed when swfupload is unavailable |
1292 | swfupload_element_id : "flash-upload-ui" // id of the element displayed when swfupload is available |
1293 | }, |
1294 | debug: false |
1295 | }); |
1296 | }; |
1297 | //--> |
1298 | </script> |
1299 | |
1300 | <div id="flash-upload-ui"> |
1301 | <?php do_action('pre-flash-upload-ui'); ?> |
1302 | |
1303 | <div><?php _e( 'Choose files to upload' ); ?> <div id="flash-browse-button"></div></div> |
1304 | <?php do_action('post-flash-upload-ui'); ?> |
1305 | <p class="howto"><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></p> |
1306 | </div> |
1307 | |
1308 | <?php endif; // $flash ?> |
1309 | |
1310 | <div id="html-upload-ui"> |
1311 | <?php do_action('pre-html-upload-ui'); ?> |
1312 | <p id="async-upload-wrap"> |
1313 | <input type="file" name="async-upload" id="async-upload" /> <input type="submit" class="button" name="html-upload" value="<?php echo attribute_escape(__('Upload')); ?>" /> <a href="#" onclick="return top.tb_remove();"><?php _e('Cancel'); ?></a> |
1314 | </p> |
1315 | |
1316 | <br class="clear" /> |
1317 | <?php if ( is_lighttpd_before_150() ): ?> |
1318 | <p><?php _e('If you want to use all capabilities of the uploader, like uploading multiple files at once, please upgrade to lighttpd 1.5.'); ?></p> |
1319 | <?php endif;?> |
1320 | <?php do_action('post-html-upload-ui'); ?> |
1321 | </div> |
1322 | <?php do_action('post-upload-ui'); ?> |
1323 | <?php |
1324 | } |
1325 | |
1326 | /** |
1327 | * {@internal Missing Short Description}} |
1328 | * |
1329 | * @since unknown |
1330 | * |
1331 | * @param unknown_type $type |
1332 | * @param unknown_type $errors |
1333 | * @param unknown_type $id |
1334 | */ |
1335 | function media_upload_type_form($type = 'file', $errors = null, $id = null) { |
1336 | media_upload_header(); |
1337 | |
1338 | $post_id = intval($_REQUEST['post_id']); |
1339 | |
1340 | $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id"); |
1341 | $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type); |
1342 | ?> |
1343 | |
1344 | <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form type-form validate" id="<?php echo $type; ?>-form"> |
1345 | <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
1346 | <?php wp_nonce_field('media-form'); ?> |
1347 | |
1348 | <h3 class="media-title"><?php _e('Add media files from your computer'); ?></h3> |
1349 | |
1350 | <?php media_upload_form( $errors ); ?> |
1351 | |
1352 | <script type="text/javascript"> |
1353 | <!-- |
1354 | jQuery(function($){ |
1355 | var preloaded = $(".media-item.preloaded"); |
1356 | if ( preloaded.length > 0 ) { |
1357 | preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); |
1358 | } |
1359 | updateMediaForm(); |
1360 | }); |
1361 | --> |
1362 | </script> |
1363 | <div id="media-items"> |
1364 | <?php |
1365 | if ( $id ) { |
1366 | if ( !is_wp_error($id) ) { |
1367 | echo get_media_items( $id, $errors ); |
1368 | } else { |
1369 | echo '<div id="media-upload-error">'.wp_specialchars($id->get_error_message()).'</div>'; |
1370 | exit; |
1371 | } |
1372 | } |
1373 | ?> |
1374 | </div> |
1375 | <input type="submit" class="button savebutton" name="save" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" /> |
1376 | <?php |
1377 | } |
1378 | |
1379 | /** |
1380 | * {@internal Missing Short Description}} |
1381 | * |
1382 | * @since unknown |
1383 | * |
1384 | * @param unknown_type $type |
1385 | * @param unknown_type $errors |
1386 | * @param unknown_type $id |
1387 | */ |
1388 | function media_upload_type_url_form($type = 'file', $errors = null, $id = null) { |
1389 | media_upload_header(); |
1390 | |
1391 | $post_id = intval($_REQUEST['post_id']); |
1392 | |
1393 | $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id"); |
1394 | $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type); |
1395 | |
1396 | $callback = "type_url_form_$type"; |
1397 | ?> |
1398 | |
1399 | <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form type-form validate" id="<?php echo $type; ?>-form"> |
1400 | <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
1401 | <?php wp_nonce_field('media-form'); ?> |
1402 | |
1403 | <?php if ( is_callable($callback) ) { ?> |
1404 | |
1405 | <h3 class="media-title"><?php _e('Add media file from URL'); ?></h3> |
1406 | |
1407 | <script type="text/javascript"> |
1408 | //<![CDATA[ |
1409 | var addExtImage = { |
1410 | |
1411 | width : '', |
1412 | height : '', |
1413 | align : 'alignnone', |
1414 | |
1415 | insert : function() { |
1416 | var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = null; |
1417 | |
1418 | if ( '' == f.src.value || '' == t.width ) return false; |
1419 | |
1420 | if ( f.title.value ) { |
1421 | title = f.title.value.replace(/['"<>]+/g, ''); |
1422 | title = ' title="'+title+'"'; |
1423 | } |
1424 | |
1425 | if ( f.alt.value ) { |
1426 | alt = f.alt.value.replace(/['"<>]+/g, ''); |
1427 | <?php if ( ! apply_filters( 'disable_captions', '' ) ) { ?> |
1428 | caption = f.alt.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>'); |
1429 | <?php } ?> |
1430 | } |
1431 | |
1432 | cls = caption ? '' : ' class="'+t.align+'"'; |
1433 | |
1434 | html = '<img alt="'+alt+'" src="'+f.src.value+'"'+title+cls+' width="'+t.width+'" height="'+t.height+'" />'; |
1435 | |
1436 | if ( f.url.value ) |
1437 | html = '<a href="'+f.url.value+'">'+html+'</a>'; |
1438 | |
1439 | if ( caption ) |
1440 | html = '[caption id="" align="'+t.align+'" width="'+t.width+'" caption="'+caption+'"]'+html+'[/caption]'; |
1441 | |
1442 | var win = window.dialogArguments || opener || parent || top; |
1443 | win.send_to_editor(html); |
1444 | }, |
1445 | |
1446 | resetImageData : function() { |
1447 | var t = addExtImage; |
1448 | |
1449 | t.width = t.height = ''; |
1450 | document.getElementById('go_button').style.color = '#bbb'; |
1451 | if ( ! document.forms[0].src.value ) |
1452 | document.getElementById('status_img').src = 'images/required.svg'; |
1453 | else document.getElementById('status_img').src = 'images/no.svg'; |
1454 | }, |
1455 | |
1456 | updateImageData : function() { |
1457 | var t = addExtImage; |
1458 | |
1459 | t.width = t.preloadImg.width; |
1460 | t.height = t.preloadImg.height; |
1461 | document.getElementById('go_button').style.color = '#333'; |
1462 | document.getElementById('status_img').src = 'images/yes.svg'; |
1463 | }, |
1464 | |
1465 | getImageData : function() { |
1466 | var t = addExtImage, src = document.forms[0].src.value; |
1467 | |
1468 | if ( ! src ) { |
1469 | t.resetImageData(); |
1470 | return false; |
1471 | } |
1472 | document.getElementById('status_img').src = 'images/loading.svg'; |
1473 | t.preloadImg = new Image(); |
1474 | t.preloadImg.onload = t.updateImageData; |
1475 | t.preloadImg.onerror = t.resetImageData; |
1476 | t.preloadImg.src = src; |
1477 | } |
1478 | } |
1479 | //]]> |
1480 | </script> |
1481 | |
1482 | <div id="media-items"> |
1483 | <div class="media-item media-blank"> |
1484 | <?php echo call_user_func($callback); ?> |
1485 | </div> |
1486 | </div> |
1487 | </form> |
1488 | <?php |
1489 | } else { |
1490 | wp_die( __('Unknown action.') ); |
1491 | } |
1492 | } |
1493 | |
1494 | /** |
1495 | * {@internal Missing Short Description}} |
1496 | * |
1497 | * @since unknown |
1498 | * |
1499 | * @param unknown_type $errors |
1500 | */ |
1501 | function media_upload_gallery_form($errors) { |
1502 | global $redir_tab; |
1503 | |
1504 | $redir_tab = 'gallery'; |
1505 | media_upload_header(); |
1506 | |
1507 | $post_id = intval($_REQUEST['post_id']); |
1508 | $form_action_url = admin_url("media-upload.php?type={$GLOBALS['type']}&tab=gallery&post_id=$post_id"); |
1509 | ?> |
1510 | |
1511 | <script type="text/javascript"> |
1512 | <!-- |
1513 | jQuery(function($){ |
1514 | var preloaded = $(".media-item.preloaded"); |
1515 | if ( preloaded.length > 0 ) { |
1516 | preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); |
1517 | updateMediaForm(); |
1518 | } |
1519 | }); |
1520 | --> |
1521 | </script> |
1522 | |
1523 | <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form validate" id="gallery-form"> |
1524 | <?php wp_nonce_field('media-form'); ?> |
1525 | <?php //media_upload_form( $errors ); ?> |
1526 | <table class="widefat" cellspacing="0"> |
1527 | <thead><tr> |
1528 | <th><?php _e('Media'); ?></th> |
1529 | <th class="order-head"><?php _e('Order'); ?></th> |
1530 | </tr></thead> |
1531 | </table> |
1532 | <div id="media-items"> |
1533 | <?php echo get_media_items($post_id, $errors); ?> |
1534 | </div> |
1535 | |
1536 | <p class="ml-submit"> |
1537 | <input type="submit" class="button savebutton" style="display:none;" name="save" id="save-all" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" /> |
1538 | <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
1539 | <input type="hidden" name="type" value="<?php echo attribute_escape( $GLOBALS['type'] ); ?>" /> |
1540 | <input type="hidden" name="tab" value="<?php echo attribute_escape( $GLOBALS['tab'] ); ?>" /> |
1541 | </p> |
1542 | |
1543 | <div id="gallery-settings" style="display:none;"> |
1544 | <div class="title"><?php _e('Gallery Settings'); ?></div> |
1545 | <table id="basic" class="describe"><tbody> |
1546 | <tr> |
1547 | <th scope="row" class="label"> |
1548 | <label> |
1549 | <span class="alignleft"><?php _e('Link thumbnails to:'); ?></span> |
1550 | </label> |
1551 | </th> |
1552 | <td class="field"> |
1553 | <input type="radio" name="linkto" id="linkto-file" value="file" /> |
1554 | <label for="linkto-file" class="radio"><?php _e('Image File'); ?></label> |
1555 | |
1556 | <input type="radio" checked="checked" name="linkto" id="linkto-post" value="post" /> |
1557 | <label for="linkto-post" class="radio"><?php _e('Attachment Page'); ?></label> |
1558 | </td> |
1559 | </tr> |
1560 | |
1561 | <tr> |
1562 | <th scope="row" class="label"> |
1563 | <label> |
1564 | <span class="alignleft"><?php _e('Order images by:'); ?></span> |
1565 | </label> |
1566 | </th> |
1567 | <td class="field"> |
1568 | <select id="orderby" name="orderby"> |
1569 | <option value="menu_order" selected="selected"><?php _e('Menu order'); ?></option> |
1570 | <option value="post_name"><?php _e('Name'); ?></option> |
1571 | <option value="ID"><?php _e('Date/Time'); ?></option> |
1572 | </select> |
1573 | </td> |
1574 | </tr> |
1575 | |
1576 | <tr> |
1577 | <th scope="row" class="label"> |
1578 | <label> |
1579 | <span class="alignleft"><?php _e('Order:'); ?></span> |
1580 | </label> |
1581 | </th> |
1582 | <td class="field"> |
1583 | <input type="radio" checked="checked" name="order" id="order-asc" value="asc" /> |
1584 | <label for="order-asc" class="radio"><?php _e('Ascending'); ?></label> |
1585 | |
1586 | <input type="radio" name="order" id="order-desc" value="desc" /> |
1587 | <label for="order-desc" class="radio"><?php _e('Descending'); ?></label> |
1588 | </td> |
1589 | </tr> |
1590 | |
1591 | <tr> |
1592 | <th scope="row" class="label"> |
1593 | <label> |
1594 | <span class="alignleft"><?php _e('Gallery columns:'); ?></span> |
1595 | </label> |
1596 | </th> |
1597 | <td class="field"> |
1598 | <select id="columns" name="columns"> |
1599 | <option value="2"><?php _e('2'); ?></option> |
1600 | <option value="3" selected="selected"><?php _e('3'); ?></option> |
1601 | <option value="4"><?php _e('4'); ?></option> |
1602 | <option value="5"><?php _e('5'); ?></option> |
1603 | <option value="6"><?php _e('6'); ?></option> |
1604 | <option value="7"><?php _e('7'); ?></option> |
1605 | <option value="8"><?php _e('8'); ?></option> |
1606 | <option value="9"><?php _e('9'); ?></option> |
1607 | </select> |
1608 | </td> |
1609 | </tr> |
1610 | </tbody></table> |
1611 | |
1612 | <p class="ml-submit"> |
1613 | <input type="button" class="button" style="display:none;" onmousedown="wpgallery.update();" name="insert-gallery" id="insert-gallery" value="<?php echo attribute_escape( __( 'Insert gallery' ) ); ?>" /> |
1614 | <input type="button" class="button" style="display:none;" onmousedown="wpgallery.update();" name="update-gallery" id="update-gallery" value="<?php echo attribute_escape( __( 'Update gallery settings' ) ); ?>" /> |
1615 | </p> |
1616 | </div> |
1617 | </form> |
1618 | <?php |
1619 | } |
1620 | |
1621 | /** |
1622 | * {@internal Missing Short Description}} |
1623 | * |
1624 | * @since unknown |
1625 | * |
1626 | * @param unknown_type $errors |
1627 | */ |
1628 | function media_upload_library_form($errors) { |
1629 | global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types; |
1630 | |
1631 | media_upload_header(); |
1632 | |
1633 | $post_id = intval($_REQUEST['post_id']); |
1634 | |
1635 | $form_action_url = admin_url("media-upload.php?type={$GLOBALS['type']}&tab=library&post_id=$post_id"); |
1636 | |
1637 | $_GET['paged'] = isset( $_GET['paged'] ) ? intval($_GET['paged']) : 0; |
1638 | if ( $_GET['paged'] < 1 ) |
1639 | $_GET['paged'] = 1; |
1640 | $start = ( $_GET['paged'] - 1 ) * 10; |
1641 | if ( $start < 1 ) |
1642 | $start = 0; |
1643 | add_filter( 'post_limits', $limit_filter = create_function( '$a', "return 'LIMIT $start, 10';" ) ); |
1644 | |
1645 | list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query(); |
1646 | |
1647 | ?> |
1648 | |
1649 | <form id="filter" action="" method="get"> |
1650 | <input type="hidden" name="type" value="<?php echo attribute_escape( $type ); ?>" /> |
1651 | <input type="hidden" name="tab" value="<?php echo attribute_escape( $tab ); ?>" /> |
1652 | <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" /> |
1653 | <input type="hidden" name="post_mime_type" value="<?php echo attribute_escape( $_GET['post_mime_type'] ); ?>" /> |
1654 | |
1655 | <p id="media-search" class="search-box"> |
1656 | <label class="hidden" for="media-search-input"><?php _e('Search Media');?>:</label> |
1657 | <input type="text" id="media-search-input" class="search-input" name="s" value="<?php the_search_query(); ?>" /> |
1658 | <input type="submit" value="<?php echo attribute_escape( __( 'Search Media' ) ); ?>" class="button" /> |
1659 | </p> |
1660 | |
1661 | <ul class="subsubsub"> |
1662 | <?php |
1663 | $type_links = array(); |
1664 | $_num_posts = (array) wp_count_attachments(); |
1665 | $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts)); |
1666 | foreach ( $matches as $_type => $reals ) |
1667 | foreach ( $reals as $real ) |
1668 | $num_posts[$_type] += $_num_posts[$real]; |
1669 | // If available type specified by media button clicked, filter by that type |
1670 | if ( empty($_GET['post_mime_type']) && !empty($num_posts[$type]) ) { |
1671 | $_GET['post_mime_type'] = $type; |
1672 | list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query(); |
1673 | } |
1674 | if ( empty($_GET['post_mime_type']) || $_GET['post_mime_type'] == 'all' ) |
1675 | $class = ' class="current"'; |
1676 | $type_links[] = "<li><a href='" . clean_url(add_query_arg(array('post_mime_type'=>'all', 'paged'=>false, 'm'=>false))) . "'$class>".__('All Types')."</a>"; |
1677 | foreach ( $post_mime_types as $mime_type => $label ) { |
1678 | $class = ''; |
1679 | |
1680 | if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) ) |
1681 | continue; |
1682 | |
1683 | if ( wp_match_mime_types($mime_type, $_GET['post_mime_type']) ) |
1684 | $class = ' class="current"'; |
1685 | |
1686 | $type_links[] = "<li><a href='" . clean_url(add_query_arg(array('post_mime_type'=>$mime_type, 'paged'=>false))) . "'$class>" . sprintf(__ngettext($label[2][0], $label[2][1], $num_posts[$mime_type]), "<span id='$mime_type-counter'>" . number_format_i18n( $num_posts[$mime_type] ) . '</span>') . '</a>'; |
1687 | } |
1688 | echo implode(' | </li>', $type_links) . '</li>'; |
1689 | unset($type_links); |
1690 | ?> |
1691 | </ul> |
1692 | |
1693 | <div class="tablenav"> |
1694 | |
1695 | <?php |
1696 | $page_links = paginate_links( array( |
1697 | 'base' => add_query_arg( 'paged', '%#%' ), |
1698 | 'format' => '', |
1699 | 'prev_text' => __('«'), |
1700 | 'next_text' => __('»'), |
1701 | 'total' => ceil($wp_query->found_posts / 10), |
1702 | 'current' => $_GET['paged'] |
1703 | )); |
1704 | |
1705 | if ( $page_links ) |
1706 | echo "<div class='tablenav-pages'>$page_links</div>"; |
1707 | ?> |
1708 | |
1709 | <div class="alignleft actions"> |
1710 | <?php |
1711 | |
1712 | $arc_query = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'attachment' ORDER BY post_date DESC"; |
1713 | |
1714 | $arc_result = $wpdb->get_results( $arc_query ); |
1715 | |
1716 | $month_count = count($arc_result); |
1717 | |
1718 | if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { ?> |
1719 | <select name='m'> |
1720 | <option<?php selected( @$_GET['m'], 0 ); ?> value='0'><?php _e('Show all dates'); ?></option> |
1721 | <?php |
1722 | foreach ($arc_result as $arc_row) { |
1723 | if ( $arc_row->yyear == 0 ) |
1724 | continue; |
1725 | $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 ); |
1726 | |
1727 | if ( $arc_row->yyear . $arc_row->mmonth == $_GET['m'] ) |
1728 | $default = ' selected="selected"'; |
1729 | else |
1730 | $default = ''; |
1731 | |
1732 | echo "<option$default value='" . attribute_escape( $arc_row->yyear . $arc_row->mmonth ) . "'>"; |
1733 | echo wp_specialchars( $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear" ); |
1734 | echo "</option>\n"; |
1735 | } |
1736 | ?> |
1737 | </select> |
1738 | <?php } ?> |
1739 | |
1740 | <input type="submit" id="post-query-submit" value="<?php echo attribute_escape( __( 'Filter »' ) ); ?>" class="button-secondary" /> |
1741 | |
1742 | </div> |
1743 | |
1744 | <br class="clear" /> |
1745 | </div> |
1746 | </form> |
1747 | |
1748 | <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form validate" id="library-form"> |
1749 | |
1750 | <?php wp_nonce_field('media-form'); ?> |
1751 | <?php //media_upload_form( $errors ); ?> |
1752 | |
1753 | <script type="text/javascript"> |
1754 | <!-- |
1755 | jQuery(function($){ |
1756 | var preloaded = $(".media-item.preloaded"); |
1757 | if ( preloaded.length > 0 ) { |
1758 | preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');}); |
1759 | updateMediaForm(); |
1760 | } |
1761 | }); |
1762 | --> |
1763 | </script> |
1764 | |
1765 | <div id="media-items"> |
1766 | <?php echo get_media_items(null, $errors); ?> |
1767 | </div> |
1768 | <p class="ml-submit"> |
1769 | <input type="submit" class="button savebutton" name="save" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" /> |
1770 | <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> |
1771 | </p> |
1772 | </form> |
1773 | <?php |
1774 | } |
1775 | |
1776 | /** |
1777 | * {@internal Missing Short Description}} |
1778 | * |
1779 | * @since unknown |
1780 | * |
1781 | * @return unknown |
1782 | */ |
1783 | function type_url_form_image() { |
1784 | |
1785 | if ( apply_filters( 'disable_captions', '' ) ) { |
1786 | $alt = __('Alternate Text'); |
1787 | $alt_help = __('Alt text for the image, e.g. "The Mona Lisa"'); |
1788 | } else { |
1789 | $alt = __('Image Caption'); |
1790 | $alt_help = __('Also used as alternate text for the image'); |
1791 | } |
1792 | |
1793 | $default_align = get_option('image_default_align'); |
1794 | if ( empty($default_align) ) |
1795 | $default_align = 'none'; |
1796 | |
1797 | return ' |
1798 | <table class="describe"><tbody> |
1799 | <tr> |
1800 | <th valign="top" scope="row" class="label" style="width:120px;"> |
1801 | <span class="alignleft"><label for="src">' . __('Image URL') . '</label></span> |
1802 | <span class="alignright"><img id="status_img" src="images/required.svg" title="required" alt="required" /></span> |
1803 | </th> |
1804 | <td class="field"><input id="src" name="src" value="" type="text" aria-required="true" onblur="addExtImage.getImageData()" /></td> |
1805 | </tr> |
1806 | |
1807 | <tr> |
1808 | <th valign="top" scope="row" class="label"> |
1809 | <span class="alignleft"><label for="title">' . __('Image Title') . '</label></span> |
1810 | <span class="alignright"><abbr title="required" class="required">*</abbr></span> |
1811 | </th> |
1812 | <td class="field"><p><input id="title" name="title" value="" type="text" aria-required="true" /></p></td> |
1813 | </tr> |
1814 | |
1815 | <tr> |
1816 | <th valign="top" scope="row" class="label"> |
1817 | <span class="alignleft"><label for="alt">' . $alt . '</label></span> |
1818 | </th> |
1819 | <td class="field"><input id="alt" name="alt" value="" type="text" aria-required="true" /> |
1820 | <p class="help">' . $alt_help . '</p></td> |
1821 | </tr> |
1822 | |
1823 | <tr class="align"> |
1824 | <th valign="top" scope="row" class="label"><p><label for="align">' . __('Alignment') . '</label></p></th> |
1825 | <td class="field"> |
1826 | <input name="align" id="align-none" value="none" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'none' ? ' checked="checked"' : '').' /> |
1827 | <label for="align-none" class="align image-align-none-label">' . __('None') . '</label> |
1828 | <input name="align" id="align-left" value="left" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'left' ? ' checked="checked"' : '').' /> |
1829 | <label for="align-left" class="align image-align-left-label">' . __('Left') . '</label> |
1830 | <input name="align" id="align-center" value="center" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'center' ? ' checked="checked"' : '').' /> |
1831 | <label for="align-center" class="align image-align-center-label">' . __('Center') . '</label> |
1832 | <input name="align" id="align-right" value="right" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'right' ? ' checked="checked"' : '').' /> |
1833 | <label for="align-right" class="align image-align-right-label">' . __('Right') . '</label> |
1834 | </td> |
1835 | </tr> |
1836 | |
1837 | <tr> |
1838 | <th valign="top" scope="row" class="label"> |
1839 | <span class="alignleft"><label for="url">' . __('Link Image To:') . '</label></span> |
1840 | </th> |
1841 | <td class="field"><input id="url" name="url" value="" type="text" /><br /> |
1842 | |
1843 | <button type="button" class="button" value="" onclick="document.forms[0].url.value=null">' . __('None') . '</button> |
1844 | <button type="button" class="button" value="" onclick="document.forms[0].url.value=document.forms[0].src.value">' . __('Link to image') . '</button> |
1845 | <p class="help">' . __('Enter a link URL or click above for presets.') . '</p></td> |
1846 | </tr> |
1847 | |
1848 | <tr> |
1849 | <td></td> |
1850 | <td> |
1851 | <input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . attribute_escape(__('Insert into Post')) . '" /> |
1852 | </td> |
1853 | </tr> |
1854 | </tbody></table> |
1855 | '; |
1856 | |
1857 | } |
1858 | |
1859 | /** |
1860 | * {@internal Missing Short Description}} |
1861 | * |
1862 | * @since unknown |
1863 | * |
1864 | * @return unknown |
1865 | */ |
1866 | function type_url_form_audio() { |
1867 | return ' |
1868 | <table class="describe"><tbody> |
1869 | <tr> |
1870 | <th valign="top" scope="row" class="label"> |
1871 | <span class="alignleft"><label for="insertonly[href]">' . __('Audio File URL') . '</label></span> |
1872 | <span class="alignright"><abbr title="required" class="required">*</abbr></span> |
1873 | </th> |
1874 | <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td> |
1875 | </tr> |
1876 | <tr> |
1877 | <th valign="top" scope="row" class="label"> |
1878 | <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span> |
1879 | <span class="alignright"><abbr title="required" class="required">*</abbr></span> |
1880 | </th> |
1881 | <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td> |
1882 | </tr> |
1883 | <tr><td></td><td class="help">' . __('Link text, e.g. "Still Alive by Jonathan Coulton"') . '</td></tr> |
1884 | <tr> |
1885 | <td></td> |
1886 | <td> |
1887 | <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" /> |
1888 | </td> |
1889 | </tr> |
1890 | </tbody></table> |
1891 | '; |
1892 | } |
1893 | |
1894 | /** |
1895 | * {@internal Missing Short Description}} |
1896 | * |
1897 | * @since unknown |
1898 | * |
1899 | * @return unknown |
1900 | */ |
1901 | function type_url_form_video() { |
1902 | return ' |
1903 | <table class="describe"><tbody> |
1904 | <tr> |
1905 | <th valign="top" scope="row" class="label"> |
1906 | <span class="alignleft"><label for="insertonly[href]">' . __('Video URL') . '</label></span> |
1907 | <span class="alignright"><abbr title="required" class="required">*</abbr></span> |
1908 | </th> |
1909 | <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td> |
1910 | </tr> |
1911 | <tr> |
1912 | <th valign="top" scope="row" class="label"> |
1913 | <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span> |
1914 | <span class="alignright"><abbr title="required" class="required">*</abbr></span> |
1915 | </th> |
1916 | <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td> |
1917 | </tr> |
1918 | <tr><td></td><td class="help">' . __('Link text, e.g. "Lucy on YouTube"') . '</td></tr> |
1919 | <tr> |
1920 | <td></td> |
1921 | <td> |
1922 | <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" /> |
1923 | </td> |
1924 | </tr> |
1925 | </tbody></table> |
1926 | '; |
1927 | } |
1928 | |
1929 | /** |
1930 | * {@internal Missing Short Description}} |
1931 | * |
1932 | * @since unknown |
1933 | * |
1934 | * @return unknown |
1935 | */ |
1936 | function type_url_form_file() { |
1937 | return ' |
1938 | <table class="describe"><tbody> |
1939 | <tr> |
1940 | <th valign="top" scope="row" class="label"> |
1941 | <span class="alignleft"><label for="insertonly[href]">' . __('URL') . '</label></span> |
1942 | <span class="alignright"><abbr title="required" class="required">*</abbr></span> |
1943 | </th> |
1944 | <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td> |
1945 | </tr> |
1946 | <tr> |
1947 | <th valign="top" scope="row" class="label"> |
1948 | <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span> |
1949 | <span class="alignright"><abbr title="required" class="required">*</abbr></span> |
1950 | </th> |
1951 | <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td> |
1952 | </tr> |
1953 | <tr><td></td><td class="help">' . __('Link text, e.g. "Ransom Demands (PDF)"') . '</td></tr> |
1954 | <tr> |
1955 | <td></td> |
1956 | <td> |
1957 | <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" /> |
1958 | </td> |
1959 | </tr> |
1960 | </tbody></table> |
1961 | '; |
1962 | } |
1963 | |
1964 | /** |
1965 | * {@internal Missing Short Description}} |
1966 | * |
1967 | * Support a GET parameter for disabling the flash uploader. |
1968 | * |
1969 | * @since unknown |
1970 | * |
1971 | * @param unknown_type $flash |
1972 | * @return unknown |
1973 | */ |
1974 | function media_upload_use_flash($flash) { |
1975 | if ( array_key_exists('flash', $_REQUEST) ) |
1976 | $flash = !empty($_REQUEST['flash']); |
1977 | return $flash; |
1978 | } |
1979 | |
1980 | add_filter('flash_uploader', 'media_upload_use_flash'); |
1981 | |
1982 | /** |
1983 | * {@internal Missing Short Description}} |
1984 | * |
1985 | * @since unknown |
1986 | */ |
1987 | function media_upload_flash_bypass() { |
1988 | echo '<p class="upload-flash-bypass">'; |
1989 | printf( __('You are using the Flash uploader. Problems? Try the <a href="%s">Browser uploader</a> instead.'), clean_url(add_query_arg('flash', 0)) ); |
1990 | echo '</p>'; |
1991 | } |
1992 | |
1993 | /** |
1994 | * {@internal Missing Short Description}} |
1995 | * |
1996 | * @since unknown |
1997 | */ |
1998 | function media_upload_html_bypass() { |
1999 | echo '<p class="upload-html-bypass">'; |
2000 | if ( array_key_exists('flash', $_REQUEST) ) |
2001 | // the user manually selected the browser uploader, so let them switch back to Flash |
2002 | printf( __('You are using the Browser uploader. Try the <a href="%s">Flash uploader</a> instead.'), clean_url(add_query_arg('flash', 1)) ); |
2003 | else |
2004 | // the user probably doesn't have Flash |
2005 | printf( __('You are using the Browser uploader.') ); |
2006 | |
2007 | echo '</p>'; |
2008 | } |
2009 | |
2010 | add_action('post-flash-upload-ui', 'media_upload_flash_bypass'); |
2011 | add_action('post-html-upload-ui', 'media_upload_html_bypass'); |
2012 | |
2013 | /** |
2014 | * {@internal Missing Short Description}} |
2015 | * |
2016 | * Make sure the GET parameter sticks when we submit a form. |
2017 | * |
2018 | * @since unknown |
2019 | * |
2020 | * @param unknown_type $url |
2021 | * @return unknown |
2022 | */ |
2023 | function media_upload_bypass_url($url) { |
2024 | if ( array_key_exists('flash', $_REQUEST) ) |
2025 | $url = add_query_arg('flash', intval($_REQUEST['flash'])); |
2026 | return $url; |
2027 | } |
2028 | |
2029 | add_filter('media_upload_form_url', 'media_upload_bypass_url'); |
2030 | |
2031 | |
2032 | |
2033 | add_filter('async_upload_image', 'get_media_item', 10, 2); |
2034 | add_filter('async_upload_audio', 'get_media_item', 10, 2); |
2035 | add_filter('async_upload_video', 'get_media_item', 10, 2); |
2036 | add_filter('async_upload_file', 'get_media_item', 10, 2); |
2037 | |
2038 | add_action('media_upload_image', 'media_upload_image'); |
2039 | add_action('media_upload_audio', 'media_upload_audio'); |
2040 | add_action('media_upload_video', 'media_upload_video'); |
2041 | add_action('media_upload_file', 'media_upload_file'); |
2042 | |
2043 | add_filter('media_upload_gallery', 'media_upload_gallery'); |
2044 | |
2045 | add_filter('media_upload_library', 'media_upload_library'); |
2046 | |
2047 | ?> |