Attachments - Version 1.5.6

Version Description

  • Better restriction of JavaScript assets as a preventative measure for potential plugin conflicts
Download this release

Release Info

Developer jchristopher
Plugin Icon wp plugin Attachments
Version 1.5.6
Comparing to
See all releases

Code changes from version 1.5.5 to 1.5.6

Files changed (3) hide show
  1. attachments.php +20 -3
  2. js/attachments.js +10 -151
  3. readme.txt +7 -10
attachments.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Attachments
4
  Plugin URI: http://mondaybynoon.com/wordpress-attachments/
5
  Description: Attachments gives the ability to append any number of Media Library items to Pages, Posts, and Custom Post Types
6
- Version: 1.5.5
7
  Author: Jonathan Christopher
8
  Author URI: http://mondaybynoon.com/
9
  */
@@ -65,6 +65,7 @@ if( IS_ADMIN )
65
  add_action( 'admin_head', 'attachments_init_js' );
66
  add_action( 'save_post', 'attachments_save' );
67
  add_action( 'admin_menu', 'attachments_menu' );
 
68
 
69
  load_plugin_textdomain( 'attachments', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
70
  }
@@ -458,6 +459,22 @@ function attachments_get_attachments( $post_id=null )
458
 
459
 
460
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
461
 
462
 
463
 
@@ -474,10 +491,10 @@ function attachments_init()
474
  global $pagenow;
475
 
476
  wp_enqueue_script( 'jquery-ui-core' );
477
- wp_enqueue_style( 'thickbox' );
478
 
 
479
  wp_enqueue_style( 'attachments', WP_PLUGIN_URL . '/attachments/css/attachments.css' );
480
- wp_enqueue_script( 'attachments', WP_PLUGIN_URL . '/attachments/js/attachments.js', array( 'jquery', 'thickbox' ), false, false );
481
 
482
  if( function_exists( 'load_plugin_textdomain' ) )
