Ticket #21585: 21585-3.patch
File 21585-3.patch, 23.8 KB (added by , 12 years ago) |
---|
-
wp-admin/admin-ajax.php
50 50 'menu-locations-save', 'menu-quick-search', 'meta-box-order', 'get-permalink', 51 51 'sample-permalink', 'inline-save', 'inline-save-tax', 'find_posts', 'widgets-order', 52 52 'save-widget', 'set-post-thumbnail', 'date_format', 'time_format', 'wp-fullscreen-save-post', 53 'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 53 'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'mce-gallery-preview', 54 54 ); 55 55 56 56 // Register core Ajax calls. -
wp-admin/includes/ajax-actions.php
50 50 51 51 wp_die( 0 ); 52 52 } 53 53 54 function wp_ajax_ajax_tag_search() { 54 55 global $wpdb; 55 56 … … 1801 1802 update_user_meta( get_current_user_id(), 'dismissed_wp_pointers', $dismissed ); 1802 1803 wp_die( 1 ); 1803 1804 } 1805 1806 function wp_ajax_mce_gallery_preview() { 1807 if ( empty($_POST['post_ID']) || empty($_POST['shortcode']) ) 1808 wp_die( 0 ); 1809 1810 $post_id = (int) $_POST['post_ID']; 1811 if ( !current_user_can('edit_post', $post_id) ) 1812 wp_die('-1'); 1813 1814 $shortcode_args = trim( str_replace('[gallery', '', $_POST['shortcode']), '[] //' ); 1815 $args = $shortcode_args ? shortcode_parse_atts( stripslashes($shortcode_args) ) : array(); 1816 $args['id'] = $post_id; 1817 $args['mce_preview'] = true; 1818 1819 echo preg_replace('/[^a-z0-9_]+/', '', $_POST['mcediv_id']) . gallery_shortcode( $args ); 1820 wp_die(); 1821 } 1822 -
wp-admin/includes/media.php
470 470 471 471 if ( isset($_POST['insert-gallery']) || isset($_POST['update-gallery']) ) { ?> 472 472 <script type="text/javascript"> 473 /* <![CDATA[ */474 473 var win = window.dialogArguments || opener || parent || top; 475 474 win.tb_remove(); 476 /* ]]> */477 475 </script> 478 476 <?php 479 477 exit; … … 1630 1628 ?> 1631 1629 1632 1630 <script type="text/javascript"> 1633 <!--1634 1631 jQuery(function($){ 1635 1632 var preloaded = $(".media-item.preloaded"); 1636 1633 if ( preloaded.length > 0 ) { … … 1638 1635 updateMediaForm(); 1639 1636 } 1640 1637 }); 1641 -->1642 1638 </script> 1643 1639 <div id="sort-buttons" class="hide-if-no-js"> 1644 1640 <span> … … 1675 1671 1676 1672 <div id="gallery-settings" style="display:none;"> 1677 1673 <div class="title"><?php _e('Gallery Settings'); ?></div> 1674 1675 <p>(Temporary, for testing only. UI is changing)</p> 1676 <p><input type="text" style="width:60%;" id="shortcode" value="[gallery]"></p> 1677 1678 <!-- 1678 1679 <table id="basic" class="describe"><tbody> 1679 1680 <tr> 1680 1681 <th scope="row" class="label"> … … 1743 1744 </td> 1744 1745 </tr> 1745 1746 </tbody></table> 1747 --> 1746 1748 1747 1749 <p class="ml-submit"> 1748 1750 <input type="button" class="button" style="display:none;" onMouseDown="wpgallery.update();" name="insert-gallery" id="insert-gallery" value="<?php esc_attr_e( 'Insert gallery' ); ?>" /> -
wp-admin/js/gallery.js
60 60 w = wpgallery.getWin(); 61 61 62 62 $('#save-all, #gallery-settings').show(); 63 if ( typeof w.tinyMCE != 'undefined' && w.tinyMCE.activeEditor && ! w.tinyMCE.activeEditor.isHidden() ) { 64 wpgallery.mcemode = true; 65 wpgallery.init(); 63 if ( typeof w.tinymce != 'undefined' && w.tinymce.activeEditor && ! w.tinymce.activeEditor.isHidden() ) { 64 wpgallery.init(true); 66 65 } else { 67 66 $('#insert-gallery').show(); 68 67 } … … 74 73 /* gallery settings */ 75 74 var tinymce = null, tinyMCE, wpgallery; 76 75 76 (function($){ 77 77 wpgallery = { 78 78 mcemode : false, 79 79 editor : {}, 80 80 dom : {}, 81 81 is_update : false, 82 82 el : {}, 83 args : '', 83 84 84 I : function(e) { 85 return document.getElementById(e); 86 }, 85 init: function(mcemode) { 86 var t = this, query, args = {}, i, val, w = t.getWin(); 87 87 88 init: function() { 89 var t = this, li, q, i, it, w = t.getWin(); 88 if ( mcemode ) 89 t.mcemode = true; 90 else 91 return; 90 92 91 if ( ! t.mcemode ) return;93 query = ('' + document.location.search).replace(/^\?/, '').split('&'); 92 94 93 li = ('' + document.location.search).replace(/^\?/, '').split('&');94 q = {};95 for (i=0; i<li.length; i++) {96 it = li[i].split('=');97 q[unescape(it[0])] = unescape(it[1]);95 for ( i in query ) { 96 if ( query[i] ) { 97 val = query[i].split('='); 98 args[decodeURIComponent(val[0])] = decodeURIComponent(val[1]); 99 } 98 100 } 99 101 100 if (q.mce_rdomain)101 document.domain = q.mce_rdomain;102 103 102 // Find window & API 104 103 tinymce = w.tinymce; 105 104 tinyMCE = w.tinyMCE; 106 105 t.editor = tinymce.EditorManager.activeEditor; 106 t.args = args; 107 108 // temp, UI is changing 109 if ( args.shortcode ) { 110 t.is_update = true; 111 $('#update-gallery').show(); 112 $('#shortcode').val( args.shortcode ); 113 } else { 114 $('#insert-gallery').show(); 115 } 107 116 108 t.setup();117 // t.setup(); 109 118 }, 110 119 111 120 getWin : function() { … … 113 122 }, 114 123 115 124 setup : function() { 116 var t = this, a, ed = t.editor, g, columns, link, order, orderby; 117 if ( ! t.mcemode ) return; 125 var t = this, shortcode = t.args.shortcode, sh, a, ed = t.editor, g, columns, link, order, orderby, val; 126 127 if ( ! t.mcemode ) 128 return; 118 129 119 t.el = ed.selection.getNode(); 130 if ( shortcode ) { 131 $('#update-gallery').show(); 132 t.is_update = true; 120 133 121 if ( t.el.nodeName != 'IMG' || ! ed.dom.hasClass(t.el, 'wpGallery') ) { 122 if ( (g = ed.dom.select('img.wpGallery')) && g[0] ) { 123 t.el = g[0]; 124 } else { 125 if ( getUserSetting('galfile') == '1' ) t.I('linkto-file').checked = "checked"; 126 if ( getUserSetting('galdesc') == '1' ) t.I('order-desc').checked = "checked"; 127 if ( getUserSetting('galcols') ) t.I('columns').value = getUserSetting('galcols'); 128 if ( getUserSetting('galord') ) t.I('orderby').value = getUserSetting('galord'); 129 jQuery('#insert-gallery').show(); 130 return; 131 } 134 columns = shortcode.match(/columns=['"]([0-9]+)['"]/); 135 link = shortcode.match(/link=['"]([^'"]+)['"]/i); 136 order = shortcode.match(/order=['"]([^'"]+)['"]/i); 137 orderby = shortcode.match(/orderby=['"]([^'"]+)['"]/i); 138 139 // console.log( columns );console.log( link );console.log( order );console.log( orderby ); 140 } else { 141 $('#insert-gallery').show(); 132 142 } 143 144 // If inserting new gallery, use the user states, if editing a gallery, use defaults + shortcode 145 if ( ( ! t.is_update && getUserSetting('galfile') ) || ( link && link[1] ) ) 146 $('#linkto-file').prop('checked', true); 133 147 134 a = ed.dom.getAttrib(t.el, 'title');135 a = ed.dom.decode(a);148 if ( ( ! t.is_update && getUserSetting('galdesc') ) || ( order && order[1] ) ) 149 $('#order-desc').prop('checked', true); 136 150 137 if ( a ) { 138 jQuery('#update-gallery').show(); 139 t.is_update = true; 151 if ( columns && columns[1] ) 152 $('#columns').val( columns[1] ); 153 else if ( ! t.is_update && ( val = getUserSetting('galcols') ) ) 154 $('#columns').val( val ); 140 155 141 columns = a.match(/columns=['"]([0-9]+)['"]/); 142 link = a.match(/link=['"]([^'"]+)['"]/i); 143 order = a.match(/order=['"]([^'"]+)['"]/i); 144 orderby = a.match(/orderby=['"]([^'"]+)['"]/i); 145 146 if ( link && link[1] ) t.I('linkto-file').checked = "checked"; 147 if ( order && order[1] ) t.I('order-desc').checked = "checked"; 148 if ( columns && columns[1] ) t.I('columns').value = ''+columns[1]; 149 if ( orderby && orderby[1] ) t.I('orderby').value = orderby[1]; 150 } else { 151 jQuery('#insert-gallery').show(); 152 } 156 if ( orderby && orderby[1] ) 157 $('#orderby').val( orderby[1] ); 158 else if ( ! t.is_update && ( val = getUserSetting('galord') ) ) 159 $('#orderby').val( val ); 153 160 }, 154 161 155 162 update : function() { 156 var t = this, ed = t.editor, a ll = '', s;163 var t = this, ed = t.editor, args = t.args, div, new_div, new_div_id, sh = $('#shortcode').val() || '[gallery]'; // '[gallery'+t.getSettings()+']'; 157 164 158 165 if ( ! t.mcemode || ! t.is_update ) { 159 s = '[gallery'+t.getSettings()+']'; 160 t.getWin().send_to_editor(s); 166 t.getWin().send_to_editor(sh); 161 167 return; 162 168 } 163 169 164 if (t.el.nodeName != 'IMG') return;170 div = ed.dom.select('#'+args.div_id); 165 171 166 all = ed.dom.decode(ed.dom.getAttrib(t.el, 'title')); 167 all = all.replace(/\s*(order|link|columns|orderby)=['"]([^'"]+)['"]/gi, ''); 168 all += t.getSettings(); 172 if ( div ) { 173 new_div = ed.dom.create( 'div', {}, ed.wpSetGalleryPreview(sh) ); 174 new_div = new_div.firstChild; 175 ed.dom.replace( new_div, div ); 176 } 169 177 170 ed.dom.setAttrib(t.el, 'title', all);171 178 t.getWin().tb_remove(); 172 179 }, 173 180 174 181 getSettings : function() { 175 var I = this.I, s = '';182 var s = '', columns = $('#columns').val(), orderby = $('#orderby').val(); 176 183 177 if ( I('linkto-file').checked) {184 if ( $('#linkto-file').prop('checked') ) { 178 185 s += ' link="file"'; 179 186 setUserSetting('galfile', '1'); 187 } else { 188 deleteUserSetting('galfile'); 180 189 } 181 190 182 if ( I('order-desc').checked) {191 if ( $('#order-desc').prop('checked') ) { 183 192 s += ' order="DESC"'; 184 193 setUserSetting('galdesc', '1'); 194 } else { 195 deleteUserSetting('galdesc'); 185 196 } 186 197 187 if ( I('columns').value != 3 ) { 188 s += ' columns="'+I('columns').value+'"'; 189 setUserSetting('galcols', I('columns').value); 198 if ( columns != 3 ) { 199 s += ' columns="'+columns+'"'; 200 setUserSetting('galcols', columns); 201 } else { 202 deleteUserSetting('galcols'); 190 203 } 191 204 192 if ( I('orderby').value != 'menu_order' ) { 193 s += ' orderby="'+I('orderby').value+'"'; 194 setUserSetting('galord', I('orderby').value); 205 if ( orderby != 'menu_order' ) { 206 s += ' orderby="'+orderby+'"'; 207 setUserSetting('galord', orderby); 208 } else { 209 deleteUserSetting('galord'); 195 210 } 196 211 197 212 return s; 198 213 } 199 214 }; 215 })(jQuery); 216 -
wp-includes/js/tinymce/plugins/wpgallery/editor_plugin_src.js
1 1 2 2 (function() { 3 3 tinymce.create('tinymce.plugins.wpGallery', { 4 sh : {i: 0}, 4 5 5 6 init : function(ed, url) { 6 var t = this ;7 var t = this, target; 7 8 9 t.ed = ed; 8 10 t.url = url; 9 11 t._createButtons(); 10 12 11 13 // Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('...'); 12 14 ed.addCommand('WP_Gallery', function() { 13 var el = ed.selection.getNode(), post_id, vp = tinymce.DOM.getViewPort(), 14 H = vp.h - 80, W = ( 640 < vp.w ) ? 640 : vp.w; 15 var shortcode, div_id, q_string, post_id, vp = tinymce.DOM.getViewPort(), H = vp.h - 80, W = ( 640 < vp.w ) ? 640 : vp.w; 15 16 16 if ( el.nodeName != 'IMG' ) return;17 if ( ed.dom.getAttrib(el, 'class').indexOf('wpGallery') == -1 )return;17 if ( !target ) 18 return; 18 19 19 post_id = tinymce.DOM.get('post_ID').value; 20 tb_show('', tinymce.documentBaseURL + 'media-upload.php?post_id='+post_id+'&tab=gallery&TB_iframe=true&width='+W+'&height='+H); 20 div_id = target.id; 21 shortcode = ed.dom.getAttrib( target, 'data-wp-gallery-args' ); // already urlencoded 22 if ( !shortcode || !div_id ) 23 return; 21 24 25 post_id = document.getElementById('post_ID'); 26 post_id = post_id ? post_id.value : 0; 27 q_string = 'post_id='+post_id+'&tab=gallery&shortcode='+shortcode+'&div_id='+encodeURIComponent(div_id)+'&TB_iframe=true&width='+W+'&height='+H; 28 29 tb_show('', tinymce.documentBaseURL + 'media-upload.php?'+q_string); 30 22 31 tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' ); 32 target = null; 23 33 }); 24 34 35 ed.addCommand('WP_Gallery_Delete', function() { 36 if ( !target ) 37 return; 38 39 ed.dom.remove(target); 40 }); 41 25 42 ed.onMouseDown.add(function(ed, e) { 26 if ( e.target.nodeName == 'IMG' && ed.dom.hasClass(e.target, 'wpGallery') ) 27 ed.plugins.wordpress._showButtons(e.target, 'wp_gallerybtns'); 43 target = ed.dom.getParent(e.target, 'div.wp-gallery-preview'); 44 45 if ( target ) 46 ed.plugins.wordpress._showButtons(target, 'wp_gallerybtns'); 28 47 }); 29 48 30 49 ed.onBeforeSetContent.add(function(ed, o) { 31 o.content = t._do_gallery(o .content);50 o.content = t._do_gallery(o); 32 51 }); 33 52 34 53 ed.onPostProcess.add(function(ed, o) { 35 if (o.get) 36 o.content = t._get_gallery(o.content); 54 if ( ( o.get || o.save ) && o.content.indexOf('data-wp-gallery-args') > -1 ) { 55 o.content = o.content.replace(/<div[^>]+data-wp-gallery-args="([^"]+)"[\s\S]+?<\/div><div class="wp-gallery-end">.?<\/div><\/div>/g, function(a, b){ 56 return '<p>'+decodeURIComponent(b)+'</p>'; 57 }); 58 } 37 59 }); 38 },39 60 40 _do_gallery : function(co) { 41 return co.replace(/\[gallery([^\]]*)\]/g, function(a,b){ 42 return '<img src="'+tinymce.baseURL+'/plugins/wpgallery/img/t.gif" class="wpGallery mceItem" title="gallery'+tinymce.DOM.encode(b)+'" />'; 61 // Chrome doesn't understand :focus in contentEditable, add/remove a css class with JS :( 62 ed.onMouseDown.add(function(ed, e) { 63 ed.dom.removeClass(ed.dom.select('div.wp-gallery-block'), 'focused'); 64 if ( ed.dom.hasClass(e.target, 'wp-gallery-block') ) 65 ed.dom.addClass(e.target, 'focused'); 43 66 }); 67 68 ed.wpSetGalleryPreview = function(content) { 69 return t._do_gallery(content); 70 } 44 71 }, 45 72 46 _get_gallery : function(co) { 73 _do_gallery : function(args) { 74 var self = this, ed = self.ed, dom = ed.dom, xhr_args, data, content, post_id, sh = self.sh, isNotDirty; 47 75 48 function getAttr(s, n) { 49 n = new RegExp(n + '=\"([^\"]+)\"', 'g').exec(s); 50 return n ? tinymce.DOM.decode(n[1]) : ''; 76 if ( typeof(args) == 'object' ) { 77 content = args.content; 78 if ( args.initial ) 79 isNotDirty = true; 80 } else { 81 content = args; 82 } 83 84 if ( content.indexOf('[gallery') == -1 ) 85 return content; 86 87 // post_ID is a hidden input field in edit-form-advanced.php 88 post_id = document.getElementById('post_ID'); 89 if ( post_id ) 90 post_id = post_id.value; 91 else 92 return content; 93 94 xhr_args = { 95 url: ajaxurl, 96 type: 'POST', 97 content_type: 'application/x-www-form-urlencoded', 98 success: function(r) { 99 var shortcode, div_id, new_id; 100 101 div_id = /^wp_gallery_shortcode_\d+/.exec(r); 102 shortcode = div_id && sh[div_id] ? sh[div_id] : ''; 103 104 if ( !div_id || !shortcode ) { 105 ed.setProgressState(false); 106 return; 107 } 108 109 div_id = div_id.toString(); 110 r = r.replace(div_id, ''); 111 // if there are any " even double entity encoded, switching Visual -> Text and back breaks it 112 shortcode = encodeURIComponent( shortcode ); 113 div = ed.dom.select('div#'+div_id); 114 115 if ( !div ) { 116 ed.setProgressState(false); 117 return; 118 } 119 120 ed.undoManager.data.pop() 121 new_id = 'wp_gallery_preview_' + div_id.replace(/[^0-9]+/, ''); 122 dom.setAttribs( div, { 123 id: new_id, 124 'data-wp-gallery-args': shortcode 125 }); 126 dom.addClass( div, 'wp-gallery-preview' ); // mceNonEditable 127 dom.setHTML( div, '<div class="wp-gallery-block"><br></div>'+r+'<div class="wp-gallery-end">\uFEFF</div>' ); 128 dom.setAttrib( dom.select('div.wp-gallery-block, div.wp-gallery-preview'), 'contenteditable', false ); 129 130 ed.setProgressState(false); 131 ed.execCommand('mceRepaint'); 132 ed.undoManager.add(); 133 134 if ( isNotDirty ) 135 ed.isNotDirty = true; 136 }, 137 error: function() { 138 ed.setProgressState(false); 139 } 51 140 }; 52 141 53 return co.replace(/(?:<p[^>]*>)*(<img[^>]+>)(?:<\/p>)*/g, function(a,im) { 54 var cls = getAttr(im, 'class'); 142 data = { 143 action: 'mce-gallery-preview', 144 post_ID: post_id 145 }; 55 146 56 if ( cls.indexOf('wpGallery') != -1 ) 57 return '<p>['+tinymce.trim(getAttr(im, 'title'))+']</p>'; 147 ed.setProgressState(true); 58 148 59 return a; 149 return content.replace(/(?:<p>\s*)?(\[gallery[^\]]*\])(?:\s*<\/p>)?/g, function(a, shortcode){ 150 var val, div_id, str = ''; 151 152 sh.i++; 153 div_id = 'wp_gallery_shortcode_' + sh.i; 154 data['mcediv_id'] = div_id; 155 sh[div_id] = shortcode; 156 data['shortcode'] = shortcode; 157 158 for ( val in data ) { 159 if ( str ) 160 str += '&'; 161 162 str += val + '=' + encodeURIComponent( data[val] ); 163 } 164 165 xhr_args['data'] = str; 166 tinymce.util.XHR.send( xhr_args ); 167 168 return '<div id="'+div_id+'">' + shortcode + '</div>'; 60 169 }); 61 170 }, 62 171 63 172 _createButtons : function() { 64 var t = this, ed = t inyMCE.activeEditor, DOM = tinymce.DOM, editButton, dellButton;173 var t = this, ed = t.ed, DOM = tinymce.DOM, editButton, dellButton; 65 174 66 175 DOM.remove('wp_gallerybtns'); 67 176 … … 79 188 }); 80 189 81 190 tinymce.dom.Event.add(editButton, 'mousedown', function(e) { 82 var ed = tinyMCE.activeEditor;83 191 ed.windowManager.bookmark = ed.selection.getBookmark('simple'); 84 192 ed.execCommand("WP_Gallery"); 193 ed.dom.events.cancel(e); 85 194 }); 86 195 87 196 dellButton = DOM.add('wp_gallerybtns', 'img', { … … 93 202 }); 94 203 95 204 tinymce.dom.Event.add(dellButton, 'mousedown', function(e) { 96 var ed = tinyMCE.activeEditor, el = ed.selection.getNode(); 97 98 if ( el.nodeName == 'IMG' && ed.dom.hasClass(el, 'wpGallery') ) { 99 ed.dom.remove(el); 100 101 ed.execCommand('mceRepaint'); 102 return false; 103 } 205 ed.execCommand('WP_Gallery_Delete'); 206 ed.execCommand('mceRepaint'); 207 ed.dom.events.cancel(e); 104 208 }); 105 209 }, 106 210 -
wp-includes/js/tinymce/themes/advanced/skins/wp_theme/content.css
141 141 height: 250px; 142 142 } 143 143 144 /* Gallery preview */ 145 146 div.wp-gallery-block { 147 height: 100%; 148 width: 100%; 149 position: absolute; 150 background: #fff; 151 opacity: 0.01; 152 filter: alpha(opacity=1); 153 top: 0; 154 left: 0; 155 bottom: 0; 156 right: 0; 157 z-index: 5; 158 } 159 160 div.wp-gallery-block.focused { 161 background-color: #000; 162 filter: alpha(opacity=25); 163 opacity: 0.25; 164 } 165 166 div.wp-gallery-preview { 167 margin: 10px auto; 168 position: relative; 169 -ms-user-select: none; 170 -moz-user-select: none; 171 -webkit-user-select: none; 172 user-select: none; 173 } 174 175 div.wp-gallery-preview .wp-gallery-end { 176 height: 1em; 177 margin-top: -1em; 178 } 179 180 div.wp-gallery-preview .gallery-icon { 181 margin: 0; 182 } 183 184 div.wp-gallery-preview .gallery-icon img { 185 display: block; 186 margin: 0 auto; 187 padding: 0; 188 max-width: 90%; 189 height: auto; 190 border: 0; 191 } 192 193 div.wp-gallery-preview dd.gallery-caption { 194 margin: 0 6%; 195 font-size: 12px; 196 } 197 198 div.wp-gallery-preview div.gallery { 199 clear: both; 200 } 201 202 div.wp-gallery-preview div.gallery dl.gallery-item { 203 float: left; 204 margin: 10px 0; 205 padding: 0; 206 } 207 208 div.wp-gallery-preview div.gallery-columns-1 dl.gallery-item { 209 width: 99%; 210 } 211 212 div.wp-gallery-preview div.gallery-columns-2 dl.gallery-item { 213 width: 49.5%; 214 } 215 216 div.wp-gallery-preview div.gallery-columns-3 dl.gallery-item { 217 width: 33%; 218 } 219 220 div.wp-gallery-preview div.gallery-columns-4 dl.gallery-item { 221 width: 24.75%; 222 } 223 224 div.wp-gallery-preview div.gallery-columns-5 dl.gallery-item { 225 width: 19.8%; 226 } 227 228 div.wp-gallery-preview div.gallery-columns-6 dl.gallery-item { 229 width: 16.5%; 230 } 231 232 div.wp-gallery-preview div.gallery-columns-7 dl.gallery-item { 233 width: 14.2%; 234 } 235 236 div.wp-gallery-preview div.gallery-columns-8 dl.gallery-item { 237 width: 12.45%; 238 } 239 240 div.wp-gallery-preview div.gallery-columns-9 dl.gallery-item { 241 width: 11.1%; 242 } 243 244 div.wp-gallery-preview div.gallery-columns-10 dl.gallery-item { 245 width: 9.99%; 246 } 247 248 249 -
wp-includes/media.php
780 780 static $instance = 0; 781 781 $instance++; 782 782 783 // Allow plugins/themes to override the default gallery template. 784 $output = apply_filters('post_gallery', '', $attr); 785 if ( $output != '' ) 786 return $output; 783 // Allow plugins/themes to override the default gallery template if not previewing. 784 if ( !isset($attr['mce_preview']) ) { 785 $output = apply_filters('post_gallery', '', $attr); 786 if ( $output != '' ) 787 return $output; 788 } 787 789 788 790 // We're trusting author input, so let's at least make sure it looks like a valid orderby statement 789 791 if ( isset( $attr['orderby'] ) ) { … … 792 794 unset( $attr['orderby'] ); 793 795 } 794 796 795 extract(shortcode_atts(array(797 $attr = shortcode_atts( array( 796 798 'order' => 'ASC', 797 799 'orderby' => 'menu_order ID', 798 'id' => $post->ID,800 'id' => isset($post) ? $post->ID : 0, 799 801 'itemtag' => 'dl', 800 802 'icontag' => 'dt', 801 803 'captiontag' => 'dd', 802 804 'columns' => 3, 803 805 'size' => 'thumbnail', 804 806 'include' => '', 805 'exclude' => '' 806 ), $attr)); 807 'exclude' => '', 808 'mce_preview' => false, 809 ), $attr ); 807 810 811 extract( $attr, EXTR_SKIP ); 808 812 $id = intval($id); 813 809 814 if ( 'RAND' == $order ) 810 815 $orderby = 'none'; 811 816 … … 817 822 foreach ( $_attachments as $key => $val ) { 818 823 $attachments[$val->ID] = $_attachments[$key]; 819 824 } 820 } elseif ( !empty($exclude) ) {825 } elseif ( !empty($exclude) && $id ) { 821 826 $exclude = preg_replace( '/[^0-9,]+/', '', $exclude ); 822 827 $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); 823 } else {828 } elseif ( $id ) { 824 829 $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); 825 830 } 826 831 … … 834 839 return $output; 835 840 } 836 841 837 $itemtag = tag_escape($itemtag); 838 $captiontag = tag_escape($captiontag); 842 if ( $mce_preview ) { 843 $itemtag = 'dl'; 844 $icontag = 'dt'; 845 $captiontag = 'dd'; 846 } else { 847 $itemtag = tag_escape($itemtag); 848 $captiontag = tag_escape($captiontag); 849 } 850 839 851 $columns = intval($columns); 840 852 $itemwidth = $columns > 0 ? floor(100/$columns) : 100; 841 853 $float = is_rtl() ? 'right' : 'left'; … … 864 876 </style> 865 877 <!-- see gallery_shortcode() in wp-includes/media.php -->"; 866 878 $size_class = sanitize_html_class( $size ); 867 $gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>"; 868 $output = apply_filters( 'gallery_style', $gallery_style . "\n\t\t" . $gallery_div ); 879 $wrapper_id = $mce_preview ? '' : " id='$selector'"; 880 $gallery_div = "<div{$wrapper_id} class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>"; 881 $itemclass = 'gallery-item'; 882 $clear_break = "<br style='clear: both' />"; 869 883 884 if ( $mce_preview ) { 885 $output = $gallery_div; 886 } else { 887 $output = apply_filters( 'gallery_style', $gallery_style . "\n\t\t" . $gallery_div ); 888 } 889 870 890 $i = 0; 871 891 foreach ( $attachments as $id => $attachment ) { 872 892 $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false); 873 893 874 $output .= "<{$itemtag} class='gallery-item'>"; 875 $output .= " 876 <{$icontag} class='gallery-icon'> 877 $link 878 </{$icontag}>"; 894 $output .= "\n<{$itemtag} class='$itemclass'><{$icontag} class='gallery-icon'>$link</{$icontag}>"; 895 879 896 if ( $captiontag && trim($attachment->post_excerpt) ) { 880 $output .= " 881 <{$captiontag} class='wp-caption-text gallery-caption'> 882 " . wptexturize($attachment->post_excerpt) . " 883 </{$captiontag}>"; 897 $output .= "<{$captiontag} class='wp-caption-text gallery-caption'>" 898 . wptexturize($attachment->post_excerpt) . 899 "</{$captiontag}>"; 884 900 } 901 885 902 $output .= "</{$itemtag}>"; 903 886 904 if ( $columns > 0 && ++$i % $columns == 0 ) 887 $output .= '<br style="clear: both" />';905 $output .= $clear_break; 888 906 } 889 907 890 $output .= " 891 <br style='clear: both;' /> 892 </div>\n"; 908 if ( substr( $output, -strlen($clear_break) ) != $clear_break ) 909 $output .= $clear_break; 893 910 911 $output .= "</div>\n"; 912 894 913 return $output; 895 914 } 896 915