From: Edward Z. Yang Date: Fri, 14 Dec 2012 23:14:54 +0000 (-0800) Subject: Wordpress 3.5 X-Git-Tag: wordpress-3.5 X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/commitdiff_plain/refs/tags/wordpress-3.5 Wordpress 3.5 Signed-off-by: Edward Z. Yang --- diff --git a/readme.html b/readme.html index d5998ba6..368674e2 100644 --- a/readme.html +++ b/readme.html @@ -8,7 +8,7 @@

WordPress -
Version 3.4.2 +
Version 3.5

Semantic Personal Publishing Platform

diff --git a/wp-activate.php b/wp-activate.php index d470772f..0d5f1dca 100644 --- a/wp-activate.php +++ b/wp-activate.php @@ -1,4 +1,12 @@ ").appendTo("head")})(jQuery),function(e,t){var n=function(e,t){return this instanceof n?this._init(e,t):new n(e,t)};n.fn=n.prototype={_color:0,_alpha:1,error:!1,_hsl:{h:0,s:0,l:0},_hsv:{h:0,s:0,v:0},_hSpace:"hsl",_init:function(e){var n="noop";switch(typeof e){case"object":return e.a!==t&&this.a(e.a),n=e.r!==t?"fromRgb":e.l!==t?"fromHsl":e.v!==t?"fromHsv":n,this[n](e);case"string":return this.fromCSS(e);case"number":return this.fromInt(parseInt(e,10))}return this},_error:function(){return this.error=!0,this},clone:function(){var e=new n(this.toInt()),t=["_alpha","_hSpace","_hsl","_hsv","error"];for(var r=t.length-1;r>=0;r--)e[t[r]]=this[t[r]];return e},setHSpace:function(e){return this._hSpace=e==="hsv"?e:"hsl",this},noop:function(){return this},fromCSS:function(e){var t,n,r=/^(rgb|hs(l|v))a?\(/;this.error=!1,e=e.replace(/^\s+/,"").replace(/\s+$/,"").replace(/;$/,"");if(e.match(r)&&e.match(/\)$/)){n=e.replace(/(\s|%)/g,"").replace(r,"").replace(/,?\);?$/,"").split(",");if(n.length<3)return this._error();if(n.length===4){this.a(parseFloat(n.pop()));if(this.error)return this}for(var i=n.length-1;i>=0;i--){n[i]=parseInt(n[i],10);if(isNaN(n[i]))return this._error()}return e.match(/^rgb/)?this.fromRgb({r:n[0],g:n[1],b:n[2]}):e.match(/^hsv/)?this.fromHsv({h:n[0],s:n[1],v:n[2]}):this.fromHsl({h:n[0],s:n[1],l:n[2]})}return this.fromHex(e)},fromRgb:function(e,n){return typeof e!="object"||e.r===t||e.g===t||e.b===t?this._error():(this.error=!1,this.fromInt(parseInt((e.r<<16)+(e.g<<8)+e.b,10),n))},fromHex:function(e){return e=e.replace(/^#/,"").replace(/^0x/,""),e.length===3&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),this.error=!/^[0-9A-F]{6}$/i.test(e),this.fromInt(parseInt(e,16))},fromHsl:function(e){var n,r,i,s,o,u,a,f;return typeof e!="object"||e.h===t||e.s===t||e.l===t?this._error():(this._hsl=e,this._hSpace="hsl",u=e.h/360,a=e.s/100,f=e.l/100,a===0?n=r=i=f:(s=f<.5?f*(1+a):f+a-f*a,o=2*f-s,n=this.hue2rgb(o,s,u+1/3),r=this.hue2rgb(o,s,u),i=this.hue2rgb(o,s,u-1/3)),this.fromRgb({r:n*255,g:r*255,b:i*255},!0))},fromHsv:function(e){var n,r,i,s,o,u,a,f,l,c,h;if(typeof e!="object"||e.h===t||e.s===t||e.v===t)return this._error();this._hsv=e,this._hSpace="hsv",n=e.h/360,r=e.s/100,i=e.v/100,a=Math.floor(n*6),f=n*6-a,l=i*(1-r),c=i*(1-f*r),h=i*(1-(1-f)*r);switch(a%6){case 0:s=i,o=h,u=l;break;case 1:s=c,o=i,u=l;break;case 2:s=l,o=i,u=h;break;case 3:s=l,o=c,u=i;break;case 4:s=h,o=l,u=i;break;case 5:s=i,o=l,u=c}return this.fromRgb({r:s*255,g:o*255,b:u*255},!0)},fromInt:function(e,n){return this._color=parseInt(e,10),isNaN(this._color)&&(this._color=0),this._color>16777215?this._color=16777215:this._color<0&&(this._color=0),n===t&&(this._hsv.h=this._hsv.s=this._hsl.h=this._hsl.s=0),this},hue2rgb:function(e,t,n){return n<0&&(n+=1),n>1&&(n-=1),n<1/6?e+(t-e)*6*n:n<.5?t:n<2/3?e+(t-e)*(2/3-n)*6:e},toString:function(){var e=parseInt(this._color,10).toString(16);if(this.error)return"";if(e.length<6)for(var t=6-e.length-1;t>=0;t--)e="0"+e;return"#"+e},toCSS:function(e,t){e=e||"hex",t=parseFloat(t||this._alpha);switch(e){case"rgb":case"rgba":var n=this.toRgb();return t<1?"rgba( "+n.r+", "+n.g+", "+n.b+", "+t+" )":"rgb( "+n.r+", "+n.g+", "+n.b+" )";case"hsl":case"hsla":var r=this.toHsl();return t<1?"hsla( "+r.h+", "+r.s+"%, "+r.l+"%, "+t+" )":"hsl( "+r.h+", "+r.s+"%, "+r.l+"% )";default:return this.toString()}},toRgb:function(){return{r:255&this._color>>16,g:255&this._color>>8,b:255&this._color}},toHsl:function(){var e=this.toRgb(),t=e.r/255,n=e.g/255,r=e.b/255,i=Math.max(t,n,r),s=Math.min(t,n,r),o,u,a=(i+s)/2;if(i===s)o=u=0;else{var f=i-s;u=a>.5?f/(2-i-s):f/(i+s);switch(i){case t:o=(n-r)/f+(nr?(t+.05)/(r+.05):(r+.05)/(t+.05)}throw"getDistanceLuminosityFrom requires a Color object"},getMaxContrastColor:function(){var e=this.toLuminosity(),t=e>=.5?"000000":"ffffff";return new n(t)},getGrayscaleContrastingColor:function(e){if(!e)return this.getMaxContrastColor();var t=e<5?5:e,n=this.getMaxContrastColor();e=n.getDistanceLuminosityFrom(this);if(e<=t)return n;var r=0===n.toInt()?1:-1;while(e>t)n=n.incrementLightness(r),e=n.getDistanceLuminosityFrom(this);return n},getReadableContrastingColor:function(e,r){if(!e instanceof n)return this;var i=r===t?5:r,s=e.getDistanceLuminosityFrom(this),o=e.getMaxContrastColor(),u=o.getDistanceLuminosityFrom(e);if(u<=i)return o;if(s>=i)return this;var a=0===o.toInt()?-1:1;while(sn.range[1]?n.range[1]:r),s[e]=r,this._spaceFunc("from",n.space,s))}},_spaceFunc:function(e,t,n){var r=t||this._hSpace,i=e+r.charAt(0).toUpperCase()+r.substr(1);return this[i](n)}};var r={h:{mod:360},s:{range:[0,100]},l:{space:"hsl",range:[0,100]},v:{space:"hsv",range:[0,100]},r:{space:"rgb",range:[0,255]},g:{space:"rgb",range:[0,255]},b:{space:"rgb",range:[0,255]}};for(var i in r)r.hasOwnProperty(i)&&(n.fn[i]=n.fn._partial(i));e.Color=n}(typeof exports=="object"&&exports||this); \ No newline at end of file diff --git a/wp-admin/js/link.dev.js b/wp-admin/js/link.dev.js deleted file mode 100644 index f8b4583d..00000000 --- a/wp-admin/js/link.dev.js +++ /dev/null @@ -1,67 +0,0 @@ -jQuery(document).ready( function($) { - - var newCat, noSyncChecks = false, syncChecks, catAddAfter; - - $('#link_name').focus(); - // postboxes - postboxes.add_postbox_toggles('link'); - - // category tabs - $('#category-tabs a').click(function(){ - var t = $(this).attr('href'); - $(this).parent().addClass('tabs').siblings('li').removeClass('tabs'); - $('.tabs-panel').hide(); - $(t).show(); - if ( '#categories-all' == t ) - deleteUserSetting('cats'); - else - setUserSetting('cats','pop'); - return false; - }); - if ( getUserSetting('cats') ) - $('#category-tabs a[href="#categories-pop"]').click(); - - // Ajax Cat - newCat = $('#newcat').one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ) } ); - $('#link-category-add-submit').click( function() { newCat.focus(); } ); - syncChecks = function() { - if ( noSyncChecks ) - return; - noSyncChecks = true; - var th = $(this), c = th.is(':checked'), id = th.val().toString(); - $('#in-link-category-' + id + ', #in-popular-category-' + id).prop( 'checked', c ); - noSyncChecks = false; - }; - - catAddAfter = function( r, s ) { - $(s.what + ' response_data', r).each( function() { - var t = $($(this).text()); - t.find( 'label' ).each( function() { - var th = $(this), val = th.find('input').val(), id = th.find('input')[0].id, name = $.trim( th.text() ), o; - $('#' + id).change( syncChecks ); - o = $( '' ).text( name ); - } ); - } ); - }; - - $('#categorychecklist').wpList( { - alt: '', - what: 'link-category', - response: 'category-ajax-response', - addAfter: catAddAfter - } ); - - $('a[href="#categories-all"]').click(function(){deleteUserSetting('cats');}); - $('a[href="#categories-pop"]').click(function(){setUserSetting('cats','pop');}); - if ( 'pop' == getUserSetting('cats') ) - $('a[href="#categories-pop"]').click(); - - $('#category-add-toggle').click( function() { - $(this).parents('div:first').toggleClass( 'wp-hidden-children' ); - $('#category-tabs a[href="#categories-all"]').click(); - $('#newcategory').focus(); - return false; - } ); - - $('.categorychecklist :checkbox').change( syncChecks ).filter( ':checked' ).change(); -}); diff --git a/wp-admin/js/link.js b/wp-admin/js/link.js index 3f5433a4..f8b4583d 100644 --- a/wp-admin/js/link.js +++ b/wp-admin/js/link.js @@ -1 +1,67 @@ -jQuery(document).ready(function(c){var b,a=false,d,e;c("#link_name").focus();postboxes.add_postbox_toggles("link");c("#category-tabs a").click(function(){var f=c(this).attr("href");c(this).parent().addClass("tabs").siblings("li").removeClass("tabs");c(".tabs-panel").hide();c(f).show();if("#categories-all"==f){deleteUserSetting("cats")}else{setUserSetting("cats","pop")}return false});if(getUserSetting("cats")){c('#category-tabs a[href="#categories-pop"]').click()}b=c("#newcat").one("focus",function(){c(this).val("").removeClass("form-input-tip")});c("#link-category-add-submit").click(function(){b.focus()});d=function(){if(a){return}a=true;var f=c(this),h=f.is(":checked"),g=f.val().toString();c("#in-link-category-"+g+", #in-popular-category-"+g).prop("checked",h);a=false};e=function(g,f){c(f.what+" response_data",g).each(function(){var h=c(c(this).text());h.find("label").each(function(){var j=c(this),l=j.find("input").val(),m=j.find("input")[0].id,i=c.trim(j.text()),k;c("#"+m).change(d);k=c('').text(i)})})};c("#categorychecklist").wpList({alt:"",what:"link-category",response:"category-ajax-response",addAfter:e});c('a[href="#categories-all"]').click(function(){deleteUserSetting("cats")});c('a[href="#categories-pop"]').click(function(){setUserSetting("cats","pop")});if("pop"==getUserSetting("cats")){c('a[href="#categories-pop"]').click()}c("#category-add-toggle").click(function(){c(this).parents("div:first").toggleClass("wp-hidden-children");c('#category-tabs a[href="#categories-all"]').click();c("#newcategory").focus();return false});c(".categorychecklist :checkbox").change(d).filter(":checked").change()}); \ No newline at end of file +jQuery(document).ready( function($) { + + var newCat, noSyncChecks = false, syncChecks, catAddAfter; + + $('#link_name').focus(); + // postboxes + postboxes.add_postbox_toggles('link'); + + // category tabs + $('#category-tabs a').click(function(){ + var t = $(this).attr('href'); + $(this).parent().addClass('tabs').siblings('li').removeClass('tabs'); + $('.tabs-panel').hide(); + $(t).show(); + if ( '#categories-all' == t ) + deleteUserSetting('cats'); + else + setUserSetting('cats','pop'); + return false; + }); + if ( getUserSetting('cats') ) + $('#category-tabs a[href="#categories-pop"]').click(); + + // Ajax Cat + newCat = $('#newcat').one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ) } ); + $('#link-category-add-submit').click( function() { newCat.focus(); } ); + syncChecks = function() { + if ( noSyncChecks ) + return; + noSyncChecks = true; + var th = $(this), c = th.is(':checked'), id = th.val().toString(); + $('#in-link-category-' + id + ', #in-popular-category-' + id).prop( 'checked', c ); + noSyncChecks = false; + }; + + catAddAfter = function( r, s ) { + $(s.what + ' response_data', r).each( function() { + var t = $($(this).text()); + t.find( 'label' ).each( function() { + var th = $(this), val = th.find('input').val(), id = th.find('input')[0].id, name = $.trim( th.text() ), o; + $('#' + id).change( syncChecks ); + o = $( '' ).text( name ); + } ); + } ); + }; + + $('#categorychecklist').wpList( { + alt: '', + what: 'link-category', + response: 'category-ajax-response', + addAfter: catAddAfter + } ); + + $('a[href="#categories-all"]').click(function(){deleteUserSetting('cats');}); + $('a[href="#categories-pop"]').click(function(){setUserSetting('cats','pop');}); + if ( 'pop' == getUserSetting('cats') ) + $('a[href="#categories-pop"]').click(); + + $('#category-add-toggle').click( function() { + $(this).parents('div:first').toggleClass( 'wp-hidden-children' ); + $('#category-tabs a[href="#categories-all"]').click(); + $('#newcategory').focus(); + return false; + } ); + + $('.categorychecklist :checkbox').change( syncChecks ).filter( ':checked' ).change(); +}); diff --git a/wp-admin/js/link.min.js b/wp-admin/js/link.min.js new file mode 100644 index 00000000..3f5433a4 --- /dev/null +++ b/wp-admin/js/link.min.js @@ -0,0 +1 @@ +jQuery(document).ready(function(c){var b,a=false,d,e;c("#link_name").focus();postboxes.add_postbox_toggles("link");c("#category-tabs a").click(function(){var f=c(this).attr("href");c(this).parent().addClass("tabs").siblings("li").removeClass("tabs");c(".tabs-panel").hide();c(f).show();if("#categories-all"==f){deleteUserSetting("cats")}else{setUserSetting("cats","pop")}return false});if(getUserSetting("cats")){c('#category-tabs a[href="#categories-pop"]').click()}b=c("#newcat").one("focus",function(){c(this).val("").removeClass("form-input-tip")});c("#link-category-add-submit").click(function(){b.focus()});d=function(){if(a){return}a=true;var f=c(this),h=f.is(":checked"),g=f.val().toString();c("#in-link-category-"+g+", #in-popular-category-"+g).prop("checked",h);a=false};e=function(g,f){c(f.what+" response_data",g).each(function(){var h=c(c(this).text());h.find("label").each(function(){var j=c(this),l=j.find("input").val(),m=j.find("input")[0].id,i=c.trim(j.text()),k;c("#"+m).change(d);k=c('').text(i)})})};c("#categorychecklist").wpList({alt:"",what:"link-category",response:"category-ajax-response",addAfter:e});c('a[href="#categories-all"]').click(function(){deleteUserSetting("cats")});c('a[href="#categories-pop"]').click(function(){setUserSetting("cats","pop")});if("pop"==getUserSetting("cats")){c('a[href="#categories-pop"]').click()}c("#category-add-toggle").click(function(){c(this).parents("div:first").toggleClass("wp-hidden-children");c('#category-tabs a[href="#categories-all"]').click();c("#newcategory").focus();return false});c(".categorychecklist :checkbox").change(d).filter(":checked").change()}); \ No newline at end of file diff --git a/wp-admin/js/media-gallery.dev.js b/wp-admin/js/media-gallery.dev.js deleted file mode 100644 index 38e4f7b4..00000000 --- a/wp-admin/js/media-gallery.dev.js +++ /dev/null @@ -1,25 +0,0 @@ -jQuery(function($){ - $( 'body' ).bind( 'click.wp-gallery', function(e){ - var target = $( e.target ), id, img_size; - - if ( target.hasClass( 'wp-set-header' ) ) { - ( window.dialogArguments || opener || parent || top ).location.href = target.data( 'location' ); - e.preventDefault(); - } else if ( target.hasClass( 'wp-set-background' ) ) { - id = target.data( 'attachment-id' ); - img_size = $( 'input[name="attachments[' + id + '][image-size]"]:checked').val(); - - jQuery.post(ajaxurl, { - action: 'set-background-image', - attachment_id: id, - size: img_size - }, function(){ - var win = window.dialogArguments || opener || parent || top; - win.tb_remove(); - win.location.reload(); - }); - - e.preventDefault(); - } - }); -}); diff --git a/wp-admin/js/media-gallery.js b/wp-admin/js/media-gallery.js index 81e51131..38e4f7b4 100644 --- a/wp-admin/js/media-gallery.js +++ b/wp-admin/js/media-gallery.js @@ -1 +1,25 @@ -jQuery(function(a){a("body").bind("click.wp-gallery",function(d){var c=a(d.target),f,b;if(c.hasClass("wp-set-header")){(window.dialogArguments||opener||parent||top).location.href=c.data("location");d.preventDefault()}else{if(c.hasClass("wp-set-background")){f=c.data("attachment-id");b=a('input[name="attachments['+f+'][image-size]"]:checked').val();jQuery.post(ajaxurl,{action:"set-background-image",attachment_id:f,size:b},function(){var e=window.dialogArguments||opener||parent||top;e.tb_remove();e.location.reload()});d.preventDefault()}}})}); \ No newline at end of file +jQuery(function($){ + $( 'body' ).bind( 'click.wp-gallery', function(e){ + var target = $( e.target ), id, img_size; + + if ( target.hasClass( 'wp-set-header' ) ) { + ( window.dialogArguments || opener || parent || top ).location.href = target.data( 'location' ); + e.preventDefault(); + } else if ( target.hasClass( 'wp-set-background' ) ) { + id = target.data( 'attachment-id' ); + img_size = $( 'input[name="attachments[' + id + '][image-size]"]:checked').val(); + + jQuery.post(ajaxurl, { + action: 'set-background-image', + attachment_id: id, + size: img_size + }, function(){ + var win = window.dialogArguments || opener || parent || top; + win.tb_remove(); + win.location.reload(); + }); + + e.preventDefault(); + } + }); +}); diff --git a/wp-admin/js/media-gallery.min.js b/wp-admin/js/media-gallery.min.js new file mode 100644 index 00000000..81e51131 --- /dev/null +++ b/wp-admin/js/media-gallery.min.js @@ -0,0 +1 @@ +jQuery(function(a){a("body").bind("click.wp-gallery",function(d){var c=a(d.target),f,b;if(c.hasClass("wp-set-header")){(window.dialogArguments||opener||parent||top).location.href=c.data("location");d.preventDefault()}else{if(c.hasClass("wp-set-background")){f=c.data("attachment-id");b=a('input[name="attachments['+f+'][image-size]"]:checked').val();jQuery.post(ajaxurl,{action:"set-background-image",attachment_id:f,size:b},function(){var e=window.dialogArguments||opener||parent||top;e.tb_remove();e.location.reload()});d.preventDefault()}}})}); \ No newline at end of file diff --git a/wp-admin/js/media-upload.dev.js b/wp-admin/js/media-upload.dev.js deleted file mode 100644 index 9b998ff2..00000000 --- a/wp-admin/js/media-upload.dev.js +++ /dev/null @@ -1,88 +0,0 @@ -// send html to the post editor - -var wpActiveEditor; - -function send_to_editor(h) { - var ed, mce = typeof(tinymce) != 'undefined', qt = typeof(QTags) != 'undefined'; - - if ( !wpActiveEditor ) { - if ( mce && tinymce.activeEditor ) { - ed = tinymce.activeEditor; - wpActiveEditor = ed.id; - } else if ( !qt ) { - return false; - } - } else if ( mce ) { - if ( tinymce.activeEditor && (tinymce.activeEditor.id == 'mce_fullscreen' || tinymce.activeEditor.id == 'wp_mce_fullscreen') ) - ed = tinymce.activeEditor; - else - ed = tinymce.get(wpActiveEditor); - } - - if ( ed && !ed.isHidden() ) { - // restore caret position on IE - if ( tinymce.isIE && ed.windowManager.insertimagebookmark ) - ed.selection.moveToBookmark(ed.windowManager.insertimagebookmark); - - if ( h.indexOf('[caption') === 0 ) { - if ( ed.wpSetImgCaption ) - h = ed.wpSetImgCaption(h); - } else if ( h.indexOf('[gallery') === 0 ) { - if ( ed.plugins.wpgallery ) - h = ed.plugins.wpgallery._do_gallery(h); - } else if ( h.indexOf('[embed') === 0 ) { - if ( ed.plugins.wordpress ) - h = ed.plugins.wordpress._setEmbed(h); - } - - ed.execCommand('mceInsertContent', false, h); - } else if ( qt ) { - QTags.insertContent(h); - } else { - document.getElementById(wpActiveEditor).value += h; - } - - try{tb_remove();}catch(e){}; -} - -// thickbox settings -var tb_position; -(function($) { - tb_position = function() { - var tbWindow = $('#TB_window'), width = $(window).width(), H = $(window).height(), W = ( 720 < width ) ? 720 : width, adminbar_height = 0; - - if ( $('body.admin-bar').length ) - adminbar_height = 28; - - if ( tbWindow.size() ) { - tbWindow.width( W - 50 ).height( H - 45 - adminbar_height ); - $('#TB_iframeContent').width( W - 50 ).height( H - 75 - adminbar_height ); - tbWindow.css({'margin-left': '-' + parseInt((( W - 50 ) / 2),10) + 'px'}); - if ( typeof document.body.style.maxWidth != 'undefined' ) - tbWindow.css({'top': 20 + adminbar_height + 'px','margin-top':'0'}); - }; - - return $('a.thickbox').each( function() { - var href = $(this).attr('href'); - if ( ! href ) return; - href = href.replace(/&width=[0-9]+/g, ''); - href = href.replace(/&height=[0-9]+/g, ''); - $(this).attr( 'href', href + '&width=' + ( W - 80 ) + '&height=' + ( H - 85 - adminbar_height ) ); - }); - }; - - $(window).resize(function(){ tb_position(); }); - - // store caret position in IE - $(document).ready(function($){ - $('a.thickbox').click(function(){ - var ed; - - if ( typeof(tinymce) != 'undefined' && tinymce.isIE && ( ed = tinymce.get(wpActiveEditor) ) && !ed.isHidden() ) { - ed.focus(); - ed.windowManager.insertimagebookmark = ed.selection.getBookmark(); - } - }); - }); - -})(jQuery); diff --git a/wp-admin/js/media-upload.js b/wp-admin/js/media-upload.js index 7d1b9bee..9fc2e819 100644 --- a/wp-admin/js/media-upload.js +++ b/wp-admin/js/media-upload.js @@ -1 +1,88 @@ -var wpActiveEditor;function send_to_editor(c){var b,a=typeof(tinymce)!="undefined",f=typeof(QTags)!="undefined";if(!wpActiveEditor){if(a&&tinymce.activeEditor){b=tinymce.activeEditor;wpActiveEditor=b.id}else{if(!f){return false}}}else{if(a){if(tinymce.activeEditor&&(tinymce.activeEditor.id=="mce_fullscreen"||tinymce.activeEditor.id=="wp_mce_fullscreen")){b=tinymce.activeEditor}else{b=tinymce.get(wpActiveEditor)}}}if(b&&!b.isHidden()){if(tinymce.isIE&&b.windowManager.insertimagebookmark){b.selection.moveToBookmark(b.windowManager.insertimagebookmark)}if(c.indexOf("[caption")===0){if(b.wpSetImgCaption){c=b.wpSetImgCaption(c)}}else{if(c.indexOf("[gallery")===0){if(b.plugins.wpgallery){c=b.plugins.wpgallery._do_gallery(c)}}else{if(c.indexOf("[embed")===0){if(b.plugins.wordpress){c=b.plugins.wordpress._setEmbed(c)}}}}b.execCommand("mceInsertContent",false,c)}else{if(f){QTags.insertContent(c)}else{document.getElementById(wpActiveEditor).value+=c}}try{tb_remove()}catch(d){}}var tb_position;(function(a){tb_position=function(){var f=a("#TB_window"),e=a(window).width(),d=a(window).height(),c=(720]*?>/g, '' ); - } - if ( er ) { - $('#find-posts-response').html(er); - } - } - }; - - $(document).ready(function() { - $('#find-posts-submit').click(function(e) { - if ( '' == $('#find-posts-response').html() ) - e.preventDefault(); - }); - $( '#find-posts .find-box-search :input' ).keypress( function( event ) { - if ( 13 == event.which ) { - findPosts.send(); - return false; - } - } ); - $( '#find-posts-search' ).click( findPosts.send ); - $( '#find-posts-close' ).click( findPosts.close ); - $('#doaction, #doaction2').click(function(e){ - $('select[name^="action"]').each(function(){ - if ( $(this).val() == 'attach' ) { - e.preventDefault(); - findPosts.open(); - } - }); - }); - }); -})(jQuery); diff --git a/wp-admin/js/media.js b/wp-admin/js/media.js index 2fe5c0f9..b4ed0fb6 100644 --- a/wp-admin/js/media.js +++ b/wp-admin/js/media.js @@ -1 +1,124 @@ -var findPosts;(function(a){findPosts={open:function(d,c){var b=document.documentElement.scrollTop||a(document).scrollTop();if(d&&c){a("#affected").attr("name",d).val(c)}a("#find-posts").show().draggable({handle:"#find-posts-head"}).css({top:b+50+"px",left:"50%",marginLeft:"-250px"});a("#find-posts-input").focus().keyup(function(f){if(f.which==27){findPosts.close()}});return false},close:function(){a("#find-posts-response").html("");a("#find-posts").draggable("destroy").hide()},send:function(){var b={ps:a("#find-posts-input").val(),action:"find_posts",_ajax_nonce:a("#_ajax_nonce").val(),post_type:a('input[name="find-posts-what"]:checked').val()};a.ajax({type:"POST",url:ajaxurl,data:b,success:function(c){findPosts.show(c)},error:function(c){findPosts.error(c)}})},show:function(b){if(typeof(b)=="string"){this.error({responseText:b});return}var c=wpAjax.parseAjaxResponse(b);if(c.errors){this.error({responseText:wpAjax.broken})}c=c.responses[0];a("#find-posts-response").html(c.data)},error:function(b){var c=b.statusText;if(b.responseText){c=b.responseText.replace(/<.[^<>]*?>/g,"")}if(c){a("#find-posts-response").html(c)}}};a(document).ready(function(){a("#find-posts-submit").click(function(b){if(""==a("#find-posts-response").html()){b.preventDefault()}});a("#find-posts .find-box-search :input").keypress(function(b){if(13==b.which){findPosts.send();return false}});a("#find-posts-search").click(findPosts.send);a("#find-posts-close").click(findPosts.close);a("#doaction, #doaction2").click(function(b){a('select[name^="action"]').each(function(){if(a(this).val()=="attach"){b.preventDefault();findPosts.open()}})})})})(jQuery); \ No newline at end of file + +var findPosts; +(function($){ + findPosts = { + open : function(af_name, af_val) { + var st = document.documentElement.scrollTop || $(document).scrollTop(), + overlay = $( '.ui-find-overlay' ); + + if ( overlay.length == 0 ) { + $( 'body' ).append( '
' ); + findPosts.overlay(); + } + + overlay.show(); + + if ( af_name && af_val ) { + $('#affected').attr('name', af_name).val(af_val); + } + $('#find-posts').show().draggable({ + handle: '#find-posts-head' + }).css({'top':st + 50 + 'px','left':'50%','marginLeft':'-328px'}); + + $('#find-posts-input').focus().keyup(function(e){ + if (e.which == 27) { findPosts.close(); } // close on Escape + }); + + // Pull some results up by default + findPosts.send(); + + return false; + }, + + close : function() { + $('#find-posts-response').html(''); + $('#find-posts').draggable('destroy').hide(); + $( '.ui-find-overlay' ).hide(); + }, + + overlay : function() { + $( '.ui-find-overlay' ).css( + { 'z-index': '999', 'width': $( document ).width() + 'px', 'height': $( document ).height() + 'px' } + ).on('click', function () { + findPosts.close(); + }); + }, + + send : function() { + var post = { + ps: $('#find-posts-input').val(), + action: 'find_posts', + _ajax_nonce: $('#_ajax_nonce').val() + }, + spinner = $( '.find-box-search .spinner' ); + + spinner.show(); + + $.ajax({ + type : 'POST', + url : ajaxurl, + data : post, + success : function(x) { findPosts.show(x); spinner.hide(); }, + error : function(r) { findPosts.error(r); spinner.hide(); } + }); + }, + + show : function(x) { + + if ( typeof(x) == 'string' ) { + this.error({'responseText': x}); + return; + } + + var r = wpAjax.parseAjaxResponse(x); + + if ( r.errors ) { + this.error({'responseText': wpAjax.broken}); + } + r = r.responses[0]; + $('#find-posts-response').html(r.data); + + // Enable whole row to be clicked + $( '.found-posts td' ).on( 'click', function () { + $( this ).parent().find( '.found-radio input' ).prop( 'checked', true ); + }); + }, + + error : function(r) { + var er = r.statusText; + + if ( r.responseText ) { + er = r.responseText.replace( /<.[^<>]*?>/g, '' ); + } + if ( er ) { + $('#find-posts-response').html(er); + } + } + }; + + $(document).ready(function() { + $('#find-posts-submit').click(function(e) { + if ( '' == $('#find-posts-response').html() ) + e.preventDefault(); + }); + $( '#find-posts .find-box-search :input' ).keypress( function( event ) { + if ( 13 == event.which ) { + findPosts.send(); + return false; + } + } ); + $( '#find-posts-search' ).click( findPosts.send ); + $( '#find-posts-close' ).click( findPosts.close ); + $('#doaction, #doaction2').click(function(e){ + $('select[name^="action"]').each(function(){ + if ( $(this).val() == 'attach' ) { + e.preventDefault(); + findPosts.open(); + } + }); + }); + }); + $(window).resize(function() { + findPosts.overlay(); + }); +})(jQuery); diff --git a/wp-admin/js/media.min.js b/wp-admin/js/media.min.js new file mode 100644 index 00000000..1ddaf1a3 --- /dev/null +++ b/wp-admin/js/media.min.js @@ -0,0 +1 @@ +var findPosts;(function(a){findPosts={open:function(e,d){var c=document.documentElement.scrollTop||a(document).scrollTop(),b=a(".ui-find-overlay");if(b.length==0){a("body").append('
');findPosts.overlay()}b.show();if(e&&d){a("#affected").attr("name",e).val(d)}a("#find-posts").show().draggable({handle:"#find-posts-head"}).css({top:c+50+"px",left:"50%",marginLeft:"-328px"});a("#find-posts-input").focus().keyup(function(f){if(f.which==27){findPosts.close()}});findPosts.send();return false},close:function(){a("#find-posts-response").html("");a("#find-posts").draggable("destroy").hide();a(".ui-find-overlay").hide()},overlay:function(){a(".ui-find-overlay").css({"z-index":"999",width:a(document).width()+"px",height:a(document).height()+"px"}).on("click",function(){findPosts.close()})},send:function(){var b={ps:a("#find-posts-input").val(),action:"find_posts",_ajax_nonce:a("#_ajax_nonce").val()},c=a(".find-box-search .spinner");c.show();a.ajax({type:"POST",url:ajaxurl,data:b,success:function(d){findPosts.show(d);c.hide()},error:function(d){findPosts.error(d);c.hide()}})},show:function(b){if(typeof(b)=="string"){this.error({responseText:b});return}var c=wpAjax.parseAjaxResponse(b);if(c.errors){this.error({responseText:wpAjax.broken})}c=c.responses[0];a("#find-posts-response").html(c.data);a(".found-posts td").on("click",function(){a(this).parent().find(".found-radio input").prop("checked",true)})},error:function(b){var c=b.statusText;if(b.responseText){c=b.responseText.replace(/<.[^<>]*?>/g,"")}if(c){a("#find-posts-response").html(c)}}};a(document).ready(function(){a("#find-posts-submit").click(function(b){if(""==a("#find-posts-response").html()){b.preventDefault()}});a("#find-posts .find-box-search :input").keypress(function(b){if(13==b.which){findPosts.send();return false}});a("#find-posts-search").click(findPosts.send);a("#find-posts-close").click(findPosts.close);a("#doaction, #doaction2").click(function(b){a('select[name^="action"]').each(function(){if(a(this).val()=="attach"){b.preventDefault();findPosts.open()}})})});a(window).resize(function(){findPosts.overlay()})})(jQuery); \ No newline at end of file diff --git a/wp-admin/js/nav-menu.dev.js b/wp-admin/js/nav-menu.dev.js deleted file mode 100644 index 13668398..00000000 --- a/wp-admin/js/nav-menu.dev.js +++ /dev/null @@ -1,965 +0,0 @@ -/** - * WordPress Administration Navigation Menu - * Interface JS functions - * - * @version 2.0.0 - * - * @package WordPress - * @subpackage Administration - */ - -var wpNavMenu; - -(function($) { - - var api = wpNavMenu = { - - options : { - menuItemDepthPerLevel : 30, // Do not use directly. Use depthToPx and pxToDepth instead. - globalMaxDepth : 11 - }, - - menuList : undefined, // Set in init. - targetList : undefined, // Set in init. - menusChanged : false, - isRTL: !! ( 'undefined' != typeof isRtl && isRtl ), - negateIfRTL: ( 'undefined' != typeof isRtl && isRtl ) ? -1 : 1, - - // Functions that run on init. - init : function() { - api.menuList = $('#menu-to-edit'); - api.targetList = api.menuList; - - this.jQueryExtensions(); - - this.attachMenuEditListeners(); - - this.setupInputWithDefaultTitle(); - this.attachQuickSearchListeners(); - this.attachThemeLocationsListeners(); - - this.attachTabsPanelListeners(); - - this.attachUnsavedChangesListener(); - - if( api.menuList.length ) // If no menu, we're in the + tab. - this.initSortables(); - - this.initToggles(); - - this.initTabManager(); - }, - - jQueryExtensions : function() { - // jQuery extensions - $.fn.extend({ - menuItemDepth : function() { - var margin = api.isRTL ? this.eq(0).css('margin-right') : this.eq(0).css('margin-left'); - return api.pxToDepth( margin && -1 != margin.indexOf('px') ? margin.slice(0, -2) : 0 ); - }, - updateDepthClass : function(current, prev) { - return this.each(function(){ - var t = $(this); - prev = prev || t.menuItemDepth(); - $(this).removeClass('menu-item-depth-'+ prev ) - .addClass('menu-item-depth-'+ current ); - }); - }, - shiftDepthClass : function(change) { - return this.each(function(){ - var t = $(this), - depth = t.menuItemDepth(); - $(this).removeClass('menu-item-depth-'+ depth ) - .addClass('menu-item-depth-'+ (depth + change) ); - }); - }, - childMenuItems : function() { - var result = $(); - this.each(function(){ - var t = $(this), depth = t.menuItemDepth(), next = t.next(); - while( next.length && next.menuItemDepth() > depth ) { - result = result.add( next ); - next = next.next(); - } - }); - return result; - }, - updateParentMenuItemDBId : function() { - return this.each(function(){ - var item = $(this), - input = item.find('.menu-item-data-parent-id'), - depth = item.menuItemDepth(), - parent = item.prev(); - - if( depth == 0 ) { // Item is on the top level, has no parent - input.val(0); - } else { // Find the parent item, and retrieve its object id. - while( ! parent[0] || ! parent[0].className || -1 == parent[0].className.indexOf('menu-item') || ( parent.menuItemDepth() != depth - 1 ) ) - parent = parent.prev(); - input.val( parent.find('.menu-item-data-db-id').val() ); - } - }); - }, - hideAdvancedMenuItemFields : function() { - return this.each(function(){ - var that = $(this); - $('.hide-column-tog').not(':checked').each(function(){ - that.find('.field-' + $(this).val() ).addClass('hidden-field'); - }); - }); - }, - /** - * Adds selected menu items to the menu. - * - * @param jQuery metabox The metabox jQuery object. - */ - addSelectedToMenu : function(processMethod) { - if ( 0 == $('#menu-to-edit').length ) { - return false; - } - - return this.each(function() { - var t = $(this), menuItems = {}, - checkboxes = t.find('.tabs-panel-active .categorychecklist li input:checked'), - re = new RegExp('menu-item\\[(\[^\\]\]*)'); - - processMethod = processMethod || api.addMenuItemToBottom; - - // If no items are checked, bail. - if ( !checkboxes.length ) - return false; - - // Show the ajax spinner - t.find('img.waiting').show(); - - // Retrieve menu item data - $(checkboxes).each(function(){ - var t = $(this), - listItemDBIDMatch = re.exec( t.attr('name') ), - listItemDBID = 'undefined' == typeof listItemDBIDMatch[1] ? 0 : parseInt(listItemDBIDMatch[1], 10); - if ( this.className && -1 != this.className.indexOf('add-to-top') ) - processMethod = api.addMenuItemToTop; - menuItems[listItemDBID] = t.closest('li').getItemData( 'add-menu-item', listItemDBID ); - }); - - // Add the items - api.addItemToMenu(menuItems, processMethod, function(){ - // Deselect the items and hide the ajax spinner - checkboxes.removeAttr('checked'); - t.find('img.waiting').hide(); - }); - }); - }, - getItemData : function( itemType, id ) { - itemType = itemType || 'menu-item'; - - var itemData = {}, i, - fields = [ - 'menu-item-db-id', - 'menu-item-object-id', - 'menu-item-object', - 'menu-item-parent-id', - 'menu-item-position', - 'menu-item-type', - 'menu-item-title', - 'menu-item-url', - 'menu-item-description', - 'menu-item-attr-title', - 'menu-item-target', - 'menu-item-classes', - 'menu-item-xfn' - ]; - - if( !id && itemType == 'menu-item' ) { - id = this.find('.menu-item-data-db-id').val(); - } - - if( !id ) return itemData; - - this.find('input').each(function() { - var field; - i = fields.length; - while ( i-- ) { - if( itemType == 'menu-item' ) - field = fields[i] + '[' + id + ']'; - else if( itemType == 'add-menu-item' ) - field = 'menu-item[' + id + '][' + fields[i] + ']'; - - if ( - this.name && - field == this.name - ) { - itemData[fields[i]] = this.value; - } - } - }); - - return itemData; - }, - setItemData : function( itemData, itemType, id ) { // Can take a type, such as 'menu-item', or an id. - itemType = itemType || 'menu-item'; - - if( !id && itemType == 'menu-item' ) { - id = $('.menu-item-data-db-id', this).val(); - } - - if( !id ) return this; - - this.find('input').each(function() { - var t = $(this), field; - $.each( itemData, function( attr, val ) { - if( itemType == 'menu-item' ) - field = attr + '[' + id + ']'; - else if( itemType == 'add-menu-item' ) - field = 'menu-item[' + id + '][' + attr + ']'; - - if ( field == t.attr('name') ) { - t.val( val ); - } - }); - }); - return this; - } - }); - }, - - initToggles : function() { - // init postboxes - postboxes.add_postbox_toggles('nav-menus'); - - // adjust columns functions for menus UI - columns.useCheckboxesForHidden(); - columns.checked = function(field) { - $('.field-' + field).removeClass('hidden-field'); - } - columns.unchecked = function(field) { - $('.field-' + field).addClass('hidden-field'); - } - // hide fields - api.menuList.hideAdvancedMenuItemFields(); - }, - - initSortables : function() { - var currentDepth = 0, originalDepth, minDepth, maxDepth, - prev, next, prevBottom, nextThreshold, helperHeight, transport, - menuEdge = api.menuList.offset().left, - body = $('body'), maxChildDepth, - menuMaxDepth = initialMenuMaxDepth(); - - // Use the right edge if RTL. - menuEdge += api.isRTL ? api.menuList.width() : 0; - - api.menuList.sortable({ - handle: '.menu-item-handle', - placeholder: 'sortable-placeholder', - start: function(e, ui) { - var height, width, parent, children, tempHolder; - - // handle placement for rtl orientation - if ( api.isRTL ) - ui.item[0].style.right = 'auto'; - - transport = ui.item.children('.menu-item-transport'); - - // Set depths. currentDepth must be set before children are located. - originalDepth = ui.item.menuItemDepth(); - updateCurrentDepth(ui, originalDepth); - - // Attach child elements to parent - // Skip the placeholder - parent = ( ui.item.next()[0] == ui.placeholder[0] ) ? ui.item.next() : ui.item; - children = parent.childMenuItems(); - transport.append( children ); - - // Update the height of the placeholder to match the moving item. - height = transport.outerHeight(); - // If there are children, account for distance between top of children and parent - height += ( height > 0 ) ? (ui.placeholder.css('margin-top').slice(0, -2) * 1) : 0; - height += ui.helper.outerHeight(); - helperHeight = height; - height -= 2; // Subtract 2 for borders - ui.placeholder.height(height); - - // Update the width of the placeholder to match the moving item. - maxChildDepth = originalDepth; - children.each(function(){ - var depth = $(this).menuItemDepth(); - maxChildDepth = (depth > maxChildDepth) ? depth : maxChildDepth; - }); - width = ui.helper.find('.menu-item-handle').outerWidth(); // Get original width - width += api.depthToPx(maxChildDepth - originalDepth); // Account for children - width -= 2; // Subtract 2 for borders - ui.placeholder.width(width); - - // Update the list of menu items. - tempHolder = ui.placeholder.next(); - tempHolder.css( 'margin-top', helperHeight + 'px' ); // Set the margin to absorb the placeholder - ui.placeholder.detach(); // detach or jQuery UI will think the placeholder is a menu item - $(this).sortable( "refresh" ); // The children aren't sortable. We should let jQ UI know. - ui.item.after( ui.placeholder ); // reattach the placeholder. - tempHolder.css('margin-top', 0); // reset the margin - - // Now that the element is complete, we can update... - updateSharedVars(ui); - }, - stop: function(e, ui) { - var children, depthChange = currentDepth - originalDepth; - - // Return child elements to the list - children = transport.children().insertAfter(ui.item); - - // Update depth classes - if( depthChange != 0 ) { - ui.item.updateDepthClass( currentDepth ); - children.shiftDepthClass( depthChange ); - updateMenuMaxDepth( depthChange ); - } - // Register a change - api.registerChange(); - // Update the item data. - ui.item.updateParentMenuItemDBId(); - - // address sortable's incorrectly-calculated top in opera - ui.item[0].style.top = 0; - - // handle drop placement for rtl orientation - if ( api.isRTL ) { - ui.item[0].style.left = 'auto'; - ui.item[0].style.right = 0; - } - - // The width of the tab bar might have changed. Just in case. - api.refreshMenuTabs( true ); - }, - change: function(e, ui) { - // Make sure the placeholder is inside the menu. - // Otherwise fix it, or we're in trouble. - if( ! ui.placeholder.parent().hasClass('menu') ) - (prev.length) ? prev.after( ui.placeholder ) : api.menuList.prepend( ui.placeholder ); - - updateSharedVars(ui); - }, - sort: function(e, ui) { - var offset = ui.helper.offset(), - edge = api.isRTL ? offset.left + ui.helper.width() : offset.left, - depth = api.negateIfRTL * api.pxToDepth( edge - menuEdge ); - // Check and correct if depth is not within range. - // Also, if the dragged element is dragged upwards over - // an item, shift the placeholder to a child position. - if ( depth > maxDepth || offset.top < prevBottom ) depth = maxDepth; - else if ( depth < minDepth ) depth = minDepth; - - if( depth != currentDepth ) - updateCurrentDepth(ui, depth); - - // If we overlap the next element, manually shift downwards - if( nextThreshold && offset.top + helperHeight > nextThreshold ) { - next.after( ui.placeholder ); - updateSharedVars( ui ); - $(this).sortable( "refreshPositions" ); - } - } - }); - - function updateSharedVars(ui) { - var depth; - - prev = ui.placeholder.prev(); - next = ui.placeholder.next(); - - // Make sure we don't select the moving item. - if( prev[0] == ui.item[0] ) prev = prev.prev(); - if( next[0] == ui.item[0] ) next = next.next(); - - prevBottom = (prev.length) ? prev.offset().top + prev.height() : 0; - nextThreshold = (next.length) ? next.offset().top + next.height() / 3 : 0; - minDepth = (next.length) ? next.menuItemDepth() : 0; - - if( prev.length ) - maxDepth = ( (depth = prev.menuItemDepth() + 1) > api.options.globalMaxDepth ) ? api.options.globalMaxDepth : depth; - else - maxDepth = 0; - } - - function updateCurrentDepth(ui, depth) { - ui.placeholder.updateDepthClass( depth, currentDepth ); - currentDepth = depth; - } - - function initialMenuMaxDepth() { - if( ! body[0].className ) return 0; - var match = body[0].className.match(/menu-max-depth-(\d+)/); - return match && match[1] ? parseInt(match[1]) : 0; - } - - function updateMenuMaxDepth( depthChange ) { - var depth, newDepth = menuMaxDepth; - if ( depthChange === 0 ) { - return; - } else if ( depthChange > 0 ) { - depth = maxChildDepth + depthChange; - if( depth > menuMaxDepth ) - newDepth = depth; - } else if ( depthChange < 0 && maxChildDepth == menuMaxDepth ) { - while( ! $('.menu-item-depth-' + newDepth, api.menuList).length && newDepth > 0 ) - newDepth--; - } - // Update the depth class. - body.removeClass( 'menu-max-depth-' + menuMaxDepth ).addClass( 'menu-max-depth-' + newDepth ); - menuMaxDepth = newDepth; - } - }, - - attachMenuEditListeners : function() { - var that = this; - $('#update-nav-menu').bind('click', function(e) { - if ( e.target && e.target.className ) { - if ( -1 != e.target.className.indexOf('item-edit') ) { - return that.eventOnClickEditLink(e.target); - } else if ( -1 != e.target.className.indexOf('menu-save') ) { - return that.eventOnClickMenuSave(e.target); - } else if ( -1 != e.target.className.indexOf('menu-delete') ) { - return that.eventOnClickMenuDelete(e.target); - } else if ( -1 != e.target.className.indexOf('item-delete') ) { - return that.eventOnClickMenuItemDelete(e.target); - } else if ( -1 != e.target.className.indexOf('item-cancel') ) { - return that.eventOnClickCancelLink(e.target); - } - } - }); - $('#add-custom-links input[type="text"]').keypress(function(e){ - if ( e.keyCode === 13 ) { - e.preventDefault(); - $("#submit-customlinkdiv").click(); - } - }); - }, - - /** - * An interface for managing default values for input elements - * that is both JS and accessibility-friendly. - * - * Input elements that add the class 'input-with-default-title' - * will have their values set to the provided HTML title when empty. - */ - setupInputWithDefaultTitle : function() { - var name = 'input-with-default-title'; - - $('.' + name).each( function(){ - var $t = $(this), title = $t.attr('title'), val = $t.val(); - $t.data( name, title ); - - if( '' == val ) $t.val( title ); - else if ( title == val ) return; - else $t.removeClass( name ); - }).focus( function(){ - var $t = $(this); - if( $t.val() == $t.data(name) ) - $t.val('').removeClass( name ); - }).blur( function(){ - var $t = $(this); - if( '' == $t.val() ) - $t.addClass( name ).val( $t.data(name) ); - }); - }, - - attachThemeLocationsListeners : function() { - var loc = $('#nav-menu-theme-locations'), params = {}; - params['action'] = 'menu-locations-save'; - params['menu-settings-column-nonce'] = $('#menu-settings-column-nonce').val(); - loc.find('input[type="submit"]').click(function() { - loc.find('select').each(function() { - params[this.name] = $(this).val(); - }); - loc.find('.waiting').show(); - $.post( ajaxurl, params, function(r) { - loc.find('.waiting').hide(); - }); - return false; - }); - }, - - attachQuickSearchListeners : function() { - var searchTimer; - - $('.quick-search').keypress(function(e){ - var t = $(this); - - if( 13 == e.which ) { - api.updateQuickSearchResults( t ); - return false; - } - - if( searchTimer ) clearTimeout(searchTimer); - - searchTimer = setTimeout(function(){ - api.updateQuickSearchResults( t ); - }, 400); - }).attr('autocomplete','off'); - }, - - updateQuickSearchResults : function(input) { - var panel, params, - minSearchLength = 2, - q = input.val(); - - if( q.length < minSearchLength ) return; - - panel = input.parents('.tabs-panel'); - params = { - 'action': 'menu-quick-search', - 'response-format': 'markup', - 'menu': $('#menu').val(), - 'menu-settings-column-nonce': $('#menu-settings-column-nonce').val(), - 'q': q, - 'type': input.attr('name') - }; - - $('img.waiting', panel).show(); - - $.post( ajaxurl, params, function(menuMarkup) { - api.processQuickSearchQueryResponse(menuMarkup, params, panel); - }); - }, - - addCustomLink : function( processMethod ) { - var url = $('#custom-menu-item-url').val(), - label = $('#custom-menu-item-name').val(); - - processMethod = processMethod || api.addMenuItemToBottom; - - if ( '' == url || 'http://' == url ) - return false; - - // Show the ajax spinner - $('.customlinkdiv img.waiting').show(); - this.addLinkToMenu( url, label, processMethod, function() { - // Remove the ajax spinner - $('.customlinkdiv img.waiting').hide(); - // Set custom link form back to defaults - $('#custom-menu-item-name').val('').blur(); - $('#custom-menu-item-url').val('http://'); - }); - }, - - addLinkToMenu : function(url, label, processMethod, callback) { - processMethod = processMethod || api.addMenuItemToBottom; - callback = callback || function(){}; - - api.addItemToMenu({ - '-1': { - 'menu-item-type': 'custom', - 'menu-item-url': url, - 'menu-item-title': label - } - }, processMethod, callback); - }, - - addItemToMenu : function(menuItem, processMethod, callback) { - var menu = $('#menu').val(), - nonce = $('#menu-settings-column-nonce').val(); - - processMethod = processMethod || function(){}; - callback = callback || function(){}; - - params = { - 'action': 'add-menu-item', - 'menu': menu, - 'menu-settings-column-nonce': nonce, - 'menu-item': menuItem - }; - - $.post( ajaxurl, params, function(menuMarkup) { - var ins = $('#menu-instructions'); - processMethod(menuMarkup, params); - if( ! ins.hasClass('menu-instructions-inactive') && ins.siblings().length ) - ins.addClass('menu-instructions-inactive'); - callback(); - }); - }, - - /** - * Process the add menu item request response into menu list item. - * - * @param string menuMarkup The text server response of menu item markup. - * @param object req The request arguments. - */ - addMenuItemToBottom : function( menuMarkup, req ) { - $(menuMarkup).hideAdvancedMenuItemFields().appendTo( api.targetList ); - }, - - addMenuItemToTop : function( menuMarkup, req ) { - $(menuMarkup).hideAdvancedMenuItemFields().prependTo( api.targetList ); - }, - - attachUnsavedChangesListener : function() { - $('#menu-management input, #menu-management select, #menu-management, #menu-management textarea').change(function(){ - api.registerChange(); - }); - - if ( 0 != $('#menu-to-edit').length ) { - window.onbeforeunload = function(){ - if ( api.menusChanged ) - return navMenuL10n.saveAlert; - }; - } else { - // Make the post boxes read-only, as they can't be used yet - $('#menu-settings-column').find('input,select').prop('disabled', true).end().find('a').attr('href', '#').unbind('click'); - } - }, - - registerChange : function() { - api.menusChanged = true; - }, - - attachTabsPanelListeners : function() { - $('#menu-settings-column').bind('click', function(e) { - var selectAreaMatch, panelId, wrapper, items, - target = $(e.target); - - if ( target.hasClass('nav-tab-link') ) { - panelId = /#(.*)$/.exec(e.target.href); - if ( panelId && panelId[1] ) - panelId = panelId[1] - else - return false; - - wrapper = target.parents('.inside').first(); - - // upon changing tabs, we want to uncheck all checkboxes - $('input', wrapper).removeAttr('checked'); - - $('.tabs-panel-active', wrapper).removeClass('tabs-panel-active').addClass('tabs-panel-inactive'); - $('#' + panelId, wrapper).removeClass('tabs-panel-inactive').addClass('tabs-panel-active'); - - $('.tabs', wrapper).removeClass('tabs'); - target.parent().addClass('tabs'); - - // select the search bar - $('.quick-search', wrapper).focus(); - - return false; - } else if ( target.hasClass('select-all') ) { - selectAreaMatch = /#(.*)$/.exec(e.target.href); - if ( selectAreaMatch && selectAreaMatch[1] ) { - items = $('#' + selectAreaMatch[1] + ' .tabs-panel-active .menu-item-title input'); - if( items.length === items.filter(':checked').length ) - items.removeAttr('checked'); - else - items.prop('checked', true); - return false; - } - } else if ( target.hasClass('submit-add-to-menu') ) { - api.registerChange(); - - if ( e.target.id && 'submit-customlinkdiv' == e.target.id ) - api.addCustomLink( api.addMenuItemToBottom ); - else if ( e.target.id && -1 != e.target.id.indexOf('submit-') ) - $('#' + e.target.id.replace(/submit-/, '')).addSelectedToMenu( api.addMenuItemToBottom ); - return false; - } else if ( target.hasClass('page-numbers') ) { - $.post( ajaxurl, e.target.href.replace(/.*\?/, '').replace(/action=([^&]*)/, '') + '&action=menu-get-metabox', - function( resp ) { - if ( -1 == resp.indexOf('replace-id') ) - return; - - var metaBoxData = $.parseJSON(resp), - toReplace = document.getElementById(metaBoxData['replace-id']), - placeholder = document.createElement('div'), - wrap = document.createElement('div'); - - if ( ! metaBoxData['markup'] || ! toReplace ) - return; - - wrap.innerHTML = metaBoxData['markup'] ? metaBoxData['markup'] : ''; - - toReplace.parentNode.insertBefore( placeholder, toReplace ); - placeholder.parentNode.removeChild( toReplace ); - - placeholder.parentNode.insertBefore( wrap, placeholder ); - - placeholder.parentNode.removeChild( placeholder ); - - } - ); - - return false; - } - }); - }, - - initTabManager : function() { - var fixed = $('.nav-tabs-wrapper'), - fluid = fixed.children('.nav-tabs'), - active = fluid.children('.nav-tab-active'), - tabs = fluid.children('.nav-tab'), - tabsWidth = 0, - fixedRight, fixedLeft, - arrowLeft, arrowRight, resizeTimer, css = {}, - marginFluid = api.isRTL ? 'margin-right' : 'margin-left', - marginFixed = api.isRTL ? 'margin-left' : 'margin-right', - msPerPx = 2; - - /** - * Refreshes the menu tabs. - * Will show and hide arrows where necessary. - * Scrolls to the active tab by default. - * - * @param savePosition {boolean} Optional. Prevents scrolling so - * that the current position is maintained. Default false. - **/ - api.refreshMenuTabs = function( savePosition ) { - var fixedWidth = fixed.width(), - margin = 0, css = {}; - fixedLeft = fixed.offset().left; - fixedRight = fixedLeft + fixedWidth; - - if( !savePosition ) - active.makeTabVisible(); - - // Prevent space from building up next to the last tab if there's more to show - if( tabs.last().isTabVisible() ) { - margin = fixed.width() - tabsWidth; - margin = margin > 0 ? 0 : margin; - css[marginFluid] = margin + 'px'; - fluid.animate( css, 100, "linear" ); - } - - // Show the arrows only when necessary - if( fixedWidth > tabsWidth ) - arrowLeft.add( arrowRight ).hide(); - else - arrowLeft.add( arrowRight ).show(); - } - - $.fn.extend({ - makeTabVisible : function() { - var t = this.eq(0), left, right, css = {}, shift = 0; - - if( ! t.length ) return this; - - left = t.offset().left; - right = left + t.outerWidth(); - - if( right > fixedRight ) - shift = fixedRight - right; - else if ( left < fixedLeft ) - shift = fixedLeft - left; - - if( ! shift ) return this; - - css[marginFluid] = "+=" + api.negateIfRTL * shift + 'px'; - fluid.animate( css, Math.abs( shift ) * msPerPx, "linear" ); - return this; - }, - isTabVisible : function() { - var t = this.eq(0), - left = t.offset().left, - right = left + t.outerWidth(); - return ( right <= fixedRight && left >= fixedLeft ) ? true : false; - } - }); - - // Find the width of all tabs - tabs.each(function(){ - tabsWidth += $(this).outerWidth(true); - }); - - // Set up fixed margin for overflow, unset padding - css['padding'] = 0; - css[marginFixed] = (-1 * tabsWidth) + 'px'; - fluid.css( css ); - - // Build tab navigation - arrowLeft = $(''); - arrowRight = $(''); - // Attach to the document - fixed.wrap('")},_destroy:function(){this.selectees.removeClass("ui-selectee").removeData("selectable-item"),this.element.removeClass("ui-selectable ui-selectable-disabled"),this._mouseDestroy()},_mouseStart:function(t){var n=this;this.opos=[t.pageX,t.pageY];if(this.options.disabled)return;var r=this.options;this.selectees=e(r.filter,this.element[0]),this._trigger("start",t),e(r.appendTo).append(this.helper),this.helper.css({left:t.clientX,top:t.clientY,width:0,height:0}),r.autoRefresh&&this.refresh(),this.selectees.filter(".ui-selected").each(function(){var r=e.data(this,"selectable-item");r.startselected=!0,!t.metaKey&&!t.ctrlKey&&(r.$element.removeClass("ui-selected"),r.selected=!1,r.$element.addClass("ui-unselecting"),r.unselecting=!0,n._trigger("unselecting",t,{unselecting:r.element}))}),e(t.target).parents().andSelf().each(function(){var r=e.data(this,"selectable-item");if(r){var i=!t.metaKey&&!t.ctrlKey||!r.$element.hasClass("ui-selected");return r.$element.removeClass(i?"ui-unselecting":"ui-selected").addClass(i?"ui-selecting":"ui-unselecting"),r.unselecting=!i,r.selecting=i,r.selected=i,i?n._trigger("selecting",t,{selecting:r.element}):n._trigger("unselecting",t,{unselecting:r.element}),!1}})},_mouseDrag:function(t){var n=this;this.dragged=!0;if(this.options.disabled)return;var r=this.options,i=this.opos[0],s=this.opos[1],o=t.pageX,u=t.pageY;if(i>o){var a=o;o=i,i=a}if(s>u){var a=u;u=s,s=a}return this.helper.css({left:i,top:s,width:o-i,height:u-s}),this.selectees.each(function(){var a=e.data(this,"selectable-item");if(!a||a.element==n.element[0])return;var f=!1;r.tolerance=="touch"?f=!(a.left>o||a.rightu||a.bottomi&&a.rights&&a.bottom").appendTo(this.element).addClass("ui-slider-range ui-widget-header"+(d.range==="min"||d.range==="max"?" ui-slider-range-"+d.range:"")));for(var i=e.length;ic&&(f=c,g=a(this),i=b)}),c.range===!0&&this.values(1)===c.min&&(i+=1,g=a(this.handles[i])),j=this._start(b,i),j===!1?!1:(this._mouseSliding=!0,h._handleIndex=i,g.addClass("ui-state-active").focus(),k=g.offset(),l=!a(b.target).parents().andSelf().is(".ui-slider-handle"),this._clickOffset=l?{left:0,top:0}:{left:b.pageX-k.left-g.width()/2,top:b.pageY-k.top-g.height()/2-(parseInt(g.css("borderTopWidth"),10)||0)-(parseInt(g.css("borderBottomWidth"),10)||0)+(parseInt(g.css("marginTop"),10)||0)},this.handles.hasClass("ui-state-hover")||this._slide(b,i,e),this._animateOff=!0,!0))},_mouseStart:function(a){return!0},_mouseDrag:function(a){var b={x:a.pageX,y:a.pageY},c=this._normValueFromMouse(b);return this._slide(a,this._handleIndex,c),!1},_mouseStop:function(a){return this.handles.removeClass("ui-state-active"),this._mouseSliding=!1,this._stop(a,this._handleIndex),this._change(a,this._handleIndex),this._handleIndex=null,this._clickOffset=null,this._animateOff=!1,!1},_detectOrientation:function(){this.orientation=this.options.orientation==="vertical"?"vertical":"horizontal"},_normValueFromMouse:function(a){var b,c,d,e,f;return this.orientation==="horizontal"?(b=this.elementSize.width,c=a.x-this.elementOffset.left-(this._clickOffset?this._clickOffset.left:0)):(b=this.elementSize.height,c=a.y-this.elementOffset.top-(this._clickOffset?this._clickOffset.top:0)),d=c/b,d>1&&(d=1),d<0&&(d=0),this.orientation==="vertical"&&(d=1-d),e=this._valueMax()-this._valueMin(),f=this._valueMin()+d*e,this._trimAlignValue(f)},_start:function(a,b){var c={handle:this.handles[b],value:this.value()};return this.options.values&&this.options.values.length&&(c.value=this.values(b),c.values=this.values()),this._trigger("start",a,c)},_slide:function(a,b,c){var d,e,f;this.options.values&&this.options.values.length?(d=this.values(b?0:1),this.options.values.length===2&&this.options.range===!0&&(b===0&&c>d||b===1&&c1){this.options.values[b]=this._trimAlignValue(c),this._refreshValue(),this._change(null,b);return}if(!arguments.length)return this._values();if(!a.isArray(arguments[0]))return this.options.values&&this.options.values.length?this._values(b):this.value();d=this.options.values,e=arguments[0];for(f=0;f=this._valueMax())return this._valueMax();var b=this.options.step>0?this.options.step:1,c=(a-this._valueMin())%b,d=a-c;return Math.abs(c)*2>=b&&(d+=c>0?b:-b),parseFloat(d.toFixed(5))},_valueMin:function(){return this.options.min},_valueMax:function(){return this.options.max},_refreshValue:function(){var b=this.options.range,c=this.options,d=this,e=this._animateOff?!1:c.animate,f,g={},h,i,j,k;this.options.values&&this.options.values.length?this.handles.each(function(b,i){f=(d.values(b)-d._valueMin())/(d._valueMax()-d._valueMin())*100,g[d.orientation==="horizontal"?"left":"bottom"]=f+"%",a(this).stop(1,1)[e?"animate":"css"](g,c.animate),d.options.range===!0&&(d.orientation==="horizontal"?(b===0&&d.range.stop(1,1)[e?"animate":"css"]({left:f+"%"},c.animate),b===1&&d.range[e?"animate":"css"]({width:f-h+"%"},{queue:!1,duration:c.animate})):(b===0&&d.range.stop(1,1)[e?"animate":"css"]({bottom:f+"%"},c.animate),b===1&&d.range[e?"animate":"css"]({height:f-h+"%"},{queue:!1,duration:c.animate}))),h=f}):(i=this.value(),j=this._valueMin(),k=this._valueMax(),f=k!==j?(i-j)/(k-j)*100:0,g[d.orientation==="horizontal"?"left":"bottom"]=f+"%",this.handle.stop(1,1)[e?"animate":"css"](g,c.animate),b==="min"&&this.orientation==="horizontal"&&this.range.stop(1,1)[e?"animate":"css"]({width:f+"%"},c.animate),b==="max"&&this.orientation==="horizontal"&&this.range[e?"animate":"css"]({width:100-f+"%"},{queue:!1,duration:c.animate}),b==="min"&&this.orientation==="vertical"&&this.range.stop(1,1)[e?"animate":"css"]({height:f+"%"},c.animate),b==="max"&&this.orientation==="vertical"&&this.range[e?"animate":"css"]({height:100-f+"%"},{queue:!1,duration:c.animate}))}}),a.extend(a.ui.slider,{version:"1.8.20"})})(jQuery); \ No newline at end of file +* Copyright 2012 jQuery Foundation and other contributors; Licensed MIT */ +(function(e,t){var n=5;e.widget("ui.slider",e.ui.mouse,{version:"1.9.2",widgetEventPrefix:"slide",options:{animate:!1,distance:0,max:100,min:0,orientation:"horizontal",range:!1,step:1,value:0,values:null},_create:function(){var t,r,i=this.options,s=this.element.find(".ui-slider-handle").addClass("ui-state-default ui-corner-all"),o="",u=[];this._keySliding=!1,this._mouseSliding=!1,this._animateOff=!0,this._handleIndex=null,this._detectOrientation(),this._mouseInit(),this.element.addClass("ui-slider ui-slider-"+this.orientation+" ui-widget"+" ui-widget-content"+" ui-corner-all"+(i.disabled?" ui-slider-disabled ui-disabled":"")),this.range=e([]),i.range&&(i.range===!0&&(i.values||(i.values=[this._valueMin(),this._valueMin()]),i.values.length&&i.values.length!==2&&(i.values=[i.values[0],i.values[0]])),this.range=e("
").appendTo(this.element).addClass("ui-slider-range ui-widget-header"+(i.range==="min"||i.range==="max"?" ui-slider-range-"+i.range:""))),r=i.values&&i.values.length||1;for(t=s.length;tn&&(i=n,s=e(this),o=t)}),c.range===!0&&this.values(1)===c.min&&(o+=1,s=e(this.handles[o])),u=this._start(t,o),u===!1?!1:(this._mouseSliding=!0,this._handleIndex=o,s.addClass("ui-state-active").focus(),a=s.offset(),f=!e(t.target).parents().andSelf().is(".ui-slider-handle"),this._clickOffset=f?{left:0,top:0}:{left:t.pageX-a.left-s.width()/2,top:t.pageY-a.top-s.height()/2-(parseInt(s.css("borderTopWidth"),10)||0)-(parseInt(s.css("borderBottomWidth"),10)||0)+(parseInt(s.css("marginTop"),10)||0)},this.handles.hasClass("ui-state-hover")||this._slide(t,o,r),this._animateOff=!0,!0))},_mouseStart:function(){return!0},_mouseDrag:function(e){var t={x:e.pageX,y:e.pageY},n=this._normValueFromMouse(t);return this._slide(e,this._handleIndex,n),!1},_mouseStop:function(e){return this.handles.removeClass("ui-state-active"),this._mouseSliding=!1,this._stop(e,this._handleIndex),this._change(e,this._handleIndex),this._handleIndex=null,this._clickOffset=null,this._animateOff=!1,!1},_detectOrientation:function(){this.orientation=this.options.orientation==="vertical"?"vertical":"horizontal"},_normValueFromMouse:function(e){var t,n,r,i,s;return this.orientation==="horizontal"?(t=this.elementSize.width,n=e.x-this.elementOffset.left-(this._clickOffset?this._clickOffset.left:0)):(t=this.elementSize.height,n=e.y-this.elementOffset.top-(this._clickOffset?this._clickOffset.top:0)),r=n/t,r>1&&(r=1),r<0&&(r=0),this.orientation==="vertical"&&(r=1-r),i=this._valueMax()-this._valueMin(),s=this._valueMin()+r*i,this._trimAlignValue(s)},_start:function(e,t){var n={handle:this.handles[t],value:this.value()};return this.options.values&&this.options.values.length&&(n.value=this.values(t),n.values=this.values()),this._trigger("start",e,n)},_slide:function(e,t,n){var r,i,s;this.options.values&&this.options.values.length?(r=this.values(t?0:1),this.options.values.length===2&&this.options.range===!0&&(t===0&&n>r||t===1&&n1){this.options.values[t]=this._trimAlignValue(n),this._refreshValue(),this._change(null,t);return}if(!arguments.length)return this._values();if(!e.isArray(arguments[0]))return this.options.values&&this.options.values.length?this._values(t):this.value();r=this.options.values,i=arguments[0];for(s=0;s=this._valueMax())return this._valueMax();var t=this.options.step>0?this.options.step:1,n=(e-this._valueMin())%t,r=e-n;return Math.abs(n)*2>=t&&(r+=n>0?t:-t),parseFloat(r.toFixed(5))},_valueMin:function(){return this.options.min},_valueMax:function(){return this.options.max},_refreshValue:function(){var t,n,r,i,s,o=this.options.range,u=this.options,a=this,f=this._animateOff?!1:u.animate,l={};this.options.values&&this.options.values.length?this.handles.each(function(r){n=(a.values(r)-a._valueMin())/(a._valueMax()-a._valueMin())*100,l[a.orientation==="horizontal"?"left":"bottom"]=n+"%",e(this).stop(1,1)[f?"animate":"css"](l,u.animate),a.options.range===!0&&(a.orientation==="horizontal"?(r===0&&a.range.stop(1,1)[f?"animate":"css"]({left:n+"%"},u.animate),r===1&&a.range[f?"animate":"css"]({width:n-t+"%"},{queue:!1,duration:u.animate})):(r===0&&a.range.stop(1,1)[f?"animate":"css"]({bottom:n+"%"},u.animate),r===1&&a.range[f?"animate":"css"]({height:n-t+"%"},{queue:!1,duration:u.animate}))),t=n}):(r=this.value(),i=this._valueMin(),s=this._valueMax(),n=s!==i?(r-i)/(s-i)*100:0,l[this.orientation==="horizontal"?"left":"bottom"]=n+"%",this.handle.stop(1,1)[f?"animate":"css"](l,u.animate),o==="min"&&this.orientation==="horizontal"&&this.range.stop(1,1)[f?"animate":"css"]({width:n+"%"},u.animate),o==="max"&&this.orientation==="horizontal"&&this.range[f?"animate":"css"]({width:100-n+"%"},{queue:!1,duration:u.animate}),o==="min"&&this.orientation==="vertical"&&this.range.stop(1,1)[f?"animate":"css"]({height:n+"%"},u.animate),o==="max"&&this.orientation==="vertical"&&this.range[f?"animate":"css"]({height:100-n+"%"},{queue:!1,duration:u.animate}))}})})(jQuery); \ No newline at end of file diff --git a/wp-includes/js/jquery/ui/jquery.ui.sortable.min.js b/wp-includes/js/jquery/ui/jquery.ui.sortable.min.js index 593dfb96..963c4de2 100644 --- a/wp-includes/js/jquery/ui/jquery.ui.sortable.min.js +++ b/wp-includes/js/jquery/ui/jquery.ui.sortable.min.js @@ -1,5 +1,5 @@ -/*! jQuery UI - v1.8.20 - 2012-04-30 -* https://github.com/jquery/jquery-ui +/*! jQuery UI - v1.9.2 - 2012-11-23 +* http://jqueryui.com * Includes: jquery.ui.sortable.js -* Copyright (c) 2012 AUTHORS.txt; Licensed MIT, GPL */ -(function(a,b){a.widget("ui.sortable",a.ui.mouse,{widgetEventPrefix:"sort",ready:!1,options:{appendTo:"parent",axis:!1,connectWith:!1,containment:!1,cursor:"auto",cursorAt:!1,dropOnEmpty:!0,forcePlaceholderSize:!1,forceHelperSize:!1,grid:!1,handle:!1,helper:"original",items:"> *",opacity:!1,placeholder:!1,revert:!1,scroll:!0,scrollSensitivity:20,scrollSpeed:20,scope:"default",tolerance:"intersect",zIndex:1e3},_create:function(){var a=this.options;this.containerCache={},this.element.addClass("ui-sortable"),this.refresh(),this.floating=this.items.length?a.axis==="x"||/left|right/.test(this.items[0].item.css("float"))||/inline|table-cell/.test(this.items[0].item.css("display")):!1,this.offset=this.element.offset(),this._mouseInit(),this.ready=!0},destroy:function(){a.Widget.prototype.destroy.call(this),this.element.removeClass("ui-sortable ui-sortable-disabled"),this._mouseDestroy();for(var b=this.items.length-1;b>=0;b--)this.items[b].item.removeData(this.widgetName+"-item");return this},_setOption:function(b,c){b==="disabled"?(this.options[b]=c,this.widget()[c?"addClass":"removeClass"]("ui-sortable-disabled")):a.Widget.prototype._setOption.apply(this,arguments)},_mouseCapture:function(b,c){var d=this;if(this.reverting)return!1;if(this.options.disabled||this.options.type=="static")return!1;this._refreshItems(b);var e=null,f=this,g=a(b.target).parents().each(function(){if(a.data(this,d.widgetName+"-item")==f)return e=a(this),!1});a.data(b.target,d.widgetName+"-item")==f&&(e=a(b.target));if(!e)return!1;if(this.options.handle&&!c){var h=!1;a(this.options.handle,e).find("*").andSelf().each(function(){this==b.target&&(h=!0)});if(!h)return!1}return this.currentItem=e,this._removeCurrentsFromItems(),!0},_mouseStart:function(b,c,d){var e=this.options,f=this;this.currentContainer=this,this.refreshPositions(),this.helper=this._createHelper(b),this._cacheHelperProportions(),this._cacheMargins(),this.scrollParent=this.helper.scrollParent(),this.offset=this.currentItem.offset(),this.offset={top:this.offset.top-this.margins.top,left:this.offset.left-this.margins.left},this.helper.css("position","absolute"),this.cssPosition=this.helper.css("position"),a.extend(this.offset,{click:{left:b.pageX-this.offset.left,top:b.pageY-this.offset.top},parent:this._getParentOffset(),relative:this._getRelativeOffset()}),this.originalPosition=this._generatePosition(b),this.originalPageX=b.pageX,this.originalPageY=b.pageY,e.cursorAt&&this._adjustOffsetFromHelper(e.cursorAt),this.domPosition={prev:this.currentItem.prev()[0],parent:this.currentItem.parent()[0]},this.helper[0]!=this.currentItem[0]&&this.currentItem.hide(),this._createPlaceholder(),e.containment&&this._setContainment(),e.cursor&&(a("body").css("cursor")&&(this._storedCursor=a("body").css("cursor")),a("body").css("cursor",e.cursor)),e.opacity&&(this.helper.css("opacity")&&(this._storedOpacity=this.helper.css("opacity")),this.helper.css("opacity",e.opacity)),e.zIndex&&(this.helper.css("zIndex")&&(this._storedZIndex=this.helper.css("zIndex")),this.helper.css("zIndex",e.zIndex)),this.scrollParent[0]!=document&&this.scrollParent[0].tagName!="HTML"&&(this.overflowOffset=this.scrollParent.offset()),this._trigger("start",b,this._uiHash()),this._preserveHelperProportions||this._cacheHelperProportions();if(!d)for(var g=this.containers.length-1;g>=0;g--)this.containers[g]._trigger("activate",b,f._uiHash(this));return a.ui.ddmanager&&(a.ui.ddmanager.current=this),a.ui.ddmanager&&!e.dropBehaviour&&a.ui.ddmanager.prepareOffsets(this,b),this.dragging=!0,this.helper.addClass("ui-sortable-helper"),this._mouseDrag(b),!0},_mouseDrag:function(b){this.position=this._generatePosition(b),this.positionAbs=this._convertPositionTo("absolute"),this.lastPositionAbs||(this.lastPositionAbs=this.positionAbs);if(this.options.scroll){var c=this.options,d=!1;this.scrollParent[0]!=document&&this.scrollParent[0].tagName!="HTML"?(this.overflowOffset.top+this.scrollParent[0].offsetHeight-b.pageY=0;e--){var f=this.items[e],g=f.item[0],h=this._intersectsWithPointer(f);if(!h)continue;if(g!=this.currentItem[0]&&this.placeholder[h==1?"next":"prev"]()[0]!=g&&!a.ui.contains(this.placeholder[0],g)&&(this.options.type=="semi-dynamic"?!a.ui.contains(this.element[0],g):!0)){this.direction=h==1?"down":"up";if(this.options.tolerance=="pointer"||this._intersectsWithSides(f))this._rearrange(b,f);else break;this._trigger("change",b,this._uiHash());break}}return this._contactContainers(b),a.ui.ddmanager&&a.ui.ddmanager.drag(this,b),this._trigger("sort",b,this._uiHash()),this.lastPositionAbs=this.positionAbs,!1},_mouseStop:function(b,c){if(!b)return;a.ui.ddmanager&&!this.options.dropBehaviour&&a.ui.ddmanager.drop(this,b);if(this.options.revert){var d=this,e=d.placeholder.offset();d.reverting=!0,a(this.helper).animate({left:e.left-this.offset.parent.left-d.margins.left+(this.offsetParent[0]==document.body?0:this.offsetParent[0].scrollLeft),top:e.top-this.offset.parent.top-d.margins.top+(this.offsetParent[0]==document.body?0:this.offsetParent[0].scrollTop)},parseInt(this.options.revert,10)||500,function(){d._clear(b)})}else this._clear(b,c);return!1},cancel:function(){var b=this;if(this.dragging){this._mouseUp({target:null}),this.options.helper=="original"?this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper"):this.currentItem.show();for(var c=this.containers.length-1;c>=0;c--)this.containers[c]._trigger("deactivate",null,b._uiHash(this)),this.containers[c].containerCache.over&&(this.containers[c]._trigger("out",null,b._uiHash(this)),this.containers[c].containerCache.over=0)}return this.placeholder&&(this.placeholder[0].parentNode&&this.placeholder[0].parentNode.removeChild(this.placeholder[0]),this.options.helper!="original"&&this.helper&&this.helper[0].parentNode&&this.helper.remove(),a.extend(this,{helper:null,dragging:!1,reverting:!1,_noFinalSort:null}),this.domPosition.prev?a(this.domPosition.prev).after(this.currentItem):a(this.domPosition.parent).prepend(this.currentItem)),this},serialize:function(b){var c=this._getItemsAsjQuery(b&&b.connected),d=[];return b=b||{},a(c).each(function(){var c=(a(b.item||this).attr(b.attribute||"id")||"").match(b.expression||/(.+)[-=_](.+)/);c&&d.push((b.key||c[1]+"[]")+"="+(b.key&&b.expression?c[1]:c[2]))}),!d.length&&b.key&&d.push(b.key+"="),d.join("&")},toArray:function(b){var c=this._getItemsAsjQuery(b&&b.connected),d=[];return b=b||{},c.each(function(){d.push(a(b.item||this).attr(b.attribute||"id")||"")}),d},_intersectsWith:function(a){var b=this.positionAbs.left,c=b+this.helperProportions.width,d=this.positionAbs.top,e=d+this.helperProportions.height,f=a.left,g=f+a.width,h=a.top,i=h+a.height,j=this.offset.click.top,k=this.offset.click.left,l=d+j>h&&d+jf&&b+ka[this.floating?"width":"height"]?l:f0?"down":"up")},_getDragHorizontalDirection:function(){var a=this.positionAbs.left-this.lastPositionAbs.left;return a!=0&&(a>0?"right":"left")},refresh:function(a){return this._refreshItems(a),this.refreshPositions(),this},_connectWith:function(){var a=this.options;return a.connectWith.constructor==String?[a.connectWith]:a.connectWith},_getItemsAsjQuery:function(b){var c=this,d=[],e=[],f=this._connectWith();if(f&&b)for(var g=f.length-1;g>=0;g--){var h=a(f[g]);for(var i=h.length-1;i>=0;i--){var j=a.data(h[i],this.widgetName);j&&j!=this&&!j.options.disabled&&e.push([a.isFunction(j.options.items)?j.options.items.call(j.element):a(j.options.items,j.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"),j])}}e.push([a.isFunction(this.options.items)?this.options.items.call(this.element,null,{options:this.options,item:this.currentItem}):a(this.options.items,this.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"),this]);for(var g=e.length-1;g>=0;g--)e[g][0].each(function(){d.push(this)});return a(d)},_removeCurrentsFromItems:function(){var a=this.currentItem.find(":data("+this.widgetName+"-item)");for(var b=0;b=0;g--){var h=a(f[g]);for(var i=h.length-1;i>=0;i--){var j=a.data(h[i],this.widgetName);j&&j!=this&&!j.options.disabled&&(e.push([a.isFunction(j.options.items)?j.options.items.call(j.element[0],b,{item:this.currentItem}):a(j.options.items,j.element),j]),this.containers.push(j))}}for(var g=e.length-1;g>=0;g--){var k=e[g][1],l=e[g][0];for(var i=0,m=l.length;i=0;c--){var d=this.items[c];if(d.instance!=this.currentContainer&&this.currentContainer&&d.item[0]!=this.currentItem[0])continue;var e=this.options.toleranceElement?a(this.options.toleranceElement,d.item):d.item;b||(d.width=e.outerWidth(),d.height=e.outerHeight());var f=e.offset();d.left=f.left,d.top=f.top}if(this.options.custom&&this.options.custom.refreshContainers)this.options.custom.refreshContainers.call(this);else for(var c=this.containers.length-1;c>=0;c--){var f=this.containers[c].element.offset();this.containers[c].containerCache.left=f.left,this.containers[c].containerCache.top=f.top,this.containers[c].containerCache.width=this.containers[c].element.outerWidth(),this.containers[c].containerCache.height=this.containers[c].element.outerHeight()}return this},_createPlaceholder:function(b){var c=b||this,d=c.options;if(!d.placeholder||d.placeholder.constructor==String){var e=d.placeholder;d.placeholder={element:function(){var b=a(document.createElement(c.currentItem[0].nodeName)).addClass(e||c.currentItem[0].className+" ui-sortable-placeholder").removeClass("ui-sortable-helper")[0];return e||(b.style.visibility="hidden"),b},update:function(a,b){if(e&&!d.forcePlaceholderSize)return;b.height()||b.height(c.currentItem.innerHeight()-parseInt(c.currentItem.css("paddingTop")||0,10)-parseInt(c.currentItem.css("paddingBottom")||0,10)),b.width()||b.width(c.currentItem.innerWidth()-parseInt(c.currentItem.css("paddingLeft")||0,10)-parseInt(c.currentItem.css("paddingRight")||0,10))}}}c.placeholder=a(d.placeholder.element.call(c.element,c.currentItem)),c.currentItem.after(c.placeholder),d.placeholder.update(c,c.placeholder)},_contactContainers:function(b){var c=null,d=null;for(var e=this.containers.length-1;e>=0;e--){if(a.ui.contains(this.currentItem[0],this.containers[e].element[0]))continue;if(this._intersectsWith(this.containers[e].containerCache)){if(c&&a.ui.contains(this.containers[e].element[0],c.element[0]))continue;c=this.containers[e],d=e}else this.containers[e].containerCache.over&&(this.containers[e]._trigger("out",b,this._uiHash(this)),this.containers[e].containerCache.over=0)}if(!c)return;if(this.containers.length===1)this.containers[d]._trigger("over",b,this._uiHash(this)),this.containers[d].containerCache.over=1;else if(this.currentContainer!=this.containers[d]){var f=1e4,g=null,h=this.positionAbs[this.containers[d].floating?"left":"top"];for(var i=this.items.length-1;i>=0;i--){if(!a.ui.contains(this.containers[d].element[0],this.items[i].item[0]))continue;var j=this.items[i][this.containers[d].floating?"left":"top"];Math.abs(j-h)this.containment[2]&&(f=this.containment[2]+this.offset.click.left),b.pageY-this.offset.click.top>this.containment[3]&&(g=this.containment[3]+this.offset.click.top));if(c.grid){var h=this.originalPageY+Math.round((g-this.originalPageY)/c.grid[1])*c.grid[1];g=this.containment?h-this.offset.click.topthis.containment[3]?h-this.offset.click.topthis.containment[2]?i-this.offset.click.left=0;f--)a.ui.contains(this.containers[f].element[0],this.currentItem[0])&&!c&&(d.push(function(a){return function(b){a._trigger("receive",b,this._uiHash(this))}}.call(this,this.containers[f])),d.push(function(a){return function(b){a._trigger("update",b,this._uiHash(this))}}.call(this,this.containers[f])))}for(var f=this.containers.length-1;f>=0;f--)c||d.push(function(a){return function(b){a._trigger("deactivate",b,this._uiHash(this))}}.call(this,this.containers[f])),this.containers[f].containerCache.over&&(d.push(function(a){return function(b){a._trigger("out",b,this._uiHash(this))}}.call(this,this.containers[f])),this.containers[f].containerCache.over=0);this._storedCursor&&a("body").css("cursor",this._storedCursor),this._storedOpacity&&this.helper.css("opacity",this._storedOpacity),this._storedZIndex&&this.helper.css("zIndex",this._storedZIndex=="auto"?"":this._storedZIndex),this.dragging=!1;if(this.cancelHelperRemoval){if(!c){this._trigger("beforeStop",b,this._uiHash());for(var f=0;f *",opacity:!1,placeholder:!1,revert:!1,scroll:!0,scrollSensitivity:20,scrollSpeed:20,scope:"default",tolerance:"intersect",zIndex:1e3},_create:function(){var e=this.options;this.containerCache={},this.element.addClass("ui-sortable"),this.refresh(),this.floating=this.items.length?e.axis==="x"||/left|right/.test(this.items[0].item.css("float"))||/inline|table-cell/.test(this.items[0].item.css("display")):!1,this.offset=this.element.offset(),this._mouseInit(),this.ready=!0},_destroy:function(){this.element.removeClass("ui-sortable ui-sortable-disabled"),this._mouseDestroy();for(var e=this.items.length-1;e>=0;e--)this.items[e].item.removeData(this.widgetName+"-item");return this},_setOption:function(t,n){t==="disabled"?(this.options[t]=n,this.widget().toggleClass("ui-sortable-disabled",!!n)):e.Widget.prototype._setOption.apply(this,arguments)},_mouseCapture:function(t,n){var r=this;if(this.reverting)return!1;if(this.options.disabled||this.options.type=="static")return!1;this._refreshItems(t);var i=null,s=e(t.target).parents().each(function(){if(e.data(this,r.widgetName+"-item")==r)return i=e(this),!1});e.data(t.target,r.widgetName+"-item")==r&&(i=e(t.target));if(!i)return!1;if(this.options.handle&&!n){var o=!1;e(this.options.handle,i).find("*").andSelf().each(function(){this==t.target&&(o=!0)});if(!o)return!1}return this.currentItem=i,this._removeCurrentsFromItems(),!0},_mouseStart:function(t,n,r){var i=this.options;this.currentContainer=this,this.refreshPositions(),this.helper=this._createHelper(t),this._cacheHelperProportions(),this._cacheMargins(),this.scrollParent=this.helper.scrollParent(),this.offset=this.currentItem.offset(),this.offset={top:this.offset.top-this.margins.top,left:this.offset.left-this.margins.left},e.extend(this.offset,{click:{left:t.pageX-this.offset.left,top:t.pageY-this.offset.top},parent:this._getParentOffset(),relative:this._getRelativeOffset()}),this.helper.css("position","absolute"),this.cssPosition=this.helper.css("position"),this.originalPosition=this._generatePosition(t),this.originalPageX=t.pageX,this.originalPageY=t.pageY,i.cursorAt&&this._adjustOffsetFromHelper(i.cursorAt),this.domPosition={prev:this.currentItem.prev()[0],parent:this.currentItem.parent()[0]},this.helper[0]!=this.currentItem[0]&&this.currentItem.hide(),this._createPlaceholder(),i.containment&&this._setContainment(),i.cursor&&(e("body").css("cursor")&&(this._storedCursor=e("body").css("cursor")),e("body").css("cursor",i.cursor)),i.opacity&&(this.helper.css("opacity")&&(this._storedOpacity=this.helper.css("opacity")),this.helper.css("opacity",i.opacity)),i.zIndex&&(this.helper.css("zIndex")&&(this._storedZIndex=this.helper.css("zIndex")),this.helper.css("zIndex",i.zIndex)),this.scrollParent[0]!=document&&this.scrollParent[0].tagName!="HTML"&&(this.overflowOffset=this.scrollParent.offset()),this._trigger("start",t,this._uiHash()),this._preserveHelperProportions||this._cacheHelperProportions();if(!r)for(var s=this.containers.length-1;s>=0;s--)this.containers[s]._trigger("activate",t,this._uiHash(this));return e.ui.ddmanager&&(e.ui.ddmanager.current=this),e.ui.ddmanager&&!i.dropBehaviour&&e.ui.ddmanager.prepareOffsets(this,t),this.dragging=!0,this.helper.addClass("ui-sortable-helper"),this._mouseDrag(t),!0},_mouseDrag:function(t){this.position=this._generatePosition(t),this.positionAbs=this._convertPositionTo("absolute"),this.lastPositionAbs||(this.lastPositionAbs=this.positionAbs);if(this.options.scroll){var n=this.options,r=!1;this.scrollParent[0]!=document&&this.scrollParent[0].tagName!="HTML"?(this.overflowOffset.top+this.scrollParent[0].offsetHeight-t.pageY=0;i--){var s=this.items[i],o=s.item[0],u=this._intersectsWithPointer(s);if(!u)continue;if(s.instance!==this.currentContainer)continue;if(o!=this.currentItem[0]&&this.placeholder[u==1?"next":"prev"]()[0]!=o&&!e.contains(this.placeholder[0],o)&&(this.options.type=="semi-dynamic"?!e.contains(this.element[0],o):!0)){this.direction=u==1?"down":"up";if(this.options.tolerance!="pointer"&&!this._intersectsWithSides(s))break;this._rearrange(t,s),this._trigger("change",t,this._uiHash());break}}return this._contactContainers(t),e.ui.ddmanager&&e.ui.ddmanager.drag(this,t),this._trigger("sort",t,this._uiHash()),this.lastPositionAbs=this.positionAbs,!1},_mouseStop:function(t,n){if(!t)return;e.ui.ddmanager&&!this.options.dropBehaviour&&e.ui.ddmanager.drop(this,t);if(this.options.revert){var r=this,i=this.placeholder.offset();this.reverting=!0,e(this.helper).animate({left:i.left-this.offset.parent.left-this.margins.left+(this.offsetParent[0]==document.body?0:this.offsetParent[0].scrollLeft),top:i.top-this.offset.parent.top-this.margins.top+(this.offsetParent[0]==document.body?0:this.offsetParent[0].scrollTop)},parseInt(this.options.revert,10)||500,function(){r._clear(t)})}else this._clear(t,n);return!1},cancel:function(){if(this.dragging){this._mouseUp({target:null}),this.options.helper=="original"?this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper"):this.currentItem.show();for(var t=this.containers.length-1;t>=0;t--)this.containers[t]._trigger("deactivate",null,this._uiHash(this)),this.containers[t].containerCache.over&&(this.containers[t]._trigger("out",null,this._uiHash(this)),this.containers[t].containerCache.over=0)}return this.placeholder&&(this.placeholder[0].parentNode&&this.placeholder[0].parentNode.removeChild(this.placeholder[0]),this.options.helper!="original"&&this.helper&&this.helper[0].parentNode&&this.helper.remove(),e.extend(this,{helper:null,dragging:!1,reverting:!1,_noFinalSort:null}),this.domPosition.prev?e(this.domPosition.prev).after(this.currentItem):e(this.domPosition.parent).prepend(this.currentItem)),this},serialize:function(t){var n=this._getItemsAsjQuery(t&&t.connected),r=[];return t=t||{},e(n).each(function(){var n=(e(t.item||this).attr(t.attribute||"id")||"").match(t.expression||/(.+)[-=_](.+)/);n&&r.push((t.key||n[1]+"[]")+"="+(t.key&&t.expression?n[1]:n[2]))}),!r.length&&t.key&&r.push(t.key+"="),r.join("&")},toArray:function(t){var n=this._getItemsAsjQuery(t&&t.connected),r=[];return t=t||{},n.each(function(){r.push(e(t.item||this).attr(t.attribute||"id")||"")}),r},_intersectsWith:function(e){var t=this.positionAbs.left,n=t+this.helperProportions.width,r=this.positionAbs.top,i=r+this.helperProportions.height,s=e.left,o=s+e.width,u=e.top,a=u+e.height,f=this.offset.click.top,l=this.offset.click.left,c=r+f>u&&r+fs&&t+le[this.floating?"width":"height"]?c:s0?"down":"up")},_getDragHorizontalDirection:function(){var e=this.positionAbs.left-this.lastPositionAbs.left;return e!=0&&(e>0?"right":"left")},refresh:function(e){return this._refreshItems(e),this.refreshPositions(),this},_connectWith:function(){var e=this.options;return e.connectWith.constructor==String?[e.connectWith]:e.connectWith},_getItemsAsjQuery:function(t){var n=[],r=[],i=this._connectWith();if(i&&t)for(var s=i.length-1;s>=0;s--){var o=e(i[s]);for(var u=o.length-1;u>=0;u--){var a=e.data(o[u],this.widgetName);a&&a!=this&&!a.options.disabled&&r.push([e.isFunction(a.options.items)?a.options.items.call(a.element):e(a.options.items,a.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"),a])}}r.push([e.isFunction(this.options.items)?this.options.items.call(this.element,null,{options:this.options,item:this.currentItem}):e(this.options.items,this.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"),this]);for(var s=r.length-1;s>=0;s--)r[s][0].each(function(){n.push(this)});return e(n)},_removeCurrentsFromItems:function(){var t=this.currentItem.find(":data("+this.widgetName+"-item)");this.items=e.grep(this.items,function(e){for(var n=0;n=0;s--){var o=e(i[s]);for(var u=o.length-1;u>=0;u--){var a=e.data(o[u],this.widgetName);a&&a!=this&&!a.options.disabled&&(r.push([e.isFunction(a.options.items)?a.options.items.call(a.element[0],t,{item:this.currentItem}):e(a.options.items,a.element),a]),this.containers.push(a))}}for(var s=r.length-1;s>=0;s--){var f=r[s][1],l=r[s][0];for(var u=0,c=l.length;u=0;n--){var r=this.items[n];if(r.instance!=this.currentContainer&&this.currentContainer&&r.item[0]!=this.currentItem[0])continue;var i=this.options.toleranceElement?e(this.options.toleranceElement,r.item):r.item;t||(r.width=i.outerWidth(),r.height=i.outerHeight());var s=i.offset();r.left=s.left,r.top=s.top}if(this.options.custom&&this.options.custom.refreshContainers)this.options.custom.refreshContainers.call(this);else for(var n=this.containers.length-1;n>=0;n--){var s=this.containers[n].element.offset();this.containers[n].containerCache.left=s.left,this.containers[n].containerCache.top=s.top,this.containers[n].containerCache.width=this.containers[n].element.outerWidth(),this.containers[n].containerCache.height=this.containers[n].element.outerHeight()}return this},_createPlaceholder:function(t){t=t||this;var n=t.options;if(!n.placeholder||n.placeholder.constructor==String){var r=n.placeholder;n.placeholder={element:function(){var n=e(document.createElement(t.currentItem[0].nodeName)).addClass(r||t.currentItem[0].className+" ui-sortable-placeholder").removeClass("ui-sortable-helper")[0];return r||(n.style.visibility="hidden"),n},update:function(e,i){if(r&&!n.forcePlaceholderSize)return;i.height()||i.height(t.currentItem.innerHeight()-parseInt(t.currentItem.css("paddingTop")||0,10)-parseInt(t.currentItem.css("paddingBottom")||0,10)),i.width()||i.width(t.currentItem.innerWidth()-parseInt(t.currentItem.css("paddingLeft")||0,10)-parseInt(t.currentItem.css("paddingRight")||0,10))}}}t.placeholder=e(n.placeholder.element.call(t.element,t.currentItem)),t.currentItem.after(t.placeholder),n.placeholder.update(t,t.placeholder)},_contactContainers:function(t){var n=null,r=null;for(var i=this.containers.length-1;i>=0;i--){if(e.contains(this.currentItem[0],this.containers[i].element[0]))continue;if(this._intersectsWith(this.containers[i].containerCache)){if(n&&e.contains(this.containers[i].element[0],n.element[0]))continue;n=this.containers[i],r=i}else this.containers[i].containerCache.over&&(this.containers[i]._trigger("out",t,this._uiHash(this)),this.containers[i].containerCache.over=0)}if(!n)return;if(this.containers.length===1)this.containers[r]._trigger("over",t,this._uiHash(this)),this.containers[r].containerCache.over=1;else{var s=1e4,o=null,u=this.containers[r].floating?"left":"top",a=this.containers[r].floating?"width":"height",f=this.positionAbs[u]+this.offset.click[u];for(var l=this.items.length-1;l>=0;l--){if(!e.contains(this.containers[r].element[0],this.items[l].item[0]))continue;if(this.items[l].item[0]==this.currentItem[0])continue;var c=this.items[l].item.offset()[u],h=!1;Math.abs(c-f)>Math.abs(c+this.items[l][a]-f)&&(h=!0,c+=this.items[l][a]),Math.abs(c-f)this.containment[2]&&(s=this.containment[2]+this.offset.click.left),t.pageY-this.offset.click.top>this.containment[3]&&(o=this.containment[3]+this.offset.click.top));if(n.grid){var u=this.originalPageY+Math.round((o-this.originalPageY)/n.grid[1])*n.grid[1];o=this.containment?u-this.offset.click.topthis.containment[3]?u-this.offset.click.topthis.containment[2]?a-this.offset.click.left=0;i--)n||r.push(function(e){return function(t){e._trigger("deactivate",t,this._uiHash(this))}}.call(this,this.containers[i])),this.containers[i].containerCache.over&&(r.push(function(e){return function(t){e._trigger("out",t,this._uiHash(this))}}.call(this,this.containers[i])),this.containers[i].containerCache.over=0);this._storedCursor&&e("body").css("cursor",this._storedCursor),this._storedOpacity&&this.helper.css("opacity",this._storedOpacity),this._storedZIndex&&this.helper.css("zIndex",this._storedZIndex=="auto"?"":this._storedZIndex),this.dragging=!1;if(this.cancelHelperRemoval){if(!n){this._trigger("beforeStop",t,this._uiHash());for(var i=0;i",widgetEventPrefix:"spin",options:{culture:null,icons:{down:"ui-icon-triangle-1-s",up:"ui-icon-triangle-1-n"},incremental:!0,max:null,min:null,numberFormat:null,page:10,step:1,change:null,spin:null,start:null,stop:null},_create:function(){this._setOption("max",this.options.max),this._setOption("min",this.options.min),this._setOption("step",this.options.step),this._value(this.element.val(),!0),this._draw(),this._on(this._events),this._refresh(),this._on(this.window,{beforeunload:function(){this.element.removeAttr("autocomplete")}})},_getCreateOptions:function(){var t={},n=this.element;return e.each(["min","max","step"],function(e,r){var i=n.attr(r);i!==undefined&&i.length&&(t[r]=i)}),t},_events:{keydown:function(e){this._start(e)&&this._keydown(e)&&e.preventDefault()},keyup:"_stop",focus:function(){this.previous=this.element.val()},blur:function(e){if(this.cancelBlur){delete this.cancelBlur;return}this._refresh(),this.previous!==this.element.val()&&this._trigger("change",e)},mousewheel:function(e,t){if(!t)return;if(!this.spinning&&!this._start(e))return!1;this._spin((t>0?1:-1)*this.options.step,e),clearTimeout(this.mousewheelTimer),this.mousewheelTimer=this._delay(function(){this.spinning&&this._stop(e)},100),e.preventDefault()},"mousedown .ui-spinner-button":function(t){function r(){var e=this.element[0]===this.document[0].activeElement;e||(this.element.focus(),this.previous=n,this._delay(function(){this.previous=n}))}var n;n=this.element[0]===this.document[0].activeElement?this.previous:this.element.val(),t.preventDefault(),r.call(this),this.cancelBlur=!0,this._delay(function(){delete this.cancelBlur,r.call(this)});if(this._start(t)===!1)return;this._repeat(null,e(t.currentTarget).hasClass("ui-spinner-up")?1:-1,t)},"mouseup .ui-spinner-button":"_stop","mouseenter .ui-spinner-button":function(t){if(!e(t.currentTarget).hasClass("ui-state-active"))return;if(this._start(t)===!1)return!1;this._repeat(null,e(t.currentTarget).hasClass("ui-spinner-up")?1:-1,t)},"mouseleave .ui-spinner-button":"_stop"},_draw:function(){var e=this.uiSpinner=this.element.addClass("ui-spinner-input").attr("autocomplete","off").wrap(this._uiSpinnerHtml()).parent().append(this._buttonHtml());this.element.attr("role","spinbutton"),this.buttons=e.find(".ui-spinner-button").attr("tabIndex",-1).button().removeClass("ui-corner-all"),this.buttons.height()>Math.ceil(e.height()*.5)&&e.height()>0&&e.height(e.height()),this.options.disabled&&this.disable()},_keydown:function(t){var n=this.options,r=e.ui.keyCode;switch(t.keyCode){case r.UP:return this._repeat(null,1,t),!0;case r.DOWN:return this._repeat(null,-1,t),!0;case r.PAGE_UP:return this._repeat(null,n.page,t),!0;case r.PAGE_DOWN:return this._repeat(null,-n.page,t),!0}return!1},_uiSpinnerHtml:function(){return""},_buttonHtml:function(){return""+""+""+""+""},_start:function(e){return!this.spinning&&this._trigger("start",e)===!1?!1:(this.counter||(this.counter=1),this.spinning=!0,!0)},_repeat:function(e,t,n){e=e||500,clearTimeout(this.timer),this.timer=this._delay(function(){this._repeat(40,t,n)},e),this._spin(t*this.options.step,n)},_spin:function(e,t){var n=this.value()||0;this.counter||(this.counter=1),n=this._adjustValue(n+e*this._increment(this.counter));if(!this.spinning||this._trigger("spin",t,{value:n})!==!1)this._value(n),this.counter++},_increment:function(t){var n=this.options.incremental;return n?e.isFunction(n)?n(t):Math.floor(t*t*t/5e4-t*t/500+17*t/200+1):1},_precision:function(){var e=this._precisionOf(this.options.step);return this.options.min!==null&&(e=Math.max(e,this._precisionOf(this.options.min))),e},_precisionOf:function(e){var t=e.toString(),n=t.indexOf(".");return n===-1?0:t.length-n-1},_adjustValue:function(e){var t,n,r=this.options;return t=r.min!==null?r.min:0,n=e-t,n=Math.round(n/r.step)*r.step,e=t+n,e=parseFloat(e.toFixed(this._precision())),r.max!==null&&e>r.max?r.max:r.min!==null&&e",remove:null,select:null,show:null,spinner:"Loading…",tabTemplate:"
  • #{label}
  • "},_create:function(){this._tabify(!0)},_setOption:function(a,b){if(a=="selected"){if(this.options.collapsible&&b==this.options.selected)return;this.select(b)}else this.options[a]=b,this._tabify()},_tabId:function(a){return a.title&&a.title.replace(/\s/g,"_").replace(/[^\w\u00c0-\uFFFF-]/g,"")||this.options.idPrefix+e()},_sanitizeSelector:function(a){return a.replace(/:/g,"\\:")},_cookie:function(){var b=this.cookie||(this.cookie=this.options.cookie.name||"ui-tabs-"+f());return a.cookie.apply(null,[b].concat(a.makeArray(arguments)))},_ui:function(a,b){return{tab:a,panel:b,index:this.anchors.index(a)}},_cleanup:function(){this.lis.filter(".ui-state-processing").removeClass("ui-state-processing").find("span:data(label.tabs)").each(function(){var b=a(this);b.html(b.data("label.tabs")).removeData("label.tabs")})},_tabify:function(c){function m(b,c){b.css("display",""),!a.support.opacity&&c.opacity&&b[0].style.removeAttribute("filter")}var d=this,e=this.options,f=/^#.+/;this.list=this.element.find("ol,ul").eq(0),this.lis=a(" > li:has(a[href])",this.list),this.anchors=this.lis.map(function(){return a("a",this)[0]}),this.panels=a([]),this.anchors.each(function(b,c){var g=a(c).attr("href"),h=g.split("#")[0],i;h&&(h===location.toString().split("#")[0]||(i=a("base")[0])&&h===i.href)&&(g=c.hash,c.href=g);if(f.test(g))d.panels=d.panels.add(d.element.find(d._sanitizeSelector(g)));else if(g&&g!=="#"){a.data(c,"href.tabs",g),a.data(c,"load.tabs",g.replace(/#.*$/,""));var j=d._tabId(c);c.href="#"+j;var k=d.element.find("#"+j);k.length||(k=a(e.panelTemplate).attr("id",j).addClass("ui-tabs-panel ui-widget-content ui-corner-bottom").insertAfter(d.panels[b-1]||d.list),k.data("destroy.tabs",!0)),d.panels=d.panels.add(k)}else e.disabled.push(b)}),c?(this.element.addClass("ui-tabs ui-widget ui-widget-content ui-corner-all"),this.list.addClass("ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all"),this.lis.addClass("ui-state-default ui-corner-top"),this.panels.addClass("ui-tabs-panel ui-widget-content ui-corner-bottom"),e.selected===b?(location.hash&&this.anchors.each(function(a,b){if(b.hash==location.hash)return e.selected=a,!1}),typeof e.selected!="number"&&e.cookie&&(e.selected=parseInt(d._cookie(),10)),typeof e.selected!="number"&&this.lis.filter(".ui-tabs-selected").length&&(e.selected=this.lis.index(this.lis.filter(".ui-tabs-selected"))),e.selected=e.selected||(this.lis.length?0:-1)):e.selected===null&&(e.selected=-1),e.selected=e.selected>=0&&this.anchors[e.selected]||e.selected<0?e.selected:0,e.disabled=a.unique(e.disabled.concat(a.map(this.lis.filter(".ui-state-disabled"),function(a,b){return d.lis.index(a)}))).sort(),a.inArray(e.selected,e.disabled)!=-1&&e.disabled.splice(a.inArray(e.selected,e.disabled),1),this.panels.addClass("ui-tabs-hide"),this.lis.removeClass("ui-tabs-selected ui-state-active"),e.selected>=0&&this.anchors.length&&(d.element.find(d._sanitizeSelector(d.anchors[e.selected].hash)).removeClass("ui-tabs-hide"),this.lis.eq(e.selected).addClass("ui-tabs-selected ui-state-active"),d.element.queue("tabs",function(){d._trigger("show",null,d._ui(d.anchors[e.selected],d.element.find(d._sanitizeSelector(d.anchors[e.selected].hash))[0]))}),this.load(e.selected)),a(window).bind("unload",function(){d.lis.add(d.anchors).unbind(".tabs"),d.lis=d.anchors=d.panels=null})):e.selected=this.lis.index(this.lis.filter(".ui-tabs-selected")),this.element[e.collapsible?"addClass":"removeClass"]("ui-tabs-collapsible"),e.cookie&&this._cookie(e.selected,e.cookie);for(var g=0,h;h=this.lis[g];g++)a(h)[a.inArray(g,e.disabled)!=-1&&!a(h).hasClass("ui-tabs-selected")?"addClass":"removeClass"]("ui-state-disabled");e.cache===!1&&this.anchors.removeData("cache.tabs"),this.lis.add(this.anchors).unbind(".tabs");if(e.event!=="mouseover"){var i=function(a,b){b.is(":not(.ui-state-disabled)")&&b.addClass("ui-state-"+a)},j=function(a,b){b.removeClass("ui-state-"+a)};this.lis.bind("mouseover.tabs",function(){i("hover",a(this))}),this.lis.bind("mouseout.tabs",function(){j("hover",a(this))}),this.anchors.bind("focus.tabs",function(){i("focus",a(this).closest("li"))}),this.anchors.bind("blur.tabs",function(){j("focus",a(this).closest("li"))})}var k,l;e.fx&&(a.isArray(e.fx)?(k=e.fx[0],l=e.fx[1]):k=l=e.fx);var n=l?function(b,c){a(b).closest("li").addClass("ui-tabs-selected ui-state-active"),c.hide().removeClass("ui-tabs-hide").animate(l,l.duration||"normal",function(){m(c,l),d._trigger("show",null,d._ui(b,c[0]))})}:function(b,c){a(b).closest("li").addClass("ui-tabs-selected ui-state-active"),c.removeClass("ui-tabs-hide"),d._trigger("show",null,d._ui(b,c[0]))},o=k?function(a,b){b.animate(k,k.duration||"normal",function(){d.lis.removeClass("ui-tabs-selected ui-state-active"),b.addClass("ui-tabs-hide"),m(b,k),d.element.dequeue("tabs")})}:function(a,b,c){d.lis.removeClass("ui-tabs-selected ui-state-active"),b.addClass("ui-tabs-hide"),d.element.dequeue("tabs")};this.anchors.bind(e.event+".tabs",function(){var b=this,c=a(b).closest("li"),f=d.panels.filter(":not(.ui-tabs-hide)"),g=d.element.find(d._sanitizeSelector(b.hash));if(c.hasClass("ui-tabs-selected")&&!e.collapsible||c.hasClass("ui-state-disabled")||c.hasClass("ui-state-processing")||d.panels.filter(":animated").length||d._trigger("select",null,d._ui(this,g[0]))===!1)return this.blur(),!1;e.selected=d.anchors.index(this),d.abort();if(e.collapsible){if(c.hasClass("ui-tabs-selected"))return e.selected=-1,e.cookie&&d._cookie(e.selected,e.cookie),d.element.queue("tabs",function(){o(b,f)}).dequeue("tabs"),this.blur(),!1;if(!f.length)return e.cookie&&d._cookie(e.selected,e.cookie),d.element.queue("tabs",function(){n(b,g)}),d.load(d.anchors.index(this)),this.blur(),!1}e.cookie&&d._cookie(e.selected,e.cookie);if(g.length)f.length&&d.element.queue("tabs",function(){o(b,f)}),d.element.queue("tabs",function(){n(b,g)}),d.load(d.anchors.index(this));else throw"jQuery UI Tabs: Mismatching fragment identifier.";a.browser.msie&&this.blur()}),this.anchors.bind("click.tabs",function(){return!1})},_getIndex:function(a){return typeof a=="string"&&(a=this.anchors.index(this.anchors.filter("[href$='"+a+"']"))),a},destroy:function(){var b=this.options;return this.abort(),this.element.unbind(".tabs").removeClass("ui-tabs ui-widget ui-widget-content ui-corner-all ui-tabs-collapsible").removeData("tabs"),this.list.removeClass("ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all"),this.anchors.each(function(){var b=a.data(this,"href.tabs");b&&(this.href=b);var c=a(this).unbind(".tabs");a.each(["href","load","cache"],function(a,b){c.removeData(b+".tabs")})}),this.lis.unbind(".tabs").add(this.panels).each(function(){a.data(this,"destroy.tabs")?a(this).remove():a(this).removeClass(["ui-state-default","ui-corner-top","ui-tabs-selected","ui-state-active","ui-state-hover","ui-state-focus","ui-state-disabled","ui-tabs-panel","ui-widget-content","ui-corner-bottom","ui-tabs-hide"].join(" "))}),b.cookie&&this._cookie(null,b.cookie),this},add:function(c,d,e){e===b&&(e=this.anchors.length);var f=this,g=this.options,h=a(g.tabTemplate.replace(/#\{href\}/g,c).replace(/#\{label\}/g,d)),i=c.indexOf("#")?this._tabId(a("a",h)[0]):c.replace("#","");h.addClass("ui-state-default ui-corner-top").data("destroy.tabs",!0);var j=f.element.find("#"+i);return j.length||(j=a(g.panelTemplate).attr("id",i).data("destroy.tabs",!0)),j.addClass("ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide"),e>=this.lis.length?(h.appendTo(this.list),j.appendTo(this.list[0].parentNode)):(h.insertBefore(this.lis[e]),j.insertBefore(this.panels[e])),g.disabled=a.map(g.disabled,function(a,b){return a>=e?++a:a}),this._tabify(),this.anchors.length==1&&(g.selected=0,h.addClass("ui-tabs-selected ui-state-active"),j.removeClass("ui-tabs-hide"),this.element.queue("tabs",function(){f._trigger("show",null,f._ui(f.anchors[0],f.panels[0]))}),this.load(0)),this._trigger("add",null,this._ui(this.anchors[e],this.panels[e])),this},remove:function(b){b=this._getIndex(b);var c=this.options,d=this.lis.eq(b).remove(),e=this.panels.eq(b).remove();return d.hasClass("ui-tabs-selected")&&this.anchors.length>1&&this.select(b+(b+1=b?--a:a}),this._tabify(),this._trigger("remove",null,this._ui(d.find("a")[0],e[0])),this},enable:function(b){b=this._getIndex(b);var c=this.options;if(a.inArray(b,c.disabled)==-1)return;return this.lis.eq(b).removeClass("ui-state-disabled"),c.disabled=a.grep(c.disabled,function(a,c){return a!=b}),this._trigger("enable",null,this._ui(this.anchors[b],this.panels[b])),this},disable:function(a){a=this._getIndex(a);var b=this,c=this.options;return a!=c.selected&&(this.lis.eq(a).addClass("ui-state-disabled"),c.disabled.push(a),c.disabled.sort(),this._trigger("disable",null,this._ui(this.anchors[a],this.panels[a]))),this},select:function(a){a=this._getIndex(a);if(a==-1)if(this.options.collapsible&&this.options.selected!=-1)a=this.options.selected;else return this;return this.anchors.eq(a).trigger(this.options.event+".tabs"),this},load:function(b){b=this._getIndex(b);var c=this,d=this.options,e=this.anchors.eq(b)[0],f=a.data(e,"load.tabs");this.abort();if(!f||this.element.queue("tabs").length!==0&&a.data(e,"cache.tabs")){this.element.dequeue("tabs");return}this.lis.eq(b).addClass("ui-state-processing");if(d.spinner){var g=a("span",e);g.data("label.tabs",g.html()).html(d.spinner)}return this.xhr=a.ajax(a.extend({},d.ajaxOptions,{url:f,success:function(f,g){c.element.find(c._sanitizeSelector(e.hash)).html(f),c._cleanup(),d.cache&&a.data(e,"cache.tabs",!0),c._trigger("load",null,c._ui(c.anchors[b],c.panels[b]));try{d.ajaxOptions.success(f,g)}catch(h){}},error:function(a,f,g){c._cleanup(),c._trigger("load",null,c._ui(c.anchors[b],c.panels[b]));try{d.ajaxOptions.error(a,f,b,e)}catch(g){}}})),c.element.dequeue("tabs"),this},abort:function(){return this.element.queue([]),this.panels.stop(!1,!0),this.element.queue("tabs",this.element.queue("tabs").splice(-2,2)),this.xhr&&(this.xhr.abort(),delete this.xhr),this._cleanup(),this},url:function(a,b){return this.anchors.eq(a).removeData("cache.tabs").data("load.tabs",b),this},length:function(){return this.anchors.length}}),a.extend(a.ui.tabs,{version:"1.8.20"}),a.extend(a.ui.tabs.prototype,{rotation:null,rotate:function(a,b){var c=this,d=this.options,e=c._rotate||(c._rotate=function(b){clearTimeout(c.rotation),c.rotation=setTimeout(function(){var a=d.selected;c.select(++a1&&e.href.replace(r,"")===location.href.replace(r,"").replace(/\s/g,"%20")}var n=0,r=/#.*$/;e.widget("ui.tabs",{version:"1.9.2",delay:300,options:{active:null,collapsible:!1,event:"click",heightStyle:"content",hide:null,show:null,activate:null,beforeActivate:null,beforeLoad:null,load:null},_create:function(){var t=this,n=this.options,r=n.active,i=location.hash.substring(1);this.running=!1,this.element.addClass("ui-tabs ui-widget ui-widget-content ui-corner-all").toggleClass("ui-tabs-collapsible",n.collapsible).delegate(".ui-tabs-nav > li","mousedown"+this.eventNamespace,function(t){e(this).is(".ui-state-disabled")&&t.preventDefault()}).delegate(".ui-tabs-anchor","focus"+this.eventNamespace,function(){e(this).closest("li").is(".ui-state-disabled")&&this.blur()}),this._processTabs();if(r===null){i&&this.tabs.each(function(t,n){if(e(n).attr("aria-controls")===i)return r=t,!1}),r===null&&(r=this.tabs.index(this.tabs.filter(".ui-tabs-active")));if(r===null||r===-1)r=this.tabs.length?0:!1}r!==!1&&(r=this.tabs.index(this.tabs.eq(r)),r===-1&&(r=n.collapsible?!1:0)),n.active=r,!n.collapsible&&n.active===!1&&this.anchors.length&&(n.active=0),e.isArray(n.disabled)&&(n.disabled=e.unique(n.disabled.concat(e.map(this.tabs.filter(".ui-state-disabled"),function(e){return t.tabs.index(e)}))).sort()),this.options.active!==!1&&this.anchors.length?this.active=this._findActive(this.options.active):this.active=e(),this._refresh(),this.active.length&&this.load(n.active)},_getCreateEventData:function(){return{tab:this.active,panel:this.active.length?this._getPanelForTab(this.active):e()}},_tabKeydown:function(t){var n=e(this.document[0].activeElement).closest("li"),r=this.tabs.index(n),i=!0;if(this._handlePageNav(t))return;switch(t.keyCode){case e.ui.keyCode.RIGHT:case e.ui.keyCode.DOWN:r++;break;case e.ui.keyCode.UP:case e.ui.keyCode.LEFT:i=!1,r--;break;case e.ui.keyCode.END:r=this.anchors.length-1;break;case e.ui.keyCode.HOME:r=0;break;case e.ui.keyCode.SPACE:t.preventDefault(),clearTimeout(this.activating),this._activate(r);return;case e.ui.keyCode.ENTER:t.preventDefault(),clearTimeout(this.activating),this._activate(r===this.options.active?!1:r);return;default:return}t.preventDefault(),clearTimeout(this.activating),r=this._focusNextTab(r,i),t.ctrlKey||(n.attr("aria-selected","false"),this.tabs.eq(r).attr("aria-selected","true"),this.activating=this._delay(function(){this.option("active",r)},this.delay))},_panelKeydown:function(t){if(this._handlePageNav(t))return;t.ctrlKey&&t.keyCode===e.ui.keyCode.UP&&(t.preventDefault(),this.active.focus())},_handlePageNav:function(t){if(t.altKey&&t.keyCode===e.ui.keyCode.PAGE_UP)return this._activate(this._focusNextTab(this.options.active-1,!1)),!0;if(t.altKey&&t.keyCode===e.ui.keyCode.PAGE_DOWN)return this._activate(this._focusNextTab(this.options.active+1,!0)),!0},_findNextTab:function(t,n){function i(){return t>r&&(t=0),t<0&&(t=r),t}var r=this.tabs.length-1;while(e.inArray(i(),this.options.disabled)!==-1)t=n?t+1:t-1;return t},_focusNextTab:function(e,t){return e=this._findNextTab(e,t),this.tabs.eq(e).focus(),e},_setOption:function(e,t){if(e==="active"){this._activate(t);return}if(e==="disabled"){this._setupDisabled(t);return}this._super(e,t),e==="collapsible"&&(this.element.toggleClass("ui-tabs-collapsible",t),!t&&this.options.active===!1&&this._activate(0)),e==="event"&&this._setupEvents(t),e==="heightStyle"&&this._setupHeightStyle(t)},_tabId:function(e){return e.attr("aria-controls")||"ui-tabs-"+i()},_sanitizeSelector:function(e){return e?e.replace(/[!"$%&'()*+,.\/:;<=>?@\[\]\^`{|}~]/g,"\\$&"):""},refresh:function(){var t=this.options,n=this.tablist.children(":has(a[href])");t.disabled=e.map(n.filter(".ui-state-disabled"),function(e){return n.index(e)}),this._processTabs(),t.active===!1||!this.anchors.length?(t.active=!1,this.active=e()):this.active.length&&!e.contains(this.tablist[0],this.active[0])?this.tabs.length===t.disabled.length?(t.active=!1,this.active=e()):this._activate(this._findNextTab(Math.max(0,t.active-1),!1)):t.active=this.tabs.index(this.active),this._refresh()},_refresh:function(){this._setupDisabled(this.options.disabled),this._setupEvents(this.options.event),this._setupHeightStyle(this.options.heightStyle),this.tabs.not(this.active).attr({"aria-selected":"false",tabIndex:-1}),this.panels.not(this._getPanelForTab(this.active)).hide().attr({"aria-expanded":"false","aria-hidden":"true"}),this.active.length?(this.active.addClass("ui-tabs-active ui-state-active").attr({"aria-selected":"true",tabIndex:0}),this._getPanelForTab(this.active).show().attr({"aria-expanded":"true","aria-hidden":"false"})):this.tabs.eq(0).attr("tabIndex",0)},_processTabs:function(){var t=this;this.tablist=this._getList().addClass("ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all").attr("role","tablist"),this.tabs=this.tablist.find("> li:has(a[href])").addClass("ui-state-default ui-corner-top").attr({role:"tab",tabIndex:-1}),this.anchors=this.tabs.map(function(){return e("a",this)[0]}).addClass("ui-tabs-anchor").attr({role:"presentation",tabIndex:-1}),this.panels=e(),this.anchors.each(function(n,r){var i,o,u,a=e(r).uniqueId().attr("id"),f=e(r).closest("li"),l=f.attr("aria-controls");s(r)?(i=r.hash,o=t.element.find(t._sanitizeSelector(i))):(u=t._tabId(f),i="#"+u,o=t.element.find(i),o.length||(o=t._createPanel(u),o.insertAfter(t.panels[n-1]||t.tablist)),o.attr("aria-live","polite")),o.length&&(t.panels=t.panels.add(o)),l&&f.data("ui-tabs-aria-controls",l),f.attr({"aria-controls":i.substring(1),"aria-labelledby":a}),o.attr("aria-labelledby",a)}),this.panels.addClass("ui-tabs-panel ui-widget-content ui-corner-bottom").attr("role","tabpanel")},_getList:function(){return this.element.find("ol,ul").eq(0)},_createPanel:function(t){return e("
    ").attr("id",t).addClass("ui-tabs-panel ui-widget-content ui-corner-bottom").data("ui-tabs-destroy",!0)},_setupDisabled:function(t){e.isArray(t)&&(t.length?t.length===this.anchors.length&&(t=!0):t=!1);for(var n=0,r;r=this.tabs[n];n++)t===!0||e.inArray(n,t)!==-1?e(r).addClass("ui-state-disabled").attr("aria-disabled","true"):e(r).removeClass("ui-state-disabled").removeAttr("aria-disabled");this.options.disabled=t},_setupEvents:function(t){var n={click:function(e){e.preventDefault()}};t&&e.each(t.split(" "),function(e,t){n[t]="_eventHandler"}),this._off(this.anchors.add(this.tabs).add(this.panels)),this._on(this.anchors,n),this._on(this.tabs,{keydown:"_tabKeydown"}),this._on(this.panels,{keydown:"_panelKeydown"}),this._focusable(this.tabs),this._hoverable(this.tabs)},_setupHeightStyle:function(t){var n,r,i=this.element.parent();t==="fill"?(e.support.minHeight||(r=i.css("overflow"),i.css("overflow","hidden")),n=i.height(),this.element.siblings(":visible").each(function(){var t=e(this),r=t.css("position");if(r==="absolute"||r==="fixed")return;n-=t.outerHeight(!0)}),r&&i.css("overflow",r),this.element.children().not(this.panels).each(function(){n-=e(this).outerHeight(!0)}),this.panels.each(function(){e(this).height(Math.max(0,n-e(this).innerHeight()+e(this).height()))}).css("overflow","auto")):t==="auto"&&(n=0,this.panels.each(function(){n=Math.max(n,e(this).height("").height())}).height(n))},_eventHandler:function(t){var n=this.options,r=this.active,i=e(t.currentTarget),s=i.closest("li"),o=s[0]===r[0],u=o&&n.collapsible,a=u?e():this._getPanelForTab(s),f=r.length?this._getPanelForTab(r):e(),l={oldTab:r,oldPanel:f,newTab:u?e():s,newPanel:a};t.preventDefault();if(s.hasClass("ui-state-disabled")||s.hasClass("ui-tabs-loading")||this.running||o&&!n.collapsible||this._trigger("beforeActivate",t,l)===!1)return;n.active=u?!1:this.tabs.index(s),this.active=o?e():s,this.xhr&&this.xhr.abort(),!f.length&&!a.length&&e.error("jQuery UI Tabs: Mismatching fragment identifier."),a.length&&this.load(this.tabs.index(s),t),this._toggle(t,l)},_toggle:function(t,n){function o(){r.running=!1,r._trigger("activate",t,n)}function u(){n.newTab.closest("li").addClass("ui-tabs-active ui-state-active"),i.length&&r.options.show?r._show(i,r.options.show,o):(i.show(),o())}var r=this,i=n.newPanel,s=n.oldPanel;this.running=!0,s.length&&this.options.hide?this._hide(s,this.options.hide,function(){n.oldTab.closest("li").removeClass("ui-tabs-active ui-state-active"),u()}):(n.oldTab.closest("li").removeClass("ui-tabs-active ui-state-active"),s.hide(),u()),s.attr({"aria-expanded":"false","aria-hidden":"true"}),n.oldTab.attr("aria-selected","false"),i.length&&s.length?n.oldTab.attr("tabIndex",-1):i.length&&this.tabs.filter(function(){return e(this).attr("tabIndex")===0}).attr("tabIndex",-1),i.attr({"aria-expanded":"true","aria-hidden":"false"}),n.newTab.attr({"aria-selected":"true",tabIndex:0})},_activate:function(t){var n,r=this._findActive(t);if(r[0]===this.active[0])return;r.length||(r=this.active),n=r.find(".ui-tabs-anchor")[0],this._eventHandler({target:n,currentTarget:n,preventDefault:e.noop})},_findActive:function(t){return t===!1?e():this.tabs.eq(t)},_getIndex:function(e){return typeof e=="string"&&(e=this.anchors.index(this.anchors.filter("[href$='"+e+"']"))),e},_destroy:function(){this.xhr&&this.xhr.abort(),this.element.removeClass("ui-tabs ui-widget ui-widget-content ui-corner-all ui-tabs-collapsible"),this.tablist.removeClass("ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all").removeAttr("role"),this.anchors.removeClass("ui-tabs-anchor").removeAttr("role").removeAttr("tabIndex").removeData("href.tabs").removeData("load.tabs").removeUniqueId(),this.tabs.add(this.panels).each(function(){e.data(this,"ui-tabs-destroy")?e(this).remove():e(this).removeClass("ui-state-default ui-state-active ui-state-disabled ui-corner-top ui-corner-bottom ui-widget-content ui-tabs-active ui-tabs-panel").removeAttr("tabIndex").removeAttr("aria-live").removeAttr("aria-busy").removeAttr("aria-selected").removeAttr("aria-labelledby").removeAttr("aria-hidden").removeAttr("aria-expanded").removeAttr("role")}),this.tabs.each(function(){var t=e(this),n=t.data("ui-tabs-aria-controls");n?t.attr("aria-controls",n):t.removeAttr("aria-controls")}),this.panels.show(),this.options.heightStyle!=="content"&&this.panels.css("height","")},enable:function(n){var r=this.options.disabled;if(r===!1)return;n===t?r=!1:(n=this._getIndex(n),e.isArray(r)?r=e.map(r,function(e){return e!==n?e:null}):r=e.map(this.tabs,function(e,t){return t!==n?t:null})),this._setupDisabled(r)},disable:function(n){var r=this.options.disabled;if(r===!0)return;if(n===t)r=!0;else{n=this._getIndex(n);if(e.inArray(n,r)!==-1)return;e.isArray(r)?r=e.merge([n],r).sort():r=[n]}this._setupDisabled(r)},load:function(t,n){t=this._getIndex(t);var r=this,i=this.tabs.eq(t),o=i.find(".ui-tabs-anchor"),u=this._getPanelForTab(i),a={tab:i,panel:u};if(s(o[0]))return;this.xhr=e.ajax(this._ajaxSettings(o,n,a)),this.xhr&&this.xhr.statusText!=="canceled"&&(i.addClass("ui-tabs-loading"),u.attr("aria-busy","true"),this.xhr.success(function(e){setTimeout(function(){u.html(e),r._trigger("load",n,a)},1)}).complete(function(e,t){setTimeout(function(){t==="abort"&&r.panels.stop(!1,!0),i.removeClass("ui-tabs-loading"),u.removeAttr("aria-busy"),e===r.xhr&&delete r.xhr},1)}))},_ajaxSettings:function(t,n,r){var i=this;return{url:t.attr("href"),beforeSend:function(t,s){return i._trigger("beforeLoad",n,e.extend({jqXHR:t,ajaxSettings:s},r))}}},_getPanelForTab:function(t){var n=e(t).attr("aria-controls");return this.element.find(this._sanitizeSelector("#"+n))}}),e.uiBackCompat!==!1&&(e.ui.tabs.prototype._ui=function(e,t){return{tab:e,panel:t,index:this.anchors.index(e)}},e.widget("ui.tabs",e.ui.tabs,{url:function(e,t){this.anchors.eq(e).attr("href",t)}}),e.widget("ui.tabs",e.ui.tabs,{options:{ajaxOptions:null,cache:!1},_create:function(){this._super();var t=this;this._on({tabsbeforeload:function(n,r){if(e.data(r.tab[0],"cache.tabs")){n.preventDefault();return}r.jqXHR.success(function(){t.options.cache&&e.data(r.tab[0],"cache.tabs",!0)})}})},_ajaxSettings:function(t,n,r){var i=this.options.ajaxOptions;return e.extend({},i,{error:function(e,t){try{i.error(e,t,r.tab.closest("li").index(),r.tab[0])}catch(n){}}},this._superApply(arguments))},_setOption:function(e,t){e==="cache"&&t===!1&&this.anchors.removeData("cache.tabs"),this._super(e,t)},_destroy:function(){this.anchors.removeData("cache.tabs"),this._super()},url:function(e){this.anchors.eq(e).removeData("cache.tabs"),this._superApply(arguments)}}),e.widget("ui.tabs",e.ui.tabs,{abort:function(){this.xhr&&this.xhr.abort()}}),e.widget("ui.tabs",e.ui.tabs,{options:{spinner:"Loading…"},_create:function(){this._super(),this._on({tabsbeforeload:function(e,t){if(e.target!==this.element[0]||!this.options.spinner)return;var n=t.tab.find("span"),r=n.html();n.html(this.options.spinner),t.jqXHR.complete(function(){n.html(r)})}})}}),e.widget("ui.tabs",e.ui.tabs,{options:{enable:null,disable:null},enable:function(t){var n=this.options,r;if(t&&n.disabled===!0||e.isArray(n.disabled)&&e.inArray(t,n.disabled)!==-1)r=!0;this._superApply(arguments),r&&this._trigger("enable",null,this._ui(this.anchors[t],this.panels[t]))},disable:function(t){var n=this.options,r;if(t&&n.disabled===!1||e.isArray(n.disabled)&&e.inArray(t,n.disabled)===-1)r=!0;this._superApply(arguments),r&&this._trigger("disable",null,this._ui(this.anchors[t],this.panels[t]))}}),e.widget("ui.tabs",e.ui.tabs,{options:{add:null,remove:null,tabTemplate:"
  • #{label}
  • "},add:function(n,r,i){i===t&&(i=this.anchors.length);var s,o,u=this.options,a=e(u.tabTemplate.replace(/#\{href\}/g,n).replace(/#\{label\}/g,r)),f=n.indexOf("#")?this._tabId(a):n.replace("#","");return a.addClass("ui-state-default ui-corner-top").data("ui-tabs-destroy",!0),a.attr("aria-controls",f),s=i>=this.tabs.length,o=this.element.find("#"+f),o.length||(o=this._createPanel(f),s?i>0?o.insertAfter(this.panels.eq(-1)):o.appendTo(this.element):o.insertBefore(this.panels[i])),o.addClass("ui-tabs-panel ui-widget-content ui-corner-bottom").hide(),s?a.appendTo(this.tablist):a.insertBefore(this.tabs[i]),u.disabled=e.map(u.disabled,function(e){return e>=i?++e:e}),this.refresh(),this.tabs.length===1&&u.active===!1&&this.option("active",0),this._trigger("add",null,this._ui(this.anchors[i],this.panels[i])),this},remove:function(t){t=this._getIndex(t);var n=this.options,r=this.tabs.eq(t).remove(),i=this._getPanelForTab(r).remove();return r.hasClass("ui-tabs-active")&&this.anchors.length>2&&this._activate(t+(t+1=t?--e:e}),this.refresh(),this._trigger("remove",null,this._ui(r.find("a")[0],i[0])),this}}),e.widget("ui.tabs",e.ui.tabs,{length:function(){return this.anchors.length}}),e.widget("ui.tabs",e.ui.tabs,{options:{idPrefix:"ui-tabs-"},_tabId:function(t){var n=t.is("li")?t.find("a[href]"):t;return n=n[0],e(n).closest("li").attr("aria-controls")||n.title&&n.title.replace(/\s/g,"_").replace(/[^\w\u00c0-\uFFFF\-]/g,"")||this.options.idPrefix+i()}}),e.widget("ui.tabs",e.ui.tabs,{options:{panelTemplate:"
    "},_createPanel:function(t){return e(this.options.panelTemplate).attr("id",t).addClass("ui-tabs-panel ui-widget-content ui-corner-bottom").data("ui-tabs-destroy",!0)}}),e.widget("ui.tabs",e.ui.tabs,{_create:function(){var e=this.options;e.active===null&&e.selected!==t&&(e.active=e.selected===-1?!1:e.selected),this._super(),e.selected=e.active,e.selected===!1&&(e.selected=-1)},_setOption:function(e,t){if(e!=="selected")return this._super(e,t);var n=this.options;this._super("active",t===-1?!1:t),n.selected=n.active,n.selected===!1&&(n.selected=-1)},_eventHandler:function(){this._superApply(arguments),this.options.selected=this.options.active,this.options.selected===!1&&(this.options.selected=-1)}}),e.widget("ui.tabs",e.ui.tabs,{options:{show:null,select:null},_create:function(){this._super(),this.options.active!==!1&&this._trigger("show",null,this._ui(this.active.find(".ui-tabs-anchor")[0],this._getPanelForTab(this.active)[0]))},_trigger:function(e,t,n){var r,i,s=this._superApply(arguments);return s?(e==="beforeActivate"?(r=n.newTab.length?n.newTab:n.oldTab,i=n.newPanel.length?n.newPanel:n.oldPanel,s=this._super("select",t,{tab:r.find(".ui-tabs-anchor")[0],panel:i[0],index:r.closest("li").index()})):e==="activate"&&n.newTab.length&&(s=this._super("show",t,{tab:n.newTab.find(".ui-tabs-anchor")[0],panel:n.newPanel[0],index:n.newTab.closest("li").index()})),s):!1}}),e.widget("ui.tabs",e.ui.tabs,{select:function(e){e=this._getIndex(e);if(e===-1){if(!this.options.collapsible||this.options.selected===-1)return;e=this.options.selected}this.anchors.eq(e).trigger(this.options.event+this.eventNamespace)}}),function(){var t=0;e.widget("ui.tabs",e.ui.tabs,{options:{cookie:null},_create:function(){var e=this.options,t;e.active==null&&e.cookie&&(t=parseInt(this._cookie(),10),t===-1&&(t=!1),e.active=t),this._super()},_cookie:function(n){var r=[this.cookie||(this.cookie=this.options.cookie.name||"ui-tabs-"+ ++t)];return arguments.length&&(r.push(n===!1?-1:n),r.push(this.options.cookie)),e.cookie.apply(null,r)},_refresh:function(){this._super(),this.options.cookie&&this._cookie(this.options.active,this.options.cookie)},_eventHandler:function(){this._superApply(arguments),this.options.cookie&&this._cookie(this.options.active,this.options.cookie)},_destroy:function(){this._super(),this.options.cookie&&this._cookie(null,this.options.cookie)}})}(),e.widget("ui.tabs",e.ui.tabs,{_trigger:function(t,n,r){var i=e.extend({},r);return t==="load"&&(i.panel=i.panel[0],i.tab=i.tab.find(".ui-tabs-anchor")[0]),this._super(t,n,i)}}),e.widget("ui.tabs",e.ui.tabs,{options:{fx:null},_getFx:function(){var t,n,r=this.options.fx;return r&&(e.isArray(r)?(t=r[0],n=r[1]):t=n=r),r?{show:n,hide:t}:null},_toggle:function(e,t){function o(){n.running=!1,n._trigger("activate",e,t)}function u(){t.newTab.closest("li").addClass("ui-tabs-active ui-state-active"),r.length&&s.show?r.animate(s.show,s.show.duration,function(){o()}):(r.show(),o())}var n=this,r=t.newPanel,i=t.oldPanel,s=this._getFx();if(!s)return this._super(e,t);n.running=!0,i.length&&s.hide?i.animate(s.hide,s.hide.duration,function(){t.oldTab.closest("li").removeClass("ui-tabs-active ui-state-active"),u()}):(t.oldTab.closest("li").removeClass("ui-tabs-active ui-state-active"),i.hide(),u())}}))})(jQuery); \ No newline at end of file diff --git a/wp-includes/js/jquery/ui/jquery.ui.tooltip.min.js b/wp-includes/js/jquery/ui/jquery.ui.tooltip.min.js new file mode 100644 index 00000000..5077d911 --- /dev/null +++ b/wp-includes/js/jquery/ui/jquery.ui.tooltip.min.js @@ -0,0 +1,5 @@ +/*! jQuery UI - v1.9.2 - 2012-11-23 +* http://jqueryui.com +* Includes: jquery.ui.tooltip.js +* Copyright 2012 jQuery Foundation and other contributors; Licensed MIT */ +(function(e){function n(t,n){var r=(t.attr("aria-describedby")||"").split(/\s+/);r.push(n),t.data("ui-tooltip-id",n).attr("aria-describedby",e.trim(r.join(" ")))}function r(t){var n=t.data("ui-tooltip-id"),r=(t.attr("aria-describedby")||"").split(/\s+/),i=e.inArray(n,r);i!==-1&&r.splice(i,1),t.removeData("ui-tooltip-id"),r=e.trim(r.join(" ")),r?t.attr("aria-describedby",r):t.removeAttr("aria-describedby")}var t=0;e.widget("ui.tooltip",{version:"1.9.2",options:{content:function(){return e(this).attr("title")},hide:!0,items:"[title]:not([disabled])",position:{my:"left top+15",at:"left bottom",collision:"flipfit flip"},show:!0,tooltipClass:null,track:!1,close:null,open:null},_create:function(){this._on({mouseover:"open",focusin:"open"}),this.tooltips={},this.parents={},this.options.disabled&&this._disable()},_setOption:function(t,n){var r=this;if(t==="disabled"){this[n?"_disable":"_enable"](),this.options[t]=n;return}this._super(t,n),t==="content"&&e.each(this.tooltips,function(e,t){r._updateContent(t)})},_disable:function(){var t=this;e.each(this.tooltips,function(n,r){var i=e.Event("blur");i.target=i.currentTarget=r[0],t.close(i,!0)}),this.element.find(this.options.items).andSelf().each(function(){var t=e(this);t.is("[title]")&&t.data("ui-tooltip-title",t.attr("title")).attr("title","")})},_enable:function(){this.element.find(this.options.items).andSelf().each(function(){var t=e(this);t.data("ui-tooltip-title")&&t.attr("title",t.data("ui-tooltip-title"))})},open:function(t){var n=this,r=e(t?t.target:this.element).closest(this.options.items);if(!r.length||r.data("ui-tooltip-id"))return;r.attr("title")&&r.data("ui-tooltip-title",r.attr("title")),r.data("ui-tooltip-open",!0),t&&t.type==="mouseover"&&r.parents().each(function(){var t=e(this),r;t.data("ui-tooltip-open")&&(r=e.Event("blur"),r.target=r.currentTarget=this,n.close(r,!0)),t.attr("title")&&(t.uniqueId(),n.parents[this.id]={element:this,title:t.attr("title")},t.attr("title",""))}),this._updateContent(r,t)},_updateContent:function(e,t){var n,r=this.options.content,i=this,s=t?t.type:null;if(typeof r=="string")return this._open(t,e,r);n=r.call(e[0],function(n){if(!e.data("ui-tooltip-open"))return;i._delay(function(){t&&(t.type=s),this._open(t,e,n)})}),n&&this._open(t,e,n)},_open:function(t,r,i){function f(e){a.of=e;if(s.is(":hidden"))return;s.position(a)}var s,o,u,a=e.extend({},this.options.position);if(!i)return;s=this._find(r);if(s.length){s.find(".ui-tooltip-content").html(i);return}r.is("[title]")&&(t&&t.type==="mouseover"?r.attr("title",""):r.removeAttr("title")),s=this._tooltip(r),n(r,s.attr("id")),s.find(".ui-tooltip-content").html(i),this.options.track&&t&&/^mouse/.test(t.type)?(this._on(this.document,{mousemove:f}),f(t)):s.position(e.extend({of:r},this.options.position)),s.hide(),this._show(s,this.options.show),this.options.show&&this.options.show.delay&&(u=setInterval(function(){s.is(":visible")&&(f(a.of),clearInterval(u))},e.fx.interval)),this._trigger("open",t,{tooltip:s}),o={keyup:function(t){if(t.keyCode===e.ui.keyCode.ESCAPE){var n=e.Event(t);n.currentTarget=r[0],this.close(n,!0)}},remove:function(){this._removeTooltip(s)}};if(!t||t.type==="mouseover")o.mouseleave="close";if(!t||t.type==="focusin")o.focusout="close";this._on(!0,r,o)},close:function(t){var n=this,i=e(t?t.currentTarget:this.element),s=this._find(i);if(this.closing)return;i.data("ui-tooltip-title")&&i.attr("title",i.data("ui-tooltip-title")),r(i),s.stop(!0),this._hide(s,this.options.hide,function(){n._removeTooltip(e(this))}),i.removeData("ui-tooltip-open"),this._off(i,"mouseleave focusout keyup"),i[0]!==this.element[0]&&this._off(i,"remove"),this._off(this.document,"mousemove"),t&&t.type==="mouseleave"&&e.each(this.parents,function(t,r){e(r.element).attr("title",r.title),delete n.parents[t]}),this.closing=!0,this._trigger("close",t,{tooltip:s}),this.closing=!1},_tooltip:function(n){var r="ui-tooltip-"+t++,i=e("
    ").attr({id:r,role:"tooltip"}).addClass("ui-tooltip ui-widget ui-corner-all ui-widget-content "+(this.options.tooltipClass||""));return e("
    ").addClass("ui-tooltip-content").appendTo(i),i.appendTo(this.document[0].body),e.fn.bgiframe&&i.bgiframe(),this.tooltips[r]=n,i},_find:function(t){var n=t.data("ui-tooltip-id");return n?e("#"+n):e()},_removeTooltip:function(e){e.remove(),delete this.tooltips[e.attr("id")]},_destroy:function(){var t=this;e.each(this.tooltips,function(n,r){var i=e.Event("blur");i.target=i.currentTarget=r[0],t.close(i,!0),e("#"+n).remove(),r.data("ui-tooltip-title")&&(r.attr("title",r.data("ui-tooltip-title")),r.removeData("ui-tooltip-title"))})}})})(jQuery); \ No newline at end of file diff --git a/wp-includes/js/jquery/ui/jquery.ui.widget.min.js b/wp-includes/js/jquery/ui/jquery.ui.widget.min.js index 32362074..865bc98d 100644 --- a/wp-includes/js/jquery/ui/jquery.ui.widget.min.js +++ b/wp-includes/js/jquery/ui/jquery.ui.widget.min.js @@ -1,5 +1,5 @@ -/*! jQuery UI - v1.8.20 - 2012-04-30 -* https://github.com/jquery/jquery-ui +/*! jQuery UI - v1.9.2 - 2012-11-23 +* http://jqueryui.com * Includes: jquery.ui.widget.js -* Copyright (c) 2012 AUTHORS.txt; Licensed MIT, GPL */ -(function(a,b){if(a.cleanData){var c=a.cleanData;a.cleanData=function(b){for(var d=0,e;(e=b[d])!=null;d++)try{a(e).triggerHandler("remove")}catch(f){}c(b)}}else{var d=a.fn.remove;a.fn.remove=function(b,c){return this.each(function(){return c||(!b||a.filter(b,[this]).length)&&a("*",this).add([this]).each(function(){try{a(this).triggerHandler("remove")}catch(b){}}),d.call(a(this),b,c)})}}a.widget=function(b,c,d){var e=b.split(".")[0],f;b=b.split(".")[1],f=e+"-"+b,d||(d=c,c=a.Widget),a.expr[":"][f]=function(c){return!!a.data(c,b)},a[e]=a[e]||{},a[e][b]=function(a,b){arguments.length&&this._createWidget(a,b)};var g=new c;g.options=a.extend(!0,{},g.options),a[e][b].prototype=a.extend(!0,g,{namespace:e,widgetName:b,widgetEventPrefix:a[e][b].prototype.widgetEventPrefix||b,widgetBaseClass:f},d),a.widget.bridge(b,a[e][b])},a.widget.bridge=function(c,d){a.fn[c]=function(e){var f=typeof e=="string",g=Array.prototype.slice.call(arguments,1),h=this;return e=!f&&g.length?a.extend.apply(null,[!0,e].concat(g)):e,f&&e.charAt(0)==="_"?h:(f?this.each(function(){var d=a.data(this,c),f=d&&a.isFunction(d[e])?d[e].apply(d,g):d;if(f!==d&&f!==b)return h=f,!1}):this.each(function(){var b=a.data(this,c);b?b.option(e||{})._init():a.data(this,c,new d(e,this))}),h)}},a.Widget=function(a,b){arguments.length&&this._createWidget(a,b)},a.Widget.prototype={widgetName:"widget",widgetEventPrefix:"",options:{disabled:!1},_createWidget:function(b,c){a.data(c,this.widgetName,this),this.element=a(c),this.options=a.extend(!0,{},this.options,this._getCreateOptions(),b);var d=this;this.element.bind("remove."+this.widgetName,function(){d.destroy()}),this._create(),this._trigger("create"),this._init()},_getCreateOptions:function(){return a.metadata&&a.metadata.get(this.element[0])[this.widgetName]},_create:function(){},_init:function(){},destroy:function(){this.element.unbind("."+this.widgetName).removeData(this.widgetName),this.widget().unbind("."+this.widgetName).removeAttr("aria-disabled").removeClass(this.widgetBaseClass+"-disabled "+"ui-state-disabled")},widget:function(){return this.element},option:function(c,d){var e=c;if(arguments.length===0)return a.extend({},this.options);if(typeof c=="string"){if(d===b)return this.options[c];e={},e[c]=d}return this._setOptions(e),this},_setOptions:function(b){var c=this;return a.each(b,function(a,b){c._setOption(a,b)}),this},_setOption:function(a,b){return this.options[a]=b,a==="disabled"&&this.widget()[b?"addClass":"removeClass"](this.widgetBaseClass+"-disabled"+" "+"ui-state-disabled").attr("aria-disabled",b),this},enable:function(){return this._setOption("disabled",!1)},disable:function(){return this._setOption("disabled",!0)},_trigger:function(b,c,d){var e,f,g=this.options[b];d=d||{},c=a.Event(c),c.type=(b===this.widgetEventPrefix?b:this.widgetEventPrefix+b).toLowerCase(),c.target=this.element[0],f=c.originalEvent;if(f)for(e in f)e in c||(c[e]=f[e]);return this.element.trigger(c,d),!(a.isFunction(g)&&g.call(this.element[0],c,d)===!1||c.isDefaultPrevented())}}})(jQuery); \ No newline at end of file +* Copyright 2012 jQuery Foundation and other contributors; Licensed MIT */ +(function(e,t){var n=0,r=Array.prototype.slice,i=e.cleanData;e.cleanData=function(t){for(var n=0,r;(r=t[n])!=null;n++)try{e(r).triggerHandler("remove")}catch(s){}i(t)},e.widget=function(t,n,r){var i,s,o,u,a=t.split(".")[0];t=t.split(".")[1],i=a+"-"+t,r||(r=n,n=e.Widget),e.expr[":"][i.toLowerCase()]=function(t){return!!e.data(t,i)},e[a]=e[a]||{},s=e[a][t],o=e[a][t]=function(e,t){if(!this._createWidget)return new o(e,t);arguments.length&&this._createWidget(e,t)},e.extend(o,s,{version:r.version,_proto:e.extend({},r),_childConstructors:[]}),u=new n,u.options=e.widget.extend({},u.options),e.each(r,function(t,i){e.isFunction(i)&&(r[t]=function(){var e=function(){return n.prototype[t].apply(this,arguments)},r=function(e){return n.prototype[t].apply(this,e)};return function(){var t=this._super,n=this._superApply,s;return this._super=e,this._superApply=r,s=i.apply(this,arguments),this._super=t,this._superApply=n,s}}())}),o.prototype=e.widget.extend(u,{widgetEventPrefix:s?u.widgetEventPrefix:t},r,{constructor:o,namespace:a,widgetName:t,widgetBaseClass:i,widgetFullName:i}),s?(e.each(s._childConstructors,function(t,n){var r=n.prototype;e.widget(r.namespace+"."+r.widgetName,o,n._proto)}),delete s._childConstructors):n._childConstructors.push(o),e.widget.bridge(t,o)},e.widget.extend=function(n){var i=r.call(arguments,1),s=0,o=i.length,u,a;for(;s",options:{disabled:!1,create:null},_createWidget:function(t,r){r=e(r||this.defaultElement||this)[0],this.element=e(r),this.uuid=n++,this.eventNamespace="."+this.widgetName+this.uuid,this.options=e.widget.extend({},this.options,this._getCreateOptions(),t),this.bindings=e(),this.hoverable=e(),this.focusable=e(),r!==this&&(e.data(r,this.widgetName,this),e.data(r,this.widgetFullName,this),this._on(!0,this.element,{remove:function(e){e.target===r&&this.destroy()}}),this.document=e(r.style?r.ownerDocument:r.document||r),this.window=e(this.document[0].defaultView||this.document[0].parentWindow)),this._create(),this._trigger("create",null,this._getCreateEventData()),this._init()},_getCreateOptions:e.noop,_getCreateEventData:e.noop,_create:e.noop,_init:e.noop,destroy:function(){this._destroy(),this.element.unbind(this.eventNamespace).removeData(this.widgetName).removeData(this.widgetFullName).removeData(e.camelCase(this.widgetFullName)),this.widget().unbind(this.eventNamespace).removeAttr("aria-disabled").removeClass(this.widgetFullName+"-disabled "+"ui-state-disabled"),this.bindings.unbind(this.eventNamespace),this.hoverable.removeClass("ui-state-hover"),this.focusable.removeClass("ui-state-focus")},_destroy:e.noop,widget:function(){return this.element},option:function(n,r){var i=n,s,o,u;if(arguments.length===0)return e.widget.extend({},this.options);if(typeof n=="string"){i={},s=n.split("."),n=s.shift();if(s.length){o=i[n]=e.widget.extend({},this.options[n]);for(u=0;u'); + }); + }, + + // ### toText( content ) + // Scans an HTML `content` string and replaces any view instances with + // their respective text representations. + toText: function( content ) { + return content.replace( /<(?:div|span)[^>]+data-wp-view="([^"]+)"[^>]*>.*?]+data-wp-view-end[^>]*><\/span><\/(?:div|span)>/g, function( match, id ) { + var instance = instances[ id ], + view; + + if ( instance ) + view = wp.mce.view.get( instance.options.viewType ); + + return instance && view ? view.text( instance ) : ''; + }); + }, + + // ### Remove internal TinyMCE attributes. + removeInternalAttrs: function( attrs ) { + var result = {}; + _.each( attrs, function( value, attr ) { + if ( -1 === attr.indexOf('data-mce') ) + result[ attr ] = value; + }); + return result; + }, + + // ### Parse an attribute string and removes internal TinyMCE attributes. + attrs: function( content ) { + return wp.mce.view.removeInternalAttrs( wp.html.attrs( content ) ); + }, + + // ### instance( scope ) + // + // Accepts a MCE view wrapper `node` (i.e. a node with the + // `wp-view-wrap` class). + instance: function( node ) { + var id = $( node ).data('wp-view'); + + if ( id ) + return instances[ id ]; + }, + + // ### Select a view. + // + // Accepts a MCE view wrapper `node` (i.e. a node with the + // `wp-view-wrap` class). + select: function( node ) { + var $node = $(node); + + // Bail if node is already selected. + if ( $node.hasClass('selected') ) + return; + + $node.addClass('selected'); + $( node.firstChild ).trigger('select'); + }, + + // ### Deselect a view. + // + // Accepts a MCE view wrapper `node` (i.e. a node with the + // `wp-view-wrap` class). + deselect: function( node ) { + var $node = $(node); + + // Bail if node is already selected. + if ( ! $node.hasClass('selected') ) + return; + + $node.removeClass('selected'); + $( node.firstChild ).trigger('deselect'); + } + }; + +}(jQuery)); \ No newline at end of file diff --git a/wp-includes/js/mce-view.min.js b/wp-includes/js/mce-view.min.js new file mode 100644 index 00000000..53e236ad --- /dev/null +++ b/wp-includes/js/mce-view.min.js @@ -0,0 +1 @@ +window.wp=window.wp||{};(function(b){var a={},c={};wp.mce=wp.mce||{};wp.mce.view={defaults:{pattern:{view:Backbone.View,text:function(d){return d.options.original},toView:function(e){if(!this.pattern){return}this.pattern.lastIndex=0;var d=this.pattern.exec(e);if(!d){return}return{index:d.index,content:d[0],options:{original:d[0],results:d}}}},shortcode:{view:Backbone.View,text:function(d){return d.options.shortcode.string()},toView:function(e){var d=wp.shortcode.next(this.shortcode,e);if(!d){return}return{index:d.index,content:d.content,options:{shortcode:d.shortcode}}}}},add:function(i,e){var g,d,h,f;if(e.extend){g=wp.mce.view.get(e.extend)}else{if(e.shortcode){g=wp.mce.view.defaults.shortcode}else{g=wp.mce.view.defaults.pattern}}_.defaults(e,g);e.id=i;f={remove:function(){delete c[this.el.id];this.$el.parent().remove();if(d){d.apply(this,arguments)}return this}};if(_.isFunction(e.view)){h=e.view}else{h=g.view;d=e.view.remove;_.defaults(f,e.view)}if(!d&&!h._mceview){d=h.prototype.remove}e.view=h.extend(f,{_mceview:true});a[i]=e},get:function(d){return a[d]},remove:function(d){delete a[d]},toViews:function(e){var d=[{content:e}],f;_.each(a,function(h,g){f=d.slice();d=[];_.each(f,function(k){var j=k.content,i;if(k.processed){d.push(k);return}while(j&&(i=h.toView(j))){if(i.index){d.push({content:j.substring(0,i.index)})}d.push({content:wp.mce.view.toView(g,i.options),processed:true});j=j.slice(i.index+i.content.length)}if(j){d.push({content:j})}})});return _.pluck(d,"content").join("")},toView:function(e,g){var f=wp.mce.view.get(e),d,h;if(!f){return""}d=new f.view(_.extend(g||{},{viewType:e}));h=d.el.id=d.el.id||_.uniqueId("__wpmce-");c[h]=d;d.$wrapper=b();return wp.html.string({tag:"span"===d.tagName?"span":"div",attrs:{"class":"wp-view-wrap wp-view-type-"+e,"data-wp-view":h,contenteditable:false}})},render:function(d){b(".wp-view-wrap",d).each(function(){var f=b(this),e=wp.mce.view.instance(this);if(!e){return}e.$wrapper=f;e.render();e.$el.detach();f.empty().append(e.el).append('')})},toText:function(d){return d.replace(/<(?:div|span)[^>]+data-wp-view="([^"]+)"[^>]*>.*?]+data-wp-view-end[^>]*><\/span><\/(?:div|span)>/g,function(g,h){var e=c[h],f;if(e){f=wp.mce.view.get(e.options.viewType)}return e&&f?f.text(e):""})},removeInternalAttrs:function(e){var d={};_.each(e,function(g,f){if(-1===f.indexOf("data-mce")){d[f]=g}});return d},attrs:function(d){return wp.mce.view.removeInternalAttrs(wp.html.attrs(d))},instance:function(d){var e=b(d).data("wp-view");if(e){return c[e]}},select:function(e){var d=b(e);if(d.hasClass("selected")){return}d.addClass("selected");b(e.firstChild).trigger("select")},deselect:function(e){var d=b(e);if(!d.hasClass("selected")){return}d.removeClass("selected");b(e.firstChild).trigger("deselect")}}}(jQuery)); \ No newline at end of file diff --git a/wp-includes/js/media-editor.js b/wp-includes/js/media-editor.js new file mode 100644 index 00000000..34777677 --- /dev/null +++ b/wp-includes/js/media-editor.js @@ -0,0 +1,646 @@ +// WordPress, TinyMCE, and Media +// ----------------------------- +(function($){ + // Stores the editors' `wp.media.controller.Frame` instances. + var workflows = {}; + + wp.media.string = { + // Joins the `props` and `attachment` objects, + // outputting the proper object format based on the + // attachment's type. + props: function( props, attachment ) { + var link, linkUrl, size, sizes, fallbacks; + + // Final fallbacks run after all processing has been completed. + fallbacks = function( props ) { + // Generate alt fallbacks and strip tags. + if ( 'image' === props.type && ! props.alt ) { + props.alt = props.caption || props.title || ''; + props.alt = props.alt.replace( /<\/?[^>]+>/g, '' ); + } + + return props; + }; + + props = props ? _.clone( props ) : {}; + + if ( attachment && attachment.type ) + props.type = attachment.type; + + if ( 'image' === props.type ) { + props = _.defaults( props || {}, { + align: getUserSetting( 'align', 'none' ), + size: getUserSetting( 'imgsize', 'medium' ), + url: '', + classes: [] + }); + } + + // All attachment-specific settings follow. + if ( ! attachment ) + return fallbacks( props ); + + props.title = props.title || attachment.title; + + link = props.link || getUserSetting( 'urlbutton', 'post' ); + if ( 'file' === link ) + linkUrl = attachment.url; + else if ( 'post' === link ) + linkUrl = attachment.link; + else if ( 'custom' === link ) + linkUrl = props.linkUrl; + props.linkUrl = linkUrl || ''; + + // Format properties for images. + if ( 'image' === attachment.type ) { + props.classes.push( 'wp-image-' + attachment.id ); + + sizes = attachment.sizes; + size = sizes && sizes[ props.size ] ? sizes[ props.size ] : attachment; + + _.extend( props, _.pick( attachment, 'align', 'caption', 'alt' ), { + width: size.width, + height: size.height, + src: size.url, + captionId: 'attachment_' + attachment.id + }); + + // Format properties for non-images. + } else { + props.title = props.title || attachment.filename; + props.rel = props.rel || 'attachment wp-att-' + attachment.id; + } + + return fallbacks( props ); + }, + + link: function( props, attachment ) { + var options; + + props = wp.media.string.props( props, attachment ); + + options = { + tag: 'a', + content: props.title, + attrs: { + href: props.linkUrl + } + }; + + if ( props.rel ) + options.attrs.rel = props.rel; + + return wp.html.string( options ); + }, + + image: function( props, attachment ) { + var img = {}, + options, classes, shortcode, html; + + props = wp.media.string.props( props, attachment ); + classes = props.classes || []; + + img.src = props.url; + _.extend( img, _.pick( props, 'width', 'height', 'alt' ) ); + + // Only assign the align class to the image if we're not printing + // a caption, since the alignment is sent to the shortcode. + if ( props.align && ! props.caption ) + classes.push( 'align' + props.align ); + + if ( props.size ) + classes.push( 'size-' + props.size ); + + img['class'] = _.compact( classes ).join(' '); + + // Generate `img` tag options. + options = { + tag: 'img', + attrs: img, + single: true + }; + + // Generate the `a` element options, if they exist. + if ( props.linkUrl ) { + options = { + tag: 'a', + attrs: { + href: props.linkUrl + }, + content: options + }; + } + + html = wp.html.string( options ); + + // Generate the caption shortcode. + if ( props.caption ) { + shortcode = {}; + + if ( img.width ) + shortcode.width = img.width; + + if ( props.captionId ) + shortcode.id = props.captionId; + + if ( props.align ) + shortcode.align = 'align' + props.align; + + html = wp.shortcode.string({ + tag: 'caption', + attrs: shortcode, + content: html + ' ' + props.caption + }); + } + + return html; + } + }; + + wp.media.gallery = (function() { + var galleries = {}; + + return { + defaults: { + order: 'ASC', + id: wp.media.view.settings.post.id, + itemtag: 'dl', + icontag: 'dt', + captiontag: 'dd', + columns: 3, + size: 'thumbnail', + orderby: 'menu_order ID' + }, + + attachments: function( shortcode ) { + var shortcodeString = shortcode.string(), + result = galleries[ shortcodeString ], + attrs, args, query, others; + + delete galleries[ shortcodeString ]; + + if ( result ) + return result; + + // Fill the default shortcode attributes. + attrs = _.defaults( shortcode.attrs.named, wp.media.gallery.defaults ); + args = _.pick( attrs, 'orderby', 'order' ); + + args.type = 'image'; + args.perPage = -1; + + // Mark the `orderby` override attribute. + if ( 'rand' === attrs.orderby ) + attrs._orderbyRandom = true; + + // Map the `orderby` attribute to the corresponding model property. + if ( ! attrs.orderby || /^menu_order(?: ID)?$/i.test( attrs.orderby ) ) + args.orderby = 'menuOrder'; + + // Map the `ids` param to the correct query args. + if ( attrs.ids ) { + args.post__in = attrs.ids.split(','); + args.orderby = 'post__in'; + } else if ( attrs.include ) { + args.post__in = attrs.include.split(','); + } + + if ( attrs.exclude ) + args.post__not_in = attrs.exclude.split(','); + + if ( ! args.post__in ) + args.uploadedTo = attrs.id; + + // Collect the attributes that were not included in `args`. + others = _.omit( attrs, 'id', 'ids', 'include', 'exclude', 'orderby', 'order' ); + + query = wp.media.query( args ); + query.gallery = new Backbone.Model( others ); + return query; + }, + + shortcode: function( attachments ) { + var props = attachments.props.toJSON(), + attrs = _.pick( props, 'orderby', 'order' ), + shortcode, clone; + + if ( attachments.gallery ) + _.extend( attrs, attachments.gallery.toJSON() ); + + // Convert all gallery shortcodes to use the `ids` property. + // Ignore `post__in` and `post__not_in`; the attachments in + // the collection will already reflect those properties. + attrs.ids = attachments.pluck('id'); + + // Copy the `uploadedTo` post ID. + if ( props.uploadedTo ) + attrs.id = props.uploadedTo; + + // Check if the gallery is randomly ordered. + if ( attrs._orderbyRandom ) + attrs.orderby = 'rand'; + delete attrs._orderbyRandom; + + // If the `ids` attribute is set and `orderby` attribute + // is the default value, clear it for cleaner output. + if ( attrs.ids && 'post__in' === attrs.orderby ) + delete attrs.orderby; + + // Remove default attributes from the shortcode. + _.each( wp.media.gallery.defaults, function( value, key ) { + if ( value === attrs[ key ] ) + delete attrs[ key ]; + }); + + shortcode = new wp.shortcode({ + tag: 'gallery', + attrs: attrs, + type: 'single' + }); + + // Use a cloned version of the gallery. + clone = new wp.media.model.Attachments( attachments.models, { + props: props + }); + clone.gallery = attachments.gallery; + galleries[ shortcode.string() ] = clone; + + return shortcode; + }, + + edit: function( content ) { + var shortcode = wp.shortcode.next( 'gallery', content ), + defaultPostId = wp.media.gallery.defaults.id, + attachments, selection; + + // Bail if we didn't match the shortcode or all of the content. + if ( ! shortcode || shortcode.content !== content ) + return; + + // Ignore the rest of the match object. + shortcode = shortcode.shortcode; + + if ( _.isUndefined( shortcode.get('id') ) && ! _.isUndefined( defaultPostId ) ) + shortcode.set( 'id', defaultPostId ); + + attachments = wp.media.gallery.attachments( shortcode ); + + selection = new wp.media.model.Selection( attachments.models, { + props: attachments.props.toJSON(), + multiple: true + }); + + selection.gallery = attachments.gallery; + + // Fetch the query's attachments, and then break ties from the + // query to allow for sorting. + selection.more().done( function() { + // Break ties with the query. + selection.props.set({ query: false }); + selection.unmirror(); + selection.props.unset('orderby'); + }); + + // Destroy the previous gallery frame. + if ( this.frame ) + this.frame.dispose(); + + // Store the current gallery frame. + this.frame = wp.media({ + frame: 'post', + state: 'gallery-edit', + title: wp.media.view.l10n.editGalleryTitle, + editing: true, + multiple: true, + selection: selection + }).open(); + + return this.frame; + } + }; + }()); + + wp.media.featuredImage = { + get: function() { + return wp.media.view.settings.post.featuredImageId; + }, + + set: function( id ) { + var settings = wp.media.view.settings; + + settings.post.featuredImageId = id; + + wp.media.post( 'set-post-thumbnail', { + json: true, + post_id: settings.post.id, + thumbnail_id: settings.post.featuredImageId, + _wpnonce: settings.post.nonce + }).done( function( html ) { + $( '.inside', '#postimagediv' ).html( html ); + }); + }, + + frame: function() { + if ( this._frame ) + return this._frame; + + this._frame = wp.media({ + state: 'featured-image', + states: [ new wp.media.controller.FeaturedImage() ] + }); + + this._frame.on( 'toolbar:create:featured-image', function( toolbar ) { + this.createSelectToolbar( toolbar, { + text: wp.media.view.l10n.setFeaturedImage + }); + }, this._frame ); + + this._frame.state('featured-image').on( 'select', this.select ); + return this._frame; + }, + + select: function() { + var settings = wp.media.view.settings, + selection = this.get('selection').single(); + + if ( ! settings.post.featuredImageId ) + return; + + wp.media.featuredImage.set( selection ? selection.id : -1 ); + }, + + init: function() { + // Open the content media manager to the 'featured image' tab when + // the post thumbnail is clicked. + $('#postimagediv').on( 'click', '#set-post-thumbnail', function( event ) { + event.preventDefault(); + // Stop propagation to prevent thickbox from activating. + event.stopPropagation(); + + wp.media.featuredImage.frame().open(); + + // Update the featured image id when the 'remove' link is clicked. + }).on( 'click', '#remove-post-thumbnail', function() { + wp.media.view.settings.post.featuredImageId = -1; + }); + } + }; + + $( wp.media.featuredImage.init ); + + wp.media.editor = { + insert: function( h ) { + var mce = typeof(tinymce) != 'undefined', + qt = typeof(QTags) != 'undefined', + wpActiveEditor = window.wpActiveEditor, + ed; + + // Delegate to the global `send_to_editor` if it exists. + // This attempts to play nice with any themes/plugins that have + // overridden the insert functionality. + if ( window.send_to_editor ) + return window.send_to_editor.apply( this, arguments ); + + if ( ! wpActiveEditor ) { + if ( mce && tinymce.activeEditor ) { + ed = tinymce.activeEditor; + wpActiveEditor = window.wpActiveEditor = ed.id; + } else if ( !qt ) { + return false; + } + } else if ( mce ) { + if ( tinymce.activeEditor && (tinymce.activeEditor.id == 'mce_fullscreen' || tinymce.activeEditor.id == 'wp_mce_fullscreen') ) + ed = tinymce.activeEditor; + else + ed = tinymce.get(wpActiveEditor); + } + + if ( ed && !ed.isHidden() ) { + // restore caret position on IE + if ( tinymce.isIE && ed.windowManager.insertimagebookmark ) + ed.selection.moveToBookmark(ed.windowManager.insertimagebookmark); + + if ( h.indexOf('[caption') !== -1 ) { + if ( ed.wpSetImgCaption ) + h = ed.wpSetImgCaption(h); + } else if ( h.indexOf('[gallery') !== -1 ) { + if ( ed.plugins.wpgallery ) + h = ed.plugins.wpgallery._do_gallery(h); + } else if ( h.indexOf('[embed') === 0 ) { + if ( ed.plugins.wordpress ) + h = ed.plugins.wordpress._setEmbed(h); + } + + ed.execCommand('mceInsertContent', false, h); + } else if ( qt ) { + QTags.insertContent(h); + } else { + document.getElementById(wpActiveEditor).value += h; + } + + // If the old thickbox remove function exists, call it in case + // a theme/plugin overloaded it. + if ( window.tb_remove ) + try { window.tb_remove(); } catch( e ) {} + }, + + add: function( id, options ) { + var workflow = this.get( id ); + + if ( workflow ) + return workflow; + + workflow = workflows[ id ] = wp.media( _.defaults( options || {}, { + frame: 'post', + state: 'insert', + title: wp.media.view.l10n.addMedia, + multiple: true + } ) ); + + workflow.on( 'insert', function( selection ) { + var state = workflow.state(); + + selection = selection || state.get('selection'); + + if ( ! selection ) + return; + + $.when.apply( $, selection.map( function( attachment ) { + var display = state.display( attachment ).toJSON(); + return this.send.attachment( display, attachment.toJSON() ); + }, this ) ).done( function() { + wp.media.editor.insert( _.toArray( arguments ).join("\n\n") ); + }); + }, this ); + + workflow.state('gallery-edit').on( 'update', function( selection ) { + this.insert( wp.media.gallery.shortcode( selection ).string() ); + }, this ); + + workflow.state('embed').on( 'select', function() { + var state = workflow.state(), + type = state.get('type'), + embed = state.props.toJSON(); + + embed.url = embed.url || ''; + + if ( 'link' === type ) { + _.defaults( embed, { + title: embed.url, + linkUrl: embed.url + }); + + this.send.link( embed ).done( function( resp ) { + wp.media.editor.insert( resp ); + }); + + } else if ( 'image' === type ) { + _.defaults( embed, { + title: embed.url, + linkUrl: '', + align: 'none', + link: 'none' + }); + + if ( 'none' === embed.link ) + embed.linkUrl = ''; + else if ( 'file' === embed.link ) + embed.linkUrl = embed.url; + + this.insert( wp.media.string.image( embed ) ); + } + }, this ); + + workflow.state('featured-image').on( 'select', wp.media.featuredImage.select ); + workflow.setState( workflow.options.state ); + return workflow; + }, + + id: function( id ) { + if ( id ) + return id; + + // If an empty `id` is provided, default to `wpActiveEditor`. + id = wpActiveEditor; + + // If that doesn't work, fall back to `tinymce.activeEditor.id`. + if ( ! id && typeof tinymce !== 'undefined' && tinymce.activeEditor ) + id = tinymce.activeEditor.id; + + // Last but not least, fall back to the empty string. + id = id || ''; + return id; + }, + + get: function( id ) { + id = this.id( id ); + return workflows[ id ]; + }, + + remove: function( id ) { + id = this.id( id ); + delete workflows[ id ]; + }, + + send: { + attachment: function( props, attachment ) { + var caption = attachment.caption, + options, html; + + // If captions are disabled, clear the caption. + if ( ! wp.media.view.settings.captions ) + delete attachment.caption; + + props = wp.media.string.props( props, attachment ); + + options = { + id: attachment.id, + post_content: attachment.description, + post_excerpt: caption + }; + + if ( props.linkUrl ) + options.url = props.linkUrl; + + if ( 'image' === attachment.type ) { + html = wp.media.string.image( props ); + + _.each({ + align: 'align', + size: 'image-size', + alt: 'image_alt' + }, function( option, prop ) { + if ( props[ prop ] ) + options[ option ] = props[ prop ]; + }); + + } else { + html = wp.media.string.link( props ); + options.post_title = props.title; + } + + return wp.media.post( 'send-attachment-to-editor', { + nonce: wp.media.view.settings.nonce.sendToEditor, + attachment: options, + html: html, + post_id: wp.media.view.settings.post.id + }); + }, + + link: function( embed ) { + return wp.media.post( 'send-link-to-editor', { + nonce: wp.media.view.settings.nonce.sendToEditor, + src: embed.linkUrl, + title: embed.title, + html: wp.media.string.link( embed ), + post_id: wp.media.view.settings.post.id + }); + } + }, + + open: function( id ) { + var workflow, editor; + + id = this.id( id ); + + // Save a bookmark of the caret position in IE. + if ( typeof tinymce !== 'undefined' ) { + editor = tinymce.get( id ); + + if ( tinymce.isIE && editor && ! editor.isHidden() ) { + editor.focus(); + editor.windowManager.insertimagebookmark = editor.selection.getBookmark(); + } + } + + workflow = this.get( id ); + + // Initialize the editor's workflow if we haven't yet. + if ( ! workflow ) + workflow = this.add( id ); + + return workflow.open(); + }, + + init: function() { + $(document.body).on( 'click', '.insert-media', function( event ) { + var $this = $(this), + editor = $this.data('editor'); + + event.preventDefault(); + + // Remove focus from the `.insert-media` button. + // Prevents Opera from showing the outline of the button + // above the modal. + // + // See: http://core.trac.wordpress.org/ticket/22445 + $this.blur(); + + wp.media.editor.open( editor ); + }); + } + }; + + _.bindAll( wp.media.editor, 'open' ); + $( wp.media.editor.init ); +}(jQuery)); diff --git a/wp-includes/js/media-editor.min.js b/wp-includes/js/media-editor.min.js new file mode 100644 index 00000000..1598ba29 --- /dev/null +++ b/wp-includes/js/media-editor.min.js @@ -0,0 +1 @@ +(function(b){var a={};wp.media.string={props:function(f,i){var h,c,e,g,d;d=function(j){if("image"===j.type&&!j.alt){j.alt=j.caption||j.title||"";j.alt=j.alt.replace(/<\/?[^>]+>/g,"")}return j};f=f?_.clone(f):{};if(i&&i.type){f.type=i.type}if("image"===f.type){f=_.defaults(f||{},{align:getUserSetting("align","none"),size:getUserSetting("imgsize","medium"),url:"",classes:[]})}if(!i){return d(f)}f.title=f.title||i.title;h=f.link||getUserSetting("urlbutton","post");if("file"===h){c=i.url}else{if("post"===h){c=i.link}else{if("custom"===h){c=f.linkUrl}}}f.linkUrl=c||"";if("image"===i.type){f.classes.push("wp-image-"+i.id);g=i.sizes;e=g&&g[f.size]?g[f.size]:i;_.extend(f,_.pick(i,"align","caption","alt"),{width:e.width,height:e.height,src:e.url,captionId:"attachment_"+i.id})}else{f.title=f.title||i.filename;f.rel=f.rel||"attachment wp-att-"+i.id}return d(f)},link:function(d,e){var c;d=wp.media.string.props(d,e);c={tag:"a",content:d.title,attrs:{href:d.linkUrl}};if(d.rel){c.attrs.rel=d.rel}return wp.html.string(c)},image:function(g,i){var c={},d,f,h,e;g=wp.media.string.props(g,i);f=g.classes||[];c.src=g.url;_.extend(c,_.pick(g,"width","height","alt"));if(g.align&&!g.caption){f.push("align"+g.align)}if(g.size){f.push("size-"+g.size)}c["class"]=_.compact(f).join(" ");d={tag:"img",attrs:c,single:true};if(g.linkUrl){d={tag:"a",attrs:{href:g.linkUrl},content:d}}e=wp.html.string(d);if(g.caption){h={};if(c.width){h.width=c.width}if(g.captionId){h.id=g.captionId}if(g.align){h.align="align"+g.align}e=wp.shortcode.string({tag:"caption",attrs:h,content:e+" "+g.caption})}return e}};wp.media.gallery=(function(){var c={};return{defaults:{order:"ASC",id:wp.media.view.settings.post.id,itemtag:"dl",icontag:"dt",captiontag:"dd",columns:3,size:"thumbnail",orderby:"menu_order ID"},attachments:function(h){var j=h.string(),d=c[j],f,e,i,g;delete c[j];if(d){return d}f=_.defaults(h.attrs.named,wp.media.gallery.defaults);e=_.pick(f,"orderby","order");e.type="image";e.perPage=-1;if("rand"===f.orderby){f._orderbyRandom=true}if(!f.orderby||/^menu_order(?: ID)?$/i.test(f.orderby)){e.orderby="menuOrder"}if(f.ids){e.post__in=f.ids.split(",");e.orderby="post__in"}else{if(f.include){e.post__in=f.include.split(",")}}if(f.exclude){e.post__not_in=f.exclude.split(",")}if(!e.post__in){e.uploadedTo=f.id}g=_.omit(f,"id","ids","include","exclude","orderby","order");i=wp.media.query(e);i.gallery=new Backbone.Model(g);return i},shortcode:function(d){var f=d.props.toJSON(),e=_.pick(f,"orderby","order"),g,h;if(d.gallery){_.extend(e,d.gallery.toJSON())}e.ids=d.pluck("id");if(f.uploadedTo){e.id=f.uploadedTo}if(e._orderbyRandom){e.orderby="rand"}delete e._orderbyRandom;if(e.ids&&"post__in"===e.orderby){delete e.orderby}_.each(wp.media.gallery.defaults,function(j,i){if(j===e[i]){delete e[i]}});g=new wp.shortcode({tag:"gallery",attrs:e,type:"single"});h=new wp.media.model.Attachments(d.models,{props:f});h.gallery=d.gallery;c[g.string()]=h;return g},edit:function(g){var f=wp.shortcode.next("gallery",g),h=wp.media.gallery.defaults.id,d,e;if(!f||f.content!==g){return}f=f.shortcode;if(_.isUndefined(f.get("id"))&&!_.isUndefined(h)){f.set("id",h)}d=wp.media.gallery.attachments(f);e=new wp.media.model.Selection(d.models,{props:d.props.toJSON(),multiple:true});e.gallery=d.gallery;e.more().done(function(){e.props.set({query:false});e.unmirror();e.props.unset("orderby")});if(this.frame){this.frame.dispose()}this.frame=wp.media({frame:"post",state:"gallery-edit",title:wp.media.view.l10n.editGalleryTitle,editing:true,multiple:true,selection:e}).open();return this.frame}}}());wp.media.featuredImage={get:function(){return wp.media.view.settings.post.featuredImageId},set:function(d){var c=wp.media.view.settings;c.post.featuredImageId=d;wp.media.post("set-post-thumbnail",{json:true,post_id:c.post.id,thumbnail_id:c.post.featuredImageId,_wpnonce:c.post.nonce}).done(function(e){b(".inside","#postimagediv").html(e)})},frame:function(){if(this._frame){return this._frame}this._frame=wp.media({state:"featured-image",states:[new wp.media.controller.FeaturedImage()]});this._frame.on("toolbar:create:featured-image",function(c){this.createSelectToolbar(c,{text:wp.media.view.l10n.setFeaturedImage})},this._frame);this._frame.state("featured-image").on("select",this.select);return this._frame},select:function(){var d=wp.media.view.settings,c=this.get("selection").single();if(!d.post.featuredImageId){return}wp.media.featuredImage.set(c?c.id:-1)},init:function(){b("#postimagediv").on("click","#set-post-thumbnail",function(c){c.preventDefault();c.stopPropagation();wp.media.featuredImage.frame().open()}).on("click","#remove-post-thumbnail",function(){wp.media.view.settings.post.featuredImageId=-1})}};b(wp.media.featuredImage.init);wp.media.editor={insert:function(g){var d=typeof(tinymce)!="undefined",j=typeof(QTags)!="undefined",c=window.wpActiveEditor,f;if(window.send_to_editor){return window.send_to_editor.apply(this,arguments)}if(!c){if(d&&tinymce.activeEditor){f=tinymce.activeEditor;c=window.wpActiveEditor=f.id}else{if(!j){return false}}}else{if(d){if(tinymce.activeEditor&&(tinymce.activeEditor.id=="mce_fullscreen"||tinymce.activeEditor.id=="wp_mce_fullscreen")){f=tinymce.activeEditor}else{f=tinymce.get(c)}}}if(f&&!f.isHidden()){if(tinymce.isIE&&f.windowManager.insertimagebookmark){f.selection.moveToBookmark(f.windowManager.insertimagebookmark)}if(g.indexOf("[caption")!==-1){if(f.wpSetImgCaption){g=f.wpSetImgCaption(g)}}else{if(g.indexOf("[gallery")!==-1){if(f.plugins.wpgallery){g=f.plugins.wpgallery._do_gallery(g)}}else{if(g.indexOf("[embed")===0){if(f.plugins.wordpress){g=f.plugins.wordpress._setEmbed(g)}}}}f.execCommand("mceInsertContent",false,g)}else{if(j){QTags.insertContent(g)}else{document.getElementById(c).value+=g}}if(window.tb_remove){try{window.tb_remove()}catch(i){}}},add:function(e,c){var d=this.get(e);if(d){return d}d=a[e]=wp.media(_.defaults(c||{},{frame:"post",state:"insert",title:wp.media.view.l10n.addMedia,multiple:true}));d.on("insert",function(f){var g=d.state();f=f||g.get("selection");if(!f){return}b.when.apply(b,f.map(function(i){var h=g.display(i).toJSON();return this.send.attachment(h,i.toJSON())},this)).done(function(){wp.media.editor.insert(_.toArray(arguments).join("\n\n"))})},this);d.state("gallery-edit").on("update",function(f){this.insert(wp.media.gallery.shortcode(f).string())},this);d.state("embed").on("select",function(){var g=d.state(),f=g.get("type"),h=g.props.toJSON();h.url=h.url||"";if("link"===f){_.defaults(h,{title:h.url,linkUrl:h.url});this.send.link(h).done(function(i){wp.media.editor.insert(i)})}else{if("image"===f){_.defaults(h,{title:h.url,linkUrl:"",align:"none",link:"none"});if("none"===h.link){h.linkUrl=""}else{if("file"===h.link){h.linkUrl=h.url}}this.insert(wp.media.string.image(h))}}},this);d.state("featured-image").on("select",wp.media.featuredImage.select);d.setState(d.options.state);return d},id:function(c){if(c){return c}c=wpActiveEditor;if(!c&&typeof tinymce!=="undefined"&&tinymce.activeEditor){c=tinymce.activeEditor.id}c=c||"";return c},get:function(c){c=this.id(c);return a[c]},remove:function(c){c=this.id(c);delete a[c]},send:{attachment:function(f,g){var c=g.caption,d,e;if(!wp.media.view.settings.captions){delete g.caption}f=wp.media.string.props(f,g);d={id:g.id,post_content:g.description,post_excerpt:c};if(f.linkUrl){d.url=f.linkUrl}if("image"===g.type){e=wp.media.string.image(f);_.each({align:"align",size:"image-size",alt:"image_alt"},function(h,i){if(f[i]){d[h]=f[i]}})}else{e=wp.media.string.link(f);d.post_title=f.title}return wp.media.post("send-attachment-to-editor",{nonce:wp.media.view.settings.nonce.sendToEditor,attachment:d,html:e,post_id:wp.media.view.settings.post.id})},link:function(c){return wp.media.post("send-link-to-editor",{nonce:wp.media.view.settings.nonce.sendToEditor,src:c.linkUrl,title:c.title,html:wp.media.string.link(c),post_id:wp.media.view.settings.post.id})}},open:function(e){var d,c;e=this.id(e);if(typeof tinymce!=="undefined"){c=tinymce.get(e);if(tinymce.isIE&&c&&!c.isHidden()){c.focus();c.windowManager.insertimagebookmark=c.selection.getBookmark()}}d=this.get(e);if(!d){d=this.add(e)}return d.open()},init:function(){b(document.body).on("click",".insert-media",function(d){var e=b(this),c=e.data("editor");d.preventDefault();e.blur();wp.media.editor.open(c)})}};_.bindAll(wp.media.editor,"open");b(wp.media.editor.init)}(jQuery)); \ No newline at end of file diff --git a/wp-includes/js/media-models.js b/wp-includes/js/media-models.js new file mode 100644 index 00000000..34cce0b7 --- /dev/null +++ b/wp-includes/js/media-models.js @@ -0,0 +1,908 @@ +window.wp = window.wp || {}; + +(function($){ + var Attachment, Attachments, Query, compare, l10n, media; + + /** + * wp.media( attributes ) + * + * Handles the default media experience. Automatically creates + * and opens a media frame, and returns the result. + * Does nothing if the controllers do not exist. + * + * @param {object} attributes The properties passed to the main media controller. + * @return {object} A media workflow. + */ + media = wp.media = function( attributes ) { + var MediaFrame = media.view.MediaFrame, + frame; + + if ( ! MediaFrame ) + return; + + attributes = _.defaults( attributes || {}, { + frame: 'select' + }); + + if ( 'select' === attributes.frame && MediaFrame.Select ) + frame = new MediaFrame.Select( attributes ); + else if ( 'post' === attributes.frame && MediaFrame.Post ) + frame = new MediaFrame.Post( attributes ); + + delete attributes.frame; + + return frame; + }; + + _.extend( media, { model: {}, view: {}, controller: {}, frames: {} }); + + // Link any localized strings. + l10n = media.model.l10n = typeof _wpMediaModelsL10n === 'undefined' ? {} : _wpMediaModelsL10n; + + // Link any settings. + media.model.settings = l10n.settings || {}; + delete l10n.settings; + + /** + * ======================================================================== + * UTILITIES + * ======================================================================== + */ + + /** + * A basic comparator. + * + * @param {mixed} a The primary parameter to compare. + * @param {mixed} b The primary parameter to compare. + * @param {string} ac The fallback parameter to compare, a's cid. + * @param {string} bc The fallback parameter to compare, b's cid. + * @return {number} -1: a should come before b. + * 0: a and b are of the same rank. + * 1: b should come before a. + */ + compare = function( a, b, ac, bc ) { + if ( _.isEqual( a, b ) ) + return ac === bc ? 0 : (ac > bc ? -1 : 1); + else + return a > b ? -1 : 1; + }; + + _.extend( media, { + /** + * media.template( id ) + * + * Fetches a template by id. + * + * @param {string} id A string that corresponds to a DOM element with an id prefixed with "tmpl-". + * For example, "attachment" maps to "tmpl-attachment". + * @return {function} A function that lazily-compiles the template requested. + */ + template: _.memoize( function( id ) { + var compiled, + options = { + evaluate: /<#([\s\S]+?)#>/g, + interpolate: /\{\{\{([\s\S]+?)\}\}\}/g, + escape: /\{\{([^\}]+?)\}\}(?!\})/g, + variable: 'data' + }; + + return function( data ) { + compiled = compiled || _.template( $( '#tmpl-' + id ).html(), null, options ); + return compiled( data ); + }; + }), + + /** + * media.post( [action], [data] ) + * + * Sends a POST request to WordPress. + * + * @param {string} action The slug of the action to fire in WordPress. + * @param {object} data The data to populate $_POST with. + * @return {$.promise} A jQuery promise that represents the request. + */ + post: function( action, data ) { + return media.ajax({ + data: _.isObject( action ) ? action : _.extend( data || {}, { action: action }) + }); + }, + + /** + * media.ajax( [action], [options] ) + * + * Sends a POST request to WordPress. + * + * @param {string} action The slug of the action to fire in WordPress. + * @param {object} options The options passed to jQuery.ajax. + * @return {$.promise} A jQuery promise that represents the request. + */ + ajax: function( action, options ) { + if ( _.isObject( action ) ) { + options = action; + } else { + options = options || {}; + options.data = _.extend( options.data || {}, { action: action }); + } + + options = _.defaults( options || {}, { + type: 'POST', + url: media.model.settings.ajaxurl, + context: this + }); + + return $.Deferred( function( deferred ) { + // Transfer success/error callbacks. + if ( options.success ) + deferred.done( options.success ); + if ( options.error ) + deferred.fail( options.error ); + + delete options.success; + delete options.error; + + // Use with PHP's wp_send_json_success() and wp_send_json_error() + $.ajax( options ).done( function( response ) { + // Treat a response of `1` as successful for backwards + // compatibility with existing handlers. + if ( response === '1' || response === 1 ) + response = { success: true }; + + if ( _.isObject( response ) && ! _.isUndefined( response.success ) ) + deferred[ response.success ? 'resolveWith' : 'rejectWith' ]( this, [response.data] ); + else + deferred.rejectWith( this, [response] ); + }).fail( function() { + deferred.rejectWith( this, arguments ); + }); + }).promise(); + }, + + // Scales a set of dimensions to fit within bounding dimensions. + fit: function( dimensions ) { + var width = dimensions.width, + height = dimensions.height, + maxWidth = dimensions.maxWidth, + maxHeight = dimensions.maxHeight, + constraint; + + // Compare ratios between the two values to determine which + // max to constrain by. If a max value doesn't exist, then the + // opposite side is the constraint. + if ( ! _.isUndefined( maxWidth ) && ! _.isUndefined( maxHeight ) ) { + constraint = ( width / height > maxWidth / maxHeight ) ? 'width' : 'height'; + } else if ( _.isUndefined( maxHeight ) ) { + constraint = 'width'; + } else if ( _.isUndefined( maxWidth ) && height > maxHeight ) { + constraint = 'height'; + } + + // If the value of the constrained side is larger than the max, + // then scale the values. Otherwise return the originals; they fit. + if ( 'width' === constraint && width > maxWidth ) { + return { + width : maxWidth, + height: Math.round( maxWidth * height / width ) + }; + } else if ( 'height' === constraint && height > maxHeight ) { + return { + width : Math.round( maxHeight * width / height ), + height: maxHeight + }; + } else { + return { + width : width, + height: height + }; + } + }, + + // Truncates a string by injecting an ellipsis into the middle. + // Useful for filenames. + truncate: function( string, length, replacement ) { + length = length || 30; + replacement = replacement || '…'; + + if ( string.length <= length ) + return string; + + return string.substr( 0, length / 2 ) + replacement + string.substr( -1 * length / 2 ); + } + }); + + + /** + * ======================================================================== + * MODELS + * ======================================================================== + */ + + /** + * wp.media.attachment + */ + media.attachment = function( id ) { + return Attachment.get( id ); + }; + + /** + * wp.media.model.Attachment + */ + Attachment = media.model.Attachment = Backbone.Model.extend({ + sync: function( method, model, options ) { + // If the attachment does not yet have an `id`, return an instantly + // rejected promise. Otherwise, all of our requests will fail. + if ( _.isUndefined( this.id ) ) + return $.Deferred().rejectWith( this ).promise(); + + // Overload the `read` request so Attachment.fetch() functions correctly. + if ( 'read' === method ) { + options = options || {}; + options.context = this; + options.data = _.extend( options.data || {}, { + action: 'get-attachment', + id: this.id + }); + return media.ajax( options ); + + // Overload the `update` request so properties can be saved. + } else if ( 'update' === method ) { + // If we do not have the necessary nonce, fail immeditately. + if ( ! this.get('nonces') || ! this.get('nonces').update ) + return $.Deferred().rejectWith( this ).promise(); + + options = options || {}; + options.context = this; + + // Set the action and ID. + options.data = _.extend( options.data || {}, { + action: 'save-attachment', + id: this.id, + nonce: this.get('nonces').update, + post_id: media.model.settings.post.id + }); + + // Record the values of the changed attributes. + if ( options.changes ) { + _.each( options.changes, function( value, key ) { + options.changes[ key ] = this.get( key ); + }, this ); + + options.data.changes = options.changes; + delete options.changes; + } + + return media.ajax( options ); + + // Overload the `delete` request so attachments can be removed. + // This will permanently delete an attachment. + } else if ( 'delete' === method ) { + options = options || {}; + + if ( ! options.wait ) + this.destroyed = true; + + options.context = this; + options.data = _.extend( options.data || {}, { + action: 'delete-post', + id: this.id, + _wpnonce: this.get('nonces')['delete'] + }); + + return media.ajax( options ).done( function() { + this.destroyed = true; + }).fail( function() { + this.destroyed = false; + }); + } + }, + + parse: function( resp, xhr ) { + if ( ! resp ) + return resp; + + // Convert date strings into Date objects. + resp.date = new Date( resp.date ); + resp.modified = new Date( resp.modified ); + return resp; + }, + + saveCompat: function( data, options ) { + var model = this; + + // If we do not have the necessary nonce, fail immeditately. + if ( ! this.get('nonces') || ! this.get('nonces').update ) + return $.Deferred().rejectWith( this ).promise(); + + return media.post( 'save-attachment-compat', _.defaults({ + id: this.id, + nonce: this.get('nonces').update, + post_id: media.model.settings.post.id + }, data ) ).done( function( resp, status, xhr ) { + model.set( model.parse( resp, xhr ), options ); + }); + } + }, { + create: function( attrs ) { + return Attachments.all.push( attrs ); + }, + + get: _.memoize( function( id, attachment ) { + return Attachments.all.push( attachment || { id: id } ); + }) + }); + + /** + * wp.media.model.Attachments + */ + Attachments = media.model.Attachments = Backbone.Collection.extend({ + model: Attachment, + + initialize: function( models, options ) { + options = options || {}; + + this.props = new Backbone.Model(); + this.filters = options.filters || {}; + + // Bind default `change` events to the `props` model. + this.props.on( 'change', this._changeFilteredProps, this ); + + this.props.on( 'change:order', this._changeOrder, this ); + this.props.on( 'change:orderby', this._changeOrderby, this ); + this.props.on( 'change:query', this._changeQuery, this ); + + // Set the `props` model and fill the default property values. + this.props.set( _.defaults( options.props || {} ) ); + + // Observe another `Attachments` collection if one is provided. + if ( options.observe ) + this.observe( options.observe ); + }, + + // Automatically sort the collection when the order changes. + _changeOrder: function( model, order ) { + if ( this.comparator ) + this.sort(); + }, + + // Set the default comparator only when the `orderby` property is set. + _changeOrderby: function( model, orderby ) { + // If a different comparator is defined, bail. + if ( this.comparator && this.comparator !== Attachments.comparator ) + return; + + if ( orderby && 'post__in' !== orderby ) + this.comparator = Attachments.comparator; + else + delete this.comparator; + }, + + // If the `query` property is set to true, query the server using + // the `props` values, and sync the results to this collection. + _changeQuery: function( model, query ) { + if ( query ) { + this.props.on( 'change', this._requery, this ); + this._requery(); + } else { + this.props.off( 'change', this._requery, this ); + } + }, + + _changeFilteredProps: function( model, options ) { + // If this is a query, updating the collection will be handled by + // `this._requery()`. + if ( this.props.get('query') ) + return; + + var changed = _.chain( options.changes ).map( function( t, prop ) { + var filter = Attachments.filters[ prop ], + term = model.get( prop ); + + if ( ! filter ) + return; + + if ( term && ! this.filters[ prop ] ) + this.filters[ prop ] = filter; + else if ( ! term && this.filters[ prop ] === filter ) + delete this.filters[ prop ]; + else + return; + + // Record the change. + return true; + }, this ).any().value(); + + if ( ! changed ) + return; + + // If no `Attachments` model is provided to source the searches + // from, then automatically generate a source from the existing + // models. + if ( ! this._source ) + this._source = new Attachments( this.models ); + + this.reset( this._source.filter( this.validator, this ) ); + }, + + validateDestroyed: false, + + validator: function( attachment ) { + if ( ! this.validateDestroyed && attachment.destroyed ) + return false; + return _.all( this.filters, function( filter, key ) { + return !! filter.call( this, attachment ); + }, this ); + }, + + validate: function( attachment, options ) { + var valid = this.validator( attachment ), + hasAttachment = !! this.getByCid( attachment.cid ); + + if ( ! valid && hasAttachment ) + this.remove( attachment, options ); + else if ( valid && ! hasAttachment ) + this.add( attachment, options ); + + return this; + }, + + validateAll: function( attachments, options ) { + options = options || {}; + + _.each( attachments.models, function( attachment ) { + this.validate( attachment, { silent: true }); + }, this ); + + if ( ! options.silent ) + this.trigger( 'reset', this, options ); + + return this; + }, + + observe: function( attachments ) { + this.observers = this.observers || []; + this.observers.push( attachments ); + + attachments.on( 'add change remove', this._validateHandler, this ); + attachments.on( 'reset', this._validateAllHandler, this ); + + this.validateAll( attachments ); + return this; + }, + + unobserve: function( attachments ) { + if ( attachments ) { + attachments.off( null, null, this ); + this.observers = _.without( this.observers, attachments ); + + } else { + _.each( this.observers, function( attachments ) { + attachments.off( null, null, this ); + }, this ); + delete this.observers; + } + + return this; + }, + + _validateHandler: function( attachment, attachments, options ) { + // If we're not mirroring this `attachments` collection, + // only retain the `silent` option. + options = attachments === this.mirroring ? options : { + silent: options && options.silent + }; + + return this.validate( attachment, options ); + }, + + _validateAllHandler: function( attachments, options ) { + return this.validateAll( attachments, options ); + }, + + mirror: function( attachments ) { + if ( this.mirroring && this.mirroring === attachments ) + return this; + + this.unmirror(); + this.mirroring = attachments; + + // Clear the collection silently. A `reset` event will be fired + // when `observe()` calls `validateAll()`. + this.reset( [], { silent: true } ); + this.observe( attachments ); + + return this; + }, + + unmirror: function() { + if ( ! this.mirroring ) + return; + + this.unobserve( this.mirroring ); + delete this.mirroring; + }, + + more: function( options ) { + var deferred = $.Deferred(), + mirroring = this.mirroring, + attachments = this; + + if ( ! mirroring || ! mirroring.more ) + return deferred.resolveWith( this ).promise(); + + // If we're mirroring another collection, forward `more` to + // the mirrored collection. Account for a race condition by + // checking if we're still mirroring that collection when + // the request resolves. + mirroring.more( options ).done( function() { + if ( this === attachments.mirroring ) + deferred.resolveWith( this ); + }); + + return deferred.promise(); + }, + + hasMore: function() { + return this.mirroring ? this.mirroring.hasMore() : false; + }, + + parse: function( resp, xhr ) { + return _.map( resp, function( attrs ) { + var attachment = Attachment.get( attrs.id ); + return attachment.set( attachment.parse( attrs, xhr ) ); + }); + }, + + _requery: function() { + if ( this.props.get('query') ) + this.mirror( Query.get( this.props.toJSON() ) ); + }, + + // If this collection is sorted by `menuOrder`, recalculates and saves + // the menu order to the database. + saveMenuOrder: function() { + if ( 'menuOrder' !== this.props.get('orderby') ) + return; + + // Removes any uploading attachments, updates each attachment's + // menu order, and returns an object with an { id: menuOrder } + // mapping to pass to the request. + var attachments = this.chain().filter( function( attachment ) { + return ! _.isUndefined( attachment.id ); + }).map( function( attachment, index ) { + // Indices start at 1. + index = index + 1; + attachment.set( 'menuOrder', index ); + return [ attachment.id, index ]; + }).object().value(); + + if ( _.isEmpty( attachments ) ) + return; + + return media.post( 'save-attachment-order', { + nonce: media.model.settings.post.nonce, + post_id: media.model.settings.post.id, + attachments: attachments + }); + } + }, { + comparator: function( a, b, options ) { + var key = this.props.get('orderby'), + order = this.props.get('order') || 'DESC', + ac = a.cid, + bc = b.cid; + + a = a.get( key ); + b = b.get( key ); + + if ( 'date' === key || 'modified' === key ) { + a = a || new Date(); + b = b || new Date(); + } + + // If `options.ties` is set, don't enforce the `cid` tiebreaker. + if ( options && options.ties ) + ac = bc = null; + + return ( 'DESC' === order ) ? compare( a, b, ac, bc ) : compare( b, a, bc, ac ); + }, + + filters: { + // Note that this client-side searching is *not* equivalent + // to our server-side searching. + search: function( attachment ) { + if ( ! this.props.get('search') ) + return true; + + return _.any(['title','filename','description','caption','name'], function( key ) { + var value = attachment.get( key ); + return value && -1 !== value.search( this.props.get('search') ); + }, this ); + }, + + type: function( attachment ) { + var type = this.props.get('type'); + return ! type || -1 !== type.indexOf( attachment.get('type') ); + }, + + uploadedTo: function( attachment ) { + var uploadedTo = this.props.get('uploadedTo'); + if ( _.isUndefined( uploadedTo ) ) + return true; + + return uploadedTo === attachment.get('uploadedTo'); + } + } + }); + + Attachments.all = new Attachments(); + + /** + * wp.media.query + */ + media.query = function( props ) { + return new Attachments( null, { + props: _.extend( _.defaults( props || {}, { orderby: 'date' } ), { query: true } ) + }); + }; + + /** + * wp.media.model.Query + * + * A set of attachments that corresponds to a set of consecutively paged + * queries on the server. + * + * Note: Do NOT change this.args after the query has been initialized. + * Things will break. + */ + Query = media.model.Query = Attachments.extend({ + initialize: function( models, options ) { + var allowed; + + options = options || {}; + Attachments.prototype.initialize.apply( this, arguments ); + + this.args = options.args; + this._hasMore = true; + this.created = new Date(); + + this.filters.order = function( attachment ) { + var orderby = this.props.get('orderby'), + order = this.props.get('order'); + + if ( ! this.comparator ) + return true; + + // We want any items that can be placed before the last + // item in the set. If we add any items after the last + // item, then we can't guarantee the set is complete. + if ( this.length ) { + return 1 !== this.comparator( attachment, this.last(), { ties: true }); + + // Handle the case where there are no items yet and + // we're sorting for recent items. In that case, we want + // changes that occurred after we created the query. + } else if ( 'DESC' === order && ( 'date' === orderby || 'modified' === orderby ) ) { + return attachment.get( orderby ) >= this.created; + + // If we're sorting by menu order and we have no items, + // accept any items that have the default menu order (0). + } else if ( 'ASC' === order && 'menuOrder' === orderby ) { + return attachment.get( orderby ) === 0; + } + + // Otherwise, we don't want any items yet. + return false; + }; + + // Observe the central `wp.Uploader.queue` collection to watch for + // new matches for the query. + // + // Only observe when a limited number of query args are set. There + // are no filters for other properties, so observing will result in + // false positives in those queries. + allowed = [ 's', 'order', 'orderby', 'posts_per_page', 'post_mime_type', 'post_parent' ]; + if ( wp.Uploader && _( this.args ).chain().keys().difference( allowed ).isEmpty().value() ) + this.observe( wp.Uploader.queue ); + }, + + hasMore: function() { + return this._hasMore; + }, + + more: function( options ) { + var query = this; + + if ( this._more && 'pending' === this._more.state() ) + return this._more; + + if ( ! this.hasMore() ) + return $.Deferred().resolveWith( this ).promise(); + + options = options || {}; + options.add = true; + + return this._more = this.fetch( options ).done( function( resp ) { + if ( _.isEmpty( resp ) || -1 === this.args.posts_per_page || resp.length < this.args.posts_per_page ) + query._hasMore = false; + }); + }, + + sync: function( method, model, options ) { + var fallback; + + // Overload the read method so Attachment.fetch() functions correctly. + if ( 'read' === method ) { + options = options || {}; + options.context = this; + options.data = _.extend( options.data || {}, { + action: 'query-attachments', + post_id: media.model.settings.post.id + }); + + // Clone the args so manipulation is non-destructive. + args = _.clone( this.args ); + + // Determine which page to query. + if ( -1 !== args.posts_per_page ) + args.paged = Math.floor( this.length / args.posts_per_page ) + 1; + + options.data.query = args; + return media.ajax( options ); + + // Otherwise, fall back to Backbone.sync() + } else { + fallback = Attachments.prototype.sync ? Attachments.prototype : Backbone; + return fallback.sync.apply( this, arguments ); + } + } + }, { + defaultProps: { + orderby: 'date', + order: 'DESC' + }, + + defaultArgs: { + posts_per_page: 40 + }, + + orderby: { + allowed: [ 'name', 'author', 'date', 'title', 'modified', 'uploadedTo', 'id', 'post__in', 'menuOrder' ], + valuemap: { + 'id': 'ID', + 'uploadedTo': 'parent', + 'menuOrder': 'menu_order ID' + } + }, + + propmap: { + 'search': 's', + 'type': 'post_mime_type', + 'perPage': 'posts_per_page', + 'menuOrder': 'menu_order', + 'uploadedTo': 'post_parent' + }, + + // Caches query objects so queries can be easily reused. + get: (function(){ + var queries = []; + + return function( props, options ) { + var args = {}, + orderby = Query.orderby, + defaults = Query.defaultProps, + query; + + // Remove the `query` property. This isn't linked to a query, + // this *is* the query. + delete props.query; + + // Fill default args. + _.defaults( props, defaults ); + + // Normalize the order. + props.order = props.order.toUpperCase(); + if ( 'DESC' !== props.order && 'ASC' !== props.order ) + props.order = defaults.order.toUpperCase(); + + // Ensure we have a valid orderby value. + if ( ! _.contains( orderby.allowed, props.orderby ) ) + props.orderby = defaults.orderby; + + // Generate the query `args` object. + // Correct any differing property names. + _.each( props, function( value, prop ) { + if ( _.isNull( value ) ) + return; + + args[ Query.propmap[ prop ] || prop ] = value; + }); + + // Fill any other default query args. + _.defaults( args, Query.defaultArgs ); + + // `props.orderby` does not always map directly to `args.orderby`. + // Substitute exceptions specified in orderby.keymap. + args.orderby = orderby.valuemap[ props.orderby ] || props.orderby; + + // Search the query cache for matches. + query = _.find( queries, function( query ) { + return _.isEqual( query.args, args ); + }); + + // Otherwise, create a new query and add it to the cache. + if ( ! query ) { + query = new Query( [], _.extend( options || {}, { + props: props, + args: args + } ) ); + queries.push( query ); + } + + return query; + }; + }()) + }); + + /** + * wp.media.model.Selection + * + * Used to manage a selection of attachments in the views. + */ + media.model.Selection = Attachments.extend({ + initialize: function( models, options ) { + Attachments.prototype.initialize.apply( this, arguments ); + this.multiple = options && options.multiple; + + // Refresh the `single` model whenever the selection changes. + // Binds `single` instead of using the context argument to ensure + // it receives no parameters. + this.on( 'add remove reset', _.bind( this.single, this, false ) ); + }, + + // Override the selection's add method. + // If the workflow does not support multiple + // selected attachments, reset the selection. + add: function( models, options ) { + if ( ! this.multiple ) + this.remove( this.models ); + + return Attachments.prototype.add.call( this, models, options ); + }, + + single: function( model ) { + var previous = this._single; + + // If a `model` is provided, use it as the single model. + if ( model ) + this._single = model; + + // If the single model isn't in the selection, remove it. + if ( this._single && ! this.getByCid( this._single.cid ) ) + delete this._single; + + this._single = this._single || this.last(); + + // If single has changed, fire an event. + if ( this._single !== previous ) { + if ( previous ) { + previous.trigger( 'selection:unsingle', previous, this ); + + // If the model was already removed, trigger the collection + // event manually. + if ( ! this.getByCid( previous.cid ) ) + this.trigger( 'selection:unsingle', previous, this ); + } + if ( this._single ) + this._single.trigger( 'selection:single', this._single, this ); + } + + // Return the single model, or the last model as a fallback. + return this._single; + } + }); + + // Clean up. Prevents mobile browsers caching + $(window).on('unload', function(){ + window.wp = null; + }); + +}(jQuery)); \ No newline at end of file diff --git a/wp-includes/js/media-models.min.js b/wp-includes/js/media-models.min.js new file mode 100644 index 00000000..9acf7751 --- /dev/null +++ b/wp-includes/js/media-models.min.js @@ -0,0 +1 @@ +window.wp=window.wp||{};(function(f){var d,c,a,e,b,g;g=wp.media=function(h){var i=g.view.MediaFrame,j;if(!i){return}h=_.defaults(h||{},{frame:"select"});if("select"===h.frame&&i.Select){j=new i.Select(h)}else{if("post"===h.frame&&i.Post){j=new i.Post(h)}}delete h.frame;return j};_.extend(g,{model:{},view:{},controller:{},frames:{}});b=g.model.l10n=typeof _wpMediaModelsL10n==="undefined"?{}:_wpMediaModelsL10n;g.model.settings=b.settings||{};delete b.settings;e=function(i,h,j,k){if(_.isEqual(i,h)){return j===k?0:(j>k?-1:1)}else{return i>h?-1:1}};_.extend(g,{template:_.memoize(function(j){var i,h={evaluate:/<#([\s\S]+?)#>/g,interpolate:/\{\{\{([\s\S]+?)\}\}\}/g,escape:/\{\{([^\}]+?)\}\}(?!\})/g,variable:"data"};return function(k){i=i||_.template(f("#tmpl-"+j).html(),null,h);return i(k)}}),post:function(i,h){return g.ajax({data:_.isObject(i)?i:_.extend(h||{},{action:i})})},ajax:function(i,h){if(_.isObject(i)){h=i}else{h=h||{};h.data=_.extend(h.data||{},{action:i})}h=_.defaults(h||{},{type:"POST",url:g.model.settings.ajaxurl,context:this});return f.Deferred(function(j){if(h.success){j.done(h.success)}if(h.error){j.fail(h.error)}delete h.success;delete h.error;f.ajax(h).done(function(k){if(k==="1"||k===1){k={success:true}}if(_.isObject(k)&&!_.isUndefined(k.success)){j[k.success?"resolveWith":"rejectWith"](this,[k.data])}else{j.rejectWith(this,[k])}}).fail(function(){j.rejectWith(this,arguments)})}).promise()},fit:function(l){var i=l.width,h=l.height,k=l.maxWidth,j=l.maxHeight,m;if(!_.isUndefined(k)&&!_.isUndefined(j)){m=(i/h>k/j)?"width":"height"}else{if(_.isUndefined(j)){m="width"}else{if(_.isUndefined(k)&&h>j){m="height"}}}if("width"===m&&i>k){return{width:k,height:Math.round(k*h/i)}}else{if("height"===m&&h>j){return{width:Math.round(j*i/h),height:j}}else{return{width:i,height:h}}}},truncate:function(h,j,i){j=j||30;i=i||"…";if(h.length<=j){return h}return h.substr(0,j/2)+i+h.substr(-1*j/2)}});g.attachment=function(h){return d.get(h)};d=g.model.Attachment=Backbone.Model.extend({sync:function(j,i,h){if(_.isUndefined(this.id)){return f.Deferred().rejectWith(this).promise()}if("read"===j){h=h||{};h.context=this;h.data=_.extend(h.data||{},{action:"get-attachment",id:this.id});return g.ajax(h)}else{if("update"===j){if(!this.get("nonces")||!this.get("nonces").update){return f.Deferred().rejectWith(this).promise()}h=h||{};h.context=this;h.data=_.extend(h.data||{},{action:"save-attachment",id:this.id,nonce:this.get("nonces").update,post_id:g.model.settings.post.id});if(h.changes){_.each(h.changes,function(l,k){h.changes[k]=this.get(k)},this);h.data.changes=h.changes;delete h.changes}return g.ajax(h)}else{if("delete"===j){h=h||{};if(!h.wait){this.destroyed=true}h.context=this;h.data=_.extend(h.data||{},{action:"delete-post",id:this.id,_wpnonce:this.get("nonces")["delete"]});return g.ajax(h).done(function(){this.destroyed=true}).fail(function(){this.destroyed=false})}}}},parse:function(i,h){if(!i){return i}i.date=new Date(i.date);i.modified=new Date(i.modified);return i},saveCompat:function(j,i){var h=this;if(!this.get("nonces")||!this.get("nonces").update){return f.Deferred().rejectWith(this).promise()}return g.post("save-attachment-compat",_.defaults({id:this.id,nonce:this.get("nonces").update,post_id:g.model.settings.post.id},j)).done(function(m,k,l){h.set(h.parse(m,l),i)})}},{create:function(h){return c.all.push(h)},get:_.memoize(function(i,h){return c.all.push(h||{id:i})})});c=g.model.Attachments=Backbone.Collection.extend({model:d,initialize:function(i,h){h=h||{};this.props=new Backbone.Model();this.filters=h.filters||{};this.props.on("change",this._changeFilteredProps,this);this.props.on("change:order",this._changeOrder,this);this.props.on("change:orderby",this._changeOrderby,this);this.props.on("change:query",this._changeQuery,this);this.props.set(_.defaults(h.props||{}));if(h.observe){this.observe(h.observe)}},_changeOrder:function(i,h){if(this.comparator){this.sort()}},_changeOrderby:function(h,i){if(this.comparator&&this.comparator!==c.comparator){return}if(i&&"post__in"!==i){this.comparator=c.comparator}else{delete this.comparator}},_changeQuery:function(h,i){if(i){this.props.on("change",this._requery,this);this._requery()}else{this.props.off("change",this._requery,this)}},_changeFilteredProps:function(i,h){if(this.props.get("query")){return}var j=_.chain(h.changes).map(function(l,n){var m=c.filters[n],k=i.get(n);if(!m){return}if(k&&!this.filters[n]){this.filters[n]=m}else{if(!k&&this.filters[n]===m){delete this.filters[n]}else{return}}return true},this).any().value();if(!j){return}if(!this._source){this._source=new c(this.models)}this.reset(this._source.filter(this.validator,this))},validateDestroyed:false,validator:function(h){if(!this.validateDestroyed&&h.destroyed){return false}return _.all(this.filters,function(j,i){return !!j.call(this,h)},this)},validate:function(k,i){var j=this.validator(k),h=!!this.getByCid(k.cid);if(!j&&h){this.remove(k,i)}else{if(j&&!h){this.add(k,i)}}return this},validateAll:function(h,i){i=i||{};_.each(h.models,function(j){this.validate(j,{silent:true})},this);if(!i.silent){this.trigger("reset",this,i)}return this},observe:function(h){this.observers=this.observers||[];this.observers.push(h);h.on("add change remove",this._validateHandler,this);h.on("reset",this._validateAllHandler,this);this.validateAll(h);return this},unobserve:function(h){if(h){h.off(null,null,this);this.observers=_.without(this.observers,h)}else{_.each(this.observers,function(i){i.off(null,null,this)},this);delete this.observers}return this},_validateHandler:function(j,h,i){i=h===this.mirroring?i:{silent:i&&i.silent};return this.validate(j,i)},_validateAllHandler:function(h,i){return this.validateAll(h,i)},mirror:function(h){if(this.mirroring&&this.mirroring===h){return this}this.unmirror();this.mirroring=h;this.reset([],{silent:true});this.observe(h);return this},unmirror:function(){if(!this.mirroring){return}this.unobserve(this.mirroring);delete this.mirroring},more:function(j){var i=f.Deferred(),k=this.mirroring,h=this;if(!k||!k.more){return i.resolveWith(this).promise()}k.more(j).done(function(){if(this===h.mirroring){i.resolveWith(this)}});return i.promise()},hasMore:function(){return this.mirroring?this.mirroring.hasMore():false},parse:function(i,h){return _.map(i,function(j){var k=d.get(j.id);return k.set(k.parse(j,h))})},_requery:function(){if(this.props.get("query")){this.mirror(a.get(this.props.toJSON()))}},saveMenuOrder:function(){if("menuOrder"!==this.props.get("orderby")){return}var h=this.chain().filter(function(i){return !_.isUndefined(i.id)}).map(function(j,i){i=i+1;j.set("menuOrder",i);return[j.id,i]}).object().value();if(_.isEmpty(h)){return}return g.post("save-attachment-order",{nonce:g.model.settings.post.nonce,post_id:g.model.settings.post.id,attachments:h})}},{comparator:function(j,i,k){var l=this.props.get("orderby"),h=this.props.get("order")||"DESC",m=j.cid,n=i.cid;j=j.get(l);i=i.get(l);if("date"===l||"modified"===l){j=j||new Date();i=i||new Date()}if(k&&k.ties){m=n=null}return("DESC"===h)?e(j,i,m,n):e(i,j,n,m)},filters:{search:function(h){if(!this.props.get("search")){return true}return _.any(["title","filename","description","caption","name"],function(i){var j=h.get(i);return j&&-1!==j.search(this.props.get("search"))},this)},type:function(i){var h=this.props.get("type");return !h||-1!==h.indexOf(i.get("type"))},uploadedTo:function(i){var h=this.props.get("uploadedTo");if(_.isUndefined(h)){return true}return h===i.get("uploadedTo")}}});c.all=new c();g.query=function(h){return new c(null,{props:_.extend(_.defaults(h||{},{orderby:"date"}),{query:true})})};a=g.model.Query=c.extend({initialize:function(j,h){var i;h=h||{};c.prototype.initialize.apply(this,arguments);this.args=h.args;this._hasMore=true;this.created=new Date();this.filters.order=function(m){var l=this.props.get("orderby"),k=this.props.get("order");if(!this.comparator){return true}if(this.length){return 1!==this.comparator(m,this.last(),{ties:true})}else{if("DESC"===k&&("date"===l||"modified"===l)){return m.get(l)>=this.created}else{if("ASC"===k&&"menuOrder"===l){return m.get(l)===0}}}return false};i=["s","order","orderby","posts_per_page","post_mime_type","post_parent"];if(wp.Uploader&&_(this.args).chain().keys().difference(i).isEmpty().value()){this.observe(wp.Uploader.queue)}},hasMore:function(){return this._hasMore},more:function(h){var i=this;if(this._more&&"pending"===this._more.state()){return this._more}if(!this.hasMore()){return f.Deferred().resolveWith(this).promise()}h=h||{};h.add=true;return this._more=this.fetch(h).done(function(j){if(_.isEmpty(j)||-1===this.args.posts_per_page||j.length If `options.silent` is true, no DOM modifications will be made. + // + // `options.add` – *boolean, `false`* + // > Use `Views.add()` as a shortcut for setting `options.add` to true. + // + // > By default, the provided `views` will replace + // any existing views associated with the selector. If `options.add` + // is true, the provided `views` will be added to the existing views. + // + // `options.at` – *integer, `undefined`* + // > When adding, to insert `views` at a specific index, use + // `options.at`. By default, `views` are added to the end of the array. + set: function( selector, views, options ) { + var existing, next; + + if ( ! _.isString( selector ) ) { + options = views; + views = selector; + selector = ''; + } + + options = options || {}; + views = _.isArray( views ) ? views : [ views ]; + existing = this.get( selector ); + next = views; + + if ( existing ) { + if ( options.add ) { + if ( _.isUndefined( options.at ) ) { + next = existing.concat( views ); + } else { + next = existing; + next.splice.apply( next, [ options.at, 0 ].concat( views ) ); + } + } else { + _.each( next, function( view ) { + view.__detach = true; + }); + + _.each( existing, function( view ) { + if ( view.__detach ) + view.$el.detach(); + else + view.dispose(); + }); + + _.each( next, function( view ) { + delete view.__detach; + }); + } + } + + this._views[ selector ] = next; + + _.each( views, function( subview ) { + var constructor = subview.Views || media.Views, + subviews = subview.views = subview.views || new constructor( subview ); + subviews.parent = this.view; + subviews.selector = selector; + }, this ); + + if ( ! options.silent ) + this._attach( selector, views, _.extend({ ready: this._isReady() }, options ) ); + + return this; + }, + + // ### Add subview(s) to existing subviews + // + // An alias to `Views.set()`, which defaults `options.add` to true. + // + // Adds any number of `views` to a `selector`. + // + // When no `selector` is provided, the root selector (the empty string) + // is used. `views` accepts a `Backbone.View` instance or an array of + // `Backbone.View` instances. + // + // Use `Views.set()` when setting `options.add` to `false`. + // + // Accepts an `options` object. By default, provided `views` will be + // inserted at the end of the array of existing views. To insert + // `views` at a specific index, use `options.at`. If `options.silent` + // is true, no DOM modifications will be made. + // + // For more information on the `options` object, see `Views.set()`. + add: function( selector, views, options ) { + if ( ! _.isString( selector ) ) { + options = views; + views = selector; + selector = ''; + } + + return this.set( selector, views, _.extend({ add: true }, options ) ); + }, + + // ### Stop tracking subviews + // + // Stops tracking `views` registered to a `selector`. If no `views` are + // set, then all of the `selector`'s subviews will be unregistered and + // disposed. + // + // Accepts an `options` object. If `options.silent` is set, `dispose` + // will *not* be triggered on the unregistered views. + unset: function( selector, views, options ) { + var existing; + + if ( ! _.isString( selector ) ) { + options = views; + views = selector; + selector = ''; + } + + views = views || []; + + if ( existing = this.get( selector ) ) { + views = _.isArray( views ) ? views : [ views ]; + this._views[ selector ] = views.length ? _.difference( existing, views ) : []; + } + + if ( ! options || ! options.silent ) + _.invoke( views, 'dispose' ); + + return this; + }, + + // ### Detach all subviews + // + // Detaches all subviews from the DOM. + // + // Helps to preserve all subview events when re-rendering the master + // view. Used in conjunction with `Views.render()`. + detach: function() { + $( _.pluck( this.all(), 'el' ) ).detach(); + return this; + }, + + // ### Render all subviews + // + // Renders all subviews. Used in conjunction with `Views.detach()`. + render: function() { + var options = { + ready: this._isReady() + }; + + _.each( this._views, function( views, selector ) { + this._attach( selector, views, options ); + }, this ); + + this.rendered = true; + return this; + }, + + // ### Dispose all subviews + // + // Triggers the `dispose()` method on all subviews. Detaches the master + // view from its parent. Resets the internals of the views manager. + // + // Accepts an `options` object. If `options.silent` is set, `unset` + // will *not* be triggered on the master view's parent. + dispose: function( options ) { + if ( ! options || ! options.silent ) { + if ( this.parent && this.parent.views ) + this.parent.views.unset( this.selector, this.view, { silent: true }); + delete this.parent; + delete this.selector; + } + + _.invoke( this.all(), 'dispose' ); + this._views = []; + return this; + }, + + // ### Replace a selector's subviews + // + // By default, sets the `$target` selector's html to the subview `els`. + // + // Can be overridden in subclasses. + replace: function( $target, els ) { + $target.html( els ); + return this; + }, + + // ### Insert subviews into a selector + // + // By default, appends the subview `els` to the end of the `$target` + // selector. If `options.at` is set, inserts the subview `els` at the + // provided index. + // + // Can be overridden in subclasses. + insert: function( $target, els, options ) { + var at = options && options.at, + $children; + + if ( _.isNumber( at ) && ($children = $target.children()).length > at ) + $children.eq( at ).before( els ); + else + $target.append( els ); + + return this; + }, + + // ### Trigger the ready event + // + // **Only use this method if you know what you're doing.** + // For performance reasons, this method does not check if the view is + // actually attached to the DOM. It's taking your word for it. + // + // Fires the ready event on the current view and all attached subviews. + ready: function() { + this.view.trigger('ready'); + + // Find all attached subviews, and call ready on them. + _.chain( this.all() ).map( function( view ) { + return view.views; + }).flatten().where({ attached: true }).invoke('ready'); + }, + + // #### Internal. Attaches a series of views to a selector. + // + // Checks to see if a matching selector exists, renders the views, + // performs the proper DOM operation, and then checks if the view is + // attached to the document. + _attach: function( selector, views, options ) { + var $selector = selector ? this.view.$( selector ) : this.view.$el, + managers; + + // Check if we found a location to attach the views. + if ( ! $selector.length ) + return this; + + managers = _.chain( views ).pluck('views').flatten().value(); + + // Render the views if necessary. + _.each( managers, function( manager ) { + if ( manager.rendered ) + return; + + manager.view.render(); + manager.rendered = true; + }, this ); + + // Insert or replace the views. + this[ options.add ? 'insert' : 'replace' ]( $selector, _.pluck( views, 'el' ), options ); + + // Set attached and trigger ready if the current view is already + // attached to the DOM. + _.each( managers, function( manager ) { + manager.attached = true; + + if ( options.ready ) + manager.ready(); + }, this ); + + return this; + }, + + // #### Internal. Checks if the current view is in the DOM. + _isReady: function() { + var node = this.view.el; + while ( node ) { + if ( node === document.body ) + return true; + node = node.parentNode; + } + + return false; + } + }); + + // wp.media.View + // ------------- + // + // The base view class. + media.View = Backbone.View.extend({ + // The constructor for the `Views` manager. + Views: media.Views, + + constructor: function( options ) { + this.views = new this.Views( this, this.views ); + this.on( 'ready', this.ready, this ); + + if ( options && options.controller ) + this.controller = options.controller; + + Backbone.View.apply( this, arguments ); + }, + + dispose: function() { + // Undelegating events, removing events from the model, and + // removing events from the controller mirror the code for + // `Backbone.View.dispose` in Backbone master. + this.undelegateEvents(); + + if ( this.model && this.model.off ) + this.model.off( null, null, this ); + + if ( this.collection && this.collection.off ) + this.collection.off( null, null, this ); + + // Unbind controller events. + if ( this.controller && this.controller.off ) + this.controller.off( null, null, this ); + + // Recursively dispose child views. + if ( this.views ) + this.views.dispose(); + + return this; + }, + + remove: function() { + this.dispose(); + return Backbone.View.prototype.remove.apply( this, arguments ); + }, + + render: function() { + var options; + + if ( this.prepare ) + options = this.prepare(); + + this.views.detach(); + + if ( this.template ) { + options = options || {}; + this.trigger( 'prepare', options ); + this.$el.html( this.template( options ) ); + } + + this.views.render(); + return this; + }, + + prepare: function() { + return this.options; + }, + + ready: function() {} + }); + + /** + * wp.media.view.Frame + */ + media.view.Frame = media.View.extend({ + initialize: function() { + this._createRegions(); + this._createStates(); + }, + + _createRegions: function() { + // Clone the regions array. + this.regions = this.regions ? this.regions.slice() : []; + + // Initialize regions. + _.each( this.regions, function( region ) { + this[ region ] = new media.controller.Region({ + view: this, + id: region, + selector: '.media-frame-' + region + }); + }, this ); + }, + + _createStates: function() { + // Create the default `states` collection. + this.states = new Backbone.Collection( null, { + model: media.controller.State + }); + + // Ensure states have a reference to the frame. + this.states.on( 'add', function( model ) { + model.frame = this; + model.trigger('ready'); + }, this ); + + if ( this.options.states ) + this.states.add( this.options.states ); + }, + + reset: function() { + this.states.invoke( 'trigger', 'reset' ); + return this; + } + }); + + // Make the `Frame` a `StateMachine`. + _.extend( media.view.Frame.prototype, media.controller.StateMachine.prototype ); + + /** + * wp.media.view.MediaFrame + */ + media.view.MediaFrame = media.view.Frame.extend({ + className: 'media-frame', + template: media.template('media-frame'), + regions: ['menu','title','content','toolbar','router'], + + initialize: function() { + media.view.Frame.prototype.initialize.apply( this, arguments ); + + _.defaults( this.options, { + title: '', + modal: true, + uploader: true + }); + + // Ensure core UI is enabled. + this.$el.addClass('wp-core-ui'); + + // Initialize modal container view. + if ( this.options.modal ) { + this.modal = new media.view.Modal({ + controller: this, + title: this.options.title + }); + + this.modal.content( this ); + } + + // Force the uploader off if the upload limit has been exceeded or + // if the browser isn't supported. + if ( wp.Uploader.limitExceeded || ! wp.Uploader.browser.supported ) + this.options.uploader = false; + + // Initialize window-wide uploader. + if ( this.options.uploader ) { + this.uploader = new media.view.UploaderWindow({ + controller: this, + uploader: { + dropzone: this.modal ? this.modal.$el : this.$el, + container: this.$el + } + }); + this.views.set( '.media-frame-uploader', this.uploader ); + } + + this.on( 'attach', _.bind( this.views.ready, this.views ), this ); + + // Bind default title creation. + this.on( 'title:create:default', this.createTitle, this ); + this.title.mode('default'); + + // Bind default menu. + this.on( 'menu:create:default', this.createMenu, this ); + }, + + render: function() { + // Activate the default state if no active state exists. + if ( ! this.state() && this.options.state ) + this.setState( this.options.state ); + + return media.view.Frame.prototype.render.apply( this, arguments ); + }, + + createTitle: function( title ) { + title.view = new media.View({ + controller: this, + tagName: 'h1' + }); + }, + + createMenu: function( menu ) { + menu.view = new media.view.Menu({ + controller: this + }); + }, + + createToolbar: function( toolbar ) { + toolbar.view = new media.view.Toolbar({ + controller: this + }); + }, + + createRouter: function( router ) { + router.view = new media.view.Router({ + controller: this + }); + }, + + createIframeStates: function( options ) { + var settings = media.view.settings, + tabs = settings.tabs, + tabUrl = settings.tabUrl, + $postId; + + if ( ! tabs || ! tabUrl ) + return; + + // Add the post ID to the tab URL if it exists. + $postId = $('#post_ID'); + if ( $postId.length ) + tabUrl += '&post_id=' + $postId.val(); + + // Generate the tab states. + _.each( tabs, function( title, id ) { + var frame = this.state( 'iframe:' + id ).set( _.defaults({ + tab: id, + src: tabUrl + '&tab=' + id, + title: title, + content: 'iframe', + menu: 'default' + }, options ) ); + }, this ); + + this.on( 'content:create:iframe', this.iframeContent, this ); + this.on( 'menu:render:default', this.iframeMenu, this ); + this.on( 'open', this.hijackThickbox, this ); + this.on( 'close', this.restoreThickbox, this ); + }, + + iframeContent: function( content ) { + this.$el.addClass('hide-toolbar'); + content.view = new media.view.Iframe({ + controller: this + }); + }, + + iframeMenu: function( view ) { + var views = {}; + + if ( ! view ) + return; + + _.each( media.view.settings.tabs, function( title, id ) { + views[ 'iframe:' + id ] = { + text: this.state( 'iframe:' + id ).get('title'), + priority: 200 + }; + }, this ); + + view.set( views ); + }, + + hijackThickbox: function() { + var frame = this; + + if ( ! window.tb_remove || this._tb_remove ) + return; + + this._tb_remove = window.tb_remove; + window.tb_remove = function() { + frame.close(); + frame.reset(); + frame.setState( frame.options.state ); + frame._tb_remove.call( window ); + }; + }, + + restoreThickbox: function() { + if ( ! this._tb_remove ) + return; + + window.tb_remove = this._tb_remove; + delete this._tb_remove; + } + }); + + // Map some of the modal's methods to the frame. + _.each(['open','close','attach','detach','escape'], function( method ) { + media.view.MediaFrame.prototype[ method ] = function( view ) { + if ( this.modal ) + this.modal[ method ].apply( this.modal, arguments ); + return this; + }; + }); + + /** + * wp.media.view.MediaFrame.Select + */ + media.view.MediaFrame.Select = media.view.MediaFrame.extend({ + initialize: function() { + media.view.MediaFrame.prototype.initialize.apply( this, arguments ); + + _.defaults( this.options, { + selection: [], + library: {}, + multiple: false, + state: 'library' + }); + + this.createSelection(); + this.createStates(); + this.bindHandlers(); + }, + + createSelection: function() { + var controller = this, + selection = this.options.selection; + + if ( ! (selection instanceof media.model.Selection) ) { + this.options.selection = new media.model.Selection( selection, { + multiple: this.options.multiple + }); + } + + this._selection = { + attachments: new Attachments(), + difference: [] + }; + }, + + createStates: function() { + var options = this.options; + + if ( this.options.states ) + return; + + // Add the default states. + this.states.add([ + // Main states. + new media.controller.Library({ + library: media.query( options.library ), + multiple: options.multiple, + title: options.title, + priority: 20 + }) + ]); + }, + + bindHandlers: function() { + this.on( 'router:create:browse', this.createRouter, this ); + this.on( 'router:render:browse', this.browseRouter, this ); + this.on( 'content:create:browse', this.browseContent, this ); + this.on( 'content:render:upload', this.uploadContent, this ); + this.on( 'toolbar:create:select', this.createSelectToolbar, this ); + }, + + // Routers + browseRouter: function( view ) { + view.set({ + upload: { + text: l10n.uploadFilesTitle, + priority: 20 + }, + browse: { + text: l10n.mediaLibraryTitle, + priority: 40 + } + }); + }, + + // Content + browseContent: function( content ) { + var state = this.state(); + + this.$el.removeClass('hide-toolbar'); + + // Browse our library of attachments. + content.view = new media.view.AttachmentsBrowser({ + controller: this, + collection: state.get('library'), + selection: state.get('selection'), + model: state, + sortable: state.get('sortable'), + search: state.get('searchable'), + filters: state.get('filterable'), + display: state.get('displaySettings'), + dragInfo: state.get('dragInfo'), + + AttachmentView: state.get('AttachmentView') + }); + }, + + uploadContent: function() { + this.$el.removeClass('hide-toolbar'); + this.content.set( new media.view.UploaderInline({ + controller: this + }) ); + }, + + // Toolbars + createSelectToolbar: function( toolbar, options ) { + options = options || this.options.button || {}; + options.controller = this; + + toolbar.view = new media.view.Toolbar.Select( options ); + } + }); + + /** + * wp.media.view.MediaFrame.Post + */ + media.view.MediaFrame.Post = media.view.MediaFrame.Select.extend({ + initialize: function() { + _.defaults( this.options, { + multiple: true, + editing: false, + state: 'insert' + }); + + media.view.MediaFrame.Select.prototype.initialize.apply( this, arguments ); + this.createIframeStates(); + }, + + createStates: function() { + var options = this.options; + + // Add the default states. + this.states.add([ + // Main states. + new media.controller.Library({ + id: 'insert', + title: l10n.insertMediaTitle, + priority: 20, + toolbar: 'main-insert', + filterable: 'all', + library: media.query( options.library ), + multiple: options.multiple ? 'reset' : false, + editable: true, + + // If the user isn't allowed to edit fields, + // can they still edit it locally? + allowLocalEdits: true, + + // Show the attachment display settings. + displaySettings: true, + // Update user settings when users adjust the + // attachment display settings. + displayUserSettings: true + }), + + new media.controller.Library({ + id: 'gallery', + title: l10n.createGalleryTitle, + priority: 40, + toolbar: 'main-gallery', + filterable: 'uploaded', + multiple: 'add', + editable: false, + + library: media.query( _.defaults({ + type: 'image' + }, options.library ) ) + }), + + // Embed states. + new media.controller.Embed(), + + // Gallery states. + new media.controller.GalleryEdit({ + library: options.selection, + editing: options.editing, + menu: 'gallery' + }), + + new media.controller.GalleryAdd() + ]); + + + if ( media.view.settings.post.featuredImageId ) { + this.states.add( new media.controller.FeaturedImage() ); + } + }, + + bindHandlers: function() { + media.view.MediaFrame.Select.prototype.bindHandlers.apply( this, arguments ); + this.on( 'menu:create:gallery', this.createMenu, this ); + this.on( 'toolbar:create:main-insert', this.createToolbar, this ); + this.on( 'toolbar:create:main-gallery', this.createToolbar, this ); + this.on( 'toolbar:create:featured-image', this.featuredImageToolbar, this ); + this.on( 'toolbar:create:main-embed', this.mainEmbedToolbar, this ); + + var handlers = { + menu: { + 'default': 'mainMenu', + 'gallery': 'galleryMenu' + }, + + content: { + 'embed': 'embedContent', + 'edit-selection': 'editSelectionContent' + }, + + toolbar: { + 'main-insert': 'mainInsertToolbar', + 'main-gallery': 'mainGalleryToolbar', + 'gallery-edit': 'galleryEditToolbar', + 'gallery-add': 'galleryAddToolbar' + } + }; + + _.each( handlers, function( regionHandlers, region ) { + _.each( regionHandlers, function( callback, handler ) { + this.on( region + ':render:' + handler, this[ callback ], this ); + }, this ); + }, this ); + }, + + // Menus + mainMenu: function( view ) { + view.set({ + 'library-separator': new media.View({ + className: 'separator', + priority: 100 + }) + }); + }, + + galleryMenu: function( view ) { + var lastState = this.lastState(), + previous = lastState && lastState.id, + frame = this; + + view.set({ + cancel: { + text: l10n.cancelGalleryTitle, + priority: 20, + click: function() { + if ( previous ) + frame.setState( previous ); + else + frame.close(); + } + }, + separateCancel: new media.View({ + className: 'separator', + priority: 40 + }) + }); + }, + + // Content + embedContent: function() { + var view = new media.view.Embed({ + controller: this, + model: this.state() + }).render(); + + this.content.set( view ); + view.url.focus(); + }, + + editSelectionContent: function() { + var state = this.state(), + selection = state.get('selection'), + view; + + view = new media.view.AttachmentsBrowser({ + controller: this, + collection: selection, + selection: selection, + model: state, + sortable: true, + search: false, + dragInfo: true, + + AttachmentView: media.view.Attachment.EditSelection + }).render(); + + view.toolbar.set( 'backToLibrary', { + text: l10n.returnToLibrary, + priority: -100, + + click: function() { + this.controller.content.mode('browse'); + } + }); + + // Browse our library of attachments. + this.content.set( view ); + }, + + // Toolbars + selectionStatusToolbar: function( view ) { + var editable = this.state().get('editable'); + + view.set( 'selection', new media.view.Selection({ + controller: this, + collection: this.state().get('selection'), + priority: -40, + + // If the selection is editable, pass the callback to + // switch the content mode. + editable: editable && function() { + this.controller.content.mode('edit-selection'); + } + }).render() ); + }, + + mainInsertToolbar: function( view ) { + var controller = this; + + this.selectionStatusToolbar( view ); + + view.set( 'insert', { + style: 'primary', + priority: 80, + text: l10n.insertIntoPost, + requires: { selection: true }, + + click: function() { + var state = controller.state(), + selection = state.get('selection'); + + controller.close(); + state.trigger( 'insert', selection ).reset(); + } + }); + }, + + mainGalleryToolbar: function( view ) { + var controller = this; + + this.selectionStatusToolbar( view ); + + view.set( 'gallery', { + style: 'primary', + text: l10n.createNewGallery, + priority: 60, + requires: { selection: true }, + + click: function() { + var selection = controller.state().get('selection'), + edit = controller.state('gallery-edit'), + models = selection.where({ type: 'image' }); + + edit.set( 'library', new media.model.Selection( models, { + props: selection.props.toJSON(), + multiple: true + }) ); + + this.controller.setState('gallery-edit'); + } + }); + }, + + featuredImageToolbar: function( toolbar ) { + this.createSelectToolbar( toolbar, { + text: l10n.setFeaturedImage, + state: this.options.state || 'upload' + }); + }, + + mainEmbedToolbar: function( toolbar ) { + toolbar.view = new media.view.Toolbar.Embed({ + controller: this + }); + }, + + galleryEditToolbar: function() { + var editing = this.state().get('editing'); + this.toolbar.set( new media.view.Toolbar({ + controller: this, + items: { + insert: { + style: 'primary', + text: editing ? l10n.updateGallery : l10n.insertGallery, + priority: 80, + requires: { library: true }, + + click: function() { + var controller = this.controller, + state = controller.state(); + + controller.close(); + state.trigger( 'update', state.get('library') ); + + controller.reset(); + // @todo: Make the state activated dynamic (instead of hardcoded). + controller.setState('upload'); + } + } + } + }) ); + }, + + galleryAddToolbar: function() { + this.toolbar.set( new media.view.Toolbar({ + controller: this, + items: { + insert: { + style: 'primary', + text: l10n.addToGallery, + priority: 80, + requires: { selection: true }, + + click: function() { + var controller = this.controller, + state = controller.state(), + edit = controller.state('gallery-edit'); + + edit.get('library').add( state.get('selection').models ); + state.trigger('reset'); + controller.setState('gallery-edit'); + } + } + } + }) ); + } + }); + + /** + * wp.media.view.Modal + */ + media.view.Modal = media.View.extend({ + tagName: 'div', + template: media.template('media-modal'), + + attributes: { + tabindex: 0 + }, + + events: { + 'click .media-modal-backdrop, .media-modal-close': 'escapeHandler', + 'keydown': 'keydown' + }, + + initialize: function() { + _.defaults( this.options, { + container: document.body, + title: '', + propagate: true, + freeze: true + }); + }, + + prepare: function() { + return { + title: this.options.title + }; + }, + + attach: function() { + if ( this.views.attached ) + return this; + + if ( ! this.views.rendered ) + this.render(); + + this.$el.appendTo( this.options.container ); + + // Manually mark the view as attached and trigger ready. + this.views.attached = true; + this.views.ready(); + + return this.propagate('attach'); + }, + + detach: function() { + if ( this.$el.is(':visible') ) + this.close(); + + this.$el.detach(); + this.views.attached = false; + return this.propagate('detach'); + }, + + open: function() { + var $el = this.$el, + options = this.options; + + if ( $el.is(':visible') ) + return this; + + if ( ! this.views.attached ) + this.attach(); + + // If the `freeze` option is set, record the window's scroll position. + if ( options.freeze ) { + this._freeze = { + scrollTop: $( window ).scrollTop() + }; + } + + $el.show().focus(); + return this.propagate('open'); + }, + + close: function( options ) { + var freeze = this._freeze; + + if ( ! this.views.attached || ! this.$el.is(':visible') ) + return this; + + this.$el.hide(); + this.propagate('close'); + + // If the `freeze` option is set, restore the container's scroll position. + if ( freeze ) { + $( window ).scrollTop( freeze.scrollTop ); + } + + if ( options && options.escape ) + this.propagate('escape'); + + return this; + }, + + escape: function() { + return this.close({ escape: true }); + }, + + escapeHandler: function( event ) { + event.preventDefault(); + this.escape(); + }, + + content: function( content ) { + this.views.set( '.media-modal-content', content ); + return this; + }, + + // Triggers a modal event and if the `propagate` option is set, + // forwards events to the modal's controller. + propagate: function( id ) { + this.trigger( id ); + + if ( this.options.propagate ) + this.controller.trigger( id ); + + return this; + }, + + keydown: function( event ) { + // Close the modal when escape is pressed. + if ( 27 === event.which ) { + event.preventDefault(); + this.escape(); + return; + } + } + }); + + // wp.media.view.FocusManager + // ---------------------------- + media.view.FocusManager = media.View.extend({ + events: { + keydown: 'recordTab', + focusin: 'updateIndex' + }, + + focus: function() { + if ( _.isUndefined( this.index ) ) + return; + + // Update our collection of `$tabbables`. + this.$tabbables = this.$(':tabbable'); + + // If tab is saved, focus it. + this.$tabbables.eq( this.index ).focus(); + }, + + recordTab: function( event ) { + // Look for the tab key. + if ( 9 !== event.keyCode ) + return; + + // First try to update the index. + if ( _.isUndefined( this.index ) ) + this.updateIndex( event ); + + // If we still don't have an index, bail. + if ( _.isUndefined( this.index ) ) + return; + + var index = this.index + ( event.shiftKey ? -1 : 1 ); + + if ( index >= 0 && index < this.$tabbables.length ) + this.index = index; + else + delete this.index; + }, + + updateIndex: function( event ) { + this.$tabbables = this.$(':tabbable'); + + var index = this.$tabbables.index( event.target ); + + if ( -1 === index ) + delete this.index; + else + this.index = index; + } + }); + + // wp.media.view.UploaderWindow + // ---------------------------- + media.view.UploaderWindow = media.View.extend({ + tagName: 'div', + className: 'uploader-window', + template: media.template('uploader-window'), + + initialize: function() { + var uploader; + + this.$browser = $('').hide().appendTo('body'); + + uploader = this.options.uploader = _.defaults( this.options.uploader || {}, { + dropzone: this.$el, + browser: this.$browser, + params: {} + }); + + // Ensure the dropzone is a jQuery collection. + if ( uploader.dropzone && ! (uploader.dropzone instanceof $) ) + uploader.dropzone = $( uploader.dropzone ); + + this.controller.on( 'activate', this.refresh, this ); + }, + + refresh: function() { + if ( this.uploader ) + this.uploader.refresh(); + }, + + ready: function() { + var postId = media.view.settings.post.id, + dropzone; + + // If the uploader already exists, bail. + if ( this.uploader ) + return; + + if ( postId ) + this.options.uploader.params.post_id = postId; + + this.uploader = new wp.Uploader( this.options.uploader ); + + dropzone = this.uploader.dropzone; + dropzone.on( 'dropzone:enter', _.bind( this.show, this ) ); + dropzone.on( 'dropzone:leave', _.bind( this.hide, this ) ); + }, + + show: function() { + var $el = this.$el.show(); + + // Ensure that the animation is triggered by waiting until + // the transparent element is painted into the DOM. + _.defer( function() { + $el.css({ opacity: 1 }); + }); + }, + + hide: function() { + var $el = this.$el.css({ opacity: 0 }); + + media.transition( $el ).done( function() { + // Transition end events are subject to race conditions. + // Make sure that the value is set as intended. + if ( '0' === $el.css('opacity') ) + $el.hide(); + }); + } + }); + + media.view.UploaderInline = media.View.extend({ + tagName: 'div', + className: 'uploader-inline', + template: media.template('uploader-inline'), + + initialize: function() { + _.defaults( this.options, { + message: '', + status: true + }); + + if ( ! this.options.$browser && this.controller.uploader ) + this.options.$browser = this.controller.uploader.$browser; + + if ( _.isUndefined( this.options.postId ) ) + this.options.postId = media.view.settings.post.id; + + if ( this.options.status ) { + this.views.set( '.upload-inline-status', new media.view.UploaderStatus({ + controller: this.controller + }) ); + } + }, + + dispose: function() { + if ( this.disposing ) + return media.View.prototype.dispose.apply( this, arguments ); + + // Run remove on `dispose`, so we can be sure to refresh the + // uploader with a view-less DOM. Track whether we're disposing + // so we don't trigger an infinite loop. + this.disposing = true; + return this.remove(); + }, + + remove: function() { + var result = media.View.prototype.remove.apply( this, arguments ); + + _.defer( _.bind( this.refresh, this ) ); + return result; + }, + + refresh: function() { + var uploader = this.controller.uploader; + + if ( uploader ) + uploader.refresh(); + }, + + ready: function() { + var $browser = this.options.$browser, + $placeholder; + + if ( this.controller.uploader ) { + $placeholder = this.$('.browser'); + + // Check if we've already replaced the placeholder. + if ( $placeholder[0] === $browser[0] ) + return; + + $browser.detach().text( $placeholder.text() ); + $browser[0].className = $placeholder[0].className; + $placeholder.replaceWith( $browser.show() ); + } + + this.refresh(); + return this; + } + }); + + /** + * wp.media.view.UploaderStatus + */ + media.view.UploaderStatus = media.View.extend({ + className: 'media-uploader-status', + template: media.template('uploader-status'), + + events: { + 'click .upload-dismiss-errors': 'dismiss' + }, + + initialize: function() { + this.queue = wp.Uploader.queue; + this.queue.on( 'add remove reset', this.visibility, this ); + this.queue.on( 'add remove reset change:percent', this.progress, this ); + this.queue.on( 'add remove reset change:uploading', this.info, this ); + + this.errors = wp.Uploader.errors; + this.errors.reset(); + this.errors.on( 'add remove reset', this.visibility, this ); + this.errors.on( 'add', this.error, this ); + }, + + dispose: function() { + wp.Uploader.queue.off( null, null, this ); + media.View.prototype.dispose.apply( this, arguments ); + return this; + }, + + visibility: function() { + this.$el.toggleClass( 'uploading', !! this.queue.length ); + this.$el.toggleClass( 'errors', !! this.errors.length ); + this.$el.toggle( !! this.queue.length || !! this.errors.length ); + }, + + ready: function() { + _.each({ + '$bar': '.media-progress-bar div', + '$index': '.upload-index', + '$total': '.upload-total', + '$filename': '.upload-filename' + }, function( selector, key ) { + this[ key ] = this.$( selector ); + }, this ); + + this.visibility(); + this.progress(); + this.info(); + }, + + progress: function() { + var queue = this.queue, + $bar = this.$bar, + memo = 0; + + if ( ! $bar || ! queue.length ) + return; + + $bar.width( ( queue.reduce( function( memo, attachment ) { + if ( ! attachment.get('uploading') ) + return memo + 100; + + var percent = attachment.get('percent'); + return memo + ( _.isNumber( percent ) ? percent : 100 ); + }, 0 ) / queue.length ) + '%' ); + }, + + info: function() { + var queue = this.queue, + index = 0, active; + + if ( ! queue.length ) + return; + + active = this.queue.find( function( attachment, i ) { + index = i; + return attachment.get('uploading'); + }); + + this.$index.text( index + 1 ); + this.$total.text( queue.length ); + this.$filename.html( active ? this.filename( active.get('filename') ) : '' ); + }, + + filename: function( filename ) { + return media.truncate( _.escape( filename ), 24 ); + }, + + error: function( error ) { + this.views.add( '.upload-errors', new media.view.UploaderStatusError({ + filename: this.filename( error.get('file').name ), + message: error.get('message') + }), { at: 0 }); + }, + + dismiss: function( event ) { + var errors = this.views.get('.upload-errors'); + + event.preventDefault(); + + if ( errors ) + _.invoke( errors, 'remove' ); + wp.Uploader.errors.reset(); + } + }); + + media.view.UploaderStatusError = media.View.extend({ + className: 'upload-error', + template: media.template('uploader-status-error') + }); + + /** + * wp.media.view.Toolbar + */ + media.view.Toolbar = media.View.extend({ + tagName: 'div', + className: 'media-toolbar', + + initialize: function() { + var state = this.controller.state(), + selection = this.selection = state.get('selection'), + library = this.library = state.get('library'); + + this._views = {}; + + // The toolbar is composed of two `PriorityList` views. + this.primary = new media.view.PriorityList(); + this.secondary = new media.view.PriorityList(); + this.primary.$el.addClass('media-toolbar-primary'); + this.secondary.$el.addClass('media-toolbar-secondary'); + + this.views.set([ this.secondary, this.primary ]); + + if ( this.options.items ) + this.set( this.options.items, { silent: true }); + + if ( ! this.options.silent ) + this.render(); + + if ( selection ) + selection.on( 'add remove reset', this.refresh, this ); + if ( library ) + library.on( 'add remove reset', this.refresh, this ); + }, + + dispose: function() { + if ( this.selection ) + this.selection.off( null, null, this ); + if ( this.library ) + this.library.off( null, null, this ); + return media.View.prototype.dispose.apply( this, arguments ); + }, + + ready: function() { + this.refresh(); + }, + + set: function( id, view, options ) { + var list; + options = options || {}; + + // Accept an object with an `id` : `view` mapping. + if ( _.isObject( id ) ) { + _.each( id, function( view, id ) { + this.set( id, view, { silent: true }); + }, this ); + + } else { + if ( ! ( view instanceof Backbone.View ) ) { + view.classes = [ 'media-button-' + id ].concat( view.classes || [] ); + view = new media.view.Button( view ).render(); + } + + view.controller = view.controller || this.controller; + + this._views[ id ] = view; + + list = view.options.priority < 0 ? 'secondary' : 'primary'; + this[ list ].set( id, view, options ); + } + + if ( ! options.silent ) + this.refresh(); + + return this; + }, + + get: function( id ) { + return this._views[ id ]; + }, + + unset: function( id, options ) { + delete this._views[ id ]; + this.primary.unset( id, options ); + this.secondary.unset( id, options ); + + if ( ! options || ! options.silent ) + this.refresh(); + return this; + }, + + refresh: function() { + var state = this.controller.state(), + library = state.get('library'), + selection = state.get('selection'); + + _.each( this._views, function( button ) { + if ( ! button.model || ! button.options || ! button.options.requires ) + return; + + var requires = button.options.requires, + disabled = false; + + if ( requires.selection && selection && ! selection.length ) + disabled = true; + else if ( requires.library && library && ! library.length ) + disabled = true; + + button.model.set( 'disabled', disabled ); + }); + } + }); + + // wp.media.view.Toolbar.Select + // ---------------------------- + media.view.Toolbar.Select = media.view.Toolbar.extend({ + initialize: function() { + var options = this.options, + controller = options.controller, + selection = controller.state().get('selection'); + + _.bindAll( this, 'clickSelect' ); + + _.defaults( options, { + event: 'select', + state: false, + reset: true, + close: true, + text: l10n.select, + + // Does the button rely on the selection? + requires: { + selection: true + } + }); + + options.items = _.defaults( options.items || {}, { + select: { + style: 'primary', + text: options.text, + priority: 80, + click: this.clickSelect, + requires: options.requires + } + }); + + media.view.Toolbar.prototype.initialize.apply( this, arguments ); + }, + + clickSelect: function() { + var options = this.options, + controller = this.controller; + + if ( options.close ) + controller.close(); + + if ( options.event ) + controller.state().trigger( options.event ); + + if ( options.reset ) + controller.reset(); + + if ( options.state ) + controller.setState( options.state ); + } + }); + + // wp.media.view.Toolbar.Embed + // --------------------------- + media.view.Toolbar.Embed = media.view.Toolbar.Select.extend({ + initialize: function() { + _.defaults( this.options, { + text: l10n.insertIntoPost, + requires: false + }); + + media.view.Toolbar.Select.prototype.initialize.apply( this, arguments ); + }, + + refresh: function() { + var url = this.controller.state().props.get('url'); + this.get('select').model.set( 'disabled', ! url || url === 'http://' ); + + media.view.Toolbar.Select.prototype.refresh.apply( this, arguments ); + } + }); + + /** + * wp.media.view.Button + */ + media.view.Button = media.View.extend({ + tagName: 'a', + className: 'media-button', + attributes: { href: '#' }, + + events: { + 'click': 'click' + }, + + defaults: { + text: '', + style: '', + size: 'large', + disabled: false + }, + + initialize: function() { + // Create a model with the provided `defaults`. + this.model = new Backbone.Model( this.defaults ); + + // If any of the `options` have a key from `defaults`, apply its + // value to the `model` and remove it from the `options object. + _.each( this.defaults, function( def, key ) { + var value = this.options[ key ]; + if ( _.isUndefined( value ) ) + return; + + this.model.set( key, value ); + delete this.options[ key ]; + }, this ); + + this.model.on( 'change', this.render, this ); + }, + + render: function() { + var classes = [ 'button', this.className ], + model = this.model.toJSON(); + + if ( model.style ) + classes.push( 'button-' + model.style ); + + if ( model.size ) + classes.push( 'button-' + model.size ); + + classes = _.uniq( classes.concat( this.options.classes ) ); + this.el.className = classes.join(' '); + + this.$el.attr( 'disabled', model.disabled ); + this.$el.text( this.model.get('text') ); + + return this; + }, + + click: function( event ) { + if ( '#' === this.attributes.href ) + event.preventDefault(); + + if ( this.options.click && ! this.model.get('disabled') ) + this.options.click.apply( this, arguments ); + } + }); + + /** + * wp.media.view.ButtonGroup + */ + media.view.ButtonGroup = media.View.extend({ + tagName: 'div', + className: 'button-group button-large media-button-group', + + initialize: function() { + this.buttons = _.map( this.options.buttons || [], function( button ) { + if ( button instanceof Backbone.View ) + return button; + else + return new media.view.Button( button ).render(); + }); + + delete this.options.buttons; + + if ( this.options.classes ) + this.$el.addClass( this.options.classes ); + }, + + render: function() { + this.$el.html( $( _.pluck( this.buttons, 'el' ) ).detach() ); + return this; + } + }); + + /** + * wp.media.view.PriorityList + */ + + media.view.PriorityList = media.View.extend({ + tagName: 'div', + + initialize: function() { + this._views = {}; + + this.set( _.extend( {}, this._views, this.options.views ), { silent: true }); + delete this.options.views; + + if ( ! this.options.silent ) + this.render(); + }, + + set: function( id, view, options ) { + var priority, views, index; + + options = options || {}; + + // Accept an object with an `id` : `view` mapping. + if ( _.isObject( id ) ) { + _.each( id, function( view, id ) { + this.set( id, view ); + }, this ); + return this; + } + + if ( ! (view instanceof Backbone.View) ) + view = this.toView( view, id, options ); + + view.controller = view.controller || this.controller; + + this.unset( id ); + + priority = view.options.priority || 10; + views = this.views.get() || []; + + _.find( views, function( existing, i ) { + if ( existing.options.priority > priority ) { + index = i; + return true; + } + }); + + this._views[ id ] = view; + this.views.add( view, { + at: _.isNumber( index ) ? index : views.length || 0 + }); + + return this; + }, + + get: function( id ) { + return this._views[ id ]; + }, + + unset: function( id ) { + var view = this.get( id ); + + if ( view ) + view.remove(); + + delete this._views[ id ]; + return this; + }, + + toView: function( options ) { + return new media.View( options ); + } + }); + + /** + * wp.media.view.MenuItem + */ + media.view.MenuItem = media.View.extend({ + tagName: 'a', + className: 'media-menu-item', + + attributes: { + href: '#' + }, + + events: { + 'click': '_click' + }, + + _click: function( event ) { + var clickOverride = this.options.click; + + if ( event ) + event.preventDefault(); + + if ( clickOverride ) + clickOverride.call( this ); + else + this.click(); + }, + + click: function() { + var state = this.options.state; + if ( state ) + this.controller.setState( state ); + }, + + render: function() { + var options = this.options; + + if ( options.text ) + this.$el.text( options.text ); + else if ( options.html ) + this.$el.html( options.html ); + + return this; + } + }); + + /** + * wp.media.view.Menu + */ + media.view.Menu = media.view.PriorityList.extend({ + tagName: 'div', + className: 'media-menu', + property: 'state', + ItemView: media.view.MenuItem, + region: 'menu', + + toView: function( options, id ) { + options = options || {}; + options[ this.property ] = options[ this.property ] || id; + return new this.ItemView( options ).render(); + }, + + ready: function() { + media.view.PriorityList.prototype.ready.apply( this, arguments ); + this.visibility(); + }, + + set: function() { + media.view.PriorityList.prototype.set.apply( this, arguments ); + this.visibility(); + }, + + unset: function() { + media.view.PriorityList.prototype.unset.apply( this, arguments ); + this.visibility(); + }, + + visibility: function() { + var region = this.region, + view = this.controller[ region ].get(), + views = this.views.get(), + hide = ! views || views.length < 2; + + if ( this === view ) + this.controller.$el.toggleClass( 'hide-' + region, hide ); + }, + + select: function( id ) { + var view = this.get( id ); + + if ( ! view ) + return; + + this.deselect(); + view.$el.addClass('active'); + }, + + deselect: function() { + this.$el.children().removeClass('active'); + } + }); + + /** + * wp.media.view.RouterItem + */ + media.view.RouterItem = media.view.MenuItem.extend({ + click: function() { + var contentMode = this.options.contentMode; + if ( contentMode ) + this.controller.content.mode( contentMode ); + } + }); + + /** + * wp.media.view.Router + */ + media.view.Router = media.view.Menu.extend({ + tagName: 'div', + className: 'media-router', + property: 'contentMode', + ItemView: media.view.RouterItem, + region: 'router', + + initialize: function() { + this.controller.on( 'content:render', this.update, this ); + media.view.Menu.prototype.initialize.apply( this, arguments ); + }, + + update: function() { + var mode = this.controller.content.mode(); + if ( mode ) + this.select( mode ); + } + }); + + + /** + * wp.media.view.Sidebar + */ + media.view.Sidebar = media.view.PriorityList.extend({ + className: 'media-sidebar' + }); + + /** + * wp.media.view.Attachment + */ + media.view.Attachment = media.View.extend({ + tagName: 'li', + className: 'attachment', + template: media.template('attachment'), + + events: { + 'click .attachment-preview': 'toggleSelectionHandler', + 'change [data-setting]': 'updateSetting', + 'change [data-setting] input': 'updateSetting', + 'change [data-setting] select': 'updateSetting', + 'change [data-setting] textarea': 'updateSetting', + 'click .close': 'removeFromLibrary', + 'click .check': 'removeFromSelection', + 'click a': 'preventDefault' + }, + + buttons: {}, + + initialize: function() { + var selection = this.options.selection; + + this.model.on( 'change:sizes change:uploading change:caption change:title', this.render, this ); + this.model.on( 'change:percent', this.progress, this ); + + // Update the selection. + this.model.on( 'add', this.select, this ); + this.model.on( 'remove', this.deselect, this ); + if ( selection ) + selection.on( 'reset', this.updateSelect, this ); + + // Update the model's details view. + this.model.on( 'selection:single selection:unsingle', this.details, this ); + this.details( this.model, this.controller.state().get('selection') ); + }, + + dispose: function() { + var selection = this.options.selection; + + // Make sure all settings are saved before removing the view. + this.updateAll(); + + if ( selection ) + selection.off( null, null, this ); + + media.View.prototype.dispose.apply( this, arguments ); + return this; + }, + + render: function() { + var options = _.defaults( this.model.toJSON(), { + orientation: 'landscape', + uploading: false, + type: '', + subtype: '', + icon: '', + filename: '', + caption: '', + title: '', + dateFormatted: '', + width: '', + height: '', + compat: false, + alt: '', + description: '' + }); + + options.buttons = this.buttons; + options.describe = this.controller.state().get('describe'); + + if ( 'image' === options.type ) + options.size = this.imageSize(); + + options.can = {}; + if ( options.nonces ) { + options.can.remove = !! options.nonces['delete']; + options.can.save = !! options.nonces.update; + } + + if ( this.controller.state().get('allowLocalEdits') ) + options.allowLocalEdits = true; + + this.views.detach(); + this.$el.html( this.template( options ) ); + + this.$el.toggleClass( 'uploading', options.uploading ); + if ( options.uploading ) + this.$bar = this.$('.media-progress-bar div'); + else + delete this.$bar; + + // Check if the model is selected. + this.updateSelect(); + + // Update the save status. + this.updateSave(); + + this.views.render(); + + return this; + }, + + progress: function() { + if ( this.$bar && this.$bar.length ) + this.$bar.width( this.model.get('percent') + '%' ); + }, + + toggleSelectionHandler: function( event ) { + var method; + + if ( event.shiftKey ) + method = 'between'; + else if ( event.ctrlKey || event.metaKey ) + method = 'toggle'; + + this.toggleSelection({ + method: method + }); + }, + + toggleSelection: function( options ) { + var collection = this.collection, + selection = this.options.selection, + model = this.model, + method = options && options.method, + single, between, models, singleIndex, modelIndex; + + if ( ! selection ) + return; + + single = selection.single(); + method = _.isUndefined( method ) ? selection.multiple : method; + + // If the `method` is set to `between`, select all models that + // exist between the current and the selected model. + if ( 'between' === method && single && selection.multiple ) { + // If the models are the same, short-circuit. + if ( single === model ) + return; + + singleIndex = collection.indexOf( single ); + modelIndex = collection.indexOf( this.model ); + + if ( singleIndex < modelIndex ) + models = collection.models.slice( singleIndex, modelIndex + 1 ); + else + models = collection.models.slice( modelIndex, singleIndex + 1 ); + + selection.add( models ).single( model ); + return; + + // If the `method` is set to `toggle`, just flip the selection + // status, regardless of whether the model is the single model. + } else if ( 'toggle' === method ) { + selection[ this.selected() ? 'remove' : 'add' ]( model ).single( model ); + return; + } + + if ( method !== 'add' ) + method = 'reset'; + + if ( this.selected() ) { + // If the model is the single model, remove it. + // If it is not the same as the single model, + // it now becomes the single model. + selection[ single === model ? 'remove' : 'single' ]( model ); + } else { + // If the model is not selected, run the `method` on the + // selection. By default, we `reset` the selection, but the + // `method` can be set to `add` the model to the selection. + selection[ method ]( model ).single( model ); + } + }, + + updateSelect: function() { + this[ this.selected() ? 'select' : 'deselect' ](); + }, + + selected: function() { + var selection = this.options.selection; + if ( selection ) + return !! selection.getByCid( this.model.cid ); + }, + + select: function( model, collection ) { + var selection = this.options.selection; + + // Check if a selection exists and if it's the collection provided. + // If they're not the same collection, bail; we're in another + // selection's event loop. + if ( ! selection || ( collection && collection !== selection ) ) + return; + + this.$el.addClass('selected'); + }, + + deselect: function( model, collection ) { + var selection = this.options.selection; + + // Check if a selection exists and if it's the collection provided. + // If they're not the same collection, bail; we're in another + // selection's event loop. + if ( ! selection || ( collection && collection !== selection ) ) + return; + + this.$el.removeClass('selected'); + }, + + details: function( model, collection ) { + var selection = this.options.selection, + details; + + if ( selection !== collection ) + return; + + details = selection.single(); + this.$el.toggleClass( 'details', details === this.model ); + }, + + preventDefault: function( event ) { + event.preventDefault(); + }, + + imageSize: function( size ) { + var sizes = this.model.get('sizes'); + + size = size || 'medium'; + + // Use the provided image size if possible. + if ( sizes && sizes[ size ] ) { + return _.clone( sizes[ size ] ); + } else { + return { + url: this.model.get('url'), + width: this.model.get('width'), + height: this.model.get('height'), + orientation: this.model.get('orientation') + }; + } + }, + + updateSetting: function( event ) { + var $setting = $( event.target ).closest('[data-setting]'), + setting, value; + + if ( ! $setting.length ) + return; + + setting = $setting.data('setting'); + value = event.target.value; + + if ( this.model.get( setting ) !== value ) + this.save( setting, value ); + }, + + // Pass all the arguments to the model's save method. + // + // Records the aggregate status of all save requests and updates the + // view's classes accordingly. + save: function() { + var view = this, + save = this._save = this._save || { status: 'ready' }, + request = this.model.save.apply( this.model, arguments ), + requests = save.requests ? $.when( request, save.requests ) : request; + + // If we're waiting to remove 'Saved.', stop. + if ( save.savedTimer ) + clearTimeout( save.savedTimer ); + + this.updateSave('waiting'); + save.requests = requests; + requests.always( function() { + // If we've performed another request since this one, bail. + if ( save.requests !== requests ) + return; + + view.updateSave( requests.state() === 'resolved' ? 'complete' : 'error' ); + save.savedTimer = setTimeout( function() { + view.updateSave('ready'); + delete save.savedTimer; + }, 2000 ); + }); + + }, + + updateSave: function( status ) { + var save = this._save = this._save || { status: 'ready' }; + + if ( status && status !== save.status ) { + this.$el.removeClass( 'save-' + save.status ); + save.status = status; + } + + this.$el.addClass( 'save-' + save.status ); + return this; + }, + + updateAll: function() { + var $settings = this.$('[data-setting]'), + model = this.model, + changed; + + changed = _.chain( $settings ).map( function( el ) { + var $input = $('input, textarea, select, [value]', el ), + setting, value; + + if ( ! $input.length ) + return; + + setting = $(el).data('setting'); + value = $input.val(); + + // Record the value if it changed. + if ( model.get( setting ) !== value ) + return [ setting, value ]; + }).compact().object().value(); + + if ( ! _.isEmpty( changed ) ) + model.save( changed ); + }, + + removeFromLibrary: function( event ) { + // Stop propagation so the model isn't selected. + event.stopPropagation(); + + this.collection.remove( this.model ); + }, + + removeFromSelection: function( event ) { + var selection = this.options.selection; + if ( ! selection ) + return; + + // Stop propagation so the model isn't selected. + event.stopPropagation(); + + selection.remove( this.model ); + } + }); + + /** + * wp.media.view.Attachment.Library + */ + media.view.Attachment.Library = media.view.Attachment.extend({ + buttons: { + check: true + } + }); + + /** + * wp.media.view.Attachment.EditLibrary + */ + media.view.Attachment.EditLibrary = media.view.Attachment.extend({ + buttons: { + close: true + } + }); + + /** + * wp.media.view.Attachments + */ + media.view.Attachments = media.View.extend({ + tagName: 'ul', + className: 'attachments', + + cssTemplate: media.template('attachments-css'), + + events: { + 'scroll': 'scroll' + }, + + initialize: function() { + this.el.id = _.uniqueId('__attachments-view-'); + + _.defaults( this.options, { + refreshSensitivity: 200, + refreshThreshold: 3, + AttachmentView: media.view.Attachment, + sortable: false, + resize: true + }); + + this._viewsByCid = {}; + + this.collection.on( 'add', function( attachment, attachments, options ) { + this.views.add( this.createAttachmentView( attachment ), { + at: options.index + }); + }, this ); + + this.collection.on( 'remove', function( attachment, attachments, options ) { + var view = this._viewsByCid[ attachment.cid ]; + delete this._viewsByCid[ attachment.cid ]; + + if ( view ) + view.remove(); + }, this ); + + this.collection.on( 'reset', this.render, this ); + + // Throttle the scroll handler. + this.scroll = _.chain( this.scroll ).bind( this ).throttle( this.options.refreshSensitivity ).value(); + + this.initSortable(); + + _.bindAll( this, 'css' ); + this.model.on( 'change:edge change:gutter', this.css, this ); + this._resizeCss = _.debounce( _.bind( this.css, this ), this.refreshSensitivity ); + if ( this.options.resize ) + $(window).on( 'resize.attachments', this._resizeCss ); + this.css(); + }, + + dispose: function() { + this.collection.props.off( null, null, this ); + $(window).off( 'resize.attachments', this._resizeCss ); + media.View.prototype.dispose.apply( this, arguments ); + }, + + css: function() { + var $css = $( '#' + this.el.id + '-css' ); + + if ( $css.length ) + $css.remove(); + + media.view.Attachments.$head().append( this.cssTemplate({ + id: this.el.id, + edge: this.edge(), + gutter: this.model.get('gutter') + }) ); + }, + + edge: function() { + var edge = this.model.get('edge'), + gutter, width, columns; + + if ( ! this.$el.is(':visible') ) + return edge; + + gutter = this.model.get('gutter') * 2; + width = this.$el.width() - gutter; + columns = Math.ceil( width / ( edge + gutter ) ); + edge = Math.floor( ( width - ( columns * gutter ) ) / columns ); + return edge; + }, + + initSortable: function() { + var collection = this.collection; + + if ( ! this.options.sortable || ! $.fn.sortable ) + return; + + this.$el.sortable( _.extend({ + // If the `collection` has a `comparator`, disable sorting. + disabled: !! collection.comparator, + + // Prevent attachments from being dragged outside the bounding + // box of the list. + containment: this.$el, + + // Change the position of the attachment as soon as the + // mouse pointer overlaps a thumbnail. + tolerance: 'pointer', + + // Record the initial `index` of the dragged model. + start: function( event, ui ) { + ui.item.data('sortableIndexStart', ui.item.index()); + }, + + // Update the model's index in the collection. + // Do so silently, as the view is already accurate. + update: function( event, ui ) { + var model = collection.at( ui.item.data('sortableIndexStart') ), + comparator = collection.comparator; + + // Temporarily disable the comparator to prevent `add` + // from re-sorting. + delete collection.comparator; + + // Silently shift the model to its new index. + collection.remove( model, { + silent: true + }).add( model, { + silent: true, + at: ui.item.index() + }); + + // Restore the comparator. + collection.comparator = comparator; + + // Fire the `reset` event to ensure other collections sync. + collection.trigger( 'reset', collection ); + + // If the collection is sorted by menu order, + // update the menu order. + collection.saveMenuOrder(); + } + }, this.options.sortable ) ); + + // If the `orderby` property is changed on the `collection`, + // check to see if we have a `comparator`. If so, disable sorting. + collection.props.on( 'change:orderby', function() { + this.$el.sortable( 'option', 'disabled', !! collection.comparator ); + }, this ); + + this.collection.props.on( 'change:orderby', this.refreshSortable, this ); + this.refreshSortable(); + }, + + refreshSortable: function() { + if ( ! this.options.sortable || ! $.fn.sortable ) + return; + + // If the `collection` has a `comparator`, disable sorting. + var collection = this.collection, + orderby = collection.props.get('orderby'), + enabled = 'menuOrder' === orderby || ! collection.comparator; + + this.$el.sortable( 'option', 'disabled', ! enabled ); + }, + + createAttachmentView: function( attachment ) { + var view = new this.options.AttachmentView({ + controller: this.controller, + model: attachment, + collection: this.collection, + selection: this.options.selection + }); + + return this._viewsByCid[ attachment.cid ] = view; + }, + + prepare: function() { + // Create all of the Attachment views, and replace + // the list in a single DOM operation. + if ( this.collection.length ) { + this.views.set( this.collection.map( this.createAttachmentView, this ) ); + + // If there are no elements, clear the views and load some. + } else { + this.views.unset(); + this.collection.more().done( this.scroll ); + } + }, + + ready: function() { + // Trigger the scroll event to check if we're within the + // threshold to query for additional attachments. + this.scroll(); + }, + + scroll: function( event ) { + // @todo: is this still necessary? + if ( ! this.$el.is(':visible') ) + return; + + if ( this.collection.hasMore() && this.el.scrollHeight < this.el.scrollTop + ( this.el.clientHeight * this.options.refreshThreshold ) ) { + this.collection.more().done( this.scroll ); + } + } + }, { + $head: (function() { + var $head; + return function() { + return $head = $head || $('head'); + }; + }()) + }); + + /** + * wp.media.view.Search + */ + media.view.Search = media.View.extend({ + tagName: 'input', + className: 'search', + + attributes: { + type: 'search', + placeholder: l10n.search + }, + + events: { + 'input': 'search', + 'keyup': 'search', + 'change': 'search', + 'search': 'search' + }, + + render: function() { + this.el.value = this.model.escape('search'); + return this; + }, + + search: function( event ) { + if ( event.target.value ) + this.model.set( 'search', event.target.value ); + else + this.model.unset('search'); + } + }); + + /** + * wp.media.view.AttachmentFilters + */ + media.view.AttachmentFilters = media.View.extend({ + tagName: 'select', + className: 'attachment-filters', + + events: { + change: 'change' + }, + + keys: [], + + initialize: function() { + this.createFilters(); + _.extend( this.filters, this.options.filters ); + + // Build `
    + diff --git a/wp-includes/js/tinymce/wp-tinymce-schema.js b/wp-includes/js/tinymce/wp-tinymce-schema.js new file mode 100644 index 00000000..999687e6 --- /dev/null +++ b/wp-includes/js/tinymce/wp-tinymce-schema.js @@ -0,0 +1,940 @@ +/** + * TinyMCE Schema.js + * + * Duck-punched by WordPress core to support a sane schema superset. + * + * Copyright, Moxiecode Systems AB + * Released under LGPL License. + * + * License: http://www.tinymce.com/license + * Contributing: http://www.tinymce.com/contributing + */ + +(function(tinymce) { + var mapCache = {}, makeMap = tinymce.makeMap, each = tinymce.each; + + function split(str, delim) { + return str.split(delim || ','); + }; + + /** + * Unpacks the specified lookup and string data it will also parse it into an object + * map with sub object for it's children. This will later also include the attributes. + */ + function unpack(lookup, data) { + var key, elements = {}; + + function replace(value) { + return value.replace(/[A-Z]+/g, function(key) { + return replace(lookup[key]); + }); + }; + + // Unpack lookup + for (key in lookup) { + if (lookup.hasOwnProperty(key)) + lookup[key] = replace(lookup[key]); + } + + // Unpack and parse data into object map + replace(data).replace(/#/g, '#text').replace(/(\w+)\[([^\]]+)\]\[([^\]]*)\]/g, function(str, name, attributes, children) { + attributes = split(attributes, '|'); + + elements[name] = { + attributes : makeMap(attributes), + attributesOrder : attributes, + children : makeMap(children, '|', {'#comment' : {}}) + } + }); + + return elements; + }; + + /** + * Returns the HTML5 schema and caches it in the mapCache. + */ + function getHTML5() { + var html5 = mapCache.html5; + + if (!html5) { + html5 = mapCache.html5 = unpack({ + A : 'accesskey|class|contextmenu|dir|draggable|dropzone|hidden|id|inert|itemid|itemprop|itemref|itemscope|itemtype|lang|spellcheck|style|tabindex|title|translate|item|role|subject|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup', + B : '#|a|abbr|area|audio|b|bdi|bdo|br|button|canvas|cite|code|command|data|datalist|del|dfn|em|embed|i|iframe|img|input|ins|kbd|keygen|label|link|map|mark|math|meta|meter|noscript|object|output|progress|q|ruby|s|samp|script|select|small|span|strong|sub|sup|svg|textarea|time|u|var|video|wbr', + C : '#|a|abbr|area|address|article|aside|audio|b|bdi|bdo|blockquote|br|button|canvas|cite|code|command|data|datalist|del|details|dfn|dialog|div|dl|em|embed|fieldset|figure|footer|form|h1|h2|h3|h4|h5|h6|header|hgroup|hr|i|iframe|img|input|ins|kbd|keygen|label|link|map|mark|math|menu|meta|meter|nav|noscript|ol|object|output|p|pre|progress|q|ruby|s|samp|script|section|select|small|span|strong|style|sub|sup|svg|table|textarea|time|u|ul|var|video|wbr' + }, 'html[A|manifest][body|head]' + + 'head[A][base|command|link|meta|noscript|script|style|title]' + + 'title[A][#]' + + 'base[A|href|target][]' + + 'link[A|href|rel|media|type|sizes|crossorigin|hreflang][]' + + 'meta[A|http-equiv|name|content|charset][]' + + 'style[A|type|media|scoped][#]' + + 'script[A|charset|type|src|defer|async|crossorigin][#]' + + 'noscript[A][C]' + + 'body[A|onafterprint|onbeforeprint|onbeforeunload|onblur|onerror|onfocus|onfullscreenchange|onfullscreenerror|onhashchange|onload|onmessage|onoffline|ononline|onpagehide|onpageshow|onpopstate|onresize|onscroll|onstorage|onunload][C]' + + 'section[A][C]' + + 'nav[A][C]' + + 'article[A][C]' + + 'aside[A][C]' + + 'h1[A][B]' + + 'h2[A][B]' + + 'h3[A][B]' + + 'h4[A][B]' + + 'h5[A][B]' + + 'h6[A][B]' + + 'hgroup[A][h1|h2|h3|h4|h5|h6]' + + 'header[A][C]' + + 'footer[A][C]' + + 'address[A][C]' + + 'p[A][B]' + + 'br[A][]' + + 'pre[A][B]' + + 'dialog[A|open][C|dd|dt]' + + 'blockquote[A|cite][C]' + + 'ol[A|start|reversed][li]' + + 'ul[A][li]' + + 'li[A|value][C]' + + 'dl[A][dd|dt]' + + 'dt[A][C|B]' + + 'dd[A][C]' + + 'a[A|href|target|download|ping|rel|media|type][C|B]' + + 'em[A][B]' + + 'strong[A][B]' + + 'small[A][B]' + + 's[A][B]' + + 'cite[A][B]' + + 'q[A|cite][B]' + + 'dfn[A][B]' + + 'abbr[A][B]' + + 'code[A][B]' + + 'var[A][B]' + + 'samp[A][B]' + + 'kbd[A][B]' + + 'sub[A][B]' + + 'sup[A][B]' + + 'i[A][B]' + + 'b[A][B]' + + 'u[A][B]' + + 'mark[A][B]' + + 'progress[A|value|max][B]' + + 'meter[A|value|min|max|low|high|optimum][B]' + + 'time[A|datetime][B]' + + 'ruby[A][B|rt|rp]' + + 'rt[A][B]' + + 'rp[A][B]' + + 'bdi[A][B]' + + 'bdo[A][B]' + + 'span[A][B]' + + 'ins[A|cite|datetime][C|B]' + + 'del[A|cite|datetime][C|B]' + + 'figure[A][C|legend|figcaption]' + + 'figcaption[A][C]' + + 'img[A|alt|src|srcset|crossorigin|usemap|ismap|width|height][]' + + 'iframe[A|name|src|srcdoc|height|width|sandbox|seamless|allowfullscreen][C|B]' + + 'embed[A|src|height|width|type][]' + + 'object[A|data|type|typemustmatch|name|usemap|form|width|height][C|B|param]' + + 'param[A|name|value][]' + + 'summary[A][B]' + + 'details[A|open][C|legend|summary]' + + 'command[A|type|label|icon|disabled|checked|radiogroup|command][]' + + 'menu[A|type|label][C|li]' + + 'legend[A][C|B]' + + 'div[A][C]' + + 'source[A|src|type|media][]' + + 'track[A|kind|src|srclang|label|default][]' + + 'audio[A|src|autobuffer|autoplay|loop|controls|crossorigin|preload|mediagroup|muted][C|source|track]' + + 'video[A|src|autobuffer|autoplay|loop|controls|width|height|poster|crossorigin|preload|mediagroup|muted][C|source|track]' + + 'hr[A][]' + + 'form[A|accept-charset|action|autocomplete|enctype|method|name|novalidate|target][C]' + + 'fieldset[A|disabled|form|name][C|legend]' + + 'label[A|form|for][B]' + + 'input[A|type|accept|alt|autocomplete|autofocus|checked|dirname|disabled|form|formaction|formenctype|formmethod|formnovalidate|formtarget|height|inputmode|list|max|maxlength|min|multiple|name|pattern|placeholder|readonly|required|size|src|step|value|width|files][]' + + 'button[A|autofocus|disabled|form|formaction|formenctype|formmethod|formnovalidate|formtarget|name|type|value][B]' + + 'select[A|autofocus|disabled|form|multiple|name|required|size][option|optgroup]' + + 'data[A|value][B]' + + 'datalist[A][B|option]' + + 'optgroup[A|disabled|label][option]' + + 'option[A|disabled|selected|label|value][#]' + + 'textarea[A|autocomplete|autofocus|cols|dirname|disabled|form|inputmode|maxlength|name|placeholder|readonly|required|rows|wrap][#]' + + 'keygen[A|autofocus|challenge|disabled|form|keytype|name][]' + + 'output[A|for|form|name][B]' + + 'canvas[A|width|height][a|button|input]' + + 'map[A|name][C|B]' + + 'area[A|alt|coords|shape|href|target|download|ping|rel|media|hreflang|type][]' + + 'math[A][]' + + 'svg[A][]' + + 'table[A][caption|colgroup|thead|tfoot|tbody|tr]' + + 'caption[A][C]' + + 'colgroup[A|span][col]' + + 'col[A|span][]' + + 'thead[A][tr]' + + 'tfoot[A][tr]' + + 'tbody[A][tr]' + + 'tr[A][th|td]' + + 'th[A|headers|rowspan|colspan|scope][C]' + + 'td[A|headers|rowspan|colspan][C]' + + 'wbr[A][]' + ); + } + + return html5; + }; + + /** + * Returns the HTML4 schema and caches it in the mapCache. + */ + function getHTML4() { + var html4 = mapCache.html4; + + if (!html4) { + // This is the XHTML 1.0 transitional elements with it's attributes and children packed to reduce it's size + html4 = mapCache.html4 = unpack({ + Z : 'H|K|N|O|P', + Y : 'X|form|R|Q', + ZG : 'E|span|width|align|char|charoff|valign', + X : 'p|T|div|U|W|isindex|fieldset|table', + ZF : 'E|align|char|charoff|valign', + W : 'pre|hr|blockquote|address|center|noframes', + ZE : 'abbr|axis|headers|scope|rowspan|colspan|align|char|charoff|valign|nowrap|bgcolor|width|height', + ZD : '[E][S]', + U : 'ul|ol|dl|menu|dir', + ZC : 'p|Y|div|U|W|table|br|span|bdo|object|applet|img|map|K|N|Q', + T : 'h1|h2|h3|h4|h5|h6', + ZB : 'X|S|Q', + S : 'R|P', + ZA : 'a|G|J|M|O|P', + R : 'a|H|K|N|O', + Q : 'noscript|P', + P : 'ins|del|script', + O : 'input|select|textarea|label|button', + N : 'M|L', + M : 'em|strong|dfn|code|q|samp|kbd|var|cite|abbr|acronym', + L : 'sub|sup', + K : 'J|I', + J : 'tt|i|b|u|s|strike', + I : 'big|small|font|basefont', + H : 'G|F', + G : 'br|span|bdo', + F : 'object|applet|img|map|iframe', + E : 'A|B|C', + D : 'accesskey|tabindex|onfocus|onblur', + C : 'onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup', + B : 'lang|xml:lang|dir', + A : 'id|class|style|title' + }, 'script[id|charset|type|language|src|defer|xml:space][]' + + 'style[B|id|type|media|title|xml:space][]' + + 'object[E|declare|classid|codebase|data|type|codetype|archive|standby|width|height|usemap|name|tabindex|align|border|hspace|vspace][#|param|Y]' + + 'param[id|name|value|valuetype|type][]' + + 'p[E|align][#|S]' + + 'a[E|D|charset|type|name|href|hreflang|rel|rev|shape|coords|target][#|Z]' + + 'br[A|clear][]' + + 'span[E][#|S]' + + 'bdo[A|C|B][#|S]' + + 'applet[A|codebase|archive|code|object|alt|name|width|height|align|hspace|vspace][#|param|Y]' + + 'h1[E|align][#|S]' + + 'img[E|src|alt|name|longdesc|width|height|usemap|ismap|align|border|hspace|vspace][]' + + 'map[B|C|A|name][X|form|Q|area]' + + 'h2[E|align][#|S]' + + 'iframe[A|longdesc|name|src|frameborder|marginwidth|marginheight|scrolling|align|width|height][#|Y]' + + 'h3[E|align][#|S]' + + 'tt[E][#|S]' + + 'i[E][#|S]' + + 'b[E][#|S]' + + 'u[E][#|S]' + + 's[E][#|S]' + + 'strike[E][#|S]' + + 'big[E][#|S]' + + 'small[E][#|S]' + + 'font[A|B|size|color|face][#|S]' + + 'basefont[id|size|color|face][]' + + 'em[E][#|S]' + + 'strong[E][#|S]' + + 'dfn[E][#|S]' + + 'code[E][#|S]' + + 'q[E|cite][#|S]' + + 'samp[E][#|S]' + + 'kbd[E][#|S]' + + 'var[E][#|S]' + + 'cite[E][#|S]' + + 'abbr[E][#|S]' + + 'acronym[E][#|S]' + + 'sub[E][#|S]' + + 'sup[E][#|S]' + + 'input[E|D|type|name|value|checked|disabled|readonly|size|maxlength|src|alt|usemap|onselect|onchange|accept|align][]' + + 'select[E|name|size|multiple|disabled|tabindex|onfocus|onblur|onchange][optgroup|option]' + + 'optgroup[E|disabled|label][option]' + + 'option[E|selected|disabled|label|value][]' + + 'textarea[E|D|name|rows|cols|disabled|readonly|onselect|onchange][]' + + 'label[E|for|accesskey|onfocus|onblur][#|S]' + + 'button[E|D|name|value|type|disabled][#|p|T|div|U|W|table|G|object|applet|img|map|K|N|Q]' + + 'h4[E|align][#|S]' + + 'ins[E|cite|datetime][#|Y]' + + 'h5[E|align][#|S]' + + 'del[E|cite|datetime][#|Y]' + + 'h6[E|align][#|S]' + + 'div[E|align][#|Y]' + + 'ul[E|type|compact][li]' + + 'li[E|type|value][#|Y]' + + 'ol[E|type|compact|start][li]' + + 'dl[E|compact][dt|dd]' + + 'dt[E][#|S]' + + 'dd[E][#|Y]' + + 'menu[E|compact][li]' + + 'dir[E|compact][li]' + + 'pre[E|width|xml:space][#|ZA]' + + 'hr[E|align|noshade|size|width][]' + + 'blockquote[E|cite][#|Y]' + + 'address[E][#|S|p]' + + 'center[E][#|Y]' + + 'noframes[E][#|Y]' + + 'isindex[A|B|prompt][]' + + 'fieldset[E][#|legend|Y]' + + 'legend[E|accesskey|align][#|S]' + + 'table[E|summary|width|border|frame|rules|cellspacing|cellpadding|align|bgcolor][caption|col|colgroup|thead|tfoot|tbody|tr]' + + 'caption[E|align][#|S]' + + 'col[ZG][]' + + 'colgroup[ZG][col]' + + 'thead[ZF][tr]' + + 'tr[ZF|bgcolor][th|td]' + + 'th[E|ZE][#|Y]' + + 'form[E|action|method|name|enctype|onsubmit|onreset|accept|accept-charset|target][#|X|R|Q]' + + 'noscript[E][#|Y]' + + 'td[E|ZE][#|Y]' + + 'tfoot[ZF][tr]' + + 'tbody[ZF][tr]' + + 'area[E|D|shape|coords|href|nohref|alt|target][]' + + 'base[id|href|target][]' + + 'body[E|onload|onunload|background|bgcolor|text|link|vlink|alink][#|Y]' + ); + } + + return html4; + }; + + /** + * WordPress Core + * + * Returns a schema that is the result of a deep merge between the HTML5 + * and HTML4 schemas. + */ + function getSaneSchema() { + var cachedMapCache = mapCache, + html5, html4; + + if ( mapCache.sane ) + return mapCache.sane; + + // Bust the mapCache so we're not dealing with the other schema objects. + mapCache = {}; + html5 = getHTML5(); + html4 = getHTML4(); + mapCache = cachedMapCache; + + each( html4, function( html4settings, tag ) { + var html5settings = html5[ tag ], + difference = []; + + // Merge tags missing in HTML5 mode. + if ( ! html5settings ) { + html5[ tag ] = html4settings; + return; + } + + // Merge attributes missing from this HTML5 tag. + each( html4settings.attributes, function( attribute, key ) { + if ( ! html5settings.attributes[ key ] ) + html5settings.attributes[ key ] = attribute; + }); + + // Merge any missing attributes into the attributes order. + each( html4settings.attributesOrder, function( key ) { + if ( -1 === tinymce.inArray( html5settings.attributesOrder, key ) ) + difference.push( key ); + }); + + html5settings.attributesOrder = html5settings.attributesOrder.concat( difference ); + + // Merge children missing from this HTML5 tag. + each( html4settings.children, function( child, key ) { + if ( ! html5settings.children[ key ] ) + html5settings.children[ key ] = child; + }); + }); + + return mapCache.sane = html5; + } + + /** + * Schema validator class. + * + * @class tinymce.html.Schema + * @example + * if (tinymce.activeEditor.schema.isValidChild('p', 'span')) + * alert('span is valid child of p.'); + * + * if (tinymce.activeEditor.schema.getElementRule('p')) + * alert('P is a valid element.'); + * + * @class tinymce.html.Schema + * @version 3.4 + */ + + /** + * Constructs a new Schema instance. + * + * @constructor + * @method Schema + * @param {Object} settings Name/value settings object. + */ + tinymce.html.Schema = function(settings) { + var self = this, elements = {}, children = {}, patternElements = [], validStyles, schemaItems; + var whiteSpaceElementsMap, selfClosingElementsMap, shortEndedElementsMap, boolAttrMap, blockElementsMap, nonEmptyElementsMap, customElementsMap = {}; + + // Creates an lookup table map object for the specified option or the default value + function createLookupTable(option, default_value, extend) { + var value = settings[option]; + + if (!value) { + // Get cached default map or make it if needed + value = mapCache[option]; + + if (!value) { + value = makeMap(default_value, ' ', makeMap(default_value.toUpperCase(), ' ')); + value = tinymce.extend(value, extend); + + mapCache[option] = value; + } + } else { + // Create custom map + value = makeMap(value, ',', makeMap(value.toUpperCase(), ' ')); + } + + return value; + }; + + settings = settings || {}; + + /** + * WordPress core uses a sane schema in place of the default "HTML5" schema. + */ + schemaItems = settings.schema == "html5" ? getSaneSchema() : getHTML4(); + + // Allow all elements and attributes if verify_html is set to false + if (settings.verify_html === false) + settings.valid_elements = '*[*]'; + + // Build styles list + if (settings.valid_styles) { + validStyles = {}; + + // Convert styles into a rule list + each(settings.valid_styles, function(value, key) { + validStyles[key] = tinymce.explode(value); + }); + } + + // Setup map objects + whiteSpaceElementsMap = createLookupTable('whitespace_elements', 'pre script noscript style textarea'); + selfClosingElementsMap = createLookupTable('self_closing_elements', 'colgroup dd dt li option p td tfoot th thead tr'); + shortEndedElementsMap = createLookupTable('short_ended_elements', 'area base basefont br col frame hr img input isindex link meta param embed source wbr'); + boolAttrMap = createLookupTable('boolean_attributes', 'checked compact declare defer disabled ismap multiple nohref noresize noshade nowrap readonly selected autoplay loop controls'); + nonEmptyElementsMap = createLookupTable('non_empty_elements', 'td th iframe video audio object', shortEndedElementsMap); + textBlockElementsMap = createLookupTable('text_block_elements', 'h1 h2 h3 h4 h5 h6 p div address pre form ' + + 'blockquote center dir fieldset header footer article section hgroup aside nav figure'); + blockElementsMap = createLookupTable('block_elements', 'hr table tbody thead tfoot ' + + 'th tr td li ol ul caption dl dt dd noscript menu isindex samp option datalist select optgroup', textBlockElementsMap); + + // Converts a wildcard expression string to a regexp for example *a will become /.*a/. + function patternToRegExp(str) { + return new RegExp('^' + str.replace(/([?+*])/g, '.$1') + '$'); + }; + + // Parses the specified valid_elements string and adds to the current rules + // This function is a bit hard to read since it's heavily optimized for speed + function addValidElements(valid_elements) { + var ei, el, ai, al, yl, matches, element, attr, attrData, elementName, attrName, attrType, attributes, attributesOrder, + prefix, outputName, globalAttributes, globalAttributesOrder, transElement, key, childKey, value, + elementRuleRegExp = /^([#+\-])?([^\[\/]+)(?:\/([^\[]+))?(?:\[([^\]]+)\])?$/, + attrRuleRegExp = /^([!\-])?(\w+::\w+|[^=:<]+)?(?:([=:<])(.*))?$/, + hasPatternsRegExp = /[*?+]/; + + if (valid_elements) { + // Split valid elements into an array with rules + valid_elements = split(valid_elements); + + if (elements['@']) { + globalAttributes = elements['@'].attributes; + globalAttributesOrder = elements['@'].attributesOrder; + } + + // Loop all rules + for (ei = 0, el = valid_elements.length; ei < el; ei++) { + // Parse element rule + matches = elementRuleRegExp.exec(valid_elements[ei]); + if (matches) { + // Setup local names for matches + prefix = matches[1]; + elementName = matches[2]; + outputName = matches[3]; + attrData = matches[4]; + + // Create new attributes and attributesOrder + attributes = {}; + attributesOrder = []; + + // Create the new element + element = { + attributes : attributes, + attributesOrder : attributesOrder + }; + + // Padd empty elements prefix + if (prefix === '#') + element.paddEmpty = true; + + // Remove empty elements prefix + if (prefix === '-') + element.removeEmpty = true; + + // Copy attributes from global rule into current rule + if (globalAttributes) { + for (key in globalAttributes) + attributes[key] = globalAttributes[key]; + + attributesOrder.push.apply(attributesOrder, globalAttributesOrder); + } + + // Attributes defined + if (attrData) { + attrData = split(attrData, '|'); + for (ai = 0, al = attrData.length; ai < al; ai++) { + matches = attrRuleRegExp.exec(attrData[ai]); + if (matches) { + attr = {}; + attrType = matches[1]; + attrName = matches[2].replace(/::/g, ':'); + prefix = matches[3]; + value = matches[4]; + + // Required + if (attrType === '!') { + element.attributesRequired = element.attributesRequired || []; + element.attributesRequired.push(attrName); + attr.required = true; + } + + // Denied from global + if (attrType === '-') { + delete attributes[attrName]; + attributesOrder.splice(tinymce.inArray(attributesOrder, attrName), 1); + continue; + } + + // Default value + if (prefix) { + // Default value + if (prefix === '=') { + element.attributesDefault = element.attributesDefault || []; + element.attributesDefault.push({name: attrName, value: value}); + attr.defaultValue = value; + } + + // Forced value + if (prefix === ':') { + element.attributesForced = element.attributesForced || []; + element.attributesForced.push({name: attrName, value: value}); + attr.forcedValue = value; + } + + // Required values + if (prefix === '<') + attr.validValues = makeMap(value, '?'); + } + + // Check for attribute patterns + if (hasPatternsRegExp.test(attrName)) { + element.attributePatterns = element.attributePatterns || []; + attr.pattern = patternToRegExp(attrName); + element.attributePatterns.push(attr); + } else { + // Add attribute to order list if it doesn't already exist + if (!attributes[attrName]) + attributesOrder.push(attrName); + + attributes[attrName] = attr; + } + } + } + } + + // Global rule, store away these for later usage + if (!globalAttributes && elementName == '@') { + globalAttributes = attributes; + globalAttributesOrder = attributesOrder; + } + + // Handle substitute elements such as b/strong + if (outputName) { + element.outputName = elementName; + elements[outputName] = element; + } + + // Add pattern or exact element + if (hasPatternsRegExp.test(elementName)) { + element.pattern = patternToRegExp(elementName); + patternElements.push(element); + } else + elements[elementName] = element; + } + } + } + }; + + function setValidElements(valid_elements) { + elements = {}; + patternElements = []; + + addValidElements(valid_elements); + + each(schemaItems, function(element, name) { + children[name] = element.children; + }); + }; + + // Adds custom non HTML elements to the schema + function addCustomElements(custom_elements) { + var customElementRegExp = /^(~)?(.+)$/; + + if (custom_elements) { + each(split(custom_elements), function(rule) { + var matches = customElementRegExp.exec(rule), + inline = matches[1] === '~', + cloneName = inline ? 'span' : 'div', + name = matches[2]; + + children[name] = children[cloneName]; + customElementsMap[name] = cloneName; + + // If it's not marked as inline then add it to valid block elements + if (!inline) { + blockElementsMap[name.toUpperCase()] = {}; + blockElementsMap[name] = {}; + } + + // Add elements clone if needed + if (!elements[name]) { + elements[name] = elements[cloneName]; + } + + // Add custom elements at span/div positions + each(children, function(element, child) { + if (element[cloneName]) + element[name] = element[cloneName]; + }); + }); + } + }; + + // Adds valid children to the schema object + function addValidChildren(valid_children) { + var childRuleRegExp = /^([+\-]?)(\w+)\[([^\]]+)\]$/; + + if (valid_children) { + each(split(valid_children), function(rule) { + var matches = childRuleRegExp.exec(rule), parent, prefix; + + if (matches) { + prefix = matches[1]; + + // Add/remove items from default + if (prefix) + parent = children[matches[2]]; + else + parent = children[matches[2]] = {'#comment' : {}}; + + parent = children[matches[2]]; + + each(split(matches[3], '|'), function(child) { + if (prefix === '-') + delete parent[child]; + else + parent[child] = {}; + }); + } + }); + } + }; + + function getElementRule(name) { + var element = elements[name], i; + + // Exact match found + if (element) + return element; + + // No exact match then try the patterns + i = patternElements.length; + while (i--) { + element = patternElements[i]; + + if (element.pattern.test(name)) + return element; + } + }; + + if (!settings.valid_elements) { + // No valid elements defined then clone the elements from the schema spec + each(schemaItems, function(element, name) { + elements[name] = { + attributes : element.attributes, + attributesOrder : element.attributesOrder + }; + + children[name] = element.children; + }); + + // Switch these on HTML4 + if (settings.schema != "html5") { + each(split('strong/b,em/i'), function(item) { + item = split(item, '/'); + elements[item[1]].outputName = item[0]; + }); + } + + // Add default alt attribute for images + elements.img.attributesDefault = [{name: 'alt', value: ''}]; + + // Remove these if they are empty by default + each(split('ol,ul,sub,sup,blockquote,span,font,a,table,tbody,tr,strong,em,b,i'), function(name) { + if (elements[name]) { + elements[name].removeEmpty = true; + } + }); + + // Padd these by default + each(split('p,h1,h2,h3,h4,h5,h6,th,td,pre,div,address,caption'), function(name) { + elements[name].paddEmpty = true; + }); + } else + setValidElements(settings.valid_elements); + + addCustomElements(settings.custom_elements); + addValidChildren(settings.valid_children); + addValidElements(settings.extended_valid_elements); + + // Todo: Remove this when we fix list handling to be valid + addValidChildren('+ol[ul|ol],+ul[ul|ol]'); + + // Delete invalid elements + if (settings.invalid_elements) { + tinymce.each(tinymce.explode(settings.invalid_elements), function(item) { + if (elements[item]) + delete elements[item]; + }); + } + + // If the user didn't allow span only allow internal spans + if (!getElementRule('span')) + addValidElements('span[!data-mce-type|*]'); + + /** + * Name/value map object with valid parents and children to those parents. + * + * @example + * children = { + * div:{p:{}, h1:{}} + * }; + * @field children + * @type {Object} + */ + self.children = children; + + /** + * Name/value map object with valid styles for each element. + * + * @field styles + * @type {Object} + */ + self.styles = validStyles; + + /** + * Returns a map with boolean attributes. + * + * @method getBoolAttrs + * @return {Object} Name/value lookup map for boolean attributes. + */ + self.getBoolAttrs = function() { + return boolAttrMap; + }; + + /** + * Returns a map with block elements. + * + * @method getBlockElements + * @return {Object} Name/value lookup map for block elements. + */ + self.getBlockElements = function() { + return blockElementsMap; + }; + + /** + * Returns a map with text block elements. Such as: p,h1-h6,div,address + * + * @method getTextBlockElements + * @return {Object} Name/value lookup map for block elements. + */ + self.getTextBlockElements = function() { + return textBlockElementsMap; + }; + + /** + * Returns a map with short ended elements such as BR or IMG. + * + * @method getShortEndedElements + * @return {Object} Name/value lookup map for short ended elements. + */ + self.getShortEndedElements = function() { + return shortEndedElementsMap; + }; + + /** + * Returns a map with self closing tags such as
  • . + * + * @method getSelfClosingElements + * @return {Object} Name/value lookup map for self closing tags elements. + */ + self.getSelfClosingElements = function() { + return selfClosingElementsMap; + }; + + /** + * Returns a map with elements that should be treated as contents regardless if it has text + * content in them or not such as TD, VIDEO or IMG. + * + * @method getNonEmptyElements + * @return {Object} Name/value lookup map for non empty elements. + */ + self.getNonEmptyElements = function() { + return nonEmptyElementsMap; + }; + + /** + * Returns a map with elements where white space is to be preserved like PRE or SCRIPT. + * + * @method getWhiteSpaceElements + * @return {Object} Name/value lookup map for white space elements. + */ + self.getWhiteSpaceElements = function() { + return whiteSpaceElementsMap; + }; + + /** + * Returns true/false if the specified element and it's child is valid or not + * according to the schema. + * + * @method isValidChild + * @param {String} name Element name to check for. + * @param {String} child Element child to verify. + * @return {Boolean} True/false if the element is a valid child of the specified parent. + */ + self.isValidChild = function(name, child) { + var parent = children[name]; + + return !!(parent && parent[child]); + }; + + /** + * Returns true/false if the specified element name and optional attribute is + * valid according to the schema. + * + * @method isValid + * @param {String} name Name of element to check. + * @param {String} attr Optional attribute name to check for. + * @return {Boolean} True/false if the element and attribute is valid. + */ + self.isValid = function(name, attr) { + var attrPatterns, i, rule = getElementRule(name); + + // Check if it's a valid element + if (rule) { + if (attr) { + // Check if attribute name exists + if (rule.attributes[attr]) { + return true; + } + + // Check if attribute matches a regexp pattern + attrPatterns = rule.attributePatterns; + if (attrPatterns) { + i = attrPatterns.length; + while (i--) { + if (attrPatterns[i].pattern.test(name)) { + return true; + } + } + } + } else { + return true; + } + } + + // No match + return false; + }; + + /** + * Returns true/false if the specified element is valid or not + * according to the schema. + * + * @method getElementRule + * @param {String} name Element name to check for. + * @return {Object} Element object or undefined if the element isn't valid. + */ + self.getElementRule = getElementRule; + + /** + * Returns an map object of all custom elements. + * + * @method getCustomElements + * @return {Object} Name/value map object of all custom elements. + */ + self.getCustomElements = function() { + return customElementsMap; + }; + + /** + * Parses a valid elements string and adds it to the schema. The valid elements format is for example "element[attr=default|otherattr]". + * Existing rules will be replaced with the ones specified, so this extends the schema. + * + * @method addValidElements + * @param {String} valid_elements String in the valid elements format to be parsed. + */ + self.addValidElements = addValidElements; + + /** + * Parses a valid elements string and sets it to the schema. The valid elements format is for example "element[attr=default|otherattr]". + * Existing rules will be replaced with the ones specified, so this extends the schema. + * + * @method setValidElements + * @param {String} valid_elements String in the valid elements format to be parsed. + */ + self.setValidElements = setValidElements; + + /** + * Adds custom non HTML elements to the schema. + * + * @method addCustomElements + * @param {String} custom_elements Comma separated list of custom elements to add. + */ + self.addCustomElements = addCustomElements; + + /** + * Parses a valid children string and adds them to the schema structure. The valid children format is for example: "element[child1|child2]". + * + * @method addValidChildren + * @param {String} valid_children Valid children elements string to parse + */ + self.addValidChildren = addValidChildren; + + self.elements = elements; + }; +})(tinymce); diff --git a/wp-includes/js/tinymce/wp-tinymce.js.gz b/wp-includes/js/tinymce/wp-tinymce.js.gz index b8ed7249..55d01ff1 100644 Binary files a/wp-includes/js/tinymce/wp-tinymce.js.gz and b/wp-includes/js/tinymce/wp-tinymce.js.gz differ diff --git a/wp-includes/js/tinymce/wp-tinymce.php b/wp-includes/js/tinymce/wp-tinymce.php index 449f0e25..83a003d7 100644 --- a/wp-includes/js/tinymce/wp-tinymce.php +++ b/wp-includes/js/tinymce/wp-tinymce.php @@ -19,7 +19,7 @@ function get_file($path) { return @file_get_contents($path); } -$expires_offset = 31536000; +$expires_offset = 31536000; // 1 year header('Content-Type: application/x-javascript; charset=UTF-8'); header('Vary: Accept-Encoding'); // Handle proxies @@ -33,5 +33,6 @@ if ( isset($_GET['c']) && 1 == $_GET['c'] && isset($_SERVER['HTTP_ACCEPT_ENCODIN echo $file; } else { echo get_file($basepath . '/tiny_mce.js'); + echo get_file($basepath . '/wp-tinymce-schema.js'); } exit; diff --git a/wp-includes/js/tw-sack.dev.js b/wp-includes/js/tw-sack.dev.js deleted file mode 100644 index f93f2a42..00000000 --- a/wp-includes/js/tw-sack.dev.js +++ /dev/null @@ -1,193 +0,0 @@ -/* Simple AJAX Code-Kit (SACK) v1.6.1 */ -/* ©2005 Gregory Wild-Smith */ -/* www.twilightuniverse.com */ -/* Software licenced under a modified X11 licence, - see documentation or authors website for more details */ - -function sack(file) { - this.xmlhttp = null; - - this.resetData = function() { - this.method = "POST"; - this.queryStringSeparator = "?"; - this.argumentSeparator = "&"; - this.URLString = ""; - this.encodeURIString = true; - this.execute = false; - this.element = null; - this.elementObj = null; - this.requestFile = file; - this.vars = new Object(); - this.responseStatus = new Array(2); - }; - - this.resetFunctions = function() { - this.onLoading = function() { }; - this.onLoaded = function() { }; - this.onInteractive = function() { }; - this.onCompletion = function() { }; - this.onError = function() { }; - this.onFail = function() { }; - }; - - this.reset = function() { - this.resetFunctions(); - this.resetData(); - }; - - this.createAJAX = function() { - try { - this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); - } catch (e1) { - try { - this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); - } catch (e2) { - this.xmlhttp = null; - } - } - - if (! this.xmlhttp) { - if (typeof XMLHttpRequest != "undefined") { - this.xmlhttp = new XMLHttpRequest(); - } else { - this.failed = true; - } - } - }; - - this.setVar = function(name, value){ - this.vars[name] = Array(value, false); - }; - - this.encVar = function(name, value, returnvars) { - if (true == returnvars) { - return Array(encodeURIComponent(name), encodeURIComponent(value)); - } else { - this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true); - } - } - - this.processURLString = function(string, encode) { - encoded = encodeURIComponent(this.argumentSeparator); - regexp = new RegExp(this.argumentSeparator + "|" + encoded); - varArray = string.split(regexp); - for (i = 0; i < varArray.length; i++){ - urlVars = varArray[i].split("="); - if (true == encode){ - this.encVar(urlVars[0], urlVars[1]); - } else { - this.setVar(urlVars[0], urlVars[1]); - } - } - } - - this.createURLString = function(urlstring) { - if (this.encodeURIString && this.URLString.length) { - this.processURLString(this.URLString, true); - } - - if (urlstring) { - if (this.URLString.length) { - this.URLString += this.argumentSeparator + urlstring; - } else { - this.URLString = urlstring; - } - } - - // prevents caching of URLString - this.setVar("rndval", new Date().getTime()); - - urlstringtemp = new Array(); - for (key in this.vars) { - if (false == this.vars[key][1] && true == this.encodeURIString) { - encoded = this.encVar(key, this.vars[key][0], true); - delete this.vars[key]; - this.vars[encoded[0]] = Array(encoded[1], true); - key = encoded[0]; - } - - urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0]; - } - if (urlstring){ - this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator); - } else { - this.URLString += urlstringtemp.join(this.argumentSeparator); - } - } - - this.runResponse = function() { - eval(this.response); - } - - this.runAJAX = function(urlstring) { - if (this.failed) { - this.onFail(); - } else { - this.createURLString(urlstring); - if (this.element) { - this.elementObj = document.getElementById(this.element); - } - if (this.xmlhttp) { - var self = this; - if (this.method == "GET") { - totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString; - this.xmlhttp.open(this.method, totalurlstring, true); - } else { - this.xmlhttp.open(this.method, this.requestFile, true); - try { - this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") - } catch (e) { } - } - - this.xmlhttp.onreadystatechange = function() { - switch (self.xmlhttp.readyState) { - case 1: - self.onLoading(); - break; - case 2: - self.onLoaded(); - break; - case 3: - self.onInteractive(); - break; - case 4: - self.response = self.xmlhttp.responseText; - self.responseXML = self.xmlhttp.responseXML; - self.responseStatus[0] = self.xmlhttp.status; - self.responseStatus[1] = self.xmlhttp.statusText; - - if (self.execute) { - self.runResponse(); - } - - if (self.elementObj) { - elemNodeName = self.elementObj.nodeName; - elemNodeName.toLowerCase(); - if (elemNodeName == "input" - || elemNodeName == "select" - || elemNodeName == "option" - || elemNodeName == "textarea") { - self.elementObj.value = self.response; - } else { - self.elementObj.innerHTML = self.response; - } - } - if (self.responseStatus[0] == "200") { - self.onCompletion(); - } else { - self.onError(); - } - - self.URLString = ""; - break; - } - }; - - this.xmlhttp.send(this.URLString); - } - } - }; - - this.reset(); - this.createAJAX(); -} diff --git a/wp-includes/js/tw-sack.js b/wp-includes/js/tw-sack.js index d1b5561e..f93f2a42 100644 --- a/wp-includes/js/tw-sack.js +++ b/wp-includes/js/tw-sack.js @@ -1 +1,193 @@ -function sack(file){this.xmlhttp=null;this.resetData=function(){this.method="POST";this.queryStringSeparator="?";this.argumentSeparator="&";this.URLString="";this.encodeURIString=true;this.execute=false;this.element=null;this.elementObj=null;this.requestFile=file;this.vars=new Object();this.responseStatus=new Array(2)};this.resetFunctions=function(){this.onLoading=function(){};this.onLoaded=function(){};this.onInteractive=function(){};this.onCompletion=function(){};this.onError=function(){};this.onFail=function(){}};this.reset=function(){this.resetFunctions();this.resetData()};this.createAJAX=function(){try{this.xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")}catch(e1){try{this.xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")}catch(e2){this.xmlhttp=null}}if(!this.xmlhttp){if(typeof XMLHttpRequest!="undefined"){this.xmlhttp=new XMLHttpRequest()}else{this.failed=true}}};this.setVar=function(name,value){this.vars[name]=Array(value,false)};this.encVar=function(name,value,returnvars){if(true==returnvars){return Array(encodeURIComponent(name),encodeURIComponent(value))}else{this.vars[encodeURIComponent(name)]=Array(encodeURIComponent(value),true)}};this.processURLString=function(string,encode){encoded=encodeURIComponent(this.argumentSeparator);regexp=new RegExp(this.argumentSeparator+"|"+encoded);varArray=string.split(regexp);for(i=0;i2;if(d&&e.reduce===d)return r&&(t=T.bind(t,r)),i?e.reduce(t,n):e.reduce(t);N(e,function(e,s,o){i?n=t.call(r,n,e,s,o):(n=e,i=!0)});if(!i)throw new TypeError("Reduce of empty array with no initial value");return n},T.reduceRight=T.foldr=function(e,t,n,r){var i=arguments.length>2;if(v&&e.reduceRight===v)return r&&(t=T.bind(t,r)),arguments.length>2?e.reduceRight(t,n):e.reduceRight(t);var s=e.length;if(s!==+s){var o=T.keys(e);s=o.length}N(e,function(u,a,f){a=o?o[--s]:--s,i?n=t.call(r,n,e[a],a,f):(n=e[a],i=!0)});if(!i)throw new TypeError("Reduce of empty array with no initial value");return n},T.find=T.detect=function(e,t,n){var r;return C(e,function(e,i,s){if(t.call(n,e,i,s))return r=e,!0}),r},T.filter=T.select=function(e,t,n){var r=[];return m&&e.filter===m?e.filter(t,n):(N(e,function(e,i,s){t.call(n,e,i,s)&&(r[r.length]=e)}),r)},T.reject=function(e,t,n){var r=[];return N(e,function(e,i,s){t.call(n,e,i,s)||(r[r.length]=e)}),r},T.every=T.all=function(e,t,r){t||(t=T.identity);var i=!0;return g&&e.every===g?e.every(t,r):(N(e,function(e,s,o){if(!(i=i&&t.call(r,e,s,o)))return n}),!!i)};var C=T.some=T.any=function(e,t,r){t||(t=T.identity);var i=!1;return y&&e.some===y?e.some(t,r):(N(e,function(e,s,o){if(i||(i=t.call(r,e,s,o)))return n}),!!i)};T.contains=T.include=function(e,t){var n=!1;return b&&e.indexOf===b?e.indexOf(t)!=-1:(n=C(e,function(e){return e===t}),n)},T.invoke=function(e,t){var n=u.call(arguments,2);return T.map(e,function(e){return(T.isFunction(t)?t:e[t]).apply(e,n)})},T.pluck=function(e,t){return T.map(e,function(e){return e[t]})},T.where=function(e,t){return T.isEmpty(t)?[]:T.filter(e,function(e){for(var n in t)if(t[n]!==e[n])return!1;return!0})},T.max=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.max.apply(Math,e);if(!t&&T.isEmpty(e))return-Infinity;var r={computed:-Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;o>=r.computed&&(r={value:e,computed:o})}),r.value},T.min=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.min.apply(Math,e);if(!t&&T.isEmpty(e))return Infinity;var r={computed:Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;or||n===void 0)return 1;if(n>>1;n.call(r,e[u])=0})})},T.difference=function(e){var t=a.apply(r,u.call(arguments,1));return T.filter(e,function(e){return!T.contains(t,e)})},T.zip=function(){var e=u.call(arguments),t=T.max(T.pluck(e,"length")),n=new Array(t);for(var r=0;r=0;n--)t=[e[n].apply(this,t)];return t[0]}},T.after=function(e,t){return e<=0?t():function(){if(--e<1)return t.apply(this,arguments)}},T.keys=S||function(e){if(e!==Object(e))throw new TypeError("Invalid object");var t=[];for(var n in e)T.has(e,n)&&(t[t.length]=n);return t},T.values=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push(e[n]);return t},T.pairs=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push([n,e[n]]);return t},T.invert=function(e){var t={};for(var n in e)T.has(e,n)&&(t[e[n]]=n);return t},T.functions=T.methods=function(e){var t=[];for(var n in e)T.isFunction(e[n])&&t.push(n);return t.sort()},T.extend=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]=t[n]}),e},T.pick=function(e){var t={},n=a.apply(r,u.call(arguments,1));return N(n,function(n){n in e&&(t[n]=e[n])}),t},T.omit=function(e){var t={},n=a.apply(r,u.call(arguments,1));for(var i in e)T.contains(n,i)||(t[i]=e[i]);return t},T.defaults=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]==null&&(e[n]=t[n])}),e},T.clone=function(e){return T.isObject(e)?T.isArray(e)?e.slice():T.extend({},e):e},T.tap=function(e,t){return t(e),e};var M=function(e,t,n,r){if(e===t)return e!==0||1/e==1/t;if(e==null||t==null)return e===t;e instanceof T&&(e=e._wrapped),t instanceof T&&(t=t._wrapped);var i=l.call(e);if(i!=l.call(t))return!1;switch(i){case"[object String]":return e==String(t);case"[object Number]":return e!=+e?t!=+t:e==0?1/e==1/t:e==+t;case"[object Date]":case"[object Boolean]":return+e==+t;case"[object RegExp]":return e.source==t.source&&e.global==t.global&&e.multiline==t.multiline&&e.ignoreCase==t.ignoreCase}if(typeof e!="object"||typeof t!="object")return!1;var s=n.length;while(s--)if(n[s]==e)return r[s]==t;n.push(e),r.push(t);var o=0,u=!0;if(i=="[object Array]"){o=e.length,u=o==t.length;if(u)while(o--)if(!(u=M(e[o],t[o],n,r)))break}else{var a=e.constructor,f=t.constructor;if(a!==f&&!(T.isFunction(a)&&a instanceof a&&T.isFunction(f)&&f instanceof f))return!1;for(var c in e)if(T.has(e,c)){o++;if(!(u=T.has(t,c)&&M(e[c],t[c],n,r)))break}if(u){for(c in t)if(T.has(t,c)&&!(o--))break;u=!o}}return n.pop(),r.pop(),u};T.isEqual=function(e,t){return M(e,t,[],[])},T.isEmpty=function(e){if(e==null)return!0;if(T.isArray(e)||T.isString(e))return e.length===0;for(var t in e)if(T.has(e,t))return!1;return!0},T.isElement=function(e){return!!e&&e.nodeType===1},T.isArray=E||function(e){return l.call(e)=="[object Array]"},T.isObject=function(e){return e===Object(e)},N(["Arguments","Function","String","Number","Date","RegExp"],function(e){T["is"+e]=function(t){return l.call(t)=="[object "+e+"]"}}),T.isArguments(arguments)||(T.isArguments=function(e){return!!e&&!!T.has(e,"callee")}),typeof /./!="function"&&(T.isFunction=function(e){return typeof e=="function"}),T.isFinite=function(e){return T.isNumber(e)&&isFinite(e)},T.isNaN=function(e){return T.isNumber(e)&&e!=+e},T.isBoolean=function(e){return e===!0||e===!1||l.call(e)=="[object Boolean]"},T.isNull=function(e){return e===null},T.isUndefined=function(e){return e===void 0},T.has=function(e,t){return c.call(e,t)},T.noConflict=function(){return e._=t,this},T.identity=function(e){return e},T.times=function(e,t,n){for(var r=0;r":">",'"':""","'":"'","/":"/"}};_.unescape=T.invert(_.escape);var D={escape:new RegExp("["+T.keys(_.escape).join("")+"]","g"),unescape:new RegExp("("+T.keys(_.unescape).join("|")+")","g")};T.each(["escape","unescape"],function(e){T[e]=function(t){return t==null?"":(""+t).replace(D[e],function(t){return _[e][t]})}}),T.result=function(e,t){if(e==null)return null;var n=e[t];return T.isFunction(n)?n.call(e):n},T.mixin=function(e){N(T.functions(e),function(t){var n=T[t]=e[t];T.prototype[t]=function(){var e=[this._wrapped];return o.apply(e,arguments),F.call(this,n.apply(T,e))}})};var P=0;T.uniqueId=function(e){var t=P++;return e?e+t:t},T.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var H=/(.)^/,B={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},j=/\\|'|\r|\n|\t|\u2028|\u2029/g;T.template=function(e,t,n){n=T.defaults({},n,T.templateSettings);var r=new RegExp([(n.escape||H).source,(n.interpolate||H).source,(n.evaluate||H).source].join("|")+"|$","g"),i=0,s="__p+='";e.replace(r,function(t,n,r,o,u){s+=e.slice(i,u).replace(j,function(e){return"\\"+B[e]}),s+=n?"'+\n((__t=("+n+"))==null?'':_.escape(__t))+\n'":r?"'+\n((__t=("+r+"))==null?'':__t)+\n'":o?"';\n"+o+"\n__p+='":"",i=u+t.length}),s+="';\n",n.variable||(s="with(obj||{}){\n"+s+"}\n"),s="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+s+"return __p;\n";try{var o=new Function(n.variable||"obj","_",s)}catch(u){throw u.source=s,u}if(t)return o(t,T);var a=function(e){return o.call(this,e,T)};return a.source="function("+(n.variable||"obj")+"){\n"+s+"}",a},T.chain=function(e){return T(e).chain()};var F=function(e){return this._chain?T(e).chain():e};T.mixin(T),N(["pop","push","reverse","shift","sort","splice","unshift"],function(e){var t=r[e];T.prototype[e]=function(){var n=this._wrapped;return t.apply(n,arguments),(e=="shift"||e=="splice")&&n.length===0&&delete n[0],F.call(this,n)}}),N(["concat","join","slice"],function(e){var t=r[e];T.prototype[e]=function(){return F.call(this,t.apply(this._wrapped,arguments))}}),T.extend(T.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}).call(this); \ No newline at end of file diff --git a/wp-admin/js/utils.dev.js b/wp-includes/js/utils.js similarity index 100% rename from wp-admin/js/utils.dev.js rename to wp-includes/js/utils.js diff --git a/wp-admin/js/utils.js b/wp-includes/js/utils.min.js similarity index 100% rename from wp-admin/js/utils.js rename to wp-includes/js/utils.min.js diff --git a/wp-includes/js/wp-ajax-response.dev.js b/wp-includes/js/wp-ajax-response.dev.js deleted file mode 100644 index d5b003cf..00000000 --- a/wp-includes/js/wp-ajax-response.dev.js +++ /dev/null @@ -1,64 +0,0 @@ -var wpAjax = jQuery.extend( { - unserialize: function( s ) { - var r = {}, q, pp, i, p; - if ( !s ) { return r; } - q = s.split('?'); if ( q[1] ) { s = q[1]; } - pp = s.split('&'); - for ( i in pp ) { - if ( jQuery.isFunction(pp.hasOwnProperty) && !pp.hasOwnProperty(i) ) { continue; } - p = pp[i].split('='); - r[p[0]] = p[1]; - } - return r; - }, - parseAjaxResponse: function( x, r, e ) { // 1 = good, 0 = strange (bad data?), -1 = you lack permission - var parsed = {}, re = jQuery('#' + r).html(''), err = ''; - - if ( x && typeof x == 'object' && x.getElementsByTagName('wp_ajax') ) { - parsed.responses = []; - parsed.errors = false; - jQuery('response', x).each( function() { - var th = jQuery(this), child = jQuery(this.firstChild), response; - response = { action: th.attr('action'), what: child.get(0).nodeName, id: child.attr('id'), oldId: child.attr('old_id'), position: child.attr('position') }; - response.data = jQuery( 'response_data', child ).text(); - response.supplemental = {}; - if ( !jQuery( 'supplemental', child ).children().each( function() { - response.supplemental[this.nodeName] = jQuery(this).text(); - } ).size() ) { response.supplemental = false } - response.errors = []; - if ( !jQuery('wp_error', child).each( function() { - var code = jQuery(this).attr('code'), anError, errorData, formField; - anError = { code: code, message: this.firstChild.nodeValue, data: false }; - errorData = jQuery('wp_error_data[code="' + code + '"]', x); - if ( errorData ) { anError.data = errorData.get(); } - formField = jQuery( 'form-field', errorData ).text(); - if ( formField ) { code = formField; } - if ( e ) { wpAjax.invalidateForm( jQuery('#' + e + ' :input[name="' + code + '"]' ).parents('.form-field:first') ); } - err += '

    ' + anError.message + '

    '; - response.errors.push( anError ); - parsed.errors = true; - } ).size() ) { response.errors = false; } - parsed.responses.push( response ); - } ); - if ( err.length ) { re.html( '
    ' + err + '
    ' ); } - return parsed; - } - if ( isNaN(x) ) { return !re.html('

    ' + x + '

    '); } - x = parseInt(x,10); - if ( -1 == x ) { return !re.html('

    ' + wpAjax.noPerm + '

    '); } - else if ( 0 === x ) { return !re.html('

    ' + wpAjax.broken + '

    '); } - return true; - }, - invalidateForm: function ( selector ) { - return jQuery( selector ).addClass( 'form-invalid' ).find('input:visible').change( function() { jQuery(this).closest('.form-invalid').removeClass( 'form-invalid' ); } ); - }, - validateForm: function( selector ) { - selector = jQuery( selector ); - return !wpAjax.invalidateForm( selector.find('.form-required').filter( function() { return jQuery('input:visible', this).val() == ''; } ) ).size(); - } -}, wpAjax || { noPerm: 'You do not have permission to do that.', broken: 'An unidentified error has occurred.' } ); - -// Basic form validation -jQuery(document).ready( function($){ - $('form.validate').submit( function() { return wpAjax.validateForm( $(this) ); } ); -}); diff --git a/wp-includes/js/wp-ajax-response.js b/wp-includes/js/wp-ajax-response.js index bdfa53ab..d5b003cf 100644 --- a/wp-includes/js/wp-ajax-response.js +++ b/wp-includes/js/wp-ajax-response.js @@ -1 +1,64 @@ -var wpAjax=jQuery.extend({unserialize:function(c){var d={},e,a,b,f;if(!c){return d}e=c.split("?");if(e[1]){c=e[1]}a=c.split("&");for(b in a){if(jQuery.isFunction(a.hasOwnProperty)&&!a.hasOwnProperty(b)){continue}f=a[b].split("=");d[f[0]]=f[1]}return d},parseAjaxResponse:function(a,f,g){var b={},c=jQuery("#"+f).html(""),d="";if(a&&typeof a=="object"&&a.getElementsByTagName("wp_ajax")){b.responses=[];b.errors=false;jQuery("response",a).each(function(){var h=jQuery(this),i=jQuery(this.firstChild),e;e={action:h.attr("action"),what:i.get(0).nodeName,id:i.attr("id"),oldId:i.attr("old_id"),position:i.attr("position")};e.data=jQuery("response_data",i).text();e.supplemental={};if(!jQuery("supplemental",i).children().each(function(){e.supplemental[this.nodeName]=jQuery(this).text()}).size()){e.supplemental=false}e.errors=[];if(!jQuery("wp_error",i).each(function(){var j=jQuery(this).attr("code"),m,l,k;m={code:j,message:this.firstChild.nodeValue,data:false};l=jQuery('wp_error_data[code="'+j+'"]',a);if(l){m.data=l.get()}k=jQuery("form-field",l).text();if(k){j=k}if(g){wpAjax.invalidateForm(jQuery("#"+g+' :input[name="'+j+'"]').parents(".form-field:first"))}d+="

    "+m.message+"

    ";e.errors.push(m);b.errors=true}).size()){e.errors=false}b.responses.push(e)});if(d.length){c.html('
    '+d+"
    ")}return b}if(isNaN(a)){return !c.html('

    '+a+"

    ")}a=parseInt(a,10);if(-1==a){return !c.html('

    '+wpAjax.noPerm+"

    ")}else{if(0===a){return !c.html('

    '+wpAjax.broken+"

    ")}}return true},invalidateForm:function(a){return jQuery(a).addClass("form-invalid").find("input:visible").change(function(){jQuery(this).closest(".form-invalid").removeClass("form-invalid")})},validateForm:function(a){a=jQuery(a);return !wpAjax.invalidateForm(a.find(".form-required").filter(function(){return jQuery("input:visible",this).val()==""})).size()}},wpAjax||{noPerm:"You do not have permission to do that.",broken:"An unidentified error has occurred."});jQuery(document).ready(function(a){a("form.validate").submit(function(){return wpAjax.validateForm(a(this))})}); \ No newline at end of file +var wpAjax = jQuery.extend( { + unserialize: function( s ) { + var r = {}, q, pp, i, p; + if ( !s ) { return r; } + q = s.split('?'); if ( q[1] ) { s = q[1]; } + pp = s.split('&'); + for ( i in pp ) { + if ( jQuery.isFunction(pp.hasOwnProperty) && !pp.hasOwnProperty(i) ) { continue; } + p = pp[i].split('='); + r[p[0]] = p[1]; + } + return r; + }, + parseAjaxResponse: function( x, r, e ) { // 1 = good, 0 = strange (bad data?), -1 = you lack permission + var parsed = {}, re = jQuery('#' + r).html(''), err = ''; + + if ( x && typeof x == 'object' && x.getElementsByTagName('wp_ajax') ) { + parsed.responses = []; + parsed.errors = false; + jQuery('response', x).each( function() { + var th = jQuery(this), child = jQuery(this.firstChild), response; + response = { action: th.attr('action'), what: child.get(0).nodeName, id: child.attr('id'), oldId: child.attr('old_id'), position: child.attr('position') }; + response.data = jQuery( 'response_data', child ).text(); + response.supplemental = {}; + if ( !jQuery( 'supplemental', child ).children().each( function() { + response.supplemental[this.nodeName] = jQuery(this).text(); + } ).size() ) { response.supplemental = false } + response.errors = []; + if ( !jQuery('wp_error', child).each( function() { + var code = jQuery(this).attr('code'), anError, errorData, formField; + anError = { code: code, message: this.firstChild.nodeValue, data: false }; + errorData = jQuery('wp_error_data[code="' + code + '"]', x); + if ( errorData ) { anError.data = errorData.get(); } + formField = jQuery( 'form-field', errorData ).text(); + if ( formField ) { code = formField; } + if ( e ) { wpAjax.invalidateForm( jQuery('#' + e + ' :input[name="' + code + '"]' ).parents('.form-field:first') ); } + err += '

    ' + anError.message + '

    '; + response.errors.push( anError ); + parsed.errors = true; + } ).size() ) { response.errors = false; } + parsed.responses.push( response ); + } ); + if ( err.length ) { re.html( '
    ' + err + '
    ' ); } + return parsed; + } + if ( isNaN(x) ) { return !re.html('

    ' + x + '

    '); } + x = parseInt(x,10); + if ( -1 == x ) { return !re.html('

    ' + wpAjax.noPerm + '

    '); } + else if ( 0 === x ) { return !re.html('

    ' + wpAjax.broken + '

    '); } + return true; + }, + invalidateForm: function ( selector ) { + return jQuery( selector ).addClass( 'form-invalid' ).find('input:visible').change( function() { jQuery(this).closest('.form-invalid').removeClass( 'form-invalid' ); } ); + }, + validateForm: function( selector ) { + selector = jQuery( selector ); + return !wpAjax.invalidateForm( selector.find('.form-required').filter( function() { return jQuery('input:visible', this).val() == ''; } ) ).size(); + } +}, wpAjax || { noPerm: 'You do not have permission to do that.', broken: 'An unidentified error has occurred.' } ); + +// Basic form validation +jQuery(document).ready( function($){ + $('form.validate').submit( function() { return wpAjax.validateForm( $(this) ); } ); +}); diff --git a/wp-includes/js/wp-ajax-response.min.js b/wp-includes/js/wp-ajax-response.min.js new file mode 100644 index 00000000..bdfa53ab --- /dev/null +++ b/wp-includes/js/wp-ajax-response.min.js @@ -0,0 +1 @@ +var wpAjax=jQuery.extend({unserialize:function(c){var d={},e,a,b,f;if(!c){return d}e=c.split("?");if(e[1]){c=e[1]}a=c.split("&");for(b in a){if(jQuery.isFunction(a.hasOwnProperty)&&!a.hasOwnProperty(b)){continue}f=a[b].split("=");d[f[0]]=f[1]}return d},parseAjaxResponse:function(a,f,g){var b={},c=jQuery("#"+f).html(""),d="";if(a&&typeof a=="object"&&a.getElementsByTagName("wp_ajax")){b.responses=[];b.errors=false;jQuery("response",a).each(function(){var h=jQuery(this),i=jQuery(this.firstChild),e;e={action:h.attr("action"),what:i.get(0).nodeName,id:i.attr("id"),oldId:i.attr("old_id"),position:i.attr("position")};e.data=jQuery("response_data",i).text();e.supplemental={};if(!jQuery("supplemental",i).children().each(function(){e.supplemental[this.nodeName]=jQuery(this).text()}).size()){e.supplemental=false}e.errors=[];if(!jQuery("wp_error",i).each(function(){var j=jQuery(this).attr("code"),m,l,k;m={code:j,message:this.firstChild.nodeValue,data:false};l=jQuery('wp_error_data[code="'+j+'"]',a);if(l){m.data=l.get()}k=jQuery("form-field",l).text();if(k){j=k}if(g){wpAjax.invalidateForm(jQuery("#"+g+' :input[name="'+j+'"]').parents(".form-field:first"))}d+="

    "+m.message+"

    ";e.errors.push(m);b.errors=true}).size()){e.errors=false}b.responses.push(e)});if(d.length){c.html('
    '+d+"
    ")}return b}if(isNaN(a)){return !c.html('

    '+a+"

    ")}a=parseInt(a,10);if(-1==a){return !c.html('

    '+wpAjax.noPerm+"

    ")}else{if(0===a){return !c.html('

    '+wpAjax.broken+"

    ")}}return true},invalidateForm:function(a){return jQuery(a).addClass("form-invalid").find("input:visible").change(function(){jQuery(this).closest(".form-invalid").removeClass("form-invalid")})},validateForm:function(a){a=jQuery(a);return !wpAjax.invalidateForm(a.find(".form-required").filter(function(){return jQuery("input:visible",this).val()==""})).size()}},wpAjax||{noPerm:"You do not have permission to do that.",broken:"An unidentified error has occurred."});jQuery(document).ready(function(a){a("form.validate").submit(function(){return wpAjax.validateForm(a(this))})}); \ No newline at end of file diff --git a/wp-includes/js/wp-list-revisions.dev.js b/wp-includes/js/wp-list-revisions.dev.js deleted file mode 100644 index 9c702c65..00000000 --- a/wp-includes/js/wp-list-revisions.dev.js +++ /dev/null @@ -1,24 +0,0 @@ -(function(w) { - var init = function() { - var pr = document.getElementById('post-revisions'), - inputs = pr ? pr.getElementsByTagName('input') : []; - pr.onclick = function() { - var i, checkCount = 0, side; - for ( i = 0; i < inputs.length; i++ ) { - checkCount += inputs[i].checked ? 1 : 0; - side = inputs[i].getAttribute('name'); - if ( ! inputs[i].checked && - ( 'left' == side && 1 > checkCount || 'right' == side && 1 < checkCount && ( ! inputs[i-1] || ! inputs[i-1].checked ) ) && - ! ( inputs[i+1] && inputs[i+1].checked && 'right' == inputs[i+1].getAttribute('name') ) ) - inputs[i].style.visibility = 'hidden'; - else if ( 'left' == side || 'right' == side ) - inputs[i].style.visibility = 'visible'; - } - } - pr.onclick(); - } - if ( w && w.addEventListener ) - w.addEventListener('load', init, false); - else if ( w && w.attachEvent ) - w.attachEvent('onload', init); -})(window); diff --git a/wp-includes/js/wp-list-revisions.js b/wp-includes/js/wp-list-revisions.js index 417572db..9c702c65 100644 --- a/wp-includes/js/wp-list-revisions.js +++ b/wp-includes/js/wp-list-revisions.js @@ -1 +1,24 @@ -(function(a){var b=function(){var d=document.getElementById("post-revisions"),c=d?d.getElementsByTagName("input"):[];d.onclick=function(){var g,f=0,e;for(g=0;gf||"right"==e&&1 checkCount || 'right' == side && 1 < checkCount && ( ! inputs[i-1] || ! inputs[i-1].checked ) ) && + ! ( inputs[i+1] && inputs[i+1].checked && 'right' == inputs[i+1].getAttribute('name') ) ) + inputs[i].style.visibility = 'hidden'; + else if ( 'left' == side || 'right' == side ) + inputs[i].style.visibility = 'visible'; + } + } + pr.onclick(); + } + if ( w && w.addEventListener ) + w.addEventListener('load', init, false); + else if ( w && w.attachEvent ) + w.attachEvent('onload', init); +})(window); diff --git a/wp-includes/js/wp-list-revisions.min.js b/wp-includes/js/wp-list-revisions.min.js new file mode 100644 index 00000000..417572db --- /dev/null +++ b/wp-includes/js/wp-list-revisions.min.js @@ -0,0 +1 @@ +(function(a){var b=function(){var d=document.getElementById("post-revisions"),c=d?d.getElementsByTagName("input"):[];d.onclick=function(){var g,f=0,e;for(g=0;gf||"right"==e&&1
  • ' - + wpLinkL10n.noMatchesFound - + '
  • '; - } - } else { - $.each( results, function() { - classes = alt ? 'alternate' : ''; - classes += this['title'] ? '' : ' no-title'; - list += classes ? '
  • ' : '
  • '; - list += ''; - list += ''; - list += this['title'] ? this['title'] : wpLinkL10n.noTitle; - list += '' + this['info'] + '
  • '; - alt = ! alt; - }); - } - - this.ul[ firstPage ? 'html' : 'append' ]( list ); - }, - maybeLoad: function() { - var self = this, - el = this.element, - bottom = el.scrollTop() + el.height(); - - if ( ! this.query.ready() || bottom < this.ul.height() - wpLink.riverBottomThreshold ) - return; - - setTimeout(function() { - var newTop = el.scrollTop(), - newBottom = newTop + el.height(); - - if ( ! self.query.ready() || newBottom < self.ul.height() - wpLink.riverBottomThreshold ) - return; - - self.waiting.show(); - el.scrollTop( newTop + self.waiting.outerHeight() ); - - self.ajax( function() { self.waiting.hide(); }); - }, wpLink.timeToTriggerRiver ); - } - }); - - Query = function( search ) { - this.page = 1; - this.allLoaded = false; - this.querying = false; - this.search = search; - }; - - $.extend( Query.prototype, { - ready: function() { - return !( this.querying || this.allLoaded ); - }, - ajax: function( callback ) { - var self = this, - query = { - action : 'wp-link-ajax', - page : this.page, - '_ajax_linking_nonce' : inputs.nonce.val() - }; - - if ( this.search ) - query.search = this.search; - - this.querying = true; - - $.post( ajaxurl, query, function(r) { - self.page++; - self.querying = false; - self.allLoaded = !r; - callback( r, query ); - }, "json" ); - } - }); - - $(document).ready( wpLink.init ); -})(jQuery); diff --git a/wp-includes/js/wplink.js b/wp-includes/js/wplink.js index 4ce2f6eb..c52d2a19 100644 --- a/wp-includes/js/wplink.js +++ b/wp-includes/js/wplink.js @@ -1 +1,593 @@ -var wpLink;(function(f){var b={},e={},d,a,c;wpLink={timeToTriggerRiver:150,minRiverAJAXDuration:200,riverBottomThreshold:5,keySensitivity:100,lastSearch:"",textarea:"",init:function(){b.dialog=f("#wp-link");b.submit=f("#wp-link-submit");b.url=f("#url-field");b.nonce=f("#_ajax_linking_nonce");b.title=f("#link-title-field");b.openInNewTab=f("#link-target-checkbox");b.search=f("#search-field");e.search=new a(f("#search-results"));e.recent=new a(f("#most-recent-results"));e.elements=f(".query-results",b.dialog);b.dialog.keydown(wpLink.keydown);b.dialog.keyup(wpLink.keyup);b.submit.click(function(g){g.preventDefault();wpLink.update()});f("#wp-link-cancel").click(function(g){g.preventDefault();wpLink.close()});f("#internal-toggle").click(wpLink.toggleInternalLinking);e.elements.bind("river-select",wpLink.updateFields);b.search.keyup(wpLink.searchInternalLinks);b.dialog.bind("wpdialogrefresh",wpLink.refresh);b.dialog.bind("wpdialogbeforeopen",wpLink.beforeOpen);b.dialog.bind("wpdialogclose",wpLink.onClose)},beforeOpen:function(){wpLink.range=null;if(!wpLink.isMCE()&&document.selection){wpLink.textarea.focus();wpLink.range=document.selection.createRange()}},open:function(){if(!wpActiveEditor){return}this.textarea=f("#"+wpActiveEditor).get(0);if(!b.dialog.data("wpdialog")){b.dialog.wpdialog({title:wpLinkL10n.title,width:480,height:"auto",modal:true,dialogClass:"wp-dialog",zIndex:300000})}b.dialog.wpdialog("open")},isMCE:function(){return tinyMCEPopup&&(d=tinyMCEPopup.editor)&&!d.isHidden()},refresh:function(){e.search.refresh();e.recent.refresh();if(wpLink.isMCE()){wpLink.mceRefresh()}else{wpLink.setDefaultValues()}b.url.focus()[0].select();if(!e.recent.ul.children().length){e.recent.ajax()}},mceRefresh:function(){var g;d=tinyMCEPopup.editor;tinyMCEPopup.restoreSelection();if(g=d.dom.getParent(d.selection.getNode(),"A")){b.url.val(d.dom.getAttrib(g,"href"));b.title.val(d.dom.getAttrib(g,"title"));if("_blank"==d.dom.getAttrib(g,"target")){b.openInNewTab.prop("checked",true)}b.submit.val(wpLinkL10n.update)}else{wpLink.setDefaultValues()}tinyMCEPopup.storeSelection()},close:function(){if(wpLink.isMCE()){tinyMCEPopup.close()}else{b.dialog.wpdialog("close")}},onClose:function(){if(!wpLink.isMCE()){wpLink.textarea.focus();if(wpLink.range){wpLink.range.moveToBookmark(wpLink.range.getBookmark());wpLink.range.select()}}},getAttrs:function(){return{href:b.url.val(),title:b.title.val(),target:b.openInNewTab.prop("checked")?"_blank":""}},update:function(){if(wpLink.isMCE()){wpLink.mceUpdate()}else{wpLink.htmlUpdate()}},htmlUpdate:function(){var i,j,k,h,l,g=wpLink.textarea;if(!g){return}i=wpLink.getAttrs();if(!i.href||i.href=="http://"){return}j='";wpLink.range.moveToBookmark(wpLink.range.getBookmark());wpLink.range.select();wpLink.range=null}else{if(typeof g.selectionStart!=="undefined"){k=g.selectionStart;h=g.selectionEnd;selection=g.value.substring(k,h);j=j+selection+"";l=k+j.length;if(k==h){l-="".length}g.value=g.value.substring(0,k)+j+g.value.substring(h,g.value.length);g.selectionStart=g.selectionEnd=l}}wpLink.close();g.focus()},mceUpdate:function(){var h=tinyMCEPopup.editor,i=wpLink.getAttrs(),j,g;tinyMCEPopup.restoreSelection();j=h.dom.getParent(h.selection.getNode(),"A");if(!i.href||i.href=="http://"){if(j){tinyMCEPopup.execCommand("mceBeginUndoLevel");g=h.selection.getBookmark();h.dom.remove(j,1);h.selection.moveToBookmark(g);tinyMCEPopup.execCommand("mceEndUndoLevel");wpLink.close()}return}tinyMCEPopup.execCommand("mceBeginUndoLevel");if(j==null){h.getDoc().execCommand("unlink",false,null);tinyMCEPopup.execCommand("mceInsertLink",false,"#mce_temp_url#",{skip_undo:1});tinymce.each(h.dom.select("a"),function(k){if(h.dom.getAttrib(k,"href")=="#mce_temp_url#"){j=k;h.dom.setAttribs(j,i)}});if(f(j).text()=="#mce_temp_url#"){h.dom.remove(j);j=null}}else{h.dom.setAttribs(j,i)}if(j&&(j.childNodes.length!=1||j.firstChild.nodeName!="IMG")){h.focus();h.selection.select(j);h.selection.collapse(0);tinyMCEPopup.storeSelection()}tinyMCEPopup.execCommand("mceEndUndoLevel");wpLink.close()},updateFields:function(i,h,g){b.url.val(h.children(".item-permalink").val());b.title.val(h.hasClass("no-title")?"":h.children(".item-title").text());if(g&&g.type=="click"){b.url.focus()}},setDefaultValues:function(){b.url.val("http://");b.title.val("");b.submit.val(wpLinkL10n.save)},searchInternalLinks:function(){var h=f(this),i,g=h.val();if(g.length>2){e.recent.hide();e.search.show();if(wpLink.lastSearch==g){return}wpLink.lastSearch=g;i=h.siblings("img.waiting").show();e.search.change(g);e.search.ajax(function(){i.hide()})}else{e.search.hide();e.recent.show()}},next:function(){e.search.next();e.recent.next()},prev:function(){e.search.prev();e.recent.prev()},keydown:function(i){var h,g=f.ui.keyCode;switch(i.which){case g.UP:h="prev";case g.DOWN:h=h||"next";clearInterval(wpLink.keyInterval);wpLink[h]();wpLink.keyInterval=setInterval(wpLink[h],wpLink.keySensitivity);break;default:return}i.preventDefault()},keyup:function(h){var g=f.ui.keyCode;switch(h.which){case g.ESCAPE:h.stopImmediatePropagation();if(!f(document).triggerHandler("wp_CloseOnEscape",[{event:h,what:"wplink",cb:wpLink.close}])){wpLink.close()}return false;break;case g.UP:case g.DOWN:clearInterval(wpLink.keyInterval);break;default:return}h.preventDefault()},delayedCallback:function(i,g){var l,k,j,h;if(!g){return i}setTimeout(function(){if(k){return i.apply(h,j)}l=true},g);return function(){if(l){return i.apply(this,arguments)}j=arguments;h=this;k=true}},toggleInternalLinking:function(h){var g=f("#search-panel"),i=b.dialog.wpdialog("widget"),k=!g.is(":visible"),j=f(window);f(this).toggleClass("toggle-arrow-active",k);b.dialog.height("auto");g.slideToggle(300,function(){setUserSetting("wplink",k?"1":"0");b[k?"search":"url"].focus();var l=j.scrollTop(),o=i.offset().top,m=o+i.outerHeight(),n=m-j.height();if(n>l){i.animate({top:ni){this.element.scrollTop(g+l-i+j)}}this.element.trigger("river-select",[h,k,this])},deselect:function(){if(this.selected){this.selected.removeClass("selected")}this.selected=false},prev:function(){if(!this.visible){return}var g;if(this.selected){g=this.selected.prev("li");if(g.length){this.select(g)}}},next:function(){if(!this.visible){return}var g=this.selected?this.selected.next("li"):f("li:not(.unselectable):first",this.element);if(g.length){this.select(g)}},ajax:function(j){var h=this,i=this.query.page==1?0:wpLink.minRiverAJAXDuration,g=wpLink.delayedCallback(function(k,l){h.process(k,l);if(j){j(k,l)}},i);this.query.ajax(g)},change:function(g){if(this.query&&this._search==g){return}this._search=g;this.query=new c(g);this.element.scrollTop(0)},process:function(h,l){var i="",j=true,g="",k=l.page==1;if(!h){if(k){i+='
  • '+wpLinkL10n.noMatchesFound+"
  • "}}else{f.each(h,function(){g=j?"alternate":"";g+=this["title"]?"":" no-title";i+=g?'
  • ':"
  • ";i+='';i+='';i+=this["title"]?this["title"]:wpLinkL10n.noTitle;i+=''+this["info"]+"
  • ";j=!j})}this.ul[k?"html":"append"](i)},maybeLoad:function(){var h=this,i=this.element,g=i.scrollTop()+i.height();if(!this.query.ready()||g'; + wpLink.range.moveToBookmark( wpLink.range.getBookmark() ); + wpLink.range.select(); + + wpLink.range = null; + } else if ( typeof textarea.selectionStart !== 'undefined' ) { + // W3C + begin = textarea.selectionStart; + end = textarea.selectionEnd; + selection = textarea.value.substring( begin, end ); + html = html + selection + ''; + cursor = begin + html.length; + + // If no next is selected, place the cursor inside the closing tag. + if ( begin == end ) + cursor -= ''.length; + + textarea.value = textarea.value.substring( 0, begin ) + + html + + textarea.value.substring( end, textarea.value.length ); + + // Update cursor position + textarea.selectionStart = textarea.selectionEnd = cursor; + } + + wpLink.close(); + textarea.focus(); + }, + + mceUpdate : function() { + var ed = tinyMCEPopup.editor, + attrs = wpLink.getAttrs(), + e, b; + + tinyMCEPopup.restoreSelection(); + e = ed.dom.getParent(ed.selection.getNode(), 'A'); + + // If the values are empty, unlink and return + if ( ! attrs.href || attrs.href == 'http://' ) { + if ( e ) { + tinyMCEPopup.execCommand("mceBeginUndoLevel"); + b = ed.selection.getBookmark(); + ed.dom.remove(e, 1); + ed.selection.moveToBookmark(b); + tinyMCEPopup.execCommand("mceEndUndoLevel"); + wpLink.close(); + } + return; + } + + tinyMCEPopup.execCommand("mceBeginUndoLevel"); + + if (e == null) { + ed.getDoc().execCommand("unlink", false, null); + tinyMCEPopup.execCommand("mceInsertLink", false, "#mce_temp_url#", {skip_undo : 1}); + + tinymce.each(ed.dom.select("a"), function(n) { + if (ed.dom.getAttrib(n, 'href') == '#mce_temp_url#') { + e = n; + ed.dom.setAttribs(e, attrs); + } + }); + + // Sometimes WebKit lets a user create a link where + // they shouldn't be able to. In this case, CreateLink + // injects "#mce_temp_url#" into their content. Fix it. + if ( $(e).text() == '#mce_temp_url#' ) { + ed.dom.remove(e); + e = null; + } + } else { + ed.dom.setAttribs(e, attrs); + } + + // Don't move caret if selection was image + if ( e && (e.childNodes.length != 1 || e.firstChild.nodeName != 'IMG') ) { + ed.focus(); + ed.selection.select(e); + ed.selection.collapse(0); + tinyMCEPopup.storeSelection(); + } + + tinyMCEPopup.execCommand("mceEndUndoLevel"); + wpLink.close(); + }, + + updateFields : function( e, li, originalEvent ) { + inputs.url.val( li.children('.item-permalink').val() ); + inputs.title.val( li.hasClass('no-title') ? '' : li.children('.item-title').text() ); + if ( originalEvent && originalEvent.type == "click" ) + inputs.url.focus(); + }, + setDefaultValues : function() { + // Set URL and description to defaults. + // Leave the new tab setting as-is. + inputs.url.val('http://'); + inputs.title.val(''); + + // Update save prompt. + inputs.submit.val( wpLinkL10n.save ); + }, + + searchInternalLinks : function() { + var t = $(this), waiting, + search = t.val(); + + if ( search.length > 2 ) { + rivers.recent.hide(); + rivers.search.show(); + + // Don't search if the keypress didn't change the title. + if ( wpLink.lastSearch == search ) + return; + + wpLink.lastSearch = search; + waiting = t.parent().find('.spinner').show(); + + rivers.search.change( search ); + rivers.search.ajax( function(){ waiting.hide(); }); + } else { + rivers.search.hide(); + rivers.recent.show(); + } + }, + + next : function() { + rivers.search.next(); + rivers.recent.next(); + }, + prev : function() { + rivers.search.prev(); + rivers.recent.prev(); + }, + + keydown : function( event ) { + var fn, key = $.ui.keyCode; + + switch( event.which ) { + case key.UP: + fn = 'prev'; + case key.DOWN: + fn = fn || 'next'; + clearInterval( wpLink.keyInterval ); + wpLink[ fn ](); + wpLink.keyInterval = setInterval( wpLink[ fn ], wpLink.keySensitivity ); + break; + default: + return; + } + event.preventDefault(); + }, + keyup: function( event ) { + var key = $.ui.keyCode; + + switch( event.which ) { + case key.ESCAPE: + event.stopImmediatePropagation(); + if ( ! $(document).triggerHandler( 'wp_CloseOnEscape', [{ event: event, what: 'wplink', cb: wpLink.close }] ) ) + wpLink.close(); + + return false; + break; + case key.UP: + case key.DOWN: + clearInterval( wpLink.keyInterval ); + break; + default: + return; + } + event.preventDefault(); + }, + + delayedCallback : function( func, delay ) { + var timeoutTriggered, funcTriggered, funcArgs, funcContext; + + if ( ! delay ) + return func; + + setTimeout( function() { + if ( funcTriggered ) + return func.apply( funcContext, funcArgs ); + // Otherwise, wait. + timeoutTriggered = true; + }, delay); + + return function() { + if ( timeoutTriggered ) + return func.apply( this, arguments ); + // Otherwise, wait. + funcArgs = arguments; + funcContext = this; + funcTriggered = true; + }; + }, + + toggleInternalLinking : function( event ) { + var panel = $('#search-panel'), + widget = inputs.dialog.wpdialog('widget'), + // We're about to toggle visibility; it's currently the opposite + visible = !panel.is(':visible'), + win = $(window); + + $(this).toggleClass('toggle-arrow-active', visible); + + inputs.dialog.height('auto'); + panel.slideToggle( 300, function() { + setUserSetting('wplink', visible ? '1' : '0'); + inputs[ visible ? 'search' : 'url' ].focus(); + + // Move the box if the box is now expanded, was opened in a collapsed state, + // and if it needs to be moved. (Judged by bottom not being positive or + // bottom being smaller than top.) + var scroll = win.scrollTop(), + top = widget.offset().top, + bottom = top + widget.outerHeight(), + diff = bottom - win.height(); + + if ( diff > scroll ) { + widget.animate({'top': diff < top ? top - diff : scroll }, 200); + } + }); + event.preventDefault(); + } + } + + River = function( element, search ) { + var self = this; + this.element = element; + this.ul = element.children('ul'); + this.waiting = element.find('.river-waiting'); + + this.change( search ); + this.refresh(); + + element.scroll( function(){ self.maybeLoad(); }); + element.delegate('li', 'click', function(e){ self.select( $(this), e ); }); + }; + + $.extend( River.prototype, { + refresh: function() { + this.deselect(); + this.visible = this.element.is(':visible'); + }, + show: function() { + if ( ! this.visible ) { + this.deselect(); + this.element.show(); + this.visible = true; + } + }, + hide: function() { + this.element.hide(); + this.visible = false; + }, + // Selects a list item and triggers the river-select event. + select: function( li, event ) { + var liHeight, elHeight, liTop, elTop; + + if ( li.hasClass('unselectable') || li == this.selected ) + return; + + this.deselect(); + this.selected = li.addClass('selected'); + // Make sure the element is visible + liHeight = li.outerHeight(); + elHeight = this.element.height(); + liTop = li.position().top; + elTop = this.element.scrollTop(); + + if ( liTop < 0 ) // Make first visible element + this.element.scrollTop( elTop + liTop ); + else if ( liTop + liHeight > elHeight ) // Make last visible element + this.element.scrollTop( elTop + liTop - elHeight + liHeight ); + + // Trigger the river-select event + this.element.trigger('river-select', [ li, event, this ]); + }, + deselect: function() { + if ( this.selected ) + this.selected.removeClass('selected'); + this.selected = false; + }, + prev: function() { + if ( ! this.visible ) + return; + + var to; + if ( this.selected ) { + to = this.selected.prev('li'); + if ( to.length ) + this.select( to ); + } + }, + next: function() { + if ( ! this.visible ) + return; + + var to = this.selected ? this.selected.next('li') : $('li:not(.unselectable):first', this.element); + if ( to.length ) + this.select( to ); + }, + ajax: function( callback ) { + var self = this, + delay = this.query.page == 1 ? 0 : wpLink.minRiverAJAXDuration, + response = wpLink.delayedCallback( function( results, params ) { + self.process( results, params ); + if ( callback ) + callback( results, params ); + }, delay ); + + this.query.ajax( response ); + }, + change: function( search ) { + if ( this.query && this._search == search ) + return; + + this._search = search; + this.query = new Query( search ); + this.element.scrollTop(0); + }, + process: function( results, params ) { + var list = '', alt = true, classes = '', + firstPage = params.page == 1; + + if ( !results ) { + if ( firstPage ) { + list += '
  • ' + + wpLinkL10n.noMatchesFound + + '
  • '; + } + } else { + $.each( results, function() { + classes = alt ? 'alternate' : ''; + classes += this['title'] ? '' : ' no-title'; + list += classes ? '
  • ' : '
  • '; + list += ''; + list += ''; + list += this['title'] ? this['title'] : wpLinkL10n.noTitle; + list += '' + this['info'] + '
  • '; + alt = ! alt; + }); + } + + this.ul[ firstPage ? 'html' : 'append' ]( list ); + }, + maybeLoad: function() { + var self = this, + el = this.element, + bottom = el.scrollTop() + el.height(); + + if ( ! this.query.ready() || bottom < this.ul.height() - wpLink.riverBottomThreshold ) + return; + + setTimeout(function() { + var newTop = el.scrollTop(), + newBottom = newTop + el.height(); + + if ( ! self.query.ready() || newBottom < self.ul.height() - wpLink.riverBottomThreshold ) + return; + + self.waiting.show(); + el.scrollTop( newTop + self.waiting.outerHeight() ); + + self.ajax( function() { self.waiting.hide(); }); + }, wpLink.timeToTriggerRiver ); + } + }); + + Query = function( search ) { + this.page = 1; + this.allLoaded = false; + this.querying = false; + this.search = search; + }; + + $.extend( Query.prototype, { + ready: function() { + return !( this.querying || this.allLoaded ); + }, + ajax: function( callback ) { + var self = this, + query = { + action : 'wp-link-ajax', + page : this.page, + '_ajax_linking_nonce' : inputs.nonce.val() + }; + + if ( this.search ) + query.search = this.search; + + this.querying = true; + + $.post( ajaxurl, query, function(r) { + self.page++; + self.querying = false; + self.allLoaded = !r; + callback( r, query ); + }, "json" ); + } + }); + + $(document).ready( wpLink.init ); +})(jQuery); diff --git a/wp-includes/js/wplink.min.js b/wp-includes/js/wplink.min.js new file mode 100644 index 00000000..9d6a5606 --- /dev/null +++ b/wp-includes/js/wplink.min.js @@ -0,0 +1 @@ +var wpLink;(function(f){var b={},e={},d,a,c;wpLink={timeToTriggerRiver:150,minRiverAJAXDuration:200,riverBottomThreshold:5,keySensitivity:100,lastSearch:"",textarea:"",init:function(){b.dialog=f("#wp-link");b.submit=f("#wp-link-submit");b.url=f("#url-field");b.nonce=f("#_ajax_linking_nonce");b.title=f("#link-title-field");b.openInNewTab=f("#link-target-checkbox");b.search=f("#search-field");e.search=new a(f("#search-results"));e.recent=new a(f("#most-recent-results"));e.elements=f(".query-results",b.dialog);b.dialog.keydown(wpLink.keydown);b.dialog.keyup(wpLink.keyup);b.submit.click(function(g){g.preventDefault();wpLink.update()});f("#wp-link-cancel").click(function(g){g.preventDefault();wpLink.close()});f("#internal-toggle").click(wpLink.toggleInternalLinking);e.elements.bind("river-select",wpLink.updateFields);b.search.keyup(wpLink.searchInternalLinks);b.dialog.bind("wpdialogrefresh",wpLink.refresh);b.dialog.bind("wpdialogbeforeopen",wpLink.beforeOpen);b.dialog.bind("wpdialogclose",wpLink.onClose)},beforeOpen:function(){wpLink.range=null;if(!wpLink.isMCE()&&document.selection){wpLink.textarea.focus();wpLink.range=document.selection.createRange()}},open:function(){if(!wpActiveEditor){return}this.textarea=f("#"+wpActiveEditor).get(0);if(!b.dialog.data("wpdialog")){b.dialog.wpdialog({title:wpLinkL10n.title,width:480,height:"auto",modal:true,dialogClass:"wp-dialog",zIndex:300000})}b.dialog.wpdialog("open")},isMCE:function(){return tinyMCEPopup&&(d=tinyMCEPopup.editor)&&!d.isHidden()},refresh:function(){e.search.refresh();e.recent.refresh();if(wpLink.isMCE()){wpLink.mceRefresh()}else{wpLink.setDefaultValues()}b.url.focus()[0].select();if(!e.recent.ul.children().length){e.recent.ajax()}},mceRefresh:function(){var g;d=tinyMCEPopup.editor;tinyMCEPopup.restoreSelection();if(g=d.dom.getParent(d.selection.getNode(),"A")){b.url.val(d.dom.getAttrib(g,"href"));b.title.val(d.dom.getAttrib(g,"title"));if("_blank"==d.dom.getAttrib(g,"target")){b.openInNewTab.prop("checked",true)}b.submit.val(wpLinkL10n.update)}else{wpLink.setDefaultValues()}tinyMCEPopup.storeSelection()},close:function(){if(wpLink.isMCE()){tinyMCEPopup.close()}else{b.dialog.wpdialog("close")}},onClose:function(){if(!wpLink.isMCE()){wpLink.textarea.focus();if(wpLink.range){wpLink.range.moveToBookmark(wpLink.range.getBookmark());wpLink.range.select()}}},getAttrs:function(){return{href:b.url.val(),title:b.title.val(),target:b.openInNewTab.prop("checked")?"_blank":""}},update:function(){if(wpLink.isMCE()){wpLink.mceUpdate()}else{wpLink.htmlUpdate()}},htmlUpdate:function(){var i,j,k,h,l,g=wpLink.textarea;if(!g){return}i=wpLink.getAttrs();if(!i.href||i.href=="http://"){return}j='";wpLink.range.moveToBookmark(wpLink.range.getBookmark());wpLink.range.select();wpLink.range=null}else{if(typeof g.selectionStart!=="undefined"){k=g.selectionStart;h=g.selectionEnd;selection=g.value.substring(k,h);j=j+selection+"";l=k+j.length;if(k==h){l-="".length}g.value=g.value.substring(0,k)+j+g.value.substring(h,g.value.length);g.selectionStart=g.selectionEnd=l}}wpLink.close();g.focus()},mceUpdate:function(){var h=tinyMCEPopup.editor,i=wpLink.getAttrs(),j,g;tinyMCEPopup.restoreSelection();j=h.dom.getParent(h.selection.getNode(),"A");if(!i.href||i.href=="http://"){if(j){tinyMCEPopup.execCommand("mceBeginUndoLevel");g=h.selection.getBookmark();h.dom.remove(j,1);h.selection.moveToBookmark(g);tinyMCEPopup.execCommand("mceEndUndoLevel");wpLink.close()}return}tinyMCEPopup.execCommand("mceBeginUndoLevel");if(j==null){h.getDoc().execCommand("unlink",false,null);tinyMCEPopup.execCommand("mceInsertLink",false,"#mce_temp_url#",{skip_undo:1});tinymce.each(h.dom.select("a"),function(k){if(h.dom.getAttrib(k,"href")=="#mce_temp_url#"){j=k;h.dom.setAttribs(j,i)}});if(f(j).text()=="#mce_temp_url#"){h.dom.remove(j);j=null}}else{h.dom.setAttribs(j,i)}if(j&&(j.childNodes.length!=1||j.firstChild.nodeName!="IMG")){h.focus();h.selection.select(j);h.selection.collapse(0);tinyMCEPopup.storeSelection()}tinyMCEPopup.execCommand("mceEndUndoLevel");wpLink.close()},updateFields:function(i,h,g){b.url.val(h.children(".item-permalink").val());b.title.val(h.hasClass("no-title")?"":h.children(".item-title").text());if(g&&g.type=="click"){b.url.focus()}},setDefaultValues:function(){b.url.val("http://");b.title.val("");b.submit.val(wpLinkL10n.save)},searchInternalLinks:function(){var h=f(this),i,g=h.val();if(g.length>2){e.recent.hide();e.search.show();if(wpLink.lastSearch==g){return}wpLink.lastSearch=g;i=h.parent().find(".spinner").show();e.search.change(g);e.search.ajax(function(){i.hide()})}else{e.search.hide();e.recent.show()}},next:function(){e.search.next();e.recent.next()},prev:function(){e.search.prev();e.recent.prev()},keydown:function(i){var h,g=f.ui.keyCode;switch(i.which){case g.UP:h="prev";case g.DOWN:h=h||"next";clearInterval(wpLink.keyInterval);wpLink[h]();wpLink.keyInterval=setInterval(wpLink[h],wpLink.keySensitivity);break;default:return}i.preventDefault()},keyup:function(h){var g=f.ui.keyCode;switch(h.which){case g.ESCAPE:h.stopImmediatePropagation();if(!f(document).triggerHandler("wp_CloseOnEscape",[{event:h,what:"wplink",cb:wpLink.close}])){wpLink.close()}return false;break;case g.UP:case g.DOWN:clearInterval(wpLink.keyInterval);break;default:return}h.preventDefault()},delayedCallback:function(i,g){var l,k,j,h;if(!g){return i}setTimeout(function(){if(k){return i.apply(h,j)}l=true},g);return function(){if(l){return i.apply(this,arguments)}j=arguments;h=this;k=true}},toggleInternalLinking:function(h){var g=f("#search-panel"),i=b.dialog.wpdialog("widget"),k=!g.is(":visible"),j=f(window);f(this).toggleClass("toggle-arrow-active",k);b.dialog.height("auto");g.slideToggle(300,function(){setUserSetting("wplink",k?"1":"0");b[k?"search":"url"].focus();var l=j.scrollTop(),o=i.offset().top,m=o+i.outerHeight(),n=m-j.height();if(n>l){i.animate({top:ni){this.element.scrollTop(g+l-i+j)}}this.element.trigger("river-select",[h,k,this])},deselect:function(){if(this.selected){this.selected.removeClass("selected")}this.selected=false},prev:function(){if(!this.visible){return}var g;if(this.selected){g=this.selected.prev("li");if(g.length){this.select(g)}}},next:function(){if(!this.visible){return}var g=this.selected?this.selected.next("li"):f("li:not(.unselectable):first",this.element);if(g.length){this.select(g)}},ajax:function(j){var h=this,i=this.query.page==1?0:wpLink.minRiverAJAXDuration,g=wpLink.delayedCallback(function(k,l){h.process(k,l);if(j){j(k,l)}},i);this.query.ajax(g)},change:function(g){if(this.query&&this._search==g){return}this._search=g;this.query=new c(g);this.element.scrollTop(0)},process:function(h,l){var i="",j=true,g="",k=l.page==1;if(!h){if(k){i+='
  • '+wpLinkL10n.noMatchesFound+"
  • "}}else{f.each(h,function(){g=j?"alternate":"";g+=this["title"]?"":" no-title";i+=g?'
  • ':"
  • ";i+='';i+='';i+=this["title"]?this["title"]:wpLinkL10n.noTitle;i+=''+this["info"]+"
  • ";j=!j})}this.ul[k?"html":"append"](i)},maybeLoad:function(){var h=this,i=this.element,g=i.scrollTop()+i.height();if(!this.query.ready()||g array(), 'a' => array( - 'class' => true, 'href' => true, - 'id' => true, - 'title' => true, 'rel' => true, 'rev' => true, 'name' => true, 'target' => true, ), - 'abbr' => array( - 'class' => true, - 'title' => true, - ), - 'acronym' => array( - 'title' => true, + 'abbr' => array(), + 'acronym' => array(), + 'area' => array( + 'alt' => true, + 'coords' => true, + 'href' => true, + 'nohref' => true, + 'shape' => true, + 'target' => true, ), 'article' => array( 'align' => true, - 'class' => true, 'dir' => true, 'lang' => true, - 'style' => true, 'xml:lang' => true, ), 'aside' => array( 'align' => true, - 'class' => true, 'dir' => true, 'lang' => true, - 'style' => true, 'xml:lang' => true, ), 'b' => array(), 'big' => array(), 'blockquote' => array( - 'id' => true, 'cite' => true, - 'class' => true, 'lang' => true, 'xml:lang' => true, ), - 'br' => array ( - 'class' => true, - ), + 'br' => array(), 'button' => array( 'disabled' => true, 'name' => true, @@ -103,24 +100,18 @@ if ( ! CUSTOM_TAGS ) { ), 'caption' => array( 'align' => true, - 'class' => true, ), - 'cite' => array ( - 'class' => true, + 'cite' => array( 'dir' => true, 'lang' => true, - 'title' => true, - ), - 'code' => array ( - 'style' => true, ), + 'code' => array(), 'col' => array( 'align' => true, 'char' => true, 'charoff' => true, 'span' => true, 'dir' => true, - 'style' => true, 'valign' => true, 'width' => true, ), @@ -130,19 +121,15 @@ if ( ! CUSTOM_TAGS ) { 'dd' => array(), 'details' => array( 'align' => true, - 'class' => true, 'dir' => true, 'lang' => true, 'open' => true, - 'style' => true, 'xml:lang' => true, ), 'div' => array( 'align' => true, - 'class' => true, 'dir' => true, 'lang' => true, - 'style' => true, 'xml:lang' => true, ), 'dl' => array(), @@ -151,18 +138,14 @@ if ( ! CUSTOM_TAGS ) { 'fieldset' => array(), 'figure' => array( 'align' => true, - 'class' => true, 'dir' => true, 'lang' => true, - 'style' => true, 'xml:lang' => true, ), 'figcaption' => array( 'align' => true, - 'class' => true, 'dir' => true, 'lang' => true, - 'style' => true, 'xml:lang' => true, ), 'font' => array( @@ -172,10 +155,8 @@ if ( ! CUSTOM_TAGS ) { ), 'footer' => array( 'align' => true, - 'class' => true, 'dir' => true, 'lang' => true, - 'style' => true, 'xml:lang' => true, ), 'form' => array( @@ -189,59 +170,36 @@ if ( ! CUSTOM_TAGS ) { ), 'h1' => array( 'align' => true, - 'class' => true, - 'id' => true, - 'style' => true, ), - 'h2' => array ( + 'h2' => array( 'align' => true, - 'class' => true, - 'id' => true, - 'style' => true, ), - 'h3' => array ( + 'h3' => array( 'align' => true, - 'class' => true, - 'id' => true, - 'style' => true, ), - 'h4' => array ( + 'h4' => array( 'align' => true, - 'class' => true, - 'id' => true, - 'style' => true, ), - 'h5' => array ( + 'h5' => array( 'align' => true, - 'class' => true, - 'id' => true, - 'style' => true, ), - 'h6' => array ( + 'h6' => array( 'align' => true, - 'class' => true, - 'id' => true, - 'style' => true, ), 'header' => array( 'align' => true, - 'class' => true, 'dir' => true, 'lang' => true, - 'style' => true, 'xml:lang' => true, ), 'hgroup' => array( 'align' => true, - 'class' => true, 'dir' => true, 'lang' => true, - 'style' => true, 'xml:lang' => true, ), - 'hr' => array ( + 'hr' => array( 'align' => true, - 'class' => true, 'noshade' => true, 'size' => true, 'width' => true, @@ -251,13 +209,12 @@ if ( ! CUSTOM_TAGS ) { 'alt' => true, 'align' => true, 'border' => true, - 'class' => true, 'height' => true, 'hspace' => true, 'longdesc' => true, 'vspace' => true, 'src' => true, - 'style' => true, + 'usemap' => true, 'width' => true, ), 'ins' => array( @@ -271,65 +228,54 @@ if ( ! CUSTOM_TAGS ) { 'legend' => array( 'align' => true, ), - 'li' => array ( + 'li' => array( 'align' => true, - 'class' => true, ), - 'menu' => array ( - 'class' => true, - 'style' => true, + 'map' => array( + 'name' => true, + ), + 'menu' => array( 'type' => true, ), 'nav' => array( 'align' => true, - 'class' => true, 'dir' => true, 'lang' => true, - 'style' => true, 'xml:lang' => true, ), 'p' => array( - 'class' => true, 'align' => true, 'dir' => true, 'lang' => true, - 'style' => true, 'xml:lang' => true, ), 'pre' => array( - 'style' => true, 'width' => true, ), 'q' => array( 'cite' => true, ), 's' => array(), - 'span' => array ( - 'class' => true, + 'span' => array( 'dir' => true, 'align' => true, 'lang' => true, - 'style' => true, - 'title' => true, 'xml:lang' => true, ), 'section' => array( 'align' => true, - 'class' => true, 'dir' => true, 'lang' => true, - 'style' => true, 'xml:lang' => true, ), + 'small' => array(), 'strike' => array(), 'strong' => array(), 'sub' => array(), 'summary' => array( 'align' => true, - 'class' => true, 'dir' => true, 'lang' => true, - 'style' => true, 'xml:lang' => true, ), 'sup' => array(), @@ -339,11 +285,8 @@ if ( ! CUSTOM_TAGS ) { 'border' => true, 'cellpadding' => true, 'cellspacing' => true, - 'class' => true, 'dir' => true, - 'id' => true, 'rules' => true, - 'style' => true, 'summary' => true, 'width' => true, ), @@ -360,7 +303,6 @@ if ( ! CUSTOM_TAGS ) { 'bgcolor' => true, 'char' => true, 'charoff' => true, - 'class' => true, 'colspan' => true, 'dir' => true, 'headers' => true, @@ -368,7 +310,6 @@ if ( ! CUSTOM_TAGS ) { 'nowrap' => true, 'rowspan' => true, 'scope' => true, - 'style' => true, 'valign' => true, 'width' => true, ), @@ -382,7 +323,6 @@ if ( ! CUSTOM_TAGS ) { 'tfoot' => array( 'align' => true, 'char' => true, - 'class' => true, 'charoff' => true, 'valign' => true, ), @@ -393,7 +333,6 @@ if ( ! CUSTOM_TAGS ) { 'bgcolor' => true, 'char' => true, 'charoff' => true, - 'class' => true, 'colspan' => true, 'headers' => true, 'height' => true, @@ -407,7 +346,6 @@ if ( ! CUSTOM_TAGS ) { 'align' => true, 'char' => true, 'charoff' => true, - 'class' => true, 'valign' => true, ), 'title' => array(), @@ -416,21 +354,15 @@ if ( ! CUSTOM_TAGS ) { 'bgcolor' => true, 'char' => true, 'charoff' => true, - 'class' => true, - 'style' => true, 'valign' => true, ), 'tt' => array(), 'u' => array(), - 'ul' => array ( - 'class' => true, - 'style' => true, + 'ul' => array( 'type' => true, ), - 'ol' => array ( - 'class' => true, + 'ol' => array( 'start' => true, - 'style' => true, 'type' => true, ), 'var' => array(), @@ -457,29 +389,18 @@ if ( ! CUSTOM_TAGS ) { 'blockquote' => array( 'cite' => true, ), - // 'br' => array(), 'cite' => array(), 'code' => array(), 'del' => array( 'datetime' => true, ), - // 'dd' => array(), - // 'dl' => array(), - // 'dt' => array(), - 'em' => array (), 'i' => array (), - // 'ins' => array('datetime' => array(), 'cite' => array()), - // 'li' => array(), - // 'ol' => array(), - // 'p' => array(), + 'em' => array(), + 'i' => array(), 'q' => array( 'cite' => true, ), 'strike' => array(), 'strong' => array(), - // 'sub' => array(), - // 'sup' => array(), - // 'u' => array(), - // 'ul' => array(), ); $allowedentitynames = array( @@ -525,6 +446,11 @@ if ( ! CUSTOM_TAGS ) { 'sdot', 'lceil', 'rceil', 'lfloor', 'rfloor', 'lang', 'rang', 'loz', 'spades', 'clubs', 'hearts', 'diams', ); + + $allowedposttags = array_map( '_wp_add_global_attributes', $allowedposttags ); +} else { + $allowedtags = wp_kses_array_lc( $allowedtags ); + $allowedposttags = wp_kses_array_lc( $allowedposttags ); } /** @@ -547,15 +473,51 @@ if ( ! CUSTOM_TAGS ) { * @param array $allowed_protocols Optional. Allowed protocol in links. * @return string Filtered content with only allowed HTML elements */ -function wp_kses($string, $allowed_html, $allowed_protocols = array ()) { +function wp_kses( $string, $allowed_html, $allowed_protocols = array() ) { if ( empty( $allowed_protocols ) ) $allowed_protocols = wp_allowed_protocols(); $string = wp_kses_no_null($string); $string = wp_kses_js_entities($string); $string = wp_kses_normalize_entities($string); - $allowed_html_fixed = wp_kses_array_lc($allowed_html); - $string = wp_kses_hook($string, $allowed_html_fixed, $allowed_protocols); // WP changed the order of these funcs and added args to wp_kses_hook - return wp_kses_split($string, $allowed_html_fixed, $allowed_protocols); + $string = wp_kses_hook($string, $allowed_html, $allowed_protocols); // WP changed the order of these funcs and added args to wp_kses_hook + return wp_kses_split($string, $allowed_html, $allowed_protocols); +} + +/** + * Return a list of allowed tags and attributes for a given context. + * + * @since 3.5.0 + * + * @param string $context The context for which to retrieve tags. Allowed values are + * post | strip | data | entities or the name of a field filter such as pre_user_description. + * @return array List of allowed tags and their allowed attributes. + */ +function wp_kses_allowed_html( $context = '' ) { + global $allowedposttags, $allowedtags, $allowedentitynames; + + if ( is_array( $context ) ) + return apply_filters( 'wp_kses_allowed_html', $context, 'explicit' ); + + switch ( $context ) { + case 'post': + return apply_filters( 'wp_kses_allowed_html', $allowedposttags, $context ); + break; + case 'user_description': + case 'pre_user_description': + $tags = $allowedtags; + $tags['a']['rel'] = true; + return apply_filters( 'wp_kses_allowed_html', $tags, $context ); + break; + case 'strip': + return apply_filters( 'wp_kses_allowed_html', array(), $context ); + break; + case 'entities': + return apply_filters( 'wp_kses_allowed_html', $allowedentitynames, $context); + break; + case 'data': + default: + return apply_filters( 'wp_kses_allowed_html', $allowedtags, $context ); + } } /** @@ -571,7 +533,7 @@ function wp_kses($string, $allowed_html, $allowed_protocols = array ()) { * @param array $allowed_protocols Allowed protocol in links * @return string Filtered content through 'pre_kses' hook */ -function wp_kses_hook($string, $allowed_html, $allowed_protocols) { +function wp_kses_hook( $string, $allowed_html, $allowed_protocols ) { $string = apply_filters('pre_kses', $string, $allowed_html, $allowed_protocols); return $string; } @@ -599,7 +561,7 @@ function wp_kses_version() { * @param array $allowed_protocols Allowed protocols to keep * @return string Content with fixed HTML tags */ -function wp_kses_split($string, $allowed_html, $allowed_protocols) { +function wp_kses_split( $string, $allowed_html, $allowed_protocols ) { global $pass_allowed_html, $pass_allowed_protocols; $pass_allowed_html = $allowed_html; $pass_allowed_protocols = $allowed_protocols; @@ -667,6 +629,9 @@ function wp_kses_split2($string, $allowed_html, $allowed_protocols) { $elem = $matches[2]; $attrlist = $matches[3]; + if ( ! is_array( $allowed_html ) ) + $allowed_html = wp_kses_allowed_html( $allowed_html ); + if ( ! isset($allowed_html[strtolower($elem)]) ) return ''; # They are using a not allowed HTML element @@ -698,6 +663,9 @@ function wp_kses_split2($string, $allowed_html, $allowed_protocols) { function wp_kses_attr($element, $attr, $allowed_html, $allowed_protocols) { # Is there a closing XHTML slash at the end of the attributes? + if ( ! is_array( $allowed_html ) ) + $allowed_html = wp_kses_allowed_html( $allowed_html ); + $xhtml_slash = ''; if (preg_match('%\s*/\s*$%', $attr)) $xhtml_slash = ' /'; @@ -776,7 +744,7 @@ function wp_kses_attr($element, $attr, $allowed_html, $allowed_protocols) { * @return array List of attributes after parsing */ function wp_kses_hair($attr, $allowed_protocols) { - $attrarr = array (); + $attrarr = array(); $mode = 0; $attrname = ''; $uris = array('xmlns', 'profile', 'href', 'src', 'cite', 'classid', 'codebase', 'data', 'usemap', 'longdesc', 'action'); @@ -1285,9 +1253,8 @@ function _wp_kses_decode_entities_chr_hexdec( $match ) { * @param string $data Content to filter, expected to be escaped with slashes * @return string Filtered content */ -function wp_filter_kses($data) { - global $allowedtags; - return addslashes( wp_kses(stripslashes( $data ), $allowedtags) ); +function wp_filter_kses( $data ) { + return addslashes( wp_kses( stripslashes( $data ), current_filter() ) ); } /** @@ -1299,9 +1266,8 @@ function wp_filter_kses($data) { * @param string $data Content to filter, expected to not be escaped * @return string Filtered content */ -function wp_kses_data($data) { - global $allowedtags; - return wp_kses( $data , $allowedtags ); +function wp_kses_data( $data ) { + return wp_kses( $data , current_filter() ); } /** @@ -1311,14 +1277,12 @@ function wp_kses_data($data) { * data from forms. * * @since 2.0.0 - * @uses $allowedposttags * * @param string $data Post content to filter, expected to be escaped with slashes * @return string Filtered post content with allowed HTML tags and attributes intact. */ function wp_filter_post_kses($data) { - global $allowedposttags; - return addslashes ( wp_kses(stripslashes( $data ), $allowedposttags) ); + return addslashes ( wp_kses( stripslashes( $data ), 'post' ) ); } /** @@ -1328,14 +1292,12 @@ function wp_filter_post_kses($data) { * data from forms. * * @since 2.9.0 - * @uses $allowedposttags * * @param string $data Post content to filter * @return string Filtered post content with allowed HTML tags and attributes intact. */ function wp_kses_post($data) { - global $allowedposttags; - return wp_kses( $data , $allowedposttags ); + return wp_kses( $data , 'post' ); } /** @@ -1346,8 +1308,8 @@ function wp_kses_post($data) { * @param string $data Content to strip all HTML from * @return string Filtered content without any HTML */ -function wp_filter_nohtml_kses($data) { - return addslashes ( wp_kses(stripslashes( $data ), array()) ); +function wp_filter_nohtml_kses( $data ) { + return addslashes ( wp_kses( stripslashes( $data ), 'strip' ) ); } /** @@ -1483,3 +1445,29 @@ function safecss_filter_attr( $css, $deprecated = '' ) { return $css; } + +/** + * Helper function to add global attributes to a tag in the allowed html list. + * + * @since 3.5.0 + * @access private + * + * @param array $value An array of attributes. + * @return array The array of attributes with global attributes added. + */ +function _wp_add_global_attributes( $value ) { + $global_attributes = array( + 'class' => true, + 'id' => true, + 'style' => true, + 'title' => true, + ); + + if ( true === $value ) + $value = array(); + + if ( is_array( $value ) ) + return array_merge( $value, $global_attributes ); + + return $value; +} diff --git a/wp-includes/l10n.php b/wp-includes/l10n.php index 7ec3c426..750e08de 100644 --- a/wp-includes/l10n.php +++ b/wp-includes/l10n.php @@ -65,7 +65,7 @@ function get_locale() { * @return string Translated text */ function translate( $text, $domain = 'default' ) { - $translations = &get_translations_for_domain( $domain ); + $translations = get_translations_for_domain( $domain ); return apply_filters( 'gettext', $translations->translate( $text ), $text, $domain ); } @@ -78,7 +78,7 @@ function before_last_bar( $string ) { } function translate_with_gettext_context( $text, $context, $domain = 'default' ) { - $translations = &get_translations_for_domain( $domain ); + $translations = get_translations_for_domain( $domain ); return apply_filters( 'gettext_with_context', $translations->translate( $text, $context ), $text, $context, $domain ); } @@ -236,7 +236,7 @@ function esc_html_x( $single, $context, $domain = 'default' ) { * @return string Either $single or $plural translated text */ function _n( $single, $plural, $number, $domain = 'default' ) { - $translations = &get_translations_for_domain( $domain ); + $translations = get_translations_for_domain( $domain ); $translation = $translations->translate_plural( $single, $plural, $number ); return apply_filters( 'ngettext', $translation, $single, $plural, $number, $domain ); } @@ -249,7 +249,7 @@ function _n( $single, $plural, $number, $domain = 'default' ) { * */ function _nx($single, $plural, $number, $context, $domain = 'default') { - $translations = &get_translations_for_domain( $domain ); + $translations = get_translations_for_domain( $domain ); $translation = $translations->translate_plural( $single, $plural, $number, $context ); return apply_filters( 'ngettext_with_context', $translation, $single, $plural, $number, $context, $domain ); } @@ -459,9 +459,16 @@ function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) { function load_theme_textdomain( $domain, $path = false ) { $locale = apply_filters( 'theme_locale', get_locale(), $domain ); - $path = ( empty( $path ) ) ? get_template_directory() : $path; + if ( ! $path ) + $path = get_template_directory(); - $mofile = "$path/$locale.mo"; + // Load the textdomain from the Theme provided location, or theme directory first + $mofile = "{$path}/{$locale}.mo"; + if ( $loaded = load_textdomain($domain, $mofile) ) + return $loaded; + + // Else, load textdomain from the Language directory + $mofile = WP_LANG_DIR . "/themes/{$domain}-{$locale}.mo"; return load_textdomain($domain, $mofile); } @@ -478,12 +485,9 @@ function load_theme_textdomain( $domain, $path = false ) { * @param string $domain Unique identifier for retrieving translated strings */ function load_child_theme_textdomain( $domain, $path = false ) { - $locale = apply_filters( 'theme_locale', get_locale(), $domain ); - - $path = ( empty( $path ) ) ? get_stylesheet_directory() : $path; - - $mofile = "$path/$locale.mo"; - return load_textdomain($domain, $mofile); + if ( ! $path ) + $path = get_stylesheet_directory(); + return load_theme_textdomain( $domain, $path ); } /** @@ -493,7 +497,7 @@ function load_child_theme_textdomain( $domain, $path = false ) { * @param string $domain * @return object A Translation instance */ -function &get_translations_for_domain( $domain ) { +function get_translations_for_domain( $domain ) { global $l10n; if ( !isset( $l10n[$domain] ) ) { $l10n[$domain] = new NOOP_Translations; diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index ae8a9f13..de76f45a 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -54,11 +54,11 @@ function user_trailingslashit($string, $type_of_url = '') { * * @param string $mode Permalink mode can be either 'title', 'id', or default, which is 'id'. */ -function permalink_anchor($mode = 'id') { - global $post; - switch ( strtolower($mode) ) { +function permalink_anchor( $mode = 'id' ) { + $post = get_post(); + switch ( strtolower( $mode ) ) { case 'title': - $title = sanitize_title($post->post_title) . '-' . $post->ID; + $title = sanitize_title( $post->post_title ) . '-' . $post->ID; echo ''; break; case 'id': @@ -77,7 +77,7 @@ function permalink_anchor($mode = 'id') { * @param bool $leavename Optional, defaults to false. Whether to keep post name or page name. * @return string */ -function get_permalink($id = 0, $leavename = false) { +function get_permalink( $id = 0, $leavename = false ) { $rewritecode = array( '%year%', '%monthnum%', @@ -96,7 +96,7 @@ function get_permalink($id = 0, $leavename = false) { $post = $id; $sample = true; } else { - $post = &get_post($id); + $post = get_post($id); $sample = false; } @@ -106,7 +106,7 @@ function get_permalink($id = 0, $leavename = false) { if ( $post->post_type == 'page' ) return get_page_link($post->ID, $leavename, $sample); elseif ( $post->post_type == 'attachment' ) - return get_attachment_link($post->ID); + return get_attachment_link( $post->ID, $leavename ); elseif ( in_array($post->post_type, get_post_types( array('_builtin' => false) ) ) ) return get_post_permalink($post->ID, $leavename, $sample); @@ -122,8 +122,10 @@ function get_permalink($id = 0, $leavename = false) { $cats = get_the_category($post->ID); if ( $cats ) { usort($cats, '_usort_terms_by_ID'); // order by ID - $category = $cats[0]->slug; - if ( $parent = $cats[0]->parent ) + $category_object = apply_filters( 'post_link_category', $cats[0], $cats, $post ); + $category_object = get_term( $category_object, 'category' ); + $category = $category_object->slug; + if ( $parent = $category_object->parent ) $category = get_category_parents($parent, false, '/', true) . $category; } // show default category in permalinks, without @@ -176,7 +178,7 @@ function get_permalink($id = 0, $leavename = false) { function get_post_permalink( $id = 0, $leavename = false, $sample = false ) { global $wp_rewrite; - $post = &get_post($id); + $post = get_post($id); if ( is_wp_error( $post ) ) return $post; @@ -230,24 +232,20 @@ function post_permalink( $post_id = 0, $deprecated = '' ) { * * @since 1.5.0 * - * @param int $id Optional. Post ID. + * @param mixed $post Optional. Post ID or object. * @param bool $leavename Optional, defaults to false. Whether to keep page name. * @param bool $sample Optional, defaults to false. Is it a sample permalink. * @return string */ -function get_page_link( $id = false, $leavename = false, $sample = false ) { - global $post; - - $id = (int) $id; - if ( !$id ) - $id = (int) $post->ID; +function get_page_link( $post = false, $leavename = false, $sample = false ) { + $post = get_post( $post ); - if ( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) + if ( 'page' == get_option( 'show_on_front' ) && $post->ID == get_option( 'page_on_front' ) ) $link = home_url('/'); else - $link = _get_page_link( $id , $leavename, $sample ); + $link = _get_page_link( $post, $leavename, $sample ); - return apply_filters('page_link', $link, $id, $sample); + return apply_filters( 'page_link', $link, $post->ID, $sample ); } /** @@ -258,18 +256,15 @@ function get_page_link( $id = false, $leavename = false, $sample = false ) { * @since 2.1.0 * @access private * - * @param int $id Optional. Post ID. + * @param mixed $post Optional. Post ID or object. * @param bool $leavename Optional. Leave name. * @param bool $sample Optional. Sample permalink. * @return string */ -function _get_page_link( $id = false, $leavename = false, $sample = false ) { - global $post, $wp_rewrite; +function _get_page_link( $post = false, $leavename = false, $sample = false ) { + global $wp_rewrite; - if ( !$id ) - $id = (int) $post->ID; - else - $post = &get_post($id); + $post = get_post( $post ); $draft_or_pending = in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) ); @@ -277,16 +272,16 @@ function _get_page_link( $id = false, $leavename = false, $sample = false ) { if ( !empty($link) && ( ( isset($post->post_status) && !$draft_or_pending ) || $sample ) ) { if ( ! $leavename ) { - $link = str_replace('%pagename%', get_page_uri($id), $link); + $link = str_replace('%pagename%', get_page_uri( $post ), $link); } $link = home_url($link); $link = user_trailingslashit($link, 'page'); } else { - $link = home_url("?page_id=$id"); + $link = home_url( '?page_id=' . $post->ID ); } - return apply_filters( '_get_page_link', $link, $id ); + return apply_filters( '_get_page_link', $link, $post->ID ); } /** @@ -296,38 +291,40 @@ function _get_page_link( $id = false, $leavename = false, $sample = false ) { * * @since 2.0.0 * - * @param int $id Optional. Post ID. + * @param mixed $post Optional. Post ID or object. + * @param bool $leavename Optional. Leave name. * @return string */ -function get_attachment_link($id = false) { - global $post, $wp_rewrite; +function get_attachment_link( $post = null, $leavename = false ) { + global $wp_rewrite; $link = false; - if ( ! $id) - $id = (int) $post->ID; + $post = get_post( $post ); - $object = get_post($id); - if ( $wp_rewrite->using_permalinks() && ($object->post_parent > 0) && ($object->post_parent != $id) ) { - $parent = get_post($object->post_parent); + if ( $wp_rewrite->using_permalinks() && ( $post->post_parent > 0 ) && ( $post->post_parent != $post->ID ) ) { + $parent = get_post($post->post_parent); if ( 'page' == $parent->post_type ) - $parentlink = _get_page_link( $object->post_parent ); // Ignores page_on_front + $parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front else - $parentlink = get_permalink( $object->post_parent ); + $parentlink = get_permalink( $post->post_parent ); - if ( is_numeric($object->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') ) - $name = 'attachment/' . $object->post_name; // // is paged so we use the explicit attachment marker + if ( is_numeric($post->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') ) + $name = 'attachment/' . $post->post_name; // // is paged so we use the explicit attachment marker else - $name = $object->post_name; + $name = $post->post_name; if ( strpos($parentlink, '?') === false ) - $link = user_trailingslashit( trailingslashit($parentlink) . $name ); + $link = user_trailingslashit( trailingslashit($parentlink) . '%postname%' ); + + if ( ! $leavename ) + $link = str_replace( '%postname%', $name, $link ); } if ( ! $link ) - $link = home_url( "/?attachment_id=$id" ); + $link = home_url( '/?attachment_id=' . $post->ID ); - return apply_filters('attachment_link', $link, $id); + return apply_filters( 'attachment_link', $link, $post->ID ); } /** @@ -487,9 +484,9 @@ function get_post_comments_feed_link($post_id = 0, $feed = '') { } else { $type = get_post_field('post_type', $post_id); if ( 'page' == $type ) - $url = home_url("?feed=$feed&page_id=$post_id"); + $url = add_query_arg( array( 'feed' => $feed, 'page_id' => $post_id ), home_url( '/' ) ); else - $url = home_url("?feed=$feed&p=$post_id"); + $url = add_query_arg( array( 'feed' => $feed, 'p' => $post_id ), home_url( '/' ) ); } return apply_filters('post_comments_feed_link', $url); @@ -512,7 +509,7 @@ function get_post_comments_feed_link($post_id = 0, $feed = '') { * @return string Link to the comment feed for the current post. */ function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) { - $url = get_post_comments_feed_link($post_id, $feed); + $url = esc_url( get_post_comments_feed_link( $post_id, $feed ) ); if ( empty($link_text) ) $link_text = __('Comments Feed'); @@ -624,7 +621,7 @@ function get_term_feed_link( $term_id, $taxonomy = 'category', $feed = '' ) { if ( 'category' == $taxonomy ) $link = apply_filters( 'category_feed_link', $link, $feed ); elseif ( 'post_tag' == $taxonomy ) - $link = apply_filters( 'category_feed_link', $link, $feed ); + $link = apply_filters( 'tag_feed_link', $link, $feed ); else $link = apply_filters( 'taxonomy_feed_link', $link, $feed, $taxonomy ); @@ -896,7 +893,7 @@ function get_post_type_archive_feed_link( $post_type, $feed = '' ) { * @return string */ function get_edit_post_link( $id = 0, $context = 'display' ) { - if ( !$post = &get_post( $id ) ) + if ( ! $post = get_post( $id ) ) return; if ( 'display' == $context ) @@ -925,7 +922,7 @@ function get_edit_post_link( $id = 0, $context = 'display' ) { * @param int $id Optional. Post ID. */ function edit_post_link( $link = null, $before = '', $after = '', $id = 0 ) { - if ( !$post = &get_post( $id ) ) + if ( !$post = get_post( $id ) ) return; if ( !$url = get_edit_post_link( $post->ID ) ) @@ -955,7 +952,7 @@ function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false if ( ! empty( $deprecated ) ) _deprecated_argument( __FUNCTION__, '3.0' ); - if ( !$post = &get_post( $id ) ) + if ( !$post = get_post( $id ) ) return; $post_type_object = get_post_type_object( $post->post_type ); @@ -969,7 +966,7 @@ function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false $delete_link = add_query_arg( 'action', $action, admin_url( sprintf( $post_type_object->_edit_link, $post->ID ) ) ); - return apply_filters( 'get_delete_post_link', wp_nonce_url( $delete_link, "$action-{$post->post_type}_{$post->ID}" ), $post->ID, $force_delete ); + return apply_filters( 'get_delete_post_link', wp_nonce_url( $delete_link, "$action-post_{$post->ID}" ), $post->ID, $force_delete ); } /** @@ -981,7 +978,7 @@ function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false * @return string */ function get_edit_comment_link( $comment_id = 0 ) { - $comment = &get_comment( $comment_id ); + $comment = get_comment( $comment_id ); if ( !current_user_can( 'edit_comment', $comment->comment_ID ) ) return; @@ -1054,6 +1051,34 @@ function edit_bookmark_link( $link = '', $before = '', $after = '', $bookmark = echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after; } +/** + * Retrieve edit user link + * + * @since 3.5.0 + * + * @param int $user_id Optional. User ID. Defaults to the current user. + * @return string URL to edit user page or empty string. + */ +function get_edit_user_link( $user_id = null ) { + if ( ! $user_id ) + $user_id = get_current_user_id(); + + if ( empty( $user_id ) || ! current_user_can( 'edit_user', $user_id ) ) + return ''; + + $user = get_userdata( $user_id ); + + if ( ! $user ) + return ''; + + if ( get_current_user_id() == $user->ID ) + $link = get_edit_profile_url( $user->ID ); + else + $link = add_query_arg( 'user_id', $user->ID, self_admin_url( 'user-edit.php' ) ); + + return apply_filters( 'get_edit_user_link', $link, $user->ID ); +} + // Navigation links /** @@ -1095,9 +1120,9 @@ function get_next_post($in_same_cat = false, $excluded_categories = '') { * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists. */ function get_adjacent_post( $in_same_cat = false, $excluded_categories = '', $previous = true ) { - global $post, $wpdb; + global $wpdb; - if ( empty( $post ) ) + if ( ! $post = get_post() ) return null; $current_post_date = $post->post_date; @@ -1108,7 +1133,11 @@ function get_adjacent_post( $in_same_cat = false, $excluded_categories = '', $pr $join = " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id"; if ( $in_same_cat ) { + if ( ! is_object_in_taxonomy( $post->post_type, 'category' ) ) + return ''; $cat_array = wp_get_object_terms($post->ID, 'category', array('fields' => 'ids')); + if ( ! $cat_array || is_wp_error( $cat_array ) ) + return ''; $join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")"; } @@ -1145,17 +1174,24 @@ function get_adjacent_post( $in_same_cat = false, $excluded_categories = '', $pr $where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare("WHERE p.post_date $op %s AND p.post_type = %s AND p.post_status = 'publish' $posts_in_ex_cats_sql", $current_post_date, $post->post_type), $in_same_cat, $excluded_categories ); $sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" ); - $query = "SELECT p.* FROM $wpdb->posts AS p $join $where $sort"; + $query = "SELECT p.id FROM $wpdb->posts AS p $join $where $sort"; $query_key = 'adjacent_post_' . md5($query); $result = wp_cache_get($query_key, 'counts'); - if ( false !== $result ) + if ( false !== $result ) { + if ( $result ) + $result = get_post( $result ); return $result; + } - $result = $wpdb->get_row("SELECT p.* FROM $wpdb->posts AS p $join $where $sort"); + $result = $wpdb->get_var( $query ); if ( null === $result ) $result = ''; wp_cache_set($query_key, $result, 'counts'); + + if ( $result ) + $result = get_post( $result ); + return $result; } @@ -1173,20 +1209,22 @@ function get_adjacent_post( $in_same_cat = false, $excluded_categories = '', $pr * @return string */ function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true) { - if ( $previous && is_attachment() && is_object( $GLOBALS['post'] ) ) - $post = & get_post($GLOBALS['post']->post_parent); + if ( $previous && is_attachment() && $post = get_post() ) + $post = get_post( $post->post_parent ); else - $post = get_adjacent_post($in_same_cat,$excluded_categories,$previous); + $post = get_adjacent_post( $in_same_cat, $excluded_categories, $previous ); if ( empty($post) ) return; if ( empty($post->post_title) ) - $post->post_title = $previous ? __('Previous Post') : __('Next Post'); + $post_title = $previous ? __('Previous Post') : __('Next Post'); + else + $post_title = $post->post_title; $date = mysql2date(get_option('date_format'), $post->post_date); - $title = str_replace('%title', $post->post_title, $title); + $title = str_replace('%title', $post_title, $title); $title = str_replace('%date', $date, $title); $title = apply_filters('the_title', $title, $post->ID); @@ -1265,9 +1303,8 @@ function prev_post_rel_link($title = '%title', $in_same_cat = false, $excluded_c * @return object */ function get_boundary_post( $in_same_cat = false, $excluded_categories = '', $start = true ) { - global $post; - - if ( empty($post) || ! is_single() || is_attachment() ) + $post = get_post(); + if ( ! $post || ! is_single() || is_attachment() ) return null; $cat_array = array(); @@ -1337,33 +1374,35 @@ function next_post_link($format='%link »', $link='%title', $in_same_cat = * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. * @param bool $previous Optional, default is true. Whether to display link to previous or next post. */ -function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) { +function adjacent_post_link( $format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true ) { if ( $previous && is_attachment() ) - $post = & get_post($GLOBALS['post']->post_parent); + $post = get_post( get_post()->post_parent ); else - $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous); - - if ( !$post ) - return; + $post = get_adjacent_post( $in_same_cat, $excluded_categories, $previous ); - $title = $post->post_title; + if ( ! $post ) { + $output = ''; + } else { + $title = $post->post_title; - if ( empty($post->post_title) ) - $title = $previous ? __('Previous Post') : __('Next Post'); + if ( empty( $post->post_title ) ) + $title = $previous ? __( 'Previous Post' ) : __( 'Next Post' ); - $title = apply_filters('the_title', $title, $post->ID); - $date = mysql2date(get_option('date_format'), $post->post_date); - $rel = $previous ? 'prev' : 'next'; + $title = apply_filters( 'the_title', $title, $post->ID ); + $date = mysql2date( get_option( 'date_format' ), $post->post_date ); + $rel = $previous ? 'prev' : 'next'; - $string = ''; - $link = str_replace('%title', $title, $link); - $link = str_replace('%date', $date, $link); - $link = $string . $link . ''; + $string = ''; + $inlink = str_replace( '%title', $title, $link ); + $inlink = str_replace( '%date', $date, $inlink ); + $inlink = $string . $inlink . ''; - $format = str_replace('%link', $link, $format); + $output = str_replace( '%link', $inlink, $format ); + } $adjacent = $previous ? 'previous' : 'next'; - echo apply_filters( "{$adjacent}_post_link", $format, $link ); + + echo apply_filters( "{$adjacent}_post_link", $output, $format, $link, $post ); } /** @@ -1385,9 +1424,9 @@ function get_pagenum_link($pagenum = 1, $escape = true ) { $home_root = parse_url(home_url()); $home_root = ( isset($home_root['path']) ) ? $home_root['path'] : ''; - $home_root = preg_quote( trailingslashit( $home_root ), '|' ); + $home_root = preg_quote( $home_root, '|' ); - $request = preg_replace('|^'. $home_root . '|', '', $request); + $request = preg_replace('|^'. $home_root . '|i', '', $request); $request = preg_replace('|^/+|', '', $request); if ( !$wp_rewrite->using_permalinks() || is_admin() ) { @@ -1410,7 +1449,7 @@ function get_pagenum_link($pagenum = 1, $escape = true ) { } $request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request); - $request = preg_replace( '|^index\.php|', '', $request); + $request = preg_replace( '|^index\.php|i', '', $request); $request = ltrim($request, '/'); $base = trailingslashit( get_bloginfo( 'url' ) ); @@ -1646,11 +1685,11 @@ function posts_nav_link( $sep = '', $prelabel = '', $nxtlabel = '' ) { * @return string */ function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) { - global $post, $wp_rewrite; + global $wp_rewrite; $pagenum = (int) $pagenum; - $result = get_permalink( $post->ID ); + $result = get_permalink(); if ( 'newest' == get_option('default_comments_page') ) { if ( $pagenum != $max_page ) { @@ -1842,7 +1881,7 @@ function get_shortcut_link() { * @return string Home url link with optional path appended. */ function home_url( $path = '', $scheme = null ) { - return get_home_url(null, $path, $scheme); + return get_home_url( null, $path, $scheme ); } /** @@ -1863,20 +1902,24 @@ function home_url( $path = '', $scheme = null ) { function get_home_url( $blog_id = null, $path = '', $scheme = null ) { $orig_scheme = $scheme; - if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) - $scheme = is_ssl() && !is_admin() ? 'https' : 'http'; - - if ( empty( $blog_id ) || !is_multisite() ) + if ( empty( $blog_id ) || !is_multisite() ) { $url = get_option( 'home' ); - else - $url = get_blog_option( $blog_id, 'home' ); + } else { + switch_to_blog( $blog_id ); + $url = get_option( 'home' ); + restore_current_blog(); + } - if ( 'relative' == $scheme ) - $url = preg_replace( '#^.+://[^/]*#', '', $url ); - elseif ( 'http' != $scheme ) - $url = str_replace( 'http://', "$scheme://", $url ); + if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) { + if ( is_ssl() && ! is_admin() ) + $scheme = 'https'; + else + $scheme = parse_url( $url, PHP_URL_SCHEME ); + } - if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) + $url = set_url_scheme( $url, $scheme ); + + if ( ! empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) $url .= '/' . ltrim( $path, '/' ); return apply_filters( 'home_url', $url, $path, $orig_scheme, $blog_id ); @@ -1895,11 +1938,11 @@ function get_home_url( $blog_id = null, $path = '', $scheme = null ) { * @uses get_site_url() * * @param string $path Optional. Path relative to the site url. - * @param string $scheme Optional. Scheme to give the site url context. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'. + * @param string $scheme Optional. Scheme to give the site url context. See set_url_scheme(). * @return string Site url link with optional path appended. */ function site_url( $path = '', $scheme = null ) { - return get_site_url(null, $path, $scheme); + return get_site_url( null, $path, $scheme ); } /** @@ -1918,33 +1961,20 @@ function site_url( $path = '', $scheme = null ) { * @return string Site url link with optional path appended. */ function get_site_url( $blog_id = null, $path = '', $scheme = null ) { - // should the list of allowed schemes be maintained elsewhere? - $orig_scheme = $scheme; - if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) { - if ( ( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() ) ) - $scheme = 'https'; - elseif ( ( 'login' == $scheme ) && force_ssl_admin() ) - $scheme = 'https'; - elseif ( ( 'admin' == $scheme ) && force_ssl_admin() ) - $scheme = 'https'; - else - $scheme = ( is_ssl() ? 'https' : 'http' ); - } - - if ( empty( $blog_id ) || !is_multisite() ) + if ( empty( $blog_id ) || !is_multisite() ) { $url = get_option( 'siteurl' ); - else - $url = get_blog_option( $blog_id, 'siteurl' ); + } else { + switch_to_blog( $blog_id ); + $url = get_option( 'siteurl' ); + restore_current_blog(); + } - if ( 'relative' == $scheme ) - $url = preg_replace( '#^.+://[^/]*#', '', $url ); - elseif ( 'http' != $scheme ) - $url = str_replace( 'http://', "{$scheme}://", $url ); + $url = set_url_scheme( $url, $scheme ); - if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) + if ( ! empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) $url .= '/' . ltrim( $path, '/' ); - return apply_filters( 'site_url', $url, $path, $orig_scheme, $blog_id ); + return apply_filters( 'site_url', $url, $path, $scheme, $blog_id ); } /** @@ -1958,7 +1988,7 @@ function get_site_url( $blog_id = null, $path = '', $scheme = null ) { * @return string Admin url link with optional path appended. */ function admin_url( $path = '', $scheme = 'admin' ) { - return get_admin_url(null, $path, $scheme); + return get_admin_url( null, $path, $scheme ); } /** @@ -1975,10 +2005,10 @@ function admin_url( $path = '', $scheme = 'admin' ) { function get_admin_url( $blog_id = null, $path = '', $scheme = 'admin' ) { $url = get_site_url($blog_id, 'wp-admin/', $scheme); - if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) - $url .= ltrim($path, '/'); + if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) + $url .= ltrim( $path, '/' ); - return apply_filters('admin_url', $url, $path, $blog_id); + return apply_filters( 'admin_url', $url, $path, $blog_id ); } /** @@ -2009,9 +2039,7 @@ function includes_url($path = '') { * @return string Content url link with optional path appended. */ function content_url($path = '') { - $url = WP_CONTENT_URL; - if ( 0 === strpos($url, 'http') && is_ssl() ) - $url = str_replace( 'http://', 'https://', $url ); + $url = set_url_scheme( WP_CONTENT_URL ); if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) $url .= '/' . ltrim($path, '/'); @@ -2043,8 +2071,8 @@ function plugins_url($path = '', $plugin = '') { else $url = WP_PLUGIN_URL; - if ( 0 === strpos($url, 'http') && is_ssl() ) - $url = str_replace( 'http://', 'https://', $url ); + + $url = set_url_scheme( $url ); if ( !empty($plugin) && is_string($plugin) ) { $folder = dirname(plugin_basename($plugin)); @@ -2069,36 +2097,24 @@ function plugins_url($path = '', $plugin = '') { * @since 3.0.0 * * @param string $path Optional. Path relative to the site url. - * @param string $scheme Optional. Scheme to give the site url context. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'. + * @param string $scheme Optional. Scheme to give the site url context. See set_url_scheme(). * @return string Site url link with optional path appended. */ function network_site_url( $path = '', $scheme = null ) { global $current_site; - if ( !is_multisite() ) + if ( ! is_multisite() ) return site_url($path, $scheme); - $orig_scheme = $scheme; - if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) { - if ( ( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() ) ) - $scheme = 'https'; - elseif ( ('login' == $scheme) && ( force_ssl_admin() ) ) - $scheme = 'https'; - elseif ( ('admin' == $scheme) && force_ssl_admin() ) - $scheme = 'https'; - else - $scheme = ( is_ssl() ? 'https' : 'http' ); - } - if ( 'relative' == $scheme ) $url = $current_site->path; else - $url = $scheme . '://' . $current_site->domain . $current_site->path; + $url = set_url_scheme( 'http://' . $current_site->domain . $current_site->path, $scheme ); - if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) - $url .= ltrim($path, '/'); + if ( ! empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) + $url .= ltrim( $path, '/' ); - return apply_filters('network_site_url', $url, $path, $orig_scheme); + return apply_filters( 'network_site_url', $url, $path, $scheme ); } /** @@ -2118,20 +2134,20 @@ function network_site_url( $path = '', $scheme = null ) { function network_home_url( $path = '', $scheme = null ) { global $current_site; - if ( !is_multisite() ) + if ( ! is_multisite() ) return home_url($path, $scheme); $orig_scheme = $scheme; - if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) - $scheme = is_ssl() && !is_admin() ? 'https' : 'http'; + if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) + $scheme = is_ssl() && ! is_admin() ? 'https' : 'http'; if ( 'relative' == $scheme ) $url = $current_site->path; else - $url = $scheme . '://' . $current_site->domain . $current_site->path; + $url = set_url_scheme( 'http://' . $current_site->domain . $current_site->path, $scheme ); - if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) + if ( ! empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) $url .= ltrim( $path, '/' ); return apply_filters( 'network_home_url', $url, $path, $orig_scheme); @@ -2302,6 +2318,10 @@ function rel_canonical() { return; $link = get_permalink( $id ); + + if ( $page = get_query_var('cpage') ) + $link = get_comments_pagenum_link( $page ); + echo "\n"; } @@ -2401,7 +2421,7 @@ function wp_shortlink_header() { * @param string $after Optional HTML to display after the link. */ function the_shortlink( $text = '', $title = '', $before = '', $after = '' ) { - global $post; + $post = get_post(); if ( empty( $text ) ) $text = __('This is the short link.'); diff --git a/wp-includes/load.php b/wp-includes/load.php index 7e026203..1742af40 100644 --- a/wp-includes/load.php +++ b/wp-includes/load.php @@ -356,7 +356,7 @@ function wp_set_wpdb_vars() { dead_db(); $wpdb->field_types = array( 'post_author' => '%d', 'post_parent' => '%d', 'menu_order' => '%d', 'term_id' => '%d', 'term_group' => '%d', 'term_taxonomy_id' => '%d', - 'parent' => '%d', 'count' => '%d','object_id' => '%d', 'term_order' => '%d', 'ID' => '%d', 'commment_ID' => '%d', 'comment_post_ID' => '%d', 'comment_parent' => '%d', + 'parent' => '%d', 'count' => '%d','object_id' => '%d', 'term_order' => '%d', 'ID' => '%d', 'comment_ID' => '%d', 'comment_post_ID' => '%d', 'comment_parent' => '%d', 'user_id' => '%d', 'link_id' => '%d', 'link_owner' => '%d', 'link_rating' => '%d', 'option_id' => '%d', 'blog_id' => '%d', 'meta_id' => '%d', 'post_id' => '%d', 'user_status' => '%d', 'umeta_id' => '%d', 'comment_karma' => '%d', 'comment_count' => '%d', // multisite: @@ -381,7 +381,7 @@ function wp_set_wpdb_vars() { * @since 3.0.0 */ function wp_start_object_cache() { - global $_wp_using_ext_object_cache; + global $_wp_using_ext_object_cache, $blog_id; $first_init = false; if ( ! function_exists( 'wp_cache_init' ) ) { @@ -403,13 +403,13 @@ function wp_start_object_cache() { // If cache supports reset, reset instead of init if already initialized. // Reset signals to the cache that global IDs have changed and it may need to update keys // and cleanup caches. - if ( !$first_init && function_exists('wp_cache_reset') ) - wp_cache_reset(); + if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) ) + wp_cache_switch_to_blog( $blog_id ); else wp_cache_init(); if ( function_exists( 'wp_cache_add_global_groups' ) ) { - wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) ); + wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache' ) ); wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) ); } } @@ -583,8 +583,11 @@ function wp_clone( $object ) { * @return bool True if inside WordPress administration pages. */ function is_admin() { - if ( defined( 'WP_ADMIN' ) ) + if ( isset( $GLOBALS['current_screen'] ) ) + return $GLOBALS['current_screen']->in_admin(); + elseif ( defined( 'WP_ADMIN' ) ) return WP_ADMIN; + return false; } @@ -599,8 +602,11 @@ function is_admin() { * @return bool True if inside WordPress network administration pages. */ function is_blog_admin() { - if ( defined( 'WP_BLOG_ADMIN' ) ) + if ( isset( $GLOBALS['current_screen'] ) ) + return $GLOBALS['current_screen']->in_admin( 'site' ); + elseif ( defined( 'WP_BLOG_ADMIN' ) ) return WP_BLOG_ADMIN; + return false; } @@ -615,8 +621,11 @@ function is_blog_admin() { * @return bool True if inside WordPress network administration pages. */ function is_network_admin() { - if ( defined( 'WP_NETWORK_ADMIN' ) ) + if ( isset( $GLOBALS['current_screen'] ) ) + return $GLOBALS['current_screen']->in_admin( 'network' ); + elseif ( defined( 'WP_NETWORK_ADMIN' ) ) return WP_NETWORK_ADMIN; + return false; } @@ -631,8 +640,11 @@ function is_network_admin() { * @return bool True if inside WordPress user administration pages. */ function is_user_admin() { - if ( defined( 'WP_USER_ADMIN' ) ) + if ( isset( $GLOBALS['current_screen'] ) ) + return $GLOBALS['current_screen']->in_admin( 'user' ); + elseif ( defined( 'WP_USER_ADMIN' ) ) return WP_USER_ADMIN; + return false; } @@ -653,6 +665,18 @@ function is_multisite() { return false; } +/** + * Retrieve the current blog id + * + * @since 3.1.0 + * + * @return int Blog id + */ +function get_current_blog_id() { + global $blog_id; + return absint($blog_id); +} + /** * Attempts an early load of translations. * diff --git a/wp-includes/media-template.php b/wp-includes/media-template.php new file mode 100644 index 00000000..909ddfe5 --- /dev/null +++ b/wp-includes/media-template.php @@ -0,0 +1,467 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 && is_admin() ) // Only in admin. Assume that theme authors know what they're doing. + if ( intval($content_width) > 0 && 'edit' == $context ) // Only in admin. Assume that theme authors know what they're doing. $max_width = min( intval($content_width), $max_width ); } // $size == 'full' has no constraint @@ -73,7 +78,7 @@ function image_constrain_size_for_editor($width, $height, $size = 'medium') { $max_height = $height; } - list( $max_width, $max_height ) = apply_filters( 'editor_max_image_size', array( $max_width, $max_height ), $size ); + list( $max_width, $max_height ) = apply_filters( 'editor_max_image_size', array( $max_width, $max_height ), $size, $context ); return wp_constrain_dimensions( $width, $height, $max_width, $max_height ); } @@ -225,44 +230,18 @@ function get_image_tag($id, $alt, $title, $align, $size='medium') { list( $img_src, $width, $height ) = image_downsize($id, $size); $hwstring = image_hwstring($width, $height); + $title = $title ? 'title="' . esc_attr( $title ) . '" ' : ''; + $class = 'align' . esc_attr($align) .' size-' . esc_attr($size) . ' wp-image-' . $id; $class = apply_filters('get_image_tag_class', $class, $id, $align, $size); - $html = '' . esc_attr($alt) . ''; + $html = '' . esc_attr($alt) . ''; $html = apply_filters( 'get_image_tag', $html, $id, $alt, $title, $align, $size ); return $html; } -/** - * Load an image from a string, if PHP supports it. - * - * @since 2.1.0 - * - * @param string $file Filename of the image to load. - * @return resource The resulting image resource on success, Error string on failure. - */ -function wp_load_image( $file ) { - if ( is_numeric( $file ) ) - $file = get_attached_file( $file ); - - if ( ! file_exists( $file ) ) - return sprintf(__('File “%s” doesn’t exist?'), $file); - - if ( ! function_exists('imagecreatefromstring') ) - return __('The GD image library is not installed.'); - - // Set artificially high because GD uses uncompressed images in memory - @ini_set( 'memory_limit', apply_filters( 'image_memory_limit', WP_MAX_MEMORY_LIMIT ) ); - $image = imagecreatefromstring( file_get_contents( $file ) ); - - if ( !is_resource( $image ) ) - return sprintf(__('File “%s” is not an image.'), $file); - - return $image; -} - /** * Calculates the new dimensions for a downsampled image. * @@ -320,7 +299,7 @@ function wp_constrain_dimensions( $current_width, $current_height, $max_width=0, } /** - * Retrieve calculated resized dimensions for use in imagecopyresampled(). + * Retrieve calculated resized dimensions for use in WP_Image_Editor. * * Calculate dimensions and coordinates for a resized image that fits within a * specified width and height. If $crop is true, the largest matching central @@ -392,92 +371,6 @@ function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = fal } -/** - * Scale down an image to fit a particular size and save a new copy of the image. - * - * The PNG transparency will be preserved using the function, as well as the - * image type. If the file going in is PNG, then the resized image is going to - * be PNG. The only supported image types are PNG, GIF, and JPEG. - * - * Some functionality requires API to exist, so some PHP version may lose out - * support. This is not the fault of WordPress (where functionality is - * downgraded, not actual defects), but of your PHP version. - * - * @since 2.5.0 - * - * @param string $file Image file path. - * @param int $max_w Maximum width to resize to. - * @param int $max_h Maximum height to resize to. - * @param bool $crop Optional. Whether to crop image or resize. - * @param string $suffix Optional. File suffix. - * @param string $dest_path Optional. New image file path. - * @param int $jpeg_quality Optional, default is 90. Image quality percentage. - * @return mixed WP_Error on failure. String with new destination path. - */ -function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) { - - $image = wp_load_image( $file ); - if ( !is_resource( $image ) ) - return new WP_Error( 'error_loading_image', $image, $file ); - - $size = @getimagesize( $file ); - if ( !$size ) - return new WP_Error('invalid_image', __('Could not read image size'), $file); - list($orig_w, $orig_h, $orig_type) = $size; - - $dims = image_resize_dimensions($orig_w, $orig_h, $max_w, $max_h, $crop); - if ( !$dims ) - return new WP_Error( 'error_getting_dimensions', __('Could not calculate resized image dimensions') ); - list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = $dims; - - $newimage = wp_imagecreatetruecolor( $dst_w, $dst_h ); - - imagecopyresampled( $newimage, $image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); - - // convert from full colors to index colors, like original PNG. - if ( IMAGETYPE_PNG == $orig_type && function_exists('imageistruecolor') && !imageistruecolor( $image ) ) - imagetruecolortopalette( $newimage, false, imagecolorstotal( $image ) ); - - // we don't need the original in memory anymore - imagedestroy( $image ); - - // $suffix will be appended to the destination filename, just before the extension - if ( !$suffix ) - $suffix = "{$dst_w}x{$dst_h}"; - - $info = pathinfo($file); - $dir = $info['dirname']; - $ext = $info['extension']; - $name = wp_basename($file, ".$ext"); - - if ( !is_null($dest_path) and $_dest_path = realpath($dest_path) ) - $dir = $_dest_path; - $destfilename = "{$dir}/{$name}-{$suffix}.{$ext}"; - - if ( IMAGETYPE_GIF == $orig_type ) { - if ( !imagegif( $newimage, $destfilename ) ) - return new WP_Error('resize_path_invalid', __( 'Resize path invalid' )); - } elseif ( IMAGETYPE_PNG == $orig_type ) { - if ( !imagepng( $newimage, $destfilename ) ) - return new WP_Error('resize_path_invalid', __( 'Resize path invalid' )); - } else { - // all other formats are converted to jpg - if ( 'jpg' != $ext && 'jpeg' != $ext ) - $destfilename = "{$dir}/{$name}-{$suffix}.jpg"; - if ( !imagejpeg( $newimage, $destfilename, apply_filters( 'jpeg_quality', $jpeg_quality, 'image_resize' ) ) ) - return new WP_Error('resize_path_invalid', __( 'Resize path invalid' )); - } - - imagedestroy( $newimage ); - - // Set correct file permissions - $stat = stat( dirname( $destfilename )); - $perms = $stat['mode'] & 0000666; //same permissions as parent folder, strip off the executable bits - @ chmod( $destfilename, $perms ); - - return $destfilename; -} - /** * Resize an image to make a thumbnail or intermediate size. * @@ -493,16 +386,18 @@ function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $de * @param bool $crop Optional, default is false. Whether to crop image to specified height and width or resize. * @return bool|array False, if no image was created. Metadata array on success. */ -function image_make_intermediate_size($file, $width, $height, $crop=false) { +function image_make_intermediate_size( $file, $width, $height, $crop = false ) { if ( $width || $height ) { - $resized_file = image_resize($file, $width, $height, $crop); - if ( !is_wp_error($resized_file) && $resized_file && $info = getimagesize($resized_file) ) { - $resized_file = apply_filters('image_make_intermediate_size', $resized_file); - return array( - 'file' => wp_basename( $resized_file ), - 'width' => $info[0], - 'height' => $info[1], - ); + $editor = wp_get_image_editor( $file ); + + if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) ) + return false; + + $resized_file = $editor->save(); + + if ( ! is_wp_error( $resized_file ) && $resized_file ) { + unset( $resized_file['path'] ); + return $resized_file; } } return false; @@ -655,12 +550,11 @@ function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = fa $hwstring = image_hwstring($width, $height); if ( is_array($size) ) $size = join('x', $size); - $attachment =& get_post($attachment_id); + $attachment = get_post($attachment_id); $default_attr = array( 'src' => $src, 'class' => "attachment-$size", 'alt' => trim(strip_tags( get_post_meta($attachment_id, '_wp_attachment_image_alt', true) )), // Use Alt field first - 'title' => trim(strip_tags( $attachment->post_title )), ); if ( empty($default_attr['alt']) ) $default_attr['alt'] = trim(strip_tags( $attachment->post_excerpt )); // If not, Use the Caption @@ -775,11 +669,18 @@ add_shortcode('gallery', 'gallery_shortcode'); * @return string HTML content to display gallery. */ function gallery_shortcode($attr) { - global $post; + $post = get_post(); static $instance = 0; $instance++; + if ( ! empty( $attr['ids'] ) ) { + // 'ids' is explicitly ordered, unless you specify otherwise. + if ( empty( $attr['orderby'] ) ) + $attr['orderby'] = 'post__in'; + $attr['include'] = $attr['ids']; + } + // Allow plugins/themes to override the default gallery template. $output = apply_filters('post_gallery', '', $attr); if ( $output != '' ) @@ -810,7 +711,6 @@ function gallery_shortcode($attr) { $orderby = 'none'; if ( !empty($include) ) { - $include = preg_replace( '/[^0-9,]+/', '', $include ); $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); $attachments = array(); @@ -818,7 +718,6 @@ function gallery_shortcode($attr) { $attachments[$val->ID] = $_attachments[$key]; } } elseif ( !empty($exclude) ) { - $exclude = preg_replace( '/[^0-9,]+/', '', $exclude ); $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); } else { $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); @@ -928,9 +827,8 @@ function next_image_link($size = 'thumbnail', $text = false) { * @param bool $prev Optional. Default is true to display previous link, false for next. */ function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false) { - global $post; - $post = get_post($post); - $attachments = array_values(get_children( array('post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') )); + $post = get_post(); + $attachments = array_values( get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) ) ); foreach ( $attachments as $k => $attachment ) if ( $attachment->ID == $post->ID ) @@ -938,8 +836,14 @@ function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false) { $k = $prev ? $k - 1 : $k + 1; - if ( isset($attachments[$k]) ) - echo wp_get_attachment_link($attachments[$k]->ID, $size, true, false, $text); + $output = $attachment_id = null; + if ( isset( $attachments[ $k ] ) ) { + $attachment_id = $attachments[ $k ]->ID; + $output = wp_get_attachment_link( $attachment_id, $size, true, false, $text ); + } + + $adjacent = $prev ? 'previous' : 'next'; + echo apply_filters( "{$adjacent}_image_link", $output, $attachment_id, $size, $text ); } /** @@ -982,38 +886,37 @@ function get_attachment_taxonomies($attachment) { } /** - * Check if the installed version of GD supports particular image type + * Return all of the taxonomy names that are registered for attachments. * - * @since 2.9.0 + * Handles mime-type-specific taxonomies such as attachment:image and attachment:video. + * + * @since 3.5.0 + * @see get_attachment_taxonomies() + * @uses get_taxonomies() * - * @param string $mime_type - * @return bool + * @param string $output The type of output to return, either taxonomy 'names' or 'objects'. 'names' is the default. + * @return array The names of all taxonomy of $object_type. */ -function gd_edit_image_support($mime_type) { - if ( function_exists('imagetypes') ) { - switch( $mime_type ) { - case 'image/jpeg': - return (imagetypes() & IMG_JPG) != 0; - case 'image/png': - return (imagetypes() & IMG_PNG) != 0; - case 'image/gif': - return (imagetypes() & IMG_GIF) != 0; - } - } else { - switch( $mime_type ) { - case 'image/jpeg': - return function_exists('imagecreatefromjpeg'); - case 'image/png': - return function_exists('imagecreatefrompng'); - case 'image/gif': - return function_exists('imagecreatefromgif'); +function get_taxonomies_for_attachments( $output = 'names' ) { + $taxonomies = array(); + foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy ) { + foreach ( $taxonomy->object_type as $object_type ) { + if ( 'attachment' == $object_type || 0 === strpos( $object_type, 'attachment:' ) ) { + if ( 'names' == $output ) + $taxonomies[] = $taxonomy->name; + else + $taxonomies[ $taxonomy->name ] = $taxonomy; + break; + } } } - return false; + + return $taxonomies; } /** * Create new GD image resource with transparency support + * @TODO: Deprecate if possible. * * @since 2.9.0 * @@ -1030,285 +933,6 @@ function wp_imagecreatetruecolor($width, $height) { return $img; } -/** - * API for easily embedding rich media such as videos and images into content. - * - * @package WordPress - * @subpackage Embed - * @since 2.9.0 - */ -class WP_Embed { - var $handlers = array(); - var $post_ID; - var $usecache = true; - var $linkifunknown = true; - - /** - * Constructor - */ - function __construct() { - // Hack to get the [embed] shortcode to run before wpautop() - add_filter( 'the_content', array(&$this, 'run_shortcode'), 8 ); - - // Shortcode placeholder for strip_shortcodes() - add_shortcode( 'embed', '__return_false' ); - - // Attempts to embed all URLs in a post - if ( get_option('embed_autourls') ) - add_filter( 'the_content', array(&$this, 'autoembed'), 8 ); - - // After a post is saved, invalidate the oEmbed cache - add_action( 'save_post', array(&$this, 'delete_oembed_caches') ); - - // After a post is saved, cache oEmbed items via AJAX - add_action( 'edit_form_advanced', array(&$this, 'maybe_run_ajax_cache') ); - } - - /** - * Process the [embed] shortcode. - * - * Since the [embed] shortcode needs to be run earlier than other shortcodes, - * this function removes all existing shortcodes, registers the [embed] shortcode, - * calls {@link do_shortcode()}, and then re-registers the old shortcodes. - * - * @uses $shortcode_tags - * @uses remove_all_shortcodes() - * @uses add_shortcode() - * @uses do_shortcode() - * - * @param string $content Content to parse - * @return string Content with shortcode parsed - */ - function run_shortcode( $content ) { - global $shortcode_tags; - - // Back up current registered shortcodes and clear them all out - $orig_shortcode_tags = $shortcode_tags; - remove_all_shortcodes(); - - add_shortcode( 'embed', array(&$this, 'shortcode') ); - - // Do the shortcode (only the [embed] one is registered) - $content = do_shortcode( $content ); - - // Put the original shortcodes back - $shortcode_tags = $orig_shortcode_tags; - - return $content; - } - - /** - * If a post/page was saved, then output JavaScript to make - * an AJAX request that will call WP_Embed::cache_oembed(). - */ - function maybe_run_ajax_cache() { - global $post_ID; - - if ( empty($post_ID) || empty($_GET['message']) || 1 != $_GET['message'] ) - return; - -?> - -handlers[$priority][$id] = array( - 'regex' => $regex, - 'callback' => $callback, - ); - } - - /** - * Unregister a previously registered embed handler. Do not use this function directly, use {@link wp_embed_unregister_handler()} instead. - * - * @param string $id The handler ID that should be removed. - * @param int $priority Optional. The priority of the handler to be removed (default: 10). - */ - function unregister_handler( $id, $priority = 10 ) { - if ( isset($this->handlers[$priority][$id]) ) - unset($this->handlers[$priority][$id]); - } - - /** - * The {@link do_shortcode()} callback function. - * - * Attempts to convert a URL into embed HTML. Starts by checking the URL against the regex of the registered embed handlers. - * If none of the regex matches and it's enabled, then the URL will be given to the {@link WP_oEmbed} class. - * - * @uses wp_oembed_get() - * @uses wp_parse_args() - * @uses wp_embed_defaults() - * @uses WP_Embed::maybe_make_link() - * @uses get_option() - * @uses current_user_can() - * @uses wp_cache_get() - * @uses wp_cache_set() - * @uses get_post_meta() - * @uses update_post_meta() - * - * @param array $attr Shortcode attributes. - * @param string $url The URL attempting to be embedded. - * @return string The embed HTML on success, otherwise the original URL. - */ - function shortcode( $attr, $url = '' ) { - global $post; - - if ( empty($url) ) - return ''; - - $rawattr = $attr; - $attr = wp_parse_args( $attr, wp_embed_defaults() ); - - // kses converts & into & and we need to undo this - // See http://core.trac.wordpress.org/ticket/11311 - $url = str_replace( '&', '&', $url ); - - // Look for known internal handlers - ksort( $this->handlers ); - foreach ( $this->handlers as $priority => $handlers ) { - foreach ( $handlers as $id => $handler ) { - if ( preg_match( $handler['regex'], $url, $matches ) && is_callable( $handler['callback'] ) ) { - if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) ) - return apply_filters( 'embed_handler_html', $return, $url, $attr ); - } - } - } - - $post_ID = ( !empty($post->ID) ) ? $post->ID : null; - if ( !empty($this->post_ID) ) // Potentially set by WP_Embed::cache_oembed() - $post_ID = $this->post_ID; - - // Unknown URL format. Let oEmbed have a go. - if ( $post_ID ) { - - // Check for a cached result (stored in the post meta) - $cachekey = '_oembed_' . md5( $url . serialize( $attr ) ); - if ( $this->usecache ) { - $cache = get_post_meta( $post_ID, $cachekey, true ); - - // Failures are cached - if ( '{{unknown}}' === $cache ) - return $this->maybe_make_link( $url ); - - if ( !empty($cache) ) - return apply_filters( 'embed_oembed_html', $cache, $url, $attr, $post_ID ); - } - - // Use oEmbed to get the HTML - $attr['discover'] = ( apply_filters('embed_oembed_discover', false) && author_can( $post_ID, 'unfiltered_html' ) ); - $html = wp_oembed_get( $url, $attr ); - - // Cache the result - $cache = ( $html ) ? $html : '{{unknown}}'; - update_post_meta( $post_ID, $cachekey, $cache ); - - // If there was a result, return it - if ( $html ) - return apply_filters( 'embed_oembed_html', $html, $url, $attr, $post_ID ); - } - - // Still unknown - return $this->maybe_make_link( $url ); - } - - /** - * Delete all oEmbed caches. - * - * @param int $post_ID Post ID to delete the caches for. - */ - function delete_oembed_caches( $post_ID ) { - $post_metas = get_post_custom_keys( $post_ID ); - if ( empty($post_metas) ) - return; - - foreach( $post_metas as $post_meta_key ) { - if ( '_oembed_' == substr( $post_meta_key, 0, 8 ) ) - delete_post_meta( $post_ID, $post_meta_key ); - } - } - - /** - * Triggers a caching of all oEmbed results. - * - * @param int $post_ID Post ID to do the caching for. - */ - function cache_oembed( $post_ID ) { - $post = get_post( $post_ID ); - - if ( empty($post->ID) || !in_array( $post->post_type, apply_filters( 'embed_cache_oembed_types', array( 'post', 'page' ) ) ) ) - return; - - // Trigger a caching - if ( !empty($post->post_content) ) { - $this->post_ID = $post->ID; - $this->usecache = false; - - $content = $this->run_shortcode( $post->post_content ); - if ( get_option('embed_autourls') ) - $this->autoembed( $content ); - - $this->usecache = true; - } - } - - /** - * Passes any unlinked URLs that are on their own line to {@link WP_Embed::shortcode()} for potential embedding. - * - * @uses WP_Embed::autoembed_callback() - * - * @param string $content The content to be searched. - * @return string Potentially modified $content. - */ - function autoembed( $content ) { - return preg_replace_callback( '|^\s*(https?://[^\s"]+)\s*$|im', array(&$this, 'autoembed_callback'), $content ); - } - - /** - * Callback function for {@link WP_Embed::autoembed()}. - * - * @uses WP_Embed::shortcode() - * - * @param array $match A regex match array. - * @return string The embed HTML on success, otherwise the original URL. - */ - function autoembed_callback( $match ) { - $oldval = $this->linkifunknown; - $this->linkifunknown = false; - $return = $this->shortcode( array(), $match[1] ); - $this->linkifunknown = $oldval; - - return "\n$return\n"; - } - - /** - * Conditionally makes a hyperlink based on an internal class variable. - * - * @param string $url URL to potentially be linked. - * @return string Linked URL or the original URL. - */ - function maybe_make_link( $url ) { - $output = ( $this->linkifunknown ) ? '' . esc_html($url) . '' : $url; - return apply_filters( 'embed_maybe_make_link', $output, $url ); - } -} -$GLOBALS['wp_embed'] = new WP_Embed(); - /** * Register an embed handler. This function should probably only be used for sites that do not support oEmbed. * @@ -1334,31 +958,27 @@ function wp_embed_unregister_handler( $id, $priority = 10 ) { /** * Create default array of embed parameters. * + * The width defaults to the content width as specified by the theme. If the + * theme does not specify a content width, then 500px is used. + * + * The default height is 1.5 times the width, or 1000px, whichever is smaller. + * + * The 'embed_defaults' filter can be used to adjust either of these values. + * * @since 2.9.0 * * @return array Default embed parameters. */ function wp_embed_defaults() { - if ( !empty($GLOBALS['content_width']) ) - $theme_width = (int) $GLOBALS['content_width']; - - $width = get_option('embed_size_w'); + if ( ! empty( $GLOBALS['content_width'] ) ) + $width = (int) $GLOBALS['content_width']; - if ( empty($width) && !empty($theme_width) ) - $width = $theme_width; - - if ( empty($width) ) + if ( empty( $width ) ) $width = 500; - $height = get_option('embed_size_h'); - - if ( empty($height) ) - $height = 700; + $height = min( ceil( $width * 1.5 ), 1000 ); - return apply_filters( 'embed_defaults', array( - 'width' => $width, - 'height' => $height, - ) ); + return apply_filters( 'embed_defaults', compact( 'width', 'height' ) ); } /** @@ -1419,6 +1039,29 @@ function wp_oembed_add_provider( $format, $provider, $regex = false ) { $oembed->providers[$format] = array( $provider, $regex ); } +/** + * Removes an oEmbed provider. + * + * @since 3.5 + * @see WP_oEmbed + * + * @uses _wp_oembed_get_object() + * + * @param string $format The URL format for the oEmbed provider to remove. + */ +function wp_oembed_remove_provider( $format ) { + require_once( ABSPATH . WPINC . '/class-oembed.php' ); + + $oembed = _wp_oembed_get_object(); + + if ( isset( $oembed->providers[ $format ] ) ) { + unset( $oembed->providers[ $format ] ); + return true; + } + + return false; +} + /** * Determines if default embed handlers should be loaded. * @@ -1457,6 +1100,145 @@ function wp_embed_handler_googlevideo( $matches, $attr, $url, $rawattr ) { return apply_filters( 'embed_googlevideo', '', $matches, $attr, $url, $rawattr ); } +/** + * {@internal Missing Short Description}} + * + * @since 2.3.0 + * + * @param unknown_type $size + * @return unknown + */ +function wp_convert_hr_to_bytes( $size ) { + $size = strtolower( $size ); + $bytes = (int) $size; + if ( strpos( $size, 'k' ) !== false ) + $bytes = intval( $size ) * 1024; + elseif ( strpos( $size, 'm' ) !== false ) + $bytes = intval($size) * 1024 * 1024; + elseif ( strpos( $size, 'g' ) !== false ) + $bytes = intval( $size ) * 1024 * 1024 * 1024; + return $bytes; +} + +/** + * {@internal Missing Short Description}} + * + * @since 2.3.0 + * + * @param unknown_type $bytes + * @return unknown + */ +function wp_convert_bytes_to_hr( $bytes ) { + $units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB' ); + $log = log( $bytes, 1024 ); + $power = (int) $log; + $size = pow( 1024, $log - $power ); + return $size . $units[$power]; +} + +/** + * {@internal Missing Short Description}} + * + * @since 2.5.0 + * + * @return unknown + */ +function wp_max_upload_size() { + $u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) ); + $p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) ); + $bytes = apply_filters( 'upload_size_limit', min( $u_bytes, $p_bytes ), $u_bytes, $p_bytes ); + return $bytes; +} + +/** + * Returns a WP_Image_Editor instance and loads file into it. + * + * @since 3.5.0 + * @access public + * + * @param string $path Path to file to load + * @param array $args Additional data. Accepts { 'mime_type'=>string, 'methods'=>{string, string, ...} } + * @return WP_Image_Editor|WP_Error + */ +function wp_get_image_editor( $path, $args = array() ) { + $args['path'] = $path; + + if ( ! isset( $args['mime_type'] ) ) { + $file_info = wp_check_filetype( $args['path'] ); + + // If $file_info['type'] is false, then we let the editor attempt to + // figure out the file type, rather than forcing a failure based on extension. + if ( isset( $file_info ) && $file_info['type'] ) + $args['mime_type'] = $file_info['type']; + } + + $implementation = _wp_image_editor_choose( $args ); + + if ( $implementation ) { + $editor = new $implementation( $path ); + $loaded = $editor->load(); + + if ( is_wp_error( $loaded ) ) + return $loaded; + + return $editor; + } + + return new WP_Error( 'image_no_editor', __('No editor could be selected.') ); +} + +/** + * Tests whether there is an editor that supports a given mime type or methods. + * + * @since 3.5.0 + * @access public + * + * @param string|array $args Array of requirements. Accepts { 'mime_type'=>string, 'methods'=>{string, string, ...} } + * @return boolean true if an eligible editor is found; false otherwise + */ +function wp_image_editor_supports( $args = array() ) { + return (bool) _wp_image_editor_choose( $args ); +} + +/** + * Tests which editors are capable of supporting the request. + * + * @since 3.5.0 + * @access private + * + * @param array $args Additional data. Accepts { 'mime_type'=>string, 'methods'=>{string, string, ...} } + * @return string|bool Class name for the first editor that claims to support the request. False if no editor claims to support the request. + */ +function _wp_image_editor_choose( $args = array() ) { + require_once ABSPATH . WPINC . '/class-wp-image-editor.php'; + require_once ABSPATH . WPINC . '/class-wp-image-editor-gd.php'; + require_once ABSPATH . WPINC . '/class-wp-image-editor-imagick.php'; + + $implementations = apply_filters( 'wp_image_editors', + array( 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD' ) ); + + foreach ( $implementations as $implementation ) { + if ( ! call_user_func( array( $implementation, 'test' ), $args ) ) + continue; + + if ( isset( $args['mime_type'] ) && + ! call_user_func( + array( $implementation, 'supports_mime_type' ), + $args['mime_type'] ) ) { + continue; + } + + if ( isset( $args['methods'] ) && + array_diff( $args['methods'], get_class_methods( $implementation ) ) ) { + continue; + } + + return $implementation; + } + + return false; +} + /** * Prints default plupload arguments. * @@ -1465,6 +1247,10 @@ function wp_embed_handler_googlevideo( $matches, $attr, $url, $rawattr ) { function wp_plupload_default_settings() { global $wp_scripts; + $data = $wp_scripts->get_data( 'wp-plupload', 'data' ); + if ( $data && false !== strpos( $data, '_wpPluploadSettings' ) ) + return; + $max_upload_size = wp_max_upload_size(); $defaults = array( @@ -1472,7 +1258,7 @@ function wp_plupload_default_settings() { 'file_data_name' => 'async-upload', // key passed to $_FILE. 'multiple_queues' => true, 'max_file_size' => $max_upload_size . 'b', - 'url' => admin_url( 'admin-ajax.php', 'relative' ), + 'url' => admin_url( 'async-upload.php', 'relative' ), 'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ), 'silverlight_xap_url' => includes_url( 'js/plupload/plupload.silverlight.xap' ), 'filters' => array( array( 'title' => __( 'Allowed Files' ), 'extensions' => '*') ), @@ -1480,6 +1266,11 @@ function wp_plupload_default_settings() { 'urlstream_upload' => true, ); + // Multi-file uploading doesn't currently work in iOS Safari, + // single-file allows the built-in camera to be used as source for images + if ( wp_is_mobile() ) + $defaults['multi_selection'] = false; + $defaults = apply_filters( 'plupload_default_settings', $defaults ); $params = array( @@ -1496,14 +1287,258 @@ function wp_plupload_default_settings() { 'mobile' => wp_is_mobile(), 'supported' => _device_can_upload(), ), + 'limitExceeded' => is_multisite() && ! is_upload_space_available() ); $script = 'var _wpPluploadSettings = ' . json_encode( $settings ) . ';'; - $data = $wp_scripts->get_data( 'wp-plupload', 'data' ); if ( $data ) $script = "$data\n$script"; $wp_scripts->add_data( 'wp-plupload', 'data', $script ); } add_action( 'customize_controls_enqueue_scripts', 'wp_plupload_default_settings' ); + +/** + * Prepares an attachment post object for JS, where it is expected + * to be JSON-encoded and fit into an Attachment model. + * + * @since 3.5.0 + * + * @param mixed $attachment Attachment ID or object. + * @return array Array of attachment details. + */ +function wp_prepare_attachment_for_js( $attachment ) { + if ( ! $attachment = get_post( $attachment ) ) + return; + + if ( 'attachment' != $attachment->post_type ) + return; + + $meta = wp_get_attachment_metadata( $attachment->ID ); + if ( false !== strpos( $attachment->post_mime_type, '/' ) ) + list( $type, $subtype ) = explode( '/', $attachment->post_mime_type ); + else + list( $type, $subtype ) = array( $attachment->post_mime_type, '' ); + + $attachment_url = wp_get_attachment_url( $attachment->ID ); + + $response = array( + 'id' => $attachment->ID, + 'title' => $attachment->post_title, + 'filename' => basename( $attachment->guid ), + 'url' => $attachment_url, + 'link' => get_attachment_link( $attachment->ID ), + 'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ), + 'author' => $attachment->post_author, + 'description' => $attachment->post_content, + 'caption' => $attachment->post_excerpt, + 'name' => $attachment->post_name, + 'status' => $attachment->post_status, + 'uploadedTo' => $attachment->post_parent, + 'date' => strtotime( $attachment->post_date_gmt ) * 1000, + 'modified' => strtotime( $attachment->post_modified_gmt ) * 1000, + 'menuOrder' => $attachment->menu_order, + 'mime' => $attachment->post_mime_type, + 'type' => $type, + 'subtype' => $subtype, + 'icon' => wp_mime_type_icon( $attachment->ID ), + 'dateFormatted' => mysql2date( get_option('date_format'), $attachment->post_date ), + 'nonces' => array( + 'update' => false, + 'delete' => false, + ), + 'editLink' => false, + ); + + if ( current_user_can( 'edit_post', $attachment->ID ) ) { + $response['nonces']['update'] = wp_create_nonce( 'update-post_' . $attachment->ID ); + $response['editLink'] = get_edit_post_link( $attachment->ID, 'raw' ); + } + + if ( current_user_can( 'delete_post', $attachment->ID ) ) + $response['nonces']['delete'] = wp_create_nonce( 'delete-post_' . $attachment->ID ); + + if ( $meta && 'image' === $type ) { + $sizes = array(); + $possible_sizes = apply_filters( 'image_size_names_choose', array( + 'thumbnail' => __('Thumbnail'), + 'medium' => __('Medium'), + 'large' => __('Large'), + 'full' => __('Full Size'), + ) ); + unset( $possible_sizes['full'] ); + + // Loop through all potential sizes that may be chosen. Try to do this with some efficiency. + // First: run the image_downsize filter. If it returns something, we can use its data. + // If the filter does not return something, then image_downsize() is just an expensive + // way to check the image metadata, which we do second. + foreach ( $possible_sizes as $size => $label ) { + if ( $downsize = apply_filters( 'image_downsize', false, $attachment->ID, $size ) ) { + if ( ! $downsize[3] ) + continue; + $sizes[ $size ] = array( + 'height' => $downsize[2], + 'width' => $downsize[1], + 'url' => $downsize[0], + 'orientation' => $downsize[2] > $downsize[1] ? 'portrait' : 'landscape', + ); + } elseif ( isset( $meta['sizes'][ $size ] ) ) { + if ( ! isset( $base_url ) ) + $base_url = str_replace( wp_basename( $attachment_url ), '', $attachment_url ); + + // Nothing from the filter, so consult image metadata if we have it. + $size_meta = $meta['sizes'][ $size ]; + + // We have the actual image size, but might need to further constrain it if content_width is narrower. + // This is not necessary for thumbnails and medium size. + if ( 'thumbnail' == $size || 'medium' == $size ) { + $width = $size_meta['width']; + $height = $size_meta['height']; + } else { + list( $width, $height ) = image_constrain_size_for_editor( $size_meta['width'], $size_meta['height'], $size, 'edit' ); + } + + $sizes[ $size ] = array( + 'height' => $height, + 'width' => $width, + 'url' => $base_url . $size_meta['file'], + 'orientation' => $height > $width ? 'portrait' : 'landscape', + ); + } + } + + $sizes['full'] = array( + 'height' => $meta['height'], + 'width' => $meta['width'], + 'url' => $attachment_url, + 'orientation' => $meta['height'] > $meta['width'] ? 'portrait' : 'landscape', + ); + + $response = array_merge( $response, array( 'sizes' => $sizes ), $sizes['full'] ); + } + + if ( function_exists('get_compat_media_markup') ) + $response['compat'] = get_compat_media_markup( $attachment->ID, array( 'in_modal' => true ) ); + + return apply_filters( 'wp_prepare_attachment_for_js', $response, $attachment, $meta ); +} + +/** + * Enqueues all scripts, styles, settings, and templates necessary to use + * all media JS APIs. + * + * @since 3.5.0 + */ +function wp_enqueue_media( $args = array() ) { + $defaults = array( + 'post' => null, + ); + $args = wp_parse_args( $args, $defaults ); + + // We're going to pass the old thickbox media tabs to `media_upload_tabs` + // to ensure plugins will work. We will then unset those tabs. + $tabs = array( + // handler action suffix => tab label + 'type' => '', + 'type_url' => '', + 'gallery' => '', + 'library' => '', + ); + + $tabs = apply_filters( 'media_upload_tabs', $tabs ); + unset( $tabs['type'], $tabs['type_url'], $tabs['gallery'], $tabs['library'] ); + + $settings = array( + 'tabs' => $tabs, + 'tabUrl' => add_query_arg( array( 'chromeless' => true ), admin_url('media-upload.php') ), + 'mimeTypes' => wp_list_pluck( get_post_mime_types(), 0 ), + 'captions' => ! apply_filters( 'disable_captions', '' ), + 'nonce' => array( + 'sendToEditor' => wp_create_nonce( 'media-send-to-editor' ), + ), + 'post' => array( + 'id' => 0, + ), + ); + + $post = null; + if ( isset( $args['post'] ) ) { + $post = get_post( $args['post'] ); + $settings['post'] = array( + 'id' => $post->ID, + 'nonce' => wp_create_nonce( 'update-post_' . $post->ID ), + ); + + if ( current_theme_supports( 'post-thumbnails', $post->post_type ) && post_type_supports( $post->post_type, 'thumbnail' ) ) { + $featured_image_id = get_post_meta( $post->ID, '_thumbnail_id', true ); + $settings['post']['featuredImageId'] = $featured_image_id ? $featured_image_id : -1; + } + } + + $hier = $post && is_post_type_hierarchical( $post->post_type ); + + $strings = array( + // Generic + 'url' => __( 'URL' ), + 'addMedia' => __( 'Add Media' ), + 'search' => __( 'Search' ), + 'select' => __( 'Select' ), + 'cancel' => __( 'Cancel' ), + /* translators: This is a would-be plural string used in the media manager. + If there is not a word you can use in your language to avoid issues with the + lack of plural support here, turn it into "selected: %d" then translate it. + */ + 'selected' => __( '%d selected' ), + 'dragInfo' => __( 'Drag and drop to reorder images.' ), + + // Upload + 'uploadFilesTitle' => __( 'Upload Files' ), + 'uploadImagesTitle' => __( 'Upload Images' ), + + // Library + 'mediaLibraryTitle' => __( 'Media Library' ), + 'insertMediaTitle' => __( 'Insert Media' ), + 'createNewGallery' => __( 'Create a new gallery' ), + 'returnToLibrary' => __( '← Return to library' ), + 'allMediaItems' => __( 'All media items' ), + 'noItemsFound' => __( 'No items found.' ), + 'insertIntoPost' => $hier ? __( 'Insert into page' ) : __( 'Insert into post' ), + 'uploadedToThisPost' => $hier ? __( 'Uploaded to this page' ) : __( 'Uploaded to this post' ), + 'warnDelete' => __( "You are about to permanently delete this item.\n 'Cancel' to stop, 'OK' to delete." ), + + // From URL + 'insertFromUrlTitle' => __( 'Insert from URL' ), + + // Featured Images + 'setFeaturedImageTitle' => __( 'Set Featured Image' ), + 'setFeaturedImage' => __( 'Set featured image' ), + + // Gallery + 'createGalleryTitle' => __( 'Create Gallery' ), + 'editGalleryTitle' => __( 'Edit Gallery' ), + 'cancelGalleryTitle' => __( '← Cancel Gallery' ), + 'insertGallery' => __( 'Insert gallery' ), + 'updateGallery' => __( 'Update gallery' ), + 'addToGallery' => __( 'Add to gallery' ), + 'addToGalleryTitle' => __( 'Add to Gallery' ), + 'reverseOrder' => __( 'Reverse order' ), + ); + + $settings = apply_filters( 'media_view_settings', $settings, $post ); + $strings = apply_filters( 'media_view_strings', $strings, $post ); + + $strings['settings'] = $settings; + + wp_localize_script( 'media-views', '_wpMediaViewsL10n', $strings ); + + wp_enqueue_script( 'media-editor' ); + wp_enqueue_style( 'media-views' ); + wp_plupload_default_settings(); + + require_once ABSPATH . WPINC . '/media-template.php'; + add_action( 'admin_footer', 'wp_print_media_templates' ); + add_action( 'wp_footer', 'wp_print_media_templates' ); + + do_action( 'wp_enqueue_media' ); +} diff --git a/wp-includes/meta.php b/wp-includes/meta.php index d6984f62..9db1de30 100644 --- a/wp-includes/meta.php +++ b/wp-includes/meta.php @@ -123,9 +123,6 @@ function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_v if ( null !== $check ) return (bool) $check; - if ( ! $meta_id = $wpdb->get_var( $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s AND $column = %d", $meta_key, $object_id ) ) ) - return add_metadata($meta_type, $object_id, $meta_key, $passed_value); - // Compare existing value to new value if no prev value given and the key exists only once. if ( empty($prev_value) ) { $old_value = get_metadata($meta_type, $object_id, $meta_key); @@ -135,6 +132,9 @@ function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_v } } + if ( ! $meta_id = $wpdb->get_var( $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s AND $column = %d", $meta_key, $object_id ) ) ) + return add_metadata($meta_type, $object_id, $meta_key, $passed_value); + $_meta_value = $meta_value; $meta_value = maybe_serialize( $meta_value ); @@ -711,7 +711,30 @@ class WP_Meta_Query { $join = array(); $where = array(); - foreach ( $this->queries as $k => $q ) { + $key_only_queries = array(); + $queries = array(); + + // Split out the meta_key only queries (we can only do this for OR) + if ( 'OR' == $this->relation ) { + foreach ( $this->queries as $k => $q ) { + if ( ! isset( $q['value'] ) && ! empty( $q['key'] ) ) + $key_only_queries[$k] = $q; + else + $queries[$k] = $q; + } + } else { + $queries = $this->queries; + } + + // Specify all the meta_key only queries in one go + if ( $key_only_queries ) { + $join[] = "INNER JOIN $meta_table ON $primary_table.$primary_id_column = $meta_table.$meta_id_column"; + + foreach ( $key_only_queries as $key => $q ) + $where["key-only-$key"] = $wpdb->prepare( "$meta_table.meta_key = %s", trim( $q['key'] ) ); + } + + foreach ( $queries as $k => $q ) { $meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : ''; $meta_type = isset( $q['type'] ) ? strtoupper( $q['type'] ) : 'CHAR'; @@ -720,10 +743,35 @@ class WP_Meta_Query { elseif ( ! in_array( $meta_type, array( 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED' ) ) ) $meta_type = 'CHAR'; + $meta_value = isset( $q['value'] ) ? $q['value'] : null; + + if ( isset( $q['compare'] ) ) + $meta_compare = strtoupper( $q['compare'] ); + else + $meta_compare = is_array( $meta_value ) ? 'IN' : '='; + + if ( ! in_array( $meta_compare, array( + '=', '!=', '>', '>=', '<', '<=', + 'LIKE', 'NOT LIKE', + 'IN', 'NOT IN', + 'BETWEEN', 'NOT BETWEEN', + 'NOT EXISTS' + ) ) ) + $meta_compare = '='; + $i = count( $join ); $alias = $i ? 'mt' . $i : $meta_table; - // Set JOIN + if ( 'NOT EXISTS' == $meta_compare ) { + $join[$i] = "LEFT JOIN $meta_table"; + $join[$i] .= $i ? " AS $alias" : ''; + $join[$i] .= " ON ($primary_table.$primary_id_column = $alias.$meta_id_column AND $alias.meta_key = '$meta_key')"; + + $where[$k] = ' ' . $alias . '.' . $meta_id_column . ' IS NULL'; + + continue; + } + $join[$i] = "INNER JOIN $meta_table"; $join[$i] .= $i ? " AS $alias" : ''; $join[$i] .= " ON ($primary_table.$primary_id_column = $alias.$meta_id_column)"; @@ -732,21 +780,12 @@ class WP_Meta_Query { if ( !empty( $meta_key ) ) $where[$k] = $wpdb->prepare( "$alias.meta_key = %s", $meta_key ); - if ( !isset( $q['value'] ) ) { + if ( is_null( $meta_value ) ) { if ( empty( $where[$k] ) ) unset( $join[$i] ); continue; } - $meta_value = $q['value']; - - $meta_compare = is_array( $meta_value ) ? 'IN' : '='; - if ( isset( $q['compare'] ) ) - $meta_compare = strtoupper( $q['compare'] ); - - if ( ! in_array( $meta_compare, array( '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) - $meta_compare = '='; - if ( in_array( $meta_compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) { if ( ! is_array( $meta_value ) ) $meta_value = preg_split( '/[,\s]+/', $meta_value ); diff --git a/wp-includes/ms-blogs.php b/wp-includes/ms-blogs.php index 8f66aadd..a1f70a40 100644 --- a/wp-includes/ms-blogs.php +++ b/wp-includes/ms-blogs.php @@ -84,28 +84,32 @@ function get_blogaddress_by_domain( $domain, $path ) { } /** - * Given a blog's (subdomain or directory) name, retrieve it's id. + * Given a blog's (subdomain or directory) slug, retrieve it's id. * * @since MU * - * @param string $name + * @param string $slug * @return int A blog id */ -function get_id_from_blogname( $name ) { +function get_id_from_blogname( $slug ) { global $wpdb, $current_site; - $blog_id = wp_cache_get( 'get_id_from_blogname_' . $name, 'blog-details' ); + + $slug = trim( $slug, '/' ); + + $blog_id = wp_cache_get( 'get_id_from_blogname_' . $slug, 'blog-details' ); if ( $blog_id ) return $blog_id; if ( is_subdomain_install() ) { - $domain = $name . '.' . $current_site->domain; + $domain = $slug . '.' . $current_site->domain; $path = $current_site->path; } else { $domain = $current_site->domain; - $path = $current_site->path . $name . '/'; + $path = $current_site->path . $slug . '/'; } + $blog_id = $wpdb->get_var( $wpdb->prepare("SELECT blog_id FROM {$wpdb->blogs} WHERE domain = %s AND path = %s", $domain, $path) ); - wp_cache_set( 'get_id_from_blogname_' . $name, $blog_id, 'blog-details' ); + wp_cache_set( 'get_id_from_blogname_' . $slug, $blog_id, 'blog-details' ); return $blog_id; } @@ -114,11 +118,11 @@ function get_id_from_blogname( $name ) { * * @since MU * - * @param int|string|array $fields A blog ID, a blog name, or an array of fields to query against. + * @param int|string|array $fields A blog ID, a blog slug, or an array of fields to query against. Optional. If not specified the current blog ID is used. * @param bool $get_all Whether to retrieve all details or only the details in the blogs table. Default is true. * @return object Blog details. */ -function get_blog_details( $fields, $get_all = true ) { +function get_blog_details( $fields = null, $get_all = true ) { global $wpdb; if ( is_array($fields ) ) { @@ -162,7 +166,9 @@ function get_blog_details( $fields, $get_all = true ) { return false; } } else { - if ( !is_numeric( $fields ) ) + if ( ! $fields ) + $blog_id = get_current_blog_id(); + elseif ( ! is_numeric( $fields ) ) $blog_id = get_id_from_blogname( $fields ); else $blog_id = $fields; @@ -222,9 +228,11 @@ function get_blog_details( $fields, $get_all = true ) { return $details; } - $details->blogname = get_blog_option( $blog_id, 'blogname' ); - $details->siteurl = get_blog_option( $blog_id, 'siteurl' ); - $details->post_count = get_blog_option( $blog_id, 'post_count' ); + switch_to_blog( $blog_id ); + $details->blogname = get_option( 'blogname' ); + $details->siteurl = get_option( 'siteurl' ); + $details->post_count = get_option( 'post_count' ); + restore_current_blog(); $details = apply_filters( 'blog_details', $details ); @@ -247,11 +255,7 @@ function refresh_blog_details( $blog_id ) { $blog_id = (int) $blog_id; $details = get_blog_details( $blog_id, false ); - wp_cache_delete( $blog_id , 'blog-details' ); - wp_cache_delete( $blog_id . 'short' , 'blog-details' ); - wp_cache_delete( md5( $details->domain . $details->path ) , 'blog-lookup' ); - wp_cache_delete( 'current_blog_' . $details->domain, 'site-options' ); - wp_cache_delete( 'current_blog_' . $details->domain . $details->path, 'site-options' ); + clean_blog_cache( $details ); do_action( 'refresh_blog_details', $blog_id ); } @@ -288,18 +292,48 @@ function update_blog_details( $blog_id, $details = array() ) { foreach ( array_intersect( array_keys( $details ), $fields ) as $field ) $update_details[$field] = $details[$field]; - $wpdb->update( $wpdb->blogs, $update_details, array('blog_id' => $blog_id) ); + $result = $wpdb->update( $wpdb->blogs, $update_details, array('blog_id' => $blog_id) ); + + if ( false === $result ) + return false; // If spam status changed, issue actions. if ( $details[ 'spam' ] != $current_details[ 'spam' ] ) { if ( $details[ 'spam' ] == 1 ) - do_action( "make_spam_blog", $blog_id ); + do_action( 'make_spam_blog', $blog_id ); else - do_action( "make_ham_blog", $blog_id ); + do_action( 'make_ham_blog', $blog_id ); } - if ( isset($details[ 'public' ]) ) - update_blog_option( $blog_id, 'blog_public', $details[ 'public' ] ); + // If mature status changed, issue actions. + if ( $details[ 'mature' ] != $current_details[ 'mature' ] ) { + if ( $details[ 'mature' ] == 1 ) + do_action( 'mature_blog', $blog_id ); + else + do_action( 'unmature_blog', $blog_id ); + } + + // If archived status changed, issue actions. + if ( $details[ 'archived' ] != $current_details[ 'archived' ] ) { + if ( $details[ 'archived' ] == 1 ) + do_action( 'archive_blog', $blog_id ); + else + do_action( 'unarchive_blog', $blog_id ); + } + + // If deleted status changed, issue actions. + if ( $details[ 'deleted' ] != $current_details[ 'deleted' ] ) { + if ( $details[ 'deleted' ] == 1 ) + do_action( 'make_delete_blog', $blog_id ); + else + do_action( 'make_undelete_blog', $blog_id ); + } + + if ( isset( $details[ 'public' ] ) ) { + switch_to_blog( $blog_id ); + update_option( 'blog_public', $details[ 'public' ] ); + restore_current_blog(); + } refresh_blog_details($blog_id); @@ -307,114 +341,115 @@ function update_blog_details( $blog_id, $details = array() ) { } /** - * Retrieve option value based on setting name and blog_id. + * Clean the blog cache + * + * @since 3.5.0 + * + * @param stdClass $blog The blog details as returned from get_blog_details() + */ +function clean_blog_cache( $blog ) { + $blog_id = $blog->blog_id; + $domain_path_key = md5( $blog->domain . $blog->path ); + + wp_cache_delete( $blog_id , 'blog-details' ); + wp_cache_delete( $blog_id . 'short' , 'blog-details' ); + wp_cache_delete( $domain_path_key, 'blog-lookup' ); + wp_cache_delete( 'current_blog_' . $blog->domain, 'site-options' ); + wp_cache_delete( 'current_blog_' . $blog->domain . $blog->path, 'site-options' ); + wp_cache_delete( 'get_id_from_blogname_' . trim( $blog->path, '/' ), 'blog-details' ); + wp_cache_delete( $domain_path_key, 'blog-id-cache' ); +} + +/** + * Retrieve option value for a given blog id based on name of option. * * If the option does not exist or does not have a value, then the return value * will be false. This is useful to check whether you need to install an option * and is commonly used during installation of plugin options and to test * whether upgrading is required. * - * There is a filter called 'blog_option_$option' with the $option being - * replaced with the option name. The filter takes two parameters. $value and - * $blog_id. It returns $value. - * The 'option_$option' filter in get_option() is not called. + * If the option was serialized then it will be unserialized when it is returned. * * @since MU - * @uses apply_filters() Calls 'blog_option_$optionname' with the option name value. * - * @param int $blog_id Optional. Blog ID, can be null to refer to the current blog. - * @param string $setting Name of option to retrieve. Should already be SQL-escaped. - * @param string $default (optional) Default value returned if option not found. + * @param int $id A blog ID. Can be null to refer to the current blog. + * @param string $option Name of option to retrieve. Expected to not be SQL-escaped. + * @param mixed $default Optional. Default value to return if the option does not exist. * @return mixed Value set for the option. */ -function get_blog_option( $blog_id, $setting, $default = false ) { - global $wpdb; +function get_blog_option( $id, $option, $default = false ) { + $id = (int) $id; - if ( null === $blog_id ) - $blog_id = $wpdb->blogid; - - $key = $blog_id . '-' . $setting . '-blog_option'; - $value = wp_cache_get( $key, 'site-options' ); - if ( $value == null ) { - if ( $blog_id == $wpdb->blogid ) { - $value = get_option( $setting, $default ); - $notoptions = wp_cache_get( 'notoptions', 'options' ); - if ( isset( $notoptions[$setting] ) ) { - wp_cache_set( $key, 'noop', 'site-options' ); - $value = $default; - } elseif ( $value == false ) { - wp_cache_set( $key, 'falsevalue', 'site-options' ); - } else { - wp_cache_set( $key, $value, 'site-options' ); - } - return apply_filters( 'blog_option_' . $setting, $value, $blog_id ); - } else { - $blog_prefix = $wpdb->get_blog_prefix( $blog_id ); - $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$blog_prefix}options WHERE option_name = %s", $setting ) ); - if ( is_object( $row ) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values - $value = $row->option_value; - if ( $value == false ) - wp_cache_set( $key, 'falsevalue', 'site-options' ); - else - wp_cache_set( $key, $value, 'site-options' ); - } else { // option does not exist, so we must cache its non-existence - wp_cache_set( $key, 'noop', 'site-options' ); - $value = $default; - } - } - } elseif ( $value == 'noop' ) { - $value = $default; - } elseif ( $value == 'falsevalue' ) { - $value = false; - } - // If home is not set use siteurl. - if ( 'home' == $setting && '' == $value ) - return get_blog_option( $blog_id, 'siteurl' ); + if ( empty( $id ) ) + $id = get_current_blog_id(); - if ( 'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting ) - $value = untrailingslashit( $value ); + if ( get_current_blog_id() == $id ) + return get_option( $option, $default ); + + switch_to_blog( $id ); + $value = get_option( $option, $default ); + restore_current_blog(); - return apply_filters( 'blog_option_' . $setting, maybe_unserialize( $value ), $blog_id ); + return apply_filters( 'blog_option_' . $option, $value, $id ); } /** - * Add an option for a particular blog. + * Add a new option for a given blog id. + * + * You do not need to serialize values. If the value needs to be serialized, then + * it will be serialized before it is inserted into the database. Remember, + * resources can not be serialized or added as an option. + * + * You can create options without values and then update the values later. + * Existing options will not be updated and checks are performed to ensure that you + * aren't adding a protected WordPress option. Care should be taken to not name + * options the same as the ones which are protected. * * @since MU * - * @param int $id The blog id - * @param string $key The option key - * @param mixed $value The option value - * @return bool True on success, false on failure. + * @param int $id A blog ID. Can be null to refer to the current blog. + * @param string $option Name of option to add. Expected to not be SQL-escaped. + * @param mixed $value Optional. Option value, can be anything. Expected to not be SQL-escaped. + * @return bool False if option was not added and true if option was added. */ -function add_blog_option( $id, $key, $value ) { +function add_blog_option( $id, $option, $value ) { $id = (int) $id; - switch_to_blog($id); - $return = add_option( $key, $value ); + if ( empty( $id ) ) + $id = get_current_blog_id(); + + if ( get_current_blog_id() == $id ) + return add_option( $option, $value ); + + switch_to_blog( $id ); + $return = add_option( $option, $value ); restore_current_blog(); - if ( $return ) - wp_cache_set( $id . '-' . $key . '-blog_option', $value, 'site-options' ); + return $return; } /** - * Delete an option for a particular blog. + * Removes option by name for a given blog id. Prevents removal of protected WordPress options. * * @since MU * - * @param int $id The blog id - * @param string $key The option key - * @return bool True on success, false on failure. + * @param int $id A blog ID. Can be null to refer to the current blog. + * @param string $option Name of option to remove. Expected to not be SQL-escaped. + * @return bool True, if option is successfully deleted. False on failure. */ -function delete_blog_option( $id, $key ) { +function delete_blog_option( $id, $option ) { $id = (int) $id; - switch_to_blog($id); - $return = delete_option( $key ); + if ( empty( $id ) ) + $id = get_current_blog_id(); + + if ( get_current_blog_id() == $id ) + return delete_option( $option ); + + switch_to_blog( $id ); + $return = delete_option( $option ); restore_current_blog(); - if ( $return ) - wp_cache_set( $id . '-' . $key . '-blog_option', '', 'site-options' ); + return $return; } @@ -424,24 +459,25 @@ function delete_blog_option( $id, $key ) { * @since MU * * @param int $id The blog id - * @param string $key The option key + * @param string $option The option key * @param mixed $value The option value * @return bool True on success, false on failrue. */ -function update_blog_option( $id, $key, $value, $deprecated = null ) { +function update_blog_option( $id, $option, $value, $deprecated = null ) { $id = (int) $id; if ( null !== $deprecated ) _deprecated_argument( __FUNCTION__, '3.1' ); - switch_to_blog($id); - $return = update_option( $key, $value ); + if ( get_current_blog_id() == $id ) + return update_option( $option, $value ); + + switch_to_blog( $id ); + $return = update_option( $option, $value ); restore_current_blog(); refresh_blog_details( $id ); - if ( $return ) - wp_cache_set( $id . '-' . $key . '-blog_option', $value, 'site-options'); return $return; } @@ -459,68 +495,61 @@ function update_blog_option( $id, $key, $value, $deprecated = null ) { * @since MU * * @param int $new_blog The id of the blog you want to switch to. Default: current blog - * @param bool $validate Whether to check if $new_blog exists before proceeding - * @return bool True on success, False if the validation failed + * @param bool $deprecated Deprecated argument + * @return bool True on success, false if the validation failed */ -function switch_to_blog( $new_blog, $validate = false ) { - global $wpdb, $table_prefix, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache; - - if ( empty($new_blog) ) - $new_blog = $blog_id; +function switch_to_blog( $new_blog, $deprecated = null ) { + global $wpdb, $wp_roles; - if ( $validate && ! get_blog_details( $new_blog ) ) - return false; + if ( empty( $new_blog ) ) + $new_blog = $GLOBALS['blog_id']; - if ( empty($switched_stack) ) - $switched_stack = array(); - - $switched_stack[] = $blog_id; + $GLOBALS['_wp_switched_stack'][] = $GLOBALS['blog_id']; /* If we're switching to the same blog id that we're on, * set the right vars, do the associated actions, but skip * the extra unnecessary work */ - if ( $blog_id == $new_blog ) { - do_action( 'switch_blog', $blog_id, $blog_id ); - $switched = true; + if ( $new_blog == $GLOBALS['blog_id'] ) { + do_action( 'switch_blog', $new_blog, $new_blog ); + $GLOBALS['switched'] = true; return true; } - $wpdb->set_blog_id($new_blog); - $table_prefix = $wpdb->prefix; - $prev_blog_id = $blog_id; - $blog_id = $new_blog; - - if ( is_object( $wp_roles ) ) { - $wpdb->suppress_errors(); - if ( method_exists( $wp_roles ,'_init' ) ) - $wp_roles->_init(); - elseif ( method_exists( $wp_roles, '__construct' ) ) - $wp_roles->__construct(); - $wpdb->suppress_errors( false ); + $wpdb->set_blog_id( $new_blog ); + $GLOBALS['table_prefix'] = $wpdb->prefix; + $prev_blog_id = $GLOBALS['blog_id']; + $GLOBALS['blog_id'] = $new_blog; + + if ( function_exists( 'wp_cache_switch_to_blog' ) ) { + wp_cache_switch_to_blog( $new_blog ); + } else { + global $wp_object_cache; + + if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) + $global_groups = $wp_object_cache->global_groups; + else + $global_groups = false; + + wp_cache_init(); + + if ( function_exists( 'wp_cache_add_global_groups' ) ) { + if ( is_array( $global_groups ) ) + wp_cache_add_global_groups( $global_groups ); + else + wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', ' blog-id-cache' ) ); + wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) ); + } } - if ( did_action('init') ) { + if ( did_action( 'init' ) ) { + $wp_roles->reinit(); $current_user = wp_get_current_user(); - if ( is_object( $current_user ) ) - $current_user->for_blog( $blog_id ); + $current_user->for_blog( $new_blog ); } - if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) - $global_groups = $wp_object_cache->global_groups; - else - $global_groups = false; + do_action( 'switch_blog', $new_blog, $prev_blog_id ); + $GLOBALS['switched'] = true; - wp_cache_init(); - if ( function_exists('wp_cache_add_global_groups') ) { - if ( is_array( $global_groups ) ) - wp_cache_add_global_groups( $global_groups ); - else - wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) ); - wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' )); - } - - do_action('switch_blog', $blog_id, $prev_blog_id); - $switched = true; return true; } @@ -530,66 +559,74 @@ function switch_to_blog( $new_blog, $validate = false ) { * @see switch_to_blog() * @since MU * - * @return bool True on success, False if we're already on the current blog + * @return bool True on success, false if we're already on the current blog */ function restore_current_blog() { - global $table_prefix, $wpdb, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache; + global $wpdb, $wp_roles; - if ( !$switched ) + if ( empty( $GLOBALS['_wp_switched_stack'] ) ) return false; - if ( !is_array( $switched_stack ) ) - return false; + $blog = array_pop( $GLOBALS['_wp_switched_stack'] ); - $blog = array_pop( $switched_stack ); - if ( $blog_id == $blog ) { + if ( $GLOBALS['blog_id'] == $blog ) { do_action( 'switch_blog', $blog, $blog ); - /* If we still have items in the switched stack, consider ourselves still 'switched' */ - $switched = ( is_array( $switched_stack ) && count( $switched_stack ) > 0 ); + // If we still have items in the switched stack, consider ourselves still 'switched' + $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] ); return true; } - $wpdb->set_blog_id($blog); - $prev_blog_id = $blog_id; - $blog_id = $blog; - $table_prefix = $wpdb->prefix; - - if ( is_object( $wp_roles ) ) { - $wpdb->suppress_errors(); - if ( method_exists( $wp_roles ,'_init' ) ) - $wp_roles->_init(); - elseif ( method_exists( $wp_roles, '__construct' ) ) - $wp_roles->__construct(); - $wpdb->suppress_errors( false ); + $wpdb->set_blog_id( $blog ); + $prev_blog_id = $GLOBALS['blog_id']; + $GLOBALS['blog_id'] = $blog; + $GLOBALS['table_prefix'] = $wpdb->prefix; + + if ( function_exists( 'wp_cache_switch_to_blog' ) ) { + wp_cache_switch_to_blog( $blog ); + } else { + global $wp_object_cache; + + if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) + $global_groups = $wp_object_cache->global_groups; + else + $global_groups = false; + + wp_cache_init(); + + if ( function_exists( 'wp_cache_add_global_groups' ) ) { + if ( is_array( $global_groups ) ) + wp_cache_add_global_groups( $global_groups ); + else + wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', ' blog-id-cache' ) ); + wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) ); + } } - if ( did_action('init') ) { + if ( did_action( 'init' ) ) { + $wp_roles->reinit(); $current_user = wp_get_current_user(); - if ( is_object( $current_user ) ) - $current_user->for_blog( $blog_id ); + $current_user->for_blog( $blog ); } - if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) - $global_groups = $wp_object_cache->global_groups; - else - $global_groups = false; + do_action( 'switch_blog', $blog, $prev_blog_id ); - wp_cache_init(); - if ( function_exists('wp_cache_add_global_groups') ) { - if ( is_array( $global_groups ) ) - wp_cache_add_global_groups( $global_groups ); - else - wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) ); - wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' )); - } + // If we still have items in the switched stack, consider ourselves still 'switched' + $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] ); - do_action('switch_blog', $blog_id, $prev_blog_id); - - /* If we still have items in the switched stack, consider ourselves still 'switched' */ - $switched = ( is_array( $switched_stack ) && count( $switched_stack ) > 0 ); return true; } +/** + * Determines if switch_to_blog() is in effect + * + * @since 3.5.0 + * + * @return bool True if switched, false otherwise. + */ +function ms_is_switched() { + return ! empty( $GLOBALS['_wp_switched_stack'] ); +} + /** * Check if a particular blog is archived. * @@ -632,12 +669,15 @@ function update_blog_status( $blog_id, $pref, $value, $deprecated = null ) { if ( null !== $deprecated ) _deprecated_argument( __FUNCTION__, '3.1' ); - if ( !in_array( $pref, array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id') ) ) + if ( ! in_array( $pref, array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id') ) ) return $value; - $wpdb->update( $wpdb->blogs, array($pref => $value, 'last_updated' => current_time('mysql', true)), array('blog_id' => $blog_id) ); + $result = $wpdb->update( $wpdb->blogs, array($pref => $value, 'last_updated' => current_time('mysql', true)), array('blog_id' => $blog_id) ); - refresh_blog_details($blog_id); + if ( false === $result ) + return false; + + refresh_blog_details( $blog_id ); if ( 'spam' == $pref ) ( $value == 1 ) ? do_action( 'make_spam_blog', $blog_id ) : do_action( 'make_ham_blog', $blog_id ); @@ -645,8 +685,8 @@ function update_blog_status( $blog_id, $pref, $value, $deprecated = null ) { ( $value == 1 ) ? do_action( 'mature_blog', $blog_id ) : do_action( 'unmature_blog', $blog_id ); elseif ( 'archived' == $pref ) ( $value == 1 ) ? do_action( 'archive_blog', $blog_id ) : do_action( 'unarchive_blog', $blog_id ); - elseif ( 'archived' == $pref ) - ( $value == 1 ) ? do_action( 'archive_blog', $blog_id ) : do_action( 'unarchive_blog', $blog_id ); + elseif ( 'deleted' == $pref ) + ( $value == 1 ) ? do_action( 'make_delete_blog', $blog_id ) : do_action( 'make_undelete_blog', $blog_id ); return $value; } diff --git a/wp-includes/ms-default-constants.php b/wp-includes/ms-default-constants.php index cc341b14..53dfc9b5 100644 --- a/wp-includes/ms-default-constants.php +++ b/wp-includes/ms-default-constants.php @@ -10,21 +10,31 @@ /** * Defines Multisite upload constants. * + * Exists for backward compatibility with legacy file-serving through + * wp-includes/ms-files.php (wp-content/blogs.php in MU). + * * @since 3.0.0 */ -function ms_upload_constants( ) { +function ms_upload_constants() { global $wpdb; - /** @since 3.0.0 */ + // This filter is attached in ms-default-filters.php but that file is not included during SHORTINIT. + add_filter( 'default_site_option_ms_files_rewriting', '__return_true' ); + + if ( ! get_site_option( 'ms_files_rewriting' ) ) + return; + // Base uploads dir relative to ABSPATH if ( !defined( 'UPLOADBLOGSDIR' ) ) define( 'UPLOADBLOGSDIR', 'wp-content/blogs.dir' ); - /** @since 3.0.0 */ - if ( !defined( 'UPLOADS' ) ) { - // Uploads dir relative to ABSPATH + // Note, the main site in a post-MU network uses wp-content/uploads. + // This is handled in wp_upload_dir() by ignoring UPLOADS for this case. + if ( ! defined( 'UPLOADS' ) ) { define( 'UPLOADS', UPLOADBLOGSDIR . "/{$wpdb->blogid}/files/" ); - if ( 'wp-content/blogs.dir' == UPLOADBLOGSDIR ) + + // Uploads dir relative to ABSPATH + if ( 'wp-content/blogs.dir' == UPLOADBLOGSDIR && ! defined( 'BLOGUPLOADDIR' ) ) define( 'BLOGUPLOADDIR', WP_CONTENT_DIR . "/blogs.dir/{$wpdb->blogid}/files/" ); } } @@ -53,7 +63,7 @@ function ms_cookie_constants( ) { * @since 2.6.0 */ if ( !defined( 'ADMIN_COOKIE_PATH' ) ) { - if( !is_subdomain_install() ) { + if ( ! is_subdomain_install() || trim( parse_url( get_option( 'siteurl' ), PHP_URL_PATH ), '/' ) ) { define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH ); } else { define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin' ); @@ -74,9 +84,12 @@ function ms_cookie_constants( ) { /** * Defines Multisite file constants. * + * Exists for backward compatibility with legacy file-serving through + * wp-includes/ms-files.php (wp-content/blogs.php in MU). + * * @since 3.0.0 */ -function ms_file_constants( ) { +function ms_file_constants() { /** * Optional support for X-Sendfile header * @since 3.0.0 diff --git a/wp-includes/ms-default-filters.php b/wp-includes/ms-default-filters.php index 44d8294a..34dc151c 100644 --- a/wp-includes/ms-default-filters.php +++ b/wp-includes/ms-default-filters.php @@ -45,6 +45,7 @@ add_filter( 'wp_upload_bits', 'upload_is_file_too_big' ); add_filter( 'import_upload_size_limit', 'fix_import_form_size' ); add_filter( 'upload_mimes', 'check_upload_mimes' ); add_filter( 'upload_size_limit', 'upload_size_limit_filter' ); +add_action( 'upload_ui_over_quota', 'multisite_over_quota_message' ); // Mail add_action( 'phpmailer_init', 'fix_phpmailer_messageid' ); @@ -60,3 +61,6 @@ add_filter( 'force_filtered_html_on_import', '__return_true' ); // WP_HOME and WP_SITEURL should not have any effect in MS remove_filter( 'option_siteurl', '_config_wp_siteurl' ); remove_filter( 'option_home', '_config_wp_home' ); + +// If the network upgrade hasn't run yet, assume ms-files.php rewriting is used. +add_filter( 'default_site_option_ms_files_rewriting', '__return_true' ); \ No newline at end of file diff --git a/wp-includes/ms-functions.php b/wp-includes/ms-functions.php index f4fe306b..0f6794b5 100644 --- a/wp-includes/ms-functions.php +++ b/wp-includes/ms-functions.php @@ -152,17 +152,12 @@ function get_blog_count( $id = 0 ) { * * @param int $blog_id ID of the blog. * @param int $post_id ID of the post you're looking for. - * @return object The post. + * @return WP_Post|null WP_Post on success or null on failure */ function get_blog_post( $blog_id, $post_id ) { - global $wpdb; - - $key = $blog_id . '-' . $post_id; - $post = wp_cache_get( $key, 'global-posts' ); - if ( $post == false ) { - $post = $wpdb->get_row( $wpdb->prepare( 'SELECT * FROM ' . $wpdb->get_blog_prefix( $blog_id ) . 'posts WHERE ID = %d', $post_id ) ); - wp_cache_add( $key, $post, 'global-posts' ); - } + switch_to_blog( $blog_id ); + $post = get_post( $post_id ); + restore_current_blog(); return $post; } @@ -183,11 +178,11 @@ function get_blog_post( $blog_id, $post_id ) { function add_user_to_blog( $blog_id, $user_id, $role ) { switch_to_blog($blog_id); - $user = new WP_User($user_id); + $user = get_userdata( $user_id ); - if ( ! $user->exists() ) { + if ( ! $user ) { restore_current_blog(); - return new WP_Error('user_does_not_exist', __('That user does not exist.')); + return new WP_Error( 'user_does_not_exist', __( 'The requested user does not exist.' ) ); } if ( !get_user_meta($user_id, 'primary_blog', true) ) { @@ -246,8 +241,8 @@ function remove_user_from_blog($user_id, $blog_id = '', $reassign = '') { } // wp_revoke_user($user_id); - $user = new WP_User($user_id); - if ( ! $user->exists() ) { + $user = get_userdata( $user_id ); + if ( ! $user ) { restore_current_blog(); return new WP_Error('user_does_not_exist', __('That user does not exist.')); } @@ -313,19 +308,15 @@ function create_empty_blog( $domain, $path, $weblog_title, $site_id = 1 ) { * * @since MU 1.0 * - * @param int $_blog_id ID of the source blog. + * @param int $blog_id ID of the source blog. * @param int $post_id ID of the desired post. * @return string The post's permalink */ -function get_blog_permalink( $_blog_id, $post_id ) { - $key = "{$_blog_id}-{$post_id}-blog_permalink"; - $link = wp_cache_get( $key, 'site-options' ); - if ( $link == false ) { - switch_to_blog( $_blog_id ); - $link = get_permalink( $post_id ); - restore_current_blog(); - wp_cache_add( $key, $link, 'site-options', 360 ); - } +function get_blog_permalink( $blog_id, $post_id ) { + switch_to_blog( $blog_id ); + $link = get_permalink( $post_id ); + restore_current_blog(); + return $link; } @@ -341,27 +332,27 @@ function get_blog_permalink( $_blog_id, $post_id ) { * * @param string $domain * @param string $path Optional. Not required for subdomain installations. - * @return int + * @return int 0 if no blog found, otherwise the ID of the matching blog */ function get_blog_id_from_url( $domain, $path = '/' ) { global $wpdb; - $domain = strtolower( $wpdb->escape( $domain ) ); - $path = strtolower( $wpdb->escape( $path ) ); + $domain = strtolower( $domain ); + $path = strtolower( $path ); $id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' ); - if ( $id == -1 ) { // blog does not exist + if ( $id == -1 ) // blog does not exist return 0; - } elseif ( $id ) { - return (int)$id; - } + elseif ( $id ) + return (int) $id; - $id = $wpdb->get_var( "SELECT blog_id FROM $wpdb->blogs WHERE domain = '$domain' and path = '$path' /* get_blog_id_from_url */" ); + $id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s and path = %s /* get_blog_id_from_url */", $domain, $path ) ); - if ( !$id ) { + if ( ! $id ) { wp_cache_set( md5( $domain . $path ), -1, 'blog-id-cache' ); - return false; + return 0; } + wp_cache_set( md5( $domain . $path ), $id, 'blog-id-cache' ); return $id; @@ -384,25 +375,32 @@ function get_blog_id_from_url( $domain, $path = '/' ) { */ function is_email_address_unsafe( $user_email ) { $banned_names = get_site_option( 'banned_email_domains' ); - if ($banned_names && !is_array( $banned_names )) - $banned_names = explode( "\n", $banned_names); + if ( $banned_names && ! is_array( $banned_names ) ) + $banned_names = explode( "\n", $banned_names ); + + $is_email_address_unsafe = false; - if ( is_array( $banned_names ) && empty( $banned_names ) == false ) { - $email_domain = strtolower( substr( $user_email, 1 + strpos( $user_email, '@' ) ) ); - foreach ( (array) $banned_names as $banned_domain ) { - if ( $banned_domain == '' ) + if ( $banned_names && is_array( $banned_names ) ) { + list( $email_local_part, $email_domain ) = explode( '@', $user_email ); + + foreach ( $banned_names as $banned_domain ) { + if ( ! $banned_domain ) continue; - if ( - strstr( $email_domain, $banned_domain ) || - ( - strstr( $banned_domain, '/' ) && - preg_match( $banned_domain, $email_domain ) - ) - ) - return true; + + if ( $email_domain == $banned_domain ) { + $is_email_address_unsafe = true; + break; + } + + $dotted_domain = ".$banned_domain"; + if ( $dotted_domain === substr( $user_email, -strlen( $dotted_domain ) ) ) { + $is_email_address_unsafe = true; + break; + } } } - return false; + + return apply_filters( 'is_email_address_unsafe', $is_email_address_unsafe, $user_email ); } /** @@ -471,7 +469,7 @@ function wpmu_validate_user_signup($user_name, $user_email) { $errors->add('user_name', __('Sorry, usernames must have letters too!')); if ( !is_email( $user_email ) ) - $errors->add('user_email', __( 'Please enter a correct email address.' ) ); + $errors->add('user_email', __( 'Please enter a valid email address.' ) ); $limited_email_domains = get_site_option( 'limited_email_domains' ); if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) { @@ -482,11 +480,11 @@ function wpmu_validate_user_signup($user_name, $user_email) { // Check if the username has been used already. if ( username_exists($user_name) ) - $errors->add('user_name', __('Sorry, that username already exists!')); + $errors->add( 'user_name', __( 'Sorry, that username already exists!' ) ); // Check if the email address has been used already. if ( email_exists($user_email) ) - $errors->add('user_email', __('Sorry, that email address is already used!')); + $errors->add( 'user_email', __( 'Sorry, that email address is already used!' ) ); // Has someone already signed up for this username? $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE user_login = %s", $user_name) ); @@ -495,7 +493,7 @@ function wpmu_validate_user_signup($user_name, $user_email) { $now = current_time( 'timestamp', true ); $diff = $now - $registered_at; // If registered more than two days ago, cancel registration and let this signup go through. - if ( $diff > 172800 ) + if ( $diff > 2 * DAY_IN_SECONDS ) $wpdb->delete( $wpdb->signups, array( 'user_login' => $user_name ) ); else $errors->add('user_name', __('That username is currently reserved but may be available in a couple of days.')); @@ -508,7 +506,7 @@ function wpmu_validate_user_signup($user_name, $user_email) { if ( $signup != null ) { $diff = current_time( 'timestamp', true ) - mysql2date('U', $signup->registered); // If registered more than two days ago, cancel registration and let this signup go through. - if ( $diff > 172800 ) + if ( $diff > 2 * DAY_IN_SECONDS ) $wpdb->delete( $wpdb->signups, array( 'user_email' => $user_email ) ); else $errors->add('user_email', __('That email address has already been used. Please check your inbox for an activation email. It will become available in a couple of days if you do nothing.')); @@ -542,7 +540,9 @@ function wpmu_validate_user_signup($user_name, $user_email) { * @return array Contains the new site data and error messages. */ function wpmu_validate_blog_signup($blogname, $blog_title, $user = '') { - global $wpdb, $domain, $base, $current_site; + global $wpdb, $domain, $current_site; + + $base = $current_site->path; $blog_title = strip_tags( $blog_title ); $blog_title = substr( $blog_title, 0, 50 ); @@ -562,7 +562,7 @@ function wpmu_validate_blog_signup($blogname, $blog_title, $user = '') { $errors->add('blogname', __( 'Please enter a site name.' ) ); if ( preg_match( '/[^a-z0-9]+/', $blogname ) ) - $errors->add('blogname', __( 'Only lowercase letters and numbers allowed.' ) ); + $errors->add('blogname', __( 'Only lowercase letters (a-z) and numbers are allowed.' ) ); if ( in_array( $blogname, $illegal_names ) == true ) $errors->add('blogname', __( 'That name is not allowed.' ) ); @@ -598,8 +598,8 @@ function wpmu_validate_blog_signup($blogname, $blog_title, $user = '') { $mydomain = "$domain"; $path = $base.$blogname.'/'; } - if ( domain_exists($mydomain, $path) ) - $errors->add('blogname', __('Sorry, that site already exists!')); + if ( domain_exists($mydomain, $path, $current_site->id) ) + $errors->add( 'blogname', __( 'Sorry, that site already exists!' ) ); if ( username_exists( $blogname ) ) { if ( is_object( $user ) == false || ( is_object($user) && ( $user->user_login != $blogname ) ) ) @@ -611,13 +611,13 @@ function wpmu_validate_blog_signup($blogname, $blog_title, $user = '') { if ( ! empty($signup) ) { $diff = current_time( 'timestamp', true ) - mysql2date('U', $signup->registered); // If registered more than two days ago, cancel registration and let this signup go through. - if ( $diff > 172800 ) + if ( $diff > 2 * DAY_IN_SECONDS ) $wpdb->delete( $wpdb->signups, array( 'domain' => $mydomain , 'path' => $path ) ); else $errors->add('blogname', __('That site is currently reserved but may be available in a couple days.')); } - $result = array('domain' => $mydomain, 'path' => $path, 'blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors); + $result = array('domain' => $mydomain, 'path' => $path, 'blogname' => $blogname, 'blog_title' => $blog_title, 'user' => $user, 'errors' => $errors); return apply_filters('wpmu_validate_blog_signup', $result); } @@ -790,7 +790,7 @@ function wpmu_signup_user_notification($user, $user_email, $key, $meta = '') { $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; $message = sprintf( apply_filters( 'wpmu_signup_user_notification_email', - __( "To activate your user, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login.\n\n" ), + __( "To activate your user, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login." ), $user, $user_email, $key, $meta ), site_url( "wp-activate.php?key=$key" ) @@ -965,7 +965,7 @@ function wpmu_create_blog($domain, $path, $title, $user_id, $meta = '', $site_id // Check if the domain has been used already. We should return an error message. if ( domain_exists($domain, $path, $site_id) ) - return new WP_Error('blog_taken', __('Site already exists.')); + return new WP_Error( 'blog_taken', __( 'Sorry, that site already exists!' ) ); if ( !defined('WP_INSTALLING') ) define( 'WP_INSTALLING', true ); @@ -1024,11 +1024,11 @@ function newblog_notify_siteadmin( $blog_id, $deprecated = '' ) { $siteurl = site_url(); restore_current_blog(); - $msg = sprintf( __( 'New Site: %1s -URL: %2s -Remote IP: %3s + $msg = sprintf( __( 'New Site: %1$s +URL: %2$s +Remote IP: %3$s -Disable these notifications: %4s' ), $blogname, $siteurl, $_SERVER['REMOTE_ADDR'], $options_site_url); +Disable these notifications: %4$s' ), $blogname, $siteurl, $_SERVER['REMOTE_ADDR'], $options_site_url); $msg = apply_filters( 'newblog_notify_siteadmin', $msg ); wp_mail( $email, sprintf( __( 'New Site Registration: %s' ), $siteurl ), $msg ); @@ -1056,13 +1056,13 @@ function newuser_notify_siteadmin( $user_id ) { if ( is_email($email) == false ) return false; - $user = new WP_User($user_id); + $user = get_userdata( $user_id ); $options_site_url = esc_url(network_admin_url('settings.php')); - $msg = sprintf(__('New User: %1s -Remote IP: %2s + $msg = sprintf(__('New User: %1$s +Remote IP: %2$s -Disable these notifications: %3s'), $user->user_login, $_SERVER['REMOTE_ADDR'], $options_site_url); +Disable these notifications: %3$s'), $user->user_login, $_SERVER['REMOTE_ADDR'], $options_site_url); $msg = apply_filters( 'newuser_notify_siteadmin', $msg, $user ); wp_mail( $email, sprintf(__('New User Registration: %s'), $user->user_login), $msg ); @@ -1084,7 +1084,8 @@ Disable these notifications: %3s'), $user->user_login, $_SERVER['REMOTE_ADDR'], */ function domain_exists($domain, $path, $site_id = 1) { global $wpdb; - return $wpdb->get_var( $wpdb->prepare("SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s AND site_id = %d", $domain, $path, $site_id) ); + $result = $wpdb->get_var( $wpdb->prepare("SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s AND site_id = %d", $domain, $path, $site_id) ); + return apply_filters( 'domain_exists', $result, $domain, $path, $site_id ); } /** @@ -1129,20 +1130,19 @@ function insert_blog($domain, $path, $site_id) { * @param string $blog_title The title of the new site. */ function install_blog($blog_id, $blog_title = '') { - global $wpdb, $table_prefix, $wp_roles; - $wpdb->suppress_errors(); + global $wpdb, $wp_roles, $current_site; // Cast for security $blog_id = (int) $blog_id; require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); - if ( $wpdb->get_results("SELECT ID FROM $wpdb->posts") ) - die(__('

    Already Installed

    You appear to have already installed WordPress. To reinstall please clear your old database tables first.

    ') . ''); + $wpdb->suppress_errors(); + if ( $wpdb->get_results( "DESCRIBE {$wpdb->posts}" ) ) + die( '

    ' . __( 'Already Installed' ) . '

    ' . __( 'You appear to have already installed WordPress. To reinstall please clear your old database tables first.' ) . '

    ' ); + $wpdb->suppress_errors( false ); - $wpdb->suppress_errors(false); - - $url = get_blogaddress_by_id($blog_id); + $url = get_blogaddress_by_id( $blog_id ); // Set everything up make_db_current_silent( 'blog' ); @@ -1150,21 +1150,23 @@ function install_blog($blog_id, $blog_title = '') { populate_roles(); $wp_roles->_init(); - // fix url. - update_option('siteurl', $url); - update_option('home', $url); - update_option('fileupload_url', $url . "files" ); - update_option('upload_path', UPLOADBLOGSDIR . "/$blog_id/files"); - update_option('blogname', stripslashes( $blog_title ) ); - update_option('admin_email', ''); - $wpdb->update( $wpdb->options, array('option_value' => ''), array('option_name' => 'admin_email') ); + $url = untrailingslashit( $url ); - // remove all perms - $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => $table_prefix.'user_level' ) ); + update_option( 'siteurl', $url ); + update_option( 'home', $url ); - $wpdb->delete( $wpdb->usermeta, array( 'meta_key' => $table_prefix.'capabilities' ) ); + if ( get_site_option( 'ms_files_rewriting' ) ) + update_option( 'upload_path', UPLOADBLOGSDIR . "/$blog_id/files" ); + else + update_option( 'upload_path', get_blog_option( $current_site->blog_id, 'upload_path' ) ); - $wpdb->suppress_errors( false ); + update_option( 'blogname', stripslashes( $blog_title ) ); + update_option( 'admin_email', '' ); + + // remove all perms + $table_prefix = $wpdb->get_blog_prefix(); + delete_metadata( 'user', 0, $table_prefix . 'user_level', null, true ); // delete all + delete_metadata( 'user', 0, $table_prefix . 'capabilities', null, true ); // delete all } /** @@ -1232,7 +1234,7 @@ We hope you enjoy your new site. Thanks! --The Team @ SITE_NAME' ) ); $url = get_blogaddress_by_id($blog_id); - $user = new WP_User($user_id); + $user = get_userdata( $user_id ); $welcome_email = str_replace( 'SITE_NAME', $current_site->site_name, $welcome_email ); $welcome_email = str_replace( 'BLOG_TITLE', $title, $welcome_email ); @@ -1281,7 +1283,7 @@ function wpmu_welcome_user_notification($user_id, $password, $meta = '') { $welcome_email = get_site_option( 'welcome_user_email' ); - $user = new WP_User($user_id); + $user = get_userdata( $user_id ); $welcome_email = apply_filters( 'update_welcome_user_email', $welcome_email, $user_id, $password, $meta); $welcome_email = str_replace( 'SITE_NAME', $current_site->site_name, $welcome_email ); @@ -1416,7 +1418,7 @@ function get_dirsize( $directory ) { $dirsize[ $directory ][ 'size' ] = recurse_dirsize( $directory ); - set_transient( 'dirsize_cache', $dirsize, 3600 ); + set_transient( 'dirsize_cache', $dirsize, HOUR_IN_SECONDS ); return $dirsize[ $directory ][ 'size' ]; } @@ -1457,34 +1459,6 @@ function recurse_dirsize( $directory ) { return $size; } -/** - * Check whether a blog has used its allotted upload space. - * - * @since MU - * @uses get_dirsize() - * - * @param bool $echo Optional. If $echo is set and the quota is exceeded, a warning message is echoed. Default is true. - * @return int - */ -function upload_is_user_over_quota( $echo = true ) { - if ( get_site_option( 'upload_space_check_disabled' ) ) - return false; - - $spaceAllowed = get_space_allowed(); - if ( empty( $spaceAllowed ) || !is_numeric( $spaceAllowed ) ) - $spaceAllowed = 10; // Default space allowed is 10 MB - - $size = get_dirsize( BLOGUPLOADDIR ) / 1024 / 1024; - - if ( ($spaceAllowed-$size) < 0 ) { - if ( $echo ) - _e( 'Sorry, you have used your space allocation. Please delete some files to upload more files.' ); // No space left - return true; - } else { - return false; - } -} - /** * Check an array of MIME types against a whitelist. * @@ -1535,33 +1509,10 @@ function update_posts_count( $deprecated = '' ) { */ function wpmu_log_new_registrations( $blog_id, $user_id ) { global $wpdb; - $user = new WP_User( (int) $user_id ); + $user = get_userdata( (int) $user_id ); $wpdb->insert( $wpdb->registration_log, array('email' => $user->user_email, 'IP' => preg_replace( '/[^0-9., ]/', '',$_SERVER['REMOTE_ADDR'] ), 'blog_id' => $blog_id, 'date_registered' => current_time('mysql')) ); } -/** - * Get the remaining upload space for this blog. - * - * @since MU - * @uses upload_is_user_over_quota() - * @uses get_space_allowed() - * @uses get_dirsize() - * - * @param int $size - * @return int - */ -function fix_import_form_size( $size ) { - if ( upload_is_user_over_quota( false ) == true ) - return 0; - - $spaceAllowed = 1024 * 1024 * get_space_allowed(); - $dirsize = get_dirsize( BLOGUPLOADDIR ); - if ( $size > $spaceAllowed - $dirsize ) - return $spaceAllowed - $dirsize; // remaining space - else - return $size; // default -} - /** * Maintains a canonical list of terms by syncing terms created for each blog with the global terms table. * @@ -1652,7 +1603,7 @@ function redirect_this_site( $deprecated = '' ) { * @return mixed If the upload is under the size limit, $upload is returned. Otherwise returns an error message. */ function upload_is_file_too_big( $upload ) { - if ( is_array( $upload ) == false || defined( 'WP_IMPORTING' ) ) + if ( is_array( $upload ) == false || defined( 'WP_IMPORTING' ) || get_site_option( 'upload_space_check_disabled' ) ) return $upload; if ( strlen( $upload['bits'] ) > ( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) ) @@ -1687,7 +1638,7 @@ function signup_nonce_check( $result ) { return $result; if ( wp_create_nonce('signup_form_' . $_POST[ 'signup_form_id' ]) != $_POST['_signup_form'] ) - wp_die( __('Please try again!') ); + wp_die( __( 'Please try again.' ) ); return $result; } @@ -1734,7 +1685,7 @@ function maybe_add_existing_user_to_blog() { if ( empty( $details ) || is_wp_error( add_existing_user_to_blog( $details ) ) ) wp_die( sprintf(__('An error occurred adding you to this site. Back to the homepage.'), home_url() ) ); - wp_die( sprintf(__('You have been added to this site. Please visit the homepage or log in using your username and password.'), home_url(), admin_url() ), __('Success') ); + wp_die( sprintf( __( 'You have been added to this site. Please visit the homepage or log in using your username and password.' ), home_url(), admin_url() ), __( 'WordPress › Success' ) ); } /** @@ -1801,7 +1752,7 @@ function is_user_spammy( $username = 0 ) { } else { $user_id = get_user_id_from_string( $username ); } - $u = new WP_User( $user_id ); + $u = get_userdata( $user_id ); return ( isset( $u->spam ) && $u->spam == 1 ); } @@ -1934,21 +1885,21 @@ function force_ssl_content( $force = '' ) { } /** - * Formats an String URL to use HTTPS if HTTP is found. + * Formats a URL to use https. + * * Useful as a filter. * * @since 2.8.5 - **/ + * + * @param string URL + * @return string URL with https as the scheme + */ function filter_SSL( $url ) { - if ( !is_string( $url ) ) - return get_bloginfo( 'url' ); //return home blog url with proper scheme - - $arrURL = parse_url( $url ); + if ( ! is_string( $url ) ) + return get_bloginfo( 'url' ); // Return home blog url with proper scheme - if ( force_ssl_content() && is_ssl() ) { - if ( 'http' === $arrURL['scheme'] ) - $url = str_replace( $arrURL['scheme'], 'https', $url ); - } + if ( force_ssl_content() && is_ssl() ) + $url = set_url_scheme( $url, 'https' ); return $url; } @@ -1977,6 +1928,89 @@ function wp_update_network_counts() { $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(blog_id) as c FROM $wpdb->blogs WHERE site_id = %d AND spam = '0' AND deleted = '0' and archived = '0'", $wpdb->siteid) ); update_site_option( 'blog_count', $count ); - $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'") ); + $count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" ); update_site_option( 'user_count', $count ); } + +/** + * Returns the space used by the current blog. + * + * @since 3.5.0 + * + * @return int Used space in megabytes + */ +function get_space_used() { + // Allow for an alternative way of tracking storage space used + $space_used = apply_filters( 'pre_get_space_used', false ); + if ( false === $space_used ) { + $upload_dir = wp_upload_dir(); + $space_used = get_dirsize( $upload_dir['basedir'] ) / 1024 / 1024; + } + + return $space_used; +} + +/** + * Returns the upload quota for the current blog. + * + * @since MU + * + * @return int Quota in megabytes + */ +function get_space_allowed() { + $space_allowed = get_option( 'blog_upload_space' ); + + if ( ! is_numeric( $space_allowed ) ) + $space_allowed = get_site_option( 'blog_upload_space' ); + + if ( empty( $space_allowed ) || ! is_numeric( $space_allowed ) ) + $space_allowed = 50; + + return $space_allowed; +} + +/** + * Determines if there is any upload space left in the current blog's quota. + * + * @since 3.0.0 + * + * @return int of upload space available in bytes + */ +function get_upload_space_available() { + $space_allowed = get_space_allowed() * 1024 * 1024; + if ( get_site_option( 'upload_space_check_disabled' ) ) + return $space_allowed; + + $space_used = get_space_used() * 1024 * 1024; + + if ( ( $space_allowed - $space_used ) <= 0 ) + return 0; + + return $space_allowed - $space_used; +} + +/** + * Determines if there is any upload space left in the current blog's quota. + * + * @since 3.0.0 + * @return bool True if space is available, false otherwise. + */ +function is_upload_space_available() { + if ( get_site_option( 'upload_space_check_disabled' ) ) + return true; + + return (bool) get_upload_space_available(); +} + +/** + * @since 3.0.0 + * + * @return int of upload size limit in bytes + */ +function upload_size_limit_filter( $size ) { + $fileupload_maxk = 1024 * get_site_option( 'fileupload_maxk', 1500 ); + if ( get_site_option( 'upload_space_check_disabled' ) ) + return min( $size, $fileupload_maxk ); + + return min( $size, $fileupload_maxk, get_upload_space_available() ); +} \ No newline at end of file diff --git a/wp-includes/ms-load.php b/wp-includes/ms-load.php index 58826e78..6a26b9cf 100644 --- a/wp-includes/ms-load.php +++ b/wp-includes/ms-load.php @@ -69,7 +69,9 @@ function wp_get_active_network_plugins() { * @return bool|string Returns true on success, or drop-in file to include. */ function ms_site_check() { - global $wpdb, $current_blog; + global $wpdb; + + $blog = get_blog_details(); // Allow short-circuiting $check = apply_filters('ms_site_check', null); @@ -80,21 +82,21 @@ function ms_site_check() { if ( is_super_admin() ) return true; - if ( '1' == $current_blog->deleted ) { + if ( '1' == $blog->deleted ) { if ( file_exists( WP_CONTENT_DIR . '/blog-deleted.php' ) ) return WP_CONTENT_DIR . '/blog-deleted.php'; else wp_die( __( 'This user has elected to delete their account and the content is no longer available.' ), '', array( 'response' => 410 ) ); } - if ( '2' == $current_blog->deleted ) { + if ( '2' == $blog->deleted ) { if ( file_exists( WP_CONTENT_DIR . '/blog-inactive.php' ) ) return WP_CONTENT_DIR . '/blog-inactive.php'; else wp_die( sprintf( __( 'This site has not been activated yet. If you are having problems activating your site, please contact %1$s.' ), str_replace( '@', ' AT ', get_site_option( 'admin_email', "support@{$current_site->domain}" ) ) ) ); } - if ( $current_blog->archived == '1' || $current_blog->spam == '1' ) { + if ( $blog->archived == '1' || $blog->spam == '1' ) { if ( file_exists( WP_CONTENT_DIR . '/blog-suspended.php' ) ) return WP_CONTENT_DIR . '/blog-suspended.php'; else @@ -232,7 +234,7 @@ function ms_not_installed() { wp_load_translations_early(); - $title = __( 'Error establishing database connection' ); + $title = __( 'Error establishing a database connection' ); $msg = '

    ' . $title . '

    '; if ( ! is_admin() ) die( $msg ); diff --git a/wp-includes/ms-settings.php b/wp-includes/ms-settings.php index 5dd460e3..af2ea0d9 100644 --- a/wp-includes/ms-settings.php +++ b/wp-includes/ms-settings.php @@ -126,6 +126,8 @@ if ( !isset( $current_site ) || !isset( $current_blog ) ) { $wpdb->set_prefix( $table_prefix, false ); // $table_prefix can be set in sunrise.php $wpdb->set_blog_id( $current_blog->blog_id, $current_blog->site_id ); $table_prefix = $wpdb->get_blog_prefix(); +$_wp_switched_stack = array(); +$switched = false; // need to init cache again after blog_id is set wp_start_object_cache(); diff --git a/wp-includes/nav-menu-template.php b/wp-includes/nav-menu-template.php index 4b9293b1..df5612d2 100644 --- a/wp-includes/nav-menu-template.php +++ b/wp-includes/nav-menu-template.php @@ -65,7 +65,6 @@ class Walker_Nav_Menu extends Walker { * @param object $args */ function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { - global $wp_query; $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; $class_names = $value = ''; @@ -156,7 +155,7 @@ function wp_nav_menu( $args = array() ) { if ( ! $menu && !$args->theme_location ) { $menus = wp_get_nav_menus(); foreach ( $menus as $menu_maybe ) { - if ( $menu_items = wp_get_nav_menu_items($menu_maybe->term_id) ) { + if ( $menu_items = wp_get_nav_menu_items( $menu_maybe->term_id, array( 'update_post_term_cache' => false ) ) ) { $menu = $menu_maybe; break; } @@ -165,15 +164,21 @@ function wp_nav_menu( $args = array() ) { // If the menu exists, get its items. if ( $menu && ! is_wp_error($menu) && !isset($menu_items) ) - $menu_items = wp_get_nav_menu_items( $menu->term_id ); + $menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'update_post_term_cache' => false ) ); - // If no menu was found or if the menu has no items and no location was requested, call the fallback_cb if it exists + /* + * If no menu was found: + * - Fallback (if one was specified), or bail. + * + * If no menu items were found: + * - Fallback, but only if no theme location was specified. + * - Otherwise, bail. + */ if ( ( !$menu || is_wp_error($menu) || ( isset($menu_items) && empty($menu_items) && !$args->theme_location ) ) && $args->fallback_cb && is_callable( $args->fallback_cb ) ) return call_user_func( $args->fallback_cb, (array) $args ); - // If no fallback function was specified and the menu doesn't exists, bail. - if ( !$menu || is_wp_error($menu) ) + if ( !$menu || is_wp_error( $menu ) || empty( $menu_items ) ) return false; $nav_menu = $items = ''; @@ -287,8 +292,6 @@ function _wp_menu_item_classes_by_context( &$menu_items ) { } } } - } elseif ( ! empty( $queried_object->post_type ) && is_post_type_hierarchical( $queried_object->post_type ) ) { - _get_post_ancestors( $queried_object ); } elseif ( ! empty( $queried_object->taxonomy ) && is_taxonomy_hierarchical( $queried_object->taxonomy ) ) { $term_hierarchy = _get_term_hierarchy( $queried_object->taxonomy ); $term_to_ancestor = array(); @@ -334,7 +337,7 @@ function _wp_menu_item_classes_by_context( &$menu_items ) { ( ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && $wp_query->is_home && $home_page_id == $menu_item->object_id ) || ( 'post_type' == $menu_item->type && $wp_query->is_singular ) || - ( 'taxonomy' == $menu_item->type && ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax ) ) + ( 'taxonomy' == $menu_item->type && ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax ) && $queried_object->taxonomy == $menu_item->object ) ) ) { $classes[] = 'current-menu-item'; @@ -361,7 +364,7 @@ function _wp_menu_item_classes_by_context( &$menu_items ) { // if the menu item corresponds to the currently-requested URL } elseif ( 'custom' == $menu_item->object ) { $_root_relative_current = untrailingslashit( $_SERVER['REQUEST_URI'] ); - $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_root_relative_current; + $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_root_relative_current ); $raw_item_url = strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url; $item_url = untrailingslashit( $raw_item_url ); $_indexless_current = untrailingslashit( preg_replace( '/index.php$/', '', $current_url ) ); @@ -472,7 +475,7 @@ function walk_nav_menu_tree( $items, $depth, $r ) { $walker = ( empty($r->walker) ) ? new Walker_Nav_Menu : $r->walker; $args = array( $items, $depth, $r ); - return call_user_func_array( array(&$walker, 'walk'), $args ); + return call_user_func_array( array($walker, 'walk'), $args ); } /** diff --git a/wp-includes/nav-menu.php b/wp-includes/nav-menu.php index 361a8de6..7a5da9e2 100644 --- a/wp-includes/nav-menu.php +++ b/wp-includes/nav-menu.php @@ -279,10 +279,6 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item if ( ( ! $menu && 0 !== $menu_id ) || is_wp_error( $menu ) ) return $menu; - $menu_items = 0 == $menu_id ? array() : (array) wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) ); - - $count = count( $menu_items ); - $defaults = array( 'menu-item-db-id' => $menu_item_db_id, 'menu-item-object-id' => 0, @@ -305,8 +301,9 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item if ( 0 == $menu_id ) { $args['menu-item-position'] = 1; } elseif ( 0 == (int) $args['menu-item-position'] ) { + $menu_items = 0 == $menu_id ? array() : (array) wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) ); $last_item = array_pop( $menu_items ); - $args['menu-item-position'] = ( $last_item && isset( $last_item->menu_order ) ) ? 1 + $last_item->menu_order : $count; + $args['menu-item-position'] = ( $last_item && isset( $last_item->menu_order ) ) ? 1 + $last_item->menu_order : count( $menu_items ); } $original_parent = 0 < $menu_item_db_id ? get_post_field( 'post_parent', $menu_item_db_id ) : 0; @@ -350,20 +347,19 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item 'post_type' => 'nav_menu_item', ); - if ( 0 != $menu_id ) + $update = 0 != $menu_item_db_id; + + // Only set the menu term if it isn't set to avoid unnecessary wp_get_object_terms() + if ( $menu_id && ( ! $update || ! is_object_in_term( $menu_item_db_id, 'nav_menu', (int) $menu->term_id ) ) ) $post['tax_input'] = array( 'nav_menu' => array( intval( $menu->term_id ) ) ); // New menu item. Default is draft status - if ( 0 == $menu_item_db_id ) { + if ( ! $update ) { $post['ID'] = 0; $post['post_status'] = 'publish' == $args['menu-item-status'] ? 'publish' : 'draft'; $menu_item_db_id = wp_insert_post( $post ); - - // Update existing menu item. Default is publish status - } else { - $post['ID'] = $menu_item_db_id; - $post['post_status'] = 'draft' == $args['menu-item-status'] ? 'draft' : 'publish'; - wp_update_post( $post ); + if ( ! $menu_item_db_id || is_wp_error( $menu_item_db_id ) ) + return $menu_item_db_id; } if ( 'custom' == $args['menu-item-type'] ) { @@ -371,14 +367,11 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item $args['menu-item-object'] = 'custom'; } - if ( ! $menu_item_db_id || is_wp_error( $menu_item_db_id ) ) - return $menu_item_db_id; - $menu_item_db_id = (int) $menu_item_db_id; update_post_meta( $menu_item_db_id, '_menu_item_type', sanitize_key($args['menu-item-type']) ); - update_post_meta( $menu_item_db_id, '_menu_item_menu_item_parent', (int) $args['menu-item-parent-id'] ); - update_post_meta( $menu_item_db_id, '_menu_item_object_id', (int) $args['menu-item-object-id'] ); + update_post_meta( $menu_item_db_id, '_menu_item_menu_item_parent', strval( (int) $args['menu-item-parent-id'] ) ); + update_post_meta( $menu_item_db_id, '_menu_item_object_id', strval( (int) $args['menu-item-object-id'] ) ); update_post_meta( $menu_item_db_id, '_menu_item_object', sanitize_key($args['menu-item-object']) ); update_post_meta( $menu_item_db_id, '_menu_item_target', sanitize_key($args['menu-item-target']) ); @@ -389,10 +382,17 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item update_post_meta( $menu_item_db_id, '_menu_item_url', esc_url_raw($args['menu-item-url']) ); if ( 0 == $menu_id ) - update_post_meta( $menu_item_db_id, '_menu_item_orphaned', time() ); - else + update_post_meta( $menu_item_db_id, '_menu_item_orphaned', (string) time() ); + elseif ( get_post_meta( $menu_item_db_id, '_menu_item_orphaned' ) ) delete_post_meta( $menu_item_db_id, '_menu_item_orphaned' ); + // Update existing menu item. Default is publish status + if ( $update ) { + $post['ID'] = $menu_item_db_id; + $post['post_status'] = 'draft' == $args['menu-item-status'] ? 'draft' : 'publish'; + wp_update_post( $post ); + } + do_action('wp_update_nav_menu_item', $menu_id, $menu_item_db_id, $args ); return $menu_item_db_id; @@ -483,8 +483,7 @@ function wp_get_nav_menu_items( $menu, $args = array() ) { return $items; $defaults = array( 'order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item', - 'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true, - 'update_post_term_cache' => false ); + 'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true ); $args = wp_parse_args( $args, $defaults ); if ( count( $items ) > 1 ) $args['include'] = implode( ',', $items ); diff --git a/wp-includes/option.php b/wp-includes/option.php index 33897b60..722d1f30 100644 --- a/wp-includes/option.php +++ b/wp-includes/option.php @@ -32,15 +32,15 @@ function get_option( $option, $default = false ) { global $wpdb; + $option = trim( $option ); + if ( empty( $option ) ) + return false; + // Allow plugins to short-circuit options. $pre = apply_filters( 'pre_option_' . $option, false ); if ( false !== $pre ) return $pre; - $option = trim($option); - if ( empty($option) ) - return false; - if ( defined( 'WP_SETUP_CONFIG' ) ) return false; @@ -174,7 +174,7 @@ function wp_load_core_site_options( $site_id = null ) { if ( empty($site_id) ) $site_id = $wpdb->siteid; - $core_options = array('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled' ); + $core_options = array('site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled', 'ms_files_rewriting' ); $core_options_in = "'" . implode("', '", $core_options) . "'"; $options = $wpdb->get_results( $wpdb->prepare("SELECT meta_key, meta_value FROM $wpdb->sitemeta WHERE meta_key IN ($core_options_in) AND site_id = %d", $site_id) ); @@ -540,6 +540,11 @@ function wp_user_settings() { if ( ! $user = wp_get_current_user() ) return; + if ( is_super_admin( $user->ID ) && + ! in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user->ID ) ) ) + ) + return; + $settings = get_user_option( 'user-settings', $user->ID ); if ( isset( $_COOKIE['wp-settings-' . $user->ID] ) ) { @@ -560,8 +565,8 @@ function wp_user_settings() { } } - setcookie( 'wp-settings-' . $user->ID, $settings, time() + 31536000, SITECOOKIEPATH ); - setcookie( 'wp-settings-time-' . $user->ID, time(), time() + 31536000, SITECOOKIEPATH ); + setcookie( 'wp-settings-' . $user->ID, $settings, time() + YEAR_IN_SECONDS, SITECOOKIEPATH ); + setcookie( 'wp-settings-time-' . $user->ID, time(), time() + YEAR_IN_SECONDS, SITECOOKIEPATH ); $_COOKIE['wp-settings-' . $user->ID] = $settings; } @@ -697,6 +702,11 @@ function wp_set_all_user_settings($all) { if ( ! $user = wp_get_current_user() ) return false; + if ( is_super_admin( $user->ID ) && + ! in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user->ID ) ) ) + ) + return; + $_updated_user_settings = $all; $settings = ''; foreach ( $all as $k => $v ) { @@ -724,7 +734,7 @@ function delete_all_user_settings() { return; update_user_option( $user->ID, 'user-settings', '', false ); - setcookie('wp-settings-' . $user->ID, ' ', time() - 31536000, SITECOOKIEPATH); + setcookie('wp-settings-' . $user->ID, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH); } /** diff --git a/wp-includes/pluggable-deprecated.php b/wp-includes/pluggable-deprecated.php index 2a202ace..69e78f5f 100644 --- a/wp-includes/pluggable-deprecated.php +++ b/wp-includes/pluggable-deprecated.php @@ -168,3 +168,25 @@ function wp_login($username, $password, $deprecated = '') { else : _deprecated_function( 'wp_login', '2.5', 'wp_signon()' ); endif; + +/** + * WordPress AtomPub API implementation. + * + * Originally stored in wp-app.php, and later wp-includes/class-wp-atom-server.php. + * It is kept here in case a plugin directly referred to the class. + * + * @since 2.2.0 + * @deprecated 3.5.0 + * @link http://wordpress.org/extend/plugins/atom-publishing-protocol/ + */ +if ( ! class_exists( 'wp_atom_server' ) ) { + class wp_atom_server { + public function __call( $name, $arguments ) { + _deprecated_function( __CLASS__ . '::' . $name, '3.5', 'the Atom Publishing Platform plugin' ); + } + + public static function __callStatic( $name, $arguments ) { + _deprecated_function( __CLASS__ . '::' . $name, '3.5', 'the Atom Publishing Platform plugin' ); + } + } +} \ No newline at end of file diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php index ac308a99..37ddb83f 100644 --- a/wp-includes/pluggable.php +++ b/wp-includes/pluggable.php @@ -529,7 +529,7 @@ function wp_validate_auth_cookie($cookie = '', $scheme = '') { // Allow a grace period for POST and AJAX requests if ( defined('DOING_AJAX') || 'POST' == $_SERVER['REQUEST_METHOD'] ) - $expired += 3600; + $expired += HOUR_IN_SECONDS; // Quick check to see if an honest cookie has expired if ( $expired < time() ) { @@ -694,24 +694,24 @@ if ( !function_exists('wp_clear_auth_cookie') ) : function wp_clear_auth_cookie() { do_action('clear_auth_cookie'); - setcookie(AUTH_COOKIE, ' ', time() - 31536000, ADMIN_COOKIE_PATH, COOKIE_DOMAIN); - setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, ADMIN_COOKIE_PATH, COOKIE_DOMAIN); - setcookie(AUTH_COOKIE, ' ', time() - 31536000, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN); - setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN); - setcookie(LOGGED_IN_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN); - setcookie(LOGGED_IN_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN); + setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN ); + setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN ); + setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN ); + setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN ); + setcookie( LOGGED_IN_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN ); + setcookie( LOGGED_IN_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN ); // Old cookies - setcookie(AUTH_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN); - setcookie(AUTH_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN); - setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN); - setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN); + setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN ); + setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN ); + setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN ); + setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN ); // Even older cookies - setcookie(USER_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN); - setcookie(PASS_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN); - setcookie(USER_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN); - setcookie(PASS_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN); + setcookie( USER_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN ); + setcookie( PASS_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN ); + setcookie( USER_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN ); + setcookie( PASS_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN ); } endif; @@ -748,11 +748,11 @@ function auth_redirect() { // If https is required and request is http, redirect if ( $secure && !is_ssl() && false !== strpos($_SERVER['REQUEST_URI'], 'wp-admin') ) { - if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) { - wp_redirect(preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI'])); + if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) { + wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) ); exit(); } else { - wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); + wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); exit(); } } @@ -767,11 +767,11 @@ function auth_redirect() { // If the user wants ssl but the session is not ssl, redirect. if ( !$secure && get_user_option('use_ssl', $user_id) && false !== strpos($_SERVER['REQUEST_URI'], 'wp-admin') ) { - if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) { - wp_redirect(preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI'])); + if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) { + wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) ); exit(); } else { - wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); + wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); exit(); } } @@ -782,12 +782,7 @@ function auth_redirect() { // The cookie is no good so force login nocache_headers(); - if ( is_ssl() ) - $proto = 'https://'; - else - $proto = 'http://'; - - $redirect = ( strpos($_SERVER['REQUEST_URI'], '/options.php') && wp_get_referer() ) ? wp_get_referer() : $proto . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; + $redirect = ( strpos( $_SERVER['REQUEST_URI'], '/options.php' ) && wp_get_referer() ) ? wp_get_referer() : set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); $login_url = wp_login_url($redirect, true); @@ -1195,7 +1190,7 @@ if ( !function_exists('wp_new_user_notification') ) : * @param string $plaintext_pass Optional. The user's plaintext password */ function wp_new_user_notification($user_id, $plaintext_pass = '') { - $user = new WP_User($user_id); + $user = get_userdata( $user_id ); $user_login = stripslashes($user->user_login); $user_email = stripslashes($user->user_email); @@ -1234,7 +1229,7 @@ if ( !function_exists('wp_nonce_tick') ) : * @return int */ function wp_nonce_tick() { - $nonce_life = apply_filters('nonce_life', 86400); + $nonce_life = apply_filters( 'nonce_life', DAY_IN_SECONDS ); return ceil(time() / ( $nonce_life / 2 )); } @@ -1256,6 +1251,8 @@ if ( !function_exists('wp_verify_nonce') ) : function wp_verify_nonce($nonce, $action = -1) { $user = wp_get_current_user(); $uid = (int) $user->ID; + if ( ! $uid ) + $uid = apply_filters( 'nonce_user_logged_out', $uid, $action ); $i = wp_nonce_tick(); @@ -1282,6 +1279,8 @@ if ( !function_exists('wp_create_nonce') ) : function wp_create_nonce($action = -1) { $user = wp_get_current_user(); $uid = (int) $user->ID; + if ( ! $uid ) + $uid = apply_filters( 'nonce_user_logged_out', $uid, $action ); $i = wp_nonce_tick(); @@ -1501,13 +1500,13 @@ function wp_generate_password( $length = 12, $special_chars = true, $extra_speci endif; if ( !function_exists('wp_rand') ) : - /** +/** * Generates a random number * * @since 2.6.2 * - * @param int $min Lower limit for the generated number (optional, default is 0) - * @param int $max Upper limit for the generated number (optional, default is 4294967295) + * @param int $min Lower limit for the generated number + * @param int $max Upper limit for the generated number * @return int A random number between min and max */ function wp_rand( $min = 0, $max = 0 ) { @@ -1536,10 +1535,12 @@ function wp_rand( $min = 0, $max = 0 ) { $value = abs(hexdec($value)); + // Some misconfigured 32bit environments (Entropy PHP, for example) truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats. + $max_random_number = 3000000000 === 2147483647 ? (float) "4294967295" : 4294967295; // 4294967295 = 0xffffffff + // Reduce the value to be within the min - max range - // 4294967295 = 0xffffffff = max random number if ( $max != 0 ) - $value = $min + (($max - $min + 1) * ($value / (4294967295 + 1))); + $value = $min + ( $max - $min + 1 ) * $value / ( $max_random_number + 1 ); return abs(intval($value)); } @@ -1577,7 +1578,7 @@ if ( !function_exists( 'get_avatar' ) ) : * @param int|string|object $id_or_email A user ID, email address, or comment object * @param int $size Size of the avatar image * @param string $default URL to a default image to use if no avatar is available - * @param string $alt Alternate text to use in image tag. Defaults to blank + * @param string $alt Alternative text to use in image tag. Defaults to blank * @return string tag for the user's avatar */ function get_avatar( $id_or_email, $size = '96', $default = '', $alt = false ) { @@ -1639,7 +1640,7 @@ function get_avatar( $id_or_email, $size = '96', $default = '', $alt = false ) { if ( 'mystery' == $default ) $default = "$host/avatar/ad516503a11cd5ca435acc9bb6523536?s={$size}"; // ad516503a11cd5ca435acc9bb6523536 == md5('unknown@gravatar.com') elseif ( 'blank' == $default ) - $default = includes_url('images/blank.gif'); + $default = $email ? 'blank' : includes_url( 'images/blank.gif' ); elseif ( !empty($email) && 'gravatar_default' == $default ) $default = ''; elseif ( 'gravatar_default' == $default ) diff --git a/wp-includes/plugin.php b/wp-includes/plugin.php index 914d7065..7e387080 100644 --- a/wp-includes/plugin.php +++ b/wp-includes/plugin.php @@ -80,8 +80,11 @@ function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) * @global array $wp_filter Stores all of the filters * * @param string $tag The name of the filter hook. - * @param callback $function_to_check optional. If specified, return the priority of that function on this hook or false if not attached. - * @return int|boolean Optionally returns the priority on that hook for the specified function. + * @param callback $function_to_check optional. + * @return mixed If $function_to_check is omitted, returns boolean for whether the hook has anything registered. + * When checking a specific function, the priority of that hook is returned, or false if the function is not attached. + * When using the $function_to_check argument, this function may return a non-boolean value that evaluates to false + * (e.g.) 0, so use the === operator for testing the return value. */ function has_filter($tag, $function_to_check = false) { global $wp_filter; @@ -254,7 +257,7 @@ function apply_filters_ref_array($tag, $args) { * @param int $accepted_args optional. The number of arguments the function accepts (default: 1). * @return boolean Whether the function existed before it was removed. */ -function remove_filter($tag, $function_to_remove, $priority = 10, $accepted_args = 1) { +function remove_filter( $tag, $function_to_remove, $priority = 10 ) { $function_to_remove = _wp_filter_build_unique_id($tag, $function_to_remove, $priority); $r = isset($GLOBALS['wp_filter'][$tag][$priority][$function_to_remove]); @@ -497,8 +500,11 @@ function do_action_ref_array($tag, $args) { * @see has_filter() has_action() is an alias of has_filter(). * * @param string $tag The name of the action hook. - * @param callback $function_to_check optional. If specified, return the priority of that function on this hook or false if not attached. - * @return int|boolean Optionally returns the priority on that hook for the specified function. + * @param callback $function_to_check optional. + * @return mixed If $function_to_check is omitted, returns boolean for whether the hook has anything registered. + * When checking a specific function, the priority of that hook is returned, or false if the function is not attached. + * When using the $function_to_check argument, this function may return a non-boolean value that evaluates to false + * (e.g.) 0, so use the === operator for testing the return value. */ function has_action($tag, $function_to_check = false) { return has_filter($tag, $function_to_check); @@ -518,11 +524,10 @@ function has_action($tag, $function_to_check = false) { * @param string $tag The action hook to which the function to be removed is hooked. * @param callback $function_to_remove The name of the function which should be removed. * @param int $priority optional The priority of the function (default: 10). - * @param int $accepted_args optional. The number of arguments the function accepts (default: 1). * @return boolean Whether the function is removed. */ -function remove_action($tag, $function_to_remove, $priority = 10, $accepted_args = 1) { - return remove_filter($tag, $function_to_remove, $priority, $accepted_args); +function remove_action( $tag, $function_to_remove, $priority = 10 ) { + return remove_filter( $tag, $function_to_remove, $priority ); } /** diff --git a/wp-includes/pomo/entry.php b/wp-includes/pomo/entry.php index 6432dbed..097e92ca 100644 --- a/wp-includes/pomo/entry.php +++ b/wp-includes/pomo/entry.php @@ -2,7 +2,7 @@ /** * Contains Translation_Entry class * - * @version $Id: entry.php 621 2011-06-13 12:21:50Z nbachiyski $ + * @version $Id: entry.php 718 2012-10-31 00:32:02Z nbachiyski $ * @package pomo * @subpackage entry */ @@ -65,14 +65,14 @@ class Translation_Entry { // prepend context and EOT, like in MO files return is_null($this->context)? $this->singular : $this->context.chr(4).$this->singular; } - + function merge_with(&$other) { $this->flags = array_unique( array_merge( $this->flags, $other->flags ) ); $this->references = array_unique( array_merge( $this->references, $other->references ) ); if ( $this->extracted_comments != $other->extracted_comments ) { $this->extracted_comments .= $other->extracted_comments; } - + } } endif; \ No newline at end of file diff --git a/wp-includes/pomo/mo.php b/wp-includes/pomo/mo.php index d76cda5c..68c0792f 100644 --- a/wp-includes/pomo/mo.php +++ b/wp-includes/pomo/mo.php @@ -2,7 +2,7 @@ /** * Class for working with MO files * - * @version $Id: mo.php 602 2011-01-30 12:43:29Z nbachiyski $ + * @version $Id: mo.php 718 2012-10-31 00:32:02Z nbachiyski $ * @package pomo * @subpackage mo */ @@ -34,7 +34,7 @@ class MO extends Gettext_Translations { fclose($fh); return $res; } - + function export() { $tmp_fh = fopen("php://temp", 'r+'); if ( !$tmp_fh ) return false; @@ -42,9 +42,21 @@ class MO extends Gettext_Translations { rewind( $tmp_fh ); return stream_get_contents( $tmp_fh ); } - + + function is_entry_good_for_export( $entry ) { + if ( empty( $entry->translations ) ) { + return false; + } + + if ( !array_filter( $entry->translations ) ) { + return false; + } + + return true; + } + function export_to_file_handle($fh) { - $entries = array_filter($this->entries, create_function('$e', 'return !empty($e->translations);')); + $entries = array_filter( $this->entries, array( $this, 'is_entry_good_for_export' ) ); ksort($entries); $magic = 0x950412de; $revision = 0; @@ -57,7 +69,7 @@ class MO extends Gettext_Translations { fwrite($fh, pack('V*', $magic, $revision, $total, $originals_lenghts_addr, $translations_lenghts_addr, $size_of_hash, $hash_addr)); fseek($fh, $originals_lenghts_addr); - + // headers' msgid is an empty string fwrite($fh, pack('VV', 0, $current_addr)); $current_addr++; @@ -69,24 +81,24 @@ class MO extends Gettext_Translations { fwrite($fh, pack('VV', $length, $current_addr)); $current_addr += $length + 1; // account for the NULL byte after } - + $exported_headers = $this->export_headers(); fwrite($fh, pack('VV', strlen($exported_headers), $current_addr)); $current_addr += strlen($exported_headers) + 1; $translations_table = $exported_headers . chr(0); - + foreach($entries as $entry) { $translations_table .= $this->export_translations($entry) . chr(0); $length = strlen($this->export_translations($entry)); fwrite($fh, pack('VV', $length, $current_addr)); $current_addr += $length + 1; } - + fwrite($fh, $originals_table); fwrite($fh, $translations_table); return true; } - + function export_original($entry) { //TODO: warnings for control characters $exported = $entry->singular; @@ -94,12 +106,12 @@ class MO extends Gettext_Translations { if (!is_null($entry->context)) $exported = $entry->context . chr(4) . $exported; return $exported; } - + function export_translations($entry) { //TODO: warnings for control characters return implode(chr(0), $entry->translations); } - + function export_headers() { $exported = ''; foreach($this->headers as $header => $value) { @@ -195,8 +207,7 @@ class MO extends Gettext_Translations { $translation = $reader->substr( $strings, $t['pos'], $t['length'] ); if ('' === $original) { - $headers = $this->make_headers($translation); - $this->set_headers($headers); + $this->set_headers($this->make_headers($translation)); } else { $entry = &$this->make_entry($original, $translation); $this->entries[$entry->key()] = &$entry; @@ -208,7 +219,7 @@ class MO extends Gettext_Translations { /** * Build a Translation_Entry from original string and translation strings, * found in a MO file - * + * * @static * @param string $original original string to translate from MO file. Might contain * 0x04 as context separator or 0x00 as singular/plural separator diff --git a/wp-includes/pomo/po.php b/wp-includes/pomo/po.php index 8320bc1e..f76be011 100644 --- a/wp-includes/pomo/po.php +++ b/wp-includes/pomo/po.php @@ -2,7 +2,7 @@ /** * Class for working with PO files * - * @version $Id: po.php 589 2010-12-18 01:40:57Z nbachiyski $ + * @version $Id: po.php 718 2012-10-31 00:32:02Z nbachiyski $ * @package pomo * @subpackage po */ @@ -18,7 +18,7 @@ ini_set('auto_detect_line_endings', 1); */ if ( !class_exists( 'PO' ) ): class PO extends Gettext_Translations { - + var $comments_before_headers = ''; /** @@ -80,10 +80,10 @@ class PO extends Gettext_Translations { if (false === $res) return false; return fclose($fh); } - + /** * Text to include as a comment before the start of the PO contents - * + * * Doesn't need to include # in the beginning of lines, these are added automatically */ function set_comment_before_headers( $text ) { @@ -120,10 +120,10 @@ class PO extends Gettext_Translations { $po = str_replace("$newline$quote$quote", '', $po); return $po; } - + /** * Gives back the original string from a PO-formatted string - * + * * @static * @param string $string PO-formatted string * @return string enascaped string @@ -153,7 +153,7 @@ class PO extends Gettext_Translations { } /** - * Inserts $with in the beginning of every new line of $string and + * Inserts $with in the beginning of every new line of $string and * returns the modified string * * @static @@ -229,9 +229,15 @@ class PO extends Gettext_Translations { } } PO::read_line($f, 'clear'); - return $res !== false; + if ( false === $res ) { + return false; + } + if ( ! $this->headers && ! $this->entries ) { + return false; + } + return true; } - + function read_entry($f, $lineno = 0) { $entry = new Translation_Entry(); // where were we in the last step @@ -336,7 +342,7 @@ class PO extends Gettext_Translations { } return array('entry' => $entry, 'lineno' => $lineno); } - + function read_line($f, $action = 'read') { static $last_line = ''; static $use_last_line = false; @@ -349,11 +355,12 @@ class PO extends Gettext_Translations { return true; } $line = $use_last_line? $last_line : fgets($f); + $line = ( "\r\n" == substr( $line, -2 ) ) ? rtrim( $line, "\r\n" ) . "\n" : $line; $last_line = $line; $use_last_line = false; return $line; } - + function add_comment_to_entry(&$entry, $po_comment_line) { $first_two = substr($po_comment_line, 0, 2); $comment = trim(substr($po_comment_line, 2)); @@ -367,11 +374,11 @@ class PO extends Gettext_Translations { $entry->translator_comments = trim($entry->translator_comments . "\n" . $comment); } } - + function trim_quotes($s) { if ( substr($s, 0, 1) == '"') $s = substr($s, 1); if ( substr($s, -1, 1) == '"') $s = substr($s, 0, -1); return $s; } } -endif; \ No newline at end of file +endif; diff --git a/wp-includes/pomo/streams.php b/wp-includes/pomo/streams.php index efaffa5a..dbb1de80 100644 --- a/wp-includes/pomo/streams.php +++ b/wp-includes/pomo/streams.php @@ -3,22 +3,22 @@ * Classes, which help reading streams of data from files. * Based on the classes from Danilo Segan * - * @version $Id: streams.php 597 2011-01-16 20:14:36Z nbachiyski $ + * @version $Id: streams.php 718 2012-10-31 00:32:02Z nbachiyski $ * @package pomo * @subpackage streams */ if ( !class_exists( 'POMO_Reader' ) ): class POMO_Reader { - + var $endian = 'little'; var $_post = ''; - + function POMO_Reader() { $this->is_overloaded = ((ini_get("mbstring.func_overload") & 2) != 0) && function_exists('mb_substr'); $this->_pos = 0; } - + /** * Sets the endianness of the file. * @@ -57,8 +57,8 @@ class POMO_Reader { $endian_letter = ('big' == $this->endian)? 'N' : 'V'; return unpack($endian_letter.$count, $bytes); } - - + + function substr($string, $start, $length) { if ($this->is_overloaded) { return mb_substr($string, $start, $length, 'ascii'); @@ -66,7 +66,7 @@ class POMO_Reader { return substr($string, $start, $length); } } - + function strlen($string) { if ($this->is_overloaded) { return mb_strlen($string, 'ascii'); @@ -74,7 +74,7 @@ class POMO_Reader { return strlen($string); } } - + function str_split($string, $chunk_size) { if (!function_exists('str_split')) { $length = $this->strlen($string); @@ -86,8 +86,8 @@ class POMO_Reader { return str_split( $string, $chunk_size ); } } - - + + function pos() { return $this->_pos; } @@ -95,7 +95,7 @@ class POMO_Reader { function is_resource() { return true; } - + function close() { return true; } @@ -108,11 +108,11 @@ class POMO_FileReader extends POMO_Reader { parent::POMO_Reader(); $this->_f = fopen($filename, 'rb'); } - + function read($bytes) { return fread($this->_f, $bytes); } - + function seekto($pos) { if ( -1 == fseek($this->_f, $pos, SEEK_SET)) { return false; @@ -120,19 +120,19 @@ class POMO_FileReader extends POMO_Reader { $this->_pos = $pos; return true; } - + function is_resource() { return is_resource($this->_f); } - + function feof() { return feof($this->_f); } - + function close() { return fclose($this->_f); } - + function read_all() { $all = ''; while ( !$this->feof() ) @@ -148,9 +148,9 @@ if ( !class_exists( 'POMO_StringReader' ) ): * of a physical file. */ class POMO_StringReader extends POMO_Reader { - + var $_str = ''; - + function POMO_StringReader($str = '') { parent::POMO_Reader(); $this->_str = $str; @@ -178,7 +178,7 @@ class POMO_StringReader extends POMO_Reader { function read_all() { return $this->substr($this->_str, $this->_pos, $this->strlen($this->_str)); } - + } endif; diff --git a/wp-includes/pomo/translations.php b/wp-includes/pomo/translations.php index 951583ac..856e38aa 100644 --- a/wp-includes/pomo/translations.php +++ b/wp-includes/pomo/translations.php @@ -2,7 +2,7 @@ /** * Class for a set of entries for translation and their associated headers * - * @version $Id: translations.php 590 2010-12-20 19:58:37Z nbachiyski $ + * @version $Id: translations.php 718 2012-10-31 00:32:02Z nbachiyski $ * @package pomo * @subpackage translations */ @@ -29,7 +29,7 @@ class Translations { $this->entries[$key] = &$entry; return true; } - + function add_entry_or_merge($entry) { if (is_array($entry)) { $entry = new Translation_Entry($entry); @@ -121,7 +121,7 @@ class Translations { $this->entries[$entry->key()] = $entry; } } - + function merge_originals_with(&$other) { foreach( $other->entries as $entry ) { if ( !isset( $this->entries[$entry->key()] ) ) @@ -134,7 +134,7 @@ class Translations { class Gettext_Translations extends Translations { /** - * The gettext implmentation of select_plural_form. + * The gettext implementation of select_plural_form. * * It lives in this class, because there are more than one descendand, which will use it and * they can't share it effectively. @@ -148,7 +148,7 @@ class Gettext_Translations extends Translations { } return call_user_func($this->_gettext_select_plural_form, $count); } - + function nplurals_and_expression_from_header($header) { if (preg_match('/^\s*nplurals\s*=\s*(\d+)\s*;\s+plural\s*=\s*(.+)$/', $header, $matches)) { $nplurals = (int)$matches[1]; @@ -174,7 +174,7 @@ class Gettext_Translations extends Translations { /** * Adds parantheses to the inner parts of ternary operators in * plural expressions, because PHP evaluates ternary oerators from left to right - * + * * @param string $expression the expression without parentheses * @return string the expression with parentheses added */ @@ -202,7 +202,7 @@ class Gettext_Translations extends Translations { } return rtrim($res, ';'); } - + function make_headers($translation) { $headers = array(); // sometimes \ns are used instead of real new lines @@ -215,7 +215,7 @@ class Gettext_Translations extends Translations { } return $headers; } - + function set_header($header, $value) { parent::set_header($header, $value); if ('Plural-Forms' == $header) { @@ -234,7 +234,7 @@ if ( !class_exists( 'NOOP_Translations' ) ): class NOOP_Translations { var $entries = array(); var $headers = array(); - + function add_entry($entry) { return true; } diff --git a/wp-includes/post-template.php b/wp-includes/post-template.php index b5b8847e..21620b45 100644 --- a/wp-includes/post-template.php +++ b/wp-includes/post-template.php @@ -26,8 +26,7 @@ function the_ID() { * @return int */ function get_the_ID() { - global $post; - return $post->ID; + return get_post()->ID; } /** @@ -97,24 +96,25 @@ function the_title_attribute( $args = '' ) { * * @since 0.71 * - * @param int $id Optional. Post ID. + * @param mixed $post Optional. Post ID or object. * @return string */ -function get_the_title( $id = 0 ) { - $post = &get_post($id); - - $title = isset($post->post_title) ? $post->post_title : ''; - $id = isset($post->ID) ? $post->ID : (int) $id; - - if ( !is_admin() ) { - if ( !empty($post->post_password) ) { - $protected_title_format = apply_filters('protected_title_format', __('Protected: %s')); - $title = sprintf($protected_title_format, $title); - } else if ( isset($post->post_status) && 'private' == $post->post_status ) { - $private_title_format = apply_filters('private_title_format', __('Private: %s')); - $title = sprintf($private_title_format, $title); +function get_the_title( $post = 0 ) { + $post = get_post( $post ); + + $title = isset( $post->post_title ) ? $post->post_title : ''; + $id = isset( $post->ID ) ? $post->ID : 0; + + if ( ! is_admin() ) { + if ( ! empty( $post->post_password ) ) { + $protected_title_format = apply_filters( 'protected_title_format', __( 'Protected: %s' ) ); + $title = sprintf( $protected_title_format, $title ); + } else if ( isset( $post->post_status ) && 'private' == $post->post_status ) { + $private_title_format = apply_filters( 'private_title_format', __( 'Private: %s' ) ); + $title = sprintf( $private_title_format, $title ); } } + return apply_filters( 'the_title', $title, $id ); } @@ -148,7 +148,7 @@ function the_guid( $id = 0 ) { * @return string */ function get_the_guid( $id = 0 ) { - $post = &get_post($id); + $post = get_post($id); return apply_filters('get_the_guid', $post->guid); } @@ -177,8 +177,10 @@ function the_content($more_link_text = null, $stripteaser = false) { * @param bool $stripteaser Optional. Strip teaser content before the more text. Default is false. * @return string */ -function get_the_content($more_link_text = null, $stripteaser = false) { - global $post, $more, $page, $pages, $multipage, $preview; +function get_the_content( $more_link_text = null, $stripteaser = false ) { + global $more, $page, $pages, $multipage, $preview; + + $post = get_post(); if ( null === $more_link_text ) $more_link_text = __( '(more...)' ); @@ -187,7 +189,7 @@ function get_the_content($more_link_text = null, $stripteaser = false) { $hasTeaser = false; // If post password required and it doesn't match the cookie. - if ( post_password_required($post) ) + if ( post_password_required() ) return get_the_password_form(); if ( $page > count($pages) ) // if the requested page doesn't exist @@ -231,7 +233,7 @@ function get_the_content($more_link_text = null, $stripteaser = false) { * @since 3.1.0 * @access private * @param array $match Match array from preg_replace_callback - * @returns string + * @return string */ function _convert_urlencoded_to_entities( $match ) { return '&#' . base_convert( $match[1], 16, 10 ) . ';'; @@ -259,14 +261,13 @@ function get_the_excerpt( $deprecated = '' ) { if ( !empty( $deprecated ) ) _deprecated_argument( __FUNCTION__, '2.3' ); - global $post; - $output = $post->post_excerpt; - if ( post_password_required($post) ) { - $output = __('There is no excerpt because this is a protected post.'); - return $output; + $post = get_post(); + + if ( post_password_required() ) { + return __( 'There is no excerpt because this is a protected post.' ); } - return apply_filters('get_the_excerpt', $output); + return apply_filters( 'get_the_excerpt', $post->post_excerpt ); } /** @@ -278,7 +279,7 @@ function get_the_excerpt( $deprecated = '' ) { * @return bool */ function has_excerpt( $id = 0 ) { - $post = &get_post( $id ); + $post = get_post( $id ); return ( !empty( $post->post_excerpt ) ); } @@ -321,7 +322,8 @@ function get_post_class( $class = '', $post_id = null ) { return $classes; $classes[] = 'post-' . $post->ID; - $classes[] = $post->post_type; + if ( ! is_admin() ) + $classes[] = $post->post_type; $classes[] = 'type-' . $post->post_type; $classes[] = 'status-' . $post->post_status; @@ -427,17 +429,19 @@ function get_body_class( $class = '' ) { $post = $wp_query->get_queried_object(); $classes[] = 'single'; - $classes[] = 'single-' . sanitize_html_class($post->post_type, $post_id); - $classes[] = 'postid-' . $post_id; - - // Post Format - if ( post_type_supports( $post->post_type, 'post-formats' ) ) { - $post_format = get_post_format( $post->ID ); - - if ( $post_format && !is_wp_error($post_format) ) - $classes[] = 'single-format-' . sanitize_html_class( $post_format ); - else - $classes[] = 'single-format-standard'; + if ( isset( $post->post_type ) ) { + $classes[] = 'single-' . sanitize_html_class($post->post_type, $post_id); + $classes[] = 'postid-' . $post_id; + + // Post Format + if ( post_type_supports( $post->post_type, 'post-formats' ) ) { + $post_format = get_post_format( $post->ID ); + + if ( $post_format && !is_wp_error($post_format) ) + $classes[] = 'single-format-' . sanitize_html_class( $post_format ); + else + $classes[] = 'single-format-standard'; + } } if ( is_attachment() ) { @@ -453,30 +457,38 @@ function get_body_class( $class = '' ) { } else if ( is_author() ) { $author = $wp_query->get_queried_object(); $classes[] = 'author'; - $classes[] = 'author-' . sanitize_html_class( $author->user_nicename , $author->ID ); - $classes[] = 'author-' . $author->ID; + if ( isset( $author->user_nicename ) ) { + $classes[] = 'author-' . sanitize_html_class( $author->user_nicename, $author->ID ); + $classes[] = 'author-' . $author->ID; + } } elseif ( is_category() ) { $cat = $wp_query->get_queried_object(); $classes[] = 'category'; - $classes[] = 'category-' . sanitize_html_class( $cat->slug, $cat->term_id ); - $classes[] = 'category-' . $cat->term_id; + if ( isset( $cat->term_id ) ) { + $classes[] = 'category-' . sanitize_html_class( $cat->slug, $cat->term_id ); + $classes[] = 'category-' . $cat->term_id; + } } elseif ( is_tag() ) { $tags = $wp_query->get_queried_object(); $classes[] = 'tag'; - $classes[] = 'tag-' . sanitize_html_class( $tags->slug, $tags->term_id ); - $classes[] = 'tag-' . $tags->term_id; + if ( isset( $tags->term_id ) ) { + $classes[] = 'tag-' . sanitize_html_class( $tags->slug, $tags->term_id ); + $classes[] = 'tag-' . $tags->term_id; + } } elseif ( is_tax() ) { $term = $wp_query->get_queried_object(); - $classes[] = 'tax-' . sanitize_html_class( $term->taxonomy ); - $classes[] = 'term-' . sanitize_html_class( $term->slug, $term->term_id ); - $classes[] = 'term-' . $term->term_id; + if ( isset( $term->term_id ) ) { + $classes[] = 'tax-' . sanitize_html_class( $term->taxonomy ); + $classes[] = 'term-' . sanitize_html_class( $term->slug, $term->term_id ); + $classes[] = 'term-' . $term->term_id; + } } } elseif ( is_page() ) { $classes[] = 'page'; $page_id = $wp_query->get_queried_object_id(); - $post = get_page($page_id); + $post = get_post($page_id); $classes[] = 'page-id-' . $page_id; @@ -498,8 +510,10 @@ function get_body_class( $class = '' ) { if ( is_user_logged_in() ) $classes[] = 'logged-in'; - if ( is_admin_bar_showing() ) + if ( is_admin_bar_showing() ) { $classes[] = 'admin-bar'; + $classes[] = 'no-customize-support'; + } if ( get_theme_mod( 'background_color' ) || get_background_image() ) $classes[] = 'custom-background'; @@ -574,20 +588,6 @@ function post_password_required( $post = null ) { return ! $wp_hasher->CheckPassword( $post->post_password, $hash ); } -/** - * Display "sticky" CSS class, if a post is sticky. - * - * @since 2.7.0 - * - * @param int $post_id An optional post ID. - */ -function sticky_class( $post_id = null ) { - if ( !is_sticky($post_id) ) - return; - - echo " sticky"; -} - /** * Page Template Functions for usage in Themes * @@ -692,7 +692,8 @@ function wp_link_pages($args = '') { * @return string Link. */ function _wp_link_page( $i ) { - global $post, $wp_rewrite; + global $wp_rewrite; + $post = get_post(); if ( 1 == $i ) { $url = get_permalink(); @@ -881,6 +882,7 @@ function wp_list_pages($args = '') { * @since 2.7.0 * * @param array|string $args + * @return string html menu */ function wp_page_menu( $args = array() ) { $defaults = array('sort_column' => 'menu_order, post_title', 'menu_class' => 'menu', 'echo' => true, 'link_before' => '', 'link_after' => ''); @@ -945,7 +947,7 @@ function walk_page_tree($pages, $depth, $current_page, $r) { $walker = $r['walker']; $args = array($pages, $depth, $r, $current_page); - return call_user_func_array(array(&$walker, 'walk'), $args); + return call_user_func_array(array($walker, 'walk'), $args); } /** @@ -962,7 +964,7 @@ function walk_page_dropdown_tree() { else $walker = $args[2]['walker']; - return call_user_func_array(array(&$walker, 'walk'), $args); + return call_user_func_array(array($walker, 'walk'), $args); } /** @@ -994,6 +996,7 @@ class Walker_Page extends Walker { * * @param string $output Passed by reference. Used to append additional content. * @param int $depth Depth of page. Used for padding. + * @param array $args */ function start_lvl( &$output, $depth = 0, $args = array() ) { $indent = str_repeat("\t", $depth); @@ -1006,6 +1009,7 @@ class Walker_Page extends Walker { * * @param string $output Passed by reference. Used to append additional content. * @param int $depth Depth of page. Used for padding. + * @param array $args */ function end_lvl( &$output, $depth = 0, $args = array() ) { $indent = str_repeat("\t", $depth); @@ -1031,9 +1035,8 @@ class Walker_Page extends Walker { extract($args, EXTR_SKIP); $css_class = array('page_item', 'page-item-'.$page->ID); if ( !empty($current_page) ) { - $_current_page = get_page( $current_page ); - _get_post_ancestors($_current_page); - if ( isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors) ) + $_current_page = get_post( $current_page ); + if ( in_array( $page->ID, $_current_page->ancestors ) ) $css_class[] = 'current_page_ancestor'; if ( $page->ID == $current_page ) $css_class[] = 'current_page_item'; @@ -1064,6 +1067,7 @@ class Walker_Page extends Walker { * @param string $output Passed by reference. Used to append additional content. * @param object $page Page data object. Not used. * @param int $depth Depth of page. Not Used. + * @param array $args */ function end_el( &$output, $page, $depth = 0, $args = array() ) { $output .= "\n"; @@ -1102,6 +1106,7 @@ class Walker_PageDropdown extends Walker { * @param object $page Page data object. * @param int $depth Depth of page in reference to parent pages. Used for padding. * @param array $args Uses 'selected' argument for selected page to set selected HTML attribute for option element. + * @param int $id */ function start_el(&$output, $page, $depth, $args, $id = 0) { $pad = str_repeat(' ', $depth * 3); @@ -1150,12 +1155,12 @@ function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $ * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string. * @param bool $permalink Optional, default is false. Whether to add permalink to image. * @param bool $icon Optional, default is false. Whether to include icon. - * @param string $text Optional, default is false. If string, then will be link text. + * @param string|bool $text Optional, default is false. If string, then will be link text. * @return string HTML content. */ function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false ) { $id = intval( $id ); - $_post = & get_post( $id ); + $_post = get_post( $id ); if ( empty( $_post ) || ( 'attachment' != $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) ) return __( 'Missing Attachment' ); @@ -1188,7 +1193,7 @@ function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = fals * @return string */ function prepend_attachment($content) { - global $post; + $post = get_post(); if ( empty($post->post_type) || $post->post_type != 'attachment' ) return $content; @@ -1215,7 +1220,7 @@ function prepend_attachment($content) { * @return string HTML content for password form for password protected post. */ function get_the_password_form() { - global $post; + $post = get_post(); $label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID ); $output = '

    ' . __("This post is password protected. To view it please enter your password below:") . '

    @@ -1261,7 +1266,7 @@ function is_page_template( $template = '' ) { * * @since 3.4.0 * - * @param int $id The page ID to check. Defaults to the current post, when used in the loop. + * @param int $post_id The page ID to check. Defaults to the current post, when used in the loop. * @return string|bool Page template filename. Returns an empty string when the default page template * is in use. Returns false if the post is not a page. */ @@ -1432,9 +1437,9 @@ function wp_list_post_revisions( $post_id = 0, $args = null ) { - - - + + + diff --git a/wp-includes/post.php b/wp-includes/post.php index dee484e0..54f17f41 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -52,21 +52,27 @@ function create_initial_post_types() { register_post_type( 'attachment', array( 'labels' => array( - 'name' => __( 'Media' ), - 'edit_item' => __( 'Edit Media' ), + 'name' => _x('Media', 'post type general name'), + 'name_admin_bar' => _x( 'Media', 'add new from admin bar' ), + 'add_new' => _x( 'Add New', 'add new media' ), + 'edit_item' => __( 'Edit Media' ), + 'view_item' => __( 'View Attachment Page' ), ), 'public' => true, - 'show_ui' => false, + 'show_ui' => true, '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ - '_edit_link' => 'media.php?attachment_id=%d', /* internal use only. don't use this when registering your own post type. */ + '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */ 'capability_type' => 'post', + 'capabilities' => array( + 'create_posts' => 'upload_files', + ), 'map_meta_cap' => true, 'hierarchical' => false, 'rewrite' => false, 'query_var' => false, 'show_in_nav_menus' => false, 'delete_with_user' => true, - 'supports' => array( 'comments', 'author' ), + 'supports' => array( 'title', 'author', 'comments' ), ) ); register_post_type( 'revision', array( @@ -204,9 +210,10 @@ function update_attached_file( $attachment_id, $file ) { return false; $file = apply_filters( 'update_attached_file', $file, $attachment_id ); - $file = _wp_relative_upload_path($file); - - return update_post_meta( $attachment_id, '_wp_attached_file', $file ); + if ( $file = _wp_relative_upload_path( $file ) ) + return update_post_meta( $attachment_id, '_wp_attached_file', $file ); + else + return delete_post_meta( $attachment_id, '_wp_attached_file' ); } /** @@ -223,11 +230,10 @@ function update_attached_file( $attachment_id, $file ) { function _wp_relative_upload_path( $path ) { $new_path = $path; - if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) { - if ( 0 === strpos($new_path, $uploads['basedir']) ) { - $new_path = str_replace($uploads['basedir'], '', $new_path); - $new_path = ltrim($new_path, '/'); - } + $uploads = wp_upload_dir(); + if ( 0 === strpos( $new_path, $uploads['basedir'] ) ) { + $new_path = str_replace( $uploads['basedir'], '', $new_path ); + $new_path = ltrim( $new_path, '/' ); } return apply_filters( '_wp_relative_upload_path', $new_path, $path ); @@ -372,56 +378,297 @@ function get_extended($post) { * @uses $wpdb * @link http://codex.wordpress.org/Function_Reference/get_post * - * @param int|object $post Post ID or post object. + * @param int|object $post Post ID or post object. Optional, default is the current post from the loop. * @param string $output Optional, default is Object. Either OBJECT, ARRAY_A, or ARRAY_N. * @param string $filter Optional, default is raw. - * @return mixed Post data + * @return WP_Post|null WP_Post on success or null on failure */ -function &get_post(&$post, $output = OBJECT, $filter = 'raw') { - global $wpdb; - $null = null; +function get_post( $post = null, $output = OBJECT, $filter = 'raw' ) { + if ( empty( $post ) && isset( $GLOBALS['post'] ) ) + $post = $GLOBALS['post']; - if ( empty($post) ) { - if ( isset($GLOBALS['post']) ) - $_post = & $GLOBALS['post']; - else - return $null; - } elseif ( is_object($post) && empty($post->filter) ) { - _get_post_ancestors($post); - $_post = sanitize_post($post, 'raw'); - wp_cache_add($post->ID, $_post, 'posts'); - } elseif ( is_object($post) && 'raw' == $post->filter ) { + if ( is_a( $post, 'WP_Post' ) ) { $_post = $post; + } elseif ( is_object( $post ) ) { + if ( empty( $post->filter ) ) { + $_post = sanitize_post( $post, 'raw' ); + $_post = new WP_Post( $_post ); + } elseif ( 'raw' == $post->filter ) { + $_post = new WP_Post( $post ); + } else { + $_post = WP_Post::get_instance( $post->ID ); + } } else { - if ( is_object($post) ) - $post_id = $post->ID; - else - $post_id = $post; + $_post = WP_Post::get_instance( $post ); + } + + if ( ! $_post ) + return null; + + $_post = $_post->filter( $filter ); + + if ( $output == ARRAY_A ) + return $_post->to_array(); + elseif ( $output == ARRAY_N ) + return array_values( $_post->to_array() ); + + return $_post; +} + +/** + * WordPress Post class. + * + * @since 3.5.0 + * + */ +final class WP_Post { + + /** + * + * @var int + */ + public $ID; + + /** + * + * @var int + */ + public $post_author = 0; + + /** + * + * @var string + */ + public $post_date = '0000-00-00 00:00:00'; + + /** + * + * @var string + */ + public $post_date_gmt = '0000-00-00 00:00:00'; + + /** + * + * @var string + */ + public $post_content = ''; + + /** + * + * @var string + */ + public $post_title = ''; + + /** + * + * @var string + */ + public $post_excerpt = ''; + + /** + * + * @var string + */ + public $post_status = 'publish'; + + /** + * + * @var string + */ + public $comment_status = 'open'; + + /** + * + * @var string + */ + public $ping_status = 'open'; + + /** + * + * @var string + */ + public $post_password = ''; + + /** + * + * @var string + */ + public $post_name = ''; + + /** + * + * @var string + */ + public $to_ping = ''; + + /** + * + * @var string + */ + public $pinged = ''; + + /** + * + * @var string + */ + public $post_modified = '0000-00-00 00:00:00'; + + /** + * + * @var string + */ + public $post_modified_gmt = '0000-00-00 00:00:00'; + + /** + * + * @var string + */ + public $post_content_filtered = ''; + + /** + * + * @var int + */ + public $post_parent = 0; + + /** + * + * @var string + */ + public $guid = ''; + + /** + * + * @var int + */ + public $menu_order = 0; + + /** + * + * @var string + */ + public $post_type = 'post'; + + /** + * + * @var string + */ + public $post_mime_type = ''; + + /** + * + * @var int + */ + public $comment_count = 0; + + /** + * + * @var string + */ + public $filter; + + public static function get_instance( $post_id ) { + global $wpdb; $post_id = (int) $post_id; - if ( ! $_post = wp_cache_get($post_id, 'posts') ) { - $_post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id)); + if ( ! $post_id ) + return false; + + $_post = wp_cache_get( $post_id, 'posts' ); + + if ( ! $_post ) { + $_post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id ) ); + if ( ! $_post ) - return $null; - _get_post_ancestors($_post); - $_post = sanitize_post($_post, 'raw'); - wp_cache_add($_post->ID, $_post, 'posts'); + return false; + + $_post = sanitize_post( $_post, 'raw' ); + wp_cache_add( $_post->ID, $_post, 'posts' ); + } elseif ( empty( $_post->filter ) ) { + $_post = sanitize_post( $_post, 'raw' ); } + + return new WP_Post( $_post ); } - if ($filter != 'raw') - $_post = sanitize_post($_post, $filter); + public function __construct( $post ) { + foreach ( get_object_vars( $post ) as $key => $value ) + $this->$key = $value; + } - if ( $output == OBJECT ) { - return $_post; - } elseif ( $output == ARRAY_A ) { - $__post = get_object_vars($_post); - return $__post; - } elseif ( $output == ARRAY_N ) { - $__post = array_values(get_object_vars($_post)); - return $__post; - } else { - return $_post; + public function __isset( $key ) { + if ( 'ancestors' == $key ) + return true; + + if ( 'page_template' == $key ) + return ( 'page' == $this->post_type ); + + if ( 'post_category' == $key ) + return true; + + if ( 'tags_input' == $key ) + return true; + + return metadata_exists( 'post', $this->ID, $key ); + } + + public function __get( $key ) { + if ( 'page_template' == $key && $this->__isset( $key ) ) { + return get_post_meta( $this->ID, '_wp_page_template', true ); + } + + if ( 'post_category' == $key ) { + if ( is_object_in_taxonomy( $this->post_type, 'category' ) ) + $terms = get_the_terms( $this, 'category' ); + + if ( empty( $terms ) ) + return array(); + + return wp_list_pluck( $terms, 'term_id' ); + } + + if ( 'tags_input' == $key ) { + if ( is_object_in_taxonomy( $this->post_type, 'post_tag' ) ) + $terms = get_the_terms( $this, 'post_tag' ); + + if ( empty( $terms ) ) + return array(); + + return wp_list_pluck( $terms, 'name' ); + } + + // Rest of the values need filtering + + if ( 'ancestors' == $key ) + $value = get_post_ancestors( $this ); + else + $value = get_post_meta( $this->ID, $key, true ); + + if ( $this->filter ) + $value = sanitize_post_field( $key, $value, $this->ID, $this->filter ); + + return $value; + } + + public function filter( $filter ) { + if ( $this->filter == $filter ) + return $this; + + if ( $filter == 'raw' ) + return self::get_instance( $this->ID ); + + return sanitize_post( $this, $filter ); + } + + public function to_array() { + $post = get_object_vars( $this ); + + foreach ( array( 'ancestors', 'page_template', 'post_category', 'tags_input' ) as $key ) { + if ( $this->__isset( $key ) ) + $post[ $key ] = $this->__get( $key ); + } + + return $post; } } @@ -433,16 +680,28 @@ function &get_post(&$post, $output = OBJECT, $filter = 'raw') { * @param int|object $post Post ID or post object * @return array Ancestor IDs or empty array if none are found. */ -function get_post_ancestors($post) { - $post = get_post($post); +function get_post_ancestors( $post ) { + if ( ! $post ) + return false; - if ( ! isset( $post->ancestors ) ) - _get_post_ancestors( $post ); + $post = get_post( $post ); - if ( ! empty( $post->ancestors ) ) - return $post->ancestors; + if ( empty( $post->post_parent ) || $post->post_parent == $post->ID ) + return array(); - return array(); + $ancestors = array(); + + $id = $ancestors[] = $post->post_parent; + + while ( $ancestor = get_post( $id ) ) { + // Loop detection: If the ancestor has been seen before, break. + if ( empty( $ancestor->post_parent ) || ( $ancestor->post_parent == $post->ID ) || in_array( $ancestor->post_parent, $ancestors ) ) + break; + + $id = $ancestors[] = $ancestor->post_parent; + } + + return $ancestors; } /** @@ -460,16 +719,12 @@ function get_post_ancestors($post) { * @param string $field Post field name * @param id $post Post ID * @param string $context Optional. How to filter the field. Default is display. - * @return WP_Error|string Value in post field or WP_Error on failure + * @return bool|string False on failure or returns the value in post field */ function get_post_field( $field, $post, $context = 'display' ) { - $post = (int) $post; $post = get_post( $post ); - if ( is_wp_error($post) ) - return $post; - - if ( !is_object($post) ) + if ( !$post ) return ''; if ( !isset($post->$field) ) @@ -490,7 +745,7 @@ function get_post_field( $field, $post, $context = 'display' ) { * @return bool|string False on failure or returns the mime type */ function get_post_mime_type($ID = '') { - $post = & get_post($ID); + $post = get_post($ID); if ( is_object($post) ) return $post->post_mime_type; @@ -671,7 +926,19 @@ function register_post_status($post_status, $args = array()) { $wp_post_statuses = array(); // Args prefixed with an underscore are reserved for internal use. - $defaults = array('label' => false, 'label_count' => false, 'exclude_from_search' => null, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'public' => null, 'internal' => null, 'protected' => null, 'private' => null, 'show_in_admin_all' => null, 'publicly_queryable' => null, 'show_in_admin_status_list' => null, 'show_in_admin_all_list' => null, 'single_view_cap' => null); + $defaults = array( + 'label' => false, + 'label_count' => false, + 'exclude_from_search' => null, + '_builtin' => false, + 'public' => null, + 'internal' => null, + 'protected' => null, + 'private' => null, + 'publicly_queryable' => null, + 'show_in_admin_status_list' => null, + 'show_in_admin_all_list' => null, + ); $args = wp_parse_args($args, $defaults); $args = (object) $args; @@ -703,10 +970,7 @@ function register_post_status($post_status, $args = array()) { $args->show_in_admin_all_list = !$args->internal; if ( null === $args->show_in_admin_status_list ) - $args->show_in_admin_status_list = !$args->internal; - - if ( null === $args->single_view_cap ) - $args->single_view_cap = $args->public ? '' : 'edit'; + $args->show_in_admin_status_list = !$args->internal; if ( false === $args->label ) $args->label = $post_status; @@ -804,19 +1068,12 @@ function post_type_exists( $post_type ) { * * @uses $post The Loop current post global * - * @param mixed $the_post Optional. Post object or post ID. + * @param mixed $post Optional. Post object or post ID. * @return bool|string post type or false on failure. */ -function get_post_type( $the_post = false ) { - global $post; - - if ( false === $the_post ) - $the_post = $post; - elseif ( is_numeric($the_post) ) - $the_post = get_post($the_post); - - if ( is_object($the_post) ) - return $the_post->post_type; +function get_post_type( $post = null ) { + if ( $post = get_post( $post ) ) + return $post->post_type; return false; } @@ -1020,7 +1277,7 @@ function register_post_type( $post_type, $args = array() ) { if ( ! empty($args->supports) ) { add_post_type_support($post_type, $args->supports); unset($args->supports); - } else { + } elseif ( false !== $args->supports ) { // Add default features add_post_type_support($post_type, array('title', 'editor')); } @@ -1028,7 +1285,8 @@ function register_post_type( $post_type, $args = array() ) { if ( false !== $args->query_var && !empty($wp) ) { if ( true === $args->query_var ) $args->query_var = $post_type; - $args->query_var = sanitize_title_with_dashes($args->query_var); + else + $args->query_var = sanitize_title_with_dashes($args->query_var); $wp->add_query_var($args->query_var); } @@ -1182,6 +1440,10 @@ function get_post_type_capabilities( $args ) { $capabilities = array_merge( $default_capabilities, $args->capabilities ); + // Post creation capability simply maps to edit_posts by default: + if ( ! isset( $capabilities['create_posts'] ) ) + $capabilities['create_posts'] = $capabilities['edit_posts']; + // Remember meta capabilities for future reference. if ( $args->map_meta_cap ) _post_type_meta_capabilities( $capabilities ); @@ -1245,7 +1507,11 @@ function get_post_type_labels( $post_type_object ) { 'all_items' => array( __( 'All Posts' ), __( 'All Pages' ) ) ); $nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name']; - return _get_custom_object_labels( $post_type_object, $nohier_vs_hier_defaults ); + + $labels = _get_custom_object_labels( $post_type_object, $nohier_vs_hier_defaults ); + + $post_type = $post_type_object->name; + return apply_filters( "post_type_labels_{$post_type}", $labels ); } /** @@ -1668,9 +1934,9 @@ function is_sticky( $post_id = 0 ) { * @since 2.3.0 * @uses sanitize_post_field() Used to sanitize the fields. * - * @param object|array $post The Post Object or Array + * @param object|WP_Post|array $post The Post Object or Array * @param string $context Optional, default is 'display'. How to sanitize post fields. - * @return object|array The now sanitized Post Object or Array (will be the same type as $post) + * @return object|WP_Post|array The now sanitized Post Object or Array (will be the same type as $post) */ function sanitize_post($post, $context = 'display') { if ( is_object($post) ) { @@ -1916,6 +2182,23 @@ function wp_count_attachments( $mime_type = '' ) { return (object) $stats; } +/** + * Get default post mime types + * + * @since 2.9.0 + * + * @return array + */ +function get_post_mime_types() { + $post_mime_types = array( // array( adj, noun ) + 'image' => array(__('Images'), __('Manage Images'), _n_noop('Image (%s)', 'Images (%s)')), + 'audio' => array(__('Audio'), __('Manage Audio'), _n_noop('Audio (%s)', 'Audio (%s)')), + 'video' => array(__('Video'), __('Manage Video'), _n_noop('Video (%s)', 'Video (%s)')), + ); + + return apply_filters('post_mime_types', $post_mime_types); +} + /** * Check a MIME-Type against a list. * @@ -2086,8 +2369,8 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { clean_post_cache( $post ); - if ( is_post_type_hierarchical( $post->post_type ) ) { - foreach ( (array) $children as $child ) + if ( is_post_type_hierarchical( $post->post_type ) && $children ) { + foreach ( $children as $child ) clean_post_cache( $child ); } @@ -2115,7 +2398,7 @@ function wp_trash_post($post_id = 0) { if ( !EMPTY_TRASH_DAYS ) return wp_delete_post($post_id, true); - if ( !$post = wp_get_single_post($post_id, ARRAY_A) ) + if ( !$post = get_post($post_id, ARRAY_A) ) return $post; if ( $post['post_status'] == 'trash' ) @@ -2147,7 +2430,7 @@ function wp_trash_post($post_id = 0) { * @return mixed False on failure */ function wp_untrash_post($post_id = 0) { - if ( !$post = wp_get_single_post($post_id, ARRAY_A) ) + if ( !$post = get_post($post_id, ARRAY_A) ) return $post; if ( $post['post_status'] != 'trash' ) @@ -2377,49 +2660,6 @@ function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) { } -/** - * Retrieve a single post, based on post ID. - * - * Has categories in 'post_category' property or key. Has tags in 'tags_input' - * property or key. - * - * @since 1.0.0 - * - * @param int $postid Post ID. - * @param string $mode How to return result, either OBJECT, ARRAY_N, or ARRAY_A. - * @return object|array Post object or array holding post contents and information - */ -function wp_get_single_post($postid = 0, $mode = OBJECT) { - $postid = (int) $postid; - - $post = get_post($postid, $mode); - - if ( - ( OBJECT == $mode && empty( $post->ID ) ) || - ( OBJECT != $mode && empty( $post['ID'] ) ) - ) - return ( OBJECT == $mode ? null : array() ); - - // Set categories and tags - if ( $mode == OBJECT ) { - $post->post_category = array(); - if ( is_object_in_taxonomy($post->post_type, 'category') ) - $post->post_category = wp_get_post_categories($postid); - $post->tags_input = array(); - if ( is_object_in_taxonomy($post->post_type, 'post_tag') ) - $post->tags_input = wp_get_post_tags($postid, array('fields' => 'names')); - } else { - $post['post_category'] = array(); - if ( is_object_in_taxonomy($post['post_type'], 'category') ) - $post['post_category'] = wp_get_post_categories($postid); - $post['tags_input'] = array(); - if ( is_object_in_taxonomy($post['post_type'], 'post_tag') ) - $post['tags_input'] = wp_get_post_tags($postid, array('fields' => 'names')); - } - - return $post; -} - /** * Insert a post. * @@ -2547,6 +2787,18 @@ function wp_insert_post($postarr, $wp_error = false) { if ( empty($post_date) || '0000-00-00 00:00:00' == $post_date ) $post_date = current_time('mysql'); + // validate the date + $mm = substr( $post_date, 5, 2 ); + $jj = substr( $post_date, 8, 2 ); + $aa = substr( $post_date, 0, 4 ); + $valid_date = wp_checkdate( $mm, $jj, $aa, $post_date ); + if ( !$valid_date ) { + if ( $wp_error ) + return new WP_Error( 'invalid_date', __( 'Whoops, the provided date is invalid.' ) ); + else + return 0; + } + if ( empty($post_date_gmt) || '0000-00-00 00:00:00' == $post_date_gmt ) { if ( !in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) $post_date_gmt = get_gmt_from_date($post_date); @@ -2667,18 +2919,18 @@ function wp_insert_post($postarr, $wp_error = false) { $current_guid = get_post_field( 'guid', $post_ID ); - clean_post_cache( $post_ID ); - // Set GUID if ( !$update && '' == $current_guid ) $wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post_ID ) ), $where ); + clean_post_cache( $post_ID ); + $post = get_post($post_ID); if ( !empty($page_template) && 'page' == $data['post_type'] ) { $post->page_template = $page_template; - $page_templates = get_page_templates(); - if ( 'default' != $page_template && !in_array($page_template, $page_templates) ) { + $page_templates = wp_get_theme()->get_page_templates(); + if ( 'default' != $page_template && ! isset( $page_templates[ $page_template ] ) ) { if ( $wp_error ) return new WP_Error('invalid_page_template', __('The page template is invalid.')); else @@ -2710,9 +2962,10 @@ function wp_insert_post($postarr, $wp_error = false) { * @since 1.0.0 * * @param array|object $postarr Post data. Arrays are expected to be escaped, objects are not. - * @return int 0 on failure, Post ID on success. + * @param bool $wp_error Optional. Allow return of WP_Error on failure. + * @return int|WP_Error The value 0 or WP_Error on failure. The post ID on success. */ -function wp_update_post($postarr = array()) { +function wp_update_post( $postarr = array(), $wp_error = false ) { if ( is_object($postarr) ) { // non-escaped post was passed $postarr = get_object_vars($postarr); @@ -2720,7 +2973,7 @@ function wp_update_post($postarr = array()) { } // First, get all of the original fields - $post = wp_get_single_post($postarr['ID'], ARRAY_A); + $post = get_post($postarr['ID'], ARRAY_A); // Escape data pulled from DB. $post = add_magic_quotes($post); @@ -2750,39 +3003,25 @@ function wp_update_post($postarr = array()) { if ($postarr['post_type'] == 'attachment') return wp_insert_attachment($postarr); - return wp_insert_post($postarr); + return wp_insert_post( $postarr, $wp_error ); } /** * Publish a post by transitioning the post status. * * @since 2.1.0 - * @uses $wpdb - * @uses do_action() Calls 'edit_post', 'save_post', and 'wp_insert_post' on post_id and post data. + * @uses wp_update_post() * - * @param int $post_id Post ID. - * @return null + * @param mixed $post Post ID or object. */ -function wp_publish_post($post_id) { - global $wpdb; - - $post = get_post($post_id); - - if ( empty($post) ) +function wp_publish_post( $post ) { + if ( ! $post = get_post( $post ) ) return; - if ( 'publish' == $post->post_status ) return; - $wpdb->update( $wpdb->posts, array( 'post_status' => 'publish' ), array( 'ID' => $post_id ) ); - - $old_status = $post->post_status; $post->post_status = 'publish'; - wp_transition_post_status('publish', $old_status, $post); - - do_action('edit_post', $post_id, $post); - do_action('save_post', $post_id, $post); - do_action('wp_insert_post', $post_id, $post); + wp_update_post( $post ); } /** @@ -2837,6 +3076,8 @@ function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_p global $wpdb, $wp_rewrite; + $original_slug = $slug; + $feeds = $wp_rewrite->feeds; if ( ! is_array( $feeds ) ) $feeds = array(); @@ -2857,6 +3098,8 @@ function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_p $slug = $alt_post_name; } } elseif ( in_array( $post_type, $hierarchical_post_types ) ) { + if ( 'nav_menu_item' == $post_type ) + return $slug; // Page slugs must be unique within their own trees. Pages are in a separate // namespace than posts so page slugs are allowed to overlap post slugs. $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( '" . implode( "', '", esc_sql( $hierarchical_post_types ) ) . "' ) AND ID != %d AND post_parent = %d LIMIT 1"; @@ -2887,7 +3130,7 @@ function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_p } } - return apply_filters( 'wp_unique_post_slug', $slug, $post_ID, $post_status, $post_type, $post_parent ); + return apply_filters( 'wp_unique_post_slug', $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ); } /** @@ -2953,11 +3196,10 @@ function wp_set_post_terms( $post_id = 0, $tags = '', $taxonomy = 'post_tag', $a // Hierarchical taxonomies must always pass IDs rather than names so that children with the same // names but different parents aren't confused. if ( is_taxonomy_hierarchical( $taxonomy ) ) { - $tags = array_map( 'intval', $tags ); - $tags = array_unique( $tags ); + $tags = array_unique( array_map( 'intval', $tags ) ); } - return wp_set_object_terms($post_id, $tags, $taxonomy, $append); + return wp_set_object_terms( $post_id, $tags, $taxonomy, $append ); } /** @@ -2986,12 +3228,7 @@ function wp_set_post_categories($post_ID = 0, $post_categories = array()) { return true; } - if ( !empty($post_categories) ) { - $post_categories = array_map('intval', $post_categories); - $post_categories = array_unique($post_categories); - } - - return wp_set_object_terms($post_ID, $post_categories, 'category'); + return wp_set_post_terms($post_ID, $post_categories, 'category'); } /** @@ -3127,7 +3364,7 @@ function get_to_ping($post_id) { function trackback_url_list($tb_list, $post_id) { if ( ! empty( $tb_list ) ) { // get post data - $postdata = wp_get_single_post($post_id, ARRAY_A); + $postdata = get_post($post_id, ARRAY_A); // import postdata as variables extract($postdata, EXTR_SKIP); @@ -3174,16 +3411,18 @@ function get_all_page_ids() { /** * Retrieves page data given a page ID or page object. * + * Use get_post() instead of get_page(). + * * @since 1.5.1 + * @deprecated 3.5.0 * * @param mixed $page Page object or page ID. Passed by reference. * @param string $output What to output. OBJECT, ARRAY_A, or ARRAY_N. * @param string $filter How the return value should be filtered. - * @return mixed Page data. + * @return WP_Post|null WP_Post on success or null on failure */ -function &get_page(&$page, $output = OBJECT, $filter = 'raw') { - $p = get_post($page, $output, $filter); - return $p; +function get_page( $page, $output = OBJECT, $filter = 'raw') { + return get_post( $page, $output, $filter ); } /** @@ -3195,7 +3434,7 @@ function &get_page(&$page, $output = OBJECT, $filter = 'raw') { * @param string $page_path Page path * @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. Default OBJECT. * @param string $post_type Optional. Post type. Default page. - * @return mixed Null when complete. + * @return WP_Post|null WP_Post on success or null on failure */ function get_page_by_path($page_path, $output = OBJECT, $post_type = 'page') { global $wpdb; @@ -3210,7 +3449,7 @@ function get_page_by_path($page_path, $output = OBJECT, $post_type = 'page') { $in_string = "'". implode( "','", $parts ) . "'"; $post_type_sql = $post_type; $wpdb->escape_by_ref( $post_type_sql ); - $pages = $wpdb->get_results( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_name IN ($in_string) AND (post_type = '$post_type_sql' OR post_type = 'attachment')", OBJECT_K ); + $pages = $wpdb->get_results( "SELECT ID, post_name, post_parent, post_type FROM $wpdb->posts WHERE post_name IN ($in_string) AND (post_type = '$post_type_sql' OR post_type = 'attachment')", OBJECT_K ); $revparts = array_reverse( $parts ); @@ -3229,13 +3468,14 @@ function get_page_by_path($page_path, $output = OBJECT, $post_type = 'page') { if ( $p->post_parent == 0 && $count+1 == count( $revparts ) && $p->post_name == $revparts[ $count ] ) { $foundid = $page->ID; - break; + if ( $page->post_type == $post_type ) + break; } } } if ( $foundid ) - return get_page( $foundid, $output ); + return get_post( $foundid, $output ); return null; } @@ -3249,13 +3489,13 @@ function get_page_by_path($page_path, $output = OBJECT, $post_type = 'page') { * @param string $page_title Page title * @param string $output Optional. Output type. OBJECT, ARRAY_N, or ARRAY_A. Default OBJECT. * @param string $post_type Optional. Post type. Default page. - * @return mixed + * @return WP_Post|null WP_Post on success or null on failure */ function get_page_by_title($page_title, $output = OBJECT, $post_type = 'page' ) { global $wpdb; $page = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type= %s", $page_title, $post_type ) ); if ( $page ) - return get_page($page, $output); + return get_post( $page, $output ); return null; } @@ -3273,7 +3513,7 @@ function get_page_by_title($page_title, $output = OBJECT, $post_type = 'page' ) * @param array $pages List of pages' objects. * @return array */ -function &get_page_children($page_id, $pages) { +function get_page_children($page_id, $pages) { $page_list = array(); foreach ( (array) $pages as $page ) { if ( $page->post_parent == $page_id ) { @@ -3297,7 +3537,7 @@ function &get_page_children($page_id, $pages) { * @param int $page_id Parent page ID. * @return array A list arranged by hierarchy. Children immediately follow their parents. */ -function &get_page_hierarchy( &$pages, $page_id = 0 ) { +function get_page_hierarchy( &$pages, $page_id = 0 ) { if ( empty( $pages ) ) { $result = array(); return $result; @@ -3342,16 +3582,11 @@ function _page_traverse_name( $page_id, &$children, &$result ){ */ function get_page_uri($page) { if ( ! is_object($page) ) - $page = get_page($page); + $page = get_post( $page ); $uri = $page->post_name; - // A page cannot be it's own parent. - if ( $page->post_parent == $page->ID ) - return $uri; - - while ($page->post_parent != 0) { - $page = get_page($page->post_parent); - $uri = $page->post_name . "/" . $uri; + foreach ( $page->ancestors as $parent ) { + $uri = get_post( $parent )->post_name . "/" . $uri; } return $uri; @@ -3370,9 +3605,11 @@ function get_page_uri($page) { * @param mixed $args Optional. Array or string of options that overrides defaults. * @return array List of pages matching defaults or $args */ -function &get_pages($args = '') { +function get_pages($args = '') { global $wpdb; + $pages = false; + $defaults = array( 'child_of' => 0, 'sort_order' => 'ASC', 'sort_column' => 'post_title', 'hierarchical' => 1, @@ -3391,19 +3628,21 @@ function &get_pages($args = '') { // Make sure the post type is hierarchical $hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) ); if ( !in_array( $post_type, $hierarchical_post_types ) ) - return false; + return $pages; // Make sure we have a valid post status if ( !is_array( $post_status ) ) $post_status = explode( ',', $post_status ); if ( array_diff( $post_status, get_post_stati() ) ) - return false; + return $pages; $cache = array(); $key = md5( serialize( compact(array_keys($defaults)) ) ); if ( $cache = wp_cache_get( 'get_pages', 'posts' ) ) { - if ( is_array($cache) && isset( $cache[ $key ] ) ) { - $pages = apply_filters('get_pages', $cache[ $key ], $r ); + if ( is_array($cache) && isset( $cache[ $key ] ) && is_array( $cache[ $key ] ) ) { + // Convert to WP_Post instances + $pages = array_map( 'get_post', $cache[ $key ] ); + $pages = apply_filters( 'get_pages', $pages, $r ); return $pages; } } @@ -3559,7 +3798,7 @@ function &get_pages($args = '') { update_post_cache( $pages ); if ( $child_of || $hierarchical ) - $pages = & get_page_children($child_of, $pages); + $pages = get_page_children($child_of, $pages); if ( !empty($exclude_tree) ) { $exclude = (int) $exclude_tree; @@ -3578,6 +3817,9 @@ function &get_pages($args = '') { $cache[ $key ] = $pages; wp_cache_set( 'get_pages', $cache, 'posts' ); + // Convert to WP_Post instances + $pages = array_map( 'get_post', $pages ); + $pages = apply_filters('get_pages', $pages, $r); return $pages; @@ -3601,7 +3843,7 @@ function is_local_attachment($url) { if (strpos($url, home_url('/?attachment_id=')) !== false) return true; if ( $id = url_to_postid($url) ) { - $post = & get_post($id); + $post = get_post($id); if ( 'attachment' == $post->post_type ) return true; } @@ -3676,13 +3918,12 @@ function wp_insert_attachment($object, $file = false, $parent = 0) { if ( ! in_array( $post_status, array( 'inherit', 'private' ) ) ) $post_status = 'inherit'; + if ( !empty($post_category) ) + $post_category = array_filter($post_category); // Filter out empty terms + // Make sure we set a valid category. - if ( !isset($post_category) || 0 == count($post_category) || !is_array($post_category) ) { - // 'post' requires at least one category. - if ( 'post' == $post_type ) - $post_category = array( get_option('default_category') ); - else - $post_category = array(); + if ( empty($post_category) || 0 == count($post_category) || !is_array($post_category) ) { + $post_category = array(); } // Are we updating or creating? @@ -3767,7 +4008,22 @@ function wp_insert_attachment($object, $file = false, $parent = 0) { $wpdb->update( $wpdb->posts, compact("post_name"), array( 'ID' => $post_ID ) ); } - wp_set_post_categories($post_ID, $post_category); + if ( is_object_in_taxonomy($post_type, 'category') ) + wp_set_post_categories( $post_ID, $post_category ); + + if ( isset( $tags_input ) && is_object_in_taxonomy($post_type, 'post_tag') ) + wp_set_post_tags( $post_ID, $tags_input ); + + // support for all custom taxonomies + if ( !empty($tax_input) ) { + foreach ( $tax_input as $taxonomy => $tags ) { + $taxonomy_obj = get_taxonomy($taxonomy); + if ( is_array($tags) ) // array = hierarchical, string = non-hierarchical. + $tags = array_filter($tags); + if ( current_user_can($taxonomy_obj->cap->assign_terms) ) + wp_set_post_terms( $post_ID, $tags, $taxonomy ); + } + } if ( $file ) update_attached_file( $post_ID, $file ); @@ -3897,7 +4153,7 @@ function wp_delete_attachment( $post_id, $force_delete = false ) { */ function wp_get_attachment_metadata( $post_id = 0, $unfiltered = false ) { $post_id = (int) $post_id; - if ( !$post =& get_post( $post_id ) ) + if ( !$post = get_post( $post_id ) ) return false; $data = get_post_meta( $post->ID, '_wp_attachment_metadata', true ); @@ -3919,12 +4175,13 @@ function wp_get_attachment_metadata( $post_id = 0, $unfiltered = false ) { */ function wp_update_attachment_metadata( $post_id, $data ) { $post_id = (int) $post_id; - if ( !$post =& get_post( $post_id ) ) + if ( !$post = get_post( $post_id ) ) return false; - $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ); - - return update_post_meta( $post->ID, '_wp_attachment_metadata', $data); + if ( $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ) ) + return update_post_meta( $post->ID, '_wp_attachment_metadata', $data ); + else + return delete_post_meta( $post->ID, '_wp_attachment_metadata' ); } /** @@ -3937,7 +4194,7 @@ function wp_update_attachment_metadata( $post_id, $data ) { */ function wp_get_attachment_url( $post_id = 0 ) { $post_id = (int) $post_id; - if ( !$post =& get_post( $post_id ) ) + if ( !$post = get_post( $post_id ) ) return false; if ( 'attachment' != $post->post_type ) @@ -3976,7 +4233,7 @@ function wp_get_attachment_url( $post_id = 0 ) { */ function wp_get_attachment_thumb_file( $post_id = 0 ) { $post_id = (int) $post_id; - if ( !$post =& get_post( $post_id ) ) + if ( !$post = get_post( $post_id ) ) return false; if ( !is_array( $imagedata = wp_get_attachment_metadata( $post->ID ) ) ) return false; @@ -3998,7 +4255,7 @@ function wp_get_attachment_thumb_file( $post_id = 0 ) { */ function wp_get_attachment_thumb_url( $post_id = 0 ) { $post_id = (int) $post_id; - if ( !$post =& get_post( $post_id ) ) + if ( !$post = get_post( $post_id ) ) return false; if ( !$url = wp_get_attachment_url( $post->ID ) ) return false; @@ -4025,7 +4282,7 @@ function wp_get_attachment_thumb_url( $post_id = 0 ) { */ function wp_attachment_is_image( $post_id = 0 ) { $post_id = (int) $post_id; - if ( !$post =& get_post( $post_id ) ) + if ( !$post = get_post( $post_id ) ) return false; if ( !$file = get_attached_file( $post->ID ) ) @@ -4033,7 +4290,7 @@ function wp_attachment_is_image( $post_id = 0 ) { $ext = preg_match('/\.([^.]+)$/', $file, $matches) ? strtolower($matches[1]) : false; - $image_exts = array('jpg', 'jpeg', 'gif', 'png'); + $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' ); if ( 'image/' == substr($post->post_mime_type, 0, 6) || $ext && 'import' == $post->post_mime_type && in_array($ext, $image_exts) ) return true; @@ -4051,12 +4308,13 @@ function wp_attachment_is_image( $post_id = 0 ) { function wp_mime_type_icon( $mime = 0 ) { if ( !is_numeric($mime) ) $icon = wp_cache_get("mime_type_icon_$mime"); + + $post_id = 0; if ( empty($icon) ) { - $post_id = 0; $post_mimes = array(); if ( is_numeric($mime) ) { $mime = (int) $mime; - if ( $post =& get_post( $mime ) ) { + if ( $post = get_post( $mime ) ) { $post_id = (int) $post->ID; $ext = preg_replace('/^.+?\.([^.]+)$/', '$1', $post->guid); if ( !empty($ext) ) { @@ -4098,7 +4356,7 @@ function wp_mime_type_icon( $mime = 0 ) { closedir($dh); } } - wp_cache_set('icon_files', $icon_files, 600); + wp_cache_add( 'icon_files', $icon_files, 'default', 600 ); } // Icon basename - extension = MIME wildcard @@ -4118,7 +4376,7 @@ function wp_mime_type_icon( $mime = 0 ) { if ( isset($types[$wilds[0]])) { $icon = $types[$wilds[0]]; if ( !is_numeric($mime) ) - wp_cache_set("mime_type_icon_$mime", $icon); + wp_cache_add("mime_type_icon_$mime", $icon); break; } } @@ -4195,9 +4453,10 @@ function get_private_posts_cap_sql( $post_type ) { * @param string $post_type Post type. * @param bool $full Optional. Returns a full WHERE statement instead of just an 'andalso' term. * @param int $post_author Optional. Query posts having a single author ID. + * @param bool $public_only Optional. Only return public posts. Skips cap checks for $current_user. Default is false. * @return string SQL WHERE code that can be added to a query. */ -function get_posts_by_author_sql( $post_type, $full = true, $post_author = null ) { +function get_posts_by_author_sql( $post_type, $full = true, $post_author = null, $public_only = false ) { global $user_ID, $wpdb; // Private posts @@ -4221,18 +4480,21 @@ function get_posts_by_author_sql( $post_type, $full = true, $post_author = null $sql .= "(post_status = 'publish'"; - if ( current_user_can( $cap ) ) { - // Does the user have the capability to view private posts? Guess so. - $sql .= " OR post_status = 'private'"; - } elseif ( is_user_logged_in() ) { - // Users can view their own private posts. - $id = (int) $user_ID; - if ( null === $post_author || ! $full ) { - $sql .= " OR post_status = 'private' AND post_author = $id"; - } elseif ( $id == (int) $post_author ) { + // Only need to check the cap if $public_only is false + if ( false === $public_only ) { + if ( current_user_can( $cap ) ) { + // Does the user have the capability to view private posts? Guess so. $sql .= " OR post_status = 'private'"; + } elseif ( is_user_logged_in() ) { + // Users can view their own private posts. + $id = (int) $user_ID; + if ( null === $post_author || ! $full ) { + $sql .= " OR post_status = 'private' AND post_author = $id"; + } elseif ( $id == (int) $post_author ) { + $sql .= " OR post_status = 'private'"; + } // else none } // else none - } // else none + } $sql .= ')'; @@ -4351,8 +4613,6 @@ function update_post_cache( &$posts ) { * Cleaning means delete from the cache of the post. Will call to clean the term * object cache associated with the post ID. * - * clean_post_cache() will call itself recursively for each child post. - * * This function not run if $_wp_suspend_cache_invalidation is not empty. See * wp_suspend_cache_invalidation(). * @@ -4383,23 +4643,13 @@ function clean_post_cache( $post ) { do_action( 'clean_post_cache', $post->ID, $post ); + if ( is_post_type_hierarchical( $post->post_type ) ) + wp_cache_delete( 'get_pages', 'posts' ); + if ( 'page' == $post->post_type ) { wp_cache_delete( 'all_page_ids', 'posts' ); - wp_cache_delete( 'get_pages', 'posts' ); do_action( 'clean_page_cache', $post->ID ); } - - if ( $children = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_type FROM $wpdb->posts WHERE post_parent = %d", $post->ID) ) ) { - foreach ( $children as $child ) { - // Loop detection - if ( $child->ID == $post->ID ) - continue; - clean_post_cache( $child ); - } - } - - if ( is_multisite() ) - wp_cache_delete( $wpdb->blogid . '-' . $post->ID, 'global-posts' ); } /** @@ -4430,8 +4680,8 @@ function update_post_caches(&$posts, $post_type = 'post', $update_term_cache = t foreach ( $posts as $post ) $post_ids[] = $post->ID; - if ( empty($post_type) ) - $post_type = 'post'; + if ( ! $post_type ) + $post_type = 'any'; if ( $update_term_cache ) { if ( is_array($post_type) ) { @@ -4571,9 +4821,8 @@ function _future_post_hook( $deprecated = '', $post ) { * @since 2.3.0 * @access private * @uses $wpdb - * @uses XMLRPC_REQUEST and APP_REQUEST constants. + * @uses XMLRPC_REQUEST constant. * @uses do_action() Calls 'xmlprc_publish_post' on post ID if XMLRPC_REQUEST is defined. - * @uses do_action() Calls 'app_publish_post' on post ID if APP_REQUEST is defined. * * @param int $post_id The ID in the database table of the post being published */ @@ -4582,8 +4831,6 @@ function _publish_post_hook($post_id) { if ( defined('XMLRPC_REQUEST') ) do_action('xmlrpc_publish_post', $post_id); - if ( defined('APP_REQUEST') ) - do_action('app_publish_post', $post_id); if ( defined('WP_IMPORTING') ) return; @@ -4595,58 +4842,6 @@ function _publish_post_hook($post_id) { wp_schedule_single_event(time(), 'do_pings'); } -/** - * Hook used to prevent page/post cache from staying dirty when a post is saved. - * - * @since 2.3.0 - * @access private - * - * @param int $post_id The ID in the database table for the $post - * @param object $post Object type containing the post information - */ -function _save_post_hook( $post_id, $post ) { - clean_post_cache( $post ); -} - -/** - * Retrieve post ancestors and append to post ancestors property. - * - * Will only retrieve ancestors once, if property is already set, then nothing - * will be done. If there is not a parent post, or post ID and post parent ID - * are the same then nothing will be done. - * - * The parameter is passed by reference, so nothing needs to be returned. The - * property will be updated and can be referenced after the function is - * complete. The post parent will be an ancestor and the parent of the post - * parent will be an ancestor. There will only be two ancestors at the most. - * - * @since 2.5.0 - * @access private - * @uses $wpdb - * - * @param object $_post Post data. - * @return null When nothing needs to be done. - */ -function _get_post_ancestors(&$_post) { - global $wpdb; - - if ( isset($_post->ancestors) ) - return; - - $_post->ancestors = array(); - - if ( empty($_post->post_parent) || $_post->ID == $_post->post_parent ) - return; - - $id = $_post->ancestors[] = (int) $_post->post_parent; - while ( $ancestor = $wpdb->get_var( $wpdb->prepare("SELECT `post_parent` FROM $wpdb->posts WHERE ID = %d LIMIT 1", $id) ) ) { - // Loop detection: If the ancestor has been seen before, break. - if ( ( $ancestor == $_post->ID ) || in_array($ancestor, $_post->ancestors) ) - break; - $id = $_post->ancestors[] = (int) $ancestor; - } -} - /** * Determines which fields of posts are to be saved in revisions. * @@ -4726,6 +4921,9 @@ function wp_save_post_revision( $post_id ) { if ( !$post = get_post( $post_id, ARRAY_A ) ) return; + if ( 'auto-draft' == $post['post_status'] ) + return; + if ( !post_type_supports($post['post_type'], 'revisions') ) return; @@ -4890,7 +5088,7 @@ function _wp_put_post_revision( $post = null, $autosave = false ) { * @param string $filter Optional sanitation filter. @see sanitize_post() * @return mixed Null if error or post object if success */ -function &wp_get_post_revision(&$post, $output = OBJECT, $filter = 'raw') { +function wp_get_post_revision(&$post, $output = OBJECT, $filter = 'raw') { $null = null; if ( !$revision = get_post( $post, OBJECT, $filter ) ) return $revision; @@ -5166,10 +5364,10 @@ function set_post_thumbnail( $post, $thumbnail_id ) { $post = get_post( $post ); $thumbnail_id = absint( $thumbnail_id ); if ( $post && $thumbnail_id && get_post( $thumbnail_id ) ) { - $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'thumbnail' ); - if ( ! empty( $thumbnail_html ) ) { + if ( $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'thumbnail' ) ) return update_post_meta( $post->ID, '_thumbnail_id', $thumbnail_id ); - } + else + return delete_post_meta( $post->ID, '_thumbnail_id' ); } return false; } diff --git a/wp-includes/query.php b/wp-includes/query.php index 5f6ccddf..443d0bb7 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -86,8 +86,7 @@ function set_query_var($var, $value) { * @param string $query * @return array List of posts */ -function &query_posts($query) { - unset($GLOBALS['wp_query']); +function query_posts($query) { $GLOBALS['wp_query'] = new WP_Query(); return $GLOBALS['wp_query']->query($query); } @@ -103,7 +102,6 @@ function &query_posts($query) { * @uses $wp_query */ function wp_reset_query() { - unset($GLOBALS['wp_query']); $GLOBALS['wp_query'] = $GLOBALS['wp_the_query']; wp_reset_postdata(); } @@ -128,7 +126,7 @@ function wp_reset_postdata() { */ /** - * Is the query for an archive page? + * Is the query for an existing archive page? * * Month, Year, Category, Author, Post Type archive... * @@ -150,7 +148,7 @@ function is_archive() { } /** - * Is the query for a post type archive page? + * Is the query for an existing post type archive page? * * @see WP_Query::is_post_type_archive() * @since 3.1.0 @@ -171,7 +169,7 @@ function is_post_type_archive( $post_types = '' ) { } /** - * Is the query for an attachment page? + * Is the query for an existing attachment page? * * @see WP_Query::is_attachment() * @since 2.0.0 @@ -191,7 +189,7 @@ function is_attachment() { } /** - * Is the query for an author archive page? + * Is the query for an existing author archive page? * * If the $author parameter is specified, this function will additionally * check if the query is for one of the authors specified. @@ -215,7 +213,7 @@ function is_author( $author = '' ) { } /** - * Is the query for a category archive page? + * Is the query for an existing category archive page? * * If the $category parameter is specified, this function will additionally * check if the query is for one of the categories specified. @@ -239,7 +237,7 @@ function is_category( $category = '' ) { } /** - * Is the query for a tag archive page? + * Is the query for an existing tag archive page? * * If the $tag parameter is specified, this function will additionally * check if the query is for one of the tags specified. @@ -263,7 +261,7 @@ function is_tag( $slug = '' ) { } /** - * Is the query for a taxonomy archive page? + * Is the query for an existing taxonomy archive page? * * If the $taxonomy parameter is specified, this function will additionally * check if the query is for that specific $taxonomy. @@ -312,7 +310,7 @@ function is_comments_popup() { } /** - * Is the query for a date archive? + * Is the query for an existing date archive? * * @see WP_Query::is_date() * @since 1.5.0 @@ -332,7 +330,7 @@ function is_date() { } /** - * Is the query for a day archive? + * Is the query for an existing day archive? * * @see WP_Query::is_day() * @since 1.5.0 @@ -452,7 +450,7 @@ function is_home() { } /** - * Is the query for a month archive? + * Is the query for an existing month archive? * * @see WP_Query::is_month() * @since 1.5.0 @@ -472,7 +470,7 @@ function is_month() { } /** - * Is the query for a single page? + * Is the query for an existing single page? * * If the $page parameter is specified, this function will additionally * check if the query is for one of the pages specified. @@ -579,7 +577,7 @@ function is_search() { } /** - * Is the query for a single post? + * Is the query for an existing single post? * * Works for any post type, except attachments and pages * @@ -608,7 +606,7 @@ function is_single( $post = '' ) { } /** - * Is the query for a single post of any post type (post, attachment, page, ... )? + * Is the query for an existing single post of any post type (post, attachment, page, ... )? * * If the $post_types parameter is specified, this function will additionally * check if the query is for one of the Posts Types specified. @@ -675,7 +673,7 @@ function is_trackback() { } /** - * Is the query for a specific year? + * Is the query for an existing year archive? * * @see WP_Query::is_year() * @since 1.5.0 @@ -979,7 +977,9 @@ class WP_Query { var $comment; /** - * Amount of posts if limit clause was not used. + * The amount of found posts for the current query. + * + * If limit clause was not used, equals $post_count. * * @since 2.1.0 * @access public @@ -1398,6 +1398,7 @@ class WP_Query { , 's' , 'sentence' , 'fields' + , 'menu_order' ); foreach ( $keys as $key ) { @@ -1452,6 +1453,7 @@ class WP_Query { if ( '' !== $qv['hour'] ) $qv['hour'] = absint($qv['hour']); if ( '' !== $qv['minute'] ) $qv['minute'] = absint($qv['minute']); if ( '' !== $qv['second'] ) $qv['second'] = absint($qv['second']); + if ( '' !== $qv['menu_order'] ) $qv['menu_order'] = absint($qv['menu_order']); // Compat. Map subpost to attachment. if ( '' != $qv['subpost'] ) @@ -1785,13 +1787,13 @@ class WP_Query { // Tag stuff if ( '' != $q['tag'] && !$this->is_singular && $this->query_vars_changed ) { if ( strpos($q['tag'], ',') !== false ) { - $tags = preg_split('/[,\s]+/', $q['tag']); + $tags = preg_split('/[,\r\n\t ]+/', $q['tag']); foreach ( (array) $tags as $tag ) { $tag = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db'); $q['tag_slug__in'][] = $tag; } - } else if ( preg_match('/[+\s]+/', $q['tag']) || !empty($q['cat']) ) { - $tags = preg_split('/[+\s]+/', $q['tag']); + } else if ( preg_match('/[+\r\n\t ]+/', $q['tag']) || !empty($q['cat']) ) { + $tags = preg_split('/[+\r\n\t ]+/', $q['tag']); foreach ( (array) $tags as $tag ) { $tag = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db'); $q['tag_slug__and'][] = $tag; @@ -1914,7 +1916,7 @@ class WP_Query { * * @return array List of posts. */ - function &get_posts() { + function get_posts() { global $wpdb, $user_ID, $_wp_using_ext_object_cache; $this->parse_query(); @@ -2040,6 +2042,9 @@ class WP_Query { $fields = "$wpdb->posts.*"; } + if ( '' !== $q['menu_order'] ) + $where .= " AND $wpdb->posts.menu_order = " . $q['menu_order']; + // If a month is specified in the querystring, load that month if ( $q['m'] ) { $q['m'] = '' . preg_replace('|[^0-9]|', '', $q['m']); @@ -2128,7 +2133,7 @@ class WP_Query { $q['pagename'] = sanitize_title_for_query( wp_basename( $q['pagename'] ) ); $q['name'] = $q['pagename']; $where .= " AND ($wpdb->posts.ID = '$reqpage')"; - $reqpage_obj = get_page($reqpage); + $reqpage_obj = get_post( $reqpage ); if ( is_object($reqpage_obj) && 'attachment' == $reqpage_obj->post_type ) { $this->is_attachment = true; $post_type = $q['post_type'] = 'attachment'; @@ -2177,6 +2182,8 @@ class WP_Query { if ( !empty($q['s']) ) { // added slashes screw with quote grouping when done early, so done later $q['s'] = stripslashes($q['s']); + if ( empty( $_GET['s'] ) && $this->is_main_query() ) + $q['s'] = urldecode($q['s']); if ( !empty($q['sentence']) ) { $q['search_terms'] = array($q['s']); } else { @@ -2213,7 +2220,17 @@ class WP_Query { if ( $this->is_tax ) { if ( empty($post_type) ) { - $post_type = 'any'; + // Do a fully inclusive search for currently registered post types of queried taxonomies + $post_type = array(); + $taxonomies = wp_list_pluck( $this->tax_query->queries, 'taxonomy' ); + foreach ( get_post_types( array( 'exclude_from_search' => false ) ) as $pt ) { + $object_taxonomies = $pt === 'attachment' ? get_taxonomies_for_attachments() : get_object_taxonomies( $pt ); + if ( array_intersect( $taxonomies, $object_taxonomies ) ) + $post_type[] = $pt; + } + if ( ! $post_type ) + $post_type = 'any'; + $post_status_join = true; } elseif ( in_array('attachment', (array) $post_type) ) { $post_status_join = true; @@ -2324,6 +2341,8 @@ class WP_Query { $orderby = "$wpdb->posts.post_date " . $q['order']; } elseif ( 'none' == $q['orderby'] ) { $orderby = ''; + } elseif ( $q['orderby'] == 'post__in' && ! empty( $post__in ) ) { + $orderby = "FIELD( {$wpdb->posts}.ID, $post__in )"; } else { // Used to filter values $allowed_keys = array('name', 'author', 'date', 'title', 'modified', 'menu_order', 'parent', 'ID', 'rand', 'comment_count'); @@ -2386,7 +2405,7 @@ class WP_Query { if ( 'any' == $post_type ) { $in_search_post_types = get_post_types( array('exclude_from_search' => false) ); if ( ! empty( $in_search_post_types ) ) - $where .= $wpdb->prepare(" AND $wpdb->posts.post_type IN ('" . join("', '", $in_search_post_types ) . "')"); + $where .= " AND $wpdb->posts.post_type IN ('" . join("', '", $in_search_post_types ) . "')"; } elseif ( !empty( $post_type ) && is_array( $post_type ) ) { $where .= " AND $wpdb->posts.post_type IN ('" . join("', '", $post_type) . "')"; } elseif ( ! empty( $post_type ) ) { @@ -2612,13 +2631,17 @@ class WP_Query { } if ( 'ids' == $q['fields'] ) { - $this->posts = $wpdb->get_col($this->request); + $this->posts = $wpdb->get_col( $this->request ); + $this->post_count = count( $this->posts ); + $this->set_found_posts( $q, $limits ); return $this->posts; } if ( 'id=>parent' == $q['fields'] ) { - $this->posts = $wpdb->get_results($this->request); + $this->posts = $wpdb->get_results( $this->request ); + $this->post_count = count( $this->posts ); + $this->set_found_posts( $q, $limits ); $r = array(); foreach ( $this->posts as $post ) @@ -2640,13 +2663,10 @@ class WP_Query { $ids = $wpdb->get_col( $this->request ); if ( $ids ) { + $this->posts = $ids; $this->set_found_posts( $q, $limits ); - _prime_post_caches( $ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] ); - - $this->posts = array_map( 'get_post', $ids ); } else { - $this->found_posts = $this->max_num_pages = 0; $this->posts = array(); } } else { @@ -2654,6 +2674,10 @@ class WP_Query { $this->set_found_posts( $q, $limits ); } + // Convert to WP_Post objects + if ( $this->posts ) + $this->posts = array_map( 'get_post', $this->posts ); + // Raw results filter. Prior to status checks. if ( !$q['suppress_filters'] ) $this->posts = apply_filters_ref_array('posts_results', array( $this->posts, &$this ) ); @@ -2700,7 +2724,7 @@ class WP_Query { } if ( $this->is_preview && $this->posts && current_user_can( $edit_cap, $this->posts[0]->ID ) ) - $this->posts[0] = apply_filters_ref_array('the_preview', array( $this->posts[0], &$this )); + $this->posts[0] = get_post( apply_filters_ref_array( 'the_preview', array( $this->posts[0], &$this ) ) ); } // Put sticky posts at the top of the posts array @@ -2730,24 +2754,15 @@ class WP_Query { // Fetch sticky posts that weren't in the query results if ( !empty($sticky_posts) ) { - $stickies__in = implode(',', array_map( 'absint', $sticky_posts )); - // honor post type(s) if not set to any - $stickies_where = ''; - if ( 'any' != $post_type && '' != $post_type ) { - if ( is_array( $post_type ) ) { - $post_types = join( "', '", $post_type ); - } else { - $post_types = $post_type; - } - $stickies_where = "AND $wpdb->posts.post_type IN ('" . $post_types . "')"; - } + $stickies = get_posts( array( + 'post__in' => $sticky_posts, + 'post_type' => $post_type, + 'post_status' => 'publish', + 'nopaging' => true + ) ); - $stickies = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE $wpdb->posts.ID IN ($stickies__in) $stickies_where" ); foreach ( $stickies as $sticky_post ) { - // Ignore sticky posts the current user cannot read or are not published. - if ( 'publish' != $sticky_post->post_status ) - continue; - array_splice($this->posts, $sticky_offset, 0, array($sticky_post)); + array_splice( $this->posts, $sticky_offset, 0, array( $sticky_post ) ); $sticky_offset++; } } @@ -2756,33 +2771,49 @@ class WP_Query { if ( !$q['suppress_filters'] ) $this->posts = apply_filters_ref_array('the_posts', array( $this->posts, &$this ) ); - $this->post_count = count($this->posts); + // Ensure that any posts added/modified via one of the filters above are + // of the type WP_Post and are filtered. + if ( $this->posts ) { + $this->post_count = count( $this->posts ); - // Always sanitize - foreach ( $this->posts as $i => $post ) { - $this->posts[$i] = sanitize_post( $post, 'raw' ); - } + $this->posts = array_map( 'get_post', $this->posts ); - if ( $q['cache_results'] ) - update_post_caches($this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache']); + if ( $q['cache_results'] ) + update_post_caches($this->posts, $post_type, $q['update_post_term_cache'], $q['update_post_meta_cache']); - if ( $this->post_count > 0 ) { - $this->post = $this->posts[0]; + $this->post = reset( $this->posts ); + } else { + $this->post_count = 0; + $this->posts = array(); } return $this->posts; } + /** + * Set up the amount of found posts and the number of pages (if limit clause was used) + * for the current query. + * + * @since 3.5.0 + * @access private + */ function set_found_posts( $q, $limits ) { global $wpdb; - if ( $q['no_found_rows'] || empty( $limits ) ) + // Bail if posts is an empty array. Continue if posts is an empty string + // null, or false to accommodate caching plugins that fill posts later. + if ( $q['no_found_rows'] || ( is_array( $this->posts ) && ! $this->posts ) ) return; - $this->found_posts = $wpdb->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) ); + if ( ! empty( $limits ) ) + $this->found_posts = $wpdb->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) ); + else + $this->found_posts = count( $this->posts ); + $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) ); - $this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] ); + if ( ! empty( $limits ) ) + $this->max_num_pages = ceil( $this->found_posts / $q['posts_per_page'] ); } /** @@ -2791,7 +2822,7 @@ class WP_Query { * @since 1.5.0 * @access public * - * @return object Next post. + * @return WP_Post Next post. */ function next_post() { @@ -2935,7 +2966,7 @@ class WP_Query { * @param string $query URL query string. * @return array List of posts. */ - function &query( $query ) { + function query( $query ) { $this->init(); $this->query = $this->query_vars = wp_parse_args( $query ); return $this->get_posts(); @@ -2967,10 +2998,10 @@ class WP_Query { if ( 'term_id' == $query['field'] ) $term = get_term( reset( $query['terms'] ), $query['taxonomy'] ); - else + elseif ( $query['terms'] ) $term = get_term_by( $query['field'], reset( $query['terms'] ), $query['taxonomy'] ); - if ( $term && ! is_wp_error($term) ) { + if ( ! empty( $term ) && ! is_wp_error( $term ) ) { $this->queried_object = $term; $this->queried_object_id = (int) $term->term_id; @@ -2981,7 +3012,7 @@ class WP_Query { $this->queried_object = get_post_type_object( $this->get('post_type') ); } elseif ( $this->is_posts_page ) { $page_for_posts = get_option('page_for_posts'); - $this->queried_object = get_page( $page_for_posts ); + $this->queried_object = get_post( $page_for_posts ); $this->queried_object_id = (int) $this->queried_object->ID; } elseif ( $this->is_singular && !is_null($this->post) ) { $this->queried_object = $this->post; @@ -3030,7 +3061,7 @@ class WP_Query { } /** - * Is the query for an archive page? + * Is the query for an existing archive page? * * Month, Year, Category, Author, Post Type archive... * @@ -3043,7 +3074,7 @@ class WP_Query { } /** - * Is the query for a post type archive page? + * Is the query for an existing post type archive page? * * @since 3.1.0 * @@ -3060,7 +3091,7 @@ class WP_Query { } /** - * Is the query for an attachment page? + * Is the query for an existing attachment page? * * @since 3.1.0 * @@ -3071,7 +3102,7 @@ class WP_Query { } /** - * Is the query for an author archive page? + * Is the query for an existing author archive page? * * If the $author parameter is specified, this function will additionally * check if the query is for one of the authors specified. @@ -3103,7 +3134,7 @@ class WP_Query { } /** - * Is the query for a category archive page? + * Is the query for an existing category archive page? * * If the $category parameter is specified, this function will additionally * check if the query is for one of the categories specified. @@ -3135,7 +3166,7 @@ class WP_Query { } /** - * Is the query for a tag archive page? + * Is the query for an existing tag archive page? * * If the $tag parameter is specified, this function will additionally * check if the query is for one of the tags specified. @@ -3163,7 +3194,7 @@ class WP_Query { } /** - * Is the query for a taxonomy archive page? + * Is the query for an existing taxonomy archive page? * * If the $taxonomy parameter is specified, this function will additionally * check if the query is for that specific $taxonomy. @@ -3191,8 +3222,13 @@ class WP_Query { $tax_array = array_intersect( array_keys( $wp_taxonomies ), (array) $taxonomy ); $term_array = (array) $term; - if ( empty( $term ) ) // Only a Taxonomy provided - return isset( $queried_object->taxonomy ) && count( $tax_array ) && in_array( $queried_object->taxonomy, $tax_array ); + // Check that the taxonomy matches. + if ( ! ( isset( $queried_object->taxonomy ) && count( $tax_array ) && in_array( $queried_object->taxonomy, $tax_array ) ) ) + return false; + + // Only a Taxonomy provided. + if ( empty( $term ) ) + return true; return isset( $queried_object->term_id ) && count( array_intersect( @@ -3213,7 +3249,7 @@ class WP_Query { } /** - * Is the query for a date archive? + * Is the query for an existing date archive? * * @since 3.1.0 * @@ -3224,7 +3260,7 @@ class WP_Query { } /** - * Is the query for a day archive? + * Is the query for an existing day archive? * * @since 3.1.0 * @@ -3311,7 +3347,7 @@ class WP_Query { } /** - * Is the query for a month archive? + * Is the query for an existing month archive? * * @since 3.1.0 * @@ -3322,7 +3358,7 @@ class WP_Query { } /** - * Is the query for a single page? + * Is the query for an existing single page? * * If the $page parameter is specified, this function will additionally * check if the query is for one of the pages specified. @@ -3401,7 +3437,7 @@ class WP_Query { } /** - * Is the query for a single post? + * Is the query for an existing single post? * * Works for any post type, except attachments and pages * @@ -3438,7 +3474,7 @@ class WP_Query { } /** - * Is the query for a single post of any post type (post, attachment, page, ... )? + * Is the query for an existing single post of any post type (post, attachment, page, ... )? * * If the $post_types parameter is specified, this function will additionally * check if the query is for one of the Posts Types specified. @@ -3483,7 +3519,7 @@ class WP_Query { } /** - * Is the query for a specific year? + * Is the query for an existing year archive? * * @since 3.1.0 * diff --git a/wp-includes/rewrite.php b/wp-includes/rewrite.php index 740ffebb..486922a3 100644 --- a/wp-includes/rewrite.php +++ b/wp-includes/rewrite.php @@ -1525,8 +1525,11 @@ class WP_Rewrite { $home_path = parse_url( home_url() ); $robots_rewrite = ( empty( $home_path['path'] ) || '/' == $home_path['path'] ) ? array( 'robots\.txt$' => $this->index . '?robots=1' ) : array(); - // Old feed files - $old_feed_files = array( '.*wp-(atom|rdf|rss|rss2|feed|commentsrss2)\.php$' => $this->index . '?feed=old' ); + // Old feed and service files + $deprecated_files = array( + '.*wp-(atom|rdf|rss|rss2|feed|commentsrss2)\.php$' => $this->index . '?feed=old', + '.*wp-app\.php(/.*)?$' => $this->index . '?error=403', + ); // Registration rules $registration_pages = array(); @@ -1585,9 +1588,9 @@ class WP_Rewrite { // Put them together. if ( $this->use_verbose_page_rules ) - $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $old_feed_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite, $author_rewrite, $date_rewrite, $page_rewrite, $post_rewrite, $this->extra_rules); + $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $deprecated_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite, $author_rewrite, $date_rewrite, $page_rewrite, $post_rewrite, $this->extra_rules); else - $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $old_feed_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $page_rewrite, $this->extra_rules); + $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $deprecated_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite, $author_rewrite, $date_rewrite, $post_rewrite, $page_rewrite, $this->extra_rules); do_action_ref_array('generate_rewrite_rules', array(&$this)); $this->rules = apply_filters('rewrite_rules_array', $this->rules); @@ -1638,7 +1641,7 @@ class WP_Rewrite { if ( ! $this->using_permalinks() ) return ''; - $site_root = parse_url(get_option('siteurl')); + $site_root = parse_url( site_url() ); if ( isset( $site_root['path'] ) ) $site_root = trailingslashit($site_root['path']); @@ -1726,75 +1729,17 @@ class WP_Rewrite { '; } - if ( !is_multisite() ) { - $rules .= ' - - - - - - - - '; - } else { - if (is_subdomain_install()) { - $rules .= ' - - - - - - - - - - - - - - - - - - - - '; - } else { - $rules .= ' - - - - - - - - - - - - - - - - - + + $rules .= ' + + + + + - - - - - - - - - - - - - - '; - } - } + + '; + if ( $add_parent_tags ) { $rules .= ' @@ -1995,9 +1940,10 @@ class WP_Rewrite { */ function set_permalink_structure($permalink_structure) { if ( $permalink_structure != $this->permalink_structure ) { + $old_permalink_structure = $this->permalink_structure; update_option('permalink_structure', $permalink_structure); $this->init(); - do_action('permalink_structure_changed', $this->permalink_structure, $permalink_structure); + do_action('permalink_structure_changed', $old_permalink_structure, $permalink_structure); } } diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 28b4edbe..efc71e60 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -57,9 +57,14 @@ function wp_default_scripts( &$scripts ) { $scripts->default_version = get_bloginfo( 'version' ); $scripts->default_dirs = array('/wp-admin/js/', '/wp-includes/js/'); - $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '.dev' : ''; + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; - $scripts->add( 'utils', "/wp-admin/js/utils$suffix.js" ); + $scripts->add( 'utils', "/wp-includes/js/utils$suffix.js" ); + did_action( 'init' ) && $scripts->localize( 'utils', 'userSettings', array( + 'url' => (string) SITECOOKIEPATH, + 'uid' => (string) get_current_user_id(), + 'time' => (string) time(), + ) ); $scripts->add( 'common', "/wp-admin/js/common$suffix.js", array('jquery', 'hoverIntent', 'utils'), false, 1 ); did_action( 'init' ) && $scripts->localize( 'common', 'commonL10n', array( @@ -90,8 +95,6 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'wp-fullscreen', "/wp-admin/js/wp-fullscreen$suffix.js", array('jquery'), false, 1 ); - $scripts->add( 'prototype', '/wp-includes/js/prototype.js', array(), '1.6.1'); - $scripts->add( 'wp-ajax-response', "/wp-includes/js/wp-ajax-response$suffix.js", array('jquery'), false, 1 ); did_action( 'init' ) && $scripts->localize( 'wp-ajax-response', 'wpAjax', array( 'noPerm' => __('You do not have permission to do that.'), @@ -105,62 +108,67 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'autosave', "/wp-includes/js/autosave$suffix.js", array('schedule', 'wp-ajax-response'), false, 1 ); - $scripts->add( 'wp-lists', "/wp-includes/js/wp-lists$suffix.js", array('wp-ajax-response'), false, 1 ); + $scripts->add( 'wp-lists', "/wp-includes/js/wp-lists$suffix.js", array( 'wp-ajax-response', 'jquery-color' ), false, 1 ); - $scripts->add( 'scriptaculous-root', '/wp-includes/js/scriptaculous/wp-scriptaculous.js', array('prototype'), '1.8.3'); - $scripts->add( 'scriptaculous-builder', '/wp-includes/js/scriptaculous/builder.js', array('scriptaculous-root'), '1.8.3'); - $scripts->add( 'scriptaculous-dragdrop', '/wp-includes/js/scriptaculous/dragdrop.js', array('scriptaculous-builder', 'scriptaculous-effects'), '1.8.3'); - $scripts->add( 'scriptaculous-effects', '/wp-includes/js/scriptaculous/effects.js', array('scriptaculous-root'), '1.8.3'); - $scripts->add( 'scriptaculous-slider', '/wp-includes/js/scriptaculous/slider.js', array('scriptaculous-effects'), '1.8.3'); - $scripts->add( 'scriptaculous-sound', '/wp-includes/js/scriptaculous/sound.js', array( 'scriptaculous-root' ), '1.8.3' ); - $scripts->add( 'scriptaculous-controls', '/wp-includes/js/scriptaculous/controls.js', array('scriptaculous-root'), '1.8.3'); - $scripts->add( 'scriptaculous', '', array('scriptaculous-dragdrop', 'scriptaculous-slider', 'scriptaculous-controls'), '1.8.3'); + // WordPress no longer uses or bundles Prototype or script.aculo.us. These are now pulled from an external source. + $scripts->add( 'prototype', '//ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js', array(), '1.7.1'); + $scripts->add( 'scriptaculous-root', '//ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/scriptaculous.js', array('prototype'), '1.9.0'); + $scripts->add( 'scriptaculous-builder', '//ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/builder.js', array('scriptaculous-root'), '1.9.0'); + $scripts->add( 'scriptaculous-dragdrop', '//ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/dragdrop.js', array('scriptaculous-builder', 'scriptaculous-effects'), '1.9.0'); + $scripts->add( 'scriptaculous-effects', '//ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/effects.js', array('scriptaculous-root'), '1.9.0'); + $scripts->add( 'scriptaculous-slider', '//ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/slider.js', array('scriptaculous-effects'), '1.9.0'); + $scripts->add( 'scriptaculous-sound', '//ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/sound.js', array( 'scriptaculous-root' ), '1.9.0' ); + $scripts->add( 'scriptaculous-controls', '//ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/controls.js', array('scriptaculous-root'), '1.9.0'); + $scripts->add( 'scriptaculous', false, array('scriptaculous-dragdrop', 'scriptaculous-slider', 'scriptaculous-controls') ); // not used in core, replaced by Jcrop.js $scripts->add( 'cropper', '/wp-includes/js/crop/cropper.js', array('scriptaculous-dragdrop') ); - $scripts->add( 'jquery', '/wp-includes/js/jquery/jquery.js', array(), '1.7.2' ); + $scripts->add( 'jquery', '/wp-includes/js/jquery/jquery.js', array(), '1.8.3' ); // full jQuery UI - $scripts->add( 'jquery-ui-core', '/wp-includes/js/jquery/ui/jquery.ui.core.min.js', array('jquery'), '1.8.20', 1 ); - $scripts->add( 'jquery-effects-core', '/wp-includes/js/jquery/ui/jquery.effects.core.min.js', array('jquery'), '1.8.20', 1 ); - - $scripts->add( 'jquery-effects-blind', '/wp-includes/js/jquery/ui/jquery.effects.blind.min.js', array('jquery-effects-core'), '1.8.20', 1 ); - $scripts->add( 'jquery-effects-bounce', '/wp-includes/js/jquery/ui/jquery.effects.bounce.min.js', array('jquery-effects-core'), '1.8.20', 1 ); - $scripts->add( 'jquery-effects-clip', '/wp-includes/js/jquery/ui/jquery.effects.clip.min.js', array('jquery-effects-core'), '1.8.20', 1 ); - $scripts->add( 'jquery-effects-drop', '/wp-includes/js/jquery/ui/jquery.effects.drop.min.js', array('jquery-effects-core'), '1.8.20', 1 ); - $scripts->add( 'jquery-effects-explode', '/wp-includes/js/jquery/ui/jquery.effects.explode.min.js', array('jquery-effects-core'), '1.8.20', 1 ); - $scripts->add( 'jquery-effects-fade', '/wp-includes/js/jquery/ui/jquery.effects.fade.min.js', array('jquery-effects-core'), '1.8.20', 1 ); - $scripts->add( 'jquery-effects-fold', '/wp-includes/js/jquery/ui/jquery.effects.fold.min.js', array('jquery-effects-core'), '1.8.20', 1 ); - $scripts->add( 'jquery-effects-highlight', '/wp-includes/js/jquery/ui/jquery.effects.highlight.min.js', array('jquery-effects-core'), '1.8.20', 1 ); - $scripts->add( 'jquery-effects-pulsate', '/wp-includes/js/jquery/ui/jquery.effects.pulsate.min.js', array('jquery-effects-core'), '1.8.20', 1 ); - $scripts->add( 'jquery-effects-scale', '/wp-includes/js/jquery/ui/jquery.effects.scale.min.js', array('jquery-effects-core'), '1.8.20', 1 ); - $scripts->add( 'jquery-effects-shake', '/wp-includes/js/jquery/ui/jquery.effects.shake.min.js', array('jquery-effects-core'), '1.8.20', 1 ); - $scripts->add( 'jquery-effects-slide', '/wp-includes/js/jquery/ui/jquery.effects.slide.min.js', array('jquery-effects-core'), '1.8.20', 1 ); - $scripts->add( 'jquery-effects-transfer', '/wp-includes/js/jquery/ui/jquery.effects.transfer.min.js', array('jquery-effects-core'), '1.8.20', 1 ); - - $scripts->add( 'jquery-ui-accordion', '/wp-includes/js/jquery/ui/jquery.ui.accordion.min.js', array('jquery-ui-core', 'jquery-ui-widget'), '1.8.20', 1 ); - $scripts->add( 'jquery-ui-autocomplete', '/wp-includes/js/jquery/ui/jquery.ui.autocomplete.min.js', array('jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-position'), '1.8.20', 1 ); - $scripts->add( 'jquery-ui-button', '/wp-includes/js/jquery/ui/jquery.ui.button.min.js', array('jquery-ui-core', 'jquery-ui-widget'), '1.8.20', 1 ); - $scripts->add( 'jquery-ui-datepicker', '/wp-includes/js/jquery/ui/jquery.ui.datepicker.min.js', array('jquery-ui-core'), '1.8.20', 1 ); - $scripts->add( 'jquery-ui-dialog', '/wp-includes/js/jquery/ui/jquery.ui.dialog.min.js', array('jquery-ui-resizable', 'jquery-ui-draggable', 'jquery-ui-button', 'jquery-ui-position'), '1.8.20', 1 ); - $scripts->add( 'jquery-ui-draggable', '/wp-includes/js/jquery/ui/jquery.ui.draggable.min.js', array('jquery-ui-core', 'jquery-ui-mouse'), '1.8.20', 1 ); - $scripts->add( 'jquery-ui-droppable', '/wp-includes/js/jquery/ui/jquery.ui.droppable.min.js', array('jquery-ui-draggable'), '1.8.20', 1 ); - $scripts->add( 'jquery-ui-mouse', '/wp-includes/js/jquery/ui/jquery.ui.mouse.min.js', array('jquery-ui-widget'), '1.8.20', 1 ); - $scripts->add( 'jquery-ui-position', '/wp-includes/js/jquery/ui/jquery.ui.position.min.js', array('jquery'), '1.8.20', 1 ); - $scripts->add( 'jquery-ui-progressbar', '/wp-includes/js/jquery/ui/jquery.ui.progressbar.min.js', array('jquery-ui-widget'), '1.8.20', 1 ); - $scripts->add( 'jquery-ui-resizable', '/wp-includes/js/jquery/ui/jquery.ui.resizable.min.js', array('jquery-ui-core', 'jquery-ui-mouse'), '1.8.20', 1 ); - $scripts->add( 'jquery-ui-selectable', '/wp-includes/js/jquery/ui/jquery.ui.selectable.min.js', array('jquery-ui-core', 'jquery-ui-mouse'), '1.8.20', 1 ); - $scripts->add( 'jquery-ui-slider', '/wp-includes/js/jquery/ui/jquery.ui.slider.min.js', array('jquery-ui-core', 'jquery-ui-mouse'), '1.8.20', 1 ); - $scripts->add( 'jquery-ui-sortable', '/wp-includes/js/jquery/ui/jquery.ui.sortable.min.js', array('jquery-ui-core', 'jquery-ui-mouse'), '1.8.20', 1 ); - $scripts->add( 'jquery-ui-tabs', '/wp-includes/js/jquery/ui/jquery.ui.tabs.min.js', array('jquery-ui-core', 'jquery-ui-widget'), '1.8.20', 1 ); - $scripts->add( 'jquery-ui-widget', '/wp-includes/js/jquery/ui/jquery.ui.widget.min.js', array('jquery'), '1.8.20', 1 ); + $scripts->add( 'jquery-ui-core', '/wp-includes/js/jquery/ui/jquery.ui.core.min.js', array('jquery'), '1.9.2', 1 ); + $scripts->add( 'jquery-effects-core', '/wp-includes/js/jquery/ui/jquery.ui.effect.min.js', array('jquery'), '1.9.2', 1 ); + + $scripts->add( 'jquery-effects-blind', '/wp-includes/js/jquery/ui/jquery.ui.effect-blind.min.js', array('jquery-effects-core'), '1.9.2', 1 ); + $scripts->add( 'jquery-effects-bounce', '/wp-includes/js/jquery/ui/jquery.ui.effect-bounce.min.js', array('jquery-effects-core'), '1.9.2', 1 ); + $scripts->add( 'jquery-effects-clip', '/wp-includes/js/jquery/ui/jquery.ui.effect-clip.min.js', array('jquery-effects-core'), '1.9.2', 1 ); + $scripts->add( 'jquery-effects-drop', '/wp-includes/js/jquery/ui/jquery.ui.effect-drop.min.js', array('jquery-effects-core'), '1.9.2', 1 ); + $scripts->add( 'jquery-effects-explode', '/wp-includes/js/jquery/ui/jquery.ui.effect-explode.min.js', array('jquery-effects-core'), '1.9.2', 1 ); + $scripts->add( 'jquery-effects-fade', '/wp-includes/js/jquery/ui/jquery.ui.effect-fade.min.js', array('jquery-effects-core'), '1.9.2', 1 ); + $scripts->add( 'jquery-effects-fold', '/wp-includes/js/jquery/ui/jquery.ui.effect-fold.min.js', array('jquery-effects-core'), '1.9.2', 1 ); + $scripts->add( 'jquery-effects-highlight', '/wp-includes/js/jquery/ui/jquery.ui.effect-highlight.min.js', array('jquery-effects-core'), '1.9.2', 1 ); + $scripts->add( 'jquery-effects-pulsate', '/wp-includes/js/jquery/ui/jquery.ui.effect-pulsate.min.js', array('jquery-effects-core'), '1.9.2', 1 ); + $scripts->add( 'jquery-effects-scale', '/wp-includes/js/jquery/ui/jquery.ui.effect-scale.min.js', array('jquery-effects-core'), '1.9.2', 1 ); + $scripts->add( 'jquery-effects-shake', '/wp-includes/js/jquery/ui/jquery.ui.effect-shake.min.js', array('jquery-effects-core'), '1.9.2', 1 ); + $scripts->add( 'jquery-effects-slide', '/wp-includes/js/jquery/ui/jquery.ui.effect-slide.min.js', array('jquery-effects-core'), '1.9.2', 1 ); + $scripts->add( 'jquery-effects-transfer', '/wp-includes/js/jquery/ui/jquery.ui.effect-transfer.min.js', array('jquery-effects-core'), '1.9.2', 1 ); + + $scripts->add( 'jquery-ui-accordion', '/wp-includes/js/jquery/ui/jquery.ui.accordion.min.js', array('jquery-ui-core', 'jquery-ui-widget'), '1.9.2', 1 ); + $scripts->add( 'jquery-ui-autocomplete', '/wp-includes/js/jquery/ui/jquery.ui.autocomplete.min.js', array('jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-position', 'jquery-ui-menu'), '1.9.2', 1 ); + $scripts->add( 'jquery-ui-button', '/wp-includes/js/jquery/ui/jquery.ui.button.min.js', array('jquery-ui-core', 'jquery-ui-widget'), '1.9.2', 1 ); + $scripts->add( 'jquery-ui-datepicker', '/wp-includes/js/jquery/ui/jquery.ui.datepicker.min.js', array('jquery-ui-core'), '1.9.2', 1 ); + $scripts->add( 'jquery-ui-dialog', '/wp-includes/js/jquery/ui/jquery.ui.dialog.min.js', array('jquery-ui-resizable', 'jquery-ui-draggable', 'jquery-ui-button', 'jquery-ui-position'), '1.9.2', 1 ); + $scripts->add( 'jquery-ui-draggable', '/wp-includes/js/jquery/ui/jquery.ui.draggable.min.js', array('jquery-ui-core', 'jquery-ui-mouse'), '1.9.2', 1 ); + $scripts->add( 'jquery-ui-droppable', '/wp-includes/js/jquery/ui/jquery.ui.droppable.min.js', array('jquery-ui-draggable'), '1.9.2', 1 ); + $scripts->add( 'jquery-ui-menu', '/wp-includes/js/jquery/ui/jquery.ui.menu.min.js', array( 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-position' ), '1.9.2', 1 ); + $scripts->add( 'jquery-ui-mouse', '/wp-includes/js/jquery/ui/jquery.ui.mouse.min.js', array('jquery-ui-widget'), '1.9.2', 1 ); + $scripts->add( 'jquery-ui-position', '/wp-includes/js/jquery/ui/jquery.ui.position.min.js', array('jquery'), '1.9.2', 1 ); + $scripts->add( 'jquery-ui-progressbar', '/wp-includes/js/jquery/ui/jquery.ui.progressbar.min.js', array('jquery-ui-widget'), '1.9.2', 1 ); + $scripts->add( 'jquery-ui-resizable', '/wp-includes/js/jquery/ui/jquery.ui.resizable.min.js', array('jquery-ui-core', 'jquery-ui-mouse'), '1.9.2', 1 ); + $scripts->add( 'jquery-ui-selectable', '/wp-includes/js/jquery/ui/jquery.ui.selectable.min.js', array('jquery-ui-core', 'jquery-ui-mouse'), '1.9.2', 1 ); + $scripts->add( 'jquery-ui-slider', '/wp-includes/js/jquery/ui/jquery.ui.slider.min.js', array('jquery-ui-core', 'jquery-ui-mouse'), '1.9.2', 1 ); + $scripts->add( 'jquery-ui-sortable', '/wp-includes/js/jquery/ui/jquery.ui.sortable.min.js', array('jquery-ui-core', 'jquery-ui-mouse'), '1.9.2', 1 ); + $scripts->add( 'jquery-ui-spinner', '/wp-includes/js/jquery/ui/jquery.ui.spinner.min.js', array( 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-button' ), '1.9.2', 1 ); + $scripts->add( 'jquery-ui-tabs', '/wp-includes/js/jquery/ui/jquery.ui.tabs.min.js', array('jquery-ui-core', 'jquery-ui-widget'), '1.9.2', 1 ); + $scripts->add( 'jquery-ui-tooltip', '/wp-includes/js/jquery/ui/jquery.ui.tooltip.min.js', array( 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-position' ), '1.9.2', 1 ); + $scripts->add( 'jquery-ui-widget', '/wp-includes/js/jquery/ui/jquery.ui.widget.min.js', array('jquery'), '1.9.2', 1 ); // deprecated, not used in core, most functionality is included in jQuery 1.3 $scripts->add( 'jquery-form', "/wp-includes/js/jquery/jquery.form$suffix.js", array('jquery'), '2.73', 1 ); // jQuery plugins - $scripts->add( 'jquery-color', "/wp-includes/js/jquery/jquery.color$suffix.js", array('jquery'), '2.0-4561m', 1 ); + $scripts->add( 'jquery-color', "/wp-includes/js/jquery/jquery.color.min.js", array('jquery'), '2.1.0', 1 ); $scripts->add( 'suggest', "/wp-includes/js/jquery/suggest$suffix.js", array('jquery'), '1.1-20110113', 1 ); $scripts->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array('jquery'), '20m', 1 ); $scripts->add( 'jquery-query', "/wp-includes/js/jquery/jquery.query.js", array('jquery'), '2.1.7', 1 ); @@ -168,8 +176,9 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'jquery-hotkeys', "/wp-includes/js/jquery/jquery.hotkeys$suffix.js", array('jquery'), '0.0.2m', 1 ); $scripts->add( 'jquery-table-hotkeys', "/wp-includes/js/jquery/jquery.table-hotkeys$suffix.js", array('jquery', 'jquery-hotkeys'), false, 1 ); $scripts->add( 'jquery-touch-punch', "/wp-includes/js/jquery/jquery.ui.touch-punch.js", array('jquery-ui-widget', 'jquery-ui-mouse'), '0.2.2', 1 ); + $scripts->add( 'jquery-masonry', "/wp-includes/js/jquery/jquery.masonry.min.js", array('jquery'), '2.1.05', 1 ); - $scripts->add( 'thickbox', "/wp-includes/js/thickbox/thickbox.js", array('jquery'), '3.1-20111117', 1 ); + $scripts->add( 'thickbox', "/wp-includes/js/thickbox/thickbox.js", array('jquery'), '3.1-20121105', 1 ); did_action( 'init' ) && $scripts->localize( 'thickbox', 'thickboxL10n', array( 'next' => __('Next >'), 'prev' => __('< Prev'), @@ -181,7 +190,7 @@ function wp_default_scripts( &$scripts ) { 'closeImage' => includes_url('js/thickbox/tb-close.png') ) ); - $scripts->add( 'jcrop', "/wp-includes/js/jcrop/jquery.Jcrop$suffix.js", array('jquery'), '0.9.8-20110113'); + $scripts->add( 'jcrop', "/wp-includes/js/jcrop/jquery.Jcrop.min.js", array('jquery'), '0.9.10'); $scripts->add( 'swfobject', "/wp-includes/js/swfobject.js", array(), '2.2-20120417'); @@ -217,7 +226,7 @@ function wp_default_scripts( &$scripts ) { 'error_uploading' => __('“%s” has failed to upload.') ); - $scripts->add( 'plupload', '/wp-includes/js/plupload/plupload.js', '1.5.4' ); + $scripts->add( 'plupload', '/wp-includes/js/plupload/plupload.js', array(), '1.5.4' ); $scripts->add( 'plupload-html5', '/wp-includes/js/plupload/plupload.html5.js', array('plupload'), '1.5.4' ); $scripts->add( 'plupload-flash', '/wp-includes/js/plupload/plupload.flash.js', array('plupload'), '1.5.4' ); $scripts->add( 'plupload-silverlight', '/wp-includes/js/plupload/plupload.silverlight.js', array('plupload'), '1.5.4' ); @@ -229,7 +238,7 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'plupload-handlers', "/wp-includes/js/plupload/handlers$suffix.js", array('plupload-all', 'jquery') ); did_action( 'init' ) && $scripts->localize( 'plupload-handlers', 'pluploadL10n', $uploader_l10n ); - $scripts->add( 'wp-plupload', "/wp-includes/js/plupload/wp-plupload$suffix.js", array('plupload-all', 'jquery', 'json2') ); + $scripts->add( 'wp-plupload', "/wp-includes/js/plupload/wp-plupload$suffix.js", array('plupload-all', 'jquery', 'json2', 'media-models'), false, 1 ); did_action( 'init' ) && $scripts->localize( 'wp-plupload', 'pluploadL10n', $uploader_l10n ); // keep 'swfupload' for back-compat. @@ -252,6 +261,9 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'json2', "/wp-includes/js/json2$suffix.js", array(), '2011-02-23'); + $scripts->add( 'underscore', '/wp-includes/js/underscore.min.js', array(), '1.4.0', 1 ); + $scripts->add( 'backbone', '/wp-includes/js/backbone.min.js', array('underscore','jquery'), '0.9.2', 1 ); + $scripts->add( 'imgareaselect', "/wp-includes/js/imgareaselect/jquery.imgareaselect$suffix.js", array('jquery'), '0.9.8', 1 ); $scripts->add( 'password-strength-meter', "/wp-admin/js/password-strength-meter$suffix.js", array('jquery'), false, 1 ); @@ -291,7 +303,7 @@ function wp_default_scripts( &$scripts ) { 'type' => 'characters' == _x( 'words', 'word count: words or characters?' ) ? 'c' : 'w', ) ); - $scripts->add( 'media-upload', "/wp-admin/js/media-upload$suffix.js", array( 'thickbox' ), false, 1 ); + $scripts->add( 'media-upload', "/wp-admin/js/media-upload$suffix.js", array( 'thickbox', 'shortcode' ), false, 1 ); $scripts->add( 'hoverIntent', "/wp-includes/js/hoverIntent$suffix.js", array('jquery'), 'r6', 1 ); @@ -306,8 +318,26 @@ function wp_default_scripts( &$scripts ) { 'cancel' => __( 'Cancel' ), 'close' => __( 'Close' ), 'cheatin' => __( 'Cheatin’ uh?' ), + + // Used for overriding the file types allowed in plupload. + 'allowedFiles' => __( 'Allowed Files' ), ) ); + $scripts->add( 'shortcode', "/wp-includes/js/shortcode$suffix.js", array( 'underscore' ), false, 1 ); + $scripts->add( 'media-models', "/wp-includes/js/media-models$suffix.js", array( 'backbone', 'jquery' ), false, 1 ); + did_action( 'init' ) && $scripts->localize( 'media-models', '_wpMediaModelsL10n', array( + 'settings' => array( + 'ajaxurl' => admin_url( 'admin-ajax.php', 'relative' ), + 'post' => array( 'id' => 0 ), + ), + ) ); + + // To enqueue media-views or media-editor, call wp_enqueue_media(). + // Both rely on numerous settings, styles, and templates to operate correctly. + $scripts->add( 'media-views', "/wp-includes/js/media-views$suffix.js", array( 'utils', 'media-models', 'wp-plupload', 'jquery-ui-sortable' ), false, 1 ); + $scripts->add( 'media-editor', "/wp-includes/js/media-editor$suffix.js", array( 'shortcode', 'media-views' ), false, 1 ); + $scripts->add( 'mce-view', "/wp-includes/js/mce-view$suffix.js", array( 'shortcode', 'media-models' ), false, 1 ); + if ( is_admin() ) { $scripts->add( 'ajaxcat', "/wp-admin/js/cat$suffix.js", array( 'wp-lists' ) ); $scripts->add_data( 'ajaxcat', 'group', 1 ); @@ -361,9 +391,9 @@ function wp_default_scripts( &$scripts ) { 'comma' => _x( ',', 'tag delimiter' ), ) ); - $scripts->add( 'link', "/wp-admin/js/link$suffix.js", array('wp-lists', 'postbox'), false, 1 ); + $scripts->add( 'link', "/wp-admin/js/link$suffix.js", array( 'wp-lists', 'postbox' ), false, 1 ); - $scripts->add( 'comment', "/wp-admin/js/comment$suffix.js", array('jquery') ); + $scripts->add( 'comment', "/wp-admin/js/comment$suffix.js", array( 'jquery', 'postbox' ) ); $scripts->add_data( 'comment', 'group', 1 ); did_action( 'init' ) && $scripts->localize( 'comment', 'commentL10n', array( 'submittedOn' => __('Submitted on:') @@ -399,6 +429,15 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'farbtastic', '/wp-admin/js/farbtastic.js', array('jquery'), '1.2' ); + $scripts->add( 'iris', '/wp-admin/js/iris.min.js', array( 'jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch' ), false, 1 ); + $scripts->add( 'wp-color-picker', "/wp-admin/js/color-picker$suffix.js", array( 'iris' ), false, 1 ); + did_action( 'init' ) && $scripts->localize( 'wp-color-picker', 'wpColorPickerL10n', array( + 'clear' => __( 'Clear' ), + 'defaultString' => __( 'Default' ), + 'pick' => __( 'Select Color' ), + 'current' => __( 'Current Color' ), + ) ); + $scripts->add( 'dashboard', "/wp-admin/js/dashboard$suffix.js", array( 'jquery', 'admin-comments', 'postbox' ), false, 1 ); $scripts->add( 'list-revisions', "/wp-includes/js/wp-list-revisions$suffix.js" ); @@ -419,14 +458,15 @@ function wp_default_scripts( &$scripts ) { ) ); // Navigation Menus - $scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", array('jquery-ui-sortable') ); + $scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'wp-lists', 'postbox' ) ); did_action( 'init' ) && $scripts->localize( 'nav-menu', 'navMenuL10n', array( 'noResultsFound' => _x('No results found.', 'search results'), 'warnDeleteMenu' => __( "You are about to permanently delete this menu. \n 'Cancel' to stop, 'OK' to delete." ), 'saveAlert' => __('The changes you made will be lost if you navigate away from this page.') ) ); - $scripts->add( 'custom-background', "/wp-admin/js/custom-background$suffix.js", array('farbtastic'), false, 1 ); + $scripts->add( 'custom-header', "/wp-admin/js/custom-header.js", array( 'jquery-masonry' ), false, 1 ); + $scripts->add( 'custom-background', "/wp-admin/js/custom-background$suffix.js", array( 'wp-color-picker', 'media-views' ), false, 1 ); $scripts->add( 'media-gallery', "/wp-admin/js/media-gallery$suffix.js", array('jquery'), false, 1 ); } } @@ -457,10 +497,10 @@ function wp_default_styles( &$styles ) { $styles->text_direction = function_exists( 'is_rtl' ) && is_rtl() ? 'rtl' : 'ltr'; $styles->default_dirs = array('/wp-admin/', '/wp-includes/css/'); - $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '.dev' : ''; + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; - $rtl_styles = array( 'wp-admin', 'ie', 'media', 'admin-bar', 'wplink', 'customize-controls' ); - // Any rtl stylesheets that don't have a .dev version for ltr + $rtl_styles = array( 'wp-admin', 'ie', 'media', 'admin-bar', 'customize-controls', 'media-views', 'wp-color-picker' ); + // Any rtl stylesheets that don't have a .min version $no_suffix = array( 'farbtastic' ); $styles->add( 'wp-admin', "/wp-admin/css/wp-admin$suffix.css" ); @@ -469,23 +509,26 @@ function wp_default_styles( &$styles ) { $styles->add_data( 'ie', 'conditional', 'lte IE 7' ); // Register "meta" stylesheet for admin colors. All colors-* style sheets should have the same version string. - $styles->add( 'colors', true, array('wp-admin') ); + $styles->add( 'colors', true, array('wp-admin', 'buttons') ); // do not refer to these directly, the right one is queued by the above "meta" colors handle - $styles->add( 'colors-fresh', "/wp-admin/css/colors-fresh$suffix.css", array('wp-admin') ); - $styles->add( 'colors-classic', "/wp-admin/css/colors-classic$suffix.css", array('wp-admin') ); + $styles->add( 'colors-fresh', "/wp-admin/css/colors-fresh$suffix.css", array('wp-admin', 'buttons') ); + $styles->add( 'colors-classic', "/wp-admin/css/colors-classic$suffix.css", array('wp-admin', 'buttons') ); $styles->add( 'media', "/wp-admin/css/media$suffix.css" ); - $styles->add( 'install', "/wp-admin/css/install$suffix.css" ); - $styles->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.css' ); + $styles->add( 'install', "/wp-admin/css/install$suffix.css", array('buttons') ); + $styles->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.css', array(), '20121105' ); $styles->add( 'farbtastic', '/wp-admin/css/farbtastic.css', array(), '1.3u1' ); - $styles->add( 'jcrop', '/wp-includes/js/jcrop/jquery.Jcrop.css', array(), '0.9.8' ); + $styles->add( 'wp-color-picker', "/wp-admin/css/color-picker$suffix.css" ); + $styles->add( 'jcrop', "/wp-includes/js/jcrop/jquery.Jcrop.min.css", array(), '0.9.10' ); $styles->add( 'imgareaselect', '/wp-includes/js/imgareaselect/imgareaselect.css', array(), '0.9.8' ); $styles->add( 'admin-bar', "/wp-includes/css/admin-bar$suffix.css" ); $styles->add( 'wp-jquery-ui-dialog', "/wp-includes/css/jquery-ui-dialog$suffix.css" ); $styles->add( 'editor-buttons', "/wp-includes/css/editor$suffix.css" ); $styles->add( 'wp-pointer', "/wp-includes/css/wp-pointer$suffix.css" ); $styles->add( 'customize-controls', "/wp-admin/css/customize-controls$suffix.css", array( 'wp-admin', 'colors', 'ie' ) ); + $styles->add( 'media-views', "/wp-includes/css/media-views$suffix.css", array( 'buttons' ) ); + $styles->add( 'buttons', "/wp-includes/css/buttons$suffix.css" ); foreach ( $rtl_styles as $rtl_style ) { $styles->add_data( $rtl_style, 'rtl', true ); @@ -503,10 +546,10 @@ function wp_default_styles( &$styles ) { * @return array Reordered array, if needed. */ function wp_prototype_before_jquery( $js_array ) { - if ( false === $jquery = array_search( 'jquery', $js_array, true ) ) + if ( false === $prototype = array_search( 'prototype', $js_array, true ) ) return $js_array; - if ( false === $prototype = array_search( 'prototype', $js_array, true ) ) + if ( false === $jquery = array_search( 'jquery', $js_array, true ) ) return $js_array; if ( $prototype < $jquery ) @@ -572,7 +615,7 @@ function wp_style_loader_src( $src, $handle ) { $url = $color->url; if ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) - $url = preg_replace('/.css$|.css(?=\?)/', '.dev.css', $url); + $url = preg_replace( '/.min.css$|.min.css(?=\?)/', '.css', $url ); if ( isset($parsed['query']) && $parsed['query'] ) { wp_parse_str( $parsed['query'], $qv ); @@ -646,7 +689,7 @@ function _print_scripts() { if ( $zip && defined('ENFORCE_GZIP') && ENFORCE_GZIP ) $zip = 'gzip'; - if ( !empty($wp_scripts->concat) ) { + if ( $concat = trim( $wp_scripts->concat, ', ' ) ) { if ( !empty($wp_scripts->print_code) ) { echo "\n\n"; } - $src = $wp_scripts->base_url . "/wp-admin/load-scripts.php?c={$zip}&load=" . trim($wp_scripts->concat, ', ') . '&ver=' . $wp_scripts->default_version; + $concat = str_split( $concat, 128 ); + $concat = 'load[]=' . implode( '&load[]=', $concat ); + + $src = $wp_scripts->base_url . "/wp-admin/load-scripts.php?c={$zip}&" . $concat . '&ver=' . $wp_scripts->default_version; echo "\n"; } diff --git a/wp-includes/shortcodes.php b/wp-includes/shortcodes.php index 1b860d27..2dfc2774 100644 --- a/wp-includes/shortcodes.php +++ b/wp-includes/shortcodes.php @@ -177,11 +177,12 @@ function get_shortcode_regex() { $tagregexp = join( '|', array_map('preg_quote', $tagnames) ); // WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag() + // Also, see shortcode_unautop() and shortcode.js. return '\\[' // Opening bracket . '(\\[?)' // 1: Optional second opening bracket for escaping shortcodes: [[tag]] . "($tagregexp)" // 2: Shortcode name - . '\\b' // Word boundary + . '(?![\\w-])' // Not followed by word character or hyphen . '(' // 3: Unroll the loop: Inside the opening shortcode tag . '[^\\]\\/]*' // Not a closing bracket or forward slash . '(?:' diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 514574e2..1932bab3 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -47,6 +47,7 @@ function create_initial_taxonomies() { 'rewrite' => $rewrite['category'], 'public' => true, 'show_ui' => true, + 'show_admin_column' => true, '_builtin' => true, ) ); @@ -56,6 +57,7 @@ function create_initial_taxonomies() { 'rewrite' => $rewrite['post_tag'], 'public' => true, 'show_ui' => true, + 'show_admin_column' => true, '_builtin' => true, ) ); @@ -89,6 +91,12 @@ function create_initial_taxonomies() { 'add_or_remove_items' => null, 'choose_from_most_used' => null, ), + 'capabilities' => array( + 'manage_terms' => 'manage_links', + 'edit_terms' => 'manage_links', + 'delete_terms' => 'manage_links', + 'assign_terms' => 'manage_links', + ), 'query_var' => false, 'rewrite' => false, 'public' => false, @@ -301,6 +309,7 @@ function is_taxonomy_hierarchical($taxonomy) { * @param string $taxonomy Name of taxonomy object * @param array|string $object_type Name of the object type for the taxonomy object. * @param array|string $args See above description for the two keys values. + * @return null|WP_Error WP_Error if errors, otherwise null. */ function register_taxonomy( $taxonomy, $object_type, $args = array() ) { global $wp_taxonomies, $wp; @@ -322,10 +331,14 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) { ); $args = wp_parse_args($args, $defaults); + if ( strlen( $taxonomy ) > 32 ) + return new WP_Error( 'taxonomy_too_long', __( 'Taxonomies cannot exceed 32 characters in length' ) ); + if ( false !== $args['query_var'] && !empty($wp) ) { if ( true === $args['query_var'] ) $args['query_var'] = $taxonomy; - $args['query_var'] = sanitize_title_with_dashes($args['query_var']); + else + $args['query_var'] = sanitize_title_with_dashes($args['query_var']); $wp->add_query_var($args['query_var']); } @@ -651,23 +664,26 @@ class WP_Tax_Query { $join = ''; $where = array(); $i = 0; + $count = count( $this->queries ); - foreach ( $this->queries as $query ) { + foreach ( $this->queries as $index => $query ) { $this->clean_query( $query ); - if ( is_wp_error( $query ) ) { + if ( is_wp_error( $query ) ) return self::$no_results; - } extract( $query ); if ( 'IN' == $operator ) { if ( empty( $terms ) ) { - if ( 'OR' == $this->relation ) + if ( 'OR' == $this->relation ) { + if ( ( $index + 1 === $count ) && empty( $where ) ) + return self::$no_results; continue; - else + } else { return self::$no_results; + } } $terms = implode( ',', $terms ); @@ -711,7 +727,7 @@ class WP_Tax_Query { $i++; } - if ( !empty( $where ) ) + if ( ! empty( $where ) ) $where = ' AND ( ' . implode( " $this->relation ", $where ) . ' )'; else $where = ''; @@ -756,12 +772,11 @@ class WP_Tax_Query { * Transforms a single query, from one field to another. * * @since 3.2.0 - * @access private * * @param array &$query The single query * @param string $resulting_field The resulting field */ - private function transform_query( &$query, $resulting_field ) { + public function transform_query( &$query, $resulting_field ) { global $wpdb; if ( empty( $query['terms'] ) ) @@ -784,7 +799,14 @@ class WP_Tax_Query { AND $wpdb->terms.{$query['field']} IN ($terms) " ); break; - + case 'term_taxonomy_id': + $terms = implode( ',', array_map( 'intval', $query['terms'] ) ); + $terms = $wpdb->get_col( " + SELECT $resulting_field + FROM $wpdb->term_taxonomy + WHERE term_taxonomy_id IN ($terms) + " ); + break; default: $terms = implode( ',', array_map( 'intval', $query['terms'] ) ); $terms = $wpdb->get_col( " @@ -845,7 +867,7 @@ class WP_Tax_Query { * @return mixed|null|WP_Error Term Row from database. Will return null if $term is empty. If taxonomy does not * exist then WP_Error will be returned. */ -function &get_term($term, $taxonomy, $output = OBJECT, $filter = 'raw') { +function get_term($term, $taxonomy, $output = OBJECT, $filter = 'raw') { global $wpdb; $null = null; @@ -1162,15 +1184,13 @@ function get_term_to_edit( $id, $taxonomy ) { * @param string|array $args The values of what to search for when returning terms * @return array|WP_Error List of Term Objects and their children. Will return WP_Error, if any of $taxonomies do not exist. */ -function &get_terms($taxonomies, $args = '') { +function get_terms($taxonomies, $args = '') { global $wpdb; $empty_array = array(); - $single_taxonomy = false; - if ( !is_array($taxonomies) ) { - $single_taxonomy = true; - $taxonomies = array($taxonomies); - } + $single_taxonomy = ! is_array( $taxonomies ) || 1 === count( $taxonomies ); + if ( ! is_array( $taxonomies ) ) + $taxonomies = array( $taxonomies ); foreach ( $taxonomies as $taxonomy ) { if ( ! taxonomy_exists($taxonomy) ) { @@ -1384,7 +1404,7 @@ function &get_terms($taxonomies, $args = '') { } if ( empty($terms) ) { - wp_cache_add( $cache_key, array(), 'terms', 86400 ); // one day + wp_cache_add( $cache_key, array(), 'terms', DAY_IN_SECONDS ); $terms = apply_filters('get_terms', array(), $taxonomies, $args); return $terms; } @@ -1392,7 +1412,7 @@ function &get_terms($taxonomies, $args = '') { if ( $child_of ) { $children = _get_term_hierarchy($taxonomies[0]); if ( ! empty($children) ) - $terms = & _get_term_children($child_of, $terms, $taxonomies[0]); + $terms = _get_term_children($child_of, $terms, $taxonomies[0]); } // Update term counts to include children. @@ -1435,7 +1455,7 @@ function &get_terms($taxonomies, $args = '') { $terms = array_slice($terms, $offset, $number); } - wp_cache_add( $cache_key, $terms, 'terms', 86400 ); // one day + wp_cache_add( $cache_key, $terms, 'terms', DAY_IN_SECONDS ); $terms = apply_filters('get_terms', $terms, $taxonomies, $args); return $terms; @@ -1665,7 +1685,7 @@ function sanitize_term_field($field, $value, $term_id, $taxonomy, $context) { * * @param string $taxonomy Taxonomy name * @param array|string $args Overwrite defaults. See get_terms() - * @return int How many terms are in $taxonomy + * @return int|WP_Error How many terms are in $taxonomy. WP_Error if $taxonomy does not exist. */ function wp_count_terms( $taxonomy, $args = array() ) { $defaults = array('hide_empty' => false); @@ -1802,6 +1822,9 @@ function wp_delete_term( $term, $taxonomy, $args = array() ) { foreach ( $tax_object->object_type as $object_type ) clean_object_term_cache( $objects, $object_type ); + // Get the object before deletion so we can pass to actions below + $deleted_term = get_term( $term, $taxonomy ); + do_action( 'delete_term_taxonomy', $tt_id ); $wpdb->delete( $wpdb->term_taxonomy, array( 'term_taxonomy_id' => $tt_id ) ); do_action( 'deleted_term_taxonomy', $tt_id ); @@ -1812,8 +1835,8 @@ function wp_delete_term( $term, $taxonomy, $args = array() ) { clean_term_cache($term, $taxonomy); - do_action('delete_term', $term, $tt_id, $taxonomy); - do_action("delete_$taxonomy", $term, $tt_id); + do_action( 'delete_term', $term, $tt_id, $taxonomy, $deleted_term ); + do_action( "delete_$taxonomy", $term, $tt_id, $deleted_term ); return true; } @@ -2211,9 +2234,12 @@ function wp_set_object_terms($object_id, $terms, $taxonomy, $append = false) { if ( in_array($tt_id, $final_tt_ids) ) $values[] = $wpdb->prepare( "(%d, %d, %d)", $object_id, $tt_id, ++$term_order); if ( $values ) - $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join(',', $values) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)"); + if ( false === $wpdb->query( "INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join( ',', $values ) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)" ) ) + return new WP_Error( 'db_insert_error', __( 'Could not insert term relationship into the database' ), $wpdb->last_error ); } + wp_cache_delete( $object_id, $taxonomy . '_relationships' ); + do_action('set_object_terms', $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids); return $tt_ids; } @@ -2540,8 +2566,10 @@ function clean_object_term_cache($object_ids, $object_type) { if ( !is_array($object_ids) ) $object_ids = array($object_ids); + $taxonomies = get_object_taxonomies( $object_type ); + foreach ( $object_ids as $id ) - foreach ( get_object_taxonomies($object_type) as $taxonomy ) + foreach ( $taxonomies as $taxonomy ) wp_cache_delete($id, "{$taxonomy}_relationships"); do_action('clean_object_term_cache', $object_ids, $object_type); @@ -2620,7 +2648,7 @@ function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true) { * @param string $taxonomy Taxonomy Name * @return bool|array Empty array if $terms found, but not $taxonomy. False if nothing is in cache for $taxonomy and $id. */ -function &get_object_term_cache($id, $taxonomy) { +function get_object_term_cache($id, $taxonomy) { $cache = wp_cache_get($id, "{$taxonomy}_relationships"); return $cache; } @@ -2766,7 +2794,7 @@ function _get_term_hierarchy($taxonomy) { * @param string $taxonomy The taxonomy which determines the hierarchy of the terms. * @return array The subset of $terms that are descendants of $term_id. */ -function &_get_term_children($term_id, $terms, $taxonomy) { +function _get_term_children($term_id, $terms, $taxonomy) { $empty_array = array(); if ( empty($terms) ) return $empty_array; @@ -2964,9 +2992,9 @@ function get_term_link( $term, $taxonomy = '') { if ( !is_object($term) ) { if ( is_int($term) ) { - $term = &get_term($term, $taxonomy); + $term = get_term($term, $taxonomy); } else { - $term = &get_term_by('slug', $term, $taxonomy); + $term = get_term_by('slug', $term, $taxonomy); } } @@ -3063,10 +3091,7 @@ function the_taxonomies($args = array()) { * @return array */ function get_the_taxonomies($post = 0, $args = array() ) { - if ( is_int($post) ) - $post =& get_post($post); - elseif ( !is_object($post) ) - $post =& $GLOBALS['post']; + $post = get_post( $post ); $args = wp_parse_args( $args, array( 'template' => '%s: %l.', @@ -3088,7 +3113,7 @@ function get_the_taxonomies($post = 0, $args = array() ) { $t['template'] = $template; $terms = get_object_term_cache($post->ID, $taxonomy); - if ( empty($terms) ) + if ( false === $terms ) $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']); $links = array(); @@ -3112,7 +3137,7 @@ function get_the_taxonomies($post = 0, $args = array() ) { * @return array */ function get_post_taxonomies($post = 0) { - $post =& get_post($post); + $post = get_post( $post ); return get_object_taxonomies($post); } @@ -3138,7 +3163,7 @@ function is_object_in_term( $object_id, $taxonomy, $terms = null ) { return new WP_Error( 'invalid_object', __( 'Invalid object ID' ) ); $object_terms = get_object_term_cache( $object_id, $taxonomy ); - if ( empty( $object_terms ) ) + if ( false === $object_terms ) $object_terms = wp_get_object_terms( $object_id, $taxonomy ); if ( is_wp_error( $object_terms ) ) @@ -3211,16 +3236,8 @@ function get_ancestors($object_id = 0, $object_type = '') { $ancestors[] = (int) $term->parent; $term = get_term($term->parent, $object_type); } - } elseif ( null !== get_post_type_object( $object_type ) ) { - $object = get_post($object_id); - if ( ! is_wp_error( $object ) && isset( $object->ancestors ) && is_array( $object->ancestors ) ) - $ancestors = $object->ancestors; - else { - while ( ! is_wp_error($object) && ! empty( $object->post_parent ) && ! in_array( $object->post_parent, $ancestors ) ) { - $ancestors[] = (int) $object->post_parent; - $object = get_post($object->post_parent); - } - } + } elseif ( post_type_exists( $object_type ) ) { + $ancestors = get_post_ancestors($object_id); } return apply_filters('get_ancestors', $ancestors, $object_id, $object_type); diff --git a/wp-includes/template-loader.php b/wp-includes/template-loader.php index fdf75f15..7051f345 100644 --- a/wp-includes/template-loader.php +++ b/wp-includes/template-loader.php @@ -6,6 +6,10 @@ if ( defined('WP_USE_THEMES') && WP_USE_THEMES ) do_action('template_redirect'); +// Halt template load for HEAD requests. Performance bump. See #14348 +if ( 'HEAD' === $_SERVER['REQUEST_METHOD'] && apply_filters( 'exit_on_http_head', true ) ) + exit(); + // Process feeds and trackbacks even if not using themes. if ( is_robots() ) : do_action('do_robots'); diff --git a/wp-includes/template.php b/wp-includes/template.php index 531b308d..d86a677f 100644 --- a/wp-includes/template.php +++ b/wp-includes/template.php @@ -59,11 +59,11 @@ function get_404_template() { * @return string */ function get_archive_template() { - $post_type = get_query_var( 'post_type' ); + $post_types = get_query_var( 'post_type' ); $templates = array(); - if ( $post_type ) + foreach ( (array) $post_types as $post_type ) $templates[] = "archive-{$post_type}.php"; $templates[] = 'archive.php'; @@ -82,8 +82,10 @@ function get_author_template() { $templates = array(); - $templates[] = "author-{$author->user_nicename}.php"; - $templates[] = "author-{$author->ID}.php"; + if ( $author ) { + $templates[] = "author-{$author->user_nicename}.php"; + $templates[] = "author-{$author->ID}.php"; + } $templates[] = 'author.php'; return get_query_template( 'author', $templates ); @@ -106,8 +108,10 @@ function get_category_template() { $templates = array(); - $templates[] = "category-{$category->slug}.php"; - $templates[] = "category-{$category->term_id}.php"; + if ( $category ) { + $templates[] = "category-{$category->slug}.php"; + $templates[] = "category-{$category->term_id}.php"; + } $templates[] = 'category.php'; return get_query_template( 'category', $templates ); @@ -130,8 +134,10 @@ function get_tag_template() { $templates = array(); - $templates[] = "tag-{$tag->slug}.php"; - $templates[] = "tag-{$tag->term_id}.php"; + if ( $tag ) { + $templates[] = "tag-{$tag->slug}.php"; + $templates[] = "tag-{$tag->term_id}.php"; + } $templates[] = 'tag.php'; return get_query_template( 'tag', $templates ); @@ -156,12 +162,14 @@ function get_tag_template() { */ function get_taxonomy_template() { $term = get_queried_object(); - $taxonomy = $term->taxonomy; $templates = array(); - $templates[] = "taxonomy-$taxonomy-{$term->slug}.php"; - $templates[] = "taxonomy-$taxonomy.php"; + if ( $term ) { + $taxonomy = $term->taxonomy; + $templates[] = "taxonomy-$taxonomy-{$term->slug}.php"; + $templates[] = "taxonomy-$taxonomy.php"; + } $templates[] = 'taxonomy.php'; return get_query_template( 'taxonomy', $templates ); @@ -280,7 +288,8 @@ function get_single_template() { $templates = array(); - $templates[] = "single-{$object->post_type}.php"; + if ( $object ) + $templates[] = "single-{$object->post_type}.php"; $templates[] = "single.php"; return get_query_template( 'single', $templates ); @@ -303,15 +312,21 @@ function get_single_template() { */ function get_attachment_template() { global $posts; - $type = explode('/', $posts[0]->post_mime_type); - if ( $template = get_query_template($type[0]) ) - return $template; - elseif ( $template = get_query_template($type[1]) ) - return $template; - elseif ( $template = get_query_template("$type[0]_$type[1]") ) - return $template; - else - return get_query_template('attachment'); + + if ( ! empty( $posts ) && isset( $posts[0]->post_mime_type ) ) { + $type = explode( '/', $posts[0]->post_mime_type ); + + if ( ! empty( $type ) ) { + if ( $template = get_query_template( $type[0] ) ) + return $template; + elseif ( $template = get_query_template( $type[1] ) ) + return $template; + elseif ( $template = get_query_template( "$type[0]_$type[1]" ) ) + return $template; + } + } + + return get_query_template( 'attachment' ); } /** diff --git a/wp-includes/theme-compat/comments-popup.php b/wp-includes/theme-compat/comments-popup.php index de4c1e9e..eb74834c 100644 --- a/wp-includes/theme-compat/comments-popup.php +++ b/wp-includes/theme-compat/comments-popup.php @@ -32,7 +32,7 @@ while( have_posts()) : the_post(); ?>

    -

    RSS feed for comments on this post.'); ?>

    +

    RSS feed for comments on this post.'); ?>

    URL to TrackBack this entry is: %s'), get_trackback_url()); ?>

    @@ -68,7 +68,7 @@ if ( post_password_required($post) ) { // and it doesn't match the cookie -

    %2$s. Log out »'), get_option('siteurl') . '/wp-admin/profile.php', $user_identity, wp_logout_url(get_permalink())); ?>

    +

    %2$s. Log out »'), get_edit_user_link(), $user_identity, wp_logout_url(get_permalink())); ?>

    diff --git a/wp-includes/theme-compat/comments.php b/wp-includes/theme-compat/comments.php index 89a888c7..75a85ed4 100644 --- a/wp-includes/theme-compat/comments.php +++ b/wp-includes/theme-compat/comments.php @@ -69,7 +69,7 @@ _deprecated_file( sprintf( __( 'Theme without %1$s' ), basename(__FILE__) ), '3. -

    %2$s.'), get_option('siteurl') . '/wp-admin/profile.php', $user_identity); ?>

    +

    %2$s.'), get_edit_user_link(), $user_identity); ?>

    diff --git a/wp-includes/theme.php b/wp-includes/theme.php index f449ae50..d8c24197 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -106,6 +106,18 @@ function wp_get_theme( $stylesheet = null, $theme_root = null ) { return new WP_Theme( $stylesheet, $theme_root ); } +/** + * Clears the cache held by get_theme_roots() and WP_Theme. + * + * @since 3.5.0 + */ +function wp_clean_themes_cache() { + delete_site_transient('update_themes'); + search_theme_directories( true ); + foreach ( wp_get_themes( array( 'errors' => null ) ) as $theme ) + $theme->cache_delete(); +} + /** * Whether a child theme is in use. * @@ -638,15 +650,17 @@ function preview_theme_ob_filter_callback( $matches ) { } /** - * Switches current theme to new template and stylesheet names. + * Switches the theme. + * + * Accepts one argument: $stylesheet of the theme. It also accepts an additional function signature + * of two arguments: $template then $stylesheet. This is for backwards compatibility. * * @since 2.5.0 * @uses do_action() Calls 'switch_theme' action, passing the new theme. * - * @param string $template Template name - * @param string $stylesheet Stylesheet name. + * @param string $stylesheet Stylesheet name */ -function switch_theme( $template, $stylesheet ) { +function switch_theme( $stylesheet ) { global $wp_theme_directories, $sidebars_widgets; if ( is_array( $sidebars_widgets ) ) @@ -654,7 +668,13 @@ function switch_theme( $template, $stylesheet ) { $old_theme = wp_get_theme(); $new_theme = wp_get_theme( $stylesheet ); - $new_name = $new_theme->get('Name'); + + if ( func_num_args() > 1 ) { + $template = $stylesheet; + $stylesheet = func_get_arg( 1 ); + } else { + $template = $new_theme->get_template(); + } update_option( 'template', $template ); update_option( 'stylesheet', $stylesheet ); @@ -662,8 +682,13 @@ function switch_theme( $template, $stylesheet ) { if ( count( $wp_theme_directories ) > 1 ) { update_option( 'template_root', get_raw_theme_root( $template, true ) ); update_option( 'stylesheet_root', get_raw_theme_root( $stylesheet, true ) ); + } else { + delete_option( 'template_root' ); + delete_option( 'stylesheet_root' ); } + $new_name = $new_theme->get('Name'); + update_option( 'current_theme', $new_name ); if ( is_admin() && false === get_option( 'theme_mods_' . $stylesheet ) ) { @@ -694,17 +719,17 @@ function validate_current_theme() { return true; if ( get_template() != WP_DEFAULT_THEME && !file_exists(get_template_directory() . '/index.php') ) { - switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME ); + switch_theme( WP_DEFAULT_THEME ); return false; } if ( get_stylesheet() != WP_DEFAULT_THEME && !file_exists(get_template_directory() . '/style.css') ) { - switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME ); + switch_theme( WP_DEFAULT_THEME ); return false; } if ( is_child_theme() && ! file_exists( get_stylesheet_directory() . '/style.css' ) ) { - switch_theme( WP_DEFAULT_THEME, WP_DEFAULT_THEME ); + switch_theme( WP_DEFAULT_THEME ); return false; } @@ -869,12 +894,7 @@ function get_header_image() { if ( is_random_header_image() ) $url = get_random_header_image(); - if ( is_ssl() ) - $url = str_replace( 'http://', 'https://', $url ); - else - $url = str_replace( 'https://', 'http://', $url ); - - return esc_url_raw( $url ); + return esc_url_raw( set_url_scheme( $url ) ); } /** @@ -1008,7 +1028,30 @@ function get_uploaded_header_images() { * @return object */ function get_custom_header() { - $data = is_random_header_image()? _get_random_header_data() : get_theme_mod( 'header_image_data' ); + global $_wp_default_headers; + + if ( is_random_header_image() ) { + $data = _get_random_header_data(); + } else { + $data = get_theme_mod( 'header_image_data' ); + if ( ! $data && current_theme_supports( 'custom-header', 'default-image' ) ) { + $directory_args = array( get_template_directory_uri(), get_stylesheet_directory_uri() ); + $data = array(); + $data['url'] = $data['thumbnail_url'] = vsprintf( get_theme_support( 'custom-header', 'default-image' ), $directory_args ); + if ( ! empty( $_wp_default_headers ) ) { + foreach ( (array) $_wp_default_headers as $default_header ) { + $url = vsprintf( $default_header['url'], $directory_args ); + if ( $data['url'] == $url ) { + $data = $default_header; + $data['url'] = $url; + $data['thumbnail_url'] = vsprintf( $data['thumbnail_url'], $directory_args ); + break; + } + } + } + } + } + $default = array( 'url' => '', 'thumbnail_url' => '', @@ -1103,7 +1146,7 @@ function background_color() { */ function _custom_background_cb() { // $background is the saved custom image, or the default image. - $background = get_background_image(); + $background = set_url_scheme( get_background_image() ); // $color is the saved custom color. // A default has to be specified in style.css. It will not be printed here. @@ -1446,6 +1489,8 @@ function _remove_theme_support( $feature ) { switch ( $feature ) { case 'custom-header' : + if ( false === did_action( 'wp_loaded', '_custom_header_background_just_in_time' ) ) + break; $support = get_theme_support( 'custom-header' ); if ( $support[0]['wp-head-callback'] ) remove_action( 'wp_head', $support[0]['wp-head-callback'] ); @@ -1454,6 +1499,8 @@ function _remove_theme_support( $feature ) { break; case 'custom-background' : + if ( false === did_action( 'wp_loaded', '_custom_header_background_just_in_time' ) ) + break; $support = get_theme_support( 'custom-background' ); remove_action( 'wp_head', $support[0]['wp-head-callback'] ); remove_action( 'admin_menu', array( $GLOBALS['custom_background'], 'init' ) ); @@ -1669,7 +1716,7 @@ function wp_customize_support_script() { request = true; - b[c] = b[c].replace( rcs, '' ); + b[c] = b[c].replace( rcs, ' ' ); b[c] += ( window.postMessage && request ? ' ' : ' no-' ) + cs; }()); diff --git a/wp-includes/update.php b/wp-includes/update.php index 34573478..b6205063 100644 --- a/wp-includes/update.php +++ b/wp-includes/update.php @@ -155,14 +155,14 @@ function wp_update_plugins() { // Check for update on a different schedule, depending on the page. switch ( current_filter() ) { case 'load-update-core.php' : - $timeout = 60; // 1 min + $timeout = MINUTE_IN_SECONDS; break; case 'load-plugins.php' : case 'load-update.php' : - $timeout = 3600; // 1 hour + $timeout = HOUR_IN_SECONDS; break; default : - $timeout = 43200; // 12 hours + $timeout = 12 * HOUR_IN_SECONDS; } $time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked ); @@ -264,14 +264,14 @@ function wp_update_themes() { // Check for update on a different schedule, depending on the page. switch ( current_filter() ) { case 'load-update-core.php' : - $timeout = 60; // 1 min + $timeout = MINUTE_IN_SECONDS; break; case 'load-themes.php' : case 'load-update.php' : - $timeout = 3600; // 1 hour + $timeout = HOUR_IN_SECONDS; break; default : - $timeout = 43200; // 12 hours + $timeout = 12 * HOUR_IN_SECONDS; } $time_not_changed = isset( $last_update->last_checked ) && $timeout > ( time( ) - $last_update->last_checked ); @@ -279,8 +279,6 @@ function wp_update_themes() { if ( $time_not_changed ) { $theme_changed = false; foreach ( $checked as $slug => $v ) { - $update_request->checked[ $slug ] = $v; - if ( !isset( $last_update->checked[ $slug ] ) || strval($last_update->checked[ $slug ]) !== strval($v) ) $theme_changed = true; } @@ -354,17 +352,17 @@ function wp_get_update_data() { } $counts['total'] = $counts['plugins'] + $counts['themes'] + $counts['wordpress']; - $update_title = array(); + $titles = array(); if ( $counts['wordpress'] ) - $update_title[] = sprintf(__('%d WordPress Update'), $counts['wordpress']); + $titles['wordpress'] = sprintf( __( '%d WordPress Update'), $counts['wordpress'] ); if ( $counts['plugins'] ) - $update_title[] = sprintf(_n('%d Plugin Update', '%d Plugin Updates', $counts['plugins']), $counts['plugins']); + $titles['plugins'] = sprintf( _n( '%d Plugin Update', '%d Plugin Updates', $counts['plugins'] ), $counts['plugins'] ); if ( $counts['themes'] ) - $update_title[] = sprintf(_n('%d Theme Update', '%d Theme Updates', $counts['themes']), $counts['themes']); + $titles['themes'] = sprintf( _n( '%d Theme Update', '%d Theme Updates', $counts['themes'] ), $counts['themes'] ); - $update_title = ! empty( $update_title ) ? esc_attr( implode( ', ', $update_title ) ) : ''; + $update_title = $titles ? esc_attr( implode( ', ', $titles ) ) : ''; - return array( 'counts' => $counts, 'title' => $update_title ); + return apply_filters( 'wp_get_update_data', array( 'counts' => $counts, 'title' => $update_title ), $titles ); } function _maybe_update_core() { @@ -373,7 +371,7 @@ function _maybe_update_core() { $current = get_site_transient( 'update_core' ); if ( isset( $current->last_checked ) && - 43200 > ( time() - $current->last_checked ) && + 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) && isset( $current->version_checked ) && $current->version_checked == $wp_version ) return; @@ -392,7 +390,7 @@ function _maybe_update_core() { */ function _maybe_update_plugins() { $current = get_site_transient( 'update_plugins' ); - if ( isset( $current->last_checked ) && 43200 > ( time() - $current->last_checked ) ) + if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) ) return; wp_update_plugins(); } @@ -408,7 +406,7 @@ function _maybe_update_plugins() { */ function _maybe_update_themes( ) { $current = get_site_transient( 'update_themes' ); - if ( isset( $current->last_checked ) && 43200 > ( time( ) - $current->last_checked ) ) + if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time( ) - $current->last_checked ) ) return; wp_update_themes(); diff --git a/wp-includes/user.php b/wp-includes/user.php index 6b342c85..7bdc37cc 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -84,33 +84,32 @@ function wp_authenticate_username_password($user, $username, $password) { return $error; } - $userdata = get_user_by('login', $username); + $user = get_user_by('login', $username); - if ( !$userdata ) + if ( !$user ) return new WP_Error('invalid_username', sprintf(__('ERROR: Invalid username. Lost your password?'), wp_lostpassword_url())); if ( is_multisite() ) { // Is user marked as spam? - if ( 1 == $userdata->spam) + if ( 1 == $user->spam) return new WP_Error('invalid_username', __('ERROR: Your account has been marked as a spammer.')); // Is a user's blog marked as spam? - if ( !is_super_admin( $userdata->ID ) && isset($userdata->primary_blog) ) { - $details = get_blog_details( $userdata->primary_blog ); + if ( !is_super_admin( $user->ID ) && isset($user->primary_blog) ) { + $details = get_blog_details( $user->primary_blog ); if ( is_object( $details ) && $details->spam == 1 ) return new WP_Error('blog_suspended', __('Site Suspended.')); } } - $userdata = apply_filters('wp_authenticate_user', $userdata, $password); - if ( is_wp_error($userdata) ) - return $userdata; + $user = apply_filters('wp_authenticate_user', $user, $password); + if ( is_wp_error($user) ) + return $user; - if ( !wp_check_password($password, $userdata->user_pass, $userdata->ID) ) + if ( !wp_check_password($password, $user->user_pass, $user->ID) ) return new WP_Error( 'incorrect_password', sprintf( __( 'ERROR: The password you entered for the username %1$s is incorrect. Lost your password?' ), $username, wp_lostpassword_url() ) ); - $user = new WP_User($userdata->ID); return $user; } @@ -166,10 +165,11 @@ function count_user_posts($userid) { * @since 3.0.0 * * @param array $users Array of user IDs. - * @param string|array $post_type Optional. Post type to check. Defaults to post. + * @param string $post_type Optional. Post type to check. Defaults to post. + * @param bool $public_only Optional. Only return counts for public posts. Defaults to false. * @return array Amount of posts each user has written. */ -function count_many_users_posts( $users, $post_type = 'post' ) { +function count_many_users_posts( $users, $post_type = 'post', $public_only = false ) { global $wpdb; $count = array(); @@ -177,7 +177,7 @@ function count_many_users_posts( $users, $post_type = 'post' ) { return $count; $userlist = implode( ',', array_map( 'absint', $users ) ); - $where = get_posts_by_author_sql( $post_type ); + $where = get_posts_by_author_sql( $post_type, true, null, $public_only ); $result = $wpdb->get_results( "SELECT post_author, COUNT(*) FROM $wpdb->posts $where AND post_author IN ($userlist) GROUP BY post_author", ARRAY_N ); foreach ( $result as $row ) { @@ -192,24 +192,6 @@ function count_many_users_posts( $users, $post_type = 'post' ) { return $count; } -/** - * Check that the user login name and password is correct. - * - * @since 0.71 - * @todo xmlrpc only. Maybe move to xmlrpc.php. - * - * @param string $user_login User name. - * @param string $user_pass User password. - * @return bool False if does not authenticate, true if username and password authenticates. - */ -function user_pass_ok($user_login, $user_pass) { - $user = wp_authenticate($user_login, $user_pass); - if ( is_wp_error($user) ) - return false; - - return true; -} - // // User option functions // @@ -255,11 +237,9 @@ function get_user_option( $option, $user = 0, $deprecated = '' ) { _deprecated_argument( __FUNCTION__, '3.0' ); if ( empty( $user ) ) - $user = wp_get_current_user(); - else - $user = new WP_User( $user ); + $user = get_current_user_id(); - if ( ! $user->exists() ) + if ( ! $user = get_userdata( $user ) ) return false; if ( $user->has_prop( $wpdb->prefix . $option ) ) // Blog specific @@ -334,6 +314,15 @@ function delete_user_option( $user_id, $option_name, $global = false ) { */ class WP_User_Query { + /** + * Query vars, after parsing + * + * @since 3.5.0 + * @access public + * @var array + */ + var $query_vars = array(); + /** * List of found user ids * @@ -402,7 +391,7 @@ class WP_User_Query { function prepare_query() { global $wpdb; - $qv = &$this->query_vars; + $qv =& $this->query_vars; if ( is_array( $qv['fields'] ) ) { $qv['fields'] = array_unique( $qv['fields'] ); @@ -417,7 +406,7 @@ class WP_User_Query { $this->query_fields = "$wpdb->users.ID"; } - if ( $this->query_vars['count_total'] ) + if ( $qv['count_total'] ) $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields; $this->query_from = "FROM $wpdb->users"; @@ -549,29 +538,64 @@ class WP_User_Query { function query() { global $wpdb; - if ( is_array( $this->query_vars['fields'] ) || 'all' == $this->query_vars['fields'] ) { + $qv =& $this->query_vars; + + if ( is_array( $qv['fields'] ) || 'all' == $qv['fields'] ) { $this->results = $wpdb->get_results("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit"); } else { $this->results = $wpdb->get_col("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit"); } - if ( $this->query_vars['count_total'] ) + if ( $qv['count_total'] ) $this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) ); if ( !$this->results ) return; - if ( 'all_with_meta' == $this->query_vars['fields'] ) { + if ( 'all_with_meta' == $qv['fields'] ) { cache_users( $this->results ); $r = array(); foreach ( $this->results as $userid ) - $r[ $userid ] = new WP_User( $userid, '', $this->query_vars['blog_id'] ); + $r[ $userid ] = new WP_User( $userid, '', $qv['blog_id'] ); $this->results = $r; + } elseif ( 'all' == $qv['fields'] ) { + foreach ( $this->results as $key => $user ) { + $this->results[ $key ] = new WP_User( $user ); + } } } + /** + * Retrieve query variable. + * + * @since 3.5.0 + * @access public + * + * @param string $query_var Query variable key. + * @return mixed + */ + function get( $query_var ) { + if ( isset( $this->query_vars[$query_var] ) ) + return $this->query_vars[$query_var]; + + return null; + } + + /** + * Set query variable. + * + * @since 3.5.0 + * @access public + * + * @param string $query_var Query variable key. + * @param mixed $value Query variable value. + */ + function set( $query_var, $value ) { + $this->query_vars[$query_var] = $value; + } + /* * Used internally to generate an SQL string for searching across multiple columns * @@ -676,6 +700,9 @@ function get_blogs_of_user( $user_id, $all = false ) { $blogs[ $blog_id ]->path = ''; $blogs[ $blog_id ]->site_id = 1; $blogs[ $blog_id ]->siteurl = get_option('siteurl'); + $blogs[ $blog_id ]->archived = 0; + $blogs[ $blog_id ]->spam = 0; + $blogs[ $blog_id ]->deleted = 0; return $blogs; } @@ -691,6 +718,9 @@ function get_blogs_of_user( $user_id, $all = false ) { 'path' => $blog->path, 'site_id' => $blog->site_id, 'siteurl' => $blog->siteurl, + 'archived' => 0, + 'spam' => 0, + 'deleted' => 0 ); } unset( $keys[ $wpdb->base_prefix . 'capabilities' ] ); @@ -717,6 +747,9 @@ function get_blogs_of_user( $user_id, $all = false ) { 'path' => $blog->path, 'site_id' => $blog->site_id, 'siteurl' => $blog->siteurl, + 'archived' => 0, + 'spam' => 0, + 'deleted' => 0 ); } } @@ -920,33 +953,31 @@ function count_users($strategy = 'time') { * @global int $user_ID The ID of the user * @global string $user_email The email address of the user * @global string $user_url The url in the user's profile - * @global string $user_pass_md5 MD5 of the user's password * @global string $user_identity The display name of the user * * @param int $for_user_id Optional. User ID to set up global data. */ function setup_userdata($for_user_id = '') { - global $user_login, $userdata, $user_level, $user_ID, $user_email, $user_url, $user_pass_md5, $user_identity; + global $user_login, $userdata, $user_level, $user_ID, $user_email, $user_url, $user_identity; if ( '' == $for_user_id ) - $user = wp_get_current_user(); - else - $user = new WP_User($for_user_id); - - $userdata = null; - $user_ID = (int) $user->ID; - $user_level = (int) isset($user->user_level) ? $user->user_level : 0; - - if ( ! $user->exists() ) { - $user_login = $user_email = $user_url = $user_pass_md5 = $user_identity = ''; + $for_user_id = get_current_user_id(); + $user = get_userdata( $for_user_id ); + + if ( ! $user ) { + $user_ID = 0; + $user_level = 0; + $userdata = null; + $user_login = $user_email = $user_url = $user_identity = ''; return; } + $user_ID = (int) $user->ID; + $user_level = (int) $user->user_level; $userdata = $user; $user_login = $user->user_login; $user_email = $user->user_email; $user_url = $user->user_url; - $user_pass_md5 = md5( $user->user_pass ); $user_identity = $user->display_name; } @@ -1221,7 +1252,7 @@ function validate_username( $username ) { * 'ID' - An integer that will be used for updating an existing user. * 'user_pass' - A string that contains the plain text password for the user. * 'user_login' - A string that contains the user's username for logging in. - * 'user_nicename' - A string that contains a nicer looking name for the user. + * 'user_nicename' - A string that contains a URL-friendly name for the user. * The default is the user's username. * 'user_url' - A string containing the user's URL for the user's web site. * 'user_email' - A string containing the user's email address. @@ -1245,13 +1276,18 @@ function validate_username( $username ) { * @uses do_action() Calls 'profile_update' hook when updating giving the user's ID * @uses do_action() Calls 'user_register' hook when creating a new user giving the user's ID * - * @param array $userdata An array of user data. + * @param mixed $userdata An array of user data or a user object of type stdClass or WP_User. * @return int|WP_Error The newly created user's ID or a WP_Error object if the user could not be created. */ -function wp_insert_user($userdata) { +function wp_insert_user( $userdata ) { global $wpdb; - extract($userdata, EXTR_SKIP); + if ( is_a( $userdata, 'stdClass' ) ) + $userdata = get_object_vars( $userdata ); + elseif ( is_a( $userdata, 'WP_User' ) ) + $userdata = $userdata->to_array(); + + extract( $userdata, EXTR_SKIP ); // Are we updating or creating? if ( !empty($ID) ) { @@ -1274,7 +1310,7 @@ function wp_insert_user($userdata) { return new WP_Error('empty_user_login', __('Cannot create a user with an empty login name.') ); if ( !$update && username_exists( $user_login ) ) - return new WP_Error('existing_user_login', __('This username is already registered.') ); + return new WP_Error( 'existing_user_login', __( 'Sorry, that username already exists!' ) ); if ( empty($user_nicename) ) $user_nicename = sanitize_title( $user_login ); @@ -1289,11 +1325,7 @@ function wp_insert_user($userdata) { $user_email = apply_filters('pre_user_email', $user_email); if ( !$update && ! defined( 'WP_IMPORTING' ) && email_exists($user_email) ) - return new WP_Error('existing_user_email', __('This email address is already registered.') ); - - if ( empty($display_name) ) - $display_name = $user_login; - $display_name = apply_filters('pre_user_display_name', $display_name); + return new WP_Error( 'existing_user_email', __( 'Sorry, that email address is already used!' ) ); if ( empty($nickname) ) $nickname = $user_login; @@ -1307,6 +1339,21 @@ function wp_insert_user($userdata) { $last_name = ''; $last_name = apply_filters('pre_user_last_name', $last_name); + if ( empty( $display_name ) ) { + if ( $update ) + $display_name = $user_login; + elseif ( $first_name && $last_name ) + /* translators: 1: first name, 2: last name */ + $display_name = sprintf( _x( '%1$s %2$s', 'Display name based on first name and last name' ), $first_name, $last_name ); + elseif ( $first_name ) + $display_name = $first_name; + elseif ( $last_name ) + $display_name = $last_name; + else + $display_name = $user_login; + } + $display_name = apply_filters( 'pre_user_display_name', $display_name ); + if ( empty($description) ) $description = ''; $description = apply_filters('pre_user_description', $description); @@ -1392,16 +1439,21 @@ function wp_insert_user($userdata) { * @see wp_insert_user() For what fields can be set in $userdata * @uses wp_insert_user() Used to update existing user or add new one if user doesn't exist already * - * @param array $userdata An array of user data. - * @return int The updated user's ID. + * @param mixed $userdata An array of user data or a user object of type stdClass or WP_User. + * @return int|WP_Error The updated user's ID or a WP_Error object if the user could not be updated. */ function wp_update_user($userdata) { + if ( is_a( $userdata, 'stdClass' ) ) + $userdata = get_object_vars( $userdata ); + elseif ( is_a( $userdata, 'WP_User' ) ) + $userdata = $userdata->to_array(); + $ID = (int) $userdata['ID']; // First, get all of the original fields $user_obj = get_userdata( $ID ); - $user = get_object_vars( $user_obj->data ); + $user = $user_obj->to_array(); // Add additional custom fields foreach ( _get_additional_user_keys( $user_obj ) as $key ) { @@ -1461,10 +1513,10 @@ function wp_create_user($username, $password, $email = '') { /** * Return a list of meta keys that wp_insert_user() is supposed to set. * - * @access private * @since 3.3.0 + * @access private * - * @param object $user WP_User instance + * @param object $user WP_User instance. * @return array */ function _get_additional_user_keys( $user ) { @@ -1473,12 +1525,12 @@ function _get_additional_user_keys( $user ) { } /** - * Set up the default contact methods + * Set up the default contact methods. * + * @since 2.9.0 * @access private - * @since * - * @param object $user User data object (optional) + * @param object $user User data object (optional). * @return array $user_contactmethods Array of contact methods and their labels. */ function _wp_get_user_contactmethods( $user = null ) { diff --git a/wp-includes/vars.php b/wp-includes/vars.php index 7585793d..23e0e580 100644 --- a/wp-includes/vars.php +++ b/wp-includes/vars.php @@ -116,7 +116,8 @@ function wp_is_mobile() { || strpos($_SERVER['HTTP_USER_AGENT'], 'Silk/') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry') !== false - || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false ) { + || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false + || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false ) { $is_mobile = true; } else { $is_mobile = false; diff --git a/wp-includes/version.php b/wp-includes/version.php index c7c9e8c9..8e751886 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,28 +4,21 @@ * * @global string $wp_version */ -$wp_version = '3.4.2'; +$wp_version = '3.5'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * * @global int $wp_db_version */ -$wp_db_version = 21707; +$wp_db_version = 22441; /** * Holds the TinyMCE version * * @global string $tinymce_version */ -$tinymce_version = '349-21274'; - -/** - * Holds the cache manifest version - * - * @global string $manifest_version - */ -$manifest_version = '20111113'; +$tinymce_version = '358-23156'; /** * Holds the required PHP version diff --git a/wp-includes/widgets.php b/wp-includes/widgets.php index 765bbffc..2277fad1 100644 --- a/wp-includes/widgets.php +++ b/wp-includes/widgets.php @@ -152,15 +152,15 @@ class WP_Widget { } function _get_display_callback() { - return array(&$this, 'display_callback'); + return array($this, 'display_callback'); } function _get_update_callback() { - return array(&$this, 'update_callback'); + return array($this, 'update_callback'); } function _get_form_callback() { - return array(&$this, 'form_callback'); + return array($this, 'form_callback'); } /** Generate the actual widget content. @@ -317,7 +317,7 @@ class WP_Widget_Factory { var $widgets = array(); function WP_Widget_Factory() { - add_action( 'widgets_init', array( &$this, '_register_widgets' ), 100 ); + add_action( 'widgets_init', array( $this, '_register_widgets' ), 100 ); } function register($widget_class) { diff --git a/wp-includes/wp-db.php b/wp-includes/wp-db.php index f4187459..391cfa4d 100644 --- a/wp-includes/wp-db.php +++ b/wp-includes/wp-db.php @@ -88,7 +88,7 @@ class wpdb { /** * Count of rows returned by previous query * - * @since 1.2.0 + * @since 0.71 * @access private * @var int */ @@ -113,9 +113,9 @@ class wpdb { var $insert_id = 0; /** - * Saved result of the last query made + * Last query made * - * @since 1.2.0 + * @since 0.71 * @access private * @var array */ @@ -124,20 +124,29 @@ class wpdb { /** * Results of the last query made * - * @since 1.0.0 + * @since 0.71 * @access private * @var array|null */ var $last_result; + /** + * MySQL result, which is either a resource or boolean. + * + * @since 0.71 + * @access protected + * @var mixed + */ + protected $result; + /** * Saved info on the table column * - * @since 1.2.0 - * @access private + * @since 0.71 + * @access protected * @var array */ - var $col_info; + protected $col_info; /** * Saved queries that were executed @@ -155,7 +164,7 @@ class wpdb { * in a single database. The second reason is for possible * security precautions. * - * @since 0.71 + * @since 2.5.0 * @access private * @var string */ @@ -164,7 +173,7 @@ class wpdb { /** * Whether the database queries are ready to start executing. * - * @since 2.5.0 + * @since 2.3.2 * @access private * @var bool */ @@ -445,10 +454,46 @@ class wpdb { * Database Username * * @since 2.9.0 - * @access private + * @access protected + * @var string + */ + protected $dbuser; + + /** + * Database Password + * + * @since 3.1.0 + * @access protected * @var string */ - var $dbuser; + protected $dbpassword; + + /** + * Database Name + * + * @since 3.1.0 + * @access protected + * @var string + */ + protected $dbname; + + /** + * Database Host + * + * @since 3.1.0 + * @access protected + * @var string + */ + protected $dbhost; + + /** + * Database Handle + * + * @since 0.71 + * @access protected + * @var string + */ + protected $dbh; /** * A textual description of the last query/get_row/get_var call @@ -489,7 +534,7 @@ class wpdb { * @param string $dbhost MySQL database host */ function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) { - register_shutdown_function( array( &$this, '__destruct' ) ); + register_shutdown_function( array( $this, '__destruct' ) ); if ( WP_DEBUG ) $this->show_errors(); @@ -515,6 +560,57 @@ class wpdb { return true; } + /** + * PHP5 style magic getter, used to lazy-load expensive data. + * + * @since 3.5.0 + * + * @param string $name The private member to get, and optionally process + * @return mixed The private member + */ + function __get( $name ) { + if ( 'col_info' == $name ) + $this->load_col_info(); + + return $this->$name; + } + + /** + * Magic function, for backwards compatibility + * + * @since 3.5.0 + * + * @param string $name The private member to set + * @param mixed $value The value to set + */ + function __set( $name, $value ) { + $this->$name = $value; + } + + /** + * Magic function, for backwards compatibility + * + * @since 3.5.0 + * + * @param string $name The private member to check + * + * @return bool If the member is set or not + */ + function __isset( $name ) { + return isset( $this->$name ); + } + + /** + * Magic function, for backwards compatibility + * + * @since 3.5.0 + * + * @param string $name The private member to unset + */ + function __unset( $name ) { + unset( $this->$name ); + } + /** * Set $this->charset and $this->collate * @@ -850,7 +946,8 @@ class wpdb { * @return void */ function escape_by_ref( &$string ) { - $string = $this->_real_escape( $string ); + if ( ! is_float( $string ) ) + $string = $this->_real_escape( $string ); } /** @@ -890,7 +987,7 @@ class wpdb { * @return null|false|string Sanitized query string, null if there is no query, false if there is an error and string * if there was something to prepare */ - function prepare( $query = null ) { // ( $query, *$args ) + function prepare( $query, $args ) { if ( is_null( $query ) ) return; @@ -901,8 +998,9 @@ class wpdb { $args = $args[0]; $query = str_replace( "'%s'", '%s', $query ); // in case someone mistakenly already singlequoted it $query = str_replace( '"%s"', '%s', $query ); // doublequote unquoting + $query = preg_replace( '|(?last_query ); - if ( function_exists( 'error_log' ) - && ( $log_file = @ini_get( 'error_log' ) ) - && ( 'syslog' == $log_file || @is_writable( $log_file ) ) - ) - @error_log( $error_str ); + error_log( $error_str ); // Are we showing errors? if ( ! $this->show_errors ) @@ -1023,6 +1117,9 @@ class wpdb { $this->last_result = array(); $this->col_info = null; $this->last_query = null; + + if ( is_resource( $this->result ) ) + mysql_free_result( $this->result ); } /** @@ -1034,10 +1131,13 @@ class wpdb { $this->is_mysql = true; + $new_link = defined( 'MYSQL_NEW_LINK' ) ? MYSQL_NEW_LINK : true; + $client_flags = defined( 'MYSQL_CLIENT_FLAGS' ) ? MYSQL_CLIENT_FLAGS : 0; + if ( WP_DEBUG ) { - $this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, true ); + $this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags ); } else { - $this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, true ); + $this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags ); } if ( !$this->dbh ) { @@ -1104,30 +1204,23 @@ class wpdb { return false; } - if ( preg_match( '/^\s*(create|alter|truncate|drop) /i', $query ) ) { + if ( preg_match( '/^\s*(create|alter|truncate|drop)\s/i', $query ) ) { $return_val = $this->result; - } elseif ( preg_match( '/^\s*(insert|delete|update|replace) /i', $query ) ) { + } elseif ( preg_match( '/^\s*(insert|delete|update|replace)\s/i', $query ) ) { $this->rows_affected = mysql_affected_rows( $this->dbh ); // Take note of the insert_id - if ( preg_match( '/^\s*(insert|replace) /i', $query ) ) { + if ( preg_match( '/^\s*(insert|replace)\s/i', $query ) ) { $this->insert_id = mysql_insert_id($this->dbh); } // Return number of rows affected $return_val = $this->rows_affected; } else { - $i = 0; - while ( $i < @mysql_num_fields( $this->result ) ) { - $this->col_info[$i] = @mysql_fetch_field( $this->result ); - $i++; - } $num_rows = 0; while ( $row = @mysql_fetch_object( $this->result ) ) { $this->last_result[$num_rows] = $row; $num_rows++; } - @mysql_free_result( $this->result ); - // Log number of rows the query returned // and return number of rows selected $this->num_rows = $num_rows; @@ -1455,6 +1548,22 @@ class wpdb { return null; } + /** + * Load the column metadata from the last query. + * + * @since 3.5.0 + * + * @access protected + */ + protected function load_col_info() { + if ( $this->col_info ) + return; + + for ( $i = 0; $i < @mysql_num_fields( $this->result ); $i++ ) { + $this->col_info[ $i ] = @mysql_fetch_field( $this->result, $i ); + } + } + /** * Retrieve column metadata from the last query. * @@ -1465,6 +1574,8 @@ class wpdb { * @return mixed Column Results */ function get_col_info( $info_type = 'name', $col_offset = -1 ) { + $this->load_col_info(); + if ( $this->col_info ) { if ( $col_offset == -1 ) { $i = 0; @@ -1506,7 +1617,7 @@ class wpdb { /** * Wraps errors in a nice header and footer and dies. * - * Will not die if wpdb::$show_errors is true + * Will not die if wpdb::$show_errors is false. * * @since 1.5.0 * @@ -1547,13 +1658,34 @@ class wpdb { * Called when WordPress is generating the table scheme. * * @since 2.5.0 + * @deprecated 3.5.0 + * @deprecated Use wpdb::has_cap( 'collation' ) * * @return bool True if collation is supported, false if version does not */ function supports_collation() { + _deprecated_function( __FUNCTION__, '3.5', 'wpdb::has_cap( \'collation\' )' ); return $this->has_cap( 'collation' ); } + /** + * The database character collate. + * + * @since 3.5.0 + * + * @return string The database character collate. + */ + public function get_charset_collate() { + $charset_collate = ''; + + if ( ! empty( $this->charset ) ) + $charset_collate = "DEFAULT CHARACTER SET $this->charset"; + if ( ! empty( $this->collate ) ) + $charset_collate .= " COLLATE $this->collate"; + + return $charset_collate; + } + /** * Determine if a database supports a particular feature * diff --git a/wp-includes/wp-diff.php b/wp-includes/wp-diff.php index 052bf133..65dd0074 100644 --- a/wp-includes/wp-diff.php +++ b/wp-includes/wp-diff.php @@ -422,7 +422,7 @@ class WP_Text_Diff_Renderer_Table extends Text_Diff_Renderer { $chars2 = count_chars($string2); // L1-norm of difference vector. - $difference = array_sum( array_map( array(&$this, 'difference'), $chars1, $chars2 ) ); + $difference = array_sum( array_map( array($this, 'difference'), $chars1, $chars2 ) ); // $string1 has zero length? Odd. Give huge penalty by not dividing. if ( !$string1 ) diff --git a/wp-load.php b/wp-load.php index 1372688f..983558ab 100644 --- a/wp-load.php +++ b/wp-load.php @@ -57,7 +57,7 @@ if ( file_exists( ABSPATH . 'wp-config.php') ) { $die = __( "There doesn't seem to be a wp-config.php file. I need this before we can get started." ) . '

    '; $die .= '

    ' . __( "Need more help? We got it." ) . '

    '; $die .= '

    ' . __( "You can create a wp-config.php file through a web interface, but this doesn't work for all server setups. The safest way is to manually create the file." ) . '

    '; - $die .= '

    ' . __( "Create a Configuration File" ) . ''; + $die .= '

    ' . __( "Create a Configuration File" ) . ''; wp_die( $die, __( 'WordPress › Error' ) ); } diff --git a/wp-login.php b/wp-login.php index 50088db9..239e4a9c 100644 --- a/wp-login.php +++ b/wp-login.php @@ -12,12 +12,12 @@ require( dirname(__FILE__) . '/wp-load.php' ); // Redirect to https login if forced to use SSL -if ( force_ssl_admin() && !is_ssl() ) { +if ( force_ssl_admin() && ! is_ssl() ) { if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) { - wp_redirect(preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI'])); + wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) ); exit(); } else { - wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); + wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); exit(); } } @@ -39,7 +39,7 @@ if ( force_ssl_admin() && !is_ssl() ) { * @param WP_Error $wp_error Optional. WordPress Error Object */ function login_header($title = 'Log In', $message = '', $wp_error = '') { - global $error, $interim_login, $current_site; + global $error, $interim_login, $current_site, $action; // Don't index any of these forms add_action( 'login_head', 'wp_no_robots' ); @@ -86,9 +86,15 @@ function login_header($title = 'Log In', $message = '', $wp_error = '') { if ( $interim_login ) $login_header_url = '#'; + $classes = array( 'login-action-' . $action, 'wp-core-ui' ); + if ( wp_is_mobile() ) + $classes[] = 'mobile'; + if ( is_rtl() ) + $classes[] = 'rtl'; + $classes = apply_filters( 'login_body_class', $classes, $action ); ?> - +

    add( 'invalid_username', __( 'ERROR: This username is invalid because it uses illegal characters. Please enter a valid username.' ) ); $sanitized_user_login = ''; } elseif ( username_exists( $sanitized_user_login ) ) { - $errors->add( 'username_exists', __( 'ERROR: This username is already registered, please choose another one.' ) ); + $errors->add( 'username_exists', __( 'ERROR: This username is already registered. Please choose another one.' ) ); } // Check the e-mail address @@ -361,13 +367,13 @@ nocache_headers(); header('Content-Type: '.get_bloginfo('html_type').'; charset='.get_bloginfo('charset')); -if ( defined('RELOCATE') ) { // Move flag is set +if ( defined( 'RELOCATE' ) && RELOCATE ) { // Move flag is set if ( isset( $_SERVER['PATH_INFO'] ) && ($_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF']) ) $_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], '', $_SERVER['PHP_SELF'] ); - $schema = is_ssl() ? 'https://' : 'http://'; - if ( dirname($schema . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) != get_option('siteurl') ) - update_option('siteurl', dirname($schema . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) ); + $url = dirname( set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ) ); + if ( $url != get_option( 'siteurl' ) ) + update_option( 'siteurl', $url ); } //Set a cookie now to see if they are supported by the browser. @@ -390,7 +396,7 @@ case 'postpass' : } // 10 days - setcookie( 'wp-postpass_' . COOKIEHASH, $wp_hasher->HashPassword( stripslashes( $_POST['post_password'] ) ), time() + 864000, COOKIEPATH ); + setcookie( 'wp-postpass_' . COOKIEHASH, $wp_hasher->HashPassword( stripslashes( $_POST['post_password'] ) ), time() + 10 * DAY_IN_SECONDS, COOKIEPATH ); wp_safe_redirect( wp_get_referer() ); exit(); @@ -432,11 +438,11 @@ case 'retrievepassword' :

    +

    -

    +

    ' . __( 'Your password has been reset.' ) . ' ' . __( 'Log in' ) . '

    ' ); login_footer(); @@ -492,7 +501,7 @@ case 'rp' :


    -

    +

    +

    +


    -

    +

    +

    +

    -

    +

    - + diff --git a/wp-mail.php b/wp-mail.php index 7fc3967b..5685b3ac 100644 --- a/wp-mail.php +++ b/wp-mail.php @@ -30,7 +30,7 @@ if ( $last_checked ) set_transient('mailserver_last_checked', true, WP_MAIL_INTERVAL); -$time_difference = get_option('gmt_offset') * 3600; +$time_difference = get_option('gmt_offset') * HOUR_IN_SECONDS; $phone_delim = '::'; diff --git a/wp-settings.php b/wp-settings.php index cb950184..65485a84 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -32,16 +32,12 @@ wp_check_php_mysql_versions(); @ini_set( 'magic_quotes_runtime', 0 ); @ini_set( 'magic_quotes_sybase', 0 ); -// Set default timezone in PHP 5. -if ( function_exists( 'date_default_timezone_set' ) ) - date_default_timezone_set( 'UTC' ); +// WordPress calculates offsets from UTC. +date_default_timezone_set( 'UTC' ); // Turn register_globals off. wp_unregister_GLOBALS(); -// Ensure these global variables do not exist so they do not interfere with WordPress. -unset( $wp_filter, $cache_lastcommentmodified ); - // Standardize $_SERVER variables across setups. wp_fix_server_vars(); @@ -138,6 +134,7 @@ require( ABSPATH . WPINC . '/taxonomy.php' ); require( ABSPATH . WPINC . '/update.php' ); require( ABSPATH . WPINC . '/canonical.php' ); require( ABSPATH . WPINC . '/shortcodes.php' ); +require( ABSPATH . WPINC . '/class-wp-embed.php' ); require( ABSPATH . WPINC . '/media.php' ); require( ABSPATH . WPINC . '/http.php' ); require( ABSPATH . WPINC . '/class-http.php' ); @@ -232,7 +229,7 @@ $wp_the_query = new WP_Query(); * @global object $wp_query * @since 1.5.0 */ -$wp_query =& $wp_the_query; +$wp_query = $wp_the_query; /** * Holds the WordPress Rewrite object for creating pretty URLs @@ -255,6 +252,13 @@ $wp = new WP(); */ $GLOBALS['wp_widget_factory'] = new WP_Widget_Factory(); +/** + * WordPress User Roles + * @global object $wp_roles + * @since 2.0.0 + */ +$GLOBALS['wp_roles'] = new WP_Roles(); + do_action( 'setup_theme' ); // Define the template related constants. diff --git a/wp-signup.php b/wp-signup.php index 2cd93c82..7d35d865 100644 --- a/wp-signup.php +++ b/wp-signup.php @@ -23,7 +23,7 @@ if ( !is_multisite() ) { } if ( !is_main_site() ) { - wp_redirect( network_home_url( 'wp-signup.php' ) ); + wp_redirect( network_site_url( 'wp-signup.php' ) ); die(); } @@ -390,11 +390,7 @@ $current_user = wp_get_current_user(); if ( $active_signup == 'none' ) { _e( 'Registration has been disabled.' ); } elseif ( $active_signup == 'blog' && !is_user_logged_in() ) { - if ( is_ssl() ) - $proto = 'https://'; - else - $proto = 'http://'; - $login_url = site_url( 'wp-login.php?redirect_to=' . urlencode($proto . $_SERVER['HTTP_HOST'] . '/wp-signup.php' )); + $login_url = site_url( 'wp-login.php?redirect_to=' . urlencode( network_site_url( 'wp-signup.php' ) ) ); echo sprintf( __( 'You must first log in, and then you can create a new site.' ), $login_url ); } else { $stage = isset( $_POST['stage'] ) ? $_POST['stage'] : 'default'; diff --git a/xmlrpc.php b/xmlrpc.php index 2d3822ca..1998e4a8 100644 --- a/xmlrpc.php +++ b/xmlrpc.php @@ -42,7 +42,7 @@ header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true); - +