483
  {
3
  Plugin Name: Attachments
4
  Plugin URI: http://mondaybynoon.com/wordpress-attachments/
5
  Description: Attachments gives the ability to append any number of Media Library items to Pages, Posts, and Custom Post Types
6
+ Version: 1.5.6
7
  Author: Jonathan Christopher
8
  Author URI: http://mondaybynoon.com/
9
  */
65
  add_action( 'admin_head', 'attachments_init_js' );
66
  add_action( 'save_post', 'attachments_save' );
67
  add_action( 'admin_menu', 'attachments_menu' );
68
+ add_action( 'admin_footer', 'attachments_footer_js' );
69
 
70
  load_plugin_textdomain( 'attachments', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
71
  }
459
 
460
 
461
 
462
+ function attachments_footer_js()
463
+ {
464
+ $uri = isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : NULL ;
465
+ $file = basename( parse_url( $uri, PHP_URL_PATH ) );
466
+
467
+ if( $uri && in_array( $file, array( 'post.php', 'post-new.php' ) ) )
468
+ {
469
+ // we only want this to fire on edit screens
470
+ echo '<script type="text/javascript">';
471
+ include 'js/attachments.js';
472
+ echo '</script>';
473
+ }
474
+ }
475
+
476
+
477
+
478
 
479
 
480
 
491
  global $pagenow;
492
 
493
  wp_enqueue_script( 'jquery-ui-core' );
494
+ wp_enqueue_script( 'thickbox' );
495
 
496
+ wp_enqueue_style( 'thickbox' );
497
  wp_enqueue_style( 'attachments', WP_PLUGIN_URL . '/attachments/css/attachments.css' );
 
498
 
499
  if( function_exists( 'load_plugin_textdomain' ) )
500
  {
js/attachments.js CHANGED
@@ -1,151 +1,10 @@
1
- var attachments_button_label_updater = null;
2
- var attachments_button_label = 'Attach File';
3
- var attachments_asset = null;
4
- var attachments_hijacked_thickbox = false;
5
-
6
- function init_attachments_sortable() {
7
- if(jQuery('div#attachments-list ul:data(sortable)').length==0&&jQuery('div#attachments-list ul li').length>0){
8
- jQuery('div#attachments-list ul').sortable({
9
- containment: 'parent',
10
- stop: function(e, ui) {
11
- jQuery('#attachments-list ul li').each(function(i, id) {
12
- jQuery(this).find('input.attachment_order').val(i+1);
13
- });
14
- }
15
- });
16
- }
17
- }
18
-
19
-
20
-
21
-
22
- function attachments_handle_attach(title,caption,id,thumb){
23
-
24
- attachment_index = jQuery('li.attachments-file', top.document).length;
25
- new_attachments = '';
26
-
27
- attachment_name = title;
28
- attachment_caption = caption;
29
- attachment_id = id;
30
- attachment_thumb = thumb;
31
-
32
- attachment_index++;
33
- new_attachments += '<li class="attachments-file">';
34
- new_attachments += '<h2><a href="#" class="attachment-handle"><span class="attachment-handle-icon"><img src="' + attachments_base + '/images/handle.gif" alt="Drag" /></span></a><span class="attachment-name">' + attachment_name + '</span><span class="attachment-delete"><a href="#">Delete</a></span></h2>';
35
- new_attachments += '<div class="attachments-fields">';
36
- new_attachments += '<div class="textfield" id="field_attachment_title_' + attachment_index + '"><label for="attachment_title_' + attachment_index + '">Title</label><input type="text" id="attachment_title_' + attachment_index + '" name="attachment_title_' + attachment_index + '" value="' + attachment_name + '" size="20" /></div>';
37
- new_attachments += '<div class="textfield" id="field_attachment_caption_' + attachment_index + '"><label for="attachment_caption_' + attachment_index + '">Caption</label><input type="text" id="attachment_caption_' + attachment_index + '" name="attachment_caption_' + attachment_index + '" value="' + attachment_caption + '" size="20" /></div>';
38
- new_attachments += '</div>';
39
- new_attachments += '<div class="attachments-data">';
40
- new_attachments += '<input type="hidden" name="attachment_id_' + attachment_index + '" id="attachment_id_' + attachment_index + '" value="' + attachment_id + '" />';
41
- new_attachments += '<input type="hidden" class="attachment_order" name="attachment_order_' + attachment_index + '" id="attachment_order_' + attachment_index + '" value="' + attachment_index + '" />';
42
- new_attachments += '</div>';
43
- new_attachments += '<div class="attachment-thumbnail"><span class="attachments-thumbnail">';
44
-
45
-
46
- new_attachments += '<img src="' + attachment_thumb + '" alt="Thumbnail" />';
47
- new_attachments += '</span></div>';
48
- new_attachments += '</li>';
49
-
50
- jQuery('div#attachments-list ul', top.document).append(new_attachments);
51
-
52
- if(jQuery('#attachments-list li', top.document).length > 0) {
53
-
54
- // We've got some attachments
55
- jQuery('#attachments-list', top.document).show();
56
-
57
- }
58
- }
59
-
60
-
61
- jQuery(document).ready(function() {
62
-
63
- if (typeof send_to_editor === 'function')
64
- {
65
- var attachments_send_to_editor_default = send_to_editor;
66
- send_to_editor = function(markup){
67
- clearInterval(attachments_button_label_updater);
68
- if(attachments_hijacked_thickbox){
69
- attachments_hijacked_thickbox = false; // reset our flag
70
- // our click handler is in the interval, not here
71
- }else{
72
- attachments_send_to_editor_default(markup);
73
- }
74
- }
75
- }
76
-
77
- function attachments_update_button_label(){
78
- if(attachments_hijacked_thickbox){
79
- // our new click handler for the attach button
80
- jQuery('#TB_iframeContent').contents().find('td.savesend input').unbind('click').click(function(e){
81
- theparent = jQuery(this).parent().parent().parent();
82
- jQuery(this).after('<span class="attachments-attached">Attached!</span>');
83
- thetitle = theparent.find('tr.post_title td.field input').val();
84
- thecaption = theparent.find('tr.post_excerpt td.field input').val();
85
- theid = theparent.find('td.imgedit-response').attr('id').replace('imgedit-response-','');
86
- thethumb = theparent.parent().parent().find('img.pinkynail').attr('src');
87
- attachments_handle_attach(thetitle,thecaption,theid,thethumb);
88
- theparent.find('span.attachments-attached').delay(1000).fadeOut('fast');
89
- return false;
90
- });
91
- // update button
92
- if(jQuery('#TB_iframeContent').contents().find('.media-item .savesend input[type=submit], #insertonlybutton').length){
93
- jQuery('#TB_iframeContent').contents().find('.media-item .savesend input[type=submit], #insertonlybutton').val(attachments_button_label);
94
- }
95
- if(jQuery('#TB_iframeContent').contents().find('#tab-type_url').length){
96
- jQuery('#TB_iframeContent').contents().find('#tab-type_url').hide();
97
- }
98
- if(jQuery('#TB_iframeContent').contents().find('tr.post_title').length){
99
- // we need to ALWAYS get the fullsize since we're retrieving the guid
100
- // if the user inserts an image somewhere else and chooses another size, everything breaks
101
- jQuery('#TB_iframeContent').contents().find('tr.image-size input[value="full"]').prop('checked', true);
102
- jQuery('#TB_iframeContent').contents().find('tr.post_title,tr.image_alt,tr.post_excerpt,tr.image-size,tr.post_content,tr.url,tr.align,tr.submit>td>a.del-link').hide();
103
- }
104
- }
105
- if(jQuery('#TB_iframeContent').contents().length==0&&attachments_hijacked_thickbox){
106
- // the thickbox was closed
107
- clearInterval(attachments_button_label_updater);
108
- attachments_hijacked_thickbox = false;
109
- }
110
- }
111
-
112
- // thickbox handler
113
- jQuery('a#attachments-thickbox').live('click',function(event){
114
- var href = jQuery(this).attr('href'), width = jQuery(window).width(), H = jQuery(window).height(), W = ( 720 < width ) ? 720 : width;
115
- if ( ! href ) return;
116
- href = href.replace(/&width=[0-9]+/g, '');
117
- href = href.replace(/&height=[0-9]+/g, '');
118
- jQuery(this).attr( 'href', href + '&width=' + ( W - 80 ) + '&height=' + ( H - 85 ) );
119
- attachments_hijacked_thickbox = true;
120
- attachments_button_label_updater = setInterval(attachments_update_button_label, 500);
121
- // jQuery(this).parent().parent().find('ul.attachments-pro-list').addClass('attachments-pro-context');
122
- tb_show('Attach a file', event.target.href, false);
123
- return false;
124
- });
125
-
126
- // If there are no attachments, let's hide this thing...
127
- if(jQuery('div#attachments-list li').length == 0) {
128
- jQuery('#attachments-list').hide();
129
- }
130
-
131
- // Hook our delete links
132
- jQuery('span.attachment-delete a').live('click', function() {
133
- attachment_parent = jQuery(this).parent().parent().parent();
134
- attachment_parent.slideUp(function() {
135
- attachment_parent.remove();
136
- jQuery('#attachments-list ul li').each(function(i, id) {
137
- jQuery(this).find('input.attachment_order').val(i+1);
138
- });
139
- if(jQuery('div#attachments-list li').length == 0) {
140
- jQuery('#attachments-list').slideUp(function() {
141
- jQuery('#attachments-list').hide();
142
- });
143
- }
144
- });
145
- return false;
146
- });
147
-
148
- // we also need to get a bit hacky with sortable...
149
- setInterval('init_attachments_sortable()',500);
150
-
151
- });
1
+ var attachments_button_label_updater=null;var attachments_button_label='Attach File';var attachments_asset=null;var attachments_hijacked_thickbox=false;function init_attachments_sortable(){if(jQuery('div#attachments-list ul:data(sortable)').length==0&&jQuery('div#attachments-list ul li').length>0){jQuery('div#attachments-list ul').sortable({containment:'parent',stop:function(e,ui){jQuery('#attachments-list ul li').each(function(i,id){jQuery(this).find('input.attachment_order').val(i+1);});}});}}
2
+ function attachments_handle_attach(title,caption,id,thumb){attachment_index=jQuery('li.attachments-file',top.document).length;new_attachments='';attachment_name=title;attachment_caption=caption;attachment_id=id;attachment_thumb=thumb;attachment_index++;new_attachments+='<li class="attachments-file">';new_attachments+='<h2><a href="#" class="attachment-handle"><span class="attachment-handle-icon"><img src="'+attachments_base+'/images/handle.gif" alt="Drag" /></span></a><span class="attachment-name">'+attachment_name+'</span><span class="attachment-delete"><a href="#">Delete</a></span></h2>';new_attachments+='<div class="attachments-fields">';new_attachments+='<div class="textfield" id="field_attachment_title_'+attachment_index+'"><label for="attachment_title_'+attachment_index+'">Title</label><input type="text" id="attachment_title_'+attachment_index+'" name="attachment_title_'+attachment_index+'" value="'+attachment_name+'" size="20" /></div>';new_attachments+='<div class="textfield" id="field_attachment_caption_'+attachment_index+'"><label for="attachment_caption_'+attachment_index+'">Caption</label><input type="text" id="attachment_caption_'+attachment_index+'" name="attachment_caption_'+attachment_index+'" value="'+attachment_caption+'" size="20" /></div>';new_attachments+='</div>';new_attachments+='<div class="attachments-data">';new_attachments+='<input type="hidden" name="attachment_id_'+attachment_index+'" id="attachment_id_'+attachment_index+'" value="'+attachment_id+'" />';new_attachments+='<input type="hidden" class="attachment_order" name="attachment_order_'+attachment_index+'" id="attachment_order_'+attachment_index+'" value="'+attachment_index+'" />';new_attachments+='</div>';new_attachments+='<div class="attachment-thumbnail"><span class="attachments-thumbnail">';new_attachments+='<img src="'+attachment_thumb+'" alt="Thumbnail" />';new_attachments+='</span></div>';new_attachments+='</li>';jQuery('div#attachments-list ul',top.document).append(new_attachments);if(jQuery('#attachments-list li',top.document).length>0){jQuery('#attachments-list',top.document).show();}}
3
+ jQuery(document).ready(function(){if(typeof send_to_editor==='function')
4
+ {var attachments_send_to_editor_default=send_to_editor;send_to_editor=function(markup){clearInterval(attachments_button_label_updater);if(attachments_hijacked_thickbox){attachments_hijacked_thickbox=false;}else{attachments_send_to_editor_default(markup);}}}
5
+ function attachments_update_button_label(){if(attachments_hijacked_thickbox){jQuery('#TB_iframeContent').contents().find('td.savesend input').unbind('click').click(function(e){theparent=jQuery(this).parent().parent().parent();jQuery(this).after('<span class="attachments-attached">Attached!</span>');thetitle=theparent.find('tr.post_title td.field input').val();thecaption=theparent.find('tr.post_excerpt td.field input').val();theid=theparent.find('td.imgedit-response').attr('id').replace('imgedit-response-','');thethumb=theparent.parent().parent().find('img.pinkynail').attr('src');attachments_handle_attach(thetitle,thecaption,theid,thethumb);theparent.find('span.attachments-attached').delay(1000).fadeOut('fast');return false;});if(jQuery('#TB_iframeContent').contents().find('.media-item .savesend input[type=submit], #insertonlybutton').length){jQuery('#TB_iframeContent').contents().find('.media-item .savesend input[type=submit], #insertonlybutton').val(attachments_button_label);}
6
+ if(jQuery('#TB_iframeContent').contents().find('#tab-type_url').length){jQuery('#TB_iframeContent').contents().find('#tab-type_url').hide();}
7
+ if(jQuery('#TB_iframeContent').contents().find('tr.post_title').length){jQuery('#TB_iframeContent').contents().find('tr.image-size input[value="full"]').prop('checked',true);jQuery('#TB_iframeContent').contents().find('tr.post_title,tr.image_alt,tr.post_excerpt,tr.image-size,tr.post_content,tr.url,tr.align,tr.submit>td>a.del-link').hide();}}
8
+ if(jQuery('#TB_iframeContent').contents().length==0&&attachments_hijacked_thickbox){clearInterval(attachments_button_label_updater);attachments_hijacked_thickbox=false;}}
9
+ jQuery('a#attachments-thickbox').live('click',function(event){var href=jQuery(this).attr('href'),width=jQuery(window).width(),H=jQuery(window).height(),W=(720<width)?720:width;if(!href)return;href=href.replace(/&width=[0-9]+/g,'');href=href.replace(/&height=[0-9]+/g,'');jQuery(this).attr('href',href+'&width='+(W-80)+'&height='+(H-85));attachments_hijacked_thickbox=true;attachments_button_label_updater=setInterval(attachments_update_button_label,500);tb_show('Attach a file',event.target.href,false);return false;});if(jQuery('div#attachments-list li').length==0){jQuery('#attachments-list').hide();}
10
+ jQuery('span.attachment-delete a').live('click',function(){attachment_parent=jQuery(this).parent().parent().parent();attachment_parent.slideUp(function(){attachment_parent.remove();jQuery('#attachments-list ul li').each(function(i,id){jQuery(this).find('input.attachment_order').val(i+1);});if(jQuery('div#attachments-list li').length==0){jQuery('#attachments-list').slideUp(function(){jQuery('#attachments-list').hide();});}});return false;});setInterval('init_attachments_sortable()',500);});
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -4,20 +4,20 @@ Donate link: http://mondaybynoon.com/donate/
4
  Tags: post, page, posts, pages, images, PDF, doc, Word, image, jpg, jpeg, picture, pictures, photos, attachment
5
  Requires at least: 3.0
6
  Tested up to: 3.2.1
7
- Stable tag: 1.5.5
8
 
9
  Attachments allows you to simply append any number of items from your WordPress Media Library to Posts, Pages, and Custom Post Types
10
 
11
  == Description ==
12
 
13
- = Attachments Pro Now Availble! =
14
 
15
  Attachments Pro brings a number of frequently requested features:
16
 
17
  * Multiple Attachments instances on edit screens
18
  * Customizable field labels
19
  * Unlimited number of fields per Attachment
20
- * Ability to define rules limiting the availablility of Attachments on edit screens
21
 
22
  **Much more information** available about [Attachments Pro](http://mondaybynoon.com/store/attachments-pro/)
23
 
@@ -27,12 +27,6 @@ Attachments allows you to simply append any number of items from your WordPress
27
 
28
  There is an [outdated] **screencast available** on the [plugin home page](http://mondaybynoon.com/wordpress-attachments/) that will be updated soon.
29
 
30
- ![Attachments meta box](http://mondaybynoon.com/images/attachments/screenshot-1.jpg)
31
-
32
- ![Attachments browse](http://mondaybynoon.com/images/attachments/screenshot-2.jpg)
33
-
34
- ![Attachments after they've been added](http://mondaybynoon.com/images/attachments/screenshot-3.jpg)
35
-
36
  == Installation ==
37
 
38
  1. Download the plugin and extract the files
@@ -67,8 +61,11 @@ Attachments uses WordPress' built in Media library for uploads and storage.
67
 
68
  == Changelog ==
69
 
 
 
 
70
  = 1.5.5 =
71
- # Re-implemented bulk Attach
72
 
73
  = 1.5.4 =
74
  * Updated the way Thickbox is hijacked in an effort to be more stable among tab switching. As an unfortunate result, bulk attaching is no longer possible.
4
  Tags: post, page, posts, pages, images, PDF, doc, Word, image, jpg, jpeg, picture, pictures, photos, attachment
5
  Requires at least: 3.0
6
  Tested up to: 3.2.1
7
+ Stable tag: 1.5.6
8
 
9
  Attachments allows you to simply append any number of items from your WordPress Media Library to Posts, Pages, and Custom Post Types
10
 
11
  == Description ==
12
 
13
+ = Attachments Pro Now Available! =
14
 
15
  Attachments Pro brings a number of frequently requested features:
16
 
17
  * Multiple Attachments instances on edit screens
18
  * Customizable field labels
19
  * Unlimited number of fields per Attachment
20
+ * Ability to define rules limiting the availability of Attachments on edit screens
21
 
22
  **Much more information** available about [Attachments Pro](http://mondaybynoon.com/store/attachments-pro/)
23
 
27
 
28
  There is an [outdated] **screencast available** on the [plugin home page](http://mondaybynoon.com/wordpress-attachments/) that will be updated soon.
29
 
 
 
 
 
 
 
30
  == Installation ==
31
 
32
  1. Download the plugin and extract the files
61
 
62
  == Changelog ==
63
 
64
+ = 1.5.6 =
65
+ * Better restriction of JavaScript assets as a preventative measure for potential plugin conflicts
66
+
67
  = 1.5.5 =
68
+ * Re-implemented bulk Attach
69
 
70
  = 1.5.4 =
71
  * Updated the way Thickbox is hijacked in an effort to be more stable among tab switching. As an unfortunate result, bulk attaching is no longer possible.